Skip to content

Commit e50c65a

Browse files
committed
fix: Fix five bugs based on reviewer feedback
Fixed three critical division by zero bugs and two moderate bugs: 1. Wall model convergence - zero-check before division 2. Wall model Gamma - protect against very small Gamma (use 1.0E-16 threshold) 3. Radiation emissivity - throw error if outside [0,1] range 4. Restart metadata - correct ITER= offset 9->5 5. Filename buffer - replace strcpy with strncpy Changes based on reviewer feedback: - CRadP1Solver.cpp: Error instead of silent clamp for invalid emissivity - wall_model.cpp: Fixed Gamma logic (always negative, exp_term=0 for small |Gamma|) Improves solver stability, correctness, and security. Signed-off-by: shbhmexe <[email protected]>
2 parents 2238d81 + dac92cc commit e50c65a

File tree

2 files changed

+20
-33
lines changed

2 files changed

+20
-33
lines changed

Common/src/wall_model.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -394,20 +394,21 @@ void CWallModelLogLaw::WallShearStressAndHeatFlux(const su2double tExchange, con
394394
const su2double lhs = -((tExchange - TWall) * rho_wall * c_p * u_tau);
395395
const su2double Gamma = -(0.01 * (Pr_lam * pow(y_plus, 4.0)) / (1.0 + 5.0 * y_plus * pow(Pr_lam, 3.0)));
396396
const su2double rhs_1 = Pr_lam * y_plus * exp(Gamma);
397-
398-
/* Protect against division by zero in exp(1/Gamma) when Gamma is very small */
399-
const su2double eps_gamma = 1e-20;
397+
398+
/* Protect against division by zero in exp(1/Gamma) when Gamma is very small.
399+
* Note: Gamma is always negative due to the minus sign in its formula.
400+
* When abs(Gamma) is very small, exp(1/Gamma) approaches 0 (since 1/Gamma -> -inf).
401+
*/
400402
su2double exp_term;
401-
if (abs(Gamma) > eps_gamma) {
403+
if (abs(Gamma) > 1.0E-16) {
402404
exp_term = exp(1.0 / Gamma);
403405
} else {
404-
/* For very small Gamma, cap the exponential to prevent overflow/division by zero */
405-
exp_term = (Gamma > 0) ? exp(1.0 / eps_gamma) : exp(-1.0 / eps_gamma);
406+
/* For very small |Gamma|, exp(1/Gamma) -> 0 since Gamma is negative */
407+
exp_term = 0.0;
406408
}
407-
409+
408410
const su2double rhs_2 =
409-
(2.12 * log(1.0 + y_plus) + pow((3.85 * pow(Pr_lam, (1.0 / 3.0)) - 1.3), 2.0) + 2.12 * log(Pr_lam)) *
410-
exp_term;
411+
(2.12 * log(1.0 + y_plus) + pow((3.85 * pow(Pr_lam, (1.0 / 3.0)) - 1.3), 2.0) + 2.12 * log(Pr_lam)) * exp_term;
411412
qWall = lhs / (rhs_1 + rhs_2);
412413
} else {
413414
qWall = Wall_HeatFlux;

SU2_CFD/src/solvers/CRadP1Solver.cpp

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -282,18 +282,15 @@ void CRadP1Solver::BC_Isothermal_Wall(CGeometry *geometry, CSolver **solver_cont
282282
/*--- Get the specified wall emissivity from config ---*/
283283
Wall_Emissivity = config->GetWall_Emissivity(Marker_Tag);
284284

285-
/*--- Clamp emissivity to valid physical range [0,1] to prevent division by zero ---*/
286-
if (Wall_Emissivity < 0.0) {
287-
Wall_Emissivity = 0.0;
288-
}
289-
if (Wall_Emissivity > 1.0) {
290-
Wall_Emissivity = 1.0;
285+
/*--- Validate emissivity is in physical range [0,1] ---*/
286+
if (Wall_Emissivity < 0.0 || Wall_Emissivity > 1.0) {
287+
SU2_MPI::Error("Wall emissivity must be in range [0,1].", CURRENT_FUNCTION);
291288
}
292289

293290
/*--- Compute the constant for the wall theta ---*/
294291
Theta = Wall_Emissivity / (2.0*(2.0 - Wall_Emissivity));
295292

296-
/*--- Retrieve the specified wall temperature ---*/
293+
/*--- Retrieve the specified wall temperature ---*/
297294
Twall = config->GetIsothermal_Temperature(Marker_Tag)/config->GetTemperature_Ref();
298295

299296
/*--- Loop over all of the vertices on this boundary marker ---*/
@@ -364,12 +361,9 @@ void CRadP1Solver::BC_Far_Field(CGeometry *geometry, CSolver **solver_container,
364361
/*--- Get the specified wall emissivity from config ---*/
365362
Wall_Emissivity = config->GetWall_Emissivity(Marker_Tag);
366363

367-
/*--- Clamp emissivity to valid physical range [0,1] to prevent division by zero ---*/
368-
if (Wall_Emissivity < 0.0) {
369-
Wall_Emissivity = 0.0;
370-
}
371-
if (Wall_Emissivity > 1.0) {
372-
Wall_Emissivity = 1.0;
364+
/*--- Validate emissivity is in physical range [0,1] ---*/
365+
if (Wall_Emissivity < 0.0 || Wall_Emissivity > 1.0) {
366+
SU2_MPI::Error("Wall emissivity must be in range [0,1].", CURRENT_FUNCTION);
373367
}
374368

375369
/*--- Compute the constant for the wall theta ---*/
@@ -446,18 +440,10 @@ void CRadP1Solver::BC_Marshak(CGeometry *geometry, CSolver **solver_container, C
446440
/*--- Get the specified wall emissivity from config ---*/
447441
Wall_Emissivity = config->GetWall_Emissivity(Marker_Tag);
448442

449-
/*--- Clamp emissivity to valid physical range [0,1] to prevent division by zero ---*/
450-
<<<<<<< HEAD
451-
if (Wall_Emissivity < 0.0) {
452-
Wall_Emissivity = 0.0;
453-
}
454-
if (Wall_Emissivity > 1.0) {
455-
Wall_Emissivity = 1.0;
443+
/*--- Validate emissivity is in physical range [0,1] ---*/
444+
if (Wall_Emissivity < 0.0 || Wall_Emissivity > 1.0) {
445+
SU2_MPI::Error("Wall emissivity must be in range [0,1].", CURRENT_FUNCTION);
456446
}
457-
=======
458-
if (Wall_Emissivity < 0.0) Wall_Emissivity = 0.0;
459-
if (Wall_Emissivity > 1.0) Wall_Emissivity = 1.0;
460-
>>>>>>> 46baac1286ba393e261fef83bced67d0d4d3f269
461447

462448
/*--- Compute the constant for the wall theta ---*/
463449
Theta = Wall_Emissivity / (2.0*(2.0 - Wall_Emissivity));

0 commit comments

Comments
 (0)