当前位置: 首页>>代码示例>>Python>>正文


Python Output.get_mesh方法代码示例

本文整理汇总了Python中Danu.Output.get_mesh方法的典型用法代码示例。如果您正苦于以下问题:Python Output.get_mesh方法的具体用法?Python Output.get_mesh怎么用?Python Output.get_mesh使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Danu.Output的用法示例。


在下文中一共展示了Output.get_mesh方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestMeshReadCoordinates

# 需要导入模块: from Danu import Output [as 别名]
# 或者: from Danu.Output import get_mesh [as 别名]
class TestMeshReadCoordinates(unittest.TestCase):

  def _writeUnstructMesh(self,name,ndim,elem):
    import numpy
    import random
    nnodes=random.randint(10,512)
    mesh = self.fh.add_unstruct_mesh(name,elem)
    x=numpy.random.random_sample((nnodes))
    if ndim == 1:
      mesh.write_coordinates(x) 
      return x
    if ndim == 2:
      y=numpy.random.random_sample((nnodes))
      mesh.write_coordinates(x,y)
      return (x,y)
    else:
      y=numpy.random.random_sample((nnodes))
      z=numpy.random.random_sample((nnodes))
      mesh.write_coordinates(x,y,z)
      return (x,y,z)

  def setUp(self):
    import os
    from Danu import Output
    from Danu import UNSTRUCTURED_MESH, STRUCTURED_MESH
    from Danu import LINE_ELEM, TRI_ELEM, QUAD_ELEM, TET_ELEM, HEX_ELEM 

    self.filename = 'test-Mesh.h5'
    if  os.path.exists(self.filename):
      os.remove(self.filename)

    self.fh       = Output(self.filename,'w')

    self.valid_mesh_types = [UNSTRUCTURED_MESH, STRUCTURED_MESH]
    self.valid_mesh_elems1 = [LINE_ELEM]
    self.valid_mesh_elems2 = [TRI_ELEM, QUAD_ELEM]
    self.valid_mesh_elems3 = [TET_ELEM, HEX_ELEM]

    self.valid_mesh_1D = []
    self.valid_mesh_2D = []
    self.valid_mesh_3D = []
     
    for elem in self.valid_mesh_elems1:
      mesh_name='Mesh 1D' + str(elem)
      self._writeUnstructMesh(mesh_name,1,elem)
      self.valid_mesh_1D.insert(0,mesh_name)

    for elem in self.valid_mesh_elems2:
      mesh_name='Mesh 2D' + str(elem)
      self._writeUnstructMesh(mesh_name,2,elem)
      self.valid_mesh_2D.insert(0,mesh_name)

    for elem in self.valid_mesh_elems3:
      mesh_name='Mesh 3D' + str(elem)
      self._writeUnstructMesh(mesh_name,3,elem)
      self.valid_mesh_3D.insert(0,mesh_name)


  def tearDown(self):
    if os.path.exists(self.filename):
      self.fh.close()
      os.remove(self.filename)

  def test_read_coord_1D(self):
    import numpy
    for mesh_name in self.valid_mesh_1D:
      mesh=self.fh.get_mesh(mesh_name)
      x=mesh.read_coordinates(0,1024)
    mesh=self.fh.get_mesh(self.valid_mesh_1D[0])
    try:
      mesh.read_coordiantes(1,1024)
    except:
      print 'Caught invalid dimension request'
  
  def test_read_coord_2D(self):
    import numpy
    for mesh_name in self.valid_mesh_2D:
      mesh=self.fh.get_mesh(mesh_name)
      x=mesh.read_coordinates(0,1024)
      y=mesh.read_coordinates(1,1024)
  
  def test_read_coord_3D(self):
    import numpy
    for mesh_name in self.valid_mesh_3D:
      mesh=self.fh.get_mesh(mesh_name)
      x=mesh.read_coordinates(0,1024)
      y=mesh.read_coordinates(1,1024)
      z=mesh.read_coordinates(2,1024)

  def test_read_fails(self):
    import numpy
    mesh=self.fh.get_mesh(self.valid_mesh_2D[0])
    try:
      mesh.read_coordinates(3,1024)
    except:
      print 'Caught invalid dimension request'
    try:
      mesh.read_coordinates(0,5)
    except:
      print 'Caught invalid nnodes size'
