Mercurial > repos > public > sbplib_julia
changeset 680:1d3e29ffc6c6 feature/boundary_quads
Add support for 0-dimensional grid, and add method boundary_grid
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Mon, 08 Feb 2021 18:43:38 +0100 |
parents | 1ce3a104afc8 |
children | 43cf58c69f91 |
files | src/Grids/EquidistantGrid.jl test/testGrids.jl |
diffstat | 2 files changed, 55 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Grids/EquidistantGrid.jl Sun Feb 07 21:28:53 2021 +0100 +++ b/src/Grids/EquidistantGrid.jl Mon Feb 08 18:43:38 2021 +0100 @@ -22,6 +22,13 @@ end return new{Dim,T}(size, limit_lower, limit_upper) end + + # Special constructor for 0-dimensional grids. + function EquidistantGrid(size::Tuple{}, limit_lower::Tuple{}, limit_upper::Tuple{}) + #TODO: Need to specialize T. + # Is Float64 a good choice here? How to propage from arguments? + return new{0,Float64}(size, limit_lower, limit_upper) + end end export EquidistantGrid @@ -104,3 +111,21 @@ """ boundary_identifiers(g::EquidistantGrid) = (((ntuple(i->(CartesianBoundary{i,Lower}(),CartesianBoundary{i,Upper}()),dimension(g)))...)...,) export boundary_identifiers + + +""" + boundary_grid(grid::EquidistantGrid,id::CartesianBoundary) + boundary_grid(::EquidistantGrid{1},::CartesianBoundary{1}) + +Creates the lower-dimensional restriciton of `grid` spanned by the dimensions +orthogonal to the boundary specified by `id`. The boundary grid of a 1-dimensional +grid is a zero-dimensional grid. +""" +function boundary_grid(grid::EquidistantGrid,id::CartesianBoundary) + dims = collect(1:dimension(grid)) + orth_dims = dims[dims .!= dim(id)] + return restrict(grid,orth_dims) +end +export boundary_grid +boundary_grid(::EquidistantGrid{1},::CartesianBoundary{1}) = EquidistantGrid((),(),()) +boundary_grid(::EquidistantGrid{1},::CartesianBoundary) = throw(DimensionMismatch("dimension of Grid and BoundaryIdentifier not matching"))
--- a/test/testGrids.jl Sun Feb 07 21:28:53 2021 +0100 +++ b/test/testGrids.jl Mon Feb 08 18:43:38 2021 +0100 @@ -63,6 +63,36 @@ @test boundary_identifiers(g) == bids @inferred boundary_identifiers(g) end + + @testset "boundary_grid" begin + @testset "1D" begin + g = EquidistantGrid(5,0.0,2.0) + (id_l, id_r) = boundary_identifiers(g) + @test boundary_grid(g,id_l) == EquidistantGrid((),(),()) + @test boundary_grid(g,id_r) == EquidistantGrid((),(),()) + + end + @testset "2D" begin + g = EquidistantGrid((5,3),(0.0,0.0),(1.0,3.0)) + (id_w, id_e, id_s, id_n) = boundary_identifiers(g) + @test boundary_grid(g,id_w) == restrict(g,2) + @test boundary_grid(g,id_e) == restrict(g,2) + @test boundary_grid(g,id_s) == restrict(g,1) + @test boundary_grid(g,id_n) == restrict(g,1) + end + @testset "3D" begin + g = EquidistantGrid((2,5,3), (0.0,0.0,0.0), (2.0,1.0,3.0)) + (id_w, id_e, + id_s, id_n, + id_t, id_b) = boundary_identifiers(g) + @test boundary_grid(g,id_w) == restrict(g,[2,3]) + @test boundary_grid(g,id_e) == restrict(g,[2,3]) + @test boundary_grid(g,id_s) == restrict(g,[1,3]) + @test boundary_grid(g,id_n) == restrict(g,[1,3]) + @test boundary_grid(g,id_t) == restrict(g,[1,2]) + @test boundary_grid(g,id_b) == restrict(g,[1,2]) + end + end end end