Commit 79f70324 authored by Mathias Chouet's avatar Mathias Chouet 🍝
Browse files

Fix #122 - refactored classes organization

parent bde96c93
import { MapIterator } from "../util/map_iterator";
import { ParamDefinition } from "./param-definition";
import { ParamsEquation } from "./params-equation";
export interface IParamDefinitionIterator extends IterableIterator<ParamDefinition> {
}
/**
* itérateur sur les paramètres d'une seule instance de ParamsEquation
*/
export class ParamDefinitionIterator implements IParamDefinitionIterator {
private _mapIterator: MapIterator<ParamDefinition>;
constructor(_params: ParamsEquation) {
this._mapIterator = new MapIterator(_params.map);
}
public next(): IteratorResult<ParamDefinition> {
return this._mapIterator.next();
}
public [Symbol.iterator](): IterableIterator<ParamDefinition> {
return this;
}
}
import { ComputeNode } from "../compute-node";
import { MapIterator } from "../util/iterator";
import { ParamDefinition } from "./param-definition";
import { ParamDomainValue } from "./param-domain";
export interface IParamDefinitionIterator extends IterableIterator<ParamDefinition> {
}
/**
* itérateur sur les paramètres d'une seule instance de ParamsEquation
*/
export class ParamDefinitionIterator implements IParamDefinitionIterator {
private _mapIterator: MapIterator<ParamDefinition>;
constructor(_params: ParamsEquation) {
this._mapIterator = new MapIterator(_params.map);
}
public next(): IteratorResult<ParamDefinition> {
return this._mapIterator.next();
}
public [Symbol.iterator](): IterableIterator<ParamDefinition> {
return this;
}
}
/**
* itérateur sur les paramètres d'un tableau de de ParamsEquation
*/
// tslint:disable-next-line:max-classes-per-file
export class ParamsEquationArrayIterator implements IParamDefinitionIterator {
private get done(): IteratorResult<ParamDefinition> {
return {
done: true,
value: undefined
};
}
private _paramsEqs: ParamsEquation[];
private _index: number = 0;
private _currentMapIterator: MapIterator<ParamDefinition>;
constructor(p: ParamsEquation[]) {
this._paramsEqs = p;
}
public next(): IteratorResult<ParamDefinition> {
if (this._currentMapIterator === undefined) {
this.nextIterator();
}
let res = this.done;
if (this._currentMapIterator) {
res = this._currentMapIterator.next();
if (res.done) {
this.nextIterator();
if (this._currentMapIterator) {
res = this._currentMapIterator.next();
}
}
}
return res;
}
public [Symbol.iterator](): IterableIterator<ParamDefinition> {
return this;
}
private nextIterator() {
if (this._index < this._paramsEqs.length) {
this._currentMapIterator = new MapIterator(this._paramsEqs[this._index++].map);
} else {
this._currentMapIterator = undefined;
}
}
}
import { IParamDefinitionIterator, ParamDefinitionIterator } from "./param_definition_iterator";
/**
* liste des paramètres d'une équation
*/
// tslint:disable-next-line:max-classes-per-file
export abstract class ParamsEquation implements Iterable<ParamDefinition> {
/** précision de calcul par défaut */
......
import { MapIterator } from "../util/map_iterator";
import { ParamDefinition } from "./param-definition";
import { IParamDefinitionIterator } from "./param_definition_iterator";
import { ParamsEquation } from "./params-equation";
/**
* itérateur sur les paramètres d'un tableau de de ParamsEquation
*/
export class ParamsEquationArrayIterator implements IParamDefinitionIterator {
private get done(): IteratorResult<ParamDefinition> {
return {
done: true,
value: undefined
};
}
private _paramsEqs: ParamsEquation[];
private _index: number = 0;
private _currentMapIterator: MapIterator<ParamDefinition>;
constructor(p: ParamsEquation[]) {
this._paramsEqs = p;
}
public next(): IteratorResult<ParamDefinition> {
if (this._currentMapIterator === undefined) {
this.nextIterator();
}
let res = this.done;
if (this._currentMapIterator) {
res = this._currentMapIterator.next();
if (res.done) {
this.nextIterator();
if (this._currentMapIterator) {
res = this._currentMapIterator.next();
}
}
}
return res;
}
public [Symbol.iterator](): IterableIterator<ParamDefinition> {
return this;
}
private nextIterator() {
if (this._index < this._paramsEqs.length) {
this._currentMapIterator = new MapIterator(this._paramsEqs[this._index++].map);
} else {
this._currentMapIterator = undefined;
}
}
}
import { CalculatorType } from "./compute-node";
import { ParamCalculability } from "./param/param-definition";
import { SectionNub } from "./section/section_nub";
import { SectionParams } from "./section/section_parametree";
import { SectionParams } from "./section/section_parametree_params";
import { acSection } from "./section/section_type";
import { Result } from "./util/result";
......
import { round, XOR } from "../base";
import { CalculatorType } from "../compute-node";
import { Dichotomie } from "../dichotomie";
import { ParamCalculability, ParamDefinition, ParamFamily } from "../param/param-definition";
import { ParamDomainValue } from "../param/param-domain";
import { ParamCalculability } from "../param/param-definition";
import { ParamValueMode } from "../param/param-value-mode";
import { ParamValues } from "../param/param-values";
import { ParamsEquation } from "../param/params-equation";
import { SectionNub } from "../section/section_nub";
import { acSection } from "../section/section_type";
import { cLog } from "../util/log";
......@@ -13,82 +11,16 @@ import { Message, MessageCode } from "../util/message";
import { Result } from "../util/result";
import { ResultElement } from "../util/resultelement";
import { MethodeResolution } from "./methode-resolution";
import { CourbeRemousParams } from "./remous_params";
export interface ITrYResult {
trY: { [key: number]: number; };
log: cLog;
}
/**
* paramètres pour les courbes de remous
*/
export class CourbeRemousParams extends ParamsEquation {
/**
* Débit amont
*/
// private _Qamont: ParamDefinition;
/**
* Tirant imposé à l'amont
*/
private _Yamont: ParamDefinition;
/**
* Tirant imposé à l'aval
*/
private _Yaval: ParamDefinition;
/**
* Longueur du bief
*/
private _Long: ParamDefinition;
/**
* Pas de discrétisation de l'espace (positif en partant de l'aval, négatif en partant de l'amont)
*/
private _Dx: ParamDefinition;
constructor(rYamont: number, rYAval: number, rLong: number, rDx: number) {
super();
this._Yamont = new ParamDefinition(this, "Yamont", ParamDomainValue.POS, "m", rYamont, ParamFamily.HEIGHTS);
this._Yaval = new ParamDefinition(this, "Yaval", ParamDomainValue.POS, "m", rYAval, ParamFamily.HEIGHTS);
this._Long = new ParamDefinition(this, "Long", ParamDomainValue.POS, "m", rLong, ParamFamily.LENGTHS);
this._Dx = new ParamDefinition(this, "Dx", ParamDomainValue.POS, "m", rDx);
this.addParamDefinition(this._Yamont);
this.addParamDefinition(this._Yaval);
this.addParamDefinition(this._Long);
this.addParamDefinition(this._Dx);
this.Pr.visible = true; // exception
}
public addParamDefinition(p: ParamDefinition) {
super.addParamDefinition(p);
}
get Yamont() {
return this._Yamont;
}
get Yaval() {
return this._Yaval;
}
get Long() {
return this._Long;
}
get Dx(): ParamDefinition {
return this._Dx;
}
}
/**
* Calcul d'une courbe de remous
*/
// tslint:disable-next-line:max-classes-per-file
export class CourbeRemous extends SectionNub {
[key: string]: any; // pour pouvoir faire this['methode]();
......
import { ParamDefinition, ParamFamily } from "../param/param-definition";
import { ParamDomainValue } from "../param/param-domain";
import { ParamsEquation } from "../param/params-equation";
/**
* paramètres pour les courbes de remous
*/
export class CourbeRemousParams extends ParamsEquation {
/**
* Débit amont
*/
// private _Qamont: ParamDefinition;
/**
* Tirant imposé à l'amont
*/
private _Yamont: ParamDefinition;
/**
* Tirant imposé à l'aval
*/
private _Yaval: ParamDefinition;
/**
* Longueur du bief
*/
private _Long: ParamDefinition;
/**
* Pas de discrétisation de l'espace (positif en partant de l'aval, négatif en partant de l'amont)
*/
private _Dx: ParamDefinition;
constructor(rYamont: number, rYAval: number, rLong: number, rDx: number) {
super();
this._Yamont = new ParamDefinition(this, "Yamont", ParamDomainValue.POS, "m", rYamont, ParamFamily.HEIGHTS);
this._Yaval = new ParamDefinition(this, "Yaval", ParamDomainValue.POS, "m", rYAval, ParamFamily.HEIGHTS);
this._Long = new ParamDefinition(this, "Long", ParamDomainValue.POS, "m", rLong, ParamFamily.LENGTHS);
this._Dx = new ParamDefinition(this, "Dx", ParamDomainValue.POS, "m", rDx);
this.addParamDefinition(this._Yamont);
this.addParamDefinition(this._Yaval);
this.addParamDefinition(this._Long);
this.addParamDefinition(this._Dx);
this.Pr.visible = true; // exception
}
public addParamDefinition(p: ParamDefinition) {
super.addParamDefinition(p);
}
get Yamont() {
return this._Yamont;
}
get Yaval() {
return this._Yaval;
}
get Long() {
return this._Long;
}
get Dx(): ParamDefinition {
return this._Dx;
}
}
import { Message, MessageCode } from "../util/message";
import { Result } from "../util/result";
import { acNewton } from "./newton";
import { acSection, ParamsSection } from "./section_type";
/**
* Calcul de la hauteur critique
*/
// tslint:disable-next-line:class-name
export class cHautCritique extends acNewton {
/**
* Section sur laquuelle porte le calcul
*/
// tslint:disable-next-line:variable-name
private Sn: acSection;
/**
* Constructeur de la classe
* @param Sn Section sur laquelle on fait le calcul
*/
// tslint:disable-next-line:variable-name
constructor(Sn: acSection, maxIter: number, dbg: boolean = false) {
super(Sn.prms, maxIter, dbg);
this.Sn = Sn.clone();
}
/**
* Calcul de la fonction dont on cherche le zéro
* @param rX Variable dont dépend la fonction
*/
public CalcFn(rX: number): Result {
const rS: Result = this.Sn.CalcSection("S", rX);
if (!rS.ok) {
return rS;
}
// Calcul de la fonction
// if (this.Sn.CalcSection("S", rX) !== 0)
if (rS.vCalc === 0) {
return new Result(new Message(MessageCode.ERROR_SECTION_SURFACE_NULLE));
}
// tslint:disable-next-line:max-line-length
// return (Math.pow(this.Sn.prms.Q.v, 2) * this.Sn.CalcSection("B", rX) / Math.pow(this.Sn.CalcSection("S", rX), 3) / ParamsSection.G - 1);
const rB: Result = this.Sn.CalcSection("B", rX);
if (!rB.ok) {
return rB;
}
const rS2: Result = this.Sn.CalcSection("S", rX);
if (!rS2.ok) {
return rS2;
}
const v = (Math.pow(this.Sn.prms.Q.v, 2) * rB.vCalc / Math.pow(rS2.vCalc, 3) / ParamsSection.G - 1);
return new Result(v);
// return Infinity;
}
/**
* Calcul analytique de la dérivée de la fonction dont on cherche le zéro
* @param rX Variable dont dépend la fonction
*/
public CalcDer(rX: number): Result {
// let S = this.Sn.CalcSection("S");
const rS: Result = this.Sn.CalcSection("S");
if (!rS.ok) {
return rS;
}
const S = rS.vCalc;
// if (S !== 0) {
if (S === 0) {
return new Result(new Message(MessageCode.ERROR_SECTION_SURFACE_NULLE));
}
// let B = this.Sn.CalcSection("B");
const rB: Result = this.Sn.CalcSection("B");
if (!rB.ok) {
return rB;
}
const B = rB.vCalc;
const rDB: Result = this.Sn.CalcSection("dB");
if (!rDB.ok) {
return rDB;
}
// L'initialisation à partir de rX a été faite lors de l'appel à CalcFn
// let Der = (this.Sn.CalcSection("dB") * S - 3 * B * B);
// tslint:disable-next-line:variable-name
const Der = (rDB.vCalc * S - 3 * B * B);
const v = Math.pow(this.Sn.prms.Q.v, 2) / ParamsSection.G * Der / Math.pow(S, 4);
return new Result(v);
// }
// return Infinity;
}
}
/**
* Calcul de la hauteur normale
*/
// tslint:disable-next-line:max-classes-per-file class-name
export class cHautNormale extends acNewton {
/**
* Section sur laquuelle porte le calcul
*/
// tslint:disable-next-line:variable-name
private Sn: acSection;
/**
* Débit connu
*/
private Q: number;
/**
* Coefficient de Strickler
*/
// tslint:disable-next-line:variable-name
private Ks: number;
/**
* Pente du fond
*/
// tslint:disable-next-line:variable-name
private If: number;
/**
* Constructeur de la classe
* @param oSn Section sur laquelle on fait le calcul
*/
// tslint:disable-next-line:variable-name
constructor(Sn: acSection, maxIter: number, dbg: boolean = false) {
super(Sn.prms, maxIter, dbg);
this.Sn = Sn;
this.Q = Sn.prms.Q.v;
this.Ks = Sn.prms.Ks.v;
this.If = Sn.prms.If.v;
}
/**
* Calcul de la fonction dont on cherche le zéro
* @param rX Variable dont dépend la fonction
*/
public CalcFn(rX: number): Result {
// Calcul de la fonction
// tslint:disable-next-line:max-line-length
// return (this.Q - this.Ks * Math.pow(this.Sn.CalcSection("R", rX), 2 / 3) * this.Sn.CalcSection("S", rX) * Math.sqrt(this.If));
const rR: Result = this.Sn.CalcSection("R", rX);
if (!rR.ok) {
return rR;
}
const rS: Result = this.Sn.CalcSection("S", rX);
if (!rS.ok) {
return rS;
}
const v = (this.Q - this.Ks * Math.pow(rR.vCalc, 2 / 3) * rS.vCalc * Math.sqrt(this.If));
return new Result(v);
}
/**
* Calcul analytique de la dérivée de la fonction dont on cherche le zéro
* @param rX Variable dont dépend la fonction
*/
public CalcDer(rX: number): Result {
const rDR: Result = this.Sn.CalcSection("dR");
if (!rDR.ok) {
return rDR;
}
const rR: Result = this.Sn.CalcSection("R");
if (!rR.ok) {
return rR;
}
const rS: Result = this.Sn.CalcSection("S");
if (!rS.ok) {
return rS;
}
// L'initialisation a été faite lors de l'appel à CalcFn
// let Der = 2 / 3 * this.Sn.CalcSection("dR") * Math.pow(this.Sn.CalcSection("R"), -1 / 3)
// * this.Sn.CalcSection("S");
// tslint:disable-next-line:variable-name
let Der = 2 / 3 * rDR.vCalc * Math.pow(rR.vCalc, -1 / 3) * rS.vCalc;
const rR2: Result = this.Sn.CalcSection("R");
if (!rR2.ok) {
return rR2;
}
const rB: Result = this.Sn.CalcSection("B");
if (!rB.ok) {
return rB;
}
// Der = Der + Math.pow(this.Sn.CalcSection("R"), 2 / 3) * this.Sn.CalcSection("B");
Der = Der + Math.pow(rR2.vCalc, 2 / 3) * rB.vCalc;
Der = Der * -this.Ks * Math.sqrt(this.If);
return new Result(Der);
}
}
/**
* Calcul de la hauteur correspondante (charge égale)
*/
// tslint:disable-next-line:max-classes-per-file class-name
export class cHautCorrespondante extends acNewton {
/**
* Tirant d'eau connu
*/
private Y: number;
/**
* 1/S^2 associé au tirant d'eau connu
*/
private _rS2: Result;
/**
* Section contenant les données de la section avec la hauteur à calculer
*/
// tslint:disable-next-line:variable-name
private Sn: acSection;
/**
* Constante de gravité
*/
private rQ2G: number;
/**
* Constructeur de la classe
* @param oSn Section sur laquelle on fait le calcul
*/
// tslint:disable-next-line:variable-name
constructor(Sn: acSection, maxIter: number, dbg: boolean = false) {
super(Sn.prms, maxIter, dbg);
this.Y = Sn.prms.Y.v;
// this.rS2 = Math.pow(Sn.CalcSection("S"), -2);
this.Sn = Sn;
// tslint:disable-next-line:no-unused-expression
this.rS2; // pour initialiser la valeur @WTF (utilise le getter)
this.rQ2G = Math.pow(Sn.prms.Q.v, 2) / (2 * ParamsSection.G);
}
private get rS2(): Result {
if (this._rS2 === undefined) {
const rS = this.Sn.CalcSection("S");
if (rS.ok) {
const v = Math.pow(rS.vCalc, -2);
this._rS2 = new Result(v);
} else {
this._rS2 = rS;
}
}