Skip to content

Commit

Permalink
Merge pull request #1788 from ibpsa/issue1785_modelicaConfTutorial
Browse files Browse the repository at this point in the history
Issue1785 modelica conf tutorial
  • Loading branch information
mwetter authored Sep 23, 2023
2 parents 4f6e0df + a50b2b5 commit 2d4f7c5
Show file tree
Hide file tree
Showing 41 changed files with 991 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ env:
# Test matrix for regression tests.
# The documentation is tested using github actions.
- TEST_ARG="make test-bestest"
- TEST_ARG="make test-dymola PACKAGE=\"IBPSA.Experimental\""
- TEST_ARG="make test-openmodelica PACKAGE=\"IBPSA.Experimental\""
- TEST_ARG="make test-dymola PACKAGE=\"IBPSA.{Examples,Experimental}\""
- TEST_ARG="make test-openmodelica PACKAGE=\"IBPSA.{Examples,Experimental}\""
- TEST_ARG="make test-dymola PACKAGE=\"IBPSA.Fluid.{Actuators,BaseClasses,Chillers,Delays,Geothermal,Examples,FMI,FixedResistances}\""
- TEST_ARG="make test-openmodelica PACKAGE=\"IBPSA.Fluid.{Actuators,BaseClasses,Chillers,Delays,Geothermal,Examples,FMI,FixedResistances}\""
- TEST_ARG="make test-dymola PACKAGE=\"IBPSA.Fluid.{HeatExchangers,HeatPumps,Humidifiers,Interfaces,MassExchangers,MixingVolumes,Movers,Sensors,Sources,Storage}\""
Expand Down
102 changes: 102 additions & 0 deletions IBPSA/Examples/Tutorial/SimpleHouse/SimpleHouse0.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
within IBPSA.Examples.Tutorial.SimpleHouse;
model SimpleHouse0
"Start file for simple house example"
extends Modelica.Icons.Example;
package MediumAir = IBPSA.Media.Air "Medium model for air";
package MediumWater = IBPSA.Media.Water "Medium model for water";
parameter Modelica.Units.SI.Area AWall = 100 "Wall area";
parameter Modelica.Units.SI.Length dWall = 0.25 "Wall thickness";
parameter Modelica.Units.SI.ThermalConductivity kWall = 0.04 "Wall thermal conductivity";
parameter Modelica.Units.SI.Density rhoWall = 2000 "Wall density";
parameter Modelica.Units.SI.SpecificHeatCapacity cpWall = 1000 "Wall specific heat capacity";
IBPSA.BoundaryConditions.WeatherData.ReaderTMY3 weaDat(filNam=
ModelicaServices.ExternalReferences.loadResource(
"modelica://IBPSA/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
"Weather data reader"
annotation (Placement(transformation(extent={{-180,-10},{-160,10}})));
IBPSA.BoundaryConditions.WeatherData.Bus weaBus "Weather data bus"
annotation (Placement(transformation(extent={{-140,-10},{-120,10}}),
iconTransformation(extent={{-152,-10},{-132,10}})));
Modelica.Thermal.HeatTransfer.Sources.PrescribedTemperature TOut
"Exterior temperature boundary condition"
annotation (Placement(transformation(extent={{-80,-10},{-60,10}})));
equation
connect(weaDat.weaBus, weaBus) annotation (Line(
points={{-160,0},{-130,0}},
color={255,204,51},
thickness=0.5));
connect(TOut.T, weaBus.TDryBul)
annotation (Line(points={{-82,0},{-130,0}}, color={0,0,127}));
annotation (Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-220,
-220},{220,220}}), graphics={
Rectangle(
extent={{-200,60},{-20,-60}},
fillColor={238,238,238},
fillPattern=FillPattern.Solid,
pattern=LinePattern.None),
Rectangle(
extent={{-200,-80},{200,-200}},
fillColor={238,238,238},
fillPattern=FillPattern.Solid,
pattern=LinePattern.None),
Rectangle(
extent={{-200,200},{200,80}},
fillColor={238,238,238},
fillPattern=FillPattern.Solid,
pattern=LinePattern.None),
Rectangle(
extent={{0,60},{200,-60}},
fillColor={238,238,238},
fillPattern=FillPattern.Solid,
pattern=LinePattern.None),
Text(
extent={{57.25,40.25},{2.75,59.75}},
textColor={0,0,127},
fillColor={255,213,170},
fillPattern=FillPattern.Solid,
textString="Building"),
Text(
extent={{-137,-99},{-203,-81}},
textColor={0,0,127},
fillColor={255,213,170},
fillPattern=FillPattern.Solid,
textString="Heating"),
Text(
extent={{-102,39},{-198,61}},
textColor={0,0,127},
fillColor={255,213,170},
fillPattern=FillPattern.Solid,
textString="Weather inputs"),
Text(
extent={{-61,179},{-199,201}},
textColor={0,0,127},
fillColor={255,213,170},
fillPattern=FillPattern.Solid,
textString="Cooling and ventilation")}),
experiment(Tolerance=1E-6, StopTime=1e+06),
Documentation(revisions="<html>
<ul>
<li>
September 4, 2023, by Jelger Jansen:<br/>
Replace IDEAS by IBPSA models and general revision/update of the model.
</li>
<li>
October 11, 2016, by Filip Jorissen:<br/>
First implementation.
</li>
</ul>
</html>", info="<html>
<p>
This model is used as the starting point for the
<a href=\"modelica://IBPSA.Examples.Tutorial.SimpleHouse\">IBPSA.Examples.Tutorial.SimpleHouse</a>
tutorial.
It contains a weather data reader and a <code>PrescribedTemperature</code> component
that allows the user to connect thermal components to the dry bulb temperature.
It was based on from the Modelica crash course organised by KU Leuven
(<a href=\"https://github.com/open-ideas/__CrashCourse__\">https://github.com/open-ideas/__CrashCourse__</a>).
</p>
</html>"),
__Dymola_Commands(file=
"modelica://IBPSA/Resources/Scripts/Dymola/Examples/Tutorial/SimpleHouse/SimpleHouse0.mos"
"Simulate and plot"));
end SimpleHouse0;
90 changes: 90 additions & 0 deletions IBPSA/Examples/Tutorial/SimpleHouse/SimpleHouse1.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
within IBPSA.Examples.Tutorial.SimpleHouse;
model SimpleHouse1 "Building wall model"
extends SimpleHouse0;

Modelica.Thermal.HeatTransfer.Components.HeatCapacitor walCap(
C=AWall*dWall*cpWall*rhoWall,
T(fixed=true))
"Thermal mass of wall"
annotation (Placement(transformation(extent={{-10,-10},{10,10}},
rotation=270,
origin={170,0})));
Modelica.Thermal.HeatTransfer.Components.ThermalResistor walRes(
R=dWall/AWall/kWall) "Thermal resistor for wall: 25 cm of rockwool"
annotation (Placement(transformation(extent={{60,-10},{80,10}})));
equation
connect(walRes.port_b, walCap.port) annotation (Line(points={{80,0},{100,0},{100,
1.77636e-15},{160,1.77636e-15}}, color={191,0,0}));
connect(TOut.port, walRes.port_a)
annotation (Line(points={{-60,0},{60,0}}, color={191,0,0}));
annotation (Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-220,
-220},{220,220}})),
experiment(Tolerance=1e-6, StopTime=1e+06),
Documentation(revisions="<html>
<ul>
<li>
September 4, 2023, by Jelger Jansen:<br/>
First implementation.
</li>
</ul>
</html>", info="<html>
<p>
A very simple building envelope model will be constructed manually using thermal resistors and heat capacitors.
The house consists of a wall represented by a single heat capacitor and a thermal resistor.
The boundary temperature are already included in
<a href=\"modelica://IBPSA.Examples.Tutorial.SimpleHouse.SimpleHouse0\">
IBPSA.Examples.Tutorial.SimpleHouse.SimpleHouse0</a>.
The wall has a surface area of <i>A<sub>wall</sub>=100 m<sup>2</sup></i>,
a thickness of <i>d<sub>wall</sub>=25 cm</i>,
a thermal conductivity of <i>k<sub>wall</sub>=0.04 W/(m K)</i>,
a density of <i>&rho;<sub>wall</sub>=2000 kg/m<sup>3</sup></i>,
and a specific heat capacity of <i>c<sub>p,wall</sub>= 1000 J/(kg K)</i>
</p>
<p>
These parameters are already declared in the equation section of
<a href=\"modelica://IBPSA.Examples.Tutorial.SimpleHouse.SimpleHouse0\">
IBPSA.Examples.Tutorial.SimpleHouse.SimpleHouse0</a>.
You can use this way of declaring parameters in the remainder of this exercise, but this is not required.
</p>
<p>
The conductive thermal resistance value of a wall may be computed as <i>R=d/(A*k)</i>.
The heat capacity value of a wall may be computed as <i>C=A*d*c<sub>p</sub>*&rho;</i>
</p>
<h4>Required models</h4>
<ul>
<li>
<a href=\"modelica://Modelica.Thermal.HeatTransfer.Components.HeatCapacitor\">
Modelica.Thermal.HeatTransfer.Components.HeatCapacitor</a>
</li>
<li>
<a href=\"modelica://Modelica.Thermal.HeatTransfer.Components.ThermalResistor\">
Modelica.Thermal.HeatTransfer.Components.ThermalResistor</a>
</li>
</ul>
<h4>Connection instructions</h4>
<p>
Connect one side of the thermal resistor to the output of <code>PrescribedTemperature</code>
and the other side of the thermal resistor to the heat capacitor.
</p>
<h4>Reference result</h4>
<p>
If you correctly added the model of the heat capacitor,
connected it to the resistor and added the parameter values for <i>C</i>,
then you should be able to simulate the model.
To do this, press the <i>Simulation Setup</i> and set the model <i>Stop time</i> to 1e6 seconds.
You can now simulate the model by pressing the <i>Simulate</i> button.
</p>
<p>
You can plot individual variables values by clicking on their name in the variable browser on the left.
Now plot the wall capacitor temperature value <i>T</i>.
It should look like the figure below (1 Ms is around 12 days).
</p>
<p align=\"center\">
<img alt=\"Wall temperature as function of time.\"
src=\"modelica://IBPSA/Resources/Images/Examples/Tutorial/SimpleHouse/result1.png\" width=\"1000\"/>
</p>
</html>"),
__Dymola_Commands(file=
"modelica://IBPSA/Resources/Scripts/Dymola/Examples/Tutorial/SimpleHouse/SimpleHouse1.mos"
"Simulate and plot"));
end SimpleHouse1;
79 changes: 79 additions & 0 deletions IBPSA/Examples/Tutorial/SimpleHouse/SimpleHouse2.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
within IBPSA.Examples.Tutorial.SimpleHouse;
model SimpleHouse2 "Building window model"
extends SimpleHouse1;

