API
Nmrc.IncidentNmrc.IncidentNmrc.PMLNmrc.allocate_matricesNmrc.allocate_stiff_matrixNmrc.apply_all_bds!Nmrc.assemble_ANmrc.assemble_A0Nmrc.assemble_A1Nmrc.assemble_A2Nmrc.assemble_loadNmrc.assemble_pml_A0Nmrc.assemble_pml_A1Nmrc.assemble_pml_A2Nmrc.assemble_tbcNmrc.beta_nNmrc.beta_nNmrc.compute_coef!Nmrc.compute_rayleigh_nNmrc.compute_scalingNmrc.coord_transformNmrc.csqrt_negimagNmrc.dofs_on_dtnNmrc.get_widthNmrc.integral_nuv̄Nmrc.integral_uvNmrc.integral_uv̄Nmrc.integral_∂₁uvNmrc.integral_∂₁uv̄Nmrc.periodic_cellNmrc.setup_bcsNmrc.setup_bdcsNmrc.setup_dofsNmrc.setup_fevsNmrc.setup_gridNmrc.setup_valsNmrc.sub_preserve_structure
Nmrc.Incident — Type
IncidentSome parameters related to the incident field.
Parameters
k: the wave numberθ: the incident fieldα: α = k * sin(θ)β: β = k * cos(θ)
Nmrc.Incident — Method
Incident(k::Float64, θ::Float64)Define the incident field with the wavenumber k and the incident field θ.
Nmrc.allocate_matrices — Method
allocate_matrices(dof::DofHandler, cst::ConstraintHandler)Allocate the complex-valued stiffness matrices.
Nmrc.allocate_stiff_matrix — Method
allocate_stiff_matrix(dofhandler::DofHandler, csthandler::ConstraintHandler, dofs)Create a sparse pattern for the stiffness matrix. We need to add extra entries due to the DtN map by hand.
Nmrc.apply_all_bds! — Method
apply_all_bds!(K::Union{SparseMatrixCSC, Symmetric}, ch::ConstraintHandler)
apply_all_bds!(KK::Union{SparseMatrixCSC, Symmetric}, f::AbstractVector, ch::ConstraintHandler, applyzero::Bool = false)Impose the periodic boundary condition and the Dirichlet boundary condition on the matrices.
Nmrc.assemble_A — Method
assemble_A(cv::CellValues, dh::DofHandler, A::SparseMatrixCSC, inc::Incident)Nmrc.assemble_A0 — Method
assemble_A0(cv::CellValues, dh::DofHandler, A₀::SparseMatrixCSC, medium::Function, k)Assemble the zero order term $\mathbf{A}_{0}$ in the Nonlinear eigenvalue problem.
$A_{0}(u, v) = \int \nabla u \cdot \nabla \bar{v} - k^{2}n(x_{1}, x_{2}) u \bar{v} d x.$
Argument
cv: CellValuesdh: DofHandlerA₀: an empty sparse pattern preallocated for A₀medium: refractive index function which describes the properties of the mediumk: the wavenumber
See also assemble_A1, assemble_A2.
Nmrc.assemble_A1 — Method
assemble_A1(cv::CellValues, dh::DofHandler, A₁::SparseMatrixCSC)Assemble the first order term $\mathbf{A}_{1}$ in the Nonlinear eigenvalue problem.
$A_{1}(u, v) = -\int 2i \partial_{1} u \bar{v} d x.$
See also assemble_A0, assemble_A2.
Nmrc.assemble_A2 — Method
assemble_A2(cv::CellValues, dh::DofHandler, A₂::SparseMatrixCSC)Assemble the second order term in the Nonlinear eigenvalue problem.
$A_{2}(u, v) = \int u \bar{v} d x.$
See also assemble_A0, assemble_A1.
Nmrc.assemble_load — Method
assemble_load(fv::FacetValues, dh::DofHandler, facetset, f, inc::Incident, height)Assemble the load vector due to the incident field.
Nmrc.assemble_pml_A0 — Method
assemble_pml_A0(cv::CellValues, dh::DofHandler, A₀::SparseMatrixCSC, medium::Function, p::PML, k)Assemble the zero order term in the quadratic eigenvalue problem constructed by PML-FEM.
\[A_{0}(u, v) = \int s(x_{2}) \frac{\partial u}{\partial x_{1}} \frac{\partial \bar{v}}{\partial x_{1}} + \frac{1}{s(x_{2})} \frac{\partial u}{\partial x_{2}} \frac{\partial \bar{v}}{\partial x_{2}} - k^{2} n(x_{1}, x_{2}) s(x_{2}) u \bar{v} dx.\]
Arguments
cv: CellValuesdh: DofHandlerA₀: Sparse matix preallocated for A₀medium: the refractive indexp: the information about PML, seePMLk: the wavenumber
See also assemble_pml_A1, assemble_pml_A2.
Nmrc.assemble_pml_A1 — Method
assemble_pml_A1(cv::CellValues, dh::DofHandler, A₁::SparseMatrixCSC, p::PML)Assemble the first order term in the quadratic eigenvalue problem constructed by PML-FEM.
\[A_{1}(u, v) = -\int 2i s(x_{2}) \frac{\partial u}{\partial x_{1}} \bar{v} dx.\]
Arguments
cv: CellValuesdh: DofHandlerA₁: Sparse matix preallocated for A₁p: the information about PML, seePML
See also assemble_pml_A0, assemble_pml_A2.
Nmrc.assemble_pml_A2 — Method
assemble_pml_A2(cv::CellValues, dh::DofHandler, A₂::SparseMatrixCSC, p::PML)Assemble the second order term in the quadratic eigenvalue problem from the PML-FEM method.
\[A_{2}(u, v) = \int s(x_{2}) u \bar{v} dx.\]
Arguments
cv: CellValuesdh: DofHandlerA₂: Sparse matix preallocated for A₂p: the information about PML, seePML
See also assemble_pml_A0, assemble_pml_A1.
Nmrc.assemble_tbc — Method
assemble_tbc(fv::FacetValues, dh::DofHandler, inc::Incident, facetset, F, N, dofsDtN; period = 2π)Assemble the TBC matrix.
Nmrc.beta_n — Method
beta_n(k, α, n)Compute $\beta_{n}$ for complex $\alpha$. We need this function when we construct nonlinear eigenvalue problems. Please note that we take the negative imaginary axis as the branch cut for square root. So we use csqrt_negimag instead of the default square root in Julia. See also csqrt_negimag.
Nmrc.beta_n — Method
beta_n(inc::Incident, n; period = 2π)Compute the $βₙ$.
Nmrc.compute_coef! — Method
compute_coef!(Θ::SparseVector, fv::FacetValues, dh::DofHandler, facetset, n; period = 2π)Compute $\Theta^{n}$ on the facetset. Actually the computation of the TBC matrix reduces to the computation of the vector $\Theta^{n}$.
Nmrc.compute_rayleigh_n — Method
compute_rayleigh_n(fv::FacetValues, dh::DofHandler, facetset, u, n)Compute the $n$-th order Rayleigh coefficient for the solution $u$. Be careful that we need to compute the Rayleigh coefficients for scattered solutions.
\[u_{n} = \int_{\text{boundary}} u e^{-inx_{1}} ds.\]
Nmrc.compute_scaling — Method
compute_scaling(A₀::M, A₁::M, A₂::M; scaling=:nothing::Symbol) where {T,M<:AbstractMatrix{T}}TBW
Nmrc.coord_transform — Method
coord_transform(x₂, p::PML)Coordinate transformation of PML method.
Nmrc.csqrt_negimag — Method
csqrt_negimag(z::Complex{T}) where T<:AbstractFloatSquare root for complex numbers which takes the negative imaginary axis as the branch cut. Note that sqrt for complex number in julia takes the negative real axis as the default branch cut.
Nmrc.dofs_on_dtn — Method
dofs_on_dtn(dh::DofHandler, field::Symbol, facetset)Extract the global indices of Dofs associated to the artificial boundary.
Nmrc.get_width — Method
get_width(p::PML)Get the width of the PML layer.
Nmrc.integral_nuv̄ — Method
integral_nuv̄(cv::CellValues, dh::DofHandler, n::Function, u, v)Compute the integral
\[\int n(x_{1}, x_{2}) u v dx, \]
where $n(x_{1}, x_{2})$ is a function defined in our computational domain (normally, the refraction index). See also integral_uv̄ and integral_∂₁uv̄.
Nmrc.integral_uv — Method
integral_uv(cv::CellValues, dh::DofHandler, u, v)Compute the integral
\[\int u v dx, \]
where $u$ and $v$ are vectors indexed by degrees of freedom. Normally, they are results obtained by FEM.
Nmrc.integral_uv̄ — Method
integral_uv̄(cv::CellValues, dh::DofHandler, u, v)Compute the integral
\[\int u \bar{v} dx, \]
where $\bar{v}$ is the conjugate of the function $v$. See also integral_nuv̄ and integral_∂₁uv̄.
Nmrc.integral_∂₁uv — Method
integral_∂₁uv(cv::CellValues, dh::DofHandler, u, v)Compute the integral
\[\int \frac{\partial u}{\partial x_{1}} v dx,\]
where $u$ and $v$ are vectors indexed by degrees of freedom. Normally, they are results obtained by FEM.
Nmrc.integral_∂₁uv̄ — Method
integral_∂₁uv̄(cv::CellValues, dh::DofHandler, u, v)Compute the integral
\[\int \frac{\partial u}{\partial x_{1}} \bar{v} dx, \]
where $\bar{v}$ is the conjugate of the function $v$. See also integral_uv̄ and integral_nuv̄.
Nmrc.periodic_cell — Method
periodic_cell(;lc=0.5, period=2π, height=2.0)Generate a mesh for the periodic cell.
Arguments
lc: the mesh size near pointsperiod: the period of the periodic cellheight: the height of the periodic cell
Points
4 ------------ 3
| |
| |
1 ------------ 2Lines
. ---- l3 ---- .
l4 l2
. ---- l1 ---- .Nmrc.setup_bcs — Method
setup_bcs(dh::DofHandler; period=2π)Set the periodic boundary condition ("left" and "right") and Dirichelt boundary condition ("bottom").
Arguments
dh: DofHandlerperiod: the period of the periodic cell, seeperiodic_cell
Nmrc.setup_bdcs — Method
setup_bdcs(dof::DofHandler, d)Set the periodic boundary condition ("left" and "right") and Dirichelt boundary condition ("bottom" and "top").
Nmrc.setup_dofs — Method
setup_dofs(grid::Grid, ip)Setup degree of freedoms.
Nmrc.setup_fevs — Method
setup_fevs(ip)Define quadrature rules on Reference triangle and setup FE values.
Nmrc.setup_grid — Method
setup_grid(;d=2π, ĥ=1.5, δ=2.0, lc=0.5, lp=0.5, vtk=false)Generate a mesh by julia interface for Gmsh and read the .msh file by FerriteGmsh.
Arguments
d: the period of the periodic layerĥ: the start of the PML layerδ: the height of the PML layerlc: mesh size near the periodic layerlp: mesh size in the PML layervtk: write.vtkfile, default isfalse
Points
5 ------------- 4
| |
6 3
| |
1 ------------- 2Lines
. ----- l4 ----- .
l5 l3
. .
l6 l2
. ----- l1 ----- .Misc
- We can generate a
*.vtkfile by replace thedo endblock withgmsh.write(*.vtk)
Nmrc.setup_vals — Method
setup_vals(ip)Set up CellValues and FacetValues by using interpolation ip. Here we need to define FacetValues because the load vector and the TBC matrix contains integral on the boundary.
Nmrc.sub_preserve_structure — Method
sub_preserve_structure(A::SparseMatrixCSC, B::SparseMatrixCSC)Subtract two sparse matrix without changing the sparse pattern. A and B should have the same sparse pattern.