Granular.jl

Julia package for granular dynamics simulation
git clone git://src.adamsgaard.dk/Granular.jl
Log | Files | Refs | README | LICENSE

commit 0033f25f4b49e1a301c2d141e0d67a703cee2cfb
parent e87de94aadd651976b2a5f0855e60d5d76a78e29
Author: Anders Damsgaard <andersd@riseup.net>
Date:   Fri, 28 Apr 2017 11:59:20 -0400

separate VTK write into icefloe and ocean subfunctions

Diffstat:
Msrc/io.jl | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
Mtest/vtk.jl | 8++++----
2 files changed, 74 insertions(+), 8 deletions(-)

diff --git a/src/io.jl b/src/io.jl @@ -8,17 +8,42 @@ export writeVTK Write a VTK file to disk containing all ice floes in the `simulation` in an unstructured mesh (file type `.vtu`). These files can be read by ParaView and can be visualized by applying a *Glyph* filter. + +If the simulation contains an `Ocean` data structure, it's contents will be +written to separate `.vtu` files. This can be disabled by setting the argument +`ocean=false`. """ function writeVTK(simulation::Simulation; - folder::String=".", - verbose::Bool=false) + folder::String=".", + verbose::Bool=false, + ocean::Bool=true) simulation.file_number += 1 - filename = string(folder, "/", simulation.id, ".", simulation.file_number) + filename = string(folder, "/", simulation.id, ".icefloes.", + simulation.file_number) + writeIceFloeVTK(simulation, filename) + + if typeof(simulation.ocean.input_file) != Bool && ocean + filename = string(folder, "/", simulation.id, ".ocean.", + simulation.file_number) + writeOceanVTK(simulation.ocean, filename) + end +end + +export writeIceFloeVTK +""" +Write a VTK file to disk containing all ice floes in the `simulation` in an +unstructured mesh (file type `.vtu`). These files can be read by ParaView and +can be visualized by applying a *Glyph* filter. This function is called by +`writeVTK()`. +""" +function writeIceFloeVTK(simulation::Simulation, + filename::String; + verbose::Bool=false) ifarr = convertIceFloeDataToArrays(simulation) - # write to disk + # add arrays to VTK file vtkfile = WriteVTK.vtk_grid(filename, ifarr.lin_pos, WriteVTK.MeshCell[]) WriteVTK.vtk_point_data(vtkfile, ifarr.density, "Density [kg m^-3]") @@ -77,3 +102,44 @@ function writeVTK(simulation::Simulation; return nothing end end + +export writeOceanVTK +""" +Write a VTK file to disk containing all ocean data in the `simulation` in a +structured grid (file type `.vts`). These files can be read by ParaView and can +be visualized by applying a *Glyph* filter. This function is called by +`writeVTK()`. +""" +function writeOceanVTK(ocean::Ocean, + filename::String; + verbose::Bool=false) + + # make each coordinate array three-dimensional + xq = similar(ocean.u[:,:,:,1]) + yq = similar(ocean.u[:,:,:,1]) + zq = similar(ocean.u[:,:,:,1]) + + for iz=1:size(xq, 3) + xq[:,:,iz] = ocean.xq + yq[:,:,iz] = ocean.yq + end + for ix=1:size(xq, 1) + for iy=1:size(xq, 2) + xq[ix,iy,:] = ocean.zl + yq[ix,iy,:] = ocean.zl + end + end + + # add arrays to VTK file + vtkfile = WriteVTK.vtk_grid(filename, xq, yq, zq) + + WriteVTK.vtk_point_data(vtkfile, u, "Zonal velocity [m/s]") + WriteVTK.vtk_point_data(vtkfile, v, "Meridional velocity [m/s]") + + outfiles = WriteVTK.vtk_save(vtkfile) + if verbose + println("Output file: " * outfiles[1]) + else + return nothing + end +end diff --git a/test/vtk.jl b/test/vtk.jl @@ -11,11 +11,11 @@ SeaIce.addIceFloeCylindrical(sim, [18., 0.], 10., 1., verbose=false) SeaIce.writeVTK(sim) if Base.is_linux() - checksum = readstring(`sha256sum test.1.vtu`) + checksum = readstring(`sha256sum test.icefloes.1.vtu`) elseif Base.is_apple() - checksum = readstring(`shasum -a 256 test.1.vtu`) + checksum = readstring(`shasum -a 256 test.icefloes.1.vtu`) else warn("checksum verification of VTK file not supported on this platform") end -rm("test.1.vtu") -@test checksum == "1c0c2bdd265abdda22ef3727e7cac829e2321462d494be2e23364653f9529c87 test.1.vtu\n" +rm("test.icefloes.1.vtu") +@test checksum == "1c0c2bdd265abdda22ef3727e7cac829e2321462d494be2e23364653f9529c87 test.icefloes.1.vtu\n"