Chi-Tech
lbs_03d_wgdsa.cc
Go to the documentation of this file.
2
5
7
8// ###################################################################
9/**Initializes the Within-Group DSA solver. */
11 bool vaccum_bcs_are_dirichlet /*=true*/)
12{
13 if (groupset.apply_wgdsa_)
14 {
15 //=========================================== Make UnknownManager
16 const size_t num_gs_groups = groupset.groups_.size();
18 uk_man.AddUnknown(chi_math::UnknownType::VECTOR_N, num_gs_groups);
19
20 //=========================================== Make boundary conditions
22 vaccum_bcs_are_dirichlet);
23
24 //=========================================== Make xs map
25 auto matid_2_mgxs_map =
27 groupset.groups_.front().id_,
28 groupset.groups_.back().id_);
29
30 //=========================================== Create solver
31 const auto& sdm = *discretization_;
32
33 auto solver = std::make_shared<acceleration::DiffusionMIPSolver>(
34 std::string(TextName() + "_WGDSA"),
35 sdm,
36 uk_man,
37 bcs,
38 matid_2_mgxs_map,
40 true); // verbosity
42
43 solver->options.residual_tolerance = groupset.wgdsa_tol_;
44 solver->options.max_iters = groupset.wgdsa_max_iters_;
45 solver->options.verbose = groupset.wgdsa_verbose_;
46 solver->options.additional_options_string = groupset.wgdsa_string_;
47
48 solver->Initialize();
49
50 std::vector<double> dummy_rhs(sdm.GetNumLocalDOFs(uk_man), 0.0);
51
52 solver->AssembleAand_b(dummy_rhs);
53
54 groupset.wgdsa_solver_ = solver;
55 }
56}
57
58// ###################################################################
59/**Cleans up memory consuming items. */
61{
62 if (groupset.apply_wgdsa_) groupset.wgdsa_solver_ = nullptr;
63}
64
65// ###################################################################
66/**Creates a vector from a lbs primary stl vector where only the
67 * scalar moments are mapped to the DOFs needed by WGDSA.*/
68std::vector<double>
70 const std::vector<double>& phi_in)
71{
72 const auto& sdm = *discretization_;
73 const auto& dphi_uk_man = groupset.wgdsa_solver_->UnknownStructure();
74 const auto& phi_uk_man = flux_moments_uk_man_;
75
76 const int gsi = groupset.groups_.front().id_;
77 const size_t gss = groupset.groups_.size();
78
79 std::vector<double> output_phi_local(sdm.GetNumLocalDOFs(dphi_uk_man), 0.0);
80
81 for (const auto& cell : grid_ptr_->local_cells)
82 {
83 const auto& cell_mapping = sdm.GetCellMapping(cell);
84 const size_t num_nodes = cell_mapping.NumNodes();
85
86 for (size_t i = 0; i < num_nodes; i++)
87 {
88 const int64_t dphi_map = sdm.MapDOFLocal(cell, i, dphi_uk_man, 0, 0);
89 const int64_t phi_map = sdm.MapDOFLocal(cell, i, phi_uk_man, 0, gsi);
90
91 double* output_mapped = &output_phi_local[dphi_map];
92 const double* phi_in_mapped = &phi_in[phi_map];
93
94 for (size_t g = 0; g < gss; g++)
95 {
96 output_mapped[g] = phi_in_mapped[g];
97 } // for g
98 } // for node
99 } // for cell
100
101 return output_phi_local;
102}
103
104// ###################################################################
105/**From the WGDSA DOFs, projects the scalar moments back into a
106 * primary STL vector.*/
108 const std::vector<double>& input,
109 std::vector<double>& output)
110{
111 const auto& sdm = *discretization_;
112 const auto& dphi_uk_man = groupset.wgdsa_solver_->UnknownStructure();
113 const auto& phi_uk_man = flux_moments_uk_man_;
114
115 const int gsi = groupset.groups_.front().id_;
116 const size_t gss = groupset.groups_.size();
117
118 for (const auto& cell : grid_ptr_->local_cells)
119 {
120 const auto& cell_mapping = sdm.GetCellMapping(cell);
121 const size_t num_nodes = cell_mapping.NumNodes();
122
123 for (size_t i = 0; i < num_nodes; i++)
124 {
125 const int64_t dphi_map = sdm.MapDOFLocal(cell, i, dphi_uk_man, 0, 0);
126 const int64_t phi_map = sdm.MapDOFLocal(cell, i, phi_uk_man, 0, gsi);
127
128 const double* input_mapped = &input[dphi_map];
129 double* output_mapped = &output[phi_map];
130
131 for (int g = 0; g < gss; g++)
132 output_mapped[g] = input_mapped[g];
133 } // for dof
134 } // for cell
135}
136
137// ###################################################################
138/**Assembles a delta-phi vector on the first moment.*/
140 const LBSGroupset& groupset,
141 const std::vector<double>& phi_in,
142 std::vector<double>& delta_phi_local)
143{
144 const auto& sdm = *discretization_;
145 const auto& dphi_uk_man = groupset.wgdsa_solver_->UnknownStructure();
146 const auto& phi_uk_man = flux_moments_uk_man_;
147
148 const int gsi = groupset.groups_.front().id_;
149 const size_t gss = groupset.groups_.size();
150
151 delta_phi_local.clear();
152 delta_phi_local.assign(sdm.GetNumLocalDOFs(dphi_uk_man), 0.0);
153
154 for (const auto& cell : grid_ptr_->local_cells)
155 {
156 const auto& cell_mapping = sdm.GetCellMapping(cell);
157 const size_t num_nodes = cell_mapping.NumNodes();
158 const auto& sigma_s = matid_to_xs_map_[cell.material_id_]->SigmaSGtoG();
159
160 for (size_t i = 0; i < num_nodes; i++)
161 {
162 const int64_t dphi_map = sdm.MapDOFLocal(cell, i, dphi_uk_man, 0, 0);
163 const int64_t phi_map = sdm.MapDOFLocal(cell, i, phi_uk_man, 0, gsi);
164
165 double* delta_phi_mapped = &delta_phi_local[dphi_map];
166 const double* phi_in_mapped = &phi_in[phi_map];
167
168 for (size_t g = 0; g < gss; g++)
169 {
170 delta_phi_mapped[g] = sigma_s[gsi + g] * phi_in_mapped[g];
171 } // for g
172 } // for node
173 } // for cell
174}
175
176// ###################################################################
177/**DAssembles a delta-phi vector on the first moment.*/
179 const LBSGroupset& groupset,
180 const std::vector<double>& delta_phi_local,
181 std::vector<double>& ref_phi_new)
182{
183 const auto& sdm = *discretization_;
184 const auto& dphi_uk_man = groupset.wgdsa_solver_->UnknownStructure();
185 const auto& phi_uk_man = flux_moments_uk_man_;
186
187 const int gsi = groupset.groups_.front().id_;
188 const size_t gss = groupset.groups_.size();
189
190 for (const auto& cell : grid_ptr_->local_cells)
191 {
192 const auto& cell_mapping = sdm.GetCellMapping(cell);
193 const size_t num_nodes = cell_mapping.NumNodes();
194
195 for (size_t i = 0; i < num_nodes; i++)
196 {
197 const int64_t dphi_map = sdm.MapDOFLocal(cell, i, dphi_uk_man, 0, 0);
198 const int64_t phi_map = sdm.MapDOFLocal(cell, i, phi_uk_man, 0, gsi);
199
200 const double* delta_phi_mapped = &delta_phi_local[dphi_map];
201 double* phi_new_mapped = &ref_phi_new[phi_map];
202
203 for (int g = 0; g < gss; g++)
204 phi_new_mapped[g] += delta_phi_mapped[g];
205 } // for dof
206 } // for cell
207}
unsigned int AddUnknown(UnknownType unk_type, unsigned int dimension=0)
std::string TextName() const
Definition: chi_solver.cc:116
std::shared_ptr< lbs::acceleration::DiffusionMIPSolver > wgdsa_solver_
Definition: lbs_groupset.h:72
std::string wgdsa_string_
Definition: lbs_groupset.h:69
std::vector< LBSGroup > groups_
Definition: lbs_groupset.h:41
void DisAssembleWGDSADeltaPhiVector(const LBSGroupset &groupset, const std::vector< double > &delta_phi_local, std::vector< double > &ref_phi_new)
std::shared_ptr< chi_math::SpatialDiscretization > discretization_
Definition: lbs_solver.h:74
std::vector< UnitCellMatrices > unit_cell_matrices_
Definition: lbs_solver.h:81
std::map< uint64_t, std::shared_ptr< SweepBndry > > sweep_boundaries_
Definition: lbs_solver.h:86
std::vector< double > WGSCopyOnlyPhi0(const LBSGroupset &groupset, const std::vector< double > &phi_in)
void InitWGDSA(LBSGroupset &groupset, bool vaccum_bcs_are_dirichlet=true)
void AssembleWGDSADeltaPhiVector(const LBSGroupset &groupset, const std::vector< double > &phi_in, std::vector< double > &delta_phi_local)
static void CleanUpWGDSA(LBSGroupset &groupset)
void GSProjectBackPhi0(const LBSGroupset &groupset, const std::vector< double > &input, std::vector< double > &output)
std::map< int, XSPtr > matid_to_xs_map_
Definition: lbs_solver.h:71
std::map< int, Multigroup_D_and_sigR > PackGroupsetXS(const std::map< int, MGXSPtr > &matid_to_xs_map, int first_grp_index, int last_group_index)
Definition: acceleration.cc:37
std::map< uint64_t, BoundaryCondition > TranslateBCs(const std::map< uint64_t, SwpBndryPtr > &sweep_boundaries, bool vaccum_bcs_are_dirichlet)
Definition: acceleration.cc:12