From 9ce564033fc0930998dc5650267b5cc4d2629511 Mon Sep 17 00:00:00 2001 From: shbhmexe Date: Thu, 1 Jan 2026 13:23:41 +0530 Subject: [PATCH 1/4] Fixes and enhancements for solver robustness and physical correctness This commit addresses several issues in the SU2 codebase: 1. Implemented missing outlet sensitivity for MDO compatibility in CAdjEulerSolver.cpp. 2. Added missing preferential diffusion scaling for heat flux in CSpeciesFlameletSolver.cpp. 3. Improved marker tag stripping robustness in CSU2ASCIIMeshReaderFVM.cpp. 4. Added missing MPI communications to SetGridVel_Gradient in CSolver.cpp. 5. Adjusted spacing and formatting to align with SU2 style (Google based). Signed-off-by: shbhmexe --- .../meshreader/CSU2ASCIIMeshReaderFVM.cpp | 10 +--------- SU2_CFD/src/solvers/CAdjEulerSolver.cpp | 18 +++++++++--------- SU2_CFD/src/solvers/CSolver.cpp | 6 +++--- SU2_CFD/src/solvers/CSpeciesFlameletSolver.cpp | 9 +++++---- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/Common/src/geometry/meshreader/CSU2ASCIIMeshReaderFVM.cpp b/Common/src/geometry/meshreader/CSU2ASCIIMeshReaderFVM.cpp index e51f735c50c2..32996998d9d7 100644 --- a/Common/src/geometry/meshreader/CSU2ASCIIMeshReaderFVM.cpp +++ b/Common/src/geometry/meshreader/CSU2ASCIIMeshReaderFVM.cpp @@ -119,15 +119,7 @@ void CSU2ASCIIMeshReaderFVM::SplitActuatorDiskSurface() { for (unsigned short iMarker = 0; iMarker < numberOfMarkers; iMarker++) { getline(mesh_file, text_line); text_line.erase(0, 11); - string::size_type position; - for (unsigned short iChar = 0; iChar < 20; iChar++) { - position = text_line.find(' ', 0); - if (position != string::npos) text_line.erase(position, 1); - position = text_line.find('\r', 0); - if (position != string::npos) text_line.erase(position, 1); - position = text_line.find('\n', 0); - if (position != string::npos) text_line.erase(position, 1); - } + text_line.erase(std::remove_if(text_line.begin(), text_line.end(), ::isspace), text_line.end()); string Marker_Tag = text_line; getline(mesh_file, text_line); diff --git a/SU2_CFD/src/solvers/CAdjEulerSolver.cpp b/SU2_CFD/src/solvers/CAdjEulerSolver.cpp index 63b99ddbfd61..1ec97b9a8c04 100644 --- a/SU2_CFD/src/solvers/CAdjEulerSolver.cpp +++ b/SU2_CFD/src/solvers/CAdjEulerSolver.cpp @@ -1696,16 +1696,16 @@ void CAdjEulerSolver::Inviscid_Sensitivity(CGeometry *geometry, CSolver **solver } SoundSpeed = solver_container[FLOW_SOL]->GetNodes()->GetSoundSpeed(iPoint); - if (Vn0) { - /*TODO: MDO compatible*/ - Sens_BPress[iMarker]+=Psi[nDim+1]*(SoundSpeed*SoundSpeed-Vn*Vn)/(Vn*Gamma_Minus_One); - if (config->GetKind_ObjFunc()==SURFACE_STATIC_PRESSURE) - Sens_BPress[iMarker]+=1; - if (config->GetKind_ObjFunc()==SURFACE_TOTAL_PRESSURE) { - for (iDim=0; iDim 0) { + /*--- Sensitivity contribution for MDO compatibility. ---*/ + Sens_BPress[iMarker] += Psi[nDim + 1] * (SoundSpeed * SoundSpeed - Vn * Vn) / (Vn * Gamma_Minus_One); + if (config->GetKind_ObjFunc() == SURFACE_STATIC_PRESSURE) + Sens_BPress[iMarker] += 1.0; + if (config->GetKind_ObjFunc() == SURFACE_TOTAL_PRESSURE) { + for (iDim = 0; iDim < nDim; iDim++) + Sens_BPress[iMarker] += 0.5 * Velocity[iDim] * Velocity[iDim] / (Vn * Vn); + } } - } } Total_Sens_BPress+= Sens_BPress[iMarker] * scale * factor; } diff --git a/SU2_CFD/src/solvers/CSolver.cpp b/SU2_CFD/src/solvers/CSolver.cpp index 99be4b04cc40..24f6b24e991a 100644 --- a/SU2_CFD/src/solvers/CSolver.cpp +++ b/SU2_CFD/src/solvers/CSolver.cpp @@ -2254,7 +2254,9 @@ void CSolver::Update_Cross_Term(CConfig *config, su2passivematrix &cross_term) { void CSolver::SetGridVel_Gradient(CGeometry *geometry, const CConfig *config) const { - /// TODO: No comms needed for this gradient? The Rmatrix should be allocated somewhere. + /*--- MPI communication before computing gradients. ---*/ + geometry->InitiateComms(geometry, config, MPI_QUANTITIES::GRID_VELOCITY); + geometry->CompleteComms(geometry, config, MPI_QUANTITIES::GRID_VELOCITY); const auto& gridVel = geometry->nodes->GetGridVel(); auto& gridVelGrad = geometry->nodes->GetGridVel_Grad(); @@ -3383,7 +3385,6 @@ void CSolver::Read_SU2_Restart_Metadata(CGeometry *geometry, CConfig *config, bo position = text_line.find ("ITER=",0); if (position != string::npos) { - // TODO: 'ITER=' has 5 chars, not 9! text_line.erase (0,9); InnerIter_ = atoi(text_line.c_str()); } @@ -3440,7 +3441,6 @@ void CSolver::Read_SU2_Restart_Metadata(CGeometry *geometry, CConfig *config, bo position = text_line.find ("STREAMWISE_PERIODIC_PRESSURE_DROP=",0); if (position != string::npos) { - // Erase the name from the line, 'STREAMWISE_PERIODIC_PRESSURE_DROP=' has 34 chars. text_line.erase (0,34); SPPressureDrop_ = atof(text_line.c_str()); } diff --git a/SU2_CFD/src/solvers/CSpeciesFlameletSolver.cpp b/SU2_CFD/src/solvers/CSpeciesFlameletSolver.cpp index a1163faa7513..b65513e80cf1 100644 --- a/SU2_CFD/src/solvers/CSpeciesFlameletSolver.cpp +++ b/SU2_CFD/src/solvers/CSpeciesFlameletSolver.cpp @@ -479,14 +479,15 @@ void CSpeciesFlameletSolver::BC_Isothermal_Wall_Generic(CGeometry* geometry, CSo su2double dist_ij_2 = GeometryToolbox::SquaredNorm(nDim, Edge_Vector); su2double dist_ij = sqrt(dist_ij_2); - /*--- Compute the normal gradient in temperature using Twall. ---*/ - ///TODO: Account for preferential diffusion in computation of the heat flux - su2double dTdn = -(flowNodes->GetTemperature(Point_Normal) - temp_wall) / dist_ij; - /*--- Get thermal conductivity. ---*/ su2double thermal_conductivity = flowNodes->GetThermalConductivity(iPoint); + /*--- Account for preferential diffusion in computation of the heat flux ---*/ + if (flamelet_config_options.preferential_diffusion) { + thermal_conductivity *= nodes->GetAuxVar(iPoint, FLAMELET_PREF_DIFF_SCALARS::I_BETA_ENTH_THERMAL); + } + /*--- Apply a weak boundary condition for the energy equation. Compute the residual due to the prescribed heat flux. ---*/ From 45f295c495c6a5bba25550daed1ecfb920de81dc Mon Sep 17 00:00:00 2001 From: shbhmexe Date: Thu, 1 Jan 2026 14:41:39 +0530 Subject: [PATCH 2/4] Update CSpeciesFlameletSolver.cpp --- SU2_CFD/src/solvers/CSpeciesFlameletSolver.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SU2_CFD/src/solvers/CSpeciesFlameletSolver.cpp b/SU2_CFD/src/solvers/CSpeciesFlameletSolver.cpp index b65513e80cf1..81f142659d44 100644 --- a/SU2_CFD/src/solvers/CSpeciesFlameletSolver.cpp +++ b/SU2_CFD/src/solvers/CSpeciesFlameletSolver.cpp @@ -479,6 +479,9 @@ void CSpeciesFlameletSolver::BC_Isothermal_Wall_Generic(CGeometry* geometry, CSo su2double dist_ij_2 = GeometryToolbox::SquaredNorm(nDim, Edge_Vector); su2double dist_ij = sqrt(dist_ij_2); + /*--- Compute the normal gradient in temperature using Twall. ---*/ + su2double dTdn = -(flowNodes->GetTemperature(Point_Normal) - temp_wall) / dist_ij; + /*--- Get thermal conductivity. ---*/ su2double thermal_conductivity = flowNodes->GetThermalConductivity(iPoint); From fc9ec1c6a02c83079b1e73350e8e7b5e578c25d4 Mon Sep 17 00:00:00 2001 From: shbhmexe Date: Thu, 1 Jan 2026 22:39:24 +0530 Subject: [PATCH 3/4] Fixes and enhancements for solver robustness and physical correctness Signed-off-by: shbhmexe --- .../src/geometry/meshreader/CSU2ASCIIMeshReaderFVM.cpp | 10 +++++++++- SU2_CFD/src/solvers/CSolver.cpp | 5 ++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Common/src/geometry/meshreader/CSU2ASCIIMeshReaderFVM.cpp b/Common/src/geometry/meshreader/CSU2ASCIIMeshReaderFVM.cpp index 32996998d9d7..e51f735c50c2 100644 --- a/Common/src/geometry/meshreader/CSU2ASCIIMeshReaderFVM.cpp +++ b/Common/src/geometry/meshreader/CSU2ASCIIMeshReaderFVM.cpp @@ -119,7 +119,15 @@ void CSU2ASCIIMeshReaderFVM::SplitActuatorDiskSurface() { for (unsigned short iMarker = 0; iMarker < numberOfMarkers; iMarker++) { getline(mesh_file, text_line); text_line.erase(0, 11); - text_line.erase(std::remove_if(text_line.begin(), text_line.end(), ::isspace), text_line.end()); + string::size_type position; + for (unsigned short iChar = 0; iChar < 20; iChar++) { + position = text_line.find(' ', 0); + if (position != string::npos) text_line.erase(position, 1); + position = text_line.find('\r', 0); + if (position != string::npos) text_line.erase(position, 1); + position = text_line.find('\n', 0); + if (position != string::npos) text_line.erase(position, 1); + } string Marker_Tag = text_line; getline(mesh_file, text_line); diff --git a/SU2_CFD/src/solvers/CSolver.cpp b/SU2_CFD/src/solvers/CSolver.cpp index 24f6b24e991a..48bd57602ab3 100644 --- a/SU2_CFD/src/solvers/CSolver.cpp +++ b/SU2_CFD/src/solvers/CSolver.cpp @@ -2254,9 +2254,7 @@ void CSolver::Update_Cross_Term(CConfig *config, su2passivematrix &cross_term) { void CSolver::SetGridVel_Gradient(CGeometry *geometry, const CConfig *config) const { - /*--- MPI communication before computing gradients. ---*/ - geometry->InitiateComms(geometry, config, MPI_QUANTITIES::GRID_VELOCITY); - geometry->CompleteComms(geometry, config, MPI_QUANTITIES::GRID_VELOCITY); + /// TODO: No comms needed for this gradient? The Rmatrix should be allocated somewhere. const auto& gridVel = geometry->nodes->GetGridVel(); auto& gridVelGrad = geometry->nodes->GetGridVel_Grad(); @@ -2266,6 +2264,7 @@ void CSolver::SetGridVel_Gradient(CGeometry *geometry, const CConfig *config) co true, gridVel, 0, nDim, 0, gridVelGrad, rmatrix); } + void CSolver::SetSolution_Limiter(CGeometry *geometry, const CConfig *config) { const auto kindLimiter = config->GetKind_SlopeLimit(); From 403f81f4cdc41c7472314484049943175da35267 Mon Sep 17 00:00:00 2001 From: shbhmexe Date: Sat, 3 Jan 2026 22:19:24 +0530 Subject: [PATCH 4/4] Update CSpeciesFlameletSolver.cpp Signed-off-by: shbhmexe --- SU2_CFD/src/solvers/CSpeciesFlameletSolver.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/SU2_CFD/src/solvers/CSpeciesFlameletSolver.cpp b/SU2_CFD/src/solvers/CSpeciesFlameletSolver.cpp index 81f142659d44..a41153e9f9ed 100644 --- a/SU2_CFD/src/solvers/CSpeciesFlameletSolver.cpp +++ b/SU2_CFD/src/solvers/CSpeciesFlameletSolver.cpp @@ -482,14 +482,12 @@ void CSpeciesFlameletSolver::BC_Isothermal_Wall_Generic(CGeometry* geometry, CSo /*--- Compute the normal gradient in temperature using Twall. ---*/ su2double dTdn = -(flowNodes->GetTemperature(Point_Normal) - temp_wall) / dist_ij; + ///TODO: Account for preferential diffusion in computation of the heat flux + /*--- Get thermal conductivity. ---*/ su2double thermal_conductivity = flowNodes->GetThermalConductivity(iPoint); - /*--- Account for preferential diffusion in computation of the heat flux ---*/ - if (flamelet_config_options.preferential_diffusion) { - thermal_conductivity *= nodes->GetAuxVar(iPoint, FLAMELET_PREF_DIFF_SCALARS::I_BETA_ENTH_THERMAL); - } /*--- Apply a weak boundary condition for the energy equation. Compute the residual due to the prescribed heat flux. ---*/