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")
Example #2
0
    def test_errors(self):
        data = {
            "buildings": {
                "default": {
                    "load_model": "rc",
                    "load_model_parameters": {
                        "rc": {
                            "order": 6
                        }
                    },
                }
            }
        }

        with self.assertRaises(Exception) as exc:
            SystemParameters.loadd(data)
        self.assertRegex(str(exc.exception), "Invalid system parameter file.*")

        sp = SystemParameters.loadd(data, validate_on_load=False)
        self.assertEqual(len(sp.validate()), 6)
        self.assertIn("'fraction_latent_person' is a required property",
                      sp.validate())
        self.assertIn("'mos_weather_filename' is a required property",
                      sp.validate())
        self.assertIn("'temp_hw_supply' is a required property", sp.validate())
        self.assertIn("'temp_setpoint_cooling' is a required property",
                      sp.validate())
        self.assertIn("'temp_setpoint_heating' is a required property",
                      sp.validate())
        self.assertIn("6 is not one of [1, 2, 3, 4]", sp.validate())
Example #3
0
 def test_csv_to_sys_param(self):
     output_sys_param_file = self.output_dir / 'test_sys_param.json'
     SystemParameters.csv_to_sys_param(
         model_type='time_series',
         scenario_dir=self.scenario_dir,
         feature_file=self.feature_file,
         sys_param_filename=output_sys_param_file)
     self.assertTrue(output_sys_param_file.exists())
Example #4
0
 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))
Example #5
0
    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)
Example #6
0
    def test_to_modelica_defaults(self):
        self.results_path = os.path.abspath("tests/output/geojson_urbanopt")
        if os.path.exists(self.results_path):
            shutil.rmtree(self.results_path)

        filename = os.path.abspath(
            "tests/geojson/data/example_geojson_13buildings.json")
        gj = GeoJsonModelicaTranslator.from_geojson(filename)
        sys_params = SystemParameters()
        gj.set_system_parameters(sys_params)
        gj.to_modelica("geojson_urbanopt", "tests/output")

        # go through the generated buildings and ensure that the resources are created
        resource_names = [
            "InternalGains_Floor",
            "InternalGains_ICT",
            "InternalGains_Meeting",
            "InternalGains_Office",
            "InternalGains_Restroom",
            "InternalGains_Storage",
        ]
        for b in gj.buildings:
            for resource_name in resource_names:
                # TEASER 0.7.2 used .txt for schedule files
                path = os.path.join(
                    gj.scaffold.loads_path.files_dir,
                    "Resources",
                    "Data",
                    b.dirname,
                    f"{resource_name}.txt",
                )
                self.assertTrue(os.path.exists(path),
                                f"Path not found: {path}")
 def test_load_system_parameters_1(self):
     filename = os.path.abspath(
         "tests/system_parameters/data/system_params_1.json")
     sdp = SystemParameters(filename)
     self.assertEqual(
         sdp.data["buildings"]["default"]["load_model_parameters"]["rc"]
         ["order"], 2)
