diff --git a/src/nub.ts b/src/nub.ts index a5f56bce6de9e668edc259e688511a58ab62dace..b6a81537d61de3c81ce03621c712d79f2948eeba 100644 --- a/src/nub.ts +++ b/src/nub.ts @@ -27,6 +27,10 @@ export abstract class Nub extends ComputeNode implements IObservable { * (used by CalcSerie with varying parameters) */ protected set currentResult(r: Result) { + // if for ex. Calc() is called outside of CalcSerie(), _result might not be initialized + if (! this._result) { + this.initNewResultElement(); + } this._result.resultElement = r.resultElement; this._result.resultElement.log = r.log; } @@ -150,9 +154,6 @@ export abstract class Nub extends ComputeNode implements IObservable { /** parameter that is to be computed */ protected _calculatedParam: ParamDefinition; - /** résultat de Calc()/CalcSerie() */ - protected _result: Result; - /** * List of children Nubs; browsed by parameters iterator. * - for ParallelStructures: contains 0 or more Structures @@ -163,6 +164,9 @@ export abstract class Nub extends ComputeNode implements IObservable { /** properties describing the Nub type */ protected _props: Props = new Props(); + /** résultat de Calc()/CalcSerie() */ + private _result: Result; + /** implémentation par délégation de IObservable */ private _observable: Observable; @@ -271,11 +275,6 @@ export abstract class Nub extends ComputeNode implements IObservable { computedVar = this.calculatedParam; } - // if Calc() is called outside of CalcSerie(), _result might not be initialized - if (! this._result) { - this.initNewResultElement(); - } - if (rInit === undefined) { rInit = computedVar.v; } @@ -395,8 +394,8 @@ export abstract class Nub extends ComputeNode implements IObservable { } } - // reinit Result - this._result = new Result(undefined, this); + // reinit Result and children Results + this.reinitResult(); // iterate over longest series (in fact any series would do) while (variated[longest].values.hasNext) { @@ -1128,7 +1127,7 @@ export abstract class Nub extends ComputeNode implements IObservable { } /** - * Adds a new empty resultElement to the current Result object, so that + * Adds a new empty ResultElement to the current Result object, so that * computation result is stored into it, via set currentResult(); does * the same for all children */ @@ -1144,6 +1143,17 @@ export abstract class Nub extends ComputeNode implements IObservable { } } + /** + * Sets this._result to a new empty Result, before starting a new CalcSerie(); + * does the same for all children + */ + public reinitResult() { + this._result = new Result(undefined, this); + for (const c of this._children) { + c.reinitResult(); + } + } + // interface IObservable /** diff --git a/src/pab/cloison_aval.ts b/src/pab/cloison_aval.ts index 1dbe30374c9712d6877f2046b74755aaadeb79e2..7896be9c33d607b631bc7f83bc7e1469259be3b0 100644 --- a/src/pab/cloison_aval.ts +++ b/src/pab/cloison_aval.ts @@ -30,10 +30,6 @@ export class CloisonAval extends ParallelStructure { if (sVarCalc !== "Z1") { throw new Error("CloisonAval sVarCalc should be Z1"); } - // if Calc() is called outside of CalcSerie(), _result might not be initialized - if (! this._result) { - this.initNewResultElement(); - } this.checkVanneLevante(); let m: Message; if (this.hasVanneLevante()) { diff --git a/src/section/section_parametree.ts b/src/section/section_parametree.ts index 9c4ff94e9cd38766b87df491d602d5cb1ecf4f3f..b23093de7fc245a6f66b9b318c1f65b2154b2e77 100644 --- a/src/section/section_parametree.ts +++ b/src/section/section_parametree.ts @@ -82,7 +82,7 @@ export class SectionParametree extends SectionNub { /* this._result = new Result(undefined, this); const re = new ResultElement(); this._result.addResultElement(re); */ - if (! this._result) { + if (! this.result) { this.initNewResultElement(); } @@ -137,7 +137,7 @@ export class SectionParametree extends SectionNub { // contrainte de cisaillement this.addExtraResultFromVar("Tau0", Y); - return this._result; + return this.result; } // calculated param is always "Y" @@ -237,9 +237,9 @@ export class SectionParametree extends SectionNub { private addExtraResultFromVar(varCalc: string, Y: number) { const r: Result = this.section.CalcSection(varCalc, Y); if (r.ok) { - this._result.resultElement.addExtraResult(varCalc, r.vCalc); + this.result.resultElement.addExtraResult(varCalc, r.vCalc); } else { - this._result.resultElement.log.addLog(r.log); + this.result.resultElement.log.addLog(r.log); } } } diff --git a/src/section/section_type.ts b/src/section/section_type.ts index dc901277000ceea64f699e81c76eb74bc45ee558..ee6cbd2bac4d1b60ce6702de737b966d7e29c1d3 100644 --- a/src/section/section_type.ts +++ b/src/section/section_type.ts @@ -242,7 +242,7 @@ export abstract class acSection extends Nub { */ public CalcSerie(rInit?: number, sDonnee?: any): Result { this.currentResult = this.parent.CalcSerie(rInit, sDonnee); - return this._result; + return this.result; } /** diff --git a/src/structure/parallel_structure.ts b/src/structure/parallel_structure.ts index f0223961d586e562fcf26c0e57a32eb7a3f232c8..7fb2fd268d43995b685a7af49c954facf10d8759 100644 --- a/src/structure/parallel_structure.ts +++ b/src/structure/parallel_structure.ts @@ -109,7 +109,7 @@ export class ParallelStructure extends Nub { */ public Calc(sVarCalc: string | any, rInit?: number): Result { // if Calc() is called outside of CalcSerie(), _result might not be initialized - if (! this._result) { + if (! this.result) { this.initNewResultElement(); } switch (sVarCalc) { @@ -117,8 +117,8 @@ export class ParallelStructure extends Nub { case "Z2": case "Q": this.currentResult = super.Calc(sVarCalc, rInit); - if (this._result.ok) { - this.getParameter(sVarCalc).v = this._result.resultElement.vCalc; + if (this.result.ok) { + this.getParameter(sVarCalc).v = this.result.resultElement.vCalc; } break; default: @@ -128,23 +128,23 @@ export class ParallelStructure extends Nub { // Pour les caractéristiques des ouvrages const structureIndex = this.getIndexForChild(sVarCalc.uid); this.currentResult = this.CalcStructPrm(structureIndex, sVarCalc.symbol); - if (this._result.ok) { + if (this.result.ok) { // Suppression des extraResults : ils sont complétés plus bas pour chaque ouvrage - this._result.resultElement.extraResults = {}; - this._children[structureIndex].getParameter(sVarCalc.symbol).v = this._result.resultElement.vCalc; + this.result.resultElement.extraResults = {}; + this._children[structureIndex].getParameter(sVarCalc.symbol).v = this.result.resultElement.vCalc; } } - if (this._result.ok) { + if (this.result.ok) { // Recalcul du débit total pour récupérer les résultats des ouvrages dans les résultats complémentaires const resQtot: Result = this.CalcQ(); for (const extraResKey in resQtot.extraResults) { if (resQtot.extraResults.hasOwnProperty(extraResKey)) { - this._result.resultElement.addExtraResult(extraResKey, resQtot.extraResults[extraResKey]); + this.result.resultElement.addExtraResult(extraResKey, resQtot.extraResults[extraResKey]); } } } - return this._result; + return this.result; } /**