https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
InputParametersChecksUtils< C > Class Template Reference

Utility class to help check parameters. More...

#include <InputParametersChecksUtils.h>

Public Member Functions

 InputParametersChecksUtils (const C *customer_class)
 
template<typename T >
void assertParamDefined (const std::string &libmesh_dbg_var(param)) const
 

Protected Member Functions

template<typename T >
void assertParamDefined (const std::string &param) const
 Check in debug mode that this parameter has been added to the validParams.
 
void checkParamsBothSetOrNotSet (const std::string &param1, const std::string &param2) const
 Check that two parameters are either both set or both not set.
 
void checkAtMostOneParamSetByUser (const std::vector< std::string > &params) const
 Check that only one of the parameters are set.
 
void checkSecondParamSetOnlyIfFirstOneTrue (const std::string &param1, const std::string &param2) const
 Check that a parameter is set only if the first one is set to true.
 
void checkSecondParamSetOnlyIfFirstOneSet (const std::string &param1, const std::string &param2) const
 Check that a parameter is set only if the first one is set.
 
void checkSecondParamNotSetIfFirstOneSet (const std::string &param1, const std::string &param2) const
 Check that a parameter is not set if the first one is set.
 
template<typename T , typename S >
void checkVectorParamsSameLength (const std::string &param1, const std::string &param2) const
 Check that the two vector parameters are of the same length.
 
template<typename T >
void checkVectorParamAndMultiMooseEnumLength (const std::string &param1, const std::string &param2) const
 Check that this vector parameter (with name defined in param1) has the same length as the MultiMooseEnum (with name defined in param2)
 
template<typename T , typename S >
void checkTwoDVectorParamsSameLength (const std::string &param1, const std::string &param2) const
 Check that the two-D vectors have exactly the same length in both dimensions.
 
template<typename T >
void checkVectorParamsNoOverlap (const std::vector< std::string > &param_vecs) const
 Check that there is no overlap between the items in each vector parameters Each vector parameter should also have unique items.
 
template<typename T >
void checkTwoDVectorParamsNoRespectiveOverlap (const std::vector< std::string > &param_vecs) const
 Check that there is no overlap between the respective items in each vector of the two-D parameters Each vector of the two-D vector parameter should also have unique items.
 
template<typename T , typename S >
void checkTwoDVectorParamInnerSameLengthAsOneDVector (const std::string &param1, const std::string &param2) const
 Check that each inner vector of a two-D vector parameter are the same size as another one-D vector parameter.
 
template<typename T >
void checkTwoDVectorParamMultiMooseEnumSameLength (const std::string &param1, const std::string &param2, const bool error_for_param2) const
 Check that the size of a two-D vector parameter matches the size of a MultiMooseEnum parameter.
 
template<typename T >
void checkVectorParamNotEmpty (const std::string &param1) const
 Check that the user did not pass an empty vector.
 
template<typename T , typename S >
void checkVectorParamsSameLengthIfSet (const std::string &param1, const std::string &param2, const bool ignore_empty_default_param2=false) const
 Check that two vector parameters are the same length if both are set.
 
template<typename T , typename S , typename U >
void checkVectorParamLengthSameAsCombinedOthers (const std::string &param1, const std::string &param2, const std::string &param3) const
 Check that a vector parameter is the same length as two others combined.
 
template<typename T >
void checkBlockwiseConsistency (const std::string &block_param_name, const std::vector< std::string > &parameter_names) const
 Check if the user commited errors during the definition of block-wise parameters.
 
template<typename T >
bool parameterConsistent (const InputParameters &other_param, const std::string &param_name) const
 Return whether two parameters are consistent.
 
template<typename T >
void warnInconsistent (const InputParameters &parameters, const std::string &param_name) const
 Emits a warning if two parameters are not equal to each other.
 
void errorDependentParameter (const std::string &param1, const std::string &value_not_set, const std::vector< std::string > &dependent_params) const
 Error messages for parameters that should depend on another parameter.
 
void errorInconsistentDependentParameter (const std::string &param1, const std::string &value_set, const std::vector< std::string > &dependent_params) const
 Error messages for parameters that should depend on another parameter but with a different error message.
 

Private Member Functions

template<typename T >
const T & forwardGetParam (const std::string &param_name) const
 Forwards parameter check to the class using this utility.
 
const InputParameters & forwardParameters () const
 Forwards obtaining parameters to the class using this utility.
 
bool forwardIsParamSetByUser (const std::string &param_name) const
 Forwards parameter check to the class using this utility.
 
