Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Preconditioning for multicomponent flows #2426

Open
wants to merge 27 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ca9083e
solving for enthalpy
Cristopher-Morales Oct 22, 2024
0487a68
fixing flux jacobian
Cristopher-Morales Oct 25, 2024
dd369bb
Merge branch 'develop' into feature_preconditioning
Cristopher-Morales Oct 26, 2024
5076f9d
fix output error
Cristopher-Morales Oct 26, 2024
09fe6f4
adding enthalpy diffusion
Cristopher-Morales Oct 31, 2024
851b13f
Merge branch 'develop' into feature_preconditioning
Cristopher-Morales Oct 31, 2024
f258308
moving enthalpy diffusion terms to CIncNSSolver.cpp
Cristopher-Morales Nov 3, 2024
63a8f37
small fix
Cristopher-Morales Nov 3, 2024
cb1d3ef
Merge branch 'develop' into feature_preconditioning
Cristopher-Morales Nov 4, 2024
30d0b88
cleaning and rewritting some functions
Cristopher-Morales Nov 9, 2024
dd22fcd
Merge branch 'develop' into feature_preconditioning
Cristopher-Morales Nov 18, 2024
7f92730
axisymetric source term and corrected flux jacobian at the wall
Cristopher-Morales Nov 22, 2024
fdbb9b9
updating BC_ConjugateHeat_Interface for fluid mixture
Cristopher-Morales Nov 30, 2024
c0b10a6
Merge branch 'develop' into feature_preconditioning
Cristopher-Morales Dec 9, 2024
911c996
Merge branch 'develop' into feature_preconditioning
Cristopher-Morales Dec 23, 2024
2af10c3
activating muscl, consistent extrapolation for multicomponent
Cristopher-Morales Jan 2, 2025
d0d0221
Merge branch 'develop' into feature_preconditioning
Cristopher-Morales Jan 2, 2025
a1f526c
correct average enthalpy for multicomponent flows output
Cristopher-Morales Jan 10, 2025
c469d32
Merge branch 'develop' into feature_preconditioning
Cristopher-Morales Jan 11, 2025
ef2dc5f
changing boolean names
Cristopher-Morales Jan 11, 2025
94bd0b0
up to date to develop
Cristopher-Morales Jan 11, 2025
1c44044
Merge branch 'develop' into feature_preconditioning
Cristopher-Morales Jan 14, 2025
912642b
adding brackets
Cristopher-Morales Jan 18, 2025
a6ce2d4
fixing warning
Cristopher-Morales Jan 18, 2025
e9d1e1f
Merge branch 'develop' into feature_preconditioning
Cristopher-Morales Jan 23, 2025
127df29
Merge branch 'develop' into feature_preconditioning
Cristopher-Morales Jan 25, 2025
211dda0
Merge branch 'develop' into feature_preconditioning
Cristopher-Morales Jan 27, 2025
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
23 changes: 23 additions & 0 deletions SU2_CFD/include/fluid/CFluidModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CLookUpTable;
class CFluidModel {
protected:
su2double StaticEnergy{0.0}; /*!< \brief Internal Energy. */
su2double Enthalpy{0.0}; /*!<*\brief Enthalpy. */
su2double Entropy{0.0}; /*!< \brief Entropy. */
su2double Density{0.0}; /*!< \brief Density. */
su2double Pressure{0.0}; /*!< \brief Pressure. */
Expand Down Expand Up @@ -113,6 +114,11 @@ class CFluidModel {
*/
su2double GetStaticEnergy() const { return StaticEnergy; }

/*!
* \brief Get fluid enthalpy.
*/
su2double GetEnthalpy() const { return Enthalpy; }

/*!
* \brief Get fluid density.
*/
Expand Down Expand Up @@ -186,6 +192,16 @@ class CFluidModel {
return mass_diffusivity;
}

/*!
* \brief Get heat diffusivity terms.
*/
virtual void GetEnthalpyDiffusivity(su2double* enthalpy_diffusions = nullptr) {}

/*!
* \brief Get gradient heat diffusivity terms.
*/
virtual void GetGradEnthalpyDiffusivity(su2double* grad_enthalpy_diffusions = nullptr) {}

/*!
* \brief Get fluid pressure partial derivative.
*/
Expand Down Expand Up @@ -339,6 +355,13 @@ class CFluidModel {
*/
virtual void SetTDState_T(su2double val_Temperature, const su2double* val_scalars = nullptr) {}

/*!
* \brief Virtual member.
* \param[in] val_enthalpy - Enthalpy value at the point.
*/
virtual void ComputeTempFromEnthalpy(su2double val_enthalpy, su2double* val_temperature,
const su2double* val_scalars = nullptr) {}
Comment on lines +358 to +363
Copy link
Member

Choose a reason for hiding this comment

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

This seems inconsistent with the SetTDState_* functions.
Should this be SetTDState_h and then you use GetTemperature to get the temperature?

Copy link
Contributor Author

@Cristopher-Morales Cristopher-Morales Jan 19, 2025

Choose a reason for hiding this comment

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

In the pull request made by evert regarding preferential diffusion, he also used the same function for the flamelet solver. The only difference is that that function is in the CSpeciesFlameletSolver.cpp and I cannot access to that function when I set the primitives in SetPrimVar in CIncNSVariable.cpp

Copy link
Member

Choose a reason for hiding this comment

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

My point is again to keep an abstract interface.
Evert's function is a private function of a specific solver which is perfectly fine, and it uses the fluid model... If you need a similar function, move it somewhere higher up in the hierarchy to make it accessible. For example the scalar solver. Or even the fluid model but implemented in a way that keeps it useful for all fluids.


/*!
* \brief Set fluid eddy viscosity provided by a turbulence model needed for computing effective thermal conductivity.
*/
Expand Down
21 changes: 21 additions & 0 deletions SU2_CFD/include/fluid/CFluidScalar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class CFluidScalar final : public CFluidModel {
*/
su2double ComputeMeanSpecificHeatCp(const su2double* val_scalars);

/*!
* \brief Compute Enthalpy given the temperature and scalars.
*/
su2double ComputeEnthalpyFromT(const su2double val_temperature, const su2double* val_scalars);
Comment on lines +94 to +97
Copy link
Member

Choose a reason for hiding this comment

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

Why doesn't this use TDState_T

Copy link
Contributor Author

@Cristopher-Morales Cristopher-Morales Jan 19, 2025

Choose a reason for hiding this comment

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

We compute the enthalpy from the temperature and the species mass fractions. That function is used for setting the enthalpy at the inlets.

Copy link
Member

Choose a reason for hiding this comment

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

And why don't you compute the enthalpy in that function too instead of adding another function?
The idea with generic classes like CFluidModel is to have a concise abstract interface. Having specific functions that only a few subclasses implement defeats the purpose of a generic interface.


/*!
* \brief Compute gas constant for mixture.
*/
Expand Down Expand Up @@ -137,6 +142,22 @@ class CFluidScalar final : public CFluidModel {
*/
inline su2double GetMassDiffusivity(int ivar) override { return massDiffusivity[ivar]; }

/*!
* \brief Get enthalpy diffusivity terms.
*/
void GetEnthalpyDiffusivity(su2double* enthalpy_diffusions) override;

/*!
* \brief Get gradient enthalpy diffusivity terms.
*/
void GetGradEnthalpyDiffusivity(su2double* grad_enthalpy_diffusions) override;

/*!
* \brief Compute Temperature from Enthalpy and scalars.
*/
void ComputeTempFromEnthalpy(const su2double val_enthalpy, su2double* val_temperature,
const su2double* val_scalars) override;

/*!
* \brief Set the Dimensionless State using Temperature.
* \param[in] t - Temperature value at the point.
Expand Down
20 changes: 20 additions & 0 deletions SU2_CFD/include/numerics/CNumerics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ class CNumerics {
const su2double
*ScalarVar_i, /*!< \brief Vector of scalar variables at point i. */
*ScalarVar_j; /*!< \brief Vector of scalar variables at point j. */
su2double
HeatFluxDiffusion; /*!< \brief Heat flux due to enthalpy diffusion for multicomponent. */
su2double
Jac_HeatFluxDiffusion; /*!< \brief Heat flux jacobian due to enthalpy diffusion for multicomponent. */
const su2double
*TransVar_i, /*!< \brief Vector of turbulent variables at point i. */
*TransVar_j; /*!< \brief Vector of turbulent variables at point j. */
Expand Down Expand Up @@ -188,6 +192,8 @@ class CNumerics {

bool nemo; /*!< \brief Flag for NEMO problems */

bool energy_multicomponent = false; /*!< \brief Flag for multicomponent and reacting flow */

bool bounded_scalar = false; /*!< \brief Flag for bounded scalar problem */

public:
Expand Down Expand Up @@ -751,6 +757,20 @@ class CNumerics {
Diffusion_Coeff_j = val_diffusioncoeff_j;
}

/*!
* \brief Set the heat flux due to enthalpy diffusion
* \param[in] val_heatfluxdiffusion - Value of the heat flux due to enthalpy diffusion.
*/
inline void SetHeatFluxDiffusion(su2double val_heatfluxdiffusion) { HeatFluxDiffusion = val_heatfluxdiffusion; }

/*!
* \brief Set Jacobian of the heat flux due to enthalpy diffusion
* \param[in] val_jacheatfluxdiffusion - Value of the heat flux jacobian due to enthalpy diffusion.
*/
inline void SetJacHeatFluxDiffusion(su2double val_jac_heatfluxdiffusion) {
Jac_HeatFluxDiffusion = val_jac_heatfluxdiffusion;
}

/*!
* \brief Set the laminar viscosity.
* \param[in] val_laminar_viscosity_i - Value of the laminar viscosity at point i.
Expand Down
9 changes: 6 additions & 3 deletions SU2_CFD/include/numerics/flow/flow_diffusion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class CAvgGrad_Base : public CNumerics {
*heat_flux_jac_i = nullptr, /*!< \brief Jacobian of the molecular + turbulent heat flux vector, projected onto the normal vector. */
**tau_jacobian_i = nullptr; /*!< \brief Jacobian of the viscous + turbulent stress tensor, projected onto the normal vector. */
su2double *Mean_PrimVar = nullptr; /*!< \brief Mean primitive variables. */
su2double Mean_HeatFluxDiffusion; /*!< \brief Mean heat flux due to enthalpy diffusion for multicomponent flows. */
su2double Mean_JacHeatFluxDiffusion; /*!< \brief Mean Jacobian heat flux due to enthalpy diffusion for multicomponent flows. */
const su2double
*PrimVar_i = nullptr,
*PrimVar_j = nullptr; /*!< \brief Primitives variables at point i and j. */
Expand Down Expand Up @@ -287,6 +289,7 @@ class CAvgGrad_Flow final : public CAvgGrad_Base {
class CAvgGradInc_Flow final : public CAvgGrad_Base {
private:
su2double Mean_Thermal_Conductivity; /*!< \brief Mean value of the effective thermal conductivity. */
su2double Mean_Heat_Capacity; /*!< \brief Mean value of the heat capacity. */
bool energy; /*!< \brief computation with the energy equation. */

/*!
Expand All @@ -298,10 +301,10 @@ class CAvgGradInc_Flow final : public CAvgGrad_Base {
* \param[in] val_gradprimvar - Gradient of the primitive variables.
* \param[in] val_normal - Normal vector, the norm of the vector is the area of the face.
* \param[in] val_thermal_conductivity - Thermal conductivity.
* \param[in] val_heatDiffusion - Heat diffusion
*/
void GetViscousIncProjFlux(const su2double* const *val_gradprimvar,
const su2double *val_normal,
su2double val_thermal_conductivity);
void GetViscousIncProjFlux(const su2double* const* val_gradprimvar, const su2double* val_normal,
su2double val_thermal_conductivity, su2double val_heatFluxDiffusion);

/*!
* \brief Compute the projection of the viscous Jacobian matrices.
Expand Down
3 changes: 2 additions & 1 deletion SU2_CFD/include/numerics/flow/flow_sources.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ class CSourceGeneralAxisymmetric_Flow final : public CSourceAxisymmetric_Flow {
class CSourceIncAxisymmetric_Flow final : public CSourceBase_Flow {
bool implicit, /*!< \brief Implicit calculation. */
viscous, /*!< \brief Viscous incompressible flows. */
energy; /*!< \brief computation with the energy equation. */
energy, /*!< \brief computation with the energy equation. */
multicomponent; /*!< \brief multicomponent incompressible flows. */

public:
/*!
Expand Down
1 change: 1 addition & 0 deletions SU2_CFD/include/output/CFlowIncOutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CFlowIncOutput final: public CFlowOutput {
private:
TURB_MODEL turb_model; /*!< \brief The kind of turbulence model*/
bool heat; /*!< \brief Boolean indicating whether have a heat problem*/
bool multicomponent; /*!< \brief Boolean indicating whether have a multicomponent problem*/
bool weakly_coupled_heat; /*!< \brief Boolean indicating whether have a weakly coupled heat equation*/
bool flamelet; /*!< \brief Boolean indicating whether we solve the flamelet equations */
unsigned short streamwisePeriodic; /*!< \brief Boolean indicating whether it is a streamwise periodic simulation. */
Expand Down
3 changes: 2 additions & 1 deletion SU2_CFD/include/solvers/CFVMFlowSolverBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class CFVMFlowSolverBase : public CSolver {
su2double Mach_Inf = 0.0; /*!< \brief Mach number at the infinity. */
su2double Density_Inf = 0.0; /*!< \brief Density at the infinity. */
su2double Energy_Inf = 0.0; /*!< \brief Energy at the infinity. */
su2double Temperature_Inf = 0.0; /*!< \brief Energy at the infinity. */
su2double Temperature_Inf = 0.0; /*!< \brief Temperature at the infinity. */
su2double Enthalpy_Inf = 0.0; /*!< \brief Enthalpy at the infinity. */
su2double Pressure_Inf = 0.0; /*!< \brief Pressure at the infinity. */
su2double* Velocity_Inf = nullptr; /*!< \brief Flow Velocity vector at the infinity. */

Expand Down
2 changes: 1 addition & 1 deletion SU2_CFD/include/solvers/CFVMFlowSolverBase.inl
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ void CFVMFlowSolverBase<V, R>::Viscous_Residual_impl(unsigned long iEdge, CGeome
const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT);
const bool tkeNeeded = (config->GetKind_Turb_Model() == TURB_MODEL::SST);

CVariable* turbNodes = nullptr;
CVariable* turbNodes = nullptr;
Copy link
Member

Choose a reason for hiding this comment

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

Please setup your IDE to remove trailing spaces.

if (tkeNeeded) turbNodes = solver_container[TURB_SOL]->GetNodes();

/*--- Points, coordinates and normal vector in edge ---*/
Expand Down
13 changes: 13 additions & 0 deletions SU2_CFD/include/solvers/CIncEulerSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ class CIncEulerSolver : public CFVMFlowSolverBase<CIncEulerVariable, ENUM_REGIME
CConfig *config,
unsigned short iMesh) final;

/*!
* \brief Recompute the extrapolated quantities, after MUSCL reconstruction,
* in a more thermodynamically consistent way.
* \note This method is static to improve the chances of it being used in a
* thread-safe manner.
* \param[in,out] fluidModel - The fluid model.
* \param[in] nDim - Number of physical dimensions.
* \param[in,out] primitive - Primitive variables.
* \param[in] scalar - scalar variable.
*/
static void ComputeConsistentExtrapolation(CFluidModel* fluidModel, unsigned short nDim, su2double* primitive,
const su2double* scalar);

/*!
* \brief Source term integration.
* \param[in] geometry - Geometrical definition of the problem.
Expand Down
18 changes: 16 additions & 2 deletions SU2_CFD/include/variables/CIncEulerVariable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/
class CIncEulerVariable : public CFlowVariable {
public:
static constexpr size_t MAXNVAR = 12;
static constexpr size_t MAXNVAR = 13;

template <class IndexType>
struct CIndices {
Expand All @@ -59,11 +59,11 @@ class CIncEulerVariable : public CFlowVariable {
inline IndexType ThermalConductivity() const { return nDim+6; }
inline IndexType CpTotal() const { return nDim+7; }
inline IndexType CvTotal() const { return nDim+8; }
inline IndexType Enthalpy() const { return nDim + 9; }

/*--- For compatible interface with NEMO. ---*/
inline IndexType SpeciesDensities() const { return std::numeric_limits<IndexType>::max(); }
inline IndexType Temperature_ve() const { return std::numeric_limits<IndexType>::max(); }
inline IndexType Enthalpy() const { return std::numeric_limits<IndexType>::max(); }
};

protected:
Expand Down Expand Up @@ -121,6 +121,14 @@ class CIncEulerVariable : public CFlowVariable {
return val_temperature <= 0.0;
}

/*!
* \brief Set the value of the enthalpy for multicomponent incompressible flows with energy equation.
* \param[in] iPoint - Point index.
*/
inline void SetEnthalpy(unsigned long iPoint, su2double val_enthalpy) {
Primitive(iPoint, indices.Enthalpy()) = val_enthalpy;
}

/*!
* \brief Set the value of the beta coeffient for incompressible flows.
* \param[in] iPoint - Point index.
Expand Down Expand Up @@ -153,6 +161,12 @@ class CIncEulerVariable : public CFlowVariable {
*/
inline su2double GetTemperature(unsigned long iPoint) const final { return Primitive(iPoint, indices.Temperature()); }

/*!
* \brief Get the enthalpy of the flow.
* \return Value of the enthalpy of the flow.
*/
inline su2double GetEnthalpy(unsigned long iPoint) const final { return Primitive(iPoint, indices.Enthalpy()); }

/*!
* \brief Get the velocity of the flow.
* \param[in] iDim - Index of the dimension.
Expand Down
1 change: 1 addition & 0 deletions SU2_CFD/include/variables/CIncNSVariable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CIncNSVariable final : public CIncEulerVariable {
private:
VectorType Tau_Wall; /*!< \brief Magnitude of the wall shear stress from a wall function. */
VectorType DES_LengthScale;
bool Energy_Multicomponent = false;

public:
/*!
Expand Down
30 changes: 30 additions & 0 deletions SU2_CFD/src/fluid/CFluidScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,43 @@ su2double CFluidScalar::ComputeMeanSpecificHeatCp(const su2double* val_scalars)
return mean_cp;
}

su2double CFluidScalar::ComputeEnthalpyFromT(const su2double val_temperature, const su2double* val_scalars){
su2double val_Enthalpy = Cp * (val_temperature - 298.15);
Copy link
Member

Choose a reason for hiding this comment

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

Isn't T0 a config option? It is bad practice to hard code constants like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://ansyshelp.ansys.com/public/account/secured?returnurl=////Views/Secured/corp/v242/en/flu_th/flu_th_sec_hxfer_theory.html this is the theory related to the enthalpy equation for multicomponent gases. T_ref is always 298.15 K for this equation

Copy link
Member

Choose a reason for hiding this comment

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

Then make it a constant, not a hard-coded value everywhere.

return val_Enthalpy;
}

void CFluidScalar::ComputeTempFromEnthalpy(const su2double val_enthalpy, su2double* val_temperature,
const su2double* val_scalars) {
MassToMoleFractions(val_scalars);
su2double val_cp = ComputeMeanSpecificHeatCp(val_scalars);
*val_temperature = val_enthalpy / val_cp + 298.15;
}

void CFluidScalar::GetEnthalpyDiffusivity(su2double* enthalpy_diffusions) {
for (int iVar = 0; iVar < n_species_mixture - 1; iVar++) {
enthalpy_diffusions[iVar] = Density *
(specificHeat[iVar] * massDiffusivity[iVar] -
specificHeat[n_species_mixture - 1] * massDiffusivity[n_species_mixture - 1]) *
(Temperature - 298.15);
}
}

void CFluidScalar::GetGradEnthalpyDiffusivity(su2double* grad_enthalpy_diffusions){
for (int iVar = 0; iVar < n_species_mixture - 1; iVar++) {
grad_enthalpy_diffusions[iVar] = Density *
(specificHeat[iVar] * massDiffusivity[iVar] -
specificHeat[n_species_mixture - 1] * massDiffusivity[n_species_mixture - 1]);
}
}

void CFluidScalar::SetTDState_T(const su2double val_temperature, const su2double* val_scalars) {
MassToMoleFractions(val_scalars);
ComputeGasConstant();
Temperature = val_temperature;
Density = Pressure_Thermodynamic / (Temperature * Gas_Constant);
Cp = ComputeMeanSpecificHeatCp(val_scalars);
Cv = Cp - Gas_Constant;
Enthalpy = ComputeEnthalpyFromT(Temperature, val_scalars);

if (wilke) {
Mu = WilkeViscosity(val_scalars);
Expand Down
Loading
Loading