view test/BoundaryConditions/sat_test.jl @ 1479:b96858a50e35 feature/boundary_conditions

Add tests for SAT
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Sat, 23 Dec 2023 23:01:28 +0100
parents bdcdbd4ea9cd
children 329720b9ba0d
line wrap: on
line source

using Test


using Sbplib.BoundaryConditions
using Sbplib.Grids
using Sbplib.LazyTensors
using Sbplib.SbpOperators

stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order = 4)

struct MockOp
end

function BoundaryConditions.sat_tensors(op::MockOp, g::TensorGrid, bc::DirichletCondition)
    e = boundary_restriction(g, stencil_set, id(bc))
    L = e
    sat_op = e'
    return sat_op, L
end

function BoundaryConditions.sat_tensors(op::MockOp, g::TensorGrid, bc::DirichletCondition, a)
    e = boundary_restriction(g, stencil_set, id(bc))
    L = a*e
    sat_op = e'
    return sat_op, L
end

function BoundaryConditions.sat_tensors(op::MockOp, g::TensorGrid, bc::NeumannCondition)
    e = boundary_restriction(g, stencil_set, id(bc))
    d = normal_derivative(g, stencil_set, id(bc))
    L = d
    sat_op = e'
    return sat_op, L
end

@testset "sat" begin
    op = MockOp()
    grid  = equidistant_grid((11,13), (0.,0.), (1.,1.))
    W, E, S, N = boundary_identifiers(grid)
    u = eval_on(grid, (x,y) -> x+y^2)

    
    dc_W = DirichletCondition(1.0, W)
    SAT_W = sat(op, grid, dc_W)
    g_W = discretize_data(grid, dc_W)
    r_W = zeros(size(grid))
    r_W[1,:] .= map(y -> (y^2-1.), range(0., 1., length=13))
    @test SAT_W(u, g_W) ≈ r_W atol = 1e-13

    dc_E = DirichletCondition(2, E)
    SAT_E = sat(op, grid, dc_E, 2.)
    g_E = discretize_data(grid, dc_E)
    r_E = zeros(size(grid))
    r_E[end,:] .= map(y -> (2*(1. + y^2)-2.), range(0., 1., length=13))
    @test SAT_E(u, g_E) ≈ r_E atol = 1e-13

    nc_S = NeumannCondition(.0, S)
    SAT_S = sat(op, grid, nc_S)
    g_S = discretize_data(grid, nc_S)
    @test SAT_S(u, g_S) ≈ zeros(size(grid)) atol = 1e-13

    nc_N = NeumannCondition(2.0, N)
    SAT_S = sat(op, grid, nc_N)
    g_N = discretize_data(grid, nc_N)
    @test SAT_S(u, g_N) ≈ zeros(size(grid)) atol = 1e-13
end