Skip to content

Commit

Permalink
op2:
Browse files Browse the repository at this point in the history
 - finally fixing numpy deprecation warning
 - fixed vg-vf case-key bug
 - fixed test_pynastrangui bug trying to load only an op2
  • Loading branch information
Steve Doyle committed Dec 5, 2024
1 parent 265afa7 commit 2b78dfc
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 5 deletions.
119 changes: 119 additions & 0 deletions pyNastran/bdf/mesh_utils/build_rib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
from pyNastran.bdf.bdf import BDF
import numpy as np

def build_rib(model: BDF,
nids_top: list[int],
nids_mid: list[int],
nids_bottom: list[int],
pid: int=1,
nid0: int=0,
eid0: int=0):

"""
T1---T2----T3----3
|
* * M1----2
|
* * M2----1
|
B1---B2----B3----0
3-0 = 3 / 3 elemnts = 1
Parameters
----------
nids_top
nids_mid
nids_bottom
Returns
-------
"""
if nid0 == 0:
nid0 = max(model.nodes) + 1
assert len(nids_top) == len(nids_bottom), (nids_top, nids_bottom)

ncols = len(nids_top)
nrows = len(nids_mid) + 2
nids_bottom2 = nids_bottom[::-1]
A = np.zeros((nrows, ncols), dtype='int32')
A[0, :] = nids_top
print(A)
print(nids_mid)
A[1:1+len(nids_mid), -1] = nids_mid
A[-1, :] = nids_bottom2
print(A)

# assume linear
nnodes_mid = len(nids_mid)
nelements_tall = nnodes_mid + 1
for jcol in range(ncols-1):
nid_top = nids_top[jcol]
nid_btm = nids_bottom2[jcol]
print('*', nid_top, nid_btm)
xyz_top = model.nodes[nid_top].get_position()
xyz_btm = model.nodes[nid_btm].get_position()
dz = (xyz_top - xyz_btm) / nelements_tall

for inode in range(nnodes_mid):
xyz_mid = xyz_top + dz * (inode + 1)
model.add_grid(nid0, xyz=xyz_mid)
nid0 += 1
A[inode+1, jcol] = nid0
eid0 = nid_matrix_to_quads(A, eid0, pid)


def nid_matrix_to_quads(nids_array: np.ndarray, eid0: int, pid: int) -> int:
print(nids_array)
n1 = nids_array[:-1, :-1].ravel()
n2 = nids_array[:-1, 1:].ravel()
n3 = nids_array[1:, 1:].ravel()
n4 = nids_array[1:, :-1].ravel()

for n1i, n2i, n3i, n4i in zip(n1, n2, n3, n4):
print(n1i, n2i, n3i, n4i)
nodes = [n1i, n2i, n3i, n4i]
model.add_cquad4(eid0, pid, nodes)
eid0 += 1
return eid0
#print(n1)
#print(n2)
#print(n3)
#print(n4)

def main():
# A = np.array([
# [1, 2, 3],
# [4, 5, 6],
# [7, 8, 9],
# ])
# nid_matrix_to_quads(A, 0)
# asdf
model = BDF()
nids_top = [1, 2, 3]
nids_mid = [4, 5]
nids_bottom = [6, 7, 8]
nid_xyzs = [
(1, 0., 0., 0.),
(2, 1., 0., 0.),
(3, 2., 0., 0.),
# mid
(4, 2., 1., 0.),
(5, 2., 2., 0.),
# btm
(6, 2., 3., 0.),
(7, 1., 0., 0.),
(8, 0., 0., 0.),
]
for nid, x, y, z in nid_xyzs:
xyz = [x, y, z]
model.add_grid(nid, xyz=xyz)
build_rib(model, nids_top, nids_mid, nids_bottom)
nids = [(6001145, 6001146, 6011896),
(6011897, 6011903, 6011908, 6011960),
(6011963, 6011968, 6011971),
]


