Skip to content

Commit d88f1cf

Browse files
committed
updating syntaxe to julia 1.0
1 parent 26a4938 commit d88f1cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+118
-113
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ plot(time_result)
9090
![Plot real part of acoustic field](example/intro/plot_time_result.png)
9191
Or for a Gaussian impulse in time:
9292
```julia
93-
t_vec = linspace(0.,700.,400)
93+
t_vec = LinRange(0.,700.,400)
9494
time_result = frequency_to_time(result; t_vec = t_vec, impulse = GaussianImpulse(max_ω))
9595
plot(time_result)
9696
```

REQUIRE

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
julia 0.5
1+
julia 1.0
22
RecipesBase
33
ProgressMeter
44
SpecialFunctions
5+
Printf
6+
LinearAlgebra
7+
Random
8+
Statistics
59
StaticArrays
610
OffsetArrays

docs/src/example/box_size/box_size.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using MultipleScattering
22
using Plots; pyplot()
33

44
function box_size_convergence(m=4, volfrac = 0.05,
5-
radius = 1.0, times = [20.0,30.0,40.0,50.0,60.0,70.0], k_arr=collect(linspace(0.01,1.0,100)) )
5+
radius = 1.0, times = [20.0,30.0,40.0,50.0,60.0,70.0], k_arr=collect(LinRange(0.01,1.0,100)) )
66

77
listener_position = [-10.0,0.0]
88
bigshape = TimeOfFlight(listener_position,maximum(times))
@@ -17,12 +17,12 @@ function box_size_convergence(m=4, volfrac = 0.05,
1717
return FrequencySimulation(particles, k_arr; seed=seed, hankel_order=m)
1818
end
1919

20-
return map(m->TimeSimulation(m;time_arr=linspace(0.0,100.0,201)),simulations)
20+
return map(m->TimeSimulation(m;time_arr=LinRange(0.0,100.0,201)),simulations)
2121
end
2222

2323
function plot_box_size_convergence(simulations;times = [20,30,40,50,60,70])
2424

25-
colors = linspace(RGB(0.6,1,0.6),RGB(0,0.4,0),length(times))
25+
colors = LinRange(RGB(0.6,1,0.6),RGB(0,0.4,0),length(times))
2626

2727
plot(xlab="Time (t)",ylab="Response")
2828
for s in eachindex(simulations)

docs/src/example/gaussian_impulse/gaussian_impulse.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using Plots
33
pyplot()
44

55
# A very sharp sinc function (dicrete delta)
6-
w_arr = collect(linspace(0.0,1.0,1000))
6+
w_arr = collect(LinRange(0.0,1.0,1000))
77
x0 = 10.;
88
t_arr = 4.:0.01:22;
99
fs = reshape([exp(im*w*x0) for w in w_arr],length(w_arr),1)

docs/src/example/hankel_convergence/convergence.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ using MultipleScattering
22
using Plots; pyplot()
33

44
function hankel_order_convergence(m=[0,1,2,3,4,5,6,7,8,9,10], volfrac = 0.1,
5-
radius = 1.0, maxtime = 40.0, k_arr=collect(linspace(0.01,1.0,100)) )
5+
radius = 1.0, maxtime = 40.0, k_arr=collect(LinRange(0.01,1.0,100)) )
66

77
listener_position = [-10.0,0.0]
88
shape = TimeOfFlight(listener_position,maxtime)
99

1010
seed = MersenneTwister(1).seed
1111
particles = random_particles(volfrac, radius, shape; seed = seed)
1212

13-
simulations = Vector{FrequencySimulation{Float64}}(length(m))
13+
simulations = Vector{FrequencySimulation{Float64}}(undef,length(m))
1414

