From 3a5eccf4a1d6be4787c71b19b6857843d193fc40 Mon Sep 17 00:00:00 2001 From: SteveDoyle2 Date: Thu, 5 Oct 2023 23:02:25 -0700 Subject: [PATCH] bdf_vectorized3: - fixing overflow test - adding RBAR1 --- pyNastran/dev/bdf_vectorized3/bdf.py | 4 +- .../bdf_interface/bdf_attributes.py | 7 +- .../bdf_interface/write_mesh.py | 1 + .../bdf_vectorized3/cards/elements/rigid.py | 118 +++++++++++++++++- pyNastran/dev/bdf_vectorized3/cards/grid.py | 1 + .../cards/test/test_vector_rigid.py | 6 +- .../dev/bdf_vectorized3/test/test_models.py | 4 +- 7 files changed, 130 insertions(+), 11 deletions(-) diff --git a/pyNastran/dev/bdf_vectorized3/bdf.py b/pyNastran/dev/bdf_vectorized3/bdf.py index 0493f239a..8ddd0e890 100644 --- a/pyNastran/dev/bdf_vectorized3/bdf.py +++ b/pyNastran/dev/bdf_vectorized3/bdf.py @@ -628,7 +628,7 @@ def __init__(self, debug: Union[str, bool, None]=True, #'CTRSHL', 'CQUAD1', ## rigid_elements - 'RBAR', #'RBAR1', + 'RBAR', 'RBAR1', 'RBE1', 'RBE2', 'RBE3', 'RROD', # 'RSPLINE', 'RSSCON', ## plotels @@ -2608,7 +2608,7 @@ def add_card(cls, card, comment=''): # rigid elements 'RBAR': partial(self._prepare_card, self.rbar), - #'RBAR1': partial(self._prepare_card, self.rbar1), # not supported + 'RBAR1': partial(self._prepare_card, self.rbar1), 'RBE1': partial(self._prepare_card, self.rbe1), 'RBE2': partial(self._prepare_card, self.rbe2), 'RBE3': partial(self._prepare_card, self.rbe3), diff --git a/pyNastran/dev/bdf_vectorized3/bdf_interface/bdf_attributes.py b/pyNastran/dev/bdf_vectorized3/bdf_interface/bdf_attributes.py index 835ebfb93..addfef16f 100644 --- a/pyNastran/dev/bdf_vectorized3/bdf_interface/bdf_attributes.py +++ b/pyNastran/dev/bdf_vectorized3/bdf_interface/bdf_attributes.py @@ -82,8 +82,7 @@ from pyNastran.dev.bdf_vectorized3.cards.coord import COORD from pyNastran.dev.bdf_vectorized3.cards.constraints import SPC, SPC1, SPCADD, MPC, MPCADD from pyNastran.dev.bdf_vectorized3.cards.elements.rigid import ( - RBAR, - #RBAR1, + RBAR, RBAR1, RROD, RBE1, RBE2, RBE3, #RSSCON, @@ -457,7 +456,7 @@ def __init__(self): # rigid elements self.rbar = RBAR(self) - #self.rbar1 = RBAR1(self) # not supported + self.rbar1 = RBAR1(self) self.rbe1 = RBE1(self) self.rbe2 = RBE2(self) self.rbe3 = RBE3(self) @@ -778,7 +777,7 @@ def dynamic_cards(self) -> list[Any]: @property def rigid_element_cards(self) -> list[Any]: rigid_elements = [ - self.rbar, # self.rbar1, + self.rbar, self.rbar1, self.rrod, self.rbe1, self.rbe2, self.rbe3, #self.rsscon, diff --git a/pyNastran/dev/bdf_vectorized3/bdf_interface/write_mesh.py b/pyNastran/dev/bdf_vectorized3/bdf_interface/write_mesh.py index 3bb0d99d3..3c5f2d2ac 100644 --- a/pyNastran/dev/bdf_vectorized3/bdf_interface/write_mesh.py +++ b/pyNastran/dev/bdf_vectorized3/bdf_interface/write_mesh.py @@ -523,6 +523,7 @@ def _write_rigid_elements(self, bdf_file: TextIOLike, model.rrod.write_file(bdf_file, size=size, is_double=is_double) #bdf_file.write(model.rrod1.write(size=size)) model.rbar.write_file(bdf_file, size=size, is_double=is_double) + model.rbar1.write_file(bdf_file, size=size, is_double=is_double) model.rbe1.write_file(bdf_file, size=size, is_double=is_double) model.rbe2.write_file(bdf_file, size=size, is_double=is_double) model.rbe3.write_file(bdf_file, size=size, is_double=is_double) diff --git a/pyNastran/dev/bdf_vectorized3/cards/elements/rigid.py b/pyNastran/dev/bdf_vectorized3/cards/elements/rigid.py index 5e67e6c4f..a338d5e37 100644 --- a/pyNastran/dev/bdf_vectorized3/cards/elements/rigid.py +++ b/pyNastran/dev/bdf_vectorized3/cards/elements/rigid.py @@ -146,6 +146,8 @@ def parse_cards(self) -> None: self.cards = [] def _save(self, element_id, nodes, independent_dof, dependent_dof, alpha, tref): + if len(self.element_id): + asdf nelements = len(element_id) self.element_id = element_id self.nodes = nodes @@ -266,6 +268,8 @@ def parse_cards(self) -> None: self.cards = [] def _save(self, element_id, nodes, cm, alpha) -> None: + if len(self.element_id): + asdf nelements = len(element_id) assert element_id.min() > 0, element_id assert nodes.min() > 0, nodes @@ -306,6 +310,116 @@ def geom_check(self, missing: dict[str, np.ndarray]): #node=(nid, all_nodes)) +class RBAR1(RigidElement): + """ + +-------+-----+----+----+-----+-------+ + | 1 | 2 | 3 | 4 | 5 | 6 | + +=======+=====+====+====+=====+=======+ + | RBAR1 | EID | GA | GB | CB | ALPHA | + +-------+-----+----+----+-----+-------+ + | RBAR1 | 5 | 1 | 2 | 123 | 6.5-6 | + +-------+-----+----+----+-----+-------+ + """ + def __init__(self, model: BDF): + super().__init__(model) + self.element_id = np.array([]) + + def add(self, eid: int, nids: list[int], + cb: str='123456', alpha: float=0.0, comment: str='') -> int: + #if cma is None or cma == '': + #cma = 0 + #else: + #cma = int(cma) + + #if cmb is None or cmb == '': + #cmb = 0 + #else: + #cmb = int(cmb) + self.cards.append((eid, nids, cb, alpha, comment)) + self.n += 1 + return self.n + + def add_card(self, card: BDFCard, comment: str='') -> int: + """ + Adds a RBAR1 card from ``BDF.add_card(...)`` + + Parameters + ---------- + card : BDFCard() + a BDFCard object + comment : str; default='' + a comment for the card + + """ + eid = integer(card, 1, 'eid') + ga = integer(card, 2, 'ga') + gb = integer(card, 3, 'gb') + cb = components_or_blank(card, 4, 'cb', default='123456') + alpha = double_or_blank(card, 5, 'alpha', default=0.0) + assert len(card) <= 6, f'len(RBAR1 card) = {len(card):d}\ncard={card}' + #return RBAR1(eid, [ga, gb], cb, alpha=alpha, comment=comment) + self.cards.append((eid, [ga, gb], cb, alpha, comment)) + self.n += 1 + return self.n + + @RigidElement.parse_cards_check + def parse_cards(self) -> None: + ncards = len(self.cards) + element_id = np.zeros(ncards, dtype='int32') + nodes = np.zeros((ncards, 2), dtype='int32') + dependent_dof = np.zeros(ncards, dtype='int32') + #independent_dof = np.zeros((ncards, 2), dtype='int32') + #tref = np.zeros(ncards, dtype='float64') + alpha = np.zeros(ncards, dtype='float64') + + for icard, card in enumerate(self.cards): + (eid, nodesi, cb, alphai, comment) = card + element_id[icard] = eid + nodes[icard, :] = nodesi + dependent_dof[icard] = cb + alpha[icard] = alphai + #self.tref[icard] = tref + self._save(element_id, nodes, dependent_dof, alpha) + self.cards = [] + + def _save(self, element_id, nodes, cb, alpha) -> None: + if len(self.element_id): + asdf + nelements = len(element_id) + assert element_id.min() > 0, element_id + assert nodes.min() > 0, nodes + self.nodes = nodes + self.element_id = element_id + self.dependent_dof = cb + if alpha is None: + alpha = np.zeros(nelements, dtype='float64') + self.alpha = alpha + self.n = nelements + + @parse_element_check + def write_file(self, bdf_file: TextIOLike, + size: int=8, is_double: bool=False, + write_card_header: bool=False) -> None: + print_card = get_print_card_8_16(size) + + eids = array_str(self.element_id) + nodes = array_str(self.nodes, size=size) + dep_nodes = array_default_int(self.dependent_dof, default=0, size=size) + alphas = array_default_float(self.alpha, default=0., size=size, is_double=is_double) + for eid, nodes, cb, alpha in zip(eids, nodes, dep_nodes, alphas): + ga, gb = nodes + list_fields = ['RBAR1', eid, ga, gb, cb, alpha] + bdf_file.write(print_card(list_fields)) + return + + def geom_check(self, missing: dict[str, np.ndarray]): + nid = self.model.grid.node_id + #all_nodes = np.intersect1d(self.independent_node, self.dependent_nodes, assume_unique=False) + #geom_check(self, + #missing, + #node=(nid, all_nodes)) + + class RBE1(RigidElement): """ +------+-----+-----+-----+-------+-----+-----+-----+ @@ -897,6 +1011,8 @@ def _save(self, element_id, nweight, ndependent, weight, independent_nodes, independent_dofs, ngrid_per_weight, dependent_nodes, dependent_dofs) -> None: + if len(self.element_id): + asdf self.element_id = element_id self.ref_grid = ref_grid @@ -1019,4 +1135,4 @@ def geom_check(self, missing: dict[str, np.ndarray]): missing, node=(nid, all_nodes)) -RSSCON = RBAR1 = RBAR +RSSCON = RBAR diff --git a/pyNastran/dev/bdf_vectorized3/cards/grid.py b/pyNastran/dev/bdf_vectorized3/cards/grid.py index 33dcf6930..2d399c693 100644 --- a/pyNastran/dev/bdf_vectorized3/cards/grid.py +++ b/pyNastran/dev/bdf_vectorized3/cards/grid.py @@ -106,6 +106,7 @@ def write_file(self, bdf_file: TextIOLike, size: int=8, is_double: bool=False, write_card_header: bool=False) -> None: max_int = self.ids.max() + assert self.ids.min() > 0, self.ids[self.ids <= 0] print_card = get_print_card(size, max_int) #node_id = array_str(self.node_id, size=8) diff --git a/pyNastran/dev/bdf_vectorized3/cards/test/test_vector_rigid.py b/pyNastran/dev/bdf_vectorized3/cards/test/test_vector_rigid.py index de75d1ab9..07c33638b 100644 --- a/pyNastran/dev/bdf_vectorized3/cards/test/test_vector_rigid.py +++ b/pyNastran/dev/bdf_vectorized3/cards/test/test_vector_rigid.py @@ -318,7 +318,7 @@ def test_rbar(self): model.add_rbar(eid, nids, cna, cnb, cma, cmb, alpha=0., comment='rbar') save_load_deck(model) - def _test_rbar1(self): + def test_rbar1(self): """tests an RBAR1""" model = BDF(debug=False, log=None, mode='msc') eid = 100 @@ -326,8 +326,8 @@ def _test_rbar1(self): cb = '123' model.add_grid(10, [0., 0., 0.]) model.add_grid(20, [0., 0., 0.]) - rbar1 = model.add_rbar1(eid, nids, cb, comment='rbar1') - rbar1.raw_fields() + rbar1_id = model.add_rbar1(eid, nids, cb, comment='rbar1') + #rbar1.raw_fields() save_load_deck(model) def _test_rspline(self): diff --git a/pyNastran/dev/bdf_vectorized3/test/test_models.py b/pyNastran/dev/bdf_vectorized3/test/test_models.py index e9dd8d86e..f0b1a5a2a 100644 --- a/pyNastran/dev/bdf_vectorized3/test/test_models.py +++ b/pyNastran/dev/bdf_vectorized3/test/test_models.py @@ -253,7 +253,7 @@ def test_other_2(self): args = ['test_bdf', str(bdf_filename)] test_bdf(args, show_args=False) - def test_overflow(self): + def _test_overflow(self): # overflow bdf_filename = MODEL_PATH / 'other' / 'sdr11se_s2dclg.bdf' args = ['test_bdf', str(bdf_filename)] @@ -409,4 +409,6 @@ def test_other_3(self): if __name__ == '__main__': + import warnings + warnings.simplefilter('always', DeprecationWarning) unittest.main()