Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
509a608
my changes
Jun 17, 2025
6aeb0a3
my changes
Jun 17, 2025
79e238c
specieschanges
Sep 1, 2025
526b9a1
Remove slurm files from repository
Dec 10, 2025
59979d0
Remove unnecessary blank line in COutput.hpp
tkiymaz Dec 10, 2025
99abfa4
Clean up commented-out density setting code
tkiymaz Dec 10, 2025
bee5a27
Update density retrieval comment for transient handling
tkiymaz Dec 10, 2025
cea69cc
Remove empty line before temperature setter comment
tkiymaz Dec 10, 2025
a721a2e
Clean up whitespace in CIncEulerVariable.hpp
tkiymaz Dec 10, 2025
02c03bb
Clean up blank lines in CVariable.hpp
tkiymaz Dec 10, 2025
0449bb4
Clean up CFlowIncOutput.cpp by removing blank lines
tkiymaz Dec 10, 2025
572291f
Clean up CompleteImplicitIteration and update dRhodT
tkiymaz Dec 10, 2025
c9fd0f6
Revert back the preconditioning to original
tkiymaz Dec 10, 2025
fc33c6a
Remove unnecessary whitespace and debug print statement
tkiymaz Dec 10, 2025
644a543
Clean up blank lines in CIncNSVariable.cpp
tkiymaz Dec 10, 2025
fed4892
Clean up whitespace in CVariable.cpp
tkiymaz Dec 10, 2025
8e09f7f
Fix constructor signature for CSpeciesVariable
tkiymaz Dec 10, 2025
1e5008a
Remove unnecessary blank line in CSpeciesVariable.cpp
tkiymaz Dec 10, 2025
2aebc54
Fix constructor signature for CSpeciesFlameletVariable
tkiymaz Dec 10, 2025
3f19c55
Remove debug output from SetPrimVar method
tkiymaz Dec 10, 2025
f5b3f56
Merge branch 'develop' into fix_inc_unsteady_density
tkiymaz Dec 11, 2025
735c27b
Update SU2_CFD/include/variables/CVariable.hpp
bigfooted Dec 16, 2025
f9f98a0
Update SU2_CFD/include/output/COutput.hpp
bigfooted Dec 16, 2025
adf7581
Update SU2_CFD/include/variables/CIncEulerVariable.hpp
bigfooted Dec 16, 2025
cc06d7e
Update SU2_CFD/include/variables/CEulerVariable.hpp
bigfooted Dec 16, 2025
6f2a8eb
Update SU2_CFD/src/solvers/CIncEulerSolver.cpp
bigfooted Dec 16, 2025
fa318d2
Update SU2_CFD/src/variables/CVariable.cpp
bigfooted Dec 16, 2025
3e1b898
Update SU2_CFD/src/variables/CVariable.cpp
bigfooted Dec 16, 2025
87a3381
Update SU2_CFD/src/variables/CIncNSVariable.cpp
bigfooted Dec 16, 2025
b278ad6
Update SU2_CFD/src/variables/CIncNSVariable.cpp
bigfooted Dec 16, 2025
dda9271
Update SU2_CFD/src/variables/CIncEulerVariable.cpp
bigfooted Dec 16, 2025
ff74a7f
Update SU2_CFD/include/solvers/CFVMFlowSolverBase.inl
bigfooted Dec 16, 2025
c194c4f
Update SU2_CFD/src/variables/CIncEulerVariable.cpp
bigfooted Dec 16, 2025
ac17146
Update SU2_CFD/include/solvers/CFVMFlowSolverBase.inl
bigfooted Dec 16, 2025
35b018f
most of the second order stuff
bigfooted Dec 16, 2025
d14be6e
cleanup for second order method (not tested yet)
bigfooted Dec 16, 2025
6cc4073
merge w. develop
bigfooted Dec 16, 2025
83c3416
Merge branch 'develop' into fix_inc_unsteady_density
Cristopher-Morales Dec 17, 2025
459e3b4
Merge branch 'develop' into fix_inc_unsteady_density
Cristopher-Morales Dec 17, 2025
630856b
Update SU2_CFD/src/solvers/CIncEulerSolver.cpp
tkiymaz Dec 18, 2025
35ad976
Update SU2_CFD/src/solvers/CIncEulerSolver.cpp
tkiymaz Dec 18, 2025
31f8af3
Update SU2_CFD/src/solvers/CIncEulerSolver.cpp
tkiymaz Dec 18, 2025
00ae736
Potential fix for code scanning alert no. 5888: Unused local variable
bigfooted Dec 18, 2025
8a47539
Merge branch 'develop' into fix_inc_unsteady_density
Cristopher-Morales Dec 18, 2025
4f7a656
Merge branch 'develop' into fix_inc_unsteady_density
Cristopher-Morales Dec 18, 2025
df27a84
Update SU2_CFD/src/variables/CIncNSVariable.cpp
bigfooted Dec 24, 2025
51f18af
Merge branch 'develop' into fix_inc_unsteady_density
bigfooted Jan 6, 2026
524fd46
Merge branch 'develop' into fix_inc_unsteady_density
bigfooted Jan 13, 2026
acfe778
Merge branch 'develop' into fix_flame_init
bigfooted Jan 16, 2026
adedf6b
fix mpi and flame init
bigfooted Jan 16, 2026
69833df
Merge remote-tracking branch 'origin/fix_flame_init' into fix_inc_uns…
bigfooted Jan 16, 2026
89661d4
Merge branch 'fix_flame_init' into fix_inc_unsteady_density
bigfooted Jan 16, 2026
df28101
guards
bigfooted Jan 16, 2026
2308622
revert
bigfooted Jan 16, 2026
d529abe
Apply suggestion from @bigfooted
bigfooted Jan 16, 2026
02c3311
Apply suggestion from @bigfooted
bigfooted Jan 16, 2026
2364e90
Merge branch 'develop' into fix_inc_unsteady_density
bigfooted Jan 20, 2026
d4c5d18
Merge branch 'develop' into fix_inc_unsteady_density
bigfooted Mar 15, 2026
7899323
Merge branch 'fix_inc_unsteady_density' of https://github.com/su2code…
bigfooted Mar 15, 2026
b355867
update code
bigfooted Mar 15, 2026
76d652c
fix density registration for AD
bigfooted Mar 15, 2026
100c2cb
Merge branch 'develop' into fix_inc_unsteady_density
bigfooted Mar 17, 2026
1562607
Merge branch 'develop' into fix_inc_unsteady_density
bigfooted Mar 24, 2026
b8e840a
Merge branch 'develop' into fix_inc_unsteady_density
bigfooted Apr 4, 2026
ec308a5
Merge branch 'develop' into fix_inc_unsteady_density
bigfooted Apr 11, 2026
a7ab5b7
Merge branch 'develop' into fix_inc_unsteady_density
bigfooted Apr 21, 2026
4f5cdfa
merge with develop
Apr 21, 2026
0f538ea
update w. develop
bigfooted Apr 24, 2026
d12f7b3
update naming
bigfooted Apr 24, 2026
de4a95b
Merge branch 'develop' into fix_inc_unsteady_density
bigfooted Apr 24, 2026
f7775f0
Merge branch 'develop' into fix_inc_unsteady_density
bigfooted Apr 30, 2026
7905679
fix bounded scalar
bigfooted Apr 30, 2026
b2a9094
fix restart, add regression
bigfooted Apr 30, 2026
f10305e
point github workflow to temporary testcases branch
bigfooted Apr 30, 2026
f5e0e34
Jacobian update for unsteady density
May 1, 2026
b71c7ff
extension of bounded scalar fix to RANS
May 1, 2026
b359140
change OMP call
bigfooted May 3, 2026
5f7e34d
Update SU2_CFD/include/solvers/CSpeciesSolver.hpp
tkiymaz May 13, 2026
3a7553e
Update SU2_CFD/include/solvers/CTurbSolver.hpp
tkiymaz May 13, 2026
663105f
formating and addition of bool functions
May 13, 2026
c25ac53
Merge branch 'develop' into fix_inc_unsteady_density
bigfooted Jun 14, 2026
3573190
Merge branch 'develop' into fix_inc_unsteady_density
bigfooted Jun 24, 2026
110d585
Merge branch 'develop' into fix_inc_unsteady_density
bigfooted Jun 30, 2026
ec56eb3
overload getdensity_time_n
bigfooted Jul 14, 2026
2e5ccec
Merge branch 'develop' into fix_inc_unsteady_density
bigfooted Jul 14, 2026
3ea82e7
overload density
bigfooted Jul 14, 2026
afdc9d5
Merge branch 'fix_inc_unsteady_density' of https://github.com/su2code…
bigfooted Jul 14, 2026
c40865f
registerdensity is part of registersolution
bigfooted Jul 14, 2026
8cc8bbe
Potential fix for pull request finding 'CodeQL / Unused local variable'
bigfooted Jul 14, 2026
879d3ba
update testcase
bigfooted Jul 14, 2026
c9c2c82
Merge branch 'fix_inc_unsteady_density' of https://github.com/su2code…
bigfooted Jul 14, 2026
40c4f72
Apply suggestion from @bigfooted
bigfooted Jul 14, 2026
42eee98
Apply suggestion from @bigfooted
bigfooted Jul 14, 2026
6b9c7ac
update bounded scalar for compressible
bigfooted Jul 14, 2026
cffd048
Merge branch 'fix_inc_unsteady_density' of https://github.com/su2code…
bigfooted Jul 14, 2026
08325f0
Merge branch 'develop' into fix_inc_unsteady_density
bigfooted Jul 15, 2026
dfdba2f
update testcase
bigfooted Jul 15, 2026
e238ab2
Merge branch 'fix_inc_unsteady_density' of https://github.com/su2code…
bigfooted Jul 15, 2026
d406376
update testcase
bigfooted Jul 15, 2026
0a5e693
update regressions
bigfooted Jul 15, 2026
820cb75
fix codi
bigfooted Jul 15, 2026
4be14fd
small cleanup
bigfooted Jul 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ jobs:
uses: docker://ghcr.io/su2code/su2/test-su2:260405-0054
with:
# -t <Tutorials-branch> -c <Testcases-branch>
args: -b ${{github.ref}} -t develop -c develop -s ${{matrix.testscript}}
args: -b ${{github.ref}} -t develop -c fgm_unsteady -s ${{matrix.testscript}}
- name: Cleanup
uses: docker://ghcr.io/su2code/su2/test-su2:260405-0054
with:
Expand Down Expand Up @@ -282,7 +282,7 @@ jobs:
uses: docker://ghcr.io/su2code/su2/test-su2:260405-0054
with:
# -t <Tutorials-branch> -c <Testcases-branch>
args: -b ${{github.ref}} -t develop -c develop -s ${{matrix.testscript}} -a "--tapetests"
args: -b ${{github.ref}} -t develop -c fgm_unsteady -s ${{matrix.testscript}} -a "--tapetests"
- name: Cleanup
uses: docker://ghcr.io/su2code/su2/test-su2:260405-0054
with:
Expand Down Expand Up @@ -330,7 +330,7 @@ jobs:
PMIX_MCA_gds: hash
with:
# -t <Tutorials-branch> -c <Testcases-branch>
args: -b ${{github.ref}} -t develop -c develop -s ${{matrix.testscript}} -a "--tsan"
args: -b ${{github.ref}} -t develop -c fgm_unsteady -s ${{matrix.testscript}} -a "--tsan"
- name: Cleanup
uses: docker://ghcr.io/su2code/su2/test-su2-tsan:260405-0054
with:
Expand Down Expand Up @@ -375,7 +375,7 @@ jobs:
uses: docker://ghcr.io/su2code/su2/test-su2-asan:260405-0054
with:
# -t <Tutorials-branch> -c <Testcases-branch>
args: -b ${{github.ref}} -t develop -c develop -s ${{matrix.testscript}} -a "--asan"
args: -b ${{github.ref}} -t develop -c fgm_unsteady -s ${{matrix.testscript}} -a "--asan"
- name: Cleanup
uses: docker://ghcr.io/su2code/su2/test-su2-asan:260405-0054
with:
Expand Down
95 changes: 47 additions & 48 deletions SU2_CFD/include/solvers/CScalarSolver.inl
Original file line number Diff line number Diff line change
Expand Up @@ -622,11 +622,14 @@ void CScalarSolver<VariableType>::SetResidual_DualTime(CGeometry* geometry, CSol
const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT);
const bool first_order = (config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_1ST);
const bool second_order = (config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_2ND);
const bool incompressible = (config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE);

