libMesh
Loading...
Searching...
No Matches
analytic_function.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
29namespace libMesh
30{
31
32// Forward Declarations
33template <typename T>
34class DenseVector;
35
47template <typename Output=Number>
48class AnalyticFunction : public FunctionBase<Output>
49{
50public:
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
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
109template <typename Output>
110inline
112 const Real time)
113{
115 libmesh_assert_msg(_number_fptr,
116 "You must construct AnalyticFunction with a scalar-valued "
117 "function in order to use this operator() override.");
118 return (this->_number_fptr(p, time));
119}
120
121
122
123template <typename Output>
124inline
126 const Real time,
127 DenseVector<Output> & output)
128{
130 libmesh_assert_msg(_vector_fptr,
131 "You must construct AnalyticFunction with a vector-valued "
132 "function in order to use this operator() override.");
133 this->_vector_fptr(output, p, time);
134 return;
135}
136
137
138
139template <typename Output>
141 FunctionBase<Output> (),
142 _number_fptr (fptr),
143 _vector_fptr (nullptr)
144{
146 this->_initialized = true;
147}
148
149
150
151template <typename Output>
152inline
154 FunctionBase<Output> (),
155 _number_fptr (nullptr),
156 _vector_fptr (fptr)
157{
159 this->_initialized = true;
160}
161
162
163
164template <typename Output>
166{
167 // dumb double-test
168 libmesh_assert ((_number_fptr != nullptr) || (_vector_fptr != nullptr));
169
170 // definitely ready
171 this->_initialized = true;
172}
173
174
175
176template <typename Output>
177inline
179{
180 // We probably need a method to reset these later...
181 _number_fptr = nullptr;
182 _vector_fptr = nullptr;
183
184 // definitely not ready
185 this->_initialized = false;
186}
187
188
189
190template <typename Output>
191inline
192std::unique_ptr<FunctionBase<Output>>
194{
195 return _number_fptr ?
196 std::make_unique<AnalyticFunction<Output>>(_number_fptr) :
197 std::make_unique<AnalyticFunction<Output>>(_vector_fptr);
198}
199
200
201} // namespace libMesh
202
203
204#endif // LIBMESH_ANALYTIC_FUNCTION_H
Wraps a function pointer into a FunctionBase object.
AnalyticFunction(AnalyticFunction &&)=default
The 5 special functions can be defaulted for this class.
OutputFunction _number_fptr
Pointer to user-provided function that computes the boundary values when an analytical expression is ...
void(* OutputVectorFunction)(DenseVector< Output > &output, const Point &p, const Real time)
Vector return value function pointer type.
AnalyticFunction(OutputFunction fptr)
Constructor.
Output(* OutputFunction)(const Point &p, const Real time)
Scalar return value function pointer type.
OutputVectorFunction _vector_fptr
Pointer to user-provided vector valued function.
virtual std::unique_ptr< FunctionBase< Output > > clone() const override
AnalyticFunction(const AnalyticFunction &)=default
virtual void init() override
The actual initialization process.
AnalyticFunction & operator=(const AnalyticFunction &)=default
virtual void clear() override
Clears the function.
virtual ~AnalyticFunction()=default
virtual Output operator()(const Point &p, const Real time=0.) override
Defines a dense vector for use in Finite Element-type computations.
Base class for functors that can be evaluated at a point and (optionally) time.
bool _initialized
When init() was called so that everything is ready for calls to operator() (...), then this bool is t...
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
The libMesh namespace provides an interface to certain functionality in the library.
libmesh_assert(ctx)
bool initialized()
Checks that library initialization has been done.
Definition libmesh.C:324
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition projection.C:81