Chi-Tech
lbsMIP_solver.cc
Go to the documentation of this file.
1#include "lbsMIP_solver.h"
2
3#include "ChiObjectFactory.h"
4
9
10namespace lbs
11{
12
14
15// ##################################################################
17{
19
20 params.SetClassName("DiffusionDFEMSolver");
21 params.SetDocGroup("lbs__LBSSolver");
22
23 params.ChangeExistingParamToOptional("name", "LBSDiffusionDFEMSolver");
24
25 return params;
26}
27
28// ##################################################################
30 const chi::InputParameters& params)
31 : LBSSolver(params)
32{
33}
34
35// ##################################################################
36/**Destructor to cleanup TGDSA*/
38{
39 for (auto& groupset : groupsets_)
40 CleanUpTGDSA(groupset);
41}
42
43// ##################################################################
44/**Initializing.*/
46{
47 options_.scattering_order = 0; // overwrite any setting otherwise
49
50 auto src_function = std::make_shared<SourceFunction>(*this);
51
52 // Initialize source func
53 using namespace std::placeholders;
55 std::bind(&SourceFunction::operator(), src_function, _1, _2, _3, _4);
56
57 //================================================== Initialize groupsets
58 // preconditioning
59 for (auto& groupset : groupsets_)
60 InitTGDSA(groupset);
61
63}
64
65// ##################################################################
66/**Initializes Within-GroupSet solvers.*/
68{
69 //============================================= Initialize groupset solvers
70 gs_mip_solvers_.assign(groupsets_.size(), nullptr);
71 const size_t num_groupsets = groupsets_.size();
72 for (size_t gs = 0; gs < num_groupsets; ++gs)
73 {
74 const auto& groupset = groupsets_[gs];
75
76 //=========================================== Make UnknownManager
77 const size_t gs_G = groupset.groups_.size();
80
81 //=========================================== Make boundary conditions
85
86 std::map<uint64_t, BC> bcs;
87 for (auto& [bid, lbs_bndry] : sweep_boundaries_)
88 {
89 if (lbs_bndry->Type() == SwpBndryType::REFLECTING)
90 bcs[bid] = {BCType::ROBIN, {0.0, 1.0, 0.0}};
91 else if (lbs_bndry->Type() == SwpBndryType::INCIDENT_ISOTROPIC_HOMOGENOUS)
92 {
93 const bool has_bndry_preference = boundary_preferences_.count(bid) > 0;
94 if (not has_bndry_preference) bcs[bid] = {BCType::ROBIN, {0.25, 0.5}};
95
96 const auto& bpref = boundary_preferences_.at(bid);
97 const bool is_vaccuum = bpref.type == BoundaryType::VACUUM;
98 if (is_vaccuum) bcs[bid] = {BCType::ROBIN, {0.25, 0.5}};
99 else
100 throw std::logic_error("Dirichlet boundary conditions not supported"
101 "for diffusion solvers.");
102 }
103 } // for sweep-boundary
104
105 //=========================================== Make xs map
107 typedef std::map<int, lbs::acceleration::Multigroup_D_and_sigR> MatID2XSMap;
108 MatID2XSMap matid_2_mgxs_map;
109 for (const auto& matid_xs_pair : matid_to_xs_map_)
110 {
111 const auto& mat_id = matid_xs_pair.first;
112 const auto& xs = matid_xs_pair.second;
113
114 const auto& diffusion_coeff = xs->DiffusionCoefficient();
115 const auto& sigma_r = xs->SigmaRemoval();
116
117 std::vector<double> Dg(gs_G, 0.0);
118 std::vector<double> sigR(gs_G, 0.0);
119
120 size_t g = 0;
121 for (size_t gprime = groupset.groups_.front().id_;
122 gprime <= groupset.groups_.back().id_;
123 ++gprime)
124 {
125 Dg[g] = diffusion_coeff[gprime];
126 sigR[g] = sigma_r[gprime];
127 ++g;
128 } // for g
129
130 matid_2_mgxs_map.insert(std::make_pair(mat_id, MGXS{Dg, sigR}));
131 }
132
133 //=========================================== Create solver
134 const auto& sdm = *discretization_;
135
136 auto solver = std::make_shared<acceleration::DiffusionMIPSolver>(
137 std::string(TextName() + "_WGSolver"),
138 sdm,
139 uk_man,
140 bcs,
141 matid_2_mgxs_map,
143 true); // verbosity
144
145 solver->options.residual_tolerance = groupset.wgdsa_tol_;
146 solver->options.max_iters = groupset.wgdsa_max_iters_;
147 solver->options.verbose = groupset.wgdsa_verbose_;
148 solver->options.additional_options_string = groupset.wgdsa_string_;
149
150 solver->Initialize();
151
152 std::vector<double> dummy_rhs(sdm.GetNumLocalDOFs(uk_man), 0.0);
153
154 solver->AssembleAand_b(dummy_rhs);
155
156 gs_mip_solvers_[gs] = solver;
157 } // for groupset
158
159 wgs_solvers_.clear(); // this is required
160 for (auto& groupset : groupsets_)
161 {
162
163 auto mip_wgs_context_ptr = std::make_shared<MIPWGSContext2<Mat, Vec, KSP>>(
164 *this,
165 groupset,
168 SUPPRESS_WG_SCATTER, // lhs_scope
170 APPLY_AGS_FISSION_SOURCES, // rhs_scope
172
173 auto wgs_solver =
174 std::make_shared<WGSLinearSolver<Mat, Vec, KSP>>(mip_wgs_context_ptr);
175
176 wgs_solvers_.push_back(wgs_solver);
177 } // for groupset
178}
179
180} // namespace lbs
void SetDocGroup(const std::string &doc_group)
void SetClassName(const std::string &class_name)
void ChangeExistingParamToOptional(const std::string &name, T value, const std::string &doc_string="")
unsigned int AddUnknown(UnknownType unk_type, unsigned int dimension=0)
std::string TextName() const
Definition: chi_solver.cc:116
std::vector< MIPSolverPtr > gs_mip_solvers_
Definition: lbsMIP_solver.h:15
void Initialize() override
void InitializeWGSSolvers() override
DiffusionDFEMSolver(const chi::InputParameters &params)
static chi::InputParameters GetInputParameters()
static chi::InputParameters GetInputParameters()
static void CleanUpTGDSA(LBSGroupset &groupset)
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::map< uint64_t, BoundaryPreference > boundary_preferences_
Definition: lbs_solver.h:85
lbs::Options options_
Definition: lbs_solver.h:61
void InitTGDSA(LBSGroupset &groupset)
void Initialize() override
std::vector< LBSGroupset > groupsets_
Definition: lbs_solver.h:68
virtual void InitializeSolverSchemes()
std::vector< LinSolvePtr > wgs_solvers_
Definition: lbs_solver.h:102
std::map< int, XSPtr > matid_to_xs_map_
Definition: lbs_solver.h:71
SetSourceFunction active_set_source_function_
Definition: lbs_solver.h:99
RegisterChiObject(lbs, DiffusionDFEMSolver)
@ APPLY_AGS_FISSION_SOURCES
Definition: lbs_structs.h:94
@ APPLY_WGS_FISSION_SOURCES
Definition: lbs_structs.h:93
@ APPLY_FIXED_SOURCES
Definition: lbs_structs.h:90
@ SUPPRESS_WG_SCATTER
Definition: lbs_structs.h:95
@ APPLY_WGS_SCATTER_SOURCES
Definition: lbs_structs.h:91
@ APPLY_AGS_SCATTER_SOURCES
Definition: lbs_structs.h:92
bool verbose_inner_iterations
Definition: lbs_structs.h:143
unsigned int scattering_order
Definition: lbs_structs.h:126