UNPKG

jalhyd

Version:

JaLHyd, a Javascript Library for Hydraulics

972 lines 41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Session = void 0; const internal_modules_1 = require("./internal_modules"); const internal_modules_2 = require("./internal_modules"); const internal_modules_3 = require("./internal_modules"); const internal_modules_4 = require("./internal_modules"); const internal_modules_5 = require("./internal_modules"); // Calculettes const internal_modules_6 = require("./internal_modules"); const internal_modules_7 = require("./internal_modules"); const internal_modules_8 = require("./internal_modules"); const internal_modules_9 = require("./internal_modules"); const internal_modules_10 = require("./internal_modules"); const internal_modules_11 = require("./internal_modules"); const internal_modules_12 = require("./internal_modules"); const internal_modules_13 = require("./internal_modules"); const internal_modules_14 = require("./internal_modules"); const internal_modules_15 = require("./internal_modules"); const internal_modules_16 = require("./internal_modules"); const internal_modules_17 = require("./internal_modules"); const internal_modules_18 = require("./internal_modules"); const internal_modules_19 = require("./internal_modules"); const internal_modules_20 = require("./internal_modules"); const internal_modules_21 = require("./internal_modules"); const internal_modules_22 = require("./internal_modules"); const internal_modules_23 = require("./internal_modules"); const internal_modules_24 = require("./internal_modules"); const internal_modules_25 = require("./internal_modules"); const internal_modules_26 = require("./internal_modules"); const internal_modules_27 = require("./internal_modules"); const internal_modules_28 = require("./internal_modules"); const internal_modules_29 = require("./internal_modules"); const internal_modules_30 = require("./internal_modules"); const internal_modules_31 = require("./internal_modules"); const internal_modules_32 = require("./internal_modules"); const internal_modules_33 = require("./internal_modules"); const internal_modules_34 = require("./internal_modules"); const internal_modules_35 = require("./internal_modules"); const internal_modules_36 = require("./internal_modules"); const internal_modules_37 = require("./internal_modules"); const internal_modules_38 = require("./internal_modules"); const internal_modules_39 = require("./internal_modules"); const internal_modules_40 = require("./internal_modules"); const internal_modules_41 = require("./internal_modules"); const internal_modules_42 = require("./internal_modules"); const internal_modules_43 = require("./internal_modules"); const internal_modules_44 = require("./internal_modules"); const internal_modules_45 = require("./internal_modules"); const internal_modules_46 = require("./internal_modules"); const internal_modules_47 = require("./internal_modules"); const internal_modules_48 = require("./internal_modules"); const internal_modules_49 = require("./internal_modules"); const internal_modules_50 = require("./internal_modules"); const internal_modules_51 = require("./internal_modules"); const internal_modules_52 = require("./internal_modules"); const internal_modules_53 = require("./internal_modules"); const internal_modules_54 = require("./internal_modules"); const internal_modules_55 = require("./internal_modules"); const internal_modules_56 = require("./internal_modules"); const internal_modules_57 = require("./internal_modules"); const internal_modules_58 = require("./internal_modules"); const internal_modules_59 = require("./internal_modules"); const internal_modules_60 = require("./internal_modules"); const internal_modules_61 = require("./internal_modules"); const internal_modules_62 = require("./internal_modules"); const internal_modules_63 = require("./internal_modules"); const internal_modules_64 = require("./internal_modules"); const internal_modules_65 = require("./internal_modules"); const internal_modules_66 = require("./internal_modules"); const internal_modules_67 = require("./internal_modules"); const internal_modules_68 = require("./internal_modules"); const internal_modules_69 = require("./internal_modules"); const internal_modules_70 = require("./internal_modules"); const internal_modules_71 = require("./internal_modules"); const internal_modules_72 = require("./internal_modules"); const internal_modules_73 = require("./internal_modules"); const internal_modules_74 = require("./internal_modules"); const internal_modules_75 = require("./internal_modules"); const internal_modules_76 = require("./internal_modules"); const internal_modules_77 = require("./internal_modules"); const internal_modules_78 = require("./internal_modules"); const internal_modules_79 = require("./internal_modules"); const internal_modules_80 = require("./internal_modules"); const internal_modules_81 = require("./internal_modules"); class Session { constructor() { /** free documentation text, in Markdown format, to save into session file (optional) */ this.documentation = ""; /** Nubs de la session */ this._nubs = []; } static getInstance() { if (Session._instance === undefined) { Session._instance = new Session(); } return Session._instance; } /** * crée un Nub et l'ajoute à la session * @param props propriétés du Nub (computeType, nodeType...) */ createSessionNub(p, dbg = false) { const res = this.createNub(p, undefined, dbg); this._nubs.push(res); return res; } /** * Adds an existing Nub to the session */ registerNub(n) { if (this.uidAlreadyUsed(n.uid)) { n.setUid(internal_modules_3.Nub.nextUID); } this._nubs.push(n); } /** * Adds many existing Nubs to the session */ registerNubs(nubs) { for (const n of nubs) { this.registerNub(n); } } /** * Removes all Nubs from the Session */ clear() { this._nubs = []; } /** * Returns number of Nubs in the session */ getNumberOfNubs() { return this._nubs.length; } /** Accessor for Nubs list */ 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 */ deleteNub(sn) { 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é`); } /** * set parameters linked to non exsting modules to fixed mode */ fixDanglingLinks() { for (const n of this._nubs) { for (const p of n.parameterIterator) { if (p.valueMode === internal_modules_78.ParamValueMode.LINK) { const targetId = p.referencedValue.nub.uid; if (this.findNubByUid(targetId) === undefined) { p.valueMode = internal_modules_78.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…) */ serialise(options, settings) { const sess = []; // session-wide settings let sessionSettings = { precision: internal_modules_5.SessionSettings.precision, maxIterations: internal_modules_5.SessionSettings.maxIterations }; if (settings) { sessionSettings = Object.assign(Object.assign({}, sessionSettings), settings); } // nubs in session let ids; let idsWithChildren; 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: internal_modules_2.config.serialisation.fileFormatVersion, created: (new Date()).toISOString() }, settings: sessionSettings, documentation: this.documentation, session: sess }); } /** * Loads (a part of) a session from a JSON representation * @param serialised JSON data * @param uids unserialise only the Nubs havin the given UIDs */ unserialise(serialised, uids) { // return value const ret = { 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) { internal_modules_5.SessionSettings.precision = data.settings.precision; } if (data.settings.maxIterations !== undefined) { internal_modules_5.SessionSettings.maxIterations = data.settings.maxIterations; } } // nubs if (data.session && Array.isArray(data.session)) { data.session.forEach((e) => { 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 */ unserialiseSingleNub(serialised, register = true) { return this.createNubFromObjectRepresentation(JSON.parse(serialised), register); } /** * Returns the Nub identified by uid if any */ findNubByUid(uid) { let foundNub; 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; } static parameterIndex(obj, symbol) { let i; const prms = obj["parameters"]; for (i in prms) { if (prms[i]["symbol"] === symbol) { return +i; } } return -1; } /** * Calcule le type de calculette compatible et modifie les propriétés en conséquence. * Permet de charger des fichiers session avec une version antérieure. * Par ex : Lechapt-Calmon -> PressureLoss */ compatibleCalculator(obj) { switch (obj["props"]["calcType"]) { case internal_modules_1.CalculatorType.LechaptCalmon: // create parent PressureLoss nub const plProps = new internal_modules_4.Props(); plProps.setPropValue("calcType", internal_modules_1.CalculatorType.PressureLoss); const pl = this.createNub(plProps); // JSON representation let res = pl.objectRepresentation(); // set Lechapt-Calmon as child res["children"] = [obj]; // move PressureLoss parameters from Lechapt-Calmon const movedParams = ["Q", "D", "J", "Lg", "Kloc"]; for (const p of movedParams) { // if child has parameter const cp = Session.parameterIndex(obj, p); if (cp !== -1) { const pp = Session.parameterIndex(res, p); if (pp === -1) { res["parameters"].push(obj["parameters"][cp]); } else { res["parameters"][pp] = obj["parameters"][cp]; } // delete obj["parameters"][pp]; obj["parameters"].splice(cp, 1); } } return res; default: return obj; } } /** * 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 */ createNub(params, parentNub, dbg = false) { var _a, _b; // true if provided values to parameter creation must be ignored const nullParams = params.getPropValue(internal_modules_4.Prop_NullParameters) === undefined ? false : params.getPropValue(internal_modules_4.Prop_NullParameters); let nub; let prms; const calcType = params.getPropValue("calcType"); switch (calcType) { case internal_modules_1.CalculatorType.ConduiteDistributrice: prms = new internal_modules_56.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 internal_modules_55.ConduiteDistrib(prms, dbg); break; case internal_modules_1.CalculatorType.LechaptCalmon: prms = new internal_modules_58.PL_LechaptCalmonParams(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 internal_modules_57.PL_LechaptCalmon(prms, dbg); break; case internal_modules_1.CalculatorType.SectionParametree: nub = new internal_modules_34.SectionParametree(undefined, dbg); break; case internal_modules_1.CalculatorType.RegimeUniforme: nub = new internal_modules_29.RegimeUniforme(undefined, dbg); break; case internal_modules_1.CalculatorType.CourbeRemous: prms = new internal_modules_31.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 internal_modules_30.CourbeRemous(undefined, prms, internal_modules_26.MethodeResolution.Trapezes, dbg); break; case internal_modules_1.CalculatorType.PabDimensions: prms = new internal_modules_49.PabDimensionParams(2, // Longueur L 1, // Largeur W 0.5, // Tirant d'eau Y 2, // Volume V nullParams); nub = new internal_modules_48.PabDimension(prms, dbg); break; case internal_modules_1.CalculatorType.PabPuissance: prms = new internal_modules_54.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 internal_modules_53.PabPuissance(prms, dbg); break; case internal_modules_1.CalculatorType.Structure: const loiDebit = params.getPropValue("loiDebit"); nub = (0, internal_modules_63.CreateStructure)(loiDebit, parentNub, dbg, nullParams); break; case internal_modules_1.CalculatorType.ParallelStructure: prms = new internal_modules_65.ParallelStructureParams(0.5, // Q 102, // Z1 101.5, // Z2 nullParams); nub = new internal_modules_64.ParallelStructure(prms, dbg); break; case internal_modules_1.CalculatorType.Dever: const deverPrms = new internal_modules_62.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 internal_modules_61.Dever(deverPrms, dbg); break; case internal_modules_1.CalculatorType.Cloisons: nub = new internal_modules_43.Cloisons(new internal_modules_44.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) 0.5, // Hauteur de chute (m) nullParams), dbg); break; case internal_modules_1.CalculatorType.MacroRugo: nub = new internal_modules_12.MacroRugo(new internal_modules_15.MacrorugoParams(12.5, // ZF1 6, // L 2.218, // B 0.05, // If 2.53, // Q 0.6, // h 0.01, // Ks 0.13, // C 0.4, // D 0.4, // k 1, // Cd0 nullParams), dbg); break; case internal_modules_1.CalculatorType.PabChute: nub = new internal_modules_46.PabChute(new internal_modules_47.PabChuteParams(2, // Z1 0.5, // Z2 1.5, // DH nullParams), dbg); break; case internal_modules_1.CalculatorType.PabNombre: nub = new internal_modules_50.PabNombre(new internal_modules_51.PabNombreParams(6, // DHT 10, // N 0.6, // DH nullParams), dbg); break; case internal_modules_1.CalculatorType.Section: const nodeType = params.getPropValue("nodeType"); nub = this.createSection(nodeType, dbg, nullParams); break; case internal_modules_1.CalculatorType.Pab: nub = new internal_modules_45.Pab(new internal_modules_52.PabParams(1.5, // Q 102, // Z1 99, // Z2 nullParams), undefined, dbg); break; case internal_modules_1.CalculatorType.CloisonAval: { prms = new internal_modules_42.CloisonsAvalParams(0.5, // Q 102, // Z1 101.5, // Z2 0, // ZRAM nullParams); nub = new internal_modules_41.CloisonAval(prms, dbg); break; } case internal_modules_1.CalculatorType.MacroRugoCompound: nub = new internal_modules_13.MacrorugoCompound(new internal_modules_14.MacrorugoCompoundParams(13.1, // Z1 12.5, // ZRT 12.5, // ZRB 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 internal_modules_1.CalculatorType.Jet: nub = new internal_modules_8.Jet(new internal_modules_9.JetParams(5, // V0 0.03, // S 30, // ZJ 29.2, // ZW 28.5, // ZF 3, // D nullParams), dbg); break; case internal_modules_1.CalculatorType.Grille: nub = new internal_modules_6.Grille(new internal_modules_7.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 internal_modules_1.CalculatorType.Pente: nub = new internal_modules_27.Pente(new internal_modules_28.PenteParams(101, // Z1 99.5, // Z2 10, // L 0.15, // I nullParams), dbg); break; case internal_modules_1.CalculatorType.Bief: nub = new internal_modules_24.Bief(undefined, new internal_modules_25.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 internal_modules_1.CalculatorType.Solveur: nub = new internal_modules_59.Solveur(new internal_modules_60.SolveurParams(undefined, undefined, nullParams)); break; case internal_modules_1.CalculatorType.YAXB: nub = new internal_modules_20.YAXB(new internal_modules_21.YAXBParams(10, // Y 2, // A 3, // X 4, // B nullParams), dbg); break; case internal_modules_1.CalculatorType.Trigo: nub = new internal_modules_18.Trigo(new internal_modules_19.TrigoParams(0.985, // Y 10, // X nullParams), dbg); break; case internal_modules_1.CalculatorType.SPP: nub = new internal_modules_16.SPP(new internal_modules_17.SPPParams(1, // Y nullParams), dbg); break; case internal_modules_1.CalculatorType.YAXN: nub = new internal_modules_22.YAXN(new internal_modules_23.YAXNParams(1, // A 1, // X 1, // B undefined, nullParams), dbg); break; case internal_modules_1.CalculatorType.ConcentrationBlocs: nub = new internal_modules_10.ConcentrationBlocs(new internal_modules_11.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 internal_modules_1.CalculatorType.Par: nub = new internal_modules_66.Par(new internal_modules_67.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 internal_modules_1.CalculatorType.ParSimulation: nub = new internal_modules_68.ParSimulation(new internal_modules_69.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 internal_modules_1.CalculatorType.PreBarrage: nub = new internal_modules_73.PreBarrage(new internal_modules_74.PreBarrageParams(1, // Q 101, // Z1 100, // Z2 nullParams), dbg); break; case internal_modules_1.CalculatorType.Espece: nub = new internal_modules_70.Espece( // default params are those for SPECIES_1 (Salmons and trouts) new internal_modules_71.EspeceParams(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 internal_modules_1.CalculatorType.RugoFondMultiple: nub = new internal_modules_1.RugoFondMultiple( // default params from excel rampe rugiosité new internal_modules_1.RugoFondMultipleParams(0.76, // Débit total (m3/s) 12.8, // Cote de l'eau amont (m) 3, // Largeur totale de la rampe (m) 0.024, // Pente longitudinale de la rampe (m/m) 0.35, // Coefficient de débit 0.3, // d65 des enrochements du fond (m) 15.5, // Coefficient de rugosité de Strickler Ks (m1/3/s) 12, // Cote de fond amont (m) 12, // Cote de fond bas amont (m)(Radier incliné seulement) 13, // Cote de fond haut amont (m) (Radier incliné seulement) 3, // Nombre de tranche d'écoulement nullParams)); break; case internal_modules_1.CalculatorType.Verificateur: nub = new internal_modules_72.Verificateur(); break; case internal_modules_1.CalculatorType.PbBassin: nub = new internal_modules_76.PbBassin(new internal_modules_77.PbBassinParams(10, // S 100, // ZF nullParams), dbg); break; case internal_modules_1.CalculatorType.PbCloison: nub = new internal_modules_75.PbCloison(undefined, undefined, undefined, nullParams); break; case internal_modules_1.CalculatorType.PressureLoss: const plParams = new internal_modules_1.PressureLossParams(3, // débit 1.2, // diamètre 0.6, /// perte de charge 100, // longueur du toyo 0, // Kloc Perte de charge singulière nullParams); const lossType = (_a = params.getPropValue("pressureLossType")) !== null && _a !== void 0 ? _a : internal_modules_80.PressureLossType.LechaptCalmon; nub = new internal_modules_79.PressureLoss(plParams, undefined, dbg); nub.setPropValue("pressureLossType", lossType); break; case internal_modules_1.CalculatorType.PressureLossLaw: const lt = (_b = params.getPropValue("pressureLossType")) !== null && _b !== void 0 ? _b : internal_modules_80.PressureLossType.LechaptCalmon; nub = this.createPressureLossLaw(lt, dbg, nullParams); nub.setPropValue("pressureLossType", lt); break; case internal_modules_1.CalculatorType.MacrorugoRemous: const crp = new internal_modules_1.MacrorugoRemousParams(12.8, // Z2 = cote de l'eau aval nullParams); nub = new internal_modules_81.MacrorugoRemous(undefined, crp, internal_modules_26.MethodeResolution.Trapezes, dbg); break; default: throw new Error(`Session.createNub() : type de module '${internal_modules_1.CalculatorType[calcType]}' non pris en charge`); } // propagate properties try { nub.setProperties(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 internal_modules_59.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 */ uidAlreadyUsed(uid, nubs = this._nubs) { let alreadyUsed = false; for (const n of nubs) { if (n.uid === uid) { 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 */ getDependingNubs(uid, symbol, includeValuesLinks = false, includeOtherDependencies = false) { const dependingNubs = []; 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. */ getDownstreamNubs() { const downstreamNubs = []; 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). */ getUpstreamNubs() { const upstreamNubs = []; 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. * Used by Solveur to find available "target" nubs to calculate. */ getUpstreamNubsHavingExtraResults() { const unher = []; 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 */ getLinkableValues(p) { let res = []; 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; } /** * @returns true if parameter is a link target in any session nub */ isParameterLinkTarget(p) { for (const n of this._nubs) { if (n.dependsOnParameter(p)) { return true; } } return false; } /** * Crée un Nub de type Section * @param nt SectionType * @param dbg activer débogage */ createSection(nt, dbg = false, nullParams = false) { switch (nt) { case internal_modules_1.SectionType.SectionTrapeze: { const prms = new internal_modules_40.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 internal_modules_39.cSnTrapez(prms, dbg); } case internal_modules_1.SectionType.SectionRectangle: { const prms = new internal_modules_38.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 internal_modules_37.cSnRectang(prms, dbg); } case internal_modules_1.SectionType.SectionCercle: { const prms = new internal_modules_33.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); return new internal_modules_32.cSnCirc(prms, dbg); } case internal_modules_1.SectionType.SectionPuissance: { const prms = new internal_modules_36.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 internal_modules_35.cSnPuiss(prms, dbg); } default: throw new Error(`type de section ${internal_modules_1.SectionType[nt]} non pris en charge`); } } /** * Crée un Nub de type loi de perte de charge */ createPressureLossLaw(plt, dbg = false, nullParams = false) { switch (plt) { case internal_modules_80.PressureLossType.LechaptCalmon: const prms = new internal_modules_58.PL_LechaptCalmonParams(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 internal_modules_57.PL_LechaptCalmon(prms, dbg); case internal_modules_80.PressureLossType.Strickler: const sp = new internal_modules_1.PL_StricklerParams(1, nullParams); return new internal_modules_1.PL_Strickler(sp); default: throw new Error(`type de perte de charge ${internal_modules_80.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 */ createNubFromObjectRepresentation(obj, register = true) { // return value; const nubPointer = { nub: undefined, meta: undefined, hasErrors: false }; // get upward compatible calculator obj = this.compatibleCalculator(obj); // decode properties const props = internal_modules_4.Props.invertEnumKeysAndValuesInProperties(obj.props, true); // create the Nub let newNub; if (register) { newNub = this.createSessionNub(new internal_modules_4.Props(props)); } else { newNub = this.createNub(new internal_modules_4.Props(props)); } // 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 */ fixLinks(serialised, uids) { // 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) => { 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 */ fixSolveurs(serialised, uids) { // 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) => { if (!uids || uids.length === 0 || uids.includes(e.uid)) { const nub = this.findNubByUid(e.uid); if (nub instanceof internal_modules_59.Solveur) { // find targetted nubToCalculate / searchedParam const ret = nub.fixTargets(e); // forwardErrors if (ret.hasErrors) { res.hasErrors = true; } } } }); } return res; } } exports.Session = Session; //# sourceMappingURL=session.js.map