20 #ifndef LIBMESH_WRAPPED_FUNCTION_H 21 #define LIBMESH_WRAPPED_FUNCTION_H 49 template <
typename Output=Number>
58 Output fptr(
const Point & p,
60 const std::string & sys_name,
61 const std::string & unknown_name) =
nullptr,
63 unsigned int varnum=0)
87 virtual std::unique_ptr<FunctionBase<Output>>
clone ()
const override;
90 const Real time = 0.)
override;
98 Real time=0.)
override;
106 const std::string & sys_name,
107 const std::string & unknown_name);
119 template <
typename Output>
124 libmesh_assert(_fptr);
125 libmesh_assert(_parameters);
129 _sys.variable_name(_varnum));
133 template <
typename Output>
135 std::unique_ptr<FunctionBase<Output>>
138 return std::unique_ptr<FunctionBase<Output>>
140 (_sys, _fptr, _parameters, _varnum));
144 template <
typename Output>
150 libmesh_assert(_fptr);
151 libmesh_assert(_parameters);
155 libmesh_assert_equal_to (output.
size(), _sys.n_components());
159 const unsigned int n_vars = _sys.n_vars();
160 for (
unsigned int v = 0; v !=
n_vars; ++v)
162 const unsigned int n_components =
163 _sys.variable(v).n_components();
164 if (n_components == 1)
165 output(_sys.variable_scalar_number(v,0)) =
166 _fptr(p, *_parameters, _sys.name(), _sys.variable_name(v));
171 libmesh_assert_equal_to (_sys.variable(v).type().family,
SCALAR);
176 for (
unsigned int j=0; j != n_components; ++j)
177 output(_sys.variable_scalar_number(v,j)) =
178 _fptr(
Point(j,0,0), *_parameters,
179 _sys.name(), _sys.variable_name(v));
185 template <
typename Output>
191 libmesh_assert(_fptr);
192 libmesh_assert(_parameters);
196 const unsigned int n_vars = _sys.n_vars();
197 for (
unsigned int v = 0; v !=
n_vars; ++v)
199 const unsigned int n_components =
200 _sys.variable(v).n_components();
201 if (n_components == 1 &&
202 i == _sys.variable_scalar_number(v,0))
203 return _fptr(p, *_parameters, _sys.name(), _sys.variable_name(v));
204 else if (i >= _sys.variable_scalar_number(v,0) &&
205 i <= _sys.variable_scalar_number(v,n_components-1))
209 libmesh_assert_equal_to (_sys.variable(i).type().family,
SCALAR);
214 for (
unsigned int j=0; j != n_components; ++j)
215 if (i == _sys.variable_scalar_number(v,j))
216 return _fptr(
Point(j,0,0), *_parameters,
217 _sys.name(), _sys.variable_name(v));
221 libmesh_error_msg(
"Component index " << i <<
" not found in system " << _sys.name());
229 #endif // LIBMESH_WRAPPED_FUNCTION_H
virtual unsigned int size() const override
Wrap a libMesh-style function pointer into a FunctionBase object.
virtual Output component(unsigned int i, const Point &p, Real time=0.) override
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
const unsigned int n_vars
Manages consistently variables, degrees of freedom, and coefficient vectors.
virtual std::unique_ptr< FunctionBase< Output > > clone() const override
WrappedFunction & operator=(const WrappedFunction &)=delete
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual ~WrappedFunction()=default
const Parameters * _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)
Base class for functors that can be evaluated at a point and (optionally) time.
A geometric point in (x,y,z) space.