Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
- Phase space: `so.wigner()` and `so.husimi()` for 1d grids, the analyzers
`Wigner` and `Husimi`, `so.plotting.plot_phase_space()`, and a phase space
notebook comparing quantum and classical flow.
- Absorbers: `ManolopoulosAbsorber1d` (transmission-free), `PowerAbsorber1d`
and `MaskAbsorber1d` (cos^(1/8) mask), and a notebook that measures
reflection and transmission of the absorbers versus energy.

- New notebooks: double slit in 2d; double well with Rabi oscillations and
coherent destruction of tunneling; dynamical localization in the kicked rotor.
Expand Down
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,27 @@ energies, states = so.lowest_eigenstates(grid, 5) # 0.5, 1.5, 2.5, ...
`grid.energy()` gives ⟨H⟩, split into `grid.expectation_kinetic()` and
`grid.expectation_potential()`.

## Absorbing boundaries

The grid is periodic, so a wave that leaves on one side comes back on the
other. An absorber passed as `absorber=` to the grid removes it near the edges:

```python
size = (-50.0, 50.0)
absorber = so.ManolopoulosAbsorber1d(E_min=0.5, x0=size[0], x1=size[1])
grid = so.Grid1d(size, 2**11, potential, psi0, absorber=absorber)
```

- `ManolopoulosAbsorber1d`: transmission-free absorber that reflects less
than 1% of all waves above `E_min`, which also sets its width; the default
choice
- `PowerAbsorber1d`: −iη uⁿ in a layer of given width (quadratic by default)
- `ExpAbsorber1d`: exponential imaginary part, optionally with a real part
- `MaskAbsorber1d`: multiplies ψ by cos^(1/8) in the layer once per time step
- `BoundaryAbsorber2d`: quadratic layer along the edges of a 2d grid

Notebook 12 measures their reflection and transmission versus energy.

## Analyzers

`so_schroedinger.analyzers` collects data during the propagation. Each
Expand Down Expand Up @@ -213,6 +234,7 @@ and the animation cells take a while.
| `09_double_well.ipynb` | tunneling between the wells of a double well: the splitting from eigenstates, the tunneling oscillation and the spectrum, Rabi oscillations, and coherent destruction of tunneling by a fast drive | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/aeberspaecher/splitoperator/blob/main/notebooks/09_double_well.ipynb) |
| `10_kicked_rotor.ipynb` | the kicked rotor as a split operator step: classical chaos in the standard map, dynamical localization against classical diffusion, the exponential momentum distribution, and noise that destroys localization | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/aeberspaecher/splitoperator/blob/main/notebooks/10_kicked_rotor.ipynb) |
| `11_phase_space.ipynb` | Wigner and Husimi functions of coherent, squeezed, excited and cat states; in the harmonic oscillator the Wigner function moves like a classical ensemble, in a quartic oscillator it filaments, interferes and partly revives, unlike the classical one | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/aeberspaecher/splitoperator/blob/main/notebooks/11_phase_space.ipynb) |
| `12_absorbers.ipynb` | reflection and transmission of absorbing boundaries versus energy: the transmission-free Manolopoulos absorber, quadratic and exponential absorbers, and a cos^(1/8) mask | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/aeberspaecher/splitoperator/blob/main/notebooks/12_absorbers.ipynb) |

To run them locally, install the extras with `pip install ".[notebooks]"` and
start `jupyter lab notebooks/`.
Expand All @@ -226,7 +248,8 @@ start `jupyter lab notebooks/`.
- `so_schroedinger.timeprop`: the split operator propagator
- `so_schroedinger.eigenstates`: ground and excited states from imaginary time
- `so_schroedinger.analyzers`: expectation values, autocorrelation spectra,
eigenstates, time integrated density and flux
eigenstates, time integrated density, flux, Wigner and Husimi snapshots
- `so_schroedinger.phasespace`: Wigner and Husimi functions in 1d
- `so_schroedinger.animation`: Matplotlib animations of the propagation
- `so_schroedinger.plotting`: one-line plots of wavefunctions, momentum
distributions and eigenstates
Expand Down
384 changes: 384 additions & 0 deletions notebooks/12_absorbers.ipynb

Large diffs are not rendered by default.

153 changes: 151 additions & 2 deletions so_schroedinger/potentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import numpy as np
from scipy.interpolate import BarycentricInterpolator
from scipy.special import expit

