Thyra Version of the Day
Loading...
Searching...
No Matches
Thyra_DefaultScaledAdjointLinearOp_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_DEFAULT_SCALED_ADJOINT_LINEAR_OP_DECL_HPP
11#define THYRA_DEFAULT_SCALED_ADJOINT_LINEAR_OP_DECL_HPP
12
13
14#include "Thyra_ScaledAdjointLinearOpBase.hpp"
15#include "Teuchos_ConstNonconstObjectContainer.hpp"
16
17
18namespace Thyra {
19
20
93template<class Scalar>
95 : virtual public ScaledAdjointLinearOpBase<Scalar>
96{
97public:
98
101
109
117 const Scalar &scalar,
118 const EOpTransp &transp,
119 const RCP<LinearOpBase<Scalar> > &Op
120 );
121
129 const Scalar &scalar,
130 const EOpTransp &transp,
131 const RCP<const LinearOpBase<Scalar> > &Op
132 );
133
155 void initialize(
156 const Scalar &scalar,
157 const EOpTransp &transp,
158 const RCP<LinearOpBase<Scalar> > &Op
159 );
160
181 void initialize(
182 const Scalar &scalar
183 ,const EOpTransp &transp
184 ,const RCP<const LinearOpBase<Scalar> > &Op
185 );
186
191
196
203 void uninitialize();
204
206
209
214 std::string description() const;
215
224 void describe(
226 const Teuchos::EVerbosityLevel verbLevel
227 ) const;
228
230
233
242
251
254
256
259
261 Scalar overallScalar() const;
263 EOpTransp overallTransp() const;
268
270
271protected:
272
275
284 bool opSupportedImpl(EOpTransp M_trans) const;
285
294 void applyImpl(
295 const EOpTransp M_trans,
297 const Ptr<MultiVectorBase<Scalar> > &Y,
298 const Scalar alpha,
299 const Scalar beta
300 ) const;
301
303
304private:
305
306 // ////////////////////////////////
307 // Private types
308
309 template <class Scalar2>
310 struct ScalarETransp {
311 Scalar2 scalar;
312 EOpTransp transp;
313 ScalarETransp()
314 {}
315 ScalarETransp( const Scalar2 &_scalar, const EOpTransp &_transp )
316 : scalar(_scalar), transp(_transp)
317 {}
318 };
319
320 typedef std::vector<ScalarETransp<Scalar> > allScalarETransp_t;
321
323
324 // ////////////////////////////////
325 // Private data members
326
327 CNLOC origOp_;
328 Scalar overallScalar_;
329 EOpTransp overallTransp_;
330 int my_index_;
331
332 RCP<allScalarETransp_t> allScalarETransp_;
333
334 // ////////////////////////////////
335 // Private member functions
336
337 void initializeImpl(
338 const Scalar &scalar,
339 const EOpTransp &transp,
340 const RCP<const LinearOpBase<Scalar> > &Op,
341 const bool isConst
342 );
343 CNLOC getOpImpl() const;
344 void assertInitialized() const;
345
346 // Not defined and not to be called
349
350};
351
352
368template<class Scalar>
371 const Scalar &scalar,
372 const RCP<LinearOpBase<Scalar> > &Op,
373 const std::string &label = ""
374 );
375
376
392template<class Scalar>
395 const Scalar &scalar,
396 const RCP<const LinearOpBase<Scalar> > &Op,
397 const std::string &label = ""
398 );
399
400
416template<class Scalar>
419 const RCP<LinearOpBase<Scalar> > &Op,
420 const std::string &label = ""
421 );
422
423
439template<class Scalar>
442 const RCP<const LinearOpBase<Scalar> > &Op,
443 const std::string &label = ""
444 );
445
446
462template<class Scalar>
465 const RCP<LinearOpBase<Scalar> > &Op,
466 const std::string &label = ""
467 );
468
469
485template<class Scalar>
488 const RCP<const LinearOpBase<Scalar> > &Op,
489 const std::string &label = ""
490 );
491
492
509template<class Scalar>
512 const Scalar &scalar, const EOpTransp &transp,
513 const RCP<LinearOpBase<Scalar> > &Op,
514 const std::string &label = ""
515 );
516
517
534template<class Scalar>
537 const Scalar &scalar, const EOpTransp &transp,
538 const RCP<const LinearOpBase<Scalar> > &Op,
539 const std::string &label = ""
540 );
541
542
543// /////////////////////////////////
544// Inline members
545
546
547template<class Scalar>
548inline
550 :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
551 ,overallTransp_(NOTRANS)
552 ,my_index_(0)
553{}
554
555
556template<class Scalar>
557inline
559 const Scalar &scalar
560 ,const EOpTransp &transp
561 ,const RCP<LinearOpBase<Scalar> > &Op
562 )
563 :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
564 ,overallTransp_(NOTRANS)
565{
566 this->initialize(scalar,transp,Op);
567}
568
569
570template<class Scalar>
571inline
573 const Scalar &scalar
574 ,const EOpTransp &transp
575 ,const RCP<const LinearOpBase<Scalar> > &Op
576 )
577 :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
578 ,overallTransp_(NOTRANS)
579{
580 this->initialize(scalar,transp,Op);
581}
582
583
584template<class Scalar>
585inline
587{
588#ifdef TEUCHOS_DEBUG
589 TEUCHOS_TEST_FOR_EXCEPT( origOp_.getConstObj().get() == NULL );
590#endif
591}
592
593
594} // end namespace Thyra
595
596
597// /////////////////////////////////
598// Inline non-members
599
600
601template<class Scalar> inline
603Thyra::nonconstScale(
604 const Scalar &scalar,
605 const RCP<LinearOpBase<Scalar> > &Op,
606 const std::string &label
607 )
608{
609 RCP<Thyra::LinearOpBase<Scalar> >
610 salo = Teuchos::rcp(
611 new DefaultScaledAdjointLinearOp<Scalar>(
612 scalar,NOTRANS,Op
613 )
614 );
615 if (label.length())
616 salo->setObjectLabel(label);
617 return salo;
618}
619
620
621template<class Scalar> inline
623Thyra::scale(
624 const Scalar &scalar,
625 const RCP<const LinearOpBase<Scalar> > &Op,
626 const std::string &label
627 )
628{
629 RCP<Thyra::LinearOpBase<Scalar> >
630 salo = Teuchos::rcp(
631 new DefaultScaledAdjointLinearOp<Scalar>(scalar,NOTRANS,Op)
632 );
633 if (label.length())
634 salo->setObjectLabel(label);
635 return salo;
636}
637
638
639template<class Scalar> inline
641Thyra::nonconstAdjoint(
642 const RCP<LinearOpBase<Scalar> > &Op,
643 const std::string &label
644 )
645{
646 RCP<Thyra::LinearOpBase<Scalar> >
647 salo = Teuchos::rcp(
648 new DefaultScaledAdjointLinearOp<Scalar>(
650 )
651 );
652 if (label.length())
653 salo->setObjectLabel(label);
654 return salo;
655}
656
657
658template<class Scalar> inline
660Thyra::adjoint(
661 const RCP<const LinearOpBase<Scalar> > &Op,
662 const std::string &label
663 )
664{
665 RCP<Thyra::LinearOpBase<Scalar> >
666 salo = Teuchos::rcp(
667 new DefaultScaledAdjointLinearOp<Scalar>(
669 )
670 );
671 if (label.length())
672 salo->setObjectLabel(label);
673 return salo;
674}
675
676
677template<class Scalar> inline
679Thyra::nonconstTranspose(
680 const RCP<LinearOpBase<Scalar> > &Op,
681 const std::string &label
682 )
683{
684 RCP<Thyra::LinearOpBase<Scalar> >
685 salo = Teuchos::rcp(
686 new DefaultScaledAdjointLinearOp<Scalar>(
688 )
689 );
690 if (label.length())
691 salo->setObjectLabel(label);
692 return salo;
693}
694
695
696template<class Scalar> inline
698Thyra::transpose(
699 const RCP<const LinearOpBase<Scalar> > &Op,
700 const std::string &label
701 )
702{
703 RCP<Thyra::LinearOpBase<Scalar> >
704 salo = Teuchos::rcp(
705 new DefaultScaledAdjointLinearOp<Scalar>(
707 )
708 );
709 if (label.length())
710 salo->setObjectLabel(label);
711 return salo;
712}
713
714
715template<class Scalar> inline
717Thyra::nonconstScaleAndAdjoint(
718 const Scalar &scalar,
719 const EOpTransp &transp,
720 const RCP<LinearOpBase<Scalar> > &Op,
721 const std::string &label
722 )
723{
724 RCP<Thyra::LinearOpBase<Scalar> >
725 salo = Teuchos::rcp(
726 new DefaultScaledAdjointLinearOp<Scalar>(scalar,transp,Op)
727 );
728 if (label.length())
729 salo->setObjectLabel(label);
730 return salo;
731}
732
733
734template<class Scalar> inline
736Thyra::scaleAndAdjoint(
737 const Scalar &scalar,
738 const EOpTransp &transp,
739 const RCP<const LinearOpBase<Scalar> > &Op,
740 const std::string &label
741 )
742{
743 RCP<Thyra::LinearOpBase<Scalar> >
744 salo = Teuchos::rcp(
745 new DefaultScaledAdjointLinearOp<Scalar>(
746 scalar, transp, Op
747 )
748 );
749 if (label.length())
750 salo->setObjectLabel(label);
751 return salo;
752}
753
754
755#endif // THYRA_DEFAULT_SCALED_ADJOINT_LINEAR_OP_DECL_HPP
Concrete decorator LinearOpBase subclass that wraps a LinearOpBase object and adds on an extra scalin...
RCP< LinearOpBase< Scalar > > getNonconstOp()
Return the non-const linear operator passed into initialize().
bool opSupportedImpl(EOpTransp M_trans) const
Return if the operation is supported on the logical linear operator.
std::string description() const
Outputs DefaultScaledAdjointLinearOp<Scalar>{this->getOrigOp().description()) along with the dimensio...
RCP< const LinearOpBase< Scalar > > scale(const Scalar &scalar, const RCP< const LinearOpBase< Scalar > > &Op, const std::string &label="")
Build an implicit const scaled linear operator.
RCP< const VectorSpaceBase< Scalar > > domain() const
Return the domain space of the logical linear operator.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Prints out the original operator as well as all of the scalings and transpositions in the order that ...
void uninitialize()
Set to uninitialized and (optionally) extract the objects passed into initialize().
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
Apply the linear operator (or its transpose) to a multi-vector : Y = alpha*op(M)*X + beta*Y.
RCP< const LinearOpBase< Scalar > > transpose(const RCP< const LinearOpBase< Scalar > > &Op, const std::string &label="")
Build an implicit const transposed linear operator.
RCP< LinearOpBase< Scalar > > nonconstAdjoint(const RCP< LinearOpBase< Scalar > > &Op, const std::string &label="")
Build an implicit non-const adjoined linear operator.
RCP< const LinearOpBase< Scalar > > clone() const
RCP< LinearOpBase< Scalar > > nonconstScale(const Scalar &scalar, const RCP< LinearOpBase< Scalar > > &Op, const std::string &label="")
Build an implicit non-const scaled linear operator.
RCP< const LinearOpBase< Scalar > > getOrigOp() const
RCP< const VectorSpaceBase< Scalar > > range() const
Return the range space of the logical linear operator.
void initialize(const Scalar &scalar, const EOpTransp &transp, const RCP< LinearOpBase< Scalar > > &Op)
Initialize with an operator with by defining adjoint (transpose) and scaling arguments.
RCP< LinearOpBase< Scalar > > nonconstTranspose(const RCP< LinearOpBase< Scalar > > &Op, const std::string &label="")
Build an implicit non-const transposed linear operator.
RCP< const LinearOpBase< Scalar > > scaleAndAdjoint(const Scalar &scalar, const EOpTransp &transp, const RCP< const LinearOpBase< Scalar > > &Op, const std::string &label="")
Build an implicit const scaled and/or adjoined (transposed) linear operator.
RCP< const LinearOpBase< Scalar > > adjoint(const RCP< const LinearOpBase< Scalar > > &Op, const std::string &label="")
Build an implicit const adjoined linear operator.
RCP< LinearOpBase< Scalar > > nonconstScaleAndAdjoint(const Scalar &scalar, const EOpTransp &transp, const RCP< LinearOpBase< Scalar > > &Op, const std::string &label="")
Build an implicit non-const scaled and/or adjoined (transposed) linear operator.
RCP< const LinearOpBase< Scalar > > getOp() const
Return the const linear operator passed into initialize().
Base class for all linear operators.
Interface for a collection of column vectors called a multi-vector.
Base class for LinearOpBase decorator subclasses that wrap a LinearOpBase object and adds on an extra...
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
@ NOTRANS
Use the non-transposed operator.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)