Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/tduretz/SeismicQ
Browse files Browse the repository at this point in the history
  • Loading branch information
jaolive committed Aug 25, 2023
2 parents b12b80f + 6350346 commit 4b28adc
Show file tree
Hide file tree
Showing 18 changed files with 1,150 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ version = "0.1.0"

[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
SymbolicNumericIntegration = "78aadeae-fbc0-11eb-17b6-c7ec0477ba9e"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SeismicQ

<h1> <img src="docs/src/assets/logo.png" alt="SeismicQ.jl" width="50"> SeismicQ </h1>

[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://tduretz.github.io/SeismicQ/dev/)
[![Build Status](https://github.com/tduretz/SeismicQ/workflows/CI/badge.svg)](https://github.com/tduretz/SeismicQ/actions)

<h1> <img src="docs/src/assets/visuel_ecocup2.png" alt="SeismicQ.jl" width="500"> </h1>
Binary file added docs/src/assets/visuel_ecocup2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ Ricker
```
```@docs
f_bulk
Spec
ComputeQgraph
Getfreq
```
89 changes: 89 additions & 0 deletions examples/FausseTrace.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Function that generates a seismic trace (Ricker function), attenuating along time,
# and plot a receiver gather (received waves at different geophone positions)

using SeismicQ, Plots, SpecialFunctions, LinearAlgebra, Printf

function main()

# Functtion that create a vector of time and
function FausseTrace(x,Ξ”t,Nt,t,Vp,Vs,Ξ±p,Ξ±s,𝑓₀,tβ‚€)

tβ‚“p = x/Vp
tβ‚“s = x/Vs

# Storage
time = zeros(Nt)
acc = zeros(Nt)

# Time loop
for it=1:Nt

# Compute Ricker function
t += Ξ”t
a = 0.5 * exp(-Ξ±p*x)*Ricker(t, tβ‚“p+tβ‚€, 𝑓₀)+ 0.5 * exp(-Ξ±s*x)*Ricker(t, tβ‚“s+tβ‚€, 𝑓₀)

# For visualisation purpose
time[it] = t
acc[it] = a
end

return(time',acc')

end

# Geophone position [m]
listβ‚“ = 0:100:5000;

# Time domain
Ξ”t = 1e-3
Nt = 2000
# Central frequency of the source [Hz]
𝑓₀ = 10.
tβ‚€ = 1.0/𝑓₀
t = -tβ‚€

# Velocities
Vp = 7000 # m/s
Vs = 4000
Ξ±p = 2e-4
Ξ±s = 4e-4 # (Ο€ * f)/ (Q * V)

time_axis = t:(Ξ”t*Nt-t)/(Nt-1):Ξ”t*Nt ;
time_vec = zeros(size(listβ‚“,1),Nt);
acc_vec = zeros(size(listβ‚“,1),Nt);
time_vec[1,:],acc_vec[1,:]= FausseTrace(listβ‚“[1,1],Ξ”t,Nt,t,Vp,Vs,Ξ±p,Ξ±s,𝑓₀,tβ‚€);
dist_axis = 0:1: size(listβ‚“,1)-1; # distances des geophones pour l instant 1,2,3,...

for i=1:size(listβ‚“,1)-1
time_vec[i+1,:],acc_vec[i+1,:] = FausseTrace(listβ‚“[i+1,1],Ξ”t,Nt,t,Vp,Vs,Ξ±p,Ξ±s,𝑓₀,tβ‚€)
end

seismic_matrix = hcat(listβ‚“,acc_vec);
@show size(seismic_matrix)
#=
# Visualisation si peu de positions
fig1 = plot(layout = (size(listβ‚“,1),1))
p1 = plot!(fig1[1],time_vec[1,:], acc_vec[1,:], xlabel="t", ylabel="a")
for i=1:size(listβ‚“,1)-1
p1 = plot!(fig1[i+1],time_vec[i+1,:], acc_vec[i+1,:], xlabel="t", ylabel="a")
end
display(fig1)
=#

# Visualisation of receiver gather
#p2 = heatmap(dist_axis,time_axis,acc_vec',
p2 = heatmap(listβ‚“,time_axis,acc_vec',
color=palette(:RdBu, 100, rev=true),
clim=(-0.5, 0.5),
cbar=true,
label=" ",
yflip=true,
title = "Receiver gather",
xlabel = "Geophone position [m]",
ylabel = "Time [s]")
display(plot(p2)) # equivalent du drawnow


end
main()
86 changes: 86 additions & 0 deletions examples/GetQTest.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using SeismicQ,Plots

function main()

#P and S velocities
Vp=7000
Vs=4000

SeismicMatrix=GenMatrix(Vp,Vs)

#distances from source
d1=3000
d2=5000

#Number of samples and time increment of traces
Nt=2000
dt=1e-3

#min and max frequencies to compute Q
fqmin=5.0
fqmax=20.0

Tmax=dt*Nt
time=[dt*i for i=1:Nt]

println("Trace length is $Tmax s using $Nt samples")

ind1=Int(trunc(d1/100))
ind2=Int(trunc(d2/100))

rec1=SeismicMatrix[ind1,2:Nt+1]
rec2=SeismicMatrix[ind2,2:Nt+1]

println("Trace 1 at offset $d1 m is found at index $ind1")
println("Trace 2 at offset $d2 m is found at index $ind2")

ampmin=-0.15
ampmax=0.3

p1=plot(time,rec1,xlabel="time (s)",ylabel="acc. (m.s⁻²)",ylim=(ampmin,ampmax),c=:"blue")
p2=plot(time,rec2,xlabel="time (s)",ylabel="acc. (m.s⁻²)",ylim=(ampmin,ampmax),c=:"red")

# second part rec1:
println("Trace 1:")

ampP,ampS,frequP,frequS=Spec(rec1,0.1,dt,Nt,0.4,0.75,0.35)

ymax=maximum(ampP)

p3=plot(frequP,ampP,title="P",xlabel="f(Hz)",ylabel="Amp",ylim=(0,ymax),c=:"blue")
p4=plot(frequS,ampS,title="S",xlabel="f(Hz)",ylabel="Amp",ylim=(0,ymax),c=:"blue")

#plot(p1,p3,p4,layout=(2,2))

# second part rec2:
println("Trace 2:")

ampP2,ampS2,frequP2,frequS2=Spec(rec2,0.1,dt,Nt,0.7,1.25,0.35)

p5=plot(frequP2,ampP2,title="P2",xlabel="f(Hz)",ylabel="Amp",ylim=(0,ymax),c=:"red")
p6=plot(frequS2,ampS2,title="S2",xlabel="f(Hz)",ylabel="Amp",ylim=(0,ymax),c=:"red")


@show frequP
indf=findall(x->x>fqmin && x<fqmax,frequP)
@show indf

#Qp=zeros(length(indf))

xp,yp=ComputeQgraph(ampP,ampP2,frequP,indf,d1,d2,Vp)

p7=plot(xp,yp,xlabel="f(Hz)",ylim=(-1.0,0.),title="Qgraph for P phase",c=:"green")

xs,ys=ComputeQgraph(ampS,ampS2,frequS,indf,d1,d2,Vs)

@show xs,ys

p8=plot(xs,ys,xlabel="f(Hz)",ylim=(-1.0,0.),title="Qgraph for S phase",c=:"green")


plot(p1,p2,p3,p5,p4,p6,p7,p8,layout=(4,2),legend=false)
#plot(p7,legend=false)

end

main()
File renamed without changes.
128 changes: 128 additions & 0 deletions examples/Wave1D_Sismo_Day4.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
using SeismicQ, Plots

function MainSource()

# Spatial extent
Lx = 50.0

# Mechanical parameters
ρ₀ = 1500.0
Kβ‚€ = 1.e9
Gβ‚€ = 1.e8
cβ‚€ = sqrt((Kβ‚€+4/3*Gβ‚€)/ρ₀)

# Discretization
Ncx = 200
Ξ”x = Lx/Ncx
xv = LinRange(0,Lx,Ncx+1)
xc = LinRange(0-Ξ”x/2,Lx+Ξ”x/2,Ncx+2)

# Source parameters
𝑓₀ = 200 # Central frequency of the source [Hz]
tβ‚€ = 1.2/𝑓₀
isrc = Int((Ncx/2)+1)

# Time domain
Ξ”t = min(1e10, Ξ”x/cβ‚€) # Courant criteria from wavespeed
Nt = 100
Nout = 10
t = 0.0#-tβ‚€

# Parameters for Sismo.
Xs = 25:0.5:50 # x_coordinates [m]
Ns = size(Xs,1)
ds = zeros(size(Xs))
@. ds = abs(Xs-xv[isrc])
velocity_matrix = zeros(Ns, Nt)
time = zeros(Nt)

# Storage on centers # +2 for ghost nodes for BCs
szv = (Ncx+1,)
szc = (Ncx+2,)
# Storage on centroids
K = ones(szc)*Kβ‚€
G = ones(szc)*Gβ‚€
Ξ΅Μ‡ = ( xx=zeros(szc), yy=zeros(szc), zz=zeros(szc), xy=zeros(szc), yz=zeros(szc), xz=zeros(szc) )
βˆ‡V = zeros(Ncx+2)
P = zeros(Ncx+2)
Ο„ = ( xx=zeros(szc), yy=zeros(szc), zz=zeros(szc), xy=zeros(szc), yz=zeros(szc), xz=zeros(szc) )
βˆ‚Vxβˆ‚x = zeros(szc)
# Storage on vertices
V = ( x=zeros(szv), y=zeros(szv), z=zeros(szv))
ρ = ones(szv)*ρ₀
f_ext = zeros(szv)

# BC
Lbc = 2.
bc_filtW_v = 1.0 .- exp.(-(xv.-0Lx).^2/Lbc.^2)
bc_filtW_c = 1.0 .- exp.(-(xc.-0Lx).^2/Lbc.^2)
bc_filtE_v = 1.0 .- exp.(-(xv.- Lx).^2/Lbc.^2)
bc_filtE_c = 1.0 .- exp.(-(xc.- Lx).^2/Lbc.^2)

# Time loop
@time for it=1:Nt

# Compute Ricker function
t += Ξ”t
a = Ricker(t, tβ‚€, 𝑓₀)
f_ext[isrc] = ρ[isrc]*a

# Velocity gradient components
@. βˆ‚Vxβˆ‚x[2:end-1] = (V.x[2:end] - V.x[1:end-1])/Ξ”x

# Divergence
@. βˆ‡V = βˆ‚Vxβˆ‚x

# Deviatoric strain rate
@. Ξ΅Μ‡.xx = βˆ‚Vxβˆ‚x - 1/3*βˆ‡V

# Stress update
@. Ο„.xx = f_shear(G)*Ξ”t*(Ξ΅Μ‡.xx) + f_relax(G)*Ο„.xx

# Pressure update
@. P = P - Ξ”t*f_bulk(K)*βˆ‡V

# Linear momentum balance
@. V.x[2:end-1] = V.x[2:end-1] + Ξ”t/ρ[2:end-1]*((Ο„.xx[3:end-1]-Ο„.xx[2:end-2])/Ξ”x - (P[3:end-1]-P[2:end-2])/Ξ”x - f_ext[2:end-1])

# Absorbing boundary Cerjean et al. (1985)
@. V.x = V.x * bc_filtW_v
@. P = P * bc_filtW_c
@. Ο„.xx = Ο„.xx * bc_filtW_c
@. V.x = V.x * bc_filtE_v
@. P = P * bc_filtE_c
@. Ο„.xx = Ο„.xx * bc_filtE_c

# Visualisation
if mod(it, Nout)==0
display(plot(xv, V.x, ylim=(-2e-4, 2e-4)))
sleep(0.1)
end

# Extract sismo data:
time[it] = t
@. velocity_matrix[:,it] = V.x[Int(Xs[:]/Ξ”x)+1]

end

# Visualization Receiver Gather:
valim = max(abs(maximum(velocity_matrix)),abs(minimum(velocity_matrix)))
p = heatmap(ds,time,velocity_matrix',color=palette(:RdBu,100,rev=true),
title="Receiver gather", xlabel="distance to the source [m]",
ylabel="time [s]",yflip=true,clim=(-valim,+valim))
display(p)

end

function f_bulk(K)
return K
end

function f_shear(G)
return 2*G
end
function f_relax(G)
return 1.
end

MainSource()
12 changes: 6 additions & 6 deletions examples/Wave2D_Day3.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SeismicQ, Plots
using SeismicQ, Plots,Classical

function MainSource()

Expand All @@ -22,7 +22,7 @@ function MainSource()


# Source parameters
𝑓₀ = 200 # Central frequency of the source [Hz]
𝑓₀ = 50 # Central frequency of the source [Hz]
tβ‚€ = 1.2/𝑓₀
isrc = Int((Nc.x/2)+1)
jsrc = Int((Nc.y/2)+1)
Expand Down Expand Up @@ -87,10 +87,10 @@ function MainSource()
@. L.i.yx[:,2:end-1] = (V.c.y[2:end,2:end-1] - V.c.y[1:end-1,2:end-1])/Ξ”.x
@. L.j.yx[2:end-1,:] = (V.v.y[2:end,:] - V.v.y[1:end-1,:])/Ξ”.x

@. L.i.yy[:,2:end-1] = (V.v.y[:,2:end] - V.v.y[:,2:end])/Ξ”.y
@. L.i.yy[:,2:end-1] = (V.v.y[:,2:end] - V.v.y[:,1:end-1])/Ξ”.y
@. L.j.yy[2:end-1,:] = (V.c.y[2:end-1,2:end] - V.c.y[2:end-1,1:end-1])/Ξ”.y

@. L.i.xy[:,2:end-1] = (V.v.x[:,2:end] - V.v.x[:,2:end])/Ξ”.y
@. L.i.xy[:,2:end-1] = (V.v.x[:,2:end] - V.v.x[:,1:end-1])/Ξ”.y
@. L.j.xy[2:end-1,:] = (V.c.x[2:end-1,2:end] - V.c.x[2:end-1,1:end-1])/Ξ”.y


Expand Down Expand Up @@ -149,14 +149,14 @@ function MainSource()
*((Ο„.j.xy[3:end-1,2:end-1]-Ο„.j.xy[2:end-2,2:end-1])/Ξ”.x
+ (Ο„.i.yy[2:end-1,3:end-1]-Ο„.i.yy[2:end-1,2:end-2])/Ξ”.y
- (P.i[2:end-1,3:end-1]-P.i[2:end-1,2:end-2])/Ξ”.y
- 0.0*f_ext.v[2:end-1,2:end-1]))
- f_ext.v[2:end-1,2:end-1]))

@. V.c.y[2:end-1,2:end-1] = (V.c.y[2:end-1,2:end-1]
+ Ξ”t/ρ.c[2:end-1,2:end-1]
*((Ο„.i.xy[2:end,2:end-1]-Ο„.i.xy[1:end-1,2:end-1])/Ξ”.x
+ (Ο„.j.yy[2:end-1,2:end]-Ο„.j.yy[2:end-1,1:end-1])/Ξ”.y
- (P.j[2:end-1,2:end]-P.j[2:end-1,1:end-1])/Ξ”.y
- 0.0*Xf_ext.c[2:end-1,2:end-1]))
- f_ext.c[2:end-1,2:end-1]))


# # Absorbing boundary Cerjean et al. (1985)
Expand Down
Loading

0 comments on commit 4b28adc

Please sign in to comment.