Example #8
0
    def test_to_modelica_defaults(self):
        feature_json_file = self.data_dir / f"{self.project_name}.json"

        gj = GeoJsonModelicaTranslator.from_geojson(feature_json_file)
        sys_params_json_file = self.data_dir / 'spawn_system_params.json'
        gj.set_system_parameters(SystemParameters(sys_params_json_file))
        gj.process_loads()

        self.assertEqual(len(gj.loads), 2)
        gj.to_modelica(self.project_name, self.output_dir)

        self.assertTrue(self.results_path / "Loads" / "Resources" / "Data" /
                        "B5a6b99ec37f4de7f94020090" /
                        "RefBldgSmallOfficeNew2004_Chicago.idf")  # noqa

        mr = ModelicaRunner()
        file_to_run = Path(gj.scaffold.loads_path.files_dir
                           ) / 'B5a6b99ec37f4de7f94020090' / 'coupling.mo'
        run_path = Path(gj.scaffold.project_path).parent

        exitcode = mr.run_in_docker(file_to_run,
                                    run_path=run_path,
                                    project_name=gj.scaffold.project_name)
        self.assertEqual(0, exitcode)

        results_path = Path(run_path / f"{gj.scaffold.project_name}_results")
        self.assertTrue(Path(results_path) / 'stdout.log')
        self.assertTrue(
            Path(results_path) /
            'spawn_single_Loads_B5a6b99ec37f4de7f94020090_SpawnCouplingETS.fmu'
        )
    def test_district_system(self):
        project_name = "chilled_water_plant_stub"
        self.data_dir, self.output_dir = self.set_up(os.path.dirname(__file__),
                                                     project_name)

        # load in the example geojson with a single office building
        filename = os.path.join(self.data_dir, "time_series_ex1.json")
        self.gj = UrbanOptGeoJson(filename)

        # load system parameter data
        filename = os.path.join(self.data_dir,
                                "time_series_system_params_ets.json")
        sys_params = SystemParameters(filename)

        cooling_plant = CoolingPlant(sys_params)
        # create chilled water stub for the ets
        chilled_water_stub = NetworkChilledWaterStub(sys_params)
        cp_cw_coupling = Coupling(cooling_plant, chilled_water_stub)

        graph = CouplingGraph([
            cp_cw_coupling,
        ])

        district = District(root_dir=self.output_dir,
                            project_name=project_name,
                            system_parameters=sys_params,
                            coupling_graph=graph)
        district.to_modelica()

        root_path = os.path.abspath(
            os.path.join(district._scaffold.districts_path.files_dir))
        self.run_and_assert_in_docker(
            os.path.join(root_path, 'DistrictEnergySystem.mo'),
            project_path=district._scaffold.project_path,
            project_name=district._scaffold.project_name)
    def test_heating_indirect(self):
        project_name = "heating_indirect"
        self.data_dir, self.output_dir = self.set_up(os.path.dirname(__file__),
                                                     project_name)

        # load in the example geojson with a single office building
        filename = os.path.join(self.data_dir, "time_series_ex1.json")
        self.gj = UrbanOptGeoJson(filename)
        # scaffold the project ourselves
        scaffold = Scaffold(self.output_dir, project_name)
        scaffold.create()

        # load system parameter data
        filename = os.path.join(self.data_dir,
                                "time_series_system_params_ets.json")
        sys_params = SystemParameters(filename)

        # currently we must setup the root project before we can run to_modelica
        package = PackageParser.new_from_template(scaffold.project_path,
                                                  scaffold.project_name,
                                                  order=[])
        package.save()
        # now test the connector (independent of the larger geojson translator)
        geojson_load_id = self.gj.buildings[0].feature.properties["id"]
        self.heating_indirect = HeatingIndirect(sys_params, geojson_load_id)
        self.heating_indirect.to_modelica(scaffold)

        root_path = os.path.abspath(
            os.path.join(scaffold.substations_path.files_dir))
        geojson_id = self.gj.buildings[0].feature.properties["id"]
        model_filepath = os.path.join(root_path,
                                      f'HeatingIndirect_{geojson_id}.mo')
        self.assertTrue(os.path.exists(model_filepath),
                        f"File does not exist: {model_filepath}")
Example #11
0
 def test_csv_to_sys_param_does_not_overwrite(self):
     with self.assertRaises(Exception) as context:
         output_sys_param_file = self.output_dir / 'test_overwriting_sys_param.json'
         SystemParameters.csv_to_sys_param(
             model_type='time_series',
             scenario_dir=self.scenario_dir,
             feature_file=self.feature_file,
             sys_param_filename=output_sys_param_file,
             overwrite=True)
         SystemParameters.csv_to_sys_param(
             model_type='time_series',
             scenario_dir=self.scenario_dir,
             feature_file=self.feature_file,
             sys_param_filename=output_sys_param_file,
             overwrite=False)
     self.assertIn("Output file already exists and overwrite is False:",
                   str(context.exception))
    def test_get_param_with_default(self):
        data = {"buildings": {"default": {"load_model": "Spawn"}}}
        sp = SystemParameters.loadd(data)
        value = sp.get_param(
            "buildings.default.load_model_parameters.rc.order", default=2)
        self.assertEqual(value, 2)

        value = sp.get_param("not.a.real.path", default=2)
        self.assertEqual(value, 2)
