From 33725287be7d607f4182d9e8bd80d92b601555bb Mon Sep 17 00:00:00 2001 From: Sylvain Mariel Date: Mon, 26 Dec 2022 23:51:23 +0100 Subject: [PATCH] Total loss --- html/PTree.html | 10 ++++++++-- js/class.Canvas.js | 9 ++++++++- js/class.Tree.js | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/html/PTree.html b/html/PTree.html index 41e6659..12576c8 100644 --- a/html/PTree.html +++ b/html/PTree.html @@ -71,13 +71,19 @@ 0 W + + Total Loss + 0 + 0 + W + Efficiency 100 100 % - + diff --git a/js/class.Canvas.js b/js/class.Canvas.js index 583d1d3..44be0c9 100644 --- a/js/class.Canvas.js +++ b/js/class.Canvas.js @@ -583,11 +583,17 @@ class Canvas { $('.totalpower.typ').text(Util.numberToSi(totalpower.typ,3)); $('.totalpower.max').text(Util.numberToSi(totalpower.max,3)); + // refresh the total losses + const loss = this.tree.getTotalLoss(); + $('.totalloss.typ').text(Util.numberToSi(loss.typ,3)); + $('.totalloss.max').text(Util.numberToSi(loss.max,3)); + + // refresh the total efficiency const efficiency = this.tree.getTotalEfficiency(); $('.totaleff.typ').text(Util.numberToSi(efficiency.typ,3)); $('.totaleff.max').text(Util.numberToSi(efficiency.max,3)); - + /* // refresh the total losses const dcdcloss = this.tree.getTotalDCDCloss(); $('.totaldcdcloss.typ').text(Util.numberToSi(dcdcloss.typ,3)); @@ -597,6 +603,7 @@ class Canvas { const ldoloss = this.tree.getTotalLDOloss(); $('.totalldoloss.typ').text(Util.numberToSi(ldoloss.typ,3)); $('.totalldoloss.max').text(Util.numberToSi(ldoloss.max,3)); + */ } diff --git a/js/class.Tree.js b/js/class.Tree.js index 73d8397..e2c9933 100644 --- a/js/class.Tree.js +++ b/js/class.Tree.js @@ -217,6 +217,20 @@ class Tree { } + // return the loss of all sources + getTotalLoss(typmax='both') { + let totalloss = {typ:0, max:0}; + this.forEachSource((source) => { + totalloss.typ += source.getPowerLoss('typ'); + totalloss.max += source.getPowerLoss('max'); + }); + + // return the typ or max or both + if('both' === typmax) return totalloss; + else return totalloss[typmax]; + } + + // Remove the reference to this tree from each item // Caution! Call .convertToCircular() before calling any other method convertToUncircular() {