URI:
       tMerge pull request #7 from anders-dc/jld2 - Granular.jl - Julia package for granular dynamics simulation
  HTML git clone git://src.adamsgaard.dk/Granular.jl
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit e4960dd35846684e7a4d91b8b0281d5cd68d5c6b
   DIR parent d2b4ce560b58bcdec2edd337060fd84b82eab556
  HTML Author: Anders Damsgaard <anders@adamsgaard.dk>
       Date:   Wed, 12 Sep 2018 20:10:42 +0200
       
       Merge pull request #7 from anders-dc/jld2
       
       Switch from JLD to JLD2
       Diffstat:
         M REQUIRE                             |       1 +
         M docs/src/man/installation.md        |       4 +---
         M examples/shear.jl                   |       9 ++++-----
         M src/io.jl                           |      86 ++++++++++---------------------
         M src/simulation.jl                   |       8 ++++----
         D test/jld.jl                         |      29 -----------------------------
         A test/jld2.jl                        |      24 ++++++++++++++++++++++++
         M test/runtests.jl                    |       2 +-
       
       8 files changed, 61 insertions(+), 102 deletions(-)
       ---
   DIR diff --git a/REQUIRE b/REQUIRE
       t@@ -1,3 +1,4 @@
        julia 1.0
        WriteVTK
        Documenter
       +JLD2
   DIR diff --git a/docs/src/man/installation.md b/docs/src/man/installation.md
       t@@ -30,9 +30,7 @@ julia> Pkg.add("Granular")
        ```
        
        This will install the contents of this repository in the folder 
       -`~/.julia/v$(JULIA_VERSION)/Granular` and install its requirements.  The 
       -package [JLD](https://github.com/JuliaIO/JLD.jl) is used for model restarts and 
       -is recommended but not required, and is thus not automatically installed.
       +`~/.julia/v$(JULIA_VERSION)/Granular` and install its requirements.
        
        ## Development installation
        If desired, the current developmental version of the [Granular.jl Github 
   DIR diff --git a/examples/shear.jl b/examples/shear.jl
       t@@ -1,7 +1,7 @@
        #/usr/bin/env julia
        ENV["MPLBACKEND"] = "Agg"
        import Granular
       -import JLD
       +import JLD2
        import PyPlot
        
        ################################################################################
       t@@ -101,8 +101,7 @@ Granular.run!(sim)
        Granular.render(sim, trim=false)
        
        # Save the simulation state to disk in case we need to reuse the current state
       -# This step requires the JLD package (Pkg.add("JLD"))
       -#Granular.writeSimulation(sim)
       +Granular.writeSimulation(sim)
        
        # Also copy the simulation in memory, in case we want to loop over different
        # normal stresses below:
       t@@ -193,7 +192,7 @@ Granular.render(sim, trim=false)
        
        # Save the simulation state to disk in case we need to reuse the consolidated
        # state (e.g. different shear velocities below)
       -#Granular.writeSimulation(sim)
       +Granular.writeSimulation(sim)
        
        # Also copy the simulation in memory, in case we want to loop over different
        # normal stresses below:
       t@@ -274,7 +273,7 @@ end
        Granular.render(sim, trim=false)
        
        # Save the simulation state to disk in case we need to reuse the sheared state
       -#Granular.writeSimulation(sim)
       +Granular.writeSimulation(sim)
        
        # Plot time vs. shear stress and dilation
        PyPlot.subplot(211)
   DIR diff --git a/src/io.jl b/src/io.jl
       t@@ -1,22 +1,9 @@
        import WriteVTK
        import Pkg
        import Dates
       +import JLD2
        using DelimitedFiles
        
       -hasJLD = false
       -if VERSION < v"0.7.0-alpha"
       -    if typeof(Pkg.installed("JLD")) == VersionNumber
       -        import JLD
       -        hasJLD = true
       -    end
       -else
       -    import Pkg
       -    if haskey(Pkg.installed(), "JLD")
       -        import JLD
       -        hasJLD = true
       -    end
       -end
       -
        ## IO functions
        
        export writeSimulation
       t@@ -26,7 +13,7 @@ export writeSimulation
                                 folder::String=".",
                                 verbose::Bool=true)
        
       -Write all content from `Simulation` to disk in JDL format.  If the `filename` 
       +Write all content from `Simulation` to disk in JLD2 format.  If the `filename` 
        parameter is not specified, it will be saved to a subdirectory under the current 
        directory named after the simulation identifier `simulation.id`.
        """
       t@@ -34,24 +21,17 @@ function writeSimulation(simulation::Simulation;
                                 filename::String="",
                                 folder::String=".",
                                 verbose::Bool=true)
       -    if !hasJLD
       -        @warn "Package JLD not found. " *
       -            "Simulation save/read not supported. " * 
       -             "Please install JLD and its " *
       -             "requirements with `Pkg.add(\"JLD\")`."
       -    else
       -        if filename == ""
       -            folder = folder * "/" * simulation.id
       -            mkpath(folder)
       -            filename = string(folder, "/", simulation.id, ".",
       -                              simulation.file_number, ".jld")
       -        end
       +    if filename == ""
       +        folder = folder * "/" * simulation.id
       +        mkpath(folder)
       +        filename = string(folder, "/", simulation.id, ".",
       +                          simulation.file_number, ".jld2")
       +    end
        
       -        JLD.save(filename, "simulation", simulation)
       +    JLD2.@save(filename, simulation)
        
       -        if verbose
       -            @info "simulation written to $filename"
       -        end
       +    if verbose
       +        @info "simulation written to $filename"
            end
            nothing
        end
       t@@ -61,7 +41,7 @@ export readSimulation
            readSimulation(filename::String="";
                           verbose::Bool=true)
        
       -Return `Simulation` content read from disk using the JDL format.
       +Return `Simulation` content read from disk using the JLD2 format.
        
        # Arguments
        * `filename::String`: path to file on disk containing the simulation
       t@@ -70,18 +50,9 @@ Return `Simulation` content read from disk using the JDL format.
        """
        function readSimulation(filename::String;
                                 verbose::Bool=true)
       -    if !hasJLD
       -        @warn "Package JLD not found. " *
       -            "Simulation save/read not supported. " * 
       -             "Please install JLD and its " *
       -             "requirements with `Pkg.add(\"JLD\")`."
       -        nothing
       -    else
       -        return JLD.load(filename, "simulation")
       -        if verbose
       -            @info "Read simulation from $filename"
       -        end
       -    end
       +    simulation = createSimulation()
       +    JLD2.@load(filename, simulation)
       +    return simulation
        end
        """
            readSimulation(simulation::Simulation;
       t@@ -101,21 +72,16 @@ Read the simulation state from disk and return as new simulation object.
        function readSimulation(simulation::Simulation;
                                 step::Integer = -1,
                                 verbose::Bool = true)
       -    if !hasJLD
       -        @warn "Package JLD not found. Simulation save/read not supported. " * 
       -             "Please install JLD and its " *
       -             "requirements with `Pkg.add(\"JLD\")`."
       -        nothing
       -    else
       -        if step == -1
       -            step = readSimulationStatus(simulation)
       -        end
       -        filename = string(simulation.id, "/", simulation.id, ".$step.jld")
       -        if verbose
       -            @info "Read simulation from $filename"
       -        end
       -        return JLD.load(filename, "simulation")
       +    if step == -1
       +        step = readSimulationStatus(simulation)
       +    end
       +    filename = string(simulation.id, "/", simulation.id, ".$step.jld2")
       +    if verbose
       +        @info "Read simulation from $filename"
            end
       +    simulation = createSimulation()
       +    JLD2.@load(filename, simulation)
       +    return simulation
        end
        
        export writeSimulationStatus
       t@@ -165,7 +131,7 @@ function readSimulationStatus(simulation_id::String;
            if verbose
                @info "$simulation_id:\n" *
                     "  time:             $(data[1]) s\n" *
       -             "  complete:         $(data[2])%\n" *
       +             "  complete:         $(abs(data[2]))%\n" *
                     "  last output file: $(Int(round(data[3])))\n"
            end
            return Int(round(data[3]))
       t@@ -1225,7 +1191,7 @@ function removeSimulationFiles(simulation::Simulation; folder::String=".")
            run(`bash -c "rm -rf $(folder)/$(simulation.id).*.vtp"`)
            run(`bash -c "rm -rf $(folder)/$(simulation.id).*.vts"`)
            run(`bash -c "rm -rf $(folder)/$(simulation.id).status.txt"`)
       -    run(`bash -c "rm -rf $(folder)/$(simulation.id).*.jld"`)
       +    run(`bash -c "rm -rf $(folder)/$(simulation.id).*.jld2"`)
            run(`bash -c "rm -rf $(folder)/$(simulation.id).py"`)
            run(`bash -c "rm -rf $(folder)/$(simulation.id).avi"`)
            run(`bash -c "rm -rf $(folder)/$(simulation.id).*.png"`)
   DIR diff --git a/src/simulation.jl b/src/simulation.jl
       t@@ -61,7 +61,7 @@ export run!
                 show_file_output = true,
                 single_step = false,
                 temporal_integration_method = "Three-term Taylor"],
       -         write_jld = false)
       +         write_jld2 = false)
        
        Run the `simulation` through time until `simulation.time` equals or exceeds 
        `simulatim.time_total`.  This function requires that all grains are added to 
       t@@ -85,7 +85,7 @@ to disk.
            is increased accordingly.
        * `temporal_integration_method::String="Three-term Taylor"`: type of integration 
            method to use.  See `updateGrainKinematics` for details.
       -* `write_jld::Bool=false`: write simulation state to disk as JLD files (see 
       +* `write_jld2::Bool=false`: write simulation state to disk as JLD2 files (see 
            `Granular.writeSimulation(...)` whenever saving VTK output.
        """
        function run!(simulation::Simulation;
       t@@ -94,7 +94,7 @@ function run!(simulation::Simulation;
                      show_file_output::Bool=true,
                      single_step::Bool=false,
                      temporal_integration_method::String="Three-term Taylor",
       -              write_jld::Bool=false)
       +              write_jld2::Bool=false)
        
            if single_step && simulation.time >= simulation.time_total
                simulation.time_total += simulation.time_step
       t@@ -130,7 +130,7 @@ function run!(simulation::Simulation;
                    if show_file_output
                        println()
                    end
       -            if write_jld
       +            if write_jld2
                        writeSimulation(simulation, verbose=show_file_output)
                    end
                    writeVTK(simulation, verbose=show_file_output)
   DIR diff --git a/test/jld.jl b/test/jld.jl
       t@@ -1,29 +0,0 @@
       -#!/usr/bin/env julia
       -
       -@info "Determining if JLD is installed"
       -if Granular.hasJLD
       -    @info "JLD found, proceeding with JLD-specific tests"
       -
       -    @info "Writing simple simulation to JLD file"
       -    sim = Granular.createSimulation(id="test")
       -    Granular.addGrainCylindrical!(sim, [ 0., 0.], 10., 1., verbose=false)
       -    Granular.addGrainCylindrical!(sim, [18., 0.], 10., 1., verbose=false)
       -    sim.ocean = Granular.createRegularOceanGrid([10, 20, 5], [10., 25., 2.])  
       -    Granular.findContacts!(sim, method="all to all")
       -    Granular.writeVTK(sim, verbose=false)
       -
       -    Granular.writeSimulation(sim)
       -    Granular.writeSimulationStatus(sim)
       -
       -    @info "Reading from JLD file by specifying the input file name"
       -    sim2 = Granular.readSimulation("./test/test.1.jld")
       -    Granular.compareSimulations(sim, sim2)
       -
       -    @info "Reading and overwriting from JLD file by simulation id"
       -    sim3 = Granular.createSimulation("test")
       -    @test 1 == Granular.readSimulationStatus(sim3)
       -    sim3 = Granular.readSimulation(sim3)
       -    Granular.compareSimulations(sim, sim3)
       -
       -    rm("./test/test.1.jld")
       -end
   DIR diff --git a/test/jld2.jl b/test/jld2.jl
       t@@ -0,0 +1,24 @@
       +#!/usr/bin/env julia
       +
       +@info "Writing simple simulation to JLD2 file"
       +sim = Granular.createSimulation(id="test")
       +Granular.addGrainCylindrical!(sim, [ 0., 0.], 10., 1., verbose=false)
       +Granular.addGrainCylindrical!(sim, [18., 0.], 10., 1., verbose=false)
       +sim.ocean = Granular.createRegularOceanGrid([10, 20, 5], [10., 25., 2.])  
       +Granular.findContacts!(sim, method="all to all")
       +Granular.writeVTK(sim, verbose=false)
       +
       +Granular.writeSimulation(sim)
       +Granular.writeSimulationStatus(sim)
       +
       +@info "Reading from JLD2 file by specifying the input file name"
       +sim2 = Granular.readSimulation("./test/test.1.jld2")
       +Granular.compareSimulations(sim, sim2)
       +
       +@info "Reading and overwriting from JLD2 file by simulation id"
       +sim3 = Granular.createSimulation("test")
       +@test 1 == Granular.readSimulationStatus(sim3)
       +sim3 = Granular.readSimulation(sim3)
       +Granular.compareSimulations(sim, sim3)
       +
       +rm("./test/test.1.jld2")
   DIR diff --git a/test/runtests.jl b/test/runtests.jl
       t@@ -26,4 +26,4 @@ run_test("temporal.jl")
        if Granular.hasNetCDF
            run_test("netcdf.jl")
        end
       -run_test("jld.jl")
       +run_test("jld2.jl")