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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5706 - (show annotations)
Mon Jun 29 03:41:36 2015 UTC (4 years, 4 months ago) by sshaw
File MIME type: text/x-python
File size: 3341 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 """2D gravity inversion example using synthetic data"""
19
20 __copyright__="""Copyright (c) 2003-2015 by The University of Queensland
21 http://www.uq.edu.au
22 Primary Business: Queensland, Australia"""
23 __license__="""Licensed under the Open Software License version 3.0
24 http://www.opensource.org/licenses/osl-3.0.php"""
25 __url__="https://launchpad.net/escript-finley"
26
27 import os
28 import esys.escriptcore.utestselect as unittest
29 from esys.escriptcore.testing import *
30 from esys.downunder import *
31 from esys.escript import unitsSI as U
32 from esys.weipa import saveSilo
33 import logging
34
35 try:
36 import esys.ripley
37 HAVE_RIPLEY = True
38 except ImportError:
39 HAVE_RIPLEY = False
40
41 try:
42 WORKDIR=os.environ['DOWNUNDER_WORKDIR']
43 except KeyError:
44 WORKDIR='.'
45
46 @unittest.skipIf(not HAVE_RIPLEY, "Ripley module not available")
47 class Test_GravityInversion2D(unittest.TestCase):
48 def test_inversion(self):
49 #be quiet about it
50 logging.getLogger('inv.MinimizerLBFGS').setLevel(logging.CRITICAL)
51 logging.getLogger('inv.GravityInversion').setLevel(logging.CRITICAL)
52
53 # interesting parameters:
54 n_humps_h = 3
55 n_humps_v = 1
56 mu = 100
57 n_cells_in_data = 100
58 # ignore:
59 full_knowledge = False
60 depth_offset = 0. * U.km
61 #
62 DIM = 2
63 n_cells_in_data = max(n_humps_h*7, n_cells_in_data)
64 l_data = 100. * U.km
65 l_pad = 40. * U.km
66 THICKNESS = 20. * U.km
67 l_air = 20. * U.km
68 n_cells_v = max(int((2*l_air+THICKNESS+depth_offset)/ \
69 l_data*n_cells_in_data + 0.5), 25)
70
71
72 source=SyntheticData(DataSource.GRAVITY, n_length=n_humps_h,
73 n_depth=n_humps_v,
74 depth=THICKNESS+depth_offset, depth_offset=depth_offset,
75 DIM=DIM, number_of_elements=n_cells_in_data, length=l_data,
76 data_offset=0, full_knowledge=full_knowledge)
77
78 domainbuilder=DomainBuilder(dim=DIM)
79 domainbuilder.addSource(source)
80 domainbuilder.setVerticalExtents(depth=l_air+THICKNESS+depth_offset,
81 air_layer=l_air, num_cells=n_cells_v)
82 domainbuilder.setPadding(l_pad)
83 domainbuilder.fixDensityBelow(depth=THICKNESS+depth_offset)
84
85 inv=GravityInversion()
86 inv.setSolverTolerance(1e-4)
87 inv.setSolverMaxIterations(50)
88 inv.setup(domainbuilder)
89 inv.getCostFunction().setTradeOffFactorsModels(mu)
90
91 rho_new = inv.run()
92 rho_ref = source.getReferenceProperty()
93 g, chi = inv.getCostFunction().getForwardModel().getSurvey(0)
94
95 if __name__ == '__main__':
96 run_tests(__name__, exit_on_failure=True)

  ViewVC Help
Powered by ViewVC 1.1.26