Mercurial > repos > public > sbplib_julia
changeset 1690:5eabe1f560f0 feature/grids/curvilinear
Reorganize nesting of tests for mapped_grid
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 23 Aug 2024 09:45:02 +0200 |
parents | e11b5b6940a2 |
children | 5bf4a35a78c5 |
files | test/Grids/mapped_grid_test.jl |
diffstat | 1 files changed, 89 insertions(+), 92 deletions(-) [+] |
line wrap: on
line diff
--- a/test/Grids/mapped_grid_test.jl Fri Aug 23 09:22:29 2024 +0200 +++ b/test/Grids/mapped_grid_test.jl Fri Aug 23 09:45:02 2024 +0200 @@ -157,58 +157,6 @@ @testset test_boundary_grid(mg, TensorGridBoundary{2, Lower}(), J1) @testset test_boundary_grid(mg, TensorGridBoundary{2, Upper}(), J1) end - - @testset "jacobian_determinant" begin - @test_broken false - end - - @testset "metric_tensor" begin - @test_broken false - end - - @testset "metric_tensor_inverse" begin - @test_broken false - end - - - @testset "min_spacing" begin - let g = mapped_grid(identity, x->@SMatrix[1], 11) - @test min_spacing(g) ≈ 0.1 - end - - let g = mapped_grid(x->x+x.^2/2, x->@SMatrix[1 .+ x], 11) - @test min_spacing(g) ≈ 0.105 - end - - let g = mapped_grid(x->x + x.*(1 .- x)/2, x->@SMatrix[1.5 .- x], 11) - @test min_spacing(g) ≈ 0.055 - end - - let g = mapped_grid(identity, x->@SMatrix[1 0; 0 1], 11,11) - @test min_spacing(g) ≈ 0.1 - end - - let g = mapped_grid(identity, x->@SMatrix[1 0; 0 1], 11,21) - @test min_spacing(g) ≈ 0.05 - end - - skew_grid(a,b, sz...) = mapped_grid(ξ̄->ξ̄[1]*a + ξ̄[2]*b, ξ̄->[a b], sz...) - - @testset let a = @SVector[1,0], b = @SVector[1,1]/√2 - g = skew_grid(a,b,11,11) - - @test min_spacing(g) ≈ 0.1*norm(b-a) - end - - @testset let a = @SVector[1,0], b = @SVector[-1,1]/√2 - g = skew_grid(a,b,11,11) - - @test min_spacing(g) ≈ 0.1*norm(a+b) - end - - # Skevt nät - end - end @testset "mapped_grid" begin @@ -223,57 +171,106 @@ lg = equidistant_grid((0,0), (1,1), 10, 11) @test logicalgrid(mg) == lg @test collect(mg) == map(x̄, lg) +end +@testset "jacobian_determinant" begin + @test_broken false +end + +@testset "metric_tensor" begin + @test_broken false +end + +@testset "metric_tensor_inverse" begin + @test_broken false +end + +@testset "min_spacing" begin + let g = mapped_grid(identity, x->@SMatrix[1], 11) + @test min_spacing(g) ≈ 0.1 + end + + let g = mapped_grid(x->x+x.^2/2, x->@SMatrix[1 .+ x], 11) + @test min_spacing(g) ≈ 0.105 + end - @testset "normal" begin - @test normal(mg, CartesianBoundary{1,Lower}()) == fill(@SVector[-1,0], 11) - @test normal(mg, CartesianBoundary{1,Upper}()) == fill(@SVector[1,0], 11) - @test normal(mg, CartesianBoundary{2,Lower}()) == fill(@SVector[0,-1], 10) - @test normal(mg, CartesianBoundary{2,Upper}()) ≈ map(boundary_grid(mg,CartesianBoundary{2,Upper}())|>logicalgrid) do ξ̄ - α = 1-2ξ̄[1] - @SVector[α,1]/√(α^2 + 1) - end + let g = mapped_grid(x->x + x.*(1 .- x)/2, x->@SMatrix[1.5 .- x], 11) + @test min_spacing(g) ≈ 0.055 + end + + let g = mapped_grid(identity, x->@SMatrix[1 0; 0 1], 11,11) + @test min_spacing(g) ≈ 0.1 + end + + let g = mapped_grid(identity, x->@SMatrix[1 0; 0 1], 11,21) + @test min_spacing(g) ≈ 0.05 + end + skew_grid(a,b, sz...) = mapped_grid(ξ̄->ξ̄[1]*a + ξ̄[2]*b, ξ̄->[a b], sz...) - x̄((ξ, η)) = @SVector[2ξ + η*(1-η), 3η+(1+η/2)*ξ^2] - J((ξ, η)) = @SMatrix[ - 2 1-2η; - (2+η)*ξ 3+1/2*ξ^2; - ] + @testset let a = @SVector[1,0], b = @SVector[1,1]/√2 + g = skew_grid(a,b,11,11) + + @test min_spacing(g) ≈ 0.1*norm(b-a) + end - g = mapped_grid(x̄,J,21,14) - g = mapped_grid(x̄,J,3,4) + @testset let a = @SVector[1,0], b = @SVector[-1,1]/√2 + g = skew_grid(a,b,11,11) + + @test min_spacing(g) ≈ 0.1*norm(a+b) + end +end - unit(v) = v/norm(v) - @testset let bId = CartesianBoundary{1,Lower}() - lbg = boundary_grid(logicalgrid(g), bId) - @test normal(g, bId) ≈ map(lbg) do (ξ, η) - -unit(@SVector[1/2, η/3-1/6]) - end - end +@testset "normal" begin + x̄((ξ, η)) = @SVector[ξ, η*(1+ξ*(ξ-1))] + J((ξ, η)) = @SMatrix[ + 1 0; + η*(2ξ-1) 1+ξ*(ξ-1); + ] + g = mapped_grid(x̄, J, 10, 11) - @testset let bId = CartesianBoundary{1,Upper}() - lbg = boundary_grid(logicalgrid(g), bId) - @test normal(g, bId) ≈ map(lbg) do (ξ, η) - unit(@SVector[7/2, 2η-1]/(5 + 3η + 2η^2)) - end + @test normal(g, CartesianBoundary{1,Lower}()) == fill(@SVector[-1,0], 11) + @test normal(g, CartesianBoundary{1,Upper}()) == fill(@SVector[1,0], 11) + @test normal(g, CartesianBoundary{2,Lower}()) == fill(@SVector[0,-1], 10) + @test normal(g, CartesianBoundary{2,Upper}()) ≈ map(boundary_grid(g,CartesianBoundary{2,Upper}())|>logicalgrid) do ξ̄ + α = 1-2ξ̄[1] + @SVector[α,1]/√(α^2 + 1) + end + + x̄((ξ, η)) = @SVector[2ξ + η*(1-η), 3η+(1+η/2)*ξ^2] + J((ξ, η)) = @SMatrix[ + 2 1-2η; + (2+η)*ξ 3+1/2*ξ^2; + ] + + g = mapped_grid(x̄,J,5,4) + + unit(v) = v/norm(v) + @testset let bId = CartesianBoundary{1,Lower}() + lbg = boundary_grid(logicalgrid(g), bId) + @test normal(g, bId) ≈ map(lbg) do (ξ, η) + -unit(@SVector[1/2, η/3-1/6]) end + end - @testset let bId = CartesianBoundary{2,Lower}() - lbg = boundary_grid(logicalgrid(g), bId) - @test normal(g, bId) ≈ map(lbg) do (ξ, η) - -unit(@SVector[-2ξ, 2]/(6 + ξ^2 - 2ξ)) - end + @testset let bId = CartesianBoundary{1,Upper}() + lbg = boundary_grid(logicalgrid(g), bId) + @test normal(g, bId) ≈ map(lbg) do (ξ, η) + unit(@SVector[7/2, 2η-1]/(5 + 3η + 2η^2)) end + end - @testset let bId = CartesianBoundary{2,Upper}() - lbg = boundary_grid(logicalgrid(g), bId) - @test normal(g, bId) ≈ map(lbg) do (ξ, η) - unit(@SVector[-3ξ, 2]/(6 + ξ^2 + 3ξ)) - end + @testset let bId = CartesianBoundary{2,Lower}() + lbg = boundary_grid(logicalgrid(g), bId) + @test normal(g, bId) ≈ map(lbg) do (ξ, η) + -unit(@SVector[-2ξ, 2]/(6 + ξ^2 - 2ξ)) + end + end + + @testset let bId = CartesianBoundary{2,Upper}() + lbg = boundary_grid(logicalgrid(g), bId) + @test normal(g, bId) ≈ map(lbg) do (ξ, η) + unit(@SVector[-3ξ, 2]/(6 + ξ^2 + 3ξ)) end end end - -# TODO: Reorganize tests to not be nested. -# Want to ues "mapped_grid" to contruct tests for some of the differential geometry methods