-
Notifications
You must be signed in to change notification settings - Fork 905
[WIP] defect correction of Nishikawa for skewed meshes #2584
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,7 @@ | |
| class CAvgGrad_Base : public CNumerics { | ||
| protected: | ||
| const unsigned short nPrimVar; /*!< \brief The size of the primitive variable array used in the numerics class. */ | ||
| const bool correct_gradient; /*!< \brief Apply a correction to the gradient term */ | ||
| const VISCOUS_GRAD_CORR correct_gradient; /*!< \brief Apply a correction to the gradient term */ | ||
| bool implicit = false; /*!< \brief Implicit calculus. */ | ||
| su2double | ||
| heat_flux_vector[MAXNDIM] = {0.0}, /*!< \brief Flux of total energy due to molecular and turbulent diffusion */ | ||
|
|
@@ -164,6 +164,15 @@ class CAvgGrad_Base : public CNumerics { | |
| su2double val_dist_ij_2, | ||
| const unsigned short val_nPrimVar); | ||
|
|
||
| void GradientCorrection(su2double** GradPrimVar, | ||
| const su2double* val_PrimVar_i, | ||
| const su2double* val_PrimVar_j, | ||
| const su2double* val_edge_vector, | ||
| su2double val_dist_ij_2, | ||
| const su2double* diss, | ||
| const unsigned short val_nPrimVar); | ||
|
|
||
|
|
||
| public: | ||
|
|
||
| /*! | ||
|
|
@@ -176,7 +185,7 @@ class CAvgGrad_Base : public CNumerics { | |
| */ | ||
| CAvgGrad_Base(unsigned short val_nDim, unsigned short val_nVar, | ||
| unsigned short val_nPrimVar, | ||
| bool val_correct_grad, const CConfig* config); | ||
| VISCOUS_GRAD_CORR val_correct_grad, const CConfig* config); | ||
|
|
||
| /*! | ||
| * \brief Destructor of the class. | ||
|
|
@@ -251,7 +260,7 @@ class CAvgGrad_Flow final : public CAvgGrad_Base { | |
| * \param[in] config - Definition of the particular problem. | ||
| */ | ||
| CAvgGrad_Flow(unsigned short val_nDim, unsigned short val_nVar, | ||
| bool val_correct_grad, const CConfig* config); | ||
| VISCOUS_GRAD_CORR val_correct_grad, const CConfig* config); | ||
|
|
||
| /*! | ||
| * \brief Compute the viscous flow residual using an average of gradients. | ||
|
|
@@ -330,7 +339,7 @@ class CAvgGradInc_Flow final : public CAvgGrad_Base { | |
| * \param[in] config - Definition of the particular problem. | ||
| */ | ||
| CAvgGradInc_Flow(unsigned short val_nDim, unsigned short val_nVar, | ||
| bool val_correct_grad, const CConfig* config); | ||
| VISCOUS_GRAD_CORR val_correct_grad, const CConfig* config); | ||
|
|
||
| /*! | ||
| * \brief Compute the viscous flow residual using an average of gradients. | ||
|
|
@@ -383,7 +392,7 @@ class CGeneralAvgGrad_Flow final : public CAvgGrad_Base { | |
| * \param[in] val_correct_grad - Apply a correction to the gradient | ||
| * \param[in] config - Definition of the particular problem. | ||
| */ | ||
| CGeneralAvgGrad_Flow(unsigned short val_nDim, unsigned short val_nVar, bool val_correct_grad, const CConfig* config); | ||
| CGeneralAvgGrad_Flow(unsigned short val_nDim, unsigned short val_nVar, VISCOUS_GRAD_CORR val_correct_grad, const CConfig* config); | ||
|
|
||
| /*! | ||
| * \brief Compute the viscous flow residual using an average of gradients. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,7 +80,7 @@ class CAvgGrad_Heat final : public CAvgGrad_Scalar<CNoFlowIndices> { | |
| * \param[in] config - Definition of the particular problem. | ||
| * \param[in] correct - Whether to correct the gradient. | ||
| */ | ||
| CAvgGrad_Heat(unsigned short val_nDim, const CConfig *config, bool correct) | ||
| CAvgGrad_Heat(unsigned short val_nDim, const CConfig *config, VISCOUS_GRAD_CORR correct) | ||
| : CAvgGrad_Scalar<CNoFlowIndices>(val_nDim, 1, correct, config) {} | ||
|
|
||
| private: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,7 +69,8 @@ class CAvgGrad_Scalar : public CNumerics { | |
| su2double* Jacobian_j[MAXNVAR]; /*!< \brief Flux Jacobian w.r.t. node j. */ | ||
| su2double JacobianBuffer[2*MAXNVAR*MAXNVAR];/*!< \brief Static storage for the two Jacobians. */ | ||
|
|
||
| const bool correct_gradient = false, incompressible = false; | ||
| const bool incompressible = false; | ||
| const VISCOUS_GRAD_CORR correct_gradient; | ||
|
|
||
| /*! | ||
| * \brief A pure virtual function; Adds any extra variables to AD | ||
|
|
@@ -91,7 +92,7 @@ class CAvgGrad_Scalar : public CNumerics { | |
| * \param[in] correct_gradient - Whether to correct gradient for skewness. | ||
| * \param[in] config - Definition of the particular problem. | ||
| */ | ||
| CAvgGrad_Scalar(unsigned short val_nDim, unsigned short val_nVar, bool correct_grad, | ||
| CAvgGrad_Scalar(unsigned short val_nDim, unsigned short val_nVar, VISCOUS_GRAD_CORR correct_grad, | ||
| const CConfig* config) | ||
| : CNumerics(val_nDim, val_nVar, config), | ||
| idx(val_nDim, config->GetnSpecies()), | ||
|
|
@@ -123,7 +124,7 @@ class CAvgGrad_Scalar : public CNumerics { | |
| AD::SetPreaccIn(Normal, nDim); | ||
| AD::SetPreaccIn(ScalarVar_Grad_i, nVar, nDim); | ||
| AD::SetPreaccIn(ScalarVar_Grad_j, nVar, nDim); | ||
| if (correct_gradient) { | ||
| if (correct_gradient != VISCOUS_GRAD_CORR::NONE) { | ||
| AD::SetPreaccIn(ScalarVar_i, nVar); | ||
| AD::SetPreaccIn(ScalarVar_j, nVar); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,7 +104,7 @@ class CAvgGrad_Species final : public CAvgGrad_Scalar<FlowIndices> { | |
| * \param[in] correct_grad - Whether to correct gradient for skewness. | ||
| * \param[in] config - Definition of the particular problem. | ||
| */ | ||
| CAvgGrad_Species(unsigned short val_nDim, unsigned short val_nVar, bool correct_grad, const CConfig* config) | ||
| CAvgGrad_Species(unsigned short val_nDim, unsigned short val_nVar, VISCOUS_GRAD_CORR correct_grad, const CConfig* config) | ||
| : CAvgGrad_Scalar<FlowIndices>(val_nDim, val_nVar, correct_grad, config), | ||
| turbulence(config->GetKind_Turb_Model() != TURB_MODEL::NONE) {} | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,7 +98,7 @@ class CAvgGrad_TransLM final : public CAvgGrad_Scalar<FlowIndices> { | |
| * \param[in] correct_grad - Whether to correct gradient for skewness. | ||
| * \param[in] config - Definition of the particular problem. | ||
| */ | ||
| CAvgGrad_TransLM(unsigned short val_nDim, unsigned short val_nVar, bool correct_grad, const CConfig* config) | ||
| CAvgGrad_TransLM(unsigned short val_nDim, unsigned short val_nVar, VISCOUS_GRAD_CORR correct_grad, const CConfig* config) | ||
| : CAvgGrad_Scalar<FlowIndices>(val_nDim, val_nVar, correct_grad, config){ | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,7 +115,7 @@ class CAvgGrad_TurbSA final : public CAvgGrad_Scalar<FlowIndices> { | |
| * \param[in] config - Definition of the particular problem. | ||
| */ | ||
| CAvgGrad_TurbSA(unsigned short val_nDim, unsigned short val_nVar, | ||
| bool correct_grad, const CConfig* config) | ||
| VISCOUS_GRAD_CORR correct_grad, const CConfig* config) | ||
| : CAvgGrad_Scalar<FlowIndices>(val_nDim, val_nVar, correct_grad, config), | ||
| use_accurate_jacobians(config->GetUse_Accurate_Turb_Jacobians()) {} | ||
| }; | ||
|
|
@@ -208,7 +208,7 @@ class CAvgGrad_TurbSA_Neg final : public CAvgGrad_Scalar<FlowIndices> { | |
| * \param[in] config - Definition of the particular problem. | ||
| */ | ||
| CAvgGrad_TurbSA_Neg(unsigned short val_nDim, unsigned short val_nVar, | ||
| bool correct_grad, const CConfig* config) | ||
| VISCOUS_GRAD_CORR correct_grad, const CConfig* config) | ||
| : CAvgGrad_Scalar<FlowIndices>(val_nDim, val_nVar, correct_grad, config) {} | ||
| }; | ||
|
|
||
|
|
@@ -275,7 +275,7 @@ class CAvgGrad_TurbSST final : public CAvgGrad_Scalar<FlowIndices> { | |
|
|
||
| /*--- We aim to treat the cross-diffusion as a diffusion term rather than a source term. | ||
| * Re-writing the cross-diffusion contribution as λ/w ∇w ∇k, where λ = (2 (1- F1) ρ σ_ω2) | ||
| * and expanding using the product rule for divergence theorem gives: ∇(w λ/w ∇k) - w ∇(λ/w ∇k). | ||
| * and expanding using the product rule for divergence theorem gives: ∇(w λ/w ∇k) - w ∇(λ/w ∇k). | ||
| * Discretising using FVM, gives: (λ)_ij ∇k - w_c (λ/w)_ij ∇k. where w_c is the cell centre value ---*/ | ||
|
|
||
| const su2double lambda_i = 2 * (1 - F1_i) * Density_i * sigma_omega_i; | ||
|
|
@@ -284,7 +284,7 @@ class CAvgGrad_TurbSST final : public CAvgGrad_Scalar<FlowIndices> { | |
| const su2double w_ij = 0.5 * (ScalarVar_i[1] + ScalarVar_j[1]); | ||
|
|
||
| const su2double diff_omega_T2 = lambda_ij; | ||
|
|
||
| const su2double diff_omega_T3 = -ScalarVar_i[1] * lambda_ij/w_ij; | ||
|
|
||
| Flux[0] = diff_kine*Proj_Mean_GradScalarVar[0]; | ||
|
|
@@ -314,7 +314,7 @@ class CAvgGrad_TurbSST final : public CAvgGrad_Scalar<FlowIndices> { | |
| Jacobian_j[0][1] = 0.0; | ||
| Jacobian_j[1][0] = (diff_omega_T2 + diff_omega_T3)*proj_on_rho_j; | ||
| Jacobian_j[1][1] = proj_on_rho_j * diff_omega_T1 + 2*lambda_ij*ScalarVar_i[1]/pow(ScalarVar_i[1]+ScalarVar_j[1],2) * Proj_Mean_GradScalarVar[0]; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -328,7 +328,7 @@ class CAvgGrad_TurbSST final : public CAvgGrad_Scalar<FlowIndices> { | |
| * \param[in] config - Definition of the particular problem. | ||
| */ | ||
| CAvgGrad_TurbSST(unsigned short val_nDim, unsigned short val_nVar, | ||
| const su2double* constants, bool correct_grad, const CConfig* config) | ||
| const su2double* constants, VISCOUS_GRAD_CORR correct_grad, const CConfig* config) | ||
| : CAvgGrad_Scalar<FlowIndices>(val_nDim, val_nVar, correct_grad, config), | ||
| sigma_k1(constants[0]), | ||
| sigma_k2(constants[1]), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,18 +49,31 @@ FORCEINLINE MatrixDbl<nVar,nDim> averageGradient(Int iPoint, Int jPoint, | |
| return avgGrad; | ||
| } | ||
|
|
||
| template<size_t nSecVar, class SecondaryType> | ||
| FORCEINLINE CCompressibleSecondary<nSecVar> averageSecondary(Int iPoint, Int jPoint, | ||
| const SecondaryType& secondary) { | ||
|
|
||
| CCompressibleSecondary<nSecVar> out; | ||
| auto second_i = gatherVariables<nSecVar>(iPoint, secondary); | ||
| auto second_j = gatherVariables<nSecVar>(jPoint, secondary); | ||
| for (size_t iVar = 0; iVar < nSecVar; ++iVar) { | ||
| out.all(iVar) = 0.5 * (second_i(iVar) + second_j(iVar)); | ||
| } | ||
| return out; | ||
| } | ||
|
|
||
| /*! | ||
| * \brief Correct average gradient with the directional derivative to avoid decoupling. | ||
| */ | ||
| template<size_t nVar, size_t nDim, class PrimitiveType> | ||
| FORCEINLINE void correctGradient(const PrimitiveType& V, | ||
| const VectorDbl<nDim>& vector_ij, | ||
| Double dist2_ij, | ||
| const VectorDbl<nDim>& diss, | ||
| MatrixDbl<nVar,nDim>& avgGrad) { | ||
| for (size_t iVar = 0; iVar < nVar; ++iVar) { | ||
| Double corr = (dot(avgGrad[iVar],vector_ij) - V.j.all(iVar) + V.i.all(iVar)) / dist2_ij; | ||
| Double corr = ( V.j.all(iVar) - V.i.all(iVar) - dot(avgGrad[iVar],vector_ij)); | ||
| for (size_t iDim = 0; iDim < nDim; ++iDim) { | ||
| avgGrad(iVar,iDim) -= corr * vector_ij(iDim); | ||
| avgGrad(iVar,iDim) += corr * diss(iDim); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -71,12 +71,16 @@ | |||||||||||||||||||||||||
| class CCompressibleViscousFluxBase : public CNumericsSIMD { | ||||||||||||||||||||||||||
| protected: | ||||||||||||||||||||||||||
| static constexpr size_t nDim = NDIM; | ||||||||||||||||||||||||||
| static constexpr size_t nPrimVarGrad = nDim+1; | ||||||||||||||||||||||||||
| static constexpr size_t nPrimVarGrad = nDim+3; | ||||||||||||||||||||||||||
| static constexpr size_t nSeconVar = 8; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const su2double gamma; | ||||||||||||||||||||||||||
| const su2double gasConst; | ||||||||||||||||||||||||||
| const su2double prandtlTurb; | ||||||||||||||||||||||||||
| const bool correct; | ||||||||||||||||||||||||||
| //const su2double cp; | ||||||||||||||||||||||||||
Check noticeCode scanning / CodeQL Commented-out code Note
This comment appears to contain commented-out code.
Copilot AutofixAI about 2 months ago The best way to fix this problem is to remove the commented-out code line
Suggested changeset
1
SU2_CFD/include/numerics_simd/flow/diffusion/viscous_fluxes.hpp
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
||||||||||||||||||||||||||
| const bool correct_EN; | ||||||||||||||||||||||||||
| const bool correct_FT; | ||||||||||||||||||||||||||
| const bool correct_AD; | ||||||||||||||||||||||||||
| const bool useSA_QCR; | ||||||||||||||||||||||||||
| const bool wallFun; | ||||||||||||||||||||||||||
| const bool uq; | ||||||||||||||||||||||||||
|
|
@@ -96,7 +100,9 @@ | |||||||||||||||||||||||||
| gamma(config.GetGamma()), | ||||||||||||||||||||||||||
| gasConst(config.GetGas_ConstantND()), | ||||||||||||||||||||||||||
| prandtlTurb(config.GetPrandtl_Turb()), | ||||||||||||||||||||||||||
| correct(iMesh == MESH_0), | ||||||||||||||||||||||||||
| correct_EN(iMesh == MESH_0 && config.GetKind_ViscousGradCorr() == VISCOUS_GRAD_CORR::EDGE_NORMAL), | ||||||||||||||||||||||||||
| correct_FT(iMesh == MESH_0 && config.GetKind_ViscousGradCorr() == VISCOUS_GRAD_CORR::FACE_TANGENT), | ||||||||||||||||||||||||||
| correct_AD(iMesh == MESH_0 && config.GetKind_ViscousGradCorr() == VISCOUS_GRAD_CORR::ALPHA_DAMPING), | ||||||||||||||||||||||||||
| useSA_QCR(config.GetSAParsedOptions().qcr2000), | ||||||||||||||||||||||||||
| wallFun(config.GetWall_Functions()), | ||||||||||||||||||||||||||
| uq(config.GetSSTParsedOptions().uq), | ||||||||||||||||||||||||||
|
|
@@ -135,6 +141,7 @@ | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const auto& solution = static_cast<const CNSVariable&>(solution_); | ||||||||||||||||||||||||||
| const auto& gradient = solution.GetGradient_Primitive(); | ||||||||||||||||||||||||||
| const auto& secondary = solution.GetSecondary(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /*--- Compute distance and handle zero without "ifs" by making it large. ---*/ | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -145,7 +152,22 @@ | |||||||||||||||||||||||||
| /*--- Compute the corrected mean gradient. ---*/ | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| auto avgGrad = averageGradient<nPrimVarGrad,nDim>(iPoint, jPoint, gradient); | ||||||||||||||||||||||||||
| if(correct) correctGradient(V, vector_ij, dist2_ij, avgGrad); | ||||||||||||||||||||||||||
| auto avgSecond = averageSecondary<nSeconVar>(iPoint, jPoint, secondary); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Double eDn = dot(vector_ij,unitNormal); | ||||||||||||||||||||||||||
| mask = eDn < EPS; | ||||||||||||||||||||||||||
| eDn += mask / (EPS); | ||||||||||||||||||||||||||
| const Double eDotN = Double(1.0) / eDn; | ||||||||||||||||||||||||||
| const Double alpha = Double(4.0) / 3.0; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| VectorDbl<nDim> diss; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if(correct_EN) for (int iDim = 0; iDim < nDim; ++iDim) diss(iDim) = vector_ij(iDim) / dist2_ij; | ||||||||||||||||||||||||||
| else if(correct_FT) for (int iDim = 0; iDim < nDim; ++iDim) diss(iDim) = unitNormal(iDim) * eDotN; | ||||||||||||||||||||||||||
| else if(correct_AD) for (int iDim = 0; iDim < nDim; ++iDim) diss(iDim) = unitNormal(iDim) * alpha * abs(eDotN); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (correct_EN || correct_FT || correct_AD) | ||||||||||||||||||||||||||
| correctGradient(V, vector_ij, diss, avgGrad); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /*--- Stress and heat flux tensors. ---*/ | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
Check warning
Code scanning / CodeQL
Missing enum case in switch Warning
Copilot Autofix
AI about 2 months ago
To fix the problem, all enum members of
VISCOUS_GRAD_CORRused in the switch statement should be handled explicitly or, alternatively, adefaultcase should be added. The best way to proceed here is to add a case forVISCOUS_GRAD_CORR::NONEto document intent and control the handling for this value. IfNONEshould have specific behavior, provide the logic; otherwise, you can make it explicit that nothing should be done (e.g., leavedissat0.0). Adding a comment may further clarify intent.Make this change directly in the
ComputeProjectedGradientfunction, at the switch statement oncorrect(lines 676–687).