Skip to content

Commit 2bb4550

Browse files
authored
Merge pull request #2008 from su2code/fea_time_params
Unify Flow and FEA unsteady options + fix unsteady FEA adjoints + add FEA python wrapper examples
2 parents fb26459 + 2b7b16f commit 2bb4550

43 files changed

Lines changed: 727 additions & 557 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Common/include/CConfig.hpp

Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ class CConfig {
150150
su2double CL_Target; /*!< \brief Fixed Cl mode Target Cl. */
151151
su2double Confinement_Param; /*!< \brief Confinement paramenter for Vorticity Confinement method. */
152152
TIME_MARCHING TimeMarching; /*!< \brief Steady or unsteady (time stepping or dual time stepping) computation. */
153-
unsigned short Dynamic_Analysis; /*!< \brief Static or dynamic structural analysis. */
154153
su2double FixAzimuthalLine; /*!< \brief Fix an azimuthal line due to misalignments of the nearfield. */
155154
su2double **DV_Value; /*!< \brief Previous value of the design variable. */
156155
su2double Venkat_LimiterCoeff; /*!< \brief Limiter coefficient */
@@ -168,9 +167,6 @@ class CConfig {
168167
su2double HarmonicBalance_Period; /*!< \brief Period of oscillation to be used with harmonic balance computations. */
169168
su2double Delta_UnstTime, /*!< \brief Time step for unsteady computations. */
170169
Delta_UnstTimeND; /*!< \brief Time step for unsteady computations (non dimensional). */
171-
su2double Delta_DynTime, /*!< \brief Time step for dynamic structural computations. */
172-
Total_DynTime, /*!< \brief Total time for dynamic structural computations. */
173-
Current_DynTime; /*!< \brief Global time of the dynamic structural computations. */
174170
su2double Total_UnstTime, /*!< \brief Total time for unsteady computations. */
175171
Total_UnstTimeND; /*!< \brief Total time for unsteady computations (non dimensional). */
176172
su2double Current_UnstTime, /*!< \brief Global time of the unsteady simulation. */
@@ -2112,17 +2108,11 @@ class CConfig {
21122108
su2double GetElasticyMod(unsigned short id_val) const { return ElasticityMod[id_val]; }
21132109

21142110
/*!
2115-
* \brief Decide whether to apply DE effects to the model.
2116-
* \return <code>TRUE</code> if the DE effects are to be applied, <code>FALSE</code> otherwise.
2117-
*/
2111+
* \brief Decide whether to apply DE effects to the model.
2112+
* \return <code>TRUE</code> if the DE effects are to be applied, <code>FALSE</code> otherwise.
2113+
*/
21182114
bool GetDE_Effects(void) const { return DE_Effects; }
21192115

2120-
/*!
2121-
* \brief Decide whether to predict the DE effects for the next time step.
2122-
* \return <code>TRUE</code> if the DE effects are to be applied, <code>FALSE</code> otherwise.
2123-
*/
2124-
bool GetDE_Predicted(void);
2125-
21262116
/*!
21272117
* \brief Get the number of different electric constants.
21282118
* \return Value of the DE modulus.
@@ -8722,34 +8712,6 @@ class CConfig {
87228712
*/
87238713
bool GetSteadyRestart(void) const { return SteadyRestart; }
87248714

8725-
/*!
8726-
* \brief Provides information about the time integration of the structural analysis, and change the write in the output
8727-
* files information about the iteration.
8728-
* \return The kind of time integration: Static or dynamic analysis
8729-
*/
8730-
unsigned short GetDynamic_Analysis(void) const { return Dynamic_Analysis; }
8731-
8732-
/*!
8733-
* \brief If we are prforming an unsteady simulation, there is only
8734-
* one value of the time step for the complete simulation.
8735-
* \return Value of the time step in an unsteady simulation (non dimensional).
8736-
*/
8737-
su2double GetDelta_DynTime(void) const { return Delta_DynTime; }
8738-
8739-
/*!
8740-
* \brief If we are prforming an unsteady simulation, there is only
8741-
* one value of the time step for the complete simulation.
8742-
* \return Value of the time step in an unsteady simulation (non dimensional).
8743-
*/
8744-
su2double GetTotal_DynTime(void) const { return Total_DynTime; }
8745-
8746-
/*!
8747-
* \brief If we are prforming an unsteady simulation, there is only
8748-
* one value of the time step for the complete simulation.
8749-
* \return Value of the time step in an unsteady simulation (non dimensional).
8750-
*/
8751-
su2double GetCurrent_DynTime(void) const { return Current_DynTime; }
8752-
87538715
/*!
87548716
* \brief Get the current instance.
87558717
* \return Current instance identifier.
@@ -8781,22 +8743,10 @@ class CConfig {
87818743
unsigned short GetnIntCoeffs(void) const { return nIntCoeffs; }
87828744

87838745
/*!
8784-
* \brief Get the number of different values for the elasticity modulus.
8785-
* \return Number of different values for the elasticity modulus.
8746+
* \brief Get the number of different materials for the elasticity solver.
8747+
* \return Number of different materials.
87868748
*/
8787-
unsigned short GetnElasticityMod(void) const { return nElasticityMod; }
8788-
8789-
/*!
8790-
* \brief Get the number of different values for the Poisson ratio.
8791-
* \return Number of different values for the Poisson ratio.
8792-
*/
8793-
unsigned short GetnPoissonRatio(void) const { return nPoissonRatio; }
8794-
8795-
/*!
8796-
* \brief Get the number of different values for the Material density.
8797-
* \return Number of different values for the Material density.
8798-
*/
8799-
unsigned short GetnMaterialDensity(void) const { return nMaterialDensity; }
8749+
unsigned short GetnElasticityMat(void) const { return nElasticityMod; }
88008750

88018751
/*!
88028752
* \brief Get the integration coefficients for the Generalized Alpha - Newmark integration integration scheme.
@@ -9282,12 +9232,6 @@ class CConfig {
92829232
*/
92839233
void SetnTime_Iter(unsigned long val_iter) { nTimeIter = val_iter; }
92849234

9285-
/*!
9286-
* \brief Get the number of pseudo-time iterations
9287-
* \return Number of pseudo-time steps run for the single-zone problem
9288-
*/
9289-
unsigned long GetnIter(void) const { return nIter; }
9290-
92919235
/*!
92929236
* \brief Get the restart iteration
92939237
* \return Iteration for the restart of multizone problems

Common/include/geometry/elements/CElementProperty.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class CProperty {
9393
/*!
9494
* \brief Extract the derivative of the Design density.
9595
*/
96-
inline virtual su2double GetAdjointDensity(void) const { return 0.0; }
96+
inline virtual su2double GetAdjointDensity(void) { return 0.0; }
9797

9898
/*!
9999
* \brief Register the Design density as an AD input variable.
@@ -177,7 +177,11 @@ class CElementProperty final : public CProperty {
177177
/*!
178178
* \brief Extract the derivative of the Design density.
179179
*/
180-
inline su2double GetAdjointDensity(void) const override { return SU2_TYPE::GetDerivative(design_rho); }
180+
inline su2double GetAdjointDensity(void) override {
181+
su2double der = SU2_TYPE::GetDerivative(design_rho);
182+
AD::ResetInput(design_rho);
183+
return der;
184+
}
181185

182186
/*!
183187
* \brief Register the Design density as an AD input variable.

Common/include/option_structure.hpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,14 +1434,12 @@ static const MapType<std::string, ENUM_HEAT_TIMESTEP> Heat_TimeStep_Map = {
14341434
* \brief Type of time integration schemes
14351435
*/
14361436
enum class STRUCT_TIME_INT {
1437-
CD_EXPLICIT, /*!< \brief Support for implementing an explicit method. */
14381437
NEWMARK_IMPLICIT, /*!< \brief Implicit Newmark integration definition. */
14391438
GENERALIZED_ALPHA, /*!< \brief Support for implementing another implicit method. */
14401439
};
14411440
static const MapType<std::string, STRUCT_TIME_INT> Time_Int_Map_FEA = {
1442-
MakePair("CD_EXPLICIT", STRUCT_TIME_INT::CD_EXPLICIT)
14431441
MakePair("NEWMARK_IMPLICIT", STRUCT_TIME_INT::NEWMARK_IMPLICIT)
1444-
MakePair("GENERALIZED_ALPHA", STRUCT_TIME_INT::GENERALIZED_ALPHA)
1442+
// MakePair("GENERALIZED_ALPHA", STRUCT_TIME_INT::GENERALIZED_ALPHA) Not fully implemented.
14451443
};
14461444

14471445
/*!
@@ -2368,18 +2366,6 @@ enum class RECORDING {
23682366
SOLUTION_AND_MESH,
23692367
};
23702368

2371-
/*!
2372-
* \brief Types of schemes for dynamic structural computations
2373-
*/
2374-
enum ENUM_DYNAMIC {
2375-
STATIC = 0, /*!< \brief A static structural computation. */
2376-
DYNAMIC = 1 /*!< \brief Use a time stepping strategy for dynamic computations. */
2377-
};
2378-
static const MapType<std::string, ENUM_DYNAMIC> Dynamic_Map = {
2379-
MakePair("NO", STATIC)
2380-
MakePair("YES", DYNAMIC)
2381-
};
2382-
23832369
/*!
23842370
* \brief Types of input file formats
23852371
*/

Common/src/CConfig.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,12 +2435,6 @@ void CConfig::SetConfig_Options() {
24352435
/* DESCRIPTION: Temporary: pseudo static analysis (no density in dynamic analysis)
24362436
* Options: NO, YES \ingroup Config */
24372437
addBoolOption("PSEUDO_STATIC", PseudoStatic, false);
2438-
/* DESCRIPTION: Dynamic or static structural analysis */
2439-
addEnumOption("DYNAMIC_ANALYSIS", Dynamic_Analysis, Dynamic_Map, STATIC);
2440-
/* DESCRIPTION: Time Step for dynamic analysis (s) */
2441-
addDoubleOption("DYN_TIMESTEP", Delta_DynTime, 0.0);
2442-
/* DESCRIPTION: Total Physical Time for dual time stepping simulations (s) */
2443-
addDoubleOption("DYN_TIME", Total_DynTime, 1.0);
24442438
/* DESCRIPTION: Parameter alpha for Newmark scheme (s) */
24452439
addDoubleOption("NEWMARK_BETA", Newmark_beta, 0.25);
24462440
/* DESCRIPTION: Parameter delta for Newmark scheme (s) */
@@ -2987,6 +2981,12 @@ void CConfig::SetConfig_Parsing(istream& config_buffer){
29872981
newString.append("\n");
29882982
if (!option_name.compare("SINGLEZONE_DRIVER"))
29892983
newString.append("Option SINGLEZONE_DRIVER is deprecated, it does not have a replacement.\n\n");
2984+
else if (!option_name.compare("DYN_TIMESTEP"))
2985+
newString.append("DYN_TIMESTEP is deprecated. Use TIME_STEP instead.\n\n");
2986+
else if (!option_name.compare("DYN_TIME"))
2987+
newString.append("DYN_TIME is deprecated. Use MAX_TIME instead.\n\n");
2988+
else if (!option_name.compare("DYNAMIC_ANALYSIS"))
2989+
newString.append("DYNAMIC_ANALYSIS is deprecated. Use TIME_DOMAIN instead.\n\n");
29902990
else {
29912991
/*--- Find the most likely candidate for the unrecognized option, based on the length
29922992
of start and end character sequences shared by candidates and the option. ---*/
@@ -3660,7 +3660,6 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i
36603660

36613661
if (Time_Domain){
36623662
Delta_UnstTime = Time_Step;
3663-
Delta_DynTime = Time_Step;
36643663

36653664
if (TimeMarching == TIME_MARCHING::TIME_STEPPING){ InnerIter = 1; }
36663665

@@ -4649,6 +4648,11 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i
46494648
MaterialDensity = new su2double[1]; MaterialDensity[0] = 7854;
46504649
}
46514650

4651+
if (nElasticityMod != nPoissonRatio || nElasticityMod != nMaterialDensity) {
4652+
SU2_MPI::Error("ELASTICITY_MODULUS, POISSON_RATIO, and MATERIAL_DENSITY need to have the same number "
4653+
"of entries (the number of materials).", CURRENT_FUNCTION);
4654+
}
4655+
46524656
if (nElectric_Constant == 0) {
46534657
nElectric_Constant = 1;
46544658
Electric_Constant = new su2double[1]; Electric_Constant[0] = 0.0;
@@ -6803,7 +6807,7 @@ void CConfig::SetOutput(SU2_COMPONENT val_software, unsigned short val_izone) {
68036807
else {
68046808
if (Time_Domain) {
68056809
cout << "Dynamic structural analysis."<< endl;
6806-
cout << "Time step provided by the user for the dynamic analysis(s): "<< Delta_DynTime << "." << endl;
6810+
cout << "Time step provided by the user for the dynamic analysis(s): "<< Time_Step << "." << endl;
68076811
} else {
68086812
cout << "Static structural analysis." << endl;
68096813
}
@@ -6871,14 +6875,11 @@ void CConfig::SetOutput(SU2_COMPONENT val_software, unsigned short val_izone) {
68716875

68726876
if (fea) {
68736877
switch (Kind_TimeIntScheme_FEA) {
6874-
case STRUCT_TIME_INT::CD_EXPLICIT:
6875-
cout << "Explicit time integration (NOT IMPLEMENTED YET)." << endl;
6876-
break;
68776878
case STRUCT_TIME_INT::GENERALIZED_ALPHA:
68786879
cout << "Generalized-alpha method." << endl;
68796880
break;
68806881
case STRUCT_TIME_INT::NEWMARK_IMPLICIT:
6881-
if (Dynamic_Analysis) cout << "Newmark implicit method for the structural time integration." << endl;
6882+
if (Time_Domain) cout << "Newmark implicit method for the structural time integration." << endl;
68826883
switch (Kind_Linear_Solver) {
68836884
case BCGSTAB:
68846885
cout << "BCGSTAB is used for solving the linear system." << endl;
@@ -8416,9 +8417,6 @@ void CConfig::SetGlobalParam(MAIN_SOLVER val_solver,
84168417

84178418
case MAIN_SOLVER::FEM_ELASTICITY:
84188419
case MAIN_SOLVER::DISC_ADJ_FEM:
8419-
8420-
Current_DynTime = static_cast<su2double>(TimeIter)*Delta_DynTime;
8421-
84228420
if (val_system == RUNTIME_FEA_SYS) {
84238421
SetKind_ConvNumScheme(NONE, CENTERED::NONE, UPWIND::NONE, LIMITER::NONE, NONE, NONE);
84248422
SetKind_TimeIntScheme(NONE);
@@ -9994,7 +9992,6 @@ void CConfig::SetMultizone(const CConfig *driver_config, const CConfig* const* c
99949992
/*--- Fix the Time Step for all subdomains, for the case of time-dependent problems ---*/
99959993
if (driver_config->GetTime_Domain()){
99969994
Delta_UnstTime = driver_config->GetTime_Step();
9997-
Delta_DynTime = driver_config->GetTime_Step();
99989995

99999996
Time_Domain = true;
100009997
}

SU2_CFD/include/drivers/CDriverBase.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,15 @@ class CDriverBase {
499499
main_geometry->GetnVertex(iMarker), "MarkerPrimitives", false);
500500
}
501501

502+
/*!
503+
* \brief Get a read-only view of the geometry sensitivity of a discrete adjoint solver.
504+
*/
505+
inline CPyWrapperMatrixView Sensitivity(unsigned short iSolver) {
506+
auto* solver = GetSolverAndCheckMarker(iSolver);
507+
auto& sensitivity = const_cast<su2activematrix&>(solver->GetNodes()->GetSensitivity());
508+
return CPyWrapperMatrixView(sensitivity, "Sensitivity", true);
509+
}
510+
502511
/*!
503512
* \brief Set the temperature of a vertex on a specified marker (MARKER_PYTHON_CUSTOM).
504513
* \note This can be the input of a heat or flow solver in a CHT setting.

SU2_CFD/include/solvers/CDiscAdjFEASolver.hpp

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class CDiscAdjFEASolver final : public CSolver {
5050
su2double* val = nullptr; /*!< \brief Value of the variable. */
5151
su2double* LocalSens = nullptr; /*!< \brief Local sensitivity (domain). */
5252
su2double* GlobalSens = nullptr; /*!< \brief Global sensitivity (mpi). */
53-
su2double* TotalSens = nullptr; /*!< \brief Total sensitivity (time domain). */
53+
su2double* OldSens = nullptr; /*!< \brief Previous global sensitivity, used to update the total. */
54+
su2double* TotalSens = nullptr; /*!< \brief Total sensitivity (integrated over time). */
5455

5556
su2double& operator[] (unsigned short i) { return val[i]; }
5657
const su2double& operator[] (unsigned short i) const { return val[i]; }
@@ -61,6 +62,7 @@ class CDiscAdjFEASolver final : public CSolver {
6162
val = new su2double[n]();
6263
LocalSens = new su2double[n]();
6364
GlobalSens = new su2double[n]();
65+
OldSens = new su2double[n]();
6466
TotalSens = new su2double[n]();
6567
}
6668

@@ -69,6 +71,7 @@ class CDiscAdjFEASolver final : public CSolver {
6971
delete [] val;
7072
delete [] LocalSens;
7173
delete [] GlobalSens;
74+
delete [] OldSens;
7275
delete [] TotalSens;
7376
}
7477

@@ -80,10 +83,19 @@ class CDiscAdjFEASolver final : public CSolver {
8083
for (auto i = 0u; i < size; ++i) LocalSens[i] = SU2_TYPE::GetDerivative(val[i]);
8184

8285
SU2_MPI::Allreduce(LocalSens, GlobalSens, size, MPI_DOUBLE, MPI_SUM, SU2_MPI::GetComm());
86+
87+
for (auto i = 0u; i < size; ++i) {
88+
/*--- Update the total by subtracting the old and adding the new value.
89+
* Then update the old value for the next call to this function. ---*/
90+
TotalSens[i] += GlobalSens[i] - OldSens[i];
91+
OldSens[i] = GlobalSens[i];
92+
}
8393
}
8494

85-
void UpdateTotal() {
86-
for (auto i = 0u; i < size; ++i) TotalSens[i] += GlobalSens[i];
95+
void Store() {
96+
/*--- Clears the old values such that on the next time step the total is
97+
* incremented instead of updated. ---*/
98+
for (auto i = 0u; i < size; ++i) OldSens[i] = 0.0;
8799
}
88100

89101
~SensData() { clear(); }
@@ -213,42 +225,6 @@ class CDiscAdjFEASolver final : public CSolver {
213225
*/
214226
inline su2double GetTotal_Sens_DVFEA(unsigned short iDVFEA) const override { return DV.TotalSens[iDVFEA]; }
215227

216-
/*!
217-
* \brief A virtual member.
218-
* \return Value of the sensitivity coefficient for the Young Modulus E
219-
*/
220-
inline su2double GetGlobal_Sens_E(unsigned short iVal) const override { return E.GlobalSens[iVal]; }
221-
222-
/*!
223-
* \brief A virtual member.
224-
* \return Value of the Mach sensitivity for the Poisson's ratio Nu
225-
*/
226-
inline su2double GetGlobal_Sens_Nu(unsigned short iVal) const override { return Nu.GlobalSens[iVal]; }
227-
228-
/*!
229-
* \brief A virtual member.
230-
* \return Value of the sensitivity coefficient for the Electric Field in the region iEField
231-
*/
232-
inline su2double GetGlobal_Sens_EField(unsigned short iEField) const override { return EField.GlobalSens[iEField]; }
233-
234-
/*!
235-
* \brief A virtual member.
236-
* \return Value of the sensitivity coefficient for the FEA DV in the region iDVFEA
237-
*/
238-
inline su2double GetGlobal_Sens_DVFEA(unsigned short iDVFEA) const override { return DV.GlobalSens[iDVFEA]; }
239-
240-
/*!
241-
* \brief Get the total sensitivity for the structural density
242-
* \return Value of the structural density sensitivity
243-
*/
244-
inline su2double GetGlobal_Sens_Rho(unsigned short iVal) const override { return Rho.GlobalSens[iVal]; }
245-
246-
/*!
247-
* \brief Get the total sensitivity for the structural weight
248-
* \return Value of the structural weight sensitivity
249-
*/
250-
inline su2double GetGlobal_Sens_Rho_DL(unsigned short iVal) const override { return Rho_DL.GlobalSens[iVal]; }
251-
252228
/*!
253229
* \brief Get the value of the Young modulus from the adjoint solver
254230
* \return Value of the Young modulus from the adjoint solver

SU2_CFD/include/solvers/CFEASolver.hpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -682,28 +682,9 @@ class CFEASolver : public CFEASolverBase {
682682
inline su2double GetFSI_ConvValue(unsigned short val_index) const final { return FSI_Conv[val_index]; }
683683

684684
/*!
685-
* \brief Retrieve the value of the dynamic Aitken relaxation factor.
686-
* \return Value of the dynamic Aitken relaxation factor.
685+
* \brief Store the value of the last Aitken relaxation factor in the current time step.
687686
*/
688-
inline su2double GetWAitken_Dyn(void) const final { return WAitken_Dyn; }
689-
690-
/*!
691-
* \brief Retrieve the value of the last Aitken relaxation factor in the previous time step.
692-
* \return Value of the last Aitken relaxation factor in the previous time step.
693-
*/
694-
inline su2double GetWAitken_Dyn_tn1(void) const final { return WAitken_Dyn_tn1; }
695-
696-
/*!
697-
* \brief Set the value of the dynamic Aitken relaxation factor
698-
* \param[in] Value of the dynamic Aitken relaxation factor
699-
*/
700-
inline void SetWAitken_Dyn(su2double waitk) final { WAitken_Dyn = waitk; }
701-
702-
/*!
703-
* \brief Set the value of the last Aitken relaxation factor in the current time step.
704-
* \param[in] Value of the last Aitken relaxation factor in the current time step.
705-
*/
706-
inline void SetWAitken_Dyn_tn1(su2double waitk_tn1) final { WAitken_Dyn_tn1 = waitk_tn1; }
687+
inline void SetWAitken_Dyn_tn1() final { WAitken_Dyn_tn1 = WAitken_Dyn; }
707688

708689
/*!
709690
* \brief Set the value of the load increment for nonlinear structural analysis

0 commit comments

Comments
 (0)