Fix bug when combining 2+ mirror symmetries and Bloch-periodic boundary conditions#3155
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3155 +/- ##
==========================================
+ Coverage 73.81% 73.90% +0.09%
==========================================
Files 18 18
Lines 5423 5454 +31
==========================================
+ Hits 4003 4031 +28
- Misses 1420 1423 +3 🚀 New features to boost your workflow:
|
| else { | ||
| const complex<double> I = complex<double>(0.0, 1.0); | ||
| eikna[d] = exp(I * kk * ((2 * pi / a) * gv.num_direction(d))); | ||
| eikna[d] = exp(I * kk * ((2 * pi / a) * user_volume.num_direction(d))); |
There was a problem hiding this comment.
Wow such a simple fix, for such a hairy bug all these years. Very cool!
There was a problem hiding this comment.
The odd thing is that mirror symmetries (the halved dimensions) would only ever be in directions
There was a problem hiding this comment.
However, it would affect you at
|
Can you verify that this fixes #132? It's not clear why it would help in a case where (But even if it fixed an unrelated bug that is nice too.) |
|
It seems the original test case in #132 with |
Fixes #132.
Root Cause
The Bloch phase factor
eikna[d]is computed using the symmetry-reduced grid volume (gv) size, while the periodic lattice translation vector (ilattice_vector) is computed using the full cell size (user_volume). This creates a mismatch between the phase applied per periodic translation and the actual translation distance.Why it only manifests with 2+ mirror symmetries + periodioc boundaries
Mirror(Y)) + periodic in X: only Y is halved, sogv.num_direction(X)equals the original fulluser_volume.nx(). The phase in X is correct. The Y direction typically has k_y = 0 with mirror symmetry, soeikna[Y] = 1regardless.Mirror(X) + Mirror(Y)) + periodic: Both X and Y are halved. If k_x ≠ 0, thengv.num_direction(X)≈user_volume.nx() / 2andeikna[X]is computed for the wrong period. The periodic translation moves by the full cell but applies the phase for half the cell. This produces incorrect field values at boundary conditions leading to expontentially growing errors (instability).eikna = exp(0) = 1regardless of cell size, so the bug is latent and harmless.Two new unit tests are added to compare the symmetry-exploiting simulation against a reference simulation without symmetry, checking field values at multiple points and energies at regular intervals.