Chi-Tech
AAH_SweepChunk.cc
Go to the documentation of this file.
1#include "AAH_SweepChunk.h"
2
5
6#define scint static_cast<int>
7
8namespace lbs
9{
10
12 const chi_mesh::MeshContinuum& grid,
13 const chi_math::SpatialDiscretization& discretization,
14 const std::vector<UnitCellMatrices>& unit_cell_matrices,
15 std::vector<lbs::CellLBSView>& cell_transport_views,
16 std::vector<double>& destination_phi,
17 std::vector<double>& destination_psi,
18 const std::vector<double>& source_moments,
19 const LBSGroupset& groupset,
20 const std::map<int, XSPtr>& xs,
21 int num_moments,
22 int max_num_cell_dofs)
23 : SweepChunk(destination_phi,
24 destination_psi,
25 grid,
26 discretization,
27 unit_cell_matrices,
28 cell_transport_views,
29 source_moments,
30 groupset,
31 xs,
32 num_moments,
33 max_num_cell_dofs,
34 std::make_unique<AAH_SweepDependencyInterface>())
35{
36 // ================================== Register kernels
37 RegisterKernel("FEMVolumetricGradTerm",
39 RegisterKernel("FEMUpwindSurfaceIntegrals",
41 RegisterKernel("FEMSSTDMassTerms",
42 std::bind(&SweepChunk::KernelFEMSTDMassTerms, this));
43 RegisterKernel("KernelPhiUpdate",
44 std::bind(&SweepChunk::KernelPhiUpdate, this));
45 RegisterKernel("KernelPsiUpdate",
46 std::bind(&SweepChunk::KernelPsiUpdate, this));
47
48 // ================================== Setup callbacks
50
51 direction_data_callbacks_and_kernels_ = {Kernel("FEMVolumetricGradTerm")};
52
53 surface_integral_kernels_ = {Kernel("FEMUpwindSurfaceIntegrals")};
54
55 mass_term_kernels_ = {Kernel("FEMSSTDMassTerms")};
56
57 flux_update_kernels_ = {Kernel("KernelPhiUpdate"), Kernel("KernelPsiUpdate")};
58
60}
61
63{
64 const chi::SubSetInfo& grp_ss_info =
66
67 gs_ss_size_ = grp_ss_info.ss_size;
68 gs_ss_begin_ = grp_ss_info.ss_begin;
70
71 int deploc_face_counter = -1;
72 int preloc_face_counter = -1;
73
78
79 auto& aah_sweep_depinterf =
81 aah_sweep_depinterf.fluds_ =
82 &dynamic_cast<chi_mesh::sweep_management::AAH_FLUDS&>(angle_set.GetFLUDS());
83
84 // ====================================================== Loop over each
85 // cell
86 const auto& spds = angle_set.GetSPDS();
87 const auto& spls = spds.GetSPLS().item_id;
88 const size_t num_spls = spls.size();
89 for (size_t spls_index = 0; spls_index < num_spls; ++spls_index)
90 {
91 cell_local_id_ = spls[spls_index];
97
98 using namespace chi_mesh::sweep_management;
99 const auto& face_orientations = spds.CellFaceOrientations()[cell_local_id_];
100
101 cell_num_faces_ = cell_->faces_.size();
103 const auto& sigma_t = xs_.at(cell_->material_id_)->SigmaTotal();
104
105 aah_sweep_depinterf.spls_index = spls_index;
106
107 // =============================================== Get Cell matrices
108 const auto& fe_intgrl_values = unit_cell_matrices_[cell_local_id_];
109 G_ = &fe_intgrl_values.G_matrix;
110 M_ = &fe_intgrl_values.M_matrix;
111 M_surf_ = &fe_intgrl_values.face_M_matrices;
112 IntS_shapeI_ = &fe_intgrl_values.face_Si_vectors;
113
114 for (auto& callback : cell_data_callbacks_)
115 callback();
116
117 // =============================================== Loop over angles in set
118 const int ni_deploc_face_counter = deploc_face_counter;
119 const int ni_preloc_face_counter = preloc_face_counter;
120
121 // as = angle set
122 // ss = subset
123 const std::vector<size_t>& as_angle_indices = angle_set.GetAngleIndices();
124 const size_t as_num_angles = as_angle_indices.size();
125 for (size_t as_ss_idx = 0; as_ss_idx < as_num_angles; ++as_ss_idx)
126 {
127 direction_num_ = as_angle_indices[as_ss_idx];
130
133
134 deploc_face_counter = ni_deploc_face_counter;
135 preloc_face_counter = ni_preloc_face_counter;
136
137 // ======================================== Reset right-handside
138 for (int gsg = 0; gsg < gs_ss_size_; ++gsg)
139 b_[gsg].assign(cell_num_nodes_, 0.0);
140
142
143 // ======================================== Upwinding structure
144 aah_sweep_depinterf.in_face_counter = 0;
145 aah_sweep_depinterf.preloc_face_counter = 0;
146 aah_sweep_depinterf.out_face_counter = 0;
147 aah_sweep_depinterf.deploc_face_counter = 0;
148
149 // ======================================== Update face orientations
150 face_mu_values_.assign(cell_num_faces_, 0.0);
151 for (int f = 0; f < cell_num_faces_; ++f)
152 face_mu_values_[f] = omega_.Dot(cell_->faces_[f].normal_);
153
154 // ======================================== Surface integrals
155 int in_face_counter = -1;
156 for (int f = 0; f < cell_num_faces_; ++f)
157 {
158 const auto& face = cell_->faces_[f];
159
160 if (face_orientations[f] != FaceOrientation::INCOMING) continue;
161
162 const bool local = cell_transport_view_->IsFaceLocal(f);
163 const bool boundary = not face.has_neighbor_;
164
165 if (local) ++in_face_counter;
166 else if (not boundary)
167 ++preloc_face_counter;
168
170 f,
172 face.neighbor_id_,
173 local,
174 boundary);
175
176 aah_sweep_depinterf.in_face_counter = in_face_counter;
177 aah_sweep_depinterf.preloc_face_counter = preloc_face_counter;
178
179 // IntSf_mu_psi_Mij_dA
181 } // for f
182
183 // ======================================== Looping over groups,
184 // Assembling mass terms
185 for (int gsg = 0; gsg < gs_ss_size_; ++gsg)
186 {
187 g_ = gs_gi_ + gsg;
188 gsg_ = gsg;
189 sigma_tg_ = sigma_t[g_];
190
192
193 // ================================= Solve system
195 }
196
197 // ======================================== Flux updates
199
200 // ======================================== Perform outgoing
201 // surface operations
202 int out_face_counter = -1;
203 for (int f = 0; f < cell_num_faces_; ++f)
204 {
205 if (face_orientations[f] != FaceOrientation::OUTGOING) continue;
206
207 // ================================= Set flags and counters
208 out_face_counter++;
209 const auto& face = cell_->faces_[f];
210 const bool local = cell_transport_view_->IsFaceLocal(f);
211 const bool boundary = not face.has_neighbor_;
212 const int locality = cell_transport_view_->FaceLocality(f);
213
214 if (not boundary and not local) ++deploc_face_counter;
215
217 f,
219 face.neighbor_id_,
220 local,
221 boundary,
222 locality);
223
224 aah_sweep_depinterf.out_face_counter = out_face_counter;
225 aah_sweep_depinterf.deploc_face_counter = deploc_face_counter;
226
228 } // for face
229
231 } // for n
232 } // for cell
233}
234
235// ##################################################################
236const double*
237AAH_SweepDependencyInterface::GetUpwindPsi(int face_node_local_idx) const
238{
239 const double* psi;
240 if (on_local_face_)
241 psi = fluds_->UpwindPsi(
242 spls_index, in_face_counter, face_node_local_idx, 0, angle_set_index_);
243 else if (not on_boundary_)
244 psi = fluds_->NLUpwindPsi(
245 preloc_face_counter, face_node_local_idx, 0, angle_set_index_);
246 else
251 face_node_local_idx,
252 gs_gi_,
255 return psi;
256}
257
258double*
260{
261 double* psi;
262 if (on_local_face_)
263 psi = fluds_->OutgoingPsi(
264 spls_index, out_face_counter, face_node_local_idx, angle_set_index_);
265 else if (not on_boundary_)
266 psi = fluds_->NLOutgoingPsi(
267 deploc_face_counter, face_node_local_idx, angle_set_index_);
268 else if (is_reflecting_bndry_)
273 face_node_local_idx,
275 else
276 psi = nullptr;
277
278 return psi;
279}
280
281} // 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
LocalCellHandler local_cells
double * NLOutgoingPsi(int outb_face_count, int face_dof, int n)
Definition: AAH_FLUDS.cc:70
double * OutgoingPsi(int cell_so_index, int outb_face_counter, int face_dof, int n)
Definition: AAH_FLUDS.cc:34
double * UpwindPsi(int cell_so_index, int inc_face_counter, int face_dof, int g, int n)
Definition: AAH_FLUDS.cc:107
double * NLUpwindPsi(int nonl_inc_face_counter, int face_dof, int g, int n)
Definition: AAH_FLUDS.cc:153
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 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 SPLS & GetSPLS() const
Definition: SPDS.h:26
AAH_SweepChunk(const chi_mesh::MeshContinuum &grid, const chi_math::SpatialDiscretization &discretization, const std::vector< UnitCellMatrices > &unit_cell_matrices, std::vector< lbs::CellLBSView > &cell_transport_views, std::vector< double > &destination_phi, std::vector< double > &destination_psi, const std::vector< double > &source_moments, const LBSGroupset &groupset, const std::map< int, XSPtr > &xs, int num_moments, int max_num_cell_dofs)
void Sweep(chi_mesh::sweep_management::AngleSet &angle_set) override
int FaceLocality(int f) const
Definition: lbs_structs.h:206
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
uint64_t cell_local_id_
Definition: SweepChunk.h:113
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
std::vector< int > item_id
Definition: SPLS.h:13
const double * GetUpwindPsi(int face_node_local_idx) const override
double * GetDownwindPsi(int face_node_local_idx) const override
chi_mesh::sweep_management::AAH_FLUDS * fluds_
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