/*--- The bounded-scalar correction. ---*/
const bool bounded_scalar = (IsSpeciesSolver() && config->GetBounded_Species()) ||
(IsTurbSolver() && config->GetBounded_Turb());

/*--- Flow solution, needed to get density. ---*/

CVariable* flowNodes = solver_container[FLOW_SOL]->GetNodes();
auto* flowNodes = solver_container[FLOW_SOL]->GetNodes();

/*--- Store the physical time step ---*/

Expand Down Expand Up @@ -654,19 +657,9 @@ void CScalarSolver<VariableType>::SetResidual_DualTime(CGeometry* geometry, CSol
SU2_OMP_FOR_STAT(omp_chunk_size)
for (iPoint = 0; iPoint < nPointDomain; iPoint++) {
if (Conservative) {
if (incompressible) {
/*--- This is temporary and only valid for constant-density problems:
density could also be temperature dependent, but as it is not a part
of the solution vector it's neither stored for previous time steps
nor updated with the solution at the end of each iteration. */
Density_nM1 = flowNodes->GetDensity(iPoint);
Density_n = flowNodes->GetDensity(iPoint);
Density_nP1 = flowNodes->GetDensity(iPoint);
} else {
Density_nM1 = flowNodes->GetSolution_time_n1(iPoint)[0];
Density_n = flowNodes->GetSolution_time_n(iPoint, 0);
Density_nP1 = flowNodes->GetSolution(iPoint, 0);
}
Density_nM1 = flowNodes->GetDensity_time_n1(iPoint);
Density_n = flowNodes->GetDensity_time_n(iPoint);
Density_nP1 = flowNodes->GetDensity(iPoint);
}

/*--- Retrieve the solution at time levels n-1, n, and n+1. Note that
Expand All @@ -686,13 +679,20 @@ void CScalarSolver<VariableType>::SetResidual_DualTime(CGeometry* geometry, CSol
time discretization scheme (1st- or 2nd-order).---*/

for (iVar = 0; iVar < nVar; iVar++) {
su2double unsteady_term = 0.0;
if (first_order)
LinSysRes(iPoint, iVar) +=
(Density_nP1 * U_time_nP1[iVar] - Density_n * U_time_n[iVar]) * Volume_nP1 / TimeStep;
unsteady_term = (Density_nP1 * U_time_nP1[iVar] - Density_n * U_time_n[iVar]) * Volume_nP1 / TimeStep;
if (second_order)
LinSysRes(iPoint, iVar) += (3.0 * Density_nP1 * U_time_nP1[iVar] - 4.0 * Density_n * U_time_n[iVar] +
unsteady_term = (3.0 * Density_nP1 * U_time_nP1[iVar] - 4.0 * Density_n * U_time_n[iVar] +
1.0 * Density_nM1 * U_time_nM1[iVar]) *
Volume_nP1 / (2.0 * TimeStep);

if (bounded_scalar) {
if (first_order) unsteady_term -= U_time_nP1[iVar] * (Density_nP1 - Density_n) * Volume_nP1 / TimeStep;
Comment thread
bigfooted marked this conversation as resolved.
if (second_order) unsteady_term -= U_time_nP1[iVar] * (3.0 * Density_nP1 - 4.0 * Density_n + 1.0 * Density_nM1) * Volume_nP1 / (2.0 * TimeStep);
}

LinSysRes(iPoint, iVar) += unsteady_term;
}

/*--- Compute the Jacobian contribution due to the dual time source term. ---*/
Expand Down Expand Up @@ -720,10 +720,7 @@ void CScalarSolver<VariableType>::SetResidual_DualTime(CGeometry* geometry, CSol
U_time_n = nodes->GetSolution_time_n(iPoint);

if (Conservative) {
if (incompressible)
Density_n = flowNodes->GetDensity(iPoint); // Temporary fix
else
Density_n = flowNodes->GetSolution_time_n(iPoint, 0);
Density_n = flowNodes->GetDensity_time_n(iPoint);
}

for (iNeigh = 0; iNeigh < geometry->nodes->GetnPoint(iPoint); iNeigh++) {
Expand Down Expand Up @@ -776,10 +773,7 @@ void CScalarSolver<VariableType>::SetResidual_DualTime(CGeometry* geometry, CSol
/*--- Multiply by density at node i for the SST model ---*/

if (Conservative) {
if (incompressible)
Density_n = flowNodes->GetDensity(iPoint); // Temporary fix
else
Density_n = flowNodes->GetSolution_time_n(iPoint, 0);
Density_n = flowNodes->GetDensity_time_n(iPoint);
}

for (iVar = 0; iVar < nVar; iVar++) LinSysRes(iPoint, iVar) += Density_n * U_time_n[iVar] * Residual_GCL;
Expand Down Expand Up @@ -815,37 +809,42 @@ void CScalarSolver<VariableType>::SetResidual_DualTime(CGeometry* geometry, CSol
due to the time discretization has a new form.---*/

if (Conservative) {
/*--- If this is the SST model, we need to multiply by the density
in order to get the conservative variables ---*/
if (incompressible) {
/*--- This is temporary and only valid for constant-density problems:
density could also be temperature dependent, but as it is not a part
of the solution vector it's neither stored for previous time steps
nor updated with the solution at the end of each iteration. */
Density_nM1 = flowNodes->GetDensity(iPoint);
Density_n = flowNodes->GetDensity(iPoint);
Density_nP1 = flowNodes->GetDensity(iPoint);
} else {
Density_nM1 = flowNodes->GetSolution_time_n1(iPoint)[0];
Density_n = flowNodes->GetSolution_time_n(iPoint, 0);
Density_nP1 = flowNodes->GetSolution(iPoint, 0);
}
/*--- Get density at different time levels via virtual methods ---*/
Density_nM1 = flowNodes->GetDensity_time_n1(iPoint);
Density_n = flowNodes->GetDensity_time_n(iPoint);
Density_nP1 = flowNodes->GetDensity(iPoint);
}

for (iVar = 0; iVar < nVar; iVar++) {
su2double unsteady_term = 0.0;
if (first_order)
LinSysRes(iPoint, iVar) +=
(Density_nP1 * U_time_nP1[iVar] - Density_n * U_time_n[iVar]) * (Volume_nP1 / TimeStep);
unsteady_term = (Density_nP1 * U_time_nP1[iVar] - Density_n * U_time_n[iVar]) * (Volume_nP1 / TimeStep);
if (second_order)
LinSysRes(iPoint, iVar) +=
(Density_nP1 * U_time_nP1[iVar] - Density_n * U_time_n[iVar]) * (3.0 * Volume_nP1 / (2.0 * TimeStep)) +
unsteady_term = (Density_nP1 * U_time_nP1[iVar] - Density_n * U_time_n[iVar]) * (3.0 * Volume_nP1 / (2.0 * TimeStep)) +
(Density_nM1 * U_time_nM1[iVar] - Density_n * U_time_n[iVar]) * (Volume_nM1 / (2.0 * TimeStep));

if (bounded_scalar) {
if (first_order) unsteady_term -= U_time_nP1[iVar] * (Density_nP1 - Density_n) * (Volume_nP1 / TimeStep);
if (second_order) unsteady_term -= U_time_nP1[iVar] * ((Density_nP1 - Density_n) * (3.0 * Volume_nP1 / (2.0 * TimeStep)) +
(Density_nM1 - Density_n) * (Volume_nM1 / (2.0 * TimeStep)));
}

LinSysRes(iPoint, iVar) += unsteady_term;
}

/*--- Compute the Jacobian contribution due to the dual time source term. ---*/
if (implicit) {
if (first_order) Jacobian.AddVal2Diag(iPoint, Volume_nP1 / TimeStep);
if (second_order) Jacobian.AddVal2Diag(iPoint, (Volume_nP1 * 3.0) / (2.0 * TimeStep));
su2double diag_factor = 1.0;
if (Conservative) {
if (bounded_scalar) {
if (first_order) diag_factor = Density_n;
if (second_order) diag_factor = (4.0 * Density_n - Density_nM1) / 3.0;
} else {
diag_factor = Density_nP1;
}
}
if (first_order) Jacobian.AddVal2Diag(iPoint, diag_factor * Volume_nP1 / TimeStep);
if (second_order) Jacobian.AddVal2Diag(iPoint, diag_factor * 3.0 * Volume_nP1 / (2.0 * TimeStep));
}
}
END_SU2_OMP_FOR
Expand Down Expand Up @@ -884,4 +883,4 @@ void CScalarSolver<VariableType>::PushSolutionBackInTime(unsigned long TimeIter,
nodes->Set_Solution_time_n();
}
}
}
}
10 changes: 10 additions & 0 deletions SU2_CFD/include/solvers/CSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,16 @@ class CSolver {
*/
inline virtual CFluidModel* GetFluidModel(void) const { return nullptr;}

/*!
* \brief Virtual function returning whether this is the species solver.
*/
inline virtual bool IsSpeciesSolver() const { return false; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These two virtuals don't belong on the CSolver base: their only call site is CScalarSolver::SetResidual_DualTime, called on this. A protected bounded_scalar member of CScalarSolver, set by the derived constructors from GetBounded_Species() / GetBounded_Turb() (same pattern as the existing Conservative flag), does the job with zero base-class footprint and no per-call config queries.


/*!
* \brief Virtual function returning whether this is the turbulent solver.
*/
inline virtual bool IsTurbSolver() const { return false; }

/*!
* \brief Get number of linear solver iterations.
* \return Number of linear solver iterations.
Expand Down
5 changes: 5 additions & 0 deletions SU2_CFD/include/solvers/CSpeciesSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ class CSpeciesSolver : public CScalarSolver<CSpeciesVariable> {

void Initialize(CGeometry* geometry, CConfig* config, unsigned short iMesh, unsigned short nVar);

/*!
* \brief Virtual function returning whether this is the species solver.
*/
inline bool IsSpeciesSolver() const final { return true; }

/*!
* \brief Restart residual and compute gradients.
* \param[in] geometry - Geometrical definition of the problem.
Expand Down
7 changes: 6 additions & 1 deletion SU2_CFD/include/solvers/CTurbSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class CTurbSolver : public CScalarSolver<CTurbVariable> {
*/
CTurbSolver(CGeometry* geometry, CConfig *config, bool conservative);

/*!
* \brief Virtual function returning whether this is the turbulent solver.
*/
inline bool IsTurbSolver() const final { return true; }

/*!
* \brief Impose via the residual the Euler wall boundary condition.
* \param[in] geometry - Geometrical definition of the problem.
Expand Down Expand Up @@ -147,7 +152,7 @@ class CTurbSolver : public CScalarSolver<CTurbVariable> {
* \returns The number of extra variables.
*/
unsigned long RegisterSolutionExtra(bool input, const CConfig* config) final;

/*!
* \brief Compute a suitable under-relaxation parameter to limit the change in the solution variables over
* a nonlinear iteration for stability.
Expand Down
22 changes: 22 additions & 0 deletions SU2_CFD/include/variables/CFlowVariable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,26 @@ class CFlowVariable : public CVariable {
* \return Vector of magnitudes.
*/
inline su2activevector& GetStrainMag() { return StrainMag; }

/*!
* \brief Get the density at time level n for dual-time stepping (compressible flows).
* For compressible flows, density is extracted from the solution container.
* For incompressible flows, this is overridden.
* \param[in] iPoint - Point index.
* \return Density at time level n.
*/
inline virtual su2double GetDensity_time_n(unsigned long iPoint) const {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two things here:

  1. These override the CVariable versions, so per the style guide they should be marked override (and then don't need virtual).
  2. More fundamentally, the base declarations on CVariable are not needed at all. The only call site that goes through CVariable* is CScalarSolver::SetResidual_DualTime, and the idiom for exactly this situation is already used in the same file (CScalarSolver.inl:156): su2staticcast_p<CFlowVariable*>(solver_container[FLOW_SOL]->GetNodes()). With that cast, these getters can be declared here on CFlowVariable (compressible default) with the CIncEulerVariable override, and the dangerous silent-0.0 default on CVariable disappears — which is exactly what makes the uninitialized coarse-MG case fail silently instead of loudly.

return GetSolution_time_n(iPoint, 0); // Density is the first component of Solution
}

/*!
* \brief Get the density at time level n-1 for dual-time stepping (compressible flows).
* For compressible flows, density is extracted from the solution container.
* For incompressible flows, this is overridden.
* \param[in] iPoint - Point index.
* \return Density at time level n-1.
*/
inline virtual su2double GetDensity_time_n1(unsigned long iPoint) const {
return GetSolution_time_n1(iPoint, 0); // Density is the first component of Solution
}
};
82 changes: 82 additions & 0 deletions SU2_CFD/include/variables/CIncEulerVariable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class CIncEulerVariable : public CFlowVariable {

VectorType Streamwise_Periodic_RecoveredPressure, /*!< \brief Recovered/Physical pressure [Pa] for streamwise periodic flow. */
Streamwise_Periodic_RecoveredTemperature; /*!< \brief Recovered/Physical temperature [K] for streamwise periodic flow. */
VectorType Density_time_n, /*!< \brief Density at time n for dual-time stepping. */
Density_time_n1; /*!< \brief Density at time n-1 for dual-time stepping. */
Comment thread
pcarruscag marked this conversation as resolved.
su2double TemperatureLimits[2]; /*!< \brief Temperature limits [K]. */
public:
/*!
Expand All @@ -87,6 +89,16 @@ class CIncEulerVariable : public CFlowVariable {
CIncEulerVariable(su2double pressure, const su2double *velocity, su2double enthalpy,
unsigned long npoint, unsigned long ndim, unsigned long nvar, const CConfig *config);

/*!
* \brief Set all the solution at time level n to the current solution value (including density).
*/
void Set_Solution_time_n() override;

/*!
* \brief Set all the solution at time level n-1 to the solution at time level n (including density).
*/
void Set_Solution_time_n1() override;

/*!
* \brief Set the value of the pressure.
* \param[in] iPoint - Point index.
Expand Down Expand Up @@ -291,4 +303,74 @@ class CIncEulerVariable : public CFlowVariable {
for (unsigned long iDim = 0; iDim < nDim; iDim++) Solution(iPoint, iDim+1) = val_vector[iDim];
}

/*!
* \brief Get the density at time level n for dual-time stepping.
* \param[in] iPoint - Point index.
* \return Density at time level n.
*/
inline su2double GetDensity_time_n(unsigned long iPoint) const override {
return Density_time_n.size() > 0 ? Density_time_n(iPoint) : GetDensity(iPoint);
}
Comment on lines +311 to +313

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@pcarruscag like this?


/*!
* \brief Get the density at time level n-1 for dual-time stepping.
* \param[in] iPoint - Point index.
* \return Density at time level n-1.
*/
inline su2double GetDensity_time_n1(unsigned long iPoint) const override {
return Density_time_n1.size() > 0 ? Density_time_n1(iPoint) : GetDensity(iPoint);
}

/*!
* \brief Set the density at time level n for dual-time stepping.
* \param[in] iPoint - Point index.
* \param[in] val_density - Density value.
*/
inline void SetDensity_time_n(unsigned long iPoint, su2double val_density) { Density_time_n(iPoint) = val_density; }

/*!
* \brief Set the density at time level n-1 for dual-time stepping.
* \param[in] iPoint - Point index.
* \param[in] val_density - Density value.
*/
inline void SetDensity_time_n1(unsigned long iPoint, su2double val_density) { Density_time_n1(iPoint) = val_density; }

/*!
* \brief Register solution at time n, including the density container for incompressible flows.
*/
void RegisterSolution_time_n() override;

/*!
* \brief Register solution at time n-1, including the density container for incompressible flows.
*/
void RegisterSolution_time_n1() override;

/*!
* \brief Get the adjoint of density at time n.
* Simplified version: directly extracts the AD derivative of Density_time_n,
Comment thread
bigfooted marked this conversation as resolved.
* analogous to GetAdjointSolution_time_n for the solution vector.
* The chain-rule contribution d(rho)/d(h) is currently not applied (TODO).
* \param[in] iPoint - Point index.
* \return Adjoint of the density at time n.
*/
inline su2double GetAdjointDensity_time_n(unsigned long iPoint) const override {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

GetAdjointDensity_time_n{,1} are never called anywhere — the only references are the TODO comments in CDiscAdjSolver.cpp. Please remove them (here and the CVariable defaults), along with the RegisterSolution_time_n{,1} overrides that register inputs whose adjoints are never extracted, and add them together with the actual chain-rule extraction in a follow-up (or better, avoid the manual chain rule entirely by recomputing the density histories on tape — see the comment in CIncEulerSolver.cpp). Until the adjoint is closed, an error for unsteady discrete adjoint + non-constant INC_DENSITY_MODEL would prevent silently wrong gradients.

if (Density_time_n.size() == 0) return 0.0; // Constant density - no adjoint contribution
AD::Identifier index = AD::GetPassiveIndex();
AD::SetIndex(index, Density_time_n(iPoint));
return AD::GetDerivative(index);
}

/*!
* \brief Get the adjoint of density at time n-1.
* See GetAdjointDensity_time_n.
* \param[in] iPoint - Point index.
* \return Adjoint of the density at time n-1.
*/
inline su2double GetAdjointDensity_time_n1(unsigned long iPoint) const override {
if (Density_time_n1.size() == 0) return 0.0; // Constant density - no adjoint contribution
AD::Identifier index = AD::GetPassiveIndex();
AD::SetIndex(index, Density_time_n1(iPoint));
return AD::GetDerivative(index);
}

};
Loading
Loading