Skip to content

Implementing variable density for unsteady incompressible flow#2641

Open
tkiymaz wants to merge 83 commits into
developfrom
fix_inc_unsteady_density
Open

Implementing variable density for unsteady incompressible flow#2641
tkiymaz wants to merge 83 commits into
developfrom
fix_inc_unsteady_density

Conversation

@tkiymaz

@tkiymaz tkiymaz commented Dec 10, 2025

Copy link
Copy Markdown

Proposed Changes

Implements variable density treatment for unsteady incompressible flow simulations. Currently, SU2 uses constant density in transient simulations, which is inaccurate for combustion cases where density varies significantly due to heat release and species composition changes. This contribution enables proper density updates during time-stepping for flamelet-based combustion modeling. For now, only 1st order time marching is implemented

Related Work

Related to incompressible flow solver and flamelet combustion modeling. No specific issue linked yet.

PR Checklist

  • I am submitting my contribution to the develop branch.
  • My contribution generates no new compiler warnings (try with --warnlevel=3 when using meson).
  • My contribution is commented and consistent with SU2 style (https://su2code.github.io/docs_v7/Style-Guide/).
  • I used the pre-commit hook to prevent dirty commits and used pre-commit run --all to format old commits.
  • I have added a test case that demonstrates my contribution, if necessary.
  • I have updated appropriate documentation (Tutorials, Docs Page, config_template.cpp), if necessary.

Tahsin Berk Kiymaz and others added 3 commits June 17, 2025 10:28
@pcarruscag

Copy link
Copy Markdown
Member

@Cristopher-Morales can you review this pr please?

Removed commented-out code for setting density at local point.
Updated the comment for density retrieval to reflect changes for transient density handling.
Removed unnecessary blank lines in CIncEulerVariable.hpp
Removed unnecessary blank lines in CVariable.hpp
Removed unnecessary blank lines to improve code readability.
@Cristopher-Morales

Copy link
Copy Markdown
Contributor

@Cristopher-Morales can you review this pr please?

Hi @pcarruscag !

Yes, I can help reviewing this PR.

Please let me know if you need something else from my side

Removed commented-out code and updated density calculation.
@bigfooted

Copy link
Copy Markdown
Contributor

@Cristopher-Morales I guess the changes to the preconditioner can be removed from this PR since we now have your implementation

Comment thread SU2_CFD/include/variables/CVariable.hpp Outdated
Removed debug print statement from SetPrimVar function.
Comment thread SU2_CFD/include/output/COutput.hpp Outdated
Comment on lines +102 to +105

inline void Set_Density_time_n(unsigned long iPoint, su2double val) {
Density_time_n[iPoint] = val;
}

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.

Documentation must be added, similar to the function above SetDensity, Same for the two functions below Set_Density_unsteady and GetDensity_time_n

@bigfooted bigfooted changed the title [WIP] Implementing variable density for unsteady incompressible flow Implementing variable density for unsteady incompressible flow Apr 30, 2026
@bigfooted

Copy link
Copy Markdown
Contributor

@pcarruscag can you have a quick look at this PR? The primal works as expected, the adjoint unsteady will be finalized in another PR.

Comment thread SU2_CFD/include/solvers/CScalarSolver.inl Outdated
Comment thread SU2_CFD/include/solvers/CScalarSolver.inl Outdated
Comment thread SU2_CFD/include/solvers/CScalarSolver.inl Outdated
Comment thread SU2_CFD/include/solvers/CSpeciesSolver.hpp Outdated
Comment thread SU2_CFD/include/solvers/CTurbSolver.hpp Outdated
Comment thread SU2_CFD/include/variables/CIncEulerVariable.hpp
Comment on lines 663 to 671
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);
Density_nM1 = incFlowNodes->GetDensity_time_n1(iPoint);
Density_n = incFlowNodes->GetDensity_time_n(iPoint);
Density_nP1 = incFlowNodes->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);
}

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.

We should use CFlowVariable to abstract this away.
Declare the GetDensity_time_n functions in CFlowVariable as virtual, the default implementation grabs density from the solution containers, whereas CIncEulerVariable overrides and uses its own containers for density.
Then the scalar solver does not need to carry logic about whether the flow is compressible or incompressible.

Comment on lines +2244 to +2252
/*!
* \brief Register the density at time n as an AD input (no-op for non-incompressible nodes).
*/
inline virtual void RegisterDensity_time_n() {}

/*!
* \brief Register the density at time n-1 as an AD input (no-op for non-incompressible nodes).
*/
inline virtual void RegisterDensity_time_n1() {}

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.

Can't this be part of registering the time_n solutions?

Comment on lines 449 to +458
SetVolumeOutputValue("PRESSURE_COEFF", iPoint, (Node_Flow->GetPressure(iPoint) - solver[FLOW_SOL]->GetPressure_Inf())/factor);
SetVolumeOutputValue("DENSITY", iPoint, Node_Flow->GetDensity(iPoint));

// Load density at previous timesteps for restart (unsteady with non-constant density)
if (config->GetTime_Domain() && config->GetKind_FluidModel() != CONSTANT_DENSITY) {
SetVolumeOutputValue("DENSITY_TIME_N", iPoint, Node_Flow_Inc->GetDensity_time_n(iPoint));
if (config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_2ND) {
SetVolumeOutputValue("DENSITY_TIME_N1", iPoint, Node_Flow_Inc->GetDensity_time_n1(iPoint));
}
}

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.

We have density in the restart file, we load more than one restart file for transient to get the previous solutions.
Why do we need each of the multiple files we write and load to also carry old information? This way we are storing and loading repeated information.

Comment on lines 172 to +176
direct_solver->GetNodes()->RegisterSolution_time_n();
/*--- Density is stored separately from the solution vector for incompressible flows. ---*/
if (config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE)
direct_solver->GetNodes()->RegisterDensity_time_n();
}

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.

So make RegisterSolution_time_n virtual and specialize it for the incompressible variable.
The purpose of abstractions like CSolver, CVariable, etc. is to keep physics/regime specific aspects contained in the "leaf classes" to allow the bigger ones like iteration, driver, etc. to deal with more general orchestration aspects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants