comparison test/Grids/equidistant_grid_test.jl @ 1133:a8c8517a310f feature/boundary_conditions

Merge with default
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Wed, 05 Oct 2022 22:05:23 +0200
parents dfbd62c7eb09
children 9275d95e2d90 102ebdaf7c11
comparison
equal deleted inserted replaced
1132:302d36b5ba8e 1133:a8c8517a310f
15 @testset "Base" begin 15 @testset "Base" begin
16 @test eltype(EquidistantGrid(4,0.0,1.0)) == Float64 16 @test eltype(EquidistantGrid(4,0.0,1.0)) == Float64
17 @test eltype(EquidistantGrid((4,3),(0,0),(1,3))) == Int 17 @test eltype(EquidistantGrid((4,3),(0,0),(1,3))) == Int
18 @test size(EquidistantGrid(4,0.0,1.0)) == (4,) 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) 19 @test size(EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))) == (5,3)
20 @test ndims(EquidistantGrid(4,0.0,1.0)) == 1
21 @test ndims(EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))) == 2
20 end 22 end
21 23
22 # dim 24 @testset "spacing" begin
23 @test dim(EquidistantGrid(4,0.0,1.0)) == 1 25 @test [spacing(EquidistantGrid(4,0.0,1.0))...] ≈ [(1. /3,)...] atol=5e-13
24 @test dim(EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))) == 2 26 @test [spacing(EquidistantGrid((5,3), (0.0,-1.0), (2.0,1.0)))...] ≈ [(0.5, 1.)...] atol=5e-13
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 27 end
45 28
46 # restrict 29 @testset "inverse_spacing" begin
47 g = EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0)) 30 @test [inverse_spacing(EquidistantGrid(4,0.0,1.0))...] ≈ [(3.,)...] atol=5e-13
48 @test restrict(g, 1) == EquidistantGrid(5,0.0,2.0) 31 @test [inverse_spacing(EquidistantGrid((5,3), (0.0,-1.0), (2.0,1.0)))...] ≈ [(2, 1.)...] atol=5e-13
49 @test restrict(g, 2) == EquidistantGrid(3,0.0,1.0) 32 end
50 33
51 g = EquidistantGrid((2,5,3), (0.0,0.0,0.0), (2.0,1.0,3.0)) 34 @testset "points" begin
52 @test restrict(g, 1) == EquidistantGrid(2,0.0,2.0) 35 g = EquidistantGrid((5,3), (-1.0,0.0), (0.0,7.11))
53 @test restrict(g, 2) == EquidistantGrid(5,0.0,1.0) 36 gp = points(g);
54 @test restrict(g, 3) == EquidistantGrid(3,0.0,3.0) 37 p = [(-1.,0.) (-1.,7.11/2) (-1.,7.11);
55 @test restrict(g, 1:2) == EquidistantGrid((2,5),(0.0,0.0),(2.0,1.0)) 38 (-0.75,0.) (-0.75,7.11/2) (-0.75,7.11);
56 @test restrict(g, 2:3) == EquidistantGrid((5,3),(0.0,0.0),(1.0,3.0)) 39 (-0.5,0.) (-0.5,7.11/2) (-0.5,7.11);
57 @test restrict(g, [1,3]) == EquidistantGrid((2,3),(0.0,0.0),(2.0,3.0)) 40 (-0.25,0.) (-0.25,7.11/2) (-0.25,7.11);
58 @test restrict(g, [2,1]) == EquidistantGrid((5,2),(0.0,0.0),(1.0,2.0)) 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 end
46
47 @testset "restrict" begin
48 g = EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))
49 @test restrict(g, 1) == EquidistantGrid(5,0.0,2.0)
50 @test restrict(g, 2) == EquidistantGrid(3,0.0,1.0)
51
52 g = EquidistantGrid((2,5,3), (0.0,0.0,0.0), (2.0,1.0,3.0))
53 @test restrict(g, 1) == EquidistantGrid(2,0.0,2.0)
54 @test restrict(g, 2) == EquidistantGrid(5,0.0,1.0)
55 @test restrict(g, 3) == EquidistantGrid(3,0.0,3.0)
56 @test restrict(g, 1:2) == EquidistantGrid((2,5),(0.0,0.0),(2.0,1.0))
57 @test restrict(g, 2:3) == EquidistantGrid((5,3),(0.0,0.0),(1.0,3.0))
58 @test restrict(g, [1,3]) == EquidistantGrid((2,3),(0.0,0.0),(2.0,3.0))
59 @test restrict(g, [2,1]) == EquidistantGrid((5,2),(0.0,0.0),(1.0,2.0))
60 end
59 61
60 @testset "boundary_identifiers" begin 62 @testset "boundary_identifiers" begin
61 g = EquidistantGrid((2,5,3), (0.0,0.0,0.0), (2.0,1.0,3.0)) 63 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}(), 64 bids = (CartesianBoundary{1,Lower}(),CartesianBoundary{1,Upper}(),
63 CartesianBoundary{2,Lower}(),CartesianBoundary{2,Upper}(), 65 CartesianBoundary{2,Lower}(),CartesianBoundary{2,Upper}(),