-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Field and Field_new models for longterm simulation & Building model…
… modified, python script for field_long modified, Init adaption in progress #33
- Loading branch information
1 parent
3e62c19
commit f2421b3
Showing
19 changed files
with
995 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* linguist-vendored | ||
*.py linguist-vendored=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
pyDMPC/ControlFramework/__pycache__/Objective_Function.cpython-36.pyc
Binary file not shown.
Binary file modified
BIN
+49 Bytes
(100%)
pyDMPC/ControlFramework/__pycache__/Subsystem.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+156 Bytes
(100%)
pyDMPC/ControlFramework/algorithm/__pycache__/BExMoC.cpython-36.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,105 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
#import matplotlib.pyplot as plt | ||
import pandas as pd | ||
import xlrd | ||
import scipy | ||
from scipy.integrate import simps | ||
#import xlrd | ||
#import scipy | ||
#from scipy.integrate import simps | ||
import pickle | ||
import os | ||
import sys | ||
|
||
import scipy.io as sio | ||
import Init | ||
# | ||
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 | ||
|
||
from modelicares import SimRes | ||
# Start the interface | ||
dymola = DymolaInterface() | ||
|
||
# Location of your libraries | ||
path_lib1 = r'C:\mst\pyDMPC\pyDMPC\ModelicaModels\ModelicaModels' | ||
path_lib2 = r'C:\mst\modelica-buildings\Buildings' | ||
path_lib3 = r'C:\mst\AixLib\Aixlib' | ||
path_lib1 = r'C:\\mst\\pyDMPC\\pyDMPC\\ModelicaModels\\ModelicaModels' | ||
path_lib2 = r'C:\\mst\\modelica-buildings\\Buildings' | ||
path_lib3 = r'C:\\mst\\AixLib\\Aixlib' | ||
path_lib = [path_lib1, path_lib2, path_lib3] | ||
|
||
# Location where to store the results | ||
path_res = r'C:\mst\dymola\Geo_long' | ||
path_res = r'C:\\mst\\dymola\\Geo_long\\' | ||
|
||
# Name of the main working directory | ||
import time | ||
timestr = time.strftime("%Y%m%d_%H%M%S") | ||
name_wkdir = r'pyDMPC_' + 'wkdir' + timestr | ||
|
||
# Open AixLib | ||
# Open AixLib, Buildings & pyDMPC Modlica Models | ||
dymola.openModel(path=os.path.join(path_lib3, 'package.mo')) | ||
dymola.openModel(path=os.path.join(path_lib2, 'package.mo')) | ||
dymola.openModel(path=os.path.join(path_lib1, 'package.mo')) | ||
|
||
# Translate any model you'd like to simulate | ||
dymola.translateModel('ModelicaModels.SubsystemModels.DetailedModels.Geo.Field') | ||
#obj_fnc_val = 'objectiveFunction' | ||
|
||
#parameters of the field model | ||
|
||
#Input: combiTable "variation": heatflow of the houses need, m_flow | ||
Q0_heat = np.array([500, 600, 300, 100, 50, 10, 0, 5, 80, 250, 300, 450]) | ||
Q0_cold = np.array([25, 25, 110, 200, 400, 600, 650, 600, 450, 300, 150, 50]) | ||
Q0_heat = np.array([5000, 6000, 3000, 1000, 500, 100, 0, 50, 800, 2500, 3000, 4500]) #in kWh | ||
Q0_cold = np.array([250, 250, 1100, 2000, 4000, 6000, 6500, 6000, 4500, 3000, 1500, 500]) #in kWh | ||
days = np.array([31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]) | ||
dQ = np.array(Q0_heat/days - Q0_cold/days) #in kWh | ||
dQ = np.array(Q0_heat/days - Q0_cold/days) #in kWh/day | ||
dt = 24 | ||
Q_flow = np.divide(dQ*1000,dt) #in W | ||
|
||
#Q_set as needed heatflow every hour a year | ||
#Q_set as needed heatflow every hour a year in W | ||
Q_set = [Q_flow[0]] *days[0] *24 + [Q_flow[1]] *days[1] *24 + [Q_flow[2]] *days[2] *24 + \ | ||
[Q_flow[3]] *days[3] *24 + [Q_flow[4]] *days[4] *24 + [Q_flow[5]] *days[5] *24 + \ | ||
[Q_flow[6]] *days[6] *24 + [Q_flow[7]] *days[7] *24 + [Q_flow[8]] *days[8] *24 + \ | ||
[Q_flow[9]] *days[9] *24 + [Q_flow[10]] *days[10] *24 + [Q_flow[11]] *days[11] *24 | ||
|
||
m_flow = [0.00025]*365 #in m³/s | ||
V_flow = 0.00025 #in m³/s | ||
rho = 1000 | ||
m_flow = [V_flow*rho]*8760 #in kg/s | ||
|
||
starttime = 0.0 | ||
stoptime = 1*365*24*3600 | ||
time = np.arange(0, stoptime, 3600) | ||
|
||
tab = np.array([time] + [Q_set] + [m_flow]) | ||
BC_array = tab.transpose(1,0) | ||
|
||
tab1 = np.array([Q_set], [m_flow]) | ||
sio.savemat((path_res +'\\'+ Init.fileName_BCsInputTable + '.mat'), {Init.tableName_BCsInputTable :BC_array}) | ||
|
||
#testList = [variation.column[1],variation.column[2]] | ||
#testValues = [BC_array[1],BC_array[2]] | ||
testList = [''] | ||
testValues = [None] | ||
variable_name=[''] | ||
final_names = ['supplyTemperature.T'] | ||
|
||
# Simulate the model | ||
output = dymola.simulateExtendedModel( | ||
problem='', | ||
startTime=0.0, | ||
stopTime=94608000, | ||
outputInterval=3600, | ||
method="Dassl", | ||
tolerance=0.0001, | ||
resultFile=os.path.join(dir_result, 'demo_results'), | ||
finalNames=[''], | ||
) | ||
|
||
problem = 'ModelicaModels.SubsystemModels.DetailedModels.Geo.Field_new', | ||
startTime = starttime, | ||
stopTime = stoptime, | ||
outputInterval = 3600, | ||
method = "Dassl", | ||
tolerance = 1, | ||
resultFile = path_res +'dsres', | ||
finalNames = final_names, | ||
initialNames = testList, | ||
initialValues = testValues | ||
) | ||
dymola.close() | ||
|
||
#field temperature regarding the longterm set temperature = trajectory | ||
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) | ||
sim = SimRes(path_res + 'dsres' + '.mat') | ||
sol = sim.to_pandas(variable_name) | ||
|
||
#pickling field temperature | ||
#T0 = 285 #ungestörte Erdreichtemperatur | ||
#T_set = T0*np.ones(3*365*24) #Vorlauftemperatur ins Feld (Soll) | ||
|
||
#pickle_out = open(path_res + "\\" + "T_out.pickle","wb") | ||
#pickle.dump(T_out, pickle_out) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
pyDMPC/ModelicaModels/ModelicaModels/SubsystemModels/DetailedModels/CoolerML.mo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
within ModelicaModels.SubsystemModels.DetailedModels; | ||
model CoolerML "Detailed model of the cooler for machine learning" | ||
|
||
extends ModelicaModels.Subsystems.BaseClasses.CoolerBaseClass; | ||
Modelica.Fluid.Sources.MassFlowSource_T IntakeAirSource( | ||
nPorts=1, | ||
m_flow=0.5, | ||
redeclare package Medium = MediumAir, | ||
X={0.03,0.97}, | ||
T=30 + 273.15, | ||
use_X_in=true, | ||
use_T_in=true, | ||
use_m_flow_in=true) | ||
annotation (Placement(transformation(extent={{-60,60},{-40,80}}))); | ||
Modelica.Fluid.Sources.Boundary_pT IntakeAirSink( | ||
nPorts=1, | ||
redeclare package Medium = MediumAir, | ||
use_T_in=false, | ||
use_X_in=false, | ||
use_p_in=false, | ||
p(displayUnit="Pa") = 101300) | ||
annotation (Placement(transformation(extent={{120,60},{100,80}}))); | ||
AixLib.Utilities.Psychrometrics.ToTotalAir toTotAir | ||
annotation (Placement(transformation(extent={{-110,56},{-90,76}}))); | ||
AixLib.Fluid.Sensors.Temperature supplyAirTemperature(redeclare package | ||
Medium = MediumAir) "Temperature of supply air" | ||
annotation (Placement(transformation(extent={{32,88},{52,108}}))); | ||
Modelica.Blocks.Sources.RealExpression realExpression3[4](y=hex.ele[:].mas.T) | ||
annotation (Placement(transformation(extent={{52,-124},{72,-104}}))); | ||
Modelica.Blocks.Interfaces.RealOutput hexele1masT "Value of Real output" | ||
annotation (Placement(transformation(extent={{92,-108},{112,-88}}))); | ||
Modelica.Blocks.Interfaces.RealOutput hexele2masT "Value of Real output" | ||
annotation (Placement(transformation(extent={{92,-118},{112,-98}}))); | ||
Modelica.Blocks.Interfaces.RealOutput hexele3masT "Value of Real output" | ||
annotation (Placement(transformation(extent={{92,-128},{112,-108}}))); | ||
Modelica.Blocks.Interfaces.RealOutput hexele4masT "Value of Real output" | ||
annotation (Placement(transformation(extent={{92,-138},{112,-118}}))); | ||
Modelica.Blocks.Interfaces.RealOutput supplyTemp "Temperature in port medium" | ||
annotation (Placement(transformation(extent={{126,88},{146,108}}))); | ||
Modelica.Blocks.Interfaces.RealInput valveOpening "Input signal connector" | ||
annotation (Placement(transformation(extent={{-160,-70},{-120,-30}}))); | ||
Modelica.Blocks.Sources.Constant x(k=0.007) annotation (Placement( | ||
transformation( | ||
extent={{10,-10},{-10,10}}, | ||
rotation=180, | ||
origin={-130,66}))); | ||
Modelica.Blocks.Sources.Constant mflow(k=0.35) annotation (Placement( | ||
transformation( | ||
extent={{10,-10},{-10,10}}, | ||
rotation=180, | ||
origin={-100,100}))); | ||
Modelica.Blocks.Interfaces.RealInput inflowTemp | ||
"Prescribed fluid temperature" | ||
annotation (Placement(transformation(extent={{-160,0},{-120,40}}))); | ||
Modelica.Thermal.HeatTransfer.Celsius.ToKelvin toKelvin annotation ( | ||
Placement(transformation( | ||
extent={{10,-10},{-10,10}}, | ||
rotation=180, | ||
origin={-84,20}))); | ||
Modelica.Thermal.HeatTransfer.Celsius.FromKelvin | ||
fromKelvin | ||
annotation ( | ||
Placement(transformation( | ||
extent={{10,-10},{-10,10}}, | ||
rotation=180, | ||
origin={82,98}))); | ||
equation | ||
connect(toTotAir.XiTotalAir, IntakeAirSource.X_in[1]) | ||
annotation (Line(points={{-89,66},{-62,66}}, color={0,0,127})); | ||
connect(toTotAir.XNonVapor, IntakeAirSource.X_in[2]) annotation (Line(points= | ||
{{-89,62},{-82,62},{-82,66},{-62,66}}, color={0,0,127})); | ||
connect(IntakeAirSource.ports[1], hex.port_a2) | ||
annotation (Line(points={{-40,70},{-12,70}}, color={0,127,255})); | ||
connect(hex.port_b2, IntakeAirSink.ports[1]) | ||
annotation (Line(points={{8,70},{100,70}}, color={0,127,255})); | ||
connect(realExpression3[1].y, hexele1masT) annotation (Line(points={{73,-114}, | ||
{84,-114},{84,-98},{102,-98}}, color={0,0,127})); | ||
connect(realExpression3[2].y, hexele2masT) annotation (Line(points={{73,-114}, | ||
{84,-114},{84,-108},{102,-108}}, color={0,0,127})); | ||
connect(realExpression3[3].y, hexele3masT) annotation (Line(points={{73,-114}, | ||
{82,-114},{82,-118},{102,-118}}, color={0,0,127})); | ||
connect(realExpression3[4].y, hexele4masT) annotation (Line(points={{73,-114}, | ||
{84,-114},{84,-128},{102,-128}}, color={0,0,127})); | ||
connect(hex.port_b2, supplyAirTemperature.port) annotation (Line(points={{8, | ||
70},{26,70},{26,88},{42,88}}, color={0,127,255})); | ||
connect(convertCommand.u, valveOpening) | ||
annotation (Line(points={{-103.2,-50},{-140,-50}}, color={0,0,127})); | ||
connect(toTotAir.XiDry, x.y) | ||
annotation (Line(points={{-111,66},{-119,66}}, color={0,0,127})); | ||
connect(mflow.y, IntakeAirSource.m_flow_in) annotation (Line(points={{-89,100}, | ||
{-74,100},{-74,78},{-60,78}}, color={0,0,127})); | ||
connect(inflowTemp, toKelvin.Celsius) | ||
annotation (Line(points={{-140,20},{-96,20}}, color={0,0,127})); | ||
connect(toKelvin.Kelvin, IntakeAirSource.T_in) annotation (Line(points={{-73, | ||
20},{-70,20},{-70,74},{-62,74}}, color={0,0,127})); | ||
connect(supplyAirTemperature.T, fromKelvin.Kelvin) | ||
annotation (Line(points={{49,98},{70,98}}, color={0,0,127})); | ||
connect(fromKelvin.Celsius, supplyTemp) | ||
annotation (Line(points={{93,98},{136,98}}, color={0,0,127})); | ||
annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram( | ||
coordinateSystem(preserveAspectRatio=false)), | ||
experiment(StopTime=100000, Interval=10)); | ||
end CoolerML; |
Oops, something went wrong.