24bool finite(
float v)
noexcept
26 return std::isfinite(
static_cast<double>(v));
33 if (field.width() == 0) {
36 const double centre = 0.5 *
static_cast<double>(field.width() - 1u);
37 return (
static_cast<double>(x) - centre) *
static_cast<double>(field.dx());
42 if (field.height() == 0) {
45 const double centre = 0.5 *
static_cast<double>(field.height() - 1u);
46 return (
static_cast<double>(y) - centre) *
static_cast<double>(field.dy());
53 throw std::invalid_argument(
"GaussianPacket2D: field must not be empty");
56 if (!(params.
sigma > 0.0f) || !finite(params.
sigma)) {
57 throw std::invalid_argument(
"GaussianPacket2D: sigma must be finite and positive");
60 if (!(params.
hbar > 0.0f) || !finite(params.
hbar)) {
61 throw std::invalid_argument(
"GaussianPacket2D: hbar must be finite and positive");
66 throw std::invalid_argument(
"GaussianPacket2D: all parameters must be finite");
69 const double sigma =
static_cast<double>(params.
sigma);
70 const double inv4Sigma2 = 1.0 / (4.0 * sigma * sigma);
71 const double invHbar = 1.0 /
static_cast<double>(params.
hbar);
73 for (std::size_t y = 0; y < field.
height(); ++y) {
75 const double dy = py -
static_cast<double>(params.
centerY);
77 for (std::size_t x = 0; x < field.
width(); ++x) {
79 const double dx = px -
static_cast<double>(params.
centerX);
81 const double envelope = std::exp(-(dx * dx + dy * dy) * inv4Sigma2);
83 (
static_cast<double>(params.
momentumX) * px +
84 static_cast<double>(params.
momentumY) * py) * invHbar;
87 static_cast<float>(envelope * std::cos(phase)),
88 static_cast<float>(envelope * std::sin(phase)));
93 throw std::runtime_error(
"GaussianPacket2D: normalization failed");
Owning Cartesian grid of complex scalar 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.
bool normalize() noexcept
Scales the field to unit discrete probability norm.
std::complex< float > Value
std::size_t width() const noexcept
Returns the number of samples along X.
static double yCoordinate(const ComplexField2D &field, std::size_t y) noexcept
Performs y coordinate.
static double xCoordinate(const ComplexField2D &field, std::size_t x) noexcept
Performs x coordinate.
static void initialize(ComplexField2D &field, const GaussianPacket2DParams ¶ms)
Initializes ialize.
Declares the gaussianpacket2d physics/numerical component used by QPE experiments.
Configuration values for Gaussian Packet2D Params.