Skip to content

Commit

Permalink
Implemented nested structures up to Scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
kapple19 committed Aug 14, 2024
1 parent d74e15f commit ea2991b
Show file tree
Hide file tree
Showing 25 changed files with 374 additions and 57 deletions.
48 changes: 21 additions & 27 deletions demo/fan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@ using OceanSonar
using OceanSonar.IntervalArithmetic
using CairoMakie

cel = OceanCelerityProfile("Munk")
bty = BathymetryProfile("Flat", z = 5e3)
ati = AltimetryProfile("Flat")

r_min = 0.0
r_max = 100e3

scen = Scenario("Munk Celerity")
fan = Fan("Gaussian",
π/20 * range(-1, 1, 5),
1e3, r_max, 1e3,
cel,
bty,
ReflectionCoefficientProfile("Reflective"),
ati,
ReflectionCoefficientProfile("Mirror")
π/20 * range(-1, 1, 3),
scen.own.pos.z, 100e3, 1e3,
scen.env.ocn.cel,
scen.env.bot.dpt,
scen.env.bot.rfl,
scen.env.srf.dpt,
scen.env.srf.rfl
)

r_ntv = interval(r_min, r_max)
Expand All @@ -26,9 +23,9 @@ z_max = r_ntv |> bty |> sup

fig = Figure()
axis = Axis(fig[1, 1], yreversed = true)
celerityheatmap!(axis, cel, r_min, r_max, z_min, z_max)
bathymetryband!(axis, bty, r_min, r_max)
altimetryband!(axis, ati, r_min, r_max)
celerityheatmap!(axis, scen.env.ocn.cel, r_min, r_max, z_min, z_max)
bathymetryband!(axis, scen.env.bot.dpt, r_min, r_max)
altimetryband!(axis, scen.env.srf.dpt, r_min, r_max)
raycurves!(axis, fan)

display(fig)
Expand All @@ -38,23 +35,20 @@ using OceanSonar
using OceanSonar.IntervalArithmetic
using CairoMakie

cel = OceanCelerityProfile("Homogeneous")
bty = BathymetryProfile("Parabolic")
ati = AltimetryProfile("Flat")

r_min = 0.0
r_max = 20e3

z_ref = 5e3

scen = Scenario("Parabolic Bathymetry")
fan = Fan("Gaussian",
range(atan(z_ref, r_max), atan(z_ref, r_max/10), 5),
0.0, r_max, 1e3,
cel,
bty,
ReflectionCoefficientProfile("Reflective"),
ati,
ReflectionCoefficientProfile("Mirror")
scen.own.pos.z, r_max, 1e3,
scen.env.ocn.cel,
scen.env.bot.dpt,
scen.env.bot.rfl,
scen.env.srf.dpt,
scen.env.srf.rfl
)

r_ntv = interval(r_min, r_max)
Expand All @@ -63,9 +57,9 @@ z_max = r_ntv |> bty |> sup

fig = Figure()
axis = Axis(fig[1, 1], yreversed = true)
celerityheatmap!(axis, cel, r_min, r_max, z_min, z_max)
bathymetryband!(axis, bty, r_min, r_max)
altimetryband!(axis, ati, r_min, r_max)
celerityheatmap!(axis, scen.env.ocn.cel, r_min, r_max, z_min, z_max)
bathymetryband!(axis, scen.env.bot.dpt, r_min, r_max)
altimetryband!(axis, scen.env.srf.dpt, r_min, r_max)
raycurves!(axis, fan)

display(fig)
18 changes: 9 additions & 9 deletions demo/interactivity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using OceanSonar, GLMakie

