Granular.jl

Julia package for granular dynamics simulation
git clone git://src.adamsgaard.dk/Granular.jl # fast
git clone https://src.adamsgaard.dk/Granular.jl.git # slow
Log | Files | Refs | README | LICENSE Back to index

two-grains.jl (1492B)


      1 #!/usr/bin/env julia
      2 import Granular
      3 
      4 # Create the simulation object which, among other things, will hold all
      5 # imformation on the simulated grains.  You can call this object whatever you
      6 # want, but in this documentation we will use the name `sim`.
      7 sim = Granular.createSimulation(id="two-grains")
      8 
      9 
     10 # Add a grain to the simulation object, having the position (0,0) in x-y space,
     11 # a radius of 0.1 m, and a thickness of 0.05 m.
     12 Granular.addGrainCylindrical!(sim, [0.0, 0.0], 0.1, 0.05)
     13 
     14 # Add a second grain, placed further down +x.
     15 Granular.addGrainCylindrical!(sim, [0.5, 0.0], 0.1, 0.05)
     16 
     17 # Set a velocity of 0.5 m/s along +x for the first grain, to make it bump into
     18 # the second grain.
     19 sim.grains[1].lin_vel[1:2] = [1.0, 0.0]
     20 
     21 # Before we can run the simulation, we need to specify the computational time
     22 # step, how often to produce output files for visualization, and for how long to
     23 # run the simulation in model time [s]:
     24 Granular.setTimeStep!(sim)
     25 Granular.setOutputFileInterval!(sim, 0.05)
     26 Granular.setTotalTime!(sim, 1.0)
     27 
     28 # Let's save the total kinetic energy before the simulation:
     29 E_kin_before = Granular.totalGrainKineticTranslationalEnergy(sim)
     30 
     31 # We can now run the simulation in a single call:
     32 Granular.run!(sim)
     33 
     34 # The kinetic energy after:
     35 E_kin_after = Granular.totalGrainKineticTranslationalEnergy(sim)
     36 
     37 # Report these values to console
     38 @info "Kinetic energy before: $E_kin_before J"
     39 @info "Kinetic energy after:  $E_kin_after J"
     40 
     41 Granular.render(sim, animation=true)