From 0e32926317111745139f53f98c1ba0c69151c972 Mon Sep 17 00:00:00 2001 From: Albert Patrick Date: Tue, 1 Aug 2023 16:17:21 -0400 Subject: [PATCH] Node Argument header functor files Refs #19420 --- framework/include/base/MooseFunctor.h | 67 +++++++++++++++++++ .../include/base/MooseFunctorArguments.h | 2 + framework/include/functions/Function.h | 5 ++ framework/include/utils/ADWrapperFunctor.h | 12 ++++ .../include/utils/ArrayComponentFunctor.h | 9 +++ .../utils/PiecewiseByBlockLambdaFunctor.h | 31 +++++++++ framework/include/variables/MooseVariableFE.h | 6 ++ 7 files changed, 132 insertions(+) diff --git a/framework/include/base/MooseFunctor.h b/framework/include/base/MooseFunctor.h index cde583504505..b02e9f202be5 100644 --- a/framework/include/base/MooseFunctor.h +++ b/framework/include/base/MooseFunctor.h @@ -86,6 +86,7 @@ class FunctorBase : public FunctorAbstract ValueType operator()(const ElemQpArg & qp, const StateArg & state) const; ValueType operator()(const ElemSideQpArg & qp, const StateArg & state) const; ValueType operator()(const ElemPointArg & elem_point, const StateArg & state) const; + ValueType operator()(const NodeArg & node, const StateArg & state) const; ///@} ///@{ @@ -98,6 +99,7 @@ class FunctorBase : public FunctorAbstract GradientType gradient(const ElemQpArg & qp, const StateArg & state) const; GradientType gradient(const ElemSideQpArg & qp, const StateArg & state) const; GradientType gradient(const ElemPointArg & elem_point, const StateArg & state) const; + GradientType gradient(const NodeArg & node, const StateArg & state) const; ///@} ///@{ @@ -110,6 +112,7 @@ class FunctorBase : public FunctorAbstract DotType dot(const ElemQpArg & qp, const StateArg & state) const; DotType dot(const ElemSideQpArg & qp, const StateArg & state) const; DotType dot(const ElemPointArg & elem_point, const StateArg & state) const; + DotType dot(const NodeArg & node, const StateArg & state) const; ///@} virtual void residualSetup() override; @@ -204,6 +207,8 @@ class FunctorBase : public FunctorAbstract */ virtual ValueType evaluate(const ElemPointArg & elem_point, const StateArg & state) const = 0; + virtual ValueType evaluate(const NodeArg & node, const StateArg & state) const = 0; + /** * Evaluate the functor gradient with a given element. Some example implementations of this * method could compute an element-average or evaluate at the element centroid @@ -252,6 +257,10 @@ class FunctorBase : public FunctorAbstract mooseError("Element-point gradient not implemented for functor " + functorName()); } + virtual GradientType evaluateGradient(const NodeArg &, const StateArg &) const + { + mooseError("Element gradient not implemented for functor " + functorName()); + } /** * Evaluate the functor time derivative with a given element. Some example implementations of * this method could compute an element-average or evaluate at the element centroid @@ -300,6 +309,11 @@ class FunctorBase : public FunctorAbstract { mooseError("Element-point time derivative not implemented for functor " + functorName()); } + + virtual DotType evaluateDot(const NodeArg &, const StateArg &) const + { + mooseError("Element time derivative not implemented for functor " + functorName()); + } ///@} private: @@ -369,6 +383,10 @@ class FunctorBase : public FunctorAbstract /// Map from face arguments to their cached evaluations mutable std::map _face_arg_to_value; + /// Map from element arguments to their cached evaluations + mutable std::map _node_arg_to_value; + + /// name of the functor MooseFunctorName _functor_name; }; @@ -525,6 +543,19 @@ FunctorBase::setCacheClearanceSchedule(const std::set & clearan _clearance_schedule = clearance_schedule; } +template +typename FunctorBase::ValueType +FunctorBase::operator()(const NodeArg & node, const StateArg & state) const +{ + if (_clearance_schedule.count(EXEC_ALWAYS)) + return evaluate(node, state); + + mooseAssert(state.state == 0, + "Cached evaluations are only currently supported for the current state."); + + return queryFVArgCache(_node_arg_to_value, node); +} + template FaceArg FunctorBase::checkFace(const Moose::FaceArg & face) const @@ -593,6 +624,7 @@ FunctorBase::clearCacheData() _elem_arg_to_value.clear(); _face_arg_to_value.clear(); + _node_arg_to_value.clear(); } template @@ -662,6 +694,13 @@ FunctorBase::gradient(const ElemPointArg & elem_point, const StateArg & state return evaluateGradient(elem_point, state); } +template +typename FunctorBase::GradientType +FunctorBase::gradient(const NodeArg & node, const StateArg & state) const +{ + return evaluateGradient(node, state); +} + template typename FunctorBase::DotType FunctorBase::dot(const ElemArg & elem, const StateArg & state) const @@ -697,6 +736,13 @@ FunctorBase::dot(const ElemPointArg & elem_point, const StateArg & state) con return evaluateDot(elem_point, state); } +template +typename FunctorBase::DotType +FunctorBase::dot(const NodeArg & node, const StateArg & state) const +{ + return evaluateDot(node, state); +} + template bool FunctorBase::hasFaceSide(const FaceInfo & fi, const bool fi_elem_side) const @@ -874,6 +920,10 @@ class FunctorEnvelope final : public FunctorBase, public FunctorEnvelopeBase { return _wrapped->operator()(elem_point, state); } + virtual ValueType evaluate(const NodeArg & node, const StateArg & state) const override + { + return _wrapped->operator()(node, state); + } virtual GradientType evaluateGradient(const ElemArg & elem, const StateArg & state) const override { @@ -897,6 +947,10 @@ class FunctorEnvelope final : public FunctorBase, public FunctorEnvelopeBase { return _wrapped->gradient(elem_point, state); } + virtual GradientType evaluateGradient(const NodeArg & node, const StateArg & state) const override + { + return _wrapped->gradient(node, state); + } virtual DotType evaluateDot(const ElemArg & elem, const StateArg & state) const override { @@ -919,6 +973,10 @@ class FunctorEnvelope final : public FunctorBase, public FunctorEnvelopeBase { return _wrapped->dot(elem_point, state); } + virtual DotType evaluateDot(const NodeArg & node, const StateArg & state) const override + { + return _wrapped->dot(node, state); + } ///@} private: @@ -961,6 +1019,8 @@ class ConstantFunctor final : public FunctorBase ValueType evaluate(const ElemQpArg &, const StateArg &) const override { return _value; } ValueType evaluate(const ElemSideQpArg &, const StateArg &) const override { return _value; } ValueType evaluate(const ElemPointArg &, const StateArg &) const override { return _value; } + ValueType evaluate(const NodeArg &, const StateArg &) const override { return _value; } + GradientType evaluateGradient(const ElemArg &, const StateArg &) const override { return 0; } GradientType evaluateGradient(const FaceArg &, const StateArg &) const override { return 0; } @@ -970,12 +1030,14 @@ class ConstantFunctor final : public FunctorBase return 0; } GradientType evaluateGradient(const ElemPointArg &, const StateArg &) const override { return 0; } + GradientType evaluateGradient(const NodeArg &, const StateArg &) const override { return 0; } DotType evaluateDot(const ElemArg &, const StateArg &) const override { return 0; } DotType evaluateDot(const FaceArg &, const StateArg &) const override { return 0; } DotType evaluateDot(const ElemQpArg &, const StateArg &) const override { return 0; } DotType evaluateDot(const ElemSideQpArg &, const StateArg &) const override { return 0; } DotType evaluateDot(const ElemPointArg &, const StateArg &) const override { return 0; } + DotType evaluateDot(const NodeArg &, const StateArg &) const override { return 0; } private: ValueType _value; @@ -1026,6 +1088,11 @@ class NullFunctor final : public FunctorBase mooseError("We should never get here. If you have, contact a MOOSE developer and tell them " "they've written broken code"); } + ValueType evaluate(const NodeArg &, const StateArg &) const override + { + mooseError("We should never get here. If you have, contact a MOOSE developer and tell them " + "they've written broken code"); + } }; template diff --git a/framework/include/base/MooseFunctorArguments.h b/framework/include/base/MooseFunctorArguments.h index 90360c05f89e..ee360b8c26ac 100644 --- a/framework/include/base/MooseFunctorArguments.h +++ b/framework/include/base/MooseFunctorArguments.h @@ -200,6 +200,8 @@ struct ElemSideQpArg * equivalent); a state of 1 indicates the most-recent "old" time or the most recent previous * nonlinear iteration, etc. */ + using NodeArg = const Node*; + struct StateArg { /** diff --git a/framework/include/functions/Function.h b/framework/include/functions/Function.h index ae322e46ecb6..0ea267ba6b85 100644 --- a/framework/include/functions/Function.h +++ b/framework/include/functions/Function.h @@ -151,6 +151,7 @@ class Function : public MooseObject, using ElemSideQpArg = Moose::ElemSideQpArg; using FaceArg = Moose::FaceArg; using ElemPointArg = Moose::ElemPointArg; + using NodeArg = Moose::NodeArg; template ValueType evaluateHelper(const R & r, const Moose::StateArg & state) const; @@ -162,6 +163,7 @@ class Function : public MooseObject, const Moose::StateArg & state) const override final; ValueType evaluate(const ElemPointArg & elem_point, const Moose::StateArg & state) const override final; + ValueType evaluate(const NodeArg & node, const Moose::StateArg & state) const override final; template GradientType evaluateGradientHelper(const R & r, const Moose::StateArg & state) const; @@ -176,6 +178,8 @@ class Function : public MooseObject, const Moose::StateArg & state) const override final; GradientType evaluateGradient(const ElemPointArg & elem_point, const Moose::StateArg & state) const override final; + GradientType evaluateGradient(const NodeArg & node, + const Moose::StateArg & state) const override final; template DotType evaluateDotHelper(const R & r, const Moose::StateArg & state) const; @@ -186,6 +190,7 @@ class Function : public MooseObject, const Moose::StateArg & state) const override final; DotType evaluateDot(const ElemPointArg & elem_point, const Moose::StateArg & state) const override final; + DotType evaluateDot(const NodeArg & node, const Moose::StateArg & state) const override final; }; template diff --git a/framework/include/utils/ADWrapperFunctor.h b/framework/include/utils/ADWrapperFunctor.h index 2bde01f10368..1f4b525138eb 100644 --- a/framework/include/utils/ADWrapperFunctor.h +++ b/framework/include/utils/ADWrapperFunctor.h @@ -71,6 +71,10 @@ class ADWrapperFunctor : public FunctorBase { return _non_ad_functor(elem_point, state); } + ValueType evaluate(const NodeArg & node, const StateArg & state) const override + { + return _non_ad_functor(node, state); + } GradientType evaluateGradient(const ElemArg & elem, const StateArg & state) const override { @@ -93,6 +97,10 @@ class ADWrapperFunctor : public FunctorBase { return _non_ad_functor.gradient(elem_point, state); } + GradientType evaluateGradient(const NodeArg & node, const StateArg & state) const override + { + return _non_ad_functor.gradient(node, state); + } DotType evaluateDot(const ElemArg & elem, const StateArg & state) const override { @@ -114,6 +122,10 @@ class ADWrapperFunctor : public FunctorBase { return _non_ad_functor.dot(elem_point, state); } + DotType evaluateDot(const NodeArg & node, const StateArg & state) const override + { + return _non_ad_functor.dot(node, state); + } ///@} private: diff --git a/framework/include/utils/ArrayComponentFunctor.h b/framework/include/utils/ArrayComponentFunctor.h index 3bee498ba118..14a48f34ac23 100644 --- a/framework/include/utils/ArrayComponentFunctor.h +++ b/framework/include/utils/ArrayComponentFunctor.h @@ -70,11 +70,20 @@ class ArrayComponentFunctor : public FunctorBase return _array(elem_point, state)[_component]; } + ValueType evaluate(const NodeArg & node, const StateArg & state) const override final + { + return _array(node, state)[_component]; + } + using FunctorBase::evaluateGradient; GradientType evaluateGradient(const ElemArg & elem, const StateArg & state) const override final { return _array.gradient(elem, state)[_component]; } + GradientType evaluateGradient(const NodeArg & node, const StateArg & state) const override final + { + return _array.gradient(node, state)[_component]; + } }; template diff --git a/framework/include/utils/PiecewiseByBlockLambdaFunctor.h b/framework/include/utils/PiecewiseByBlockLambdaFunctor.h index 0796926d6c92..69d7eb371f84 100644 --- a/framework/include/utils/PiecewiseByBlockLambdaFunctor.h +++ b/framework/include/utils/PiecewiseByBlockLambdaFunctor.h @@ -70,6 +70,7 @@ class PiecewiseByBlockLambdaFunctor : public Moose::FunctorBase using ElemQpFn = std::function; using ElemSideQpFn = std::function; using ElemPointFn = std::function; + using NodeFn = std::function; ValueType evaluate(const Moose::ElemArg & elem_arg, const Moose::StateArg & time) const override; ValueType evaluate(const Moose::FaceArg & face, const Moose::StateArg & time) const override; @@ -78,12 +79,15 @@ class PiecewiseByBlockLambdaFunctor : public Moose::FunctorBase const Moose::StateArg & time) const override; ValueType evaluate(const Moose::ElemPointArg & elem_point, const Moose::StateArg & time) const override; + ValueType evaluate(const Moose::NodeArg & node_arg, const Moose::StateArg & time) const override; using Moose::FunctorBase::evaluateGradient; GradientType evaluateGradient(const Moose::ElemArg & elem_arg, const Moose::StateArg &) const override; GradientType evaluateGradient(const Moose::FaceArg & face_arg, const Moose::StateArg &) const override; + GradientType evaluateGradient(const Moose::NodeArg & node_arg, + const Moose::StateArg &) const override; private: /** @@ -109,6 +113,10 @@ class PiecewiseByBlockLambdaFunctor : public Moose::FunctorBase /// Functors that return evaluations at an arbitrary physical point in an element std::unordered_map _elem_point_functor; + /// Functors that return element average values (or cell centroid values or whatever the + /// implementer wants to return for a given element argument) + std::unordered_map _node_functor; + /// The mesh that this functor operates on const MooseMesh & _mesh; }; @@ -288,6 +296,21 @@ PiecewiseByBlockLambdaFunctor::evaluate(const Moose::ElemPointArg & elem_poin return it->second(elem_point_arg, time); } +template +typename PiecewiseByBlockLambdaFunctor::ValueType +PiecewiseByBlockLambdaFunctor::evaluate(const Moose::NodeArg & node_arg, + const Moose::StateArg & time) const +{ + const Node * const node = node_arg.node; + mooseAssert(node && node != libMesh::remote_node, + "The element must be non-null and non-remote in functor material properties"); + auto it = _node_functor.find(node->subdomain_id()); + if (it == _node_functor.end()) + subdomainErrorMessage(node->subdomain_id()); + + return it->second(node_arg, time); +} + template typename PiecewiseByBlockLambdaFunctor::GradientType PiecewiseByBlockLambdaFunctor::evaluateGradient(const Moose::ElemArg & elem_arg, @@ -303,3 +326,11 @@ PiecewiseByBlockLambdaFunctor::evaluateGradient(const Moose::FaceArg & face_a { return Moose::FV::greenGaussGradient(face_arg, time, *this, true, _mesh); } + +template +typename PiecewiseByBlockLambdaFunctor::GradientType +PiecewiseByBlockLambdaFunctor::evaluateGradient(const Moose::NodeArg & node_arg, + const Moose::StateArg & time) const +{ + return Moose::FV::greenGaussGradient(node_arg, time, *this, true, _mesh); +} \ No newline at end of file diff --git a/framework/include/variables/MooseVariableFE.h b/framework/include/variables/MooseVariableFE.h index c2e0e3e36b07..a206879b36e6 100644 --- a/framework/include/variables/MooseVariableFE.h +++ b/framework/include/variables/MooseVariableFE.h @@ -689,6 +689,8 @@ class MooseVariableFE : public MooseVariableField using ElemSideQpArg = Moose::ElemSideQpArg; using FaceArg = Moose::FaceArg; using StateArg = Moose::StateArg; + using NodeArg = Moose::NodeArg; + ValueType evaluate(const ElemArg &, const StateArg &) const override final { @@ -698,6 +700,10 @@ class MooseVariableFE : public MooseVariableField { mooseError("Face info functor overload not yet implemented for finite element variables"); } + ValueType evaluate(const NodeArg &, const StateArg &) const override final + { + mooseError("Node functor overload not yet implemented for finite element variables"); + } }; template