From 9bb899d8678c4eb33cc19b24ca70cb6123a66a4b Mon Sep 17 00:00:00 2001 From: Adesina Lekan Samuel <98513928+limitless-100@users.noreply.github.com> Date: Fri, 4 Apr 2025 11:13:44 +0100 Subject: [PATCH 1/2] Update schroedinger.md * Corrected the wrong spellings of "Schrodinger" in a few instances * Added another code example (Dirac equation) * Improved the readability of the short text under the Schrodinger equation code. * Part of my future plans include exploring if MethodOfLines.jl can actually solve "all" linear complex PDEs in entirety. The main aim is to look for possible exceptions. --- docs/src/tutorials/schroedinger.md | 67 ++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/docs/src/tutorials/schroedinger.md b/docs/src/tutorials/schroedinger.md index 0e834a213..43e460971 100644 --- a/docs/src/tutorials/schroedinger.md +++ b/docs/src/tutorials/schroedinger.md @@ -1,7 +1,10 @@ -# Schrödinger Equation +# Linear Complex PDEs -MethodOfLines can solve linear complex PDEs like the Scrödinger equation: +MethodOfLines can solve many linear complex PDEs like Telegraph equation, Schrödinger equation, Dirac equation, et cetera. +## Examples + +### 1. Schrödinger Equation ```@example schro using MethodOfLines, OrdinaryDiffEq, Plots, DomainSets, ModelingToolkit @@ -48,4 +51,62 @@ gif(anim, "schroedinger.gif", fps = 10) Note that complex initial conditions are supported, but must be marked with a `=>` operator. -This represents the second from ground state of a particle in an infinite quantum well, try changing the potential `V(x)`, initial conditions and BCs, it is extremely interesting to see how the wave function evolves even for nonphysical combinations. Be sure to post interesting results on the discourse! +This represents the second from ground state of a particle in an infinite quantum well. Try changing the potential `V(x)`, initial conditions and boundary conditions to see how extremely interesting the wave function evolves even for nonphysical combinations. Be sure to post interesting results on the discourse! + + +### 2. Dirac Equation +```@example dirac + +# Dirac Equation in 1+1 Dimensions +using MethodOfLines, OrdinaryDiffEq, DomainSets, ModelingToolkit, Plots + +@parameters t, x +@variables u1(..) u2(..) # Components of the Dirac spinor + +Dt = Differential(t) +Dx = Differential(x) + +m = 1.0 # Mass term + +# Dirac equation in 1+1 dimensions (natural units: c = ħ = 1) +eqs = [ + Equation(Dt(u1(t, x)), -Dx(u2(t, x)) - m * u1(t, x)), + Equation(Dt(u2(t, x)), Dx(u1(t, x)) - m * u2(t, x)) +] + +# Initial conditions +u1_0(x) = exp(-10 * (x - 0.5)^2) +u2_0(x) = 0.0 + +xmin, xmax = 0, 1 +bcs = [ + Equation(u1(0, x), u1_0(x)), + Equation(u2(0, x), u2_0(x)), + Equation(u1(t, xmin), 0), + Equation(u1(t, xmax), 0), + Equation(u2(t, xmin), 0), + Equation(u2(t, xmax), 0) +] + +domains = [t ∈ Interval(0, 1), x ∈ Interval(xmin, xmax)] + +@named sys = PDESystem(eqs, bcs, domains, [t, x], [u1(t, x), u2(t, x)]) + +disc = MOLFiniteDifference([x => 100], t) +prob = discretize(sys, disc) +sol = solve(prob, TRBDF2(), saveat=0.01) + +discx = sol[x] +disct = sol[t] +disc_u1 = sol[u1(t, x)] +disc_u2 = sol[u2(t, x)] + +anim = @animate for i in 1:length(disct) + plot(discx, [disc_u1[i, :], disc_u2[i, :]], ylim=(-1, 1), title="t = $(disct[i])", + xlabel="x", ylabel="Ψ(t,x)", label=["u1 = Re(Ψ)" "u2 = Im(Ψ)"], legend=:topleft) +end +gif(anim, "dirac_equation.gif", fps=10) +``` +This shows the time evolution of the two components (`u_1` and `u_2`) of a Dirac spinor in 1+1 dimensions. By solving the Dirac equation with specific initial conditions and boundary conditions, we observe how the particle's wavefunction evolves over time. Experimenting with different initial conditions or mass values can reveal interesting behaviors of relativistic particles. + +Note that the Dirac equation can be viewed as a relativistic extension of Schrödinger equation. From 8a4bfba5b5089cfac05309698f03374951b96aa5 Mon Sep 17 00:00:00 2001 From: Adesina Lekan Samuel <98513928+limitless-100@users.noreply.github.com> Date: Fri, 4 Apr 2025 16:18:22 +0100 Subject: [PATCH 2/2] Update schroedinger.md Converting the "Equation" statements to ~ operators in order to maintain consistent writing style --- docs/src/tutorials/schroedinger.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/src/tutorials/schroedinger.md b/docs/src/tutorials/schroedinger.md index 43e460971..a7a3b2718 100644 --- a/docs/src/tutorials/schroedinger.md +++ b/docs/src/tutorials/schroedinger.md @@ -70,8 +70,8 @@ m = 1.0 # Mass term # Dirac equation in 1+1 dimensions (natural units: c = ħ = 1) eqs = [ - Equation(Dt(u1(t, x)), -Dx(u2(t, x)) - m * u1(t, x)), - Equation(Dt(u2(t, x)), Dx(u1(t, x)) - m * u2(t, x)) + Dt(u1(t, x)) ~ -Dx(u2(t, x)) - m * u1(t, x), + Dt(u2(t, x)) ~ Dx(u1(t, x)) - m * u2(t, x) ] # Initial conditions @@ -80,12 +80,12 @@ u2_0(x) = 0.0 xmin, xmax = 0, 1 bcs = [ - Equation(u1(0, x), u1_0(x)), - Equation(u2(0, x), u2_0(x)), - Equation(u1(t, xmin), 0), - Equation(u1(t, xmax), 0), - Equation(u2(t, xmin), 0), - Equation(u2(t, xmax), 0) + u1(0, x) ~ u1_0(x), + u2(0, x) ~ u2_0(x), + u1(t, xmin) ~ 0, + u1(t, xmax) ~ 0, + u2(t, xmin) ~ 0, + u2(t, xmax) ~ 0 ] domains = [t ∈ Interval(0, 1), x ∈ Interval(xmin, xmax)]