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 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 InputParametersforwardParameters () 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 206 of file InputParametersChecksUtils.h.

207{
208 mooseAssert(forwardParameters().template have_parameter<T>(param),
209 "Parameter '" + param + "' is not defined with type '" +
210 MooseUtils::prettyCppType<T>() + "' in object type '" +
211 MooseUtils::prettyCppType(forwardType()) + "'. Check your code.");
212}
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

◆ 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 483 of file InputParametersChecksUtils.h.

485{
486 const std::vector<std::vector<SubdomainName>> & block_names =
487 forwardGetParam<std::vector<std::vector<SubdomainName>>>(block_param_name);
488
489 if (block_names.size())
490 {
491 // We only check block-restrictions if the customer class is not restricted to `ANY_BLOCK_ID`.
492 // If the users define blocks that are not on the mesh, they will receive errors from the
493 // objects created by the customer class
494 const auto & object_blocks = forwardBlocks();
495 if (std::find(object_blocks.begin(), object_blocks.end(), "ANY_BLOCK_ID") ==
496 object_blocks.end())
497 for (const auto & block_group : block_names)
498 for (const auto & block : block_group)
499 if (std::find(object_blocks.begin(), object_blocks.end(), block) == object_blocks.end())
500 forwardParamError(block_param_name,
501 "Block '" + block + "' is not present in the block restriction of " +
502 forwardName() +
503 "!\nBlock restriction: " + Moose::stringify(object_blocks));
504
505 for (const auto & param_name : parameter_names)
506 {
507 const std::vector<T> & param_vector = forwardGetParam<std::vector<T>>(param_name);
508 if (block_names.size() != param_vector.size())
509 forwardParamError(param_name,
510 "The number of entries in '" + param_name + "' (" +
511 std::to_string(param_vector.size()) +
512 ") is not the same as the number of blocks"
513 " (" +
514 std::to_string(block_names.size()) + ") in '" + block_param_name +
515 "'!");
516 }
517 }
518 else
519 {
520 unsigned int previous_size = 0;
521 for (const auto param_i : index_range(parameter_names))
522 {
523 const std::vector<T> & param_vector =
524 forwardGetParam<std::vector<T>>(parameter_names[param_i]);
525 if (param_i == 0)
526 {
527 if (param_vector.size() > 1)
528 forwardParamError(parameter_names[param_i],
529 "The user should only use one or zero entries in " +
530 parameter_names[param_i] + " if " + block_param_name +
531 " not defined!");
532 previous_size = param_vector.size();
533 }
534 else
535 {
536 if (previous_size != param_vector.size())
537 forwardParamError(parameter_names[param_i],
538 "The number of entries in '" + parameter_names[param_i] +
539 "' is not the same as the number of entries in '" +
540 parameter_names[param_i - 1] + "'!");
541 }
542 }
543 }
544}
for(PetscInt i=0;i< nvars;++i)
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.
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 592 of file InputParametersChecksUtils.h.

594{
595 if ((forwardIsParamValid(param1) + forwardIsParamValid(param2)) % 2 != 0)
596 forwardParamError(param1,
597 "Parameters '" + param1 + "' and '" + param2 +
598 "' must be either both set or both not set.");
599}
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 628 of file InputParametersChecksUtils.h.

630{
632 forwardParamError(param2,
633 "Parameter '" + param2 + "' should not be specified if parameter '" + param1 +
634 "' is specified.");
635}
bool forwardIsParamSetByUser(const std::string &param_name) const
Forwards parameter check to the class using this utility.

◆ 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 617 of file InputParametersChecksUtils.h.

619{
620 if (!forwardIsParamSetByUser(param1) && forwardIsParamSetByUser(param2))
621 forwardParamError(param2,
622 "Parameter '" + param2 + "' should not be set if parameter '" + param1 +
623 "' is not specified.");
624}

◆ 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 603 of file InputParametersChecksUtils.h.

605{
606 mooseAssert(forwardParameters().template have_parameter<bool>(param1),
607 "Cannot check if parameter " + param1 +
608 " is true if it's not a bool parameter of this object");
609 if (!forwardGetParam<bool>(param1) && forwardIsParamSetByUser(param2))
610 forwardParamError(param2,
611 "Parameter '" + param1 + "' cannot be set to false if parameter '" + param2 +
612 "' is set by the user");
613}

◆ 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 296 of file InputParametersChecksUtils.h.

