Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation

Package with functions for load aggregation

Information

This package contains functions for load aggregation. For further information, consult the documentation of Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.GroundTemperatureResponse.

Extends from Modelica.Icons.BasesPackage (Icon for packages containing base classes).

Package Content

Name Description
Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.aggregationCellTimes aggregationCellTimes Function which builds the time and cell width vectors for aggregation
Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.aggregationWeightingFactors aggregationWeightingFactors Calculates the kappa vector for load aggregation
Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.countAggregationCells countAggregationCells Function which returns the number of aggregation cells in the aggregation vector
Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.shiftAggregationCells shiftAggregationCells Performs the shifting operation for load aggregation and determines the current cell
Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.temperatureResponseMatrix temperatureResponseMatrix Reads and possibly writes a matrix with a time series of the borefield's temperature response
Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.temporalSuperposition temporalSuperposition Performs temporal superposition for the load aggregation procedure
Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.Validation Validation Validation models for LoadAggregation

Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.aggregationCellTimes Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.aggregationCellTimes

Function which builds the time and cell width vectors for aggregation

Information

Simultaneously constructs both the nu vector, which is the aggregation time of each cell, and the rCel vector, which is the temporal size of each cell normalized with the time resolution of load aggregation tLoaAgg.

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

TypeNameDefaultDescription
Integeri Size of time vector
ReallvlBas Base for growth between each level, e.g. 2
IntegernCel Number of cells of same size per level
TimetLoaAgg Time resolution of load aggregation [s]
TimetimFin Total simulation max length [s]

Outputs

TypeNameDescription
Timenu[i]Time vector nu of size i [s]
RealrCel[i]Cell width vector of size i [1]

Modelica definition

function aggregationCellTimes "Function which builds the time and cell width vectors for aggregation" extends Modelica.Icons.Function; input Integer i "Size of time vector"; input Real lvlBas "Base for growth between each level, e.g. 2"; input Integer nCel "Number of cells of same size per level"; input Modelica.Units.SI.Time tLoaAgg(final min=Modelica.Constants.small) "Time resolution of load aggregation"; input Modelica.Units.SI.Time timFin "Total simulation max length"; output Modelica.Units.SI.Time nu[i] "Time vector nu of size i"; output Real rCel[i](each unit="1") "Cell width vector of size i"; protected Real width_j; algorithm width_j := 0; for j in 1:i loop width_j := width_j + tLoaAgg*lvlBas^floor((j-1)/nCel); nu[j] := width_j; rCel[j] := lvlBas^floor((j-1)/nCel); end for; if nu[i]>timFin then nu[i] := timFin; rCel[i] := (nu[i]-nu[i-1])/tLoaAgg; end if; end aggregationCellTimes;

Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.aggregationWeightingFactors Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.aggregationWeightingFactors

Calculates the kappa vector for load aggregation

Information

This function uses spline interpolation to construct the weighting factors vector kappa using the aggregation times nu and the temperature step reponse (a time-series in the form of a matrix) of the borefield as an input.

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

TypeNameDefaultDescription
Integeri Size of aggregation vector
IntegernTimTot Size of g-function time table
ThermalResistanceTStep[nTimTot, 2] Time matrix with TStep [K/W]
Timenu[i] Aggregation time vector nu [s]

Outputs

TypeNameDescription
ThermalResistancekappa[i]Weighting factors vector [K/W]

Modelica definition

