Skip to content

Commit

Permalink
op2_vectorized3:
Browse files Browse the repository at this point in the history
 - adding h5 results
  • Loading branch information
SteveDoyle2 committed Oct 22, 2023
1 parent 2c19d5d commit 7b03f44
Show file tree
Hide file tree
Showing 15 changed files with 3,437 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from pyNastran.dev.bdf_vectorized3.bdf_interface.h5_pytables.h5_nodes import load_h5_node
from pyNastran.dev.bdf_vectorized3.bdf_interface.h5_pytables.h5_coords import load_h5_coord
#from pyNastran.dev.bdf_vectorized3.bdf_interface.h5_pytables.h5_parameter import load_h5_parameter
from pyNastran.dev.bdf_vectorized3.bdf_interface.h5_pytables.h5_parameter import load_h5_parameter
#from pyNastran.dev.bdf_vectorized3.bdf_interface.h5_pytables.h5_partition import load_h5_partition
from pyNastran.dev.bdf_vectorized3.bdf_interface.h5_pytables.h5_properties import load_h5_property
from pyNastran.dev.bdf_vectorized3.bdf_interface.h5_pytables.h5_materials import load_h5_material
Expand Down Expand Up @@ -74,9 +74,9 @@ def read_geometry_from_h5(model: BDF, h5_file: File, input_path: str):
elif name == 'LOAD':
log.warning(f'skipping h5group name={name}')
continue
#elif name == 'PARAMETER':
#load_h5_parameter(model, h5_node_)
#continue
elif name == 'PARAMETER':
load_h5_parameter(model, h5_node_)
continue
#elif name == 'PARTITION':
#load_h5_partition(model, h5_node_)
#continue
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
from __future__ import annotations
from typing import TYPE_CHECKING
import numpy as np

from .utils import cast_encoding_strip, cast_encoding_strip0, get_group_name
if TYPE_CHECKING: # pragma: no cover
from pyNastran.dev.bdf_vectorized3.bdf import BDF
from tables import Group


def _load_h5_parameter_pvt(model: BDF, group: Group, encoding: str):
for h5_element in group._f_iter_nodes():
class_id = h5_element._c_classid
if class_id == 'GROUP':
group_name = get_group_name(group)
raise RuntimeError(group_name)
#msg += f'{indent}Group: {group_name}\n'
#indent += ' '
#print_group(group, indent=indent)
#continue
elif class_id == 'TABLE':
pass
else: # pragma: no cover
raise RuntimeError(class_id)
datatype = h5_element.name
data = h5_element.read()
name_bytes = data['NAME']
name = cast_encoding_strip(name_bytes, encoding)
if datatype == 'INT':
# NAME, VALUE
value = data['VALUE']
for key, valuei in zip(name, value):
model.add_param(key, [valuei])
elif datatype == 'CHAR':
# NAME, VALUE
value_bytes = data['VALUE']
value = cast_encoding_strip(value_bytes, encoding)
for key, valuei in zip(name, value):
model.add_param(key, [valuei])
elif datatype == 'DOUBLE':
# NAME, VALUE
value = data['VALUE']
for key, valuei in zip(name, value):
model.add_param(key, [valuei])
else: # pragma: no cover
raise NotImplementedError(datatype)
x = 1

def _load_h5_parameter_group(model: BDF, group: Group, encoding: str):
group_name = get_group_name(group)
skip_names = {'CASECC', 'TSTEP'} # , 'PVT',
if group_name in skip_names:
model.log.warning(f'skipping {group_name} in _load_h5_parameter_group')
elif group_name == 'PVT':
_load_h5_parameter_pvt(model, group, encoding)
elif group_name == 'AECOMP':
#('NAME', 'LISTTYPE', 'LISTIDS_POS', 'LISTIDS_LEN', 'DOMAIN_ID')
identity = group['IDENTITY'].read()
name = identity['NAME']
list_type = cast_encoding_strip(identity['LISTTYPE'], encoding)
nlists = identity['LISTIDS_LEN']
lists = group['LISTIDS'].read()
model.aecomp._save(name, list_type, nlists, lists)
elif group_name == 'AECOMPL':
#('NAME', 'LABELS_POS', 'LABELS_LEN', 'DOMAIN_ID')
identity = group['IDENTITY'].read()
name = identity['NAME']
nlabels = identity['LABELS_LEN']
labels_bytes = group['LABELS'].read()
labels = cast_encoding_strip0(labels_bytes, encoding)
model.aecompl._save(name, nlabels, labels)
elif group_name == 'AEFACT':
#('SID', 'DIS_POS', 'DIS_LEN', 'DOMAIN_ID')
identity = group['IDENTITY'].read()
aefact_id = identity['SID']
nfractions = identity['DIS_LEN']
fractions = group['DIS'].read()
model.aefact._save(aefact_id, nfractions, fractions)
else:
raise NotImplementedError(group_name)

