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

#include <ExplicitVectorOperators_fwd.hpp>

Detailed Description

template<class shape_storage_type>
class mm::ExplicitVectorOperators< shape_storage_type >

A class for evaluating typical operators needed in spatial discretization.

This class represents vector 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, divergence, ... that can be applied to vector fields at given points.

Note
The scalar types (and sometimes even dimensions) of the given fields and the shapes can be different. We support computing the gradient of a 3d complex-valued field over 2d domain with double shapes: the result is a 3x2 complex matrix.
Template Parameters
shape_storage_typeStorage class for shapes. Must satisfy the 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);
ExplicitVectorOperators<decltype(storage)> op(storage);
std::cout << op << std::endl;
VectorField2d v(d.size()); // constant scalar field, value 1.34 at each point
v = Vec2d(12.4, -3.4);
Vec2d val = op.lap(v, 2); // laplace at point d.pos(2);
Eigen::Matrix2d grad = op.grad(v, 4); // gradient at point d.pos(4);
double div = op.div(v, 3); // divergence at points d.pos(3);
VectorField<std::complex<double>, 3> complex_field(d.size()); // 3d complex field
complex_field.setConstant(std::complex<double>(2.5, -7.1));
Eigen::Matrix<std::complex<double>, 3, 2> cgrad = op.grad(complex_field, 1);
See also
ExplicitOperators

Definition at line 38 of file ExplicitVectorOperators_fwd.hpp.

Public Member Functions

 ExplicitVectorOperators ()
 Construct empty explicit vector operators. More...
 
 ExplicitVectorOperators (const shape_storage_t &ss)
 Construct explicit vector 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<class vector_field_t >
vector_type< vector_field_t >::type lap (const vector_field_t &u, int node) const
 Returns Laplacian of vector field u in node with index node. More...
 
template<typename op_family_t , typename vector_field_t >
vector_type< vector_field_t >::type apply (const vector_field_t &u, int node, typename op_family_t::operator_t o) const
 Returns an approximation of applying the requested operator to each component of field u at node node. More...
 
template<typename op_family_t , typename vector_field_t >
vector_type< vector_field_t >::type apply (const vector_field_t &u, int node) const
 Overload for default constructible operator. More...
 
template<class vector_field_t >
Eigen::Matrix< typename vector_type< vector_field_t >::type::scalar_t, vector_type< vector_field_t >::type::dim, dimgrad (const vector_field_t &u, int node) const
 Returns gradient of vector field u in node with index node. More...
 
template<class vector_field_t >
vector_type< vector_field_t >::type::scalar_t div (const vector_field_t &u, int node) const
 Returns divergence of a vector field u in in node with index node. More...
 
template<class vector_field_t >
vector_type< vector_field_t >::type curl (const vector_field_t &u, int node) const
 Returns curl of a vector field u in node with index node. More...
 
template<class vector_field_t >
vector_type< vector_field_t >::type graddiv (const vector_field_t &u, int node) const
 Returns gradient of divergence of a vector field u in in node with index node. More...
 
template<class vector_field_t >
vector_type< vector_field_t >::type neumann (const vector_field_t &u, int node, const vector_t &normal, typename vector_type< vector_field_t >::type val) const
 This is a vectorised version of ExplicitOperators::neumann. 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 ExplicitVectorOperators< S > &op)
 Output basic info 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 44 of file ExplicitVectorOperators_fwd.hpp.

Constructor & Destructor Documentation

◆ ExplicitVectorOperators() [1/2]

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

Construct empty explicit vector operators.

Definition at line 52 of file ExplicitVectorOperators_fwd.hpp.

◆ ExplicitVectorOperators() [2/2]

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

Construct explicit vector 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 explicitVectorOperators() member function.

Definition at line 61 of file ExplicitVectorOperators_fwd.hpp.

Member Function Documentation

◆ apply() [1/2]

template<class shape_storage_type >
template<typename op_family_t , typename vector_field_t >
vector_type<vector_field_t>::type mm::ExplicitVectorOperators< shape_storage_type >::apply ( const vector_field_t &  u,
int  node 
) const
inline

Overload for default constructible operator.

See also
apply

