Chi-Tech
lagD_03_buildsparsity.cc
Go to the documentation of this file.
2
4
5#include "chi_runtime.h"
6#include "chi_log.h"
7
9{
10
11// ###################################################################
12/**Builds the sparsity pattern for a Discontinuous Finite Element Method.*/
14 std::vector<int64_t>& nodal_nnz_in_diag,
15 std::vector<int64_t>& nodal_nnz_off_diag,
16 const chi_math::UnknownManager& unknown_manager) const
17{
18 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LOCAL CONNECTIVITY
19 size_t local_dof_count = local_base_block_size_;
20
21 nodal_nnz_in_diag.clear();
22 nodal_nnz_off_diag.clear();
23
24 nodal_nnz_in_diag.resize(local_dof_count, 0);
25 nodal_nnz_off_diag.resize(local_dof_count, 0);
26
27 int lc = 0;
28 for (const auto& cell : ref_grid_.local_cells)
29 {
30 const auto& cell_mapping = GetCellMapping(cell);
31 size_t num_nodes = cell_mapping.NumNodes();
32
33 //==================================== Self connection
34 for (int i = 0; i < num_nodes; ++i)
35 {
36 int64_t ir = cell_local_block_address_[lc] + i;
37 nodal_nnz_in_diag[ir] += static_cast<int64_t>(num_nodes);
38 }
39
40 //==================================== Local adjacent cell connections
41 for (auto& face : cell.faces_)
42 {
43 if (face.has_neighbor_ and face.IsNeighborLocal(ref_grid_))
44 {
45 const auto& adj_cell = ref_grid_.cells[face.neighbor_id_];
46 const auto& adj_cell_mapping = GetCellMapping(adj_cell);
47
48 for (int i = 0; i < num_nodes; ++i)
49 {
50 int64_t ir = cell_local_block_address_[lc] + i;
51 nodal_nnz_in_diag[ir] +=
52 static_cast<int64_t>(adj_cell_mapping.NumNodes());
53 }
54 }
55 } // for face
56 ++lc;
57 } // for local cell
58
59 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% NEIGHBORING CONNECTIVITY
60 lc = 0;
61 for (auto& cell : ref_grid_.local_cells)
62 {
63 const auto& cell_mapping = GetCellMapping(cell);
64
65 //==================================== Local adjacent cell connections
66 for (auto& face : cell.faces_)
67 {
68 if (face.has_neighbor_ and (not face.IsNeighborLocal(ref_grid_)))
69 {
70 const auto& adj_cell = ref_grid_.cells[face.neighbor_id_];
71 const auto& adj_cell_mapping = GetCellMapping(adj_cell);
72
73 for (int i = 0; i < cell_mapping.NumNodes(); ++i)
74 {
75 int64_t ir = cell_local_block_address_[lc] + i;
76 nodal_nnz_off_diag[ir] +=
77 static_cast<int64_t>(adj_cell_mapping.NumNodes());
78 }
79 }
80 }
81 ++lc;
82 } // for local cell
83
84 //============================================= Spacing according to unknown
85 // manager
86 auto backup_nnz_in_diag = nodal_nnz_in_diag;
87 auto backup_nnz_off_diag = nodal_nnz_off_diag;
88
89 unsigned int N = unknown_manager.GetTotalUnknownStructureSize();
90
91 nodal_nnz_in_diag.clear();
92 nodal_nnz_off_diag.clear();
93
94 nodal_nnz_in_diag.resize(local_base_block_size_ * N, 0);
95 nodal_nnz_off_diag.resize(local_base_block_size_ * N, 0);
96
98 {
99 int ir = -1;
100 for (int i = 0; i < local_base_block_size_; ++i)
101 {
102 for (int j = 0; j < N; ++j)
103 {
104 ++ir;
105 nodal_nnz_in_diag[ir] = backup_nnz_in_diag[i];
106 nodal_nnz_off_diag[ir] = backup_nnz_off_diag[i];
107 } // for j
108 } // for i
109 }
110 else if (unknown_manager.dof_storage_type_ ==
112 {
113 int ir = -1;
114 for (int j = 0; j < N; ++j)
115 {
116 for (int i = 0; i < local_base_block_size_; ++i)
117 {
118 ++ir;
119 nodal_nnz_in_diag[ir] = backup_nnz_in_diag[i];
120 nodal_nnz_off_diag[ir] = backup_nnz_off_diag[i];
121 } // for i
122 } // for j
123 }
124
126}
127
128} // namespace chi_math::spatial_discretization
static chi::MPI_Info & mpi
Definition: chi_runtime.h:78
void Barrier() const
Definition: mpi_info.cc:38
const CellMapping & GetCellMapping(const chi_mesh::Cell &cell) const
const chi_mesh::MeshContinuum & ref_grid_
UnknownStorageType dof_storage_type_
unsigned int GetTotalUnknownStructureSize() const
void BuildSparsityPattern(std::vector< int64_t > &nodal_nnz_in_diag, std::vector< int64_t > &nodal_nnz_off_diag, const UnknownManager &unknown_manager) const override
LocalCellHandler local_cells
GlobalCellHandler cells