Skip to content

Commit

Permalink
Merge pull request #1018 from ibpsa/issue422b_borefield_reverse_and_sha
Browse files Browse the repository at this point in the history
Issue422b borefield reverse and sha
  • Loading branch information
mwetter authored Sep 15, 2018
2 parents 44faa50 + dd83751 commit 6bf6891
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ model GroundTemperatureResponse "Model calculating discrete load aggregation"
iconTransformation(extent={{-120,-10},{-100,10}})));

protected
constant Integer nSeg = 12 "Number of line source segments per borehole";
constant Integer nSegMax = 1500 "Max total number of segments in g-function calculation";
final parameter Integer nSeg = integer(if 12*borFieDat.conDat.nBor<nSegMax then 12 else floor(nSegMax/borFieDat.conDat.nBor))
"Number of segments per borehole for g-function calculation";
constant Integer nTimSho = 26 "Number of time steps in short time region";
constant Integer nTimLon = 50 "Number of time steps in long time region";
constant Real ttsMax = exp(5) "Maximum non-dimensional time for g-function calculation";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,54 @@ function shaGFunction
"SHA1 encryption of the g-function arguments";

protected
String shaStr;
String formatStr = "1.3e";

String formatStrGen = "1.3e" "String format for general parameters";
String formatStrCoo = ".2f" "String format for coordinate";
algorithm
shaStr := String(nBor, format=formatStr);
sha := IBPSA.Utilities.Cryptographics.sha(String(nBor, format=formatStrGen));
sha := IBPSA.Utilities.Cryptographics.sha(sha + String(hBor, format=formatStrGen));
sha := IBPSA.Utilities.Cryptographics.sha(sha + String(dBor, format=formatStrGen));
sha := IBPSA.Utilities.Cryptographics.sha(sha + String(rBor, format=formatStrGen));
sha := IBPSA.Utilities.Cryptographics.sha(sha + String(aSoi, format=formatStrGen));
sha := IBPSA.Utilities.Cryptographics.sha(sha + String(nSeg, format=formatStrGen));
sha := IBPSA.Utilities.Cryptographics.sha(sha + String(nTimSho, format=formatStrGen));
sha := IBPSA.Utilities.Cryptographics.sha(sha + String(nTimLon, format=formatStrGen));
sha := IBPSA.Utilities.Cryptographics.sha(sha + String(ttsMax, format=formatStrGen));
for i in 1:nBor loop
shaStr := shaStr
+ String(cooBor[i, 1], format=formatStr)
+ String(cooBor[i, 2], format=formatStr);
sha := IBPSA.Utilities.Cryptographics.sha(sha + String(cooBor[i, 1], format=formatStrCoo));
sha := IBPSA.Utilities.Cryptographics.sha(sha + String(cooBor[i, 2], format=formatStrCoo));
end for;
shaStr := shaStr
+ String(hBor, format=formatStr)
+ String(dBor, format=formatStr)
+ String(rBor, format=formatStr)
+ String(aSoi, format=formatStr)
+ String(nSeg, format=formatStr)
+ String(nTimSho, format=formatStr)
+ String(nTimLon, format=formatStr)
+ String(ttsMax, format=formatStr);

sha := IBPSA.Utilities.Cryptographics.sha(shaStr);

