Mercurial > repos > public > sbplib_julia
comparison test/Grids/tensor_grid_test.jl @ 1829:871f3f1decea refactor/grids/iterable_boundary_indices
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sun, 20 Oct 2024 21:38:09 +0200 |
parents | 8adecef380b4 863385aae454 |
children | 27e74f524c4f |
comparison
equal
deleted
inserted
replaced
1828:8adecef380b4 | 1829:871f3f1decea |
---|---|
1 using Test | 1 using Test |
2 using Sbplib.Grids | 2 using Diffinitive.Grids |
3 using StaticArrays | 3 using StaticArrays |
4 using Sbplib.RegionIndices | |
5 | 4 |
6 @testset "TensorGrid" begin | 5 @testset "TensorGrid" begin |
7 g₁ = EquidistantGrid(range(0,1,length=11)) | 6 g₁ = EquidistantGrid(range(0,1,length=11)) |
8 g₂ = EquidistantGrid(range(2,3,length=6)) | 7 g₂ = EquidistantGrid(range(2,3,length=6)) |
9 g₃ = EquidistantGrid(1:10) | 8 g₃ = EquidistantGrid(1:10) |
136 @test axes(g, 1) == 1:11 | 135 @test axes(g, 1) == 1:11 |
137 @test axes(g, 2) == 1:6 | 136 @test axes(g, 2) == 1:6 |
138 @test axes(g) == (1:11,1:6) | 137 @test axes(g) == (1:11,1:6) |
139 end | 138 end |
140 | 139 |
140 @testset "min_spacing" begin | |
141 g₁ = EquidistantGrid(range(0,1,length=11)) | |
142 g₂ = EquidistantGrid(range(2,3,length=6)) | |
143 g₃ = ZeroDimGrid(@SVector[1,2]) | |
144 | |
145 @test min_spacing(TensorGrid(g₁, g₂)) == 1/10 | |
146 @test min_spacing(TensorGrid(g₂, g₃)) == 1/5 | |
147 end | |
148 | |
141 @testset "refine" begin | 149 @testset "refine" begin |
142 g1(n) = EquidistantGrid(range(0,1,length=n)) | 150 g1(n) = EquidistantGrid(range(0,1,length=n)) |
143 g2(n) = EquidistantGrid(range(2,3,length=n)) | 151 g2(n) = EquidistantGrid(range(2,3,length=n)) |
144 | 152 |
145 @test refine(TensorGrid(g1(11), g2(6)),1) == TensorGrid(g1(11), g2(6)) | 153 @test refine(TensorGrid(g1(11), g2(6)),1) == TensorGrid(g1(11), g2(6)) |
159 @test coarsen(TensorGrid(g1(11), g₄), 1) == TensorGrid(g1(11), g₄) | 167 @test coarsen(TensorGrid(g1(11), g₄), 1) == TensorGrid(g1(11), g₄) |
160 @test coarsen(TensorGrid(g1(21), g₄), 2) == TensorGrid(g1(11), g₄) | 168 @test coarsen(TensorGrid(g1(21), g₄), 2) == TensorGrid(g1(11), g₄) |
161 end | 169 end |
162 | 170 |
163 @testset "boundary_identifiers" begin | 171 @testset "boundary_identifiers" begin |
164 @test boundary_identifiers(TensorGrid(g₁, g₂)) == map((n,id)->TensorGridBoundary{n,id}(), (1,1,2,2), (Lower,Upper,Lower,Upper)) | 172 @test boundary_identifiers(TensorGrid(g₁, g₂)) == map((n,id)->TensorGridBoundary{n,id}(), (1,1,2,2), (LowerBoundary,UpperBoundary,LowerBoundary,UpperBoundary)) |
165 @test boundary_identifiers(TensorGrid(g₁, g₄)) == (TensorGridBoundary{1,Lower}(),TensorGridBoundary{1,Upper}()) | 173 @test boundary_identifiers(TensorGrid(g₁, g₄)) == (TensorGridBoundary{1,LowerBoundary}(),TensorGridBoundary{1,UpperBoundary}()) |
166 end | 174 end |
167 | 175 |
168 @testset "boundary_grid" begin | 176 @testset "boundary_grid" begin |
169 @test boundary_grid(TensorGrid(g₁, g₂), TensorGridBoundary{1, Upper}()) == TensorGrid(ZeroDimGrid(g₁[end]), g₂) | 177 @test boundary_grid(TensorGrid(g₁, g₂), TensorGridBoundary{1, UpperBoundary}()) == TensorGrid(ZeroDimGrid(g₁[end]), g₂) |
170 @test boundary_grid(TensorGrid(g₁, g₄), TensorGridBoundary{1, Upper}()) == TensorGrid(ZeroDimGrid(g₁[end]), g₄) | 178 @test boundary_grid(TensorGrid(g₁, g₄), TensorGridBoundary{1, UpperBoundary}()) == TensorGrid(ZeroDimGrid(g₁[end]), g₄) |
171 end | 179 end |
172 | 180 |
173 @testset "boundary_indices" begin | 181 @testset "boundary_indices" begin |
174 g₁ = EquidistantGrid(range(0,1,length=11)) | 182 g₁ = EquidistantGrid(range(0,1,length=11)) |
175 g₂ = EquidistantGrid(range(2,3,length=6)) | 183 g₂ = EquidistantGrid(range(2,3,length=6)) |
176 g₄ = ZeroDimGrid(@SVector[1,2]) | 184 g₄ = ZeroDimGrid(@SVector[1,2]) |
177 | 185 |
178 gf = reshape(1:(11*6),11,6) | 186 gf = reshape(1:(11*6),11,6) |
179 @test gf[boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, Lower}())] == gf[1,:] | 187 @test gf[boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, LowerBoundary}())] == gf[1,:] |
180 @test gf[boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, Upper}())] == gf[11,:] | 188 @test gf[boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, UpperBoundary}())] == gf[11,:] |
181 @test gf[boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, Lower}())] == gf[:,1] | 189 @test gf[boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, LowerBoundary}())] == gf[:,1] |
182 @test gf[boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, Upper}())] == gf[:,6] | 190 @test gf[boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, UpperBoundary}())] == gf[:,6] |
183 | 191 |
184 gf = rand(11) | 192 gf = rand(11) |
185 @show boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, Lower}()) | 193 @show boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, LowerBoundary}()) |
186 @test gf[boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, Lower}())] == gf[1] | 194 @test gf[boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, LowerBoundary}())] == gf[1] |
187 @test gf[boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, Upper}())] == gf[11] | 195 @test gf[boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, UpperBoundary}())] == gf[11] |
188 @test gf[boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, Lower}())]== gf[1] | 196 @test gf[boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, LowerBoundary}())]== gf[1] |
189 @test gf[boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, Upper}())]== gf[11] | 197 @test gf[boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, UpperBoundary}())]== gf[11] |
190 | 198 |
191 @test collect(boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, Lower}())) == [CartesianIndex(1,i) for i ∈ 1:6] | 199 @test collect(boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, LowerBoundary}())) == [CartesianIndex(1,i) for i ∈ 1:6] |
192 @test collect(boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, Upper}())) == [CartesianIndex(11,i) for i ∈ 1:6] | 200 @test collect(boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, UpperBoundary}())) == [CartesianIndex(11,i) for i ∈ 1:6] |
193 @test collect(boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, Lower}())) == [CartesianIndex(i,1) for i ∈ 1:11] | 201 @test collect(boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, LowerBoundary}())) == [CartesianIndex(i,1) for i ∈ 1:11] |
194 @test collect(boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, Upper}())) == [CartesianIndex(i,6) for i ∈ 1:11] | 202 @test collect(boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, UpperBoundary}())) == [CartesianIndex(i,6) for i ∈ 1:11] |
195 @test collect(boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, Lower}())) == fill(1) | 203 @test collect(boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, LowerBoundary}())) == fill(1) |
196 @test collect(boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, Upper}())) == fill(11) | 204 @test collect(boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, UpperBoundary}())) == fill(11) |
197 @test collect(boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, Lower}())) == fill(1) | 205 @test collect(boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, LowerBoundary}())) == fill(1) |
198 @test collect(boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, Upper}())) == fill(11) | 206 @test collect(boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, UpperBoundary}())) == fill(11) |
199 # TBD: What do we actually expect for 1D grids? | 207 # TBD: What do we actually expect for 1D grids? |
200 end | 208 end |
201 end | 209 end |
202 | 210 |
203 @testset "combined_coordinate_vector_type" begin | 211 @testset "combined_coordinate_vector_type" begin |