if __name__ == '__main__':
main()
7 changes: 6 additions & 1 deletion pyNastran/gui/arg_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ def determine_format(input_filename: str,
"""
if output_filenames is None:
output_filenames = []
assert None not in output_filenames, output_filenames

out_exts = [os.path.splitext(fname)[1] for fname in output_filenames]
try:
out_exts = [os.path.splitext(fname)[1] for fname in output_filenames]
except TypeError:
print(f'output_filenames = {output_filenames}')
raise
out_ext = '' if len(out_exts) == 0 else out_exts[0]

if allowed_formats is None:
Expand Down
5 changes: 4 additions & 1 deletion pyNastran/gui/test/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,11 @@ def run_docopt(argv=None):
if not os.path.isfile(input_filename):
raise RuntimeError(f'input_filename={input_filename!r} is not a file')
input_filenames = [input_filename]
output_filenames = [output_filename]
output_filenames = []
if output_filename is not None:
output_filenames.append(output_filename)

assert None not in output_filenames, output_filenames
if data['--format']:
formati = data['--format'].lower()
else:
Expand Down
41 changes: 38 additions & 3 deletions pyNastran/op2/op2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,9 @@ def combine_results(self, combine: bool=True) -> None:
raise IndexError(msg)
#if not subcasei == isubcase:
#continue
if case_key not in subcase_key2[subcasei]:
subcase_key2s = list(subcase_key2)
is_new_key = _inlist_int_tuple(case_key, subcase_key2[subcasei])
if not is_new_key:
subcase_key2[isubcase].append(case_key)
self.subcase_key = subcase_key2
#print('subcase_key = %s' % self.subcase_key)
Expand Down Expand Up @@ -1079,7 +1081,7 @@ def get_key_order(self) -> list[NastranKey]:
keys = []
table_types = self.get_table_types()
skip_tables = ['gpdt', 'bgpdt', 'eqexin', 'grid_point_weight', 'psds',
'monitor1', 'monitor3', 'cstm']
'monitor1', 'monitor3', 'cstm', 'vg_vf_response']
for table_type in sorted(table_types):
if table_type in skip_tables or table_type.startswith('responses.'):
continue
Expand Down Expand Up @@ -1120,7 +1122,11 @@ def get_key_order(self) -> list[NastranKey]:

used_keys = set([])
for key in keys:
#print('key = %s' % str(key))
try:
len(key) # vg_vf_response uses a single integer
except TypeError:
self.log.error('key = %s' % str(key))
raise
if len(key) == 6:
isubcase, analysis_code, sort_method, count, superelement_adaptivity_index, pval_step = key
used_key = (isubcase, analysis_code, sort_method, count, ogs, superelement_adaptivity_index, pval_step)
Expand Down Expand Up @@ -1331,6 +1337,8 @@ def transform_gpforce_to_global(self, nids_all, nids_transform, icd_transform, c

def _inlist(case_key: int, keys: list[Any]) -> bool:
"""
Fixes numpy deprecation warning
case_key not in subcase_key2[isubcase])
"""
if len(keys) == 0:
Expand All @@ -1347,6 +1355,33 @@ def _inlist(case_key: int, keys: list[Any]) -> bool:
return True
return found_case_key

def _inlist_int_tuple(case_key: int | tuple,
keys: list[Any]) -> bool:
"""
Fixes numpy deprecation warning
found_case_key = case_key not in subcase_key2[isubcase])
"""
if len(keys) == 0:
return False
#assert isinstance(case_key, integer_types), case_key
assert isinstance(keys, list), keys
#print(type(case_key))
found_case_key = False
if isinstance(case_key, integer_types):
for key in keys:
if isinstance(key, tuple):
continue
if key == case_key:
return True
else:
assert isinstance(case_key, tuple), case_key
for key in keys:
if isinstance(key, integer_types):
continue
if key == case_key:
return True
return found_case_key

def read_op2(op2_filename: Optional[str]=None,
load_geometry: bool=False,
Expand Down
1 change: 1 addition & 0 deletions pyNastran/op2/test/test_op2.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ def run_op2(op2_filename: PathLike, make_geom: bool=False, combine: bool=True,
op2.get_op2_stats(short=True)
op2.object_attributes()
op2.object_methods()
op2.get_key_order()
if not quiet:
print(f'---stats for {op2_filename}---')
print(op2.get_op2_stats(short=short_stats))
Expand Down

0 comments on commit 2b78dfc

Please sign in to comment.