def test_get_param_with_none_building_id(self): filename = self.data_dir / 'system_params_1.json' sdp = SystemParameters(filename) self.maxDiff = None with self.assertRaises(SystemExit) as context: sdp.get_param_by_building_id(None, "ets_model", "Not None") self.assertIn( "No building_id submitted. Please retry and include the feature_id", str(context.exception))
def test_get_param_with_building_id(self): filename = os.path.abspath( "tests/system_parameters/data/system_params_1.json") sdp = SystemParameters(filename) value = sdp.get_param_by_building_id("abcd1234", "ets.system") self.assertEqual(value, "Booster Heater")
def test_get_param_with_building_id_defaults(self): filename = self.data_dir / 'system_params_1.json' sdp = SystemParameters(filename) self.maxDiff = None # ensure the defaults are respected. abcd1234 has NO metamodel defined value = sdp.get_param_by_building_id("abcd1234", "ets_model", "Not None") self.assertEqual("None", value) # grab the schema default value = sdp.get_param_by_building_id("defgh2345", "ets_model", "Not None") self.assertEqual("Indirect Heating and Cooling", value) value = sdp.get_param_by_building_id("defgh2345", "ets_model_parameters", "Not None") self.assertEqual( { "indirect": { "heat_flow_nominal": 8000, "heat_exchanger_efficiency": 0.8, "nominal_mass_flow_district": 0.5, "nominal_mass_flow_building": 0.5, "valve_pressure_drop": 6000, "heat_exchanger_secondary_pressure_drop": 500, "heat_exchanger_primary_pressure_drop": 500, "cooling_supply_water_temperature_building": 7, "heating_supply_water_temperature_building": 50, "delta_temp_chw_building": 5, "delta_temp_chw_district": 8, "delta_temp_hw_building": 15, "delta_temp_hw_district": 20, "cooling_controller_y_max": 1, "cooling_controller_y_min": 0, "heating_controller_y_max": 1, "heating_controller_y_min": 0 } }, value) # respect the passed default value value = sdp.get_param_by_building_id( "defgh2345", "ets_model_parameters.NominalFlow_Building", 24815) self.assertEqual(24815, value)
def test_expanded_paths(self): filename = self.data_dir / 'system_params_1.json' sdp = SystemParameters(filename) for s in sdp.validate(): print(s) value = sdp.get_param_by_building_id( "ijk678", "load_model_parameters.spawn.idf_filename") self.assertEqual(Path(value), Path(filename).parent / 'example_model.idf') value = sdp.get_param_by_building_id( "ijk678", "load_model_parameters.spawn.mos_weather_filename") self.assertEqual(Path(value), Path(filename).parent / 'example_weather.mos') value = sdp.get_param_by_building_id( "ijk678", "load_model_parameters.spawn.epw_filename") self.assertEqual(Path(value), Path(filename).parent / 'example_weather.epw') # verify that the second spawn paths resolve too. value = sdp.get_param_by_building_id( "lmn000", "load_model_parameters.spawn.idf_filename") self.assertEqual(Path(value), Path(filename).parent / 'example_model_2.idf')
class MixedLoadsTest(TestCaseBase): def setUp(self): self.project_name = 'mixed_loads' _, self.output_dir = self.set_up( Path(__file__).parent, self.project_name) filename = self.SHARED_DATA_DIR / 'mixed_loads_district' / 'geojson.json' self.gj = UrbanOptGeoJson(filename) # load system parameter data filename = self.SHARED_DATA_DIR / 'mixed_loads_district' / 'system_params.json' self.sys_params = SystemParameters(filename) def test_mixed_loads_district_energy_system(self): # create cooling network and plant cooling_network = Network2Pipe(self.sys_params) cooling_plant = CoolingPlant(self.sys_params) # create heating network and plant heating_network = Network2Pipe(self.sys_params) heating_plant = HeatingPlantWithOptionalCHP(self.sys_params) # store all couplings to construct the District system all_couplings = [ Coupling(cooling_network, cooling_plant), Coupling(heating_network, heating_plant), ] # keep track of separate loads and etses for testing purposes loads = [] heat_etses = [] cool_etses = [] load_model_map = { "spawn": Spawn, "rc": Teaser, "time_series": TimeSeries } for geojson_load in self.gj.buildings: load_model_name = self.sys_params.get_param_by_building_id( geojson_load.id, "load_model") load_model = load_model_map[load_model_name] load = load_model(self.sys_params, geojson_load) loads.append(load) geojson_load_id = geojson_load.feature.properties["id"] cooling_indirect = CoolingIndirect(self.sys_params, geojson_load_id) cool_etses.append(cooling_indirect) all_couplings.append(Coupling(load, cooling_indirect)) all_couplings.append(Coupling(cooling_indirect, cooling_network)) heating_indirect = HeatingIndirect(self.sys_params, geojson_load_id) heat_etses.append(heating_indirect) all_couplings.append(Coupling(load, heating_indirect)) all_couplings.append(Coupling(heating_indirect, heating_network)) # verify we used all load types in the model used_classes = [type(x) for x in loads] for expected_load in load_model_map.values(): assert expected_load in used_classes # create the couplings and graph graph = CouplingGraph(all_couplings) district = District(root_dir=self.output_dir, project_name=self.project_name, system_parameters=self.sys_params, coupling_graph=graph) district.to_modelica() root_path = Path(district._scaffold.districts_path.files_dir).resolve() self.run_and_assert_in_docker( Path(root_path) / 'DistrictEnergySystem.mo', project_path=district._scaffold.project_path, project_name=district._scaffold.project_name)