parameter Modelica.Units.SI.Area AWin=2 "Window area";

Modelica.Blocks.Math.Gain gaiWin(k=AWin)
"Gain for solar irradiance through the window"
annotation (Placement(transformation(extent={{20,-50},{40,-30}})));
Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow win
"Very simple window model"
annotation (Placement(transformation(extent={{60,-50},{80,-30}})));
equation
connect(gaiWin.y, win.Q_flow)
annotation (Line(points={{41,-40},{60,-40}}, color={0,0,127}));
connect(gaiWin.u, weaBus.HDirNor) annotation (Line(points={{18,-40},{-130,-40},
{-130,0}}, color={0,0,127}), Text(
string="%second",
index=1,
extent={{-6,3},{-6,3}},
horizontalAlignment=TextAlignment.Right));
connect(win.port, walCap.port) annotation (Line(points={{80,-40},{110,-40},{110,
1.77636e-15},{160,1.77636e-15}}, color={191,0,0}));
annotation (Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-220,
-220},{220,220}})),
experiment(Tolerance=1e-6, StopTime=1e+06),
Documentation(revisions="<html>
<ul>
<li>
September 4, 2023, by Jelger Jansen:<br/>
First implementation.
</li>
</ul>
</html>", info="<html>
<p>
The window has a surface area of <i>2 m<sup>2</sup></i>.
In this simple model we will therefore assume that
two times the outdoor solar irradiance is injected as heat onto the inside of the wall.
</p>
<h4>Required models</h4>
<ul>
<li>
<a href=\"modelica://Modelica.Blocks.Math.Gain\">
Modelica.Blocks.Math.Gain</a>
</li>
<li>
<a href=\"modelica://Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow\">
Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow</a>
</li>
</ul>
<h4>Connection instructions</h4>
<p>
To be able to use the value of the outdoor solar irradiance
you will need to access the weather data reader.
To do this, make a connection to the <code>weaBus</code>.
In the dialog box select <i>&lt;New Variable&gt;</i> and here type <code>HDirNor</code>,
which is the direct solar irradiance on a surface of <i>1 m<sup>2</sup></i>,
perpendicular to the sun rays.
Set the gain factor <code>k</code> to 2,
in order to get the solar irradiance through the window of <i>2 m<sup>2</sup></i>.
</p>
<p>
Make a connection with the <code>PrescribedHeatFlow</code> as well.
This block makes the connection between the heat flow from the gain, represented as a real value,
and a heat port that is compatible with the connectors of the thermal capacitance and resistance.
</p>
<h4>Reference result</h4>
<p>
The result with and without the window model is plotted in the figure below.
</p>
<p align=\"center\">
<img alt=\"Wall temperature as function of time, with (blue) and without (red) window.\"
src=\"modelica://IBPSA/Resources/Images/Examples/Tutorial/SimpleHouse/result2.png\" width=\"1000\"/>
</p>
</html>"),
__Dymola_Commands(file=
"modelica://IBPSA/Resources/Scripts/Dymola/Examples/Tutorial/SimpleHouse/SimpleHouse2.mos"
"Simulate and plot"));
end SimpleHouse2;
87 changes: 87 additions & 0 deletions IBPSA/Examples/Tutorial/SimpleHouse/SimpleHouse3.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
within IBPSA.Examples.Tutorial.SimpleHouse;
model SimpleHouse3 "Air model"
extends SimpleHouse2;

