-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add kz-2d option in Scheme, like in Python #1062
Conversation
This is not working as expected: the results for (set-param! resolution 100)
(define dpml 1.0)
(define sx 10)
(set! sx (+ sx (* 2 dpml)))
(define cell (make lattice (size sx no-size no-size)))
(set! geometry-lattice cell)
(define boundary-layers (list (make pml (thickness dpml))))
(set! pml-layers boundary-layers)
(define fcen 1.0)
;; rotation angle of source: CCW around Y axis, 0 degrees along +X axis
(define-param theta 19.4)
(set! theta (deg->rad theta))
;; plane of incidence is XZ
(define k (vector3* fcen (vector3 0 0 (sin theta))))
(set! k-point k)
(set-param! kz-2d "real/imag")
(define pw-src (list (make source
(src (make gaussian-src (frequency fcen) (fwidth (* 0.2 fcen))))
(component Ey)
(center (+ (* -0.5 sx) dpml)))))
(set! sources pw-src)
(define refl (add-flux fcen 0 1 (make flux-region (center (* -0.25 sx)))))
(run-sources+ (stop-when-fields-decayed 50 Ey (vector3 (+ (* -0.5 sx) dpml)) 1e-9))
(display-fluxes refl)
(save-flux "refl-flux" refl)
(reset-meep)
(set! geometry-lattice cell)
(set! pml-layers boundary-layers)
(set! k-point k)
(set! sources pw-src)
;; add a block with n=3.5 for the air-dielectric interface
(set! geometry (list (make block
(center (* 0.25 sx))
(size (* 0.5 sx) infinity infinity)
(material (make medium (index 3.5))))))
(define refl (add-flux fcen 0 1 (make flux-region (center (* -0.25 sx)))))
(load-minus-flux "refl-flux" refl)
(run-sources+ (stop-when-fields-decayed 50 Ey (vector3 (+ (* -0.5 sx) dpml)) 1e-9))
(display-fluxes refl) test 1. master (kz-2d param removed): R=0.32723302320623470134
notes: 3d simulation with complex fields. test 2. this branch; kz-2d="3d": R=0.32723384536461509102
notes: 2d simulation with complex fields which is incorrect. Rather, this should be a 3d simulation with complex fields identical to test 1. test 3. this branch; kz-2d="real/imag": R=0.32723384536461509102
notes: 2d simulation with complex fields which is incorrect. Should be a 2d simulation with real fields. test 4. this branch; kz-2d="complex": R=0.32723384536461509102
notes: 2d simulation with complex fields which is correct. |
Just pushed a bugfix. |
Seems to be working now for "3d" and "complex" but not for "real/imag". test 2. this branch; kz-2d="3d" (correct)
notes: 3d simulation with complex fields which is correct. test 3. this branch; kz-2d="real/imag"
notes: 2d simulation with real fields which is correct. Note that the flux values are different than the other tests simply because the simulation involves real rather than complex fields. test 4. this branch; kz-2d="complex" (correct)
notes: 2d simulation with complex fields which is correct. |
Not sure what the issue is yet. |
Actually, the results for this PR after the latest commit are correct. The reflection coefficient in test 3 is 0.32723380138628651758 which matches the analytic result. It's just that the flux values from the normalization and scattering run are different in test 3 than those in test 2 and 4 because the simulation involves real rather than complex fields. The Scheme results are identical to those of the Python version. This PR can therefore be merged and then followed by #1063. |
* add kz-2d option in scheme, like in Python, replacing undocumented special-kz * whoops, strings in scheme use equal, not eq
Mirrors #1035. Replaces undocumented
special-kz?