Medusa  1.1
Coordinate Free Mehless Method implementation
mm::ExplicitOperators< shape_storage_type > Class Template Reference

#include <ExplicitOperators_fwd.hpp>

Detailed Description

template<class shape_storage_type>
class mm::ExplicitOperators< shape_storage_type >

A class for evaluating typical operators needed in spatial discretization.

This class represents scalar differential operators, discretely approximated with shape functions that are stored in given shape storage. These shape functions are used to construct approximations of common operators such as gradient, Laplacian and coordinate derivatives that can be applied to scalar fields at given points.

Template Parameters
shape_storage_typeStorage class for shapes. Shape storage concept.

Usage example:

BoxShape<Vec2d> box({0.0, 0.0}, {1.0, 1.0});
DomainDiscretization<Vec2d> d = box.discretizeWithStep(0.02);
d.findSupport(FindClosest(9));
WLS<Monomials<Vec2d>, NoWeight<Vec2d>, ScaleToFarthest> wls(2);
auto storage = d.computeShapes(wls);
ExplicitOperators<decltype(storage)> op(storage);
std::cout << op << std::endl;
Range<double> field(d.size(), 1.34); // constant scalar field, value 1.34 at each point
double val = op.lap(field, 2); // laplace at point d.pos(2);
Vec2d grad = op.grad(field, 4); // gradient at point d.pos(4);
ScalarField<std::complex<double>> complex_field(d.size());
std::complex<double> c(2.4, -0.3);
complex_field.setConstant(c); // constant complex field, value c at each point
// what should the value at node 0 be, so that the normal derivative is 0 + 0i?
std::complex<double> neu = op.neumann(field, 0, {-1}, 0.0); // result equal to c
See also
ExplicitVectorOperators

Definition at line 35 of file ExplicitOperators_fwd.hpp.

Public Member Functions

 ExplicitOperators ()
 Construct empty explicit operators. More...
 
 ExplicitOperators (const shape_storage_t &ss)
 Construct explicit operators over given shape storage. More...
 
void setShapes (const shape_storage_t &shape_storage_)
 Sets a new shape storage from which this operators are generated. More...
 
bool hasShapes () const
 Returns true if operators have a non-null pointer to storage and false otherwise. More...
 
template<typename scalar_field_t >
scalar_type< scalar_field_t >::type lap (const scalar_field_t &u, int node) const
 Returns an approximation of Laplacian of field u in node-th node. More...
 
template<typename scalar_field_t >
Vec< typename scalar_type< scalar_field_t >::type, ExplicitOperators< shape_storage_type >::dimgrad (const scalar_field_t &u, int node) const
 Returns an approximation of gradient of field u in node-th node. More...
 
template<typename scalar_field_t >
scalar_type< scalar_field_t >::type neumann (const scalar_field_t &u, int node, const vector_t &normal, typename scalar_type< scalar_field_t >::type val) const
 Calculates a new field value a for u at node, such that the Neumann boundary condition du/dn(node) = val holds. More...
 
template<typename scalar_field_t >
scalar_type< scalar_field_t >::type d1 (const scalar_field_t &u, int var, int node) const
 Returns an approximation of requested derivative of field u in node-th node. More...
 
template<typename scalar_field_t >
scalar_type< scalar_field_t >::type d2 (const scalar_field_t &u, int varmin, int varmax, int node) const
 Returns an approximation of requested second derivative of field u in node-th node. More...
 
template<typename op_family_t , typename scalar_field_t >
scalar_type< scalar_field_t >::type apply (const scalar_field_t &u, int node, typename op_family_t::operator_t o) const
 Returns an approximation of applying the requested operator to field u at node node. More...
 
template<typename op_family_t , typename scalar_field_t >
scalar_type< scalar_field_t >::type apply (const scalar_field_t &u, int node) const
 Overload for default constructible operator. More...
 

Public Types

enum  { dim = shape_storage_t::dim }
 Store dimension of the domain. More...
 
typedef shape_storage_type shape_storage_t
 Type of shape storage. More...
 
typedef shape_storage_t::vector_t vector_t
 Vector type. More...
 
typedef shape_storage_t::scalar_t scalar_t
 Scalar type. More...
 

Friends

template<typename S >
std::ostream & operator<< (std::ostream &os, const ExplicitOperators< S > &op)
 Output basic information about given operators. More...
 

Private Attributes

const shape_storage_tss
 Pointer to shape storage, but name is shortened for readability. More...
 

Member Enumeration Documentation

◆ anonymous enum

template<class shape_storage_type >
anonymous enum

Store dimension of the domain.

Enumerator
dim 

Dimensionality of the function domain.

