tadd fields to grain VTK files, add the option to render with `status()` - Gran… | |
git clone git://src.adamsgaard.dk/Granular.jl | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit d75d17f32be9aee6a303c150dfa120373b95cf22 | |
parent 27b1f0f8266144d202c7c3e4f9f6952be5826b13 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Wed, 29 Nov 2017 10:20:34 -0500 | |
add fields to grain VTK files, add the option to render with `status()` | |
Diffstat: | |
M src/datatypes.jl | 3 +++ | |
M src/grain.jl | 11 +++++++++++ | |
M src/io.jl | 26 ++++++++++++++++++++++++-- | |
M src/temporal_integration.jl | 12 +++++++++++- | |
M test/memory-management.jl | 5 ++--- | |
M test/vtk.jl | 2 +- | |
6 files changed, 52 insertions(+), 7 deletions(-) | |
--- | |
diff --git a/src/datatypes.jl b/src/datatypes.jl | |
t@@ -21,6 +21,7 @@ mutable struct GrainCylindrical | |
lin_acc::Vector{Float64} | |
force::Vector{Float64} | |
external_body_force::Vector{Float64} | |
+ lin_disp::Vector{Float64} | |
# Angular kinematic degrees of freedom for vertical rotation around center | |
ang_pos::Float64 | |
t@@ -106,6 +107,8 @@ mutable struct GrainArrays | |
lin_vel::Array{Float64, 2} | |
lin_acc::Array{Float64, 2} | |
force::Array{Float64, 2} | |
+ external_body_force::Array{Float64, 2} | |
+ lin_disp::Array{Float64, 2} | |
# Angular kinematic degrees of freedom for vertical rotation around center | |
ang_pos::Array{Float64, 2} | |
diff --git a/src/grain.jl b/src/grain.jl | |
t@@ -224,6 +224,7 @@ function addGrainCylindrical!(simulation::Simulation, | |
lin_acc, | |
force, | |
[0., 0.], # external_body_force | |
+ [0., 0.], # lin_disp | |
ang_pos, | |
ang_vel, | |
t@@ -341,6 +342,8 @@ function convertGrainDataToArrays(simulation::Simulation) | |
zeros(Float64, 3, length(simulation.grains)), | |
zeros(Float64, 3, length(simulation.grains)), | |
zeros(Float64, 3, length(simulation.grains)), | |
+ zeros(Float64, 3, length(simulation.grains)), | |
+ zeros(Float64, 3, length(simulation.grains)), | |
zeros(Float64, 3, length(simulation.grains)), | |
zeros(Float64, 3, length(simulation.grains)), | |
t@@ -397,6 +400,9 @@ function convertGrainDataToArrays(simulation::Simulation) | |
ifarr.lin_vel[1:2, i] = simulation.grains[i].lin_vel | |
ifarr.lin_acc[1:2, i] = simulation.grains[i].lin_acc | |
ifarr.force[1:2, i] = simulation.grains[i].force | |
+ ifarr.external_body_force[1:2, i] = | |
+ simulation.grains[i].external_body_force | |
+ ifarr.lin_disp[1:2, i] = simulation.grains[i].lin_disp | |
ifarr.ang_pos[3, i] = simulation.grains[i].ang_pos | |
ifarr.ang_vel[3, i] = simulation.grains[i].ang_vel | |
t@@ -470,6 +476,8 @@ function deleteGrainArrays!(ifarr::GrainArrays) | |
ifarr.lin_vel = f2 | |
ifarr.lin_acc = f2 | |
ifarr.force = f2 | |
+ ifarr.external_body_force = f2 | |
+ ifarr.lin_disp = f2 | |
ifarr.ang_pos = f2 | |
ifarr.ang_vel = f2 | |
t@@ -532,6 +540,7 @@ function printGrainInfo(f::GrainCylindrical) | |
println(" lin_vel: $(f.lin_vel) m/s") | |
println(" lin_acc: $(f.lin_acc) m/s^2") | |
println(" force: $(f.force) N\n") | |
+ println(" external_body_force: $(f.external_body_force) N\n") | |
println(" ang_pos: $(f.ang_pos) rad") | |
println(" ang_vel: $(f.ang_vel) rad/s") | |
t@@ -668,6 +677,7 @@ function compareGrains(if1::GrainCylindrical, if2::GrainCy… | |
@test if1.lin_acc ≈ if2.lin_acc | |
@test if1.force ≈ if2.force | |
@test if1.external_body_force ≈ if2.external_body_force | |
+ @test if1.lin_disp ≈ if2.lin_disp | |
@test if1.ang_pos ≈ if2.ang_pos | |
@test if1.ang_vel ≈ if2.ang_vel | |
t@@ -772,6 +782,7 @@ function zeroKinematics!(sim::Simulation) | |
grain.lin_vel .= zeros(2) | |
grain.lin_acc .= zeros(2) | |
grain.force .= zeros(2) | |
+ grain.lin_disp .= zeros(2) | |
grain.ang_vel = 0. | |
grain.ang_acc = 0. | |
grain.torque = 0. | |
diff --git a/src/io.jl b/src/io.jl | |
t@@ -186,14 +186,28 @@ end | |
export status | |
""" | |
+ status(folder[, loop, t_int, colored_output, write_header, render) | |
+ | |
Shows the status of all simulations with output files written under the | |
specified `folder`, which is the current working directory by default. | |
+ | |
+# Arguments | |
+`folder::String="."`: directory (including subdirectories) to scan for | |
+ simulation output. | |
+`loop::Bool=false`: continue printing the status every `t_int` seconds. | |
+`t_int::Int=10`: interval between status updates when `loop=true`. | |
+`colored_output::Bool=true`: display output with colors. | |
+`write_header::Bool=true`: write header line explaining the data. | |
+visualize::Bool=false`: render the simulation output. Does not work well when | |
+ `loop=true`, as the script regenerates (and overwrites) all output graphi… | |
+ on every call. | |
""" | |
function status(folder::String="."; | |
loop::Bool=false, | |
t_int::Int=10, | |
colored_output::Bool=true, | |
- write_header::Bool=true) | |
+ write_header::Bool=true, | |
+ visualize::Bool=false) | |
if colored_output | |
id_color_complete = :green | |
t@@ -253,6 +267,11 @@ function status(folder::String="."; | |
print_with_color(time_color, "$time_s ($time_h) \t") | |
print_with_color(percentage_color, "$percentage \t") | |
print_with_color(lastfile_color, "$lastfile \n") | |
+ | |
+ if visualize | |
+ sim = createSimulation(id) | |
+ render(sim) | |
+ end | |
end | |
if write_header | |
println("--------------------------------------" * | |
t@@ -354,6 +373,7 @@ function writeGrainVTK(simulation::Simulation, | |
WriteVTK.vtk_point_data(vtkfile, ifarr.lin_acc, | |
"Linear acceleration [m s^-2]") | |
WriteVTK.vtk_point_data(vtkfile, ifarr.force, "Sum of forces [N]") | |
+ WriteVTK.vtk_point_data(vtkfile, ifarr.lin_disp, "Linear displacement [m]") | |
WriteVTK.vtk_point_data(vtkfile, ifarr.ang_pos, "Angular position [rad]") | |
WriteVTK.vtk_point_data(vtkfile, ifarr.ang_vel, | |
t@@ -759,7 +779,8 @@ function writeParaviewPythonScript(simulation::Simulation; | |
end | |
if simulation.file_number == 0 | |
- simulation.file_number = readSimulationStatus(simulation) | |
+ simulation.file_number = readSimulationStatus(simulation, | |
+ verbose=verbose) | |
end | |
open(filename, "w") do f | |
t@@ -786,6 +807,7 @@ imagegrains.PointArrayStatus = [ | |
'Linear velocity [m s^-1]', | |
'Linear acceleration [m s^-2]', | |
'Sum of forces [N]', | |
+'Linear displacement [m]', | |
'Angular position [rad]', | |
'Angular velocity [rad s^-1]', | |
'Angular acceleration [rad s^-2]', | |
diff --git a/src/temporal_integration.jl b/src/temporal_integration.jl | |
t@@ -68,6 +68,11 @@ function updateGrainKinematicsTwoTermTaylor!(grain::GrainCy… | |
grain.lin_pos += | |
grain.lin_vel * simulation.time_step + | |
0.5*grain.lin_acc * simulation.time_step^2.0 | |
+ | |
+ grain.lin_disp += | |
+ grain.lin_vel * simulation.time_step + | |
+ 0.5*grain.lin_acc * simulation.time_step^2.0 | |
+ | |
grain.ang_pos += | |
grain.ang_vel * simulation.time_step + | |
0.5*grain.ang_acc * simulation.time_step^2.0 | |
t@@ -111,6 +116,12 @@ function updateGrainKinematicsThreeTermTaylor!(grain::Gra… | |
grain.lin_vel * simulation.time_step + | |
0.5 * grain.lin_acc * simulation.time_step^2. + | |
1. / 6. * d_lin_acc_dt * simulation.time_step^3. | |
+ | |
+ grain.lin_disp += | |
+ grain.lin_vel * simulation.time_step + | |
+ 0.5 * grain.lin_acc * simulation.time_step^2. + | |
+ 1. / 6. * d_lin_acc_dt * simulation.time_step^3. | |
+ | |
grain.ang_pos += | |
grain.ang_vel * simulation.time_step + | |
0.5 * grain.ang_acc * simulation.time_step^2. + | |
t@@ -232,4 +243,3 @@ function updateWallKinematicsThreeTermTaylor!(wall::WallLi… | |
nothing | |
end | |
- | |
diff --git a/test/memory-management.jl b/test/memory-management.jl | |
t@@ -11,9 +11,8 @@ empty_sim_size_recursive = 552 | |
@test sizeof(sim) == empty_sim_size | |
@test Base.summarysize(sim) == empty_sim_size_recursive | |
-size_per_grain = 368 | |
-#size_per_grain_recursive = 1552 # Nc_max = 16 | |
-size_per_grain_recursive = 2576 # Nc_max = 32 | |
+size_per_grain = 376 | |
+size_per_grain_recursive = 2600 # Nc_max = 32 | |
info("Testing memory usage when adding grains") | |
for i=1:100 | |
diff --git a/test/vtk.jl b/test/vtk.jl | |
t@@ -29,7 +29,7 @@ end | |
grainpath = "test/test.grains.1.vtu" | |
grainchecksum = | |
-"c75ffde29fbdd80161dafd524e690fbcbae2136d4f68c29f725d2d2454c6a162 " * | |
+"8a8830bb5448ba7daa3f1194a1c6bbfa933823edf9aad43c5259be25550a80ed " * | |
grainpath * "\n" | |
graininteractionpath = "test/test.grain-interaction.1.vtp" |