ADFWI.propagator

ADFWI.propagator.acoustic_kernels

ADFWI.propagator.acoustic_kernels.forward_kernel(nx: int, nz: int, dx: float, dz: float, nt: int, dt: float, nabc: int, free_surface: bool, src_x: Tensor, src_z: Tensor, src_n: int, src_v: Tensor, rcv_x: Tensor, rcv_z: Tensor, rcv_n: int, damp: Tensor, v: Tensor, rho: Tensor, checkpoint_segments: int = 1, device: device = device(type='cpu'), dtype: dtype = torch.float32) Dict[str, Tensor][source]

Forward simulation of Acoustic Waveform Equation.

Parameters:
  • nx (int) – Number of grid points along the X-axis.

  • nz (int) – Number of grid points along the Z-axis.

  • dx (float) – Grid spacing along the X-axis.

  • dz (float) – Grid spacing along the Z-axis.

  • nt (int) – Number of time points for recording waveforms.

  • dt (float) – Time spacing (unit: s).

  • nabc (int) – Number of absorbing boundary conditions.

  • free_surface (bool) – Indicates if there’s a free surface.

  • src_x (torch.Tensor) – Source locations along the X-axis.

  • src_z (torch.Tensor) – Source locations along the Z-axis.

  • src_n (int) – Number of sources.

  • src_v (torch.Tensor) – Wavelets for each source.

  • rcv_x (torch.Tensor) – Receiver locations along the X-axis.

  • rcv_z (torch.Tensor) – Receiver locations along the Z-axis.

  • rcv_n (int) – Number of receivers.

  • damp (torch.Tensor) – Damping tensor for the absorbing boundary.

  • v (torch.Tensor) – P-wave velocity (km/s).

  • rho (torch.Tensor) – Density (kg/m^3).

  • checkpoint_segments (int, optional) – Segments of the checkpoints for saving memory (default is 1).

  • device (torch.device, optional) – Device type, default is “cpu”.

  • dtype (torch.dtype, optional) – Data type for tensors, default is torch.float32.

Returns:

record_waveform – Dictionary containing recorded waveforms and forward wavefields: Recorded vertical velocity at the receivers, Recorded horizontal velocity at the receivers, Forward wavefield of pressure, Forward wavefield of vertical velocity, Forward wavefield of horizontal velocity.

Return type:

dict

ADFWI.propagator.acoustic_propagator

class ADFWI.propagator.acoustic_propagator.AcousticPropagator(model: AbstractModel, survey: Survey, device: str | None = 'cpu', cpu_num: int | None = 1, gpu_num: int | None = 1, dtype: dtype = torch.float32)[source]

Bases: Module

Defines the propagator for the isotropic acoustic wave equation (stress-velocity form), solved by the finite difference method.

Parameters:
  • model (AbstractModel) – The model object that defines the physical properties of the medium.

  • survey (Survey) – The survey object containing the source and receiver information.

  • device (str, optional) – The device type for the computation. Default is ‘cpu’.

  • cpu_num (int, optional) – The number of CPU threads to use. Default is 1.

  • gpu_num (int, optional) – The number of GPU devices to use. Default is 1.

  • dtype (torch.dtype, optional) – The data type for tensors. Default is torch.float32.

boundary_condition(vmax=None)[source]

Set boundary conditions based on the specified ABC type.

forward(model: AbstractModel | None = None, shot_index: int | None = None, checkpoint_segments: int = 1) Dict[str, Tensor][source]

Forward simulation for selected shots.

Parameters:
  • model (Optional[AbstractModel], optional) – Model to use for simulation. If not provided, defaults to the instance’s model.

  • shot_index (Optional[int], optional) – Index of the shot to simulate.

  • checkpoint_segments (int, optional) – Number of segments for checkpointing to save memory. Default is 1.

Returns:

record_waveform – Dictionary containing recorded waveforms.

Return type:

dict