bool forwardIsParamValid (const std::string &param_name) const
 Forwards parameter check to the class using this utility.
 
template<typename... Args>
void forwardParamError (Args &&... args) const
 Forwards error to the class using this utility to get better error messages.
 
template<typename... Args>
void forwardMooseError (Args &&... args) const
 Forwards error to the class using this utility to get better error messages.
 
template<typename... Args>
void forwardMooseWarning (Args &&... args) const
 Forwards warning to the class using this utility to get better error messages.
 
const std::string & forwardType () const
 Get the type of the class using this utility.
 
virtual const std::string & forwardName () const
 Get the name of the class using this utility.
 
const std::vector< SubdomainName > & forwardBlocks () const
 Get the blocks for the class using this utility.
 

Private Attributes

const C *const _customer_class
 

Detailed Description

template<typename C>
class InputParametersChecksUtils< C >

Utility class to help check parameters.

This will be replaced by every check being baked into the validParams() logic, one day

Template Parameters
Ctype of the class using this utility C must be derived from both MooseBaseParameterInterface and MooseBaseErrorInterface

Definition at line 27 of file InputParametersChecksUtils.h.

Constructor & Destructor Documentation

◆ InputParametersChecksUtils()

template<typename C >
InputParametersChecksUtils< C >::InputParametersChecksUtils ( const C *  customer_class)
inline

Definition at line 30 of file InputParametersChecksUtils.h.

30: _customer_class(customer_class) {}

Member Function Documentation

◆ assertParamDefined() [1/2]

template<typename C >
template<typename T >
void InputParametersChecksUtils< C >::assertParamDefined ( const std::string &  libmesh_dbg_varparam) const

Definition at line 209 of file InputParametersChecksUtils.h.

210{
211 mooseAssert(forwardParameters().template have_parameter<T>(param),
212 "Parameter '" + param + "' is not defined with type '" +
213 MooseUtils::prettyCppType<T>() + "' in object type '" +
214 MooseUtils::prettyCppType(forwardType()) + "'. Check your code.");
215}
const InputParameters & forwardParameters() const
Forwards obtaining parameters to the class using this utility.
const std::string & forwardType() const
Get the type of the class using this utility.
std::string prettyCppType(const std::string &cpp_type)

◆ assertParamDefined() [2/2]

template<typename C >
template<typename T >
void InputParametersChecksUtils< C >::assertParamDefined ( const std::string &  param) const
protected

Check in debug mode that this parameter has been added to the validParams.

Parameters
paramparameter that should be defined

◆ checkAtMostOneParamSetByUser()

template<typename C >
void InputParametersChecksUtils< C >::checkAtMostOneParamSetByUser ( const std::vector< std::string > &  params) const
protected

Check that only one of the parameters are set.

Parameters
paramsvector of parameters, only one should be set

Definition at line 606 of file InputParametersChecksUtils.h.

608{
609 unsigned int num_set = 0;
610 for (const auto & param : params)
611 num_set += forwardIsParamSetByUser(param);
612
613 if (num_set <= 1)
614 return;
615
616 std::vector<std::string> params_set;
617 std::string first_set;
618 for (const auto & param : params)
620 {
621 params_set.push_back(param);
622 if (first_set.empty())
623 first_set = param;
624 }
625
626 forwardParamError(first_set,
627 "Only one parameter of:\n" + Moose::stringify(params),
628 "\nshould be set but:\n" + Moose::stringify(params_set),
629 "\nhave been set.");
630}
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
void forwardParamError(Args &&... args) const
Forwards error to the class using this utility to get better error messages.
bool forwardIsParamSetByUser(const std::string &param_name) const
Forwards parameter check to the class using this utility.
std::string stringify(const T &t)
conversion to string
Definition Conversion.h:65

◆ checkBlockwiseConsistency()

template<typename C >
template<typename T >
void InputParametersChecksUtils< C >::checkBlockwiseConsistency ( const std::string &  block_param_name,
const std::vector< std::string > &  parameter_names 
) const
protected

Check if the user commited errors during the definition of block-wise parameters.

Parameters
block_param_namethe name of the parameter that provides the groups of blocks
parameter_namesvector of the names of the parameters that are defined on a per-block basis

Definition at line 486 of file InputParametersChecksUtils.h.

