Skip to content

Commit

Permalink
Node Argument header functor files
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertJP7 authored and lindsayad committed Oct 4, 2023
1 parent e8c7f09 commit 9f21155
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 0 deletions.
67 changes: 67 additions & 0 deletions framework/include/base/MooseFunctor.h
Expand Up @@ -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;
///@}

///@{
Expand All @@ -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;
///@}

///@{
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -369,6 +383,10 @@ class FunctorBase : public FunctorAbstract
/// Map from face arguments to their cached evaluations
mutable std::map<FaceArg, ValueType> _face_arg_to_value;

/// Map from element arguments to their cached evaluations
mutable std::map<NodeArg, ValueType> _node_arg_to_value;


/// name of the functor
MooseFunctorName _functor_name;
};
Expand Down Expand Up @@ -525,6 +543,19 @@ FunctorBase<T>::setCacheClearanceSchedule(const std::set<ExecFlagType> & clearan
_clearance_schedule = clearance_schedule;
}

template <typename T>
typename FunctorBase<T>::ValueType
FunctorBase<T>::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 <typename T>
FaceArg
FunctorBase<T>::checkFace(const Moose::FaceArg & face) const
Expand Down Expand Up @@ -593,6 +624,7 @@ FunctorBase<T>::clearCacheData()

_elem_arg_to_value.clear();
_face_arg_to_value.clear();
_node_arg_to_value.clear();
}

template <typename T>
Expand Down Expand Up @@ -662,6 +694,13 @@ FunctorBase<T>::gradient(const ElemPointArg & elem_point, const StateArg & state
return evaluateGradient(elem_point, state);
}

template <typename T>
typename FunctorBase<T>::GradientType
FunctorBase<T>::gradient(const NodeArg & node, const StateArg & state) const
{
return evaluateGradient(node, state);
}

template <typename T>
typename FunctorBase<T>::DotType
FunctorBase<T>::dot(const ElemArg & elem, const StateArg & state) const
Expand Down Expand Up @@ -697,6 +736,13 @@ FunctorBase<T>::dot(const ElemPointArg & elem_point, const StateArg & state) con
return evaluateDot(elem_point, state);
}

template <typename T>
typename FunctorBase<T>::DotType
FunctorBase<T>::dot(const NodeArg & node, const StateArg & state) const
{
return evaluateDot(node, state);
}

template <typename T>
bool
FunctorBase<T>::hasFaceSide(const FaceInfo & fi, const bool fi_elem_side) const
Expand Down Expand Up @@ -874,6 +920,10 @@ class FunctorEnvelope final : public FunctorBase<T>, 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
{
Expand All @@ -897,6 +947,10 @@ class FunctorEnvelope final : public FunctorBase<T>, 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
{
Expand All @@ -919,6 +973,10 @@ class FunctorEnvelope final : public FunctorBase<T>, 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:
Expand Down Expand Up @@ -961,6 +1019,8 @@ class ConstantFunctor final : public FunctorBase<T>
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; }
Expand All @@ -970,12 +1030,14 @@ class ConstantFunctor final : public FunctorBase<T>
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;
Expand Down Expand Up @@ -1026,6 +1088,11 @@ class NullFunctor final : public FunctorBase<T>
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 <typename T>
Expand Down
2 changes: 2 additions & 0 deletions framework/include/base/MooseFunctorArguments.h
Expand Up @@ -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
{
/**
Expand Down
5 changes: 5 additions & 0 deletions framework/include/functions/Function.h
Expand Up @@ -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 <typename R>
ValueType evaluateHelper(const R & r, const Moose::StateArg & state) const;
Expand All @@ -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 <typename R>
GradientType evaluateGradientHelper(const R & r, const Moose::StateArg & state) const;
Expand All @@ -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 <typename R>
DotType evaluateDotHelper(const R & r, const Moose::StateArg & state) const;
Expand All @@ -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 <typename U>
Expand Down
12 changes: 12 additions & 0 deletions framework/include/utils/ADWrapperFunctor.h
Expand Up @@ -71,6 +71,10 @@ class ADWrapperFunctor : public FunctorBase<T>
{
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
{
Expand All @@ -93,6 +97,10 @@ class ADWrapperFunctor : public FunctorBase<T>
{
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
{
Expand All @@ -114,6 +122,10 @@ class ADWrapperFunctor : public FunctorBase<T>
{
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:
Expand Down
9 changes: 9 additions & 0 deletions framework/include/utils/ArrayComponentFunctor.h
Expand Up @@ -70,11 +70,20 @@ class ArrayComponentFunctor : public FunctorBase<T>
return _array(elem_point, state)[_component];
}

ValueType evaluate(const NodeArg & node, const StateArg & state) const override final
{
return _array(node, state)[_component];
}

using FunctorBase<T>::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 <typename T, typename ArrayTypeFunctor>
Expand Down
31 changes: 31 additions & 0 deletions framework/include/utils/PiecewiseByBlockLambdaFunctor.h
Expand Up @@ -70,6 +70,7 @@ class PiecewiseByBlockLambdaFunctor : public Moose::FunctorBase<T>
using ElemQpFn = std::function<T(const Moose::ElemQpArg &, const Moose::StateArg &)>;
using ElemSideQpFn = std::function<T(const Moose::ElemSideQpArg &, const Moose::StateArg &)>;
using ElemPointFn = std::function<T(const Moose::ElemPointArg &, const Moose::StateArg &)>;
using NodeFn = std::function<T(const Moose::NodeArg &, const Moose::StateArg &)>;

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;
Expand All @@ -78,12 +79,15 @@ class PiecewiseByBlockLambdaFunctor : public Moose::FunctorBase<T>
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<T>::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:
/**
Expand All @@ -109,6 +113,10 @@ class PiecewiseByBlockLambdaFunctor : public Moose::FunctorBase<T>
/// Functors that return evaluations at an arbitrary physical point in an element
std::unordered_map<SubdomainID, ElemPointFn> _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<SubdomainID, NodeFn> _node_functor;

/// The mesh that this functor operates on
const MooseMesh & _mesh;
};
Expand Down Expand Up @@ -279,6 +287,21 @@ PiecewiseByBlockLambdaFunctor<T>::evaluate(const Moose::ElemPointArg & elem_poin
return it->second(elem_point_arg, time);
}

template <typename T>
typename PiecewiseByBlockLambdaFunctor<T>::ValueType
PiecewiseByBlockLambdaFunctor<T>::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 T>
typename PiecewiseByBlockLambdaFunctor<T>::GradientType
PiecewiseByBlockLambdaFunctor<T>::evaluateGradient(const Moose::ElemArg & elem_arg,
Expand All @@ -294,3 +317,11 @@ PiecewiseByBlockLambdaFunctor<T>::evaluateGradient(const Moose::FaceArg & face_a
{
return Moose::FV::greenGaussGradient(face_arg, time, *this, true, _mesh);
}

template <typename T>
typename PiecewiseByBlockLambdaFunctor<T>::GradientType
PiecewiseByBlockLambdaFunctor<T>::evaluateGradient(const Moose::NodeArg & node_arg,
const Moose::StateArg & time) const
{
return Moose::FV::greenGaussGradient(node_arg, time, *this, true, _mesh);
}
6 changes: 6 additions & 0 deletions framework/include/variables/MooseVariableFE.h
Expand Up @@ -689,6 +689,8 @@ class MooseVariableFE : public MooseVariableField<OutputType>
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
{
Expand All @@ -698,6 +700,10 @@ class MooseVariableFE : public MooseVariableField<OutputType>
{
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 <typename OutputType>
Expand Down

0 comments on commit 9f21155

Please sign in to comment.