Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
scatteringobservables2d_tests.cpp
Go to the documentation of this file.
1/**
2 * @file scatteringobservables2d_tests.cpp
3 * @brief Implements regression and invariant tests for scatteringobservables2d tests.
4 * @ingroup qpe_tests
5 *
6 * Source: @c tests/scatteringobservables2d_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
16
17#include <cmath>
18#include <sstream>
19
20namespace qpe { namespace tests {
21namespace {
22
23/**
24 * @brief Performs near.
25 * @param a The a value used by the operation.
26 * @param b The b value used by the operation.
27 * @param tolerance The tolerance value used by the operation.
28 */
29bool near(double a, double b, double tolerance)
30{
31 return std::abs(a - b) <= tolerance;
32}
33
34} // namespace
35
36/**
37 * @brief Runs scattering observables2 d tests.
38 * @param error Output diagnostic text on failure.
39 */
40bool runScatteringObservables2DTests(std::string &error)
41{
42 error.clear();
43
44 // 6 x 2 grid, dx=dy=1. x coordinates are
45 // -2.5, -1.5, -0.5, +0.5, +1.5, +2.5.
46 ComplexField2D field(6, 2, 1.0f, 1.0f);
47 field.fill(ComplexField2D::Value(1.0f, 0.0f));
48
50
51 // Two x columns per region, two y rows: 4 samples in every region.
52 if (!near(m.total, 12.0, 1.0e-12) ||
53 !near(m.left, 4.0, 1.0e-12) ||
54 !near(m.interaction, 4.0, 1.0e-12) ||
55 !near(m.right, 4.0, 1.0e-12) ||
56 !near(m.leftFraction, 1.0 / 3.0, 1.0e-12) ||
57 !near(m.interactionFraction, 1.0 / 3.0, 1.0e-12) ||
58 !near(m.rightFraction, 1.0 / 3.0, 1.0e-12)) {
59 std::ostringstream ss;
60 ss << "region integration mismatch: total=" << m.total
61 << " left=" << m.left
62 << " interaction=" << m.interaction
63 << " right=" << m.right;
64 error = ss.str();
65 return false;
66 }
67
68 // Boundary order is intentionally reversible for convenience.
69 const ScatteringRegions2D reversed = ScatteringObservables2D::measureX(field, 1.0, -1.0);
70 if (!near(reversed.left, m.left, 1.0e-12) ||
71 !near(reversed.interaction, m.interaction, 1.0e-12) ||
72 !near(reversed.right, m.right, 1.0e-12)) {
73 error = "reversed boundaries changed the result";
74 return false;
75 }
76
77 return true;
78}
79
80} } // namespace qpe::tests
Owning Cartesian grid of complex scalar samples.
void fill(const Value &value)
Assigns one complex value to every grid sample.
std::complex< float > Value
static ScatteringRegions2D measureX(const ComplexField2D &field, double leftBoundary, double rightBoundary) noexcept
Measures x.
Declares the complex scalar field container representing two-dimensional wave functions.
bool runScatteringObservables2DTests(std::string &error)
Runs scattering observables2 d tests.
Declares the scatteringobservables2d physics/numerical component used by QPE experiments.
Declares regression and invariant tests for scatteringobservables2d tests.
Data structure used by the Scattering Regions2D component.