#.........这里部分代码省略.........
开发者ID:certik,项目名称:truchas-release,代码行数:103,代码来源:TestMesh.py

示例2: TestMeshUtils

# 需要导入模块: from Danu import Output [as 别名]
# 或者: from Danu.Output import get_mesh [as 别名]
class TestMeshUtils(unittest.TestCase):
  
  def setUp(self):
    from Danu import Output
    from Danu import UNSTRUCTURED_MESH, STRUCTURED_MESH
    from Danu import LINE_ELEM, TRI_ELEM, QUAD_ELEM, TET_ELEM, HEX_ELEM 

    self.filename = 'test-Mesh.h5'
    if os.path.exists(self.filename):
      os.remove(self.filename)
    self.fh       = Output(self.filename,'w')

    self.mesh_count = 0
    self.mesh_names = []

    self.valid_mesh_types = [UNSTRUCTURED_MESH, STRUCTURED_MESH]
    self.valid_mesh_elems1 = [LINE_ELEM]
    self.valid_mesh_elems2 = [TRI_ELEM, QUAD_ELEM]
    self.valid_mesh_elems3 = [TET_ELEM, HEX_ELEM]

  def tearDown(self):
    if os.path.exists(self.filename):
      self.fh.close()
      os.remove(self.filename)

  def test_mesh_open(self):
    import Danu 
    mesh_name='Test Mesh DNE'
    self.failUnlessRaises(RuntimeError,self.fh.get_mesh,mesh_name) 
    Mesh(self.fh,mesh_name,Danu.UNSTRUCTURED_MESH,Danu.LINE_ELEM)
    mesh=self.fh.get_mesh(mesh_name)

  def test_mesh_destory(self):
    import Danu
    mesh_name='Test Mesh'
    mesh=Mesh(self.fh,mesh_name,Danu.UNSTRUCTURED_MESH,Danu.LINE_ELEM)
    del mesh

  def test_mesh_create_1D(self):
    import random
    import string
    for mesh_type in self.valid_mesh_types:
      for elem in self.valid_mesh_elems1:
        mesh_name = ''.join(random.choice(string.letters) for i in xrange(16))
        mesh = Mesh(self.fh,mesh_name,mesh_type,elem)
        self.assertEqual(mesh.dim,1, 'Incorrect dimension')
        self.assertEqual(mesh.mesh_type,mesh_type,'Incorrect mesh type')
        self.assertEqual(mesh.elem_type,elem,'Incorrect mesh element type')

  def test_mesh_create_2D(self):
    import random
    import string
    for mesh_type in self.valid_mesh_types:
      for elem in self.valid_mesh_elems2:
        mesh_name = ''.join(random.choice(string.letters) for i in xrange(16))
        mesh = Mesh(self.fh,mesh_name,mesh_type,elem)
        self.assertEqual(mesh.dim,2, 'Incorrect dimension')
        self.assertEqual(mesh.mesh_type,mesh_type,'Incorrect mesh type')
        self.assertEqual(mesh.elem_type,elem,'Incorrect mesh element type')

  def test_mesh_create_3D(self):
    import random
    import string
    for mesh_type in self.valid_mesh_types:
      for elem in self.valid_mesh_elems3:
        mesh_name = ''.join(random.choice(string.letters) for i in xrange(16))
        mesh = Mesh(self.fh,mesh_name,mesh_type,elem)
        self.assertEqual(mesh.dim,3, 'Incorrect dimension')
        self.assertEqual(mesh.mesh_type,mesh_type,'Incorrect mesh type')
        self.assertEqual(mesh.elem_type,elem,'Incorrect mesh element type')
开发者ID:certik,项目名称:truchas-release,代码行数:72,代码来源:TestMesh.py


注:本文中的Danu.Output.get_mesh方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。