Example #13
0
    def test_get_param_with_default(self):
        data = {"buildings": {"default": {"load_model": "spawn"}}}
        sp = SystemParameters.loadd(data)
        # this path doesn't exist, but there is a default
        value = sp.get_param(
            "buildings.default.load_model_parameters.rc.order", default=2)
        self.assertEqual(2, value)

        value = sp.get_param("not.a.real.path", default=2)
        self.assertEqual(2, value)
Example #14
0
 def test_validate_sys_param_template(self):
     output_sys_param_file = self.output_dir / 'bogus_sys_param.json'
     with self.assertRaises(Exception) as context:
         SystemParameters.csv_to_sys_param(
             scenario_dir=self.scenario_dir,
             feature_file=self.feature_file,
             sys_param_filename=output_sys_param_file)
     self.assertIn(
         "csv_to_sys_param() missing 1 required positional argument: 'model_type'",
         str(context.exception))
     with self.assertRaises(Exception) as context:
         bogus_template_type = 'openstudio'
         SystemParameters.csv_to_sys_param(
             model_type=bogus_template_type,
             scenario_dir=self.scenario_dir,
             feature_file=self.feature_file,
             sys_param_filename=output_sys_param_file)
     self.assertIn(
         f"No template found. {bogus_template_type} is not a valid template",
         str(context.exception))
    def setUp(self):
        self.project_name = 'district_heating_and_cooling_systems'
        self.data_dir, self.output_dir = self.set_up(Path(__file__).parent, self.project_name)

        # load in the example geojson with a single office building
        filename = Path(self.data_dir) / "time_series_ex1.json"
        self.gj = UrbanOptGeoJson(filename)

        # load system parameter data
        filename = Path(self.data_dir) / "time_series_system_params_ets.json"
        self.sys_params = SystemParameters(filename)
    def test_errors(self):
        data = {
            "buildings": {
                "default": {
                    "load_model": "ROM/RC",
                    "load_model_parameters": {
                        "rc": {
                            "order": 6
                        }
                    },
                }
            }
        }

        with self.assertRaises(Exception) as exc:
            SystemParameters.loadd(data)
        self.assertRegex(str(exc.exception), "Invalid system parameter file.*")

        sp = SystemParameters.loadd(data, validate_on_load=False)
        self.assertEqual(sp.validate()[0], "6 is not one of [1, 2, 3, 4]")
Example #17
0
    def test_to_modelica_defaults(self):
        self.results_path = os.path.abspath("tests/output/geojson_1")
        if os.path.exists(self.results_path):
            shutil.rmtree(self.results_path)

        filename = os.path.abspath("tests/geojson/data/geojson_1.json")
        gj = GeoJsonModelicaTranslator.from_geojson(filename)
        sys_params = SystemParameters()
        gj.set_system_parameters(sys_params)
        gj.to_modelica("geojson_1", "tests/output")

        # setup what we are going to check
        model_names = [
            "Floor",
            "ICT",
            "Meeting",
            "Office",
            "package",
            "Restroom",
            "Storage",
        ]
        building_paths = [
            os.path.join(gj.scaffold.loads_path.files_dir, b.dirname)
            for b in gj.buildings
        ]
        path_checks = [
            f"{os.path.sep.join(r)}.mo"
            for r in itertools.product(building_paths, model_names)
        ]

        for p in path_checks:
            self.assertTrue(os.path.exists(p), f"Path not found {p}")

        # go through the generated buildings and ensure that the resources are created
        resource_names = [
            "InternalGains_Floor",
            "InternalGains_ICT",
            "InternalGains_Meeting",
            "InternalGains_Office",
            "InternalGains_Restroom",
            "InternalGains_Storage",
        ]
        for b in gj.buildings:
            for resource_name in resource_names:
                # TEASER 0.7.2 used .txt for schedule files
                path = os.path.join(
                    gj.scaffold.loads_path.files_dir,
                    "Resources",
                    "Data",
                    b.dirname,
                    f"{resource_name}.txt",
                )
                self.assertTrue(os.path.exists(path),
                                f"Path not found: {path}")
Example #18
0
    def setUp(self):
        self.project_name = 'teaser_district_heating_and_cooling_systems'
        self.data_dir, self.output_dir = self.set_up(
            Path(__file__).parent, self.project_name)

        filename = Path(self.data_dir) / "teaser_geojson_two_loads.json"
        self.gj = UrbanOptGeoJson(filename)

        # load system parameter data
        filename = Path(self.data_dir) / "teaser_system_params_two_loads.json"
        self.sys_params = SystemParameters(filename)
