libMesh
Public Member Functions | Protected Attributes | List of all members
libMesh::WrappedFunction< Output > Class Template Reference

This class provides a wrapper with which to evaluate a (libMesh-style) function pointer in a FunctionBase-compatible interface. More...

#include <wrapped_function.h>

Inheritance diagram for libMesh::WrappedFunction< Output >:
[legend]

Public Member Functions

 WrappedFunction (const System &sys, Output fptr(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)=libmesh_nullptr, const Parameters *parameters=libmesh_nullptr, unsigned int varnum=0)
 Constructor to wrap scalar-valued function pointers. More...
 
virtual UniquePtr< FunctionBase< Output > > clone () const libmesh_override
 
virtual Output operator() (const Point &p, const Real time=0.) libmesh_override
 
virtual void operator() (const Point &p, const Real time, DenseVector< Output > &output) libmesh_override
 Evaluation function for time-dependent vector-valued functions. More...
 
virtual Output component (unsigned int i, const Point &p, Real time=0.) libmesh_override
 
virtual void init ()
 The actual initialization process. More...
 
virtual void clear ()
 Clears the function. More...
 
void operator() (const Point &p, DenseVector< Output > &output)
 Evaluation function for time-independent vector-valued functions. More...
 
bool initialized () const
 
void set_is_time_dependent (bool is_time_dependent)
 Function to set whether this is a time-dependent function or not. More...
 
bool is_time_dependent () const
 

Protected Attributes

const System_sys
 
