コード例 #1
0
 def test_open_rdonly(self):
     from Danu import FILE_ACC_RDONLY
     bad_file = 'does-not-exist-' + self.filename
     try:
         file = Output(bad_file, 'r')
     except:
         print 'Caught the bad file error'
     else:
         print 'Failed to catch the error'
         raise
     file = Output(self.filename, 'r')
     access = file.access
     self.assertEqual(access, FILE_ACC_RDONLY)
     del file
コード例 #2
0
    def setUp(self):
        import random
        import string

        self.filename = 'test-Output.h5'

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

        self.attributes = []

        self.int_attr_name = 'Dummy Int Attribute'
        self.attributes.append(self.int_attr_name)
        self.int_attr = random.randint(0, 1000000)
        self.fh.set_attribute(self.int_attr_name, self.int_attr)

        self.double_attr_name = 'Dummy Double Attribute'
        self.attributes.append(self.double_attr_name)
        self.double_attr = random.random()
        self.fh.set_attribute(self.double_attr_name, self.double_attr)

        self.str_attr_name = 'Dummy String Attribute'
        self.attributes.append(self.str_attr_name)
        str_len = random.randint(10, 1024)
        self.str_attr = ''.join(
            random.choice(string.letters) for i in xrange(str_len))
        self.fh.set_attribute(self.str_attr_name, self.str_attr)
コード例 #3
0
ファイル: TestMesh.py プロジェクト: xyuan/truchas-release
    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
コード例 #4
0
    def setUp(self):
        import os
        from Danu import Output
        import random
        import numpy

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

        self.fh = Output(self.filename, 'w')
        self.sim = self.fh.add_simulation('Test Sequence')

        seq = self.sim.get_nextSequence(0, 0.0)
        n1 = random.randint(10, 20)
        n2 = random.randint(10, 20)
        n3 = random.randint(10, 20)
        self.data = numpy.zeros((n1, n2, n3))
        i = 0
        while i < n1:
            j = 0
            while j < n2:
                k = 0
                while k < n3:
                    self.data[i][j] = random.randint(0, 10000)
                    k = k + 1
                j = j + 1
            i = i + 1

        self.data_name = 'Integer Data'
        seq.data_write(self.data_name, self.data)
コード例 #5
0
ファイル: TestMesh.py プロジェクト: xyuan/truchas-release
    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)
コード例 #6
0
ファイル: TestMesh.py プロジェクト: xyuan/truchas-release
    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)
コード例 #7
0
    def setUp(self):
        import os
        import numpy
        import random
        from Danu import Output

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

        self.fh = Output(self.filename, 'w')
        self.sim = self.fh.add_simulation('Test Simulation')

        self.data_name_1d = 'Double Data 1D'
        self.n = random.randint(1000, 10000)
        self.data_1d = numpy.random.random_sample((self.n))
        self.sim.data_write(self.data_name_1d, self.data_1d)

        self.data_name_2d = 'Double Data 2D'
        self.n1 = random.randint(100, 1000)
        self.n2 = random.randint(100, 1000)
        self.data_2d = numpy.random.random_sample((self.n1, self.n2))
        self.sim.data_write(self.data_name_2d, self.data_2d)

        self.data_name_3d = 'Double Data 3D'
        self.n1 = random.randint(10, 100)
        self.n2 = random.randint(10, 100)
        self.n3 = random.randint(10, 100)
        self.data_3d = numpy.random.random_sample((self.n1, self.n2, self.n3))
        self.sim.data_write(self.data_name_3d, self.data_3d)
コード例 #8
0
    def setUp(self):
        import os
        from Danu import Output

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

        self.fh = Output(self.filename, 'w')
コード例 #9
0
    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]
コード例 #10
0
  def setUp(self):
    import os
    from Danu import Output

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

    self.fh=Output(self.filename,'w')
    self.sim=self.fh.add_simulation('Test Probe')
コード例 #11
0
    def setUp(self):
        import os
        import numpy
        import random
        from Danu import Output

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

        self.fh = Output(self.filename, 'w')
        self.sim = self.fh.add_simulation('Test Simulation')
コード例 #12
0
    def setUp(self):
        import os
        from Danu import Output
        import random
        import numpy

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

        self.fh = Output(self.filename, 'w')
        self.sim = self.fh.add_simulation('Test Sequence')
        self.seq = self.sim.get_nextSequence(0, 0.0)
コード例 #13
0
    def setUp(self):
        import os
        import numpy
        import random
        from Danu import Output

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

        self.fh = Output(self.filename, 'w')
        self.sim = self.fh.add_simulation('Test Simulation')

        self.data_name_1d = 'Integer Data 1D'
        self.n = random.randint(1000, 10000)
        self.data_1d = numpy.zeros((self.n), numpy.int32)
        i = 0
        while i < self.n:
            self.data_1d[i] = random.randint(1, 100000)
            i = i + 1
        self.sim.data_write(self.data_name_1d, self.data_1d)

        self.data_name_2d = 'Integer Data 2D'
        self.n1 = random.randint(100, 1000)
        self.n2 = random.randint(100, 1000)
        self.data_2d = numpy.zeros((self.n1, self.n2), numpy.int32)
        i = 0
        while i < self.n1:
            j = 0
            while j < self.n2:
                self.data_2d[i][j] = random.randint(1, 100000)
                j = j + 1
            i = i + 1
        self.sim.data_write(self.data_name_2d, self.data_2d)

        self.data_name_3d = 'Integer Data 3D'
        self.n1 = random.randint(10, 100)
        self.n2 = random.randint(10, 100)
        self.n3 = random.randint(10, 100)
        self.data_3d = numpy.zeros((self.n1, self.n2, self.n3), numpy.int32)
        i = 0
        while i < self.n1:
            j = 0
            while j < self.n2:
                k = 0
                while k < self.n3:
                    self.data_3d[i][j][k] = random.randint(1, 100000)
                    k = k + 1
                j = j + 1
            i = i + 1
        self.sim.data_write(self.data_name_3d, self.data_3d)
