Commit 5378ee83 authored by Mathias Chouet's avatar Mathias Chouet 🍝
Browse files

Add module YAXB

parent 3f52eaab
import { ConduiteDistrib } from "../src/cond_distri";
import { ConduiteDistribParams } from "../src/cond_distri_params";
import { checkResult } from "./test_func";
describe("Class ConduiteDistrib: ", () => {
// beforeEach(() => {
// });
// beforeAll(() => {
// });
describe("Calc(): ", () => {
it("Q should be 9.393", () => {
const 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
);
const nub = new ConduiteDistrib(prms);
checkResult(nub.Calc("Q", 0), 9.393);
});
});
describe("Calc(): ", () => {
it("Q should be 152.992", () => {
const 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
);
const 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;
checkResult(nub.Calc("Q", 0), 152.992);
});
});
describe("Calc(): ", () => {
it("D should be 2.12847", () => {
const 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
);
const nub = new ConduiteDistrib(prms);
const r = nub.Calc("D", 0);
checkResult(r, 2.12847);
});
});
describe("Calc(): ", () => {
it("J should be 0.00814", () => {
const 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
);
const nub = new ConduiteDistrib(prms);
checkResult(nub.Calc("J", 0), 0.00814);
});
});
describe("Calc(): ", () => {
it("Lg should be 737.021", () => {
const 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
);
const nub = new ConduiteDistrib(prms);
checkResult(nub.Calc("Lg", 0), 737.021);
});
});
describe("Calc(): ", () => {
it("Nu should be 0.00295", () => {
const 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
);
const nub = new ConduiteDistrib(prms);
checkResult(nub.Calc("Nu", 0), 0.00295);
});
});
});
import { ConduiteDistrib } from "../src/cond_distri"; import { YAXB } from "../src/axb";
import { ConduiteDistribParams } from "../src/cond_distri_params"; import { YAXBParams } from "../src/axb_params";
import { checkResult } from "./test_func"; import { MessageCode } from "../src/index";
describe("Class ConduiteDistrib: ", () => { describe("Class YAXB: ", () => {
// beforeEach(() => {
// });
// beforeAll(() => {
// });
describe("Calc(): ", () => { it("Y should be 10", () => {
it("Q should be 9.393", () => { const nub = new YAXB(new YAXBParams(666, 2, 3, 4));
const prms = new ConduiteDistribParams(undefined, // débit Q nub.calculatedParam = nub.prms.Y;
1.2, // diamètre D nub.CalcSerie();
0.6, // perte de charge J expect(nub.result.vCalc).toBe(10);
100, // Longueur de la conduite Lg
1e-6, // Viscosité dynamique Nu
);
const nub = new ConduiteDistrib(prms);
checkResult(nub.Calc("Q", 0), 9.393);
});
}); });
describe("Calc(): ", () => { it("A should be 2", () => {
it("Q should be 152.992", () => { const nub = new YAXB(new YAXBParams(10, 666, 3, 4));
const prms = new ConduiteDistribParams(undefined, // débit Q nub.calculatedParam = nub.prms.A;
2, // diamètre D nub.CalcSerie();
0.7, // perte de charge J expect(nub.result.vCalc).toBe(2);
10, // Longueur de la conduite Lg
1e-6, // Viscosité dynamique Nu
);
const 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;
checkResult(nub.Calc("Q", 0), 152.992);
}); });
});
describe("Calc(): ", () => {
it("D should be 2.12847", () => {
const 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
);
const nub = new ConduiteDistrib(prms);
const r = nub.Calc("D", 0); it("X should be 3", () => {
checkResult(r, 2.12847); const nub = new YAXB(new YAXBParams(10, 2, 666, 4));
nub.calculatedParam = nub.prms.X;
nub.CalcSerie();
expect(nub.result.vCalc).toBe(3);
}); });
});
describe("Calc(): ", () => {
it("J should be 0.00814", () => {
const 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
);
const nub = new ConduiteDistrib(prms); it("B should be 4", () => {
const nub = new YAXB(new YAXBParams(10, 2, 3, 666));
checkResult(nub.Calc("J", 0), 0.00814); nub.calculatedParam = nub.prms.B;
}); nub.CalcSerie();
expect(nub.result.vCalc).toBe(4);
}); });
describe("Calc(): ", () => { it("calc A with X = 0 should trigger error", () => {
it("Lg should be 737.021", () => { const nub = new YAXB(new YAXBParams(10, 666, 0, 4));
const prms = new ConduiteDistribParams(3, // débit Q nub.calculatedParam = nub.prms.A;
1.2, // diamètre D nub.CalcSerie();
0.6, // perte de charge J expect(nub.result.ok).toBe(false);
undefined, // Longueur de la conduite Lg expect(nub.result.resultElement.log.messages.length).toBe(1);
1e-6, // Viscosité dynamique Nu expect(nub.result.resultElement.log.messages[0].code).toBe(MessageCode.ERROR_DIVISION_BY_ZERO);
);
const nub = new ConduiteDistrib(prms);
checkResult(nub.Calc("Lg", 0), 737.021);
});
}); });
describe("Calc(): ", () => { it("calc X with A = 0 should trigger error", () => {
it("Nu should be 0.00295", () => { const nub = new YAXB(new YAXBParams(10, 0, 666, 4));
const prms = new ConduiteDistribParams(3, // débit Q nub.calculatedParam = nub.prms.X;
1.2, // diamètre D nub.CalcSerie();
0.6, // perte de charge J expect(nub.result.ok).toBe(false);
100, // Longueur de la conduite Lg expect(nub.result.resultElement.log.messages.length).toBe(1);
undefined, // Viscosité dynamique Nu expect(nub.result.resultElement.log.messages[0].code).toBe(MessageCode.ERROR_DIVISION_BY_ZERO);
);
const nub = new ConduiteDistrib(prms);
checkResult(nub.Calc("Nu", 0), 0.00295);
});
}); });
}); });
import { YAXBParams } from "./axb_params";
import { CalculatorType } from "./compute-node";
import { Nub } from "./nub";
import { ParamCalculability } from "./param/param-definition";
import { Message, MessageCode } from "./util/message";
import { Result } from "./util/result";
/**
* Y = A.X + B
*/
export class YAXB extends Nub {
constructor(prms: YAXBParams, dbg: boolean = false) {
super(prms, dbg);
this._calcType = CalculatorType.YAXB;
this._defaultCalculatedParam = prms.Y;
this.resetDefaultCalculatedParam();
}
/** paramètres castés au bon type */
get prms(): YAXBParams {
return this._prms as YAXBParams;
}
public Equation(sVarCalc: string): Result {
let v: number;
switch (sVarCalc) {
case "Y":
v = this.prms.A.v * this.prms.X.v + this.prms.B.v;
break;
case "A":
if (this.prms.X.v === 0) {
const m = new Message(MessageCode.ERROR_DIVISION_BY_ZERO);
m.extraVar.symbol = "X";
return new Result(m);
}
v = (this.prms.Y.v - this.prms.B.v) / this.prms.X.v;
break;
case "X":
if (this.prms.A.v === 0) {
const m = new Message(MessageCode.ERROR_DIVISION_BY_ZERO);
m.extraVar.symbol = "A";
return new Result(m);
}
v = (this.prms.Y.v - this.prms.B.v) / this.prms.A.v;
break;
case "B":
v = this.prms.Y.v - (this.prms.A.v * this.prms.X.v);
break;
default:
throw new Error("AXB.Equation() : invalid variable name " + sVarCalc);
}
return new Result(v, this);
}
/** paramétrage de la calculabilité des paramètres */
protected setParametersCalculability() {
this.prms.Y.calculability = ParamCalculability.EQUATION;
this.prms.A.calculability = ParamCalculability.EQUATION;
this.prms.X.calculability = ParamCalculability.EQUATION;
this.prms.B.calculability = ParamCalculability.EQUATION;
}
}
import { ParamDefinition, ParamFamily } from "./param/param-definition";
import { ParamDomainValue } from "./param/param-domain";
import { ParamsEquation } from "./param/params-equation";
/**
* Y = A.X + B
*/
export class YAXBParams extends ParamsEquation {
/** Y */
private _Y: ParamDefinition;
/** A */
private _A: ParamDefinition;
/** X */
private _X: ParamDefinition;
/** B */
private _B: ParamDefinition;
constructor(rY: number, rA: number, rX: number, rB: number) {
super();
this._Y = new ParamDefinition(this, "Y", ParamDomainValue.ANY, undefined, rY, ParamFamily.ANY);
this._A = new ParamDefinition(this, "A", ParamDomainValue.ANY, undefined, rA, ParamFamily.ANY);
this._X = new ParamDefinition(this, "X", ParamDomainValue.ANY, undefined, rX, ParamFamily.ANY);
this._B = new ParamDefinition(this, "B", ParamDomainValue.ANY, undefined, rB, ParamFamily.ANY);
this.addParamDefinition(this._Y);
this.addParamDefinition(this._A);
this.addParamDefinition(this._X);
this.addParamDefinition(this._B);
}
get Y() {
return this._Y;
}
get A() {
return this._A;
}
get X() {
return this._X;
}
get B() {
return this._B;
}
}
...@@ -30,7 +30,8 @@ export enum CalculatorType { ...@@ -30,7 +30,8 @@ export enum CalculatorType {
Grille, // Pertes de charge grille de prise d'eau Grille, // Pertes de charge grille de prise d'eau
Pente, Pente,
Bief, Bief,
Solveur // Nub qui résout des chaînes de Nubs par dichotomie Solveur, // Nub qui résout des chaînes de Nubs par dichotomie
YAXB // Y = A.X + B
} }
/** /**
......
...@@ -30,6 +30,7 @@ export enum ParamCalculability { ...@@ -30,6 +30,7 @@ export enum ParamCalculability {
* Parameter family: defines linkability with other parameters/results * Parameter family: defines linkability with other parameters/results
*/ */
export enum ParamFamily { export enum ParamFamily {
ANY, // peut être lié à n'importe quel paramètre
LENGTHS, // longueur LENGTHS, // longueur
WIDTHS, // largeur WIDTHS, // largeur
SLOPES, // pente SLOPES, // pente
......
...@@ -8,6 +8,8 @@ import { Props } from "./props"; ...@@ -8,6 +8,8 @@ import { Props } from "./props";
import { config } from "./config"; import { config } from "./config";
// Calculettes // Calculettes
import { YAXB } from "./axb";
import { YAXBParams } from "./axb_params";
import { ConduiteDistrib } from "./cond_distri"; import { ConduiteDistrib } from "./cond_distri";
import { LechaptCalmon } from "./lechaptcalmon"; import { LechaptCalmon } from "./lechaptcalmon";
import { MacroRugo } from "./macrorugo/macrorugo"; import { MacroRugo } from "./macrorugo/macrorugo";
...@@ -20,6 +22,8 @@ import { PabPuissance } from "./pab/pab_puissance"; ...@@ -20,6 +22,8 @@ import { PabPuissance } from "./pab/pab_puissance";
import { RegimeUniforme } from "./regime_uniforme"; import { RegimeUniforme } from "./regime_uniforme";
import { CourbeRemous } from "./remous/remous"; import { CourbeRemous } from "./remous/remous";
import { SectionParametree } from "./section/section_parametree"; import { SectionParametree } from "./section/section_parametree";
import { Solveur } from "./solveur/solveur";
import { SolveurParams } from "./solveur/solveur_params";
// Classes relatives aux sections // Classes relatives aux sections
import { BiefParams, BiefRegime } from "./remous/bief_params"; import { BiefParams, BiefRegime } from "./remous/bief_params";
...@@ -66,8 +70,6 @@ import { JetParams } from "./devalaison/jet_params"; ...@@ -66,8 +70,6 @@ import { JetParams } from "./devalaison/jet_params";
import { Pente } from "./pente"; import { Pente } from "./pente";
import { PenteParams } from "./pente_params"; import { PenteParams } from "./pente_params";
import { Bief } from "./remous/bief"; import { Bief } from "./remous/bief";
import { Solveur } from "./solveur/solveur";
import { SolveurParams } from "./solveur/solveur_params";
export class Session { export class Session {
...@@ -584,6 +586,18 @@ export class Session { ...@@ -584,6 +586,18 @@ export class Session {
); );
break; break;
case CalculatorType.YAXB:
nub = new YAXB(
new YAXBParams(
10, // Y
2, // A
3, // X
4 // B
),
dbg
);
break;
default: default:
throw new Error( throw new Error(
`Session.createNub() : type de module '${CalculatorType[calcType]}' non pris en charge` `Session.createNub() : type de module '${CalculatorType[calcType]}' non pris en charge`
......
...@@ -52,6 +52,11 @@ export enum MessageCode { ...@@ -52,6 +52,11 @@ export enum MessageCode {
*/ */
ERROR_DICHO_FUNCTION_VARIATION, ERROR_DICHO_FUNCTION_VARIATION,
/**
* impossible de résoudre l'équation en raison d'une division par zéro
*/
ERROR_DIVISION_BY_ZERO,
/** /**
* la cote amont Z1 est plus basse que la cote aval Z2 * la cote amont Z1 est plus basse que la cote aval Z2
*/ */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment