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 //
4 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef THYRA_LINEAR_OP_DECL_HPP
43 #define THYRA_LINEAR_OP_DECL_HPP
44 
45 #include "Thyra_OperatorVectorTypes.hpp"
46 #include "Teuchos_Describable.hpp"
47 #include "Teuchos_ExpandScalarTypeMacros.hpp"
48 #include "Teuchos_PromotionTraits.hpp"
49 
50 
51 namespace Thyra {
52 
53 
190 template<class Scalar>
191 class LinearOpBase : virtual public Teuchos::Describable {
192 public:
193 
196 
212  virtual RCP< const VectorSpaceBase<Scalar> > range() const = 0;
213 
229  virtual RCP< const VectorSpaceBase<Scalar> > domain() const = 0;
230 
242  bool opSupported(EOpTransp M_trans) const
243  {
244  return opSupportedImpl(M_trans);
245  }
246 
292  void apply(
293  const EOpTransp M_trans,
294  const MultiVectorBase<Scalar> &X,
295  const Ptr<MultiVectorBase<Scalar> > &Y,
296  const Scalar alpha,
297  const Scalar beta
298  ) const
299  {
300  applyImpl(M_trans, X, Y, alpha, beta);
301  }
302 
315  virtual RCP<const LinearOpBase<Scalar> > clone() const;
316 
318 
319 protected:
320 
323 
325  virtual bool opSupportedImpl(EOpTransp M_trans) const = 0;
326 
328  virtual void applyImpl(
329  const EOpTransp M_trans,
330  const MultiVectorBase<Scalar> &X,
331  const Ptr<MultiVectorBase<Scalar> > &Y,
332  const Scalar alpha,
333  const Scalar beta
334  ) const = 0;
335 
337 
338 private:
339 
340  // Not defined and not to be called
342  operator=(const LinearOpBase<Scalar>&);
343 
344 };
345 
346 
352 template<class Scalar>
353 bool isFullyUninitialized( const LinearOpBase<Scalar> &M );
354 
355 
361 template<class Scalar>
362 bool isPartiallyInitialized( const LinearOpBase<Scalar> &M );
363 
364 
370 template<class Scalar>
371 bool isFullyInitialized( const LinearOpBase<Scalar> &M );
372 
373 
378 template<class Scalar>
379 inline
380 bool opSupported( const LinearOpBase<Scalar> &M, EOpTransp M_trans );
381 
382 
387 template<class Scalar>
388 void apply(
389  const LinearOpBase<Scalar> &M,
390  const EOpTransp M_trans,
391  const MultiVectorBase<Scalar> &X,
392  const Ptr<MultiVectorBase<Scalar> > &Y,
393  const Scalar alpha = static_cast<Scalar>(1.0),
394  const Scalar beta = static_cast<Scalar>(0.0)
395  );
396 
397 
404 inline
405 void apply(
406  const LinearOpBase<double> &M,
407  const EOpTransp M_trans,
408  const MultiVectorBase<double> &X,
409  const Ptr<MultiVectorBase<double> > &Y,
410  const double alpha = 1.0,
411  const double beta = 0.0
412  );
413 
414 
415 } // end namespace Thyra
416 
417 
418 //
419 // Inline and other Template Implementations
420 //
421 
422 
423 template<class Scalar>
424 inline
425 bool Thyra::isFullyUninitialized( const LinearOpBase<Scalar> &M )
426 {
427  return ( is_null(M.range()) || is_null(M.domain()) );
428 }
429 
430 
431 template<class Scalar>
432 bool Thyra::isPartiallyInitialized( const LinearOpBase<Scalar> &M )
433 {
434  return
435  (
436  ( !is_null(M.range()) && !is_null(M.domain()) )
437  &&
438  (
440  && !opSupported(M,TRANS) && !opSupported(M,CONJTRANS)
441  )
442  );
443 }
444 
445 
446 template<class Scalar>
447 bool Thyra::isFullyInitialized( const LinearOpBase<Scalar> &M )
448 {
449  return
450  (
451  ( !is_null(M.range()) && !is_null(M.domain()) )
452  &&
453  (
456  )
457  );
458 }
459 
460 
461 template<class Scalar>
462 inline
463 bool Thyra::opSupported( const LinearOpBase<Scalar> &M, EOpTransp M_trans )
464 {
465  return M.opSupported(M_trans);
466 }
467 
468 
469 inline
470 void Thyra::apply(
471  const LinearOpBase<double> &M,
472  const EOpTransp M_trans,
473  const MultiVectorBase<double> &X,
474  const Ptr<MultiVectorBase<double> > &Y,
475  const double alpha,
476  const double beta
477  )
478 {
479  apply<double>(M, M_trans, X, Y, alpha, beta);
480 }
481 
482 
483 #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.