LCOV - code coverage report
Current view: top level - include/numerics - fem_function_base.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4229 (6a9aeb) with base 727f46 Lines: 3 8 37.5 %
Date: 2025-08-19 19:27:09 Functions: 7 27 25.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
       3             : 
       4             : // This library is free software; you can redistribute it and/or
       5             : // modify it under the terms of the GNU Lesser General Public
       6             : // License as published by the Free Software Foundation; either
       7             : // version 2.1 of the License, or (at your option) any later version.
       8             : 
       9             : // This library is distributed in the hope that it will be useful,
      10             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             : // Lesser General Public License for more details.
      13             : 
      14             : // You should have received a copy of the GNU Lesser General Public
      15             : // License along with this library; if not, write to the Free Software
      16             : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      17             : 
      18             : 
      19             : 
      20             : #ifndef LIBMESH_FEM_FUNCTION_BASE_H
      21             : #define LIBMESH_FEM_FUNCTION_BASE_H
      22             : 
      23             : // Local Includes
      24             : #include "libmesh/libmesh_common.h"
      25             : #include "libmesh/dense_vector.h" // required to instantiate a DenseVector<> below
      26             : #include "libmesh/fem_context.h"
      27             : 
      28             : // C++ includes
      29             : #include <memory>
      30             : 
      31             : namespace libMesh
      32             : {
      33             : 
      34             : // Forward Declarations
      35             : class Point;
      36             : 
      37             : /**
      38             :  * FEMFunctionBase is a base class from which users can derive in
      39             :  * order to define "function-like" objects that can be used within
      40             :  * FEMSystem.
      41             :  *
      42             :  * \author Roy Stogner
      43             :  * \date 2012
      44             :  */
      45             : template <typename Output=Number>
      46             : class FEMFunctionBase
      47             : {
      48             : protected:
      49             : 
      50             :   /**
      51             :    * Constructor.
      52             :    */
      53       12818 :   FEMFunctionBase () = default;
      54             : 
      55             : public:
      56             : 
      57             :   /**
      58             :    * The 5 special functions can be defaulted for this class.
      59             :    */
      60             :   FEMFunctionBase (FEMFunctionBase &&) = default;
      61             :   FEMFunctionBase (const FEMFunctionBase &) = default;
      62             :   FEMFunctionBase & operator= (const FEMFunctionBase &) = default;
      63             :   FEMFunctionBase & operator= (FEMFunctionBase &&) = default;
      64       12818 :   virtual ~FEMFunctionBase () = default;
      65             : 
      66             :   /**
      67             :    * Any post-construction initialization
      68             :    */
      69           0 :   virtual void init () {}
      70             : 
      71             :   /**
      72             :    * Prepares a context object for use.
      73             :    *
      74             :    * Most problems will want to reimplement this for efficiency, in
      75             :    * order to call FE::get_*() as their particular function requires.
      76             :    */
      77       14008 :   virtual void init_context (const FEMContext &) {}
      78             : 
      79             :   /**
      80             :    * \returns A new copy of the function.
      81             :    *
      82             :    * The new copy should be as "deep" as necessary to allow
      83             :    * independent destruction and simultaneous evaluations of the
      84             :    * copies in different threads.
      85             :    */
      86             :   virtual std::unique_ptr<FEMFunctionBase<Output>> clone () const = 0;
      87             : 
      88             :   /**
      89             :    * \returns The scalar function value at coordinate \p p and time \p
      90             :    * time, which defaults to zero.
      91             :    *
      92             :    * Pure virtual, so you have to override it.
      93             :    */
      94             :   virtual Output operator() (const FEMContext &,
      95             :                              const Point & p,
      96             :                              const Real time = 0.) = 0;
      97             : 
      98             :   /**
      99             :    * Evaluation function for time-independent vector-valued functions.
     100             :    * Sets output values in the passed-in \p output DenseVector.
     101             :    */
     102             :   void operator() (const FEMContext &,
     103             :                    const Point & p,
     104             :                    DenseVector<Output> & output);
     105             : 
     106             :   /**
     107             :    * Evaluation function for time-dependent vector-valued functions.
     108             :    * Sets output values in the passed-in \p output DenseVector.
     109             :    *
     110             :    * Pure virtual, so you have to override it.
     111             :    */
     112             :   virtual void operator() (const FEMContext &,
     113             :                            const Point & p,
     114             :                            const Real time,
     115             :                            DenseVector<Output> & output) = 0;
     116             : 
     117             :   /**
     118             :    * \returns The vector component \p i at coordinate \p p and time \p
     119             :    * time.
     120             :    *
     121             :    * \note Subclasses aren't required to override this, since the default
     122             :    * implementation is based on the full vector evaluation, which is
     123             :    * often correct.
     124             :    *
     125             :    * \note Subclasses are recommended to override this, since the default
     126             :    * implementation is based on a vector evaluation, which is usually
     127             :    * unnecessarily inefficient.
     128             :    */
     129             :   virtual Output component(const FEMContext &,
     130             :                            unsigned int i,
     131             :                            const Point & p,
     132             :                            Real time=0.);
     133             : };
     134             : 
     135             : template <typename Output>
     136             : inline
     137           0 : Output FEMFunctionBase<Output>::component (const FEMContext & context,
     138             :                                            unsigned int i,
     139             :                                            const Point & p,
     140             :                                            Real time)
     141             : {
     142           0 :   DenseVector<Output> outvec(i+1);
     143           0 :   (*this)(context, p, time, outvec);
     144           0 :   return outvec(i);
     145             : }
     146             : 
     147             : template <typename Output>
     148             : inline
     149             : void FEMFunctionBase<Output>::operator() (const FEMContext & context,
     150             :                                           const Point & p,
     151             :                                           DenseVector<Output> & output)
     152             : {
     153             :   // Call the time-dependent function with t=0.
     154             :   this->operator()(context, p, 0., output);
     155             : }
     156             : 
     157             : } // namespace libMesh
     158             : 
     159             : #endif // LIBMESH_FEM_FUNCTION_BASE_H

Generated by: LCOV version 1.14