{"id":21079352,"url":"https://github.com/azimonti/schrodinger-equation-simulation","last_synced_at":"2025-10-11T19:04:19.291Z","repository":{"id":242876279,"uuid":"810535338","full_name":"azimonti/schrodinger-equation-simulation","owner":"azimonti","description":"Schrödinger equation numerical simulation in 1D and 2D","archived":false,"fork":false,"pushed_at":"2024-10-07T13:24:25.000Z","size":58808,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-20T23:27:12.981Z","etag":null,"topics":["double-slit","numerical-simulation","quantum-mechanics","schrodinger-equation"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/azimonti.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-04T22:12:34.000Z","updated_at":"2024-10-07T13:24:29.000Z","dependencies_parsed_at":"2025-01-20T23:35:36.835Z","dependency_job_id":null,"html_url":"https://github.com/azimonti/schrodinger-equation-simulation","commit_stats":null,"previous_names":["azimonti/schrodinger-equation-simulation"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azimonti%2Fschrodinger-equation-simulation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azimonti%2Fschrodinger-equation-simulation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azimonti%2Fschrodinger-equation-simulation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azimonti%2Fschrodinger-equation-simulation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azimonti","download_url":"https://codeload.github.com/azimonti/schrodinger-equation-simulation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243524065,"owners_count":20304691,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["double-slit","numerical-simulation","quantum-mechanics","schrodinger-equation"],"created_at":"2024-11-19T19:45:47.039Z","updated_at":"2025-10-11T19:04:19.286Z","avatar_url":"https://github.com/azimonti.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Schrödinger Equation Simulation - 1D\n\nNumerical simulation of the Schrödinger equation in 1D.\n\n## Features\n\n- **Potential Types**:\n  - Free space\n  - Harmonic oscillator\n  - Infinite high barrier\n  - Infinite right barrier\n  - Finite right barrier\n\n- **Wavefunction Initialization**:\n  - Wavepackets\n  - Eigenfunctions for the harmonic oscillator or infinite well\n\n- **Visualization**:\n  - Probability density\n  - Real and imaginary parts of the wavefunction\n  - Modulus and phase (color phase)\n\n- **Time Evolution Methods**:\n  - Implicit Crank-Nicolson (second-order)\n  - Explicit Runge-Kutta (8th order)\n\n- **Units**:\n  - Electron scale units\n  - Normalized units\n\n## Potential Function\n\n```python\ndef create_potential(x):\n    match p.potential:\n        case 0:\n            # free space\n            return np.zeros(len(x))\n        case 1:\n            # harmonic oscillator\n            return 0.5 * p.m * p.omega**2 * x ** 2\n        case 2:\n            # infinite high barrier\n            V = np.zeros(len(x))\n            # with a value too big RK solver is not converging\n            V[x \u003c= -p.Vx_bar] = 1e4\n            V[x \u003e= p.Vx_bar] = 1e4\n            return V\n        case 3:\n            # infinite right barrier\n            V = np.zeros(len(x))\n            V[x \u003e= p.Vx_bar] = p.V_barrier\n            return V\n        case 4:\n            # finite right barrier\n            V = np.zeros(len(x))\n            V[(x \u003e= p.Vx_bar) \u0026 (x \u003c= p.Vx_finite_bar)] = p.V_barrier\n            return V\n        case _:\n            raise NotImplementedError(\n                f\"Potential {p.potential} not implemented\")\n```\n\nSome example configurations are available in the `examples_1d` directory.\n\n## Visualization Options\n\n- **Probability Density**:\n  Visualize `|\\psi(x)|^2`\n\n- **Wavefunction**:\n  - Real and imaginary parts\n  - Modulus and phase (color phase)\n\n## Time Evolution Methods\n\n- **Implicit Crank-Nicolson**:\n  Second-order method for time integration.\n\n- **Explicit Runge-Kutta**:\n  8th order method for higher precision in time integration.\n\n## Example Results\n\nPlain wave probability density:\n\nhttps://github.com/user-attachments/assets/ec4be06e-73a4-4d9c-9e4e-94eccea29c00\n\nBarrier of infinite length wavefunction with phase:\n\nhttps://github.com/user-attachments/assets/9e189fa3-d9bb-4c7c-89d4-eaf4bdc1da8a\n\nHarmonic oscillator single eigensolution for `n=3` showing no change in the wavefunction magnitude, only a change in the phase:\n\nhttps://github.com/user-attachments/assets/a62f3526-ee19-4d3e-bbe9-223830be8f4f\n\n# Schrödinger Equation Simulation - 2D\n\nNumerical simulation of the Schrödinger equation in 2D.\n\n## Features\n\n- **Potential Types**:\n  - Free space\n  - Particle in a box\n  - Particle with barrier (in a box or in free space)\n  - Particle with multiple slits (in a box or in free space)\n\n- **Wavefunction Initialization**:\n  - Wavepackets\n\n- **Visualization**:\n  - Probability density\n  - Modulus and phase (color phase)\n\n- **Time Evolution Methods**:\n  - Implicit Crank-Nicolson (second-order)\n\n- **Units**:\n  - Normalized units\n\nSome example configurations are available in the `examples_2d` directory.\n\n# Double Slit Experiment For Electrons\n\nIn this numerical simulation of the double slit experiment with electrons, the Schrödinger equation is used to model a wavepacket passing through a double slit. After interaction with the slits, the simulation calculates the fraction of the wavepacket that reaches a screen positioned behind the slits. This fraction is then used to simulate individual electrons impacting the screen, forming an interference pattern. The vertical position of each electron is randomly distributed uniformly along the vertical axis, simulating slits with a height much greater than their width.\n\n## Example Results\n\nWavepacket probability distribution at the screen location:\n\n![Wavepacket probability distribution at the screen location](examples_2d/electrons_beam/png/wavepacket_probability_distribution_screen.png)\n\nWavepacket probability distribution at the screen location:\n\n![Wavepacket probability distribution at the screen location](examples_2d/electrons_beam/png/wavepacket_probability_distribution_screen_2d.png)\n\n15000 electron beam buildup at the screen location:\n\nhttps://github.com/user-attachments/assets/46772b45-ed44-4dda-9cd1-c9d806072250\n\n15000 electron beam distribution at the screen location, very close to the wavepacket probability as expected:\n\n![Wavepacket probability distribution at the screen location](examples_2d/electrons_beam/png/15000_electron_beam_distribution.png)\n\n# Getting Started\n\nTo get started with these simulations:\n1. Clone the repository:\n   ```\n   git clone https://github.com/azimonti/schrodinger-equation-simulation.git\n   ```\n2. Navigate to the repository directory:\n   ```\n   cd schrodinger-equation-simulation\n   ```\n3. Install required dependencies:\n   ```\n   pip install -r requirements.txt\n   ```\n4. Run the simulation scripts:\n   ```\n   python schrodinger_1d.py\n   python schrodinger_2d.py\n   ```\n\n# Contributing\n\nContributions to the simulation of Schrödinger project are welcome. Whether it's through submitting bug reports, proposing new features, or contributing to the code, your help is appreciated. For major changes, please open an issue first to discuss what you would like to change.\n\n# License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n# Contact\n\nThis README provides a comprehensive overview of your Schrödinger equation simulation project, including its features, usage instructions, and potential types.\n\nPlease refer to these articles ([here](https://www.azimonti.com/programming/simulations/qm/1d-schrodinger-equation.html), [here](https://www.azimonti.com/programming/simulations/qm/2d-schrodinger-equation.html), and [here](https://www.azimonti.com/programming/simulations/qm/electron-double-slit-experiment.html)) for more detail explaination of the numerical aspects of these simulations.\n\nIf you have any questions or want to get in touch regarding the project, please open an issue or contact the repository maintainers directly through GitHub.\n\nThank you for exploring the quantum mechanics of the Schrödinger equation with us!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazimonti%2Fschrodinger-equation-simulation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazimonti%2Fschrodinger-equation-simulation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazimonti%2Fschrodinger-equation-simulation/lists"}