libMesh
function_base.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 #include "libmesh/auto_ptr.h"
27 
28 // C++ includes
29 #include <cstddef>
30 
31 namespace libMesh
32 {
33 
34 // Forward Declarations
35 class Point;
36 
60 template <typename Output=Number>
61 class FunctionBase
62 {
63 protected:
64 
68  explicit
69  FunctionBase (const FunctionBase * master = libmesh_nullptr);
70 
71 public:
72 
76  virtual ~FunctionBase ();
77 
81  virtual void init () {}
82 
86  virtual void clear () {}
87 
95  virtual UniquePtr<FunctionBase<Output>> clone () const = 0;
96 
103  virtual Output operator() (const Point & p,
104  const Real time = 0.) = 0;
105 
110  void operator() (const Point & p,
111  DenseVector<Output> & output);
112 
119  virtual void operator() (const Point & p,
120  const Real time,
121  DenseVector<Output> & output) = 0;
122 
135  virtual Output component(unsigned int i,
136  const Point & p,
137  Real time=0.);
138 
139 
144  bool initialized () const;
145 
153 
158  bool is_time_dependent() const;
159 
160 protected:
161 
169 
175 
180 
181 };
182 
183 
184 // ------------------------------------------------------------
185 // FunctionBase inline methods
186 
187 template<typename Output>
188 inline
190  _master (master),
191  _initialized (false),
192  _is_time_dependent (true) // Assume we are time-dependent until the user says otherwise
193 {
194 }
195 
196 
197 
198 template<typename Output>
199 inline
201 {
202 }
203 
204 
205 
206 template <typename Output>
207 inline
209 {
210  return (this->_initialized);
211 }
212 
213 template <typename Output>
214 inline
216 {
218 }
219 
220 template <typename Output>
221 inline
223 {
224  return (this->_is_time_dependent);
225 }
226 
227 
228 template <typename Output>
229 inline
230 Output FunctionBase<Output>::component (unsigned int i,
231  const Point & p,
232  Real time)
233 {
234  DenseVector<Output> outvec(i+1);
235  (*this)(p, time, outvec);
236  return outvec(i);
237 }
238 
239 
240 
241 template <typename Output>
242 inline
244  DenseVector<Output> & output)
245 {
246  // Call the time-dependent function with t=0.
247  this->operator()(p, 0., output);
248 }
249 
250 } // namespace libMesh
251 
252 #endif // LIBMESH_FUNCTION_BASE_H
virtual Output component(unsigned int i, const Point &p, Real time=0.)
bool initialized() const
const FunctionBase * _master
Const pointer to our master, initialized to NULL.
bool _initialized
When init() was called so that everything is ready for calls to operator() (...), then this bool is t...
const class libmesh_nullptr_t libmesh_nullptr
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:81
virtual ~FunctionBase()
Destructor.
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
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
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
virtual UniquePtr< FunctionBase< Output > > clone() const =0
FunctionBase(const FunctionBase *master=libmesh_nullptr)
Constructor.
Defines a dense vector for use in Finite Element-type computations.
This is the base class for functor-like classes.
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
virtual void clear()
Clears the function.
Definition: function_base.h:86