Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve free surface stabilization
Browse files Browse the repository at this point in the history
albert-de-montserrat committed Jul 5, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 0682fc9 commit 53131bf
Showing 4 changed files with 104 additions and 36 deletions.
11 changes: 9 additions & 2 deletions src/Interpolations.jl
Original file line number Diff line number Diff line change
@@ -6,14 +6,21 @@ Interpolates the values of `Vx` onto the grid points of `Vy`.
# Arguments
- `Vx_on_Vy::AbstractArray`: `Vx` at `Vy` grid points.
- `Vx::AbstractArray`: `Vx` at its staggered grid points.
"""
@parallel_indices (i, j) function interp_Vx_on_Vy!(Vx_on_Vy, Vx)
Vx_on_Vy[i + 1, j] = 0.25 * (Vx[i, j] + Vx[i + 1, j] + Vx[i, j + 1] + Vx[i + 1, j + 1])
return nothing
end

@parallel_indices (i, j) function interp_Vx∂ρ∂x_on_Vy!(Vx_on_Vy, Vx, ρg, _dx)
nx, ny = size(ρg)
ii = clamp(i, 1, nx)
ii1 = clamp(i+1, 1, nx)
jj = clamp(j, 1, ny)
Vx_on_Vy[i + 1, j] = (0.25 * (Vx[i, j] + Vx[i + 1, j] + Vx[i, j + 1] + Vx[i + 1, j + 1])) * (ρg[ii1, jj] - ρg[ii, jj]) * _dx
return nothing
end

# From cell vertices to cell center

temperature2center!(thermal) = temperature2center!(backend(thermal), thermal)
16 changes: 16 additions & 0 deletions src/boundaryconditions/no_slip.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
@views function no_slip!(Ax, Ay, bc)
if bc.left
Ax[1, :] .= 0
Ay[2, :] .= Ay[3, :] / 3
Ay[1, :] .= -Ay[2, :]
end
if bc.right
Ax[end, :] .= 0
Ay[end-1, :] .= Ay[end-2, :] / 3
Ay[end, :] .= -Ay[end - 1, :]
end
if bc.bot
Ax[:, 2] .= Ax[:, 3] / 3
Ax[:, 1] .= -Ax[:, 2]
Ay[:, 1] .= 0
end
if bc.top
Ax[:, end-1] .= Ax[:, end - 2] / 3
Ax[:, end] .= -Ax[:, end - 1]
Ay[:, end] .= 0
end
@@ -20,34 +24,46 @@ end
@views function no_slip!(Ax, Ay, Az, bc)
if bc.left
Ax[1, :, :] .= 0
Ay[2, :, :] .= Ay[3, :, :] / 3
Ay[1, :, :] .= -Ay[2, :, :]
Az[2, :, :] .= Az[3, :, :] / 3
Az[1, :, :] .= -Az[2, :, :]
end
if bc.right
Ax[end, :, :] .= 0
Ay[end-1, :, :] .= Ay[end - 2, :, :] / 3
Ay[end, :, :] .= -Ay[end - 1, :, :]
Az[end-1, :, :] .= Az[end - 2, :, :] / 3
Az[end, :, :] .= -Az[end - 1, :, :]
end

if bc.front
Ax[:, 2, :] .= -Ax[:, 3, :] / 3
Ax[:, 1, :] .= -Ax[:, 2, :]
Ay[:, 1, :] .= 0
Az[:, 2, :] .= -Az[:, 3, :] / 3
Az[:, 1, :] .= -Az[:, 2, :]
end

if bc.back
Ax[:, end-2, :] .= -Ax[:, end - 2, :] / 3
Ax[:, end, :] .= -Ax[:, end - 1, :]
Ay[:, end, :] .= 0
Az[:, end-2, :] .= -Az[:, end - 2, :] / 3
Az[:, end, :] .= -Az[:, end - 1, :]
end

if bc.bot
Ax[:, :, 1] .= -Ax[:, :, 3] / 3
Ax[:, :, 1] .= -Ax[:, :, 2]
Ay[:, :, 1] .= -Ay[:, :, 3] / 3
Ay[:, :, 1] .= -Ay[:, :, 2]
Az[:, :, 1] .= 0
end
if bc.top
Ax[:, :, end-1] .= -Ax[:, :, end - 2] / 3
Ax[:, :, end] .= -Ax[:, :, end - 1]
Ay[:, :, end-1] .= -Ay[:, :, end - 2] / 3
Ay[:, :, end] .= -Ay[:, :, end - 1]
Az[:, :, end] .= 0
end
16 changes: 10 additions & 6 deletions src/stokes/Stokes2D.jl
Original file line number Diff line number Diff line change
@@ -578,10 +578,14 @@ function _solve!(
args,
)
center2vertex!(stokes.τ.xy, stokes.τ.xy_c)
update_halo!(stokes.τ.xy)
# update_halo!(stokes.τ.xy)

@parallel (1:(size(stokes.V.Vy, 1) - 2), 1:size(stokes.V.Vy, 2)) interp_Vx_on_Vy!(
Vx_on_Vy, stokes.V.Vx
# @parallel (1:(size(stokes.V.Vy, 1) - 2), 1:size(stokes.V.Vy, 2)) interp_Vx_on_Vy!(
# Vx_on_Vy, stokes.V.Vx
# )

@parallel (1:(size(stokes.V.Vy, 1) - 2), 1:size(stokes.V.Vy, 2)) interp_Vx∂ρ∂x_on_Vy!(
Vx_on_Vy, stokes.V.Vx, ρg[2], _di[1]
)

@hide_communication b_width begin # communication/computation overlap
@@ -599,7 +603,7 @@ function _solve!(
# apply boundary conditions
free_surface_bcs!(stokes, flow_bcs, η, rheology, phase_ratios, dt, di)
flow_bcs!(stokes, flow_bcs)
update_halo!(@velocity(stokes)...)
# update_halo!(@velocity(stokes)...)
end
end

@@ -621,8 +625,8 @@ function _solve!(
)
# errs = maximum_mpi.((abs.(stokes.R.Rx), abs.(stokes.R.Ry), abs.(stokes.R.RP)))
errs = (
norm_mpi(stokes.R.Rx) / length(stokes.R.Rx),
norm_mpi(stokes.R.Ry) / length(stokes.R.Ry),
norm_mpi(@views stokes.R.Rx[2:end-1, 2:end-1]) / length(stokes.R.Rx),
norm_mpi(@views stokes.R.Ry[2:end-1, 2:end-1]) / length(stokes.R.Ry),
norm_mpi(stokes.R.RP) / length(stokes.R.RP),
)
push!(norm_Rx, errs[1])
97 changes: 69 additions & 28 deletions src/stokes/VelocityKernels.jl
Original file line number Diff line number Diff line change
@@ -134,30 +134,56 @@ end
end

if all((i, j) .< size(Vy) .- 1)
# θ = 1.0
# # Interpolate Vx into Vy node
# Vxᵢⱼ = Vx_on_Vy[i + 1, j + 1]
# # Vertical velocity
# Vyᵢⱼ = Vy[i + 1, j + 1]
# # Get necessary buoyancy forces
# i_W, i_E = max(i - 1, 1), min(i + 1, nx)
# j_N = min(j + 1, ny)
# ρg_stencil = (
# ρgy[i_W, j], ρgy[i, j], ρgy[i_E, j], ρgy[i_W, j_N], ρgy[i, j_N], ρgy[i_E, j_N]
# )
# ρg_W = (ρg_stencil[1] + ρg_stencil[2] + ρg_stencil[4] + ρg_stencil[5]) * 0.25
# ρg_E = (ρg_stencil[2] + ρg_stencil[3] + ρg_stencil[5] + ρg_stencil[6]) * 0.25
# ρg_S = ρg_stencil[2]
# ρg_N = ρg_stencil[5]
# # Spatial derivatives
# ∂ρg∂x = (ρg_E - ρg_W) * _dx
# ∂ρg∂y = (ρg_N - ρg_S) * _dy
# # correction term
# ρg_correction = (Vxᵢⱼ * ∂ρg∂x + Vyᵢⱼ * ∂ρg∂y) * θ * dt

# Vy[i + 1, j + 1] +=
# (-d_ya(P) + d_ya(τyy) + d_xi(τxy) - av_ya(ρgy) - ρg_correction) * ηdτ /
# av_ya(ητ)

θ = 1.0
# Interpolate Vx into Vy node
# Interpolated Vx into Vy node (includes density gradient)
Vxᵢⱼ = Vx_on_Vy[i + 1, j + 1]
# Vertical velocity
Vyᵢⱼ = Vy[i + 1, j + 1]
# Get necessary buoyancy forces
i_W, i_E = max(i - 1, 1), min(i + 1, nx)
# i_W, i_E = max(i - 1, 1), min(i + 1, nx)
j_N = min(j + 1, ny)
ρg_stencil = (
ρgy[i_W, j], ρgy[i, j], ρgy[i_E, j], ρgy[i_W, j_N], ρgy[i, j_N], ρgy[i_E, j_N]
)
ρg_W = (ρg_stencil[1] + ρg_stencil[2] + ρg_stencil[4] + ρg_stencil[5]) * 0.25
ρg_E = (ρg_stencil[2] + ρg_stencil[3] + ρg_stencil[5] + ρg_stencil[6]) * 0.25
ρg_S = ρg_stencil[2]
ρg_N = ρg_stencil[5]
# ρg_stencil = (
# ρgy[i_W, j], ρgy[i, j], ρgy[i_E, j], ρgy[i_W, j_N], ρgy[i, j_N], ρgy[i_E, j_N]
# )
# ρg_W = (ρg_stencil[1] + ρg_stencil[2] + ρg_stencil[4] + ρg_stencil[5]) * 0.25
# ρg_E = (ρg_stencil[2] + ρg_stencil[3] + ρg_stencil[5] + ρg_stencil[6]) * 0.25
ρg_S = ρgy[i, j]
ρg_N = ρgy[i, j_N]
# Spatial derivatives
∂ρg∂x = (ρg_E - ρg_W) * _dx
# ∂ρg∂x = (ρg_E - ρg_W) * _dx
∂ρg∂y = (ρg_N - ρg_S) * _dy
# correction term
ρg_correction = (Vxᵢⱼ * ∂ρg∂x + Vyᵢⱼ * ∂ρg∂y) * θ * dt
ρg_correction = (Vxᵢⱼ + Vyᵢⱼ * ∂ρg∂y) * θ * dt

Vy[i + 1, j + 1] +=
(-d_ya(P) + d_ya(τyy) + d_xi(τxy) - av_ya(ρgy) + ρg_correction) * ηdτ /
av_ya(ητ)

end

return nothing
@@ -265,33 +291,48 @@ end
Rx[i, j] = d_xa(τxx) + d_yi(τxy) - d_xa(P) - av_xa(ρgx)
end
if all((i, j) .≤ size(Ry))
# θ = 1.0
# Vxᵢⱼ = Vx_on_Vy[i + 1, j + 1]
# # Vertical velocity
# Vyᵢⱼ = Vy[i + 1, j + 1]
# # Get necessary buoyancy forces
# i_W, i_E = max(i - 1, 1), min(i + 1, nx)
# j_N = min(j + 1, ny)
# ρg_stencil = (
# ρgy[i_W, j],
# ρgy[i, j],
# ρgy[i_E, j],
# ρgy[i_W, j_N],
# ρgy[i, j_N],
# ρgy[i_E, j_N],
# )
# ρg_W = (ρg_stencil[1] + ρg_stencil[2] + ρg_stencil[4] + ρg_stencil[5]) * 0.25
# ρg_E = (ρg_stencil[2] + ρg_stencil[3] + ρg_stencil[5] + ρg_stencil[6]) * 0.25
# ρg_S = ρg_stencil[2]
# ρg_N = ρg_stencil[5]
# # Spatial derivatives
# ∂ρg∂x = (ρg_E - ρg_W) * _dx
# ∂ρg∂y = (ρg_N - ρg_S) * _dy
# # correction term
# ρg_correction = (Vxᵢⱼ * ∂ρg∂x + Vyᵢⱼ * ∂ρg∂y) * θ * dt
# Ry[i, j] = d_ya(τyy) + d_xi(τxy) - d_ya(P) - av_ya(ρgy) + ρg_correction
# # Ry[i, j] = d_ya(τyy) + d_xi(τxy) - d_ya(P) - av_ya(ρgy)

θ = 1.0
# 0.25 * (Vx[i, j + 1] + Vx[i + 1, j + 1] + Vx[i, j + 2] + Vx[i + 1, j + 2])
# Interpolated Vx into Vy node (includes density gradient)
Vxᵢⱼ = Vx_on_Vy[i + 1, j + 1]
# Vertical velocity
Vyᵢⱼ = Vy[i + 1, j + 1]
# Get necessary buoyancy forces
i_W, i_E = max(i - 1, 1), min(i + 1, nx)
j_N = min(j + 1, ny)
ρg_stencil = (
ρgy[i_W, j],
ρgy[i, j],
ρgy[i_E, j],
ρgy[i_W, j_N],
ρgy[i, j_N],
ρgy[i_E, j_N],
)
ρg_W = (ρg_stencil[1] + ρg_stencil[2] + ρg_stencil[4] + ρg_stencil[5]) * 0.25
ρg_E = (ρg_stencil[2] + ρg_stencil[3] + ρg_stencil[5] + ρg_stencil[6]) * 0.25
ρg_S = ρg_stencil[2]
ρg_N = ρg_stencil[5]
ρg_S = ρgy[i, j]
ρg_N = ρgy[i, j_N]
# Spatial derivatives
∂ρg∂x = (ρg_E - ρg_W) * _dx
∂ρg∂y = (ρg_N - ρg_S) * _dy
# correction term
ρg_correction = (Vxᵢⱼ * ∂ρg∂x + Vyᵢⱼ * ∂ρg∂y) * θ * dt
ρg_correction = (Vxᵢⱼ + Vyᵢⱼ * ∂ρg∂y) * θ * dt

Ry[i, j] = d_ya(τyy) + d_xi(τxy) - d_ya(P) - av_ya(ρgy) + ρg_correction
# Ry[i, j] = d_ya(τyy) + d_xi(τxy) - d_ya(P) - av_ya(ρgy)
end
end

0 comments on commit 53131bf

Please sign in to comment.