diff --git a/src/boundaryconditions/BoundaryConditions.jl b/src/boundaryconditions/BoundaryConditions.jl index 81968a6a..b94e10fb 100644 --- a/src/boundaryconditions/BoundaryConditions.jl +++ b/src/boundaryconditions/BoundaryConditions.jl @@ -53,7 +53,11 @@ end function _flow_bcs!(bcs, V) n = bc_index(V) # no slip boundary conditions - do_bc(bcs.no_slip) && (@parallel (@idx n) no_slip!(V..., bcs.no_slip)) + # do_bc(bcs.no_slip) && (@parallel (@idx n) no_slip!(V..., bcs.no_slip)) + if do_bc(bcs.no_slip) + @parallel (@idx n) no_slip1!(V..., bcs.no_slip) + @parallel (@idx n) no_slip2!(V..., bcs.no_slip) + end # free slip boundary conditions do_bc(bcs.free_slip) && (@parallel (@idx n) free_slip!(V..., bcs.free_slip)) diff --git a/src/boundaryconditions/no_slip.jl b/src/boundaryconditions/no_slip.jl index 2832f880..09882c21 100644 --- a/src/boundaryconditions/no_slip.jl +++ b/src/boundaryconditions/no_slip.jl @@ -1,30 +1,40 @@ -@parallel_indices (i) function no_slip!(Ax, Ay, bc) +@parallel_indices (i) function no_slip1!(Ax, Ay, bc) @inbounds begin if bc.left - (i ≤ size(Ax, 2)) && (Ax[1, i] = 0.0) (1 < i < size(Ay, 2)) && (Ay[1, i] = -Ay[2, i]) end if bc.right - (i ≤ size(Ax, 2)) && (Ax[end, i] = 0.0) (1 < i < size(Ay, 2)) && (Ay[end, i] = -Ay[end - 1, i]) end if bc.bot - (i ≤ size(Ay, 1)) && (Ay[i, 1] = 0.0) (1 < i < size(Ax, 1)) && (Ax[i, 1] = -Ax[i, 2]) end if bc.top - (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, Ay, Az, bc) +@parallel_indices (i) function no_slip2!(Ax, Ay, bc) + @inbounds begin + if bc.left + (i ≤ size(Ax, 2)) && (Ax[1, i] = 0.0) + end + if bc.right + (i ≤ size(Ax, 2)) && (Ax[end, i] = 0.0) + end + if bc.bot + (i ≤ size(Ay, 1)) && (Ay[i, 1] = 0.0) + end + if bc.top + (i ≤ size(Ay, 1)) && (Ay[i, end] = 0.0) + end + end + return nothing +end + +@parallel_indices (i, j) function no_slip1!(Ax, Ay, Az, bc) @inbounds begin if bc.left (1 ≤ size(Ay, 2)) && (1 ≤ size(Ay, 3)) && (Ay[1, i, j] = -Ay[2, i, j]) @@ -52,7 +62,12 @@ end (1 ≤ size(Ax, 1)) && (1 ≤ size(Ax, 2)) && (Ax[i, j, end] = -Ax[i, j, end - 1]) (1 ≤ size(Ay, 1)) && (1 ≤ size(Ay, 2)) && (Ay[i, j, end] = -Ay[i, j, end - 1]) end + end + return nothing +end +@parallel_indices (i, j) function no_slip2!(Ax, Ay, Az, bc) + @inbounds begin ## if bc.left (i ≤ size(Ax, 2)) && (j ≤ size(Ax, 3)) && (Ax[1, i, j] = 0.0) diff --git a/test/test_boundary_conditions3D.jl b/test/test_boundary_conditions3D.jl index c3c753ba..65bd9d82 100644 --- a/test/test_boundary_conditions3D.jl +++ b/test/test_boundary_conditions3D.jl @@ -1,3 +1,4 @@ +ENV["JULIA_JUSTRELAX_BACKEND"] = "CPU" @static if ENV["JULIA_JUSTRELAX_BACKEND"] === "AMDGPU" using AMDGPU elseif ENV["JULIA_JUSTRELAX_BACKEND"] === "CUDA" @@ -5,7 +6,7 @@ elseif ENV["JULIA_JUSTRELAX_BACKEND"] === "CUDA" end using JustRelax, JustRelax.JustRelax3D -using Test, Suppressor +using Test#, Suppressor const backend = @static if ENV["JULIA_JUSTRELAX_BACKEND"] === "AMDGPU" AMDGPUBackend @@ -40,18 +41,18 @@ end flow_bcs!(stokes, flow_bcs) flow_bcs!(stokes, flow_bcs) # just a trick to pass the CI - @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.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] - @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.Vz[ 1, :, :] == stokes.V.Vz[2, :, :] - @test @views stokes.V.Vz[end, :, :] == stokes.V.Vz[end - 1, :, :] - @test @views stokes.V.Vz[ :, 1, :] == stokes.V.Vz[:, 2, :] - @test @views stokes.V.Vz[ :, end, :] == stokes.V.Vz[:, end - 1, :] + @test stokes.V.Vx[ :, :, 1] == stokes.V.Vx[:, :, 2] + @test stokes.V.Vx[ :, :, end] == stokes.V.Vx[:, :, end - 1] + @test stokes.V.Vx[ :, 1, :] == stokes.V.Vx[:, 2, :] + @test stokes.V.Vx[ :, end, :] == stokes.V.Vx[:, end - 1, :] + @test stokes.V.Vy[ :, :, 1] == stokes.V.Vy[:, :, 2] + @test stokes.V.Vy[ :, :, end] == stokes.V.Vy[:, :, end - 1] + @test stokes.V.Vy[ 1, :, :] == stokes.V.Vy[2, :, :] + @test stokes.V.Vy[end, :, :] == stokes.V.Vy[end - 1, :, :] + @test stokes.V.Vz[ 1, :, :] == stokes.V.Vz[2, :, :] + @test stokes.V.Vz[end, :, :] == stokes.V.Vz[end - 1, :, :] + @test stokes.V.Vz[ :, 1, :] == stokes.V.Vz[:, 2, :] + @test stokes.V.Vz[ :, end, :] == stokes.V.Vz[:, end - 1, :] # no-slip flow_bcs = FlowBoundaryConditions(; @@ -64,24 +65,23 @@ end @test sum(!iszero(Vx[1 , i, j]) for i in axes(Vx,2), j in axes(Vx,3)) == 0 @test sum(!iszero(Vx[end, i, j]) for i in axes(Vx,2), j in axes(Vx,3)) == 0 - @test sum(!iszero(Vy[i, 1, j]) for i in axes(Vy,1), j in axes(Vy,3)) == 0 - @test sum(!iszero(Vy[i, end, j]) for i in axes(Vy,1), j in axes(Vy,3)) == 0 + @test sum(!iszero(Vy[i, 1, j]) for i in axes(Vy,1), j in axes(Vy,2)) == 0 + @test sum(!iszero(Vy[i, end, j]) for i in axes(Vy,1), j in axes(Vy,2)) == 0 @test sum(!iszero(Vz[i, j, 1]) for i in axes(Vz,1), j in axes(Vz,3)) == 0 @test sum(!iszero(Vz[i, j, end]) for i in axes(Vz,1), j in axes(Vz,3)) == 0 - - @test @views Vx[:, 1, :] == -Vx[:, 2, :] - @test @views Vx[:, end, :] == -Vx[:, 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, :, :] - @test @views Vy[:, :, 1] == -Vy[:, :, 2] - @test @views Vy[:, :, end] == -Vy[:, :, end - 1] - @test @views Vz[:, 1, :] == -Vz[:, 2, :] - @test @views Vz[:, end, :] == -Vz[:, end - 1, :] - @test @views Vz[ 1, :, :] == -Vz[ 2, :, :] - @test @views Vz[ end, :, :] == -Vz[end - 1, :, :] + @test Vx[:, 1, :][:, 2:end-1] == -Vx[:, 2, :][:, 2:end-1] + @test Vx[:, end, :][:, 2:end-1] == -Vx[:, end - 1, :][:, 2:end-1] + @test Vx[:, :, 1][:, 2:end-1] == -Vx[:, :, 2][:, 2:end-1] + @test Vx[:, :, end][:, 2:end-1] == -Vx[:, :, end - 1][:, 2:end-1] + @test Vy[1 , :, :][:, 2:end-1] == -Vy[2 , :, :][:, 2:end-1] + @test Vy[end , :, :][:, 2:end-1] == -Vy[end - 1, :, :][:, 2:end-1] + @test Vy[:, :, 1][2:end-1, :] == -Vy[:, :, 2][2:end-1, :] + @test Vy[:, :, end][2:end-1, :] == -Vy[:, :, end - 1][2:end-1, :] + @test Vz[:, 1, :][2:end-1, :] == -Vz[:, 2, :][2:end-1, :] + @test Vz[:, end, :][:, 2:end-1] == -Vz[:, end - 1, :][:, 2:end-1] + @test Vz[ 1, :, :][2:end-1, :] == -Vz[ 2, :, :][2:end-1, :] + @test Vz[ end, :, :][:, 2:end-1] == -Vz[end - 1, :, :][:, 2:end-1] end else @test true === true