function_base.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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" // deprecated
27 
28 // C++ includes
29 #include <cstddef>
30 #include <memory>
31 
32 namespace libMesh
33 {
34 
35 // Forward Declarations
36 class Point;
37 
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 
141  virtual Output component(unsigned int i,
142  const Point & p,
143  Real time=0.);
144 
145 
150  bool initialized () const;
151 
159 
164  bool is_time_dependent() const;
165 
166 protected:
167 
175 
181 
186 
187 };
188 
189 
190 // ------------------------------------------------------------
191 // FunctionBase inline methods
192 
193 template<typename Output>
194 inline
196  _master (master),
197  _initialized (false),
198  _is_time_dependent (true) // Assume we are time-dependent until the user says otherwise
199 {
200 }
201 
202 
203 
204 template <typename Output>
205 inline
207 {
208  return (this->_initialized);
209 }
210 
211 template <typename Output>
212 inline
213 void FunctionBase<Output>::set_is_time_dependent( bool is_time_dependent )
214 {
215  this->_is_time_dependent = is_time_dependent;
216 }
217 
218 template <typename Output>
219 inline
221 {
222  return (this->_is_time_dependent);
223 }
224 
225 
226 template <typename Output>
227 inline
228 Output FunctionBase<Output>::component (unsigned int i,
229  const Point & p,
230  Real time)
231 {
232  DenseVector<Output> outvec(i+1);
233  (*this)(p, time, outvec);
234  return outvec(i);
235 }
236 
237 
238 
239 template <typename Output>
240 inline
242  DenseVector<Output> & output)
243 {
244  // Call the time-dependent function with t=0.
245  this->operator()(p, 0., output);
246 }
247 
248 } // namespace libMesh
249 
250 #endif // LIBMESH_FUNCTION_BASE_H
FunctionBase(const FunctionBase *master=nullptr)
virtual Output component(unsigned int i, const Point &p, Real time=0.)
const FunctionBase * _master
virtual Output operator()(const Point &p, const Real time=0.)=0
virtual void init()
Definition: function_base.h:87
void set_is_time_dependent(bool is_time_dependent)
virtual ~FunctionBase()=default
bool is_time_dependent() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool initialized() const
bool initialized()
Definition: libmesh.C:258
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 geometric point in (x,y,z) space.
Definition: point.h:38
virtual void clear()
Definition: function_base.h:92