/
viscoelastic_example.py
76 lines (60 loc) · 3.14 KB
/
viscoelastic_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import numpy as np
from argparse import ArgumentParser
from devito import configuration
from devito.logger import info
from examples.seismic.viscoelastic import ViscoelasticWaveSolver
from examples.seismic import demo_model, setup_geometry
def viscoelastic_setup(shape=(50, 50), spacing=(15.0, 15.0), tn=500., space_order=4,
nbl=10, constant=True, **kwargs):
preset = 'constant-viscoelastic' if constant else 'layers-viscoelastic'
model = demo_model(preset, space_order=space_order, shape=shape, nbl=nbl,
dtype=kwargs.pop('dtype', np.float32), spacing=spacing)
# Source and receiver geometries
geometry = setup_geometry(model, tn)
# Create solver object to provide relevant operators
solver = ViscoelasticWaveSolver(model, geometry, space_order=space_order, **kwargs)
return solver
def run(shape=(50, 50), spacing=(20.0, 20.0), tn=1000.0,
space_order=4, nbl=40, autotune=False, constant=False, **kwargs):
solver = viscoelastic_setup(shape=shape, spacing=spacing, nbl=nbl, tn=tn,
space_order=space_order, constant=constant, **kwargs)
info("Applying Forward")
# Define receiver geometry (spread across x, just below surface)
rec1, rec2, v, tau, summary = solver.forward(autotune=autotune)
return (summary.gflopss, summary.oi, summary.timings,
[rec1, rec2, v, tau])
def test_viscoelastic():
_, _, _, [rec1, rec2, v, tau] = run()
norm = lambda x: np.linalg.norm(x.data.reshape(-1))
assert np.isclose(norm(rec1), 12.9297, atol=1e-3, rtol=0)
assert np.isclose(norm(rec2), 0.42867, atol=1e-3, rtol=0)
if __name__ == "__main__":
description = ("Example script for a set of viscoelastic operators.")
parser = ArgumentParser(description=description)
parser.add_argument('--2d', dest='dim2', default=False, action='store_true',
help="Preset to determine the physical problem setup")
parser.add_argument("-so", "--space_order", default=4,
type=int, help="Space order of the simulation")
parser.add_argument("--nbl", default=40,
type=int, help="Number of boundary layers around the domain")
parser.add_argument("--constant", default=False, action='store_true',
help="Constant velocity model, default is a two layer model")
parser.add_argument("-opt", default="advanced",
choices=configuration._accepted['opt'],
help="Performance optimization level")
parser.add_argument('-a', '--autotune', default='off',
choices=(configuration._accepted['autotuning']),
help="Operator auto-tuning mode")
args = parser.parse_args()
# 2D preset parameters
if args.dim2:
shape = (150, 150)
spacing = (10.0, 10.0)
tn = 750.0
# 3D preset parameters
else:
shape = (150, 150, 150)
spacing = (10.0, 10.0, 10.0)
tn = 1250.0
run(shape=shape, spacing=spacing, nbl=args.nbl, tn=tn, opt=args.opt,
space_order=args.space_order, autotune=args.autotune, constant=args.constant)