Debian Codegraph @

packages/stratimikos/adapters/amesos/src/Thyra_AmesosLinearOpWithSolveFactory.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_FACTORY_HPP
11 #define THYRA_AMESOS_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
12
13 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
14 #include "Thyra_AmesosTypes.hpp"
15 #include "Amesos_BaseSolver.h"
16 #include "Thyra_EpetraOperatorViewExtractorBase.hpp"
17 #include "Teuchos_StandardMemberCompositionMacros.hpp"
18 #include "Teuchos_StandardCompositionMacros.hpp"
19
20 namespace Thyra {
21
22 /** \brief Concrete <tt>LinearOpWithSolveFactoryBase</tt> adapter subclass that uses
23 * Amesos direct solvers.
24 *
25 * This class creates objects of type <tt>AmesosLinearOpWithSolve</tt>
26 * (through the <tt>LinearOpWithSolveBase</tt> interface) which can then be
27 * used to solve for linear systems. The <tt>%AmesosLinearOpWithSolve</tt>
28 * objects created and initialized by this object are completely independent
29 * from <tt>*this</tt>. This allows for multiple
30 * <tt>%AmesosLinearOpWithSolve</tt> objects to be created and maintained
31 * simultaneously and for <tt>*this</tt> factory object to be destroyed
32 * without affecting the created <tt>%AmesosLinearOpWithSolve</tt> objects.
33 *
34 * ToDo: Mention parameter list usage.
35 *
36 * <b>Development notes:</b> This class has been designed to allow for "smart"
37 * <tt>EpetraLinearOpBase</tt> subclasses that can create an
38 * <tt>Epetra_Operator</tt> view on command where the underlying storage may
39 * not be an <tt>Epetra</tt> object. However, the current implementation of
40 * at least some of the <tt>Amesos_BaseSolver</tt> subclasses do not allow the
41 * <tt>%Epetra_Operator</tt> object to change after construction. Therefore,
42 * this current flawed implementation requires that every call to the
43 * <tt>EpetraLinearOpBase::getEpetraOpView()</tt> function return the same
44 * <tt>%Epetra_Operator</tt> object.
45 *
46 * \ingroup Amesos_Thyra_adapters_grp
47 */
48 class AmesosLinearOpWithSolveFactory : public LinearOpWithSolveFactoryBase<double> {
49 public:
50
51 /** \name Parameter names for Paramter List */
52 //@{
53
54 /** \brief . */
55 static const std::string SolverType_name;
56 /** \brief . */
57 static const std::string RefactorizationPolicy_name;
58 /** \brief . */
59 static const std::string ThrowOnPreconditionerInput_name;
60 /** \brief . */
61 static const std::string Amesos_Settings_name;
62
63 //@}
64
65 /** \name Constructors/initializers/accessors */
66 //@{
67
68 /** \brief . */
69 ~AmesosLinearOpWithSolveFactory();
70
71 /** \brief Constructor which sets the defaults.
72 */
73 AmesosLinearOpWithSolveFactory(
74 const Amesos::ESolverType solverType
75 #ifdef HAVE_AMESOS_KLU
76 = Amesos::KLU
77 #else
78 = Amesos::LAPACK
79 #endif
80 ,const Amesos::ERefactorizationPolicy refactorizationPolicy = Amesos::REPIVOT_ON_REFACTORIZATION
81 ,const bool throwOnPrecInput = true
82 );
83
84 /** \brief Set the strategy object used to extract an
85 * <tt>Epetra_Operator</tt> view of an input forward operator.
86 *
87 * This view will then be dynamically casted to <tt>Epetra_RowMatrix</tt>
88 * before it is used.
89 *
90 * The default implementation used is <tt>EpetraOperatorViewExtractorBase</tt>.
91 */
92 STANDARD_COMPOSITION_MEMBERS( EpetraOperatorViewExtractorBase, epetraFwdOpViewExtractor );
93
94 //@}
95
96 /** @name Overridden public functions from LinearOpWithSolveFactoryBase */
97 //@{
98
99 /** \brief Returns true if <tt>dynamic_cast<const
100 * EpetraLinearOpBase*>(fwdOpSrc)!=NULL</tt> .
101 */
102 bool isCompatible( const LinearOpSourceBase<double> &fwdOpSrc ) const;
103
104 /** \brief . */
105 Teuchos::RCP<LinearOpWithSolveBase<double> > createOp() const;
106
107 /** \brief . */
108 void initializeOp(
109 const Teuchos::RCP<const LinearOpSourceBase<double> > &fwdOpSrc
110 ,LinearOpWithSolveBase<double> *Op
111 ,const ESupportSolveUse supportSolveUse
112 ) const;
113
114 /** \brief Returns <tt>false</tt> . */
115 bool supportsPreconditionerInputType(const EPreconditionerInputType precOpType) const;
116
117 /** \brief Throws exception if <tt>this->throwOnPrecInput()==true</tt> and
118 * calls <tt>this->initializeOp(fwdOpSrc,Op)</tt> otherwise
119 */
120 void initializePreconditionedOp(
121 const Teuchos::RCP<const LinearOpSourceBase<double> > &fwdOpSrc
122 ,const Teuchos::RCP<const PreconditionerBase<double> > &prec
123 ,LinearOpWithSolveBase<double> *Op
124 ,const ESupportSolveUse supportSolveUse
125 ) const;
126
127 /** \brief Throws exception if <tt>this->throwOnPrecInput()==true</tt> and
128 * calls <tt>this->initializeOp(fwdOpSrc,Op)</tt> otherwise
129 */
130 void initializePreconditionedOp(
131 const Teuchos::RCP<const LinearOpSourceBase<double> > &fwdOpSrc
132 ,const Teuchos::RCP<const LinearOpSourceBase<double> > &approxFwdOpSrc
133 ,LinearOpWithSolveBase<double> *Op
134 ,const ESupportSolveUse supportSolveUse
135 ) const;
136
137 /** \brief . */
138 void uninitializeOp(
139 LinearOpWithSolveBase<double> *Op
140 ,Teuchos::RCP<const LinearOpSourceBase<double> > *fwdOpSrc
141 ,Teuchos::RCP<const PreconditionerBase<double> > *prec
142 ,Teuchos::RCP<const LinearOpSourceBase<double> > *approxFwdOpSrc
143 ,ESupportSolveUse *supportSolveUse
144 ) const;
145
146 //@}
147
148 /** @name Overridden from ParameterListAcceptor */
149 //@{
150
151 /** \brief . */
152 void setParameterList(Teuchos::RCP<Teuchos::ParameterList> const& paramList);
153 /** \brief . */
154 Teuchos::RCP<Teuchos::ParameterList> getNonconstParameterList();
155 /** \brief . */
156 Teuchos::RCP<Teuchos::ParameterList> unsetParameterList();
157 /** \brief . */
158 Teuchos::RCP<const Teuchos::ParameterList> getParameterList() const;
159 /** \brief . */
160 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
161
162 //@}
163
164 /** \name Public functions overridden from Teuchos::Describable. */
165 //@{
166
167 /** \brief . */
168 std::string description() const;
169
170 //@}
171
172 private:
173
174 // /////////////////////////
175 // Private data members
176
177 Amesos::ESolverType solverType_;
178 Amesos::ERefactorizationPolicy refactorizationPolicy_;
179 bool throwOnPrecInput_;
180 Teuchos::RCP<Teuchos::ParameterList> paramList_;
181
182 // /////////////////////////
183 // Private member functions
184
185 static Teuchos::RCP<const Teuchos::ParameterList>
186 generateAndGetValidParameters();
187
188 };
189
190 } // namespace Thyra
191
192 #endif // THYRA_AMESOS_LINEAR_OP_WITH_SOLVE_FACTORY_HPP