16 #include "Teuchos_GlobalMPISession.hpp"
22 #include "ROL_UnaryFunctions.hpp"
29 a.
applyUnary(ROL::Elementwise::AbsoluteValue<RealT>());
30 return a.
reduce(ROL::Elementwise::ReductionMax<RealT>());
34 ROL::Ptr<std::ostream> outStream) {
40 ROL::Ptr<std::vector<RealT>> vsv
41 = ROL::makePtr<std::vector<RealT>>(numPoints, 0.0);
42 ROL::Ptr<std::vector<RealT>> xsv
43 = ROL::makePtr<std::vector<RealT>>(numPoints, 0.0);
44 ROL::Ptr<std::vector<RealT>> gsv
45 = ROL::makePtr<std::vector<RealT>>(numPoints, 0.0);
46 ROL::Ptr<std::vector<RealT>> lsv
47 = ROL::makePtr<std::vector<RealT>>(numPoints, 0.0);
48 ROL::Ptr<std::vector<RealT>> usv
49 = ROL::makePtr<std::vector<RealT>>(numPoints, 0.0);
51 ROL::Ptr<std::vector<RealT>> out1sv
52 = ROL::makePtr<std::vector<RealT>>(numPoints, 0.0);
53 ROL::Ptr<std::vector<RealT>> out2sv
54 = ROL::makePtr<std::vector<RealT>>(numPoints, 0.0);
61 ROL::Ptr<ROL::Vector<RealT>> lp = ROL::makePtr<ROL::StdVector<RealT>>(lsv);
62 ROL::Ptr<ROL::Vector<RealT>> up = ROL::makePtr<ROL::StdVector<RealT>>(usv);
67 lp->randomize(-10.0, 10.0);
68 up->randomize( 0.0, 10.0);
82 out1.applyUnary(ROL::Elementwise::Reciprocal<RealT>());
84 out2.
applyUnary(ROL::Elementwise::Reciprocal<RealT>());
86 errorFlag += errorInftyNorm > tol;
88 *outStream << std::endl;
89 *outStream <<
"Scaling Check at " << numPoints
90 <<
" Randomly Sampled Points -- " << std::endl
91 <<
" Infinity Norm of | v - 1/f(1/f(v)) | = "
92 << errorInftyNorm << std::endl;
93 *outStream << std::endl;
109 : boundsBC_(boundsBC), g_(g), v_(g) {
115 RealT& tol)
override {
116 boundsBC_.applyInverseScalingFunction(c, v_, x, g_);
117 c.
applyUnary( ROL::Elementwise::Reciprocal<RealT>());
118 c.
applyBinary(ROL::Elementwise::Multiply<RealT>(), g_);
123 boundsBC_.applyScalingFunctionJacobian(jv, v, x, g_);
125 } testWrapper(boundsBC, g);
132 out1.randomize(-1.0, 1.0);
135 out2.
scale(1 - gamma);
136 out1.applyBinary(ROL::Elementwise::Multiply<RealT>(), out2);
141 *outStream <<
"Elementwise Jacobian Check:" << std::endl;
142 testWrapper.checkApplyJacobian(out1, v, out2,
true, *outStream, 15);
143 *outStream << std::endl;
151 errorInftyNorm = 100;
153 errorFlag += errorInftyNorm > tol;
155 *outStream <<
"Consistency Check at " << numPoints
156 <<
" Randomly Sampled Points -- " << std::endl
157 <<
" Infinity Norm of | StdBoundConstraint - Elementwise |:"
159 <<
" Inverse = " << errorInftyNorm << std::endl;
164 errorFlag += errorInftyNorm > tol;
166 *outStream <<
" Jacobian = " << errorInftyNorm << std::endl;
167 *outStream << std::endl;
180 std::vector<RealT> ewErrors, svErrors;
183 ROL::Ptr<std::vector<RealT>> vsv
184 = ROL::makePtr<std::vector<RealT>>(numCases, 0.0);
185 ROL::Ptr<std::vector<RealT>> xsv
186 = ROL::makePtr<std::vector<RealT>>(numCases, 0.0);
187 ROL::Ptr<std::vector<RealT>> gsv
188 = ROL::makePtr<std::vector<RealT>>(numCases, 0.0);
189 ROL::Ptr<std::vector<RealT>> lsv
190 = ROL::makePtr<std::vector<RealT>>(numCases, 0.0);
191 ROL::Ptr<std::vector<RealT>> usv
192 = ROL::makePtr<std::vector<RealT>>(numCases, 0.0);
194 ROL::Ptr<std::vector<RealT>> resultp
195 = ROL::makePtr<std::vector<RealT>>(numCases, 0.0);
196 ROL::Ptr<std::vector<RealT>> targetp
197 = ROL::makePtr<std::vector<RealT>>(numCases, 0.0);
204 ROL::Ptr<ROL::Vector<RealT>> lp = ROL::makePtr<ROL::StdVector<RealT>>(lsv);
205 ROL::Ptr<ROL::Vector<RealT>> up = ROL::makePtr<ROL::StdVector<RealT>>(usv);
220 (*lsv)[1] = ROL::ROL_NINF<RealT>();
221 (*usv)[1] = ROL::ROL_INF<RealT>();
228 (*usv)[2] = ROL::ROL_INF<RealT>();
234 (*targetp)[0] = (*vsv)[0]*(*gsv)[0];
235 (*targetp)[1] = (*vsv)[1]*1.0;
236 (*targetp)[2] = (*vsv)[2]*1.0;
238 target.
applyBinary(ROL::Elementwise::DivideAndInvert<RealT>(), v);
239 target.
applyBinary(ROL::Elementwise::Multiply<RealT>(), v);
240 boundsBC.applyInverseScalingFunction(result, v, x, g);
241 ewErrors.push_back(
calcError(result, target));
243 svErrors.push_back(
calcError(result, target));
246 (*targetp)[0] = (*vsv)[0]*(*gsv)[0];
249 boundsBC.applyScalingFunctionJacobian(result, v, x, g);
250 ewErrors.push_back(
calcError(result, target));
252 svErrors.push_back(
calcError(result, target));
254 *outStream <<
"Elementwise Test Case Errors (Infinity Norm):" << std::endl
255 <<
" Inverse = " << ewErrors[1] << std::endl
256 <<
" Jacobian = " << ewErrors[2] << std::endl;
257 *outStream <<
"StdBoundConstraint Test Case Errors (Infinity Norm):" << std::endl
258 <<
" Inverse = " << svErrors[1] << std::endl
259 <<
" Jacobian = " << svErrors[2] << std::endl;
260 *outStream << std::endl;
262 RealT maxError = std::max(*std::max_element(svErrors.begin(), svErrors.end()),
263 *std::max_element(ewErrors.begin(), ewErrors.end()));
264 return maxError > tol;
267 int main(
int argc,
char *argv[]) {
269 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
273 int iprint = argc - 1;
274 ROL::Ptr<std::ostream> outStream;
277 outStream = ROL::makePtrFromRef(std::cout);
279 outStream = ROL::makePtrFromRef(bhs);
292 catch (std::logic_error& err) {
293 *outStream << err.what() <<
"\n";
298 std::cout <<
"End Result: TEST FAILED\n";
300 std::cout <<
"End Result: TEST PASSED\n";
Contains definitions for std::vector bound constraints.
virtual void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
void axpy(const Real alpha, const Vector< Real > &x)
Compute where .
void scale(const Real alpha)
Compute where .
int testCases(RealT tol, ROL::Ptr< std::ostream > outStream)
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
RealT calcError(ROL::Vector< RealT > &a, const ROL::Vector< RealT > &b)
void randomize(const Real l=0.0, const Real u=1.0)
Set vector to be uniform random between [l,u].
virtual Real reduce(const Elementwise::ReductionOp< Real > &r) const
virtual void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector &x)
void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector< Real > &x)
Defines the linear algebra or vector space interface.
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
virtual void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)=0
Evaluate the constraint operator at .
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
void applyInverseScalingFunction(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const override
Apply inverse scaling function.
Provides the elementwise interface to apply upper and lower bound constraints.
virtual void applyUnary(const Elementwise::UnaryFunction< Real > &f)
void set(const Vector< Real > &x)
Set where .
void applyScalingFunctionJacobian(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const override
Apply scaling function Jacobian.
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
void applyInverseScalingFunction(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const override
Apply inverse scaling function.
void projectInterior(Vector< Real > &x) override
Project optimization variables into the interior of the feasible set.
int testRandomInputs(int numPoints, RealT tol, ROL::Ptr< std::ostream > outStream)
void applyScalingFunctionJacobian(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const override
Apply scaling function Jacobian.
Defines the general constraint operator interface.