Skip to content

Commit 9fd4ee0

Browse files
committed
working primal version
1 parent 67296cb commit 9fd4ee0

18 files changed

Lines changed: 111 additions & 45 deletions

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818
[submodule "externals/opdi"]
1919
path = externals/opdi
2020
url = https://github.com/SciCompKL/OpDiLib
21+
[submodule "externals/mel"]
22+
path = externals/mel
23+
url = https://github.com/pcarruscag/MEL.git

Common/include/CConfig.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ class CConfig {
8080
su2double EA_ScaleFactor; /*!< \brief Equivalent Area scaling factor */
8181
su2double AdjointLimit; /*!< \brief Adjoint variable limit */
8282
string* ConvField; /*!< \brief Field used for convergence check.*/
83-
string ConvCriteria; // This option is deprecated. After a grace period until 7.2.0 the usage warning should become an error.
8483

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

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

5179+
/*!
5180+
* \brief Get the user expression for the custom objective function.
5181+
*/
5182+
const string& GetCustomObjFunc() const { return CustomObjFunc; }
5183+
51805184
/*!
51815185
* \brief Get the kind of sensitivity smoothing technique.
51825186
* \return Kind of sensitivity smoothing technique.

Common/src/CConfig.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,10 +1925,12 @@ void CConfig::SetConfig_Options() {
19251925

19261926
/*!\brief OBJECTIVE_WEIGHT \n DESCRIPTION: Adjoint problem boundary condition weights. Applies scaling factor to objective(s) \ingroup Config*/
19271927
addDoubleListOption("OBJECTIVE_WEIGHT", nObjW, Weight_ObjFunc);
1928-
/*!\brief OBJECTIVE_FUNCTION
1929-
* \n DESCRIPTION: Adjoint problem boundary condition \n OPTIONS: see \link Objective_Map \endlink \n DEFAULT: DRAG_COEFFICIENT \ingroup Config*/
1928+
/*!\brief OBJECTIVE_FUNCTION \n DESCRIPTION: Adjoint problem boundary condition \n OPTIONS: see \link Objective_Map \endlink \n DEFAULT: DRAG_COEFFICIENT \ingroup Config*/
19301929
addEnumListOption("OBJECTIVE_FUNCTION", nObj, Kind_ObjFunc, Objective_Map);
19311930

1931+
/*!\brief CUSTOM_OBJFUNC \n DESCRIPTION: User-provided definition of a custom objective function. \ingroup Config*/
1932+
addStringOption("CUSTOM_OBJFUNC", CustomObjFunc, "");
1933+
19321934
/* DESCRIPTION: parameter for the definition of a complex objective function */
19331935
addDoubleOption("DCD_DCL_VALUE", dCD_dCL, 0.0);
19341936
/* DESCRIPTION: parameter for the definition of a complex objective function */
@@ -3527,6 +3529,11 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i
35273529
}
35283530
}
35293531

3532+
if (Kind_ObjFunc[0] == CUSTOM_OBJFUNC && CustomObjFunc.empty()) {
3533+
SU2_MPI::Error("The expression for the custom objective function was not set.\n"
3534+
"For example, CUSTOM_OBJFUNC= LIFT/DRAG", CURRENT_FUNCTION);
3535+
}
3536+
35303537
/*--- Check for unsteady problem ---*/
35313538

