Skip to content

Commit

Permalink
Refactoring and enhancing to support multiple GHEs in a single distri…
Browse files Browse the repository at this point in the history
…ct (#601)

* use ghe ids and data from ThermalNetwork demo 2

* refactor sys_params.get_param_by_id to take any id, not just buildings

* refactor usage of get_param_by_building_id to get_param_by_id

* fix ghe_dir path in test sys-param file

* handle non-ghe districts

* test for getting param by ghe_id

* rename gfunction dir because I changed the ghe_id in the test sys-param file

* use consistent ghe_id across tests so paths work as expected
  • Loading branch information
vtnate authored Nov 24, 2023
1 parent 9aad27c commit e90cb3e
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 105 deletions.
2 changes: 1 addition & 1 deletion geojson_modelica_translator/geojson_modelica_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _parse_couplings(geojson, sys_params, district_type=None):

# create the loads and their ETSes
for building in geojson.buildings:
load_model_type = sys_params.get_param_by_building_id(building.id, "load_model")
load_model_type = sys_params.get_param_by_id(building.id, "load_model")
load_class = LOAD_MODEL_TO_CLASS[load_model_type]
load = load_class(sys_params, building)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def to_modelica(self):
coupling_load = coupling.get_load()
if coupling_load is not None:
# read sys params file for the load
building_sys_params = self.system_parameters.get_param_by_building_id(coupling_load.building_id, '$')
building_sys_params = self.system_parameters.get_param_by_id(coupling_load.building_id, '$')
template_context['sys_params']['building'] = building_sys_params
# Note which load is being used, so ports connect properly in couplings/5G_templates/ConnectStatements
template_context['sys_params']['load_num'] = load_num
Expand All @@ -128,7 +128,7 @@ def to_modelica(self):
template_params.update(**common_template_params)

if issubclass(type(model), LoadBase):
building_sys_params = self.system_parameters.get_param_by_building_id(model.building_id, '$')
building_sys_params = self.system_parameters.get_param_by_id(model.building_id, '$')
template_params['sys_params']['building'] = building_sys_params

templated_instance, instance_template_path = model.render_instance(template_params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def to_modelica(self, scaffold):
"""
cooling_indirect_template = self.template_env.get_template("CoolingIndirect.mot")

ets_data = self.system_parameters.get_param_by_building_id(
ets_data = self.system_parameters.get_param_by_id(
self._geojson_load_id,
'ets_indirect_parameters'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def to_modelica(self, scaffold):
"""
heating_indirect_template = self.template_env.get_template("HeatingIndirect.mot")

ets_data = self.system_parameters.get_param_by_building_id(
ets_data = self.system_parameters.get_param_by_id(
self._geojson_load_id,
"ets_indirect_parameters"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,58 +40,58 @@ def __init__(self, system_parameters, geojson_load):
# TODO: Decide if we're requiring sys-param file, and if all loads have an ets.
# test_base.py and test_time_series.py test these cases
if system_parameters is not None:
if self.system_parameters.get_param_by_building_id(
if self.system_parameters.get_param_by_id(
self.building_id, "ets_indirect_parameters") is not None:
self.ets_template_data = {
"heat_flow_nominal": self.system_parameters.get_param_by_building_id(
"heat_flow_nominal": self.system_parameters.get_param_by_id(
self.building_id, "ets_indirect_parameters.heat_flow_nominal"
),
"heat_exchanger_efficiency": self.system_parameters.get_param_by_building_id(
"heat_exchanger_efficiency": self.system_parameters.get_param_by_id(
self.building_id, "ets_indirect_parameters.heat_exchanger_efficiency"
),
"nominal_mass_flow_district": self.system_parameters.get_param_by_building_id(
"nominal_mass_flow_district": self.system_parameters.get_param_by_id(
self.building_id, "ets_indirect_parameters.nominal_mass_flow_district"
),
"nominal_mass_flow_building": self.system_parameters.get_param_by_building_id(
"nominal_mass_flow_building": self.system_parameters.get_param_by_id(
self.building_id, "ets_indirect_parameters.nominal_mass_flow_building"
),
"valve_pressure_drop": self.system_parameters.get_param_by_building_id(
"valve_pressure_drop": self.system_parameters.get_param_by_id(
self.building_id, "ets_indirect_parameters.valve_pressure_drop"
),
"heat_exchanger_secondary_pressure_drop": self.system_parameters.get_param_by_building_id(
"heat_exchanger_secondary_pressure_drop": self.system_parameters.get_param_by_id(
self.building_id, "ets_indirect_parameters.heat_exchanger_secondary_pressure_drop"
),
"heat_exchanger_primary_pressure_drop": self.system_parameters.get_param_by_building_id(
"heat_exchanger_primary_pressure_drop": self.system_parameters.get_param_by_id(
self.building_id, "ets_indirect_parameters.heat_exchanger_primary_pressure_drop"
),
"cooling_supply_water_temperature_building": convert_c_to_k(self.system_parameters.get_param_by_building_id(
"cooling_supply_water_temperature_building": convert_c_to_k(self.system_parameters.get_param_by_id(
self.building_id, "ets_indirect_parameters.cooling_supply_water_temperature_building"
)),
"heating_supply_water_temperature_building": convert_c_to_k(self.system_parameters.get_param_by_building_id(
"heating_supply_water_temperature_building": convert_c_to_k(self.system_parameters.get_param_by_id(
self.building_id, "ets_indirect_parameters.heating_supply_water_temperature_building"
)),
"delta_temp_chw_building": self.system_parameters.get_param_by_building_id(
"delta_temp_chw_building": self.system_parameters.get_param_by_id(
self.building_id, "ets_indirect_parameters.delta_temp_chw_building"
),
"delta_temp_chw_district": self.system_parameters.get_param_by_building_id(
"delta_temp_chw_district": self.system_parameters.get_param_by_id(
self.building_id, "ets_indirect_parameters.delta_temp_chw_district"
),
"delta_temp_hw_building": self.system_parameters.get_param_by_building_id(
"delta_temp_hw_building": self.system_parameters.get_param_by_id(
self.building_id, "ets_indirect_parameters.delta_temp_hw_building"
),
"delta_temp_hw_district": self.system_parameters.get_param_by_building_id(
"delta_temp_hw_district": self.system_parameters.get_param_by_id(
self.building_id, "ets_indirect_parameters.delta_temp_hw_district"
),
"cooling_controller_y_max": self.system_parameters.get_param_by_building_id(
"cooling_controller_y_max": self.system_parameters.get_param_by_id(
self.building_id, "ets_indirect_parameters.cooling_controller_y_max"
),
"cooling_controller_y_min": self.system_parameters.get_param_by_building_id(
"cooling_controller_y_min": self.system_parameters.get_param_by_id(
self.building_id, "ets_indirect_parameters.cooling_controller_y_min"
),
"heating_controller_y_max": self.system_parameters.get_param_by_building_id(
"heating_controller_y_max": self.system_parameters.get_param_by_id(
self.building_id, "ets_indirect_parameters.heating_controller_y_max"
),
"heating_controller_y_min": self.system_parameters.get_param_by_building_id(
"heating_controller_y_min": self.system_parameters.get_param_by_id(
self.building_id, "ets_indirect_parameters.heating_controller_y_min"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,48 +49,48 @@ def to_modelica(self, scaffold, keep_original_models=False):
# grab the data from the system_parameter file for this building id
# TODO: create method in system_parameter class to make this easier

idf_filename = self.system_parameters.get_param_by_building_id(
idf_filename = self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.spawn.idf_filename"
)
thermal_zones = self.system_parameters.get_param_by_building_id(
thermal_zones = self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.spawn.thermal_zone_names",
)
zone_nom_htg_loads = self.system_parameters.get_param_by_building_id(
zone_nom_htg_loads = self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.spawn.zone_nom_htg_loads",
)
zone_nom_clg_loads = self.system_parameters.get_param_by_building_id(
zone_nom_clg_loads = self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.spawn.zone_nom_clg_loads",
)
# TODO: pick up default value from schema if not specified in system_parameters,
# to avoid the inline if/then statement in nominal_values below
has_liquid_heating = self.system_parameters.get_param_by_building_id(
has_liquid_heating = self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.spawn.has_liquid_heating",
)
has_liquid_cooling = self.system_parameters.get_param_by_building_id(
has_liquid_cooling = self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.spawn.has_liquid_cooling",
)
has_electric_heating = self.system_parameters.get_param_by_building_id(
has_electric_heating = self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.spawn.has_electric_heating",
)
has_electric_cooling = self.system_parameters.get_param_by_building_id(
has_electric_cooling = self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.spawn.has_electric_cooling",
)
hhw_supply_temp = convert_c_to_k(self.system_parameters.get_param_by_building_id(
hhw_supply_temp = convert_c_to_k(self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.spawn.temp_hw_supply",
))
hhw_return_temp = convert_c_to_k(self.system_parameters.get_param_by_building_id(
hhw_return_temp = convert_c_to_k(self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.spawn.temp_hw_return",
))
chw_supply_temp = convert_c_to_k(self.system_parameters.get_param_by_building_id(
chw_supply_temp = convert_c_to_k(self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.spawn.temp_chw_supply",
))
chw_return_temp = convert_c_to_k(self.system_parameters.get_param_by_building_id(
chw_return_temp = convert_c_to_k(self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.spawn.temp_chw_return",
))
temp_setpoint_cooling = convert_c_to_k(self.system_parameters.get_param_by_building_id(
temp_setpoint_cooling = convert_c_to_k(self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.spawn.temp_setpoint_cooling",
))
temp_setpoint_heating = convert_c_to_k(self.system_parameters.get_param_by_building_id(
temp_setpoint_heating = convert_c_to_k(self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.spawn.temp_setpoint_heating",
))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def to_modelica(self, scaffold, keep_original_models=False):
)

prj.used_library_calc = "IBPSA"
prj.number_of_elements_calc = self.system_parameters.get_param_by_building_id(
prj.number_of_elements_calc = self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.rc.order"
)
prj.merge_windows_calc = False
Expand Down Expand Up @@ -330,7 +330,7 @@ def post_process(self, scaffold, keep_original_models=False):
mofile.remove_connect('weaDat.weaBus', 'weaBus')

# add new port connections
rc_order = self.system_parameters.get_param_by_building_id(
rc_order = self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.rc.order"
)
thermal_zone_name = None
Expand Down Expand Up @@ -509,36 +509,36 @@ def post_process(self, scaffold, keep_original_models=False):
"path": os.path.dirname(mos_weather_filename),
},
"nominal_values": {
"chw_supply_temp": convert_c_to_k(self.system_parameters.get_param_by_building_id(
"chw_supply_temp": convert_c_to_k(self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.rc.temp_chw_supply"
)),
"chw_return_temp": convert_c_to_k(self.system_parameters.get_param_by_building_id(
"chw_return_temp": convert_c_to_k(self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.rc.temp_chw_return"
)),
"hhw_supply_temp": convert_c_to_k(self.system_parameters.get_param_by_building_id(
"hhw_supply_temp": convert_c_to_k(self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.rc.temp_hw_supply"
)),
"hhw_return_temp": convert_c_to_k(self.system_parameters.get_param_by_building_id(
"hhw_return_temp": convert_c_to_k(self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.rc.temp_hw_return"
)),
"temp_setpoint_heating": convert_c_to_k(self.system_parameters.get_param_by_building_id(
"temp_setpoint_heating": convert_c_to_k(self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.rc.temp_setpoint_heating"
)),
"temp_setpoint_cooling": convert_c_to_k(self.system_parameters.get_param_by_building_id(
"temp_setpoint_cooling": convert_c_to_k(self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.rc.temp_setpoint_cooling"
)),
# FIXME: pick up default value from schema if not specified in system_parameters,
# FYI: Modelica insists on booleans being lowercase, so we need to explicitly set "true" and "false"
"has_liquid_heating": "true" if self.system_parameters.get_param_by_building_id(
"has_liquid_heating": "true" if self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.rc.has_liquid_heating",
) else "false",
"has_liquid_cooling": "true" if self.system_parameters.get_param_by_building_id(
"has_liquid_cooling": "true" if self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.rc.has_liquid_cooling",
) else "false",
"has_electric_heating": "true" if self.system_parameters.get_param_by_building_id(
"has_electric_heating": "true" if self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.rc.has_electric_heating",
) else "false",
"has_electric_cooling": "true" if self.system_parameters.get_param_by_building_id(
"has_electric_cooling": "true" if self.system_parameters.get_param_by_id(
self.building_id, "load_model_parameters.rc.has_electric_cooling",
) else "false",
}
Expand Down
Loading

0 comments on commit e90cb3e

Please sign in to comment.