Skip to content

Commit 8c9630c

Browse files
committed
Merge branch 'feature/parallelization'
2 parents 4a37ac6 + fe936e4 commit 8c9630c

File tree

14 files changed

+79
-26
lines changed

14 files changed

+79
-26
lines changed

.codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ coverage:
33
project:
44
default:
55
target: 100%
6-
threshold: 1%
6+
threshold: 2%

.github/workflows/CI.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ on:
44
branches:
55
- 'master'
66
- 'release-'
7+
- 'feature/*'
78
tags:
89
- '*'
910
pull_request:
11+
branches:
12+
- '*'
1013
release:
1114
types: [published]
1215

Project.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
name = "SphericalScattering"
22
uuid = "1a9ea918-b599-4f1f-bd9a-d681e8bb5b3e"
33
authors = ["Bernd Hofmann <[email protected]> and contributors"]
4-
version = "0.7.2"
4+
version = "0.8.0"
55

66
[deps]
77
LegendrePolynomials = "3db4a2ba-fc88-11e8-3e01-49c72059a882"
88
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
9+
OhMyThreads = "67456a42-1dca-4109-a031-0a68de7e3ad5"
910
PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a"
11+
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
1012
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
1113
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1214

@@ -19,7 +21,9 @@ SphericalScatteringExt = "PlotlyJS"
1921
[compat]
2022
LegendrePolynomials = "0.3, 0.4"
2123
LinearAlgebra = "1"
24+
OhMyThreads = "0.8.3"
2225
PlotlyJS = "0.18"
26+
ProgressMeter = "1.10.4"
2327
SpecialFunctions = "1, 2"
2428
StaticArrays = "1"
2529
julia = "1.10"

src/SphericalScattering.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const ε0 = 8.8541878176e-12 # default permittivity
2020
using SpecialFunctions, LegendrePolynomials
2121
using LinearAlgebra
2222
using StaticArrays
23+
using OhMyThreads
24+
using ProgressMeter
2325

2426

2527

