ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
function
operator
ROL_BlockOperator.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_BLOCKOPERATOR_H
11
#define ROL_BLOCKOPERATOR_H
12
13
#include "
ROL_LinearOperator.hpp
"
14
#include "
ROL_PartitionedVector.hpp
"
15
23
24
namespace
ROL
{
25
26
template
<
class
Real>
27
class
BlockOperator
:
public
LinearOperator
<Real> {
28
29
typedef
Vector<Real>
V
;
// ROL Vector
30
typedef
PartitionedVector<Real>
PV
;
// Partitioned Vector
31
typedef
LinearOperator<Real>
OP
;
// Linear Operator
32
33
typedef
std::vector<ROL::Ptr<OP> >
OpVec
;
// Vector (column-stacked matrix) of pointers to operators
34
typedef
typename
OpVec::size_type
uint
;
// index type
35
36
private
:
37
38
ROL::Ptr<OpVec>
blocks_
;
39
40
public
:
41
BlockOperator
() {}
42
BlockOperator
(
const
ROL::Ptr<OpVec> &blocks ) :
blocks_
(blocks) {}
43
44
virtual
void
apply
(
V
&Hv,
const
V
&v, Real &tol )
const
{
45
46
// Downcast to Partitioned Vectors
47
PV
&Hv_part =
dynamic_cast<
PV
&
>
(Hv);
48
const
PV
&v_part =
dynamic_cast<
const
PV
&
>
(v);
49
50
uint
nvec1 = v_part.
numVectors
();
51
uint
nvec2 = Hv_part.
numVectors
();
52
uint
nblks =
blocks_
->size();
53
54
ROL_TEST_FOR_EXCEPTION( (nvec1 != nvec2), std::invalid_argument,
55
">>> ERROR (ROL_BlockOperator, apply): "
56
"Mismatch between input and output number of subvectors."
);
57
58
ROL_TEST_FOR_EXCEPTION( (nblks != nvec1*nvec2 ) , std::invalid_argument,
59
">>> ERROR (ROL_BlockOperator, apply): "
60
"Block operator dimension mismatch."
);
61
62
for
(
uint
i=0; i<nvec1; ++i ) {
63
64
ROL::Ptr<V> Hvi = Hv_part.
get
(i);
65
ROL::Ptr<V> u = Hvi->clone();
66
67
u->zero();
68
69
for
(
uint
j=0; j<nvec2; ++j ) {
70
uint
k = i+nvec1*j;
71
(*blocks_)[k]->apply(*u,*v_part.
get
(j),tol);
72
Hvi->plus(*u);
73
}
74
}
75
}
76
77
78
};
// class BlockOperator
79
80
}
// namespace ROL
81
82
#endif
// ROL_BLOCKOPERATOR_H
ROL_LinearOperator.hpp
ROL_PartitionedVector.hpp
ROL::BlockOperator::apply
virtual void apply(V &Hv, const V &v, Real &tol) const
Definition
ROL_BlockOperator.hpp:44
ROL::BlockOperator::OpVec
std::vector< ROL::Ptr< OP > > OpVec
Definition
ROL_BlockOperator.hpp:33
ROL::BlockOperator::OP
LinearOperator< Real > OP
Definition
ROL_BlockOperator.hpp:31
ROL::BlockOperator::blocks_
ROL::Ptr< OpVec > blocks_
Definition
ROL_BlockOperator.hpp:38
ROL::BlockOperator::PV
PartitionedVector< Real > PV
Definition
ROL_BlockOperator.hpp:30
ROL::BlockOperator::uint
OpVec::size_type uint
Definition
ROL_BlockOperator.hpp:34
ROL::BlockOperator::V
Vector< Real > V
Definition
ROL_BlockOperator.hpp:29
ROL::BlockOperator::BlockOperator
BlockOperator()
Definition
ROL_BlockOperator.hpp:41
ROL::BlockOperator::BlockOperator
BlockOperator(const ROL::Ptr< OpVec > &blocks)
Definition
ROL_BlockOperator.hpp:42
ROL::LinearOperator
Provides the interface to apply a linear operator.
Definition
ROL_LinearOperator.hpp:37
ROL::PartitionedVector
Defines the linear algebra of vector space on a generic partitioned vector.
Definition
ROL_PartitionedVector.hpp:26
ROL::PartitionedVector::get
ROL::Ptr< const Vector< Real > > get(size_type i) const
Definition
ROL_PartitionedVector.hpp:221
ROL::PartitionedVector::numVectors
size_type numVectors() const
Definition
ROL_PartitionedVector.hpp:237
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
ROL
Definition
ROL_ElementwiseVector.hpp:27
Generated by
1.17.0