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)=NULL, const Parameters *parameters=NULL, unsigned int varnum=0)
 
virtual AutoPtr< FunctionBase
< Output > > 
clone () const
 
virtual Output operator() (const Point &p, const Real time=0.)
 
virtual void operator() (const Point &p, const Real time, DenseVector< Output > &output)
 
virtual Output component (unsigned int i, const Point &p, Real time=0.)
 
virtual void init ()
 
virtual void clear ()
 
void operator() (const Point &p, DenseVector< Output > &output)
 
bool initialized () 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
 

Detailed Description

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

Definition at line 44 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 = NULL,
const Parameters parameters = NULL,
unsigned int  varnum = 0 
)
inline

Constructor to wrap scalar-valued function pointers.

Definition at line 51 of file wrapped_function.h.

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

58  : _sys(sys),
59  _fptr(fptr),
60  _parameters(parameters),
61  _varnum(varnum)
62  {
63  this->_initialized = true;
64  if (!parameters)
65  _parameters = &sys.get_equation_systems().parameters;
66  }

Member Function Documentation

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

Clears the function.

Reimplemented in libMesh::ParsedFunction< Output >, libMesh::MeshFunction, and libMesh::AnalyticFunction< Output >.

Definition at line 90 of file function_base.h.

90 {}
template<typename Output >
AutoPtr< 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 130 of file wrapped_function.h.

131 {
132  return AutoPtr<FunctionBase<Output> >
133  (new WrappedFunction<Output>
135 }
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 191 of file wrapped_function.h.

References libMesh::err, libMesh::libmesh_assert(), libMesh::n_vars, and libMeshEnums::SCALAR.

194 {
197 
198  // Loop over variables, then over each component in
199  // vector-valued variables.
200  const unsigned int n_vars = _sys.n_vars();
201  for (unsigned int v = 0; v != n_vars; ++v)
202  {
203  const unsigned int n_components =
205  if (n_components == 1 &&
206  i == _sys.variable_scalar_number(v,0))
207  return _fptr(p, *_parameters, _sys.name(), _sys.variable_name(v));
208  else if (i >= _sys.variable_scalar_number(v,0) &&
209  i <= _sys.variable_scalar_number(v,n_components-1))
210  {
211  // Right now our only non-scalar variable type is the
212  // SCALAR variables. The irony is priceless.
213  libmesh_assert_equal_to (_sys.variable(i).type().family, SCALAR);
214 
215  // We pass the point (j,0,0) to an old-style fptr function
216  // pointer to distinguish the different scalars within the
217  // SCALAR variable.
218  for (unsigned int j=0; j != n_components; ++j)
219  if (i == _sys.variable_scalar_number(v,j))
220  return _fptr(Point(j,0,0), *_parameters,
221  _sys.name(), _sys.variable_name(v));
222  }
223  }
224  libMesh::err << "Component index " << i <<
225  " not found in system " << _sys.name() << std::endl;
226  libmesh_error();
227  return Output();
228 }
template<typename Output>
virtual void libMesh::FunctionBase< Output >::init ( )
inlinevirtualinherited

The actual initialization process.

Reimplemented in libMesh::ParsedFunction< Output >, libMesh::MeshFunction, and libMesh::AnalyticFunction< Output >.

Definition at line 85 of file function_base.h.

85 {}
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 194 of file function_base.h.

195 {
196  return (this->_initialized);
197 }
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 115 of file wrapped_function.h.

References libMesh::libmesh_assert().

117 {
120  return _fptr(p,
121  *_parameters,
122  _sys.name(),
124 }
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 145 of file wrapped_function.h.

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

148 {
151 
152  // We fill each entry of output with a single scalar component of
153  // the data in our System
154  const unsigned int size = output.size();
155  libmesh_assert_equal_to (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 }
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 216 of file function_base.h.

218 {
219  // Call the time-dependent function with t=0.
220  this->operator()(p, 0., output);
221 }

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

Definition at line 98 of file wrapped_function.h.

template<typename Output>
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 166 of file function_base.h.

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

template<typename Output>
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 160 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

Definition at line 96 of file wrapped_function.h.

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

Definition at line 105 of file wrapped_function.h.


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

Site Created By: libMesh Developers
Last modified: February 07 2014 16:58:02 UTC

Hosted By:
SourceForge.net Logo