forked from idaholab/moose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputParameters.h
1698 lines (1479 loc) · 60.3 KB
/
InputParameters.h
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
#pragma once
// MOOSE includes
#include "MooseUtils.h"
#include "MooseError.h"
#include "MooseTypes.h"
#include "MultiMooseEnum.h"
#include "ExecFlagEnum.h"
#include "Conversion.h"
#include "libmesh/parameters.h"
#ifdef LIBMESH_HAVE_FPARSER
#include "libmesh/fparser.hh"
#else
template <typename T>
class FunctionParserBase
{
}
#endif
#include <tuple>
#include <unordered_map>
// Forward declarations
class Action;
class InputParameters;
class MooseEnum;
class MooseObject;
class MultiMooseEnum;
class Problem;
/**
* The main MOOSE class responsible for handling user-defined
* parameters in almost every MOOSE system.
*/
class InputParameters : public Parameters
{
public:
InputParameters(const InputParameters & rhs);
InputParameters(const Parameters & rhs);
virtual ~InputParameters() = default;
virtual void clear() override;
/**
* This method adds a description of the class that will be displayed
* in the input file syntax dump
*/
void addClassDescription(const std::string & doc_string);
/**
* Returns the class description
*/
std::string getClassDescription() const;
/**
* Override from libMesh to set user-defined attributes on our parameter
*/
virtual void set_attributes(const std::string & name, bool inserted_only) override;
/// This functions is called in set as a 'callback' to avoid code duplication
template <typename T>
void setHelper(const std::string & name);
/**
* Returns a writable reference to the named parameters. Note: This is not a virtual
* function! Use caution when comparing to the parent class implementation
* @param name The name of the parameter to set
* @param quiet_mode When true the parameter is kept with set_by_add_param=true,
* this is generally not needed.
*
* "quite_mode" returns a writable reference to the named parameter, without setting
* set_by_add_param to false. Using this method of set will make the parameter to continue to
* behave if its value where set ONLY by addParam and not by any other method.
*
* This was added for handling parameters in the Output objects that have behavior dependent
* on whether the user modified the parameters.
*
*/
template <typename T>
T & set(const std::string & name, bool quiet_mode = false);
/**
* Given a series of parameters names and values, sets each name to
* the corresponding value. Any number of name, value pairs can be
* supplied.
*
* Note that each \p value must be of the correct type for the
* parameter of that name, not merely of a type convertible to the
* correct type.
*
* @param name The name of the first parameter to set
*/
template <typename T, typename... Ts>
void setParameters(const std::string & name, const T & value, Ts... extra_input_parameters);
/**
* Runs a range on the supplied parameter if it exists and throws an error if that check fails.
* @returns Boolean indicating whether range check exists
*/
template <typename T, typename UP_T>
void rangeCheck(const std::string & full_name,
const std::string & short_name,
InputParameters::Parameter<T> * param,
std::ostream & oss = Moose::out);
template <typename T, typename UP_T>
void rangeCheck(const std::string & full_name,
const std::string & short_name,
InputParameters::Parameter<std::vector<T>> * param,
std::ostream & oss = Moose::out);
/**
* Verifies that the requested parameter exists and is not NULL and returns it to the caller.
* The template parameter must be a pointer or an error will be thrown.
*/
template <typename T>
T getCheckedPointerParam(const std::string & name, const std::string & error_string = "") const;
/**
* This method adds a parameter and documentation string to the InputParameters
* object that will be extracted from the input file. If the parameter is
* missing in the input file, and error will be thrown
*/
template <typename T>
void addRequiredParam(const std::string & name, const std::string & doc_string);
/**
* This version of addRequiredParam is here for a consistent use with MooseEnums. Use of
* this function for any other type will throw an error.
*/
template <typename T>
void
addRequiredParam(const std::string & name, const T & moose_enum, const std::string & doc_string);
///@{
/**
* These methods add an option parameter and a documentation string to the InputParameters object.
* The first version of this function takes a default value which is used if the parameter is not
* found in the input file. The second method will leave the parameter uninitialized but can be
* checked with "isParamValid" before use.
*/
template <typename T, typename S>
void addParam(const std::string & name, const S & value, const std::string & doc_string);
template <typename T>
void addParam(const std::string & name, const std::string & doc_string);
///@}
///@{
// BEGIN RANGE CHECKED PARAMETER METHODS
/**
* These methods add an range checked parameters. A lower and upper bound can be supplied and the
* supplied parameter will be checked to fall within that range.
*/
template <typename T>
void addRequiredRangeCheckedParam(const std::string & name,
const std::string & parsed_function,
const std::string & doc_string);
template <typename T>
void addRangeCheckedParam(const std::string & name,
const T & value,
const std::string & parsed_function,
const std::string & doc_string);
template <typename T>
void addRangeCheckedParam(const std::string & name,
const std::string & parsed_function,
const std::string & doc_string);
// END RANGE CHECKED PARAMETER METHODS
///@}
/**
* These methods add an option parameter and with a customer type to the InputParameters object.
* The custom
* type will be output in YAML dumps and can be used within the GUI application.
*/
template <typename T>
void addRequiredCustomTypeParam(const std::string & name,
const std::string & custom_type,
const std::string & doc_string);
template <typename T>
void addCustomTypeParam(const std::string & name,
const T & value,
const std::string & custom_type,
const std::string & doc_string);
template <typename T>
void addCustomTypeParam(const std::string & name,
const std::string & custom_type,
const std::string & doc_string);
/**
* These method add a parameter to the InputParameters object which can be retrieved like any
* other parameter. This parameter however is not printed in the Input file syntax dump or web
* page dump so does not take a documentation string. The first version of this function takes an
* optional default value.
*/
template <typename T>
void addPrivateParam(const std::string & name, const T & value);
template <typename T>
void addPrivateParam(const std::string & name);
/**
* Add parameters for retrieval from the command line.
*
* NOTE: This ONLY works for App objects! This is not valid for normal MOOSE objects!
*
* @param name The name of the parameter
* @param syntax Space separated list of command-line switch syntax that can set this option
* @param doc_string Documentation. This will be shown for --help
*/
template <typename T>
void addRequiredCommandLineParam(const std::string & name,
const std::string & syntax,
const std::string & doc_string);
template <typename T>
void addCommandLineParam(const std::string & name,
const std::string & syntax,
const std::string & doc_string);
template <typename T>
void addCommandLineParam(const std::string & name,
const std::string & syntax,
const T & value,
const std::string & doc_string);
/**
* @param name The name of the parameter
* @param value The default value of this parameter if it requires one
* @param doc_string Documentation. This will be shown for --help
* @param deprecation_message The message that will will print about why this param was
* deprecated. It might mention the "new way".
*/
template <typename T>
void addDeprecatedParam(const std::string & name,
const T & value,
const std::string & doc_string,
const std::string & deprecation_message);
template <typename T>
void addDeprecatedParam(const std::string & name,
const std::string & doc_string,
const std::string & deprecation_message);
/**
* This method checks to make sure that we aren't adding a parameter with the same name but a
* different type. It
* throws a MooseError if an inconsistent type is detected. While this state is supported by
* libMesh it brings
* nothing but blood and tears for those who try ;)
*
* @param name the name of the parameter
*/
template <typename T>
void checkConsistentType(const std::string & name) const;
/**
* Get the syntax for a command-line parameter
*/
std::vector<std::string> getSyntax(const std::string & name) const;
/**
* Get the documentation string for a parameter
*/
const std::string & getDescription(const std::string & name) const;
/**
* This method takes a space delimited list of parameter names and adds them to the specified
* group name.
* This information is used in the GUI to group parameters into logical sections.
*/
void addParamNamesToGroup(const std::string & space_delim_names, const std::string group_name);
/**
* This method retrieves the group name for the passed parameter name if one exists. Otherwise an
* empty string is returned.
*/
std::string getGroupName(const std::string & param_name) const;
/**
* This method suppresses an inherited parameter so that it isn't required or valid
* in the derived class. The parameter is added to the private parameter list.
* Suppressing a parameter can have dire consequences.
* Use at your own risk!
*/
template <typename T>
void suppressParameter(const std::string & name);
/**
* Changes the parameter to be required.
* @param name The parameter name
*/
template <typename T>
void makeParamRequired(const std::string & name);
/**
* Changes the parameter to not be required.
* @param name The parameter name
*/
template <typename T>
void makeParamNotRequired(const std::string & name);
/**
* This method adds a coupled variable name pair. The parser will look for variable
* name pair in the input file and can return a reference to the storage location
* for the coupled variable if found
*/
void addCoupledVar(const std::string & name, const std::string & doc_string);
/**
* This method adds a deprecated coupled variable name pair. The parser will look for variable
* name pair in the input file and can return a reference to the storage location
* for the coupled variable if found. The doc string for the deprecated variable will be
* constructed from the doc string for the new variable. A deprecation message will also be
* automatically generated
*/
void addDeprecatedCoupledVar(const std::string & old_name,
const std::string & new_name,
const std::string & removal_date = "");
/**
* This method adds a coupled variable name pair. The parser will look for variable
* name pair in the input file and can return a reference to the storage location
* for the coupled variable if found
*
* Also - you can provide a default value for this variable in the case that an actual variable is
* not provided.
*/
void addCoupledVar(const std::string & name, const Real value, const std::string & doc_string);
/**
* This method adds a coupled variable name pair. The parser will look for variable
* name pair in the input file and can return a reference to the storage location
* for the coupled variable if found
*
* Also - you can provide a vector of values for this variable in the case that an actual variable
* is not provided.
*/
void addCoupledVar(const std::string & name,
const std::vector<Real> & value,
const std::string & doc_string);
///@{
/**
* These methods add a coupled variable name pair. The parser will look for variable
* name pair in the input file and can return a reference to the storage location
* for the coupled variable if found.
*
* This version of the method will build a vector if the given the base_name and num_name
* parameters exist
* in the input file:
* e.g.
* [./foo]
* ...
* some_base = base_
* some_num = 5
* [../]
*
* # The coupling parameter will be passed this vector: "base_0 base_1 base_2 base_3 base_4"
*/
void addCoupledVarWithAutoBuild(const std::string & name,
const std::string & base_name,
const std::string & num_name,
const std::string & doc_string);
void addRequiredCoupledVarWithAutoBuild(const std::string & name,
const std::string & base_name,
const std::string & num_name,
const std::string & doc_string);
///@}
/**
* Utility functions for retrieving one of the MooseTypes variables into the common "string" base
* class.
* Scalar and Vector versions are supplied
*/
std::string getMooseType(const std::string & name) const;
std::vector<std::string> getVecMooseType(const std::string & name) const;
/**
* This method adds a coupled variable name pair. The parser will look for variable
* name pair in the input file and can return a reference to the storage location
* for the coupled variable. If the coupled variable is not supplied in the input
* file, and error is thrown.
*
* Version 2: An auto built vector will be built from the base_name and num_name param. See
* addCoupledVar for an example
*/
void addRequiredCoupledVar(const std::string & name, const std::string & doc_string);
/**
* Returns the documentation string for the specified parameter name
*/
std::string getDocString(const std::string & name) const;
/**
* Set the doc string of a parameter.
*
* This method is generally used from within the validParams function to modify the documentation
* for an
* existing parameter, such as a parameter that is supplied from an interface class.
*/
void setDocString(const std::string & name, const std::string & doc);
/**
* Returns a boolean indicating whether the specified parameter is required or not
*/
bool isParamRequired(const std::string & name) const;
/**
* This method returns parameters that have been initialized in one fashion or another,
* i.e. The value was supplied as a default argument or read and properly converted from
* the input file
*/
bool isParamValid(const std::string & name) const;
/**
* Returns whether or not the parameter was set due to addParam. If not then it was either set
* programmatically
* or was read through the input file.
*/
bool isParamSetByAddParam(const std::string & name) const;
/**
* Returns True if the parameters is deprecated.
*/
bool isParamDeprecated(const std::string & name) const;
/**
* This method returns true if all of the parameters in this object are valid
* (i.e. isParamValid(name) == true - for all parameters)
*/
bool areAllRequiredParamsValid() const;
/**
* Prints the type of the requested parameter by name
*/
std::string type(const std::string & name) const;
/**
* Returns a Boolean indicating whether the specified parameter is private or not
*/
bool isPrivate(const std::string & name) const;
/**
* Declare the given parameters as controllable
*/
void declareControllable(const std::string & name, std::set<ExecFlagType> execute_flags = {});
/**
* Marker a parameter that has been changed by the Control system (this is for output purposes)
*/
void markControlled(const std::string & name);
/**
* Returns a Boolean indicating whether the specified parameter is controllable
*/
bool isControllable(const std::string & name) const;
/**
* Return the allowed execute flags for a controllable parameter
*/
const std::set<ExecFlagType> & getControllableExecuteOnTypes(const std::string & name) const;
/**
* This method must be called from every base "Moose System" to create linkage with the Action
* System.
* See "Moose.C" for the registerMooseObjectTask() calls.
*/
void registerBase(const std::string & value);
/**
* This method is used to define the MOOSE system name that is used by the TheWarehouse object
* for storing objects to be retrieved for execution. The base class of every object class
* that will be called for execution (e.g., UserObject objects) should call this method.
*
* This is different from registerBase because the name supplied to registerBase is used to
* associate syntax, but the objects created often go to the same objects for execution, as is
* the case for Postprocessor object which are executed with UserObjects.
*
* See the AttribSystem object for use Attribute.h/C.
*/
void registerSystemAttributeName(const std::string & value);
/**
* This method is here to indicate which Moose types a particular Action may build. It takes a
* space delimited list of registered MooseObjects. TODO: For now we aren't actually checking
* this list when we build objects. Since individual actions can do whatever they want it's not
* exactly trivial to check this without changing the user API. This function properly restricts
* the syntax and YAML dumps.
*/
void registerBuildableTypes(const std::string & names);
/**
* Tells MOOSE about a RelationshipManager that this object needs. RelationshipManagers
* handle element "ghosting", "non-local DOF access" and "sparsity pattern" relationships.
*
* Basically: if this object needs non-local (ie non-current-element) data access then you
* probably need a relationship manager
*
* @param name The name of the RelationshipManager type
* @param rm_type The type (GEOMETRIC/ALGEBRAIC) of the RelationshipManger. Note: You can use
* boolean logic to to "or" RelationshipManagerTypes together to make a RelationshipManager that
* is multi-typed.
* @param input_parameter_callback This is a function pointer that will get called to fill in the
* RelationShipManager's InputParameters. See MooseTypes.h for the signature of this function.
*/
void addRelationshipManager(
const std::string & name,
Moose::RelationshipManagerType rm_type,
Moose::RelationshipManagerInputParameterCallback input_parameter_callback = nullptr);
/**
* Clears all currently registered RelationshipManagers
*/
void clearRelationshipManagers() { _buildable_rm_types.clear(); }
/**
* Returns the list of buildable types as a std::vector<std::string>
*/
const std::vector<std::string> & getBuildableTypes() const;
/**
* Returns the list of buildable (or required) RelationshipManager object types for this object.
*/
const std::vector<std::tuple<std::string,
Moose::RelationshipManagerType,
Moose::RelationshipManagerInputParameterCallback>> &
getBuildableRelationshipManagerTypes() const;
///@{
/**
* Mutators for controlling whether or not the outermost level of syntax will be collapsed when
* printed.
*/
void collapseSyntaxNesting(bool collapse);
bool collapseSyntaxNesting() const;
///@}
///@{
/**
* Mutators for controlling whether or not the outermost level of syntax will be collapsed when
* printed.
*/
void mooseObjectSyntaxVisibility(bool visibility);
bool mooseObjectSyntaxVisibility() const;
///@}
///@{
/**
* Copy and Copy/Add operators for the InputParameters object
*/
using Parameters::operator=;
using Parameters::operator+=;
InputParameters & operator=(const InputParameters & rhs);
InputParameters & operator+=(const InputParameters & rhs);
///@}
/**
* This function checks parameters stored in the object to make sure they are in the correct
* state as the user expects:
* Required parameters are verified as valid meaning that they were either initialized when
* they were created, or were read from an input file or some other valid source
*/
void checkParams(const std::string & parsing_syntax);
/**
* Methods returning iterators to the coupled variables names stored in this
* InputParameters object
*/
inline std::set<std::string>::const_iterator coupledVarsBegin() const
{
return _coupled_vars.begin();
}
inline std::set<std::string>::const_iterator coupledVarsEnd() const
{
return _coupled_vars.end();
}
/**
* Return the coupled variable parameter names.
*/
const std::set<std::string> & getCoupledVariableParamNames() const { return _coupled_vars; }
/**
* Return the new to deprecated variable name map
*/
const std::unordered_map<std::string, std::string> & getNewToDeprecatedVarMap() const
{
return _new_to_deprecated_coupled_vars;
}
/**
* Return whether or not the coupled variable exists
* @param coupling_name The name of the coupled variable to test for
* @return True if the variable exists in the coupled variables for this InputParameters object
*/
bool hasCoupledValue(const std::string & coupling_name) const;
/**
* Return whether or not the requested parameter has a default coupled value.
*
* @param coupling_name The name of the coupling parameter to get the default value for.
*/
bool hasDefaultCoupledValue(const std::string & coupling_name) const;
/**
* Get the default value for an optionally coupled variable.
*
* @param coupling_name The name of the coupling parameter to get the default value for.
* @param i By default 0, in general the index of the requested coupled default value.
*/
Real defaultCoupledValue(const std::string & coupling_name, unsigned int i = 0) const;
/**
* Get the number of defaulted coupled value entries
*
* @param coupling_name The name of the coupling parameter to get the default value for.
*/
unsigned int numberDefaultCoupledValues(const std::string & coupling_name) const;
/**
* Set the default value for an optionally coupled variable (called by the Parser).
*
* @param coupling_name The name of the coupling parameter to get the default value for.
* @param value Default value to set.
* @param i By default 0, in general the index of the requested coupled default value.
*/
void defaultCoupledValue(const std::string & coupling_name, Real value, unsigned int i = 0);
/**
* Returns the auto build vectors for all parameters.
*/
std::map<std::string, std::pair<std::string, std::string>> getAutoBuildVectors() const;
// BEGIN APPLY PARAMETER METHODS
/**
* Method for applying common parameters
* @param common The set of parameters to apply to the parameters stored in this object
* @param exclude A vector of parameters to exclude
*
* 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
* (3) Local parameter must be invalid OR not have been set from its default
* (4) Both cannot be private
*
* Output objects have a set of common parameters that are passed
* down to each of the output objects created. This method is used for
* applying those common parameters.
*
* @see CommonOutputAction AddOutputAction
*/
void applyParameters(const InputParameters & common,
std::vector<std::string> exclude = std::vector<std::string>());
/**
* Method for applying common parameters
* @param common The set of parameters to apply to the parameters stored in this object
* @param include A vector of parameters to apply
*
* 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
* (3) Local parameter must be invalid OR not have been set from its default
* (4) Both cannot be private
*
* Output objects have a set of common parameters that are passed
* down to each of the output objects created. This method is used for
* applying those common parameters.
*
* @see CommonOutputAction AddOutputAction
*/
void applySpecificParameters(const InputParameters & common,
const std::vector<std::string> & include,
bool allow_private = false);
/**
* Apply values from a single parameter in common, to a single parameter stored in this object
* @param common The set of InputParameters from which to extract parameters from
* @param common_name The name within common from which to get the parameter values
*
* 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
* (3) Local parameter must be invalid OR not have been set from its default
* (4) Both cannot be private
*/
void applyParameter(const InputParameters & common,
const std::string & common_name,
bool allow_private = false);
// END APPLY PARAMETER METHODS
/**
* Apply properties of a single coupled variable in common, to a single coupled variable stored in
* this object
* @param common The set of InputParameters from which to extract the coupled variable's
* properties
* @param var_name The name of the coupled variable whose properties are to be applied
*
* In order to apply the properties, both the local parameters and the common parameters must
* have a coupled variable with name var_name
*/
void applyCoupledVar(const InputParameters & common, const std::string & var_name);
/**
* Deprecated method. Use isParamSetByUser() instead.
*/
bool paramSetByUser(const std::string & name) const;
/**
* Method returns true if the parameter was by the user
* @param name The parameter name
*/
bool isParamSetByUser(const std::string & name) const;
///@{
/*
* These methods are here to retrieve parameters for scalar and vector types respectively. We will
* throw errors
* when returning most scalar types, but will allow retrieving empty vectors.
*/
template <typename T>
static const T &
getParamHelper(const std::string & name, const InputParameters & pars, const T * the_type);
template <typename T>
static const std::vector<T> & getParamHelper(const std::string & name,
const InputParameters & pars,
const std::vector<T> * the_type);
///@}
using Parameters::get;
/// Combine two vector parameters into a single vector of pairs
template <typename R1,
typename R2,
typename V1 = typename std::conditional<std::is_same<R1, MooseEnumItem>::value,
MultiMooseEnum,
std::vector<R1>>::type,
typename V2 = typename std::conditional<std::is_same<R2, MooseEnumItem>::value,
MultiMooseEnum,
std::vector<R2>>::type>
std::vector<std::pair<R1, R2>> get(const std::string & param1, const std::string & param2) const;
/**
* Return list of controllable parameters
*/
std::set<std::string> getControllableParameters() const;
/**
* Return names of parameters within a group.
*/
std::set<std::string> getGroupParameters(const std::string & group) const;
/**
* Provide a set of reserved values for a parameter. These are values that are in addition
* to the normal set of values the parameter can take.
*/
void setReservedValues(const std::string & name, const std::set<std::string> & reserved);
/**
* Get a set of reserved parameter values.
* Returns a set by value since we can return an empty set.
*/
std::set<std::string> reservedValues(const std::string & name) const;
///@{
/**
* Get/set a string representing the location (i.e. filename,linenum) in the input text for the
* block containing parameters for this object.
*/
std::string & blockLocation() { return _block_location; }
const std::string & blockLocation() const { return _block_location; }
///@}
///@{
/**
* Get/set a string representing the full HIT parameter path from the input file (e.g.
* "Mesh/foo") for the block containing parameters for this object.
*/
std::string & blockFullpath() { return _block_fullpath; }
const std::string & blockFullpath() const { return _block_fullpath; }
///@}
///@{
/**
* Get/set a string representing the location in the input text the parameter originated from
* (i.e. filename,linenum) for the given param.
*/
const std::string & inputLocation(const std::string & param) const
{
return at(param)._input_location;
}
std::string & inputLocation(const std::string & param) { return at(param)._input_location; }
///@}
///@{
/**
* Get/set a string representing the full HIT parameter path from the input file (e.g.
* "Mesh/foo/bar" for param "bar") for the given param.
*/
const std::string & paramFullpath(const std::string & param) const
{
return at(param)._param_fullpath;
}
std::string & paramFullpath(const std::string & param) { return at(param)._param_fullpath; }
///@}
/// generate error message prefix with parameter name and location (if available)
std::string errorPrefix(const std::string & param) const;
/**
* Get/set a string representing the raw, unmodified token text for the given param. This is
* usually only set/useable for file-path type parameters.
*/
std::string & rawParamVal(const std::string & param) { return _params[param]._raw_val; }
const std::string & rawParamVal(const std::string & param) const
{
return _params.at(param)._raw_val;
}
/**
* Informs this object that values for this parameter set from the input file or from the command
* line should be ignored
*/
template <typename T>
void ignoreParameter(const std::string & name);
/**
* Whether to ignore the value of an input parameter set in the input file or from the command
* line.
*/
bool shouldIgnore(const std::string & name);
/**
* @returns True if the parameter with name \p name is of type T.
*/
template <typename T>
bool isType(const std::string & name) const;
/**
* @returns True if these parameters were constructed using the legacy method.
**/
bool fromLegacyConstruction() const { return _from_legacy_construction; }
private:
// Private constructor so that InputParameters can only be created in certain places.
InputParameters();
/**
* Method to terminate the recursive setParameters definition
*/
void setParameters() {}
/**
* Helper that uses overloading to distinguish adding commandline parameters of
* a scalar and a vector kind. Vector parameters are options that may appear multiple
* times on the command line (like -i).
*/
template <typename T>
void addCommandLineParamHelper(const std::string & name,
const std::string & syntax,
const std::string & doc_string,
T *);
template <typename T>
void addCommandLineParamHelper(const std::string & name,
const std::string & syntax,
const std::string & doc_string,
std::vector<T> *);
/**
* Private method for setting deprecated coupled variable documentation strings
*/
void setDeprecatedVarDocString(const std::string & new_name, const std::string & doc_string);
struct Metadata
{
std::string _doc_string;
/// The custom type that will be printed in the YAML dump for a parameter if supplied
std::string _custom_type;
std::vector<std::string> _cli_flag_names;
/// The names of the parameters organized into groups
std::string _group;
/// The map of functions used for range checked parameters
std::string _range_function;
/// directions for auto build vectors (base_, 5) -> "base_0 base_1 base_2 base_3 base_4")
std::pair<std::string, std::string> _autobuild_vecs;
/// True for parameters that are required (i.e. will cause an abort if not supplied)
bool _required = false;
/**
* Whether the parameter is either explicitly set or provided a default value when added
* Note: We do not store MooseEnum names in valid params, instead we ask MooseEnums whether
* they are valid or not.
*/
bool _valid = false;
/// The set of parameters that will NOT appear in the the dump of the parser tree
bool _is_private = false;
bool _have_coupled_default = false;
/// The default value for optionally coupled variables
std::vector<Real> _coupled_default = {0};
/// True if a parameters value was set by addParam, and not set again.
bool _set_by_add_param = false;
/// The reserved option names for a parameter
std::set<std::string> _reserved_values;
/// If non-empty, this parameter is deprecated.
std::string _deprecation_message;
/// original location of parameter (i.e. filename,linenum) - used for nice error messages.
std::string _input_location;
/// full HIT path of the parameter from the input file - used for nice error messages.
std::string _param_fullpath;
/// raw token text for a parameter - usually only set for filepath type params.
std::string _raw_val;
/// True if the parameters is controllable
bool _controllable = false;
/// Controllable execute flag restriction
std::set<ExecFlagType> _controllable_flags;
/// whether user setting of this parameter should be ignored
bool _ignore = false;
};
Metadata & at(const std::string & param)
{
if (_params.count(param) == 0)
mooseError("param '", param, "' not present in InputParams");
return _params[param];
}
const Metadata & at(const std::string & param) const
{
if (_params.count(param) == 0)
mooseError("param '", param, "' not present in InputParams");
return _params.at(param);
}
/**
* Toggle the availability of the copy constructor
*
* When MooseObject is created via the Factory this flag is set to false, so when a MooseObject is
* created if
* the constructor is not a const reference an error is produced. This method allows the
* InputParameterWarehouse
* to disable copying.
*/
void allowCopy(bool status) { _allow_copy = status; }
/**
* Make sure the parameter name doesn't have any invalid characters.
*/
void checkParamName(const std::string & name) const;
/**
* This method is called when adding a Parameter with a default value, can be specialized for
* non-matching types.
*/
template <typename T, typename S>
void setParamHelper(const std::string & name, T & l_value, const S & r_value);
/// original location of input block (i.e. filename,linenum) - used for nice error messages.
std::string _block_location;
/// full HIT path of the block from the input file - used for nice error messages.
std::string _block_fullpath;
/// The actual parameter data. Each Metadata object contains attributes for the corresponding
/// parameter.
std::map<std::string, Metadata> _params;
/// The coupled variables set
std::set<std::string> _coupled_vars;
/// The class description for the owning object. This string is used in many places including
/// mouse-over events, and external documentation produced from the source code.
std::string _class_description;
/// The parameter is used to restrict types that can be built. Typically this is used for
/// MooseObjectAction derived Actions.
std::vector<std::string> _buildable_types;
/// The RelationshipManagers that this object may either build or require.
/// The optional second argument may be supplied to "downgrade" the functionality of the corresponding
/// relationship manager (e.g. An AlgebraicRelationshipManager could be only used as a
/// GeometricRelationshipManager for a given simulation).
std::vector<std::tuple<std::string,
Moose::RelationshipManagerType,
Moose::RelationshipManagerInputParameterCallback>>
_buildable_rm_types;
/// This parameter collapses one level of nesting in the syntax blocks. It is used
/// in conjunction with MooseObjectAction derived Actions.
bool _collapse_nesting;
/// This parameter hides derived MOOSE object types from appearing in syntax dumps
bool _moose_object_syntax_visibility;