Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
18 namespace Thyra {
19 
20 
93 template<class Scalar>
95  : virtual public ScaledAdjointLinearOpBase<Scalar>
96 {
97 public:
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 
271 protected:
272 
275 
284  bool opSupportedImpl(EOpTransp M_trans) const;
285 
294  void applyImpl(
295  const EOpTransp M_trans,
296  const MultiVectorBase<Scalar> &X,
297  const Ptr<MultiVectorBase<Scalar> > &Y,
298  const Scalar alpha,
299  const Scalar beta
300  ) const;
301 
303 
304 private:
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 
368 template<class Scalar>
370 nonconstScale(
371  const Scalar &scalar,
372  const RCP<LinearOpBase<Scalar> > &Op,
373  const std::string &label = ""
374  );
375 
376 
392 template<class Scalar>
394 scale(
395  const Scalar &scalar,
396  const RCP<const LinearOpBase<Scalar> > &Op,
397  const std::string &label = ""
398  );
399 
400 
416 template<class Scalar>
418 nonconstAdjoint(
419  const RCP<LinearOpBase<Scalar> > &Op,
420  const std::string &label = ""
421  );
422 
423 
439 template<class Scalar>
441 adjoint(
442  const RCP<const LinearOpBase<Scalar> > &Op,
443  const std::string &label = ""
444  );
445 
446 
462 template<class Scalar>
464 nonconstTranspose(
465  const RCP<LinearOpBase<Scalar> > &Op,
466  const std::string &label = ""
467  );
468 
469 
485 template<class Scalar>
487 transpose(
488  const RCP<const LinearOpBase<Scalar> > &Op,
489  const std::string &label = ""
490  );
491 
492 
509 template<class Scalar>
511 nonconstScaleAndAdjoint(
512  const Scalar &scalar, const EOpTransp &transp,
513  const RCP<LinearOpBase<Scalar> > &Op,
514  const std::string &label = ""
515  );
516 
517 
534 template<class Scalar>
536 scaleAndAdjoint(
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 
547 template<class Scalar>
548 inline
550  :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
551  ,overallTransp_(NOTRANS)
552  ,my_index_(0)
553 {}
554 
555 
556 template<class Scalar>
557 inline
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 
570 template<class Scalar>
571 inline
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 
584 template<class Scalar>
585 inline
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 
601 template<class Scalar> inline
603 Thyra::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 
621 template<class Scalar> inline
623 Thyra::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 
639 template<class Scalar> inline
641 Thyra::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 
658 template<class Scalar> inline
660 Thyra::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 
677 template<class Scalar> inline
679 Thyra::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 
696 template<class Scalar> inline
698 Thyra::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 
715 template<class Scalar> inline
717 Thyra::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 
734 template<class Scalar> inline
736 Thyra::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
RCP< const VectorSpaceBase< Scalar > > range() const
Return the range space of the logical linear operator.
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
RCP< const LinearOpBase< Scalar > > getOrigOp() const
std::string description() const
Outputs DefaultScaledAdjointLinearOp&lt;Scalar&gt;{this-&gt;getOrigOp().description()) along with the dimensio...
Use the non-transposed operator.
Use the transposed operator with complex-conjugate clements (same as TRANS for real scalar types)...
RCP< LinearOpBase< Scalar > > getNonconstOp()
Return the non-const linear operator passed into initialize().
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.
Use the transposed operator.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
RCP< const LinearOpBase< Scalar > > getOp() const
Return the const linear operator passed into initialize().
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...
Concrete decorator LinearOpBase subclass that wraps a LinearOpBase object and adds on an extra scalin...
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...
Base class for all linear operators.
RCP< const LinearOpBase< Scalar > > clone() const
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 ...
RCP< const VectorSpaceBase< Scalar > > domain() const
Return the domain space of the logical linear operator.
bool opSupportedImpl(EOpTransp M_trans) const
Return if the operation is supported on the logical linear operator.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)