Line data Source code
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 : #pragma once
11 :
12 : // MOOSE includes
13 : #include "MooseUtils.h"
14 : #include "MooseError.h"
15 : #include "MooseTypes.h"
16 : #include "MooseEnum.h"
17 : #include "MultiMooseEnum.h"
18 : #include "ExecFlagEnum.h"
19 : #include "Conversion.h"
20 : #include "DataFileUtils.h"
21 : #include "MoosePassKey.h"
22 :
23 : #include "libmesh/parameters.h"
24 :
25 : #ifdef LIBMESH_HAVE_FPARSER
26 : #include "libmesh/fparser.hh"
27 : #else
28 : template <typename T>
29 : class FunctionParserBase
30 : {
31 : }
32 : #endif
33 :
34 : #include <tuple>
35 : #include <unordered_map>
36 : #include <mutex>
37 : #include <optional>
38 : #include <filesystem>
39 : #include <regex>
40 :
41 : #include <gtest/gtest.h>
42 :
43 : // Forward declarations
44 : class Action;
45 : class ActionFactory;
46 : class Factory;
47 : class FEProblemBase;
48 : class InputParameters;
49 : class MooseEnum;
50 : class MooseObject;
51 : class MultiMooseEnum;
52 : class Problem;
53 : namespace hit
54 : {
55 : class Node;
56 : }
57 : namespace Moose
58 : {
59 : class Builder;
60 : }
61 : class CommandLine;
62 :
63 : /**
64 : * The main MOOSE class responsible for handling user-defined
65 : * parameters in almost every MOOSE system.
66 : */
67 : class InputParameters : public libMesh::Parameters
68 : {
69 : public:
70 : InputParameters(const InputParameters & rhs);
71 : InputParameters(const Parameters & rhs);
72 :
73 78059821 : virtual ~InputParameters() = default;
74 :
75 : virtual void clear() override;
76 :
77 : /**
78 : * Structure for storing information about a command line parameter
79 : */
80 : struct CommandLineMetadata
81 : {
82 : enum ArgumentType
83 : {
84 : NONE,
85 : OPTIONAL,
86 : REQUIRED
87 : };
88 :
89 : /// The syntax for the parameter
90 : std::string syntax;
91 : /// The switches for the parameter (i.e., [-t, --timing])
92 : std::vector<std::string> switches;
93 : /// The type of argument
94 : ArgumentType argument_type;
95 : /// Whether or not the argument is required
96 : bool required;
97 : /// Whether or not the parameter was set by the CommandLine
98 : bool set_by_command_line = false;
99 : /// Whether or not the parameter is global (passed to MultiApps)
100 : bool global = false;
101 : };
102 :
103 : /**
104 : * Class that is used as a parameter to setHitNode() that allows only
105 : * relevant classes to set the hit node
106 : */
107 : class SetHitNodeKey
108 : {
109 : friend class Action;
110 : friend class ActionFactory;
111 : friend class Moose::Builder;
112 : friend class Factory;
113 : friend class FEProblemBase;
114 : friend class InputParameters;
115 : FRIEND_TEST(InputParametersTest, fileNames);
116 5448620 : SetHitNodeKey() {}
117 : SetHitNodeKey(const SetHitNodeKey &) {}
118 : };
119 :
120 : /**
121 : * Class that is used as a parameter to setHitNode(param) that allows only
122 : * relevant classes to set the hit node
123 : */
124 : class SetParamHitNodeKey
125 : {
126 : friend class Moose::Builder;
127 : FRIEND_TEST(InputParametersTest, fileNames);
128 2667955 : SetParamHitNodeKey() {}
129 : SetParamHitNodeKey(const SetParamHitNodeKey &) {}
130 : };
131 :
132 : /**
133 : * Determines whether or not the given type is a type that is supported for
134 : * a command line parameter.
135 : *
136 : * In particular, whether or not CommandLine::populateCommandLineParams
137 : * supports extracting these types.
138 : */
139 : template <typename T>
140 : struct isValidCommandLineType
141 : {
142 : static constexpr bool value =
143 : std::is_same_v<T, std::string> || std::is_same_v<T, std::vector<std::string>> ||
144 : std::is_same_v<T, Real> || std::is_same_v<T, unsigned int> || std::is_same_v<T, int> ||
145 : std::is_same_v<T, bool> || std::is_same_v<T, MooseEnum>;
146 : };
147 :
148 : /**
149 : * This method adds a description of the class that will be displayed
150 : * in the input file syntax dump
151 : */
152 : void addClassDescription(const std::string & doc_string);
153 :
154 : /**
155 : * Returns the class description
156 : */
157 : std::string getClassDescription() const;
158 :
159 : /**
160 : * Override from libMesh to set user-defined attributes on our parameter
161 : */
162 : virtual void set_attributes(const std::string & name, bool inserted_only) override;
163 :
164 : /**
165 : * @return The deprecated parameter message for the given parameter, if any
166 : */
167 : std::optional<std::string> queryDeprecatedParamMessage(const std::string & name) const;
168 :
169 : /// This functions is called in set as a 'callback' to avoid code duplication
170 : template <typename T>
171 : void setHelper(const std::string & name);
172 :
173 : /**
174 : * Returns a writable reference to the named parameters. Note: This is not a virtual
175 : * function! Use caution when comparing to the parent class implementation
176 : * @param name The name of the parameter to set
177 : * @param quiet_mode When true the parameter is kept with set_by_add_param=true,
178 : * this is generally not needed.
179 : *
180 : * "quite_mode" returns a writable reference to the named parameter, without setting
181 : * set_by_add_param to false. Using this method of set will make the parameter to continue to
182 : * behave if its value where set ONLY by addParam and not by any other method.
183 : *
184 : * This was added for handling parameters in the Output objects that have behavior dependent
185 : * on whether the user modified the parameters.
186 : *
187 : */
188 : template <typename T>
189 : T & set(const std::string & name, bool quiet_mode = false);
190 :
191 : /**
192 : * Given a series of parameters names and values, sets each name to
193 : * the corresponding value. Any number of name, value pairs can be
194 : * supplied.
195 : *
196 : * Note that each \p value must be of the correct type for the
197 : * parameter of that name, not merely of a type convertible to the
198 : * correct type.
199 : *
200 : * @param name The name of the first parameter to set
201 : */
202 : template <typename T, typename... Ts>
203 : void setParameters(const std::string & name, const T & value, Ts... extra_input_parameters);
204 :
205 : /**
206 : * Runs a range on the supplied parameter if it exists and throws an error if that check fails.
207 : * @returns Optional of whether or not the error is a user error (false = developer error) and
208 : * the associated error
209 : *
210 : * If \p include_param_path = true, include the parameter path in the error message
211 : */
212 : ///@{
213 : template <typename T, typename UP_T>
214 : std::optional<std::pair<bool, std::string>>
215 : rangeCheck(const std::string & full_name,
216 : const std::string & short_name,
217 : const InputParameters::Parameter<T> & param,
218 : const bool include_param_path = true);
219 : template <typename T, typename UP_T>
220 : std::optional<std::pair<bool, std::string>>
221 : rangeCheck(const std::string & full_name,
222 : const std::string & short_name,
223 : const InputParameters::Parameter<std::vector<T>> & param,
224 : const bool include_param_path = true);
225 : ///@}
226 : /**
227 : * Verifies that the requested parameter exists and is not NULL and returns it to the caller.
228 : * The template parameter must be a pointer or an error will be thrown.
229 : */
230 : template <typename T>
231 : T getCheckedPointerParam(const std::string & name, const std::string & error_string = "") const;
232 :
233 : /**
234 : * This method adds a parameter and documentation string to the InputParameters
235 : * object that will be extracted from the input file. If the parameter is
236 : * missing in the input file, an error will be thrown
237 : */
238 : template <typename T>
239 : void addRequiredParam(const std::string & name, const std::string & doc_string);
240 :
241 : /**
242 : * This version of addRequiredParam is here for a consistent use with MooseEnums. Use of
243 : * this function for any other type will throw an error.
244 : */
245 : template <typename T>
246 : void
247 : addRequiredParam(const std::string & name, const T & moose_enum, const std::string & doc_string);
248 :
249 : ///@{
250 : /**
251 : * These methods add an optional parameter and a documentation string to the InputParameters
252 : * object. The first version of this function takes a default value which is used if the parameter
253 : * is not found in the input file. The second method will leave the parameter uninitialized but
254 : * can be checked with "isParamValid" before use.
255 : */
256 : template <typename T, typename S>
257 : void addParam(const std::string & name, const S & value, const std::string & doc_string);
258 : template <typename T>
259 : void addParam(const std::string & name, const std::string & doc_string);
260 : ///@}
261 :
262 : /**
263 : * Enable support for initializer lists as default arguments for container type.
264 : */
265 : template <typename T>
266 8195707 : void addParam(const std::string & name,
267 : const std::initializer_list<typename T::value_type> & value,
268 : const std::string & doc_string)
269 : {
270 16391414 : addParam<T>(name, T{value}, doc_string);
271 8195707 : }
272 :
273 : ///@{
274 : // BEGIN RANGE CHECKED PARAMETER METHODS
275 : /**
276 : * These methods add an range checked parameters. A lower and upper bound can be supplied and the
277 : * supplied parameter will be checked to fall within that range.
278 : */
279 : template <typename T>
280 : void addRequiredRangeCheckedParam(const std::string & name,
281 : const std::string & parsed_function,
282 : const std::string & doc_string);
283 : template <typename T>
284 : void addRangeCheckedParam(const std::string & name,
285 : const T & value,
286 : const std::string & parsed_function,
287 : const std::string & doc_string);
288 : template <typename T>
289 : void addRangeCheckedParam(const std::string & name,
290 : const std::string & parsed_function,
291 : const std::string & doc_string);
292 : // END RANGE CHECKED PARAMETER METHODS
293 : ///@}
294 :
295 : /**
296 : * These methods add an option parameter and with a customer type to the InputParameters object.
297 : * The custom type will be output in YAML dumps and can be used within the GUI application.
298 : */
299 : template <typename T>
300 : void addRequiredCustomTypeParam(const std::string & name,
301 : const std::string & custom_type,
302 : const std::string & doc_string);
303 : template <typename T>
304 : void addCustomTypeParam(const std::string & name,
305 : const T & value,
306 : const std::string & custom_type,
307 : const std::string & doc_string);
308 : template <typename T>
309 : void addCustomTypeParam(const std::string & name,
310 : const std::string & custom_type,
311 : const std::string & doc_string);
312 : template <typename T>
313 : void addDeprecatedCustomTypeParam(const std::string & name,
314 : const std::string & custom_type,
315 : const std::string & doc_string,
316 : const std::string & deprecation_msg);
317 :
318 : /**
319 : * These method add a parameter to the InputParameters object which can be retrieved like any
320 : * other parameter. This parameter however is not printed in the Input file syntax dump or web
321 : * page dump so does not take a documentation string. The first version of this function takes an
322 : * optional default value.
323 : */
324 : template <typename T>
325 : void addPrivateParam(const std::string & name, const T & value);
326 : template <typename T>
327 : void addPrivateParam(const std::string & name);
328 :
329 : /**
330 : * Add parameters for retrieval from the command line.
331 : *
332 : * NOTE: This ONLY works for App objects! This is not valid for normal MOOSE objects!
333 : *
334 : * @param name The name of the parameter
335 : * @param syntax Space separated list of command-line switch syntax that can set this option
336 : * @param doc_string Documentation. This will be shown for --help
337 : */
338 : template <typename T>
339 : void addRequiredCommandLineParam(const std::string & name,
340 : const std::string & syntax,
341 : const std::string & doc_string);
342 : template <typename T>
343 : void addCommandLineParam(const std::string & name,
344 : const std::string & syntax,
345 : const std::string & doc_string);
346 : template <typename T>
347 : void addCommandLineParam(const std::string & name,
348 : const std::string & syntax,
349 : const T & value,
350 : const std::string & doc_string);
351 : template <typename T>
352 4 : void addCommandLineParam(const std::string & name,
353 : const std::string & syntax,
354 : const std::initializer_list<typename T::value_type> & value,
355 : const std::string & doc_string)
356 : {
357 8 : addCommandLineParam<T>(name, syntax, T{value}, doc_string);
358 4 : }
359 :
360 : /**
361 : * Add a command line parameter with an optional value.
362 : *
363 : * This is a deprecated option and only remains for two parameters:
364 : * "mesh_only" and "recover". There are issues with command line
365 : * parameters with optional values because if a value following
366 : * one of these is a hit cli parameter, we don't know if we should
367 : * apply it to the optional option or as a hit parameter.
368 : *
369 : * It is also allowed for "run" as we take all arguments past
370 : * --run and pass to python.
371 : *
372 : * @param name The name of the parameer
373 : * @param syntax Space separated list of command-line switch syntax that can set this option
374 : * @param value The default value to assign
375 : * @param doc_string Documentation. This will be shown for --help
376 : */
377 : template <typename T>
378 : void addOptionalValuedCommandLineParam(const std::string & name,
379 : const std::string & syntax,
380 : const T & value,
381 : const std::string & doc_string);
382 :
383 : /**
384 : * Sets the command line parameter with \p name as global.
385 : *
386 : * Global here means that it will be passed to all child MultiApps.
387 : */
388 : void setGlobalCommandLineParam(const std::string & name);
389 :
390 : /**
391 : * @param name The name of the parameter
392 : * @param value The default value of this parameter if it requires one
393 : * @param doc_string Documentation. This will be shown for --help
394 : * @param deprecation_message The message that will will print about why this param was
395 : * deprecated. It might mention the "new way".
396 : */
397 : template <typename T>
398 : void addDeprecatedParam(const std::string & name,
399 : const T & value,
400 : const std::string & doc_string,
401 : const std::string & deprecation_message);
402 :
403 : template <typename T>
404 : void addDeprecatedParam(const std::string & name,
405 : const std::string & doc_string,
406 : const std::string & deprecation_message);
407 :
408 : /**
409 : * This method checks to make sure that we aren't adding a parameter with the same name but a
410 : * different type. It
411 : * throws a MooseError if an inconsistent type is detected. While this state is supported by
412 : * libMesh it brings
413 : * nothing but blood and tears for those who try ;)
414 : *
415 : * @param name the name of the parameter
416 : */
417 : template <typename T>
418 : void checkConsistentType(const std::string & name) const;
419 :
420 : /**
421 : * @return Whether or not the parameter \p name is a command line parameter
422 : */
423 : bool isCommandLineParameter(const std::string & name) const;
424 :
425 : /**
426 : * @return Queries for the command line metadata for the parameter \p name
427 : *
428 : * Will return an empty optional if the parameter is not a command line param.
429 : */
430 : std::optional<InputParameters::CommandLineMetadata>
431 : queryCommandLineMetadata(const std::string & name) const;
432 :
433 : /**
434 : * @return The command line metadata for the parameter \p name.
435 : */
436 : const InputParameters::CommandLineMetadata &
437 : getCommandLineMetadata(const std::string & name) const;
438 :
439 : /**
440 : * Class that is used as a parameter to commandLineParamSet() that allows only
441 : * the CommandLine to set that a parmeter is set by the command line
442 : */
443 : class CommandLineParamSetKey
444 : {
445 : friend class CommandLine;
446 : FRIEND_TEST(InputParametersTest, commandLineParamSetNotCLParam);
447 459178 : CommandLineParamSetKey() {}
448 : CommandLineParamSetKey(const CommandLineParamSetKey &) {}
449 : };
450 : /**
451 : * Marks the command line parameter \p name as set by the CommandLine.
452 : *
453 : * Protected by the CommandLineParamSetKey so that only the CommandLine can call this.
454 : */
455 : void commandLineParamSet(const std::string & name, const CommandLineParamSetKey);
456 :
457 : /**
458 : * Get the documentation string for a parameter
459 : */
460 : const std::string & getDescription(const std::string & name) const;
461 :
462 : /**
463 : * This method takes a space delimited list of parameter names and adds them to the specified
464 : * group name.
465 : * This information is used in the GUI to group parameters into logical sections.
466 : */
467 : void addParamNamesToGroup(const std::string & space_delim_names, const std::string group_name);
468 :
469 : /**
470 : * This method renames a parameter group
471 : * @param old_name previous name of the parameter group
472 : * @param new_name new name of the parameter group
473 : */
474 : void renameParameterGroup(const std::string & old_name, const std::string & new_name);
475 :
476 : /**
477 : * This method retrieves the group name for the passed parameter name if one exists. Otherwise an
478 : * empty string is returned.
479 : */
480 : std::string getGroupName(const std::string & param_name) const;
481 :
482 : /**
483 : * This method suppresses an inherited parameter so that it isn't required or valid
484 : * in the derived class. The parameter is added to the private parameter list.
485 : * Suppressing a parameter can have dire consequences.
486 : * Use at your own risk!
487 : */
488 : template <typename T>
489 : void suppressParameter(const std::string & name);
490 :
491 : /**
492 : * Changes the parameter to be required.
493 : * @param name The parameter name
494 : */
495 : template <typename T>
496 : void makeParamRequired(const std::string & name);
497 :
498 : /**
499 : * Changes the parameter to not be required.
500 : * @param name The parameter name
501 : */
502 : template <typename T>
503 : void makeParamNotRequired(const std::string & name);
504 :
505 : /**
506 : * This method adds a coupled variable name pair. The parser will look for variable
507 : * name pair in the input file and can return a reference to the storage location
508 : * for the coupled variable if found
509 : */
510 : void addCoupledVar(const std::string & name, const std::string & doc_string);
511 :
512 : /**
513 : * This method adds a deprecated coupled variable name pair. The parser will look for variable
514 : * name pair in the input file and can return a reference to the storage location
515 : * for the coupled variable if found. The doc string for the deprecated variable will be
516 : * constructed from the doc string for the new variable. A deprecation message will also be
517 : * automatically generated
518 : */
519 : void addDeprecatedCoupledVar(const std::string & old_name,
520 : const std::string & new_name,
521 : const std::string & removal_date = "");
522 :
523 : /**
524 : * This method adds a coupled variable name pair. The parser will look for variable
525 : * name pair in the input file and can return a reference to the storage location
526 : * for the coupled variable if found
527 : *
528 : * Also - you can provide a default value for this variable in the case that an actual variable is
529 : * not provided.
530 : */
531 : void addCoupledVar(const std::string & name, const Real value, const std::string & doc_string);
532 :
533 : /**
534 : * This method adds a coupled variable name pair. The parser will look for variable
535 : * name pair in the input file and can return a reference to the storage location
536 : * for the coupled variable if found
537 : *
538 : * Also - you can provide a vector of values for this variable in the case that an actual variable
539 : * is not provided.
540 : */
541 : void addCoupledVar(const std::string & name,
542 : const std::vector<Real> & value,
543 : const std::string & doc_string);
544 :
545 : ///@{
546 : /**
547 : * These methods add a coupled variable name pair. The parser will look for variable
548 : * name pair in the input file and can return a reference to the storage location
549 : * for the coupled variable if found.
550 : *
551 : * This version of the method will build a vector if the given the base_name and num_name
552 : * parameters exist
553 : * in the input file:
554 : * e.g.
555 : * [./foo]
556 : * ...
557 : * some_base = base_
558 : * some_num = 5
559 : * [../]
560 : *
561 : * # The coupling parameter will be passed this vector: "base_0 base_1 base_2 base_3 base_4"
562 : */
563 : void addCoupledVarWithAutoBuild(const std::string & name,
564 : const std::string & base_name,
565 : const std::string & num_name,
566 : const std::string & doc_string);
567 : void addRequiredCoupledVarWithAutoBuild(const std::string & name,
568 : const std::string & base_name,
569 : const std::string & num_name,
570 : const std::string & doc_string);
571 : ///@}
572 :
573 : /**
574 : * Utility functions for retrieving one of the MooseTypes variables into the common "string" base
575 : * class.
576 : * Scalar and Vector versions are supplied
577 : */
578 : std::string getMooseType(const std::string & name) const;
579 : std::vector<std::string> getVecMooseType(const std::string & name) const;
580 :
581 : /**
582 : * @returns Whether or not these parameters are for a MooseBase object, that is,
583 : * one with a name and type.
584 : *
585 : * Needed so that we can produce richer errors from within InputParameters
586 : * that have the context of the underlying object, if possible.
587 : */
588 : bool isMooseBaseObject() const;
589 :
590 : /**
591 : * @return The object type represented by these parameters, if any
592 : */
593 : const std::string * queryObjectType() const;
594 :
595 : /**
596 : * @returns The underlying owning object type, for MooseBase objects with parameters
597 : *
598 : * Will error if a type does not exist
599 : */
600 : const std::string & getObjectType() const;
601 : /**
602 : * @returns The underlying owning object name, for MooseBase objects with parameters
603 : */
604 : const std::string & getObjectName() const;
605 :
606 : /**
607 : * This method adds a coupled variable name pair. The parser will look for variable
608 : * name pair in the input file and can return a reference to the storage location
609 : * for the coupled variable. If the coupled variable is not supplied in the input
610 : * file, and error is thrown.
611 : *
612 : * Version 2: An auto built vector will be built from the base_name and num_name param. See
613 : * addCoupledVar for an example
614 : */
615 : void addRequiredCoupledVar(const std::string & name, const std::string & doc_string);
616 :
617 : /**
618 : * Returns the documentation string for the specified parameter name
619 : */
620 : std::string getDocString(const std::string & name) const;
621 :
622 : /**
623 : * Set the doc string of a parameter.
624 : *
625 : * This method is generally used from within the validParams function to modify the documentation
626 : * for an
627 : * existing parameter, such as a parameter that is supplied from an interface class.
628 : */
629 : void setDocString(const std::string & name, const std::string & doc);
630 :
631 : /**
632 : * Returns the documentation unit string for the specified parameter name
633 : */
634 : std::string getDocUnit(const std::string & name) const;
635 :
636 : /**
637 : * Set the unit string of a parameter.
638 : *
639 : * This method is only used within MooseDocs and the input syntax dump in order to provide a
640 : * developer-expected unit for software quality assurance purposes.
641 : */
642 : void setDocUnit(const std::string & name, const std::string & doc_unit);
643 :
644 : /**
645 : * Returns a boolean indicating whether the specified parameter is required or not
646 : */
647 : bool isParamRequired(const std::string & name) const;
648 :
649 : /**
650 : * Forces parameter of given name to be not required regardless of type
651 : */
652 : void makeParamNotRequired(const std::string & name);
653 :
654 : /**
655 : * This method returns parameters that have been initialized in one fashion or another,
656 : * i.e. The value was supplied as a default argument or read and properly converted from
657 : * the input file
658 : */
659 : bool isParamValid(const std::string & name) const;
660 :
661 : /**
662 : * Returns whether or not the parameter was set due to addParam. If not then it was either set
663 : * programmatically
664 : * or was read through the input file.
665 : */
666 : bool isParamSetByAddParam(const std::string & name) const;
667 :
668 : /**
669 : * Returns True if the parameters is deprecated.
670 : */
671 : bool isParamDeprecated(const std::string & name) const;
672 :
673 : #ifdef MOOSE_KOKKOS_ENABLED
674 : /**
675 : * Returns whether this InputParameters belongs to a Kokkos object
676 : * Checks whether MooseBase::kokkos_object_param is valid
677 : */
678 : bool isKokkosObject() const;
679 : #endif
680 :
681 : /**
682 : * This method returns true if all of the parameters in this object are valid
683 : * (i.e. isParamValid(name) == true - for all parameters)
684 : */
685 : bool areAllRequiredParamsValid() const;
686 :
687 : /**
688 : * Prints the type of the requested parameter by name
689 : */
690 : std::string type(const std::string & name) const;
691 :
692 : /**
693 : * Returns a Boolean indicating whether the specified parameter is private or not
694 : */
695 : bool isPrivate(const std::string & name) const;
696 :
697 : /**
698 : * Declare the given parameters as controllable
699 : */
700 : void declareControllable(const std::string & name, std::set<ExecFlagType> execute_flags = {});
701 :
702 : /**
703 : * Marker a parameter that has been changed by the Control system (this is for output purposes)
704 : */
705 : void markControlled(const std::string & name);
706 :
707 : /**
708 : * Returns a Boolean indicating whether the specified parameter is controllable
709 : */
710 : bool isControllable(const std::string & name) const;
711 :
712 : /**
713 : * Return the allowed execute flags for a controllable parameter
714 : */
715 : const std::set<ExecFlagType> & getControllableExecuteOnTypes(const std::string & name) const;
716 :
717 : /**
718 : * This method must be called from every base "Moose System" to create linkage with the Action
719 : * System.
720 : * See "Moose.C" for the registerMooseObjectTask() calls.
721 : */
722 : void registerBase(const std::string & value);
723 :
724 : /**
725 : * @return Whether or not the object has a registered base
726 : *
727 : * The base is registered with registerBase()
728 : */
729 : bool hasBase() const;
730 :
731 : /**
732 : * @return The base system of the object these parameters are for, if any
733 : *
734 : * Set via registerBase().
735 : */
736 : const std::string & getBase() const;
737 :
738 : /**
739 : * This method is used to define the MOOSE system name that is used by the TheWarehouse object
740 : * for storing objects to be retrieved for execution. The base class of every object class
741 : * that will be called for execution (e.g., UserObject objects) should call this method.
742 : *
743 : * This is different from registerBase because the name supplied to registerBase is used to
744 : * associate syntax, but the objects created often go to the same objects for execution, as is
745 : * the case for Postprocessor object which are executed with UserObjects.
746 : *
747 : * See the AttribSystem object for use Attribute.h/C.
748 : */
749 : void registerSystemAttributeName(const std::string & value);
750 :
751 : /**
752 : * Get the system attribute name if it was registered. Otherwise throw an error.
753 : * See the AttribSystem object for use Attribute.h/C.
754 : */
755 : const std::string & getSystemAttributeName() const;
756 :
757 : /**
758 : * This method is here to indicate which Moose types a particular Action may build. It takes a
759 : * space delimited list of registered MooseObjects. TODO: For now we aren't actually checking
760 : * this list when we build objects. Since individual actions can do whatever they want it's not
761 : * exactly trivial to check this without changing the user API. This function properly restricts
762 : * the syntax and YAML dumps.
763 : */
764 : void registerBuildableTypes(const std::string & names);
765 :
766 : /**
767 : * Tells MOOSE about a RelationshipManager that this object needs. RelationshipManagers
768 : * handle element "ghosting", "non-local DOF access" and "sparsity pattern" relationships.
769 : *
770 : * Basically: if this object needs non-local (ie non-current-element) data access then you
771 : * probably need a relationship manager
772 : *
773 : * @param name The name of the RelationshipManager type
774 : * @param rm_type The type (GEOMETRIC/ALGEBRAIC) of the RelationshipManger. Note: You can use
775 : * boolean logic to to "or" RelationshipManagerTypes together to make a RelationshipManager that
776 : * is multi-typed.
777 : * @param input_parameter_callback This is a function pointer that will get called to fill in the
778 : * RelationShipManager's InputParameters. See MooseTypes.h for the signature of this function.
779 : */
780 : void addRelationshipManager(
781 : const std::string & name,
782 : Moose::RelationshipManagerType rm_type,
783 : Moose::RelationshipManagerInputParameterCallback input_parameter_callback = nullptr);
784 :
785 : /**
786 : * Clears all currently registered RelationshipManagers
787 : */
788 6810 : void clearRelationshipManagers() { _buildable_rm_types.clear(); }
789 :
790 : /**
791 : * Returns the list of buildable types as a std::vector<std::string>
792 : */
793 : const std::vector<std::string> & getBuildableTypes() const;
794 :
795 : /**
796 : * Returns the list of buildable (or required) RelationshipManager object types for this object.
797 : */
798 : const std::vector<std::tuple<std::string,
799 : Moose::RelationshipManagerType,
800 : Moose::RelationshipManagerInputParameterCallback>> &
801 : getBuildableRelationshipManagerTypes() const;
802 :
803 : ///@{
804 : /**
805 : * Mutators for controlling whether or not the outermost level of syntax will be collapsed when
806 : * printed.
807 : */
808 : void collapseSyntaxNesting(bool collapse);
809 : bool collapseSyntaxNesting() const;
810 : ///@}
811 :
812 : ///@{
813 : /**
814 : * Mutators for controlling whether or not the outermost level of syntax will be collapsed when
815 : * printed.
816 : */
817 : void mooseObjectSyntaxVisibility(bool visibility);
818 : bool mooseObjectSyntaxVisibility() const;
819 : ///@}
820 :
821 : ///@{
822 : /**
823 : * Copy and Copy/Add operators for the InputParameters object
824 : */
825 : using Parameters::operator=;
826 : using Parameters::operator+=;
827 : InputParameters & operator=(const InputParameters & rhs);
828 : InputParameters & operator+=(const InputParameters & rhs);
829 : ///@}
830 :
831 : /**
832 : * This function checks parameters stored in the object to make sure they are in the correct
833 : * state as the user expects:
834 : * Required parameters are verified as valid meaning that they were either initialized when
835 : * they were created, or were read from an input file or some other valid source
836 : */
837 : void checkParams(const std::string & parsing_syntax);
838 :
839 : /**
840 : * Performs a range check on the parameter (which must have a range check)
841 : *
842 : * @param value The parameter value
843 : * @param long_name The full path to the parameter
844 : * @param short_name The name of the parameter
845 : * @param include_param_path Whether or not to include the parameter path in errors
846 : * @return An error, if any; first is whether or not it is a user error and second is the message
847 : */
848 : std::optional<std::pair<bool, std::string>> parameterRangeCheck(const Parameters::Value & value,
849 : const std::string & long_name,
850 : const std::string & short_name,
851 : const bool include_param_path);
852 :
853 : /**
854 : * Finalizes the parameters, which must be done before constructing any objects
855 : * with these parameters (to be called in the corresponding factories).
856 : * typed parameters.
857 : *
858 : * This calls checkParams() and sets up the absolute paths for all file name.
859 : */
860 : void finalize(const std::string & parsing_syntax);
861 :
862 : /**
863 : * @return A file base to associate with these parameters.
864 : *
865 : * Optionally, an input parameter can be provided via \p param_name.
866 : *
867 : * If the parameter is provided, we have the following options:
868 : * - The parameter itself has a hit node set (context for that parameter)
869 : * - The InputParameters object has a hit node set (context for all parameters)
870 : * - Neither of the above and we die
871 : *
872 : * In the event that a the parameter is set via command line, this will
873 : * attempt to look at the parameter's parents to find a suitable context.
874 : */
875 : std::filesystem::path
876 : getFileBase(const std::optional<std::string> & param_name = std::optional<std::string>()) const;
877 :
878 : /**
879 : * Methods returning iterators to the coupled variables names stored in this
880 : * InputParameters object
881 : */
882 960210 : inline std::set<std::string>::const_iterator coupledVarsBegin() const
883 : {
884 960210 : return _coupled_vars.begin();
885 : }
886 1370799 : inline std::set<std::string>::const_iterator coupledVarsEnd() const
887 : {
888 1370799 : return _coupled_vars.end();
889 : }
890 :
891 : /**
892 : * Return the coupled variable parameter names.
893 : */
894 4749 : const std::set<std::string> & getCoupledVariableParamNames() const { return _coupled_vars; }
895 :
896 : /**
897 : * Return the new to deprecated variable name map
898 : */
899 374913 : const std::unordered_map<std::string, std::string> & getNewToDeprecatedVarMap() const
900 : {
901 374913 : return _new_to_deprecated_coupled_vars;
902 : }
903 :
904 : /// Return whether a parameter has a range check
905 : bool isRangeChecked(const std::string & param_name) const;
906 :
907 : /// Return the range check function for any parameter (empty string if it is not range checked)
908 : std::string rangeCheckedFunction(const std::string & name) const;
909 :
910 : /// Return whether a parameter has a default
911 : bool hasDefault(const std::string & param_name) const;
912 :
913 : /**
914 : * Return whether or not the coupled variable exists
915 : * @param coupling_name The name of the coupled variable to test for
916 : * @return True if the variable exists in the coupled variables for this InputParameters object
917 : */
918 : bool hasCoupledVar(const std::string & coupling_name) const;
919 :
920 : /**
921 : * Return whether or not the coupled variable exists
922 : * @param coupling_name The name of the coupled variable to test for
923 : * @return True if the variable exists in the coupled variables for this InputParameters object
924 : */
925 : bool hasCoupledValue(const std::string & coupling_name) const
926 : {
927 : mooseDeprecated("InputParameters::hasCoupledValue() is deprecated. Use "
928 : "InputParameters::hasCoupledVar() instead.");
929 : return hasCoupledVar(coupling_name);
930 : }
931 :
932 : /**
933 : * Set a coupled variable parameter to a single variable name.
934 : *
935 : * @param coupling_name The name of the coupling parameter to set.
936 : * @param value The variable name to set.
937 : */
938 : void setCoupledVar(const std::string & coupling_name, const std::string & value);
939 :
940 : /**
941 : * Set a coupled variable parameter to multiple variable names.
942 : *
943 : * @param coupling_name The name of the coupling parameter to set.
944 : * @param values The variable names to set.
945 : */
946 : void setCoupledVar(const std::string & coupling_name, const std::vector<VariableName> & values);
947 :
948 : /**
949 : * Get a coupled variable parameter.
950 : *
951 : * @param coupling_name The name of the coupling parameter to get.
952 : */
953 : const std::vector<VariableName> & getCoupledVar(const std::string & coupling_name) const;
954 :
955 : /**
956 : * Return whether or not the requested parameter has a default coupled value.
957 : *
958 : * @param coupling_name The name of the coupling parameter to get the default value for.
959 : */
960 : bool hasDefaultCoupledValue(const std::string & coupling_name) const;
961 :
962 : /**
963 : * Get the default value for an optionally coupled variable.
964 : *
965 : * @param coupling_name The name of the coupling parameter to get the default value for.
966 : * @param i By default 0, in general the index of the requested coupled default value.
967 : */
968 : Real defaultCoupledValue(const std::string & coupling_name, unsigned int i = 0) const;
969 :
970 : /**
971 : * Get the number of defaulted coupled value entries
972 : *
973 : * @param coupling_name The name of the coupling parameter to get the default value for.
974 : */
975 : unsigned int numberDefaultCoupledValues(const std::string & coupling_name) const;
976 :
977 : /**
978 : * Set the default value for an optionally coupled variable (called by the Parser).
979 : *
980 : * @param coupling_name The name of the coupling parameter to get the default value for.
981 : * @param value Default value to set.
982 : * @param i By default 0, in general the index of the requested coupled default value.
983 : */
984 : void defaultCoupledValue(const std::string & coupling_name, Real value, unsigned int i = 0);
985 :
986 : /**
987 : * Returns the auto build vectors for all parameters.
988 : */
989 : std::map<std::string, std::pair<std::string, std::string>> getAutoBuildVectors() const;
990 :
991 : // BEGIN APPLY PARAMETER METHODS
992 : /**
993 : * Method for applying common parameters
994 : * @param common The set of parameters to apply to the parameters stored in this object
995 : * @param exclude A vector of parameters to exclude
996 : *
997 : * In order to apply common parameter 4 statements must be satisfied
998 : * (1) A local parameter must exist with the same name as common parameter
999 : * (2) Common parameter must be valid
1000 : * (3) Local parameter must be invalid OR not have been set from its default
1001 : * (4) Both cannot be private (unless \p allow_private = true)
1002 : *
1003 : * Output objects have a set of common parameters that are passed
1004 : * down to each of the output objects created. This method is used for
1005 : * applying those common parameters.
1006 : *
1007 : * @see CommonOutputAction AddOutputAction
1008 : */
1009 : void applyParameters(const InputParameters & common,
1010 : const std::vector<std::string> & exclude = {},
1011 : const bool allow_private = false);
1012 :
1013 : /**
1014 : * Variant of applyParameters that only applies parameters explicitly set by the user in
1015 : * @p common (i.e. isParamSetByUser() is true). Object-type defaults are therefore never
1016 : * overridden by common-block defaults, only by values the user actually wrote.
1017 : */
1018 : void applyCommonUserSetParameters(const InputParameters & common,
1019 : const std::vector<std::string> & exclude = {},
1020 : const bool allow_private = false);
1021 :
1022 : /**
1023 : * Method for applying common parameters
1024 : * @param common The set of parameters to apply to the parameters stored in this object
1025 : * @param include A vector of parameters to apply
1026 : *
1027 : * In order to apply common parameter 4 statements must be satisfied
1028 : * (1) A local parameter must exist with the same name as common parameter
1029 : * (2) Common parameter must valid
1030 : * (3) Local parameter must be invalid OR not have been set from its default
1031 : * (4) Both cannot be private
1032 : *
1033 : * Output objects have a set of common parameters that are passed
1034 : * down to each of the output objects created. This method is used for
1035 : * applying those common parameters.
1036 : *
1037 : * @see CommonOutputAction AddOutputAction
1038 : */
1039 : void applySpecificParameters(const InputParameters & common,
1040 : const std::vector<std::string> & include,
1041 : bool allow_private = false);
1042 :
1043 : /**
1044 : * Apply values from a single parameter in common, to a single parameter stored in this object
1045 : * @param common The set of InputParameters from which to extract parameters from
1046 : * @param common_name The name within common from which to get the parameter values
1047 : *
1048 : * In order to apply common parameter 4 statements must be satisfied
1049 : * (1) A local parameter must exist with the same name as common parameter
1050 : * (2) Common parameter must valid
1051 : * (3) Local parameter must be invalid OR not have been set from its default
1052 : * (4) Both cannot be private
1053 : */
1054 : void applyParameter(const InputParameters & common,
1055 : const std::string & common_name,
1056 : bool allow_private = false);
1057 : // END APPLY PARAMETER METHODS
1058 :
1059 : /**
1060 : * Apply properties of a single coupled variable in common, to a single coupled variable stored in
1061 : * this object
1062 : * @param common The set of InputParameters from which to extract the coupled variable's
1063 : * properties
1064 : * @param var_name The name of the coupled variable whose properties are to be applied
1065 : *
1066 : * In order to apply the properties, both the local parameters and the common parameters must
1067 : * have a coupled variable with name var_name
1068 : */
1069 : void applyCoupledVar(const InputParameters & common, const std::string & var_name);
1070 :
1071 : /**
1072 : * Deprecated method. Use isParamSetByUser() instead.
1073 : */
1074 : bool paramSetByUser(const std::string & name) const;
1075 :
1076 : /**
1077 : * Method returns true if the parameter was set by the user
1078 : * @param name The parameter name
1079 : */
1080 : bool isParamSetByUser(const std::string & name) const;
1081 :
1082 : /**
1083 : * Method returns true if the parameter is defined for any type. If the
1084 : * type is known, use have_parameter<T>() instead.
1085 : * @param name The parameter name
1086 : */
1087 : bool isParamDefined(const std::string & name) const;
1088 :
1089 : /**
1090 : * Query a parameter
1091 : *
1092 : * If the parameter is not valid, nullptr will be returned
1093 : *
1094 : * @param name The name of the parameter
1095 : * @return A pointer to the parameter value, if it exists
1096 : */
1097 : template <typename T>
1098 : const T * queryParam(const std::string & name) const;
1099 :
1100 : ///@{
1101 : /*
1102 : * These methods are here to retrieve parameters for scalar and vector types respectively. We will
1103 : * throw errors
1104 : * when returning most scalar and vector types.
1105 : */
1106 : template <typename T>
1107 : static const T & getParamHelper(const std::string & name, const InputParameters & pars);
1108 : ///@}
1109 :
1110 : using Parameters::get;
1111 :
1112 : /// Combine two vector parameters into a single vector of pairs
1113 : template <typename R1,
1114 : typename R2,
1115 : typename V1 = typename std::conditional<std::is_same<R1, MooseEnumItem>::value,
1116 : MultiMooseEnum,
1117 : std::vector<R1>>::type,
1118 : typename V2 = typename std::conditional<std::is_same<R2, MooseEnumItem>::value,
1119 : MultiMooseEnum,
1120 : std::vector<R2>>::type>
1121 : std::vector<std::pair<R1, R2>> get(const std::string & param1, const std::string & param2) const;
1122 :
1123 : /**
1124 : * @returns list of all parameters
1125 : */
1126 : std::set<std::string> getParametersList() const;
1127 :
1128 : /**
1129 : * Return list of controllable parameters
1130 : */
1131 : std::set<std::string> getControllableParameters() const;
1132 :
1133 : /**
1134 : * Return names of parameters within a group.
1135 : */
1136 : std::set<std::string> getGroupParameters(const std::string & group) const;
1137 :
1138 : /**
1139 : * Provide a set of reserved values for a parameter. These are values that are in addition
1140 : * to the normal set of values the parameter can take.
1141 : */
1142 : void setReservedValues(const std::string & name, const std::set<std::string> & reserved);
1143 :
1144 : /**
1145 : * Get a set of reserved parameter values.
1146 : * Returns a set by value since we can return an empty set.
1147 : */
1148 : std::set<std::string> reservedValues(const std::string & name) const;
1149 :
1150 : /**
1151 : * @return A string representing the location (i.e. filename,linenum) in the input text for the
1152 : * block containing parameters for this object.
1153 : */
1154 : std::string blockLocation() const;
1155 :
1156 : /**
1157 : * @return A string representing the full HIT parameter path from the input file (e.g.
1158 : * "Mesh/foo") for the block containing parameters for this object.
1159 : */
1160 : std::string blockFullpath() const;
1161 :
1162 : /**
1163 : * @return The hit node associated with setting the parameter \p param, if any
1164 : */
1165 : const hit::Node * getHitNode(const std::string & param) const;
1166 : /**
1167 : * Sets the hit node associated with the parameter \p param to \p node
1168 : *
1169 : * Is protected to be called by only the Builder via the SetParamHitNodeKey.
1170 : */
1171 : void setHitNode(const std::string & param, const hit::Node & node, const SetParamHitNodeKey);
1172 :
1173 : /**
1174 : * @return A string representing the location in the input text the parameter originated from
1175 : * (i.e. filename,linenum) for the given param
1176 : */
1177 : std::string inputLocation(const std::string & param) const;
1178 :
1179 : /**
1180 : * @return A string representing the full HIT parameter path from the input file (e.g.
1181 : * "Mesh/foo/bar" for param "bar") for the given param.
1182 : */
1183 : std::string paramFullpath(const std::string & param) const;
1184 :
1185 : /**
1186 : * Returns a prefix containing the parameter name and location (if available)
1187 : */
1188 : std::string paramLocationPrefix(const std::string & param) const;
1189 :
1190 : /**
1191 : * @return A message used as a prefix for output relating to a parameter.
1192 : *
1193 : * Will first prefix with a path to the parameter, or the parameter that
1194 : * resulted in the creation of these parameters, if available. The message
1195 : * will then be prefixed with the block path to the parameter, if available.
1196 : */
1197 : template <typename... Args>
1198 : std::string paramMessage(const std::string & param, Args... args) const;
1199 :
1200 : /**
1201 : * Emits an error prefixed with the object information, if available.
1202 : */
1203 : template <typename... Args>
1204 : [[noreturn]] void mooseError(Args &&... args) const;
1205 :
1206 : /**
1207 : * Emits a parameter error prefixed with the parameter location and
1208 : * object information if available.
1209 : */
1210 : template <typename... Args>
1211 : [[noreturn]] void paramError(const std::string & param, Args... args) const;
1212 :
1213 : /**
1214 : * @return A string representing the raw, unmodified token text for the given param.
1215 : * This is only set if this parameter is parsed from hit
1216 : */
1217 : std::string rawParamVal(const std::string & param) const;
1218 :
1219 : /**
1220 : * Informs this object that values for this parameter set from the input file or from the command
1221 : * line should be ignored
1222 : */
1223 : template <typename T>
1224 : void ignoreParameter(const std::string & name);
1225 :
1226 : /**
1227 : * Whether to ignore the value of an input parameter set in the input file or from the command
1228 : * line.
1229 : */
1230 : bool shouldIgnore(const std::string & name);
1231 :
1232 : /**
1233 : * @returns True if the parameter with name \p name is of type T.
1234 : */
1235 : template <typename T>
1236 : bool isType(const std::string & name) const;
1237 :
1238 : /**
1239 : * Determine the actual variable name from the given variable \emph parameter name
1240 : * @param var_param_name the name of the variable parameter, e.g. 'variable'
1241 : * @param moose_object_with_var_param_name the name of the moose object holding the variable
1242 : * parameter. Used for potential error messaging
1243 : */
1244 : std::string varName(const std::string & var_param_name,
1245 : const std::string & moose_object_with_var_param_name) const;
1246 :
1247 : /**
1248 : * Rename a parameter and provide a new documentation string
1249 : * @param old_name The old name of the parameter
1250 : * @param new_name The new name of the parameter
1251 : * @param new_docstring The new documentation string for the parameter
1252 : * If left empty, uses the old docstring for the renamed parameter
1253 : */
1254 : void renameParam(const std::string & old_name,
1255 : const std::string & new_name,
1256 : const std::string & new_docstring);
1257 :
1258 : /**
1259 : * Rename a coupled variable and provide a new documentation string
1260 : * @param old_name The old name of the coupled variable
1261 : * @param new_name The new name of the coupled variable
1262 : * @param new_docstring The new documentation string for the coupled variable
1263 : */
1264 : void renameCoupledVar(const std::string & old_name,
1265 : const std::string & new_name,
1266 : const std::string & new_docstring);
1267 :
1268 : void deprecateParam(const std::string & old_name,
1269 : const std::string & new_name,
1270 : const std::string & removal_date);
1271 :
1272 : void deprecateCoupledVar(const std::string & old_name,
1273 : const std::string & new_name,
1274 : const std::string & removal_date);
1275 :
1276 : /**
1277 : * Checks whether the provided name is a renamed parameter name. If so we return the 'new' name.
1278 : * If not we return the incoming name
1279 : * @param name The name to check for whether it is a renamed name
1280 : * @return The new name if the incoming \p name is a renamed name, else \p name
1281 : */
1282 : std::string checkForRename(const std::string & name) const;
1283 :
1284 : /**
1285 : * A wrapper around the \p Parameters base class method. Checks for parameter rename before
1286 : * calling the base class method
1287 : * @param name The name to query the parameter values map with
1288 : * @return The parameter value corresponding to the (possibly renamed) name
1289 : */
1290 : template <typename T>
1291 : const T & get(std::string_view name) const;
1292 :
1293 : /**
1294 : * A wrapper around the \p Parameters base class method. Checks for parameter rename before
1295 : * calling the base class method. This method tells whether a parameter with a known type is
1296 : * defined. If the type is unknown, use isParamDefined().
1297 : * @param name The name to query the parameter values map with
1298 : * @return Whether there is a key in the parameter values map corresponding to the (possibly
1299 : * renamed) name
1300 : */
1301 : template <typename T>
1302 : bool have_parameter(std::string_view name) const;
1303 :
1304 : /**
1305 : * A routine to transfer a parameter from one class' validParams to another
1306 : * @param source_param The parameters list holding the param we would like to transfer
1307 : * @param name The name of the parameter to transfer
1308 : * @param new_description A new description of the parameter. If unspecified, uses the
1309 : * source_params'
1310 : */
1311 : template <typename T>
1312 : void transferParam(const InputParameters & source_param,
1313 : const std::string & name,
1314 : const std::string & new_name = "",
1315 : const std::string & new_description = "");
1316 :
1317 : /**
1318 : * Return all the aliased names associated with \p param_name. The returned container will always
1319 : * contain \p param_name itself. Other aliases in addition to \p param_name will include the base
1320 : * class parameter name if \p param_name is the derived class parameter name, or deprecated names
1321 : * that \p param_name is meant to replace.
1322 : * @param param_name The name of the parameter that we want to lookup aliases for. This parameter
1323 : * name must exist in our metadata and parameter names to values map, e.g. this parameter must
1324 : * represent the derived class parameter name if a base class parameter has been renamed or the
1325 : * blessed parameter name in situations where associated parameter names have been deprecated
1326 : * @return All aliases which logically resolve-to/are-associated-with \p param_name, including \p
1327 : * param_name itself
1328 : */
1329 : std::vector<std::string> paramAliases(const std::string & param_name) const;
1330 :
1331 : /**
1332 : * @return The hit node that represents the syntax responsible for creating
1333 : * these parameters, if any
1334 : */
1335 23927750 : const hit::Node * getHitNode() const { return _hit_node; }
1336 : /**
1337 : * Sets the hit node that represents the syntax responsible for creating
1338 : * these parameters
1339 : *
1340 : * Is protected to be called by only the ActionFactory, Builder, and Factory
1341 : * via the SetHitNodeKey.
1342 : */
1343 5448620 : void setHitNode(const hit::Node & node, const SetHitNodeKey) { _hit_node = &node; }
1344 :
1345 : /**
1346 : * @return Whether or not finalize() has been called
1347 : */
1348 : bool isFinalized() const { return _finalized; }
1349 :
1350 : /**
1351 : * @return The DataFileName path for the parameter \p name (if any).
1352 : */
1353 : std::optional<Moose::DataFileUtils::Path> queryDataFileNamePath(const std::string & name) const;
1354 :
1355 : /**
1356 : * Entrypoint for the Builder to setup a std::vector<VariableName> parameter,
1357 : * which will setup the default variable names if appropriate
1358 : *
1359 : * @param names The variable names
1360 : * @param node The hit node that produced this parameter
1361 : * @return An error message, if any
1362 : */
1363 : std::optional<std::string> setupVariableNames(std::vector<VariableName> & names,
1364 : const hit::Node & node,
1365 : const Moose::PassKey<Moose::Builder>);
1366 :
1367 : private:
1368 : // Private constructor so that InputParameters can only be created in certain places.
1369 : InputParameters();
1370 :
1371 : /**
1372 : * Method to terminate the recursive setParameters definition
1373 : */
1374 17823 : void setParameters() {}
1375 :
1376 : template <typename T>
1377 : static constexpr bool isFunctorNameType();
1378 :
1379 : /**
1380 : * Appends description of what a functor is to a doc string.
1381 : */
1382 : template <typename T>
1383 : std::string appendFunctorDescription(const std::string & doc_string) const;
1384 :
1385 : /**
1386 : * Private method for setting deprecated coupled variable documentation strings
1387 : */
1388 : void setDeprecatedVarDocString(const std::string & new_name, const std::string & doc_string);
1389 :
1390 : void renameParamInternal(const std::string & old_name,
1391 : const std::string & new_name,
1392 : const std::string & docstring,
1393 : const std::string & removal_date);
1394 :
1395 : void renameCoupledVarInternal(const std::string & old_name,
1396 : const std::string & new_name,
1397 : const std::string & docstring,
1398 : const std::string & removal_date);
1399 :
1400 : /**
1401 : * Get the context associated with a parameter for a message.
1402 : * @param param The parameter name
1403 : * @return Pair that is the string prefix for the parameter (fullpath) and a pointer to the best
1404 : * hit node that can be associated with the parameter (if any)
1405 : */
1406 : std::pair<std::string, const hit::Node *> paramMessageContext(const std::string & param) const;
1407 : /**
1408 : * Get a prefix for messages associated with a parameter.
1409 : *
1410 : * Will include the best file path possible for the parameter and the parameter's fullpath.
1411 : */
1412 : std::string paramMessagePrefix(const std::string & param) const;
1413 :
1414 : struct Metadata
1415 : {
1416 : std::string _doc_string;
1417 : /// The developer-designated unit of the parameter for use in documentation
1418 : std::string _doc_unit;
1419 : /// The custom type that will be printed in the YAML dump for a parameter if supplied
1420 : std::string _custom_type;
1421 : /// The data pertaining to a command line parameter (empty if not a command line param)
1422 : std::optional<CommandLineMetadata> _cl_data;
1423 : /// The searched path information pertaining to a DataFileName parameter
1424 : std::optional<Moose::DataFileUtils::Path> _data_file_name_path;
1425 : /// The names of the parameters organized into groups
1426 : std::string _group;
1427 : /// The map of functions used for range checked parameters
1428 : std::string _range_function;
1429 : /// directions for auto build vectors (base_, 5) -> "base_0 base_1 base_2 base_3 base_4")
1430 : std::pair<std::string, std::string> _autobuild_vecs;
1431 : /// True for parameters that are required (i.e. will cause an abort if not supplied)
1432 : bool _required = false;
1433 : /**
1434 : * Whether the parameter is either explicitly set or provided a default value when added
1435 : * Note: We do not store MooseEnum names in valid params, instead we ask MooseEnums whether
1436 : * they are valid or not.
1437 : */
1438 : bool _valid = false;
1439 : /// The set of parameters that will NOT appear in the the dump of the parser tree
1440 : bool _is_private = false;
1441 : bool _have_coupled_default = false;
1442 : /// The default value for optionally coupled variables
1443 : std::vector<Real> _coupled_default = {0};
1444 : /// True if a parameters value was set by addParam, and not set again.
1445 : bool _set_by_add_param = false;
1446 : /// The reserved option names for a parameter
1447 : std::set<std::string> _reserved_values;
1448 : /// If non-empty, this parameter is deprecated.
1449 : std::string _deprecation_message;
1450 : /// Original location of parameter node; used for error messages
1451 : const hit::Node * _hit_node;
1452 : /// True if the parameters is controllable
1453 : bool _controllable = false;
1454 : /// Controllable execute flag restriction
1455 : std::set<ExecFlagType> _controllable_flags;
1456 : /// whether user setting of this parameter should be ignored
1457 : bool _ignore = false;
1458 : };
1459 :
1460 13444406 : Metadata & at(const std::string & param_name)
1461 : {
1462 13444406 : const auto param = checkForRename(param_name);
1463 13444406 : if (_params.count(param) == 0)
1464 0 : mooseError("param '", param, "' not present in InputParams");
1465 26888812 : return _params[param];
1466 13444406 : }
1467 29397630 : const Metadata & at(const std::string & param_name) const
1468 : {
1469 29397630 : const auto param = checkForRename(param_name);
1470 29397630 : if (_params.count(param) == 0)
1471 0 : mooseError("param '", param, "' not present in InputParams");
1472 58795260 : return _params.at(param);
1473 29397630 : }
1474 :
1475 : /**
1476 : * Toggle the availability of the copy constructor
1477 : *
1478 : * When MooseObject is created via the Factory this flag is set to false, so when a MooseObject is
1479 : * created if
1480 : * the constructor is not a const reference an error is produced. This method allows the
1481 : * InputParameterWarehouse
1482 : * to disable copying.
1483 : */
1484 8277124 : void allowCopy(bool status) { _allow_copy = status; }
1485 :
1486 : /**
1487 : * Make sure the parameter name doesn't have any invalid characters.
1488 : */
1489 : void checkParamName(const std::string & name) const;
1490 :
1491 : /**
1492 : * This method is called when adding a Parameter with a default value, can be specialized for
1493 : * non-matching types.
1494 : */
1495 : template <typename T, typename S>
1496 : void setParamHelper(const std::string & name, T & l_value, const S & r_value);
1497 :
1498 : /**
1499 : * Helper for all of the addCommandLineParam() calls, which sets up _cl_data in the metadata
1500 : *
1501 : * @param name The parameter name
1502 : * @param syntax The parameter syntax
1503 : * @param required Whether or not the parameter is required
1504 : * @param value_required Whethre or not the parameter requires a value
1505 : */
1506 : template <typename T>
1507 : void addCommandLineParamHelper(const std::string & name,
1508 : const std::string & syntax,
1509 : const bool required,
1510 : const bool value_required);
1511 :
1512 : /**
1513 : * Internal helper for calling back to mooseError(), ideally from the underlying
1514 : * MooseBase object if it is available (for more context)
1515 : */
1516 : [[noreturn]] void callMooseError(std::string msg,
1517 : const bool with_prefix = true,
1518 : const hit::Node * node = nullptr,
1519 : const bool show_trace = true) const;
1520 :
1521 : /// The actual parameter data. Each Metadata object contains attributes for the corresponding
1522 : /// parameter.
1523 : std::map<std::string, Metadata> _params;
1524 :
1525 : /// The coupled variables set
1526 : std::set<std::string> _coupled_vars;
1527 :
1528 : /// The class description for the owning object. This string is used in many places including
1529 : /// mouse-over events, and external documentation produced from the source code.
1530 : std::string _class_description;
1531 :
1532 : /// The parameter is used to restrict types that can be built. Typically this is used for
1533 : /// MooseObjectAction derived Actions.
1534 : std::vector<std::string> _buildable_types;
1535 :
1536 : /// The RelationshipManagers that this object may either build or require.
1537 : /// The optional second argument may be supplied to "downgrade" the functionality of the corresponding
1538 : /// relationship manager (e.g. An AlgebraicRelationshipManager could be only used as a
1539 : /// GeometricRelationshipManager for a given simulation).
1540 : std::vector<std::tuple<std::string,
1541 : Moose::RelationshipManagerType,
1542 : Moose::RelationshipManagerInputParameterCallback>>
1543 : _buildable_rm_types;
1544 :
1545 : /// This parameter collapses one level of nesting in the syntax blocks. It is used
1546 : /// in conjunction with MooseObjectAction derived Actions.
1547 : bool _collapse_nesting;
1548 :
1549 : /// This parameter hides derived MOOSE object types from appearing in syntax dumps
1550 : bool _moose_object_syntax_visibility;
1551 :
1552 : /// Flag for disabling deprecated parameters message, this is used by applyParameters to avoid
1553 : /// dumping messages.
1554 : bool _show_deprecated_message;
1555 :
1556 : /// A flag for toggling the error message in the copy constructor.
1557 : bool _allow_copy;
1558 :
1559 : /// A map from deprecated coupled variable names to the new blessed name
1560 : std::unordered_map<std::string, std::string> _new_to_deprecated_coupled_vars;
1561 :
1562 : /// A map from base-class/deprecated parameter names to derived-class/blessed parameter names and
1563 : /// the deprecation messages in the case that the "old" parameter name is a deprecated parameter
1564 : /// name. The deprecation message will be empty if the "old" parameter name represents a base
1565 : /// class parameter name
1566 : std::map<std::string, std::pair<std::string, std::string>> _old_to_new_name_and_dep;
1567 :
1568 : /// A map from derived-class/blessed parameter names to associated base-class/deprecated parameter
1569 : /// names
1570 : std::multimap<std::string, std::string> _new_to_old_names;
1571 :
1572 : /// The hit node representing the syntax that created these parameters, if any
1573 : const hit::Node * _hit_node;
1574 :
1575 : /// Whether or not we've called finalize() on these parameters yet
1576 : bool _finalized;
1577 :
1578 : // These are the only objects allowed to _create_ InputParameters
1579 : friend InputParameters emptyInputParameters();
1580 : friend class InputParameterWarehouse;
1581 : friend class Parser;
1582 : // for the printInputFile function in the action warehouse
1583 : friend class ActionWarehouse;
1584 : };
1585 :
1586 : template <typename T>
1587 : void
1588 372165670 : InputParameters::setHelper(const std::string & /*name*/)
1589 : {
1590 372165670 : }
1591 :
1592 : // Template and inline function implementations
1593 : template <typename T>
1594 : T &
1595 372165670 : InputParameters::set(const std::string & name_in, bool quiet_mode)
1596 : {
1597 372165670 : const auto name = checkForRename(name_in);
1598 :
1599 372165670 : checkParamName(name);
1600 372165670 : checkConsistentType<T>(name);
1601 :
1602 372165670 : T & result = this->Parameters::set<T>(name);
1603 :
1604 372165670 : if (quiet_mode)
1605 6407094 : _params[name]._set_by_add_param = true;
1606 :
1607 372165670 : setHelper<T>(name);
1608 :
1609 372165670 : return result;
1610 372165670 : }
1611 :
1612 : template <typename T, typename... Ts>
1613 : void
1614 17823 : InputParameters::setParameters(const std::string & name,
1615 : const T & value,
1616 : Ts... extra_input_parameters)
1617 : {
1618 17823 : this->set<T>(name) = value;
1619 17823 : this->setParameters(extra_input_parameters...);
1620 17823 : }
1621 :
1622 : template <typename T, typename UP_T>
1623 : std::optional<std::pair<bool, std::string>>
1624 1429321 : InputParameters::rangeCheck(const std::string & full_name,
1625 : const std::string & short_name,
1626 : const InputParameters::Parameter<std::vector<T>> & param,
1627 : const bool include_param_path)
1628 : {
1629 1429321 : if (!isParamValid(short_name))
1630 765367 : return {};
1631 :
1632 663954 : const auto & range_function = _params[short_name]._range_function;
1633 663954 : if (range_function.empty())
1634 540556 : return {};
1635 :
1636 : /**
1637 : * Automatically detect the variables used in the range checking expression.
1638 : * We allow the following variables (where snam is the short_name of the parameter)
1639 : *
1640 : * snam : tests every component in the vector
1641 : * 'snam > 0'
1642 : * snam_size : the size of the vector
1643 : * 'snam_size = 5'
1644 : * snam_i : where i is a number from 0 to sname_size-1 tests a specific component
1645 : * 'snam_0 > snam_1'
1646 : */
1647 123398 : FunctionParserBase<UP_T> fp;
1648 123398 : std::vector<std::string> vars;
1649 123398 : if (fp.ParseAndDeduceVariables(range_function, vars) != -1) // -1 for success
1650 : return {{false,
1651 2 : "Error parsing expression '" + range_function + "' for parameter " + short_name + ""}};
1652 :
1653 : // Fparser parameter buffer
1654 123396 : std::vector<UP_T> parbuf(vars.size());
1655 :
1656 : // parameter vector
1657 123396 : const std::vector<T> & value = param.get();
1658 :
1659 : // iterate over all vector values (maybe ;)
1660 123396 : bool need_to_iterate = false;
1661 123396 : unsigned int i = 0;
1662 : do
1663 : {
1664 : // set parameters
1665 250042 : for (unsigned int j = 0; j < vars.size(); j++)
1666 : {
1667 125082 : if (vars[j] == short_name)
1668 : {
1669 124752 : if (value.size() == 0)
1670 : {
1671 5 : std::ostringstream oss;
1672 5 : oss << "Range checking empty vector";
1673 5 : if (include_param_path)
1674 5 : oss << " parameter " << full_name;
1675 5 : oss << "; expression = '" << range_function << "'";
1676 5 : return {{true, oss.str()}};
1677 5 : }
1678 :
1679 124747 : parbuf[j] = value[i];
1680 124747 : need_to_iterate = true;
1681 : }
1682 330 : else if (vars[j] == short_name + "_size")
1683 81 : parbuf[j] = value.size();
1684 : else
1685 : {
1686 249 : if (vars[j].substr(0, short_name.size() + 1) != short_name + "_")
1687 2 : return {{false, "Error parsing expression '" + range_function + "'"}};
1688 247 : std::istringstream iss(vars[j]);
1689 247 : iss.seekg(short_name.size() + 1);
1690 :
1691 : size_t index;
1692 247 : if (iss >> index && iss.eof())
1693 : {
1694 245 : if (index >= value.size())
1695 : {
1696 5 : std::ostringstream oss;
1697 5 : oss << "Error parsing expression '" + range_function + "'";
1698 5 : if (include_param_path)
1699 5 : oss << " for parameter " << full_name;
1700 5 : oss << "; out of range variable '" + vars[j] << "'";
1701 5 : return {{true, oss.str()}};
1702 5 : }
1703 240 : parbuf[j] = value[index];
1704 : }
1705 : else
1706 : return {{false,
1707 2 : "Error parsing expression '" + range_function + "'; invalid variable '" +
1708 2 : vars[j] + "'"}};
1709 247 : }
1710 : }
1711 :
1712 : // ensure range-checked input file parameter comparison functions
1713 : // do absolute floating point comparisons instead of using a default epsilon.
1714 124960 : auto tmp_eps = fp.epsilon();
1715 124960 : fp.setEpsilon(0);
1716 124960 : UP_T result = fp.Eval(&parbuf[0]);
1717 124960 : fp.setEpsilon(tmp_eps);
1718 :
1719 : // test function using the parameters determined above
1720 124960 : if (fp.EvalError())
1721 0 : return {{false, "Error evaluating expression '" + range_function + "'"}};
1722 :
1723 124960 : if (!result)
1724 : {
1725 21 : std::ostringstream oss;
1726 21 : oss << "Range check failed";
1727 21 : if (include_param_path)
1728 21 : oss << " for parameter " << full_name;
1729 21 : oss << "; expression = '" << range_function << "'";
1730 21 : if (need_to_iterate)
1731 3 : oss << ", component " << i;
1732 21 : return {{true, oss.str()}};
1733 21 : }
1734 :
1735 124939 : } while (need_to_iterate && ++i < value.size());
1736 :
1737 123361 : return {};
1738 123398 : }
1739 :
1740 : template <typename T, typename UP_T>
1741 : std::optional<std::pair<bool, std::string>>
1742 16385790 : InputParameters::rangeCheck(const std::string & full_name,
1743 : const std::string & short_name,
1744 : const InputParameters::Parameter<T> & param,
1745 : const bool include_param_path)
1746 : {
1747 16385790 : if (!isParamValid(short_name))
1748 2790638 : return {};
1749 :
1750 13595152 : const auto & range_function = _params[short_name]._range_function;
1751 13595152 : if (range_function.empty())
1752 11857966 : return {};
1753 :
1754 : // Parse the expression
1755 1737186 : FunctionParserBase<UP_T> fp;
1756 1737186 : if (fp.Parse(range_function, short_name) != -1) // -1 for success
1757 : return {{false,
1758 2 : "Error parsing expression '" + range_function + "'" + " for parameter " + short_name}};
1759 :
1760 : // ensure range-checked input file parameter comparison functions
1761 : // do absolute floating point comparisons instead of using a default epsilon.
1762 1737184 : auto tmp_eps = fp.epsilon();
1763 1737184 : fp.setEpsilon(0);
1764 : // We require a non-const value for the implicit upscaling of the parameter type
1765 1737184 : std::vector<UP_T> value(1, param.get());
1766 1737184 : UP_T result = fp.Eval(&value[0]);
1767 1737184 : fp.setEpsilon(tmp_eps);
1768 :
1769 1737184 : if (fp.EvalError())
1770 : return {{true,
1771 : "Error evaluating expression '" + range_function + "' for parameter " + short_name +
1772 0 : "; perhaps you used the wrong variable name?"}};
1773 :
1774 1737184 : if (!result)
1775 : {
1776 11 : std::ostringstream oss;
1777 11 : oss << "Range check failed";
1778 11 : if (include_param_path)
1779 9 : oss << " for parameter " << full_name;
1780 11 : oss << "; expression = '" << range_function << "', value = " << value[0];
1781 11 : return {{true, oss.str()}};
1782 11 : }
1783 :
1784 1737173 : return {};
1785 1737186 : }
1786 :
1787 : template <typename T>
1788 : T
1789 26871764 : InputParameters::getCheckedPointerParam(const std::string & name_in,
1790 : const std::string & error_string) const
1791 : {
1792 26871764 : const auto name = checkForRename(name_in);
1793 :
1794 26871764 : T param = this->get<T>(name);
1795 :
1796 : // Note: You will receive a compile error on this line if you attempt to pass a non-pointer
1797 : // template type to this method
1798 26871764 : if (!param)
1799 9 : mooseError("Parameter ", name, " is NULL.\n", error_string);
1800 53743510 : return this->get<T>(name);
1801 26871755 : }
1802 :
1803 : template <typename T>
1804 : void
1805 15321117 : InputParameters::addRequiredParam(const std::string & name, const std::string & doc_string)
1806 : {
1807 15321117 : checkParamName(name);
1808 15321117 : checkConsistentType<T>(name);
1809 :
1810 15321117 : InputParameters::insert<T>(name);
1811 15321117 : auto & metadata = _params[name];
1812 15321117 : metadata._required = true;
1813 : if constexpr (isFunctorNameType<T>())
1814 352550 : metadata._doc_string = appendFunctorDescription<T>(doc_string);
1815 : else
1816 14968567 : metadata._doc_string = doc_string;
1817 15321117 : }
1818 :
1819 : template <typename T>
1820 : void
1821 : InputParameters::addRequiredParam(const std::string & /*name*/,
1822 : const T & /*value*/,
1823 : const std::string & /*doc_string*/)
1824 : {
1825 : mooseError("You cannot call addRequiredParam and supply a default value for this type, please "
1826 : "use addParam instead");
1827 : }
1828 :
1829 : template <typename T, typename S>
1830 : void
1831 158370650 : InputParameters::addParam(const std::string & name, const S & value, const std::string & doc_string)
1832 : {
1833 158370650 : checkParamName(name);
1834 158370650 : checkConsistentType<T>(name);
1835 :
1836 158370650 : T & l_value = InputParameters::set<T>(name);
1837 158370650 : auto & metadata = _params[name];
1838 : if constexpr (isFunctorNameType<T>())
1839 316005 : metadata._doc_string = appendFunctorDescription<T>(doc_string);
1840 : else
1841 158054645 : metadata._doc_string = doc_string;
1842 :
1843 : // Set the parameter now
1844 158370650 : setParamHelper(name, l_value, value);
1845 :
1846 : /* Indicate the default value, as set via addParam, is being used. The parameter is removed from
1847 : the list whenever
1848 : it changes, see set_attributes */
1849 158370650 : metadata._set_by_add_param = true;
1850 158370650 : }
1851 :
1852 : template <typename T>
1853 : void
1854 66038851 : InputParameters::addParam(const std::string & name, const std::string & doc_string)
1855 : {
1856 66038851 : checkParamName(name);
1857 66038845 : checkConsistentType<T>(name);
1858 :
1859 66038845 : InputParameters::insert<T>(name);
1860 : if constexpr (isFunctorNameType<T>())
1861 154339 : _params[name]._doc_string = appendFunctorDescription<T>(doc_string);
1862 : else
1863 65884506 : _params[name]._doc_string = doc_string;
1864 66038845 : }
1865 :
1866 : template <typename T, typename S>
1867 : void
1868 157907554 : InputParameters::setParamHelper(const std::string & /*name*/, T & l_value, const S & r_value)
1869 : {
1870 157907554 : l_value = r_value;
1871 157907554 : }
1872 :
1873 : template <typename T>
1874 : void
1875 5181094 : InputParameters::addCommandLineParamHelper(const std::string & name,
1876 : const std::string & syntax,
1877 : const bool required,
1878 : const bool value_required)
1879 : {
1880 : static_assert(isValidCommandLineType<T>::value,
1881 : "This type is not a supported command line parameter type. See "
1882 : "CommandLine::populateCommandLineParams to add it as a supported type.");
1883 :
1884 5181094 : auto & cl_data = at(name)._cl_data;
1885 5181094 : cl_data = CommandLineMetadata();
1886 :
1887 : // Split up the syntax by whitespace
1888 5181094 : std::vector<std::string> syntax_split;
1889 10362188 : MooseUtils::tokenize(syntax, syntax_split, 1, " \t\n\v\f\r");
1890 :
1891 : // Set the single syntax string as the combined syntax with removed whitespace
1892 5181094 : cl_data->syntax = MooseUtils::stringJoin(syntax_split);
1893 : mooseAssert(cl_data->syntax.size(), "Empty token");
1894 :
1895 : // Set the switches; only parse those that begin with "-" as we also
1896 : // provide examples within the syntax
1897 12759637 : for (const auto & val : syntax_split)
1898 7578545 : if (val.rfind("-", 0) == 0)
1899 : {
1900 5587018 : if (!std::regex_search(val, std::regex("^\\-+[a-zA-Z]")))
1901 2 : mooseError("The switch '",
1902 : val,
1903 : "' for the command line parameter '",
1904 : name,
1905 : "' is invalid. It must begin with an alphabetical character.");
1906 :
1907 5587016 : cl_data->switches.push_back(val);
1908 5587016 : libMesh::add_command_line_name(val);
1909 : }
1910 :
1911 5181092 : cl_data->required = required;
1912 5181092 : cl_data->global = false;
1913 :
1914 : // No arguments needed for a boolean parameter
1915 : if constexpr (std::is_same_v<T, bool>)
1916 : {
1917 : (void)value_required; // purposely unused; doesn't take a value
1918 3312492 : cl_data->argument_type = CommandLineMetadata::ArgumentType::NONE;
1919 : }
1920 : // MooseEnums require a value
1921 : else if constexpr (std::is_same_v<T, MooseEnum>)
1922 : {
1923 : (void)value_required; // purposely unused; always required
1924 135300 : cl_data->argument_type = CommandLineMetadata::ArgumentType::REQUIRED;
1925 : }
1926 : // The user didn't specify a default, so a value is required
1927 1733300 : else if (value_required)
1928 1395056 : cl_data->argument_type = CommandLineMetadata::ArgumentType::REQUIRED;
1929 : // Otherwise, it's optional (user specified a default)
1930 : else
1931 338244 : cl_data->argument_type = CommandLineMetadata::ArgumentType::OPTIONAL;
1932 5181094 : }
1933 :
1934 : template <typename T>
1935 : void
1936 159723 : InputParameters::addRequiredRangeCheckedParam(const std::string & name,
1937 : const std::string & parsed_function,
1938 : const std::string & doc_string)
1939 : {
1940 159723 : addRequiredParam<T>(name, doc_string);
1941 159723 : _params[name]._range_function = parsed_function;
1942 159723 : }
1943 :
1944 : template <typename T>
1945 : void
1946 5757987 : InputParameters::addRangeCheckedParam(const std::string & name,
1947 : const T & value,
1948 : const std::string & parsed_function,
1949 : const std::string & doc_string)
1950 : {
1951 5757987 : addParam<T>(name, value, doc_string);
1952 5757987 : _params[name]._range_function = parsed_function;
1953 5757987 : }
1954 :
1955 : template <typename T>
1956 : void
1957 772845 : InputParameters::addRangeCheckedParam(const std::string & name,
1958 : const std::string & parsed_function,
1959 : const std::string & doc_string)
1960 : {
1961 772845 : addParam<T>(name, doc_string);
1962 772845 : _params[name]._range_function = parsed_function;
1963 772845 : }
1964 :
1965 : template <typename T>
1966 : void
1967 137653 : InputParameters::addRequiredCustomTypeParam(const std::string & name,
1968 : const std::string & custom_type,
1969 : const std::string & doc_string)
1970 : {
1971 137653 : addRequiredParam<T>(name, doc_string);
1972 137653 : _params[name]._custom_type = custom_type;
1973 137653 : }
1974 :
1975 : template <typename T>
1976 : void
1977 34183 : InputParameters::addCustomTypeParam(const std::string & name,
1978 : const T & value,
1979 : const std::string & custom_type,
1980 : const std::string & doc_string)
1981 : {
1982 34183 : addParam<T>(name, value, doc_string);
1983 34183 : _params[name]._custom_type = custom_type;
1984 34183 : }
1985 :
1986 : template <typename T>
1987 : void
1988 23191 : InputParameters::addCustomTypeParam(const std::string & name,
1989 : const std::string & custom_type,
1990 : const std::string & doc_string)
1991 : {
1992 23191 : addParam<T>(name, doc_string);
1993 23191 : _params[name]._custom_type = custom_type;
1994 23191 : }
1995 :
1996 : template <typename T>
1997 : void
1998 17753 : InputParameters::addDeprecatedCustomTypeParam(const std::string & name,
1999 : const std::string & custom_type,
2000 : const std::string & doc_string,
2001 : const std::string & deprecation_message)
2002 : {
2003 17753 : _show_deprecated_message = false;
2004 17753 : addParam<T>(name, doc_string);
2005 17753 : auto & metadata = _params[name];
2006 17753 : metadata._custom_type = custom_type;
2007 :
2008 17753 : metadata._deprecation_message = deprecation_message;
2009 17753 : _show_deprecated_message = true;
2010 17753 : }
2011 :
2012 : template <typename T>
2013 : void
2014 107739635 : InputParameters::addPrivateParam(const std::string & name)
2015 : {
2016 107739635 : checkParamName(name);
2017 107739635 : checkConsistentType<T>(name);
2018 :
2019 107739635 : InputParameters::insert<T>(name);
2020 107739635 : _params[name]._is_private = true;
2021 107739635 : }
2022 :
2023 : template <typename T>
2024 : void
2025 140581395 : InputParameters::addPrivateParam(const std::string & name, const T & value)
2026 : {
2027 140581395 : checkParamName(name);
2028 140581395 : checkConsistentType<T>(name);
2029 :
2030 140581395 : InputParameters::set<T>(name) = value;
2031 140581395 : auto & metadata = _params[name];
2032 140581395 : metadata._is_private = true;
2033 140581395 : metadata._set_by_add_param = true;
2034 140581395 : }
2035 :
2036 : template <typename T>
2037 : void
2038 2 : InputParameters::addRequiredCommandLineParam(const std::string & name,
2039 : const std::string & syntax,
2040 : const std::string & doc_string)
2041 : {
2042 : static_assert(!std::is_same_v<T, bool>, "Cannot be used for a bool");
2043 :
2044 2 : addRequiredParam<T>(name, doc_string);
2045 2 : addCommandLineParamHelper<T>(name, syntax, /* required = */ true, /* value_required = */ true);
2046 2 : }
2047 :
2048 : template <typename T>
2049 : void
2050 4369851 : InputParameters::addCommandLineParam(const std::string & name,
2051 : const std::string & syntax,
2052 : const std::string & doc_string)
2053 : {
2054 : static_assert(!std::is_same_v<T, MooseEnum>,
2055 : "addCommandLineParam() without a value cannot be used with a MooseEnum because a "
2056 : "MooseEnum requires initialization");
2057 :
2058 4369851 : auto constexpr is_bool = std::is_same_v<T, bool>;
2059 : if constexpr (is_bool)
2060 3109550 : addParam<T>(name, false, doc_string);
2061 : else
2062 1260301 : addParam<T>(name, doc_string);
2063 :
2064 4369851 : addCommandLineParamHelper<T>(
2065 : name, syntax, /* required = */ false, /* value_required = */ !is_bool);
2066 4369849 : }
2067 :
2068 : template <typename T>
2069 : void
2070 472997 : InputParameters::addCommandLineParam(const std::string & name,
2071 : const std::string & syntax,
2072 : const T & value,
2073 : const std::string & doc_string)
2074 : {
2075 : if constexpr (std::is_same_v<T, bool>)
2076 : mooseAssert(!value, "Default for bool must be false");
2077 :
2078 472997 : addParam<T>(name, value, doc_string);
2079 472997 : addCommandLineParamHelper<T>(name, syntax, /* required = */ false, /* value_required = */ true);
2080 472997 : }
2081 :
2082 : template <typename T>
2083 : void
2084 338244 : InputParameters::addOptionalValuedCommandLineParam(const std::string & name,
2085 : const std::string & syntax,
2086 : const T & value,
2087 : const std::string & doc_string)
2088 : {
2089 : mooseAssert(name == "citations" || name == "csg_only" || name == "mesh_only" ||
2090 : name == "recover" || name == "run",
2091 : "Not supported for new parameters");
2092 : static_assert(!std::is_same_v<T, bool>, "Cannot be used for a bool (does not take a value)");
2093 338244 : addParam<T>(name, value, doc_string);
2094 338244 : addCommandLineParamHelper<T>(name, syntax, /* required = */ false, /* value_required = */ false);
2095 338244 : }
2096 :
2097 : template <typename T>
2098 : void
2099 860217318 : InputParameters::checkConsistentType(const std::string & name_in) const
2100 : {
2101 860217318 : const auto name = checkForRename(name_in);
2102 :
2103 : // If we don't currently have the Parameter, can't be any inconsistency
2104 860217318 : InputParameters::const_iterator it = _values.find(name);
2105 860217318 : if (it == _values.end())
2106 771264093 : return;
2107 :
2108 : // Now, if we already have the Parameter, but it doesn't have the
2109 : // right type, throw an error.
2110 88953225 : if (!this->Parameters::have_parameter<T>(name))
2111 0 : mooseError("Attempting to set parameter \"",
2112 : name,
2113 : "\" with type (",
2114 : libMesh::demangle(typeid(T).name()),
2115 : ")\nbut the parameter already exists as type (",
2116 0 : it->second->type(),
2117 : ")");
2118 860217318 : }
2119 :
2120 : template <typename T>
2121 : void
2122 5702501 : InputParameters::suppressParameter(const std::string & name_in)
2123 : {
2124 5702501 : const auto name = checkForRename(name_in);
2125 5702501 : if (!this->have_parameter<T>(name))
2126 2 : mooseError("Unable to suppress nonexistent parameter: ", name);
2127 :
2128 5702499 : auto & metadata = _params[name];
2129 5702499 : metadata._required = false;
2130 5702499 : metadata._is_private = true;
2131 5702499 : metadata._controllable = false;
2132 5702501 : }
2133 :
2134 : template <typename T>
2135 : void
2136 2770 : InputParameters::ignoreParameter(const std::string & name_in)
2137 : {
2138 2770 : const auto name = checkForRename(name_in);
2139 2770 : suppressParameter<T>(name);
2140 2770 : _params[name]._ignore = true;
2141 2770 : }
2142 :
2143 : template <typename T>
2144 : void
2145 24715 : InputParameters::makeParamRequired(const std::string & name_in)
2146 : {
2147 24715 : const auto name = checkForRename(name_in);
2148 :
2149 24715 : if (!this->have_parameter<T>(name))
2150 4 : mooseError("Unable to require nonexistent parameter: ", name);
2151 :
2152 24711 : _params[name]._required = true;
2153 24715 : }
2154 :
2155 : template <typename T>
2156 : void
2157 51591 : InputParameters::makeParamNotRequired(const std::string & name_in)
2158 : {
2159 51591 : const auto name = checkForRename(name_in);
2160 :
2161 51591 : if (!this->have_parameter<T>(name))
2162 0 : mooseError("Unable to un-require nonexistent parameter: ", name);
2163 :
2164 51591 : _params[name]._required = false;
2165 51591 : }
2166 :
2167 : template <typename T>
2168 : void
2169 3252628 : InputParameters::addDeprecatedParam(const std::string & name,
2170 : const T & value,
2171 : const std::string & doc_string,
2172 : const std::string & deprecation_message)
2173 : {
2174 3252628 : _show_deprecated_message = false;
2175 : mooseAssert(!_old_to_new_name_and_dep.count(name),
2176 : "Attempting to deprecate via addDeprecatedParam the parameter, '"
2177 : << name << "', already deprecated via deprecateParam or renamed via renameParam");
2178 3252628 : addParam<T>(name, value, doc_string);
2179 :
2180 3252628 : _params[name]._deprecation_message = deprecation_message;
2181 3252628 : _show_deprecated_message = true;
2182 3252628 : }
2183 :
2184 : template <typename T>
2185 : void
2186 1311104 : InputParameters::addDeprecatedParam(const std::string & name,
2187 : const std::string & doc_string,
2188 : const std::string & deprecation_message)
2189 : {
2190 1311104 : _show_deprecated_message = false;
2191 : mooseAssert(!_old_to_new_name_and_dep.count(name),
2192 : "Attempting to deprecate via addDeprecatedParam the parameter, '"
2193 : << name << "', already deprecated via deprecateParam or renamed via renameParam");
2194 1311104 : addParam<T>(name, doc_string);
2195 :
2196 1311104 : _params[name]._deprecation_message = deprecation_message;
2197 1311104 : _show_deprecated_message = true;
2198 1311104 : }
2199 :
2200 : // Forward declare MooseEnum specializations for add*Param
2201 : template <>
2202 : void InputParameters::addRequiredParam<MooseEnum>(const std::string & name,
2203 : const MooseEnum & moose_enum,
2204 : const std::string & doc_string);
2205 :
2206 : template <>
2207 : void InputParameters::addRequiredParam<MultiMooseEnum>(const std::string & name,
2208 : const MultiMooseEnum & moose_enum,
2209 : const std::string & doc_string);
2210 :
2211 : template <>
2212 : void InputParameters::addRequiredParam<std::vector<MooseEnum>>(
2213 : const std::string & name,
2214 : const std::vector<MooseEnum> & moose_enums,
2215 : const std::string & doc_string);
2216 :
2217 : template <>
2218 : void InputParameters::addRequiredParam<std::vector<MultiMooseEnum>>(
2219 : const std::string & name,
2220 : const std::vector<MultiMooseEnum> & moose_enums,
2221 : const std::string & doc_string);
2222 :
2223 : template <>
2224 : void InputParameters::addParam<MooseEnum>(const std::string & /*name*/,
2225 : const std::string & /*doc_string*/);
2226 :
2227 : template <>
2228 : void InputParameters::addParam<MultiMooseEnum>(const std::string & /*name*/,
2229 : const std::string & /*doc_string*/);
2230 :
2231 : template <>
2232 : void InputParameters::addParam<std::vector<MooseEnum>>(const std::string & /*name*/,
2233 : const std::string & /*doc_string*/);
2234 :
2235 : template <>
2236 : void InputParameters::addParam<std::vector<MultiMooseEnum>>(const std::string & /*name*/,
2237 : const std::string & /*doc_string*/);
2238 :
2239 : template <>
2240 : void
2241 : InputParameters::addRequiredParam<std::vector<MultiMooseEnum>>(const std::string & /*name*/,
2242 : const std::string & /*doc_string*/);
2243 :
2244 : template <>
2245 : void InputParameters::addPrivateParam<MooseEnum>(const std::string & /*name*/);
2246 :
2247 : template <>
2248 : void InputParameters::addPrivateParam<MultiMooseEnum>(const std::string & /*name*/);
2249 :
2250 : template <>
2251 : void InputParameters::addDeprecatedParam<MooseEnum>(const std::string & /*name*/,
2252 : const std::string & /*doc_string*/,
2253 : const std::string & /*deprecation_message*/);
2254 :
2255 : template <>
2256 : void
2257 : InputParameters::addDeprecatedParam<MultiMooseEnum>(const std::string & /*name*/,
2258 : const std::string & /*doc_string*/,
2259 : const std::string & /*deprecation_message*/);
2260 :
2261 : template <>
2262 : void InputParameters::addDeprecatedParam<std::vector<MooseEnum>>(
2263 : const std::string & /*name*/,
2264 : const std::string & /*doc_string*/,
2265 : const std::string & /*deprecation_message*/);
2266 :
2267 : // Forward declare specializations for setParamHelper
2268 : template <>
2269 : void InputParameters::setParamHelper<PostprocessorName, Real>(const std::string & name,
2270 : PostprocessorName & l_value,
2271 : const Real & r_value);
2272 :
2273 : template <>
2274 : void InputParameters::setParamHelper<PostprocessorName, int>(const std::string & name,
2275 : PostprocessorName & l_value,
2276 : const int & r_value);
2277 :
2278 : template <>
2279 : void InputParameters::setParamHelper<FunctionName, Real>(const std::string & /*name*/,
2280 : FunctionName & l_value,
2281 : const Real & r_value);
2282 :
2283 : template <>
2284 : void InputParameters::setParamHelper<FunctionName, int>(const std::string & /*name*/,
2285 : FunctionName & l_value,
2286 : const int & r_value);
2287 :
2288 : template <>
2289 : void InputParameters::setParamHelper<MaterialPropertyName, Real>(const std::string & /*name*/,
2290 : MaterialPropertyName & l_value,
2291 : const Real & r_value);
2292 :
2293 : template <>
2294 : void InputParameters::setParamHelper<MaterialPropertyName, int>(const std::string & /*name*/,
2295 : MaterialPropertyName & l_value,
2296 : const int & r_value);
2297 :
2298 : template <>
2299 : void InputParameters::setParamHelper<MooseFunctorName, Real>(const std::string & /*name*/,
2300 : MooseFunctorName & l_value,
2301 : const Real & r_value);
2302 :
2303 : template <>
2304 : void InputParameters::setParamHelper<MooseFunctorName, int>(const std::string & /*name*/,
2305 : MooseFunctorName & l_value,
2306 : const int & r_value);
2307 :
2308 : template <typename T>
2309 : const T *
2310 1377 : InputParameters::queryParam(const std::string & name) const
2311 : {
2312 1377 : return isParamValid(name) ? &getParamHelper<T>(name, *this) : nullptr;
2313 : }
2314 :
2315 : template <typename T>
2316 : const T &
2317 43148122 : InputParameters::getParamHelper(const std::string & name_in, const InputParameters & pars)
2318 : {
2319 43148122 : const auto name = pars.checkForRename(name_in);
2320 :
2321 43148122 : if (!pars.isParamValid(name))
2322 4 : pars.mooseError("The parameter \"", name, "\" is being retrieved before being set.");
2323 :
2324 86296236 : return pars.get<T>(name);
2325 43148122 : }
2326 :
2327 : // Declare specializations so we don't fall back on the generic
2328 : // implementation, but the definition will be in InputParameters.C so
2329 : // we won't need to bring in *MooseEnum header files here.
2330 : template <>
2331 : const MooseEnum & InputParameters::getParamHelper<MooseEnum>(const std::string & name,
2332 : const InputParameters & pars);
2333 :
2334 : template <>
2335 : const MultiMooseEnum &
2336 : InputParameters::getParamHelper<MultiMooseEnum>(const std::string & name,
2337 : const InputParameters & pars);
2338 :
2339 : template <typename R1, typename R2, typename V1, typename V2>
2340 : std::vector<std::pair<R1, R2>>
2341 141673 : InputParameters::get(const std::string & param1_in, const std::string & param2_in) const
2342 : {
2343 141673 : const auto param1 = checkForRename(param1_in);
2344 141673 : const auto param2 = checkForRename(param2_in);
2345 :
2346 141673 : const auto & v1 = get<V1>(param1);
2347 141673 : const auto & v2 = get<V2>(param2);
2348 :
2349 141673 : auto controllable = getControllableParameters();
2350 141673 : if (controllable.count(param1) || controllable.count(param2))
2351 4 : mooseError("Parameters ",
2352 : param1,
2353 : " and/or ",
2354 : param2 + " are controllable parameters and cannot be retireved using "
2355 : "the MooseObject::getParam/InputParameters::get methods for pairs");
2356 :
2357 141671 : if (v1.size() != v2.size())
2358 12 : paramError(param1,
2359 : "Vector parameters ",
2360 : param1,
2361 : "(size: ",
2362 : v1.size(),
2363 : ") and " + param2,
2364 : "(size: ",
2365 : v2.size(),
2366 : ") are of different lengths \n");
2367 :
2368 141663 : std::vector<std::pair<R1, R2>> parameter_pairs;
2369 141663 : auto i1 = v1.begin();
2370 141663 : auto i2 = v2.begin();
2371 194655 : for (; i1 != v1.end() && i2 != v2.end(); ++i1, ++i2)
2372 52992 : parameter_pairs.emplace_back(std::make_pair(*i1, *i2));
2373 283326 : return parameter_pairs;
2374 141675 : }
2375 :
2376 : InputParameters emptyInputParameters();
2377 :
2378 : template <typename T>
2379 : bool
2380 86137 : InputParameters::isType(const std::string & name_in) const
2381 : {
2382 86137 : const auto name = checkForRename(name_in);
2383 :
2384 86137 : if (!_params.count(name))
2385 0 : mooseError("Parameter \"", name, "\" is not valid.");
2386 172274 : return have_parameter<T>(name);
2387 86137 : }
2388 :
2389 : template <typename T>
2390 : const T &
2391 200139801 : InputParameters::get(std::string_view name_in) const
2392 : {
2393 200139801 : const auto name = checkForRename(std::string(name_in));
2394 :
2395 400279602 : return Parameters::get<T>(name);
2396 200139801 : }
2397 :
2398 : template <typename T>
2399 : bool
2400 2544130025 : InputParameters::have_parameter(std::string_view name_in) const
2401 : {
2402 2544130025 : const auto name = checkForRename(std::string(name_in));
2403 :
2404 5088260050 : return Parameters::have_parameter<T>(name);
2405 2544130025 : }
2406 :
2407 : template <typename T>
2408 : void
2409 4213578 : InputParameters::transferParam(const InputParameters & source_params,
2410 : const std::string & name_in,
2411 : const std::string & new_name,
2412 : const std::string & new_description)
2413 : {
2414 4213578 : const auto name = source_params.checkForRename(std::string(name_in));
2415 4213578 : const auto p_name = new_name.empty() ? name_in : new_name;
2416 4213578 : if (!source_params.have_parameter<T>(name) && !source_params.hasCoupledVar(name))
2417 0 : mooseError("The '",
2418 : name_in,
2419 : "' parameter could not be transferred because it does not exist with type '",
2420 : MooseUtils::prettyCppType<T>(),
2421 : "' in the source parameters");
2422 4213578 : if (name != name_in)
2423 0 : mooseWarning("The transferred parameter " + name_in + " is deprecated in favor of " + name +
2424 : " in the source parameters. The new name should likely be used for the parameter "
2425 : "transfer instead.");
2426 8427156 : const std::string description =
2427 8427156 : new_description.empty() ? source_params.getDescription(name) : new_description;
2428 :
2429 4213578 : if (source_params.isParamRequired(name))
2430 : {
2431 : // Check for a variable parameter
2432 10 : if (source_params.hasCoupledVar(name))
2433 2 : addRequiredCoupledVar(p_name, description);
2434 : // Enums parameters have a default list of options
2435 : else if constexpr (std::is_same_v<MooseEnum, T> || std::is_same_v<MultiMooseEnum, T>)
2436 4 : addRequiredParam<T>(p_name, source_params.get<T>(name), description);
2437 4 : else if (source_params.isRangeChecked(name))
2438 2 : addRequiredRangeCheckedParam<T>(
2439 : p_name, source_params.rangeCheckedFunction(name), description);
2440 : else
2441 2 : addRequiredParam<T>(p_name, description);
2442 : }
2443 : else
2444 : {
2445 : // Check for a variable parameter
2446 4213568 : if (source_params.hasCoupledVar(name))
2447 : {
2448 6 : if (!source_params.hasDefaultCoupledValue(name))
2449 2 : addCoupledVar(p_name, description);
2450 4 : else if (source_params.numberDefaultCoupledValues(name) == 1)
2451 2 : addCoupledVar(p_name, source_params.defaultCoupledValue(name), description);
2452 : else
2453 : {
2454 2 : std::vector<Real> coupled_values;
2455 6 : for (const auto i : libMesh::make_range(source_params.numberDefaultCoupledValues(name)))
2456 4 : coupled_values.push_back(source_params.defaultCoupledValue(name, i));
2457 2 : addCoupledVar(p_name, coupled_values, description);
2458 2 : }
2459 : }
2460 4213562 : else if (source_params.isRangeChecked(name))
2461 : {
2462 4 : if (source_params.hasDefault(name))
2463 0 : addRangeCheckedParam<T>(p_name,
2464 : source_params.get<T>(name),
2465 : source_params.rangeCheckedFunction(name),
2466 : description);
2467 : else
2468 4 : addRangeCheckedParam<T>(p_name, source_params.rangeCheckedFunction(name), description);
2469 : }
2470 : else if constexpr (std::is_same_v<MooseEnum, T> || std::is_same_v<MultiMooseEnum, T>)
2471 817771 : addParam<T>(p_name, source_params.get<T>(name), description);
2472 : else
2473 : {
2474 3395787 : if (source_params.hasDefault(name))
2475 4 : addParam<T>(p_name, source_params.get<T>(name), description);
2476 : else
2477 3395783 : addParam<T>(p_name, description);
2478 : }
2479 : }
2480 :
2481 : // Copy other attributes
2482 4213578 : if (source_params.isPrivate(name))
2483 2 : _params[p_name]._is_private = true;
2484 4213578 : if (source_params.isControllable(name))
2485 2 : _params[p_name]._controllable = true;
2486 4213578 : }
2487 :
2488 : template <typename... Args>
2489 : [[noreturn]] void
2490 80 : InputParameters::mooseError(Args &&... args) const
2491 : {
2492 80 : std::ostringstream oss;
2493 80 : moose::internal::mooseStreamAll(oss, std::forward<Args>(args)...);
2494 118 : callMooseError(oss.str());
2495 38 : }
2496 :
2497 : template <typename... Args>
2498 : std::string
2499 206 : InputParameters::paramMessage(const std::string & param, Args... args) const
2500 : {
2501 206 : std::ostringstream oss;
2502 206 : moose::internal::mooseStreamAll(oss, std::forward<Args>(args)...);
2503 412 : return paramMessagePrefix(param) + oss.str();
2504 206 : }
2505 :
2506 : template <typename... Args>
2507 : [[noreturn]] void
2508 1294 : InputParameters::paramError(const std::string & param, Args... args) const
2509 : {
2510 1294 : std::ostringstream oss;
2511 1294 : moose::internal::mooseStreamAll(oss, std::forward<Args>(args)...);
2512 1294 : const auto [prefix, node] = paramMessageContext(param);
2513 1386 : callMooseError(prefix + oss.str(), false, node, /* show_trace = */ false);
2514 92 : }
2515 :
2516 : namespace Moose
2517 : {
2518 : namespace internal
2519 : {
2520 : template <typename T>
2521 : constexpr T *
2522 : getNullptrExample()
2523 : {
2524 : return nullptr;
2525 : }
2526 :
2527 : #ifdef MOOSE_MFEM_ENABLED
2528 :
2529 : template <typename T>
2530 : constexpr bool
2531 : isMFEMFunctorNameTypeHelper(T *)
2532 : {
2533 : return std::is_same_v<T, MFEMScalarCoefficientName> ||
2534 : std::is_same_v<T, MFEMVectorCoefficientName>;
2535 : }
2536 :
2537 : template <typename T, typename A>
2538 : constexpr bool
2539 : isMFEMFunctorNameTypeHelper(std::vector<T, A> *)
2540 : {
2541 : return isMFEMFunctorNameTypeHelper(getNullptrExample<T>());
2542 : }
2543 :
2544 : #endif
2545 :
2546 : template <typename T>
2547 : constexpr bool
2548 : isScalarFunctorNameTypeHelper(T *)
2549 : {
2550 : return std::is_same_v<T, MooseFunctorName>
2551 : #ifdef MOOSE_MFEM_ENABLED
2552 : || std::is_same_v<T, MFEMScalarCoefficientName>
2553 : #endif
2554 : ;
2555 : }
2556 :
2557 : template <typename T, typename A>
2558 : constexpr bool
2559 : isScalarFunctorNameTypeHelper(std::vector<T, A> *)
2560 : {
2561 : return isScalarFunctorNameTypeHelper(getNullptrExample<T>());
2562 : }
2563 :
2564 : template <typename T>
2565 : constexpr bool
2566 : isVectorFunctorNameTypeHelper(T *)
2567 : {
2568 : #ifdef MOOSE_MFEM_ENABLED
2569 : return std::is_same_v<T, MFEMVectorCoefficientName>;
2570 : #else
2571 : return false;
2572 : #endif
2573 : }
2574 :
2575 : template <typename T, typename A>
2576 : constexpr bool
2577 : isVectorFunctorNameTypeHelper(std::vector<T, A> *)
2578 : {
2579 : return isVectorFunctorNameTypeHelper(getNullptrExample<T>());
2580 : }
2581 :
2582 : template <typename T>
2583 : constexpr bool
2584 : isFunctorNameTypeHelper(T * ex)
2585 : {
2586 : return isScalarFunctorNameTypeHelper(ex) || isVectorFunctorNameTypeHelper(ex);
2587 : }
2588 : }
2589 : }
2590 :
2591 : template <typename T>
2592 : constexpr bool
2593 : InputParameters::isFunctorNameType()
2594 : {
2595 : return Moose::internal::isFunctorNameTypeHelper(Moose::internal::getNullptrExample<T>());
2596 : }
2597 :
2598 : template <typename T>
2599 : std::string
2600 822894 : InputParameters::appendFunctorDescription(const std::string & doc_string) const
2601 : {
2602 822894 : auto numeric_value_type = []()
2603 : {
2604 : if constexpr (Moose::internal::isScalarFunctorNameTypeHelper(
2605 : Moose::internal::getNullptrExample<T>()))
2606 771638 : return "number";
2607 : else if constexpr (Moose::internal::isVectorFunctorNameTypeHelper(
2608 : Moose::internal::getNullptrExample<T>()))
2609 51256 : return "numeric vector value (enclosed in curly braces)";
2610 : else
2611 : {
2612 : mooseAssert(false, "We control instantiations of this method");
2613 : return "";
2614 : }
2615 : };
2616 :
2617 : return MooseUtils::trim(doc_string, ". ") + ". A functor is any of the following: a variable, " +
2618 : (
2619 : #ifdef MOOSE_MFEM_ENABLED
2620 : Moose::internal::isMFEMFunctorNameTypeHelper(Moose::internal::getNullptrExample<T>())
2621 : ? "an MFEM"
2622 : :
2623 : #endif
2624 : "a functor") +
2625 2468682 : " material property, a function, a postprocessor or a " + numeric_value_type() + ".";
2626 : }
|