Mercurial > repos > public > sbplib_julia
comparison test/Grids/mapped_grid_test.jl @ 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 |
comparison
equal
deleted
inserted
replaced
| 1689:e11b5b6940a2 | 1690:5eabe1f560f0 |
|---|---|
| 155 @testset test_boundary_grid(mg, TensorGridBoundary{1, Lower}(), J2) | 155 @testset test_boundary_grid(mg, TensorGridBoundary{1, Lower}(), J2) |
| 156 @testset test_boundary_grid(mg, TensorGridBoundary{1, Upper}(), J2) | 156 @testset test_boundary_grid(mg, TensorGridBoundary{1, Upper}(), J2) |
| 157 @testset test_boundary_grid(mg, TensorGridBoundary{2, Lower}(), J1) | 157 @testset test_boundary_grid(mg, TensorGridBoundary{2, Lower}(), J1) |
| 158 @testset test_boundary_grid(mg, TensorGridBoundary{2, Upper}(), J1) | 158 @testset test_boundary_grid(mg, TensorGridBoundary{2, Upper}(), J1) |
| 159 end | 159 end |
| 160 | |
| 161 @testset "jacobian_determinant" begin | |
| 162 @test_broken false | |
| 163 end | |
| 164 | |
| 165 @testset "metric_tensor" begin | |
| 166 @test_broken false | |
| 167 end | |
| 168 | |
| 169 @testset "metric_tensor_inverse" begin | |
| 170 @test_broken false | |
| 171 end | |
| 172 | |
| 173 | |
| 174 @testset "min_spacing" begin | |
| 175 let g = mapped_grid(identity, x->@SMatrix[1], 11) | |
| 176 @test min_spacing(g) ≈ 0.1 | |
| 177 end | |
| 178 | |
| 179 let g = mapped_grid(x->x+x.^2/2, x->@SMatrix[1 .+ x], 11) | |
| 180 @test min_spacing(g) ≈ 0.105 | |
| 181 end | |
| 182 | |
| 183 let g = mapped_grid(x->x + x.*(1 .- x)/2, x->@SMatrix[1.5 .- x], 11) | |
| 184 @test min_spacing(g) ≈ 0.055 | |
| 185 end | |
| 186 | |
| 187 let g = mapped_grid(identity, x->@SMatrix[1 0; 0 1], 11,11) | |
| 188 @test min_spacing(g) ≈ 0.1 | |
| 189 end | |
| 190 | |
| 191 let g = mapped_grid(identity, x->@SMatrix[1 0; 0 1], 11,21) | |
| 192 @test min_spacing(g) ≈ 0.05 | |
| 193 end | |
| 194 | |
| 195 skew_grid(a,b, sz...) = mapped_grid(ξ̄->ξ̄[1]*a + ξ̄[2]*b, ξ̄->[a b], sz...) | |
| 196 | |
| 197 @testset let a = @SVector[1,0], b = @SVector[1,1]/√2 | |
| 198 g = skew_grid(a,b,11,11) | |
| 199 | |
| 200 @test min_spacing(g) ≈ 0.1*norm(b-a) | |
| 201 end | |
| 202 | |
| 203 @testset let a = @SVector[1,0], b = @SVector[-1,1]/√2 | |
| 204 g = skew_grid(a,b,11,11) | |
| 205 | |
| 206 @test min_spacing(g) ≈ 0.1*norm(a+b) | |
| 207 end | |
| 208 | |
| 209 # Skevt nät | |
| 210 end | |
| 211 | |
| 212 end | 160 end |
| 213 | 161 |
| 214 @testset "mapped_grid" begin | 162 @testset "mapped_grid" begin |
| 215 x̄((ξ, η)) = @SVector[ξ, η*(1+ξ*(ξ-1))] | 163 x̄((ξ, η)) = @SVector[ξ, η*(1+ξ*(ξ-1))] |
| 216 J((ξ, η)) = @SMatrix[ | 164 J((ξ, η)) = @SMatrix[ |
| 221 @test mg isa MappedGrid{SVector{2,Float64}, 2} | 169 @test mg isa MappedGrid{SVector{2,Float64}, 2} |
| 222 | 170 |
| 223 lg = equidistant_grid((0,0), (1,1), 10, 11) | 171 lg = equidistant_grid((0,0), (1,1), 10, 11) |
| 224 @test logicalgrid(mg) == lg | 172 @test logicalgrid(mg) == lg |
| 225 @test collect(mg) == map(x̄, lg) | 173 @test collect(mg) == map(x̄, lg) |
| 226 | 174 end |
| 227 | 175 |
| 228 @testset "normal" begin | 176 @testset "jacobian_determinant" begin |
| 229 @test normal(mg, CartesianBoundary{1,Lower}()) == fill(@SVector[-1,0], 11) | 177 @test_broken false |
| 230 @test normal(mg, CartesianBoundary{1,Upper}()) == fill(@SVector[1,0], 11) | 178 end |
| 231 @test normal(mg, CartesianBoundary{2,Lower}()) == fill(@SVector[0,-1], 10) | 179 |
| 232 @test normal(mg, CartesianBoundary{2,Upper}()) ≈ map(boundary_grid(mg,CartesianBoundary{2,Upper}())|>logicalgrid) do ξ̄ | 180 @testset "metric_tensor" begin |
| 233 α = 1-2ξ̄[1] | 181 @test_broken false |
| 234 @SVector[α,1]/√(α^2 + 1) | 182 end |
| 235 end | 183 |
| 236 | 184 @testset "metric_tensor_inverse" begin |
| 237 | 185 @test_broken false |
| 238 x̄((ξ, η)) = @SVector[2ξ + η*(1-η), 3η+(1+η/2)*ξ^2] | 186 end |
| 239 J((ξ, η)) = @SMatrix[ | 187 |
| 240 2 1-2η; | 188 @testset "min_spacing" begin |
| 241 (2+η)*ξ 3+1/2*ξ^2; | 189 let g = mapped_grid(identity, x->@SMatrix[1], 11) |
| 242 ] | 190 @test min_spacing(g) ≈ 0.1 |
| 243 | 191 end |
| 244 g = mapped_grid(x̄,J,21,14) | 192 |
| 245 g = mapped_grid(x̄,J,3,4) | 193 let g = mapped_grid(x->x+x.^2/2, x->@SMatrix[1 .+ x], 11) |
| 246 | 194 @test min_spacing(g) ≈ 0.105 |
| 247 unit(v) = v/norm(v) | 195 end |
| 248 @testset let bId = CartesianBoundary{1,Lower}() | 196 |
| 249 lbg = boundary_grid(logicalgrid(g), bId) | 197 let g = mapped_grid(x->x + x.*(1 .- x)/2, x->@SMatrix[1.5 .- x], 11) |
| 250 @test normal(g, bId) ≈ map(lbg) do (ξ, η) | 198 @test min_spacing(g) ≈ 0.055 |
| 251 -unit(@SVector[1/2, η/3-1/6]) | 199 end |
| 252 end | 200 |
| 253 end | 201 let g = mapped_grid(identity, x->@SMatrix[1 0; 0 1], 11,11) |
| 254 | 202 @test min_spacing(g) ≈ 0.1 |
| 255 @testset let bId = CartesianBoundary{1,Upper}() | 203 end |
| 256 lbg = boundary_grid(logicalgrid(g), bId) | 204 |
| 257 @test normal(g, bId) ≈ map(lbg) do (ξ, η) | 205 let g = mapped_grid(identity, x->@SMatrix[1 0; 0 1], 11,21) |
| 258 unit(@SVector[7/2, 2η-1]/(5 + 3η + 2η^2)) | 206 @test min_spacing(g) ≈ 0.05 |
| 259 end | 207 end |
| 260 end | 208 |
| 261 | 209 skew_grid(a,b, sz...) = mapped_grid(ξ̄->ξ̄[1]*a + ξ̄[2]*b, ξ̄->[a b], sz...) |
| 262 @testset let bId = CartesianBoundary{2,Lower}() | 210 |
| 263 lbg = boundary_grid(logicalgrid(g), bId) | 211 @testset let a = @SVector[1,0], b = @SVector[1,1]/√2 |
| 264 @test normal(g, bId) ≈ map(lbg) do (ξ, η) | 212 g = skew_grid(a,b,11,11) |
| 265 -unit(@SVector[-2ξ, 2]/(6 + ξ^2 - 2ξ)) | 213 |
| 266 end | 214 @test min_spacing(g) ≈ 0.1*norm(b-a) |
| 267 end | 215 end |
| 268 | 216 |
| 269 @testset let bId = CartesianBoundary{2,Upper}() | 217 @testset let a = @SVector[1,0], b = @SVector[-1,1]/√2 |
| 270 lbg = boundary_grid(logicalgrid(g), bId) | 218 g = skew_grid(a,b,11,11) |
| 271 @test normal(g, bId) ≈ map(lbg) do (ξ, η) | 219 |
| 272 unit(@SVector[-3ξ, 2]/(6 + ξ^2 + 3ξ)) | 220 @test min_spacing(g) ≈ 0.1*norm(a+b) |
| 273 end | 221 end |
| 274 end | 222 end |
| 275 end | 223 |
| 276 end | 224 @testset "normal" begin |
| 277 | 225 x̄((ξ, η)) = @SVector[ξ, η*(1+ξ*(ξ-1))] |
| 278 # TODO: Reorganize tests to not be nested. | 226 J((ξ, η)) = @SMatrix[ |
| 279 # Want to ues "mapped_grid" to contruct tests for some of the differential geometry methods | 227 1 0; |
| 228 η*(2ξ-1) 1+ξ*(ξ-1); | |
| 229 ] | |
| 230 g = mapped_grid(x̄, J, 10, 11) | |
| 231 | |
| 232 @test normal(g, CartesianBoundary{1,Lower}()) == fill(@SVector[-1,0], 11) | |
| 233 @test normal(g, CartesianBoundary{1,Upper}()) == fill(@SVector[1,0], 11) | |
| 234 @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 ξ̄ | |
| 236 α = 1-2ξ̄[1] | |
| 237 @SVector[α,1]/√(α^2 + 1) | |
| 238 end | |
| 239 | |
| 240 x̄((ξ, η)) = @SVector[2ξ + η*(1-η), 3η+(1+η/2)*ξ^2] | |
| 241 J((ξ, η)) = @SMatrix[ | |
| 242 2 1-2η; | |
| 243 (2+η)*ξ 3+1/2*ξ^2; | |
| 244 ] | |
| 245 | |
| 246 g = mapped_grid(x̄,J,5,4) | |
| 247 | |
| 248 unit(v) = v/norm(v) | |
| 249 @testset let bId = CartesianBoundary{1,Lower}() | |
| 250 lbg = boundary_grid(logicalgrid(g), bId) | |
| 251 @test normal(g, bId) ≈ map(lbg) do (ξ, η) | |
| 252 -unit(@SVector[1/2, η/3-1/6]) | |
| 253 end | |
| 254 end | |
| 255 | |
| 256 @testset let bId = CartesianBoundary{1,Upper}() | |
| 257 lbg = boundary_grid(logicalgrid(g), bId) | |
| 258 @test normal(g, bId) ≈ map(lbg) do (ξ, η) | |
| 259 unit(@SVector[7/2, 2η-1]/(5 + 3η + 2η^2)) | |
| 260 end | |
| 261 end | |
| 262 | |
| 263 @testset let bId = CartesianBoundary{2,Lower}() | |
| 264 lbg = boundary_grid(logicalgrid(g), bId) | |
| 265 @test normal(g, bId) ≈ map(lbg) do (ξ, η) | |
| 266 -unit(@SVector[-2ξ, 2]/(6 + ξ^2 - 2ξ)) | |
| 267 end | |
| 268 end | |
| 269 | |
| 270 @testset let bId = CartesianBoundary{2,Upper}() | |
| 271 lbg = boundary_grid(logicalgrid(g), bId) | |
| 272 @test normal(g, bId) ≈ map(lbg) do (ξ, η) | |
| 273 unit(@SVector[-3ξ, 2]/(6 + ξ^2 + 3ξ)) | |
| 274 end | |
| 275 end | |
| 276 end |