Example #19
0
class GeoJsonModelicaTranslator(object):
    """
    Main class for using the GeoJSON to Modelica Translator.
    """
    def __init__(
        self,
        geojson_filepath,
        sys_params_filepath,
        root_dir,
        project_name,
    ):
        """Create an instance of this class

        :param geojson_filepath: str, path to GeoJSON file
        :param sys_params_filepath: str, path to system parameters file
        :param root_dir: str, where to create the package
        :project_name: str, name of the package
        """
        if not Path(geojson_filepath).exists():
            raise FileNotFoundError(
                f'GeoJSON file path does not exist: {geojson_filepath}')
        if not Path(sys_params_filepath).exists():
            raise FileNotFoundError(
                f'System parameters file path does not exist: {sys_params_filepath}'
            )

        self._system_parameters = SystemParameters(sys_params_filepath)

        geojson_ids = self._system_parameters.get_default(
            '$.buildings.custom[*].geojson_id', [])
        self._geojson = UrbanOptGeoJson(geojson_filepath, geojson_ids)

        self._root_dir = root_dir
        self._project_name = project_name
        self._couplings = _parse_couplings(self._geojson,
                                           self._system_parameters)
        self._coupling_graph = CouplingGraph(self._couplings)
        self._district = District(self._root_dir, self._project_name,
                                  self._system_parameters,
                                  self._coupling_graph)
        self._package_created = False

    def to_modelica(self):
        """Generate the modelica package. Call `simulate` method on the result
        to run the package

        :return: ModelicaPackage
        """
        self._district.to_modelica()

        return ModelicaPackage(self._district.district_model_filepath,
                               self._root_dir, self._project_name)
Example #20
0
 def test_missing_files(self):
     with self.assertRaises(Exception) as context:
         output_sys_param_file = self.output_dir / 'going_to_fail_first.json'
         missing_scenario_dir = self.scenario_dir / 'foobar'
         SystemParameters.csv_to_sys_param(
             model_type='time_series',
             scenario_dir=missing_scenario_dir,
             feature_file=self.feature_file,
             sys_param_filename=output_sys_param_file)
     self.assertIn(
         f"Unable to find your scenario. The path you provided was: {missing_scenario_dir}",
         str(context.exception))
     with self.assertRaises(Exception) as context:
         missing_feature_file = self.data_dir / 'sdk_output_skeleton' / 'foobar.json'
         SystemParameters.csv_to_sys_param(
             model_type='time_series',
             scenario_dir=self.scenario_dir,
             feature_file=missing_feature_file,
             sys_param_filename=output_sys_param_file)
     self.assertIn(
         f"Unable to find your feature file. The path you provided was: {missing_feature_file}",
         str(context.exception))
def build_sys_param(model_type: str, sys_param_filename: Path, scenario_file: Path, feature_file: Path, overwrite: bool):
    """
    Create system parameters file using uo_sdk output

    SYS_PARAM_FILENAME: Path/name to sys-param file be created. Be sure to include the ".json" suffix.

    SCENARIO_FILE: Path to sdk scenario file.

    FEATURE_FILE: Path to sdk json feature file with data about the buildings.

    \b
    MODEL_TYPE: selection for which kind of simulation this sys-param file will support.
        Valid choices for MODEL_TYPE: "time_series"

    \f
    :param model_type: string, selection of which model type to use in the GMT
    :param sys_param_filename: Path, location & name of json output file to save
    :param scenario_file: Path, location of SDK scenario_file
    :param feature_file: Path, location of SDK feature_file
    :param overwrite: Boolean, flag to overwrite an existing file of the same name/location
    """

    # Use scenario_file to be consistent with sdk
    scenario_name = Path(scenario_file).stem
    scenario_dir = Path(scenario_file).parent / 'run' / scenario_name

    SystemParameters.csv_to_sys_param(
        model_type=model_type,
        sys_param_filename=Path(sys_param_filename),
        scenario_dir=Path(scenario_dir),
        feature_file=Path(feature_file),
        overwrite=overwrite
    )

    if Path(sys_param_filename).exists():
        print(f"\nSystem parameters file {sys_param_filename} successfully created.")
    else:
        raise SystemExit(f"{sys_param_filename} failed. Please check your inputs and try again.")
