Reference documentation for deal.II version 9.1.0-pre
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 Functions

(Note that these are not member functions.)

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 = typename std::enable_if< internal::PackagedOperationImplementation::has_vector_interface< Range>::type::value>::type>
PackagedOperation< 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>
PackagedOperation< 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>
PackagedOperation< 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>
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;

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;

As an example consider the addition of multiple vectors

// ..
::Vector<double> result = a + b - c + d;

or the computation of a residual \(b-Ax\):

// ..
const auto op_a = linear_operator(A);
::Vector<double> residual = b - op_a * x;

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;
Author
Matthias Maier, 2015

Definition at line 35 of file packaged_operation.h.

Constructor & Destructor Documentation

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 109 of file packaged_operation.h.

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

Default copy constructor.

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 144 of file packaged_operation.h.

Member Function Documentation

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

Default copy assignment operator.

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 165 of file packaged_operation.h.

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 184 of file packaged_operation.h.

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 203 of file packaged_operation.h.

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 214 of file packaged_operation.h.

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 225 of file packaged_operation.h.

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 236 of file packaged_operation.h.

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 246 of file packaged_operation.h.

Member Data Documentation

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 257 of file packaged_operation.h.

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 263 of file packaged_operation.h.

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 272 of file packaged_operation.h.


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