Skip to content

Commit

Permalink
* added script file to predict long term behavior of field and added …
Browse files Browse the repository at this point in the history
…new field model, #33
  • Loading branch information
MStillerEBC committed May 7, 2019
1 parent 8b2c9b6 commit 566cd62
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 45 deletions.
2 changes: 0 additions & 2 deletions pyDMPC/ControlFramework/Objective_Function.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ def Obj(values_DVs, BC, s):
print("cost_total: " + str(cost_total))
print("output: " + str(tout))

pickle_out

'''Temporary objective function value'''
obj_fnc_vals = [1]

Expand Down
Binary file modified pyDMPC/ControlFramework/__pycache__/Init.cpython-36.pyc
Binary file not shown.
Binary file not shown.
41 changes: 40 additions & 1 deletion pyDMPC/ControlFramework/field_long.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,47 @@
import scipy
from scipy.integrate import simps
import pickle
import os
import sys

sys.path.insert(0, os.path.join('C:\\', 'Program Files (x86)', 'Dymola 2018', 'Modelica',
'Library', 'python_interface', 'dymola.egg'))

#Simulation of field model
# Import dymola package
from dymola.dymola_interface import DymolaInterface

# Start the interface
dymola = DymolaInterface()

# Location of your local AixLib clone
dir_aixlib = r'C:\mst\AixLib\Aixlib'

# Location where to store the results
dir_result = <path/to/where/you/want/it>

# Open AixLib
dymola.openModel(path=os.path.join(dir_aixlib, 'package.mo'))

# Translate any model you'd like to simulate
dymola.translateModel('AixLib.ThermalZones.ReducedOrder.Examples.ThermalZone')

# Simulate the model
output = dymola.simulateExtendedModel(
problem='AixLib.ThermalZones.ReducedOrder.Examples.ThermalZone',
startTime=0.0,
stopTime=3.1536e+07,
outputInterval=3600,
method="Dassl",
tolerance=0.0001,
resultFile=os.path.join(dir_result, 'demo_results'),
finalNames=['thermalZone.TAir' ],
)

dymola.close()

#field temperature regarding the longterm set temperature = trajectory
T_set = 285*np.ones(3*365*24) #Vorlauftemperatur ins Feld (Soll)
T0 = 285 #ungestörte Erdreichtemperatur
T_set = T0*np.ones(3*365*24) #Vorlauftemperatur ins Feld (Soll)
pickle_out = open("T_set.pickle","wb")
pickle.dump(T_set, pickle_out)
2 changes: 1 addition & 1 deletion pyDMPC/ControlFramework/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Q_need_heat = np.array([500, 600, 300, 100, 50, 10, 0, 5, 80, 250, 300, 450]) #in kWh/Monat
Q_need_cold = np.array([25, 25, 110, 200, 400, 600, 650, 600, 450, 300, 150, 50]) #in kWh/Monat
days = np.array([31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]) #Tage im Monat: Jan 31, Feb 28, ...
cp_water = 4.186 #in kJ/(kg K)
cp_water = 4.186 #in kJ/(kg K)
m_flow = 0.5 #kg/s

