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
Merged
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
[submodule "externals/opdi"]
path = externals/opdi
url = https://github.com/SciCompKL/OpDiLib
[submodule "externals/mel"]
path = externals/mel
url = https://github.com/pcarruscag/MEL.git
Comment on lines +21 to +23
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, nice to have this modularized away (also with a compatible license 😉 )

14 changes: 6 additions & 8 deletions Common/include/CConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class CConfig {
su2double EA_ScaleFactor; /*!< \brief Equivalent Area scaling factor */
su2double AdjointLimit; /*!< \brief Adjoint variable limit */
string* ConvField; /*!< \brief Field used for convergence check.*/
string ConvCriteria; // This option is deprecated. After a grace period until 7.2.0 the usage warning should become an error.

string* WndConvField; /*!< \brief Function where to apply the windowed convergence criteria for the time average of the unsteady (single zone) flow problem. */
unsigned short nConvField; /*!< \brief Number of fields used to monitor convergence.*/
Expand Down Expand Up @@ -436,7 +435,7 @@ class CConfig {
Unst_CFL; /*!< \brief Unsteady CFL number. */

bool ReorientElements; /*!< \brief Flag for enabling element reorientation. */
bool AddIndNeighbor; /*!< \brief Include indirect neighbor in the agglomeration process. */
string CustomObjFunc; /*!< \brief User-defined objective function. */
unsigned short nDV, /*!< \brief Number of design variables. */
nObj, nObjW; /*! \brief Number of objective functions. */
unsigned short* nDV_Value; /*!< \brief Number of values for each design variable (might be different than 1 if we allow arbitrary movement). */
Expand Down Expand Up @@ -5177,6 +5176,11 @@ class CConfig {
*/
void SetWeight_ObjFunc(unsigned short val_obj, su2double val) { Weight_ObjFunc[val_obj] = val; }

/*!
* \brief Get the user expression for the custom objective function.
*/
const string& GetCustomObjFunc() const { return CustomObjFunc; }

/*!
* \brief Get the kind of sensitivity smoothing technique.
* \return Kind of sensitivity smoothing technique.
Expand Down Expand Up @@ -5469,12 +5473,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
108 changes: 12 additions & 96 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 Expand Up @@ -2352,35 +2268,35 @@ class COptionBase {
private:
std::vector<std::string> value;
public:
COptionBase() {};
virtual ~COptionBase() = 0;
virtual ~COptionBase() = default;

const std::vector<std::string>& GetValue() const {return value;}

virtual std::string SetValue(std::vector<std::string> value){this->value = value; return "";}
std::vector<std::string> GetValue() {return value;}
virtual std::string SetValue(const std::vector<std::string>& val) {
value = val;
return "";
}
virtual void SetDefault() = 0;

std::string optionCheckMultipleValues(std::vector<std::string> & option_value, std::string type_id, std::string option_name) {
std::string optionCheckMultipleValues(const std::vector<std::string>& option_value,
std::string type_id, const std::string& option_name) {
if (option_value.size() != 1) {
std::string newString;
newString.append(option_name);
std::string newString(option_name);
newString.append(": multiple values for type ");
newString.append(type_id);
return newString;
}
return "";
}

std::string badValue(std::vector<std::string> & option_value, std::string type_id, std::string option_name) {
std::string newString;
newString.append(option_name);
std::string badValue(std::string type_id, const std::string& option_name) {
std::string newString(option_name);
newString.append(": improper option value for type ");
newString.append(type_id);
return newString;
}
};

inline COptionBase::~COptionBase() {}

#ifdef ENABLE_MAPS
#include "option_structure.inl"
#endif
Loading