// @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_FACTORY_HPP
#define THYRA_AMESOS_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
#include "Thyra_LinearOpWithSolveFactoryBase.hpp"
#include "Thyra_AmesosTypes.hpp"
#include "Amesos_BaseSolver.h"
#include "Thyra_EpetraOperatorViewExtractorBase.hpp"
#include "Teuchos_StandardMemberCompositionMacros.hpp"
#include "Teuchos_StandardCompositionMacros.hpp"
namespace Thyra {
/** \brief Concrete LinearOpWithSolveFactoryBase adapter subclass that uses
* Amesos direct solvers.
*
* This class creates objects of type AmesosLinearOpWithSolve
* (through the LinearOpWithSolveBase interface) which can then be
* used to solve for linear systems. The %AmesosLinearOpWithSolve
* objects created and initialized by this object are completely independent
* from *this. This allows for multiple
* %AmesosLinearOpWithSolve objects to be created and maintained
* simultaneously and for *this factory object to be destroyed
* without affecting the created %AmesosLinearOpWithSolve objects.
*
* ToDo: Mention parameter list usage.
*
* Development notes: This class has been designed to allow for "smart"
* EpetraLinearOpBase subclasses that can create an
* Epetra_Operator view on command where the underlying storage may
* not be an Epetra object. However, the current implementation of
* at least some of the Amesos_BaseSolver subclasses do not allow the
* %Epetra_Operator object to change after construction. Therefore,
* this current flawed implementation requires that every call to the
* EpetraLinearOpBase::getEpetraOpView() function return the same
* %Epetra_Operator object.
*
* \ingroup Amesos_Thyra_adapters_grp
*/
class AmesosLinearOpWithSolveFactory : public LinearOpWithSolveFactoryBase {
public:
/** \name Parameter names for Paramter List */
//@{
/** \brief . */
static const std::string SolverType_name;
/** \brief . */
static const std::string RefactorizationPolicy_name;
/** \brief . */
static const std::string ThrowOnPreconditionerInput_name;
/** \brief . */
static const std::string Amesos_Settings_name;
//@}
/** \name Constructors/initializers/accessors */
//@{
/** \brief . */
~AmesosLinearOpWithSolveFactory();
/** \brief Constructor which sets the defaults.
*/
AmesosLinearOpWithSolveFactory(
const Amesos::ESolverType solverType
#ifdef HAVE_AMESOS_KLU
= Amesos::KLU
#else
= Amesos::LAPACK
#endif
,const Amesos::ERefactorizationPolicy refactorizationPolicy = Amesos::REPIVOT_ON_REFACTORIZATION
,const bool throwOnPrecInput = true
);
/** \brief Set the strategy object used to extract an
* Epetra_Operator view of an input forward operator.
*
* This view will then be dynamically casted to Epetra_RowMatrix
* before it is used.
*
* The default implementation used is EpetraOperatorViewExtractorBase.
*/
STANDARD_COMPOSITION_MEMBERS( EpetraOperatorViewExtractorBase, epetraFwdOpViewExtractor );
//@}
/** @name Overridden public functions from LinearOpWithSolveFactoryBase */
//@{
/** \brief Returns true if dynamic_cast(fwdOpSrc)!=NULL .
*/
bool isCompatible( const LinearOpSourceBase &fwdOpSrc ) const;
/** \brief . */
Teuchos::RCP > createOp() const;
/** \brief . */
void initializeOp(
const Teuchos::RCP > &fwdOpSrc
,LinearOpWithSolveBase *Op
,const ESupportSolveUse supportSolveUse
) const;
/** \brief Returns false . */
bool supportsPreconditionerInputType(const EPreconditionerInputType precOpType) const;
/** \brief Throws exception if this->throwOnPrecInput()==true and
* calls this->initializeOp(fwdOpSrc,Op) otherwise
*/
void initializePreconditionedOp(
const Teuchos::RCP > &fwdOpSrc
,const Teuchos::RCP > &prec
,LinearOpWithSolveBase *Op
,const ESupportSolveUse supportSolveUse
) const;
/** \brief Throws exception if this->throwOnPrecInput()==true and
* calls this->initializeOp(fwdOpSrc,Op) otherwise
*/
void initializePreconditionedOp(
const Teuchos::RCP > &fwdOpSrc
,const Teuchos::RCP > &approxFwdOpSrc
,LinearOpWithSolveBase *Op
,const ESupportSolveUse supportSolveUse
) const;
/** \brief . */
void uninitializeOp(
LinearOpWithSolveBase *Op
,Teuchos::RCP > *fwdOpSrc
,Teuchos::RCP > *prec
,Teuchos::RCP > *approxFwdOpSrc
,ESupportSolveUse *supportSolveUse
) const;
//@}
/** @name Overridden from ParameterListAcceptor */
//@{
/** \brief . */
void setParameterList(Teuchos::RCP const& paramList);
/** \brief . */
Teuchos::RCP getNonconstParameterList();
/** \brief . */
Teuchos::RCP unsetParameterList();
/** \brief . */
Teuchos::RCP getParameterList() const;
/** \brief . */
Teuchos::RCP getValidParameters() const;
//@}
/** \name Public functions overridden from Teuchos::Describable. */
//@{
/** \brief . */
std::string description() const;
//@}
private:
// /////////////////////////
// Private data members
Amesos::ESolverType solverType_;
Amesos::ERefactorizationPolicy refactorizationPolicy_;
bool throwOnPrecInput_;
Teuchos::RCP paramList_;
// /////////////////////////
// Private member functions
static Teuchos::RCP
generateAndGetValidParameters();
};
} // namespace Thyra
#endif // THYRA_AMESOS_LINEAR_OP_WITH_SOLVE_FACTORY_HPP