Newer
Older
import { CalculatorType, ComputeNodeType } from "./compute-node";
import { Nub } from "./nub";
import { Props, SessionNub } from "./session_nub";
// Calculettes
import { ConduiteDistrib, ConduiteDistribParams } from "./cond_distri";
import { LechaptCalmon, LechaptCalmonParams } from "./lechaptcalmon";
import { PabDimension, PabDimensionParams } from "./pab/pab_dimension";
import { PabPuissance, PabPuissanceParams } from "./pab/pab_puissance";
import { RegimeUniforme } from "./regime_uniforme";
import { CourbeRemous, CourbeRemousParams, MethodeResolution } from "./remous";
import { SectionParametree } from "./section/section_nub";
import { Cloisons, CloisonsParams } from "./structure/cloisons";
import { Dever, DeverParams } from "./structure/dever";
import { ParallelStructure, ParallelStructureParams } from "./structure/parallel_structure";
// Classes relatives aux sections
import { cSnCirc, ParamsSectionCirc } from "./section/section_circulaire";
import { cSnPuiss, ParamsSectionPuiss } from "./section/section_puissance";
import { cSnRectang, ParamsSectionRectang } from "./section/section_rectang";
import { cSnTrapez, ParamsSectionTrapez } from "./section/section_trapez";
import { acSection } from "./section/section_type";
// Classes relatives aux structures

Grand Francois
committed
import { CreateStructure } from "./structure/factory_structure";
import { Structure } from "./structure/structure";
import { LoiDebit, StructureType } from "./structure/structure_props";
public static getInstance() {
if (NubFactory._instance === undefined) {
NubFactory._instance = new NubFactory();
}
return NubFactory._instance;
}
private static _instance: NubFactory; // instance pour le pattern singleton

Grand Francois
committed
private _session: SessionNub[];

Grand Francois
committed
this._session = [];
}
public setDefaultPrecision(p: number) {
this._defaultPrecision = p;
}

Grand Francois
committed
/**
* créé un Nub et l'ajoute à la session
*/
public createSessionNub(p: Props | {}): SessionNub {

Grand Francois
committed
const res = this.newSessionNub(p);

Grand Francois
committed
this._session.push(res);
return res;
}
public findSessionNub(params: Props | {}): SessionNub {

Grand Francois
committed
return n;
}

Grand Francois
committed
/**
* remplace un SessionNub par un nouveau
* @param sn SessionNub à remplacer
* @param params propriété du nouveau SessionNub
*/
public replaceSessionNub(sn: SessionNub, params: Props): SessionNub {
let i = 0;
for (const n of this._session) {

Grand Francois
committed
const newNub = this.newSessionNub(params);
this._session[i] = newNub;
this.replaceStructureNub(sn.nub, newNub.nub);
return newNub;
}
i++;
}
// pas trouvé
return undefined;
}

Grand Francois
committed
/**
* déplace un SessionNub associé à un nub Structure d'une position vers le début de la liste de structures
* @param sn SessionNub à remplacer
* @param params propriété du nouveau SessionNub
*/
public moveStructureNubUp(sn: SessionNub) {
const psn = this.findParallelStructureWithNub(sn.nub);

Grand Francois
committed
// déplacement
if (psn) {
let i = 0;
for (const n of this._session) {
if (n.uid === sn.uid && i > 0) {
const nS: SessionNub = this._session[i - 1];

Grand Francois
committed
this._session[i - 1] = this._session[i];

Grand Francois
committed
psn.moveStructureUp(sn.nub as Structure);
return;
}
i++;
}
}
throw new Error(
`NubFactory.moveStructureNubUp() : la structure (uid ${sn.uid}) à déplacer n'a pas été trouvée`
);

Grand Francois
committed
}

Grand Francois
committed
/**
* déplace un SessionNub associé à un nub Structure d'une position vers la fin de la liste de structures
* @param sn SessionNub à remplacer
* @param params propriété du nouveau SessionNub
*/
public moveStructureNubDown(sn: SessionNub) {
const psn = this.findParallelStructureWithNub(sn.nub);
// déplacement
if (psn) {
let i = 0;
for (const n of this._session) {
if (n.uid === sn.uid && i < this._session.length - 1) {
const nS: SessionNub = this._session[i];

Grand Francois
committed
this._session[i] = this._session[i + 1];

Grand Francois
committed
psn.moveStructureDown(sn.nub as Structure);
return;
}
i++;
}
}
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
throw new Error(
`NubFactory.moveStructureNubDown() : la structure (uid ${sn.uid}) à déplacer n'a pas été trouvée`
);
}
public deleteSessionNub(sn: SessionNub) {
let i = 0;
for (const n of this._session) {
if (n.uid === sn.uid) {
this._session.splice(i, 1);
this.deleteStructureNub(sn.nub);
return;
}
i++;
}
throw new Error(`NubFactory.deleteSessionNub() : le SessionNub (uid ${sn.uid}) à supprimer n'a pas été trouvé`);
}
private newSessionNub(p: Props | {}): SessionNub {
const params = p instanceof Props ? p : new Props(p);
const nub = this.createNub(params);
return new SessionNub(nub, params);
}
private replaceStructureNub(oldNub: Nub, newNub: Nub) {
const b1 = oldNub instanceof Structure;
const b2 = newNub instanceof Structure;
if ((b1 && !b2) || (!b1 && b2)) {
throw new Error(
`NubFactory.replaceStructureNub() : arguments incorrects (${typeof (oldNub)}/${typeof (newNub)}`
);
}
if (b1 && b2) {
for (const sn of this._session) {
if (sn.nub instanceof ParallelStructure) {
const psn = sn.nub as ParallelStructure;
let i = 0;
for (const st of psn.structures) {
if (st.uid === oldNub.uid) {
psn.replaceStructure(i, newNub as Structure);
return;
}
i++;
}
}
}
throw new Error(
`NubFactory.replaceStructureNub() : la structure (uid ${oldNub.uid}) à remplacer n'a pas été trouvée`
);
}
// copie (dans la mesure du possible) des modes de valeur des paramètres
for (const p of newNub.parameters) {
try {
const p2 = oldNub.getParameter(p.symbol);
p.valueMode = p2.valueMode;
} catch (e) {
// ???
}
}
}
private deleteStructureNub(n: Nub) {
if (n instanceof Structure) {
for (const sn of this._session) {
if (sn.nub instanceof ParallelStructure) {
const psn = sn.nub as ParallelStructure;
let i = 0;
for (const st of psn.structures) {
if (st.uid === n.uid) {
psn.deleteStructure(i);
return;
}
i++;
}
}
}
throw new Error(
`NubFactory.deleteStructureNub() : la structure (uid ${n.uid}) à supprimer n'a pas été trouvée`
);
}
}
/**
* recherche du nub ouvrages parallèles possédant l'ouvrage donné
*/
private findParallelStructureWithNub(n: Nub) {
for (const s of this._session) {
if (s.nub instanceof ParallelStructure) {
const res = s.nub as ParallelStructure;
if (res.hasStructure(n)) {
return res;
}
}
}
return undefined;

Grand Francois
committed
}
/**
* créé un Nub
* @param calcType type de Nub
* @param nodeType sous type de Nub
* @param params paramètres supplémentaires spécifiques
*/

