Granular.jl

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

commit e9251cfbec42e68b3bba195c3629726ff62a1170
parent 4ed62a69d63596911dba86daa7272127ba54ab2d
Author: Anders Damsgaard <andersd@riseup.net>
Date:   Mon, 19 Jun 2017 11:45:59 -0400

skip atmosphere grid sorting when the atmosphere grid geometry is identical to the ocean grid

Diffstat:
Msrc/atmosphere.jl | 7+++++--
Msrc/datatypes.jl | 3+++
Msrc/grid.jl | 14++++++++++++++
Msrc/simulation.jl | 8+++++++-
Mtest/grid.jl | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 84 insertions(+), 3 deletions(-)

diff --git a/src/atmosphere.jl b/src/atmosphere.jl @@ -15,7 +15,9 @@ function createEmptyAtmosphere() zeros(1,1,1,1), zeros(1,1,1,1), - Array{Array{Int, 1}}(1, 1)) + Array{Array{Int, 1}}(1, 1), + + false) end export interpolateAtmosphereVelocitiesToCorners @@ -124,7 +126,8 @@ function createRegularAtmosphereGrid(n::Array{Int, 1}, xh, yh, zl, u, v, - Array{Array{Int, 1}}(size(xh, 1), size(xh, 2))) + Array{Array{Int, 1}}(size(xh, 1), size(xh, 2)), + false) end export addAtmosphereDrag! diff --git a/src/datatypes.jl b/src/datatypes.jl @@ -247,6 +247,9 @@ type Atmosphere v::Array{Float64, 4} ice_floe_list::Array{Array{Int, 1}, 2} + + # If true the grid positions are identical to the ocean grid + collocated_with_ocean_grid::Bool end # Top-level simulation type diff --git a/src/grid.jl b/src/grid.jl @@ -470,3 +470,17 @@ function findEmptyPositionInGridCell(simulation::Simulation, return false end end + +""" +Copy ice floe related information from ocean to atmosphere grid. This is useful +when the two grids are of identical geometry, meaning only only one sorting +phase is necessary. +""" +function copyGridSortingInfo!(ocean::Ocean, atmosphere::Atmosphere, + icefloes::Array{IceFloeCylindrical, 1}) + + for icefloe in icefloes + icefloe.atmosphere_grid_pos = deepcopy(icefloe.ocean_grid_pos) + end + atmosphere.ice_floe_list = deepcopy(ocean.ice_floe_list) +end diff --git a/src/simulation.jl b/src/simulation.jl @@ -118,7 +118,8 @@ function run!(simulation::Simulation; zeroForcesAndTorques!(simulation) - if typeof(simulation.atmosphere.input_file) != Bool + if typeof(simulation.atmosphere.input_file) != Bool && + !simulation.atmosphere.collocated_with_ocean_grid sortIceFloesInGrid!(simulation, simulation.atmosphere) end @@ -126,6 +127,11 @@ function run!(simulation::Simulation; sortIceFloesInGrid!(simulation, simulation.ocean) findContacts!(simulation, method="ocean grid") + if simulation.atmosphere.collocated_with_ocean_grid + copyGridSortingInfo!(simulation.ocean, simulation.atmosphere, + simulation.ice_floes) + end + elseif typeof(simulation.atmosphere.input_file) != Bool findContacts!(simulation, method="atmosphere grid") diff --git a/test/grid.jl b/test/grid.jl @@ -258,3 +258,58 @@ SeaIce.sortIceFloesInGrid!(sim, sim.ocean, verbose=verbose) pos = SeaIce.findEmptyPositionInGridCell(sim, sim.ocean, 2, 2, 0.5, verbose=false) @test pos == false + +info("Test default sorting with ocean/atmosphere grids") +sim = SeaIce.createSimulation() +sim.ocean = SeaIce.createRegularOceanGrid([4, 4, 2], [4., 4., 2.]) +sim.atmosphere = SeaIce.createRegularAtmosphereGrid([4, 4, 2], [4., 4., 2.]) +SeaIce.addIceFloeCylindrical(sim, [0.5, 0.5], .1, 1., verbose=verbose) +SeaIce.addIceFloeCylindrical(sim, [0.7, 0.7], .1, 1., verbose=verbose) +SeaIce.addIceFloeCylindrical(sim, [2.6, 2.5], .1, 1., verbose=verbose) +SeaIce.sortIceFloesInGrid!(sim, sim.ocean, verbose=verbose) +SeaIce.setTimeStep!(sim) +SeaIce.setTotalTime!(sim, 1.0) +SeaIce.run!(sim, single_step=true, verbose=verbose) +@test sim.ice_floes[1].ocean_grid_pos == [1, 1] +@test sim.ice_floes[2].ocean_grid_pos == [1, 1] +@test sim.ice_floes[3].ocean_grid_pos == [3, 3] +@test sim.ocean.ice_floe_list[1, 1] == [1, 2] +@test sim.ocean.ice_floe_list[2, 2] == [] +@test sim.ocean.ice_floe_list[3, 3] == [3] +@test sim.ice_floes[1].atmosphere_grid_pos == [1, 1] +@test sim.ice_floes[2].atmosphere_grid_pos == [1, 1] +@test sim.ice_floes[3].atmosphere_grid_pos == [3, 3] +@test sim.atmosphere.ice_floe_list[1, 1] == [1, 2] +@test sim.atmosphere.ice_floe_list[2, 2] == [] +@test sim.atmosphere.ice_floe_list[3, 3] == [3] + +info("Test optimization when ocean/atmosphere grids are collocated") +sim = SeaIce.createSimulation() +sim.ocean = SeaIce.createRegularOceanGrid([4, 4, 2], [4., 4., 2.]) +sim.atmosphere = SeaIce.createRegularAtmosphereGrid([4, 4, 2], [4., 4., 2.]) +sim.atmosphere.collocated_with_ocean_grid = true +SeaIce.addIceFloeCylindrical(sim, [0.5, 0.5], .1, 1., verbose=verbose) +SeaIce.addIceFloeCylindrical(sim, [0.7, 0.7], .1, 1., verbose=verbose) +SeaIce.addIceFloeCylindrical(sim, [2.6, 2.5], .1, 1., verbose=verbose) +SeaIce.sortIceFloesInGrid!(sim, sim.ocean, verbose=verbose) +SeaIce.setTimeStep!(sim) +SeaIce.setTotalTime!(sim, 1.0) +SeaIce.run!(sim, single_step=true, verbose=verbose) +@test sim.ice_floes[1].ocean_grid_pos == [1, 1] +@test sim.ice_floes[2].ocean_grid_pos == [1, 1] +@test sim.ice_floes[3].ocean_grid_pos == [3, 3] +@test sim.ocean.ice_floe_list[1, 1] == [1, 2] +@test sim.ocean.ice_floe_list[2, 2] == [] +@test sim.ocean.ice_floe_list[3, 3] == [3] +@test sim.ice_floes[1].atmosphere_grid_pos == [1, 1] +@test sim.ice_floes[2].atmosphere_grid_pos == [1, 1] +@test sim.ice_floes[3].atmosphere_grid_pos == [3, 3] +@test sim.atmosphere.ice_floe_list[1, 1] == [1, 2] +@test sim.atmosphere.ice_floe_list[2, 2] == [] +@test sim.atmosphere.ice_floe_list[3, 3] == [3] + +info("Testing ocean drag") +sim = SeaIce.createSimulation() +sim.ocean.u[:,:,1,1] = 5. +SeaIce.addIceFloeCylindrical(sim, [2.5, 3.5], 1., 1., verbose=verbose) +SeaIce.addIceFloeCylindrical(sim, [2.6, 2.5], 1., 1., verbose=verbose)