libMesh
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | List of all members
libMesh::FDMGradient< GradType > Class Template Reference

#include <fdm_gradient.h>

Inheritance diagram for libMesh::FDMGradient< GradType >:
[legend]

Public Types

typedef TensorTools::DecrementRank< GradType >::type ValType
 

Public Member Functions

 FDMGradient (FEMFunctionBase< ValType > &value_func, Real eps)
 
virtual void init_context (const FEMContext &c) override
 Prepares a context object for use.
 
virtual std::unique_ptr< FEMFunctionBase< GradType > > clone () const override
 
virtual GradType operator() (const FEMContext &c, const Point &p, const Real time=0.) override
 
virtual void operator() (const FEMContext &c, const Point &p, const Real time, DenseVector< GradType > &output) override
 Evaluation function for time-dependent vector-valued functions.
 
virtual GradType component (const FEMContext &c, unsigned int i, const Point &p, Real time) override
 
virtual void init ()
 Any post-construction initialization.
 
void operator() (const FEMContext &, const Point &p, DenseVector< GradType > &output)
 Evaluation function for time-independent vector-valued functions.
 

Private Attributes

std::unique_ptr< FEMFunctionBase< ValType > > _val_func
 
Real _eps
 

Detailed Description

template<typename GradType>
class libMesh::FDMGradient< GradType >

Definition at line 30 of file fdm_gradient.h.

Member Typedef Documentation

◆ ValType

template<typename GradType >
typedef TensorTools::DecrementRank<GradType>::type libMesh::FDMGradient< GradType >::ValType

Definition at line 33 of file fdm_gradient.h.

Constructor & Destructor Documentation

◆ FDMGradient()

template<typename GradType >
libMesh::FDMGradient< GradType >::FDMGradient ( FEMFunctionBase< ValType > &  value_func,
Real  eps 
)
inline

Definition at line 35 of file fdm_gradient.h.

36 :
37 _val_func(value_func.clone()), _eps(eps)
38 {}
std::unique_ptr< FEMFunctionBase< ValType > > _val_func

Member Function Documentation

◆ clone()

template<typename GradType >
virtual std::unique_ptr< FEMFunctionBase< GradType > > libMesh::FDMGradient< GradType >::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< GradType >.

Definition at line 43 of file fdm_gradient.h.

44 { return std::make_unique<FDMGradient<GradType>>(*_val_func, _eps); }

References libMesh::FDMGradient< GradType >::_eps, and libMesh::FDMGradient< GradType >::_val_func.

◆ component()

template<typename GradType >
virtual GradType libMesh::FDMGradient< GradType >::component ( const FEMContext context,
unsigned int  i,
const Point p,
Real  time 
)
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< GradType >.

Definition at line 118 of file fdm_gradient.h.

122 {
123 GradType g;
124
125 auto & val = *_val_func;
126
127 Real one_over_dim = Real(0.5) / _eps;
128
129 g(0) = (val.component(c, i, p+Point(_eps), time) -
130 val.component(c, i, p+Point(-_eps), time)) * one_over_dim;
131#if LIBMESH_DIM > 1
132 g(1) = (val.component(c, i, p+Point(0,_eps), time) -
133 val.component(c, i, p+Point(0,-_eps), time)) * one_over_dim;
134#endif
135#if LIBMESH_DIM > 2
136 g(2) = (val.component(c, i, p+Point(0,0,_eps), time) -
137 val.component(c, i, p+Point(0,0,-_eps), time)) * one_over_dim;
138#endif
139
140 return g;
141 }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

References libMesh::FDMGradient< GradType >::_eps, libMesh::FDMGradient< GradType >::_val_func, and libMesh::Real.

◆ init()

virtual void libMesh::FEMFunctionBase< GradType >::init ( )
inlinevirtualinherited

Any post-construction initialization.

Definition at line 69 of file fem_function_base.h.

69{}

◆ init_context()

