class TestReadDouble3D(TestCase): 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.random.random_sample((n1, n2, n3)) self.data_name = 'Double Data' seq.data_write(self.data_name, self.data) def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def runTest(self): seq = self.sim.get_sequence('Series 1') read_data = seq.data_read(self.data_name) self.assertEqual(read_data.all(), self.data.all())
class TestUtils(TestCase): 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') self.sim = self.fh.add_simulation('Test Simulation') def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def test_data_count(self): cnt = self.sim.data_count() self.assertEqual(cnt, 0) def test_data_exists(self): data_name = 'Dataset' self.assertEqual(self.sim.data_exists(data_name), 0) def test_data_list(self): list = self.sim.data_list() self.assertEqual(len(list), 0)
class TestOutputWriteAttribute(unittest.TestCase): 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') def tearDown(self): if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def test_string_attribute(self): import random str_len = random.randint(16, 1024) self.fh.set_attribute(self.str_attr_name, os.urandom(str_len)) def test_double_attribute(self): import random self.fh.set_attribute(self.double_attr_name, random.random()) def test_int_attribute(self): import random self.fh.set_attribute(self.int_attr_name, random.randint(0, 100000))
class TestUtils(TestCase): 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') self.sim=self.fh.add_simulation('Test Simulation') def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def test_data_count(self): cnt=self.sim.data_count() self.assertEqual(cnt,0) def test_data_exists(self): data_name='Dataset' self.assertEqual(self.sim.data_exists(data_name),0) def test_data_list(self): list=self.sim.data_list() self.assertEqual(len(list),0)
class TestOutputWriteAttribute(unittest.TestCase): 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') def tearDown(self): if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def test_string_attribute(self): import random str_len = random.randint(16,1024) self.fh.set_attribute(self.str_attr_name,os.urandom(str_len)) def test_double_attribute(self): import random self.fh.set_attribute(self.double_attr_name,random.random()) def test_int_attribute(self): import random self.fh.set_attribute(self.int_attr_name,random.randint(0,100000))
class TestReadDouble3D(TestCase): 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.random.random_sample((n1,n2,n3)) self.data_name='Double Data' seq.data_write(self.data_name,self.data) def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def runTest(self): seq=self.sim.get_sequence('Series 1') read_data=seq.data_read(self.data_name) self.assertEqual(read_data.all(), self.data.all())
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)
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)
class TestCreate(TestCase): 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') def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def test_create_int(self): import numpy import random len=random.randint(1,7) num=random.randint(128,512) idata=numpy.zeros((num,len)) i=0 while i < num: l=0 while l < len: idata[i][l]=random.randint(0,100000) l=l+1 i=i+1 probe=Probe(self.sim,'Int Data',idata) def test_create_float(self): import numpy import random len=random.randint(1,7) num=random.randint(128,512) data=numpy.float32(numpy.random.random_sample((num,len))) probe=Probe(self.sim,'Float data',data) def test_create_double(self): import numpy import random len=random.randint(1,7) num=random.randint(128,512) data=numpy.random.random_sample((num,len)) probe=Probe(self.sim,'Double data',data)
class TestBasic(TestCase): 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') def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def runTest(self): import random import numpy print 'Begin basic test' try: probe=Probe() except: print 'Caught invalid number of arguments' try: probe=Probe(self.sim) except: print 'Caught invalid number of arguments' try: probe=Probe(self.sim,'Dummy Probe') except: print 'Caught invalid number of arguments' try: data=numpy.ones((10)) probe=Probe(self.sim,'Dummy Probe',data) except: print 'Caught incorrect argument type' # Simple constructor and delete len=2 num=20 data=numpy.ones((num,len)) probe= Probe(self.sim,'Dummy Probe',data) del probe probe=self.sim.probe_open('Dummy Probe') self.assertEqual(probe.length(),len) self.assertEqual(probe.number(),num)
class TestAttributes(TestCase): 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) def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def runTest(self): import random probe=self.sim.probe_open(self.probe_name) # integers int_name='Integer Attribute' try: probe.get_attribute(int_name) except: print 'Caught DNE attribute' else: raise RuntimeError, 'Failed to catch DNE error' int_attr=random.randint(1,102400) probe.set_attribute(int_name,int_attr) read_attr=probe.get_attribute(int_name) self.assertEqual(int_attr,read_attr) # double dbl_name='Double Attribute' dbl_attr=random.random() probe.set_attribute(dbl_name,dbl_attr) read_dbl=probe.get_attribute(dbl_name) self.assertEqual(read_dbl,dbl_attr) # string str_name='Chacracter Name Attribute' str_attr='ajksdweiouamnv 9iajemn oiwiwe' probe.set_attribute(str_name,str_attr) string=probe.get_attribute(str_name) self.assertEqual(string,str_attr)
class TestAttributes(TestCase): 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) def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def runTest(self): import random seq=self.seq # integers int_name='Integer Attribute' try: seq.get_attribute(int_name) except: print 'Caught DNE attribute' else: raise RuntimeError, 'Failed to catch DNE error' int_attr=random.randint(1,102400) seq.set_attribute(int_name,int_attr) read_attr=seq.get_attribute(int_name) self.assertEqual(int_attr,read_attr) # double dbl_name='Double Attribute' dbl_attr=random.random() seq.set_attribute(dbl_name,dbl_attr) read_dbl=seq.get_attribute(dbl_name) self.assertEqual(read_dbl,dbl_attr) # string str_name='Chacracter Name Attribute' str_attr='ajksdweiouamnv 9iajemn oiwiwe' seq.set_attribute(str_name,str_attr) string=seq.get_attribute(str_name) self.assertEqual(string,str_attr)
class TestAttributes(TestCase): 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) def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def runTest(self): import random seq = self.seq # integers int_name = 'Integer Attribute' try: seq.get_attribute(int_name) except: print 'Caught DNE attribute' else: raise RuntimeError, 'Failed to catch DNE error' int_attr = random.randint(1, 102400) seq.set_attribute(int_name, int_attr) read_attr = seq.get_attribute(int_name) self.assertEqual(int_attr, read_attr) # double dbl_name = 'Double Attribute' dbl_attr = random.random() seq.set_attribute(dbl_name, dbl_attr) read_dbl = seq.get_attribute(dbl_name) self.assertEqual(read_dbl, dbl_attr) # string str_name = 'Chacracter Name Attribute' str_attr = 'ajksdweiouamnv 9iajemn oiwiwe' seq.set_attribute(str_name, str_attr) string = seq.get_attribute(str_name) self.assertEqual(string, str_attr)
class TestBasic(TestCase): def setUp(self): import os from Danu import Output 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') def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def runTest(self): import random import numpy print 'Begin basic test' try: seq=Sequence() except: print 'Caught invalid number of arguments' try: seq=Sequence(self.sim) except: print 'Caught invalid name or id' try: seq=Sequence(self.sim,'Series DNE') except: print 'Caught id group that does not exist' try: seq=Sequence(self.sim,seriesname='Series 10') except: print 'Caught group name that does not exist' cycle=random.randint(0,10) time=numpy.float64(random.randint(0,1000)) seq=self.sim.get_nextSequence(cycle,time) id=seq.id del seq seq_name=self.sim.get_sequence_name(id) new_seq=Sequence(self.sim,seq_name) del new_seq
class TestBasic(TestCase): def setUp(self): import os from Danu import Output 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') def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def runTest(self): import random import numpy print 'Begin basic test' try: seq = Sequence() except: print 'Caught invalid number of arguments' try: seq = Sequence(self.sim) except: print 'Caught invalid name or id' try: seq = Sequence(self.sim, 'Series DNE') except: print 'Caught id group that does not exist' try: seq = Sequence(self.sim, seriesname='Series 10') except: print 'Caught group name that does not exist' cycle = random.randint(0, 10) time = numpy.float64(random.randint(0, 1000)) seq = self.sim.get_nextSequence(cycle, time) id = seq.id del seq seq_name = self.sim.get_sequence_name(id) new_seq = Sequence(self.sim, seq_name) del new_seq
class TestOutputReadAttribute(unittest.TestCase): 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) def tearDown(self): if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def test_string_attribute(self): test_str = self.fh.get_attribute(self.str_attr_name) self.assertEqual(test_str, self.str_attr) def test_double_attribute(self): test_double = self.fh.get_attribute(self.double_attr_name) self.assertEqual(test_double, self.double_attr) def test_int_attribute(self): test_int = self.fh.get_attribute(self.int_attr_name) self.assertEqual(test_int, self.int_attr) def test_attributes(self): attributes = self.fh.attributes() for attr in self.attributes: if attr not in attributes: TestCase.fail('Failed to read attributes correctly')
class TestOutputReadAttribute(unittest.TestCase): 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) def tearDown(self): if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def test_string_attribute(self): test_str = self.fh.get_attribute(self.str_attr_name) self.assertEqual(test_str,self.str_attr) def test_double_attribute(self): test_double = self.fh.get_attribute(self.double_attr_name) self.assertEqual(test_double,self.double_attr) def test_int_attribute(self): test_int = self.fh.get_attribute(self.int_attr_name) self.assertEqual(test_int,self.int_attr) def test_attributes(self): attributes = self.fh.attributes() for attr in self.attributes: if attr not in attributes: TestCase.fail('Failed to read attributes correctly')
class TestDataReadFloat(TestCase): 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 = 'Float Data 1D' self.n = random.randint(1000, 10000) self.data_1d = numpy.float32(numpy.random.random_sample((self.n))) self.sim.data_write(self.data_name_1d, self.data_1d) self.data_name_2d = 'Float Data 2D' self.n1 = random.randint(100, 1000) self.n2 = random.randint(100, 1000) self.data_2d = numpy.float32( numpy.random.random_sample((self.n1, self.n2))) self.sim.data_write(self.data_name_2d, self.data_2d) self.data_name_3d = 'Float Data 3D' self.n1 = random.randint(10, 100) self.n2 = random.randint(10, 100) self.n3 = random.randint(10, 100) self.data_3d = numpy.float32( numpy.random.random_sample((self.n1, self.n2, self.n3))) self.sim.data_write(self.data_name_3d, self.data_3d) def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() def runTest(self): data1 = self.sim.data_read(self.data_name_1d) self.assertEqual(data1.all(), self.data_1d.all()) data2 = self.sim.data_read(self.data_name_2d) self.assertEqual(data2.all(), self.data_2d.all()) data3 = self.sim.data_read(self.data_name_3d) self.assertEqual(data3.all(), self.data_3d.all())
class TestDataReadDouble(TestCase): 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) def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() def runTest(self): data1=self.sim.data_read(self.data_name_1d) self.assertEqual(data1.all(),self.data_1d.all()) data2=self.sim.data_read(self.data_name_2d) self.assertEqual(data2.all(),self.data_2d.all()) data3=self.sim.data_read(self.data_name_3d) self.assertEqual(data3.all(),self.data_3d.all())
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()
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()
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)
class TestReadInteger3D(TestCase): 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) def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def runTest(self): seq=self.sim.get_sequence('Series 1') read_data=seq.data_read(self.data_name) self.assertEqual(read_data.all(), self.data.all())
class TestReadInteger3D(TestCase): 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) def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def runTest(self): seq = self.sim.get_sequence('Series 1') read_data = seq.data_read(self.data_name) self.assertEqual(read_data.all(), self.data.all())
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)
class TestReadInteger1D(TestCase): 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) def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def runTest(self): seq=self.sim.get_sequence('Series 1') try: read_data=seq.data_read('Data DNE') except: print 'Caught Data set that did not exist' read_data=seq.data_read(self.data_name) self.assertEqual(read_data.all(), self.data.all())
class TestReadInteger1D(TestCase): 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) def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def runTest(self): seq = self.sim.get_sequence('Series 1') try: read_data = seq.data_read('Data DNE') except: print 'Caught Data set that did not exist' read_data = seq.data_read(self.data_name) self.assertEqual(read_data.all(), self.data.all())
def setUp(self): self.filename = 'test-Output.h5' # Create the file fh = Output(self.filename) fh.close()
class TestSequence(TestCase): 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') def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() def test_basic(self): from Danu import Sequence import numpy import random cycle=random.randint(10,100) time=numpy.random.random_sample((1))[0] seq=self.sim.get_nextSequence(cycle,time); print seq.id print seq.time print seq.cycle def test_sequence_count(self): import random import numpy cnt=self.sim.sequence_count() self.assertEqual(cnt,0,'Failed to return zero count') gen_cnt=random.randint(1,100) cycle=1 i=1 time=numpy.random.random_sample((1))[0] while i <= gen_cnt: time=time+numpy.random.random_sample((1))[0] seq=self.sim.get_nextSequence(cycle,time) del seq i=i+1 cnt=self.sim.sequence_count() self.assertEqual(cnt,gen_cnt) def test_sequence_exists(self): import random import numpy cycle=1 time=numpy.random.random_sample((1))[0] flag=self.sim.sequence_exists('Series DNE') self.assertEqual(flag,0,'Failed to return false status') seq=self.sim.get_nextSequence(cycle,time) id=seq.id del seq seq_name=self.sim.get_sequence_name(id) flag=self.sim.sequence_exists(seq_name) self.assertEqual(flag,1,'Failed to return true status') def test_sequence_list(self): import random import numpy list=self.sim.sequence_list() self.assertEqual(len(list),0,'Failed to return empty list') gen_cnt=random.randint(1,100) cycle=1 i=1 time=numpy.random.random_sample((1))[0] names=[] while i <= gen_cnt: time=time+numpy.random.random_sample((1))[0] seq=self.sim.get_nextSequence(cycle,time) seq_name=self.sim.get_sequence_name(seq.id) names.append(seq_name) del seq i=i+1 list=self.sim.sequence_list() self.assertEqual(len(list),gen_cnt,'Failed to return correct list size') for name in names: self.assertTrue(name in list)
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)
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)
class TestDataReadInteger(TestCase): 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) def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() def runTest(self): try: data = self.sim.data_read('Data DNE') except: print 'Caught bad non-series data name' else: raise RuntimeError, 'Failed to catch DNE dataset name' data1 = self.sim.data_read(self.data_name_1d) self.assertEqual(data1.all(), self.data_1d.all()) data2 = self.sim.data_read(self.data_name_2d) self.assertEqual(data2.all(), self.data_2d.all()) data3 = self.sim.data_read(self.data_name_3d) self.assertEqual(data3.all(), self.data_3d.all())
class TestOutputSimulations(unittest.TestCase): def setUp(self): import random self.filename = 'test-Output.h5' self.fh = Output(self.filename, 'w') def tearDown(self): if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def test_sim_list(self): import random list = self.fh.simulation_list() self.assertEqual(len(list), 0) n = random.randint(10, 20) i = 0 save_names = [] while i < n: sim_name = 'Simulation ' + str(i) save_names.insert(i, sim_name) self.fh.add_simulation(sim_name) i = i + 1 list = self.fh.simulation_list() self.assertEqual(len(list), n) for name in save_names: if not name in list: raise RuntimeError, 'Name not found in list' def test_add_simulation(self): sim_name = 'New Simulation' self.fh.add_simulation(sim_name) def test_sim_count(self): import random sim_count = self.fh.simulation_count() self.assertEqual(sim_count, 0) n = random.randint(10, 20) i = 0 while i < n: sim_name = 'Simulation ' + str(i) self.fh.add_simulation(sim_name) i = i + 1 cnt = self.fh.simulation_count() self.assertEqual(cnt, n) def test_sim_exists(self): sim_name = 'Sim DNE' self.assertEqual(self.fh.simulation_exists(sim_name), 0) sim_name = 'Smin Does Exist' self.fh.add_simulation(sim_name) self.assertEqual(self.fh.simulation_exists(sim_name), 1) def test_get_simulation(self): import Danu sim_name = 'Fetchme' try: sim = self.get_simulation(sim_name) except: print 'Caught get_simulation DNE test' else: raise RuntimeError, 'Failed to raise an error' self.fh.add_simulation(sim_name) sim = self.fh.get_simulation(sim_name) if not isinstance(sim, Danu.Simulation): raise RuntimeError, 'Failed to return simulation object'
class TestWriteData(TestCase): 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') self.sim=self.fh.add_simulation('Test Simulation') def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() def test_write_int(self): import random import numpy data_name='Data Set 1D Integer' nsize=random.randint(1000,100000) data=numpy.zeros((nsize),numpy.int32) i=0 while i < nsize: data[i]=random.randint(0,100000) i=i+1 self.sim.data_write(data_name,data) del data data_name='Data Set 2D Integer' n1=random.randint(100,1000) n2=random.randint(100,1000) data=numpy.zeros((n1,n2),numpy.int32) i=0 j=0 while i < n1: while j < n2: data[i][j]=random.randint(0,100000) j=j+1 i=i+1 self.sim.data_write(data_name,data) del data data_name='Data Set 3D Integer' n1=random.randint(100,1000) n2=random.randint(100,1000) n3=random.randint(100,1000) data=numpy.zeros((n1,n2,n3),numpy.int32) i=0 j=0 k=0 while i < n1: while j < n2: while k < n3: data[i][j][k]=random.randint(0,100000) k=k+1 j=j+1 i=i+1 self.sim.data_write(data_name,data) del data def test_write_double(self): import random import numpy data_name='Data Set 1D Double' nsize=random.randint(1000,100000) data=numpy.random.random_sample((nsize)) self.sim.data_write(data_name,data) del data data_name='Data Set 2D Double' n1=random.randint(100,1000) n2=random.randint(100,1000) data=numpy.random.random_sample((n1,n2)) self.sim.data_write(data_name,data) del data data_name='Data Set 3D Double' n1=random.randint(100,1000) n2=random.randint(100,1000) n3=random.randint(100,1000) data=numpy.random.random_sample((n1,n2,n3)) self.sim.data_write(data_name,data) del data def test_write_float(self): import random import numpy data_name='Data Set 1D Float' nsize=random.randint(1000,100000) data=numpy.float32(numpy.random.random_sample((nsize))) self.sim.data_write(data_name,data) del data data_name='Data Set 2D Float' n1=random.randint(100,1000) n2=random.randint(100,1000) data=numpy.float32(numpy.random.random_sample((n1,n2))) self.sim.data_write(data_name,data) del data data_name='Data Set 3D Float' n1=random.randint(10,100) n2=random.randint(10,100) n3=random.randint(10,100) data=numpy.float32(numpy.random.random_sample((n1,n2,n3))) self.sim.data_write(data_name,data) del data
class TestWriteData(TestCase): 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') self.sim = self.fh.add_simulation('Test Simulation') def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() def test_write_int(self): import random import numpy data_name = 'Data Set 1D Integer' nsize = random.randint(1000, 100000) data = numpy.zeros((nsize), numpy.int32) i = 0 while i < nsize: data[i] = random.randint(0, 100000) i = i + 1 self.sim.data_write(data_name, data) del data data_name = 'Data Set 2D Integer' n1 = random.randint(100, 1000) n2 = random.randint(100, 1000) data = numpy.zeros((n1, n2), numpy.int32) i = 0 j = 0 while i < n1: while j < n2: data[i][j] = random.randint(0, 100000) j = j + 1 i = i + 1 self.sim.data_write(data_name, data) del data data_name = 'Data Set 3D Integer' n1 = random.randint(100, 1000) n2 = random.randint(100, 1000) n3 = random.randint(100, 1000) data = numpy.zeros((n1, n2, n3), numpy.int32) i = 0 j = 0 k = 0 while i < n1: while j < n2: while k < n3: data[i][j][k] = random.randint(0, 100000) k = k + 1 j = j + 1 i = i + 1 self.sim.data_write(data_name, data) del data def test_write_double(self): import random import numpy data_name = 'Data Set 1D Double' nsize = random.randint(1000, 100000) data = numpy.random.random_sample((nsize)) self.sim.data_write(data_name, data) del data data_name = 'Data Set 2D Double' n1 = random.randint(100, 1000) n2 = random.randint(100, 1000) data = numpy.random.random_sample((n1, n2)) self.sim.data_write(data_name, data) del data data_name = 'Data Set 3D Double' n1 = random.randint(100, 1000) n2 = random.randint(100, 1000) n3 = random.randint(100, 1000) data = numpy.random.random_sample((n1, n2, n3)) self.sim.data_write(data_name, data) del data def test_write_float(self): import random import numpy data_name = 'Data Set 1D Float' nsize = random.randint(1000, 100000) data = numpy.float32(numpy.random.random_sample((nsize))) self.sim.data_write(data_name, data) del data data_name = 'Data Set 2D Float' n1 = random.randint(100, 1000) n2 = random.randint(100, 1000) data = numpy.float32(numpy.random.random_sample((n1, n2))) self.sim.data_write(data_name, data) del data data_name = 'Data Set 3D Float' n1 = random.randint(10, 100) n2 = random.randint(10, 100) n3 = random.randint(10, 100) data = numpy.float32(numpy.random.random_sample((n1, n2, n3))) self.sim.data_write(data_name, data) del data
class TestReadData(TestCase): 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') # Int data self.idata_name='Int data' len=random.randint(1,7) num=random.randint(128,512) self.idata=numpy.zeros((num,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))) 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)) probe=Probe(self.sim,self.rdata_name,self.rdata) def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def test_read_int(self): probe=self.sim.probe_open(self.idata_name) read_data=probe.read() self.assertEqual(read_data.all(), self.idata.all()) def test_read_float(self): probe=self.sim.probe_open(self.fdata_name) read_data=probe.read() self.assertEqual(read_data.all(), self.fdata.all()) def test_read_double(self): probe=self.sim.probe_open(self.rdata_name) read_data=probe.read() self.assertEqual(read_data.all(), self.rdata.all())
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')
class TestOutputSimulations(unittest.TestCase): def setUp(self): import random self.filename = 'test-Output.h5' self.fh = Output(self.filename,'w') def tearDown(self): if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def test_sim_list(self): import random list=self.fh.simulation_list() self.assertEqual(len(list),0) n=random.randint(10,20) i=0 save_names=[] while i < n: sim_name='Simulation ' + str(i) save_names.insert(i,sim_name) self.fh.add_simulation(sim_name) i=i+1 list=self.fh.simulation_list() self.assertEqual(len(list),n) for name in save_names: if not name in list: raise RuntimeError, 'Name not found in list' def test_add_simulation(self): sim_name='New Simulation' self.fh.add_simulation(sim_name) def test_sim_count(self): import random sim_count=self.fh.simulation_count() self.assertEqual(sim_count,0) n=random.randint(10,20) i=0 while i < n: sim_name='Simulation ' + str(i) self.fh.add_simulation(sim_name) i=i+1 cnt=self.fh.simulation_count() self.assertEqual(cnt,n) def test_sim_exists(self): sim_name='Sim DNE' self.assertEqual(self.fh.simulation_exists(sim_name),0) sim_name='Smin Does Exist' self.fh.add_simulation(sim_name) self.assertEqual(self.fh.simulation_exists(sim_name),1) def test_get_simulation(self): import Danu sim_name='Fetchme' try: sim=self.get_simulation(sim_name) except: print 'Caught get_simulation DNE test' else: raise RuntimeError, 'Failed to raise an error' self.fh.add_simulation(sim_name) sim=self.fh.get_simulation(sim_name) if not isinstance(sim,Danu.Simulation): raise RuntimeError, 'Failed to return simulation object'
def setUp(self): self.filename = 'test-Output.h5' # Create the file fh = Output(self.filename) fh.close()
class TestWriteData(TestCase): def setUp(self): import os from Danu import Output 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') def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def test_write_1D(self): import numpy import random seq=self.sim.get_nextSequence(0,0.0) size=random.randint(128,512) idata=numpy.zeros((size)) i=0 while i < size: idata[i]=random.randint(0,100000) i=i+1 seq.data_write('Integer Data',idata) size=random.randint(128,512) data=numpy.float32(numpy.random.random_sample((size))) seq.data_write('Float Data',data) size=random.randint(128,512) data=numpy.random.random_sample((size)) seq.data_write('Double Data',data) def test_write_2D(self): import numpy import random seq=self.sim.get_nextSequence(0,0.0) n1=random.randint(10,128) n2=random.randint(10,128) idata=numpy.zeros((n1,n2)) i=0 while i < n1: j=0 while j < n2: idata[i][j]=random.randint(1,1000) j=j+1 i=i+1 seq.data_write('Integer Data',idata) data=numpy.float32(numpy.random.random_sample((n1,n2))) seq.data_write('Float Data',data) data=numpy.random.random_sample((n1,n2)) seq.data_write('Double Data',data) def test_write_3D(self): import numpy import random seq=self.sim.get_nextSequence(0,0.0) n1=random.randint(1,20) n2=random.randint(1,20) n3=random.randint(1,20) idata=numpy.zeros((n1,n2,n3)) i=0 while i < n1: j=0 while j < n2: k=0 while k < n3: idata[i][j][k]=random.randint(1,1000) k=k+1 j=j+1 i=i+1 seq.data_write('Integer Data',idata) data=numpy.float32(numpy.random.random_sample((n1,n2,n3))) seq.data_write('Float Data',data) data=numpy.random.random_sample((n1,n2,n3)) seq.data_write('Double Data',data)
class TestSequence(TestCase): 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') def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() def test_basic(self): from Danu import Sequence import numpy import random cycle = random.randint(10, 100) time = numpy.random.random_sample((1))[0] seq = self.sim.get_nextSequence(cycle, time) print seq.id print seq.time print seq.cycle def test_sequence_count(self): import random import numpy cnt = self.sim.sequence_count() self.assertEqual(cnt, 0, 'Failed to return zero count') gen_cnt = random.randint(1, 100) cycle = 1 i = 1 time = numpy.random.random_sample((1))[0] while i <= gen_cnt: time = time + numpy.random.random_sample((1))[0] seq = self.sim.get_nextSequence(cycle, time) del seq i = i + 1 cnt = self.sim.sequence_count() self.assertEqual(cnt, gen_cnt) def test_sequence_exists(self): import random import numpy cycle = 1 time = numpy.random.random_sample((1))[0] flag = self.sim.sequence_exists('Series DNE') self.assertEqual(flag, 0, 'Failed to return false status') seq = self.sim.get_nextSequence(cycle, time) id = seq.id del seq seq_name = self.sim.get_sequence_name(id) flag = self.sim.sequence_exists(seq_name) self.assertEqual(flag, 1, 'Failed to return true status') def test_sequence_list(self): import random import numpy list = self.sim.sequence_list() self.assertEqual(len(list), 0, 'Failed to return empty list') gen_cnt = random.randint(1, 100) cycle = 1 i = 1 time = numpy.random.random_sample((1))[0] names = [] while i <= gen_cnt: time = time + numpy.random.random_sample((1))[0] seq = self.sim.get_nextSequence(cycle, time) seq_name = self.sim.get_sequence_name(seq.id) names.append(seq_name) del seq i = i + 1 list = self.sim.sequence_list() self.assertEqual(len(list), gen_cnt, 'Failed to return correct list size') for name in names: self.assertTrue(name in list)
class TestDataReadInteger(TestCase): 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) def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() def runTest(self): try: data=self.sim.data_read('Data DNE') except: print 'Caught bad non-series data name' else: raise RuntimeError, 'Failed to catch DNE dataset name' data1=self.sim.data_read(self.data_name_1d) self.assertEqual(data1.all(),self.data_1d.all()) data2=self.sim.data_read(self.data_name_2d) self.assertEqual(data2.all(),self.data_2d.all()) data3=self.sim.data_read(self.data_name_3d) self.assertEqual(data3.all(),self.data_3d.all())
class TestWriteData(TestCase): def setUp(self): import os from Danu import Output 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') def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def test_write_1D(self): import numpy import random seq = self.sim.get_nextSequence(0, 0.0) size = random.randint(128, 512) idata = numpy.zeros((size)) i = 0 while i < size: idata[i] = random.randint(0, 100000) i = i + 1 seq.data_write('Integer Data', idata) size = random.randint(128, 512) data = numpy.float32(numpy.random.random_sample((size))) seq.data_write('Float Data', data) size = random.randint(128, 512) data = numpy.random.random_sample((size)) seq.data_write('Double Data', data) def test_write_2D(self): import numpy import random seq = self.sim.get_nextSequence(0, 0.0) n1 = random.randint(10, 128) n2 = random.randint(10, 128) idata = numpy.zeros((n1, n2)) i = 0 while i < n1: j = 0 while j < n2: idata[i][j] = random.randint(1, 1000) j = j + 1 i = i + 1 seq.data_write('Integer Data', idata) data = numpy.float32(numpy.random.random_sample((n1, n2))) seq.data_write('Float Data', data) data = numpy.random.random_sample((n1, n2)) seq.data_write('Double Data', data) def test_write_3D(self): import numpy import random seq = self.sim.get_nextSequence(0, 0.0) n1 = random.randint(1, 20) n2 = random.randint(1, 20) n3 = random.randint(1, 20) idata = numpy.zeros((n1, n2, n3)) i = 0 while i < n1: j = 0 while j < n2: k = 0 while k < n3: idata[i][j][k] = random.randint(1, 1000) k = k + 1 j = j + 1 i = i + 1 seq.data_write('Integer Data', idata) data = numpy.float32(numpy.random.random_sample((n1, n2, n3))) seq.data_write('Float Data', data) data = numpy.random.random_sample((n1, n2, n3)) seq.data_write('Double Data', data)
class TestWrite(TestCase): 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) def tearDown(self): import os if os.path.exists(self.filename): self.fh.close() os.remove(self.filename) def test_write_int(self): import numpy import random len=self.idata_len + 1 num=random.randint(128,512) idata=numpy.zeros((num,len)) probe=self.sim.probe_open(self.idata_name) try: probe.write(idata) except: print 'Caught error when trying to write mis-sized data' idata=numpy.zeros((num,self.idata_len)) probe.write(idata) def test_write_float(self): import numpy import random len=self.fdata_len+1 num=random.randint(128,512) data=numpy.float32(numpy.random.random_sample((num,len))) probe=self.sim.probe_open(self.fdata_name) try: probe.write(data) except: print 'Caught error when trying to write mis-sized data' data=numpy.float32(numpy.random.random_sample((num,self.fdata_len))) probe.write(data) def test_write_double(self): import numpy import random len=self.rdata_len+1 num=random.randint(128,512) data=numpy.random.random_sample((num,len)) probe=self.sim.probe_open(self.rdata_name) try: probe.write(data) except: print 'Caught mis-sized data array' len=self.rdata_len data=numpy.random.random_sample((num,len)) probe.write(data)
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')
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' def test_coordinates_1D(self): import numpy mesh=self.fh.get_mesh(self.valid_mesh_1D[0]) coordinates=mesh.coordinates() self.assertEqual(len(coordinates),1) nnodes=coordinates[0].size idx=0 for array in coordinates: read_array=mesh.read_coordinates(idx,nnodes) self.assertEqual(read_array.all(),array.all()) def test_coordinates_2D(self): import numpy mesh=self.fh.get_mesh(self.valid_mesh_2D[1]) coordinates=mesh.coordinates() self.assertEqual(len(coordinates),2) nnodes=coordinates[0].size idx=0 for array in coordinates: read_array=mesh.read_coordinates(idx,nnodes) self.assertEqual(read_array.all(),array.all()) def test_coordinates_3D(self): import numpy mesh=self.fh.get_mesh(self.valid_mesh_3D[1]) coordinates=mesh.coordinates() self.assertEqual(len(coordinates),3) nnodes=coordinates[0].size idx=0 for array in coordinates: read_array=mesh.read_coordinates(idx,nnodes) self.assertEqual(read_array.all(),array.all())
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' def test_coordinates_1D(self): import numpy mesh = self.fh.get_mesh(self.valid_mesh_1D[0]) coordinates = mesh.coordinates() self.assertEqual(len(coordinates), 1) nnodes = coordinates[0].size idx = 0 for array in coordinates: read_array = mesh.read_coordinates(idx, nnodes) self.assertEqual(read_array.all(), array.all()) def test_coordinates_2D(self): import numpy mesh = self.fh.get_mesh(self.valid_mesh_2D[1]) coordinates = mesh.coordinates() self.assertEqual(len(coordinates), 2) nnodes = coordinates[0].size idx = 0 for array in coordinates: read_array = mesh.read_coordinates(idx, nnodes) self.assertEqual(read_array.all(), array.all()) def test_coordinates_3D(self): import numpy mesh = self.fh.get_mesh(self.valid_mesh_3D[1]) coordinates = mesh.coordinates() self.assertEqual(len(coordinates), 3) nnodes = coordinates[0].size idx = 0 for array in coordinates: read_array = mesh.read_coordinates(idx, nnodes) self.assertEqual(read_array.all(), array.all())