Mercurial > repos > public > sbplib_julia
comparison test/BoundaryConditions/boundary_condition_test.jl @ 1406:b4ec84190e6b feature/boundary_conditions
Start reimplementing tests
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Tue, 22 Aug 2023 21:53:05 +0200 |
parents | bdcdbd4ea9cd |
children | 5f79549f60ae |
comparison
equal
deleted
inserted
replaced
1405:da1b85c80a3f | 1406:b4ec84190e6b |
---|---|
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 | 5 |
6 grid_1D = equidistant_grid(11, 0.0, 1.0) | 6 @testset "BoundaryCondition" begin |
7 grid_2D = equidistant_grid((11,15), (0.0, 0.0), (1.0,1.0)) | 7 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)) | 8 grid_3d = equidistant_grid((11,15,13), (0.0, 0.0, 0.0), (1.0,1.0, 1.0)) |
9 (id_l,_) = boundary_identifiers(grid_1D) | 9 (_,_,_,id_n) = boundary_identifiers(grid_2d) |
10 (_,_,_,id_n) = boundary_identifiers(grid_2D) | 10 (_,_,_,_,id_b,_) = boundary_identifiers(grid_3d) |
11 (_,_,_,_,id_b,_) = boundary_identifiers(grid_3D) | |
12 | 11 |
13 # @testset "BoundaryData" begin | 12 g = 3.14 |
14 | 13 f(x,y) = x^2+y^2 |
15 # @testset "ConstantBoundaryData" begin | 14 @test DirichletCondition(g,id_n) isa BoundaryCondition{Float64} |
16 # c = float(pi) | 15 @test NeumannCondition(f,id_n) isa BoundaryCondition{<:Function} |
17 # @test ConstantBoundaryData(c) isa BoundaryData | |
18 # g_1D = discretize(ConstantBoundaryData(c),boundary_grid(grid_1D, id_l)) | |
19 # g_2D = discretize(ConstantBoundaryData(c),boundary_grid(grid_2D, id_n)) | |
20 # @test g_1D isa Function | |
21 # @test g_2D isa Function | |
22 # @test g_1D(0.) == fill(c) | |
23 # @test g_2D(2.) == c*ones(11) | |
24 # @test_throws MethodError g_1D(0.,0.) | |
25 # @test_throws MethodError g_2D(0.,0.) | |
26 # end | |
27 | 16 |
28 # @testset "TimeDependentBoundaryData" begin | 17 # g_n = discretize_data(grid_2d,DirichletCondition(f,id_n)) |
29 # f(t) = 1. /(t+0.1) | 18 # @test g_n .≈ g*ones(1,11) |
30 # @test TimeDependentBoundaryData(f) isa BoundaryData | 19 end |
31 # g_1D = discretize(TimeDependentBoundaryData(f),boundary_grid(grid_1D, id_l)) | |
32 # g_2D = discretize(TimeDependentBoundaryData(f),boundary_grid(grid_2D, id_n)) | |
33 # @test g_1D isa Function | |
34 # @test g_2D isa Function | |
35 # @test g_1D(0.) == f(0.)*fill(1) | |
36 # @test g_2D(2.) == f(2.)*ones(11) | |
37 # @test_throws MethodError g_1D(0.,0.) | |
38 # @test_throws MethodError g_2D(0.,0.) | |
39 # end | |
40 | |
41 # #TBD: Is it reasoanble to have SpaceDependentBoundaryData for 1D-grids? It would then be a constant | |
42 # # which then may be represented by ConstantBoundaryData. | |
43 # @testset "SpaceDependentBoundaryData" begin | |
44 # f0(x) = 2 | |
45 # f1(x,y) = x.^2 | |
46 # f2(x,y,z) = x.^2 - y | |
47 # @test SpaceDependentBoundaryData(f1) isa BoundaryData | |
48 # g_1D = discretize(SpaceDependentBoundaryData(f0),boundary_grid(grid_1D, id_l)) | |
49 # g_2D = discretize(SpaceDependentBoundaryData(f1),boundary_grid(grid_2D, id_n)) | |
50 # g_3D = discretize(SpaceDependentBoundaryData(f2),boundary_grid(grid_3D, id_n)) | |
51 # @test g_1D isa Function | |
52 # @test g_2D isa Function | |
53 # @test g_3D isa Function | |
54 # @test g_1D(1.) == fill(f0()) # Does not work since eval_on for f0 returns (). | |
55 # @test g_2D(2.) ≈ f1.(range(0., 1., 11)) rtol=1e-14 | |
56 # @test g_3D(0.) ≈ eval_on(boundary_grid(grid_3D, id_n),f2) rtol=1e-14 | |
57 # @test_throws MethodError g_1D(0.,0.) | |
58 # @test_throws MethodError g_2D(0.,0.) | |
59 # @test_throws MethodError g_3D(0.,0.) | |
60 # end | |
61 | |
62 # # TBD: Include tests for 1D-grids? See TBD above | |
63 # @testset "SpaceTimeDependentBoundaryData" begin | |
64 # fx1(x) = x.^2 | |
65 # fx2(x,y) = x.^2 - y | |
66 # ft(t) = exp(t) | |
67 # ftx1(t,x) = ft(t)*fx1(x) | |
68 # ftx2(t,x,y) = ft(t)*fx2(x,y) | |
69 # @test SpaceTimeDependentBoundaryData(ftx1) isa BoundaryData | |
70 # g_2D = discretize(SpaceTimeDependentBoundaryData(ftx1),boundary_grid(grid_2D, id_n)) | |
71 # g_3D = discretize(SpaceTimeDependentBoundaryData(ftx2),boundary_grid(grid_3D, id_b)) | |
72 # @test g_2D isa Function | |
73 # @test g_3D isa Function | |
74 # @test g_2D(2.) ≈ ft(2.)*fx1.(range(0., 1., 11)) rtol=1e-14 | |
75 # @test g_3D(3.14) ≈ ft(3.14)*eval_on(boundary_grid(grid_3D, id_b),fx2) rtol=1e-14 | |
76 # @test_throws MethodError g_2D(0.,0.) | |
77 # @test_throws MethodError g_3D(0.,0.) | |
78 # end | |
79 | |
80 # @testset "ZeroBoundaryData" begin | |
81 # @test ZeroBoundaryData() isa BoundaryData | |
82 # g_2D = discretize(ZeroBoundaryData(), boundary_grid(grid_2D, id_n)) | |
83 # g_3D = discretize(ZeroBoundaryData(), boundary_grid(grid_3D, id_b)) | |
84 # @test g_2D isa Function | |
85 # @test g_3D isa Function | |
86 # @test g_2D(2.) ≈ 0.0*range(0., 1., 11) rtol=1e-14 | |
87 # f(x,y,z) = 0 | |
88 # @test g_3D(3.14) ≈ 0.0*eval_on(boundary_grid(grid_3D, id_b), f) rtol=1e-14 | |
89 # @test_throws MethodError g_2D(0.,0.) | |
90 # @test_throws MethodError g_3D(0.,0.) | |
91 # end | |
92 # end | |
93 | |
94 # @testset "BoundaryCondition" begin | |
95 # g = ConstantBoundaryData(1.0) | |
96 # NeumannCondition(g,id_n) isa BoundaryCondition{ConstantBoundaryData} | |
97 # DirichletCondition(g,id_n) isa BoundaryCondition{ConstantBoundaryData} | |
98 # @test data(NeumannCondition(g,id_n)) == g | |
99 # end |