diff --git a/package.json b/package.json index df3591aa67d470bf8f121cb3a33da0fab5d7ca51..66b089a3aa528f80e74c09291ea371eb42ff7a60 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 0000000000000000000000000000000000000000..2dbed059103434303b1a20ace4b380c3d3705d15 --- /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 cb9e20eb161e535ef2df116d24937c7cb4dfad5d..01adbca1bb1db0bbc4d0d7a54d20702ba65ed7dd 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 0000000000000000000000000000000000000000..0534f39bdaeb40533e6e3403bd2ec4ce3442db6d --- /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 99f12a169103333a50d4d0cf1e961ad9f841a846..6dabd736f0743fb8f242ccd47601dab36d7c56f7 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