Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
potentialfield2d.h
Go to the documentation of this file.
1/**
2 * @file potentialfield2d.h
3 * @brief Declares the potentialfield2d physics/numerical component used by QPE experiments.
4 * @ingroup qpe_quantum
5 *
6 * Source: @c core/quantum/potentialfield2d.h. 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
12#pragma once
13
14#include <cstddef>
15#include <cstdint>
16#include <vector>
17
18namespace qpe {
19
20class ComplexField2D;
21
22/**
23 * @brief Data structure used by the Potential Point2D component.
24 *
25 * The structure keeps related values explicit and testable across the QPE physics, analysis, or persistence layers.
26 */
28{
29 float x = 0.0f;
30 float y = 0.0f;
31};
32
33// Scalar potential V(x,y) sampled on the same regular grid used by psi.
34//
35// Geometry methods operate in physical coordinates, not pixel/sample indices.
36// This is intentional: the exact same geometry can later be drawn by the GUI
37// and consumed by the solver without a second coordinate system.
38/**
39 * @brief Implements the Potential Field2D component.
40 *
41 * The class provides one focused service within the QPE architecture and is documented here independently of the experiment-level Help.
42 */
44{
45public:
46 using Value = float;
47
48 /**
49 * @brief Performs potential field2 d.
50 */
51 PotentialField2D() = default;
52 /**
53 * @brief Performs potential field2 d.
54 * @param width The width value used by the operation.
55 * @param height The height value used by the operation.
56 * @param dx The dx value used by the operation.
57 * @param dy The dy value used by the operation.
58 */
59 PotentialField2D(std::size_t width,
60 std::size_t height,
61 float dx = 1.0f,
62 float dy = 1.0f);
63
64 /**
65 * @brief Performs resize.
66 * @param width The width value used by the operation.
67 * @param height The height value used by the operation.
68 * @param dx The dx value used by the operation.
69 * @param dy The dy value used by the operation.
70 */
71 void resize(std::size_t width,
72 std::size_t height,
73 float dx = 1.0f,
74 float dy = 1.0f);
75
76 /**
77 * @brief Performs clear.
78 */
79 void clear() noexcept;
80 /**
81 * @brief Performs fill.
82 * @param value Value to assign or evaluate.
83 */
84 void fill(Value value) noexcept;
85
86 /**
87 * @brief Performs empty.
88 */
89 bool empty() const noexcept;
90
91 /**
92 * @brief Returns width.
93 */
94 std::size_t width() const noexcept;
95 /**
96 * @brief Returns height.
97 */
98 std::size_t height() const noexcept;
99 /**
100 * @brief Returns size.
101 */
102 std::size_t size() const noexcept;
103
104 /**
105 * @brief Performs dx.
106 */
107 float dx() const noexcept;
108 /**
109 * @brief Performs dy.
110 */
111 float dy() const noexcept;
112
113 /**
114 * @brief Returns the potential sample at a grid coordinate without bounds checking.
115 * @param x Zero-based X sample index.
116 * @param y Zero-based Y sample index.
117 * @return Potential value at `(x,y)`.
118 */
119 Value operator()(std::size_t x, std::size_t y) const noexcept;
120 /**
121 * @brief Performs at.
122 * @param x X coordinate/value.
123 * @param y Y coordinate/value.
124 */
125 Value at(std::size_t x, std::size_t y) const;
126
127 /**
128 * @brief Performs set.
129 * @param x X coordinate/value.
130 * @param y Y coordinate/value.
131 * @param value Value to assign or evaluate.
132 */
133 void set(std::size_t x, std::size_t y, Value value) noexcept;
134 /**
135 * @brief Sets at.
136 * @param x X coordinate/value.
137 * @param y Y coordinate/value.
138 * @param value Value to assign or evaluate.
139 */
140 void setAt(std::size_t x, std::size_t y, Value value);
141
142 // Add another sampled potential defined on the same grid. This is used
143 // by PotentialScene2D to compose independent potential terms without
144 // changing the semantics of the existing geometry rasterizers.
145 /**
146 * @brief Performs accumulate.
147 * @param other The other value used by the operation.
148 * @param scale The scale value used by the operation.
149 */
150 void accumulate(const PotentialField2D &other, Value scale = 1.0f);
151
152 /**
153 * @brief Performs data.
154 */
155 const Value *data() const noexcept;
156
157 /**
158 * @brief Performs matches grid.
159 * @param field Field data to read or modify.
160 */
161 bool matchesGrid(const ComplexField2D &field) const noexcept;
162
163 /**
164 * @brief Performs minimum.
165 */
166 Value minimum() const noexcept;
167 /**
168 * @brief Performs maximum.
169 */
170 Value maximum() const noexcept;
171
172 /**
173 * @brief Performs revision.
174 */
175 std::uint64_t revision() const noexcept;
176
177 // Physical coordinate of a sample. As for GaussianPacket2D, the grid is
178 // centred around (0,0); even-sized grids therefore straddle zero.
179 /**
180 * @brief Performs x coordinate.
181 * @param x X coordinate/value.
182 */
183 double xCoordinate(std::size_t x) const noexcept;
184 /**
185 * @brief Performs y coordinate.
186 * @param y Y coordinate/value.
187 */
188 double yCoordinate(std::size_t y) const noexcept;
189
190 // Geometry primitives. Every call updates the field in one bulk operation
191 // and increments revision() exactly once.
192 /**
193 * @brief Adds rectangle.
194 * @param centerX The center x value used by the operation.
195 * @param centerY The center y value used by the operation.
196 * @param width The width value used by the operation.
197 * @param height The height value used by the operation.
198 * @param value Value to assign or evaluate.
199 */
200 void addRectangle(float centerX,
201 float centerY,
202 float width,
203 float height,
204 Value value);
205
206 /**
207 * @brief Adds circle.
208 * @param centerX The center x value used by the operation.
209 * @param centerY The center y value used by the operation.
210 * @param radius The radius value used by the operation.
211 * @param value Value to assign or evaluate.
212 */
213 void addCircle(float centerX,
214 float centerY,
215 float radius,
216 Value value);
217
218 // Thick finite line segment, useful for arbitrary barriers/walls.
219 /**
220 * @brief Adds barrier.
221 * @param x1 The x1 value used by the operation.
222 * @param y1 The y1 value used by the operation.
223 * @param x2 The x2 value used by the operation.
224 * @param y2 The y2 value used by the operation.
225 * @param thickness The thickness value used by the operation.
226 * @param value Value to assign or evaluate.
227 */
228 void addBarrier(float x1,
229 float y1,
230 float x2,
231 float y2,
232 float thickness,
233 Value value);
234
235 /**
236 * @brief Adds polygon.
237 * @param vertices The vertices value used by the operation.
238 * @param value Value to assign or evaluate.
239 */
240 void addPolygon(const std::vector<PotentialPoint2D> &vertices,
241 Value value);
242
243 // Vertical full-height wall with one aperture.
244 /**
245 * @brief Adds single slit.
246 * @param centerX The center x value used by the operation.
247 * @param barrierWidth The barrier width value used by the operation.
248 * @param slitCenterY The slit center y value used by the operation.
249 * @param slitHeight The slit height value used by the operation.
250 * @param value Value to assign or evaluate.
251 */
252 void addSingleSlit(float centerX,
253 float barrierWidth,
254 float slitCenterY,
255 float slitHeight,
256 Value value);
257
258 // Vertical full-height wall with two apertures. slitSeparation is the
259 // centre-to-centre distance between the two openings.
260 /**
261 * @brief Adds double slit.
262 * @param centerX The center x value used by the operation.
263 * @param barrierWidth The barrier width value used by the operation.
264 * @param slitCenterY The slit center y value used by the operation.
265 * @param slitSeparation The slit separation value used by the operation.
266 * @param slitHeight The slit height value used by the operation.
267 * @param value Value to assign or evaluate.
268 */
269 void addDoubleSlit(float centerX,
270 float barrierWidth,
271 float slitCenterY,
272 float slitSeparation,
273 float slitHeight,
274 Value value);
275
276 // Smooth analytic potentials. These are additive terms sampled directly
277 // on the simulation grid. Positive/negative amplitudes naturally produce
278 // barriers/wells where applicable.
279 /**
280 * @brief Adds gaussian.
281 * @param centerX The center x value used by the operation.
282 * @param centerY The center y value used by the operation.
283 * @param sigmaX The sigma x value used by the operation.
284 * @param sigmaY The sigma y value used by the operation.
285 * @param amplitude The amplitude value used by the operation.
286 */
287 void addGaussian(float centerX,
288 float centerY,
289 float sigmaX,
290 float sigmaY,
291 Value amplitude);
292
293 /**
294 * @brief Adds harmonic.
295 * @param centerX The center x value used by the operation.
296 * @param centerY The center y value used by the operation.
297 * @param offset The offset value used by the operation.
298 * @param curvatureX The curvature x value used by the operation.
299 * @param curvatureY The curvature y value used by the operation.
300 */
301 void addHarmonic(float centerX,
302 float centerY,
303 Value offset,
304 float curvatureX,
305 float curvatureY);
306
307 // Traceless quadratic deformation used by the Berry-phase loop:
308 // V += q1[(x-xc)^2-(y-yc)^2] + 2 q2 (x-xc)(y-yc).
309 // Together with an isotropic harmonic trap, (q1,q2) rotates a fixed
310 // anisotropy without changing its principal curvatures.
311 /**
312 * @brief Adds quadrupole.
313 * @param centerX The center x value used by the operation.
314 * @param centerY The center y value used by the operation.
315 * @param q1 The q1 value used by the operation.
316 * @param q2 The q2 value used by the operation.
317 */
318 void addQuadrupole(float centerX,
319 float centerY,
320 Value q1,
321 Value q2);
322
323 // One-dimensional standing-wave optical lattice used by Kapitza-Dirac
324 // diffraction. period is the spatial period of the intensity/potential:
325 // V += depth * cos^2(pi*x/period + phase/2).
326 /**
327 * @brief Adds standing wave x.
328 * @param period The period value used by the operation.
329 * @param depth The depth value used by the operation.
330 * @param phaseDegrees The phase degrees value used by the operation.
331 */
332 void addStandingWaveX(float period,
333 Value depth,
334 float phaseDegrees = 0.0f);
335
336 /**
337 * @brief Adds linear.
338 * @param centerX The center x value used by the operation.
339 * @param centerY The center y value used by the operation.
340 * @param offset The offset value used by the operation.
341 * @param slopeX The slope x value used by the operation.
342 * @param slopeY The slope y value used by the operation.
343 */
344 void addLinear(float centerX,
345 float centerY,
346 Value offset,
347 float slopeX,
348 float slopeY);
349
350 /**
351 * @brief Adds softened radial.
352 * @param centerX The center x value used by the operation.
353 * @param centerY The center y value used by the operation.
354 * @param coupling The coupling value used by the operation.
355 * @param softening The softening value used by the operation.
356 */
357 void addSoftenedRadial(float centerX,
358 float centerY,
359 Value coupling,
360 float softening);
361
362 // Finite Bunimovich-stadium billiard: V=0 inside the stadium and
363 // V=value everywhere outside it. straightLength is the distance between
364 // the centres of the two semicircular end caps; radius is the common
365 // stadium radius. This primitive is intended for closed quantum billiards.
366 /**
367 * @brief Adds stadium exterior.
368 * @param centerX The center x value used by the operation.
369 * @param centerY The center y value used by the operation.
370 * @param straightLength The straight length value used by the operation.
371 * @param radius The radius value used by the operation.
372 * @param value Value to assign or evaluate.
373 */
374 void addStadiumExterior(float centerX,
375 float centerY,
376 float straightLength,
377 float radius,
378 Value value);
379
380private:
381 /**
382 * @brief Returns index.
383 * @param x X coordinate/value.
384 * @param y Y coordinate/value.
385 */
386 std::size_t index(std::size_t x, std::size_t y) const noexcept;
387 /**
388 * @brief Checks ed index.
389 * @param x X coordinate/value.
390 * @param y Y coordinate/value.
391 */
392 std::size_t checkedIndex(std::size_t x, std::size_t y) const;
393 /**
394 * @brief Performs touch.
395 */
396 void touch() noexcept;
397
398 std::size_t width_ = 0;
399 std::size_t height_ = 0;
400 float dx_ = 1.0f;
401 float dy_ = 1.0f;
402 std::vector<Value> data_;
403 std::uint64_t revision_ = 0;
404};
405
406} // namespace qpe
Owning Cartesian grid of complex scalar samples.
Implements the Potential Field2D component.
Value at(std::size_t x, std::size_t y) const
Performs at.
void addHarmonic(float centerX, float centerY, Value offset, float curvatureX, float curvatureY)
Adds harmonic.
std::size_t height() const noexcept
Returns height.
void addLinear(float centerX, float centerY, Value offset, float slopeX, float slopeY)
Adds linear.
void clear() noexcept
Performs clear.
void fill(Value value) noexcept
Performs fill.
std::uint64_t revision() const noexcept
Performs revision.
void resize(std::size_t width, std::size_t height, float dx=1.0f, float dy=1.0f)
Performs resize.
void addPolygon(const std::vector< PotentialPoint2D > &vertices, Value value)
Adds polygon.
void addRectangle(float centerX, float centerY, float width, float height, Value value)
Adds rectangle.
double xCoordinate(std::size_t x) const noexcept
Performs x coordinate.
std::size_t checkedIndex(std::size_t x, std::size_t y) const
Checks ed index.
Value minimum() const noexcept
Performs minimum.
std::size_t size() const noexcept
Returns size.
float dy() const noexcept
Performs dy.
void touch() noexcept
Performs touch.
bool matchesGrid(const ComplexField2D &field) const noexcept
Performs matches grid.
const Value * data() const noexcept
Performs data.
void setAt(std::size_t x, std::size_t y, Value value)
Sets at.
void addCircle(float centerX, float centerY, float radius, Value value)
Adds circle.
bool empty() const noexcept
Performs empty.
std::size_t index(std::size_t x, std::size_t y) const noexcept
Returns index.
void addGaussian(float centerX, float centerY, float sigmaX, float sigmaY, Value amplitude)
Adds gaussian.
std::size_t width() const noexcept
Returns width.
std::vector< Value > data_
void addStandingWaveX(float period, Value depth, float phaseDegrees=0.0f)
Adds standing wave x.
double yCoordinate(std::size_t y) const noexcept
Performs y coordinate.
float dx() const noexcept
Performs dx.
PotentialField2D()=default
Performs potential field2 d.
void addQuadrupole(float centerX, float centerY, Value q1, Value q2)
Adds quadrupole.
void addBarrier(float x1, float y1, float x2, float y2, float thickness, Value value)
Adds barrier.
void set(std::size_t x, std::size_t y, Value value) noexcept
Performs set.
void addStadiumExterior(float centerX, float centerY, float straightLength, float radius, Value value)
Adds stadium exterior.
void addSoftenedRadial(float centerX, float centerY, Value coupling, float softening)
Adds softened radial.
void accumulate(const PotentialField2D &other, Value scale=1.0f)
Performs accumulate.
void addDoubleSlit(float centerX, float barrierWidth, float slitCenterY, float slitSeparation, float slitHeight, Value value)
Adds double slit.
Value maximum() const noexcept
Performs maximum.
void addSingleSlit(float centerX, float barrierWidth, float slitCenterY, float slitHeight, Value value)
Adds single slit.
Data structure used by the Potential Point2D component.