PolyDEAL
 
Loading...
Searching...
No Matches
PackagedOperationMG< Range > Class Template Reference

#include <packaged_operation_for_mg.h>

Public Member Functions

 PackagedOperationMG ()
 
 PackagedOperationMG (const PackagedOperationMG< Range > &)=default
 
 PackagedOperationMG (const Range &u)
 
PackagedOperationMG< Range > & operator= (const PackagedOperationMG< Range > &)=default
 
PackagedOperationMG< Range > & operator= (const Range &u)
 
 operator Range () const
 

Related Symbols

(Note that these are not member symbols.)

Vector space operations
template<typename Range >
PackagedOperationMG< Range > operator+ (const PackagedOperationMG< Range > &first_comp, const PackagedOperationMG< Range > &second_comp)
 
template<typename Range >
PackagedOperationMG< Range > operator- (const PackagedOperationMG< Range > &first_comp, const PackagedOperationMG< Range > &second_comp)
 
template<typename Range >
PackagedOperationMG< Range > operator* (const PackagedOperationMG< Range > &comp, typename Range::value_type number)
 
template<typename Range >
PackagedOperationMG< Range > operator* (typename Range::value_type number, const PackagedOperationMG< Range > &comp)
 
template<typename Range >
PackagedOperationMG< Range > operator+ (const PackagedOperationMG< Range > &comp, const Range &offset)
 
template<typename Range >
PackagedOperationMG< Range > operator+ (const Range &offset, const PackagedOperationMG< Range > &comp)
 
template<typename Range >
PackagedOperationMG< Range > operator- (const PackagedOperationMG< Range > &comp, const Range &offset)
 
template<typename Range >
PackagedOperationMG< Range > operator- (const Range &offset, const PackagedOperationMG< Range > &comp)
 
Creation of a PackagedOperationMG object
template<typename Range , typename = typename std::enable_if< internal::PackagedOperationImplementation::has_vector_interface< Range>::type::value>::type>
PackagedOperationMG< Range > operator+ (const Range &u, const Range &v)
 
template<typename Range , typename = typename std::enable_if< internal::PackagedOperationImplementation::has_vector_interface< Range>::type::value>::type>
PackagedOperationMG< Range > operator- (const Range &u, const Range &v)
 
template<typename Range , typename = typename std::enable_if< internal::PackagedOperationImplementation::has_vector_interface< Range>::type::value>::type>
PackagedOperationMG< Range > operator* (const Range &u, typename Range::value_type number)
 
template<typename Range , typename = typename std::enable_if< internal::PackagedOperationImplementation::has_vector_interface< Range>::type::value>::type>
PackagedOperationMG< Range > operator* (typename Range::value_type number, const Range &u)
 
template<typename Range , typename Domain , typename Payload >
PackagedOperationMG< Range > operator* (const LinearOperatorMG< Range, Domain, Payload > &op, const Domain &u)
 
template<typename Range , typename Domain , typename Payload >
PackagedOperationMG< Domain > operator* (const Range &u, const LinearOperatorMG< Range, Domain, Payload > &op)
 
template<typename Range , typename Domain , typename Payload >
PackagedOperationMG< Range > operator* (const LinearOperatorMG< Range, Domain, Payload > &op, const PackagedOperationMG< Domain > &comp)
 
template<typename Range , typename Domain , typename Payload >
PackagedOperationMG< Domain > operator* (const PackagedOperationMG< Range > &comp, const LinearOperatorMG< Range, Domain, Payload > &op)
 

In-place vector space operations

std::function< void(Range &v)> apply
 
std::function< void(Range &v)> apply_add
 
std::function< void(Range &v, bool omit_zeroing_entries)> reinit_vector
 
PackagedOperationMG< Range > & operator+= (const PackagedOperationMG< Range > &second_comp)
 
PackagedOperationMG< Range > & operator-= (const PackagedOperationMG< Range > &second_comp)
 
PackagedOperationMG< Range > & operator+= (const Range &offset)
 
PackagedOperationMG< Range > & operator-= (const Range &offset)
 
PackagedOperationMG< Range > & operator*= (typename Range::value_type number)
 

Detailed Description

template<typename Range>
class PackagedOperationMG< Range >

A class to store a computation.

The PackagedOperationMG class allows lazy evaluation of expressions involving vectors and linear operators. This is done by storing the computational expression and only performing the computation when either the object is implicitly converted to a vector object, or apply (or apply_add) is invoked by hand. This avoids unnecessary temporary storage of intermediate results.

The class essentially consists of std::function objects that store the knowledge of how to generate the result of a computation and store it in a vector:

std::function<void(Range &)> apply;
std::function<void(Range &)> apply_add;
std::function< void(Range &v)> apply_add
std::function< void(Range &v)> apply

Similar to the LinearOperatorMG class it also has knowledge about how to initialize a vector of the Range space:

std::function<void(Range &, bool)> reinit_vector;
std::function< void(Range &v, bool omit_zeroing_entries)> reinit_vector

As an example consider the addition of multiple vectors

// ..
Vector<double> result = a + b - c + d;
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)

or the computation of a residual $b-Ax$:

// ..
const auto op_a = linear_operator(A);
auto residual = b - op_a * x;
LinearOperator< Range, Domain, Payload > linear_operator(const OperatorExemplar &, const Matrix &)

The expression residual is of type PackagedOperationMG<Vector<double>>. It stores references to A, b and x and defers the actual computation until apply, or apply_add are explicitly invoked,

residual.reinit_vector(y);
residual.apply(y);
residual.apply_add(y);

or until the PackagedOperationMG object is implicitly converted:

