An error occurred while loading the file. Please try again.
-
Grand Francois authored
refs #334
e7159bbf
import { isNumeric } from "./internal_modules";
import { CalculatorType, SectionType } from "./internal_modules";
import { config } from "./internal_modules";
import { LCMaterial } from "./internal_modules";
import { LinkedValue } from "./internal_modules";
import { Nub } from "./internal_modules";
import { ParamDefinition } from "./internal_modules";
import { Props, Prop_NullParameters } from "./internal_modules";
import { SessionSettings } from "./internal_modules";
// Calculettes
import { Grille, GrilleProfile, GrilleType } from "./internal_modules";
import { GrilleParams } from "./internal_modules";
import { Jet } from "./internal_modules";
import { JetParams } from "./internal_modules";
import { ConcentrationBlocs } from "./internal_modules";
import { ConcentrationBlocsParams } from "./internal_modules";
import { MacroRugo } from "./internal_modules";
import { MacrorugoCompound } from "./internal_modules";
import { MacrorugoCompoundParams } from "./internal_modules";
import { MacrorugoParams } from "./internal_modules";
import { MRCInclination } from "./internal_modules";
import { SPP, SPPOperation } from "./internal_modules";
import { SPPParams } from "./internal_modules";
import { Trigo, TrigoOperation, TrigoUnit } from "./internal_modules";
import { TrigoParams } from "./internal_modules";
import { YAXB } from "./internal_modules";
import { YAXBParams } from "./internal_modules";
import { YAXN } from "./internal_modules";
import { YAXNParams } from "./internal_modules";
import { Bief } from "./internal_modules";
import { BiefParams, BiefRegime } from "./internal_modules";
import { MethodeResolution } from "./internal_modules";
import { Pente } from "./internal_modules";
import { PenteParams } from "./internal_modules";
import { RegimeUniforme } from "./internal_modules";
import { CourbeRemous } from "./internal_modules";
import { CourbeRemousParams } from "./internal_modules";
import { cSnCirc } from "./internal_modules";
import { ParamsSectionCirc } from "./internal_modules";
import { SectionParametree } from "./internal_modules";
import { cSnPuiss } from "./internal_modules";
import { ParamsSectionPuiss } from "./internal_modules";
import { cSnRectang } from "./internal_modules";
import { ParamsSectionRectang } from "./internal_modules";
import { cSnTrapez } from "./internal_modules";
import { ParamsSectionTrapez } from "./internal_modules";
import { acSection } from "./internal_modules";
import { CloisonAval } from "./internal_modules";
import { CloisonsAvalParams } from "./internal_modules";
import { Cloisons } from "./internal_modules";
import { CloisonsParams } from "./internal_modules";
import { Pab } from "./internal_modules";
import { PabChute } from "./internal_modules";
import { PabChuteParams } from "./internal_modules";
import { PabDimension } from "./internal_modules";
import { PabDimensionParams } from "./internal_modules";
import { PabNombre } from "./internal_modules";
import { PabNombreParams } from "./internal_modules";
import { PabParams } from "./internal_modules";
import { PabPuissance } from "./internal_modules";
import { PabPuissanceParams } from "./internal_modules";
import { ConduiteDistrib } from "./internal_modules";
import { ConduiteDistribParams } from "./internal_modules";
import { PL_LechaptCalmon } from "./internal_modules";
import { PL_LechaptCalmonParams } from "./internal_modules";
import { Solveur } from "./internal_modules";
import { SolveurParams } from "./internal_modules";
import { Dever } from "./internal_modules";
import { DeverParams } from "./internal_modules";
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
import { CreateStructure } from "./internal_modules";
import { ParallelStructure } from "./internal_modules";
import { ParallelStructureParams } from "./internal_modules";
import { LoiDebit, StructureType } from "./internal_modules";
import { Par, ParType } from "./internal_modules";
import { ParParams } from "./internal_modules";
import { ParSimulation } from "./internal_modules";
import { ParSimulationParams } from "./internal_modules";
import { FishSpecies } from "./internal_modules";
import { Espece } from "./internal_modules";
import { EspeceParams } from "./internal_modules";
import { Verificateur } from "./internal_modules";
import { DivingJetSupport } from "./internal_modules";
import { PreBarrage } from "./internal_modules";
import { PreBarrageParams } from "./internal_modules";
import { PbCloison } from "./internal_modules";
import { PbBassin } from "./internal_modules";
import { PbBassinParams } from "./internal_modules";
import { ParamValueMode } from "./internal_modules";
import { PressureLoss } from "./internal_modules";
import { PressureLossLaw, PressureLossType } from "./internal_modules";
export class Session {
/** correspondance entre les noms des propriétés et les enum associés */
public static enumFromProperty: any = {
loiDebit: LoiDebit,
methodeResolution: MethodeResolution,
material: LCMaterial,
gridProfile: GrilleProfile,
gridType: GrilleType,
regime: BiefRegime,
trigoOperation: TrigoOperation,
trigoUnit: TrigoUnit,
sppOperation: SPPOperation,
nodeType: SectionType,
calcType: CalculatorType,
structureType: StructureType,
inclinedApron: MRCInclination,
parType: ParType,
species: FishSpecies,
divingJetSupported: DivingJetSupport,
pressureLossType: PressureLossType
};
public static getInstance(): Session {
if (Session._instance === undefined) {
Session._instance = new Session();
}
return Session._instance;
}
/**
* Returns a copy of given map, inverting enum keys and values
*/
public static invertEnumKeysAndValuesInProperties(stringProps: any, forceNumbers: boolean = false) {
const res = JSON.parse(JSON.stringify(stringProps)); // clone
for (const k in res) {
if (!forceNumbers || !isNumeric(res[k])) {
if (Object.keys(Session.enumFromProperty).includes(k)) {
const enumClass = Session.enumFromProperty[k];
res[k] = enumClass[res[k]];
}
}
}
return res;
}
/** instance pour le pattern singleton */
private static _instance: Session;
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
/** free documentation text, in Markdown format, to save into session file (optional) */
public documentation = "";
/** Nubs de la session */
private _nubs: Nub[] = [];
/**
* crée un Nub et l'ajoute à la session
* @param props propriétés du Nub (computeType, nodeType...)
*/
public createSessionNub(p: Props, dbg: boolean = false): Nub {
const res = this.createNub(p, undefined, dbg);
this._nubs.push(res);
return res;
}
/**
* Adds an existing Nub to the session
*/
public registerNub(n: Nub) {
if (this.uidAlreadyUsed(n.uid)) {
n.setUid(Nub.nextUID);
}
this._nubs.push(n);
}
/**
* Adds many existing Nubs to the session
*/
public registerNubs(nubs: Nub[]) {
for (const n of nubs) {
this.registerNub(n);
}
}
/**
* Removes all Nubs from the Session
*/
public clear() {
this._nubs = [];
}
/**
* Returns number of Nubs in the session
*/
public getNumberOfNubs() {
return this._nubs.length;
}
/** Accessor for Nubs list */
public getAllNubs() {
return this._nubs;
}
/**
* Removes a Nub from the session; does not consider Structure nubs inside Calculator nubs
* @param sn the Nub to remove from the session
*/
public deleteNub(sn: Nub) {
let i = 0;
for (const n of this._nubs) {
if (n.uid === sn.uid) {
this._nubs.splice(i, 1);
this.fixDanglingLinks();
return;
}
i++;
}
throw new Error(`Session.deleteNub() : le Nub (uid ${sn.uid}) à supprimer n'a pas été trouvé`);
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
}
/**
* set parameters linked to non exsting modules to fixed mode
*/
private fixDanglingLinks() {
for (const n of this._nubs) {
for (const p of n.parameterIterator) {
if (p.valueMode === ParamValueMode.LINK) {
const targetId = p.referencedValue.nub.uid;
if (this.findNubByUid(targetId) === undefined) {
p.valueMode = ParamValueMode.SINGLE;
}
}
}
}
}
/**
* Returns a JSON representation of (a part of) the current session
* @param options an object having Nub uids as keys, with extra data object as values;
* if empty or undefined, all Nubs are serialised
* @param settings app preferences to store in the session file (decimals, precision…)
*/
public serialise(options?: { [key: string]: {} }, settings?: { [key: string]: {} }): string {
const sess: any[] = [];
// session-wide settings
let sessionSettings = {
precision: SessionSettings.precision,
maxIterations: SessionSettings.maxIterations
};
if (settings) {
sessionSettings = { ...sessionSettings, ...settings };
}
// nubs in session
let ids: string[];
let idsWithChildren: string[];
if (options) {
ids = Object.keys(options);
idsWithChildren = [...ids];
// add ids of children
for (const n of this._nubs) {
if (ids.includes(n.uid)) {
for (const c of n.getChildren()) {
idsWithChildren.push(c.uid);
}
}
}
}
for (const n of this._nubs) {
if (ids === undefined || ids.length === 0) {
sess.push(n.objectRepresentation(undefined, ids));
} else if (ids.includes(n.uid)) {
sess.push(n.objectRepresentation(options[n.uid], idsWithChildren));
}
}
return JSON.stringify({
header: {
source: "jalhyd",
format_version: config.serialisation.fileFormatVersion,
created: (new Date()).toISOString()
},
settings: sessionSettings,
documentation: this.documentation,
session: sess
});
}
/**
* Loads (a part of) a session from a JSON representation
281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
* @param serialised JSON data
* @param uids unserialise only the Nubs havin the given UIDs
*/
public unserialise(serialised: string, uids?: string[]): { nubs: any[], hasErrors: boolean, settings: any } {
// return value
const ret: { nubs: any[], hasErrors: boolean, settings: any } = {
nubs: [],
hasErrors: false,
settings: {}
};
// unserialise to object
const data = JSON.parse(serialised);
// settings
if (data.settings) {
ret.settings = data.settings;
if (data.settings.precision !== undefined) {
SessionSettings.precision = data.settings.precision;
}
if (data.settings.maxIterations !== undefined) {
SessionSettings.maxIterations = data.settings.maxIterations;
}
}
// nubs
if (data.session && Array.isArray(data.session)) {
data.session.forEach((e: any) => {
if (!uids || uids.length === 0 || uids.includes(e.uid)) {
const nubPointer = this.createNubFromObjectRepresentation(e);
ret.nubs.push(nubPointer);
// forward errors
if (nubPointer.hasErrors) {
ret.hasErrors = true;
}
}
});
}
// concatenate doc
if (data.documentation !== undefined && data.documentation !== "") {
this.documentation += `\n\n` + data.documentation;
}
// second pass for links
const flRes = this.fixLinks(serialised, uids);
// forward errors
if (flRes.hasErrors) {
ret.hasErrors = true;
}
// second pass for Solveurs
const fsRes = this.fixSolveurs(serialised, uids);
// forward errors
if (fsRes.hasErrors) {
ret.hasErrors = true;
}
return ret;
}
/**
* Creates a Nub from a JSON representation and adds it to the current session; returns
* a pointer to the Nub and its JSON metadata
* @param serialised JSON representation of a single Nub
* @param register if false, new Nub will just be returned and won't be registered into the session
*/
public unserialiseSingleNub(serialised: string, register: boolean = true): { nub: Nub, meta: any } {
return this.createNubFromObjectRepresentation(JSON.parse(serialised), register);
}
/**
* Returns the Nub identified by uid if any
*/
public findNubByUid(uid: string): Nub {
351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
let foundNub: Nub;
outerLoop:
for (const n of this._nubs) {
if (n.uid === uid) {
foundNub = n;
}
for (const s of n.getChildren()) {
if (s.uid === uid) {
foundNub = s;
break outerLoop;
}
}
}
return foundNub;
}
/**
* Crée un Nub à partir d'une description (Props)
* @param params propriétés à partir desquelles on détermine la classe du Nub à créer
* - calcType: type de Nub
* - nodeType: pour un Nub contenant une section
* - loiDebit: pour un Nub de type Structure (calcType doit être CalculatorType.Structure)
* Si d'autres propriétés sont fournies, elle écraseront les éventuelles propriétés par défaut
* définies dans le constructeur du Nub créé
* @param dbg activer débogage
*/
public createNub(params: Props, parentNub?: Nub, dbg: boolean = false): Nub {
const calcType: CalculatorType = params.getPropValue("calcType");
// true if provided values to parameter creation must be ignored
const nullParams: boolean = params.getPropValue(Prop_NullParameters) === undefined ? false : params.getPropValue(Prop_NullParameters);
let nub: Nub;
let prms: any;
switch (calcType) {
case CalculatorType.ConduiteDistributrice:
prms = new ConduiteDistribParams(
3, // 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
nullParams
);
nub = new ConduiteDistrib(prms, dbg);
break;
case CalculatorType.LechaptCalmon:
prms = new PL_LechaptCalmonParams(
3, // débit
1.2, // diamètre
0.6, /// perte de charge
100, // longueur du toyo
0, // Ks Perte de charge singulière
1.863, // paramètre L du matériau
2, // paramètre M du matériau
5.33, // paramètre N du matériau
nullParams
);
nub = new PL_LechaptCalmon(prms, dbg);
break;
case CalculatorType.SectionParametree:
nub = new SectionParametree(undefined, dbg);
break;
case CalculatorType.RegimeUniforme:
nub = new RegimeUniforme(undefined, dbg);
break;
421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
case CalculatorType.CourbeRemous:
prms = new CourbeRemousParams(
100.25, // Z1 = cote de l'eau amont
100.4, // Z2 = cote de l'eau aval
100.1, // ZF1 = cote de fond amont
100, // ZF2 = cote de fond aval
100, // Long = Longueur du bief
5, // Dx = Pas d'espace
nullParams
);
nub = new CourbeRemous(undefined, prms, MethodeResolution.EulerExplicite, dbg);
break;
case CalculatorType.PabDimensions:
prms = new PabDimensionParams(
2, // Longueur L
1, // Largeur W
0.5, // Tirant d'eau Y
2, // Volume V
nullParams
);
nub = new PabDimension(prms, dbg);
break;
case CalculatorType.PabPuissance:
prms = new PabPuissanceParams(
0.3, // Chute entre bassins DH (m)
0.1, // Débit Q (m3/s)
0.5, // Volume V (m3)
588.6, // Puissance dissipée PV (W/m3)
nullParams
);
nub = new PabPuissance(prms, dbg);
break;
case CalculatorType.Structure:
const loiDebit: LoiDebit = params.getPropValue("loiDebit");
nub = CreateStructure(loiDebit, (parentNub as ParallelStructure), dbg, nullParams);
break;
case CalculatorType.ParallelStructure:
prms = new ParallelStructureParams(
0.5, // Q
102, // Z1
101.5, // Z2
nullParams
);
nub = new ParallelStructure(prms, dbg);
break;
case CalculatorType.Dever:
const deverPrms = new DeverParams(
0.5, // Q
102, // Z1
10, // BR : largeur du cours d'eau
99, // ZR : cote du lit du cours d'eau
nullParams
);
nub = new Dever(deverPrms, dbg);
break;
case CalculatorType.Cloisons:
nub = new Cloisons(
new CloisonsParams(
1.5, // 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)
491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
0.5, // Hauteur de chute (m)
nullParams
), dbg
);
break;
case CalculatorType.MacroRugo:
nub = new MacroRugo(
new MacrorugoParams(
12.5, // ZF1
6, // L
1, // B
0.05, // If
1.57, // Q
0.6, // h
0.01, // Ks
0.13, // C
0.4, // D
0.4, // k
1, // Cd0
nullParams
), dbg
);
break;
case CalculatorType.PabChute:
nub = new PabChute(
new PabChuteParams(
2, // Z1
0.5, // Z2
1.5, // DH
nullParams
), dbg
);
break;
case CalculatorType.PabNombre:
nub = new PabNombre(
new PabNombreParams(
6, // DHT
10, // N
0.6, // DH
nullParams
), dbg
);
break;
case CalculatorType.Section:
const nodeType: SectionType = params.getPropValue("nodeType");
nub = this.createSection(nodeType, dbg, nullParams);
break;
case CalculatorType.Pab:
nub = new Pab(
new PabParams(
1.5, // Q
102, // Z1
99, // Z2
nullParams
), undefined, dbg
);
break;
case CalculatorType.CloisonAval: {
prms = new CloisonsAvalParams(
0.5, // Q
102, // Z1
101.5, // Z2
0, // ZRAM
nullParams
561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
);
nub = new CloisonAval(prms, dbg);
break;
}
case CalculatorType.MacroRugoCompound:
nub = new MacrorugoCompound(
new MacrorugoCompoundParams(
13.1, // Z1
12.5, // ZRL
12.5, // ZRR
4, // B
3, // DH
0.05, // If
0.01, // Ks
0.13, // C
0.4, // D
0.4, // k
1, // Cd0
nullParams
), dbg
);
break;
case CalculatorType.Jet:
nub = new Jet(
new JetParams(
5, // V0
0.03, // S
30, // ZJ
29.2, // ZW
28.5, // ZF
3, // D
nullParams
), dbg
);
break;
case CalculatorType.Grille:
nub = new Grille(
new GrilleParams(
10, // QMax
100, // CRad
101.5, // CEau
101.5, // CSomGrille
2, // B
72, // Beta
90, // Alpha
20, // b
20, // p
20, // e
2, // a
1.5, // c
0.5, // O
0.5, // Ob
0.1, // OEntH
4, // cIncl
nullParams
), dbg
);
break;
case CalculatorType.Pente:
nub = new Pente(
new PenteParams(
101, // Z1
99.5, // Z2
10, // L
0.15, // I
nullParams
631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
), dbg
);
break;
case CalculatorType.Bief:
nub = new Bief(
undefined,
new BiefParams(
100.25, // Z1 = cote de l'eau amont
100.4, // Z2 = cote de l'eau aval
100.1, // ZF1 = cote de fond amont
100, // ZF2 = cote de fond aval
100, // Long = Longueur du bief
5, // Dx = Pas d'espace
nullParams
),
dbg
);
break;
case CalculatorType.Solveur:
nub = new Solveur(
new SolveurParams(undefined, undefined, nullParams)
);
break;
case CalculatorType.YAXB:
nub = new YAXB(
new YAXBParams(
10, // Y
2, // A
3, // X
4, // B
nullParams
),
dbg
);
break;
case CalculatorType.Trigo:
nub = new Trigo(
new TrigoParams(
0.985, // Y
10, // X
nullParams
),
dbg
);
break;
case CalculatorType.SPP:
nub = new SPP(
new SPPParams(
1, // Y
nullParams
),
dbg
);
break;
case CalculatorType.YAXN:
nub = new YAXN(
new YAXNParams(
1, // A
1, // X
1, // B
undefined,
nullParams
),
dbg
701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
);
break;
case CalculatorType.ConcentrationBlocs:
nub = new ConcentrationBlocs(
new ConcentrationBlocsParams(
0.128, // Concentration de blocs
5, // Nombre de motifs
4.9, // Largeur de la passe
0.35, // Diamètre des plots
nullParams
), dbg
);
break;
case CalculatorType.Par:
nub = new Par(
new ParParams(
0.25, // Q
10, // Z1
9, // Z2
0.64, // ha
0.2, // S
0.4, // P
0.6, // L
0.1, // a
1, // N
1, // M
nullParams
), dbg
);
break;
case CalculatorType.ParSimulation:
nub = new ParSimulation(
new ParSimulationParams(
0.25, // Q
10, // Z1
9, // Z2
0.2, // S
0.4, // P
undefined, // Nb
9.242, // ZR1
undefined, // ZD1
8.222, // ZR2
undefined, // ZD2
0.6, // L
0.1, // a
1, // N
1, // M
nullParams
), dbg
);
break;
case CalculatorType.PreBarrage:
nub = new PreBarrage(
new PreBarrageParams(
1, // Q
101, // Z1
100, // Z2
nullParams
), dbg
);
break;
case CalculatorType.Espece:
nub = new Espece(
// default params are those for SPECIES_1 (Salmons and trouts)
new EspeceParams(
771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
0.35, // DHMaxS
0.35, // DHMaxP
0.3, // BMin
1, // PMinS
1, // PMinP
2.5, // LMinS
2.5, // LMinP
0.3, // HMin
0.4, // YMin
2.5, // VeMax
0.2, // YMinSB
0.3, // YMinPB
150, // PVMaxPrec
200, // PVMaxLim
nullParams
)
);
break;
case CalculatorType.Verificateur:
nub = new Verificateur();
break;
case CalculatorType.PbBassin:
nub = new PbBassin(new PbBassinParams(
10, // S
100, // ZF
nullParams
), dbg);
break;
case CalculatorType.PbCloison:
nub = new PbCloison(undefined, undefined, undefined, nullParams);
break;
case CalculatorType.PressureLoss:
const lossType: PressureLossType = params.getPropValue("pressureLossType");
const pl = this.createPressureLossLaw(lossType, dbg, nullParams);
nub = new PressureLoss(pl, dbg);
break;
default:
throw new Error(
`Session.createNub() : type de module '${CalculatorType[calcType]}' non pris en charge`
);
}
// propagate properties
try {
nub.properties = params;
} catch (e) {
// loading Solveur properties when unserialising a session might fail because target
// Nub / param do not exist yet; silent fail in this case, and Solveur.fixTargets()
// might fix it later
if (!(nub instanceof Solveur)) {
throw e;
}
}
return nub;
}
/**
* Returns true if given uid is already used by a Nub in this session,
* or a Structure nub inside one of them
*/
public uidAlreadyUsed(uid: string, nubs: Nub[] = this._nubs): boolean {
let alreadyUsed = false;
for (const n of nubs) {
if (n.uid === uid) {
841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
alreadyUsed = true;
break;
}
if (!alreadyUsed) {
alreadyUsed = this.uidAlreadyUsed(uid, n.getChildren());
}
}
return alreadyUsed;
}
/**
* Returns all Nubs depending on the given one (parameter or result),
* without following links (1st level only)
* @param uid UID of the Nub that underwent a change
* @param symbol symbol of the parameter whose value change triggered this method; if specified,
* Nubs targetting this symbol will be considered dependent
* @param includeValuesLinks if true, even Nubs targetting non-calculated non-modified parameters
* will be considered dependent @see jalhyd#98
* @param includeOtherDependencies if true, will be considered dependent
* - Solveur Nubs having given Nub either as X or as Ytarget's parent Nub
* - Verificateur Nubs having given Nub either as selected Custom Species or Pass to check
*/
public getDependingNubs(
uid: string,
symbol?: string,
includeValuesLinks: boolean = false,
includeOtherDependencies: boolean = false
): Nub[] {
const dependingNubs: Nub[] = [];
for (const n of this._nubs) {
if (
n.uid !== uid
&& n.resultDependsOnNub(uid, [], symbol, includeValuesLinks, includeOtherDependencies)
) {
dependingNubs.push(n);
}
}
return dependingNubs;
}
/**
* Returns all Nubs depending on the result of at least one other Nub.
* Used by Solveur to find available "target" nubs to calculate.
*/
public getDownstreamNubs(): Nub[] {
const downstreamNubs: Nub[] = [];
for (const n of this._nubs) {
if (n.getRequiredNubs().length > 0) {
downstreamNubs.push(n);
}
}
return downstreamNubs;
}
/**
* Returns all Nubs that do not depend on the result of any other Nub
* (includes single Nubs).
*/
public getUpstreamNubs(): Nub[] {
const upstreamNubs: Nub[] = [];
for (const n of this._nubs) {
if (n.getRequiredNubs().length === 0) {
upstreamNubs.push(n);
}
}
return upstreamNubs;
}
/**
* Returns all upstream Nubs that have at least one declared extra result.
911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
* Used by Solveur to find available "target" nubs to calculate.
*/
public getUpstreamNubsHavingExtraResults() {
const unher: Nub[] = [];
for (const n of this.getUpstreamNubs()) {
if (n.resultsFamilies && Object.keys(n.resultsFamilies).length > 0) {
unher.push(n);
}
}
return unher;
}
/**
* Returns a list of nub/symbol couples, that can be linked to the given
* parameter, among all current nubs
* @param p
*/
public getLinkableValues(p: ParamDefinition): LinkedValue[] {
let res: LinkedValue[] = [];
for (const n of this._nubs) {
const linkableValues = n.getLinkableValues(p);
res = res.concat(linkableValues);
}
/* console.log("LINKABLE VALUES", res.map((lv) => {
return `${lv.nub.uid}(${lv.nub.constructor.name})/${lv.symbol}`;
})); */
return res;
}
/**
* Crée un Nub de type Section
* @param nt SectionType
* @param dbg activer débogage
*/
public createSection(nt: SectionType, dbg: boolean = false, nullParams: boolean = false): acSection {
switch (nt) {
case SectionType.SectionTrapeze: {
const prms = new ParamsSectionTrapez(2.5, // largeur de fond
0.56, // fruit
0.8, // tirant d'eau
40, // Ks=Strickler
1.2, // Q=Débit
0.001, // If=pente du fond
1, // YB= hauteur de berge
nullParams
);
return new cSnTrapez(prms, dbg);
}
case SectionType.SectionRectangle: {
const prms = 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
1, // YB=hauteur de berge
nullParams
);
return new cSnRectang(prms, dbg);
}
case SectionType.SectionCercle: {
const prms = new ParamsSectionCirc(2, // diamètre
0.8, // tirant d'eau
40, // Ks=Strickler
1.2, // Q=Débit
0.001, // If=pente du fond
1, // YB= hauteur de berge
nullParams
981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
);
return new cSnCirc(prms, dbg);
}
case SectionType.SectionPuissance: {
const prms = new ParamsSectionPuiss(0.5, // coefficient
0.8, // tirant d'eau
4, // largeur de berge
40, // Ks=Strickler
1.2, // Q=Débit
0.001, // If=pente du fond
1, // YB= hauteur de berge
nullParams
);
return new cSnPuiss(prms, dbg);
}
default:
throw new Error(`type de section ${SectionType[nt]} non pris en charge`);
}
}
/**
* Crée un Nub de type perte de charge
*/
private createPressureLossLaw(plt: PressureLossType, dbg: boolean = false, nullParams: boolean = false): PressureLossLaw {
switch (plt) {
case PressureLossType.LechaptCalmon:
const prms = new PL_LechaptCalmonParams(
3, // débit
1.2, // diamètre
0.6, /// perte de charge
100, // longueur du toyo
0, // Ks Perte de charge singulière
1.863, // paramètre L du matériau
2, // paramètre M du matériau
5.33, // paramètre N du matériau
nullParams
);
return new PL_LechaptCalmon(prms, dbg);
default:
throw new Error(`type de perte de charge ${PressureLossType[plt]} non pris en charge`);
}
}
/**
* Creates a Nub from an object representation and adds it to the current session; returns
* a pointer to the Nub and its JSON metadata
* @param obj object representation of a single Nub
* @param register if false, new Nub will just be returned and won't be registered into the session
*/
private createNubFromObjectRepresentation(obj: any, register: boolean = true)
: { nub: Nub, meta: any, hasErrors: boolean } {
// return value;
const nubPointer: { nub: Nub, meta: any, hasErrors: boolean } = {
nub: undefined,
meta: undefined,
hasErrors: false
};
// decode properties
const props = Session.invertEnumKeysAndValuesInProperties(obj.props, true);
// create the Nub
let newNub;
if (register) {
newNub = this.createSessionNub(new Props(props));
} else {
newNub = this.createNub(new Props(props));
1051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
}
// try to keep the original ID
if (!this.uidAlreadyUsed(obj.uid)) {
newNub.setUid(obj.uid);
}
const res = newNub.loadObjectRepresentation(obj);
nubPointer.nub = newNub;
// forward errors
if (res.hasErrors) {
nubPointer.hasErrors = true;
}
// add metadata (used by GUI, for ex.)
if (obj.meta) {
nubPointer.meta = obj.meta;
}
return nubPointer;
}
/**
* Asks all loaded Nubs to relink any parameter that has a wrong target
*/
private fixLinks(serialised: string, uids?: string[]): { hasErrors: boolean } {
// return value
const res = {
hasErrors: false
};
const data = JSON.parse(serialised);
if (data.session && Array.isArray(data.session)) {
// find each corresponding Nub in the session
data.session.forEach((e: any) => {
if (!uids || uids.length === 0 || uids.includes(e.uid)) {
const nub = this.findNubByUid(e.uid);
// find linked parameters
const ret = nub.fixLinks(e);
// forwardErrors
if (ret.hasErrors) {
res.hasErrors = true;
}
}
});
}
return res;
}
/**
* Asks every loaded Solveur to reconnect to its nubToCalculate / searchedParameter
*/
private fixSolveurs(serialised: string, uids?: string[]): { hasErrors: boolean } {
// return value
const res = {
hasErrors: false
};
const data = JSON.parse(serialised);
if (data.session && Array.isArray(data.session)) {
// find each corresponding Nub in the session
data.session.forEach((e: any) => {
if (!uids || uids.length === 0 || uids.includes(e.uid)) {
const nub = this.findNubByUid(e.uid);
if (nub instanceof Solveur) {
// find targetted nubToCalculate / searchedParam
const ret = nub.fixTargets(e);
// forwardErrors
if (ret.hasErrors) {
res.hasErrors = true;
}
}
}
});
}
return res;
112111221123
}
}