33 if (!(
dx > 0.0f) || !(
dy > 0.0f)) {
34 throw std::invalid_argument(
"ComplexField2D: dx and dy must be positive");
86 return data_[index(x, y)];
91 return data_[index(x, y)];
118 const double re =
static_cast<double>(v.real());
119 const double im =
static_cast<double>(v.imag());
120 sum += re * re + im * im;
127 return sumAbs2() *
static_cast<double>(
dx_) *
static_cast<double>(
dy_);
132 return std::sqrt(
norm2());
137 const double n =
norm();
138 if (!(n > 0.0) || !std::isfinite(n)) {
142 const float scale =
static_cast<float>(1.0 / n);
151 return y * width_ + x;
157 throw std::out_of_range(
"ComplexField2D: coordinates outside field");
std::size_t checkedIndex(std::size_t x, std::size_t y) const
Checks ed index.
std::size_t size() const noexcept
Returns the total number of complex samples.
double norm2() const noexcept
Returns the discrete integral of |psi|^2 including dx*dy.
ComplexField2D()=default
Constructs an empty field.
bool empty() const noexcept
Returns whether the field contains no samples.
float dx() const noexcept
Returns the X grid spacing.
std::size_t height() const noexcept
Returns the number of samples along Y.
double norm() const noexcept
Returns the square root of the discrete probability norm.
Value & at(std::size_t x, std::size_t y)
Returns a mutable sample with bounds checking.
void clear() noexcept
Releases all samples and returns the field to the empty state.
void fill(const Value &value)
Assigns one complex value to every grid sample.
double sumAbs2() const noexcept
Returns the raw sample sum sum(|psi|^2) without cell area.
bool normalize() noexcept
Scales the field to unit discrete probability norm.
Value * data() noexcept
Returns mutable contiguous row-major sample storage.
void resize(std::size_t width, std::size_t height, float dx=1.0f, float dy=1.0f)
Reallocates the grid and resets all samples to zero.
std::size_t index(std::size_t x, std::size_t y) const noexcept
Returns index.
std::vector< Value > data_
std::complex< float > Value
float dy() const noexcept
Returns the Y grid spacing.
Value & operator()(std::size_t x, std::size_t y) noexcept
Returns a mutable sample without bounds checking.
std::size_t width() const noexcept
Returns the number of samples along X.
Declares the complex scalar field container representing two-dimensional wave functions.