Chi-Tech
lbs_00a_setoptions.cc
Go to the documentation of this file.
1#include "lbs_solver.h"
2
3#include "ChiObjectFactory.h"
4
5namespace lbs
6{
7
8// ##################################################################
9RegisterSyntaxBlock(/*namespace_name=*/lbs,
10 /*block_name=*/OptionsBlock,
11 /*syntax_function=*/LBSSolver::OptionsBlock);
12
14{
16
17 params.SetGeneralDescription("Set options from a large list of parameters");
18 params.SetDocGroup("LBSUtilities");
19
20 // clang-format off
21 params.AddOptionalParameter("spatial_discretization", "pwld",
22 "What spatial discretization to use. Currently only `\"pwld\"` "
23 "is supported");
24 params.AddOptionalParameter("scattering_order",1,
25 "Defines the level of harmonic expansion for the scattering source.");
26 params.AddOptionalParameter("sweep_eager_limit",32'000,
27 "The eager limit to be used in message size during sweep initialization.\n"
28 " This expects to be followed by a size in bytes (Max 64,0000)See note below."
29 "\\n\\n"
30 " ###Note on the Eager limit\n"
31 "The eager limit is the message size limit before which non-blocking MPI send"
32 "calls will execute without waiting for a matching receive call. The limit is"
33 "platform dependent but in general 64 kb. Some systems have 32 kb as a limit"
34 "and therefore we use that as a default limit in ChiTech. There is a fine"
35 "interplay between message size and the shear amount of messages that will be"
36 "sent. In general smaller messages tend to be more efficient, however, when"
37 "there are too many small messages being sent around the communication system"
38 "on the given platform will start to suffer. One can gain a small amount of"
39 "parallel efficiency by lowering this limit, however, there is a point where"
40 "the parallel efficiency will actually get worse so use with caution.");
41 params.AddOptionalParameter("read_restart_data",false,
42 "Flag indicating whether restart data is to be read.");
43 params.AddOptionalParameter("read_restart_folder_name","YRestart",
44 "Folder name to use when reading restart data.");
45 params.AddOptionalParameter("read_restart_file_base","restart",
46 "File base name to use when reading restart data.");
47 params.AddOptionalParameter("write_restart_data",false,
48 "Flag indicating whether restart data is to be written.");
49 params.AddOptionalParameter("write_restart_folder_name","YRestart",
50 "Folder name to use when writing restart data.");
51 params.AddOptionalParameter("write_restart_file_base","restart",
52 "File base name to use when writing restart data.");
53 params.AddOptionalParameter("write_restart_interval",30.0,
54 "Interval at which restart data is to be written. Currently not implemented.");
55 params.AddOptionalParameter("use_precursors",false,
56 "Flag for using delayed neutron precursors.");
57 params.AddOptionalParameter("use_source_moments",false,
58 "Flag for ignoring fixed sources and selectively using source moments "
59 "obtained elsewhere.");
60 params.AddOptionalParameter("save_angular_flux",false,
61 "Flag indicating whether angular fluxes are to be stored or not.");
62 params.AddOptionalParameter("verbose_inner_iterations",true,
63 "Flag to control verbosity of inner iterations.");
64 params.AddOptionalParameter("verbose_outer_iterations",true,
65 "Flag to control verbosity of across-groupset iterations.");
66 params.AddOptionalParameter("verbose_ags_iterations",false,
67 "Flag to control verbosity of across-groupset iterations.");
68 params.AddOptionalParameter("power_field_function_on",false,
69 "Flag to control the creation of the power generation field function. If set "
70 "to `true` then a field function will be created with the general name "
71 "`<solver_name>_power_generation`.");
72 params.AddOptionalParameter("power_default_kappa",3.20435e-11,
73 "Default `kappa` value (Energy released per fission) to use for power "
74 "generation when cross sections do not have `kappa` values. Default: "
75 "3.20435e-11 Joule (corresponding to 200 MeV per fission).");
76 params.AddOptionalParameter("power_normalization",-1.0,
77 "Power normalization factor to use. Supply a negative or zero number to turn "
78 "this off.");
79 params.AddOptionalParameter("field_function_prefix_option","prefix",
80 "Prefix option on field function names. Default: `\"prefix\"`. Can be "
81 "`\"prefix\"` or "
82 "`\"solver_name\"`. "
83 "By default this option is `\"prefix\"` which means it uses the designated "
84 "\"prefix\" (another option), however, that is defaulted to nothing. "
85 "Therefore, default behavior is to export flux moment fields functions as "
86 "`phi_gXXX_mYYY` where `XXX` is the zero padded 3 digit group number and "
87 "similarly for `YYY`.");
88 params.AddOptionalParameter("field_function_prefix","",
89 "Prefix to use on all field functions. Default: `\"\"`. "
90 "By default this option is empty but if specified then flux moments will "
91 "exported as `prefix_phi_gXXX_mYYY` where `XXX` is the zero padded 3 digit "
92 "group number and similarly for `YYY`. The underscore after \"prefix\" is "
93 "added automatically.");
94 params.AddOptionalParameterArray("boundary_conditions",
95 {},
96 "A table contain sub-tables for each boundary specification.");
97 params.LinkParameterToBlock("boundary_conditions",
98 "lbs::BoundaryOptionsBlock");
99
100 using namespace chi_data_types;
101 params.ConstrainParameterRange("spatial_discretization",
102 AllowableRangeList::New({"pwld"}));
103
104 params.ConstrainParameterRange("field_function_prefix_option",
105 AllowableRangeList::New({"prefix", "solver_name"}));
106 // clang-format on
107
108 return params;
109}
110
111// ##################################################################
112RegisterSyntaxBlock(/*namespace_in_lua=*/lbs,
113 /*name_in_lua=*/BoundaryOptionsBlock,
114 /*syntax_function=*/LBSSolver::BoundaryOptionsBlock);
115
117{
119
120 // clang-format off
122 "Set options for boundary conditions. See \\ref LBSBCs");
123 params.SetDocGroup("LBSUtilities");
124
125 params.AddRequiredParameter<std::string>("name",
126 "Boundary name that identifies the specific boundary");
127 params.AddRequiredParameter<std::string>("type",
128 "Boundary type specification.");
129
130 params.AddOptionalParameterArray<double>("group_strength", {},
131 "Required only if `type` is `\"incident_isotropic\"`. An array of isotropic "
132 "strength per group");
133
134 params.AddOptionalParameter("function_name", "",
135 "Text name of the lua function to be called for this boundary condition. For"
136 " more on this boundary condition type.");
137
138 using namespace chi_data_types;
139 params.ConstrainParameterRange("name", AllowableRangeList::New({
140 "xmin", "xmax", "ymin", "ymax", "zmin", "zmax"}));
141
142 params.ConstrainParameterRange("type", AllowableRangeList::New({
143 "vacuum", "incident_isotropic", "reflecting",
144 "incident_anisotropic_heterogeneous"}));
145 // clang-format on
146
147 return params;
148}
149
150// ##################################################################
152{
153 const auto& user_params = params.ParametersAtAssignment();
154
155 for (size_t p = 0; p < user_params.NumParameters(); ++p)
156 {
157 const auto& spec = user_params.GetParam(p);
158
159 if (spec.Name() == "spatial_discretization")
160 {
161 auto sdm_name = spec.GetValue<std::string>();
162 if (sdm_name == "pwld")
163 Options().sd_type =
165 }
166
167 else if (spec.Name() == "scattering_order")
168 Options().scattering_order = spec.GetValue<int>();
169
170 else if (spec.Name() == "sweep_eager_limit")
171 Options().sweep_eager_limit = spec.GetValue<int>();
172
173 else if (spec.Name() == "read_restart_data")
174 Options().read_restart_data = spec.GetValue<bool>();
175
176 else if (spec.Name() == "read_restart_folder_name")
178 spec.GetValue<std::string>();
179
180 else if (spec.Name() == "read_restart_file_base")
182 spec.GetValue<std::string>();
183
184 else if (spec.Name() == "write_restart_data")
185 Options().write_restart_data = spec.GetValue<bool>();
186
187 else if (spec.Name() == "write_restart_folder_name")
189 spec.GetValue<std::string>();
190
191 else if (spec.Name() == "write_restart_file_base")
193 spec.GetValue<std::string>();
194
195 else if (spec.Name() == "write_restart_interval")
196 Options().write_restart_interval = spec.GetValue<double>();
197
198 else if (spec.Name() == "use_precursors")
199 Options().use_precursors = spec.GetValue<bool>();
200
201 else if (spec.Name() == "use_source_moments")
202 Options().use_src_moments = spec.GetValue<bool>();
203
204 else if (spec.Name() == "save_angular_flux")
205 Options().save_angular_flux = spec.GetValue<bool>();
206
207 else if (spec.Name() == "verbose_inner_iterations")
208 Options().verbose_inner_iterations = spec.GetValue<bool>();
209
210 else if (spec.Name() == "verbose_ags_iterations")
211 Options().verbose_ags_iterations = spec.GetValue<bool>();
212
213 else if (spec.Name() == "verbose_outer_iterations")
214 Options().verbose_outer_iterations = spec.GetValue<bool>();
215
216 else if (spec.Name() == "power_field_function_on")
217 Options().power_field_function_on = spec.GetValue<bool>();
218
219 else if (spec.Name() == "power_default_kappa")
220 Options().power_default_kappa = spec.GetValue<double>();
221
222 else if (spec.Name() == "power_normalization")
223 Options().power_normalization = spec.GetValue<double>();
224
225 else if (spec.Name() == "field_function_prefix_option")
226 {
228 spec.GetValue<std::string>();
229 }
230
231 else if (spec.Name() == "field_function_prefix")
232 Options().field_function_prefix = spec.GetValue<std::string>();
233
234 else if (spec.Name() == "boundary_conditions")
235 {
236 spec.RequireBlockTypeIs(chi::ParameterBlockType::ARRAY);
237
238 for (size_t b = 0; b < spec.NumParameters(); ++b)
239 {
240 auto bndry_params = BoundaryOptionsBlock();
241 bndry_params.AssignParameters(spec.GetParam(b));
242
243 SetBoundaryOptions(bndry_params);
244 }
245 }
246 } // for p
247}
248
249// ##################################################################
251{
252 const std::string fname = __FUNCTION__;
253 const auto& user_params = params.ParametersAtAssignment();
254 const auto boundary_name = user_params.GetParamValue<std::string>("name");
255 const auto bndry_type = user_params.GetParamValue<std::string>("type");
256
257 const std::map<std::string, uint64_t> supported_bndry_names = {{"xmin", 1},
258 {"xmax", 0},
259 {"ymin", 3},
260 {"ymax", 2},
261 {"zmin", 5},
262 {"zmax", 4}};
263 const auto bid = supported_bndry_names.at(boundary_name);
264 const std::map<std::string, lbs::BoundaryType> type_list = {
265 {"vacuum", BoundaryType::VACUUM},
266 {"incident_isotropic", BoundaryType::INCIDENT_ISOTROPIC},
267 {"reflecting", BoundaryType::REFLECTING},
268 {"incident_anisotropic_heterogeneous",
270
271 const auto type = type_list.at(bndry_type);
272 switch (type)
273 {
276 {
277 BoundaryPreferences()[bid] = {type};
278 break;
279 }
281 {
282 if (not user_params.Has("group_strength"))
283 {
284 std::string message = fname;
285 message += ":boundary_conditions:"
286 "type=\"incident_isotropic\" requires parameter "
287 "\"group_strength\".";
288
289 throw std::invalid_argument(message);
290 }
291 user_params.RequireParameterBlockTypeIs(
292 "group_strength",
294
295 const auto group_strength =
296 user_params.GetParamVectorValue<double>("group_strength");
297 BoundaryPreferences()[bid] = {type, group_strength};
298 break;
299 }
301 {
302 if (not user_params.Has("function_name"))
303 {
304 std::string message = fname;
305 message += ":boundary_conditions:"
306 "type=\"incident_anisotropic_heterogeneous\" requires "
307 "parameter \"function_name\".";
308
309 throw std::invalid_argument(message);
310 }
311 const auto bndry_function_name =
312 user_params.GetParamValue<std::string>("function_name");
313
314 BoundaryPreferences()[bid] = {type, {}, bndry_function_name};
315 break;
316 }
317 }
318}
319
320}
void SetDocGroup(const std::string &doc_group)
void AddRequiredParameter(const std::string &name, const std::string &doc_string)
const ParameterBlock & ParametersAtAssignment() const
void ConstrainParameterRange(const std::string &param_name, AllowableRangePtr allowable_range)
void AddOptionalParameter(const std::string &name, T value, const std::string &doc_string)
void SetGeneralDescription(const std::string &description)
void LinkParameterToBlock(const std::string &param_name, const std::string &block_name)
void AddOptionalParameterArray(const std::string &name, const std::vector< T > &array, const std::string &doc_string)
T GetParamValue(const std::string &param_name) const
ParameterBlock & GetParam(const std::string &param_name)
void SetBoundaryOptions(const chi::InputParameters &params)
std::map< uint64_t, BoundaryPreference > & BoundaryPreferences()
static chi::InputParameters BoundaryOptionsBlock()
lbs::Options & Options()
static chi::InputParameters OptionsBlock()
void SetOptions(const chi::InputParameters &params)
@ INCIDENT_ANISTROPIC_HETEROGENEOUS
RegisterSyntaxBlock(lbs, OptionsBlock, LBSSolver::OptionsBlock)
std::string write_restart_file_base
Definition: lbs_structs.h:135
int sweep_eager_limit
Definition: lbs_structs.h:127
bool use_src_moments
Definition: lbs_structs.h:139
bool verbose_inner_iterations
Definition: lbs_structs.h:143
std::string read_restart_file_base
Definition: lbs_structs.h:131
std::string write_restart_folder_name
Definition: lbs_structs.h:134
std::string field_function_prefix_option
Definition: lbs_structs.h:151
double power_normalization
Definition: lbs_structs.h:149
bool verbose_ags_iterations
Definition: lbs_structs.h:144
bool verbose_outer_iterations
Definition: lbs_structs.h:145
bool read_restart_data
Definition: lbs_structs.h:129
std::string field_function_prefix
Definition: lbs_structs.h:152
bool write_restart_data
Definition: lbs_structs.h:133
double power_default_kappa
Definition: lbs_structs.h:148
unsigned int scattering_order
Definition: lbs_structs.h:126
double write_restart_interval
Definition: lbs_structs.h:136
bool use_precursors
Definition: lbs_structs.h:138
SDMType sd_type
Definition: lbs_structs.h:125
bool save_angular_flux
Definition: lbs_structs.h:141
std::string read_restart_folder_name
Definition: lbs_structs.h:130
bool power_field_function_on
Definition: lbs_structs.h:147