Skip to content

Commit

Permalink
Merge branch 'revise/embeddingAPI'
Browse files Browse the repository at this point in the history
  • Loading branch information
HoBeZwe committed Feb 5, 2024
2 parents 330075e + ab56913 commit 40eccb7
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 120 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SphericalScattering"
uuid = "1a9ea918-b599-4f1f-bd9a-d681e8bb5b3e"
authors = ["Bernd Hofmann <Bernd.Hofmann@tum.de> and contributors"]
version = "0.6.0"
version = "0.7.0"

[deps]
LegendrePolynomials = "3db4a2ba-fc88-11e8-3e01-49c72059a882"
Expand Down
19 changes: 10 additions & 9 deletions docs/src/scatterer.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Sphere Dimensions

!!! note
In all of the following setups the sphere is embedded in a homogeneous background medium with permeability ``\mu`` and permittivity ``\varepsilon`` defined by [`Medium(ε, μ)`](@ref). The values [`μ0`](@ref) and [`ε0`](@ref) are provided containing the free space values.
In all of the following setups the sphere is embedded in a homogeneous background medium with permeability ``\mu`` and permittivity ``\varepsilon``.
This medium is defined only by the chosen excitation as a [`Medium(ε, μ)`](@ref).


---
Expand All @@ -26,7 +27,7 @@ PECSphere
---
## Dielectric Sphere

The dielectric sphere has radius ``r`` and is assumed to be located in the origin. It is defined by [`DielectricSphere`](@ref). In addition to the embedding [`Medium(ε, μ)`](@ref) a filling [`Medium(εᵢ, μᵢ)`](@ref) with permeability ``\mu_\mathrm{i}`` and permittivity ``\varepsilon_\mathrm{i}`` has to be defined.
The dielectric sphere has radius ``r`` and is assumed to be located in the origin. It is defined by [`DielectricSphere`](@ref), where the filling [`Medium(εᵢ, μᵢ)`](@ref) with permeability ``\mu_\mathrm{i}`` and permittivity ``\varepsilon_\mathrm{i}`` has to be defined.
```@raw html
<div align="center">
<img src="../assets/DielectricSphere.svg" width="300"/>
Expand All @@ -39,13 +40,13 @@ The dielectric sphere has radius ``r`` and is assumed to be located in the origi
```@docs
DielectricSphere
```
Here `radius` is a Float and `filling` of type [`Medium(εᵢ, μᵢ)`](@ref).
Here `radius` is a Float and `filling` is of type [`Medium(εᵢ, μᵢ)`](@ref).


---
## Layered Dielectric Sphere

The layered dielectric sphere has radii ``[r_1, r_2, \dots, r_N]`` and is assumed to be located in the origin. It is defined by [`LayeredSphere`](@ref). In addition to the embedding [`Medium(ε, μ)`](@ref) a vector of fillings [[`Medium(ε₁, μ₁)`](@ref), [`Medium(ε₂, μ₂)`](@ref), ..., [`Medium(εN, μN)`](@ref)] with permeability ``\mu_n`` and permittivity ``\varepsilon_n`` has to be defined.
The layered dielectric sphere has radii ``[r_1, r_2, \dots, r_N]`` and is assumed to be located in the origin. It is defined by [`LayeredSphere`](@ref), where the vector of fillings [[`Medium(ε₁, μ₁)`](@ref), [`Medium(ε₂, μ₂)`](@ref), ..., [`Medium(εN, μN)`](@ref)] with permeability ``\mu_n`` and permittivity ``\varepsilon_n`` has to be defined.
```@raw html
<div align="center">
<img src="../assets/LayeredSphere.svg" width="300"/>
Expand All @@ -58,13 +59,13 @@ The layered dielectric sphere has radii ``[r_1, r_2, \dots, r_N]`` and is assume
```@docs
LayeredSphere
```
with, e.g., `radii = SVector(0.25, 0.5, 1.0)` and `radii = SVector(Medium(ε1, μ1), Medium(ε2, μ2), Medium(ε3, μ3))`.
with, e.g., `radii = SVector(0.25, 0.5, 1.0)` and `filling = SVector(Medium(ε1, μ1), Medium(ε2, μ2), Medium(ε3, μ3))`.


---
## Layered Dielectric Sphere with PEC Core