コード例 #14
0
  def setUp(self):
    import os
    from Danu import Output
    import random
    import numpy

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

    self.fh=Output(self.filename,'w')
    self.sim=self.fh.add_simulation('Test Probe')
    self.probe_name='Dummy Probe'
    data=numpy.ones((3,10))
    Probe(self.sim,self.probe_name,data)
コード例 #15
0
ファイル: TestMesh.py プロジェクト: xyuan/truchas-release
    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]
コード例 #16
0
  def setUp(self):
    import os
    import random
    import numpy
    from Danu import Output

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

    self.fh=Output(self.filename,'w')
    self.sim=self.fh.add_simulation('Test Probe')

    # Int data
    self.idata_name='Int data'
    len=random.randint(1,7)
    num=random.randint(128,512)
    self.idata=numpy.zeros((num,len))
    self.idata_len=len
    i=0
    while i < num:
      l=0
      while l < len:
	self.idata[i][l]=random.randint(0,100000)
	l=l+1
      i=i+1
    probe=Probe(self.sim,self.idata_name,self.idata)  

    # Float data
    self.fdata_name='Float data'
    len=random.randint(1,7)
    num=random.randint(128,512)
    self.fdata=numpy.float32(numpy.random.random_sample((num,len)))
    self.fdata_len=len
    probe=Probe(self.sim,self.fdata_name,self.fdata)  

    # Double data
    self.rdata_name='Double data'
    len=random.randint(1,7)
    num=random.randint(128,512)
    self.rdata=numpy.random.random_sample((num,len))
    self.rdata_len=len
    probe=Probe(self.sim,self.rdata_name,self.rdata)  
コード例 #17
0
    def setUp(self):
        import os
        from Danu import Output
        import random
        import numpy

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

        self.fh = Output(self.filename, 'w')
        self.sim = self.fh.add_simulation('Test Sequence')

        seq = self.sim.get_nextSequence(0, 0.0)
        n = random.randint(128, 512)
        self.data = numpy.random.random_sample((n))

        self.data_name = 'Double Data'
        seq.data_write(self.data_name, self.data)
コード例 #18
0
    def setUp(self):
        import os
        from Danu import Output
        import random
        import numpy

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

        self.fh = Output(self.filename, 'w')
        self.sim = self.fh.add_simulation('Test Sequence')

        seq = self.sim.get_nextSequence(0, 0.0)
        n1 = random.randint(12, 50)
        n2 = random.randint(10, 60)
        n3 = random.randint(2, 40)
        self.data = numpy.float32(numpy.random.random_sample((n1, n2, n3)))

        self.data_name = 'Float Data'
        seq.data_write(self.data_name, self.data)
コード例 #19
0
    def setUp(self):
        import os
        from Danu import Output
        import random
        import numpy

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

        self.fh = Output(self.filename, 'w')
        self.sim = self.fh.add_simulation('Test Sequence')

        seq = self.sim.get_nextSequence(0, 0.0)
        n = random.randint(128, 512)
        self.data = numpy.zeros((n))
        i = 0
        while i < n:
            self.data[i] = random.randint(0, 10000)
            i = i + 1

        self.data_name = 'Integer Data'
        seq.data_write(self.data_name, self.data)
コード例 #20
0
 def test_open_rdwr(self):
     from Danu import FILE_ACC_RDWR
     file = Output(self.filename, 'w')
     access = file.access
     self.assertEqual(access, FILE_ACC_RDWR)
     del file
コード例 #21
0
    def setUp(self):
        self.filename = 'test-Output.h5'

        # Create the file
        fh = Output(self.filename)
        fh.close()
コード例 #22
0
    def setUp(self):

        import random

        self.filename = 'test-Output.h5'
        self.fh = Output(self.filename, 'w')
コード例 #23
0
 def test_open_dflt(self):
     file = Output(self.filename)
     del file
コード例 #24
0
 def setUp(self):
     self.filename = 'test-Output.h5'
     self.int_attr_name = 'Dummy Int Attribute'
     self.double_attr_name = 'Dummy Double Attribute'
     self.str_attr_name = 'Dummy String Attribute'
     self.fh = Output(self.filename, 'a')
コード例 #25
0
 def test_flush(self):
     file = Output(self.filename, 'a')
     file.flush()
     file.flush(1)
     del file
コード例 #26
0
 def test_open_append(self):
     from Danu import FILE_ACC_APPEND
     file = Output(self.filename, 'a')
     access = file.access
     self.assertEqual(access, FILE_ACC_APPEND)
     del file