https://mooseframework.inl.gov
Loading...
Searching...
No Matches
BatchMeshGeneratorAction.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10// MOOSE includes
12#include "ActionFactory.h"
13
14#include "MooseMesh.h"
15#include "MeshGenerator.h"
16#include "Factory.h"
17#include "MooseApp.h"
18#include "MooseUtils.h"
19
20#include "hit/hit.h"
21
22registerMooseAction("MooseApp", BatchMeshGeneratorAction, "add_mesh_generator");
23
26{
28
29 params.set<std::string>("type") = "BatchMeshGeneratorAction";
30
31 params.addClassDescription("Batch generate meshes using actions.");
32 params.addRequiredParam<std::string>("mesh_generator_type",
33 "Type of the mesh generator to be batch generated.");
34 params.addRequiredParam<std::string>("mesh_name_prefix",
35 "Prefix name of the meshes to be batch generated.");
36
37 params.addParam<std::vector<std::string>>("batch_scalar_input_param_names",
38 std::vector<std::string>(),
39 "Names of the scalar input parameters to be altered.");
40 MultiMooseEnum default_types(
41 "BOOL REAL SHORT USHORT INT UINT LONG ULONG LONGLONG ULONGLONG DOFIDTYPE BDRYIDTYPE SDIDTYPE "
42 "STRING SDNAME BDRYNAME MGNAME MFNAME ENUM REALVECTORVALUE POINT",
43 "");
45 "batch_scalar_input_param_types",
46 default_types,
47 "Types of the scalar input parameters to be altered in each generator of the batch.");
48 params.addParam<std::vector<std::vector<std::string>>>(
49 "batch_scalar_input_param_values",
50 {},
51 "Values of the scalar input parameters to be assigned.");
52
53 params.addParam<std::vector<std::string>>("batch_vector_input_param_names",
54 std::vector<std::string>(),
55 "Name of the vector input parameters to be altered.");
56 params.addParam<MultiMooseEnum>("batch_vector_input_param_types",
57 default_types,
58 "Type of the vector input parameters to be altered.");
59 params.addParam<std::vector<std::vector<std::vector<std::string>>>>(
60 "batch_vector_input_param_values",
61 {},
62 "Values of the vector input parameters to be assigned.");
63
64 MooseEnum multi_batch_params_method("corresponding cartesian_product", "cartesian_product");
65 params.addParam<MooseEnum>("multi_batch_params_method",
66 multi_batch_params_method,
67 "Method to generate multiple batch parameters.Options: " +
68 multi_batch_params_method.getRawNames());
69
70 params.addParam<std::vector<std::string>>(
71 "fixed_scalar_input_param_names", {}, "Names of the input parameters to be fixed.");
72 params.addParam<MultiMooseEnum>("fixed_scalar_input_param_types",
73 default_types,
74 "Types of the input parameters to be fixed.");
75 params.addParam<std::vector<std::string>>(
76 "fixed_scalar_input_param_values", {}, "Values of the input parameters to be fixed.");
77 params.addParam<std::vector<std::string>>(
78 "fixed_vector_input_param_names", {}, "Names of the input vector parameters to be fixed.");
79 params.addParam<MultiMooseEnum>("fixed_vector_input_param_types",
80 default_types,
81 "Types of the input vector parameters to be fixed.");
82 params.addParam<std::vector<std::vector<std::string>>>(
83 "fixed_vector_input_param_values", {}, "Values of the input vector parameters to be fixed.");
84 params.addParam<bool>("use_decomposed_index",
85 false,
86 "Whether to use the decomposed index for the mesh name (only effective for "
87 "the cartesian_product method).");
88
89 params.addParamNamesToGroup("batch_scalar_input_param_names batch_scalar_input_param_types "
90 "batch_scalar_input_param_values "
91 "batch_vector_input_param_names batch_vector_input_param_types "
92 "batch_vector_input_param_values",
93 "Batch Input");
94 params.addParamNamesToGroup("fixed_scalar_input_param_names fixed_scalar_input_param_types "
95 "fixed_scalar_input_param_values "
96 "fixed_vector_input_param_names fixed_vector_input_param_types "
97 "fixed_vector_input_param_values",
98 "Fixed Input");
99
100 return params;
101}
102
104 : Action(params),
106 _mesh_generator_type(getParam<std::string>("mesh_generator_type")),
107 _mesh_name_prefix(getParam<std::string>("mesh_name_prefix")),
108 _batch_scalar_input_param_names(
109 getParam<std::vector<std::string>>("batch_scalar_input_param_names")),
110 _batch_scalar_input_param_types(isParamValid("batch_scalar_input_param_types")
111 ? getParam<MultiMooseEnum>("batch_scalar_input_param_types")
112 .template getSetValueIDs<ParameterType>()
113 : std::vector<ParameterType>()),
114 _batch_scalar_input_param_values(
115 getParam<std::vector<std::vector<std::string>>>("batch_scalar_input_param_values")),
116 _batch_vector_input_param_names(
117 getParam<std::vector<std::string>>("batch_vector_input_param_names")),
118 _batch_vector_input_param_types(isParamValid("batch_vector_input_param_types")
119 ? getParam<MultiMooseEnum>("batch_vector_input_param_types")
120 .template getSetValueIDs<ParameterType>()
121 : std::vector<ParameterType>()),
122 _batch_vector_input_param_values(getParam<std::vector<std::vector<std::vector<std::string>>>>(
123 "batch_vector_input_param_values")),
124 _multi_batch_params_method(getParam<MooseEnum>("multi_batch_params_method")
125 .template getEnum<MultiBatchParamsMethod>()),
126 _fixed_scalar_input_param_names(
127 getParam<std::vector<std::string>>("fixed_scalar_input_param_names")),
128 _fixed_scalar_input_param_types(isParamValid("fixed_scalar_input_param_types")
129 ? getParam<MultiMooseEnum>("fixed_scalar_input_param_types")
130 .template getSetValueIDs<ParameterType>()
131 : std::vector<ParameterType>()),
132 _fixed_scalar_input_param_values(
133 getParam<std::vector<std::string>>("fixed_scalar_input_param_values")),
134 _fixed_vector_input_param_names(
135 getParam<std::vector<std::string>>("fixed_vector_input_param_names")),
136 _fixed_vector_input_param_types(isParamValid("fixed_vector_input_param_types")
137 ? getParam<MultiMooseEnum>("fixed_vector_input_param_types")
138 .template getSetValueIDs<ParameterType>()
139 : std::vector<ParameterType>()),
140 _fixed_vector_input_param_values(
141 getParam<std::vector<std::vector<std::string>>>("fixed_vector_input_param_values")),
142 _use_decomposed_index(getParam<bool>("use_decomposed_index"))
143{
144 // Sanity check for the fixed input parameters
145 checkVectorParamAndMultiMooseEnumLength<std::string>("fixed_scalar_input_param_names",
146 "fixed_scalar_input_param_types");
147 const auto fixed_scalar_real_compound_num =
148 std::count_if(_fixed_scalar_input_param_types.begin(),
150 [this](const ParameterType & type) { return isCompoundRealScalarType(type); });
151 if (fixed_scalar_real_compound_num > 0)
152 {
154 (Moose::dim - 1) * fixed_scalar_real_compound_num !=
156 paramError("fixed_scalar_input_param_values",
157 "This parameter must have a size that is consistent with "
158 "fixed_scalar_input_param_names. Note that each REALVECTORVALUE or POINT type "
159 "parameter must be represented as ",
160 std::to_string(Moose::dim),
161 " separate values instead of 1.");
162 // Rearrange _fixed_scalar_input_param_values so that each compound real scalar value is in one
163 // single string
164 auto fixed_scalar_input_param_values_tmp(_fixed_scalar_input_param_values);
166 unsigned int raw_value_ct = 0;
167 for (const auto i : index_range(_fixed_scalar_input_param_types))
168 {
170 {
171 // In that case, the string element needs to contain three elements separated by spaces
172 _fixed_scalar_input_param_values[i] = MooseUtils::join(
173 fixed_scalar_input_param_values_tmp.begin() + raw_value_ct,
174 fixed_scalar_input_param_values_tmp.begin() + raw_value_ct + Moose::dim,
175 " ");
176 raw_value_ct += Moose::dim;
177 }
178 else
179 {
180 _fixed_scalar_input_param_values[i] = fixed_scalar_input_param_values_tmp[raw_value_ct];
181 raw_value_ct += 1;
182 }
183 }
184 }
185 else
186 checkVectorParamsSameLength<std::string, std::string>("fixed_scalar_input_param_names",
187 "fixed_scalar_input_param_values");
188
189 checkVectorParamAndMultiMooseEnumLength<std::string>("fixed_vector_input_param_names",
190 "fixed_vector_input_param_types");
191 // The compound real scalar value type does not alter the length of
192 // 'fixed_vector_input_param_values'
193 checkVectorParamsSameLength<std::string, std::vector<std::string>>(
194 "fixed_vector_input_param_names", "fixed_vector_input_param_values");
195 // But we still need to process the affected elements
196 for (const auto i : index_range(_fixed_vector_input_param_types))
197 {
199 {
200 // Ensure that each compound real scalar value is represented as Moose::dim Real values
201 if (_fixed_vector_input_param_values[i].size() % Moose::dim != 0)
202 paramError("fixed_vector_input_param_values",
203 "This parameter must have a size that is consistent with "
204 "fixed_vector_input_param_names. Note that each REALVECTORVALUE or POINT type "
205 "parameter must be represented as ",
206 std::to_string(Moose::dim),
207 " separate values instead of 1.");
208 auto unit_fixed_vector_input_param_values_tmp(_fixed_vector_input_param_values[i]);
209 _fixed_vector_input_param_values[i].resize(unit_fixed_vector_input_param_values_tmp.size() /
210 Moose::dim);
211 for (const auto j : index_range(_fixed_vector_input_param_values[i]))
212 _fixed_vector_input_param_values[i][j] = MooseUtils::join(
213 unit_fixed_vector_input_param_values_tmp.begin() + j * Moose::dim,
214 unit_fixed_vector_input_param_values_tmp.begin() + j * Moose::dim + Moose::dim,
215 " ");
216 }
217 }
218
219 // Sanity check for the batch input parameters
220 checkVectorParamAndMultiMooseEnumLength<std::string>("batch_scalar_input_param_names",
221 "batch_scalar_input_param_types");
222 // The compound real scalar value type does not alter the length of
223 // 'batch_scalar_input_param_values'
224 checkVectorParamsSameLength<std::string, std::vector<std::string>>(
225 "batch_scalar_input_param_names", "batch_scalar_input_param_values");
226 // But we still need to process the affected elements
227 for (const auto i : index_range(_batch_scalar_input_param_types))
228 {
230 {
231 // Ensure that each compound real scalar value is represented as Moose::dim Real values
232 if (_batch_scalar_input_param_values[i].size() % Moose::dim != 0)
233 paramError("batch_scalar_input_param_values",
234 "This parameter must have a size that is consistent with "
235 "batch_scalar_input_param_names. Note that each REALVECTORVALUE or POINT type "
236 "parameter must be represented as ",
237 std::to_string(Moose::dim),
238 " separate values instead of 1.");
239 auto unit_batch_scalar_input_param_values_tmp(_batch_scalar_input_param_values[i]);
240 _batch_scalar_input_param_values[i].resize(unit_batch_scalar_input_param_values_tmp.size() /
241 3);
242 for (const auto j : index_range(_batch_scalar_input_param_values[i]))
243 _batch_scalar_input_param_values[i][j] = MooseUtils::join(
244 unit_batch_scalar_input_param_values_tmp.begin() + j * Moose::dim,
245 unit_batch_scalar_input_param_values_tmp.begin() + j * Moose::dim + Moose::dim,
246 " ");
247 }
248 }
249
250 checkVectorParamAndMultiMooseEnumLength<std::string>("batch_vector_input_param_names",
251 "batch_vector_input_param_types");
253 checkVectorParamsSameLength<std::string, std::vector<std::vector<std::string>>>(
254 "batch_vector_input_param_names", "batch_vector_input_param_values");
255 // But we still need to process the affected elements
256 for (const auto i : index_range(_batch_vector_input_param_types))
257 {
259 {
260 for (const auto j : index_range(_batch_vector_input_param_values[i]))
261 {
262 // Ensure that each compound real scalar value is represented as Moose::dim Real values
263 if (_batch_vector_input_param_values[i][j].size() % Moose::dim != 0)
264 paramError("batch_vector_input_param_values",
265 "This parameter must have a size that is consistent with "
266 "batch_vector_input_param_names. Note that each REALVECTORVALUE or POINT type "
267 "parameter must be represented as ",
269 " separate values instead of 1.");
270 auto unit_batch_vector_input_param_values_tmp(_batch_vector_input_param_values[i][j]);
272 unit_batch_vector_input_param_values_tmp.size() / 3);
273 for (const auto k : index_range(_batch_vector_input_param_values[i][j]))
274 _batch_vector_input_param_values[i][j][k] = MooseUtils::join(
275 unit_batch_vector_input_param_values_tmp.begin() + k * Moose::dim,
276 unit_batch_vector_input_param_values_tmp.begin() + k * Moose::dim + Moose::dim,
277 " ");
278 }
279 }
280 }
281
282 // At least we want this action to create one mesh generator
284 mooseError("BatchMeshGeneratorAction: " + _name +
285 ", batch_scalar_input_param_names and batch_vector_input_param_names cannot be "
286 "empty at the same time.");
287
288 // If the previous check is passed, batch_params_sizes will not be empty
289 // But we need to check if any element of the batch_params_values are empty
290 std::set<unsigned int> batch_params_sizes;
291 for (const auto & unit_batch_scalar_param_values : _batch_scalar_input_param_values)
292 {
293 if (unit_batch_scalar_param_values.empty())
294 paramError("batch_scalar_input_param_values",
295 "this parameter cannot contain empty elements.");
296 batch_params_sizes.emplace(unit_batch_scalar_param_values.size());
297 }
298 for (const auto & unit_batch_vector_param_values : _batch_vector_input_param_values)
299 {
300 if (unit_batch_vector_param_values.empty())
301 paramError("batch_vector_input_param_values",
302 "this parameter cannot contain empty elements.");
303 batch_params_sizes.emplace(unit_batch_vector_param_values.size());
304 }
305
306 // Then for the corresponding method, the sizes of the batch_params_values should be the same
308 batch_params_sizes.size() > 1)
309 mooseError("BatchMeshGeneratorAction: " + _name +
310 ", elements of batch_scalar_input_param_values and batch_vector_input_param_values "
311 "must have the same size in corresponding mode.");
312
313 // Decomposed index cannot be used with the corresponding method
315 paramError("use_decomposed_index",
316 "Decomposed index cannot be used with the corresponding method.");
317 // Check the parameter types are given correctly here so that we do not need to do it when setting
318 // the values.
320 // batch scalar input parameters
321 checkInputParametersTypes(set_params,
322 "batch_scalar_input_param_names",
325 // fix scalar input parameters
326 checkInputParametersTypes(set_params,
327 "fixed_scalar_input_param_names",
330 // batch vector input parameters
331 checkInputParametersTypes(set_params,
332 "batch_vector_input_param_names",
335 true);
336 // fix vector input parameters
337 checkInputParametersTypes(set_params,
338 "fixed_vector_input_param_names",
341 true);
342}
343
344void
346{
347 if (_current_task == "add_mesh_generator")
349}
350
351void
353{
354 std::vector<std::vector<std::string>> processed_batch_scalar_input_param_values;
355 std::vector<std::vector<std::vector<std::string>>> processed_batch_vector_input_param_values;
356 // generate the decomposed indices for the cartesian product method
357 std::vector<std::vector<unsigned int>> processed_batch_indices;
359 {
360 processed_batch_scalar_input_param_values = _batch_scalar_input_param_values;
361 processed_batch_vector_input_param_values = _batch_vector_input_param_values;
363 {
364 processed_batch_indices.push_back(std::vector<unsigned int>(
365 processed_batch_vector_input_param_values.empty()
366 ? processed_batch_scalar_input_param_values.front().size()
367 : processed_batch_vector_input_param_values.front().size()));
368 std::iota(processed_batch_indices.back().begin(), processed_batch_indices.back().end(), 0);
369 }
370 }
371 else // cartesian_product
372 {
373 // We basically need to reconstruct the corresponding parameters based on the cartesian product
374 // algorithm
375 for (const auto i : index_range(_batch_scalar_input_param_values))
376 {
377 // For the first element, just copy the parameters
378 if (processed_batch_scalar_input_param_values.empty())
379 {
380 processed_batch_scalar_input_param_values.push_back(_batch_scalar_input_param_values[i]);
382 {
383 processed_batch_indices.push_back(
384 std::vector<unsigned int>(_batch_scalar_input_param_values[i].size()));
385 std::iota(
386 processed_batch_indices.back().begin(), processed_batch_indices.back().end(), 0);
387 }
388 }
389 else
390 {
391 const unsigned int num_new_batch_params = _batch_scalar_input_param_values[i].size();
392 const unsigned int num_processed_batch_params =
393 processed_batch_scalar_input_param_values.front().size();
394 // All the elements in the processed_batch_scalar_input_param_values need to be duplicated
395 // for num_new_batch_params times
396 for (auto & unit_processed_batch_scalar_input_param_values :
397 processed_batch_scalar_input_param_values)
398 {
399 auto temp_params = unit_processed_batch_scalar_input_param_values;
400 for (unsigned int j = 1; j < num_new_batch_params; j++)
401 {
402 unit_processed_batch_scalar_input_param_values.insert(
403 unit_processed_batch_scalar_input_param_values.end(),
404 temp_params.begin(),
405 temp_params.end());
406 }
407 }
409 {
410 // Same as the composed indices
411 for (auto & unit_processed_batch_indices : processed_batch_indices)
412 {
413 auto temp_indices = unit_processed_batch_indices;
414 for (unsigned int j = 1; j < num_new_batch_params; j++)
415 {
416 unit_processed_batch_indices.insert(
417 unit_processed_batch_indices.end(), temp_indices.begin(), temp_indices.end());
418 }
419 }
420 }
421
422 // Then, add a new element to the processed_batch_scalar_input_param_values by repeating
423 // each element in _batch_scalar_input_param_values[i] for num_processed_batch_params times
424 processed_batch_scalar_input_param_values.push_back({});
425 for (const auto & unit_batch_scalar_input_param_values :
427 for (unsigned int j = 0; j < num_processed_batch_params; j++)
428 processed_batch_scalar_input_param_values.back().push_back(
429 unit_batch_scalar_input_param_values);
431 {
432 // Same as the composed indices
433 processed_batch_indices.push_back({});
434 for (const auto & unit_batch_scalar_input_param_values_index :
435 index_range(_batch_scalar_input_param_values[i]))
436 for (unsigned int j = 0; j < num_processed_batch_params; j++)
437 processed_batch_indices.back().push_back(unit_batch_scalar_input_param_values_index);
438 }
439 }
440 }
441 for (const auto i : index_range(_batch_vector_input_param_values))
442 {
443 // For the first element, just copy the parameters
444 if (processed_batch_vector_input_param_values.empty())
445 {
446 if (processed_batch_scalar_input_param_values.empty())
447 {
448 // if no batch scalar input parameters are used
449 // we just need to initiate the processed_batch_vector_input_param_values as the first one
450 // to fill
451 processed_batch_vector_input_param_values.push_back(_batch_vector_input_param_values[i]);
453 {
454 processed_batch_indices.push_back(
455 std::vector<unsigned int>(_batch_vector_input_param_values[i].size()));
456 std::iota(
457 processed_batch_indices.back().begin(), processed_batch_indices.back().end(), 0);
458 }
459 }
460 else
461 {
462 processed_batch_vector_input_param_values.push_back({});
463 // if there are batch scalar input parameters, then each element needs to be duplicated
464 // for that amount of times
465 for (const auto & unit_batch_vector_input_param_values :
467 for (unsigned int j = 0; j < processed_batch_scalar_input_param_values.front().size();
468 j++)
469 processed_batch_vector_input_param_values.back().push_back(
470 unit_batch_vector_input_param_values);
471 // Then the scalar input parameters need to be duplicated for the number of elements in
472 // the processed_batch_vector_input_param_values
473 for (auto & unit_processed_batch_scalar_input_param_values :
474 processed_batch_scalar_input_param_values)
475 {
476 auto temp_params = unit_processed_batch_scalar_input_param_values;
477 for (unsigned int j = 1; j < processed_batch_vector_input_param_values.back().size();
478 j++)
479 {
480 unit_processed_batch_scalar_input_param_values.insert(
481 unit_processed_batch_scalar_input_param_values.end(),
482 temp_params.begin(),
483 temp_params.end());
484 }
485 }
487 {
488 // Add the indices for the first batch vector input parameter
489 processed_batch_indices.push_back({});
490 for (const auto & unit_batch_vector_input_param_values_index :
491 index_range(_batch_vector_input_param_values[i]))
492 for (unsigned int j = 0; j < processed_batch_indices.front().size(); j++)
493 processed_batch_indices.back().push_back(
494 unit_batch_vector_input_param_values_index);
495 // Duplicate the indices for the batch scalar input parameters
496 for (unsigned int k = 1; k < processed_batch_indices.size(); k++)
497 {
498 auto & unit_processed_batch_indices = processed_batch_indices[k - 1];
499 auto temp_indices = unit_processed_batch_indices;
500 for (unsigned int j = 1; j < _batch_vector_input_param_values[i].size(); j++)
501 {
502 unit_processed_batch_indices.insert(
503 unit_processed_batch_indices.end(), temp_indices.begin(), temp_indices.end());
504 }
505 }
506 }
507 }
508 }
509 else
510 {
511 const unsigned int num_new_batch_params = _batch_vector_input_param_values[i].size();
512 const unsigned int num_processed_batch_params =
513 processed_batch_vector_input_param_values.front().size();
514 // All the elements in the processed_batch_vector_input_param_values need to be duplicated
515 // for num_new_batch_params times
516 for (auto & unit_processed_batch_vector_input_param_values :
517 processed_batch_vector_input_param_values)
518 {
519 auto temp_params = unit_processed_batch_vector_input_param_values;
520 for (unsigned int j = 1; j < num_new_batch_params; j++)
521 {
522 unit_processed_batch_vector_input_param_values.insert(
523 unit_processed_batch_vector_input_param_values.end(),
524 temp_params.begin(),
525 temp_params.end());
526 }
527 }
529 {
530 // Same for the decomposed indices
531 for (auto & unit_processed_batch_indices : processed_batch_indices)
532 {
533 auto temp_indices = unit_processed_batch_indices;
534 for (unsigned int j = 1; j < num_new_batch_params; j++)
535 {
536 unit_processed_batch_indices.insert(
537 unit_processed_batch_indices.end(), temp_indices.begin(), temp_indices.end());
538 }
539 }
540 }
541 // if there are also batch scalar input parameters, it also needs to be duplicated
542 for (auto & unit_processed_batch_scalar_input_param_values :
543 processed_batch_scalar_input_param_values)
544 {
545 auto temp_params = unit_processed_batch_scalar_input_param_values;
546 for (unsigned int j = 1; j < num_new_batch_params; j++)
547 {
548 unit_processed_batch_scalar_input_param_values.insert(
549 unit_processed_batch_scalar_input_param_values.end(),
550 temp_params.begin(),
551 temp_params.end());
552 }
553 }
554 // Then, add a new element to the processed_batch_vector_input_param_values by repeating
555 // each element in _batch_vector_input_param_values[i] for num_processed_batch_params times
556 processed_batch_vector_input_param_values.push_back({});
557 for (const auto & unit_batch_vector_input_param_values :
559 for (unsigned int j = 0; j < num_processed_batch_params; j++)
560 processed_batch_vector_input_param_values.back().push_back(
561 unit_batch_vector_input_param_values);
563 {
564 // Same for the decomposed indices
565 processed_batch_indices.push_back({});
566 for (const auto & unit_batch_vector_input_param_values_index :
567 index_range(_batch_vector_input_param_values[i]))
568 for (unsigned int j = 0; j < num_processed_batch_params; j++)
569 processed_batch_indices.back().push_back(unit_batch_vector_input_param_values_index);
570 }
571 }
572 }
573 }
574
575 // Now, we can add the mesh generators by looping through the processed params
576 const unsigned int num_batch_params =
577 processed_batch_vector_input_param_values.empty()
578 ? processed_batch_scalar_input_param_values.front().size()
579 : processed_batch_vector_input_param_values.front().size();
580 for (const auto i : make_range(num_batch_params))
581 {
583 for (const auto j : index_range(_batch_scalar_input_param_values))
584 setScalarParams(params,
587 processed_batch_scalar_input_param_values[j][i]);
588 for (const auto j : index_range(_batch_vector_input_param_values))
589 setVectorParams(params,
592 processed_batch_vector_input_param_values[j][i]);
593 for (const auto j : index_range(_fixed_scalar_input_param_names))
594 setScalarParams(params,
598 for (const auto j : index_range(_fixed_vector_input_param_names))
599 setVectorParams(params,
603
604 std::string mesh_index;
606 for (const auto & process_batch_index : processed_batch_indices)
607 mesh_index += '_' + std::to_string(process_batch_index[i]);
608 else
609 mesh_index = "_" + std::to_string(i);
610
612 _mesh_generator_type, _mesh_name_prefix + mesh_index, params);
613 }
614}
615
616void
618 const std::string & param_name,
619 const ParameterType & param_type,
620 const std::string & param_value) const
621{
622 switch (param_type)
623 {
624 case (ParameterType::REAL):
625 params.set<Real>(param_name) = MooseUtils::convert<Real>(param_value);
626 break;
628 params.set<short>(param_name) = MooseUtils::convert<short>(param_value);
629 break;
631 params.set<unsigned short>(param_name) = MooseUtils::convert<unsigned short>(param_value);
632 break;
633 case (ParameterType::INT):
634 params.set<int>(param_name) = MooseUtils::convert<int>(param_value);
635 break;
636 case (ParameterType::UINT):
637 params.set<unsigned int>(param_name) = MooseUtils::convert<unsigned int>(param_value);
638 break;
639 case (ParameterType::LONG):
640 params.set<long>(param_name) = MooseUtils::convert<long>(param_value);
641 break;
643 params.set<unsigned long>(param_name) = MooseUtils::convert<unsigned long>(param_value);
644 break;
646 params.set<long long>(param_name) = MooseUtils::convert<long long>(param_value);
647 break;
649 params.set<unsigned long long>(param_name) =
650 MooseUtils::convert<unsigned long long>(param_value);
651 break;
653 params.set<dof_id_type>(param_name) = MooseUtils::convert<dof_id_type>(param_value);
654 break;
656 params.set<boundary_id_type>(param_name) = MooseUtils::convert<boundary_id_type>(param_value);
657 break;
659 params.set<subdomain_id_type>(param_name) =
660 MooseUtils::convert<subdomain_id_type>(param_value);
661 break;
662 case (ParameterType::ENUM):
663 params.set<MooseEnum>(param_name) = param_value;
664 break;
666 params.set<std::string>(param_name) = param_value;
667 break;
669 params.set<SubdomainName>(param_name) = param_value;
670 break;
672 params.set<BoundaryName>(param_name) = param_value;
673 break;
675 params.set<MeshGeneratorName>(param_name) = param_value;
676 break;
678 params.set<MeshFileName>(param_name) = param_value;
679 break;
680 case (ParameterType::BOOL):
681 hit::toBool(param_value, &params.set<bool>(param_name));
682 break;
684 params.set<RealVectorValue>(param_name) =
685 convertStringToCompoundRealScalar<RealVectorValue>(param_value);
686 break;
688 params.set<Point>(param_name) = convertStringToCompoundRealScalar<Point>(param_value);
689 break;
690 default:
691 mooseAssert(false,
692 "impossible situation."); // as we use MultiMooseEnum to ensure the type is valid
693 }
694}
695
696void
698 const std::string & param_name,
699 const ParameterType & param_type,
700 const std::vector<std::string> & param_value) const
701{
702 switch (param_type)
703 {
704 case (ParameterType::REAL):
705 convertAndSetNumericVector<Real>(params, param_name, param_value);
706 break;
708 convertAndSetNumericVector<short>(params, param_name, param_value);
709 break;
711 convertAndSetNumericVector<unsigned short>(params, param_name, param_value);
712 break;
713 case (ParameterType::INT):
714 convertAndSetNumericVector<int>(params, param_name, param_value);
715 break;
716 case (ParameterType::UINT):
717 convertAndSetNumericVector<unsigned int>(params, param_name, param_value);
718 break;
719 case (ParameterType::LONG):
720 convertAndSetNumericVector<long>(params, param_name, param_value);
721 break;
723 convertAndSetNumericVector<unsigned long>(params, param_name, param_value);
724 break;
726 convertAndSetNumericVector<long long>(params, param_name, param_value);
727 break;
729 convertAndSetNumericVector<unsigned long long>(params, param_name, param_value);
730 break;
732 convertAndSetNumericVector<dof_id_type>(params, param_name, param_value);
733 break;
735 convertAndSetNumericVector<boundary_id_type>(params, param_name, param_value);
736 break;
738 convertAndSetNumericVector<subdomain_id_type>(params, param_name, param_value);
739 break;
740 case (ParameterType::ENUM):
741 params.set<MultiMooseEnum>(param_name) = param_value;
742 break;
744 params.set<std::vector<std::string>>(param_name) = param_value;
745 break;
747 convertAndSetStringLikeVector<SubdomainName>(params, param_name, param_value);
748 break;
750 convertAndSetStringLikeVector<BoundaryName>(params, param_name, param_value);
751 break;
753 convertAndSetStringLikeVector<MeshGeneratorName>(params, param_name, param_value);
754 break;
756 convertAndSetStringLikeVector<MeshFileName>(params, param_name, param_value);
757 break;
758 case (ParameterType::BOOL):
759 {
760 std::vector<bool> values(param_value.size());
761 std::transform(param_value.begin(),
762 param_value.end(),
763 values.begin(),
764 [](const std::string & val)
765 {
766 bool tmp;
767 hit::toBool(val, &tmp);
768 return tmp;
769 });
770 params.set<std::vector<bool>>(param_name) = values;
771 break;
772 }
774 convertAndSetCompoundRealScalarVector<RealVectorValue>(params, param_name, param_value);
775 break;
777 convertAndSetCompoundRealScalarVector<Point>(params, param_name, param_value);
778 break;
779 default:
780 mooseAssert(false,
781 "impossible situation."); // as we use MultiMooseEnum to ensure the type is valid
782 }
783}
784
785template <typename T>
786void
788 InputParameters & params,
789 const std::string & param_name,
790 const std::vector<std::string> & param_value) const
791{
792 std::vector<T> values(param_value.size());
793 std::transform(param_value.begin(),
794 param_value.end(),
795 values.begin(),
796 [](const std::string & val) { return MooseUtils::convert<T>(val); });
797 params.set<std::vector<T>>(param_name) = values;
798}
799
800template <typename T>
801void
803 InputParameters & params,
804 const std::string & param_name,
805 const std::vector<std::string> & param_value) const
806{
807 std::vector<T> values(param_value.size());
808 std::transform(param_value.begin(),
809 param_value.end(),
810 values.begin(),
811 [this](const std::string & val)
812 { return convertStringToCompoundRealScalar<T>(val); });
813 params.set<std::vector<T>>(param_name) = values;
814}
815
816template <typename T>
817void
819 InputParameters & params,
820 const std::string & param_name,
821 const std::vector<std::string> & param_value) const
822{
823 std::vector<T> values(param_value.size());
824 std::transform(param_value.begin(),
825 param_value.end(),
826 values.begin(),
827 [](const std::string & val) { return T(val); });
828 params.set<std::vector<T>>(param_name) = values;
829}
830
831void
833 const std::string & action_input_param_name,
834 const std::vector<std::string> & param_names,
835 const std::vector<ParameterType> & param_types,
836 const bool & is_vector) const
837{
838 for (const auto i : index_range(param_names))
839 {
840 switch (param_types[i])
841 {
842 case (ParameterType::REAL):
843 checkInputParameterType<Real>(params, action_input_param_name, param_names[i], is_vector);
844 break;
846 checkInputParameterType<short>(params, action_input_param_name, param_names[i], is_vector);
847 break;
849 checkInputParameterType<unsigned short>(
850 params, action_input_param_name, param_names[i], is_vector);
851 break;
852 case (ParameterType::INT):
853 checkInputParameterType<int>(params, action_input_param_name, param_names[i], is_vector);
854 break;
855 case (ParameterType::UINT):
856 checkInputParameterType<unsigned int>(
857 params, action_input_param_name, param_names[i], is_vector);
858 break;
859 case (ParameterType::LONG):
860 checkInputParameterType<long>(params, action_input_param_name, param_names[i], is_vector);
861 break;
863 checkInputParameterType<unsigned long>(
864 params, action_input_param_name, param_names[i], is_vector);
865 break;
867 checkInputParameterType<long long>(
868 params, action_input_param_name, param_names[i], is_vector);
869 break;
871 checkInputParameterType<unsigned long long>(
872 params, action_input_param_name, param_names[i], is_vector);
873 break;
875 checkInputParameterType<dof_id_type>(
876 params, action_input_param_name, param_names[i], is_vector);
877 break;
879 checkInputParameterType<boundary_id_type>(
880 params, action_input_param_name, param_names[i], is_vector);
881 break;
883 checkInputParameterType<subdomain_id_type>(
884 params, action_input_param_name, param_names[i], is_vector);
885 break;
886 case (ParameterType::ENUM):
887 if (is_vector)
888 checkInputParameterType<MultiMooseEnum>(
889 params, action_input_param_name, param_names[i], false);
890 else
891 checkInputParameterType<MooseEnum>(
892 params, action_input_param_name, param_names[i], false);
893 break;
895 checkInputParameterType<std::string>(
896 params, action_input_param_name, param_names[i], is_vector);
897 break;
899 checkInputParameterType<SubdomainName>(
900 params, action_input_param_name, param_names[i], is_vector);
901 break;
903 checkInputParameterType<BoundaryName>(
904 params, action_input_param_name, param_names[i], is_vector);
905 break;
907 checkInputParameterType<MeshGeneratorName>(
908 params, action_input_param_name, param_names[i], is_vector);
909 break;
911 checkInputParameterType<MeshFileName>(
912 params, action_input_param_name, param_names[i], is_vector);
913 break;
914 case (ParameterType::BOOL):
915 checkInputParameterType<bool>(params, action_input_param_name, param_names[i], is_vector);
916 break;
918 checkInputParameterType<RealVectorValue>(
919 params, action_input_param_name, param_names[i], is_vector);
920 break;
922 checkInputParameterType<Point>(params, action_input_param_name, param_names[i], is_vector);
923 break;
924 default:
925 mooseAssert(
926 false,
927 "impossible situation."); // as we use MultiMooseEnum to ensure the type is valid
928 }
929 }
930}
931
932template <typename T>
933void
935 const std::string & action_input_param_name,
936 const std::string & param_name,
937 const bool & is_vector) const
938{
939 if ((is_vector && !params.isType<std::vector<T>>(param_name)) ||
940 (!is_vector && !params.isType<T>(param_name)))
941 paramError(action_input_param_name,
942 "the input parameter, " + param_name + ", has the wrong type. It should be " +
943 params.type(param_name) + ".");
944}
945
946template <typename T>
947T
949{
950 const auto split_str = MooseUtils::split(str, " ");
951 mooseAssert(split_str.size() == Moose::dim,
952 "string used for compound real scalar conversion should contain three elements.");
953 T ret(MooseUtils::convert<Real>(split_str[0]));
954 for (const auto i :
955 make_range(static_cast<std::remove_cv_t<decltype(Moose::dim)>>(1), Moose::dim))
956 ret(i) = MooseUtils::convert<Real>(split_str[i]);
957 return ret;
958}
959
960bool
962{
963 const auto valid_types = {ParameterType::REALVECTORVALUE, ParameterType::POINT};
964 return std::count(valid_types.begin(), valid_types.end(), param_type);
965}
registerMooseAction("MooseApp", BatchMeshGeneratorAction, "add_mesh_generator")
std::array< Real, 2 > values
Definition MortarUtils.C:52
Base class for actions.
Definition Action.h:38
static InputParameters validParams()
Definition Action.C:26
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition Action.h:172
Action to generate batches of mesh generators from vectors of parameter values.
T convertStringToCompoundRealScalar(const std::string &str) const
Convert a string to a compound real scalar type.
std::vector< std::vector< std::string > > _fixed_vector_input_param_values
Values of the vector input parameters to keep fixed in the batch generation.
const std::vector< ParameterType > _fixed_scalar_input_param_types
Types of the vector input parameters to keep fixed in the batch generation.
std::vector< std::vector< std::string > > _batch_scalar_input_param_values
Values of the scalar input parameters to vary in the batch generation.
const std::vector< std::string > _fixed_vector_input_param_names
Names of the vector input parameters to keep fixed in the batch generation.
const std::string _mesh_generator_type
Type (object name) of the mesh generator to use for batch generation.
bool isCompoundRealScalarType(const ParameterType &param_type) const
Check if the parameter type is a compound real scalar type.
const std::string _mesh_name_prefix
Prefix to use for naming the batch generated meshes.
const MultiBatchParamsMethod _multi_batch_params_method
Method to use for generating the batch parameters.
static InputParameters validParams()
virtual void act() override final
Method to add objects to the simulation or perform other setup tasks.
const std::vector< std::string > _batch_vector_input_param_names
Names of the vector input parameters to vary in the batch generation.
void checkInputParameterType(const InputParameters &params, const std::string &action_input_param_name, const std::string &param_name, const bool &is_vector) const
Check the type of the input parameter is valid, otherwise throw an error.
const std::vector< std::string > _fixed_scalar_input_param_names
Names of the vector input parameters to keep fixed in the batch generation.
const std::vector< ParameterType > _batch_scalar_input_param_types
Types of the scalar input parameters to vary in the batch generation.
const std::vector< ParameterType > _fixed_vector_input_param_types
Types of the vector input parameters to keep fixed in the batch generation.
std::vector< std::vector< std::vector< std::string > > > _batch_vector_input_param_values
Values of the vector input parameters to vary in the batch generation.
void setVectorParams(InputParameters &params, const std::string &param_name, const ParameterType &param_type, const std::vector< std::string > &param_value) const
Set the vector input parameters for a unit mesh generator.
const std::vector< ParameterType > _batch_vector_input_param_types
Types of the vector input parameters to vary in the batch generation.
void convertAndSetNumericVector(InputParameters &params, const std::string &param_name, const std::vector< std::string > &param_value) const
Convert a vector of strings to a numeric vector and set it in the InputParameters object.
std::vector< std::string > _fixed_scalar_input_param_values
Values of the vector input parameters to keep fixed in the batch generation.
void setScalarParams(InputParameters &params, const std::string &param_name, const ParameterType &param_type, const std::string &param_value) const
Set the scalar input parameters for a unit mesh generator.
void convertAndSetCompoundRealScalarVector(InputParameters &params, const std::string &param_name, const std::vector< std::string > &param_value) const
Convert a vector of strings to a compound real scalar type vector and set it in the InputParameters o...
void convertAndSetStringLikeVector(InputParameters &params, const std::string &param_name, const std::vector< std::string > &param_value) const
Convert a vector of strings to a string-derived type vector and set it in the InputParameters object.
void checkInputParametersTypes(const InputParameters &params, const std::string &action_input_param_name, const std::vector< std::string > &param_names, const std::vector< ParameterType > &param_types, const bool &is_vector=false) const
Check the types of the input parameters are valid, otherwise throw an error.
const std::vector< std::string > _batch_scalar_input_param_names
Names of the scalar input parameters to vary in the batch generation.
BatchMeshGeneratorAction(const InputParameters &params)
const bool _use_decomposed_index
Flag to indicate if the decomposed index should be used in the mesh name.
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
Utility class to help check parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
std::string type(const std::string &name) const
Prints the type of the requested parameter by name.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
bool isType(const std::string &name) const
void addMeshGenerator(const std::string &type, const std::string &name, const InputParameters &params)
Add a mesh generator that will act on the meshes in the system.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
Definition MooseApp.h:407
MeshGeneratorSystem & getMeshGeneratorSystem()
Gets the system that manages the MeshGenerators.
Definition MooseApp.h:886
const std::string & type() const
Get the type of this class.
Definition MooseBase.h:93
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271
const std::string & _name
The name of this class.
Definition MooseBase.h:381
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type.
std::vector< std::string > split(const std::string &str, const std::string &delimiter, std::size_t max_count)
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition Moose.h:165