488{
489 const std::vector<std::vector<SubdomainName>> & block_names =
490 forwardGetParam<std::vector<std::vector<SubdomainName>>>(block_param_name);
491
492 if (block_names.size())
493 {
494 // We only check block-restrictions if the customer class is not restricted to `ANY_BLOCK_ID`.
495 // If the users define blocks that are not on the mesh, they will receive errors from the
496 // objects created by the customer class
497 const auto & object_blocks = forwardBlocks();
498 if (std::find(object_blocks.begin(), object_blocks.end(), "ANY_BLOCK_ID") ==
499 object_blocks.end())
500 for (const auto & block_group : block_names)
501 for (const auto & block : block_group)
502 if (std::find(object_blocks.begin(), object_blocks.end(), block) == object_blocks.end())
503 forwardParamError(block_param_name,
504 "Block '" + block + "' is not present in the block restriction of " +
505 forwardName() +
506 "!\nBlock restriction: " + Moose::stringify(object_blocks));
507
508 for (const auto & param_name : parameter_names)
509 {
510 const std::vector<T> & param_vector = forwardGetParam<std::vector<T>>(param_name);
511 if (block_names.size() != param_vector.size())
512 forwardParamError(param_name,
513 "The number of entries in '" + param_name + "' (" +
514 std::to_string(param_vector.size()) +
515 ") is not the same as the number of blocks"
516 " (" +
517 std::to_string(block_names.size()) + ") in '" + block_param_name +
518 "'!");
519 }
520 }
521 else
522 {
523 unsigned int previous_size = 0;
524 for (const auto param_i : index_range(parameter_names))
525 {
526 const std::vector<T> & param_vector =
527 forwardGetParam<std::vector<T>>(parameter_names[param_i]);
528 if (param_i == 0)
529 {
530 if (param_vector.size() > 1)
531 forwardParamError(parameter_names[param_i],
532 "The user should only use one or zero entries in " +
533 parameter_names[param_i] + " if " + block_param_name +
534 " not defined!");
535 previous_size = param_vector.size();
536 }
537 else
538 {
539 if (previous_size != param_vector.size())
540 forwardParamError(parameter_names[param_i],
541 "The number of entries in '" + parameter_names[param_i] +
542 "' is not the same as the number of entries in '" +
543 parameter_names[param_i - 1] + "'!");
544 }
545 }
546 }
547}
for(PetscInt i=0;i< nvars;++i)
const std::vector< SubdomainName > & forwardBlocks() const
Get the blocks for the class using this utility.
virtual const std::string & forwardName() const
Get the name of the class using this utility.
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
Definition KokkosUtils.h:40
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
std::string stringify(MOOSEIOType type)
Definition NEML2Utils.C:18
auto index_range(const T &sizable)

◆ checkParamsBothSetOrNotSet()

template<typename C >
void InputParametersChecksUtils< C >::checkParamsBothSetOrNotSet ( const std::string &  param1,
const std::string &  param2 
) const
protected

Check that two parameters are either both set or both not set.

Parameters
param1first parameter to check
param2second parameter to check

Definition at line 595 of file InputParametersChecksUtils.h.

597{
598 if ((forwardIsParamValid(param1) + forwardIsParamValid(param2)) % 2 != 0)
599 forwardParamError(param1,
600 "Parameters '" + param1 + "' and '" + param2 +
601 "' must be either both set or both not set.");
602}
bool forwardIsParamValid(const std::string &param_name) const
Forwards parameter check to the class using this utility.

◆ checkSecondParamNotSetIfFirstOneSet()

template<typename C >
void InputParametersChecksUtils< C >::checkSecondParamNotSetIfFirstOneSet ( const std::string &  param1,
const std::string &  param2 
) const
protected

Check that a parameter is not set if the first one is set.

Parameters
param1first parameter to check, check that the second is not if this one is set
param2second parameter to check, that should not be set if first one is set

Definition at line 659 of file InputParametersChecksUtils.h.

661{
663 forwardParamError(param2,
664 "Parameter '" + param2 + "' should not be specified if parameter '" + param1 +
665 "' is specified.");
666}

◆ checkSecondParamSetOnlyIfFirstOneSet()

template<typename C >
void InputParametersChecksUtils< C >::checkSecondParamSetOnlyIfFirstOneSet ( const std::string &  param1,
const std::string &  param2 
) const
protected

Check that a parameter is set only if the first one is set.

Parameters
param1first parameter to check, check the second if set
param2second parameter to check, that should be set if first one is set

Definition at line 648 of file InputParametersChecksUtils.h.

650{
651 if (!forwardIsParamSetByUser(param1) && forwardIsParamSetByUser(param2))
652 forwardParamError(param2,
653 "Parameter '" + param2 + "' should not be set if parameter '" + param1 +
654 "' is not specified.");
655}