training: bool

ADFWI.propagator.elastic_kernels

ADFWI.propagator.elastic_kernels.forward_kernel(nx: int, nz: int, dx: float, dz: float, nt: int, dt: float, nabc: int, free_surface: bool, src_x: Tensor, src_z: Tensor, src_n: int, src_v: Tensor, MT: Tensor, rcv_x: Tensor, rcv_z: Tensor, rcv_n: int, abc_type: str, bcx: Tensor, bcz: Tensor, damp: Tensor, lamu: Tensor, lam: Tensor, bx: Tensor, bz: Tensor, CC: List[Tensor], fd_order=4, n_segments=1, device: device = device(type='cpu'), dtype=torch.float32)[source]

Perform the forward wavefield simulation for a given elastic model using finite difference method.

Parameters:
  • nx (int) – Number of grid points in the x direction.

  • nz (int) – Number of grid points in the z direction.

  • dx (float) – Grid spacing in the x direction.

  • dz (float) – Grid spacing in the z direction.

  • nt (int) – Number of time steps in the simulation.

  • dt (float) – Time step size.

  • nabc (int) – Size of the absorbing boundary layer (PML/ABL).

  • free_surface (bool) – Flag indicating whether the model includes a free surface.

  • src_x (Tensor) – Tensor containing the x-coordinates of the sources.

  • src_z (Tensor) – Tensor containing the z-coordinates of the sources.

  • src_n (int) – Number of sources.

  • src_v (Tensor) – Tensor containing the source wavefield values.

  • MT (Tensor) – Source type tensor (e.g., moment tensor).

  • rcv_x (Tensor) – Tensor containing the x-coordinates of the receivers.

  • rcv_z (Tensor) – Tensor containing the z-coordinates of the receivers.

  • rcv_n (int) – Number of receivers.

  • abc_type (str) – Type of absorbing boundary condition (‘pml’ or ‘abl’).

  • bcx (Tensor) – PML damping profile in the x direction.

  • bcz (Tensor) – PML damping profile in the z direction.

  • damp (Tensor) – Damping function for ABL.

  • lamu (Tensor) – Lame’s first parameter.

  • lam (Tensor) – Lame’s second parameter.

  • bx (Tensor) – Elasticity coefficient for the x direction.

  • bz (Tensor) – Elasticity coefficient for the z direction.

  • CC (List[Tensor]) – List containing the elastic moduli tensors [C11, C13, C15, C33, C35, C55].

  • fd_order (int, optional) – The finite difference scheme order, default is 4.

  • n_segments (int, optional) – Number of segments to split the source wavefield into, default is 1.

  • device (torch.device, optional) – The device to run the simulation on, default is ‘cpu’.

  • dtype (torch.dtype, optional) – The data type for the tensors, default is torch.float32.

Returns:

A dictionary containing the recorded waveforms at receivers and the forward wavefield.

Return type:

Dict[str, torch.Tensor]

ADFWI.propagator.elastic_propagator

class ADFWI.propagator.elastic_propagator.ElasticPropagator(model: AbstractModel, survey: Survey, device: str | None = 'cpu', cpu_num: int | None = 1, gpu_num: int | None = 1, dtype=torch.float32)[source]

Bases: Module

The class of defining the propagator for the isotropic elastic wave equation (stress-velocity form), which is solved by the finite difference method.

Parameters:
  • model (AbstractModel) – The model object, which contains the properties of the physical model (e.g., velocity, density).

  • survey (Survey) – The survey object, which contains information about the source and receiver locations and wavelet.

  • device (Optional[str], default='cpu') – The device to run the computation on. Can be ‘cpu’ for CPU or ‘cuda’ for GPU.

  • cpu_num (Optional[int], default=1) – The number of CPU cores to use for parallel computations.

  • gpu_num (Optional[int], default=1) – The number of GPUs to use for parallel computations. Should be set according to available GPU resources.

  • dtype (torch.dtype, default=torch.float32) – The data type of the tensors. Typically torch.float32 for balance between performance and precision.

