From 802242fd1ef077387c387e733b69cc5244763b46 Mon Sep 17 00:00:00 2001
From: "francois.grand" <francois.grand@irstea.fr>
Date: Wed, 4 Apr 2018 10:12:21 +0200
Subject: [PATCH] =?UTF-8?q?=20#46=20:=20ajout=20du=20Nub=20pour=20les=20se?=
 =?UTF-8?q?ctions=20param=C3=A9tr=C3=A9es=20-=20Nub.CalcSerie()=20:=20ajou?=
 =?UTF-8?q?t=20d'un=20param=C3=A8tre=20pr=C3=A9cisant=20la=20variable=20?=
 =?UTF-8?q?=C3=A0=20calculer=20(n=C3=A9cessaire=20car=20les=20variables=20?=
 =?UTF-8?q?=C3=A0=20calculer=20pour=20les=20sections=20param=C3=A9tr=C3=A9?=
 =?UTF-8?q?es=20ne=20font=20pas=20partie=20des=20param=C3=A8tres=20du=20Nu?=
 =?UTF-8?q?b)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/compute-node.ts        |   4 +
 src/index.ts               |   1 +
 src/nub.ts                 |  43 +++++++---
 src/parameters.ts          | 170 -------------------------------------
 src/section/section_nub.ts | 123 ++++++++++++++++++++++++++-
 5 files changed, 156 insertions(+), 185 deletions(-)
 delete mode 100644 src/parameters.ts

diff --git a/src/compute-node.ts b/src/compute-node.ts
index acc5e5b4..cb63fe3b 100644
--- a/src/compute-node.ts
+++ b/src/compute-node.ts
@@ -44,6 +44,10 @@ export abstract class ComputeNode extends Debug {
         this._prms.DefineCalculability();
     }
 
+    public get parameters(): ParamsEquation {
+        return this._prms;
+    }
+
     public getParameter(name: string): ParamDefinition {
         return this._prms.getParameter(name);
     }
diff --git a/src/index.ts b/src/index.ts
index 17ecd1a8..92585173 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -12,6 +12,7 @@ export * from "./dichotomie";
 export * from "./lechaptcalmon";
 export * from "./regime_uniforme";
 export * from "./remous";
+export * from "./section/section_nub";
 export * from "./section/section_type";
 export * from "./section/section_trapez";
 export * from "./section/section_rectang";
