analytic_function.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_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>
35 
47 template <typename Output=Number>
48 class AnalyticFunction : public FunctionBase<Output>
49 {
50 public:
51 
53  typedef Output (*OutputFunction)(const Point & p, const Real time);
54 
60 
62  typedef void (*OutputVectorFunction)(DenseVector<Output> & output,
63  const Point & p,
64  const Real time);
69 
73  AnalyticFunction (AnalyticFunction &&) = default;
74  AnalyticFunction (const AnalyticFunction &) = default;
75  AnalyticFunction & operator= (const AnalyticFunction &) = default;
77  virtual ~AnalyticFunction () = default;
78 
85 
90 
91  virtual void init () override;
92 
93  virtual void clear () override;
94 
95  virtual std::unique_ptr<FunctionBase<Output>> clone () const override;
96 
97  virtual Output operator() (const Point & p,
98  const Real time=0.) override;
99 
100  virtual void operator() (const Point & p,
101  const Real time,
102  DenseVector<Output> & output) override;
103 };
104 
105 
106 
107 // ------------------------------------------------------------
108 // AnalyticFunction inline methods
109 template <typename Output>
110 inline
112  const Real time)
113 {
114  libmesh_assert (this->initialized());
115  return (this->_number_fptr(p, time));
116 }
117 
118 
119 
120 template <typename Output>
121 inline
123  const Real time,
124  DenseVector<Output> & output)
125 {
126  libmesh_assert (this->initialized());
127  this->_vector_fptr(output, p, time);
128  return;
129 }
130 
131 
132 
133 template <typename Output>
135  FunctionBase<Output> (),
136  _number_fptr (fptr),
137  _vector_fptr (nullptr)
138 {
139  libmesh_assert(fptr);
140  this->_initialized = true;
141 }
142 
143 
144 
145 template <typename Output>
146 inline
147 AnalyticFunction<Output>::AnalyticFunction (OutputVectorFunction fptr) :
148  FunctionBase<Output> (),
149  _number_fptr (nullptr),
150  _vector_fptr (fptr)
151 {
152  libmesh_assert(fptr);
153  this->_initialized = true;
154 }
155 
156 
157 
158 template <typename Output>
160 {
161  // dumb double-test
162  libmesh_assert ((_number_fptr != nullptr) || (_vector_fptr != nullptr));
163 
164  // definitely ready
165  this->_initialized = true;
166 }
167 
168 
169 
170 template <typename Output>
171 inline
173 {
174  // We probably need a method to reset these later...
175  _number_fptr = nullptr;
176  _vector_fptr = nullptr;
177 
178  // definitely not ready
179  this->_initialized = false;
180 }
181 
182 
183 
184 template <typename Output>
185 inline
186 std::unique_ptr<FunctionBase<Output>>
188 {
189  return std::unique_ptr<FunctionBase<Output>>
190  ( _number_fptr ?
191  new AnalyticFunction<Output>(_number_fptr) :
192  new AnalyticFunction<Output>(_vector_fptr) );
193 }
194 
195 
196 } // namespace libMesh
197 
198 
199 #endif // LIBMESH_ANALYTIC_FUNCTION_H
virtual Output operator()(const Point &p, const Real time=0.) override
Output(* OutputFunction)(const Point &p, const Real time)
OutputVectorFunction _vector_fptr
Wraps a function pointer into a FunctionBase object.
virtual std::unique_ptr< FunctionBase< Output > > clone() const override
virtual ~AnalyticFunction()=default
void(* OutputVectorFunction)(DenseVector< Output > &output, const Point &p, const Real time)
AnalyticFunction(OutputFunction fptr)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void init() override
virtual void clear() override
bool initialized()
Definition: libmesh.C:258
Base class for functors that can be evaluated at a point and (optionally) time.
AnalyticFunction & operator=(const AnalyticFunction &)=default
A geometric point in (x,y,z) space.
Definition: point.h:38