libMesh
Public Member Functions | Protected Attributes | List of all members
libMesh::WrappedFunctor< 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_functor.h>

Inheritance diagram for libMesh::WrappedFunctor< Output >:
[legend]

Public Member Functions

 WrappedFunctor (const FunctionBase< Output > &func)
 Constructor to wrap FunctionBase functors in a FEMFunctionBase compatible shim. More...
 
 WrappedFunctor (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...
 
 WrappedFunctor (const WrappedFunctor &)=delete
 This class can't be copy constructed or assigned because it contains a unique_ptr member. More...
 
WrappedFunctoroperator= (const WrappedFunctor &)=delete
 
 WrappedFunctor (WrappedFunctor &&)=default
 The remaining 5 special functions can be defaulted. More...
 
WrappedFunctoroperator= (WrappedFunctor &&)=default
 
virtual ~WrappedFunctor ()=default
 
virtual void init () override
 Any post-construction initialization. More...
 
virtual void init_context (const FEMContext &c) override
 Tell the context we don't need anything from it. More...
 
virtual std::unique_ptr< FEMFunctionBase< Output > > clone () const override
 
virtual Output operator() (const FEMContext &, const Point &p, const Real time=0.) override
 
virtual void operator() (const FEMContext &, const Point &p, const Real time, DenseVector< Output > &output) override
 Evaluation function for time-dependent vector-valued functions. More...
 
virtual Output component (const FEMContext &, unsigned int i, const Point &p, Real time=0.) override
 
void operator() (const FEMContext &, const Point &p, DenseVector< Output > &output)
 Evaluation function for time-independent vector-valued functions. More...
 

Protected Attributes

std::unique_ptr< FunctionBase< Output > > _func
 

Detailed Description

template<typename Output = Number>
class libMesh::WrappedFunctor< 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 fem_function_base.h.

Author
Roy Stogner
Date
2015

Definition at line 47 of file wrapped_functor.h.

Constructor & Destructor Documentation

◆ WrappedFunctor() [1/4]

template<typename Output = Number>
libMesh::WrappedFunctor< Output >::WrappedFunctor ( const FunctionBase< Output > &  func)
inline

Constructor to wrap FunctionBase functors in a FEMFunctionBase compatible shim.

Definition at line 55 of file wrapped_functor.h.

56  : _func(func.clone())
57  { }
std::unique_ptr< FunctionBase< Output > > _func

◆ WrappedFunctor() [2/4]

template<typename Output = Number>
libMesh::WrappedFunctor< Output >::WrappedFunctor ( 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 62 of file wrapped_functor.h.

68  :
69  _func(std::make_unique<WrappedFunction<Output>>(sys, fptr, parameters, varnum)) {}
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:80
std::unique_ptr< FunctionBase< Output > > _func

◆ WrappedFunctor() [3/4]

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

This class can't be copy constructed or assigned because it contains a unique_ptr member.

◆ WrappedFunctor() [4/4]

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

The remaining 5 special functions can be defaulted.

◆ ~WrappedFunctor()

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

Member Function Documentation

◆ clone()

template<typename Output = Number>
virtual std::unique_ptr<FEMFunctionBase<Output> > libMesh::WrappedFunctor< 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::FEMFunctionBase< Output >.

Definition at line 95 of file wrapped_functor.h.

96  {
97  return std::make_unique<WrappedFunctor<Output>>(*_func);
98  }

◆ component()

template<typename Output = Number>
virtual Output libMesh::WrappedFunctor< Output >::component ( const FEMContext context,
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::FEMFunctionBase< Output >.

Definition at line 111 of file wrapped_functor.h.

References libMesh::WrappedFunctor< Output >::_func.

115  { return _func->component(i, p, time); }
std::unique_ptr< FunctionBase< Output > > _func

◆ init()

template<typename Output = Number>
virtual void libMesh::WrappedFunctor< Output >::init ( )
inlineoverridevirtual

Any post-construction initialization.

Reimplemented from libMesh::FEMFunctionBase< Output >.

Definition at line 88 of file wrapped_functor.h.

References libMesh::WrappedFunctor< Output >::_func.

88 { _func->init(); }
std::unique_ptr< FunctionBase< Output > > _func

◆ init_context()

template<typename Output >
void libMesh::WrappedFunctor< Output >::init_context ( const FEMContext c)
overridevirtual

Tell the context we don't need anything from it.

Reimplemented from libMesh::FEMFunctionBase< Output >.

Definition at line 124 of file wrapped_functor.h.

References dim, libMesh::FEMContext::elem_dimensions(), libMesh::FEMContext::get_element_fe(), libMesh::FEAbstract::get_nothing(), libMesh::make_range(), and libMesh::DiffContext::n_vars().

125 {
126  for (auto dim : c.elem_dimensions())
127  {
128  for (auto v : make_range(c.n_vars()))
129  {
130  FEAbstract * fe;
131  c.get_element_fe(v, fe, dim);
132  fe->get_nothing();
133  }
134  }
135 }
unsigned int dim
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:140

◆ operator()() [1/3]

template<typename Output = Number>
virtual Output libMesh::WrappedFunctor< Output >::operator() ( const FEMContext ,
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::FEMFunctionBase< Output >.

Definition at line 100 of file wrapped_functor.h.

References libMesh::WrappedFunctor< Output >::_func.

103  { return _func->operator()(p, time); }
std::unique_ptr< FunctionBase< Output > > _func

◆ operator()() [2/3]

template<typename Output >
void libMesh::FEMFunctionBase< Output >::operator() ( const FEMContext context,
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 149 of file fem_function_base.h.

152 {
153  // Call the time-dependent function with t=0.
154  this->operator()(context, p, 0., output);
155 }
virtual Output operator()(const FEMContext &, const Point &p, const Real time=0.)=0

◆ operator()() [3/3]

template<typename Output = Number>
virtual void libMesh::WrappedFunctor< Output >::operator() ( const FEMContext ,
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::FEMFunctionBase< Output >.

Definition at line 105 of file wrapped_functor.h.

References libMesh::WrappedFunctor< Output >::_func.

109  { _func->operator() (p, time, output); }
std::unique_ptr< FunctionBase< Output > > _func

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

Member Data Documentation

◆ _func

template<typename Output = Number>
std::unique_ptr<FunctionBase<Output> > libMesh::WrappedFunctor< Output >::_func
protected

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