ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
test
function
function/test_12.cpp
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
14
15
16
#include "
ROL_HouseholderReflector.hpp
"
17
#include "
ROL_StdVector.hpp
"
18
#include "
ROL_RandomVector.hpp
"
19
#include "
ROL_Stream.hpp
"
20
#include "ROL_GlobalMPISession.hpp"
21
22
template
<
class
Real>
23
void
printVector
(
const
ROL::Vector<Real>
&x, std::ostream &outStream ) {
24
25
ROL::Ptr<const std::vector<Real> > xp =
26
dynamic_cast<
const
ROL::StdVector<Real>
&
>
(x).getVector();
27
28
outStream <<
"Standard Vector"
<< std::endl;
29
for
(
size_t
i=0; i<xp->size(); ++i ) {
30
outStream << (*xp)[i] << std::endl;
31
}
32
}
33
34
35
36
typedef
double
RealT
;
37
38
int
main
(
int
argc,
char
*argv[]) {
39
40
typedef
ROL::Vector<RealT>
V
;
41
typedef
ROL::StdVector<RealT>
SV;
42
43
44
45
ROL::GlobalMPISession mpiSession(&argc, &argv);
46
47
// This little trick lets us print to std::cout only if a (dummy) command-line argument is provided.
48
int
iprint = argc - 1;
49
ROL::Ptr<std::ostream> outStream;
50
ROL::nullstream
bhs;
// outputs nothing
51
if
(iprint > 0)
52
outStream = ROL::makePtrFromRef(std::cout);
53
else
54
outStream = ROL::makePtrFromRef(bhs);
55
56
int
errorFlag = 0;
57
58
try
{
59
60
int
dim
= 10;
61
62
RealT
tol = std::sqrt(
ROL::ROL_EPSILON<RealT>
());
63
64
ROL::Ptr<V> v = ROL::makePtr<SV>( ROL::makePtr<std::vector<RealT>>(
dim
) );
65
ROL::Ptr<V> Hv = v->clone();
66
ROL::Ptr<V> HHv = v->clone();
67
68
ROL::Ptr<V> e0 = v->basis(0);
69
70
RandomizeVector(*v);
71
72
ROL::HouseholderReflector<RealT>
H(v,e0);
73
74
// Reflect v about a vector to the x direction
75
// Verify that the result is parallel to x
76
77
printVector
(*v,*outStream);
78
79
H.
apply
(*Hv, *v, tol);
80
81
printVector
(*Hv,*outStream);
82
83
H.
apply
(*HHv, *Hv, tol);
84
85
printVector
(*HHv,*outStream);
86
87
}
88
89
catch
(std::logic_error& err) {
90
*outStream << err.what() <<
"\n"
;
91
errorFlag = -1000;
92
};
// end try
93
94
if
(errorFlag != 0)
95
std::cout <<
"End Result: TEST FAILED\n"
;
96
else
97
std::cout <<
"End Result: TEST PASSED\n"
;
98
99
return
0;
100
}
101
102
V
Vector< Real > V
Definition
ROL_BlockOperator2Diagonal.hpp:46
ROL_HouseholderReflector.hpp
ROL_RandomVector.hpp
ROL_StdVector.hpp
ROL_Stream.hpp
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
ROL::HouseholderReflector
Provides the interface to create a Householder reflector operator, that when applied to a vector x,...
Definition
ROL_HouseholderReflector.hpp:41
ROL::HouseholderReflector::apply
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Definition
ROL_HouseholderReflector.hpp:69
ROL::StdVector
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Definition
ROL_StdVector.hpp:27
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
RealT
double RealT
Definition
function/constraint/test_01.cpp:29
main
int main(int argc, char *argv[])
Definition
function/test_12.cpp:38
printVector
void printVector(const ROL::Vector< Real > &x, std::ostream &outStream)
Definition
function/test_12.cpp:23
ROL::details::nullstream
basic_nullstream< char, std::char_traits< char > > nullstream
Definition
ROL_Stream.hpp:36
ROL::ROL_EPSILON
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.
Definition
ROL_Types.hpp:57
dim
constexpr auto dim
Definition
vector/test_11.cpp:23
Generated by
1.17.0