-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4187a05
commit 507a43f
Showing
3 changed files
with
172 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# --- | ||
# jupyter: | ||
# jupytext: | ||
# custom_cell_magics: kql | ||
# formats: jl:percent,ipynb | ||
# text_representation: | ||
# extension: .jl | ||
# format_name: percent | ||
# format_version: '1.3' | ||
# jupytext_version: 1.11.2 | ||
# kernelspec: | ||
# display_name: base | ||
# language: julia | ||
# name: julia-1.9 | ||
# --- | ||
|
||
# %% [markdown] | ||
# # Mode solving | ||
|
||
# %% [markdown] | ||
# ```{caution} | ||
# **This example is under construction** | ||
# As Julia-Dicts are not ordered, the mesh might become incorrect when adjusted (for now, better do the meshing in python) | ||
# ``` | ||
|
||
# %% tags=["hide-output", "thebe-init"] | ||
using PyCall | ||
np = pyimport("numpy") | ||
shapely = pyimport("shapely") | ||
shapely.affinity = pyimport("shapely.affinity") | ||
clip_by_rect = pyimport("shapely.ops").clip_by_rect | ||
OrderedDict = pyimport("collections").OrderedDict | ||
mesh_from_OrderedDict = pyimport("femwell.mesh").mesh_from_OrderedDict | ||
|
||
radius = 100000 | ||
wg_width = 0.5 | ||
wg_thickness = 0.22 | ||
sim_width = 3 | ||
sim_height = 4 | ||
core = shapely.geometry.box(radius - wg_width / 2, 0, radius + wg_width / 2, wg_thickness) | ||
|
||
env = shapely.geometry.box( | ||
radius - sim_width / 2, | ||
-sim_height / 2, | ||
radius + sim_width / 2, | ||
sim_height / 2, | ||
) | ||
|
||
polygons = OrderedDict( | ||
core = core, | ||
box = clip_by_rect(env, -np.inf, -np.inf, np.inf, 0), | ||
clad = clip_by_rect(env, -np.inf, 0, np.inf, np.inf), | ||
) | ||
|
||
resolutions = Dict( | ||
"core" => Dict("resolution" => 0.03, "distance" => 0.5), | ||
"slab" => Dict("resolution" => 0.03, "distance" => 0.5), | ||
) | ||
|
||
mesh = mesh_from_OrderedDict( | ||
polygons, | ||
resolutions, | ||
default_resolution_max = 1, | ||
filename = "mesh.msh", | ||
) | ||
|
||
# %% tags=["remove-stderr", "hide-output", "thebe-init"] | ||
using Gridap | ||
using Gridap.Geometry | ||
using Gridap.Visualization | ||
using Gridap.ReferenceFEs | ||
using GridapGmsh | ||
using GridapMakie, CairoMakie | ||
|
||
using Femwell.Maxwell.Waveguide | ||
|
||
CairoMakie.inline!(true) | ||
|
||
# %% tags=["remove-stderr"] | ||
model = GmshDiscreteModel("mesh.msh") | ||
Ω = Triangulation(model) | ||
#fig = plot(Ω) | ||
#fig.axis.aspect=DataAspect() | ||
#wireframe!(Ω, color=:black, linewidth=1) | ||
#display(fig) | ||
|
||
labels = get_face_labeling(model) | ||
|
||
epsilons = ["core" => 3.5^2, "box" => 1.444^2, "clad" => 1.44^2] | ||
ε(tag) = Dict(get_tag_from_name(labels, u) => v for (u, v) in epsilons)[tag] | ||
|
||
|
||
#dΩ = Measure(Ω, 1) | ||
τ = CellField(get_face_tag(labels, num_cell_dims(model)), Ω) | ||
|
||
modes = calculate_modes(model, ε ∘ τ, λ = 1.55, num = 2, order = 1, radius = radius) | ||
println(n_eff(modes[2])) | ||
# write_mode_to_vtk("mode", modes[2]) | ||
|
||
plot_mode(modes[2], absolute = true) | ||
#plot_mode(modes[2]) | ||
modes | ||
|
||
# %% [markdown] | ||
# For comparison, we the effective refractive index of a straight waveguide: | ||
|
||
# %% tags=["remove-stderr"] | ||
|
||
modes_p = calculate_modes(model, ε ∘ τ, λ = 1.55, num = 2, order = 1) | ||
println(n_eff(modes_p[2])) | ||
plot_mode(modes_p[2], absolute = true) | ||
|
||
# %% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters