comparison test/Grids/mapped_grid_test.jl @ 1738:7573c9244e47 feature/grids/curvilinear

Factor out testset for construct and remove some Todos
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 10 Sep 2024 22:23:42 +0200
parents a4e1721a7109
children e1ae5d8e30c3
comparison
equal deleted inserted replaced
1737:a4e1721a7109 1738:7573c9244e47
26 26
27 return x̄, J 27 return x̄, J
28 end 28 end
29 29
30 @testset "MappedGrid" begin 30 @testset "MappedGrid" begin
31 lg = equidistant_grid((0,0), (1,1), 11, 21) 31 @testset "Constructor" begin
32 x̄ = map(ξ̄ -> 2ξ̄, lg) 32 lg = equidistant_grid((0,0), (1,1), 11, 21)
33 J = map(ξ̄ -> @SArray(fill(2., 2, 2)), lg) 33 x̄ = map(ξ̄ -> 2ξ̄, lg)
34 mg = MappedGrid(lg, x̄, J) 34 J = map(ξ̄ -> @SArray(fill(2., 2, 2)), lg)
35 35 mg = MappedGrid(lg, x̄, J)
36 # TODO: Test constructor for different dims of range and domain for the coordinates 36
37 # TODO: Test constructor with different type than TensorGrid. a dummy type? 37 # TODO: Test constructor for different dims of range and domain for the coordinates
38 # TODO: Test that the element types agree 38 # TODO: Test constructor with different type than TensorGrid. a dummy type?
39 39 # TODO: Test that the element types agree
40 @test_broken false # @test_throws ArgumentError("Sizes must match") MappedGrid(lg, map(ξ̄ -> @SArray[ξ̄[1], ξ̄[2], -ξ̄[1]], lg), rand(SMatrix{2,3,Float64},15,11)) 40
41 41 @test_broken false # @test_throws ArgumentError("Sizes must match") MappedGrid(lg, map(ξ̄ -> @SArray[ξ̄[1], ξ̄[2], -ξ̄[1]], lg), rand(SMatrix{2,3,Float64},15,11))
42 42
43 @test mg isa Grid{SVector{2, Float64},2} 43
44 44 @test mg isa Grid{SVector{2, Float64},2}
45 @test jacobian(mg) isa Array{<:AbstractMatrix} 45
46 @test logicalgrid(mg) isa Grid 46 @test jacobian(mg) isa Array{<:AbstractMatrix}
47 @test logicalgrid(mg) isa Grid
48 end
47 49
48 @testset "Indexing Interface" begin 50 @testset "Indexing Interface" begin
49 lg = equidistant_grid((0,0), (1,1), 11, 21) 51 lg = equidistant_grid((0,0), (1,1), 11, 21)
50 x̄ = map(ξ̄ -> 2ξ̄, lg) 52 x̄ = map(ξ̄ -> 2ξ̄, lg)
51 J = map(ξ̄ -> @SArray(fill(2., 2, 2)), lg) 53 J = map(ξ̄ -> @SArray(fill(2., 2, 2)), lg)
86 @testset "lastindex" begin 88 @testset "lastindex" begin
87 @test lastindex(mg, 1) == 11 89 @test lastindex(mg, 1) == 11
88 @test lastindex(mg, 2) == 21 90 @test lastindex(mg, 2) == 21
89 end 91 end
90 end 92 end
91 # TODO: Test with different types of logical grids
92 93
93 @testset "Iterator interface" begin 94 @testset "Iterator interface" begin
95 lg = equidistant_grid((0,0), (1,1), 11, 21)
96 x̄ = map(ξ̄ -> 2ξ̄, lg)
97 J = map(ξ̄ -> @SArray(fill(2., 2, 2)), lg)
98 mg = MappedGrid(lg, x̄, J)
99
94 sg = MappedGrid( 100 sg = MappedGrid(
95 equidistant_grid((0,0), (1,1), 15, 11), 101 equidistant_grid((0,0), (1,1), 15, 11),
96 map(ξ̄ -> @SArray[ξ̄[1], ξ̄[2], -ξ̄[1]], lg), rand(SMatrix{2,3,Float64},15,11) 102 map(ξ̄ -> @SArray[ξ̄[1], ξ̄[2], -ξ̄[1]], lg), rand(SMatrix{2,3,Float64},15,11)
97 ) 103 )
98 104
129 135
130 @test collect(mg) == 2 .* lg 136 @test collect(mg) == 2 .* lg
131 end 137 end
132 138
133 @testset "Base" begin 139 @testset "Base" begin
140 lg = equidistant_grid((0,0), (1,1), 11, 21)
141 x̄ = map(ξ̄ -> 2ξ̄, lg)
142 J = map(ξ̄ -> @SArray(fill(2., 2, 2)), lg)
143 mg = MappedGrid(lg, x̄, J)
144
134 @test ndims(mg) == 2 145 @test ndims(mg) == 2
135 end 146 end
136 147
137 @testset "==" begin 148 @testset "==" begin
138 sz = (15,11) 149 sz = (15,11)
158 @test sg != sg3 # Different coordinates 169 @test sg != sg3 # Different coordinates
159 @test sg != sg4 # Different jacobian 170 @test sg != sg4 # Different jacobian
160 end 171 end
161 172
162 @testset "boundary_identifiers" begin 173 @testset "boundary_identifiers" begin
163 lg = equidistant_grid((0,0), (1,1), 11, 11) # TODO: Change dims of the grid to be different 174 lg = equidistant_grid((0,0), (1,1), 11, 15)
164 x̄ = map(ξ̄ -> 2ξ̄, lg) 175 x̄ = map(ξ̄ -> 2ξ̄, lg)
165 J = map(ξ̄ -> @SArray(fill(2., 2, 2)), lg) 176 J = map(ξ̄ -> @SArray(fill(2., 2, 2)), lg)
166 mg = MappedGrid(lg, x̄, J) 177 mg = MappedGrid(lg, x̄, J)
167 @test boundary_identifiers(mg) == boundary_identifiers(lg) 178 @test boundary_identifiers(mg) == boundary_identifiers(lg)
168 end 179 end
169 180
170 @testset "boundary_indices" begin 181 @testset "boundary_indices" begin
171 lg = equidistant_grid((0,0), (1,1), 11, 11) # TODO: Change dims of the grid to be different 182 lg = equidistant_grid((0,0), (1,1), 11, 15)
172 x̄ = map(ξ̄ -> 2ξ̄, lg) 183 x̄ = map(ξ̄ -> 2ξ̄, lg)
173 J = map(ξ̄ -> @SArray(fill(2., 2, 2)), lg) 184 J = map(ξ̄ -> @SArray(fill(2., 2, 2)), lg)
174 mg = MappedGrid(lg, x̄, J) 185 mg = MappedGrid(lg, x̄, J)
175 186
176 @test boundary_indices(mg, CartesianBoundary{1,LowerBoundary}()) == boundary_indices(lg,CartesianBoundary{1,LowerBoundary}()) 187 @test boundary_indices(mg, CartesianBoundary{1,LowerBoundary}()) == boundary_indices(lg,CartesianBoundary{1,LowerBoundary}())