Grand Francois
committed
private createNub(params: Props): Nub {
const calcType: CalculatorType = params.getPropValue("calcType");
const nodeType: ComputeNodeType = params.getPropValue("nodeType");
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
switch (calcType) {
case CalculatorType.ConduiteDistributrice:
{
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
1e-6, // Viscosité dynamique Nu
);
return new ConduiteDistrib(prms);
}
case CalculatorType.LechaptCalmon:
{
const prms = new LechaptCalmonParams(3, // débit
1.2, // diamètre
0.6, /// perte de charge
100, // longueur du toyo
1.863, // paramètre L du matériau
2, // paramètre M du matériau
5.33// paramètre N du matériau
);
return new LechaptCalmon(prms);
}
case CalculatorType.SectionParametree:
return new SectionParametree(this.createSection(nodeType));
case CalculatorType.RegimeUniforme:
const sect: acSection = this.createSection(nodeType);
const ru = new RegimeUniforme(sect);
return ru;
case CalculatorType.CourbeRemous:
{
const sectCR: acSection = this.createSection(nodeType);
const prms = new CourbeRemousParams(sectCR, 0.15, // Yamont = tirant amont
0.4, // Yaval = tirant aval
100, // Long= Longueur du bief
5, // Dx=Pas d'espace
MethodeResolution.EulerExplicite
);
return new CourbeRemous(prms);
}
case CalculatorType.PabDimensions:
{
const prms = new PabDimensionParams(
2, // Longueur L
1, // Largeur W
0.5, // Tirant d'eau Y
2 // Volume V
);
return new PabDimension(prms);
}
case CalculatorType.PabPuissance:
{
const prms = new PabPuissanceParams(
0.3, // Chute entre bassins DH (m)
0.1, // Débit Q (m3/s)
0.5, // Volume V (m3)
);
return new PabPuissance(prms);
}
case CalculatorType.Structure:

Grand Francois
committed
const structType: StructureType = params.getPropValue("structureType");
const loiDebit: LoiDebit = params.getPropValue("loiDebit");
return CreateStructure(structType, loiDebit);
case CalculatorType.ParallelStructure:
{
const prms = new ParallelStructureParams(0.5, // Q
102, // Z1
101.5 // Z2
);
return new ParallelStructure(prms);
}
case CalculatorType.Dever:
{
const prms = new DeverParams(0.5, // Q
102, // Z1
10, // BR : largeur du cours d'eau
99 // ZR : cote du lit du cours d'eau
);
return new Dever(prms);
}
case CalculatorType.Cloisons:
{
return 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)
)
);
}
throw new Error(
// tslint:disable-next-line:max-line-length
`NubFactory.createNub() : calculatrice '${CalculatorType[calcType]}' / noeud de calcul '${ComputeNodeType[nodeType]}' non pris en charge`
);
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
}
}
private createSection(nt: ComputeNodeType): acSection {
switch (nt) {
case ComputeNodeType.None: // pour les paramètres communs, n'importe quelle section convient
case ComputeNodeType.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
this._defaultPrecision, // précision
1, // YB= hauteur de berge
);
return new cSnTrapez(prms);
}
case ComputeNodeType.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
this._defaultPrecision, // précision
1 // YB=hauteur de berge
);
return new cSnRectang(prms);
}
case ComputeNodeType.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
this._defaultPrecision, // précision
1, // YB= hauteur de berge
);
return new cSnCirc(prms);
}
case ComputeNodeType.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
this._defaultPrecision, // précision
1, // YB= hauteur de berge
);
return new cSnPuiss(prms);
}
default:
throw new Error(`type de section ${ComputeNodeType[nt]} non pris en charge`);
}
}

Grand Francois
committed
// public get sessionNubIterator(): IterableIterator<SessionNub> {
// return this._session[Symbol.iterator](); // crée un itérateur à partir d'un tableau
// }