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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4544 - (hide annotations)
Thu Nov 28 04:01:46 2013 UTC (5 years, 10 months ago) by gross
File MIME type: text/x-python
File size: 4040 byte(s)
wave simulator base added
1 gross 4539
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 gross 4544 from esys.escript import *
31 gross 4539 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 xrange(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 xrange(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 gross 4541
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 gross 4544 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 gross 4539
106 gross 4544 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    
113    
114 gross 4539 if __name__ == "__main__":
115     suite = unittest.TestSuite()
116     suite.addTest(unittest.makeSuite(TestSeismicTools))
117     s=unittest.TextTestRunner(verbosity=2).run(suite)
118     if not s.wasSuccessful(): sys.exit(1)
119    

  ViewVC Help
Powered by ViewVC 1.1.26