libMesh
function_base.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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 
61 template <typename Output=Number>
62 class FunctionBase
63 {
64 protected:
65 
69  explicit
70  FunctionBase (const FunctionBase * master = nullptr);
71 
72 public:
73 
77  FunctionBase (FunctionBase &&) = default;
78  FunctionBase (const FunctionBase &) = default;
79  FunctionBase & operator= (const FunctionBase &) = default;
80  FunctionBase & operator= (FunctionBase &&) = default;
81  virtual ~FunctionBase () = default;
82 
86  virtual void init () {}
87 
91  virtual void clear () {}
92 
100  virtual std::unique_ptr<FunctionBase<Output>> clone () const = 0;
101 
108  virtual Output operator() (const Point & p,
109  const Real time = 0.) = 0;
110 
115  void operator() (const Point & p,
116  DenseVector<Output> & output);
117 
124  virtual void operator() (const Point & p,
125  const Real time,
126  DenseVector<Output> & output) = 0;
127 
140  virtual Output component(unsigned int i,
141  const Point & p,
142  Real time=0.);
143 
144 
149  bool initialized () const;
150 
158 
163  bool is_time_dependent() const;
164 
165 protected:
166 
174 
180 
185 
186 };
187 
188 
189 // ------------------------------------------------------------
190 // FunctionBase inline methods
191 
192 template<typename Output>
193 inline
195  _master (master),
196  _initialized (false),
197  _is_time_dependent (true) // Assume we are time-dependent until the user says otherwise
198 {
199 }
200 
201 
202 
203 template <typename Output>
204 inline
206 {
207  return (this->_initialized);
208 }
209 
210 template <typename Output>
211 inline
212 void FunctionBase<Output>::set_is_time_dependent( bool is_time_dependent )
213 {
214  this->_is_time_dependent = is_time_dependent;
215 }
216 
217 template <typename Output>
218 inline
220 {
221  return (this->_is_time_dependent);
222 }
223 
224 
225 template <typename Output>
226 inline
227 Output FunctionBase<Output>::component (unsigned int i,
228  const Point & p,
229  Real time)
230 {
231  DenseVector<Output> outvec(i+1);
232  (*this)(p, time, outvec);
233  return outvec(i);
234 }
235 
236 
237 
238 template <typename Output>
239 inline
241  DenseVector<Output> & output)
242 {
243  // Call the time-dependent function with t=0.
244  this->operator()(p, 0., output);
245 }
246 
247 } // namespace libMesh
248 
249 #endif // LIBMESH_FUNCTION_BASE_H
libMesh::FunctionBase
Base class for functors that can be evaluated at a point and (optionally) time.
Definition: dirichlet_boundaries.h:44
libMesh::FunctionBase::is_time_dependent
bool is_time_dependent() const
Definition: function_base.h:219
libMesh::FunctionBase::clone
virtual std::unique_ptr< FunctionBase< Output > > clone() const =0
libMesh::FunctionBase::init
virtual void init()
The actual initialization process.
Definition: function_base.h:86
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::FunctionBase::_is_time_dependent
bool _is_time_dependent
Cache whether or not this function is actually time-dependent.
Definition: function_base.h:184
libMesh::FunctionBase::operator=
FunctionBase & operator=(const FunctionBase &)=default
libMesh::FunctionBase::set_is_time_dependent
void set_is_time_dependent(bool is_time_dependent)
Function to set whether this is a time-dependent function or not.
Definition: function_base.h:212
libMesh::FunctionBase::initialized
bool initialized() const
Definition: function_base.h:205
libMesh::FunctionBase::component
virtual Output component(unsigned int i, const Point &p, Real time=0.)
Definition: function_base.h:227
libMesh::FunctionBase::FunctionBase
FunctionBase(const FunctionBase *master=nullptr)
Constructor.
Definition: function_base.h:194
libMesh::FunctionBase::_initialized
bool _initialized
When init() was called so that everything is ready for calls to operator() (...), then this bool is t...
Definition: function_base.h:179
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::FunctionBase::_master
const FunctionBase * _master
Const pointer to our master, initialized to nullptr.
Definition: function_base.h:173
libMesh::initialized
bool initialized()
Checks that library initialization has been done.
Definition: libmesh.C:265
libMesh::FunctionBase::operator()
virtual Output operator()(const Point &p, const Real time=0.)=0
libMesh::FunctionBase::clear
virtual void clear()
Clears the function.
Definition: function_base.h:91
libMesh::FunctionBase::~FunctionBase
virtual ~FunctionBase()=default
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::DenseVector< Output >