comparison test/Grids/curvilinear_grid_test.jl @ 1450:647c8b18b84f feature/grids/curvilinear

Implement iterator interface
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 23 Nov 2023 10:16:19 +0100
parents af73340a8f0e
children 2e08f3444354
comparison
equal deleted inserted replaced
1449:a0b1449dba4e 1450:647c8b18b84f
60 end 60 end
61 end 61 end
62 # TODO: Test with different types of logical grids 62 # TODO: Test with different types of logical grids
63 63
64 @testset "Iterator interface" begin 64 @testset "Iterator interface" begin
65 # @test eltype(EquidistantGrid(0:10)) == Int 65 sg = CurvilinearGrid(
66 # @test eltype(EquidistantGrid(0:2:10)) == Int 66 equidistant_grid((15,11), (0,0), (1,1)),
67 # @test eltype(EquidistantGrid(0:0.1:10)) == Float64 67 map(ξ̄ -> @SArray[ξ̄[1], ξ̄[2], -ξ̄[1]], lg), rand(SMatrix{2,3,Float64},15,11)
68 )
68 69
69 # @test size(EquidistantGrid(0:10)) == (11,) 70 @test eltype(cg) == SVector{2,Float64}
70 # @test size(EquidistantGrid(0:0.1:10)) == (101,) 71 @test eltype(sg) == SVector{3,Float64}
71 72
72 # @test collect(EquidistantGrid(0:0.1:0.5)) == [0.0, 0.1, 0.2, 0.3, 0.4, 0.5] 73 @test eltype(typeof(cg)) == SVector{2,Float64}
74 @test eltype(typeof(sg)) == SVector{3,Float64}
73 75
74 # @test Base.IteratorSize(EquidistantGrid{Float64, StepRange{Float64}}) == Base.HasShape{1}() 76 @test size(cg) == (11,11)
77 @test size(sg) == (15,11)
78
79 @test size(cg,2) == 11
80 @test size(sg,2) == 11
81
82 @test length(cg) == 121
83 @test length(sg) == 165
84
85 @test Base.IteratorSize(cg) == Base.HasShape{2}()
86 @test Base.IteratorSize(typeof(cg)) == Base.HasShape{2}()
87
88 @test Base.IteratorSize(sg) == Base.HasShape{2}()
89 @test Base.IteratorSize(typeof(sg)) == Base.HasShape{2}()
90
91 element, state = iterate(cg)
92 @test element == lg[1,1].*2
93 element, _ = iterate(cg, state)
94 @test element == lg[2,1].*2
95
96 element, state = iterate(sg)
97 @test element == sg.physicalcoordinates[1,1]
98 element, _ = iterate(sg, state)
99 @test element == sg.physicalcoordinates[2,1]
100
101 @test collect(cg) == 2 .* lg
75 end 102 end
76 103
77 @testset "Base" begin 104 @testset "Base" begin
78 # @test ndims(EquidistantGrid(0:10)) == 1 105 # @test ndims(EquidistantGrid(0:10)) == 1
79 end 106 end