-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_results.py
305 lines (230 loc) · 11.2 KB
/
test_results.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
import os
import tempfile
from copy import deepcopy
from itertools import product
import numpy as np
import pandas
import pytest
import flow360.component.v1.units as u1
import flow360.v1 as fl
from flow360 import log
from flow360.component.simulation import units as u2
from flow360.component.simulation.operating_condition.operating_condition import (
AerospaceCondition,
)
from flow360.component.simulation.simulation_params import SimulationParams
from flow360.component.simulation.utils import model_attribute_unlock
log.set_logging_level("DEBUG")
@pytest.fixture(autouse=True)
def change_test_dir(request, monkeypatch):
monkeypatch.chdir(request.fspath.dirname)
@pytest.fixture()
def data_path(mock_id):
return os.path.join("data", mock_id)
def test_actuator_disk_results(mock_id, mock_response, data_path):
case = fl.Case(id=mock_id)
with fl.SI_unit_system:
params = fl.Flow360Params(
geometry=fl.Geometry(
mesh_unit=u1.m,
),
freestream=fl.FreestreamFromVelocity(velocity=286, alpha=3.06),
fluid_properties=fl.air,
boundaries={},
)
results = case.results
results.actuator_disks.load_from_local(
os.path.join(data_path, "results", "actuatorDisk_output_v2.csv")
)
print(results.actuator_disks.as_dataframe())
assert results.actuator_disks.values["Disk0_Power"][0] == 30.0625485898572
results.actuator_disks.to_base("SI", params=params)
assert isinstance(results.actuator_disks.as_dataframe(), pandas.DataFrame)
assert isinstance(results.actuator_disks.as_dict(), dict)
assert isinstance(results.actuator_disks.as_numpy(), np.ndarray)
assert float(results.actuator_disks.values["Disk0_Power"][0].v) == 1451191686.9478528
assert str(results.actuator_disks.values["Disk0_Power"][0].units) == "kg*m**2/s**3"
assert float(results.actuator_disks.values["Disk0_Force"][0].v) == 106613080.32014923
assert str(results.actuator_disks.values["Disk0_Force"][0].units) == "kg*m/s**2"
assert float(results.actuator_disks.values["Disk0_Moment"][0].v) == 1494767678.3286672
assert str(results.actuator_disks.values["Disk0_Moment"][0].units) == "kg*m**2/s**2"
# should be no change is calling again:
results.actuator_disks.to_base("SI", params=params)
assert float(results.actuator_disks.values["Disk0_Power"][0].v) == 1451191686.9478528
assert str(results.actuator_disks.values["Disk0_Power"][0].units) == "kg*m**2/s**3"
results.actuator_disks.to_base("Imperial", params=params)
assert float(results.actuator_disks.values["Disk0_Power"][0].v) == 34437301746.89787
assert str(results.actuator_disks.values["Disk0_Power"][0].units) == "ft**2*lb/s**3"
def test_bet_disk_results(mock_id, mock_response, data_path):
case = fl.Case(id=mock_id)
with fl.SI_unit_system:
params = fl.Flow360Params(
geometry=fl.Geometry(
mesh_unit=u1.m,
),
freestream=fl.FreestreamFromVelocity(velocity=286, alpha=3.06),
fluid_properties=fl.air,
boundaries={},
)
results = case.results
results.bet_forces.load_from_local(os.path.join(data_path, "results", "bet_forces_v2.csv"))
print(results.bet_forces.as_dataframe())
assert results.bet_forces.values["Disk0_Force_x"][0] == -1397.09615312895
results.bet_forces.to_base("SI", params=params)
assert isinstance(results.bet_forces.as_dataframe(), pandas.DataFrame)
assert isinstance(results.bet_forces.as_dict(), dict)
assert isinstance(results.bet_forces.as_numpy(), np.ndarray)
assert float(results.bet_forces.values["Disk0_Force_x"][0].v) == -198185092.5822863
assert str(results.bet_forces.values["Disk0_Force_x"][0].units) == "kg*m/s**2"
assert float(results.bet_forces.values["Disk0_Moment_x"][0].v) == 23068914203.12496
assert str(results.bet_forces.values["Disk0_Moment_x"][0].units) == "kg*m**2/s**2"
def test_bet_disk_results_with_simulation_interface(mock_id, mock_response, data_path):
case = fl.Case(id=mock_id)
with u2.SI_unit_system:
params = SimulationParams(operating_condition=AerospaceCondition(velocity_magnitude=286))
with model_attribute_unlock(params.private_attribute_asset_cache, "project_length_unit"):
params.private_attribute_asset_cache.project_length_unit = 1 * u2.m
results = case.results
results.bet_forces.load_from_local(os.path.join(data_path, "results", "bet_forces_v2.csv"))
print(results.bet_forces.as_dataframe())
assert results.bet_forces.values["Disk0_Force_x"][0] == -1397.09615312895
results.bet_forces.to_base("SI", params=params)
assert isinstance(results.bet_forces.as_dataframe(), pandas.DataFrame)
assert isinstance(results.bet_forces.as_dict(), dict)
assert isinstance(results.bet_forces.as_numpy(), np.ndarray)
assert float(results.bet_forces.values["Disk0_Force_x"][0].v) == -198185092.5822863
assert str(results.bet_forces.values["Disk0_Force_x"][0].units) == "kg*m/s**2"
assert float(results.bet_forces.values["Disk0_Moment_x"][0].v) == 23068914203.12496
assert str(results.bet_forces.values["Disk0_Moment_x"][0].units) == "kg*m**2/s**2"
def test_downloading(mock_id, mock_response, s3_download_override):
case = fl.Case(id=mock_id)
results = case.results
with tempfile.TemporaryDirectory() as dir:
temp_file_name = os.path.join(dir, "temp.csv")
results.bet_forces.download(temp_file_name, overwrite=True)
results.bet_forces.load_from_local(temp_file_name)
assert results.bet_forces.values["Disk0_Force_x"][0] == -1397.09615312895
case = deepcopy(fl.Case(id=mock_id))
results = case.results
assert results.bet_forces.values["Disk0_Force_x"][0] == -1397.09615312895
case = deepcopy(fl.Case(id=mock_id))
results = case.results
with tempfile.TemporaryDirectory() as temp_dir:
results.bet_forces.download(os.path.join(temp_dir, "bet"))
results.bet_forces.load_from_local(os.path.join(temp_dir, "bet.csv"))
assert results.bet_forces.values["Disk0_Force_x"][0] == -1397.09615312895
@pytest.mark.usefixtures("s3_download_override")
def test_downloader(mock_id, mock_response):
case = fl.Case(id=mock_id)
results = case.results
with tempfile.TemporaryDirectory() as temp_dir:
results.download(all=True, destination=temp_dir)
files = os.listdir(temp_dir)
assert len(files) == 14
results.total_forces.load_from_local(os.path.join(temp_dir, "total_forces_v2.csv"))
assert results.total_forces.values["CL"][0] == 0.400770406499246
case = deepcopy(fl.Case(id=mock_id))
results = case.results
with tempfile.TemporaryDirectory() as temp_dir:
results.download(all=True, total_forces=False, destination=temp_dir)
files = os.listdir(temp_dir)
assert len(files) == 13
case = deepcopy(fl.Case(id=mock_id))
results = case.results
with tempfile.TemporaryDirectory() as temp_dir:
results.download(total_forces=True, destination=temp_dir)
files = os.listdir(temp_dir)
assert len(files) == 1
results.total_forces.load_from_local(os.path.join(temp_dir, "total_forces_v2.csv"))
assert results.total_forces.values["CL"][0] == 0.400770406499246
@pytest.mark.usefixtures("s3_download_override")
def test_x_sectional_results(mock_id, mock_response):
case = fl.Case(id=mock_id)
cd_curve = case.results.x_slicing_force_distribution
# wait for postprocessing to finish
cd_curve.wait()
boundaries = ["fluid/fuselage", "fluid/leftWing", "fluid/rightWing"]
variables = ["Cumulative_CD_Curve", "CD_per_length"]
x_columns = ["X"]
total = [f"total{postfix}" for postfix in variables]
all_headers = (
[f"{prefix}_{postfix}" for prefix, postfix in product(boundaries, variables)]
+ x_columns
+ total
)
expected_val = 0.32168454968207594
assert cd_curve.as_dataframe().iloc[-1]["totalCumulative_CD_Curve"] == 0.42326354287032886
assert set(cd_curve.values.keys()) == set(all_headers)
cd_curve.filter(include="*Wing*")
assert cd_curve.as_dataframe().iloc[-1]["totalCumulative_CD_Curve"] == expected_val
boundaries = ["fluid/leftWing", "fluid/rightWing"]
all_headers = (
[f"{prefix}_{postfix}" for prefix, postfix in product(boundaries, variables)]
+ x_columns
+ total
)
assert set(cd_curve.values.keys()) == set(all_headers)
cd_curve.filter(exclude="*fuselage*")
assert cd_curve.as_dataframe().iloc[-1]["totalCumulative_CD_Curve"] == expected_val
boundaries = ["fluid/leftWing", "fluid/rightWing"]
all_headers = (
[f"{prefix}_{postfix}" for prefix, postfix in product(boundaries, variables)]
+ x_columns
+ total
)
assert set(cd_curve.values.keys()) == set(all_headers)
cd_curve.filter(include=["fluid/leftWing", "fluid/rightWing"])
assert cd_curve.as_dataframe().iloc[-1]["totalCumulative_CD_Curve"] == expected_val
boundaries = ["fluid/leftWing", "fluid/rightWing"]
all_headers = (
[f"{prefix}_{postfix}" for prefix, postfix in product(boundaries, variables)]
+ x_columns
+ total
)
assert set(cd_curve.values.keys()) == set(all_headers)
@pytest.mark.usefixtures("s3_download_override")
def test_y_sectional_results(mock_id, mock_response):
case = fl.Case(id=mock_id)
y_slicing = case.results.y_slicing_force_distribution
# wait for postprocessing to finish
y_slicing.wait()
boundaries = ["fluid/fuselage", "fluid/leftWing", "fluid/rightWing"]
variables = ["CFx_per_span", "CFz_per_span", "CMy_per_span"]
x_columns = ["Y"]
total = [f"total{postfix}" for postfix in variables]
all_headers = (
[f"{prefix}_{postfix}" for prefix, postfix in product(boundaries, variables)]
+ x_columns
+ total
)
assert (
y_slicing.as_dataframe().iloc[-1]["totalCFx_per_span"] == -0.017427309558312547
) # this is numerical error introduced by method used in release-24.11
assert set(y_slicing.values.keys()) == set(all_headers)
y_slicing.filter(include="*Wing*")
assert y_slicing.as_dataframe().iloc[-1]["totalCFx_per_span"] == -0.017427309558312547
boundaries = ["fluid/leftWing", "fluid/rightWing"]
all_headers = (
[f"{prefix}_{postfix}" for prefix, postfix in product(boundaries, variables)]
+ x_columns
+ total
)
assert set(y_slicing.values.keys()) == set(all_headers)
y_slicing.filter(exclude="*fuselage*")
assert y_slicing.as_dataframe().iloc[-1]["totalCFx_per_span"] == -0.017427309558312547
boundaries = ["fluid/leftWing", "fluid/rightWing"]
all_headers = (
[f"{prefix}_{postfix}" for prefix, postfix in product(boundaries, variables)]
+ x_columns
+ total
)
assert set(y_slicing.values.keys()) == set(all_headers)
y_slicing.filter(include=["fluid/leftWing", "fluid/rightWing"])
assert y_slicing.as_dataframe().iloc[-1]["totalCFx_per_span"] == -0.017427309558312547
boundaries = ["fluid/leftWing", "fluid/rightWing"]
all_headers = (
[f"{prefix}_{postfix}" for prefix, postfix in product(boundaries, variables)]
+ x_columns
+ total
)
assert set(y_slicing.values.keys()) == set(all_headers)