diff --git a/src/macrorugo/macrorugo_remous.ts b/src/macrorugo/macrorugo_remous.ts new file mode 100644 index 0000000000000000000000000000000000000000..38a61e62e24b655e06a604439f10b5cecd204dac --- /dev/null +++ b/src/macrorugo/macrorugo_remous.ts @@ -0,0 +1,88 @@ +import { CalculatorType } from "../compute-node"; +import { MethodeResolution } from "../open-channel/methode-resolution"; +import {CourbeRemous} from "../open-channel/remous"; +import { CourbeRemousParams } from "../open-channel/remous_params"; +import { cSnRectang } from "../open-channel/section/section_rectang"; +import { ParamsSectionRectang } from "../open-channel/section/section_rectang_params"; +import { Session } from "../session"; +import { Result } from "../util/result"; +import { MacroRugo } from "./macrorugo"; + +export class MacroRugoRemous extends CourbeRemous { + + private nubMacroRugo: MacroRugo; + + constructor(nubMacroRugo: MacroRugo, + crp: CourbeRemousParams, + method: MethodeResolution = MethodeResolution.Trapezes, + dbg: boolean = false + ) { + super(undefined, crp, method, dbg); + const sectParams = new ParamsSectionRectang( + undefined, undefined, undefined, undefined, undefined, Infinity + ); + const s = new cSnRectang(sectParams); + this.setSection(s); + + this.nubMacroRugo = nubMacroRugo; + } + + /** + * Clone the MacroRugo nub for the sake of calculation + */ + public setNubMacroRugoFromProps(): void { + const nubUID: string = this._props.getPropValue("nubMacroRugo"); + if (nubUID !== undefined && nubUID !== "") { + const nub = Session.getInstance().findNubByUid(nubUID); + if (nub!== undefined) { + if (nub.calcType !== CalculatorType.MacroRugo) { + throw new Error("nubMacroRugo must be a MacroRugo nub"); + } + //TODO: check that all parameters are in fixed mode + this.nubMacroRugo = nub.clone() as MacroRugo; + // Set result as input parameter + if (this.nubMacroRugo.result === undefined) { + this.nubMacroRugo.CalcSerie(); + } + this.nubMacroRugo.calculatedParam.v = this.nubMacroRugo.result.vCalc; + this.nubMacroRugo.calculatedParam = this.nubMacroRugo.prms.If; + } + // silent fail if (nub === undefined) + + } + } + + /** + * Synchronises section and MacroRugo parameters + */ + private syncSectionMacroRugo() { + this.section.prms.LargeurBerge.v = this.nubMacroRugo.prms.B.V; + this.nubMacroRugo.prms.Q.v = this.section.prms.Q.v; + } + + /** + * Computes the backwater curve + * @param rInit Not used + * @returns Nub result + */ + public CalcSerie(rInit?: number): Result { + this.setNubMacroRugoFromProps(); + if (this.nubMacroRugo === undefined) { + throw new Error("nubMacroRugo is undefined"); + } + this.syncSectionMacroRugo(); + return super.CalcSerie(rInit); + } + + /** + * Updates the Strickler coefficient from MacroRugo and + * computes the next point of the backwater curve + * @param Y current water depth (m) + */ + protected Calc_Y(Y: number): Result { + this.nubMacroRugo.prms.Y.v = Y; + this.nubMacroRugo.Calc("If"); + this.section.prms.Ks.v = this.nubMacroRugo.result.resultElement.values.Strickler; + return super.Calc_Y(Y); + } +} \ No newline at end of file diff --git a/src/open-channel/remous.ts b/src/open-channel/remous.ts index 2e2f15a8031fce2e5c5087d6706383ae3df67570..4057cf046bb252af58bc511087b06f70c69e1821 100644 --- a/src/open-channel/remous.ts +++ b/src/open-channel/remous.ts @@ -840,7 +840,7 @@ export class CourbeRemous extends SectionNub { * @param Y Tirant d'eau initial * @return Tirant d'eau */ - private Calc_Y(Y: number): Result { + protected Calc_Y(Y: number): Result { // let funcCalcY = 'Calc_Y_' + Resolution; // return this[funcCalcY](Y); let res: Result;