libMesh::WrappedFunction< Output > Class Template Reference

Wrap a libMesh-style function pointer into a FunctionBase object. More...

#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)=nullptr, const Parameters *parameters=nullptr, unsigned int varnum=0)
 
 WrappedFunction (WrappedFunction &&)=default
 
 WrappedFunction (const WrappedFunction &)=default
 
virtual ~WrappedFunction ()=default
 
WrappedFunctionoperator= (const WrappedFunction &)=delete
 
WrappedFunctionoperator= (WrappedFunction &&)=delete
 
virtual std::unique_ptr< FunctionBase< Output > > clone () const override
 
virtual Output operator() (const Point &p, const Real time=0.) override
 
virtual void operator() (const Point &p, const Real time, DenseVector< Output > &output) override
 
virtual Output component (unsigned int i, const Point &p, Real time=0.) 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 >

Wrap a libMesh-style function pointer into a FunctionBase object.

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
Note
To wrap an ordinary function pointer use the AnalyticFunction class.

Definition at line 50 of file wrapped_function.h.

Constructor & Destructor Documentation

◆ WrappedFunction() [1/3]

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 = nullptr,
const Parameters parameters = nullptr,
unsigned int  varnum = 0 
)
inline

Constructor to wrap scalar-valued function pointers.

Definition at line 57 of file wrapped_function.h.

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

64  : _sys(sys),
65  _fptr(fptr),
66  _parameters(parameters),
67  _varnum(varnum)
68  {
69  this->_initialized = true;
70  if (!parameters)
71  _parameters = &sys.get_equation_systems().parameters;
72  }
Output(* _fptr)(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
const Parameters * _parameters

◆ WrappedFunction() [2/3]

template<typename Output = Number>
libMesh::WrappedFunction< Output >::WrappedFunction ( WrappedFunction< Output > &&  )
default

The move/copy ctor and destructor are defaulted for this class.

◆ WrappedFunction() [3/3]

template<typename Output = Number>
libMesh::WrappedFunction< Output >::WrappedFunction ( const WrappedFunction< Output > &  )
default

◆ ~WrappedFunction()

template<typename Output = Number>
virtual libMesh::WrappedFunction< Output >::~WrappedFunction ( )
virtualdefault

Member Function Documentation

◆ clear()

template<typename Output = Number>
virtual void libMesh::FunctionBase< Output >::clear ( )
inlinevirtualinherited

◆ clone()

template<typename Output >
std::unique_ptr< FunctionBase< Output > > libMesh::WrappedFunction< Output >::clone ( ) const
inlineoverridevirtual
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 136 of file wrapped_function.h.

137 {
138  return std::unique_ptr<FunctionBase<Output>>
139  (new WrappedFunction<Output>
141 }
Output(* _fptr)(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
const Parameters * _parameters

◆ component()

template<typename Output >
Output libMesh::WrappedFunction< Output >::component ( unsigned int  i,
const Point p,
Real  time = 0. 
)
inlineoverridevirtual
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 187 of file wrapped_function.h.

References n_vars, and libMesh::SCALAR.

190 {
191  libmesh_assert(_fptr);
192  libmesh_assert(_parameters);
193 
194  // Loop over variables, then over each component in
195  // vector-valued variables.
196  const unsigned int n_vars = _sys.n_vars();
197  for (unsigned int v = 0; v != n_vars; ++v)
198  {
199  const unsigned int 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))
206  {
207  // Right now our only non-scalar variable type is the
208  // SCALAR variables. The irony is priceless.
209  libmesh_assert_equal_to (_sys.variable(i).type().family, SCALAR);
210 
211  // We pass the point (j,0,0) to an old-style fptr function
212  // pointer to distinguish the different scalars within the
213  // SCALAR variable.
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));
218  }
219  }
220 
221  libmesh_error_msg("Component index " << i << " not found in system " << _sys.name());
222  return Output();
223 }
FEFamily family
Definition: fe_type.h:204
unsigned int variable_scalar_number(const std::string &var, unsigned int component) const
Definition: system.h:2164
const Variable & variable(unsigned int var) const
Definition: system.h:2133
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:69
unsigned int n_components() const
Definition: variable.h:125
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2153
const Parameters * _parameters
const std::string & name() const
Definition: system.h:2017
unsigned int n_vars() const
Definition: system.h:2105
const FEType & type() const
Definition: variable.h:119

◆ init()

template<typename Output = Number>
virtual void libMesh::FunctionBase< Output >::init ( )
inlinevirtualinherited

◆ initialized()

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 206 of file function_base.h.

207 {
208  return (this->_initialized);
209 }

◆ is_time_dependent()

template<typename Output >
bool libMesh::FunctionBase< Output >::is_time_dependent ( ) const
inlineinherited
Returns
true when the function this object represents is actually time-dependent, false otherwise.

Definition at line 220 of file function_base.h.

Referenced by libMesh::CompositeFunction< Output >::attach_subfunction().

221 {
222  return (this->_is_time_dependent);
223 }

