Skip to content

Commit

Permalink
fix merge weird conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
albert-de-montserrat committed Mar 25, 2024
1 parent 84ae48d commit 7ad0927
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 109 deletions.
28 changes: 1 addition & 27 deletions src/boundaryconditions/BoundaryConditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ end

# BOUNDARY CONDITIONS KERNELS

@parallel_indices (i) function no_slip!(Ax::T, Ay::T, bc) where {T}
@parallel_indices (i) function no_slip!(Ax, Ay, bc)
@inbounds begin
if bc.left
(i size(Ax, 2)) && (Ax[1, i] = 0.0)
Expand All @@ -115,32 +115,6 @@ end
return nothing
end

@parallel_indices (i, j) function no_slip!(Ax::T, Ay::T, Az::T, bc) where {T}
@inbounds begin
if bc.bot
(i size(Ax, 1)) && (j size(Ax, 2)) && (Ax[i, j, 1] = -Ax[i, j, 2])
(i size(Ay, 1)) && (j size(Ay, 2)) && (Ay[i, j, 1] = -Ay[i, j, 2])
end
if bc.top
(i size(Ax, 1)) && (j size(Ax, 2)) && (Ax[i, j, end] = -Ax[i, j, end - 1])
(i size(Ay, 1)) && (j size(Ay, 2)) && (Ay[i, j, end] = -Ay[i, j, end - 1])
end
if bc.left
(i size(Ay, 1)) && (Ay[i, 1] = 0.0)
(1 < i < size(Ax, 1)) && (Ax[i, 1] = -Ax[i, 2])
end
if bc.right
(i size(Ay, 1)) && (Ay[i, end] = 0.0)
(1 < i < size(Ax, 1)) && (Ax[i, end] = -Ax[i, end - 1])
end
# corners
# bc.bot && (Ax[1, 1] = 0.0; Ax[1, 1] = 0.0)
# bc.left && bc.bot && (Ax[1, 1] = 0.0)
# bc.right && bc.top && (Ay[end, end] = 0.0)
end
return nothing
end

@parallel_indices (i, j) function no_slip!(Ax::T, Ay::T, Az::T, bc) where {T}
@inbounds begin
if bc.bot
Expand Down
166 changes: 84 additions & 82 deletions test/test_boundary_conditions2D.jl
Original file line number Diff line number Diff line change
@@ -1,101 +1,103 @@
using Test, Suppressor
using Test
using JustRelax

model = PS_Setup(:cpu, Float64, 2)
environment!(model)

@testset "Flow boundary conditions 2D" begin
# periodicity
n = 5 # number of elements
Vx, Vy = PTArray(rand(n + 1, n + 2)), PTArray(rand(n + 2, n + 1))
bcs = FlowBoundaryConditions(;
no_slip=(left=false, right=false, top=false, bot=false),
free_slip=(left=false, right=false, top=false, bot=false),
periodicity=(left=true, right=true, top=true, bot=true),
)
flow_bcs!(bcs, Vx, Vy)

@test @views Vx[: , 1] == Vx[: , end - 1]
@test @views Vx[: , end] == Vx[: , 2]
@test @views Vy[1 , :] == Vy[end - 1, :]
@test @views Vy[end, :] == Vy[2 , :]
n = 5 # number of elements
Vx, Vy = PTArray(rand(n + 1, n + 2)), PTArray(rand(n + 2, n + 1))

# free-slip
bcs = FlowBoundaryConditions(;
no_slip=(left=false, right=false, top=false, bot=false),
free_slip=(left=true, right=true, top=true, bot=true),
periodicity=(left=false, right=false, top=false, bot=false),
)
flow_bcs!(bcs, Vx, Vy)

# free-slip
bcs = FlowBoundaryConditions(;
no_slip=(left=false, right=false, top=false, bot=false),
free_slip=(left=true, right=true, top=true, bot=true),
periodicity=(left=false, right=false, top=false, bot=false),
)
flow_bcs!(bcs, Vx, Vy)
@test @views Vx[:, 1] == Vx[:, 2]
@test @views Vx[:, end] == Vx[:, end - 1]
@test @views Vy[1, :] == Vy[2, :]
@test @views Vy[end, :] == Vy[end - 1, :]