def load_h5_parameter(model: BDF, group: Group, encoding: str='latin1'):
for h5_element in group._f_iter_nodes():
class_id = h5_element._c_classid
if class_id == 'GROUP':
_load_h5_parameter_group(model, h5_element, encoding)
continue
elif class_id == 'TABLE':
pass
else: # pragma: no cover
raise RuntimeError(class_id)
name = h5_element.name
data = h5_element.read()
#if name in {'PVT'}:
#model.log.warning(f'skipping {element_name} in load_h5_parameter')
if name == 'TSTEPNL':
model.log.warning(f'skipping {name} in load_h5_parameter')
elif name == 'AEROS':
#('ACSID', 'RCSID', 'REFC', 'REFB', 'REFS', 'SYMXZ', 'SYMXY', 'DOMAIN_ID')
acsid = data['ACSID'][0]
rcsid = data['RCSID'][0]
bref = data['REFB'][0]
cref = data['REFC'][0]
sref = data['REFS'][0]
sym_xz = data['SYMXZ'][0]
sym_xy = data['SYMXY'][0]
aeros = model.add_aeros(cref, bref, sref, acsid=acsid,
rcsid=rcsid, sym_xz=sym_xz, sym_xy=sym_xy, comment='')
str(aeros)
elif name == 'AESTAT':
#('ID', 'LABEL', 'DOMAIN_ID')
aestat_ids = data['ID']
labels = data['LABEL']
for aestat_id, label in zip(aestat_ids, labels):
label_str = label.strip().decode('latin1')
model.add_aestat(aestat_id, label_str, comment='')
elif name == 'MDLPRM':
#('NAME', 'VALUE', 'DOMAIN_ID')
names = data['NAME']
values = data['VALUE']
mdlprm_dict = {}
for name, value in zip(names, values):
name_str = name.strip().decode('latin1')
mdlprm_dict[name_str] = value
assert len(mdlprm_dict) == 1, mdlprm_dict
assert 'HDF5' in mdlprm_dict, mdlprm_dict
model.add_mdlprm(mdlprm_dict, comment='')
elif name == 'MONPNT1':
name = data['NAME']
label = data['LABEL']
axes = data['AXES']
comp = data['COMP']
cp = data['CP']
xyz = np.stack(
[data['X'], data['Y'], data['Z']],
axis=1)
assert xyz.shape[1] == 3, xyz.shape
cd = data['CD']
model.monpnt1._save(
name, label, comp, axes, cp, xyz, cd)
else: # pragma: no cover
raise NotImplementedError(name)
2 changes: 1 addition & 1 deletion pyNastran/dev/bdf_vectorized3/cards/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from pyNastran.femutils.utils import hstack_lists


if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: no cover
from pyNastran.bdf.bdf_interface.bdf_card import BDFCard
from pyNastran.nptyping_interface import NDArray3float
from pyNastran.dev.bdf_vectorized3.bdf import BDF
Expand Down
5 changes: 3 additions & 2 deletions pyNastran/dev/bdf_vectorized3/nastran_io3.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
create_alt_conm2_grids, create_alt_rbe2_grids, create_alt_rbe3_grids,
create_alt_axes,
create_monpnt)
#from pyNastran.dev.op2_vectorized3.op2_geom import OP2, OP2Geom
from pyNastran.dev.op2_vectorized3.op2_hdf5 import OP2, OP2Geom
from pyNastran.dev.op2_vectorized3.op2_hdf5 import Results
from pyNastran.utils import PathLike
if TYPE_CHECKING: # pragma: no cover
from pyNastran.gui.main_window import MainWindow
Expand Down Expand Up @@ -85,7 +86,7 @@ def _load_op2_results(self, model: OP2, plot: bool) -> None:
self.gui._finish_results_io2(name, form, cases)

def load_h5_results(self, h5_filename: PathLike, plot: bool=True):
model = OP2(debug=True, log=None, mode='msc')
model = Results(debug=True, log=None, mode='msc')
model.read_h5(h5_filename)
self._load_op2_results(model, plot)

Expand Down
14 changes: 7 additions & 7 deletions pyNastran/dev/bdf_vectorized3/test/test_vector_gui_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ def run_nastran_gui(filename: str, load_results: bool=True):


