File: zone_plate.py

package info (click to toggle)
meep-openmpi 1.25.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 64,556 kB
  • sloc: cpp: 32,214; python: 27,958; lisp: 1,225; makefile: 505; sh: 249; ansic: 131; javascript: 5
file content (153 lines) | stat: -rw-r--r-- 3,871 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import math

import matplotlib.pyplot as plt
import numpy as np

import meep as mp

resolution = 25  # pixels/μm

dpml = 1.0  # PML thickness
dsub = 2.0  # substrate thickness
dpad = 2.0  # padding betweeen zone plate and PML
zh = 0.5  # zone-plate height
zN = 25  # number of zones (odd zones: π phase shift, even zones: none)
focal_length = 200  # focal length of zone plate
spot_length = 100  # far-field line length
ff_res = 10  # far-field resolution

pml_layers = [mp.PML(thickness=dpml)]

wvl_cen = 0.5
frq_cen = 1 / wvl_cen
dfrq = 0.2 * frq_cen

## radii of zones
## ref: eq. 7 of http://zoneplate.lbl.gov/theory
r = [
    math.sqrt(n * wvl_cen * (focal_length + n * wvl_cen / 4)) for n in range(1, zN + 1)
]

sr = r[-1] + dpad + dpml
sz = dpml + dsub + zh + dpad + dpml
cell_size = mp.Vector3(sr, 0, sz)

sources = [
    mp.Source(
        mp.GaussianSource(frq_cen, fwidth=dfrq, is_integrated=True),
        component=mp.Er,
        center=mp.Vector3(0.5 * sr, 0, -0.5 * sz + dpml),
        size=mp.Vector3(sr),
    ),
    mp.Source(
        mp.GaussianSource(frq_cen, fwidth=dfrq, is_integrated=True),
        component=mp.Ep,
        center=mp.Vector3(0.5 * sr, 0, -0.5 * sz + dpml),
        size=mp.Vector3(sr),
        amplitude=-1j,
    ),
]

glass = mp.Medium(index=1.5)

geometry = [
    mp.Block(
        material=glass,
        size=mp.Vector3(sr, 0, dpml + dsub),
        center=mp.Vector3(0.5 * sr, 0, -0.5 * sz + 0.5 * (dpml + dsub)),
    )
]

geometry.extend(
    mp.Block(
        material=glass if n % 2 == 0 else mp.vacuum,
        size=mp.Vector3(r[n], 0, zh),
        center=mp.Vector3(0.5 * r[n], 0, -0.5 * sz + dpml + dsub + 0.5 * zh),
    )
    for n in range(zN - 1, -1, -1)
)

sim = mp.Simulation(
    cell_size=cell_size,
    boundary_layers=pml_layers,
    resolution=resolution,
    sources=sources,
    geometry=geometry,
    dimensions=mp.CYLINDRICAL,
    m=-1,
)

## near-field monitor
n2f_obj = sim.add_near2far(
    frq_cen,
    0,
    1,
    mp.Near2FarRegion(
        center=mp.Vector3(0.5 * (sr - dpml), 0, 0.5 * sz - dpml),
        size=mp.Vector3(sr - dpml),
    ),
    mp.Near2FarRegion(
        center=mp.Vector3(sr - dpml, 0, 0.5 * sz - dpml - 0.5 * (dsub + zh + dpad)),
        size=mp.Vector3(z=dsub + zh + dpad),
    ),
)

sim.plot2D()
if mp.am_master():
    plt.savefig("zone_plate_epsilon.png", bbox_inches="tight", dpi=150)

sim.run(until_after_sources=100)

ff_r = sim.get_farfields(
    n2f_obj,
    ff_res,
    center=mp.Vector3(
        0.5 * (sr - dpml), 0, -0.5 * sz + dpml + dsub + zh + focal_length
    ),
    size=mp.Vector3(sr - dpml),
)

ff_z = sim.get_farfields(
    n2f_obj,
    ff_res,
    center=mp.Vector3(z=-0.5 * sz + dpml + dsub + zh + focal_length),
    size=mp.Vector3(z=spot_length),
)

E2_r = (
    np.absolute(ff_r["Ex"]) ** 2
    + np.absolute(ff_r["Ey"]) ** 2
    + np.absolute(ff_r["Ez"]) ** 2
)
E2_z = (
    np.absolute(ff_z["Ex"]) ** 2
    + np.absolute(ff_z["Ey"]) ** 2
    + np.absolute(ff_z["Ez"]) ** 2
)

if mp.am_master():
    plt.figure(dpi=200)
    plt.subplot(1, 2, 1)
    plt.semilogy(np.linspace(0, sr - dpml, len(E2_r)), E2_r, "bo-")
    plt.xlim(-2, 20)
    plt.xticks(list(np.arange(0, 25, 5)))
    plt.grid(True, axis="y", which="both", ls="-")
    plt.xlabel(r"$r$ coordinate (μm)")
    plt.ylabel(r"energy density of far fields, |E|$^2$")
    plt.subplot(1, 2, 2)
    plt.semilogy(
        np.linspace(
            focal_length - 0.5 * spot_length,
            focal_length + 0.5 * spot_length,
            len(E2_z),
        ),
        E2_z,
        "bo-",
    )
    plt.grid(True, axis="y", which="both", ls="-")
    plt.xlabel(r"$z$ coordinate (μm)")
    plt.ylabel(r"energy density of far fields, |E|$^2$")
    plt.suptitle(f"binary-phase zone plate with focal length $z$ = {focal_length} μm")

    plt.tight_layout()
    plt.savefig("zone_plate_farfields.png")