Mercurial > repos > public > sbplib_julia
comparison test/Grids/manifolds_test.jl @ 2008:df2cbcb7a2b1 default
Merge feature/grids/manifolds
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 01 May 2025 15:05:11 +0200 |
parents | a1b2453c02c9 |
children |
comparison
equal
deleted
inserted
replaced
2005:52e5ab4a96d5 | 2008:df2cbcb7a2b1 |
---|---|
1 using Test | |
2 | |
3 using Diffinitive.Grids | |
4 using Diffinitive.RegionIndices | |
5 using Diffinitive.LazyTensors | |
6 | |
7 using StaticArrays | |
8 | |
9 west = CartesianBoundary{1,LowerBoundary} | |
10 east = CartesianBoundary{1,UpperBoundary} | |
11 south = CartesianBoundary{2,LowerBoundary} | |
12 north = CartesianBoundary{2,UpperBoundary} | |
13 bottom = CartesianBoundary{3, LowerBoundary} | |
14 top = CartesianBoundary{3, UpperBoundary} | |
15 | |
16 @testset "Chart" begin | |
17 X(ξ) = 2ξ | |
18 Grids.jacobian(::typeof(X), ξ) = @SMatrix[2 0; 0 2] | |
19 c = Chart(X, unitsquare()) | |
20 @test c isa Chart{2} | |
21 @test parameterspace(c) == unitsquare() | |
22 @test ndims(c) == 2 | |
23 | |
24 @testset "Calling" begin | |
25 c = Chart(X, unitsquare()) | |
26 @test c([.3,.2]) == [.6,.4] | |
27 @test_throws DomainError c([3,2]) | |
28 end | |
29 | |
30 @testset "jacobian(::Chart, ⋅)" begin | |
31 c = Chart(X, unitsquare()) | |
32 @test_throws DomainError jacobian(c, [3,2]) | |
33 @test jacobian(c, [.3,.2]) == [2 0; 0 2] | |
34 end | |
35 | |
36 @test Set(boundary_identifiers(Chart(X,unitsquare()))) == Set([east(),west(),south(),north()]) | |
37 end | |
38 | |
39 @testset "CartesianAtlas" begin | |
40 @testset "Constructors" begin | |
41 c = Chart(identity, unitsquare()) | |
42 @test CartesianAtlas([c c; c c]) isa Atlas | |
43 | |
44 c2 = Chart(x->2x, unitsquare()) | |
45 @test CartesianAtlas([c c2; c2 c]) isa CartesianAtlas | |
46 @test CartesianAtlas(@SMatrix[c c; c c]) isa CartesianAtlas | |
47 @test CartesianAtlas(@SMatrix[c c2; c2 c]) isa CartesianAtlas | |
48 end | |
49 | |
50 @testset "Getters" begin | |
51 c = Chart(identity, unitsquare()) | |
52 a = CartesianAtlas([c c; c c]) | |
53 @test charts(a) == [c c; c c] | |
54 end | |
55 | |
56 @testset "connections" begin | |
57 # 2D | |
58 a = CartesianAtlas(fill(Chart(identity, unitsquare()), 2,3)) | |
59 | |
60 @test Set(connections(a)) == Set([ | |
61 (MultiBlockBoundary{(1,1), east}(), MultiBlockBoundary{(2,1), west}()), | |
62 (MultiBlockBoundary{(1,1), north}(), MultiBlockBoundary{(1,2), south}()), | |
63 (MultiBlockBoundary{(2,1), north}(), MultiBlockBoundary{(2,2), south}()), | |
64 (MultiBlockBoundary{(1,2), east}(), MultiBlockBoundary{(2,2), west}()), | |
65 (MultiBlockBoundary{(1,2), north}(), MultiBlockBoundary{(1,3), south}()), | |
66 (MultiBlockBoundary{(2,2), north}(), MultiBlockBoundary{(2,3), south}()), | |
67 (MultiBlockBoundary{(1,3), east}(), MultiBlockBoundary{(2,3), west}()), | |
68 ]) | |
69 | |
70 # 3D | |
71 a = CartesianAtlas(fill(Chart(identity, unitcube()), 2,2,3)) | |
72 @test Set(connections(a)) == Set([ | |
73 (MultiBlockBoundary{(1,1,1), east}(), MultiBlockBoundary{(2,1,1), west}()), | |
74 (MultiBlockBoundary{(1,1,1), north}(), MultiBlockBoundary{(1,2,1), south}()), | |
75 (MultiBlockBoundary{(2,1,1), north}(), MultiBlockBoundary{(2,2,1), south}()), | |
76 (MultiBlockBoundary{(1,2,1), east}(), MultiBlockBoundary{(2,2,1), west}()), | |
77 | |
78 (MultiBlockBoundary{(1,1,2), east}(), MultiBlockBoundary{(2,1,2), west}()), | |
79 (MultiBlockBoundary{(1,1,2), north}(), MultiBlockBoundary{(1,2,2), south}()), | |
80 (MultiBlockBoundary{(2,1,2), north}(), MultiBlockBoundary{(2,2,2), south}()), | |
81 (MultiBlockBoundary{(1,2,2), east}(), MultiBlockBoundary{(2,2,2), west}()), | |
82 | |
83 (MultiBlockBoundary{(1,1,3), east}(), MultiBlockBoundary{(2,1,3), west}()), | |
84 (MultiBlockBoundary{(1,1,3), north}(), MultiBlockBoundary{(1,2,3), south}()), | |
85 (MultiBlockBoundary{(2,1,3), north}(), MultiBlockBoundary{(2,2,3), south}()), | |
86 (MultiBlockBoundary{(1,2,3), east}(), MultiBlockBoundary{(2,2,3), west}()), | |
87 | |
88 (MultiBlockBoundary{(1,1,1), top}(), MultiBlockBoundary{(1,1,2), bottom}()), | |
89 (MultiBlockBoundary{(2,1,1), top}(), MultiBlockBoundary{(2,1,2), bottom}()), | |
90 (MultiBlockBoundary{(1,2,1), top}(), MultiBlockBoundary{(1,2,2), bottom}()), | |
91 (MultiBlockBoundary{(2,2,1), top}(), MultiBlockBoundary{(2,2,2), bottom}()), | |
92 | |
93 (MultiBlockBoundary{(1,1,2), top}(), MultiBlockBoundary{(1,1,3), bottom}()), | |
94 (MultiBlockBoundary{(2,1,2), top}(), MultiBlockBoundary{(2,1,3), bottom}()), | |
95 (MultiBlockBoundary{(1,2,2), top}(), MultiBlockBoundary{(1,2,3), bottom}()), | |
96 (MultiBlockBoundary{(2,2,2), top}(), MultiBlockBoundary{(2,2,3), bottom}()), | |
97 ]) | |
98 end | |
99 | |
100 @testset "boundary_identifiers" begin | |
101 # 2D | |
102 a = CartesianAtlas(fill(Chart(identity, unitcube()), 2,3)) | |
103 @test Set(boundary_identifiers(a)) == Set([ | |
104 MultiBlockBoundary{(1,1), south}(), | |
105 MultiBlockBoundary{(2,1), south}(), | |
106 MultiBlockBoundary{(2,1), east}(), | |
107 MultiBlockBoundary{(2,2), east}(), | |
108 MultiBlockBoundary{(2,3), east}(), | |
109 MultiBlockBoundary{(1,3), north}(), | |
110 MultiBlockBoundary{(2,3), north}(), | |
111 MultiBlockBoundary{(1,1), west}(), | |
112 MultiBlockBoundary{(1,2), west}(), | |
113 MultiBlockBoundary{(1,3), west}(), | |
114 ]) | |
115 | |
116 # 3D | |
117 a = CartesianAtlas(fill(Chart(identity, unitsquare()), 2,2,3)) | |
118 @test Set(boundary_identifiers(a)) == Set([ | |
119 MultiBlockBoundary{(1,1,1), bottom}(), | |
120 MultiBlockBoundary{(2,1,1), bottom}(), | |
121 MultiBlockBoundary{(1,2,1), bottom}(), | |
122 MultiBlockBoundary{(2,2,1), bottom}(), | |
123 | |
124 MultiBlockBoundary{(1,1,3), top}(), | |
125 MultiBlockBoundary{(2,1,3), top}(), | |
126 MultiBlockBoundary{(1,2,3), top}(), | |
127 MultiBlockBoundary{(2,2,3), top}(), | |
128 | |
129 MultiBlockBoundary{(1,1,1), west}(), | |
130 MultiBlockBoundary{(1,2,1), west}(), | |
131 MultiBlockBoundary{(1,1,2), west}(), | |
132 MultiBlockBoundary{(1,2,2), west}(), | |
133 MultiBlockBoundary{(1,1,3), west}(), | |
134 MultiBlockBoundary{(1,2,3), west}(), | |
135 | |
136 MultiBlockBoundary{(2,1,1), east}(), | |
137 MultiBlockBoundary{(2,2,1), east}(), | |
138 MultiBlockBoundary{(2,1,2), east}(), | |
139 MultiBlockBoundary{(2,2,2), east}(), | |
140 MultiBlockBoundary{(2,1,3), east}(), | |
141 MultiBlockBoundary{(2,2,3), east}(), | |
142 | |
143 MultiBlockBoundary{(1,1,1), south}(), | |
144 MultiBlockBoundary{(2,1,1), south}(), | |
145 MultiBlockBoundary{(1,1,2), south}(), | |
146 MultiBlockBoundary{(2,1,2), south}(), | |
147 MultiBlockBoundary{(1,1,3), south}(), | |
148 MultiBlockBoundary{(2,1,3), south}(), | |
149 | |
150 MultiBlockBoundary{(1,2,1), north}(), | |
151 MultiBlockBoundary{(2,2,1), north}(), | |
152 MultiBlockBoundary{(1,2,2), north}(), | |
153 MultiBlockBoundary{(2,2,2), north}(), | |
154 MultiBlockBoundary{(1,2,3), north}(), | |
155 MultiBlockBoundary{(2,2,3), north}(), | |
156 ]) | |
157 end | |
158 end | |
159 | |
160 @testset "UnstructuredAtlas" begin | |
161 @testset "Constructors" begin | |
162 c1 = Chart(identity, unitsquare()) | |
163 c2 = Chart(x->2x, unitsquare()) | |
164 cn = [ | |
165 (MultiBlockBoundary{1, east}(), MultiBlockBoundary{2, west}()), | |
166 (MultiBlockBoundary{1, north}(), MultiBlockBoundary{3, west}()), | |
167 (MultiBlockBoundary{2, north}(), MultiBlockBoundary{3, south}()), | |
168 ] | |
169 | |
170 @test UnstructuredAtlas([c1, c1, c1], cn) isa UnstructuredAtlas | |
171 @test UnstructuredAtlas([c1, c2, c1, c2], cn) isa UnstructuredAtlas | |
172 | |
173 | |
174 cn = @SVector[ | |
175 (MultiBlockBoundary{1, east}(), MultiBlockBoundary{2, west}()), | |
176 (MultiBlockBoundary{1, north}(), MultiBlockBoundary{3, west}()), | |
177 (MultiBlockBoundary{2, north}(), MultiBlockBoundary{3, south}()), | |
178 ] | |
179 @test UnstructuredAtlas(@SVector[c1, c1, c1], cn) isa UnstructuredAtlas | |
180 @test UnstructuredAtlas(@SVector[c1, c2, c1, c2], cn) isa UnstructuredAtlas | |
181 end | |
182 | |
183 @testset "Getters" begin | |
184 c = Chart(identity, unitsquare()) | |
185 cn = [ | |
186 (MultiBlockBoundary{1, east}(), MultiBlockBoundary{2, west}()), | |
187 (MultiBlockBoundary{1, north}(), MultiBlockBoundary{3, west}()), | |
188 (MultiBlockBoundary{2, north}(), MultiBlockBoundary{3, south}()), | |
189 ] | |
190 | |
191 a = UnstructuredAtlas([c, c, c], cn) | |
192 | |
193 @test charts(a) == [c,c,c] | |
194 @test connections(a) == cn | |
195 end | |
196 | |
197 @testset "boundary_identifiers" begin | |
198 c = Chart(identity, unitsquare()) | |
199 cn = [ | |
200 (MultiBlockBoundary{1, east}(), MultiBlockBoundary{2, west}()), | |
201 (MultiBlockBoundary{1, north}(), MultiBlockBoundary{3, west}()), | |
202 (MultiBlockBoundary{2, north}(), MultiBlockBoundary{3, south}()), | |
203 ] | |
204 | |
205 a = UnstructuredAtlas([c, c, c], cn) | |
206 | |
207 @test Set(boundary_identifiers(a)) == Set([ | |
208 MultiBlockBoundary{1, west}(), | |
209 MultiBlockBoundary{1, south}(), | |
210 MultiBlockBoundary{2, south}(), | |
211 MultiBlockBoundary{2, east}(), | |
212 MultiBlockBoundary{3, north}(), | |
213 MultiBlockBoundary{3, east}(), | |
214 ]) | |
215 | |
216 end | |
217 end |