Chi-Tech
lbsadj_innerproduct.cc
Go to the documentation of this file.
1#include "lbsadj_solver.h"
2
4
5// ###################################################################
6/**Computes the inner product of the flux and the material source.*/
8{
9 double local_integral = 0.0;
10
11 //============================================= Material sources
12 for (const auto& cell : grid_ptr_->local_cells)
13 {
14 if (matid_to_src_map_.count(cell.material_id_) == 0) continue; //Skip if no src
15
16 const auto& transport_view = cell_transport_views_[cell.local_id_];
17 const auto& source = matid_to_src_map_[cell.material_id_];
18 const auto& fe_values = unit_cell_matrices_[cell.local_id_];
19
20 for (const auto& group : groups_)
21 {
22 const int g = group.id_;
23 const double Q = source->source_value_g_[g];
24
25 if (Q > 0.0)
26 {
27 const int num_nodes = transport_view.NumNodes();
28 for (int i = 0; i < num_nodes; ++i)
29 {
30 const size_t dof_map = transport_view.MapDOF(i, 0, g); //unknown map
31
32 const double phi = phi_old_local_[dof_map];
33
34 local_integral += Q * phi * fe_values.Vi_vectors[i];
35 }//for node
36 }//check source value >0
37 }//for group
38 }//for cell
39
40 //============================================= Point sources
41 for (const auto& point_source : point_sources_)
42 {
43 const auto& info_list = point_source.ContainingCellsInfo();
44 for (const auto& info : info_list)
45 {
46 const auto& cell = grid_ptr_->local_cells[info.cell_local_id];
47 const auto& transport_view = cell_transport_views_[cell.local_id_];
48 const auto& source_strength = point_source.Strength();
49 const auto& shape_values = info.shape_values;
50
51 for (const auto& group : groups_)
52 {
53 const int g = group.id_;
54 const double S = source_strength[g] * info.volume_weight;
55
56 if (S > 0.0)
57 {
58 const int num_nodes = transport_view.NumNodes();
59 for (int i = 0; i < num_nodes; ++i)
60 {
61 const size_t dof_map = transport_view.MapDOF(i, 0, g); //unknown map
62
63 const double phi_i = phi_old_local_[dof_map];
64
65 local_integral += S * phi_i * shape_values[i];
66 }//for node
67 }//check source value >0
68 }//for group
69 }//for cell
70 }//for point source
71
72 double global_integral = 0.0;
73
74 MPI_Allreduce(&local_integral, //sendbuf
75 &global_integral, //recvbuf
76 1, MPI_DOUBLE, //count, datatype
77 MPI_SUM, //op
78 Chi::mpi.comm); //comm
79
80 return global_integral;
81}
static chi::MPI_Info & mpi
Definition: chi_runtime.h:78
std::vector< PointSource > point_sources_
Definition: lbs_solver.h:69
chi_mesh::MeshContinuumPtr grid_ptr_
Definition: lbs_solver.h:75
std::vector< lbs::CellLBSView > cell_transport_views_
Definition: lbs_solver.h:83
std::vector< UnitCellMatrices > unit_cell_matrices_
Definition: lbs_solver.h:81
std::vector< LBSGroup > groups_
Definition: lbs_solver.h:67
std::vector< double > phi_old_local_
Definition: lbs_solver.h:95
std::map< int, IsotropicSrcPtr > matid_to_src_map_
Definition: lbs_solver.h:72