parameter Modelica.Units.SI.Volume VZone=8*8*3 "Zone volume";
parameter Modelica.Units.SI.MassFlowRate mAir_flow_nominal=1
"Nominal mass flow rate for air loop";
parameter Modelica.Units.SI.CoefficientOfHeatTransfer hWall=2
"Convective heat transfer coefficient at the wall";

Modelica.Thermal.HeatTransfer.Components.ThermalResistor conRes(R=1/hWall/
AWall) "Thermal resistance for convective heat transfer" annotation (
Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=270,
origin={110,20})));
IBPSA.Fluid.MixingVolumes.MixingVolume zon(
redeclare package Medium = MediumAir,
V=VZone,
energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
m_flow_nominal=mAir_flow_nominal) "Very simple zone air model"
annotation (Placement(transformation(extent={{160,50},{180,30}})));
equation
connect(zon.heatPort, conRes.port_a)
annotation (Line(points={{160,40},{110,40},{110,30}}, color={191,0,0}));
connect(conRes.port_b, walCap.port) annotation (Line(points={{110,10},{110,1.77636e-15},
{160,1.77636e-15}}, color={191,0,0}));
annotation (Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-220,
-220},{220,220}})),
experiment(Tolerance=1e-6, StopTime=1e+06),
Documentation(revisions="<html>
<ul>
<li>
September 4, 2023, by Jelger Jansen:<br/>
First implementation.
</li>
</ul>
</html>", info="<html>
<p>
To increase the model detail we now add an air model assuming the zone is <i>8m</i> x <i>8m</i> x <i>3m</i> in size.
The air will exchange heat with the wall.
This may be modelled using a thermal resistance representing
the convective heat resistance which is equal to <i>R<sub>conv</sub>=1/(h*A)</i>,
where <i>A</i> is the heat exchange surface area and <i>h=2 W/(m<sup>2</sup>*K)</i> is the convective heat transfer coefficient.
</p>
<h4>Required models</h4>
<ul>
<li>
<a href=\"modelica://IBPSA.Fluid.MixingVolumes.MixingVolume\">
IBPSA.Fluid.MixingVolumes.MixingVolume</a>
</li>
<li>
<a href=\"modelica://Modelica.Thermal.HeatTransfer.Components.ThermalResistor\">
Modelica.Thermal.HeatTransfer.Components.ThermalResistor</a>
</li>
</ul>
<h4>Connection instructions</h4>
<p>
The <code>MixingVolume</code> <code>Medium</code> parameter contains information about
the type of fluid and its properties that should be modelled by the <code>MixingVolume</code>.
Set its value to <code>MediumAir</code>, which is declared in the template,
by typing <code>redeclare package Medium = MediumAir</code>.
For the nominal mass flow rate you may assume a value of <i>1 kg/m<sup>3</sup></i> for now.
You will have to change this value once you add a ventilation system to the model (see
<a href=\"modelica://IBPSA.Examples.Tutorial.SimpleHouse.SimpleHouse6\">
IBPSA.Examples.Tutorial.SimpleHouse.SimpleHouse6</a>).
Finally, set the <code>energyDynamics</code> of the <code>MixingVolume</code>,
which can be found in the <code>Dynamics</code> tab of the model parameter window, to <code>FixedInitial</code>.
</p>
<p>
Make a connection with the <code>PrescribedHeatFlow</code> as well.
This block makes the connection between the heat flow from the gain, represented as a real value,
and a heat port that is compatible with the connectors of the thermal capacitance and resistance.
</p>
<h4>Reference result</h4>
<p>
The result with and without the air model is plotted in the figure below.
</p>
<p align=\"center\">
<img alt=\"Wall temperature as function of time, with (green) and without (blue) air model.\"
src=\"modelica://IBPSA/Resources/Images/Examples/Tutorial/SimpleHouse/result3.png\" width=\"1000\"/>
</p>
</html>"),
__Dymola_Commands(file=
"modelica://IBPSA/Resources/Scripts/Dymola/Examples/Tutorial/SimpleHouse/SimpleHouse3.mos"
"Simulate and plot"));
end SimpleHouse3;
Loading

0 comments on commit 2d4f7c5

Please sign in to comment.