|
33 | 33 | #include "../../../Common/include/linear_algebra/CMatrixVectorProduct.hpp" |
34 | 34 | #include "../../../Common/include/linear_algebra/CSysSolve.hpp" |
35 | 35 |
|
| 36 | +#ifdef CODI_FORWARD_TYPE |
| 37 | + using Scalar = su2double; |
| 38 | +#else |
| 39 | + using Scalar = su2mixedfloat; |
| 40 | +#endif |
| 41 | + |
| 42 | +class LinOperator; |
| 43 | +class LinPreconditioner; |
| 44 | + |
36 | 45 | /*! |
37 | 46 | * \class CDiscAdjSinglezoneDriver |
38 | 47 | * \ingroup DiscAdj |
|
42 | 51 | */ |
43 | 52 | class CDiscAdjSinglezoneDriver : public CSinglezoneDriver { |
44 | 53 | protected: |
45 | | -#ifdef CODI_FORWARD_TYPE |
46 | | - using Scalar = su2double; |
47 | | -#else |
48 | | - using Scalar = su2mixedfloat; |
49 | | -#endif |
50 | 54 |
|
51 | 55 | unsigned long nAdjoint_Iter; /*!< \brief The number of adjoint iterations that are run on the fixed-point solver.*/ |
52 | 56 | RECORDING RecordingState; /*!< \brief The kind of recording the tape currently holds.*/ |
@@ -79,27 +83,8 @@ class CDiscAdjSinglezoneDriver : public CSinglezoneDriver { |
79 | 83 | CSysVector<Scalar> AdjSol; |
80 | 84 | CPreconditioner<Scalar>* PrimalPreconditioner = nullptr; |
81 | 85 | CSysMatrixVectorProduct<Scalar>* PrimalJacobian = nullptr; |
82 | | - |
83 | | - class LinOperator : public CMatrixVectorProduct<Scalar> { |
84 | | - public: |
85 | | - CDiscAdjSinglezoneDriver* const driver; |
86 | | - LinOperator(CDiscAdjSinglezoneDriver* d) : driver(d) { } |
87 | | - |
88 | | - inline void operator()(const CSysVector<Scalar> & u, CSysVector<Scalar> & v) const override { |
89 | | - driver->ApplyOperator(u, v); |
90 | | - } |
91 | | - }; |
92 | | - |
93 | | - class LinPreconditioner : public CPreconditioner<Scalar> { |
94 | | - public: |
95 | | - CDiscAdjSinglezoneDriver* const driver; |
96 | | - |
97 | | - LinPreconditioner(CDiscAdjSinglezoneDriver* d): driver(d) { } |
98 | | - |
99 | | - inline void operator()(const CSysVector<Scalar> & u, CSysVector<Scalar> & v) const override { |
100 | | - driver->ApplyPreconditioner(u, v); |
101 | | - } |
102 | | - }; |
| 86 | + LinOperator* AdjOperator = nullptr; |
| 87 | + LinPreconditioner* AdjPreconditioner = nullptr; |
103 | 88 |
|
104 | 89 | /*! |
105 | 90 | * \brief Record one iteration of a flow iteration in within multiple zones. |
@@ -149,16 +134,6 @@ class CDiscAdjSinglezoneDriver : public CSinglezoneDriver { |
149 | 134 | */ |
150 | 135 | void UpdateAdjointsResidual(); |
151 | 136 |
|
152 | | - /*! |
153 | | - * \brief Adjoint problem Jacobian-vector product. |
154 | | - */ |
155 | | - void ApplyOperator(const CSysVector<Scalar>& u, CSysVector<Scalar>& v); |
156 | | - |
157 | | - /*! |
158 | | - * \brief Adjoint problem preconditioner (based on the transpose approximate Jacobian of the primal problem). |
159 | | - */ |
160 | | - void ApplyPreconditioner(const CSysVector<Scalar>& u, CSysVector<Scalar>& v); |
161 | | - |
162 | 137 | /*! |
163 | 138 | * \brief Initialize the adjoint value of the objective function. |
164 | 139 | */ |
@@ -318,4 +293,34 @@ class CDiscAdjSinglezoneDriver : public CSinglezoneDriver { |
318 | 293 | offset += solver->GetnVar(); |
319 | 294 | } |
320 | 295 | } |
| 296 | + |
| 297 | + /*! |
| 298 | + * \brief Adjoint problem Jacobian-vector product. |
| 299 | + */ |
| 300 | + void ApplyOperator(const CSysVector<Scalar>& u, CSysVector<Scalar>& v); |
| 301 | + |
| 302 | + /*! |
| 303 | + * \brief Adjoint problem preconditioner (based on the transpose approximate Jacobian of the primal problem). |
| 304 | + */ |
| 305 | + void ApplyPreconditioner(const CSysVector<Scalar>& u, CSysVector<Scalar>& v); |
| 306 | +}; |
| 307 | + |
| 308 | +class LinOperator : public CMatrixVectorProduct<Scalar> { |
| 309 | + public: |
| 310 | + CDiscAdjSinglezoneDriver* const driver; |
| 311 | + LinOperator(CDiscAdjSinglezoneDriver* d) : driver(d) { } |
| 312 | + |
| 313 | + inline void operator()(const CSysVector<Scalar> & u, CSysVector<Scalar> & v) const override { |
| 314 | + driver->ApplyOperator(u, v); |
| 315 | + } |
| 316 | +}; |
| 317 | + |
| 318 | +class LinPreconditioner : public CPreconditioner<Scalar> { |
| 319 | + public: |
| 320 | + CDiscAdjSinglezoneDriver* const driver; |
| 321 | + LinPreconditioner(CDiscAdjSinglezoneDriver* d) : driver(d) { } |
| 322 | + |
| 323 | + inline void operator()(const CSysVector<Scalar> & u, CSysVector<Scalar> & v) const override { |
| 324 | + driver->ApplyPreconditioner(u, v); |
| 325 | + } |
321 | 326 | }; |
0 commit comments