In [2]:
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline

In [1]:
import math
import meep as mp
from meep import mpb

num_bands = 8
resolution = 32
geometry_lattice = mp.Lattice(size=mp.Vector3(1, 1),
                              basis1=mp.Vector3(math.sqrt(3) / 2, 0.5),
                              basis2=mp.Vector3(math.sqrt(3) / 2, -0.5))
geometry = [mp.Cylinder(0.2, material=mp.Medium(epsilon=12))]
k_points = [
    mp.Vector3(),               # Gamma
    mp.Vector3(y=0.5),          # M
    mp.Vector3(1 / -3, 1 / 3),  # K
    mp.Vector3(),               # Gamma
]
k_points = mp.interpolate(4, k_points)

ms = mpb.ModeSolver(
    geometry=geometry,
    geometry_lattice=geometry_lattice,
    k_points=k_points,
    resolution=resolution,
    num_bands=num_bands
)
ms.run_tm(mpb.output_at_kpoint(mp.Vector3(1 / -3, 1 / 3), mpb.fix_efield_phase,
          mpb.output_efield_z))
tm_freqs = ms.all_freqs
tm_gaps = ms.gap_list
ms.run_te()
te_freqs = ms.all_freqs
te_gaps = ms.gap_list


Initializing eigensolver data
Computing 8 bands with 1e-07 tolerance
16 k-points
  Vector3<0.0, 0.0, 0.0>
  Vector3<0.0, 0.1, 0.0>
  Vector3<0.0, 0.2, 0.0>
  Vector3<0.0, 0.30000000000000004, 0.0>
  Vector3<0.0, 0.4, 0.0>
  Vector3<0.0, 0.5, 0.0>
  Vector3<-0.06666666666666667, 0.4666666666666667, 0.0>
  Vector3<-0.13333333333333333, 0.43333333333333335, 0.0>
  Vector3<-0.2, 0.39999999999999997, 0.0>
  Vector3<-0.26666666666666666, 0.36666666666666664, 0.0>
  Vector3<-0.3333333333333333, 0.3333333333333333, 0.0>
  Vector3<-0.26666666666666666, 0.26666666666666666, 0.0>
  Vector3<-0.19999999999999998, 0.19999999999999998, 0.0>
  Vector3<-0.1333333333333333, 0.1333333333333333, 0.0>
  Vector3<-0.06666666666666665, 0.06666666666666665, 0.0>
  Vector3<0.0, 0.0, 0.0>
elapsed time for initialization: 0.004171609878540039
Outputting epsilon.h5...
elapsed time for k point: 0.0905911922454834
elapsed time for k point: 0.055701494216918945
elapsed time for k point: 0.045659542083740234
elapsed time for k point: 0.07368135452270508
elapsed time for k point: 0.04258275032043457
elapsed time for k point: 0.04249119758605957
elapsed time for k point: 0.04757571220397949
elapsed time for k point: 0.061188459396362305
elapsed time for k point: 0.03998517990112305
elapsed time for k point: 0.039756059646606445
elapsed time for k point: 0.03606891632080078
Outputting fields to e.k11.b01.z.tm.h5...
Outputting fields to e.k11.b02.z.tm.h5...
Outputting fields to e.k11.b03.z.tm.h5...
Outputting fields to e.k11.b04.z.tm.h5...
Outputting fields to e.k11.b05.z.tm.h5...
Outputting fields to e.k11.b06.z.tm.h5...
Outputting fields to e.k11.b07.z.tm.h5...
Outputting fields to e.k11.b08.z.tm.h5...
elapsed time for k point: 0.05903124809265137
elapsed time for k point: 0.04381871223449707
elapsed time for k point: 0.04783916473388672
elapsed time for k point: 0.05981016159057617
elapsed time for k point: 0.07385110855102539
Band 1 range: 0.0 at Vector3<0.0, 0.0, 0.0> to 0.27469022601674825 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0>
Band 2 range: 0.44533108106909675 at Vector3<0.0, 0.5, 0.0> to 0.5605181463869627 at Vector3<0.0, 0.0, 0.0>
Band 3 range: 0.4902389149689675 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0> to 0.5605607990535272 at Vector3<0.0, 0.0, 0.0>
Band 4 range: 0.5932960878698785 at Vector3<0.0, 0.0, 0.0> to 0.7907195975678284 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0>
Band 5 range: 0.790832076496515 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0> to 0.8374511179880573 at Vector3<0.0, 0.0, 0.0>
Band 6 range: 0.8375948535575019 at Vector3<0.0, 0.0, 0.0> to 0.8672009266363848 at Vector3<-0.2, 0.39999999999999997, 0.0>
Band 7 range: 0.8691349976044128 at Vector3<-0.13333333333333333, 0.43333333333333335, 0.0> to 0.9941291198691656 at Vector3<0.0, 0.0, 0.0>
Band 8 range: 0.8992499096210413 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0> to 1.0983183609808018 at Vector3<0.0, 0.0, 0.0>
Gap from band 1 (0.27469022601674825) to band 2 (0.44533108106909675), 47.39883483253746%
Gap from band 3 (0.5605607990535272) to band 4 (0.5932960878698785), 5.6740639480231065%
Gap from band 4 (0.7907195975678284) to band 5 (0.790832076496515), 0.014223870206851423%
Gap from band 5 (0.8374511179880573) to band 6 (0.8375948535575019), 0.01716198503041161%
Gap from band 6 (0.8672009266363848) to band 7 (0.8691349976044128), 0.22277612770969557%
total elapsed time for run: 0.9146349430084229
done
Initializing eigensolver data
Computing 8 bands with 1e-07 tolerance
16 k-points
  Vector3<0.0, 0.0, 0.0>
  Vector3<0.0, 0.1, 0.0>
  Vector3<0.0, 0.2, 0.0>
  Vector3<0.0, 0.30000000000000004, 0.0>
  Vector3<0.0, 0.4, 0.0>
  Vector3<0.0, 0.5, 0.0>
  Vector3<-0.06666666666666667, 0.4666666666666667, 0.0>
  Vector3<-0.13333333333333333, 0.43333333333333335, 0.0>
  Vector3<-0.2, 0.39999999999999997, 0.0>
  Vector3<-0.26666666666666666, 0.36666666666666664, 0.0>
  Vector3<-0.3333333333333333, 0.3333333333333333, 0.0>
  Vector3<-0.26666666666666666, 0.26666666666666666, 0.0>
  Vector3<-0.19999999999999998, 0.19999999999999998, 0.0>
  Vector3<-0.1333333333333333, 0.1333333333333333, 0.0>
  Vector3<-0.06666666666666665, 0.06666666666666665, 0.0>
  Vector3<0.0, 0.0, 0.0>