Definition at line 110 of file ExplicitVectorOperators_fwd.hpp.

◆ apply() [2/2]

template<class shape_storage_type >
template<typename op_family_t , typename vector_field_t >
vector_type<vector_field_t>::type mm::ExplicitVectorOperators< shape_storage_type >::apply ( const vector_field_t &  u,
int  node,
typename op_family_t::operator_t  o 
) const

Returns an approximation of applying the requested operator to each component of 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);
ExplicitVectorOperators<decltype(storage)> op(storage);
VectorField<std::complex<double>, 3> field(d.size());
std::complex<double> c(2.4, -0.3);
field.setConstant(c);
Vec<std::complex<double>, 3> lap = op.apply<Lap<2>>(field, 52);
Vec<std::complex<double>, 3> dx = op.apply<Dx>(field, 34);
Vec<std::complex<double>, 3> dy = op.apply<Dy>(field, 32);

◆ curl()

template<class shape_storage_type >
template<class vector_field_t >
vector_type<vector_field_t>::type mm::ExplicitVectorOperators< shape_storage_type >::curl ( const vector_field_t &  u,
int  node 
) const

Returns curl of a vector field u in node with index node.

Returns
The rotor of u, where dim = 3 and \(\vec{u} = [u, v, w]\). The return value is \( \curl \vec{u} = \[\dpar{w}{y} - \dpar{v}{z}, \dpar{u}{z} - \dpar{w}{x}, \dpar{v}{x} - \dpar{u}{y}\] \) evaluated in point with index node, where derivatives are approximated using shape functions from ss.
Exceptions
Static-assertionfails if u is not three dimensional.

◆ div()

template<class shape_storage_type >
template<class vector_field_t >
vector_type<vector_field_t>::type::scalar_t mm::ExplicitVectorOperators< shape_storage_type >::div ( const vector_field_t &  u,
int  node 
) const

Returns divergence of a vector field u in in node with index node.

Returns
The divergence of u, e.g. when dim = 3 and \(\vec{u} = [u, v, w]\), the returned value is \( \nabla\cdot \vec{u} = \dpar{u}{x} + \dpar{v}{y} + \dpar{w}{z} \) evaluated in point with index node, where derivatives are approximated using shape functions from ss.
Exceptions
Static-assertionfails if the dimension of u is not equal to domain dimension.

◆ grad()

template<class shape_storage_type >
template<class vector_field_t >
Eigen::Matrix<typename vector_type<vector_field_t>::type::scalar_t, vector_type<vector_field_t>::type::dim, dim> mm::ExplicitVectorOperators< shape_storage_type >::grad ( const vector_field_t &  u,
int  node 
) const

Returns gradient of vector field u in node with index node.

The field u and the domain can have different dimensions.

Returns
The gradient (Jacobi matrix) of u, e.g. when dim(u) = 3 and and \(\vec{u} = [u, v, w]\) and the domain dimension is 2, the returned value is

\[ \nabla \vec{u} = \begin{bmatrix} \dpar{u}{x}, \dpar{u}{y} \\ \dpar{v}{x}, \dpar{v}{y} \\ \dpar{w}{x}, \dpar{w}{y} \end{bmatrix} \]

evaluated in point with index node, where derivatives are approximated using shape functions from ss.

◆ graddiv()

template<class shape_storage_type >
template<class vector_field_t >
vector_type<vector_field_t>::type mm::ExplicitVectorOperators< shape_storage_type >::graddiv ( const vector_field_t &  u,
int  node 
) const

Returns gradient of divergence of a vector field u in in node with index node.

Returns
The gradient of divergence of u, e.g. when dim = 3 and \(\vec{u} = [u, v, w]\), the returned value is

\[ \nabla(\nabla\cdot \vec{u}) = \begin{bmatrix} \dpar{^2u}{x^2} + \dpar{^2v}{x\partial y} + \dpar{^2w}{x\partial z} \\ \dpar{^2u}{x\partial y} + \dpar{^2v}{^2y} + \dpar{^2w}{y\partial z} \\ \dpar{^2u}{x\partial z} + \dpar{^2v}{y\partial z} + \dpar{^2w}{^2z} \end{bmatrix} \]

