Skip to content

Commit

Permalink
bdf vectorization:
Browse files Browse the repository at this point in the history
 - adding CMASS1-4, PMASS
 - more tests
 - write_file work
 - added index checking to card slicing
 - geom_check work
 - fixed CPENTA writing bug
  • Loading branch information
SteveDoyle2 committed Sep 11, 2023
1 parent 53ab755 commit ef313d3
Show file tree
Hide file tree
Showing 17 changed files with 2,636 additions and 256 deletions.
22 changes: 11 additions & 11 deletions pyNastran/dev/bdf_vectorized3/bdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from pyNastran.bdf.cards.coordinate_systems import transform_coords_vectorized
from pyNastran.dev.bdf_vectorized3.bdf_interface.h5_pytables.h5_geometry import read_h5_geometry
#from .bdf.cards.elements.bar import BAROR
#from .bdf.cards.elements.beam import BEAMOR
from .cards.elements.beam import BEAMOR

#from pyNastran.bdf.cards.elements.elements import CFAST, CGAP, CRAC2D, CRAC3D, PLOTEL, GENEL
#from pyNastran.bdf.cards.properties.properties import PFAST, PGAP, PRAC2D, PRAC3D
Expand Down Expand Up @@ -117,7 +117,7 @@
#MATT1, MATT2, MATT3, MATT4, MATT5, MATT8, MATT9, MATS1)

