Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
utkinis committed Oct 13, 2023
1 parent 8382ce3 commit 2a0f9d1
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions test/test_bc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,30 @@ using FastIce.BoundaryConditions
@testset "value" begin
@testset "x-dim" begin
data(field) .= 0.0
west_bc = DirichletBC{HalfCell}(1.0)
east_bc = DirichletBC{FullCell}(0.5)
apply_bcs!(Val(1), backend, grid, (field,), ((west_bc, east_bc),); async=false)
@test all((parent(field)[1, 2:ny+1, 2:nz+1] .+ parent(field)[2, 2:ny+1, 2:nz+1]) ./ 2 .≈ west_bc.condition)
@test all(parent(field)[nx+2, 2:ny+1, 2:nz+1] .≈ east_bc.condition)
west_bc = FieldBoundaryConditions((field,), (DirichletBC{HalfCell}(1.0),))
east_bc = FieldBoundaryConditions((field,), (DirichletBC{FullCell}(0.5),))
apply_boundary_conditions!(Val(1), Val(1), backend, grid, west_bc; async=false)
apply_boundary_conditions!(Val(2), Val(1), backend, grid, east_bc; async=false)
@test all((field[0, 1:ny, 1:nz] .+ field[1, 1:ny, 1:nz]) ./ 2 .≈ west_bc.conditions[1].condition)
@test all(field[nx+1, 1:ny, 1:nz] .≈ east_bc.conditions[1].condition)
end
@testset "y-dim" begin
data(field) .= 0.0
south_bc = DirichletBC{HalfCell}(1.0)
north_bc = DirichletBC{FullCell}(0.5)
apply_bcs!(Val(2), backend, grid, (field,), ((south_bc, north_bc),); async=false)
@test all((parent(field)[2:nx+1, 1, 2:nz+1] .+ parent(field)[2:nx+1, 2, 2:nz+1]) ./ 2 .≈ south_bc.condition)
@test all(parent(field)[2:nx+1, ny+2, 2:nz+1] .≈ north_bc.condition)
south_bc = FieldBoundaryConditions((field,), (DirichletBC{HalfCell}(1.0),))
north_bc = FieldBoundaryConditions((field,), (DirichletBC{FullCell}(0.5),))
apply_boundary_conditions!(Val(1), Val(2), backend, grid, south_bc; async=false)
apply_boundary_conditions!(Val(2), Val(2), backend, grid, north_bc; async=false)
@test all((field[1:nx, 0, 1:nz] .+ field[1:nx, 1, 1:nz]) ./ 2 .≈ south_bc.conditions[1].condition)
@test all(field[1:nx, ny+1, 1:nz] .≈ north_bc.conditions[1].condition)
end
@testset "z-dim" begin
data(field) .= 0.0
bot_bc = DirichletBC{HalfCell}(1.0)
top_bc = DirichletBC{FullCell}(0.5)
apply_bcs!(Val(3), backend, grid, (field,), ((bot_bc, top_bc),); async=false)
@test all((parent(field)[2:nx+1, 2:ny+1, 1] .+ parent(field)[2:nx+1, 2:ny+1, 2]) ./ 2 .≈ bot_bc.condition)
@test all(parent(field)[2:nx+1, 2:ny+1, nz+2] .≈ top_bc.condition)
bottom_bc = FieldBoundaryConditions((field,), (DirichletBC{HalfCell}(1.0),))
top_bc = FieldBoundaryConditions((field,), (DirichletBC{FullCell}(0.5),))
apply_boundary_conditions!(Val(1), Val(3), backend, grid, bottom_bc; async=false)
apply_boundary_conditions!(Val(2), Val(3), backend, grid, top_bc; async=false)
@test all((field[1:nx, 1:ny, 0] .+ field[1:nx, 1:ny, 1]) ./ 2 .≈ bottom_bc.conditions[1].condition)
@test all(field[1:nx, 1:ny, nz+1] .≈ top_bc.conditions[1].condition)
end
end
@testset "array" begin
Expand All @@ -42,35 +45,38 @@ using FastIce.BoundaryConditions
bc_array_east = KernelAbstractions.allocate(backend, Float64, (size(grid, 2), size(grid, 3)))
bc_array_west .= 1.0
bc_array_east .= 0.5
west_bc = DirichletBC{HalfCell}(bc_array_west)
east_bc = DirichletBC{FullCell}(bc_array_east)
apply_bcs!(Val(1), backend, grid, (field,), ((west_bc, east_bc),); async=false)
@test all((parent(field)[1, 2:ny+1, 2:nz+1] .+ parent(field)[2, 2:ny+1, 2:nz+1]) ./ 2 .≈ west_bc.condition)
@test all(parent(field)[nx+2, 2:ny+1, 2:nz+1] .≈ east_bc.condition)
west_bc = FieldBoundaryConditions((field,), (DirichletBC{HalfCell}(bc_array_west),))
east_bc = FieldBoundaryConditions((field,), (DirichletBC{FullCell}(bc_array_east),))
apply_boundary_conditions!(Val(1), Val(1), backend, grid, west_bc; async=false)
apply_boundary_conditions!(Val(2), Val(1), backend, grid, east_bc; async=false)
@test all((field[0, 1:ny, 1:nz] .+ field[1, 1:ny, 1:nz]) ./ 2 .≈ west_bc.conditions[1].condition)
@test all(field[nx+1, 1:ny, 1:nz] .≈ east_bc.conditions[1].condition)
end
@testset "y-dim" begin
data(field) .= 0.0
bc_array_south = KernelAbstractions.allocate(backend, Float64, (size(grid, 2), size(grid, 3)))
bc_array_north = KernelAbstractions.allocate(backend, Float64, (size(grid, 2), size(grid, 3)))
bc_array_south .= 1.0
bc_array_north .= 0.5
south_bc = DirichletBC{HalfCell}(bc_array_south)
north_bc = DirichletBC{FullCell}(bc_array_north)
apply_bcs!(Val(2), backend, grid, (field,), ((south_bc, north_bc),); async=false)
@test all((parent(field)[2:nx+1, 1, 2:nz+1] .+ parent(field)[2:nx+1, 2, 2:nz+1]) ./ 2 .≈ south_bc.condition)
@test all(parent(field)[2:nx+1, ny+2, 2:nz+1] .≈ north_bc.condition)
south_bc = FieldBoundaryConditions((field,), (DirichletBC{HalfCell}(bc_array_south),))
north_bc = FieldBoundaryConditions((field,), (DirichletBC{FullCell}(bc_array_north),))
apply_boundary_conditions!(Val(1), Val(2), backend, grid, south_bc; async=false)
apply_boundary_conditions!(Val(2), Val(2), backend, grid, north_bc; async=false)
@test all((field[1:nx, 0, 1:nz] .+ field[1:nx, 1, 1:nz]) ./ 2 .≈ south_bc.conditions[1].condition)
@test all(field[1:nx, ny+1, 1:nz] .≈ north_bc.conditions[1].condition)
end
@testset "z-dim" begin
data(field) .= 0.0
bc_array_bot = KernelAbstractions.allocate(backend, Float64, (size(grid, 2), size(grid, 3)))
bc_array_top = KernelAbstractions.allocate(backend, Float64, (size(grid, 2), size(grid, 3)))
bc_array_bot .= 1.0
bc_array_top .= 0.5
bot_bc = DirichletBC{HalfCell}(bc_array_bot)
top_bc = DirichletBC{FullCell}(bc_array_top)
apply_bcs!(Val(3), backend, grid, (field,), ((bot_bc, top_bc),); async=false)
@test all((parent(field)[2:nx+1, 2:ny+1, 1] .+ parent(field)[2:nx+1, 2:ny+1, 2]) ./ 2 .≈ bot_bc.condition)
@test all(parent(field)[2:nx+1, 2:ny+1, nz+2] .≈ top_bc.condition)
bottom_bc = FieldBoundaryConditions((field,), (DirichletBC{HalfCell}(bc_array_bot),))
top_bc = FieldBoundaryConditions((field,), (DirichletBC{FullCell}(bc_array_top),))
apply_boundary_conditions!(Val(1), Val(3), backend, grid, bottom_bc; async=false)
apply_boundary_conditions!(Val(2), Val(3), backend, grid, top_bc; async=false)
@test all((field[1:nx, 1:ny, 0] .+ field[1:nx, 1:ny, 1]) ./ 2 .≈ bottom_bc.conditions[1].condition)
@test all(field[1:nx, 1:ny, nz+1] .≈ top_bc.conditions[1].condition)
end
end
end
Expand Down

0 comments on commit 2a0f9d1

Please sign in to comment.