Skip to content

Commit

Permalink
Ray tracing works
Browse files Browse the repository at this point in the history
  • Loading branch information
kapple19 committed Aug 6, 2024
1 parent f0fff78 commit fb79b8d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ version = "1.0.0-DEV"

[deps]
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"

[weakdeps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand All @@ -15,4 +17,6 @@ OceanSonarAbstractTreesExt = "AbstractTrees"
[compat]
AbstractTrees = "0.4"
InteractiveUtils = "1.11.0"
ModelingToolkit = "9.30.0"
OrdinaryDiffEq = "6.87.0"
julia = "1.10"
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
OceanSonar = "03019ade-4524-4ecd-af79-46d4f04a1b56"
56 changes: 56 additions & 0 deletions src/02_acoustics/03_propagation/tracing.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
function TracingODESystem(
c_ocn::Function,
r_max::Real;
name
)
@parameters begin
s, [description = "Ray arc length"]
end

pars = @parameters begin
r₀ = 0.0
z₀
θ₀
end

@variables begin
θ(s), [description = "Ray angle, positive downwards"]
c(s), [description = "Ray celerity"]
end

deps = @variables begin
r(s) = r₀
z(s) = z₀
ξ(s) = cos(θ₀) / c_ocn(r₀, z₀)
ζ(s) = sin(θ₀) / c_ocn(r₀, z₀)
end

Ds = Differential(s)

(r′, z′) = c_ocn(r′, z′)^2
∂c_∂r(r′, z′) = ModelingToolkit.derivative(c_ocn(r, z′), r′)
∂c_∂z(r′, z′) = ModelingToolkit.derivative(c_ocn(r′, z), z′)

eqns = [
Ds(r) ~ c_ocn(r, z) * ξ
Ds(z) ~ c_ocn(r, z) * ζ
Ds(ξ) ~ -∂c_∂r(r, z) / c_ocn(r, z)^2
Ds(ζ) ~ -∂c_∂z(r, z) / c_ocn(r, z)^2
θ ~ atan(ζ, ξ)
c ~ c_ocn(r, z)
]

maximum_range = [r ~ r_max] => (
(ntg, _, _, _) -> terminate!(ntg),
[], [], []
)

events = [
maximum_range
]

return ODESystem(eqns, s, deps, pars;
name = name,
continuous_events = events
)
end
11 changes: 10 additions & 1 deletion src/OceanSonar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ export subtypes

using InteractiveUtils: subtypes

using ModelingToolkit:
ModelingToolkit,
Differential,
ODESystem,
terminate!,
@mtkbuild,
@parameters,
@variables

"""
```
include_subroots(path::AbstractString)
Expand Down Expand Up @@ -37,6 +46,6 @@ end

include_subroots(@__FILE__)

const TRIGGER_RECOMPILATION_BY_CHANGING_THIS_NUMBER = 0
const TRIGGER_RECOMPILATION_BY_CHANGING_THIS_NUMBER = 1

end

0 comments on commit fb79b8d

Please sign in to comment.