boundary_condition()[source]

Set boundary conditions based on the specified ABC type.

forward(model: AbstractModel | None = None, shot_index=None, fd_order=4, checkpoint_segments=1)[source]

Perform a forward simulation using finite difference method for the elastic wave equation.

Parameters:
  • model (Optional[AbstractModel]) – The model for the simulation. If None, use the default model.

  • shot_index (Optional[int]) – Index of the shot for which to compute the waveform.

  • fd_order (int) – The order of the finite difference method (default is 4).

  • checkpoint_segments (int) – The number of segments for saving intermediate states (default is 1).

Returns:

record_waveform – The recorded waveforms at the receiver locations.

Return type:

torch.Tensor

training: bool

ADFWI.propagator.boundary_condition

ADFWI.propagator.boundary_condition.bc_gerjan(nx, nz, dx, dz, pml, alpha=0.0053, free_surface=True)[source]

PML implementation based on Gerjan et al., 1985, where the damping profile is defined as G = exp(a * [I - i]^2), with ‘a’ as the attenuation factor.

Parameters:
  • nx (int) – Number of grid points along the x-axis.

  • nz (int) – Number of grid points along the z-axis.

  • dx (float) – Grid spacing along the x-axis.

  • dz (float) – Grid spacing along the z-axis.

  • pml (int) – The width of the PML region (number of grid points).

  • alpha (float, optional) – The attenuation factor, default is 0.0053.

  • free_surface (bool, optional) – If True, assume a free surface at the top of the model. Default is True.

Returns:

damp – The damping profile applied across the grid in both x and z directions.

Return type:

numpy.ndarray

ADFWI.propagator.boundary_condition.bc_pml(nx, nz, dx, dz, pml, vmax, free_surface=True)[source]

Calculate the damping in both x and z directions for the Perfectly Matched Layer (PML).

Parameters:
  • nx (int) – Number of grid points along the x-axis.

  • nz (int) – Number of grid points along the z-axis.

  • dx (float) – Grid spacing along the x-axis.

  • dz (float) – Grid spacing along the z-axis.

  • pml (int) – The width of the PML region (number of grid points).

  • vmax (float) – Maximum velocity in the model.

  • free_surface (bool, optional) – If True, assume a free surface at the top of the model. Default is True.

Returns:

damp_global – The damping profile for both x and z directions, applied across the grid.

Return type:

numpy.ndarray

ADFWI.propagator.boundary_condition.bc_pml_xz(nx, nz, dx, dz, pml, vmax, free_surface=True)[source]

Calculate the damping coefficients for both x and z directions using the PML (Perfectly Matched Layer) method. The damping is applied to the boundaries in both directions (x and z).

Parameters:
  • nx (int) – Number of grid points along the x-axis.

  • nz (int) – Number of grid points along the z-axis.

  • dx (float) – Grid spacing along the x-axis.

  • dz (float) – Grid spacing along the z-axis.

  • pml (int) – The width of the PML region (number of grid points).

  • vmax (float) – Maximum wave velocity in the model.

  • free_surface (bool, optional) – If True, assume a free surface at the top of the model. Default is True.

Returns:

  • BCx (numpy.ndarray) – The damping profile applied to the x boundaries.

  • BCz (numpy.ndarray) – The damping profile applied to the z boundaries.

ADFWI.propagator.boundary_condition.bc_sincos(nx, nz, dx, dz, pml, free_surface=False)[source]

Set up a damping profile using a sine-cosine function for the Perfectly Matched Layer (PML).

Parameters:
  • nx (int) – Number of grid points along the x-axis.

  • nz (int) – Number of grid points along the z-axis.

  • dx (float) – Grid spacing along the x-axis.

  • dz (float) – Grid spacing along the z-axis.

  • pml (int) – The width of the PML region (number of grid points).

  • free_surface (bool, optional) – If True, assume a free surface at the top of the model. Default is False.

