327 const bool printToStream =
true,
328 std::ostream & outStream = std::cout )
const {
334 std::vector<Real> vCheck;
338 ROL::Ptr<std::ostream> pStream;
340 pStream = ROL::makePtrFromRef(outStream);
342 pStream = ROL::makePtrFromRef(bhs);
346 ROL::nullstream oldFormatState, headerFormatState;
347 oldFormatState.copyfmt(*pStream);
349 ROL::Ptr<Vector> v = this->
clone();
350 ROL::Ptr<Vector> vtmp = this->
clone();
351 ROL::Ptr<Vector> xtmp = x.
clone();
352 ROL::Ptr<Vector> ytmp = y.
clone();
354 *pStream <<
"\n" << std::setw(width) << std::left << std::setfill(
'*') <<
"********** Begin verification of linear algebra. " <<
"\n\n";
355 headerFormatState.copyfmt(*pStream);
358 v->set(*
this); xtmp->set(x); ytmp->set(y);
359 v->plus(x); xtmp->plus(*
this); v->axpy(-one, *xtmp); vCheck.push_back(v->norm());
360 *pStream << std::scientific << std::setprecision(12) << std::setfill(
'>');
361 *pStream << std::setw(width) << std::left <<
"Commutativity of addition. Consistency error: " <<
" " << vCheck.back() <<
"\n";
364 v->set(*
this); xtmp->set(x); ytmp->set(y);
365 ytmp->plus(x); v->plus(*ytmp); xtmp->plus(*
this); xtmp->plus(y); v->axpy(-one, *xtmp); vCheck.push_back(v->norm());
366 *pStream << std::setw(width) << std::left <<
"Associativity of addition. Consistency error: " <<
" " << vCheck.back() <<
"\n";
369 v->set(*
this); xtmp->set(x); ytmp->set(y);
370 v->zero(); v->plus(x); v->axpy(-one, x); vCheck.push_back(v->norm());
371 *pStream << std::setw(width) << std::left <<
"Identity element of addition. Consistency error: " <<
" " << vCheck.back() <<
"\n";
374 v->set(*
this); xtmp->set(x); ytmp->set(y);
375 v->scale(-one); v->plus(*
this); vCheck.push_back(v->norm());
376 *pStream << std::setw(width) << std::left <<
"Inverse elements of addition. Consistency error: " <<
" " << vCheck.back() <<
"\n";
379 v->set(*
this); xtmp->set(x); ytmp->set(y);
380 v->scale(one); v->axpy(-one, *
this); vCheck.push_back(v->norm());
381 *pStream << std::setw(width) << std::left <<
"Identity element of scalar multiplication. Consistency error: " <<
" " << vCheck.back() <<
"\n";
384 v->set(*
this); vtmp->set(*
this);
385 v->scale(b); v->scale(a); vtmp->scale(a*b); v->axpy(-one, *vtmp); vCheck.push_back(v->norm());
386 *pStream << std::setw(width) << std::left <<
"Consistency of scalar multiplication with field multiplication. Consistency error: " <<
" " << vCheck.back() <<
"\n";
389 v->set(*
this); vtmp->set(*
this);
390 v->scale(a+b); vtmp->scale(a); vtmp->axpy(b, *
this); v->axpy(-one, *vtmp); vCheck.push_back(v->norm());
391 *pStream << std::setw(width) << std::left <<
"Distributivity of scalar multiplication with respect to field addition. Consistency error: " <<
" " << vCheck.back() <<
"\n";
394 v->set(*
this); xtmp->set(x); ytmp->set(y);
395 v->plus(x); v->scale(a); xtmp->scale(a); xtmp->axpy(a, *
this); v->axpy(-one, *xtmp); vCheck.push_back(v->norm());
396 *pStream << std::setw(width) << std::left <<
"Distributivity of scalar multiplication with respect to vector addition. Consistency error: " <<
" " << vCheck.back() <<
"\n";
399 vCheck.push_back(std::abs(this->
dot(x) - x.
dot(*
this)));
400 *pStream << std::setw(width) << std::left <<
"Commutativity of dot (inner) product over the field of reals. Consistency error: " <<
" " << vCheck.back() <<
"\n";
404 xtmp->plus(y); vCheck.push_back(std::abs(this->
dot(*xtmp) - this->
dot(x) - this->
dot(y))/std::max({
static_cast<Real
>(std::abs(this->
dot(*xtmp))),
static_cast<Real
>(std::abs(this->
dot(x))),
static_cast<Real
>(std::abs(this->
dot(y))), one}));
405 *pStream << std::setw(width) << std::left <<
"Additivity of dot (inner) product. Consistency error: " <<
" " << vCheck.back() <<
"\n";
409 Real vnorm = v->norm();
412 vCheck.push_back(std::abs(v->norm() -
zero));
415 vCheck.push_back(std::abs(v->norm() - one));
417 *pStream << std::setw(width) << std::left <<
"Consistency of scalar multiplication and norm. Consistency error: " <<
" " << vCheck.back() <<
"\n";
421 xtmp = ROL::constPtrCast<Vector>(ROL::makePtrFromRef(this->
dual()));
422 ytmp = ROL::constPtrCast<Vector>(ROL::makePtrFromRef(xtmp->dual()));
423 v->axpy(-one, *ytmp); vCheck.push_back(v->norm());
424 *pStream << std::setw(width) << std::left <<
"Reflexivity. Consistency error: " <<
" " << vCheck.back() <<
"\n";
429 Real vx = v->apply(*xtmp);
430 Real vxd = v->dot(xtmp->dual());
431 Real vdx = xtmp->dot(v->dual());
433 vCheck.push_back(std::max(std::abs(vx-vxd),std::abs(vx-vdx)));
436 vCheck.push_back(std::max(std::abs(vx-vxd),std::abs(vx-vdx))/std::abs(vx));
438 *pStream << std::setw(width) << std::left <<
"Consistency of apply and dual:" <<
" " << vCheck.back() <<
"\n\n";
443 pStream->copyfmt(headerFormatState);
444 *pStream << std::setw(width) << std::left <<
"********** End verification of linear algebra. " <<
"\n\n";
447 pStream->copyfmt(oldFormatState);