Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
uriele committed Aug 31, 2023
0 parents commit 66e0a8e
Show file tree
Hide file tree
Showing 20 changed files with 976 additions and 0 deletions.
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# See https://domluna.github.io/JuliaFormatter.jl/stable/ for a list of options
35 changes: 35 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI
on:
push:
branches:
- master
tags: ['*']
pull_request:
concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1.9'
- 'nightly'
os:
- ubuntu-latest
arch:
- x64
steps:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
16 changes: 16 additions & 0 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CompatHelper
on:
schedule:
- cron: 0 0 * * *
workflow_dispatch:
jobs:
CompatHelper:
runs-on: ubuntu-latest
steps:
- name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}
run: julia -e 'using CompatHelper; CompatHelper.main()'
31 changes: 31 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: TagBot
on:
issue_comment:
types:
- created
workflow_dispatch:
inputs:
lookback:
default: 3
permissions:
actions: read
checks: read
contents: write
deployments: read
issues: read
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
ssh: ${{ secrets.DOCUMENTER_KEY }}
16 changes: 16 additions & 0 deletions .github/workflows/register.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Register Package
on:
workflow_dispatch:
inputs:
version:
description: Version to register or component to bump
required: true
jobs:
register:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: julia-actions/RegisterAction@latest
with:
token: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Manifest.toml
/docs/Manifest.toml
/docs/build/
38 changes: 38 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Documentation: http://docs.travis-ci.com/user/languages/julia
language: julia
notifications:
email: false
julia:
- 1.9
- nightly
os:
- linux
arch:
- x64
cache:
directories:
- ~/.julia/artifacts
jobs:
fast_finish: true
allow_failures:
- julia: nightly
include:
- stage: Documentation
julia: 1
script:
- |
julia --project=docs -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()'
- |
julia --project=docs -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()
using Documenter: DocMeta, doctest
using ImaginaryOptics
DocMeta.setdocmeta!(ImaginaryOptics, :DocTestSetup, :(using ImaginaryOptics); recursive=true)
doctest(ImaginaryOptics)
include("docs/make.jl")'
after_success: skip
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Marco Menarini <menarini.marco@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
16 changes: 16 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name = "ImaginaryOptics"
uuid = "ed0a9f63-0a1c-4465-a5fd-c9e4b6c1d448"
authors = ["Marco Menarini <menarini.marco@gmail.com>"]
version = "1.0.0-DEV"

[deps]
Arpack = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97"

[compat]
julia = "1.9"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ImaginaryOptics

