/[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 4576 - (show annotations)
Mon Dec 9 23:35:30 2013 UTC (5 years, 10 months ago) by sshaw
File MIME type: text/x-python
File size: 4935 byte(s)
python3ified things, replaced mixed whitespace and xrange calls
1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2013 by 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 since 2012 by School of Earth Sciences
13 #
14 ##############################################################################
15
16 __copyright__="""Copyright (c) 2003-2013 by University of Queensland
17 http://www.uq.edu.au
18 Primary Business: Queensland, Australia"""
19 __license__="""Licensed under the Open Software License version 3.0
20 http://www.opensource.org/licenses/osl-3.0.php"""
21 __url__="https://launchpad.net/escript-finley"
22
23 import logging
24 import unittest
25 import numpy as np
26 import os
27 import sys
28 from esys.downunder import *
29 from esys.escript import unitsSI as U
30 from esys.escript import *
31 from esys.weipa import saveSilo
32
33 # this is mainly to avoid warning messages
34 logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO)
35
36 try:
37 TEST_DATA_ROOT=os.environ['DOWNUNDER_TEST_DATA_ROOT']
38 except KeyError:
39 TEST_DATA_ROOT='ref_data'
40
41 try:
42 WORKDIR=os.environ['DOWNUNDER_WORKDIR']
43 except KeyError:
44 WORKDIR='.'
45
46
47
48
49 class TestSeismicTools(unittest.TestCase):
50 def test_segy_writer1(self):
51 sw= SimpleSEGYWriter(receiver_group=[0.,1.,2.], source=1., sampling_interval=10*U.msec, text="testing")
52 self.assertRaises(ValueError, sw.addRecord, [1])
53 for i in range(713):
54 # Create some random data.
55 data = np.random.ranf(3)
56 sw.addRecord(data)
57 sw.write(os.path.join(WORKDIR,"test1.sgy"))
58
59 def test_segy_writer2(self):
60 sw= SimpleSEGYWriter(receiver_group=[(0.,0.),(1.,-1.),(2.,-2)], source=(3,3), sampling_interval=10*U.msec, text="testing")
61 self.assertRaises(ValueError, sw.addRecord, [1])
62 for i in range(411):
63 # Create some random data.
64 data = np.random.ranf(3)
65 sw.addRecord(data)
66 sw.write(os.path.join(WORKDIR,"test2.sgy"))
67
68 def test_ricker(self):
69 rw=Ricker(f_dom=40, t_dom=None)
70
71 self.assertTrue(abs(rw.getValue(0)) < 1e-6)
72 self.assertAlmostEquals(rw.getValue(rw.getCenter()), 1. )
73 self.assertTrue(abs(rw.getAcceleration(0.)) < 1.)
74 def test_wavebase(self):
75 class TestWave(WaveBase):
76 def _getAcceleration(self, t, u):
77 return -sin(t)
78 tw=TestWave(dt=0.001, u0=0., v0=1., t0=0.)
79 self.assertAlmostEquals(0.001, tw.getTimeStepSize())
80
81 t_ref=0.005
82 t, u=tw.update(t_ref)
83 self.assertTrue(abs(t-t_ref) < 1e-9)
84 self.assertTrue(abs(u-sin(t_ref)) < 1e-6)
85
86 t_ref=0.007
87 t, u=tw.update(t_ref)
88 self.assertTrue(abs(t-t_ref) < 1e-9)
89 self.assertTrue(abs(u-sin(t_ref)) < 1e-6)
90
91 t_ref=0.0071
92 t, u=tw.update(t_ref)
93 self.assertTrue(abs(t-t_ref) < 1e-9)
94 self.assertTrue(abs(u-sin(t_ref)) < 1e-6)
95
96 t_ref=0.01
97 t, u=tw.update(t_ref)
98 self.assertTrue(abs(t-t_ref) < 1e-9)
99 self.assertTrue(abs(u-sin(t_ref)) < 1e-6)
100
101 t_ref=0.02
102 t, u=tw.update(t_ref)
103 self.assertTrue(abs(t-t_ref) < 1e-9)
104 self.assertTrue(abs(u-sin(t_ref)) < 1e-6)
105
106 t_ref=0.5
107 t, u=tw.update(t_ref)
108 self.assertTrue(abs(t-t_ref) < 1e-9)
109 self.assertTrue(abs(u-sin(t_ref)) < 1e-6)
110
111 self.assertRaises(ValueError, tw.update, t_ref-1)
112 def test_sonicwave2D(self):
113
114 from esys.finley import Rectangle
115
116 domain=Rectangle(5,5, diracPoints=[(0.5,1.)], diracTags=['sss'])
117 v_p=1.
118
119 sw=SonicWave( domain, v_p, Ricker(0.5), source_tag='sss')
120 u=sw.update(1.)[1]
121 self.assertTrue(isinstance(u,Data))
122 self.assertEquals(u.getShape(), ())
123 self.assertEquals(u.getFunctionSpace(), Solution(domain))
124
125 def test_sonicwave3D(self):
126
127 from esys.finley import Brick
128
129 domain=Brick(5,5,5, diracPoints=[(0.5,0.5,1.)], diracTags=['sss'])
130 v_p=1.
131
132 sw=SonicWave( domain, v_p, Ricker(0.5), source_tag='sss')
133 u=sw.update(1.)[1]
134 self.assertTrue(isinstance(u,Data))
135 self.assertEquals(u.getShape(), ())
136 self.assertEquals(u.getFunctionSpace(), Solution(domain))
137
138
139 if __name__ == "__main__":
140 suite = unittest.TestSuite()
141 suite.addTest(unittest.makeSuite(TestSeismicTools))
142 s=unittest.TextTestRunner(verbosity=2).run(suite)
143 if not s.wasSuccessful(): sys.exit(1)
144

  ViewVC Help
Powered by ViewVC 1.1.26