-
Notifications
You must be signed in to change notification settings - Fork 220
/
wavesolver.py
266 lines (230 loc) · 10.5 KB
/
wavesolver.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
from devito import Function, TimeFunction
from devito.tools import memoized_meth
from examples.seismic.self_adjoint.operators import IsoFwdOperator, IsoAdjOperator, \
IsoJacobianFwdOperator, IsoJacobianAdjOperator
class SaIsoAcousticWaveSolver(object):
"""
Solver object for a scalar isotropic variable density visco- acoustic
self adjoint wave equation that provides operators for seismic inversion problems
and encapsulates the time and space discretization for a given problem setup.
Parameters
----------
npad : int, required
Number of points in the absorbing boundary.
Typically set to 50.
omega : float, required
Center circular frequency for dissipation only attenuation.
qmin : float, required
Minimum Q value on the exterior of the absorbing boundary.
Typically set to 0.1.
qmax : float, required
Maximum Q value in the interior of the model.
Typically set to 100.0.
b : Function, required
Physical model with buoyancy (m^3/kg).
v : Function, required
Physical model with velocity (m/msec).
src : SparseTimeFunction (PointSource)
Source position and time signature.
rec : SparseTimeFunction (PointSource)
Receiver positions and time signature.
time_axis : TimeAxis
Defines temporal sampling.
space_order: int, optional
Order of the spatial stencil discretisation. Defaults to 8.
"""
def __init__(self, model, geometry, space_order=8, **kwargs):
self.model = model
self.geometry = geometry
assert self.model.grid == geometry.grid
self.space_order = space_order
# Time step is .5 time smaller due to Q
self.model.dt_scale = .5
# Cache compiler options
self._kwargs = kwargs
@property
def dt(self):
return self.model.critical_dt
@memoized_meth
def op_fwd(self, save=None):
"""Cached operator for forward runs with buffered wavefield"""
return IsoFwdOperator(self.model, save=save, geometry=self.geometry,
space_order=self.space_order, **self._kwargs)
@memoized_meth
def op_adj(self, save=None):
"""Cached operator for adjoint runs"""
return IsoAdjOperator(self.model, save=save, geometry=self.geometry,
space_order=self.space_order, **self._kwargs)
@memoized_meth
def op_jacadj(self, save=True):
"""Cached operator for gradient runs"""
return IsoJacobianAdjOperator(self.model, save=save, geometry=self.geometry,
space_order=self.space_order, **self._kwargs)
@memoized_meth
def op_jac(self, save=None):
"""Cached operator for born runs"""
return IsoJacobianFwdOperator(self.model, save=save, geometry=self.geometry,
space_order=self.space_order, **self._kwargs)
def forward(self, src=None, rec=None, b=None, vp=None, damp=None, u=None,
save=None, **kwargs):
"""
Forward modeling function that creates the necessary
data objects for running a forward modeling operator.
No required parameters.
Parameters
----------
src : SparseTimeFunction, required
Time series data for the injected source term.
rec : SparseTimeFunction, optional, defaults to new rec
The interpolated receiver data.
b : Function or float, optional, defaults to b at construction
The time-constant buoyancy.
v : Function or float, optional, defaults to v at construction
The time-constant velocity.
damp : Function or float
The time-constant dissipation only attenuation w/Q field.
u : Function or float
Stores the computed wavefield.
save : bool, optional
Whether or not to save the entire (unrolled) wavefield.
Returns
----------
Receiver time series data, TimeFunction wavefield u, and performance summary
"""
# Source term is read-only, so re-use the default
src = src or self.geometry.src
# Create a new receiver object to store the result
rec = rec or self.geometry.rec
# Create the forward wavefield if not provided
u = u or TimeFunction(name='u', grid=self.model.grid,
save=self.geometry.nt if save else None,
time_order=2, space_order=self.space_order)
# Pick input physical parameters
kwargs.update(self.model.physical_params(vp=vp, damp=damp, b=b))
kwargs.update({'dt': kwargs.pop('dt', self.dt)})
# Execute operator and return wavefield and receiver data
summary = self.op_fwd(save).apply(src=src, rec=rec, u=u, **kwargs)
return rec, u, summary
def adjoint(self, rec, src=None, b=None, v=None, damp=None, vp=None,
save=None, **kwargs):
"""
Adjoint modeling function that creates the necessary
data objects for running a adjoint modeling operator.
Required parameters: rec.
Parameters
----------
rec : SparseTimeFunction
The interpolated receiver data to be injected.
src : SparseTimeFunction
Time series data for the adjoint source term.
b : Function or float
The time-constant buoyancy.
v : Function or float
The time-constant velocity.
damp : Function or float
The time-constant dissipation only attenuation w/Q field.
ua : Function or float
Stores the computed adjoint wavefield.
Returns
----------
Adjoint source time series data, wavefield TimeFunction ua,
and performance summary
"""
# Create a new adjoint source and receiver symbol
srca = src or self.geometry.new_src(name='srca', src_type=None)
# Create the adjoint wavefield if not provided
v = v or TimeFunction(name='v', grid=self.model.grid,
time_order=2, space_order=self.space_order)
# Pick input physical parameters
kwargs.update(self.model.physical_params(vp=vp, damp=damp, b=b))
kwargs.update({'dt': kwargs.pop('dt', self.dt)})
# Execute operator and return wavefield and receiver data
summary = self.op_adj(save).apply(src=srca, rec=rec, v=v, **kwargs)
return srca, v, summary
def jacobian(self, dm, src=None, rec=None, b=None, vp=None, damp=None,
u0=None, du=None, save=None, **kwargs):
"""
Linearized JacobianForward modeling function that creates the necessary
data objects for running a Jacobian forward modeling operator.
Required parameters: dm.
Parameters
----------
dm : Function or float
The perturbation to the velocity model.
src : SparseTimeFunction
Time series data for the injected source term.
rec : SparseTimeFunction, optional, defaults to new rec
The interpolated receiver data.
b : Function or float
The time-constant buoyancy.
v : Function or float
The time-constant velocity.
damp : Function or float
The time-constant dissipation only attenuation w/Q field.
u0 : Function or float
Stores the computed background wavefield.
du : Function or float
Stores the computed perturbed wavefield.
save : bool, optional
Whether or not to save the entire (unrolled) wavefield.
Returns
----------
Receiver time series data rec, TimeFunction background wavefield u0,
TimeFunction perturbation wavefield du, and performance summary
"""
# Source term is read-only, so re-use the default
src = src or self.geometry.src
# Create a new receiver object to store the result
rec = rec or self.geometry.rec
# Create the forward wavefields u and U if not provided
u0 = u0 or TimeFunction(name='u0', grid=self.model.grid,
save=self.geometry.nt if save else None,
time_order=2, space_order=self.space_order)
du = du or TimeFunction(name='du', grid=self.model.grid,
time_order=2, space_order=self.space_order)
# Pick input physical parameters
kwargs.update(self.model.physical_params(vp=vp, damp=damp, b=b))
kwargs.update({'dt': kwargs.pop('dt', self.dt)})
# Execute operator and return wavefield and receiver data
summary = self.op_jac(save).apply(dm=dm, u0=u0, du=du, src=src, rec=rec, **kwargs)
return rec, u0, du, summary
def jacobian_adjoint(self, rec, u0, b=None, vp=None, damp=None,
dm=None, du=None, **kwargs):
"""
Linearized JacobianForward modeling function that creates the necessary
data objects for running a Jacobian forward modeling operator.
Required parameters: rec, u0.
Parameters
----------
rec : SparseTimeFunction
The interpolated receiver data to be injected.
u0 : Function or float
Stores the computed background wavefield.
b : Function or float
The time-constant buoyancy.
v : Function or float
The time-constant velocity.
damp : Function or float
The time-constant dissipation only attenuation w/Q field.
dm : Function or float
The perturbation to the velocity model.
du : Function or float
Stores the computed perturbed wavefield.
Returns
----------
Function model perturbation dm, Receiver time series data rec,
TimeFunction background wavefield u0, TimeFunction perturbation wavefield du,
and performance summary
"""
# Get model perturbation Function or create
dm = dm or Function(name='dm', grid=self.model.grid,
space_order=self.space_order)
# Create the perturbation wavefield if not provided
du = du or TimeFunction(name='du', grid=self.model.grid,
time_order=2, space_order=self.space_order)
# Pick input physical parameters
kwargs.update(self.model.physical_params(vp=vp, damp=damp, b=b))
kwargs.update({'dt': kwargs.pop('dt', self.dt)})
# Run operator
summary = self.op_jacadj().apply(rec=rec, dm=dm, du=du, u0=u0, **kwargs)
return dm, u0, du, summary