The layered dielectric sphere has radii ``[r_1, r_2, \dots, r_{N+1}]`` and is assumed to be located in the origin. It is defined by [`LayeredSpherePEC`](@ref). In addition to the embedding [`Medium(ε, μ)`](@ref) a vector of fillings [[`Medium(ε₁, μ₁)`](@ref), [`Medium(ε₂, μ₂)`](@ref), ..., [`Medium(εN, μN)`](@ref)] with permeability ``\mu_n`` and permittivity ``\varepsilon_n`` has to be defined.
The layered dielectric sphere has radii ``[r_1, r_2, \dots, r_{N+1}]`` and is assumed to be located in the origin. It is defined by [`LayeredSpherePEC`](@ref), where the vector of fillings [[`Medium(ε₁, μ₁)`](@ref), [`Medium(ε₂, μ₂)`](@ref), ..., [`Medium(εN, μN)`](@ref)] with permeability ``\mu_n`` and permittivity ``\varepsilon_n`` has to be defined.
```@raw html
<div align="center">
<img src="../assets/LayeredSpherePEC.svg" width="300"/>
Expand All @@ -76,13 +77,13 @@ The layered dielectric sphere has radii ``[r_1, r_2, \dots, r_{N+1}]`` and is as
```@docs
LayeredSpherePEC
```
with, e.g., `radii = SVector(0.25, 0.5, 1.0)` and `radii = SVector(Medium(ε1, μ1), Medium(ε2, μ2))`.
with, e.g., `radii = SVector(0.25, 0.5, 1.0)` and `filling = SVector(Medium(ε1, μ1), Medium(ε2, μ2))`.


---
## [Dielectric Sphere with Thin Impedance Layer](@id dielecimped)

The dielectric sphere with a thin impedance layer of thickness ``t`` has radius ``r`` and is assumed to be located in the origin. It is defined by [`DielectricSphereThinImpedanceLayer`](@ref). Unlike the LayeredSphere model, the solution is obtained by using an approximation: it is assumed that the impedance is so high that the displacement field is purely radial (see [[6, pp. 230ff]](@ref refs)). This leads to a potential drop across the thin layer, while the displacement field is constant in radial direction. In addition to the embedding [`Medium(ε, μ)`](@ref) and filling [`Medium(εᵢ, μᵢ)`](@ref), the impedance layer must be specified, both the [`Medium(εₜ, μₜ)`](@ref) and its `thickness`.
The dielectric sphere with a thin impedance layer of thickness ``t`` has radius ``r`` and is assumed to be located in the origin. It is defined by [`DielectricSphereThinImpedanceLayer`](@ref). Unlike the LayeredSphere model, the solution is obtained by using an approximation: it is assumed that the impedance is so high that the displacement field is purely radial (see [[6, pp. 230ff]](@ref refs)). This leads to a potential drop across the thin layer, while the displacement field is constant in radial direction. In addition to the filling [`Medium(εᵢ, μᵢ)`](@ref), the impedance layer must be specified, both the [`Medium(εₜ, μₜ)`](@ref) and its `thickness`.
```@raw html
<div align="center">
<img src="../assets/ImpedanceLayer.svg" width="300"/>
Expand All @@ -98,4 +99,4 @@ The dielectric sphere with a thin impedance layer of thickness ``t`` has radius
```@docs
DielectricSphereThinImpedanceLayer
```
Here `radius` and `thickness` are a Floats, `embedding`, `filling` and `thinlayer` are of type [`Medium`](@ref).
Here `radius` and `thickness` are a Floats, `filling` and `thinlayer` are of type [`Medium`](@ref).
14 changes: 6 additions & 8 deletions src/UniformField/scattered.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ Compute the electric field scattered by a sphere, for an incident uniform field.
"""
function scatteredfield(sphere::Sphere, excitation::UniformField, quantity::Field; parameter::Parameter=Parameter())

sphere.embedding == excitation.embedding || error("Excitation and sphere are not in the same medium.") # verify excitation and sphere are in the same medium

F = zeros(fieldType(quantity), size(quantity.locations))

# --- compute field in Cartesian representation
Expand All @@ -31,7 +29,7 @@ function scatteredfield(
sphere::DielectricSphere, excitation::UniformField, point, quantity::ElectricField; parameter::Parameter=Parameter()
)

ε0 = sphere.embedding.ε
ε0 = excitation.embedding.ε
ε1 = sphere.filling.ε
E0 = field(excitation, point, quantity)

Expand Down Expand Up @@ -60,7 +58,7 @@ function scatteredfield(
sphere::DielectricSphere, excitation::UniformField, point, quantity::ScalarPotential; parameter::Parameter=Parameter()
)

ε0 = sphere.embedding.ε
ε0 = excitation.embedding.ε
ε1 = sphere.filling.ε
Φ0 = field(excitation, point, quantity)

Expand Down Expand Up @@ -137,7 +135,7 @@ function scatteredfield(
E = scatteredfield(sphere, excitation, point, ElectricField(quantity.locations); parameter=parameter)

if norm(point) > sphere.radius
D = sphere.embedding.ε * E
D = excitation.embedding.ε * E
else
D = sphere.filling.ε * E
end
Expand Down Expand Up @@ -217,7 +215,7 @@ function scatterCoeff(sp::DielectricSphereThinImpedanceLayer, ex::UniformField)
R = sp.radius
Δ = sp.thickness
εₘ = sp.thinlayer.ε
εₑ = sp.embedding.ε
εₑ = ex.embedding.ε
εᵢ = sp.filling.ε
E₀ = ex.amplitude

Expand Down Expand Up @@ -346,7 +344,7 @@ function scatterCoeff(sphere::LayeredSphere{LN,LR,LC}, excitation::UniformField{

a = reverse(sphere.radii)
n = length(a)
perms = reverse(getfield.(vcat(sphere.filling, sphere.embedding), 1))
perms = reverse(getfield.(vcat(sphere.filling, excitation.embedding), 1))

T = promote_type(LR, LC, FC, FT, FR)

Expand Down Expand Up @@ -458,7 +456,7 @@ function scatterCoeff(sphere::LayeredSpherePEC{LN,LD,LR,LC}, excitation::Uniform

a = reverse(sphere.radii)
n = length(a) - 1
perms = reverse(getfield.(vcat(sphere.filling, sphere.embedding), 1))
perms = reverse(getfield.(vcat(sphere.filling, excitation.embedding), 1))

T = promote_type(LR, LC, FC, FT, FR)

Expand Down
1 change: 0 additions & 1 deletion src/dipoles/scattered.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function scatteredfield(sphere::PECSphere, excitation::Dipole, quantity::Field;

T = typeof(excitation.frequency)

sphere.embedding == excitation.embedding || error("Excitation and sphere are not in the same medium.") # verify excitation and sphere are in the same medium
excitation.orientation × excitation.position == SVector{3,T}(0, 0, 0) || error("The dipole is not perpendicular to the sphere.")

F = zeros(SVector{3,Complex{T}}, size(quantity.locations))
Expand Down
17 changes: 0 additions & 17 deletions src/planeWave/excitation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,3 @@ planeWave(;
polarization = SVector{3,typeof(frequency)}(1.0, 0.0, 0.0),
) = PlaneWave(embedding, frequency, amplitude, direction, polarization)


"""
ex = planeWave(
sp::Sphere;
frequency = error("missing argument `frequency`"),
amplitude = 1.0,
direction = SVector{3,typeof(frequency)}(0.0, 0.0, 1.0),
polarization = SVector{3,typeof(frequency)}(1.0, 0.0, 0.0),
)
"""
planeWave(
sp::Sphere;
frequency = error("missing argument `frequency`"),
amplitude = 1.0,
direction = SVector{3,typeof(frequency)}(0.0, 0.0, 1.0),
polarization = SVector{3,typeof(frequency)}(1.0, 0.0, 0.0),
) = PlaneWave(sp.embedding, frequency, amplitude, direction, polarization)
10 changes: 4 additions & 6 deletions src/planeWave/scattered.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ Compute the electric field scattered by a PEC sphere, for an incident plane wave
"""
function scatteredfield(sphere::Sphere, excitation::PlaneWave, quantity::Field; parameter::Parameter=Parameter())

