tpacking.jl - Granular.jl - Julia package for granular dynamics simulation
 (HTM) git clone git://src.adamsgaard.dk/Granular.jl
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       tpacking.jl (7005B)
       ---
            1 #!/usr/bin/env julia
            2 using Test
            3 import Granular
            4 
            5 verbose = false
            6 plot = false
            7 plot_packings=false
            8 
            9 @info "Testing regular packing generation (power law GSD)"
           10 sim = Granular.createSimulation()
           11 Granular.regularPacking!(sim, [2, 2], 1., 1., size_distribution="powerlaw")
           12 @test 4 == length(sim.grains)
           13 for grain in sim.grains
           14     @test grain.contact_radius ≈ 1.
           15 end
           16 
           17 sim = Granular.createSimulation()
           18 Granular.regularPacking!(sim, [10, 10], 1., 10., size_distribution="powerlaw")
           19 @test 100 == length(sim.grains)
           20 for grain in sim.grains
           21     @test grain.contact_radius >= 1.
           22     @test grain.contact_radius <= 10.
           23 end
           24 plot && Granular.plotGrains(sim, filetype="regular-powerlaw.png", show_figure=false)
           25 
           26 @info "Testing regular packing generation (uniform GSD)"
           27 sim = Granular.createSimulation()
           28 Granular.regularPacking!(sim, [2, 2], 1., 1., size_distribution="uniform")
           29 @test 4 == length(sim.grains)
           30 for grain in sim.grains
           31     @test grain.contact_radius ≈ 1.
           32 end
           33 
           34 sim = Granular.createSimulation()
           35 Granular.regularPacking!(sim, [10, 10], 1., 10., size_distribution="uniform")
           36 @test 100 == length(sim.grains)
           37 for grain in sim.grains
           38     @test grain.contact_radius >= 1.
           39     @test grain.contact_radius <= 10.
           40 end
           41 plot && Granular.plotGrains(sim, filetype="regular-uniform.png", show_figure=false)
           42 
           43 
           44 @info "Testing irregular (Poisson-disk) packing generation (monodisperse size)"
           45 sim = Granular.createSimulation("poisson1-monodisperse-nopadding")
           46 sim.ocean = Granular.createRegularOceanGrid([1, 1, 1], [1., 1., 1.])
           47 Granular.irregularPacking!(sim,
           48                            radius_max=.1,
           49                            radius_min=.1,
           50                            padding_factor=0.,
           51                            plot_during_packing=plot_packings,
           52                            verbose=verbose)
           53 @test length(sim.grains) > 23
           54 
           55 @info "Testing irregular (Poisson-disk) packing generation (wide PSD)"
           56 sim = Granular.createSimulation("poisson2-wide-nopadding")
           57 sim.ocean = Granular.createRegularOceanGrid([1, 1, 1], [1., 1., 1.])
           58 Granular.irregularPacking!(sim,
           59                            radius_max=.1,
           60                            radius_min=.005,
           61                            padding_factor=0.,
           62                            plot_during_packing=plot_packings,
           63                            verbose=verbose)
           64 @test length(sim.grains) > 280
           65 sim = Granular.createSimulation("poisson3-wide-padding")
           66 sim.ocean = Granular.createRegularOceanGrid([1, 1, 1], [1., 1., 1.])
           67 Granular.irregularPacking!(sim,
           68                            radius_max=.1,
           69                            radius_min=.005,
           70                            padding_factor=2.,
           71                            plot_during_packing=plot_packings,
           72                            verbose=verbose)
           73 @test length(sim.grains) > 280
           74 
           75 sim = Granular.createSimulation("poisson4-binary-search")
           76 sim.ocean = Granular.createRegularOceanGrid([1, 1, 1], [1., 1., 1.])
           77 Granular.irregularPacking!(sim,
           78                            radius_max=.1,
           79                            radius_min=.005,
           80                            binary_radius_search=true,
           81                            plot_during_packing=plot_packings,
           82                            verbose=verbose)
           83 @test length(sim.grains) > 280
           84 
           85 @info "Testing irregular packing with inactive boundaries"
           86 sim = Granular.createSimulation("poisson-inactive")
           87 sim.ocean = Granular.createRegularOceanGrid([5, 5, 1], [1., 1., 1.])
           88 Granular.setGridBoundaryConditions!(sim.ocean, "inactive", verbose=verbose)
           89 Granular.irregularPacking!(sim,
           90                            radius_max=.05,
           91                            radius_min=.1,
           92                            padding_factor=0.,
           93                            plot_during_packing=plot_packings,
           94                            verbose=verbose)
           95 Granular.findContacts!(sim, method="ocean grid")
           96 plot && Granular.plotGrains(sim, filetype="poisson-inactive.png", show_figure=false)
           97 for grain in sim.grains
           98     @test grain.n_contacts == 0
           99 end
          100 
          101 @info "Testing irregular packing with periodic boundaries"
          102 sim = Granular.createSimulation("poisson-periodic")
          103 sim.ocean = Granular.createRegularOceanGrid([5, 5, 1], [1., 1., 1.])
          104 Granular.setGridBoundaryConditions!(sim.ocean, "periodic", verbose=verbose)
          105 Granular.irregularPacking!(sim,
          106                            radius_max=.05,
          107                            radius_min=.1,
          108                            padding_factor=0.,
          109                            plot_during_packing=plot_packings,
          110                            verbose=verbose)
          111 plot && Granular.plotGrains(sim, filetype="poisson-periodic.png", show_figure=false)
          112 Granular.findContacts!(sim, method="ocean grid")
          113 for grain in sim.grains
          114     @test grain.n_contacts == 0
          115 end
          116 
          117 
          118 @info "Testing raster-based mapping algorithm"
          119 sim = Granular.createSimulation("raster-packing1")
          120 sim.ocean = Granular.createRegularOceanGrid([1, 1, 1], [1., 1., 1.])
          121 Granular.addGrainCylindrical!(sim, [0.5, 0.5], 0.4, 1.0)
          122 occupied = Granular.rasterMap(sim, 0.08)
          123 occupied_ans = Array{Bool}([
          124 0 0 0 0 0 0 0 0 0 0 0 0;
          125 0 0 0 1 1 1 1 1 1 0 0 0;
          126 0 0 1 1 1 1 1 1 1 1 1 0;
          127 0 1 1 1 1 1 1 1 1 1 1 0;
          128 0 1 1 1 1 1 1 1 1 1 1 1;
          129 0 1 1 1 1 1 1 1 1 1 1 1;
          130 0 1 1 1 1 1 1 1 1 1 1 1;
          131 0 1 1 1 1 1 1 1 1 1 1 1;
          132 0 1 1 1 1 1 1 1 1 1 1 0;
          133 0 0 1 1 1 1 1 1 1 1 1 0;
          134 0 0 1 1 1 1 1 1 1 1 0 0;
          135 0 0 0 0 1 1 1 1 0 0 0 0])
          136 @test occupied == occupied_ans
          137 Granular.addGrainCylindrical!(sim, [0.03, 0.03], 0.02, 1.0)
          138 occupied = Granular.rasterMap(sim, 0.08)
          139 occupied_ans = Array{Bool}([
          140 1 0 0 0 0 0 0 0 0 0 0 0;
          141 0 0 0 1 1 1 1 1 1 0 0 0;
          142 0 0 1 1 1 1 1 1 1 1 1 0;
          143 0 1 1 1 1 1 1 1 1 1 1 0;
          144 0 1 1 1 1 1 1 1 1 1 1 1;
          145 0 1 1 1 1 1 1 1 1 1 1 1;
          146 0 1 1 1 1 1 1 1 1 1 1 1;
          147 0 1 1 1 1 1 1 1 1 1 1 1;
          148 0 1 1 1 1 1 1 1 1 1 1 0;
          149 0 0 1 1 1 1 1 1 1 1 1 0;
          150 0 0 1 1 1 1 1 1 1 1 0 0;
          151 0 0 0 0 1 1 1 1 0 0 0 0])
          152 @test occupied == occupied_ans
          153 sim_init = deepcopy(sim)
          154 plot && Granular.plotGrains(sim, filetype="rastermap.png", show_figure=false)
          155 
          156 @info "Testing raster-based mapping algorithm (power law GSD)"
          157 sim = deepcopy(sim_init)
          158 np_init = length(sim.grains)
          159 Granular.rasterPacking!(sim, 0.02, 0.04, verbose=verbose)
          160 @test np_init < length(sim.grains)
          161 plot && Granular.plotGrains(sim, filetype="powerlaw.png", show_figure=false)
          162 
          163 @info "Testing raster-based mapping algorithm (uniform GSD)"
          164 sim = deepcopy(sim_init)
          165 np_init = length(sim.grains)
          166 Granular.rasterPacking!(sim, 0.02, 0.04, size_distribution="uniform",
          167                         verbose=verbose)
          168 @test np_init < length(sim.grains)
          169 plot && Granular.plotGrains(sim, filetype="uniform.png", show_figure=false)
          170 
          171 @info "Tesing square packing"
          172 sim = Granular.createSimulation()
          173 Granular.regularPacking!(sim, [5,6], 1.0, 1.0, tiling="square",
          174                         padding_factor=0.0)
          175 @test length(sim.grains) == 5*6
          176 plot && Granular.plotGrains(sim, filetype="square.png", show_figure=false)
          177 
          178 @info "Tesing triangular packing"
          179 sim = Granular.createSimulation()
          180 Granular.regularPacking!(sim, [6,6], 1.0, 1.0, tiling="triangular",
          181                         padding_factor=0.0)
          182 @test length(sim.grains) == 6*6
          183 plot && Granular.plotGrains(sim, filetype="triangular.png", show_figure=false)