298{
299 assertParamDefined<std::vector<std::vector<T>>>(param1);
300 assertParamDefined<std::vector<S>>(param2);
301 for (const auto & sub_vec_i : index_range(forwardGetParam<std::vector<std::vector<T>>>(param1)))
302 {
303 const auto size_1 = forwardGetParam<std::vector<std::vector<T>>>(param1)[sub_vec_i].size();
304 const auto size_2 = forwardGetParam<std::vector<S>>(param2).size();
305 if (size_1 != size_2)
306 forwardParamError(param1,
307 "Vector at index " + std::to_string(sub_vec_i) + " (size " +
308 std::to_string(size_1) +
309 ") "
310 " of this parameter should be the same length as parameter '" +
311 param2 + "' (size " + std::to_string(size_2) + ")");
312 }
313}
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 318 of file InputParametersChecksUtils.h.

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

◆ 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 395 of file InputParametersChecksUtils.h.

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

271{
272 checkVectorParamsSameLength<std::vector<T>, std::vector<S>>(param1, param2);
273 if (forwardIsParamValid(param1) && forwardIsParamValid(param2))
274 {
275 const auto value1 = forwardGetParam<std::vector<std::vector<T>>>(param1);
276 const auto value2 = forwardGetParam<std::vector<std::vector<S>>>(param2);
277 for (const auto index : index_range(value1))
278 if (value1[index].size() != value2[index].size())
280 param1,
281 "Vector at index " + std::to_string(index) + " of 2D vector parameter '" + param1 +
282 "' is not the same size as its counterpart from 2D vector parameter '" + param2 +
283 "'.\nSize first vector: " + std::to_string(value1[index].size()) +
284 "\nSize second vector: " + std::to_string(value2[index].size()));
285 }
286 // handle empty vector defaults
287 else if (forwardIsParamValid(param1) || forwardIsParamValid(param2))
288 if (forwardGetParam<std::vector<T>>(param1).size() ||
289 forwardGetParam<std::vector<S>>(param2).size())
290 checkParamsBothSetOrNotSet(param1, param2);
291}
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 243 of file InputParametersChecksUtils.h.

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

◆ 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 346 of file InputParametersChecksUtils.h.

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

◆ 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 425 of file InputParametersChecksUtils.h.

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

◆ 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 366 of file InputParametersChecksUtils.h.

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

◆ 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 217 of file InputParametersChecksUtils.h.

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

◆ 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 435 of file InputParametersChecksUtils.h.

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

◆ 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 562 of file InputParametersChecksUtils.h.

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

◆ 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 577 of file InputParametersChecksUtils.h.

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

◆ 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 192 of file InputParametersChecksUtils.h.

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

◆ 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 153 of file InputParametersChecksUtils.h.

154 {
155 return _customer_class->template getParam<T>(param_name);
156 }

◆ 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 160 of file InputParametersChecksUtils.h.

161 {
162 return _customer_class->isParamSetByUser(param_name);
163 }

◆ 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 165 of file InputParametersChecksUtils.h.

166 {
167 return _customer_class->isParamValid(param_name);
168 }

◆ 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 177 of file InputParametersChecksUtils.h.

178 {
179 _customer_class->mooseError(std::forward<Args>(args)...);
180 }

◆ 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 183 of file InputParametersChecksUtils.h.

184 {
185 _customer_class->mooseWarning(std::forward<Args>(args)...);
186 }

◆ 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 190 of file InputParametersChecksUtils.h.

190{ 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 171 of file InputParametersChecksUtils.h.

172 {
173 _customer_class->paramError(std::forward<Args>(args)...);
174 }

◆ forwardParameters()

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

Forwards obtaining parameters to the class using this utility.

Definition at line 158 of file InputParametersChecksUtils.h.

158{ 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 188 of file InputParametersChecksUtils.h.

188{ 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 460 of file InputParametersChecksUtils.h.

462{
463 assertParamDefined<T>(param_name);
464 mooseAssert(other_param.have_parameter<T>(param_name),
465 "This should have been a parameter from the parameters being compared");
466 bool consistent = true;
467 if (forwardParameters().isParamValid(param_name) && other_param.isParamValid(param_name))
468 {
469 if constexpr (std::is_same_v<MooseEnum, T>)
470 {
471 if (!forwardGetParam<T>(param_name).compareCurrent(other_param.get<T>(param_name)))
472 consistent = false;
473 }
474 else if (forwardGetParam<T>(param_name) != other_param.get<T>(param_name))
475 consistent = false;
476 }
477 return consistent;
478}
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 549 of file InputParametersChecksUtils.h.

551{
552 const bool consistent = parameterConsistent<T>(other_param, param_name);
553 if (!consistent)
554 forwardMooseWarning("Parameter " + param_name + " is inconsistent between Physics \"" +
555 forwardName() + "\" of type \"" + forwardType() +
556 "\" and the parameter set for \"" + other_param.getObjectName() +
557 "\" of type \"" + other_param.getObjectType() + "\"");
558}
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: