libMesh
analytic_function.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_ANALYTIC_FUNCTION_H
21 #define LIBMESH_ANALYTIC_FUNCTION_H
22 
23 // Local Includes
24 #include "libmesh/function_base.h"
25 
26 // C++ includes
27 #include <cstddef>
28 
29 namespace libMesh
30 {
31 
32 // Forward Declarations
33 template <typename T>
34 class DenseVector;
35 
45 template <typename Output=Number>
46 class AnalyticFunction : public FunctionBase<Output>
47 {
48 public:
49 
54  AnalyticFunction (Output fptr(const Point & p,
55  const Real time));
56 
62  const Point & p,
63  const Real time));
68 
69 
75  Output (* _number_fptr) (const Point & p,
76  const Real time);
77 
81  void (* _vector_fptr) (DenseVector<Output> & output,
82  const Point & p,
83  const Real time);
84 
85  virtual void init () libmesh_override;
86 
87  virtual void clear () libmesh_override;
88 
89  virtual UniquePtr<FunctionBase<Output>> clone () const libmesh_override;
90 
91  virtual Output operator() (const Point & p,
92  const Real time=0.) libmesh_override;
93 
94  virtual void operator() (const Point & p,
95  const Real time,
96  DenseVector<Output> & output) libmesh_override;
97 };
98 
99 
100 
101 // ------------------------------------------------------------
102 // AnalyticFunction inline methods
103 template <typename Output>
104 inline
105 Output AnalyticFunction<Output>::operator() (const Point & p,
106  const Real time)
107 {
108  libmesh_assert (this->initialized());
109  return (this->_number_fptr(p, time));
110 }
111 
112 
113 
114 template <typename Output>
115 inline
117  const Real time,
118  DenseVector<Output> & output)
119 {
120  libmesh_assert (this->initialized());
121  this->_vector_fptr(output, p, time);
122  return;
123 }
124 
125 
126 
127 template <typename Output>
129  const Real time)) :
131  _number_fptr (fptr),
133 {
135  this->_initialized = true;
136 }
137 
138 
139 
140 template <typename Output>
141 inline
143  const Point & p,
144  const Real time)) :
148 {
150  this->_initialized = true;
151 }
152 
153 
154 
155 template <typename Output>
156 inline
158 {
159 }
160 
161 
162 
163 template <typename Output>
165 {
166  // dumb double-test
168 
169  // definitely ready
170  this->_initialized = true;
171 }
172 
173 
174 
175 template <typename Output>
176 inline
178 {
179  // We probably need a method to reset these later...
182 
183  // definitely not ready
184  this->_initialized = false;
185 }
186 
187 
188 
189 template <typename Output>
190 inline
193 {
195  ( _number_fptr ?
198 }
199 
200 
201 } // namespace libMesh
202 
203 
204 #endif // LIBMESH_ANALYTIC_FUNCTION_H
virtual UniquePtr< FunctionBase< Output > > clone() const libmesh_override
bool initialized() const
virtual Output operator()(const Point &p, const Real time=0.) libmesh_override
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
AnalyticFunction(Output fptr(const Point &p, const Real time))
Constructor.
The libMesh namespace provides an interface to certain functionality in the library.
This class provides function-like objects for which an analytical expression can be provided...
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:78
libmesh_assert(j)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
virtual void clear() libmesh_override
Clears the function.
void(* _vector_fptr)(DenseVector< Output > &output, const Point &p, const Real time)
Pointer to user-provided vector valued function.
Output(* _number_fptr)(const Point &p, const Real time)
Pointer to user-provided function that computes the boundary values when an analytical expression is ...
virtual void init() libmesh_override
The actual initialization process.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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