Skip to content

Commit

Permalink
Separating isotropic hemlholtz resonator from general helmholtz reson…
Browse files Browse the repository at this point in the history
…ator
  • Loading branch information
pivaps committed Sep 18, 2024
1 parent 2d48ba6 commit ea96351
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/MultipleScattering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export Symmetry, AbstractSymmetry, AbstractPlanarSymmetry, AbstractAzimuthalSymm
export WithoutSymmetry, PlanarSymmetry, PlanarAzimuthalSymmetry, AzimuthalSymmetry, RadialSymmetry, TranslationSymmetry

## Shapes
export Shape, Circle, Sphere, SphericalHelmholtz, Rectangle, Box, EmptyShape, Halfspace, Plate, TimeOfFlightPlaneWaveToPoint, TimeOfFlightPointWaveToPoint
export Shape, Circle, Sphere, IsotropicHelmholtz, Helmholtz, Rectangle, Box, EmptyShape, Halfspace, Plate, TimeOfFlightPlaneWaveToPoint, TimeOfFlightPointWaveToPoint

export outer_radius, volume, name, iscongruent, (), congruent, in, issubset, origin, shape, (==), isequal, show
export boundary_functions, boundary_points, boundary_data, bounding_box, corners
Expand Down
2 changes: 1 addition & 1 deletion src/physics/acoustics/helmholtz_circle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The T-matrix for a 2D circlular Helmholtz resonator in a 2D acoustic medium.
"""
function t_matrix(p::Particle{2,Acoustic{T,2},SphericalHelmholtz{T,2}}, outer_medium::Acoustic{T,2}, ω::T, basis_order::Integer)::Diagonal{Complex{T}} where T <: AbstractFloat
function t_matrix(p::Particle{2,Acoustic{T,2},IsotropicHelmholtz{T,2}}, outer_medium::Acoustic{T,2}, ω::T, basis_order::Integer)::Diagonal{Complex{T}} where T <: AbstractFloat

M = basis_order
ε = p.shape.aperture
Expand Down
66 changes: 52 additions & 14 deletions src/shapes/sphere.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,24 @@ struct Sphere{T,Dim} <: AbstractSphere{Dim}
end

"""
SphericalHelmholtz([origin=zeros(),] radius, aperture)
IsotropicHelmholtz([origin=zeros(),] radius, aperture)
A [`Shape`](@ref) which represents a 2D thin-walled isotropic Helmholtz resonator.
"""

struct SphericalHelmholtz{T,Dim} <: AbstractSphere{Dim}
struct IsotropicHelmholtz{T,Dim} <: AbstractSphere{Dim}
origin::SVector{Dim,T}
radius::T
aperture::T
end

"""
Helmholtz([origin=zeros(),] radius, aperture)
A [`Shape`](@ref) which represents a general 2D Helmholtz resonator.
"""

struct Helmholtz{T,Dim} <: AbstractSphere{Dim}
origin::SVector{Dim,T}
radius::T
inner_radius::T
Expand All @@ -32,19 +44,33 @@ end
# Alternate constructors, where type is inferred naturally
Sphere(origin::NTuple{Dim}, radius::T) where {T,Dim} = Sphere{T,Dim}(origin, radius)
Sphere(origin::AbstractVector, radius::T) where {T} = Sphere{T,length(origin)}(origin, radius)
SphericalHelmholtz(origin::NTuple{Dim}, radius::T, inner_radius::T, aperture::T, orientation::T) where {T, Dim} = SphericalHelmholtz{T,Dim}(origin, radius, inner_radius, aperture, orientation)

SphericalHelmholtz(origin::NTuple{Dim}, radius::T; inner_radius::T = zero(T), aperture::T = zero(T), orientation::T = zero(T)) where {T, Dim} = SphericalHelmholtz{T,Dim}(origin, radius, inner_radius, aperture, orientation)
IsotropicHelmholtz(origin::NTuple{2}, radius::T, aperture::T) where {T} = IsotropicHelmholtz{T,2}(origin, radius, aperture)

Helmholtz(origin::NTuple{Dim}, radius::T, inner_radius::T, aperture::T, orientation::T) where {T,Dim} = Helmholtz{T,Dim}(origin, radius, inner_radius, aperture, orientation)

Sphere(Dim, radius::T) where {T} = Sphere{T,Dim}(zeros(T,Dim), radius)

function SphericalHelmholtz(Dim::Int, radius::T;
IsotropicHelmholtz(radius::T, aperture::T) where {T} = IsotropicHelmholtz{T,2}(zeros(T, 2), radius, aperture)

Helmholtz(radius::T, inner_radius::T, aperture::T) where {T} = Helmholtz{T,2}(zeros(T, 2), radius, inner_radius, aperture, zero(T))

Helmholtz(origin::NTuple{Dim}, radius::T; inner_radius::T=zero(T), aperture::T=zero(T), orientation::T=zero(T)) where {T,Dim} = Helmholtz{T,Dim}(origin, radius, inner_radius, aperture, orientation)

function IsotropicHelmholtz(Dim::Int, radius::T;
origin::T=zeros(T, Dim),
aperture::T=zero(T)) where {T}

return IsotropicHelmholtz{T,Dim}(origin, radius, aperture)
end

function Helmholtz(Dim::Int, radius::T;
origin::T = zeros(T,Dim),
aperture::T = zero(T),
inner_radius::T = zero(T),
orientation::T = zero(T)) where {T}

return SphericalHelmholtz{T,Dim}(origin, radius, inner_radius, aperture, orientation)
return Helmholtz{T,Dim}(origin, radius, inner_radius, aperture, orientation)
end

Circle(origin::Union{AbstractVector{T},NTuple{2,T}}, radius::T) where T <: AbstractFloat = Sphere{T,2}(origin, radius::T)
Expand All @@ -53,7 +79,7 @@ Sphere(radius::T) where {T} = Sphere{T,3}(zeros(T,3), radius)

name(shape::Sphere) = "Sphere"
name(shape::Sphere{T,2}) where T = "Circle"
name(shape::SphericalHelmholtz) = "SphericalHelmholtz"
name(shape::IsotropicHelmholtz) = "IsotropicHelmholtz"
Symmetry(shape::AbstractSphere{Dim}) where {Dim} = RadialSymmetry{Dim}()

outer_radius(sphere::AbstractSphere) = sphere.radius
Expand Down Expand Up @@ -98,7 +124,11 @@ function ==(c1::Sphere, c2::Sphere)
c1.origin == c2.origin && c1.radius == c2.radius
end

function ==(c1::SphericalHelmholtz, c2::SphericalHelmholtz)
function ==(c1::IsotropicHelmholtz, c2::IsotropicHelmholtz)
c1.origin == c2.origin && c1.radius == c2.radius && c1.aperture == c2.aperture
end

function ==(c1::Helmholtz, c2::Helmholtz)
c1.origin == c2.origin && c1.radius == c2.radius && c1.inner_radius == c2.inner_radius && c1.aperture == c2.aperture && c1.orientation == c2.orientation
end

Expand All @@ -111,8 +141,12 @@ function isequal(c1::Sphere, c2::Sphere)
isequal(c1.origin, c2.origin) && isequal(c1.radius, c2.radius)
end

function isequal(c1::SphericalHelmholtz, c2::SphericalHelmholtz)
isequal(c1.origin, c2.origin) && isequal(c1.radius, c2.radius) && s1.aperture == s2.aperture
function isequal(c1::IsotropicHelmholtz, c2::IsotropicHelmholtz)
isequal(c1.origin, c2.origin) && isequal(c1.radius, c2.radius) && isequal(s1.aperture, s2.aperture)
end

function isequal(c1::Helmholtz, c2::Helmholtz)
isequal(c1.origin, c2.origin) && isequal(c1.radius, c2.radius) && isequal(c1.inner_radius, c2.inner_radius) && isequal(s1.aperture, s2.aperture) && isequal(c1.orientation, c2.orientation)
end

function iscongruent(c1::AbstractSphere, c2::AbstractSphere)
Expand All @@ -123,16 +157,20 @@ function iscongruent(s1::Sphere, s2::Sphere)
s1.radius == s2.radius
end

function iscongruent(s1::SphericalHelmholtz, s2::SphericalHelmholtz)
function iscongruent(s1::IsotropicHelmholtz, s2::IsotropicHelmholtz)
s1.radius == s2.radius && s1.aperture == s2.aperture
end

function iscongruent(s1::Helmholtz, s2::Helmholtz)
s1.radius == s2.radius && s1.aperture == s2.aperture && s1.inner_radius == s2.inner_radius && s1.orientation == s2.orientation
end

function congruent(s::Sphere, x)
Sphere(x, s.radius)
end

function congruent(s::SphericalHelmholtz, x)
SphericalHelmholtz(x, s.radius, s.aperture)
function congruent(s::IsotropicHelmholtz, x)
IsotropicHelmholtz(x, s.radius, s.aperture)
end

function Circle(sphere::AbstractSphere; y = sphere.origin[2])
Expand Down Expand Up @@ -189,7 +227,7 @@ function boundary_functions(circle::Sphere{T,2}) where T
return x, y
end

function boundary_functions(circle::SphericalHelmholtz{T,2}) where T
function boundary_functions(circle::Helmholtz{T,2}) where T

function x(t)
check_boundary_coord_range(t)
Expand Down
33 changes: 28 additions & 5 deletions test/particle_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,16 @@
circle_congruent = Sphere((4.0,7.0),2.0)
rect = Box((1.0,2.0),(2.0,4.0))

resonator = SphericalHelmholtz((1.0,3.0),2.0, 0.2, 0.01, -1.3)
resonator_kws = SphericalHelmholtz((1.0,3.0),2.0; inner_radius = 0.2, aperture = 0.1, orientation = -1.3)
resonator_dif_aperture = SphericalHelmholtz((1.0,3.0),2.0; aperture = 0.1)
resonator_identical = SphericalHelmholtz((1.0,3.0), 2.0; orientation = -1.3, inner_radius = 0.2, aperture = 0.01)
resonator_congruent = SphericalHelmholtz((4.0,7.0), 2.0; orientation = -1.3, inner_radius = 0.2, aperture = 0.01)
iso_resonator = IsotropicHelmholtz((1.0, 3.0), 2.0, 0.2)
iso_resonator_dif_aperture = IsotropicHelmholtz((1.0, 3.0), 2.0, 0.1)
iso_resonator_identical = IsotropicHelmholtz((1.0, 3.0), 2.0, 0.2)
iso_resonator_congruent = IsotropicHelmholtz((4.0, 7.0), 2.0, 0.2)

resonator = Helmholtz((1.0, 3.0), 2.0, 0.2, 0.01, -1.3)
resonator_kws = Helmholtz((1.0, 3.0), 2.0; inner_radius=0.2, aperture=0.1, orientation=-1.3)
resonator_dif_aperture = Helmholtz((1.0, 3.0), 2.0; aperture=0.1)
resonator_identical = Helmholtz((1.0, 3.0), 2.0; orientation=-1.3, inner_radius=0.2, aperture=0.01)
resonator_congruent = Helmholtz((4.0, 7.0), 2.0; orientation=-1.3, inner_radius=0.2, aperture=0.01)

# Construct four particles, with two the same
p = Particle(a2,circle)
Expand All @@ -67,6 +72,14 @@
p_different = Particle(a2, rect)
p_congruent = Particle(a2,circle_congruent)

# Construct three isotropic resonator particles
p_iso_r = Particle(a2, iso_resonator)
p_iso_r_reference = p_iso_r
p_iso_r_dif_aperture = Particle(a2, iso_resonator_dif_aperture)
p_iso_r_identical = Particle(a2, iso_resonator_identical)
p_iso_r_different = p_different
p_iso_r_congruent = Particle(a2, iso_resonator_congruent)

# Construct three resonator particles
pr = Particle(a2, resonator)
pr_reference = pr
Expand All @@ -83,9 +96,19 @@
@test !(pr == pr_dif_aperture)
@test p != pr
@test !(p == pr)
@test p != p_iso_r
@test !(p == p_iso_r)
@test iscongruent(p, p_congruent)
@test !iscongruent(p, p_different)
@test !iscongruent(p, pr)
@test p_iso_r == p_iso_r_identical
@test p_iso_r != p_iso_r_different
@test !(p_iso_r == p_iso_r_different)
@test p_iso_r != pr
@test !(p_iso_r == pr)
@test iscongruent(p_iso_r, p_iso_r_congruent)
@test !iscongruent(p_iso_r, p_iso_r_dif_aperture)
@test !iscongruent(p_iso_r, p_iso_r_different)
@test pr == pr_identical
@test pr != pr_different
@test !(pr == pr_different)
Expand Down

0 comments on commit ea96351

Please sign in to comment.