Chi-Tech
lbsDO_compute_leakage.cc
Go to the documentation of this file.
2
4
5/**Computes the angular flux based leakage from boundary surfaces.
6\param groupset_id The groupset for which to compute the leakage.
7\param boundary_id uint64_t The boundary-id for which to perform the integration.
8
9\return The leakage as a value.
10*/
12 ComputeLeakage(const int groupset_id, const uint64_t boundary_id) const
13{
14 const std::string fname = "lbs::SteadySolver::ComputeLeakage";
15
16 //================================================== Perform checks
17 if (groupset_id<0 or groupset_id>=groupsets_.size())
18 throw std::invalid_argument(fname + ": Invalid groupset_id specified.");
19
21 throw std::logic_error(fname + ": Requires options.save_angular_flux to be"
22 " true.");
23
24 //================================================== Get info
25 const auto& sdm = *discretization_;
26 const auto& groupset = groupsets_.at(groupset_id);
27 const auto& psi_uk_man = groupset.psi_uk_man_;
28 const auto& quadrature = groupset.quadrature_;
29
30 const size_t num_angles = quadrature->omegas_.size();
31
32 const int gsi = groupset.groups_.front().id_;
33 const int gsf = groupset.groups_.back().id_;
34 const int gs_num_groups = gsf+1-gsi;
35
36 //================================================== Start integration
37 std::vector<double> local_leakage(gs_num_groups, 0.0);
38 for (const auto& cell : grid_ptr_->local_cells)
39 {
40 const auto& cell_mapping = sdm.GetCellMapping(cell);
41 const auto& fe_values = unit_cell_matrices_[cell.local_id_];
42
43 size_t f=0;
44 for (const auto& face : cell.faces_)
45 {
46 if (not face.has_neighbor_ and face.neighbor_id_ == boundary_id)
47 {
48 const auto& IntF_shapeI = fe_values.face_Si_vectors[f];
49 const size_t num_face_nodes = cell_mapping.NumFaceNodes(f);
50 for (size_t fi=0; fi<num_face_nodes; ++fi)
51 {
52 const int i = cell_mapping.MapFaceNode(f, fi);
53 for (size_t n=0; n<num_angles; ++n)
54 {
55 const auto& omega = quadrature->omegas_[n];
56 const auto& weight = quadrature->weights_[n];
57 const double mu = omega.Dot(face.normal_);
58 if (mu > 0.0)
59 {
60 for (int gi=0; gi<gs_num_groups; ++gi)
61 {
62 const int g = gi+gsi;
63 const int64_t imap = sdm.MapDOFLocal(cell, i, psi_uk_man, n, g);
64
65 const double psi = psi_new_local_[groupset_id][imap];
66
67 local_leakage[gi] += weight * mu * psi * IntF_shapeI[i];
68 }//for g
69 }//outgoing
70 }//for n
71 }//for face node
72 }//if right bndry
73 ++f;
74 }//for face
75 }//for cell
76
77 std::vector<double> global_leakage(gs_num_groups, 0.0);
78 MPI_Allreduce(local_leakage.data(), //sendbuf
79 global_leakage.data(), //recvbuf,
80 gs_num_groups, MPI_DOUBLE, //count+datatype
81 MPI_SUM, //operation
82 Chi::mpi.comm); //comm
83
84 return global_leakage;
85}
static chi::MPI_Info & mpi
Definition: chi_runtime.h:78
const MPI_Comm & comm
MPI communicator.
Definition: mpi_info.h:28
std::vector< double > ComputeLeakage(int groupset_id, uint64_t boundary_id) const
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< UnitCellMatrices > unit_cell_matrices_
Definition: lbs_solver.h:81
lbs::Options options_
Definition: lbs_solver.h:61
std::vector< LBSGroupset > groupsets_
Definition: lbs_solver.h:68
bool save_angular_flux
Definition: lbs_structs.h:141