function aggregationWeightingFactors "Calculates the kappa vector for load aggregation" extends Modelica.Icons.Function; input Integer i "Size of aggregation vector"; input Integer nTimTot "Size of g-function time table"; input Modelica.Units.SI.ThermalResistance TStep[nTimTot,2] "Time matrix with TStep"; input Modelica.Units.SI.Time nu[i] "Aggregation time vector nu"; output Modelica.Units.SI.ThermalResistance kappa[i] "Weighting factors vector"; protected Modelica.Units.SI.ThermalResistance prevT "Interpolated value of TStep at previous cell"; Modelica.Units.SI.ThermalResistance curT "Interpolated value of TStep at current cell"; Integer curInt "Integer to select data interval"; Real[size(TStep[:,1], 1)] d(each unit="K/J") "Derivatives at the support points"; algorithm d := Buildings.Utilities.Math.Functions.splineDerivatives( x=TStep[:,1], y=TStep[:,2], ensureMonotonicity=false); for j in 1:i loop if j==1 then prevT := 0; else //Spline interpolation at nu[j-1] for k in 1:size(TStep[:,1], 1) - 1 loop if nu[j-1] > TStep[k,1] then curInt := k; end if; end for; prevT := Buildings.Utilities.Math.Functions.cubicHermiteLinearExtrapolation( x=nu[j-1], x1=TStep[curInt,1], x2=TStep[curInt+1,1], y1=TStep[curInt,2], y2=TStep[curInt+1,2], y1d=d[curInt], y2d=d[curInt + 1]); end if; //Spline interpolation at nu[j] for k in 1:size(TStep[:,1], 1) - 1 loop if nu[j] > TStep[k,1] then curInt := k; end if; end for; curT := Buildings.Utilities.Math.Functions.cubicHermiteLinearExtrapolation( x=nu[j], x1=TStep[curInt,1], x2=TStep[curInt+1,1], y1=TStep[curInt,2], y2=TStep[curInt+1,2], y1d=d[curInt], y2d=d[curInt + 1]); kappa[j] := curT-prevT; end for; end aggregationWeightingFactors;

Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.countAggregationCells Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.countAggregationCells

Function which returns the number of aggregation cells in the aggregation vector

Information

Function that counts the required length of the aggregation time vector nu and of the weighting factor vectors kappa based on the maximum time for calculations related to the ground temperature response.

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

TypeNameDefaultDescription
ReallvlBas Base for growth between each level, e.g. 2
IntegernCel Number of cells of same size per level
TimetimFin Total simulation max length [s]
TimetLoaAgg Time resolution of load aggregation [s]

Outputs

TypeNameDescription
IntegeriSize of aggregation vectors

Modelica definition

function countAggregationCells "Function which returns the number of aggregation cells in the aggregation vector" extends Modelica.Icons.Function; input Real lvlBas "Base for growth between each level, e.g. 2"; input Integer nCel(min=1) "Number of cells of same size per level"; input Modelica.Units.SI.Time timFin "Total simulation max length"; input Modelica.Units.SI.Time tLoaAgg "Time resolution of load aggregation"; output Integer i(min=1) "Size of aggregation vectors"; protected Modelica.Units.SI.Duration width_i "Width of current aggregation cell"; Modelica.Units.SI.Time nu_i "End time of current aggregation cell"; algorithm assert(timFin > 0, "Total simulation time must be bigger than 0."); width_i := 0; nu_i := 0; i := 0; while nu_i<timFin loop i := i+1; width_i := tLoaAgg*lvlBas^floor((i-1)/nCel); nu_i := nu_i + width_i; end while; end countAggregationCells;

Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.shiftAggregationCells Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.shiftAggregationCells

Performs the shifting operation for load aggregation and determines the current cell

Information

Performs the shifting operation which propagates the thermal load history towards the more distant aggregation cells, and then sets the current cell's value at 0. Additionally, this function also outputs the last filled load aggregation cell.

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

TypeNameDefaultDescription
Integeri Number of aggregation cells
HeatFlowRateQAgg_flow[i] Vector of aggregated loads [W]
RealrCel[i] Aggregation cell widths
Timenu[i] Cell aggregation times [s]
TimecurTim Current simulation time [s]

Outputs

TypeNameDescription
IntegercurCelCurrent occupied aggregation cell
HeatFlowRateQAggShi_flow[i]Shifted vector of aggregated loads [W]

Modelica definition

