Skip to content

Commit 7932a50

Browse files
committed
encapsulate OF computation and selection of the FEA solver
1 parent 609e362 commit 7932a50

13 files changed

Lines changed: 102 additions & 224 deletions

SU2_CFD/include/solvers/CEulerSolver.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ class CEulerSolver : public CFVMFlowSolverBase<CEulerVariable, COMPRESSIBLE> {
474474
* \brief Compute weighted-sum "combo" objective output
475475
* \param[in] config - Definition of the particular problem.
476476
*/
477-
void Evaluate_ObjFunc(CConfig *config) override;
477+
void Evaluate_ObjFunc(const CConfig *config) override;
478478

479479
/*!
480480
* \brief Impose the far-field boundary condition using characteristics.

SU2_CFD/include/solvers/CFEASolver.hpp

Lines changed: 65 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class CFEASolver : public CSolver {
6969
su2double Total_OFVolFrac; /*!< \brief Total Objective Function: Volume fraction (topology optimization). */
7070
su2double Total_OFDiscreteness; /*!< \brief Total Objective Function: Discreteness (topology optimization). */
7171
su2double Total_OFCompliance; /*!< \brief Total Objective Function: Compliance (topology optimization). */
72+
su2double ObjFunc;
7273

7374
su2double Global_OFRefGeom; /*!< \brief Global Objective Function (added over time steps): Reference Geometry. */
7475
su2double Global_OFRefNode; /*!< \brief Global Objective Function (added over time steps): Reference Node. */
@@ -198,6 +199,34 @@ class CFEASolver : public CSolver {
198199
su2double der,
199200
su2double der_avg) const;
200201

202+
/*!
203+
* \brief Compute the objective function for a reference geometry
204+
* \param[in] geometry - Geometrical definition of the problem.
205+
* \param[in] config - Definition of the particular problem.
206+
*/
207+
void Compute_OFRefGeom(CGeometry *geometry, const CConfig *config);
208+
209+
/*!
210+
* \brief Compute the objective function for a reference node
211+
* \param[in] geometry - Geometrical definition of the problem.
212+
* \param[in] config - Definition of the particular problem.
213+
*/
214+
void Compute_OFRefNode(CGeometry *geometry, const CConfig *config);
215+
216+
/*!
217+
* \brief Compute the objective function for a volume fraction
218+
* \param[in] geometry - Geometrical definition of the problem.
219+
* \param[in] config - Definition of the particular problem.
220+
*/
221+
void Compute_OFVolFrac(CGeometry *geometry, const CConfig *config);
222+
223+
/*!
224+
* \brief Compute the compliance objective function
225+
* \param[in] geometry - Geometrical definition of the problem.
226+
* \param[in] config - Definition of the particular problem.
227+
*/
228+
void Compute_OFCompliance(CGeometry *geometry, const CConfig *config);
229+
201230
public:
202231
/*!
203232
* \brief Constructor of the class.
@@ -245,20 +274,6 @@ class CFEASolver : public CSolver {
245274
CConfig *config,
246275
unsigned long TimeIter) override;
247276

248-
/*!
249-
* \brief Compute the time step for solving the FEM equations.
250-
* \param[in] geometry - Geometrical definition of the problem.
251-
* \param[in] solver_container - Container vector with all the solutions.
252-
* \param[in] config - Definition of the particular problem.
253-
* \param[in] iMesh - Index of the mesh in multigrid computations.
254-
* \param[in] Iteration - Index of the current iteration.
255-
*/
256-
inline void SetTime_Step(CGeometry *geometry,
257-
CSolver **solver_container,
258-
CConfig *config,
259-
unsigned short iMesh,
260-
unsigned long Iteration) override { }
261-
262277
/*!
263278
* \brief Get the value of the reference coordinate to set on the element structure.
264279
* \param[in] geometry - Geometrical definition of the problem.
@@ -508,15 +523,14 @@ class CFEASolver : public CSolver {
508523
/*!
509524
* \brief Postprocessing.
510525
* \param[in] geometry - Geometrical definition of the problem.
511-
* \param[in] solver_container - Container vector with all the solutions.
512526
* \param[in] config - Definition of the particular problem.
513-
* \param[in] iMesh - Index of the mesh in multigrid computations.
527+
* \param[in] numerics - Implementation of numerical method.
528+
* \param[in] of_comp_mode - Mode to compute just the objective function.
514529
*/
515-
void Postprocessing(CGeometry *geometry,
516-
CSolver **solver_container,
517-
CConfig *config,
518-
CNumerics **numerics,
519-
unsigned short iMesh) final;
530+
inline void Postprocessing(CGeometry *geometry,
531+
CConfig *config,
532+
CNumerics **numerics,
533+
bool of_comp_mode) final;
520534

521535
/*!
522536
* \brief Routine to solve the Jacobian-Residual linearized system.
@@ -565,6 +579,36 @@ class CFEASolver : public CSolver {
565579
*/
566580
inline su2double GetTotal_OFCompliance(void) const final { return Total_OFCompliance; }
567581

582+
/*!
583+
* \brief Compute the objective function.
584+
* \param[in] config - Definition of the problem.
585+
*/
586+
inline void Evaluate_ObjFunc(const CConfig *config) final {
587+
ObjFunc = 0.0;
588+
switch (config->GetKind_ObjFunc()) {
589+
case REFERENCE_GEOMETRY:
590+
ObjFunc = GetTotal_OFRefGeom();
591+
break;
592+
case REFERENCE_NODE:
593+
ObjFunc = GetTotal_OFRefNode();
594+
break;
595+
case TOPOL_COMPLIANCE:
596+
ObjFunc = GetTotal_OFCompliance();
597+
break;
598+
case VOLUME_FRACTION:
599+
ObjFunc = GetTotal_OFVolFrac();
600+
break;
601+
case TOPOL_DISCRETENESS:
602+
ObjFunc = GetTotal_OFDiscreteness();
603+
break;
604+
}
605+
}
606+
607+
/*!
608+
* \brief Provide the total "combo" objective (weighted sum of other values).
609+
*/
610+
inline su2double GetTotal_ComboObj() const final { return ObjFunc; }
611+
568612
/*!
569613
* \brief Determines whether there is an element-based file or not.
570614
* \return Bool that defines whether the solution has an element-based file or not
@@ -652,43 +696,13 @@ class CFEASolver : public CSolver {
652696
*/
653697
void SetAitken_Relaxation(CGeometry *geometry, CConfig *config) final;
654698

655-
/*!
656-
* \brief Compute the objective function for a reference geometry
657-
* \param[in] geometry - Geometrical definition of the problem.
658-
* \param[in] config - Definition of the particular problem.
659-
*/
660-
void Compute_OFRefGeom(CGeometry *geometry, const CConfig *config) final;
661-
662-
/*!
663-
* \brief Compute the objective function for a reference node
664-
* \param[in] geometry - Geometrical definition of the problem.
665-
* \param[in] config - Definition of the particular problem.
666-
*/
667-
void Compute_OFRefNode(CGeometry *geometry, const CConfig *config) final;
668-
669-
/*!
670-
* \brief Compute the objective function for a volume fraction
671-
* \param[in] geometry - Geometrical definition of the problem.
672-
* \param[in] config - Definition of the particular problem.
673-
*/
674-
void Compute_OFVolFrac(CGeometry *geometry, const CConfig *config) final;
675-
676-
/*!
677-
* \brief Compute the compliance objective function
678-
* \param[in] geometry - Geometrical definition of the problem.
679-
* \param[in] config - Definition of the particular problem.
680-
*/
681-
void Compute_OFCompliance(CGeometry *geometry, const CConfig *config) final;
682-
683699
/*!
684700
* \brief Compute the penalty due to the stiffness increase
685701
* \param[in] geometry - Geometrical definition of the problem.
686-
* \param[in] solver_container - Container vector with all the solutions.
687702
* \param[in] numerics - Description of the numerical method.
688703
* \param[in] config - Definition of the particular problem.
689704
*/
690705
void Stiffness_Penalty(CGeometry *geometry,
691-
CSolver **solver_container,
692706
CNumerics **numerics_container,
693707
CConfig *config);
694708

SU2_CFD/include/solvers/CIncEulerSolver.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,6 @@ class CIncEulerSolver : public CFVMFlowSolverBase<CIncEulerVariable, INCOMPRESSI
213213
*/
214214
void SetMax_Eigenvalue(CGeometry *geometry, CConfig *config);
215215

216-
/*!
217-
* \author H. Kline
218-
* \brief Compute weighted-sum "combo" objective output
219-
* \param[in] config - Definition of the particular problem.
220-
*/
221-
void Evaluate_ObjFunc(CConfig *config) final;
222-
223216
/*!
224217
* \brief Impose the far-field boundary condition using characteristics.
225218
* \param[in] geometry - Geometrical definition of the problem.

SU2_CFD/include/solvers/CNSSolver.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class CNSSolver final : public CEulerSolver {
149149
* \brief Compute weighted-sum "combo" objective output
150150
* \param[in] config - Definition of the particular problem.
151151
*/
152-
void Evaluate_ObjFunc(CConfig *config) override;
152+
void Evaluate_ObjFunc(const CConfig *config) override;
153153

154154
/*!
155155
* \brief Impose a constant heat-flux condition at the wall.

SU2_CFD/include/solvers/CSolver.hpp

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -742,16 +742,15 @@ class CSolver {
742742
/*!
743743
* \brief A virtual member, overloaded.
744744
* \param[in] geometry - Geometrical definition of the problem.
745-
* \param[in] solver_container - Container vector with all the solutions.
746745
* \param[in] config - Definition of the particular problem.
747-
*
748-
* \param[in] iMesh - Index of the mesh in multigrid computations.
746+
* \param[in] numerics - Implementation of numerical method.
747+
* \param[in] of_comp_mode - Mode to compute just the objective function.
749748
*/
750749
inline virtual void Postprocessing(CGeometry *geometry,
751-
CSolver **solver_container,
752750
CConfig *config,
753751
CNumerics **numerics,
754-
unsigned short iMesh) { }
752+
bool of_comp_mode = false) { }
753+
755754
/*!
756755
* \brief A virtual member.
757756
* \param[in] geometry - Geometrical definition of the problem.
@@ -847,7 +846,7 @@ class CSolver {
847846
* \brief Compute weighted-sum "combo" objective output
848847
* \param[in] config - Definition of the particular problem.
849848
*/
850-
inline virtual void Evaluate_ObjFunc(CConfig *config) {};
849+
inline virtual void Evaluate_ObjFunc(const CConfig *config) {};
851850

