mirror of
https://github.com/edoverg/modeconverter.git
synced 2026-10-14 23:06:39 +00:00
fixing plots
This commit is contained in:
+13
-13
@@ -328,9 +328,9 @@
|
|||||||
" False, \n",
|
" False, \n",
|
||||||
" ax=ax1,\n",
|
" ax=ax1,\n",
|
||||||
" output_plane=output_plane,\n",
|
" output_plane=output_plane,\n",
|
||||||
" show_sources = True,\n",
|
" show_sources = False,\n",
|
||||||
" show_monitors = True,\n",
|
" show_monitors = False,\n",
|
||||||
" show_boundary_layers = True,\n",
|
" show_boundary_layers = False,\n",
|
||||||
" )\n",
|
" )\n",
|
||||||
" circ1 = Circle((2,2), minimum_length/2)\n",
|
" circ1 = Circle((2,2), minimum_length/2)\n",
|
||||||
" ax1.add_patch(circ1)\n",
|
" ax1.add_patch(circ1)\n",
|
||||||
@@ -339,9 +339,9 @@
|
|||||||
" False, \n",
|
" False, \n",
|
||||||
" ax=ax2,\n",
|
" ax=ax2,\n",
|
||||||
" output_plane=output_plane_xy,\n",
|
" output_plane=output_plane_xy,\n",
|
||||||
" show_sources = True,\n",
|
" show_sources = False,\n",
|
||||||
" show_monitors = True,\n",
|
" show_monitors = False,\n",
|
||||||
" show_boundary_layers = True,\n",
|
" show_boundary_layers = False,\n",
|
||||||
" )\n",
|
" )\n",
|
||||||
" circ2 = Circle((2,2), minimum_length/2)\n",
|
" circ2 = Circle((2,2), minimum_length/2)\n",
|
||||||
" ax2.add_patch(circ2)\n",
|
" ax2.add_patch(circ2)\n",
|
||||||
@@ -414,9 +414,9 @@
|
|||||||
" False, \n",
|
" False, \n",
|
||||||
" ax=ax1,\n",
|
" ax=ax1,\n",
|
||||||
" output_plane=output_plane,\n",
|
" output_plane=output_plane,\n",
|
||||||
" show_sources = True,\n",
|
" show_sources = False,\n",
|
||||||
" show_monitors = True,\n",
|
" show_monitors = False,\n",
|
||||||
" show_boundary_layers = True,\n",
|
" show_boundary_layers = False,\n",
|
||||||
")\n",
|
")\n",
|
||||||
"\n",
|
"\n",
|
||||||
"circ1 = Circle((2,2), minimum_length/2)\n",
|
"circ1 = Circle((2,2), minimum_length/2)\n",
|
||||||
@@ -427,15 +427,15 @@
|
|||||||
" False, \n",
|
" False, \n",
|
||||||
" ax=ax2,\n",
|
" ax=ax2,\n",
|
||||||
" output_plane=output_plane_xy,\n",
|
" output_plane=output_plane_xy,\n",
|
||||||
" show_sources = True,\n",
|
" show_sources = False,\n",
|
||||||
" show_monitors = True,\n",
|
" show_monitors = False,\n",
|
||||||
" show_boundary_layers = True,\n",
|
" show_boundary_layers = False,\n",
|
||||||
")\n",
|
")\n",
|
||||||
"circ2 = Circle((2,2), minimum_length/2)\n",
|
"circ2 = Circle((2,2), minimum_length/2)\n",
|
||||||
"ax2.add_patch(circ2)\n",
|
"ax2.add_patch(circ2)\n",
|
||||||
"ax2.axis(\"off\")\n",
|
"ax2.axis(\"off\")\n",
|
||||||
" \n",
|
" \n",
|
||||||
"plt.savefig(\"results/final_design.pdf\")\n"
|
"plt.savefig(\"results/final_design_xy.pdf\")\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
+28
-27
@@ -1,6 +1,7 @@
|
|||||||
|
# %% [markdown]
|
||||||
# This is a first attempt at creating an inverse designed fiber mode converter in meep. At first, we try to implement and combine tutorials from both tidy3d and meep.
|
# This is a first attempt at creating an inverse designed fiber mode converter in meep. At first, we try to implement and combine tutorials from both tidy3d and meep.
|
||||||
|
|
||||||
|
# %%
|
||||||
import meep as mp
|
import meep as mp
|
||||||
import meep.adjoint as mpa
|
import meep.adjoint as mpa
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@@ -12,7 +13,7 @@ from matplotlib.patches import Circle
|
|||||||
import scipy as sp
|
import scipy as sp
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
# %%
|
||||||
######PHYSICS SETUP######
|
######PHYSICS SETUP######
|
||||||
|
|
||||||
mp.verbosity(1)
|
mp.verbosity(1)
|
||||||
@@ -38,7 +39,7 @@ buffer = 2.5
|
|||||||
pml_size = 1.0
|
pml_size = 1.0
|
||||||
pml_layers = [mp.PML(pml_size)]
|
pml_layers = [mp.PML(pml_size)]
|
||||||
|
|
||||||
|
# %%
|
||||||
######FILTER######
|
######FILTER######
|
||||||
minimum_length = 0.09 # minimum length scale (microns)
|
minimum_length = 0.09 # minimum length scale (microns)
|
||||||
eta_i = (
|
eta_i = (
|
||||||
@@ -48,7 +49,7 @@ eta_e = 0.55 # erosion design field thresholding point (between 0 and 1)
|
|||||||
eta_d = 1 - eta_e # dilation design field thresholding point (between 0 and 1)
|
eta_d = 1 - eta_e # dilation design field thresholding point (between 0 and 1)
|
||||||
filter_radius = mpa.get_conic_radius_from_eta_e(minimum_length, eta_e)
|
filter_radius = mpa.get_conic_radius_from_eta_e(minimum_length, eta_e)
|
||||||
|
|
||||||
|
# %%
|
||||||
######DESIGN REGION######
|
######DESIGN REGION######
|
||||||
design_region_width = 4.0
|
design_region_width = 4.0
|
||||||
design_region_length = 4.0
|
design_region_length = 4.0
|
||||||
@@ -104,7 +105,7 @@ geometry = [
|
|||||||
design_region_block,
|
design_region_block,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# %%
|
||||||
######SOURCE######
|
######SOURCE######
|
||||||
fcen = 1 / wavelength
|
fcen = 1 / wavelength
|
||||||
width = 0.2
|
width = 0.2
|
||||||
@@ -116,7 +117,7 @@ source = [mp.Source(src, component=mp.Ex, size=source_size, center=source_center
|
|||||||
#src = mp.ContinuousSource(frequency=fcen, fwidth=fwidth, is_integrated=True)
|
#src = mp.ContinuousSource(frequency=fcen, fwidth=fwidth, is_integrated=True)
|
||||||
#source = [mp.Source(src, component=mp.Ex, size=source_size, center=source_center)]
|
#source = [mp.Source(src, component=mp.Ex, size=source_size, center=source_center)]
|
||||||
|
|
||||||
|
# %%
|
||||||
######SIMULATION######
|
######SIMULATION######
|
||||||
kpoint = mp.Vector3()
|
kpoint = mp.Vector3()
|
||||||
sim = mp.Simulation(
|
sim = mp.Simulation(
|
||||||
@@ -128,7 +129,7 @@ sim = mp.Simulation(
|
|||||||
resolution = resolution,
|
resolution = resolution,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# %%
|
||||||
######MONITOR######
|
######MONITOR######
|
||||||
far_field_obs_point_z_coord = 15
|
far_field_obs_point_z_coord = 15
|
||||||
far_z = [mp.Vector3(0,0,far_field_obs_point_z_coord)] #this is the far-field-focal-point
|
far_z = [mp.Vector3(0,0,far_field_obs_point_z_coord)] #this is the far-field-focal-point
|
||||||
@@ -153,7 +154,7 @@ def J1(FF):
|
|||||||
return obj_to_return
|
return obj_to_return
|
||||||
#returns the first point of all frequencies of the Ey component
|
#returns the first point of all frequencies of the Ey component
|
||||||
|
|
||||||
|
# %%
|
||||||
######CHECK PLOT######
|
######CHECK PLOT######
|
||||||
output_plane = mp.Volume(
|
output_plane = mp.Volume(
|
||||||
center=mp.Vector3(0,0,0),
|
center=mp.Vector3(0,0,0),
|
||||||
@@ -169,7 +170,7 @@ fig = sim.plot2D(show_sources=True,show_monitors=True,show_epsilon=True, output_
|
|||||||
#sim.plot2D(fields=mp.Ex,output_plane=output_plane)
|
#sim.plot2D(fields=mp.Ex,output_plane=output_plane)
|
||||||
#plt.savefig("fields.pdf")
|
#plt.savefig("fields.pdf")
|
||||||
|
|
||||||
|
# %%
|
||||||
######OPTIMIZATION PROBLEM######
|
######OPTIMIZATION PROBLEM######
|
||||||
'''
|
'''
|
||||||
An OptimizationProblem class object knows how to do one basic thing:
|
An OptimizationProblem class object knows how to do one basic thing:
|
||||||
@@ -189,10 +190,9 @@ opt = mpa.OptimizationProblem(
|
|||||||
|
|
||||||
######CHECK PLOT######
|
######CHECK PLOT######
|
||||||
figure = opt.plot2D(True, output_plane=output_plane)
|
figure = opt.plot2D(True, output_plane=output_plane)
|
||||||
plt.savefig("results/simulation_setup.pdf")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# %%
|
||||||
def mapping(x,eta,beta):
|
def mapping(x,eta,beta):
|
||||||
'''
|
'''
|
||||||
Arguments:
|
Arguments:
|
||||||
@@ -253,9 +253,9 @@ def f(v, gradient, cur_beta):
|
|||||||
False,
|
False,
|
||||||
ax=ax1,
|
ax=ax1,
|
||||||
output_plane=output_plane,
|
output_plane=output_plane,
|
||||||
show_sources = True,
|
show_sources = False,
|
||||||
show_monitors = True,
|
show_monitors = False,
|
||||||
show_boundary_layers = True,
|
show_boundary_layers = False,
|
||||||
)
|
)
|
||||||
circ1 = Circle((2,2), minimum_length/2)
|
circ1 = Circle((2,2), minimum_length/2)
|
||||||
ax1.add_patch(circ1)
|
ax1.add_patch(circ1)
|
||||||
@@ -264,13 +264,16 @@ def f(v, gradient, cur_beta):
|
|||||||
False,
|
False,
|
||||||
ax=ax2,
|
ax=ax2,
|
||||||
output_plane=output_plane_xy,
|
output_plane=output_plane_xy,
|
||||||
show_sources = True,
|
show_sources = False,
|
||||||
show_monitors = True,
|
show_monitors = False,
|
||||||
show_boundary_layers = True,
|
show_boundary_layers = False,
|
||||||
)
|
)
|
||||||
circ2 = Circle((2,2), minimum_length/2)
|
circ2 = Circle((2,2), minimum_length/2)
|
||||||
ax2.add_patch(circ2)
|
ax2.add_patch(circ2)
|
||||||
|
|
||||||
|
if not os.path.exists("results"):
|
||||||
|
os.makedirs("results")
|
||||||
|
|
||||||
plt.savefig("results/iter_{}.pdf".format(cur_iter[0]+1))
|
plt.savefig("results/iter_{}.pdf".format(cur_iter[0]+1))
|
||||||
|
|
||||||
cur_iter[0] += cur_iter[0] + 1
|
cur_iter[0] += cur_iter[0] + 1
|
||||||
@@ -309,6 +312,7 @@ if optimization_start:
|
|||||||
cur_beta = cur_beta * beta_scale #update beta
|
cur_beta = cur_beta * beta_scale #update beta
|
||||||
print("current beta: ", cur_beta)
|
print("current beta: ", cur_beta)
|
||||||
|
|
||||||
|
# %%
|
||||||
######RESULTS######
|
######RESULTS######
|
||||||
#plot the figure of merit over iterations
|
#plot the figure of merit over iterations
|
||||||
plt.figure()
|
plt.figure()
|
||||||
@@ -328,9 +332,9 @@ opt.plot2D(
|
|||||||
False,
|
False,
|
||||||
ax=ax1,
|
ax=ax1,
|
||||||
output_plane=output_plane,
|
output_plane=output_plane,
|
||||||
show_sources = True,
|
show_sources = False,
|
||||||
show_monitors = True,
|
show_monitors = False,
|
||||||
show_boundary_layers = True,
|
show_boundary_layers = False,
|
||||||
)
|
)
|
||||||
|
|
||||||
circ1 = Circle((2,2), minimum_length/2)
|
circ1 = Circle((2,2), minimum_length/2)
|
||||||
@@ -341,15 +345,12 @@ opt.plot2D(
|
|||||||
False,
|
False,
|
||||||
ax=ax2,
|
ax=ax2,
|
||||||
output_plane=output_plane_xy,
|
output_plane=output_plane_xy,
|
||||||
show_sources = True,
|
show_sources = False,
|
||||||
show_monitors = True,
|
show_monitors = False,
|
||||||
show_boundary_layers = True,
|
show_boundary_layers = False,
|
||||||
)
|
)
|
||||||
circ2 = Circle((2,2), minimum_length/2)
|
circ2 = Circle((2,2), minimum_length/2)
|
||||||
ax2.add_patch(circ2)
|
ax2.add_patch(circ2)
|
||||||
ax2.axis("off")
|
ax2.axis("off")
|
||||||
|
|
||||||
plt.savefig("results/final_design.pdf")
|
plt.savefig("results/final_design_xy.pdf")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user