Definition at line 41 of file ExplicitOperators_fwd.hpp.

Constructor & Destructor Documentation

◆ ExplicitOperators() [1/2]

template<class shape_storage_type >
mm::ExplicitOperators< shape_storage_type >::ExplicitOperators ( )
inline

Construct empty explicit operators.

Definition at line 49 of file ExplicitOperators_fwd.hpp.

◆ ExplicitOperators() [2/2]

template<class shape_storage_type >
mm::ExplicitOperators< shape_storage_type >::ExplicitOperators ( const shape_storage_t ss)
inlineexplicit

Construct explicit operators over given shape storage.

The pointer to given storage is stored as a non-owning pointer. It is the user's responsibility that given storage is valid throughout the use use of this class.

This class is usually constructed directly from shape storage using the explicitOperators() member function.

Definition at line 58 of file ExplicitOperators_fwd.hpp.

Member Function Documentation

◆ apply() [1/2]

template<class shape_storage_type >
template<typename op_family_t , typename scalar_field_t >
scalar_type<scalar_field_t>::type mm::ExplicitOperators< shape_storage_type >::apply ( const scalar_field_t &  u,
int  node 
) const
inline

Overload for default constructible operator.

See also
apply

Definition at line 186 of file ExplicitOperators_fwd.hpp.

◆ apply() [2/2]

template<class shape_storage_type >
template<typename op_family_t , typename scalar_field_t >
scalar_type<scalar_field_t>::type mm::ExplicitOperators< shape_storage_type >::apply ( const scalar_field_t &  u,
int  node,
typename op_family_t::operator_t  o 
) const

Returns an approximation of applying the requested operator to field u at node node.

Parameters
uField to which the operator is applied.
nodeNode at which the derived field is evaluated.
oThe operator to apply.
Warning
The operator approximation is obtained from shape storage using the op_family_t type. The first weights computed for family of type op_family_t are used.

Usage example:

struct Dx : Der1<2> { Dx() : Der1(0) {} };
struct Dy : Der1<2> { Dy() : Der1(1) {} };
auto storage = d.computeShapes<std::tuple<Dx, Dy, Lap<2>>>(wls);
ExplicitOperators<decltype(storage)> op(storage);
ScalarField<std::complex<double>> field(d.size());
std::complex<double> c(2.4, -0.3);
field.setConstant(c);
std::complex<double> lap = op.apply<Lap<2>>(field, 52);
std::complex<double> dx = op.apply<Dx>(field, 34);
std::complex<double> dy = op.apply<Dy>(field, 32);

◆ d1()

template<class shape_storage_type >
template<typename scalar_field_t >
scalar_type<scalar_field_t>::type mm::ExplicitOperators< shape_storage_type >::d1 ( const scalar_field_t &  u,
int  var,
int  node 
) const
inline

Returns an approximation of requested derivative of field u in node-th node.

Returns
The approximation of the derivative \( \dpar{ u}{ x_v} \), where \(x_v\) is the var-th variable and approximation is taken from ss.
Exceptions
Assertionfails unless 0 <= var && var < dim holds.

Definition at line 150 of file ExplicitOperators_fwd.hpp.

◆ d2()

template<class shape_storage_type >
template<typename scalar_field_t >
scalar_type<scalar_field_t>::type mm::ExplicitOperators< shape_storage_type >::d2 ( const scalar_field_t &  u,
int  varmin,
int  varmax,
int  node 
) const
inline

Returns an approximation of requested second derivative of field u in node-th node.

Returns
The approximation of the derivative \( \dpar{^2 u}{ x_v x_w} \), where \(x_v\) is the varmin-th variable, \(x_w\) is the varmax-th variable and approximation is taken from ss.
Exceptions
Assertionfails unless 0 <= varmin <= varmax < dim holds.

Definition at line 163 of file ExplicitOperators_fwd.hpp.

◆ grad()

template<class shape_storage_type >
template<typename scalar_field_t >
Vec<typename scalar_type<scalar_field_t>::type, ExplicitOperators<shape_storage_type>::dim> mm::ExplicitOperators< shape_storage_type >::grad ( const scalar_field_t &  u,
int  node 
) const

Returns an approximation of gradient of field u in node-th node.

Returns
Vector containing the components of the gradient, e.g. when dim = 3: \( [ \dpar{ u}{ x}, \dpar{ u}{ y}, \dpar{ u}{ z} ]^T\), where derivatives are approximated using shape functions from ss.

◆ hasShapes()

template<class shape_storage_type >
bool mm::ExplicitOperators< shape_storage_type >::hasShapes ( ) const
inline

Returns true if operators have a non-null pointer to storage and false otherwise.

