Mercurial > repos > public > sbplib_julia
comparison test/SbpOperators/boundary_conditions/sat_test.jl @ 1603:fca4a01d60c9 feature/boundary_conditions
Remove module BoundaryConditions, moving its content to SbpOperators
author | Vidar Stiernström <vidar.stiernstrom@gmail.com> |
---|---|
date | Tue, 04 Jun 2024 16:46:14 -0700 |
parents | test/BoundaryConditions/sat_test.jl@3e7438e2a033 |
children | 471a948cd2b2 |
comparison
equal
deleted
inserted
replaced
1602:3e7438e2a033 | 1603:fca4a01d60c9 |
---|---|
1 using Test | |
2 | |
3 using Sbplib.Grids | |
4 using Sbplib.LazyTensors | |
5 using Sbplib.SbpOperators | |
6 | |
7 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order = 4) | |
8 | |
9 struct MockOp end | |
10 | |
11 function SbpOperators.sat_tensors(op::MockOp, g::Grid, bc::DirichletCondition; a = 1.) | |
12 e = boundary_restriction(g, stencil_set, boundary(bc)) | |
13 L = a*e | |
14 sat_op = e' | |
15 return sat_op, L | |
16 end | |
17 | |
18 function SbpOperators.sat_tensors(op::MockOp, g::Grid, bc::NeumannCondition) | |
19 e = boundary_restriction(g, stencil_set, boundary(bc)) | |
20 d = normal_derivative(g, stencil_set, boundary(bc)) | |
21 L = d | |
22 sat_op = e' | |
23 return sat_op, L | |
24 end | |
25 | |
26 @testset "sat" begin | |
27 op = MockOp() | |
28 @testset "1D" begin | |
29 grid = equidistant_grid(0., 1., 11) | |
30 l, r = boundary_identifiers(grid) | |
31 u = eval_on(grid, x-> 1. + 2x^2) | |
32 dc = DirichletCondition(1.0, l) | |
33 g_l = discretize_data(grid, dc) | |
34 SAT_l = sat(op, grid, dc) | |
35 @test SAT_l(u, g_l) ≈ zeros((size(grid))) atol = 1e-13 | |
36 | |
37 nc = NeumannCondition(4.0, r) | |
38 g_r = discretize_data(grid, nc) | |
39 SAT_r = sat(op, grid, nc) | |
40 @test SAT_r(u, g_r) ≈ zeros((size(grid))) atol = 1e-13 | |
41 end | |
42 @testset "2D" begin | |
43 grid = equidistant_grid((0.,0.), (1.,1.), 11, 13) | |
44 W, E, S, N = boundary_identifiers(grid) | |
45 u = eval_on(grid, (x,y) -> x+y^2) | |
46 | |
47 dc_W = DirichletCondition(1.0, W) | |
48 SAT_W = sat(op, grid, dc_W) | |
49 g_W = discretize_data(grid, dc_W) | |
50 r_W = zeros(size(grid)) | |
51 r_W[1,:] .= map(y -> (y^2-1.), range(0., 1., length=13)) | |
52 @test SAT_W(u, g_W) ≈ r_W atol = 1e-13 | |
53 | |
54 dc_E = DirichletCondition(2, E) | |
55 SAT_E = sat(op, grid, dc_E; a = 2.) | |
56 g_E = discretize_data(grid, dc_E) | |
57 r_E = zeros(size(grid)) | |
58 r_E[end,:] .= map(y -> (2*(1. + y^2)-2.), range(0., 1., length=13)) | |
59 @test SAT_E(u, g_E) ≈ r_E atol = 1e-13 | |
60 | |
61 nc_S = NeumannCondition(.0, S) | |
62 SAT_S = sat(op, grid, nc_S) | |
63 g_S = discretize_data(grid, nc_S) | |
64 @test SAT_S(u, g_S) ≈ zeros(size(grid)) atol = 1e-13 | |
65 | |
66 nc_N = NeumannCondition(2.0, N) | |
67 SAT_N = sat(op, grid, nc_N) | |
68 g_N = discretize_data(grid, nc_N) | |
69 @test SAT_N(u, g_N) ≈ zeros(size(grid)) atol = 1e-13 | |
70 end | |
71 end |