diff --git a/src/nub.ts b/src/nub.ts
index 6ed251bd..9d77e19a 100644
--- a/src/nub.ts
+++ b/src/nub.ts
@@ -39,10 +39,12 @@ export abstract class Nub extends ComputeNode {
      * @param rPrec précision de calcul
      */
     public Calc(sVarCalc: string, rInit?: number, rPrec: number = 0.001): Result {
+        const computedVar = this.getParameter(sVarCalc);
+
         if (rInit === undefined) {
-            rInit = this._prms.map[sVarCalc].v;
+            rInit = computedVar.v;
         }
-        if (this._prms.map[sVarCalc].isAnalytical()) {
+        if (computedVar.isAnalytical()) {
             this._result = this.Equation(sVarCalc);
             return this._result;
         }
@@ -53,14 +55,20 @@ export abstract class Nub extends ComputeNode {
             return this._result;
         }
         const sAnalyticalPrm: string = this.getFirstAnalyticalParameter().symbol;
-        this._prms.map[sVarCalc].v = resSolve.vCalc;
+        computedVar.v = resSolve.vCalc;
         const res: Result = this.Equation(sAnalyticalPrm);
         res.vCalc = resSolve.vCalc;
         this._result = res;
         return res;
     }
 
-    public CalcSerie(rPrec: number = 0.001, rInit?: number): Result {
+    /**
+     * effectue une série de calculs sur un paramètre
+     * @param rPrec précision de calcul
+     * @param rInit solution approximative du paramètre
+     * @param sDonnee éventuel symbole du paramètre à calculer
+     */
+    public CalcSerie(rPrec: number = 0.001, rInit?: number, sDonnee?: string): Result {
         const res = new Result();
         this._result = res;
 
@@ -79,28 +87,35 @@ export abstract class Nub extends ComputeNode {
                     break;
 
                 case ParamValueMode.CALCUL:
-                    if (computedParam == undefined)
-                        computedParam = p;
-                    else
-                        throw new Error(`CalcSerie() : il y plusieurs paramètres à calculer (au moins ${computedParam.symbol} et ${p.symbol})`);
+                    if (sDonnee == undefined) {
+                        if (computedParam == undefined)
+                            computedParam = p;
+                        else
+                            throw new Error(`CalcSerie() : il y plusieurs paramètres à calculer (au moins ${computedParam.symbol} et ${p.symbol})`);
+                    }
                     break;
             }
         }
 
-        if (computedParam == undefined)
-            throw new Error(`CalcSerie() : aucun paramètre à calculer`);
+        if (sDonnee)
+            var computedSymbol: string = sDonnee;
+        else {
+            if (computedParam == undefined)
+                throw new Error(`CalcSerie() : aucun paramètre à calculer`);
+            computedSymbol = computedParam.symbol;
+        }
 
         if (rInit === undefined)
-            rInit = this._prms.map[computedParam.symbol].v;
+            rInit = this._prms.map[computedSymbol].v;
 
         if (variatedParam == undefined)
-            this.Calc(computedParam.symbol, rInit, rPrec); // résultat dans this._result
+            this.Calc(computedSymbol, rInit, rPrec); // résultat dans this._result
         else {
             const res = new Result();
             variatedParam.paramValues.initIterator();
             while (variatedParam.paramValues.hasNext) {
                 variatedParam.paramValues.next;
-                this.Calc(computedParam.symbol, rInit, rPrec);  // résultat dans this._result
+                this.Calc(computedSymbol, rInit, rPrec);  // résultat dans this._result
                 res.addResultElement(this._result.resultElement);
                 res.addLog(this._result.log);
                 if (this._result.ok)
@@ -121,7 +136,7 @@ export abstract class Nub extends ComputeNode {
     private Solve(sVarCalc: string, rInit: number, rPrec: number): Result {
         const dicho: Dichotomie = new Dichotomie(this, sVarCalc, this.DBG);
         dicho.startIntervalMaxSteps = this._dichoStartIntervalMaxSteps;
-        const target = this._prms.getFirstAnalyticalParameter();
+        const target = this.getFirstAnalyticalParameter();
         return dicho.Dichotomie(target.v, rPrec, rInit);
     }
 
diff --git a/src/parameters.ts b/src/parameters.ts
deleted file mode 100644
index 88275fa9..00000000
--- a/src/parameters.ts
+++ /dev/null
@@ -1,170 +0,0 @@
-import { ComputeNodeType, CalculatorType } from "./compute-node"
-import { ParamsEquation } from "./param/params-equation";
-import { ParamDefinition } from "./param/param-definition";
-import { ConduiteDistribParams, ConduiteDistrib } from "./cond_distri";
-import { LechaptCalmonParams, LechaptCalmon } from "./lechaptcalmon";
-import { acSection } from "./section/section_type";
-import { ParamsSectionTrapez, cSnTrapez } from "./section/section_trapez";
-import { ParamsSectionRectang, cSnRectang } from "./section/section_rectang";
-import { ParamsSectionCirc, cSnCirc } from "./section/section_circulaire";
-import { ParamsSectionPuiss, cSnPuiss } from "./section/section_puissance";
-import { RegimeUniforme } from "./regime_uniforme";
-import { CourbeRemous, CourbeRemousParams } from "./remous";
-import { PabDimensionParams, PabDimension } from "./pab/pab_dimension";
-import { PabPuissanceParams, PabPuissance } from "./pab/pab_puissance";
-import { HashTable } from "./util/hashtable";
-import { ParallelStructureParams } from "./structure/parallel_structure_params";
-import { ParallelStructure } from "./structure/parallel_structure";
-import { RectangularStructureParams } from "./structure/rectangular_structure_params";
-import { StructureCem88d } from "./structure/structure_cem88d";
-import { StructureKiviParams } from "./structure/structure_kivi_params";
-import { StructureKivi } from "./structure/structure_kivi";
-
-
-export class ComputeNodeParameters {
-    private static _instance: ComputeNodeParameters;
-
-    private _nodes: HashTable;
-
-    private constructor() {
-        this._nodes = new HashTable();
-    }
-
-    public static getInstance() {
-        if (ComputeNodeParameters._instance == undefined)
-            ComputeNodeParameters._instance = new ComputeNodeParameters();
-        return ComputeNodeParameters._instance;
-    }
-
-    private createSection(nt: ComputeNodeType): acSection {
-        switch (nt) {
-            case ComputeNodeType.None: // pour les paramètres communs, n'importe quelle section convient
-            case ComputeNodeType.SectionTrapeze:
-                {
-                    let cn = new ParamsSectionTrapez(1, 0.5, undefined, undefined,
-                        1, undefined, 0.1, 1);
-                    let n = new cSnTrapez(cn); // pour initialiser la calculabilité des paramètres
-                    return n;
-                }
-
-            case ComputeNodeType.SectionRectangle:
-                {
-                    let cn = new ParamsSectionRectang(undefined, 1, undefined, 1,
-                        undefined, 0.1, 1);
-                    let n = new cSnRectang(cn); // pour initialiser la calculabilité des paramètres
-                    return n;
-                }
-
-            case ComputeNodeType.SectionCercle:
-                {
-                    let cn = new ParamsSectionCirc(1, undefined, undefined, 1,
-                        undefined, 0.1, 1);
-                    let n = new cSnCirc(cn); // pour initialiser la calculabilité des paramètres
-                    return n;
-                }
-
-            case ComputeNodeType.SectionPuissance:
-                {
-                    let cn = new ParamsSectionPuiss(0.5, undefined, 1, undefined,
-                        1, undefined, 0.1, 1);
-                    let n = new cSnPuiss(cn); // pour initialiser la calculabilité des paramètres
-                    return n;
-                }
-
-            default:
-                throw new Error(`type de section ${ComputeNodeType[nt]} non pris en charge`);
-        }
-    }
-
-    private createComputeNodeParameters(calcType: CalculatorType, nodeType: ComputeNodeType): ParamsEquation {
-        switch (calcType) {
-            case CalculatorType.ConduiteDistributrice:
-                {
-                    const cn = new ConduiteDistribParams(undefined, undefined, undefined, undefined, undefined);
-                    const n = new ConduiteDistrib(cn); // pour initialiser la calculabilité des paramètres
-                    return cn;
-                }
-
-            case CalculatorType.LechaptCalmon:
-                {
-                    const cn = new LechaptCalmonParams(undefined, undefined, undefined, undefined, undefined, undefined, undefined);
-                    const n = new LechaptCalmon(cn); // pour initialiser la calculabilité des paramètres
-                    return cn;
-                }
-
-            case CalculatorType.SectionParametree:
-                {
-                    const sect: acSection = this.createSection(nodeType);
-                    return sect.prms;
-                }
-
-            case CalculatorType.RegimeUniforme:
-                const sect: acSection = this.createSection(nodeType);
-                const ru = new RegimeUniforme(sect); // pour initialiser la calculabilité des paramètres
-                return sect.prms;
-
-
-            case CalculatorType.CourbeRemous:
-                {
-                    const sect: acSection = this.createSection(nodeType);
-                    const crp = new CourbeRemousParams(sect, undefined, undefined, undefined, undefined, undefined);
-                    const ru = new CourbeRemous(crp); // pour initialiser la calculabilité des paramètres
-                    return crp;
-                }
-
-            case CalculatorType.PabDimensions:
-                {
-                    let cn = new PabDimensionParams(undefined, undefined, undefined);
-                    let n = new PabDimension(cn); // pour initialiser la calculabilité des paramètres
-                    return cn;
-                }
-
-            case CalculatorType.PabPuissance:
-                {
-                    let cn = new PabPuissanceParams(undefined, undefined, undefined);
-                    let n = new PabPuissance(cn); // pour initialiser la calculabilité des paramètres
-                    return cn;
-                }
-
-            case CalculatorType.Structure:
-                switch (nodeType) {
-                    case ComputeNodeType.None: // pour les paramètres communs, n'importe quelle structure convient
-                    case ComputeNodeType.StructureRectangle:
-                        let cn = new RectangularStructureParams(undefined, 0.5, 2, 1, undefined, undefined);
-                        let n = new StructureCem88d(cn);
-                        return cn;
-
-                    case ComputeNodeType.StructureKIVI:
-                        {
-                            let cn = new StructureKiviParams(undefined, 1, 2, 1, undefined, undefined, undefined, undefined);
-                            let n = new StructureKivi(cn);
-                            return cn;
-                        }
-
-                    default:
-                        throw new Error(`ComputeNodeParameters.createComputeNodeParameters() : calculatrice '${CalculatorType[calcType]}' / noeud de calcul '${ComputeNodeType[nodeType]}' non pris en charge`);
-                }
-
-            case CalculatorType.ParallelStructure:
-                {
-                    let cn = new ParallelStructureParams(undefined, undefined, undefined);
-                    let n = new ParallelStructure(cn);
-                    return cn;
-                }
-
-            default:
-                throw new Error(`ComputeNodeParameters.createComputeNodeParameters() : calculatrice '${CalculatorType[calcType]}' / noeud de calcul '${ComputeNodeType[nodeType]}' non pris en charge`);
-        }
-    }
-
-    public getComputeNodeParameter(calcType: CalculatorType, nodeType: ComputeNodeType, symbol: string): ParamDefinition {
-        const key = { calcType, nodeType };
-        let params = this._nodes.get(key);
-        if (params == undefined) {
-            params = this.createComputeNodeParameters(calcType, nodeType);
-            this._nodes.put(key, params);
-        }
-
-        return params.map[symbol];
-    }
-}
diff --git a/src/section/section_nub.ts b/src/section/section_nub.ts
index 50250f7d..af47cd5d 100644
--- a/src/section/section_nub.ts
+++ b/src/section/section_nub.ts
@@ -1,13 +1,112 @@
 import { Nub } from "../nub";
 import { acSection } from "./section_type";
 import { Result } from "../util/result";
+import { ParamDefinition, ParamCalculability } from "../param/param-definition";
+import { ParamDomain, ParamDomainValue } from "../param/param-domain";
 
 /**
  * Nub sur les sections paramétrées
  */
 export class SectionParametree extends Nub {
+    private _section: acSection;
+
+    private _sectionVars: { [key: string]: ParamDefinition };
+
     constructor(sect: acSection, dbg: boolean = false) {
         super(sect.prms, dbg);
+        this._section = sect;
+        this.initSectionVars();
+    }
+
+    private initSectionVars() {
+        this._sectionVars = {};
+        this.initSectionVar("Hs");
+        this.initSectionVar("Hsc");
+        this.initSectionVar("B");
+        this.initSectionVar("P");
+        this.initSectionVar("S");
+        this.initSectionVar("R");
+        this.initSectionVar("V");
+        this.initSectionVar("Fr");
+        this.initSectionVar("Yc");
+        this.initSectionVar("Yn");
+        this.initSectionVar("Yf");
+        this.initSectionVar("Yt");
+        this.initSectionVar("Yco");
+        this.initSectionVar("J");
+        this.initSectionVar("Imp");
+        this.initSectionVar("Tau0");
+        this.initSectionVar("I-J");
+    }
+
+    private initSectionVar(symbol: string) {
+        this._sectionVars[symbol] = this.createSectionVar(symbol);
+    }
+
+    private createSectionVar(symbol: string): ParamDefinition {
+        switch (symbol) {
+            case "Hs":
+            case "Hsc":
+            case "B":
+            case "P":
+            case "S":
+            case "R":
+            case "V":
+            case "Fr":
+            case "Yc":
+            case "Yn":
+            case "Yf":
+            case "Yt":
+            case "Yco":
+            case "J":
+            case "Imp":
+            case "Tau0":
+                var dom = new ParamDomain(ParamDomainValue.POS_NULL);
+                break;
+
+            case "I-J":
+                var dom = new ParamDomain(ParamDomainValue.ANY);
+                break;
+
+            default:
+                throw new Error(`SectionParametree.createSectionVar() : symbole ${symbol} non pris en charge`);
+        }
+
+        const res = new ParamDefinition(symbol, dom);
+        res.calculability = ParamCalculability.EQUATION;
+        return res;
+    }
+
+    public get section(): acSection {
+        return this._section;
+    }
+
+    public getParameter(name: string): ParamDefinition {
+        try {
+            return super.getParameter(name);
+        }
+        catch (e) {
+            // pas trouvé -> il s'agit peut être d'une variable dans le genre Hs, B, P, ...
+            const res = this._sectionVars[name];
+
+            if (!res)
+                throw new Error(`SectionParametree.getParameter() : nom de paramètre ${name} incorrect`);
+
+            return res;
+        }
+    }
+
+    public getFirstAnalyticalParameter(): ParamDefinition {
+        let res = super.getFirstAnalyticalParameter();
+        if (res)
+            return res;
+
+        for (const k in this._sectionVars) {
+            const p = this._sectionVars[k];
+            if (p.isAnalytical)
+                return p;
+        }
+        return undefined;
     }
 
     /**
@@ -17,6 +116,28 @@ export class SectionParametree extends Nub {
     }
 
     Equation(sVarCalc: string): Result {
-        throw new Error(`SectionParam.Equation() : calcul sur ${sVarCalc} non implémenté`);
+        switch (sVarCalc) {
+            case "Hs":
+            case "Hsc":
+            case "B":
+            case "P":
+            case "S":
+            case "R":
+            case "V":
+            case "Fr":
+            case "Yc":
+            case "Yn":
+            case "Yf":
+            case "Yt":
+            case "Yco":
+            case "J":
+            case "Imp":
+            case "Tau0":
+            case "I-J":
+                return this._section.Calc(sVarCalc, this.getParameter("Y").v);
+
+            default:
+                throw new Error(`SectionParam.Equation() : calcul sur ${sVarCalc} non implémenté`);
+        }
     }
 }
-- 
GitLab