diff --git a/Makefile b/Makefile index e3e6ff5e6308833b239d005ef0162a0496f5e7c5..cc5e7d2a61aa9cf8f212c35bedef7f70d8830d8d 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,13 @@ buildspec : jasmine : buildspec cls npm run jasmine -karma : +jasmine2 : + make clean;make buildspec;./node_modules/.bin/jasmine --config=spec/support/jasmine-RUcirc.json + +testjs : + make; node build/src/test.js + +karma : buildspec npm run karma cls : diff --git a/spec/cond_distri.spec.ts b/spec/cond_distri.spec.ts index 23b04cecfdb336263dbb424538867108fa81912b..f0226a176ff04dd1a28fca57c4b0298748b82d23 100644 --- a/spec/cond_distri.spec.ts +++ b/spec/cond_distri.spec.ts @@ -1,7 +1,7 @@ /// <reference path="../node_modules/@types/jasmine/index.d.ts" /> import { Result } from "../src/base"; -import { ConduiteDistrib } from "../src/cond_distri"; +import { ConduiteDistrib, ConduiteDistribParams } from "../src/cond_distri"; describe('Class ConduiteDistrib: ', () => { // beforeEach(() => { @@ -13,73 +13,95 @@ describe('Class ConduiteDistrib: ', () => { describe('Calc(): ', () => { it('Q should be 9.393', () => { - let nub = new ConduiteDistrib(); - nub.v.d = 1.2; - nub.v.j = 0.6; - nub.v.lg = 100; - nub.v.nu = 1e-6; + let prms = new ConduiteDistribParams(undefined, // débit Q + 1.2, // diamètre D + 0.6, // perte de charge J + 100, // Longueur de la conduite Lg + 1e-6 // Viscosité dynamique Nu + ); - expect(nub.Calc("q").vCalc).toBeCloseTo(9.393, 3); + let nub = new ConduiteDistrib(prms); + + expect(nub.Calc("Q").vCalc).toBeCloseTo(9.393, 3); }); }); describe('Calc(): ', () => { it('Q should be 152.992', () => { - let nub = new ConduiteDistrib(); - nub.v.d = 2; - nub.v.j = 0.7; - nub.v.lg = 10; - nub.v.nu = 1e-6; + let prms = new ConduiteDistribParams(undefined, // débit Q + 2, // diamètre D + 0.7, // perte de charge J + 10, // Longueur de la conduite Lg + 1e-6 // Viscosité dynamique Nu + ); + + let nub = new ConduiteDistrib(prms); + nub.prms.D.v = 2; + nub.prms.J.v = 0.7; + nub.prms.Lg.v = 10; + nub.prms.Nu.v = 1e-6; - expect(nub.Calc("q").vCalc).toBeCloseTo(152.992, 3); + expect(nub.Calc("Q").vCalc).toBeCloseTo(152.992, 3); }); }); describe('Calc(): ', () => { it('D should be 2.12847', () => { - let nub = new ConduiteDistrib(); - nub.v.q = 3; - nub.v.j = 0.7; - nub.v.lg = 10; - nub.v.nu = 1e-6; + let prms = new ConduiteDistribParams(3, // débit Q + undefined, // diamètre D + 0.7, // perte de charge J + 10, // Longueur de la conduite Lg + 1e-6 // Viscosité dynamique Nu + ); + + let nub = new ConduiteDistrib(prms); - expect(nub.Calc("d").vCalc).toBeCloseTo(2.12847, 5); + expect(nub.Calc("D").vCalc).toBeCloseTo(2.12847, 5); }); }); describe('Calc(): ', () => { it('J should be 0.00814', () => { - let nub = new ConduiteDistrib(); - nub.v.q = 3; - nub.v.d = 1.2; - nub.v.lg = 10; - nub.v.nu = 1e-6; + let prms = new ConduiteDistribParams(3, // débit Q + 1.2, // diamètre D + undefined, // perte de charge J + 10, // Longueur de la conduite Lg + 1e-6 // Viscosité dynamique Nu + ); - expect(nub.Calc("j").vCalc).toBeCloseTo(0.00814, 5); + let nub = new ConduiteDistrib(prms); + + expect(nub.Calc("J").vCalc).toBeCloseTo(0.00814, 5); }); }); describe('Calc(): ', () => { it('Lg should be 737.021', () => { - let nub = new ConduiteDistrib(); - nub.v.q = 3; - nub.v.d = 1.2; - nub.v.j = 0.6; - nub.v.nu = 1e-6; + let prms = new ConduiteDistribParams(3, // débit Q + 1.2, // diamètre D + 0.6, // perte de charge J + undefined, // Longueur de la conduite Lg + 1e-6 // Viscosité dynamique Nu + ); + + let nub = new ConduiteDistrib(prms); - expect(nub.Calc("lg").vCalc).toBeCloseTo(737.021, 3); + expect(nub.Calc("Lg").vCalc).toBeCloseTo(737.021, 3); }); }); describe('Calc(): ', () => { it('Nu should be 0.00295', () => { - let nub = new ConduiteDistrib(); - nub.v.q = 3; - nub.v.d = 1.2; - nub.v.j = 0.6; - nub.v.lg = 100; + let prms = new ConduiteDistribParams(3, // débit Q + 1.2, // diamètre D + 0.6, // perte de charge J + 100, // Longueur de la conduite Lg + undefined // Viscosité dynamique Nu + ); + + let nub = new ConduiteDistrib(prms); - expect(nub.Calc("nu").vCalc).toBeCloseTo(0.00295, 5); + expect(nub.Calc("Nu").vCalc).toBeCloseTo(0.00295, 5); }); }); }); diff --git a/spec/nubtest.ts b/spec/nubtest.ts index e6a32d2adb1e1dc1cd78d0806343b0afc847517e..d0f0c2f9937060100a4561ec8bf69e09beb80dd9 100644 --- a/spec/nubtest.ts +++ b/spec/nubtest.ts @@ -1,16 +1,76 @@ -import { Result, IParamsEquation } from "../src/base"; +import { Result } from "../src/base"; import { Nub } from "../src/nub"; +import { ParamDefinition, ParamDomain, ParamDomainValue, ParamCalculability, IParamsEquation } from "../src/param"; + + +// export class NubTest extends Nub { +// constructor(dbg: boolean = false) { +// super(dbg); +// } + +// Equation(): Result { +// return new Result(this.prms["A"] + this.prms["B"]); +// } + +// protected createParams(): IParamsEquation { +// let res: IParamsEquation = {}; + +// res['A'] = new ParamDefinition('A', ParamDomain.POS, ParamCalculability.DIRECT, 1); +// res['B'] = new ParamDefinition('B', ParamDomain.POS, ParamCalculability.DICHO, 2); +// res['C'] = new ParamDefinition('C', ParamDomain.POS, ParamCalculability.DICHO, 3); + +// return res; +// } +// } + +class NubTestParams implements IParamsEquation { + private _A: ParamDefinition; + private _B: ParamDefinition; + private _C: ParamDefinition; + + constructor() { + this._A = new ParamDefinition('A', ParamDomainValue.POS_NULL, 1); + this._B = new ParamDefinition('B', ParamDomainValue.POS_NULL, 2); + this._C = new ParamDefinition('C', ParamDomainValue.POS_NULL, 3); + } + + get A() { + return this._A; + } + + get B() { + return this._B; + } + + get C() { + return this._C; + } +} export class NubTest extends Nub { - constructor(v: IParamsEquation, dbg: boolean = false) { - super(v, dbg); - this.sVarsEq = ["C"]; + constructor(prms: NubTestParams, dbg: boolean = false) { + super(prms, dbg); + } + + protected setParametersCalculability() { + this.getParameter('A').calculability = ParamCalculability.DICHO; + this.getParameter('B').calculability = ParamCalculability.DICHO; + //this.getParameter('C').calculability = ParamCalculability.EQUATION; // TODO } + + get prms(): NubTestParams { + return <NubTestParams>this._prms; + } + + Equation(): Result { - return new Result(this.v["A"] + this.v["B"]); + // C = A+B + // return new Result(this.prms["A"] + this.prms["B"]); + return new Result(this.prms.A.v + this.prms.B.v); } } -export let nub = new NubTest({ "A": 1, "B": 2, "C": 3 }); + +export let nub = new NubTest(new NubTestParams()); //export let res = new Result(0); diff --git a/spec/regime_uniforme_circ.spec.ts b/spec/regime_uniforme_circ.spec.ts index 3b48f312d1dff457fb58eb9b56239b7ec5a57327..f1d01da151cf9ef963a9369df90ed306e37cf988 100644 --- a/spec/regime_uniforme_circ.spec.ts +++ b/spec/regime_uniforme_circ.spec.ts @@ -2,8 +2,7 @@ import { Result } from "../src/base"; import { RegimeUniforme } from "../src/regime_uniforme"; -import { cSnCirc } from "../src/section/section_circulaire"; -import { cParamsCanal } from "../src/section/section_type"; +import { ParamsSectionCirc, cSnCirc } from "../src/section/section_circulaire"; import { precDigits, precDist } from "./nubtest"; describe('Class RegimeUniforme / section circulaire : ', () => { @@ -12,7 +11,9 @@ describe('Class RegimeUniforme / section circulaire : ', () => { describe('Calc(): ', () => { it('Diamètre should be 6', () => { - let paramCnl = new cParamsCanal(40, // Ks=Strickler + let paramSect = new ParamsSectionCirc(undefined, // diamètre + 0.6613, // tirant d'eau + 40, // Ks=Strickler 1.2, // Q=Débit 0.001, // If=pente du fond precDist, // précision @@ -20,11 +21,7 @@ describe('Class RegimeUniforme / section circulaire : ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnCirc(undefined, paramCnl, - 0 // diamètre - ); - // tirant d'eau - sect.v.Y = 0.6613; + let sect = new cSnCirc(undefined, paramSect); let ru = new RegimeUniforme(sect); @@ -34,7 +31,9 @@ describe('Class RegimeUniforme / section circulaire : ', () => { it('Ks should be 40', () => { - let paramCnl = new cParamsCanal(0, // Ks=Strickler + let paramCnl = new ParamsSectionCirc(6, // diamètre + 0.6613, // tirant d'eau + undefined, // Ks=Strickler 1.2, // Q=Débit 0.001, // If=pente du fond precDist, // précision @@ -42,12 +41,7 @@ describe('Class RegimeUniforme / section circulaire : ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnCirc(undefined, paramCnl, - 6 // diamètre - ); - // tirant d'eau - sect.v.Y = 0.6613; - + let sect = new cSnCirc(undefined, paramCnl); let ru = new RegimeUniforme(sect); expect(ru.Calc("Ks").vCalc).toBeCloseTo(40, 2); @@ -55,19 +49,17 @@ describe('Class RegimeUniforme / section circulaire : ', () => { it('If should be 0.001', () => { - let paramCnl = new cParamsCanal(40, // Ks=Strickler + let paramCnl = new ParamsSectionCirc(6, // diamètre + 0.6613, // tirant d'eau + 40, // Ks=Strickler 1.2, // Q=Débit - 0, // If=pente du fond + undefined, // If=pente du fond precDist, // précision 1 // YB= hauteur de berge // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnCirc(undefined, paramCnl, - 6 // diamètre - ); - // tirant d'eau - sect.v.Y = 0.6613; + let sect = new cSnCirc(undefined, paramCnl); let ru = new RegimeUniforme(sect); @@ -75,19 +67,17 @@ describe('Class RegimeUniforme / section circulaire : ', () => { }); it('Q should be 1.2', () => { - let paramCnl = new cParamsCanal(40, // Ks=Strickler - 0, // Q=Débit + let paramCnl = new ParamsSectionCirc(6, // diamètre + 0.6613, // tirant d'eau + 40, // Ks=Strickler + undefined, // Q=Débit 0.001, // If=pente du fond precDist, // précision 1 // YB= hauteur de berge // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnCirc(undefined, paramCnl, - 6 // diamètre - ); - // tirant d'eau - sect.v.Y = 0.6613; + let sect = new cSnCirc(undefined, paramCnl); let ru = new RegimeUniforme(sect); @@ -95,7 +85,9 @@ describe('Class RegimeUniforme / section circulaire : ', () => { }); it('Y should be 0.6613', () => { - let paramCnl = new cParamsCanal(40, // Ks=Strickler + let paramCnl = new ParamsSectionCirc(6, // diamètre + undefined, // tirant d'eau + 40, // Ks=Strickler 1.2, // Q=Débit 0.001, // If=pente du fond precDist, // précision @@ -103,11 +95,7 @@ describe('Class RegimeUniforme / section circulaire : ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnCirc(undefined, paramCnl, - 6 // diamètre - ); - // tirant d'eau - sect.v.Y = 0; + let sect = new cSnCirc(undefined, paramCnl); let ru = new RegimeUniforme(sect); diff --git a/spec/regime_uniforme_puissance.spec.ts b/spec/regime_uniforme_puissance.spec.ts index 8363d83a46bc44e0d97ffffe367f0a19b09ec86f..e19d0db26aad494c7017f140cf2681f61e97f0c4 100644 --- a/spec/regime_uniforme_puissance.spec.ts +++ b/spec/regime_uniforme_puissance.spec.ts @@ -2,8 +2,7 @@ import { Result } from "../src/base"; import { RegimeUniforme } from "../src/regime_uniforme"; -import { cSnPuiss } from "../src/section/section_puissance"; -import { cParamsCanal } from "../src/section/section_type"; +import { ParamsSectionPuiss, cSnPuiss } from "../src/section/section_puissance"; import { precDigits, precDist } from "./nubtest"; describe('Class RegimeUniforme / section puissance: ', () => { @@ -12,7 +11,10 @@ describe('Class RegimeUniforme / section puissance: ', () => { describe('Calc(): ', () => { it('k should be 0.635', () => { - let paramCnl = new cParamsCanal(40, // Ks=Strickler + let prms = new ParamsSectionPuiss(undefined, // coef + 0.8, // tirant d'eau + 4, // largeur de berge + 40, // Ks=Strickler 1.2, // Q=Débit 0.001, // If=pente du fond precDist, // précision @@ -20,12 +22,7 @@ describe('Class RegimeUniforme / section puissance: ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnPuiss(undefined, paramCnl, - 0, // coef - 4 // largeur de berge - ); - // tirant d'eau - sect.v.Y = 0.8; + let sect = new cSnPuiss(undefined, prms); let ru = new RegimeUniforme(sect, false); @@ -33,7 +30,10 @@ describe('Class RegimeUniforme / section puissance: ', () => { }); it('LargeurBerge should be 3.474', () => { - let paramCnl = new cParamsCanal(40, // Ks=Strickler + let prms = new ParamsSectionPuiss(0.5, // coef + 0.8, // tirant d'eau + undefined, // largeur de berge + 40, // Ks=Strickler 1.2, // Q=Débit 0.001, // If=pente du fond precDist, // précision @@ -41,12 +41,7 @@ describe('Class RegimeUniforme / section puissance: ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnPuiss(undefined, paramCnl, - 0.5, // coef - 0 // largeur de berge - ); - // tirant d'eau - sect.v.Y = 0.8; + let sect = new cSnPuiss(undefined, prms); let ru = new RegimeUniforme(sect, false); @@ -54,7 +49,10 @@ describe('Class RegimeUniforme / section puissance: ', () => { }); it('Strickler should be 33.774', () => { - let paramCnl = new cParamsCanal(0, // Ks=Strickler + let prms = new ParamsSectionPuiss(0.5, // coef + 0.8, // tirant d'eau + 4, // largeur de berge + undefined, // Ks=Strickler 1.2, // Q=Débit 0.001, // If=pente du fond precDist, // précision @@ -62,12 +60,7 @@ describe('Class RegimeUniforme / section puissance: ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnPuiss(undefined, paramCnl, - 0.5, // coef - 4 // largeur de berge - ); - // tirant d'eau - sect.v.Y = 0.8; + let sect = new cSnPuiss(undefined, prms); let ru = new RegimeUniforme(sect, false); @@ -76,20 +69,18 @@ describe('Class RegimeUniforme / section puissance: ', () => { it('If should be 0.002', () => { - let paramCnl = new cParamsCanal(40, // Ks=Strickler + let prms = new ParamsSectionPuiss(0.5, // coef + 0.8, // tirant d'eau + 4, // largeur de berge + 40, // Ks=Strickler 1.2, // Q=Débit - 0, // If=pente du fond + undefined, // If=pente du fond precDist, // précision 1 // YB= hauteur de berge // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnPuiss(undefined, paramCnl, - 0.5, // coef - 4 // largeur de berge - ); - // tirant d'eau - sect.v.Y = 0.8; + let sect = new cSnPuiss(undefined, prms); let ru = new RegimeUniforme(sect, false); @@ -97,20 +88,18 @@ describe('Class RegimeUniforme / section puissance: ', () => { }); it('Q should be 1.421', () => { - let paramCnl = new cParamsCanal(40, // Ks=Strickler - 0, // Q=Débit + let prms = new ParamsSectionPuiss(0.5, // coef + 0.8, // tirant d'eau + 4, // largeur de berge + 40, // Ks=Strickler + undefined, // Q=Débit 0.001, // If=pente du fond precDist, // précision 1 // YB= hauteur de berge // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnPuiss(undefined, paramCnl, - 0.5, // coef - 4 // largeur de berge - ); - // tirant d'eau - sect.v.Y = 0.8; + let sect = new cSnPuiss(undefined, prms); let ru = new RegimeUniforme(sect, false); @@ -118,7 +107,10 @@ describe('Class RegimeUniforme / section puissance: ', () => { }); it('Y should be 0.742', () => { - let paramCnl = new cParamsCanal(40, // Ks=Strickler + let paramCnl = new ParamsSectionPuiss(0.5, // coef + undefined, // tirant d'eau + 4, // largeur de berge + 40, // Ks=Strickler 1.2, // Q=Débit 0.001, // If=pente du fond precDist, // précision @@ -126,12 +118,7 @@ describe('Class RegimeUniforme / section puissance: ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnPuiss(undefined, paramCnl, - 0.5, // coef - 4 // largeur de berge - ); - // tirant d'eau - sect.v.Y = 0; + let sect = new cSnPuiss(undefined, paramCnl); let ru = new RegimeUniforme(sect, false); diff --git a/spec/regime_uniforme_rect.spec.ts b/spec/regime_uniforme_rect.spec.ts index 1a3ee29ed12bbff929418edecb62f2d4247d054b..5472c9ce5546ce5672a8b995cadd6ba3276fafa9 100644 --- a/spec/regime_uniforme_rect.spec.ts +++ b/spec/regime_uniforme_rect.spec.ts @@ -2,8 +2,7 @@ import { Result } from "../src/base"; import { RegimeUniforme } from "../src/regime_uniforme"; -import { cSnRectang } from "../src/section/section_rectang"; -import { cParamsCanal } from "../src/section/section_type"; +import { ParamsSectionRectang, cSnRectang } from "../src/section/section_rectang"; import { precDigits, precDist } from "./nubtest"; describe('Class RegimeUniforme / section rectangulaire : ', () => { @@ -15,7 +14,9 @@ describe('Class RegimeUniforme / section rectangulaire : ', () => { * test de la largeur de fond (= largeur de berge pour le rectangulaire) */ it('LargeurBerge should be 2.5', () => { - let paramCnl = new cParamsCanal(40, // Ks=Strickler + let prms = new ParamsSectionRectang(0.8, // tirant d'eau + undefined, // largeur de fond + 40, // Ks=Strickler 1.568, // Q=Débit 0.001, // If=pente du fond precDist, // précision @@ -23,20 +24,16 @@ describe('Class RegimeUniforme / section rectangulaire : ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - - let sect = new cSnRectang(undefined, paramCnl, - 0, // largeur de fond - false); - // tirant d'eau - sect.v.Y = 0.8; - + let sect = new cSnRectang(undefined, prms, false); let ru = new RegimeUniforme(sect, false); expect(ru.Calc("LargeurBerge").vCalc).toBeCloseTo(2.5, precDigits); }); it('Strickler should be 30.618', () => { - let prmsCanal = new cParamsCanal(40, // Ks=Strickler + let prms = new ParamsSectionRectang(0.8, // tirant d'eau + 2.5, // largeur de fond + undefined, // Ks=Strickler 1.2, // Q=Débit 0.001, // If=pente du fond precDist, // précision @@ -44,33 +41,24 @@ describe('Class RegimeUniforme / section rectangulaire : ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnRectang(undefined, prmsCanal, - 2.5 // largeur de fond - ); - // tirant d'eau - sect.v.Y = 0.8; - + let sect = new cSnRectang(undefined, prms); let ru = new RegimeUniforme(sect); - // nom variable à calculer, valeur de Ks expect(ru.Calc("Ks").vCalc).toBeCloseTo(30.618, precDigits); }); it('If should be 0.001', () => { - let prmsCanal = new cParamsCanal(40, // Ks=Strickler + let prms = new ParamsSectionRectang(0.8, // tirant d'eau + 2.5, // largeur de fond + 40, // Ks=Strickler 1.568, // Q=Débit - 0, // If=pente du fond + undefined, // If=pente du fond precDist, // précision 1 // YB=hauteur de berge // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnRectang(undefined, prmsCanal, - 2.5 // largeur de fond - ); - // tirant d'eau - sect.v.Y = 0.8; - + let sect = new cSnRectang(undefined, prms); let ru = new RegimeUniforme(sect, false); // nom variable à calculer, valeur de Ks @@ -78,49 +66,43 @@ describe('Class RegimeUniforme / section rectangulaire : ', () => { }); it('Q should be 1.568', () => { - let prmsCanal = new cParamsCanal(40, // Ks=Strickler - 0, // Q=Débit + let prms = new ParamsSectionRectang(0.8, // tirant d'eau + 2.5, // largeur de fond + 40, // Ks=Strickler + undefined, // Q=Débit 0.001, // If=pente du fond precDist, // précision 1 // YB=hauteur de berge // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnRectang(undefined, prmsCanal, - 2.5 // largeur de fond - ); - // tirant d'eau - sect.v.Y = 0.8; - + let sect = new cSnRectang(undefined, prms); let ru = new RegimeUniforme(sect); - // nom variable à calculer, valeur de Q expect(ru.Calc("Q").vCalc).toBeCloseTo(1.568, precDigits); }); it('Q should be 0.731', () => { - let prmsCanal = new cParamsCanal(30, // Ks=Strickler - 0, // Q=Débit + let prms = new ParamsSectionRectang(1.1, // tirant d'eau + 3, // largeur de fond + 30, // Ks=Strickler + undefined, // Q=Débit 0.0001, // If=pente du fond precDist, // précision 1.2 // YB=hauteur de berge // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnRectang(undefined, prmsCanal, - 3 // largeur de fond - ); - // tirant d'eau - sect.v.Y = 1.1; - + let sect = new cSnRectang(undefined, prms); let ru = new RegimeUniforme(sect); - // nom variable à calculer, valeur de Q expect(ru.Calc("Q").vCalc).toBeCloseTo(0.731, precDigits); }); it('Y should be 0.663', () => { - let prmsCanal = new cParamsCanal(40, // Ks=Strickler + let prms = new ParamsSectionRectang(undefined, // tirant d'eau + 40, // Ks=Strickler + 2.5, // largeur de fond 1.2, // Q=Débit 0.001, // If=pente du fond precDist, // précision @@ -128,12 +110,7 @@ describe('Class RegimeUniforme / section rectangulaire : ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnRectang(undefined, prmsCanal, - 2.5 // largeur de fond - ); - // tirant d'eau - sect.v.Y = 0; - + let sect = new cSnRectang(undefined, prms); let ru = new RegimeUniforme(sect); // nom variable à calculer, valeur de Ks diff --git a/spec/regime_uniforme_trapeze.spec.ts b/spec/regime_uniforme_trapeze.spec.ts index 0e7d1edb3f9a2384c91826032d5082bcace9d0b1..2b3a76772459e8d69489a7356d94169566b36842 100644 --- a/spec/regime_uniforme_trapeze.spec.ts +++ b/spec/regime_uniforme_trapeze.spec.ts @@ -2,8 +2,7 @@ import { Result } from "../src/base"; import { RegimeUniforme } from "../src/regime_uniforme"; -import { cSnTrapez } from "../src/section/section_trapez"; -import { cParamsCanal } from "../src/section/section_type"; +import { ParamsSectionTrapez, cSnTrapez } from "../src/section/section_trapez"; import { precDigits, precDist } from "./nubtest"; describe('Class RegimeUniforme / section trapèze: ', () => { @@ -12,7 +11,10 @@ describe('Class RegimeUniforme / section trapèze: ', () => { describe('Calc(): ', () => { it('LargeurFond should be 2.5', () => { - let paramCnl = new cParamsCanal(40, // Ks=Strickler + let prms = new ParamsSectionTrapez(undefined, // largeur de fond + 0.56, // fruit + 0.8, // tirant d'eau + 40, // Ks=Strickler 1.988428, // Q=Débit 0.001, // If=pente du fond precDist, // précision @@ -20,12 +22,7 @@ describe('Class RegimeUniforme / section trapèze: ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnTrapez(undefined, paramCnl, - 0, // largeur de fond - 0.56 // fruit - ); - // tirant d'eau - sect.v.Y = 0.8; + let sect = new cSnTrapez(undefined, prms); let ru = new RegimeUniforme(sect, false); @@ -33,7 +30,10 @@ describe('Class RegimeUniforme / section trapèze: ', () => { }); it('Fruit should be 0.56', () => { - let paramCnl = new cParamsCanal(40, // Ks=Strickler + let prms = new ParamsSectionTrapez(2.5, // largeur de fond + undefined, // fruit + 0.587, // tirant d'eau + 40, // Ks=Strickler 1.2, // Q=Débit 0.001, // If=pente du fond precDist, // précision @@ -41,20 +41,17 @@ describe('Class RegimeUniforme / section trapèze: ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnTrapez(undefined, paramCnl, - 2.5, // largeur de fond - 0 // fruit - ); - // tirant d'eau - sect.v.Y = 0.587; - + let sect = new cSnTrapez(undefined, prms); let ru = new RegimeUniforme(sect); expect(ru.Calc("Fruit").vCalc).toBeCloseTo(0.56, precDigits); }); it('Ks should be 24.14', () => { - let paramCnl = new cParamsCanal(0, // Ks=Strickler + let prms = new ParamsSectionTrapez(2.5, // largeur de fond + 0.56, // fruit + 0.8, // tirant d'eau + undefined, // Ks=Strickler 1.2, // Q=Débit 0.001, // If=pente du fond precDist, // précision @@ -62,41 +59,35 @@ describe('Class RegimeUniforme / section trapèze: ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnTrapez(undefined, paramCnl, - 2.5, // largeur de fond - 0.56 // fruit - ); - // tirant d'eau - sect.v.Y = 0.8; - + let sect = new cSnTrapez(undefined, prms); let ru = new RegimeUniforme(sect); expect(ru.Calc("Ks").vCalc).toBeCloseTo(24.14, precDigits); }); it('If should be 0.001', () => { - let paramCnl = new cParamsCanal(40, // Ks=Strickler + let prms = new ParamsSectionTrapez(2.5, // largeur de fond + 0.56, // fruit + 0.587, // tirant d'eau + 40, // Ks=Strickler 1.2, // Q=Débit - 0, // If=pente du fond + undefined, // If=pente du fond precDist, // précision 1 // YB= hauteur de berge // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnTrapez(undefined, paramCnl, - 2.5, // largeur de fond - 0.56 // fruit - ); - // tirant d'eau - sect.v.Y = 0.587; - + let sect = new cSnTrapez(undefined, prms); let ru = new RegimeUniforme(sect); expect(ru.Calc("If").vCalc).toBeCloseTo(0.001, precDigits); }); it('Q should be 1.2', () => { - let paramCnl = new cParamsCanal(40, // Ks=Strickler + let prms = new ParamsSectionTrapez(2.5, // largeur de fond + 0.56, // fruit + 0.587, // tirant d'eau + 40, // Ks=Strickler 0, // Q=Débit 0.001, // If=pente du fond precDist, // précision @@ -104,20 +95,17 @@ describe('Class RegimeUniforme / section trapèze: ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnTrapez(undefined, paramCnl, - 2.5, // largeur de fond - 0.56 // fruit - ); - // tirant d'eau - sect.v.Y = 0.587; - + let sect = new cSnTrapez(undefined, prms); let ru = new RegimeUniforme(sect); expect(ru.Calc("Q").vCalc).toBeCloseTo(1.2, precDigits); }); it('Y should be 0.587', () => { - let paramCnl = new cParamsCanal(40, // Ks=Strickler + let prms = new ParamsSectionTrapez(2.5, // largeur de fond + 0.56, // fruit + undefined, // tirant d'eau + 40, // Ks=Strickler 1.2, // Q=Débit 0.001, // If=pente du fond precDist, // précision @@ -125,13 +113,7 @@ describe('Class RegimeUniforme / section trapèze: ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - let sect = new cSnTrapez(undefined, paramCnl, - 2.5, // largeur de fond - 0.56 // fruit - ); - // tirant d'eau - sect.v.Y = 0; - + let sect = new cSnTrapez(undefined, prms); let ru = new RegimeUniforme(sect); expect(ru.Calc("Y").vCalc).toBeCloseTo(0.587, precDigits); diff --git a/spec/section_param_rect_fluvial.spec.ts b/spec/section_param_rect_fluvial.spec.ts index 7a8dd60214c0c76aeaf9895b3a6abb4668097d43..0371cd946f12db05320517e3f02efcadd6752b3a 100644 --- a/spec/section_param_rect_fluvial.spec.ts +++ b/spec/section_param_rect_fluvial.spec.ts @@ -2,15 +2,16 @@ import { Result } from "../src/base"; import { nub, precDigits, precDist } from "./nubtest"; -import { cSnRectang } from "../src/section/section_rectang"; -import { cParamsCanal } from "../src/section/section_type"; +import { ParamsSectionRectang, cSnRectang } from "../src/section/section_rectang"; -let paramCnl: cParamsCanal; +let paramSection: ParamsSectionRectang; let sect: cSnRectang; describe('Section paramétrée rectangulaire : ', () => { beforeEach(() => { - paramCnl = new cParamsCanal(40, // Ks=Strickler + paramSection = new ParamsSectionRectang(0.8, // tirant d'eau + 2.5, // largeur de fond + 40, // Ks=Strickler 1.2, // Q=Débit 0.001, // If=pente du fond precDist, // précision @@ -18,11 +19,7 @@ describe('Section paramétrée rectangulaire : ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - sect = new cSnRectang(undefined, paramCnl, - 2.5 // largeur de fond - ); - // tirant d'eau - sect.v.Y = 0.8; + sect = new cSnRectang(undefined, paramSection); }); describe('fluvial :', () => { @@ -93,14 +90,14 @@ describe('Section paramétrée rectangulaire : ', () => { // perte de charge it('J should equal to 0.00059', () => { - paramCnl.v.Prec = 0.00001; + paramSection.Prec.v = 0.00001; expect(sect.Calc_J()).toBeCloseTo(0.00059, precDigits); }); // Variation linéaire de l'énergie spécifique it('I-J should equal to 0.00041', () => { - paramCnl.v.Prec = 0.00001; - expect(sect.Calc('I-J')).toBeCloseTo(0.00041, precDigits); + paramSection.Prec.v = 0.00001; + expect(sect.Calc("I-J")).toBeCloseTo(0.00041, precDigits); }); // impulsion hydraulique diff --git a/spec/section_param_rect_torrentiel.spec.ts b/spec/section_param_rect_torrentiel.spec.ts index d21cf8b14aaa322c782ae8fd09a2a3916e2b798c..98e741e1fa4038058935a0a92e5f2e06ae742a4c 100644 --- a/spec/section_param_rect_torrentiel.spec.ts +++ b/spec/section_param_rect_torrentiel.spec.ts @@ -2,15 +2,16 @@ import { Result } from "../src/base"; import { nub, precDigits, precDist } from "./nubtest"; -import { cSnRectang } from "../src/section/section_rectang"; -import { cParamsCanal } from "../src/section/section_type"; +import { ParamsSectionRectang, cSnRectang } from "../src/section/section_rectang"; -let paramCnl: cParamsCanal; +let paramSection: ParamsSectionRectang; let sect: cSnRectang; describe('Section paramétrée rectangulaire : ', () => { beforeEach(() => { - paramCnl = new cParamsCanal(40, // Ks=Strickler + paramSection = new ParamsSectionRectang(0.8, // tirant d'eau + 2.5, // largeur de fond + 40, // Ks=Strickler 10, // Q=Débit 0.001, // If=pente du fond precDist, // précision @@ -18,11 +19,7 @@ describe('Section paramétrée rectangulaire : ', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - sect = new cSnRectang(undefined, paramCnl, - 2.5 // largeur de fond - ); - // tirant d'eau - sect.v.Y = 0.8; + sect = new cSnRectang(undefined, paramSection); }); describe('torrentiel :', () => { @@ -100,7 +97,7 @@ describe('Section paramétrée rectangulaire : ', () => { // Variation linéaire de l'énergie spécifique it('I-J should equal to -0.04', () => { //paramCnl.v.Prec = 0.00001; - expect(sect.Calc('I-J')).toBeCloseTo(-0.04, precDigits); + expect(sect.Calc("I-J")).toBeCloseTo(-0.04, precDigits); }); // impulsion hydraulique diff --git a/spec/section_param_trapez_fluvial.spec.ts b/spec/section_param_trapez_fluvial.spec.ts index d0d6a9a106b887e76ca4322e517cd11d0b4fdee9..352641e7b410f9549a3c04b03418ba5f6ba3f30f 100644 --- a/spec/section_param_trapez_fluvial.spec.ts +++ b/spec/section_param_trapez_fluvial.spec.ts @@ -2,28 +2,25 @@ import { Result } from "../src/base"; import { nub, precDigits, precDist } from "./nubtest"; -import { cSnTrapez } from "../src/section/section_trapez"; -import { cParamsCanal } from "../src/section/section_type"; +import { ParamsSectionTrapez, cSnTrapez } from "../src/section/section_trapez"; -let paramCnl: cParamsCanal; +let paramSection: ParamsSectionTrapez; let sect: cSnTrapez; describe('Section paramétrée trapèze : ', () => { beforeEach(() => { - paramCnl = new cParamsCanal(40, // Ks=Strickler + paramSection = new ParamsSectionTrapez(2.5, // largeur de fond + 0.56, // fruit + 0.8, // tirant d'eau 1.2, // Q=Débit + 40, // Ks=Strickler 0.001, // If=pente du fond precDist, // précision 1 // YB= hauteur de berge // YCL=Condition limite en cote à l'amont ou à l'aval ); - sect = new cSnTrapez(undefined, paramCnl, - 2.5, // largeur de fond - 0.56 // fruit - ); - // tirant d'eau - sect.v.Y = 0.8; + sect = new cSnTrapez(undefined, paramSection); }); describe('fluvial :', () => { @@ -94,13 +91,13 @@ describe('Section paramétrée trapèze : ', () => { // perte de charge it('J should equal to 0.00036', () => { - paramCnl.v.Prec = 0.00001; + paramSection.Prec.v = 0.00001; expect(sect.Calc_J()).toBeCloseTo(0.00036, precDigits); }); // Variation linéaire de l'énergie spécifique it('I-J should equal to 0.001', () => { - expect(sect.Calc('I-J')).toBeCloseTo(0.001, precDigits); + expect(sect.Calc("I-J")).toBeCloseTo(0.001, precDigits); }); // impulsion hydraulique diff --git a/spec/section_param_trapez_torrentiel.spec.ts b/spec/section_param_trapez_torrentiel.spec.ts index 45ca6638151c28022f7c0553d6191279ee3f1ab0..c659aa2ba602bff676f6b25924c3011ab0297129 100644 --- a/spec/section_param_trapez_torrentiel.spec.ts +++ b/spec/section_param_trapez_torrentiel.spec.ts @@ -2,15 +2,17 @@ import { Result } from "../src/base"; import { nub, precDigits, precDist } from "./nubtest"; -import { cSnTrapez } from "../src/section/section_trapez"; -import { cParamsCanal } from "../src/section/section_type"; +import { ParamsSectionTrapez, cSnTrapez } from "../src/section/section_trapez"; -let paramCnl: cParamsCanal; +let paramCnl: ParamsSectionTrapez; let sect: cSnTrapez; describe('Section paramétrée trapèze :', () => { beforeEach(() => { - paramCnl = new cParamsCanal(40, // Ks=Strickler + paramCnl = new ParamsSectionTrapez(2.5, // largeur de fond + 0.56, // fruit + 0.8, // tirant d'eau + 40, // Ks=Strickler 10, // Q=Débit 0.001, // If=pente du fond precDist, // précision @@ -18,12 +20,7 @@ describe('Section paramétrée trapèze :', () => { // YCL=Condition limite en cote à l'amont ou à l'aval ); - sect = new cSnTrapez(undefined, paramCnl, - 2.5, // largeur de fond - 0.56 // fruit - ); - // tirant d'eau - sect.v.Y = 0.8; + sect = new cSnTrapez(undefined, paramCnl); }); describe('torrentiel :', () => { @@ -100,7 +97,7 @@ describe('Section paramétrée trapèze :', () => { // Variation linéaire de l'énergie spécifique it('I-J should equal to -0.024', () => { - expect(sect.Calc('I-J')).toBeCloseTo(-0.024, precDigits); + expect(sect.Calc("I-J")).toBeCloseTo(-0.024, precDigits); }); // impulsion hydraulique diff --git a/src/base.ts b/src/base.ts index 7a51fe820b6b4ed167ca75f35555baa88e9e3d58..cc396210e2a41c2608444b4feba216fe7ec19682 100644 --- a/src/base.ts +++ b/src/base.ts @@ -1,7 +1,6 @@ /** * Résultat de calcul comprenant la valeur du résultat et des calculs annexes (flag, calculs intermédiaires...) */ - export class Result { /** Valeur calculée */ private _vCalc: number; @@ -17,7 +16,6 @@ export class Result { get vCalc() { return this._vCalc; } } - /** * Série de valeurs à calculer définie par le nom de la variable à sérier et le vecteur de valeur */ @@ -31,14 +29,6 @@ export class Serie { } } -/** - * liste des valeurs des variables - */ -export interface IParamsEquation { - [key: string]: number; // map : array of numbers with string keys -} - - /** * Gestion des messages de debogage dans la console * @note Etendre cette classe pour toutes les classes à debugguer diff --git a/src/cond_distri.ts b/src/cond_distri.ts index e654973265a53819744dd3e72b54617d1ea973d3..f4bbc0f4dfaba58997d3375d100cc3b751841d51 100644 --- a/src/cond_distri.ts +++ b/src/cond_distri.ts @@ -1,42 +1,84 @@ -import { Result, IParamsEquation } from "./base"; +import { Result } from "./base"; +import { ParamDefinition, ParamDomain, ParamDomainValue, ParamCalculability, IParamsEquation } from "../src/param"; import { Nub } from "./nub"; -// export interface IParamConduiteDistrib extends IParametres { -export class ParamConduiteDistrib implements IParamsEquation { - [key: string]: number; +// // export interface IParamConduiteDistrib extends IParametres { +// export class ParamConduiteDistrib implements IParamsEquation { +// [key: string]: number; +// /** Débit */ +// ["q"]: number = 0; +// /** Diamètre */ +// ["d"]: number = 0; +// /** Perte de charge */ +// ["j"]: number = 0; +// /** Longueur de la conduite */ +// ["lg"]: number = 0; +// /** Viscosité dynamique ni */ +// ["nu"]: number = 0; +// } + +export class ConduiteDistribParams implements IParamsEquation { /** Débit */ - ["q"]: number = 0; + private _Q: ParamDefinition; + /** Diamètre */ - ["d"]: number = 0; + private _D: ParamDefinition; + /** Perte de charge */ - ["j"]: number = 0; + private _J: ParamDefinition; + /** Longueur de la conduite */ - ["lg"]: number = 0; - /** Viscosité dynamique ni */ - ["nu"]: number = 0; -} + private _Lg: ParamDefinition; + + /** Viscosité dynamique nu */ + private _Nu: ParamDefinition; + constructor(rQ, rD, rJ, rLg, rNu) { + this._Q = new ParamDefinition('Q', ParamDomainValue.POS, rQ); + this._D = new ParamDefinition('D', ParamDomainValue.POS, rD); + this._J = new ParamDefinition('J', ParamDomainValue.POS, rJ); + this._Lg = new ParamDefinition('Lg', ParamDomainValue.POS, rLg); + this._Nu = new ParamDefinition('Nu', ParamDomainValue.POS, rNu); + } + + get Q() { + return this._Q; + } + + get D() { + return this._D; + } + + get J() { + return this._J; + } + + get Lg() { + return this._Lg; + } + + get Nu() { + return this._Nu; + } +} export class ConduiteDistrib extends Nub { - constructor() { - // let params: ParamConduiteDistrib; - // params = new ParamConduiteDistrib; - let params: { [key: string]: number }; - params = {}; - // params["q"] = 0; - // params["d"] = 0; - // params["j"] = 0; - // params["lg"] = 0; - // params["nu"] = 0; - super(params); - - this.AddVarEq("q"); - this.AddVarEq("d"); - this.AddVarEq("j"); - this.AddVarEq("lg"); - this.AddVarEq("nu"); + constructor(prms: ConduiteDistribParams, dbg: boolean = false) { + super(prms, dbg); + } + + protected setParametersCalculability() { + this.prms.J.calculability = ParamCalculability.EQUATION; + this.prms.D.calculability = ParamCalculability.EQUATION; + this.prms.Q.calculability = ParamCalculability.EQUATION; + this.prms.Lg.calculability = ParamCalculability.EQUATION; + this.prms.Nu.calculability = ParamCalculability.EQUATION; + } + + get prms(): ConduiteDistribParams { + return <ConduiteDistribParams>this._prms; } Equation(sVarCalc: string): Result { @@ -46,25 +88,28 @@ export class ConduiteDistrib extends Nub { var K = 0.3164 * Math.pow(4, 1.75) / (5.5 * 9.81 * Math.pow(3.1415, 1.75)); // Constante de la formule switch (sVarCalc) { - case "j": - v = K * Math.pow(this.v.nu, 0.25) * Math.pow(this.v.q, 1.75) * this.v.lg / Math.pow(this.v.d, 4.75); + case "J": + v = K * Math.pow(this.prms.Nu.v, 0.25) * Math.pow(this.prms.Q.v, 1.75) * this.prms.Lg.v / Math.pow(this.prms.D.v, 4.75); break; - case "d": - v = Math.pow(this.v.j / (K * Math.pow(this.v.nu, 0.25) * Math.pow(this.v.q, 1.75) * this.v.lg), 1 / 4.75); + case "D": + v = Math.pow(this.prms.J.v / (K * Math.pow(this.prms.Nu.v, 0.25) * Math.pow(this.prms.Q.v, 1.75) * this.prms.Lg.v), 1 / 4.75); break; - case "q": - v = Math.pow(this.v.j / (K * Math.pow(this.v.nu, 0.25) * this.v.lg / Math.pow(this.v.d, 4.75)), 1 / 1.75) + case "Q": + v = Math.pow(this.prms.J.v / (K * Math.pow(this.prms.Nu.v, 0.25) * this.prms.Lg.v / Math.pow(this.prms.D.v, 4.75)), 1 / 1.75) break; - case "lg": - v = this.v.j / (K * Math.pow(this.v.nu, 0.25) * Math.pow(this.v.q, 1.75) / Math.pow(this.v.d, 4.75)); + case "Lg": + v = this.prms.J.v / (K * Math.pow(this.prms.Nu.v, 0.25) * Math.pow(this.prms.Q.v, 1.75) / Math.pow(this.prms.D.v, 4.75)); break; - case "nu": - v = Math.pow(this.v.j / (K * Math.pow(this.v.q, 1.75) * this.v.lg / Math.pow(this.v.d, 4.75)), 1 / 0.25); + case "Nu": + v = Math.pow(this.prms.J.v / (K * Math.pow(this.prms.Q.v, 1.75) * this.prms.Lg.v / Math.pow(this.prms.D.v, 4.75)), 1 / 0.25); break; + + default: + throw 'ConduiteDistrib.Equation() : invalid parameter name ' + sVarCalc; } return new Result(v); diff --git a/src/dichotomie.ts b/src/dichotomie.ts index cccab1801570426d6f26673c616b4610e781c554..3fbc004cbf9052b81e8559ecd89a950e1b2713b5 100644 --- a/src/dichotomie.ts +++ b/src/dichotomie.ts @@ -15,17 +15,20 @@ export class Dichotomie extends Debug { */ constructor(private nub: Nub, private sVarCalc: string, dbg: boolean = false) { super(dbg); - this.debug(nub); + //this.debug(nub); } - /** Valeur inconnue à rechercher */ - get vX() { - return this.nub.v[this.sVarCalc]; + /** + * Valeur inconnue à rechercher + */ + get vX(): number { + // return this.nub.prms[this.sVarCalc]; + return this.nub.getParameter(this.sVarCalc).v; } - /** Valeur inconnue à rechercher */ - set vX(vCalc) { - this.nub.v[this.sVarCalc] = vCalc; + set vX(vCalc: number) { + //this.nub.prms[this.sVarCalc] = vCalc; + this.nub.getParameter(this.sVarCalc).v = vCalc; } /** @@ -46,7 +49,8 @@ export class Dichotomie extends Debug { /** * @note */ - let r = this.nub.Equation(this.nub.sVarsEq[0]); + // let r = this.nub.Equation(this.nub.sVarsEq[0]); + let r = this.nub.Equation(this.nub.getFirstAnalyticalParameter().symbol); this.debug('dicho : Calcul(vX=' + this.vX + ')=' + r.vCalc); return r; } diff --git a/src/lechaptcalmon.ts b/src/lechaptcalmon.ts index 0a349a7a46a2ad13ab145d252ff66c475902514c..c88ca8701b2cf210abe579a7b1e5ec167b665c5a 100644 --- a/src/lechaptcalmon.ts +++ b/src/lechaptcalmon.ts @@ -1,34 +1,92 @@ -import { Result, IParamsEquation } from "./base"; +import { Result } from "./base"; +import { ParamDefinition, ParamDomain, ParamDomainValue, ParamCalculability, IParamsEquation } from "../src/param"; import { Nub } from "./nub"; -interface IParamLechaptCalmon extends IParamsEquation { +class LechaptCalmonParams implements IParamsEquation { /** Débit */ - Q: number; + private _Q: ParamDefinition; + /** Diamètre */ - D: number; + private _D: ParamDefinition; + /** Perte de charge */ - J: number; + private _J: ParamDefinition; + /** Longueur de la conduite */ - Lg: number; + private _Lg: ParamDefinition; + /** Paramètre de rugosité L */ - L: number; + private _L: ParamDefinition; + /** Paramètre de rugosité M */ - M: number; + private _M: ParamDefinition; + /** Paramètre de rugosité N */ - N: number; -} + private _N: ParamDefinition; + constructor(rQ, rD, rJ, rLg, rL, rM, rN) { + this._Q = new ParamDefinition('Q', ParamDomainValue.POS, rQ); + this._D = new ParamDefinition('D', ParamDomainValue.POS, rD); + this._J = new ParamDefinition('J', ParamDomainValue.POS, rJ); + this._Lg = new ParamDefinition('Lg', ParamDomainValue.POS, rLg); + this._L = new ParamDefinition('L', ParamDomainValue.POS, rL); + this._M = new ParamDefinition('M', ParamDomainValue.POS, rM); + this._N = new ParamDefinition('N', ParamDomainValue.POS, rN); + } + + get Q() { + return this._Q; + } + + get D() { + return this._D; + } + + get J() { + return this._J; + } + + get Lg() { + return this._Lg; + } + + get L() { + return this._L; + } + + get M() { + return this._M; + } + + get N() { + return this._N; + } +} class LechaptCalmon extends Nub { + constructor(prms: LechaptCalmonParams) { + super(prms, false); + } + protected setParametersCalculability() { + this.prms.Q.calculability = ParamCalculability.EQUATION; + this.prms.D.calculability = ParamCalculability.EQUATION; + this.prms.J.calculability = ParamCalculability.EQUATION; + this.prms.Lg.calculability = ParamCalculability.EQUATION; - constructor(parametres: IParamLechaptCalmon) { - super(parametres); - this.AddVarEq("Q"); - this.AddVarEq("D"); - this.AddVarEq("J"); - this.AddVarEq("Lg"); + /* + this._Q = new ParamDefinition('Q', ParamDomainValue.POS, ParamCalculability.EQUATION); + this._D = new ParamDefinition('D', ParamDomainValue.POS, ParamCalculability.EQUATION); + this._J = new ParamDefinition('J', ParamDomainValue.POS, ParamCalculability.EQUATION); + this._Lg = new ParamDefinition('Lg', ParamDomainValue.POS, ParamCalculability.EQUATION); + this._L = new ParamDefinition('L', ParamDomainValue.POS, ParamCalculability.DICHO); + this._M = new ParamDefinition('M', ParamDomainValue.POS, ParamCalculability.DICHO); + this._N = new ParamDefinition('N', ParamDomainValue.POS, ParamCalculability.DICHO); +*/ + } + get prms(): LechaptCalmonParams { + return <LechaptCalmonParams>this._prms; } Equation(sVarCalc: string): Result { @@ -36,22 +94,22 @@ class LechaptCalmon extends Nub { switch (sVarCalc) { case "Q": - v = Math.pow((((this.v.J * Math.pow(this.v.D, this.v.N)) / this.v.L) * (1000 / this.v.Lg)), 1 / this.v.M); + v = Math.pow((((this.prms.J.v * Math.pow(this.prms.D.v, this.prms.N.v)) / this.prms.L.v) * (1000 / this.prms.Lg.v)), 1 / this.prms.M.v); break; case "D": - v = Math.pow((((this.v.L * Math.pow(this.v.Q, this.v.M)) / this.v.J) * (this.v.Lg / 1000)), 1 / this.v.N); + v = Math.pow((((this.prms.L.v * Math.pow(this.prms.Q.v, this.prms.M.v)) / this.prms.J.v) * (this.prms.Lg.v / 1000)), 1 / this.prms.N.v); break case "J": - v = ((this.v.L * Math.pow(this.v.Q, this.v.M)) / Math.pow(this.v.D, this.v.N)) * (this.v.Lg / 1000); + v = ((this.prms.L.v * Math.pow(this.prms.Q.v, this.prms.M.v)) / Math.pow(this.prms.D.v, this.prms.N.v)) * (this.prms.Lg.v / 1000); break; case "Lg": - v = ((this.v.J * Math.pow(this.v.D, this.v.N)) / (this.v.L * Math.pow(this.v.Q, this.v.M))) * 1000; + v = ((this.prms.J.v * Math.pow(this.prms.D.v, this.prms.N.v)) / (this.prms.L.v * Math.pow(this.prms.Q.v, this.prms.M.v))) * 1000; default: - throw "invalid variable name " + sVarCalc; + throw "LechaptCalmon.Equation() : invalid variable name " + sVarCalc; } return new Result(v); diff --git a/src/nub.ts b/src/nub.ts index e6a257e0dccf6e08cbd524df5044e53486e28d98..af7ce428cea2b897bdc6d40dc2ea4f733757e431 100644 --- a/src/nub.ts +++ b/src/nub.ts @@ -1,27 +1,42 @@ -import { Debug, IParamsEquation, Result, Serie } from "./base" +import { Debug, Result, Serie } from "./base" import { Dichotomie } from "./dichotomie" +import { ComputeNode, ParamDefinition, IParamsEquation } from "./param" + +// interface IPrmsEquation { +// [key: string]: number; // map : array of numbers with string keys +// } /** * Classe abstraite de Noeud de calcul : classe de base pour tous les calculs */ -export abstract class Nub extends Debug { +export abstract class Nub extends ComputeNode { /// Nom des variables calculées par la méthode Equation - private _varsEq: string[] = []; + //private _varsEq: string[] = []; - public v: IParamsEquation; + // protected _prms: IParamsEquation; - constructor(paramsEq: IParamsEquation, dbg: boolean = false) { - super(dbg); - this.v = paramsEq; - } + // constructor(prms: IParamsEquation, dbg: boolean = false) { + // super(prms, dbg); + // } + private checkParametersCalculability() { + let res = []; + + for (let ps in this._prms) { + let p: ParamDefinition = this._prms[ps]; + if (p.calculability == undefined) + res.push(p.symbol); + } + + if (res.length > 0) + throw 'Calculability of parameter(s) ' + res.toString() + ' has not been defined'; + } /** * Formule utilisée pour le calcul analytique (solution directe ou méthode de résolution spécifique) */ abstract Equation(sVarCalc: string): Result; - /** * Calcul d'une équation quelque soit l'inconnue à calculer * @param sVarCalc nom de la variable à calculer @@ -33,11 +48,9 @@ export abstract class Nub extends Debug { this.debug("nub : rInit=" + rInit); this.debug("nub : rPrec=" + rPrec); - for (let sVarEq of this._varsEq) { - if (sVarCalc == sVarEq) { - return this.Equation(sVarCalc); - } - } + if (this._prms[sVarCalc].isAnalytical()) + return this.Equation(sVarCalc); + return this.Solve(sVarCalc, rInit, rPrec); } @@ -51,19 +64,25 @@ export abstract class Nub extends Debug { return results; } - get sVarsEq(): string[] { - return this._varsEq; - } + public getParameter(name: string) { + for (let ps in this._prms) { + let p: ParamDefinition = this._prms[ps]; + if (p.symbol == name) + return p; + } - set sVarsEq(sVarsEq: string[]) { - this._varsEq = sVarsEq; + throw 'Nub.getParameter() : invalid parameter name ' + name; } - AddVarEq(sVarEq: string) { - this._varsEq.push(sVarEq); + public getFirstAnalyticalParameter(): ParamDefinition { + for (let ps in this._prms) { + let p: ParamDefinition = this._prms[ps]; + if (p.isAnalytical()) + return p; + } + return undefined; } - /** * Résoud l'équation par une méthode numérique * @param sVarCalc nom de la variable à calculer @@ -72,7 +91,7 @@ export abstract class Nub extends Debug { */ Solve(sVarCalc: string, rInit: number, rPrec: number): Result { let dicho: Dichotomie = new Dichotomie(this, sVarCalc, this.DBG); - var target = this.v[this._varsEq[0]]; - return dicho.Dichotomie(target, rPrec, rInit); + var target = this.getFirstAnalyticalParameter(); + return dicho.Dichotomie(target.v, rPrec, rInit); } } diff --git a/src/param.ts b/src/param.ts new file mode 100644 index 0000000000000000000000000000000000000000..86e2d429fdfbb6cb2cd655eb72840d52ae39f655 --- /dev/null +++ b/src/param.ts @@ -0,0 +1,279 @@ +import { Debug } from './base'; + +/** + * domaine de définition du paramètre + */ +export enum ParamDomainValue { + /** + * >0, =0, <0 + */ + ANY, + + /** + * >=0 + */ + POS_NULL, + + + /** + * > 0 + */ + POS, + + /** + * <>0 + */ + NOT_NULL, + + /** + * interval + */ + INTERVAL +} + +export class ParamDomain { + private _value: ParamDomainValue; + + private _min: number; + + private _max: number; + + constructor(d: ParamDomainValue, min: number = 0, max: number = -1) { + this.checkValue(d, min, max); + this._value = d; + this._min = min; + this._max = max; + } + + private checkValue(val, min, max) { + switch (val) { + case ParamDomainValue.INTERVAL: + if (min > max) + throw "invalid " + min + "/" + max + " min/max boundaries for 'interval' parameter definition domain" + break; + + default: + break; + } + } + + get value() { + return this._value; + } + + get min() { + return this._min; + } + + get max() { + return this._max; + } +} + +/** + * calculabilité du paramètre + */ +export enum ParamCalculability { + /** + * paramètre fixé + */ + NONE, + + /** + * paramètre calculable analytiquement, par méthode de Newton, ... + */ + EQUATION, + + /** + * paramètre calculable par dichotomie + */ + DICHO +} + +/** + * définition d'un paramètre + */ +export class ParamDefinition { + /** + * symbole + */ + private _symbol: string; + + /** + * calculabilité + */ + private _calc: ParamCalculability; + + /** + * domaine de définition + */ + private _domain: ParamDomain; + + /** + * ancienne valeur du paramètre + */ + // private _savedValue: number; + + /** + * valeur du paramètre + */ + private _value: number; + + // constructor(s: string, d: ParamDomain, c: ParamCalculability, val: number = undefined) { + constructor(s: string, d: any, val: number = undefined) { + this._symbol = s; + + if (d instanceof ParamDomain) + this._domain = d; + else + this._domain = new ParamDomain(<ParamDomainValue>d); + + this._calc = undefined; + this.checkValue(val); + this._value = val; + } + + get() { + return this._value; + } + + /** + * getter symbole + */ + get symbol(): string { + return this._symbol; + } + + /* + * méthodes de calculabilité + */ + + /** + * variable calculable ? + */ + isComputable(): boolean { + return this.calculability != ParamCalculability.NONE; + } + + /** + * variable calculable par l'équation ? + */ + isAnalytical(): boolean { + return this.calculability == ParamCalculability.EQUATION; + } + + get calculability(): ParamCalculability { + if (this._calc == undefined) + throw "value of parameter '" + this._symbol + "' calculability is not defined"; + + return this._calc; + } + + set calculability(c: ParamCalculability) { + this._calc = c; + } + + /** + * gestion de la valeur + */ + get v(): number { + if (this._value == undefined) + throw "value of '" + this._symbol + "' parameter is not defined"; + return this._value; + } + + set v(val: number) { + if (this.calculability == ParamCalculability.NONE) + throw "value of '" + this._symbol + "' parameter cannot be changed"; + this.checkValue(val); + this._value = val; + } + + private checkValue(v: number) { + let sDomain = ParamDomainValue[this._domain.value]; + + switch (this._domain.value) { + case ParamDomainValue.ANY: + break; + + case ParamDomainValue.POS: + if (v <= 0) + throw "parameter '" + this._symbol + "' : invalid " + v + " value (cannot be <=0)"; + break; + + case ParamDomainValue.POS_NULL: + if (v < 0) + throw "parameter '" + this._symbol + "' : invalid " + v + " value (cannot be <0)"; + break; + + case ParamDomainValue.NOT_NULL: + if (v == 0) + throw "parameter '" + this._symbol + "' : value cannot be 0"; + break; + + case ParamDomainValue.INTERVAL: + let min = this._domain.min; + let max = this._domain.max; + if (v < min || v > max) + throw "parameter '" + this._symbol + "' : value " + v + " is out of [" + min + ", " + max + "] interval"; + break; + + default: + throw "parameter '" + this._symbol + "' : non supported '" + sDomain + "' definition domain"; + } + } + + isDefined(): boolean { + return this._value != undefined; + } + + + undefine() { + this._value = undefined; + // this._savedValue = undefined; + } + + /** + * gestion du cache + */ + /* + saveValue() { + if (this._value == undefined) + throw "parameter '" + this._symbol + "' : cannot save 'undefined' value"; + if (this._savedValue != undefined) + throw "parameter '" + this._symbol + "' : previous saved value " + this._savedValue + " has not been restored"; + this._savedValue = this._value; + } + + restoreValue() { + if (this._savedValue == undefined) + throw "parameter '" + this._symbol + "' : value has not been saved"; + this._value = this._savedValue; + this._savedValue = undefined; + } + */ +} + + +/** + * liste des paramètres d'une équation + */ +export interface IParamsEquation { + //[key: string]: ParamDefinition; // map : array of ParamDefinition with string keys + // [key: string]: number; // map : array of ParamDefinition with string keys +} + +/** + * noeud de calcul + */ +export abstract class ComputeNode extends Debug { + protected _prms: IParamsEquation; + + protected abstract setParametersCalculability(); + + constructor(prms: IParamsEquation, dbg: boolean = false) { + super(dbg); + this._prms = prms; + this.setParametersCalculability(); + } +} diff --git a/src/regime_uniforme.ts b/src/regime_uniforme.ts index bee2efa5db81407af69fad80ede733355660edee..260198b76395069ae91b99a37dc134f0288e9201 100644 --- a/src/regime_uniforme.ts +++ b/src/regime_uniforme.ts @@ -1,19 +1,23 @@ -import { Result, IParamsEquation } from "./base"; +import { Result } from "./base"; import { Nub } from "./nub"; -import { acSection, cParamsCanal } from "./section/section_type"; - - +import { ParamsSection, acSection } from "./section/section_type"; +import { ParamDefinition, ParamCalculability, IParamsEquation } from "./param" export class RegimeUniforme extends Nub { private Sn: acSection; ///< Objet section constructor(s: acSection, dbg: boolean = false) { - super(s.v, dbg); - + super(s.prms, dbg); this.Sn = s; + } + + protected setParametersCalculability() { + this.prms.Q.calculability = ParamCalculability.EQUATION; + this.prms.Y.calculability = ParamCalculability.EQUATION; + } - this.AddVarEq("Q"); - this.AddVarEq("Y"); + get prms(): ParamsSection { + return <ParamsSection>this._prms; } /** @@ -22,11 +26,11 @@ export class RegimeUniforme extends Nub { */ Calc_Qn(): number { this.Sn.Reset(true); - if (this.Sn.oP.v.If <= 0) { + if (this.Sn.prms.If.v <= 0) { var Qn: number = 0; // ? false bool //this.oLog.Add('h_normale_pente_neg_nul',true); } else { - Qn = this.Sn.oP.v.Ks * Math.pow(this.Sn.Calc('R', this.Sn.v.Y), 2 / 3) * this.Sn.Calc('S', this.Sn.v.Y) * Math.sqrt(this.Sn.oP.v.If); + Qn = this.Sn.prms.Ks.v * Math.pow(this.Sn.Calc("R", this.Sn.prms.Y.v), 2 / 3) * this.Sn.Calc("S", this.Sn.prms.Y.v) * Math.sqrt(this.Sn.prms.If.v); //this.debug("RU : Qn=" + Qn); } return Qn; @@ -37,7 +41,7 @@ export class RegimeUniforme extends Nub { switch (sVarCalc) { case 'Y': - v = this.Sn.Calc('Yn'); + v = this.Sn.Calc("Yn"); break; case 'Q': @@ -50,7 +54,7 @@ export class RegimeUniforme extends Nub { // break; default: - throw "invalid variable name " + sVarCalc; + throw "RegimeUniforme.Equation() : invalid variable name " + sVarCalc; } return new Result(v); diff --git a/src/section/hauteur.ts b/src/section/hauteur.ts index c62e28c49b51d5fb3c8b81681f6589d59aff8bb4..c56073acf3de656291903aad4571e84643a3c3ab 100644 --- a/src/section/hauteur.ts +++ b/src/section/hauteur.ts @@ -8,17 +8,15 @@ import { cLog } from "./log"; */ export class cHautCritique extends acNewton { private Sn: acSection; - private oP: cParamsCanal; /** * Constructeur de la classe * @param oSn Section sur laquelle on fait le calcul * @param oP Paramètres supplémentaires (Débit, précision...) */ - constructor(Sn: acSection, oP: cParamsCanal, dbg: boolean = false) { - super(oP, dbg); + constructor(Sn: acSection, dbg: boolean = false) { + super(Sn.prms, dbg); this.Sn = Sn.clone(); - this.oP = oP; } /** @@ -27,8 +25,8 @@ export class cHautCritique extends acNewton { */ CalcFn(rX) { // Calcul de la fonction - if (this.Sn.Calc('S', rX) != 0) { - var Fn = (Math.pow(this.oP.v.Q, 2) * this.Sn.Calc('B', rX) / Math.pow(this.Sn.Calc('S', rX), 3) / cParamsCanal.G - 1); + if (this.Sn.Calc("S", rX) != 0) { + var Fn = (Math.pow(this.Sn.prms.Q.v, 2) * this.Sn.Calc("B", rX) / Math.pow(this.Sn.Calc("S", rX), 3) / cParamsCanal.G - 1); } else { Fn = Infinity; @@ -41,10 +39,10 @@ export class cHautCritique extends acNewton { * @param rX Variable dont dépend la fonction */ CalcDer(rX) { - if (this.Sn.Calc('S') != 0) { + if (this.Sn.Calc("S") != 0) { // L'initialisation à partir de rX a été faite lors de l'appel à CalcFn - var Der = (this.Sn.Calc('dB') * this.Sn.Calc('S') - 3 * this.Sn.Calc('B') * this.Sn.Calc('B')); - Der = Math.pow(this.oP.v.Q, 2) / cParamsCanal.G * Der / Math.pow(this.Sn.Calc('S'), 4); + var Der = (this.Sn.Calc("dB") * this.Sn.Calc("S") - 3 * this.Sn.Calc("B") * this.Sn.Calc("B")); + Der = Math.pow(this.Sn.prms.Q.v, 2) / cParamsCanal.G * Der / Math.pow(this.Sn.Calc("S"), 4); } else { Der = Infinity; @@ -68,12 +66,12 @@ export class cHautNormale extends acNewton { * @param oSn Section sur laquelle on fait le calcul * @param oP Paramètres supplémentaires (Débit, précision...) */ - constructor(Sn: acSection, oP: cParamsCanal, dbg: boolean = false) { - super(oP, dbg); + constructor(Sn: acSection, dbg: boolean = false) { + super(Sn.prms, dbg); this.Sn = Sn; - this.Q = oP.v.Q; - this.Ks = oP.v.Ks; - this.If = oP.v.If; + this.Q = Sn.prms.Q.v; + this.Ks = Sn.prms.Ks.v; + this.If = Sn.prms.If.v; } /** @@ -82,7 +80,7 @@ export class cHautNormale extends acNewton { */ CalcFn(rX) { // Calcul de la fonction - var Fn = (this.Q - this.Ks * Math.pow(this.Sn.Calc('R', rX), 2 / 3) * this.Sn.Calc('S', rX) * Math.sqrt(this.If)); + var Fn = (this.Q - this.Ks * Math.pow(this.Sn.Calc("R", rX), 2 / 3) * this.Sn.Calc("S", rX) * Math.sqrt(this.If)); return Fn; } @@ -92,8 +90,8 @@ export class cHautNormale extends acNewton { */ CalcDer(rX) { // L'initialisation a été faite lors de l'appel à CalcFn - var Der = 2 / 3 * this.Sn.Calc('dR') * Math.pow(this.Sn.Calc('R'), -1 / 3) * this.Sn.Calc('S'); - Der = Der + Math.pow(this.Sn.Calc('R'), 2 / 3) * this.Sn.Calc('B'); + var Der = 2 / 3 * this.Sn.Calc("dR") * Math.pow(this.Sn.Calc("R"), -1 / 3) * this.Sn.Calc("S"); + Der = Der + Math.pow(this.Sn.Calc("R"), 2 / 3) * this.Sn.Calc("B"); Der = Der * -this.Ks * Math.sqrt(this.If); //spip_log('cHautNormale:CalcDer('.rX.')='.rDer,'hydraulic.'._LOG_DEBUG); return Der; @@ -114,12 +112,12 @@ export class cHautCorrespondante extends acNewton { * @param oSn Section sur laquelle on fait le calcul * @param oP Paramètres supplémentaires (Débit, précision...) */ - constructor(Sn: acSection, oP: cParamsCanal, dbg: boolean = false) { - super(oP, dbg); - this.Y = Sn.v.Y; - this.rS2 = Math.pow(Sn.Calc('S'), -2); + constructor(Sn: acSection, dbg: boolean = false) { + super(Sn.prms, dbg); + this.Y = Sn.prms.Y.v; + this.rS2 = Math.pow(Sn.Calc("S"), -2); this.Sn = Sn; - this.rQ2G = Math.pow(oP.v.Q, 2) / (2 * cParamsCanal.G); + this.rQ2G = Math.pow(Sn.prms.Q.v, 2) / (2 * cParamsCanal.G); } /** @@ -128,7 +126,7 @@ export class cHautCorrespondante extends acNewton { */ CalcFn(rX) { // Calcul de la fonction - var Fn = this.Y - rX + (this.rS2 - Math.pow(this.Sn.Calc('S', rX), -2)) * this.rQ2G; + var Fn = this.Y - rX + (this.rS2 - Math.pow(this.Sn.Calc("S", rX), -2)) * this.rQ2G; //~ spip_log('cHautCorrespondante:CalcFn('.rX.')='.rFn,'hydraulic.'._LOG_DEBUG); return Fn; } @@ -139,8 +137,8 @@ export class cHautCorrespondante extends acNewton { */ CalcDer(rX) { // L'initialisation a été faite lors de l'appel à CalcFn - if (this.Sn.Calc('S') != 0) { - var Der = -1 + 2 * this.rQ2G * this.Sn.Calc('B') / Math.pow(this.Sn.Calc('S'), 3); + if (this.Sn.Calc("S") != 0) { + var Der = -1 + 2 * this.rQ2G * this.Sn.Calc("B") / Math.pow(this.Sn.Calc("S"), 3); } else { Der = Infinity; @@ -172,13 +170,13 @@ export class cHautConjuguee extends acNewton { * @param oSn Section sur laquelle on fait le calcul * @param oP Paramètres supplémentaires (Débit, précision...) */ - constructor(oSn: acSection, oP: cParamsCanal, dbg: boolean = false) { - super(oP, dbg); - this.Y = oSn.v.Y; - this.rQ2 = Math.pow(oP.v.Q, 2); + constructor(oSn: acSection, dbg: boolean = false) { + super(oSn.prms, dbg); + this.Y = oSn.prms.Y.v; + this.rQ2 = Math.pow(oSn.prms.Q.v, 2); this.Sn = oSn; - this.rS = oSn.Calc('S'); - this.rSYg = oSn.Calc('SYg'); + this.rS = oSn.Calc("S"); + this.rSYg = oSn.Calc("SYg"); } /** @@ -186,10 +184,10 @@ export class cHautConjuguee extends acNewton { * @param rX Variable dont dépend la fonction */ CalcFn(rX) { - // Réinitialisation des paramètres hydrauliques de oSn avec l'appel this->oSn->Calc('S',rX) - if (this.rS > 0 && this.Sn.Calc('S', rX) > 0) { - var Fn = this.rQ2 * (1 / this.rS - 1 / this.Sn.Calc('S')); - Fn = Fn + cParamsCanal.G * (this.rSYg - this.Sn.Calc('SYg')); + // Réinitialisation des paramètres hydrauliques de oSn avec l'appel this->oSn->Calc("S',rX) + if (this.rS > 0 && this.Sn.Calc("S", rX) > 0) { + var Fn = this.rQ2 * (1 / this.rS - 1 / this.Sn.Calc("S")); + Fn = Fn + cParamsCanal.G * (this.rSYg - this.Sn.Calc("SYg")); } else { Fn = -Infinity; @@ -204,9 +202,9 @@ export class cHautConjuguee extends acNewton { */ CalcDer(rX) { // L'initialisation a été faite lors de l'appel à CalcFn - if (this.rS > 0 && this.Sn.Calc('S') > 0) { - var Der = this.rQ2 * this.Sn.Calc('dS') * Math.pow(this.Sn.Calc('S'), -2); - Der = Der - cParamsCanal.G * this.Sn.Calc('dSYg', rX); + if (this.rS > 0 && this.Sn.Calc("S") > 0) { + var Der = this.rQ2 * this.Sn.Calc("dS") * Math.pow(this.Sn.Calc("S"), -2); + Der = Der - cParamsCanal.G * this.Sn.Calc("dSYg", rX); } else { Der = -Infinity; diff --git a/src/section/newton.ts b/src/section/newton.ts index 592beb944802773c6759d6f2d1808eee2d9d8cb4..f89e2bc775538d89a1383f9d563462ce21614215 100644 --- a/src/section/newton.ts +++ b/src/section/newton.ts @@ -18,8 +18,8 @@ export abstract class acNewton extends Debug { */ constructor(oP: cParamsCanal, dbg: boolean = false) { super(dbg); - this.rTol = oP.v.Prec; - this.Dx = oP.v.Prec / 10; + this.rTol = oP.Prec.v; + this.Dx = oP.Prec.v / 10; } /** diff --git a/src/section/section_circulaire.ts b/src/section/section_circulaire.ts index cc327cc78ddad0fb035de37d84d93ee43073caf2..e32b23467c8bef34d7471c32119a9570e78f508f 100644 --- a/src/section/section_circulaire.ts +++ b/src/section/section_circulaire.ts @@ -1,6 +1,24 @@ -import { acSection, cParamsCanal } from "./section_type"; +import { ParamDefinition, ParamDomain, ParamDomainValue, ParamCalculability } from "../param"; +import { acSection, ParamsSection } from "./section_type"; import { cLog } from "./log"; +export class ParamsSectionCirc extends ParamsSection { + private _D: ParamDefinition; // Diamètre du cercle + + constructor(rD, rY, rKs, rQ, rIf, rPrec, rYB, rYCL = undefined, rDx = undefined, rLong = undefined) { + super(rY, undefined, rKs, rQ, rIf, rPrec, rYB, rYCL); + this._D = new ParamDefinition('D', ParamDomainValue.POS, rD); + } + + /** + * Diamètre du cercle + */ + get D(): ParamDefinition { + return this._D; + } +} + + /** * Calculs de la section circulaire */ @@ -10,10 +28,22 @@ export class cSnCirc extends acSection { private Alpha: number; /// Angle de la surface libre par rapport au fond protected nbDessinPoints = 50; - constructor(oLog: cLog, oP: cParamsCanal, D: number, dbg: boolean = false) { + // constructor(oLog: cLog, oP: cParamsCanal, D: number, dbg: boolean = false) { + constructor(oLog: cLog, oP: ParamsSectionCirc, dbg: boolean = false) { super(oLog, oP, dbg); - this.v.D = D; // 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 + + if (this.prms.D.isDefined() && this.prms.YB.isDefined()) + this.CalcGeo('B'); + } + + protected setParametersCalculability() { + super.setParametersCalculability(); + this.prms.D.calculability = ParamCalculability.DICHO; + } + + get prms(): ParamsSectionCirc { + return <ParamsSectionCirc>this._prms; } /** @@ -23,19 +53,19 @@ export class cSnCirc extends acSection { */ 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); + // this.debug('YB ' + this.prms.YB.v); + // this.debug('D ' + this.prms.D.v); + // this.debug('min ' + Math.min(this.prms.YB.v, this.prms.D.v)); + // this.debug('Y ' + this.prms.Y.v); - // 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() + // let min = Math.min(this.prms.YB.v, this.prms.D.v); + // this.debug('min( YB(=' + this.prms.YB.v + '), D(=' + this.prms.D.v + ')) = ' + min); + // this.debug('max(0, Y(=' + this.prms.Y.v + ') - min(YB, D)(=' + min + ') = ' + Math.max(0, this.prms.Y.v - Math.min(this.prms.YB.v, this.prms.D.v))); + // return Math.max(0, this.prms.Y.v - Math.min(this.prms.YB.v, this.prms.D.v)); + return this.prms.Y.v - Math.min(this.prms.YB.v, this.prms.D.v); // >= 0 par définition, et toujours vrai car utilisé après test isDebordement() // if (this.isDebordement()) - // return this.v.Y - this.v.YB; + // return this.prms.Y.v - this.prms.YB.v; // return 0; } @@ -45,9 +75,9 @@ export class cSnCirc extends acSection { * @returns true en cas de débordement */ private isDebordement(): boolean { - // return this.v.Y > Math.min(this.v.YB, this.v.D); + // return this.prms.Y.v > Math.min(this.prms.YB.v, this.prms.D.v); //return this.valeurYDebordement() > 0; - return this.v.Y >= this.v.D || this.v.Y >= this.v.YB + return this.prms.Y.v >= this.prms.D.v || this.prms.Y.v >= this.prms.YB.v } /** @@ -55,21 +85,21 @@ export class cSnCirc extends acSection { * @return Alpha */ // Calc_Alpha() { - // if (this.v.Y > this.oP.v.YB) { + // if (this.prms.Y.v > this.oP.v.YB) { // // var rY = this.oP.v.YB; - // var rY = this.v.YB; + // var rY = this.prms.YB.v; // } // else { - // rY = this.v.Y; + // rY = this.prms.Y.v; // } // if (rY <= 0) { // return 0; // } - // else if (rY > this.v.D) { + // else if (rY > this.prms.D.v) { // return Math.PI; // } // else { - // var alpha = Math.acos(1. - rY / (this.v.D / 2.)); + // var alpha = Math.acos(1. - rY / (this.prms.D.v / 2.)); // if (alpha > Math.PI) { // return Math.PI; // } @@ -78,17 +108,23 @@ export class cSnCirc extends acSection { // } // } // } + private Calc_AlphaY(Y: number, D: number) { + let alpha = Math.acos(1. - Y / (D / 2.)); + return Math.min(alpha, Math.PI); + } + Calc_Alpha() { - if (this.v.Y <= 0) + if (this.prms.Y.v <= 0) return 0; if (this.isDebordement()) return Math.PI; - let alpha = Math.acos(1. - this.v.Y / (this.v.D / 2.)); - if (alpha > Math.PI) - return Math.PI; + // let alpha = Math.acos(1. - this.prms.Y.v / (this.prms.D.v / 2.)); + // if (alpha > Math.PI) + // return Math.PI; - return alpha; + // return alpha; + return this.Calc_AlphaY(this.prms.Y.v, this.prms.D.v); } /** @@ -96,12 +132,20 @@ 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.isDebordement()) { + // if (this.prms.Y.v <= 0 || this.prms.Y.v >= this.prms.D.v || this.prms.Y.v > this.oP.v.YB) { + if (this.prms.Y.v <= 0 || this.isDebordement()) return 0; - } - else { - return 2. / this.v.D / Math.sqrt(1. - Math.pow(1. - 2. * this.v.Y / this.v.D, 2)); + + return 2. / this.prms.D.v / Math.sqrt(1. - Math.pow(1. - 2. * this.prms.Y.v / this.prms.D.v, 2)); + } + + Calc_LargeurBerge() { + if (this.prms.D.isDefined && this.prms.YB.isDefined) { + let d = this.prms.D.v; + let yb = this.prms.YB.v; + if (yb >= d) + return 0; + return this.Calc_AlphaY(yb, d); } } @@ -110,13 +154,15 @@ export class cSnCirc extends acSection { * @return B */ Calc_B() { - // if (this.v.Y > this.oP.v.YB) { + // if (this.prms.Y.v > this.oP.v.YB) { if (this.isDebordement()) { + if (!this.prms.LargeurBerge.isDefined()) + this.prms.LargeurBerge.v = this.Calc_LargeurBerge(); + return super.Calc_B_Debordement(); } - else { - return this.v.D * Math.sin(this.Calc('Alpha')); - } + + return this.prms.D.v * Math.sin(this.Calc("Alpha")); } /** @@ -126,15 +172,13 @@ export class cSnCirc extends acSection { */ // Calc_P(rY = 0) { Calc_P() { - // if (this.v.Y > this.oP.v.YB && !this.bSnFermee) { - if (this.isDebordement() && !this.bSnFermee) { + // if (this.prms.Y.v > 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.valeurYDebordement()); - } - else { - return this.v.D * this.Calc('Alpha'); - } + // return this.CalcGeo("P') + super.Calc_P_Debordement(this.prms.Y.v - this.oP.v.YB); + return this.CalcGeo("P") + super.Calc_P_Debordement(this.valeurYDebordement()); + + return this.prms.D.v * this.Calc("Alpha"); } /** @@ -144,14 +188,13 @@ export class cSnCirc extends acSection { */ // Calc_S(rY = 0) { Calc_S() { - // 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'))); - } + // if (this.prms.Y.v > this.oP.v.YB) { + if (this.isDebordement() && !this.bSnFermee) + // return this.CalcGeo("S") + super.Calc_S_Debordement(this.prms.Y.v - this.oP.v.YB); + return this.CalcGeo("S") + super.Calc_S_Debordement(this.valeurYDebordement()); + + let alpha = this.Calc("Alpha"); + return Math.pow(this.prms.D.v, 2) / 4 * (alpha - Math.sin(alpha) * Math.cos(alpha)); } @@ -160,13 +203,11 @@ export class cSnCirc extends acSection { * @return dP */ Calc_dP() { - // if (this.v.Y > this.oP.v.YB && !this.bSnFermee) { - if (this.isDebordement() && !this.bSnFermee) { + // if (this.prms.Y.v > this.oP.v.YB && !this.bSnFermee) { + if (this.isDebordement() && !this.bSnFermee) return super.Calc_dP_Debordement(); - } - else { - return this.v.D * this.Calc('dAlpha'); - } + + return this.prms.D.v * this.Calc("dAlpha"); } /** @@ -174,13 +215,11 @@ export class cSnCirc extends acSection { * @return dB */ Calc_dB() { - // if (this.v.Y > this.oP.v.YB) { - if (this.isDebordement()) { + // if (this.prms.Y.v > 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')); - } + + return this.prms.D.v * this.Calc("dAlpha") * Math.cos(this.Calc("Alpha")); } /** @@ -191,8 +230,9 @@ export class cSnCirc extends acSection { */ // Calc_SYg(rY = 0) { Calc_SYg() { - var SYg = Math.sin(this.Calc('Alpha')) - Math.pow(Math.sin(this.Calc('Alpha')), 3) / 3 - this.Calc('Alpha') * Math.cos(this.Calc('Alpha')); - SYg = Math.pow(this.v.D, 3) / 8 * SYg; + let alpha = this.Calc("Alpha"); + let SYg = Math.sin(alpha) - Math.pow(Math.sin(alpha), 3) / 3 - alpha * Math.cos(alpha); + SYg = Math.pow(this.prms.D.v, 3) / 8 * SYg; return SYg; } @@ -204,12 +244,14 @@ export class cSnCirc extends acSection { */ // Calc_dSYg(rY = 0) { Calc_dSYg() { - var cos = Math.cos(this.Calc('Alpha')); - var sin = Math.sin(this.Calc('Alpha')); - var SYg = this.Calc('dAlpha') * cos; - SYg += - this.Calc('dAlpha') * cos * Math.pow(sin, 2); - SYg += - this.Calc('dAlpha') * cos + this.Calc('Alpha') * this.Calc('dAlpha') * sin; - SYg = 3 * Math.pow(this.v.D, 3) / 8 * SYg; + let alpha = this.Calc("Alpha"); + let dAlpha = this.Calc("dAlpha"); + var cos = Math.cos(alpha); + var sin = Math.sin(alpha); + var SYg = dAlpha * cos; + SYg += - dAlpha * cos * Math.pow(sin, 2); + SYg += - dAlpha * cos + alpha * dAlpha * sin; + SYg = 3 * Math.pow(this.prms.D.v, 3) / 8 * SYg; return SYg; } } \ No newline at end of file diff --git a/src/section/section_puissance.ts b/src/section/section_puissance.ts index 07f51e6f262db0a428453816d272c3f1a0eaa6bb..d458864c954d77727f96a7d969b934a887d7edf8 100644 --- a/src/section/section_puissance.ts +++ b/src/section/section_puissance.ts @@ -1,6 +1,24 @@ -import { acSection, cParamsCanal } from "./section_type"; +import { ParamDefinition, ParamDomain, ParamDomainValue, ParamCalculability } from "../param"; +import { acSection, ParamsSection } from "./section_type"; import { cLog } from "./log"; + +export class ParamsSectionPuiss extends ParamsSection { + private _k: ParamDefinition; // Coefficient de forme compris entre 0 et 1 + + constructor(rk, rY, rLargeurBerge, rKs, rQ, rIf, rPrec, rYB, rYCL = 0, rDx = 0, rLong = 0) { + super(rY, rLargeurBerge, rKs, rQ, rIf, rPrec, rYB, rYCL); + this._k = new ParamDefinition('k', new ParamDomain(ParamDomainValue.INTERVAL, 0, 1), rk); + } + + /** + * Coefficient de forme compris entre 0 et 1 + */ + get k(): ParamDefinition { + return this._k; + } +} + /** * Calculs de la section parabolique ou "puissance" */ @@ -9,28 +27,38 @@ export class cSnPuiss extends acSection { //LargeurBerge => La largeur des berges est déjà présente dans acSection protected nbDessinPoints = 50; - constructor(oLog: cLog, oP: cParamsCanal, rk: number, LargeurBerge: number, dbg: boolean = false) { + constructor(oLog: cLog, oP: ParamsSectionPuiss, dbg: boolean = false) { super(oLog, oP, dbg); - this.v.k = rk; - this.v.LargeurBerge = LargeurBerge; + // this.prms.k = rk; + // this.prms.LargeurBerge = LargeurBerge; + } + + protected setParametersCalculability() { + super.setParametersCalculability(); + this.prms.k.calculability = ParamCalculability.DICHO; } + + get prms(): ParamsSectionPuiss { + return <ParamsSectionPuiss>this._prms; + } + /** * Calcul de Lambda (mais on garde la routine Alpha commune avec la section circulaire) * @return Lambda */ - Calc_Alpha() { - return this.v.LargeurBerge / Math.pow(this.oP.v.YB, this.v.k); + Calc_Alpha(): number { + return this.prms.LargeurBerge.v / Math.pow(this.prms.YB.v, this.prms.k.v); } /** * Calcul de la largeur au miroir. * @return B */ - Calc_B() { - if (this.v.Y >= this.oP.v.YB) { - return this.v.LargeurBerge; + Calc_B(): number { + if (this.prms.Y.v >= this.prms.YB.v) { + return this.prms.LargeurBerge.v; } else { - return this.Calc('Alpha') * Math.pow(this.v.Y, this.v.k); + return this.Calc("Alpha") * Math.pow(this.prms.Y.v, this.prms.k.v); } } /** @@ -39,13 +67,13 @@ export class cSnPuiss extends acSection { * @return B */ // Calc_P(rY = 0) { - Calc_P() { + Calc_P(): number { var n = 100; /// Le nombre de partie pour le calcul de l'intégrale - var Lambda2 = Math.pow(this.Calc('Alpha'), 2); + var Lambda2 = Math.pow(this.Calc("Alpha"), 2); var P = 0; /// Le périmètre à calculer var Previous = 0; for (var i = 1; i <= n; i++) { - var Current = Math.pow(this.v.Y * i / n, this.v.k) / 2; + var Current = Math.pow(this.prms.Y.v * i / n, this.prms.k.v) / 2; P += Math.sqrt(Math.pow(n, -2) + Lambda2 * Math.pow(Current - Previous, 2)); Previous = Current; } @@ -59,24 +87,27 @@ export class cSnPuiss extends acSection { * @return S */ // Calc_S(rY = 0) { - Calc_S() { - return this.Calc('Alpha') * Math.pow(this.v.Y, this.v.k + 1) / (this.v.k + 1); + Calc_S(): number { + let k = this.prms.k.v; + return this.Calc("Alpha") * Math.pow(this.prms.Y.v, k + 1) / (k + 1); } /** * Calcul de dérivée du périmètre hydraulique par rapport au tirant d'eau. * @return dP */ - Calc_dP() { - return 2 * Math.sqrt(1 + Math.pow(this.v.k * this.Calc('Alpha') / 2, 2) * Math.pow(this.v.Y, 2 * (this.v.k - 1))); + Calc_dP(): number { + let k = this.prms.k.v; + return 2 * Math.sqrt(1 + Math.pow(k * this.Calc("Alpha") / 2, 2) * Math.pow(this.prms.Y.v, 2 * (k - 1))); } /** * Calcul de dérivée de la largeur au miroir par rapport au tirant d'eau. * @return dB */ - Calc_dB() { - return this.Calc('Alpha') * this.v.k * Math.pow(this.v.Y, this.v.k - 1); + Calc_dB(): number { + let k = this.prms.k.v; + return this.Calc("Alpha") * k * Math.pow(this.prms.Y.v, k - 1); } /** * Calcul de la distance du centre de gravité de la section à la surface libre @@ -85,8 +116,9 @@ export class cSnPuiss extends acSection { * @return S x Yg */ // Calc_SYg(rY = 0) { - Calc_SYg() { - return this.Calc('Alpha') * Math.pow(this.v.Y, this.v.k + 2) / ((this.v.k + 1) * (this.v.k + 2)); + Calc_SYg(): number { + let k = this.prms.k.v; + return this.Calc("Alpha") * Math.pow(this.prms.Y.v, k + 2) / ((k + 1) * (k + 2)); } /** * Calcul de la dérivée distance du centre de gravité de la section à la surface libre @@ -95,8 +127,10 @@ export class cSnPuiss extends acSection { * @return S x Yg */ // Calc_dSYg(rY = 0) { - Calc_dSYg() { - var SYg = this.Calc('dAlpha') * Math.pow(this.v.Y, this.v.k + 2) + this.Calc('Alpha') * Math.pow(this.v.Y, this.v.k + 1) * (this.v.k + 2); - return SYg / ((this.v.k + 1) * (this.v.k + 2)); + Calc_dSYg(): number { + let k = this.prms.k.v; + let Y = this.prms.Y.v; + let SYg = this.Calc("dAlpha") * Math.pow(Y, k + 2) + this.Calc("Alpha") * Math.pow(Y, k + 1) * (k + 2); + return SYg / ((k + 1) * (k + 2)); } } \ No newline at end of file diff --git a/src/section/section_rectang.ts b/src/section/section_rectang.ts index e8e3ef75006d0f52b77679fba3ed480cfab089a0..f0dfb3ecd6723f60efe126c21d85fd082acdf616 100644 --- a/src/section/section_rectang.ts +++ b/src/section/section_rectang.ts @@ -1,13 +1,25 @@ -import { acSection, cParamsCanal } from "./section_type"; +import { ParamDefinition, ParamDomain, ParamCalculability } from "../param"; +import { acSection, ParamsSection } from "./section_type"; import { cLog } from "./log"; +export class ParamsSectionRectang extends ParamsSection { + constructor(rY, rLargeurFond, rKs, rQ, rIf, rPrec, rYB, rYCL = 0, rDx = 0, rLong = 0) { + super(rY, + rLargeurFond, // LargeurBerge=LargeurFond + rKs, rQ, rIf, rPrec, rYB, rYCL); + } +} + /** * Calculs de la section rectangulaire */ export class cSnRectang extends acSection { - constructor(oLog: cLog, oP: cParamsCanal, LargeurFond: number, dbg: boolean = false) { + constructor(oLog: cLog, oP: ParamsSectionRectang, dbg: boolean = false) { super(oLog, oP, dbg); - this.v.LargeurBerge = LargeurFond; + } + + get prms(): ParamsSectionRectang { + return <ParamsSectionRectang>this._prms; } /** @@ -16,31 +28,31 @@ export class cSnRectang extends acSection { * @return Périmètre mouillé (m) */ // Calc_P(rY = 0) { - Calc_P() { - return this.v.LargeurBerge + super.Calc_P_Debordement(this.v.Y); + Calc_P(): number { + return this.prms.LargeurBerge.v + super.Calc_P_Debordement(this.prms.Y.v); } - Calc_dP() { + Calc_dP(): number { return super.Calc_dP_Debordement(); } - Calc_B() { + Calc_B(): number { return super.Calc_B_Debordement(); } - Calc_dB() { + Calc_dB(): number { return super.Calc_dB_Debordement(); } - Calc_S() { - return super.Calc_S_Debordement(this.v.Y); + Calc_S(): number { + return super.Calc_S_Debordement(this.prms.Y.v); } /** * Calcul du tirant d'eau conjugué avec la formule analytique pour la section rectangulaire * @return tirant d'eau conjugué */ - CalcYco() { - return this.v.Y * (Math.sqrt(1 + 8 * Math.pow(this.Calc('Fr'), 2)) - 1) / 2; + CalcYco(): number { + return this.prms.Y.v * (Math.sqrt(1 + 8 * Math.pow(this.Calc("Fr"), 2)) - 1) / 2; } } \ No newline at end of file diff --git a/src/section/section_trapez.ts b/src/section/section_trapez.ts index 118fa195532e78ddd9da9fc3a03167a4e0eeafd8..f8d71c0110c9a65ede8fe19fefa940da62188a14 100644 --- a/src/section/section_trapez.ts +++ b/src/section/section_trapez.ts @@ -1,24 +1,61 @@ -import { acSection, cParamsCanal } from "./section_type"; +import { ParamDefinition, ParamDomain, ParamDomainValue, ParamCalculability } from "../param"; +import { acSection, ParamsSection } from "./section_type"; import { cLog } from "./log"; + +export class ParamsSectionTrapez extends ParamsSection { + private _LargeurFond: ParamDefinition; // Largeur au fond + private _Fruit: ParamDefinition; // Fruit des berges + + constructor(rLargeurFond, rFruit, rY, rKs, rQ, rIf, rPrec, rYB, rYCL = 0, rDx = 0, rLong = 0) { + super(rY, undefined, rKs, rQ, rIf, rPrec, rYB, rYCL); + this._LargeurFond = new ParamDefinition('LargeurFond', ParamDomainValue.POS_NULL, rLargeurFond); + this._Fruit = new ParamDefinition('Fruit', ParamDomainValue.POS_NULL, rFruit); + } + + /** + * Largeur au fond + */ + get LargeurFond(): ParamDefinition { + return this._LargeurFond; + } + + /** + * Fruit des berges + */ + get Fruit(): ParamDefinition { + return this._Fruit; + } +} + + /** * Calculs de la section trapézoïdale */ export class cSnTrapez extends acSection { // public LargeurFond; /// Largeur au fond // public Fruit; /// Fruit des berges - constructor(oLog: cLog, oP: cParamsCanal, LargeurFond: number, Fruit: number, dbg: boolean = false) { + constructor(oLog: cLog, oP: ParamsSectionTrapez, dbg: boolean = false) { super(oLog, oP, dbg); - this.v.LargeurFond = LargeurFond; - this.v.Fruit = Fruit; } - Calc_B(bBerge = false) { - if (!bBerge && this.v.Y > this.oP.v.YB) { - return this.v.LargeurBerge; + + protected setParametersCalculability() { + super.setParametersCalculability(); + this.prms.LargeurFond.calculability = ParamCalculability.DICHO; + this.prms.Fruit.calculability = ParamCalculability.DICHO; + } + + get prms(): ParamsSectionTrapez { + return <ParamsSectionTrapez>this._prms; + } + + Calc_B(bBerge = false): number { + if (!bBerge && this.prms.Y > this.prms.YB) { + return this.prms.LargeurBerge.v; } else { - return this.v.LargeurFond + 2 * this.v.Fruit * this.v.Y; + return this.prms.LargeurFond.v + 2 * this.prms.Fruit.v * this.prms.Y.v; } } @@ -28,12 +65,12 @@ export class cSnTrapez extends acSection { * @return Périmètre mouillé (m) */ // Calc_P(rY = 0) { - Calc_P() { - if (this.v.Y > this.oP.v.YB) { - var P = this.CalcGeo('P') + super.Calc_P_Debordement(this.v.Y - this.oP.v.YB); + Calc_P(): number { + if (this.prms.Y > this.prms.YB) { + var P = this.CalcGeo("P") + super.Calc_P_Debordement(this.prms.Y.v - this.prms.YB.v); } else { - P = this.v.LargeurFond + 2 * Math.sqrt(1 + Math.pow(this.v.Fruit, 2)) * this.v.Y; + P = this.prms.LargeurFond.v + 2 * Math.sqrt(1 + Math.pow(this.prms.Fruit.v, 2)) * this.prms.Y.v; } //~ spip_log('Trapez->CalcP(rY='.this->rY.')='.P,'hydraulic.'._LOG_DEBUG); return P; @@ -45,12 +82,12 @@ export class cSnTrapez extends acSection { * @return Surface mouillée (m2) */ // Calc_S(rY = 0) { - Calc_S() { - if (this.v.Y > this.oP.v.YB) { - var S = this.CalcGeo('S') + super.Calc_S_Debordement(this.v.Y - this.oP.v.YB); + Calc_S(): number { + if (this.prms.Y > this.prms.YB) { + var S = this.CalcGeo("S") + super.Calc_S_Debordement(this.prms.Y.v - this.prms.YB.v); } else { - S = this.v.Y * (this.v.LargeurFond + this.v.Fruit * this.v.Y); + S = this.prms.Y.v * (this.prms.LargeurFond.v + this.prms.Fruit.v * this.prms.Y.v); } //~ spip_log('Trapez->CalcS(rY='.this->rY.')='.S,'hydraulic.'._LOG_DEBUG); return S; @@ -60,12 +97,12 @@ export class cSnTrapez extends acSection { * Calcul de dérivée de la surface hydraulique par rapport au tirant d'eau. * @return dS */ - Calc_dS() { - if (this.v.Y > this.oP.v.YB) { + Calc_dS(): number { + if (this.prms.Y > this.prms.YB) { return super.Calc_dS(); } else { - return this.v.LargeurFond + 2 * this.v.Fruit * this.v.Y; + return this.prms.LargeurFond.v + 2 * this.prms.Fruit.v * this.prms.Y.v; } } @@ -73,12 +110,12 @@ export class cSnTrapez extends acSection { * Calcul de dérivée du périmètre hydraulique par rapport au tirant d'eau. * @return dP */ - Calc_dP() { - if (this.v.Y > this.oP.v.YB) { + Calc_dP(): number { + if (this.prms.Y > this.prms.YB) { return super.Calc_dP_Debordement(); } else { - return 2 * Math.sqrt(1 + this.v.Fruit * this.v.Fruit); + return 2 * Math.sqrt(1 + this.prms.Fruit.v * this.prms.Fruit.v); } } @@ -86,12 +123,12 @@ export class cSnTrapez extends acSection { * 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) { + Calc_dB(): number { + if (this.prms.Y > this.prms.YB) { return super.Calc_dB_Debordement(); } else { - return 2 * this.v.LargeurFond * this.v.Fruit; + return 2 * this.prms.LargeurFond.v * this.prms.Fruit.v; } } /** @@ -101,8 +138,8 @@ export class cSnTrapez extends acSection { * @return S x Yg */ // Calc_SYg(rY = 0) { - Calc_SYg() { - return (this.v.LargeurFond / 2 + this.v.Fruit * this.v.Y / 3) * Math.pow(this.v.Y, 2); + Calc_SYg(): number { + return (this.prms.LargeurFond.v / 2 + this.prms.Fruit.v * this.prms.Y.v / 3) * Math.pow(this.prms.Y.v, 2); } /** * Calcul de la dérivée de la distance du centre de gravité de la section à la surface libre @@ -111,9 +148,9 @@ export class cSnTrapez extends acSection { * @return S x Yg */ // Calc_dSYg(rY = 0) { - Calc_dSYg() { - var SYg = this.v.Fruit / 3 * Math.pow(this.v.Y, 2); - SYg += (this.v.LargeurFond / 2 + this.v.Fruit * this.v.Y / 3) * 2 * this.v.Y; + Calc_dSYg(): number { + var SYg = this.prms.Fruit.v / 3 * Math.pow(this.prms.Y.v, 2); + SYg += (this.prms.LargeurFond.v / 2 + this.prms.Fruit.v * this.prms.Y.v / 3) * 2 * this.prms.Y.v; return SYg; } } \ No newline at end of file diff --git a/src/section/section_type.ts b/src/section/section_type.ts index a32e55bb3579c6d040c993d1ef35289cb8c4ae32..95c1b01fc4906c8eda338e32129c02389e849241 100644 --- a/src/section/section_type.ts +++ b/src/section/section_type.ts @@ -1,52 +1,138 @@ -import { IParamsEquation, Debug } from "../base" -import { cHautCritique, cHautNormale, cHautCorrespondante, cHautConjuguee } from "./hauteur"; import { cLog } from "./log"; +import { ComputeNode, ParamDefinition, ParamDomain, ParamDomainValue, ParamCalculability, IParamsEquation } from "../param"; +import { cHautCritique, cHautNormale, cHautCorrespondante, cHautConjuguee } from "./hauteur"; /** * Gestion des Paramètres du canal (hors section) */ -export class cParamsCanal { - private _v: IParamsEquation = {}; - - // public YCL; /// Condition limite en cote à l'amont ou à l'aval - // public Ks; /// Strickler - // public Q; /// Débit - // public Long; /// Longueur du bief - // public If; /// Pente du fond - // public Dx; /// Pas d'espace (positif en partant de l'aval, négatif en partant de l'amont) - // public Prec; /// Précision de calcul et d'affichage +export abstract class cParamsCanal implements IParamsEquation { public static readonly G: number = 9.81;/// Constante de gravité - // public iPrec; /// Précision en nombre de décimales - // public YB; /// Hauteur de berge + + private _Ks: ParamDefinition; // Strickler + private _Q: ParamDefinition; // Débit + private _If: ParamDefinition; // Pente du fond + private _Prec: ParamDefinition; // Précision de calcul et d'affichage + private _iPrec: ParamDefinition; // Précision en nombre de décimales + private _YB: ParamDefinition; // Hauteur de berge + private _YCL: ParamDefinition; // Condition limite en cote à l'amont ou à l'aval + private _Dx: ParamDefinition; // Pas d'espace (positif en partant de l'aval, négatif en partant de l'amont) + private _Long: ParamDefinition; // Longueur du bief + // public Resolution; /// Méthode de résolution "Euler" ou "RK4" - constructor(rKs, rQ, rIf, rPrec, rYB, rYCL = 0, rDx = 0, rLong = 0) //, sResolution = '') { + constructor(rKs, rQ, rIf, rPrec, rYB, rYCL = undefined, rDx = undefined, rLong = undefined) //, sResolution = '') { { - //this.v.Resolution = sResolution; - this.v.YCL = rYCL; - this.v.Ks = rKs; - this.v.Q = rQ; - this.v.Long = rLong; - this.v.If = rIf; - this.v.Dx = rDx; - this.v.Prec = rPrec; - this.v.YB = rYB; - this.v.iPrec = -Math.log(rPrec) / Math.log(10); - } - - get v() { return this._v; } + //this.prms.Resolution = sResolution; + this._Ks = new ParamDefinition('Ks', ParamDomainValue.POS, rKs); + this._Q = new ParamDefinition('Q', ParamDomainValue.POS_NULL, rQ); + this._If = new ParamDefinition('If', ParamDomainValue.ANY, rIf); + this._Prec = new ParamDefinition('Prec', ParamDomainValue.POS, rPrec); + this._iPrec = new ParamDefinition('iPrec', ParamDomainValue.ANY, -Math.log(rPrec) / Math.log(10)); + this._YB = new ParamDefinition('YB', ParamDomainValue.POS, rYB); + this._YCL = new ParamDefinition('YCL', ParamDomainValue.POS_NULL, rYCL); + this._Dx = new ParamDefinition('Dx', ParamDomainValue.NOT_NULL, rDx); + this._Long = new ParamDefinition('Long', ParamDomainValue.POS, rLong); + } + + /** + * Strickler + */ + get Ks(): ParamDefinition { + return this._Ks; + } + + /** + * Débit + */ + get Q(): ParamDefinition { + return this._Q; + } + + /** + * Pente du fond + */ + get If(): ParamDefinition { + return this._If; + } + + /** + * Précision de calcul et d'affichage + */ + get Prec(): ParamDefinition { + return this._Prec; + } + + /** + * Précision en nombre de décimales + */ + get iPrec(): ParamDefinition { + return this._iPrec; + } + + /** + * Hauteur de berge + */ + get YB(): ParamDefinition { + return this._YB; + } + + /** + * Condition limite en cote à l'amont ou à l'aval + */ + get YCL(): ParamDefinition { + return this._YCL; + } + + /** + * Pas d'espace (positif en partant de l'aval, négatif en partant de l'amont) + */ + get Dx(): ParamDefinition { + return this._Dx; + } + + /** + * Longueur du bief + */ + get Long() { + return this._Long; + } +} + + +export abstract class ParamsSection extends cParamsCanal { + private _Y: ParamDefinition; // Tirant d'eau + private _LargeurBerge: ParamDefinition; // largeur au débordement + + constructor(rY, rLargeurBerge, rKs, rQ, rIf, rPrec, rYB, rYCL = undefined, rDx = undefined, rLong = undefined) { + super(rKs, rQ, rIf, rPrec, rYB, rYCL, rDx, rLong); + + this._Y = new ParamDefinition('Y', ParamDomainValue.POS_NULL, rY); + this._LargeurBerge = new ParamDefinition('LargeurBerge', ParamDomainValue.POS_NULL, rLargeurBerge); + } + + /** + * Tirant d'eau + */ + get Y(): ParamDefinition { + return this._Y; + } + + /** + * Largeur au débordement + */ + get LargeurBerge(): ParamDefinition { + return this._LargeurBerge; + } } /** * Gestion commune pour les différents types de section. * Comprend les formules pour la section rectangulaire pour gérer les débordements */ -export abstract class acSection extends Debug { - // private _v: IParamsEquation; - +export abstract class acSection extends ComputeNode { //public Y; /// Tirant d'eau public HautCritique: number; /// Tirant d'eau critique public HautNormale; /// Tirant d'eau normal - public oP: cParamsCanal; /// Paramètres du système canal (classe oParam) + //public oP: ParamsSection; /// Paramètres du système canal (classe oParam) protected oLog: cLog; /// Pour l'affichage du journal de calcul //public LargeurBerge; /// largeur au débordement @@ -84,19 +170,35 @@ export abstract class acSection extends Debug { * Construction de la classe. * Calcul des hauteurs normale et critique */ - constructor(oLog: cLog, oP: cParamsCanal, dbg: boolean = false) { - super(dbg); - this.oP = oP; + constructor(oLog: cLog, oP: ParamsSection, dbg: boolean = false) { + super(oP, dbg); + //this.prms = oP; this.oLog = oLog; // this._v = oP.v; // copie la référence au tableau - this.v.Y = 0; - this.v.LargeurBerge = 0; + // this.prms.Y.v = 0; + // this.prms.LargeurBerge.v = 0; - // this.CalcGeo('B'); // à ce point, il manque des paramètres pour certaines sections (ex : fruit pour trapèze) + // this.CalcGeo("B'); // à ce point, il manque des paramètres pour certaines sections (ex : fruit pour trapèze) } - get v() { return this.oP.v; } + protected setParametersCalculability() { + this.prms.Ks.calculability = ParamCalculability.DICHO; + this.prms.Q.calculability = ParamCalculability.DICHO; + this.prms.If.calculability = ParamCalculability.DICHO; + this.prms.Prec.calculability = ParamCalculability.NONE; + this.prms.iPrec.calculability = ParamCalculability.NONE; + this.prms.YB.calculability = ParamCalculability.DICHO; + this.prms.YCL.calculability = ParamCalculability.DICHO; + this.prms.Dx.calculability = ParamCalculability.DICHO; + this.prms.Long.calculability = ParamCalculability.DICHO; + this.prms.Y.calculability = ParamCalculability.DICHO; + this.prms.LargeurBerge.calculability = ParamCalculability.DICHO; + } + + get prms(): ParamsSection { + return <ParamsSection>this._prms; + } public clone(): acSection { return Object.create(this); @@ -117,15 +219,15 @@ export abstract class acSection extends Debug { * Mémorise les données hydraulique en cours ou les restitue * @param bMem true pour mémorisation, false pour restitution */ - Swap(bMem) { + private Swap(bMem) { if (bMem) { - this.debug('save Y=' + this.v.Y); - this.Y_old = this.v.Y; + this.debug('save Y=' + this.prms.Y.v); + this.Y_old = this.prms.Y.v; this.Calc_old = this.arCalc; } else { this.debug('restore Y=' + this.Y_old); - this.v.Y = this.Y_old; + this.prms.Y.v = this.Y_old; this.arCalc = this.Calc_old; this.Calc_old = {}; } @@ -137,12 +239,12 @@ export abstract class acSection extends Debug { * @param bRecalc Pour forcer le recalcul de la donnée * @return la donnée calculée */ - Calc(sDonnee: string, rY: number = undefined) { - this.debug('in Calc(' + sDonnee + ', rY=' + rY + ') old ' + sDonnee + '=' + this.arCalc[sDonnee]); - this.debug('this.Y=' + this.v.Y); + Calc(sDonnee: string, rY: number = undefined): number { + this.debug("in Calc(" + sDonnee + ", rY = " + rY + ") old " + sDonnee + "= " + this.arCalc[sDonnee]); + this.debug("this.Y=" + this.prms.Y.v); - if (rY != undefined && rY != this.v.Y) { - this.v.Y = rY; + if (rY != undefined && rY != this.prms.Y.v) { + this.prms.Y.v = rY; // On efface toutes les données dépendantes de Y pour forcer le calcul this.Reset(false); } @@ -150,7 +252,7 @@ export abstract class acSection extends Debug { // La donnée a besoin d'être calculée switch (sDonnee) { case 'I-J': // Variation linéaire de l'énergie spécifique (I-J) en m/m - this.arCalc[sDonnee] = this.oP.v.If - this.Calc('J'); + this.arCalc[sDonnee] = this.prms.If.v - this.Calc("J"); break; // case 'Yn': // Hauteur normale @@ -169,12 +271,12 @@ export abstract class acSection extends Debug { this.arCalc[sDonnee] = res; break; } - this.debug('Calc(' + sDonnee + ') resultat -> ' + this.arCalc[sDonnee]); + this.debug("Calc(" + sDonnee + ") resultat -> " + this.arCalc[sDonnee]); } else - this.debug('Calc(' + sDonnee + ') cache=' + this.arCalc[sDonnee]); + this.debug("Calc(" + sDonnee + ") cache= " + this.arCalc[sDonnee]); - this.debug('this.Y=' + this.v.Y); + this.debug('this.Y=' + this.prms.Y.v); return this.arCalc[sDonnee]; } @@ -185,31 +287,31 @@ export abstract class acSection extends Debug { * @param rY Hauteur d'eau * @return la donnée calculée */ - CalcGeo(sDonnee) { + CalcGeo(sDonnee): number { this.debug("in CalcGeo(" + sDonnee + ') old ' + sDonnee + '=' + this.arCalcGeo[sDonnee]); - this.debug('this.Y=' + this.v.Y); + this.debug('this.Y=' + this.prms.Y.v); // if (sDonnee != 'B' && !this.arCalcGeo['B']) { if (sDonnee != 'B' && this.arCalcGeo['B'] == undefined) { // Si la largeur aux berges n'a pas encore été calculée, on commence par ça - this.CalcGeo('B'); + this.CalcGeo("B"); } // if (!this.arCalcGeo[sDonnee]) { if (this.arCalcGeo[sDonnee] == undefined) { // La donnée a besoin d'être calculée this.Swap(true); // On mémorise les données hydrauliques en cours this.Reset(false); - this.v.Y = this.oP.v.YB; + this.prms.Y.v = this.prms.YB.v; switch (sDonnee) { case 'B': // Largeur aux berges this.arCalcGeo[sDonnee] = this.Calc_B(); - if (this.arCalcGeo[sDonnee] < this.oP.v.YB / 100) { + if (this.arCalcGeo[sDonnee] < this.prms.YB.v / 100) { // Section fermée this.bSnFermee = true; // On propose une fente de Preissmann égale à 1/100 de la hauteur des berges - this.arCalcGeo[sDonnee] = this.oP.v.YB / 100; + this.arCalcGeo[sDonnee] = this.prms.YB.v / 100; } - this.v.LargeurBerge = this.arCalcGeo[sDonnee]; + this.prms.LargeurBerge.v = this.arCalcGeo[sDonnee]; break; default: @@ -219,15 +321,15 @@ export abstract class acSection extends Debug { this.arCalcGeo[sDonnee] = res; break; } - //~ spip_log('CalcGeo('.sDCalcGeonnee.',rY='.this->oP->rYB.')='.this->arCalcGeo[sDonnee],'hydraulic.'._LOG_DEBUG); + //~ spip_log('CalcGeo(".sDCalcGeonnee.',rY='.this->oP->rYB.')='.this->arCalcGeo[sDonnee],'hydraulic.'._LOG_DEBUG); this.Swap(false); // On restitue les données hydrauliques en cours - this.debug('CalcGeo(' + sDonnee + ') resultat -> ' + this.arCalcGeo[sDonnee]); + this.debug("CalcGeo(" + sDonnee + ") resultat -> " + this.arCalcGeo[sDonnee]); } - // this.debug('CalcGeo(' + sDonnee + ')=' + this.arCalcGeo[sDonnee]); + // this.debug('CalcGeo(" + sDonnee + ')=' + this.arCalcGeo[sDonnee]); else - this.debug('CalcGeo(' + sDonnee + ') cache=' + this.arCalcGeo[sDonnee]); + this.debug("CalcGeo(" + sDonnee + ") cache= " + this.arCalcGeo[sDonnee]); - this.debug('this.Y=' + this.v.Y); + this.debug('this.Y=' + this.prms.Y.v); return this.arCalcGeo[sDonnee]; } @@ -236,20 +338,20 @@ export abstract class acSection extends Debug { * Calcul de la surface hydraulique. * @return La surface hydraulique */ - abstract Calc_S(); + abstract Calc_S(): number; - Calc_dS() { - return this.Calc('B'); // largeur au miroir + Calc_dS(): number { + return this.Calc("B"); // largeur au miroir } /** * calcul de la surface hydraulique en cas de débordement * @param Y hauteur d'eau au dela de la berge **/ - Calc_S_Debordement(Y: number) { - this.debug('section->CalcS(rY=' + Y + ') LargeurBerge=' + this.v.LargeurBerge); - return Y * this.v.LargeurBerge; + Calc_S_Debordement(Y: number): number { + this.debug('section->CalcS(rY=' + Y + ') LargeurBerge=' + this.prms.LargeurBerge); + return Y * this.prms.LargeurBerge.v; } /** @@ -262,21 +364,21 @@ export abstract class acSection extends Debug { * Calcul de la dérivée surface hydraulique en cas de débordement * @return La dérivée de la surface hydraulique en cas de débordement */ - Calc_dS_Debordement() { - return this.v.LargeurBerge; + Calc_dS_Debordement(): number { + return this.prms.LargeurBerge.v; } /** * Calcul du périmètre hydraulique. * @return Le périmètre hydraulique */ - abstract Calc_P(); + abstract Calc_P(): number; /** * Calcul du périmètre hydraulique en cas de débordement * @param Y hauteur d'eau au dela de la berge */ - Calc_P_Debordement(Y: number) { + Calc_P_Debordement(Y: number): number { return 2 * Y; } @@ -284,13 +386,13 @@ export abstract class acSection extends Debug { * Calcul de dérivée du périmètre hydraulique par rapport au tirant d'eau. * @return dP */ - abstract Calc_dP(); + abstract Calc_dP(): number; /** * Calcul de dérivée du périmètre hydraulique par rapport au tirant d'eau en cas de débordement * @return la dérivée du périmètre hydraulique par rapport au tirant d'eau en cas de débordement */ - Calc_dP_Debordement() { + Calc_dP_Debordement(): number { return 2; } @@ -298,55 +400,53 @@ export abstract class acSection extends Debug { * Calcul du rayon hydraulique. * @return Le rayon hydraulique */ - Calc_R() { + Calc_R(): number { this.debug("in calc_R") - if (this.Calc('P') != 0) { - return this.Calc('S') / this.Calc('P'); - } - else { - return Infinity; - } + let P = this.Calc("P"); + if (P != 0) + return this.Calc("S") / P; + + return Infinity; } /** * Calcul de dérivée du rayon hydraulique par rapport au tirant d'eau. * @return dR */ - Calc_dR() { - if (this.Calc('P') != 0) { - return ((this.Calc('B') * this.Calc('P') - this.Calc('S') * this.Calc('dP')) / Math.pow(this.Calc('P'), 2)); - } - else { - return 0; - } + Calc_dR(): number { + let P = this.Calc("P"); + if (P != 0) + return ((this.Calc("B") * P - this.Calc("S") * this.Calc("dP")) / Math.pow(P, 2)); + + return 0; } /** * Calcul de la largeur au miroir. * @return La largeur au miroir */ - abstract Calc_B(); + abstract Calc_B(): number; /** * Calcul de la largeur au miroir en cas de débordement * @return La largeur au miroir en cas de débordement */ - Calc_B_Debordement() { - return this.v.LargeurBerge; + Calc_B_Debordement(): number { + return this.prms.LargeurBerge.v; } /** * Calcul de dérivée de la largeur au miroir par rapport au tirant d'eau. * @return dB */ - abstract Calc_dB(); + abstract Calc_dB(): number; /** * Calcul de dérivée de la largeur au miroir par rapport au tirant d'eau en cas de débordement * @return la dérivée de la largeur au miroir par rapport au tirant d'eau en cas de débordement */ - Calc_dB_Debordement() { + Calc_dB_Debordement(): number { return 0; } @@ -354,34 +454,32 @@ export abstract class acSection extends Debug { * Calcul de la perte de charge par la formule de Manning-Strickler. * @return La perte de charge */ - Calc_J() { - if (this.Calc('R') != 0) { - return Math.pow(this.Calc('V') / this.oP.v.Ks, 2) / Math.pow(this.Calc('R'), 4 / 3); - } - else { - return Infinity; - } + Calc_J(): number { + let R = this.Calc("R"); + if (R != 0) + return Math.pow(this.Calc("V") / this.prms.Ks.v, 2) / Math.pow(R, 4 / 3); + + return Infinity; } /** * Calcul du nombre de Froude. * @return Le nombre de Froude */ - Calc_Fr() { - if (this.Calc('S') != 0) { - return this.oP.v.Q / this.Calc('S') * Math.sqrt(this.Calc('B') / this.Calc('S') / cParamsCanal.G); - } - else { - return Infinity; - } + Calc_Fr(): number { + let S = this.Calc("S"); + if (S != 0) + return this.prms.Q.v / S * Math.sqrt(this.Calc("B") / S / cParamsCanal.G); + + return Infinity; } /** * Calcul de dy/dx */ - Calc_dYdX(Y) { - // L'appel à Calc('J') avec Y en paramètre réinitialise toutes les données dépendantes de la ligne d'eau - return - (this.oP.v.If - this.Calc('J', Y) / (1 - Math.pow(this.Calc('Fr', Y), 2))); + Calc_dYdX(Y): number { + // L'appel à Calc("J') avec Y en paramètre réinitialise toutes les données dépendantes de la ligne d'eau + return - (this.prms.If.v - this.Calc("J", Y) / (1 - Math.pow(this.Calc("Fr", Y), 2))); } XOR(a, b) { @@ -392,31 +490,30 @@ export abstract class acSection extends Debug { * Calcul du point suivant de la courbe de remous par la méthode Euler explicite. * @return Tirant d'eau */ - Calc_Y_Euler(Y) { - // L'appel à Calc('J') avec Y en paramètre réinitialise toutes les données dépendantes de la ligne d'eau - var Y2 = Y + this.oP.v.Dx * this.Calc_dYdX(Y); - if (this.XOR(this.oP.v.Dx > 0, !(Y2 < this.HautCritique))) { - return false; - } else { - return Y2; - } + Calc_Y_Euler(Y): number { + // L'appel à Calc("J') avec Y en paramètre réinitialise toutes les données dépendantes de la ligne d'eau + var Y2 = Y + this.prms.Dx.v * this.Calc_dYdX(Y); + if (this.XOR(this.prms.Dx.v > 0, !(Y2 < this.HautCritique))) + return undefined; + + return Y2; } /** * Calcul du point suivant de la courbe de remous par la méthode RK4. * @return Tirant d'eau */ - Calc_Y_RK4(Y) { - // L'appel à Calc('J') avec Y en paramètre réinitialise toutes les données dépendantes de la ligne d'eau - var Dx = this.oP.v.Dx; + Calc_Y_RK4(Y): number { + // L'appel à Calc("J') avec Y en paramètre réinitialise toutes les données dépendantes de la ligne d'eau + var Dx = this.prms.Dx.v; var k1 = this.Calc_dYdX(Y); - if (this.XOR(Dx > 0, !(Y + Dx / 2 * k1 < this.HautCritique))) { return false; } + if (this.XOR(Dx > 0, !(Y + Dx / 2 * k1 < this.HautCritique))) { return undefined; } var k2 = this.Calc_dYdX(Y + Dx / 2 * k1); - if (this.XOR(Dx > 0, !(Y + Dx / 2 * k2 < this.HautCritique))) { return false; } + if (this.XOR(Dx > 0, !(Y + Dx / 2 * k2 < this.HautCritique))) { return undefined; } var k3 = this.Calc_dYdX(Y + Dx / 2 * k2); - if (this.XOR(Dx > 0, !(Y + Dx / 2 * k3 < this.HautCritique))) { return false; } + if (this.XOR(Dx > 0, !(Y + Dx / 2 * k3 < this.HautCritique))) { return undefined; } var k4 = this.Calc_dYdX(Y + Dx * k3); - if (this.XOR(Dx > 0, !(Y + Dx / 6 * (k1 + 2 * (k2 + k3) + k4) < this.HautCritique))) { return false; } + if (this.XOR(Dx > 0, !(Y + Dx / 6 * (k1 + 2 * (k2 + k3) + k4) < this.HautCritique))) { return undefined; } return Y + Dx / 6 * (k1 + 2 * (k2 + k3) + k4); } // /** @@ -424,7 +521,7 @@ export abstract class acSection extends Debug { // * @return Tirant d'eau // */ // Calc_Y(rY) { - // var funcCalcY = 'Calc_Y_' + this.oP.Resolution; + // var funcCalcY = 'Calc_Y_' + this.prms.Resolution; // var methods = Object.getOwnPropertyNames(this).filter(function (p) { // return typeof this[p] === 'function'; // }); @@ -442,31 +539,30 @@ export abstract class acSection extends Debug { * Calcul de la vitesse moyenne. * @return Vitesse moyenne */ - Calc_V() { - if (this.Calc('S') != 0) { - return this.oP.v.Q / this.Calc('S'); - } - else { - return Infinity; - } + Calc_V(): number { + let S = this.Calc("S"); + if (S != 0) + return this.prms.Q.v / S; + + return Infinity; } /** * Calcul de la charge spécifique. * @return Charge spécifique */ - Calc_Hs() { - return this.v.Y + Math.pow(this.Calc('V'), 2) / (2 * cParamsCanal.G); + Calc_Hs(): number { + return this.prms.Y.v + Math.pow(this.Calc("V"), 2) / (2 * cParamsCanal.G); } /** * Calcul de la charge spécifique critique. * @return Charge spécifique critique */ - Calc_Hsc() { + Calc_Hsc(): number { this.Swap(true); // On mémorise les données hydrauliques en cours // On calcule la charge avec la hauteur critique - var Hsc = this.Calc('Hs', this.CalcGeo('Yc')); + var Hsc = this.Calc("Hs", this.CalcGeo("Yc")); // On restitue les données initiales this.Swap(false); return Hsc; @@ -476,14 +572,14 @@ export abstract class acSection extends Debug { * Calcul du tirant d'eau critique. * @return tirant d'eau critique */ - Calc_Yc() { + Calc_Yc(): number { //this.debug("in calcYc"); - var hautCritique = new cHautCritique(this, this.oP); - /*if(!this.HautCritique == hautCritique.Newton(this.oP.YB) || !hautCritique.HasConverged()) { + var hautCritique = new cHautCritique(this, this.DBG); + /*if(!this.HautCritique == hautCritique.Newton(this.prms.YB) || !hautCritique.HasConverged()) { //traduction de code de langue: //this.oLog.Add(_T('hydraulic:h_critique')+' : '+_T('hydraulic:newton_non_convergence'),true); }*/ - this.HautCritique = hautCritique.Newton(this.oP.v.YB); + this.HautCritique = hautCritique.Newton(this.prms.YB.v); return this.HautCritique; } @@ -491,16 +587,16 @@ export abstract class acSection extends Debug { * Calcul du tirant d'eau normal. * @return tirant d'eau normal */ - Calc_Yn() { + Calc_Yn(): number { this.debug("in calc_Yn"); - if (this.oP.v.If <= 0) { + if (this.prms.If.v <= 0) { this.HautNormale = false; //this.oLog.Add(_T('hydraulic:h_normale_pente_neg_nul'),true); } else { - var oHautNormale = new cHautNormale(this, this.oP); - //if(!this.HautNormale == oHautNormale.Newton(this.CalcGeo('Yc')) || !oHautNormale.HasConverged()) { + var oHautNormale = new cHautNormale(this, this.DBG); + //if(!this.HautNormale == oHautNormale.Newton(this.CalcGeo("Yc')) || !oHautNormale.HasConverged()) { //this.oLog.Add(_T('hydraulic:h_normale').' : '._T('hydraulic:newton_non_convergence'),true); - this.HautNormale = oHautNormale.Newton(this.CalcGeo('Yc')); + this.HautNormale = oHautNormale.Newton(this.CalcGeo("Yc")); this.debug("hautnormale" + this.HautNormale); // } } @@ -511,45 +607,41 @@ export abstract class acSection extends Debug { * Calcul du tirant d'eau fluvial. * @return tirant d'eau fluvial */ - Calc_Yf() { - if (this.v.Y > this.CalcGeo('Yc')) { - return this.v.Y; - } - else { - var oHautCorrespondante = new cHautCorrespondante(this, this.oP, this.DBG); - return oHautCorrespondante.Newton(this.Calc('Yc') * 2); - } + Calc_Yf(): number { + if (this.prms.Y.v > this.CalcGeo("Yc")) + return this.prms.Y.v; + + var oHautCorrespondante = new cHautCorrespondante(this, this.DBG); + return oHautCorrespondante.Newton(this.Calc("Yc") * 2); } /** * Calcul du tirant d'eau torrentiel. * @return tirant d'eau torrentiel */ - Calc_Yt() { - if (this.v.Y < this.CalcGeo('Yc')) { - return this.v.Y; - } - else { - var oHautCorrespondante = new cHautCorrespondante(this, this.oP, this.DBG); - return oHautCorrespondante.Newton(this.CalcGeo('Yc') / 2); - } + Calc_Yt(): number { + if (this.prms.Y.v < this.CalcGeo("Yc")) + return this.prms.Y.v; + + var oHautCorrespondante = new cHautCorrespondante(this, this.DBG); + return oHautCorrespondante.Newton(this.CalcGeo("Yc") / 2); } /** * Calcul du tirant d'eau conjugué. * @return tirant d'eau conjugué */ - Calc_Yco() { + Calc_Yco(): number { this.Swap(true); - var oHautConj = new cHautConjuguee(this, this.oP); + var oHautConj = new cHautConjuguee(this, this.DBG); // Choisir une valeur initiale du bon côté de la courbe - if (this.Calc('Fr') < 1) { + if (this.Calc("Fr") < 1) { // Ecoulement fluvial, on cherche la conjuguée à partir du tirant d'eau torrentiel - var Y0 = this.Calc('Yt'); + var Y0 = this.Calc("Yt"); } else { // Ecoulement torrentiel, on cherche la conjuguée à partir du tirant d'eau fluvial - Y0 = this.Calc('Yf'); + Y0 = this.Calc("Yf"); } let Yco = oHautConj.Newton(Y0); this.Swap(false); @@ -560,8 +652,8 @@ export abstract class acSection extends Debug { * Calcul de la contrainte de cisaillement. * @return contrainte de cisaillement */ - Calc_Tau0() { - return 1000 * cParamsCanal.G * this.Calc('R') * this.Calc('J'); + Calc_Tau0(): number { + return 1000 * cParamsCanal.G * this.Calc("R") * this.Calc("J"); } /** @@ -570,10 +662,10 @@ export abstract class acSection extends Debug { * @return S x Yg */ // Calc_SYg(rY) { - // return Math.pow(rY, 2) * this.v.LargeurBerge / 2; + // return Math.pow(rY, 2) * this.prms.LargeurBerge / 2; // } - Calc_SYg() { - return Math.pow(this.v.Y, 2) * this.v.LargeurBerge / 2; + Calc_SYg(): number { + return Math.pow(this.prms.Y.v, 2) * this.prms.LargeurBerge.v / 2; } /** @@ -582,25 +674,25 @@ export abstract class acSection extends Debug { * @return S x Yg */ // Calc_dSYg(rY) { - // return rY * this.v.LargeurBerge; + // return rY * this.prms.LargeurBerge; // } - Calc_dSYg() { - return this.v.Y * this.v.LargeurBerge; + Calc_dSYg(): number { + return this.prms.Y.v * this.prms.LargeurBerge.v; } /** * Calcul de l'impulsion hydraulique. * @return Impulsion hydraulique */ - Calc_Imp() { - return 1000 * (this.oP.v.Q * this.Calc('V') + cParamsCanal.G * this.Calc('SYg')); + Calc_Imp(): number { + return 1000 * (this.prms.Q.v * this.Calc("V") + cParamsCanal.G * this.Calc("SYg")); } /** * Calcul de l'angle Alpha entre la surface libre et le fond pour les sections circulaires. * @return Angle Alpha pour une section circulaire, 0 sinon. */ - Calc_Alpha() { + Calc_Alpha(): number { return 0; } @@ -608,7 +700,7 @@ export abstract class acSection extends Debug { * Calcul de la dérivée de l'angle Alpha entre la surface libre et le fond pour les sections circulaires. * @return Dérivée de l'angle Alpha pour une section circulaire, 0 sinon. */ - Calc_dAlpha() { + Calc_dAlpha(): number { return 0; } @@ -617,12 +709,12 @@ export abstract class acSection extends Debug { * @return tableau de couples de coordonnées (x,y) */ /*DessinCoordonnees() { - var Pas = this.oP.YB / this.nbDessinPoints; + var Pas = this.prms.YB / this.nbDessinPoints; var Points = new Array(); this.Swap(true); // On mémorise les données hydrauliques en cours - for(var Y=0; Y<this.oP.YB+Pas/2; Y=Y+Pas) { + for(var Y=0; Y<this.prms.YB+Pas/2; Y=Y+Pas) { //Y boolean or what ? - Points['x'][] = this.Calc('B',Y)/2; + Points['x'][] = this.Calc("B',Y)/2; Points['y'][] = Y; } // On restitue les données initiales