39 error =
"real constant field must have zero probability current";
45 const std::size_t width = 96;
46 const std::size_t height = 48;
47 const float dx = 0.05f;
48 const float dy = 0.05f;
51 for (std::size_t y = 0; y < height; ++y) {
52 for (std::size_t x = 0; x < width; ++x) {
53 const double phase = k *
static_cast<double>(x) * dx;
55 static_cast<float>(std::cos(phase)),
56 static_cast<float>(std::sin(phase)));
61 const float hbar = 1.0f;
62 const float mass = 2.0f;
66 const std::size_t cx = width / 2;
67 const std::size_t cy = height / 2;
68 const std::size_t ci = cy * width + cx;
69 const double probability = std::norm(std::complex<double>(
70 static_cast<double>(plane(cx, cy).real()),
71 static_cast<double>(plane(cx, cy).imag())));
72 const double expected = probability *
73 (
static_cast<double>(hbar) /
static_cast<double>(mass)) *
74 std::sin(k * dx) / dx;
76 if (std::abs(
static_cast<double>(current.
jx[ci]) - expected) > 2.0e-5) {
77 error =
"plane-wave Jx does not match the finite-difference reference";
80 if (std::abs(current.
jy[ci]) > 1.0e-6f) {
81 error =
"plane wave along X must have Jy approximately zero";
85 error =
"positive-k plane wave must carry positive integrated X current";
94 if (std::abs(
static_cast<double>(gaugeCurrent.
jx[ci]) -
95 static_cast<double>(current.
jx[ci])) > 2.0e-7 ||
96 std::abs(
static_cast<double>(gaugeCurrent.
jy[ci]) -
97 static_cast<double>(current.
jy[ci])) > 2.0e-7 ||
100 error =
"identity-gauge current must match the ordinary current";
110 const double ax = 0.17;
111 const double ay = -0.11;
112 for (std::size_t y = 0; y < height; ++y) {
113 for (std::size_t x = 0; x < width; ++x) {
114 const double chi = ax *
static_cast<double>(x) + ay *
static_cast<double>(y);
115 const std::complex<float> phase(
static_cast<float>(std::cos(chi)),
116 static_cast<float>(std::sin(chi)));
117 transformed(x, y) *= phase;
118 if (x + 1u < width) {
119 const double dchi = chi - (ax *
static_cast<double>(x + 1u) + ay *
static_cast<double>(y));
121 static_cast<float>(std::cos(dchi)),
static_cast<float>(std::sin(dchi))));
123 if (y + 1u < height) {
124 const double dchi = chi - (ax *
static_cast<double>(x) + ay *
static_cast<double>(y + 1u));
126 static_cast<float>(std::cos(dchi)),
static_cast<float>(std::sin(dchi))));
132 if (std::abs(
static_cast<double>(invariantCurrent.
jx[ci]) -
133 static_cast<double>(current.
jx[ci])) > 3.0e-6 ||
134 std::abs(
static_cast<double>(invariantCurrent.
jy[ci]) -
135 static_cast<double>(current.
jy[ci])) > 3.0e-6 ||
138 error =
"gauge-covariant probability current is not U(1) invariant";
141 }
catch (
const std::exception &e) {