commit c5ffb485728badec9ab61be35670289b2a24efac
parent bfdbba1d09a0acec0586cb0de27b5b90112d6ec8
Author: Anders Damsgaard <andersd@riseup.net>
Date: Fri, 22 Dec 2017 15:55:22 -0500
Add `color` field to grains
Diffstat:
3 files changed, 51 insertions(+), 7 deletions(-)
diff --git a/src/datatypes.jl b/src/datatypes.jl
@@ -69,6 +69,9 @@ mutable struct GrainCylindrical
granular_stress::Vector{Float64}
ocean_stress::Vector{Float64}
atmosphere_stress::Vector{Float64}
+
+ # Visualization parameters
+ color::Int
end
# Type for linear (flat) and frictionless dynamic walls
@@ -149,6 +152,8 @@ mutable struct GrainArrays
granular_stress::Array{Float64, 2}
ocean_stress::Array{Float64, 2}
atmosphere_stress::Array{Float64, 2}
+
+ color::Vector{Int}
end
#=
diff --git a/src/grain.jl b/src/grain.jl
@@ -98,6 +98,8 @@ are optional, and come with default values. The only required arguments are
ocean drag [Pa].
* `atmosphere_stress::Vector{Float64} = [0., 0.]`: resultant stress on grain
from atmosphere drag [Pa].
+* `color::Int=0`: type number, usually used for associating a color to the grain
+ during visualization.
# Examples
The most basic example adds a new grain to the simulation `sim`, with a
@@ -171,7 +173,8 @@ function addGrainCylindrical!(simulation::Simulation,
n_contacts::Int = 0,
granular_stress::Vector{Float64} = [0., 0.],
ocean_stress::Vector{Float64} = [0., 0.],
- atmosphere_stress::Vector{Float64} = [0., 0.])
+ atmosphere_stress::Vector{Float64} = [0., 0.],
+ color::Int = 0)
# Check input values
if length(lin_pos) != 2
@@ -266,7 +269,9 @@ function addGrainCylindrical!(simulation::Simulation,
granular_stress,
ocean_stress,
- atmosphere_stress
+ atmosphere_stress,
+
+ color
)
# Overwrite previous placeholder values
@@ -379,6 +384,9 @@ function convertGrainDataToArrays(simulation::Simulation)
zeros(Float64, 3, length(simulation.grains)),
zeros(Float64, 3, length(simulation.grains)),
zeros(Float64, 3, length(simulation.grains)),
+
+ Array{Int}(length(simulation.grains)),
+
)
# fill arrays
@@ -450,6 +458,8 @@ function convertGrainDataToArrays(simulation::Simulation)
ifarr.ocean_stress[1:2, i] = simulation.grains[i].ocean_stress
ifarr.atmosphere_stress[1:2, i] =
simulation.grains[i].atmosphere_stress
+
+ ifarr.color[i] = simulation.grains[i].color
end
return ifarr
@@ -514,6 +524,7 @@ function deleteGrainArrays!(ifarr::GrainArrays)
ifarr.ocean_stress = f2
ifarr.atmosphere_stress = f2
+ ifarr.color = i1
gc()
nothing
end
@@ -579,6 +590,8 @@ function printGrainInfo(f::GrainCylindrical)
println(" granular_stress: $(f.granular_stress) Pa")
println(" ocean_stress: $(f.ocean_stress) Pa")
println(" atmosphere_stress: $(f.atmosphere_stress) Pa")
+
+ println(" color: $(f.color)\n")
nothing
end
@@ -723,6 +736,8 @@ function compareGrains(if1::GrainCylindrical, if2::GrainCylindrical)
@test if1.granular_stress ≈ if2.granular_stress
@test if1.ocean_stress ≈ if2.ocean_stress
@test if1.atmosphere_stress ≈ if2.atmosphere_stress
+
+ @test if1.color ≈ if2.color
nothing
end
diff --git a/src/io.jl b/src/io.jl
@@ -431,6 +431,9 @@ function writeGrainVTK(simulation::Simulation,
WriteVTK.vtk_point_data(vtkfile, ifarr.atmosphere_stress,
"Atmosphere stress [Pa]")
+ WriteVTK.vtk_point_data(vtkfile, ifarr.color,
+ "Color [-]")
+
deleteGrainArrays!(ifarr)
ifarr = 0
gc()
@@ -834,7 +837,8 @@ imagegrains.PointArrayStatus = [
'Number of contacts [-]',
'Granular stress [Pa]',
'Ocean stress [Pa]',
-'Atmosphere stress [Pa]']
+'Atmosphere stress [Pa]',
+'Color [-]']
animationScene1 = GetAnimationScene()
@@ -1204,6 +1208,8 @@ function plotGrains(sim::Simulation;
filetype::String = "png",
gnuplot_terminal::String = "png crop size 1200,1200",
plot_interactions::Bool = true,
+ palette_scalar::String = "contact_radius",
+ cbrange::Vector{Float64} = [NaN, NaN],
show_figure::Bool = true,
verbose::Bool = true)
@@ -1215,10 +1221,24 @@ function plotGrains(sim::Simulation;
x = Float64[]
y = Float64[]
r = Float64[]
+ scalars = Float64[]
for grain in sim.grains
push!(x, grain.lin_pos[1])
push!(y, grain.lin_pos[2])
push!(r, grain.contact_radius)
+
+ if palette_scalar == "contact_radius"
+ push!(scalars, grain.contact_radius)
+
+ elseif palette_scalar == "areal_radius"
+ push!(scalars, grain.areal_radius)
+
+ elseif palette_scalar == "color"
+ push!(scalars, grain.color)
+
+ else
+ error("palette_scalar = '$palette_scalar' not understood.")
+ end
end
# prepare interaction data
@@ -1268,7 +1288,6 @@ function plotGrains(sim::Simulation;
contact_stiffness_normal)
end
-
push!(i1, i)
push!(i2, j)
push!(inter_particle_vector, p)
@@ -1290,7 +1309,7 @@ function plotGrains(sim::Simulation;
# write grain data to temporary file on disk
datafile = Base.Filesystem.tempname()
- writedlm(datafile, [x y r])
+ writedlm(datafile, [x y r scalars])
gnuplotscript = Base.Filesystem.tempname()
#=
@@ -1335,11 +1354,15 @@ function plotGrains(sim::Simulation;
# light gray to black
write(f, "set palette defined ( 1 '#d3d3d3', 2 '#000000')\n")
+
+ if !isnan(cbrange[1])
+ write(f, "set cbrange [$(cbrange[1]):$(cbrange[2])]\n")
+ end
# gray to white
#write(f, "set palette defined (0 'gray', 1 'white')\n")
- write(f, """set cblabel "Diameter [m]"
+ write(f, """set cblabel "$palette_scalar"
set size ratio -1
set key off\n""")
@@ -1366,7 +1389,8 @@ function plotGrains(sim::Simulation;
end
end
- write(f,"""plot "$(datafile)" with circles palette fs lt 1 lc rgb "black" t "Particle"
+ #write(f,"""plot "$(datafile)" with circles lt 1 lc rgb "black" t "Particle"
+ write(f,"""plot "$(datafile)" with circles fill solid fillcolor palette lw 0 title "Particle"
""")
end