Mercurial > repos > public > sbplib_julia
comparison test/BoundaryConditions/boundary_condition_test.jl @ 1481:ee242c3fe4af feature/boundary_conditions
Support boundary identifiers for 1D grids
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Mon, 25 Dec 2023 19:23:09 +0100 |
parents | fefc81a9c155 |
children | 330c39505a94 |
comparison
equal
deleted
inserted
replaced
1480:4550beef9694 | 1481:ee242c3fe4af |
---|---|
2 | 2 |
3 using Sbplib.BoundaryConditions | 3 using Sbplib.BoundaryConditions |
4 using Sbplib.Grids | 4 using Sbplib.Grids |
5 | 5 |
6 @testset "BoundaryCondition" begin | 6 @testset "BoundaryCondition" begin |
7 grid_1d = equidistant_grid(11, 0.0, 1.0) | |
7 grid_2d = equidistant_grid((11,15), (0.0, 0.0), (1.0,1.0)) | 8 grid_2d = equidistant_grid((11,15), (0.0, 0.0), (1.0,1.0)) |
8 grid_3d = equidistant_grid((11,15,13), (0.0, 0.0, 0.0), (1.0,1.0, 1.0)) | 9 grid_3d = equidistant_grid((11,15,13), (0.0, 0.0, 0.0), (1.0,1.0, 1.0)) |
10 (id_l,_) = boundary_identifiers(grid_1d) | |
9 (_,_,_,id_n) = boundary_identifiers(grid_2d) | 11 (_,_,_,id_n) = boundary_identifiers(grid_2d) |
10 (_,_,_,_,id_b,_) = boundary_identifiers(grid_3d) | 12 (_,_,_,_,id_b,_) = boundary_identifiers(grid_3d) |
11 | 13 |
12 g = 3.14 | 14 g = 3.14 |
13 f(x,y,z) = x^2+y^2+z^2 | 15 f(x,y,z) = x^2+y^2+z^2 |
16 @test DirichletCondition(g,id_l) isa BoundaryCondition{Float64} | |
14 @test DirichletCondition(g,id_n) isa BoundaryCondition{Float64} | 17 @test DirichletCondition(g,id_n) isa BoundaryCondition{Float64} |
15 @test NeumannCondition(f,id_b) isa BoundaryCondition{<:Function} | 18 @test NeumannCondition(f,id_b) isa BoundaryCondition{<:Function} |
16 | 19 |
20 @test fill(g) ≈ discretize_data(grid_1d,DirichletCondition(g,id_l)) | |
17 @test g*ones(11,1) ≈ discretize_data(grid_2d,DirichletCondition(g,id_n)) | 21 @test g*ones(11,1) ≈ discretize_data(grid_2d,DirichletCondition(g,id_n)) |
18 X = repeat(0:1/10:1, inner = (1,15)) | 22 X = repeat(0:1/10:1, inner = (1,15)) |
19 Y = repeat(0:1/14:1, outer = (1,11)) | 23 Y = repeat(0:1/14:1, outer = (1,11)) |
20 @test map((x,y)->f(x,y,0), X,Y') ≈ discretize_data(grid_3d,NeumannCondition(f,id_b)) | 24 @test map((x,y)->f(x,y,0), X,Y') ≈ discretize_data(grid_3d,NeumannCondition(f,id_b)) |
21 end | 25 end |