Debian Codegraph @

packages/stratimikos/adapters/amesos/src/Thyra_AmesosLinearOpWithSolve.hpp

raw
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
10 #ifndef THYRA_AMESOS_LINEAR_OP_WITH_SOLVE_HPP
11 #define THYRA_AMESOS_LINEAR_OP_WITH_SOLVE_HPP
12
13 #include "Thyra_LinearOpWithSolveBase.hpp"
14 #include "Thyra_LinearOpSourceBase.hpp"
15 #include "Thyra_EpetraLinearOpBase.hpp"
16 #include "Epetra_LinearProblem.h"
17 #include "Amesos_BaseSolver.h"
18
19
20 namespace Thyra {
21
22
23 /** \brief Concrete <tt>LinearOpWithSolveBase</tt> subclass that adapts any
24 * <tt>Amesos_BaseSolver</tt> object.
25 *
26 * See the <tt>LinearOpWithSolveBase</tt> interface for a description of how
27 * to use objects of this type.
28 *
29 * <b>Note:</b> Clients should not generally directly create objects of this
30 * type but instead should use <tt>AmesosLinearOpWithSolveFactory</tt>. Only
31 * very sophisticated users should ever directly interact with an object
32 * through this subclass interface.
33 *
34 * \ingroup Amesos_Thyra_adapters_grp
35 */
36 class AmesosLinearOpWithSolve : virtual public LinearOpWithSolveBase<double>
37 {
38 public:
39
40 /** @name Constructors/initializers/accessors */
41 //@{
42
43 /** \brief Construct to uninitialized. */
44 AmesosLinearOpWithSolve();
45
46 /** \brief Calls <tt>this->initialize()</tt>. */
47 AmesosLinearOpWithSolve(
48 const Teuchos::RCP<const LinearOpBase<double> > &fwdOp,
49 const Teuchos::RCP<const LinearOpSourceBase<double> > &fwdOpSrc,
50 const Teuchos::RCP<Epetra_LinearProblem> &epetraLP,
51 const Teuchos::RCP<Amesos_BaseSolver> &amesosSolver,
52 const EOpTransp amesosSolverTransp,
53 const double amesosSolverScalar
54 );
55
56 /** \brief First initialization.
57 *
58 * \param fwdOp
59 * [in] The forward operator for which the factorization exists.
60 * \param epetraLP
61 * [in] The <tt>Epetra_LinearProblem</tt> object that was used to
62 * create the <tt>Amesos_BaseSolver</tt> object
63 * <tt>*amesosSolver</tt>. Note that the RHS and the LHS
64 * multi-vector pointers in this object will be set and unset
65 * here.
66 * \param amesosSolver
67 * [in] Contains the factored, and ready to go,
68 * <tt>Amesos_BaseSolver</tt> object ready to solve linear system.
69 * \param amesosSolverTransp
70 * [in] Determines if the %Amesos solver should be used as its
71 * transpose or not.
72 * \param amesosSolverScalar
73 * [in] Determines the scaling factor associated with the %Amesos
74 * solver. The solution to the linear solve is scaled by
75 * <tt>1/amesosSolverScalar</tt>.
76 *
77 * <b>Preconditions:</b><ul>
78 * <li><tt>fwdOp.get()!=NULL</tt>
79 * <li><tt>epetraLP.get()!=NULL</tt>
80 * <li><tt>amesosSolver.get()!=NULL</tt>
81 * <li><tt>*epetraLP->GetOperator()</tt> is compatible with <tt>*fwdOp</tt>
82 * <li><tt>epetraLP->GetLHS()==NULL</tt>
83 * <li><tt>epetraLP->GetRHS()==NULL</tt>
84 * <li><tt>*amesosSolver</tt> contains the factorization of <tt>*fwdOp</tt> and is
85 * ready to solve linear systems!
86 * </ul>
87 *
88 * <b>Postconditions:</b><ul>
89 * <li><tt>this->get_fwdOp().get() == fwdOp.get()</tt>
90 * <li><tt>this->get_epetraLP().get() == epetraLP.get()</tt>
91 * <li><tt>this->get_amesosSolver().get() == amesosSolver.get()</tt>
92 * <li><tt>this->get_amesosSolverTransp() == amesosSolverTransp</tt>
93 * <li><tt>this->get_amesosSolverScalar() == amesosSolverScalar</tt>
94 * </ul>
95 */
96 void initialize(
97 const Teuchos::RCP<const LinearOpBase<double> > &fwdOp,
98 const Teuchos::RCP<const LinearOpSourceBase<double> > &fwdOpSrc,
99 const Teuchos::RCP<Epetra_LinearProblem> &epetraLP,
100 const Teuchos::RCP<Amesos_BaseSolver> &amesosSolver,
101 const EOpTransp amesosSolverTransp,
102 const double amesosSolverScalar
103 );
104
105 /** \brief Extract the <tt>LinearOpSourceBase<double></tt> object so that it can be modified.
106 *
107 * <b>Postconditions:</b><ul>
108 * <li><tt>return.get()</tt> is the same as <tt>this->get_fwdOpSrc().get()</tt> before call.
109 * <li><tt><tt>this->get_fwdOpSrc().get()==NULL</tt>
110 * </ul>
111 */
112 Teuchos::RCP<const LinearOpSourceBase<double> > extract_fwdOpSrc();
113
114 /** \brief . */
115 Teuchos::RCP<const LinearOpBase<double> > get_fwdOp() const;
116
117 /** \brief . */
118 Teuchos::RCP<const LinearOpSourceBase<double> > get_fwdOpSrc() const;
119
120 /** \brief . */
121 Teuchos::RCP<Epetra_LinearProblem> get_epetraLP() const;
122
123 /** \brief . */
124 Teuchos::RCP<Amesos_BaseSolver> get_amesosSolver() const;
125
126 /** \brief . */
127 EOpTransp get_amesosSolverTransp() const;
128
129 /** \brief . */
130 double get_amesosSolverScalar() const;
131
132 /** \brief Uninitialize.
133 */
134 void uninitialize(
135 Teuchos::RCP<const LinearOpBase<double> > *fwdOp = NULL,
136 Teuchos::RCP<const LinearOpSourceBase<double> > *fwdOpSrc = NULL,
137 Teuchos::RCP<Epetra_LinearProblem> *epetraLP = NULL,
138 Teuchos::RCP<Amesos_BaseSolver> *amesosSolver = NULL,
139 EOpTransp *amesosSolverTransp = NULL,
140 double *amesosSolverScalar = NULL
141 );
142
143 //@}
144
145 /** @name Overridden public functions from LinearOpBase */
146 //@{
147 /** \brief. */
148 Teuchos::RCP< const VectorSpaceBase<double> > range() const;
149 /** \brief. */
150 Teuchos::RCP< const VectorSpaceBase<double> > domain() const;
151 /** \brief. */
152 Teuchos::RCP<const LinearOpBase<double> > clone() const;
153 //@}
154
155 /** @name Overridden public functions from Teuchos::Describable */
156 //@{
157 /** \brief . */
158 std::string description() const;
159 /** \brief . */
160 void describe(
161 Teuchos::FancyOStream &out,
162 const Teuchos::EVerbosityLevel verbLevel
163 ) const;
164 //@}
165
166 protected:
167
168 /** @name Overridden from LinearOpBase */
169 //@{
170 /** \brief . */
171 virtual bool opSupportedImpl(EOpTransp M_trans) const;
172 /** \brief . */
173 virtual void applyImpl(
174 const EOpTransp M_trans,
175 const MultiVectorBase<double> &X,
176 const Ptr<MultiVectorBase<double> > &Y,
177 const double alpha,
178 const double beta
179 ) const;
180 //@}
181
182 /** @name Overridden from LinearOpWithSolveBase. */
183 //@{
184 /** \brief . */
185 virtual bool solveSupportsImpl(EOpTransp M_trans) const;
186 /** \brief . */
187 virtual bool solveSupportsSolveMeasureTypeImpl(
188 EOpTransp M_trans, const SolveMeasureType& solveMeasureType
189 ) const;
190 /** \brief . */
191 SolveStatus<double> solveImpl(
192 const EOpTransp M_trans,
193 const MultiVectorBase<double> &B,
194 const Ptr<MultiVectorBase<double> > &X,
195 const Ptr<const SolveCriteria<double> > solveCriteria
196 ) const;
197 //@}
198
199 private:
200
201 Teuchos::RCP<const LinearOpBase<double> > fwdOp_;
202 Teuchos::RCP<const LinearOpSourceBase<double> > fwdOpSrc_;
203 Teuchos::RCP<Epetra_LinearProblem> epetraLP_;
204 Teuchos::RCP<Amesos_BaseSolver> amesosSolver_;
205 EOpTransp amesosSolverTransp_;
206 double amesosSolverScalar_;
207
208 void assertInitialized() const;
209
210 };
211
212 // ///////////////////////////
213 // Inline members
214
215 inline
216 Teuchos::RCP<const LinearOpBase<double> >
217 AmesosLinearOpWithSolve::get_fwdOp() const
218 {
219 return fwdOp_;
220 }
221
222 inline
223 Teuchos::RCP<const LinearOpSourceBase<double> >
224 AmesosLinearOpWithSolve::get_fwdOpSrc() const
225 {
226 return fwdOpSrc_;
227 }
228
229 inline
230 Teuchos::RCP<Epetra_LinearProblem>
231 AmesosLinearOpWithSolve::get_epetraLP() const
232 {
233 return epetraLP_;
234 }
235
236 inline
237 Teuchos::RCP<Amesos_BaseSolver>
238 AmesosLinearOpWithSolve::get_amesosSolver() const
239 {
240 return amesosSolver_;
241 }
242
243 inline
244 EOpTransp AmesosLinearOpWithSolve::get_amesosSolverTransp() const
245 {
246 return amesosSolverTransp_;
247 }
248
249 inline
250 double AmesosLinearOpWithSolve::get_amesosSolverScalar() const
251 {
252 return amesosSolverScalar_;
253 }
254
255 } // namespace Thyra
256
257 #endif // THYRA_AMESOS_LINEAR_OP_WITH_SOLVE_HPP