本文整理汇总了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])]
#.........这里部分代码省略.........