Output(* _fptr )(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
 
const Parameters_parameters
 
unsigned int _varnum
 
const FunctionBase_master
 Const pointer to our master, initialized to NULL. More...
 
bool _initialized
 When init() was called so that everything is ready for calls to operator() (...), then this bool is true. More...
 
bool _is_time_dependent
 Cache whether or not this function is actually time-dependent. More...
 

Detailed Description

template<typename Output = Number>
class libMesh::WrappedFunction< Output >

This class provides a wrapper with which to evaluate a (libMesh-style) function pointer in a FunctionBase-compatible interface.

All overridden virtual functions are documented in function_base.h.

Author
Roy Stogner
Date
2012

Definition at line 47 of file wrapped_function.h.

Constructor & Destructor Documentation

template<typename Output = Number>
libMesh::WrappedFunction< Output >::WrappedFunction ( const System sys,
Output   fptrconst Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name = libmesh_nullptr,
const Parameters parameters = libmesh_nullptr,
unsigned int  varnum = 0 
)

Constructor to wrap scalar-valued function pointers.

Definition at line 54 of file wrapped_function.h.

References libMesh::FunctionBase< Output >::_initialized, libMesh::WrappedFunction< Output >::_parameters, libMesh::WrappedFunction< Output >::clone(), libMesh::WrappedFunction< Output >::component(), libMesh::System::get_equation_systems(), libMesh::WrappedFunction< Output >::operator()(), libMesh::EquationSystems::parameters, and libMesh::Real.

61  : _sys(sys),
62  _fptr(fptr),
63  _parameters(parameters),
64  _varnum(varnum)
65  {
66  this->_initialized = true;
67  if (!parameters)
69  }
Output(* _fptr)(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
ImplicitSystem & sys
bool _initialized
When init() was called so that everything is ready for calls to operator() (...), then this bool is t...
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:78
const Parameters * _parameters
const EquationSystems & get_equation_systems() const
Definition: system.h:712
Parameters parameters
Data structure holding arbitrary parameters.

Member Function Documentation

template<typename Output = Number>
virtual void libMesh::FunctionBase< Output >::clear ( )
virtualinherited
template<typename Output >
UniquePtr< FunctionBase< Output > > libMesh::WrappedFunction< Output >::clone ( ) const
virtual
Returns
A new copy of the function.

The new copy should be as "deep" as necessary to allow independent destruction and simultaneous evaluations of the copies in different threads.

Implements libMesh::FunctionBase< Output >.

Definition at line 120 of file wrapped_function.h.

References libMesh::WrappedFunction< Output >::_fptr, libMesh::WrappedFunction< Output >::_parameters, libMesh::WrappedFunction< Output >::_sys, and libMesh::WrappedFunction< Output >::_varnum.

Referenced by libMesh::WrappedFunction< Output >::WrappedFunction().

121 {
122  return UniquePtr<FunctionBase<Output>>
123  (new WrappedFunction<Output>
125 }
Output(* _fptr)(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
const Parameters * _parameters
template<typename Output >
Output libMesh::WrappedFunction< Output >::component ( unsigned int  i,
const Point p,
Real  time = 0. 
)
virtual
Returns
The vector component i at coordinate p and time time.
Note
Subclasses aren't required to override this, since the default implementation is based on the full vector evaluation, which is often correct.
Subclasses are recommended to override this, since the default implementation is based on a vector evaluation, which is usually unnecessarily inefficient.

Reimplemented from libMesh::FunctionBase< Output >.

Definition at line 171 of file wrapped_function.h.

References libMesh::WrappedFunction< Output >::_fptr, libMesh::WrappedFunction< Output >::_parameters, libMesh::WrappedFunction< Output >::_sys, libMesh::FEType::family, libMesh::libmesh_assert(), libMesh::Variable::n_components(), n_vars, libMesh::System::n_vars(), libMesh::System::name(), libMesh::SCALAR, libMesh::Variable::type(), libMesh::System::variable(), libMesh::System::variable_name(), and libMesh::System::variable_scalar_number().

Referenced by libMesh::WrappedFunction< Output >::WrappedFunction().

174 {
177 
178  // Loop over variables, then over each component in
179  // vector-valued variables.
180  const unsigned int n_vars = _sys.n_vars();
181  for (unsigned int v = 0; v != n_vars; ++v)
182  {
183  const unsigned int n_components =
185  if (n_components == 1 &&
186  i == _sys.variable_scalar_number(v,0))
187  return _fptr(p, *_parameters, _sys.name(), _sys.variable_name(v));
188  else if (i >= _sys.variable_scalar_number(v,0) &&
189  i <= _sys.variable_scalar_number(v,n_components-1))
190  {
191  // Right now our only non-scalar variable type is the
192  // SCALAR variables. The irony is priceless.
193  libmesh_assert_equal_to (_sys.variable(i).type().family, SCALAR);
194 
195  // We pass the point (j,0,0) to an old-style fptr function
196  // pointer to distinguish the different scalars within the
197  // SCALAR variable.
198  for (unsigned int j=0; j != n_components; ++j)
199  if (i == _sys.variable_scalar_number(v,j))
200  return _fptr(Point(j,0,0), *_parameters,
201  _sys.name(), _sys.variable_name(v));
202  }
203  }
204 
205  libmesh_error_msg("Component index " << i << " not found in system " << _sys.name());
206  return Output();
207 }
FEFamily family
The type of finite element.
Definition: fe_type.h:203
const FEType & type() const
Definition: variable.h:119
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2134
Output(* _fptr)(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
const unsigned int n_vars
Definition: tecplot_io.C:68
const std::string & name() const
Definition: system.h:1998
libmesh_assert(j)
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.h:2114
unsigned int n_components() const
Definition: variable.h:125
const Parameters * _parameters
unsigned int variable_scalar_number(const std::string &var, unsigned int component) const
Definition: system.h:2145
unsigned int n_vars() const
Definition: system.h:2086
template<typename Output = Number>
virtual void libMesh::FunctionBase< Output >::init ( )
virtualinherited
template<typename Output >
bool libMesh::FunctionBase< Output >::initialized ( ) const
inherited
Returns
true when this object is properly initialized and ready for use, false otherwise.

Definition at line 208 of file function_base.h.

References libMesh::FunctionBase< Output >::_initialized.

Referenced by libMesh::FunctionBase< Real >::clear(), and libMesh::AnalyticFunction< Output >::operator()().

209 {
210  return (this->_initialized);
211 }
bool _initialized
When init() was called so that everything is ready for calls to operator() (...), then this bool is t...
template<typename Output >
bool libMesh::FunctionBase< Output >::is_time_dependent ( ) const
inherited
template<typename Output >
Output libMesh::WrappedFunction< Output >::operator() ( const Point p,
const Real  time = 0. 
)
virtual
Returns
The scalar function value at coordinate p and time time, which defaults to zero.

Pure virtual, so you have to override it.

Implements libMesh::FunctionBase< Output >.

Definition at line 105 of file wrapped_function.h.

References libMesh::WrappedFunction< Output >::_fptr, libMesh::WrappedFunction< Output >::_parameters, libMesh::WrappedFunction< Output >::_sys, libMesh::WrappedFunction< Output >::_varnum, libMesh::libmesh_assert(), libMesh::System::name(), and libMesh::System::variable_name().

Referenced by libMesh::WrappedFunction< Output >::WrappedFunction().

107 {
110  return _fptr(p,
111  *_parameters,
112  _sys.name(),
114 }
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2134
Output(* _fptr)(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
const std::string & name() const
Definition: system.h:1998
libmesh_assert(j)
const Parameters * _parameters
template<typename Output >
void libMesh::WrappedFunction< Output >::operator() ( const Point p,
const Real  time,
DenseVector< Output > &  output 
)
virtual

Evaluation function for time-dependent vector-valued functions.

Sets output values in the passed-in output DenseVector.

Pure virtual, so you have to override it.

Implements libMesh::FunctionBase< Output >.

Definition at line 130 of file wrapped_function.h.

References libMesh::WrappedFunction< Output >::_fptr, libMesh::WrappedFunction< Output >::_parameters, libMesh::WrappedFunction< Output >::_sys, libMesh::FEType::family, libMesh::libmesh_assert(), libMesh::Variable::n_components(), libMesh::System::n_components(), n_vars, libMesh::System::n_vars(), libMesh::System::name(), libMesh::SCALAR, libMesh::DenseVector< T >::size(), libMesh::Variable::type(), libMesh::System::variable(), libMesh::System::variable_name(), and libMesh::System::variable_scalar_number().

133 {
136 
137  // We fill each entry of output with a single scalar component of
138  // the data in our System
139  libmesh_assert_equal_to (output.size(), _sys.n_components());
140 
141  // Loop over variables, then over each component in
142  // vector-valued variables, evaluating each.
143  const unsigned int n_vars = _sys.n_vars();
144  for (unsigned int v = 0; v != n_vars; ++v)
145  {
146  const unsigned int n_components =
148  if (n_components == 1)
149  output(_sys.variable_scalar_number(v,0)) =
151  else
152  {
153  // Right now our only non-scalar variable type is the
154  // SCALAR variables. The irony is priceless.
155  libmesh_assert_equal_to (_sys.variable(v).type().family, SCALAR);
156 
157  // We pass the point (j,0,0) to an old-style fptr function
158  // pointer to distinguish the different scalars within the
159  // SCALAR variable.
160  for (unsigned int j=0; j != n_components; ++j)
161  output(_sys.variable_scalar_number(v,j)) =
162  _fptr(Point(j,0,0), *_parameters,
163  _sys.name(), _sys.variable_name(v));
164  }
165  }
166 }
FEFamily family
The type of finite element.
Definition: fe_type.h:203
const FEType & type() const
Definition: variable.h:119
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2134
Output(* _fptr)(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
const unsigned int n_vars
Definition: tecplot_io.C:68
const std::string & name() const
Definition: system.h:1998
libmesh_assert(j)
unsigned int n_components() const
Definition: system.h:2102
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.h:2114
unsigned int n_components() const
Definition: variable.h:125
const Parameters * _parameters
unsigned int variable_scalar_number(const std::string &var, unsigned int component) const
Definition: system.h:2145
unsigned int n_vars() const
Definition: system.h:2086
template<typename Output>
void libMesh::FunctionBase< Output >::operator() ( const Point p,
DenseVector< Output > &  output 
)
inherited

Evaluation function for time-independent vector-valued functions.

Sets output values in the passed-in output DenseVector.

Definition at line 243 of file function_base.h.

References libMesh::FunctionBase< Output >::operator()().

245 {
246  // Call the time-dependent function with t=0.
247  this->operator()(p, 0., output);
248 }
virtual Output operator()(const Point &p, const Real time=0.)=0
template<typename Output >
void libMesh::FunctionBase< Output >::set_is_time_dependent ( bool  is_time_dependent)
inherited

Function to set whether this is a time-dependent function or not.

This is intended to be only used by subclasses who cannot natively determine time-dependence. In such a case, this function should be used immediately following construction.

Definition at line 215 of file function_base.h.

References libMesh::FunctionBase< Output >::_is_time_dependent, and libMesh::FunctionBase< Output >::is_time_dependent().

Referenced by libMesh::FunctionBase< Real >::clear().

216 {
218 }
bool is_time_dependent() const
bool _is_time_dependent
Cache whether or not this function is actually time-dependent.

Member Data Documentation

template<typename Output = Number>
Output(* libMesh::WrappedFunction< Output >::_fptr) (const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
protected
template<typename Output = Number>
bool libMesh::FunctionBase< Output >::_initialized
protectedinherited
template<typename Output = Number>
bool libMesh::FunctionBase< Output >::_is_time_dependent
protectedinherited
template<typename Output = Number>
const FunctionBase* libMesh::FunctionBase< Output >::_master
protectedinherited

Const pointer to our master, initialized to NULL.

There may be cases where multiple functions are required, but to save memory, one master handles some centralized data.

Definition at line 168 of file function_base.h.

template<typename Output = Number>
const Parameters* libMesh::WrappedFunction< Output >::_parameters
protected
template<typename Output = Number>
const System& libMesh::WrappedFunction< Output >::_sys
protected
template<typename Output = Number>
unsigned int libMesh::WrappedFunction< Output >::_varnum
protected

The documentation for this class was generated from the following file: