From c3dab5cc7c15c2bf8162ca3d4e2ef86123407207 Mon Sep 17 00:00:00 2001 From: "francois.grand" <francois.grand@irstea.fr> Date: Wed, 6 Dec 2017 10:00:40 +0100 Subject: [PATCH] =?UTF-8?q?=20-=20classe=20Result=20:=20d=C3=A9placement?= =?UTF-8?q?=20dans=20son=20fichier=20(util/result.ts)=20=20-=20classe=20Re?= =?UTF-8?q?sult=20:=20remplacement=20du=20membre=20=5Fmessage=20par=20un?= =?UTF-8?q?=20cLog=20(ensemble=20de=20Message)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/base.spec.ts | 1 - spec/cond_distri.spec.ts | 2 +- spec/lechaptcalmon.spec.ts | 2 +- spec/nubtest.ts | 3 +- .../regime_uniforme_circ.spec.ts | 2 +- .../regime_uniforme_puissance.spec.ts | 2 +- .../regime_uniforme_rect.spec.ts | 2 +- .../regime_uniforme_trapeze.spec.ts | 2 +- .../section_param_circ_fluvial.spec.ts | 2 +- .../section_param_circ_torrentiel.spec.ts | 2 +- .../section_param_puiss_fluvial.spec.ts | 2 +- .../section_param_puiss_torrentiel.spec.ts | 2 +- .../section_param_rect_conv_newton.spec.ts | 2 +- .../section_param_rect_fluvial.spec.ts | 2 +- .../section_param_rect_torrentiel.spec.ts | 2 +- .../section_param_trapez_fluvial.spec.ts | 2 +- .../section_param_trapez_torrentiel.spec.ts | 2 +- spec/structure/rectangular_structure.ts | 2 +- spec/structure/structure.spec.ts | 6 +- spec/structure/structure_cem88d.spec.ts | 2 +- spec/structure/structure_cem88v.spec.ts | 2 +- spec/structure/structure_cunge80.spec.ts | 2 +- spec/structure/structure_orifice_free.spec.ts | 2 +- .../structure_orifice_submerged.spec.ts | 2 +- spec/structure/structure_weir_free.spec.ts | 2 +- spec/structure/test_rectangular_structure.ts | 2 +- spec/structure/test_structure_cem88d.ts | 2 +- spec/structure/test_structure_cem88v.ts | 2 +- spec/structure/test_structure_cunge80.ts | 2 +- src/base.ts | 36 ----------- src/cond_distri.ts | 2 +- src/dichotomie.ts | 6 +- src/lechaptcalmon.ts | 2 +- src/nub.ts | 3 +- src/regime_uniforme.ts | 4 +- src/remous.ts | 39 +++++++----- src/structure/structure.ts | 17 ++--- src/structure/structure_cem88d.ts | 16 ++--- src/structure/structure_cem88v.ts | 28 +++++---- src/structure/structure_cunge80.ts | 32 +++++----- src/structure/structure_orifice_free.ts | 13 ++-- src/structure/structure_orifice_submerged.ts | 13 ++-- src/structure/structure_params.ts | 2 +- src/structure/structure_weir_free.ts | 15 +++-- src/util/result.ts | 62 +++++++++++++++++++ 45 files changed, 201 insertions(+), 151 deletions(-) create mode 100644 src/util/result.ts diff --git a/spec/base.spec.ts b/spec/base.spec.ts index 17f37c3f..1c61ec68 100644 --- a/spec/base.spec.ts +++ b/spec/base.spec.ts @@ -1,6 +1,5 @@ /// <reference path="../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../src/base"; import { nub, precDigits } from "./nubtest"; import { Message, MessageCode, MessageSeverity } from "../src/util/message"; diff --git a/spec/cond_distri.spec.ts b/spec/cond_distri.spec.ts index 5b5c9f93..fc6fe224 100644 --- a/spec/cond_distri.spec.ts +++ b/spec/cond_distri.spec.ts @@ -1,7 +1,7 @@ // tslint:disable-next-line:no-reference /// <reference path="../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../src/base"; +import { Result } from "../src/util/result"; import { ConduiteDistrib, ConduiteDistribParams } from "../src/cond_distri"; import { equalEpsilon } from "./nubtest"; diff --git a/spec/lechaptcalmon.spec.ts b/spec/lechaptcalmon.spec.ts index 8c1d7470..076c66e1 100644 --- a/spec/lechaptcalmon.spec.ts +++ b/spec/lechaptcalmon.spec.ts @@ -1,6 +1,6 @@ /// <reference path="../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../src/base"; +import { Result } from "../src/util/result"; import { equalEpsilon } from "./nubtest"; import { LechaptCalmonParams, LechaptCalmon } from "../src/lechaptcalmon" diff --git a/spec/nubtest.ts b/spec/nubtest.ts index ce4b3e7c..62f0e9c6 100644 --- a/spec/nubtest.ts +++ b/spec/nubtest.ts @@ -1,4 +1,4 @@ -import { Result } from "../src/base"; +import { Result } from "../src/util/result"; import { Nub } from "../src/nub"; import { ComputeNodeType, ParamCalculability, ParamDefinition, ParamDomain, ParamDomainValue, ParamsEquation, @@ -57,7 +57,6 @@ export class NubTest extends Nub { } export let nub = new NubTest(new NubTestParams()); -// export let res = new Result(0); /** * précision de calcul (nombre de décimales) diff --git a/spec/regime_uniforme/regime_uniforme_circ.spec.ts b/spec/regime_uniforme/regime_uniforme_circ.spec.ts index 228ff02e..720976c2 100644 --- a/spec/regime_uniforme/regime_uniforme_circ.spec.ts +++ b/spec/regime_uniforme/regime_uniforme_circ.spec.ts @@ -1,7 +1,7 @@ // tslint:disable-next-line:no-reference /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { RegimeUniforme } from "../../src/regime_uniforme"; import { cSnCirc, ParamsSectionCirc } from "../../src/section/section_circulaire"; import { equalEpsilon, precDist } from "../nubtest"; diff --git a/spec/regime_uniforme/regime_uniforme_puissance.spec.ts b/spec/regime_uniforme/regime_uniforme_puissance.spec.ts index 092b21a5..54c9221e 100644 --- a/spec/regime_uniforme/regime_uniforme_puissance.spec.ts +++ b/spec/regime_uniforme/regime_uniforme_puissance.spec.ts @@ -1,7 +1,7 @@ // tslint:disable-next-line:no-reference /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { RegimeUniforme } from "../../src/regime_uniforme"; import { cSnPuiss, ParamsSectionPuiss } from "../../src/section/section_puissance"; import { MessageCode } from "../../src/util/message"; diff --git a/spec/regime_uniforme/regime_uniforme_rect.spec.ts b/spec/regime_uniforme/regime_uniforme_rect.spec.ts index bae4b078..bf8c7b37 100644 --- a/spec/regime_uniforme/regime_uniforme_rect.spec.ts +++ b/spec/regime_uniforme/regime_uniforme_rect.spec.ts @@ -1,7 +1,7 @@ // tslint:disable-next-line:no-reference /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { RegimeUniforme } from "../../src/regime_uniforme"; import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rectang"; import { equalEpsilon, precDist } from "../nubtest"; diff --git a/spec/regime_uniforme/regime_uniforme_trapeze.spec.ts b/spec/regime_uniforme/regime_uniforme_trapeze.spec.ts index 479d3567..7bf9f878 100644 --- a/spec/regime_uniforme/regime_uniforme_trapeze.spec.ts +++ b/spec/regime_uniforme/regime_uniforme_trapeze.spec.ts @@ -1,7 +1,7 @@ // tslint:disable-next-line:no-reference /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { RegimeUniforme } from "../../src/regime_uniforme"; import { cSnTrapez, ParamsSectionTrapez } from "../../src/section/section_trapez"; import { equalEpsilon, precDist } from "../nubtest"; diff --git a/spec/section_param/section_param_circ_fluvial.spec.ts b/spec/section_param/section_param_circ_fluvial.spec.ts index e214367d..50c651bb 100644 --- a/spec/section_param/section_param_circ_fluvial.spec.ts +++ b/spec/section_param/section_param_circ_fluvial.spec.ts @@ -1,4 +1,4 @@ -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { cSnCirc, ParamsSectionCirc } from "../../src/section/section_circulaire"; import { equalEpsilon, precDist } from "../nubtest"; diff --git a/spec/section_param/section_param_circ_torrentiel.spec.ts b/spec/section_param/section_param_circ_torrentiel.spec.ts index a658912f..917eb5e3 100644 --- a/spec/section_param/section_param_circ_torrentiel.spec.ts +++ b/spec/section_param/section_param_circ_torrentiel.spec.ts @@ -1,4 +1,4 @@ -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { cSnCirc, ParamsSectionCirc } from "../../src/section/section_circulaire"; import { equalEpsilon, precDist } from "../nubtest"; diff --git a/spec/section_param/section_param_puiss_fluvial.spec.ts b/spec/section_param/section_param_puiss_fluvial.spec.ts index 96a4d964..5b5df722 100644 --- a/spec/section_param/section_param_puiss_fluvial.spec.ts +++ b/spec/section_param/section_param_puiss_fluvial.spec.ts @@ -1,4 +1,4 @@ -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { cSnPuiss, ParamsSectionPuiss } from "../../src/section/section_puissance"; import { equalEpsilon, precDist } from "../nubtest"; diff --git a/spec/section_param/section_param_puiss_torrentiel.spec.ts b/spec/section_param/section_param_puiss_torrentiel.spec.ts index 65d0e12a..6cc2be4a 100644 --- a/spec/section_param/section_param_puiss_torrentiel.spec.ts +++ b/spec/section_param/section_param_puiss_torrentiel.spec.ts @@ -1,4 +1,4 @@ -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { cSnPuiss, ParamsSectionPuiss } from "../../src/section/section_puissance"; import { equalEpsilon, precDist } from "../nubtest"; diff --git a/spec/section_param/section_param_rect_conv_newton.spec.ts b/spec/section_param/section_param_rect_conv_newton.spec.ts index fad04b03..1d0fc9c5 100644 --- a/spec/section_param/section_param_rect_conv_newton.spec.ts +++ b/spec/section_param/section_param_rect_conv_newton.spec.ts @@ -1,5 +1,5 @@ // tslint:disable:no-console -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rectang"; import { MessageCode } from "../../src/util/message"; import { equalEpsilon, precDist } from "../nubtest"; diff --git a/spec/section_param/section_param_rect_fluvial.spec.ts b/spec/section_param/section_param_rect_fluvial.spec.ts index 5ed19701..8ae7cca9 100644 --- a/spec/section_param/section_param_rect_fluvial.spec.ts +++ b/spec/section_param/section_param_rect_fluvial.spec.ts @@ -1,4 +1,4 @@ -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rectang"; import { equalEpsilon, precDist } from "../nubtest"; diff --git a/spec/section_param/section_param_rect_torrentiel.spec.ts b/spec/section_param/section_param_rect_torrentiel.spec.ts index b225406a..a5e7e374 100644 --- a/spec/section_param/section_param_rect_torrentiel.spec.ts +++ b/spec/section_param/section_param_rect_torrentiel.spec.ts @@ -1,4 +1,4 @@ -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { cSnRectang, ParamsSectionRectang } from "../../src/section/section_rectang"; import { equalEpsilon, precDist } from "../nubtest"; diff --git a/spec/section_param/section_param_trapez_fluvial.spec.ts b/spec/section_param/section_param_trapez_fluvial.spec.ts index 086028bc..f2095057 100644 --- a/spec/section_param/section_param_trapez_fluvial.spec.ts +++ b/spec/section_param/section_param_trapez_fluvial.spec.ts @@ -1,4 +1,4 @@ -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { cSnTrapez, ParamsSectionTrapez } from "../../src/section/section_trapez"; import { equalEpsilon, precDist } from "../nubtest"; diff --git a/spec/section_param/section_param_trapez_torrentiel.spec.ts b/spec/section_param/section_param_trapez_torrentiel.spec.ts index 2b0cc47a..2b033272 100644 --- a/spec/section_param/section_param_trapez_torrentiel.spec.ts +++ b/spec/section_param/section_param_trapez_torrentiel.spec.ts @@ -1,4 +1,4 @@ -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { cSnTrapez, ParamsSectionTrapez } from "../../src/section/section_trapez"; import { equalEpsilon, precDist } from "../nubtest"; diff --git a/spec/structure/rectangular_structure.ts b/spec/structure/rectangular_structure.ts index 34b3b6ae..deee5285 100644 --- a/spec/structure/rectangular_structure.ts +++ b/spec/structure/rectangular_structure.ts @@ -1,7 +1,7 @@ // tslint:disable-next-line:no-reference /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { RectangularStructure } from "../../src/structure/rectangular_structure"; import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; import { precDigits } from "../nubtest"; diff --git a/spec/structure/structure.spec.ts b/spec/structure/structure.spec.ts index 4f0ba77c..575f9586 100644 --- a/spec/structure/structure.spec.ts +++ b/spec/structure/structure.spec.ts @@ -1,8 +1,8 @@ // tslint:disable-next-line:no-reference /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../../src/base"; -import { Structure, StructureFlowMode, StructureFlowRegime, StructureParams} from "../../src/structure/structure"; +import { Result } from "../../src/util/result"; +import { Structure, StructureFlowMode, StructureFlowRegime, StructureParams } from "../../src/structure/structure"; import { equalEpsilon } from "../nubtest"; function check(val1: Result, val2: number) { @@ -35,7 +35,7 @@ class StructureTest extends Structure { case "Q": v = this.prms.h1.v - this.prms.h2.v; break; - default: + default: throw new Error("StructureTest.Equation() : invalid parameter name " + sVarCalc); } return new Result(v); diff --git a/spec/structure/structure_cem88d.spec.ts b/spec/structure/structure_cem88d.spec.ts index 1be7f28a..bae6c610 100644 --- a/spec/structure/structure_cem88d.spec.ts +++ b/spec/structure/structure_cem88d.spec.ts @@ -1,7 +1,7 @@ // tslint:disable-next-line:no-reference /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params"; import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; import { StructureCem88d } from "../../src/structure/structure_cem88d"; diff --git a/spec/structure/structure_cem88v.spec.ts b/spec/structure/structure_cem88v.spec.ts index c2b3d1da..0ab80754 100644 --- a/spec/structure/structure_cem88v.spec.ts +++ b/spec/structure/structure_cem88v.spec.ts @@ -1,7 +1,7 @@ // tslint:disable-next-line:no-reference /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params"; import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; import { StructureCem88v } from "../../src/structure/structure_cem88v"; diff --git a/spec/structure/structure_cunge80.spec.ts b/spec/structure/structure_cunge80.spec.ts index 69cb47d9..8e4bc032 100644 --- a/spec/structure/structure_cunge80.spec.ts +++ b/spec/structure/structure_cunge80.spec.ts @@ -1,7 +1,7 @@ // tslint:disable-next-line:no-reference /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params"; import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; import { StructureCunge80 } from "../../src/structure/structure_cunge80"; diff --git a/spec/structure/structure_orifice_free.spec.ts b/spec/structure/structure_orifice_free.spec.ts index db51c1ec..44e1a7c3 100644 --- a/spec/structure/structure_orifice_free.spec.ts +++ b/spec/structure/structure_orifice_free.spec.ts @@ -1,7 +1,7 @@ // tslint:disable-next-line:no-reference /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params"; import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; import { StructureOrificeFree } from "../../src/structure/structure_orifice_free"; diff --git a/spec/structure/structure_orifice_submerged.spec.ts b/spec/structure/structure_orifice_submerged.spec.ts index 050bd6a7..bf4cd9e8 100644 --- a/spec/structure/structure_orifice_submerged.spec.ts +++ b/spec/structure/structure_orifice_submerged.spec.ts @@ -1,7 +1,7 @@ // tslint:disable-next-line:no-reference /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params"; import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; import { StructureOrificeSubmerged } from "../../src/structure/structure_orifice_submerged"; diff --git a/spec/structure/structure_weir_free.spec.ts b/spec/structure/structure_weir_free.spec.ts index 9a75c2d0..1aa66d3a 100644 --- a/spec/structure/structure_weir_free.spec.ts +++ b/spec/structure/structure_weir_free.spec.ts @@ -1,7 +1,7 @@ // tslint:disable-next-line:no-reference /// <reference path="../../node_modules/@types/jasmine/index.d.ts" /> -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params"; import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; import { StructureWeirFree } from "../../src/structure/structure_weir_free"; diff --git a/spec/structure/test_rectangular_structure.ts b/spec/structure/test_rectangular_structure.ts index 9b7b60bd..11844263 100644 --- a/spec/structure/test_rectangular_structure.ts +++ b/spec/structure/test_rectangular_structure.ts @@ -1,4 +1,4 @@ -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { RectangularStructure } from "../../src/structure/rectangular_structure"; import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; import { expect, it } from "../mock_jasmine"; diff --git a/spec/structure/test_structure_cem88d.ts b/spec/structure/test_structure_cem88d.ts index 92c67471..0e005407 100644 --- a/spec/structure/test_structure_cem88d.ts +++ b/spec/structure/test_structure_cem88d.ts @@ -1,4 +1,4 @@ -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { RectangularStructureParams, StructureCem88d } from "../../src/structure/structure_cem88d"; import { describe, xdescribe } from "../mock_jasmine"; import { precDigits } from "../nubtest"; diff --git a/spec/structure/test_structure_cem88v.ts b/spec/structure/test_structure_cem88v.ts index 20acbfae..c1be649b 100644 --- a/spec/structure/test_structure_cem88v.ts +++ b/spec/structure/test_structure_cem88v.ts @@ -1,4 +1,4 @@ -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { RectangularStructureParams, StructureCem88v } from "../../src/structure/structure_cem88v"; import { describe, xdescribe } from "../mock_jasmine"; import { precDigits } from "../nubtest"; diff --git a/spec/structure/test_structure_cunge80.ts b/spec/structure/test_structure_cunge80.ts index 7cc5df7c..60d79418 100644 --- a/spec/structure/test_structure_cunge80.ts +++ b/spec/structure/test_structure_cunge80.ts @@ -1,4 +1,4 @@ -import { Result } from "../../src/base"; +import { Result } from "../../src/util/result"; import { RectangularStructureParams } from "../../src/structure/rectangular_structure_params"; import { StructureFlowMode, StructureFlowRegime } from "../../src/structure/structure"; import { StructureCunge80 } from "../../src/structure/structure_cunge80"; diff --git a/src/base.ts b/src/base.ts index ad55b28f..4365b942 100644 --- a/src/base.ts +++ b/src/base.ts @@ -1,39 +1,3 @@ -import { Message, MessageCode } from "./util/message"; - -/** - * Résultat de calcul comprenant la valeur du résultat et des calculs annexes (flag, calculs intermédiaires...) - */ -export class Result { - - /** Calculs intermédiaires ou supplémentaires, flags de calcul */ - public extraVar: { [key: string]: any }; - - /** Valeur calculée */ - public vCalc: number; - - private _message: Message; - - /** - * Résultat de calcul - * @param v Valeur numérique du résultat - * @param m Message d'erreur - * @param e Calculs intermédiaires ou supplémentaires, flags de calcul - */ - constructor(v: number, e?: { [key: string]: any }, m?: Message) { - this.vCalc = v; - this.extraVar = e; - this._message = m; - } - - get code() { - if (this._message == undefined) - return MessageCode.ERROR_OK; - return this._message.code; - } - - get Message() { return this._message; } -} - /** * Série de valeurs à calculer définie par le nom de la variable à sérier et le vecteur de valeur */ diff --git a/src/cond_distri.ts b/src/cond_distri.ts index d27d43bb..6ab4a1f2 100644 --- a/src/cond_distri.ts +++ b/src/cond_distri.ts @@ -1,4 +1,4 @@ -import { Result } from "./base"; +import { Result } from "./util/result"; import { ComputeNodeType, ParamDefinition, ParamDomain, ParamDomainValue, ParamCalculability, ParamsEquation } from "./param"; import { Nub } from "./nub"; diff --git a/src/dichotomie.ts b/src/dichotomie.ts index d02fd2a0..49e85018 100644 --- a/src/dichotomie.ts +++ b/src/dichotomie.ts @@ -1,5 +1,6 @@ // import { XOR, BoolIdentity, Debug, Result, ResultCode, UndefinedError } from "./base"; -import { XOR, BoolIdentity, Debug, Result } from "./base"; +import { XOR, BoolIdentity, Debug } from "./base"; +import { Result } from "./util/result"; import { Message, MessageCode } from "./util/message"; import { Nub } from "./nub"; import { ParamDefinition, ParamDomain, ParamDomainValue } from "./param" @@ -461,8 +462,7 @@ export class Dichotomie extends Debug { if (r.ok) var interv: SearchInterval = r.intSearch; else { - let result = new Result(undefined, undefined, r.res); - return result; + return new Result(r.res); } // Dichotomie diff --git a/src/lechaptcalmon.ts b/src/lechaptcalmon.ts index c7a8a635..39dd48c8 100644 --- a/src/lechaptcalmon.ts +++ b/src/lechaptcalmon.ts @@ -1,4 +1,4 @@ -import { Result } from "./base"; +import { Result } from "./util/result"; import { ComputeNodeType, ParamDefinition, ParamDomain, ParamDomainValue, ParamCalculability, ParamsEquation } from "./param"; import { Nub } from "./nub"; diff --git a/src/nub.ts b/src/nub.ts index bb30a00a..d3822c3a 100644 --- a/src/nub.ts +++ b/src/nub.ts @@ -1,4 +1,5 @@ -import { Debug, Result, Serie } from "./base" +import { Debug, Serie } from "./base" +import { Result } from "./util/result"; import { Dichotomie } from "./dichotomie" import { ComputeNode, ParamDefinition, ParamsEquation } from "./param" diff --git a/src/regime_uniforme.ts b/src/regime_uniforme.ts index 1692c59f..5582c5e6 100644 --- a/src/regime_uniforme.ts +++ b/src/regime_uniforme.ts @@ -1,4 +1,4 @@ -import { Result } from "./base"; +import { Result } from "./util/result"; import { Nub } from "./nub"; import { ParamsSection, acSection } from "./section/section_type"; import { ParamDefinition, ParamCalculability } from "./param" @@ -54,4 +54,4 @@ export class RegimeUniforme extends Nub { return new Result(v); } -} \ No newline at end of file +} diff --git a/src/remous.ts b/src/remous.ts index de53b50c..ff305273 100644 --- a/src/remous.ts +++ b/src/remous.ts @@ -1,5 +1,6 @@ import { ParamsSection, acSection } from "./section/section_type"; -import { XOR, Result, round } from "./base"; +import { XOR, round } from "./base"; +import { Result } from "./util/result"; import { ParamsEquation, ParamDefinition, ParamCalculability, ComputeNodeType, ParamDomainValue } from "./param"; import { Dichotomie } from "./dichotomie"; import { Nub } from "./nub"; @@ -168,8 +169,9 @@ export class CourbeRemous extends Nub { private Calc_Y_EulerExplicite(Y: number): Result { // L'appel à Calc('J') avec Y en paramètre réinitialise toutes les données dépendantes de la ligne d'eau let Y2 = Y + this.Dx * this.Calc_dYdX(Y); - if (XOR(this.Dx > 0, !(Y2 < this.Sn.HautCritique))) - return new Result(undefined, new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE)); + if (XOR(this.Dx > 0, !(Y2 < this.Sn.HautCritique))) { + return new Result(new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE)); + } return new Result(Y2); } @@ -189,22 +191,25 @@ export class CourbeRemous extends Nub { let hc = this.Sn.HautCritique; //if ($this ->rDx > 0 xor !($Y + $rDx / 2 * $rk1 < $this ->oSect ->rHautCritique)) { return false; } - if (XOR(Dx > 0, !(Y + Dx / 2 * k1 < hc))) - return new Result(undefined, new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE)); + if (XOR(Dx > 0, !(Y + Dx / 2 * k1 < hc))) { + return new Result(new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE)); + } //$rk2 = $this ->Calc_dYdX($Y + $rDx / 2 * $rk1); let k2 = this.Calc_dYdX(Y + Dx / 2 * k1); //if ($this ->rDx > 0 xor !($Y + $rDx / 2 * $rk2 < $this ->oSect ->rHautCritique)) { return false; } - if (XOR(Dx > 0, !(Y + Dx / 2 * k2 < hc))) - return new Result(undefined, new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE)); + if (XOR(Dx > 0, !(Y + Dx / 2 * k2 < hc))) { + return new Result(new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE)); + } //$rk3 = $this ->Calc_dYdX($Y + $rDx / 2 * $rk2); let k3 = this.Calc_dYdX(Y + Dx / 2 * k2); //if ($this ->rDx > 0 xor !($Y + $rDx / 2 * $rk3 < $this ->oSect ->rHautCritique)) { return false; } - if (XOR(Dx > 0, !(Y + Dx / 2 * k3 < hc))) - return new Result(undefined, new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE)); + if (XOR(Dx > 0, !(Y + Dx / 2 * k3 < hc))) { + return new Result(new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE)); + } //$rk4 = $this ->Calc_dYdX($Y + $rDx * $rk3); let k4 = this.Calc_dYdX(Y + Dx * k3); @@ -213,8 +218,9 @@ export class CourbeRemous extends Nub { let Yout = Y + Dx / 6 * (k1 + 2 * (k2 + k3) + k4); //if ($this ->rDx > 0 xor !($Yout < $this ->oSect ->rHautCritique)) { return false; } - if (XOR(Dx > 0, !(Yout < hc))) - return new Result(undefined, new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE)); + if (XOR(Dx > 0, !(Yout < hc))) { + let res = new Result(new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE)); + } return new Result(Yout); } @@ -254,13 +260,14 @@ export class CourbeRemous extends Nub { let r: Result = Dicho.Dichotomie(Trapez_Fn, this.prmSect.Prec.v, Y); // if ($flag < 0) { - if (r.code != MessageCode.ERROR_OK) + if (!r.ok) return r; let Y2 = r.vCalc; // } elseif($this ->rDx > 0 xor !($Y2 < $this ->oSect ->rHautCritique)) { - if (XOR(this.Dx > 0, !(Y2 < this.Sn.HautCritique))) - return new Result(undefined, new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE)); + if (XOR(this.Dx > 0, !(Y2 < this.Sn.HautCritique))) { + return new Result(new Message(MessageCode.ERROR_REMOUS_ARRET_CRITIQUE)); + } return new Result(Y2); } @@ -337,7 +344,7 @@ export class CourbeRemous extends Nub { // this.debug("end trY " + this.last(trY)); // this.debug("Yn " + this.Sn.HautNormale); - if (rY.code == MessageCode.ERROR_OK) { + if (rY.ok) { // on vérifie qu'on ne traverse pas la hauteur normale (à la précision de calcul près) let prec: number = this.prms.map.Prec.v; let b1: boolean = lastY - this.Sn.HautNormale > prec; @@ -689,4 +696,4 @@ export class CourbeRemous extends Nub { return { "flu": crbFlu, "tor": crbTor, "trX": trX, "tRes": tRes }; } -} \ No newline at end of file +} diff --git a/src/structure/structure.ts b/src/structure/structure.ts index f1254a47..c9f43ae1 100644 --- a/src/structure/structure.ts +++ b/src/structure/structure.ts @@ -1,4 +1,4 @@ -import { Result } from "../base"; +import { Result } from "../util/result"; import { Nub } from "../nub"; import { ParamCalculability } from "../param"; import { Message } from "../util/message"; @@ -55,12 +55,13 @@ export abstract class Structure extends Nub { /** * Calcul du mode et du régime d'écoulement */ - public Equation(sVarCalc: string): Result { - this.CheckEquation(sVarCalc); - const res: Result = new Result(undefined, { - Mode: this.getFlowMode(), - Regime: this.getFlowRegime()}); - return res; + public abstract Equation(sVarCalc: string): Result; + + protected defaultResultData() { + return { + Mode: this.getFlowMode(), + Regime: this.getFlowRegime() + }; } /** @@ -161,7 +162,7 @@ export abstract class Structure extends Nub { /** * Test générique si VarCalc="Q" pour l'utilisation de Equation */ - private CheckEquation(sVarCalc: string) { + protected CheckEquation(sVarCalc: string) { if (sVarCalc !== "Q") { throw new Error("Structure.Equation() : invalid parameter name " + sVarCalc); } } } diff --git a/src/structure/structure_cem88d.ts b/src/structure/structure_cem88d.ts index 8ddde874..345e6825 100644 --- a/src/structure/structure_cem88d.ts +++ b/src/structure/structure_cem88d.ts @@ -1,4 +1,4 @@ -import { Result } from "../base"; +import { Result } from "../util/result"; import { RectangularStructure } from "./rectangular_structure"; import { RectangularStructureParams } from "./rectangular_structure_params"; import { Structure, StructureFlowMode, StructureFlowRegime } from "./structure"; @@ -15,16 +15,18 @@ export class StructureCem88d extends RectangularStructure { * @param sVarCalc Variable à calculer (doit être "Q") */ public Equation(sVarCalc: string): Result { - const res: Result = super.Equation(sVarCalc); + super.CheckEquation(sVarCalc); + const data = super.defaultResultData(); + let v: number; const cd: number = this.prms.Cd.v * this.prms.L.v * Structure.R2G; const b1: number = Math.sqrt(this.prms.h1.v); const b2: number = Math.sqrt(this.prms.h1.v - this.prms.h2.v); const cd1: number = cd * 2.5981; // cd * 3*sqrt(3)/2 this.debug("StructureCem88d.Equation b1=" + b1 + " b2=" + b2 + " cd1=" + cd1); - switch (res.extraVar.Mode) { + switch (data.Mode) { case StructureFlowMode.WEIR: - switch (res.extraVar.Regime) { + switch (data.Regime) { case StructureFlowRegime.FREE: v = cd * this.prms.h1.v * b1; break; @@ -36,7 +38,7 @@ export class StructureCem88d extends RectangularStructure { break; case StructureFlowMode.ORIFICE: const b3: number = Math.pow(this.prms.h1.v - this.prms.W.v, 1.5); - switch (res.extraVar.Regime) { + switch (data.Regime) { case StructureFlowRegime.FREE: v = cd * (this.prms.h1.v * b1 - b3); break; @@ -52,7 +54,7 @@ export class StructureCem88d extends RectangularStructure { this.debug( "StructureCem88d.Equation(h1=" + this.prms.h1.v + ",h2=" + this.prms.h2.v + ",W=" + this.prms.W.v + ") => Q=" + v); - res.vCalc = v; - return res; + + return new Result(v, data); } } diff --git a/src/structure/structure_cem88v.ts b/src/structure/structure_cem88v.ts index 457f4300..cef783f7 100644 --- a/src/structure/structure_cem88v.ts +++ b/src/structure/structure_cem88v.ts @@ -1,4 +1,4 @@ -import { Result } from "../base"; +import { Result } from "../util/result"; import { RectangularStructure } from "./rectangular_structure"; import { RectangularStructureParams } from "./rectangular_structure_params"; import { Structure, StructureFlowMode, StructureFlowRegime } from "./structure"; @@ -15,17 +15,19 @@ export class StructureCem88v extends RectangularStructure { * @param sVarCalc Variable à calculer (doit être "Q") */ public Equation(sVarCalc: string): Result { - const res: Result = super.Equation(sVarCalc); + super.CheckEquation(sVarCalc); + const data = super.defaultResultData(); + let v: number; const mu0: number = 2 / 3 * this.prms.Cd.v; let KF: number; - if (res.extraVar.Regime !== StructureFlowRegime.FREE) { - KF = this.getKF(Math.sqrt( 1 - this.prms.h2.v / this.prms.h1.v), this.getAlfa(this.prms.h2.v)); + if (data.Regime !== StructureFlowRegime.FREE) { + KF = this.getKF(Math.sqrt(1 - this.prms.h2.v / this.prms.h1.v), this.getAlfa(this.prms.h2.v)); } - switch (res.extraVar.Mode) { + switch (data.Mode) { case StructureFlowMode.WEIR: const muf: number = mu0 - 0.08; - switch (res.extraVar.Regime) { + switch (data.Regime) { case StructureFlowRegime.FREE: v = muf * this.prms.L.v * Structure.R2G * Math.pow(this.prms.h1.v, 1.5); break; @@ -36,21 +38,21 @@ export class StructureCem88v extends RectangularStructure { } break; case StructureFlowMode.ORIFICE: - const mu: number = mu0 - 0.08 / (this.prms.h1.v / this.prms.W.v); + const mu: number = mu0 - 0.08 / (this.prms.h1.v / this.prms.W.v); const mu1: number = mu0 - 0.08 / (this.prms.h1.v / this.prms.W.v - 1); - if (res.extraVar.Regime === StructureFlowRegime.FREE) { + if (data.Regime === StructureFlowRegime.FREE) { v = this.prms.L.v * Structure.R2G * (mu * Math.pow(this.prms.h1.v, 1.5) - - mu1 * Math.pow(this.prms.h1.v - this.prms.W.v, 1.5)); + - mu1 * Math.pow(this.prms.h1.v - this.prms.W.v, 1.5)); } else { - if (res.extraVar.Regime === StructureFlowRegime.PARTIAL) { + if (data.Regime === StructureFlowRegime.PARTIAL) { v = this.prms.L.v * Structure.R2G * ( KF * mu * Math.pow(this.prms.h1.v, 1.5) - mu1 * Math.pow(this.prms.h1.v - this.prms.W.v, 1.5) ); } else { const KF1 = this.getKF( - Math.sqrt( 1 - (this.prms.h2.v - this.prms.W.v) / (this.prms.h1.v - this.prms.W.v)), + Math.sqrt(1 - (this.prms.h2.v - this.prms.W.v) / (this.prms.h1.v - this.prms.W.v)), this.getAlfa(this.prms.h2.v - this.prms.W.v), ); v = this.prms.L.v * Structure.R2G * ( @@ -63,8 +65,8 @@ export class StructureCem88v extends RectangularStructure { this.debug( "StructureCem88v.Equation(h1=" + this.prms.h1.v + ",h2=" + this.prms.h2.v + ",W=" + this.prms.W.v + ") => Q=" + v); - res.vCalc = v; - return res; + + return new Result(v, data); } /** diff --git a/src/structure/structure_cunge80.ts b/src/structure/structure_cunge80.ts index d9cc8f44..bc8b05c4 100644 --- a/src/structure/structure_cunge80.ts +++ b/src/structure/structure_cunge80.ts @@ -1,4 +1,4 @@ -import { Result } from "../base"; +import { Result } from "../util/result"; import { RectangularStructure } from "./rectangular_structure"; import { RectangularStructureParams } from "./rectangular_structure_params"; import { Structure, StructureFlowMode, StructureFlowRegime } from "./structure"; @@ -14,31 +14,35 @@ export class StructureCunge80 extends RectangularStructure { * @param sVarCalc Variable à calculer (doit être égale à Q ici) */ public Equation(sVarCalc: string): Result { - const res: Result = super.Equation(sVarCalc); - switch (res.extraVar.Regime) { + super.CheckEquation(sVarCalc); + const data = super.defaultResultData(); + let v: number; + + switch (data.Regime) { case StructureFlowRegime.FREE: - if (res.extraVar.Mode === StructureFlowMode.WEIR) { + if (data.Mode === StructureFlowMode.WEIR) { const R32: number = 3 * Math.sqrt(3) / 2; - res.vCalc = this.prms.Cd.v * this.prms.L.v * Structure.R2G / R32 * Math.pow(this.prms.h1.v, 1.5); - this.debug("StructureCunge80.Equation WEIR FREE Q=" + res.vCalc); + v = this.prms.Cd.v * this.prms.L.v * Structure.R2G / R32 * Math.pow(this.prms.h1.v, 1.5); + this.debug("StructureCunge80.Equation WEIR FREE Q=" + v); } else { - res.vCalc = this.prms.Cd.v * this.prms.L.v * Structure.R2G + v = this.prms.Cd.v * this.prms.L.v * Structure.R2G * this.prms.W.v * Math.pow(this.prms.h1.v - this.prms.W.v, 0.5); - this.debug("StructureCunge80.Equation ORIFICE FREE Q=" + res.vCalc); + this.debug("StructureCunge80.Equation ORIFICE FREE Q=" + v); } break; case StructureFlowRegime.SUBMERGED: - if (res.extraVar.Mode === StructureFlowMode.WEIR) { - res.vCalc = this.prms.Cd.v * this.prms.L.v * Structure.R2G * this.prms.h2.v + if (data.Mode === StructureFlowMode.WEIR) { + v = this.prms.Cd.v * this.prms.L.v * Structure.R2G * this.prms.h2.v * Math.sqrt(this.prms.h1.v - this.prms.h2.v); - this.debug("StructureCunge80.Equation WEIR SUBMERGED Q=" + res.vCalc); + this.debug("StructureCunge80.Equation WEIR SUBMERGED Q=" + v); } else { - res.vCalc = this.prms.Cd.v * this.prms.L.v * Structure.R2G + v = this.prms.Cd.v * this.prms.L.v * Structure.R2G * this.prms.W.v * Math.sqrt(this.prms.h1.v - this.prms.h2.v); - this.debug("StructureCunge80.Equation ORIFICE SUBMERGED Q=" + res.vCalc); + this.debug("StructureCunge80.Equation ORIFICE SUBMERGED Q=" + v); } } - return res; + + return new Result(v, data); } protected getFlowRegime() { diff --git a/src/structure/structure_orifice_free.ts b/src/structure/structure_orifice_free.ts index fcb3477b..39272136 100644 --- a/src/structure/structure_orifice_free.ts +++ b/src/structure/structure_orifice_free.ts @@ -1,4 +1,4 @@ -import { Result } from "../base"; +import { Result } from "../util/result"; import { RectangularStructure } from "./rectangular_structure"; import { RectangularStructureParams } from "./rectangular_structure_params"; import { Structure, StructureFlowMode, StructureFlowRegime } from "./structure"; @@ -14,11 +14,14 @@ export class StructureOrificeFree extends RectangularStructure { * @param sVarCalc Variable à calculer (doit être égale à Q ici) */ public Equation(sVarCalc: string): Result { - const res: Result = super.Equation(sVarCalc); + super.CheckEquation(sVarCalc); + const data = super.defaultResultData(); + // TODO : Warning si les conditions hydrauliques ne correspondent pas à un écoulement dénoyé - res.extraVar.Regime = StructureFlowRegime.FREE; - res.vCalc = this.prms.Cd.v * Math.min(this.prms.W.v, this.prms.h1.v) * this.prms.L.v + data.Regime = StructureFlowRegime.FREE; + const v = this.prms.Cd.v * Math.min(this.prms.W.v, this.prms.h1.v) * this.prms.L.v * Structure.R2G * Math.sqrt(this.prms.h1.v); - return res; + + return new Result(v, data); } } diff --git a/src/structure/structure_orifice_submerged.ts b/src/structure/structure_orifice_submerged.ts index bfdc4e57..c8a67015 100644 --- a/src/structure/structure_orifice_submerged.ts +++ b/src/structure/structure_orifice_submerged.ts @@ -1,4 +1,4 @@ -import { Result } from "../base"; +import { Result } from "../util/result"; import { RectangularStructure } from "./rectangular_structure"; import { RectangularStructureParams } from "./rectangular_structure_params"; import { Structure, StructureFlowMode, StructureFlowRegime } from "./structure"; @@ -14,11 +14,14 @@ export class StructureOrificeSubmerged extends RectangularStructure { * @param sVarCalc Variable à calculer (doit être égale à Q ici) */ public Equation(sVarCalc: string): Result { - const res: Result = super.Equation(sVarCalc); + super.CheckEquation(sVarCalc); + const data = super.defaultResultData(); + // TODO : Warning si les conditions hydrauliques ne correspondent pas à un écoulement dénoyé - res.extraVar.Regime = StructureFlowRegime.SUBMERGED; - res.vCalc = this.prms.Cd.v * Math.min(this.prms.W.v, this.prms.h1.v) * this.prms.L.v + data.Regime = StructureFlowRegime.SUBMERGED; + const v = this.prms.Cd.v * Math.min(this.prms.W.v, this.prms.h1.v) * this.prms.L.v * Structure.R2G * Math.sqrt(this.prms.h1.v - this.prms.h2.v); - return res; + + return new Result(v, data); } } diff --git a/src/structure/structure_params.ts b/src/structure/structure_params.ts index 52305ce7..53904718 100644 --- a/src/structure/structure_params.ts +++ b/src/structure/structure_params.ts @@ -1,4 +1,4 @@ -import { Result } from "../base"; +import { Result } from "../util/result"; import { Nub } from "../nub"; import { ComputeNodeType, ParamDefinition, ParamDomain, ParamDomainValue, ParamsEquation } from "../param"; import { Message } from "../util/message"; diff --git a/src/structure/structure_weir_free.ts b/src/structure/structure_weir_free.ts index fd124640..4f862723 100644 --- a/src/structure/structure_weir_free.ts +++ b/src/structure/structure_weir_free.ts @@ -1,4 +1,4 @@ -import { Result } from "../base"; +import { Result } from "../util/result"; import { RectangularStructure } from "./rectangular_structure"; import { RectangularStructureParams } from "./rectangular_structure_params"; import { Structure, StructureFlowMode, StructureFlowRegime } from "./structure"; @@ -14,11 +14,14 @@ export class StructureWeirFree extends RectangularStructure { * @param sVarCalc Variable à calculer (doit être "Q") */ public Equation(sVarCalc: string): Result { - const res: Result = super.Equation(sVarCalc); + super.CheckEquation(sVarCalc); + const data = super.defaultResultData(); + // TODO : Warning si les conditions hydrauliques ne correspondent pas à un seuil dénoyé - res.extraVar.Regime = StructureFlowRegime.FREE; - res.extraVar.Mode = StructureFlowMode.WEIR; - res.vCalc = this.prms.Cd.v * this.prms.L.v * Structure.R2G * Math.pow(this.prms.h1.v, 1.5); - return res; + data.Regime = StructureFlowRegime.FREE; + data.Mode = StructureFlowMode.WEIR; + const v = this.prms.Cd.v * this.prms.L.v * Structure.R2G * Math.pow(this.prms.h1.v, 1.5); + + return new Result(v, data); } } diff --git a/src/util/result.ts b/src/util/result.ts new file mode 100644 index 00000000..1456888a --- /dev/null +++ b/src/util/result.ts @@ -0,0 +1,62 @@ +import { cLog } from "./log"; +import { Message, MessageCode } from "./message"; + +/** + * Résultat de calcul comprenant la valeur du résultat et des calculs annexes (flag, calculs intermédiaires...) + */ +export class Result { + /** Valeur calculée */ + private _vCalc: number; + + private _log: cLog; + + constructor(v: number | Message, d: {} = undefined) { + this._log = new cLog(); + if (typeof v == "number") { + this._vCalc = v; + const m = new Message(MessageCode.ERROR_OK); + m.extraVar = d; + this._log.add(m); + } + else { + if (d != undefined) + throw new Error("appel à Result.constructor() invalide"); + this._log.add(v); + } + }; + + get vCalc() { return this._vCalc; } + + get code(): MessageCode { + if (this.messageCount != 1) + throw new Error("appel à Result.code invalide, il n'y pas exactement un message de log"); + return this._log.messages[0].code; + } + + get extraVar() { + if (this.messageCount != 1) + throw new Error("appel à Result.extraVar invalide, il n'y pas exactement un message de log"); + return this._log.messages[0].extraVar; + } + + public addMessage(m: Message) { + this._log.add(m); + } + + public get log(): cLog { + return this._log; + } + + private get messageCount(): number { + return this._log.messages.length; + } + + public get ok(): boolean { + if (this._vCalc == undefined) + return false; + for (let m of this._log.messages) + if (m.code != MessageCode.ERROR_OK) + return false; + return true; + } +} -- GitLab