Skip to content

Commit 7b693c2

Browse files
committed
more tests
1 parent a710b70 commit 7b693c2

File tree

3 files changed

+110
-11
lines changed

3 files changed

+110
-11
lines changed

pyNastran/f06/dev/flutter/utils.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
from pathlib import Path
44
import shutil
5+
import traceback
56
from typing import Optional, TYPE_CHECKING
67
from matplotlib import pyplot as plt
78
from pyNastran.f06.parse_flutter import make_flutter_response, get_flutter_units
@@ -145,3 +146,60 @@ def move_filename(old_filename: Path,
145146
if old_filename.exists():
146147
os.remove(old_filename)
147148
return
149+
150+
151+
def get_point_removal_str(point_removal: list[tuple[float, float]]):
152+
"""
153+
>>> point_removal = [[400.0, 410.0], [450.0, 500.0]]
154+
point_removal_str = get_point_removal_str(point_removal)
155+
>>> point_removal_str
156+
'400:410,450:500'
157+
158+
>>> point_removal = [[450.0, -1.0]]
159+
point_removal_str = get_point_removal_str(point_removal)
160+
>>> point_removal_str
161+
'450:'
162+
163+
>>> point_removal = [[-1.0, 500.0]]
164+
point_removal_str = get_point_removal_str(point_removal)
165+
>>> point_removal_str
166+
':500'
167+
"""
168+
out = []
169+
for mini, maxi in point_removal:
170+
if mini > 0 and maxi > 0:
171+
outi = f'{mini:g}:{maxi:g}'
172+
elif mini > 0:
173+
outi = f'{mini:g}:'
174+
elif maxi > 0:
175+
outi = f'{maxi:g}:'
176+
else:
177+
continue
178+
out.append(outi)
179+
point_removal_str = ','.join(out)
180+
return point_removal_str
181+
182+
183+
def point_removal_str_to_point_removal(point_removal_str: str,
184+
log: SimpleLogger) -> list[tuple[float, float]]:
185+
point_removal = []
186+
point_removal_list = point_removal_str.split(',')
187+
188+
if point_removal_list == ['']:
189+
pass
190+
else:
191+
try:
192+
for ipoint, point in enumerate(point_removal_list):
193+
sline = point.split(':')
194+
assert len(sline) == 2, f'point_removal[{ipoint}]={sline}; point_removal={str(point_removal_list)}'
195+
a_str = sline[0].strip()
196+
b_str = sline[1].strip()
197+
a = float(a_str) if a_str != '' else -1.0
198+
b = float(b_str) if b_str != '' else -1.0
199+
point_float = (a, b)
200+
point_removal.append(point_float)
201+
except Exception as e:
202+
log.error(str(e))
203+
# print(traceback.print_tb(e))
204+
print(traceback.print_exception(e))
205+
return point_removal

pyNastran/f06/f06_matrix_parser.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ def _parse_complex_row_lines(lines: list[str]) -> tuple[np.ndarray, np.ndarray]:
346346
line2 = line.replace('D', 'E')
347347
row_id_str, data_str = line2.split(')')
348348

349-
pairs = data_str.replace(' ', '!').split('!')
349+
# split based on double spaces, but we need a character that is valid
350+
pairs = data_str.replace(' ', '!').strip('!').split('!')
350351
#pairs = [line2[10:35], line2[35:61], line2[61:84], line2[84:110], line2[110:135]]
351352
row_i = int(row_id_str)
352353
for pair in pairs:
@@ -358,6 +359,7 @@ def _parse_complex_row_lines(lines: list[str]) -> tuple[np.ndarray, np.ndarray]:
358359
datai = complex(reali, complexi)
359360
data_list.append(datai)
360361
row_index_list.append(row_i)
362+
# print(f' {row_i}: {datai}')
361363
row_i += 1
362364
row_index = np.array(row_index_list, dtype='int32')
363365
data = np.array(data_list, dtype='complex128')
@@ -368,15 +370,6 @@ def _parse_real_row_lines(lines: list[str]) -> tuple[np.ndarray, np.ndarray]:
368370
"""
369371
1) 1.1010E+01 1.3762E+00 -4.2021E+00 -5.2526E-01
370372
"""
371-
#lines = [
372-
#' 1) -3.5846E+01,-1.3275E+02 -1.5510E+01, 2.3578E-01 -3.2339E+01,-4.9373E+00 6.8078E+01, 1.3428E+01 3.0262E+01, 2.4554E+01',
373-
#' 6) 1.5360E-04,-1.1042E-04 -4.7606E-04, 2.3069E-04 1.0359E-03,-1.5668E-04 -1.3075E-03, 7.8472E-04 2.3471E-04,-4.8359E-04',
374-
#]
375-
#lines = [
376-
#' 1) -3.5846E+01,-1.3275E+02',
377-
#' 6) 1.5360E-04,-1.1042E-04',
378-
#]
379-
380373
row_index_list = []
381374
data_list = []
382375
for line in lines:
@@ -507,5 +500,6 @@ def main(): # pragma: no cover
507500
for row, col, value in zip(mat.row, mat.col, mat.data):
508501
print(f'{row}, {col}, {value}')
509502

503+
510504
if __name__ == '__main__':
511505
main()

pyNastran/f06/test/test_f06_utils.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@
4040
)
4141
from pyNastran.f06.flutter_response import _reshape_eigenvectors
4242
from pyNastran.f06.parse_trim import read_f06_trim
43+
from pyNastran.f06.f06_matrix_parser import _parse_real_row_lines, _parse_complex_row_lines
4344
from pyNastran.f06.f06_to_pressure_loads import f06_to_pressure_loads
4445
from pyNastran.f06.dev.read_sol_200 import plot_sol_200 # read_sol_200
4546
from pyNastran.op2.op2 import OP2
4647
from pyNastran.utils import print_bad_path
4748
try:
4849
from pyNastran.f06.dev.flutter.utils import (
49-
load_f06_op2, get_png_filename, get_plot_file)
50+
load_f06_op2, get_png_filename, get_plot_file,
51+
point_removal_str_to_point_removal,
52+
get_point_removal_str)
5053
except ImportError:
5154
pass
5255
IS_DEV = pyNastran.DEV
@@ -61,6 +64,16 @@
6164