class TestGuiModels(unittest.TestCase):
def _test_h5_freq(self):
def test_h5_freq(self):
h5_filename = MODEL_PATH / 'elements' / 'freq_elements.h5'
run_nastran_gui(h5_filename)

def _test_h5_transient(self):
def test_h5_transient(self):
h5_filename = MODEL_PATH / 'elements' / 'time_elements.h5'
run_nastran_gui(h5_filename)

def _test_h5_transient_thermal(self):
h5_filename = MODEL_PATH / 'elements' / 'time_thermal_elements.h5'
run_nastran_gui(h5_filename)

def _test_h5_static(self):
def test_h5_static(self):
h5_filename = MODEL_PATH / 'sol_101_elements' / 'static_solid_shell_bar.h5'
run_nastran_gui(h5_filename)

def _test_h5_modes(self):
def test_h5_modes(self):
h5_filename = MODEL_PATH / 'elements' / 'modes_elements.h5'
run_nastran_gui(h5_filename)

Expand Down Expand Up @@ -79,13 +79,13 @@ def _test_h5_buckling2(self):
#h5_filename = r'C:\NASA\m4\formats\git\pyNastran\models\msc\test_model_cfast.h5'
#run_nastran_gui(h5_filename)

def _test_beam_modes1(self):
def test_beam_modes1(self):
bdf_filename = MODEL_PATH / 'beam_modes' / 'beam_modes.dat'
run_nastran_gui(bdf_filename)
def _test_beam_modes2(self):
def test_beam_modes2(self):
bdf_filename = MODEL_PATH / 'beam_modes' / 'cbarao_cbeam_static.bdf'
run_nastran_gui(bdf_filename)
def _test_beam_modes3(self):
def test_beam_modes3(self):
bdf_filename = MODEL_PATH / 'beam_modes' / 'cbarao_cbeam_modes.bdf'
run_nastran_gui(bdf_filename)

Expand Down
4 changes: 2 additions & 2 deletions pyNastran/dev/bdf_vectorized3/test/test_vector_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ def test_h5_modes_complex(self):
args2 = ['test_op2', str(h5_filename), '-gctf', '--quiet'] # o
test_op2(args2, show_args=False)

def test_h5_buckling(self):
def _test_h5_buckling(self):
h5_filename = MODEL_PATH / 'sol_101_elements' / 'buckling_solid_shell_bar.h5'
args = ['test_bdf', str(h5_filename), '--skip_nominal', '--quiet']
test_bdf(args, show_args=False)
args2 = ['test_op2', str(h5_filename), '-gctf', '--quiet'] # o
test_op2(args2, show_args=False)

def test_h5_buckling2(self):
def _test_h5_buckling2(self):
h5_filename = MODEL_PATH / 'sol_101_elements' / 'buckling2_solid_shell_bar.h5'
args = ['test_bdf', str(h5_filename), '--skip_nominal', '--quiet']
test_bdf(args, show_args=False)
Expand Down
8 changes: 4 additions & 4 deletions pyNastran/dev/op2_vectorized3/op2_geom.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@ def __init__(self, make_geom: bool=True,
def is_geometry(self) -> bool:
return True

#def read_h5(self, h5_filename: Union[str, PurePath], combine=None):
#"""TODO: should support geometry"""
#from pyNastran2.op2.op2_interface.h5_pytables.h5_results import read_h5_geometry_result
#read_h5_geometry_result(self, h5_filename, root_path='/')
def read_h5(self, h5_filename: Union[str, PurePath], combine=None):
"""TODO: should support geometry"""
from pyNastran.dev.op2_vectorized3.op2_interface.h5_pytables.h5_results import read_h5_geometry_result
read_h5_geometry_result(self, h5_filename, root_path='/')

def read_op2(self, op2_filename: Optional[Union[str, PurePath]]=None, combine: bool=True,
build_dataframe: Optional[bool]=False,
Expand Down
3 changes: 2 additions & 1 deletion pyNastran/dev/op2_vectorized3/op2_hdf5.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from pathlib import PurePath
from typing import Union
from .op2_geom import OP2, OP2Geom
from pyNastran.dev.op2_vectorized3.op2_interface.h5_pytables.h5_results import read_h5_result
from pyNastran.dev.op2_vectorized3.op2_interface.h5_pytables.h5_results import read_h5_geometry_result

class Results(Results):
class Results(OP2):
def read_h5(self, h5_filename: Union[str, PurePath], combine=None):
read_h5_result(self, h5_filename, root_path='/')

Expand Down
Empty file.
Empty file.
Loading

0 comments on commit 7b03f44

Please sign in to comment.