20#ifndef LIBMESH_WRAPPED_FUNCTION_H
21#define LIBMESH_WRAPPED_FUNCTION_H
24#include "libmesh/dense_vector.h"
25#include "libmesh/equation_systems.h"
26#include "libmesh/function_base.h"
27#include "libmesh/libmesh_common.h"
28#include "libmesh/point.h"
29#include "libmesh/system.h"
30#include "libmesh/fe_interface.h"
31#include "libmesh/variable.h"
52template <
typename Output=Number>
63 const std::string & sys_name,
64 const std::string & unknown_name) =
nullptr,
66 unsigned int varnum=0)
90 virtual std::unique_ptr<FunctionBase<Output>>
clone ()
const override;
93 const Real time = 0.)
override;
101 Real time=0.)
override;
109 const std::string & sys_name,
110 const std::string & unknown_name);
122template <
typename Output>
132 _sys.variable_name(_varnum));
136template <
typename Output>
138std::unique_ptr<FunctionBase<Output>>
141 return std::make_unique<WrappedFunction<Output>>
142 (_sys, _fptr, _parameters, _varnum);
146template <
typename Output>
157 libmesh_assert_equal_to (output.
size(), _sys.n_components());
161 const unsigned int n_vars = _sys.n_vars();
162 for (
unsigned int v = 0; v !=
n_vars; ++v)
164 const auto n_components =
165 _sys.variable(v).n_components(_sys.get_mesh());
166 if (n_components == 1)
167 output(_sys.variable_scalar_number(v,0)) =
168 _fptr(p, *_parameters, _sys.name(), _sys.variable_name(v));
173 libmesh_assert_equal_to (_sys.variable(v).type().family,
SCALAR);
178 for (
unsigned int j=0; j != n_components; ++j)
179 output(_sys.variable_scalar_number(v,j)) =
180 _fptr(
Point(j,0,0), *_parameters,
181 _sys.name(), _sys.variable_name(v));
187template <
typename Output>
199 const unsigned int n_vars = _sys.n_vars();
200 for (
unsigned int v = 0; v !=
n_vars; ++v)
202 const auto & var_fe_type = _sys.variable_type(v);
203 const auto n_components = _sys.variable(v).n_components(_sys.get_mesh());
204 if (i >= vc + n_components)
210 if (n_components > 1 && var_fe_type.family !=
SCALAR)
212 "WrappedFunction::component cannot currently evaluate vector finite element families");
214 if (n_components == 1)
215 return _fptr(p, *_parameters, _sys.name(), _sys.variable_name(v));
218 libmesh_assert_equal_to (_sys.variable(i).type().family,
SCALAR);
223 for (
unsigned int j=0; j != n_components; ++j)
225 return _fptr(
Point(j,0,0), *_parameters,
226 _sys.name(), _sys.variable_name(v));
230 libmesh_error_msg(
"Component index " << i <<
" not found in system " << _sys.name());
Defines a dense vector for use in Finite Element-type computations.
virtual unsigned int size() const override final
Parameters parameters
Data structure holding arbitrary parameters.
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...
This class provides the ability to map between arbitrary, user-defined strings and several data types...
A Point defines a location in LIBMESH_DIM dimensional Real space.
Manages consistently variables, degrees of freedom, and coefficient vectors.
const EquationSystems & get_equation_systems() const
Wrap a libMesh-style function pointer into a FunctionBase object.
WrappedFunction & operator=(const WrappedFunction &)=delete
This class contains a const reference so it can't be assigned.
const Parameters * _parameters
virtual Output operator()(const Point &p, const Real time=0.) override
virtual Output component(unsigned int i, const Point &p, Real time=0.) override
virtual ~WrappedFunction()=default
WrappedFunction(const System &sys, Output fptr(const Point &p, const Parameters ¶meters, const std::string &sys_name, const std::string &unknown_name)=nullptr, const Parameters *parameters=nullptr, unsigned int varnum=0)
Constructor to wrap scalar-valued function pointers.
WrappedFunction(WrappedFunction &&)=default
The move/copy ctor and destructor are defaulted for this class.
Output(* _fptr)(const Point &p, const Parameters ¶meters, const std::string &sys_name, const std::string &unknown_name)
WrappedFunction(const WrappedFunction &)=default
virtual std::unique_ptr< FunctionBase< Output > > clone() const override
The libMesh namespace provides an interface to certain functionality in the library.
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)