Mercurial > repos > public > sbplib_julia
comparison test/Grids/mapped_grid_test.jl @ 1736:863385aae454 feature/grids/curvilinear
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 10 Sep 2024 21:59:10 +0200 |
parents | 36986b75bf98 |
children | a4e1721a7109 |
comparison
equal
deleted
inserted
replaced
1735:36986b75bf98 | 1736:863385aae454 |
---|---|
1 using Sbplib.Grids | 1 using Diffinitive.Grids |
2 using Sbplib.RegionIndices | 2 using Diffinitive.RegionIndices |
3 using Test | 3 using Test |
4 using StaticArrays | 4 using StaticArrays |
5 using LinearAlgebra | 5 using LinearAlgebra |
6 | 6 |
7 | 7 |
171 lg = equidistant_grid((0,0), (1,1), 11, 11) # TODO: Change dims of the grid to be different | 171 lg = equidistant_grid((0,0), (1,1), 11, 11) # TODO: Change dims of the grid to be different |
172 x̄ = map(ξ̄ -> 2ξ̄, lg) | 172 x̄ = map(ξ̄ -> 2ξ̄, lg) |
173 J = map(ξ̄ -> @SArray(fill(2., 2, 2)), lg) | 173 J = map(ξ̄ -> @SArray(fill(2., 2, 2)), lg) |
174 mg = MappedGrid(lg, x̄, J) | 174 mg = MappedGrid(lg, x̄, J) |
175 | 175 |
176 @test boundary_indices(mg, CartesianBoundary{1,Lower}()) == boundary_indices(lg,CartesianBoundary{1,Lower}()) | 176 @test boundary_indices(mg, CartesianBoundary{1,LowerBoundary}()) == boundary_indices(lg,CartesianBoundary{1,LowerBoundary}()) |
177 @test boundary_indices(mg, CartesianBoundary{2,Lower}()) == boundary_indices(lg,CartesianBoundary{2,Lower}()) | 177 @test boundary_indices(mg, CartesianBoundary{2,LowerBoundary}()) == boundary_indices(lg,CartesianBoundary{2,LowerBoundary}()) |
178 @test boundary_indices(mg, CartesianBoundary{1,Upper}()) == boundary_indices(lg,CartesianBoundary{1,Upper}()) | 178 @test boundary_indices(mg, CartesianBoundary{1,UpperBoundary}()) == boundary_indices(lg,CartesianBoundary{1,UpperBoundary}()) |
179 end | 179 end |
180 | 180 |
181 @testset "boundary_grid" begin | 181 @testset "boundary_grid" begin |
182 x̄, J = _partially_curved_mapping() | 182 x̄, J = _partially_curved_mapping() |
183 mg = mapped_grid(x̄, J, 10, 11) | 183 mg = mapped_grid(x̄, J, 10, 11) |
206 @test jacobian(bg) == jacobian(expected_bg) | 206 @test jacobian(bg) == jacobian(expected_bg) |
207 # TODO: Implement equality of a curvilinear grid and simlify the above | 207 # TODO: Implement equality of a curvilinear grid and simlify the above |
208 end | 208 end |
209 end | 209 end |
210 | 210 |
211 @testset test_boundary_grid(mg, TensorGridBoundary{1, Lower}(), J2) | 211 @testset test_boundary_grid(mg, TensorGridBoundary{1, LowerBoundary}(), J2) |
212 @testset test_boundary_grid(mg, TensorGridBoundary{1, Upper}(), J2) | 212 @testset test_boundary_grid(mg, TensorGridBoundary{1, UpperBoundary}(), J2) |
213 @testset test_boundary_grid(mg, TensorGridBoundary{2, Lower}(), J1) | 213 @testset test_boundary_grid(mg, TensorGridBoundary{2, LowerBoundary}(), J1) |
214 @testset test_boundary_grid(mg, TensorGridBoundary{2, Upper}(), J1) | 214 @testset test_boundary_grid(mg, TensorGridBoundary{2, UpperBoundary}(), J1) |
215 end | 215 end |
216 end | 216 end |
217 | 217 |
218 @testset "mapped_grid" begin | 218 @testset "mapped_grid" begin |
219 x̄, J = _partially_curved_mapping() | 219 x̄, J = _partially_curved_mapping() |
275 end | 275 end |
276 | 276 |
277 @testset "normal" begin | 277 @testset "normal" begin |
278 g = mapped_grid(_partially_curved_mapping()...,10, 11) | 278 g = mapped_grid(_partially_curved_mapping()...,10, 11) |
279 | 279 |
280 @test normal(g, CartesianBoundary{1,Lower}()) == fill(@SVector[-1,0], 11) | 280 @test normal(g, CartesianBoundary{1,LowerBoundary}()) == fill(@SVector[-1,0], 11) |
281 @test normal(g, CartesianBoundary{1,Upper}()) == fill(@SVector[1,0], 11) | 281 @test normal(g, CartesianBoundary{1,UpperBoundary}()) == fill(@SVector[1,0], 11) |
282 @test normal(g, CartesianBoundary{2,Lower}()) == fill(@SVector[0,-1], 10) | 282 @test normal(g, CartesianBoundary{2,LowerBoundary}()) == fill(@SVector[0,-1], 10) |
283 @test normal(g, CartesianBoundary{2,Upper}()) ≈ map(boundary_grid(g,CartesianBoundary{2,Upper}())|>logicalgrid) do ξ̄ | 283 @test normal(g, CartesianBoundary{2,UpperBoundary}()) ≈ map(boundary_grid(g,CartesianBoundary{2,UpperBoundary}())|>logicalgrid) do ξ̄ |
284 α = 1-2ξ̄[1] | 284 α = 1-2ξ̄[1] |
285 @SVector[α,1]/√(α^2 + 1) | 285 @SVector[α,1]/√(α^2 + 1) |
286 end | 286 end |
287 | 287 |
288 g = mapped_grid(_fully_curved_mapping()...,5,4) | 288 g = mapped_grid(_fully_curved_mapping()...,5,4) |
289 | 289 |
290 unit(v) = v/norm(v) | 290 unit(v) = v/norm(v) |
291 @testset let bId = CartesianBoundary{1,Lower}() | 291 @testset let bId = CartesianBoundary{1,LowerBoundary}() |
292 lbg = boundary_grid(logicalgrid(g), bId) | 292 lbg = boundary_grid(logicalgrid(g), bId) |
293 @test normal(g, bId) ≈ map(lbg) do (ξ, η) | 293 @test normal(g, bId) ≈ map(lbg) do (ξ, η) |
294 -unit(@SVector[1/2, η/3-1/6]) | 294 -unit(@SVector[1/2, η/3-1/6]) |
295 end | 295 end |
296 end | 296 end |
297 | 297 |
298 @testset let bId = CartesianBoundary{1,Upper}() | 298 @testset let bId = CartesianBoundary{1,UpperBoundary}() |
299 lbg = boundary_grid(logicalgrid(g), bId) | 299 lbg = boundary_grid(logicalgrid(g), bId) |
300 @test normal(g, bId) ≈ map(lbg) do (ξ, η) | 300 @test normal(g, bId) ≈ map(lbg) do (ξ, η) |
301 unit(@SVector[7/2, 2η-1]/(5 + 3η + 2η^2)) | 301 unit(@SVector[7/2, 2η-1]/(5 + 3η + 2η^2)) |
302 end | 302 end |
303 end | 303 end |
304 | 304 |
305 @testset let bId = CartesianBoundary{2,Lower}() | 305 @testset let bId = CartesianBoundary{2,LowerBoundary}() |
306 lbg = boundary_grid(logicalgrid(g), bId) | 306 lbg = boundary_grid(logicalgrid(g), bId) |
307 @test normal(g, bId) ≈ map(lbg) do (ξ, η) | 307 @test normal(g, bId) ≈ map(lbg) do (ξ, η) |
308 -unit(@SVector[-2ξ, 2]/(6 + ξ^2 - 2ξ)) | 308 -unit(@SVector[-2ξ, 2]/(6 + ξ^2 - 2ξ)) |
309 end | 309 end |
310 end | 310 end |
311 | 311 |
312 @testset let bId = CartesianBoundary{2,Upper}() | 312 @testset let bId = CartesianBoundary{2,UpperBoundary}() |
313 lbg = boundary_grid(logicalgrid(g), bId) | 313 lbg = boundary_grid(logicalgrid(g), bId) |
314 @test normal(g, bId) ≈ map(lbg) do (ξ, η) | 314 @test normal(g, bId) ≈ map(lbg) do (ξ, η) |
315 unit(@SVector[-3ξ, 2]/(6 + ξ^2 + 3ξ)) | 315 unit(@SVector[-3ξ, 2]/(6 + ξ^2 + 3ξ)) |
316 end | 316 end |
317 end | 317 end |