Chi-Tech
lbs_01g_initparrays.cc
Go to the documentation of this file.
1#include "lbs_solver.h"
2
4
5#include "chi_runtime.h"
6#include "chi_log.h"
7#include "chi_mpi.h"
9
10#include <iomanip>
11
12// ###################################################################
13/**Initializes parallel arrays.*/
15{
16 Chi::log.Log() << "Initializing parallel arrays."
17 << " G=" << num_groups_ << " M=" << num_moments_ << std::endl;
18
19 //================================================== Initialize unknown
20 // structure
22 for (size_t m = 0; m < num_moments_; m++)
23 {
25 groups_.size());
26 flux_moments_uk_man_.unknowns_.back().text_name_ = "m" + std::to_string(m);
27 }
28
29 //================================================== Compute local # of dof
31 local_node_count_ = discretization_->GetNumLocalDOFs(per_node);
32 glob_node_count_ = discretization_->GetNumGlobalDOFs(per_node);
33
34 //================================================== Compute num of unknowns
35 size_t num_grps = groups_.size();
36 size_t local_unknown_count = local_node_count_ * num_grps * num_moments_;
37
39 << "LBS Number of phi unknowns: " << local_unknown_count;
40
41 //================================================== Size local vectors
42 q_moments_local_.assign(local_unknown_count, 0.0);
43 phi_old_local_.assign(local_unknown_count, 0.0);
44 phi_new_local_.assign(local_unknown_count, 0.0);
45
46 //============================================= Setup groupset psi vectors
47 psi_new_local_.clear();
48 for (auto& groupset : groupsets_)
49 {
50 psi_new_local_.emplace_back();
52 {
53 size_t num_ang_unknowns =
54 discretization_->GetNumLocalDOFs(groupset.psi_uk_man_);
55 psi_new_local_.back().assign(num_ang_unknowns, 0.0);
56 }
57 }
58
59 //============================================= Setup precursor vector
61 {
62 size_t num_precursor_dofs =
63 grid_ptr_->local_cells.size() * max_precursors_per_material_;
64 precursor_new_local_.assign(num_precursor_dofs, 0.0);
65 }
66
67 //================================================== Read Restart data
72
73 //================================================== Initialize transport
74 // views
75 // Transport views act as a data structure to store information
76 // related to the transport simulation. The most prominent function
77 // here is that it holds the means to know where a given cell's
78 // transport quantities are located in the unknown vectors (i.e. phi)
79 //
80 // Also, for a given cell, within a given sweep chunk,
81 // we need to solve a matrix which square size is the
82 // amount of nodes on the cell. max_cell_dof_count is
83 // initialized here.
84 //
85 size_t block_MG_counter = 0; // Counts the strides of moment and group
86
87 const chi_mesh::Vector3 ihat(1.0, 0.0, 0.0);
88 const chi_mesh::Vector3 jhat(0.0, 1.0, 0.0);
89 const chi_mesh::Vector3 khat(0.0, 0.0, 1.0);
90
93 cell_transport_views_.reserve(grid_ptr_->local_cells.size());
94 for (auto& cell : grid_ptr_->local_cells)
95 {
96 size_t num_nodes = discretization_->GetCellNumNodes(cell);
97 int mat_id = cell.material_id_;
98
99 // compute cell volumes
100 double cell_volume = 0.0;
101 const auto& IntV_shapeI = unit_cell_matrices_[cell.local_id_].Vi_vectors;
102 for (size_t i = 0; i < num_nodes; ++i)
103 cell_volume += IntV_shapeI[i];
104
105 size_t cell_phi_address = block_MG_counter;
106
107 const size_t num_faces = cell.faces_.size();
108 std::vector<bool> face_local_flags(num_faces, true);
109 std::vector<int> face_locality(num_faces, Chi::mpi.location_id);
110 std::vector<const chi_mesh::Cell*> neighbor_cell_ptrs(num_faces, nullptr);
111 bool cell_on_boundary = false;
112 int f = 0;
113 for (auto& face : cell.faces_)
114 {
115 if (not face.has_neighbor_)
116 {
117 chi_mesh::Vector3& n = face.normal_;
118
119 int boundary_id = -1;
120 if (n.Dot(ihat) > 0.999) boundary_id = 0;
121 else if (n.Dot(ihat) < -0.999)
122 boundary_id = 1;
123 else if (n.Dot(jhat) > 0.999)
124 boundary_id = 2;
125 else if (n.Dot(jhat) < -0.999)
126 boundary_id = 3;
127 else if (n.Dot(khat) > 0.999)
128 boundary_id = 4;
129 else if (n.Dot(khat) < -0.999)
130 boundary_id = 5;
131
132 if (boundary_id >= 0) face.neighbor_id_ = boundary_id;
133 cell_on_boundary = true;
134
135 face_local_flags[f] = false;
136 face_locality[f] = -1;
137 } // if bndry
138 else
139 {
140 const int neighbor_partition = face.GetNeighborPartitionID(*grid_ptr_);
141 face_local_flags[f] = (neighbor_partition == Chi::mpi.location_id);
142 face_locality[f] = neighbor_partition;
143 neighbor_cell_ptrs[f] = &grid_ptr_->cells[face.neighbor_id_];
144 }
145
146 ++f;
147 } // for f
148
149 if (num_nodes > max_cell_dof_count_) max_cell_dof_count_ = num_nodes;
150
151 cell_transport_views_.emplace_back(cell_phi_address,
152 num_nodes,
153 num_grps,
155 *matid_to_xs_map_[mat_id],
156 cell_volume,
157 face_local_flags,
158 face_locality,
159 neighbor_cell_ptrs,
160 cell_on_boundary);
161 block_MG_counter += num_nodes * num_grps * num_moments_;
162 } // for local cell
163
164 //================================================== Populate grid nodal
165 // mappings
166 // This is used in the Flux Data Structures (FLUDS)
167 grid_nodal_mappings_.clear();
168 grid_nodal_mappings_.reserve(grid_ptr_->local_cells.size());
169 for (auto& cell : grid_ptr_->local_cells)
170 {
172 cell_nodal_mapping.reserve(cell.faces_.size());
173
174 for (auto& face : cell.faces_)
175 {
176 std::vector<short> face_node_mapping;
177 std::vector<short> cell_node_mapping;
178 int ass_face = -1;
179
180 if (face.has_neighbor_)
181 {
182 grid_ptr_->FindAssociatedVertices(face, face_node_mapping);
183 grid_ptr_->FindAssociatedCellVertices(face, cell_node_mapping);
184 ass_face = face.GetNeighborAssociatedFace(*grid_ptr_);
185 }
186
187 cell_nodal_mapping.emplace_back(
188 ass_face, face_node_mapping, cell_node_mapping);
189 } // for f
190
191 grid_nodal_mappings_.push_back(cell_nodal_mapping);
192 } // for local cell
193
194 //================================================== Get grid localized
195 // communicator set
196 grid_local_comm_set_ = grid_ptr_->MakeMPILocalCommunicatorSet();
197
198 //================================================== Make face histogram
199 grid_face_histogram_ = grid_ptr_->MakeGridFaceHistogram();
200
201 //================================================== Initialize
202 // Field Functions
204
206 Chi::log.Log()
207 << "Done with parallel arrays. Process memory = "
208 << std::setprecision(3) << chi::Console::GetMemoryUsageInMB() << " MB"
209 << std::endl;
210}
static chi::ChiLog & log
Definition: chi_runtime.h:81
static chi::MPI_Info & mpi
Definition: chi_runtime.h:78
LogStream LogAllVerbose1()
Definition: chi_log.h:241
LogStream Log(LOG_LVL level=LOG_0)
Definition: chi_log.cc:35
static double GetMemoryUsageInMB()
Get current memory usage in Megabytes.
void Barrier() const
Definition: mpi_info.cc:38
const int & location_id
Current process rank.
Definition: mpi_info.h:26
unsigned int AddUnknown(UnknownType unk_type, unsigned int dimension=0)
std::vector< Unknown > unknowns_
static UnknownManager GetUnitaryUnknownManager()
std::vector< double > precursor_new_local_
Definition: lbs_solver.h:97
std::vector< std::vector< double > > psi_new_local_
Definition: lbs_solver.h:96
chi_mesh::MeshContinuumPtr grid_ptr_
Definition: lbs_solver.h:75
std::shared_ptr< chi_math::SpatialDiscretization > discretization_
Definition: lbs_solver.h:74
std::vector< lbs::CellLBSView > cell_transport_views_
Definition: lbs_solver.h:83
std::vector< UnitCellMatrices > unit_cell_matrices_
Definition: lbs_solver.h:81
GridFaceHistogramPtr grid_face_histogram_
Definition: lbs_solver.h:79
std::vector< double > phi_new_local_
Definition: lbs_solver.h:95
std::vector< LBSGroup > groups_
Definition: lbs_solver.h:67
chi_math::UnknownManager flux_moments_uk_man_
Definition: lbs_solver.h:88
size_t max_cell_dof_count_
Definition: lbs_solver.h:90
std::vector< double > q_moments_local_
Definition: lbs_solver.h:94
size_t num_groups_
Definition: lbs_solver.h:63
uint64_t glob_node_count_
Definition: lbs_solver.h:92
lbs::Options options_
Definition: lbs_solver.h:61
std::vector< double > phi_old_local_
Definition: lbs_solver.h:95
std::vector< CellFaceNodalMapping > grid_nodal_mappings_
Definition: lbs_solver.h:77
std::vector< LBSGroupset > groupsets_
Definition: lbs_solver.h:68
MPILocalCommSetPtr grid_local_comm_set_
Definition: lbs_solver.h:78
virtual void InitializeParrays()
uint64_t local_node_count_
Definition: lbs_solver.h:91
std::map< int, XSPtr > matid_to_xs_map_
Definition: lbs_solver.h:71
void ReadRestartData(const std::string &folder_name, const std::string &file_base)
size_t max_precursors_per_material_
Definition: lbs_solver.h:65
size_t num_moments_
Definition: lbs_solver.h:62
std::vector< FaceNodalMapping > CellFaceNodalMapping
Vector3 Dot(const chi_mesh::TensorRank2Dim3 &that) const
std::string read_restart_file_base
Definition: lbs_structs.h:131
bool read_restart_data
Definition: lbs_structs.h:129
bool use_precursors
Definition: lbs_structs.h:138
bool save_angular_flux
Definition: lbs_structs.h:141
std::string read_restart_folder_name
Definition: lbs_structs.h:130