50 #include "Teuchos_GlobalMPISession.hpp"
56 #include "ROL_UnaryFunctions.hpp"
63 a.
applyUnary(ROL::Elementwise::AbsoluteValue<RealT>());
64 return a.
reduce(ROL::Elementwise::ReductionMax<RealT>());
68 ROL::Ptr<std::ostream> outStream) {
74 ROL::Ptr<std::vector<RealT>> vsv
75 = ROL::makePtr<std::vector<RealT>>(numPoints, 0.0);
76 ROL::Ptr<std::vector<RealT>> xsv
77 = ROL::makePtr<std::vector<RealT>>(numPoints, 0.0);
78 ROL::Ptr<std::vector<RealT>> gsv
79 = ROL::makePtr<std::vector<RealT>>(numPoints, 0.0);
80 ROL::Ptr<std::vector<RealT>> lsv
81 = ROL::makePtr<std::vector<RealT>>(numPoints, 0.0);
82 ROL::Ptr<std::vector<RealT>> usv
83 = ROL::makePtr<std::vector<RealT>>(numPoints, 0.0);
85 ROL::Ptr<std::vector<RealT>> out1sv
86 = ROL::makePtr<std::vector<RealT>>(numPoints, 0.0);
87 ROL::Ptr<std::vector<RealT>> out2sv
88 = ROL::makePtr<std::vector<RealT>>(numPoints, 0.0);
95 ROL::Ptr<ROL::Vector<RealT>> lp = ROL::makePtr<ROL::StdVector<RealT>>(lsv);
96 ROL::Ptr<ROL::Vector<RealT>> up = ROL::makePtr<ROL::StdVector<RealT>>(usv);
101 lp->randomize(-10.0, 10.0);
102 up->randomize( 0.0, 10.0);
116 out1.applyUnary(ROL::Elementwise::Reciprocal<RealT>());
118 out2.
applyUnary(ROL::Elementwise::Reciprocal<RealT>());
120 errorFlag += errorInftyNorm > tol;
122 *outStream << std::endl;
123 *outStream <<
"Scaling Check at " << numPoints
124 <<
" Randomly Sampled Points -- " << std::endl
125 <<
" Infinity Norm of | v - 1/f(1/f(v)) | = "
126 << errorInftyNorm << std::endl;
127 *outStream << std::endl;
143 : boundsBC_(boundsBC), g_(g), v_(g) {
149 RealT& tol)
override {
150 boundsBC_.applyInverseScalingFunction(c, v_, x, g_);
151 c.
applyUnary( ROL::Elementwise::Reciprocal<RealT>());
152 c.
applyBinary(ROL::Elementwise::Multiply<RealT>(), g_);
157 boundsBC_.applyScalingFunctionJacobian(jv, v, x, g_);
159 } testWrapper(boundsBC, g);
166 out1.randomize(-1.0, 1.0);
169 out2.
scale(1 - gamma);
170 out1.applyBinary(ROL::Elementwise::Multiply<RealT>(), out2);
175 *outStream <<
"Elementwise Jacobian Check:" << std::endl;
176 testWrapper.checkApplyJacobian(out1, v, out2,
true, *outStream, 15);
177 *outStream << std::endl;
185 errorInftyNorm = 100;
187 errorFlag += errorInftyNorm > tol;
189 *outStream <<
"Consistency Check at " << numPoints
190 <<
" Randomly Sampled Points -- " << std::endl
191 <<
" Infinity Norm of | StdBoundConstraint - Elementwise |:"
193 <<
" Inverse = " << errorInftyNorm << std::endl;
198 errorFlag += errorInftyNorm > tol;
200 *outStream <<
" Jacobian = " << errorInftyNorm << std::endl;
201 *outStream << std::endl;
214 std::vector<RealT> ewErrors, svErrors;
217 ROL::Ptr<std::vector<RealT>> vsv
218 = ROL::makePtr<std::vector<RealT>>(numCases, 0.0);
219 ROL::Ptr<std::vector<RealT>> xsv
220 = ROL::makePtr<std::vector<RealT>>(numCases, 0.0);
221 ROL::Ptr<std::vector<RealT>> gsv
222 = ROL::makePtr<std::vector<RealT>>(numCases, 0.0);
223 ROL::Ptr<std::vector<RealT>> lsv
224 = ROL::makePtr<std::vector<RealT>>(numCases, 0.0);
225 ROL::Ptr<std::vector<RealT>> usv
226 = ROL::makePtr<std::vector<RealT>>(numCases, 0.0);
228 ROL::Ptr<std::vector<RealT>> resultp
229 = ROL::makePtr<std::vector<RealT>>(numCases, 0.0);
230 ROL::Ptr<std::vector<RealT>> targetp
231 = ROL::makePtr<std::vector<RealT>>(numCases, 0.0);
238 ROL::Ptr<ROL::Vector<RealT>> lp = ROL::makePtr<ROL::StdVector<RealT>>(lsv);
239 ROL::Ptr<ROL::Vector<RealT>> up = ROL::makePtr<ROL::StdVector<RealT>>(usv);
254 (*lsv)[1] = ROL::ROL_NINF<RealT>();
255 (*usv)[1] = ROL::ROL_INF<RealT>();
262 (*usv)[2] = ROL::ROL_INF<RealT>();
268 (*targetp)[0] = (*vsv)[0]*(*gsv)[0];
269 (*targetp)[1] = (*vsv)[1]*1.0;
270 (*targetp)[2] = (*vsv)[2]*1.0;
272 target.
applyBinary(ROL::Elementwise::DivideAndInvert<RealT>(), v);
273 target.
applyBinary(ROL::Elementwise::Multiply<RealT>(), v);
274 boundsBC.applyInverseScalingFunction(result, v, x, g);
275 ewErrors.push_back(
calcError(result, target));
277 svErrors.push_back(
calcError(result, target));
280 (*targetp)[0] = (*vsv)[0]*(*gsv)[0];
283 boundsBC.applyScalingFunctionJacobian(result, v, x, g);
284 ewErrors.push_back(
calcError(result, target));
286 svErrors.push_back(
calcError(result, target));
288 *outStream <<
"Elementwise Test Case Errors (Infinity Norm):" << std::endl
289 <<
" Inverse = " << ewErrors[1] << std::endl
290 <<
" Jacobian = " << ewErrors[2] << std::endl;
291 *outStream <<
"StdBoundConstraint Test Case Errors (Infinity Norm):" << std::endl
292 <<
" Inverse = " << svErrors[1] << std::endl
293 <<
" Jacobian = " << svErrors[2] << std::endl;
294 *outStream << std::endl;
296 RealT maxError = std::max(*std::max_element(svErrors.begin(), svErrors.end()),
297 *std::max_element(ewErrors.begin(), ewErrors.end()));
298 return maxError > tol;
301 int main(
int argc,
char *argv[]) {
303 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
307 int iprint = argc - 1;
308 ROL::Ptr<std::ostream> outStream;
311 outStream = ROL::makePtrFromRef(std::cout);
313 outStream = ROL::makePtrFromRef(bhs);
326 catch (std::logic_error& err) {
327 *outStream << err.what() <<
"\n";
332 std::cout <<
"End Result: TEST FAILED\n";
334 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.