Skip to content

Commit

Permalink
Merge branch 'develop' into bump-om
Browse files Browse the repository at this point in the history
  • Loading branch information
vtnate authored Nov 15, 2024
2 parents 1a98b10 + f8d1fbb commit bff8721
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 57 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ repos:
hooks:
# Run the linter
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --output-format=full]
# unsafe fixes: https://docs.astral.sh/ruff/linter/#fixes
args: [--fix, --exit-non-zero-on-fix, --output-format=full, --unsafe-fixes]
# Run the formatter
- id: ruff-format
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# TODO: grab version from pyproject.toml
poetry_file = toml.load("../pyproject.toml")

# The short X.Y version.
Expand Down
14 changes: 10 additions & 4 deletions geojson_modelica_translator/geojson_modelica_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ def _parse_couplings(geojson, sys_params, sys_param_district_type):
class ModelicaPackage:
"""Represents a modelica package which can be simulated"""

def __init__(self, file_to_run, project_path, project_name):
self._file_to_run = file_to_run
def __init__(self, project_path, project_name):
self._project_path = project_path
self._project_name = project_name

Expand All @@ -137,9 +136,16 @@ def simulate(self):
:return: tuple(bool, pathlib.Path), True or False depending on simulation success
followed by the path to the results directory
"""
_log.debug(f"Model name: {self._project_name}.Districts.DistrictEnergySystem")
_log.debug(f"file to load: {self._project_path / self._project_name / 'package.mo'}")
_log.debug(f"run path: {self._project_path / self._project_name}")

modelica_runner = ModelicaRunner()
return modelica_runner.run_in_docker(
self._file_to_run, run_path=self._project_path, project_name=self._project_name
action="compile_and_run",
model_name=f"{self._project_name}.Districts.DistrictEnergySystem",
file_to_load=self._project_path / self._project_name / "package.mo",
run_path=self._project_path / self._project_name,
)


Expand Down Expand Up @@ -194,4 +200,4 @@ def to_modelica(self):
"""
self._district.to_modelica()

return ModelicaPackage(self._district.district_model_filepath, self._root_dir, self._project_name)
return ModelicaPackage(self._root_dir, self._project_name)
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ def lookup_building_type(self, building_type):
mapping = {
# Single Family is not configured right now.
"Single-Family": "SingleFamilyDwelling",
"Office": "office",
"Laboratory": "institute8",
"Education": "institute",
"Inpatient health care": "institute8",
"Outpatient health care": "institute4",
"Nursing": "institute4",
"Service": "institute4",
"Retail other than mall": "office",
"Strip shopping mall": "office",
"Enclosed mall": "office",
"Food sales": "institute4",
"Food service": "institute4",
"Office": "bmvbs_office",
"Laboratory": "bmvbs_institute8",
"Education": "bmvbs_institute",
"Inpatient health care": "bmvbs_institute8",
"Outpatient health care": "bmvbs_institute4",
"Nursing": "bmvbs_institute4",
"Service": "bmvbs_institute4",
"Retail other than mall": "bmvbs_office",
"Strip shopping mall": "bmvbs_office",
"Enclosed mall": "bmvbs_office",
"Food sales": "bmvbs_institute4",
"Food service": "bmvbs_institute4",
}

# Other types to map!
Expand All @@ -73,7 +73,7 @@ def lookup_building_type(self, building_type):
raise Exception(f"Building type of {building_type} not defined in GeoJSON to TEASER mappings")

def to_modelica(self, scaffold, keep_original_models=False):
"""Save the TEASER representation of a sinlge building to the filesystem. The path will
"""Save the TEASER representation of a single building to the filesystem. The path will
be scaffold.loads_path.files_dir.
:param scaffold: Scaffold object, contains all the paths of the project
Expand All @@ -82,10 +82,9 @@ def to_modelica(self, scaffold, keep_original_models=False):
# Teaser changes the current dir, so make sure to reset it back to where we started
curdir = os.getcwd()
try:
prj = Project(load_data=True)
prj = Project()
prj.add_non_residential(
method="bmvbs",
usage=self.lookup_building_type(self.building["building_type"]),
geometry_data=self.lookup_building_type(self.building["building_type"]),
name=self.building_name,
year_of_construction=self.building["year_built"],
number_of_floors=self.building["num_stories"],
Expand All @@ -94,7 +93,7 @@ def to_modelica(self, scaffold, keep_original_models=False):
office_layout=1,
window_layout=1,
with_ahu=False,
construction_type="heavy",
construction_data="iwu_heavy",
)

prj.used_library_calc = "IBPSA"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ def to_modelica(self, scaffold):

