11/* !
2- * \file CQuasiNewtonDriver .hpp
2+ * \file CQuasiNewtonInvLeastSquares .hpp
33 * \brief Implements a method to accelerate and stabilize the convergence
44 * of fixed point iterations, the history of past iterates is used to compute
55 * a least squares approximation of the inverse of the Jacobian, which is then
4646 * as the new input of the FP, run the FP, etc.
4747 */
4848template <class Scalar_t >
49- class CQuasiNewtonDriver {
49+ class CQuasiNewtonInvLeastSquares {
5050public:
5151 using Scalar = Scalar_t;
5252 using Index = typename su2matrix<Scalar>::Index;
@@ -57,7 +57,7 @@ class CQuasiNewtonDriver {
5757
5858 enum : size_t {BLOCK_SIZE = 1024 }; /* !< \brief Loop tiling parameter. */
5959 std::vector<su2matrix<Scalar> > X, R; /* !< \brief Input and residual history of the FP. */
60- su2matrix<Scalar> corr ; /* !< \brief Correction to the natural FP result. */
60+ su2matrix<Scalar> work ; /* !< \brief Work matrix ( FP result, correction, and approx solution) . */
6161 su2vector<Scalar> mat, rhs, sol; /* !< \brief Matrix, rhs, and solution of the normal equations. */
6262 Index iSample = 0 ; /* !< \brief Current sample index. */
6363 Index nPtDomain = 0 ; /* !< \brief Local size of the history, considered in dot products. */
@@ -73,7 +73,7 @@ class CQuasiNewtonDriver {
7373
7474 void computeNormalEquations () {
7575 /* --- Size for the dot products. ---*/
76- const auto end = std::min<Index>(nPtDomain,corr .rows ())*corr .cols ();
76+ const auto end = std::min<Index>(nPtDomain,work .rows ())*work .cols ();
7777
7878 mat = Scalar (0 ); rhs = Scalar (0 );
7979
@@ -90,7 +90,7 @@ class CQuasiNewtonDriver {
9090 }
9191
9292 /* --- MPI reduction of the dot products. ---*/
93- if (nPtDomain < corr .rows ()) {
93+ if (nPtDomain < work .rows ()) {
9494 const auto type = (sizeof (Scalar) < sizeof (double ))? MPI_FLOAT : MPI_DOUBLE;
9595
9696 su2vector<Scalar> tmp (mat.size ());
@@ -125,6 +125,7 @@ class CQuasiNewtonDriver {
125125 for (Index k = 0 ; k < blkSize; ++k) {
126126 sum += (ri1[k]-ri0[k]) * (rj1[k]-rj0[k]);
127127 }
128+ /* --- 1D index of (i,j) in lower triangular storage. ---*/
128129 const auto iCoeff = i*(i+1 )/2 + j;
129130 mat (iCoeff) += sum;
130131 }
@@ -143,10 +144,10 @@ class CQuasiNewtonDriver {
143144
144145public:
145146 /* ! \brief Default construction without allocation. */
146- CQuasiNewtonDriver () = default ;
147+ CQuasiNewtonInvLeastSquares () = default ;
147148
148149 /* ! \brief Construction with allocation, see "resize". */
149- CQuasiNewtonDriver (Index nsample, Index npt, Index nvar, Index nptdomain = 0 ) {
150+ CQuasiNewtonInvLeastSquares (Index nsample, Index npt, Index nvar, Index nptdomain = 0 ) {
150151 resize (nsample, npt, nvar, nptdomain);
151152 }
152153
@@ -162,7 +163,7 @@ class CQuasiNewtonDriver {
162163 SU2_MPI::Error (" Invalid quasi-Newton parameters" , CURRENT_FUNCTION);
163164 iSample = 0 ;
164165 nPtDomain = nptdomain? nptdomain : npt;
165- corr .resize (npt,nvar);
166+ work .resize (npt,nvar);
166167 X.clear ();
167168 R.clear ();
168169 for (Index i = 0 ; i < nsample; ++i) {
@@ -186,10 +187,10 @@ class CQuasiNewtonDriver {
186187 * \brief Access the current fixed-point result.
187188 * \note Use these to STORE the result of running the FP.
188189 */
189- su2matrix<Scalar>& FPresult () { return corr ; }
190- const su2matrix<Scalar>& FPresult () const { return corr ; }
191- Scalar& FPresult (Index iPt, Index iVar) { return corr (iPt,iVar); }
192- const Scalar& FPresult (Index iPt, Index iVar) const { return corr (iPt,iVar); }
190+ su2matrix<Scalar>& FPresult () { return work ; }
191+ const su2matrix<Scalar>& FPresult () const { return work ; }
192+ Scalar& FPresult (Index iPt, Index iVar) { return work (iPt,iVar); }
193+ const Scalar& FPresult (Index iPt, Index iVar) const { return work (iPt,iVar); }
193194
194195 /* !
195196 * \brief Access the current solution approximation.
@@ -207,9 +208,9 @@ class CQuasiNewtonDriver {
207208 const su2matrix<Scalar>& compute () {
208209 /* --- Compute FP residual, clear correction. ---*/
209210 SU2_OMP_SIMD
210- for (Index i = 0 ; i < corr .size (); ++i) {
211- R[iSample].data ()[i] = corr .data ()[i] - X[iSample].data ()[i];
212- corr .data ()[i] = Scalar (0 );
211+ for (Index i = 0 ; i < work .size (); ++i) {
212+ R[iSample].data ()[i] = work .data ()[i] - X[iSample].data ()[i];
213+ work .data ()[i] = Scalar (0 );
213214 }
214215
215216 if (iSample > 0 ) {
@@ -229,9 +230,9 @@ class CQuasiNewtonDriver {
229230 const auto x0 = X[k].data ();
230231 const auto r0 = R[k].data ();
231232 SU2_OMP_SIMD
232- for (Index i = 0 ; i < corr .size (); ++i) {
233+ for (Index i = 0 ; i < work .size (); ++i) {
233234 Scalar dy = r1[i]-r0[i] + x1[i]-x0[i];
234- corr .data ()[i] += sol (k) * dy;
235+ work .data ()[i] += sol (k) * dy;
235236 }
236237 }
237238 }
@@ -244,9 +245,9 @@ class CQuasiNewtonDriver {
244245
245246 /* --- Set new solution. ---*/
246247 SU2_OMP_SIMD
247- for (Index i = 0 ; i < corr .size (); ++i)
248- corr .data ()[i] += R[iSample].data ()[i] + X[iSample].data ()[i];
249- std::swap (X[++iSample], corr );
248+ for (Index i = 0 ; i < work .size (); ++i)
249+ work .data ()[i] += R[iSample].data ()[i] + X[iSample].data ()[i];
250+ std::swap (X[++iSample], work );
250251
251252 return solution ();
252253 }
0 commit comments