Skip to content

Commit

Permalink
add mode source (#13)
Browse files Browse the repository at this point in the history
* add mode source

* update toml
  • Loading branch information
smartalecH authored Jun 12, 2024
1 parent cc568c0 commit b9ccfd8
Show file tree
Hide file tree
Showing 25 changed files with 838 additions and 203 deletions.
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ version = "0.1.0"
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Einsum = "b7d42ee7-0b51-5a75-98ca-779d3107e4c0"
GeometryPrimitives = "17051e67-205e-509e-8301-03b320b998e6"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Metal = "dde4c033-4e86-420c-a63e-0dd931031962"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
VectorModesolver = "8c544392-5fd9-4640-bea4-e12b3d59d9d1"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"

[compat]
Makie = "0.19"
CairoMakie = "0.12"
julia = "1.8"

[extras]
Expand Down
2 changes: 1 addition & 1 deletion examples/dipole.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
# (c) Meta Platforms, Inc. and affiliates.
#
# Simulate a dipole in vacuum.

Expand Down
2 changes: 1 addition & 1 deletion examples/periodic_slab.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
# (c) Meta Platforms, Inc. and affiliates.
#
# Using DFT monitors, compute the transmission of a planewave in 3D through a
# simple slab structure. Compare the computed response to the analytic response.
Expand Down
2 changes: 1 addition & 1 deletion examples/sphere.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
# (c) Meta Platforms, Inc. and affiliates.
#
# Simulate the scattering of a planewave off of a conductive sphere.

Expand Down
72 changes: 72 additions & 0 deletions examples/waveguide.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# (c) Meta Platforms, Inc. and affiliates.
#
# Excitation of a dielectric waveguide using a mode source.

import Khronos
using CairoMakie
using GeometryPrimitives

Khronos.choose_backend(Khronos.CUDADevice(), Float64)

function build_waveguide_simulation::Number)

geometry = [
Khronos.Object(
Cuboid([0.0, 0.0, 0.0], [100.0, 0.5, 0.22]),
Khronos.Material= 3.4^2),
), # Waveguide - Si
Khronos.Object(
Cuboid([0.0, 0.0, 0.0], [100.0, 100.0, 100.0]),
Khronos.Material= 1.44^2),
), # Background material -- SiO2
]

sources = [
Khronos.ModeSource(
time_profile = Khronos.ContinuousWaveSource(fcen = 1.0 / λ),
frequency = 1.0 / λ,
mode_solver_resolution = 50,
mode_index = 1,
center = [0.0, 0.0, 0.0],
size = [0.0, 2.0, 2.0],
solver_tolerance = 1e-6,
geometry = geometry,
),
]

# Build the simulation object, such that it spans a cube 10μm×10μm×10μm. Place PML 1μm thick.
sim = Khronos.Simulation(
cell_size = [4.0, 4.0, 6.0],
cell_center = [0.0, 0.0, 0.0],
resolution = 25,
geometry = geometry,
sources = sources,
boundaries = [[1.0, 1.0], [1.0, 1.0], [1.0, 1.0]],
)
return sim
end

λ = 1.55
sim = build_waveguide_simulation(λ)

# scene = Khronos.plot2D(
# sim,
# nothing,
# Khronos.Volume([0.0, 0.0, 0.0], [6.0, 2.0, 2.0]);
# plot_geometry=true,
# )


# scene = Khronos.plot_source(sim, sim.sources[1])
# save("waveguide_source.png", scene)

t_end = 40.0;
Khronos.run(sim, until = t_end)

scene = Khronos.plot2D(
sim,
Khronos.Ey(),
Khronos.Volume([0.0, 0.0, 0.0], [6.0, 4.0, 4.0]);
plot_geometry = true,
)
save("waveguide.png", scene)
2 changes: 1 addition & 1 deletion src/Boundaries.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
# (c) Meta Platforms, Inc. and affiliates.

abstract type Boundary end

Expand Down
2 changes: 1 addition & 1 deletion src/DataStructures.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
# (c) Meta Platforms, Inc. and affiliates.

