Public
Edited
Nov 13, 2024
Importers
5 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
psi_dt = function (psi, expV, expK, expABC) {
psi = cmultiply(psi, expV) // step 1
psi = nj.fft(psi) // step 2 - FT
psi = cmultiply(psi, expK) // step 2
psi = nj.ifft(psi) // step 2 - Inverse FT
psi = cmultiply(psi, expV) // step 3
psi = cmultiply(psi, expABC) // Absorbing boundary condition
return psi
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
x = nj.arange(numx).multiply(dx).subtract(xmax).reshape(numx,1)
Insert cell
Insert cell
k = fftfreq(x)
Insert cell
Insert cell
Insert cell
expK = cexp(k.pow(2).multiply(-dt))
Insert cell
V = x.pow(2)
Insert cell
expV = cexp(V.multiply(-dt/2))
Insert cell
expABC = {
let absorb = nj.tanh(x.subtract(xmax).divide(w)).add(2).subtract(nj.tanh(x.add(xmax).divide(w))).multiply(-lambda*dt)
let expABC = nj.exp(absorb)
expABC = nj.concatenate(expABC, nj.zeros([numx,1]) ) // need to add 2nd column of zeros for the zero imaginary part
return expABC

}
Insert cell
Insert cell
Insert cell
psi0 = nj.concatenate(nj.exp(x.subtract(1).pow(2).multiply(-1)), nj.zeros([numx,1]) ).multiply(Math.pow(2 / Math.PI, 0.25))
Insert cell
Insert cell
psi0_squared = cnorm2(psi0).multiply(10) // x10 to make it more visible on the plot
Insert cell
Insert cell
mutable psi=psi0 // This sets the initial condition for the simulation of psi

// Note, for more info on "mutable" see https://observablehq.com/@mbostock/mutable-values
Insert cell
{
if(simulate===true) { // Only simulate when simulation checkbox has been checked
mutable psi = psi_dt(psi, expV, expK, expABC) // This runs the simulation indefinitely
}
return "Indefinite simulation loop"
}
Insert cell
psi_squared = cnorm2(psi).multiply(10) // x10 to make it more visible on the plot
Insert cell
Insert cell
graph.update([x,psi_squared,V])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more