| 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_AMESOS2_LINEAR_OP_WITH_SOLVE_DECL_HPP |
| 11 |
#define THYRA_AMESOS2_LINEAR_OP_WITH_SOLVE_DECL_HPP |
| 12 |
|
| 13 |
#include "Thyra_LinearOpWithSolveBase.hpp" |
| 14 |
#include "Thyra_LinearOpSourceBase.hpp" |
| 15 |
#include <Tpetra_Map.hpp> |
| 16 |
#include <Tpetra_MultiVector.hpp> |
| 17 |
#include <Tpetra_CrsMatrix.hpp> |
| 18 |
|
| 19 |
#include "Thyra_TpetraLinearOp.hpp" |
| 20 |
#include "Thyra_TpetraThyraWrappers.hpp" |
| 21 |
#include "Thyra_DefaultDiagonalLinearOp.hpp" |
| 22 |
#include "Thyra_LinearOpTester.hpp" |
| 23 |
|
| 24 |
#include "Amesos2.hpp" |
| 25 |
#include "Amesos2_Version.hpp" |
| 26 |
#include "Amesos2_Solver.hpp" |
| 27 |
|
| 28 |
namespace Thyra { |
| 29 |
|
| 30 |
/** \brief Concrete <tt>LinearOpWithSolveBase</tt> subclass in terms of |
| 31 |
* <tt>Amesos2</tt>. |
| 32 |
* |
| 33 |
* ToDo: Finish documentation! |
| 34 |
* |
| 35 |
* \ingroup Amesos2_Thyra_adapters_grp |
| 36 |
*/ |
| 37 |
template<typename Scalar> |
| 38 |
class Amesos2LinearOpWithSolve: virtual public LinearOpWithSolveBase<Scalar> |
| 39 |
{ |
| 40 |
public: |
| 41 |
using MAT = Tpetra::CrsMatrix<Scalar>; |
| 42 |
using Op = Tpetra::Operator<Scalar>; |
| 43 |
using MV = Tpetra::MultiVector<Scalar>; |
| 44 |
using Solver = ::Amesos2::Solver<MAT, MV>; |
| 45 |
using ConverterT = TpetraOperatorVectorExtraction<Scalar>; |
| 46 |
|
| 47 |
/** @name Constructors/initializers/accessors */ |
| 48 |
//@{ |
| 49 |
|
| 50 |
/** \brief Construct to uninitialized. */ |
| 51 |
Amesos2LinearOpWithSolve(); |
| 52 |
|
| 53 |
/** \brief Calls <tt>this->initialize()</tt>. */ |
| 54 |
Amesos2LinearOpWithSolve( |
| 55 |
const Teuchos::RCP<const LinearOpBase<Scalar> > &fwdOp, |
| 56 |
const Teuchos::RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc, |
| 57 |
const Teuchos::RCP< Solver > &amesos2Solver, |
| 58 |
const EOpTransp amesos2SolverTransp, |
| 59 |
const Scalar amesos2SolverScalar |
| 60 |
); |
| 61 |
|
| 62 |
/** \brief Initialize after construction. */ |
| 63 |
void initialize( |
| 64 |
const Teuchos::RCP<const LinearOpBase<Scalar> > &fwdOp, |
| 65 |
const Teuchos::RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc, |
| 66 |
const Teuchos::RCP< Solver > &amesos2Solver |
| 67 |
); |
| 68 |
|
| 69 |
/** \brief Extract the forward <tt>LinearOpSourceBase<double></tt> object so |
| 70 |
* that it can be modified and remove it from this object. |
| 71 |
* |
| 72 |
* <b>Postconditions:</b><ul> |
| 73 |
* <li><tt>return.get()</tt> is the same as <tt>this->get_fwdOpSrc().get()</tt> before call. |
| 74 |
* <li><tt><tt>this->get_fwdOpSrc().get()==NULL</tt> |
| 75 |
* </ul> |
| 76 |
*/ |
| 77 |
Teuchos::RCP<const LinearOpSourceBase<Scalar> > extract_fwdOpSrc(); |
| 78 |
|
| 79 |
/** \brief . */ |
| 80 |
Teuchos::RCP<const LinearOpBase<Scalar> > get_fwdOp() const; |
| 81 |
|
| 82 |
/** \brief . */ |
| 83 |
Teuchos::RCP<Solver> get_amesos2Solver(); |
| 84 |
|
| 85 |
/** \brief . */ |
| 86 |
Teuchos::RCP<const LinearOpSourceBase<Scalar> > get_fwdOpSrc() const; |
| 87 |
|
| 88 |
/** @name Overridden public functions from LinearOpBase */ |
| 89 |
//@{ |
| 90 |
/** \brief. */ |
| 91 |
Teuchos::RCP< const VectorSpaceBase<Scalar> > range() const; |
| 92 |
/** \brief. */ |
| 93 |
Teuchos::RCP< const VectorSpaceBase<Scalar> > domain() const; |
| 94 |
/** \brief. */ |
| 95 |
Teuchos::RCP<const LinearOpBase<Scalar> > clone() const; |
| 96 |
//@} |
| 97 |
|
| 98 |
/** @name Overridden public functions from Teuchos::Describable */ |
| 99 |
//@{ |
| 100 |
/** \brief . */ |
| 101 |
std::string description() const; |
| 102 |
/** \brief . */ |
| 103 |
void describe( |
| 104 |
Teuchos::FancyOStream &out, |
| 105 |
const Teuchos::EVerbosityLevel verbLevel |
| 106 |
) const; |
| 107 |
//@} |
| 108 |
|
| 109 |
protected: |
| 110 |
|
| 111 |
/** @name Overridden from LinearOpBase */ |
| 112 |
//@{ |
| 113 |
/** \brief . */ |
| 114 |
virtual bool opSupportedImpl(EOpTransp M_trans) const; |
| 115 |
/** \brief . */ |
| 116 |
virtual void applyImpl( |
| 117 |
const EOpTransp M_trans, |
| 118 |
const MultiVectorBase<Scalar> &X, |
| 119 |
const Ptr<MultiVectorBase<Scalar> > &Y, |
| 120 |
const Scalar alpha, |
| 121 |
const Scalar beta |
| 122 |
) const; |
| 123 |
//@} |
| 124 |
|
| 125 |
/** @name Overridden from LinearOpWithSolveBase. */ |
| 126 |
//@{ |
| 127 |
/** \brief . */ |
| 128 |
virtual bool solveSupportsImpl(EOpTransp M_trans) const; |
| 129 |
/** \brief . */ |
| 130 |
virtual bool solveSupportsSolveMeasureTypeImpl( |
| 131 |
EOpTransp M_trans, const SolveMeasureType& solveMeasureType |
| 132 |
) const; |
| 133 |
/** \brief . */ |
| 134 |
SolveStatus<Scalar> solveImpl( |
| 135 |
const EOpTransp M_trans, |
| 136 |
const MultiVectorBase<Scalar> &B, |
| 137 |
const Ptr<MultiVectorBase<Scalar> > &X, |
| 138 |
const Ptr<const SolveCriteria<Scalar> > solveCriteria |
| 139 |
) const; |
| 140 |
//@} |
| 141 |
|
| 142 |
private: |
| 143 |
|
| 144 |
Teuchos::RCP<const LinearOpBase<Scalar> > fwdOp_; |
| 145 |
Teuchos::RCP<const LinearOpSourceBase<Scalar> > fwdOpSrc_; |
| 146 |
Teuchos::RCP< Solver > amesos2Solver_; |
| 147 |
|
| 148 |
void assertInitialized() const; |
| 149 |
|
| 150 |
}; |
| 151 |
|
| 152 |
// /////////////////////////// |
| 153 |
// Inline members |
| 154 |
|
| 155 |
template<typename Scalar> |
| 156 |
inline |
| 157 |
Teuchos::RCP<const LinearOpBase<Scalar> > |
| 158 |
Amesos2LinearOpWithSolve<Scalar>::get_fwdOp() const |
| 159 |
{ |
| 160 |
return fwdOp_; |
| 161 |
} |
| 162 |
|
| 163 |
template<typename Scalar> |
| 164 |
inline |
| 165 |
Teuchos::RCP<typename Amesos2LinearOpWithSolve<Scalar>::Solver> |
| 166 |
Amesos2LinearOpWithSolve<Scalar>::get_amesos2Solver() |
| 167 |
{ |
| 168 |
return amesos2Solver_; |
| 169 |
} |
| 170 |
|
| 171 |
template<typename Scalar> |
| 172 |
inline |
| 173 |
Teuchos::RCP<const LinearOpSourceBase<Scalar> > |
| 174 |
Amesos2LinearOpWithSolve<Scalar>::get_fwdOpSrc() const |
| 175 |
{ |
| 176 |
return fwdOpSrc_; |
| 177 |
} |
| 178 |
|
| 179 |
} // namespace Thyra |
| 180 |
|
| 181 |
#endif // THYRA_AMESOS2_LINEAR_OP_WITH_SOLVE_HPP |