/[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 4657 - (show annotations)
Thu Feb 6 06:12:20 2014 UTC (5 years, 8 months ago) by jfenwick
File MIME type: text/x-python
File size: 5003 byte(s)
I changed some files.
Updated copyright notices, added GeoComp.



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

  ViewVC Help
Powered by ViewVC 1.1.26