Skip to content

Commit

Permalink
* added python script for heating and cooling budget calculation, #33
Browse files Browse the repository at this point in the history
  • Loading branch information
MStillerEBC committed Apr 18, 2019
1 parent 27bb3dc commit 9abd718
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 13 deletions.
49 changes: 49 additions & 0 deletions pyDMPC/ControlFramework/Heatdemand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import xlrd
import scipy
from scipy.integrate import simps

DATA_FILE = "C:/mst/Grafana/Grafana3.xlsx"

# Read Excel data of Grafana csv file
def read_excel_file(Grafana3):
book = xlrd.open_workbook(Grafana3, encoding_override = "utf-8")
sheet = book.sheet_by_index(0)
time = np.asarray([sheet.cell(i, 0).value for i in range(1, sheet.nrows)]) #in s
vol_flow = np.asarray([sheet.cell(i, 1).value for i in range(1, sheet.nrows)]) #in l/min
T_flow = np.asarray([sheet.cell(i, 2).value for i in range(1, sheet.nrows)]) #in °C
T_return = np.asarray([sheet.cell(i, 3).value for i in range(1, sheet.nrows)]) #in °C
mode = np.asarray([sheet.cell(i, 4).value for i in range(1, sheet.nrows)]) #1=cooling mode; 2=heating mode
return time, vol_flow, T_flow, T_return, mode

time, vol_flow, T_flow, T_return, mode = read_excel_file(DATA_FILE)

# Variables of the fluid in double u-pipes
cp_water = 4.186 #in kJ/(kg K)
rho_water = 1000 #in kg/m³

#calculation of heatflow in timestep
dT = np.subtract(T_return, T_flow)
Q_flow = np.asarray(cp_water*rho_water*(vol_flow/60000)*dT) #in kW

##Plotting Q(time)
#plt.plot(time, Q, lw=2)
#plt.axis([0, 26768640, -7, 7])
#plt.show()

#calculating heating budget [kWh/year] of field
Q_flow_heating = Q_flow.clip(min=0)
Q_heating = scipy.integrate.simps(Q_flow_heating, time)/3600
print("The heating budget for one year is", Q_heating, "kWh")

#calculating cooling budget [kWh/year] of field
Q_flow_cooling = Q_flow.clip(max=0)
Q_cooling = scipy.integrate.simps(Q_flow_cooling, time)/3600
print("The cooling budget for one year is", Q_cooling, "kWh")

##Calculating field temperature
#u = #heat transfer parameters borehole
#T_field = np.sum(T_rohr, np.divide(Q_flow, u))

2 changes: 1 addition & 1 deletion pyDMPC/ControlFramework/Init.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
sim_time_global = 10000 # -> not used yet
sync_rate = 5*60 # Synchronisation rate in seconds
optimization_interval = 10*60 # After one interval the optimization is repeated
prediction_horizon = 3600 #Common prediction horizon in seconds
prediction_horizon = 86400 #Common prediction horizon in seconds