interactive_raycurves(
OceanCelerityProfile("Munk"),
BathymetryProfile("Flat", z = 5e3),
AltimetryProfile("Flat");
OceanCelerityProfile(:Munk),
BathymetryProfile(:Flat, z = 5e3),
AltimetryProfile(:Flat);
r_max = 100e3,
num_rays = 5,
min_angle = -π/20,
Expand All @@ -15,9 +15,9 @@ interactive_raycurves(
using OceanSonar, GLMakie

interactive_raycurves(
OceanCelerityProfile("Homogeneous"),
OceanCelerityProfile(:Homogeneous),
BathymetryProfile("Parabolic"),
AltimetryProfile("Flat");
AltimetryProfile(:Flat);
r_max = 20e3,
z_src = 0.0,
num_rays = 5,
Expand All @@ -28,11 +28,11 @@ interactive_raycurves(
##
using OceanSonar, GLMakie

cel = OceanCelerityProfile("Homogeneous")
ati = AltimetryProfile("Flat")
cel = OceanCelerityProfile(:Homogeneous)
ati = AltimetryProfile(:Flat)
bty = BathymetryProfile("Parabolic")
Rsrf = ReflectionCoefficientProfile("Reflective")
Rbot = ReflectionCoefficientProfile("Mirror")
Rsrf = ReflectionCoefficientProfile(:Reflective)
Rbot = ReflectionCoefficientProfile(:Mirror)

r_max = 20e3
z_src = 0.0
Expand Down
4 changes: 2 additions & 2 deletions ext/OceanSonarGLMakieExt/ray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ function interactive_raycurves(
range(min_angle, max_angle, num_rays),
z₀, r_max, 1e3,
cel,
bty, ReflectionCoefficientProfile("Reflective"),
ati, ReflectionCoefficientProfile("Mirror")
bty, ReflectionCoefficientProfile(:Reflective),
ati, ReflectionCoefficientProfile(:Mirror)
)
end

Expand Down
8 changes: 4 additions & 4 deletions prototyping/sonar_equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ struct AbsentEntity <: AbstractEntity end
mutable struct Entity{ET <: EmissionType} <: AbstractEntity
SL::Float64
NL::Float64
pos::RectangularCoordinate{2}
pos::RectangularCoordinate{DownwardDepth}
end

function Entity{ETnew <: EmissionType}(ent::Entity{ETold}) where {ETold <: EmissionType}
Entity{ETnew}(field => getpropert(ent, field) for field in fieldnames(Entity))
Entity{ETnew}(field => getproperty(ent, field) for field in fieldnames(Entity))
end

source_level(own::Entity{Signaling}, tgt::Entity{NoiseOnly}, fac::AbsentEntity = AbsentEntity()) = own.SL
Expand All @@ -36,11 +36,11 @@ reverberation_level(env::Environment, prop::SonarPropagation, own::Entity{NoiseO
reverberation_level(env::Environment, prop::SonarPropagation, own::Entity{NoiseOnly}, tgt::Entity{NoiseOnly}, fac::Entity{Signaling} ) = reverberation(env, prop, own, fac)

@kwdef struct AcousticConfig
beam_model::ModelName = ModelName("Gaussian")
beam_model::ModelName = ModelName(:Gaussian)
end

@kwdef struct PropagationConfig
acoustic_config::AcousticConfig = AcousticConfig("BeamTracing")
acoustic_config::AcousticConfig = AcousticConfig(:BeamTracing)
end

struct SonarPropagation
Expand Down
6 changes: 6 additions & 0 deletions src/00_preliminary/01_general/01_auxiliary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ export uniquesort!
export cossin
export

macro initialise_function()
return quote
function anon end
end
end

const uniquesort! = unique! sort!

const cossin = reverse sincos
Expand Down
4 changes: 4 additions & 0 deletions src/00_preliminary/02_modelling/02_modelling_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ abstract type ModellingContainer <: ModellingType end
abstract type ModellingComputation <: ModellingType end

children(T::Type{<:ModellingType}) = subtypes(T)

abstract type EnvironmentComponent end

children(T::Type{<:EnvironmentComponent}) = subtypes(T)
10 changes: 5 additions & 5 deletions src/00_preliminary/02_modelling/04_spatial_orientation.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
orienter(::SpatialDimensionSize{2}, r::Real; x₀::Real, y₀::Real, θ::Real) = (x₀, y₀) .+ r .* cossin(θ)
orienter(SDS::SpatialDimensionSize{2}, x::Real, y::Real; x₀::Real, y₀::Real, θ::Real) = orienter(SDS, hypot(x, y); x₀ = x₀, y₀ = y₀, θ = θ)
orienter(::SpatialDimensionSize{3}, z::Real; x₀::Real, y₀::Real, θ::Real) = (x₀, y₀, z)
orienter(SDS::SpatialDimensionSize{3}, r::Real, z::Real; x₀::Real, y₀::Real, θ::Real) = orienter(SDS, z; x₀ = x₀, y₀ = y₀, θ = θ) .+ ((r .* cossin(θ))..., 0.0)
orienter(SDS::SpatialDimensionSize{3}, x::Real, y::Real, z::Real; x₀::Real, y₀::Real, θ::Real) = orienter(SDS, hypot(x, y), z; x₀ = x₀, y₀ = y₀, θ = θ)
orient(::SpatialDimensionSize{2}, r::Real; x₀::Real, y₀::Real, θ::Real) = (x₀, y₀) .+ r .* cossin(θ)
orient(SDS::SpatialDimensionSize{2}, x::Real, y::Real; x₀::Real, y₀::Real, θ::Real) = orient(SDS, hypot(x, y); x₀ = x₀, y₀ = y₀, θ = θ)
orient(::SpatialDimensionSize{3}, z::Real; x₀::Real, y₀::Real, θ::Real) = (x₀, y₀, z)
orient(SDS::SpatialDimensionSize{3}, r::Real, z::Real; x₀::Real, y₀::Real, θ::Real) = orient(SDS, z; x₀ = x₀, y₀ = y₀, θ = θ) .+ ((r .* cossin(θ))..., 0.0)
orient(SDS::SpatialDimensionSize{3}, x::Real, y::Real, z::Real; x₀::Real, y₀::Real, θ::Real) = orient(SDS, hypot(x, y), z; x₀ = x₀, y₀ = y₀, θ = θ)

# TODO: Let SpatialDimensionSize{3} call SpatialDimensionSize{2} where appropriate
9 changes: 8 additions & 1 deletion src/00_preliminary/02_modelling/05_generic_behaviour.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ function (FunctorType::Type{<:ModellingFunctor})(
pars...
) where {M}
modelling_function = ModellingFunction(FunctorType)
profile(args::Real...) = modelling_function(model, orienter(SDS, args...; x₀ = x₀, y₀ = y₀, θ = θ)...; pars...)
profile(args::Real...) = modelling_function(model, orient(SDS, args...; x₀ = x₀, y₀ = y₀, θ = θ)...; pars...)
FunctorType{profile |> typeof}(profile)
end

function (functor::ModellingFunctor)(::SpatialDimensionSize, args::Real...; pars...)
functor.profile(args...)
end

# function (container::ModellingContainer)(; kw...)
# (
# haskey(kw, field) ? kw[field] : @initialise_function()
# for field in fieldnames(container)
# ) |> splat(container)
# end
13 changes: 13 additions & 0 deletions src/00_preliminary/02_modelling/06_modelling_implementations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,16 @@ macro implement_spatially_modelled_function_and_functor(functor_name, spatial_di
ModellingFunction(::Type{<:$functor_name}) = $function_name
end
end

# macro add_container_defaults_method(container_name)
# container = getproperty(OceanSonar, container_name)
# fields = fieldnames(container)
# @eval begin
# function $container_name(; kw...)
# (
# haskey(kw, field) ? kw[field] : @initialise_function()
# for field in fields
# ) |> splat($container_name)
# end
# end
# end
1 change: 1 addition & 0 deletions src/99_postliminary/01_functors/boundary/bathymetry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ bathymetry_profile(::ModelName{:Flat}, x::Real, y::Real; z::Real) = z
bathymetry_profile(::ModelName{:Epipelagic}, x::Real, y::Real) = 100.0
bathymetry_profile(::ModelName{:Mesopelagic}, x::Real, y::Real) = 1e3
bathymetry_profile(::ModelName{:Bathypelagic}, x::Real, y::Real) = 4e3
bathymetry_profile(::ModelName{:Deep}, x::Real, y::Real) = 5e3
bathymetry_profile(::ModelName{:Abyssopelagic}, x::Real, y::Real) = 6e3

bathymetry_profile(::ModelName{:Bottomless}, x::Real, y::Real) = Inf
Expand Down
6 changes: 5 additions & 1 deletion src/99_postliminary/01_functors/celerity/ocean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ function ocean_celerity_profile(::ModelName{:Munk}, x::Real, y::Real, z::Real;
- 1 + exp(-z̃)
)
)
end
end

function ocean_celerity_profile(::ModelName{:RefractionSquared}, x::Real, y::Real, z::Real; c₀ = 1550)
c₀ / sqrt(1 + 2.4z / c₀)
end
7 changes: 4 additions & 3 deletions src/99_postliminary/01_functors/reflection_coefficient.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ function (FunctorType::Type{<:ReflectionCoefficientProfile})(
pars...
) where {M}
modelling_function = ModellingFunction(FunctorType)
profile(r::Real, φ::Real) = modelling_function(model, orienter(SDS, r; x₀ = x₀, y₀ = y₀, θ = θ)..., φ; pars...)
profile(x::Real, y::Real, φ::Real) = modelling_function(model, orienter(SDS, x, y; x₀ = x₀, y₀ = y₀, θ = θ)..., φ; pars...)
profile(r::Real, φ::Real) = modelling_function(model, orient(SDS, r; x₀ = x₀, y₀ = y₀, θ = θ)..., φ; pars...)
profile(x::Real, y::Real, φ::Real) = modelling_function(model, orient(SDS, x, y; x₀ = x₀, y₀ = y₀, θ = θ)..., φ; pars...)
FunctorType{profile |> typeof}(profile)
end

## Models
reflection_coefficient_profile(::ModelName{:Mirror}, x::Real, y::Real, φ::Real) = ComplexF64(-1.0)
reflection_coefficient_profile(::ModelName{:Absorbent}, x::Real, y::Real, φ::Real) = ComplexF64(0.0)
reflection_coefficient_profile(::ModelName{:Reflective}, x::Real, y::Real, φ::Real) = ComplexF64(1.0)
reflection_coefficient_profile(::ModelName{:Reflective}, x::Real, y::Real, φ::Real; ϕ::Real = 0.0) = cis(ϕ)
reflection_coefficient_profile(::ModelName{:Translucent}, x::Real, y::Real, φ::Real; ϕ::Real = 0.0) = 0.5cis(ϕ)
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ struct UpwardDepth <: PositiveDepthDirection end

abstract type AbstractCoordinateSystem{DepthDir <: PositiveDepthDirection} end

RectangularCoordinateNaN(DepthDir::Type{<:PositiveDepthDirection}) = RectangularCoordinate{DepthDir}(x = NaN32, y = NaN32, z = NaN32)

@kwdef mutable struct RectangularCoordinate{DepthDir} <: AbstractCoordinateSystem{DepthDir}
x::Float32
y::Float32
Expand All @@ -28,3 +30,7 @@ end
θ::Float32
φ::Float32
end

# function show(io::IO, ::MIME"text/plain", pos::AbstractCoordinateSystem{DepthDir}) where {DepthDir <: PositiveDepthDirection}

# end
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export Surface
export Bottom

abstract type InterfaceType <: EnvironmentComponent end

struct SurfaceInterface <: InterfaceType end
struct BottomInterface <: InterfaceType end

@kwdef mutable struct AcousticInterface{IT <: InterfaceType} <: ModellingContainer
dpt::Function
rfl::Function
end

Surface = AcousticInterface{SurfaceInterface}
Bottom = AcousticInterface{BottomInterface}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
AcousticInterface{BottomInterface}(::ModelName{:ReflectiveDeep}) = AcousticInterface{BottomInterface}(
dpt = BathymetryProfile(:Deep),
rfl = ReflectionCoefficientProfile(:Reflective),
)

AcousticInterface{BottomInterface}(::ModelName{:AbsorbentDeep}) = AcousticInterface{BottomInterface}(
dpt = BathymetryProfile(:Deep),
rfl = ReflectionCoefficientProfile(:Absorbent)
)

AcousticInterface{BottomInterface}(::ModelName{:TranslucentDeep}) = AcousticInterface{BottomInterface}(
dpt = BathymetryProfile(:Deep),
rfl = ReflectionCoefficientProfile(:Translucent)
)

AcousticInterface{BottomInterface}(::ModelName{:ParabolicBathymetry}) = AcousticInterface{BottomInterface}(
dpt = BathymetryProfile(:Parabolic),
rfl = ReflectionCoefficientProfile(:Reflective)
)

AcousticInterface{BottomInterface}(::ModelName{:AbsorbentMesopelagic}) = AcousticInterface{BottomInterface}(
dpt = BathymetryProfile(:Mesopelagic),
rfl = ReflectionCoefficientProfile(:Absorbent)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
AcousticInterface{SurfaceInterface}(::ModelName{:Mirror}) = AcousticInterface{SurfaceInterface}(
dpt = AltimetryProfile(:Flat),
rfl = ReflectionCoefficientProfile(:Mirror)
)

AcousticInterface{SurfaceInterface}(::ModelName{:Absorbent}) = AcousticInterface{SurfaceInterface}(
dpt = AltimetryProfile(:Flat),
rfl = ReflectionCoefficientProfile(:Absorbent)
)

AcousticInterface{SurfaceInterface}(::ModelName{:Translucent}) = AcousticInterface{SurfaceInterface}(
dpt = AltimetryProfile(:Flat),
rfl = ReflectionCoefficientProfile(:Translucent; ϕ = π)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
export Atmosphere
export Ocean
export Seabed

abstract type MediumType <: EnvironmentComponent end

struct AtmosphereMedium <: MediumType end
struct OceanMedium <: MediumType end
struct SeabedMedium <: MediumType end

mutable struct AcousticMedium{MT <: MediumType} <: ModellingContainer
den::Function
wnd::Function
cel::Function
shear_cel::Function
atn::Function
shear_atn::Function
end

Atmosphere = AcousticMedium{AtmosphereMedium}
Ocean = AcousticMedium{OceanMedium}
Seabed = AcousticMedium{SeabedMedium}

AcousticMedium{AtmosphereMedium}(;
den::Function = AtmosphereDensityProfile(:Homogeneous),
wnd::Function = @initialise_function,
cel::Function = AtmosphereCelerityProfile(:Homogeneous),
shear_cel::Function = @initialise_function,
atn::Function = @initialise_function,
shear_atn::Function = @initialise_function,
) = AcousticMedium{AtmosphereMedium}(den, wnd, cel, shear_cel, atn, shear_atn)

AcousticMedium{OceanMedium}(;
den::Function = OceanDensityProfile(:Homogeneous),
wnd::Function = @initialise_function,
cel::Function = OceanCelerityProfile(:Munk),
shear_cel::Function = @initialise_function,
atn::Function = @initialise_function,
shear_atn::Function = @initialise_function,
) = AcousticMedium{OceanMedium}(den, wnd, cel, shear_cel, atn, shear_atn)

AcousticMedium{SeabedMedium}(;
den::Function = SeabedDensityProfile(:Homogeneous),
wnd::Function = @initialise_function,
cel::Function = SeabedCelerityProfile(:Homogeneous),
shear_cel::Function = @initialise_function,
atn::Function = @initialise_function,
shear_atn::Function = @initialise_function,
) = AcousticMedium{SeabedMedium}(den, wnd, cel, shear_cel, atn, shear_atn)
Loading

0 comments on commit ea2991b

Please sign in to comment.