elapsed time for initialization: 0.006161689758300781
Outputting epsilon.h5...
elapsed time for k point: 0.15283560752868652
elapsed time for k point: 0.10227298736572266
elapsed time for k point: 0.07835555076599121
elapsed time for k point: 0.06203007698059082
elapsed time for k point: 0.06897616386413574
elapsed time for k point: 0.05510568618774414
elapsed time for k point: 0.06617093086242676
elapsed time for k point: 0.07337594032287598
elapsed time for k point: 0.08975911140441895
elapsed time for k point: 0.07498002052307129
elapsed time for k point: 0.0859231948852539
elapsed time for k point: 0.08907198905944824
elapsed time for k point: 0.06461143493652344
elapsed time for k point: 0.08724069595336914
elapsed time for k point: 0.10591506958007812
elapsed time for k point: 0.10394883155822754
Band 1 range: 0.0 at Vector3<0.0, 0.0, 0.0> to 0.4912358164155421 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0>
Band 2 range: 0.47307223980397584 at Vector3<0.0, 0.5, 0.0> to 0.5631059454934054 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0>
Band 3 range: 0.5631505237340395 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0> to 0.7939289543994177 at Vector3<0.0, 0.0, 0.0>
Band 4 range: 0.7676614802373236 at Vector3<0.0, 0.5, 0.0> to 0.8214230165371805 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0>
Band 5 range: 0.8651948161670014 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0> to 1.0334130378837394 at Vector3<0.0, 0.0, 0.0>
Band 6 range: 0.86523080078068 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0> to 1.0334231173608948 at Vector3<0.0, 0.0, 0.0>
Band 7 range: 1.0213677201035718 at Vector3<0.0, 0.5, 0.0> to 1.1159672190021006 at Vector3<0.0, 0.0, 0.0>
Band 8 range: 1.1086627112265826 at Vector3<-0.26666666666666666, 0.26666666666666666, 0.0> to 1.1168108652006026 at Vector3<0.0, 0.0, 0.0>
Gap from band 2 (0.5631059454934054) to band 3 (0.5631505237340395), 0.007916179281023615%
Gap from band 4 (0.8214230165371805) to band 5 (0.8651948161670014), 5.190482251648066%
total elapsed time for run: 1.38558030128479
done

In [5]:
efields = []
def get_efields(ms, band):
    efields.append(ms.get_efield(band, bloch_phase=True))

ms.run_tm(mpb.output_at_kpoint(mp.Vector3(1 / -3, 1 / 3), mpb.fix_efield_phase,
          get_efields))

# Create an MPBData instance to transform the efields
md = mpb.MPBData(rectify=True, resolution=32, periods=3)

