tinitialize ocean grid contents as empty arrays before binning ice floes - Gran… | |
git clone git://src.adamsgaard.dk/Granular.jl | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 15e08a9f502d2abb083235b8d8f0ca3e82daed7e | |
parent 3610b39fe2e0ccd8645733a34ec3eedca4e1e11f | |
Author: Anders Damsgaard <[email protected]> | |
Date: Sun, 30 Apr 2017 13:34:28 -0400 | |
initialize ocean grid contents as empty arrays before binning ice floes | |
Diffstat: | |
M src/grid.jl | 31 ++++++++++++++++-------------… | |
M src/simulation.jl | 3 +++ | |
M test/grid.jl | 16 +++++++++++++++- | |
3 files changed, 34 insertions(+), 16 deletions(-) | |
--- | |
diff --git a/src/grid.jl b/src/grid.jl | |
t@@ -32,22 +32,27 @@ export sortIceFloesInOceanGrid! | |
""" | |
Find ice-floe positions in ocean grid, based on their center positions. | |
""" | |
-function sortIceFloesInOceanGrid!(simulation::Simulation, verbose=true) | |
- | |
- # TODO: initialize empty ice_floe_list before appending to list | |
- simulation.ocean.ice_floe_list | |
+function sortIceFloesInOceanGrid!(simulation::Simulation; verbose=false) | |
+ | |
+ simulation.ocean.ice_floe_list = | |
+ Array{Array{Int, 1}}(size(simulation.ocean.xh, 1), | |
+ size(simulation.ocean.xh, 2)) | |
+ for i=1:size(simulation.ocean.xh, 1) | |
+ for j=1:size(simulation.ocean.xh, 2) | |
+ simulation.ocean.ice_floe_list[i, j] = Int[] | |
+ end | |
+ end | |
for idx in 1:length(simulation.ice_floes) | |
- if cellContainsIceFloe(simulation.ocean, i, j, | |
- simulation.ice_floes[idx]) | |
+ i, j = findCellContainingPoint(simulation.ocean, | |
+ simulation.ice_floes[idx].lin_pos) | |
- # add cell to ice floe | |
- simulation.ice_floes[idx].ocean_grid_pos = [i, j] | |
+ # add cell to ice floe | |
+ simulation.ice_floes[idx].ocean_grid_pos = [i, j] | |
- # add ice floe to cell | |
- push!(simulation.ice_floe_list[i, j], idx) | |
- end | |
+ # add ice floe to cell | |
+ push!(simulation.ocean.ice_floe_list[i, j], idx) | |
end | |
end | |
t@@ -127,10 +132,6 @@ Returns ocean-grid corner coordinates in the following or… | |
south-east corner, north-east corner, north-west corner). | |
""" | |
function getCellCornerCoordinates(ocean::Ocean, i::Int, j::Int) | |
- #sw = [ocean.xq[i-1, j-1], ocean.yq[i-1, j-1]] | |
- #se = [ocean.xq[ i, j-1], ocean.yq[ i, j-1]] | |
- #ne = [ocean.xq[ i, j], ocean.yq[ i, j]] | |
- #nw = [ocean.xq[i-1, j], ocean.yq[i-1, j]] | |
sw = [ocean.xq[ i, j], ocean.yq[ i, j]] | |
se = [ocean.xq[i+1, j], ocean.yq[i+1, j]] | |
ne = [ocean.xq[i+1, j+1], ocean.yq[i+1, j+1]] | |
diff --git a/src/simulation.jl b/src/simulation.jl | |
t@@ -108,6 +108,9 @@ function run!(simulation::Simulation; | |
end | |
zeroForcesAndTorques!(simulation) | |
+ if typeof(simulation.ocean.input_file) != Bool | |
+ sortIceFloesInOceanGrid!(simulation) | |
+ end | |
findContacts!(simulation) | |
interact!(simulation) | |
if typeof(simulation.ocean.input_file) != Bool | |
diff --git a/test/grid.jl b/test/grid.jl | |
t@@ -1,6 +1,7 @@ | |
#!/usr/bin/env julia | |
-# Check the contact search and geometry of a two-particle interaction | |
+# Check the grid interpolation and sorting functions | |
+verbose = true | |
info("#### $(basename(@__FILE__)) ####") | |
t@@ -82,3 +83,16 @@ info("Testing cell binning") | |
@test SeaIce.findCellContainingPoint(ocean, [6.2, 53.4]) == (1, 1) | |
@test SeaIce.findCellContainingPoint(ocean, [7.2, 53.4]) == (2, 1) | |
@test_throws ErrorException SeaIce.findCellContainingPoint(ocean, [0.2, 53.4]) | |
+ | |
+sim = SeaIce.createSimulation() | |
+sim.ocean = SeaIce.readOceanNetCDF("Baltic/00010101.ocean_month.nc", | |
+ "Baltic/ocean_hgrid.nc") | |
+SeaIce.addIceFloeCylindrical(sim, [6.5, 53.5], 10., 1., verbose=verbose) | |
+SeaIce.addIceFloeCylindrical(sim, [6.6, 53.5], 10., 1., verbose=verbose) | |
+SeaIce.addIceFloeCylindrical(sim, [7.5, 53.5], 10., 1., verbose=verbose) | |
+SeaIce.sortIceFloesInOceanGrid!(sim, verbose=verbose) | |
+@test sim.ice_floes[1].ocean_grid_pos == [1, 1] | |
+@test sim.ice_floes[2].ocean_grid_pos == [1, 1] | |
+@test sim.ice_floes[3].ocean_grid_pos == [2, 1] | |
+@test sim.ocean.ice_floe_list[1, 1] == [1, 2] | |
+@test sim.ocean.ice_floe_list[2, 1] == [3] |