from pyNastran.bdf.cards.methods import EIGB, EIGC, EIGR, EIGP, EIGRL, MODTRAK
#from .bdf.cards.grid import GRDSET
from .cards.grid import GRDSET
#from pyNastran.bdf.cards.nodes import GRDSET # GRID, SPOINTs, EPOINTs, POINT, SEQGP, GRIDB
from pyNastran.bdf.cards.aero.aero import (
#AESURF,
Expand Down Expand Up @@ -592,7 +592,7 @@ def __init__(self, debug: Union[str, bool, None]=True,

## masses
'CONM1', 'CONM2',
#'CMASS1', 'CMASS2', 'CMASS3', 'CMASS4',
'CMASS1', 'CMASS2', 'CMASS3', 'CMASS4',

## nsms
#'NSM', 'NSM1', 'NSML', 'NSML1',
Expand Down Expand Up @@ -638,7 +638,7 @@ def __init__(self, debug: Union[str, bool, None]=True,
#'PLOTEL',

## properties
#'PMASS',
'PMASS',
'PELAS', # 'PGAP', 'PFAST',
'PLPLANE', 'PPLANE',
#'PBUSH', 'PBUSH1D',
Expand Down Expand Up @@ -2433,11 +2433,11 @@ def add_card(cls, card, comment=''):
#'GENEL' : partial(self._prepare_card, self.genel),

# mass
#'PMASS' : partial(self._prepare_card, self.pmass),
#'CMASS1' : partial(self._prepare_card, self.cmass1),
#'CMASS2' : partial(self._prepare_card, self.cmass2),
#'CMASS3' : partial(self._prepare_card, self.cmass3),
#'CMASS4' : partial(self._prepare_card, self.cmass4),
'PMASS' : partial(self._prepare_card, self.pmass),
'CMASS1' : partial(self._prepare_card, self.cmass1),
'CMASS2' : partial(self._prepare_card, self.cmass2),
'CMASS3' : partial(self._prepare_card, self.cmass3),
'CMASS4' : partial(self._prepare_card, self.cmass4),
'CONM1' : partial(self._prepare_card, self.conm1),
'CONM2' : partial(self._prepare_card, self.conm2),

Expand Down Expand Up @@ -2740,7 +2740,7 @@ def add_card(cls, card, comment=''):
# GRDSET-will be last card to update from _card_parser_prepare
'GRDSET' : self._prepare_grdset,
#'BAROR' : self._prepare_baror,
#'BEAMOR' : self._prepare_beamor,
'BEAMOR' : self._prepare_beamor,
#'BDYOR': self._prepare_bdyor,

#'BCTSET' : self._prepare_bctset,
Expand Down Expand Up @@ -3382,7 +3382,7 @@ def _add_card_helper(self, card_obj: BDFCard, card: list[str],
#self.log.error(str(card_obj))
#raise
else:
print(card_obj)
self.log.warning(f'rejecting {card_obj}')
#raise RuntimeError(card_obj)
self.reject_cards.append(card_obj)

Expand Down
20 changes: 10 additions & 10 deletions pyNastran/dev/bdf_vectorized3/bdf_interface/bdf_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#CHACAB, CHACBR,
)
from pyNastran.dev.bdf_vectorized3.cards.elements.mass import CONM1, CONM2
#from pyNastran.dev.bdf_vectorized3.cards.elements.cmass import PMASS, CMASS1, CMASS2, CMASS3, CMASS4
from pyNastran.dev.bdf_vectorized3.cards.elements.cmass import PMASS, CMASS1, CMASS2, CMASS3, CMASS4
#from pyNastran.dev.bdf_vectorized3.cards.elements.nsm import NSMADD, NSM, NSM1, NSML, NSML1
#from pyNastran.dev.bdf_vectorized3.cards.elements.thermal import CHBDYE, CHBDYP, CHBDYG, CONV, PCONV, CONVM, PCONVM, PHBDY
#from pyNastran.dev.bdf_vectorized3.cards.elements.plot import PLOTEL
Expand Down Expand Up @@ -329,11 +329,11 @@ def __init__(self):
#self.solid_properties = []

# mass
#self.pmass = PMASS(self)
#self.cmass1 = CMASS1(self)
#self.cmass2 = CMASS2(self)
#self.cmass3 = CMASS3(self)
#self.cmass4 = CMASS4(self)
self.pmass = PMASS(self)
self.cmass1 = CMASS1(self)
self.cmass2 = CMASS2(self)
self.cmass3 = CMASS3(self)
self.cmass4 = CMASS4(self)
self.conm1 = CONM1(self)
self.conm2 = CONM2(self)

Expand Down Expand Up @@ -620,7 +620,7 @@ def elements(self) -> list[Any]:
#self.genel,
] + self.shell_elements + self.solid_elements + axisymmetric_elements + [
self.conm1, self.conm2,
#self.cmass1, self.cmass2, self.cmass3, #self.cmass4,
self.cmass1, self.cmass2, self.cmass3, self.cmass4,
#self.cplsts3, self.cplsts4, self.cplsts6, self.cplsts8,
#self.cplstn3, self.cplstn4, self.cplstn6, self.cplstn8,
] + acoustic_elements
Expand Down Expand Up @@ -668,7 +668,7 @@ def properties(self) -> list[Any]:
] + self.bar_properties + self.beam_properties + [
self.pshear,
] + self.shell_properties + self.solid_properties + [
#self.pmass,
self.pmass,
]
return properties

Expand Down Expand Up @@ -1378,8 +1378,8 @@ def inertia(self) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
#return element_id, abs_mass, cg, inertia
mass_cg = mass[:, None] * centroid
imass = (mass != 0)
cg = np.zeros(centroid.shape, dtype=centroid.dtype)
cg[imass] = mass_cg[imass, :] / mass
cg = np.full(centroid.shape, np.nan, dtype=centroid.dtype)
cg[imass] = mass_cg[imass, :] / mass[imass, np.newaxis]

#cg = mass_cg.sum(axis=0) / mass.sum()
#assert len(cg) == 3, cg
Expand Down
98 changes: 49 additions & 49 deletions pyNastran/dev/bdf_vectorized3/bdf_interface/write_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def _write_nodes(self, bdf_file: TextIOLike,
model = self.model
if model.spoint.n:
bdf_file.write('$SPOINTS\n')
bdf_file.write(model.spoint.write(size=size))
model.spoint.write_file(bdf_file, size=size, is_double=is_double)
#if model.epoint.n:
#bdf_file.write('$EPOINTS\n')
#bdf_file.write(model.epoint.write(size=size))
Expand Down Expand Up @@ -380,10 +380,10 @@ def _write_elements(self, bdf_file: TextIOLike,
#bdf_file.write(model.plotel.write(size=size))

# celas
model.celas1.write_file(bdf_file, size=size)
model.celas2.write_file(bdf_file, size=size)
model.celas3.write_file(bdf_file, size=size)
model.celas4.write_file(bdf_file, size=size)
model.celas1.write_file(bdf_file, size=size, is_double=is_double)
model.celas2.write_file(bdf_file, size=size, is_double=is_double)
model.celas3.write_file(bdf_file, size=size, is_double=is_double)
model.celas4.write_file(bdf_file, size=size, is_double=is_double)

# cdamp
#bdf_file.write(model.cdamp1.write(size=size))
Expand All @@ -404,26 +404,26 @@ def _write_elements(self, bdf_file: TextIOLike,
#bdf_file.write(model.cfast.write(size=size))

# rod
bdf_file.write(model.crod.write(size=size))
bdf_file.write(model.conrod.write(size=size))
bdf_file.write(model.ctube.write(size=size))
model.crod.write_file(bdf_file, size=size, is_double=is_double)
model.conrod.write_file(bdf_file, size=size, is_double=is_double)
model.ctube.write_file(bdf_file, size=size, is_double=is_double)

# bar/beam/shear
bdf_file.write(model.cbar.write(size=size))
bdf_file.write(model.cbarao.write(size=size))
bdf_file.write(model.cbeam.write(size=size))
model.cshear.write_file(bdf_file, size=size)
model.cbar.write_file(bdf_file, size=size, is_double=is_double)
model.cbarao.write_file(bdf_file, size=size, is_double=is_double)
model.cbeam.write_file(bdf_file, size=size, is_double=is_double)
model.cshear.write_file(bdf_file, size=size, is_double=is_double)

# shells
#all_shells = (mo
model.ctria3.write_file(bdf_file, size=size)
model.cquad4.write_file(bdf_file, size=size)
model.ctria6.write_file(bdf_file, size=size)
model.cquad8.write_file(bdf_file, size=size)
model.ctriar.write_file(bdf_file, size=size)
model.cquadr.write_file(bdf_file, size=size)
model.cquad.write_file(bdf_file, size=size)
#bdf_file.write(model.snorm.write(size=size))
model.ctria3.write_file(bdf_file, size=size, is_double=is_double)
model.cquad4.write_file(bdf_file, size=size, is_double=is_double)
model.ctria6.write_file(bdf_file, size=size, is_double=is_double)
model.cquad8.write_file(bdf_file, size=size, is_double=is_double)
model.ctriar.write_file(bdf_file, size=size, is_double=is_double)
model.cquadr.write_file(bdf_file, size=size, is_double=is_double)
model.cquad.write_file(bdf_file, size=size, is_double=is_double)
#bdf_file.write(model.snorm.write(size=size), is_double=is_double)

# axisymmetric shells
#bdf_file.write(model.ctriax.write(size=size))
Expand All @@ -447,10 +447,10 @@ def _write_elements(self, bdf_file: TextIOLike,
#bdf_file.write(model.cplstn8.write(size=size))

# solids
model.ctetra.write_file(bdf_file, size=size)
model.cpenta.write_file(bdf_file, size=size)
model.chexa.write_file(bdf_file, size=size)
model.cpyram.write_file(bdf_file, size=size)
model.ctetra.write_file(bdf_file, size=size, is_double=is_double)
model.cpenta.write_file(bdf_file, size=size, is_double=is_double)
model.chexa.write_file(bdf_file, size=size, is_double=is_double)
model.cpyram.write_file(bdf_file, size=size, is_double=is_double)

# acoustic solids
#bdf_file.write(model.chacab.write(size=size))
Expand Down Expand Up @@ -539,8 +539,8 @@ def _write_masses(self, bdf_file: TextIOLike,
model = self.model
all_masses = (
model.conm1, model.conm2,
#model.pmass,
#model.cmass1, model.cmass2, model.cmass3, model.cmass4,
model.pmass,
model.cmass1, model.cmass2, model.cmass3, model.cmass4,
)
masses = [mass for mass in all_masses if mass.n > 0]
if len(masses) == 0:
Expand Down Expand Up @@ -585,26 +585,26 @@ def _write_properties(self, bdf_file: TextIOLike,
#bdf_file.write(model.pfast.write(size=size))

# rod
bdf_file.write(model.prod.write(size=size))
bdf_file.write(model.ptube.write(size=size))
model.prod.write_file(bdf_file, size=size, is_double=is_double)
model.ptube.write_file(bdf_file, size=size, is_double=is_double)

# bar
bdf_file.write(model.pbar.write(size=size))
bdf_file.write(model.pbarl.write(size=size))
bdf_file.write(model.pbrsect.write(size=size))
model.pbar.write_file(bdf_file, size=size, is_double=is_double)
model.pbarl.write_file(bdf_file, size=size, is_double=is_double)
model.pbrsect.write_file(bdf_file, size=size, is_double=is_double)

# beam
bdf_file.write(model.pbeam.write(size=size))
bdf_file.write(model.pbeaml.write(size=size))
bdf_file.write(model.pbcomp.write(size=size))
model.pbeam.write_file(bdf_file, size=size, is_double=is_double)
model.pbeaml.write_file(bdf_file, size=size, is_double=is_double)
model.pbcomp.write_file(bdf_file, size=size, is_double=is_double)

# shear
bdf_file.write(model.pshear.write(size=size))
model.pshear.write_file(bdf_file, size=size, is_double=is_double)

# shell
model.pshell.write_file(bdf_file, size=size)
model.pcomp.write_file(bdf_file, size=size)
model.pcompg.write_file(bdf_file, size=size)
model.pshell.write_file(bdf_file, size=size, is_double=is_double)
model.pcomp.write_file(bdf_file, size=size, is_double=is_double)
model.pcompg.write_file(bdf_file, size=size, is_double=is_double)

# planar shells
model.plplane.write_file(bdf_file, size=size)
Expand Down Expand Up @@ -880,17 +880,17 @@ def _write_loads(self, bdf_file: TextIOLike,
#bdf_file.write(model.accel.write(size=size))
#bdf_file.write(model.accel1.write(size=size))

bdf_file.write(model.force.write(size=size))
bdf_file.write(model.force1.write(size=size))
bdf_file.write(model.force2.write(size=size))
bdf_file.write(model.moment.write(size=size))
bdf_file.write(model.moment1.write(size=size))
bdf_file.write(model.moment2.write(size=size))
bdf_file.write(model.pload.write(size=size))
bdf_file.write(model.pload1.write(size=size))
bdf_file.write(model.pload2.write(size=size))
bdf_file.write(model.pload4.write(size=size))
model.sload.write_file(bdf_file, size=size)
model.force.write_file(bdf_file, size=size, is_double=is_double)
model.force1.write_file(bdf_file, size=size, is_double=is_double)
model.force2.write_file(bdf_file, size=size, is_double=is_double)
model.moment.write_file(bdf_file, size=size, is_double=is_double)
model.moment1.write_file(bdf_file, size=size, is_double=is_double)
model.moment2.write_file(bdf_file, size=size, is_double=is_double)
model.pload.write_file(bdf_file, size=size, is_double=is_double)
model.pload1.write_file(bdf_file, size=size, is_double=is_double)
model.pload2.write_file(bdf_file, size=size, is_double=is_double)
model.pload4.write_file(bdf_file, size=size, is_double=is_double)
model.sload.write_file(bdf_file, size=size, is_double=is_double)
#bdf_file.write(model.tempd.write(size=size)) # default temp
#bdf_file.write(model.temp.write(size=size))
#bdf_file.write(model.spcd.write(size=size))
Expand Down
7 changes: 7 additions & 0 deletions pyNastran/dev/bdf_vectorized3/cards/base_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ def slice_card_by_index(self, i: np.ndarray,

def index(self, ids: np.ndarray,
assume_sorted: bool=True,
check_index: bool=True,
inverse: bool=False) -> np.ndarray:
"""
Parameters
Expand All @@ -261,6 +262,8 @@ def index(self, ids: np.ndarray,
the node/element/property/material/etc. ids
assume_sorted: bool; default=True
assume the parent array (e.g., elem.element_id is sorted)
check_index: bool; default=True
validate the lookup
inverse: bool; default=False
False: get the indices for the ids
True: get the inverse indices for the ids
Expand Down Expand Up @@ -289,6 +292,10 @@ def index(self, ids: np.ndarray,
return None # np.arange(len(ids), dtype='int32')
ids = np.atleast_1d(np.asarray(ids, dtype=self_ids.dtype))
ielem = np.searchsorted(self_ids, ids)
if check_index:
actual_ids = self_ids[ielem]
if not np.array_equal(actual_ids, ids):
raise KeyError(f'{self.type}: expected_{self._id_name}={ids}; actual_{self._id_name}={actual_ids}')
if inverse:
i = np.arange(len(self_ids), dtype=self_ids.dtype)
index = np.setdiff1d(i, ielem)
Expand Down
Loading

0 comments on commit ef313d3

Please sign in to comment.