Skip to content

Commit 88fc0f7

Browse files
committed
address review comments
1 parent 2c762d1 commit 88fc0f7

3 files changed

Lines changed: 44 additions & 43 deletions

File tree

Common/include/toolboxes/CQuasiNewtonDriver.hpp renamed to Common/include/toolboxes/CQuasiNewtonInvLeastSquares.hpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -46,7 +46,7 @@
4646
* as the new input of the FP, run the FP, etc.
4747
*/
4848
template<class Scalar_t>
49-
class CQuasiNewtonDriver {
49+
class CQuasiNewtonInvLeastSquares {
5050
public:
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

144145
public:
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
}

SU2_CFD/src/drivers/CDiscAdjMultizoneDriver.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "../../include/output/COutputLegacy.hpp"
3232
#include "../../include/output/COutput.hpp"
3333
#include "../../include/iteration/CIterationFactory.hpp"
34-
#include "../../../Common/include/toolboxes/CQuasiNewtonDriver.hpp"
34+
#include "../../../Common/include/toolboxes/CQuasiNewtonInvLeastSquares.hpp"
3535

3636
CDiscAdjMultizoneDriver::CDiscAdjMultizoneDriver(char* confFile,
3737
unsigned short val_nZone,
@@ -164,7 +164,7 @@ void CDiscAdjMultizoneDriver::Run() {
164164

165165
unsigned long wrt_sol_freq = 9999;
166166
unsigned long nOuterIter = driver_config->GetnOuter_Iter();
167-
vector<CQuasiNewtonDriver<passivedouble> > QNDriver(nZone);
167+
vector<CQuasiNewtonInvLeastSquares<passivedouble> > fixPtCorrector(nZone);
168168

169169
for (iZone = 0; iZone < nZone; iZone++) {
170170

@@ -182,10 +182,10 @@ void CDiscAdjMultizoneDriver::Run() {
182182
/*--- Prepare quasi-Newton drivers. ---*/
183183

184184
if (config_container[iZone]->GetnQuasiNewtonSamples() > 1) {
185-
QNDriver[iZone].resize(config_container[iZone]->GetnQuasiNewtonSamples(),
186-
geometry_container[iZone][INST_0][MESH_0]->GetnPoint(),
187-
GetTotalNumberOfVariables(iZone, true),
188-
geometry_container[iZone][INST_0][MESH_0]->GetnPointDomain());
185+
fixPtCorrector[iZone].resize(config_container[iZone]->GetnQuasiNewtonSamples(),
186+
geometry_container[iZone][INST_0][MESH_0]->GetnPoint(),
187+
GetTotalNumberOfVariables(iZone, true),
188+
geometry_container[iZone][INST_0][MESH_0]->GetnPointDomain());
189189
}
190190
}
191191

@@ -264,9 +264,9 @@ void CDiscAdjMultizoneDriver::Run() {
264264

265265
/*--- Reset QN driver for new inner iterations. ---*/
266266

267-
if (QNDriver[iZone].size()) {
268-
QNDriver[iZone].reset();
269-
if(restart && (iOuterIter==1)) GetAllSolutions(iZone, true, QNDriver[iZone]);
267+
if (fixPtCorrector[iZone].size()) {
268+
fixPtCorrector[iZone].reset();
269+
if(restart && (iOuterIter==1)) GetAllSolutions(iZone, true, fixPtCorrector[iZone]);
270270
}
271271

272272
for (unsigned long iInnerIter = 0; iInnerIter < nInnerIter[iZone]; iInnerIter++) {
@@ -299,10 +299,10 @@ void CDiscAdjMultizoneDriver::Run() {
299299

300300
/*--- Use QN driver to improve the solution. ---*/
301301

302-
if (QNDriver[iZone].size()) {
303-
GetAllSolutions(iZone, true, QNDriver[iZone].FPresult());
304-
QNDriver[iZone].compute();
305-
if(iInnerIter) SetAllSolutions(iZone, true, QNDriver[iZone]);
302+
if (fixPtCorrector[iZone].size()) {
303+
GetAllSolutions(iZone, true, fixPtCorrector[iZone].FPresult());
304+
fixPtCorrector[iZone].compute();
305+
if(iInnerIter) SetAllSolutions(iZone, true, fixPtCorrector[iZone]);
306306
}
307307

308308
/*--- This is done explicitly here for multizone cases, only in inner iterations and not when

SU2_CFD/src/drivers/CDiscAdjSinglezoneDriver.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "../../include/output/COutput.hpp"
3333
#include "../../include/iteration/CIterationFactory.hpp"
3434
#include "../../include/iteration/CTurboIteration.hpp"
35-
#include "../../../Common/include/toolboxes/CQuasiNewtonDriver.hpp"
35+
#include "../../../Common/include/toolboxes/CQuasiNewtonInvLeastSquares.hpp"
3636

3737
CDiscAdjSinglezoneDriver::CDiscAdjSinglezoneDriver(char* confFile,
3838
unsigned short val_nZone,
@@ -152,14 +152,14 @@ void CDiscAdjSinglezoneDriver::Run() {
152152

153153
const bool steady = !config->GetTime_Domain();
154154

155-
CQuasiNewtonDriver<passivedouble> QNDriver;
155+
CQuasiNewtonInvLeastSquares<passivedouble> fixPtCorrector;
156156
if (config->GetnQuasiNewtonSamples() > 1) {
157-
QNDriver.resize(config->GetnQuasiNewtonSamples(),
158-
geometry_container[ZONE_0][INST_0][MESH_0]->GetnPoint(),
159-
GetTotalNumberOfVariables(ZONE_0,true),
160-
geometry_container[ZONE_0][INST_0][MESH_0]->GetnPointDomain());
157+
fixPtCorrector.resize(config->GetnQuasiNewtonSamples(),
158+
geometry_container[ZONE_0][INST_0][MESH_0]->GetnPoint(),
159+
GetTotalNumberOfVariables(ZONE_0,true),
160+
geometry_container[ZONE_0][INST_0][MESH_0]->GetnPointDomain());
161161

162-
if (TimeIter != 0) GetAllSolutions(ZONE_0, true, QNDriver);
162+
if (TimeIter != 0) GetAllSolutions(ZONE_0, true, fixPtCorrector);
163163
}
164164

165165
for (auto Adjoint_Iter = 0ul; Adjoint_Iter < nAdjoint_Iter; Adjoint_Iter++) {
@@ -207,9 +207,9 @@ void CDiscAdjSinglezoneDriver::Run() {
207207

208208
/*--- Correct the solution with the quasi-Newton approach. ---*/
209209

210-
if (QNDriver.size()) {
211-
GetAllSolutions(ZONE_0, true, QNDriver.FPresult());
212-
SetAllSolutions(ZONE_0, true, QNDriver.compute());
210+
if (fixPtCorrector.size()) {
211+
GetAllSolutions(ZONE_0, true, fixPtCorrector.FPresult());
212+
SetAllSolutions(ZONE_0, true, fixPtCorrector.compute());
213213
}
214214

215215
}

0 commit comments

Comments
 (0)