diff --git a/src/compute-node.ts b/src/compute-node.ts index 5cb78f80b0b224d82eea77e04215d71d5911c8d6..7ecc73e9a884a138ad2441b3a0000529a6e08eee 100644 --- a/src/compute-node.ts +++ b/src/compute-node.ts @@ -1,6 +1,6 @@ import { Debug, IDebug } from "./base"; import { JalhydObject } from "./jalhyd_object"; -import { ParamCalculability, ParamDefinition } from "./param/param-definition"; +import { ParamDefinition } from "./param/param-definition"; import { IParamDefinitionIterator } from "./param/param_definition_iterator"; import { ParamsEquation } from "./param/params-equation"; @@ -28,7 +28,8 @@ export enum CalculatorType { MacroRugoCompound, // Passe à enrochement composée Jet, // Impact de jet Grille, // Pertes de charge grille de prise d'eau - Pente + Pente, + Bief } /** diff --git a/src/index.ts b/src/index.ts index 722ed965273003b3d362571b8f91894934b375f0..0401022226a05eecbcff8e6dc332bfa0e88c095c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -55,3 +55,5 @@ export * from "./macrorugo/macrorugo"; export * from "./macrorugo/macrorugo_compound"; export * from "./devalaison/jet"; export * from "./devalaison/grille"; +export * from "./remous/bief"; +export * from "./remous/bief_params"; diff --git a/src/nub.ts b/src/nub.ts index 706b0924d698b926f99fd3569aa231bdaef6eb87..5b8c331c3947e41ddc8f1e38056d70ef3db3519a 100644 --- a/src/nub.ts +++ b/src/nub.ts @@ -68,18 +68,7 @@ export abstract class Nub extends ComputeNode implements IObservable { } public set properties(props: Props) { - // copy observers - const observers = this._props.getObservers(); - // empty props - this._props.reset(); - // restore observers - for (const obs of observers) { - this._props.addObserver(obs); - } - // set new props values - for (const p of Object.keys(props.props)) { - this._props.setPropValue(p, props.getPropValue(p)); - } + this.setProperties(props); } /** @@ -219,6 +208,22 @@ export abstract class Nub extends ComputeNode implements IObservable { this.resetDefaultCalculatedParam(); } + // move code out of setter to ease inheritance + public setProperties(props: Props) { + // copy observers + const observers = this._props.getObservers(); + // empty props + this._props.reset(); + // restore observers + for (const obs of observers) { + this._props.addObserver(obs); + } + // set new props values + for (const p of Object.keys(props.props)) { + this._props.setPropValue(p, props.getPropValue(p)); + } + } + /** * Finds the previous calculated parameter and sets its mode to SINGLE */ diff --git a/src/remous/bief.ts b/src/remous/bief.ts new file mode 100644 index 0000000000000000000000000000000000000000..a6ed1e8ac8f0f5c5934c39d58807a6e1e961c6af --- /dev/null +++ b/src/remous/bief.ts @@ -0,0 +1,126 @@ +import { CalculatorType } from "../compute-node"; +import { ParamCalculability } from "../param/param-definition"; +import { SectionNub } from "../section/section_nub"; +import { acSection } from "../section/section_type"; +import { Observer } from "../util/observer"; +import { Result } from "../util/result"; +import { BiefParams, BiefRegime } from "./bief_params"; +import { MethodeResolution } from "./methode-resolution"; +import { CourbeRemous } from "./remous"; +import { CourbeRemousParams } from "./remous_params"; + +export class Bief extends SectionNub implements Observer { + + constructor(s: acSection, bp: BiefParams, regime: BiefRegime = BiefRegime.Fluvial, dbg: boolean = false) { + super(bp, dbg); + this._calcType = CalculatorType.Bief; + this.setSection(s); + this._props.addObserver(this); + this.properties.setPropValue("regime", regime); + this._defaultCalculatedParam = bp.Z1; + } + + public get prms(): BiefParams { + return this._prms as BiefParams; + } + + public setSection(s: acSection) { + super.setSection(s); + this.setParametersCalculability(); // to override acSection's tuning + } + + public Equation(sVarCalc: string): Result { + let v: number; + + // local CourbeRemous with same section and same parameters + const rp = new CourbeRemousParams( + this.prms.Z1.v, + this.prms.Z2.v, + this.prms.ZF1.v, + this.prms.ZF2.v, + this.prms.Long.v, + this.prms.Dx.v + ); + const secCopy = JSON.parse(JSON.stringify(this.section)); + const rem = new CourbeRemous(secCopy, rp, MethodeResolution.Trapezes); + + switch (sVarCalc) { + case "Z1": + break; + + case "Z2": + break; + + case "Ks": + break; + + case "Q": + break; + + default: + throw new Error("Bief.Equation() : invalid variable name " + sVarCalc); + } + + return new Result(v, this); + } + + // interface Observer + public update(sender: any, data: any) { + if (data.action === "propertyChange") { + switch (data.name) { + case "regime": + if (data.value === BiefRegime.Fluvial) { + this.prms.Z1.calculability = ParamCalculability.EQUATION; + if (this.calculatedParam === undefined || this.calculatedParam === this.prms.Z2) { + this.prms.Z1.setCalculated(); + } + this.prms.Z2.calculability = ParamCalculability.FREE; + } + if (data.value === BiefRegime.Torrentiel) { + this.prms.Z2.calculability = ParamCalculability.EQUATION; + if (this.calculatedParam === undefined || this.calculatedParam === this.prms.Z1) { + this.prms.Z2.setCalculated(); + } + this.prms.Z1.calculability = ParamCalculability.FREE; + } + break; + } + } + } + + protected setParametersCalculability() { + this.prms.Long.calculability = ParamCalculability.FIXED; + this.prms.Dx.calculability = ParamCalculability.FIXED; + this.prms.Yamont.calculability = ParamCalculability.FIXED; + this.prms.Yaval.calculability = ParamCalculability.FIXED; + // do not set Z1 and Z2 here to avoid both being calculable at the same time + this.prms.ZF1.calculability = ParamCalculability.FIXED; + this.prms.ZF2.calculability = ParamCalculability.FIXED; + // section params + if (this.section) { + this.section.prms.Ks.calculability = ParamCalculability.DICHO; + this.section.prms.Q.calculability = ParamCalculability.DICHO; + this.section.prms.If.calculability = ParamCalculability.FIXED; + this.section.prms.YB.calculability = ParamCalculability.FIXED; + this.section.prms.Y.calculability = ParamCalculability.FIXED; + this.section.prms.LargeurBerge.calculability = ParamCalculability.FIXED; + // parameters depending on section type + const D = this.section.getParameter("D"); + if (D) { + D.calculability = ParamCalculability.FIXED; + } + const k = this.section.getParameter("k"); + if (k) { + k.calculability = ParamCalculability.FIXED; + } + const fruit = this.section.getParameter("Fruit"); + if (fruit) { + fruit.calculability = ParamCalculability.FIXED; + } + const largeurFond = this.section.getParameter("LargeurFond"); + if (largeurFond) { + largeurFond.calculability = ParamCalculability.FIXED; + } + } + } +} diff --git a/src/remous/bief_params.ts b/src/remous/bief_params.ts new file mode 100644 index 0000000000000000000000000000000000000000..ed84bd477acf4e29df104577f4a6665d1a0c89c6 --- /dev/null +++ b/src/remous/bief_params.ts @@ -0,0 +1,14 @@ +import { CourbeRemousParams } from "./remous_params"; + +export enum BiefRegime { + Fluvial, + Torrentiel +} + +/** + * paramètres pour les cotes de bief; pour l'instant rien de spécifique + * (le régime est une propriété et non un paramètre) + */ +export class BiefParams extends CourbeRemousParams { + +} diff --git a/src/remous/remous.ts b/src/remous/remous.ts index 28a8a44855b6131d5752a807d7504817f839b65f..026e48cac38983880e4c8874e6dc127182aad932 100644 --- a/src/remous/remous.ts +++ b/src/remous/remous.ts @@ -22,7 +22,6 @@ export interface ITrYResult { * Calcul d'une courbe de remous */ export class CourbeRemous extends SectionNub { - [key: string]: any; // pour pouvoir faire this['methode](); private static _availableMethodeResolution: Array<{ id: string, value: MethodeResolution }> = [ { diff --git a/src/section/section_nub.ts b/src/section/section_nub.ts index b7e8f9dff8b3c1baf03bf6860c8532812a00555c..5d61281974652a0a14dea0f0253700e6013ab799 100644 --- a/src/section/section_nub.ts +++ b/src/section/section_nub.ts @@ -36,7 +36,7 @@ export abstract class SectionNub extends Nub { // setter is not inherited from Nub if getter is redefined :/ public set properties(props: Props) { - this._props = props.clone(); + super.setProperties(props); } public getParameter(name: string): ParamDefinition { diff --git a/src/section/section_type.ts b/src/section/section_type.ts index c5752a1f73187c9e9e142e71a9e2615696f077dc..72b7f40b5af369d72aa9461a5a84f0aedb5b2c5a 100644 --- a/src/section/section_type.ts +++ b/src/section/section_type.ts @@ -113,7 +113,7 @@ export abstract class acSection extends Nub { // setter is not inherited from Nub if getter is redefined :/ public set properties(props: Props) { - this._props = props.clone(); + super.setProperties(props); } /** diff --git a/src/session.ts b/src/session.ts index d23638632ee3df94c62ffe92bb6ef444a37e5af3..40ef2c256ac4926965a55f23936deac302e76f1d 100644 --- a/src/session.ts +++ b/src/session.ts @@ -2,6 +2,7 @@ import { CalculatorType, ComputeNodeType } from "./compute-node"; import { LCMaterial } from "./lc-material"; import { LinkedValue } from "./linked-value"; import { Nub } from "./nub"; +import { ParamDefinition } from "./param/param-definition"; import { Props } from "./props"; import { config } from "./config"; @@ -21,6 +22,7 @@ import { CourbeRemous } from "./remous/remous"; import { SectionParametree } from "./section/section_parametree"; // Classes relatives aux sections +import { BiefParams, BiefRegime } from "./remous/bief_params"; import { cSnCirc } from "./section/section_circulaire"; import { cSnPuiss } from "./section/section_puissance"; import { cSnRectang } from "./section/section_rectang"; @@ -42,7 +44,6 @@ import { PabDimensionParams } from "./pab/pab_dimensions_params"; import { PabNombreParams } from "./pab/pab_nombre_params"; import { PabParams } from "./pab/pab_params"; import { PabPuissanceParams } from "./pab/pab_puissance_params"; -import { ParamDefinition } from "./param/param-definition"; import { MethodeResolution } from "./remous/methode-resolution"; import { CourbeRemousParams } from "./remous/remous_params"; import { ParamsSectionCirc } from "./section/section_circulaire_params"; @@ -64,6 +65,7 @@ import { Jet } from "./devalaison/jet"; import { JetParams } from "./devalaison/jet_params"; import { Pente } from "./pente"; import { PenteParams } from "./pente_params"; +import { Bief } from "./remous/bief"; export class Session { @@ -107,6 +109,9 @@ export class Session { case "gridProfile": res[k] = GrilleProfile[res[k]]; break; + case "regime": + res[k] = BiefRegime[res[k]]; + break; // "varCalc" is not an enum // "inclinedApron" is not an enum } @@ -530,6 +535,23 @@ export class Session { ); break; + case CalculatorType.Bief: + const regime: BiefRegime = params.getPropValue("regime"); + nub = new Bief( + undefined, + new BiefParams( + 100.25, // Z1 = cote de l'eau amont + 100.4, // Z2 = cote de l'eau aval + 100.1, // ZF1 = cote de fond amont + 100, // ZF2 = cote de fond aval + 100, // Long = Longueur du bief + 5, // Dx = Pas d'espace + ), + regime, + dbg + ); + break; + default: throw new Error( `Session.createNub() : type de module '${CalculatorType[calcType]}' non pris en charge` diff --git a/src/structure/structure.ts b/src/structure/structure.ts index ef4d58d4af8ffb00b9a5b01cae0d01a02cc5f831..25930e83303becbf613c025ebc6c5e8dcef10cb7 100644 --- a/src/structure/structure.ts +++ b/src/structure/structure.ts @@ -87,7 +87,7 @@ export abstract class Structure extends Nub { // setter is not inherited from Nub if getter is redefined :/ public set properties(props: Props) { - this._props = props.clone(); + super.setProperties(props); } get isZDVcalculable(): boolean {