@test @views Vx[:, 1] == Vx[:, 2]
@test @views Vx[:, end] == Vx[:, end - 1]
@test @views Vy[1, :] == Vy[2, :]
@test @views Vy[end, :] == Vy[end - 1, :]
# no-slip
Vx, Vy = PTArray(rand(n + 1, n + 2)), PTArray(rand(n + 2, n + 1))
bcs = FlowBoundaryConditions(;
no_slip=(left=true, right=true, top=true, bot=true),
free_slip=(left=false, right=false, top=false, bot=false),
periodicity=(left=false, right=false, top=false, bot=false),
)
flow_bcs!(bcs, Vx, Vy)
@test sum(!iszero(Vx[1 , i]) for i in axes(Vx,2)) == 0
@test sum(!iszero(Vx[end, i]) for i in axes(Vx,2)) == 0
@test sum(!iszero(Vy[i, 1]) for i in axes(Vy,1)) == 0
@test sum(!iszero(Vy[i, 1]) for i in axes(Vy,1)) == 0
@test @views Vy[1 , :] == -Vy[2 , :]
@test @views Vy[end, :] == -Vy[end - 1, :]
@test @views Vx[: , 1] == -Vx[: , 2]
@test @views Vx[: , end] == -Vx[: , end - 1]

# no-slip
Vx, Vy = PTArray(rand(n + 1, n + 2)), PTArray(rand(n + 2, n + 1))
bcs = FlowBoundaryConditions(;
no_slip=(left=true, right=true, top=true, bot=true),
free_slip=(left=false, right=false, top=false, bot=false),
periodicity=(left=false, right=false, top=false, bot=false),
)
flow_bcs!(bcs, Vx, Vy)
@test sum(!iszero(Vx[1 , i]) for i in axes(Vx,2)) == 0
@test sum(!iszero(Vx[end, i]) for i in axes(Vx,2)) == 0
@test sum(!iszero(Vy[i, 1]) for i in axes(Vy,1)) == 0
@test sum(!iszero(Vy[i, 1]) for i in axes(Vy,1)) == 0
@test @views Vy[1 , :] == -Vy[2 , :]
@test @views Vy[end, :] == -Vy[end - 1, :]
@test @views Vx[: , 1] == -Vx[: , 2]
@test @views Vx[: , end] == -Vx[: , end - 1]

# test with StokesArrays
# periodicity
ni = 5, 5
stokes = StokesArrays(ni, ViscoElastic)
stokes.V.Vx .= PTArray(rand(n + 1, n + 2))
stokes.V.Vy .= PTArray(rand(n + 2, n + 1))
flow_bcs = FlowBoundaryConditions(;
no_slip=(left=false, right=false, top=false, bot=false),
free_slip=(left=false, right=false, top=false, bot=false),
periodicity=(left=true, right=true, top=true, bot=true),
)
flow_bcs!(stokes, flow_bcs)
# test with StokesArrays
# periodicity
ni = 5, 5
stokes = StokesArrays(ni, ViscoElastic)
stokes.V.Vx .= PTArray(rand(n + 1, n + 2))
stokes.V.Vy .= PTArray(rand(n + 2, n + 1))
flow_bcs = FlowBoundaryConditions(;
no_slip=(left=false, right=false, top=false, bot=false),
free_slip=(left=false, right=false, top=false, bot=false),
periodicity=(left=true, right=true, top=true, bot=true),
)
flow_bcs!(stokes, flow_bcs)

@test @views stokes.V.Vx[:, 1] == stokes.V.Vx[:, end - 1]
@test @views stokes.V.Vx[:, end] == stokes.V.Vx[:, 2]
@test @views stokes.V.Vy[1, :] == stokes.V.Vy[end - 1, :]
@test @views stokes.V.Vy[end, :] == stokes.V.Vy[2, :]
@test @views stokes.V.Vx[:, 1] == stokes.V.Vx[:, end - 1]
@test @views stokes.V.Vx[:, end] == stokes.V.Vx[:, 2]
@test @views stokes.V.Vy[1, :] == stokes.V.Vy[end - 1, :]
@test @views stokes.V.Vy[end, :] == stokes.V.Vy[2, :]

