From 1593583e8dbb415fc8beb47eab9b7abd670cf5bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Fri, 31 Mar 2023 15:18:12 +0200 Subject: [PATCH] fix: NaN in CourbeRemous results due to negative Y values in Calc_Y_RK4() refs #339 --- src/open-channel/remous.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/open-channel/remous.ts b/src/open-channel/remous.ts index 2e2f15a8..7eab9c0c 100644 --- a/src/open-channel/remous.ts +++ b/src/open-channel/remous.ts @@ -757,7 +757,7 @@ export class CourbeRemous extends SectionNub { } // let k2 = this.Calc_dYdX(Y + Dx / 2 * k1); - const rDXDY2: Result = this.Calc_dYdX(Y + rDx / 2 * k1); + const rDXDY2: Result = this.Calc_dYdX(Math.max(Y + rDx / 2 * k1, 0)); if (!rDXDY2.ok) { return rDXDY2; } @@ -768,7 +768,7 @@ export class CourbeRemous extends SectionNub { } // let k3 = this.Calc_dYdX(Y + Dx / 2 * k2); - const rDXDY3: Result = this.Calc_dYdX(Y + rDx / 2 * k2); + const rDXDY3: Result = this.Calc_dYdX(Math.max(Y + rDx / 2 * k2, 0)); if (!rDXDY3.ok) { return rDXDY3; } @@ -779,14 +779,14 @@ export class CourbeRemous extends SectionNub { } // let k4 = this.Calc_dYdX(Y + Dx * k3); - const rDXDY4: Result = this.Calc_dYdX(Y + rDx * k3); + const rDXDY4: Result = this.Calc_dYdX(Math.max(Y + rDx * k3, 0)); if (!rDXDY4.ok) { return rDXDY4; } const k4 = rDXDY4.vCalc; // tslint:disable-next-line:variable-name - const Yout = Y + rDx / 6 * (k1 + 2 * (k2 + k3) + k4); + const Yout = Math.max(Y + rDx / 6 * (k1 + 2 * (k2 + k3) + k4), 0); // if ($this ->rDx > 0 xor !($Yout < $this ->oSect ->rHautCritique)) { return false; } if (XOR(rDx > 0, !(Yout < hc))) { -- GitLab