LCOV - code coverage report
Current view: top level - include/utils - InputParametersChecksUtils.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 57 81 70.4 %
Date: 2025-07-17 01:28:37 Functions: 42 52 80.8 %
Legend: Lines: hit not hit

          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             : #include "InputParameters.h"
      13             : #include "Moose.h"
      14             : 
      15             : // C++ includes
      16             : #include <cstdlib>
      17             : #include <tuple>
      18             : #include <type_traits>
      19             : 
      20             : /**
      21             :  * Utility class to help check parameters.
      22             :  * This will be replaced by every check being baked into the validParams() logic, one day
      23             :  * @tparam C type of the class using this utility
      24             :  * C must be derived from both MooseBaseParameterInterface and MooseBaseErrorInterface
      25             :  */
      26             : template <typename C>
      27             : class InputParametersChecksUtils
      28             : {
      29             : public:
      30         682 :   InputParametersChecksUtils(const C * customer_class) : _customer_class(customer_class) {}
      31             : 
      32             : protected:
      33             :   /// Check in debug mode that this parameter has been added to the validParams
      34             :   /// @param param parameter that should be defined
      35             :   template <typename T>
      36             :   void assertParamDefined(const std::string & param) const;
      37             :   /// Check that two parameters are either both set or both not set
      38             :   /// @param param1 first parameter to check
      39             :   /// @param param2 second parameter to check
      40             :   void checkParamsBothSetOrNotSet(const std::string & param1, const std::string & param2) const;
      41             :   /// Check that a parameter is set only if the first one is set to true
      42             :   /// @param param1 first parameter to check, check the second if true
      43             :   /// @param param2 second parameter to check, that should be set if first one is true
      44             :   void checkSecondParamSetOnlyIfFirstOneTrue(const std::string & param1,
      45             :                                              const std::string & param2) const;
      46             :   /// Check that a parameter is set only if the first one is set
      47             :   /// @param param1 first parameter to check, check the second if set
      48             :   /// @param param2 second parameter to check, that should be set if first one is set
      49             :   void checkSecondParamSetOnlyIfFirstOneSet(const std::string & param1,
      50             :                                             const std::string & param2) const;
      51             :   /// Check that a parameter is not set if the first one is set
      52             :   /// @param param1 first parameter to check, check that the second is not if this one is set
      53             :   /// @param param2 second parameter to check, that should not be set if first one is set
      54             :   void checkSecondParamNotSetIfFirstOneSet(const std::string & param1,
      55             :                                            const std::string & param2) const;
      56             :   /// Check that the two vector parameters are of the same length
      57             :   /// @param param1 first vector parameter to compare the size of
      58             :   /// @param param2 second vector parameter to compare the size of
      59             :   template <typename T, typename S>
      60             :   void checkVectorParamsSameLength(const std::string & param1, const std::string & param2) const;
      61             :   /// Check that this vector parameter (with name defined in \p param1) has the same length as the MultiMooseEnum (with name defined in \p param2)
      62             :   /// @param param1 vector parameter to compare the size of
      63             :   /// @param param2 multiMooseEnum parameter to compare the size of
      64             :   template <typename T>
      65             :   void checkVectorParamAndMultiMooseEnumLength(const std::string & param1,
      66             :                                                const std::string & param2) const;
      67             :   /// Check that the two-D vectors have exactly the same length in both dimensions
      68             :   /// @param param1 first two-D vector parameter to check the dimensions of
      69             :   /// @param param2 second two-D vector parameter to check the dimensions of
      70             :   template <typename T, typename S>
      71             :   void checkTwoDVectorParamsSameLength(const std::string & param1,
      72             :                                        const std::string & param2) const;
      73             :   /// Check that there is no overlap between the items in each vector parameters
      74             :   /// Each vector parameter should also have unique items
      75             :   /// @param param_vecs vector of parameters that should not overlap with each other
      76             :   template <typename T>
      77             :   void checkVectorParamsNoOverlap(const std::vector<std::string> & param_vecs) const;
      78             :   /// Check that there is no overlap between the respective items in each vector of the two-D parameters
      79             :   /// Each vector of the two-D vector parameter should also have unique items
      80             :   /// @param param_vecs vector of parameters that should not overlap with each other
      81             :   template <typename T>
      82             :   void checkTwoDVectorParamsNoRespectiveOverlap(const std::vector<std::string> & param_vecs) const;
      83             :   /// Check that each inner vector of a two-D vector parameter are the same size as another one-D vector parameter
      84             :   /// @param param1 two-D vector parameter to check the dimensions of
      85             :   /// @param param2 one-D vector parameter to set the desired size
      86             :   template <typename T, typename S>
      87             :   void checkTwoDVectorParamInnerSameLengthAsOneDVector(const std::string & param1,
      88             :                                                        const std::string & param2) const;
      89             :   /// Check that the size of a two-D vector parameter matches the size of a MultiMooseEnum parameter
      90             :   /// @param param1 two-D vector parameter to check the unrolled size of
      91             :   /// @param param2 MultiMooseEnum parameter to set the desired size
      92             :   template <typename T>
      93             :   void checkTwoDVectorParamMultiMooseEnumSameLength(const std::string & param1,
      94             :                                                     const std::string & param2,
      95             :                                                     const bool error_for_param2) const;
      96             :   /// Check that the user did not pass an empty vector
      97             :   /// @param param1 vector parameter that should not be empty
      98             :   template <typename T>
      99             :   void checkVectorParamNotEmpty(const std::string & param1) const;
     100             :   /// Check that two vector parameters are the same length if both are set
     101             :   /// @param param1 first vector parameter to check the size of
     102             :   /// @param param2 second vector parameter to check the size of
     103             :   template <typename T, typename S>
     104             :   void checkVectorParamsSameLengthIfSet(const std::string & param1,
     105             :                                         const std::string & param2,
     106             :                                         const bool ignore_empty_default_param2 = false) const;
     107             :   /// Check that a vector parameter is the same length as two others combined
     108             :   /// @param param1 vector parameter that provides the target size
     109             :   /// @param param2 vector parameter that provides one term in the combined size
     110             :   /// @param param3 vector parameter that provides one term in the combined size
     111             :   template <typename T, typename S, typename U>
     112             :   void checkVectorParamLengthSameAsCombinedOthers(const std::string & param1,
     113             :                                                   const std::string & param2,
     114             :                                                   const std::string & param3) const;
     115             : 
     116             :   /// Check if the user commited errors during the definition of block-wise parameters
     117             :   /// @param block_param_name the name of the parameter that provides the groups of blocks
     118             :   /// @param parameter_names vector of the names of the parameters that are defined on a per-block basis
     119             :   template <typename T>
     120             :   void checkBlockwiseConsistency(const std::string & block_param_name,
     121             :                                  const std::vector<std::string> & parameter_names) const;
     122             :   /// Return whether two parameters are consistent
     123             :   /// @param other_param InputParameters object from another object to check the 'param_name' parameter in
     124             :   /// @param param_name the name of the parameter to check for consistency
     125             :   template <typename T>
     126             :   bool parameterConsistent(const InputParameters & other_param,
     127             :                            const std::string & param_name) const;
     128             :   /// Emits a warning if two parameters are not equal to each other
     129             :   /// @param other_param InputParameters object from another object to check the 'param_name' parameter in
     130             :   /// @param param_name the name of the parameter to check for consistency
     131             :   template <typename T>
     132             :   void warnInconsistent(const InputParameters & parameters, const std::string & param_name) const;
     133             :   /// Error messages for parameters that should depend on another parameter
     134             :   /// @param param1 the parameter has not been set to the desired value (for logging purposes)
     135             :   /// @param value_not_set the desired value (for logging purposes)
     136             :   /// @param dependent_params all the parameters that should not have been since 'param1' was not set to 'value_not_set'
     137             :   void errorDependentParameter(const std::string & param1,
     138             :                                const std::string & value_not_set,
     139             :                                const std::vector<std::string> & dependent_params) const;
     140             :   /// Error messages for parameters that should depend on another parameter but with a different error message
     141             :   /// @param param1 the parameter has not been set to the desired value (for logging purposes)
     142             :   /// @param value_set the value it has been set to and which is not appropriate (for logging purposes)
     143             :   /// @param dependent_params all the parameters that should not have been set since 'param1' was set to 'value_set'
     144             :   void errorInconsistentDependentParameter(const std::string & param1,
     145             :                                            const std::string & value_set,
     146             :                                            const std::vector<std::string> & dependent_params) const;
     147             : 
     148             : private:
     149             :   // Convenience routines so that defining new checks feels very similar to coding checks in
     150             :   // MooseObjects and Actions (MooseParameterInterface-derived classes)
     151             :   /// Forwards parameter check to the class using this utility
     152             :   template <typename T>
     153        8704 :   T forwardGetParam(const std::string & param_name) const
     154             :   {
     155        8704 :     return _customer_class->template getParam<T>(param_name);
     156             :   }
     157             :   /// Forwards obtaining parameters to the class using this utility
     158             :   const InputParameters & forwardParameters() const { return _customer_class->parameters(); }
     159             :   /// Forwards parameter check to the class using this utility
     160         700 :   bool forwardIsParamSetByUser(const std::string & param_name) const
     161             :   {
     162         700 :     return _customer_class->isParamSetByUser(param_name);
     163             :   }
     164             :   /// Forwards parameter check to the class using this utility
     165        7710 :   bool forwardIsParamValid(const std::string & param_name) const
     166             :   {
     167        7710 :     return _customer_class->isParamValid(param_name);
     168             :   }
     169             :   /// Forwards error to the class using this utility to get better error messages
     170             :   template <typename... Args>
     171          32 :   void forwardParamError(Args &&... args) const
     172             :   {
     173          32 :     _customer_class->paramError(std::forward<Args>(args)...);
     174             :   }
     175             :   /// Forwards error to the class using this utility to get better error messages
     176             :   template <typename... Args>
     177           0 :   void forwardMooseError(Args &&... args) const
     178             :   {
     179           0 :     _customer_class->mooseError(std::forward<Args>(args)...);
     180             :   }
     181             :   /// Forwards warning to the class using this utility to get better error messages
     182             :   template <typename... Args>
     183             :   void forwardMooseWarning(Args &&... args) const
     184             :   {
     185             :     _customer_class->mooseWarning(std::forward<Args>(args)...);
     186             :   }
     187             :   /// Get the type of the class using this utility
     188             :   const std::string & forwardType() const { return _customer_class->type(); }
     189             :   /// Get the name of the class using this utility
     190           0 :   virtual const std::string & forwardName() const { return _customer_class->name(); }
     191             :   /// Get the blocks for the class using this utility
     192             :   const std::vector<SubdomainName> & forwardBlocks() const
     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             :   }
     198             : 
     199             :   // A pointer to the class using this
     200             :   const C * const _customer_class;
     201             : };
     202             : 
     203             : template <typename C>
     204             : template <typename T>
     205             : void
     206        7476 : InputParametersChecksUtils<C>::assertParamDefined(const std::string & libmesh_dbg_var(param)) const
     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        7476 : }
     213             : 
     214             : template <typename C>
     215             : template <typename T, typename S>
     216             : void
     217        2366 : InputParametersChecksUtils<C>::checkVectorParamsSameLength(const std::string & param1,
     218             :                                                            const std::string & param2) const
     219             : {
     220        2366 :   assertParamDefined<std::vector<T>>(param1);
     221        2366 :   assertParamDefined<std::vector<S>>(param2);
     222             : 
     223        2366 :   if (forwardIsParamValid(param1) && forwardIsParamValid(param2))
     224             :   {
     225        2366 :     const auto size_1 = forwardGetParam<std::vector<T>>(param1).size();
     226        2366 :     const auto size_2 = forwardGetParam<std::vector<S>>(param2).size();
     227        2366 :     if (size_1 != size_2)
     228          16 :       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           0 :   else if (forwardIsParamValid(param1) || forwardIsParamValid(param2))
     235           0 :     if (forwardGetParam<std::vector<T>>(param1).size() ||
     236           0 :         forwardGetParam<std::vector<T>>(param2).size())
     237           0 :       checkParamsBothSetOrNotSet(param1, param2);
     238        2350 : }
     239             : 
     240             : template <typename C>
     241             : template <typename T>
     242             : void
     243         848 : InputParametersChecksUtils<C>::checkVectorParamAndMultiMooseEnumLength(
     244             :     const std::string & param1, const std::string & param2) const
     245             : {
     246         848 :   assertParamDefined<std::vector<T>>(param1);
     247         848 :   assertParamDefined<MultiMooseEnum>(param2);
     248             : 
     249         848 :   if (forwardIsParamValid(param1) && forwardIsParamValid(param2))
     250             :   {
     251         494 :     const auto size_1 = forwardGetParam<std::vector<T>>(param1).size();
     252         494 :     const auto size_2 = forwardGetParam<MultiMooseEnum>(param2).size();
     253         494 :     if (size_1 != size_2)
     254          16 :       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         354 :   else if (forwardIsParamValid(param1) || forwardIsParamValid(param2))
     261        1062 :     if (forwardGetParam<std::vector<T>>(param1).size() ||
     262         708 :         forwardGetParam<MultiMooseEnum>(param2).size())
     263           0 :       checkParamsBothSetOrNotSet(param1, param2);
     264         832 : }
     265             : 
     266             : template <typename C>
     267             : template <typename T, typename S>
     268             : void
     269         336 : InputParametersChecksUtils<C>::checkTwoDVectorParamsSameLength(const std::string & param1,
     270             :                                                                const std::string & param2) const
     271             : {
     272         336 :   checkVectorParamsSameLength<std::vector<T>, std::vector<S>>(param1, param2);
     273         336 :   if (forwardIsParamValid(param1) && forwardIsParamValid(param2))
     274             :   {
     275         336 :     const auto value1 = forwardGetParam<std::vector<std::vector<T>>>(param1);
     276         336 :     const auto value2 = forwardGetParam<std::vector<std::vector<S>>>(param2);
     277         416 :     for (const auto index : index_range(value1))
     278          80 :       if (value1[index].size() != value2[index].size())
     279           0 :         forwardParamError(
     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           0 :                 "'.\nSize first vector: " + std::to_string(value1[index].size()) +
     284           0 :                 "\nSize second vector: " + std::to_string(value2[index].size()));
     285         336 :   }
     286             :   // handle empty vector defaults
     287           0 :   else if (forwardIsParamValid(param1) || forwardIsParamValid(param2))
     288           0 :     if (forwardGetParam<std::vector<T>>(param1).size() ||
     289           0 :         forwardGetParam<std::vector<T>>(param2).size())
     290           0 :       checkParamsBothSetOrNotSet(param1, param2);
     291         336 : }
     292             : 
     293             : template <typename C>
     294             : template <typename T, typename S>
     295             : void
     296             : InputParametersChecksUtils<C>::checkTwoDVectorParamInnerSameLengthAsOneDVector(
     297             :     const std::string & param1, const std::string & param2) const
     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             : }
     314             : 
     315             : template <typename C>
     316             : template <typename T>
     317             : void
     318             : InputParametersChecksUtils<C>::checkTwoDVectorParamMultiMooseEnumSameLength(
     319             :     const std::string & param1, const std::string & param2, const bool error_for_param2) const
     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             : }
     342             : 
     343             : template <typename C>
     344             : template <typename T, typename S, typename U>
     345             : void
     346             : InputParametersChecksUtils<C>::checkVectorParamLengthSameAsCombinedOthers(
     347             :     const std::string & param1, const std::string & param2, const std::string & param3) const
     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             : }
     362             : 
     363             : template <typename C>
     364             : template <typename T>
     365             : void
     366         778 : InputParametersChecksUtils<C>::checkVectorParamsNoOverlap(
     367             :     const std::vector<std::string> & param_vec) const
     368             : {
     369         778 :   std::set<std::string> unique_params;
     370        1826 :   for (const auto & param : param_vec)
     371             :   {
     372        1048 :     assertParamDefined<std::vector<T>>(param);
     373             : 
     374        2360 :     for (const auto & value : forwardGetParam<std::vector<T>>(param))
     375        1312 :       if (!unique_params.insert(value).second)
     376             :       {
     377           0 :         auto copy_params = param_vec;
     378           0 :         copy_params.erase(std::find(copy_params.begin(), copy_params.end(), param));
     379             :         // Overlap between multiple vectors of parameters
     380           0 :         if (copy_params.size())
     381           0 :           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           0 :           forwardMooseError("Item '" + value + "' specified in vector parameter '" + param +
     387             :                             "' is repeated, which is not allowed.");
     388           0 :       }
     389             :   }
     390         778 : }
     391             : 
     392             : template <typename C>
     393             : template <typename T>
     394             : void
     395             : InputParametersChecksUtils<C>::checkTwoDVectorParamsNoRespectiveOverlap(
     396             :     const std::vector<std::string> & param_vec) const
     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             : }
     421             : 
     422             : template <typename C>
     423             : template <typename T>
     424             : void
     425             : InputParametersChecksUtils<C>::checkVectorParamNotEmpty(const std::string & param) const
     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             : }
     431             : 
     432             : template <typename C>
     433             : template <typename T, typename S>
     434             : void
     435             : InputParametersChecksUtils<C>::checkVectorParamsSameLengthIfSet(
     436             :     const std::string & param1,
     437             :     const std::string & param2,
     438             :     const bool ignore_empty_default_param2) const
     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             : }
     456             : 
     457             : template <typename C>
     458             : template <typename T>
     459             : bool
     460             : InputParametersChecksUtils<C>::parameterConsistent(const InputParameters & other_param,
     461             :                                                    const std::string & param_name) const
     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             : }
     479             : 
     480             : template <typename C>
     481             : template <typename T>
     482             : void
     483             : InputParametersChecksUtils<C>::checkBlockwiseConsistency(
     484             :     const std::string & block_param_name, const std::vector<std::string> & parameter_names) const
     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             : }
     545             : 
     546             : template <typename C>
     547             : template <typename T>
     548             : void
     549             : InputParametersChecksUtils<C>::warnInconsistent(const InputParameters & other_param,
     550             :                                                 const std::string & param_name) const
     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 \"" +
     557             :                         other_param.get<std::string>("_action_name") + "\" of type \"" +
     558             :                         other_param.get<std::string>("action_type") + "\"");
     559             : }
     560             : 
     561             : template <typename C>
     562             : void
     563             : InputParametersChecksUtils<C>::errorDependentParameter(
     564             :     const std::string & param1,
     565             :     const std::string & value_not_set,
     566             :     const std::vector<std::string> & dependent_params) const
     567             : {
     568             :   for (const auto & dependent_param : dependent_params)
     569             :     if (forwardIsParamSetByUser(dependent_param))
     570             :       forwardParamError(dependent_param,
     571             :                         "Parameter '" + dependent_param +
     572             :                             "' should not be set by the user if parameter '" + param1 +
     573             :                             "' has not been set to '" + value_not_set + "'");
     574             : }
     575             : 
     576             : template <typename C>
     577             : void
     578             : InputParametersChecksUtils<C>::errorInconsistentDependentParameter(
     579             :     const std::string & param1,
     580             :     const std::string & value_set,
     581             :     const std::vector<std::string> & dependent_params) const
     582             : {
     583             :   for (const auto & dependent_param : dependent_params)
     584             :     if (forwardIsParamSetByUser(dependent_param))
     585             :       forwardParamError(dependent_param,
     586             :                         "Parameter '" + dependent_param +
     587             :                             "' should not be set by the user if parameter '" + param1 +
     588             :                             "' has been set to '" + value_set + "'");
     589             : }
     590             : 
     591             : template <typename C>
     592             : void
     593         128 : InputParametersChecksUtils<C>::checkParamsBothSetOrNotSet(const std::string & param1,
     594             :                                                           const std::string & param2) const
     595             : {
     596         128 :   if ((forwardIsParamValid(param1) + forwardIsParamValid(param2)) % 2 != 0)
     597           0 :     forwardParamError(param1,
     598             :                       "Parameters '" + param1 + "' and '" + param2 +
     599             :                           "' must be either both set or both not set.");
     600         128 : }
     601             : 
     602             : template <typename C>
     603             : void
     604         556 : InputParametersChecksUtils<C>::checkSecondParamSetOnlyIfFirstOneTrue(
     605             :     const std::string & param1, const std::string & param2) const
     606             : {
     607             :   mooseAssert(forwardParameters().template have_parameter<bool>(param1),
     608             :               "Cannot check if parameter " + param1 +
     609             :                   " is true if it's not a bool parameter of this object");
     610         556 :   if (!forwardGetParam<bool>(param1) && forwardIsParamSetByUser(param2))
     611           0 :     forwardParamError(param2,
     612             :                       "Parameter '" + param1 + "' cannot be set to false if parameter '" + param2 +
     613             :                           "' is set by the user");
     614         556 : }
     615             : 
     616             : template <typename C>
     617             : void
     618             : InputParametersChecksUtils<C>::checkSecondParamSetOnlyIfFirstOneSet(
     619             :     const std::string & param1, const std::string & param2) const
     620             : {
     621             :   if (!forwardIsParamSetByUser(param1) && forwardIsParamSetByUser(param2))
     622             :     forwardParamError(param2,
     623             :                       "Parameter '" + param2 + "' should not be set if parameter '" + param1 +
     624             :                           "' is not specified.");
     625             : }
     626             : 
     627             : template <typename C>
     628             : void
     629         144 : InputParametersChecksUtils<C>::checkSecondParamNotSetIfFirstOneSet(const std::string & param1,
     630             :                                                                    const std::string & param2) const
     631             : {
     632         144 :   if (forwardIsParamSetByUser(param1) && forwardIsParamSetByUser(param2))
     633           0 :     forwardParamError(param2,
     634             :                       "Parameter '" + param2 + "' should not be specified if parameter '" + param1 +
     635             :                           "' is specified.");
     636         144 : }

Generated by: LCOV version 1.14