Stratimikos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_Amesos2LinearOpWithSolve_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stratimikos: Thyra-based strategies for linear solvers
4 //
5 // Copyright 2006 NTESS and the Stratimikos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
11 #include "Thyra_MultiVectorStdOps.hpp"
12 #include "Teuchos_TimeMonitor.hpp"
13 #include <Teuchos_RCP.hpp>
14 
15 
16 namespace Thyra {
17 
18 
19 // Constructors/initializers/accessors
20 
21 
22 template<typename Scalar>
24 {}
25 
26 
27 template<typename Scalar>
29  const Teuchos::RCP<const LinearOpBase<Scalar> > &fwdOp,
30  const Teuchos::RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
31  const Teuchos::RCP< Solver > &amesos2Solver,
32  const EOpTransp /* amesos2SolverTransp */,
33  const Scalar /* amesos2SolverScalar */
34  )
35 {
36  this->initialize(fwdOp,fwdOpSrc,amesos2Solver);
37 }
38 
39 
40 template<typename Scalar>
42  const Teuchos::RCP<const LinearOpBase<Scalar> > &fwdOp,
43  const Teuchos::RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
44  const Teuchos::RCP< Solver > &amesos2Solver
45  )
46 {
47  fwdOp_ = fwdOp;
48  fwdOpSrc_ = fwdOpSrc;
49  amesos2Solver_ = amesos2Solver;
50  const std::string fwdOpLabel = fwdOp_->getObjectLabel();
51  if(fwdOpLabel.length())
52  this->setObjectLabel( "lows("+fwdOpLabel+")" );
53 }
54 
55 
56 template<typename Scalar>
59 {
61  _fwdOpSrc = fwdOpSrc_;
62  fwdOpSrc_ = Teuchos::null;
63  return _fwdOpSrc;
64 }
65 
66 
67 // Overridden from LinearOpBase
68 
69 
70 template<typename Scalar>
73 {
74  return ( fwdOp_.get() ? fwdOp_->range() : Teuchos::null );
75 }
76 
77 
78 template<typename Scalar>
81 {
82  return ( fwdOp_.get() ? fwdOp_->domain() : Teuchos::null );
83 }
84 
85 
86 template<typename Scalar>
89 {
90  return Teuchos::null; // Not supported yet but could be
91 }
92 
93 
94 // Overridden from Teuchos::Describable
95 
96 
97 template<typename Scalar>
99 {
100  std::ostringstream oss;
102  if(!is_null(amesos2Solver_)) {
103  oss
104  << "{fwdOp="<<fwdOp_->description()
105  << ",amesos2Solver="<<typeName(*amesos2Solver_)<<"}";
106  }
107  return oss.str();
108 }
109 
110 
111 template<typename Scalar>
114  const Teuchos::EVerbosityLevel verbLevel
115  ) const
116 {
117  using Teuchos::OSTab;
118  using Teuchos::typeName;
119  using Teuchos::describe;
120  switch(verbLevel) {
122  case Teuchos::VERB_LOW:
123  out << this->description() << std::endl;
124  break;
126  case Teuchos::VERB_HIGH:
128  {
129  out
131  << "rangeDim=" << this->range()->dim()
132  << ",domainDim="<< this->domain()->dim() << "}\n";
133  OSTab tab(out);
134  if(!is_null(fwdOp_)) {
135  out << "fwdOp = " << describe(*fwdOp_,verbLevel);
136  }
137  if(!is_null(amesos2Solver_)) {
138  out << "amesos2Solver=" << typeName(*amesos2Solver_) << "\n";
139  }
140  break;
141  }
142  default:
143  TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
144  }
145 }
146 
147 
148 // protected
149 
150 
151 // Overridden from LinearOpBase
152 
153 
154 template<typename Scalar>
156 {
157  return ::Thyra::opSupported(*fwdOp_,M_trans);
158 }
159 
160 
161 template<typename Scalar>
163  const EOpTransp M_trans,
164  const MultiVectorBase<Scalar> &X,
165  const Ptr<MultiVectorBase<Scalar> > &Y,
166  const Scalar alpha,
167  const Scalar beta
168  ) const
169 {
170  Thyra::apply( *fwdOp_, M_trans, X, Y, alpha, beta );
171 }
172 
173 
174 // Overridden from LinearOpWithSolveBase
175 
176 template<typename Scalar>
178 {
179  if (Thyra::real_trans(M_trans) == Thyra::NOTRANS) {
180  // Assume every amesos2 solver supports a basic forward solve!
181  return true;
182  }
183  // dai: not sure how to query amesos2 transpose capability
184  return false;
185 }
186 
187 
188 template<typename Scalar>
190  EOpTransp /* M_trans */, const SolveMeasureType& /* solveMeasureType */
191  ) const
192 {
193  return true; // I am a direct solver so I should be able to do it all!
194 }
195 
196 
197 template<typename Scalar>
198 SolveStatus<Scalar>
200  const EOpTransp /* M_trans */,
201  const MultiVectorBase<Scalar> &B,
202  const Ptr<MultiVectorBase<Scalar> > &X,
203  const Ptr<const SolveCriteria<Scalar> > /* solveCriteria */
204  ) const
205 {
206  auto Btpetra = ConverterT::getConstTpetraMultiVector(Teuchos::rcpFromRef(B));
207 
208  auto Xtpetra = ConverterT::getTpetraMultiVector(Teuchos::rcpFromPtr(X));
209 
210  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
211  Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
212 
213  if(out.get() && static_cast<int>(verbLevel) > static_cast<int>(Teuchos::VERB_NONE))
214  *out << "\nSolving system using Amesos2 solver "
215  << typeName(*amesos2Solver_) << " ...\n\n";
216 
217  amesos2Solver_->solve(Xtpetra.ptr(), Btpetra.ptr());
218 
219  SolveStatus<Scalar> solveStatus;
220  solveStatus.solveStatus = SOLVE_STATUS_CONVERGED;
221  return solveStatus;
222 }
223 
224 
225 } // end namespace Thyra
virtual bool solveSupportsSolveMeasureTypeImpl(EOpTransp M_trans, const SolveMeasureType &solveMeasureType) const
void initialize(const Teuchos::RCP< const LinearOpBase< Scalar > > &fwdOp, const Teuchos::RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const Teuchos::RCP< Solver > &amesos2Solver)
Initialize after construction.
std::string typeName(const T &t)
SolveStatus< Scalar > solveImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &B, const Ptr< MultiVectorBase< Scalar > > &X, const Ptr< const SolveCriteria< Scalar > > solveCriteria) const
bool is_null(const boost::shared_ptr< T > &p)
virtual void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
T * get() const
virtual bool opSupportedImpl(EOpTransp M_trans) const
basic_OSTab< char > OSTab
Teuchos::RCP< const VectorSpaceBase< Scalar > > domain() const
Teuchos::RCP< const LinearOpBase< Scalar > > clone() const
virtual std::string description() const
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Teuchos::RCP< const VectorSpaceBase< Scalar > > range() const
virtual bool solveSupportsImpl(EOpTransp M_trans) const
Amesos2LinearOpWithSolve()
Construct to uninitialized.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Teuchos::RCP< const LinearOpSourceBase< Scalar > > extract_fwdOpSrc()
Extract the forward LinearOpSourceBase&lt;double&gt; object so that it can be modified and remove it from t...