◆ checkSecondParamSetOnlyIfFirstOneTrue()

template<typename C >
void InputParametersChecksUtils< C >::checkSecondParamSetOnlyIfFirstOneTrue ( const std::string &  param1,
const std::string &  param2 
) const
protected

Check that a parameter is set only if the first one is set to true.

Parameters
param1first parameter to check, check the second if true
param2second parameter to check, that should be set if first one is true

Definition at line 634 of file InputParametersChecksUtils.h.

636{
637 mooseAssert(forwardParameters().template have_parameter<bool>(param1),
638 "Cannot check if parameter " + param1 +
639 " is true if it's not a bool parameter of this object");
640 if (!forwardGetParam<bool>(param1) && forwardIsParamSetByUser(param2))
641 forwardParamError(param2,
642 "Parameter '" + param1 + "' cannot be set to false if parameter '" + param2 +
643 "' is set by the user");
644}

◆ checkTwoDVectorParamInnerSameLengthAsOneDVector()

template<typename C >
template<typename T , typename S >
void InputParametersChecksUtils< C >::checkTwoDVectorParamInnerSameLengthAsOneDVector ( const std::string &  param1,
const std::string &  param2 
) const
protected

Check that each inner vector of a two-D vector parameter are the same size as another one-D vector parameter.

Parameters
param1two-D vector parameter to check the dimensions of
param2one-D vector parameter to set the desired size

Definition at line 299 of file InputParametersChecksUtils.h.

301{
302 assertParamDefined<std::vector<std::vector<T>>>(param1);
303 assertParamDefined<std::vector<S>>(param2);
304 for (const auto & sub_vec_i : index_range(forwardGetParam<std::vector<std::vector<T>>>(param1)))
305 {
306 const auto size_1 = forwardGetParam<std::vector<std::vector<T>>>(param1)[sub_vec_i].size();
307 const auto size_2 = forwardGetParam<std::vector<S>>(param2).size();
308 if (size_1 != size_2)
309 forwardParamError(param1,
310 "Vector at index " + std::to_string(sub_vec_i) + " (size " +
311 std::to_string(size_1) +
312 ") "
313 " of this parameter should be the same length as parameter '" +
314 param2 + "' (size " + std::to_string(size_2) + ")");
315 }
316}
const T & forwardGetParam(const std::string &param_name) const
Forwards parameter check to the class using this utility.

◆ checkTwoDVectorParamMultiMooseEnumSameLength()

template<typename C >
template<typename T >
void InputParametersChecksUtils< C >::checkTwoDVectorParamMultiMooseEnumSameLength ( const std::string &  param1,
const std::string &  param2,
const bool  error_for_param2 
) const
protected

Check that the size of a two-D vector parameter matches the size of a MultiMooseEnum parameter.

Parameters
param1two-D vector parameter to check the unrolled size of
param2MultiMooseEnum parameter to set the desired size

Definition at line 321 of file InputParametersChecksUtils.h.

323{
324 assertParamDefined<std::vector<std::vector<T>>>(param1);
325 assertParamDefined<MultiMooseEnum>(param2);
326 const auto vec1 = forwardGetParam<std::vector<std::vector<T>>>(param1);
327 const auto enum2 = forwardGetParam<MultiMooseEnum>(param2);
328 const auto size_1 = vec1.empty() ? 0 : vec1.size() * vec1[0].size();
329 const auto size_2 = enum2.size();
330 if (size_1 != size_2)
331 {
332 if (error_for_param2)
333 forwardParamError(param2,
334 "Vector enumeration parameter (size " + std::to_string(size_2) +
335 ") is not the same size as the vector of vector parameter '" + param1 +
336 "' (size " + std::to_string(size_1) + ")");
337 else
338 forwardParamError(param1,
339 "Vector of vector parameter '" + param1 + "' (total size " +
340 std::to_string(size_1) +
341 ") is not the same size as vector-enumeration parameter '" + param2 +
342 "' (size " + std::to_string(size_2) + ")");
343 }
344}

◆ checkTwoDVectorParamsNoRespectiveOverlap()

template<typename C >
template<typename T >
void InputParametersChecksUtils< C >::checkTwoDVectorParamsNoRespectiveOverlap ( const std::vector< std::string > &  param_vecs) const
protected

Check that there is no overlap between the respective items in each vector of the two-D parameters Each vector of the two-D vector parameter should also have unique items.

Parameters
param_vecsvector of parameters that should not overlap with each other

