Mercurial > repos > public > sbplib_julia
comparison test/Grids/curvilinear_grid_test.jl @ 1432:64b60b42d367 feature/grids/curvilinear
Implement indexing interface
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 28 Aug 2023 09:30:34 +0200 |
parents | 6adf31ba6cfd |
children | af73340a8f0e |
comparison
equal
deleted
inserted
replaced
1431:6adf31ba6cfd | 1432:64b60b42d367 |
---|---|
1 using Sbplib.Grids | 1 using Sbplib.Grids |
2 using Test | 2 using Test |
3 using StaticArrays | 3 using StaticArrays |
4 | 4 |
5 @testset "CurvilinearGrid" begin | 5 @testset "CurvilinearGrid" begin |
6 g = equidistant_grid((10,10), (0,0), (1,1)) | 6 lg = equidistant_grid((11,11), (0,0), (1,1)) |
7 x̄ = map(ξ̄ -> 2ξ̄, g) | 7 x̄ = map(ξ̄ -> 2ξ̄, lg) |
8 J = map(ξ̄ -> @SArray(fill(2., 2, 2)), g) | 8 J = map(ξ̄ -> @SArray(fill(2., 2, 2)), lg) |
9 cg = CurvilinearGrid(lg, x̄, J) | |
9 | 10 |
10 @test CurvilinearGrid(g, x̄, J) isa Grid{SVector{2, Float64},2} | 11 @test cg isa Grid{SVector{2, Float64},2} |
11 | 12 |
12 cg = CurvilinearGrid(g, x̄, J) | |
13 @test jacobian(cg) isa Array{<:AbstractMatrix} | 13 @test jacobian(cg) isa Array{<:AbstractMatrix} |
14 @test logicalgrid(cg) isa Grid | 14 @test logicalgrid(cg) isa Grid |
15 | 15 |
16 @testset "Indexing Interface" begin | |
17 cg = CurvilinearGrid(lg, x̄, J) | |
18 @test cg[1,1] == [0.0, 0.0] | |
19 @test cg[4,2] == [0.6, 0.2] | |
20 @test cg[6,10] == [1., 1.8] | |
16 | 21 |
17 @testset "Indexing Interface" begin | 22 @test cg[begin, begin] == [0.0, 0.0] |
18 # cg = CurvilinearGrid(g, x̄, J) | 23 @test cg[end,end] == [2.0, 2.0] |
19 # @test cg[1,1] == [0.0, 0.0] | 24 @test cg[begin,end] == [0., 2.] |
20 # @test cg[4,2] == [3/9,1/9] | |
21 # @test cg[6,10] == [5/9, 1] | |
22 | 25 |
23 # @test cg[begin, begin] == [0.0, 0.0] | 26 @test eachindex(cg) == CartesianIndices((11,11)) |
24 # @test cg[end,end] == [1.0, 1.0] | |
25 # @test cg[begin,end] == [0., 1.] | |
26 | 27 |
27 # @test eachindex(cg) == 1:101 | 28 @testset "cartesian indexing" begin |
29 cases = [ | |
30 (1,1) , | |
31 (3,5) , | |
32 (10,6), | |
33 (1,1) , | |
34 (3,2) , | |
35 ] | |
36 | |
37 @testset "i = $is" for (lg, is) ∈ cases | |
38 @test cg[CartesianIndex(is...)] == cg[is...] | |
39 end | |
40 end | |
41 | |
42 @testset "eachindex" begin | |
43 @test eachindex(cg) == CartesianIndices((11,11)) | |
44 end | |
45 | |
46 @testset "firstindex" begin | |
47 @test firstindex(cg, 1) == 1 | |
48 @test firstindex(cg, 2) == 1 | |
49 end | |
50 | |
51 @testset "lastindex" begin | |
52 @test lastindex(cg, 1) == 11 | |
53 @test lastindex(cg, 2) == 11 | |
54 end | |
28 end | 55 end |
56 # TODO: Test with different types of logical grids | |
29 | 57 |
30 @testset "Iterator interface" begin | 58 @testset "Iterator interface" begin |
31 # @test eltype(EquidistantGrid(0:10)) == Int | 59 # @test eltype(EquidistantGrid(0:10)) == Int |
32 # @test eltype(EquidistantGrid(0:2:10)) == Int | 60 # @test eltype(EquidistantGrid(0:2:10)) == Int |
33 # @test eltype(EquidistantGrid(0:0.1:10)) == Float64 | 61 # @test eltype(EquidistantGrid(0:0.1:10)) == Float64 |