本文整理汇总了Python中pyNastran.bdf.bdf.BDF.readBDF方法的典型用法代码示例。如果您正苦于以下问题:Python BDF.readBDF方法的具体用法?Python BDF.readBDF怎么用?Python BDF.readBDF使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyNastran.bdf.bdf.BDF
的用法示例。
在下文中一共展示了BDF.readBDF方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import readBDF [as 别名]
def run(self, bdfName):
model = BDF()
model.cardsToRead = get_cards()
model.readBDF(bdfName)
cc = model.caseControlDeck
#print cc.subcases
analysisCases = []
for (isub, subcase) in sorted(cc.subcases.iteritems()):
if subcase.hasParameter('LOAD'):
analysisCases.append(subcase)
#print analysisCases
for case in analysisCases:
print(case)
(value, options) = case.get_parameter('STRESS')
print("STRESS value = %s" % (value))
print("STRESS options = %s" % (options))
if case.hasParameter('TEMPERATURE(INITIAL)'):
(value, options) = case.get_parameter('TEMPERATURE(INITIAL)')
print('value = %s' % (value))
print('options = %s' % (options))
raise NotImplementedError('TEMPERATURE(INITIAL) not supported')
#integrate(B.T*E*alpha*dt*Ads)
#sys.exit('starting case')
self.runCase(model, case)
示例2: test_case_control_02
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import readBDF [as 别名]
def test_case_control_02(self):
bdf_filename = os.path.join(test_path, 'unit', 'case_control.dat')
bdf_filename2 = os.path.join(test_path, 'unit', 'case_control_out.dat')
mesh = BDF(debug=True,log=None)
mesh.readBDF(bdf_filename, includeDir=None, xref=True)
str(mesh.caseControlDeck)
mesh.caseControlDeck.create_new_subcase(1)
#with self.assertRaises(AssertionError):
str(mesh.caseControlDeck)
subcase1 = mesh.caseControlDeck.subcases[1]
str(subcase1)
mesh.caseControlDeck.add_parameter_to_local_subcase(1, 'LOAD=1')
str(mesh.caseControlDeck)
mesh.caseControlDeck.create_new_subcase(2)
mesh.caseControlDeck.add_parameter_to_local_subcase(2, 'LOAD=2')
mesh.write_bdf(bdf_filename2)
#print("---cc 3---\n%s" % str(mesh.caseControlDeck))
f = open(bdf_filename2, 'r')
lines = f.readlines()
f.close()
lines_expected = [
'$EXECUTIVE CONTROL DECK',
'SOL 101',
'CEND',
'$CASE CONTROL DECK',
'TITLE = STATIC',
'SUBCASE 1',
' LOAD = 1',
'SUBCASE 2',
' LOAD = 2',
'BEGIN BULK',
'$PARAMS',
'PARAM AUTOSPC YES',
'PARAM NOFISR 0',
'$NODES',
'GRID 1 0. 0. 0.',
'ENDDATA',
]
for line, line_expected in zip(lines, lines_expected):
line = line.rstrip()
msg = 'The lines are not the same...\n'
msg += 'line = %r\n' % line
msg += 'expected = %r' % line_expected
self.assertEqual(line, line_expected, msg)
示例3: run_fem2
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import readBDF [as 别名]
def run_fem2(bdfModel, outModel, xref, debug=False, log=None):
assert os.path.exists(bdfModel), bdfModel
assert os.path.exists(outModel), outModel
fem2 = BDF(debug=debug, log=log)
fem2.log.info('starting fem2')
sys.stdout.flush()
try:
fem2.readBDF(outModel, xref=xref)
except:
print("failed reading |%s|" % (outModel))
raise
#fem2.sumForces()
#fem2.sumMoments()
outModel2 = bdfModel + '_out2'
fem2.writeBDFAsPatran(outModel2)
#fem2.writeAsCTRIA3(outModel2)
os.remove(outModel2)
return (fem2)
示例4: PanelBuckling
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import readBDF [as 别名]
class PanelBuckling(object):
def __init__(self, bdfFileName):
"""
Preliminary work on a panel buckling code
Assumptions:
1. node connectivitity (no gaps)
2. large change in normal vector signifies change in panel
3. only CTRIA3, CQUAD4 elements
"""
self.bdf = BDF(debug=True, log=None)
self.bdf.readBDF(bdfFileName, xref=True)
self.maxAngle = 10.
def makePanels(self):
self.shells = {}
## maps elements to edges
Edges = {}
for eid, element in sorted(self.bdf.elements.iteritems()):
if isinstance(element, ShellElement):
Edges[eid] = []
self.shells[eid] = element
on = True
## maps edges to elements
Edges2 = {}
Normals = {}
for eid, element in sorted(self.shells.iteritems()):
edges = []
Normals[eid] = element.Normal()
nodeIDs = element.nodeIDs()
for i in xrange(len(nodeIDs) - 1):
key = tuple(sorted([nodeIDs[i], nodeIDs[i + 1]]))
Edges[eid].append(key)
Edges2[key] = []
key = tuple(sorted([nodeIDs[i + 1], nodeIDs[0]]))
Edges[eid].append(key)
Edges2[key] = []
#print "Edges[eid=%s] = %s" %(eid,Edges[eid])
if on:
#print Edges[eid]
on = False
#print 'nodeIDs[%s] = %s' %(eid,element.nodeIDs())
#Edges[eid] = edges
del key, edges, element
for eid, edges in sorted(Edges.iteritems()):
for edge in edges:
Edges2[edge].append(eid)
#print "Edges2[edge=%s] = %s" %(edge,Edges2[edge])
#print "Edges[edge=%s] = %s" %(edge,Edges2[edge]) # edges to elements
self.buildEdgeCount(Edges, Edges2, Normals)
#self.buildPanel2(Edges,Edges2,Normals)
self.buildPanelMove(Edges, Edges2, Normals)
def buildEdgeCount(self, Edges, Edges2, Normals):
#Edges2 = {} ## maps edges to elements
#print "Edges[edge=%s] = %s" %(edge,Edges2[edge]) # edges to elements
self.edgeCount = {}
for edge, elements in sorted(Edges2.iteritems()):
#elements = self.removeExtraElements2(elements)
self.edgeCount[edge] = len(elements)
print "edge=%s elements=%s edgeCount=%s" % (
edge, elements, self.edgeCount[edge])
def buildPanelMove(self, Edges, Edges2, Normals, eStart=None):
self.unclaimed = Normals.keys()
eStart = 22040
if eStart is None:
eStart = self.unclaimed[0]
self.unclaimed = set(self.unclaimed)
print "eStart = ", eStart
#Edges2 = {} ## maps edges to elements
#print "Edges[edge=%s] = %s" %(edge,Edges2[edge]) # edges to elements
patches = {}
patch = [eStart]
self.claimed = []
iLevel = 0
patch = self.buildPatch(patch, iLevel, Edges, Edges2, eStart)
print "self.claimed = ", self.claimed
# if a node is shared by *3* elements at the edge of a patch, it's a corner element
# from 2, 1 is found, then 3 is found
# from 1, 2 is found, then 3 is found
# from 1,2,3 we can find ?
#
#================
# ||
# 1 | ? ||
# | ||
# -----*-------||
# 2 | 3 ||
# | ||
#.........这里部分代码省略.........
示例5: loadGeometry
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import readBDF [as 别名]
def loadGeometry(self, bdf_filename):
model = BDF()
model.readBDF(bdf_filename)
nNodes = model.nNodes()
nElements = model.nElements()
nCAeros = model.nCAeros()
#print "nNodes = ",nNodes
print "nElements = ", nElements
self.grid = vtk.vtkUnstructuredGrid()
self.grid2 = vtk.vtkUnstructuredGrid()
#self.aQuadGrid.Allocate(nElements+nNodes, 1000)
if 'CONM2' in model.cardCount:
nCONM2 = model.cardCount['CONM2']
else:
nCONM2 = 0
self.grid.Allocate(nElements, 1000)
self.grid2.Allocate(nCAeros + nCONM2, 1000)
points = vtk.vtkPoints()
points.SetNumberOfPoints(nNodes)
nidMap = {}
i = 0
#elem.SetNumberOfPoints(nNodes)
for nid, node in sorted(model.nodes.iteritems()):
#print "i = ",i
point = node.Position()
#print "point = ",point
#sys.stdout.flush()
#aVoxel = vtk.vtkPixel()
#print "made voxel"; sys.stdout.flush()
points.InsertPoint(i, *point)
#print str(element)
#elem = vtk.vtkVertex()
#elem.GetPointIds().SetId(0, i)
#self.aQuadGrid.InsertNextCell(elem.GetCellType(), elem.GetPointIds())
nidMap[nid] = i
i += 1
j = 0
points2 = vtk.vtkPoints()
points2.SetNumberOfPoints(nCAeros * 4 + nCONM2)
for eid, element in sorted(model.caeros.iteritems()):
if isinstance(element, CAERO1):
cpoints = element.Points()
elem = vtkQuad()
elem.GetPointIds().SetId(0, j)
elem.GetPointIds().SetId(1, j + 1)
elem.GetPointIds().SetId(2, j + 2)
elem.GetPointIds().SetId(3, j + 3)
points2.InsertPoint(j, *cpoints[0])
points2.InsertPoint(j + 1, *cpoints[1])
points2.InsertPoint(j + 2, *cpoints[2])
points2.InsertPoint(j + 3, *cpoints[3])
self.grid2.InsertNextCell(
elem.GetCellType(), elem.GetPointIds())
j += 4
self.mapElements(points, points2, nidMap, model, j)
示例6: loadNastranGeometry
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import readBDF [as 别名]
def loadNastranGeometry(self, bdfFileName, dirname, isNodal, isCentroidal):
self.isNodal = isNodal
self.isCentroidal = isCentroidal
#key = self.caseKeys[self.iCase]
#case = self.resultCases[key]
#skipReading = self.removeOldGeometry(bdfFileName)
#if skipReading:
#return
if bdfFileName is None:
self.grid = vtk.vtkUnstructuredGrid()
self.gridResult = vtk.vtkFloatArray()
#self.emptyResult = vtk.vtkFloatArray()
#self.vectorResult = vtk.vtkFloatArray()
self.grid2 = vtk.vtkUnstructuredGrid()
self.scalarBar.VisibilityOff()
return
else:
self.TurnTextOff()
self.grid.Reset()
self.grid2.Reset()
self.gridResult = vtk.vtkFloatArray()
self.gridResult.Reset()
self.gridResult.Modified()
self.eidMap = {}
self.nidMap = {}
self.resultCases = {}
self.nCases = 0
try:
if hasattr(self, caseKeys):
del self.caseKeys
del self.iCase
del self.iSubcaseNameMap
except NameError:
print("cant delete geo")
#pass
###
#print dir(self)
self.scalarBar.VisibilityOff()
self.scalarBar.Modified()
model = BDF()
self.modelType = model.modelType
model.readBDF(bdfFileName, includeDir=dirname)
nNodes = model.nNodes()
nElements = model.nElements()
nCAeros = model.nCAeros()
self.nNodes = nNodes
self.nElements = nElements
#print "nNodes = ",self.nNodes
print("nElements = %i" % (self.nElements))
#self.aQuadGrid.Allocate(nElements+nNodes, 1000)
if 'CONM2' in model.cardCount:
nCONM2 = model.cardCount['CONM2']
else:
nCONM2 = 0
self.grid.Allocate(self.nElements, 1000)
#self.gridResult.SetNumberOfComponents(self.nElements)
#self.gridResult.SetNumberOfComponents(0)
self.gridResult.SetNumberOfComponents(self.nElements)
#self.gridResult.Allocate(self.nNodes,1000)
self.grid2.Allocate(nCAeros + nCONM2, 1000)
points = vtk.vtkPoints()
points.SetNumberOfPoints(self.nNodes)
self.gridResult.Allocate(self.nNodes, 1000)
#vectorReselt.SetNumberOfComponents(3)
self.nidMap = {}
#elem.SetNumberOfPoints(nNodes)
if 0:
i = 0
fraction = 1. / nNodes # so you can color the nodes by ID
for (nid, node) in sorted(model.nodes.iteritems()):
#print "i = ",i
point = node.Position()
#print "point = ",point
points.InsertPoint(i, *point)
self.gridResult.InsertNextValue(i * fraction)
#print str(element)
#elem = vtk.vtkVertex()
#elem.GetPointIds().SetId(0, i)
#self.aQuadGrid.InsertNextCell(elem.GetCellType(),
# elem.GetPointIds())
#vectorResult.InsertTuple3(0, 0.0, 0.0, 1.0)
self.nidMap[nid] = i
i += 1
if 1:
i = 0
for (nid, node) in sorted(model.nodes.iteritems()):
point = node.Position()
points.InsertPoint(i, *point)
self.nidMap[nid] = i
#.........这里部分代码省略.........
示例7: NastranComponent
# 需要导入模块: from pyNastran.bdf.bdf import BDF [as 别名]
# 或者: from pyNastran.bdf.bdf.BDF import readBDF [as 别名]
#.........这里部分代码省略.........
# if we want to supply a function that will parse
# out the wanted information from the output object
if trait.nastran_func:
output_variables[name] = trait
# this is the grid method of accessing. We have to
# specify a header, id, and column and
# the output variable will be set to that value
elif trait.nastran_header and trait.nastran_constraints :
grid_outputs[name] = trait
elif trait.nastran_header or trait.nastran_constraints:
raise RuntimeError("You specified at least one of " + \
"nastran_header and nastran_constraints"+\
", but you " + \
"did not specify all them. You " + \
"most probably mistyped")
# do our work in a tmp dir
tmpdir = mkdtemp(dir = self.output_tempdir_dir)
tmppath = os.path.join(tmpdir, "input.bdf")
pyNastran_get_card_methods = {
'PSHELL': 'Property',
'PROD': 'Property',
'FORCE': 'Load',
'MAT1': 'Material',
}
########## Read BDF ##########
self.timing_section( "Read BDF" )
self.bdf = BDF(debug=False,log=logging.getLogger() )
self.bdf.readBDF(self.nastran_filename,xref=True)
########## Modify BDF ##########
self.timing_section( "Modify BDF" )
for name, trait in iteritems(smart_replacements):
value = getattr(self, name)
nastran_id = int( trait.nastran_id )
get_method = getattr( self.bdf, pyNastran_get_card_methods[ trait.nastran_card ] )
# some of these methods have an extra arg for error reporting
args = inspect.getargspec(get_method).args
if 'msg' in args:
nastran_item = get_method( nastran_id, 'dummy msg' )
else:
nastran_item = get_method( nastran_id )
if trait.nastran_card == 'FORCE' :
nastran_item = nastran_item[0]
setattr(nastran_item, trait.nastran_field, value)
########## update hook ##########
self.update_hook()
########## write modified BDF ##########
self.timing_section( "Write modified BDF" )
#self.bdf.write_bdf(tmppath)
self.bdf.write_bdf(tmppath,precision='double',size=16)
########## Run Nastran via subprocess ##########
self.timing_section( "Run Nastran" )
self.output_filename = os.path.join(tmpdir, "input.out")
print(self.output_filename) # perhaps this should be logged, or something