48 #include "ROL_Elementwise_Function.hpp" 50 #include "Teuchos_RefCountPtr.hpp" 51 #include "Teuchos_oblackholestream.hpp" 99 virtual void scale(
const Real alpha ) = 0;
109 virtual Real
dot(
const Vector &x )
const = 0;
118 virtual Real
norm()
const = 0;
129 virtual Teuchos::RCP<Vector>
clone()
const = 0;
144 Teuchos::RCP<Vector> ax = x.
clone();
158 this->
scale( (Real)0 );
172 virtual Teuchos::RCP<Vector>
basis(
const int i )
const {
return Teuchos::null;}
217 virtual void applyUnary(
const Elementwise::UnaryFunction<Real> &f ) {
218 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
219 "The method applyUnary is called but not implemented" << std::endl);
223 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
224 "The method applyBinary is called but not implemented" << std::endl);
227 virtual Real
reduce(
const Elementwise::ReductionOp<Real> &r )
const {
228 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
229 "The method reduce is called but not implemented" << std::endl);
261 const bool printToStream =
true,
262 std::ostream & outStream = std::cout )
const {
268 std::vector<Real> vCheck;
270 Teuchos::oblackholestream bhs;
272 Teuchos::RCP<std::ostream> pStream;
274 pStream = Teuchos::rcp(&outStream,
false);
276 pStream = Teuchos::rcp(&bhs,
false);
280 Teuchos::oblackholestream oldFormatState, headerFormatState;
281 oldFormatState.copyfmt(*pStream);
283 Teuchos::RCP<Vector> v = this->
clone();
284 Teuchos::RCP<Vector> vtmp = this->
clone();
285 Teuchos::RCP<Vector> xtmp = x.
clone();
286 Teuchos::RCP<Vector> ytmp = y.
clone();
289 *pStream <<
"\n" << std::setw(width) << std::left << std::setfill(
'*') <<
"********** Begin verification of linear algebra. " <<
"\n\n";
290 headerFormatState.copyfmt(*pStream);
293 v->set(*
this); xtmp->set(x); ytmp->set(y);
294 v->plus(x); xtmp->plus(*
this); v->axpy(-one, *xtmp); vCheck.push_back(v->norm());
295 *pStream << std::scientific << std::setprecision(12) << std::setfill('>
'); 296 *pStream << std::setw(width) << std::left << "Commutativity of addition. Consistency error: " << " " << vCheck.back() << "\n"; 298 // Associativity of addition. 299 v->set(*this); xtmp->set(x); ytmp->set(y); 300 ytmp->plus(x); v->plus(*ytmp); xtmp->plus(*this); xtmp->plus(y); v->axpy(-one, *xtmp); vCheck.push_back(v->norm()); 301 *pStream << std::setw(width) << std::left << "Associativity of addition. Consistency error: " << " " << vCheck.back() << "\n"; 303 // Identity element of addition. 304 v->set(*this); xtmp->set(x); ytmp->set(y); 305 v->zero(); v->plus(x); v->axpy(-one, x); vCheck.push_back(v->norm()); 306 *pStream << std::setw(width) << std::left << "Identity element of addition. Consistency error: " << " " << vCheck.back() << "\n"; 308 // Inverse elements of addition. 309 v->set(*this); xtmp->set(x); ytmp->set(y); 310 v->scale(-one); v->plus(*this); vCheck.push_back(v->norm()); 311 *pStream << std::setw(width) << std::left << "Inverse elements of addition. Consistency error: " << " " << vCheck.back() << "\n"; 313 // Identity element of scalar multiplication. 314 v->set(*this); xtmp->set(x); ytmp->set(y); 315 v->scale(one); v->axpy(-one, *this); vCheck.push_back(v->norm()); 316 *pStream << std::setw(width) << std::left << "Identity element of scalar multiplication. Consistency error: " << " " << vCheck.back() << "\n"; 318 // Consistency of scalar multiplication with field multiplication. 319 v->set(*this); vtmp->set(*this); 320 v->scale(b); v->scale(a); vtmp->scale(a*b); v->axpy(-one, *vtmp); vCheck.push_back(v->norm()); 321 *pStream << std::setw(width) << std::left << "Consistency of scalar multiplication with field multiplication. Consistency error: " << " " << vCheck.back() << "\n"; 323 // Distributivity of scalar multiplication with respect to field addition. 324 v->set(*this); vtmp->set(*this); 325 v->scale(a+b); vtmp->scale(a); vtmp->axpy(b, *this); v->axpy(-one, *vtmp); vCheck.push_back(v->norm()); 326 *pStream << std::setw(width) << std::left << "Distributivity of scalar multiplication with respect to field addition. Consistency error: " << " " << vCheck.back() << "\n"; 328 // Distributivity of scalar multiplication with respect to vector addition. 329 v->set(*this); xtmp->set(x); ytmp->set(y); 330 v->plus(x); v->scale(a); xtmp->scale(a); xtmp->axpy(a, *this); v->axpy(-one, *xtmp); vCheck.push_back(v->norm()); 331 *pStream << std::setw(width) << std::left << "Distributivity of scalar multiplication with respect to vector addition. Consistency error: " << " " << vCheck.back() << "\n"; 333 // Commutativity of dot (inner) product over the field of reals. 334 vCheck.push_back(std::abs(this->dot(x) - x.dot(*this))); 335 *pStream << std::setw(width) << std::left << "Commutativity of dot (inner) product over the field of reals. Consistency error: " << " " << vCheck.back() << "\n"; 337 // Additivity of dot (inner) product. 339 xtmp->plus(y); vCheck.push_back(std::abs(this->dot(*xtmp) - x.dot(*this) - y.dot(*this))); 340 *pStream << std::setw(width) << std::left << "Additivity of dot (inner) product. Consistency error: " << " " << vCheck.back() << "\n"; 342 // Consistency of scalar multiplication and norm. 344 Real vnorm = v->norm(); 347 vCheck.push_back(std::abs(v->norm() - zero)); 350 vCheck.push_back(std::abs(v->norm() - one)); 352 *pStream << std::setw(width) << std::left << "Consistency of scalar multiplication and norm. Consistency error: " << " " << vCheck.back() << "\n"; 356 xtmp = Teuchos::rcp_const_cast<Vector>(Teuchos::rcpFromRef(this->dual())); 357 ytmp = Teuchos::rcp_const_cast<Vector>(Teuchos::rcpFromRef(xtmp->dual())); 358 v->axpy(-one, *ytmp); vCheck.push_back(v->norm()); 359 *pStream << std::setw(width) << std::left << "Reflexivity. Consistency error: " << " " << vCheck.back() << "\n\n"; 361 //*pStream << "************ End verification of linear algebra.\n\n"; 363 // Restore format state of pStream used for the header info. 364 pStream->copyfmt(headerFormatState); 365 *pStream << std::setw(width) << std::left << "********** End verification of linear algebra. " << "\n\n"; 367 // Restore format state of the original pStream. 368 pStream->copyfmt(oldFormatState); virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
virtual void scale(const Real alpha)=0
Compute where .
virtual int dimension() const
Return dimension of the vector space.
virtual void plus(const Vector &x)=0
Compute , where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
virtual Real reduce(const Elementwise::ReductionOp< Real > &r) const
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 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 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 void applyUnary(const Elementwise::UnaryFunction< Real > &f)
virtual Teuchos::RCP< Vector > basis(const int i) const
Return i-th basis vector.
virtual Real norm() const =0
Returns where .