Mercurial > repos > public > sbplib_julia
comparison test/Grids/mapped_grid_test.jl @ 1691:5bf4a35a78c5 feature/grids/curvilinear
Factor out functions for the mappings used in tests of MappedGrid
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 23 Aug 2024 12:50:08 +0200 |
parents | 5eabe1f560f0 |
children | a4c52ae93b11 6eb5b48607e0 |
comparison
equal
deleted
inserted
replaced
1690:5eabe1f560f0 | 1691:5bf4a35a78c5 |
---|---|
1 using Sbplib.Grids | 1 using Sbplib.Grids |
2 using Sbplib.RegionIndices | 2 using Sbplib.RegionIndices |
3 using Test | 3 using Test |
4 using StaticArrays | 4 using StaticArrays |
5 using LinearAlgebra | 5 using LinearAlgebra |
6 | |
7 | |
8 _skew_mapping(a,b) = (ξ̄->ξ̄[1]*a + ξ̄[2]*b, ξ̄->[a b]) | |
9 | |
10 function _partially_curved_mapping() | |
11 x̄((ξ, η)) = @SVector[ξ, η*(1+ξ*(ξ-1))] | |
12 J((ξ, η)) = @SMatrix[ | |
13 1 0; | |
14 η*(2ξ-1) 1+ξ*(ξ-1); | |
15 ] | |
16 | |
17 return x̄, J | |
18 end | |
19 | |
20 function _fully_curved_mapping() | |
21 x̄((ξ, η)) = @SVector[2ξ + η*(1-η), 3η+(1+η/2)*ξ^2] | |
22 J((ξ, η)) = @SMatrix[ | |
23 2 1-2η; | |
24 (2+η)*ξ 3+1/2*ξ^2; | |
25 ] | |
26 | |
27 return x̄, J | |
28 end | |
6 | 29 |
7 @testset "MappedGrid" begin | 30 @testset "MappedGrid" begin |
8 lg = equidistant_grid((0,0), (1,1), 11, 11) # TODO: Change dims of the grid to be different | 31 lg = equidistant_grid((0,0), (1,1), 11, 11) # TODO: Change dims of the grid to be different |
9 x̄ = map(ξ̄ -> 2ξ̄, lg) | 32 x̄ = map(ξ̄ -> 2ξ̄, lg) |
10 J = map(ξ̄ -> @SArray(fill(2., 2, 2)), lg) | 33 J = map(ξ̄ -> @SArray(fill(2., 2, 2)), lg) |
116 @test boundary_indices(mg, CartesianBoundary{2,Lower}()) == boundary_indices(lg,CartesianBoundary{2,Lower}()) | 139 @test boundary_indices(mg, CartesianBoundary{2,Lower}()) == boundary_indices(lg,CartesianBoundary{2,Lower}()) |
117 @test boundary_indices(mg, CartesianBoundary{1,Upper}()) == boundary_indices(lg,CartesianBoundary{1,Upper}()) | 140 @test boundary_indices(mg, CartesianBoundary{1,Upper}()) == boundary_indices(lg,CartesianBoundary{1,Upper}()) |
118 end | 141 end |
119 | 142 |
120 @testset "boundary_grid" begin | 143 @testset "boundary_grid" begin |
121 x̄((ξ, η)) = @SVector[ξ, η*(1+ξ*(ξ-1))] | 144 x̄, J = _partially_curved_mapping() |
122 J((ξ, η)) = @SMatrix[ | |
123 1 0; | |
124 η*(2ξ-1) 1+ξ*(ξ-1); | |
125 ] | |
126 | |
127 mg = mapped_grid(x̄, J, 10, 11) | 145 mg = mapped_grid(x̄, J, 10, 11) |
128 J1((ξ, η)) = @SMatrix[ | 146 J1((ξ, η)) = @SMatrix[ |
129 1 ; | 147 1 ; |
130 η*(2ξ-1); | 148 η*(2ξ-1); |
131 ] | 149 ] |
158 @testset test_boundary_grid(mg, TensorGridBoundary{2, Upper}(), J1) | 176 @testset test_boundary_grid(mg, TensorGridBoundary{2, Upper}(), J1) |
159 end | 177 end |
160 end | 178 end |
161 | 179 |
162 @testset "mapped_grid" begin | 180 @testset "mapped_grid" begin |
163 x̄((ξ, η)) = @SVector[ξ, η*(1+ξ*(ξ-1))] | 181 x̄, J = _partially_curved_mapping() |
164 J((ξ, η)) = @SMatrix[ | |
165 1 0; | |
166 η*(2ξ-1) 1+ξ*(ξ-1); | |
167 ] | |
168 mg = mapped_grid(x̄, J, 10, 11) | 182 mg = mapped_grid(x̄, J, 10, 11) |
169 @test mg isa MappedGrid{SVector{2,Float64}, 2} | 183 @test mg isa MappedGrid{SVector{2,Float64}, 2} |
170 | 184 |
171 lg = equidistant_grid((0,0), (1,1), 10, 11) | 185 lg = equidistant_grid((0,0), (1,1), 10, 11) |
172 @test logicalgrid(mg) == lg | 186 @test logicalgrid(mg) == lg |
204 | 218 |
205 let g = mapped_grid(identity, x->@SMatrix[1 0; 0 1], 11,21) | 219 let g = mapped_grid(identity, x->@SMatrix[1 0; 0 1], 11,21) |
206 @test min_spacing(g) ≈ 0.05 | 220 @test min_spacing(g) ≈ 0.05 |
207 end | 221 end |
208 | 222 |
209 skew_grid(a,b, sz...) = mapped_grid(ξ̄->ξ̄[1]*a + ξ̄[2]*b, ξ̄->[a b], sz...) | |
210 | 223 |
211 @testset let a = @SVector[1,0], b = @SVector[1,1]/√2 | 224 @testset let a = @SVector[1,0], b = @SVector[1,1]/√2 |
212 g = skew_grid(a,b,11,11) | 225 g = mapped_grid(_skew_mapping(a,b)...,11,11) |
213 | 226 |
214 @test min_spacing(g) ≈ 0.1*norm(b-a) | 227 @test min_spacing(g) ≈ 0.1*norm(b-a) |
215 end | 228 end |
216 | 229 |
217 @testset let a = @SVector[1,0], b = @SVector[-1,1]/√2 | 230 @testset let a = @SVector[1,0], b = @SVector[-1,1]/√2 |
218 g = skew_grid(a,b,11,11) | 231 g = mapped_grid(_skew_mapping(a,b)...,11,11) |
219 | 232 |
220 @test min_spacing(g) ≈ 0.1*norm(a+b) | 233 @test min_spacing(g) ≈ 0.1*norm(a+b) |
221 end | 234 end |
222 end | 235 end |
223 | 236 |
224 @testset "normal" begin | 237 @testset "normal" begin |
225 x̄((ξ, η)) = @SVector[ξ, η*(1+ξ*(ξ-1))] | 238 g = mapped_grid(_partially_curved_mapping()...,10, 11) |
226 J((ξ, η)) = @SMatrix[ | |
227 1 0; | |
228 η*(2ξ-1) 1+ξ*(ξ-1); | |
229 ] | |
230 g = mapped_grid(x̄, J, 10, 11) | |
231 | 239 |
232 @test normal(g, CartesianBoundary{1,Lower}()) == fill(@SVector[-1,0], 11) | 240 @test normal(g, CartesianBoundary{1,Lower}()) == fill(@SVector[-1,0], 11) |
233 @test normal(g, CartesianBoundary{1,Upper}()) == fill(@SVector[1,0], 11) | 241 @test normal(g, CartesianBoundary{1,Upper}()) == fill(@SVector[1,0], 11) |
234 @test normal(g, CartesianBoundary{2,Lower}()) == fill(@SVector[0,-1], 10) | 242 @test normal(g, CartesianBoundary{2,Lower}()) == fill(@SVector[0,-1], 10) |
235 @test normal(g, CartesianBoundary{2,Upper}()) ≈ map(boundary_grid(g,CartesianBoundary{2,Upper}())|>logicalgrid) do ξ̄ | 243 @test normal(g, CartesianBoundary{2,Upper}()) ≈ map(boundary_grid(g,CartesianBoundary{2,Upper}())|>logicalgrid) do ξ̄ |
236 α = 1-2ξ̄[1] | 244 α = 1-2ξ̄[1] |
237 @SVector[α,1]/√(α^2 + 1) | 245 @SVector[α,1]/√(α^2 + 1) |
238 end | 246 end |
239 | 247 |
240 x̄((ξ, η)) = @SVector[2ξ + η*(1-η), 3η+(1+η/2)*ξ^2] | 248 g = mapped_grid(_fully_curved_mapping()...,5,4) |
241 J((ξ, η)) = @SMatrix[ | |
242 2 1-2η; | |
243 (2+η)*ξ 3+1/2*ξ^2; | |
244 ] | |
245 | |
246 g = mapped_grid(x̄,J,5,4) | |
247 | 249 |
248 unit(v) = v/norm(v) | 250 unit(v) = v/norm(v) |
249 @testset let bId = CartesianBoundary{1,Lower}() | 251 @testset let bId = CartesianBoundary{1,Lower}() |
250 lbg = boundary_grid(logicalgrid(g), bId) | 252 lbg = boundary_grid(logicalgrid(g), bId) |
251 @test normal(g, bId) ≈ map(lbg) do (ξ, η) | 253 @test normal(g, bId) ≈ map(lbg) do (ξ, η) |