ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
test
step
step/test_17.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_GetTestProblems.hpp
"
15
#include "
ROL_OptimizationSolver.hpp
"
16
#include "
ROL_Stream.hpp
"
17
#include "ROL_GlobalMPISession.hpp"
18
19
#include <iostream>
20
21
typedef
double
RealT
;
22
23
int
main
(
int
argc,
char
*argv[]) {
24
25
ROL::GlobalMPISession mpiSession(&argc, &argv);
26
27
// This little trick lets us print to std::cout only if a (dummy) command-line argument is provided.
28
int
iprint = argc - 1;
29
ROL::Ptr<std::ostream> outStream;
30
ROL::nullstream
bhs;
// outputs nothing
31
if
(iprint > 0)
32
outStream = ROL::makePtrFromRef(std::cout);
33
else
34
outStream = ROL::makePtrFromRef(bhs);
35
36
int
errorFlag = 0;
37
38
// *** Test body.
39
40
try
{
41
std::string filename =
"input.xml"
;
42
auto
parlist = ROL::getParametersFromXmlFile( filename );
43
44
// Setup optimization problem
45
ROL::Ptr<ROL::Vector<RealT>> x0;
46
std::vector<ROL::Ptr<ROL::Vector<RealT>>> z;
47
ROL::Ptr<ROL::OptimizationProblem<RealT>> optProblem;
48
ROL::GetTestProblem<RealT>
(optProblem,x0,z,
ROL::TESTOPTPROBLEM_CANTILEVERBEAM
);
49
50
// Get Dimension of Problem
51
// int dim = x0->dimension();
52
// parlist->sublist("General").sublist("Krylov").set("Iteration Limit", 2*dim);
53
54
// Check Derivatives
55
optProblem->check(*outStream);
56
57
// Error Vector
58
// ROL::Ptr<ROL::Vector<RealT>> e = x0->clone();
59
// e->zero();
60
61
// Setup optimization solver
62
parlist->sublist(
"Status Test"
).set(
"Gradient Tolerance"
,
static_cast<
RealT
>
(1e-6));
63
parlist->sublist(
"Step"
).set(
"Type"
,
"Fletcher"
);
64
ROL::OptimizationSolver<RealT>
optSolver(*optProblem,*parlist);
65
optSolver.
solve
(*outStream);
66
67
// Compute Error
68
// RealT err(0);
69
// for (int i = 0; i < static_cast<int>(z.size()); ++i) {
70
// e->set(*x0);
71
// e->axpy(-1.0,*z[i]);
72
// if (i == 0) {
73
// err = e->norm();
74
// }
75
// else {
76
// err = std::min(err,e->norm());
77
// }
78
// }
79
// *outStream << std::endl << "Norm of Error: " << err << std::endl;
80
//
81
// RealT tol = static_cast<RealT>(1e-3)*std::max(z[0]->norm(),static_cast<RealT>(1));
82
// errorFlag += ((err < tol) ? 0 : 1);
83
}
84
catch
(std::logic_error& err) {
85
*outStream << err.what() << std::endl;
86
errorFlag = -1000;
87
};
// end try
88
89
if
(errorFlag != 0)
90
std::cout <<
"End Result: TEST FAILED"
<< std::endl;
91
else
92
std::cout <<
"End Result: TEST PASSED"
<< std::endl;
93
94
return
0;
95
96
}
97
ROL_GetTestProblems.hpp
Contains definitions of test objective functions.
ROL_OptimizationSolver.hpp
ROL_Stream.hpp
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
ROL::OptimizationSolver
Provides a simplified interface for solving a wide range of optimization problems.
Definition
ROL_OptimizationSolver.hpp:29
ROL::OptimizationSolver::solve
int solve(const ROL::Ptr< StatusTest< Real > > &status=ROL::nullPtr, const bool combineStatus=true)
Solve optimization problem with no iteration output.
Definition
ROL_OptimizationSolver.hpp:180
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::TESTOPTPROBLEM_CANTILEVERBEAM
@ TESTOPTPROBLEM_CANTILEVERBEAM
Definition
ROL_GetTestProblems.hpp:158
ROL::GetTestProblem
void GetTestProblem(Ptr< OptimizationProblem< Real > > &problem, Ptr< Vector< Real > > &x0, std::vector< Ptr< Vector< Real > > > &x, const ETestOptProblem test)
Definition
ROL_GetTestProblems.hpp:309
main
int main(int argc, char *argv[])
Definition
step/test_17.cpp:23
Generated by
1.17.0