Example #22
0
    def __init__(
        self,
        geojson_filepath,
        sys_params_filepath,
        root_dir,
        project_name,
    ):
        """Create an instance of this class

        :param geojson_filepath: str, path to GeoJSON file
        :param sys_params_filepath: str, path to system parameters file
        :param root_dir: str, where to create the package
        :project_name: str, name of the package
        """
        if not Path(geojson_filepath).exists():
            raise FileNotFoundError(
                f'GeoJSON file path does not exist: {geojson_filepath}')
        if not Path(sys_params_filepath).exists():
            raise FileNotFoundError(
                f'System parameters file path does not exist: {sys_params_filepath}'
            )

        self._system_parameters = SystemParameters(sys_params_filepath)

        geojson_ids = self._system_parameters.get_default(
            '$.buildings.custom[*].geojson_id', [])
        self._geojson = UrbanOptGeoJson(geojson_filepath, geojson_ids)

        self._root_dir = root_dir
        self._project_name = project_name
        self._couplings = _parse_couplings(self._geojson,
                                           self._system_parameters)
        self._coupling_graph = CouplingGraph(self._couplings)
        self._district = District(self._root_dir, self._project_name,
                                  self._system_parameters,
                                  self._coupling_graph)
        self._package_created = False
Example #23
0
    def test_get_param(self):
        data = {
            "buildings": {
                "default": {
                    "load_model": "rc",
                    "load_model_parameters": {
                        "rc": {
                            "order": 4,
                            "mos_weather_filename": "path-to-file",
                            "fraction_latent_person": 1.25,
                            "temp_hw_supply": 40,
                            "temp_setpoint_heating": 40,
                            "temp_setpoint_cooling": 24
                        }
                    },
                }
            }
        }
        sp = SystemParameters.loadd(data)
        # $.buildings.*[?load_model=spawn].load_model_parameters.spawn.idf_filename
        value = sp.get_param(
            "$.buildings.default.load_model_parameters.rc.order")
        self.assertEqual(value, 4)

        value = sp.get_param("buildings.default.load_model")
        self.assertEqual(value, "rc")

        value = sp.get_param("buildings.default")
        self.assertDictEqual(
            value, {
                "load_model": "rc",
                "load_model_parameters": {
                    "rc": {
                        "order": 4,
                        "mos_weather_filename": "path-to-file",
                        "fraction_latent_person": 1.25,
                        "temp_hw_supply": 40,
                        "temp_setpoint_heating": 40,
                        "temp_setpoint_cooling": 24
                    }
                }
            })

        value = sp.get_param("")
        self.assertIsNone(value)

        value = sp.get_param("not.a.real.path")
        self.assertIsNone(value)
    def test_Teaser_heating(self):
        project_name = 'teaser_district_heating'
        self.data_dir, self.output_dir = self.set_up(os.path.dirname(__file__),
                                                     project_name)

        # load in the example geojson with a single office building
        filename = os.path.join(self.data_dir, "teaser_geojson_two_loads.json")
        self.gj = UrbanOptGeoJson(filename)

        # load system parameter data
        filename = os.path.join(self.data_dir,
                                "teaser_system_params_two_loads.json")
        sys_params = SystemParameters(filename)

        # create network and plant
        network = Network2Pipe(sys_params)
        heating_plant = HeatingPlantWithOptionalCHP(sys_params)

        # create our our load/ets/stubs
        all_couplings = [Coupling(network, heating_plant)]
        for geojson_load in self.gj.buildings:
            teaser_load = Teaser(sys_params, geojson_load)
            geojson_load_id = geojson_load.feature.properties["id"]
            heating_indirect_system = HeatingIndirect(sys_params,
                                                      geojson_load_id)
            cold_water_stub = EtsColdWaterStub(sys_params)
            all_couplings.append(Coupling(teaser_load,
                                          heating_indirect_system))
            all_couplings.append(Coupling(teaser_load, cold_water_stub))
            all_couplings.append(Coupling(heating_indirect_system, network))

        # create the couplings and graph
        graph = CouplingGraph(all_couplings)

        district = District(root_dir=self.output_dir,
                            project_name=project_name,
                            system_parameters=sys_params,
                            coupling_graph=graph)
        district.to_modelica()

        root_path = os.path.abspath(
            os.path.join(district._scaffold.districts_path.files_dir))
        self.run_and_assert_in_docker(
            os.path.join(root_path, 'DistrictEnergySystem.mo'),
            project_path=district._scaffold.project_path,
            project_name=district._scaffold.project_name)
