Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_LinearOpBase_decl.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
4 //
5 // Copyright 2004 NTESS and the Thyra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef THYRA_LINEAR_OP_DECL_HPP
11 #define THYRA_LINEAR_OP_DECL_HPP
12 
13 #include "Thyra_OperatorVectorTypes.hpp"
14 #include "Teuchos_Describable.hpp"
15 #include "Teuchos_ExpandScalarTypeMacros.hpp"
16 #include "Teuchos_PromotionTraits.hpp"
17 
18 
19 namespace Thyra {
20 
21 
158 template<class Scalar>
159 class LinearOpBase : virtual public Teuchos::Describable {
160 public:
161 
164 
180  virtual RCP< const VectorSpaceBase<Scalar> > range() const = 0;
181 
197  virtual RCP< const VectorSpaceBase<Scalar> > domain() const = 0;
198 
210  bool opSupported(EOpTransp M_trans) const
211  {
212  return opSupportedImpl(M_trans);
213  }
214 
260  void apply(
261  const EOpTransp M_trans,
262  const MultiVectorBase<Scalar> &X,
263  const Ptr<MultiVectorBase<Scalar> > &Y,
264  const Scalar alpha,
265  const Scalar beta
266  ) const
267  {
268  applyImpl(M_trans, X, Y, alpha, beta);
269  }
270 
283  virtual RCP<const LinearOpBase<Scalar> > clone() const;
284 
286 
287 protected:
288 
291 
293  virtual bool opSupportedImpl(EOpTransp M_trans) const = 0;
294 
296  virtual void applyImpl(
297  const EOpTransp M_trans,
298  const MultiVectorBase<Scalar> &X,
299  const Ptr<MultiVectorBase<Scalar> > &Y,
300  const Scalar alpha,
301  const Scalar beta
302  ) const = 0;
303 
305 
306 private:
307 
308  // Not defined and not to be called
310  operator=(const LinearOpBase<Scalar>&);
311 
312 };
313 
314 
320 template<class Scalar>
321 bool isFullyUninitialized( const LinearOpBase<Scalar> &M );
322 
323 
329 template<class Scalar>
330 bool isPartiallyInitialized( const LinearOpBase<Scalar> &M );
331 
332 
338 template<class Scalar>
339 bool isFullyInitialized( const LinearOpBase<Scalar> &M );
340 
341 
346 template<class Scalar>
347 inline
348 bool opSupported( const LinearOpBase<Scalar> &M, EOpTransp M_trans );
349 
350 
355 template<class Scalar>
356 void apply(
357  const LinearOpBase<Scalar> &M,
358  const EOpTransp M_trans,
359  const MultiVectorBase<Scalar> &X,
360  const Ptr<MultiVectorBase<Scalar> > &Y,
361  const Scalar alpha = static_cast<Scalar>(1.0),
362  const Scalar beta = static_cast<Scalar>(0.0)
363  );
364 
365 
372 inline
373 void apply(
374  const LinearOpBase<double> &M,
375  const EOpTransp M_trans,
376  const MultiVectorBase<double> &X,
377  const Ptr<MultiVectorBase<double> > &Y,
378  const double alpha = 1.0,
379  const double beta = 0.0
380  );
381 
382 
383 } // end namespace Thyra
384 
385 
386 //
387 // Inline and other Template Implementations
388 //
389 
390 
391 template<class Scalar>
392 inline
393 bool Thyra::isFullyUninitialized( const LinearOpBase<Scalar> &M )
394 {
395  return ( is_null(M.range()) || is_null(M.domain()) );
396 }
397 
398 
399 template<class Scalar>
400 bool Thyra::isPartiallyInitialized( const LinearOpBase<Scalar> &M )
401 {
402  return
403  (
404  ( !is_null(M.range()) && !is_null(M.domain()) )
405  &&
406  (
408  && !opSupported(M,TRANS) && !opSupported(M,CONJTRANS)
409  )
410  );
411 }
412 
413 
414 template<class Scalar>
415 bool Thyra::isFullyInitialized( const LinearOpBase<Scalar> &M )
416 {
417  return
418  (
419  ( !is_null(M.range()) && !is_null(M.domain()) )
420  &&
421  (
424  )
425  );
426 }
427 
428 
429 template<class Scalar>
430 inline
431 bool Thyra::opSupported( const LinearOpBase<Scalar> &M, EOpTransp M_trans )
432 {
433  return M.opSupported(M_trans);
434 }
435 
436 
437 inline
438 void Thyra::apply(
439  const LinearOpBase<double> &M,
440  const EOpTransp M_trans,
441  const MultiVectorBase<double> &X,
442  const Ptr<MultiVectorBase<double> > &Y,
443  const double alpha,
444  const double beta
445  )
446 {
447  apply<double>(M, M_trans, X, Y, alpha, beta);
448 }
449 
450 
451 #endif // THYRA_LINEAR_OP_DECL_HPP
virtual bool opSupportedImpl(EOpTransp M_trans) const =0
Override in subclass.
bool is_null(const boost::shared_ptr< T > &p)
virtual RCP< const VectorSpaceBase< Scalar > > range() const =0
Return a smart pointer for the range space for this operator.
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
virtual void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const =0
Override in subclass.
Use the non-transposed operator.
Use the transposed operator with complex-conjugate clements (same as TRANS for real scalar types)...
bool opSupported(EOpTransp M_trans) const
Return if the M_trans operation of apply() is supported or not.
Use the non-transposed operator with complex-conjugate elements (same as NOTRANS for real scalar type...
Use the transposed operator.
Interface for a collection of column vectors called a multi-vector.
bool opSupported(const LinearOpBase< Scalar > &M, EOpTransp M_trans)
Determines if an operation is supported for a single scalar type.
void apply(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
Apply the linear operator to a multi-vector : Y = alpha*op(M)*X + beta*Y.
virtual RCP< const LinearOpBase< Scalar > > clone() const
Clone the linear operator object (if supported).
Base class for all linear operators.
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.