tAdd data structures and handling of fields associated with regular grids - Gra… | |
git clone git://src.adamsgaard.dk/Granular.jl | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit ea2796081adee6a056d0df05fba1ec0163ddcf0c | |
parent ba27e7cf2151993e2d59aa43b13401a7aea19e5d | |
Author: Anders Damsgaard <[email protected]> | |
Date: Wed, 3 Jan 2018 10:42:11 -0500 | |
Add data structures and handling of fields associated with regular grids | |
Diffstat: | |
M src/atmosphere.jl | 7 +++++-- | |
M src/datatypes.jl | 16 ++++++++++++++++ | |
M src/grid.jl | 8 ++++++++ | |
M src/ocean.jl | 21 ++++++++++++++------- | |
M test/memory-management.jl | 2 +- | |
M test/runtests.jl | 10 +++++----- | |
6 files changed, 49 insertions(+), 15 deletions(-) | |
--- | |
diff --git a/src/atmosphere.jl b/src/atmosphere.jl | |
t@@ -21,7 +21,9 @@ function createEmptyAtmosphere() | |
1, 1, 1, 1, | |
- false) | |
+ false, | |
+ | |
+ false, [1.,1.,1.], [1,1,1], [1.,1.,1.]) | |
end | |
export interpolateAtmosphereVelocitiesToCorners | |
t@@ -138,7 +140,8 @@ function createRegularAtmosphereGrid(n::Vector{Int}, | |
u, v, | |
Array{Array{Int, 1}}(size(xh, 1), size(xh, 2)), | |
bc_west, bc_south, bc_east, bc_north, | |
- false) | |
+ false, | |
+ true, L, n, dx) | |
end | |
export addAtmosphereDrag! | |
diff --git a/src/datatypes.jl b/src/datatypes.jl | |
t@@ -237,6 +237,14 @@ mutable struct Ocean | |
bc_south::Integer | |
bc_east::Integer | |
bc_north::Integer | |
+ | |
+ # If the grid is regular, allow for simpler particle sorting | |
+ regular_grid::Bool | |
+ | |
+ # Grid size when regular_grid == true | |
+ L::Vector{Float64} # Grid length | |
+ n::Vector{Integer} # Cell count | |
+ dx::Vector{Float64} # Cell size | |
end | |
#= | |
t@@ -313,6 +321,14 @@ mutable struct Atmosphere | |
# If true the grid positions are identical to the ocean grid | |
collocated_with_ocean_grid::Bool | |
+ | |
+ # If the grid is regular, allow for simpler particle sorting | |
+ regular_grid::Bool | |
+ | |
+ # Grid size when regular_grid == true | |
+ L::Vector{Float64} # Grid length | |
+ n::Vector{Integer} # Cell count | |
+ dx::Vector{Float64} # Cell size | |
end | |
# Top-level simulation type | |
diff --git a/src/grid.jl b/src/grid.jl | |
t@@ -284,6 +284,14 @@ function isPointInCell(grid::Any, i::Int, j::Int, | |
nw::Vector{Float64} = Vector{Float64}(2); | |
method::String="Conformal") | |
+ #=if grid.regular_grid | |
+ if [i,j] == Int.(ceil.(point ./ grid.dx[1:2])) | |
+ return true | |
+ else | |
+ return false | |
+ end | |
+ end=# | |
+ | |
@views sw .= grid.xq[ i, j], grid.yq[ i, j] | |
@views se .= grid.xq[ i+1, j], grid.yq[ i+1, j] | |
@views ne .= grid.xq[ i+1, j+1], grid.yq[ i+1, j+1] | |
diff --git a/src/ocean.jl b/src/ocean.jl | |
t@@ -20,7 +20,8 @@ function createEmptyOcean() | |
zeros(1,1,1,1), | |
zeros(1,1,1,1), | |
Array{Array{Int, 1}}(1, 1), | |
- 1, 1, 1, 1) | |
+ 1, 1, 1, 1, | |
+ false, [1.,1.,1.], [1,1,1], [1.,1.,1.]) | |
end | |
export readOceanNetCDF | |
t@@ -29,12 +30,15 @@ Read ocean NetCDF files generated by MOM6 from disk and re… | |
structure. | |
# Arguments | |
-* `velocity_file::String`: Path to NetCDF file containing ocean velocities, | |
+* `velocity_file::String`: path to NetCDF file containing ocean velocities, | |
etc., (e.g. `prog__####_###.nc`). | |
-* `grid_file::String`: Path to NetCDF file containing ocean super-grid | |
+* `grid_file::String`: path to NetCDF file containing ocean super-grid | |
information (typically `INPUT/ocean_hgrid.nc`). | |
+* `regular_grid::Bool=false`: `true` if the grid is regular (all cells | |
+ equal and grid is Cartesian) or `false` (default). | |
""" | |
-function readOceanNetCDF(velocity_file::String, grid_file::String) | |
+function readOceanNetCDF(velocity_file::String, grid_file::String; | |
+ regular_grid::Bool=false) | |
time, u, v, h, e, zl, zi = readOceanStateNetCDF(velocity_file) | |
xh, yh, xq, yq = readOceanGridNetCDF(grid_file) | |
t@@ -63,7 +67,9 @@ function readOceanNetCDF(velocity_file::String, grid_file::S… | |
h, | |
e, | |
Array{Array{Int, 1}}(size(xh, 1), size(xh, 2)), | |
- 1, 1, 1, 1 | |
+ 1, 1, 1, 1, | |
+ | |
+ false, [1.,1.,1.], [1,1,1], [1.,1.,1.] | |
) | |
return ocean | |
end | |
t@@ -216,7 +222,7 @@ one 4-th dimension matrix per `time` step. Sea surface wi… | |
the ocean spanning `z<0.`. Vertical indexing starts with `k=0` at the sea | |
surface, and increases downwards. | |
""" | |
-function createRegularOceanGrid(n::Array{Int, 1}, | |
+function createRegularOceanGrid(n::Vector{Int}, | |
L::Vector{Float64}; | |
origo::Vector{Float64} = zeros(2), | |
time::Vector{Float64} = zeros(1), | |
t@@ -250,7 +256,8 @@ function createRegularOceanGrid(n::Array{Int, 1}, | |
zl, zi, | |
u, v, h, e, | |
Array{Array{Int, 1}}(size(xh, 1), size(xh, 2)), | |
- bc_west, bc_south, bc_east, bc_north) | |
+ bc_west, bc_south, bc_east, bc_north, | |
+ true, L, n, dx) | |
end | |
export addOceanDrag! | |
diff --git a/test/memory-management.jl b/test/memory-management.jl | |
t@@ -6,7 +6,7 @@ info("Testing memory footprint of Granular types") | |
sim = Granular.createSimulation() | |
empty_sim_size = 104 | |
-empty_sim_size_recursive = 552 | |
+empty_sim_size_recursive = 752 | |
@test sizeof(sim) == empty_sim_size | |
@test Base.summarysize(sim) == empty_sim_size_recursive | |
diff --git a/test/runtests.jl b/test/runtests.jl | |
t@@ -1,12 +1,16 @@ | |
using Compat.Test | |
import Granular | |
+include("grid.jl") | |
+include("contact-search-and-geometry.jl") | |
+include("grid-boundaries.jl") | |
+include("ocean.jl") | |
+include("atmosphere.jl") | |
include("wall.jl") | |
include("grain.jl") | |
include("packing.jl") | |
include("util.jl") | |
include("temporal.jl") | |
-include("contact-search-and-geometry.jl") | |
include("collision-2floes-normal.jl") | |
include("collision-5floes-normal.jl") | |
include("collision-2floes-oblique.jl") | |
t@@ -14,8 +18,4 @@ include("cohesion.jl") | |
include("netcdf.jl") | |
include("vtk.jl") | |
include("jld.jl") | |
-include("grid.jl") | |
-include("grid-boundaries.jl") | |
-include("ocean.jl") | |
-include("atmosphere.jl") | |
include("memory-management.jl") |