Skip to content

Commit

Permalink
* Init_simple and Subsystem_simple added to Control Framework for Sim…
Browse files Browse the repository at this point in the history
…ple Models, #55
  • Loading branch information
MStillerEBC committed Sep 3, 2019
1 parent 30fee76 commit e2130b4
Show file tree
Hide file tree
Showing 8 changed files with 568 additions and 30 deletions.
19 changes: 9 additions & 10 deletions pyDMPC/ControlFramework/Init.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@
model_type.append("Linear")
ups_neigh.append(None)
downs_neigh.append(1)
input_names.append(["supplyTemperature.T"])
input_names.append(["supplyTemperature"])
input_variables.append([r"variation.table[1,2]"])
inputs.append(range(280,290,5))
output_names.append(["returnTemperature"])
set_points.append([287])
state_var_names.append(["const.y"])
model_state_var_names.append(["const.k"]) #"const.k"
state_var_names.append(["const.k"])
model_state_var_names.append(["sum1.y"]) #"const.k"
start.append(0.)
stop.append(7200.)
incr.append(10.)
Expand All @@ -83,13 +83,13 @@
lib_paths.append(glob_lib_paths)
res_path.append(glob_res_path + "\\" + name_wkdir)
dym_path.append(glob_dym_path)
mod_path.append(r'ModelicaModels.SubsystemModels.DetailedModels.Geo.Building')
mod_path.append(r'ModelicaModels.SubsystemModels.DetailedModels.Geo.GeothermalHeatPump')
command_names.append(["heatShare"])
command_variables.append(["decisionVariables.table[1,2]"])
commands.append(range(0,105,5))
commands.append(range(35,45,5))
traj_points.append([])
traj_var.append([])
cost_fac.append([-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3000.0, -3000.0])
cost_fac.append([-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3000.0, -3000.0, 10.0, 2.0])
factors.append([1, -60./4.18/8./100.])

