tdecrease memory allocation in grid-related functions - 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 452355e25ad6bd307882d6a60c0e2f1febfc5cb0
 (DIR) parent 3a15d9e39ecaeda0fe5433300bca2290d9af51a9
 (HTM) Author: Anders Damsgaard <andersd@riseup.net>
       Date:   Tue,  3 Oct 2017 12:09:52 -0400
       
       decrease memory allocation in grid-related functions
       
       Diffstat:
         M src/grid.jl                         |      49 ++++++++++++-------------------
         M src/packing.jl                      |       2 +-
       
       2 files changed, 20 insertions(+), 31 deletions(-)
       ---
 (DIR) diff --git a/src/grid.jl b/src/grid.jl
       t@@ -27,11 +27,9 @@ south-west (-x, -y)-facing corner.
        
            x_tilde_inv = 1. - x_tilde
        
       -    @views interp_val[1] = 
       +    @views interp_val .= 
            (field_x[i+1, j+1]*x_tilde + field_x[i, j+1]*x_tilde_inv)*y_tilde + 
       -    (field_x[i+1, j]*x_tilde + field_x[i, j]*x_tilde_inv)*(1. - y_tilde)
       -
       -    @views interp_val[2] = 
       +    (field_x[i+1, j]*x_tilde + field_x[i, j]*x_tilde_inv)*(1. - y_tilde),
            (field_y[i+1, j+1]*x_tilde + field_y[i, j+1]*x_tilde_inv)*y_tilde + 
            (field_y[i+1, j]*x_tilde + field_y[i, j]*x_tilde_inv)*(1.  - y_tilde)
        
       t@@ -53,13 +51,11 @@ end
        
            x_tilde_inv = 1. - x_tilde
        
       -    @views interp_val[1] = 
       +    @views interp_val .= 
            (field_x[i+1, j+1, k, it]*x_tilde + 
             field_x[i, j+1, k, it]*x_tilde_inv)*y_tilde + 
            (field_x[i+1, j, k, it]*x_tilde + 
       -     field_x[i, j, k, it]*x_tilde_inv)*(1. - y_tilde)
       -
       -    @views interp_val[2] = 
       +     field_x[i, j, k, it]*x_tilde_inv)*(1. - y_tilde),
            (field_y[i+1, j+1, k, it]*x_tilde + 
             field_y[i, j+1, k, it]*x_tilde_inv)*y_tilde + 
            (field_y[i+1, j, k, it]*x_tilde + 
       t@@ -285,22 +281,19 @@ The function uses either an area-based approach (`method = "Area"`), or a
        conformal mapping approach (`method = "Conformal"`).  The area-based approach is 
        more robust.  This function returns `true` or `false`.
        """
       -function isPointInCell(grid::Any, i::Int, j::Int, point::Vector{Float64},
       -                       sw::Vector{Float64} = Vector{Float64}(2),
       -                       se::Vector{Float64} = Vector{Float64}(2),
       -                       ne::Vector{Float64} = Vector{Float64}(2),
       -                       nw::Vector{Float64} = Vector{Float64}(2);
       -                       method::String="Conformal")
       +function isPointInCell(grid::Any, i::Int, j::Int,
       +                                 point::Vector{Float64},
       +                                 sw::Vector{Float64} = Vector{Float64}(2),
       +                                 se::Vector{Float64} = Vector{Float64}(2),
       +                                 ne::Vector{Float64} = Vector{Float64}(2),
       +                                 nw::Vector{Float64} = Vector{Float64}(2);
       +                                 method::String="Conformal")
        
            #sw, se, ne, nw = getCellCornerCoordinates(grid.xq, grid.yq, i, j)
       -    @views sw[1] = grid.xq[  i,   j]
       -    @views sw[2] = grid.yq[  i,   j]
       -    @views se[1] = grid.xq[i+1,   j]
       -    @views se[2] = grid.yq[i+1,   j]
       -    @views ne[1] = grid.xq[i+1, j+1]
       -    @views ne[2] = grid.yq[i+1, j+1]
       -    @views nw[1] = grid.xq[  i, j+1]
       -    @views nw[2] = grid.yq[  i, j+1]
       +    @views sw .= grid.xq[   i,   j], grid.yq[   i,   j]
       +    @views se .= grid.xq[ i+1,   j], grid.yq[ i+1,   j]
       +    @views ne .= grid.xq[ i+1, j+1], grid.yq[ i+1, j+1]
       +    @views nw .= grid.xq[   i, j+1], grid.yq[   i, j+1]
        
            if method == "Area"
                if areaOfQuadrilateral(sw, se, ne, nw) ≈
       t@@ -342,14 +335,10 @@ function isPointInGrid(grid::Any, point::Vector{Float64},
        
            #sw, se, ne, nw = getCellCornerCoordinates(grid.xq, grid.yq, i, j)
            nx, ny = size(grid.xq)
       -    @views sw[1] = grid.xq[  1,  1]
       -    @views sw[2] = grid.yq[  1,  1]
       -    @views se[1] = grid.xq[ nx,  1]
       -    @views se[2] = grid.yq[ nx,  1]
       -    @views ne[1] = grid.xq[ nx, ny]
       -    @views ne[2] = grid.yq[ nx, ny]
       -    @views nw[1] = grid.xq[  1, ny]
       -    @views nw[2] = grid.yq[  1, ny]
       +    @views sw .= grid.xq[  1,  1], grid.yq[  1,  1]
       +    @views se .= grid.xq[ nx,  1], grid.yq[ nx,  1]
       +    @views ne .= grid.xq[ nx, ny], grid.yq[ nx, ny]
       +    @views nw .= grid.xq[  1, ny], grid.yq[  1, ny]
        
            if method == "Area"
                if areaOfQuadrilateral(sw, se, ne, nw) ≈
 (DIR) diff --git a/src/packing.jl b/src/packing.jl
       t@@ -29,7 +29,7 @@ described by [Robert Bridson (2007)](http://www.cs.ubc.ca/~rbridson/docs/bridson
        
        """
        function poissonDiscSampling(simulation::Simulation;
       -                             ;radius_max::Real=.1,
       +                             radius_max::Real=.1,
                                     radius_min::Real=.1,
                                     sample_limit::Integer=30,
                                     max_padding_factor::Real=2.,