Example #25
0
    def test_district_system(self):
        project_name = "district_system"
        self.data_dir, self.output_dir = self.set_up(os.path.dirname(__file__),
                                                     project_name)

        # load in the example geojson with a single office building
        filename = os.path.join(self.data_dir, "time_series_ex1.json")
        self.gj = UrbanOptGeoJson(filename)

        # load system parameter data
        filename = os.path.join(self.data_dir,
                                "time_series_system_params_ets.json")
        sys_params = SystemParameters(filename)

        # Create the time series load, ets and their coupling
        time_series_load = TimeSeries(sys_params, self.gj.buildings[0])
        geojson_load_id = self.gj.buildings[0].feature.properties["id"]
        cooling_indirect_system = CoolingIndirect(sys_params, geojson_load_id)
        ts_ci_coupling = Coupling(time_series_load, cooling_indirect_system)

        # create chilled water stub for the ets
        chilled_water_stub = NetworkChilledWaterStub(sys_params)
        ci_cw_coupling = Coupling(cooling_indirect_system, chilled_water_stub)

        #  create hot water stub for the load
        hot_water_stub = EtsHotWaterStub(sys_params)
        ts_hw_coupling = Coupling(time_series_load, hot_water_stub)

        graph = CouplingGraph([
            ts_ci_coupling,
            ci_cw_coupling,
            ts_hw_coupling,
        ])

        district = District(root_dir=self.output_dir,
                            project_name=project_name,
                            system_parameters=sys_params,
                            coupling_graph=graph)
        district.to_modelica()

        root_path = os.path.abspath(
            os.path.join(district._scaffold.districts_path.files_dir))
        self.run_and_assert_in_docker(
            os.path.join(root_path, 'DistrictEnergySystem.mo'),
            project_path=district._scaffold.project_path,
            project_name=district._scaffold.project_name)
Example #26
0
    def test_no_ets_and_run(self):
        project_name = "time_series_no_ets"
        self.data_dir, self.output_dir = self.set_up(os.path.dirname(__file__),
                                                     project_name)

        # load in the example geojson with a single office building
        filename = os.path.join(self.data_dir, "time_series_ex1.json")
        self.gj = UrbanOptGeoJson(filename)
        # scaffold the project ourselves
        scaffold = Scaffold(self.output_dir, project_name)
        scaffold.create()

        # load system parameter data
        filename = os.path.join(self.data_dir,
                                "time_series_system_params_no_ets.json")
        sys_params = SystemParameters(filename)

        # now test the connector (independent of the larger geojson translator)
        self.time_series = TimeSeries(sys_params, self.gj.buildings[0])

        self.assertIsNotNone(self.time_series)
        self.assertIsNotNone(self.time_series.building)
        self.assertEqual(
            "time_series",
            self.time_series.system_parameters.get_param("buildings.custom")[0]
            ["load_model"])

        # currently we must setup the root project before we can run to_modelica
        package = PackageParser.new_from_template(scaffold.project_path,
                                                  scaffold.project_name,
                                                  order=[])
        package.save()
        self.time_series.to_modelica(scaffold)

        root_path = os.path.abspath(
            os.path.join(scaffold.loads_path.files_dir,
                         'B5a6b99ec37f4de7f94020090'))
        files = [
            os.path.join(root_path, 'building.mo'),
        ]

        # verify that there are only 2 files that matter (coupling and building)
        for file in files:
            self.assertTrue(os.path.exists(file),
                            f"File does not exist: {file}")