1515
for i = eachindex(m)
1616
simulations[i] = FrequencySimulation(particles, k_arr; seed=seed, hankel_order=m[i])
@@ -20,10 +20,10 @@ function hankel_order_convergence(m=[0,1,2,3,4,5,6,7,8,9,10], volfrac = 0.1,
2020
end
2121

2222
function plot_hankel_order_convergence(simulations)
23-
responses = Vector{Vector{Complex{Float64}}}(length(simulations))
24-
m = Vector{Int64}(length(simulations))
23+
responses = Vector{Vector{Complex{Float64}}}(undef,length(simulations))
24+
m = Vector{Int64}(undef,length(simulations))
2525

26-
labels = Matrix{String}(1,0)
26+
# labels = Matrix{String}(undef,1,0)
2727
for i = eachindex(simulations)
2828
responses[i] = reshape(simulations[i].response, size(simulations[i].response,1))
2929
m[i] = simulations[i].hankel_order
@@ -33,9 +33,9 @@ function plot_hankel_order_convergence(simulations)
3333
error = [r .- responses[end] for r in responses[1:end-1]]
3434
integrated_error = norm.(error).*map(m->((m.k_arr[end]-m.k_arr[1])/length(m.k_arr)),simulations[1:end-1])
3535

36-
colors = reshape(linspace(RGB(0.6,1,0.6),RGB(0,0.4,0),length(m)),1,length(m))
37-
realcolors = reshape(linspace(RGB(0.6,0.6,1),RGB(0,0,0.4),length(m)),1,length(m))
38-
imagcolors = reshape(linspace(RGB(1,0.6,0.6),RGB(0.4,0,0),length(m)),1,length(m))
36+
colors = reshape(LinRange(RGB(0.6,1,0.6),RGB(0,0.4,0),length(m)),1,length(m))
37+
realcolors = reshape(LinRange(RGB(0.6,0.6,1),RGB(0,0,0.4),length(m)),1,length(m))
38+
imagcolors = reshape(LinRange(RGB(1,0.6,0.6),RGB(0.4,0,0),length(m)),1,length(m))
3939

4040
absvec(v) = abs.(v)
4141
plot(

docs/src/example/lens/lens.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function run_lens(;
99
innertime=34.0
1010
)
1111

12-
k_arr=collect(linspace(0.01,2.0,100))
12+
k_arr=collect(LinRange(0.01,2.0,100))
1313

1414
# Generate particles which are at most outertime away from our listener
1515
outershape = TimeOfFlight(listener_position,outertime)

docs/src/example/moments/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ plot_shape = annotate!([(listener_position[1], listener_position[2] -2., "Receiv
2727
## Calculate the moments of the scattered wave
2828
The code below chooses a random (uniform distribution) configuration of particles inside `shape` and calculates the received signal at `listener` for wavenumbers `k_arr`,
2929
```julia
30-
k_arr = collect(linspace(0.01,1.0,100))
30+
k_arr = collect(LinRange(0.01,1.0,100))
3131
simulation = FrequencySimulation(volfrac,radius,k_arr; shape=shape, listener_positions = listener, seed = 1)
3232
plot(simulation)
3333
```

docs/src/example/moments/moments.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ function moments_example()
88
volfrac = 0.01
99
radius = 1.0
1010
num_particles = 10
11-
k_arr = collect(linspace(0.01,1.0,100))
11+
k_arr = collect(LinRange(0.01,1.0,100))
1212

1313
# region to place the particles
1414
shape = Rectangle(volfrac, radius, num_particles)
1515
# Holder for our simulations
16-
simulations = Vector{FrequencySimulation{Float64}}(10)
16+
simulations = Vector{FrequencySimulation{Float64}}(undef,10)
1717
for i=1:10
1818
simulations[i] = FrequencySimulation(volfrac,radius,k_arr;seed=[0x7f5def91, 0x82255da3, 0xc5e461c7, UInt32(i)])
1919
end

docs/src/example/near_surface_backscattering/backscattering.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ widths = [round(s.shape.topright[1]) for s in simulations]
4848
listener_position = simulations[1].listener_positions[:]
4949
times = 2*(widths .- listener_position[1]) # time if takes for an incident plane wave to reach the furthest particles and then return to the receiver
5050

51-
# [Int.(round.(linspace(1,length(num_particles)-1,5))); length(num_particles)]
51+
# [Int.(round.(LinRange(1,length(num_particles)-1,5))); length(num_particles)]
5252
plot()
5353
for i in [1,3,6,9,12,13]
5454
plot!(time_simulations[i],label="$(num_particles[i]) particles"

docs/src/example/random_particles/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ which wavenumbers (k) to evaluate at
1515
```julia
1616
volfrac = 0.01
1717
radius = 1.0
18-
k_arr = collect(linspace(0.01,1.0,100))
18+
k_arr = collect(LinRange(0.01,1.0,100))
1919
simulation = FrequencySimulation(volfrac,radius,k_arr)
2020
```
2121

docs/src/example/random_particles/random_particles.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using MultipleScattering
1010
# which wavenumbers (k) to evaluate at
1111
volfrac = 0.01
1212
radius = 1.0
13-
k_arr = collect(linspace(0.01,1.0,100))
13+
k_arr = collect(LinRange(0.01,1.0,100))
1414
simulation = FrequencySimulation(volfrac,radius,k_arr)
1515

1616
# We use the `Plots` package to plot both the response at the listener position

docs/src/example/random_particles_in_circle/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The code [particles_in_circle.jl](particles_in_circle.jl) compares the scattered
55
```julia
66
using MultipleScattering
77

8-
k_arr = collect(linspace(0.1,1.0,10))
8+
k_arr = collect(LinRange(0.1,1.0,10))
99

1010
# You can also pick your own shape, an generate random particles inside it
1111
# with a certain radius ands volume fraction

docs/src/example/random_particles_in_circle/particles_in_circle.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using MultipleScattering
22

3-
k_arr = collect(linspace(0.1,1.0,10))
3+
k_arr = collect(LinRange(0.1,1.0,10))
44

55
# You can also pick your own shape, an generate random particles inside it
66
# with a certain radius ands volume fraction

docs/src/example/time_response_single_particle/time_response_single_particle.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@ using MultipleScattering
22
using Plots
33

44
function run_time_response_single_particle(;
5-
k_arr = collect(linspace(0.001,50.0,2000)),
5+
k_arr = collect(LinRange(0.001,50.0,2000)),
66
particle_x = 100.0
77
)
88

9-
# Vector of one particle
10-
particles = Vector{Particle{Float64}}(1)
119
# Radius of particle
1210
radius = 1.0
1311
# Phase speed inside the particle
1412
c = 0.5 + 0.0*im
1513
# Density of particle
1614
ρ = 10.0
17-
# Define positions and radii
18-
particles[1] = Particle{Float64}([particle_x,0.0],radius,c,ρ)
15+
# Define positions and radii of particle
16+
particles = [Particle{Float64}([particle_x,0.0],radius,c,ρ)]
1917
# Simulate a single particle in frequency space
2018
freq_simulation = FrequencySimulation(particles,k_arr; hankel_order = 10)
2119
# Convert the frequency simulation into a time simulation

docs/src/example/transducers/transducer_scatterer.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ a2_host = Acoustic(1.0,1.0 + 0.0im,2)
88
# Create a finite transducer by adding point sources
99
n = 100
1010
amp = 10.0/n
11-
transducer = sum(point_source(a2_host, [-2.,y], amp) for y in linspace(-2.,2.,n))
11+
transducer = sum(point_source(a2_host, [-2.,y], amp) for y in LinRange(-2.,2.,n))
1212
sim = FrequencySimulation(a2_host, transducer)
1313

1414
using Plots; gr()
@@ -22,7 +22,7 @@ timres = frequency_to_time(simres);
2222

2323
plot(timres, 10., seriestype=:contour)
2424

25-
ts = filter(t -> t<16, transpose(timres.t))
25+
ts = filter(t -> t<16, timres.t)
2626
anim = @animate for t in ts
2727
plot(timres,t,seriestype=:contour, clim=(0.,1.25), c=:balance)
2828
end

example/plot/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bottomleft = [-25.,-max_width]
2727
bounds = Rectangle(bottomleft,topright)
2828
result = run(simulation, bounds, [ω]; res=100)
2929

30-
ts = linspace(0.,2pi/ω,30)
30+
ts = LinRange(0.,2pi/ω,30)
3131

3232
maxc = round(10*maximum(real.(field(result))))/10
3333
minc = round(10*minimum(real.(field(result))))/10

example/random_particles/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ x = [-10.,0.]
3333
host_medium = Acoustic(1.0, 1.0, 2)
3434
source = plane_source(host_medium; position = x, direction = [1.0,0.])
3535

36-
ωs = linspace(0.01,1.0,100)
36+
ωs = LinRange(0.01,1.0,100)
3737

3838
simulation = FrequencySimulation(host_medium, particles, source)
3939
result = run(simulation, x, ωs)

example/random_particles/random_particles.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ x = [-10.,0.]
2525
host_medium = Acoustic(2; ρ=1.0, c=1.0)
2626
source = plane_source(host_medium; position = x, direction = [1.0,0.])
2727

28-
ωs = linspace(0.01,1.0,100)
28+
ωs = LinRange(0.01,1.0,100)
2929

3030
simulation = FrequencySimulation(host_medium, particles, source)
3131
result = run(simulation, x, ωs)

example/random_particles_in_circle/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Resulting in the figures:
5050
If we compare the response measured at the listener `[-10., 0.]`, they should be very similar:
5151
```julia
5252
# define angular frequency range
53-
ωs = collect(linspace(0.1,1.0,10))
53+
ωs = collect(LinRange(0.1,1.0,10))
5454
result = run(simulation, x, ωs)
5555
big_result = run(big_particle_simulation, x, ωs)
5656

example/random_particles_in_circle/particles_in_circle.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ source = plane_source(host_medium; position = x, direction = [1.0,0.])
2323
simulation = FrequencySimulation(host_medium, particles, source)
2424

2525
# define angular frequency range
26-
ωs = collect(linspace(0.1,1.0,10))
26+
ωs = collect(LinRange(0.1,1.0,10))
2727
result = run(simulation, x, ωs)
2828

2929
big_particle = Particle(particle_medium, circle)
@@ -52,7 +52,7 @@ savefig("plot_field.png")
5252

5353
pyplot(leg=false, size=(1.8*height,height))
5454

55-
ωs = collect(linspace(0.1,1.0,10))
55+
ωs = collect(LinRange(0.1,1.0,10))
5656
result = run(simulation, x, ωs)
5757
big_result = run(big_particle_simulation, x, ωs)
5858

src/MultipleScattering.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ export t_matrix, get_t_matrices
2525
export scattering_matrix
2626

2727
import SpecialFunctions: besselj, hankelh1
28+
import Printf: @printf
2829

2930
import StaticArrays: SVector
3031

3132
import OffsetArrays: OffsetArray
3233

33-
using RecipesBase
34+
using Random, LinearAlgebra, RecipesBase, Statistics
3435
using ProgressMeter
3536

3637
# Generic machinery common to all physical models

src/physics/acoustics/acoustics.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ include("boundary_data.jl")
3737
function basis_function(medium::Acoustic{T,2}, ω::T) where {T}
3838
return function acoustic_basis_function(m::Integer, x::SVector{2,T})
3939
r = norm(x)
40-
θ = atan2(x[2],x[1])
40+
θ = atan(x[2],x[1])
4141
k = ω/medium.c
4242
hankelh1(m,k*r)*exp(im*θ*m)
4343
end
@@ -47,7 +47,7 @@ end
4747
function basis_function(p::Particle{T,2,Acoustic{T,2}}, ω::T) where {T}
4848
return function acoustic_basis_function(m::Integer, x::SVector{2,T})
4949
r = norm(x)
50-
θ = atan2(x[2],x[1])
50+
θ = atan(x[2],x[1])
5151
k = ω/p.medium.c
5252
besselj(m,k*r)*exp(im*θ*m)
5353
end

src/physics/acoustics/boundary_data.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ function boundary_data(shape::Shape{T,2}, inside_medium::Acoustic{T,2}, outside_
2121
in_pressure = run(sim, inside_points, ωs; kws...)
2222

2323
fields = (in2_results.field - in1_results.field)/(dr * in_m.ρ)
24-
in_displace = FrequencySimulationResult(fields, inside_points, RowVector(ωs))
24+
in_displace = FrequencySimulationResult(fields, inside_points, Vector(ωs))
2525

2626
# results from just outside particles
2727
out1_results = run(sim, outside1_points, ωs; kws...)
2828
out2_results = run(sim, outside2_points, ωs; kws...)
2929
out_pressure = run(sim, outside_points, ωs; kws...)
3030

3131
fields = (out2_results.field - out1_results.field)/(dr * out_m.ρ)
32-
out_displace = FrequencySimulationResult(fields, outside_points, RowVector(ωs))
32+
out_displace = FrequencySimulationResult(fields, outside_points, Vector(ωs))
3333

3434
return ([in_pressure, out_pressure], [in_displace, out_displace])
3535
end

src/physics/acoustics/source.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function besselj_field(source::Source{Acoustic{T,2},T}, medium::Acoustic{T,2}, c
55
centre = SVector{2,T}(centre)
66

77
return (x,ω) -> sum(
8-
source.coef(n,centre,ω)*besselj(n,ω/medium.c*norm(x - centre))*exp(im*n*atan2(x[2] - centre[2],x[1] - centre[1]))
8+
source.coef(n,centre,ω)*besselj(n,ω/medium.c*norm(x - centre))*exp(im*n*atan(x[2] - centre[2],x[1] - centre[1]))
99
for n = -basis_order:basis_order)
1010

1111
end
@@ -15,7 +15,7 @@ end
1515
1616
Create 2D [`Acoustic`](@ref) point [`Source`](@ref) (zeroth Hankel function of first type)
1717
"""
18-
function point_source{T}(medium::Acoustic{T,2}, source_position, amplitude::Union{T,Complex{T}} = one(T))::Source{Acoustic{T,2},T}
18+
function point_source(medium::Acoustic{T,2}, source_position, amplitude::Union{T,Complex{T}} = one(T))::Source{Acoustic{T,2},T} where T <: AbstractFloat
1919

2020
# Convert to SVector for efficiency and consistency
2121
source_position = SVector{2,T}(source_position)
@@ -25,7 +25,7 @@ function point_source{T}(medium::Acoustic{T,2}, source_position, amplitude::Unio
2525
function source_coef(n,centre,ω)
2626
k = ω/medium.c
2727
r = norm(centre - source_position)
28-
θ = atan2(centre[2]-source_position[2], centre[1]-source_position[1])
28+
θ = atan(centre[2]-source_position[2], centre[1]-source_position[1])
2929
# using Graf's addition theorem
3030
return (amplitude*im)/4 * hankelh1(-n,k*r) * exp(-im*n*θ)
3131
end
@@ -61,7 +61,7 @@ function plane_source(medium::Acoustic{T,2}, position, direction = SVector(one(T
6161

6262
function source_coef(n,centre,ω)
6363
# Jacobi-Anger expansion
64-
θ = atan2(direction[2],direction[1])
64+
θ = atan(direction[2],direction[1])
6565
source_field(centre,ω) * exp(im * n *(T(pi)/2 - θ))
6666
end
6767

src/plot/plot.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ include("plot_field.jl")
1515
@series begin
1616
label --> "$apply x=$(simres.x[x_ind])"
1717
xlabel --> xlab
18-
(transpose(getfield(simres, 3)[ω_indices]), apply_field)
18+
(getfield(simres, 3)[ω_indices], apply_field)
1919
end
2020
end
2121
end

src/plot/plot_field.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Plot the result in space (across all x) for a specific angular frequency
22
@recipe function plot(simres::FrequencySimulationResult, ω::AbstractFloat;
33
time = 0.0, # does not except "t" as name of variable..
4-
x_indices = indices(simres.x,1),
4+
x_indices = axes(simres.x,1),
55
ω_index = findmin(abs.(getfield(simres, 3) .- ω))[2],
66
field_apply = real, seriestype = :surface)
77

@@ -35,7 +35,7 @@ end
3535

3636
# Plot the result in space (across all x) for a specific angular frequency
3737
@recipe function plot(timres::TimeSimulationResult, t::AbstractFloat;
38-
x_indices = indices(timres.x,1),
38+
x_indices = axes(timres.x,1),
3939
t_index = findmin(abs.(getfield(timres, 3) .- t))[2],
4040
field_apply = real, seriestype = :surface)
4141

0 commit comments

Comments
 (0)