xxxxxxxxxx
78
//2d 1-Electron Ground State Time Dependent
let u = [];
let K = [];
let r = 0;
let norm = 0;
let N=100;
let dt;
let h;
let t=0;
function setup() {
createCanvas(400, 400);
h=1/N;
dt=0.3*pow(h,2);
for (var i=0;i<N+1;i++){
u[i]=[];
K[i]=[];
for (var j=0;j<N+1;j++){
u[i][j]=0; r=pow((i-50)/h,2)+pow((j-50)/h,2)+0.000001;
K[i][j]=5/sqrt(r);
}
}
for (var m=0;m<20;m++){
for (var n=0;n<20;n++){
u[40+m][40+n]=1;
}
}
}
function draw() {
background(220);
t=t+1000*dt;
noStroke();
norm = 0;
for (var i=1;i<N;i++){
for (var j=1;j<N;j++){
u[i][j]=u[i][j]+0.5*dt*(u[i+1][j]-4*u[i][j]+u[i-1][j]+u[i][j+1]+u[i][j-1])/pow(h,2)+dt*u[i][j]*K[i][j];
norm = norm + pow(u[i][j]*h,2);
}
}
for (var i=1;i<N;i++){
for (var j=1;j<N;j++){
u[i][j]=u[i][j]/sqrt(norm);
fill(255,0,0,100*u[i][j]);
square(4*i,4*j,4);
}
}
for (var i=1;i<N-1;i++){
fill(255,0,0,255);
ellipse(4*i,200-30*u[i][50],4);
fill(0,255,0,255);
ellipse(4*i,200-30*u[i][50]*cos(t),4);
fill(0,0,255,255);
ellipse(4*i,200-30*u[i][50]*sin(t),4);
}
fill(0);
text(norm,350,390);
ellipse(200,200,10);
text("norm(psi) = ",300,390);
text("attractive proton kernel",160,215);
text("2d 1-Electron Atom Ground State Wave Function Psi(x,t) solves",20,20);
text("i*dPsi/dt + HPsi =0, H = - 0.5*Laplacian - 1/r, r = 1/sqrt(x^2+y^2). ",50,40);
// text("Minimise sum of kinetic + potential energy:",20,60);
// text("integral (0.5*|grad(u)|^2 - u^2/K(x,y))dxdy ",50,90);
text("takes form Psi(x,t) = exp(i*E*t)*psi(x) = cos(E*t)*psi(x) + i*sin(E*t)*psi(x)",20,60);
text("with psi(x) eigenfunction of H satisfying Hpsi = E*psi, E smallest eigenvalue. ",0,80);
text("Compute psi by time stepping dpsi/dt+Hpsi=0 with normalisation",20,110)
text("norm(psi) = sqrt(integral psi^2dxdy) = 1 (*)",100,130);
text("See concentration of electron density psi^2 (red) towards kernel",20,250);
text("with concentration balanced by Laplacian (kinetic energy)",20,270);
text("red: eigenfunction psi, density, mid section",20,350);
text("blue, green: components of Psi, mid section",20,370);
text("See time dependency of Psi(x,t).",20,290);
text("Electron oscillates (Psi), electron density (psi) stationary.",20,310);
stroke(0);
line(0,200,400,200);
}