Definition at line 69 of file ExplicitOperators_fwd.hpp.

◆ lap()

template<class shape_storage_type >
template<typename scalar_field_t >
scalar_type<scalar_field_t>::type mm::ExplicitOperators< shape_storage_type >::lap ( const scalar_field_t &  u,
int  node 
) const
inline

Returns an approximation of Laplacian of field u in node-th node.

Returns
The Laplacian of u, e.g. when dim = 3: \( \dpar{^2 u}{ x^2} + \dpar{^2 u}{ y^2} + \dpar{^2 u}{ z^2} \), where derivatives are approximated using shape functions from ss.

Definition at line 81 of file ExplicitOperators_fwd.hpp.

◆ neumann()

template<class shape_storage_type >
template<typename scalar_field_t >
scalar_type<scalar_field_t>::type mm::ExplicitOperators< shape_storage_type >::neumann ( const scalar_field_t &  u,
int  node,
const vector_t normal,
typename scalar_type< scalar_field_t >::type  val 
) const

Calculates a new field value a for u at node, such that the Neumann boundary condition du/dn(node) = val holds.

Denote given index node by \(i\) and val by \(v\). The function returns such \(a\), that by setting \( u(i) = a\) we satisfy the condition \( \dpar{ u}{ \vec n}(i) = v\). This is done using the following formula:

\[ a = \frac{v - \sum\limits_{i=1}^{s} \sum\limits_{d=1}^{dim} n_d \chi_{\dpar{}{ x_d}}(i)\ u(i)} {\sum\limits_{d=1}^{dim} n_d \chi_{\dpar{}{ x_d}}(0)}, \]

where \(\chi_{\dpar{}{ x_d}}\) represents the formula for the shape function of first derivative wrt. \(d\).

Note
A few assumptions must hold for the support domain.
  • Each node should be its own first first support node.
  • For symmetrical supports the central node may not affect the calculated derivation and therefore this function is unable to give a value and will crash.

The function is constructed in such a way to make explicit iteration with Neumann boundary conditions simple. To satisfy \(\dpar{u}{\vec n} = v\), we simply use

u[i] = op.neumann(u, i, domain.normal(i), v);
Parameters
uScalar field to evaluate.
nodeIndex of the node, whose value should be changed to satisfy the boundary condition.
normalVector \(\vec{n}\) with the same dimensionality as the problem domain giving the direction of the derivation. Usually the unit normal vector.
valThe value that \(\dpar{ u}{ \vec n}\) should be equal to.
Returns
A new value \(a\), such that \(\dpar{ u}{ \vec n} = v\) after setting \( u(i) = a\).
Exceptions
Assertionfails if node's first support node is not node.
Assertionfails if node's value has negligible effect on the derivation, because no value could change the value of \(\dpar{ u}{ \vec n}\).

◆ setShapes()

template<class shape_storage_type >
void mm::ExplicitOperators< shape_storage_type >::setShapes ( const shape_storage_t shape_storage_)
inline

Sets a new shape storage from which this operators are generated.

As in the constructor, the pointer to given storage is stored as a non-owning pointer. It is the user's responsibility that given storage is valid throughout the use use of this class.

Parameters
shape_storage_New shape storage.

Definition at line 66 of file ExplicitOperators_fwd.hpp.

Friends And Related Function Documentation

◆ operator<<

template<class shape_storage_type >
template<typename S >
std::ostream& operator<< ( std::ostream &  os,
const ExplicitOperators< S > &  op 
)
friend

Output basic information about given operators.

Definition at line 80 of file ExplicitOperators.hpp.

Member Data Documentation

◆ ss

template<class shape_storage_type >
const shape_storage_t* mm::ExplicitOperators< shape_storage_type >::ss
private

Pointer to shape storage, but name is shortened for readability.

Definition at line 45 of file ExplicitOperators_fwd.hpp.


The documentation for this class was generated from the following file:
mm::ExplicitOperators::lap
scalar_type< scalar_field_t >::type lap(const scalar_field_t &u, int node) const
Returns an approximation of Laplacian of field u in node-th node.
Definition: ExplicitOperators_fwd.hpp:81
mm::ExplicitOperators::ExplicitOperators
ExplicitOperators()
Construct empty explicit operators.
Definition: ExplicitOperators_fwd.hpp:49
mm::ExplicitOperators::grad
Vec< typename scalar_type< scalar_field_t >::type, ExplicitOperators< shape_storage_type >::dim > grad(const scalar_field_t &u, int node) const
Returns an approximation of gradient of field u in node-th node.
mm::Vec2d
Vec< double, 2 > Vec2d
Convenience typedef for 2d vector of doubles.
Definition: Vec_fwd.hpp:34