Skip to content
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

Merged
merged 2 commits into from
Dec 11, 2019
Merged

add kz-2d option in Scheme, like in Python #1062

merged 2 commits into from
Dec 11, 2019

Conversation

stevengj
Copy link
Collaborator

Mirrors #1035. Replaces undocumented special-kz?

@oskooi
Copy link
Collaborator

oskooi commented Nov 29, 2019

This is not working as expected: the results for kz-2d="real/imag" and kz-2d="3d" are identical to kz-2d="complex" (whereas they should be different). This demonstrated in the four cases below for the test based on the Python example in 2d Cell with Out-of-Plane Wavevector.

(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

Using MPI version 3.1, 1 processes
-----------
Initializing structure...
Working in 3D dimensions.
Computational cell is 12 x 0 x 0 with resolution 100
time for choose_chunkdivision = 0.000444852 s
time for set_epsilon = 0.00638165 s
-----------
Meep: using complex fields.
field decay(t = 50.005): 0.2812781878868968 / 0.2812781878868968 = 1.0
on time step 18550 (time=92.75), 0.000215639 s/step
field decay(t = 100.01): 6.779250788039936e-10 / 0.2812781878868968 = 2.410158725413114e-9
field decay(t = 150.01500000000001): 1.441138674098281e-14 / 0.2812781878868968 = 5.1235351198926564e-14
run 0 finished at t = 150.01500000000001 (30003 timesteps)
flux1:, 1.0, 6.627873733577471
creating output file "./refl-angular-kz2d-refl-flux.h5"...
-----------
Initializing structure...
Working in 3D dimensions.
Computational cell is 12 x 0 x 0 with resolution 100
     block, center = (3,0,0)
          size (6,1e+20,1e+20)
          axes (1,0,0), (0,1,0), (0,0,1)
          dielectric constant epsilon diagonal = (12.25,12.25,12.25)
time for choose_chunkdivision = 0.000422211 s
time for set_epsilon = 0.00963338 s
-----------
Meep: using complex fields.
field decay(t = 50.005): 0.3197934615090844 / 0.3197934615090844 = 1.0
on time step 18109 (time=90.545), 0.000220892 s/step
field decay(t = 100.01): 2.2728475122971836e-5 / 0.3197934615090844 = 7.107235718866062e-5
field decay(t = 150.01500000000001): 3.5295805813682057e-13 / 0.3197934615090844 = 1.1037062999075547e-12
run 1 finished at t = 150.01500000000001 (30003 timesteps)
flux2:, 1.0, -2.16885915926775

notes: 3d simulation with complex fields.

test 2. this branch; kz-2d="3d": R=0.32723384536461509102

$ meep kz-2d=\"3d\" refl-angular-kz2d.ctl
Using MPI version 3.1, 1 processes
command-line param: kz-2d="3d"
-----------
Initializing structure...
Working in 2D dimensions.
Computational cell is 12 x 0 x 0 with resolution 100
time for choose_chunkdivision = 0.000422745 s
time for set_epsilon = 0.00222137 s
-----------
Meep: using complex fields.
field decay(t = 50.005): 0.2812794555668702 / 0.2812794555668702 = 1.0
field decay(t = 100.01): 6.779199536132915e-10 / 0.2812794555668702 = 2.410129642234485e-9
field decay(t = 150.01500000000001): 1.4411411411334994e-14 / 0.2812794555668702 = 5.123520799729679e-14
run 0 finished at t = 150.01500000000001 (30003 timesteps)
flux1:, 1.0, 6.628610417760838
creating output file "./refl-angular-kz2d-refl-flux.h5"...
-----------
Initializing structure...
Working in 2D dimensions.
Computational cell is 12 x 0 x 0 with resolution 100
     block, center = (3,0,0)
          size (6,1e+20,1e+20)
          axes (1,0,0), (0,1,0), (0,0,1)
          dielectric constant epsilon diagonal = (12.25,12.25,12.25)
time for choose_chunkdivision = 0.000407884 s
time for set_epsilon = 0.00319857 s
-----------
Meep: using complex fields.
field decay(t = 50.005): 0.3197923858755609 / 0.3197923858755609 = 1.0
field decay(t = 100.01): 2.2729242537770092e-5 / 0.3197923858755609 = 7.107499597133811e-5
field decay(t = 150.01500000000001): 3.529403224473502e-13 / 0.3197923858755609 = 1.1036545522528105e-12
run 1 finished at t = 150.01500000000001 (30003 timesteps)
flux2:, 1.0, -2.1691056764278267

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

$ meep kz-2d=\"real\/imag\" refl-angular-kz2d.ctl
Using MPI version 3.1, 1 processes
command-line param: kz-2d="real/imag"
-----------
Initializing structure...
Working in 2D dimensions.
Computational cell is 12 x 0 x 0 with resolution 100
time for choose_chunkdivision = 0.000419934 s
time for set_epsilon = 0.00217976 s
-----------
Meep: using complex fields.
field decay(t = 50.005): 0.2812794555668702 / 0.2812794555668702 = 1.0
field decay(t = 100.01): 6.779199536132915e-10 / 0.2812794555668702 = 2.410129642234485e-9
field decay(t = 150.01500000000001): 1.4411411411334994e-14 / 0.2812794555668702 = 5.123520799729679e-14
run 0 finished at t = 150.01500000000001 (30003 timesteps)
flux1:, 1.0, 6.628610417760838
creating output file "./refl-angular-kz2d-refl-flux.h5"...
-----------
Initializing structure...
Working in 2D dimensions.
Computational cell is 12 x 0 x 0 with resolution 100
     block, center = (3,0,0)
          size (6,1e+20,1e+20)
          axes (1,0,0), (0,1,0), (0,0,1)
          dielectric constant epsilon diagonal = (12.25,12.25,12.25)
time for choose_chunkdivision = 0.000409589 s
time for set_epsilon = 0.00318009 s
-----------
Meep: using complex fields.
field decay(t = 50.005): 0.3197923858755609 / 0.3197923858755609 = 1.0
field decay(t = 100.01): 2.2729242537770092e-5 / 0.3197923858755609 = 7.107499597133811e-5
field decay(t = 150.01500000000001): 3.529403224473502e-13 / 0.3197923858755609 = 1.1036545522528105e-12
run 1 finished at t = 150.01500000000001 (30003 timesteps)
flux2:, 1.0, -2.1691056764278267

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

$ meep kz-2d=\"complex\" refl-angular-kz2d.ctl
Using MPI version 3.1, 1 processes
command-line param: kz-2d="complex"
-----------
Initializing structure...
Working in 2D dimensions.
Computational cell is 12 x 0 x 0 with resolution 100
time for choose_chunkdivision = 0.000429341 s
time for set_epsilon = 0.00222978 s
-----------
Meep: using complex fields.
field decay(t = 50.005): 0.2812794555668702 / 0.2812794555668702 = 1.0
field decay(t = 100.01): 6.779199536132915e-10 / 0.2812794555668702 = 2.410129642234485e-9
field decay(t = 150.01500000000001): 1.4411411411334994e-14 / 0.2812794555668702 = 5.123520799729679e-14
run 0 finished at t = 150.01500000000001 (30003 timesteps)
flux1:, 1.0, 6.628610417760838
creating output file "./refl-angular-kz2d-refl-flux.h5"...
-----------
Initializing structure...
Working in 2D dimensions.
Computational cell is 12 x 0 x 0 with resolution 100
     block, center = (3,0,0)
          size (6,1e+20,1e+20)
          axes (1,0,0), (0,1,0), (0,0,1)
          dielectric constant epsilon diagonal = (12.25,12.25,12.25)
time for choose_chunkdivision = 0.000416895 s
time for set_epsilon = 0.00322164 s
-----------
Meep: using complex fields.
field decay(t = 50.005): 0.3197923858755609 / 0.3197923858755609 = 1.0
field decay(t = 100.01): 2.2729242537770092e-5 / 0.3197923858755609 = 7.107499597133811e-5
field decay(t = 150.01500000000001): 3.529403224473502e-13 / 0.3197923858755609 = 1.1036545522528105e-12
run 1 finished at t = 150.01500000000001 (30003 timesteps)
flux2:, 1.0, -2.1691056764278267

notes: 2d simulation with complex fields which is correct.

@stevengj
Copy link
Collaborator Author

stevengj commented Dec 5, 2019

Just pushed a bugfix.

@oskooi
Copy link
Collaborator

oskooi commented Dec 5, 2019

Seems to be working now for "3d" and "complex" but not for "real/imag".

test 2. this branch; kz-2d="3d" (correct)

$ meep kz-2d=\"3d\" refl-angular-kz2d.ctl
Using MPI version 3.1, 1 processes
command-line param: kz-2d="3d"
-----------
Initializing structure...
Working in 3D dimensions.
Computational cell is 12 x 0 x 0 with resolution 100
time for choose_chunkdivision = 0.00043975 s
time for set_epsilon = 0.00666184 s
-----------
Meep: using complex fields.
field decay(t = 50.005): 0.2812781878868968 / 0.2812781878868968 = 1.0
on time step 18561 (time=92.805), 0.000215516 s/step
field decay(t = 100.01): 6.779250788039936e-10 / 0.2812781878868968 = 2.410158725413114e-9
field decay(t = 150.01500000000001): 1.441138674098281e-14 / 0.2812781878868968 = 5.1235351198926564e-14
run 0 finished at t = 150.01500000000001 (30003 timesteps)
flux1:, 1.0, 6.627873733577471
creating output file "./refl-angular-kz2d-refl-flux.h5"...
-----------
Initializing structure...
Working in 3D dimensions.
Computational cell is 12 x 0 x 0 with resolution 100
     block, center = (3,0,0)
          size (6,1e+20,1e+20)
          axes (1,0,0), (0,1,0), (0,0,1)
          dielectric constant epsilon diagonal = (12.25,12.25,12.25)
time for choose_chunkdivision = 0.000422233 s
time for set_epsilon = 0.00908603 s
-----------
Meep: using complex fields.
field decay(t = 50.005): 0.3197934615090844 / 0.3197934615090844 = 1.0
on time step 18015 (time=90.075), 0.00022204 s/step
field decay(t = 100.01): 2.2728475122971836e-5 / 0.3197934615090844 = 7.107235718866062e-5
field decay(t = 150.01500000000001): 3.5295805813682057e-13 / 0.3197934615090844 = 1.1037062999075547e-12
run 1 finished at t = 150.01500000000001 (30003 timesteps)
flux2:, 1.0, -2.16885915926775

notes: 3d simulation with complex fields which is correct.

test 3. this branch; kz-2d="real/imag" (incorrect)

$ meep kz-2d=\"real\/imag\" refl-angular-kz2d.ctl
Using MPI version 3.1, 1 processes
command-line param: kz-2d="real/imag"
-----------
Initializing structure...
Working in 2D dimensions.
Computational cell is 12 x 0 x 0 with resolution 100
time for choose_chunkdivision = 0.000424123 s
time for set_epsilon = 0.00222528 s
-----------
field decay(t = 50.005): 0.2812099361065445 / 0.2812099361065445 = 1.0
field decay(t = 100.01): 4.92105633236362e-13 / 0.2812099361065445 = 1.7499581986673243e-12
run 0 finished at t = 100.01 (20002 timesteps)
flux1:, 1.0, 1.6571526131041487
creating output file "./refl-angular-kz2d-refl-flux.h5"...
-----------
Initializing structure...
Working in 2D dimensions.
Computational cell is 12 x 0 x 0 with resolution 100
     block, center = (3,0,0)
          size (6,1e+20,1e+20)
          axes (1,0,0), (0,1,0), (0,0,1)
          dielectric constant epsilon diagonal = (12.25,12.25,12.25)
time for choose_chunkdivision = 0.000407652 s
time for set_epsilon = 0.003203 s
-----------
field decay(t = 50.005): 0.31935437830252517 / 0.31935437830252517 = 1.0
field decay(t = 100.01): 1.670959985971737e-5 / 0.31935437830252517 = 5.232306489278293e-5
field decay(t = 150.01500000000001): 2.155564131875997e-15 / 0.31935437830252517 = 6.7497560025121246e-15
run 1 finished at t = 150.01500000000001 (30003 timesteps)
flux2:, 1.0, -0.5422763490632887

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)