# free-slip
flow_bcs = FlowBoundaryConditions(;
no_slip=(left=false, right=false, top=false, bot=false),
free_slip=(left=true, right=true, top=true, bot=true),
periodicity=(left=false, right=false, top=false, bot=false),
)
flow_bcs!(stokes, flow_bcs)
# free-slip
flow_bcs = FlowBoundaryConditions(;
no_slip=(left=false, right=false, top=false, bot=false),
free_slip=(left=true, right=true, top=true, bot=true),
periodicity=(left=false, right=false, top=false, bot=false),
)
flow_bcs!(stokes, flow_bcs)

@test @views stokes.V.Vx[ :, 1] == stokes.V.Vx[ :, 2]
@test @views stokes.V.Vx[ :, end] == stokes.V.Vx[ :, end - 1]
@test @views stokes.V.Vy[ 1, :] == stokes.V.Vy[ 2, :]
@test @views stokes.V.Vy[end, :] == stokes.V.Vy[end - 1, :]

# no-slip
flow_bcs = FlowBoundaryConditions(;
no_slip=(left=true, right=true, top=true, bot=true),
free_slip=(left=false, right=false, top=false, bot=false),
periodicity=(left=false, right=false, top=false, bot=false),
)
flow_bcs!(stokes, flow_bcs)
# no-slip
flow_bcs = FlowBoundaryConditions(;
no_slip=(left=true, right=true, top=true, bot=true),
free_slip=(left=false, right=false, top=false, bot=false),
periodicity=(left=false, right=false, top=false, bot=false),
)
flow_bcs!(stokes, flow_bcs)

@test sum(!iszero(stokes.V.Vx[1 , i]) for i in axes(Vx,2)) == 0
@test sum(!iszero(stokes.V.Vx[end, i]) for i in axes(Vx,2)) == 0
@test sum(!iszero(stokes.V.Vy[i, 1]) for i in axes(Vy,1)) == 0
@test sum(!iszero(stokes.V.Vy[i, 1]) for i in axes(Vy,1)) == 0
@test @views stokes.V.Vy[1 , :] == -stokes.V.Vy[2 , :]
@test @views stokes.V.Vy[end, :] == -stokes.V.Vy[end - 1, :]
@test @views stokes.V.Vx[: , 1] == -stokes.V.Vx[: , 2]
@test @views stokes.V.Vx[: , end] == -stokes.V.Vx[: , end - 1]
end

@testset "Temperature boundary conditions 2D" begin
ni = 5, 5 # number of elements
thermal = ThermalArrays(ni)
# free-slip
bcs = TemperatureBoundaryConditions(;
no_flux = (left = true, right = true, top = true, bot = true),
)
thermal_bcs!(thermal, bcs)

@test sum(!iszero(stokes.V.Vx[1 , i]) for i in axes(Vx,2)) == 0
@test sum(!iszero(stokes.V.Vx[end, i]) for i in axes(Vx,2)) == 0
@test sum(!iszero(stokes.V.Vy[i, 1]) for i in axes(Vy,1)) == 0
@test sum(!iszero(stokes.V.Vy[i, 1]) for i in axes(Vy,1)) == 0
@test @views stokes.V.Vy[1 , :] == -stokes.V.Vy[2 , :]
@test @views stokes.V.Vy[end, :] == -stokes.V.Vy[end - 1, :]
@test @views stokes.V.Vx[: , 1] == -stokes.V.Vx[: , 2]
@test @views stokes.V.Vx[: , end] == -stokes.V.Vx[: , end - 1]
end
@test @views thermal.T[ :, 1] == thermal.T[ :, 2]
@test @views thermal.T[ :, end] == thermal.T[ :, end - 1]
@test @views thermal.T[ 1, :] == thermal.T[ 2, :]
@test @views thermal.T[end, :] == thermal.T[end - 1, :]
end

0 comments on commit 7ad0927

Please sign in to comment.