// @HEADER // ***************************************************************************** // Stratimikos: Thyra-based strategies for linear solvers // // Copyright 2006 NTESS and the Stratimikos contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef THYRA_AMESOS_LINEAR_OP_WITH_SOLVE_HPP #define THYRA_AMESOS_LINEAR_OP_WITH_SOLVE_HPP #include "Thyra_LinearOpWithSolveBase.hpp" #include "Thyra_LinearOpSourceBase.hpp" #include "Thyra_EpetraLinearOpBase.hpp" #include "Epetra_LinearProblem.h" #include "Amesos_BaseSolver.h" namespace Thyra { /** \brief Concrete LinearOpWithSolveBase subclass that adapts any * Amesos_BaseSolver object. * * See the LinearOpWithSolveBase interface for a description of how * to use objects of this type. * * Note: Clients should not generally directly create objects of this * type but instead should use AmesosLinearOpWithSolveFactory. Only * very sophisticated users should ever directly interact with an object * through this subclass interface. * * \ingroup Amesos_Thyra_adapters_grp */ class AmesosLinearOpWithSolve : virtual public LinearOpWithSolveBase { public: /** @name Constructors/initializers/accessors */ //@{ /** \brief Construct to uninitialized. */ AmesosLinearOpWithSolve(); /** \brief Calls this->initialize(). */ AmesosLinearOpWithSolve( const Teuchos::RCP > &fwdOp, const Teuchos::RCP > &fwdOpSrc, const Teuchos::RCP &epetraLP, const Teuchos::RCP &amesosSolver, const EOpTransp amesosSolverTransp, const double amesosSolverScalar ); /** \brief First initialization. * * \param fwdOp * [in] The forward operator for which the factorization exists. * \param epetraLP * [in] The Epetra_LinearProblem object that was used to * create the Amesos_BaseSolver object * *amesosSolver. Note that the RHS and the LHS * multi-vector pointers in this object will be set and unset * here. * \param amesosSolver * [in] Contains the factored, and ready to go, * Amesos_BaseSolver object ready to solve linear system. * \param amesosSolverTransp * [in] Determines if the %Amesos solver should be used as its * transpose or not. * \param amesosSolverScalar * [in] Determines the scaling factor associated with the %Amesos * solver. The solution to the linear solve is scaled by * 1/amesosSolverScalar. * * Preconditions:
    *
  • fwdOp.get()!=NULL *
  • epetraLP.get()!=NULL *
  • amesosSolver.get()!=NULL *
  • *epetraLP->GetOperator() is compatible with *fwdOp *
  • epetraLP->GetLHS()==NULL *
  • epetraLP->GetRHS()==NULL *
  • *amesosSolver contains the factorization of *fwdOp and is * ready to solve linear systems! *
* * Postconditions:
    *
  • this->get_fwdOp().get() == fwdOp.get() *
  • this->get_epetraLP().get() == epetraLP.get() *
  • this->get_amesosSolver().get() == amesosSolver.get() *
  • this->get_amesosSolverTransp() == amesosSolverTransp *
  • this->get_amesosSolverScalar() == amesosSolverScalar *
*/ void initialize( const Teuchos::RCP > &fwdOp, const Teuchos::RCP > &fwdOpSrc, const Teuchos::RCP &epetraLP, const Teuchos::RCP &amesosSolver, const EOpTransp amesosSolverTransp, const double amesosSolverScalar ); /** \brief Extract the LinearOpSourceBase object so that it can be modified. * * Postconditions:
    *
  • return.get() is the same as this->get_fwdOpSrc().get() before call. *
  • this->get_fwdOpSrc().get()==NULL *
*/ Teuchos::RCP > extract_fwdOpSrc(); /** \brief . */ Teuchos::RCP > get_fwdOp() const; /** \brief . */ Teuchos::RCP > get_fwdOpSrc() const; /** \brief . */ Teuchos::RCP get_epetraLP() const; /** \brief . */ Teuchos::RCP get_amesosSolver() const; /** \brief . */ EOpTransp get_amesosSolverTransp() const; /** \brief . */ double get_amesosSolverScalar() const; /** \brief Uninitialize. */ void uninitialize( Teuchos::RCP > *fwdOp = NULL, Teuchos::RCP > *fwdOpSrc = NULL, Teuchos::RCP *epetraLP = NULL, Teuchos::RCP *amesosSolver = NULL, EOpTransp *amesosSolverTransp = NULL, double *amesosSolverScalar = NULL ); //@} /** @name Overridden public functions from LinearOpBase */ //@{ /** \brief. */ Teuchos::RCP< const VectorSpaceBase > range() const; /** \brief. */ Teuchos::RCP< const VectorSpaceBase > domain() const; /** \brief. */ Teuchos::RCP > clone() const; //@} /** @name Overridden public functions from Teuchos::Describable */ //@{ /** \brief . */ std::string description() const; /** \brief . */ void describe( Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel ) const; //@} protected: /** @name Overridden from LinearOpBase */ //@{ /** \brief . */ virtual bool opSupportedImpl(EOpTransp M_trans) const; /** \brief . */ virtual void applyImpl( const EOpTransp M_trans, const MultiVectorBase &X, const Ptr > &Y, const double alpha, const double beta ) const; //@} /** @name Overridden from LinearOpWithSolveBase. */ //@{ /** \brief . */ virtual bool solveSupportsImpl(EOpTransp M_trans) const; /** \brief . */ virtual bool solveSupportsSolveMeasureTypeImpl( EOpTransp M_trans, const SolveMeasureType& solveMeasureType ) const; /** \brief . */ SolveStatus solveImpl( const EOpTransp M_trans, const MultiVectorBase &B, const Ptr > &X, const Ptr > solveCriteria ) const; //@} private: Teuchos::RCP > fwdOp_; Teuchos::RCP > fwdOpSrc_; Teuchos::RCP epetraLP_; Teuchos::RCP amesosSolver_; EOpTransp amesosSolverTransp_; double amesosSolverScalar_; void assertInitialized() const; }; // /////////////////////////// // Inline members inline Teuchos::RCP > AmesosLinearOpWithSolve::get_fwdOp() const { return fwdOp_; } inline Teuchos::RCP > AmesosLinearOpWithSolve::get_fwdOpSrc() const { return fwdOpSrc_; } inline Teuchos::RCP AmesosLinearOpWithSolve::get_epetraLP() const { return epetraLP_; } inline Teuchos::RCP AmesosLinearOpWithSolve::get_amesosSolver() const { return amesosSolver_; } inline EOpTransp AmesosLinearOpWithSolve::get_amesosSolverTransp() const { return amesosSolverTransp_; } inline double AmesosLinearOpWithSolve::get_amesosSolverScalar() const { return amesosSolverScalar_; } } // namespace Thyra #endif // THYRA_AMESOS_LINEAR_OP_WITH_SOLVE_HPP