-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest_gmt_lib_des.py
172 lines (142 loc) · 6.65 KB
/
test_gmt_lib_des.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# :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
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 DHC5GWasteHeatAndGHX
from geojson_modelica_translator.modelica.GMT_Lib.DHC.DHC_5G_waste_heat_GHX_variable import DHC5GWasteHeatAndGHXVariable
from geojson_modelica_translator.modelica.modelica_runner import ModelicaRunner
from geojson_modelica_translator.system_parameters.system_parameters import SystemParameters
from geojson_modelica_translator.utils import linecount
PARENT_DIR = Path(__file__).parent
GMT_LIB_PATH = PARENT_DIR.parent.parent / "geojson_modelica_translator" / "modelica" / "GMT_Lib"
DES_PARAMS = PARENT_DIR.parent / "data_shared" / "system_params_des_5g.json"
env = Environment(
loader=FileSystemLoader(GMT_LIB_PATH),
undefined=StrictUndefined,
variable_start_string="{$",
variable_end_string="$}",
)
class GmtLibDesTest(unittest.TestCase):
@pytest.mark.simulation
def test_5G_des_waste_heat_and_ghx(self): # noqa: N802
# -- 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") 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): # noqa: N802
# -- 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") 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
@pytest.mark.simulation
def test_5G_des_waste_heat_and_ghx_variable(self): # noqa: N802
# -- Setup
package_output_dir = PARENT_DIR / "output"
package_name = "DES_5G_Variable"
if (package_output_dir / package_name).exists():
rmtree(package_output_dir / package_name)
sys_params = SystemParameters(DES_PARAMS)
# -- Act
cpv = DHC5GWasteHeatAndGHXVariable(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") 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_variable_dymola(self): # noqa: N802
# -- Setup
package_output_dir = PARENT_DIR / "output"
package_name = "DES_5G_Variable_Dymola"
if (package_output_dir / package_name).exists():
rmtree(package_output_dir / package_name)
sys_params = SystemParameters(DES_PARAMS)
# -- Act
cpv = DHC5GWasteHeatAndGHXVariable(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") 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