comparison test/BoundaryConditions/boundary_condition_test.jl @ 1602:3e7438e2a033 feature/boundary_conditions

Address review comments (1 left to be discussed)
author Vidar Stiernström <vidar.stiernstrom@gmail.com>
date Sat, 01 Jun 2024 17:39:54 -0700
parents 330c39505a94
children
comparison
equal deleted inserted replaced
1601:fad18896d20a 1602:3e7438e2a033
1 using Test 1 using Test
2 2
3 using Sbplib.BoundaryConditions 3 using Sbplib.BoundaryConditions
4 using Sbplib.Grids 4 using Sbplib.Grids
5 using Sbplib.RegionIndices
5 6
6 @testset "BoundaryCondition" begin 7 @testset "BoundaryCondition" begin
7 grid_1d = equidistant_grid(0.0, 1.0, 11) 8 grid_1d = equidistant_grid(0.0, 1.0, 11)
8 grid_2d = equidistant_grid((0.0, 0.0), (1.0,1.0), 11, 15) 9 grid_2d = equidistant_grid((0.0, 0.0), (1.0,1.0), 11, 15)
9 grid_3d = equidistant_grid((0.0, 0.0, 0.0), (1.0,1.0, 1.0), 11, 15, 13) 10 grid_3d = equidistant_grid((0.0, 0.0, 0.0), (1.0,1.0, 1.0), 11, 15, 13)
11 (_,_,_,id_n) = boundary_identifiers(grid_2d) 12 (_,_,_,id_n) = boundary_identifiers(grid_2d)
12 (_,_,_,_,id_b,_) = boundary_identifiers(grid_3d) 13 (_,_,_,_,id_b,_) = boundary_identifiers(grid_3d)
13 14
14 g = 3.14 15 g = 3.14
15 f(x,y,z) = x^2+y^2+z^2 16 f(x,y,z) = x^2+y^2+z^2
16 @test DirichletCondition(g,id_l) isa BoundaryCondition{Float64} 17 @testset "Constructors" begin
17 @test DirichletCondition(g,id_n) isa BoundaryCondition{Float64} 18 @test DirichletCondition(g,id_l) isa BoundaryCondition{Lower}
18 @test NeumannCondition(f,id_b) isa BoundaryCondition{<:Function} 19 @test DirichletCondition(g,id_n) isa BoundaryCondition{CartesianBoundary{2,Upper}}
20 @test DirichletCondition(g,id_l) isa DirichletCondition{Float64,Lower}
21 @test NeumannCondition(f,id_b) isa NeumannCondition{<:Function}
22 end
19 23
20 @test fill(g) ≈ discretize_data(grid_1d,DirichletCondition(g,id_l)) 24 @testset "boundary" begin
21 @test g*ones(11,1) ≈ discretize_data(grid_2d,DirichletCondition(g,id_n)) 25 @test boundary(DirichletCondition(g,id_l)) == id_l
22 X = repeat(0:1/10:1, inner = (1,15)) 26 @test boundary(NeumannCondition(f,id_b)) == id_b
23 Y = repeat(0:1/14:1, outer = (1,11)) 27 end
24 @test map((x,y)->f(x,y,0), X,Y') ≈ discretize_data(grid_3d,NeumannCondition(f,id_b)) 28
29 @testset "boundary_data" begin
30 @test boundary_data(DirichletCondition(g,id_l)) == g
31 @test boundary_data(NeumannCondition(f,id_b)) == f
32 end
33
34 @testset "discretize_data" begin
35 @test fill(g) ≈ discretize_data(grid_1d,DirichletCondition(g,id_l))
36 @test g*ones(11,1) ≈ discretize_data(grid_2d,DirichletCondition(g,id_n))
37 X = repeat(0:1/10:1, inner = (1,15))
38 Y = repeat(0:1/14:1, outer = (1,11))
39 @test map((x,y)->f(x,y,0), X,Y') ≈ discretize_data(grid_3d,NeumannCondition(f,id_b))
40 end
25 end 41 end