An error occurred while loading the file. Please try again.
-
Mathias Chouet authored3f44ff89
import { ConduiteDistrib, ConduiteDistribParams } from "../../src/cond_distri";
import { Nub, ParallelStructure, ParamDefinition, ParamValueMode, SectionParametree, Session } from "../../src/index";
import { MacroRugo } from "../../src/macrorugo/macrorugo";
import { Cloisons } from "../../src/pab/cloisons";
import { CloisonsParams } from "../../src/pab/cloisons_params";
import { PabChute, PabChuteParams } from "../../src/pab/pab_chute";
import { RegimeUniforme } from "../../src/regime_uniforme";
import { MethodeResolution } from "../../src/remous/methode-resolution";
import { CourbeRemous, CourbeRemousParams } from "../../src/remous/remous";
import { cSnCirc, ParamsSectionCirc } from "../../src/section/section_circulaire";
import { cSnTrapez, ParamsSectionTrapez } from "../../src/section/section_trapez";
import { Dever, DeverParams } from "../../src/structure/dever";
import { CreateStructure } from "../../src/structure/factory_structure";
import { RectangularStructure, RectangularStructureParams } from "../../src/structure/rectangular_structure";
import { LoiDebit } from "../../src/structure/structure_props";
import {
StructureWeirSubmergedLarinier,
} from "../../src/structure/structure_weir_submerged_larinier";
import { sessionSpaghetti } from "./serialisation.session.spaghetti";
/**
* IMPORTANT !
* Décommenter temporairement la ligne suivante (import { } from "./mock_jasmine")
* Pour exécuter ce code dans le débugger.
* Faire de même avec le fichier test_func.ts
*/
// import { describe, expect, it, xdescribe, xit } from "../mock_jasmine";
function createEnv() {
// create complex session
const dever: Dever = new Dever(
new DeverParams(
0, // rQ Débit total (m3/s)
102, // rZ1 Cote de l'eau amont (m)
2, // rBR Largeur du cours d'eau amont (m)
100 // rZR Cote du lit du cours d'eau amont (m)
),
false // debug
);
dever.addChild(CreateStructure(LoiDebit.TriangularTruncWeirFree, dever, false));
const cloisons: Cloisons = new Cloisons(
new CloisonsParams(
0, // Débit total (m3/s)
102, // Cote de l'eau amont (m)
10, // Longueur des bassins (m)
1, // Largeur des bassins (m)
1, // Profondeur moyenne (m)
0.5 // Hauteur de chute (m)
),
false // debug
);
const fente: StructureWeirSubmergedLarinier = new StructureWeirSubmergedLarinier(
new RectangularStructureParams(
0,
101,
102,
101.5,
0.2,
0.65
)
);
cloisons.addChild(fente);
const prmsCD = 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
);
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
const conduite = new ConduiteDistrib(prmsCD);
const prmsST = new ParamsSectionTrapez(2.5, // largeur de fond
0.56, // fruit
undefined, // tirant d'eau
40, // Ks=Strickler
2, // Q=Débit
0.001, // If=pente du fond
1, // YB= hauteur de berge
);
const sect = new cSnTrapez(prmsST);
const prem = new CourbeRemousParams(0.15, // Yamont = tirant amont
0.803, // Yaval = tirant aval
5, // Long= Longueur du bief
5, // Dx=Pas d'espace
);
const rem = new CourbeRemous(sect, prem, MethodeResolution.Trapezes);
const paramSection = new ParamsSectionCirc(2, // diamètre
0.8, // tirant d'eau
40, // Ks=Strickler
10, // Q=Débit
0.001, // If=pente du fond
1, // YB= hauteur de berge
);
const section = new cSnCirc(paramSection);
const sp = new SectionParametree(section);
Session.getInstance().clear();
Session.getInstance().registerNub(dever);
Session.getInstance().registerNub(cloisons);
Session.getInstance().registerNub(conduite);
Session.getInstance().registerNub(rem);
Session.getInstance().registerNub(sp);
}
function checkLink(param: ParamDefinition, nub: Nub, symbol: string) {
expect(param.valueMode).toBe(ParamValueMode.LINK);
expect(param.referencedValue).toBeDefined();
if (param.referencedValue) {
expect(param.referencedValue.nub.uid).toBe(nub.uid);
expect(param.referencedValue.symbol).toBe(symbol);
}
}
describe("serialising / deserialising session - ", () => {
it ("serialized file should contain 5 Nubs", () => {
createEnv();
const session = Session.getInstance().serialise();
const js = JSON.parse(session);
expect(Object.keys(js)).toContain("session");
expect(js.session.length).toBe(5);
});
it ("reloading serialized file should give 5 Nubs", () => {
createEnv();
const session = Session.getInstance().serialise();
Session.getInstance().clear();
expect(Session.getInstance().getNumberOfNubs()).toBe(0);
Session.getInstance().unserialise(session);
expect(Session.getInstance().getNumberOfNubs()).toBe(5);
});
it("when saving a SectionParametree, the edited values should be present in the file", () => {
// d
const paramSection = new ParamsSectionCirc(
2, // diamètre
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
0.8, // tirant d'eau
40, // Ks=Strickler
10, // Q=Débit
0.001, // If=pente du fond
1, // YB= hauteur de berge
);
const section = new cSnCirc(paramSection);
const sp = new SectionParametree(section);
sp.section.prms.Ks.singleValue = 42;
const serialised = sp.serialise();
expect(serialised).toContain('{"symbol":"Ks","mode":"SINGLE","value":42}');
});
it ("loaded serialized RegimeUniforme should be calculable", () => {
Session.getInstance().clear();
// tslint:disable-next-line:max-line-length
const session = `{"session":[{"uid":"YTEwZG","props":{"calcType":3,"nodeType":2},"meta":{"title":"R. uniforme"},"children":[{"uid":"NDcxN3","props":{"calcType":14,"nodeType":2},"children":[],"parameters":[{"symbol":"Pr","mode":"SINGLE","value":0.0001},{"symbol":"Ks","mode":"SINGLE","value":40},{"symbol":"Q","mode":"CALCUL"},{"symbol":"If","mode":"SINGLE","value":0.001},{"symbol":"YB","mode":"SINGLE","value":1},{"symbol":"Y","mode":"SINGLE","value":0.89},{"symbol":"LargeurBerge","mode":"SINGLE","value":2.5}]}],"parameters":[{"symbol":"Pr","mode":"SINGLE","value":0.0001}]}]}`;
Session.getInstance().unserialise(session);
expect(Session.getInstance().getNumberOfNubs()).toBe(1);
const RU = Session.getInstance().findNubByUid("YTEwZG");
expect(RU).toBeDefined();
const calculatedParam = RU.calculatedParam;
expect(calculatedParam.symbol).toBe("Q");
let nbCalc = 0;
for (const p of RU.parameterIterator) {
if (p.valueMode === ParamValueMode.CALCUL) {
nbCalc++;
}
}
expect(nbCalc).toBe(1);
RU.CalcSerie();
expect(RU.result).toBeDefined();
});
it ("loaded serialized Ouvrages should be calculable", () => {
Session.getInstance().clear();
// tslint:disable-next-line:max-line-length
const session = `{"session":[{"uid":"NGVzdz","props":{"calcType":8,"nodeType":0},"meta":{"title":"Ouvrages"},"children":[{"uid":"Z2F4dz","props":{"calcType":7,"nodeType":5,"structureType":1,"loiDebit":1},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":100},{"symbol":"W","mode":"SINGLE","value":0.5},{"symbol":"L","mode":"SINGLE","value":2}]},{"uid":"ZDR4cX","props":{"calcType":7,"nodeType":5,"structureType":1,"loiDebit":1},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":100},{"symbol":"W","mode":"SINGLE","value":0.5},{"symbol":"L","mode":"CALCUL"}]}],"parameters":[{"symbol":"Pr","mode":"SINGLE","value":0.0001},{"symbol":"Q","mode":"SINGLE","value":3.5},{"symbol":"Z1","mode":"SINGLE","value":102},{"symbol":"Z2","mode":"SINGLE","value":101.5}]}]}`;
Session.getInstance().unserialise(session);
expect(Session.getInstance().getNumberOfNubs()).toBe(1);
const OUV = Session.getInstance().findNubByUid("NGVzdz");
expect(OUV).toBeDefined();
const calculatedParam = OUV.calculatedParam;
expect(calculatedParam.symbol).toBe("L");
let nbCalc = 0;
for (const p of OUV.parameterIterator) {
if (p.valueMode === ParamValueMode.CALCUL) {
nbCalc++;
}
}
expect(nbCalc).toBe(1);
OUV.CalcSerie();
expect(OUV.result).toBeDefined();
expect(OUV.result.vCalc).toBeCloseTo(1.031);
});
it ("loaded serialized spaghetti session should have the right target for every link", () => {
Session.getInstance().clear();
// tslint:disable-next-line:max-line-length
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
Session.getInstance().unserialise(JSON.stringify(sessionSpaghetti));
expect(Session.getInstance().getNumberOfNubs()).toBe(5);
const SP = (Session.getInstance().findNubByUid("ZHh1YW") as SectionParametree);
const OU = (Session.getInstance().findNubByUid("dGx0em") as ParallelStructure);
const MR = (Session.getInstance().findNubByUid("eTgwMG") as MacroRugo);
const RU = (Session.getInstance().findNubByUid("dzA1OX") as RegimeUniforme);
const DD = (Session.getInstance().findNubByUid("cXFraW") as Dever);
// 1. check Section Paramétrée
expect(SP).toBeDefined();
checkLink(SP.section.prms.LargeurBerge, OU.structures[2], "L");
// 2. check Macro-rugo
expect(MR).toBeDefined();
checkLink(MR.prms.ZF1, OU, "Z1");
checkLink(MR.prms.Q, SP.section, "Q");
// 3. check Ouvrages
expect(OU).toBeDefined();
checkLink(OU.prms.Z2, DD, "Z1");
const struct2 = (OU.structures[1] as RectangularStructure);
checkLink(struct2.prms.L, OU.structures[2], "L");
const struct3 = (OU.structures[2] as RectangularStructure);
checkLink(struct3.prms.W, OU.structures[1], "W");
checkLink(struct3.prms.CdGR, OU.structures[0], "CdGR");
// 4. check Régime Uniforme
expect(RU).toBeDefined();
checkLink(RU.section.prms.Q, DD, "CvQT");
// 5. check Déversoirs dénoyés
expect(DD).toBeDefined();
checkLink(DD.prms.BR, SP, "B");
});
it ("nghyd#263 - errors without consequences should not appear", () => {
Session.getInstance().clear();
// tslint:disable-next-line:max-line-length
const json = `{"header":{"source":"jalhyd","format_version":"1.1","created":"2019-07-31T12:08:20.284Z"},"session":[{"uid":"NjdmM3","props":{"calcType":"PabChute","nodeType":"None"},"meta":{"title":"PAB : chute"},"children":[],"parameters":[{"symbol":"Z1","mode":"SINGLE","value":29.99},{"symbol":"Z2","mode":"SINGLE","value":26.81},{"symbol":"DH","mode":"CALCUL"}]},{"uid":"eWNjdG","props":{"calcType":"PabNombre","nodeType":"None"},"meta":{"title":"PAB : nombre"},"children":[],"parameters":[{"symbol":"DHT","mode":"LINK","targetNub":"NjdmM3","targetParam":"DH"},{"symbol":"N","mode":"SINGLE","value":14},{"symbol":"DH","mode":"CALCUL"}]},{"uid":"dXM4em","props":{"calcType":"PabPuissance","nodeType":"None"},"meta":{"title":"PAB : puissance"},"children":[],"parameters":[{"symbol":"DH","mode":"LINK","targetNub":"eWNjdG","targetParam":"DH"},{"symbol":"Q","mode":"SINGLE","value":1.8},{"symbol":"V","mode":"CALCUL"},{"symbol":"PV","mode":"SINGLE","value":140}]},{"uid":"bzNlaX","props":{"calcType":"PabDimensions","nodeType":"None"},"meta":{"title":"PAB : dimensions"},"children":[],"parameters":[{"symbol":"L","mode":"SINGLE","value":5},{"symbol":"W","mode":"SINGLE","value":3.6},{"symbol":"Y","mode":"CALCUL"},{"symbol":"V","mode":"LINK","targetNub":"dXM4em","targetParam":"V"}]},{"uid":"cGI5d3","props":{"calcType":"Cloisons","nodeType":"None"},"meta":{"title":"Cloisons"},"children":[{"uid":"ZzZzbD","props":{"calcType":"Structure","structureType":"SeuilRectangulaire","loiDebit":"WeirSubmergedLarinier"},"children":[],"parameters":[{"symbol":"h1","mode":"CALCUL"},{"symbol":"L","mode":"SINGLE","value":0.5},{"symbol":"CdWSL","mode":"SINGLE","value":0.83}]}],"parameters":[{"symbol":"Q","mode":"LINK","targetNub":"dXM4em","targetParam":"Q"},{"symbol":"Z1","mode":"SINGLE","value":30.14},{"symbol":"LB","mode":"SINGLE","value":4.5},{"symbol":"BB","mode":"LINK","targetNub":"bzNlaX","targetParam":"W"},{"symbol":"PB","mode":"SINGLE","value":2.5},{"symbol":"DH","mode":"LINK","targetNub":"eWNjdG","targetParam":"DH"}]}]}`;
const res = Session.getInstance().unserialise(json);
expect(res.hasErrors).toBe(false);
});
});
describe("nodeType property - ", () => {
it("serialized SectionNub should have a nodeType property", () => {
const prmsST = new ParamsSectionTrapez(
2.5, // largeur de fond
0.56, // fruit
undefined, // tirant d'eau
40, // Ks=Strickler
2, // Q=Débit
0.001, // If=pente du fond
1, // YB= hauteur de berge
);
const sect = new cSnTrapez(prmsST);
const prem = new CourbeRemousParams(0.15, // Yamont = tirant amont
0.803, // Yaval = tirant aval
5, // Long= Longueur du bief
5, // Dx=Pas d'espace
);
const rem = new CourbeRemous(sect, prem, MethodeResolution.Trapezes);
Session.getInstance().clear();
Session.getInstance().registerNub(rem);
const serialized = Session.getInstance().serialise();
281282283284285286287288289290291292293294295296297298
expect(serialized).toContain('"nodeType":"SectionTrapeze"');
});
it("serialized Nub with no Section should not have a nodeType property", () => {
const prms = new PabChuteParams(
2, // Cote Hamont Z1
0.5, // Cote aval Z2
1.5, // Chute DH
);
const pc = new PabChute(prms);
Session.getInstance().clear();
Session.getInstance().registerNub(pc);
const serialized = Session.getInstance().serialise();
expect(serialized).not.toContain('"nodeType"');
});
});