Skip to content

Commit a9a8f68

Browse files
authored
Don't store/use secondary partial derivatives when it's not necessary (#2789)
* stash * don't allocate/use secondary variables for ideal gas
1 parent 536a639 commit a9a8f68

7 files changed

Lines changed: 62 additions & 50 deletions

File tree

SU2_CFD/include/solvers/CFVMFlowSolverBase.inl

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ void CFVMFlowSolverBase<V, R>::Viscous_Residual_impl(unsigned long iEdge, CGeome
451451

452452
const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT);
453453
const bool tkeNeeded = (config->GetKind_Turb_Model() == TURB_MODEL::SST);
454+
const bool ideal_gas = (config->GetKind_FluidModel() == STANDARD_AIR) ||
455+
(config->GetKind_FluidModel() == IDEAL_GAS);
454456

455457
CVariable* turbNodes = nullptr;
456458
if (tkeNeeded) turbNodes = solver_container[TURB_SOL]->GetNodes();
@@ -469,10 +471,10 @@ void CFVMFlowSolverBase<V, R>::Viscous_Residual_impl(unsigned long iEdge, CGeome
469471

470472
numerics->SetPrimitive(nodes->GetPrimitive(iPoint),
471473
nodes->GetPrimitive(jPoint));
472-
473-
numerics->SetSecondary(nodes->GetSecondary(iPoint),
474-
nodes->GetSecondary(jPoint));
475-
474+
if (!ideal_gas) {
475+
numerics->SetSecondary(nodes->GetSecondary(iPoint),
476+
nodes->GetSecondary(jPoint));
477+
}
476478
/*--- Gradients. ---*/
477479

478480
numerics->SetPrimVarGradient(nodes->GetGradient_Primitive(iPoint),
@@ -1149,6 +1151,8 @@ void CFVMFlowSolverBase<V, FlowRegime>::BC_Sym_Plane(CGeometry* geometry, CSolve
11491151
SU2_ZONE_SCOPED
11501152

11511153
const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT);
1154+
const bool ideal_gas = (config->GetKind_FluidModel() == STANDARD_AIR) ||
1155+
(config->GetKind_FluidModel() == IDEAL_GAS);
11521156
const auto iVel = prim_idx.Velocity();
11531157

11541158
/*--- Blazek chapter 8.:
@@ -1205,7 +1209,9 @@ void CFVMFlowSolverBase<V, FlowRegime>::BC_Sym_Plane(CGeometry* geometry, CSolve
12051209

12061210
/*--- Set Primitive and Secondary for numerics class. ---*/
12071211
conv_numerics->SetPrimitive(V_domain, V_reflected);
1208-
conv_numerics->SetSecondary(nodes->GetSecondary(iPoint), nodes->GetSecondary(iPoint));
1212+
if (!ideal_gas) {
1213+
conv_numerics->SetSecondary(nodes->GetSecondary(iPoint), nodes->GetSecondary(iPoint));
1214+
}
12091215

12101216
/*--- Compute the residual using an upwind scheme. ---*/
12111217
auto residual = conv_numerics->ComputeResidual(config);
@@ -1329,6 +1335,8 @@ void CFVMFlowSolverBase<V, FlowRegime>::BC_Fluid_Interface(CGeometry* geometry,
13291335
CConfig* config) {
13301336
SU2_ZONE_SCOPED
13311337

1338+
const bool ideal_gas = config->GetKind_FluidModel() == STANDARD_AIR || config->GetKind_FluidModel() == IDEAL_GAS;
1339+
13321340
unsigned long iVertex, jVertex, iPoint, Point_Normal = 0;
13331341
unsigned short iDim, iVar, jVar, iMarker, nDonorVertex;
13341342

@@ -1380,19 +1388,15 @@ void CFVMFlowSolverBase<V, FlowRegime>::BC_Fluid_Interface(CGeometry* geometry,
13801388

13811389
conv_numerics->SetPrimitive(PrimVar_i, PrimVar_j);
13821390

1383-
if (FlowRegime == ENUM_REGIME::COMPRESSIBLE) {
1384-
if (!(config->GetKind_FluidModel() == STANDARD_AIR || config->GetKind_FluidModel() == IDEAL_GAS)) {
1385-
auto Secondary_i = nodes->GetSecondary(iPoint);
1386-
1387-
P_static = PrimVar_j[nDim + 1];
1388-
rho_static = PrimVar_j[nDim + 2];
1389-
GetFluidModel()->SetTDState_Prho(P_static, rho_static);
1391+
if (FlowRegime == ENUM_REGIME::COMPRESSIBLE && !ideal_gas) {
1392+
P_static = PrimVar_j[nDim + 1];
1393+
rho_static = PrimVar_j[nDim + 2];
1394+
GetFluidModel()->SetTDState_Prho(P_static, rho_static);
13901395

1391-
Secondary_j[0] = GetFluidModel()->GetdPdrho_e();
1392-
Secondary_j[1] = GetFluidModel()->GetdPde_rho();
1396+
Secondary_j[0] = GetFluidModel()->GetdPdrho_e();
1397+
Secondary_j[1] = GetFluidModel()->GetdPde_rho();
13931398

1394-
conv_numerics->SetSecondary(Secondary_i, Secondary_j);
1395-
}
1399+
conv_numerics->SetSecondary(nodes->GetSecondary(iPoint), Secondary_j);
13961400
}
13971401

13981402
/*--- Set the normal vector ---*/

SU2_CFD/include/solvers/CSolver.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ class CSolver {
8383
nPrimVar, /*!< \brief Number of primitive variables of the problem. */
8484
nPrimVarGrad, /*!< \brief Number of primitive variables of the problem in the gradient computation. */
8585
nSecondaryVar, /*!< \brief Number of primitive variables of the problem. */
86-
nSecondaryVarGrad, /*!< \brief Number of primitive variables of the problem in the gradient computation. */
8786
nVarGrad, /*!< \brief Number of variables for deallocating the LS Cvector. */
8887
nDim; /*!< \brief Number of dimensions of the problem. */
8988
unsigned long nPoint; /*!< \brief Number of points of the computational grid. */
@@ -415,11 +414,6 @@ class CSolver {
415414
*/
416415
inline unsigned short GetnSecondaryVar(void) const { return nSecondaryVar; }
417416

418-
/*!
419-
* \brief Get the number of variables of the problem.
420-
*/
421-
inline unsigned short GetnSecondaryVarGrad(void) const { return nSecondaryVarGrad; }
422-
423417
/*!
424418
* \brief Get the number of variables of the problem.
425419
*/

SU2_CFD/include/variables/CVariable.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,12 @@ class CVariable {
103103

104104
VectorType SolutionExtra_BGS_k; /*!< \brief Intermediate storage, enables cross term extraction as that is also pushed to Solution. */
105105

106-
protected:
107106
unsigned long nPoint = 0; /*!< \brief Number of points in the domain. */
108107
unsigned long nDim = 0; /*!< \brief Number of dimension of the problem. */
109108
unsigned long nVar = 0; /*!< \brief Number of variables of the problem. */
110109
unsigned long nPrimVar = 0; /*!< \brief Number of primitive variables. */
111110
unsigned long nPrimVarGrad = 0; /*!< \brief Number of primitives for which a gradient is computed. */
112111
unsigned long nSecondaryVar = 0; /*!< \brief Number of secondary variables. */
113-
unsigned long nSecondaryVarGrad = 0; /*!< \brief Number of secondaries for which a gradient is computed. */
114112
unsigned long nAuxVar = 0; /*!< \brief Number of auxiliary variables. */
115113

116114
/*--- Only allow default construction by derived classes. ---*/

SU2_CFD/src/solvers/CEulerSolver.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ CEulerSolver::CEulerSolver(CGeometry *geometry, CConfig *config,
121121
/*--- Centered schemes only need gradients for viscous fluxes (T and v). ---*/
122122
nPrimVarGrad = EulerNPrimVarGrad(config, nDim);
123123
nSecondaryVar = nSecVar;
124-
nSecondaryVarGrad = 2;
125124

126125
/*--- Initialize nVarGrad for deallocation ---*/
127126

@@ -1883,8 +1882,11 @@ void CEulerSolver::Upwind_Residual(CGeometry *geometry, CSolver **solver_contain
18831882

18841883
/*--- Get primitive and secondary variables ---*/
18851884

1886-
auto V_i = nodes->GetPrimitive(iPoint); auto V_j = nodes->GetPrimitive(jPoint);
1887-
auto S_i = nodes->GetSecondary(iPoint); auto S_j = nodes->GetSecondary(jPoint);
1885+
auto V_i = nodes->GetPrimitive(iPoint);
1886+
auto V_j = nodes->GetPrimitive(jPoint);
1887+
1888+
const su2double* S_i = ideal_gas? nullptr : nodes->GetSecondary(iPoint);
1889+
const su2double* S_j = ideal_gas? nullptr : nodes->GetSecondary(jPoint);
18881890

18891891
/*--- Set them with or without high order reconstruction using MUSCL strategy. ---*/
18901892

@@ -5081,9 +5083,11 @@ void CEulerSolver::BC_Riemann(CGeometry *geometry, CSolver **solver_container,
50815083

50825084
const string Marker_Tag = config->GetMarker_All_TagBound(val_marker);
50835085
const bool viscous = config->GetViscous(),
5084-
implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT),
5086+
implicit = config->GetKind_TimeIntScheme() == EULER_IMPLICIT,
50855087
gravity = config->GetGravityForce(),
5086-
tkeNeeded = (config->GetKind_Turb_Model() == TURB_MODEL::SST);
5088+
tkeNeeded = config->GetKind_Turb_Model() == TURB_MODEL::SST,
5089+
ideal_gas = config->GetKind_FluidModel() == STANDARD_AIR ||
5090+
config->GetKind_FluidModel() == IDEAL_GAS;
50875091

50885092
su2double **P_Tensor = new su2double*[nVar],
50895093
**invP_Tensor = new su2double*[nVar];
@@ -5451,7 +5455,7 @@ void CEulerSolver::BC_Riemann(CGeometry *geometry, CSolver **solver_container,
54515455

54525456
/*--- Secondary variables ---*/
54535457

5454-
auto S_domain = nodes->GetSecondary(iPoint);
5458+
const su2double* S_domain = ideal_gas? nullptr : nodes->GetSecondary(iPoint);
54555459

54565460
/*--- Compute secondary thermodynamic properties (partial derivatives...) ---*/
54575461
su2double S_boundary[8];
@@ -5527,6 +5531,8 @@ void CEulerSolver::BC_TurboRiemann(CGeometry *geometry, CSolver **solver_contain
55275531
bool viscous = config->GetViscous();
55285532
bool gravity = (config->GetGravityForce());
55295533
bool tkeNeeded = (config->GetKind_Turb_Model() == TURB_MODEL::SST);
5534+
const bool ideal_gas = config->GetKind_FluidModel() == STANDARD_AIR ||
5535+
config->GetKind_FluidModel() == IDEAL_GAS;
55305536

55315537
su2double *Normal, *turboNormal, *UnitNormal, *FlowDirMix, FlowDirMixMag, *turboVelocity;
55325538
Normal = new su2double[nDim];
@@ -5947,7 +5953,7 @@ void CEulerSolver::BC_TurboRiemann(CGeometry *geometry, CSolver **solver_contain
59475953

59485954
/*--- Secondary variables ---*/
59495955

5950-
S_domain = nodes->GetSecondary(iPoint);
5956+
S_domain = ideal_gas ? nullptr : nodes->GetSecondary(iPoint);
59515957

59525958
/*--- Compute secondary thermodynamic properties (partial derivatives...) ---*/
59535959

@@ -6203,6 +6209,8 @@ void CEulerSolver::BC_Giles(CGeometry *geometry, CSolver **solver_container, CNu
62036209
bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT);
62046210
string Marker_Tag = config->GetMarker_All_TagBound(val_marker);
62056211
bool viscous = config->GetViscous();
6212+
const bool ideal_gas = config->GetKind_FluidModel() == STANDARD_AIR ||
6213+
config->GetKind_FluidModel() == IDEAL_GAS;
62066214
unsigned short nSpanWiseSections = geometry->GetnSpanWiseSections(config->GetMarker_All_TurbomachineryFlag(val_marker));
62076215
su2double relfacAvgCfg = config->GetGiles_RelaxFactorAverage(Marker_Tag);
62086216
su2double relfacFouCfg = config->GetGiles_RelaxFactorFourier(Marker_Tag);
@@ -6538,8 +6546,7 @@ void CEulerSolver::BC_Giles(CGeometry *geometry, CSolver **solver_container, CNu
65386546
V_domain = nodes->GetPrimitive(iPoint);
65396547

65406548
/*--- Retrieve domain Secondary variables ---*/
6541-
S_domain = nodes->GetSecondary(iPoint);
6542-
6549+
S_domain = ideal_gas? nullptr : nodes->GetSecondary(iPoint);
65436550

65446551
/*--- Compute the internal state u_i ---*/
65456552
Velocity2_i = 0;

SU2_CFD/src/solvers/CNSSolver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ unsigned long CNSSolver::SetPrimitive_Variables(CSolver **solver_container, cons
158158

159159
/*--- Compressible flow, primitive variables nDim+5, (T, vx, vy, vz, P, rho, h, c, lamMu, eddyMu, ThCond, Cp) ---*/
160160

161-
bool physical = static_cast<CNSVariable*>(nodes)->SetPrimVar(iPoint, eddy_visc, turb_ke, GetFluidModel());
162-
nodes->SetSecondaryVar(iPoint, GetFluidModel());
161+
auto* ns_nodes = static_cast<CNSVariable*>(nodes);
162+
bool physical = ns_nodes->SetPrimVar(iPoint, eddy_visc, turb_ke, GetFluidModel());
163+
ns_nodes->SetSecondaryVar(iPoint, GetFluidModel());
163164

164165
/*--- Check for non-realizable states for reporting. ---*/
165166

SU2_CFD/src/variables/CEulerVariable.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ unsigned long EulerNPrimVarGrad(const CConfig *config, unsigned long ndim) {
4343
return ndim + 4;
4444
}
4545

46+
unsigned long EulerNSecVar(const CConfig *config) {
47+
const bool ideal_gas = config->GetKind_FluidModel() == STANDARD_AIR ||
48+
config->GetKind_FluidModel() == IDEAL_GAS;
49+
if (ideal_gas) return 0;
50+
return config->GetViscous() ? 8 : 2;
51+
}
52+
4653
CEulerVariable::CEulerVariable(su2double density, const su2double *velocity, su2double energy, unsigned long npoint,
4754
unsigned long ndim, unsigned long nvar, const CConfig *config)
4855
: CFlowVariable(npoint, ndim, nvar, ndim + 9, EulerNPrimVarGrad(config, ndim), config),
@@ -52,8 +59,7 @@ CEulerVariable::CEulerVariable(su2double density, const su2double *velocity, su2
5259
(config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_2ND);
5360
const bool classical_rk4 = (config->GetKind_TimeIntScheme_Flow() == CLASSICAL_RK4_EXPLICIT);
5461

55-
nSecondaryVar = config->GetViscous() ? 8 : 2,
56-
nSecondaryVarGrad = 2;
62+
nSecondaryVar = EulerNSecVar(config);
5763

5864
/*--- Solution initialization ---*/
5965

@@ -156,10 +162,11 @@ bool CEulerVariable::SetPrimVar(unsigned long iPoint, CFluidModel *FluidModel) {
156162
}
157163

158164
void CEulerVariable::SetSecondaryVar(unsigned long iPoint, CFluidModel *FluidModel) {
165+
if (nSecondaryVar == 0) return;
159166

160-
/*--- Compute secondary thermo-physical properties (partial derivatives...) ---*/
167+
/*--- Compute secondary thermo-physical properties (partial derivatives...) ---*/
161168

162-
SetdPdrho_e(iPoint, FluidModel->GetdPdrho_e());
163-
SetdPde_rho(iPoint, FluidModel->GetdPde_rho());
169+
SetdPdrho_e(iPoint, FluidModel->GetdPdrho_e());
170+
SetdPde_rho(iPoint, FluidModel->GetdPde_rho());
164171

165172
}

SU2_CFD/src/variables/CNSVariable.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,21 +210,22 @@ bool CNSVariable::SetPrimVar(unsigned long iPoint, su2double eddy_visc, su2doubl
210210
}
211211

212212
void CNSVariable::SetSecondaryVar(unsigned long iPoint, CFluidModel *FluidModel) {
213+
if (nSecondaryVar == 0) return;
213214

214-
/*--- Compute secondary thermodynamic properties (partial derivatives...) ---*/
215+
/*--- Compute secondary thermodynamic properties (partial derivatives...) ---*/
215216

216-
SetdPdrho_e( iPoint, FluidModel->GetdPdrho_e() );
217-
SetdPde_rho( iPoint, FluidModel->GetdPde_rho() );
217+
SetdPdrho_e( iPoint, FluidModel->GetdPdrho_e() );
218+
SetdPde_rho( iPoint, FluidModel->GetdPde_rho() );
218219

219-
SetdTdrho_e( iPoint, FluidModel->GetdTdrho_e() );
220-
SetdTde_rho( iPoint, FluidModel->GetdTde_rho() );
220+
SetdTdrho_e( iPoint, FluidModel->GetdTdrho_e() );
221+
SetdTde_rho( iPoint, FluidModel->GetdTde_rho() );
221222

222-
/*--- Compute secondary thermo-physical properties (partial derivatives...) ---*/
223+
/*--- Compute secondary thermo-physical properties (partial derivatives...) ---*/
223224

224-
Setdmudrho_T( iPoint, FluidModel->Getdmudrho_T() );
225-
SetdmudT_rho( iPoint, FluidModel->GetdmudT_rho() );
225+
Setdmudrho_T( iPoint, FluidModel->Getdmudrho_T() );
226+
SetdmudT_rho( iPoint, FluidModel->GetdmudT_rho() );
226227

227-
Setdktdrho_T( iPoint, FluidModel->Getdktdrho_T() );
228-
SetdktdT_rho( iPoint, FluidModel->GetdktdT_rho() );
228+
Setdktdrho_T( iPoint, FluidModel->Getdktdrho_T() );
229+
SetdktdT_rho( iPoint, FluidModel->GetdktdT_rho() );
229230

230231
}

0 commit comments

Comments
 (0)