LCOV - code coverage report
Current view: top level - include/userobjects - SpatialUserObjectFunctor.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 8601ad Lines: 14 28 50.0 %
Date: 2025-07-18 13:27:08 Functions: 20 153 13.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #pragma once
      11             : 
      12             : #include "MooseFunctor.h"
      13             : #include "InputParameters.h"
      14             : #include "BlockRestrictable.h"
      15             : 
      16             : /**
      17             :  * Base class for creating a user object with the SpatialUserObject and Moose::Functor APIs
      18             :  */
      19             : template <typename UserObjectType>
      20             : class SpatialUserObjectFunctor : public UserObjectType, public Moose::FunctorBase<Real>
      21             : {
      22             : public:
      23             :   static InputParameters validParams();
      24             : 
      25             :   SpatialUserObjectFunctor(const InputParameters & params);
      26             :   virtual bool hasBlocks(SubdomainID sub) const override;
      27             : 
      28             : protected:
      29             :   using ElemArg = Moose::ElemArg;
      30             :   using ElemQpArg = Moose::ElemQpArg;
      31             :   using ElemSideQpArg = Moose::ElemSideQpArg;
      32             :   using FaceArg = Moose::FaceArg;
      33             :   using ElemPointArg = Moose::ElemPointArg;
      34             :   using NodeArg = Moose::NodeArg;
      35             : 
      36             :   virtual Real evaluate(const ElemArg & elem, const Moose::StateArg & state) const override;
      37             :   virtual Real evaluate(const FaceArg & face, const Moose::StateArg & state) const override final;
      38             :   virtual Real evaluate(const ElemQpArg & qp, const Moose::StateArg & state) const override;
      39             :   virtual Real evaluate(const ElemSideQpArg & elem_side_qp,
      40             :                         const Moose::StateArg & state) const override final;
      41             :   virtual Real evaluate(const ElemPointArg & elem_point,
      42             :                         const Moose::StateArg & state) const override final;
      43             :   virtual Real evaluate(const NodeArg & node, const Moose::StateArg & state) const override final;
      44             : 
      45           0 :   virtual bool supportsFaceArg() const override final { return true; }
      46           0 :   virtual bool supportsElemSideQpArg() const override final { return true; }
      47             : 
      48             : private:
      49             :   /*
      50             :    * Helper template implementing functor evaluations
      51             :    */
      52             :   template <typename SpatialArg>
      53             :   Real evaluateTemplate(const SpatialArg & position, const Moose::StateArg & state) const;
      54             : };
      55             : 
      56             : template <typename UserObjectType>
      57             : InputParameters
      58      510994 : SpatialUserObjectFunctor<UserObjectType>::validParams()
      59             : {
      60      510994 :   auto params = UserObjectType::validParams();
      61             :   // Spatial UOs are used in the transfers
      62      510994 :   ExecFlagEnum & exec_enum = params.template set<ExecFlagEnum>("execute_on", true);
      63      510994 :   exec_enum.addAvailableFlags(EXEC_TRANSFER);
      64      510994 :   return params;
      65           0 : }
      66             : 
      67             : template <typename UserObjectType>
      68        5903 : SpatialUserObjectFunctor<UserObjectType>::SpatialUserObjectFunctor(const InputParameters & params)
      69       17709 :   : UserObjectType(params), Moose::FunctorBase<Real>(this->name())
      70             : {
      71       11806 : }
      72             : 
      73             : template <typename UserObjectType>
      74             : template <typename SpatialArg>
      75             : Real
      76        1800 : SpatialUserObjectFunctor<UserObjectType>::evaluateTemplate(
      77             :     const SpatialArg & position, const Moose::StateArg & libmesh_dbg_var(state)) const
      78             : {
      79             :   mooseAssert(state.state == 0, "We do not currently support evaluating at old states");
      80        1800 :   return this->spatialValue(position.getPoint());
      81             : }
      82             : 
      83             : template <typename UserObjectType>
      84             : Real
      85           0 : SpatialUserObjectFunctor<UserObjectType>::evaluate(const ElemArg & elem,
      86             :                                                    const Moose::StateArg & state) const
      87             : {
      88           0 :   return evaluateTemplate(elem, state);
      89             : }
      90             : 
      91             : template <typename UserObjectType>
      92             : Real
      93        1800 : SpatialUserObjectFunctor<UserObjectType>::evaluate(const FaceArg & face,
      94             :                                                    const Moose::StateArg & state) const
      95             : {
      96        1800 :   return evaluateTemplate(face, state);
      97             : }
      98             : 
      99             : template <typename UserObjectType>
     100             : Real
     101           0 : SpatialUserObjectFunctor<UserObjectType>::evaluate(const ElemQpArg & qp,
     102             :                                                    const Moose::StateArg & state) const
     103             : {
     104           0 :   return evaluateTemplate(qp, state);
     105             : }
     106             : 
     107             : template <typename UserObjectType>
     108             : Real
     109           0 : SpatialUserObjectFunctor<UserObjectType>::evaluate(const ElemSideQpArg & elem_side_qp,
     110             :                                                    const Moose::StateArg & state) const
     111             : {
     112           0 :   return evaluateTemplate(elem_side_qp, state);
     113             : }
     114             : 
     115             : template <typename UserObjectType>
     116             : Real
     117           0 : SpatialUserObjectFunctor<UserObjectType>::evaluate(const ElemPointArg & elem_point,
     118             :                                                    const Moose::StateArg & state) const
     119             : {
     120           0 :   return evaluateTemplate(elem_point, state);
     121             : }
     122             : 
     123             : template <typename UserObjectType>
     124             : Real
     125           0 : SpatialUserObjectFunctor<UserObjectType>::evaluate(const NodeArg & node,
     126             :                                                    const Moose::StateArg & state) const
     127             : {
     128           0 :   return evaluateTemplate(node, state);
     129             : }
     130             : 
     131             : template <typename UserObjectType>
     132             : bool
     133     1032981 : SpatialUserObjectFunctor<UserObjectType>::hasBlocks(const SubdomainID sub_id) const
     134             : {
     135             :   if constexpr (std::is_base_of<BlockRestrictable, UserObjectType>::value)
     136     1032981 :     return UserObjectType::hasBlocks(sub_id);
     137             :   else
     138           0 :     return Moose::FunctorBase<Real>::hasBlocks(sub_id);
     139             : }

Generated by: LCOV version 1.14