-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing 3D no-slip boundary condition (#187)
* add missing 3D no_slip * 3D BCs tests * 3D no_slip * docs * format * fix CI * fix no_slip in 3D * remove commented code * remove commented code * remove file * fix 3d velocity interpolation * small bug * format * remove old lines of code * format * fix CI? * format * fix * fix again * format a bit * fix no slip2D
- Loading branch information
1 parent
9e6e0df
commit 0682fc9
Showing
7 changed files
with
208 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Flow boundary conditions | ||
|
||
Supported boundary conditions: | ||
|
||
1. Free slip | ||
|
||
$\frac{\partial u_i}{\partial x_i} = 0$ at the boundary $\Gamma$ | ||
|
||
2. No slip | ||
|
||
$u_i = 0$ at the boundary $\Gamma$ | ||
|
||
3. Free surface | ||
|
||
$\sigma_z = 0 \rightarrow \tau_z = P$ at the top boundary | ||
|
||
## Defining the boundary contions | ||
Information regarding flow boundary conditions is defined in the `FlowBoundaryConditions` object. They can be switched on and off by setting them as `true` or `false` at the appropriate boundaries. Valid boundary names are `left` and `right`, `top` and `bot`, and for the 3D case, `front` and `back`. | ||
|
||
For example, if we want to have free free-slip in every single boundary in a 2D simulation, we need to instantiate `FlowBoundaryConditions` as: | ||
```julia | ||
bcs = FlowBoundaryConditions(; | ||
no_slip = (left=false, right=false, top=false, bot=false), | ||
free_slip = (left=true, right=true, top=true, bot=true), | ||
free_surface = false | ||
) | ||
``` | ||
|
||
The equivalent for the 3D case would be: | ||
```julia | ||
bcs = FlowBoundaryConditions(; | ||
no_slip = (left=false, right=false, top=false, bot=false, front=false, back=false), | ||
free_slip = (left=true, right=true, top=true, bot=true, front=true, back=true), | ||
free_surface = false | ||
) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,54 @@ | ||
@parallel_indices (i) function no_slip!(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 | ||
@views function no_slip!(Ax, Ay, bc) | ||
if bc.left | ||
Ax[1, :] .= 0 | ||
Ay[1, :] .= -Ay[2, :] | ||
end | ||
if bc.right | ||
Ax[end, :] .= 0 | ||
Ay[end, :] .= -Ay[end - 1, :] | ||
end | ||
if bc.bot | ||
Ax[:, 1] .= -Ax[:, 2] | ||
Ay[:, 1] .= 0 | ||
end | ||
if bc.top | ||
Ax[:, end] .= -Ax[:, end - 1] | ||
Ay[:, end] .= 0 | ||
end | ||
end | ||
|
||
@views function no_slip!(Ax, Ay, Az, bc) | ||
if bc.left | ||
Ax[1, :, :] .= 0 | ||
Ay[1, :, :] .= -Ay[2, :, :] | ||
Az[1, :, :] .= -Az[2, :, :] | ||
end | ||
if bc.right | ||
Ax[end, :, :] .= 0 | ||
Ay[end, :, :] .= -Ay[end - 1, :, :] | ||
Az[end, :, :] .= -Az[end - 1, :, :] | ||
end | ||
|
||
if bc.front | ||
Ax[:, 1, :] .= -Ax[:, 2, :] | ||
Ay[:, 1, :] .= 0 | ||
Az[:, 1, :] .= -Az[:, 2, :] | ||
end | ||
|
||
if bc.back | ||
Ax[:, end, :] .= -Ax[:, end - 1, :] | ||
Ay[:, end, :] .= 0 | ||
Az[:, end, :] .= -Az[:, end - 1, :] | ||
end | ||
|
||
if bc.bot | ||
Ax[:, :, 1] .= -Ax[:, :, 2] | ||
Ay[:, :, 1] .= -Ay[:, :, 2] | ||
Az[:, :, 1] .= 0 | ||
end | ||
if bc.top | ||
Ax[:, :, end] .= -Ax[:, :, end - 1] | ||
Ay[:, :, end] .= -Ay[:, :, end - 1] | ||
Az[:, :, end] .= 0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
@static if ENV["JULIA_JUSTRELAX_BACKEND"] === "AMDGPU" | ||
using AMDGPU | ||
elseif ENV["JULIA_JUSTRELAX_BACKEND"] === "CUDA" | ||
using CUDA | ||
end | ||
|
||
using JustRelax, JustRelax.JustRelax3D | ||
using Test | ||
|
||
const backend = @static if ENV["JULIA_JUSTRELAX_BACKEND"] === "AMDGPU" | ||
AMDGPUBackend | ||
elseif ENV["JULIA_JUSTRELAX_BACKEND"] === "CUDA" | ||
CUDABackend | ||
else | ||
CPUBackend | ||
end | ||
|
||
@testset "Boundary Conditions" begin | ||
if backend === CPUBackend | ||
|
||
# test incompatible boundary conditions | ||
@test_throws ErrorException FlowBoundaryConditions(; | ||
no_slip = (left=true, right=true, front=true, back=true, top=true, bot=true), | ||
free_slip = (left=false, right=true, front=true, back=true, top=true, bot=true), | ||
) | ||
|
||
# test with StokesArrays | ||
ni = 5, 5, 5 | ||
stokes = StokesArrays(backend, ni) | ||
stokes.V.Vx .= PTArray(backend)(rand(size(stokes.V.Vx)...)) | ||
stokes.V.Vy .= PTArray(backend)(rand(size(stokes.V.Vy)...)) | ||
stokes.V.Vz .= PTArray(backend)(rand(size(stokes.V.Vz)...)) | ||
|
||
# free-slip | ||
flow_bcs = FlowBoundaryConditions(; | ||
no_slip = (left=false, right=false, front=false, back=false, top=false, bot=false), | ||
free_slip = (left=true, right=true, front=true, back=true, top=true, bot=true), | ||
) | ||
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, :] | ||
|
||
# no-slip | ||
flow_bcs = FlowBoundaryConditions(; | ||
no_slip = (left=true, right=true, front=true, back=true, top=true, bot=true), | ||
free_slip = (left=false, right=false, front=false, back=false, top=false, bot=false), | ||
) | ||
flow_bcs!(stokes, flow_bcs) | ||
|
||
(; Vx, Vy, Vz) = stokes.V | ||
@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,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, :, :] | ||
else | ||
@test true === true | ||
end | ||
end |