converted = []
for f in efields:
    # Get just the z component of the efields
    f = f[..., 2]
    converted.append(md.convert(f))

for i, f in enumerate(converted):
    plt.subplot(331 + i)
    plt.contour(converted_eps.T, cmap='binary')
    plt.imshow(np.real(f).T, interpolation='spline36', cmap='RdBu', alpha=0.9)
    plt.axis('off')

plt.show()


Initializing eigensolver data
Computing 8 bands with 1e-07 tolerance
16 k-points
  Vector3<0.0, 0.0, 0.0>
  Vector3<0.0, 0.1, 0.0>
  Vector3<0.0, 0.2, 0.0>
  Vector3<0.0, 0.30000000000000004, 0.0>
  Vector3<0.0, 0.4, 0.0>
  Vector3<0.0, 0.5, 0.0>
  Vector3<-0.06666666666666667, 0.4666666666666667, 0.0>
  Vector3<-0.13333333333333333, 0.43333333333333335, 0.0>
  Vector3<-0.2, 0.39999999999999997, 0.0>
  Vector3<-0.26666666666666666, 0.36666666666666664, 0.0>
  Vector3<-0.3333333333333333, 0.3333333333333333, 0.0>
  Vector3<-0.26666666666666666, 0.26666666666666666, 0.0>
  Vector3<-0.19999999999999998, 0.19999999999999998, 0.0>
  Vector3<-0.1333333333333333, 0.1333333333333333, 0.0>
  Vector3<-0.06666666666666665, 0.06666666666666665, 0.0>
  Vector3<0.0, 0.0, 0.0>
elapsed time for initialization: 0.00611114501953125
Outputting epsilon.h5...
elapsed time for k point: 0.10001444816589355
elapsed time for k point: 0.05996417999267578
elapsed time for k point: 0.05382895469665527
elapsed time for k point: 0.0482792854309082
elapsed time for k point: 0.06704854965209961
elapsed time for k point: 0.04594159126281738
elapsed time for k point: 0.053566694259643555
elapsed time for k point: 0.04610753059387207
elapsed time for k point: 0.03913235664367676
elapsed time for k point: 0.039084672927856445
elapsed time for k point: 0.05995631217956543
elapsed time for k point: 0.04987764358520508
elapsed time for k point: 0.045241355895996094
elapsed time for k point: 0.053000450134277344
elapsed time for k point: 0.07826566696166992
elapsed time for k point: 0.060247182846069336
Band 1 range: 0.0 at Vector3<0.0, 0.0, 0.0> to 0.2746902260167482 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0>
Band 2 range: 0.4453310810691098 at Vector3<0.0, 0.5, 0.0> to 0.5605181430819429 at Vector3<0.0, 0.0, 0.0>
Band 3 range: 0.4902389149689676 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0> to 0.5605607964855761 at Vector3<0.0, 0.0, 0.0>
Band 4 range: 0.5932960880346015 at Vector3<0.0, 0.0, 0.0> to 0.7907195975678288 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0>
Band 5 range: 0.790832076496516 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0> to 0.8374511174251633 at Vector3<0.0, 0.0, 0.0>
Band 6 range: 0.837594853406181 at Vector3<0.0, 0.0, 0.0> to 0.8672009266363928 at Vector3<-0.2, 0.39999999999999997, 0.0>
Band 7 range: 0.8691349976047852 at Vector3<-0.13333333333333333, 0.43333333333333335, 0.0> to 0.9941291061767797 at Vector3<0.0, 0.0, 0.0>
Band 8 range: 0.8992499096210417 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0> to 1.0983183646074062 at Vector3<0.0, 0.0, 0.0>
Gap from band 1 (0.2746902260167482) to band 2 (0.4453310810691098), 47.398834832540246%
Gap from band 3 (0.5605607964855761) to band 4 (0.5932960880346015), 5.674064433500026%
Gap from band 4 (0.7907195975678288) to band 5 (0.790832076496516), 0.014223870206921608%
Gap from band 5 (0.8374511174251633) to band 6 (0.837594853406181), 0.0171620341794383%
Gap from band 6 (0.8672009266363928) to band 7 (0.8691349976047852), 0.22277612775161734%
total elapsed time for run: 0.9477133750915527
done
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-5-f455f10d920d> in <module>()
     17 for i, f in enumerate(converted):
     18     plt.subplot(331 + i)
---> 19     plt.contour(converted_eps.T, cmap='binary')
     20     plt.imshow(np.real(f).T, interpolation='spline36', cmap='RdBu', alpha=0.9)
     21     plt.axis('off')

NameError: name 'converted_eps' is not defined

In [6]:
plt.imshow(converted_eps.T, interpolation='spline36', cmap='binary')
plt.axis('off')


