Fix bug when symmetry + non-symmetric boundary conditions are defined #2429
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a bug a user encountered which was brought to my attention by @FilipeFcp. Basically, when a simulation is created with symmetry applied along a given axis, but with boundary conditions that differ on the left and right side, physically we just ignore the left side. However, in the case of PML/Absorber boundaries with a different number of layers, the simulation grid that would be created would still use the left-side number of layers, and create a non-symmetric grid on which the "expanded fields" are defined.
The initial fix I tried (the code change here) just fixes the grid generation to use whatever number of layers is on the right. This fixes the issue that was observed in the recorded field data, however I realize that the current state can still be kind of confusing. For example, if I plot such a simulation, I get this:
Obviously something is going wrong here too as the overlaid "symmetry region" extends into the large absorber region on the right. Ideally, if we are neglecting the boundary definition on the left, we should actually incorporate this everywhere, and e.g. display the simulation with the right-side boundary on the left, too.
I'm afraid doing this automatically may be a bit frustrating though. For example, one option is to create a
_boundary_spec
property that mirrorsboundary_spec
, but replaces any minus-side boundaries with the plus-side ones, if a symmetry is applied - then use this everywhere internally. The issue though is that what is written to the json will not correspond to what is e.g. displayed, which can again be confusing. Maybe better is to take the route of introducing a validator that would modify theboundary_spec
upon creation - but might that be confusing to the user too? Meaning that their input will be modified - but in some sense, it will be "made right".The last alternative is to just add a validator to require that the user makes the boundary specs symmetric, if symmetry is applied. More strict from a user perspective, but at least fool- and confusion-proof.
After writing all this out, maybe the best is to add the dynamic validator that modifies
boundary_spec
if needed. What do you think @yaugenst ?