Skip to content

Commit

Permalink
move modelica tests to class
Browse files Browse the repository at this point in the history
  • Loading branch information
nllong committed Aug 14, 2023
1 parent b7fafc5 commit 608d541
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 70 deletions.
137 changes: 69 additions & 68 deletions tests/GMT_Lib/test_gmt_lib_des.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# :copyright (c) URBANopt, Alliance for Sustainable Energy, LLC, and other contributors.
# See also https://github.com/urbanopt/geojson-modelica-translator/blob/develop/LICENSE.md

import unittest
import pytest
from pathlib import Path
from shutil import rmtree

import pytest
from jinja2 import Environment, FileSystemLoader, StrictUndefined

from geojson_modelica_translator.modelica.GMT_Lib.DHC.DHC_5G_waste_heat_GHX import (
Expand All @@ -27,70 +28,70 @@
variable_end_string='$}'
)


@pytest.mark.simulation
def test_5G_des_waste_heat_and_ghx():
# -- Setup
package_output_dir = PARENT_DIR / 'output'
package_name = 'DES_5G'
if (package_output_dir / package_name).exists():
rmtree(package_output_dir / package_name)
sys_params = SystemParameters(DES_PARAMS)

# -- Act
cpv = DHC5GWasteHeatAndGHX(sys_params)
cpv.build_from_template(package_output_dir, package_name)

# -- Assert
# Did the mofile get created?
assert linecount(package_output_dir / package_name / 'Districts' / 'district.mo') > 20

# Test to make sure that a zero SWH peak is set to a minimum value.
# Otherwise, Modelica will error out.
with open(package_output_dir / package_name / 'Resources' / 'Data' / 'Districts' / '8' / 'B11.mos', 'r') as f:
assert '#Peak water heating load = 7714.5 Watts' in f.read()

# -- Act - with simulation
runner = ModelicaRunner()
success, _ = runner.run_in_docker(
'compile_and_run', f"{package_name}.Districts.district",
file_to_load=package_output_dir / package_name / 'package.mo',
run_path=package_output_dir / package_name,
start_time=0, stop_time=86400)

assert success is True


@pytest.mark.dymola
def test_5G_des_waste_heat_and_ghx_dymola():
# -- Setup
package_output_dir = PARENT_DIR / 'output'
package_name = 'DES_5G_Dymola'
if (package_output_dir / package_name).exists():
rmtree(package_output_dir / package_name)
sys_params = SystemParameters(DES_PARAMS)

# -- Act
cpv = DHC5GWasteHeatAndGHX(sys_params)
cpv.build_from_template(package_output_dir, package_name)

# -- Assert
# Did the mofile get created?
assert linecount(package_output_dir / package_name / 'Districts' / 'district.mo') > 20

# Test to make sure that a zero SWH peak is set to a minimum value.
# Otherwise, Modelica will error out.
with open(package_output_dir / package_name / 'Resources' / 'Data' / 'Districts' / '8' / 'B11.mos', 'r') as f:
assert '#Peak water heating load = 7714.5 Watts' in f.read()

# -- Act - with simulation
runner = ModelicaRunner()
success, _ = runner.run_in_dymola(
'simulate', f"{package_name}.Districts.district",
file_to_load=package_output_dir / package_name,
run_path=package_output_dir / package_name,
start_time=0, stop_time=86400, step_size=300,
# debug=True
)

assert success is True
class GmtLibDesTest(unittest.TestCase):

@pytest.mark.simulation
def test_5G_des_waste_heat_and_ghx(self):
# -- Setup
package_output_dir = PARENT_DIR / 'output'
package_name = 'DES_5G'
if (package_output_dir / package_name).exists():
rmtree(package_output_dir / package_name)
sys_params = SystemParameters(DES_PARAMS)

# -- Act
cpv = DHC5GWasteHeatAndGHX(sys_params)
cpv.build_from_template(package_output_dir, package_name)

# -- Assert
# Did the mofile get created?
assert linecount(package_output_dir / package_name / 'Districts' / 'district.mo') > 20

# Test to make sure that a zero SWH peak is set to a minimum value.
# Otherwise, Modelica will error out.
with open(package_output_dir / package_name / 'Resources' / 'Data' / 'Districts' / '8' / 'B11.mos', 'r') as f:
assert '#Peak water heating load = 7714.5 Watts' in f.read()

# -- Act - with simulation
runner = ModelicaRunner()
success, _ = runner.run_in_docker(
'compile_and_run', f"{package_name}.Districts.district",
file_to_load=package_output_dir / package_name / 'package.mo',
run_path=package_output_dir / package_name,
start_time=0, stop_time=86400)

assert success is True

@pytest.mark.dymola
def test_5G_des_waste_heat_and_ghx_dymola(self):
# -- Setup
package_output_dir = PARENT_DIR / 'output'
package_name = 'DES_5G_Dymola'
if (package_output_dir / package_name).exists():
rmtree(package_output_dir / package_name)
sys_params = SystemParameters(DES_PARAMS)

# -- Act
cpv = DHC5GWasteHeatAndGHX(sys_params)
cpv.build_from_template(package_output_dir, package_name)

# -- Assert
# Did the mofile get created?
assert linecount(package_output_dir / package_name / 'Districts' / 'district.mo') > 20

# Test to make sure that a zero SWH peak is set to a minimum value.
# Otherwise, Modelica will error out.
with open(package_output_dir / package_name / 'Resources' / 'Data' / 'Districts' / '8' / 'B11.mos', 'r') as f:
assert '#Peak water heating load = 7714.5 Watts' in f.read()

# -- Act - with simulation
runner = ModelicaRunner()
success, _ = runner.run_in_dymola(
'simulate', f"{package_name}.Districts.district",
file_to_load=package_output_dir / package_name,
run_path=package_output_dir / package_name,
start_time=0, stop_time=86400, step_size=300,
debug=True
)

assert success is True
2 changes: 1 addition & 1 deletion tests/modelica/test_csv_modelica.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_csv_modelica_at_60_min_timestep(self):
self.assertTrue('111600,57.2,82.2,5.784,16.2,6.7,3.062' in data)
self.assertFalse('9900,40.1,82.2,0.879,14.9,6.7,1.512' in data)

def test_csv_modelica_at_60_min_timestep_with_Eplus_file(self):
def test_csv_modelica_at_60_min_timestep_with_energyplus_file(self):
input_file = Path(self.data_dir) / 'mfrt.csv'
output_modelica_file_name = Path(self.output_dir) / 'mfrt_output.csv'

Expand Down
2 changes: 1 addition & 1 deletion tests/modelica/test_modelica_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,6 @@ def test_compile_mbl_pid_in_dymola(self):

mr = ModelicaRunner()
success, _ = mr.run_in_dymola(
'compile', model_name, run_path=results_path, file_to_load=None #, debug=True
'compile', model_name, run_path=results_path, file_to_load=None, debug=True
)
self.assertTrue(success)

0 comments on commit 608d541

Please sign in to comment.