y = residual;
y += residual;
y -= residual;
Note
The step-20 tutorial program has a detailed usage example of the LinearOperatorMG class.

Definition at line 105 of file packaged_operation_for_mg.h.

Constructor & Destructor Documentation

◆ PackagedOperationMG() [1/3]

template<typename Range >
PackagedOperationMG< Range >::PackagedOperationMG ( )
inline

Create an empty PackagedOperationMG object. All std::function member objects are initialized with default variants that throw an exception upon invocation.

Definition at line 113 of file packaged_operation_for_mg.h.

References PackagedOperationMG< Range >::apply, PackagedOperationMG< Range >::apply_add, Assert, and PackagedOperationMG< Range >::reinit_vector.

Referenced by PackagedOperationMG< Range >::operator+=(), and PackagedOperationMG< Range >::operator-=().

◆ PackagedOperationMG() [2/3]

template<typename Range >
PackagedOperationMG< Range >::PackagedOperationMG ( const PackagedOperationMG< Range > & )
default

Default copy constructor.

◆ PackagedOperationMG() [3/3]

template<typename Range >
PackagedOperationMG< Range >::PackagedOperationMG ( const Range & u)
inline

Constructor that creates a PackagedOperationMG object from a reference vector u. The PackagedOperationMG returns u.

The PackagedOperationMG object that is created stores a reference to u. Thus, the vector must remain a valid reference for the whole lifetime of the PackagedOperationMG object. All changes made on u after the creation of the PackagedOperationMG object are reflected by the operator object.

Definition at line 149 of file packaged_operation_for_mg.h.

Member Function Documentation

◆ operator Range()

template<typename Range >
PackagedOperationMG< Range >::operator Range ( ) const
inline

Convert a PackagedOperationMG to its result.

This conversion operator creates a vector of the Range space and calls apply() on it.

Definition at line 189 of file packaged_operation_for_mg.h.

References PackagedOperationMG< Range >::apply, and PackagedOperationMG< Range >::reinit_vector.

◆ operator*=()

template<typename Range >
PackagedOperationMG< Range > & PackagedOperationMG< Range >::operator*= ( typename Range::value_type number)
inline

Scalar multiplication of the PackagedOperationMG with a number.

Definition at line 251 of file packaged_operation_for_mg.h.

◆ operator+=() [1/2]

template<typename Range >
PackagedOperationMG< Range > & PackagedOperationMG< Range >::operator+= ( const PackagedOperationMG< Range > & second_comp)
inline

Addition with a PackagedOperationMG second_comp with the same Range.

Definition at line 208 of file packaged_operation_for_mg.h.

◆ operator+=() [2/2]

template<typename Range >
PackagedOperationMG< Range > & PackagedOperationMG< Range >::operator+= ( const Range & offset)
inline

Add a constant offset (of the Range space) to the result of a PackagedOperationMG.

Definition at line 230 of file packaged_operation_for_mg.h.

References PackagedOperationMG< Range >::PackagedOperationMG().

◆ operator-=() [1/2]

template<typename Range >
PackagedOperationMG< Range > & PackagedOperationMG< Range >::operator-= ( const PackagedOperationMG< Range > & second_comp)
inline

Subtraction with a PackagedOperationMG second_comp with the same Range.

Definition at line 219 of file packaged_operation_for_mg.h.

◆ operator-=() [2/2]

template<typename Range >
PackagedOperationMG< Range > & PackagedOperationMG< Range >::operator-= ( const Range & offset)
inline

Subtract a constant offset (of the Range space) from the result of a PackagedOperationMG.

Definition at line 241 of file packaged_operation_for_mg.h.

References PackagedOperationMG< Range >::PackagedOperationMG().

◆ operator=() [1/2]

template<typename Range >
PackagedOperationMG< Range > & PackagedOperationMG< Range >::operator= ( const PackagedOperationMG< Range > & )
default

Default copy assignment operator.

◆ operator=() [2/2]

template<typename Range >
PackagedOperationMG< Range > & PackagedOperationMG< Range >::operator= ( const Range & u)
inline

Copy assignment operator that creates a PackagedOperationMG object from a reference vector u. The PackagedOperationMG returns u.

The PackagedOperationMG object that is created stores a reference to u. Thus, the vector must remain a valid reference for the whole lifetime of the PackagedOperationMG object. All changes made on u after the creation of the PackagedOperationMG object are reflected by the operator object.

Definition at line 170 of file packaged_operation_for_mg.h.

References PackagedOperationMG< Range >::apply, PackagedOperationMG< Range >::apply_add, and PackagedOperationMG< Range >::reinit_vector.

Member Data Documentation

◆ apply

template<typename Range >
std::function<void(Range &v)> PackagedOperationMG< Range >::apply

◆ apply_add

template<typename Range >
std::function<void(Range &v)> PackagedOperationMG< Range >::apply_add

Add the result of the PackagedOperationMG to a vector v of the Range space.

Definition at line 268 of file packaged_operation_for_mg.h.

Referenced by PackagedOperationMG< Range >::operator=(), and PackagedOperationMG< Range >::PackagedOperationMG().

◆ reinit_vector

template<typename Range >
std::function<void(Range &v, bool omit_zeroing_entries)> PackagedOperationMG< Range >::reinit_vector

Initializes a vector v of the Range space to be directly usable as the destination parameter in an application of apply, or apply_add. Similar to the reinit functions of the vector classes, the boolean determines whether a fast initialization is done, i.e., if it is set to false the content of the vector is set to 0.

Definition at line 277 of file packaged_operation_for_mg.h.

Referenced by PackagedOperationMG< Range >::operator Range(), PackagedOperationMG< Range >::operator=(), and PackagedOperationMG< Range >::PackagedOperationMG().


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