35 #include "Teuchos_GlobalMPISession.hpp"
36 #include "Teuchos_XMLParameterListHelpers.hpp"
40 int main(
int argc,
char *argv[]) {
42 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
45 int iprint = argc - 1;
46 ROL::Ptr<std::ostream> outStream;
49 outStream = ROL::makePtrFromRef(std::cout);
51 outStream = ROL::makePtrFromRef(bhs);
61 ROL::ParameterList parlist;
63 std::string jsonFileName(
"parameters.json");
64 parlist.setName(
"Imported from " + jsonFileName);
68 std::string stepname =
"Trust Region";
71 ROL::Ptr<ROL::Step<RealT> > step = stepFactory.
getStep(stepname, parlist);
74 RealT gtol = parlist.get(
"Gradient Tolerance",1e-12);
75 RealT stol = parlist.get(
"Step Tolerance",1e-14);
76 int maxit = parlist.get(
"Maximum Number of Iterations",100);
77 ROL::Ptr<ROL::StatusTest<RealT> > status = ROL::makePtr<ROL::StatusTest<RealT>>(gtol, stol, maxit);
81 ROL::Ptr<std::vector<RealT> > x_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 1.0);
82 ROL::Ptr<std::vector<RealT> > k_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
85 ROL::Ptr<ROL::Vector<RealT> > k = ROL::makePtr<ROL::StdVector<RealT>>(k_ptr);
87 for(
int i=0;i<
dim;++i) {
94 algo.run(x, obj,
true, *outStream);
97 ROL::Ptr<std::vector<RealT> > xtrue_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
103 *outStream << std::scientific <<
"\n Absolute Error: " << abserr;
104 if ( abserr > sqrt(ROL::ROL_EPSILON<RealT>())) ) {
109 Teuchos::writeParameterListToXmlFile(parlist,
"parameters.xml");
112 catch (std::logic_error& err) {
113 *outStream << err.what() <<
"\n";
118 std::cout <<
"End Result: TEST FAILED\n";
120 std::cout <<
"End Result: TEST PASSED\n";
void axpy(const Real alpha, const Vector< Real > &x)
Compute where .
void stepFactory(ROL::ParameterList &parlist, ROL::Ptr< ROL::Step< Real > > &step)
A minimalist step factory which specializes the Step Type depending on whether a Trust-Region or Line...
ROL::Ptr< Step< Real > > getStep(const std::string &type, ROL::ParameterList &parlist) const
void JSON_Parameters(const std::string &jsonFileName, ROL::ParameterList &parlist)
Read a JSON file and store all parameters in a ROL::ParameterList. Checks for a key called "Algorithm...
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
basic_nullstream< char, std::char_traits< char >> nullstream
Real norm() const
Returns where .
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Provides an interface to run optimization algorithms.
Contains definitions for the Zakharov function as evaluated using only the ROL::Vector interface...
int main(int argc, char *argv[])