ROL
ROL_BlockOperator2Diagonal.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Rapid Optimization Library (ROL) Package
4//
5// Copyright 2014 NTESS and the ROL contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef ROL_BLOCKOPERATOR2DIAGONAL_H
11#define ROL_BLOCKOPERATOR2DIAGONAL_H
12
14
25namespace ROL {
26
27template<class Real>
29
30 typedef Vector<Real> V; // ROL Vector
31 typedef PartitionedVector<Real> PV; // ROL PartitionedVector
32 typedef LinearOperator<Real> OP; // Linear Operator
33
34private:
35
36 ROL::Ptr<OP> A_, D_;
37
38public:
39
40 BlockOperator2Diagonal( ROL::Ptr<OP> &A, ROL::Ptr<OP> &D ) : A_(A), D_(D) {}
41
42 }
43
44 void apply( V &Hv, const V &v, Real &tol ) const {
45
47 PV &Hv_pv = dynamic_cast<PV&>(Hv);
48 const PV &v_pv = dynamic_cast<const PV&>(v);
49
50 ROL::Ptr<V> Hv1 = Hv_pv.get(0);
51 ROL::Ptr<V> Hv2 = Hv_pv.get(1);
52 ROL::Ptr<const V> v1 = v_pv.get(0);
53 ROL::Ptr<const V> v2 = v_pv.get(1);
54
55 A_->apply(*Hv1,*v1,tol);
56 D_->apply(*Hv2,*v2,tol);
57
58 }
59
60
61 void applyInverse( V &Hv, const V &v Real &tol ) const {
62
63
64 PV &Hv_pv = dynamic_cast<PV&>(Hv);
65 const PV &v_pv = dynamic_cast<const PV&>(v);
66
67 ROL::Ptr<V> Hv1 = Hv_pv.get(0);
68 ROL::Ptr<V> Hv2 = Hv_pv.get(1);
69 ROL::Ptr<const V> v1 = v_pv.get(0);
70 ROL::Ptr<const V> v2 = v_pv.get(1);
71
72 A_->applyInverse(*Hv1,*v1,tol);
73 D_->applyInverse(*Hv2,*v2,tol);
74
75 }
76
77 ROL::Ptr<LinearOperator<Real> > getOperator( int row, int col ) const {
78 if( row == 0 && col == 0 ) {
79 return A_;
80 }
81 else if( row == 1 && col == 1 ) {
82 return D_;
83 }
84 else {
85 ROL_TEST_FOR_EXCEPTION( true, std::invalid_argument,
86 ">>> ERROR (ROL_BlockOperator2Diagonal, getOperator): "
87 "invalid block indices.");
88 }
89
90 }
91
92
93}; // class BlockOperator2Diagonal
94
95} // namespace ROL
96
97#endif // ROL_BLOCKOPERATOR2DIAGONAL_H
ROL::Ptr< OP > A_
Vector< Real > V
PartitionedVector< Real > PV
ROL::Ptr< OP > D_
Provides the interface to apply a 2x2 block diagonal operator to a partitioned vector.
BlockOperator2Diagonal(ROL::Ptr< OP > &A, ROL::Ptr< OP > &D)
Provides the interface to apply a 2x2 block operator to a partitioned vector.
void apply(V &Hv, const V &v, Real &tol) const
Apply linear operator.
Provides the interface to apply a linear operator.
Defines the linear algebra of vector space on a generic partitioned vector.
Defines the linear algebra or vector space interface.
ROL::BlockOperator2Diagonal BlockOperator2 apply(V &Hv, const V &v, Real &tol) const
ROL::Ptr< LinearOperator< Real > > getOperator(int row, int col) const
void applyInverse(V &Hv, const V &v Real &tol) const