commit 499f5049d0234373ea97c734d4b2583b3731f0dc
parent 696a7c97df4dd85b8cd88f2910e6b32e6ad5730f
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Sun, 10 Mar 2019 21:06:41 +0100
Update strailt.jl example for Granular and Julia 1.0+
Diffstat:
M | examples/strait.jl | | | 116 | +++++++++++++++++++++++++++++++++++++++++-------------------------------------- |
1 file changed, 60 insertions(+), 56 deletions(-)
diff --git a/examples/strait.jl b/examples/strait.jl
@@ -1,11 +1,11 @@
#!/usr/bin/env julia
-import SeaIce
+import Granular
using Random
-sim = SeaIce.createSimulation(id="strait")
+sim = Granular.createSimulation(id="strait")
n = [10, 10, 2]
-#sim = SeaIce.createSimulation(id="nares_strait_coarse_elast")
+#sim = Granular.createSimulation(id="nares_strait_coarse_elast")
#n = [6, 6, 2]
# Initialize ocean
@@ -13,10 +13,10 @@ Lx = 50.e3
Lx_constriction = 5e3
L = [Lx, Lx*1.5, 1e3]
Ly_constriction = 20e3
-sim.ocean = SeaIce.createRegularOceanGrid(n, L, name="poiseuille_flow")
-sim.ocean.v[:, :, 1, 1] = 1e-8*((sim.ocean.xq - Lx/2.).^2 - Lx^2./4.)
+sim.ocean = Granular.createRegularOceanGrid(n, L, name="poiseuille_flow")
+sim.ocean.v[:, :, 1, 1] = 1e-8.*((sim.ocean.xq .- Lx/2.).^2.0 .- Lx^2.0/4.0)
-# Initialize confining walls, which are ice floes that are fixed in space
+# Initialize confining walls, which are grains that are fixed in space
r = minimum(L[1:2]/n[1:2])/2.
r_min = r/4.
h = 1.
@@ -24,21 +24,22 @@ h = 1.
## N-S segments
r_walls = r_min
for y in range((L[2] - Ly_constriction)/2.,
- stop=Ly_constriction + (L[2] - Ly_constriction)/2.,
+ stop=Ly_constriction + (L[2] - Ly_constriction)/2.0,
length=Int(round(Ly_constriction/(r_walls*2))))
- SeaIce.addIceFloeCylindrical!(sim, [(Lx - Lx_constriction)/2., y], r_walls,
- h, fixed=true, verbose=false)
+ Granular.addGrainCylindrical!(sim, [(Lx - Lx_constriction)/2.0, y],
+ r_walls,
+ h, fixed=true, verbose=false)
end
-for y in range((L[2] - Ly_constriction)/2.,
- stop=Ly_constriction + (L[2] - Ly_constriction)/2.,
+for y in range((L[2] - Ly_constriction)/2.0,
+ stop=Ly_constriction + (L[2] - Ly_constriction)/2.0,
length=Int(round(Ly_constriction/(r_walls*2))))
- SeaIce.addIceFloeCylindrical!(sim,
+ Granular.addGrainCylindrical!(sim,
[Lx_constriction +
- (L[1] - Lx_constriction)/2., y], r_walls, h,
+ (L[1] - Lx_constriction)/2.0, y], r_walls, h,
fixed=true, verbose=false)
end
-dx = 2.*r_walls*sin(atan((Lx - Lx_constriction)/(L[2] - Ly_constriction)))
+dx = 2.0*r_walls*sin(atan((Lx - Lx_constriction)/(L[2] - Ly_constriction)))
## NW diagonal
x = r_walls:dx:((Lx - Lx_constriction)/2.)
@@ -46,7 +47,7 @@ y = range(L[2] - r_walls,
stop=(L[2] - Ly_constriction)/2. + Ly_constriction + r_walls,
length=length(x))
for i in 1:length(x)
- SeaIce.addIceFloeCylindrical!(sim, [x[i], y[i]], r_walls, h, fixed=true,
+ Granular.addGrainCylindrical!(sim, [x[i], y[i]], r_walls, h, fixed=true,
verbose=false)
end
@@ -56,40 +57,41 @@ y = range(L[2] - r_walls,
stop=(L[2] - Ly_constriction)/2. + Ly_constriction + r_walls,
length=length(x))
for i in 1:length(x)
- SeaIce.addIceFloeCylindrical!(sim, [x[i], y[i]], r_walls, h, fixed=true,
- verbose=false)
+ Granular.addGrainCylindrical!(sim, [x[i], y[i]], r_walls, h, fixed=true,
+ verbose=false)
end
## SW diagonal
x = r_walls:dx:((Lx - Lx_constriction)/2.)
-y = range(r, stop=(L[2] - Ly_constriction)/2. - r_walls,
+y = range(r, stop=(L[2] - Ly_constriction)/2.0 - r_walls,
length=length(x))
for i in 1:length(x)
- SeaIce.addIceFloeCylindrical!(sim, [x[i], y[i]], r_walls, h, fixed=true,
- verbose=false)
+ Granular.addGrainCylindrical!(sim, [x[i], y[i]], r_walls, h, fixed=true,
+ verbose=false)
end
## SE diagonal
x = (L[1] - r_walls):(-dx):((Lx - Lx_constriction)/2. + Lx_constriction)
y = range(r_walls, stop=(L[2] - Ly_constriction)/2. - r_walls, length=length(x))
for i in 1:length(x)
- SeaIce.addIceFloeCylindrical!(sim, [x[i], y[i]], r_walls, h, fixed=true,
- verbose=false)
+ Granular.addGrainCylindrical!(sim, [x[i], y[i]], r_walls, h, fixed=true,
+ verbose=false)
end
-n_walls = length(sim.ice_floes)
-@info "added $(n_walls) fixed ice floes as walls"
+n_walls = length(sim.grains)
+@info "added $(n_walls) fixed grains as walls"
-# Initialize ice floes in wedge north of the constriction
-iy = 1
-dy = sqrt((2.*r_walls)^2. - dx^2.)
-spacing_to_boundaries = 4.*r
-floe_padding = .5*r
+# Initialize grains in wedge north of the constriction
+dy = sqrt((2.0*r_walls)^2.0 - dx^2.0)
+spacing_to_boundaries = 4.0*r
+floe_padding = 0.5*r
noise_amplitude = floe_padding
Random.seed!(1)
-for y in (L[2] - r - noise_amplitude):(-(2.*r + floe_padding)):((L[2] -
- Ly_constriction)/2. + Ly_constriction)
- for x in (r + noise_amplitude):(2.*r + floe_padding):(Lx - r -
+let
+iy = 1
+for y in (L[2] - r - noise_amplitude):(-(2.0*r + floe_padding)):((L[2] -
+ Ly_constriction)/2.0 + Ly_constriction)
+ for x in (r + noise_amplitude):(2.0*r + floe_padding):(Lx - r -
noise_amplitude)
if iy % 2 == 0
x += 1.5*r
@@ -107,49 +109,51 @@ for y in (L[2] - r - noise_amplitude):(-(2.*r + floe_padding)):((L[2] -
end
r_rand = r_min + rand()*(r - r_min)
- SeaIce.addIceFloeCylindrical!(sim, [x_, y_], r_rand, h, verbose=false)
+ Granular.addGrainCylindrical!(sim, [x_, y_], r_rand, h, verbose=false)
end
iy += 1
end
-n = length(sim.ice_floes) - n_walls
-@info "added $n ice floes"
+end
+n = length(sim.grains) - n_walls
+@info "added $n grains"
# Remove old simulation files
-SeaIce.removeSimulationFiles(sim)
+Granular.removeSimulationFiles(sim)
k_n = 1e7 # N/m
k_t = k_n
#gamma_t = 1e7 # N/(m/s)
-gamma_t = 0.
+gamma_t = 0.0
mu_d = 0.7
rotating = true
-for i=1:length(sim.ice_floes)
- sim.ice_floes[i].contact_stiffness_normal = k_n
- sim.ice_floes[i].contact_stiffness_tangential = k_t
- sim.ice_floes[i].contact_viscosity_tangential = gamma_t
- sim.ice_floes[i].contact_dynamic_friction = mu_d
- sim.ice_floes[i].rotating = rotating
+for i=1:length(sim.grains)
+ sim.grains[i].contact_stiffness_normal = k_n
+ sim.grains[i].contact_stiffness_tangential = k_t
+ sim.grains[i].contact_viscosity_tangential = gamma_t
+ sim.grains[i].contact_dynamic_friction = mu_d
+ sim.grains[i].rotating = rotating
end
# Set temporal parameters
-SeaIce.setTotalTime!(sim, 6.*60.*60.)
-SeaIce.setOutputFileInterval!(sim, 60.)
-SeaIce.setTimeStep!(sim)
+Granular.setTotalTime!(sim, 6.0*60.0*60.0)
+Granular.setOutputFileInterval!(sim, 60.0)
+Granular.setTimeStep!(sim)
-# Run simulation for 10 time steps, then add new icefloes from the top
+# Run simulation for 10 time steps, then add new grains the top
while sim.time < sim.time_total
for it=1:10
- SeaIce.run!(sim, status_interval=1, single_step=true)
+ Granular.run!(sim, status_interval=1, single_step=true)
end
for i=1:size(sim.ocean.xh, 1)
- if sim.ocean.ice_floe_list[i, end] == []
+ if sim.ocean.grain_list[i, end] == []
- x, y = SeaIce.getCellCenterCoordinates(sim.ocean, i,
- size(sim.ocean.xh, 2))
+ x, y = Granular.getCellCenterCoordinates(sim.ocean.xh,
+ sim.ocean.yh,
+ i, size(sim.ocean.xh, 2))
# Enable for high mass flux
r_rand = r_min + rand()*(r - r_min)
- SeaIce.addIceFloeCylindrical!(sim, [x-r, y-r], r_rand, h,
+ Granular.addGrainCylindrical!(sim, [x-r, y-r], r_rand, h,
verbose=false,
contact_stiffness_normal=k_n,
contact_stiffness_tangential=k_t,
@@ -157,7 +161,7 @@ while sim.time < sim.time_total
contact_dynamic_friction = mu_d,
rotating=rotating)
r_rand = r_min + rand()*(r - r_min)
- SeaIce.addIceFloeCylindrical!(sim, [x+r, y-r], r_rand, h,
+ Granular.addGrainCylindrical!(sim, [x+r, y-r], r_rand, h,
verbose=false,
contact_stiffness_normal=k_n,
contact_stiffness_tangential=k_t,
@@ -165,7 +169,7 @@ while sim.time < sim.time_total
contact_dynamic_friction = mu_d,
rotating=rotating)
r_rand = r_min + rand()*(r - r_min)
- SeaIce.addIceFloeCylindrical!(sim, [x+r, y+r], r_rand, h,
+ Granular.addGrainCylindrical!(sim, [x+r, y+r], r_rand, h,
verbose=false,
contact_stiffness_normal=k_n,
contact_stiffness_tangential=k_t,
@@ -173,7 +177,7 @@ while sim.time < sim.time_total
contact_dynamic_friction = mu_d,
rotating=rotating)
r_rand = r_min + rand()*(r - r_min)
- SeaIce.addIceFloeCylindrical!(sim, [x-r, y+r], r_rand, h,
+ Granular.addGrainCylindrical!(sim, [x-r, y+r], r_rand, h,
verbose=false,
contact_stiffness_normal=k_n,
contact_stiffness_tangential=k_t,
@@ -184,7 +188,7 @@ while sim.time < sim.time_total
# Enable for low mass flux
#x += noise_amplitude*(0.5 - rand())
#y += noise_amplitude*(0.5 - rand())
- #SeaIce.addIceFloeCylindrical!(sim, [x, y], r, h, verbose=false)
+ #Granular.addGrainCylindrical!(sim, [x, y], r, h, verbose=false)
end
end
end