本文整理匯總了Python中sfepy.fem.mesh.Mesh.elements方法的典型用法代碼示例。如果您正苦於以下問題:Python Mesh.elements方法的具體用法?Python Mesh.elements怎麽用?Python Mesh.elements使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sfepy.fem.mesh.Mesh
的用法示例。
在下文中一共展示了Mesh.elements方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: gen_mesh_from_poly
# 需要導入模塊: from sfepy.fem.mesh import Mesh [as 別名]
# 或者: from sfepy.fem.mesh.Mesh import elements [as 別名]
def gen_mesh_from_poly(filename, verbose=True):
"""
Import mesh generated by tetgen or triangle.
Parameters
----------
filename : string
file name
Returns
-------
mesh : Mesh instance
triangular or tetrahedral mesh
"""
def getnodes(fnods,up):
f=file(fnods)
l=[int(x) for x in f.readline().split()]
npoints,dim,nattrib,nbound=l
if verbose: up.init(npoints)
nodes=[]
for line in f:
if line[0]=="#": continue
l=[float(x) for x in line.split()]
l = l[:(dim + 1)]
l[0]=int(l[0])
nodes.append(tuple(l))
assert l[0]==len(nodes)
assert npoints==len(nodes)
return nodes
def getele(fele,up):
f=file(fele)
l=[int(x) for x in f.readline().split()]
nele,nnod,nattrib=l
#we have either linear or quadratic tetrahedra:
if nnod in [4,10]:
elem = 'tetra'
linear = (nnod == 4)
if nnod in [3, 7]:
elem = 'tri'
linear = (nnod == 3)
# if nattrib!=1:
# raise "tetgen didn't assign an entity number to each element (option -A)"
els=[]
regions={}
for line in f:
if line[0]=="#": continue
l=[int(x) for x in line.split()]
if elem == 'tri':
if linear:
assert (len(l) - 1 - nattrib) == 3
els.append((l[0],l[1],l[2],l[3]))
regionnum=l[5]
else:
assert len(l)-2 == 10
els.append((l[0],54,l[1],l[2],l[3],l[4],
l[5],l[6],l[7],l[8],l[9],l[10]))
regionnum=l[11]
if elem == 'tetra':
if linear:
assert len(l)-2 == 4
els.append((l[0],54,l[1],l[2],l[3],l[4]))
regionnum=l[5]
else:
assert len(l)-2 == 10
els.append((l[0],54,l[1],l[2],l[3],l[4],
l[5],l[6],l[7],l[8],l[9],l[10]))
regionnum=l[11]
if regionnum==0:
print "see %s, element # %d"%(fele,l[0])
raise "there are elements not belonging to any physical entity"
if regions.has_key(regionnum):
regions[regionnum].append(l[0])
else:
regions[regionnum]=[l[0]]
assert l[0]==len(els)
if verbose: up.update(l[0])
return els,regions,linear
def getBCfaces(ffaces,up):
f=file(ffaces)
l=[int(x) for x in f.readline().split()]
nfaces,nattrib=l
if nattrib!=1:
raise "tetgen didn't assign an entity number to each face \
(option -A)"
if verbose: up.init(nfaces)
faces={}
for line in f:
if line[0]=="#": continue
l=[int(x) for x in line.split()]
assert len(l)==5
regionnum=l[4]
if regionnum==0: continue
if faces.has_key(regionnum):
faces[regionnum].append((l[1],l[2],l[3]))
else:
faces[regionnum]=[(l[1],l[2],l[3])]
#.........這裏部分代碼省略.........