2626 * License along with SU2. If not, see <http://www.gnu.org/licenses/>.
2727 */
2828
29-
3029#pragma once
3130
3231#include " ../CConfig.hpp"
@@ -59,6 +58,17 @@ class CPreconditioner {
5958 * \brief Generic "preprocessing" hook derived classes may implement to build the preconditioner.
6059 */
6160 virtual void Build () {}
61+
62+ /* !
63+ * \brief Return true to identify the identity preconditioner, may allow some solvers to be more efficient.
64+ */
65+ virtual bool IsIdentity () const { return false ; }
66+
67+ /* !
68+ * \brief Factory method.
69+ */
70+ static CPreconditioner* Create (ENUM_LINEAR_SOLVER_PREC kind, CSysMatrix<ScalarType>& jacobian,
71+ CGeometry* geometry, const CConfig* config);
6272};
6373template <class ScalarType >
6474CPreconditioner<ScalarType>::~CPreconditioner () {}
@@ -74,25 +84,22 @@ class CJacobiPreconditioner final : public CPreconditioner<ScalarType> {
7484 CSysMatrix<ScalarType>& sparse_matrix; /* !< \brief Pointer to matrix that defines the preconditioner. */
7585 CGeometry* geometry; /* !< \brief Pointer to geometry associated with the matrix. */
7686 const CConfig *config; /* !< \brief Pointer to problem configuration. */
77- bool transp; /* !< \brief If the transpose version of the preconditioner is required. */
7887
7988public:
8089 /* !
8190 * \brief Constructor of the class.
8291 * \param[in] matrix_ref - Matrix reference that will be used to define the preconditioner.
8392 * \param[in] geometry_ref - Geometry associated with the problem.
8493 * \param[in] config_ref - Config of the problem.
85- * \param[in] transposed - If the transpose version of the preconditioner is required.
8694 */
8795 inline CJacobiPreconditioner (CSysMatrix<ScalarType> & matrix_ref,
88- CGeometry *geometry_ref, const CConfig *config_ref, bool transposed ) :
96+ CGeometry *geometry_ref, const CConfig *config_ref) :
8997 sparse_matrix(matrix_ref)
9098 {
9199 if ((geometry_ref == nullptr ) || (config_ref == nullptr ))
92100 SU2_MPI::Error (" Preconditioner needs to be built with valid references." , CURRENT_FUNCTION);
93101 geometry = geometry_ref;
94102 config = config_ref;
95- transp = transposed;
96103 }
97104
98105 /* !
@@ -113,7 +120,7 @@ class CJacobiPreconditioner final : public CPreconditioner<ScalarType> {
113120 * \note Request the associated matrix to build the preconditioner.
114121 */
115122 inline void Build () override {
116- sparse_matrix.BuildJacobiPreconditioner (transp );
123+ sparse_matrix.BuildJacobiPreconditioner ();
117124 }
118125};
119126
@@ -128,25 +135,22 @@ class CILUPreconditioner final : public CPreconditioner<ScalarType> {
128135 CSysMatrix<ScalarType>& sparse_matrix; /* !< \brief Pointer to matrix that defines the preconditioner. */
129136 CGeometry* geometry; /* !< \brief Pointer to geometry associated with the matrix. */
130137 const CConfig *config; /* !< \brief Pointer to problem configuration. */
131- bool transp; /* !< \brief If the transpose version of the preconditioner is required. */
132138
133139public:
134140 /* !
135141 * \brief Constructor of the class.
136142 * \param[in] matrix_ref - Matrix reference that will be used to define the preconditioner.
137143 * \param[in] geometry_ref - Geometry associated with the problem.
138144 * \param[in] config_ref - Config of the problem.
139- * \param[in] transposed - If the transpose version of the preconditioner is required.
140145 */
141146 inline CILUPreconditioner (CSysMatrix<ScalarType> & matrix_ref,
142- CGeometry *geometry_ref, const CConfig *config_ref, bool transposed ) :
147+ CGeometry *geometry_ref, const CConfig *config_ref) :
143148 sparse_matrix(matrix_ref)
144149 {
145150 if ((geometry_ref == nullptr ) || (config_ref == nullptr ))
146151 SU2_MPI::Error (" Preconditioner needs to be built with valid references." , CURRENT_FUNCTION);
147152 geometry = geometry_ref;
148153 config = config_ref;
149- transp = transposed;
150154 }
151155
152156 /* !
@@ -167,7 +171,7 @@ class CILUPreconditioner final : public CPreconditioner<ScalarType> {
167171 * \note Request the associated matrix to build the preconditioner.
168172 */
169173 inline void Build () override {
170- sparse_matrix.BuildILUPreconditioner (transp );
174+ sparse_matrix.BuildILUPreconditioner ();
171175 }
172176};
173177
@@ -263,7 +267,7 @@ class CLineletPreconditioner final : public CPreconditioner<ScalarType> {
263267 * \note Request the associated matrix to build the preconditioner.
264268 */
265269 inline void Build () override {
266- sparse_matrix.BuildJacobiPreconditioner (false );
270+ sparse_matrix.BuildJacobiPreconditioner ();
267271 }
268272};
269273
@@ -279,7 +283,6 @@ class CPastixPreconditioner final : public CPreconditioner<ScalarType> {
279283 CGeometry* geometry; /* !< \brief Geometry associated with the problem. */
280284 const CConfig *config; /* !< \brief Configuration of the problem. */
281285 unsigned short kind_fact; /* !< \brief The type of factorization desired. */
282- bool transp; /* !< \brief If the transpose version of the preconditioner is required. */
283286
284287public:
285288 /* !
@@ -288,18 +291,16 @@ class CPastixPreconditioner final : public CPreconditioner<ScalarType> {
288291 * \param[in] geometry_ref - Associated geometry.
289292 * \param[in] config_ref - Problem configuration.
290293 * \param[in] kind_factorization - Type of factorization required.
291- * \param[in] transposed - If the transpose version of the preconditioner is required.
292294 */
293295 inline CPastixPreconditioner (CSysMatrix<ScalarType> & matrix_ref, CGeometry *geometry_ref,
294- const CConfig *config_ref, unsigned short kind_factorization, bool transposed ) :
296+ const CConfig *config_ref, unsigned short kind_factorization) :
295297 sparse_matrix(matrix_ref)
296298 {
297299 if ((geometry_ref == nullptr ) || (config_ref == nullptr ))
298300 SU2_MPI::Error (" Preconditioner needs to be built with valid references." , CURRENT_FUNCTION);
299301 geometry = geometry_ref;
300302 config = config_ref;
301303 kind_fact = kind_factorization;
302- transp = transposed;
303304 }
304305
305306 /* !
@@ -320,6 +321,35 @@ class CPastixPreconditioner final : public CPreconditioner<ScalarType> {
320321 * \note Request the associated matrix to build the preconditioner.
321322 */
322323 inline void Build () override {
323- sparse_matrix.BuildPastixPreconditioner (geometry, config, kind_fact, transp );
324+ sparse_matrix.BuildPastixPreconditioner (geometry, config, kind_fact);
324325 }
325326};
327+
328+
329+ template <class ScalarType >
330+ CPreconditioner<ScalarType>* CPreconditioner<ScalarType>::Create(ENUM_LINEAR_SOLVER_PREC kind,
331+ CSysMatrix<ScalarType>& jacobian,
332+ CGeometry* geometry,
333+ const CConfig* config) {
334+ CPreconditioner<ScalarType>* prec = nullptr ;
335+
336+ switch (kind) {
337+ case JACOBI:
338+ prec = new CJacobiPreconditioner<ScalarType>(jacobian, geometry, config);
339+ break ;
340+ case LINELET:
341+ prec = new CLineletPreconditioner<ScalarType>(jacobian, geometry, config);
342+ break ;
343+ case LU_SGS:
344+ prec = new CLU_SGSPreconditioner<ScalarType>(jacobian, geometry, config);
345+ break ;
346+ case ILU:
347+ prec = new CILUPreconditioner<ScalarType>(jacobian, geometry, config);
348+ break ;
349+ case PASTIX_ILU: case PASTIX_LU_P: case PASTIX_LDLT_P:
350+ prec = new CPastixPreconditioner<ScalarType>(jacobian, geometry, config, kind);
351+ break ;
352+ }
353+
354+ return prec;
355+ }
0 commit comments