Skip to content

Commit 7776bef

Browse files
committed
structural objective functions in history, delete a lot of unused stuff
1 parent 95cc5b1 commit 7776bef

13 files changed

Lines changed: 145 additions & 266 deletions

SU2_CFD/include/solvers/CDiscAdjFEASolver.hpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,6 @@ class CDiscAdjFEASolver final : public CSolver {
160160
*/
161161
void ExtractAdjoint_Solution(CGeometry *geometry, CConfig *config) override;
162162

163-
/*!
164-
* \brief Register the objective function as output.
165-
* \param[in] geometry - The geometrical definition of the problem.
166-
*/
167-
void RegisterObj_Func(CConfig *config) override;
168-
169163
/*!
170164
* \brief Set the surface sensitivity.
171165
* \param[in] geometry - Geometrical definition of the problem.
@@ -180,13 +174,6 @@ class CDiscAdjFEASolver final : public CSolver {
180174
*/
181175
void SetSensitivity(CGeometry *geometry, CConfig *config, CSolver*) override;
182176

183-
/*!
184-
* \brief Set the objective function.
185-
* \param[in] geometry - Geometrical definition of the problem.
186-
* \param[in] config - Definition of the particular problem.
187-
*/
188-
void SetAdj_ObjFunc(CGeometry *geometry, CConfig* config) override;
189-
190177
/*!
191178
* \brief Provide the total Young's modulus sensitivity
192179
* \return Value of the total Young's modulus sensitivity

SU2_CFD/include/solvers/CDiscAdjSolver.hpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,6 @@ class CDiscAdjSolver final : public CSolver {
140140
*/
141141
void ExtractAdjoint_Geometry(CGeometry *geometry, CConfig *config) override;
142142

143-
/*!
144-
* \brief Register the objective function as output.
145-
* \param[in] geometry - The geometrical definition of the problem.
146-
*/
147-
void RegisterObj_Func(CConfig *config) override;
148-
149143
/*!
150144
* \brief Set the surface sensitivity.
151145
* \param[in] geometry - Geometrical definition of the problem.
@@ -160,13 +154,6 @@ class CDiscAdjSolver final : public CSolver {
160154
*/
161155
void SetSensitivity(CGeometry *geometry, CConfig *config, CSolver*) override;
162156

163-
/*!
164-
* \brief Set the objective function.
165-
* \param[in] geometry - Geometrical definition of the problem.
166-
* \param[in] config - Definition of the particular problem.
167-
*/
168-
void SetAdj_ObjFunc(CGeometry *geometry, CConfig* config) override;
169-
170157
/*!
171158
* \brief Provide the total shape sensitivity coefficient.
172159
* \return Value of the geometrical sensitivity coefficient

SU2_CFD/include/solvers/CFEASolver.hpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ class CFEASolver : public CSolver {
6767
su2double Total_OFRefGeom; /*!< \brief Total Objective Function: Reference Geometry. */
6868
su2double Total_OFRefNode; /*!< \brief Total Objective Function: Reference Node. */
6969
su2double Total_OFVolFrac; /*!< \brief Total Objective Function: Volume fraction (topology optimization). */
70+
su2double Total_OFDiscreteness; /*!< \brief Total Objective Function: Discreteness (topology optimization). */
7071
su2double Total_OFCompliance; /*!< \brief Total Objective Function: Compliance (topology optimization). */
71-
su2double Total_OFCombo = 0.0; /*!< \brief One of the above, for output/history purposes. */
7272

7373
su2double Global_OFRefGeom; /*!< \brief Global Objective Function (added over time steps): Reference Geometry. */
7474
su2double Global_OFRefNode; /*!< \brief Global Objective Function (added over time steps): Reference Node. */
@@ -541,33 +541,29 @@ class CFEASolver : public CSolver {
541541

542542
/*!
543543
* \brief Retrieve the value of the objective function for a reference geometry
544-
* \param[out] OFRefGeom - value of the objective function.
545544
*/
546545
inline su2double GetTotal_OFRefGeom(void) const final { return Total_OFRefGeom; }
547546

548547
/*!
549548
* \brief Retrieve the value of the objective function for a reference node
550-
* \param[out] OFRefNode - value of the objective function.
551549
*/
552550
inline su2double GetTotal_OFRefNode(void) const final { return Total_OFRefNode; }
553551

554552
/*!
555553
* \brief Retrieve the value of the volume fraction objective function
556-
* \param[out] OFVolFrac - value of the objective function.
557554
*/
558555
inline su2double GetTotal_OFVolFrac(void) const final { return Total_OFVolFrac; }
559556

560557
/*!
561-
* \brief Retrieve the value of the structural compliance objective function
562-
* \return Value of the objective function.
558+
* \brief Retrieve the value of the discreteness objective function
563559
*/
564-
inline su2double GetTotal_OFCompliance(void) const final { return Total_OFCompliance; }
560+
inline su2double GetTotal_OFDiscreteness(void) const final { return Total_OFDiscreteness; }
565561

566562
/*!
567-
* \brief Retrieve the value of the combined objective function
568-
* \note For now there is no combination, this is just a seletion.
563+
* \brief Retrieve the value of the structural compliance objective function
564+
* \return Value of the objective function.
569565
*/
570-
inline su2double GetTotal_ComboObj(void) const final { return Total_OFCombo; }
566+
inline su2double GetTotal_OFCompliance(void) const final { return Total_OFCompliance; }
571567

572568
/*!
573569
* \brief Determines whether there is an element-based file or not.

SU2_CFD/include/solvers/CSolver.hpp

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,6 +2465,11 @@ class CSolver {
24652465
*/
24662466
inline virtual su2double GetTotal_OFVolFrac() const { return 0; }
24672467

2468+
/*!
2469+
* \brief Retrieve the value of the discreteness objective function
2470+
*/
2471+
inline virtual su2double GetTotal_OFDiscreteness() const { return 0; }
2472+
24682473
/*!
24692474
* \brief A virtual member.
24702475
* \return Value of the objective function for the structural compliance.
@@ -3630,41 +3635,6 @@ class CSolver {
36303635
CConfig *config,
36313636
int val_iter) { }
36323637

3633-
/*!
3634-
* \brief A virtual member.
3635-
* \param[in] geometry - Geometrical definition of the problem.
3636-
* \param[in] solver_container - Container vector with all the solutions.
3637-
* \param[in] numerics - Description of the numerical method.
3638-
* \param[in] config - Definition of the particular problem.
3639-
*/
3640-
inline virtual void RefGeom_Sensitivity(CGeometry *geometry,
3641-
CSolver **solver_container,
3642-
CConfig *config){ }
3643-
3644-
/*!
3645-
* \brief A virtual member.
3646-
* \param[in] geometry - Geometrical definition of the problem.
3647-
* \param[in] solver_container - Container vector with all the solutions.
3648-
* \param[in] numerics - Description of the numerical method.
3649-
* \param[in] config - Definition of the particular problem.
3650-
*/
3651-
inline virtual void DE_Sensitivity(CGeometry *geometry,
3652-
CSolver **solver_container,
3653-
CNumerics **numerics_container,
3654-
CConfig *config) { }
3655-
3656-
/*!
3657-
* \brief A virtual member.
3658-
* \param[in] geometry - Geometrical definition of the problem.
3659-
* \param[in] solver_container - Container vector with all the solutions.
3660-
* \param[in] numerics - Description of the numerical method.
3661-
* \param[in] config - Definition of the particular problem.
3662-
*/
3663-
inline virtual void Stiffness_Sensitivity(CGeometry *geometry,
3664-
CSolver **solver_container,
3665-
CNumerics **numerics_container,
3666-
CConfig *config) { }
3667-
36683638
/*!
36693639
* \brief A virtual member.
36703640
* \param[in] iElem - element parameter.
@@ -3777,12 +3747,6 @@ class CSolver {
37773747
*/
37783748
inline virtual void ExtractAdjoint_Geometry(CGeometry *geometry, CConfig *config) {}
37793749

3780-
/*!
3781-
* \brief A virtual member
3782-
* \param[in] geometry - The geometrical definition of the problem.
3783-
*/
3784-
inline virtual void RegisterObj_Func(CConfig *config){}
3785-
37863750
/*!
37873751
* \brief A virtual member.
37883752
* \param[in] geometry - Geometrical definition of the problem.
@@ -3798,13 +3762,6 @@ class CSolver {
37983762
*/
37993763
inline virtual void SetSensitivity(CGeometry *geometry, CConfig *config, CSolver *target_solver = nullptr){ }
38003764

3801-
/*!
3802-
* \brief A virtual member. Extract and set the derivative of objective function.
3803-
* \param[in] geometry - Geometrical definition of the problem.
3804-
* \param[in] config - Definition of the particular problem.
3805-
*/
3806-
inline virtual void SetAdj_ObjFunc(CGeometry *geometry, CConfig *config) { }
3807-
38083765
/*!
38093766
* \brief A virtual member.
38103767
* \param[in] Set value of interest: 0 - Initial value, 1 - Current value.

SU2_CFD/src/drivers/CDiscAdjMultizoneDriver.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,13 @@ void CDiscAdjMultizoneDriver::SetObjFunction(unsigned short kind_recording) {
758758
ObjFunc += solvers[FEA_SOL]->GetTotal_OFCompliance()*Weight_ObjFunc;
759759
break;
760760
case VOLUME_FRACTION:
761-
case TOPOL_DISCRETENESS:
762761
solvers[FEA_SOL]->Compute_OFVolFrac(geometry, config);
763762
ObjFunc += solvers[FEA_SOL]->GetTotal_OFVolFrac()*Weight_ObjFunc;
764763
break;
764+
case TOPOL_DISCRETENESS:
765+
solvers[FEA_SOL]->Compute_OFVolFrac(geometry, config);
766+
ObjFunc += solvers[FEA_SOL]->GetTotal_OFDiscreteness()*Weight_ObjFunc;
767+
break;
765768

766769
default:
767770
ObjectiveNotCovered = true;

SU2_CFD/src/drivers/CDiscAdjSinglezoneDriver.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,11 @@ void CDiscAdjSinglezoneDriver::SetObjFunction(){
436436
ObjFunc = solver[FEA_SOL]->GetTotal_OFCompliance();
437437
break;
438438
case VOLUME_FRACTION:
439-
case TOPOL_DISCRETENESS:
440439
ObjFunc = solver[FEA_SOL]->GetTotal_OFVolFrac();
441440
break;
441+
case TOPOL_DISCRETENESS:
442+
ObjFunc = solver[FEA_SOL]->GetTotal_OFDiscreteness();
443+
break;
442444
default:
443445
ObjFunc = 0.0; // If the objective function is computed in a different physical problem
444446
break;

SU2_CFD/src/iteration/CDiscAdjFEAIteration.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,6 @@ void CDiscAdjFEAIteration::RegisterOutput(CSolver***** solver, CGeometry**** geo
401401

402402
void CDiscAdjFEAIteration::InitializeAdjoint(CSolver***** solver, CGeometry**** geometry, CConfig** config,
403403
unsigned short iZone, unsigned short iInst) {
404-
/*--- Initialize the adjoint of the objective function (typically with 1.0) ---*/
405-
406-
solver[iZone][iInst][MESH_0][ADJFEA_SOL]->SetAdj_ObjFunc(geometry[iZone][iInst][MESH_0], config[iZone]);
407-
408404
/*--- Initialize the adjoints the conservative variables ---*/
409405

410406
solver[iZone][iInst][MESH_0][ADJFEA_SOL]->SetAdjoint_Output(geometry[iZone][iInst][MESH_0], config[iZone]);
@@ -455,9 +451,11 @@ void CDiscAdjFEAIteration::Postprocess(COutput* output, CIntegration**** integra
455451
myfile_res << scientific << solver[val_iZone][val_iInst][MESH_0][FEA_SOL]->GetTotal_OFRefNode() << "\t";
456452
break;
457453
case VOLUME_FRACTION:
458-
case TOPOL_DISCRETENESS:
459454
myfile_res << scientific << solver[val_iZone][val_iInst][MESH_0][FEA_SOL]->GetTotal_OFVolFrac() << "\t";
460455
break;
456+
case TOPOL_DISCRETENESS:
457+
myfile_res << scientific << solver[val_iZone][val_iInst][MESH_0][FEA_SOL]->GetTotal_OFDiscreteness() << "\t";
458+
break;
461459
case TOPOL_COMPLIANCE:
462460
myfile_res << scientific << solver[val_iZone][val_iInst][MESH_0][FEA_SOL]->GetTotal_OFCompliance() << "\t";
463461
break;

SU2_CFD/src/output/CAdjElasticityOutput.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ void CAdjElasticityOutput::SetHistoryOutputFields(CConfig *config){
106106
AddHistoryOutput("SENS_E", "Sens[E]", ScreenOutputFormat::SCIENTIFIC, "SENSITIVITY", "");
107107
AddHistoryOutput("SENS_NU","Sens[Nu]", ScreenOutputFormat::SCIENTIFIC, "SENSITIVITY", "");
108108

109-
AddHistoryOutput("COMBO", "ObjFun", ScreenOutputFormat::SCIENTIFIC, "COMBO", "", HistoryFieldType::COEFFICIENT);
110-
111109
AddHistoryOutput("LINSOL_ITER", "LinSolIter", ScreenOutputFormat::INTEGER, "LINSOL", "Number of iterations of the linear solver.");
112110
AddHistoryOutput("LINSOL_RESIDUAL", "LinSolRes", ScreenOutputFormat::FIXED, "LINSOL", "Residual of the linear solver.");
113111

@@ -141,8 +139,6 @@ inline void CAdjElasticityOutput::LoadHistoryData(CConfig *config, CGeometry *ge
141139
SetHistoryOutputValue("SENS_E", Total_SensE);
142140
SetHistoryOutputValue("SENS_NU", Total_SensNu);
143141

144-
SetHistoryOutputValue("COMBO", solver[FEA_SOL]->GetTotal_ComboObj());
145-
146142
SetHistoryOutputValue("LINSOL_ITER", solver[ADJFEA_SOL]->GetIterLinSolver());
147143
SetHistoryOutputValue("LINSOL_RESIDUAL", log10(solver[ADJFEA_SOL]->GetResLinSolver()));
148144

SU2_CFD/src/output/CElasticityOutput.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,15 @@ void CElasticityOutput::LoadHistoryData(CConfig *config, CGeometry *geometry, CS
134134
SetHistoryOutputValue("LINSOL_ITER", fea_solver->GetIterLinSolver());
135135
SetHistoryOutputValue("LINSOL_RESIDUAL", log10(fea_solver->GetResLinSolver()));
136136

137-
SetHistoryOutputValue("COMBO", fea_solver->GetTotal_ComboObj());
137+
SetHistoryOutputValue("REFERENCE_NODE", fea_solver->GetTotal_OFRefNode());
138+
SetHistoryOutputValue("TOPOL_COMPLIANCE", fea_solver->GetTotal_OFCompliance());
139+
if (config->GetRefGeom()) {
140+
SetHistoryOutputValue("REFERENCE_GEOMETRY", fea_solver->GetTotal_OFRefGeom());
141+
}
142+
if (config->GetTopology_Optimization()) {
143+
SetHistoryOutputValue("VOLUME_FRACTION", fea_solver->GetTotal_OFVolFrac());
144+
SetHistoryOutputValue("TOPOL_DISCRETENESS", fea_solver->GetTotal_OFDiscreteness());
145+
}
138146

139147
}
140148

@@ -158,10 +166,14 @@ void CElasticityOutput::SetHistoryOutputFields(CConfig *config){
158166
AddHistoryOutput("BGS_DISP_Z", "bgs[DispZ]", ScreenOutputFormat::FIXED, "BGS_RES", "", HistoryFieldType::RESIDUAL);
159167

160168
AddHistoryOutput("VMS", "VonMises", ScreenOutputFormat::SCIENTIFIC, "", "VMS");
161-
AddHistoryOutput("LOAD_INCREMENT", "Load[%]", ScreenOutputFormat::PERCENT, "", "LOAD_INCREMENT");
162-
AddHistoryOutput("LOAD_RAMP", "Load_Ramp", ScreenOutputFormat::FIXED, "", "LOAD_RAMP");
163-
164-
AddHistoryOutput("COMBO", "ObjFun", ScreenOutputFormat::SCIENTIFIC, "COMBO", "", HistoryFieldType::COEFFICIENT);
169+
AddHistoryOutput("LOAD_INCREMENT", "Load[%]", ScreenOutputFormat::PERCENT, "", "LOAD_INCREMENT");
170+
AddHistoryOutput("LOAD_RAMP", "Load_Ramp",ScreenOutputFormat::FIXED, "", "LOAD_RAMP");
171+
172+
AddHistoryOutput("REFERENCE_GEOMETRY", "RefGeom", ScreenOutputFormat::SCIENTIFIC, "STRUCT_COEFF", "", HistoryFieldType::COEFFICIENT);
173+
AddHistoryOutput("REFERENCE_NODE", "RefNode", ScreenOutputFormat::SCIENTIFIC, "STRUCT_COEFF", "", HistoryFieldType::COEFFICIENT);
174+
AddHistoryOutput("VOLUME_FRACTION", "VolFrac", ScreenOutputFormat::SCIENTIFIC, "STRUCT_COEFF", "", HistoryFieldType::COEFFICIENT);
175+
AddHistoryOutput("TOPOL_DISCRETENESS", "TopDisc", ScreenOutputFormat::SCIENTIFIC, "STRUCT_COEFF", "", HistoryFieldType::COEFFICIENT);
176+
AddHistoryOutput("TOPOL_COMPLIANCE", "TopComp", ScreenOutputFormat::SCIENTIFIC, "STRUCT_COEFF", "", HistoryFieldType::COEFFICIENT);
165177

166178
}
167179

SU2_CFD/src/solvers/CDiscAdjFEASolver.cpp

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -462,67 +462,6 @@ void CDiscAdjFEASolver::RegisterOutput(CGeometry *geometry, CConfig *config){
462462

463463
}
464464

465-
void CDiscAdjFEASolver::RegisterObj_Func(CConfig *config){
466-
467-
/*--- Here we can add new (scalar) objective functions ---*/
468-
469-
switch (config->GetKind_ObjFunc()){
470-
case REFERENCE_GEOMETRY:
471-
ObjFunc_Value = direct_solver->GetTotal_OFRefGeom();
472-
break;
473-
case REFERENCE_NODE:
474-
ObjFunc_Value = direct_solver->GetTotal_OFRefNode();
475-
break;
476-
case VOLUME_FRACTION:
477-
case TOPOL_DISCRETENESS:
478-
ObjFunc_Value = direct_solver->GetTotal_OFVolFrac();
479-
break;
480-
case TOPOL_COMPLIANCE:
481-
ObjFunc_Value = direct_solver->GetTotal_OFCompliance();
482-
break;
483-
default:
484-
ObjFunc_Value = 0.0; // If the objective function is computed in a different physical problem
485-
break;
486-
/*--- Template for new objective functions where TemplateObjFunction()
487-
* is the routine that returns the obj. function value. The computation
488-
* must be done while the tape is active, i.e. between AD::StartRecording() and
489-
* AD::StopRecording() in DiscAdjMeanFlowIteration::Iterate(). The best place is somewhere
490-
* inside MeanFlowIteration::Iterate().
491-
*
492-
* case TEMPLATE_OBJECTIVE:
493-
* ObjFunc_Value = TemplateObjFunction();
494-
* break;
495-
* ---*/
496-
}
497-
if (rank == MASTER_NODE){
498-
AD::RegisterOutput(ObjFunc_Value);
499-
}
500-
}
501-
502-
503-
void CDiscAdjFEASolver::SetAdj_ObjFunc(CGeometry *geometry, CConfig *config){
504-
505-
bool dynamic = (config->GetTime_Domain());
506-
unsigned long IterAvg_Obj = config->GetIter_Avg_Objective();
507-
unsigned long TimeIter = config->GetTimeIter();
508-
su2double seeding = 1.0;
509-
510-
if (dynamic){
511-
if (TimeIter < IterAvg_Obj){
512-
seeding = 1.0/((su2double)IterAvg_Obj);
513-
}
514-
else{
515-
seeding = 0.0;
516-
}
517-
}
518-
519-
if (rank == MASTER_NODE){
520-
SU2_TYPE::SetDerivative(ObjFunc_Value, SU2_TYPE::GetValue(seeding));
521-
} else {
522-
SU2_TYPE::SetDerivative(ObjFunc_Value, 0.0);
523-
}
524-
}
525-
526465
void CDiscAdjFEASolver::ExtractAdjoint_Solution(CGeometry *geometry, CConfig *config){
527466

528467
bool dynamic = config->GetTime_Domain();

0 commit comments

Comments
 (0)