Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DiagonalEpetraLinearOpWithSolveFactory.cpp
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 #include "Thyra_DiagonalEpetraLinearOpWithSolveFactory.hpp"
43 #include "Thyra_DefaultDiagonalLinearOpWithSolve.hpp"
44 #include "Thyra_EpetraLinearOp.hpp"
46 #include "Teuchos_dyn_cast.hpp"
47 
48 #include "Epetra_RowMatrix.h"
49 #include "Epetra_Vector.h"
50 #include "Epetra_Map.h"
51 
52 
53 namespace Thyra {
54 
55 
57  const LinearOpSourceBase<double> &fwdOpSrc
58  ) const
59 {
60  using Teuchos::outArg;
62  fwdOp = fwdOpSrc.getOp();
63  const EpetraLinearOpBase *eFwdOp = NULL;
64  if( ! (eFwdOp = dynamic_cast<const EpetraLinearOpBase*>(&*fwdOp)) )
65  return false;
66  RCP<const Epetra_Operator> epetraFwdOp;
67  EOpTransp epetraFwdOpTransp;
68  EApplyEpetraOpAs epetraFwdOpApplyAs;
69  EAdjointEpetraOp epetraFwdOpAdjointSupport;
70  eFwdOp->getEpetraOpView(outArg(epetraFwdOp), outArg(epetraFwdOpTransp),
71  outArg(epetraFwdOpApplyAs), outArg(epetraFwdOpAdjointSupport) );
72  if( !dynamic_cast<const Epetra_RowMatrix*>(&*epetraFwdOp) )
73  return false;
74  return true;
75 }
76 
77 
80 {
82 }
83 
84 
86  const RCP<const LinearOpSourceBase<double> > &fwdOpSrc
88  ,const ESupportSolveUse /* supportSolveUse */
89  ) const
90 {
91  using Teuchos::outArg;
92  TEUCHOS_TEST_FOR_EXCEPT(Op==NULL);
93  TEUCHOS_TEST_FOR_EXCEPT(fwdOpSrc.get()==NULL);
94  TEUCHOS_TEST_FOR_EXCEPT(fwdOpSrc->getOp().get()==NULL);
95  RCP<const LinearOpBase<double> > fwdOp = fwdOpSrc->getOp();
96  const EpetraLinearOpBase &eFwdOp = Teuchos::dyn_cast<const EpetraLinearOpBase>(*fwdOp);
97  RCP<const Epetra_Operator> epetraFwdOp;
98  EOpTransp epetraFwdOpTransp;
99  EApplyEpetraOpAs epetraFwdOpApplyAs;
100  EAdjointEpetraOp epetraFwdOpAdjointSupport;
101  eFwdOp.getEpetraOpView(outArg(epetraFwdOp), outArg(epetraFwdOpTransp),
102  outArg(epetraFwdOpApplyAs), outArg(epetraFwdOpAdjointSupport) );
103  const Epetra_RowMatrix &eRMOp =
104  Teuchos::dyn_cast<const Epetra_RowMatrix>(*epetraFwdOp);
105  const Epetra_Map &map = eRMOp.OperatorDomainMap();
107  e_diag = Teuchos::rcp(new Epetra_Vector(map));
108  eRMOp.ExtractDiagonalCopy(*e_diag);
110  space = create_VectorSpace(Teuchos::rcp(new Epetra_Map(map)));
112  diag = create_Vector(e_diag,space);
113  Teuchos::set_extra_data<RCP<const LinearOpSourceBase<double> > >(
114  fwdOpSrc, "Thyra::DiagonalEpetraLinearOpWithSolveFactory::fwdOpSrc",
115  Teuchos::inOutArg(diag)
116  );
118  Teuchos::rcp_implicit_cast<const VectorBase<double> >(diag)
119  );
120  // Above cast is questionable but should be okay based on use.
121 }
122 
123 
126  ,RCP<const LinearOpSourceBase<double> > *fwdOpSrc
127  ,RCP<const PreconditionerBase<double> > *prec
128  ,RCP<const LinearOpSourceBase<double> > *approxFwdOpSrc
129  ,ESupportSolveUse * /* supportSolveUse */
130  ) const
131 {
132  using Teuchos::get_extra_data;
133  TEUCHOS_TEST_FOR_EXCEPT(Op==NULL);
137  diag = diagOp.getDiag();
138  if( fwdOpSrc ) {
139  if(diag.get()) {
140  *fwdOpSrc =
141  get_extra_data<RCP<const LinearOpSourceBase<double> > >(
142  diag,"Thyra::DiagonalEpetraLinearOpWithSolveFactory::fwdOpSrc"
143  );
144  }
145  }
146  else {
147  *fwdOpSrc = Teuchos::null;
148  }
149  if(prec) *prec = Teuchos::null; // We never keep a preconditioner!
150  if(approxFwdOpSrc) *approxFwdOpSrc = Teuchos::null; // We never keep a preconditioner!
151 }
152 
153 
154 // Overridden from ParameterListAcceptor
155 
156 
158  RCP<Teuchos::ParameterList> const& /* paramList */
159  )
160 {}
161 
162 
165 {
166  return Teuchos::null;
167 }
168 
169 
172 {
173  return Teuchos::null;
174 }
175 
176 
179 {
180  return Teuchos::null;
181 }
182 
183 
186 {
187  return Teuchos::null;
188 }
189 
190 
191 } // namespace Thyra
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const &paramList)
Base class for all linear operators that can support a high-level solve operation.
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
Teuchos::RCP< const Teuchos::ParameterList > getParameterList() const
RCP< const VectorSpaceBase< double > > create_VectorSpace(const RCP< const Epetra_Map > &epetra_map)
Create an VectorSpaceBase object given an Epetra_Map object.
RCP< const VectorBase< Scalar > > getDiag() const
Abstract base class for all LinearOpBase objects that can return an Epetra_Operator view of themselve...
bool isCompatible(const LinearOpSourceBase< double > &fwdOpSrc) const
T_To & dyn_cast(T_From &from)
T * get() const
virtual const Epetra_Map & OperatorDomainMap() const =0
virtual int ExtractDiagonalCopy(Epetra_Vector &Diagonal) const =0
Simple interface class to access a precreated preconditioner as one or more linear operators objects ...
void initialize(const RCP< const VectorSpaceBase< Scalar > > &space)
Initialize given a vector space which allocates a vector internally.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< LinearOpWithSolveBase< double > > createOp() const
RCP< VectorBase< double > > create_Vector(const RCP< Epetra_Vector > &epetra_v, const RCP< const VectorSpaceBase< double > > &space=Teuchos::null)
Create a non-const VectorBase object from a non-const Epetra_Vector object.
Concrete LinearOpWithSolveBase subclass for diagonal linear operators.
void uninitializeOp(LinearOpWithSolveBase< double > *Op, Teuchos::RCP< const LinearOpSourceBase< double > > *fwdOpSrc, Teuchos::RCP< const PreconditionerBase< double > > *prec, Teuchos::RCP< const LinearOpSourceBase< double > > *approxFwdOpSrc, ESupportSolveUse *supportSolveUse) const
Uninitialize a LinearOpWithSolveBase object and return its remembered forward linear operator and pot...
EAdjointEpetraOp
Determine if adjoints are supported on Epetra_Opeator or not.
virtual void getEpetraOpView(const Ptr< RCP< const Epetra_Operator > > &epetraOp, const Ptr< EOpTransp > &epetraOpTransp, const Ptr< EApplyEpetraOpAs > &epetraOpApplyAs, const Ptr< EAdjointEpetraOp > &epetraOpAdjointSupport) const =0
Return a smart pointer to a const Epetra_Operator view of this object and how the object is applied t...
void initializeOp(const Teuchos::RCP< const LinearOpSourceBase< double > > &fwdOpSrc, LinearOpWithSolveBase< double > *Op, const ESupportSolveUse supportSolveUse) const
Abstract interface for finite-dimensional dense vectors.
Base interface for objects that can return a linear operator.
ESupportSolveUse
Enum that specifies how a LinearOpWithSolveBase object will be used for solves after it is constructe...
EApplyEpetraOpAs
Determine how the apply an Epetra_Operator as a linear operator.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
virtual Teuchos::RCP< const LinearOpBase< Scalar > > getOp() const =0
Return a const left preconditioner linear operator if one is designed or targeted to be applied on th...
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)