sphere.embedding == excitation.embedding || error("Excitation and sphere are not in the same medium.") # verify excitation and sphere are in the same medium

T = typeof(excitation.frequency)
F = zeros(SVector{3,Complex{T}}, size(quantity.locations))

Expand Down Expand Up @@ -148,7 +146,7 @@ Returns ``H₀/ηᵢ``, where ``H₀`` is the magnetic field of the incident pla
For PEC layers, it returns ``0``.
"""
function amplitude(sphere, excitation::PlaneWave, quantity::MagneticField, r)
η = impedance(sphere, r)
η = impedance(sphere, excitation, r)

if η == 0.0 # PEC case
return η * excitation.amplitude # return zero of correct type
Expand All @@ -166,7 +164,7 @@ Returns ``E₀``, where ``E₀`` is the electric field of the incident plane wav
For PEC layers, it returns ``0``.
"""
function amplitude(sphere, excitation::PlaneWave, quantity::ElectricField, r)
η = impedance(sphere, r)
η = impedance(sphere, excitation, r)

if η == 0.0 # PEC case
return η * excitation.amplitude # return zero of correct type
Expand Down Expand Up @@ -248,8 +246,8 @@ function scatterCoeff(sphere::DielectricSphere, excitation::PlaneWave, n::Int)
f = excitation.frequency
T = typeof(f)

ε2 = sphere.embedding.ε
μ2 = sphere.embedding.μ
ε2 = excitation.embedding.ε
μ2 = excitation.embedding.μ

ε1 = sphere.filling.ε
μ1 = sphere.filling.μ
Expand Down
1 change: 0 additions & 1 deletion src/ringCurrent/scattered.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function scatteredfield(sphere::PECSphere, excitation::RingCurrent, quantity::Fi

T = typeof(excitation.frequency)

sphere.embedding == excitation.embedding || error("Excitation and sphere are not in the same medium.") # verify excitation and sphere are in the same medium
excitation.orientation × excitation.center == SVector{3,T}(0, 0, 0) ||
error("The ring current is not perpendicular to the sphere.")

Expand Down
Loading

2 comments on commit 40eccb7

@HoBeZwe
Copy link
Owner Author

@HoBeZwe HoBeZwe commented on 40eccb7 Feb 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Breaking changes

  • The API for the embedding is changed/simplified: the embedding is now solely defined by the excitation, no longer by the sphere description. This avoids double definitions.
  • The ordering of the radii for the multilayered spheres now fits the images in the documentation (it is reversed compared to the previous version).

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/100314

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.0 -m "<description of version>" 40eccb73585f8148e44beabf6727fc680c9a43ca
git push origin v0.7.0

Please sign in to comment.