libMesh
wrapped_functor.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 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_WRAPPED_FUNCTOR_H
21 #define LIBMESH_WRAPPED_FUNCTOR_H
22 
23 // Local Includes
24 #include "libmesh/fem_function_base.h"
25 #include "libmesh/function_base.h"
26 #include "libmesh/point.h"
27 
28 // C++ includes
29 #include <cstddef>
30 #include <memory>
31 
32 namespace libMesh
33 {
34 
44 template <typename Output=Number>
45 class WrappedFunctor : public FEMFunctionBase<Output>
46 {
47 public:
48 
54  : _func(func.clone())
55  { }
56 
61  WrappedFunctor (const WrappedFunctor &) = delete;
62  WrappedFunctor & operator= (const WrappedFunctor &) = delete;
63 
67  WrappedFunctor (WrappedFunctor &&) = default;
69  virtual ~WrappedFunctor () = default;
70 
71  virtual std::unique_ptr<FEMFunctionBase<Output>> clone () const override
72  {
73  return std::make_unique<WrappedFunctor<Output>>(*_func);
74  }
75 
76  virtual Output operator() (const FEMContext &,
77  const Point & p,
78  const Real time = 0.) override
79  { return _func->operator()(p, time); }
80 
81  virtual void operator() (const FEMContext &,
82  const Point & p,
83  const Real time,
84  DenseVector<Output> & output) override
85  { _func->operator() (p, time, output); }
86 
87  virtual Output component (const FEMContext &,
88  unsigned int i,
89  const Point & p,
90  Real time=0.) override
91  { return _func->component(i, p, time); }
92 
93 protected:
94 
95  std::unique_ptr<FunctionBase<Output>> _func;
96 };
97 
98 
99 
100 } // namespace libMesh
101 
102 #endif // LIBMESH_WRAPPED_FUNCTOR_H
WrappedFunctor & operator=(const WrappedFunctor &)=delete
virtual Output component(const FEMContext &, unsigned int i, const Point &p, Real time=0.) override
The libMesh namespace provides an interface to certain functionality in the library.
virtual std::unique_ptr< FEMFunctionBase< Output > > clone() const override
This class provides a wrapper with which to evaluate a (libMesh-style) function pointer in a Function...
virtual Output operator()(const FEMContext &, const Point &p, const Real time=0.) override
std::unique_ptr< FunctionBase< Output > > _func
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:62
virtual ~WrappedFunctor()=default
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
WrappedFunctor(const FunctionBase< Output > &func)
Constructor to wrap FunctionBase functors in a FEMFunctionBase compatible shim.
Base class for functors that can be evaluated at a point and (optionally) time.
FEMFunctionBase is a base class from which users can derive in order to define "function-like" object...
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39