35323539
if ((TimeMarching == TIME_MARCHING::TIME_STEPPING ||

SU2_CFD/include/output/CFlowOutput.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,6 @@ class CFlowOutput : public CFVMOutput{
182182
*/
183183
void Set_NearfieldInverseDesign(CSolver *solver, const CGeometry *geometry, const CConfig *config);
184184

185-
/*!
186-
* \brief Set the values of the rotating frame coefficients (CT, CQ and CMerit).
187-
* \param[in] config - Definition of the particular problem.
188-
* \param[in] solver - The container holding all solution data.
189-
*/
190-
virtual void SetComboAndCustomObjectives(CConfig *config, CSolver **solver);
191-
192185
/*!
193186
* \brief Compute value of the Q criteration for vortex idenfitication
194187
* \param[in] VelocityGradient - Velocity gradients

SU2_CFD/include/output/COutput.hpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,21 @@ class COutput {
371371
* \param[in] field - Name of the field
372372
* \return Value of the field
373373
*/
374-
su2double GetHistoryFieldValue(string field){
374+
su2double GetHistoryFieldValue(const string& field) const {
375375
return historyOutput_Map.at(field).value;
376376
}
377377

378-
su2double GetHistoryFieldValuePerSurface(string field, unsigned short iMarker){
378+
su2double GetHistoryFieldValuePerSurface(const string& field, unsigned short iMarker) const {
379379
return historyOutputPerSurface_Map.at(field)[iMarker].value;
380380
}
381381

382+
/*!
383+
* \brief Evaluate a custom expression of the history values.
384+
* \param[in] expression - Some user-defined math with the history field names as variables.
385+
* \return Result of the expression
386+
*/
387+
su2double ComputeCustomHistoryValue(const string& expression) const;
388+
382389
/*!
383390
* \brief Get a vector with all output fields in a particular group
384391
* \param groupname - Name of the history group
@@ -398,15 +405,15 @@ class COutput {
398405
* \brief Get the list of all output fields
399406
* \return Vector container all output fields
400407
*/
401-
vector<string> GetHistoryOutput_List(){
408+
const vector<string>& GetHistoryOutput_List() const {
402409
return historyOutput_List;
403410
}
404411

405412
/*!
406413
* \brief Get the map containing all output fields
407414
* \return Map containing all output fields
408415
*/
409-
map<string, HistoryOutputField> GetHistoryFields(){
416+
const map<string, HistoryOutputField>& GetHistoryFields() const {
410417
return historyOutput_Map;
411418
}
412419

@@ -683,6 +690,15 @@ class COutput {
683690
*/
684691
void AllocateDataSorters(CConfig *config, CGeometry *geometry);
685692

693+
/*!
694+
* \brief Computes the custom and combo objectives.
695+
* \note To be called after all other history outputs are set.
696+
* \param[in] idxSol - Index of the main solver.
697+
* \param[in] config - Definition of the particular problem.
698+
* \param[in] solver - The container holding all solution data.
699+
*/
700+
void SetCustomAndComboObjectives(int idxSol, const CConfig *config, CSolver **solver);
701+
686702
/*--------------------------------- Virtual functions ---------------------------------------- */
687703
public:
688704

SU2_CFD/src/drivers/CDiscAdjMultizoneDriver.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,22 +729,18 @@ void CDiscAdjMultizoneDriver::SetObjFunction(RECORDING kind_recording) {
729729
}
730730

731731
direct_output[iZone]->SetHistory_Output(geometry, solvers, config);
732-
733-
solvers[FLOW_SOL]->Evaluate_ObjFunc(config, solvers);
734732
ObjFunc += solvers[FLOW_SOL]->GetTotal_ComboObj();
735733
break;
736734

737735
case MAIN_SOLVER::DISC_ADJ_HEAT:
738736
solvers[HEAT_SOL]->Heat_Fluxes(geometry, solvers, config);
739737
direct_output[iZone]->SetHistory_Output(geometry, solvers, config);
740-
solvers[HEAT_SOL]->Evaluate_ObjFunc(config, solvers);
741738
ObjFunc += solvers[HEAT_SOL]->GetTotal_ComboObj();
742739
break;
743740

744741
case MAIN_SOLVER::DISC_ADJ_FEM:
745742
solvers[FEA_SOL]->Postprocessing(geometry, config, numerics_container[iZone][INST_0][MESH_0][FEA_SOL], true);
746743
direct_output[iZone]->SetHistory_Output(geometry, solvers, config);
747-
solvers[FEA_SOL]->Evaluate_ObjFunc(config, solvers);
748744
ObjFunc += solvers[FEA_SOL]->GetTotal_ComboObj();
749745
break;
750746

SU2_CFD/src/drivers/CDiscAdjSinglezoneDriver.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,10 @@ void CDiscAdjSinglezoneDriver::SetObjFunction(){
355355
case MAIN_SOLVER::DISC_ADJ_EULER: case MAIN_SOLVER::DISC_ADJ_NAVIER_STOKES: case MAIN_SOLVER::DISC_ADJ_RANS:
356356
case MAIN_SOLVER::DISC_ADJ_FEM_EULER: case MAIN_SOLVER::DISC_ADJ_FEM_NS: case MAIN_SOLVER::DISC_ADJ_FEM_RANS:
357357

358-
direct_output->SetHistory_Output(geometry, solver, config, config->GetTimeIter(),
359-
config->GetOuterIter(), config->GetInnerIter());
360-
361358
/*--- Surface based obj. function ---*/
362359

363-
solver[FLOW_SOL]->Evaluate_ObjFunc(config, solver);
360+
direct_output->SetHistory_Output(geometry, solver, config, config->GetTimeIter(),
361+
config->GetOuterIter(), config->GetInnerIter());
364362
ObjFunc += solver[FLOW_SOL]->GetTotal_ComboObj();
365363

366364
/*--- These calls to be moved to a generic framework at a next stage ---*/
@@ -390,7 +388,6 @@ void CDiscAdjSinglezoneDriver::SetObjFunction(){
390388
case MAIN_SOLVER::DISC_ADJ_HEAT:
391389
direct_output->SetHistory_Output(geometry, solver, config, config->GetTimeIter(),
392390
config->GetOuterIter(), config->GetInnerIter());
393-
solver[HEAT_SOL]->Evaluate_ObjFunc(config, solver);
394391
ObjFunc = solver[HEAT_SOL]->GetTotal_ComboObj();
395392
break;
396393

@@ -399,7 +396,6 @@ void CDiscAdjSinglezoneDriver::SetObjFunction(){
399396

400397
direct_output->SetHistory_Output(geometry, solver, config, config->GetTimeIter(),
401398
config->GetOuterIter(), config->GetInnerIter());
402-
solver[FEA_SOL]->Evaluate_ObjFunc(config, solver);
403399
ObjFunc = solver[FEA_SOL]->GetTotal_ComboObj();
404400
break;
405401

SU2_CFD/src/output/CElasticityOutput.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ void CElasticityOutput::LoadHistoryData(CConfig *config, CGeometry *geometry, CS
146146
SetHistoryOutputValue("VOLUME_FRACTION", fea_solver->GetTotal_OFVolFrac());
147147
SetHistoryOutputValue("TOPOL_DISCRETENESS", fea_solver->GetTotal_OFDiscreteness());
148148
}
149+
/*--- Keep this as last, since it uses the history values that were set. ---*/
150+
SetCustomAndComboObjectives(FEA_SOL, config, solver);
149151

150152
}
151153

@@ -154,8 +156,6 @@ void CElasticityOutput::SetHistoryOutputFields(CConfig *config){
154156
AddHistoryOutput("LINSOL_ITER", "LinSolIter", ScreenOutputFormat::INTEGER, "LINSOL", "Number of iterations of the linear solver.");
155157
AddHistoryOutput("LINSOL_RESIDUAL", "LinSolRes", ScreenOutputFormat::FIXED, "LINSOL", "Residual of the linear solver.");
156158

157-
// Residuals
158-
159159
AddHistoryOutput("RMS_UTOL", "rms[U]", ScreenOutputFormat::FIXED, "RMS_RES", "", HistoryFieldType::RESIDUAL);
160160
AddHistoryOutput("RMS_RTOL", "rms[R]", ScreenOutputFormat::FIXED, "RMS_RES", "", HistoryFieldType::RESIDUAL);
161161
AddHistoryOutput("RMS_ETOL", "rms[E]", ScreenOutputFormat::FIXED, "RMS_RES", "", HistoryFieldType::RESIDUAL);
@@ -182,6 +182,7 @@ void CElasticityOutput::SetHistoryOutputFields(CConfig *config){
182182
AddHistoryOutput("VOLUME_FRACTION", "VolFrac", ScreenOutputFormat::SCIENTIFIC, "STRUCT_COEFF", "", HistoryFieldType::COEFFICIENT);
183183
AddHistoryOutput("TOPOL_DISCRETENESS", "TopDisc", ScreenOutputFormat::SCIENTIFIC, "STRUCT_COEFF", "", HistoryFieldType::COEFFICIENT);
184184
}
185+
AddHistoryOutput("COMBO", "ComboObj", ScreenOutputFormat::SCIENTIFIC, "COMBO", "Combined obj. function value.", HistoryFieldType::COEFFICIENT);
185186

186187
}
187188

SU2_CFD/src/output/CFlowCompOutput.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,13 @@ void CFlowCompOutput::LoadHistoryData(CConfig *config, CGeometry *geometry, CSol
480480
Set_CpInverseDesign(flow_solver, geometry, config);
481481

482482
/*--- Set nearfield diff fields ---*/
483+
483484
if (config->GetEquivArea()) Set_NearfieldInverseDesign(flow_solver, geometry, config);
484485

486+
/*--- Keep this as last, since it uses the history values that were set. ---*/
487+
488+
SetCustomAndComboObjectives(FLOW_SOL, config, solver);
489+
485490
}
486491

487492
bool CFlowCompOutput::SetInit_Residuals(const CConfig *config){

SU2_CFD/src/output/CFlowIncOutput.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ void CFlowIncOutput::LoadHistoryData(CConfig *config, CGeometry *geometry, CSolv
298298

299299
SetRotatingFrameCoefficients(config, flow_solver);
300300

301+
/*--- Keep this as last, since it uses the history values that were set. ---*/
302+
303+
SetCustomAndComboObjectives(FLOW_SOL, config, solver);
304+
301305
}
302306

303307
void CFlowIncOutput::SetVolumeOutputFields(CConfig *config){

0 commit comments

Comments
 (0)