# list of exported names:
__all__ = [
Expand All @@ -29,6 +30,9 @@
"InterpolatingPotential1d",
"RandomPotential1d",
"ExpAbsorber1d",
"PowerAbsorber1d",
"ManolopoulosAbsorber1d",
"MaskAbsorber1d",
"gaussian_random_field",
"Potential2d",
"HarmOscPot2d",
Expand Down Expand Up @@ -563,8 +567,8 @@ def __init__(self, A_real, A_imag, lreal, limag, x0, x1, absorb_left=True, absor
def V(self, x, t):
x = np.asarray(x, dtype=float)
real = self._A_real * (
self._A_left / (1.0 + np.exp(self._alpha_r * (x - (self._x0 + self._lreal))))
+ self._A_right / (1.0 + np.exp(-self._alpha_r * (x - (self._x1 - self._lreal))))
self._A_left * expit(-self._alpha_r * (x - (self._x0 + self._lreal)))
+ self._A_right * expit(self._alpha_r * (x - (self._x1 - self._lreal)))
)
imag = self._A_imag * (
self._A_left * np.exp(-np.abs(x - self._x0) / self._limag)
Expand All @@ -573,6 +577,151 @@ def V(self, x, t):
return real + 1j * imag


class _EdgeAbsorber1d(Potential1d):
r"""Absorbing layers of width $w$ at the edges of a 1d grid.

Derived classes implement ``_profile(u)`` for the depth
$u = (w - d)/w$ into a layer, with $d$ the distance to the edge: $u = 0$
at the inner end of the layer and $u = 1$ at the edge.
"""

is_time_dependent = False

def __init__(self, width, x0, x1, absorb_left=True, absorb_right=True):
self.width = float(width)
self._x0, self._x1 = float(x0), float(x1)
self._left, self._right = bool(absorb_left), bool(absorb_right)

def V(self, x, t):
x = np.asarray(x, dtype=float)
V = np.zeros(x.shape, dtype=complex)
for absorb, d in ((self._left, x - self._x0), (self._right, self._x1 - x)):
if absorb:
inside = d < self.width
V[inside] += self._profile(1.0 - d[inside] / self.width)
return V

def _profile(self, u):
raise NotImplementedError


class PowerAbsorber1d(_EdgeAbsorber1d):
r"""Complex absorbing potential $-i\eta\,u^n$ in layers at the edges,
$u$ rising from 0 to 1 across a layer of width $w$; the 1d counterpart of
``BoundaryAbsorber2d`` (which has $n = 2$).

Slow waves are reflected by the onset of the potential, fast ones are
transmitted through the layer (and come back from the other side of the
periodic grid); for a given width, $\eta$ trades one for the other. The
reflection is smallest for wavelengths much shorter than $w$. Cmp. Riss
and Meyer, J. Phys. B 28, 1475 (1995).
"""

def __init__(self, width, strength, x0, x1, power=2, absorb_left=True, absorb_right=True):
"""Create absorbing layers.

Parameters
----------
width : float
Width w of each layer.
strength : float
Maximum absorption rate eta (positive), reached at the edge.
x0, x1 : float
Grid boundaries.
power : float, optional
Exponent n.
absorb_left, absorb_right : bool, optional
Absorb at the left respectively right boundary of the grid.
"""

super().__init__(width, x0, x1, absorb_left, absorb_right)
self.strength, self.power = float(strength), float(power)

def _profile(self, u):
return -1j * self.strength * u**self.power


class ManolopoulosAbsorber1d(_EdgeAbsorber1d):
r"""Transmission-free complex absorbing potential of Manolopoulos,
J. Chem. Phys. 117, 9552 (2002).

The potential $-i\,\frac{1}{2}(2\pi/w)^2 f(y)$ with
$f(y) = ay - by^3 + 4/(c - y)^2 - 4/(c + y)^2$ and $y = c\,u$ diverges
at the edge, so nothing is transmitted. The width is fixed by the lowest
energy to absorb, $w = c/(2\delta k_\mathrm{min})$ with
$E_\mathrm{min} = k_\mathrm{min}^2/2$; for $\delta = 0.2$ the
reflection is below 1% for all $E > E_\mathrm{min}$ and falls rapidly
with energy. The constants are $c = 2.62206$, $a = 1 - 16/c^3$ and
$b = (1 - 17/c^3)/c^2$.

Use it at the edges of the grid. The divergence is cut off at a large
finite value, so the grid point on the edge just sets $\psi = 0$ in
each step.
"""

c = 2.62206

def __init__(self, E_min, x0, x1, delta=0.2, absorb_left=True, absorb_right=True):
r"""Create absorbing layers.

Parameters
----------
E_min : float
Lowest kinetic energy that is absorbed well.
x0, x1 : float
Grid boundaries.
delta : float, optional
Accuracy parameter; smaller values give a wider layer and less
reflection near $E_\mathrm{min}$.
absorb_left, absorb_right : bool, optional
Absorb at the left respectively right boundary of the grid.
"""

self.E_min, self.delta = float(E_min), float(delta)
k_min = np.sqrt(2 * self.E_min)
super().__init__(self.c / (2 * self.delta * k_min), x0, x1, absorb_left, absorb_right)

def _profile(self, u):
c = self.c
a, b = 1 - 16 / c**3, (1 - 17 / c**3) / c**2
y = c * np.minimum(u, 1 - 1e-6)
f = a * y - b * y**3 + 4 / (c - y) ** 2 - 4 / (c + y) ** 2
return -0.5j * (2 * np.pi / self.width) ** 2 * f


class MaskAbsorber1d(_EdgeAbsorber1d):
r"""Multiply $\psi$ by the mask $\cos^{p}(\pi u/2)$ once per time step,
written as the complex potential $i\ln(\cos^{p}(\pi u/2))/\Delta t$.

Masks are popular in strong-field physics, often with $p = 1/8$, cmp.
Krause, Schafer and Kulander, Phys. Rev. A 45, 4998 (1992). Since the
mask acts once per step, its effect depends on the time step: use it
with the ``dt`` it was made for (with ``SplitOperator(order=4)`` the
substeps still add up to one mask per step).

Parameters
----------
width : float
Width w of each layer.
dt : float
Time step of the propagation.
x0, x1 : float
Grid boundaries.
power : float, optional
Exponent p.
absorb_left, absorb_right : bool, optional
Absorb at the left respectively right boundary of the grid.
"""

def __init__(self, width, dt, x0, x1, power=1 / 8, absorb_left=True, absorb_right=True):
super().__init__(width, x0, x1, absorb_left, absorb_right)
self.dt, self.power = float(dt), float(power)

def _profile(self, u):
mask = np.cos(np.pi / 2 * u) ** self.power # cos(pi/2) is 6e-17 in floating point, not 0
return 1j * np.log(mask) / self.dt


# -----------------------------------------------------------------------
# 2d potentials: evaluated as V(r, t) with r = (X, Y)
class Potential2d(Potential):
Expand Down
38 changes: 38 additions & 0 deletions tests/test_potentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
so.InterpolatingPotential1d([(-10, 5), (0, 0), (10, 5)]),
so.RandomPotential1d(lambda r: np.exp(-(r**2) / 2), x, 1.0, rng=0),
so.ExpAbsorber1d(-1.0, -1.0, 2.0, 2.0, -10.0, 10.0),
so.PowerAbsorber1d(3.0, 2.0, -10.0, 10.0),
so.ManolopoulosAbsorber1d(0.5, -10.0, 10.0, absorb_right=False),
so.MaskAbsorber1d(3.0, 0.01, -10.0, 10.0),
]


Expand Down Expand Up @@ -59,3 +62,38 @@ def test_gaussian_random_field_has_requested_correlation():
lag = int(ell / dx)
corr = np.mean(field * np.roll(field, lag))
assert corr == pytest.approx(np.exp(-0.5), abs=0.05)


def test_power_absorber_profile():
pot = so.PowerAbsorber1d(width=4.0, strength=2.0, x0=-10.0, x1=10.0, power=3, absorb_left=False)
V = pot.V(np.array([-10.0, 5.9, 6.0, 8.0, 10.0]), 0.0)
assert V == pytest.approx([0.0, 0.0, 0.0, -2j * 0.5**3, -2j])


def test_manolopoulos_absorber_width_and_divergence():
pot = so.ManolopoulosAbsorber1d(E_min=2.0, x0=-10.0, x1=10.0)
assert pot.width == pytest.approx(2.62206 / (2 * 0.2 * 2.0))
V = pot.V(x, 0.0)
assert np.all(np.real(V) == 0.0) and np.all(np.imag(V) <= 0.0)
inner = np.abs(x) < 10.0 - pot.width
assert np.all(V[inner] == 0.0)
assert np.all(np.diff(np.imag(V[x > 0])) <= 0.0) # grows towards the edge
assert -np.imag(V[-1]) > 1e10 # divergence, cut off


def test_manolopoulos_absorber_absorbs_above_e_min():
# E = 4 E_min: nearly everything is absorbed, and nothing is transmitted
size = (-60.0, 0.0)
absorber = so.ManolopoulosAbsorber1d(0.5, *size, absorb_left=False)
grid = so.Grid1d(size, 2**11, so.ConstantPotential(0.0), so.Gaussian1d(-30.0, 3.0, 2.0), absorber=absorber)
so.SplitOperator().propagate(grid, 0.01, 3000) # the slowest parts need t = 30
assert grid.psi_norm**2 < 1e-4


def test_mask_absorber_applies_the_mask_once_per_step():
dt, width = 0.02, 5.0
pot = so.MaskAbsorber1d(width, dt, -10.0, 10.0)
xs = np.array([-9.0, 0.0, 7.0])
mask = np.exp(-1j * pot.V(xs, 0.0) * dt)
expected = [np.cos(np.pi / 2 * 4 / 5) ** (1 / 8), 1.0, np.cos(np.pi / 2 * 2 / 5) ** (1 / 8)]
assert mask == pytest.approx(expected)
Loading