tadd tests for regular packing generation, add docstring to grid.jl - Granular.… | |
git clone git://src.adamsgaard.dk/Granular.jl | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit a9fb9ff582212dcc6d22f83851987d97bda76f4f | |
parent 6942faf25139645b324b47eea7b671e7dde7aba6 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Mon, 6 Nov 2017 14:59:16 -0500 | |
add tests for regular packing generation, add docstring to grid.jl | |
Diffstat: | |
M src/grid.jl | 8 +++++++- | |
M src/packing.jl | 49 +++++++++++++++++++++++++++++… | |
M test/packing.jl | 32 +++++++++++++++++++++++++++++… | |
3 files changed, 86 insertions(+), 3 deletions(-) | |
--- | |
diff --git a/src/grid.jl b/src/grid.jl | |
t@@ -799,9 +799,15 @@ export fitGridToGrains! | |
Fit the ocean or atmosphere grid for a simulation to the current grains and | |
their positions. | |
+ | |
+# Arguments | |
+* `simulation::Simulation`: simulation object to manipulate. | |
+* `grid::Any`: Ocean or Atmosphere grid to manipulate. | |
+* `padding::Real`: optional padding around edges [m]. | |
+* `verbose::Bool`: show grid information when function completes. | |
""" | |
function fitGridToGrains!(simulation::Simulation, grid::Any; | |
- padding::Float64 = 0., verbose::Bool = true) | |
+ padding::Real=0., verbose::Bool=true) | |
if typeof(grid) != Ocean && typeof(grid) != Atmosphere | |
error("grid must be of Ocean or Atmosphere type") | |
diff --git a/src/packing.jl b/src/packing.jl | |
t@@ -2,9 +2,56 @@ | |
export regularPacking! | |
""" | |
+ | |
+ regularPacking!(simulation, n, r_min, r_max[, padding_factor, | |
+ size_distribution, size_distribution_parameter]) | |
+ | |
+Create a grid-based regular packing with grain numbers along each axis specifi… | |
+by the `n` vector. | |
+ | |
+# Arguments | |
+* `simulation::Simulation`: simulation object where the grains are inserted, | |
+ preferably not containing prior grains. | |
+* `n::Vector{Integer}`: 2-element vector determining number of grains along the | |
+ `x` and `y` axes. | |
+* `r_min::Real`: minimum desired grain radius. | |
+* `r_max::Real`: maximum desired grain radius. | |
+* `padding_factor::Real`: percentage-wise padding around each grain to allow f… | |
+ random perturbations to grain position. | |
+* `size_distribution::String`: grain-size distribution to sample. Valid values | |
+ are "powerlaw" and "uniform". | |
+* `size_distribution_parameter::Real`: parameter to pass to the grain-size | |
+ distribution generating function. | |
+* `seed::Integer`: seed value to the pseudo-random number generator. | |
""" | |
function regularPacking!(simulation::Simulation, | |
- ) | |
+ n::Vector{Int}, | |
+ r_min::Real, | |
+ r_max::Real; | |
+ padding_factor::Real=.1, | |
+ size_distribution::String="powerlaw", | |
+ size_distribution_parameter::Real=-1.8, | |
+ seed::Integer=1) | |
+ | |
+ r_rand = 0. | |
+ h = .5 # disc tickness | |
+ dx = r_max*2.*(1. + padding_factor) # cell size | |
+ srand(seed) | |
+ | |
+ for iy in 1:n[2] | |
+ for ix in 1:n[1] | |
+ | |
+ if size_distribution == "powerlaw" | |
+ r_rand = Granular.randpower(1, size_distribution_parameter, | |
+ r_min, r_max) | |
+ elseif size_distribution == "uniform" | |
+ r_rand = rand()*(r_max - r_min) + r_min | |
+ end | |
+ | |
+ addGrainCylindrical!(simulation, [ix*dx - .5*dx, iy*dx - .5*dx], | |
+ r_rand, h, verbose=false) | |
+ end | |
+ end | |
end | |
diff --git a/test/packing.jl b/test/packing.jl | |
t@@ -2,6 +2,36 @@ | |
verbose = true | |
-#info("#### $(basename(@__FILE__)) ####") | |
+info("#### $(basename(@__FILE__)) ####") | |
+info("Testing regular packing generation (power law GSD)") | |
+sim = Granular.createSimulation() | |
+Granular.regularPacking!(sim, [2, 2], 1., 1., size_distribution="powerlaw") | |
+Test.@test 4 == length(sim.grains) | |
+for grain in sim.grains | |
+ Test.@test grain.contact_radius ≈ 1. | |
+end | |
+sim = Granular.createSimulation() | |
+Granular.regularPacking!(sim, [10, 10], 1., 10., size_distribution="powerlaw") | |
+Test.@test 100 == length(sim.grains) | |
+for grain in sim.grains | |
+ Test.@test grain.contact_radius >= 1. | |
+ Test.@test grain.contact_radius <= 10. | |
+end | |
+ | |
+info("Testing regular packing generation (uniform GSD)") | |
+sim = Granular.createSimulation() | |
+Granular.regularPacking!(sim, [2, 2], 1., 1., size_distribution="uniform") | |
+Test.@test 4 == length(sim.grains) | |
+for grain in sim.grains | |
+ Test.@test grain.contact_radius ≈ 1. | |
+end | |
+ | |
+sim = Granular.createSimulation() | |
+Granular.regularPacking!(sim, [10, 10], 1., 10., size_distribution="uniform") | |
+Test.@test 100 == length(sim.grains) | |
+for grain in sim.grains | |
+ Test.@test grain.contact_radius >= 1. | |
+ Test.@test grain.contact_radius <= 10. | |
+end |