Skip to content

Commit

Permalink
Merge pull request idaholab#18462 from parikshitbajpai/vector-pairs-u…
Browse files Browse the repository at this point in the history
…tility

Add utility function to create vector of pairs from two input parameters
  • Loading branch information
dschwen committed Aug 4, 2021
2 parents c29026b + a7dd4e6 commit f2340a0
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions framework/include/base/MooseObject.h
Expand Up @@ -87,6 +87,16 @@ class MooseObject : public ConsoleStreamInterface, public libMesh::ParallelObjec
template <typename T>
const T & getParam(const std::string & name) const;

/**
* Retrieve two parameters and provide pair of parameters for the object
* @param param1 The name of first parameter
* @param param2 The name of second parameter
* @return Vector of pairs of first and second parameters
*/
template <typename T1, typename T2>
std::vector<std::pair<T1, T2>> getParamPairs(const std::string & param1,
const std::string & param2) const;

/**
* Verifies that the requested parameter exists and is not NULL and returns it to the caller.
* The template parameter must be a pointer or an error will be thrown.
Expand Down Expand Up @@ -255,6 +265,25 @@ MooseObject::getParam(const std::string & name) const
return InputParameters::getParamHelper(name, _pars, static_cast<T *>(0));
}

template <typename T1, typename T2>
std::vector<std::pair<T1, T2>>
MooseObject::getParamPairs(const std::string & param1, const std::string & param2) const
{
auto v1 = getParam<std::vector<T1>>(param1);
auto v2 = getParam<std::vector<T2>>(param2);

if (v1.size() != v2.size())
callMooseErrorRaw("Vector parameters " + paramErrorPrefix(_pars, param1) +
"(size: " + v1.size() + ") and " + paramErrorPrefix(_pars, param2) +
"(size: " + v2.size() + ") are of different lengths \n",
&_app);

std::vector<std::pair<T1, T2>> parameter_pair;
for (std::size_t i = 0; i < v1.size(); ++i)
parameter_pair.emplace_back(std::make_pair(v1[i], v2[i]));
return parameter_pair;
}

template <typename... Args>
[[noreturn]] void
MooseObject::paramError(const std::string & param, Args... args) const
Expand Down

0 comments on commit f2340a0

Please sign in to comment.