tadd function for cell center coordinates, add tests - Granular.jl - Julia pack… | |
git clone git://src.adamsgaard.dk/Granular.jl | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit dec15a9e0cb198b20df8eaab444a6d03d2a1a80e | |
parent 764f9a160974b94ffec0b0572a0bcdc2cbc49336 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Mon, 1 May 2017 10:28:19 -0400 | |
add function for cell center coordinates, add tests | |
Diffstat: | |
M examples/nares_strait.jl | 18 +++++++++++++++--- | |
M src/grid.jl | 22 ++++++++++++++++++++++ | |
M test/grid.jl | 8 ++++++++ | |
3 files changed, 45 insertions(+), 3 deletions(-) | |
--- | |
diff --git a/examples/nares_strait.jl b/examples/nares_strait.jl | |
t@@ -81,7 +81,8 @@ noise_amplitude = floe_padding | |
Base.Random.srand(1) | |
for y in (L[2] - r - noise_amplitude):(-(2.*r + floe_padding)):((L[2] - | |
Ly_constriction)/2. + Ly_constriction) | |
- for x in (Lx*.125):(2.*r + floe_padding):(Lx*.875 - 2.*r) | |
+ for x in (r + noise_amplitude):(2.*r + floe_padding):(Lx - r - | |
+ noise_amplitude) | |
if iy % 2 == 0 | |
x += 1.5*r | |
end | |
t@@ -104,8 +105,19 @@ end | |
n = length(sim.ice_floes) - n_walls | |
info("added $(n) ice floes") | |
-# Run temporal loop | |
+# Set temporal parameters | |
SeaIce.setTotalTime!(sim, 24.*60.*60.) | |
SeaIce.setOutputFileInterval!(sim, 60.) | |
SeaIce.setTimeStep!(sim) | |
-SeaIce.run!(sim, status_interval=1) | |
+ | |
+# Run simulation for 10 time steps, then add new icefloes from the top | |
+while sim.time < sim.time_total | |
+ for it=1:10 | |
+ SeaIce.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] == [] | |
+ SeaIce.addIceFloeCylindrical(sim, [x, y], r, h, verbose=false) | |
+ end | |
+ end | |
+end | |
diff --git a/src/grid.jl b/src/grid.jl | |
t@@ -145,8 +145,15 @@ end | |
export getCellCornerCoordinates | |
""" | |
+ getCellCornerCoordinates(ocean, i, j) | |
+ | |
Returns ocean-grid corner coordinates in the following order (south-west corne… | |
south-east corner, north-east corner, north-west corner). | |
+ | |
+# Arguments | |
+* `ocean::Ocean`: ocean object containing grid. | |
+* `i::Int`: x-index of cell. | |
+* `j::Int`: y-index of cell. | |
""" | |
function getCellCornerCoordinates(ocean::Ocean, i::Int, j::Int) | |
sw = [ocean.xq[ i, j], ocean.yq[ i, j]] | |
t@@ -156,6 +163,21 @@ function getCellCornerCoordinates(ocean::Ocean, i::Int, j… | |
return sw, se, ne, nw | |
end | |
+export getCellCenterCoordinates | |
+""" | |
+ getCellCenterCoordinates(ocean, i, j) | |
+ | |
+Returns ocean-grid center coordinates (h-point). | |
+ | |
+# Arguments | |
+* `ocean::Ocean`: ocean object containing grid. | |
+* `i::Int`: x-index of cell. | |
+* `j::Int`: y-index of cell. | |
+""" | |
+function getCellCenterCoordinates(ocean::Ocean, i::Int, j::Int) | |
+ return [ocean.xh[i, j], ocean.yh[i, j]] | |
+end | |
+ | |
export areaOfTriangle | |
"Returns the area of an triangle with corner coordinates `a`, `b`, and `c`." | |
function areaOfTriangle(a::Array{float, 1}, | |
diff --git a/test/grid.jl b/test/grid.jl | |
t@@ -8,6 +8,14 @@ info("#### $(basename(@__FILE__)) ####") | |
ocean = SeaIce.readOceanNetCDF("Baltic/00010101.ocean_month.nc", | |
"Baltic/ocean_hgrid.nc") | |
+info("Testing coordinate retrieval functions") | |
+sw, se, ne, nw = SeaIce.getCellCornerCoordinates(ocean, 1, 1) | |
+@test sw ≈ [6., 53.] | |
+@test se ≈ [7., 53.] | |
+@test ne ≈ [7., 54.] | |
+@test nw ≈ [6., 54.] | |
+@test SeaIce.getCellCenterCoordinates(ocean, 1, 1) ≈ [6.5, 53.5] | |
+ | |
info("Testing area-determination methods") | |
@test SeaIce.areaOfTriangle([0., 0.], [1., 0.], [0., 1.]) ≈ .5 | |
@test SeaIce.areaOfTriangle([1., 0.], [0., 1.], [0., 0.]) ≈ .5 |