Skip to content

Commit 51a9cb9

Browse files
committed
cleanup
1 parent 1549d45 commit 51a9cb9

8 files changed

Lines changed: 23 additions & 52 deletions

File tree

Common/include/geometry/elements/CElementProperty.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class CProperty {
9393
/*!
9494
* \brief Extract the derivative of the Design density.
9595
*/
96-
inline virtual su2double GetAdjointDensity(void) const { return 0.0; }
96+
inline virtual su2double GetAdjointDensity(void) { return 0.0; }
9797

9898
/*!
9999
* \brief Register the Design density as an AD input variable.
@@ -177,7 +177,11 @@ class CElementProperty final : public CProperty {
177177
/*!
178178
* \brief Extract the derivative of the Design density.
179179
*/
180-
inline su2double GetAdjointDensity(void) const override { return SU2_TYPE::GetDerivative(design_rho); }
180+
inline su2double GetAdjointDensity(void) override {
181+
su2double der = SU2_TYPE::GetDerivative(design_rho);
182+
AD::ResetInput(design_rho);
183+
return der;
184+
}
181185

182186
/*!
183187
* \brief Register the Design density as an AD input variable.

SU2_CFD/include/variables/CFEABoundVariable.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,7 @@ class CFEABoundVariable final : public CFEAVariable {
157157
/*!
158158
* \brief Register the flow tractions as input variable.
159159
*/
160-
void RegisterFlowTraction() override;
161-
162-
/*!
163-
* \brief Resets the AD indices of the flow tractions.
164-
*/
165-
void ResetInputFlowTraction() override;
160+
void RegisterFlowTraction(bool reset) override;
166161

167162
/*!
168163
* \brief Extract the flow traction derivatives.

SU2_CFD/include/variables/CVariable.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,12 +2160,7 @@ class CVariable {
21602160
/*!
21612161
* \brief A virtual member.
21622162
*/
2163-
inline virtual void RegisterFlowTraction() { }
2164-
2165-
/*!
2166-
* \brief A virtual member.
2167-
*/
2168-
inline virtual void ResetInputFlowTraction() { }
2163+
inline virtual void RegisterFlowTraction(bool reset) { }
21692164

21702165
/*!
21712166
* \brief A virtual member.

SU2_CFD/src/solvers/CDiscAdjFEASolver.cpp

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -124,32 +124,21 @@ CDiscAdjFEASolver::~CDiscAdjFEASolver() { delete nodes; }
124124

125125
void CDiscAdjFEASolver::SetRecording(CGeometry* geometry, CConfig *config){
126126

127-
unsigned long iPoint;
128-
unsigned short iDim, iVar;
129-
130127
/*--- Reset the solution to the initial (converged) solution ---*/
131128

132-
for (iPoint = 0; iPoint < nPoint; iPoint++) {
133-
for (iVar = 0; iVar < nVar; iVar++)
129+
for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) {
130+
for (auto iVar = 0u; iVar < nVar; iVar++)
134131
direct_solver->GetNodes()->SetSolution(iPoint, iVar, nodes->GetSolution_Direct(iPoint)[iVar]);
135-
136-
auto Coord = geometry->nodes->GetCoord(iPoint);
137-
for (iDim = 0; iDim < nDim; iDim++) AD::ResetInput(Coord[iDim]);
138132
}
139133

140134
/*--- Reset the input for time n ---*/
141135

142136
if (config->GetTime_Domain()) {
143-
for (iPoint = 0; iPoint < nPoint; iPoint++)
144-
for (iVar = 0; iVar < nVar; iVar++)
137+
for (auto iPoint = 0ul; iPoint < nPoint; iPoint++)
138+
for (auto iVar = 0u; iVar < nVar; iVar++)
145139
AD::ResetInput(direct_solver->GetNodes()->GetSolution_time_n(iPoint)[iVar]);
146140
}
147141

148-
/*--- Set the Jacobian to zero since this is not done inside the meanflow iteration
149-
* when running the discrete adjoint solver. ---*/
150-
151-
direct_solver->Jacobian.SetValZero();
152-
153142
/*--- Set indices to zero ---*/
154143

155144
RegisterVariables(geometry, config, true);
@@ -202,19 +191,18 @@ void CDiscAdjFEASolver::RegisterVariables(CGeometry *geometry, CConfig *config,
202191
for (iVar = 0; iVar < nDV; iVar++) AD::ResetInput(DV[iVar]);
203192
}
204193

205-
direct_solver->GetNodes()->ResetInputFlowTraction();
206-
207194
if (!reset) {
208195
E.Register();
209196
Nu.Register();
210197
Rho.Register();
211198
Rho_DL.Register();
212199
if (de_effects) EField.Register();
213200
if (fea_dv) DV.Register();
201+
}
214202

215-
/*--- Register the flow tractions ---*/
216-
if (config->GetnMarker_Fluid_Load() > 0)
217-
direct_solver->GetNodes()->RegisterFlowTraction();
203+
/*--- Register or reset the flow tractions ---*/
204+
if (config->GetnMarker_Fluid_Load() > 0) {
205+
direct_solver->GetNodes()->RegisterFlowTraction(reset);
218206
}
219207

220208
}
@@ -372,12 +360,12 @@ void CDiscAdjFEASolver::SetSensitivity(CGeometry *geometry, CConfig *config, CSo
372360

373361
for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++) {
374362

375-
//auto Coord = geometry->nodes->GetCoord(iPoint);
363+
auto Coord = geometry->nodes->GetCoord(iPoint);
376364

377365
for (unsigned short iDim = 0; iDim < nDim; iDim++) {
378366

379367
su2double Sensitivity = geometry->nodes->GetAdjointSolution(iPoint, iDim);
380-
//AD::ResetInput(Coord[iDim]);
368+
AD::ResetInput(Coord[iDim]);
381369

382370
if (!time_domain) {
383371
nodes->SetSensitivity(iPoint, iDim, Sensitivity);

SU2_CFD/src/solvers/CDiscAdjSolver.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,6 @@ void CDiscAdjSolver::SetRecording(CGeometry* geometry, CConfig *config){
146146
END_SU2_OMP_FOR
147147
}
148148

149-
/*--- Set the Jacobian to zero since this is not done inside the fluid iteration
150-
* when running the discrete adjoint solver. ---*/
151-
152-
direct_solver->Jacobian.SetValZero();
153-
154149
/*--- Set indices to zero ---*/
155150

156151
RegisterVariables(geometry, config, true);

SU2_CFD/src/variables/CFEABoundVariable.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,10 @@ void CFEABoundVariable::Clear_FlowTraction() { FlowTraction.setConstant(0.0); }
6969

7070
void CFEABoundVariable::Clear_SurfaceLoad_Res() { Residual_Ext_Surf.setConstant(0.0); }
7171

72-
void CFEABoundVariable::RegisterFlowTraction() {
72+
void CFEABoundVariable::RegisterFlowTraction(bool reset) {
7373
if (!fsi_analysis) return;
7474
for (unsigned long iVertex = 0; iVertex < FlowTraction.rows(); iVertex++)
7575
for (unsigned long iVar = 0; iVar < nVar; iVar++)
76-
AD::RegisterInput(FlowTraction(iVertex,iVar));
76+
if (reset) AD::ResetInput(FlowTraction(iVertex,iVar));
77+
else AD::RegisterInput(FlowTraction(iVertex,iVar));
7778
}
78-
79-
void CFEABoundVariable::ResetInputFlowTraction() {
80-
if (!fsi_analysis) return;
81-
for (unsigned long iVertex = 0; iVertex < FlowTraction.rows(); iVertex++)
82-
for (unsigned long iVar = 0; iVar < nVar; iVar++)
83-
AD::ResetInput(FlowTraction(iVertex,iVar));
84-
}

TestCases/parallel_regression_AD.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def main():
413413
pywrapper_Unst_FEA_AD.cfg_dir = "py_wrapper/custom_load_fea"
414414
pywrapper_Unst_FEA_AD.cfg_file = "config.cfg"
415415
pywrapper_Unst_FEA_AD.test_iter = 100
416-
pywrapper_Unst_FEA_AD.test_vals = [0.256684, 0.256684, 0.031988, 0.032015, -18.44906, -18.45085]
416+
pywrapper_Unst_FEA_AD.test_vals = [0.256684, 0.256684, 0.319877, 0.320149, -0.184491, -0.184509]
417417
pywrapper_Unst_FEA_AD.command = TestCase.Command("mpirun -n 2", "python", "run_ad.py")
418418
pywrapper_Unst_FEA_AD.timeout = 1600
419419
pywrapper_Unst_FEA_AD.tol = 0.00001

TestCases/py_wrapper/custom_load_fea/run_ad.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def main():
243243
# Print results for the regression script to check.
244244
if rank == 0:
245245
print("\n")
246-
print(100, 100, sens_load_fd, sens_load, sens_rho_fd, sens_rho, sens_height_fd, sens_height)
246+
print(100, 100, sens_load_fd, sens_load, sens_rho_fd * 10, sens_rho * 10, sens_height_fd / 100, sens_height / 100)
247247

248248

249249
if __name__ == '__main__':

0 commit comments

Comments
 (0)