diff --git a/framework/include/base/MooseObject.h b/framework/include/base/MooseObject.h index 5f9456daf637..442fa9c7a5b0 100644 --- a/framework/include/base/MooseObject.h +++ b/framework/include/base/MooseObject.h @@ -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 - [[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()) @@ -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 - 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()) @@ -135,7 +135,7 @@ class MooseObject : public ConsoleStreamInterface, public libMesh::ParallelObjec * the given args. */ template - 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()) diff --git a/framework/include/transfers/MultiAppTransfer.h b/framework/include/transfers/MultiAppTransfer.h index 336469154def..9d7751ce2bb5 100644 --- a/framework/include/transfers/MultiAppTransfer.h +++ b/framework/include/transfers/MultiAppTransfer.h @@ -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; }; diff --git a/framework/src/transfers/MultiAppCopyTransfer.C b/framework/src/transfers/MultiAppCopyTransfer.C index e047db489efc..c414ee75f311 100644 --- a/framework/src/transfers/MultiAppCopyTransfer.C +++ b/framework/src/transfers/MultiAppCopyTransfer.C @@ -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( diff --git a/framework/src/transfers/MultiAppTransfer.C b/framework/src/transfers/MultiAppTransfer.C index 35e3ad4a6090..160ddfe0af9b 100644 --- a/framework/src/transfers/MultiAppTransfer.C +++ b/framework/src/transfers/MultiAppTransfer.C @@ -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."); + } +}