#Wärmebedarf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ model SimpleModelGeo_2 "extends Modelica.Icons.Example;extends ModelicaModels.Ba
AixLib.Fluid.Sources.FixedBoundary bou( redeclare package Medium =
Water,
p=100000,
T=285.15,
nPorts=1) annotation (Placement(
T=285.15) annotation (Placement(
transformation(
extent={{10,-10},{-10,10}},
rotation=-90,
Expand All @@ -18,30 +17,29 @@ model SimpleModelGeo_2 "extends Modelica.Icons.Example;extends ModelicaModels.Ba
V=200,
energyDynamics=Modelica.Fluid.Types.Dynamics.DynamicFreeInitial,
m_flow_small=50,
p_start=100000,
nPorts=4) annotation (
p_start=100000) annotation (
Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=-90,
origin={54,-6})));
origin={64,-4})));
AixLib.Fluid.FixedResistances.HydraulicResistance hydraulicResistance(
redeclare package Medium = Water,
m_flow_nominal=100,
diameter=0.5,
m_flow_start=0,
zeta=0.3)
annotation (Placement(transformation(extent={{-22,-8},{-2,12}})));
annotation (Placement(transformation(extent={{-34,-8},{-14,12}})));
Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow prescribedHeatFlow
annotation (Placement(transformation(extent={{-6,-6},{6,6}},
rotation=-90,
origin={54,20})));
origin={64,30})));
AixLib.Fluid.Movers.FlowControlled_m_flow fan(redeclare package Medium =
Water,
m_flow_small=1,
m_flow_start=50,
inputType=AixLib.Fluid.Types.InputType.Constant,
m_flow_nominal=25)
annotation (Placement(transformation(extent={{8,-44},{-12,-24}})));
annotation (Placement(transformation(extent={{6,-42},{-14,-22}})));
Modelica.Blocks.Sources.Pulse Q_flow_need_heat(
width=50,
period=86400,
Expand Down Expand Up @@ -84,7 +82,7 @@ model SimpleModelGeo_2 "extends Modelica.Icons.Example;extends ModelicaModels.Ba
origin={-44,-100})));
AixLib.Fluid.Sensors.MassFlowRate senMasFlo1(redeclare package Medium =
Water)
annotation (Placement(transformation(extent={{36,-28},{24,-40}})));
annotation (Placement(transformation(extent={{26,-26},{14,-38}})));
Modelica.Blocks.Interfaces.RealOutput buildingMassflow_out annotation (
Placement(transformation(
extent={{-4,-4},{4,4}},
Expand All @@ -95,7 +93,7 @@ model SimpleModelGeo_2 "extends Modelica.Icons.Example;extends ModelicaModels.Ba
annotation (Placement(transformation(extent={{-68,-88},{-58,-80}})));
AixLib.Fluid.Sensors.Temperature senTem1(redeclare package Medium =
Water)
annotation (Placement(transformation(extent={{70,-26},{80,-16}})));
annotation (Placement(transformation(extent={{90,10},{100,20}})));
Modelica.Blocks.Math.Product product
annotation (Placement(transformation(extent={{-12,62},{-2,72}})));
Modelica.Blocks.Interfaces.RealInput valveQflow "scaling the buildings need"
Expand All @@ -108,13 +106,13 @@ model SimpleModelGeo_2 "extends Modelica.Icons.Example;extends ModelicaModels.Ba
annotation (Placement(transformation(extent={{-20,-88},{-10,-80}})));
AixLib.Fluid.Sensors.Temperature senTem3(redeclare package Medium =
Water)
annotation (Placement(transformation(extent={{2,24},{12,34}})));
annotation (Placement(transformation(extent={{-12,20},{-2,30}})));
AixLib.Fluid.Sensors.MassFlowRate senMasFlo2(redeclare package Medium =
Water)
annotation (Placement(transformation(extent={{22,-4},{34,8}})));
annotation (Placement(transformation(extent={{6,-4},{18,8}})));
AixLib.Fluid.Sensors.MassFlowRate senMasFlo3(redeclare package Medium =
Water)
annotation (Placement(transformation(extent={{-26,-28},{-38,-40}})));
annotation (Placement(transformation(extent={{-26,-26},{-38,-38}})));
Modelica.Blocks.Interfaces.RealOutput fieldTemperature_in annotation (
Placement(transformation(
extent={{-4,-4},{4,4}},
Expand Down Expand Up @@ -150,57 +148,50 @@ equation
92},{-46,92},{-46,63.6},{-36.8,63.6}},
color={0,0,127}));
connect(prescribedHeatFlow.port, vol1.heatPort)
annotation (Line(points={{54,14},{54,4}}, color={191,0,0}));
annotation (Line(points={{64,24},{64,6}}, color={191,0,0}));
connect(senMasFlo.m_flow, fieldMassflow_out) annotation (Line(points={{-44,
-4.6},{-44,-100}}, color={0,0,127}));
connect(senMasFlo1.m_flow, buildingMassflow_out) annotation (Line(points={{30,
-40.6},{30,-100}}, color={0,0,127}));
connect(senMasFlo1.m_flow, buildingMassflow_out) annotation (Line(points={{20,
-38.6},{20,-70},{30,-70},{30,-100}},
color={0,0,127}));
connect(senMasFlo.port_b, hydraulicResistance.port_a) annotation (Line(points={{-38,2},
{-22,2}}, color={0,127,255}));
{-34,2}}, color={0,127,255}));
connect(fan.port_a, senMasFlo1.port_b)
annotation (Line(points={{8,-34},{24,-34}}, color={0,127,255}));
annotation (Line(points={{6,-32},{14,-32}}, color={0,127,255}));
connect(senTem.T, fieldTemperature) annotation (Line(points={{-59.5,-84},{-58,
-84},{-58,-100}}, color={0,0,127}));
connect(senTem1.T, buildingTemperature) annotation (Line(points={{78.5,-21},{
84,-21},{84,-100}}, color={0,0,127}));
connect(senTem1.T, buildingTemperature) annotation (Line(points={{98.5,15},{
84,15},{84,-100}}, color={0,0,127}));
connect(product.y, prescribedHeatFlow.Q_flow) annotation (Line(points={{-1.5,67},
{16,67},{16,52},{54,52},{54,26}}, color={0,0,127}));
{16,67},{16,52},{64,52},{64,36}}, color={0,0,127}));
connect(Q_flow_need.y, product.u2)
annotation (Line(points={{-27.6,64},{-13,64}},
color={0,0,127}));
connect(buildingNeed, Q_flow_need.y) annotation (Line(points={{-24,100},{-24,
64},{-27.6,64}}, color={0,0,127}));
connect(hydraulicResistance.port_b, senMasFlo2.port_a)
annotation (Line(points={{-2,2},{22,2}}, color={0,127,255}));
connect(senMasFlo2.port_b, vol1.ports[1])
annotation (Line(points={{34,2},{44,2},{44,-3}}, color={0,127,255}));
connect(senMasFlo1.port_a, vol1.ports[2]) annotation (Line(points={{36,-34},{
44,-34},{44,-5}}, color={0,127,255}));
connect(bou.ports[1], vol1.ports[3]) annotation (Line(points={{64,-40},{64,
-34},{44,-34},{44,-7}}, color={0,127,255}));
connect(senTem1.port, vol1.ports[4]) annotation (Line(points={{75,-26},{66,
-26},{66,-18},{44,-18},{44,-9}},
color={0,127,255}));
annotation (Line(points={{-14,2},{6,2}}, color={0,127,255}));
connect(senMasFlo3.port_a, fan.port_b)
annotation (Line(points={{-26,-34},{-12,-34}}, color={0,127,255}));
annotation (Line(points={{-26,-32},{-14,-32}}, color={0,127,255}));
connect(senTem2.port, fan.port_b) annotation (Line(points={{-15,-88},{-20,-88},
{-20,-34},{-12,-34}}, color={0,127,255}));
{-20,-32},{-14,-32}}, color={0,127,255}));
connect(senTem2.T, fieldTemperature_in) annotation (Line(points={{-11.5,-84},
{-10,-84},{-10,-100}}, color={0,0,127}));
connect(senTem3.T, buildingTemperature_in)
annotation (Line(points={{10.5,29},{12,29},{12,100}}, color={0,0,127}));
annotation (Line(points={{-3.5,25},{12,25},{12,100}}, color={0,0,127}));
connect(senMasFlo3.m_flow, fieldMassflow_in)
annotation (Line(points={{-32,-40.6},{-32,-100}}, color={0,0,127}));
annotation (Line(points={{-32,-38.6},{-32,-100}}, color={0,0,127}));
connect(senMasFlo2.m_flow, buildingMassflow_in)
annotation (Line(points={{28,8.6},{28,100}}, color={0,0,127}));
annotation (Line(points={{12,8.6},{12,54},{28,54},{28,100}},
color={0,0,127}));
connect(senTem3.port, senMasFlo2.port_a)
annotation (Line(points={{7,24},{7,2},{22,2}}, color={0,127,255}));
annotation (Line(points={{-7,20},{-7,2},{6,2}}, color={0,127,255}));
connect(Q_flow_need_cold.y, Q_flow_need.u[2]) annotation (Line(points={{-53.6,
70},{-48,70},{-48,56},{-36.8,56},{-36.8,64.4}}, color={0,0,127}));
connect(valveQflow, product.u1) annotation (Line(points={{-14,100},{-14,86},{
-14,70},{-13,70}}, color={0,0,127}));
connect(senMasFlo3.port_b, borFie.port_a) annotation (Line(points={{-38,-34},{
-56,-34},{-56,-32},{-82,-32},{-82,-24}}, color={0,127,255}));
connect(senMasFlo3.port_b, borFie.port_a) annotation (Line(points={{-38,-32},
{-82,-32},{-82,-24}}, color={0,127,255}));
connect(borFie.port_b, senMasFlo.port_a) annotation (Line(points={{-82,-4},{-66,
-4},{-66,2},{-50,2}}, color={0,127,255}));
connect(senTem.port, borFie.port_a) annotation (Line(points={{-63,-88},{-76,-88},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
within ModelicaModels.SubsystemModels.DetailedModels.Geo;
model Field_new "Simplified model of geothermal field"
extends HeatExchangerCommunicationBaseClass(IntakeAirSource(nPorts=1));
AixLib.Fluid.Geothermal.Borefields.TwoUTubes borFie(redeclare package Medium
= Water) annotation (Placement(
transformation(
extent={{-26,-25},{26,25}},
rotation=0,
origin={-14,13})));
equation
connect(IntakeAirSource.ports[1], borFie.port_a) annotation (Line(points={{
-100,12},{-84,12},{-84,10},{-40,10},{-40,13}}, color={0,127,255}));
connect(borFie.port_b, massFlow.port_a) annotation (Line(points={{12,13},{54,
13},{54,6},{116,6},{116,12}}, color={0,127,255}));
connect(supplyTemperature.port, massFlow.port_a) annotation (Line(points={{
104,38},{100,38},{100,8},{96,8},{96,6},{116,6},{116,12}}, color={0,
127,255}));
end Field_new;
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
within ModelicaModels.SubsystemModels.DetailedModels.Geo;
model GeothermalHeatPump "Example of a geothermal heat pump system"

extends Modelica.Icons.Example;

extends
AixLib.Fluid.Examples.GeothermalHeatPump.BaseClasses.GeothermalHeatPumpControlledBase(
redeclare AixLib.Fluid.Examples.GeothermalHeatPump.Components.BoilerStandAlone PeakLoadDevice(redeclare
package Medium = Medium));

AixLib.Fluid.Sources.Boundary_pT coldConsumerFlow(redeclare package Medium =
Medium, nPorts=1) annotation (Placement(transformation(
extent={{-6,-6},{6,6}},
rotation=180,
origin={154,-20})));
AixLib.Fluid.Sources.Boundary_pT heatConsumerFlow(redeclare package Medium =
Medium, nPorts=1) "Sink representing heat consumer" annotation (
Placement(transformation(
extent={{-6,-6},{6,6}},
rotation=180,
origin={154,-50})));
AixLib.Fluid.Sources.Boundary_pT heatConsumerReturn(
redeclare package Medium = Medium,
nPorts=1,
T=303.15) "Source representing heat consumer" annotation (Placement(
transformation(
extent={{-6,-6},{6,6}},
rotation=180,
origin={154,-106})));
AixLib.Fluid.Sources.Boundary_pT coldConsumerReturn(
redeclare package Medium = Medium,
nPorts=1,
T=290.15) "Source representing cold consumer" annotation (Placement(
transformation(
extent={{-6,-6},{6,6}},
rotation=180,
origin={154,32})));
Modelica.Blocks.Sources.Constant pressureDifference(k=20000)
"Pressure difference used for all pumps" annotation (
Placement(transformation(
extent={{-6,-6},{6,6}},
rotation=180,
origin={154,6})));
AixLib.Controls.HeatPump.HPControllerOnOff hPControllerOnOff(bandwidth=5)
"Controls the temperature in the heat storage by switching the heat pump on or off"
annotation (Placement(transformation(extent={{-78,62},{-58,82}})));
Modelica.Blocks.Sources.Constant TStorageSet(k=273.15 + 35)
"Set point of upper heat storage temperature"
annotation (Placement(transformation(extent={{-160,0},{-148,12}})));
AixLib.Fluid.Examples.GeothermalHeatPump.Control.geothermalFieldController geothermalFieldControllerCold(
temperature_low=273.15 + 6, temperature_high=273.15 + 8)
"Controls the heat exchange with the geothermal field and the heat storage"
annotation (Placement(transformation(extent={{-100,28},{-84,44}})));
AixLib.Fluid.Examples.GeothermalHeatPump.Control.geothermalFieldController geothermalFieldControllerHeat
"Controls the heat exchange with the geothermal field and the heat storage"
annotation (Placement(transformation(extent={{-100,-34},{-84,-18}})));
equation
connect(resistanceColdConsumerFlow.port_b,coldConsumerFlow. ports[1])
annotation (Line(points={{94,-20},{94,-20},{148,-20}}, color={0,127,255}));
connect(pressureDifference.y, pumpColdConsumer.dp_in) annotation (Line(points={{147.4,6},
{147.4,6},{65,6},{65,-11.6}}, color={0,0,127}));
connect(pressureDifference.y, pumpHeatConsumer.dp_in) annotation (Line(points={{147.4,6},
{147.4,6},{56,6},{56,-36},{65,-36},{65,-41.6}}, color={0,
0,127}));
connect(resistanceColdConsumerReturn.port_a,coldConsumerReturn. ports[1])
annotation (Line(points={{94,32},{114,32},{148,32}},
color={0,127,255}));
connect(resistanceHeatConsumerReturn.port_a,heatConsumerReturn. ports[1])
annotation (Line(points={{94,-106},{94,-106},{148,-106}}, color={0,127,255}));
connect(pressureDifference.y, pumpEvaporator.dp_in) annotation (Line(points={{147.4,6},
{147.4,6},{64,6},{64,54},{7,54},{7,44.4}}, color={0,0,
127}));
connect(pressureDifference.y, pumpCondenser.dp_in) annotation (Line(points={{147.4,6},
{56,6},{56,-36},{-1,-36},{-1,-89.6}}, color={0,0,127}));
connect(pumpGeothermalSource.dp_in,pressureDifference. y) annotation (Line(
points={{-89,-45.6},{-89,-36},{56,-36},{56,6},{147.4,6}}, color={0,
0,127}));
connect(PeakLoadDevice.port_b,heatConsumerFlow. ports[1]) annotation (Line(
points={{120,-50},{120,-50},{148,-50}}, color={0,127,255}));
connect(TStorageSet.y,hPControllerOnOff. T_meas) annotation (Line(points={{-147.4,
6},{-132,6},{-132,76},{-78,76}}, color={0,0,127}));
connect(getTStorageUpper.y, hPControllerOnOff.T_set) annotation (Line(points=
{{-139,68},{-139,68},{-116,68},{-78,68}}, color={0,0,127}));
connect(hPControllerOnOff.heatPumpControlBus, heatPumpControlBus) annotation (
Line(
points={{-58.05,72.05},{-44,72.05},{-44,79},{-0.5,79}},
color={255,204,51},
thickness=0.5), Text(
string="%second",
index=1,
extent={{6,3},{6,3}}));
connect(PeakLoadDevice.chemicalEnergyFlowRate, chemicalEnergyFlowRate)
annotation (Line(points={{112.77,-56.54},{112.77,-118},{-26,-118},{-26,-100},
{-71.5,-100},{-71.5,-119.5}}, color={0,0,127}));
connect(getTStorageLower.y,geothermalFieldControllerCold. temperature)
annotation (Line(points={{-139,52},{-122,52},{-108,52},{-108,36},{-100,36}},
color={0,0,127}));
connect(geothermalFieldControllerCold.valveOpening1, valveColdStorage.y)
annotation (Line(points={{-83.04,40.8},{-82,40.8},{-82,40},{-82,52},{-82,54},
{-52,54},{-52,46.4}}, color={0,0,127}));
connect(geothermalFieldControllerCold.valveOpening2, valveHeatSource.y)
annotation (Line(points={{-83.04,31.2},{-82,31.2},{-82,1},{-68.4,1}}, color=
{0,0,127}));
connect(getTStorageUpper.y,geothermalFieldControllerHeat. temperature)
annotation (Line(points={{-139,68},{-120,68},{-120,-26},{-100,-26}}, color=
{0,0,127}));
connect(valveHeatSink.y, geothermalFieldControllerHeat.valveOpening1)
annotation (Line(points={{-30,-45.6},{-30,-45.6},{-30,-32},{-30,-21.2},{-83.04,
-21.2}}, color={0,0,127}));
connect(geothermalFieldControllerHeat.valveOpening2, valveHeatStorage.y)
annotation (Line(points={{-83.04,-30.8},{-56,-30.8},{-56,-63},{-26.4,-63}},
color={0,0,127}));
annotation (experiment(StopTime=86400, Interval=10), Documentation(revisions="<html>
<ul>
<li>
May 19, 2017, by Marc Baranski:<br/>
First implementation.
</li>
</ul>
</html>", info="<html>
<p>Simple stand-alone model of a combined heat and cold supply system.
The geothermal heat pump can either transport heat </p>
<ul>
<li>
from the cold to the heat storage
</li>
<li>
from the cold storage to the geothermal field (heat storage disconnected)
</li>
<li>
from the geothermal field to the heat storage
</li>
</ul>
<p>In the flow line of the heating circuit a boiler is connected as a peak load device.
Consumers are modeled as sinks are sources with a constant temperature.</p>
</html>"),
Diagram(coordinateSystem(extent={{-160,-120},{160,80}})),
Icon(coordinateSystem(extent={{-160,-120},{160,80}})));
end GeothermalHeatPump;
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
HeatExchangerCommunicationBaseClass
Building
Field
GeothermalHeatPump
Field_new
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
AHU
Geo
ModelGeo
GeothermalHeatPump

0 comments on commit 566cd62

Please sign in to comment.