Reference documentation for deal.II version 9.5.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
PackagedOperation< Range > Class Template Reference

#include <deal.II/lac/packaged_operation.h>

Public Member Functions

 PackagedOperation ()
 
 PackagedOperation (const PackagedOperation< Range > &)=default
 
 PackagedOperation (const Range &u)
 
PackagedOperation< Range > & operator= (const PackagedOperation< Range > &)=default
 
PackagedOperation< Range > & operator= (const Range &u)
 
 operator Range () const
 
In-place vector space operations
PackagedOperation< Range > & operator+= (const PackagedOperation< Range > &second_comp)
 
PackagedOperation< Range > & operator-= (const PackagedOperation< Range > &second_comp)
 
PackagedOperation< Range > & operator+= (const Range &offset)
 
PackagedOperation< Range > & operator-= (const Range &offset)
 
PackagedOperation< Range > & operator*= (typename Range::value_type number)
 

Public Attributes

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

Related Symbols

(Note that these are not member symbols.)

Vector space operations
template<typename Range >
PackagedOperation< Range > operator+ (const PackagedOperation< Range > &first_comp, const PackagedOperation< Range > &second_comp)
 
template<typename Range >
PackagedOperation< Range > operator- (const PackagedOperation< Range > &first_comp, const PackagedOperation< Range > &second_comp)
 
template<typename Range >
PackagedOperation< Range > operator* (const PackagedOperation< Range > &comp, typename Range::value_type number)
 
template<typename Range >
PackagedOperation< Range > operator* (typename Range::value_type number, const PackagedOperation< Range > &comp)
 
template<typename Range >
PackagedOperation< Range > operator+ (const PackagedOperation< Range > &comp, const Range &offset)
 
template<typename Range >
PackagedOperation< Range > operator+ (const Range &offset, const PackagedOperation< Range > &comp)
 
template<typename Range >
PackagedOperation< Range > operator- (const PackagedOperation< Range > &comp, const Range &offset)
 
template<typename Range >
PackagedOperation< Range > operator- (const Range &offset, const PackagedOperation< Range > &comp)
 
Creation of a PackagedOperation object
template<typename Range , typename = std::enable_if_t<internal::PackagedOperationImplementation:: has_vector_interface<Range>::type::value>>
PackagedOperation< Range > operator+ (const Range &u, const Range &v)
 
template<typename Range , typename = std::enable_if_t<internal::PackagedOperationImplementation:: has_vector_interface<Range>::type::value>>
PackagedOperation< Range > operator- (const Range &u, const Range &v)
 
template<typename Range , typename = std::enable_if_t<internal::PackagedOperationImplementation:: has_vector_interface<Range>::type::value>>
PackagedOperation< Range > operator* (const Range &u, typename Range::value_type number)
 
template<typename Range , typename = std::enable_if_t<internal::PackagedOperationImplementation:: has_vector_interface<Range>::type::value>>
PackagedOperation< Range > operator* (typename Range::value_type number, const Range &u)
 
template<typename Range , typename Domain , typename Payload >
PackagedOperation< Range > operator* (const LinearOperator< Range, Domain, Payload > &op, const Domain &u)
 
template<typename Range , typename Domain , typename Payload >
PackagedOperation< Domain > operator* (const Range &u, const LinearOperator< Range, Domain, Payload > &op)
 
template<typename Range , typename Domain , typename Payload >
PackagedOperation< Range > operator* (const LinearOperator< Range, Domain, Payload > &op, const PackagedOperation< Domain > &comp)
 
template<typename Range , typename Domain , typename Payload >
PackagedOperation< Domain > operator* (const PackagedOperation< Range > &comp, const LinearOperator< Range, Domain, Payload > &op)
 
Creation of PackagedOperation objects related to the Schur Complement
template<typename Range_1 , typename Domain_1 , typename Range_2 , typename Payload >
PackagedOperation< Range_2 > condense_schur_rhs (const LinearOperator< Range_1, Domain_1, Payload > &A_inv, const LinearOperator< Range_2, Domain_1, Payload > &C, const Range_1 &f, const Range_2 &g)
 
template<typename Range_1 , typename Domain_1 , typename Domain_2 , typename Payload >
PackagedOperation< Domain_1 > postprocess_schur_solution (const LinearOperator< Range_1, Domain_1, Payload > &A_inv, const LinearOperator< Range_1, Domain_2, Payload > &B, const Domain_2 &y, const Range_1 &f)
 

Detailed Description

template<typename Range>
class PackagedOperation< Range >

A class to store a computation.

The PackagedOperation 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
std::function< void(Range &v)> apply_add

Similar to the LinearOperator 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> a, b, c, d;
// ..
Vector<double> result = a + b - c + d;

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 PackagedOperation<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 PackagedOperation object is implicitly converted:

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

Definition at line 105 of file packaged_operation.h.

Constructor & Destructor Documentation

◆ PackagedOperation() [1/3]

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

Create an empty PackagedOperation 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.h.

◆ PackagedOperation() [2/3]

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

Default copy constructor.

◆ PackagedOperation() [3/3]

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

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

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

Definition at line 148 of file packaged_operation.h.

Member Function Documentation

◆ operator=() [1/2]

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

Default copy assignment operator.

◆ operator=() [2/2]

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

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

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

Definition at line 169 of file packaged_operation.h.

◆ operator Range()

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

Convert a PackagedOperation to its result.

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

Definition at line 188 of file packaged_operation.h.

◆ operator+=() [1/2]

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

Addition with a PackagedOperation second_comp with the same Range.

Definition at line 207 of file packaged_operation.h.

◆ operator-=() [1/2]

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

Subtraction with a PackagedOperation second_comp with the same Range.

Definition at line 218 of file packaged_operation.h.

◆ operator+=() [2/2]

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

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

Definition at line 229 of file packaged_operation.h.

◆ operator-=() [2/2]

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

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

Definition at line 240 of file packaged_operation.h.

◆ operator*=()

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

Scalar multiplication of the PackagedOperation with a number.

Definition at line 250 of file packaged_operation.h.

Member Data Documentation

◆ apply

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

Store the result of the PackagedOperation in a vector v of the Range space.

Definition at line 261 of file packaged_operation.h.

◆ apply_add

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

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

Definition at line 267 of file packaged_operation.h.

◆ reinit_vector

template<typename Range >
std::function<void(Range &v, bool omit_zeroing_entries)> PackagedOperation< 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 276 of file packaged_operation.h.


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