annotate test/Grids/curvilinear_grid_test.jl @ 1431:6adf31ba6cfd feature/grids/curvilinear

Add `jacobian` and `logicalgrid`
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 25 Aug 2023 15:41:19 +0200
parents 9fc3c1af33e5
children 64b60b42d367
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1426
9c689a627244 Add src and test file for curvilinear grid type
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
1 using Sbplib.Grids
9c689a627244 Add src and test file for curvilinear grid type
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
2 using Test
1430
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
3 using StaticArrays
1426
9c689a627244 Add src and test file for curvilinear grid type
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
4
9c689a627244 Add src and test file for curvilinear grid type
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
5 @testset "CurvilinearGrid" begin
1430
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
6 g = equidistant_grid((10,10), (0,0), (1,1))
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
7 x̄ = map(ξ̄ -> 2ξ̄, g)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
8 J = map(ξ̄ -> @SArray(fill(2., 2, 2)), g)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
9
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
10 @test CurvilinearGrid(g, x̄, J) isa Grid{SVector{2, Float64},2}
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
11
1431
6adf31ba6cfd Add `jacobian` and `logicalgrid`
Jonatan Werpers <jonatan@werpers.com>
parents: 1430
diff changeset
12 cg = CurvilinearGrid(g, x̄, J)
6adf31ba6cfd Add `jacobian` and `logicalgrid`
Jonatan Werpers <jonatan@werpers.com>
parents: 1430
diff changeset
13 @test jacobian(cg) isa Array{<:AbstractMatrix}
6adf31ba6cfd Add `jacobian` and `logicalgrid`
Jonatan Werpers <jonatan@werpers.com>
parents: 1430
diff changeset
14 @test logicalgrid(cg) isa Grid
1430
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
15
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
16
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
17 @testset "Indexing Interface" begin
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
18 # cg = CurvilinearGrid(g, x̄, J)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
19 # @test cg[1,1] == [0.0, 0.0]
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
20 # @test cg[4,2] == [3/9,1/9]
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
21 # @test cg[6,10] == [5/9, 1]
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
22
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
23 # @test cg[begin, begin] == [0.0, 0.0]
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
24 # @test cg[end,end] == [1.0, 1.0]
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
25 # @test cg[begin,end] == [0., 1.]
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
26
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
27 # @test eachindex(cg) == 1:101
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
28 end
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
29
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
30 @testset "Iterator interface" begin
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
31 # @test eltype(EquidistantGrid(0:10)) == Int
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
32 # @test eltype(EquidistantGrid(0:2:10)) == Int
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
33 # @test eltype(EquidistantGrid(0:0.1:10)) == Float64
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
34
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
35 # @test size(EquidistantGrid(0:10)) == (11,)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
36 # @test size(EquidistantGrid(0:0.1:10)) == (101,)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
37
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
38 # @test collect(EquidistantGrid(0:0.1:0.5)) == [0.0, 0.1, 0.2, 0.3, 0.4, 0.5]
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
39
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
40 # @test Base.IteratorSize(EquidistantGrid{Float64, StepRange{Float64}}) == Base.HasShape{1}()
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
41 end
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
42
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
43 @testset "Base" begin
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
44 # @test ndims(EquidistantGrid(0:10)) == 1
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
45 end
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
46
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
47 @testset "boundary_identifiers" begin
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
48 # g = EquidistantGrid(0:0.1:10)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
49 # @test boundary_identifiers(g) == (Lower(), Upper())
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
50 # @inferred boundary_identifiers(g)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
51 end
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
52
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
53 @testset "boundary_grid" begin
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
54 # g = EquidistantGrid(0:0.1:1)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
55 # @test boundary_grid(g, Lower()) == ZeroDimGrid(0.0)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
56 # @test boundary_grid(g, Upper()) == ZeroDimGrid(1.0)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
57 end
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
58
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
59 @testset "refine" begin
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
60 # g = EquidistantGrid(0:0.1:1)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
61 # @test refine(g, 1) == g
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
62 # @test refine(g, 2) == EquidistantGrid(0:0.05:1)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
63 # @test refine(g, 3) == EquidistantGrid(0:(0.1/3):1)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
64 end
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
65
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
66 @testset "coarsen" begin
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
67 # g = EquidistantGrid(0:1:10)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
68 # @test coarsen(g, 1) == g
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
69 # @test coarsen(g, 2) == EquidistantGrid(0:2:10)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
70
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
71 # g = EquidistantGrid(0:0.1:1)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
72 # @test coarsen(g, 1) == g
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
73 # @test coarsen(g, 2) == EquidistantGrid(0:0.2:1)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
74
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
75 # g = EquidistantGrid(0:10)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
76 # @test coarsen(g, 1) == EquidistantGrid(0:1:10)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
77 # @test coarsen(g, 2) == EquidistantGrid(0:2:10)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
78
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
79 # @test_throws DomainError(3, "Size minus 1 must be divisible by the ratio.") coarsen(g, 3)
9fc3c1af33e5 Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents: 1426
diff changeset
80 end
1426
9c689a627244 Add src and test file for curvilinear grid type
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
81 end