changeset 239:60011a10e17d boundary_conditions

Add tests for BoundaryValue and fix index types
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 26 Jun 2019 20:02:01 +0200
parents d56bf288b3be
children 6bce42abf43d
files DiffOps/src/laplace.jl DiffOps/test/runtests.jl
diffstat 2 files changed, 20 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/DiffOps/src/laplace.jl	Wed Jun 26 20:01:10 2019 +0200
+++ b/DiffOps/src/laplace.jl	Wed Jun 26 20:02:01 2019 +0200
@@ -12,7 +12,7 @@
 
 # Not correct abstraction level
 # TODO: Not type stable D:<
-function apply(d::NormalDerivative, v::AbstractArray, I::CartesianIndex{2})
+function apply(d::NormalDerivative, v::AbstractArray, I::NTuple{2,Int})
 	i = I[dim(d.bId)]
 	j = I[3-dim(d.bId)]
 	N_i = d.grid.size[dim(d.bId)]
@@ -31,7 +31,7 @@
 	end
 end
 
-function apply_transpose(d::NormalDerivative, v::AbstractArray, I::CartesianIndex{1})
+function apply_transpose(d::NormalDerivative, v::AbstractArray, I::NTuple{1,Int})
     u = selectdim(v,3-dim(d.bId),I)
     return apply_d(d.op, d.grid.inverse_spacing[dim(d.bId)], u, region(d.bId))
 end
@@ -54,7 +54,7 @@
 LazyTensors.range_size(e::BoundaryValue{T}, domain_size::NTuple{1,Integer}) where T = size(e.grid)
 LazyTensors.domain_size(e::BoundaryValue{T}, range_size::NTuple{2,Integer}) where T = (range_size[3-dim(e.bId)],);
 
-function LazyTensors.apply(e::BoundaryValue, v::AbstractArray, I::CartesianIndex{2})
+function LazyTensors.apply(e::BoundaryValue, v::AbstractArray, I::NTuple{2,Int})
 	i = I[dim(e.bId)]
 	j = I[3-dim(e.bId)]
 	N_i = e.grid.size[dim(e.bId)]
@@ -73,8 +73,8 @@
 	end
 end
 
-function LazyTensors.apply_transpose(e::BoundaryValue, v::AbstractArray, I::CartesianIndex{1})
-	u = selectdim(v,3-dim(e.bId),I)
+function LazyTensors.apply_transpose(e::BoundaryValue, v::AbstractArray, I::NTuple{1,Int})
+	u = selectdim(v,3-dim(e.bId),I[1])
 	return apply_e(e.op, u, region(e.bId))
 end
 
--- a/DiffOps/test/runtests.jl	Wed Jun 26 20:01:10 2019 +0200
+++ b/DiffOps/test/runtests.jl	Wed Jun 26 20:02:01 2019 +0200
@@ -9,19 +9,19 @@
 
 @testset "BoundaryValue" begin
     op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt")
-    g = EquidistantGrid((3,3), (0.0, 0.0), (1.0,1.0))
+    g = EquidistantGrid((4,5), (0.0, 0.0), (1.0,1.0))
 
     e_w = BoundaryValue(op, g, CartesianBoundary{1,Lower}())
     e_e = BoundaryValue(op, g, CartesianBoundary{1,Upper}())
     e_s = BoundaryValue(op, g, CartesianBoundary{2,Lower}())
     e_n = BoundaryValue(op, g, CartesianBoundary{2,Upper}())
 
-    v = [
-        1 2 3;
-        4 5 6;
-        7 8 9.0;
-        10 11 12;
-    ]
+    v = zeros(Float64, 4, 5)
+    v[:,5] = [1, 2, 3,4]
+    v[:,4] = [1, 2, 3,4]
+    v[:,3] = [4, 5, 6, 7]
+    v[:,2] = [7, 8, 9, 10]
+    v[:,1] = [10, 11, 12, 13]
 
     @test e_w  isa TensorMapping{T,2,1} where T
     @test e_w' isa TensorMapping{T,1,2} where T
@@ -31,7 +31,14 @@
     @test domain_size(e_s, (3,2)) == (3,)
     @test domain_size(e_n, (3,2)) == (3,)
 
+    @test size(e_w'*v) == (5,)
+    @test size(e_e'*v) == (5,)
+    @test size(e_s'*v) == (4,)
+    @test size(e_n'*v) == (4,)
 
-    @test collect(e_w'*v) == [1,4,7.0]
+    @test collect(e_w'*v) == [10,7,4,1.0,1]
+    @test collect(e_e'*v) == [13,10,7,4,4.0]
+    @test collect(e_s'*v) == [10,11,12,13.0]
+    @test collect(e_n'*v) == [1,2,3,4.0]
 
 end