/[escript]/trunk/finley/test/python/run_inputOutput.py
ViewVC logotype

Annotation of /trunk/finley/test/python/run_inputOutput.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6936 - (hide annotations)
Wed Jan 15 00:05:28 2020 UTC (2 years, 6 months ago) by aellery
File MIME type: text/x-python
File size: 11395 byte(s)
bug fixes
1 ksteube 1809
2 jfenwick 3981 ##############################################################################
3 ksteube 1754 #
4 jfenwick 6651 # Copyright (c) 2003-2018 by The University of Queensland
5 jfenwick 3981 # http://www.uq.edu.au
6 ksteube 1754 #
7 ksteube 1809 # Primary Business: Queensland, Australia
8 jfenwick 6112 # Licensed under the Apache License, version 2.0
9     # http://www.apache.org/licenses/LICENSE-2.0
10 ksteube 1754 #
11 jfenwick 3981 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 jfenwick 4657 # Development 2012-2013 by School of Earth Sciences
13     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 jfenwick 3981 #
15     ##############################################################################
16 ksteube 1754
17 sshaw 5706 from __future__ import print_function, division
18 jfenwick 4019
19 jfenwick 6651 __copyright__="""Copyright (c) 2003-2018 by The University of Queensland
20 jfenwick 3981 http://www.uq.edu.au
21 ksteube 1809 Primary Business: Queensland, Australia"""
22 jfenwick 6112 __license__="""Licensed under the Apache License, version 2.0
23     http://www.apache.org/licenses/LICENSE-2.0"""
24 jfenwick 2344 __url__="https://launchpad.net/escript-finley"
25 ksteube 1809
26 ksteube 1754 """
27     Test suite for input and output of meshes and data objects
28    
29 jfenwick 2625 :remark:
30 ksteube 1754
31 jfenwick 2625 :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 ksteube 1754 """
37    
38 jfenwick 4938 import esys.escriptcore.utestselect as unittest, sys
39 sshaw 4984 from esys.escriptcore.testing import *
40 ksteube 1754 from esys.escript import *
41 jfenwick 3934 from esys.finley import Rectangle, Brick, LoadMesh, ReadMesh, GetMeshFromFile, ReadGmsh
42 aellery 6734 import os as os
43 aellery 6875 import numpy as np
44 ksteube 1754
45     try:
46 caltinay 3349 FINLEY_WORKDIR=os.environ['FINLEY_WORKDIR']
47     except KeyError:
48 aellery 6743 FINLEY_WORKDIR=os.path.join(os.getcwd(),"finley/test/")
49 caltinay 3349
50     try:
51 ksteube 1754 FINLEY_TEST_DATA=os.environ['FINLEY_TEST_DATA']
52     except KeyError:
53 aellery 6743 FINLEY_TEST_DATA=os.path.join(os.getcwd(),"finley/test/python")
54 ksteube 1754
55 gross 2416 FINLEY_TEST_MESH_PATH=os.path.join(FINLEY_TEST_DATA,"data_meshes")
56 ksteube 1754
57     REL_TOL=1.e-6
58    
59 ksteube 1805 # Number of elements scales up with number of MPI processes
60 caltinay 4437 mpisize = getMPISizeWorld()
61     NE0 = 7 * mpisize
62 ksteube 1805 NE1 = 11
63     NE2 = 5
64    
65 caltinay 6282 class Test_InputOutputOnFinley(unittest.TestCase):
66 ksteube 1805 # Check that two domains are equal using Fourier integrals
67     # We cannot compare the X coordinates since they are on different domains
68 ksteube 1866 def domainsEqual(self, m1, m2, nft=100):
69 jfenwick 3551 self.assertTrue(m1.getDim() == m2.getDim(), "Dimensions differ")
70     self.assertTrue(m1.getNumDataPointsGlobal() == m2.getNumDataPointsGlobal(), "Num data points differ")
71 ksteube 1772 for tagName in m1.showTagNames().split(", "):
72 jfenwick 3551 self.assertTrue(m2.isValidTagName(tagName), "m1 has a tag '%s' not present in m2" % tagName)
73 ksteube 1772 for tagName in m2.showTagNames().split(", "):
74 jfenwick 3551 self.assertTrue(m1.isValidTagName(tagName), "m2 has a tag '%s' not present in m1" % tagName)
75     self.assertTrue(m1.getTag(tagName) == m2.getTag(tagName), "values of tag '%s' differ" % tagName)
76 ksteube 1805 for fs in ["Solution", "ReducedSolution", "Function", "ReducedFunction", "ContinuousFunction", "ReducedContinuousFunction"]:
77 ksteube 1772 fs1 = eval("%s(m1)" % fs)
78     fs2 = eval("%s(m2)" % fs)
79     x1 = fs1.getX()
80     x2 = fs2.getX()
81     for n in range(1, nft+1):
82     integ1 = integrate(sin(n*x1))
83     integ2 = integrate(sin(n*x2))
84 jfenwick 3551 self.assertTrue(Lsup(abs(integ1-integ2)) <= REL_TOL, "integrals for n=%d differ" % n)
85 ksteube 1772 return True
86    
87 ksteube 1754 # Does optimize=True change Rectangle for order=1?
88     def test_Rectangle_optimize_order1(self):
89 jfenwick 3901 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False,useElementsOnFace=0)
90     mydomain2 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=True,useElementsOnFace=0)
91 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
92 ksteube 1754
93     # Does optimize=True change Rectangle for order=2?
94 ksteube 1829 def test_Rectangle_optimize_order2(self):
95 jfenwick 3901 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=2, l0=1., l1=1., optimize=False,useElementsOnFace=0)
96     mydomain2 = Rectangle(n0=NE0, n1=NE1, order=2, l0=1., l1=1., optimize=True,useElementsOnFace=0)
97 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
98 ksteube 1754
99 gross 2722 # Does optimize=True change Rectangle for order=-1?
100     def test_Rectangle_optimize_macro(self):
101 jfenwick 3901 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=-1, l0=1., l1=1., optimize=False, useElementsOnFace=0)
102     mydomain2 = Rectangle(n0=NE0, n1=NE1, order=-1, l0=1., l1=1., optimize=True,useElementsOnFace=0)
103 gross 2722 self.domainsEqual(mydomain1, mydomain2)
104    
105 ksteube 1754 # Does optimize=True change Brick for order=1?
106     def test_Brick_optimize_order1(self):
107 jfenwick 3901 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False,useElementsOnFace=0)
108     mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=True,useElementsOnFace=0)
109 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
110 ksteube 1754
111     # Does optimize=True change Brick for order=2?
112 ksteube 1829 def test_Brick_optimize_order2(self):
113 jfenwick 3901 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False,useElementsOnFace=0)
114     mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=True,useElementsOnFace=0)
115 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
116 gross 2722 # Does optimize=True change Brick for order=-1?
117     def test_Brick_optimize_macro(self):
118 jfenwick 3901 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=-1, l0=1., l1=1., l2=1., optimize=False,useElementsOnFace=0)
119     mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=-1, l0=1., l1=1., l2=1., optimize=True,useElementsOnFace=0)
120 gross 2722 self.domainsEqual(mydomain1, mydomain2)
121 ksteube 1754
122 sshaw 5060 @unittest.skipIf(not loadIsConfigured(), "load not configured")
123 ksteube 1805 def test_data_dump_to_NetCDF_rectangle(self):
124 sshaw 5060 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False,useElementsOnFace=0)
125     d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
126     d1.expand()
127     dumpfile=os.path.join(FINLEY_WORKDIR, "tempfile.dump.nc")
128     d1.dump(dumpfile)
129     d2=load(dumpfile, mydomain1)
130     self.assertTrue(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
131 ksteube 1805
132 sshaw 5060 @unittest.skipIf(not loadIsConfigured(), "load not configured")
133 ksteube 1805 def test_data_dump_to_NetCDF_brick(self):
134 sshaw 5060 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
135     d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
136     d1.expand()
137     dumpfile=os.path.join(FINLEY_WORKDIR, "tempfile.dump.nc")
138     d1.dump(dumpfile)
139     d2=load(dumpfile, mydomain1)
140     self.assertTrue(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
141 ksteube 1805
142 aellery 6825 # @unittest.skipIf(not loadIsConfigured() or mpisize > 1, "load not configured or mpisize > 1")
143     # def test_mesh_dump_to_NetCDF_rectangle(self):
144     # mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
145     # dumpfile=os.path.join(FINLEY_WORKDIR, "tempfile.mesh.nc")
146     # mydomain1.dump(dumpfile)
147     # mydomain2=LoadMesh(dumpfile)
148     # self.domainsEqual(mydomain1, mydomain2)
149 ksteube 1754
150 caltinay 4437 @unittest.skipIf(mpisize>1, "more than 1 MPI rank")
151 jfenwick 3934 def test_gmshTags(self):
152 gross 4024 dom=ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH, "tagtest.msh"),2)
153     tags=dom.showTagNames().split(', ')
154     self.assertEqual(tags,['tag1', 'tag2', 'tag3'],'error with tags')
155     self.assertEqual(dom.getTag('tag1'),1,'error with tag1')
156     self.assertEqual(dom.getTag('tag2'),2,'error with tag2')
157     self.assertEqual(dom.getTag('tag3'),3,'error with tag3')
158 caltinay 5984 self.assertRaises(ValueError, dom.getTag, 'tag4')
159 aellery 6743
160 jduplessis 5043 @unittest.skipIf(mpisize>1, "more than 1 MPI rank")
161 jduplessis 5032 def test_gmshNamedTags(self):
162     dom=ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH, "test_Add.msh"),3)
163     sigma = Scalar(0,Function(dom))
164     sigma.expand()
165     sigma.setTaggedValue("v5",10)
166     self.assertEqual(Lsup(sigma),10.0,"Named value not set properly")
167    
168 gross 4024 def test_flyTags(self):
169     dom=ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH, "rectangle_8x10.fly"))
170 caltinay 4437 tags=sorted(dom.showTagNames().split(', '))
171     self.assertEqual(tags,sorted(['top', 'bottom', 'left', 'right']))
172 gross 4024 self.assertEqual(dom.getTag('top'),20,'error with top')
173     self.assertEqual(dom.getTag('bottom'),10,'error with bottom,')
174     self.assertEqual(dom.getTag('left'),1,'error with left')
175     self.assertEqual(dom.getTag('right'),2,'error with reight')
176 caltinay 5984 self.assertRaises(ValueError, dom.getTag, 'tag4')
177 jfenwick 3934
178 aellery 6825 # @unittest.skipIf(not loadIsConfigured() or mpisize>1, "load not configured or mpisize > 1")
179     # def test_mesh_dump_to_NetCDF_brick(self):
180     # mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
181     # dumpfile=os.path.join(FINLEY_WORKDIR, "tempfile.mesh.nc")
182     # mydomain1.dump(dumpfile)
183     # mydomain2=LoadMesh(dumpfile)
184     # self.domainsEqual(mydomain1, mydomain2)
185 ksteube 1755
186 caltinay 4437 @unittest.skipIf(mpisize>15, "more than 15 MPI ranks")
187 ksteube 1772 def test_mesh_read_rectangle_from_finley_file(self):
188 caltinay 4437 mydomain1 = Rectangle(n0=8, n1=10, order=1, l0=1., l1=1., optimize=False)
189     mydomain2 = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH,"rectangle_8x10.fly"))
190     self.domainsEqual(mydomain1, mydomain2)
191 ksteube 1772
192 caltinay 4437 @unittest.skipIf(mpisize>15, "more than 15 MPI ranks")
193 ksteube 1772 def test_mesh_read_brick_from_finley_file(self):
194 ksteube 1805 mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False)
195 gross 2416 mydomain2 = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH,"brick_8x10x12.fly"))
196 ksteube 1805 self.domainsEqual(mydomain1, mydomain2)
197 caltinay 4437
198     @unittest.skipIf(mpisize>1, "more than 1 MPI rank")
199 jfenwick 3912 def test_GetMeshFromFile(self):
200     m=GetMeshFromFile(os.path.join(FINLEY_TEST_MESH_PATH,'tet10_gmsh.msh'), numDim=3)
201     del m
202     m=GetMeshFromFile(os.path.join(FINLEY_TEST_MESH_PATH, 'tet10.fly'))
203     # now we try some params
204     m=GetMeshFromFile(os.path.join(FINLEY_TEST_MESH_PATH,'tet10_gmsh.msh'), numDim=3, integrationOrder=2)
205 ksteube 1772
206 aellery 6875 def test_connectivity_info(self):
207     if hasFeature("boostnumpy"):
208 uqaeller 6935 domain=Rectangle(n0=3,n1=4)
209 aellery 6875 testvalues=domain.getConnectivityInfo()
210     correctvalues=[[0., 1., 5., 4.],
211     [ 1., 2., 6., 5.],
212     [ 2., 3., 7., 6.],
213     [ 4., 5., 9., 8.],
214     [ 5., 6.,10., 9.],
215     [ 6., 7.,11.,10.],
216     [ 8., 9.,13.,12.],
217     [ 9.,10.,14.,13.],
218     [10.,11.,15.,14.],
219     [12.,13.,17.,16.],
220     [13.,14.,18.,17.],
221     [14.,15.,19.,18.]]
222     for i in range(0,testvalues.shape[0]):
223     for j in range(0,4):
224     self.assertEqual(testvalues[i][j],correctvalues[i][j])
225    
226 uqaeller 6935 def test_readgmsh_format_4_0(self):
227 aellery 6936 mydomain1 = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH,"testcube.2.2.msh"), numDim=3)
228     mydomain2 = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH,"testcube.4.0.msh"), numDim=3)
229 uqaeller 6935 self.domainsEqual(mydomain1, mydomain2)
230    
231 aellery 6936 def test_readgmsh_format_4_1(self):
232     mydomain1 = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH,"testcube.2.2.msh"), numDim=3)
233     mydomain2 = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH,"testcube.4.1.msh"), numDim=3)
234     self.domainsEqual(mydomain1, mydomain2)
235    
236 ksteube 1754 if __name__ == '__main__':
237 sshaw 4984 run_tests(__name__, exit_on_failure=True)

  ViewVC Help
Powered by ViewVC 1.1.26