Skip to content

Commit

Permalink
* Long term simulation of the field, #33
Browse files Browse the repository at this point in the history
adding python scripts for calculating trajectory and long term temperature into field
adjusting objective function for long term information
  • Loading branch information
MStillerEBC committed May 2, 2019
1 parent 9abd718 commit 8b2c9b6
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 13 deletions.
39 changes: 27 additions & 12 deletions pyDMPC/ControlFramework/Heatdemand.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import xlrd
import scipy
from scipy.integrate import simps
import os

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

Expand All @@ -26,24 +27,38 @@ def read_excel_file(Grafana3):

#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
Q_flow_geo = np.asarray(cp_water*rho_water*(vol_flow/60000)*dT) #in kW
#COP = np.asarray((Q_flow + Pel)/Pel) #if COP(T)
#COP = 3.5 #if COP = konst
#
#if Q_flow_geo >0:
# Q_flow = np.asarray((COP/(COP-1))*Q_flow_geo)
#else:
# Q_flow = Q_flow_geo

##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")
np.savetxt("C:\mst\Grafana\Q_flow.csv", np.c_([time], [Q_flow_geo]), delimiter=",")

#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))

#
#
#
##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))
#
8 changes: 7 additions & 1 deletion pyDMPC/ControlFramework/Objective_Function.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import Init
import numpy as np
import pickle

'''Global variables used for simulation handling'''
# Variable indicating if the subsystem model is compiled
Expand Down Expand Up @@ -209,8 +210,11 @@ def Obj(values_DVs, BC, s):
print("cost_total: " + str(cost_total))
print("output: " + str(tout))
else:
pickle_in = open("T_set.pickle","rb")
T_set = pickle.load(pickle_in)

for tout in output_traj[0]:
cost_total += Init.cost_factor*(values_DVs - s.Q_set)**2 + Init.cost_factor*(tout - s.T_set)**2
cost_total += Init.cost_factor*(values_DVs - s.Q_set)**2 + Init.cost_factor*(tout - T_set)**2
#cost_total += max(0.01,cost_par[k])*Init.cost_factor + 100*(max(abs(tout-273-Init.set_point[0])-Init.tolerance,0))**2
k += 1

Expand All @@ -219,6 +223,8 @@ 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 added pyDMPC/ControlFramework/T_set.pickle
Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions pyDMPC/ControlFramework/field_long.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import xlrd
import scipy
from scipy.integrate import simps
import pickle

#field temperature regarding the longterm set temperature = trajectory
T_set = 285*np.ones(3*365*24) #Vorlauftemperatur ins Feld (Soll)
pickle_out = open("T_set.pickle","wb")
pickle.dump(T_set, pickle_out)
30 changes: 30 additions & 0 deletions pyDMPC/ControlFramework/trajectory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import xlrd
import scipy
from scipy.integrate import simps

#Gebäudebedarf
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)
m_flow = 0.5 #kg/s

#Wärmebedarf
#Annahme: jeder Tag in einem Monat x hat das selbe Lastprofil und hat denselben Energiebedarf (Q_flow=konst)
day_heatneed = np.array(Q_need_heat/days) #Wärmebedarf eines Tages des Monats x
Q_heatflow_day = np.array(day_heatneed/24) #benötigter übertragener Wärmestrom an Warmwasserkreislauf[kW]
#welche Temperaturdifferenz ist für den benötigten Wärmestrom nötig
dT_heat = np.array(Q_heatflow_day/(m_flow*cp_water))

#Kältebedarf
day_coldneed = np.array(Q_need_cold/days) #Wärmebedarf eines Tages des Monats x
Q_coldflow_day = np.array(day_coldneed/24) #benötigter übertragener Wärmestrom an Warmwasserkreislauf[kW]
#welche Temperaturdifferenz ist für den benötigten Kältestrom nötig
dT_cold = np.array(Q_coldflow_day/(m_flow*cp_water))

#effektiver Wärme/Kältebedarf eines Tages eines Monats
dQ_flow_day = np.array(Q_heatflow_day - Q_coldflow_day)
dT = np.array(dQ_flow_day/(m_flow*cp_water))

0 comments on commit 8b2c9b6

Please sign in to comment.