Mercurial > repos > public > sbplib_julia
comparison test/testSbpOperators.jl @ 644:e3fd4b7aa789 feature/volume_and_boundary_operators
Refactor tests for NormalDerivative
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Mon, 04 Jan 2021 18:28:00 +0100 |
parents | 0928bbc3ee8b |
children | c5ccab5cf164 |
comparison
equal
deleted
inserted
replaced
643:0928bbc3ee8b | 644:e3fd4b7aa789 |
---|---|
807 end | 807 end |
808 end | 808 end |
809 end | 809 end |
810 | 810 |
811 @testset "NormalDerivative" begin | 811 @testset "NormalDerivative" begin |
812 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | 812 g_1D = EquidistantGrid(11, 0.0, 1.0) |
813 g = EquidistantGrid((5,6), (0.0, 0.0), (4.0,5.0)) | 813 g_2D = EquidistantGrid((11,12), (0.0, 0.0), (1.0,1.0)) |
814 | 814 @testset "Constructors" begin |
815 d_w = NormalDerivative(g, op.dClosure, CartesianBoundary{1,Lower}()) | 815 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) |
816 d_e = NormalDerivative(g, op.dClosure, CartesianBoundary{1,Upper}()) | 816 @testset "1D" begin |
817 d_s = NormalDerivative(g, op.dClosure, CartesianBoundary{2,Lower}()) | 817 d_l = NormalDerivative(g_1D, op.dClosure, Lower()) |
818 d_n = NormalDerivative(g, op.dClosure, CartesianBoundary{2,Upper}()) | 818 @test d_l == NormalDerivative(g_1D, op.dClosure, CartesianBoundary{1,Lower}()) |
819 | 819 @test d_l isa BoundaryOperator{T,Lower} where T |
820 | 820 @test d_l isa TensorMapping{T,0,1} where T |
821 v = evalOn(g, (x,y)-> x^2 + (y-1)^2 + x*y) | 821 end |
822 v∂x = evalOn(g, (x,y)-> 2*x + y) | 822 @testset "2D" begin |
823 v∂y = evalOn(g, (x,y)-> 2*(y-1) + x) | 823 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) |
824 | 824 d_w = NormalDerivative(g_2D, op.dClosure, CartesianBoundary{1,Lower}()) |
825 @test d_w isa TensorMapping{T,1,2} where T | 825 d_n = NormalDerivative(g_2D, op.dClosure, CartesianBoundary{2,Upper}()) |
826 | 826 Ix = IdentityMapping{Float64}((size(g_2D)[1],)) |
827 @test d_w*v ≈ v∂x[1,:] | 827 Iy = IdentityMapping{Float64}((size(g_2D)[2],)) |
828 @test d_e*v ≈ -v∂x[end,:] | 828 d_l = NormalDerivative(restrict(g_2D,1),op.dClosure,Lower()) |
829 @test d_s*v ≈ v∂y[:,1] | 829 d_r = NormalDerivative(restrict(g_2D,2),op.dClosure,Upper()) |
830 @test d_n*v ≈ -v∂y[:,end] | 830 @test d_w == d_l⊗Iy |
831 | 831 @test d_n == Ix⊗d_r |
832 | 832 @test d_w isa TensorMapping{T,1,2} where T |
833 d_x_l = zeros(Float64, size(g)[1]) | 833 @test d_n isa TensorMapping{T,1,2} where T |
834 d_x_u = zeros(Float64, size(g)[1]) | 834 end |
835 for i ∈ eachindex(d_x_l) | 835 end |
836 d_x_l[i] = op.dClosure[i-1] | 836 @testset "Accuracy" begin |
837 d_x_u[i] = op.dClosure[length(d_x_u)-i] | 837 v = evalOn(g_2D, (x,y)-> x^2 + (y-1)^2 + x*y) |
838 end | 838 v∂x = evalOn(g_2D, (x,y)-> 2*x + y) |
839 | 839 v∂y = evalOn(g_2D, (x,y)-> 2*(y-1) + x) |
840 d_y_l = zeros(Float64, size(g)[2]) | 840 # TODO: Test for higher order polynomials? |
841 d_y_u = zeros(Float64, size(g)[2]) | 841 @testset "2nd order" begin |
842 for i ∈ eachindex(d_y_l) | 842 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) |
843 d_y_l[i] = op.dClosure[i-1] | 843 d_w = NormalDerivative(g_2D, op.dClosure, CartesianBoundary{1,Lower}()) |
844 d_y_u[i] = op.dClosure[length(d_y_u)-i] | 844 d_e = NormalDerivative(g_2D, op.dClosure, CartesianBoundary{1,Upper}()) |
845 end | 845 d_s = NormalDerivative(g_2D, op.dClosure, CartesianBoundary{2,Lower}()) |
846 | 846 d_n = NormalDerivative(g_2D, op.dClosure, CartesianBoundary{2,Upper}()) |
847 function prod_matrix(x,y) | 847 |
848 G = zeros(Float64, length(x), length(y)) | 848 @test d_w*v ≈ v∂x[1,:] atol = 1e-13 |
849 for I ∈ CartesianIndices(G) | 849 @test d_e*v ≈ -v∂x[end,:] atol = 1e-13 |
850 G[I] = x[I[1]]*y[I[2]] | 850 @test d_s*v ≈ v∂y[:,1] atol = 1e-13 |
851 end | 851 @test d_n*v ≈ -v∂y[:,end] atol = 1e-13 |
852 | 852 end |
853 return G | 853 |
854 end | 854 @testset "4th order" begin |
855 | 855 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) |
856 g_x = [1,2,3,4.0,5] | 856 d_w = NormalDerivative(g_2D, op.dClosure, CartesianBoundary{1,Lower}()) |
857 g_y = [5,4,3,2,1.0,11] | 857 d_e = NormalDerivative(g_2D, op.dClosure, CartesianBoundary{1,Upper}()) |
858 | 858 d_s = NormalDerivative(g_2D, op.dClosure, CartesianBoundary{2,Lower}()) |
859 G_w = prod_matrix(d_x_l, g_y) | 859 d_n = NormalDerivative(g_2D, op.dClosure, CartesianBoundary{2,Upper}()) |
860 G_e = prod_matrix(d_x_u, g_y) | 860 |
861 G_s = prod_matrix(g_x, d_y_l) | 861 @test d_w*v ≈ v∂x[1,:] atol = 1e-13 |
862 G_n = prod_matrix(g_x, d_y_u) | 862 @test d_e*v ≈ -v∂x[end,:] atol = 1e-13 |
863 | 863 @test d_s*v ≈ v∂y[:,1] atol = 1e-13 |
864 @test d_w'*g_y ≈ G_w | 864 @test d_n*v ≈ -v∂y[:,end] atol = 1e-13 |
865 @test_broken d_e'*g_y ≈ G_e | 865 end |
866 @test d_s'*g_x ≈ G_s | 866 end |
867 @test_broken d_n'*g_x ≈ G_n | 867 |
868 #TODO: Need to check this? Tested in BoundaryOperator. If so, the old test | |
869 # below should be fixed. | |
870 @testset "Transpose" begin | |
871 # op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
872 # d_x_l = zeros(Float64, size(g_2D)[1]) | |
873 # d_x_u = zeros(Float64, size(g_2D)[1]) | |
874 # for i ∈ eachindex(d_x_l) | |
875 # d_x_l[i] = op.dClosure[i-1] | |
876 # d_x_u[i] = op.dClosure[length(d_x_u)-i] | |
877 # end | |
878 # d_y_l = zeros(Float64, size(g_2D)[2]) | |
879 # d_y_u = zeros(Float64, size(g_2D)[2]) | |
880 # for i ∈ eachindex(d_y_l) | |
881 # d_y_l[i] = op.dClosure[i-1] | |
882 # d_y_u[i] = op.dClosure[length(d_y_u)-i] | |
883 # end | |
884 # function prod_matrix(x,y) | |
885 # G = zeros(Float64, length(x), length(y)) | |
886 # for I ∈ CartesianIndices(G) | |
887 # G[I] = x[I[1]]*y[I[2]] | |
888 # end | |
889 # | |
890 # return G | |
891 # end | |
892 # g_x = [1,2,3,4.0,5] | |
893 # g_y = [5,4,3,2,1.0,11] | |
894 # | |
895 # G_w = prod_matrix(d_x_l, g_y) | |
896 # G_e = prod_matrix(d_x_u, g_y) | |
897 # G_s = prod_matrix(g_x, d_y_l) | |
898 # G_n = prod_matrix(g_x, d_y_u) | |
899 # | |
900 # @test d_w'*g_y ≈ G_w | |
901 # @test_broken d_e'*g_y ≈ G_e | |
902 # @test d_s'*g_x ≈ G_s | |
903 # @test_broken d_n'*g_x ≈ G_n | |
904 end | |
868 end | 905 end |
869 # | 906 # |
870 # @testset "BoundaryQuadrature" begin | 907 # @testset "BoundaryQuadrature" begin |
871 # op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | 908 # op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) |
872 # g = EquidistantGrid((10,11), (0.0, 0.0), (1.0,1.0)) | 909 # g = EquidistantGrid((10,11), (0.0, 0.0), (1.0,1.0)) |