libMesh
function_base.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_FUNCTION_BASE_H
21 #define LIBMESH_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 
27 // C++ includes
28 #include <cstddef>
29 #include <memory>
30 
31 namespace libMesh
32 {
33 
34 // Forward Declarations
35 class Point;
36 
62 template <typename Output=Number>
63 class FunctionBase
64 {
65 protected:
66 
70  explicit
71  FunctionBase (const FunctionBase * master = nullptr);
72 
73 public:
74 
78  FunctionBase (FunctionBase &&) = default;
79  FunctionBase (const FunctionBase &) = default;
80  FunctionBase & operator= (const FunctionBase &) = default;
81  FunctionBase & operator= (FunctionBase &&) = default;
82  virtual ~FunctionBase () = default;
83 
87  virtual void init () {}
88 
92  virtual void clear () {}
93 
101  virtual std::unique_ptr<FunctionBase<Output>> clone () const = 0;
102 
109  virtual Output operator() (const Point & p,
110  const Real time = 0.) = 0;
111 
116  void operator() (const Point & p,
117  DenseVector<Output> & output);
118 
125  virtual void operator() (const Point & p,
126  const Real time,
127  DenseVector<Output> & output) = 0;
128 
145  virtual Output component(unsigned int i,
146  const Point & p,
147  Real time=0.);
148 
149 
154  bool initialized () const;
155 
163 
168  bool is_time_dependent() const;
169 
170 protected:
171 
179 
185 
190 
191 };
192 
193 
194 // ------------------------------------------------------------
195 // FunctionBase inline methods
196 
197 template<typename Output>
198 inline
200  _master (master),
201  _initialized (false),
202  _is_time_dependent (true) // Assume we are time-dependent until the user says otherwise
203 {
204 }
205 
206 
207 
208 template <typename Output>
209 inline
211 {
212  return (this->_initialized);
213 }
214 
215 template <typename Output>
216 inline
217 void FunctionBase<Output>::set_is_time_dependent( bool is_time_dependent )
218 {
219  this->_is_time_dependent = is_time_dependent;
220 }
221 
222 template <typename Output>
223 inline
225 {
226  return (this->_is_time_dependent);
227 }
228 
229 
230 template <typename Output>
231 inline
232 Output FunctionBase<Output>::component (unsigned int i,
233  const Point & p,
234  Real time)
235 {
236  DenseVector<Output> outvec(i+1);
237  (*this)(p, time, outvec);
238  return outvec(i);
239 }
240 
241 
242 
243 template <typename Output>
244 inline
246  DenseVector<Output> & output)
247 {
248  // Call the time-dependent function with t=0.
249  this->operator()(p, 0., output);
250 }
251 
252 } // namespace libMesh
253 
254 #endif // LIBMESH_FUNCTION_BASE_H
FunctionBase(const FunctionBase *master=nullptr)
Constructor.
virtual Output component(unsigned int i, const Point &p, Real time=0.)
const FunctionBase * _master
Const pointer to our master, initialized to nullptr.
bool _initialized
When init() was called so that everything is ready for calls to operator() (...), then this bool is t...
virtual Output operator()(const Point &p, const Real time=0.)=0
The libMesh namespace provides an interface to certain functionality in the library.
virtual void init()
The actual initialization process.
Definition: function_base.h:87
void set_is_time_dependent(bool is_time_dependent)
Function to set whether this is a time-dependent function or not.
virtual ~FunctionBase()=default
bool is_time_dependent() const
bool _is_time_dependent
Cache whether or not this function is actually time-dependent.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool initialized() const
bool initialized()
Checks that library initialization has been done.
Definition: libmesh.C:266
virtual std::unique_ptr< FunctionBase< Output > > clone() const =0
Base class for functors that can be evaluated at a point and (optionally) time.
FunctionBase & operator=(const FunctionBase &)=default
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
virtual void clear()
Clears the function.
Definition: function_base.h:92