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)=nullptr, const Parameters *parameters=nullptr, unsigned int varnum=0)
 Constructor to wrap scalar-valued function pointers. More...
 
 WrappedFunction (WrappedFunction &&)=default
 The move/copy ctor and destructor are defaulted for this class. More...
 
 WrappedFunction (const WrappedFunction &)=default
 
virtual ~WrappedFunction ()=default
 
WrappedFunctionoperator= (const WrappedFunction &)=delete
 This class contains a const reference so it can't be assigned. More...
 
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
 Evaluation function for time-dependent vector-valued functions. More...
 
virtual Output component (unsigned int i, const Point &p, Real time=0.) 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 nullptr. 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

◆ 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 
)

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::System::get_equation_systems(), and libMesh::EquationSystems::parameters.

61  : _sys(sys),
62  _fptr(fptr),
63  _parameters(parameters),
64  _varnum(varnum)
65  {
66  this->_initialized = true;
67  if (!parameters)
68  _parameters = &sys.get_equation_systems().parameters;
69  }
Output(* _fptr)(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
bool _initialized
When init() was called so that everything is ready for calls to operator() (...), then this bool is t...
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 ( )
virtualinherited

◆ clone()

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

134 {
135  return std::unique_ptr<FunctionBase<Output>>
136  (new WrappedFunction<Output>
138 }
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. 
)
overridevirtual
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 184 of file wrapped_function.h.

References libMesh::SCALAR.

187 {
188  libmesh_assert(_fptr);
189  libmesh_assert(_parameters);
190 
191  // Loop over variables, then over each component in
192  // vector-valued variables.
193  const unsigned int n_vars = _sys.n_vars();
194  for (unsigned int v = 0; v != n_vars; ++v)
195  {
196  const unsigned int n_components =
198  if (n_components == 1 &&
199  i == _sys.variable_scalar_number(v,0))
200  return _fptr(p, *_parameters, _sys.name(), _sys.variable_name(v));
201  else if (i >= _sys.variable_scalar_number(v,0) &&
202  i <= _sys.variable_scalar_number(v,n_components-1))
203  {
204  // Right now our only non-scalar variable type is the
205  // SCALAR variables. The irony is priceless.
206  libmesh_assert_equal_to (_sys.variable(i).type().family, SCALAR);
207 
208  // We pass the point (j,0,0) to an old-style fptr function
209  // pointer to distinguish the different scalars within the
210  // SCALAR variable.
211  for (unsigned int j=0; j != n_components; ++j)
212  if (i == _sys.variable_scalar_number(v,j))
213  return _fptr(Point(j,0,0), *_parameters,
214  _sys.name(), _sys.variable_name(v));
215  }
216  }
217 
218  libmesh_error_msg("Component index " << i << " not found in system " << _sys.name());
219  return Output();
220 }
FEFamily family
The type of finite element.
Definition: fe_type.h:204
unsigned int variable_scalar_number(const std::string &var, unsigned int component) const
Definition: system.h:2157
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.h:2126
Output(* _fptr)(const Point &p, const Parameters &parameters, const std::string &sys_name, const std::string &unknown_name)
unsigned int n_components() const
Definition: variable.h:125
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2146
const Parameters * _parameters
const std::string & name() const
Definition: system.h:2010
unsigned int n_vars() const
Definition: system.h:2098
const FEType & type() const
Definition: variable.h:119

◆ init()

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

◆ initialized()

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

206 {
207  return (this->_initialized);
208 }
bool _initialized
When init() was called so that everything is ready for calls to operator() (...), then this bool is t...

◆ is_time_dependent()

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

Definition at line 219 of file function_base.h.

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

220 {
221  return (this->_is_time_dependent);
222 }
bool _is_time_dependent
Cache whether or not this function is actually time-dependent.

◆ operator()() [1/3]

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

120 {
121  libmesh_assert(_fptr);
122  libmesh_assert(_parameters);
123  return _fptr(p,
124  *_parameters,
125  _sys.name(),
127 }
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:2146
const Parameters * _parameters
const std::string & name() const
Definition: system.h:2010

◆ operator()() [2/3]

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

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

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

146 {
147  libmesh_assert(_fptr);
148  libmesh_assert(_parameters);
149 
150  // We fill each entry of output with a single scalar component of
151  // the data in our System
152  libmesh_assert_equal_to (output.size(), _sys.n_components());
153 
154  // Loop over variables, then over each component in
155  // vector-valued variables, evaluating each.
156  const unsigned int n_vars = _sys.n_vars();
157  for (unsigned int v = 0; v != n_vars; ++v)
158  {
159  const unsigned int n_components =
161  if (n_components == 1)
162  output(_sys.variable_scalar_number(v,0)) =
164  else
165  {
166  // Right now our only non-scalar variable type is the
167  // SCALAR variables. The irony is priceless.
168  libmesh_assert_equal_to (_sys.variable(v).type().family, SCALAR);
169 
170  // We pass the point (j,0,0) to an old-style fptr function
171  // pointer to distinguish the different scalars within the
172  // SCALAR variable.
173  for (unsigned int j=0; j != n_components; ++j)
174  output(_sys.variable_scalar_number(v,j)) =
175  _fptr(Point(j,0,0), *_parameters,
176  _sys.name(), _sys.variable_name(v));
177  }
178  }
179 }
virtual unsigned int size() const override
Definition: dense_vector.h:92
FEFamily family
The type of finite element.
Definition: fe_type.h:204
unsigned int variable_scalar_number(const std::string &var, unsigned int component) const
Definition: system.h:2157
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.h:2126
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:2114
unsigned int n_components() const
Definition: variable.h:125
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2146
const Parameters * _parameters
const std::string & name() const
Definition: system.h:2010
unsigned int n_vars() const
Definition: system.h:2098
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 
)
inherited

Evaluation function for time-independent vector-valued functions.

Sets output values in the passed-in output DenseVector.

Definition at line 240 of file function_base.h.

242 {
243  // Call the time-dependent function with t=0.
244  this->operator()(p, 0., output);
245 }
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)
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 212 of file function_base.h.

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

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 101 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 179 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 184 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 173 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 99 of file wrapped_function.h.

◆ _varnum

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

Definition at line 108 of file wrapped_function.h.


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