Granular.jl

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

commit dafb5876273163ab2718cbcd4e8e256534e7a4c3
parent dc28eeb14147dfb1e066f1679ef96eaed901660e
Author: Anders Damsgaard <andersd@riseup.net>
Date:   Fri,  5 Jan 2018 10:57:41 -0500

Add `origo` vector to regular grids for handling non-zero grid origins

Diffstat:
Msrc/atmosphere.jl | 4++--
Msrc/datatypes.jl | 14++++++++------
Msrc/grid.jl | 4++--
Msrc/ocean.jl | 6+++---
Mtest/memory-management.jl | 2+-
5 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/src/atmosphere.jl b/src/atmosphere.jl @@ -23,7 +23,7 @@ function createEmptyAtmosphere() false, - false, [1.,1.,1.], [1,1,1], [1.,1.,1.]) + false, [0.,0.,0.], [1.,1.,1.], [1,1,1], [1.,1.,1.]) end export interpolateAtmosphereVelocitiesToCorners @@ -141,7 +141,7 @@ function createRegularAtmosphereGrid(n::Vector{Int}, Array{Array{Int, 1}}(size(xh, 1), size(xh, 2)), bc_west, bc_south, bc_east, bc_north, false, - true, L, n, dx) + true, origo, L, n, dx) end export addAtmosphereDrag! diff --git a/src/datatypes.jl b/src/datatypes.jl @@ -242,9 +242,10 @@ mutable struct Ocean regular_grid::Bool # Grid size when regular_grid == true - L::Vector{Float64} # Grid length - n::Vector{Integer} # Cell count - dx::Vector{Float64} # Cell size + origo::Vector{Float64} # Grid origo + L::Vector{Float64} # Grid length + n::Vector{Integer} # Cell count + dx::Vector{Float64} # Cell size end #= @@ -326,9 +327,10 @@ mutable struct Atmosphere regular_grid::Bool # Grid size when regular_grid == true - L::Vector{Float64} # Grid length - n::Vector{Integer} # Cell count - dx::Vector{Float64} # Cell size + origo::Vector{Float64} # Grid origo + L::Vector{Float64} # Grid length + n::Vector{Integer} # Cell count + dx::Vector{Float64} # Cell size end # Top-level simulation type diff --git a/src/grid.jl b/src/grid.jl @@ -164,7 +164,7 @@ function sortGrainsInGrid!(simulation::Simulation, grid::Any; verbose=true) else if grid.regular_grid - i, j = Int.(floor.(simulation.grains[idx].lin_pos + i, j = Int.(floor.((simulation.grains[idx].lin_pos - grid.origo) ./ grid.dx[1:2])) + [1,1] else @@ -299,7 +299,7 @@ function isPointInCell(grid::Any, i::Int, j::Int, method::String="Conformal") if grid.regular_grid - if [i,j] == Int.(floor.(point ./ grid.dx[1:2])) + [1,1] + if [i,j] == Int.(floor.((point - grid.origo) ./ grid.dx[1:2])) + [1,1] return true else return false diff --git a/src/ocean.jl b/src/ocean.jl @@ -21,7 +21,7 @@ function createEmptyOcean() zeros(1,1,1,1), Array{Array{Int, 1}}(1, 1), 1, 1, 1, 1, - false, [1.,1.,1.], [1,1,1], [1.,1.,1.]) + false, [0.,0.,0.], [1.,1.,1.], [1,1,1], [1.,1.,1.]) end export readOceanNetCDF @@ -69,7 +69,7 @@ function readOceanNetCDF(velocity_file::String, grid_file::String; Array{Array{Int, 1}}(size(xh, 1), size(xh, 2)), 1, 1, 1, 1, - false, [1.,1.,1.], [1,1,1], [1.,1.,1.] + false, [0.,0.,0.], [1.,1.,1.], [1,1,1], [1.,1.,1.] ) return ocean end @@ -257,7 +257,7 @@ function createRegularOceanGrid(n::Vector{Int}, u, v, h, e, Array{Array{Int, 1}}(size(xh, 1), size(xh, 2)), bc_west, bc_south, bc_east, bc_north, - true, L, n, dx) + true, origo, L, n, dx) end export addOceanDrag! diff --git a/test/memory-management.jl b/test/memory-management.jl @@ -6,7 +6,7 @@ info("Testing memory footprint of Granular types") sim = Granular.createSimulation() empty_sim_size = 104 -empty_sim_size_recursive = 752 +empty_sim_size_recursive = 816 @test sizeof(sim) == empty_sim_size @test Base.summarysize(sim) == empty_sim_size_recursive