"""
Expand Down
2 changes: 1 addition & 1 deletion src/Fields.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
# (c) Meta Platforms, Inc. and affiliates.

# -------------------------------------------------------------------------- #
# General field array utility functions
Expand Down
67 changes: 67 additions & 0 deletions src/Geometry.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# (c) Meta Platforms, Inc. and affiliates.
#
# Contains all relevant functions for manipulating geometry.
#
# NOTE [smartalecH] Don't use Inf to specify bounds in gometric shapes, as it's
# not compatible with `findfirst`.

"""
Base.findfirst()
Expand Down Expand Up @@ -285,3 +291,64 @@ get_mat_conductivity_from_field(sim::SimulationData, ::Electric, ::Y) =
sim.geometry_data.σDy
get_mat_conductivity_from_field(sim::SimulationData, ::Electric, ::Z) =
sim.geometry_data.σDz

# ---------------------------------------------------------- #
# Material functions
# ---------------------------------------------------------- #

function get_ε_at_frequency(material, frequency)
ε = zeros(ComplexF64, 3, 3)

# Account for all the DC terms first
ε .+= isnothing(material.ε) ? 0 : material.ε * I(3)
ε[1, 1] += isnothing(material.εx) ? 0 : material.εx
ε[2, 2] += isnothing(material.εy) ? 0 : material.εy
ε[3, 3] += isnothing(material.εz) ? 0 : material.εz
ε[1, 2] += isnothing(material.εxy) ? 0 : material.εxy
ε[2, 1] += isnothing(material.εxy) ? 0 : material.εxy
ε[1, 3] += isnothing(material.εxz) ? 0 : material.εxz
ε[3, 1] += isnothing(material.εxz) ? 0 : material.εxz
ε[2, 3] += isnothing(material.εyz) ? 0 : material.εyz
ε[3, 2] += isnothing(material.εyz) ? 0 : material.εyz

# Now handle all the conductivities
ω = 2 * π * frequency
if !isnothing(material.σD)
ε = (1 .+ im * material.σD / ω .* I(3)) .* ε
end
if !isnothing(material.σDx)
ε[1, 1] = (1 + im * material.σDx / ω) * ε[1, 1]
end
if !isnothing(material.σDy)
ε[2, 2] = (1 + im * material.σDy / ω) * ε[2, 2]
end
if !isnothing(material.σDx)
ε[3, 3] = (1 + im * material.σDz / ω) * ε[3, 3]
end

return ε
end

function fit_complex_material::Number, frequency::Number)
return Material{Float64}= real(ε), σD = 2 * π * frequency * imag(ε) / real(ε))
end

"""
transform_material(material::AbstractArray)::AbstractArray
Transforms a material tensor `material` by a specified `transformation_matrix`.
More generally, the susceptibilities χ are transformed to MχMᵀ/|det M|, which
corresponds to [transformation
optics](http://math.mit.edu/~stevenj/18.369/coordinate-transform.pdf) for an
arbitrary curvilinear coordinate transformation with Jacobian matrix M. The
absolute value of the determinant is to prevent inadvertent construction of
left-handed materials
"""
function transform_material(
material::AbstractArray,
transformation_matrix::AbstractArray,
)::AbstractArray
return transformation_matrix * material * transformation_matrix' /
det(transformation_matrix)
end
7 changes: 5 additions & 2 deletions src/Khronos.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
# (c) Meta Platforms, Inc. and affiliates.

module Khronos

using Einsum
using GeometryPrimitives
using Parameters
using KernelAbstractions
using Revise
using Logging
using LinearAlgebra
using OffsetArrays
import VectorModesolver

macro status(exs)
@logmsg(0, exs)
Expand All @@ -23,10 +25,11 @@ include("load_deps.jl")

include("DataStructures.jl")
include("utils.jl")
include("Geometry.jl")
include("Mode.jl")
include("Boundaries.jl")
include("Sources/Sources.jl")
include("Fields.jl")
include("Geometry.jl")
include("DFT.jl")
include("Monitors.jl")
include("Timestep.jl")
Expand Down
Loading

0 comments on commit b9ccfd8

Please sign in to comment.