comparison DiffOps/test/runtests.jl @ 244:a827568fc251 boundary_conditions

Fix NormalDerivative and add tests
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 26 Jun 2019 21:22:36 +0200
parents 9819243102dd
children 5571d2c5bf0f
comparison
equal deleted inserted replaced
243:01a67d1b8b5d 244:a827568fc251
2 using DiffOps 2 using DiffOps
3 using Grids 3 using Grids
4 using SbpOperators 4 using SbpOperators
5 using RegionIndices 5 using RegionIndices
6 using LazyTensors 6 using LazyTensors
7
8 @test_broken false
9 7
10 @testset "BoundaryValue" begin 8 @testset "BoundaryValue" begin
11 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") 9 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt")
12 g = EquidistantGrid((4,5), (0.0, 0.0), (1.0,1.0)) 10 g = EquidistantGrid((4,5), (0.0, 0.0), (1.0,1.0))
13 11
54 G_s[:,1] = g_x 52 G_s[:,1] = g_x
55 53
56 G_n = zeros(Float64, (4,5)) 54 G_n = zeros(Float64, (4,5))
57 G_n[:,5] = g_x 55 G_n[:,5] = g_x
58 56
57 @test size(e_w*g_y) == (4,5)
58 @test size(e_e*g_y) == (4,5)
59 @test size(e_s*g_x) == (4,5)
60 @test size(e_n*g_x) == (4,5)
61
59 @test collect(e_w*g_y) == G_w 62 @test collect(e_w*g_y) == G_w
60 @test collect(e_e*g_y) == G_e 63 @test collect(e_e*g_y) == G_e
61 @test collect(e_s*g_x) == G_s 64 @test collect(e_s*g_x) == G_s
62 @test collect(e_n*g_x) == G_n 65 @test collect(e_n*g_x) == G_n
66 end
63 67
68 @testset "NormalDerivative" begin
69 op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt")
70 g = EquidistantGrid((5,6), (0.0, 0.0), (4.0,5.0))
71
72 d_w = NormalDerivative(op, g, CartesianBoundary{1,Lower}())
73 d_e = NormalDerivative(op, g, CartesianBoundary{1,Upper}())
74 d_s = NormalDerivative(op, g, CartesianBoundary{2,Lower}())
75 d_n = NormalDerivative(op, g, CartesianBoundary{2,Upper}())
76
77
78 v = evalOn(g, (x,y)-> x^2 + (y-1)^2 + x*y)
79 v∂x = evalOn(g, (x,y)-> 2*x + y)
80 v∂y = evalOn(g, (x,y)-> 2*(y-1) + x)
81
82 @test d_w isa TensorMapping{T,2,1} where T
83 @test d_w' isa TensorMapping{T,1,2} where T
84
85 @test domain_size(d_w, (3,2)) == (2,)
86 @test domain_size(d_e, (3,2)) == (2,)
87 @test domain_size(d_s, (3,2)) == (3,)
88 @test domain_size(d_n, (3,2)) == (3,)
89
90 @test size(d_w'*v) == (6,)
91 @test size(d_e'*v) == (6,)
92 @test size(d_s'*v) == (5,)
93 @test size(d_n'*v) == (5,)
94
95 @test collect(d_w'*v) ≈ v∂x[1,:]
96 @test collect(d_e'*v) ≈ v∂x[5,:]
97 @test collect(d_s'*v) ≈ v∂y[:,1]
98 @test collect(d_n'*v) ≈ v∂y[:,6]
99
100
101 d_x_l = zeros(Float64, 5)
102 d_x_u = zeros(Float64, 5)
103 for i ∈ eachindex(d_x_l)
104 d_x_l[i] = op.dClosure[i-1]
105 d_x_u[i] = -op.dClosure[length(d_x_u)-i]
106 end
107
108 d_y_l = zeros(Float64, 6)
109 d_y_u = zeros(Float64, 6)
110 for i ∈ eachindex(d_y_l)
111 d_y_l[i] = op.dClosure[i-1]
112 d_y_u[i] = -op.dClosure[length(d_y_u)-i]
113 end
114
115 function ❓(x,y)
116 G = zeros(Float64, length(x), length(y))
117 for I ∈ CartesianIndices(G)
118 G[I] = x[I[1]]*y[I[2]]
119 end
120
121 return G
122 end
123
124 g_x = [1,2,3,4.0,5]
125 g_y = [5,4,3,2,1.0,11]
126
127 G_w = ❓(d_x_l, g_y)
128 G_e = ❓(d_x_u, g_y)
129 G_s = ❓(g_x, d_y_l)
130 G_n = ❓(g_x, d_y_u)
131
132
133 @test size(d_w*g_y) == (5,6)
134 @test size(d_e*g_y) == (5,6)
135 @test size(d_s*g_x) == (5,6)
136 @test size(d_n*g_x) == (5,6)
137
138 @test collect(d_w*g_y) ≈ G_w
139 @test collect(d_e*g_y) ≈ G_e
140 @test collect(d_s*g_x) ≈ G_s
141 @test collect(d_n*g_x) ≈ G_n
64 end 142 end