852851
/*!
853852
* \brief A virtual member.
@@ -3593,38 +3592,6 @@ class CSolver {
35933592
unsigned short val_kind_solver,
35943593
unsigned short val_kind_marker) const;
35953594

3596-
/*!
3597-
* \brief A virtual member.
3598-
* \param[in] geometry - Geometrical definition of the problem.
3599-
* \param[in] config - Definition of the particular problem.
3600-
*/
3601-
inline virtual void Compute_OFRefGeom(CGeometry *geometry,
3602-
const CConfig *config) { }
3603-
3604-
/*!
3605-
* \brief A virtual member.
3606-
* \param[in] geometry - Geometrical definition of the problem.
3607-
* \param[in] config - Definition of the particular problem.
3608-
*/
3609-
inline virtual void Compute_OFRefNode(CGeometry *geometry,
3610-
const CConfig *config) { }
3611-
3612-
/*!
3613-
* \brief A virtual member.
3614-
* \param[in] geometry - Geometrical definition of the problem.
3615-
* \param[in] config - Definition of the particular problem.
3616-
*/
3617-
inline virtual void Compute_OFVolFrac(CGeometry *geometry,
3618-
const CConfig *config) { }
3619-
3620-
/*!
3621-
* \brief A virtual member.
3622-
* \param[in] geometry - Geometrical definition of the problem.
3623-
* \param[in] config - Definition of the particular problem.
3624-
*/
3625-
inline virtual void Compute_OFCompliance(CGeometry *geometry,
3626-
const CConfig *config) { }
3627-
36283595
/*!
36293596
* \brief A virtual member.
36303597
* \param[in] geometry - Geometrical definition of the problem.

SU2_CFD/src/drivers/CDiscAdjMultizoneDriver.cpp

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,10 @@ void CDiscAdjMultizoneDriver::SetObjFunction(unsigned short kind_recording) {
684684
case DISC_ADJ_HEAT:
685685
solvers[HEAT_SOL]->Heat_Fluxes(geometry, solvers, config);
686686
break;
687+
688+
case DISC_ADJ_FEM:
689+
solvers[FEA_SOL]->Postprocessing(geometry, config, numerics_container[iZone][INST_0][MESH_0][FEA_SOL], true);
690+
break;
687691
}
688692
}
689693

@@ -693,14 +697,9 @@ void CDiscAdjMultizoneDriver::SetObjFunction(unsigned short kind_recording) {
693697

694698
auto config = config_container[iZone];
695699
auto solvers = solver_container[iZone][INST_0][MESH_0];
696-
auto geometry = geometry_container[iZone][INST_0][MESH_0];
697-
698-
/*--- Not-per-surface objective functions (shall not be included above) ---*/
699700

