Mercurial > repos > public > sbplib_julia
changeset 1128:dfbd62c7eb09 feature/grids
Rename dim to ndims in Grids.jl
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Wed, 05 Oct 2022 22:00:30 +0200 |
parents | 5490d0a38007 |
children | 2d231546c091 |
files | src/Grids/Grids.jl src/Grids/equidistant_grid.jl src/Grids/grid.jl src/SbpOperators/volumeops/laplace/laplace.jl test/Grids/equidistant_grid_test.jl |
diffstat | 5 files changed, 12 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Grids/Grids.jl Wed Oct 05 21:26:37 2022 +0200 +++ b/src/Grids/Grids.jl Wed Oct 05 22:00:30 2022 +0200 @@ -4,7 +4,6 @@ # Grid export Grid -export dim export dims export points export evalOn
--- a/src/Grids/equidistant_grid.jl Wed Oct 05 21:26:37 2022 +0200 +++ b/src/Grids/equidistant_grid.jl Wed Oct 05 22:00:30 2022 +0200 @@ -62,13 +62,10 @@ Base.size(g::EquidistantGrid) = g.size - -""" - dim(grid::EquidistantGrid) +Base.ndims(::EquidistantGrid{Dim}) where Dim = Dim -The dimension of the grid. -""" -dim(::EquidistantGrid{Dim}) where Dim = Dim + + """ @@ -140,7 +137,7 @@ CartesianBoundary(2,Lower), ...) """ -boundary_identifiers(g::EquidistantGrid) = (((ntuple(i->(CartesianBoundary{i,Lower}(),CartesianBoundary{i,Upper}()),dim(g)))...)...,) +boundary_identifiers(g::EquidistantGrid) = (((ntuple(i->(CartesianBoundary{i,Lower}(),CartesianBoundary{i,Upper}()),ndims(g)))...)...,) """ @@ -168,7 +165,7 @@ function refine(grid::EquidistantGrid, r::Int) sz = size(grid) new_sz = (sz .- 1).*r .+ 1 - return EquidistantGrid{dim(grid), eltype(grid)}(new_sz, grid.limit_lower, grid.limit_upper) + return EquidistantGrid{ndims(grid), eltype(grid)}(new_sz, grid.limit_lower, grid.limit_upper) end @@ -190,5 +187,5 @@ new_sz = (sz .- 1).÷r .+ 1 - return EquidistantGrid{dim(grid), eltype(grid)}(new_sz, grid.limit_lower, grid.limit_upper) + return EquidistantGrid{ndims(grid), eltype(grid)}(new_sz, grid.limit_lower, grid.limit_upper) end
--- a/src/Grids/grid.jl Wed Oct 05 21:26:37 2022 +0200 +++ b/src/Grids/grid.jl Wed Oct 05 22:00:30 2022 +0200 @@ -2,12 +2,11 @@ Grid Should implement - dim(grid::Grid) + Base.ndims(grid::Grid) points(grid::Grid) """ abstract type Grid end -function dim end # TODO: Rename to Base.ndims instead? That's the name used for arrays. function points end """ @@ -15,7 +14,7 @@ A range containing the dimensions of `grid` """ -dims(grid::Grid) = 1:dim(grid) +dims(grid::Grid) = 1:ndims(grid) """ evalOn(grid::Grid, f::Function) @@ -25,4 +24,4 @@ function evalOn(grid::Grid, f::Function) F(x) = f(x...) return F.(points(grid)) -end \ No newline at end of file +end
--- a/src/SbpOperators/volumeops/laplace/laplace.jl Wed Oct 05 21:26:37 2022 +0200 +++ b/src/SbpOperators/volumeops/laplace/laplace.jl Wed Oct 05 22:00:30 2022 +0200 @@ -48,7 +48,7 @@ """ function laplace(grid::EquidistantGrid, inner_stencil, closure_stencils) Δ = second_derivative(grid, inner_stencil, closure_stencils, 1) - for d = 2:dim(grid) + for d = 2:ndims(grid) Δ += second_derivative(grid, inner_stencil, closure_stencils, d) end return Δ
--- a/test/Grids/equidistant_grid_test.jl Wed Oct 05 21:26:37 2022 +0200 +++ b/test/Grids/equidistant_grid_test.jl Wed Oct 05 22:00:30 2022 +0200 @@ -17,12 +17,10 @@ @test eltype(EquidistantGrid((4,3),(0,0),(1,3))) == Int @test size(EquidistantGrid(4,0.0,1.0)) == (4,) @test size(EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))) == (5,3) + @test ndims(EquidistantGrid(4,0.0,1.0)) == 1 + @test ndims(EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))) == 2 end - # dim - @test dim(EquidistantGrid(4,0.0,1.0)) == 1 - @test dim(EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))) == 2 - @testset "spacing" begin @test [spacing(EquidistantGrid(4,0.0,1.0))...] ≈ [(1. /3,)...] atol=5e-13 @test [spacing(EquidistantGrid((5,3), (0.0,-1.0), (2.0,1.0)))...] ≈ [(0.5, 1.)...] atol=5e-13