Skip to content

Commit

Permalink
Merge pull request #16 from ajarifi/main
Browse files Browse the repository at this point in the history
add Delta potential
  • Loading branch information
ohno committed Feb 8, 2024
2 parents 1956fdc + d229b00 commit 84b5755
Show file tree
Hide file tree
Showing 15 changed files with 723 additions and 23 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ This is the guideline for adding new models.
6. Write the code in that file. First we need to create a structure `struct ModelName` with the same name as the model name (The best way is Find & Replace). Create V, E, ψ and other functions. Because the function names conflict, you must always give the structure as an argument. Multi-dispatch avoids conflict. We recommend using Revice.jl while coding. Run `include("./developer/revice.jl")` on the REPL or use dev.ipynb.
7. Add test code test/ModelName.jl. At a minimum, it is recommended to check the normalization and the orthogonality of wavefunction using QuadGK.jl. All tests will be executed by executing `include("./developer/test.jl")`. It will take about 2 minutes to complete.
8. Add documentation. Add either docs/ModelName.md or docs/jmd/ModelName.jmd (if you have a jmd file, the md file will be automatically generated). Include at least the definition of the Hamiltonian and the analytical solutions (eigenvalues and eigenfunctions).
9. Execute `include("./developer/docs.jl")` to compile. Please check docs/build/*.html in your browser.
10. Push the code.
11. Submit a pull request on GitHub.
9. Add the new model into `pages=[...]` in docs/make.jl.
10. Execute `include("./developer/docs.jl")` to compile. Please check docs/build/*.html in your browser.
11. Push the code.
12. Submit a pull request on GitHub.

## Acknowledgment

Expand Down
356 changes: 343 additions & 13 deletions developer/dev.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/jmd2md.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Antique
using Weave

for file in Antique.models # [:InfinitePotentialWell :HarmonicOscillator :MorsePotential :HydrogenAtom]
for file in Antique.models # [:DeltaPotential]
weave("./src/jmd/$file.jmd", doctype="github", out_path="./src/", fig_path="./assets/fig/")
text = Antique.load("./src/$file.md")
# remove ``` after include(...s)
Expand Down
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ makedocs(;
"Harmonic Oscillator" => "HarmonicOscillator.md" ,
"Morse Potential" => "MorsePotential.md" ,
"Hydrogen Atom" => "HydrogenAtom.md" ,
"Delta Potential" => "DeltaPotential.md" ,
],
)

Expand Down
139 changes: 139 additions & 0 deletions docs/src/DeltaPotential.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
```@meta
CurrentModule = Antique
```

# Delta Potential

The Delta potential is one of the simplest models for quantum mechanical system in 1D.
It always has one bound state and its wave function has a cusp at the origin.

## Defitions

This model is described with the time-independent Schrödinger equation

```math
\hat{H} \psi(x) = E \psi(x),
```

and the Hamiltonian
```math
\hat{H} = - \frac{\hbar^2}{2m} \frac{\mathrm{d}^2}{\mathrm{d}x ^2} + V(x).
```

Parameters are specified with the following struct.

#### Parameters

```@docs
DeltaPotential
```

#### Potential
```@docs
V(::DeltaPotential)
```

#### Eigen Values
```@docs
E(::DeltaPotential)
```

#### Eigen Functions
```@docs
ψ(::DeltaPotential)
```

## Usage & Examples

[Install Antique.jl](@ref Install) for the first use and run `using Antique` before each use. The energy `E()`, wavefunction `ψ()`, potential `V()` and some other functions are suppoted. In this system, the model is generated by `DeltaPotential` and several parameters `α`, `m` and `` are set as optional arguments.

```julia
using Antique
DP = DeltaPotential=1.0, m=1.0, ℏ=1.0)
```




Parameters:

```julia
julia> DP.α
1.0

julia> DP.m
1.0

julia> DP.
1.0
```



Eigen values:

```julia
julia> E(DP)
-0.5
```



Wave functions:

```julia
DP = DeltaPotential=0.1, m=0.5, ℏ=0.1)
x = LinRange(-2,2,500);

using Plots
plot(x, x->ψ(DP,x), linewidth=3)
plot!(xlim=[-2,2], ylim=[0,2.5], legend=false)
plot!(xlabel="x", ylabel="ψ(x)", title="Delta Potential")
```

![](./assets/fig//DeltaPotential_4_1.png)



## Testing

Unit testing and Integration testing were done using numerical integration ([QuadGK.jl](https://juliamath.github.io/QuadGK.jl/stable/)). The test script is [here](https://github.com/ohno/Antique.jl/blob/main/test/DeltaPotential.jl).

#### Normalization of $\psi(x)$

```math
\int_{-\infty}^{\infty} \psi^\ast(x) \psi(x) ~\mathrm{d}x = 1
```

```
α | m | ℏ | analytical | numerical
--- | --- | --- | ----------------- | -----------------
0.1 | 0.1 | 0.1 | 1.000000000000 | 1.000000000000 ✔
0.1 | 0.1 | 1.0 | 1.000000000000 | 1.000000000000 ✔
0.1 | 0.1 | 7.0 | 1.000000000000 | 1.000004676239 ✔
0.1 | 1.0 | 0.1 | 1.000000000000 | 1.000000000000 ✔
0.1 | 1.0 | 1.0 | 1.000000000000 | 1.000000000000 ✔
0.1 | 1.0 | 7.0 | 1.000000000000 | 0.999999999999 ✔
0.1 | 7.0 | 0.1 | 1.000000000000 | 1.000000000000 ✔
0.1 | 7.0 | 1.0 | 1.000000000000 | 1.000000000000 ✔
0.1 | 7.0 | 7.0 | 1.000000000000 | 1.000000000000 ✔
1.0 | 0.1 | 0.1 | 1.000000000000 | 1.000000000000 ✔
1.0 | 0.1 | 1.0 | 1.000000000000 | 1.000000000000 ✔
1.0 | 0.1 | 7.0 | 1.000000000000 | 0.999999999999 ✔
1.0 | 1.0 | 0.1 | 1.000000000000 | 1.000000000000 ✔
1.0 | 1.0 | 1.0 | 1.000000000000 | 1.000000000000 ✔
1.0 | 1.0 | 7.0 | 1.000000000000 | 1.000000000000 ✔
1.0 | 7.0 | 0.1 | 1.000000000000 | 1.000000000000 ✔
1.0 | 7.0 | 1.0 | 1.000000000000 | 1.000000000000 ✔
1.0 | 7.0 | 7.0 | 1.000000000000 | 1.000000000000 ✔
7.0 | 0.1 | 0.1 | 1.000000000000 | 1.000000000000 ✔
7.0 | 0.1 | 1.0 | 1.000000000000 | 1.000000000000 ✔
7.0 | 0.1 | 7.0 | 1.000000000000 | 1.000000000000 ✔
7.0 | 1.0 | 0.1 | 1.000000000000 | 1.000000000000 ✔
7.0 | 1.0 | 1.0 | 1.000000000000 | 1.000000000000 ✔
7.0 | 1.0 | 7.0 | 1.000000000000 | 1.000000000000 ✔
7.0 | 7.0 | 0.1 | 1.000000000000 | 1.000000000000 ✔
7.0 | 7.0 | 1.0 | 1.000000000000 | 1.000000000000 ✔
7.0 | 7.0 | 7.0 | 1.000000000000 | 1.000000000000 ✔
```
2 changes: 1 addition & 1 deletion docs/src/InfinitePotentialWell.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The infinite potential well (particle in a box) is the simplest model for quantu

#### Hamiltonian
```math
\hat{H} = \frac{\hbar^2}{2m} \frac{\mathrm{d}^2}{\mathrm{d}x ^2} + V(x)
\hat{H} = - \frac{\hbar^2}{2m} \frac{\mathrm{d}^2}{\mathrm{d}x ^2} + V(x)
```

#### Potential
Expand Down
Binary file added docs/src/assets/fig/DeltaPotential_4_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 10 additions & 3 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ There are more examples on each model page.
</a>
<code>HydrogenAtom</code>
</div>
<div class="item">
<a target="_blank" href="./DeltaPotential">
<img src="assets/fig/DeltaPotential_4_1.png" alt="DeltaPotential"/>
</a>
<code>DeltaPotential</code>
</div>
</div>
```

Expand All @@ -89,9 +95,10 @@ This is the guideline for adding new models.
6. Write the code in that file. First we need to create a structure `struct ModelName` with the same name as the model name (The best way is Find & Replace). Create V, E, ψ and other functions. Because the function names conflict, you must always give the structure as an argument. Multi-dispatch avoids conflict. We recommend using Revice.jl while coding. Run `include("./developer/revice.jl")` on the REPL or use dev.ipynb.
7. Add test code test/ModelName.jl. At a minimum, it is recommended to check the normalization and the orthogonality of wavefunction using QuadGK.jl. All tests will be executed by executing `include("./developer/test.jl")`. It will take about 2 minutes to complete.
8. Add documentation. Add either docs/ModelName.md or docs/jmd/ModelName.jmd (if you have a jmd file, the md file will be automatically generated). Include at least the definition of the Hamiltonian and the analytical solutions (eigenvalues and eigenfunctions).
9. Execute `include("./developer/docs.jl")` to compile. Please check docs/build/*.html in your browser.
10. Push the code.
11. Submit a pull request on GitHub.
9. Add the new model into `pages=[...]` in docs/make.jl.
10. Execute `include("./developer/docs.jl")` to compile. Please check docs/build/*.html in your browser.
11. Push the code.
12. Submit a pull request on GitHub.

## Acknowledgment

Expand Down
87 changes: 87 additions & 0 deletions docs/src/jmd/DeltaPotential.jmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
```@meta
CurrentModule = Antique
```

# Delta Potential

The Delta potential is one of the simplest models for quantum mechanical system in 1D.
It always has one bound state and its wave function has a cusp at the origin.

## Defitions

This model is described with the time-independent Schrödinger equation

```math
\hat{H} \psi(x) = E \psi(x),
```

and the Hamiltonian
```math
\hat{H} = - \frac{\hbar^2}{2m} \frac{\mathrm{d}^2}{\mathrm{d}x ^2} + V(x).
```

Parameters are specified with the following struct.

#### Parameters

```@docs
DeltaPotential
```

#### Potential
```@docs
V(::DeltaPotential)
```

#### Eigen Values
```@docs
E(::DeltaPotential)
```

#### Eigen Functions
```@docs
ψ(::DeltaPotential)
```

## Usage & Examples

[Install Antique.jl](@ref Install) for the first use and run `using Antique` before each use. The energy `E()`, wavefunction `ψ()`, potential `V()` and some other functions are suppoted. In this system, the model is generated by `DeltaPotential` and several parameters `α`, `m` and `ℏ` are set as optional arguments.

```julia; cache = :all; results = "hidden"
using Antique
DP = DeltaPotential(α=1.0, m=1.0, ℏ=1.0)
```

Parameters:

```julia; term = true
DP.α
DP.m
DP.ℏ
```

Eigen values:

```julia; term = true
E(DP)
```

Wave functions:

```julia
DP = DeltaPotential(α=0.1, m=0.5, ℏ=0.1)
x = LinRange(-2,2,500);

using Plots
plot(x, x->ψ(DP,x), linewidth=3)
plot!(xlim=[-2,2], ylim=[0,2.5], legend=false)
plot!(xlabel="x", ylabel="ψ(x)", title="Delta Potential")
```

## Testing

Unit testing and Integration testing were done using numerical integration ([QuadGK.jl](https://juliamath.github.io/QuadGK.jl/stable/)). The test script is [here](https://github.com/ohno/Antique.jl/blob/main/test/DeltaPotential.jl).

```julia; line_width = 500
println(Antique.load("../../test/result/DeltaPotential.log"))
```
2 changes: 1 addition & 1 deletion docs/src/jmd/InfinitePotentialWell.jmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The infinite potential well (particle in a box) is the simplest model for quantu

#### Hamiltonian
```math
\hat{H} = \frac{\hbar^2}{2m} \frac{\mathrm{d}^2}{\mathrm{d}x ^2} + V(x)
\hat{H} = - \frac{\hbar^2}{2m} \frac{\mathrm{d}^2}{\mathrm{d}x ^2} + V(x)
```

#### Potential
Expand Down
1 change: 1 addition & 0 deletions src/Antique.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Antique
:HarmonicOscillator,
:MorsePotential,
:HydrogenAtom,
:DeltaPotential,
]

# for Julia 1.1
Expand Down
62 changes: 62 additions & 0 deletions src/DeltaPotential.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
export DeltaPotential, V, E, ψ

# Parameters
@kwdef struct DeltaPotential
α = 1.0
m = 1.0
= 1.0
end

# Potential
function V(model::DeltaPotential, x)
return x==0 ? -Inf : 0
end

# Energy
function E(model::DeltaPotential)
α = model.α
m = model.m
= model.
return -(m*α^2)/(2*^2)
end

# Wave Function
function ψ(model::DeltaPotential, x)
α = model.α
m = model.m
= model.
return sqrt(m*α)/* exp.(-m*α*abs.(x)/^2)
end

# Documents

@doc raw"""
`DeltaPotential(α=1.0, m=1.0, ℏ=1.0)`
``\alpha`` is the potential strength, ``m`` is the mass of particle and ``\hbar`` is the reduced Planck constant (Dirac's constant).
""" DeltaPotential

@doc raw"""
`V(model::DeltaPotential; x)`
```math
V(x) = -\alpha \delta(x).
```
""" V(model::DeltaPotential)

@doc raw"""
`E(model::DeltaPotential)`
```math
E = - \frac{m\alpha^2}{2\hbar^2}
```
""" E(model::DeltaPotential)

@doc raw"""
`ψ(model::DeltaPotential, x)`
```math
\psi(x) = \frac{\sqrt{m\alpha}}{\hbar} \mathrm{e}^{-m\alpha |x|/\hbar^2}
```
""" ψ(model::DeltaPotential)
Loading

0 comments on commit 84b5755

Please sign in to comment.