◆ operator()() [1/3]

template<typename Output >
Output libMesh::WrappedFunction< Output >::operator() ( const Point p,
const Real  time = 0. 
)
inlineoverridevirtual
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 121 of file wrapped_function.h.

123 {
124  libmesh_assert(_fptr);
125  libmesh_assert(_parameters);
126  return _fptr(p,
127  *_parameters,
128  _sys.name(),
130 }
Output(* _fptr)(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2153
const Parameters * _parameters
const std::string & name() const
Definition: system.h:2017

◆ operator()() [2/3]

template<typename Output >
void libMesh::WrappedFunction< Output >::operator() ( const Point p,
const Real  time,
DenseVector< Output > &  output 
)
inlineoverridevirtual

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 146 of file wrapped_function.h.

References n_vars, libMesh::SCALAR, and libMesh::DenseVector< T >::size().

149 {
150  libmesh_assert(_fptr);
151  libmesh_assert(_parameters);
152 
153  // We fill each entry of output with a single scalar component of
154  // the data in our System
155  libmesh_assert_equal_to (output.size(), _sys.n_components());
156 
157  // Loop over variables, then over each component in
158  // vector-valued variables, evaluating each.
159  const unsigned int n_vars = _sys.n_vars();
160  for (unsigned int v = 0; v != n_vars; ++v)
161  {
162  const unsigned int n_components =
164  if (n_components == 1)
165  output(_sys.variable_scalar_number(v,0)) =
167  else
168  {
169  // Right now our only non-scalar variable type is the
170  // SCALAR variables. The irony is priceless.
171  libmesh_assert_equal_to (_sys.variable(v).type().family, SCALAR);
172 
173  // We pass the point (j,0,0) to an old-style fptr function
174  // pointer to distinguish the different scalars within the
175  // SCALAR variable.
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));
180  }
181  }
182 }
virtual unsigned int size() const override
Definition: dense_vector.h:92
FEFamily family
Definition: fe_type.h:204
unsigned int variable_scalar_number(const std::string &var, unsigned int component) const
Definition: system.h:2164
const Variable & variable(unsigned int var) const
Definition: system.h:2133
Output(* _fptr)(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
unsigned int n_components() const
Definition: system.h:2121
const unsigned int n_vars
Definition: tecplot_io.C:69
unsigned int n_components() const
Definition: variable.h:125
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2153
const Parameters * _parameters
const std::string & name() const
Definition: system.h:2017
unsigned int n_vars() const
Definition: system.h:2105
const FEType & type() const
Definition: variable.h:119

◆ operator()() [3/3]

template<typename Output>
void libMesh::FunctionBase< Output >::operator() ( const Point p,
DenseVector< Output > &  output 
)
inlineinherited

Evaluation function for time-independent vector-valued functions. Sets output values in the passed-in output DenseVector.

Definition at line 241 of file function_base.h.

243 {
244  // Call the time-dependent function with t=0.
245  this->operator()(p, 0., output);
246 }
virtual Output operator()(const Point &p, const Real time=0.)=0

◆ operator=() [1/2]

template<typename Output = Number>
WrappedFunction& libMesh::WrappedFunction< Output >::operator= ( const WrappedFunction< Output > &  )
delete

This class contains a const reference so it can't be assigned.

◆ operator=() [2/2]

template<typename Output = Number>
WrappedFunction& libMesh::WrappedFunction< Output >::operator= ( WrappedFunction< Output > &&  )
delete

◆ set_is_time_dependent()

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 213 of file function_base.h.

214 {
216 }
bool is_time_dependent() const

Member Data Documentation

◆ _fptr

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

Definition at line 104 of file wrapped_function.h.

◆ _initialized

template<typename Output = Number>
bool libMesh::FunctionBase< Output >::_initialized
protectedinherited

When init() was called so that everything is ready for calls to operator() (...), then this bool is true.

Definition at line 180 of file function_base.h.

Referenced by libMesh::AnalyticFunction< Output >::AnalyticFunction(), libMesh::ConstFunction< Output >::ConstFunction(), and libMesh::WrappedFunction< Output >::WrappedFunction().

◆ _is_time_dependent

template<typename Output = Number>
bool libMesh::FunctionBase< Output >::_is_time_dependent
protectedinherited

Cache whether or not this function is actually time-dependent.

Definition at line 185 of file function_base.h.

Referenced by libMesh::CompositeFunction< Output >::attach_subfunction(), and libMesh::ConstFunction< Output >::ConstFunction().

◆ _master

template<typename Output = Number>
const FunctionBase* libMesh::FunctionBase< Output >::_master
protectedinherited

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

Definition at line 174 of file function_base.h.

◆ _parameters

template<typename Output = Number>
const Parameters* libMesh::WrappedFunction< Output >::_parameters
protected

◆ _sys

template<typename Output = Number>
const System& libMesh::WrappedFunction< Output >::_sys
protected

Definition at line 102 of file wrapped_function.h.

◆ _varnum

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

Definition at line 111 of file wrapped_function.h.


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