annotation (
Inline=false,
Documentation(info="<html>
<p>
This function concatenates the various arguments required to generate the borefield's
thermal response into a single input string. Each argument is formatted in exponential notation
This function returns the SHA1 encryption of its arguments.
</p>
<h4>Implementation</h4>
<p>
Each argument is formatted in exponential notation
with four significant digits, for example <code>1.234e+001</code>, with no spaces or
other separating characters between each argument value. Because a borefield has a variable
number of boreholes, and because the (x,y) coordinates of each borehole are taken into
account, the total length of this input string is variable.
other separating characters between each argument value.
To prevent too long strings that can cause buffer overflows,
the sha encoding of each argument is computed and added to the next string that
is parsed.
</p>
<p>
Once the input string has been put together, the SHA1 encryption of this string
is computed using
<a href=\"modelica://IBPSA.Utilities.Cryptographics.sha\">IBPSA.Utilities.Cryptographics.sha</a>
and returned by this function.
The SHA1 encryption is computed using
<a href=\"modelica://IBPSA.Utilities.Cryptographics.sha\">IBPSA.Utilities.Cryptographics.sha</a>.
</p>
</html>", revisions="<html>
<ul>
<li>
September 11, 2018, by Michael Wetter:<br/>
Refactored implementation to avoid buffer overflow.
</li>
<li>
September 11, 2018 by Damien Picard:<br/>
Split long strings into small strings to avoid buffer overflow.
See <a href=\"https://github.com/ibpsa/modelica-ibpsa/pull/1018\">#1018</a>.
</li>
<li>
June 22, 2018 by Alex Laferri&egrave;re:<br/>
First implementation.
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,11 @@ partial model PartialBorefield

IBPSA.Fluid.BaseClasses.MassFlowRateMultiplier masFloDiv(
redeclare final package Medium = Medium,
final allowFlowReversal=allowFlowReversal,
final k=borFieDat.conDat.nBor) "Division of flow rate"
annotation (Placement(transformation(extent={{-60,-50},{-80,-30}})));

IBPSA.Fluid.BaseClasses.MassFlowRateMultiplier masFloMul(
redeclare final package Medium = Medium,
final allowFlowReversal=allowFlowReversal,
final k=borFieDat.conDat.nBor) "Mass flow multiplier"
annotation (Placement(transformation(extent={{60,-50},{80,-30}})));

Expand Down
3 changes: 2 additions & 1 deletion IBPSA/Fluid/Geothermal/Borefields/Examples/Borefields.mo
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
within IBPSA.Fluid.Geothermal.Borefields.Examples;
model Borefields
"Example model with several borefield configurations operating simultaneously."
"Example model with several borefield configurations operating simultaneously"
extends Modelica.Icons.Example;

package Medium = IBPSA.Media.Water;

parameter Modelica.SIunits.Time tLoaAgg=300
Expand Down
133 changes: 133 additions & 0 deletions IBPSA/Fluid/Geothermal/Borefields/Examples/RectangularBorefield.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
within IBPSA.Fluid.Geothermal.Borefields.Examples;
model RectangularBorefield "Example model of a rectangular borefield"
extends Modelica.Icons.Example;

package Medium = IBPSA.Media.Water "Medium model";

parameter Modelica.SIunits.Time tLoaAgg=300
"Time resolution of load aggregation";

parameter Modelica.SIunits.Temperature TGro = 283.15
"Ground temperature";
parameter Modelica.SIunits.Velocity v_nominal = 1 "Nominal velocity";
parameter Modelica.SIunits.MassFlowRate m_flow_nominal = nBorHol*v_nominal*rTub^2*3.14*1000
"Nominal mass flow rate";
parameter Modelica.SIunits.Pressure dpBorFie_nominal = (hBor+(xBorFie+yBorFie)/2)*2
"Pressure losses for the entire borefield";
parameter Modelica.SIunits.Pressure dpHex_nominal = 10000 "Pressure drop heat exchanger";
parameter Modelica.SIunits.Pressure dp_nominal = dpBorFie_nominal + dpHex_nominal
"Total pressure drop";

parameter Modelica.SIunits.Height hBor = 100 "Total height of the borehole";
parameter Modelica.SIunits.Radius rTub = 0.02 "Outer radius of the tubes";
parameter Modelica.SIunits.Length xBorFie = 10 "Borefield length";
parameter Modelica.SIunits.Length yBorFie = 30 "Borefield width";
parameter Modelica.SIunits.Length dBorHol = 5 "Distance between two boreholes";

final parameter Integer nXBorHol = integer((xBorFie+dBorHol)/dBorHol) "Number of boreholes in x-direction";
final parameter Integer nYBorHol = integer((yBorFie+dBorHol)/dBorHol) "Number of boreholes in y-direction";
final parameter Integer nBorHol = nXBorHol*nYBorHol "Number of boreholes";

final parameter IBPSA.Fluid.Geothermal.Borefields.Data.Filling.Bentonite filDat
annotation (Placement(transformation(extent={{20,40},{40,60}})));
final parameter IBPSA.Fluid.Geothermal.Borefields.Data.Soil.SandStone soiDat
"Soil data" annotation (Placement(transformation(extent={{50,40},{70,60}})));
final parameter IBPSA.Fluid.Geothermal.Borefields.Data.Configuration.Template conDat(
final borCon=IBPSA.Fluid.Geothermal.Borefields.Types.BoreholeConfiguration.SingleUTube,
final use_Rb=false,
final mBor_flow_nominal=m_flow_nominal/(nXBorHol*nYBorHol),
final mBorFie_flow_nominal=m_flow_nominal,
final hBor=hBor,
final dBor=1,
final rBor=0.2,
final rTub=rTub,
final kTub=0.5,
final eTub=0.002,
final xC=0.05,
final dp_nominal=dpBorFie_nominal,
final cooBor = {{dBorHol*mod((i-1),nXBorHol), dBorHol*floor((i-1)/nXBorHol)} for i in 1:nBorHol})
"Borefield configuration"
annotation (Placement(transformation(extent={{80,40},{100,60}})));

final parameter IBPSA.Fluid.Geothermal.Borefields.Data.Borefield.Template
borFieDat(
final filDat=filDat,
final soiDat=soiDat,
final conDat=conDat) "Borefield parameters"
annotation (Placement(transformation(extent={{60,74},{80,94}})));

IBPSA.Fluid.Geothermal.Borefields.OneUTube borFie(
redeclare package Medium = Medium,
borFieDat=borFieDat,
energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
TExt0_start=280.65,
allowFlowReversal=false)
"Geothermal borefield"
annotation (Placement(transformation(extent={{40,-10},{60,10}})));

IBPSA.Fluid.Sources.Boundary_pT bou(
redeclare package Medium = Medium, nPorts=1)
"Pressure boundary condition"
annotation (Placement(transformation(extent={{-60,-70},{-40,-50}})));

Movers.FlowControlled_m_flow pum(
redeclare package Medium = Medium,
addPowerToMedium=false,
use_inputFilter=false,
energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState,
massDynamics=Modelica.Fluid.Types.Dynamics.SteadyState,
inputType=IBPSA.Fluid.Types.InputType.Constant,
m_flow_nominal=borFieDat.conDat.mBorFie_flow_nominal,
allowFlowReversal=false)
annotation (Placement(transformation(extent={{0,-10},{20,10}})));
HeatExchangers.Heater_T hea(
redeclare package Medium = Medium,
show_T=true,
m_flow_nominal=borFieDat.conDat.mBorFie_flow_nominal,
m_flow(start=borFieDat.conDat.mBorFie_flow_nominal),
energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyStateInitial,
dp_nominal=dpHex_nominal,
allowFlowReversal=false) "Heater"
annotation (Placement(transformation(extent={{-40,-10},{-20,10}})));
Modelica.Blocks.Sources.Constant TSou(k=293.15)
"Temperature of water that goes into the borefield"
annotation (Placement(transformation(extent={{-80,20},{-60,40}})));
equation

connect(hea.port_b, pum.port_a)
annotation (Line(points={{-20,0},{0,0}}, color={0,127,255}));
connect(TSou.y, hea.TSet) annotation (Line(points={{-59,30},{-52,30},{-52,8},{
-42,8}}, color={0,0,127}));
connect(pum.port_b, borFie.port_a)
annotation (Line(points={{20,0},{40,0}}, color={0,127,255}));
connect(borFie.port_b, hea.port_a) annotation (Line(points={{60,0},{70,0},{70,
-20},{-52,-20},{-52,0},{-40,0}}, color={0,127,255}));
connect(pum.port_a, bou.ports[1])
annotation (Line(points={{0,0},{0,-60},{-40,-60}}, color={0,127,255}));
annotation (Documentation(info="<html>
<p>
This example model illustrates how to configure the layout
of the boreholes for a rectangular borefield.
The configuration is
</p>
<pre>
cooBor = {{dBorHol*mod((i-1),nXBorHol), dBorHol*floor((i-1)/nXBorHol)} for i in 1:nBorHol}
</pre>
<p>
where <code>dBorHol</code> is the distance between the boreholes,
<code>nXBorHol</code> is the number of boreholes in the x-direction, and
<code>nBorHol</code> is the total number of boreholes.
</p>
</html>", revisions="<html>
<ul>
<li>
September 10, 2018, by Michael Wetter:<br/>
First implementation.
</li>
</ul>
</html>"),
__Dymola_Commands(file="Resources/Scripts/Dymola/Fluid/Geothermal/Borefields/Examples/RectangularBorefield.mos"
"Simulate and plot"),
experiment(
StopTime=2678400,Tolerance=1e-6));
end RectangularBorefield;
1 change: 1 addition & 0 deletions IBPSA/Fluid/Geothermal/Borefields/Examples/package.order
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Borefields
RectangularBorefield
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
last-generated=2018-09-11
statistics-simulation=
{
"linear": "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0",
"nonlinear": " ",
"number of continuous time states": "43",
"numerical Jacobians": "0"
}
hea.sta_a.T=[2.806499938964844e+02, 2.922489624023438e+02, 2.923782958984375e+02, 2.924201965332031e+02, 2.924427795410156e+02, 2.924582824707031e+02, 2.924699401855469e+02, 2.924793090820312e+02, 2.924869384765625e+02, 2.924936828613281e+02, 2.9249951171875e+02, 2.925046691894531e+02, 2.925093994140625e+02, 2.92513671875e+02, 2.925176391601562e+02, 2.925213012695312e+02, 2.925247192382812e+02, 2.925281066894531e+02, 2.925312805175781e+02, 2.925343017578125e+02, 2.925372924804688e+02, 2.925401306152344e+02, 2.925428771972656e+02, 2.925456237792969e+02, 2.925482482910156e+02, 2.925508117675781e+02, 2.925533752441406e+02, 2.925558471679688e+02, 2.925582885742188e+02, 2.925607299804688e+02, 2.925630493164062e+02, 2.925653686523438e+02, 2.925676574707031e+02, 2.925699768066406e+02, 2.92572265625e+02, 2.925744934082031e+02, 2.925766906738281e+02, 2.92578857421875e+02, 2.925810241699219e+02, 2.925831909179688e+02, 2.925853271484375e+02, 2.925874328613281e+02, 2.925894775390625e+02, 2.925915222167969e+02, 2.925935668945312e+02, 2.925955810546875e+02, 2.925976257324219e+02, 2.925995788574219e+02, 2.926015319824219e+02, 2.926034851074219e+02, 2.926054077148438e+02, 2.926073303222656e+02, 2.926092529296875e+02, 2.926111145019531e+02, 2.926129760742188e+02, 2.926148376464844e+02, 2.926166687011719e+02, 2.926185302734375e+02, 2.926203308105469e+02, 2.926220703125e+02, 2.926238098144531e+02, 2.926255187988281e+02, 2.926272583007812e+02, 2.926289978027344e+02, 2.926307067871094e+02, 2.926324157714844e+02, 2.926341247558594e+02, 2.926358337402344e+02, 2.926375427246094e+02, 2.926392211914062e+02, 2.926408386230469e+02, 2.926424255371094e+02, 2.926440124511719e+02, 2.926455993652344e+02, 2.926471862792969e+02, 2.926487731933594e+02, 2.926503295898438e+02, 2.926519165039062e+02, 2.926534729003906e+02, 2.92655029296875e+02, 2.926565856933594e+02, 2.926580810546875e+02, 2.926595458984375e+02, 2.926610107421875e+02, 2.926624450683594e+02, 2.926638793945312e+02, 2.926653442382812e+02, 2.926667785644531e+02, 2.92668212890625e+02, 2.926696472167969e+02, 2.926710815429688e+02, 2.926724853515625e+02, 2.926739196777344e+02, 2.926752624511719e+02, 2.926766052246094e+02, 2.926779479980469e+02, 2.926792602539062e+02, 2.926806030273438e+02, 2.926819458007812e+02, 2.926832580566406e+02, 2.926845703125e+02]
time=[0e+00, 2.6784e+06]
borFie.groTemRes.delTBor=[0e+00, 2.106655597686768e+00, 2.882045269012451e+00, 3.253863573074341e+00, 3.486679553985596e+00, 3.656929492950439e+00, 3.787418127059937e+00, 3.89473295211792e+00, 3.982996463775635e+00, 4.061352252960205e+00, 4.131009101867676e+00, 4.191467761993408e+00, 4.24700927734375e+00, 4.298527240753174e+00, 4.346031188964844e+00, 4.389286518096924e+00, 4.430964469909668e+00, 4.47255277633667e+00, 4.51012134552002e+00, 4.547041893005371e+00, 4.583920001983643e+00, 4.617668628692627e+00, 4.651390075683594e+00, 4.684808254241943e+00, 4.71635913848877e+00, 4.747883796691895e+00, 4.779049396514893e+00, 4.809280872344971e+00, 4.839463710784912e+00, 4.868901252746582e+00, 4.89725399017334e+00, 4.925564289093018e+00, 4.953824996948242e+00, 4.9820237159729e+00, 5.01015043258667e+00, 5.03732967376709e+00, 5.064004898071289e+00, 5.09062385559082e+00, 5.117181777954102e+00, 5.143670558929443e+00, 5.170083999633789e+00, 5.195383071899414e+00, 5.220542907714844e+00, 5.245645999908447e+00, 5.270686626434326e+00, 5.29565954208374e+00, 5.320385932922363e+00, 5.344318866729736e+00, 5.368195056915283e+00, 5.392014980316162e+00, 5.415772438049316e+00, 5.43946361541748e+00, 5.462751865386963e+00, 5.485588073730469e+00, 5.508368492126465e+00, 5.53109073638916e+00, 5.553752422332764e+00, 5.57634973526001e+00, 5.598067283630371e+00, 5.61942720413208e+00, 5.640746116638184e+00, 5.662021160125732e+00, 5.683245182037354e+00, 5.704416275024414e+00, 5.72553014755249e+00, 5.746585845947266e+00, 5.767580986022949e+00, 5.788514614105225e+00, 5.809386730194092e+00, 5.829885959625244e+00, 5.849430561065674e+00, 5.868940830230713e+00, 5.88841724395752e+00, 5.907854557037354e+00, 5.927248477935791e+00, 5.946595668792725e+00, 5.965893745422363e+00, 5.985140800476074e+00, 6.004335403442383e+00, 6.023477554321289e+00, 6.04256534576416e+00, 6.060677051544189e+00, 6.078505516052246e+00, 6.09630823135376e+00, 6.114082336425781e+00, 6.13182258605957e+00, 6.149526119232178e+00, 6.167187690734863e+00, 6.184808254241943e+00, 6.202384948730469e+00, 6.219917297363281e+00, 6.237403392791748e+00, 6.25454568862915e+00, 6.271007537841797e+00, 6.287444114685059e+00, 6.303857326507568e+00, 6.320241928100586e+00, 6.336595058441162e+00, 6.352912425994873e+00, 6.369194030761719e+00, 6.385437965393066e+00]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
simulateModel("IBPSA.Fluid.Geothermal.Borefields.Examples.RectangularBorefield", stopTime=2678400, method="Cvode", tolerance=1e-06, resultFile="RectangularBorefield");
createPlot(id=1, position={15, 10, 592, 689}, y={"hea.sta_a.T"}, range={0.0, 3000000.0, 5.0, 20.0}, grid=true, colors={{28,108,200}}, displayUnits={"degC"});
createPlot(id=1, position={15, 10, 592, 342}, y={"borFie.groTemRes.delTBor"}, range={0.0, 3000000.0, -5.0, 10.0}, grid=true, subPlot=2, colors={{28,108,200}});

0 comments on commit 6bf6891

Please sign in to comment.