libMesh
analytic_function.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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 
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 {
140  this->_initialized = true;
141 }
142 
143 
144 
145 template <typename Output>
146 inline
148  FunctionBase<Output> (),
149  _number_fptr (nullptr),
150  _vector_fptr (fptr)
151 {
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 _number_fptr ?
190  std::make_unique<AnalyticFunction<Output>>(_number_fptr) :
191  std::make_unique<AnalyticFunction<Output>>(_vector_fptr);
192 }
193 
194 
195 } // namespace libMesh
196 
197 
198 #endif // LIBMESH_ANALYTIC_FUNCTION_H
OutputFunction _number_fptr
Pointer to user-provided function that computes the boundary values when an analytical expression is ...
virtual Output operator()(const Point &p, const Real time=0.) override
bool _initialized
When init() was called so that everything is ready for calls to operator() (...), then this bool is t...
Output(* OutputFunction)(const Point &p, const Real time)
Scalar return value function pointer type.
The libMesh namespace provides an interface to certain functionality in the library.
OutputVectorFunction _vector_fptr
Pointer to user-provided vector valued function.
Wraps a function pointer into a FunctionBase object.
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:80
virtual std::unique_ptr< FunctionBase< Output > > clone() const override
libmesh_assert(ctx)
virtual ~AnalyticFunction()=default
void(* OutputVectorFunction)(DenseVector< Output > &output, const Point &p, const Real time)
Vector return value function pointer type.
AnalyticFunction(OutputFunction fptr)
Constructor.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void init() override
The actual initialization process.
virtual void clear() override
Clears the function.
bool initialized()
Checks that library initialization has been done.
Definition: libmesh.C:276
Base class for functors that can be evaluated at a point and (optionally) time.
AnalyticFunction & operator=(const AnalyticFunction &)=default
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39