本文整理汇总了Python中Danu.Output.mesh_list方法的典型用法代码示例。如果您正苦于以下问题:Python Output.mesh_list方法的具体用法?Python Output.mesh_list怎么用?Python Output.mesh_list使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Danu.Output
的用法示例。
在下文中一共展示了Output.mesh_list方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestOutputMesh
# 需要导入模块: from Danu import Output [as 别名]
# 或者: from Danu.Output import mesh_list [as 别名]
class TestOutputMesh(unittest.TestCase):
def setUp(self):
from Danu import LINE_ELEM, TRI_ELEM, QUAD_ELEM, TET_ELEM, HEX_ELEM
self.filename = 'test-Output.h5'
self.fh = Output(self.filename,'w')
self.mesh_count = 0
self.mesh_names = []
self.valid_elems = [LINE_ELEM, TRI_ELEM, QUAD_ELEM, TET_ELEM, HEX_ELEM]
def tearDown(self):
if os.path.exists(self.filename):
self.fh.close()
os.remove(self.filename)
def get_random_elem(self):
from random import choice
return choice(self.valid_elems)
def test_add_mesh_u(self):
# Require and element type
try:
self.fh.add_unstruct_mesh('Test Mesh')
except RuntimeError:
print 'Caught the invalid mesh value'
# Test all avail mesh types
for elem in self.valid_elems:
mesh_name = 'Test Mesh ' + str(elem)
self.fh.add_unstruct_mesh(mesh_name,elem)
# Try to add an existing mesh
elem = self.valid_elems[0]
mesh_name = 'Test Mesh ' + str(elem)
try:
self.fh.add_unstruct_mesh(mesh_name,elem)
except:
print 'Caught the exception when mesh already exists'
def test_mesh_exists(self):
import random
import string
mesh_name = ''.join(random.choice(string.letters) for i in xrange(16))
self.assertEqual(self.fh.mesh_exists(mesh_name),0,'Failed to query DNE mesh correctly')
mesh_name = 'Test Mesh'
elem = self.get_random_elem()
mesh = self.fh.add_unstruct_mesh(mesh_name,elem)
self.assertFalse(mesh is NoneType, 'Failed to add random mesh type')
self.assertTrue(self.fh.mesh_exists(mesh_name), 'Failed to locate existing mesh')
def test_mesh_count(self):
import random
self.assertEqual(self.mesh_count,self.fh.mesh_count(), 'Failed to return correct mesh count')
num_mesh = random.randint(1,32)
m = 1
while m <= num_mesh:
elem = self.get_random_elem()
mesh_name = 'Test Mesh ' + str(m)
self.fh.add_unstruct_mesh(mesh_name,elem)
self.mesh_count = self.mesh_count + 1
m = m + 1
self.assertEqual(self.mesh_count,self.fh.mesh_count(), 'Failed to return correct mesh count')
def test_mesh_list(self):
import random
mesh_list = self.fh.mesh_list()
self.assertEqual(len(mesh_list),self.mesh_count, 'Incorrect mesh list length')
num_mesh = random.randint(1,32)
m = 1
while m <= num_mesh:
elem = self.get_random_elem()
mesh_name = 'Test Mesh ' + str(m)
self.fh.add_unstruct_mesh(mesh_name,elem)
self.mesh_count = self.mesh_count + 1
self.mesh_names.append(mesh_name)
m = m + 1
mesh_list = self.fh.mesh_list()
for name in mesh_list:
self.assertTrue(name in self.mesh_names)