ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
test
vector
vector/test_11.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
13
14
#include "
ROL_StdArray.hpp
"
15
#include "
ROL_StdVector.hpp
"
16
#include "
ROL_Stream.hpp
"
17
#include "ROL_GlobalMPISession.hpp"
18
19
#include <iostream>
20
21
using
RealT
= double;
22
23
constexpr
auto
dim
= 100u;
24
25
int
main
(
int
argc,
char
*argv[]) {
26
27
ROL::GlobalMPISession mpiSession(&argc, &argv);
28
29
ROL::StdArray<RealT,dim>::initialize_pool
();
30
31
int
iprint = argc - 1;
32
ROL::Ptr<std::ostream> outStream;
33
ROL::nullstream
bhs;
// outputs nothing
34
if
(iprint > 0) outStream = ROL::makePtrFromRef(std::cout);
35
else
outStream = ROL::makePtrFromRef(bhs);
36
37
auto
print_pool_count = [&outStream]() {
38
*outStream <<
"Currently using "
<<
ROL::StdArray<RealT, dim>::pool_count
()
39
<<
" Vectors from the pool"
<< std::endl;
40
};
41
42
int
errorFlag = 0;
43
44
RealT
errtol =
ROL::ROL_THRESHOLD<RealT>
();
45
46
// *** Test body.
47
48
print_pool_count();
49
50
try
{
51
52
53
ROL::StdArray<RealT, dim>
x, y, z;
54
55
print_pool_count();
56
57
x.
randomize
();
58
y.
randomize
();
59
z.
randomize
();
60
61
// Standard tests.
62
auto
consistency = x.
checkVector
(y, z,
true
, *outStream);
63
ROL::StdVector<RealT>
checkvec( ROL::makePtrFromRef(consistency) );
64
65
if
(checkvec.
norm
() > std::sqrt(
ROL::ROL_EPSILON<RealT>
())) errorFlag++;
66
67
// Basis tests.
68
// set x to first basis vector
69
auto
zp = x.
clone
();
70
zp = x.
basis
(0);
71
RealT
znorm = zp->norm();
72
*outStream <<
"Norm of ROL::Vector z (first basis vector): "
<< znorm <<
"\n"
;
73
if
( std::abs(znorm-1.0) > errtol ) {
74
*outStream <<
"---> POSSIBLE ERROR ABOVE!\n"
;
75
errorFlag++;
76
};
77
78
// set x to middle basis vector
79
zp = x.
basis
(
dim
/2);
80
znorm = zp->norm();
81
*outStream <<
"\nNorm of ROL::Vector z ('middle' basis vector): "
<< znorm <<
"\n"
;
82
if
( std::abs(znorm-1.0) > errtol ) {
83
*outStream <<
"---> POSSIBLE ERROR ABOVE!\n"
;
84
errorFlag++;
85
};
86
87
// set x to last basis vector
88
zp = x.
basis
(
dim
-1);
89
znorm = zp->norm();
90
*outStream <<
"\nNorm of ROL::Vector z (last basis vector): "
<< znorm <<
"\n"
;
91
if
( std::abs(znorm-1.0) > errtol ) {
92
*outStream <<
"---> POSSIBLE ERROR ABOVE!\n"
;
93
errorFlag++;
94
};
95
96
// Repeat the checkVector tests with a zero vector.
97
x.
scale
(0.0);
98
consistency = x.
checkVector
(x, x,
true
, *outStream);
99
if
(checkvec.
norm
() > 0.0) {
100
errorFlag++;
101
}
102
103
print_pool_count();
104
}
105
catch
(std::logic_error& err) {
106
*outStream << err.what() <<
"\n"
;
107
errorFlag = -1000;
108
};
// end try
109
110
print_pool_count();
111
112
if
(errorFlag != 0) std::cout <<
"End Result: TEST FAILED\n"
;
113
else
std::cout <<
"End Result: TEST PASSED\n"
;
114
115
116
return
0;
117
118
}
119
ROL_StdArray.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::ROL::Vector::checkVector
virtual std::vector< Real > checkVector(const Vector< Real > &x, const Vector< Real > &y, const bool printToStream=true, std::ostream &outStream=std::cout) const
Verify vector-space methods.
Definition
ROL_Constraint_SerialSimOpt.hpp:292
ROL::StdArray
Provides the std::array implementation of the ROL::Vector interface.
Definition
ROL_StdArray.hpp:28
ROL::StdArray::randomize
void randomize(const Real l=-1.0, const Real u=1.0)
Set vector to be uniform random between [l,u].
Definition
ROL_StdArray.hpp:119
ROL::StdArray::initialize_pool
static void initialize_pool()
Definition
ROL_StdArray.hpp:131
ROL::StdArray::pool_count
static std::size_t pool_count()
Definition
ROL_StdArray.hpp:136
ROL::StdArray::scale
void scale(const Real alpha)
Compute where .
Definition
ROL_StdArray.hpp:67
ROL::StdArray::basis
Ptr< Vector< Real > > basis(const int i) const
Return i-th basis vector.
Definition
ROL_StdArray.hpp:88
ROL::StdArray::clone
virtual Ptr< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
Definition
ROL_StdArray.hpp:84
ROL::StdVector
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Definition
ROL_StdVector.hpp:27
ROL::StdVector::norm
Real norm() const
Returns where .
Definition
ROL_StdVector.hpp:109
RealT
double RealT
Definition
function/constraint/test_01.cpp:29
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
ROL::ROL_THRESHOLD
Real ROL_THRESHOLD(void)
Tolerance for various equality tests.
Definition
ROL_Types.hpp:63
main
int main(int argc, char *argv[])
Definition
vector/test_11.cpp:25
dim
constexpr auto dim
Definition
vector/test_11.cpp:23
Generated by
1.17.0