6265

6366
class TestF06Flutter(unittest.TestCase):
67+
def test_point_removal(self):
68+
log = SimpleLogger(level='debug')
69+
msg = '400:410,450:500'
70+
point_removal = [[400.0, 410.0], [450.0, 500.0]]
71+
point_removal_list = point_removal_str_to_point_removal(
72+
msg, log)
73+
assert np.allclose(point_removal, point_removal_list), point_removal_list
74+
75+
out = get_point_removal_str(point_removal_list)
76+
assert out == msg, out
6477

6578
def test_reshape_eigenvectors(self):
6679
"""
@@ -941,6 +954,40 @@ def test_split_int_colon(self):
941954
f = split_int_colon('1,3,5')
942955
assert f == [1, 3, 5], f
943956

957+
def test_parse_real_row_lines(self):
958+
lines = [
959+
' 1) 1.1010E+01 1.3762E+00 -4.2021E+00 -5.2526E-01',
960+
]
961+
row1, data1 = _parse_real_row_lines(lines)
962+
assert np.array_equal(row1, [1, 2, 3, 4])
963+
assert np.array_equal(data1, [1.1010E+01, 1.3762E+00, -4.2021E+00, -5.2526E-01])
964+
965+
def test_parse_complex_row_lines(self):
966+
lines = [
967+
' 1) -3.5846E+01,-1.3275E+02 -1.5510E+01, 2.3578E-01 -3.2339E+01,-4.9373E+00 6.8078E+01, 1.3428E+01 3.0262E+01, 2.4554E+01',
968+
' 6) 1.5360E-04,-1.1042E-04 -4.7606E-04, 2.3069E-04 1.0359E-03,-1.5668E-04 -1.3075E-03, 7.8472E-04 2.3471E-04,-4.8359E-04',
969+
]
970+
row1, data1 = _parse_complex_row_lines(lines)
971+
assert np.array_equal(row1, [1, 2, 3, 4, 5,
972+
6, 7, 8, 9, 10]), row1
973+
reals = [
974+
-3.5846E+01, -1.5510E+01, -3.2339E+01, 6.8078E+01, 3.0262E+01,
975+
1.5360E-04, -4.7606E-04, 1.0359E-03, -1.3075E-03, 2.3471E-04]
976+
imags = [
977+
-1.3275E+02, 2.3578E-01, -4.9373E+00, 1.3428E+01, 2.4554E+01,
978+
-1.1042E-04, 2.3069E-04, -1.5668E-04, 7.8472E-04, -4.8359E-04]
979+
assert np.array_equal(data1.real, reals)
980+
assert np.array_equal(data1.imag, imags)
981+
982+
lines = [
983+
' 1) -3.5846E+01,-1.3275E+02',
984+
' 6) 1.5360E-04,-1.1042E-04',
985+
]
986+
row2, data2 = _parse_complex_row_lines(lines)
987+
assert np.array_equal(row2, [1, 6])
988+
assert np.array_equal(data2.real, [-3.5846E+01, 1.5360E-04])
989+
assert np.array_equal(data2.imag, [-1.3275E+02, -1.1042E-04])
990+
944991

945992
if __name__ == '__main__': # pragma: no cover
946993
unittest.main()

0 commit comments

Comments
 (0)