template<typename GradType >
virtual void libMesh::FDMGradient< GradType >::init_context ( const FEMContext )
inlineoverridevirtual

Prepares a context object for use.

Most problems will want to reimplement this for efficiency, in order to call FE::get_*() as their particular function requires.

Reimplemented from libMesh::FEMFunctionBase< GradType >.

Definition at line 40 of file fdm_gradient.h.

41 { _val_func->init_context(c); }

References libMesh::FDMGradient< GradType >::_val_func.

◆ operator()() [1/3]

void libMesh::FEMFunctionBase< GradType >::operator() ( const FEMContext context,
const Point p,
DenseVector< GradType > &  output 
)
inlineinherited

Evaluation function for time-independent vector-valued functions.

Sets output values in the passed-in output DenseVector.

Definition at line 102 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 GradType operator()(const FEMContext &, const Point &p, const Real time=0.)=0

◆ operator()() [2/3]

template<typename GradType >
virtual void libMesh::FDMGradient< GradType >::operator() ( const FEMContext ,
const Point p,
const Real  time,
DenseVector< GradType > &  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< GradType >.

Definition at line 70 of file fdm_gradient.h.

74 {
75 auto sz = output.size();
76 DenseVector<ValType> v(sz);
77
78 auto & val = *_val_func;
79
80 val(c, p+Point(_eps), time, v);
81 for (auto i : make_range(sz))
82 output(i)(0) = v(i);
83
84 val(c, p+Point(-_eps), time, v);
85 for (auto i : make_range(sz))
86 {
87 output(i)(0) -= v(i);
88 output(i)(0) /= 2;
89 }
90
91#if LIBMESH_DIM > 1
92 val(c, p+Point(0,_eps), time, v);
93 for (auto i : make_range(sz))
94 output(i)(1) = v(i);
95
96 val(c, p+Point(0,-_eps), time, v);
97 for (auto i : make_range(sz))
98 {
99 output(i)(1) -= v(i);
100 output(i)(1) /= 2;
101 }
102#endif
103#if LIBMESH_DIM > 2
104 val(c, p+Point(0,0,_eps), time, v);
105 for (auto i : make_range(sz))
106 output(i)(2) = v(i);
107
108 val(c, p+Point(0,0,-_eps), time, v);
109 for (auto i : make_range(sz))
110 {
111 output(i)(2) -= v(i);
112 output(i)(2) /= 2;
113 }
114#endif
115 }
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:176

References libMesh::FDMGradient< GradType >::_eps, libMesh::FDMGradient< GradType >::_val_func, libMesh::make_range(), and libMesh::DenseVector< T >::size().

◆ operator()() [3/3]

template<typename GradType >
virtual GradType libMesh::FDMGradient< GradType >::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< GradType >.

Definition at line 46 of file fdm_gradient.h.

49 {
50 GradType g;
51
52 auto & val = *_val_func;
53
54 Real one_over_dim = Real(0.5) / _eps;
55
56 g(0) = (val(c, p+Point(_eps), time) -
57 val(c, p+Point(-_eps), time)) * one_over_dim;
58#if LIBMESH_DIM > 1
59 g(1) = (val(c, p+Point(0,_eps), time) -
60 val(c, p+Point(0,-_eps), time)) * one_over_dim;
61#endif
62#if LIBMESH_DIM > 2
63 g(2) = (val(c, p+Point(0,0,_eps), time) -
64 val(c, p+Point(0,0,-_eps), time)) * one_over_dim;
65#endif
66
67 return g;
68 }

References libMesh::FDMGradient< GradType >::_eps, libMesh::FDMGradient< GradType >::_val_func, and libMesh::Real.

Member Data Documentation

◆ _eps

template<typename GradType >
Real libMesh::FDMGradient< GradType >::_eps
private

◆ _val_func

template<typename GradType >
std::unique_ptr<FEMFunctionBase<ValType> > libMesh::FDMGradient< GradType >::_val_func
private

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