Definition at line 398 of file InputParametersChecksUtils.h.

400{
401 // Outer loop, each param is the name of a parameter for a vector of vectors
402 for (const auto & param : param_vec)
403 {
404 assertParamDefined<std::vector<std::vector<T>>>(param);
405 const auto & twoD_vec = forwardGetParam<std::vector<std::vector<T>>>(param);
406 std::vector<std::set<T>> unique_params(twoD_vec.size());
407
408 // Loop over each outer vector and compare the inner vectors respectively to other parameters
409 for (const auto i : index_range(twoD_vec))
410 {
411 for (const auto & value : twoD_vec[i])
412 if (!unique_params[i].insert(value).second)
413 {
414 auto copy_params = param_vec;
415 copy_params.erase(std::find(copy_params.begin(), copy_params.end(), param));
416 forwardMooseError("Item '" + value + "' specified in vector parameter '" + param +
417 "' is also present in one or more of the two-D vector parameters '" +
418 Moose::stringify(copy_params) +
419 "' in the inner vector of the same index, which is not allowed.");
420 }
421 }
422 }
423}
void forwardMooseError(Args &&... args) const
Forwards error to the class using this utility to get better error messages.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ checkTwoDVectorParamsSameLength()

template<typename C >
template<typename T , typename S >
void InputParametersChecksUtils< C >::checkTwoDVectorParamsSameLength ( const std::string &  param1,
const std::string &  param2 
) const
protected

Check that the two-D vectors have exactly the same length in both dimensions.

Parameters
param1first two-D vector parameter to check the dimensions of
param2second two-D vector parameter to check the dimensions of

Definition at line 272 of file InputParametersChecksUtils.h.

274{
275 checkVectorParamsSameLength<std::vector<T>, std::vector<S>>(param1, param2);
276 if (forwardIsParamValid(param1) && forwardIsParamValid(param2))
277 {
278 const auto value1 = forwardGetParam<std::vector<std::vector<T>>>(param1);
279 const auto value2 = forwardGetParam<std::vector<std::vector<S>>>(param2);
280 for (const auto index : index_range(value1))
281 if (value1[index].size() != value2[index].size())
283 param1,
284 "Vector at index " + std::to_string(index) + " of 2D vector parameter '" + param1 +
285 "' is not the same size as its counterpart from 2D vector parameter '" + param2 +
286 "'.\nSize first vector: " + std::to_string(value1[index].size()) +
287 "\nSize second vector: " + std::to_string(value2[index].size()));
288 }
289 // handle empty vector defaults
290 else if (forwardIsParamValid(param1) || forwardIsParamValid(param2))
291 if (forwardGetParam<std::vector<T>>(param1).size() ||
292 forwardGetParam<std::vector<S>>(param2).size())
293 checkParamsBothSetOrNotSet(param1, param2);
294}
void checkParamsBothSetOrNotSet(const std::string &param1, const std::string &param2) const
Check that two parameters are either both set or both not set.

◆ checkVectorParamAndMultiMooseEnumLength()

template<typename C >
template<typename T >
void InputParametersChecksUtils< C >::checkVectorParamAndMultiMooseEnumLength ( const std::string &  param1,
const std::string &  param2 
) const
protected

Check that this vector parameter (with name defined in param1) has the same length as the MultiMooseEnum (with name defined in param2)

Parameters
param1vector parameter to compare the size of
param2multiMooseEnum parameter to compare the size of

Definition at line 246 of file InputParametersChecksUtils.h.

248{
249 assertParamDefined<std::vector<T>>(param1);
250 assertParamDefined<MultiMooseEnum>(param2);
251
252 if (forwardIsParamValid(param1) && forwardIsParamValid(param2))
253 {
254 const auto size_1 = forwardGetParam<std::vector<T>>(param1).size();
255 const auto size_2 = forwardGetParam<MultiMooseEnum>(param2).size();
256 if (size_1 != size_2)
257 forwardParamError(param1,
258 "Vector parameters '" + param1 + "' (size " + std::to_string(size_1) +
259 ") and '" + param2 + "' (size " + std::to_string(size_2) +
260 ") must be the same size");
261 }
262 // handle empty vector defaults
263 else if (forwardIsParamValid(param1) || forwardIsParamValid(param2))
264 if (forwardGetParam<std::vector<T>>(param1).size() ||
265 forwardGetParam<MultiMooseEnum>(param2).size())
266 checkParamsBothSetOrNotSet(param1, param2);
267}

◆ checkVectorParamLengthSameAsCombinedOthers()