sys_id.append(1)
Expand All @@ -112,13 +112,12 @@
lib_paths.append(glob_lib_paths)
res_path.append(glob_res_path + "\\" + name_wkdir)
dym_path.append(glob_dym_path)
mod_path.append(r'ModelicaModels.SubsystemModels.DetailedModels.Geo.Field')
mod_path.append(r'ModelicaModels.SubsystemModels.DetailedModels.Geo.Field2')
command_names.append(["traj"])
command_variables.append(["decisionVariables.table[1,2]"])
commands.append(range(0,105,5))
traj_points.append(range(280,290,1))
traj_var.append(["supplyTemperature.T"])
cost_fac.append([-1.0, 0.0, 10.0, -10.0, 0.0, 0.0, 0.0, 0.0 ])
cost_fac.append([-1.0, 0.0, 10.0, -10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
factors.append([0,0])
#Legend: cost_fac.append([real_cost, cost_downstr_neigh, cost_dev_setpoint_penalty, cost_dev_setpoint_reward, cost_integ_penalty, cost_integ_reward, cost_diff_penalty, cost_diff_reward])

#Legend: cost_fac.append([real_cost_field, cost_downstr_neigh, cost_dev_setpoint_penalty, cost_dev_setpoint_reward, cost_integ_penalty, cost_integ_reward, cost_diff_penalty, cost_diff_reward, real_cost_boiler, real_cost_heatpump])
14 changes: 7 additions & 7 deletions pyDMPC/ControlFramework/Init_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@
model_type.append("Linear")
ups_neigh.append(None)
downs_neigh.append(1)
input_names.append(["supplyTemperature.T"])
input_names.append(["supplyTemperature"])
input_variables.append([r"variation.table[1,2]"])
inputs.append(range(280,290,5))
output_names.append(["returnTemperature"])
set_points.append([287])
state_var_names.append(["const.y"])
model_state_var_names.append(["const.k"]) #"const.k"
state_var_names.append(["const.k"])
model_state_var_names.append(["sum1.y"]) #"const.k"
start.append(0.)
stop.append(7200.)
incr.append(10.)
Expand All @@ -89,7 +89,7 @@
commands.append(range(35,45,5))
traj_points.append([])
traj_var.append([])
cost_fac.append([-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3000.0, -3000.0])
cost_fac.append([-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3000.0, -3000.0, 10.0, 2.0])
factors.append([1, -60./4.18/8./100.])

sys_id.append(1)
Expand All @@ -112,12 +112,12 @@
lib_paths.append(glob_lib_paths)
res_path.append(glob_res_path + "\\" + name_wkdir)
dym_path.append(glob_dym_path)
mod_path.append(r'ModelicaModels.SubsystemModels.DetailedModels.Geo.Field')
mod_path.append(r'ModelicaModels.SubsystemModels.DetailedModels.Geo.Field2')
command_names.append(["traj"])
command_variables.append(["decisionVariables.table[1,2]"])
commands.append(range(0,105,5))
traj_points.append(range(280,290,1))
traj_var.append(["supplyTemperature.T"])
cost_fac.append([-1.0, 0.0, 10.0, -10.0, 0.0, 0.0, 0.0, 0.0 ])
cost_fac.append([-1.0, 0.0, 10.0, -10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
factors.append([0,0])
#Legend: cost_fac.append([real_cost, cost_downstr_neigh, cost_dev_setpoint_penalty, cost_dev_setpoint_reward, cost_integ_penalty, cost_integ_reward, cost_diff_penalty, cost_diff_reward])
#Legend: cost_fac.append([real_cost_field, cost_downstr_neigh, cost_dev_setpoint_penalty, cost_dev_setpoint_reward, cost_integ_penalty, cost_integ_reward, cost_diff_penalty, cost_diff_reward, real_cost_boiler, real_cost_heatpump])
124 changes: 124 additions & 0 deletions pyDMPC/ControlFramework/Init_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Global paths
glob_lib_paths = [r'C:\mst\pyDMPC\pyDMPC\ModelicaModels\ModelicaModels',
r'C:\mst\modelica-buildings\Buildings',
r'C:\mst\AixLib\AixLib']
glob_res_path = r'C:\mst\dymola'
glob_dym_path = r'C:\Program Files (x86)\Dymola 2018\Modelica\Library\python_interface\dymola.egg'

# Working directory
import time
timestr = time.strftime("%Y%m%d_%H%M%S")
name_wkdir = r'pyDMPC_' + 'wkdir' + timestr

# Controlled system
contr_sys_typ = "Modelica"
ads_id = '5.59.199.202.1.1'
ads_port = 851
name_fmu = 'pyDMPCFMU_Geo.fmu'
orig_fmu_path = glob_res_path + '\\' + name_fmu
dest_fmu_path = glob_res_path + '\\' + name_wkdir + '\\' + name_fmu
time_incr = 120

# States
inputs = []
input_names = []
traj_points = []
input_variables = []
commands = []
command_variables = []
output_names = []
set_points = []
state_var_names = []
model_state_var_names = []
traj_var = []

# Times
start = []
stop = []
incr = []
opt_time = []
samp_time = []

# Paths
lib_paths = []
res_path = []
dym_path = []
mod_path = []
command_names = []

# Modifiers
cost_fac = []
factors = []

# Variation
min_var = []
max_var = []
inc_var = []

# Subsystem Config
model_type = []
name = []
sys_id = []
ups_neigh = []
downs_neigh = []

# Subsystems
sys_id.append(0)
name.append("Building")
model_type.append("Linear")
ups_neigh.append(None)
downs_neigh.append(1)
input_names.append(["supplyTemperature.T"])
input_variables.append([r"variation.table[1,2]"])
inputs.append(range(280,290,5))
output_names.append(["returnTemperature"])
set_points.append([287])
state_var_names.append(["const.y"])
model_state_var_names.append(["const.k"]) #"const.k"
start.append(0.)
stop.append(7200.)
incr.append(10.)
opt_time.append(3600)
samp_time.append(10)
lib_paths.append(glob_lib_paths)
res_path.append(glob_res_path + "\\" + name_wkdir)
dym_path.append(glob_dym_path)
mod_path.append(r'ModelicaModels.SubsystemModels.DetailedModels.Geo.Building')
command_names.append(["heatShare"])
command_variables.append(["decisionVariables.table[1,2]"])
commands.append(range(0,105,5))
traj_points.append([])
traj_var.append([])
cost_fac.append([-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3000.0, -3000.0])
factors.append([1, -60./4.18/8./100.])

sys_id.append(1)
name.append("Field")
model_type.append("Modelica")
ups_neigh.append(0)
downs_neigh.append(None)
input_names.append(["returnTemperature.T"])
input_variables.append(["external"])
inputs.append([])
output_names.append(["movMea.y"])
set_points.append([285.65])
state_var_names.append(["supplyTemperature.T"])
model_state_var_names.append(["vol.T_start"])
start.append(0.)
stop.append(3600.0*24*365.25*3)
incr.append(3600.)
opt_time.append(86400)
samp_time.append(10)
lib_paths.append(glob_lib_paths)
res_path.append(glob_res_path + "\\" + name_wkdir)
dym_path.append(glob_dym_path)
mod_path.append(r'ModelicaModels.SubsystemModels.DetailedModels.Geo.Field')
command_names.append(["traj"])
command_variables.append(["decisionVariables.table[1,2]"])
commands.append(range(0,105,5))
traj_points.append(range(280,290,1))
traj_var.append(["supplyTemperature.T"])
cost_fac.append([-1.0, 0.0, 10.0, -10.0, 0.0, 0.0, 0.0, 0.0 ])
factors.append([0,0])
#Legend: cost_fac.append([real_cost, cost_downstr_neigh, cost_dev_setpoint_penalty, cost_dev_setpoint_reward, cost_integ_penalty, cost_integ_reward, cost_diff_penalty, cost_diff_reward])

10 changes: 5 additions & 5 deletions pyDMPC/ControlFramework/Subsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ def calc_cost(self, command, outputs):

cost = self.cost_fac[0] * command

#if self.cost_rec != []:
#energy_heater = self.model.get_results("chemicalEnergy[-1]")
#cost += self.cost_fac[1] * energy_heater #Realkosten Chiller/Heater
#energy_heatpump = self.model.get_results("heatPumpEnergy[-1]")
#cost += self.cost_fac[2] * energy_heatpump #Realkosten Strom Wärmepumpe
if self.cost_rec != []:
energy_heater = self.model.get_results("chemicalEnergy[-1]")
cost += cost_fac[8] * energy_heater #Realkosten Chiller/Heater
energy_heatpump = self.model.get_results("heatPumpEnergy[-1]")
cost += cost_fac[9] * energy_heatpump #Realkosten Strom Wärmepumpe

if self.cost_rec != []:
if type(self.cost_rec) is scipy.interpolate.interpolate.interp1d:
Expand Down
10 changes: 5 additions & 5 deletions pyDMPC/ControlFramework/Subsystem_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ def calc_cost(self, command, outputs):

cost = self.cost_fac[0] * command

#if self.cost_rec != []:
#energy_heater = self.model.get_results("chemicalEnergy[-1]")
#cost += self.cost_fac[1] * energy_heater #Realkosten Chiller/Heater
#energy_heatpump = self.model.get_results("heatPumpEnergy[-1]")
#cost += self.cost_fac[2] * energy_heatpump #Realkosten Strom Wärmepumpe
if self.cost_rec != []:
energy_heater = self.model.get_results("chemicalEnergy[-1]")
cost += cost_fac[8] * energy_heater #Realkosten Chiller/Heater
energy_heatpump = self.model.get_results("heatPumpEnergy[-1]")
cost += cost_fac[9] * energy_heatpump #Realkosten Strom Wärmepumpe

if self.cost_rec != []:
if type(self.cost_rec) is scipy.interpolate.interpolate.interp1d:
Expand Down
Loading

0 comments on commit e2130b4

Please sign in to comment.