Skip to content

Commit

Permalink
Merge pull request idaholab#29572 from GiudGiud/PR_real_functors
Browse files Browse the repository at this point in the history
Allow retrieving non-AD variables as non-AD functors
  • Loading branch information
GiudGiud authored Dec 19, 2024
2 parents dc0e9c8 + 6f87087 commit d939715
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion framework/include/problems/SubProblem.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ class SubProblem : public Problem
/// Whether or not this problem has the variable
virtual bool hasVariable(const std::string & var_name) const = 0;

/// Whether or not this problem has this linear variable
virtual bool hasLinearVariable(const std::string & var_name) const;

/// Whether or not this problem has this auxiliary variable
virtual bool hasAuxiliaryVariable(const std::string & var_name) const;

/**
* Returns the variable reference for requested variable which must
* be of the expected_var_type (Nonlinear vs. Auxiliary) and
Expand Down Expand Up @@ -1252,8 +1258,10 @@ SubProblem::getFunctor(const std::string & name,
mooseError("We already have the functor; it should not be unset");

// Check for whether this is a valid request
// We allow auxiliary variables and linear variables to be retrieved as non AD
if (!requested_functor_is_ad && requestor_is_ad &&
true_functor_is == SubProblem::TrueFunctorIs::AD)
true_functor_is == SubProblem::TrueFunctorIs::AD &&
!(hasAuxiliaryVariable(name) || hasLinearVariable(name)))
mooseError("The AD object '",
requestor_name,
"' is requesting the functor '",
Expand Down
15 changes: 15 additions & 0 deletions framework/src/problems/SubProblem.C
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,21 @@ SubProblem::getAxisymmetricRadialCoord() const
return mesh().getAxisymmetricRadialCoord();
}

bool
SubProblem::hasLinearVariable(const std::string & var_name) const
{
for (const auto i : make_range(numLinearSystems()))
if (systemBaseLinear(i).hasVariable(var_name))
return true;
return false;
}

bool
SubProblem::hasAuxiliaryVariable(const std::string & var_name) const
{
return systemBaseAuxiliary().hasVariable(var_name);
}

template <typename T>
MooseVariableFEBase &
SubProblem::getVariableHelper(const THREAD_ID tid,
Expand Down

0 comments on commit d939715

Please sign in to comment.