Out[6]:
(-0.5, 191.5, 165.5, -0.5)

In [9]:
ef = ms.get_efield(1, bloch_phase=True)

In [11]:
ef.shape


Out[11]:
(32, 32, 1, 3)

In [12]:
efields = []
def get_efields(ms, band):
    efields.append(ms.get_efield(band, bloch_phase=True))

ms.run_tm(mpb.output_at_kpoint(mp.Vector3(1 / -3, 1 / 3), mpb.fix_efield_phase,
          get_efields))

# Create an MPBData instance to transform the efields
md = mpb.MPBData(rectify=True, resolution=32, periods=3)


Initializing eigensolver data
Computing 8 bands with 1e-07 tolerance
16 k-points
  Vector3<0.0, 0.0, 0.0>
  Vector3<0.0, 0.1, 0.0>
  Vector3<0.0, 0.2, 0.0>
  Vector3<0.0, 0.30000000000000004, 0.0>
  Vector3<0.0, 0.4, 0.0>
  Vector3<0.0, 0.5, 0.0>
  Vector3<-0.06666666666666667, 0.4666666666666667, 0.0>
  Vector3<-0.13333333333333333, 0.43333333333333335, 0.0>
  Vector3<-0.2, 0.39999999999999997, 0.0>
  Vector3<-0.26666666666666666, 0.36666666666666664, 0.0>
  Vector3<-0.3333333333333333, 0.3333333333333333, 0.0>
  Vector3<-0.26666666666666666, 0.26666666666666666, 0.0>
  Vector3<-0.19999999999999998, 0.19999999999999998, 0.0>
  Vector3<-0.1333333333333333, 0.1333333333333333, 0.0>
  Vector3<-0.06666666666666665, 0.06666666666666665, 0.0>
  Vector3<0.0, 0.0, 0.0>
elapsed time for initialization: 0.007373332977294922
Outputting epsilon.h5...
elapsed time for k point: 0.11075496673583984
elapsed time for k point: 0.05318808555603027
elapsed time for k point: 0.04919695854187012
elapsed time for k point: 0.04758119583129883
elapsed time for k point: 0.04171943664550781
elapsed time for k point: 0.04094552993774414
elapsed time for k point: 0.060126304626464844
elapsed time for k point: 0.0441133975982666
elapsed time for k point: 0.03760099411010742
elapsed time for k point: 0.03973507881164551
elapsed time for k point: 0.03795933723449707
elapsed time for k point: 0.04369163513183594
elapsed time for k point: 0.04398965835571289
elapsed time for k point: 0.04800224304199219
elapsed time for k point: 0.0571904182434082
elapsed time for k point: 0.05233883857727051
Band 1 range: 0.0 at Vector3<0.0, 0.0, 0.0> to 0.2746902260167482 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0>
Band 2 range: 0.4453310810690971 at Vector3<0.0, 0.5, 0.0> to 0.5605181430819429 at Vector3<0.0, 0.0, 0.0>
Band 3 range: 0.49023891496896754 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0> to 0.5605607964855761 at Vector3<0.0, 0.0, 0.0>
Band 4 range: 0.5932960880346015 at Vector3<0.0, 0.0, 0.0> to 0.7907195975678294 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0>
Band 5 range: 0.7908320764965168 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0> to 0.8374511174251633 at Vector3<0.0, 0.0, 0.0>
Band 6 range: 0.8375948534061814 at Vector3<0.0, 0.0, 0.0> to 0.8672009266363931 at Vector3<-0.2, 0.39999999999999997, 0.0>
Band 7 range: 0.8691349976047841 at Vector3<-0.13333333333333333, 0.43333333333333335, 0.0> to 0.9941291061767797 at Vector3<0.0, 0.0, 0.0>
Band 8 range: 0.8992499096210417 at Vector3<-0.3333333333333333, 0.3333333333333333, 0.0> to 1.0983183646074062 at Vector3<0.0, 0.0, 0.0>
Gap from band 1 (0.2746902260167482) to band 2 (0.4453310810690971), 47.39883483253755%
Gap from band 3 (0.5605607964855761) to band 4 (0.5932960880346015), 5.674064433500026%
Gap from band 4 (0.7907195975678294) to band 5 (0.7908320764965168), 0.014223870206949676%
Gap from band 5 (0.8374511174251633) to band 6 (0.8375948534061814), 0.017162034179491317%
Gap from band 6 (0.8672009266363931) to band 7 (0.8691349976047841), 0.2227761277514512%
total elapsed time for run: 0.8401346206665039
done

In [20]:
efields[0].shape


Out[20]:
(32, 32, 1, 3)

In [27]:
print(converted[0].shape)


(96, 83, 96)