libMesh::WrappedFunction< Output > Class Template Reference

#include <wrapped_function.h>

Inheritance diagram for libMesh::WrappedFunction< Output >:

List of all members.

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.

00058     : _sys(sys),
00059       _fptr(fptr),
00060       _parameters(parameters),
00061       _varnum(varnum)
00062   {
00063     this->_initialized = true;
00064     if (!parameters)
00065       _parameters = &sys.get_equation_systems().parameters;
00066   }


Member Function Documentation

template<typename Output = Number>
virtual void libMesh::FunctionBase< Output >::clear (  )  [inline, virtual, inherited]

Clears the function.

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

Definition at line 90 of file function_base.h.

00090 {}

template<typename Output >
AutoPtr< FunctionBase< Output > > libMesh::WrappedFunction< Output >::clone (  )  const [inline, 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 130 of file wrapped_function.h.

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

00131 {
00132   return AutoPtr<FunctionBase<Output> >
00133     (new WrappedFunction<Output>
00134       (_sys, _fptr, _parameters, _varnum));
00135 }

template<typename Output >
Output libMesh::WrappedFunction< Output >::component ( unsigned int  i,
const Point p,
Real  time = 0. 
) [inline, virtual]
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::WrappedFunction< Output >::_fptr, libMesh::WrappedFunction< Output >::_parameters, libMesh::WrappedFunction< Output >::_sys, libMesh::err, libMesh::FEType::family, libMesh::Variable::n_components(), libMesh::System::n_vars(), n_vars, libMesh::System::name(), libMeshEnums::SCALAR, libMesh::Variable::type(), libMesh::System::variable(), libMesh::System::variable_name(), and libMesh::System::variable_scalar_number().

00194 {
00195   libmesh_assert(_fptr);
00196   libmesh_assert(_parameters);
00197 
00198   // Loop over variables, then over each component in
00199   // vector-valued variables.
00200   const unsigned int n_vars = _sys.n_vars();
00201   for (unsigned int v = 0; v != n_vars; ++v)
00202     {
00203       const unsigned int n_components =
00204         _sys.variable(v).n_components();
00205       if (n_components == 1 &&
00206           i == _sys.variable_scalar_number(v,0))
00207         return _fptr(p, *_parameters, _sys.name(), _sys.variable_name(v));
00208       else if (i >= _sys.variable_scalar_number(v,0) &&
00209                i <= _sys.variable_scalar_number(v,n_components-1))
00210         {
00211           // Right now our only non-scalar variable type is the
00212           // SCALAR variables.  The irony is priceless.
00213           libmesh_assert_equal_to (_sys.variable(i).type().family, SCALAR);
00214 
00215           // We pass the point (j,0,0) to an old-style fptr function
00216           // pointer to distinguish the different scalars within the
00217           // SCALAR variable.
00218           for (unsigned int j=0; j != n_components; ++j)
00219             if (i == _sys.variable_scalar_number(v,j))
00220               return _fptr(Point(j,0,0), *_parameters,
00221                            _sys.name(), _sys.variable_name(v));
00222         }
00223     }
00224   libMesh::err << "Component index " << i <<
00225                   " not found in system " << _sys.name() << std::endl;
00226   libmesh_error();
00227   return Output();
00228 }

template<typename Output = Number>
virtual void libMesh::FunctionBase< Output >::init (  )  [inline, virtual, inherited]

The actual initialization process.

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

Definition at line 85 of file function_base.h.

00085 {}

template<typename Output >
bool libMesh::FunctionBase< Output >::initialized (  )  const [inline, inherited]
Returns:
true when this object is properly initialized and ready for use, false otherwise.

Definition at line 194 of file function_base.h.

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

Referenced by libMesh::AnalyticFunction< Output >::operator()().

00195 {
00196   return (this->_initialized);
00197 }

template<typename Output>
void libMesh::FunctionBase< Output >::operator() ( const Point p,
DenseVector< Output > &  output 
) [inline, inherited]

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.

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

00218 {
00219   // Call the time-dependent function with t=0.
00220   this->operator()(p, 0., output);
00221 }

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

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::WrappedFunction< Output >::_fptr, libMesh::WrappedFunction< Output >::_parameters, libMesh::WrappedFunction< Output >::_sys, libMesh::FEType::family, libMesh::Variable::n_components(), libMesh::System::n_components(), libMesh::System::n_vars(), n_vars, libMesh::System::name(), libMeshEnums::SCALAR, libMesh::DenseVector< T >::size(), libMesh::Variable::type(), libMesh::System::variable(), libMesh::System::variable_name(), and libMesh::System::variable_scalar_number().

00148 {
00149   libmesh_assert(_fptr);
00150   libmesh_assert(_parameters);
00151 
00152   // We fill each entry of output with a single scalar component of
00153   // the data in our System
00154   const unsigned int size = output.size();
00155   libmesh_assert_equal_to (size, _sys.n_components());
00156 
00157   // Loop over variables, then over each component in
00158   // vector-valued variables, evaluating each.
00159   const unsigned int n_vars = _sys.n_vars();
00160   for (unsigned int v = 0; v != n_vars; ++v)
00161     {
00162       const unsigned int n_components =
00163         _sys.variable(v).n_components();
00164       if (n_components == 1)
00165         output(_sys.variable_scalar_number(v,0)) =
00166            _fptr(p, *_parameters, _sys.name(), _sys.variable_name(v));
00167       else
00168         {
00169           // Right now our only non-scalar variable type is the
00170           // SCALAR variables.  The irony is priceless.
00171           libmesh_assert_equal_to (_sys.variable(v).type().family, SCALAR);
00172 
00173           // We pass the point (j,0,0) to an old-style fptr function
00174           // pointer to distinguish the different scalars within the
00175           // SCALAR variable.
00176           for (unsigned int j=0; j != n_components; ++j)
00177             output(_sys.variable_scalar_number(v,j)) =
00178                _fptr(Point(j,0,0), *_parameters,
00179                      _sys.name(), _sys.variable_name(v));
00180         }
00181     }
00182 }

template<typename Output >
Output libMesh::WrappedFunction< Output >::operator() ( const Point p,
const Real  time = 0. 
) [inline, virtual]
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::WrappedFunction< Output >::_fptr, libMesh::WrappedFunction< Output >::_parameters, libMesh::WrappedFunction< Output >::_sys, libMesh::WrappedFunction< Output >::_varnum, libMesh::System::name(), and libMesh::System::variable_name().

00117 {
00118   libmesh_assert(_fptr);
00119   libmesh_assert(_parameters);
00120   return _fptr(p,
00121                *_parameters,
00122                _sys.name(),
00123                _sys.variable_name(_varnum));
00124 }


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>
const FunctionBase* libMesh::FunctionBase< Output >::_master [protected, inherited]

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>
unsigned int libMesh::WrappedFunction< Output >::_varnum [protected]

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

Site Created By: libMesh Developers
Last modified: February 05 2013 19:55:43 UTC

Hosted By:
SourceForge.net Logo