Mercurial > repos > public > sbplib_julia
changeset 785:21d6bc4a6d65 refactor/inner_product_recursive
Remove default value for inner_stencil in inner_product()
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 19 Jul 2021 21:16:14 +0200 |
parents | cd8cd6db2a42 |
children | 937e19326795 |
files | src/SbpOperators/volumeops/inner_products/inner_product.jl test/SbpOperators/volumeops/inner_products/inner_product_test.jl test/SbpOperators/volumeops/inner_products/inverse_inner_product_test.jl |
diffstat | 3 files changed, 19 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/SbpOperators/volumeops/inner_products/inner_product.jl Mon Jul 19 20:39:38 2021 +0200 +++ b/src/SbpOperators/volumeops/inner_products/inner_product.jl Mon Jul 19 21:16:14 2021 +0200 @@ -6,8 +6,7 @@ `inner_product(grid::EquidistantGrid, closure_stencils, inner_stencil)` creates `H` on `grid` the using a set of stencils `closure_stencils` for the points in -the closure regions and the stencil and `inner_stencil` in the interior. If -`inner_stencil` is omitted a central interior stencil with weight 1 is used. +the closure regions and the stencil and `inner_stencil` in the interior. On a 1-dimensional `grid`, `H` is a `VolumeOperator`. On a N-dimensional `grid`, `H` is the outer product of the 1-dimensional inner product operators in @@ -15,7 +14,7 @@ `SbpOperators.volume_operator(...)` for more details. On a 0-dimensional `grid`, `H` is a 0-dimensional `IdentityMapping`. """ -function inner_product(grid::EquidistantGrid, closure_stencils, inner_stencil = CenteredStencil(one(eltype(grid)))) +function inner_product(grid::EquidistantGrid, closure_stencils, inner_stencil) Hs = () for i ∈ 1:dimension(grid) @@ -26,7 +25,7 @@ end export inner_product -function inner_product(grid::EquidistantGrid{1}, closure_stencils, inner_stencil = CenteredStencil(one(eltype(grid)))) +function inner_product(grid::EquidistantGrid{1}, closure_stencils, inner_stencil) h = spacing(grid) H = SbpOperators.volume_operator(grid, scale(inner_stencil,h[1]), scale.(closure_stencils,h[1]), even, 1) return H
--- a/test/SbpOperators/volumeops/inner_products/inner_product_test.jl Mon Jul 19 20:39:38 2021 +0200 +++ b/test/SbpOperators/volumeops/inner_products/inner_product_test.jl Mon Jul 19 21:16:14 2021 +0200 @@ -16,20 +16,19 @@ @testset "inner_product" begin op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) @testset "0D" begin - H = inner_product(EquidistantGrid{Float64}(),op.quadratureClosure) + H = inner_product(EquidistantGrid{Float64}(), op.quadratureClosure, CenteredStencil(1.)) @test H == IdentityMapping{Float64}() @test H isa TensorMapping{T,0,0} where T end @testset "1D" begin - H = inner_product(g_1D,op.quadratureClosure) - inner_stencil = CenteredStencil(1.) - @test H == inner_product(g_1D,op.quadratureClosure,inner_stencil) + H = inner_product(g_1D, op.quadratureClosure, CenteredStencil(1.)) + @test H == inner_product(g_1D, op.quadratureClosure, CenteredStencil(1.)) @test H isa TensorMapping{T,1,1} where T end @testset "2D" begin - H = inner_product(g_2D,op.quadratureClosure) - H_x = inner_product(restrict(g_2D,1),op.quadratureClosure) - H_y = inner_product(restrict(g_2D,2),op.quadratureClosure) + H = inner_product(g_2D, op.quadratureClosure, CenteredStencil(1.)) + H_x = inner_product(restrict( g_2D,1),op.quadratureClosure, CenteredStencil(1.)) + H_y = inner_product(restrict( g_2D,2),op.quadratureClosure, CenteredStencil(1.)) @test H == H_x⊗H_y @test H isa TensorMapping{T,2,2} where T end @@ -38,12 +37,12 @@ @testset "Sizes" begin op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) @testset "1D" begin - H = inner_product(g_1D,op.quadratureClosure) + H = inner_product(g_1D, op.quadratureClosure, CenteredStencil(1.)) @test domain_size(H) == size(g_1D) @test range_size(H) == size(g_1D) end @testset "2D" begin - H = inner_product(g_2D,op.quadratureClosure) + H = inner_product(g_2D, op.quadratureClosure, CenteredStencil(1.)) @test domain_size(H) == size(g_2D) @test range_size(H) == size(g_2D) end @@ -60,7 +59,7 @@ @testset "2nd order" begin op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) - H = inner_product(g_1D,op.quadratureClosure) + H = inner_product(g_1D, op.quadratureClosure, CenteredStencil(1.)) for i = 1:2 @test integral(H,v[i]) ≈ v[i+1][end] - v[i+1][1] rtol = 1e-14 end @@ -69,7 +68,7 @@ @testset "4th order" begin op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) - H = inner_product(g_1D,op.quadratureClosure) + H = inner_product(g_1D, op.quadratureClosure, CenteredStencil(1.)) for i = 1:4 @test integral(H,v[i]) ≈ v[i+1][end] - v[i+1][1] rtol = 1e-14 end @@ -83,13 +82,13 @@ u = evalOn(g_2D,(x,y)->sin(x)+cos(y)) @testset "2nd order" begin op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) - H = inner_product(g_2D,op.quadratureClosure) + H = inner_product(g_2D, op.quadratureClosure, CenteredStencil(1.)) @test integral(H,v) ≈ b*Lx*Ly rtol = 1e-13 @test integral(H,u) ≈ π rtol = 1e-4 end @testset "4th order" begin op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) - H = inner_product(g_2D,op.quadratureClosure) + H = inner_product(g_2D, op.quadratureClosure, CenteredStencil(1.)) @test integral(H,v) ≈ b*Lx*Ly rtol = 1e-13 @test integral(H,u) ≈ π rtol = 1e-8 end
--- a/test/SbpOperators/volumeops/inner_products/inverse_inner_product_test.jl Mon Jul 19 20:39:38 2021 +0200 +++ b/test/SbpOperators/volumeops/inner_products/inverse_inner_product_test.jl Mon Jul 19 21:16:14 2021 +0200 @@ -57,14 +57,14 @@ u = evalOn(g_1D,x->x^3-x^2+1) @testset "2nd order" begin op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) - H = inner_product(g_1D,op.quadratureClosure) + H = inner_product(g_1D, op.quadratureClosure, CenteredStencil(1.)) Hi = inverse_inner_product(g_1D,op.quadratureClosure) @test Hi*H*v ≈ v rtol = 1e-15 @test Hi*H*u ≈ u rtol = 1e-15 end @testset "4th order" begin op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) - H = inner_product(g_1D,op.quadratureClosure) + H = inner_product(g_1D, op.quadratureClosure, CenteredStencil(1.)) Hi = inverse_inner_product(g_1D,op.quadratureClosure) @test Hi*H*v ≈ v rtol = 1e-15 @test Hi*H*u ≈ u rtol = 1e-15 @@ -75,14 +75,14 @@ u = evalOn(g_2D,(x,y)->x*y + x^5 - sqrt(y)) @testset "2nd order" begin op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) - H = inner_product(g_2D,op.quadratureClosure) + H = inner_product(g_2D, op.quadratureClosure, CenteredStencil(1.)) Hi = inverse_inner_product(g_2D,op.quadratureClosure) @test Hi*H*v ≈ v rtol = 1e-15 @test Hi*H*u ≈ u rtol = 1e-15 end @testset "4th order" begin op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) - H = inner_product(g_2D,op.quadratureClosure) + H = inner_product(g_2D, op.quadratureClosure, CenteredStencil(1.)) Hi = inverse_inner_product(g_2D,op.quadratureClosure) @test Hi*H*v ≈ v rtol = 1e-15 @test Hi*H*u ≈ u rtol = 1e-15