/[escript]/release/5.2/speckley/test/python/run_diracOnSpeckley.py
ViewVC logotype

Contents of /release/5.2/speckley/test/python/run_diracOnSpeckley.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6692 - (show annotations)
Mon Jun 25 02:31:06 2018 UTC (3 years, 2 months ago) by jfenwick
File MIME type: text/x-python
File size: 6594 byte(s)
Fix

1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2018 by The University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Apache License, version 2.0
9 # http://www.apache.org/licenses/LICENSE-2.0
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-2018 by The University of Queensland
20 http://www.uq.edu.au
21 Primary Business: Queensland, Australia"""
22 __license__="""Licensed under the Apache License, version 2.0
23 http://www.apache.org/licenses/LICENSE-2.0"""
24 __url__="https://launchpad.net/escript-finley"
25
26 import os, sys
27 import esys.escriptcore.utestselect as unittest
28 from esys.escriptcore.testing import *
29 from esys.escript import *
30 from esys.speckley import Rectangle, Brick
31
32 try:
33 SPECKLEY_WORKDIR=os.environ['SPECKLEY_WORKDIR']
34 except KeyError:
35 SPECKLEY_WORKDIR='.'
36
37 class Test_SpeckleyDiracPoints(unittest.TestCase):
38 # constants
39 numRanks = getMPISizeWorld()
40 rank = getMPIRankWorld()
41 shortEdge = 5
42 longEdge = 3*numRanks
43
44 def generateRects(self, order, a, b):
45 rectX = Rectangle(order, self.longEdge, self.shortEdge, l0=self.longEdge,
46 l1=self.shortEdge, d0=self.numRanks, diracPoints=[(a,b)], diracTags=["test"])
47 rectY = Rectangle(order, self.shortEdge, self.longEdge, l0=self.shortEdge,
48 l1=self.longEdge, d1=self.numRanks, diracPoints=[(b,a)], diracTags=["test"])
49 return [rectX, rectY]
50
51 def generateBricks(self, order, a, b, c):
52 brickX = Brick(order, self.longEdge, 5, 5,
53 l0=self.longEdge, l1=5, l2=5,
54 d0=self.numRanks,
55 diracPoints=[(a,b,c)], diracTags=["test"])
56 brickY = Brick(order, 5, self.longEdge, 5,
57 l0=5, l1=self.longEdge, l2=self.shortEdge,
58 d1=self.numRanks,
59 diracPoints=[(c,a,b)], diracTags=["test"])
60 brickZ = Brick(order, 5, 5, self.longEdge,
61 l0=5, l1=5, l2=self.longEdge,
62 d2=self.numRanks,
63 diracPoints=[(b,c,a)], diracTags=["test"])
64 dims = [ [self.longEdge, 5, 5], [5, self.longEdge, 5],
65 [5, 5, self.longEdge]]
66 return [brickX, brickY, brickZ], dims
67
68 def owns(self, refs, y, x, xLong):
69 if xLong and self.rank*3 - 1 <= x <= self.rank*3 + 3:
70 return True
71 elif not xLong and self.rank*3 - 1 <= y <= self.rank*3 + 3:
72 return True
73 return False
74
75 def setUp(self):
76 pass
77
78 def tearDown(self):
79 pass
80
81 def test_Creation(self):
82 r = self.numRanks
83 el = self.numRanks*3
84
85 #test bad types
86 with self.assertRaises(TypeError):
87 Rectangle(2, 5, el, d1=r, diracPoints=(.0,0.), diracTags=["test"])
88 with self.assertRaises(TypeError):
89 Rectangle(2, 5, el, d1=r, diracPoints=[(.0,0.)], diracTags=("test"))
90 with self.assertRaises(TypeError):
91 Rectangle(2, 5, el, d1=r, diracPoints=[.0], diracTags=["test"])
92 with self.assertRaises(TypeError):
93 Rectangle(2, 5, el, d1=r, diracPoints=[.0,.0], diracTags=["test"])
94
95 with self.assertRaises(TypeError):
96 Brick(2, 5, el, 5, d1=r, diracPoints=(.0,0.,0.), diracTags=["test"])
97 with self.assertRaises(TypeError):
98 Brick(2, 5, el, 5, d1=r, diracPoints=[(.0,0.,0.)], diracTags=("test"))
99 with self.assertRaises(TypeError):
100 Brick(2, 5, el, 5, d1=r, diracPoints=[.0,0.], diracTags=["test"])
101
102 #test bad arg lengths
103 with self.assertRaises(RuntimeError):
104 Rectangle(2, 5, el, d1=r, diracPoints=[(.0,)], diracTags=["test"])
105 with self.assertRaises(RuntimeError):
106 Rectangle(2, 5, el, d1=r, diracPoints=[(.0,1.)], diracTags=[])
107 with self.assertRaises(RuntimeError):
108 Rectangle(2, 5, el, d1=r, diracPoints=[(.0,0.)], diracTags=["test", "break"])
109 with self.assertRaises(RuntimeError):
110 Rectangle(2, 5, el, d1=r, diracPoints=[(.0,0.,0.)], diracTags=["test"])
111
112 with self.assertRaises(RuntimeError):
113 Brick(2, 5, el, 5, d1=r, diracPoints=[(.0,0.,0.,0.)], diracTags=["test"])
114 with self.assertRaises(RuntimeError):
115 Brick(2, 5, el, 5, d1=r, diracPoints=[(.0,0.,)], diracTags=["test"])
116 with self.assertRaises(RuntimeError):
117 Brick(2, 5, el, 5, d1=r, diracPoints=[(.0,)], diracTags=["test"])
118
119 def test_DDF_to_Continuous_2D(self):
120 expected_value = self.numRanks*11
121 for order in range(2, 11):
122 rectX, rectY = self.generateRects(order, self.longEdge, self.shortEdge)
123 for dom, point in [(rectX, (self.longEdge, self.shortEdge)),
124 (rectY, (self.shortEdge, self.longEdge))]:
125 xDDF = Data(0, DiracDeltaFunctions(dom))
126 xDDF.setTaggedValue("test", expected_value)
127
128 X = dom.getX()
129 expected_data = whereZero(X[0]-point[0]) * whereZero(X[1]-point[1]) * expected_value
130 cont = interpolate(xDDF, ContinuousFunction(dom))
131 result = Lsup(expected_data - cont)
132 self.assertLess(result, 1e-15,
133 "Interpolation failure, expected zero, got %g"%result)
134
135 def test_DDF_to_Continuous_3D(self):
136 expected_value = self.numRanks*11
137 for order in range(2, 11):
138 doms, dims = self.generateBricks(order, self.longEdge,
139 self.shortEdge, self.shortEdge)
140 for dom, point in zip(doms, dims):
141 xDDF = Data(0, DiracDeltaFunctions(dom))
142 xDDF.setTaggedValue("test", expected_value)
143
144 X = dom.getX()
145 expected_data = whereZero(X[0]-point[0]) \
146 * whereZero(X[1]-point[1]) * whereZero(X[2]-point[2]) \
147 * expected_value
148 cont = interpolate(xDDF, ContinuousFunction(dom))
149 result = Lsup(expected_data - cont)
150 self.assertLess(result, 1e-15,
151 "Interpolation failure, expected zero, got %g"%result)
152
153 if __name__ == '__main__':
154 run_tests(__name__, exit_on_failure=True)
155
156

  ViewVC Help
Powered by ViewVC 1.1.26