simulation
Simulation module.
Provides a class for the simulation of one-dimensional single particle quantum dynamics in a time-independent external potential. The wave packet is propagated in time by applying the time evolution operator at each time step. While the simulation is running for a specified number of time steps, wave function, probability density and expectation values are saved at specified intervals.
Examples:
To set up a simulation, a grid, a particle, its initial wave function and a potential function are required.
>>> from functools import partial
>>> import wave_packet_dynamics as wpd
>>> simulation = wpd.Simulation(
... grid=wpd.Grid((0, 10), 1000),
... particle=wpd.particles.Electron(),
... wave_function=partial(
... wpd.wave_function.gaussian, sigma=1, x0=5, k0=10
... ),
... potential=wpd.potential.zero,
... )
Creating a simulation object also normalizes the wave function.
>>> simulation.expectation_value("total_density")
np.float64(1.0000005734276094)
At any point of the simulation, expectation values can be calculated.
>>> simulation.expectation_value("position")
np.float64(5.000002867138047)
>>> simulation.expectation_value("momentum")
np.float64(9.983189000651)
>>> simulation.expectation_value("kinetic_energy")
np.float64(50.08273993919016)
>>> simulation.expectation_value("potential_energy")
np.float64(0.0)
Calling the simulation object will run the simulation for a specified number of time steps with a given time interval. Additionally, simulation data is saved at specified intervals.
>>> simulation(
... time_interval=0.01,
... total_time_steps=1000,
... save_step=1001,
... save_directory="output",
... )
>>> simulation.time
9.999999999999831
Simulation
Simulation of a single particle in an electrostatic potential.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid |
Grid
|
Grid on which the simulation is performed. |
required |
particle |
Particle
|
The particle to simulate. |
required |
wave_function |
Callable[[NDArray[float64]], NDArray[complex128]]
|
The initial wave function of the particle. |
required |
potential |
Callable[[NDArray[float64]], NDArray[float64]]
|
The electrostatic potential acting on the particle. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
time |
float
|
The current time of the simulation. |
__call__(time_interval: float, total_time_steps: int, save_step: int = 10, save_directory: str | Path = 'simulation') -> None
Run the simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_interval |
float
|
Time interval between two consecutive time steps. |
required |
total_time_steps |
int
|
Total number of time steps. |
required |
save_step |
int
|
Save interval in time steps. |
10
|
save_directory |
str or Path
|
Output directory. |
'simulation'
|
Raises:
| Type | Description |
|---|---|
FileExistsError
|
If the output directory already exists. |
density: NDArray[np.float64]
property
Calculate the probability density.
Notes
The probability density is defined as the absolute square of the wave function.
normalize() -> None
Normalize the wave function.
expectation_value(observable: str) -> float
Calculate the expectation value of an observable.
Notes
The expectation value of an observable (\(A\)) is calculated using the corresponding self-adjoint linear operator (\(\hat{A}\)).