Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom objective function (e.g. 'DRAG + LIFT') #1478

Merged
merged 13 commits into from
Jan 9, 2022
6 changes: 0 additions & 6 deletions Common/include/CConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5469,12 +5469,6 @@ class CConfig {
*/
string GetObjFunc_Extension(string val_filename) const;

/*!
* \brief Get the criteria for structural residual (relative/absolute).
* \return Relative/Absolute criteria for structural convergence.
*/
unsigned short GetResidual_Criteria_FEM(void) const { return Res_FEM_CRIT; }

/*!
* \brief Get functional that is going to be used to evaluate the residual flow convergence.
* \return Functional that is going to be used to evaluate the residual flow convergence.
Expand Down
84 changes: 0 additions & 84 deletions Common/include/option_structure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1563,17 +1563,8 @@ enum ENUM_OBJECTIVE {
SURFACE_SPECIES_0 = 58, /*!< \brief Surface Avg. Species_0 objective function definition. */
SURFACE_SPECIES_VARIANCE = 59,/*!< \brief Species Variance objective function definition. */
CUSTOM_OBJFUNC = 31, /*!< \brief Custom objective function definition. */
TOTAL_PRESSURE_LOSS = 39,
KINETIC_ENERGY_LOSS = 40,
TOTAL_EFFICIENCY = 41,
TOTAL_STATIC_EFFICIENCY = 42,
Comment on lines -1566 to -1569
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess these are never implemented?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or they were dropped in v7

EULERIAN_WORK = 43,
TOTAL_ENTHALPY_IN = 44,
FLOW_ANGLE_IN = 45,
FLOW_ANGLE_OUT = 46,
MASS_FLOW_IN = 47,
MASS_FLOW_OUT = 48,
PRESSURE_RATIO = 49,
ENTROPY_GENERATION = 50,
REFERENCE_GEOMETRY = 60, /*!< \brief Norm of displacements with respect to target geometry. */
REFERENCE_NODE = 61, /*!< \brief Objective function defined as the difference of a particular node respect to a reference position. */
Expand Down Expand Up @@ -1617,18 +1608,9 @@ static const MapType<std::string, ENUM_OBJECTIVE> Objective_Map = {
MakePair("SURFACE_SPECIES_0", SURFACE_SPECIES_0)
MakePair("SURFACE_SPECIES_VARIANCE", SURFACE_SPECIES_VARIANCE)
MakePair("CUSTOM_OBJFUNC", CUSTOM_OBJFUNC)
MakePair("TOTAL_EFFICIENCY", TOTAL_EFFICIENCY)
MakePair("TOTAL_STATIC_EFFICIENCY", TOTAL_STATIC_EFFICIENCY)
MakePair("TOTAL_PRESSURE_LOSS", TOTAL_PRESSURE_LOSS)
MakePair("EULERIAN_WORK", EULERIAN_WORK)
MakePair("TOTAL_ENTHALPY_IN", TOTAL_ENTHALPY_IN)
MakePair("FLOW_ANGLE_IN", FLOW_ANGLE_IN)
MakePair("FLOW_ANGLE_OUT", FLOW_ANGLE_OUT)
MakePair("MASS_FLOW_IN", MASS_FLOW_IN)
MakePair("MASS_FLOW_OUT", MASS_FLOW_OUT)
MakePair("PRESSURE_RATIO", PRESSURE_RATIO)
MakePair("ENTROPY_GENERATION", ENTROPY_GENERATION)
MakePair("KINETIC_ENERGY_LOSS", KINETIC_ENERGY_LOSS)
MakePair("REFERENCE_GEOMETRY", REFERENCE_GEOMETRY)
MakePair("REFERENCE_NODE", REFERENCE_NODE)
MakePair("VOLUME_FRACTION", VOLUME_FRACTION)
Expand All @@ -1637,46 +1619,6 @@ static const MapType<std::string, ENUM_OBJECTIVE> Objective_Map = {
MakePair("STRESS_PENALTY", STRESS_PENALTY)
};

/*!
* \brief Types of residual criteria equations
*/
enum ENUM_RESIDUAL {
RHO_RESIDUAL = 1, /*!< \brief Rho equation residual criteria equation. */
RHO_ENERGY_RESIDUAL = 2 /*!< \brief RhoE equation residual criteria equation. */
};
static const MapType<std::string, ENUM_RESIDUAL> Residual_Map = {
MakePair("RHO", RHO_RESIDUAL)
MakePair("RHO_ENERGY", RHO_ENERGY_RESIDUAL)
};

/*!
* \brief Types of residual criteria for structural problems
*/
enum ENUM_RESFEM {
RESFEM_RELATIVE = 1, /*!< \brief Relative criteria: Res/Res0. */
RESFEM_ABSOLUTE = 2 /*!< \brief Absolute criteria: abs(Res). */
};
static const MapType<std::string, ENUM_RESFEM> ResFem_Map = {
MakePair("RELATIVE", RESFEM_RELATIVE)
MakePair("ABSOLUTE", RESFEM_ABSOLUTE)
};

/*!
* \brief Types of sensitivities to compute
*/
enum ENUM_SENS {
SENS_GEOMETRY = 1, /*!< \brief Geometrical sensitivity. */
SENS_MACH = 2, /*!< \brief Mach number sensitivity. */
SENS_AOA = 3, /*!< \brief Angle of attack sensitivity. */
SENS_AOS = 4 /*!< \brief Angle of Sideslip sensitivity. */
};
static const MapType<std::string, ENUM_SENS> Sens_Map = {
MakePair("SENS_GEOMETRY", SENS_GEOMETRY)
MakePair("SENS_MACH", SENS_MACH)
MakePair("SENS_AOA", SENS_AOA)
MakePair("SENS_AOS", SENS_AOS)
};

/*!
* \brief Types of input file formats
*/
Expand Down Expand Up @@ -1823,32 +1765,6 @@ static const MapType<std::string, MG_CYCLE> MG_Cycle_Map = {
MakePair("FULLMG_CYCLE", FULLMG_CYCLE)
};

/*!
* \brief Type of solution output variables
*/
enum ENUM_OUTPUT_VARS {
DENSITY = 1, /*!< \brief Density. */
VEL_X = 2, /*!< \brief X-component of velocity. */
VEL_Y = 3, /*!< \brief Y-component of velocity. */
VEL_Z = 4, /*!< \brief Z-component of velocity. */
PRESSURE = 5, /*!< \brief Static pressure. */
MACH = 6, /*!< \brief Mach number. */
TEMPERATURE = 7, /*!< \brief Temperature. */
LAM_VISC = 8, /*!< \brief Laminar viscosity. */
EDDY_VISC = 9 /*!< \brief Eddy viscosity. */
};
static const MapType<std::string, ENUM_OUTPUT_VARS> Output_Vars_Map = {
MakePair("DENSITY", DENSITY)
MakePair("VEL_X", VEL_X)
MakePair("VEL_Y", VEL_Y)
MakePair("VEL_Z", VEL_Z)
MakePair("PRESSURE", PRESSURE)
MakePair("MACH", MACH)
MakePair("TEMPERATURE", TEMPERATURE)
MakePair("LAM_VISC", LAM_VISC)
MakePair("EDDY_VISC", EDDY_VISC)
};

/*!
* \brief Types of design parameterizations
*/
Expand Down
33 changes: 13 additions & 20 deletions Common/src/CConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3466,10 +3466,10 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i
nObjW = nObj;
}
else if(nObj>1) {
SU2_MPI::Error(string("When using more than one OBJECTIVE_FUNCTION, MARKER_MONITORING must be the same length or length 1.\n ") +
string("For multiple surfaces per objective, either use one objective or list the objective multiple times.\n") +
string("For multiple objectives per marker either use one marker or list the marker multiple times.\n")+
string("Similar rules apply for multi-objective optimization using OPT_OBJECTIVE rather than OBJECTIVE_FUNCTION."),
SU2_MPI::Error("When using more than one OBJECTIVE_FUNCTION, MARKER_MONITORING must be the same length or length 1.\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this string( wrapper can be removed in quite a few places in the CConfig.cpp

"For multiple surfaces per objective, either use one objective or list the objective multiple times.\n"
"For multiple objectives per marker either use one marker or list the marker multiple times.\n"
"Similar rules apply for multi-objective optimization using OPT_OBJECTIVE rather than OBJECTIVE_FUNCTION.",
CURRENT_FUNCTION);
}
}
Expand All @@ -3479,8 +3479,8 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i

if (nObjW<nObj) {
if (Weight_ObjFunc!= nullptr && nObjW>1) {
SU2_MPI::Error(string("The option OBJECTIVE_WEIGHT must either have the same length as OBJECTIVE_FUNCTION,\n") +
string("be lenght 1, or be deleted from the config file (equal weights will be applied)."), CURRENT_FUNCTION);
SU2_MPI::Error("The option OBJECTIVE_WEIGHT must either have the same length as OBJECTIVE_FUNCTION,\n"
"be lenght 1, or be deleted from the config file (equal weights will be applied).", CURRENT_FUNCTION);
}
Weight_ObjFunc = new su2double[nObj];
for (unsigned short iObj=0; iObj<nObj; iObj++)
Expand Down Expand Up @@ -3512,13 +3512,13 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i
case SURFACE_SPECIES_VARIANCE:
case CUSTOM_OBJFUNC:
if (Kind_ObjFunc[iObj] != Obj_0) {
SU2_MPI::Error(string("The following objectives can only be used for the first surface in a multi-objective \n")+
string("problem or as a single objective applied to multiple monitoring markers:\n")+
string("INVERSE_DESIGN_PRESSURE, INVERSE_DESIGN_HEATFLUX, THRUST_COEFFICIENT, TORQUE_COEFFICIENT\n")+
string("FIGURE_OF_MERIT, SURFACE_TOTAL_PRESSURE, SURFACE_STATIC_PRESSURE, SURFACE_MASSFLOW\n")+
string("SURFACE_UNIFORMITY, SURFACE_SECONDARY, SURFACE_MOM_DISTORTION, SURFACE_SECOND_OVER_UNIFORM\n")+
string("SURFACE_PRESSURE_DROP, SURFACE_STATIC_TEMPERATURE, SURFACE_SPECIES_0\n")+
string("SURFACE_SPECIES_VARIANCE, CUSTOM_OBJFUNC.\n"), CURRENT_FUNCTION);
SU2_MPI::Error("The following objectives can only be used for the first surface in a multi-objective \n"
"problem or as a single objective applied to multiple monitoring markers:\n"
"INVERSE_DESIGN_PRESSURE, INVERSE_DESIGN_HEATFLUX, THRUST_COEFFICIENT, TORQUE_COEFFICIENT\n"
"FIGURE_OF_MERIT, SURFACE_TOTAL_PRESSURE, SURFACE_STATIC_PRESSURE, SURFACE_MASSFLOW\n"
"SURFACE_UNIFORMITY, SURFACE_SECONDARY, SURFACE_MOM_DISTORTION, SURFACE_SECOND_OVER_UNIFORM\n"
"SURFACE_PRESSURE_DROP, SURFACE_STATIC_TEMPERATURE, SURFACE_SPECIES_0\n"
"SURFACE_SPECIES_VARIANCE, CUSTOM_OBJFUNC.\n", CURRENT_FUNCTION);
}
break;
default:
Expand Down Expand Up @@ -8203,15 +8203,8 @@ string CConfig::GetObjFunc_Extension(string val_filename) const {
case SURFACE_SPECIES_VARIANCE: AdjExt = "_specvar"; break;
case SURFACE_MACH: AdjExt = "_mach"; break;
case CUSTOM_OBJFUNC: AdjExt = "_custom"; break;
case KINETIC_ENERGY_LOSS: AdjExt = "_ke"; break;
case TOTAL_PRESSURE_LOSS: AdjExt = "_pl"; break;
case FLOW_ANGLE_OUT: AdjExt = "_fao"; break;
case FLOW_ANGLE_IN: AdjExt = "_fai"; break;
case TOTAL_EFFICIENCY: AdjExt = "_teff"; break;
case TOTAL_STATIC_EFFICIENCY: AdjExt = "_tseff"; break;
case EULERIAN_WORK: AdjExt = "_ew"; break;
case MASS_FLOW_IN: AdjExt = "_mfi"; break;
case MASS_FLOW_OUT: AdjExt = "_mfo"; break;
case ENTROPY_GENERATION: AdjExt = "_entg"; break;
case REFERENCE_GEOMETRY: AdjExt = "_refgeom"; break;
case REFERENCE_NODE: AdjExt = "_refnode"; break;
Expand Down
5 changes: 0 additions & 5 deletions SU2_CFD/include/output/CElasticityOutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ class CElasticityOutput final: public COutput {
*/
CElasticityOutput(CConfig *config, unsigned short nDim);

/*!
* \brief Destructor of the class.
*/
~CElasticityOutput(void) override;

/*!
* \brief Load the history output field values
* \param[in] config - Definition of the particular problem.
Expand Down
7 changes: 7 additions & 0 deletions SU2_CFD/include/output/CFlowOutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ class CFlowOutput : public CFVMOutput{
*/
void Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *geometry, const CConfig *config);

/*!
* \brief Set the values of the rotating frame coefficients (CT, CQ and CMerit).
* \param[in] config - Definition of the particular problem.
* \param[in] solver - The container holding all solution data.
*/
virtual void SetComboAndCustomObjectives(CConfig *config, CSolver **solver);

/*!
* \brief Compute value of the Q criteration for vortex idenfitication
* \param[in] VelocityGradient - Velocity gradients
Expand Down
5 changes: 0 additions & 5 deletions SU2_CFD/include/output/CHeatOutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ class CHeatOutput final: public CFVMOutput {
*/
CHeatOutput(CConfig *config, unsigned short nDim);

/*!
* \brief Destructor of the class.
*/
~CHeatOutput(void) override;

/*!
* \brief Set the available history output fields
* \param[in] config - Definition of the particular problem.
Expand Down
10 changes: 2 additions & 8 deletions SU2_CFD/include/solvers/CEulerSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,9 @@ class CEulerSolver : public CFVMFlowSolverBase<CEulerVariable, ENUM_REGIME::COMP
* \author H. Kline
* \brief Compute weighted-sum "combo" objective output
* \param[in] config - Definition of the particular problem.
* \param[in] solver - Container vector with all the solutions.
*/
void Evaluate_ObjFunc(const CConfig *config) override;
void Evaluate_ObjFunc(const CConfig *config, CSolver **solver) override;

/*!
* \brief Impose the far-field boundary condition using characteristics.
Expand Down Expand Up @@ -807,13 +808,6 @@ class CEulerSolver : public CFVMFlowSolverBase<CEulerVariable, ENUM_REGIME::COMP
*/
inline su2double GetTotal_CNearFieldOF() const final { return Total_CNearFieldOF; }

/*!
* \author H. Kline
* \brief Add to the value of the total 'combo' objective.
* \param[in] val_obj - Value of the contribution to the 'combo' objective.
*/
inline void AddTotal_ComboObj(su2double val_obj) final {Total_ComboObj +=val_obj;}

/*!
* \brief Set the value of the Aero drag.
* \param[in] val_cequivarea - Value of the aero drag.
Expand Down
26 changes: 12 additions & 14 deletions SU2_CFD/include/solvers/CFEASolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class CFEASolver : public CSolver {
su2double Total_OFDiscreteness; /*!< \brief Total Objective Function: Discreteness (topology optimization). */
su2double Total_OFCompliance; /*!< \brief Total Objective Function: Compliance (topology optimization). */
su2double Total_OFStressPenalty; /*!< \brief Total Objective Function: Stress penalty. */
su2double ObjFunc;

su2double Global_OFRefGeom; /*!< \brief Global Objective Function (added over time steps): Reference Geometry. */
su2double Global_OFRefNode; /*!< \brief Global Objective Function (added over time steps): Reference Node. */
Expand Down Expand Up @@ -556,36 +555,35 @@ class CFEASolver : public CSolver {
/*!
* \brief Compute the objective function.
* \param[in] config - Definition of the problem.
* \param[in] solver - Container vector with all the solutions.
*/
inline void Evaluate_ObjFunc(const CConfig *config) final {
ObjFunc = 0.0;
void Evaluate_ObjFunc(const CConfig *config, CSolver**) final {
Total_ComboObj = 0.0;
switch (config->GetKind_ObjFunc()) {
case REFERENCE_GEOMETRY:
ObjFunc = GetTotal_OFRefGeom();
Total_ComboObj = GetTotal_OFRefGeom();
break;
case REFERENCE_NODE:
ObjFunc = GetTotal_OFRefNode();
Total_ComboObj = GetTotal_OFRefNode();
break;
case TOPOL_COMPLIANCE:
ObjFunc = GetTotal_OFCompliance();
Total_ComboObj = GetTotal_OFCompliance();
break;
case VOLUME_FRACTION:
ObjFunc = GetTotal_OFVolFrac();
Total_ComboObj = GetTotal_OFVolFrac();
break;
case TOPOL_DISCRETENESS:
ObjFunc = GetTotal_OFDiscreteness();
Total_ComboObj = GetTotal_OFDiscreteness();
break;
case STRESS_PENALTY:
ObjFunc = GetTotal_OFStressPenalty();
Total_ComboObj = GetTotal_OFStressPenalty();
break;
case CUSTOM_OBJFUNC:
Total_ComboObj = Total_Custom_ObjFunc;
break;
}
}

/*!
* \brief Provide the total "combo" objective (weighted sum of other values).
*/
inline su2double GetTotal_ComboObj() const final { return ObjFunc; }

/*!
* \brief Determines whether there is an element-based file or not.
* \return Bool that defines whether the solution has an element-based file or not
Expand Down
41 changes: 0 additions & 41 deletions SU2_CFD/include/solvers/CFVMFlowSolverBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ class CFVMFlowSolverBase : public CSolver {
su2double AeroCoeffForceRef = 1.0; /*!< \brief Reference force for aerodynamic coefficients. */
su2double DynamicPressureRef = 1.0; /*!< \brief Reference dynamic pressure. */

su2double InverseDesign = 0.0; /*!< \brief Inverse design functional for each boundary. */
su2double Total_ComboObj = 0.0; /*!< \brief Total 'combo' objective for all monitored boundaries */
su2double Total_Custom_ObjFunc = 0.0; /*!< \brief Total custom objective function for all the boundaries. */
su2double Total_CpDiff = 0.0; /*!< \brief Total Equivalent Area coefficient for all the boundaries. */
su2double Total_HeatFluxDiff = 0.0; /*!< \brief Total Equivalent Area coefficient for all the boundaries. */
su2double Total_CEquivArea = 0.0; /*!< \brief Total Equivalent Area coefficient for all the boundaries. */
Expand Down Expand Up @@ -1995,20 +1992,6 @@ class CFVMFlowSolverBase : public CSolver {
*/
inline void SetTotal_CNearFieldOF(su2double val_cnearfieldpress) final { Total_CNearFieldOF = val_cnearfieldpress; }

/*!
* \author H. Kline
* \brief Set the total "combo" objective (weighted sum of other values).
* \param[in] ComboObj - Value of the combined objective.
*/
inline void SetTotal_ComboObj(su2double ComboObj) final { Total_ComboObj = ComboObj; }

/*!
* \author H. Kline
* \brief Provide the total "combo" objective (weighted sum of other values).
* \return Value of the "combo" objective values.
*/
inline su2double GetTotal_ComboObj() const final { return Total_ComboObj; }

/*!
* \brief Provide the total (inviscid + viscous) non dimensional Equivalent Area coefficient.
* \return Value of the Equivalent Area coefficient (inviscid + viscous contribution).
Expand All @@ -2027,24 +2010,6 @@ class CFVMFlowSolverBase : public CSolver {
*/
inline su2double GetTotal_CEquivArea() const final { return Total_CEquivArea; }

/*!
* \brief Set the value of the custom objective function.
* \param[in] val_Total_Custom_ObjFunc - Value of the total custom objective function.
* \param[in] val_weight - Value of the weight for the custom objective function.
*/
inline void SetTotal_Custom_ObjFunc(su2double val_total_custom_objfunc, su2double val_weight) final {
Total_Custom_ObjFunc = val_total_custom_objfunc * val_weight;
}

/*!
* \brief Add the value of the custom objective function.
* \param[in] val_Total_Custom_ObjFunc - Value of the total custom objective function.
* \param[in] val_weight - Value of the weight for the custom objective function.
*/
inline void AddTotal_Custom_ObjFunc(su2double val_total_custom_objfunc, su2double val_weight) final {
Total_Custom_ObjFunc += val_total_custom_objfunc * val_weight;
}

/*!
* \brief Provide the total heat load.
* \return Value of the heat load (viscous contribution).
Expand All @@ -2069,12 +2034,6 @@ class CFVMFlowSolverBase : public CSolver {
*/
inline void SetTotal_MaxHeatFlux(su2double val_Total_MaxHeat) final { Total_MaxHeat = val_Total_MaxHeat; }

/*!
* \brief Provide the total custom objective function.
* \return Value of the custom objective function.
*/
inline su2double GetTotal_Custom_ObjFunc() const final { return Total_Custom_ObjFunc; }

/*!
* \brief Provide the Pressure coefficient.
* \param[in] val_marker - Surface marker where the coefficient is computed.
Expand Down
Loading