Granular.jl

Julia package for granular dynamics simulation
git clone git://src.adamsgaard.dk/Granular.jl
Log | Files | Refs | README | LICENSE

commit e8dac6694d087e8d0f174260b7c674897978b320
parent 2e147d502dba2dd18246f4c0d7f92c40a235631d
Author: Anders Damsgaard <andersd@riseup.net>
Date:   Mon,  2 Apr 2018 15:19:14 -0400

Specify uninitialized arrays with keyword `undef` as per Julia 0.7

Diffstat:
Msrc/atmosphere.jl | 18+++++++++---------
Msrc/grid.jl | 18+++++++++---------
Msrc/ocean.jl | 16++++++++--------
Mtest/grain.jl | 4++--
Mtest/wall.jl | 4++--
5 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/src/atmosphere.jl b/src/atmosphere.jl @@ -19,7 +19,7 @@ function createEmptyAtmosphere() zeros(1,1,1,1), zeros(1,1,1,1), - Array{Vector{Int}}(1, 1), + Array{Vector{Int}}(undef, 1, 1), zeros(1,1), 1, 1, 1, 1, @@ -42,8 +42,8 @@ function interpolateAtmosphereVelocitiesToCorners(u_in::Array{Float64, 4}, end nx, ny, nz, nt = size(u_in) - #u = Array{Float64}(nx+1, ny+1, nz, nt) - #v = Array{Float64}(nx+1, ny+1, nz, nt) + #u = Array{Float64}(undef, nx+1, ny+1, nz, nt) + #v = Array{Float64}(undef, nx+1, ny+1, nz, nt) u = zeros(nx+1, ny+1, nz, nt) v = zeros(nx+1, ny+1, nz, nt) for i=1:nx @@ -164,7 +164,7 @@ function createRegularAtmosphereGrid(n::Vector{Int}, xh, yh, zl, u, v, - Array{Array{Int, 1}}(size(xh, 1), size(xh, 2)), + Array{Array{Int, 1}}(undef, size(xh, 1), size(xh, 2)), zeros(size(xh)), bc_west, bc_south, bc_east, bc_north, false, @@ -182,11 +182,11 @@ function addAtmosphereDrag!(simulation::Simulation) end u, v = interpolateAtmosphereState(simulation.atmosphere, simulation.time) - uv_interp = Vector{Float64}(2) - sw = Vector{Float64}(2) - se = Vector{Float64}(2) - ne = Vector{Float64}(2) - nw = Vector{Float64}(2) + uv_interp = Vector{Float64}(undef, 2) + sw = Vector{Float64}(undef, 2) + se = Vector{Float64}(undef, 2) + ne = Vector{Float64}(undef, 2) + nw = Vector{Float64}(undef, 2) for grain in simulation.grains diff --git a/src/grid.jl b/src/grid.jl @@ -86,10 +86,10 @@ function curl(grid::Any, j::Int, k::Int, it::Int, - sw::Vector{Float64} = Vector{Float64}(2), - se::Vector{Float64} = Vector{Float64}(2), - ne::Vector{Float64} = Vector{Float64}(2), - nw::Vector{Float64} = Vector{Float64}(2)) + sw::Vector{Float64} = Vector{Float64}(undef, 2), + se::Vector{Float64} = Vector{Float64}(undef, 2), + ne::Vector{Float64} = Vector{Float64}(undef, 2), + nw::Vector{Float64} = Vector{Float64}(undef, 2)) #sw, se, ne, nw = getCellCornerCoordinates(grid.xq, grid.yq, i, j) sw[1] = grid.xq[ i, j] @@ -120,7 +120,7 @@ function sortGrainsInGrid!(simulation::Simulation, grid::Any; verbose=true) if simulation.time_iteration == 0 grid.grain_list = - Array{Array{Int, 1}}(size(grid.xh, 1), size(grid.xh, 2)) + Array{Array{Int, 1}}(undef, size(grid.xh, 1), size(grid.xh, 2)) for i=1:size(grid.xh, 1) for j=1:size(grid.xh, 2) @@ -135,10 +135,10 @@ function sortGrainsInGrid!(simulation::Simulation, grid::Any; verbose=true) end end - sw = Vector{Float64}(2) - se = Vector{Float64}(2) - ne = Vector{Float64}(2) - nw = Vector{Float64}(2) + sw = Vector{Float64}(undef, 2) + se = Vector{Float64}(undef, 2) + ne = Vector{Float64}(undef, 2) + nw = Vector{Float64}(undef, 2) for idx=1:length(simulation.grains) diff --git a/src/ocean.jl b/src/ocean.jl @@ -34,7 +34,7 @@ function createEmptyOcean() zeros(1,1,1,1), zeros(1,1,1,1), zeros(1,1,1,1), - Array{Array{Int, 1}}(1, 1), + Array{Array{Int, 1}}(undef, 1, 1), zeros(1,1), 1, 1, 1, 1, false, [0.,0.,0.], [1.,1.,1.], [1,1,1], [1.,1.,1.]) @@ -89,7 +89,7 @@ function readOceanNetCDF(velocity_file::String, grid_file::String; v, h, e, - Array{Array{Int, 1}}(size(xh, 1), size(xh, 2)), + Array{Array{Int, 1}}(undef, size(xh, 1), size(xh, 2)), zeros(size(xh)), 1, 1, 1, 1, @@ -320,7 +320,7 @@ function createRegularOceanGrid(n::Vector{Int}, xh, yh, zl, zi, u, v, h, e, - Array{Array{Int, 1}}(size(xh, 1), size(xh, 2)), + Array{Array{Int, 1}}(undef, size(xh, 1), size(xh, 2)), zeros(size(xh)), bc_west, bc_south, bc_east, bc_north, true, origo, L, n, dx) @@ -337,11 +337,11 @@ function addOceanDrag!(simulation::Simulation) end u, v, h, e = interpolateOceanState(simulation.ocean, simulation.time) - uv_interp = Vector{Float64}(2) - sw = Vector{Float64}(2) - se = Vector{Float64}(2) - ne = Vector{Float64}(2) - nw = Vector{Float64}(2) + uv_interp = Vector{Float64}(undef, 2) + sw = Vector{Float64}(undef, 2) + se = Vector{Float64}(undef, 2) + ne = Vector{Float64}(undef, 2) + nw = Vector{Float64}(undef, 2) for grain in simulation.grains diff --git a/test/grain.jl b/test/grain.jl @@ -30,13 +30,13 @@ Granular.addGrainCylindrical!(sim, [ 0., 0.], 10., 1., verbose=false) Granular.addGrainCylindrical!(sim, [ 0., 0.], 10., 1., verbose=false) Granular.compareGrains(sim.grains[1], sim.grains[2]) -gnuplot = true +global gnuplot = true try run(`gnuplot --version`) catch return_signal if isa(return_signal, Base.UVError) Compat.@warn "Skipping plotting routines: Could not launch gnuplot process" - gnuplot = false + global gnuplot = false end end if gnuplot diff --git a/test/wall.jl b/test/wall.jl @@ -413,10 +413,10 @@ sim = Granular.createSimulation() Granular.regularPacking!(sim, [5, 5], 1.0, 2.0) Granular.fitGridToGrains!(sim, sim.ocean) Granular.setGridBoundaryConditions!(sim.ocean, "impermeable") -y_max_init = 0. +global y_max_init = 0. for grain in sim.grains if y_max_init < grain.lin_pos[2] + grain.contact_radius - y_max_init = grain.lin_pos[2] + grain.contact_radius + global y_max_init = grain.lin_pos[2] + grain.contact_radius end end Granular.addWallLinearFrictionless!(sim, [0., 1.], y_max_init,