forked from idaholab/moose
/
InputParameters.C
1152 lines (1007 loc) · 37.7 KB
/
InputParameters.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html
#include "InputParameters.h"
// MOOSE includes
#include "MooseEnum.h"
#include "MooseTypes.h"
#include "MooseUtils.h"
#include "MultiMooseEnum.h"
#include "ExecFlagEnum.h"
#include "pcrecpp.h"
#include <cmath>
InputParameters
emptyInputParameters()
{
InputParameters params;
return params;
}
InputParameters::InputParameters()
: Parameters(),
_collapse_nesting(false),
_moose_object_syntax_visibility(true),
_show_deprecated_message(true),
_allow_copy(true),
_from_legacy_construction(true)
{
}
InputParameters::InputParameters(const InputParameters & rhs)
: Parameters(),
_show_deprecated_message(true),
_allow_copy(true),
_from_legacy_construction(rhs._from_legacy_construction)
{
*this = rhs;
}
InputParameters::InputParameters(const Parameters & rhs)
: _show_deprecated_message(true), _allow_copy(true), _from_legacy_construction(true)
{
_params.clear();
Parameters::operator=(rhs);
_collapse_nesting = false;
_moose_object_syntax_visibility = true;
}
void
InputParameters::clear()
{
Parameters::clear();
_params.clear();
_coupled_vars.clear();
_new_to_deprecated_coupled_vars.clear();
_collapse_nesting = false;
_moose_object_syntax_visibility = true;
_show_deprecated_message = true;
_allow_copy = true;
_from_legacy_construction = true;
_block_fullpath = "";
_block_location = "";
}
void
InputParameters::addClassDescription(const std::string & doc_string)
{
_class_description = doc_string;
}
void
InputParameters::set_attributes(const std::string & name, bool inserted_only)
{
if (!inserted_only)
{
/**
* "._set_by_add_param" and ".deprecated_params" are not populated until after
* the default value has already been set in libMesh (first callback to this
* method). Therefore if a variable is in/not in one of these sets, you can
* be assured it was put there outside of the "addParam*()" calls.
*/
_params[name]._set_by_add_param = false;
// valid_params don't make sense for MooseEnums
if (!have_parameter<MooseEnum>(name) && !have_parameter<MultiMooseEnum>(name))
_params[name]._valid = true;
if (_show_deprecated_message)
{
if (_params.count(name) && !_params[name]._deprecation_message.empty())
mooseDeprecated(
"The parameter ", name, " is deprecated.\n", _params[name]._deprecation_message);
}
}
}
std::string
InputParameters::getClassDescription() const
{
return _class_description;
}
InputParameters &
InputParameters::operator=(const InputParameters & rhs)
{
// An error to help minimize the segmentation faults that occure when MooseObjects do not have the
// correct constructor
if (!rhs._allow_copy)
{
const std::string & name =
rhs.get<std::string>("_object_name"); // If _allow_parameter_copy is set then so is name
// (see InputParameterWarehouse::addInputParameters)
mooseError("Copying of the InputParameters object for the ",
name,
" object is not allowed.\n\nThe likely cause for this error ",
"is having a constructor that does not use a const reference, all constructors\nfor "
"MooseObject based classes should be as follows:\n\n",
" MyObject::MyObject(const InputParameters & parameters);");
}
Parameters::operator=(rhs);
_params = rhs._params;
_buildable_types = rhs._buildable_types;
_buildable_rm_types = rhs._buildable_rm_types;
_collapse_nesting = rhs._collapse_nesting;
_moose_object_syntax_visibility = rhs._moose_object_syntax_visibility;
_coupled_vars = rhs._coupled_vars;
_new_to_deprecated_coupled_vars = rhs._new_to_deprecated_coupled_vars;
_allow_copy = rhs._allow_copy;
_block_fullpath = rhs._block_fullpath;
_block_location = rhs._block_location;
return *this;
}
InputParameters &
InputParameters::operator+=(const InputParameters & rhs)
{
Parameters::operator+=(rhs);
// TODO: this is not a proper merge - if a particular parameter exists in both this and rhs,
// then we should actually smartly merge both metadata structs before storing in this.
for (auto it = rhs._params.begin(); it != rhs._params.end(); ++it)
_params[it->first] = it->second;
_buildable_types.insert(
_buildable_types.end(), rhs._buildable_types.begin(), rhs._buildable_types.end());
_buildable_rm_types.insert(
_buildable_rm_types.end(), rhs._buildable_rm_types.begin(), rhs._buildable_rm_types.end());
// Collapse nesting and moose object syntax hiding are not modified with +=
_coupled_vars.insert(rhs._coupled_vars.begin(), rhs._coupled_vars.end());
_new_to_deprecated_coupled_vars.insert(rhs._new_to_deprecated_coupled_vars.begin(),
rhs._new_to_deprecated_coupled_vars.end());
return *this;
}
void
InputParameters::setDeprecatedVarDocString(const std::string & new_name,
const std::string & doc_string)
{
auto coupled_vars_it = _new_to_deprecated_coupled_vars.find(new_name);
if (coupled_vars_it != _new_to_deprecated_coupled_vars.end())
{
auto params_it = _params.find(coupled_vars_it->second);
if (params_it == _params.end())
mooseError("There must have been a mistake in the construction of the new to deprecated "
"coupled vars map because the old name ",
coupled_vars_it->second,
" doesn't exist in the parameters data.");
params_it->second._doc_string = doc_string;
}
}
void
InputParameters::addCoupledVar(const std::string & name, Real value, const std::string & doc_string)
{
addParam<std::vector<VariableName>>(name, doc_string);
_coupled_vars.insert(name);
_params[name]._coupled_default.assign(1, value);
_params[name]._have_coupled_default = true;
// Set the doc string for any associated deprecated coupled var
setDeprecatedVarDocString(name, doc_string);
}
void
InputParameters::addCoupledVar(const std::string & name,
const std::vector<Real> & value,
const std::string & doc_string)
{
// std::vector<VariableName>(1, Moose::stringify(value)),
addParam<std::vector<VariableName>>(name, doc_string);
_coupled_vars.insert(name);
_params[name]._coupled_default = value;
_params[name]._have_coupled_default = true;
// Set the doc string for any associated deprecated coupled var
setDeprecatedVarDocString(name, doc_string);
}
void
InputParameters::addCoupledVar(const std::string & name, const std::string & doc_string)
{
addParam<std::vector<VariableName>>(name, doc_string);
_coupled_vars.insert(name);
// Set the doc string for any associated deprecated coupled var
setDeprecatedVarDocString(name, doc_string);
}
void
InputParameters::addDeprecatedCoupledVar(const std::string & old_name,
const std::string & new_name,
const std::string & removal_date /*=""*/)
{
_show_deprecated_message = false;
// Set the doc string if we are adding the deprecated var after the new var has already been added
auto params_it = _params.find(new_name);
std::string doc_string;
if (params_it != _params.end())
doc_string = params_it->second._doc_string;
addParam<std::vector<VariableName>>(old_name, doc_string);
_coupled_vars.insert(old_name);
_new_to_deprecated_coupled_vars.emplace(new_name, old_name);
std::string deprecation_message =
"The coupled variable parameter '" + old_name + "' has been deprecated";
if (!removal_date.empty())
deprecation_message += " and will be removed " + removal_date;
deprecation_message += ". Please use the '" + new_name + "' coupled variable parameter instead.";
_params[old_name]._deprecation_message = deprecation_message;
_show_deprecated_message = true;
}
void
InputParameters::addCoupledVarWithAutoBuild(const std::string & name,
const std::string & base_name,
const std::string & num_name,
const std::string & doc_string)
{
addParam<std::vector<VariableName>>(name, doc_string);
_coupled_vars.insert(name);
_params[name]._autobuild_vecs = std::make_pair(base_name, num_name);
// Additionally there are two more parameters that need to be added:
addParam<std::string>(base_name, doc_string + " (base_name)");
addParam<unsigned int>(num_name, doc_string + " (num_name)");
}
void
InputParameters::addRequiredCoupledVarWithAutoBuild(const std::string & name,
const std::string & base_name,
const std::string & num_name,
const std::string & doc_string)
{
addRequiredParam<std::vector<VariableName>>(name, doc_string);
addCoupledVarWithAutoBuild(name, base_name, num_name, doc_string);
}
void
InputParameters::addRequiredCoupledVar(const std::string & name, const std::string & doc_string)
{
addRequiredParam<std::vector<VariableName>>(name, doc_string);
_coupled_vars.insert(name);
}
std::string
InputParameters::getDocString(const std::string & name) const
{
std::string doc_string;
auto it = _params.find(name);
if (it != _params.end())
for (const auto & ch : it->second._doc_string)
{
if (ch == '\n')
doc_string += " ... ";
else
doc_string += ch;
}
return doc_string;
}
void
InputParameters::setDocString(const std::string & name, const std::string & doc)
{
auto it = _params.find(name);
if (it == _params.end())
mooseError("Unable to set the documentation string (using setDocString) for the \"",
name,
"\" parameter, the parameter does not exist.");
it->second._doc_string = doc;
}
bool
InputParameters::isParamRequired(const std::string & name) const
{
return _params.count(name) > 0 && _params.at(name)._required;
}
bool
InputParameters::isParamValid(const std::string & name) const
{
if (have_parameter<MooseEnum>(name))
return get<MooseEnum>(name).isValid();
else if (have_parameter<MultiMooseEnum>(name))
return get<MultiMooseEnum>(name).isValid();
else if (have_parameter<ExecFlagEnum>(name))
return get<ExecFlagEnum>(name).isValid();
else
return _params.count(name) > 0 && _params.at(name)._valid;
}
bool
InputParameters::isParamSetByAddParam(const std::string & name) const
{
return _params.count(name) > 0 && _params.at(name)._set_by_add_param;
}
bool
InputParameters::isParamDeprecated(const std::string & name) const
{
return _params.count(name) > 0 && !_params.at(name)._deprecation_message.empty();
}
bool
InputParameters::areAllRequiredParamsValid() const
{
for (const auto & it : *this)
if (isParamRequired(it.first) && !isParamValid(it.first))
return false;
return true;
}
bool
InputParameters::isPrivate(const std::string & name) const
{
return _params.count(name) > 0 && _params.at(name)._is_private;
}
void
InputParameters::declareControllable(const std::string & input_names,
std::set<ExecFlagType> execute_flags)
{
std::vector<std::string> names;
MooseUtils::tokenize<std::string>(input_names, names, 1, " ");
for (auto & name : names)
{
auto map_iter = _params.find(name);
if (map_iter != _params.end()) // error is handled by checkParams method
{
map_iter->second._controllable = true;
map_iter->second._controllable_flags = execute_flags;
}
else
mooseError("The input parameter '",
name,
"' does not exist, thus cannot be marked as controllable.");
}
}
bool
InputParameters::isControllable(const std::string & name)
{
return _params.count(name) > 0 && _params[name]._controllable;
}
const std::set<ExecFlagType> &
InputParameters::getControllableExecuteOnTypes(const std::string & name)
{
return _params[name]._controllable_flags;
}
void
InputParameters::registerBase(const std::string & value)
{
InputParameters::set<std::string>("_moose_base") = value;
_params["_moose_base"]._is_private = true;
}
void
InputParameters::registerSystemAttributeName(const std::string & value)
{
InputParameters::set<std::string>("_moose_warehouse_system_name") = value;
_params["_moose_warehouse_system_name"]._is_private = true;
}
void
InputParameters::registerBuildableTypes(const std::string & names)
{
_buildable_types.clear();
MooseUtils::tokenize(names, _buildable_types, 1, " \t\n\v\f\r"); // tokenize on whitespace
}
void
InputParameters::addRelationshipManager(
const std::string & name,
Moose::RelationshipManagerType rm_type,
Moose::RelationshipManagerInputParameterCallback input_parameter_callback)
{
_buildable_rm_types.emplace_back(name, rm_type, input_parameter_callback);
}
const std::vector<std::string> &
InputParameters::getBuildableTypes() const
{
return _buildable_types;
}
const std::vector<std::tuple<std::string,
Moose::RelationshipManagerType,
Moose::RelationshipManagerInputParameterCallback>> &
InputParameters::getBuildableRelationshipManagerTypes() const
{
return _buildable_rm_types;
}
void
InputParameters::collapseSyntaxNesting(bool collapse)
{
_collapse_nesting = collapse;
}
bool
InputParameters::collapseSyntaxNesting() const
{
return _collapse_nesting;
}
void
InputParameters::mooseObjectSyntaxVisibility(bool visibility)
{
_moose_object_syntax_visibility = visibility;
}
bool
InputParameters::mooseObjectSyntaxVisibility() const
{
return _moose_object_syntax_visibility;
}
#define dynamicCastRangeCheck(type, up_type, long_name, short_name, param, oss) \
do \
{ \
InputParameters::Parameter<type> * scalar_p = \
dynamic_cast<InputParameters::Parameter<type> *>(param); \
if (scalar_p) \
rangeCheck<type, up_type>(long_name, short_name, scalar_p, oss); \
InputParameters::Parameter<std::vector<type>> * vector_p = \
dynamic_cast<InputParameters::Parameter<std::vector<type>> *>(param); \
if (vector_p) \
rangeCheck<type, up_type>(long_name, short_name, vector_p, oss); \
} while (0)
#define checkMooseType(param_type, name) \
if (have_parameter<param_type>(name) || have_parameter<std::vector<param_type>>(name)) \
oss << inputLocation(param_name) << ": non-controllable type '" << type(name) \
<< "' for parameter '" << paramFullpath(param_name) << "' marked controllable";
void
InputParameters::checkParams(const std::string & parsing_syntax)
{
std::string parampath = blockFullpath() != "" ? blockFullpath() : parsing_syntax;
std::ostringstream oss;
// Required parameters
for (const auto & it : *this)
{
if (!isParamValid(it.first) && isParamRequired(it.first))
{
// check if an old, deprecated name exists for this parameter that may be specified
auto oit = _new_to_deprecated_coupled_vars.find(it.first);
if (oit != _new_to_deprecated_coupled_vars.end() && isParamValid(oit->second))
continue;
oss << blockLocation() << ": missing required parameter '" << parampath + "/" + it.first
<< "'\n";
oss << "\tDoc String: \"" + getDocString(it.first) + "\"" << std::endl;
}
}
// Range checked parameters
for (const auto & it : *this)
{
std::string long_name(parampath + "/" + it.first);
dynamicCastRangeCheck(Real, Real, long_name, it.first, it.second, oss);
dynamicCastRangeCheck(int, long, long_name, it.first, it.second, oss);
dynamicCastRangeCheck(long, long, long_name, it.first, it.second, oss);
dynamicCastRangeCheck(unsigned int, long, long_name, it.first, it.second, oss);
}
// Controllable parameters
for (const auto & param_name : getControllableParameters())
{
if (isPrivate(param_name))
oss << inputLocation(param_name) << ": private parameter '" << paramFullpath(param_name)
<< "' marked controllable";
checkMooseType(NonlinearVariableName, param_name);
checkMooseType(AuxVariableName, param_name);
checkMooseType(VariableName, param_name);
checkMooseType(BoundaryName, param_name);
checkMooseType(SubdomainName, param_name);
checkMooseType(PostprocessorName, param_name);
checkMooseType(VectorPostprocessorName, param_name);
checkMooseType(UserObjectName, param_name);
checkMooseType(MaterialPropertyName, param_name);
}
if (!oss.str().empty())
mooseError(oss.str());
}
bool
InputParameters::hasCoupledValue(const std::string & coupling_name) const
{
return _coupled_vars.find(coupling_name) != _coupled_vars.end();
}
bool
InputParameters::hasDefaultCoupledValue(const std::string & coupling_name) const
{
return _params.count(coupling_name) > 0 && _params.at(coupling_name)._have_coupled_default &&
_coupled_vars.count(coupling_name) > 0;
}
void
InputParameters::defaultCoupledValue(const std::string & coupling_name, Real value, unsigned int i)
{
_params[coupling_name]._coupled_default.resize(i + 1);
_params[coupling_name]._coupled_default[i] = value;
_params[coupling_name]._have_coupled_default = true;
}
Real
InputParameters::defaultCoupledValue(const std::string & coupling_name, unsigned int i) const
{
auto value_it = _params.find(coupling_name);
if (value_it == _params.end() || !value_it->second._have_coupled_default)
mooseError("Attempted to retrieve default value for coupled variable '",
coupling_name,
"' when none was provided. \n\nThere are three reasons why this may have "
"occurred:\n 1. The other version of params.addCoupledVar() should be used in order "
"to provide a default value. \n 2. This should have been a required coupled "
"variable added with params.addRequiredCoupledVar() \n 3. The call to get the "
"coupled value should have been properly guarded with isCoupled()\n");
return value_it->second._coupled_default.at(i);
}
unsigned int
InputParameters::numberDefaultCoupledValues(const std::string & coupling_name) const
{
auto value_it = _params.find(coupling_name);
if (value_it == _params.end())
mooseError("Attempted to retrieve default value for coupled variable '",
coupling_name,
"' when none was provided.");
return value_it->second._coupled_default.size();
}
std::map<std::string, std::pair<std::string, std::string>>
InputParameters::getAutoBuildVectors() const
{
std::map<std::string, std::pair<std::string, std::string>> abv;
for (auto it = _params.begin(); it != _params.end(); ++it)
{
if (!it->second._autobuild_vecs.first.empty())
abv[it->first] = it->second._autobuild_vecs;
}
return abv;
}
std::string
InputParameters::type(const std::string & name) const
{
if (!_values.count(name))
mooseError("Parameter \"", name, "\" not found.\n\n", *this);
if (_coupled_vars.find(name) != _coupled_vars.end())
return "std::vector<VariableName>";
else if (_params.count(name) > 0 && !_params.at(name)._custom_type.empty())
return _params.at(name)._custom_type;
return _values.at(name)->type();
}
std::string
InputParameters::getMooseType(const std::string & name) const
{
std::string var;
if (have_parameter<VariableName>(name))
var = get<VariableName>(name);
else if (have_parameter<NonlinearVariableName>(name))
var = get<NonlinearVariableName>(name);
else if (have_parameter<AuxVariableName>(name))
var = get<AuxVariableName>(name);
else if (have_parameter<PostprocessorName>(name))
var = get<PostprocessorName>(name);
else if (have_parameter<VectorPostprocessorName>(name))
var = get<VectorPostprocessorName>(name);
else if (have_parameter<FunctionName>(name))
var = get<FunctionName>(name);
else if (have_parameter<UserObjectName>(name))
var = get<UserObjectName>(name);
else if (have_parameter<MaterialPropertyName>(name))
var = get<MaterialPropertyName>(name);
else if (have_parameter<std::string>(name))
var = get<std::string>(name);
return var;
}
std::vector<std::string>
InputParameters::getVecMooseType(const std::string & name) const
{
std::vector<std::string> svars;
if (have_parameter<std::vector<VariableName>>(name))
{
std::vector<VariableName> vars = get<std::vector<VariableName>>(name);
std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
}
else if (have_parameter<std::vector<NonlinearVariableName>>(name))
{
std::vector<NonlinearVariableName> vars = get<std::vector<NonlinearVariableName>>(name);
std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
}
else if (have_parameter<std::vector<AuxVariableName>>(name))
{
std::vector<AuxVariableName> vars = get<std::vector<AuxVariableName>>(name);
std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
}
else if (have_parameter<std::vector<MaterialPropertyName>>(name))
{
std::vector<MaterialPropertyName> vars = get<std::vector<MaterialPropertyName>>(name);
std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
}
else if (have_parameter<std::vector<std::string>>(name))
{
std::vector<std::string> vars = get<std::vector<std::string>>(name);
std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
}
return svars;
}
void
InputParameters::addParamNamesToGroup(const std::string & space_delim_names,
const std::string group_name)
{
std::vector<std::string> elements;
MooseUtils::tokenize(space_delim_names, elements, 1, " \t\n\v\f\r"); // tokenize on whitespace
// Since we don't require types (templates) for this method, we need
// to get a raw list of parameter names to compare against.
std::set<std::string> param_names;
for (const auto & it : *this)
param_names.insert(it.first);
for (const auto & param_name : elements)
if (_params.count(param_name) > 0)
_params[param_name]._group = group_name;
else
mooseError("Unable to find a parameter with name: ",
param_name,
" when adding to group ",
group_name,
'.');
}
std::vector<std::string>
InputParameters::getSyntax(const std::string & name) const
{
auto it = _params.find(name);
if (it == _params.end())
mooseError("No parameter exists with the name ", name);
return it->second._cli_flag_names;
}
std::string
InputParameters::getGroupName(const std::string & param_name) const
{
auto it = _params.find(param_name);
if (it != _params.end())
return it->second._group;
return std::string();
}
void
InputParameters::applyParameters(const InputParameters & common,
const std::vector<std::string> exclude)
{
// Loop through the common parameters
for (const auto & it : common)
{
// Common parameter name
const std::string & common_name = it.first;
// Continue to next parameter, if the current is in list of excluded parameters
if (std::find(exclude.begin(), exclude.end(), common_name) != exclude.end())
continue;
applyParameter(common, common_name);
}
// Loop through the coupled variables
for (std::set<std::string>::const_iterator it = common.coupledVarsBegin();
it != common.coupledVarsEnd();
++it)
{
// Variable name
const std::string var_name = *it;
// Continue to next variable, if the current is in list of excluded parameters
if (std::find(exclude.begin(), exclude.end(), var_name) != exclude.end())
continue;
applyCoupledVar(common, var_name);
}
}
void
InputParameters::applySpecificParameters(const InputParameters & common,
const std::vector<std::string> & include,
bool allow_private)
{
// Loop through the common parameters
for (const auto & it : common)
{
// Common parameter name
const std::string & common_name = it.first;
// Continue to next parameter, if the current is not in list of included parameters
if (std::find(include.begin(), include.end(), common_name) == include.end())
continue;
applyParameter(common, common_name, allow_private);
}
// Loop through the coupled variables
for (std::set<std::string>::const_iterator it = common.coupledVarsBegin();
it != common.coupledVarsEnd();
++it)
{
// Variable name
const std::string var_name = *it;
// Continue to next variable, if the current is not in list of included parameters
if (std::find(include.begin(), include.end(), var_name) == include.end())
continue;
applyCoupledVar(common, var_name);
}
}
void
InputParameters::applyCoupledVar(const InputParameters & common, const std::string & var_name)
{
// Disable the display of deprecated message when applying common parameters, this avoids a dump
// of messages
_show_deprecated_message = false;
// If the local parameters has a coupled variable, populate it with the value from the common
// parameters, if the common parameters has the coupled variable too
if (hasCoupledValue(var_name))
{
if (common.hasDefaultCoupledValue(var_name))
{
// prepare a vector of default coupled values
std::vector<Real> defaults(common.numberDefaultCoupledValues(var_name));
for (unsigned int j = 0; j < common.numberDefaultCoupledValues(var_name); ++j)
defaults[j] = common.defaultCoupledValue(var_name, j);
addCoupledVar(var_name, defaults, common.getDocString(var_name));
}
else if (common.hasCoupledValue(var_name))
addCoupledVar(var_name, common.getDocString(var_name));
}
// Enable deprecated message printing
_show_deprecated_message = true;
}
void
InputParameters::applyParameter(const InputParameters & common,
const std::string & common_name,
bool allow_private)
{
// Disable the display of deprecated message when applying common parameters, this avoids a dump
// of messages
_show_deprecated_message = false;
// Extract the properties from the local parameter for the current common parameter name
const bool local_exist = _values.find(common_name) != _values.end();
const bool local_set = _params.count(common_name) > 0 && !_params[common_name]._set_by_add_param;
const bool local_priv = allow_private ? false : isPrivate(common_name);
const bool local_valid = isParamValid(common_name);
// Extract the properties from the common parameter
const bool common_exist = common._values.find(common_name) != common._values.end();
const bool common_priv = allow_private ? false : common.isPrivate(common_name);
const bool common_valid = common.isParamValid(common_name);
/* In order to apply common parameter 4 statements must be satisfied
* (1) A local parameter must exist with the same name as common parameter
* (2) Common parameter must valid and exist
* (3) Local parameter must be invalid OR not have been set from its default
* (4) Both cannot be private
*/
if (local_exist && common_exist && common_valid && (!local_valid || !local_set) &&
(!common_priv || !local_priv))
{
delete _values[common_name];
_values[common_name] = common._values.find(common_name)->second->clone();
set_attributes(common_name, false);
}
// Enable deprecated message printing
_show_deprecated_message = true;
}
///Deprecated method
bool
InputParameters::paramSetByUser(const std::string & name) const
{
mooseDeprecated("paramSetByUser() is deprecated. Use isParamSetByUser() instead.");
return isParamSetByUser(name);
}
bool
InputParameters::isParamSetByUser(const std::string & name) const
{
if (!isParamValid(name))
// if the parameter is invalid, it is for sure not set by the user
return false;
else
// If the parameters is not located in the list, then it was set by the user
return _params.count(name) > 0 && !_params.at(name)._set_by_add_param;
}
const std::string &
InputParameters::getDescription(const std::string & name) const
{
auto it = _params.find(name);
if (it == _params.end())
mooseError("No parameter exists with the name ", name);
return it->second._doc_string;
}
template <>
void
InputParameters::addRequiredParam<MooseEnum>(const std::string & name,
const MooseEnum & moose_enum,
const std::string & doc_string)
{
InputParameters::set<MooseEnum>(name) = moose_enum; // valid parameter is set by set_attributes
_params[name]._required = true;
_params[name]._doc_string = doc_string;
}
template <>
void
InputParameters::addRequiredParam<MultiMooseEnum>(const std::string & name,
const MultiMooseEnum & moose_enum,
const std::string & doc_string)
{
InputParameters::set<MultiMooseEnum>(name) =
moose_enum; // valid parameter is set by set_attributes
_params[name]._required = true;
_params[name]._doc_string = doc_string;
}
template <>
void
InputParameters::addRequiredParam<std::vector<MooseEnum>>(
const std::string & name,
const std::vector<MooseEnum> & moose_enums,
const std::string & doc_string)
{
InputParameters::set<std::vector<MooseEnum>>(name) =
moose_enums; // valid parameter is set by set_attributes
_params[name]._required = true;
_params[name]._doc_string = doc_string;
}
template <>
void
InputParameters::addParam<MooseEnum>(const std::string & /*name*/,
const std::string & /*doc_string*/)
{
mooseError("You must supply a MooseEnum object when using addParam, even if the parameter is not "
"required!");
}
template <>
void
InputParameters::addParam<MultiMooseEnum>(const std::string & /*name*/,
const std::string & /*doc_string*/)
{
mooseError("You must supply a MultiMooseEnum object when using addParam, even if the parameter "
"is not required!");
}
template <>
void
InputParameters::addParam<std::vector<MooseEnum>>(const std::string & /*name*/,
const std::string & /*doc_string*/)
{
mooseError("You must supply a vector of MooseEnum object(s) when using addParam, even if the "
"parameter is not required!");
}
template <>
void
InputParameters::addPrivateParam<MooseEnum>(const std::string & /*name*/)
{
mooseError("You must supply a MooseEnum object when using addPrivateParam, even if the parameter "
"is not required!");
}
template <>
void
InputParameters::addPrivateParam<MultiMooseEnum>(const std::string & /*name*/)
{
mooseError("You must supply a MultiMooseEnum object when using addPrivateParam, even if the "
"parameter is not required!");
}
template <>
void
InputParameters::addDeprecatedParam<MooseEnum>(const std::string & /*name*/,
const std::string & /*doc_string*/,
const std::string & /*deprecation_message*/)
{
mooseError("You must supply a MooseEnum object and the deprecation string when using "
"addDeprecatedParam, even if the parameter is not required!");
}
template <>
void
InputParameters::addDeprecatedParam<MultiMooseEnum>(const std::string & /*name*/,
const std::string & /*doc_string*/,
const std::string & /*deprecation_message*/)
{
mooseError("You must supply a MultiMooseEnum object and the deprecation string when using "
"addDeprecatedParam, even if the parameter is not required!");
}
template <>
void
InputParameters::addDeprecatedParam<std::vector<MooseEnum>>(
const std::string & /*name*/,
const std::string & /*doc_string*/,
const std::string & /*deprecation_message*/)
{
mooseError("You must supply a vector of MooseEnum object(s) and the deprecation string when "
"using addDeprecatedParam, even if the parameter is not required!");
}
template <>
void
InputParameters::setParamHelper<PostprocessorName, Real>(const std::string & /*name*/,
PostprocessorName & l_value,
const Real & r_value)
{
// Assign the default value so that it appears in the dump
std::ostringstream oss;
oss << r_value;
l_value = oss.str();
}
template <>
void
InputParameters::setParamHelper<PostprocessorName, int>(const std::string & /*name*/,
PostprocessorName & l_value,
const int & r_value)
{
// Assign the default value so that it appears in the dump
std::ostringstream oss;
oss << r_value;
l_value = oss.str();