700701
const auto Weight_ObjFunc = config->GetWeight_ObjFunc(0);
701702

702-
bool ObjectiveNotCovered = false;
703-
704703
switch (config->GetKind_Solver()) {
705704

706705
case DISC_ADJ_EULER: case DISC_ADJ_NAVIER_STOKES: case DISC_ADJ_RANS:
@@ -717,67 +716,29 @@ void CDiscAdjMultizoneDriver::SetObjFunction(unsigned short kind_recording) {
717716
}
718717
}
719718
ObjFunc += val*Weight_ObjFunc;
720-
721-
/*--- This is not ideal... ---*/
722-
ObjectiveNotCovered = (val==0.0);
723719
break;
724720
}
725721
case DISC_ADJ_HEAT:
726722
{
727723
switch(config->GetKind_ObjFunc()) {
728-
729-
// Not yet covered by new output structure. Be careful these use MARKER_MONITORING.
730-
731724
case TOTAL_HEATFLUX:
732725
ObjFunc += solvers[HEAT_SOL]->GetTotal_HeatFlux()*Weight_ObjFunc;
733726
break;
734727
case AVG_TEMPERATURE:
735728
ObjFunc += solvers[HEAT_SOL]->GetTotal_AvgTemperature()*Weight_ObjFunc;
736729
break;
737-
738-
default:
739-
ObjectiveNotCovered = true;
740-
break;
741730
}
742731
break;
743732
}
744733
case DISC_ADJ_FEM:
745734
{
746-
switch(config->GetKind_ObjFunc()) {
747-
748-
case REFERENCE_NODE:
749-
solvers[FEA_SOL]->Compute_OFRefNode(geometry, config);
750-
ObjFunc += solvers[FEA_SOL]->GetTotal_OFRefNode()*Weight_ObjFunc;
751-
break;
752-
case REFERENCE_GEOMETRY:
753-
solvers[FEA_SOL]->Compute_OFRefGeom(geometry, config);
754-
ObjFunc += solvers[FEA_SOL]->GetTotal_OFRefGeom()*Weight_ObjFunc;
755-
break;
756-
case TOPOL_COMPLIANCE:
757-
solvers[FEA_SOL]->Compute_OFCompliance(geometry, config);
758-
ObjFunc += solvers[FEA_SOL]->GetTotal_OFCompliance()*Weight_ObjFunc;
759-
break;
760-
case VOLUME_FRACTION:
761-
solvers[FEA_SOL]->Compute_OFVolFrac(geometry, config);
762-
ObjFunc += solvers[FEA_SOL]->GetTotal_OFVolFrac()*Weight_ObjFunc;
763-
break;
764-
case TOPOL_DISCRETENESS:
765-
solvers[FEA_SOL]->Compute_OFVolFrac(geometry, config);
766-
ObjFunc += solvers[FEA_SOL]->GetTotal_OFDiscreteness()*Weight_ObjFunc;
767-
break;
768-
769-
default:
770-
ObjectiveNotCovered = true;
771-
break;
772-
}
735+
solvers[FEA_SOL]->Evaluate_ObjFunc(config);
736+
ObjFunc += solvers[FEA_SOL]->GetTotal_ComboObj()*Weight_ObjFunc;
773737
break;
774738
}
775739
default:
776740
break;
777741
}
778-
779-
if (ObjectiveNotCovered && (rank == MASTER_NODE) && (kind_recording == SOLUTION_VARIABLES))
780-
cout << " Objective function not covered in Zone " << iZone << endl;
781742
}
782743