function shiftAggregationCells "Performs the shifting operation for load aggregation and determines the current cell" extends Modelica.Icons.Function; input Integer i "Number of aggregation cells"; input Modelica.Units.SI.HeatFlowRate QAgg_flow[i] "Vector of aggregated loads"; input Real rCel[i](each min=Modelica.Constants.small) "Aggregation cell widths"; input Modelica.Units.SI.Time nu[i] "Cell aggregation times"; input Modelica.Units.SI.Time curTim "Current simulation time"; output Integer curCel "Current occupied aggregation cell"; output Modelica.Units.SI.HeatFlowRate QAggShi_flow[i] "Shifted vector of aggregated loads"; algorithm curCel := 1; for j in (i-1):-1:1 loop if curTim>=nu[j+1] then QAggShi_flow[j+1] := ((rCel[j+1] - 1)*QAgg_flow[j+1] + QAgg_flow[j])/rCel[j+1]; if j==(i-1) then curCel := i; end if; elseif curTim>=nu[j] then QAggShi_flow[j+1] := (rCel[j+1]*QAgg_flow[j+1] + QAgg_flow[j])/rCel[j+1]; curCel := j+1; else QAggShi_flow[j+1] := QAgg_flow[j+1]; end if; end for; QAggShi_flow[1] := 0; end shiftAggregationCells;

Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.temperatureResponseMatrix Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.temperatureResponseMatrix

Reads and possibly writes a matrix with a time series of the borefield's temperature response

Information

This function uses the parameters required to calculate the borefield's thermal response to build a SHA1-encrypted string unique to the borefield in question. Then, if the forceGFunCalc input is true or if there is no .mat file with the SHA1 hash as its filename in the tmp/temperatureResponseMatrix folder, the thermal response will be calculated and written as a .mat file. Otherwise, the thermal response will simply be read from the .mat file. In the .mat file, the data is saved in a matrix with the name TStep, where the first column is the time (in seconds) and the second column is the temperature step response, which is the g-function divided by 2 π H ksoi, with H being the borehole length and ksoi being the thermal conductivity of the soil.

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

TypeNameDefaultDescription
IntegernBor Number of boreholes
RealcooBor[nBor, 2] Borehole coordinates
HeighthBor Borehole length [m]
HeightdBor Borehole buried depth [m]
RadiusrBor Borehole radius [m]
ThermalDiffusivityaSoi Thermal diffusivity of soil [m2/s]
ThermalConductivitykSoi Thermal conductivity of soil [W/(m.K)]
IntegernSeg Number of line source segments per borehole
IntegernClu Number of clusters for g-function calculation
IntegernTimSho Number of time steps in short time region
IntegernTimLon Number of time steps in long time region
IntegernTimTot Number of g-function points
RealttsMax Maximum non-dimensional time for g-function calculation
Stringsha SHA-1 encryption of the g-function arguments
BooleanforceGFunCalc Set to true to force the thermal response to be calculated at the start

Outputs

TypeNameDescription
ThermalResistanceTStep[nTimTot, 2]Temperature step-response time series [K/W]

Modelica definition

