/[escript]/branches/trilinos_from_5897/dudley/test/python/run_inputOutput.py
ViewVC logotype

Contents of /branches/trilinos_from_5897/dudley/test/python/run_inputOutput.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6079 - (show annotations)
Mon Mar 21 12:22:38 2016 UTC (2 years, 10 months ago) by caltinay
File MIME type: text/x-python
File size: 8172 byte(s)
Big commit - making dudley much more like finley to make it more
managable. Fixed quite a few issues that had been fixed in finley.
Disposed of all ReducedNode/ReducedDOF entities that dudley never supported.
Compiles and passes tests.

1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2016 by The University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 from __future__ import print_function, division
18
19 __copyright__="""Copyright (c) 2003-2016 by The University of Queensland
20 http://www.uq.edu.au
21 Primary Business: Queensland, Australia"""
22 __license__="""Licensed under the Open Software License version 3.0
23 http://www.opensource.org/licenses/osl-3.0.php"""
24 __url__="https://launchpad.net/escript-finley"
25
26 """
27 Test suite for input and output of meshes and data objects
28
29 :remark:
30
31 :var __author__: name of author
32 :var __licence__: licence agreement
33 :var __url__: url entry point on documentation
34 :var __version__: version
35 :var __date__: date of the version
36 """
37
38 import esys.escriptcore.utestselect as unittest, sys
39 from esys.escriptcore.testing import *
40 from esys.escript import *
41 from esys.dudley import Rectangle, Brick, LoadMesh, ReadMesh, ReadGmsh
42
43 try:
44 DUDLEY_WORKDIR=os.environ['DUDLEY_WORKDIR']
45 except KeyError:
46 DUDLEY_WORKDIR='.'
47
48 try:
49 DUDLEY_TEST_DATA=os.environ['DUDLEY_TEST_DATA']
50 except KeyError:
51 DUDLEY_TEST_DATA='.'
52
53 DUDLEY_TEST_MESH_PATH=os.path.join(DUDLEY_TEST_DATA,"data_meshes")
54
55 REL_TOL=1.e-6
56
57 # Number of elements scales up with number of MPI processes
58 NE0 = 7 * getMPISizeWorld()
59 NE1 = 11
60 NE2 = 5
61
62 class Test_InputOutput(unittest.TestCase):
63
64 # Check that two domains are equal using Fourier integrals
65 # We cannot compare the X coordinates since they are on different domains
66 def domainsEqual(self, m1, m2, nft=100):
67 self.assertTrue(m1.getDim() == m2.getDim(), "Dimensions differ")
68 self.assertTrue(m1.getNumDataPointsGlobal() == m2.getNumDataPointsGlobal(), "Num data points differ")
69 for tagName in m1.showTagNames().split(", "):
70 self.assertTrue(m2.isValidTagName(tagName), "m1 has a tag '%s' not present in m2" % tagName)
71 for tagName in m2.showTagNames().split(", "):
72 self.assertTrue(m1.isValidTagName(tagName), "m2 has a tag '%s' not present in m1" % tagName)
73 self.assertTrue(m1.getTag(tagName) == m2.getTag(tagName), "values of tag '%s' differ" % tagName)
74 for fs in ["Solution", "ReducedSolution", "Function", "ReducedFunction", "ContinuousFunction", "ReducedContinuousFunction"]:
75 fs1 = eval("%s(m1)" % fs)
76 fs2 = eval("%s(m2)" % fs)
77 x1 = fs1.getX()
78 x2 = fs2.getX()
79 for n in range(1, nft+1):
80 integ1 = integrate(sin(n*x1))
81 integ2 = integrate(sin(n*x2))
82 self.assertTrue(Lsup(abs(integ1-integ2)) <= REL_TOL, "integrals for n=%d differ" % n)
83 return True
84
85 # Does optimize=True change Rectangle for order=1?
86 def test_Rectangle_optimize_order1(self):
87 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
88 mydomain2 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=True)
89 self.domainsEqual(mydomain1, mydomain2)
90
91 # Does optimize=True change Rectangle for order=-1?
92 def test_Rectangle_optimize_macro(self):
93 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=-1, l0=1., l1=1., optimize=False)
94 mydomain2 = Rectangle(n0=NE0, n1=NE1, order=-1, l0=1., l1=1., optimize=True)
95 self.domainsEqual(mydomain1, mydomain2)
96
97 # Does optimize=True change Brick for order=1?
98 def test_Brick_optimize_order1(self):
99 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False)
100 mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=True)
101 self.domainsEqual(mydomain1, mydomain2)
102
103 # Does optimize=True change Brick for order=-1?
104 def test_Brick_optimize_macro(self):
105 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=-1, l0=1., l1=1., l2=1., optimize=False)
106 mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=-1, l0=1., l1=1., l2=1., optimize=True)
107 self.domainsEqual(mydomain1, mydomain2)
108
109 @unittest.skipIf(not loadIsConfigured(), "loading not configured")
110 def test_data_dump_to_NetCDF_rectangle(self):
111 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
112 d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
113 d1.expand()
114 dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.dump.nc")
115 d1.dump(dumpfile)
116 d2=load(dumpfile, mydomain1)
117 self.assertTrue(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
118
119 @unittest.skipIf(not loadIsConfigured(), "loading not configured")
120 def test_data_dump_to_NetCDF_brick(self):
121 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False)
122 d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
123 d1.expand()
124 dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.dump.nc")
125 d1.dump(dumpfile)
126 d2=load(dumpfile, mydomain1)
127 self.assertTrue(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
128
129 @unittest.skipIf(not loadIsConfigured(), "loading not configured")
130 def test_mesh_dump_to_NetCDF_rectangle(self):
131 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
132 dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.mesh.nc")
133 mydomain1.dump(dumpfile)
134 mydomain2=LoadMesh(dumpfile)
135 self.domainsEqual(mydomain1, mydomain2)
136
137 @unittest.skipIf(getEscriptParamInt('MPIBUILD', 0), "MPI build")
138 def test_gmshTags(self):
139 dom=ReadGmsh(os.path.join(DUDLEY_TEST_MESH_PATH, "tagtest.msh"),2)
140 tags=dom.showTagNames().split(', ')
141 self.assertEqual(tags,['tag1','tag2', 'tag3'],'error with tags')
142 self.assertEqual(dom.getTag('tag1'),1,'error with tag1')
143 self.assertEqual(dom.getTag('tag2'),2,'error with tag2')
144 self.assertEqual(dom.getTag('tag3'),3,'error with tag3')
145 self.assertRaises(ValueError, dom.getTag, 'tag4')
146
147 def test_flyTags(self):
148 dom=ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH, "tagtest2.fly"))
149 tags=sorted(dom.showTagNames().split(', '))
150 self.assertEqual(tags,sorted(['tag1', 'tag2', 'tag3', 'tag4', 'All']))
151 self.assertEqual(dom.getTag('tag1'),5,'error with tag1')
152 self.assertEqual(dom.getTag('tag2'),8,'error with tag2,')
153 self.assertEqual(dom.getTag('tag3'),6,'error with tag3')
154 self.assertEqual(dom.getTag('tag4'),7,'error with tag4')
155 self.assertEqual(dom.getTag('All'),10,'error with All')
156 self.assertRaises(ValueError, dom.getTag, 'tag6')
157
158 @unittest.skipIf(not loadIsConfigured(), "loading not configured")
159 def test_mesh_dump_to_NetCDF_brick(self):
160 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False)
161 dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.mesh.nc")
162 mydomain1.dump(dumpfile)
163 mydomain2=LoadMesh(dumpfile)
164 self.domainsEqual(mydomain1, mydomain2)
165
166 @unittest.skipIf(getMPISizeWorld() >= 16, "Too many MPI processes")
167 def fixme_test_mesh_read_rectangle_from_dudley_file(self):
168 mydomain1 = Rectangle(n0=8, n1=10, order=1, l0=1., l1=1., optimize=False)
169 mydomain2 = ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH,"rectangle_8x10.fly"))
170 self.domainsEqual(mydomain1, mydomain2)
171
172 @unittest.skipIf(getMPISizeWorld() >= 16, "Too many MPI processes")
173 def fixme_test_mesh_read_brick_from_dudley_file(self):
174 mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False)
175 mydomain2 = ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH,"brick_8x10x12.fly"))
176 self.domainsEqual(mydomain1, mydomain2)
177
178 if __name__ == '__main__':
179 run_tests(__name__, exit_on_failure=True)
180

  ViewVC Help
Powered by ViewVC 1.1.26