本文整理汇总了Python中pyNastran.bdf.bdf.BDF.add_card方法的典型用法代码示例。如果您正苦于以下问题:Python BDF.add_card方法的具体用法?Python BDF.add_card怎么用?Python BDF.add_card使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyNastran.bdf.bdf.BDF
的用法示例。
在下文中一共展示了BDF.add_card方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getNodes
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import add_card [as 别名]
def getNodes(self, grids, grids_expected, coords):
model = BDF(debug=False)
for grid in grids:
(nid, cid, x, y, z) = grid
model.add_card(['GRID', nid, cid, x, y, z], 'GRID')
for coord in coords:
(cid, rid, x, y, z) = coord
model.add_card(['CORD2R', cid, rid] + x + y + z, 'CORD2R')
coordObj = model.Coord(cid)
model.cross_reference()
for (i, grid) in enumerate(grids_expected):
(nid, cid, x, y, z) = grid
node = model.Node(nid)
pos = node.Position()
n = array([x, y, z])
msg = 'i=%s expected=%s actual=%s\n' % (i, n, pos)
msg += 'n=%s grid=\n%s' % (nid, node)
coord = node.cp
msg += 'n=%s coord=\n%s' % (node.nid, coord)
while coord.rid:
msg += 'n=%s rcoord=\n%s' % (node.nid, coord.rid)
coord = coord.rid
assert allclose(n, pos), msg
示例2: test_aelist_1
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import add_card [as 别名]
def test_aelist_1(self):
"""checks the AELIST card"""
log = SimpleLogger(level='warning')
model = BDF(log=log)
data = ['AELIST', 75, 1001, 'THRU', 1075, 1101, 'THRU', 1109, 1201, 1202]
model.add_card(data, data[0], comment_bad, is_list=True)
elements = list(range(1001, 1076)) + list(range(1101, 1110)) + [1201, 1202]
aelist = AELIST(74, elements)
aelist.validate()
aelist.write_card()
aelist75 = model.aelists[75]
#print(aelist.elements)
#print(elements)
self.assertTrue(elements == aelist75.elements)
elements = list(range(1001, 1076)) + list(range(1101, 1110)) + [1108, 1202]
data = ['AELIST', 76, 1001, 'THRU', 1075, 1101, 'THRU', 1109, 1108, 1202]
model.add_card(data, data[0], comment_bad, is_list=True)
aelist76 = model.aelists[76]
#print(aelist76 .elements)
#print(elements)
self.assertFalse(elements == aelist76.elements)
elements = list(set(elements))
elements.sort()
self.assertTrue(elements == aelist76.elements)
elements = [1000, 1000, 1000, 2000, 1000, 2000]
aelist = AELIST(75, elements)
aelist.clean_ids()
str(aelist.write_card())
示例3: test_pbeam_11
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import add_card [as 别名]
def test_pbeam_11(self):
model = BDF()
lines = [
#'PBEAM 1 1 1.e8 1.e8 1.e8 10. 1.',
#' NO 1. 3.e5 3.e8 3.e8 10. 1.',
'PBEAM 1 1 1.+8 1.+8 1.+8 10. 1.',
' NO 1. 300000. 3.+8 3.+8 10. 1.',
]
model.add_card(lines, 'PBEAM', is_list=False)
lines_expected = [
'PBEAM 1 1 1.+8 1.+8 1.+8 10. 1.',
'+',
' NO 1. 300000. 3.+8 3.+8 10. 1.',
]
prop = model.properties[1]
#print(prop.raw_fields())
lines_actual = prop.write_card().split('\n')
msgA = ''
for line_expected, line_actual in zip(lines_expected, lines_actual):
#assert line_expected == line_actual, line_actual
actual = str(line_actual)
expected = str(line_expected)
msg = msgA + '\nactual = %r\n' % actual
msg += 'expected = %r' % expected
self.assertEqual(actual, expected, msg)
示例4: test_cord2r_02
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import add_card [as 别名]
def test_cord2r_02(self):
grid = ['GRID 20143 7 -9.31-4 .11841 .028296']
coord = [
'CORD2R 7 1.135 .089237 -.0676 .135 .089237 -.0676',
' 1.135 .089237 .9324'
]
model = BDF(debug=False)
card = model.process_card(grid)
model.add_card(card, card[0])
card = model.process_card(coord)
model.add_card(card, card[0])
model.cross_reference()
coord = model.Coord(7)
#print(coord.origin)
#print(coord.i, coord.j, coord.k)
g = model.Node(20143)
#print(g.Position(debug=False))
xyz = g.Position()
# by running it through Patran...
#GRID 20143 1.1067 .207647 -.068531
expected = array([1.106704, .207647, -0.068531])
diff = xyz - expected
msg = '\nexpected=%s \nactual =%s \ndiff =%s' % (expected, xyz, diff)
assert allclose(diff, 0.), msg
coord = model.Coord(7)
coord.beta_n(1)
coord.beta_n(2)
coord.beta_n(3)
coord.beta_n(6)
self.assertTrue(array_equal(coord.T(), coord.beta_n(2)))
示例5: test_encoding_write
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import add_card [as 别名]
def test_encoding_write(self):
from pyNastran.bdf.bdf import BDF
mesh = BDF()
mesh.add_card(['GRID', 100000, 0, 43.91715, -29., .8712984], 'GRID')
mesh.write_bdf('out.bdf')
lines_expected = [
'$pyNastran: version=msc',
'$pyNastran: punch=False',
'$pyNastran: encoding=ascii',
'$NODES',
'GRID 100000 43.91715 -29..8712984',
]
bdf_filename = 'out.bdf'
with codec_open(bdf_filename, 'r', encoding='ascii') as f:
lines = f.readlines()
i = 0
for line, line_expected in zip(lines, lines_expected):
line = line.rstrip()
line_expected = line_expected.rstrip()
msg = 'The lines are not the same...i=%s\n' % i
msg += 'line = %r\n' % line
msg += 'expected = %r\n' % line_expected
msg += '-------------\n--Actual--\n%s' % ''.join(lines)
msg += '-------------\n--Expected--\n%s' % ''.join(lines_expected)
self.assertEqual(line, line_expected, msg)
i += 1
示例6: test_solid_03
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import add_card [as 别名]
def test_solid_03(self):
"""checks linear static solid material"""
mid = 2
pid = 4
rho = 0.1
cards = [
# $ Solid Nodes
["GRID", 11, 0, 0.0, 0.0, 0.0, 0],
["GRID", 12, 0, 1.0, 0.0, 0.0, 0],
["GRID", 13, 0, 1.0, 1.0, 0.0, 0],
["GRID", 14, 0, 0.0, 1.0, 0.0, 0],
["GRID", 15, 0, 0.0, 0.0, 2.0, 0],
["GRID", 16, 0, 1.0, 0.0, 2.0, 0],
["GRID", 17, 0, 1.0, 1.0, 2.0, 0],
["GRID", 18, 0, 0.0, 1.0, 2.0, 0],
# Solids
["CHEXA", 7, pid, 11, 12, 13, 14, 15, 16, 17, 18],
["CTETRA", 8, pid, 11, 12, 13, 15],
# Solid Nodes
["GRID", 21, 0, 0.0, 0.0, 0.0, 0],
["GRID", 22, 0, 1.0, 0.0, 0.0, 0],
["GRID", 23, 0, 1.0, 1.0, 0.0, 0],
["GRID", 24, 0, 0.0, 0.0, 2.0, 0],
["GRID", 25, 0, 1.0, 0.0, 2.0, 0],
["GRID", 26, 0, 1.0, 1.0, 2.0, 0],
["CPENTA", 9, pid, 21, 22, 23, 24, 25, 26],
# static
["PSOLID", pid, mid, 0],
["MAT1", mid, 1.0, 2.0, 3.0, rho],
["MATS1", mid, None, "PLASTIC", 0.0, 1, 1, 100000.0],
]
model = BDF(debug=False)
for fields in cards:
model.add_card(fields, fields[0], is_list=True)
model.cross_reference()
示例7: test_cord2_rcs_01
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import add_card [as 别名]
def test_cord2_rcs_01(self):
"""
all points are located at <30,40,50>
"""
model = BDF(debug=False)
cards = [
[#'$ Femap with NX Nastran Coordinate System 10 : rectangular defined in a rectangular',
'CORD2R* 10 0 10. 5.',
'* 3. 10.3420201433 4.53015368961 3.81379768136* ',
'* 10.7198463104 5.68767171433 3.09449287122',],
[#'$ Femap with NX Nastran Coordinate System 11 : cylindrical defined in rectangular',
'CORD2C* 11 0 7. 3.',
'* 9. 7.64278760969 2.73799736977 9.71984631039* ',
'* 7.75440650673 3.37968226211 8.46454486422',],
[#'$ Femap with NX Nastran Coordinate System 12 : spherical defined in rectangular',
'CORD2S* 12 0 12. 8.',
'* 5. 12.6427876097 7.86697777844 5.75440650673* ',
'* 12.6634139482 8.58906867688 4.53861076379',],
['GRID* 10 10 42.9066011565 34.2422137135',
'* 28.6442730262 0',],
['GRID* 11 11 48.8014631871 78.8394787869',
'* 34.6037164304 0',],
['GRID* 12 12 58.0775343829 44.7276544324',
'* 75.7955331161 0',],
]
for lines in cards:
card = model.process_card(lines)
model.add_card(card, card[0])
model.cross_reference()
for nid in model.nodes:
a = array([30.,40.,50.])
b = model.Node(nid).Position()
self.assertTrue(allclose(array([30.,40.,50.]), model.Node(nid).Position()), str(a-b))
示例8: test_deqatn_1b
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import add_card [as 别名]
def test_deqatn_1b(self):
model = BDF(debug=None)
#model.cards_to_read.add('DEQATN')
model.test_deqatn = True
card = ["DEQATN", 1000, "MAXDIFF(t1,t2)=abs(t2-t1)/t1"]
with self.assertRaises(ValueError):
model.add_card(card, "DEQATN", is_list=False)
示例9: getNodes
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import add_card [as 别名]
def getNodes(self, grids, gridsExpected, coords, debug=False):
mesh = BDF(debug=False)
for (nid, grid) in enumerate(grids):
(cid, x, y, z) = grid
mesh.add_card(["GRID", nid + 1, cid, x, y, z], "GRID")
gridObj = mesh.Node(nid + 1)
if debug:
print(gridObj)
for (cid, coord) in enumerate(coords):
# print coord
(rid, x, y, z) = coord
obj = mesh.add_card(["CORD2R", cid + 1, rid] + x + y + z, "CORD2R")
coordObj = mesh.Coord(cid + 1)
if debug:
print(coordObj)
mesh.cross_reference()
for (i, grid) in enumerate(gridsExpected):
(cid, x, y, z) = grid
node = mesh.Node(i + 1)
pos = node.Position()
n = array([x, y, z])
msg = "expected=%s actual=%s\n" % (n, pos)
msg += "n=%s grid=\n%s" % (i + 1, node)
coord = node.cp
msg += "n=%s coord=\n%s" % (node.nid, coord)
while coord.rid:
msg += "n=%s rcoord=\n%s" % (node.nid, coord.rid)
coord = coord.rid
assert allclose(n, pos), msg
示例10: test_cord2r_1
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import add_card [as 别名]
def test_cord2r_1(self):
grid = ['GRID 20143 7 -9.31-4 .11841 .028296']
coord = [
'CORD2R 7 1.135 .089237 -.0676 .135 .089237 -.0676',
' 1.135 .089237 .9324']
model = BDF(debug=False)
card = model.process_card(grid)
model.add_card(card, card[0])
card = model.process_card(coord)
model.add_card(card, card[0])
model.cross_reference()
g = model.Node(20143)
#print(g.Position(debug=False))
# by running it through Patran...
#GRID 20143 1.1067 .207647 -.068531
diff = g.Position() - array([1.106704, .207647, -0.068531])
msg = 'diff=%s' % diff
assert allclose(diff, 0.), msg
coord = model.Coord(7)
coord.T()
self.assertTrue(array_equal(coord.T(), coord.beta_n(2)))
示例11: test_deqatn_10
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import add_card [as 别名]
def test_deqatn_10(self):
"""
per nast/tpl/ptdmi1.dat
"""
model = BDF(debug=None)
model.cards_to_read.add('DEQATN')
model.test_deqatn = True
card = [
'deqatn 2 f(x,y,z)= 1.;',
' L=x+y',
]
model.add_card(card, 'DEQATN', is_list=False)
model.cross_reference()
s = StringIO()
model.write_bdf(s, close=False)
s.getvalue()
s.close()
eq = model.dequations[2]
x = zeros(10., dtype='float32')
y = zeros(11., dtype='float32')
z = zeros(12., dtype='float32')
#out = eq.func(x, y, z)
out = eq.func(1.0, 2.0)
print(out)
示例12: test_deqatn_9
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import add_card [as 别名]
def test_deqatn_9(self):
"""
per nast/tpl/ptdmi1.dat
"""
model = BDF(debug=None)
model.cards_to_read.add('DEQATN')
model.test_deqatn = True
card = [
'deqatn 2 f(x,y,z)= 1.;',
' L=1+2+3+',
' + 4/min(1,2);',
' b= 4.;',
' h= 2.;',
' t1= 200.;',
' t2= 300.;',
' t=t1*(L-x)/L+t2*x/L',
' +4'
]
model.add_card(card, 'DEQATN', is_list=False)
model.cross_reference()
s = StringIO()
model.write_bdf(s, close=False)
s.getvalue()
s.close()
示例13: _get_nodes
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import add_card [as 别名]
def _get_nodes(self, grids, grids_expected, coords):
model = BDF(debug=False)
for grid in grids:
(nid, cid, x, y, z) = grid
model.add_card(["GRID", nid, cid, x, y, z], "GRID")
for coord in coords:
(cid, rid, x, y, z) = coord
model.add_card(["CORD2R", cid, rid] + x + y + z, "CORD2R")
coordObj = model.Coord(cid)
model.cross_reference()
for i, grid in enumerate(grids_expected):
nid, cid, x, y, z = grid
node = model.Node(nid)
pos = node.Position()
n = array([x, y, z])
msg = "i=%s expected=%s actual=%s\n" % (i, n, pos)
msg += "n=%s grid=\n%s" % (nid, node)
coord = node.cp
msg += "n=%s coord=\n%s" % (node.nid, coord)
while coord.rid:
msg += "n=%s rcoord=\n%s" % (node.nid, coord.rid)
coord = coord.rid
assert allclose(n, pos), msg
示例14: add_card
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import add_card [as 别名]
def add_card(self, card_lines, card_name, comment='', is_list=True):
card_name = card_name.upper()
self._increase_card_count(card_name)
if card_name in ['DEQATN']:
card_obj = card_lines
card = card_lines
else:
if is_list:
fields = card_lines
else:
fields = to_fields(card_lines, card_name)
# apply OPENMDAO syntax
if self._is_dynamic_syntax:
fields = [self._parse_dynamic_syntax(field) if '%' in
field[0:1] else field for field in fields]
card = wipe_empty_fields([interpret_value(field, fields)
if field is not None
else None for field in fields])
else: # leave everything as strings
card = wipe_empty_fields(fields)
card_obj = BDFCard(card)
if card_name == 'HYPER':
hyper = HYPER(card_obj, comment)
self.hyper[hyper.pid] = hyper
return
elif card_name == 'FLOW':
flow = FLOW(card_obj, comment)
self.flow[flow.flow_id] = flow
return
BDF.add_card(self, card, card_name, comment=comment, is_list=True)
示例15: test_cord2_bad_01
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import add_card [as 别名]
def test_cord2_bad_01(self):
model = BDF(debug=False)
cards = [
["CORD2R", 1, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], # fails on self.k
["CORD2R", 2, 0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0], # fails on normalize self.j
["CORD2R", 3, 0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], # passes
["CORD2R", 4, 0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], # passes
["CORD2R", 5, 4, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], # passes
]
for card in cards:
cid = card[1]
if cid in [1, 2]:
with self.assertRaises(RuntimeError):
model.add_card(card, card[0], is_list=True)
else:
model.add_card(card, card[0], is_list=True)
# this runs because it's got rid=0
cord4 = model.Coord(4)
cord4.transform_node_to_global([0.0, 0.0, 0.0])
# this doesn't run because rid != 0
cord5 = model.Coord(5)
with self.assertRaises(RuntimeError):
cord5.transform_node_to_global([0.0, 0.0, 0.0])
model.cross_reference()