Skip to content

Commit 43f8e89

Browse files
committed
working on tests
1 parent 3fa9a48 commit 43f8e89

File tree

5 files changed

+229
-168
lines changed

5 files changed

+229
-168
lines changed

pyNastran/f06/dev/flutter/gui_flutter.py

Lines changed: 25 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,17 @@
5656
from pyNastran.f06.flutter_response import FlutterResponse, Limit
5757
from pyNastran.f06.parse_flutter import get_flutter_units
5858

59-
X_PLOT_TYPES = ['eas', 'tas', 'rho', 'q', 'mach', 'alt', 'kfreq', 'ikfreq', 'index']
60-
PLOT_TYPES = ['x-damp-freq', 'x-damp-kfreq', 'root-locus', 'modal-participation',
61-
'zimmerman']
62-
UNITS_IN = ['english_in', 'english_kt', 'english_ft',
63-
'si', 'si_mm']
64-
MODE_SWITCH_METHODS = ['None', 'Frequency', 'Damping']
65-
66-
UNITS_OUT = UNITS_IN
67-
6859
# FONT_SIZE = 12
6960
from pyNastran.f06.dev.flutter.utils import (
7061
get_point_removal_str,
7162
point_removal_str_to_point_removal,
72-
get_plot_file, update_ylog_style, load_f06_op2,
73-
get_png_filename,)
63+
_float_passed_to_default, _to_str,
64+
get_plot_flags, get_plot_file,
65+
update_ylog_style, get_png_filename,
66+
load_f06_op2,
67+
X_PLOT_TYPES, PLOT_TYPES, UNITS_IN, MODE_SWITCH_METHODS,
68+
)
69+
UNITS_OUT = UNITS_IN
7470

7571
import pyNastran
7672
PKG_PATH = Path(pyNastran.__path__[0])
@@ -1011,75 +1007,27 @@ def setup_widgets(self) -> None:
10111007
def on_plot_type(self) -> None:
10121008
x_plot_type = self.x_plot_type_pulldown.currentText()
10131009
plot_type = self.plot_type_pulldown.currentText()
1014-
1015-
show_index_lim = False
1016-
show_eas_lim = False
1017-
show_tas_lim = False
1018-
show_mach_lim = False
1019-
show_alt_lim = False
1020-
show_q_lim = False
1021-
show_rho_lim = False
1022-
1023-
show_xlim = False
1024-
show_freq = False
1025-
show_damp = False
1026-
show_root_locus = False
1027-
show_zimmerman = False
1028-
show_modal_participation = False
1029-
1030-
# PLOT_TYPES = ['x-damp-freq', 'x-damp-kfreq', 'root-locus']
1031-
assert plot_type in PLOT_TYPES, plot_type
10321010
self.on_units_out()
10331011

1034-
if x_plot_type == 'kfreq':
1035-
show_kfreq = True
1036-
else:
1037-
show_kfreq = False
1012+
flags = get_plot_flags(plot_type, x_plot_type)
1013+
show_index_lim = flags['show_index_lim']
1014+
show_eas_lim = flags['show_eas_lim']
1015+
show_tas_lim = flags['show_tas_lim']
1016+
show_mach_lim = flags['show_mach_lim']
1017+
show_alt_lim = flags['show_alt_lim']
1018+
show_q_lim = flags['show_q_lim']
1019+
show_rho_lim = flags['show_rho_lim']
1020+
1021+
show_xlim = flags['show_xlim']
1022+
show_freq = flags['show_freq']
1023+
show_damp = flags['show_damp']
1024+
show_kfreq = flags['show_kfreq']
1025+
show_ikfreq = flags['show_ikfreq']
1026+
show_root_locus = flags['show_root_locus']
1027+
show_zimmerman = flags['show_zimmerman']
1028+
show_modal_participation = flags['show_modal_participation']
1029+
10381030

