tadd functions to set or add to a constant body force per grain - 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
       ---
 (DIR) commit 46353905835603c8e1d78ce7fcb33976c59f7dc1
 (DIR) parent dd52011a929bd3c3921c26b1545e4c9e07cb8942
 (HTM) Author: Anders Damsgaard <andersd@riseup.net>
       Date:   Mon,  6 Nov 2017 20:00:09 -0500
       
       add functions to set or add to a constant body force per grain
       
       Diffstat:
         M examples/shear.jl                   |       6 ++++++
         M src/datatypes.jl                    |       1 +
         M src/grain.jl                        |      30 ++++++++++++++++++++++++++++++
         M src/simulation.jl                   |       2 +-
         M test/grain.jl                       |       7 +++++++
       
       5 files changed, 45 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/examples/shear.jl b/examples/shear.jl
       t@@ -21,6 +21,12 @@ sim.ocean.v[:, :, 1, 1] = -5.0
        Granular.setGridBoundaryConditions!(sim.ocean, "impermeable", "north south")
        Granular.setGridBoundaryConditions!(sim.ocean, "periodic", "east west")
        
       +# Add gravitational acceleration to all grains
       +g = [0., -9.8]
       +for grain in sim.grains
       +    Granular.addBodyForce!(grain, grain.mass*g)
       +end
       +
        # Automatically set the computational time step based on grain sizes and
        # properties
        Granular.setTimeStep!(sim)
 (DIR) diff --git a/src/datatypes.jl b/src/datatypes.jl
       t@@ -20,6 +20,7 @@ mutable struct GrainCylindrical
            lin_vel::Vector{Float64}
            lin_acc::Vector{Float64}
            force::Vector{Float64}
       +    external_body_force::Vector{Float64}
        
            # Angular kinematic degrees of freedom for vertical rotation around center
            ang_pos::Float64
 (DIR) diff --git a/src/grain.jl b/src/grain.jl
       t@@ -220,6 +220,7 @@ function addGrainCylindrical!(simulation::Simulation,
                                         lin_vel,
                                         lin_acc,
                                         force,
       +                                 [0., 0.], # external_body_force
        
                                         ang_pos,
                                         ang_vel,
       t@@ -596,6 +597,34 @@ function totalGrainKineticRotationalEnergy(simulation::Simulation)
            return E_sum
        end
        
       +export addBodyForce!
       +"""
       +    setBodyForce!(grain, force)
       +
       +Add to the value of the external body force on a grain.
       +
       +# Arguments
       +* `grain::GrainCylindrical`: the grain to set the body force for.
       +* `force::Vector{Float64}`: a vector of force [N]
       +"""
       +function addBodyForce!(grain::GrainCylindrical, force::Vector{Float64})
       +    grain.external_body_force += force
       +end
       +
       +export setBodyForce!
       +"""
       +    setBodyForce!(grain, force)
       +
       +Set the value of the external body force on a grain.
       +
       +# Arguments
       +* `grain::GrainCylindrical`: the grain to set the body force for.
       +* `force::Vector{Float64}`: a vector of force [N]
       +"""
       +function setBodyForce!(grain::GrainCylindrical, force::Vector{Float64})
       +    grain.external_body_force = force
       +end
       +
        export compareGrains
        """
            compareGrains(if1::GrainCylindrical, if2::GrainCylindrical)
       t@@ -621,6 +650,7 @@ function compareGrains(if1::GrainCylindrical, if2::GrainCylindrical)
            Test.@test if1.lin_vel ≈ if2.lin_vel
            Test.@test if1.lin_acc ≈ if2.lin_acc
            Test.@test if1.force ≈ if2.force
       +    Test.@test if1.external_body_force ≈ if2.external_body_force
        
            Test.@test if1.ang_pos ≈ if2.ang_pos
            Test.@test if1.ang_vel ≈ if2.ang_vel
 (DIR) diff --git a/src/simulation.jl b/src/simulation.jl
       t@@ -229,7 +229,7 @@ export zeroForcesAndTorques!
        "Sets the `force` and `torque` values of all grains to zero."
        function zeroForcesAndTorques!(simulation::Simulation)
            for grain in simulation.grains
       -        fill!(grain.force, 0.)
       +        grain.force = grain.external_body_force
                grain.torque = 0.
                grain.pressure = 0.
            end
 (DIR) diff --git a/test/grain.jl b/test/grain.jl
       t@@ -42,3 +42,10 @@ if typeof(Pkg.installed("PyPlot")) == VersionNumber
        else
            Test.@test_throws ErrorException Granular.plotGrainSizeDistribution(sim)
        end
       +
       +sim = Granular.createSimulation(id="test")
       +Granular.addGrainCylindrical!(sim, [ 0., 0.], 10., 1., verbose=false)
       +Granular.setBodyForce!(sim.grains[1], [1., 2.])
       +Test.@test sim.grains[1].external_body_force ≈ [1., 2.]
       +Granular.addBodyForce!(sim.grains[1], [1., 2.])
       +Test.@test sim.grains[1].external_body_force ≈ [2., 4.]