Skip to content

Commit

Permalink
Create a helper function for performing proper variable error checks …
Browse files Browse the repository at this point in the history
…in MultiAppTransfer

(refs idaholab#13754)
  • Loading branch information
aeslaughter committed Jul 18, 2019
1 parent 17c1c8b commit 3891cf8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
6 changes: 3 additions & 3 deletions framework/include/base/MooseObject.h
Expand Up @@ -104,7 +104,7 @@ class MooseObject : public ConsoleStreamInterface, public libMesh::ParallelObjec
* back to the normal behavior of mooseError - only printing a message using the given args.
*/
template <typename... Args>
[[noreturn]] void paramError(const std::string & param, Args... args)
[[noreturn]] void paramError(const std::string & param, Args... args) const
{
auto prefix = param + ": ";
if (!_pars.inputLocation(param).empty())
Expand All @@ -119,7 +119,7 @@ class MooseObject : public ConsoleStreamInterface, public libMesh::ParallelObjec
* back to the normal behavior of mooseWarning - only printing a message using the given args.
*/
template <typename... Args>
void paramWarning(const std::string & param, Args... args)
void paramWarning(const std::string & param, Args... args) const
{
auto prefix = param + ": ";
if (!_pars.inputLocation(param).empty())
Expand All @@ -135,7 +135,7 @@ class MooseObject : public ConsoleStreamInterface, public libMesh::ParallelObjec
* the given args.
*/
template <typename... Args>
void paramInfo(const std::string & param, Args... args)
void paramInfo(const std::string & param, Args... args) const
{
auto prefix = param + ": ";
if (!_pars.inputLocation(param).empty())
Expand Down
12 changes: 12 additions & 0 deletions framework/include/transfers/MultiAppTransfer.h
Expand Up @@ -119,4 +119,16 @@ class MultiAppTransfer : public Transfer
* see StochasticToolsTransfer for an example.
*/
void checkMultiAppExecuteOn();

/**
* Helper for checking a problem for a variable.
*
* @param fe_problem The problem that should contain the variable
* @parem var_name The name of the variable that should exist within the problem
* @param param_name (optional) The input file parameter name for throwing paramError, if not
* provided a mooseError is thrown.
*/
void checkVariable(const FEProblemBase & fe_problem,
const VariableName & var_name,
const std::string & param_name = "") const;
};
7 changes: 2 additions & 5 deletions framework/src/transfers/MultiAppCopyTransfer.C
Expand Up @@ -66,11 +66,8 @@ void
MultiAppCopyTransfer::transfer(FEProblemBase & to_problem, FEProblemBase & from_problem)
{
// Perform error checking
if (!to_problem.hasVariable(_to_var_name))
paramError("variable", "The variable '", _to_var_name, "' does not exist.");

if (!from_problem.hasVariable(_from_var_name))
paramError("source_variable", "The variable '", _from_var_name, "' does not exist.");
checkVariable(to_problem, _to_var_name, "variable");
checkVariable(from_problem, _from_var_name, "source_variable");

// Populate the to/from variables needed to perform the transfer
MooseVariableFEBase & to_var = to_problem.getVariable(
Expand Down
14 changes: 14 additions & 0 deletions framework/src/transfers/MultiAppTransfer.C
Expand Up @@ -264,3 +264,17 @@ MultiAppTransfer::getTransferVector(unsigned int i_local, std::string var_name)

return _multi_app->appTransferVector(_local2global_map[i_local], var_name);
}

void
MultiAppTransfer::checkVariable(const FEProblemBase & fe_problem,
const VariableName & var_name,
const std::string & param_name) const
{
if (!fe_problem.hasVariable(var_name))
{
if (param_name.empty())
mooseError("The variable '", var_name, "' does not exist.");
else
paramError(param_name, "The variable '", var_name, "' does not exist.");
}
}

0 comments on commit 3891cf8

Please sign in to comment.