1039-
if x_plot_type == 'ikfreq':
1040-
show_ikfreq = True
1041-
else:
1042-
show_ikfreq = False
1043-
1044-
if plot_type == 'x-damp-freq':
1045-
show_xlim = True
1046-
show_damp = True
1047-
show_freq = True
1048-
elif plot_type == 'x-damp-kfreq':
1049-
# kfreq-damp-kfreq not handled
1050-
show_xlim = True
1051-
show_damp = True
1052-
show_kfreq = True
1053-
elif plot_type == 'zimmerman':
1054-
show_zimmerman = True
1055-
elif plot_type == 'root-locus':
1056-
show_root_locus = True
1057-
# show_kfreq = False
1058-
elif plot_type == 'modal-participation':
1059-
show_modal_participation = True
1060-
# show_kfreq = False
1061-
else: # pragma: no cover
1062-
raise RuntimeError(f'plot_type={plot_type!r}')
1063-
1064-
if show_xlim:
1065-
if 'index' == x_plot_type:
1066-
show_index_lim = True
1067-
elif 'eas' == x_plot_type:
1068-
show_eas_lim = True
1069-
elif 'tas' == x_plot_type:
1070-
show_tas_lim = True
1071-
elif 'mach' == x_plot_type:
1072-
show_mach_lim = True
1073-
elif 'alt' == x_plot_type:
1074-
show_alt_lim = True
1075-
elif 'q' == x_plot_type:
1076-
show_q_lim = True
1077-
elif 'rho' == x_plot_type:
1078-
show_rho_lim = True
1079-
elif 'kfreq' == x_plot_type:
1080-
show_kfreq_lim = True
1081-
elif 'ikfreq' == x_plot_type:
1082-
show_ikfreq_lim = True
10831031
# print(f'x_plot_type={x_plot_type} show_damp={show_damp}; show_xlim={show_xlim}')
10841032
# assert show_xlim is False, show_xlim
10851033

