Chi-Tech
lbs_05a_update_fieldfuncs.cc
Go to the documentation of this file.
1#include "lbs_solver.h"
2
5
6#include "chi_log.h"
7
8namespace lbs
9{
10
11// ###################################################################
12/**Copy relevant section of phi_old to the field functions.*/
14{
15 const auto& sdm = *discretization_;
16 const auto& phi_uk_man = flux_moments_uk_man_;
17
18 //======================================== Update flux moments
19 for (const auto& [g_and_m, ff_index] : phi_field_functions_local_map_)
20 {
21 const size_t g = g_and_m.first;
22 const size_t m = g_and_m.second;
23
24 std::vector<double> data_vector_local(local_node_count_, 0.0);
25
26 for (const auto& cell : grid_ptr_->local_cells)
27 {
28 const auto& cell_mapping = sdm.GetCellMapping(cell);
29 const size_t num_nodes = cell_mapping.NumNodes();
30
31 for (size_t i = 0; i < num_nodes; ++i)
32 {
33 const int64_t imapA = sdm.MapDOFLocal(cell, i, phi_uk_man, m, g);
34 const int64_t imapB = sdm.MapDOFLocal(cell, i);
35
36 data_vector_local[imapB] = phi_old_local_[imapA];
37 } // for node
38 } // for cell
39
40 auto& ff_ptr = field_functions_.at(ff_index);
41 ff_ptr->UpdateFieldVector(data_vector_local);
42 }
43 // for (size_t g = 0; g < groups_.size(); ++g)
44 //{
45 // for (size_t m = 0; m < num_moments_; ++m)
46 // {
47 // std::vector<double> data_vector_local(local_node_count_, 0.0);
48 //
49 // for (const auto& cell : grid_ptr_->local_cells)
50 // {
51 // const auto& cell_mapping = sdm.GetCellMapping(cell);
52 // const size_t num_nodes = cell_mapping.NumNodes();
53 //
54 // for (size_t i = 0; i < num_nodes; ++i)
55 // {
56 // const int64_t imapA = sdm.MapDOFLocal(cell, i, phi_uk_man, m, g);
57 // const int64_t imapB = sdm.MapDOFLocal(cell, i);
58 //
59 // data_vector_local[imapB] = phi_old_local_[imapA];
60 // } // for node
61 // } // for cell
62 //
63 // ChiLogicalErrorIf(phi_field_functions_local_map_.count({g, m}) == 0,
64 // "Update error for phi based field functions");
65 //
66 // const size_t ff_index = phi_field_functions_local_map_.at({g, m});
67 //
68 // auto& ff_ptr = field_functions_.at(ff_index);
69 // ff_ptr->UpdateFieldVector(data_vector_local);
70 // } // for m
71 // } // for g
72
73 //======================================== Update power generation
74 // if enabled
76 {
77 std::vector<double> data_vector_local(local_node_count_, 0.0);
78
79 double local_total_power = 0.0;
80 for (const auto& cell : grid_ptr_->local_cells)
81 {
82 const auto& cell_mapping = sdm.GetCellMapping(cell);
83 const size_t num_nodes = cell_mapping.NumNodes();
84
85 const auto& Vi = unit_cell_matrices_[cell.local_id_].Vi_vectors;
86
87 const auto& xs = matid_to_xs_map_.at(cell.material_id_);
88
89 if (not xs->IsFissionable()) continue;
90
91 for (size_t i = 0; i < num_nodes; ++i)
92 {
93 const int64_t imapA = sdm.MapDOFLocal(cell, i);
94 const int64_t imapB = sdm.MapDOFLocal(cell, i, phi_uk_man, 0, 0);
95
96 double nodal_power = 0.0;
97 for (size_t g = 0; g < groups_.size(); ++g)
98 {
99 const double sigma_fg = xs->SigmaFission()[g];
100 // const double kappa_g = xs->Kappa()[g];
101 const double kappa_g = options_.power_default_kappa;
102
103 nodal_power += kappa_g * sigma_fg * phi_old_local_[imapB + g];
104 } // for g
105
106 data_vector_local[imapA] = nodal_power;
107 local_total_power += nodal_power * Vi[i];
108 } // for node
109 } // for cell
110
112 {
113 double globl_total_power;
114 MPI_Allreduce(&local_total_power, // sendbuf
115 &globl_total_power, // recvbuf
116 1,
117 MPI_DOUBLE, // count + datatype
118 MPI_SUM, // operation
119 Chi::mpi.comm); // communicator
120
121 chi_math::Scale(data_vector_local,
122 options_.power_normalization / globl_total_power);
123 }
124
125 const size_t ff_index = power_gen_fieldfunc_local_handle_;
126
127 auto& ff_ptr = field_functions_.at(ff_index);
128 ff_ptr->UpdateFieldVector(data_vector_local);
129
130 } // if power enabled
131}
132
133// ###################################################################
134/**Sets the internal phi vector to the value in the associated
135field function.*/
137 const std::vector<size_t>& m_indices,
138 const std::vector<size_t>& g_indices)
139{
140 std::vector<size_t> m_ids_to_copy = m_indices;
141 std::vector<size_t> g_ids_to_copy = g_indices;
142 if (m_indices.empty())
143 for (size_t m=0; m<num_moments_; ++m)
144 m_ids_to_copy.push_back(m);
145 if (g_ids_to_copy.empty())
146 for (size_t g=0; g<num_groups_; ++g)
147 g_ids_to_copy.push_back(g);
148
149 const auto& sdm = *discretization_;
150 const auto& phi_uk_man = flux_moments_uk_man_;
151
152 for (const size_t m : m_ids_to_copy)
153 {
154 for (const size_t g : g_ids_to_copy)
155 {
156 const size_t ff_index = phi_field_functions_local_map_.at({g,m});
157 auto& ff_ptr = field_functions_.at(ff_index);
158 auto& ff_data = ff_ptr->FieldVector();
159
160 for (const auto& cell : grid_ptr_->local_cells)
161 {
162 const auto& cell_mapping = sdm.GetCellMapping(cell);
163 const size_t num_nodes = cell_mapping.NumNodes();
164
165 for (size_t i = 0; i < num_nodes; ++i)
166 {
167 const int64_t imapA = sdm.MapDOFLocal(cell, i);
168 const int64_t imapB = sdm.MapDOFLocal(cell, i, phi_uk_man, m, g);
169
170 if (which_phi == PhiSTLOption::PHI_OLD)
171 phi_old_local_[imapB] = ff_data[imapA];
172 else if (which_phi == PhiSTLOption::PHI_NEW)
173 phi_new_local_[imapB] = ff_data[imapA];
174 } // for node
175 }//for cell
176 }//for g
177 }//for m
178
179}
180
181} // namespace lbs
static chi::MPI_Info & mpi
Definition: chi_runtime.h:78
std::vector< std::shared_ptr< FieldFunctionGridBased > > field_functions_
Definition: chi_solver.h:58
chi_mesh::MeshContinuumPtr grid_ptr_
Definition: lbs_solver.h:75
std::shared_ptr< chi_math::SpatialDiscretization > discretization_
Definition: lbs_solver.h:74
void SetPhiFromFieldFunctions(PhiSTLOption which_phi, const std::vector< size_t > &m_indices, const std::vector< size_t > &g_indices)
std::vector< UnitCellMatrices > unit_cell_matrices_
Definition: lbs_solver.h:81
std::vector< double > phi_new_local_
Definition: lbs_solver.h:95
std::vector< LBSGroup > groups_
Definition: lbs_solver.h:67
chi_math::UnknownManager flux_moments_uk_man_
Definition: lbs_solver.h:88
size_t power_gen_fieldfunc_local_handle_
Definition: lbs_solver.h:106
size_t num_groups_
Definition: lbs_solver.h:63
lbs::Options options_
Definition: lbs_solver.h:61
std::vector< double > phi_old_local_
Definition: lbs_solver.h:95
std::map< std::pair< size_t, size_t >, size_t > phi_field_functions_local_map_
Definition: lbs_solver.h:105
uint64_t local_node_count_
Definition: lbs_solver.h:91
std::map< int, XSPtr > matid_to_xs_map_
Definition: lbs_solver.h:71
size_t num_moments_
Definition: lbs_solver.h:62
void Scale(VecDbl &x, const double &val)
PhiSTLOption
Definition: lbs_structs.h:105
double power_normalization
Definition: lbs_structs.h:149
double power_default_kappa
Definition: lbs_structs.h:148
bool power_field_function_on
Definition: lbs_structs.h:147