50 #include "ROL_Elementwise_Function.hpp" 52 #include "Teuchos_RefCountPtr.hpp" 53 #include "Teuchos_oblackholestream.hpp" 101 virtual void scale(
const Real alpha ) = 0;
111 virtual Real
dot(
const Vector &x )
const = 0;
120 virtual Real
norm()
const = 0;
131 virtual Teuchos::RCP<Vector>
clone()
const = 0;
146 Teuchos::RCP<Vector> ax = x.
clone();
160 this->
scale( (Real)0 );
174 virtual Teuchos::RCP<Vector>
basis(
const int i )
const {
return Teuchos::null;}
219 virtual void applyUnary(
const Elementwise::UnaryFunction<Real> &f ) {
220 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
221 "The method applyUnary wass called, but not implemented" << std::endl);
225 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
226 "The method applyBinary wass called, but not implemented" << std::endl);
229 virtual Real
reduce(
const Elementwise::ReductionOp<Real> &r )
const {
230 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
231 "The method reduce was called, but not implemented" << std::endl);
234 virtual void print( std::ostream &outStream )
const {
235 outStream <<
"The method print was called, but not implemented" << std::endl;
268 const bool printToStream =
true,
269 std::ostream & outStream = std::cout )
const {
275 std::vector<Real> vCheck;
277 Teuchos::oblackholestream bhs;
279 Teuchos::RCP<std::ostream> pStream;
281 pStream = Teuchos::rcp(&outStream,
false);
283 pStream = Teuchos::rcp(&bhs,
false);
287 Teuchos::oblackholestream oldFormatState, headerFormatState;
288 oldFormatState.copyfmt(*pStream);
290 Teuchos::RCP<Vector> v = this->
clone();
291 Teuchos::RCP<Vector> vtmp = this->
clone();
292 Teuchos::RCP<Vector> xtmp = x.
clone();
293 Teuchos::RCP<Vector> ytmp = y.
clone();
296 *pStream <<
"\n" << std::setw(width) << std::left << std::setfill(
'*') <<
"********** Begin verification of linear algebra. " <<
"\n\n";
297 headerFormatState.copyfmt(*pStream);
300 v->set(*
this); xtmp->set(x); ytmp->set(y);
301 v->plus(x); xtmp->plus(*
this); v->axpy(-one, *xtmp); vCheck.push_back(v->norm());
302 *pStream << std::scientific << std::setprecision(12) << std::setfill('>
'); 303 *pStream << std::setw(width) << std::left << "Commutativity of addition. Consistency error: " << " " << vCheck.back() << "\n"; 305 // Associativity of addition. 306 v->set(*this); xtmp->set(x); ytmp->set(y); 307 ytmp->plus(x); v->plus(*ytmp); xtmp->plus(*this); xtmp->plus(y); v->axpy(-one, *xtmp); vCheck.push_back(v->norm()); 308 *pStream << std::setw(width) << std::left << "Associativity of addition. Consistency error: " << " " << vCheck.back() << "\n"; 310 // Identity element of addition. 311 v->set(*this); xtmp->set(x); ytmp->set(y); 312 v->zero(); v->plus(x); v->axpy(-one, x); vCheck.push_back(v->norm()); 313 *pStream << std::setw(width) << std::left << "Identity element of addition. Consistency error: " << " " << vCheck.back() << "\n"; 315 // Inverse elements of addition. 316 v->set(*this); xtmp->set(x); ytmp->set(y); 317 v->scale(-one); v->plus(*this); vCheck.push_back(v->norm()); 318 *pStream << std::setw(width) << std::left << "Inverse elements of addition. Consistency error: " << " " << vCheck.back() << "\n"; 320 // Identity element of scalar multiplication. 321 v->set(*this); xtmp->set(x); ytmp->set(y); 322 v->scale(one); v->axpy(-one, *this); vCheck.push_back(v->norm()); 323 *pStream << std::setw(width) << std::left << "Identity element of scalar multiplication. Consistency error: " << " " << vCheck.back() << "\n"; 325 // Consistency of scalar multiplication with field multiplication. 326 v->set(*this); vtmp->set(*this); 327 v->scale(b); v->scale(a); vtmp->scale(a*b); v->axpy(-one, *vtmp); vCheck.push_back(v->norm()); 328 *pStream << std::setw(width) << std::left << "Consistency of scalar multiplication with field multiplication. Consistency error: " << " " << vCheck.back() << "\n"; 330 // Distributivity of scalar multiplication with respect to field addition. 331 v->set(*this); vtmp->set(*this); 332 v->scale(a+b); vtmp->scale(a); vtmp->axpy(b, *this); v->axpy(-one, *vtmp); vCheck.push_back(v->norm()); 333 *pStream << std::setw(width) << std::left << "Distributivity of scalar multiplication with respect to field addition. Consistency error: " << " " << vCheck.back() << "\n"; 335 // Distributivity of scalar multiplication with respect to vector addition. 336 v->set(*this); xtmp->set(x); ytmp->set(y); 337 v->plus(x); v->scale(a); xtmp->scale(a); xtmp->axpy(a, *this); v->axpy(-one, *xtmp); vCheck.push_back(v->norm()); 338 *pStream << std::setw(width) << std::left << "Distributivity of scalar multiplication with respect to vector addition. Consistency error: " << " " << vCheck.back() << "\n"; 340 // Commutativity of dot (inner) product over the field of reals. 341 vCheck.push_back(std::abs(this->dot(x) - x.dot(*this))); 342 *pStream << std::setw(width) << std::left << "Commutativity of dot (inner) product over the field of reals. Consistency error: " << " " << vCheck.back() << "\n"; 344 // Additivity of dot (inner) product. 346 xtmp->plus(y); vCheck.push_back(std::abs(this->dot(*xtmp) - this->dot(x) - this->dot(y))/std::max(std::abs(this->dot(*xtmp)), std::max(std::abs(this->dot(x)), std::abs(this->dot(y))))); 347 *pStream << std::setw(width) << std::left << "Additivity of dot (inner) product. Consistency error: " << " " << vCheck.back() << "\n"; 349 // Consistency of scalar multiplication and norm. 351 Real vnorm = v->norm(); 354 vCheck.push_back(std::abs(v->norm() - zero)); 357 vCheck.push_back(std::abs(v->norm() - one)); 359 *pStream << std::setw(width) << std::left << "Consistency of scalar multiplication and norm. Consistency error: " << " " << vCheck.back() << "\n"; 363 xtmp = Teuchos::rcp_const_cast<Vector>(Teuchos::rcpFromRef(this->dual())); 364 ytmp = Teuchos::rcp_const_cast<Vector>(Teuchos::rcpFromRef(xtmp->dual())); 365 v->axpy(-one, *ytmp); vCheck.push_back(v->norm()); 366 *pStream << std::setw(width) << std::left << "Reflexivity. Consistency error: " << " " << vCheck.back() << "\n\n"; 368 //*pStream << "************ End verification of linear algebra.\n\n"; 370 // Restore format state of pStream used for the header info. 371 pStream->copyfmt(headerFormatState); 372 *pStream << std::setw(width) << std::left << "********** End verification of linear algebra. " << "\n\n"; 374 // Restore format state of the original pStream. 375 pStream->copyfmt(oldFormatState); virtual void scale(const Real alpha)=0
Compute where .
virtual void plus(const Vector &x)=0
Compute , where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
virtual void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector &x)
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void zero()
Set to zero vector.
Defines the linear algebra or vector space interface.
virtual Real dot(const Vector &x) const =0
Compute where .
virtual Teuchos::RCP< Vector > basis(const int i) const
Return i-th basis vector.
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
virtual int dimension() const
Return dimension of the vector space.
virtual void applyUnary(const Elementwise::UnaryFunction< Real > &f)
virtual Real reduce(const Elementwise::ReductionOp< Real > &r) const
virtual std::vector< Real > checkVector(const Vector< Real > &x, const Vector< Real > &y, const bool printToStream=true, std::ostream &outStream=std::cout) const
Verify vector-space methods.
virtual Real norm() const =0
Returns where .
virtual void print(std::ostream &outStream) const