""" Directories and Modelica libraries """
# Path where the main working directory shall be created
Expand Down
Binary file modified pyDMPC/ControlFramework/__pycache__/Init.cpython-36.pyc
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ model SimpleModelGeo "extends Modelica.Icons.Example;extends ModelicaModels.Base
annotation (Placement(transformation(
extent={{-6,-6},{6,6}},
rotation=90,
origin={-88,-64})));
origin={-88,-86})));
Modelica.Thermal.HeatTransfer.Components.ThermalResistor thermalResistor(R=0.5)
annotation (Placement(transformation(
extent={{-6,-6},{6,6}},
Expand Down Expand Up @@ -164,9 +164,9 @@ model SimpleModelGeo "extends Modelica.Icons.Example;extends ModelicaModels.Base
origin={-23,43})));
Modelica.Blocks.Sources.Constant const1(k=0)
annotation (Placement(transformation(extent={{-68,42},{-58,52}})));
Modelica.Blocks.Sources.CombiTimeTable combiTimeTable
annotation (Placement(transformation(extent={{-100,20},{-80,40}})));
equation
connect(fixedTemperature.port, thermalResistor.port_a)
annotation (Line(points={{-88,-58},{-88,-48}}, color={191,0,0}));
connect(pulse1.y, Q_flow_need_cold.u1) annotation (Line(points={{-87.6,76},{
-66,76},{-66,72.4},{-62.8,72.4}}, color={0,0,127}));
connect(const.y, Q_flow_need_cold.u2) annotation (Line(points={{-87.6,60},{
Expand Down Expand Up @@ -236,6 +236,8 @@ equation
-42.75,47},{-42.75,49},{-27,49}}, color={0,0,127}));
connect(senMasFlo.port_a, vol.ports[3]) annotation (Line(points={{-50,2},{-68,
2},{-68,-3.33333}}, color={0,127,255}));
connect(fixedTemperature.port, thermalResistor.port_a)
annotation (Line(points={{-88,-80},{-88,-48}}, color={191,0,0}));
annotation (Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,
-100},{120,100}})), Diagram(
coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,207 @@ model SimpleModelGeo_2 "extends Modelica.Icons.Example;extends ModelicaModels.Ba
AixLib.Fluid.Sources.FixedBoundary bou( redeclare package Medium =
Water,
p=100000,
T=285.15) annotation (Placement(
T=285.15,
nPorts=1) annotation (Placement(
transformation(
extent={{10,-10},{-10,10}},
rotation=-90,
origin={64,-50})));
AixLib.Fluid.MixingVolumes.MixingVolume vol1(redeclare package Medium =
Water,
m_flow_nominal=100,
V=200,
energyDynamics=Modelica.Fluid.Types.Dynamics.DynamicFreeInitial,
m_flow_small=50,
p_start=100000,
nPorts=4) annotation (
Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=-90,
origin={84,-30})));
origin={54,-6})));
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}})));
Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow prescribedHeatFlow
annotation (Placement(transformation(extent={{-6,-6},{6,6}},
rotation=-90,
origin={54,20})));
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={{10,-44},{-10,-24}})));
Subsystems.Geo.GeothermalHeatPump geothermalHeatPump
annotation (Placement(transformation(extent={{18,2},{50,22}})));
annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
coordinateSystem(preserveAspectRatio=false)));
annotation (Placement(transformation(extent={{8,-44},{-12,-24}})));
Modelica.Blocks.Sources.Pulse Q_flow_need_heat(
width=50,
period=86400,
amplitude=2200)
annotation (Placement(transformation(extent={{-96,88},{-88,96}})));
Modelica.Blocks.Sources.Pulse pulse1(
width=50,
period=86400,
startTime=43200,
amplitude=2200)
annotation (Placement(transformation(extent={{-96,72},{-88,80}})));
Modelica.Blocks.Math.Product Q_flow_need_cold
annotation (Placement(transformation(extent={{-62,66},{-54,74}})));
Modelica.Blocks.Sources.Constant const(k=-1)
annotation (Placement(transformation(extent={{-96,56},{-88,64}})));
Modelica.Blocks.Math.Sum Q_flow_need(nin=2)
annotation (Placement(transformation(extent={{-36,60},{-28,68}})));
Modelica.Blocks.Interfaces.RealOutput buildingNeed annotation (Placement(
transformation(
extent={{-4,-4},{4,4}},
rotation=90,
origin={-24,100})));
Modelica.Blocks.Interfaces.RealOutput fieldTemperature annotation (Placement(
transformation(
extent={{-4,-4},{4,4}},
rotation=-90,
origin={-58,-100})));
Modelica.Blocks.Interfaces.RealOutput buildingTemperature annotation (
Placement(transformation(
extent={{-4,-4},{4,4}},
rotation=-90,
origin={84,-100})));
AixLib.Fluid.Sensors.MassFlowRate senMasFlo(redeclare package Medium =
Water)
annotation (Placement(transformation(extent={{-50,8},{-38,-4}})));
Modelica.Blocks.Interfaces.RealOutput fieldMassflow_out annotation (Placement(
transformation(
extent={{-4,-4},{4,4}},
rotation=-90,
origin={-44,-100})));
AixLib.Fluid.Sensors.MassFlowRate senMasFlo1(redeclare package Medium =
Water)
annotation (Placement(transformation(extent={{36,-28},{24,-40}})));
Modelica.Blocks.Interfaces.RealOutput buildingMassflow_out annotation (
Placement(transformation(
extent={{-4,-4},{4,4}},
rotation=-90,
origin={30,-100})));
AixLib.Fluid.Sensors.Temperature senTem(redeclare package Medium =
Water)
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}})));
Modelica.Blocks.Math.Product product
annotation (Placement(transformation(extent={{-12,62},{-2,72}})));
Modelica.Blocks.Interfaces.RealInput valveQflow "scaling the buildings need"
annotation (Placement(transformation(
extent={{-4,-4},{4,4}},
rotation=-90,
origin={-14,100})));
AixLib.Fluid.Sensors.Temperature senTem2(redeclare package Medium =
Water)
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}})));
AixLib.Fluid.Sensors.MassFlowRate senMasFlo2(redeclare package Medium =
Water)
annotation (Placement(transformation(extent={{22,-4},{34,8}})));
AixLib.Fluid.Sensors.MassFlowRate senMasFlo3(redeclare package Medium =
Water)
annotation (Placement(transformation(extent={{-26,-28},{-38,-40}})));
Modelica.Blocks.Interfaces.RealOutput fieldTemperature_in annotation (
Placement(transformation(
extent={{-4,-4},{4,4}},
rotation=-90,
origin={-10,-100})));
Modelica.Blocks.Interfaces.RealOutput buildingTemperature_in annotation (
Placement(transformation(
extent={{-4,-4},{4,4}},
rotation=90,
origin={12,100})));
Modelica.Blocks.Interfaces.RealOutput fieldMassflow_in annotation (Placement(
transformation(
extent={{-4,-4},{4,4}},
rotation=-90,
origin={-32,-100})));
Modelica.Blocks.Interfaces.RealOutput buildingMassflow_in annotation (
Placement(transformation(
extent={{-4,-4},{4,4}},
rotation=90,
origin={28,100})));
AixLib.Fluid.Geothermal.Borefields.TwoUTubes borFie(redeclare package Medium =
Water) annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=90,
origin={-82,-14})));
equation
connect(pulse1.y, Q_flow_need_cold.u1) annotation (Line(points={{-87.6,76},{
-66,76},{-66,72.4},{-62.8,72.4}}, color={0,0,127}));
connect(const.y, Q_flow_need_cold.u2) annotation (Line(points={{-87.6,60},{
-76,60},{-76,66},{-62.8,66},{-62.8,67.6}}, color={0,0,127}));
connect(Q_flow_need_heat.y, Q_flow_need.u[1]) annotation (Line(points={{-87.6,
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}));
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(senMasFlo.port_b, hydraulicResistance.port_a) annotation (Line(points={{-38,2},
{-22,2}}, color={0,127,255}));
connect(fan.port_a, senMasFlo1.port_b)
annotation (Line(points={{8,-34},{24,-34}}, 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(product.y, prescribedHeatFlow.Q_flow) annotation (Line(points={{-1.5,67},
{16,67},{16,52},{54,52},{54,26}}, 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}));
connect(senMasFlo3.port_a, fan.port_b)
annotation (Line(points={{-26,-34},{-12,-34}}, 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}));
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}));
connect(senMasFlo3.m_flow, fieldMassflow_in)
annotation (Line(points={{-32,-40.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}));
connect(senTem3.port, senMasFlo2.port_a)
annotation (Line(points={{7,24},{7,2},{22,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(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},
{-76,-70},{-82,-70},{-82,-24}}, color={0,127,255}));
annotation (Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,
-100},{120,100}})), Diagram(
coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{100,
100}})));
end SimpleModelGeo_2;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ControlledSystemBoundaries
SimpleModelGeo_2
SimpleModelGeo
SimpleModelGeo_2
2 changes: 1 addition & 1 deletion pyDMPC/ModelicaModels/ModelicaModels/dsin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Modelica experiment file
double experiment(7,1)
0 # StartTime Time at which integration starts
# (and linearization and trimming time)
3600 # StopTime Time at which integration stops
86400 # StopTime Time at which integration stops
10 # Increment Communication step size, if > 0
0 # nInterval Number of communication intervals, if > 0
1.0000000000000000E-004 # Tolerance Relative precision of signals for
Expand Down

0 comments on commit 9abd718

Please sign in to comment.