Chi-Tech
lbs_01i_init_point_sources.cc
Go to the documentation of this file.
1#include "lbs_solver.h"
2
4
5#include "chi_runtime.h"
6#include "chi_log.h"
7
8/**Intializes all point sources.*/
10{
11 const std::string fname = "InitializePointSources";
12
13 //============================================= Loop over point sources
14 for (auto& point_source : point_sources_)
15 {
16 if (point_source.Strength().size() != num_groups_)
17 throw std::logic_error(
18 fname + ": Point source multigroup strength vector "
19 "is not compatible with the number of "
20 "groups in the simulation. Expected " +
21 std::to_string(num_groups_) + " found " +
22 std::to_string(point_source.Strength().size()));
23
24 const auto& p = point_source.Location();
25 double v_total = 0.0; //Total volume of all cells sharing
26 // this source
27 std::vector<PointSource::ContainingCellInfo> temp_list;
28 for (const auto& cell : grid_ptr_->local_cells)
29 {
30 if (grid_ptr_->CheckPointInsideCell(cell, p))
31 {
32 const auto& cell_view = discretization_->GetCellMapping(cell);
33 const auto& cell_matrices = unit_cell_matrices_[cell.local_id_];
34 const auto& M = cell_matrices.M_matrix;
35 const auto& I = cell_matrices.Vi_vectors;
36
37 std::vector<double> shape_values;
38 cell_view.ShapeValues(point_source.Location(),
39 shape_values/**ByRef*/);
40
41 const auto M_inv = chi_math::Inverse(M);
42
43 const auto q_p_weights = chi_math::MatMul(M_inv, shape_values);
44
45 double v_cell = 0.0;
46 for (double val : I) v_cell += val;
47 v_total += v_cell;
48
49 temp_list.push_back(
51 cell.local_id_,
52 shape_values,
53 q_p_weights});
54 }//if inside
55 }//for local cell
56
57 auto ghost_global_ids = grid_ptr_->cells.GetGhostGlobalIDs();
58 for (uint64_t ghost_global_id : ghost_global_ids)
59 {
60 const auto& neighbor_cell = grid_ptr_->cells[ghost_global_id];
61 if (grid_ptr_->CheckPointInsideCell(neighbor_cell, p))
62 {
63 const auto& cell_matrices =
64 unit_ghost_cell_matrices_[neighbor_cell.global_id_];
65 for (double val : cell_matrices.Vi_vectors)
66 v_total += val;
67 }//if point inside
68 }//for ghost cell
69
70 point_source.ClearInitializedInfo();
71 for (const auto& info : temp_list)
72 {
73 point_source.AddContainingCellInfo(info.volume_weight/v_total,
74 info.cell_local_id,
75 info.shape_values,
76 info.node_weights);
77 const auto& cell = grid_ptr_->local_cells[info.cell_local_id];
78 //Output message
79 {
80 std::stringstream output;
81 output << "Point source at " << p.PrintStr() << " assigned to cell "
82 << cell.global_id_ << " with shape values ";
83 for (double val : info.shape_values) output << val << " ";
84 output << "volume_weight=" << info.volume_weight/v_total;
85
86 Chi::log.LogAll() << output.str();
87 }
88 }//for info in temp list
89 }//for point_source
90}
static chi::ChiLog & log
Definition: chi_runtime.h:81
LogStream LogAll()
Definition: chi_log.h:237
std::vector< PointSource > point_sources_
Definition: lbs_solver.h:69
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
size_t num_groups_
Definition: lbs_solver.h:63
std::map< uint64_t, UnitCellMatrices > unit_ghost_cell_matrices_
Definition: lbs_solver.h:82
MatDbl Inverse(const MatDbl &A)
MatDbl MatMul(const MatDbl &A, const double c)