Thyra Version of the Day
Loading...
Searching...
No Matches
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
19namespace Thyra {
20
21
158template<class Scalar>
159class LinearOpBase : virtual public Teuchos::Describable {
160public:
161
164
181
198
210 bool opSupported(EOpTransp M_trans) const
211 {
212 return opSupportedImpl(M_trans);
213 }
214
260 void apply(
261 const EOpTransp M_trans,
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
287protected:
288
291
293 virtual bool opSupportedImpl(EOpTransp M_trans) const = 0;
294
296 virtual void applyImpl(
297 const EOpTransp M_trans,
299 const Ptr<MultiVectorBase<Scalar> > &Y,
300 const Scalar alpha,
301 const Scalar beta
302 ) const = 0;
303
305
306private:
307
308 // Not defined and not to be called
310 operator=(const LinearOpBase<Scalar>&);
311
312};
313
314
320template<class Scalar>
322
323
329template<class Scalar>
331
332
338template<class Scalar>
340
341
346template<class Scalar>
347inline
349
350
355template<class Scalar>
356void apply(
357 const LinearOpBase<Scalar> &M,
358 const EOpTransp M_trans,
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
372inline
373void apply(
374 const LinearOpBase<double> &M,
375 const EOpTransp M_trans,
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
391template<class Scalar>
392inline
393bool Thyra::isFullyUninitialized( const LinearOpBase<Scalar> &M )
394{
395 return ( is_null(M.range()) || is_null(M.domain()) );
396}
397
398
399template<class Scalar>
400bool Thyra::isPartiallyInitialized( const LinearOpBase<Scalar> &M )
401{
402 return
403 (
404 ( !is_null(M.range()) && !is_null(M.domain()) )
405 &&
406 (
407 !opSupported(M,NOTRANS) && !opSupported(M,CONJ)
408 && !opSupported(M,TRANS) && !opSupported(M,CONJTRANS)
409 )
410 );
411}
412
413
414template<class Scalar>
415bool Thyra::isFullyInitialized( const LinearOpBase<Scalar> &M )
416{
417 return
418 (
419 ( !is_null(M.range()) && !is_null(M.domain()) )
420 &&
421 (
422 opSupported(M,NOTRANS) || opSupported(M,CONJ)
423 || opSupported(M,TRANS) || opSupported(M,CONJTRANS)
424 )
425 );
426}
427
428
429template<class Scalar>
430inline
431bool Thyra::opSupported( const LinearOpBase<Scalar> &M, EOpTransp M_trans )
432{
433 return M.opSupported(M_trans);
434}
435
436
437inline
438void 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
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. `*.