Skip to content

Commit b39109c

Browse files
committed
try to fix objective functions, #1075
1 parent 236dace commit b39109c

19 files changed

Lines changed: 453 additions & 534 deletions

Common/include/CConfig.hpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ class CConfig {
141141
Sens_Remove_Sharp, /*!< \brief Flag for removing or not the sharp edges from the sensitivity computation. */
142142
Hold_GridFixed, /*!< \brief Flag hold fixed some part of the mesh during the deformation. */
143143
Axisymmetric, /*!< \brief Flag for axisymmetric calculations */
144-
Integrated_HeatFlux, /*!< \brief Flag for heat flux BC whether it deals with integrated values.*/
145-
Buffet_Monitoring; /*!< \brief Flag for computing the buffet sensor.*/
144+
Integrated_HeatFlux; /*!< \brief Flag for heat flux BC whether it deals with integrated values.*/
146145
su2double Buffet_k; /*!< \brief Sharpness coefficient for buffet sensor.*/
147146
su2double Buffet_lambda; /*!< \brief Offset parameter for buffet sensor.*/
148147
su2double Damp_Engine_Inflow; /*!< \brief Damping factor for the engine inlet. */
@@ -5034,11 +5033,6 @@ class CConfig {
50345033
*/
50355034
unsigned short GetKind_ObjFunc(unsigned short val_obj = 0) const { return Kind_ObjFunc[val_obj]; }
50365035

5037-
/*!
5038-
* \brief Similar to GetKind_ObjFunc but returns the corresponding string.
5039-
*/
5040-
string GetName_ObjFunc(unsigned short val_obj = 0) const;
5041-
50425036
/*!
50435037
* \author H. Kline
50445038
* \brief Get the weight of objective function. There are several options: Drag coefficient,
@@ -5867,12 +5861,6 @@ class CConfig {
58675861
*/
58685862
unsigned short GetDesign_Variable(unsigned short val_dv) const { return Design_Variable[val_dv]; }
58695863

5870-
/*!
5871-
* \brief Provides the buffet monitoring information.
5872-
* \return Buffet monitoring information, if <code>TRUE</code> then the code will compute the buffet sensor.
5873-
*/
5874-
bool GetBuffet_Monitoring(void) const { return Buffet_Monitoring; }
5875-
58765864
/*!
58775865
* \brief Get the buffet sensor sharpness coefficient.
58785866
* \return Sharpness coefficient for buffet sensor.

Common/include/option_structure.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ enum ENUM_OBJECTIVE {
14851485
INVERSE_DESIGN_HEATFLUX = 6, /*!< \brief Heat flux objective function definition (inverse design). */
14861486
TOTAL_HEATFLUX = 7, /*!< \brief Total heat flux. */
14871487
MAXIMUM_HEATFLUX = 8, /*!< \brief Maximum heat flux. */
1488-
TOTAL_AVG_TEMPERATURE = 70, /*!< \brief Total averaged temperature. */
1488+
AVG_TEMPERATURE = 70, /*!< \brief Total averaged temperature. */
14891489
MOMENT_X_COEFFICIENT = 9, /*!< \brief Pitching moment objective function definition. */
14901490
MOMENT_Y_COEFFICIENT = 10, /*!< \brief Rolling moment objective function definition. */
14911491
MOMENT_Z_COEFFICIENT = 11, /*!< \brief Yawing objective function definition. */
@@ -1545,7 +1545,7 @@ static const MapType<string, ENUM_OBJECTIVE> Objective_Map = {
15451545
MakePair("TORQUE", TORQUE_COEFFICIENT)
15461546
MakePair("TOTAL_HEATFLUX", TOTAL_HEATFLUX)
15471547
MakePair("MAXIMUM_HEATFLUX", MAXIMUM_HEATFLUX)
1548-
MakePair("TOTAL_AVG_TEMPERATURE", TOTAL_AVG_TEMPERATURE)
1548+
MakePair("AVG_TEMPERATURE", AVG_TEMPERATURE)
15491549
MakePair("FIGURE_OF_MERIT", FIGURE_OF_MERIT)
15501550
MakePair("BUFFET", BUFFET_SENSOR)
15511551
MakePair("SURFACE_TOTAL_PRESSURE", SURFACE_TOTAL_PRESSURE)

Common/src/CConfig.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,8 +1594,6 @@ void CConfig::SetConfig_Options() {
15941594
/* DESCRIPTION: Evaluate a problem with engines */
15951595
addBoolOption("ENGINE", Engine, false);
15961596

1597-
/* DESCRIPTION: Compute buffet sensor */
1598-
addBoolOption("BUFFET_MONITORING", Buffet_Monitoring, false);
15991597
/* DESCRIPTION: Sharpness coefficient for the buffet sensor */
16001598
addDoubleOption("BUFFET_K", Buffet_k, 10.0);
16011599
/* DESCRIPTION: Offset parameter for the buffet sensor */
@@ -3502,10 +3500,6 @@ void CConfig::SetPostprocessing(unsigned short val_software, unsigned short val_
35023500
SU2_MPI::Error("Harmonic Balance not yet implemented for the incompressible solver.", CURRENT_FUNCTION);
35033501
}
35043502

3505-
if ((Kind_Solver != NAVIER_STOKES && Kind_Solver != RANS) && (Buffet_Monitoring == true)){
3506-
SU2_MPI::Error("Buffet monitoring incompatible with solvers other than NAVIER_STOKES and RANS", CURRENT_FUNCTION);
3507-
}
3508-
35093503
/*--- Check for Fluid model consistency ---*/
35103504

35113505
if (standard_air) {
@@ -7996,9 +7990,9 @@ string CConfig::GetObjFunc_Extension(string val_filename) const {
79967990
case TORQUE_COEFFICIENT: AdjExt = "_cq"; break;
79977991
case TOTAL_HEATFLUX: AdjExt = "_totheat"; break;
79987992
case MAXIMUM_HEATFLUX: AdjExt = "_maxheat"; break;
7999-
case TOTAL_AVG_TEMPERATURE: AdjExt = "_avtp"; break;
7993+
case AVG_TEMPERATURE: AdjExt = "_avtp"; break;
80007994
case FIGURE_OF_MERIT: AdjExt = "_merit"; break;
8001-
case BUFFET_SENSOR: AdjExt = "_buffet"; break;
7995+
case BUFFET_SENSOR: AdjExt = "_buffet"; break;
80027996
case SURFACE_TOTAL_PRESSURE: AdjExt = "_pt"; break;
80037997
case SURFACE_STATIC_PRESSURE: AdjExt = "_pe"; break;
80047998
case SURFACE_MASSFLOW: AdjExt = "_mfr"; break;
@@ -9305,13 +9299,6 @@ short CConfig::FindInterfaceMarker(unsigned short iInterface) const {
93059299
return -1;
93069300
}
93079301

9308-
string CConfig::GetName_ObjFunc(unsigned short val_obj) const {
9309-
for (auto item : Objective_Map)
9310-
if (item.second == static_cast<ENUM_OBJECTIVE>(Kind_ObjFunc[val_obj]))
9311-
return item.first;
9312-
return string();
9313-
}
9314-
93159302
void CConfig::Tick(double *val_start_time) {
93169303

93179304
#ifdef PROFILE

SU2_CFD/include/solvers/CFVMFlowSolverBase.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,13 @@ class CFVMFlowSolverBase : public CSolver {
14641464
*/
14651465
void Friction_Forces(const CGeometry* geometry, const CConfig* config) final;
14661466

1467+
/*!
1468+
* \brief Compute the buffet sensor.
1469+
* \param[in] geometry - Geometrical definition of the problem.
1470+
* \param[in] config - Definition of the particular problem.
1471+
*/
1472+
inline virtual void Buffet_Monitoring(const CGeometry *geometry, const CConfig *config) { }
1473+
14671474
/*!
14681475
* \brief Allocates the final pointer of SlidingState depending on how many donor vertex donate to it.
14691476
* That number is stored in SlidingStateNodes[val_marker][val_vertex].

SU2_CFD/include/solvers/CFVMFlowSolverBase.inl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,6 +2487,10 @@ void CFVMFlowSolverBase<V, FlowRegime>::Friction_Forces(const CGeometry* geometr
24872487
SurfaceCoeff.CMy[iMarker_Monitoring] += SurfaceViscCoeff.CMy[iMarker_Monitoring];
24882488
SurfaceCoeff.CMz[iMarker_Monitoring] += SurfaceViscCoeff.CMz[iMarker_Monitoring];
24892489
}
2490+
2491+
2492+
Buffet_Monitoring(geometry, config);
2493+
24902494
}
24912495

24922496
template<class V, ENUM_REGIME R>
@@ -2586,6 +2590,9 @@ su2double CFVMFlowSolverBase<V,R>::EvaluateCommonObjFunc(const CConfig& config)
25862590
case SURFACE_SECOND_OVER_UNIFORM:
25872591
objFun += weight * config.GetSurface_SecondOverUniform(0);
25882592
break;
2593+
case SURFACE_PRESSURE_DROP:
2594+
objFun += weight * config.GetSurface_PressureDrop(0);
2595+
break;
25892596
case CUSTOM_OBJFUNC:
25902597
objFun += weight * Total_Custom_ObjFunc;
25912598
break;

SU2_CFD/include/solvers/CNSSolver.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class CNSSolver final : public CEulerSolver {
203203
* \param[in] geometry - Geometrical definition of the problem.
204204
* \param[in] config - Definition of the particular problem.
205205
*/
206-
void Buffet_Monitoring(CGeometry *geometry, CConfig *config) override;
206+
void Buffet_Monitoring(const CGeometry *geometry, const CConfig *config) override;
207207

208208
/*!
209209
* \brief Compute the viscous contribution for a particular edge.

SU2_CFD/include/solvers/CSolver.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,13 +1638,6 @@ class CSolver {
16381638
*/
16391639
inline virtual void Friction_Forces(const CGeometry* geometry, const CConfig* config) { }
16401640

1641-
/*!
1642-
* \brief A virtual member.
1643-
* \param[in] geometry - Geometrical definition of the problem.
1644-
* \param[in] config - Definition of the particular problem.
1645-
*/
1646-
inline virtual void Buffet_Monitoring(CGeometry *geometry, CConfig *config) { }
1647-
16481641
/*!
16491642
* \brief A virtual member.
16501643
* \param[in] geometry - Geometrical definition of the problem.

SU2_CFD/src/drivers/CDiscAdjMultizoneDriver.cpp

Lines changed: 17 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,6 @@ void CDiscAdjMultizoneDriver::DirectIteration(unsigned short iZone, unsigned sho
654654
void CDiscAdjMultizoneDriver::SetObjFunction(unsigned short kind_recording) {
655655

656656
ObjFunc = 0.0;
657-
su2double Weight_ObjFunc;
658-
659-
unsigned short iMarker_Analyze, nMarker_Analyze;
660657

661658
/*--- Call objective function calculations. ---*/
662659

@@ -678,14 +675,16 @@ void CDiscAdjMultizoneDriver::SetObjFunction(unsigned short kind_recording) {
678675
if(config->GetWeakly_Coupled_Heat()) {
679676
solvers[HEAT_SOL]->Heat_Fluxes(geometry, solvers, config);
680677
}
678+
679+
direct_output[iZone]->SetHistory_Output(geometry, solvers, config);
680+
681681
solvers[FLOW_SOL]->Evaluate_ObjFunc(config);
682682
break;
683+
683684
case DISC_ADJ_HEAT:
684685
solvers[HEAT_SOL]->Heat_Fluxes(geometry, solvers, config);
685686
break;
686687
}
687-
688-
direct_output[iZone]->SetHistory_Output(geometry, solvers, config);
689688
}
690689

691690
/*--- Extract objective function values. ---*/
@@ -696,28 +695,9 @@ void CDiscAdjMultizoneDriver::SetObjFunction(unsigned short kind_recording) {
696695
auto solvers = solver_container[iZone][INST_0][MESH_0];
697696
auto geometry = geometry_container[iZone][INST_0][MESH_0];
698697

699-
nMarker_Analyze = config->GetnMarker_Analyze();
700-
701-
for (iMarker_Analyze = 0; iMarker_Analyze < nMarker_Analyze; iMarker_Analyze++) {
702-
703-
Weight_ObjFunc = config->GetWeight_ObjFunc(iMarker_Analyze);
704-
705-
switch (config->GetKind_Solver()) {
706-
707-
case DISC_ADJ_EULER: case DISC_ADJ_NAVIER_STOKES: case DISC_ADJ_RANS:
708-
// per-surface output to be added soon
709-
break;
710-
case HEAT_EQUATION: case DISC_ADJ_HEAT:
711-
// per-surface output to be added soon
712-
break;
713-
default:
714-
break;
715-
}
716-
}
717-
718698
/*--- Not-per-surface objective functions (shall not be included above) ---*/
719699

720-
Weight_ObjFunc = config->GetWeight_ObjFunc(0);
700+
const auto Weight_ObjFunc = config->GetWeight_ObjFunc(0);
721701

722702
bool ObjectiveNotCovered = false;
723703

@@ -726,57 +706,20 @@ void CDiscAdjMultizoneDriver::SetObjFunction(unsigned short kind_recording) {
726706
case DISC_ADJ_EULER: case DISC_ADJ_NAVIER_STOKES: case DISC_ADJ_RANS:
727707
case DISC_ADJ_INC_EULER: case DISC_ADJ_INC_NAVIER_STOKES: case DISC_ADJ_INC_RANS:
728708
{
729-
string FieldName;
730-
731-
switch (config->GetKind_ObjFunc()) {
732-
733-
// Aerodynamic coefficients
734-
735-
case DRAG_COEFFICIENT:
736-
case LIFT_COEFFICIENT:
737-
case SIDEFORCE_COEFFICIENT:
738-
case EFFICIENCY:
739-
case MOMENT_X_COEFFICIENT:
740-
case MOMENT_Y_COEFFICIENT:
741-
case MOMENT_Z_COEFFICIENT:
742-
case FORCE_X_COEFFICIENT:
743-
case FORCE_Y_COEFFICIENT:
744-
case FORCE_Z_COEFFICIENT:
745-
FieldName = config->GetName_ObjFunc();
746-
break;
747-
748-
// Other surface-related output values
749-
// The names are different than in CConfig...
750-
751-
case SURFACE_MASSFLOW: FieldName = "AVG_MASSFLOW"; break;
752-
case SURFACE_MACH: FieldName = "AVG_MACH"; break;
753-
case SURFACE_UNIFORMITY: FieldName = "UNIFORMITY"; break;
754-
case SURFACE_SECONDARY: FieldName = "SECONDARY_STRENGTH"; break;
755-
case SURFACE_MOM_DISTORTION: FieldName = "MOMENTUM_DISTORTION"; break;
756-
case SURFACE_SECOND_OVER_UNIFORM: FieldName = "SECONDARY_OVER_UNIFORMITY"; break;
757-
case TOTAL_AVG_TEMPERATURE: FieldName = "AVG_TOTALTEMP"; break;
758-
case SURFACE_TOTAL_PRESSURE: FieldName = "AVG_TOTALPRESS"; break;
759-
760-
// Not yet covered by new output structure. Be careful these use MARKER_MONITORING.
761-
762-
case SURFACE_PRESSURE_DROP:
763-
ObjFunc += config->GetSurface_PressureDrop(0)*Weight_ObjFunc;
764-
break;
765-
case SURFACE_STATIC_PRESSURE:
766-
ObjFunc += config->GetSurface_Pressure(0)*Weight_ObjFunc;
767-
break;
768-
case TOTAL_HEATFLUX:
769-
ObjFunc += solvers[FLOW_SOL]->GetTotal_HeatFlux()*Weight_ObjFunc;
770-
break;
709+
auto val = solvers[FLOW_SOL]->GetTotal_ComboObj();
771710

772-
default:
773-
ObjectiveNotCovered = true;
774-
break;
711+
if (config->GetWeakly_Coupled_Heat()) {
712+
if (config->GetKind_ObjFunc() == TOTAL_HEATFLUX) {
713+
val += solvers[HEAT_SOL]->GetTotal_HeatFlux();
714+
}
715+
else if (config->GetKind_ObjFunc() == AVG_TEMPERATURE) {
716+
val += solvers[HEAT_SOL]->GetTotal_AvgTemperature();
717+
}
775718
}
719+
ObjFunc += val*Weight_ObjFunc;
776720

777-
if(!FieldName.empty())
778-
ObjFunc += direct_output[iZone]->GetHistoryFieldValue(FieldName)*Weight_ObjFunc;
779-
721+
/*--- This is not ideal... ---*/
722+
ObjectiveNotCovered = (val==0.0);
780723
break;
781724
}
782725
case DISC_ADJ_HEAT:
@@ -788,7 +731,7 @@ void CDiscAdjMultizoneDriver::SetObjFunction(unsigned short kind_recording) {
788731
case TOTAL_HEATFLUX:
789732
ObjFunc += solvers[HEAT_SOL]->GetTotal_HeatFlux()*Weight_ObjFunc;
790733
break;
791-
case TOTAL_AVG_TEMPERATURE:
734+
case AVG_TEMPERATURE:
792735
ObjFunc += solvers[HEAT_SOL]->GetTotal_AvgTemperature()*Weight_ObjFunc;
793736
break;
794737

SU2_CFD/src/drivers/CDiscAdjSinglezoneDriver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ void CDiscAdjSinglezoneDriver::SetObjFunction(){
377377
if (config->GetKind_ObjFunc() == TOTAL_HEATFLUX) {
378378
ObjFunc += solver[HEAT_SOL]->GetTotal_HeatFlux();
379379
}
380-
else if (config->GetKind_ObjFunc() == TOTAL_AVG_TEMPERATURE) {
380+
else if (config->GetKind_ObjFunc() == AVG_TEMPERATURE) {
381381
ObjFunc += solver[HEAT_SOL]->GetTotal_AvgTemperature();
382382
}
383383
}
@@ -416,7 +416,7 @@ void CDiscAdjSinglezoneDriver::SetObjFunction(){
416416
case TOTAL_HEATFLUX:
417417
ObjFunc = solver[HEAT_SOL]->GetTotal_HeatFlux();
418418
break;
419-
case TOTAL_AVG_TEMPERATURE:
419+
case AVG_TEMPERATURE:
420420
ObjFunc = solver[HEAT_SOL]->GetTotal_AvgTemperature();
421421
break;
422422
default:

SU2_CFD/src/integration/CMultiGridIntegration.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -688,12 +688,6 @@ void CMultiGridIntegration::NonDimensional_Parameters(CGeometry **geometry, CSol
688688
solver_container[FinestMesh][FLOW_SOL]->Momentum_Forces(geometry[FinestMesh], config);
689689
solver_container[FinestMesh][FLOW_SOL]->Friction_Forces(geometry[FinestMesh], config);
690690

691-
/*--- Evaluate the buffet metric if requested ---*/
692-
693-
if(config->GetBuffet_Monitoring() || config->GetKind_ObjFunc() == BUFFET_SENSOR){
694-
solver_container[FinestMesh][FLOW_SOL]->Buffet_Monitoring(geometry[FinestMesh], config);
695-
}
696-
697691
break;
698692

699693
case RUNTIME_ADJFLOW_SYS:

0 commit comments

Comments
 (0)