impure function temperatureResponseMatrix "Reads and possibly writes a matrix with a time series of the borefield's temperature response" extends Modelica.Icons.Function; input Integer nBor "Number of boreholes"; input Real cooBor[nBor, 2] "Borehole coordinates"; input Modelica.Units.SI.Height hBor "Borehole length"; input Modelica.Units.SI.Height dBor "Borehole buried depth"; input Modelica.Units.SI.Radius rBor "Borehole radius"; input Modelica.Units.SI.ThermalDiffusivity aSoi "Thermal diffusivity of soil"; input Modelica.Units.SI.ThermalConductivity kSoi "Thermal conductivity of soil"; input Integer nSeg "Number of line source segments per borehole"; input Integer nClu "Number of clusters for g-function calculation"; input Integer nTimSho "Number of time steps in short time region"; input Integer nTimLon "Number of time steps in long time region"; input Integer nTimTot "Number of g-function points"; input Real ttsMax "Maximum non-dimensional time for g-function calculation"; input String sha "SHA-1 encryption of the g-function arguments"; input Boolean forceGFunCalc "Set to true to force the thermal response to be calculated at the start"; output Modelica.Units.SI.ThermalResistance TStep[nTimTot,2] "Temperature step-response time series"; protected String pathSave "Path of the folder used to save the g-function"; Modelica.Units.SI.Time[nTimTot] tGFun "g-function evaluation times"; Real[nTimTot] gFun "g-function vector"; Boolean writegFun = false "True if g-function was succesfully written to file"; Integer labels[nBor](each fixed=false) "Cluster label associated with each data point"; Integer cluSiz[nClu](each fixed=false) "Size of the clusters"; Integer nCluUni "Number of unique borehole clusters"; algorithm pathSave := "tmp/temperatureResponseMatrix/" + sha + "TStep.mat"; if forceGFunCalc or not Modelica.Utilities.Files.exist(pathSave) then (labels, cluSiz, nCluUni) := Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.ThermalResponseFactors.clusterBoreholes( nBor=nBor, cooBor=cooBor, hBor=hBor, dBor=dBor, rBor=rBor, nClu=nClu); (tGFun,gFun) := Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.ThermalResponseFactors.gFunction( nBor=nBor, cooBor=cooBor, hBor=hBor, dBor=dBor, rBor=rBor, aSoi=aSoi, nSeg=nSeg, nClu=nCluUni, nTimSho=nTimSho, nTimLon=nTimLon, ttsMax=ttsMax, labels = labels, cluSiz = cluSiz[1:nCluUni]); for i in 1:nTimTot loop TStep[i,1] := tGFun[i]; TStep[i,2] := gFun[i]/(2*Modelica.Constants.pi*hBor*nBor*kSoi); end for; //creation of a temporary folder in the simulation folder Modelica.Utilities.Files.createDirectory("tmp"); Modelica.Utilities.Files.createDirectory("tmp/temperatureResponseMatrix"); writegFun := Modelica.Utilities.Streams.writeRealMatrix( fileName=pathSave, matrixName="TStep", matrix=TStep, append=false); end if; TStep := Modelica.Utilities.Streams.readRealMatrix( fileName=pathSave, matrixName="TStep", nrow=nTimTot, ncol=2); end temperatureResponseMatrix;

Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.temporalSuperposition Buildings.Fluid.Geothermal.Borefields.BaseClasses.HeatTransfer.LoadAggregation.temporalSuperposition

Performs temporal superposition for the load aggregation procedure

Information

Performs the temporal superposition operation to obtain the temperature change at the borehole wall at the current time step, which is the scalar product of the aggregated load vector and the kappa step response vector. To avoid unnecessary calculations, the current aggregation cell in the simulation is used to truncate the values from the vectors that are not required.

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

TypeNameDefaultDescription
Integeri Number of aggregation cells
HeatFlowRateQAgg_flow[i] Vector of aggregated loads [W]
ThermalResistancekappa[i] Weighting factors for each aggregation cell [K/W]
IntegercurCel Current occupied aggregation cell

Outputs

TypeNameDescription
TemperatureDifferencedeltaTbDelta T at wall [K]

Modelica definition

function temporalSuperposition "Performs temporal superposition for the load aggregation procedure" extends Modelica.Icons.Function; input Integer i "Number of aggregation cells"; input Modelica.Units.SI.HeatFlowRate QAgg_flow[i] "Vector of aggregated loads"; input Modelica.Units.SI.ThermalResistance kappa[i] "Weighting factors for each aggregation cell"; input Integer curCel "Current occupied aggregation cell"; output Modelica.Units.SI.TemperatureDifference deltaTb "Delta T at wall"; algorithm deltaTb := QAgg_flow[1:curCel]*kappa[1:curCel]; end temporalSuperposition;