evaluated in point with index node, where derivatives are approximated using shape functions from ss.
Exceptions
Static-assertionfails if the dimension of u is not equal to domain dimension.

◆ hasShapes()

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

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

Definition at line 72 of file ExplicitVectorOperators_fwd.hpp.

◆ lap()

template<class shape_storage_type >
template<class vector_field_t >
vector_type<vector_field_t>::type mm::ExplicitVectorOperators< shape_storage_type >::lap ( const vector_field_t &  u,
int  node 
) const
inline

Returns Laplacian of vector field u in node with index node.

Returns
The Laplacian of u, e.g. when dim = 3 and \(\vec{u} = [u, v, w]\), the returned value is \( \nabla^2 \vec{u} = [ \dpar{^2 u}{x^2} + \dpar{^2 u}{y^2} + \dpar{^2 u}{z^2}, \dpar{^2 v}{x^2} + \dpar{^2 v}{y^2} + \dpar{^2 v}{z^2}, \dpar{^2 w}{x^2} + \dpar{^2 w}{y^2} + \dpar{^2 w}{z^2} ]^T\) evaluated in point with index node where derivatives are approximated using shape functions from ss.
Exceptions
Static-assertionfails if the dimension of u is not equal to domain dimension.

Definition at line 87 of file ExplicitVectorOperators_fwd.hpp.

◆ neumann()

template<class shape_storage_type >
template<class vector_field_t >
vector_type<vector_field_t>::type mm::ExplicitVectorOperators< shape_storage_type >::neumann ( const vector_field_t &  u,
int  node,
const vector_t normal,
typename vector_type< vector_field_t >::type  val 
) const

This is a vectorised version of ExplicitOperators::neumann.

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 \(\vec v\). The function returns such \(\vec a\), that by setting \( \vec{u}(i) = \vec{a}\) we satisfy the condition \( \dpar{\vec u}{\vec n}(i) = \vec v\). This is done using the following formula:

\[ \vec{a} = \frac{ \vec{v} - \sum\limits_{i=1}^{s} \sum\limits_{d=1}^{dim} n_d \chi_{\dpar{}{ x_d}}(i)\ \vec{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.
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{ \vec u}{ \vec n}\) should be equal to.
Returns
A new value \(\vec a\), such that \(\dpar{\vec u}{\vec n} = \vec v\) after setting \(\vec u(i) = \vec 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{\vec u}{\vec n}\).
Static-assertionfails if the dimension of u is not equal to domain dimension.
See also
ExplicitOperators::neumann

◆ setShapes()

template<class shape_storage_type >
void mm::ExplicitVectorOperators< 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 69 of file ExplicitVectorOperators_fwd.hpp.

Friends And Related Function Documentation

◆ operator<<

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

Output basic info about given operators.

Definition at line 151 of file ExplicitVectorOperators.hpp.

Member Data Documentation

◆ ss

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

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

Definition at line 48 of file ExplicitVectorOperators_fwd.hpp.


The documentation for this class was generated from the following file:
mm::ExplicitVectorOperators::grad
Eigen::Matrix< typename vector_type< vector_field_t >::type::scalar_t, vector_type< vector_field_t >::type::dim, dim > grad(const vector_field_t &u, int node) const
Returns gradient of vector field u in node with index node.
mm::ExplicitVectorOperators::ExplicitVectorOperators
ExplicitVectorOperators()
Construct empty explicit vector operators.
Definition: ExplicitVectorOperators_fwd.hpp:52
mm::VectorField2d
VectorField< double, 2 > VectorField2d
Two dimensional vector field of doubles.
Definition: VectorField_fwd.hpp:152
mm::ExplicitVectorOperators::div
vector_type< vector_field_t >::type::scalar_t div(const vector_field_t &u, int node) const
Returns divergence of a vector field u in in node with index node.
mm::Vec2d
Vec< double, 2 > Vec2d
Convenience typedef for 2d vector of doubles.
Definition: Vec_fwd.hpp:34
mm::ExplicitVectorOperators::lap
vector_type< vector_field_t >::type lap(const vector_field_t &u, int node) const
Returns Laplacian of vector field u in node with index node.
Definition: ExplicitVectorOperators_fwd.hpp:87