tAllow for grid BC specification via coordinate system axes - Granular.jl - Jul… | |
git clone git://src.adamsgaard.dk/Granular.jl | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit b346a38af7d1ceed4ca36d6b2253b34200ddd183 | |
parent 1066430542dfb0b2ec929f5c712adc581e3d0c46 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Fri, 4 May 2018 10:47:08 -0400 | |
Allow for grid BC specification via coordinate system axes | |
Diffstat: | |
M src/grid.jl | 18 ++++++++++++------ | |
M test/grid-boundaries.jl | 51 +++++++++++++++++++++++++++++… | |
2 files changed, 63 insertions(+), 6 deletions(-) | |
--- | |
diff --git a/src/grid.jl b/src/grid.jl | |
t@@ -698,7 +698,8 @@ Grains can interact mechanically across the periodic bound… | |
* `grid::Any`: `Ocean` or `Atmosphere` grid to apply the boundary condition to. | |
* `grid_face::String`: Grid face to apply the boundary condition to. Valid | |
values are any combination and sequence of `"west"` (-x), `"south"` (-y), | |
- `"east"` (+x), `"north"` (+y). The values may be delimited in any way. | |
+ `"east"` (+x), `"north"` (+y), or simply any combination of `"-x"`, `"+x"`, | |
+ `"-y"`, and `"+y"`. The specifiers may be delimited in any way. | |
Also, and by default, all boundaries can be selected with `"all"` (-x, -y, | |
+x, +y), which overrides any other face selection. | |
* `mode::String`: Boundary behavior, accepted values are `"inactive"`, | |
t@@ -718,6 +719,11 @@ be periodic: | |
setGridBoundaryConditions!(ocean, "inactive", "south north") | |
setGridBoundaryConditions!(ocean, "periodic", "west east") | |
+or specify the conditions from the coordinate system axes: | |
+ | |
+ setGridBoundaryConditions!(ocean, "inactive", "-y +y") | |
+ setGridBoundaryConditions!(ocean, "periodic", "-x +x") | |
+ | |
""" | |
function setGridBoundaryConditions!(grid::Any, | |
mode::String, | |
t@@ -734,22 +740,22 @@ function setGridBoundaryConditions!(grid::Any, | |
error("Mode '$mode' not recognized as a valid boundary condition type") | |
end | |
- if Compat.occursin("west", grid_face) | |
+ if Compat.occursin("west", grid_face) || Compat.occursin("-x", grid_face) | |
grid.bc_west = grid_bc_flags[mode] | |
something_changed = true | |
end | |
- if Compat.occursin("south", grid_face) | |
+ if Compat.occursin("south", grid_face) || Compat.occursin("-y", grid_face) | |
grid.bc_south = grid_bc_flags[mode] | |
something_changed = true | |
end | |
- if Compat.occursin("east", grid_face) | |
+ if Compat.occursin("east", grid_face) || Compat.occursin("+x", grid_face) | |
grid.bc_east = grid_bc_flags[mode] | |
something_changed = true | |
end | |
- if Compat.occursin("north", grid_face) | |
+ if Compat.occursin("north", grid_face) || Compat.occursin("+y", grid_face) | |
grid.bc_north = grid_bc_flags[mode] | |
something_changed = true | |
end | |
t@@ -764,7 +770,7 @@ function setGridBoundaryConditions!(grid::Any, | |
if !something_changed | |
error("grid_face string '$grid_face' not understood, " * | |
- "must be east, west, north, and/or south.") | |
+ "must be east, west, north, south, -x, +x, -y, and/or +y.") | |
end | |
if verbose | |
diff --git a/test/grid-boundaries.jl b/test/grid-boundaries.jl | |
t@@ -44,6 +44,57 @@ if !Compat.Sys.iswindows() | |
@test ocean.bc_north == 1 | |
@test ocean.bc_south == 2 | |
+ Granular.setGridBoundaryConditions!(ocean, "inactive", "all", verbose=fals… | |
+ (out_r, out_w) = redirect_stdout() | |
+ Granular.setGridBoundaryConditions!(ocean, "periodic", "-y, -x", | |
+ verbose=true) | |
+ close(out_w) | |
+ redirect_stdout(originalSTDOUT) | |
+ output = String(readavailable(out_r)) | |
+ @test output == """West (-x): periodic\t(2) | |
+ East (+x): inactive\t(1) | |
+ South (-y): periodic\t(2) | |
+ North (+y): inactive\t(1) | |
+ """ | |
+ @test ocean.bc_west == 2 | |
+ @test ocean.bc_east == 1 | |
+ @test ocean.bc_north == 1 | |
+ @test ocean.bc_south == 2 | |
+ | |
+ Granular.setGridBoundaryConditions!(ocean, "inactive", "all", verbose=fals… | |
+ (out_r, out_w) = redirect_stdout() | |
+ Granular.setGridBoundaryConditions!(ocean, "periodic", "north, east", | |
+ verbose=true) | |
+ close(out_w) | |
+ redirect_stdout(originalSTDOUT) | |
+ output = String(readavailable(out_r)) | |
+ @test output == """West (-x): inactive\t(1) | |
+ East (+x): periodic\t(2) | |
+ South (-y): inactive\t(1) | |
+ North (+y): periodic\t(2) | |
+ """ | |
+ @test ocean.bc_west == 1 | |
+ @test ocean.bc_east == 2 | |
+ @test ocean.bc_north == 2 | |
+ @test ocean.bc_south == 1 | |
+ | |
+ Granular.setGridBoundaryConditions!(ocean, "inactive", "all", verbose=fals… | |
+ (out_r, out_w) = redirect_stdout() | |
+ Granular.setGridBoundaryConditions!(ocean, "periodic", "+y, +x", | |
+ verbose=true) | |
+ close(out_w) | |
+ redirect_stdout(originalSTDOUT) | |
+ output = String(readavailable(out_r)) | |
+ @test output == """West (-x): inactive\t(1) | |
+ East (+x): periodic\t(2) | |
+ South (-y): inactive\t(1) | |
+ North (+y): periodic\t(2) | |
+ """ | |
+ @test ocean.bc_west == 1 | |
+ @test ocean.bc_east == 2 | |
+ @test ocean.bc_north == 2 | |
+ @test ocean.bc_south == 1 | |
+ | |
(out_r, out_w) = redirect_stdout() | |
Granular.setGridBoundaryConditions!(ocean, "inactive", "all", verbose=fals… | |
close(out_w) |