view DiffOps/test/runtests.jl @ 243:01a67d1b8b5d boundary_conditions

Fix minus sign error
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 26 Jun 2019 21:19:00 +0200
parents 9819243102dd
children a827568fc251
line wrap: on
line source

using Test
using DiffOps
using Grids
using SbpOperators
using RegionIndices
using LazyTensors

@test_broken false

@testset "BoundaryValue" begin
    op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt")
    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 = 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

    @test domain_size(e_w, (3,2)) == (2,)
    @test domain_size(e_e, (3,2)) == (2,)
    @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) == [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]

    g_x = [1,2,3,4.0]
    g_y = [5,4,3,2,1.0]

    G_w = zeros(Float64, (4,5))
    G_w[1,:] = g_y

    G_e = zeros(Float64, (4,5))
    G_e[4,:] = g_y

    G_s = zeros(Float64, (4,5))
    G_s[:,1] = g_x

    G_n = zeros(Float64, (4,5))
    G_n[:,5] = g_x

    @test collect(e_w*g_y) == G_w
    @test collect(e_e*g_y) == G_e
    @test collect(e_s*g_x) == G_s
    @test collect(e_n*g_x) == G_n

end