[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://marcom.github.io/ImaginaryOptics.jl/stable/)
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://marcom.github.io/ImaginaryOptics.jl/dev/)
[![Build Status](https://github.com/marcom/ImaginaryOptics.jl/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/marcom/ImaginaryOptics.jl/actions/workflows/CI.yml?query=branch%3Amaster)
[![Build Status](https://travis-ci.com/marcom/ImaginaryOptics.jl.svg?branch=master)](https://travis-ci.com/marcom/ImaginaryOptics.jl)
[![PkgEval](https://JuliaCI.github.io/NanosoldierReports/pkgeval_badges/I/ImaginaryOptics.svg)](https://JuliaCI.github.io/NanosoldierReports/pkgeval_badges/I/ImaginaryOptics.html)
3 changes: 3 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
ImaginaryOptics = "ed0a9f63-0a1c-4465-a5fd-c9e4b6c1d448"
25 changes: 25 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using ImaginaryOptics
using Documenter

DocMeta.setdocmeta!(ImaginaryOptics, :DocTestSetup, :(using ImaginaryOptics); recursive=true)

makedocs(;
modules=[ImaginaryOptics],
authors="Marco Menarini <menarini.marco@gmail.com>",
repo="https://github.com/marcom/ImaginaryOptics.jl/blob/{commit}{path}#{line}",
sitename="ImaginaryOptics.jl",
format=Documenter.HTML(;
prettyurls=get(ENV, "CI", "false") == "true",
canonical="https://marcom.github.io/ImaginaryOptics.jl",
edit_link="master",
assets=String[],
),
pages=[
"Home" => "index.md",
],
)

deploydocs(;
repo="github.com/marcom/ImaginaryOptics.jl",
devbranch="master",
)
14 changes: 14 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
```@meta
CurrentModule = ImaginaryOptics
```

# ImaginaryOptics

Documentation for [ImaginaryOptics](https://github.com/marcom/ImaginaryOptics.jl).

```@index
```

```@autodocs
Modules = [ImaginaryOptics]
```
41 changes: 41 additions & 0 deletions src/ImaginaryOptics.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
ImaginaryOptics.jl
The code uses the negative sign convention for the propagation direction. Thus the gain and losses are defined using
Thus a value of ϵ″>0 indicates gain and a value of ϵ″<0 indicates losses. The code uses the following convention for the sign of the imaginary part of the dielectric function:
```math
ϵ=ϵ′+im*ϵ″
```
"""
module ImaginaryOptics
import Unitful: μ0,ϵ0,c0,μm,ns,μs,s,cm,V,rad
import Unitful.Length as UnitLength
import Unitful.Time as UnitTime
import Unitful: ustrip,unit, @u_str,𝐋,dimension
using SparseArrays
import Arpack: eigs # for eigenvalues
@enum SOURCE_TYPE TFSF SOFT_SOURCE
@enum MODE_TYPE TE TM
@enum PML_TYPE PML_CLASSIC PML_RUMPF
@enum BOUNDARY_CONDITIONS begin
DIRICHLET
NEUMANN
ROBIN
PERIODIC
TRANSPARENT
end

@enum SOLVER_TYPE BEAM_PROPAGATION_METHODS DOMAIN_DECOMPOSITION_METHODS FDFD_METHODS
abstract type AbstractField{T<:AbstractFloat} end
abstract type AbstractSource{T<:AbstractFloat} end
abstract type AbstractSolver{T<:AbstractFloat} end
abstract type AbstractMaterial{T<:AbstractFloat} end
include("utility.jl")
include("common_solver_functions.jl")


export μm,μ0,ϵ0,c0
export propagation_phase
# Write your package code here.

end
52 changes: 52 additions & 0 deletions src/beam_propagation_method.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@



"""
BPM_solver{T}(Nx::Int,Ny::Int,dx_norm::T,dy_norm::T,ERzz::Matrix{Complex{T}};nonlinear::Bool=true,Npmly=10,kwargs...) where T<:AbstractFloat
BPM_solver{T}(NS::NTuple{2,Int},RES::NTuple{2,T},ERzz;kwargs...) where T<:AbstractFloat
BPM_solver{T}(NS::NTuple{2,Int},dx_norm::T,ERzz;kwargs...) where T<:AbstractFloat
BPM_solver{T}(Nx::Int,Ny::Int,dx_norm::T,ERzz;kwargs...) where T<:AbstractFloat
BPM_solver is a subtype of AbstractDomain that contains the information to solve the numerical problem. As the name says it is used to solve the problem using the beam
propagation method (BPM). The current version uses the nonlinear Crank Nicolson method to the direct problem and autodifferentiation to solve the inverse problem. The current
version only supports the paraxial approximation, future version will support Pade approximants to solve large angles.
# INPUTS
- `Nx::Int`: number of points in the x direction
- `Ny::Int`: number of points in the y direction
- `dx_norm::T`: grid spacing in the x direction in normalized units (i.e. dx_norm=dx*k₀)
- `dy_norm::T`: grid spacing in the y direction in normalized units (i.e. dy_norm=dy*k₀)
- `ERzz ::Matrix{Complex{T}}`: matrix containing the real part of the dielectric function. It is a misnomer, since in the case of active devices it
can be complex and equal to ϵ_core-k_min^2.
- `nonlinear::Bool=false`: if true, the nonlinear term is included in the BPM equation (BPM has been made to solve the nonlinear optimization in 1D and 2D, by default it is true)
- `wpmly=10::Int=10`: number of PML points in the direction perpendicular to the propagation direction (y direction)
See also: [DomainFDFD](@ref), [DomainDecomposition](@ref), [DomainDecompositionLowMemory](@ref),
"""
struct BPM_solver{T} <: AbstractDomain{T}
nonlinear :: Bool
N :: Tuple{Int,Int}
laplacian :: SparseMatrixCSC{Complex{T}}
epsilon :: Matrix{T}

function BPM_solver(Nx::Int,Ny::Int,dx_norm::T,dy_norm::T,epsilon::Vector{T};
nonlinear::Bool=true,wpmly=10,kwargs...) where T<:AbstractFloat


@info("Nx: $Nx, Ny: $Ny, dx_norm: $dx_norm, dy_norm: $dy_norm, Npmly: $Npmly")
_,∇=Laplacian(1,Ny,dx_norm,dy_norm;wpmlx=0,wpmly=wpmly,check=2,kwargs...)
@debug("Nx: $Nx, Ny: $Ny, dx_norm: $dx_norm, dy_norm: $dy_norm, Npmly: $Npmly")
_,∇=Laplacian(1,Ny,dx_norm,dy_norm;wpmlx=0,wpmly=wpmly,check=2,kwargs...)
# Assume μ=1 that is the case for most materials
laplacian=∇[4]*∇[2]

@debug("lapacialian created")
N=(Nx,Ny)
epsilon=reshape(epsilon,Nx,Ny)
new{T}(nonlinear,(Nx,Ny),laplacian,epsilon)
end
end

BPM_solver(NS::NTuple{2,Int},RES::NTuple{2,T},epsilon_real::Union{VecOrMat{T},VecOrMat{Complex{T}}};kwargs...) where T<:AbstractFloat =BPM_solver(NS...,RES...,epsilon_real;kwargs...)
BPM_solver(NS::NTuple{2,Int},dx_norm::T,epsilon_real::Union{VecOrMat{T},VecOrMat{Complex{T}}};kwargs...) where T<:AbstractFloat =BPM_solver(NS...,dx_norm,dx_norm,epsilon_real;kwargs...)
BPM_solver(Nx::Int,Ny::Int,dx_norm::T,epsilon_real::Union{VecOrMat{T},VecOrMat{Complex{T}}};kwargs...) where T<:AbstractFloat =BPM_solver(Nx,Ny,dx_norm,dx_norm,epsilon_real;kwargs...)

Loading

0 comments on commit 66e0a8e

Please sign in to comment.