@@ -2299,21 +2247,6 @@ def get_float_or_none(line_edit: QLineEdit) -> tuple[Optional[float | str], bool
22992247
return value, is_passed
23002248

23012249

2302-
def _to_str(value: Optional[int | float]) -> str:
2303-
if value is None:
2304-
str_value = ''
2305-
else:
2306-
str_value = str(value)
2307-
return str_value
2308-
2309-
2310-
def _float_passed_to_default(value: float, is_passed: bool,
2311-
default: float=-1.0) -> float:
2312-
if is_passed and value is None:
2313-
value = default
2314-
return value
2315-
2316-
23172250
def main(f06_filename: str='') -> None: # pragma: no cover
23182251
# kills the program when you hit Cntl+C from the command line
23192252
# doesn't save the current state as presumably there's been an error

pyNastran/f06/dev/flutter/test_gui_flutter.py

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
from pathlib import Path
22
import unittest
33

4+
import numpy as np
45
from cpylog import SimpleLogger
56

6-
from pyNastran.dev.bdf_vectorized3.bdf import read_bdf
7+
import pyNastran
78
from pyNastran.f06.dev.flutter.nastran_utils import (
89
get_element_table, get_property_table, get_material_table)
910
from pyNastran.f06.dev.flutter.action import Action
10-
from pyNastran.f06.dev.flutter.utils import load_f06_op2
11+
from pyNastran.f06.dev.flutter.utils import (
12+
get_plot_flags,
13+
load_f06_op2, get_png_filename, get_plot_file,
14+
point_removal_str_to_point_removal,
15+
get_point_removal_str)
16+
17+
IS_DEV = pyNastran.DEV
18+
if IS_DEV:
19+
from pyNastran.dev.bdf_vectorized3.bdf import read_bdf
1120

12-
import pyNastran
1321
PKG_PATH = Path(pyNastran.__path__[0])
1422
MODEL_PATH = (PKG_PATH / '..' / 'models').absolute()
23+
AERO_PATH = MODEL_PATH / 'aero'
1524

1625

1726
class TestGuiFlutter(unittest.TestCase):
@@ -28,14 +37,79 @@ def test_action(self) -> None:
2837

2938
def test_load_f06_op2(self) -> None:
3039
f06_filename = MODEL_PATH / 'aero' / '2_mode_flutter' / '0012_flutter.op2'
31-
log = SimpleLogger(level='info')
40+
log = SimpleLogger(level='warning')
3241
in_units = 'si'
3342
out_units = 'si'
3443
load_f06_op2(f06_filename, log, in_units, out_units, use_rhoref=False)
3544

3645
op2_filename = MODEL_PATH / 'bwb' / 'bwb_saero.op2'
3746
load_f06_op2(op2_filename, log, in_units, out_units, use_rhoref=False)
3847

48+
@unittest.skipIf(not IS_DEV, 'no flutter-dev')
49+
def test_plot_flutter_0012_dev(self):
50+
"""tests load_f06_op2 and get_png_filename"""
51+
log = SimpleLogger(level='warning')
52+
dirname = AERO_PATH / '2_mode_flutter'
53+
f06_filename = dirname / '0012_flutter.f06'
54+
model, responses = load_f06_op2(f06_filename, log,
55+
in_units='si', out_units='si', use_rhoref=False)
56+
assert model is None, model
57+
assert len(responses) == 1, responses
58+
59+
f06_filename2 = 'cat.f06'
60+
model, responses = load_f06_op2(
61+
f06_filename2, log,
62+
in_units='si', out_units='si', use_rhoref=False)
63+
assert model is None, model
64+
assert len(responses) == 0, responses
65+
66+
f06_filename2 = 'cat.op2'
67+
model, responses = load_f06_op2(
68+
f06_filename2, log,
69+
in_units='si', out_units='si', use_rhoref=False)
70+
assert model is None, model
71+
assert len(responses) == 0, responses
72+
73+
def test_plot_file(self):
74+
out = get_plot_file()
75+
76+
base = 'base'
77+
x_plot_type = 'eas'
78+
plot_type = 'Vg'
79+
export_to_png = True
80+
png_filename0, png_filename = get_png_filename(
81+
base, x_plot_type, plot_type,
82+
export_to_png)
83+
assert png_filename0 == 'base_Vg.png', png_filename0
84+
assert png_filename == 'base_Vg.png', png_filename
85+
png_filename0, png_filename = get_png_filename(
86+
base, x_plot_type, 'x-'+plot_type,
87+
export_to_png)
88+
assert png_filename0 == 'base_eas-Vg.png', png_filename0
89+
assert png_filename == 'base_eas-Vg.png', png_filename
90+
91+
png_filename0, png_filename = get_png_filename(
92+
base, 'x-'+x_plot_type, plot_type,
93+
export_to_png=False)
94+
assert png_filename0 == 'base_Vg.png', png_filename0
95+
assert png_filename is None, png_filename
96+
97+
def test_get_plot_flags(self):
98+
# X_PLOT_TYPES = ['eas', 'tas', 'rho', 'q', 'mach', 'alt', 'kfreq', 'ikfreq', 'index']
99+
# PLOT_TYPES = ['x-damp-freq', 'x-damp-kfreq', 'root-locus', 'modal-participation', 'zimmerman']
100+
flags = get_plot_flags('x-damp-freq', 'eas')
101+
del flags
102+
103+
def test_point_removal(self):
104+
log = SimpleLogger(level='debug')
105+
msg = '400:410,450:500'
106+
point_removal = [[400.0, 410.0], [450.0, 500.0]]
107+
point_removal_list = point_removal_str_to_point_removal(
108+
msg, log)
109+
assert np.allclose(point_removal, point_removal_list), point_removal_list
110+
111+
out = get_point_removal_str(point_removal_list)
112+
assert out == msg, out
39113

40114
if __name__ == '__main__':
41115
unittest.main()

pyNastran/f06/dev/flutter/utils.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
from pyNastran.op2.op2 import OP2
1414

1515

16+
X_PLOT_TYPES = ['eas', 'tas', 'rho', 'q', 'mach', 'alt', 'kfreq', 'ikfreq', 'index']
17+
PLOT_TYPES = ['x-damp-freq', 'x-damp-kfreq', 'root-locus', 'modal-participation',
18+
'zimmerman']
19+
UNITS_IN = ['english_in', 'english_kt', 'english_ft',
20+
'si', 'si_mm']
21+
MODE_SWITCH_METHODS = ['None', 'Frequency', 'Damping']
22+
1623
def load_f06_op2(f06_filename: str, log: SimpleLogger,
1724
in_units: str,
1825
out_units: str,
@@ -203,3 +210,110 @@ def point_removal_str_to_point_removal(point_removal_str: str,
203210
# print(traceback.print_tb(e))
204211
print(traceback.print_exception(e))
205212
return point_removal
213+
214+
215+
216+
217+
def _to_str(value: Optional[int | float]) -> str:
218+
if value is None:
219+
str_value = ''
220+
else:
221+
str_value = str(value)
222+
return str_value
223+
224+
225+
def _float_passed_to_default(value: float, is_passed: bool,
226+
default: float=-1.0) -> float:
227+
if is_passed and value is None:
228+
value = default
229+
return value
230+
231+
232+
def get_plot_flags(plot_type: str,
233+
x_plot_type: str) -> dict[str, bool]:
234+
show_index_lim = False
235+
show_eas_lim = False
236+
show_tas_lim = False
237+
show_mach_lim = False
238+
show_alt_lim = False
239+
show_q_lim = False
240+
show_rho_lim = False
241+
242+
show_xlim = False
243+
show_freq = False
244+
show_damp = False
245+
show_root_locus = False
246+
show_zimmerman = False
247+
show_modal_participation = False
248+
249+
# PLOT_TYPES = ['x-damp-freq', 'x-damp-kfreq', 'root-locus']
250+
assert plot_type in PLOT_TYPES, plot_type
251+
252+
if x_plot_type == 'kfreq':
253+
show_kfreq = True
254+
else:
255+
show_kfreq = False
256+
257+
if x_plot_type == 'ikfreq':
258+
show_ikfreq = True
259+
else:
260+
show_ikfreq = False
261+
262+
if plot_type == 'x-damp-freq':
263+
show_xlim = True
264+
show_damp = True
265+
show_freq = True
266+
elif plot_type == 'x-damp-kfreq':
267+
# kfreq-damp-kfreq not handled
268+
show_xlim = True
269+
show_damp = True
270+
show_kfreq = True
271+
elif plot_type == 'zimmerman':
272+
show_zimmerman = True
273+
elif plot_type == 'root-locus':
274+
show_root_locus = True
275+
# show_kfreq = False
276+
elif plot_type == 'modal-participation':
277+
show_modal_participation = True
278+
# show_kfreq = False
279+
else: # pragma: no cover
280+
raise RuntimeError(f'plot_type={plot_type!r}')
281+
282+
if show_xlim:
283+
if 'index' == x_plot_type:
284+
show_index_lim = True
285+
elif 'eas' == x_plot_type:
286+
show_eas_lim = True
287+
elif 'tas' == x_plot_type:
288+
show_tas_lim = True
289+
elif 'mach' == x_plot_type:
290+
show_mach_lim = True
291+
elif 'alt' == x_plot_type:
292+
show_alt_lim = True
293+
elif 'q' == x_plot_type:
294+
show_q_lim = True
295+
elif 'rho' == x_plot_type:
296+
show_rho_lim = True
297+
elif 'kfreq' == x_plot_type:
298+
show_kfreq_lim = True
299+
elif 'ikfreq' == x_plot_type:
300+
show_ikfreq_lim = True
301+
flags = {
302+
'show_index_lim': show_index_lim,
303+
'show_eas_lim': show_eas_lim,
304+
'show_tas_lim': show_tas_lim,
305+
'show_mach_lim': show_mach_lim,
306+
'show_alt_lim': show_alt_lim,
307+
'show_q_lim': show_q_lim,
308+
'show_rho_lim': show_rho_lim,
309+
310+
'show_xlim': show_xlim,
311+
'show_freq': show_freq,
312+
'show_damp': show_damp,
313+
'show_kfreq': show_kfreq,
314+
'show_ikfreq': show_ikfreq,
315+
'show_root_locus': show_root_locus,
316+
'show_modal_participation': show_modal_participation,
317+
'show_zimmerman': show_zimmerman,
318+
}
319+
return flags

pyNastran/f06/f06_to_pressure_loads.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def f06_to_pressure_loads(f06_filename: PathLike,
1414
loads_filename: PathLike,
1515
nid_csv_filename: PathLike='',
1616
eid_csv_filename: PathLike='',
17-
log: Optional[SimpleLogger]=None,
1817
nlines_max: int=1_000_000,
18+
log: Optional[SimpleLogger]=None,
1919
debug: bool=False) -> dict:
2020
caero_model = read_bdf(aerobox_caero_filename, log=log,
2121
xref=False, validate=False, debug=debug)

0 commit comments

Comments
 (0)