libMesh::WrappedFunction< Output > Class Template Reference

#include <wrapped_function.h>

Inheritance diagram for libMesh::WrappedFunction< Output >:

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)
 
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
 
virtual Output component (unsigned int i, const Point &p, Real time=0.) libmesh_override
 
virtual void init ()
 
virtual void clear ()
 
void operator() (const Point &p, DenseVector< Output > &output)
 
bool initialized () const
 
void set_is_time_dependent (bool is_time_dependent)
 
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
 
bool _initialized
 
bool _is_time_dependent
 

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.

Author
Roy Stogner
Date
2012

Definition at line 46 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 
)
inline

Constructor to wrap scalar-valued function pointers.

Definition at line 53 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.

60  : _sys(sys),
61  _fptr(fptr),
62  _parameters(parameters),
63  _varnum(varnum)
64  {
65  this->_initialized = true;
66  if (!parameters)
68  }
Output(* _fptr)(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
ImplicitSystem & sys
const Parameters * _parameters
const EquationSystems & get_equation_systems() const
Definition: system.h:711

Member Function Documentation

template<typename Output = Number>
virtual void libMesh::FunctionBase< Output >::clear ( )
inlinevirtualinherited
template<typename Output >
UniquePtr< FunctionBase< Output > > libMesh::WrappedFunction< Output >::clone ( ) const
inlinevirtual

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 132 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().

133 {
134  return UniquePtr<FunctionBase<Output> >
135  (new WrappedFunction<Output>
137 }
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. 
)
inlinevirtual
Returns
the vector component i at coordinate p and time time.

Reimplemented from libMesh::FunctionBase< Output >.

Definition at line 192 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().

195 {
198 
199  // Loop over variables, then over each component in
200  // vector-valued variables.
201  const unsigned int n_vars = _sys.n_vars();
202  for (unsigned int v = 0; v != n_vars; ++v)
203  {
204  const unsigned int n_components =
206  if (n_components == 1 &&
207  i == _sys.variable_scalar_number(v,0))
208  return _fptr(p, *_parameters, _sys.name(), _sys.variable_name(v));
209  else if (i >= _sys.variable_scalar_number(v,0) &&
210  i <= _sys.variable_scalar_number(v,n_components-1))
211  {
212  // Right now our only non-scalar variable type is the
213  // SCALAR variables. The irony is priceless.
214  libmesh_assert_equal_to (_sys.variable(i).type().family, SCALAR);
215 
216  // We pass the point (j,0,0) to an old-style fptr function
217  // pointer to distinguish the different scalars within the
218  // SCALAR variable.
219  for (unsigned int j=0; j != n_components; ++j)
220  if (i == _sys.variable_scalar_number(v,j))
221  return _fptr(Point(j,0,0), *_parameters,
222  _sys.name(), _sys.variable_name(v));
223  }
224  }
225 
226  libmesh_error_msg("Component index " << i << " not found in system " << _sys.name());
227  return Output();
228 }
FEFamily family
Definition: fe_type.h:206
const FEType & type() const
Definition: variable.h:119
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2123
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:1987
libmesh_assert(j)
const Variable & variable(unsigned int var) const
Definition: system.h:2103
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:2134
unsigned int n_vars() const
Definition: system.h:2075
template<typename Output = Number>
virtual void libMesh::FunctionBase< Output >::init ( )
inlinevirtualinherited
template<typename Output >
bool libMesh::FunctionBase< Output >::initialized ( ) const
inlineinherited
Returns
true when this object is properly initialized and ready for use, false otherwise.

Definition at line 212 of file function_base.h.

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

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

213 {
214  return (this->_initialized);
215 }
template<typename Output >
bool libMesh::FunctionBase< Output >::is_time_dependent ( ) const
inlineinherited
template<typename Output >
Output libMesh::WrappedFunction< Output >::operator() ( const Point p,
const Real  time = 0. 
)
inlinevirtual
Returns
the scalar value of variable varnum at coordinate p and time time.

Implements libMesh::FunctionBase< Output >.

Definition at line 117 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().

119 {
122  return _fptr(p,
123  *_parameters,
124  _sys.name(),
126 }
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2123
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:1987
libmesh_assert(j)
const Parameters * _parameters
template<typename Output >
void libMesh::WrappedFunction< Output >::operator() ( const Point p,
const Real  time,
DenseVector< Output > &  output 
)
inlinevirtual

Return function for vectors. Returns in output the values of all system variables at the coordinate p and for time time.

Implements libMesh::FunctionBase< Output >.

Definition at line 147 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().

150 {
153 
154  // We fill each entry of output with a single scalar component of
155  // the data in our System
156  libmesh_assert_equal_to (output.size(), _sys.n_components());
157 
158  // Loop over variables, then over each component in
159  // vector-valued variables, evaluating each.
160  const unsigned int n_vars = _sys.n_vars();
161  for (unsigned int v = 0; v != n_vars; ++v)
162  {
163  const unsigned int n_components =
165  if (n_components == 1)
166  output(_sys.variable_scalar_number(v,0)) =
168  else
169  {
170  // Right now our only non-scalar variable type is the
171  // SCALAR variables. The irony is priceless.
172  libmesh_assert_equal_to (_sys.variable(v).type().family, SCALAR);
173 
174  // We pass the point (j,0,0) to an old-style fptr function
175  // pointer to distinguish the different scalars within the
176  // SCALAR variable.
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));
181  }
182  }
183 }
FEFamily family
Definition: fe_type.h:206
const FEType & type() const
Definition: variable.h:119
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2123
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:1987
libmesh_assert(j)
unsigned int n_components() const
Definition: system.h:2091
const Variable & variable(unsigned int var) const
Definition: system.h:2103
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:2134
unsigned int n_vars() const
Definition: system.h:2075
template<typename Output>
void libMesh::FunctionBase< Output >::operator() ( const Point p,
DenseVector< Output > &  output 
)
inlineinherited

Return function for vectors. Returns in output the values of the data at the coordinate p.

Definition at line 247 of file function_base.h.

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

249 {
250  // Call the time-dependent function with t=0.
251  this->operator()(p, 0., output);
252 }
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)
inlineinherited

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 219 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().

220 {
222 }
bool is_time_dependent() const

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 >::_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 172 of file function_base.h.

template<typename Output = Number>
unsigned int libMesh::WrappedFunction< Output >::_varnum
protected

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