783744
if (rank == MASTER_NODE) {

SU2_CFD/src/drivers/CDiscAdjSinglezoneDriver.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -425,26 +425,9 @@ void CDiscAdjSinglezoneDriver::SetObjFunction(){
425425
break;
426426

427427
case DISC_ADJ_FEM:
428-
switch (config->GetKind_ObjFunc()){
429-
case REFERENCE_GEOMETRY:
430-
ObjFunc = solver[FEA_SOL]->GetTotal_OFRefGeom();
431-
break;
432-
case REFERENCE_NODE:
433-
ObjFunc = solver[FEA_SOL]->GetTotal_OFRefNode();
434-
break;
435-
case TOPOL_COMPLIANCE:
436-
ObjFunc = solver[FEA_SOL]->GetTotal_OFCompliance();
437-
break;
438-
case VOLUME_FRACTION:
439-
ObjFunc = solver[FEA_SOL]->GetTotal_OFVolFrac();
440-
break;
441-
case TOPOL_DISCRETENESS:
442-
ObjFunc = solver[FEA_SOL]->GetTotal_OFDiscreteness();
443-
break;
444-
default:
445-
ObjFunc = 0.0; // If the objective function is computed in a different physical problem
446-
break;
447-
}
428+
solver[FEA_SOL]->Postprocessing(geometry, config, numerics_container[ZONE_0][INST_0][MESH_0][FEA_SOL], true);
429+
solver[FEA_SOL]->Evaluate_ObjFunc(config);
430+
ObjFunc = solver[FEA_SOL]->GetTotal_ComboObj();
448431
break;
449432
}
450433

0 commit comments

Comments
 (0)