# convert the values to match Modelica gfunctions
for i in range(len(gfunction)):
gfunction[gfunction.columns[0]].iloc[i] = (
math.exp(gfunction[gfunction.columns[0]].iloc[i])
gfunction.loc[i, gfunction.columns[0]] = (
math.exp(gfunction.loc[i, gfunction.columns[0]])
* template_data["configuration"]["borehole_height"] ** 2
/ (9 * template_data["soil"]["conductivity"] / template_data["soil"]["volumetric_heat_capacity"])
)
gfunction[gfunction.columns[1]].iloc[i] = gfunction[gfunction.columns[1]].iloc[i] / (
gfunction.loc[i, gfunction.columns[1]] = gfunction.loc[i, gfunction.columns[1]] / (
template_data["configuration"]["number_of_boreholes"]
* 2
* math.pi
Expand Down
2 changes: 1 addition & 1 deletion geojson_modelica_translator/modelica/csv_modelica.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(self, input_csv_file_path, sig_fig=3):

# Dymola wants time to start at zero.
# If time doesn't start at zero, copy the first line and set time column to zero.
if self.timeseries_output.loc[0][0] != 0:
if self.timeseries_output.iloc[0, 0] != 0:
self.timeseries_timestep = self.timeseries_output.loc[[0], :]
if "SecondsFromStart" in self.timeseries_output.columns:
self.timeseries_timestep["SecondsFromStart"] = 0
Expand Down
6 changes: 5 additions & 1 deletion geojson_modelica_translator/modelica/modelica_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ def cleanup_path(self, path: Path, model_name: str, **kwargs: dict) -> None:
f"{model_name.replace('.', '_')}_FMU.libs",
]

# keep these files if debug is passed
conditional_remove_files = [
"compile_fmu.mos",
"simulate.mos",
Expand All @@ -446,10 +447,13 @@ def cleanup_path(self, path: Path, model_name: str, **kwargs: dict) -> None:
logger.debug("Removing temporary files")

if not kwargs.get("debug", False):
logger.debug("...and removing intermediate files")
logger.debug("...and removing scripts to run the simulation")
files_to_remove.extend(conditional_remove_files)

for f in files_to_remove:
logger.debug(f"Removing {f}")
if (path / f).is_dir():
continue
(path / f).unlink(missing_ok=True)

# The other files below will always be removed, debug or not
Expand Down
2 changes: 1 addition & 1 deletion geojson_modelica_translator/results_ghp.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def adjust_year(dt):
df_values = df_values.set_index("Datetime")

# Resample to 1 hour data, taking the first occurrence for each interval
df_resampled = df_values.resample("1H").first().reset_index()
df_resampled = df_values.resample("1h").first().reset_index()

# Format datetime to desired format
df_resampled["Datetime"] = df_resampled["Datetime"].dt.strftime("%m/%d/%Y %H:%M")
Expand Down
8 changes: 6 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ modelica-builder = "^0.6.0"
# modelica-builder = { git = "https://github.com/urbanopt/modelica-builder.git", branch = "prep-v0.6.0"}
pandas = "~2"
requests = "^2.28"
teaser = "0.7.5"
#teaser = { git = "https://github.com/urbanopt/TEASER.git", branch = "development"}
teaser = "1.0.1"
# teaser = { git = "https://github.com/RWTH-EBC/TEASER.git", branch = "development" }

myst-parser = "^4.0.0"
[tool.poetry.dev-dependencies]
Expand Down
48 changes: 24 additions & 24 deletions tests/geojson_modelica_translator/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from pathlib import Path

# import pytest
import pytest

from geojson_modelica_translator.geojson_modelica_translator import GeoJsonModelicaTranslator
from tests.base_test_case import TestCaseBase

Expand All @@ -30,26 +31,25 @@ def test_to_modelica_is_successful_when_inputs_are_valid(self):
# -- Assert
assert (output_dir / project_name / "package.mo").exists()

# The NREL site models don't run for some reason. Commenting out for now since
# these models are here as a reference. We will revisit after upgrading to MBL 9.0.
# @pytest.mark.simulation
# def test_successfully_creates_and_simulates_when_inputs_are_valid(self):
# # -- Setup
# project_name = 'simulate_package'
# _, output_dir = self.set_up(ROOT_DIR, project_name)

# gmt = GeoJsonModelicaTranslator(
# self.geojson_file,
# self.sys_params_file,
# output_dir,
# project_name,
# )

# package = gmt.to_modelica()

# # -- Act
# success, results_dir = package.simulate()

# # -- Assert
# self.assertTrue(success, 'simulation did not complete successfully')
# self.assertTrue((results_dir / 'stdout.log').exists())
@pytest.mark.simulation
@pytest.mark.skip("OMC Spawn - Failed to find spawn executable in Buildings Library")
def test_successfully_creates_and_simulates_when_inputs_are_valid(self):
# -- Setup
project_name = "simulate_package"
_, output_dir = self.set_up(ROOT_DIR, project_name)

gmt = GeoJsonModelicaTranslator(
self.geojson_file,
self.sys_params_file,
output_dir,
project_name,
)

package = gmt.to_modelica()

# -- Act
success, results_dir = package.simulate()

# -- Assert
assert success, "simulation did not complete successfully"
assert (results_dir / "stdout.log").exists()

0 comments on commit bff8721

Please sign in to comment.