Thyra Version of the Day
Loading...
Searching...
No Matches
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
51namespace Thyra {
52
53
190template<class Scalar>
191class LinearOpBase : virtual public Teuchos::Describable {
192public:
193
196
213
230
242 bool opSupported(EOpTransp M_trans) const
243 {
244 return opSupportedImpl(M_trans);
245 }
246
292 void apply(
293 const EOpTransp M_trans,
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
319protected:
320
323
325 virtual bool opSupportedImpl(EOpTransp M_trans) const = 0;
326
328 virtual void applyImpl(
329 const EOpTransp M_trans,
331 const Ptr<MultiVectorBase<Scalar> > &Y,
332 const Scalar alpha,
333 const Scalar beta
334 ) const = 0;
335
337
338private:
339
340 // Not defined and not to be called
342 operator=(const LinearOpBase<Scalar>&);
343
344};
345
346
352template<class Scalar>
354
355
361template<class Scalar>
363
364
370template<class Scalar>
372
373
378template<class Scalar>
379inline
381
382
387template<class Scalar>
388void apply(
389 const LinearOpBase<Scalar> &M,
390 const EOpTransp M_trans,
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
404inline
405void apply(
406 const LinearOpBase<double> &M,
407 const EOpTransp M_trans,
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
423template<class Scalar>
424inline
425bool Thyra::isFullyUninitialized( const LinearOpBase<Scalar> &M )
426{
427 return ( is_null(M.range()) || is_null(M.domain()) );
428}
429
430
431template<class Scalar>
432bool Thyra::isPartiallyInitialized( const LinearOpBase<Scalar> &M )
433{
434 return
435 (
436 ( !is_null(M.range()) && !is_null(M.domain()) )
437 &&
438 (
439 !opSupported(M,NOTRANS) && !opSupported(M,CONJ)
440 && !opSupported(M,TRANS) && !opSupported(M,CONJTRANS)
441 )
442 );
443}
444
445
446template<class Scalar>
447bool Thyra::isFullyInitialized( const LinearOpBase<Scalar> &M )
448{
449 return
450 (
451 ( !is_null(M.range()) && !is_null(M.domain()) )
452 &&
453 (
454 opSupported(M,NOTRANS) || opSupported(M,CONJ)
455 || opSupported(M,TRANS) || opSupported(M,CONJTRANS)
456 )
457 );
458}
459
460
461template<class Scalar>
462inline
463bool Thyra::opSupported( const LinearOpBase<Scalar> &M, EOpTransp M_trans )
464{
465 return M.opSupported(M_trans);
466}
467
468
469inline
470void 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
Base class for all linear operators.
bool isPartiallyInitialized(const LinearOpBase< Scalar > &M)
Determines if a linear operator is in the "Partially Initialized" state or not.
virtual bool opSupportedImpl(EOpTransp M_trans) const =0
Override in subclass.
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.
bool isFullyUninitialized(const LinearOpBase< Scalar > &M)
Determines if a linear operator is in the "Fully Uninitialized" state or not.
void apply(const LinearOpBase< Scalar > &M, const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha=static_cast< Scalar >(1.0), const Scalar beta=static_cast< Scalar >(0.0))
Non-member function call for M.apply(...).
virtual RCP< const VectorSpaceBase< Scalar > > range() const =0
Return a smart pointer for the range space for this operator.
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.
bool isFullyInitialized(const LinearOpBase< Scalar > &M)
Determines if a linear operator is in the "Fully Initialized" state or not.
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
bool opSupported(EOpTransp M_trans) const
Return if the M_trans operation of apply() is supported or not.
void apply(const LinearOpBase< double > &M, const EOpTransp M_trans, const MultiVectorBase< double > &X, const Ptr< MultiVectorBase< double > > &Y, const double alpha=1.0, const double beta=0.0)
Calls apply<double>(...).
bool opSupported(const LinearOpBase< Scalar > &M, EOpTransp M_trans)
Determines if an operation is supported for a single scalar type.
virtual RCP< const LinearOpBase< Scalar > > clone() const
Clone the linear operator object (if supported).
Interface for a collection of column vectors called a multi-vector.
bool is_null(const std::shared_ptr< T > &p)
EOpTransp
Enumeration for determining how a linear operator is applied. `*.