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


Python Output.add_unstruct_mesh方法代码示例

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


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

示例1: TestConnectivity

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

  def setUp(self):
    import os
    import numpy
    import random
    from Danu import Output
    from Danu import UNSTRUCTURED_MESH
    from Danu import HEX_ELEM, HEX_ELEM_ORDER 

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

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

    self.mesh_name='Test Mesh 3D HEX'
    self.mesh=self.fh.add_unstruct_mesh(self.mesh_name,HEX_ELEM)
    
    self.data_name='Data to Read'
    self.nelem=random.randint(10,2048)
    self.data=numpy.zeros((self.nelem,HEX_ELEM_ORDER),dtype=numpy.int32)
    nc=0
    while nc < self.nelem:
      i=0
      while i < HEX_ELEM_ORDER:
        self.data[nc][i]=random.randint(0,100000)
        i=i+1
      nc=nc+1	

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

  def test_basic(self):
    import numpy
    import random

    # try to read before a write
    try:
      r_data=self.mesh.read_connectivity()
    except:
      print 'Caught the read before write error'

    self.mesh.write_connectivity(self.data)  
    read_data=self.mesh.read_connectivity()
    self.assertEqual(read_data.all(),self.data.all())

  def test_offset(self):
    import numpy
    import random

    self.mesh.write_connectivity(self.data)  

    offset=self.mesh.connectivity_offset()
    self.assertEqual(offset,0)
开发者ID:certik,项目名称:truchas-release,代码行数:60,代码来源:TestMesh.py

示例2: TestAttributes

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

  def setUp(self):
    import os
    import numpy
    import random
    from Danu import Output
    from Danu import UNSTRUCTURED_MESH
    from Danu import HEX_ELEM, HEX_ELEM_ORDER 

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

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

    self.mesh_name='Test Mesh 3D HEX'
    self.mesh=self.fh.add_unstruct_mesh(self.mesh_name,HEX_ELEM)
    
    self.n=random.randint(10,2048)
    self.x=numpy.random.random_sample((self.n))
    self.y=numpy.random.random_sample((self.n))
    self.z=numpy.random.random_sample((self.n))
    self.coordinates=[self.x,self.y,self.z]
    self.mesh.write_coordinates(self.x,self.y,self.z)
    self.nelem=random.randint(1024,2048)
    self.data=numpy.zeros((self.nelem,HEX_ELEM_ORDER),dtype=numpy.int32)
    nc=0
    while nc < self.nelem:
      i=0
      while i < HEX_ELEM_ORDER:
        self.data[nc][i]=random.randint(0,100000)
        i=i+1
      nc=nc+1	
    self.mesh.write_connectivity(self.data)

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

  def runTest(self):
    import Danu
    self.assertEqual(self.x.size,self.mesh.nnodes())
    self.assertEqual(Danu.HEX_ELEM_ORDER,self.mesh.elem_order())
    print self.mesh.nelem()
开发者ID:certik,项目名称:truchas-release,代码行数:49,代码来源:TestMesh.py

示例3: TestMeshWriteCoordinates

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

  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'
    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_write_coordinates_1D(self):
    import numpy
    import random
    from Danu import LINE_ELEM

    mesh_name = '1D Mesh'
    nnodes=random.randint(128,1024)
    mesh = self.fh.add_unstruct_mesh(mesh_name,LINE_ELEM)
    xcoordinates = numpy.random.random_sample((nnodes))
    try:
      mesh.write_coordinates()
      raise RuntimeError, "Failed to raise exception"
    except:
      print "Caught null argument exception"

    try:
      mesh.write_coordinates(1)
      raise RuntimeError, "Failed to raise exception"
    except:
      print "Caught invalid data type"

    mesh.write_coordinates(xcoordinates)
开发者ID:certik,项目名称:truchas-release,代码行数:48,代码来源:TestMesh.py

示例4: TestOutputMesh

# 需要导入模块: from Danu import Output [as 别名]
# 或者: from Danu.Output import add_unstruct_mesh [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)
开发者ID:certik,项目名称:truchas-release,代码行数:82,代码来源:TestOutput.py


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