Skip to content

Commit

Permalink
remove P gradient
Browse files Browse the repository at this point in the history
  • Loading branch information
albert-de-montserrat committed Apr 24, 2024
1 parent 69b3709 commit 10907b2
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 69 deletions.
35 changes: 17 additions & 18 deletions src/stokes/Stokes2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,16 @@ function JustRelax.solve!(
Aij .= 0.0
end
Vx_on_Vy = @zeros(size(stokes.V.Vy))


ρg_bg = 2700 * 9.81
Plitho = reverse(cumsum(reverse((ρg[2] .+ ρg_bg) .* di[2], dims=2), dims=2), dims=2)
args.P .= stokes.P .+ Plitho .- minimum(stokes.P)

while iter iterMax
iterMin < iter && err < ϵ && break

wtime0 += @elapsed begin
compute_maxloc!(ητ, η; window=(1, 1))
# compute_maxloc!(ητ, η_vep; window=(1, 1))
update_halo!(ητ)

@parallel (@idx ni) compute_∇V!(stokes.∇V, @velocity(stokes)..., _di...)
Expand All @@ -583,11 +586,12 @@ function JustRelax.solve!(
if rem(iter, 5) == 0
@parallel (@idx ni) compute_ρg!(ρg[2], phase_ratios.center, rheology, args)
end
# args.P .= reverse(cumsum(reverse(ρg[2] .+ ρg_bg, dims=2), dims=2), dims=2)

@parallel (@idx ni .+ 1) compute_strain_rate!(
@strain(stokes)..., stokes.∇V, @velocity(stokes)..., _di...
)

if rem(iter, nout) == 0
@copy η0 η
end
Expand All @@ -609,7 +613,8 @@ function JustRelax.solve!(
@strain(stokes),
@tensor_center(stokes.ε_pl),
stokes.EII_pl,
stokes.P,
args.P,
# stokes.P,
θ,
η,
η_vep,
Expand All @@ -619,6 +624,7 @@ function JustRelax.solve!(
dt,
θ_dτ,
)
# θ .-= args.P
free_surface_bcs!(stokes, flow_bcs)

@parallel center2vertex!(stokes.τ.xy, stokes.τ.xy_c)
Expand All @@ -629,25 +635,17 @@ function JustRelax.solve!(
)

@hide_communication b_width begin # communication/computation overlap
# @parallel compute_V!(
# @velocity(stokes)...,
# Vx_on_Vy,
# θ,
# @stress(stokes)...,
# pt_stokes.ηdτ,
# ρg...,
# ητ,
# _di...,
# dt * free_surface,
# )
@parallel compute_V!(
@velocity(stokes)...,
Vx_on_Vy,
stokes.P,
@stress(stokes)...,
pt_stokes.ηdτ,
ρg...,
ρg[1],
ρg[2],
ητ,
_di...,
dt * free_surface,
)
# apply boundary conditions
free_surface_bcs!(stokes, flow_bcs, η, rheology, phase_ratios, dt, di)
Expand All @@ -668,7 +666,8 @@ function JustRelax.solve!(
Vx_on_Vy,
stokes.P,
@stress(stokes)...,
ρg...,
ρg[1],
ρg[2],
_di...,
dt * free_surface,
)
Expand Down Expand Up @@ -703,7 +702,7 @@ function JustRelax.solve!(
end
end

stokes.P .= θ
# stokes.P .= θ
# @views stokes.P .-= stokes.P[:, end]

# accumulate plastic strain tensor
Expand Down
69 changes: 40 additions & 29 deletions subduction/LAMEM2D.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# using CUDA
using CUDA
using JustRelax, JustRelax.DataIO
import JustRelax.@cell
using ParallelStencil
@init_parallel_stencil(Threads, Float64, 2)
# @init_parallel_stencil(CUDA, Float64, 2)
# @init_parallel_stencil(Threads, Float64, 2)
@init_parallel_stencil(CUDA, Float64, 2)

using JustPIC
using JustPIC._2D
# Threads is the default backend,
# to run on a CUDA GPU load CUDA.jl (i.e. "using CUDA") at the beginning of the script,
# and to run on an AMD GPU load AMDGPU.jl (i.e. "using AMDGPU") at the beginning of the script.
const backend = CPUBackend # Options: CPUBackend, CUDABackend, AMDGPUBackend
# const backend = CUDABackend # Options: CPUBackend, CUDABackend, AMDGPUBackend
# const backend = CPUBackend # Options: CPUBackend, CUDABackend, AMDGPUBackend
const backend = CUDABackend # Options: CPUBackend, CUDABackend, AMDGPUBackend

# setup ParallelStencil.jl environment
model = PS_Setup(:cpu, Float64, 2) # or (:CUDA, Float64, 3) or (:AMDGPU, Float64, 3)
# model = PS_Setup(:CUDA, Float64, 2) # or (:CUDA, Float64, 3) or (:AMDGPU, Float64, 3)
# model = PS_Setup(:cpu, Float64, 2) # or (:CUDA, Float64, 3) or (:AMDGPU, Float64, 3)
model = PS_Setup(:CUDA, Float64, 2) # or (:CUDA, Float64, 3) or (:AMDGPU, Float64, 3)
environment!(model)

# Load script dependencies
Expand All @@ -42,12 +42,12 @@ function copyinn_x!(A, B)
@parallel f_x(A, B)
end


# Initial pressure profile - not accurate
@parallel function init_P!(P, ρg, z)
@all(P) = abs(@all(ρg) * @all_k(z)) * <(@all_k(z), 0.0)
return nothing
end

## END OF HELPER FUNCTION ------------------------------------------------------------

## BEGIN OF MAIN SCRIPT --------------------------------------------------------------
Expand Down Expand Up @@ -89,7 +89,7 @@ function main(li, origin, phases_GMG, igg; nx=16, ny=16, figdir="figs2D", do_vtk
# STOKES ---------------------------------------------
# Allocate arrays needed for every Stokes problem
stokes = StokesArrays(ni, ViscoElastic)
pt_stokes = PTStokesCoeffs(li, di; ϵ=1e-4, CFL = 0.99 / 2.1)
pt_stokes = PTStokesCoeffs(li, di; ϵ=1e-4, Re=3π, r=1e0, CFL = 1 / 2.1) # Re=3π, r=0.7
# ----------------------------------------------------

# TEMPERATURE PROFILE --------------------------------
Expand All @@ -108,22 +108,29 @@ function main(li, origin, phases_GMG, igg; nx=16, ny=16, figdir="figs2D", do_vtk

# Buoyancy forces
ρg = ntuple(_ -> @zeros(ni...), Val(2))
for _ in 1:2
compute_ρg!(ρg[2], phase_ratios, rheology, (T=thermal.Tc, P=stokes.P))
JustRelax.Stokes2D.init_P!(stokes.P, ρg[2], xci[2])
end
# for _ in 1:2
# compute_ρg!(ρg[2], phase_ratios, rheology, (T=thermal.Tc, P=stokes.P))
# JustRelax.Stokes2D.init_P!(stokes.P, ρg[2], xci[2])
# end
compute_ρg!(ρg[2], phase_ratios, rheology, (T=thermal.Tc, P=stokes.P))
# Plitho = reverse(cumsum(reverse(ρg[2] .+ (2700*9.81), dims=2), dims=2), dims=2)

ρg_bg = 2700 * 9.81
# args.P .= reverse(cumsum(reverse(ρg[2] .+ ρg_bg, dims=2), dims=2), dims=2)
Plitho = reverse(cumsum(reverse((ρg[2] .+ ρg_bg).* di[2], dims=2), dims=2), dims=2)
# args.P = stokes.P .+ Plitho .- minimum(stokes.P)

# Rheology
η = @ones(ni...)
η_vep = similar(η)
args = (; T = thermal.Tc, P = stokes.P, dt = Inf)
args0 = (; T = thermal.Tc, P = Plitho, dt = Inf)
compute_viscosity!(
η, 1.0, phase_ratios, stokes, args, rheology, (1e18, 1e24)
η, 1.0, phase_ratios, stokes, args0, rheology, (1e18, 1e24)
)

# PT coefficients for thermal diffusion
pt_thermal = PTThermalCoeffs(
rheology, phase_ratios, args, dt, ni, di, li; ϵ=1e-5, CFL=1e-2 / 3
rheology, phase_ratios, args0, dt, ni, di, li; ϵ=1e-5, CFL=1e-3 / 3
)

# Boundary conditions
Expand All @@ -142,8 +149,9 @@ function main(li, origin, phases_GMG, igg; nx=16, ny=16, figdir="figs2D", do_vtk
ax1 = Axis(fig[1,1], aspect = 2/3, title = "T")
ax2 = Axis(fig[1,2], aspect = 2/3, title = "log10(η)")
scatter!(ax1, Array(thermal.T[2:end-1,:][:]), Yv./1e3)
scatter!(ax2, Array(log10.(η[:])), Y./1e3)
# scatter!(ax2, Array(ρg[2][:]), Y./1e3)
# scatter!(ax2, Array(log10.(η[:])), Y./1e3)
# scatter!(ax2, Array(stokes.P[:]), Y./1e3)
scatter!(ax2, Array(Plitho[:]), Y./1e3)
ylims!(ax1, minimum(xvi[2])./1e3, 0)
ylims!(ax2, minimum(xvi[2])./1e3, 0)
hideydecorations!(ax2)
Expand Down Expand Up @@ -188,11 +196,13 @@ function main(li, origin, phases_GMG, igg; nx=16, ny=16, figdir="figs2D", do_vtk
thermal_bcs!(thermal, thermal_bc)
temperature2center!(thermal)

# interpolate fields from particle to grid vertices
# particle2grid!(thermal.T, pT, xvi, particles)
# temperature2center!(thermal)
# Update buoyancy and viscosity -
args = (; T = thermal.Tc, P = stokes.P, dt=Inf)
Plitho .= reverse(cumsum(reverse((ρg[2] .+ ρg_bg).* di[2], dims=2), dims=2), dims=2)
# Plitho .= -(ρg[2] .+ ρg_bg) .* xci[2]'
Plitho .= stokes.P .+ Plitho .- minimum(stokes.P)
# args.P .= 0

args = (; T = thermal.Tc, P = Plitho, dt=Inf)
compute_viscosity!(
η, 1.0, phase_ratios, stokes, args, rheology, (1e18, 1e24)
)
Expand All @@ -214,10 +224,10 @@ function main(li, origin, phases_GMG, igg; nx=16, ny=16, figdir="figs2D", do_vtk
dt,
igg;
iterMax = 100e3,
nout = 1e3,
nout = 2e3,
viscosity_cutoff = (1e18, 1e24),
free_surface = false,
# viscosity_relaxation = 1e-5
viscosity_relaxation = 1e-2
);
end
println("Stokes solver time ")
Expand Down Expand Up @@ -271,7 +281,7 @@ function main(li, origin, phases_GMG, igg; nx=16, ny=16, figdir="figs2D", do_vtk
if do_vtk
JustRelax.velocity2vertex!(Vx_v, Vy_v, @velocity(stokes)...)
data_v = (;
T = Array(thermal.T),
T = Array(T_buffer),
τxy = Array(stokes.τ.xy),
εxy = Array(stokes.ε.xy),
Vx = Array(Vx_v),
Expand All @@ -283,7 +293,7 @@ function main(li, origin, phases_GMG, igg; nx=16, ny=16, figdir="figs2D", do_vtk
τyy = Array(stokes.τ.yy),
εxx = Array(stokes.ε.xx),
εyy = Array(stokes.ε.yy),
η = Array(η),
η = Array(η_vep),
)
velocity_v = (
Array(Vx_v),
Expand Down Expand Up @@ -346,13 +356,14 @@ do_vtk = true # set to true to generate VTK files for ParaView
figdir = "Subduction_LAMEM_2D"
# nx, ny = 512, 256
# nx, ny = 512, 128
nx, ny = 384, 64
n = 64
nx, ny = n*6, n
nx, ny = 512, 128
li, origin, phases_GMG, T_GMG = GMG_subduction_2D(nx+1, ny+1)
igg = if !(JustRelax.MPI.Initialized()) # initialize (or not) MPI grid
IGG(init_global_grid(nx, ny, 1; init_MPI= true)...)
else
igg
end

# main(li, origin, phases_GMG, igg; figdir = figdir, nx = nx, ny = ny, do_vtk = do_vtk);

main(li, origin, phases_GMG, igg; figdir = figdir, nx = nx, ny = ny, do_vtk = do_vtk);
41 changes: 19 additions & 22 deletions subduction/LAMEM_rheology.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@ function init_rheologies()
ϕ_oceanic_crust = sind(0)
C_oceanic_crust = 5e6

ϕ_oceanic_litho = sind(0)
ϕ_oceanic_litho = sind(10)
C_oceanic_litho = 5e6

ϕ_cont_crust = sind(20)
C_cont_crust = 30e6

soft_C = LinearSoftening((C_oceanic_litho*0.95, C_oceanic_litho), (0.1, 0.5))
soft_C = LinearSoftening((C_oceanic_litho*0.05, C_oceanic_litho), (0.1, 0.5))

# common physical properties
α = 3e-5 # 1 / K
Cp = 1000 # J / kg K
# C = 3e6 # Pa
η_reg = 1e18

η_reg = 1e20
ρbg = 2700 # kg / m^3

# Define rheolgy struct
rheology = (
# Name = "dry olivine - Hirth_Kohlstedt_2003",
SetMaterialParams(;
Phase = 1,
Density = PT_Density(; ρ0=3.3e3, α = α, β = 0e0, T0 = 273),
Density = PT_Density(; ρ0=3.3e3-ρbg, α = α, β = 0e0, T0 = 273),
HeatCapacity = ConstantHeatCapacity(; Cp=Cp),
Conductivity = ConstantConductivity(; k = 3),
CompositeRheology = CompositeRheology(
(
disl_dry_olivine,
diff_dry_olivine,
# ConstantElasticity(; G=5e10, ν=0.5),
DruckerPrager_regularised(; C = C_dry_olivine, ϕ=ϕ_dry_olivine, η_vp=η_reg, Ψ=0.0) # non-regularized plasticity
ConstantElasticity(; G=5e10, ν=0.5),
DruckerPrager_regularised(; C = C_dry_olivine, ϕ=ϕ_dry_olivine, η_vp=η_reg, Ψ=0.0, softening_C = soft_C) # non-regularized plasticity
)
),
RadioactiveHeat = ConstantRadioactiveHeat(6.6667e-12),
Expand All @@ -53,70 +53,67 @@ function init_rheologies()
# Name = "oceanic crust",
SetMaterialParams(;
Phase = 2,
Density = PT_Density(; ρ0=3.3e3, α = α, β = 0e0, T0 = 273),
Density = PT_Density(; ρ0=3.3e3-ρbg, α = α, β = 0e0, T0 = 273),
HeatCapacity = ConstantHeatCapacity(; Cp=Cp),
Conductivity = ConstantConductivity(; k =3 ),
CompositeRheology = CompositeRheology(
(
disl_oceanic_crust,
# ConstantElasticity(; G=5e10, ν=0.5),
ConstantElasticity(; G=5e10, ν=0.5),
DruckerPrager_regularised(; C = C_oceanic_crust, ϕ = ϕ_oceanic_crust, η_vp=η_reg, Ψ=0.0, softening_C = soft_C) # non-regularized plasticity
)
),
RadioactiveHeat = ConstantRadioactiveHeat(2.333e-10),
# Elasticity = ConstantElasticity(; G=5e10, ν=0.5),
),
# Name = "oceanic lithosphere",
SetMaterialParams(;
Phase = 3,
Density = PT_Density(; ρ0=3.3e3, α = α, β = 0e0, T0 = 273),
Density = PT_Density(; ρ0=3.3e3-ρbg, α = α, β = 0e0, T0 = 273),
HeatCapacity = ConstantHeatCapacity(; Cp=Cp),
Conductivity = ConstantConductivity(; k = 3),
Conductivity = ConstantConductivity(; k = 3),
CompositeRheology = CompositeRheology(
(
disl_dry_olivine,
diff_dry_olivine,
ConstantElasticity(; G=5e10, ν=0.5),
DruckerPrager_regularised(; C = C_dry_olivine, ϕ=ϕ_dry_olivine, η_vp=η_reg, Ψ=0.0) # non-regularized plasticity
DruckerPrager_regularised(; C = C_dry_olivine, ϕ=ϕ_dry_olivine, η_vp=η_reg, Ψ=0.0, softening_C = soft_C) # non-regularized plasticity
)
),
RadioactiveHeat = ConstantRadioactiveHeat(6.6667e-12),
Elasticity = ConstantElasticity(; G=5e10, ν=0.5),
# Elasticity = ConstantElasticity(; G=5e10, ν=0.5),
),
# Name = "continental crust",
SetMaterialParams(;
Phase = 4,
Density = PT_Density(; ρ0=2.7e3, α = α, β = 0e0, T0 = 273),
Density = PT_Density(; ρ0=2.7e3-ρbg, α = α, β = 0e0, T0 = 273),
RadioactiveHeat = ConstantRadioactiveHeat(5.3571e-10),
HeatCapacity = ConstantHeatCapacity(; Cp=Cp),
Conductivity = ConstantConductivity(; k =3 ),
CompositeRheology = CompositeRheology(
(
disl_cont_crust,
# ConstantElasticity(; G=5e10, ν=0.5),
DruckerPrager_regularised(; C = C_cont_crust, ϕ = ϕ_cont_crust, η_vp=η_reg, Ψ=0.0) # non-regularized plasticity
ConstantElasticity(; G=5e10, ν=0.5),
DruckerPrager_regularised(; C = C_cont_crust, ϕ = ϕ_cont_crust, η_vp=η_reg, Ψ=0.0, softening_C = soft_C) # non-regularized plasticity
)
),
# Elasticity = ConstantElasticity(; G=5e10, ν=0.5),
Elasticity = ConstantElasticity(; G=5e10, ν=0.5),
),
# Name = "continental lithosphere",
SetMaterialParams(;
Phase = 5,
Density = PT_Density(; ρ0=3.3e3, α = α, β = 0e0, T0 = 273),
Density = PT_Density(; ρ0=3.3e3-ρbg, α = α, β = 0e0, T0 = 273),
HeatCapacity = ConstantHeatCapacity(; Cp=Cp),
Conductivity = ConstantConductivity(; k = 3),
CompositeRheology = CompositeRheology(
(
disl_dry_olivine,
diff_dry_olivine,
# ConstantElasticity(; G=5e10, ν=0.5),
DruckerPrager_regularised(; C = C_dry_olivine, ϕ=ϕ_dry_olivine, η_vp=η_reg, Ψ=0.0) # non-regularized plasticity
ConstantElasticity(; G=5e10, ν=0.5),
DruckerPrager_regularised(; C = C_dry_olivine, ϕ=ϕ_dry_olivine, η_vp=η_reg, Ψ=0.0, softening_C = soft_C) # non-regularized plasticity
)
),
RadioactiveHeat = ConstantRadioactiveHeat(6.6667e-12),
# Elasticity = ConstantElasticity(; G=5e10, ν=0.5),
Elasticity = ConstantElasticity(; G=5e10, ν=0.5),
),
)
end
Expand Down

0 comments on commit 10907b2

Please sign in to comment.