/[escript]/trunk/ripley/test/python/run_escriptOnRipley.py
ViewVC logotype

Diff of /trunk/ripley/test/python/run_escriptOnRipley.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4764 by jfenwick, Thu Feb 27 11:02:55 2014 UTC revision 4765 by sshaw, Wed Mar 19 00:17:16 2014 UTC
# Line 26  import sys Line 26  import sys
26  import unittest  import unittest
27    
28  from esys.escript import *  from esys.escript import *
29  from esys.ripley import Rectangle, Brick  from esys.ripley import Rectangle, Brick, ripleycpp
30  from test_objects import Test_Dump, Test_SetDataPointValue, Test_saveCSV, Test_TableInterpolation  from test_objects import Test_Dump, Test_SetDataPointValue, Test_saveCSV, Test_TableInterpolation
31  from test_objects import Test_Domain, Test_GlobalMinMax, Test_Lazy  from test_objects import Test_Domain, Test_GlobalMinMax, Test_Lazy
32    
# Line 189  class Test_randomOnRipley(unittest.TestC Line 189  class Test_randomOnRipley(unittest.TestC
189          self.assertRaises(RuntimeError, RandomData, (), fs, 0, ("gaussian",20,0.1))          self.assertRaises(RuntimeError, RandomData, (), fs, 0, ("gaussian",20,0.1))
190          RandomData((2,3),fs)          RandomData((2,3),fs)
191    
192    class Test_binaryGridOnRipley(unittest.TestCase):
193        def setUp(self):
194            self.byteorder = ripleycpp.BYTEORDER_NATIVE
195            self.datatype = ripleycpp.DATATYPE_FLOAT64
196            self.ranks = getMPISizeWorld()
197    
198        def read(self, filename, FS, expected, zipped = False):
199            first = [0 for i in expected]
200            reverse = [0 for i in expected]
201            scale = [1 for i in expected]
202            if not zipped:
203                return ripleycpp._readBinaryGrid(filename, FS, (), 50000,
204                    self.byteorder, self.datatype, first, expected, scale, reverse)
205            return ripleycpp._readBinaryGridFromZipped(filename, FS, (), 50000,
206                    self.byteorder, self.datatype, first, expected, scale, reverse)
207    
208        def write(self, domain, data, filename):
209            domain.writeBinaryGrid(data, filename, self.byteorder, self.datatype)
210    
211        def adjust(self, NE, ftype):
212            if ftype == ContinuousFunction:
213                return [i+1 for i in NE]
214            return NE
215    
216        def generateUniqueData(self, FS, dim):
217            x = FS.getX()
218            if dim == 2:
219                return x[0] * 10 * (10*self.ranks-1) + x[1]
220            return x[0] * 100 * (10*self.ranks-1) + x[1] * 100 + x[2]
221    
222        def test_BrickWriteThenRead(self):
223            NE = [10*self.ranks-1, 10*self.ranks-1, 10]
224            domain = Brick(NE[0], NE[1], NE[2], d2=0)
225            for ftype in [ReducedFunction, ContinuousFunction]:
226                FS = ftype(domain)
227                original = self.generateUniqueData(FS, 3)
228                self.write(domain, original, "ref_data/tempfile")
229                result = self.read("ref_data/tempfile", FS, self.adjust(NE, ftype))
230                os.unlink("ref_data/tempfile")
231                self.assertEqual(Lsup(original - result), 0, "Data objects don't match for "+str(FS))
232    
233        def test_RectangleWriteThenRead(self):
234            NE = [10*self.ranks-1, 10]
235            domain = Rectangle(NE[0], NE[1], d1=0)
236            for ftype in [ReducedFunction, ContinuousFunction]:
237                FS = ftype(domain)
238                original = self.generateUniqueData(FS, 2)
239                self.write(domain, original, "ref_data/tempfile")
240                result = self.read("ref_data/tempfile", FS, self.adjust(NE, ftype))
241                os.unlink("ref_data/tempfile")
242                self.assertEqual(Lsup(original - result), 0, "Data objects don't match for "+str(FS))
243    
244        @unittest.skipIf(getMPISizeWorld() > 1,
245            "Skipping compressed binary grid tests due element stretching")
246        def test_BrickCompressed(self):
247            NE = [10*self.ranks-1, 10*self.ranks-1, 10]
248            domain = Brick(NE[0], NE[1], NE[2], d1=0, d2=0)
249            for filename, ftype in [("ref_data/BrickRedF%s.grid.gz", ReducedFunction),
250                    ("ref_data/BrickConF%s.grid.gz", ContinuousFunction)]:
251                FS = ftype(domain)
252                filename = filename%self.ranks
253                unzipped = self.read(filename[:-3], FS, self.adjust(NE, ftype))
254                zipped = self.read(filename, FS, self.adjust(NE, ftype), zipped=True)
255                self.assertEqual(Lsup(zipped - unzipped), 0, "Data objects don't match for "+str(FS))
256    
257        @unittest.skipIf(getMPISizeWorld() > 1,
258            "Skipping compressed binary grid tests due element stretching")
259        def test_RectangleCompressed(self):
260            NE = [10*self.ranks-1, 10]
261            domain = Rectangle(NE[0], NE[1], d1=0)
262            for filename, ftype in [("ref_data/RectRedF%s.grid.gz", ReducedFunction),
263                    ("ref_data/RectConF%s.grid.gz", ContinuousFunction)]:
264                FS = ftype(domain)
265                filename = filename%self.ranks
266                unzipped = self.read(filename[:-3], FS, self.adjust(NE, ftype))
267                zipped = self.read(filename, FS, self.adjust(NE, ftype), zipped=True)
268                self.assertEqual(Lsup(zipped - unzipped), 0, "Data objects don't match for "+str(FS))
269    
270  if __name__ == '__main__':  if __name__ == '__main__':
271      suite = unittest.TestSuite()      suite = unittest.TestSuite()
# Line 199  if __name__ == '__main__': Line 275  if __name__ == '__main__':
275      suite.addTest(unittest.makeSuite(Test_TableInterpolationOnRipley))      suite.addTest(unittest.makeSuite(Test_TableInterpolationOnRipley))
276      suite.addTest(unittest.makeSuite(Test_CSVOnRipley))      suite.addTest(unittest.makeSuite(Test_CSVOnRipley))
277      suite.addTest(unittest.makeSuite(Test_randomOnRipley))      suite.addTest(unittest.makeSuite(Test_randomOnRipley))
278        suite.addTest(unittest.makeSuite(Test_binaryGridOnRipley))
279      s=unittest.TextTestRunner(verbosity=2).run(suite)      s=unittest.TextTestRunner(verbosity=2).run(suite)
280      if not s.wasSuccessful(): sys.exit(1)      if not s.wasSuccessful(): sys.exit(1)
281    

Legend:
Removed from v.4764  
changed lines
  Added in v.4765

  ViewVC Help
Powered by ViewVC 1.1.26