API Reference

Data Structure

ADSeismic.ElasticSourceType
mutable struct ElasticSource
    srci::Union{Array{Int64, 1},PyObject}
    srcj::Union{Array{Int64, 1},PyObject}
    srctype::Union{Array{Int64, 1},PyObject}
    srcv::Union{Array{Float64, 2},PyObject}
end

Add source terms to different components according to srctype

  • 0: vx
  • 1: vy
  • 2: σxx
  • 3: σyy
  • 4: σxy
source

Simulation

ADSeismic.AcousticPropagatorSolverMethod

AcousticPropagatorSolver(param::AcousticPropagatorParams, src::AcousticSource, c::Union{PyObject, Array{Float64, 2}})

Arguments

  • 'param::AcousticPropagatorParams': model configuration parameters, such as NX, NT
  • 'src::AcousticSource': source locations
  • 'c::Union{PyObject, Array{Float64, 2}}': velocity model

Return

  • 'AcousticPropagator': forward calculation results, like displacement u
source
ADSeismic.SimulatedObservation!Method
SimulatedObservation!(ap::AcousticPropagator, rcv::AcousticReceiver)

Extract and save simulated displacement u into rcv::AcousticReceiver.

source
ADSeismic.pml_helperMethod
pml_helper(x::Float64, y::Float64, param::AcousticPropagatorParams)

Computing the PML profile.

source

I/O

ADSeismic.load_acoustic_modelMethod

loadacousticmodel(filename::String; inv_vp::Bool = false, kwargs...)

Load acoustic model from a MAT file.

Arguments

  • 'filename::String': MAT filename
  • 'inv_vp::Bool': inversion of velocity (default: false)

Return

  • AcousticPropagatorSolver(src::AcousticSource)
source

Utilities

ADSeismic.RickerFunction
Ricker(epp::Union{ElasticPropagatorParams, AcousticPropagatorParams}, 
a::Union{PyObject, <:Real}, 
shift::Union{PyObject, <:Real}, 
amp::Union{PyObject, <:Real}=1.0)

Returns a Ricker wavelet (a tensor).

  • epp: a ElasticPropagatorParams or an AcousticPropagatorParams
  • a: Width parameter
  • shift: Center of the Ricker wavelet
  • amp: Amplitude of the Ricker wavelet

\[f(x) = \mathrm{amp}A (1 - x^2/a^2) exp(-x^2/2 a^2)\]

where

\[A = 2/sqrt(3a)pi^1/4\]

source
ADSeismic.compute_loss_and_grads_GPUMethod
compute_loss_and_grads_GPU(model::Function, src::Union{Array{AcousticSource},Array{ElasticSource}},
rcv_sim::Union{Array{AcousticReceiver}, Array{ElasticReceiver}}, Rs::Array{Array{Float64}}, vs::Union{PyObject, Array{PyObject}})

Computes the loss and the gradients of the model on all available GPUs.

source
ADSeismic.visualize_wavefieldMethod
visualize_wavefield(val::Array{Float64, 3}, 
    param::Union{ElasticPropagatorParams,AcousticPropagatorParams})
visualize_wavefield(val::Array{Array{Float64, 3}, 1}, 
    param::Union{MPIAcousticPropagatorParams, MPIElasticPropagatorParams})

Visualizes the wavefield and returns the handle of the animation. You can save the animation to gif via

p = visualize_wavefield(...)
saveanim(p, "myfigure.gif")
source

Optimization

ADSeismic.LBFGS!Function
LBFGS!(sess::PyObject, loss::PyObject, max_iter::Int64=15000; 
vars::Array{PyObject}=PyObject[], callback::Union{Function, Nothing}=nothing, kwargs...)

BFGS! is a simplified interface for BFGS optimizer. See also ScipyOptimizerInterface. callback is a callback function with signature

callback(vs::Array, iter::Int64, loss::Float64)

vars is an array consisting of tensors and its values will be the input to vs.

Example 1

a = Variable(1.0)
loss = (a - 10.0)^2
sess = Session(); init(sess)
BFGS!(sess, loss)

Example 2

θ1 = Variable(1.0)
θ2 = Variable(1.0)
loss = (θ1-1)^2 + (θ2-2)^2
cb = (vs, iter, loss)->begin 
    printstyled("[#iter $iter] θ1=$(vs[1]), θ2=$(vs[2]), loss=$loss\n", color=:green)
end
sess = Session(); init(sess)
cb(run(sess, [θ1, θ2]), 0, run(sess, loss))
BFGS!(sess, loss, 100; vars=[θ1, θ2], callback=cb)

Example 3

Use bounds to specify upper and lower bound of a variable.

x = Variable(2.0)    
loss = x^2
sess = Session(); init(sess)
BFGS!(sess, loss, bounds=Dict(x=>[1.0,3.0]))
source
ADSeismic.LBFGS!Function
LBFGS!(value_and_gradients_function::Function, initial_position::Union{PyObject, Array{Float64}}, max_iter::Int64=50, args...;kwargs...)

Applies the BFGS optimizer to value_and_gradients_function

source
ADSeismic.LBFGS!Method
LBFGS!(sess::PyObject, loss::PyObject, grads::Union{Array{T},Nothing,PyObject}, 
vars::Union{Array{PyObject},PyObject}; kwargs...) where T<:Union{Nothing, PyObject}

Running BFGS algorithm $\min_{\texttt{vars}} \texttt{loss}(\texttt{vars})$ The gradients grads must be provided. Typically, grads[i] = gradients(loss, vars[i]). grads[i] can exist on different devices (GPU or CPU).

Example 1

import Optim # required
a = Variable(0.0)
loss = (a-1)^2
g = gradients(loss, a)
sess = Session(); init(sess)
BFGS!(sess, loss, g, a)

Example 2

import Optim # required
a = Variable(0.0)
loss = (a^2+a-1)^2
g = gradients(loss, a)
sess = Session(); init(sess)
cb = (vs, iter, loss)->begin 
    printstyled("[#iter $iter] a = $vs, loss=$loss\n", color=:green)
end
BFGS!(sess, loss, g, a; callback = cb)
source