Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
quantumtextureframe2d.cpp
Go to the documentation of this file.
1/**
2 * @file quantumtextureframe2d.cpp
3 * @brief Implements the quantumtextureframe2d visualization component used by QPE.
4 * @ingroup qpe_graphics
5 *
6 * Source: @c graphics/renderer/quantumtextureframe2d.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 <algorithm>
18#include <cmath>
19#include <stdexcept>
20
21namespace qpe {
22
23bool QuantumTextureFrame2D::empty() const noexcept
24{
25 const std::size_t sampleCount = width * height;
26 return width == 0 || height == 0 ||
27 probability.size() != sampleCount ||
28 phase.size() != sampleCount ||
29 potential.size() != sampleCount;
30}
31
33 const PotentialField2D &potentialField)
34{
35 if (field.empty()) {
36 return QuantumTextureFrame2D();
37 }
38
39 if (!potentialField.empty() && !potentialField.matchesGrid(field)) {
40 throw std::invalid_argument("QuantumTextureFrame2D: potential grid does not match wavefunction grid");
41 }
42
44 frame.width = field.width();
45 frame.height = field.height();
46
47 const std::size_t sampleCount = field.size();
48 frame.probability.resize(sampleCount);
49 frame.phase.resize(sampleCount);
50 frame.potential.resize(sampleCount, 0.0f);
51
52 const ComplexField2D::Value *psi = field.data();
53 const PotentialField2D::Value *potential = potentialField.empty()
54 ? nullptr
55 : potentialField.data();
56
57 for (std::size_t i = 0; i < sampleCount; ++i) {
58 const float real = psi[i].real();
59 const float imag = psi[i].imag();
60 const float p = real * real + imag * imag;
61 const float ph = std::atan2(imag, real);
62 const float v = potential ? potential[i] : 0.0f;
63
64 frame.probability[i] = p;
65 frame.phase[i] = ph;
66 frame.potential[i] = v;
67
68 frame.maxProbability = std::max(frame.maxProbability, p);
69 frame.maxAbsPotential = std::max(frame.maxAbsPotential, std::abs(v));
70 }
71
72 return frame;
73}
74
75} // namespace qpe
Owning Cartesian grid of complex scalar samples.
std::size_t size() const noexcept
Returns the total number of complex samples.
bool empty() const noexcept
Returns whether the field contains no samples.
std::size_t height() const noexcept
Returns the number of samples along Y.
Value * data() noexcept
Returns mutable contiguous row-major sample storage.
std::complex< float > Value
std::size_t width() const noexcept
Returns the number of samples along X.
Implements the Potential Field2D component.
bool matchesGrid(const ComplexField2D &field) const noexcept
Performs matches grid.
const Value * data() const noexcept
Performs data.
bool empty() const noexcept
Performs empty.
Declares the complex scalar field container representing two-dimensional wave functions.
Declares the potentialfield2d physics/numerical component used by QPE experiments.
Declares the quantumtextureframe2d visualization component used by QPE.
Data structure used by the Quantum Texture Frame2D component.
static QuantumTextureFrame2D build(const ComplexField2D &field, const PotentialField2D &potential)
Performs build.
bool empty() const noexcept
Performs empty.