From 7b86f8fe91b0a9cd87f1f3311735f7f492b20a8a Mon Sep 17 00:00:00 2001 From: Albert de Montserrat <58044444+albert-de-montserrat@users.noreply.github.com> Date: Wed, 27 Mar 2024 11:28:18 +0100 Subject: [PATCH 1/7] Non dimensionalize convection miniapp (#123) * non dimensional convection miniapp * more non dim * finish nondim-ing the miniapp * cleaning * reduce plotting frequency * fix rheology --- .../Particles2D/Layered_rheology.jl | 4 +- .../Layered_convection2D.jl | 398 ++++++++++++++++++ .../Particles2D_nonDim/Layered_rheology.jl | 209 +++++++++ src/rheology/Viscosity.jl | 8 +- 4 files changed, 613 insertions(+), 6 deletions(-) create mode 100644 miniapps/convection/Particles2D_nonDim/Layered_convection2D.jl create mode 100644 miniapps/convection/Particles2D_nonDim/Layered_rheology.jl diff --git a/miniapps/convection/Particles2D/Layered_rheology.jl b/miniapps/convection/Particles2D/Layered_rheology.jl index c5a6f6e6..3c3f1912 100644 --- a/miniapps/convection/Particles2D/Layered_rheology.jl +++ b/miniapps/convection/Particles2D/Layered_rheology.jl @@ -7,8 +7,8 @@ function init_rheologies(; is_plastic = true) disl_lower_crust = DislocationCreep(A=2.08e-23, n=3.2, E=238e3, V=6e-6, r=0.0, R=8.3145) disl_lithospheric_mantle = DislocationCreep(A=2.51e-17, n=3.5, E=530e3, V=6e-6, r=0.0, R=8.3145) disl_sublithospheric_mantle = DislocationCreep(A=2.51e-17, n=3.5, E=530e3, V=6e-6, r=0.0, R=8.3145) - diff_lithospheric_mantle = DislocationCreep(A=2.51e-17, n=1.0, E=530e3, V=6e-6, r=0.0, R=8.3145) - diff_sublithospheric_mantle = DislocationCreep(A=2.51e-17, n=1.0, E=530e3, V=6e-6, r=0.0, R=8.3145) + diff_lithospheric_mantle = DiffusionCreep(A=2.51e-17, n=1.0, E=530e3, V=6e-6, p=0, r=0.0, R=8.3145) + diff_sublithospheric_mantle = DiffusionCreep(A=2.51e-17, n=1.0, E=530e3, V=6e-6, p=0, r=0.0, R=8.3145) # Elasticity el_upper_crust = SetConstantElasticity(; G=25e9, ν=0.5) diff --git a/miniapps/convection/Particles2D_nonDim/Layered_convection2D.jl b/miniapps/convection/Particles2D_nonDim/Layered_convection2D.jl new file mode 100644 index 00000000..923e7286 --- /dev/null +++ b/miniapps/convection/Particles2D_nonDim/Layered_convection2D.jl @@ -0,0 +1,398 @@ +using JustRelax, JustRelax.DataIO +import JustRelax.@cell +using ParallelStencil +@init_parallel_stencil(Threads, Float64, 2) #or (CUDA, Float64, 2) or (AMDGPU, 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 + +# setup ParallelStencil.jl environment +model = PS_Setup(:Threads, Float64, 2) #or (:CUDA, Float64, 2) or (:AMDGPU, Float64, 2) +environment!(model) + +# Load script dependencies +using Printf, LinearAlgebra, GeoParams, GLMakie, CellArrays + +# Load file with all the rheology configurations +include("Layered_rheology.jl") + +## SET OF HELPER FUNCTIONS PARTICULAR FOR THIS SCRIPT -------------------------------- + +function copyinn_x!(A, B) + @parallel function f_x(A, B) + @all(A) = @inn_x(B) + return nothing + end + + @parallel f_x(A, B) +end + +import ParallelStencil.INDICES +const idx_j = INDICES[2] +macro all_j(A) + esc(:($A[$idx_j])) +end + +# Initial pressure profile - not accurate +@parallel function init_P!(P, ρg, z) + @all(P) = abs(@all(ρg) * @all_j(z)) * <(@all_j(z), 0.0) + return nothing +end + +# Initial thermal profile +@parallel_indices (i, j) function init_T!(T, y, thick_air, CharDim) + depth = -y[j] - thick_air + + # (depth - 15e3) because we have 15km of sticky air + if depth < nondimensionalize(0e0km, CharDim) + T[i + 1, j] = nondimensionalize(273e0K, CharDim) + + elseif nondimensionalize(0e0km, CharDim) ≤ (depth) < nondimensionalize(35km, CharDim) + dTdZ = nondimensionalize((923-273)/35 * K/km, CharDim) + + offset = nondimensionalize(273e0K, CharDim) + T[i + 1, j] = (depth) * dTdZ + offset + + elseif nondimensionalize(110km, CharDim) > (depth) ≥ nondimensionalize(35km, CharDim) + dTdZ = nondimensionalize((1492-923)/75 * K/km, CharDim) + offset = nondimensionalize(923K, CharDim) + T[i + 1, j] = (depth - nondimensionalize(35km, CharDim)) * dTdZ + offset + + elseif (depth) ≥ nondimensionalize(110km, CharDim) + dTdZ = nondimensionalize((1837 - 1492)/590 * K/km, CharDim) + offset = nondimensionalize(1492e0K, CharDim) + T[i + 1, j] = (depth - nondimensionalize(110km, CharDim)) * dTdZ + offset + + end + + return nothing +end + +# Thermal rectangular perturbation +function rectangular_perturbation!(T, xc, yc, r, xvi, thick_air, CharDim) + + @parallel_indices (i, j) function _rectangular_perturbation!(T, xc, yc, r, CharDim, x, y) + @inbounds if ((x[i]-xc)^2 ≤ r^2) && ((y[j] - yc - thick_air)^2 ≤ r^2) + depth = -y[j] - thick_air + dTdZ = nondimensionalize((2047 - 2017)K / 50km, CharDim) + offset = nondimensionalize(2017e0K, CharDim) + T[i + 1, j] = (depth - nondimensionalize(585km, CharDim)) * dTdZ + offset + end + return nothing + end + + ni = length.(xvi) + @parallel (@idx ni) _rectangular_perturbation!(T, xc, yc, r, CharDim, xvi...) + + return nothing +end + +## END OF HELPER FUNCTION ------------------------------------------------------------ + +## BEGIN OF MAIN SCRIPT -------------------------------------------------------------- +function main2D(igg; ar=8, ny=16, nx=ny*8, figdir="figs2D", do_vtk =false) + + thickness = 700 * km + η0 = 1e21 + CharDim = GEO_units(; + length = thickness, viscosity = η0, temperature = 1e3K + ) + # Physical domain ------------------------------------ + thick_air = nondimensionalize(0e0km, CharDim) # thickness of sticky air layer + ly = nondimensionalize(thickness, CharDim) + thick_air # domain length in y + lx = ly * ar # domain length in x + ni = nx, ny # number of cells + li = lx, ly # domain length in x- and y- + di = @. li / ni # grid step in x- and -y + origin = 0.0, -ly # origin coordinates (15km f sticky air layer) + grid = Geometry(ni, li; origin = origin) + (; xci, xvi) = grid # nodes at the center and vertices of the cells + # ---------------------------------------------------- + + # Physical properties using GeoParams ---------------- + rheology = init_rheologies(CharDim; is_plastic = true) + κ = (4 / (rheology[4].HeatCapacity[1].Cp * rheology[4].Density[1].ρ0)) + dt = dt_diff = 0.5 * min(di...)^2 / κ / 2.01 # diffusive CFL timestep limiter + # ---------------------------------------------------- + + # Initialize particles ------------------------------- + nxcell, max_xcell, min_xcell = 25, 30, 8 + particles = init_particles( + backend, nxcell, max_xcell, min_xcell, xvi..., di..., ni... + ) + subgrid_arrays = SubgridDiffusionCellArrays(particles) + # velocity grids + grid_vx, grid_vy = velocity_grids(xci, xvi, di) + # temperature + pT, pPhases = init_cell_arrays(particles, Val(2)) + particle_args = (pT, pPhases) + + # Elliptical temperature anomaly + xc_anomaly = lx/2 # origin of thermal anomaly + yc_anomaly = nondimensionalize(-610km, CharDim) # origin of thermal anomaly + r_anomaly = nondimensionalize(25km, CharDim) # radius of perturbation + init_phases!(pPhases, particles, lx, yc_anomaly, r_anomaly, thick_air, CharDim) + phase_ratios = PhaseRatio(ni, length(rheology)) + @parallel (@idx ni) phase_ratios_center(phase_ratios.center, pPhases) + # ---------------------------------------------------- + + # STOKES --------------------------------------------- + # Allocate arrays needed for every Stokes problem + stokes = StokesArrays(ni, ViscoElastic) + pt_stokes = PTStokesCoeffs(li, di; ϵ=1e-7, CFL = 0.9 / √2.1) + # ---------------------------------------------------- + + # TEMPERATURE PROFILE -------------------------------- + thermal = ThermalArrays(ni) + thermal_bc = TemperatureBoundaryConditions(; + no_flux = (left = true, right = true, top = false, bot = false), + periodicity = (left = false, right = false, top = false, bot = false), + ) + # initialize thermal profile - Half space cooling + @parallel (@idx ni .+ 1) init_T!(thermal.T, xvi[2], thick_air, CharDim) + thermal_bcs!(thermal.T, thermal_bc) + Tbot = thermal.T[1, 1] + Ttop = thermal.T[1, end] + rectangular_perturbation!(thermal.T, xc_anomaly, yc_anomaly, r_anomaly, xvi, thick_air, CharDim) + @parallel (JustRelax.@idx size(thermal.Tc)...) temperature2center!(thermal.Tc, thermal.T) + # ---------------------------------------------------- + + # Buoyancy forces + ρg = @zeros(ni...), @zeros(ni...) + for _ in 1:1 + @parallel (JustRelax.@idx ni) compute_ρg!(ρg[2], phase_ratios.center, rheology, (T=thermal.Tc, P=stokes.P)) + @parallel init_P!(stokes.P, ρg[2], xci[2]) + end + # Rheology + η = @ones(ni...) + args = (; T = thermal.Tc, P = stokes.P, dt = Inf) + viscosity_cutoff = nondimensionalize((1e16Pa*s, 1e24Pa*s), CharDim) + @parallel (@idx ni) compute_viscosity!( + η, 1.0, phase_ratios.center, @strain(stokes)..., args, rheology, viscosity_cutoff + ) + η_vep = copy(η) + + # PT coefficients for thermal diffusion + pt_thermal = PTThermalCoeffs( + rheology, phase_ratios, args, dt, ni, di, li; ϵ=1e-5, CFL= 1e-2 / √2.1 + ) + + # Boundary conditions + flow_bcs = FlowBoundaryConditions(; + free_slip = (left = true, right=true, top=true, bot=true), + periodicity = (left = false, right = false, top = false, bot = false), + ) + flow_bcs!(stokes, flow_bcs) # apply boundary conditions + update_halo!(stokes.V.Vx, stokes.V.Vy) + + # IO ------------------------------------------------ + # if it does not exist, make folder where figures are stored + if do_vtk + vtk_dir = joinpath(figdir, "vtk") + take(vtk_dir) + end + take(figdir) + # ---------------------------------------------------- + + # Plot initial T and η profiles + let + Yv = [y for x in xvi[1], y in xvi[2]][:] + Y = [y for x in xci[1], y in xci[2]][:] + fig = Figure(size = (1200, 900)) + 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) + scatter!(ax2, Array(log10.(η[:])), Y) + ylims!(ax1, minimum(xvi[2]), 0) + ylims!(ax2, minimum(xvi[2]), 0) + hideydecorations!(ax2) + # save(joinpath(figdir, "initial_profile.png"), fig) + fig + end + + T_buffer = @zeros(ni.+1) + Told_buffer = similar(T_buffer) + dt₀ = similar(stokes.P) + for (dst, src) in zip((T_buffer, Told_buffer), (thermal.T, thermal.Told)) + copyinn_x!(dst, src) + end + grid2particle!(pT, xvi, T_buffer, particles) + + local Vx_v, Vy_v + if do_vtk + Vx_v = @zeros(ni.+1...) + Vy_v = @zeros(ni.+1...) + end + # Time loop + t, it = 0.0, 0 + while t < nondimensionalize(5e6yr, CharDim) # run only for 5 Myrs + + # interpolate fields from particle to grid vertices + particle2grid!(T_buffer, pT, xvi, particles) + @views T_buffer[:, end] .= Ttop + @views T_buffer[:, 1] .= Tbot + @views thermal.T[2:end-1, :] .= T_buffer + temperature2center!(thermal) + + # Update buoyancy and viscosity - + args = (; T = thermal.Tc, P = stokes.P, dt=Inf) + @parallel (@idx ni) compute_viscosity!( + η, 1.0, phase_ratios.center, @strain(stokes)..., args, rheology, viscosity_cutoff + ) + @parallel (JustRelax.@idx ni) compute_ρg!(ρg[2], phase_ratios.center, rheology, args) + # ------------------------------ + + # Stokes solver ---------------- + solve!( + stokes, + pt_stokes, + di, + flow_bcs, + ρg, + η, + η_vep, + phase_ratios, + rheology, + args, + Inf, + igg; + iterMax = 150e3, + nout = 1e3, + viscosity_cutoff = viscosity_cutoff + ) + @parallel (JustRelax.@idx ni) JustRelax.Stokes2D.tensor_invariant!(stokes.ε.II, @strain(stokes)...) + dt = compute_dt(stokes, di, dt_diff) + # ------------------------------ + + # Thermal solver --------------- + heatdiffusion_PT!( + thermal, + pt_thermal, + thermal_bc, + rheology, + args, + dt, + di; + igg = igg, + phase = phase_ratios, + iterMax = 10e3, + nout = 1e2, + verbose = true, + ) + for (dst, src) in zip((T_buffer, Told_buffer), (thermal.T, thermal.Told)) + copyinn_x!(dst, src) + end + subgrid_characteristic_time!( + subgrid_arrays, particles, dt₀, phase_ratios, rheology, thermal, stokes, xci, di + ) + centroid2particle!(subgrid_arrays.dt₀, xci, dt₀, particles) + subgrid_diffusion!( + pT, T_buffer, thermal.ΔT[2:end-1, :], subgrid_arrays, particles, xvi, di, dt + ) + # ------------------------------ + + # Advection -------------------- + # advect particles in space + advection_RK!(particles, @velocity(stokes), grid_vx, grid_vy, dt, 2 / 3) + # advect particles in memory + move_particles!(particles, xvi, particle_args) + # check if we need to inject particles + inject = check_injection(particles) + inject && inject_particles_phase!(particles, pPhases, (pT, ), (T_buffer,), xvi) + # update phase ratios + @parallel (@idx ni) phase_ratios_center(phase_ratios.center, pPhases) + + @show it += 1 + t += dt + + # Data I/O and plotting --------------------- + if it == 1 || rem(it, 25) == 0 + checkpointing(figdir, stokes, thermal.T, η, t) + + if do_vtk + JustRelax.velocity2vertex!(Vx_v, Vy_v, @velocity(stokes)...) + data_v = (; + T = Array(thermal.T[2:end-1, :]), + τxy = Array(stokes.τ.xy), + εxy = Array(stokes.ε.xy), + Vx = Array(Vx_v), + Vy = Array(Vy_v), + ) + data_c = (; + P = Array(stokes.P), + τxx = Array(stokes.τ.xx), + τyy = Array(stokes.τ.yy), + εxx = Array(stokes.ε.xx), + εyy = Array(stokes.ε.yy), + η = Array(η), + ) + do_vtk( + joinpath(vtk_dir, "vtk_" * lpad("$it", 6, "0")), + xvi, + xci, + data_v, + data_c + ) + end + + # Make particles plottable + p = particles.coords + ppx, ppy = p + pxv = ppx.data[:] + pyv = ppy.data[:] + clr = pPhases.data[:] + clr = pT.data[:] + idxv = particles.index.data[:]; + + # Make Makie figure + fig = Figure(size = (900, 900), title = "t = $t") + ax1 = Axis(fig[1,1], aspect = ar, title = "T [K] (t=$(t/(1e6 * 3600 * 24 *365.25)) Myrs)") + ax2 = Axis(fig[2,1], aspect = ar, title = "Vy [m/s]") + ax3 = Axis(fig[1,3], aspect = ar, title = "log10(εII)") + ax4 = Axis(fig[2,3], aspect = ar, title = "log10(η)") + # Plot temperature + h1 = heatmap!(ax1, xvi[1], xvi[2], Array(thermal.T[2:end-1,:]) , colormap=:batlow) + # Plot particles phase + h2 = scatter!(ax2, Array(pxv[idxv]), Array(pyv[idxv]), color=Array(clr[idxv])) + # Plot 2nd invariant of strain rate + h3 = heatmap!(ax3, xci[1], xci[2], Array(log10.(stokes.ε.II)) , colormap=:batlow) + # Plot effective viscosity + h4 = heatmap!(ax4, xci[1], xci[2], Array(log10.(η_vep)) , colormap=:batlow) + hidexdecorations!(ax1) + hidexdecorations!(ax2) + hidexdecorations!(ax3) + Colorbar(fig[1,2], h1) + Colorbar(fig[2,2], h2) + Colorbar(fig[1,4], h3) + Colorbar(fig[2,4], h4) + linkaxes!(ax1, ax2, ax3, ax4) + save(joinpath(figdir, "$(it).png"), fig) + fig + end + # ------------------------------ + + end + + return nothing +end +## END OF MAIN SCRIPT ---------------------------------------------------------------- + +# (Path)/folder where output data and figures are stored +figdir = "Plume2D" +do_vtk = false # set to true to generate VTK files for ParaView +ar = 1 # aspect ratio +n = 128 +nx = n*ar - 2 +ny = n - 2 +igg = if !(JustRelax.MPI.Initialized()) # initialize (or not) MPI grid + IGG(init_global_grid(nx, ny, 1; init_MPI= true)...) +else + igg +end + +# run main script +main2D(igg; figdir = figdir, ar = ar, nx = nx, ny = ny, do_vtk = do_vtk); diff --git a/miniapps/convection/Particles2D_nonDim/Layered_rheology.jl b/miniapps/convection/Particles2D_nonDim/Layered_rheology.jl new file mode 100644 index 00000000..7bda50fb --- /dev/null +++ b/miniapps/convection/Particles2D_nonDim/Layered_rheology.jl @@ -0,0 +1,209 @@ +# from "Fingerprinting secondary mantle plumes", Cloetingh et al. 2022 + +function init_rheologies(CharDim; is_plastic = true) + + # Dislocation and Diffusion creep + disl_upper_crust = DislocationCreep( + A=5.07e-18Pa^(-23//10) / s, # units are Pa^(-n) / s + n=2.3NoUnits, + E=154e3J/mol, + V=6e-6m^3/mol, + r=0.0NoUnits, + R=8.3145J/mol/K + ) + disl_lower_crust = DislocationCreep( + A=2.08e-23Pa^(-32//10) / s, # units are Pa^(-n) / s + n=3.2NoUnits, + E=238e3J/mol, + V=6e-6m^3/mol, + r=0.0NoUnits, + R=8.3145J/mol/K, + ) + disl_lithospheric_mantle = DislocationCreep( + A=2.51e-17Pa^(-35//10) / s, # units are Pa^(-n) / s + n=3.5NoUnits, + E=530e3J/mol, + V=6e-6m^3/mol, + r=0.0NoUnits, + R=8.3145J/mol/K + ) + disl_sublithospheric_mantle = DislocationCreep( + A=2.51e-17Pa^(-35//10) / s, # units are Pa^(-n) / s + n=3.5NoUnits, + E=530e3J/mol, + V=6e-6m^3/mol, + r=0.0NoUnits, + R=8.3145J/mol/K + ) + diff_lithospheric_mantle = DiffusionCreep( + A=2.51e-17Pa^(-1) / s, # units are Pa^(-n - r) / s * m^(-p) + n=1.0NoUnits, + E=530e3J/mol, + V=6e-6m^3/mol, + r=0.0NoUnits, + p=0.0NoUnits, + R=8.3145J/mol/K + ) + diff_sublithospheric_mantle = DiffusionCreep( + A=2.51e-17Pa^(-1) / s, # units are Pa^(-n - r) / s * m^(-p) + n=1.0NoUnits, + E=530e3J/mol, + V=6e-6m^3/mol, + r=0.0NoUnits, + p=0.0NoUnits, + R=8.3145J/mol/K + ) + + # Elasticity + el_upper_crust = SetConstantElasticity(; G=25e9Pa, ν=0.5) + el_lower_crust = SetConstantElasticity(; G=25e9Pa, ν=0.5) + el_lithospheric_mantle = SetConstantElasticity(; G=67e9Pa, ν=0.5) + el_sublithospheric_mantle = SetConstantElasticity(; G=67e9Pa, ν=0.5) + β_upper_crust = inv(get_Kb(el_upper_crust)) + β_lower_crust = inv(get_Kb(el_lower_crust)) + β_lithospheric_mantle = inv(get_Kb(el_lithospheric_mantle)) + β_sublithospheric_mantle = inv(get_Kb(el_sublithospheric_mantle)) + + # Physical properties using GeoParams ---------------- + η_reg = 1e16 * Pa * s + cohesion = 3e6 * Pa + friction = asind(0.2) + pl_crust = if is_plastic + DruckerPrager_regularised(; C = cohesion, ϕ=friction, η_vp=η_reg, Ψ=0.0) # non-regularized plasticity + else + DruckerPrager_regularised(; C = Inf, ϕ=friction, η_vp=η_reg, Ψ=0.0) # non-regularized plasticity + end + friction = asind(0.3) + pl = if is_plastic + DruckerPrager_regularised(; C = cohesion, ϕ=friction, η_vp=η_reg, Ψ=0.0) # non-regularized plasticity + else + DruckerPrager_regularised(; C = Inf, ϕ=friction, η_vp=η_reg, Ψ=0.0) # non-regularized plasticity + end + pl_wz = if is_plastic + DruckerPrager_regularised(; C = 2e6Pa, ϕ=2.0, η_vp=η_reg, Ψ=0.0) # non-regularized plasticity + else + DruckerPrager_regularised(; C = Inf, ϕ=friction, η_vp=η_reg, Ψ=0.0) # non-regularized plasticity + end + + # crust + K_crust = TP_Conductivity(; + a = 0.64, + b = 807e0, + c = 0.77, + d = 0.00004*1e-6, + ) + + K_mantle = TP_Conductivity(; + a = 0.73, + b = 1293e0, + c = 0.77, + d = 0.00004*1e-6, + ) + + g = -9.81m/s^2 + + # Define rheolgy struct + rheology = ( + # Name = "UpperCrust", + SetMaterialParams(; + Phase = 1, + Density = PT_Density(; ρ0=2.75e3kg / m^3, β=β_upper_crust, T0=0e0C, α = 3.5e-5/ K), + HeatCapacity = ConstantHeatCapacity(; Cp=7.5e2J / kg / K), + Conductivity = K_crust, + # CompositeRheology = CompositeRheology((LinearViscous(; η=1e22Pa*s),)), + CompositeRheology = CompositeRheology((disl_upper_crust, el_upper_crust, pl_crust)), + Elasticity = el_upper_crust, + RadioactiveHeat = ConstantRadioactiveHeat(0.0), + Gravity = ConstantGravity(; g=g), + CharDim = CharDim, + ), + # Name = "LowerCrust", + SetMaterialParams(; + Phase = 2, + Density = PT_Density(; ρ0=3e3kg / m^3, β=β_upper_crust, T0=0e0C, α = 3.5e-5/ K), + HeatCapacity = ConstantHeatCapacity(; Cp=7.5e2J / kg / K), + Conductivity = K_crust, + RadioactiveHeat = ConstantRadioactiveHeat(0.0), + # CompositeRheology = CompositeRheology((LinearViscous(; η=5e21Pa*s),)), + CompositeRheology = CompositeRheology((disl_lower_crust, el_lower_crust, pl_crust)), + Gravity = ConstantGravity(; g=g), + Elasticity = el_lower_crust, + CharDim = CharDim, + ), + # Name = "LithosphericMantle", + SetMaterialParams(; + Phase = 3, + Density = PT_Density(; ρ0=3.3e3kg / m^3, β=β_upper_crust, T0=0e0C, α = 3.5e-5/ K), + HeatCapacity = ConstantHeatCapacity(; Cp=1.25e3J / kg / K), + Conductivity = K_mantle, + RadioactiveHeat = ConstantRadioactiveHeat(0.0), + # CompositeRheology = CompositeRheology((LinearViscous(; η=1e19Pa*s),)), + CompositeRheology = CompositeRheology((disl_lithospheric_mantle, diff_lithospheric_mantle, el_lithospheric_mantle, pl)), + Gravity = ConstantGravity(; g=g), + Elasticity = el_lithospheric_mantle, + CharDim = CharDim, + ), + SetMaterialParams(; + Phase = 4, + Density = PT_Density(; ρ0=(3.3e3-50)kg / m^3, β=β_upper_crust, T0=0e0C, α = 3.5e-5/ K), + HeatCapacity = ConstantHeatCapacity(; Cp=1.25e3J / kg / K), + Conductivity = K_mantle, + RadioactiveHeat = ConstantRadioactiveHeat(0.0), + # CompositeRheology = CompositeRheology((LinearViscous(; η=1e19Pa*s),)), + CompositeRheology = CompositeRheology((disl_sublithospheric_mantle, diff_sublithospheric_mantle, el_sublithospheric_mantle)), + Gravity = ConstantGravity(; g=g), + Elasticity = el_sublithospheric_mantle, + CharDim = CharDim, + ), + # Name = "StickyAir", + SetMaterialParams(; + Phase = 5, + Density = ConstantDensity(; ρ=1e3kg / m^3), # water density + HeatCapacity = ConstantHeatCapacity(; Cp=3e3J / kg / K), + RadioactiveHeat = ConstantRadioactiveHeat(0.0), + Conductivity = ConstantConductivity(; k=1.0Watt / m / K), + Gravity = ConstantGravity(; g=g), + CompositeRheology = CompositeRheology((LinearViscous(; η=1e19Pa*s),)), + CharDim = CharDim, + ), + ) +end + +function init_phases!(phases, particles, Lx, d, r, thick_air, CharDim) + ni = size(phases) + + @parallel_indices (i, j) function init_phases!(phases, px, py, index, r, Lx, CharDim) + @inbounds for ip in JustRelax.cellaxes(phases) + # quick escape + JustRelax.@cell(index[ip, i, j]) == 0 && continue + + x = JustRelax.@cell px[ip, i, j] + depth = -(JustRelax.@cell py[ip, i, j]) - nondimensionalize(thick_air * km, CharDim) + if nondimensionalize(0e0km, CharDim) ≤ depth ≤ nondimensionalize(21e3km, CharDim) + @cell phases[ip, i, j] = 1.0 + + elseif nondimensionalize(35e3km, CharDim) ≥ depth > nondimensionalize(21e3km, CharDim) + @cell phases[ip, i, j] = 2.0 + + elseif nondimensionalize(90e3km, CharDim) ≥ depth > nondimensionalize(35e3km, CharDim) + @cell phases[ip, i, j] = 3.0 + + elseif depth > nondimensionalize(90e3km, CharDim) + @cell phases[ip, i, j] = 3.0 + + elseif depth < nondimensionalize(0e0km, CharDim) + @cell phases[ip, i, j] = 5.0 + + end + + # plume - rectangular + if ((x - Lx * 0.5)^2 ≤ r^2) && (((JustRelax.@cell py[ip, i, j]) - d - nondimensionalize(thick_air * km, CharDim))^2 ≤ r^2) + JustRelax.@cell phases[ip, i, j] = 4.0 + end + end + return nothing + end + + @parallel (JustRelax.@idx ni) init_phases!(phases, particles.coords..., particles.index, r, Lx, CharDim) +end + \ No newline at end of file diff --git a/src/rheology/Viscosity.jl b/src/rheology/Viscosity.jl index d9089086..e07ca4c1 100644 --- a/src/rheology/Viscosity.jl +++ b/src/rheology/Viscosity.jl @@ -12,7 +12,7 @@ ε = εxx[I...], εyy[I...] # we need strain rate not to be zero, otherwise we get NaNs - εII_0 = allzero(ε...) * 1e-15 + εII_0 = allzero(ε...) * eps() # argument fields at local index args_ij = local_viscosity_args(args, I...) @@ -59,7 +59,7 @@ end ε = εxx[I...], εyy[I...] # we need strain rate not to be zero, otherwise we get NaNs - εII_0 = allzero(ε...) * 1e-18 + εII_0 = allzero(ε...) * eps() # argument fields at local index args_ij = local_viscosity_args(args, I...) @@ -95,7 +95,7 @@ end εij_normal = εxx[I...], εyy[I...], εzz[I...] # we need strain rate not to be zero, otherwise we get NaNs - εII_0 = allzero(εij_normal...) * 1e-18 + εII_0 = allzero(εij_normal...) * eps() # # argument fields at local index args_ijk = local_viscosity_args(args, I...) @@ -145,7 +145,7 @@ end εij_normal = εxx[I...], εyy[I...], εzz[I...] # we need strain rate not to be zero, otherwise we get NaNs - εII_0 = allzero(εij_normal...) * 1e-18 + εII_0 = allzero(εij_normal...) * eps() # # argument fields at local index args_ijk = local_viscosity_args(args, I...) From cb858ad9c53299ed124cd0a1a3ab08e1869ce2ce Mon Sep 17 00:00:00 2001 From: Albert de Montserrat <58044444+albert-de-montserrat@users.noreply.github.com> Date: Wed, 27 Mar 2024 14:13:06 +0100 Subject: [PATCH 2/7] Update non dimensional convection miniapp (#124) * Update Layered_rheology.jl * Update Layered_convection2D.jl * Update Layered_rheology.jl --- .../Layered_convection2D.jl | 28 ++++++------ .../Particles2D_nonDim/Layered_rheology.jl | 43 +++++++------------ 2 files changed, 31 insertions(+), 40 deletions(-) diff --git a/miniapps/convection/Particles2D_nonDim/Layered_convection2D.jl b/miniapps/convection/Particles2D_nonDim/Layered_convection2D.jl index 923e7286..50e646e4 100644 --- a/miniapps/convection/Particles2D_nonDim/Layered_convection2D.jl +++ b/miniapps/convection/Particles2D_nonDim/Layered_convection2D.jl @@ -97,7 +97,7 @@ end function main2D(igg; ar=8, ny=16, nx=ny*8, figdir="figs2D", do_vtk =false) thickness = 700 * km - η0 = 1e21 + η0 = 1e20 CharDim = GEO_units(; length = thickness, viscosity = η0, temperature = 1e3K ) @@ -178,7 +178,7 @@ function main2D(igg; ar=8, ny=16, nx=ny*8, figdir="figs2D", do_vtk =false) # PT coefficients for thermal diffusion pt_thermal = PTThermalCoeffs( - rheology, phase_ratios, args, dt, ni, di, li; ϵ=1e-5, CFL= 1e-2 / √2.1 + rheology, phase_ratios, args, dt, ni, di, li; ϵ=1e-6, CFL= 1e-3 / √2.1 ) # Boundary conditions @@ -206,11 +206,11 @@ function main2D(igg; ar=8, ny=16, nx=ny*8, figdir="figs2D", do_vtk =false) 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) - scatter!(ax2, Array(log10.(η[:])), Y) + scatter!(ax2, Array(log10.(A[:])), Y) ylims!(ax1, minimum(xvi[2]), 0) ylims!(ax2, minimum(xvi[2]), 0) hideydecorations!(ax2) - # save(joinpath(figdir, "initial_profile.png"), fig) + save(joinpath(figdir, "initial_profile.png"), fig) fig end @@ -233,9 +233,10 @@ function main2D(igg; ar=8, ny=16, nx=ny*8, figdir="figs2D", do_vtk =false) # interpolate fields from particle to grid vertices particle2grid!(T_buffer, pT, xvi, particles) - @views T_buffer[:, end] .= Ttop - @views T_buffer[:, 1] .= Tbot @views thermal.T[2:end-1, :] .= T_buffer + @views thermal.T[:, end] .= Ttop + @views thermal.T[:, 1] .= Tbot + thermal_bcs!(thermal.T, thermal_bc) temperature2center!(thermal) # Update buoyancy and viscosity - @@ -279,8 +280,8 @@ function main2D(igg; ar=8, ny=16, nx=ny*8, figdir="figs2D", do_vtk =false) di; igg = igg, phase = phase_ratios, - iterMax = 10e3, - nout = 1e2, + iterMax = 50e3, + nout = 5e2, verbose = true, ) for (dst, src) in zip((T_buffer, Told_buffer), (thermal.T, thermal.Told)) @@ -345,19 +346,20 @@ function main2D(igg; ar=8, ny=16, nx=ny*8, figdir="figs2D", do_vtk =false) pxv = ppx.data[:] pyv = ppy.data[:] clr = pPhases.data[:] - clr = pT.data[:] idxv = particles.index.data[:]; # Make Makie figure - fig = Figure(size = (900, 900), title = "t = $t") - ax1 = Axis(fig[1,1], aspect = ar, title = "T [K] (t=$(t/(1e6 * 3600 * 24 *365.25)) Myrs)") - ax2 = Axis(fig[2,1], aspect = ar, title = "Vy [m/s]") + t_dim = Float16(dimensionalize(t, yr, CharDim).val / 1e3) + fig = Figure(size = (900, 900), title = "t = $t_dim [kyr]") + ax1 = Axis(fig[1,1], aspect = ar, title = "T [K] ; t=$t_dim [kyrs]") + ax2 = Axis(fig[2,1], aspect = ar, title = "phase") + # ax2 = Axis(fig[2,1], aspect = ar, title = "Vy [m/s]") ax3 = Axis(fig[1,3], aspect = ar, title = "log10(εII)") ax4 = Axis(fig[2,3], aspect = ar, title = "log10(η)") # Plot temperature h1 = heatmap!(ax1, xvi[1], xvi[2], Array(thermal.T[2:end-1,:]) , colormap=:batlow) # Plot particles phase - h2 = scatter!(ax2, Array(pxv[idxv]), Array(pyv[idxv]), color=Array(clr[idxv])) + h2 = scatter!(ax2, Array(pxv[idxv]), Array(pyv[idxv]), color=Array(clr[idxv]), colormap=:grayC) # Plot 2nd invariant of strain rate h3 = heatmap!(ax3, xci[1], xci[2], Array(log10.(stokes.ε.II)) , colormap=:batlow) # Plot effective viscosity diff --git a/miniapps/convection/Particles2D_nonDim/Layered_rheology.jl b/miniapps/convection/Particles2D_nonDim/Layered_rheology.jl index 7bda50fb..c1b091fb 100644 --- a/miniapps/convection/Particles2D_nonDim/Layered_rheology.jl +++ b/miniapps/convection/Particles2D_nonDim/Layered_rheology.jl @@ -79,28 +79,21 @@ function init_rheologies(CharDim; is_plastic = true) else DruckerPrager_regularised(; C = Inf, ϕ=friction, η_vp=η_reg, Ψ=0.0) # non-regularized plasticity end - pl_wz = if is_plastic - DruckerPrager_regularised(; C = 2e6Pa, ϕ=2.0, η_vp=η_reg, Ψ=0.0) # non-regularized plasticity - else - DruckerPrager_regularised(; C = Inf, ϕ=friction, η_vp=η_reg, Ψ=0.0) # non-regularized plasticity - end - - # crust + K_crust = TP_Conductivity(; - a = 0.64, - b = 807e0, - c = 0.77, - d = 0.00004*1e-6, + a = 0.64Watt / K / m , + b = 807e00Watt / m , + c = 0.77K, + d = 0.00004/ MPa, ) - K_mantle = TP_Conductivity(; - a = 0.73, - b = 1293e0, - c = 0.77, - d = 0.00004*1e-6, + a = 0.73Watt / K / m , + b = 1293e00Watt / m , + c = 0.77K, + d = 0.00004/ MPa, ) - - g = -9.81m/s^2 + + g = 9.81m/s^2 # Define rheolgy struct rheology = ( @@ -110,7 +103,6 @@ function init_rheologies(CharDim; is_plastic = true) Density = PT_Density(; ρ0=2.75e3kg / m^3, β=β_upper_crust, T0=0e0C, α = 3.5e-5/ K), HeatCapacity = ConstantHeatCapacity(; Cp=7.5e2J / kg / K), Conductivity = K_crust, - # CompositeRheology = CompositeRheology((LinearViscous(; η=1e22Pa*s),)), CompositeRheology = CompositeRheology((disl_upper_crust, el_upper_crust, pl_crust)), Elasticity = el_upper_crust, RadioactiveHeat = ConstantRadioactiveHeat(0.0), @@ -124,7 +116,6 @@ function init_rheologies(CharDim; is_plastic = true) HeatCapacity = ConstantHeatCapacity(; Cp=7.5e2J / kg / K), Conductivity = K_crust, RadioactiveHeat = ConstantRadioactiveHeat(0.0), - # CompositeRheology = CompositeRheology((LinearViscous(; η=5e21Pa*s),)), CompositeRheology = CompositeRheology((disl_lower_crust, el_lower_crust, pl_crust)), Gravity = ConstantGravity(; g=g), Elasticity = el_lower_crust, @@ -137,7 +128,6 @@ function init_rheologies(CharDim; is_plastic = true) HeatCapacity = ConstantHeatCapacity(; Cp=1.25e3J / kg / K), Conductivity = K_mantle, RadioactiveHeat = ConstantRadioactiveHeat(0.0), - # CompositeRheology = CompositeRheology((LinearViscous(; η=1e19Pa*s),)), CompositeRheology = CompositeRheology((disl_lithospheric_mantle, diff_lithospheric_mantle, el_lithospheric_mantle, pl)), Gravity = ConstantGravity(; g=g), Elasticity = el_lithospheric_mantle, @@ -149,7 +139,6 @@ function init_rheologies(CharDim; is_plastic = true) HeatCapacity = ConstantHeatCapacity(; Cp=1.25e3J / kg / K), Conductivity = K_mantle, RadioactiveHeat = ConstantRadioactiveHeat(0.0), - # CompositeRheology = CompositeRheology((LinearViscous(; η=1e19Pa*s),)), CompositeRheology = CompositeRheology((disl_sublithospheric_mantle, diff_sublithospheric_mantle, el_sublithospheric_mantle)), Gravity = ConstantGravity(; g=g), Elasticity = el_sublithospheric_mantle, @@ -179,16 +168,16 @@ function init_phases!(phases, particles, Lx, d, r, thick_air, CharDim) x = JustRelax.@cell px[ip, i, j] depth = -(JustRelax.@cell py[ip, i, j]) - nondimensionalize(thick_air * km, CharDim) - if nondimensionalize(0e0km, CharDim) ≤ depth ≤ nondimensionalize(21e3km, CharDim) + if nondimensionalize(0e0km, CharDim) ≤ depth ≤ nondimensionalize(21km, CharDim) @cell phases[ip, i, j] = 1.0 - elseif nondimensionalize(35e3km, CharDim) ≥ depth > nondimensionalize(21e3km, CharDim) + elseif nondimensionalize(35km, CharDim) ≥ depth > nondimensionalize(21km, CharDim) @cell phases[ip, i, j] = 2.0 - elseif nondimensionalize(90e3km, CharDim) ≥ depth > nondimensionalize(35e3km, CharDim) + elseif nondimensionalize(90km, CharDim) ≥ depth > nondimensionalize(35km, CharDim) @cell phases[ip, i, j] = 3.0 - elseif depth > nondimensionalize(90e3km, CharDim) + elseif depth > nondimensionalize(90km, CharDim) @cell phases[ip, i, j] = 3.0 elseif depth < nondimensionalize(0e0km, CharDim) @@ -206,4 +195,4 @@ function init_phases!(phases, particles, Lx, d, r, thick_air, CharDim) @parallel (JustRelax.@idx ni) init_phases!(phases, particles.coords..., particles.index, r, Lx, CharDim) end - \ No newline at end of file + From 4bf93124c91fac14227bf0542937e852bf82057e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 22:17:29 +0000 Subject: [PATCH 3/7] Bump codecov/codecov-action from 4.0.1 to 4.1.1 Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 4.0.1 to 4.1.1. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v4.0.1...v4.1.1) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2e5fc65..65d0725f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,7 +42,7 @@ jobs: - uses: julia-actions/julia-buildpkg@latest - uses: julia-actions/julia-runtest@latest - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v4.0.1 + - uses: codecov/codecov-action@v4.1.1 with: token: ${{ secrets.CODECOV_TOKEN }} fail_ci_if_error: false # or true if you want CI to fail when Codecov fails From b4f3d4a4e28670fb3d114c8ef5410c3971adfd2a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 22:17:32 +0000 Subject: [PATCH 4/7] Bump julia-actions/setup-julia from 1 to 2 Bumps [julia-actions/setup-julia](https://github.com/julia-actions/setup-julia) from 1 to 2. - [Release notes](https://github.com/julia-actions/setup-julia/releases) - [Commits](https://github.com/julia-actions/setup-julia/compare/v1...v2) --- updated-dependencies: - dependency-name: julia-actions/setup-julia dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/ci.yml | 2 +- .github/workflows/format_check.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2e5fc65..b8cd52c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: - x64 steps: - uses: actions/checkout@v4 - - uses: julia-actions/setup-julia@v1 + - uses: julia-actions/setup-julia@v2 with: version: ${{ matrix.version }} arch: ${{ matrix.arch }} diff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.yml index 602898a2..3fb7870f 100644 --- a/.github/workflows/format_check.yml +++ b/.github/workflows/format_check.yml @@ -20,7 +20,7 @@ jobs: - x64 steps: - uses: actions/checkout@v4 - - uses: julia-actions/setup-julia@v1 + - uses: julia-actions/setup-julia@v2 with: version: ${{ matrix.version }} arch: ${{ matrix.arch }} From e2344d9626e329c5ea18165a28767fb222cf198a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 22:17:37 +0000 Subject: [PATCH 5/7] Bump crate-ci/typos from 1.19.0 to 1.20.1 Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.19.0 to 1.20.1. - [Release notes](https://github.com/crate-ci/typos/releases) - [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md) - [Commits](https://github.com/crate-ci/typos/compare/v1.19.0...v1.20.1) --- updated-dependencies: - dependency-name: crate-ci/typos dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/SpellCheck.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/SpellCheck.yml b/.github/workflows/SpellCheck.yml index e8f2271f..a339d409 100644 --- a/.github/workflows/SpellCheck.yml +++ b/.github/workflows/SpellCheck.yml @@ -10,4 +10,4 @@ jobs: - name: Checkout Actions Repository uses: actions/checkout@v4 - name: Check spelling - uses: crate-ci/typos@v1.19.0 + uses: crate-ci/typos@v1.20.1 From 9c7a2cb76d23755737eceb03e80db289b6631225 Mon Sep 17 00:00:00 2001 From: Albert de Montserrat <58044444+albert-de-montserrat@users.noreply.github.com> Date: Tue, 2 Apr 2024 23:46:09 +0200 Subject: [PATCH 6/7] Bump ParallelStencil (#126) * Bump ParallelStencil * bump --- Project.toml | 8 ++++---- test/Project.toml | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Project.toml b/Project.toml index 1227b3f7..215b4e08 100644 --- a/Project.toml +++ b/Project.toml @@ -23,15 +23,15 @@ WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192" [compat] AMDGPU = "0.6, 0.7, 0.8" -Adapt = "3.7.2" +Adapt = "3" CUDA = "4.4.1, 5" -CellArrays = "0.1, 0.2" +CellArrays = "0.2" GeoParams = "0.5" HDF5 = "0.17.1" -ImplicitGlobalGrid = "0.14.0, 0.15.0" +ImplicitGlobalGrid = "0.15.0" MPI = "0.20" MuladdMacro = "0.2" -ParallelStencil = "0.9, 0.10, 0.11" +ParallelStencil = "0.12" Reexport = "1.2.2" StaticArrays = "1" Statistics = "1" diff --git a/test/Project.toml b/test/Project.toml index dc1656a7..c1444d4f 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -2,6 +2,7 @@ AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a" JustPIC = "10dc771f-8528-4cd9-9d3b-b21b2e693339" ParallelStencil = "94395366-693c-11ea-3b26-d9b7aac5d958" +CellArrays = "d35fcfd7-7af4-4c67-b1aa-d78070614af4" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" @@ -10,7 +11,8 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] JustPIC = "0.2" -ParallelStencil = "0.9, 0.10, 0.11" +ParallelStencil = "0.11, 0.12" +CellArrays = "0.2" StaticArrays = "1" Statistics = "1" julia = "1.9, 1.10" From 73e35d44cda456f18b0479749f40a382c8be2402 Mon Sep 17 00:00:00 2001 From: Albert de Montserrat <58044444+albert-de-montserrat@users.noreply.github.com> Date: Wed, 3 Apr 2024 11:23:33 +0200 Subject: [PATCH 7/7] Free surface bcs (#125) * free surface stabilization * free surface stabilization * update * fix CI * rayleigh taylor test * fix no slip BCs * fix free surface correciton * Rayleigh Taylor miniapp * format * update miniapp * remove comment * add testing script * fix spelling * update to newest JP and GP * update crustal benchmark * fix dt (cant be Inf anymore) * surface stabilization miniapps * few tweaks * fix tests (dt != Inf) * fix van keken test * fix VK again * introduce pressure shift * update Rayleigh Taylor miniapp * format * BC fixes * format * reverse change * improve indexing * fix BCs test * reduce relaxation coeff * proto script * introduce Dani's Freesurface Vy stabilisation * fix index * add again dani's freesurface functions * update * move Blankenbach to Stokes2D * update RT app * remove periodic BCs * free surface bcs * remove periodic BCs tests * few updates * some cleaning * remove BCs from file * format * 3D free surface BC * fix index * remove `periodicity` * remove files * format * update * fix stokes * format * fix test * fix tests * fix * oopsie --------- Co-authored-by: Pascal Aellig Co-authored-by: Pascal Aellig <93140290+aelligp@users.noreply.github.com> --- _typos.toml | 1 + .../Blankenbach2D/Benchmark2D_WENO5.jl | 2 - .../Blankenbach2D/Benchmark2D_sgd.jl | 2 - .../Blankenbach2D/Benchmark2D_sgd_scaled.jl | 2 - .../Blankenbach2D/Blankenbach_Rheology.jl | 0 .../Blankenbach_Rheology_scaled.jl | 0 .../PlumeFreeSurface_2D.jl | 28 ++-- .../RayleighTaylor2D.jl | 61 ++++--- .../stokes2D/shear_heating/Shearheating2D.jl | 2 - .../stokes2D/sinking_block/SinkingBlock2D.jl | 1 - .../stokes3D/burstedde/Burstedde.jl | 3 - .../stokes3D/shear_band/ShearBand3D.jl | 1 - .../stokes3D/shear_heating/Shearheating3D.jl | 2 - miniapps/benchmarks/stokes3D/solvi/SolVi3D.jl | 3 - .../stokes3D/taylor_green/TaylorGreen.jl | 3 - .../diffusion/diffusion3D.jl | 1 - .../diffusion/diffusion3D_MPI.jl | 1 - .../diffusion/diffusion3D_multiphase.jl | 1 - .../convection/GlobalConvection2D_Upwind.jl | 2 - .../convection/GlobalConvection2D_WENO5.jl | 2 - .../GlobalConvection2D_WENO5_MPI.jl | 2 - .../convection/GlobalConvection3D_Upwind.jl | 2 - .../Particles2D/Layered_convection2D.jl | 1 - .../Layered_convection2D.jl | 2 - .../Particles3D/Layered_convection3D.jl | 6 +- src/MetaJustRelax.jl | 3 +- src/boundaryconditions/BoundaryConditions.jl | 152 +++++++++++------- src/stokes/Stokes2D.jl | 22 ++- src/stokes/VelocityKernels.jl | 2 +- test/test_boundary_conditions2D.jl | 33 +--- test/test_diffusion3D.jl | 1 - test/test_diffusion3D_multiphase.jl | 1 - test/test_shearheating2D.jl | 2 - test/test_shearheating3D.jl | 2 - test/test_sinking_block.jl | 1 - 35 files changed, 162 insertions(+), 188 deletions(-) rename miniapps/benchmarks/{ => stokes2D}/Blankenbach2D/Benchmark2D_WENO5.jl (98%) rename miniapps/benchmarks/{ => stokes2D}/Blankenbach2D/Benchmark2D_sgd.jl (99%) rename miniapps/benchmarks/{ => stokes2D}/Blankenbach2D/Benchmark2D_sgd_scaled.jl (99%) rename miniapps/benchmarks/{ => stokes2D}/Blankenbach2D/Blankenbach_Rheology.jl (100%) rename miniapps/benchmarks/{ => stokes2D}/Blankenbach2D/Blankenbach_Rheology_scaled.jl (100%) diff --git a/_typos.toml b/_typos.toml index b12f4144..ac343ee7 100644 --- a/_typos.toml +++ b/_typos.toml @@ -1,3 +1,4 @@ [default.extend-words] Ths = "Ths" oly = "oly" +iy = "iy" diff --git a/miniapps/benchmarks/Blankenbach2D/Benchmark2D_WENO5.jl b/miniapps/benchmarks/stokes2D/Blankenbach2D/Benchmark2D_WENO5.jl similarity index 98% rename from miniapps/benchmarks/Blankenbach2D/Benchmark2D_WENO5.jl rename to miniapps/benchmarks/stokes2D/Blankenbach2D/Benchmark2D_WENO5.jl index 06723236..385255ea 100755 --- a/miniapps/benchmarks/Blankenbach2D/Benchmark2D_WENO5.jl +++ b/miniapps/benchmarks/stokes2D/Blankenbach2D/Benchmark2D_WENO5.jl @@ -115,7 +115,6 @@ function main2D(igg; ar=8, ny=16, nx=ny*8, nit = 1e1, figdir="figs2D", save_vtk thermal = ThermalArrays(ni) thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true, right = true, top = false, bot = false), - periodicity = (left = false, right = false, top = false, bot = false), ) # initialize thermal profile @parallel (@idx size(thermal.T)) init_T!(thermal.T, xvi[2]) @@ -153,7 +152,6 @@ function main2D(igg; ar=8, ny=16, nx=ny*8, nit = 1e1, figdir="figs2D", save_vtk # Boundary conditions ------------------------------- flow_bcs = FlowBoundaryConditions(; free_slip = (left = true, right=true, top=true, bot=true), - periodicity = (left = false, right = false, top = false, bot = false), ) flow_bcs!(stokes, flow_bcs) # apply boundary conditions update_halo!(stokes.V.Vx, stokes.V.Vy) diff --git a/miniapps/benchmarks/Blankenbach2D/Benchmark2D_sgd.jl b/miniapps/benchmarks/stokes2D/Blankenbach2D/Benchmark2D_sgd.jl similarity index 99% rename from miniapps/benchmarks/Blankenbach2D/Benchmark2D_sgd.jl rename to miniapps/benchmarks/stokes2D/Blankenbach2D/Benchmark2D_sgd.jl index 5d13f659..0e093229 100755 --- a/miniapps/benchmarks/Blankenbach2D/Benchmark2D_sgd.jl +++ b/miniapps/benchmarks/stokes2D/Blankenbach2D/Benchmark2D_sgd.jl @@ -121,7 +121,6 @@ function main2D(igg; ar=8, ny=16, nx=ny*8, nit = 1e1, figdir="figs2D", save_vtk thermal = ThermalArrays(ni) thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true, right = true, top = false, bot = false), - periodicity = (left = false, right = false, top = false, bot = false), ) # initialize thermal profile @parallel (@idx size(thermal.T)) init_T!(thermal.T, xvi[2]) @@ -159,7 +158,6 @@ function main2D(igg; ar=8, ny=16, nx=ny*8, nit = 1e1, figdir="figs2D", save_vtk # Boundary conditions ------------------------------- flow_bcs = FlowBoundaryConditions(; free_slip = (left = true, right=true, top=true, bot=true), - periodicity = (left = false, right = false, top = false, bot = false), ) flow_bcs!(stokes, flow_bcs) # apply boundary conditions update_halo!(stokes.V.Vx, stokes.V.Vy) diff --git a/miniapps/benchmarks/Blankenbach2D/Benchmark2D_sgd_scaled.jl b/miniapps/benchmarks/stokes2D/Blankenbach2D/Benchmark2D_sgd_scaled.jl similarity index 99% rename from miniapps/benchmarks/Blankenbach2D/Benchmark2D_sgd_scaled.jl rename to miniapps/benchmarks/stokes2D/Blankenbach2D/Benchmark2D_sgd_scaled.jl index 9811aab6..a084e4a3 100755 --- a/miniapps/benchmarks/Blankenbach2D/Benchmark2D_sgd_scaled.jl +++ b/miniapps/benchmarks/stokes2D/Blankenbach2D/Benchmark2D_sgd_scaled.jl @@ -116,7 +116,6 @@ function main2D(igg; ar=8, ny=16, nx=ny*8, nit = 1e1, figdir="figs2D", save_vtk thermal = ThermalArrays(ni) thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true, right = true, top = false, bot = false), - periodicity = (left = false, right = false, top = false, bot = false), ) # initialize thermal profile @parallel (@idx size(thermal.T)) init_T!(thermal.T, xvi[2]) @@ -152,7 +151,6 @@ function main2D(igg; ar=8, ny=16, nx=ny*8, nit = 1e1, figdir="figs2D", save_vtk # Boundary conditions ------------------------------- flow_bcs = FlowBoundaryConditions(; free_slip = (left = true, right=true, top=true, bot=true), - periodicity = (left = false, right = false, top = false, bot = false), ) flow_bcs!(stokes, flow_bcs) # apply boundary conditions update_halo!(stokes.V.Vx, stokes.V.Vy) diff --git a/miniapps/benchmarks/Blankenbach2D/Blankenbach_Rheology.jl b/miniapps/benchmarks/stokes2D/Blankenbach2D/Blankenbach_Rheology.jl similarity index 100% rename from miniapps/benchmarks/Blankenbach2D/Blankenbach_Rheology.jl rename to miniapps/benchmarks/stokes2D/Blankenbach2D/Blankenbach_Rheology.jl diff --git a/miniapps/benchmarks/Blankenbach2D/Blankenbach_Rheology_scaled.jl b/miniapps/benchmarks/stokes2D/Blankenbach2D/Blankenbach_Rheology_scaled.jl similarity index 100% rename from miniapps/benchmarks/Blankenbach2D/Blankenbach_Rheology_scaled.jl rename to miniapps/benchmarks/stokes2D/Blankenbach2D/Blankenbach_Rheology_scaled.jl diff --git a/miniapps/benchmarks/stokes2D/free_surface_stabilization/PlumeFreeSurface_2D.jl b/miniapps/benchmarks/stokes2D/free_surface_stabilization/PlumeFreeSurface_2D.jl index 7ea24726..78f6b10c 100644 --- a/miniapps/benchmarks/stokes2D/free_surface_stabilization/PlumeFreeSurface_2D.jl +++ b/miniapps/benchmarks/stokes2D/free_surface_stabilization/PlumeFreeSurface_2D.jl @@ -37,25 +37,25 @@ end function init_phases!(phases, particles) ni = size(phases) - + @parallel_indices (i, j) function init_phases!(phases, px, py, index) r=100e3 f(x, A, λ) = A * sin(π*x/λ) - + @inbounds for ip in JustRelax.cellaxes(phases) # quick escape JustRelax.@cell(index[ip, i, j]) == 0 && continue x = JustRelax.@cell px[ip, i, j] - depth = -(JustRelax.@cell py[ip, i, j]) + depth = -(JustRelax.@cell py[ip, i, j]) @cell phases[ip, i, j] = 2.0 - + if 0e0 ≤ depth ≤ 100e3 @cell phases[ip, i, j] = 1.0 - else + else @cell phases[ip, i, j] = 2.0 - + if ((x - 250e3)^2 + (depth - 250e3)^2 ≤ r^2) @cell phases[ip, i, j] = 3.0 end @@ -121,7 +121,7 @@ function main(igg, nx, ny) pT, pPhases = init_cell_arrays(particles, Val(2)) particle_args = (pT, pPhases) - # Elliptical temperature anomaly + # Elliptical temperature anomaly init_phases!(pPhases, particles) phase_ratios = PhaseRatio(ni, length(rheology)) @parallel (@idx ni) phase_ratios_center(phase_ratios.center, pPhases) @@ -136,7 +136,7 @@ function main(igg, nx, ny) # TEMPERATURE PROFILE -------------------------------- thermal = ThermalArrays(ni) # ---------------------------------------------------- - + # Buoyancy forces & rheology ρg = @zeros(ni...), @zeros(ni...) η = @ones(ni...) @@ -149,7 +149,7 @@ function main(igg, nx, ny) η_vep = copy(η) # Boundary conditions - flow_bcs = FlowBoundaryConditions(; + flow_bcs = FlowBoundaryConditions(; free_slip = (left = true, right=true, top=true, bot=true), ) @@ -181,7 +181,7 @@ function main(igg, nx, ny) # Stokes solver ---------------- args = (; T = thermal.Tc, P = stokes.P, dt=Inf) - + @parallel (JustRelax.@idx ni) compute_ρg!(ρg[2], phase_ratios.center, rheology, (T=thermal.Tc, P=stokes.P)) @parallel init_P!(stokes.P, ρg[2], xci[2]) @parallel (@idx ni) compute_viscosity!( @@ -212,13 +212,13 @@ function main(igg, nx, ny) # advect particles in space advection_RK!(particles, @velocity(stokes), grid_vx, grid_vy, dt, 2 / 3) # advect particles in memory - move_particles!(particles, xvi, particle_args) + move_particles!(particles, xvi, particle_args) # check if we need to inject particles inject = check_injection(particles) inject && inject_particles_phase!(particles, pPhases, (), (), xvi) # update phase ratios @parallel (@idx ni) phase_ratios_center(phase_ratios.center, pPhases) - + @show it += 1 t += dt @@ -230,7 +230,7 @@ function main(igg, nx, ny) heatmap!(ax, xci[1].*1e-3, xci[2].*1e-3, Array(log10.(η)), colormap = :grayC) arrows!( ax, - xvi[1][1:nt:end-1]./1e3, xvi[2][1:nt:end-1]./1e3, Array.((Vx_v[1:nt:end-1, 1:nt:end-1], Vy_v[1:nt:end-1, 1:nt:end-1]))..., + xvi[1][1:nt:end-1]./1e3, xvi[2][1:nt:end-1]./1e3, Array.((Vx_v[1:nt:end-1, 1:nt:end-1], Vy_v[1:nt:end-1, 1:nt:end-1]))..., lengthscale = 25 / max(maximum(Vx_v), maximum(Vy_v)), color = :red, ) @@ -253,4 +253,4 @@ else igg end -main(igg, nx, ny) \ No newline at end of file +main(igg, nx, ny) diff --git a/miniapps/benchmarks/stokes2D/free_surface_stabilization/RayleighTaylor2D.jl b/miniapps/benchmarks/stokes2D/free_surface_stabilization/RayleighTaylor2D.jl index 6ec170e0..3a13d3fb 100644 --- a/miniapps/benchmarks/stokes2D/free_surface_stabilization/RayleighTaylor2D.jl +++ b/miniapps/benchmarks/stokes2D/free_surface_stabilization/RayleighTaylor2D.jl @@ -30,7 +30,7 @@ macro all_j(A) end @parallel_indices (i, j) function init_P!(P, ρg, z) - P[i, j] = sum(abs(ρg[i, jj] * z[jj]) * z[jj] < 0.0 for jj in j:size(P, 2)) + P[i, j] = sum(abs(ρg[i, jj] * z[jj]) for jj in j:size(P, 2)) return nothing end @@ -68,9 +68,9 @@ end function RT_2D(igg, nx, ny) # Physical domain ------------------------------------ - thick_air = 100e3 # thickness of sticky air layer + thick_air = 100e3 # thickness of sticky air layer ly = 500e3 + thick_air # domain length in y - lx = 500e3 # domain length in x + lx = 500e3 # domain length in x ni = nx, ny # number of cells li = lx, ly # domain length in x- and y- di = @. li / ni # grid step in x- and -y @@ -84,8 +84,8 @@ function RT_2D(igg, nx, ny) # Name = "Air", SetMaterialParams(; Phase = 1, - Density = ConstantDensity(; ρ=1e1), - CompositeRheology = CompositeRheology((LinearViscous(; η=1e19),)), + Density = ConstantDensity(; ρ=1e0), + CompositeRheology = CompositeRheology((LinearViscous(; η=1e16),)), Gravity = ConstantGravity(; g=9.81), ), # Name = "Crust", @@ -120,14 +120,13 @@ function RT_2D(igg, nx, ny) A = 5e3 # Amplitude of the anomaly init_phases!(pPhases, particles, A) phase_ratios = PhaseRatio(ni, length(rheology)) - # @parallel (@idx ni) phase_ratios_center(phase_ratios.center, pPhases) @parallel (@idx ni) phase_ratios_center(phase_ratios.center, particles.coords, xci, di, pPhases) # ---------------------------------------------------- # STOKES --------------------------------------------- # Allocate arrays needed for every Stokes problem stokes = StokesArrays(ni, ViscoElastic) - pt_stokes = PTStokesCoeffs(li, di; ϵ=1e-5, CFL = 0.95 / √2.1) + pt_stokes = PTStokesCoeffs(li, di; ϵ=1e-8, CFL = 0.95 / √2.1) # ---------------------------------------------------- # TEMPERATURE PROFILE -------------------------------- @@ -136,19 +135,20 @@ function RT_2D(igg, nx, ny) # Buoyancy forces & rheology ρg = @zeros(ni...), @zeros(ni...) - η = @zeros(ni...) + η = @ones(ni...) args = (; T = thermal.Tc, P = stokes.P, dt = Inf) @parallel (JustRelax.@idx ni) compute_ρg!(ρg[2], phase_ratios.center, rheology, (T=thermal.Tc, P=stokes.P)) @parallel init_P!(stokes.P, ρg[2], xci[2]) @parallel (@idx ni) compute_viscosity!( - η, 1.0, phase_ratios.center, @strain(stokes)..., args, rheology, (1e19, Inf) + η, 0.0, phase_ratios.center, @strain(stokes)..., args, rheology, (1e19, 1e24) ) η_vep = copy(η) # Boundary conditions flow_bcs = FlowBoundaryConditions(; - free_slip = (left = true, right=true, top=true, bot=false), - no_slip = (left = false, right=false, top=false, bot=true), + free_slip = (left = true, right = true, top = true, bot = false), + no_slip = (left = false, right = false, top = false, bot = true), + free_surface = true, ) # Plot initial T and η profiles @@ -159,7 +159,6 @@ function RT_2D(igg, nx, ny) ax2 = Axis(fig[1,2], aspect = 2/3, title = "log10(η)") scatter!(ax1, Array(ρg[2][:]./9.81), Y./1e3) scatter!(ax2, Array(log10.(η[:])), Y./1e3) - # scatter!(ax2, Array(stokes.P[:]), Y./1e3) ylims!(ax1, minimum(xvi[2])./1e3, 0) ylims!(ax2, minimum(xvi[2])./1e3, 0) hideydecorations!(ax2) @@ -174,7 +173,8 @@ function RT_2D(igg, nx, ny) # Time loop t, it = 0.0, 0 - dt = dt_max = 50e3 * (3600 * 24 * 365.25) + dt = 1e3 * (3600 * 24 * 365.25) + dt_max = 50e3 * (3600 * 24 * 365.25) while it < 500 # run only for 5 Myrs # Stokes solver ---------------- @@ -184,7 +184,6 @@ function RT_2D(igg, nx, ny) @parallel (@idx ni) compute_viscosity!( η, 1.0, phase_ratios.center, @strain(stokes)..., args, rheology, (-Inf, Inf) ) - # η .= mean(η) solve!( stokes, pt_stokes, @@ -198,22 +197,22 @@ function RT_2D(igg, nx, ny) args, dt, igg; - iterMax = 75e3, - iterMin = 15e3, - viscosity_relaxation = 1e-1, - nout = 5e3, - viscosity_cutoff=(-Inf, Inf) + iterMax = 150e3, + iterMin = 5e3, + viscosity_relaxation = 1e-2, + nout = 5e3, + free_surface = true, + viscosity_cutoff = (-Inf, Inf) ) - # dt = if it ≤ 10 - # min(compute_dt(stokes, di) / 2, 1e3 * (3600 * 24 * 365.25)) - # elseif 10 < it ≤ 20 - # min(compute_dt(stokes, di) / 2, 10e3 * (3600 * 24 * 365.25)) - # elseif 20 < it ≤ 30 - # min(compute_dt(stokes, di) / 2, 25e3 * (3600 * 24 * 365.25)) - # else - # min(compute_dt(stokes, di) / 2, dt_max) - # end - dt = min(compute_dt(stokes, di) / 2, dt_max) + dt = if it ≤ 10 + min(compute_dt(stokes, di), 1e3 * (3600 * 24 * 365.25)) + elseif 10 < it ≤ 20 + min(compute_dt(stokes, di), 10e3 * (3600 * 24 * 365.25)) + elseif 20 < it ≤ 30 + min(compute_dt(stokes, di), 25e3 * (3600 * 24 * 365.25)) + else + min(compute_dt(stokes, di), dt_max) + end # ------------------------------ # Advection -------------------- @@ -241,9 +240,8 @@ function RT_2D(igg, nx, ny) pyv = ppy.data[:]./1e3 clr = pPhases.data[:] - fig = Figure(resolution = (900, 900), title = "t = $t") + fig = Figure(size = (900, 900), title = "t = $t") ax = Axis(fig[1,1], aspect = 1, title = " t=$(t/(1e3 * 3600 * 24 *365.25)) Kyrs") - # heatmap!(ax, xci[1].*1e-3, xci[2].*1e-3, Array(log10.(η)), colormap = :grayC) scatter!( ax, pxv, pyv, @@ -251,7 +249,6 @@ function RT_2D(igg, nx, ny) colormap = :lajolla, markersize = 3 ) - # scatter!(ax, pxv, pyv, color=clr, colormap = :grayC) arrows!( ax, xvi[1][1:nt:end-1]./1e3, xvi[2][1:nt:end-1]./1e3, Array.((Vx_v[1:nt:end-1, 1:nt:end-1], Vy_v[1:nt:end-1, 1:nt:end-1]))..., diff --git a/miniapps/benchmarks/stokes2D/shear_heating/Shearheating2D.jl b/miniapps/benchmarks/stokes2D/shear_heating/Shearheating2D.jl index b500b1e7..fa743d57 100644 --- a/miniapps/benchmarks/stokes2D/shear_heating/Shearheating2D.jl +++ b/miniapps/benchmarks/stokes2D/shear_heating/Shearheating2D.jl @@ -102,7 +102,6 @@ function main2D(igg; ar=8, ny=16, nx=ny*8, figdir="figs2D", do_vtk =false) thermal = ThermalArrays(ni) thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true, right = true, top = false, bot = false), - periodicity = (left = false, right = false, top = false, bot = false), ) # Initialize constant temperature @@ -134,7 +133,6 @@ function main2D(igg; ar=8, ny=16, nx=ny*8, figdir="figs2D", do_vtk =false) # Boundary conditions flow_bcs = FlowBoundaryConditions(; free_slip = (left = true, right=true, top=true, bot=true), - periodicity = (left = false, right = false, top = false, bot = false), ) ## Compression and not extension - fix this εbg = 5e-14 diff --git a/miniapps/benchmarks/stokes2D/sinking_block/SinkingBlock2D.jl b/miniapps/benchmarks/stokes2D/sinking_block/SinkingBlock2D.jl index 7cd0d604..581c1e5d 100644 --- a/miniapps/benchmarks/stokes2D/sinking_block/SinkingBlock2D.jl +++ b/miniapps/benchmarks/stokes2D/sinking_block/SinkingBlock2D.jl @@ -146,7 +146,6 @@ function sinking_block2D(igg; ar=8, ny=16, nx=ny*8, figdir="figs2D", thermal_per # Boundary conditions flow_bcs = FlowBoundaryConditions(; free_slip = (left = true, right = true, top = true, bot = true), - periodicity = (left = false, right = false, top = false, bot = false), ) flow_bcs!(stokes, flow_bcs) # apply boundary conditions update_halo!(stokes.V.Vx, stokes.V.Vy) diff --git a/miniapps/benchmarks/stokes3D/burstedde/Burstedde.jl b/miniapps/benchmarks/stokes3D/burstedde/Burstedde.jl index 64fcd03c..6b654e3b 100644 --- a/miniapps/benchmarks/stokes3D/burstedde/Burstedde.jl +++ b/miniapps/benchmarks/stokes3D/burstedde/Burstedde.jl @@ -211,9 +211,6 @@ function burstedde(; nx=16, ny=16, nz=16, init_MPI=true, finalize_MPI=false) flow_bcs = FlowBoundaryConditions(; free_slip = (left=false, right=false, top=false, bot=false, back=false, front=false), no_slip = (left=false, right=false, top=false, bot=false, back=false, front=false), - periodicity = ( - left=false, right=false, top=false, bot=false, back=false, front=false - ), ) # impose analytical velociity at the boundaries of the domain velocity!(stokes, xci, xvi, di) diff --git a/miniapps/benchmarks/stokes3D/shear_band/ShearBand3D.jl b/miniapps/benchmarks/stokes3D/shear_band/ShearBand3D.jl index 0baf07f0..27fb2bae 100644 --- a/miniapps/benchmarks/stokes3D/shear_band/ShearBand3D.jl +++ b/miniapps/benchmarks/stokes3D/shear_band/ShearBand3D.jl @@ -106,7 +106,6 @@ function main(igg; nx=64, ny=64, nz=64, figdir="model_figs") flow_bcs = FlowBoundaryConditions(; free_slip = (left = true , right = true , top = true , bot = true , back = true , front = true), no_slip = (left = false, right = false, top = false, bot = false, back = false, front = false), - periodicity = (left = false, right = false, top = false, bot = false, back = false, front = false), ) stokes.V.Vx .= PTArray([ x*εbg/2 for x in xvi[1], _ in 1:ny+2, _ in 1:nz+2]) stokes.V.Vy .= PTArray([ y*εbg/2 for _ in 1:nx+2, y in xvi[2], _ in 1:nz+2]) diff --git a/miniapps/benchmarks/stokes3D/shear_heating/Shearheating3D.jl b/miniapps/benchmarks/stokes3D/shear_heating/Shearheating3D.jl index 8ddca4b5..c123799c 100644 --- a/miniapps/benchmarks/stokes3D/shear_heating/Shearheating3D.jl +++ b/miniapps/benchmarks/stokes3D/shear_heating/Shearheating3D.jl @@ -90,7 +90,6 @@ function main3D(igg; ar=8, ny=16, nx=ny*8, nz=ny*8, figdir="figs3D", do_vtk =fal thermal = ThermalArrays(ni) thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true , right = true , top = false, bot = false, front = true , back = true), - periodicity = (left = false, right = false, top = false, bot = false, front = false, back = false), ) # Initialize constant temperature @@ -123,7 +122,6 @@ function main3D(igg; ar=8, ny=16, nx=ny*8, nz=ny*8, figdir="figs3D", do_vtk =fal flow_bcs = FlowBoundaryConditions(; free_slip = (left = true , right = true , top = true , bot = true , front = true , back = true ), no_slip = (left = false, right = false, top = false, bot = false, front = false, back = false), - periodicity = (left = false, right = false, top = false, bot = false, front = false, back = false), ) ## Compression and not extension - fix this εbg = 5e-14 diff --git a/miniapps/benchmarks/stokes3D/solvi/SolVi3D.jl b/miniapps/benchmarks/stokes3D/solvi/SolVi3D.jl index a969d73f..7d6ba67c 100644 --- a/miniapps/benchmarks/stokes3D/solvi/SolVi3D.jl +++ b/miniapps/benchmarks/stokes3D/solvi/SolVi3D.jl @@ -93,9 +93,6 @@ function solVi3D(; flow_bcs = FlowBoundaryConditions(; free_slip = (left=false, right=false, top=false, bot=false, back=false, front=false), no_slip = (left=false, right=false, top=false, bot=false, back=false, front=false), - periodicity = ( - left=false, right=false, top=false, bot=false, back=false, front=false - ), ) flow_bcs!(stokes, flow_bcs) # apply boundary conditions update_halo!(stokes.V.Vx, stokes.V.Vy, stokes.V.Vz) diff --git a/miniapps/benchmarks/stokes3D/taylor_green/TaylorGreen.jl b/miniapps/benchmarks/stokes3D/taylor_green/TaylorGreen.jl index af560aa9..ea943937 100644 --- a/miniapps/benchmarks/stokes3D/taylor_green/TaylorGreen.jl +++ b/miniapps/benchmarks/stokes3D/taylor_green/TaylorGreen.jl @@ -116,9 +116,6 @@ function taylorGreen(; nx=16, ny=16, nz=16, init_MPI=true, finalize_MPI=false) flow_bcs = FlowBoundaryConditions(; free_slip=(left=false, right=false, top=false, bot=false, back=false, front=false), no_slip=(left=false, right=false, top=false, bot=false, back=false, front=false), - periodicity=( - left=false, right=false, top=false, bot=false, back=false, front=false - ), ) # impose analytical velocity at the boundaries of the domain velocity!(stokes, xci, xvi) diff --git a/miniapps/benchmarks/thermal_diffusion/diffusion/diffusion3D.jl b/miniapps/benchmarks/thermal_diffusion/diffusion/diffusion3D.jl index d4e248e6..4d33b3af 100644 --- a/miniapps/benchmarks/thermal_diffusion/diffusion/diffusion3D.jl +++ b/miniapps/benchmarks/thermal_diffusion/diffusion/diffusion3D.jl @@ -87,7 +87,6 @@ function diffusion_3D(; pt_thermal = PTThermalCoeffs(K, ρCp, dt, di, li; CFL = 0.75 / √3.1) thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true , right = true , top = false, bot = false, front = true , back = true), - periodicity = (left = false, right = false, top = false, bot = false, front = false, back = false), ) @parallel (@idx size(thermal.T)) init_T!(thermal.T, xvi[3]) diff --git a/miniapps/benchmarks/thermal_diffusion/diffusion/diffusion3D_MPI.jl b/miniapps/benchmarks/thermal_diffusion/diffusion/diffusion3D_MPI.jl index a802c5d1..4d151cf8 100644 --- a/miniapps/benchmarks/thermal_diffusion/diffusion/diffusion3D_MPI.jl +++ b/miniapps/benchmarks/thermal_diffusion/diffusion/diffusion3D_MPI.jl @@ -89,7 +89,6 @@ function diffusion_3D(; pt_thermal = PTThermalCoeffs(K, ρCp, dt, di, li; CFL = 0.75 / √3.1) thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true , right = true , top = false, bot = false, front = true , back = true), - periodicity = (left = false, right = false, top = false, bot = false, front = false, back = false), ) @parallel (@idx size(thermal.T)) init_T!(thermal.T, xvi[3], lz) diff --git a/miniapps/benchmarks/thermal_diffusion/diffusion/diffusion3D_multiphase.jl b/miniapps/benchmarks/thermal_diffusion/diffusion/diffusion3D_multiphase.jl index e0e261b8..011de511 100644 --- a/miniapps/benchmarks/thermal_diffusion/diffusion/diffusion3D_multiphase.jl +++ b/miniapps/benchmarks/thermal_diffusion/diffusion/diffusion3D_multiphase.jl @@ -129,7 +129,6 @@ function diffusion_3D(; # Boundary conditions thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true , right = true , top = false, bot = false, front = true , back = true), - periodicity = (left = false, right = false, top = false, bot = false, front = false, back = false), ) @parallel (@idx size(thermal.T)) init_T!(thermal.T, xvi[3]) diff --git a/miniapps/convection/GlobalConvection2D_Upwind.jl b/miniapps/convection/GlobalConvection2D_Upwind.jl index 45d8725e..564ea436 100644 --- a/miniapps/convection/GlobalConvection2D_Upwind.jl +++ b/miniapps/convection/GlobalConvection2D_Upwind.jl @@ -139,7 +139,6 @@ function thermal_convection2D(; ar=8, ny=16, nx=ny*8, figdir="figs2D", thermal_p thermal = ThermalArrays(ni) thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true, right = true, top = false, bot = false), - periodicity = (left = false, right = false, top = false, bot = false), ) # initialize thermal profile - Half space cooling adiabat = 0.3 # adiabatic gradient @@ -187,7 +186,6 @@ function thermal_convection2D(; ar=8, ny=16, nx=ny*8, figdir="figs2D", thermal_p # Boundary conditions flow_bcs = FlowBoundaryConditions(; free_slip = (left = true, right=true, top=true, bot=true), - periodicity = (left = false, right = false, top = false, bot = false), ) flow_bcs!(stokes, flow_bcs) # apply boundary conditions update_halo!(stokes.V.Vx, stokes.V.Vy) diff --git a/miniapps/convection/GlobalConvection2D_WENO5.jl b/miniapps/convection/GlobalConvection2D_WENO5.jl index f78513ec..383a0f06 100644 --- a/miniapps/convection/GlobalConvection2D_WENO5.jl +++ b/miniapps/convection/GlobalConvection2D_WENO5.jl @@ -140,7 +140,6 @@ function thermal_convection2D(igg; ar=8, ny=16, nx=ny*8, figdir="figs2D", therma thermal = ThermalArrays(ni) thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true, right = true, top = false, bot = false), - periodicity = (left = false, right = false, top = false, bot = false), ) # initialize thermal profile - Half space cooling adiabat = 0.3 # adiabatic gradient @@ -194,7 +193,6 @@ function thermal_convection2D(igg; ar=8, ny=16, nx=ny*8, figdir="figs2D", therma # Boundary conditions flow_bcs = FlowBoundaryConditions(; free_slip = (left = true, right=true, top=true, bot=true), - periodicity = (left = false, right = false, top = false, bot = false), ) flow_bcs!(stokes, flow_bcs) # apply boundary conditions update_halo!(stokes.V.Vx, stokes.V.Vy) diff --git a/miniapps/convection/GlobalConvection2D_WENO5_MPI.jl b/miniapps/convection/GlobalConvection2D_WENO5_MPI.jl index 56f0873e..8a89e6ea 100644 --- a/miniapps/convection/GlobalConvection2D_WENO5_MPI.jl +++ b/miniapps/convection/GlobalConvection2D_WENO5_MPI.jl @@ -140,7 +140,6 @@ function thermal_convection2D(igg; ar=8, ny=16, nx=ny*8, figdir="figs2D", therma thermal = ThermalArrays(ni) thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true, right = true, top = false, bot = false), - periodicity = (left = false, right = false, top = false, bot = false), ) # initialize thermal profile - Half space cooling adiabat = 0.3 # adiabatic gradient @@ -195,7 +194,6 @@ function thermal_convection2D(igg; ar=8, ny=16, nx=ny*8, figdir="figs2D", therma # Boundary conditions flow_bcs = FlowBoundaryConditions(; free_slip = (left = true , right = true , top = true , bot = true), - periodicity = (left = false, right = false, top = false, bot = false), ) flow_bcs!(stokes, flow_bcs) # apply boundary conditions update_halo!(@velocity(stokes)...) diff --git a/miniapps/convection/GlobalConvection3D_Upwind.jl b/miniapps/convection/GlobalConvection3D_Upwind.jl index e1a20083..130e6e46 100644 --- a/miniapps/convection/GlobalConvection3D_Upwind.jl +++ b/miniapps/convection/GlobalConvection3D_Upwind.jl @@ -142,7 +142,6 @@ function thermal_convection3D(; ar=8, nz=16, nx=ny*8, ny=nx, figdir="figs3D", th thermal = ThermalArrays(ni) thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true, right = true, top = false, bot = false, front=true, back=true), - periodicity = (left = false, right = false, top = false, bot = false, front=false, back=false), ) # initialize thermal profile - Half space cooling adiabat = 0.3 # adiabatic gradient @@ -192,7 +191,6 @@ function thermal_convection3D(; ar=8, nz=16, nx=ny*8, ny=nx, figdir="figs3D", th flow_bcs = FlowBoundaryConditions(; free_slip = (left=true , right=true , top=true , bot=true , front=true , back=true ), no_slip = (left=false, right=false, top=false, bot=false, front=false, back=false), - periodicity = (left=false, right=false, top=false, bot=false, front=false, back=false), ) flow_bcs!(stokes, flow_bcs) # apply boundary conditions update_halo!(stokes.V.Vx, stokes.V.Vy, stokes.V.Vz) diff --git a/miniapps/convection/Particles2D/Layered_convection2D.jl b/miniapps/convection/Particles2D/Layered_convection2D.jl index d375d61e..17aebf90 100644 --- a/miniapps/convection/Particles2D/Layered_convection2D.jl +++ b/miniapps/convection/Particles2D/Layered_convection2D.jl @@ -144,7 +144,6 @@ function main2D(igg; ar=8, ny=16, nx=ny*8, figdir="figs2D", do_vtk =false) thermal = ThermalArrays(ni) thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true, right = true, top = false, bot = false), - periodicity = (left = false, right = false, top = false, bot = false), ) # initialize thermal profile - Half space cooling @parallel (@idx ni .+ 1) init_T!(thermal.T, xvi[2], thick_air) diff --git a/miniapps/convection/Particles2D_nonDim/Layered_convection2D.jl b/miniapps/convection/Particles2D_nonDim/Layered_convection2D.jl index 50e646e4..61a0afdb 100644 --- a/miniapps/convection/Particles2D_nonDim/Layered_convection2D.jl +++ b/miniapps/convection/Particles2D_nonDim/Layered_convection2D.jl @@ -150,7 +150,6 @@ function main2D(igg; ar=8, ny=16, nx=ny*8, figdir="figs2D", do_vtk =false) thermal = ThermalArrays(ni) thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true, right = true, top = false, bot = false), - periodicity = (left = false, right = false, top = false, bot = false), ) # initialize thermal profile - Half space cooling @parallel (@idx ni .+ 1) init_T!(thermal.T, xvi[2], thick_air, CharDim) @@ -184,7 +183,6 @@ function main2D(igg; ar=8, ny=16, nx=ny*8, figdir="figs2D", do_vtk =false) # Boundary conditions flow_bcs = FlowBoundaryConditions(; free_slip = (left = true, right=true, top=true, bot=true), - periodicity = (left = false, right = false, top = false, bot = false), ) flow_bcs!(stokes, flow_bcs) # apply boundary conditions update_halo!(stokes.V.Vx, stokes.V.Vy) diff --git a/miniapps/convection/Particles3D/Layered_convection3D.jl b/miniapps/convection/Particles3D/Layered_convection3D.jl index 9a92bc80..ab28d49e 100644 --- a/miniapps/convection/Particles3D/Layered_convection3D.jl +++ b/miniapps/convection/Particles3D/Layered_convection3D.jl @@ -130,7 +130,6 @@ function main3D(igg; ar=1, nx=16, ny=16, nz=16, figdir="figs3D", do_vtk =false) thermal = ThermalArrays(ni) thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true , right = true , top = false, bot = false, front = true , back = true), - periodicity = (left = false, right = false, top = false, bot = false, front = false, back = false), ) # initialize thermal profile - Half space cooling @parallel init_T!(thermal.T, xvi[3]) @@ -162,7 +161,6 @@ function main3D(igg; ar=1, nx=16, ny=16, nz=16, figdir="figs3D", do_vtk =false) flow_bcs = FlowBoundaryConditions(; free_slip = (left = true , right = true , top = true , bot = true , front = true , back = true ), no_slip = (left = false, right = false, top = false, bot = false, front = false, back = false), - periodicity = (left = false, right = false, top = false, bot = false, front = false, back = false), ) flow_bcs!(stokes, flow_bcs) # apply boundary conditions update_halo!(stokes.V.Vx, stokes.V.Vy, stokes.V.Vz) @@ -170,7 +168,7 @@ function main3D(igg; ar=1, nx=16, ny=16, nz=16, figdir="figs3D", do_vtk =false) # IO ------------------------------------------------- # if it does not exist, make folder where figures are stored if do_vtk - vtk_dir = figdir*"\\vtk" + vtk_dir = joinpath(figdir, "vtk") take(vtk_dir) end take(figdir) @@ -354,4 +352,4 @@ end # (Path)/folder where output data and figures are stored figdir = "Plume3D_$n" -main3D(igg; figdir = figdir, ar = ar, nx = nx, ny = ny, nz = nz, do_vtk = do_vtk); +# main3D(igg; figdir = figdir, ar = ar, nx = nx, ny = ny, nz = nz, do_vtk = do_vtk); diff --git a/src/MetaJustRelax.jl b/src/MetaJustRelax.jl index 2bf96618..9b4ee1cb 100644 --- a/src/MetaJustRelax.jl +++ b/src/MetaJustRelax.jl @@ -114,7 +114,8 @@ function environment!(model::PS_Setup{T,N}) where {T,N} free_slip_x!, free_slip_y!, free_slip_z!, - apply_free_slip! + apply_free_slip!, + free_surface_bcs! include(joinpath(@__DIR__, "phases/phases.jl")) export PhaseRatio, fn_ratio, phase_ratios_center diff --git a/src/boundaryconditions/BoundaryConditions.jl b/src/boundaryconditions/BoundaryConditions.jl index 9a79a705..b96aa008 100644 --- a/src/boundaryconditions/BoundaryConditions.jl +++ b/src/boundaryconditions/BoundaryConditions.jl @@ -2,31 +2,28 @@ abstract type AbstractBoundaryConditions end struct TemperatureBoundaryConditions{T,nD} <: AbstractBoundaryConditions no_flux::T - periodicity::T function TemperatureBoundaryConditions(; - no_flux::T=(left=true, right=false, top=false, bot=false), - periodicity::T=(left=false, right=false, top=false, bot=false), + no_flux::T=(left=true, right=false, top=false, bot=false) ) where {T} - @assert length(no_flux) === length(periodicity) nD = length(no_flux) == 4 ? 2 : 3 - return new{T,nD}(no_flux, periodicity) + return new{T,nD}(no_flux) end end struct FlowBoundaryConditions{T,nD} <: AbstractBoundaryConditions no_slip::T free_slip::T - periodicity::T + free_surface::Bool function FlowBoundaryConditions(; no_slip::T=(left=false, right=false, top=false, bot=false), free_slip::T=(left=true, right=true, top=true, bot=true), - periodicity::T=(left=false, right=false, top=false, bot=false), + free_surface::Bool=false, ) where {T} - @assert length(no_slip) === length(free_slip) === length(periodicity) + @assert length(no_slip) === length(free_slip) nD = length(no_slip) == 4 ? 2 : 3 - return new{T,nD}(no_slip, free_slip, periodicity) + return new{T,nD}(no_slip, free_slip, free_surface) end end @@ -55,8 +52,6 @@ function thermal_bcs!(T, bcs::TemperatureBoundaryConditions) # no flux boundary conditions do_bc(bcs.no_flux) && (@parallel (@idx n) free_slip!(T, bcs.no_flux)) - # periodic conditions - do_bc(bcs.periodicity) && (@parallel (@idx n) periodic_boundaries!(T, bcs.periodicity)) return nothing end @@ -66,24 +61,22 @@ end Apply the prescribed flow boundary conditions `bc` on the `stokes` """ + +flow_bcs!(stokes, bcs::FlowBoundaryConditions) = _flow_bcs!(bcs, @velocity(stokes)) +function flow_bcs!(bcs::FlowBoundaryConditions, V::Vararg{T,N}) where {T,N} + return _flow_bcs!(bcs, tuple(V...)) +end + function _flow_bcs!(bcs::FlowBoundaryConditions, V) n = bc_index(V) # no slip boundary conditions do_bc(bcs.no_slip) && (@parallel (@idx n) no_slip!(V..., bcs.no_slip)) # free slip boundary conditions do_bc(bcs.free_slip) && (@parallel (@idx n) free_slip!(V..., bcs.free_slip)) - # periodic conditions - do_bc(bcs.periodicity) && - (@parallel (@idx n) periodic_boundaries!(V..., bcs.periodicity)) return nothing end -flow_bcs!(stokes, bcs::FlowBoundaryConditions) = _flow_bcs!(bcs, @velocity(stokes)) -function flow_bcs!(bcs::FlowBoundaryConditions, V::Vararg{T,N}) where {T,N} - return _flow_bcs!(bcs, tuple(V...)) -end - # BOUNDARY CONDITIONS KERNELS @parallel_indices (i) function no_slip!(Ax, Ay, bc) @@ -216,54 +209,93 @@ end return nothing end -@parallel_indices (i) function periodic_boundaries!(Ax, Ay, bc) - @inbounds begin - if i ≤ size(Ax, 1) - bc.bot && (Ax[i, 1] = Ax[i, end - 1]) - bc.top && (Ax[i, end] = Ax[i, 2]) - end - if i ≤ size(Ay, 2) - bc.left && (Ay[1, i] = Ay[end - 1, i]) - bc.right && (Ay[end, i] = Ay[2, i]) - end +function free_surface_bcs!( + stokes, bcs::FlowBoundaryConditions, η, rheology, phase_ratios, dt, di +) + indices_range(Vx, Vy) = @idx (size(Vy, 2) - 1) + indices_range(Vx, Vy, Vz) = @idx (size(Vz, 1) - 2, size(Vz, 2) - 2) + + V = @velocity(stokes) + n = indices_range(V...) + + if bcs.free_surface + # apply boundary conditions + @parallel n FreeSurface_Vy!( + V..., + stokes.P, + stokes.P0, + stokes.τ_o.yy, + η, + rheology, + phase_ratios.center, + dt, + di..., + ) end - return nothing end -@parallel_indices (i) function periodic_boundaries!( - T::_T, bc -) where {_T<:AbstractArray{<:Any,2}} - @inbounds begin - if i ≤ size(T, 1) - bc.bot && (T[i, 1] = T[i, end - 1]) - bc.top && (T[i, end] = T[i, 2]) - end - if i ≤ size(T, 2) - bc.left && (T[1, i] = T[end - 1, i]) - bc.right && (T[end, i] = T[2, i]) - end +function free_surface_bcs!(τ::SymmetricTensor, bcs::FlowBoundaryConditions) + if bcs.free_surface + @views τ.yy[:, end] .= 0.0 end +end + +@parallel_indices (i) function FreeSurface_Vy!( + Vx::AbstractArray{T,2}, + Vy::AbstractArray{T,2}, + P::AbstractArray{T,2}, + P_old::AbstractArray{T,2}, + τyy_old::AbstractArray{T,2}, + η::AbstractArray{T,2}, + rheology, + phase_ratios, + dt::T, + dx::T, + dy::T, +) where {T} + phase = @inbounds phase_ratios[i, end] + Gdt = fn_ratio(get_shear_modulus, rheology, phase) * dt + Vy[i + 1, end] = + Vy[i + 1, end - 1] + + 3.0 / 2.0 * + ( + P[i, end] / (2.0 * η[i, end]) - + (τyy_old[i, end] + P_old[i, end]) / (2.0 * Gdt) + + inv(3.0) * (Vx[i + 1, end - 1] - Vx[i, end - 1]) * inv(dx) + ) * + dy return nothing end -@parallel_indices (i, j) function periodic_boundaries!( - T::_T, bc -) where {_T<:AbstractArray{<:Any,3}} - nx, ny, nz = size(T) - @inbounds begin - if i ≤ nx && j ≤ ny - bc.bot && (T[i, j, 1] = T[i, j, end - 1]) - bc.top && (T[i, j, end] = T[i, j, 2]) - end - if i ≤ ny && j ≤ nz - bc.left && (T[1, i, j] = T[end - 1, i, j]) - bc.right && (T[end, i, j] = T[2, i, j]) - end - if i ≤ nx && j ≤ nz - bc.front && (T[i, 1, j] = T[i, end - 1, j]) - bc.back && (T[i, end, j] = T[i, 2, j]) - end - end +@parallel_indices (i, j) function FreeSurface_Vy!( + Vx::AbstractArray{T,3}, + Vy::AbstractArray{T,3}, + Vz::AbstractArray{T,3}, + P::AbstractArray{T,3}, + P_old::AbstractArray{T,3}, + τyy_old::AbstractArray{T,3}, + η::AbstractArray{T,3}, + rheology, + phase_ratios, + dt::T, + dx::T, + dy::T, + dz::T, +) where {T} + phase = @inbounds phase_ratios[i, j, end] + Gdt = fn_ratio(get_shear_modulus, rheology, phase) * dt + Vz[i + 1, j + 1, end] = + Vz[i + 1, j + 1, end - 1] + + 3.0 / 2.0 * + ( + P[i, j, end] / (2.0 * η[i, j, end]) - + (τyy_old[i, j, end] + P_old[i, j, end]) / (2.0 * Gdt) + + inv(3.0) * ( + (Vx[i + 1, j + 1, end - 1] - Vx[i, j + 1, end - 1]) * inv(dx) + + (Vy[i + 1, j + 1, end - 1] - Vy[i + 1, j, end - 1]) * inv(dy) + ) + ) * + dz return nothing end diff --git a/src/stokes/Stokes2D.jl b/src/stokes/Stokes2D.jl index e2bb80f7..e9dbc685 100644 --- a/src/stokes/Stokes2D.jl +++ b/src/stokes/Stokes2D.jl @@ -335,6 +335,7 @@ function JustRelax.solve!( nout=500, b_width=(4, 4, 0), verbose=true, + free_surface=false, ) where {A,B,C,D,T} # unpack @@ -368,6 +369,8 @@ function JustRelax.solve!( wtime0 = 0.0 λ = @zeros(ni...) θ = @zeros(ni...) + Vx_on_Vy = @zeros(size(stokes.V.Vy)) + while iter < 2 || (err > ϵ && iter ≤ iterMax) wtime0 += @elapsed begin @parallel (@idx ni) compute_∇V!(stokes.∇V, @velocity(stokes)..., _di...) @@ -408,16 +411,21 @@ function JustRelax.solve!( @parallel center2vertex!(stokes.τ.xy, stokes.τ.xy_c) 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 + ) + @hide_communication b_width begin # communication/computation overlap @parallel compute_V!( @velocity(stokes)..., + Vx_on_Vy, θ, @stress(stokes)..., pt_stokes.ηdτ, ρg..., ητ, _di..., - dt, + dt * free_surface, ) # apply boundary conditions flow_bcs!(stokes, flow_bcs) @@ -431,11 +439,12 @@ function JustRelax.solve!( stokes.R.Rx, stokes.R.Ry, @velocity(stokes)..., + Vx_on_Vy, stokes.P, @stress(stokes)..., ρg..., _di..., - dt, + dt * free_surface, ) errs = maximum.((abs.(stokes.R.Rx), abs.(stokes.R.Ry), abs.(stokes.R.RP))) @@ -565,6 +574,11 @@ function JustRelax.solve!( θ_dτ, ) + # stokes.P[1, 1] = stokes.P[2, 1] + # stokes.P[end, 1] = stokes.P[end - 1, 1] + # stokes.P[1, end] = stokes.P[2, end] + # stokes.P[end, end] = stokes.P[end - 1, end] + if rem(iter, 5) == 0 @parallel (@idx ni) compute_ρg!(ρg[2], phase_ratios.center, rheology, args) end @@ -605,6 +619,7 @@ function JustRelax.solve!( dt, θ_dτ, ) + free_surface_bcs!(stokes.τ, flow_bcs) @parallel center2vertex!(stokes.τ.xy, stokes.τ.xy_c) update_halo!(stokes.τ.xy) @@ -626,7 +641,9 @@ function JustRelax.solve!( dt * free_surface, ) # apply boundary conditions + free_surface_bcs!(stokes, flow_bcs, η, rheology, phase_ratios, dt, di) flow_bcs!(stokes, flow_bcs) + update_halo!(stokes.V.Vx, stokes.V.Vy) end end @@ -679,6 +696,7 @@ function JustRelax.solve!( end stokes.P .= θ + # @views stokes.P .-= stokes.P[:, end] # accumulate plastic strain tensor @parallel (@idx ni) accumulate_tensor!(stokes.EII_pl, @tensor_center(stokes.ε_pl), dt) diff --git a/src/stokes/VelocityKernels.jl b/src/stokes/VelocityKernels.jl index be0801ba..0ba63e20 100644 --- a/src/stokes/VelocityKernels.jl +++ b/src/stokes/VelocityKernels.jl @@ -88,7 +88,7 @@ end return nothing end -## VELOCITY +## VELOCITY @parallel_indices (i, j) function compute_V!( Vx::AbstractArray{T,2}, Vy, P, τxx, τyy, τxy, ηdτ, ρgx, ρgy, ητ, _dx, _dy diff --git a/test/test_boundary_conditions2D.jl b/test/test_boundary_conditions2D.jl index 87896a75..e0d9dd0b 100644 --- a/test/test_boundary_conditions2D.jl +++ b/test/test_boundary_conditions2D.jl @@ -1,31 +1,16 @@ -using Test, Suppressor using JustRelax - +using Test, Suppressor model = PS_Setup(:cpu, Float64, 2) environment!(model) @testset "Boundary Conditions" begin @suppress 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 , :] - # 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) @@ -39,7 +24,6 @@ environment!(model) 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 @@ -52,28 +36,14 @@ environment!(model) @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 @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) @@ -86,7 +56,6 @@ environment!(model) 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) diff --git a/test/test_diffusion3D.jl b/test/test_diffusion3D.jl index cbba7b08..19661f01 100644 --- a/test/test_diffusion3D.jl +++ b/test/test_diffusion3D.jl @@ -88,7 +88,6 @@ function diffusion_3D(; pt_thermal = PTThermalCoeffs(K, ρCp, dt, di, li; CFL = 0.75 / √3.1) thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true , right = true , top = false, bot = false, front = true , back = true), - periodicity = (left = false, right = false, top = false, bot = false, front = false, back = false), ) @parallel (@idx size(thermal.T)) init_T!(thermal.T, xvi[3]) diff --git a/test/test_diffusion3D_multiphase.jl b/test/test_diffusion3D_multiphase.jl index 52b8398d..24b3bca5 100644 --- a/test/test_diffusion3D_multiphase.jl +++ b/test/test_diffusion3D_multiphase.jl @@ -132,7 +132,6 @@ function diffusion_3D(; # Boundary conditions thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true , right = true , top = false, bot = false, front = true , back = true), - periodicity = (left = false, right = false, top = false, bot = false, front = false, back = false), ) @parallel (@idx size(thermal.T)) init_T!(thermal.T, xvi[3]) diff --git a/test/test_shearheating2D.jl b/test/test_shearheating2D.jl index ec9d93af..df580a99 100644 --- a/test/test_shearheating2D.jl +++ b/test/test_shearheating2D.jl @@ -109,7 +109,6 @@ function Shearheating2D() thermal = ThermalArrays(ni) thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true, right = true, top = false, bot = false), - periodicity = (left = false, right = false, top = false, bot = false), ) # Initialize constant temperature @@ -141,7 +140,6 @@ function Shearheating2D() # Boundary conditions flow_bcs = FlowBoundaryConditions(; free_slip = (left = true, right=true, top=true, bot=true), - periodicity = (left = false, right = false, top = false, bot = false), ) ## Compression and not extension - fix this εbg = 5e-14 diff --git a/test/test_shearheating3D.jl b/test/test_shearheating3D.jl index 8188f3d0..0e1b8647 100644 --- a/test/test_shearheating3D.jl +++ b/test/test_shearheating3D.jl @@ -95,7 +95,6 @@ function Shearheating3D(nx=16, ny=16, nz=16) thermal = ThermalArrays(ni) thermal_bc = TemperatureBoundaryConditions(; no_flux = (left = true , right = true , top = false, bot = false, front = true , back = true), - periodicity = (left = false, right = false, top = false, bot = false, front = false, back = false), ) # Initialize constant temperature @@ -128,7 +127,6 @@ function Shearheating3D(nx=16, ny=16, nz=16) flow_bcs = FlowBoundaryConditions(; free_slip = (left = true , right = true , top = true , bot = true , front = true , back = true ), no_slip = (left = false, right = false, top = false, bot = false, front = false, back = false), - periodicity = (left = false, right = false, top = false, bot = false, front = false, back = false), ) ## Compression and not extension - fix this εbg = 5e-14 diff --git a/test/test_sinking_block.jl b/test/test_sinking_block.jl index 6d502e55..06c3f079 100644 --- a/test/test_sinking_block.jl +++ b/test/test_sinking_block.jl @@ -155,7 +155,6 @@ function Sinking_Block2D() # Boundary conditions flow_bcs = FlowBoundaryConditions(; free_slip = (left = true, right = true, top = true, bot = true), - periodicity = (left = false, right = false, top = false, bot = false), ) flow_bcs!(stokes, flow_bcs) # apply boundary conditions update_halo!(stokes.V.Vx, stokes.V.Vy)