安装miniconda
打开终端
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
bash miniconda.sh
创建mp环境
conda create -n mp -c conda-forge pymeep pymeep-extras
案例代码
可以使用其他工具,编辑好代码,例如用pycharm编辑保存test_mp.py
import meep as mp
from meep import mpb
import numpy as np
from matplotlib import pyplot as plt
# Then the wavelength
omega = 1 / 0.78
material_SiN = mp.Medium(index=2.02)
width_guide = 0.65
height_guide = 0.25
resolution=200
size_cal_y=2
size_cal_z=2
geometry = [mp.Block(material=material_SiN,
size=mp.Vector3(mp.inf,width_guide, height_guide),
center=mp.Vector3(0, 0, height_guide/2))]
geometry_lattice = mp.Lattice(size=mp.Vector3(0, size_cal_y, size_cal_z))
num_modes = 4
ms = mpb.ModeSolver(
geometry_lattice = geometry_lattice,
geometry = geometry,
resolution = resolution,
num_bands = num_modes
)
E = []
store_fields = lambda ms_temp, mode: E.append(ms_temp.get_efield(which_band=mode,bloch_phase=False))
k = ms.find_k(
mp.NO_PARITY,
omega, # omega
1, # band_min
num_modes, # band_max
mp.Vector3(1,0,0), # korig_and_kdir
1e-4, # tol
omega * 2, # kmag_guess
omega * 0.1, # kmag_min
omega * 2, # kmag_max
store_fields, # band_funcs
)
neff=k[0]/omega #
eps = ms.get_epsilon() #
eps_arr=np.transpose(np.array(eps))
# %%
x_list=np.linspace(-size_cal_y/2,size_cal_y/2,resolution*2)
y_list=np.linspace(-size_cal_z/2,size_cal_z/2,resolution*2)
x_grid,y_grid=np.meshgrid(x_list,y_list)
plt.figure(figsize=(12,4))
# Plot the E fields
for mode in range(num_modes):
Ex=np.squeeze(E[mode][:,:,0,1]).transpose()
print('Current band: {}'.format(mode+1))
plt.subplot(1,num_modes,1+mode)
plt.pcolormesh(x_grid,y_grid,eps.transpose(), cmap='binary')
plt.pcolormesh(x_grid,y_grid,np.abs(Ex), cmap='jet', alpha=0.9)
plt.axis('off')
st_title='Ex of mode '+str(mode+1)+' from MPB neff=' +str('%.2f' %(k[mode]/omega))
plt.title(st_title)
plt.tight_layout()
plt.savefig('.//SimulatedFieldMPB.png')
plt.show()
激活mp环境与运行
在test_mp.py所在的文件夹打开终端
conda activate mp
python test_mp.py

版本
Ubuntu:
lsb_release -a
LSB Version: core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal
参考:
《Approaching (Almost) Any Machine Learning Problem》
https://github.com/abhishekkrthakur/approachingalmost
https://zhuanlan.zhihu.com/p/162148062
https://zhuanlan.zhihu.com/p/388551748

4638

被折叠的 条评论
为什么被折叠?



