Skip to content

Commit

Permalink
fixing tests; renaming MATCID from thru to end
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveDoyle2 committed Nov 18, 2024
1 parent b058269 commit 4c0fb85
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 35 deletions.
36 changes: 18 additions & 18 deletions pyNastran/bdf/cards/coordinate_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ class MATCID(BaseCard):
def __init__(self, cid: int,
eids=None,
start: Optional[int]=None,
thru: Optional[int]=None,
end: Optional[int]=None,
by: Optional[int]=1,
comment: str=''):
"""
Expand All @@ -1326,7 +1326,7 @@ def __init__(self, cid: int,
Array of element identification numbers
start: int
used in format alternative 2 and 3, indicates starting eID
thru : int
end : int
used in format alternative 2 and 3
by : int; default=1
used in format alternative 3
Expand Down Expand Up @@ -1367,18 +1367,18 @@ def __init__(self, cid: int,
self.comment = comment
self.cid = cid
if eids is not None:
assert eids is not None, f'eids={eids}, start={start}, thru={thru}, by={by}'
assert start is None and thru is None and (by is None or by == 1), f'eids={eids}, start={start}, thru={thru}, by={by}'
assert eids is not None, f'eids={eids}, start={start}, end={end}, by={by}'
assert start is None and end is None and (by is None or by == 1), f'eids={eids}, start={start}, end={end}, by={by}'
else:
assert eids is None, f'cid={cid}, eids={eids}'
assert isinstance(start, int) and isinstance(thru, int) and isinstance(by, int), f'cid={cid}, start={start} thru={thru} by={by}'
assert isinstance(start, int) and isinstance(end, int) and isinstance(by, int), f'cid={cid}, start={start} end={end} by={by}'
self.start = start
self.thru = thru
self.end = end
self.by = by
self.eids = eids

@classmethod
def add_card(cls, card, comment=''):
def add_card(cls, card: BDFCard, comment: str=''):
"""
Material Coordinate System for Solid Elements
Expand Down Expand Up @@ -1430,23 +1430,23 @@ def add_card(cls, card, comment=''):
if field2 == 'ALL':
eids = None
start = 1
thru = -1
return cls(cid, eids, start, thru, by, comment=comment)
end = -1
return cls(cid, eids, start, end, by, comment=comment)

assert field2 > 0, f'{field2}'
n_fields = len(card)
field3 = integer_or_string(card, 3, 'pos3')
if isinstance(field3, str): # THRU
thru_eid2 = integer_or_string(card, 3, 'THRU/eid2')
if isinstance(thru_eid2, str): # THRU
eids = None
assert field3 == 'THRU', f'{field3}'
assert thru_eid2 == 'THRU', f'{thru_eid2}'
start = integer(card, 2, 'start')
thru = integer(card, 4, 'thru')
assert thru > start, f'start={start}, thru={thru}'
end = integer(card, 4, 'end')
assert end > start, f'start={start}, end={end}'

if n_fields > 5: # BY
by = integer_or_blank(card, 6, 'by', default=1)
assert by > 0, f'{by}'
return cls(cid, eids, start, thru, by, comment=comment)
return cls(cid, eids, start, end, by, comment=comment)
else: # Multiple eIDs referenced without using THRU / BY
eids = np.empty([n_fields - 2], dtype=int)
for i in range(2, n_fields):
Expand Down Expand Up @@ -1478,11 +1478,11 @@ def raw_fields(self):
assert self.cid is not None, self.cid
if self.eids is not None:
list_fields = ['MATCID', self.cid] + list(self.eids)
elif self.start == 1 and self.thru == -1 and self.by == 1:
elif self.start == 1 and self.end == -1 and self.by == 1:
list_fields = ['MATCID', self.cid, 'ALL']
else:
assert self.start is not None and self.start > 0, (self.start, self.thru, self.by)
list_fields = ['MATCID', self.cid, self.start, 'THRU', self.thru]
assert self.start is not None and self.start > 0, (self.start, self.end, self.by)
list_fields = ['MATCID', self.cid, self.start, 'THRU', self.end]
if self.by != 1:
list_fields.extend(['BY', self.by])
return list_fields
Expand Down
32 changes: 15 additions & 17 deletions pyNastran/bdf/cards/test/test_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,11 +1108,12 @@ def test_matcid(self):
1.135, 0.089237, 0.9324],

# MATCID Variants
# cids = [7, 8, 9, 10]
['MATCID', cids[0], 7, 8, 9, 10, 11, 12, 13, 14], # Manual
['MATCID', cids[1], 7, 'THRU', 14], # Using 'THRU'
['MATCID', cids[2], 7, 'THRU', 14, 'BY', 1], # Using 'BY'
['MATCID', cids[3], 'ALL'], # Using 'ALL'
]
]

model = BDF(debug=False)
for fields in cards:
Expand All @@ -1132,38 +1133,35 @@ def test_matcid(self):
matcid = matcids[0]
self.assertEqual(matcid.Cid(), cid)

self.assertIn(matcid.form, [1, 2, 3, 4])

if matcid.form == 1:
if matcid.cid == 7:
self.assertEqual(matcid.Cid(), 7)
self.assertTrue((matcid.eids == np.array([7, 8, 9, 10, 11, 12, 13, 14], dtype=int)).all())
self.assertIsNone(matcid.start)
self.assertIsNone(matcid.thru)
self.assertIsNone(matcid.by)
self.assertIsNone(matcid.end)
self.assertEqual(matcid.by, 1)

elif matcid.form == 2:
elif matcid.cid == 8:
self.assertEqual(matcid.Cid(), 8)
self.assertEqual(matcid.start, 7)
self.assertEqual(matcid.thru, 14)
self.assertEqual(matcid.end, 14)

self.assertIsNone(matcid.eids)
self.assertIsNone(matcid.by)
self.assertEqual(matcid.by, 1)
# self.assertIsNone(matcid.by)

elif matcid.form == 3:
elif matcid.cid == 9:
self.assertEqual(matcid.Cid(), 9)
self.assertEqual(matcid.start, 7)
self.assertEqual(matcid.thru, 14)
self.assertEqual(matcid.end, 14)
self.assertEqual(matcid.by, 1)

self.assertIsNone(matcid.eids)

else: # matcid == 4
else: # cid == 10
self.assertEqual(matcid.Cid(), 10)

self.assertIsNone(matcid.eids)
self.assertIsNone(matcid.start)
self.assertIsNone(matcid.thru)
self.assertIsNone(matcid.by)
self.assertEqual(matcid.start, 1)
self.assertEqual(matcid.end, -1)
self.assertEqual(matcid.by, 1)

def make_tri(model):
model.add_grid(1, [0., 0., 0.])
Expand Down

0 comments on commit 4c0fb85

Please sign in to comment.