Mercurial > repos > public > sbplib_julia
comparison test/Grids/equidistant_grid_test.jl @ 1116:c2d7e940639e feature/grids
Rename AbstractGrid to Grid and clean up Grids module
| author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
|---|---|
| date | Fri, 15 Jul 2022 09:54:15 +0200 |
| parents | test/Grids/EquidistantGrid_test.jl@6530fceef37c |
| children | b9c6b0d8f0fa |
comparison
equal
deleted
inserted
replaced
| 1115:6530fceef37c | 1116:c2d7e940639e |
|---|---|
| 1 using Sbplib.Grids | |
| 2 using Test | |
| 3 using Sbplib.RegionIndices | |
| 4 | |
| 5 | |
| 6 @testset "EquidistantGrid" begin | |
| 7 @test EquidistantGrid(4,0.0,1.0) isa EquidistantGrid | |
| 8 @test EquidistantGrid(4,0.0,8.0) isa EquidistantGrid | |
| 9 # constuctor | |
| 10 @test_throws DomainError EquidistantGrid(0,0.0,1.0) | |
| 11 @test_throws DomainError EquidistantGrid(1,1.0,1.0) | |
| 12 @test_throws DomainError EquidistantGrid(1,1.0,-1.0) | |
| 13 @test EquidistantGrid(4,0.0,1.0) == EquidistantGrid((4,),(0.0,),(1.0,)) | |
| 14 | |
| 15 @testset "Base" begin | |
| 16 @test eltype(EquidistantGrid(4,0.0,1.0)) == Float64 | |
| 17 @test eltype(EquidistantGrid((4,3),(0,0),(1,3))) == Int | |
| 18 @test size(EquidistantGrid(4,0.0,1.0)) == (4,) | |
| 19 @test size(EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))) == (5,3) | |
| 20 end | |
| 21 | |
| 22 # dim | |
| 23 @test dim(EquidistantGrid(4,0.0,1.0)) == 1 | |
| 24 @test dim(EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))) == 2 | |
| 25 | |
| 26 # spacing | |
| 27 @test [spacing(EquidistantGrid(4,0.0,1.0))...] ≈ [(1. /3,)...] atol=5e-13 | |
| 28 @test [spacing(EquidistantGrid((5,3), (0.0,-1.0), (2.0,1.0)))...] ≈ [(0.5, 1.)...] atol=5e-13 | |
| 29 | |
| 30 # inverse_spacing | |
| 31 @test [inverse_spacing(EquidistantGrid(4,0.0,1.0))...] ≈ [(3.,)...] atol=5e-13 | |
| 32 @test [inverse_spacing(EquidistantGrid((5,3), (0.0,-1.0), (2.0,1.0)))...] ≈ [(2, 1.)...] atol=5e-13 | |
| 33 | |
| 34 # points | |
| 35 g = EquidistantGrid((5,3), (-1.0,0.0), (0.0,7.11)) | |
| 36 gp = points(g); | |
| 37 p = [(-1.,0.) (-1.,7.11/2) (-1.,7.11); | |
| 38 (-0.75,0.) (-0.75,7.11/2) (-0.75,7.11); | |
| 39 (-0.5,0.) (-0.5,7.11/2) (-0.5,7.11); | |
| 40 (-0.25,0.) (-0.25,7.11/2) (-0.25,7.11); | |
| 41 (0.,0.) (0.,7.11/2) (0.,7.11)] | |
| 42 for i ∈ eachindex(gp) | |
| 43 @test [gp[i]...] ≈ [p[i]...] atol=5e-13 | |
| 44 end | |
| 45 | |
| 46 # restrict | |
| 47 g = EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0)) | |
| 48 @test restrict(g, 1) == EquidistantGrid(5,0.0,2.0) | |
| 49 @test restrict(g, 2) == EquidistantGrid(3,0.0,1.0) | |
| 50 | |
| 51 g = EquidistantGrid((2,5,3), (0.0,0.0,0.0), (2.0,1.0,3.0)) | |
| 52 @test restrict(g, 1) == EquidistantGrid(2,0.0,2.0) | |
| 53 @test restrict(g, 2) == EquidistantGrid(5,0.0,1.0) | |
| 54 @test restrict(g, 3) == EquidistantGrid(3,0.0,3.0) | |
| 55 @test restrict(g, 1:2) == EquidistantGrid((2,5),(0.0,0.0),(2.0,1.0)) | |
| 56 @test restrict(g, 2:3) == EquidistantGrid((5,3),(0.0,0.0),(1.0,3.0)) | |
| 57 @test restrict(g, [1,3]) == EquidistantGrid((2,3),(0.0,0.0),(2.0,3.0)) | |
| 58 @test restrict(g, [2,1]) == EquidistantGrid((5,2),(0.0,0.0),(1.0,2.0)) | |
| 59 | |
| 60 @testset "boundary_identifiers" begin | |
| 61 g = EquidistantGrid((2,5,3), (0.0,0.0,0.0), (2.0,1.0,3.0)) | |
| 62 bids = (CartesianBoundary{1,Lower}(),CartesianBoundary{1,Upper}(), | |
| 63 CartesianBoundary{2,Lower}(),CartesianBoundary{2,Upper}(), | |
| 64 CartesianBoundary{3,Lower}(),CartesianBoundary{3,Upper}()) | |
| 65 @test boundary_identifiers(g) == bids | |
| 66 @inferred boundary_identifiers(g) | |
| 67 end | |
| 68 | |
| 69 @testset "boundary_grid" begin | |
| 70 @testset "1D" begin | |
| 71 g = EquidistantGrid(5,0.0,2.0) | |
| 72 (id_l, id_r) = boundary_identifiers(g) | |
| 73 @test boundary_grid(g,id_l) == EquidistantGrid{Float64}() | |
| 74 @test boundary_grid(g,id_r) == EquidistantGrid{Float64}() | |
| 75 @test_throws DomainError boundary_grid(g,CartesianBoundary{2,Lower}()) | |
| 76 @test_throws DomainError boundary_grid(g,CartesianBoundary{0,Lower}()) | |
| 77 end | |
| 78 @testset "2D" begin | |
| 79 g = EquidistantGrid((5,3),(0.0,0.0),(1.0,3.0)) | |
| 80 (id_w, id_e, id_s, id_n) = boundary_identifiers(g) | |
| 81 @test boundary_grid(g,id_w) == restrict(g,2) | |
| 82 @test boundary_grid(g,id_e) == restrict(g,2) | |
| 83 @test boundary_grid(g,id_s) == restrict(g,1) | |
| 84 @test boundary_grid(g,id_n) == restrict(g,1) | |
| 85 @test_throws DomainError boundary_grid(g,CartesianBoundary{4,Lower}()) | |
| 86 end | |
| 87 @testset "3D" begin | |
| 88 g = EquidistantGrid((2,5,3), (0.0,0.0,0.0), (2.0,1.0,3.0)) | |
| 89 (id_w, id_e, | |
| 90 id_s, id_n, | |
| 91 id_t, id_b) = boundary_identifiers(g) | |
| 92 @test boundary_grid(g,id_w) == restrict(g,[2,3]) | |
| 93 @test boundary_grid(g,id_e) == restrict(g,[2,3]) | |
| 94 @test boundary_grid(g,id_s) == restrict(g,[1,3]) | |
| 95 @test boundary_grid(g,id_n) == restrict(g,[1,3]) | |
| 96 @test boundary_grid(g,id_t) == restrict(g,[1,2]) | |
| 97 @test boundary_grid(g,id_b) == restrict(g,[1,2]) | |
| 98 @test_throws DomainError boundary_grid(g,CartesianBoundary{4,Lower}()) | |
| 99 end | |
| 100 end | |
| 101 | |
| 102 @testset "refine" begin | |
| 103 @test refine(EquidistantGrid{Float64}(), 1) == EquidistantGrid{Float64}() | |
| 104 @test refine(EquidistantGrid{Float64}(), 2) == EquidistantGrid{Float64}() | |
| 105 | |
| 106 g = EquidistantGrid((10,5),(0.,1.),(2.,3.)) | |
| 107 @test refine(g, 1) == g | |
| 108 @test refine(g, 2) == EquidistantGrid((19,9),(0.,1.),(2.,3.)) | |
| 109 @test refine(g, 3) == EquidistantGrid((28,13),(0.,1.),(2.,3.)) | |
| 110 end | |
| 111 | |
| 112 @testset "coarsen" begin | |
| 113 @test coarsen(EquidistantGrid{Float64}(), 1) == EquidistantGrid{Float64}() | |
| 114 @test coarsen(EquidistantGrid{Float64}(), 2) == EquidistantGrid{Float64}() | |
| 115 | |
| 116 g = EquidistantGrid((7,13),(0.,1.),(2.,3.)) | |
| 117 @test coarsen(g, 1) == g | |
| 118 @test coarsen(g, 2) == EquidistantGrid((4,7),(0.,1.),(2.,3.)) | |
| 119 @test coarsen(g, 3) == EquidistantGrid((3,5),(0.,1.),(2.,3.)) | |
| 120 | |
| 121 @test_throws DomainError(4, "Size minus 1 must be divisible by the ratio.") coarsen(g, 4) == EquidistantGrid((3,5),(0.,1.),(2.,3.)) | |
| 122 end | |
| 123 end |
