From a06518275598601ca2f3e4c63356868e2f223db0 Mon Sep 17 00:00:00 2001 From: "francois.grand" <francois.grand@irstea.fr> Date: Fri, 19 May 2017 12:03:03 +0200 Subject: [PATCH] =?UTF-8?q?Impl=C3=A9mentation=20conduite=20distributrice?= =?UTF-8?q?=20+=20tests=20(issue=20#2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +- spec/cond_distri.spec.ts | 103 +++++++++++++++++++++++++++++++++++++++ src/base.ts | 18 +++---- src/cond_distri.ts | 71 +++++++++++++++++++++++++++ src/dichotomie.ts | 2 +- 5 files changed, 186 insertions(+), 11 deletions(-) create mode 100644 spec/cond_distri.spec.ts create mode 100644 src/cond_distri.ts diff --git a/package.json b/package.json index df3591aa..66b089a3 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,9 @@ }, "scripts": { "build": "./node_modules/typescript/bin/tsc --p src/tsconfig.app.json", + "buildtest": "./node_modules/typescript/bin/tsc --p spec/tsconfig.spec.json", "test": "./node_modules/typescript/bin/tsc --p spec/tsconfig.spec.json && ./node_modules/karma/bin/karma start", "lint": "./node_modules/tslint/bin/tslint", "viz": "tsviz -recursive src/ jalhyd_class_diagram.png" } -} +} \ No newline at end of file diff --git a/spec/cond_distri.spec.ts b/spec/cond_distri.spec.ts new file mode 100644 index 00000000..2dbed059 --- /dev/null +++ b/spec/cond_distri.spec.ts @@ -0,0 +1,103 @@ +/// <reference path="../node_modules/@types/jasmine/index.d.ts" /> + +import { Result } from "../src/base"; +import { ConduiteDistrib } from "../src/cond_distri"; + +describe('Class ConduiteDistrib: ', () => { + // beforeEach(() => { + // nub.sVarsEq = ["C"]; + // res.vCalc = 3; + // }); + // beforeAll(() => { + // }); + + 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 res = new Result; + res.vCalc = 9.393428919333346; + + expect(nub.Calc("q").vCalc).toEqual(res.vCalc); + }); + }); + + 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 res = new Result; + res.vCalc = 152.99207150346; + + expect(nub.Calc("q").vCalc).toEqual(res.vCalc); + }); + }); + + describe('Calc(): ', () => { + it('D should be 2.128465006', () => { + let nub = new ConduiteDistrib(); + nub.v.q = 3; + nub.v.j = 0.7; + nub.v.lg = 10; + nub.v.nu = 1e-6; + + let res = new Result; + res.vCalc = 2.1284650063949666; + + expect(nub.Calc("d").vCalc).toEqual(res.vCalc); + }); + }); + + describe('Calc(): ', () => { + it('J should be 0.00814087671', () => { + let nub = new ConduiteDistrib(); + nub.v.q = 3; + nub.v.d = 1.2; + nub.v.lg = 10; + nub.v.nu = 1e-6; + + let res = new Result; + res.vCalc = 0.008140876712328136; + + expect(nub.Calc("j").vCalc).toEqual(res.vCalc); + }); + }); + + describe('Calc(): ', () => { + it('Lg should be 0.008140876712328136', () => { + let nub = new ConduiteDistrib(); + nub.v.q = 3; + nub.v.d = 1.2; + nub.v.j = 0.6; + nub.v.nu = 1e-6; + + let res = new Result; + res.vCalc = 737.0213567924325; + + expect(nub.Calc("lg").vCalc).toEqual(res.vCalc); + }); + }); + + describe('Calc(): ', () => { + it('Nu should be 0.00295066762', () => { + let nub = new ConduiteDistrib(); + nub.v.q = 3; + nub.v.d = 1.2; + nub.v.j = 0.6; + nub.v.lg = 100; + + let res = new Result; + res.vCalc = 0.0029506676187219757; + + expect(nub.Calc("nu").vCalc).toEqual(res.vCalc); + }); + }); +}); diff --git a/src/base.ts b/src/base.ts index cb9e20eb..01adbca1 100644 --- a/src/base.ts +++ b/src/base.ts @@ -7,7 +7,7 @@ export class Result { /** Valeur calculée */ public vCalc: number; /** Variables intermédiaires, flags d'erreur */ - public extraVar: {}; + public extraVar: {}; } /** @@ -25,7 +25,7 @@ export class Serie { export interface IParametres { - [key: string]: number; + [key: string]: number; // map : array of numbers with string keys } @@ -38,14 +38,14 @@ export abstract class Debug { /** * @param DBG Flag de débuggage */ - constructor(private DBG: boolean) {} + constructor(private DBG: boolean) { } /** * Affiche un message dans la console si le flag this.DBG est à true * @param s Message à afficher dans la console */ protected debug(s: any) { - if(this.DBG) console.log(s); + if (this.DBG) console.log(s); } } @@ -55,7 +55,7 @@ export abstract class Debug { */ export abstract class Nub extends Debug { /// Nom des variables calculées par la méthode Equation - private _varsEq: string[]; + private _varsEq: string[] = []; public v: IParametres; @@ -65,7 +65,7 @@ export abstract class Nub extends Debug { } - /** + /** * Formule utilisée pour le calcul analytique (solution directe ou méthode de résolution spécifique) */ abstract Equation(sVarCalc: string): Result; @@ -75,10 +75,10 @@ export abstract class Nub extends Debug { * Calcul d'une équation quelque soit l'inconnue à calculer */ Calc(sVarCalc: string): Result { - for(let sVarEq of this._varsEq) { - if(sVarCalc == sVarEq) { + for (let sVarEq of this._varsEq) { + if (sVarCalc == sVarEq) { return this.Equation(sVarCalc); - } + } } return this.Solve(sVarCalc); } diff --git a/src/cond_distri.ts b/src/cond_distri.ts new file mode 100644 index 00000000..0534f39b --- /dev/null +++ b/src/cond_distri.ts @@ -0,0 +1,71 @@ +import { Nub, Result, IParametres } from "./base"; + + +// export interface IParamConduiteDistrib extends IParametres { +export class ParamConduiteDistrib implements IParametres { + [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 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"); + } + + Equation(sVarCalc: string): Result { + let res: Result = new Result(); + + 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": + res.vCalc = 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); + break; + + case "d": + res.vCalc = 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); + break; + + case "q": + res.vCalc = 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) + break; + + case "lg": + res.vCalc = 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)); + break; + + case "nu": + res.vCalc = 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); + break; + } + + + return res; + } +} \ No newline at end of file diff --git a/src/dichotomie.ts b/src/dichotomie.ts index 99f12a16..6dabd736 100644 --- a/src/dichotomie.ts +++ b/src/dichotomie.ts @@ -154,6 +154,6 @@ export class Dichotomie extends Debug { } } res.vCalc = v - return ; + return res; } } \ No newline at end of file -- GitLab