libMesh
Loading...
Searching...
No Matches
function_base.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
31namespace libMesh
32{
33
34// Forward Declarations
35class Point;
36
62template <typename Output=Number>
64{
65protected:
66
70 explicit
71 FunctionBase (const FunctionBase * master = nullptr);
72
73public:
74
78 FunctionBase (FunctionBase &&) = default;
79 FunctionBase (const FunctionBase &) = default;
80 FunctionBase & operator= (const 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
170protected:
171
179
185
190
191};
192
193
194// ------------------------------------------------------------
195// FunctionBase inline methods
196
197template<typename Output>
198inline
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
208template <typename Output>
209inline
211{
212 return (this->_initialized);
213}
214
215template <typename Output>
216inline
218{
219 this->_is_time_dependent = is_time_dependent;
220}
221
222template <typename Output>
223inline
225{
226 return (this->_is_time_dependent);
227}
228
229
230template <typename Output>
231inline
232Output 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
243template <typename Output>
244inline
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
Defines a dense vector for use in Finite Element-type computations.
Base class for functors that can be evaluated at a point and (optionally) time.
virtual void init()
The actual initialization process.
virtual ~FunctionBase()=default
virtual Output component(unsigned int i, const Point &p, Real time=0.)
const FunctionBase * _master
Const pointer to our master, initialized to nullptr.
virtual std::unique_ptr< FunctionBase< Output > > clone() const =0
bool _initialized
When init() was called so that everything is ready for calls to operator() (...), then this bool is t...
void set_is_time_dependent(bool is_time_dependent)
Function to set whether this is a time-dependent function or not.
bool is_time_dependent() const
FunctionBase & operator=(const FunctionBase &)=default
FunctionBase(const FunctionBase *master=nullptr)
Constructor.
bool _is_time_dependent
Cache whether or not this function is actually time-dependent.
FunctionBase(FunctionBase &&)=default
The 5 special functions can be defaulted for this class.
FunctionBase(const FunctionBase &)=default
virtual void clear()
Clears the function.
virtual Output operator()(const Point &p, const Real time=0.)=0
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
The libMesh namespace provides an interface to certain functionality in the library.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real