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 //
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_DEFAULT_SCALED_ADJOINT_LINEAR_OP_DECL_HPP
43 #define THYRA_DEFAULT_SCALED_ADJOINT_LINEAR_OP_DECL_HPP
44 
45 
46 #include "Thyra_ScaledAdjointLinearOpBase.hpp"
47 #include "Teuchos_ConstNonconstObjectContainer.hpp"
48 
49 
50 namespace Thyra {
51 
52 
125 template<class Scalar>
127  : virtual public ScaledAdjointLinearOpBase<Scalar>
128 {
129 public:
130 
133 
141 
149  const Scalar &scalar,
150  const EOpTransp &transp,
151  const RCP<LinearOpBase<Scalar> > &Op
152  );
153 
161  const Scalar &scalar,
162  const EOpTransp &transp,
163  const RCP<const LinearOpBase<Scalar> > &Op
164  );
165 
187  void initialize(
188  const Scalar &scalar,
189  const EOpTransp &transp,
190  const RCP<LinearOpBase<Scalar> > &Op
191  );
192 
213  void initialize(
214  const Scalar &scalar
215  ,const EOpTransp &transp
216  ,const RCP<const LinearOpBase<Scalar> > &Op
217  );
218 
223 
228 
235  void uninitialize();
236 
238 
241 
246  std::string description() const;
247 
256  void describe(
258  const Teuchos::EVerbosityLevel verbLevel
259  ) const;
260 
262 
265 
274 
283 
286 
288 
291 
293  Scalar overallScalar() const;
295  EOpTransp overallTransp() const;
300 
302 
303 protected:
304 
307 
316  bool opSupportedImpl(EOpTransp M_trans) const;
317 
326  void applyImpl(
327  const EOpTransp M_trans,
328  const MultiVectorBase<Scalar> &X,
329  const Ptr<MultiVectorBase<Scalar> > &Y,
330  const Scalar alpha,
331  const Scalar beta
332  ) const;
333 
335 
336 private:
337 
338  // ////////////////////////////////
339  // Private types
340 
341  template <class Scalar2>
342  struct ScalarETransp {
343  Scalar2 scalar;
344  EOpTransp transp;
345  ScalarETransp()
346  {}
347  ScalarETransp( const Scalar2 &_scalar, const EOpTransp &_transp )
348  : scalar(_scalar), transp(_transp)
349  {}
350  };
351 
352  typedef std::vector<ScalarETransp<Scalar> > allScalarETransp_t;
353 
355 
356  // ////////////////////////////////
357  // Private data members
358 
359  CNLOC origOp_;
360  Scalar overallScalar_;
361  EOpTransp overallTransp_;
362  int my_index_;
363 
364  RCP<allScalarETransp_t> allScalarETransp_;
365 
366  // ////////////////////////////////
367  // Private member functions
368 
369  void initializeImpl(
370  const Scalar &scalar,
371  const EOpTransp &transp,
372  const RCP<const LinearOpBase<Scalar> > &Op,
373  const bool isConst
374  );
375  CNLOC getOpImpl() const;
376  void assertInitialized() const;
377 
378  // Not defined and not to be called
381 
382 };
383 
384 
400 template<class Scalar>
402 nonconstScale(
403  const Scalar &scalar,
404  const RCP<LinearOpBase<Scalar> > &Op,
405  const std::string &label = ""
406  );
407 
408 
424 template<class Scalar>
426 scale(
427  const Scalar &scalar,
428  const RCP<const LinearOpBase<Scalar> > &Op,
429  const std::string &label = ""
430  );
431 
432 
448 template<class Scalar>
450 nonconstAdjoint(
451  const RCP<LinearOpBase<Scalar> > &Op,
452  const std::string &label = ""
453  );
454 
455 
471 template<class Scalar>
473 adjoint(
474  const RCP<const LinearOpBase<Scalar> > &Op,
475  const std::string &label = ""
476  );
477 
478 
494 template<class Scalar>
496 nonconstTranspose(
497  const RCP<LinearOpBase<Scalar> > &Op,
498  const std::string &label = ""
499  );
500 
501 
517 template<class Scalar>
519 transpose(
520  const RCP<const LinearOpBase<Scalar> > &Op,
521  const std::string &label = ""
522  );
523 
524 
541 template<class Scalar>
543 nonconstScaleAndAdjoint(
544  const Scalar &scalar, const EOpTransp &transp,
545  const RCP<LinearOpBase<Scalar> > &Op,
546  const std::string &label = ""
547  );
548 
549 
566 template<class Scalar>
568 scaleAndAdjoint(
569  const Scalar &scalar, const EOpTransp &transp,
570  const RCP<const LinearOpBase<Scalar> > &Op,
571  const std::string &label = ""
572  );
573 
574 
575 // /////////////////////////////////
576 // Inline members
577 
578 
579 template<class Scalar>
580 inline
582  :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
583  ,overallTransp_(NOTRANS)
584  ,my_index_(0)
585 {}
586 
587 
588 template<class Scalar>
589 inline
591  const Scalar &scalar
592  ,const EOpTransp &transp
593  ,const RCP<LinearOpBase<Scalar> > &Op
594  )
595  :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
596  ,overallTransp_(NOTRANS)
597 {
598  this->initialize(scalar,transp,Op);
599 }
600 
601 
602 template<class Scalar>
603 inline
605  const Scalar &scalar
606  ,const EOpTransp &transp
607  ,const RCP<const LinearOpBase<Scalar> > &Op
608  )
609  :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
610  ,overallTransp_(NOTRANS)
611 {
612  this->initialize(scalar,transp,Op);
613 }
614 
615 
616 template<class Scalar>
617 inline
619 {
620 #ifdef TEUCHOS_DEBUG
621  TEUCHOS_TEST_FOR_EXCEPT( origOp_.getConstObj().get() == NULL );
622 #endif
623 }
624 
625 
626 } // end namespace Thyra
627 
628 
629 // /////////////////////////////////
630 // Inline non-members
631 
632 
633 template<class Scalar> inline
635 Thyra::nonconstScale(
636  const Scalar &scalar,
637  const RCP<LinearOpBase<Scalar> > &Op,
638  const std::string &label
639  )
640 {
641  RCP<Thyra::LinearOpBase<Scalar> >
642  salo = Teuchos::rcp(
643  new DefaultScaledAdjointLinearOp<Scalar>(
644  scalar,NOTRANS,Op
645  )
646  );
647  if (label.length())
648  salo->setObjectLabel(label);
649  return salo;
650 }
651 
652 
653 template<class Scalar> inline
655 Thyra::scale(
656  const Scalar &scalar,
657  const RCP<const LinearOpBase<Scalar> > &Op,
658  const std::string &label
659  )
660 {
661  RCP<Thyra::LinearOpBase<Scalar> >
662  salo = Teuchos::rcp(
663  new DefaultScaledAdjointLinearOp<Scalar>(scalar,NOTRANS,Op)
664  );
665  if (label.length())
666  salo->setObjectLabel(label);
667  return salo;
668 }
669 
670 
671 template<class Scalar> inline
673 Thyra::nonconstAdjoint(
674  const RCP<LinearOpBase<Scalar> > &Op,
675  const std::string &label
676  )
677 {
678  RCP<Thyra::LinearOpBase<Scalar> >
679  salo = Teuchos::rcp(
680  new DefaultScaledAdjointLinearOp<Scalar>(
682  )
683  );
684  if (label.length())
685  salo->setObjectLabel(label);
686  return salo;
687 }
688 
689 
690 template<class Scalar> inline
692 Thyra::adjoint(
693  const RCP<const LinearOpBase<Scalar> > &Op,
694  const std::string &label
695  )
696 {
697  RCP<Thyra::LinearOpBase<Scalar> >
698  salo = Teuchos::rcp(
699  new DefaultScaledAdjointLinearOp<Scalar>(
701  )
702  );
703  if (label.length())
704  salo->setObjectLabel(label);
705  return salo;
706 }
707 
708 
709 template<class Scalar> inline
711 Thyra::nonconstTranspose(
712  const RCP<LinearOpBase<Scalar> > &Op,
713  const std::string &label
714  )
715 {
716  RCP<Thyra::LinearOpBase<Scalar> >
717  salo = Teuchos::rcp(
718  new DefaultScaledAdjointLinearOp<Scalar>(
720  )
721  );
722  if (label.length())
723  salo->setObjectLabel(label);
724  return salo;
725 }
726 
727 
728 template<class Scalar> inline
730 Thyra::transpose(
731  const RCP<const LinearOpBase<Scalar> > &Op,
732  const std::string &label
733  )
734 {
735  RCP<Thyra::LinearOpBase<Scalar> >
736  salo = Teuchos::rcp(
737  new DefaultScaledAdjointLinearOp<Scalar>(
739  )
740  );
741  if (label.length())
742  salo->setObjectLabel(label);
743  return salo;
744 }
745 
746 
747 template<class Scalar> inline
749 Thyra::nonconstScaleAndAdjoint(
750  const Scalar &scalar,
751  const EOpTransp &transp,
752  const RCP<LinearOpBase<Scalar> > &Op,
753  const std::string &label
754  )
755 {
756  RCP<Thyra::LinearOpBase<Scalar> >
757  salo = Teuchos::rcp(
758  new DefaultScaledAdjointLinearOp<Scalar>(scalar,transp,Op)
759  );
760  if (label.length())
761  salo->setObjectLabel(label);
762  return salo;
763 }
764 
765 
766 template<class Scalar> inline
768 Thyra::scaleAndAdjoint(
769  const Scalar &scalar,
770  const EOpTransp &transp,
771  const RCP<const LinearOpBase<Scalar> > &Op,
772  const std::string &label
773  )
774 {
775  RCP<Thyra::LinearOpBase<Scalar> >
776  salo = Teuchos::rcp(
777  new DefaultScaledAdjointLinearOp<Scalar>(
778  scalar, transp, Op
779  )
780  );
781  if (label.length())
782  salo->setObjectLabel(label);
783  return salo;
784 }
785 
786 
787 #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)