template<typename C >
template<typename T , typename S , typename U >
void InputParametersChecksUtils< C >::checkVectorParamLengthSameAsCombinedOthers ( const std::string &  param1,
const std::string &  param2,
const std::string &  param3 
) const
protected

Check that a vector parameter is the same length as two others combined.

Parameters
param1vector parameter that provides the target size
param2vector parameter that provides one term in the combined size
param3vector parameter that provides one term in the combined size

Definition at line 349 of file InputParametersChecksUtils.h.

351{
352 assertParamDefined<std::vector<T>>(param1);
353 assertParamDefined<std::vector<S>>(param2);
354 assertParamDefined<std::vector<U>>(param3);
355 const auto size_1 = forwardGetParam<std::vector<T>>(param1).size();
356 const auto size_2 = forwardGetParam<std::vector<S>>(param2).size();
357 const auto size_3 = forwardGetParam<std::vector<U>>(param3).size();
358
359 if (size_1 != size_2 + size_3)
360 forwardParamError(param1,
361 "Vector parameter '" + param1 + "' (size " + std::to_string(size_1) +
362 ") should be the same size as parameter '" + param2 + "' and '" + param3 +
363 " combined (total size " + std::to_string(size_2 + size_3) + ")");
364}

◆ checkVectorParamNotEmpty()

template<typename C >
template<typename T >
void InputParametersChecksUtils< C >::checkVectorParamNotEmpty ( const std::string &  param1) const
protected

Check that the user did not pass an empty vector.

Parameters
param1vector parameter that should not be empty

Definition at line 428 of file InputParametersChecksUtils.h.

429{
430 assertParamDefined<std::vector<T>>(param);
431 if (!forwardGetParam<std::vector<T>>(param).size())
432 forwardParamError(param, "Parameter '" + param + "' should not be set to an empty vector.");
433}

◆ checkVectorParamsNoOverlap()

template<typename C >
template<typename T >
void InputParametersChecksUtils< C >::checkVectorParamsNoOverlap ( const std::vector< std::string > &  param_vecs) const
protected

Check that there is no overlap between the items in each vector parameters Each vector parameter should also have unique items.

Parameters
param_vecsvector of parameters that should not overlap with each other

Definition at line 369 of file InputParametersChecksUtils.h.

371{
372 std::set<std::string> unique_params;
373 for (const auto & param : param_vec)
374 {
375 assertParamDefined<std::vector<T>>(param);
376
377 for (const auto & value : forwardGetParam<std::vector<T>>(param))
378 if (!unique_params.insert(value).second)
379 {
380 auto copy_params = param_vec;
381 copy_params.erase(std::find(copy_params.begin(), copy_params.end(), param));
382 // Overlap between multiple vectors of parameters
383 if (copy_params.size())
384 forwardMooseError("Item '" + value + "' specified in vector parameter '" + param +
385 "' is also present in one or more of the parameters '" +
386 Moose::stringify(copy_params) + "', which is not allowed.");
387 // Overlap within a single vector parameter caused by a repeated item
388 else
389 forwardMooseError("Item '" + value + "' specified in vector parameter '" + param +
390 "' is repeated, which is not allowed.");
391 }
392 }
393}

◆ checkVectorParamsSameLength()

template<typename C >
template<typename T , typename S >
void InputParametersChecksUtils< C >::checkVectorParamsSameLength ( const std::string &  param1,
const std::string &  param2 
) const
protected

Check that the two vector parameters are of the same length.

Parameters
param1first vector parameter to compare the size of
param2second vector parameter to compare the size of

Definition at line 220 of file InputParametersChecksUtils.h.

222{
223 assertParamDefined<std::vector<T>>(param1);
224 assertParamDefined<std::vector<S>>(param2);
225
226 if (forwardIsParamValid(param1) && forwardIsParamValid(param2))
227 {
228 const auto size_1 = forwardGetParam<std::vector<T>>(param1).size();
229 const auto size_2 = forwardGetParam<std::vector<S>>(param2).size();
230 if (size_1 != size_2)
231 forwardParamError(param1,
232 "Vector parameters '" + param1 + "' (size " + std::to_string(size_1) +
233 ") and '" + param2 + "' (size " + std::to_string(size_2) +
234 ") must be the same size");
235 }
236 // handle empty vector defaults
237 else if (forwardIsParamValid(param1) || forwardIsParamValid(param2))
238 if (forwardGetParam<std::vector<T>>(param1).size() ||
239 forwardGetParam<std::vector<S>>(param2).size())
240 checkParamsBothSetOrNotSet(param1, param2);
241}

