@@ -61,6 +61,8 @@ protected
6161 "Weight factor for each aggregation cell" ;
6262 final parameter Real [i] rCel(each fixed= false ) "Cell widths" ;
6363
64+ discrete Boolean sampleLoad "Boolean variable used to trigger sampled load calculation" ;
65+
6466 discrete Modelica.Units.SI.HeatFlowRate[i] QAgg_flow
6567 "Vector of aggregated loads" ;
6668 discrete Modelica.Units.SI.HeatFlowRate[i] QAggShi_flow
@@ -127,21 +129,25 @@ equation
127129 der (delTBor) = dTStepdt* QBor_flow + derDelTBor0;
128130 der (U) = QBor_flow;
129131
130- when sample (t_start, tLoaAgg) then
132+ sampleLoad = sample (t_start, tLoaAgg);
133+ when sampleLoad then
131134 // Assign average load since last aggregation step to the first cell of the
132135 // aggregation vector
133136 U_old = U;
134137
135138 // Store (U - pre(U_old))/tLoaAgg in QAgg_flow[1], and pre(QAggShi_flow) in the other elements
136139 QAgg_flow = cat(1 , {(U - pre (U_old))/ tLoaAgg}, pre (QAggShi_flow[2 :end ]));
140+ end when ;
141+ when sampleLoad then
137142 // Shift loads in aggregation cells
138143 (curCel,QAggShi_flow) = IBPSA.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.shiftAggregationCells(
139144 i= i,
140145 QAgg_flow= QAgg_flow,
141146 rCel= rCel,
142147 nu= nu,
143148 curTim= (time - t_start));
144-
149+ end when ;
150+ when sampleLoad then
145151 // Determine the temperature change at the next aggregation step (assuming
146152 // no loads until then)
147153 delTBor0 = IBPSA.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.temporalSuperposition(
@@ -343,6 +349,12 @@ doi:10.1080/19401493.2021.1968953</a>.
343349</html>" , revisions="<html>
344350<ul>
345351<li>
352+ October 6, 2025, by Michael Wetter:<br/>
353+ Reformulated <code>when</code> block to avoid continuous and discrete variable assignment in the same block.<br/>
354+ This is for
355+ <a href=\" https://github.com/lbl-srg/modelica-buildings/issues/4321\">Buildings, #4321</a>.
356+ </li>
357+ <li>
346358June 9, 2022 by Massimo Cimmino:<br/>
347359Updated the function to use the more efficient method of Prieto and Cimmino
348360(2021).
0 commit comments