From fa4e9c8dcd4af13e0ad41f9870070775abfe417a Mon Sep 17 00:00:00 2001
From: "francois.grand" <francois.grand@irstea.fr>
Date: Thu, 1 Jun 2017 11:18:53 +0200
Subject: [PATCH] section_circulaire.ts : ajout isDebordement(),
 valeurDebordement()

---
 src/section/section_circulaire.ts | 115 ++++++++++++++++++++++--------
 1 file changed, 87 insertions(+), 28 deletions(-)

diff --git a/src/section/section_circulaire.ts b/src/section/section_circulaire.ts
index 8740c7bd..f2425f04 100644
--- a/src/section/section_circulaire.ts
+++ b/src/section/section_circulaire.ts
@@ -13,34 +13,82 @@ export class cSnCirc extends acSection {
         constructor(oLog: cLog, oP: cParamsCanal, D: number, dbg: boolean = false) {
                 super(oLog, oP, dbg);
                 this.v.D = D;
-                if (oP.v.YB > D) { oP.v.YB = D; } // On place la berge au sommet du cercle
+                // commenté car si D est la variable à déterminer, il peut valoir n'importe quoi... if (oP.v.YB > D) { oP.v.YB = D; } // On place la berge au sommet du cercle 
         }
+
+        /**
+         * valeur du débordement
+         * Le tirant d'eau est soustrait soit à la côte de berge, soit au diamètre
+         * au cas où le canal soit "enterré" (côte de berge > diamètre)
+         */
+        private valeurYDebordement(): number {
+                // this.debug('deb');
+                // this.debug('YB ' + this.v.YB);
+                // this.debug('D ' + this.v.D);
+                // this.debug('min ' + Math.min(this.v.YB, this.v.D));
+                // this.debug('Y ' + this.v.Y);
+
+                // let min = Math.min(this.v.YB, this.v.D);
+                // this.debug('min( YB(=' + this.v.YB + '), D(=' + this.v.D + ')) = ' + min);
+                // this.debug('max(0, Y(=' + this.v.Y + ') - min(YB, D)(=' + min + ') = ' + Math.max(0, this.v.Y - Math.min(this.v.YB, this.v.D)));
+                // return Math.max(0, this.v.Y - Math.min(this.v.YB, this.v.D));
+                return this.v.Y - Math.min(this.v.YB, this.v.D); // >= 0 par définition, et toujours vrai car utilisé après test isDebordement()
+
+                // if (this.isDebordement())
+                //       return this.v.Y - this.v.YB;
+
+                // return 0;
+        }
+
+        /**
+         * teste le débordement.
+         * @returns true en cas de débordement
+         */
+        private isDebordement(): boolean {
+                // return this.v.Y > Math.min(this.v.YB, this.v.D);
+                //return this.valeurYDebordement() > 0;
+                return this.v.Y >= this.v.D || this.v.Y >= this.v.YB
+        }
+
         /**
          * Calcul de l'angle Alpha de la surface libre par rapport au fond.
          * @return Alpha
          */
+        // Calc_Alpha() {
+        //         if (this.v.Y > this.oP.v.YB) {
+        //                 // var rY = this.oP.v.YB;
+        //                 var rY = this.v.YB;
+        //         }
+        //         else {
+        //                 rY = this.v.Y;
+        //         }
+        //         if (rY <= 0) {
+        //                 return 0;
+        //         }
+        //         else if (rY > this.v.D) {
+        //                 return Math.PI;
+        //         }
+        //         else {
+        //                 var alpha = Math.acos(1. - rY / (this.v.D / 2.));
+        //                 if (alpha > Math.PI) {
+        //                         return Math.PI;
+        //                 }
+        //                 else {
+        //                         return alpha;
+        //                 }
+        //         }
+        // }
         Calc_Alpha() {
-                if (this.v.Y > this.oP.v.YB) {
-                        var rY = this.oP.v.YB;
-                }
-                else {
-                        rY = this.v.Y;
-                }
-                if (rY <= 0) {
+                if (this.v.Y <= 0)
                         return 0;
-                }
-                else if (rY > this.v.D) {
+                if (this.isDebordement())
                         return Math.PI;
-                }
-                else {
-                        var alpha = Math.acos(1. - rY / (this.v.D / 2.));
-                        if (alpha > Math.PI) {
-                                return Math.PI;
-                        }
-                        else {
-                                return alpha;
-                        }
-                }
+
+                let alpha = Math.acos(1. - this.v.Y / (this.v.D / 2.));
+                if (alpha > Math.PI)
+                        return Math.PI;
+
+                return alpha;
         }
 
         /**
@@ -48,7 +96,8 @@ export class cSnCirc extends acSection {
          * @return dAlpha
          */
         Calc_dAlpha() {
-                if (this.v.Y <= 0 || this.v.Y >= this.v.D || this.v.Y > this.oP.v.YB) {
+                // if (this.v.Y <= 0 || this.v.Y >= this.v.D || this.v.Y > this.oP.v.YB) {
+                if (this.v.Y <= 0 || this.isDebordement()) {
                         return 0;
                 }
                 else {
@@ -61,7 +110,8 @@ export class cSnCirc extends acSection {
          * @return B
          */
         Calc_B() {
-                if (this.v.Y > this.oP.v.YB) {
+                // if (this.v.Y > this.oP.v.YB) {
+                if (this.isDebordement()) {
                         return super.Calc_B_Debordement();
                 }
                 else {
@@ -75,9 +125,11 @@ export class cSnCirc extends acSection {
          * @return B
          */
         Calc_P(rY = 0) {
-                if (this.v.Y > this.oP.v.YB && !this.bSnFermee) {
+                // if (this.v.Y > this.oP.v.YB && !this.bSnFermee) {
+                if (this.isDebordement() && !this.bSnFermee) {
                         // On n'ajoute pas le périmètre dans le cas d'une fente de Preissmann
-                        return this.CalcGeo('P') + super.Calc_P_Debordement(this.v.Y - this.oP.v.YB);
+                        // return this.CalcGeo('P') + super.Calc_P_Debordement(this.v.Y - this.oP.v.YB);
+                        return this.CalcGeo('P') + super.Calc_P_Debordement(this.valeurYDebordement());
                 }
                 else {
                         return this.v.D * this.Calc('Alpha');
@@ -90,8 +142,10 @@ export class cSnCirc extends acSection {
          * @return S
          */
         Calc_S(rY = 0) {
-                if (this.v.Y > this.oP.v.YB) {
-                        return this.CalcGeo('S') + super.Calc_S_Debordement(this.v.Y - this.oP.v.YB);
+                // if (this.v.Y > this.oP.v.YB) {
+                if (this.isDebordement() && !this.bSnFermee) {
+                        // return this.CalcGeo('S') + super.Calc_S_Debordement(this.v.Y - this.oP.v.YB);
+                        return this.CalcGeo('S') + super.Calc_S_Debordement(this.valeurYDebordement());
                 }
                 else {
                         return Math.pow(this.v.D, 2) / 4 * (this.Calc('Alpha') - Math.sin(this.Calc('Alpha')) * Math.cos(this.Calc('Alpha')));
@@ -104,25 +158,29 @@ export class cSnCirc extends acSection {
          * @return dP
          */
         Calc_dP() {
-                if (this.v.Y > this.oP.v.YB && !this.bSnFermee) {
+                // if (this.v.Y > this.oP.v.YB && !this.bSnFermee) {
+                if (this.isDebordement() && !this.bSnFermee) {
                         return super.Calc_dP_Debordement();
                 }
                 else {
                         return this.v.D * this.Calc('dAlpha');
                 }
         }
+
         /**
          * Calcul de dérivée de la largeur au miroir par rapport au tirant d'eau.
          * @return dB
          */
         Calc_dB() {
-                if (this.v.Y > this.oP.v.YB) {
+                // if (this.v.Y > this.oP.v.YB) {
+                if (this.isDebordement()) {
                         return super.Calc_dB_Debordement();
                 }
                 else {
                         return this.v.D * this.Calc('dAlpha') * Math.cos(this.Calc('Alpha'));
                 }
         }
+
         /**
          * Calcul de la distance du centre de gravité de la section à la surface libre
          * multiplié par la surface hydraulique
@@ -134,6 +192,7 @@ export class cSnCirc extends acSection {
                 SYg = Math.pow(this.v.D, 3) / 8 * SYg;
                 return SYg;
         }
+
         /**
          * Calcul de la dérivée de la distance du centre de gravité de la section à la surface libre
          * multiplié par la surface hydraulique
-- 
GitLab