◆ checkVectorParamsSameLengthIfSet()

template<typename C >
template<typename T , typename S >
void InputParametersChecksUtils< C >::checkVectorParamsSameLengthIfSet ( const std::string &  param1,
const std::string &  param2,
const bool  ignore_empty_default_param2 = false 
) const
protected

Check that two vector parameters are the same length if both are set.

Parameters
param1first vector parameter to check the size of
param2second vector parameter to check the size of

Definition at line 438 of file InputParametersChecksUtils.h.

442{
443 assertParamDefined<std::vector<T>>(param1);
444 assertParamDefined<std::vector<S>>(param2);
445
446 if (forwardIsParamValid(param1) && forwardIsParamValid(param2))
447 {
448 const auto size_1 = forwardGetParam<std::vector<T>>(param1).size();
449 const auto size_2 = forwardGetParam<std::vector<S>>(param2).size();
450 if (ignore_empty_default_param2 && (size_2 == 0) && !forwardIsParamSetByUser(param2))
451 return;
452 if (size_1 != size_2)
453 forwardParamError(param1,
454 "Parameter '" + param1 + "' (size " + std::to_string(size_1) + ") and '" +
455 param2 + "' (size " + std::to_string(size_2) +
456 ") must be the same size if set.");
457 }
458}

◆ errorDependentParameter()

template<typename C >
void InputParametersChecksUtils< C >::errorDependentParameter ( const std::string &  param1,
const std::string &  value_not_set,
const std::vector< std::string > &  dependent_params 
) const
protected

Error messages for parameters that should depend on another parameter.

Parameters
param1the parameter has not been set to the desired value (for logging purposes)
value_not_setthe desired value (for logging purposes)
dependent_paramsall the parameters that should not have been since 'param1' was not set to 'value_not_set'

Definition at line 565 of file InputParametersChecksUtils.h.

569{
570 for (const auto & dependent_param : dependent_params)
571 if (forwardIsParamSetByUser(dependent_param))
572 forwardParamError(dependent_param,
573 "Parameter '" + dependent_param +
574 "' should not be set by the user if parameter '" + param1 +
575 "' has not been set to '" + value_not_set + "'");
576}

◆ errorInconsistentDependentParameter()

template<typename C >
void InputParametersChecksUtils< C >::errorInconsistentDependentParameter ( const std::string &  param1,
const std::string &  value_set,
const std::vector< std::string > &  dependent_params 
) const
protected

Error messages for parameters that should depend on another parameter but with a different error message.

Parameters
param1the parameter has not been set to the desired value (for logging purposes)
value_setthe value it has been set to and which is not appropriate (for logging purposes)
dependent_paramsall the parameters that should not have been set since 'param1' was set to 'value_set'

Definition at line 580 of file InputParametersChecksUtils.h.

584{
585 for (const auto & dependent_param : dependent_params)
586 if (forwardIsParamSetByUser(dependent_param))
587 forwardParamError(dependent_param,
588 "Parameter '" + dependent_param +
589 "' should not be set by the user if parameter '" + param1 +
590 "' has been set to '" + value_set + "'");
591}

◆ forwardBlocks()

template<typename C >
const std::vector< SubdomainName > & InputParametersChecksUtils< C >::forwardBlocks ( ) const
inlineprivate

Get the blocks for the class using this utility.

Definition at line 195 of file InputParametersChecksUtils.h.

196 {
197 // TODO Use SFINAE to create a version for classes that do not define blocks()
198 // TODO Use SFINAE to force blocks() to return a reference as well
199 return _customer_class->blocks();
200 }

◆ forwardGetParam()

template<typename C >
template<typename T >
const T & InputParametersChecksUtils< C >::forwardGetParam ( const std::string &  param_name) const
inlineprivate

Forwards parameter check to the class using this utility.

Definition at line 156 of file InputParametersChecksUtils.h.

157 {
158 return _customer_class->template getParam<T>(param_name);
159 }

◆ forwardIsParamSetByUser()

template<typename C >
bool InputParametersChecksUtils< C >::forwardIsParamSetByUser ( const std::string &  param_name) const
inlineprivate

Forwards parameter check to the class using this utility.

Definition at line 163 of file InputParametersChecksUtils.h.

164 {
165 return _customer_class->isParamSetByUser(param_name);
166 }

◆ forwardIsParamValid()

template<typename C >
bool InputParametersChecksUtils< C >::forwardIsParamValid ( const std::string &  param_name) const
inlineprivate