$ meep kz-2d=\"complex\" refl-angular-kz2d.ctl
Using MPI version 3.1, 1 processes
command-line param: kz-2d="complex"
-----------
Initializing structure...
Working in 2D dimensions.
Computational cell is 12 x 0 x 0 with resolution 100
time for choose_chunkdivision = 0.000421726 s
time for set_epsilon = 0.00224295 s
-----------
Meep: using complex fields.
field decay(t = 50.005): 0.2812794555668702 / 0.2812794555668702 = 1.0
field decay(t = 100.01): 6.779199536132915e-10 / 0.2812794555668702 = 2.410129642234485e-9
field decay(t = 150.01500000000001): 1.4411411411334994e-14 / 0.2812794555668702 = 5.123520799729679e-14
run 0 finished at t = 150.01500000000001 (30003 timesteps)
flux1:, 1.0, 6.628610417760838
creating output file "./refl-angular-kz2d-refl-flux.h5"...
-----------
Initializing structure...
Working in 2D dimensions.
Computational cell is 12 x 0 x 0 with resolution 100
     block, center = (3,0,0)
          size (6,1e+20,1e+20)
          axes (1,0,0), (0,1,0), (0,0,1)
          dielectric constant epsilon diagonal = (12.25,12.25,12.25)
time for choose_chunkdivision = 0.000412161 s
time for set_epsilon = 0.00334707 s
-----------
Meep: using complex fields.
field decay(t = 50.005): 0.3197923858755609 / 0.3197923858755609 = 1.0
field decay(t = 100.01): 2.2729242537770092e-5 / 0.3197923858755609 = 7.107499597133811e-5
field decay(t = 150.01500000000001): 3.529403224473502e-13 / 0.3197923858755609 = 1.1036545522528105e-12
run 1 finished at t = 150.01500000000001 (30003 timesteps)
flux2:, 1.0, -2.1691056764278267

notes: 2d simulation with complex fields which is correct.

@stevengj
Copy link
Collaborator Author

stevengj commented Dec 5, 2019

Not sure what the issue is yet.

@oskooi
Copy link
Collaborator

oskooi commented Dec 6, 2019

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.

@stevengj stevengj merged commit 5dcdf58 into master Dec 11, 2019
@stevengj stevengj deleted the kz2d-scheme branch December 11, 2019 02:07
bencbartlett pushed a commit to bencbartlett/meep that referenced this pull request Sep 9, 2021
* add kz-2d option in scheme, like in Python, replacing undocumented special-kz

* whoops, strings in scheme use equal, not eq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants