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" 51 template <
typename Output=Number>
62 const std::string & sys_name,
63 const std::string & unknown_name) =
nullptr,
65 unsigned int varnum=0)
89 virtual std::unique_ptr<FunctionBase<Output>>
clone ()
const override;
92 const Real time = 0.)
override;
100 Real time=0.)
override;
108 const std::string & sys_name,
109 const std::string & unknown_name);
121 template <
typename Output>
131 _sys.variable_name(_varnum));
135 template <
typename Output>
137 std::unique_ptr<FunctionBase<Output>>
140 return std::make_unique<WrappedFunction<Output>>
141 (_sys, _fptr, _parameters, _varnum);
145 template <
typename Output>
156 libmesh_assert_equal_to (output.
size(), _sys.n_components());
160 const unsigned int n_vars = _sys.n_vars();
161 for (
unsigned int v = 0; v !=
n_vars; ++v)
163 const unsigned int n_components =
164 _sys.variable(v).n_components();
165 if (n_components == 1)
166 output(_sys.variable_scalar_number(v,0)) =
167 _fptr(p, *_parameters, _sys.name(), _sys.variable_name(v));
172 libmesh_assert_equal_to (_sys.variable(v).type().family,
SCALAR);
177 for (
unsigned int j=0; j != n_components; ++j)
178 output(_sys.variable_scalar_number(v,j)) =
179 _fptr(
Point(j,0,0), *_parameters,
180 _sys.name(), _sys.variable_name(v));
186 template <
typename Output>
198 const unsigned int n_vars = _sys.n_vars();
199 for (
unsigned int v = 0; v !=
n_vars; ++v)
201 const auto & var_fe_type = _sys.variable_type(v);
202 const unsigned int n_components = [&var_fe_type, v,
this](){
203 if (var_fe_type.family ==
SCALAR)
204 return _sys.variable(v).n_components();
208 if (i >= vc + n_components)
214 if (n_components > 1 && var_fe_type.family !=
SCALAR)
216 "WrappedFunction::component cannot currently evaluate vector finite element families");
218 if (n_components == 1)
219 return _fptr(p, *_parameters, _sys.name(), _sys.variable_name(v));
222 libmesh_assert_equal_to (_sys.variable(i).type().family,
SCALAR);
227 for (
unsigned int j=0; j != n_components; ++j)
229 return _fptr(
Point(j,0,0), *_parameters,
230 _sys.name(), _sys.variable_name(v));
234 libmesh_error_msg(
"Component index " << i <<
" not found in system " << _sys.name());
242 #endif // LIBMESH_WRAPPED_FUNCTION_H
Wrap a libMesh-style function pointer into a FunctionBase object.
virtual Output component(unsigned int i, const Point &p, Real time=0.) override
This class provides the ability to map between arbitrary, user-defined strings and several data types...
virtual Output operator()(const Point &p, const Real time=0.) override
Output(* _fptr)(const Point &p, const Parameters ¶meters, const std::string &sys_name, const std::string &unknown_name)
const EquationSystems & get_equation_systems() const
bool _initialized
When init() was called so that everything is ready for calls to operator() (...), then this bool is t...
The libMesh namespace provides an interface to certain functionality in the library.
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Manages consistently variables, degrees of freedom, and coefficient vectors.
virtual std::unique_ptr< FunctionBase< Output > > clone() const override
static unsigned int n_vec_dim(const MeshBase &mesh, const FEType &fe_type)
WrappedFunction & operator=(const WrappedFunction &)=delete
This class contains a const reference so it can't be assigned.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual ~WrappedFunction()=default
const Parameters * _parameters
Parameters parameters
Data structure holding arbitrary parameters.
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.
virtual unsigned int size() const override final
Base class for functors that can be evaluated at a point and (optionally) time.
A Point defines a location in LIBMESH_DIM dimensional Real space.