analytic_function.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 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 
33 
34 // Forward Declarations
35 template <typename T>
37 
38 
47 // ------------------------------------------------------------
48 // AnalyticFunction class definition
49 template <typename Output=Number>
50 class AnalyticFunction : public FunctionBase<Output>
51 {
52 public:
53 
58  AnalyticFunction (Output fptr(const Point& p,
59  const Real time));
60 
65  AnalyticFunction (void fptr(DenseVector<Output>& output,
66  const Point& p,
67  const Real time));
72 
73 
79  Output (* _number_fptr) (const Point& p,
80  const Real time);
81 
85  void (* _vector_fptr) (DenseVector<Output>& output,
86  const Point& p,
87  const Real time);
88 
92  void init ();
93 
97  void clear ();
98 
102  virtual AutoPtr<FunctionBase<Output> > clone () const;
103 
108  Output operator() (const Point& p,
109  const Real time=0.);
110 
115  void operator() (const Point& p,
116  const Real time,
117  DenseVector<Output>& output);
118 
119 };
120 
121 
122 
123 // ------------------------------------------------------------
124 // AnalyticFunction inline methods
125 template <typename Output>
126 inline
128  const Real time)
129 {
130  libmesh_assert (this->initialized());
131  return (this->_number_fptr(p, time));
132 }
133 
134 
135 
136 template <typename Output>
137 inline
139  const Real time,
140  DenseVector<Output>& output)
141 {
142  libmesh_assert (this->initialized());
143  this->_vector_fptr(output, p, time);
144  return;
145 }
146 
147 
148 
149 template <typename Output>
151  const Real time)) :
152  FunctionBase<Output> (),
153  _number_fptr (fptr),
154  _vector_fptr (NULL)
155 {
156  libmesh_assert(fptr);
157  this->_initialized = true;
158 }
159 
160 
161 
162 template <typename Output>
163 inline
165  const Point& p,
166  const Real time)) :
167  FunctionBase<Output> (),
168  _number_fptr (NULL),
169  _vector_fptr (fptr)
170 {
171  libmesh_assert(fptr);
172  this->_initialized = true;
173 }
174 
175 
176 
177 template <typename Output>
178 inline
180 {
181 }
182 
183 
184 
185 template <typename Output>
187 {
188  // dumb double-test
189  libmesh_assert ((_number_fptr != NULL) || (_vector_fptr != NULL));
190 
191  // definitely ready
192  this->_initialized = true;
193 }
194 
195 
196 
197 template <typename Output>
198 inline
200 {
201  // We probably need a method to reset these later...
202  _number_fptr = NULL;
203  _vector_fptr = NULL;
204 
205  // definitely not ready
206  this->_initialized = false;
207 }
208 
209 
210 
211 template <typename Output>
212 inline
215 {
217  ( _number_fptr ?
218  new AnalyticFunction<Output>(_number_fptr) :
219  new AnalyticFunction<Output>(_vector_fptr) );
220 }
221 
222 
223 } // namespace libMesh
224 
225 
226 #endif // LIBMESH_ANALYTIC_FUNCTION_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:04 UTC

Hosted By:
SourceForge.net Logo