Granular.jl

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

commit 6040ef7fcf67910a07df699fe383a365fde93796
parent 4947424934abc67010b9a1e184b5464373f1f94a
Author: Anders Damsgaard <andersd@riseup.net>
Date:   Fri,  3 Nov 2017 15:09:36 -0400

update periodicity check to reflect change in datatypes.jl

Diffstat:
Msrc/contact_search.jl | 23+++++++++++++++++++----
Mtest/periodic-boundaries.jl | 20++++++++++++++++++++
2 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/src/contact_search.jl b/src/contact_search.jl @@ -72,6 +72,21 @@ Perform an O(n^2) all-to-all contact search between all grains in the """ function findContactsAllToAll!(simulation::Simulation) + if simulation.ocean.bc_west > 1 || + simulation.ocean.bc_east > 1 || + simulation.ocean.bc_north > 1 || + simulation.ocean.bc_south > 1 + error("Ocean boundary conditions to not work with all-to-all contact " * + "search") + end + if simulation.atmosphere.bc_west > 1 || + simulation.atmosphere.bc_east > 1 || + simulation.atmosphere.bc_north > 1 || + simulation.atmosphere.bc_south > 1 + error("Atmopshere boundary conditions to not work with all-to-all " * + "contact search") + end + @inbounds for i = 1:length(simulation.grains) # Check contacts with other grains @@ -121,18 +136,18 @@ function findContactsInGrid!(simulation::Simulation, grid::Any) # around if they are periodic if i < 1 || i > nx || j < 1 || j > ny - if i < 1 && grid.bc_west == 1 # periodic -x + if i < 1 && grid.bc_west == 2 # periodic -x distance_modifier[1] = grid.xq[end] - grid.xq[1] i_corrected = nx - elseif i > nx && grid.bc_east == 1 # periodic +x + elseif i > nx && grid.bc_east == 2 # periodic +x distance_modifier[1] = -(grid.xq[end] - grid.xq[1]) i_corrected = 1 end - if j < 1 && grid.bc_south == 1 # periodic -y + if j < 1 && grid.bc_south == 2 # periodic -y distance_modifier[2] = grid.yq[end] - grid.yq[1] j_corrected = ny - elseif j > ny && grid.bc_north == 1 # periodic +y + elseif j > ny && grid.bc_north == 2 # periodic +y distance_modifier[2] = -(grid.yq[end] - grid.yq[1]) j_corrected = 1 end diff --git a/test/periodic-boundaries.jl b/test/periodic-boundaries.jl @@ -102,3 +102,23 @@ Test.@test_throws ErrorException Granular.setGridBoundaryConditions!(ocean, Test.@test_throws ErrorException Granular.setGridBoundaryConditions!(ocean, "asdf") + + +info("Testing granular interaction across periodic boundaries") +sim = Granular.createSimulation() +sim.ocean = Granular.createRegularOceanGrid([5, 5, 2], [1., 1., 1.]) +Granular.setGridBoundaryConditions!(sim.ocean, "periodic") +Granular.addGrainCylindrical!(sim, [0.1, 0.5], 0.11, 0.1, verbose=false) +Granular.addGrainCylindrical!(sim, [0.9, 0.5], 0.11, 0.1, verbose=false) + +# there should be an error if all-to-all contact search is used +Test.@test_throws ErrorException Granular.findContacts!(sim) +Test.@test_throws ErrorException Granular.findContacts!(sim, method="all to all") +Test.@test_throws ErrorException Granular.findContactsAllToAll!(sim) + +Granular.sortGrainsInGrid!(sim, sim.ocean, verbose=false) +Granular.findContacts!(sim, method="ocean grid") +Test.@test 2 == sim.grains[1].contacts[1] +Test.@test 1 == sim.grains[1].n_contacts +Test.@test 1 == sim.grains[2].n_contacts +