Granular.jl

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

commit 9bfdd56e07dad1fbf93a3d33799a97ff6a4f85e2
parent 3d0915f604fa11d221d503a7c9129e7419e08d33
Author: Anders Damsgaard <andersd@riseup.net>
Date:   Thu,  8 Jun 2017 13:50:35 -0400

fix monte-carlo sampling procedure, add more tests with partially full cells

Diffstat:
Msrc/grid.jl | 9++++++++-
Mtest/grid.jl | 25+++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/src/grid.jl b/src/grid.jl @@ -395,7 +395,6 @@ function findEmptyPositionInGridCell(simulation::Simulation, n_iter::Int = 10, seed::Int = 1, verbose::Bool = false) - Base.Random.srand(i*j*seed) overlap_found = false i_iter = 0 pos = [NaN NaN] @@ -404,11 +403,16 @@ function findEmptyPositionInGridCell(simulation::Simulation, for i_iter=1:n_iter + overlap_found = false + Base.Random.srand(i*j*seed*i_iter) # generate random candidate position x_tilde = Base.Random.rand() y_tilde = Base.Random.rand() pos = [bilinearInterpolation(grid.xq, x_tilde, y_tilde, i, j) bilinearInterpolation(grid.yq, x_tilde, y_tilde, i, j)] + if verbose + info("trying poisition $pos in cell $i,$j") + end # search for contacts in current and eight neighboring cells for i_neighbor_corr=[0 -1 1] @@ -431,6 +435,9 @@ function findEmptyPositionInGridCell(simulation::Simulation, (simulation.ice_floes[icefloe_idx].contact_radius + r) if overlap < 0. + if verbose + info("overlap with $icefloe_idx in cell $i,$j") + end overlap_found = true break end diff --git a/test/grid.jl b/test/grid.jl @@ -196,6 +196,7 @@ atmosphere.v[:, :, 1, 1] = 0.0 info("Testing findEmptyPositionInGridCell") +info("# Insert into empty cell") sim = SeaIce.createSimulation() sim.ocean = SeaIce.createRegularOceanGrid([4, 4, 2], [4., 4., 2.]) SeaIce.sortIceFloesInGrid!(sim, sim.ocean, verbose=verbose) @@ -204,6 +205,28 @@ pos = SeaIce.findEmptyPositionInGridCell(sim, sim.ocean, 1, 1, 0.5, @test pos != false @test SeaIce.isPointInCell(sim.ocean, 1, 1, pos) == true +info("# Insert into cell with one other ice floe") +sim = SeaIce.createSimulation() +sim.ocean = SeaIce.createRegularOceanGrid([4, 4, 2], [4., 4., 2.]) +SeaIce.addIceFloeCylindrical(sim, [.25, .25], .25, 1., verbose=verbose) +SeaIce.sortIceFloesInGrid!(sim, sim.ocean, verbose=verbose) +pos = SeaIce.findEmptyPositionInGridCell(sim, sim.ocean, 1, 1, .25, + verbose=true) +@test pos != false +@test SeaIce.isPointInCell(sim.ocean, 1, 1, pos) == true + +info("# Insert into cell with two other ice floes") +sim = SeaIce.createSimulation() +sim.ocean = SeaIce.createRegularOceanGrid([4, 4, 2], [4., 4., 2.]) +SeaIce.addIceFloeCylindrical(sim, [.25, .25], .25, 1., verbose=verbose) +SeaIce.addIceFloeCylindrical(sim, [.75, .75], .25, 1., verbose=verbose) +SeaIce.sortIceFloesInGrid!(sim, sim.ocean, verbose=verbose) +pos = SeaIce.findEmptyPositionInGridCell(sim, sim.ocean, 1, 1, .25, + verbose=true) +@test pos != false +@test SeaIce.isPointInCell(sim.ocean, 1, 1, pos) == true + +info("# Insert into full cell") sim = SeaIce.createSimulation() sim.ocean = SeaIce.createRegularOceanGrid([4, 4, 2], [4., 4., 2.]) SeaIce.addIceFloeCylindrical(sim, [.5, .5], 1., 1., verbose=verbose) @@ -215,6 +238,7 @@ pos = SeaIce.findEmptyPositionInGridCell(sim, sim.ocean, 1, 1, 0.5, verbose=false) @test pos == false +info("# Insert into empty cell") sim = SeaIce.createSimulation() sim.ocean = SeaIce.createRegularOceanGrid([4, 4, 2], [4., 4., 2.]) SeaIce.sortIceFloesInGrid!(sim, sim.ocean, verbose=verbose) @@ -223,6 +247,7 @@ pos = SeaIce.findEmptyPositionInGridCell(sim, sim.ocean, 2, 2, 0.5, @test pos != false @test SeaIce.isPointInCell(sim.ocean, 2, 2, pos) == true +info("# Insert into full cell") sim = SeaIce.createSimulation() sim.ocean = SeaIce.createRegularOceanGrid([4, 4, 2], [4., 4., 2.]) SeaIce.addIceFloeCylindrical(sim, [1.5, 1.5], 1., 1., verbose=verbose)