/[escript]/trunk/downunder/test/python/run_seismic.py
ViewVC logotype

Contents of /trunk/downunder/test/python/run_seismic.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5706 - (show annotations)
Mon Jun 29 03:41:36 2015 UTC (4 years, 3 months ago) by sshaw
File MIME type: text/x-python
File size: 5519 byte(s)
all python files now force use of python3 prints and division syntax to stop sneaky errors appearing in py3 environs
1 ##############################################################################
2 #
3 # Copyright (c) 2003-2015 by The University of Queensland
4 # http://www.uq.edu.au
5 #
6 # Primary Business: Queensland, Australia
7 # Licensed under the Open Software License version 3.0
8 # http://www.opensource.org/licenses/osl-3.0.php
9 #
10 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11 # Development 2012-2013 by School of Earth Sciences
12 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
13 #
14 ##############################################################################
15
16 from __future__ import print_function, division
17
18 __copyright__="""Copyright (c) 2003-2015 by The University of Queensland
19 http://www.uq.edu.au
20 Primary Business: Queensland, Australia"""
21 __license__="""Licensed under the Open Software License version 3.0
22 http://www.opensource.org/licenses/osl-3.0.php"""
23 __url__="https://launchpad.net/escript-finley"
24
25 import logging
26 import esys.escriptcore.utestselect as unittest
27 from esys.escriptcore.testing import *
28 import numpy as np
29 import os
30 import sys
31 from esys.downunder import *
32 from esys.escript import unitsSI as U
33 from esys.escript import *
34 from esys.weipa import saveSilo
35
36 # this is mainly to avoid warning messages
37 logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO)
38
39 try:
40 from esys.ripley import Rectangle as rRect, Brick as rBrick
41 HAVE_RIPLEY = True
42 except ImportError:
43 HAVE_RIPLEY = False
44
45 try:
46 from esys.finley import Rectangle as fRect, Brick as fBrick
47 HAVE_FINLEY = True
48 except ImportError:
49 HAVE_FINLEY = False
50
51
52
53 try:
54 TEST_DATA_ROOT=os.environ['DOWNUNDER_TEST_DATA_ROOT']
55 except KeyError:
56 TEST_DATA_ROOT='ref_data'
57
58 try:
59 WORKDIR=os.environ['DOWNUNDER_WORKDIR']
60 except KeyError:
61 WORKDIR='.'
62
63 writeFailMessage = "This feature (SimpleSEGYWriter.write()) depends on obspy,"+\
64 " which is not installed, see https://github.com/obspy/obspy for install guide"
65
66
67 class TestSeismicTools(unittest.TestCase):
68 @unittest.skipIf(getMPISizeWorld() > 1,
69 "segywriters don't support multiple ranks")
70 def test_segy_writer1(self):
71 sw= SimpleSEGYWriter(receiver_group=[0.,1.,2.], source=1., sampling_interval=10*U.msec, text="testing")
72 self.assertRaises(ValueError, sw.addRecord, [1])
73 for i in range(713):
74 # Create some random data.
75 data = np.random.ranf(3)
76 sw.addRecord(data)
77 try:
78 sw.write(os.path.join(WORKDIR,"test1.sgy"))
79 except Exception as e:
80 if str(e) == writeFailMessage:
81 raise unittest.SkipTest("obspy not installed")
82 raise e
83
84 @unittest.skipIf(getMPISizeWorld() > 1,
85 "segywriters don't support multiple ranks")
86 def test_segy_writer2(self):
87 sw= SimpleSEGYWriter(receiver_group=[(0.,0.),(1.,-1.),(2.,-2)], source=(3,3), sampling_interval=10*U.msec, text="testing")
88 self.assertRaises(ValueError, sw.addRecord, [1])
89 for i in range(411):
90 # Create some random data.
91 data = np.random.ranf(3)
92 sw.addRecord(data)
93 try:
94 sw.write(os.path.join(WORKDIR,"test2.sgy"))
95 except Exception as e:
96 if str(e) == writeFailMessage:
97 raise unittest.SkipTest("obspy not installed")
98 raise e
99
100 def test_ricker(self):
101 rw=Ricker(f_dom=40, t_dom=None)
102
103 self.assertLess(abs(rw.getValue(0)), 1e-6)
104 self.assertAlmostEqual(rw.getValue(rw.getCenter()), 1. )
105 self.assertLess(abs(rw.getAcceleration(0.)), 1.)
106
107 def test_wavebase(self):
108 class TestWave(WaveBase):
109 def _getAcceleration(self, t, u):
110 return -sin(t)
111 def check_values(self, tw, t_ref):
112 t, u=tw.update(t_ref)
113 self.assertLess(abs(t-t_ref), 1e-9)
114 self.assertLess(abs(u-sin(t_ref)), 1e-6)
115
116 tw=TestWave(dt=0.001, u0=0., v0=1., t0=0.)
117 self.assertAlmostEqual(0.001, tw.getTimeStepSize())
118 for t in [0.005, 0.007, 0.0071, 0.01, 0.02, 0.5]:
119 check_values(self, tw, t)
120 self.assertRaises(ValueError, tw.update, t-1)
121
122 def sonicRunner(self, domain, label):
123 v_p=1.
124 sw = SonicWave(domain, v_p, Ricker(0.5), source_tag='sss')
125 u = sw.update(1.)[1]
126 self.assertIsInstance(u, Data,
127 "u is not Data instance for %s"%label)
128 self.assertEqual(u.getShape(), (),
129 "u is not shape () for %s"%label)
130 self.assertEqual(u.getFunctionSpace(), Solution(domain),
131 "functionspace != solution for %s"%label)
132
133 def test_sonicwave2D(self):
134 doms = []
135 if HAVE_RIPLEY:
136 doms.append((rRect, "ripley"))
137 if HAVE_FINLEY:
138 doms.append((fRect, "finley"))
139 for domType, impl in doms:
140 domain=domType(5,5, diracPoints=[(0.5,1.)], diracTags=['sss'])
141 self.sonicRunner(domain, "%s.Rectangle"%impl)
142
143 def test_sonicwave3D(self):
144 doms = []
145 if HAVE_RIPLEY:
146 doms.append((rBrick, "ripley"))
147 if HAVE_FINLEY:
148 doms.append((fBrick, "finley"))
149 for domType, impl in doms:
150 domain=domType(5,5,5, diracPoints=[(0.5,0.5,1.)], diracTags=['sss'])
151 self.sonicRunner(domain, "%s.Brick"%impl)
152
153 if __name__ == '__main__':
154 run_tests(__name__, exit_on_failure=True)
155

  ViewVC Help
Powered by ViewVC 1.1.26