Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
scatteringobservables2d.cpp
Go to the documentation of this file.
1/**
2 * @file scatteringobservables2d.cpp
3 * @brief Implements the scatteringobservables2d physics/numerical component used by QPE experiments.
4 * @ingroup qpe_quantum
5 *
6 * Source: @c core/quantum/scatteringobservables2d.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
15
16#include <cmath>
17#include <utility>
18
19namespace qpe {
20
22 double leftBoundary,
23 double rightBoundary) noexcept
24{
26 if (field.empty()) {
27 return out;
28 }
29
30 if (leftBoundary > rightBoundary) {
31 std::swap(leftBoundary, rightBoundary);
32 }
33
34 const double cellArea = static_cast<double>(field.dx()) *
35 static_cast<double>(field.dy());
36
37 for (std::size_t y = 0; y < field.height(); ++y) {
38 for (std::size_t x = 0; x < field.width(); ++x) {
39 const auto &v = field(x, y);
40 const double re = static_cast<double>(v.real());
41 const double im = static_cast<double>(v.imag());
42 const double p = (re * re + im * im) * cellArea;
43 const double px = GaussianPacket2D::xCoordinate(field, x);
44
45 out.total += p;
46 if (px < leftBoundary) {
47 out.left += p;
48 } else if (px > rightBoundary) {
49 out.right += p;
50 } else {
51 out.interaction += p;
52 }
53 }
54 }
55
56 if (out.total > 0.0 && std::isfinite(out.total)) {
57 const double inv = 1.0 / out.total;
58 out.leftFraction = out.left * inv;
59 out.interactionFraction = out.interaction * inv;
60 out.rightFraction = out.right * inv;
61 }
62
63 return out;
64}
65
66} // namespace qpe
Owning Cartesian grid of complex scalar samples.
static double xCoordinate(const ComplexField2D &field, std::size_t x) noexcept
Performs x coordinate.
static ScatteringRegions2D measureX(const ComplexField2D &field, double leftBoundary, double rightBoundary) noexcept
Measures x.
Declares the gaussianpacket2d physics/numerical component used by QPE experiments.
Declares the scatteringobservables2d physics/numerical component used by QPE experiments.
Data structure used by the Scattering Regions2D component.