Forwards parameter check to the class using this utility.

Definition at line 168 of file InputParametersChecksUtils.h.

169 {
170 return _customer_class->isParamValid(param_name);
171 }

◆ forwardMooseError()

template<typename C >
template<typename... Args>
void InputParametersChecksUtils< C >::forwardMooseError ( Args &&...  args) const
inlineprivate

Forwards error to the class using this utility to get better error messages.

Definition at line 180 of file InputParametersChecksUtils.h.

181 {
182 _customer_class->mooseError(std::forward<Args>(args)...);
183 }

◆ forwardMooseWarning()

template<typename C >
template<typename... Args>
void InputParametersChecksUtils< C >::forwardMooseWarning ( Args &&...  args) const
inlineprivate

Forwards warning to the class using this utility to get better error messages.

Definition at line 186 of file InputParametersChecksUtils.h.

187 {
188 _customer_class->mooseWarning(std::forward<Args>(args)...);
189 }

◆ forwardName()

template<typename C >
virtual const std::string & InputParametersChecksUtils< C >::forwardName ( ) const
inlineprivatevirtual

Get the name of the class using this utility.

Definition at line 193 of file InputParametersChecksUtils.h.

193{ return _customer_class->name(); }

◆ forwardParamError()

template<typename C >
template<typename... Args>
void InputParametersChecksUtils< C >::forwardParamError ( Args &&...  args) const
inlineprivate

Forwards error to the class using this utility to get better error messages.

Definition at line 174 of file InputParametersChecksUtils.h.

175 {
176 _customer_class->paramError(std::forward<Args>(args)...);
177 }

◆ forwardParameters()

template<typename C >
const InputParameters & InputParametersChecksUtils< C >::forwardParameters ( ) const
inlineprivate

Forwards obtaining parameters to the class using this utility.

Definition at line 161 of file InputParametersChecksUtils.h.

161{ return _customer_class->parameters(); }

◆ forwardType()

template<typename C >
const std::string & InputParametersChecksUtils< C >::forwardType ( ) const
inlineprivate

Get the type of the class using this utility.

Definition at line 191 of file InputParametersChecksUtils.h.

191{ return _customer_class->type(); }

◆ parameterConsistent()

template<typename C >
template<typename T >
bool InputParametersChecksUtils< C >::parameterConsistent ( const InputParameters &  other_param,
const std::string &  param_name 
) const
protected

Return whether two parameters are consistent.

Parameters
other_paramInputParameters object from another object to check the 'param_name' parameter in
param_namethe name of the parameter to check for consistency

Definition at line 463 of file InputParametersChecksUtils.h.

465{
466 assertParamDefined<T>(param_name);
467 mooseAssert(other_param.have_parameter<T>(param_name),
468 "This should have been a parameter from the parameters being compared");
469 bool consistent = true;
470 if (forwardParameters().isParamValid(param_name) && other_param.isParamValid(param_name))
471 {
472 if constexpr (std::is_same_v<MooseEnum, T>)
473 {
474 if (!forwardGetParam<T>(param_name).compareCurrent(other_param.get<T>(param_name)))
475 consistent = false;
476 }
477 else if (forwardGetParam<T>(param_name) != other_param.get<T>(param_name))
478 consistent = false;
479 }
480 return consistent;
481}
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
bool have_parameter(std::string_view name) const
A wrapper around the Parameters base class method.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another,...

◆ warnInconsistent()

template<typename C >
template<typename T >
void InputParametersChecksUtils< C >::warnInconsistent ( const InputParameters &  parameters,
const std::string &  param_name 
) const
protected

Emits a warning if two parameters are not equal to each other.

Parameters
other_paramInputParameters object from another object to check the 'param_name' parameter in
param_namethe name of the parameter to check for consistency

Definition at line 552 of file InputParametersChecksUtils.h.

554{
555 const bool consistent = parameterConsistent<T>(other_param, param_name);
556 if (!consistent)
557 forwardMooseWarning("Parameter " + param_name + " is inconsistent between Physics \"" +
558 forwardName() + "\" of type \"" + forwardType() +
559 "\" and the parameter set for \"" + other_param.getObjectName() +
560 "\" of type \"" + other_param.getObjectType() + "\"");
561}
void forwardMooseWarning(Args &&... args) const
Forwards warning to the class using this utility to get better error messages.

Member Data Documentation

◆ _customer_class

template<typename C >
const C* const InputParametersChecksUtils< C >::_customer_class
private

The documentation for this class was generated from the following file: