Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
wavepacketobservables2d_tests.cpp
Go to the documentation of this file.
1/**
2 * @file wavepacketobservables2d_tests.cpp
3 * @brief Implements regression and invariant tests for wavepacketobservables2d tests.
4 * @ingroup qpe_tests
5 *
6 * Source: @c tests/wavepacketobservables2d_tests.cpp. This file is part of Quantum Phenomena Explorer (QPE),
7 * maintained by Officina Turini. See LICENSE_IT.txt / LICENSE.txt for the
8 * QPE freeware source-available terms and THIRD_PARTY_NOTICES.txt for
9 * third-party components.
10 */
11
13
18
19#include <cmath>
20#include <sstream>
21
22namespace qpe { namespace tests {
23namespace {
24
25/**
26 * @brief Performs near.
27 * @param a The a value used by the operation.
28 * @param b The b value used by the operation.
29 * @param tolerance The tolerance value used by the operation.
30 */
31bool near(double a, double b, double tolerance)
32{
33 return std::abs(a - b) <= tolerance;
34}
35
36} // namespace
37
38/**
39 * @brief Runs wave packet observables2 d tests.
40 * @param error Output diagnostic text on failure.
41 */
42bool runWavePacketObservables2DTests(std::string &error)
43{
44 error.clear();
45
46 ComplexField2D field(256, 256, 0.08f, 0.08f);
47
49 packet.centerX = -4.0f;
50 packet.centerY = 0.75f;
51 packet.sigma = 0.9f;
52 packet.momentumX = 2.5f;
53 packet.momentumY = 0.0f;
54 packet.hbar = 1.0f;
55 GaussianPacket2D::initialize(field, packet);
56
58 if (!near(initial.norm2, 1.0, 2.0e-5) ||
59 !near(initial.meanX, packet.centerX, 2.0e-3) ||
60 !near(initial.meanY, packet.centerY, 2.0e-3) ||
61 !near(initial.sigmaX, packet.sigma, 2.0e-3) ||
62 !near(initial.sigmaY, packet.sigma, 2.0e-3)) {
63 std::ostringstream ss;
64 ss << "initial spatial observables mismatch: norm=" << initial.norm2
65 << " meanX=" << initial.meanX << " meanY=" << initial.meanY
66 << " sigmaX=" << initial.sigmaX << " sigmaY=" << initial.sigmaY;
67 error = ss.str();
68 return false;
69 }
70
71 SplitStepFourier2DParams solverParams;
72 solverParams.mass = 1.0f;
73 solverParams.hbar = 1.0f;
74 solverParams.dt = 0.02f;
75 SplitStepFourierSolver2D solver(solverParams);
76
77 const int steps = 25; // t = 0.5
78 for (int i = 0; i < steps; ++i) {
79 solver.stepFree(field);
80 }
81
83 const double t = solver.time();
84 const double expectedMeanX = static_cast<double>(packet.centerX) +
85 static_cast<double>(packet.momentumX) / solverParams.mass * t;
86 const double sigma0 = packet.sigma;
87 const double spreadingTerm = solverParams.hbar * t /
88 (2.0 * solverParams.mass * sigma0 * sigma0);
89 const double expectedSigma = sigma0 * std::sqrt(1.0 + spreadingTerm * spreadingTerm);
90
91 if (!near(evolved.norm2, 1.0, 1.0e-4) ||
92 !near(evolved.meanX, expectedMeanX, 1.5e-2) ||
93 !near(evolved.meanY, packet.centerY, 5.0e-3) ||
94 !near(evolved.sigmaX, expectedSigma, 1.5e-2) ||
95 !near(evolved.sigmaY, expectedSigma, 1.5e-2)) {
96 std::ostringstream ss;
97 ss << "free propagation mismatch: norm=" << evolved.norm2
98 << " meanX=" << evolved.meanX << " expectedX=" << expectedMeanX
99 << " sigmaX=" << evolved.sigmaX << " expectedSigma=" << expectedSigma;
100 error = ss.str();
101 return false;
102 }
103
104 return true;
105}
106
107} } // namespace qpe::tests
Owning Cartesian grid of complex scalar samples.
static void initialize(ComplexField2D &field, const GaussianPacket2DParams &params)
Initializes ialize.
Symmetric split-step Fourier solver for the scalar 2D Schrodinger equation.
double time() const noexcept
Returns accumulated simulation time in solver units.
void stepFree(ComplexField2D &field)
Advances a free (V=0) scalar field by one cached kinetic step.
static SpatialObservables2D spatial(const ComplexField2D &field) noexcept
Performs spatial.
Declares the complex scalar field container representing two-dimensional wave functions.
Declares the gaussianpacket2d physics/numerical component used by QPE experiments.
bool runWavePacketObservables2DTests(std::string &error)
Runs wave packet observables2 d tests.
Declares the two-dimensional split-step Fourier propagator for the scalar Schrodinger branch.
Configuration values for Gaussian Packet2D Params.
Data structure used by the Spatial Observables2D component.
Physical/numerical parameters for scalar split-step propagation.
float hbar
Reduced Planck constant in simulation units.
float dt
Propagation step in simulation time units.
float mass
Particle/effective mass in simulation units.
Declares the wavepacketobservables2d physics/numerical component used by QPE experiments.
Declares regression and invariant tests for wavepacketobservables2d tests.