Add support for dft_force with mirror symmetry#3161
Add support for dft_force with mirror symmetry#3161oskooi wants to merge 1 commit intoNanoComp:masterfrom
dft_force with mirror symmetry#3161Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3161 +/- ##
==========================================
+ Coverage 73.81% 73.91% +0.09%
==========================================
Files 18 18
Lines 5423 5455 +32
==========================================
+ Hits 4003 4032 +29
- Misses 1420 1423 +3
🚀 New features to boost your workflow:
|
|
This "fix" seems wrong. The It could of course be that there is some other bug in how this procedure is being carried out, but the solution is not to remove it entirely, since the symmetry reduction is an important optimization. |
|
It is true, however, that the diagonal and off-diagonal stress-tensor terms should be transformed separately. And the problem is essentially that the (Diagonal terms basically don't pick up any transformation, whereas off-diagonal terms pick up two transformations.) The right fix here is maybe to add a second component to the (For the diagonal terms, we can just set |
|
An even easier fix is to optionally let |
Fixes #129.
Context
#129 reports field instability when combining DFT force monitors with symmetry objects. The root cause is that
fields::add_dft_force()insrc/stress.cppunconditionally callsS.reduce(where_)to apply symmetry reduction to the force region volumes. In contrast,fields::add_dft_flux()insrc/dft.cpphas ause_symmetryparameter (defaulting totrue) that allows bypassingS.reduce().The
S.reduce()operation is problematic for force calculations because the stress tensor involves pairing different field components (E in force direction vs. E in normal direction) as off-diagonal terms. When symmetry transforms the volume and modifies the component weights, the paired DFT chunk lists (offdiag1,offdiag2) can end up with mismatched structures, producing incorrect/unstable force values.Fix
Step 1: Add
use_symmetryparameter toadd_dft_forcein C++ (3 files)src/meep.hpp(lines 2165-2174): Addbool use_symmetry = trueparameter to all threeadd_dft_forceoverloads, matching the pattern ofadd_dft_flux(lines 2045-2057).src/stress.cpp(lines 153-157): Accept the newuse_symmetryparameter and conditionally applyS.reduce():volume_list *where = use_symmetry ? S.reduce(where_): new volume_list(where_); This mirrors dft.cpp line 607.Step 2: Pass
use_symmetry=Falsefrom Python when symmetries are present (1 file)python/simulation.py(lines 3399-3404): Modify_add_forceto passuse_symmetry=Falsetoadd_dft_forcewhen the simulation has symmetry objects. This is done by passing an extra argument through_add_fluxish_stuff, which already supports*argsforwarding (line 3818:add_dft_stuff(vol_list, freq, decimation_factor, *args)).Step 3: Add unit test (1 file)
symmetries=[mp.Mirror(mp.Y)].