48 #include "Teuchos_RefCountPtr.hpp"
49 #include "Teuchos_oblackholestream.hpp"
97 virtual void scale(
const Real alpha ) = 0;
107 virtual Real
dot(
const Vector &x )
const = 0;
116 virtual Real
norm()
const = 0;
127 virtual Teuchos::RCP<Vector>
clone()
const = 0;
142 Teuchos::RCP<Vector> ax = x.
clone();
156 this->
scale( (Real)0 );
170 virtual Teuchos::RCP<Vector>
basis(
const int i )
const {
return Teuchos::null;}
244 const bool printToStream =
true,
245 std::ostream & outStream = std::cout )
const {
251 std::vector<Real> vCheck;
253 Teuchos::oblackholestream bhs;
255 Teuchos::RCP<std::ostream> pStream;
257 pStream = Teuchos::rcp(&outStream,
false);
259 pStream = Teuchos::rcp(&bhs,
false);
263 Teuchos::oblackholestream oldFormatState, headerFormatState;
264 oldFormatState.copyfmt(*pStream);
266 Teuchos::RCP<Vector> v = this->
clone();
267 Teuchos::RCP<Vector> vtmp = this->
clone();
268 Teuchos::RCP<Vector> xtmp = x.
clone();
269 Teuchos::RCP<Vector> ytmp = y.
clone();
272 *pStream <<
"\n" << std::setw(width) << std::left << std::setfill(
'*') <<
"********** Begin verification of linear algebra. " <<
"\n\n";
273 headerFormatState.copyfmt(*pStream);
276 v->set(*
this); xtmp->set(x); ytmp->set(y);
277 v->plus(x); xtmp->plus(*
this); v->axpy(-one, *xtmp); vCheck.push_back(v->norm());
278 *pStream << std::scientific << std::setprecision(12) << std::setfill('>
');
279 *pStream << std::setw(width) << std::left << "Commutativity of addition. Consistency error: " << " " << vCheck.back() << "\n";
281 // Associativity of addition.
282 v->set(*this); xtmp->set(x); ytmp->set(y);
283 ytmp->plus(x); v->plus(*ytmp); xtmp->plus(*this); xtmp->plus(y); v->axpy(-one, *xtmp); vCheck.push_back(v->norm());
284 *pStream << std::setw(width) << std::left << "Associativity of addition. Consistency error: " << " " << vCheck.back() << "\n";
286 // Identity element of addition.
287 v->set(*this); xtmp->set(x); ytmp->set(y);
288 v->zero(); v->plus(x); v->axpy(-one, x); vCheck.push_back(v->norm());
289 *pStream << std::setw(width) << std::left << "Identity element of addition. Consistency error: " << " " << vCheck.back() << "\n";
291 // Inverse elements of addition.
292 v->set(*this); xtmp->set(x); ytmp->set(y);
293 v->scale(-one); v->plus(*this); vCheck.push_back(v->norm());
294 *pStream << std::setw(width) << std::left << "Inverse elements of addition. Consistency error: " << " " << vCheck.back() << "\n";
296 // Identity element of scalar multiplication.
297 v->set(*this); xtmp->set(x); ytmp->set(y);
298 v->scale(one); v->axpy(-one, *this); vCheck.push_back(v->norm());
299 *pStream << std::setw(width) << std::left << "Identity element of scalar multiplication. Consistency error: " << " " << vCheck.back() << "\n";
301 // Consistency of scalar multiplication with field multiplication.
302 v->set(*this); vtmp->set(*this);
303 v->scale(b); v->scale(a); vtmp->scale(a*b); v->axpy(-one, *vtmp); vCheck.push_back(v->norm());
304 *pStream << std::setw(width) << std::left << "Consistency of scalar multiplication with field multiplication. Consistency error: " << " " << vCheck.back() << "\n";
306 // Distributivity of scalar multiplication with respect to field addition.
307 v->set(*this); vtmp->set(*this);
308 v->scale(a+b); vtmp->scale(a); vtmp->axpy(b, *this); v->axpy(-one, *vtmp); vCheck.push_back(v->norm());
309 *pStream << std::setw(width) << std::left << "Distributivity of scalar multiplication with respect to field addition. Consistency error: " << " " << vCheck.back() << "\n";
311 // Distributivity of scalar multiplication with respect to vector addition.
312 v->set(*this); xtmp->set(x); ytmp->set(y);
313 v->plus(x); v->scale(a); xtmp->scale(a); xtmp->axpy(a, *this); v->axpy(-one, *xtmp); vCheck.push_back(v->norm());
314 *pStream << std::setw(width) << std::left << "Distributivity of scalar multiplication with respect to vector addition. Consistency error: " << " " << vCheck.back() << "\n";
316 // Commutativity of dot (inner) product over the field of reals.
317 vCheck.push_back(std::abs(this->dot(x) - x.dot(*this)));
318 *pStream << std::setw(width) << std::left << "Commutativity of dot (inner) product over the field of reals. Consistency error: " << " " << vCheck.back() << "\n";
320 // Additivity of dot (inner) product.
322 xtmp->plus(y); vCheck.push_back(std::abs(this->dot(*xtmp) - x.dot(*this) - y.dot(*this)));
323 *pStream << std::setw(width) << std::left << "Additivity of dot (inner) product. Consistency error: " << " " << vCheck.back() << "\n";
325 // Consistency of scalar multiplication and norm.
327 Real vnorm = v->norm();
330 vCheck.push_back(std::abs(v->norm() - zero));
333 vCheck.push_back(std::abs(v->norm() - one));
335 *pStream << std::setw(width) << std::left << "Consistency of scalar multiplication and norm. Consistency error: " << " " << vCheck.back() << "\n";
339 xtmp = Teuchos::rcp_const_cast<Vector>(Teuchos::rcpFromRef(this->dual()));
340 ytmp = Teuchos::rcp_const_cast<Vector>(Teuchos::rcpFromRef(xtmp->dual()));
341 v->axpy(-one, *ytmp); vCheck.push_back(v->norm());
342 *pStream << std::setw(width) << std::left << "Reflexivity. Consistency error: " << " " << vCheck.back() << "\n\n";
344 //*pStream << "************ End verification of linear algebra.\n\n";
346 // Restore format state of pStream used for the header info.
347 pStream->copyfmt(headerFormatState);
348 *pStream << std::setw(width) << std::left << "********** End verification of linear algebra. " << "\n\n";
350 // Restore format state of the original pStream.
351 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 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 set(const Vector &x)
Set where .
virtual Teuchos::RCP< Vector > basis(const int i) const
Return i-th basis vector.
virtual Real norm() const =0
Returns where .