tadd several measures for reducing memory footprint - 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 aaacaf68ad468bebb4cb7024f63d193fa7d3b5f9
 (DIR) parent f51076d53050ade8a00bc1216257be807a5df907
 (HTM) Author: Anders Damsgaard <andersd@riseup.net>
       Date:   Fri, 23 Jun 2017 15:04:10 -0400
       
       add several measures for reducing memory footprint
       
       Diffstat:
         M src/atmosphere.jl                   |      16 ++++++++++------
         M src/grid.jl                         |      48 ++++++++++++++++++-------------
         M src/icefloe.jl                      |      53 ++++++++++++++++++++++++++++++
         M src/io.jl                           |       4 ++++
         M src/ocean.jl                        |      14 ++++++++------
       
       5 files changed, 103 insertions(+), 32 deletions(-)
       ---
 (DIR) diff --git a/src/atmosphere.jl b/src/atmosphere.jl
       t@@ -163,12 +163,16 @@ function addAtmosphereDrag!(simulation::Simulation)
                         """)
                end
        
       -        u_local = bilinearInterpolation(u, x_tilde, y_tilde, i, j, k, 1)
       -        v_local = bilinearInterpolation(v, x_tilde, y_tilde, i, j, k, 1)
       -        vel_curl = curl(simulation.atmosphere, x_tilde, y_tilde, i, j, k, 1)
       -
       -        applyAtmosphereDragToIceFloe!(ice_floe, u_local, v_local)
       -        applyAtmosphereVorticityToIceFloe!(ice_floe, vel_curl)
       +        applyAtmosphereDragToIceFloe!(ice_floe,
       +                                      bilinearInterpolation(u,
       +                                                            x_tilde, y_tilde,
       +                                                            i, j, k, 1),
       +                                      bilinearInterpolation(v,
       +                                                            x_tilde, y_tilde,
       +                                                            i, j, k, 1))
       +        applyAtmosphereVorticityToIceFloe!(ice_floe,
       +                                           curl(simulation.atmosphere,
       +                                                x_tilde, y_tilde, i, j, k, 1))
            end
        end
        
 (DIR) diff --git a/src/grid.jl b/src/grid.jl
       t@@ -21,9 +21,9 @@ function bilinearInterpolation(field::Array{Float64, 4},
                                       k::Int,
                                       it::Int)
        
       -    if x_tilde < 0. || x_tilde > 1. || y_tilde < 0. || y_tilde > 1.
       -        error("relative coordinates outside bounds ($(x_tilde), $(y_tilde))")
       -    end
       +    #if x_tilde < 0. || x_tilde > 1. || y_tilde < 0. || y_tilde > 1.
       +        #error("relative coordinates outside bounds ($(x_tilde), $(y_tilde))")
       +    #end
        
            return (field[i+1, j+1, k, it]*x_tilde +
                    field[i, j+1, k, it]*(1. - x_tilde))*y_tilde +
       t@@ -86,12 +86,20 @@ Find ice-floe positions in grid, based on their center positions.
        """
        function sortIceFloesInGrid!(simulation::Simulation, grid::Any; verbose=false)
        
       -    grid.ice_floe_list =
       -        Array{Array{Int, 1}}(size(grid.xh, 1), size(grid.xh, 2))
       -    #fill!(grid.ice_floe_list, Int[])
       -    for i=1:size(grid.xh, 1)
       -        for j=1:size(grid.xh, 2)
       -            grid.ice_floe_list[i, j] = Int[]
       +    if simulation.time_iteration == 0
       +        grid.ice_floe_list =
       +            Array{Array{Int, 1}}(size(grid.xh, 1), size(grid.xh, 2))
       +
       +        for i=1:size(grid.xh, 1)
       +            for j=1:size(grid.xh, 2)
       +                grid.ice_floe_list[i, j] = Int[]
       +            end
       +        end
       +    else
       +        for i=1:size(grid.xh, 1)
       +            for j=1:size(grid.xh, 2)
       +                empty!(grid.ice_floe_list[i, j])
       +            end
                end
            end
        
       t@@ -146,7 +154,8 @@ function sortIceFloesInGrid!(simulation::Simulation, grid::Any; verbose=false)
        
                    if !found
                        i, j = findCellContainingPoint(grid,
       -                                               simulation.ice_floes[idx].lin_pos)
       +                                               simulation.ice_floes[idx].
       +                                               lin_pos)
                    end
        
                    # remove ice floe if it is outside of the grid
       t@@ -211,8 +220,7 @@ function getNonDimensionalCellCoordinates(grid::Any, i::Int, j::Int,
                                                  point::Array{float, 1})
        
            sw, se, ne, nw = getCellCornerCoordinates(grid.xq, grid.yq, i, j)
       -    x_tilde, y_tilde = conformalQuadrilateralCoordinates(sw, se, ne, nw, point)
       -    return [x_tilde, y_tilde]
       +    return conformalQuadrilateralCoordinates(sw, se, ne, nw, point)
        end
        
        export isPointInCell
       t@@ -264,13 +272,13 @@ south-east corner, north-east corner, north-west corner).
        * `i::Int`: x-index of cell.
        * `j::Int`: y-index of cell.
        """
       -function getCellCornerCoordinates(xq::Array{Float64, 2}, yq::Array{Float64, 2},
       -                                  i::Int, j::Int)
       -    sw = [xq[  i,   j], yq[  i,   j]]
       -    se = [xq[i+1,   j], yq[i+1,   j]]
       -    ne = [xq[i+1, j+1], yq[i+1, j+1]]
       -    nw = [xq[  i, j+1], yq[  i, j+1]]
       -    return sw, se, ne, nw
       +@inline function getCellCornerCoordinates(xq::Array{Float64, 2}, 
       +                                          yq::Array{Float64, 2},
       +                                          i::Int, j::Int)
       +    return Float64[xq[  i,   j], yq[  i,   j]],
       +        Float64[xq[i+1,   j], yq[i+1,   j]],
       +        Float64[xq[i+1, j+1], yq[i+1, j+1]],
       +        Float64[xq[  i, j+1], yq[  i, j+1]]
        end
        
        export getCellCenterCoordinates
       t@@ -379,7 +387,7 @@ function conformalQuadrilateralCoordinates(A::Array{float, 1},
                      "alpha = $(alpha), beta = $(beta), gamma = $(gamma), ",
                      "delta = $(delta), epsilon = $(epsilon), kappa = $(kappa)")
            end
       -    return [x_tilde, y_tilde]
       +    return Float64[x_tilde, y_tilde]
        end
        
        export findEmptyPositionInGridCell
 (DIR) diff --git a/src/icefloe.jl b/src/icefloe.jl
       t@@ -317,6 +317,59 @@ function convertIceFloeDataToArrays(simulation::Simulation)
            return ifarr
        end
        
       +function deleteIceFloeArrays!(ifarr::IceFloeArrays)
       +    ifarr.density = 0
       +
       +    ifarr.thickness = 0
       +    ifarr.contact_radius = 0
       +    ifarr.areal_radius = 0
       +    ifarr.circumreference = 0
       +    ifarr.horizontal_surface_area = 0
       +    ifarr.side_surface_area = 0
       +    ifarr.volume = 0
       +    ifarr.mass = 0
       +    ifarr.moment_of_inertia = 0
       +
       +    ifarr.lin_pos = 0
       +    ifarr.lin_vel = 0
       +    ifarr.lin_acc = 0
       +    ifarr.force = 0
       +
       +    ifarr.ang_pos = 0
       +    ifarr.ang_vel = 0
       +    ifarr.ang_acc = 0
       +    ifarr.torque = 0
       +
       +    ifarr.fixed = 0
       +    ifarr.rotating = 0
       +    ifarr.enabled = 0
       +
       +    ifarr.contact_stiffness_normal = 0
       +    ifarr.contact_stiffness_tangential = 0
       +    ifarr.contact_viscosity_normal = 0
       +    ifarr.contact_viscosity_tangential = 0
       +    ifarr.contact_static_friction = 0
       +    ifarr.contact_dynamic_friction = 0
       +
       +    ifarr.youngs_modulus = 0
       +    ifarr.poissons_ratio = 0
       +    ifarr.tensile_strength = 0
       +    ifarr.compressive_strength_prefactor = 0
       +
       +    ifarr.ocean_drag_coeff_vert = 0
       +    ifarr.ocean_drag_coeff_horiz = 0
       +    ifarr.atmosphere_drag_coeff_vert = 0
       +    ifarr.atmosphere_drag_coeff_horiz = 0
       +
       +    ifarr.pressure = 0
       +    ifarr.n_contacts = 0
       +
       +    ifarr.granular_stress = 0
       +    ifarr.ocean_stress = 0
       +    ifarr.atmosphere_stress = 0
       +    gc()
       +end
       +
        export printIceFloeInfo
        """
            printIceFloeInfo(icefloe::IceFloeCylindrical)
 (DIR) diff --git a/src/io.jl b/src/io.jl
       t@@ -336,6 +336,10 @@ function writeIceFloeVTK(simulation::Simulation,
            WriteVTK.vtk_point_data(vtkfile, ifarr.atmosphere_stress,
                                    "Atmosphere stress [Pa]")
        
       +    deleteIceFloeArrays!(ifarr)
       +    ifarr = 0
       +    gc()
       +
            outfiles = WriteVTK.vtk_save(vtkfile)
            if verbose
                info("Output file: " * outfiles[1])
 (DIR) diff --git a/src/ocean.jl b/src/ocean.jl
       t@@ -274,12 +274,14 @@ function addOceanDrag!(simulation::Simulation)
                         """)
                end
        
       -        u_local = bilinearInterpolation(u, x_tilde, y_tilde, i, j, k, 1)
       -        v_local = bilinearInterpolation(v, x_tilde, y_tilde, i, j, k, 1)
       -        vel_curl = curl(simulation.ocean, x_tilde, y_tilde, i, j, k, 1)
       -
       -        applyOceanDragToIceFloe!(ice_floe, u_local, v_local)
       -        applyOceanVorticityToIceFloe!(ice_floe, vel_curl)
       +        applyOceanDragToIceFloe!(ice_floe,
       +                                 bilinearInterpolation(u, x_tilde, y_tilde,
       +                                                       i, j, k, 1),
       +                                 bilinearInterpolation(v, x_tilde, y_tilde,
       +                                                       i, j, k, 1))
       +        applyOceanVorticityToIceFloe!(ice_floe,
       +                                      curl(simulation.ocean, x_tilde, y_tilde,
       +                                           i, j, k, 1))
            end
        end