Chi-Tech
CBC_SweepChunk.cc
Go to the documentation of this file.
1#include "CBC_SweepChunk.h"
2
3#include "mesh/Cell/cell.h"
8
9#define scint static_cast<int>
10
11namespace lbs
12{
13
15 std::vector<double>& destination_phi,
16 std::vector<double>& destination_psi,
17 const chi_mesh::MeshContinuum& grid,
18 const chi_math::SpatialDiscretization& discretization,
19 const std::vector<UnitCellMatrices>& unit_cell_matrices,
20 std::vector<lbs::CellLBSView>& cell_transport_views,
21 const std::vector<double>& source_moments,
22 const LBSGroupset& groupset,
23 const std::map<int, XSPtr>& xs,
24 int num_moments,
25 int max_num_cell_dofs)
26 : SweepChunk(destination_phi,
27 destination_psi,
28 grid,
29 discretization,
30 unit_cell_matrices,
31 cell_transport_views,
32 source_moments,
33 groupset,
34 xs,
35 num_moments,
36 max_num_cell_dofs,
37 std::make_unique<CBC_SweepDependencyInterface>()),
38 cbc_sweep_depinterf_(
39 dynamic_cast<CBC_SweepDependencyInterface&>(sweep_dependency_interface_))
40{
41 // ================================== Register kernels
42 RegisterKernel("FEMVolumetricGradTerm",
44 RegisterKernel("FEMUpwindSurfaceIntegrals",
46 RegisterKernel("FEMSSTDMassTerms",
47 std::bind(&SweepChunk::KernelFEMSTDMassTerms, this));
48 RegisterKernel("KernelPhiUpdate",
49 std::bind(&SweepChunk::KernelPhiUpdate, this));
50 RegisterKernel("KernelPsiUpdate",
51 std::bind(&SweepChunk::KernelPsiUpdate, this));
52
53 // ================================== Setup callbacks
55
56 direction_data_callbacks_and_kernels_ = {Kernel("FEMVolumetricGradTerm")};
57
58 surface_integral_kernels_ = {Kernel("FEMUpwindSurfaceIntegrals")};
59
60 mass_term_kernels_ = {Kernel("FEMSSTDMassTerms")};
61
62 flux_update_kernels_ = {Kernel("KernelPhiUpdate"), Kernel("KernelPsiUpdate")};
63
65}
66
68{
69 cbc_sweep_depinterf_.fluds_ = &dynamic_cast<CBC_FLUDS&>(angle_set.GetFLUDS());
70
71 const chi::SubSetInfo& grp_ss_info =
73
74 gs_ss_size_ = grp_ss_info.ss_size;
75 gs_ss_begin_ = grp_ss_info.ss_begin;
77
82
85 angle_set.GetNumGroups() * angle_set.GetNumAngles();
86}
87
90{
91 cell_ptr_ = cell_ptr;
93
99
100 cell_num_faces_ = cell_->faces_.size();
102
103 // =============================================== Get Cell matrices
104 const auto& fe_intgrl_values = unit_cell_matrices_[cell_local_id_];
105 G_ = &fe_intgrl_values.G_matrix;
106 M_ = &fe_intgrl_values.M_matrix;
107 M_surf_ = &fe_intgrl_values.face_M_matrices;
108 IntS_shapeI_ = &fe_intgrl_values.face_Si_vectors;
109
110 for (auto& callback : cell_data_callbacks_)
111 callback();
112
114}
115
116void CBC_SweepChunk::SetCells(const std::vector<const chi_mesh::Cell*>& cell_ptrs)
117{
118 cell_ptrs_ = cell_ptrs;
119}
120
122{
124 const auto& face_orientations =
126 const auto& sigma_t = xs_.at(cell_->material_id_)->SigmaTotal();
127
128 // as = angle set
129 // ss = subset
130 const std::vector<size_t>& as_angle_indices = angle_set.GetAngleIndices();
131 const size_t as_num_angles = as_angle_indices.size();
132 for (size_t as_ss_idx = 0; as_ss_idx < as_num_angles; ++as_ss_idx)
133 {
134 direction_num_ = as_angle_indices[as_ss_idx];
137
140
141 // ======================================== Reset right-handside
142 for (int gsg = 0; gsg < gs_ss_size_; ++gsg)
143 b_[gsg].assign(cell_num_nodes_, 0.0);
144
146
147 // ======================================== Update face orientations
148 face_mu_values_.assign(cell_num_faces_, 0.0);
149 for (int f = 0; f < cell_num_faces_; ++f)
150 face_mu_values_[f] = omega_.Dot(cell_->faces_[f].normal_);
151
152 // ======================================== Surface integrals
153 for (int f = 0; f < cell_num_faces_; ++f)
154 {
155 const auto& face = cell_->faces_[f];
156
157 if (face_orientations[f] != FaceOrientation::INCOMING) continue;
158
159 const bool local = cell_transport_view_->IsFaceLocal(f);
160 const bool boundary = not face.has_neighbor_;
161
163 f, cell_mapping_->NumFaceNodes(f), face.neighbor_id_, local, boundary);
164
165 // IntSf_mu_psi_Mij_dA
167 } // for f
168
169 // ======================================== Looping over groups,
170 // Assembling mass terms
171 for (int gsg = 0; gsg < gs_ss_size_; ++gsg)
172 {
173 g_ = gs_gi_ + gsg;
174 gsg_ = gsg;
175 sigma_tg_ = sigma_t[g_];
176
178
179 // ================================= Solve system
181 }
182
183 // ======================================== Flux updates
185
186 // ======================================== Perform outgoing
187 // surface operations
188 for (int f = 0; f < cell_num_faces_; ++f)
189 {
190 if (face_orientations[f] != FaceOrientation::OUTGOING) continue;
191
192 // ================================= Set flags and counters
193 const auto& face = cell_->faces_[f];
194 const bool local = cell_transport_view_->IsFaceLocal(f);
195 const bool boundary = not face.has_neighbor_;
196 const int locality = cell_transport_view_->FaceLocality(f);
197
199 f,
201 face.neighbor_id_,
202 local,
203 boundary,
204 locality);
205
207 } // for face
208
210 } // for n
211}
212
213// ##################################################################
215 size_t num_face_nodes,
216 uint64_t neighbor_id,
217 bool on_local_face,
218 bool on_boundary)
219{
220 current_face_idx_ = face_id;
221 num_face_nodes_ = num_face_nodes;
222 neighbor_id_ = neighbor_id;
223 on_local_face_ = on_local_face;
224 on_boundary_ = on_boundary;
225
228
229 if (on_local_face_)
230 {
235 }
236 else if (not on_boundary_)
237 {
240 }
241}
242
244 size_t num_face_nodes,
245 uint64_t neighbor_id,
246 bool on_local_face,
247 bool on_boundary,
248 int locality)
249{
250 current_face_idx_ = face_id;
251 num_face_nodes_ = num_face_nodes;
252 neighbor_id_ = neighbor_id;
253 face_locality_ = locality;
254 on_local_face_ = on_local_face;
255 on_boundary_ = on_boundary;
256
259
261 (on_boundary_ and
262 angle_set_->GetBoundaries()[neighbor_id_]->IsReflecting());
263
264 if (not on_local_face_ and not on_boundary_)
265 {
266 auto& async_comm = *angle_set_->GetCommunicator();
267
268 size_t data_size = num_face_nodes_ * group_angle_stride_;
269
270 psi_dnwnd_data_ = &async_comm.InitGetDownwindMessageData(
274 angle_set_->GetID(),
275 data_size);
276 }
277}
278
279const double*
280CBC_SweepDependencyInterface::GetUpwindPsi(int face_node_local_idx) const
281{
282 const double* psi;
283 if (on_local_face_)
284 {
285 const unsigned int adj_cell_node =
286 face_nodal_mapping_->cell_node_mapping_[face_node_local_idx];
287
291 }
292 else if (not on_boundary_)
293 {
294 const unsigned int adj_face_node =
295 face_nodal_mapping_->face_node_mapping_[face_node_local_idx];
296
298 *psi_upwnd_data_block_, adj_face_node, angle_set_index_);
299 }
300 else
305 face_node_local_idx,
306 gs_gi_,
309
310 return psi;
311}
312
313double*
315{
316 double* psi = nullptr;
317
318 if (on_local_face_) psi = nullptr; // We don't write local face outputs
319 else if (not on_boundary_)
320 {
321 const size_t addr_offset = face_node_local_idx * group_angle_stride_ +
323
324 psi = &(*psi_dnwnd_data_)[addr_offset];
325 }
326 else if (is_reflecting_bndry_)
331 face_node_local_idx,
333
334 return psi;
335}
336
337} // namespace lbs
#define scint
size_t NumNodes() const
Definition: CellMapping.cc:34
size_t NumFaceNodes(size_t face_index) const
Definition: CellMapping.cc:36
const CellMapping & GetCellMapping(const chi_mesh::Cell &cell) const
std::vector< CellFace > faces_
Definition: cell.h:82
uint64_t local_id_
Definition: cell.h:76
int material_id_
Definition: cell.h:79
uint64_t global_id_
Definition: cell.h:75
LocalCellHandler local_cells
std::map< uint64_t, SweepBndryPtr > & GetBoundaries()
Definition: AngleSet.cc:50
virtual const double * PsiBndry(uint64_t bndry_map, unsigned int angle_num, uint64_t cell_local_id, unsigned int face_num, unsigned int fi, int g, size_t gs_ss_begin, bool surface_source_active)=0
const std::vector< size_t > & GetAngleIndices() const
Definition: AngleSet.cc:46
virtual AsynchronousCommunicator * GetCommunicator()
Definition: AngleSet.cc:58
virtual double * ReflectingPsiOutBoundBndry(uint64_t bndry_map, unsigned int angle_num, uint64_t cell_local_id, unsigned int face_num, unsigned int fi, size_t gs_ss_begin)=0
const SPDS & GetSPDS() const
Definition: AngleSet.cc:34
const FaceNodalMapping & GetFaceNodalMapping(uint64_t cell_local_id, unsigned int face_id) const
const std::vector< std::vector< FaceOrientation > > & CellFaceOrientations() const
Definition: SPDS.h:46
const double * GetLocalCellUpwindPsi(const std::vector< double > &psi_data_block, const chi_mesh::Cell &cell)
Definition: CBC_FLUDS.cc:36
const std::vector< double > & GetNonLocalUpwindData(uint64_t cell_global_id, unsigned int face_id) const
Definition: CBC_FLUDS.cc:46
const chi_mesh::sweep_management::FLUDSCommonData & CommonData() const
Definition: CBC_FLUDS.cc:25
const std::vector< double > & GetLocalUpwindDataBlock() const
Definition: CBC_FLUDS.cc:30
const double * GetNonLocalUpwindPsi(const std::vector< double > &psi_data, unsigned int face_node_mapped, unsigned int angle_set_index)
Definition: CBC_FLUDS.cc:53
void SetAngleSet(chi_mesh::sweep_management::AngleSet &angle_set) override
chi_mesh::Cell const * cell_ptr_
void SetCells(const std::vector< const chi_mesh::Cell * > &cell_ptrs) override
CBC_SweepDependencyInterface & cbc_sweep_depinterf_
void Sweep(chi_mesh::sweep_management::AngleSet &angle_set) override
void SetCell(chi_mesh::Cell const *cell_ptr, chi_mesh::sweep_management::AngleSet &angle_set) override
std::vector< const chi_mesh::Cell * > cell_ptrs_
CBC_SweepChunk(std::vector< double > &destination_phi, std::vector< double > &destination_psi, const chi_mesh::MeshContinuum &grid, const chi_math::SpatialDiscretization &discretization, const std::vector< UnitCellMatrices > &unit_cell_matrices, std::vector< lbs::CellLBSView > &cell_transport_views, const std::vector< double > &source_moments, const LBSGroupset &groupset, const std::map< int, XSPtr > &xs, int num_moments, int max_num_cell_dofs)
int FaceLocality(int f) const
Definition: lbs_structs.h:206
const chi_mesh::Cell * FaceNeighbor(int f) const
Definition: lbs_structs.h:207
bool IsFaceLocal(int f) const
Definition: lbs_structs.h:205
std::vector< chi::SubSetInfo > grp_subset_infos_
Definition: lbs_groupset.h:50
std::shared_ptr< chi_math::AngularQuadrature > quadrature_
Definition: lbs_groupset.h:42
std::vector< LBSGroup > groups_
Definition: lbs_groupset.h:41
std::vector< std::vector< double > > Atemp_
Definition: SweepChunk.h:108
std::vector< CallbackFunction > surface_integral_kernels_
Definition: SweepChunk.h:136
const std::vector< VecDbl > * IntS_shapeI_
Definition: SweepChunk.h:122
std::vector< CallbackFunction > flux_update_kernels_
Definition: SweepChunk.h:146
void KernelPhiUpdate()
Definition: SweepChunk.cc:196
void KernelFEMSTDMassTerms()
Definition: SweepChunk.cc:160
chi_mesh::Vector3 omega_
Definition: SweepChunk.h:129
size_t cell_num_faces_
Definition: SweepChunk.h:117
size_t direction_num_
Definition: SweepChunk.h:128
void RegisterKernel(const std::string &name, CallbackFunction function)
Definition: SweepChunk.cc:57
double direction_qweight_
Definition: SweepChunk.h:130
size_t gs_ss_begin_
Definition: SweepChunk.h:104
const std::vector< UnitCellMatrices > & unit_cell_matrices_
Definition: SweepChunk.h:88
std::vector< double > face_mu_values_
Definition: SweepChunk.h:127
const std::vector< MatDbl > * M_surf_
Definition: SweepChunk.h:121
const MatDbl * M_
Definition: SweepChunk.h:120
const std::map< int, XSPtr > & xs_
Definition: SweepChunk.h:92
CellLBSView * cell_transport_view_
Definition: SweepChunk.h:116
std::vector< CallbackFunction > mass_term_kernels_
Definition: SweepChunk.h:143
const LBSGroupset & groupset_
Definition: SweepChunk.h:91
std::vector< CallbackFunction > direction_data_callbacks_and_kernels_
Definition: SweepChunk.h:133
const chi_math::SpatialDiscretization & grid_fe_view_
Definition: SweepChunk.h:87
void KernelPsiUpdate()
Definition: SweepChunk.cc:216
CallbackFunction Kernel(const std::string &name) const
Definition: SweepChunk.cc:69
SweepDependencyInterface & sweep_dependency_interface_
Definition: SweepChunk.h:97
void KernelFEMVolumetricGradientTerm()
Definition: SweepChunk.cc:121
size_t cell_num_nodes_
Definition: SweepChunk.h:118
virtual void OutgoingSurfaceOperations()
Definition: SweepChunk.cc:89
size_t gs_ss_size_
Definition: SweepChunk.h:103
double sigma_tg_
Definition: SweepChunk.h:140
static void ExecuteKernels(const std::vector< CallbackFunction > &kernels)
Definition: SweepChunk.cc:78
const chi_mesh::Cell * cell_
Definition: SweepChunk.h:114
std::vector< std::vector< double > > b_
Definition: SweepChunk.h:110
std::vector< CallbackFunction > post_cell_dir_sweep_callbacks_
Definition: SweepChunk.h:149
const MatVec3 * G_
Definition: SweepChunk.h:119
std::vector< CallbackFunction > cell_data_callbacks_
Definition: SweepChunk.h:125
const chi_mesh::MeshContinuum & grid_
Definition: SweepChunk.h:86
void KernelFEMUpwindSurfaceIntegrals()
Definition: SweepChunk.cc:132
const chi_math::CellMapping * cell_mapping_
Definition: SweepChunk.h:115
std::vector< lbs::CellLBSView > & grid_transport_view_
Definition: SweepChunk.h:89
void GaussElimination(MatDbl &A, VecDbl &b, int n)
size_t ss_size
Definition: chi_utils.h:53
size_t ss_begin
Definition: chi_utils.h:51
Vector3 Dot(const chi_mesh::TensorRank2Dim3 &that) const
const std::vector< short > face_node_mapping_
const std::vector< short > cell_node_mapping_
void SetupIncomingFace(int face_id, size_t num_face_nodes, uint64_t neighbor_id, bool on_local_face, bool on_boundary) override
std::vector< double > * psi_dnwnd_data_
void SetupOutgoingFace(int face_id, size_t num_face_nodes, uint64_t neighbor_id, bool on_local_face, bool on_boundary, int locality) override
const chi_mesh::sweep_management::FaceNodalMapping * face_nodal_mapping_
const std::vector< double > * psi_upwnd_data_block_
const chi_mesh::Cell * neighbor_cell_ptr_
const CellLBSView * cell_transport_view_
double * GetDownwindPsi(int face_node_local_idx) const override
const double * GetUpwindPsi(int face_node_local_idx) const override
virtual void SetupOutgoingFace(int face_id, size_t num_face_nodes, uint64_t neighbor_id, bool on_local_face, bool on_boundary, int locality)
Definition: SweepChunk.cc:251
const chi_mesh::Cell * cell_ptr_
Definition: SweepChunk.h:26
virtual void SetupIncomingFace(int face_id, size_t num_face_nodes, uint64_t neighbor_id, bool on_local_face, bool on_boundary)
Definition: SweepChunk.cc:236
chi_mesh::sweep_management::AngleSet * angle_set_
Definition: SweepChunk.h:20