src/UniformField/scattered.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ function scatteredfield(sphere::Sphere, excitation::UniformField, quantity::Fiel
88

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

11+
points = quantity.locations
12+
p = progress(length(points))
13+
1114
# --- compute field in Cartesian representation
12-
for (ind, point) in enumerate(quantity.locations)
13-
F[ind] = scatteredfield(sphere, excitation, point, quantity; parameter=parameter)
15+
@tasks for ind in eachindex(points)
16+
F[ind] = scatteredfield(sphere, excitation, points[ind], quantity; parameter=parameter)
17+
next!(p)
1418
end
19+
finish!(p)
1520

1621
return F
1722
end

src/dataHandling.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ struct Parameter
3838
end
3939

4040
Parameter() = Parameter(-1, 1e-12)
41+
42+
# global setting for the style of the progress bar
43+
function progress(numIter::Int)
44+
return Progress(numIter; barglyphs=BarGlyphs("[=> ]"), color=:white)
45+
end

src/dipoles/incident.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ function field(excitation::Dipole, point, quantity::ElectricField; parameter::Pa
3535

3636
Il = excitation.amplitude
3737
k = wavenumber(excitation)
38-
ε = excitation.embedding.ε
39-
μ = excitation.embedding.μ
38+
ε = excitation.embedding.ε
39+
μ = excitation.embedding.μ
4040

4141
r0 = excitation.position
4242
p = excitation.orientation
@@ -87,8 +87,8 @@ function field(excitation::HertzianDipole, point, quantity::FarField; parameter:
8787

8888
Il = excitation.amplitude
8989
k = wavenumber(excitation)
90-
ε = excitation.embedding.ε
91-
μ = excitation.embedding.μ
90+
ε = excitation.embedding.ε
91+
μ = excitation.embedding.μ
9292

9393
r0 = excitation.position
9494
p = excitation.orientation

src/planeWave/scattered.jl

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ function scatteredfield(sphere::Sphere, excitation::PlaneWave, quantity::Field;
1212
# --- rotate coordinates
1313
points = rotate(excitation, quantity.locations; inverse=true)
1414

15+
p = progress(length(points))
16+
1517
# --- compute field in Cartesian representation
16-
for (ind, point) in enumerate(points)
17-
F[ind] = scatteredfield(sphere, excitation, point, quantity; parameter=parameter)
18+
@tasks for ind in eachindex(points)
19+
F[ind] = scatteredfield(sphere, excitation, points[ind], quantity; parameter=parameter)
20+
next!(p)
1821
end
22+
finish!(p)
1923

2024
# --- rotate resulting field
2125
rotate!(excitation, F; inverse=false)
@@ -42,10 +46,9 @@ function scatteredfield(sphere::Sphere, excitation::PlaneWave, point, quantity::
4246

4347
eps = parameter.relativeAccuracy
4448

45-
ST = SVector{3,Complex{T}}
46-
F = ST(0.0, 0.0, 0.0)
49+
F = SVector{3,Complex{T}}(0.0, 0.0, 0.0)
4750

48-
A₀ = amplitude(sphere, excitation::PlaneWave, quantity, r)
51+
A₀ = amplitude(sphere, excitation, quantity, r)
4952

5053
A₀ == 0.0 && return F # Inside of PEC return zero field
5154

@@ -80,7 +83,30 @@ function scatteredfield(sphere::Sphere, excitation::PlaneWave, point, quantity::
8083

8184
end
8285

83-
return convertSpherical2Cartesian(A₀ .* F, point_sph)
86+
Fin = inside(sphere, excitation, point, quantity; parameter=parameter)
87+
88+
return convertSpherical2Cartesian(A₀ .* F, point_sph) + Fin
89+
end
90+
91+
92+
function inside(sphere::Sphere, excitation::PlaneWave{T,R,C}, point, quantity::Field; parameter) where {T,R,C}
93+
94+
return SVector{3,Complex{R}}(0.0, 0.0, 0.0) # no correction needed
95+
end
96+
97+
function inside(sphere::DielectricSphere, excitation::PlaneWave{T,R,C}, point, quantity::FarField; parameter) where {T,R,C}
98+
99+
return SVector{3,Complex{R}}(0.0, 0.0, 0.0) # no correction needed
100+
end
101+
102+
function inside(sphere::DielectricSphere, excitation::PlaneWave{T,R,C}, point, quantity::Field; parameter) where {T,R,C}
103+
104+
# inside the sphere the incident field has to be substracted to get only the scattered part
105+
if norm(point) < sphere.radius
106+
return -field(excitation, point, quantity; parameter=parameter)
107+
end
108+
109+
return SVector{3,Complex{R}}(0.0, 0.0, 0.0)
84110
end
85111

86112

src/ringCurrent/incident.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ function field(excitation::RingCurrent, point, quantity::MagneticField; paramete
122122

123123
eps = parameter.relativeAccuracy
124124

125-
Hr = Complex{T}(0.0) # initialize
125+
Hr = Complex{T}(0.0) # initialize
126126
= Complex{T}(0.0) # initialize
127127
δHr = T(Inf)
128-
n = -1
128+
n = -1
129129

130130
r = point_sph[1]
131131

src/ringCurrent/scattered.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ function scatteredfield(sphere::PECSphere, excitation::RingCurrent, quantity::Fi
1919
# --- translate/rotate coordinates
2020
points = rotate(excitation, quantity.locations; inverse=true)
2121

22+
p = progress(length(points))
23+
2224
# --- compute field in Cartesian representation
23-
for (ind, point) in enumerate(points)
24-
F[ind] = scatteredfield(sphere, exc, point, fieldType; parameter=parameter)
25+
@tasks for ind in eachindex(points)
26+
F[ind] = scatteredfield(sphere, exc, points[ind], fieldType; parameter=parameter)
27+
next!(p)
2528
end
29+
finish!(p)
2630

2731
# --- rotate resulting field
2832
rotate!(excitation, F; inverse=false)

src/sphere.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ end
210210
wavenumber(sp::Sphere, ex::Excitation, r)
211211
212212
Returns the wavenumber at radius `r` in the sphere `sp`.
213-
If this part is PEC, k=0 is rweturned.
213+
If this part is PEC, k=0 is returned.
214214
"""
215215
function wavenumber(sp::PECSphere, ex::Excitation, r)
216216
ε = ex.embedding.ε

src/sphericalModes/scattered.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ function scatteredfield(sphere::PECSphere, excitation::SphericalMode, quantity::
1919

2020
γ = scatterCoeff(sphere, excitation, excitation.n, wavenumber(excitation) * sphere.radius)
2121

22+
p = progress(length(points))
23+
2224
# --- compute field in Cartesian representation
23-
for (ind, point) in enumerate(points)
24-
F[ind] = γ * scatteredfield(sphere, exc, point, fieldType; parameter=parameter)
25+
@tasks for ind in eachindex(points)
26+
F[ind] = γ * scatteredfield(sphere, exc, points[ind], fieldType; parameter=parameter)
27+
next!(p)
2528
end
29+
finish!(p)
2630

2731
# --- rotate resulting field
2832
# rotate!(F, excitation.rotation)

src/utils.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
55
Convenience function returning points (in Cartesian and spherical coordinates) on a spherical grid at a distance 'r' and a resolution in degrees.
66
"""
7-
function sphericalGridPoints(; r=1.0, resolution=5)
7+
function sphericalGridPoints(; r=1.0, resolution=5, center=SVector(0.0, 0.0, 0.0))
88

99
ϑ = range(0.0; stop=π, length=round(Int, 180 / resolution)) # default: 5° steps
1010
ϕ = range(0.0; stop=2π, length=round(Int, 360 / resolution)) # default: 5° steps
1111

12-
points_cart = [SVector(r * cos(φ) * sin(θ), r * sin(φ) * sin(θ), r * cos(θ)) for θ in ϑ, φ in ϕ]
13-
points_sph = [SVector(r, θ, φ) for θ in ϑ, φ in ϕ]
12+
points_cart = [SVector(r * cos(φ) * sin(θ), r * sin(φ) * sin(θ), r * cos(θ)) + center for θ in ϑ, φ in ϕ]
13+
points_sph = [SVector(r, θ, φ) + center for θ in ϑ, φ in ϕ]
1414

1515
return points_cart, points_sph
1616
end

test/planeWave_dielectric.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777

7878
# E-Field
7979
EF₂ = scatteredfield(sp, ex, ElectricField(points_cartNF))
80-
EF₁ = scatteredfield(sp, ex, ElectricField(points_cartNF_inside))
80+
EF₁ = field(sp, ex, ElectricField(points_cartNF_inside))
8181

8282
diff_EF₂ = norm.(EF₂ - EF₂MoM) ./ maximum(norm.(EF₂)) # worst case error
8383
diff_EF₁ = norm.(EF₁ - EF₁MoM) ./ maximum(norm.(EF₁)) # worst case error
@@ -90,7 +90,7 @@
9090
HF₁MoM = hfield(𝓣k1, -(1 / η1)^2 .* m, RT, 𝓚k1, -j, RT, points_cartNF_inside)
9191

9292
HF₂ = scatteredfield(sp, ex, MagneticField(points_cartNF))
93-
HF₁ = scatteredfield(sp, ex, MagneticField(points_cartNF_inside))
93+
HF₁ = field(sp, ex, MagneticField(points_cartNF_inside))
9494

9595
diff_HF₂ = norm.(HF₂ - HF₂MoM) ./ maximum(norm.(HF₂)) # worst case error
9696
diff_HF₁ = norm.(HF₁ - HF₁MoM) ./ maximum(norm.(HF₁)) # worst case error

0 commit comments

Comments
 (0)