Skip to content

Commit

Permalink
simplifying adding solid elements
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveDoyle2 committed May 19, 2017
1 parent e990a5a commit 912dca7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 119 deletions.
49 changes: 44 additions & 5 deletions pyNastran/bdf/bdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
from pyNastran.bdf.cards.elements.springs import CELAS1, CELAS2, CELAS3, CELAS4
from pyNastran.bdf.cards.properties.springs import PELAS, PELAST

from pyNastran.bdf.cards.elements.solid import (CTETRA, CPYRAM, CPENTA, CHEXA, CIHEX1, CIHEX2)
from pyNastran.bdf.cards.elements.solid import (CIHEX1, CIHEX2,
CTETRA4, CPYRAM5, CPENTA6, CHEXA8,
CTETRA10, CPYRAM13, CPENTA15, CHEXA20)
from pyNastran.bdf.cards.elements.rigid import RBAR, RBAR1, RBE1, RBE2, RBE3, RROD, RSPLINE

from pyNastran.bdf.cards.elements.axisymmetric_shells import (
Expand Down Expand Up @@ -1875,10 +1877,6 @@ def add_card(cls, card, comment=''):
'CSHEAR' : (CSHEAR, self._add_element_object),
'PSHEAR' : (PSHEAR, self._add_property_object),

'CTETRA' : (CTETRA, self._add_element_object),
'CPYRAM' : (CPYRAM, self._add_element_object),
'CPENTA' : (CPENTA, self._add_element_object),
'CHEXA' : (CHEXA, self._add_element_object),
'CIHEX1' : (CIHEX1, self._add_element_object),
'CIHEX2' : (CIHEX2, self._add_element_object),
'PIHEX' : (PIHEX, self._add_property_object),
Expand Down Expand Up @@ -2193,6 +2191,11 @@ def add_card(cls, card, comment=''):
'DELAY' : (DELAY, self._add_delay_object),
}
self._card_parser_prepare = {
'CTETRA' : self._prepare_ctetra,
'CPENTA' : self._prepare_cpenta,
'CHEXA' : self._prepare_chexa,
'CPYRAM' : self._prepare_cpyram,

'CORD1R' : self._prepare_cord1r,
'CORD1C' : self._prepare_cord1c,
'CORD1S' : self._prepare_cord1s,
Expand Down Expand Up @@ -2283,6 +2286,42 @@ def _write_reject_message(self, card_name, card_obj, comment=''):
raise RuntimeError('No executive/case control deck was defined.')
self.log.info(' rejecting card_name = %s' % card_name)

def _prepare_ctetra(self, card, card_obj, comment=''):
"""adds a CTETRA4/CTETRA10"""
if len(card_obj) == 7:
elem = CTETRA4.add_card(card_obj, comment=comment)
else:
elem = CTETRA10.add_card(card_obj, comment=comment)
self._add_element_object(elem)
return elem

def _prepare_cpyram(self, card, card_obj, comment=''):
"""adds a CPYRAM5/CPYRAM13"""
if len(card_obj) == 8:
elem = CPYRAM5.add_card(card_obj, comment=comment)
else:
elem = CPYRAM13.add_card(card_obj, comment=comment)
self._add_element_object(elem)
return elem

def _prepare_cpenta(self, card, card_obj, comment=''):
"""adds a CPENTA6/CPENTA15"""
if len(card_obj) == 9:
elem = CPENTA6.add_card(card_obj, comment=comment)
else:
elem = CPENTA15.add_card(card_obj, comment=comment)
self._add_element_object(elem)
return elem

def _prepare_chexa(self, card, card_obj, comment=''):
"""adds a CHEXA8/CHEXA20"""
if len(card_obj) == 11:
elem = CHEXA8.add_card(card_obj, comment=comment)
else:
elem = CHEXA20.add_card(card_obj, comment=comment)
self._add_element_object(elem)
return elem

def _prepare_bctset(self, card, card_obj, comment=''):
"""adds a GRDSET"""
card = BCTSET.add_card(card_obj, comment=comment, sol=self.sol)
Expand Down
4 changes: 0 additions & 4 deletions pyNastran/bdf/bdf_interface/add_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,6 @@ def add_ctetra(self, eid, pid, nids, comment=''):
nids : List[int]
node ids; n=4 or 10
"""
#elem = CTETRA(eid, pid, nids, comment=comment)
if len(nids) == 4:
elem = CTETRA4(eid, pid, nids, comment=comment)
else:
Expand All @@ -1897,7 +1896,6 @@ def add_cpyram(self, eid, pid, nids, comment=''):
nids : List[int]
node ids; n=5 or 13
"""
#elem = CPYRAM(eid, pid, nids, comment=comment)
if len(nids) == 5:
elem = CPYRAM5(eid, pid, nids, comment=comment)
else:
Expand All @@ -1918,7 +1916,6 @@ def add_cpenta(self, eid, pid, nids, comment=''):
nids : List[int]
node ids; n=6 or 15
"""
#elem = CPENTA(eid, pid, nids, comment=comment)
if len(nids) == 6:
elem = CPENTA6(eid, pid, nids, comment=comment)
else:
Expand All @@ -1939,7 +1936,6 @@ def add_chexa(self, eid, pid, nids, comment=''):
nids : List[int]
node ids; n=8 or 20
"""
#elem = CHEXA(eid, pid, nids, comment=comment)
if len(nids) == 8:
elem = CHEXA8(eid, pid, nids, comment=comment)
else:
Expand Down
110 changes: 2 additions & 108 deletions pyNastran/bdf/cards/elements/solid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* CPENTA15
* CTETRA4
* CTETRA10
* CIHEX1
* CIHEX2
All solid elements are SolidElement and Element objects.
"""
Expand Down Expand Up @@ -178,114 +180,6 @@ def raw_fields(self):
def center_of_mass(self):
return self.Centroid()

class CHEXA(object):
def __init__(self, eid, pid, nids, comment=''):
if len(nids) == 8:
return CHEXA8(eid, pid, nids, comment=comment)
elif len(nids) == 20:
return CHEXA20(eid, pid, nids, comment=comment)
else:
msg = 'len(nids)=%s; expected 8 or 20; nids=%s' % (len(nids), nids)
raise RuntimeError(msg)

@classmethod
def add_card(cls, card, comment):
"""
Adds a CHEXA8/CHEXA20 card from ``BDF.add_card(...)``
Parameters
----------
card : BDFCard()
a BDFCard object
comment : str; default=''
a comment for the card
"""
if card.nfields == 11:
return CHEXA8.add_card(card, comment=comment)
else:
return CHEXA20.add_card(card, comment=comment)

class CTETRA(object):
def __init__(self, eid, pid, nids, comment=''):
if len(nids) == 4:
return CTETRA4(eid, pid, nids, comment=comment)
elif len(nids) == 10:
return CTETRA10(eid, pid, nids, comment=comment)
else:
msg = 'len(nids)=%s; expected 8 or 20; nids=%s' % (len(nids), nids)
raise RuntimeError(msg)

@classmethod
def add_card(cls, card, comment):
"""
Adds a CTETRA4/CTETRA10 card from ``BDF.add_card(...)``
Parameters
----------
card : BDFCard()
a BDFCard object
comment : str; default=''
a comment for the card
"""
if card.nfields == 7:
return CTETRA4.add_card(card, comment=comment)
else:
return CTETRA10.add_card(card, comment=comment)

class CPENTA(object):
def __init__(self, eid, pid, nids, comment=''):
if len(nids) == 6:
return CPENTA6(eid, pid, nids, comment=comment)
elif len(nids) == 15:
return CPENTA15(eid, pid, nids, comment=comment)
else:
msg = 'len(nids)=%s; expected 8 or 20; nids=%s' % (len(nids), nids)
raise RuntimeError(msg)

@classmethod
def add_card(cls, card, comment):
"""
Adds a CPENTA6/CPENTA15 card from ``BDF.add_card(...)``
Parameters
----------
card : BDFCard()
a BDFCard object
comment : str; default=''
a comment for the card
"""
if card.nfields == 9:
return CPENTA6.add_card(card, comment=comment)
else:
return CPENTA15.add_card(card, comment=comment)

class CPYRAM(object):
def __init__(self, eid, pid, nids, comment=''):
if len(nids) == 5:
return CPYRAM5(eid, pid, nids, comment=comment)
elif len(nids) == 13:
return CPYRAM13(eid, pid, nids, comment=comment)
else:
msg = 'len(nids)=%s; expected 8 or 20; nids=%s' % (len(nids), nids)
raise RuntimeError(msg)

@classmethod
def add_card(cls, card, comment):
"""
Adds a CPYRAM5/CPYRAM13 card from ``BDF.add_card(...)``
Parameters
----------
card : BDFCard()
a BDFCard object
comment : str; default=''
a comment for the card
"""
if card.nfields == 8:
return CPYRAM5.add_card(card, comment=comment)
else:
return CPYRAM13.add_card(card, comment=comment)


class CHEXA8(SolidElement):
"""
Expand Down
4 changes: 2 additions & 2 deletions pyNastran/bdf/cards/test/test_solids.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import copy
import unittest

from pyNastran.bdf.bdf import read_bdf, BDF, BDFCard, CPENTA
from pyNastran.bdf.bdf import read_bdf, BDF, BDFCard
from pyNastran.bdf.cards.elements.solid import (
#CTETRA4, CHEXA8, CPENTA6,
#CTETRA10, CHEXA20,
Expand Down Expand Up @@ -34,7 +34,7 @@ def test_cpenta_01(self):
209, 210, 217, None, None, None, 213, 214, 218], node_ids
nids = [201, 202, 203, 205, 206, 207,
209, 210, 217, None, None, None, 213, 214, 218]
CPENTA.add_card(card, comment='spike')
CPENTA15.add_card(card, comment='spike')
eid = 85
pid = 22
bdf.add_cpenta(eid, pid, nids, comment='spike')
Expand Down

0 comments on commit 912dca7

Please sign in to comment.