Example #27
0
    def test_to_modelica_defaults(self):
        feature_json_file = self.data_dir / f"{self.project_name}.json"

        gj = GeoJsonModelicaTranslator.from_geojson(feature_json_file)
        sys_params_json_file = self.data_dir / 'geojson_8_system_params.json'
        sys_params = SystemParameters(sys_params_json_file)
        gj.set_system_parameters(sys_params)
        gj.process_loads()

        self.assertEqual(len(gj.loads), 8)

        all_couplings = []

        for geojson_load in gj.json_loads:
            teaser_load = Teaser(sys_params, geojson_load)

            hot_stub = EtsHotWaterStub(sys_params)
            cold_stub = EtsColdWaterStub(sys_params)
            all_couplings.append(Coupling(teaser_load, hot_stub))
            all_couplings.append(Coupling(teaser_load, cold_stub))

        graph = CouplingGraph(all_couplings)

        district = District(
            root_dir=self.output_dir,
            project_name=self.project_name,
            system_parameters=sys_params,
            coupling_graph=graph
        )

        district.to_modelica()

        # run a single file to make sure it simulates
        mr = ModelicaRunner()

        root_path = os.path.abspath(os.path.join(district._scaffold.districts_path.files_dir))
        exitcode = mr.run_in_docker(os.path.join(root_path, 'DistrictEnergySystem.mo'),
                                    run_path=Path(district._scaffold.project_path).resolve().parent,
                                    project_name=district._scaffold.project_name)
        self.assertEqual(0, exitcode)
    def test_get_param(self):
        data = {
            "buildings": {
                "default": {
                    "load_model": "ROM/RC",
                    "load_model_parameters": {
                        "rc": {
                            "order": 4
                        }
                    },
                }
            }
        }
        sp = SystemParameters.loadd(data)
        value = sp.get_param(
            "buildings.default.load_model_parameters.rc.order")
        self.assertEqual(value, 4)

        value = sp.get_param("buildings.default.load_model")
        self.assertEqual(value, "ROM/RC")

        value = sp.get_param("buildings.default")
        self.assertDictEqual(
            value,
            {
                "load_model": "ROM/RC",
                "load_model_parameters": {
                    "rc": {
                        "order": 4
                    }
                }
            },
        )

        value = sp.get_param("")
        self.assertIsNone(value)

        value = sp.get_param("not.a.real.path")
        self.assertIsNone(value)
Example #29
0
    def test_chp_system(self):
        self.project_name = 'heat_with_chp'
        self.data_dir, self.output_dir = self.set_up(
            Path(__file__).parent, self.project_name)

        # load in the example geojson with a single office building
        filename = Path(self.data_dir) / "time_series_ex1.json"
        self.gj = self.gj = UrbanOptGeoJson(filename)

        # load system parameter data
        filename = Path(self.data_dir) / "time_series_system_params_chp.json"
        self.sys_params = SystemParameters(filename)

        # create network and plant
        network = Network2Pipe(self.sys_params)
        heating_plant = HeatingPlantWithOptionalCHP(self.sys_params)

        # create our our load/ets/stubs
        all_couplings = [Coupling(network, heating_plant)]
        for geojson_load in self.gj.buildings:
            time_series_load = TimeSeries(self.sys_params, geojson_load)
            geojson_load_id = geojson_load.feature.properties["id"]
            heating_indirect_system = HeatingIndirect(self.sys_params,
                                                      geojson_load_id)
            cold_water_stub = EtsColdWaterStub(self.sys_params)
            all_couplings.append(
                Coupling(time_series_load, heating_indirect_system))
            all_couplings.append(Coupling(time_series_load, cold_water_stub))
            all_couplings.append(Coupling(heating_indirect_system, network))

        # 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()
Example #30
0
    def setUp(self):
        root_dir, project_name = "tests/model_connectors/output", "spawn_two_building"

        if os.path.exists(os.path.join(root_dir, project_name)):
            shutil.rmtree(os.path.join(root_dir, project_name))

        # load in the example geojson with a single offie building
        filename = os.path.abspath(
            "tests/model_connectors/data/spawn_geojson_ex2.json")
        self.gj = GeoJsonModelicaTranslator.from_geojson(filename)
        self.gj.scaffold_directory(
            root_dir, project_name
        )  # use the GeoJson translator to scaffold out the directory

        # load system parameter data
        filename = os.path.abspath(
            "tests/model_connectors/data/spawn_system_params_ex2.json")
        sys_params = SystemParameters(filename)

        # now test the spawn connector (independent of the larger geojson translator
        self.spawn = SpawnConnector(sys_params)

        for b in self.gj.buildings:
            self.spawn.add_building(b)