Thyra Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DiagonalEpetraLinearOpWithSolveFactory.cpp
Go to the documentation of this file.
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 
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 {
81  return Teuchos::rcp(new DefaultDiagonalLinearOpWithSolve<double>());
82 }
83 
84 
86  const RCP<const LinearOpSourceBase<double> > &fwdOpSrc
87  ,LinearOpWithSolveBase<double> *Op
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  );
117  Teuchos::dyn_cast< DefaultDiagonalLinearOpWithSolve<double> >(*Op).initialize(
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 
125  LinearOpWithSolveBase<double> *Op
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);
134  DefaultDiagonalLinearOpWithSolve<double>
135  &diagOp = Teuchos::dyn_cast<DefaultDiagonalLinearOpWithSolve<double> >(*Op);
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)
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.
Abstract base class for all LinearOpBase objects that can return an Epetra_Operator view of themselve...
bool isCompatible(const LinearOpSourceBase< double > &fwdOpSrc) const
T * get() const
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.
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
EAdjointEpetraOp
Determine if adjoints are supported on Epetra_Opeator or not.
T_To & dyn_cast(T_From &from)
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
EApplyEpetraOpAs
Determine how the apply an Epetra_Operator as a linear operator.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)