Returns:

damp – The damping profile applied across the grid in both x and z directions.

Return type:

numpy.ndarray

ADFWI.propagator.gradient_process

class ADFWI.propagator.gradient_process.GradProcessor(grad_mute=0, grad_smooth=0, grad_mask=None, norm_grad=True, forw_illumination=True, marine_or_land='land')[source]

Bases: object

Class for processing gradients, applying various gradient manipulation techniques such as masking, tapering, smoothing, and normalization.

Parameters:
  • grad_mute (int, optional) – Size of the gradient mute zone (default is 0).

  • grad_smooth (int, optional) – Size of the smoothing window (default is 0).

  • grad_mask (ndarray, optional) – A mask to apply to the gradient (default is None).

  • norm_grad (bool, optional) – Whether to normalize the gradient (default is True).

  • forw_illumination (bool, optional) – Whether to apply the forward illumination (default is True).

  • marine_or_land (str, optional) – Defines the environment (‘marine’ or ‘land’, default is ‘land’).

forward(nx, nz, vmax, grad, forw=None)[source]

Processes the gradient by applying tapering, masking, smoothing, and normalization.

Parameters:
  • nx (int) – The number of grid points in the horizontal (x) direction.

  • nz (int) – The number of grid points in the vertical (z) direction.

  • vmax (float) – The maximum value of the gradient, used for normalization.

  • grad (ndarray) – The gradient to be processed.

  • forw (ndarray, optional) – The forward model, used for applying forward illumination (default is None).

Returns:

grad – The processed gradient after applying all operations (mute, mask, smoothing, etc.).

Return type:

ndarray

ADFWI.propagator.gradient_process.gauss2(X, Y, mu, sigma, normalize=True)[source]

Evaluates the 2D Gaussian function over the points X and Y.

Parameters:
  • X (ndarray) – A 1D array of x coordinates where the Gaussian function will be evaluated.

  • Y (ndarray) – A 1D array of y coordinates where the Gaussian function will be evaluated.

  • mu (ndarray) – A 1D array of length 2, representing the mean (mu_x, mu_y) of the Gaussian distribution.

  • sigma (ndarray) – A 2x2 array representing the covariance matrix of the Gaussian distribution.

  • normalize (bool, optional, default=True) – Whether to normalize the Gaussian function (i.e., to ensure the integral over all space equals 1).

Returns:

Z – The evaluated Gaussian function at the points (X, Y).

Return type:

ndarray

ADFWI.propagator.gradient_process.grad_taper(nz, nx, tapersize=20, thred=0.05, marine_or_land='marine')[source]

Creates a tapering function for gradient damping, typically used for applying boundary conditions or damping regions in wave propagation models.

Parameters:
  • nz (int) – The number of grid points in the vertical (z) direction.

  • nx (int) – The number of grid points in the horizontal (x) direction.

  • tapersize (int, optional) – The size of the tapering region. Default is 20.

  • thred (float, optional) – The threshold value for the tapering effect. Default is 0.05.

  • marine_or_land (str, optional) – Specifies the type of environment. ‘marine’ or ‘Offshore’ for water (marine) or other values for land environments. Default is ‘marine’.

Returns:

taper – A 2D array representing the tapering function applied to the grid. It has values between 0 and 1, with the boundary regions having lower values.

Return type:

ndarray

ADFWI.propagator.gradient_process.smooth2d(Z, span=10)[source]

Smooths values on a 2D rectangular grid using a Gaussian filter.

Parameters:
  • Z (ndarray) – A 2D array representing the values to be smoothed (input grid).

  • span (int, optional) – The span or size of the Gaussian filter, which determines the extent of smoothing. Default is 10.

Returns:

Z – A 2D array with the smoothed values.

Return type:

ndarray