tadd functionality to read/write simulation and simulation status to disk - Gra… | |
git clone git://src.adamsgaard.dk/Granular.jl | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit e82bda84db3fa2525beabcc434837a0e484cc087 | |
parent 5445639fc2cc81ef14066c5c67e773097c0f07f2 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Fri, 9 Jun 2017 16:07:58 -0400 | |
add functionality to read/write simulation and simulation status to disk | |
Diffstat: | |
M src/io.jl | 52 +++++++++++++++++++++++++++++… | |
M src/simulation.jl | 2 ++ | |
D test/jdl.jl | 61 -----------------------------… | |
A test/jld.jl | 16 ++++++++++++++++ | |
M test/runtests.jl | 2 +- | |
M test/vtk.jl | 2 ++ | |
6 files changed, 73 insertions(+), 62 deletions(-) | |
--- | |
diff --git a/src/io.jl b/src/io.jl | |
t@@ -4,6 +4,7 @@ import JLD | |
## IO functions | |
+export writeSimulation | |
""" | |
writeSimulation(simulation::Simulation; | |
filename::String="", | |
t@@ -32,6 +33,7 @@ function writeSimulation(simulation::Simulation; | |
end | |
end | |
+export readSimulation | |
""" | |
readSimulation(filename::String=""; | |
verbose::Bool=true) | |
t@@ -46,6 +48,54 @@ function readSimulation(filename::String=""; | |
return JLD.load(filename, "simulation") | |
end | |
+export writeSimulationStatus | |
+""" | |
+ writeSimulationStatus(simulation::Simulation; | |
+ folder::String=".", | |
+ verbose::Bool=false) | |
+ | |
+Write current simulation status to disk in a minimal txt file. | |
+""" | |
+function writeSimulationStatus(simulation::Simulation; | |
+ folder::String=".", | |
+ verbose::Bool=false) | |
+ folder = folder * "/" * simulation.id | |
+ mkpath(folder) | |
+ filename = string(folder, "/", simulation.id, ".status.txt") | |
+ | |
+ writedlm(filename, [simulation.time | |
+ simulation.time/simulation.time_total*100. | |
+ float(simulation.file_number)]) | |
+ if verbose | |
+ info("wrote status to $filename") | |
+ end | |
+end | |
+ | |
+export readSimulationStatus | |
+""" | |
+ readSimulationStatus(filename::String; | |
+ folder::String=".", | |
+ verbose::Bool=false) | |
+ | |
+Write current simulation status to disk in a minimal txt file. | |
+""" | |
+function readSimulationStatus(simulation_id::String; | |
+ folder::String=".", | |
+ verbose::Bool=true) | |
+ | |
+ folder = folder * "/" * simulation_id | |
+ filename = string(folder, "/", simulation_id, ".status.txt") | |
+ | |
+ data = readdlm(filename) | |
+ if verbose | |
+ info("$simulation_id:\n" * | |
+ " time: $(data[1]) s\n" * | |
+ " complete: $(data[2])%\n" * | |
+ " last output file: $(Int(round(data[3])))\n") | |
+ end | |
+ return data[3] | |
+end | |
+ | |
export writeVTK | |
""" | |
Write a VTK file to disk containing all ice floes in the `simulation` in an | |
t@@ -497,5 +547,7 @@ function removeSimulationFiles(simulation::Simulation; fol… | |
run(`bash -c "rm -rf $(folder)/$(simulation.id).*.vtu"`) | |
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)"`) | |
end | |
diff --git a/src/simulation.jl b/src/simulation.jl | |
t@@ -100,7 +100,9 @@ function run!(simulation::Simulation; | |
if show_file_output | |
println() | |
end | |
+ writeSimulation(simulation, verbose=show_file_output) | |
writeVTK(simulation, verbose=show_file_output) | |
+ writeSimulationStatus(simulation, verbose=show_file_output) | |
simulation.file_time_since_output_file = 0.0 | |
end | |
diff --git a/test/jdl.jl b/test/jdl.jl | |
t@@ -1,61 +0,0 @@ | |
-#!/usr/bin/env julia | |
- | |
-info("#### $(basename(@__FILE__)) ####") | |
- | |
-info("Writing simple simulation to JDL file") | |
-sim = SeaIce.createSimulation(id="test") | |
-SeaIce.addIceFloeCylindrical(sim, [ 0., 0.], 10., 1., verbose=false) | |
-SeaIce.addIceFloeCylindrical(sim, [18., 0.], 10., 1., verbose=false) | |
-sim.ocean = SeaIce.createRegularOceanGrid([10, 20, 5], [10., 25., 2.]) | |
-SeaIce.findContacts!(sim, method="all to all") | |
-SeaIce.writeVTK(sim, verbose=false) | |
- | |
-SeaIce.writeSimulation(sim) | |
- | |
-sim2 = SeaIce.readSimulation("./test/test.1.jld") | |
-SeaIce.compareSimulations(sim, sim2) | |
- | |
- | |
- | |
-""" | |
-cmd_post = "" | |
-if Base.is_linux() | |
- cmd = "sha256sum" | |
-elseif Base.is_apple() | |
- cmd = ["shasum", "-a", "256"] | |
-elseif Base.is_windows() | |
- info("checksum verification not yet implemented on Windows") | |
- exit() | |
- cmd = ["powershell", "-Command", "\"Get-FileHash", "-Algorithm", "SHA256"] | |
- cmd_post = "\"" | |
-else | |
- error("checksum verification of VTK file not supported on this platform") | |
-end | |
- | |
-icefloepath = "test/test.icefloes.1.vtu" | |
-icefloechecksum = | |
-"c75ffde29fbdd80161dafd524e690fbcbae2136d4f68c29f725d2d2454c6a162 " * | |
-icefloepath * "\n" | |
- | |
-oceanpath = "test/test.ocean.1.vts" | |
-oceanchecksum = | |
-"d56ffb109841a803f2b2b94c74c87f7a497237204841d557d2b1043694d51f0d " * | |
-oceanpath * "\n" | |
- | |
-@test readstring(`$(cmd) $(icefloepath)$(cmd_post)`) == icefloechecksum | |
-@test readstring(`$(cmd) $(oceanpath)$(cmd_post)`) == oceanchecksum | |
- | |
-SeaIce.removeSimulationFiles(sim) | |
- | |
-info("Testing VTK write during run!()") | |
-SeaIce.setOutputFileInterval!(sim, 1e-9) | |
-SeaIce.setTotalTime!(sim, 1.5) | |
-SeaIce.setTimeStep!(sim) | |
-sim.file_number = 0 | |
-SeaIce.run!(sim, single_step=true) | |
- | |
-@test readstring(`$(cmd) $(icefloepath)$(cmd_post)`) == icefloechecksum | |
-@test readstring(`$(cmd) $(oceanpath)$(cmd_post)`) == oceanchecksum | |
- | |
-SeaIce.removeSimulationFiles(sim) | |
-""" | |
diff --git a/test/jld.jl b/test/jld.jl | |
t@@ -0,0 +1,16 @@ | |
+#!/usr/bin/env julia | |
+ | |
+info("#### $(basename(@__FILE__)) ####") | |
+ | |
+info("Writing simple simulation to JLD file") | |
+sim = SeaIce.createSimulation(id="test") | |
+SeaIce.addIceFloeCylindrical(sim, [ 0., 0.], 10., 1., verbose=false) | |
+SeaIce.addIceFloeCylindrical(sim, [18., 0.], 10., 1., verbose=false) | |
+sim.ocean = SeaIce.createRegularOceanGrid([10, 20, 5], [10., 25., 2.]) | |
+SeaIce.findContacts!(sim, method="all to all") | |
+SeaIce.writeVTK(sim, verbose=false) | |
+ | |
+SeaIce.writeSimulation(sim) | |
+ | |
+sim2 = SeaIce.readSimulation("./test/test.1.jld") | |
+SeaIce.compareSimulations(sim, sim2) | |
diff --git a/test/runtests.jl b/test/runtests.jl | |
t@@ -10,7 +10,7 @@ include("collision-2floes-oblique.jl") | |
include("cohesion.jl") | |
include("netcdf.jl") | |
include("vtk.jl") | |
-include("jdl.jl") | |
+include("jld.jl") | |
include("grid.jl") | |
include("ocean.jl") | |
include("atmosphere.jl") | |
diff --git a/test/vtk.jl b/test/vtk.jl | |
t@@ -51,4 +51,6 @@ SeaIce.run!(sim, single_step=true) | |
@test readstring(`$(cmd) $(icefloepath)$(cmd_post)`) == icefloechecksum | |
@test readstring(`$(cmd) $(oceanpath)$(cmd_post)`) == oceanchecksum | |
+@test SeaIce.readSimulationStatus(sim.id) == 1 | |
+ | |
SeaIce.removeSimulationFiles(sim) |