Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
probabilitycontours2d_tests.cpp
Go to the documentation of this file.
1/**
2 * @file probabilitycontours2d_tests.cpp
3 * @brief Implements regression and invariant tests for probabilitycontours2d tests.
4 * @ingroup qpe_tests
5 *
6 * Source: @c tests/probabilitycontours2d_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 {
21namespace tests {
22namespace {
23
24/**
25 * @brief Performs fail.
26 * @param errorMessage The error message value used by the operation.
27 * @param text The text value used by the operation.
28 */
29bool fail(std::string &errorMessage, const char *text)
30{
31 errorMessage = text;
32 return false;
33}
34
35} // namespace
36
37/**
38 * @brief Runs probability contours2 d tests.
39 * @param errorMessage The error message value used by the operation.
40 */
41bool runProbabilityContours2DTests(std::string &errorMessage)
42{
43 errorMessage.clear();
44
45 ComplexField2D field(65u, 65u, 0.1f, 0.1f);
46 const double centre = 32.0;
47 for (std::size_t y = 0u; y < field.height(); ++y) {
48 for (std::size_t x = 0u; x < field.width(); ++x) {
49 const double dx = static_cast<double>(x) - centre;
50 const double dy = static_cast<double>(y) - centre;
51 const double p = std::exp(-(dx * dx + dy * dy) / 160.0);
52 field(x, y) = ComplexField2D::Value(static_cast<float>(std::sqrt(p)), 0.0f);
53 }
54 }
55
57 field, 6u, ProbabilityContourSpacing2D::Linear, 4.0f, 384u);
58 if (linear.levels.size() != 6u || linear.segments.empty()) {
59 return fail(errorMessage, "ProbabilityContours2D: linear Gaussian contours missing");
60 }
61 for (std::size_t i = 1u; i < linear.levels.size(); ++i) {
62 if (!(linear.levels[i] > linear.levels[i - 1u])) {
63 return fail(errorMessage, "ProbabilityContours2D: linear levels are not increasing");
64 }
65 }
66
68 field, 8u, ProbabilityContourSpacing2D::Logarithmic, 5.0f, 384u);
69 if (logarithmic.levels.size() != 8u || logarithmic.segments.empty()) {
70 return fail(errorMessage, "ProbabilityContours2D: logarithmic Gaussian contours missing");
71 }
72 if (!(logarithmic.levels.front() < linear.levels.front())) {
73 return fail(errorMessage, "ProbabilityContours2D: logarithmic spacing did not reach faint structure");
74 }
75
76 ComplexField2D large(1024u, 256u, 0.1f, 0.1f);
77 large.fill(ComplexField2D::Value(1.0f, 0.0f));
79 large, 4u, ProbabilityContourSpacing2D::Linear, 4.0f, 384u);
80 if (sampled.samplingStride < 2u) {
81 return fail(errorMessage, "ProbabilityContours2D: automatic live-view downsampling not applied");
82 }
83 if (!sampled.segments.empty()) {
84 return fail(errorMessage, "ProbabilityContours2D: constant field should not produce contours");
85 }
86
87 return true;
88}
89
90} // namespace tests
91} // namespace qpe
Owning Cartesian grid of complex scalar samples.
std::size_t height() const noexcept
Returns the number of samples along Y.
void fill(const Value &value)
Assigns one complex value to every grid sample.
std::complex< float > Value
std::size_t width() const noexcept
Returns the number of samples along X.
static ProbabilityContours2DResult compute(const ComplexField2D &field, std::size_t requestedLevels, ProbabilityContourSpacing2D spacing, float logDecades=4.0f, std::size_t targetSamplesPerAxis=384u)
Performs compute.
Declares the complex scalar field container representing two-dimensional wave functions.
bool runProbabilityContours2DTests(std::string &errorMessage)
Runs probability contours2 d tests.
Declares the probabilitycontours2d physics/numerical component used by QPE experiments.
Declares regression and invariant tests for probabilitycontours2d tests.
Data record containing Probability Contours2D Result.
std::vector< ProbabilityContourSegment2D > segments