17 for (
auto& group : groupset.
groups_)
18 cell_transport_view.ZeroOutflow(group.id_);
26 Chi::log.
Log() <<
"\n********** Computing balance\n";
31 auto mat_src = phi_old_local_;
32 mat_src.assign(mat_src.size(),0.0);
33 for (
auto& groupset : groupsets_)
35 q_moments_local_.assign(q_moments_local_.size(), 0.0);
36 active_set_source_function_(groupset, q_moments_local_,
45 double local_out_flow = 0.0;
46 double local_in_flow = 0.0;
47 double local_absorption = 0.0;
48 double local_production = 0.0;
49 for (
const auto& cell : grid_ptr_->local_cells)
51 const auto& cell_mapping = discretization_->GetCellMapping(cell);
52 const auto& transport_view = cell_transport_views_[cell.local_id_];
53 const auto& fe_intgrl_values = unit_cell_matrices_[cell.local_id_];
54 const size_t num_nodes = transport_view.NumNodes();
55 const auto& IntV_shapeI = fe_intgrl_values.Vi_vectors;
56 const auto& IntS_shapeI = fe_intgrl_values.face_Si_vectors;
63 for (
int f=0; f<cell.faces_.size(); ++f)
65 const auto& face = cell.faces_[f];
67 for (
const auto& groupset : groupsets_)
69 for (
int n = 0; n < groupset.quadrature_->omegas_.size(); ++n)
71 const auto &omega = groupset.quadrature_->omegas_[n];
72 const double wt = groupset.quadrature_->weights_[n];
73 const double mu = omega.Dot(face.normal_);
75 if (mu < 0.0 and (not face.has_neighbor_))
77 const auto &bndry = sweep_boundaries_[face.neighbor_id_];
78 for (
int fi = 0; fi < face.vertex_ids_.size(); ++fi)
80 const int i = cell_mapping.MapFaceNode(f, fi);
81 const auto &IntFi_shapeI = IntS_shapeI[f][i];
83 for (
const auto& group : groupset.groups_)
85 const int g = group.id_;
86 const double psi = *bndry->HeterogeneousPsiIncoming(
87 cell.local_id_, f, fi, n, g, 0);
88 local_in_flow -= mu * wt * psi * IntFi_shapeI;
101 for (
int g=0; g < num_groups_; ++g)
102 local_out_flow += transport_view.GetOutflow(g);
106 const auto& xs = transport_view.XS();
107 const auto& sigma_a = xs.SigmaAbsorption();
108 for (
int i=0; i<num_nodes; ++i)
109 for (
int g=0; g < num_groups_; ++g)
111 size_t imap = transport_view.MapDOF(i,0,g);
112 double phi_0g = phi_old_local_[imap];
113 double q_0g = mat_src[imap];
115 local_absorption += sigma_a[g] * phi_0g * IntV_shapeI[i];
116 local_production += q_0g * IntV_shapeI[i];
121 double local_balance = local_production + local_in_flow
122 - local_absorption - local_out_flow;
123 double local_gain = local_production + local_in_flow;
125 std::vector<double> local_balance_table = {local_absorption,
131 size_t table_size = local_balance_table.size();
133 std::vector<double> globl_balance_table(table_size,0.0);
135 MPI_Allreduce(local_balance_table.data(),
136 globl_balance_table.data(),
137 table_size,MPI_DOUBLE,
141 double globl_absorption = globl_balance_table.at(0);
142 double globl_production = globl_balance_table.at(1);
143 double globl_in_flow = globl_balance_table.at(2);
144 double globl_out_flow = globl_balance_table.at(3);
145 double globl_balance = globl_balance_table.at(4);
146 double globl_gain = globl_balance_table.at(5);
149 << std::setprecision(5) << std::scientific
150 <<
" Absorption rate = " << globl_absorption <<
"\n"
151 <<
" Production rate = " << globl_production <<
"\n"
152 <<
" In-flow rate = " << globl_in_flow <<
"\n"
153 <<
" Out-flow rate = " << globl_out_flow <<
"\n"
154 <<
" Net Gain (In-flow + sources) = " << globl_gain <<
"\n"
155 <<
" Net Balance = " << globl_balance <<
"\n"
156 <<
" (Net Balance)/(Net Gain) = " << globl_balance/globl_gain <<
"\n";
158 Chi::log.
Log() <<
"\n********** Done computing balance\n";
static chi::MPI_Info & mpi
LogStream Log(LOG_LVL level=LOG_0)
const MPI_Comm & comm
MPI communicator.
void ZeroOutflowBalanceVars(LBSGroupset &groupset)
std::vector< LBSGroup > groups_
std::vector< lbs::CellLBSView > cell_transport_views_
virtual void GSScopedCopyPrimarySTLvectors(LBSGroupset &groupset, const std::vector< double > &x_src, std::vector< double > &y)
@ APPLY_AGS_FISSION_SOURCES
@ APPLY_WGS_FISSION_SOURCES