From 2ed4dabeb770e3ca9caf13d23751736d44fe15d7 Mon Sep 17 00:00:00 2001 From: Duretz Thibault Date: Sat, 8 Oct 2022 11:58:14 +0200 Subject: [PATCH 01/49] add examples of usage of GeoPrams in basic PT codes --- GeoParams_PT_examples/.DS_Store | Bin 0 -> 6148 bytes GeoParams_PT_examples/.vscode/settings.json | 2 + GeoParams_PT_examples/Project.toml | 11 + .../src/Stokes2D_ve_bench_GeoParams.jl | 132 ++++++++++ .../src/Stokes2D_ve_inclusion_GeoParams.jl | 142 +++++++++++ .../src/Stokes2D_vep_bench_GeoParams.jl | 142 +++++++++++ .../src/Stokes2D_vep_reg_vc_GeoParams.jl | 227 ++++++++++++++++++ 7 files changed, 656 insertions(+) create mode 100644 GeoParams_PT_examples/.DS_Store create mode 100644 GeoParams_PT_examples/.vscode/settings.json create mode 100644 GeoParams_PT_examples/Project.toml create mode 100644 GeoParams_PT_examples/src/Stokes2D_ve_bench_GeoParams.jl create mode 100644 GeoParams_PT_examples/src/Stokes2D_ve_inclusion_GeoParams.jl create mode 100644 GeoParams_PT_examples/src/Stokes2D_vep_bench_GeoParams.jl create mode 100644 GeoParams_PT_examples/src/Stokes2D_vep_reg_vc_GeoParams.jl diff --git a/GeoParams_PT_examples/.DS_Store b/GeoParams_PT_examples/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0"] +version = "0.1.0" + +[deps] +GeoParams = "e018b62d-d9de-4a26-8697-af89c310ae38" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" diff --git a/GeoParams_PT_examples/src/Stokes2D_ve_bench_GeoParams.jl b/GeoParams_PT_examples/src/Stokes2D_ve_bench_GeoParams.jl new file mode 100644 index 0000000..19bac9e --- /dev/null +++ b/GeoParams_PT_examples/src/Stokes2D_ve_bench_GeoParams.jl @@ -0,0 +1,132 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra, GeoParams +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +# Rheology +@views function UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, dt ) + ε̇iic = ones(size(ε̇xx)) + ε̇iiv = ones(size(ε̇xy)) + τii0c = sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) + τii0v = zeros(size(ε̇xy)) + τii0v[2:end-1,2:end-1] = sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) + Phase = 1 + # Centroids + for i in eachindex(τxx) + v = MatParam[Phase].CompositeRheology[1] + args = (; τII_old = τii0c[i], dt=dt) + η_eff = computeViscosity_εII(v, ε̇iic[i], args) + τxx[i] = 2*η_eff*ε̇xx[i] + τyy[i] = 2*η_eff*ε̇yy[i] + end + # Vertices + for i in eachindex(τxy) + v = MatParam[Phase].CompositeRheology[1] + args = (; τII_old = τii0v[i], dt=dt) + η_eff = computeViscosity_εII(v, ε̇iiv[i], args) + τxy[i] = 2*η_eff*ε̇xy[i] + end +end +# 2D Stokes routine +@views function Stokes2D_ve() + # Physics + Lx, Ly = 1.0, 1.0 # domain size + ξ = 10.0 # Maxwell relaxation time + η0 = 1.0 # viscous viscosity + G = 1.0 # elastic shear modulus + εbg = 1.0 # background strain-rate + + MatParam = (SetMaterialParams(Name="Matrix", Phase=1, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G),LinearViscous(η=η0))),) + + # Numerics + nt = 50 # number of time steps + ncx, ncy = 31, 31 # numerical grid resolution + Vdmp = 4.0 # convergence acceleration (damping) + Ptsc = 8.0 # iterative time step limiter + ε = 1e-6 # nonlinear tolerence + iterMax = 1e5 # max number of iters + nout = 200 # check frequency + # Preprocessing + dx, dy = Lx/ncx, Ly/ncy + dt = η0/(G*ξ + 1e-15) + # Array initialisation + Pt = zeros(Dat, ncx ,ncy ) + ∇V = zeros(Dat, ncx ,ncy ) + Vx = zeros(Dat, ncx+1,ncy ) + Vy = zeros(Dat, ncx ,ncy+1) + ε̇xx = zeros(Dat, ncx ,ncy ) + ε̇yy = zeros(Dat, ncx ,ncy ) + ε̇xy = zeros(Dat, ncx+1,ncy+1) + τxx = zeros(Dat, ncx ,ncy ) + τyy = zeros(Dat, ncx ,ncy ) + τxy = zeros(Dat, ncx+1,ncy+1) + τxx0 = zeros(Dat, ncx ,ncy ) + τyy0 = zeros(Dat, ncx ,ncy ) + τxy0 = zeros(Dat, ncx+1,ncy+1) + Rx = zeros(Dat, ncx-1,ncy ) + Ry = zeros(Dat, ncx ,ncy-1) + dVxdt = zeros(Dat, ncx-1,ncy ) + dVydt = zeros(Dat, ncx ,ncy-1) + Rog = zeros(Dat, ncx ,ncy ) + Xc = ξ*ones(Dat, ncx, ncy) + Xv = ξ*ones(Dat, ncx+1, ncy+1) + ηc = η0*ones(Dat, ncx, ncy) + ηv = η0*ones(Dat, ncx+1, ncy+1) + # Initialisation + xc, yc = LinRange(dx/2, Lx-dx/2, ncx), LinRange(dy/2, Ly-dy/2, ncy) + xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) + (Xvx,Yvx) = ([x for x=xv,y=yc], [y for x=xv,y=yc]) + (Xvy,Yvy) = ([x for x=xc,y=yv], [y for x=xc,y=yv]) + Vx .= εbg.*Xvx + Vy .= .-εbg.*Yvy + dtVx = min(dx,dy)^2.0./av_xa(ηc)./4.1 + dtVy = min(dx,dy)^2.0./av_ya(ηc)./4.1 + dtPt = 4.1*ηc/max(ncx,ncy)/Ptsc + # Time loop + t=0.0; evo_t=[]; evo_τxx=[] + for it = 1:nt + iter=1; err=2*ε; err_evo1=[]; err_evo2=[]; + τxx0.=τxx; τyy0.=τyy; τxy0.=τxy + while (err>ε && iter<=iterMax) + # divergence - pressure + ∇V .= diff(Vx, dims=1)./dx .+ diff(Vy, dims=2)./dy + Pt .= Pt .- dtPt.*∇V + # strain rates + ε̇xx .= diff(Vx, dims=1)./dx .- 1.0/3.0*∇V + ε̇yy .= diff(Vy, dims=2)./dy .- 1.0/3.0*∇V + ε̇xy[2:end-1,2:end-1] .= 0.5.*(diff(Vx[2:end-1,:], dims=2)./dy .+ diff(Vy[:,2:end-1], dims=1)./dx) + # stresses + UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, dt ) + # velocities + Rx .= .-diff(Pt, dims=1)./dx .+ diff(τxx, dims=1)./dx .+ diff(τxy[2:end-1,:], dims=2)./dy + Ry .= .-diff(Pt, dims=2)./dy .+ diff(τyy, dims=2)./dy .+ diff(τxy[:,2:end-1], dims=1)./dx .+ av_ya(Rog) + dVxdt .= dVxdt.*(1-Vdmp/ncx) .+ Rx + dVydt .= dVydt.*(1-Vdmp/ncy) .+ Ry + Vx[2:end-1,:] .= Vx[2:end-1,:] .+ dVxdt.*dtVx + Vy[:,2:end-1] .= Vy[:,2:end-1] .+ dVydt.*dtVy + # convergence check + if mod(iter, nout)==0 + norm_Rx = norm(Rx)/length(Rx); norm_Ry = norm(Ry)/length(Ry); norm_∇V = norm(∇V)/length(∇V) + err = maximum([norm_Rx, norm_Ry, norm_∇V]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %d, iter = %d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V) + + end + iter+=1; global itg=iter + end + t = t + dt + push!(evo_t, t); push!(evo_τxx, maximum(τxx)) + # Plotting + p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") + p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p3 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewidth=2.0) # analytical solution + display(plot(p1, p2, p3)) + end + return +end + +Stokes2D_ve() diff --git a/GeoParams_PT_examples/src/Stokes2D_ve_inclusion_GeoParams.jl b/GeoParams_PT_examples/src/Stokes2D_ve_inclusion_GeoParams.jl new file mode 100644 index 0000000..d619413 --- /dev/null +++ b/GeoParams_PT_examples/src/Stokes2D_ve_inclusion_GeoParams.jl @@ -0,0 +1,142 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra, GeoParams +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +# Rheology +@views function UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, dt, Phasec, Phasev ) + ε̇iic = ones(size(ε̇xx)) + ε̇iiv = ones(size(ε̇xy)) + τii0c = sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) + τii0v = zeros(size(ε̇xy)) + τii0v[2:end-1,2:end-1] = sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) + # Centroids + for i in eachindex(τxx) + v = MatParam[Phasec[i]].CompositeRheology[1] + args = (; τII_old = τii0c[i], dt=dt) + η_eff = computeViscosity_εII(v, ε̇iic[i], args) + τxx[i] = 2*η_eff*ε̇xx[i] + τyy[i] = 2*η_eff*ε̇yy[i] + end + # Vertices + for i in eachindex(τxy) + v = MatParam[Phasev[i]].CompositeRheology[1] + args = (; τII_old = τii0v[i], dt=dt) + η_eff = computeViscosity_εII(v, ε̇iiv[i], args) + τxy[i] = 2*η_eff*ε̇xy[i] + end +end +# 2D Stokes routine +@views function Stokes2D_ve() + # Physics + Lx, Ly = 1.0, 1.0 # domain size + ξ = 10.0 # Maxwell relaxation time + η0 = 1.0 # viscous viscosity + G = 1.0 # elastic shear modulus + εbg = 1.0 # background strain-rate + radi = 0.01 + + MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G),LinearViscous(η=η0))), + SetMaterialParams(Name="Inclusion", Phase=2, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G*0.25),LinearViscous(η=η0))), + ) + + # Numerics + nt = 1 # number of time steps + ncx, ncy = 31, 31 # numerical grid resolution + Vdmp = 9.0 # convergence acceleration (damping) + Ptsc = 10.0 # iterative time step limiter + ε = 1e-6 # nonlinear tolerence + iterMax = 1e5 # max number of iters + nout = 500 # check frequency + # Preprocessing + dx, dy = Lx/ncx, Ly/ncy + dt = η0/(G*ξ + 1e-15) + # Array initialisation + Pt = zeros(Dat, ncx ,ncy ) + ∇V = zeros(Dat, ncx ,ncy ) + Vx = zeros(Dat, ncx+1,ncy ) + Vy = zeros(Dat, ncx ,ncy+1) + ε̇xx = zeros(Dat, ncx ,ncy ) + ε̇yy = zeros(Dat, ncx ,ncy ) + ε̇xy = zeros(Dat, ncx+1,ncy+1) + τxx = zeros(Dat, ncx ,ncy ) + τyy = zeros(Dat, ncx ,ncy ) + τxy = zeros(Dat, ncx+1,ncy+1) + τxx0 = zeros(Dat, ncx ,ncy ) + τyy0 = zeros(Dat, ncx ,ncy ) + τxy0 = zeros(Dat, ncx+1,ncy+1) + Rx = zeros(Dat, ncx-1,ncy ) + Ry = zeros(Dat, ncx ,ncy-1) + dVxdt = zeros(Dat, ncx-1,ncy ) + dVydt = zeros(Dat, ncx ,ncy-1) + Rog = zeros(Dat, ncx ,ncy ) + Xc = ξ*ones(Dat, ncx, ncy) + Xv = ξ*ones(Dat, ncx+1, ncy+1) + ηc = η0*ones(Dat, ncx, ncy) + ηv = η0*ones(Dat, ncx+1, ncy+1) + Phasec = ones(Int, ncx ,ncy ) + Phasev = ones(Int, ncx+1,ncy+1) + xc, yc = LinRange(dx/2, Lx-dx/2, ncx), LinRange(dy/2, Ly-dy/2, ncy) + xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + Phasec[radc.ε && iter<=iterMax) + # divergence - pressure + ∇V .= diff(Vx, dims=1)./dx .+ diff(Vy, dims=2)./dy + Pt .= Pt .- dtPt.*∇V + # strain rates + ε̇xx .= diff(Vx, dims=1)./dx .- 1.0/3.0*∇V + ε̇yy .= diff(Vy, dims=2)./dy .- 1.0/3.0*∇V + ε̇xy[2:end-1,2:end-1] .= 0.5.*(diff(Vx[2:end-1,:], dims=2)./dy .+ diff(Vy[:,2:end-1], dims=1)./dx) + # stresses + UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, dt, Phasec, Phasev ) + # velocities + Rx .= .-diff(Pt, dims=1)./dx .+ diff(τxx, dims=1)./dx .+ diff(τxy[2:end-1,:], dims=2)./dy + Ry .= .-diff(Pt, dims=2)./dy .+ diff(τyy, dims=2)./dy .+ diff(τxy[:,2:end-1], dims=1)./dx .+ av_ya(Rog) + dVxdt .= dVxdt.*(1-Vdmp/ncx) .+ Rx + dVydt .= dVydt.*(1-Vdmp/ncy) .+ Ry + Vx[2:end-1,:] .= Vx[2:end-1,:] .+ dVxdt.*dtVx + Vy[:,2:end-1] .= Vy[:,2:end-1] .+ dVydt.*dtVy + # convergence check + if mod(iter, nout)==0 + norm_Rx = norm(Rx)/length(Rx); norm_Ry = norm(Ry)/length(Ry); norm_∇V = norm(∇V)/length(∇V) + err = maximum([norm_Rx, norm_Ry, norm_∇V]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %d, iter = %d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V) + end + iter+=1; global itg=iter + end + t = t + dt + push!(evo_t, t); push!(evo_τxx, maximum(τxx)) + # Plotting + p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") + p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p3 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewidth=2.0) # analytical solution + display(plot(p1, p2, p3)) + end + return +end + +Stokes2D_ve() diff --git a/GeoParams_PT_examples/src/Stokes2D_vep_bench_GeoParams.jl b/GeoParams_PT_examples/src/Stokes2D_vep_bench_GeoParams.jl new file mode 100644 index 0000000..9a65f9f --- /dev/null +++ b/GeoParams_PT_examples/src/Stokes2D_vep_bench_GeoParams.jl @@ -0,0 +1,142 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra, GeoParams +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +# Rheology +# @views function UpdateStress!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, ηc, ηv, Xc, Xv ) +# τxx .= τxx0.*Xc./(Xc.+1.0) .+ 2.0.*ηc.*ε̇xx./(Xc.+1.0) +# τyy .= τyy0.*Xc./(Xc.+1.0) .+ 2.0.*ηc.*ε̇yy./(Xc.+1.0) +# τxy .= τxy0.*Xv./(Xv.+1.0) .+ 2.0.*ηv.*ε̇xy./(Xv.+1.0) +# end +@views function UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, dt ) + ε̇iic = ones(size(ε̇xx)) # dummy strain rate (linear) + ε̇iiv = ones(size(ε̇xy)) # dummy strain rate (linear) + τii0c = sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) + τii0v = zeros(size(ε̇xy)) + τii0v[2:end-1,2:end-1] = sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) + # Update centroids + Phase = 1; + for i in eachindex(τxx) + v = MatParam[Phase].CompositeRheology[1] + args = (; τII_old = τii0c[i], dt=dt, P=0.0) + η_eff = computeViscosity_εII(v, ε̇iic[i], args) + τxx[i] = 2*η_eff*ε̇xx[i] + τyy[i] = 2*η_eff*ε̇yy[i] + end + # Update vertices + for i in eachindex(τxy) + v = MatParam[Phase].CompositeRheology[1] + args = (; τII_old = τii0v[i], dt=dt) + η_eff = computeViscosity_εII(v, ε̇iiv[i], args, P=0.0) + τxy[i] = 2*η_eff*ε̇xy[i] + end +end + +# 2D Stokes routine +@views function Stokes2D_ve() + # Physics + Lx, Ly = 1.0, 1.0 # domain size + ξ = 10.0 # Maxwell relaxation time + η0 = 1.0 # viscous viscosity + G = 1.0 # elastic shear modulus + εbg = 1.0 # background strain-rate + + MatParam = (SetMaterialParams(Name="Matrix", Phase=1, + CompositeRheology = CompositeRheology( + ConstantElasticity(G=G), + LinearViscous(η=η0), + DruckerPrager(C=1.5, ϕ=0))),) + + # Numerics + nt = 50 # number of time steps + ncx, ncy = 31, 31 # numerical grid resolution + Vdmp = 4.0 # convergence acceleration (damping) + Ptsc = 8.0 # iterative time step limiter + ε = 1e-6 # nonlinear tolerence + iterMax = 1e5 # max number of iters + nout = 200 # check frequency + # Preprocessing + dx, dy = Lx/ncx, Ly/ncy + dt = η0/(G*ξ + 1e-15) + # Array initialisation + Pt = zeros(Dat, ncx ,ncy ) + ∇V = zeros(Dat, ncx ,ncy ) + Vx = zeros(Dat, ncx+1,ncy ) + Vy = zeros(Dat, ncx ,ncy+1) + ε̇xx = zeros(Dat, ncx ,ncy ) + ε̇yy = zeros(Dat, ncx ,ncy ) + ε̇xy = zeros(Dat, ncx+1,ncy+1) + τxx = zeros(Dat, ncx ,ncy ) + τyy = zeros(Dat, ncx ,ncy ) + τxy = zeros(Dat, ncx+1,ncy+1) + τxx0 = zeros(Dat, ncx ,ncy ) + τyy0 = zeros(Dat, ncx ,ncy ) + τxy0 = zeros(Dat, ncx+1,ncy+1) + Rx = zeros(Dat, ncx-1,ncy ) + Ry = zeros(Dat, ncx ,ncy-1) + dVxdt = zeros(Dat, ncx-1,ncy ) + dVydt = zeros(Dat, ncx ,ncy-1) + Rog = zeros(Dat, ncx ,ncy ) + Xc = ξ*ones(Dat, ncx, ncy) + Xv = ξ*ones(Dat, ncx+1, ncy+1) + ηc = η0*ones(Dat, ncx, ncy) + ηv = η0*ones(Dat, ncx+1, ncy+1) + # Initialisation + xc, yc = LinRange(dx/2, Lx-dx/2, ncx), LinRange(dy/2, Ly-dy/2, ncy) + xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) + (Xvx,Yvx) = ([x for x=xv,y=yc], [y for x=xv,y=yc]) + (Xvy,Yvy) = ([x for x=xc,y=yv], [y for x=xc,y=yv]) + Vx .= εbg.*Xvx + Vy .= .-εbg.*Yvy + dtVx = min(dx,dy)^2.0./av_xa(ηc)./4.1 + dtVy = min(dx,dy)^2.0./av_ya(ηc)./4.1 + dtPt = 4.1*ηc/max(ncx,ncy)/Ptsc + # Time loop + t=0.0; evo_t=[]; evo_τxx=[] + for it = 1:nt + iter=1; err=2*ε; err_evo1=[]; err_evo2=[]; + τxx0.=τxx; τyy0.=τyy; τxy0.=τxy + while (err>ε && iter<=iterMax) + # divergence - pressure + ∇V .= diff(Vx, dims=1)./dx .+ diff(Vy, dims=2)./dy + Pt .= Pt .- dtPt.*∇V + # strain rates + ε̇xx .= diff(Vx, dims=1)./dx .- 1.0/3.0*∇V + ε̇yy .= diff(Vy, dims=2)./dy .- 1.0/3.0*∇V + ε̇xy[2:end-1,2:end-1] .= 0.5.*(diff(Vx[2:end-1,:], dims=2)./dy .+ diff(Vy[:,2:end-1], dims=1)./dx) + # stresses + UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, dt ) + # UpdateStress!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, ηc, ηv, Xc, Xv ) + # velocities + Rx .= .-diff(Pt, dims=1)./dx .+ diff(τxx, dims=1)./dx .+ diff(τxy[2:end-1,:], dims=2)./dy + Ry .= .-diff(Pt, dims=2)./dy .+ diff(τyy, dims=2)./dy .+ diff(τxy[:,2:end-1], dims=1)./dx .+ av_ya(Rog) + dVxdt .= dVxdt.*(1-Vdmp/ncx) .+ Rx + dVydt .= dVydt.*(1-Vdmp/ncy) .+ Ry + Vx[2:end-1,:] .= Vx[2:end-1,:] .+ dVxdt.*dtVx + Vy[:,2:end-1] .= Vy[:,2:end-1] .+ dVydt.*dtVy + # convergence check + if mod(iter, nout)==0 + norm_Rx = norm(Rx)/length(Rx); norm_Ry = norm(Ry)/length(Ry); norm_∇V = norm(∇V)/length(∇V) + err = maximum([norm_Rx, norm_Ry, norm_∇V]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %d, iter = %d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V) + + end + iter+=1; global itg=iter + end + t = t + dt + push!(evo_t, t); push!(evo_τxx, maximum(τxx)) + # Plotting + p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") + p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p3 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewidth=2.0) # analytical solution + display(plot(p1, p2, p3)) + end + return +end + +Stokes2D_ve() diff --git a/GeoParams_PT_examples/src/Stokes2D_vep_reg_vc_GeoParams.jl b/GeoParams_PT_examples/src/Stokes2D_vep_reg_vc_GeoParams.jl new file mode 100644 index 0000000..3794779 --- /dev/null +++ b/GeoParams_PT_examples/src/Stokes2D_vep_reg_vc_GeoParams.jl @@ -0,0 +1,227 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +# Rheology +function UpdateStressVEVP!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xyc, ε̇xxv, ε̇yyv, ε̇xy, τxx0, τyy0, τxy0, τxxv0, τyyv0, τxyv0, ε̇xx1, ε̇yy1, ε̇xy1, ε̇xxv1, ε̇yyv1, ε̇xyv1, τii, τiiv, Pt, Ptv, τ_y, sinϕ, η_ve, η_vev, η_reg, dQdτxx, dQdτyy, dQdτxy, dQdτxxv, dQdτyyv, dQdτxyv, η_e, η_ev, ε̇ii, ε̇iiv ) + # visco-elastic strain rates + ε̇xx1 .= ε̇xx .+ τxx0 ./2.0./η_e + ε̇yy1 .= ε̇yy .+ τyy0 ./2.0./η_e + ε̇xy1 .= ε̇xyc .+ τxy0 ./2.0./η_e + ε̇ii .= sqrt.(0.5*(ε̇xx1.^2 .+ ε̇yy1.^2) .+ ε̇xy1.^2) + # visco-elastic strain rates vertices + ε̇xxv1 .= ε̇xxv .+ τxxv0./2.0./η_ev + ε̇yyv1 .= ε̇yyv .+ τyyv0./2.0./η_ev + ε̇xyv1 .= ε̇xyv .+ τxyv0./2.0./η_ev + ε̇iiv .= sqrt.(0.5*(ε̇xxv1.^2 .+ ε̇yyv1.^2) .+ ε̇xyv1.^2) + # trial stress + τxx .= 2.0.*η_ve.*ε̇xx1 + τyy .= 2.0.*η_ve.*ε̇yy1 + τxy .= 2.0.*η_ve.*ε̇xy1 + τii .= sqrt.(0.5*(τxx.^2 .+ τyy.^2) .+ τxy.^2) + # trial stress vertices + τxxv .= 2.0.*η_vev.*ε̇xxv1 + τyyv .= 2.0.*η_vev.*ε̇yyv1 + τxyv .= 2.0.*η_vev.*ε̇xyv1 + τiiv .= sqrt.(0.5*(τxxv.^2 .+ τyyv.^2) .+ τxyv.^2) + # yield function + F .= τii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(η_ve .+ η_reg) + dQdτxx .= 0.5.*τxx./τii + dQdτyy .= 0.5.*τyy./τii + dQdτxy .= τxy./τii + # yield function vertices + Fv .= τiiv .- τ_y .- Ptv.*sinϕ + Plav .= 0.0 + Plav .= Fv .> 0.0 + λv .= Plav.*Fv./(η_vev .+ η_reg) + dQdτxxv.= 0.5.*τxxv./τiiv + dQdτyyv.= 0.5.*τyyv./τiiv + dQdτxyv.= τxyv./τiiv + # plastic corrections + τxx .= 2.0.*η_ve.*(ε̇xx1 .- λ.*dQdτxx) + τyy .= 2.0.*η_ve.*(ε̇yy1 .- λ.*dQdτyy) + τxy .= 2.0.*η_ve.*(ε̇xy1 .- 0.5.*λ.*dQdτxy) + τii .= sqrt.(0.5*(τxx.^2 .+ τyy.^2) .+ τxy.^2) + Fchk .= τii .- τ_y .- Pt.*sinϕ .- λ.*η_reg + η_vep .= τii./2.0./ε̇ii + # plastic corrections vertices + τxxv .= 2.0.*η_vev.*(ε̇xxv1 .- λv.*dQdτxxv) + τyyv .= 2.0.*η_vev.*(ε̇yyv1 .- λv.*dQdτyyv) + τxyv .= 2.0.*η_vev.*(ε̇xyv1 .- 0.5.*λv.*dQdτxyv) + τiiv .= sqrt.(0.5*(τxxv.^2 .+ τyyv.^2) .+ τxyv.^2) + Fchkv .= τiiv .- τ_y .- Ptv.*sinϕ .- λv.*η_reg + η_vepv .= τiiv./2.0./ε̇iiv +end +# 2D Stokes routine +@views function Stokes2D_vep() + do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) + η_reg = 1.2e-2 # regularisation "viscosity" + # Physics + Lx, Ly = 1.0, 1.0 # domain size + radi = 0.01 # inclusion radius + τ_y = 1.6 # yield stress. If do_DP=true, τ_y stand for the cohesion: c*cos(ϕ) + sinϕ = sind(30)*do_DP # sinus of the friction angle + η0 = 1.0 # viscous viscosity + G0 = 1.0 # elastic shear modulus + Gi = G0/(6.0-4.0*do_DP) # elastic shear modulus perturbation + εbg = 1.0 # background strain-rate + # Numerics + nt = 10 # number of time steps + ncx, ncy = 63, 63 # numerical grid resolution + Vdmp = 4.0 # convergence acceleration (damping) + Vsc = 2.0 # iterative time step limiter + Ptsc = 6.0 # iterative time step limiter + ε = 1e-6 # nonlinear tolerence + iterMax = 3e4 # max number of iters + nout = 200 # check frequency + # Preprocessing + dx, dy = Lx/ncx, Ly/ncy + dt = η0/G0/4.0 # assumes Maxwell time of 4 + # Array initialisation + Pt = zeros(Dat, ncx ,ncy ) + ∇V = zeros(Dat, ncx ,ncy ) + Vx = zeros(Dat, ncx+1,ncy ) + Vy = zeros(Dat, ncx ,ncy+1) + ε̇xx = zeros(Dat, ncx ,ncy ) + ε̇yy = zeros(Dat, ncx ,ncy ) + ε̇xyv = zeros(Dat, ncx+1,ncy+1) + ε̇xy = zeros(Dat, ncx ,ncy ) + ε̇xx1 = zeros(Dat, ncx ,ncy ) + ε̇yy1 = zeros(Dat, ncx ,ncy ) + ε̇xy1 = zeros(Dat, ncx ,ncy ) + ε̇xyv1 = zeros(Dat, ncx+1,ncy+1) + τxx = zeros(Dat, ncx ,ncy ) + τyy = zeros(Dat, ncx ,ncy ) + τxy = zeros(Dat, ncx ,ncy ) + τxyv = zeros(Dat, ncx+1,ncy+1) + τxx0 = zeros(Dat, ncx ,ncy ) + τyy0 = zeros(Dat, ncx ,ncy ) + τxy0 = zeros(Dat, ncx ,ncy ) + τxyv0 = zeros(Dat, ncx+1,ncy+1) + # for vertices implementation + Ptv = zeros(Dat, ncx+1,ncy+1) + ε̇xxv = zeros(Dat, ncx+1,ncy+1) + ε̇yyv = zeros(Dat, ncx+1,ncy+1) + ε̇xxv1 = zeros(Dat, ncx+1,ncy+1) + ε̇yyv1 = zeros(Dat, ncx+1,ncy+1) + τxxv = zeros(Dat, ncx+1,ncy+1) + τyyv = zeros(Dat, ncx+1,ncy+1) + τxxv0 = zeros(Dat, ncx+1,ncy+1) + τyyv0 = zeros(Dat, ncx+1,ncy+1) + Fchkv = zeros(Dat, ncx+1,ncy+1) + Fv = zeros(Dat, ncx+1,ncy+1) + Plav = zeros(Dat, ncx+1,ncy+1) + λv = zeros(Dat, ncx+1,ncy+1) + dQdτxxv = zeros(Dat, ncx+1,ncy+1) + dQdτyyv = zeros(Dat, ncx+1,ncy+1) + dQdτxyv = zeros(Dat, ncx+1,ncy+1) + τiiv = zeros(Dat, ncx+1,ncy+1) + ε̇iiv = zeros(Dat, ncx+1,ncy+1) + # for vertices implementation + τii = zeros(Dat, ncx ,ncy ) + ε̇ii = zeros(Dat, ncx ,ncy ) + F = zeros(Dat, ncx ,ncy ) + Fchk = zeros(Dat, ncx ,ncy ) + Pla = zeros(Dat, ncx ,ncy ) + λ = zeros(Dat, ncx ,ncy ) + dQdτxx = zeros(Dat, ncx ,ncy ) + dQdτyy = zeros(Dat, ncx ,ncy ) + dQdτxy = zeros(Dat, ncx ,ncy ) + Rx = zeros(Dat, ncx-1,ncy ) + Ry = zeros(Dat, ncx ,ncy-1) + dVxdt = zeros(Dat, ncx-1,ncy ) + dVydt = zeros(Dat, ncx ,ncy-1) + dtPt = zeros(Dat, ncx ,ncy ) + dtVx = zeros(Dat, ncx-1,ncy ) + dtVy = zeros(Dat, ncx ,ncy-1) + Rog = zeros(Dat, ncx ,ncy ) + η_v = η0*ones(Dat, ncx ,ncy ) + η_e = dt*G0*ones(Dat, ncx ,ncy ) + η_ev = dt*G0*ones(Dat, ncx+1,ncy+1) + η_ve = ones(Dat, ncx ,ncy ) + η_vep = ones(Dat, ncx ,ncy ) + η_vepv = ones(Dat, ncx+1,ncy+1) + η_vev = ones(Dat, ncx+1,ncy+1) # for vertices implementation + η_vv = η0*ones(Dat, ncx+1,ncy+1) # for vertices implementation + # Initial condition + xc, yc = LinRange(dx/2, Lx-dx/2, ncx), LinRange(dy/2, Ly-dy/2, ncy) + xc, yc = LinRange(dx/2, Lx-dx/2, ncx), LinRange(dy/2, Ly-dy/2, ncy) + xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) + (Xvx,Yvx) = ([x for x=xv,y=yc], [y for x=xv,y=yc]) + (Xvy,Yvy) = ([x for x=xc,y=yv], [y for x=xc,y=yv]) + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + Phasec = ones(Int, ncx ,ncy ) + Phasev = ones(Int, ncx+1,ncy+1) + Phasec[radc.ε && iter<=iterMax) + # divergence - pressure + ∇V .= diff(Vx, dims=1)./dx .+ diff(Vy, dims=2)./dy + Pt .= Pt .- dtPt.*∇V + # strain rates + ε̇xx .= diff(Vx, dims=1)./dx .- 1.0/3.0*∇V + ε̇yy .= diff(Vy, dims=2)./dy .- 1.0/3.0*∇V + ε̇xyv[2:end-1,2:end-1] .= 0.5.*(diff(Vx[2:end-1,:], dims=2)./dy .+ diff(Vy[:,2:end-1], dims=1)./dx) + ε̇xxv[2:end-1,2:end-1] .= av(ε̇xx); ε̇xxv[1,:].=ε̇xxv[2,:]; ε̇xxv[end,:].=ε̇xxv[end-1,:]; ε̇xxv[:,1].=ε̇xxv[:,2]; ε̇xxv[:,end].=ε̇xxv[:,end-1] + ε̇yyv[2:end-1,2:end-1] .= av(ε̇yy); ε̇yyv[1,:].=ε̇yyv[2,:]; ε̇yyv[end,:].=ε̇yyv[end-1,:]; ε̇yyv[:,1].=ε̇yyv[:,2]; ε̇yyv[:,end].=ε̇yyv[:,end-1] + Ptv[2:end-1,2:end-1] .= av(Pt); Ptv[1,:].= Ptv[2,:]; Ptv[end,:].= Ptv[end-1,:]; Ptv[:,1].= Ptv[:,2]; Ptv[:,end].= Ptv[:,end-1] + ε̇xy .= av(ε̇xyv) + # Rheology + UpdateStressVEVP!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, ε̇xxv, ε̇yyv, ε̇xy, τxx0, τyy0, τxy0, τxxv0, τyyv0, τxyv0, ε̇xx1, ε̇yy1, ε̇xy1, ε̇xxv1, ε̇yyv1, ε̇xyv1, τii, τiiv, Pt, Ptv, τ_y, sinϕ, η_ve, η_vev, η_reg, dQdτxx, dQdτyy, dQdτxy, dQdτxxv, dQdτyyv, dQdτxyv, η_e, η_ev, ε̇ii, ε̇iiv ) + # PT timestep + dtVx .= min(dx,dy)^2.0./av_xa(η_vep)./4.1./Vsc + dtVy .= min(dx,dy)^2.0./av_ya(η_vep)./4.1./Vsc + dtPt .= 4.1.*η_vep./max(ncx,ncy)./Ptsc + # velocities + Rx .= .-diff(Pt, dims=1)./dx .+ diff(τxx, dims=1)./dx .+ diff(τxyv[2:end-1,:], dims=2)./dy + Ry .= .-diff(Pt, dims=2)./dy .+ diff(τyy, dims=2)./dy .+ diff(τxyv[:,2:end-1], dims=1)./dx .+ av_ya(Rog) + dVxdt .= dVxdt.*(1-Vdmp/ncx) .+ Rx + dVydt .= dVydt.*(1-Vdmp/ncy) .+ Ry + Vx[2:end-1,:] .= Vx[2:end-1,:] .+ dVxdt.*dtVx + Vy[:,2:end-1] .= Vy[:,2:end-1] .+ dVydt.*dtVy + # convergence check + if mod(iter, nout)==0 + norm_Rx = norm(Rx)/length(Rx); norm_Ry = norm(Ry)/length(Ry); norm_∇V = norm(∇V)/length(∇V) + err = maximum([norm_Rx, norm_Ry, norm_∇V]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %d, iter = %d, err = %1.2e norm[Rx=%1.2e, Ry=%1.2e, ∇V=%1.2e] (Fchk=%1.2e - Fchkv=%1.2e) \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V, maximum(Fchk), maximum(Fchkv)) + end + iter+=1; itg=iter + end + t = t + dt + push!(evo_t, t); push!(evo_τxx, maximum(τxx)) + # Plotting + p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") + # p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p2 = heatmap(xc, yc, η_vep' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="η_vep") + p3 = heatmap(xc, yc, τii' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="τii") + p4 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G0./η0)), linewidth=2.0) # analytical solution for VE loading + plot!(evo_t, 2.0.*εbg.*η0.*ones(size(evo_t)), linewidth=2.0) # viscous flow stress + if !do_DP plot!(evo_t, τ_y*ones(size(evo_t)), linewidth=2.0) end # von Mises yield stress + display(plot(p1, p2, p3, p4)) + end + return +end + +Stokes2D_vep() From 802b50d823ecd7cec967281bb55bfb6f5da54212 Mon Sep 17 00:00:00 2001 From: Duretz Thibault Date: Sat, 8 Oct 2022 16:38:48 +0200 Subject: [PATCH 02/49] improved damping stategy --- .../src/Stokes2D_VE_bench_GeoParams.jl | 152 +++++++++++++++++ .../src/Stokes2D_VE_inclusion_GeoParams.jl | 158 ++++++++++++++++++ .../src/Stokes2D_ve_bench_GeoParams.jl | 132 --------------- .../src/Stokes2D_ve_inclusion_GeoParams.jl | 142 ---------------- 4 files changed, 310 insertions(+), 274 deletions(-) create mode 100644 GeoParams_PT_examples/src/Stokes2D_VE_bench_GeoParams.jl create mode 100644 GeoParams_PT_examples/src/Stokes2D_VE_inclusion_GeoParams.jl delete mode 100644 GeoParams_PT_examples/src/Stokes2D_ve_bench_GeoParams.jl delete mode 100644 GeoParams_PT_examples/src/Stokes2D_ve_inclusion_GeoParams.jl diff --git a/GeoParams_PT_examples/src/Stokes2D_VE_bench_GeoParams.jl b/GeoParams_PT_examples/src/Stokes2D_VE_bench_GeoParams.jl new file mode 100644 index 0000000..3b7b7f2 --- /dev/null +++ b/GeoParams_PT_examples/src/Stokes2D_VE_bench_GeoParams.jl @@ -0,0 +1,152 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra, GeoParams +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +# Rheology +@views function UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt ) + ε̇iic = ones(size(ε̇xx)) + ε̇iiv = ones(size(ε̇xy)) + τii0c = sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) + τii0v = zeros(size(ε̇xy)) + τii0v[2:end-1,2:end-1] = sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) + Phase = 1 + # Centroids + for i in eachindex(τxx) + v = MatParam[Phase].CompositeRheology[1] + args = (; τII_old = τii0c[i], dt=Δt) + η_eff = computeViscosity_εII(v, ε̇iic[i], args) + τxx[i] = 2*η_eff*ε̇xx[i] + τyy[i] = 2*η_eff*ε̇yy[i] + end + # Vertices + for i in eachindex(τxy) + v = MatParam[Phase].CompositeRheology[1] + args = (; τII_old = τii0v[i], dt=Δt) + η_eff = computeViscosity_εII(v, ε̇iiv[i], args) + τxy[i] = 2*η_eff*ε̇xy[i] + end +end +# 2D Stokes routine +@views function Stokes2D_VE_benchmark() + # Physics + Lx, Ly = 1.0, 1.0 # domain size + ξ = 10.0 # Maxwell relaxation time + η0 = 1.0 # viscous viscosity + G = 1.0 # elastic shear modulus + εbg = 1.0 # background strain-rate + + MatParam = (SetMaterialParams(Name="Matrix", Phase=1, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G),LinearViscous(η=η0))),) + + # Numerics + nt = 1 # number of time steps + ncx, ncy = 31, 31 # numerical grid resolution + ε = 1e-6 # nonlinear tolerence + iterMax = 1e5 # max number of iters + nout = 200 # check frequency + # Iterative parameters ------------------------------------------- + Reopt = 5π + cfl = 0.5 + ρ = 1#cfl*Reopt/ncx + # Preprocessing + Δx, Δy = Lx/ncx, Ly/ncy + Δt = η0/(G*ξ + 1e-15) + # Array initialisation + Pt = zeros(Dat, ncx ,ncy ) + ∇V = zeros(Dat, ncx ,ncy ) + Vx = zeros(Dat, ncx+1,ncy+2) + Vy = zeros(Dat, ncx+2,ncy+1) + ε̇xx = zeros(Dat, ncx ,ncy ) + ε̇yy = zeros(Dat, ncx ,ncy ) + ε̇xy = zeros(Dat, ncx+1,ncy+1) + τxx = zeros(Dat, ncx ,ncy ) + τyy = zeros(Dat, ncx ,ncy ) + τxy = zeros(Dat, ncx+1,ncy+1) + τxx0 = zeros(Dat, ncx ,ncy ) + τyy0 = zeros(Dat, ncx ,ncy ) + τxy0 = zeros(Dat, ncx+1,ncy+1) + Rx = zeros(Dat, ncx+1,ncy ) + Ry = zeros(Dat, ncx ,ncy+1) + Rp = zeros(Dat, ncx ,ncy ) + dVxdτ = zeros(Dat, ncx+1,ncy ) + dVydτ = zeros(Dat, ncx ,ncy+1) + dPdτ = zeros(Dat, ncx ,ncy ) + Δτv = zeros(Dat, ncx+1,ncy+1) + Δτvx = zeros(Dat, ncx+1,ncy ) + Δτvy = zeros(Dat, ncx ,ncy+1) + κΔτp = zeros(Dat, ncx ,ncy ) + Rog = zeros(Dat, ncx ,ncy ) + ηc = η0*ones(Dat, ncx, ncy) + ηv = η0*ones(Dat, ncx+1, ncy+1) + # Initialisation + xc, yc = LinRange( Δx/2, Lx-Δx/2, ncx+0), LinRange( Δy/2, Ly-Δy/2, ncy+0) + xce, yce = LinRange(-Δx/2, Lx+Δx/2, ncx+2), LinRange(-Δy/2, Ly+Δy/2, ncy+2) + xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) + (Xvx,Yvx) = ([x for x=xv,y=yce], [y for x=xv,y=yce]) + (Xvy,Yvy) = ([x for x=xce,y=yv], [y for x=xce,y=yv]) + Vx .= εbg.*Xvx + Vy .= .-εbg.*Yvy + # Time loop + t=0.0; evo_t=[]; evo_τxx=[] + for it = 1:nt + iter=1; err=2*ε; err_evo1=[]; err_evo2=[]; + τxx0.=τxx; τyy0.=τyy; τxy0.=τxy + while (err>ε && iter<=iterMax) + # BCs + Vx[:,1] .= Vx[:,2] # S + Vx[:,end] .= Vx[:,end-1] # N + Vy[1,:] .= Vy[2,:] # W + Vy[end,:] .= Vy[end-1,:] # E + # Kinematics + ∇V .= diff(Vx[:,2:end-1], dims=1)./Δx .+ diff(Vy[2:end-1,:], dims=2)./Δy + ε̇xx .= diff(Vx[:,2:end-1], dims=1)./Δx .- 1.0/3.0*∇V + ε̇yy .= diff(Vy[2:end-1,:], dims=2)./Δy .- 1.0/3.0*∇V + ε̇xy .= 0.5.*(diff(Vx, dims=2)./Δy .+ diff(Vy, dims=1)./Δx) + # Stresses + UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt ) + if iter==1 + display(τxx') + end + # Residuals + Rx[2:end-1,:] .= .-diff(Pt, dims=1)./Δx .+ diff(τxx, dims=1)./Δx .+ diff(τxy[2:end-1,:], dims=2)./Δy + Ry[:,2:end-1] .= .-diff(Pt, dims=2)./Δy .+ diff(τyy, dims=2)./Δy .+ diff(τxy[:,2:end-1], dims=1)./Δx #.+ av_ya(Rog) + Rp .= .-∇V + # PT time step ----------------------------------------------- + Δτv .= ρ*min(Δx,Δy)^2 ./ ηv ./ 4.1 * cfl + Δτvx .= (Δτv[:,1:end-1] .+ Δτv[:,2:end]) / 2. + Δτvy .= (Δτv[1:end-1,:] .+ Δτv[2:end,:]) / 2. + κΔτp .= cfl .* ηc .* Δx ./ Lx + # Calculate rate update -------------------------------------- + dVxdτ .= (1-ρ) .* dVxdτ .+ Rx + dVydτ .= (1-ρ) .* dVydτ .+ Ry + dPdτ .= Rp + # Update velocity and pressure ------------------------------- + Vx[:,2:end-1] .+= Δτvx ./ ρ .* dVxdτ + Vy[2:end-1,:] .+= Δτvy ./ ρ .* dVydτ + Pt .+= κΔτp .* dPdτ + # convergence check + if mod(iter, nout)==0 + norm_Rx = norm(Rx)/sqrt(length(Rx)); norm_Ry = norm(Ry)/sqrt(length(Ry)); norm_∇V = norm(∇V)/sqrt(length(∇V)) + err = maximum([norm_Rx, norm_Ry, norm_∇V]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %03d, iter = %04d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V) + end + iter+=1; global itg=iter + end + t = t + Δt + push!(evo_t, t); push!(evo_τxx, maximum(τxx)) + # Plotting + p1 = heatmap(xv, yc, Vx[:,2:end-1]', aspect_ratio=1, xlims=(0, Lx), ylims=(Δy/2, Ly-Δy/2), c=:inferno, title="Vx") + p2 = heatmap(xc, yv, Vy[2:end-1,:]', aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p3 = heatmap(xc, yc, ε̇xx' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="P") + p4 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewiΔth=0, markershape=:circle, framestyle=:box, markersize=3) + p4 = plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewiΔth=2.0) # analytical solution + display(plot(p1, p2, p3, p4)) + end + return +end + +Stokes2D_VE_benchmark() diff --git a/GeoParams_PT_examples/src/Stokes2D_VE_inclusion_GeoParams.jl b/GeoParams_PT_examples/src/Stokes2D_VE_inclusion_GeoParams.jl new file mode 100644 index 0000000..ba3d781 --- /dev/null +++ b/GeoParams_PT_examples/src/Stokes2D_VE_inclusion_GeoParams.jl @@ -0,0 +1,158 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra, GeoParams +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +# Rheology +@views function UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt, Phasec, Phasev ) + ε̇iic = ones(size(ε̇xx)) + ε̇iiv = ones(size(ε̇xy)) + τii0c = sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) + τii0v = zeros(size(ε̇xy)) + τii0v[2:end-1,2:end-1] = sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) + # Centroids + for i in eachindex(τxx) + v = MatParam[Phasec[i]].CompositeRheology[1] + args = (; τII_old = τii0c[i], dt=Δt) + ηc[i] = computeViscosity_εII(v, ε̇iic[i], args) + τxx[i] = 2*ηc[i]*ε̇xx[i] + τyy[i] = 2*ηc[i]*ε̇yy[i] + end + # Vertices + for i in eachindex(τxy) + v = MatParam[Phasev[i]].CompositeRheology[1] + args = (; τII_old = τii0v[i], dt=Δt) + ηv[i] = computeViscosity_εII(v, ε̇iiv[i], args) + τxy[i] = 2*ηv[i]*ε̇xy[i] + end +end +# 2D Stokes routine +@views function Stokes2D_VE_inclusion() + # Physics + Lx, Ly = 1.0, 1.0 # domain size + ξ = 10.0 # Maxwell relaxation time + η0 = 1.0 # viscous viscosity + G = 1.0 # elastic shear modulus + εbg = 1.0 # background strain-rate + radi = 0.01 + + MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G),LinearViscous(η=η0))), + SetMaterialParams(Name="Inclusion", Phase=2, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G*0.1),LinearViscous(η=η0*0.1))), + ) + + # Numerics + nt = 10 # number of time steps + ncx, ncy = 51, 51 # numerical grid resolution + ε = 1e-6 # nonlinear tolerence + iterMax = 1e4 # max number of iters + nout = 500 # check frequency + # Iterative parameters ------------------------------------------- + Reopt = 5π + cfl = 0.5 + ρ = cfl*Reopt/ncx + # Preprocessing + Δx, Δy = Lx/ncx, Ly/ncy + Δt = η0/(G*ξ + 1e-15) + # Array initialisation + Pt = zeros(Dat, ncx ,ncy ) + ∇V = zeros(Dat, ncx ,ncy ) + Vx = zeros(Dat, ncx+1,ncy+2) + Vy = zeros(Dat, ncx+2,ncy+1) + ε̇xx = zeros(Dat, ncx ,ncy ) + ε̇yy = zeros(Dat, ncx ,ncy ) + ε̇xy = zeros(Dat, ncx+1,ncy+1) + τxx = zeros(Dat, ncx ,ncy ) + τyy = zeros(Dat, ncx ,ncy ) + τxy = zeros(Dat, ncx+1,ncy+1) + τxx0 = zeros(Dat, ncx ,ncy ) + τyy0 = zeros(Dat, ncx ,ncy ) + τxy0 = zeros(Dat, ncx+1,ncy+1) + Rx = zeros(Dat, ncx+1,ncy ) + Ry = zeros(Dat, ncx ,ncy+1) + Rp = zeros(Dat, ncx ,ncy ) + dVxdτ = zeros(Dat, ncx+1,ncy ) + dVydτ = zeros(Dat, ncx ,ncy+1) + dPdτ = zeros(Dat, ncx ,ncy ) + Δτv = zeros(Dat, ncx+1,ncy+1) + Δτvx = zeros(Dat, ncx+1,ncy ) + Δτvy = zeros(Dat, ncx ,ncy+1) + κΔτp = zeros(Dat, ncx ,ncy ) + Rog = zeros(Dat, ncx ,ncy ) + ηc = η0*ones(Dat, ncx, ncy) + ηv = η0*ones(Dat, ncx+1, ncy+1) + Phasec = ones(Int, ncx ,ncy ) + Phasev = ones(Int, ncx+1,ncy+1) + # Initialisation + xce, yce = LinRange(-Δx/2, Lx+Δx/2, ncx+2), LinRange(-Δy/2, Ly+Δy/2, ncy+2) + xc, yc = LinRange(Δx/2, Lx-Δx/2, ncx), LinRange(Δy/2, Ly-Δy/2, ncy) + xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + Phasec[radc.ε && iter<=iterMax) + # BCs + Vx[:,1] .= Vx[:,2] # S + Vx[:,end] .= Vx[:,end-1] # N + Vy[1,:] .= Vy[2,:] # W + Vy[end,:] .= Vy[end-1,:] # E + # Kinematics + ∇V .= diff(Vx[:,2:end-1], dims=1)./Δx .+ diff(Vy[2:end-1,:], dims=2)./Δy + ε̇xx .= diff(Vx[:,2:end-1], dims=1)./Δx .- 1.0/3.0*∇V + ε̇yy .= diff(Vy[2:end-1,:], dims=2)./Δy .- 1.0/3.0*∇V + ε̇xy .= 0.5.*(diff(Vx, dims=2)./Δy .+ diff(Vy, dims=1)./Δx) + # Stresses + UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt, Phasec, Phasev ) + # Residuals + Rx[2:end-1,:] .= .-diff(Pt, dims=1)./Δx .+ diff(τxx, dims=1)./Δx .+ diff(τxy[2:end-1,:], dims=2)./Δy + Ry[:,2:end-1] .= .-diff(Pt, dims=2)./Δy .+ diff(τyy, dims=2)./Δy .+ diff(τxy[:,2:end-1], dims=1)./Δx #.+ av_ya(Rog) + Rp .= .-∇V + # PT time step ----------------------------------------------- + Δτv .= ρ*min(Δx,Δy)^2 ./ ηv ./ 4.1 * cfl + Δτvx .= (Δτv[:,1:end-1] .+ Δτv[:,2:end]) / 2. + Δτvy .= (Δτv[1:end-1,:] .+ Δτv[2:end,:]) / 2. + κΔτp .= cfl .* ηc .* Δx ./ Lx + # Calculate rate update -------------------------------------- + dVxdτ .= (1-ρ) .* dVxdτ .+ Rx + dVydτ .= (1-ρ) .* dVydτ .+ Ry + dPdτ .= Rp + # Update velocity and pressure ------------------------------- + Vx[:,2:end-1] .+= Δτvx ./ ρ .* dVxdτ + Vy[2:end-1,:] .+= Δτvy ./ ρ .* dVydτ + Pt .+= κΔτp .* dPdτ + # convergence check + if mod(iter, nout)==0 + norm_Rx = norm(Rx)/sqrt(length(Rx)); norm_Ry = norm(Ry)/sqrt(length(Ry)); norm_∇V = norm(∇V)/sqrt(length(∇V)) + err = maximum([norm_Rx, norm_Ry, norm_∇V]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %03d, iter = %04d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V) + end + iter+=1; global itg=iter + end + t = t + Δt + push!(evo_t, t); push!(evo_τxx, maximum(τxx)) + # Plotting + p1 = heatmap(xv, yc, Vx[:,2:end-1]', aspect_ratio=1, xlims=(0, Lx), ylims=(Δy/2, Ly-Δy/2), c=:inferno, title="Vx") + p2 = heatmap(xc, yv, Vy[2:end-1,:]', aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p3 = heatmap(xc, yc, Pt' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="P") + p4 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + p4 = plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewidth=2.0) # analytical solution + display(plot(p1, p2, p3, p4)) + end + return +end + +Stokes2D_VE_inclusion() \ No newline at end of file diff --git a/GeoParams_PT_examples/src/Stokes2D_ve_bench_GeoParams.jl b/GeoParams_PT_examples/src/Stokes2D_ve_bench_GeoParams.jl deleted file mode 100644 index 19bac9e..0000000 --- a/GeoParams_PT_examples/src/Stokes2D_ve_bench_GeoParams.jl +++ /dev/null @@ -1,132 +0,0 @@ -# Initialisation -using Plots, Printf, Statistics, LinearAlgebra, GeoParams -Dat = Float64 # Precision (double=Float64 or single=Float32) -# Macros -@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) -@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) -@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) -# Rheology -@views function UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, dt ) - ε̇iic = ones(size(ε̇xx)) - ε̇iiv = ones(size(ε̇xy)) - τii0c = sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) - τii0v = zeros(size(ε̇xy)) - τii0v[2:end-1,2:end-1] = sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) - Phase = 1 - # Centroids - for i in eachindex(τxx) - v = MatParam[Phase].CompositeRheology[1] - args = (; τII_old = τii0c[i], dt=dt) - η_eff = computeViscosity_εII(v, ε̇iic[i], args) - τxx[i] = 2*η_eff*ε̇xx[i] - τyy[i] = 2*η_eff*ε̇yy[i] - end - # Vertices - for i in eachindex(τxy) - v = MatParam[Phase].CompositeRheology[1] - args = (; τII_old = τii0v[i], dt=dt) - η_eff = computeViscosity_εII(v, ε̇iiv[i], args) - τxy[i] = 2*η_eff*ε̇xy[i] - end -end -# 2D Stokes routine -@views function Stokes2D_ve() - # Physics - Lx, Ly = 1.0, 1.0 # domain size - ξ = 10.0 # Maxwell relaxation time - η0 = 1.0 # viscous viscosity - G = 1.0 # elastic shear modulus - εbg = 1.0 # background strain-rate - - MatParam = (SetMaterialParams(Name="Matrix", Phase=1, - CompositeRheology = CompositeRheology(ConstantElasticity(G=G),LinearViscous(η=η0))),) - - # Numerics - nt = 50 # number of time steps - ncx, ncy = 31, 31 # numerical grid resolution - Vdmp = 4.0 # convergence acceleration (damping) - Ptsc = 8.0 # iterative time step limiter - ε = 1e-6 # nonlinear tolerence - iterMax = 1e5 # max number of iters - nout = 200 # check frequency - # Preprocessing - dx, dy = Lx/ncx, Ly/ncy - dt = η0/(G*ξ + 1e-15) - # Array initialisation - Pt = zeros(Dat, ncx ,ncy ) - ∇V = zeros(Dat, ncx ,ncy ) - Vx = zeros(Dat, ncx+1,ncy ) - Vy = zeros(Dat, ncx ,ncy+1) - ε̇xx = zeros(Dat, ncx ,ncy ) - ε̇yy = zeros(Dat, ncx ,ncy ) - ε̇xy = zeros(Dat, ncx+1,ncy+1) - τxx = zeros(Dat, ncx ,ncy ) - τyy = zeros(Dat, ncx ,ncy ) - τxy = zeros(Dat, ncx+1,ncy+1) - τxx0 = zeros(Dat, ncx ,ncy ) - τyy0 = zeros(Dat, ncx ,ncy ) - τxy0 = zeros(Dat, ncx+1,ncy+1) - Rx = zeros(Dat, ncx-1,ncy ) - Ry = zeros(Dat, ncx ,ncy-1) - dVxdt = zeros(Dat, ncx-1,ncy ) - dVydt = zeros(Dat, ncx ,ncy-1) - Rog = zeros(Dat, ncx ,ncy ) - Xc = ξ*ones(Dat, ncx, ncy) - Xv = ξ*ones(Dat, ncx+1, ncy+1) - ηc = η0*ones(Dat, ncx, ncy) - ηv = η0*ones(Dat, ncx+1, ncy+1) - # Initialisation - xc, yc = LinRange(dx/2, Lx-dx/2, ncx), LinRange(dy/2, Ly-dy/2, ncy) - xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) - (Xvx,Yvx) = ([x for x=xv,y=yc], [y for x=xv,y=yc]) - (Xvy,Yvy) = ([x for x=xc,y=yv], [y for x=xc,y=yv]) - Vx .= εbg.*Xvx - Vy .= .-εbg.*Yvy - dtVx = min(dx,dy)^2.0./av_xa(ηc)./4.1 - dtVy = min(dx,dy)^2.0./av_ya(ηc)./4.1 - dtPt = 4.1*ηc/max(ncx,ncy)/Ptsc - # Time loop - t=0.0; evo_t=[]; evo_τxx=[] - for it = 1:nt - iter=1; err=2*ε; err_evo1=[]; err_evo2=[]; - τxx0.=τxx; τyy0.=τyy; τxy0.=τxy - while (err>ε && iter<=iterMax) - # divergence - pressure - ∇V .= diff(Vx, dims=1)./dx .+ diff(Vy, dims=2)./dy - Pt .= Pt .- dtPt.*∇V - # strain rates - ε̇xx .= diff(Vx, dims=1)./dx .- 1.0/3.0*∇V - ε̇yy .= diff(Vy, dims=2)./dy .- 1.0/3.0*∇V - ε̇xy[2:end-1,2:end-1] .= 0.5.*(diff(Vx[2:end-1,:], dims=2)./dy .+ diff(Vy[:,2:end-1], dims=1)./dx) - # stresses - UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, dt ) - # velocities - Rx .= .-diff(Pt, dims=1)./dx .+ diff(τxx, dims=1)./dx .+ diff(τxy[2:end-1,:], dims=2)./dy - Ry .= .-diff(Pt, dims=2)./dy .+ diff(τyy, dims=2)./dy .+ diff(τxy[:,2:end-1], dims=1)./dx .+ av_ya(Rog) - dVxdt .= dVxdt.*(1-Vdmp/ncx) .+ Rx - dVydt .= dVydt.*(1-Vdmp/ncy) .+ Ry - Vx[2:end-1,:] .= Vx[2:end-1,:] .+ dVxdt.*dtVx - Vy[:,2:end-1] .= Vy[:,2:end-1] .+ dVydt.*dtVy - # convergence check - if mod(iter, nout)==0 - norm_Rx = norm(Rx)/length(Rx); norm_Ry = norm(Ry)/length(Ry); norm_∇V = norm(∇V)/length(∇V) - err = maximum([norm_Rx, norm_Ry, norm_∇V]) - push!(err_evo1, err); push!(err_evo2, itg) - @printf("it = %d, iter = %d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V) - - end - iter+=1; global itg=iter - end - t = t + dt - push!(evo_t, t); push!(evo_τxx, maximum(τxx)) - # Plotting - p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") - p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") - p3 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) - plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewidth=2.0) # analytical solution - display(plot(p1, p2, p3)) - end - return -end - -Stokes2D_ve() diff --git a/GeoParams_PT_examples/src/Stokes2D_ve_inclusion_GeoParams.jl b/GeoParams_PT_examples/src/Stokes2D_ve_inclusion_GeoParams.jl deleted file mode 100644 index d619413..0000000 --- a/GeoParams_PT_examples/src/Stokes2D_ve_inclusion_GeoParams.jl +++ /dev/null @@ -1,142 +0,0 @@ -# Initialisation -using Plots, Printf, Statistics, LinearAlgebra, GeoParams -Dat = Float64 # Precision (double=Float64 or single=Float32) -# Macros -@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) -@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) -@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) -# Rheology -@views function UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, dt, Phasec, Phasev ) - ε̇iic = ones(size(ε̇xx)) - ε̇iiv = ones(size(ε̇xy)) - τii0c = sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) - τii0v = zeros(size(ε̇xy)) - τii0v[2:end-1,2:end-1] = sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) - # Centroids - for i in eachindex(τxx) - v = MatParam[Phasec[i]].CompositeRheology[1] - args = (; τII_old = τii0c[i], dt=dt) - η_eff = computeViscosity_εII(v, ε̇iic[i], args) - τxx[i] = 2*η_eff*ε̇xx[i] - τyy[i] = 2*η_eff*ε̇yy[i] - end - # Vertices - for i in eachindex(τxy) - v = MatParam[Phasev[i]].CompositeRheology[1] - args = (; τII_old = τii0v[i], dt=dt) - η_eff = computeViscosity_εII(v, ε̇iiv[i], args) - τxy[i] = 2*η_eff*ε̇xy[i] - end -end -# 2D Stokes routine -@views function Stokes2D_ve() - # Physics - Lx, Ly = 1.0, 1.0 # domain size - ξ = 10.0 # Maxwell relaxation time - η0 = 1.0 # viscous viscosity - G = 1.0 # elastic shear modulus - εbg = 1.0 # background strain-rate - radi = 0.01 - - MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, - CompositeRheology = CompositeRheology(ConstantElasticity(G=G),LinearViscous(η=η0))), - SetMaterialParams(Name="Inclusion", Phase=2, - CompositeRheology = CompositeRheology(ConstantElasticity(G=G*0.25),LinearViscous(η=η0))), - ) - - # Numerics - nt = 1 # number of time steps - ncx, ncy = 31, 31 # numerical grid resolution - Vdmp = 9.0 # convergence acceleration (damping) - Ptsc = 10.0 # iterative time step limiter - ε = 1e-6 # nonlinear tolerence - iterMax = 1e5 # max number of iters - nout = 500 # check frequency - # Preprocessing - dx, dy = Lx/ncx, Ly/ncy - dt = η0/(G*ξ + 1e-15) - # Array initialisation - Pt = zeros(Dat, ncx ,ncy ) - ∇V = zeros(Dat, ncx ,ncy ) - Vx = zeros(Dat, ncx+1,ncy ) - Vy = zeros(Dat, ncx ,ncy+1) - ε̇xx = zeros(Dat, ncx ,ncy ) - ε̇yy = zeros(Dat, ncx ,ncy ) - ε̇xy = zeros(Dat, ncx+1,ncy+1) - τxx = zeros(Dat, ncx ,ncy ) - τyy = zeros(Dat, ncx ,ncy ) - τxy = zeros(Dat, ncx+1,ncy+1) - τxx0 = zeros(Dat, ncx ,ncy ) - τyy0 = zeros(Dat, ncx ,ncy ) - τxy0 = zeros(Dat, ncx+1,ncy+1) - Rx = zeros(Dat, ncx-1,ncy ) - Ry = zeros(Dat, ncx ,ncy-1) - dVxdt = zeros(Dat, ncx-1,ncy ) - dVydt = zeros(Dat, ncx ,ncy-1) - Rog = zeros(Dat, ncx ,ncy ) - Xc = ξ*ones(Dat, ncx, ncy) - Xv = ξ*ones(Dat, ncx+1, ncy+1) - ηc = η0*ones(Dat, ncx, ncy) - ηv = η0*ones(Dat, ncx+1, ncy+1) - Phasec = ones(Int, ncx ,ncy ) - Phasev = ones(Int, ncx+1,ncy+1) - xc, yc = LinRange(dx/2, Lx-dx/2, ncx), LinRange(dy/2, Ly-dy/2, ncy) - xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) - radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 - radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 - Phasec[radc.ε && iter<=iterMax) - # divergence - pressure - ∇V .= diff(Vx, dims=1)./dx .+ diff(Vy, dims=2)./dy - Pt .= Pt .- dtPt.*∇V - # strain rates - ε̇xx .= diff(Vx, dims=1)./dx .- 1.0/3.0*∇V - ε̇yy .= diff(Vy, dims=2)./dy .- 1.0/3.0*∇V - ε̇xy[2:end-1,2:end-1] .= 0.5.*(diff(Vx[2:end-1,:], dims=2)./dy .+ diff(Vy[:,2:end-1], dims=1)./dx) - # stresses - UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, dt, Phasec, Phasev ) - # velocities - Rx .= .-diff(Pt, dims=1)./dx .+ diff(τxx, dims=1)./dx .+ diff(τxy[2:end-1,:], dims=2)./dy - Ry .= .-diff(Pt, dims=2)./dy .+ diff(τyy, dims=2)./dy .+ diff(τxy[:,2:end-1], dims=1)./dx .+ av_ya(Rog) - dVxdt .= dVxdt.*(1-Vdmp/ncx) .+ Rx - dVydt .= dVydt.*(1-Vdmp/ncy) .+ Ry - Vx[2:end-1,:] .= Vx[2:end-1,:] .+ dVxdt.*dtVx - Vy[:,2:end-1] .= Vy[:,2:end-1] .+ dVydt.*dtVy - # convergence check - if mod(iter, nout)==0 - norm_Rx = norm(Rx)/length(Rx); norm_Ry = norm(Ry)/length(Ry); norm_∇V = norm(∇V)/length(∇V) - err = maximum([norm_Rx, norm_Ry, norm_∇V]) - push!(err_evo1, err); push!(err_evo2, itg) - @printf("it = %d, iter = %d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V) - end - iter+=1; global itg=iter - end - t = t + dt - push!(evo_t, t); push!(evo_τxx, maximum(τxx)) - # Plotting - p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") - p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") - p3 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) - plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewidth=2.0) # analytical solution - display(plot(p1, p2, p3)) - end - return -end - -Stokes2D_ve() From 73ccb570b67f8b24987fc9412e0dbb3cff3dc845 Mon Sep 17 00:00:00 2001 From: Duretz Thibault Date: Sun, 9 Oct 2022 15:35:44 +0200 Subject: [PATCH 03/49] Basic 2D discontinuous Poisson solver that could receive a non-linear conductivity update using GeoParams(?) --- GeoParams_PT_examples/src/Poisson2D_PT_v0.jl | 113 +++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 GeoParams_PT_examples/src/Poisson2D_PT_v0.jl diff --git a/GeoParams_PT_examples/src/Poisson2D_PT_v0.jl b/GeoParams_PT_examples/src/Poisson2D_PT_v0.jl new file mode 100644 index 0000000..89546f1 --- /dev/null +++ b/GeoParams_PT_examples/src/Poisson2D_PT_v0.jl @@ -0,0 +1,113 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +@views avh(A) = ( 0.25./A[1:end-1,1:end-1] .+ 0.25./A[1:end-1,2:end-0] .+ 0.25./A[2:end-0,1:end-1] .+ 0.25./A[2:end-0,2:end-0]).^(-1) +# 2D Poisson routine +@views function Poisson2D() + # Physics + Lx, Ly = 6.0, 6.0 # domain size + T_West = 0.0 + T_East = 0.0 + T_South = 0.0 + T_North = 0.0 + slope = -15. + k1 = 1 + k2 = 1e4 + # Numerics + ncx, ncy = 51, 51 # numerical grid resolution + ε = 1e-6 # nonlinear tolerence + iterMax = 1e4 # max number of iters + nout = 500 # check frequency + # Iterative parameters ------------------------------------------- + Reopt = 0.625*π + cfl = 0.32 + ρ = cfl*Reopt/ncx + nsm = 5 + # Reopt = 0.625*π /3 + # cfl = 0.3*4 + # ρ = cfl*Reopt/ncx + # nsm = 10 + # Preprocessing + Δx, Δy = Lx/ncx, Ly/ncy + # Array initialisation + T = zeros(Dat, ncx+2, ncy+2) + ∂T∂x = zeros(Dat, ncx+1, ncy ) + ∂T∂y = zeros(Dat, ncx , ncy+1) + qx = zeros(Dat, ncx+1, ncy ) + qy = zeros(Dat, ncx , ncy+1) + RT = zeros(Dat, ncx , ncy ) + dTdτ = zeros(Dat, ncx , ncy ) + Δτc = zeros(Dat, ncx , ncy ) + kv = k1*ones(Dat, ncx+1, ncy+1) + kx = zeros(Dat, ncx+1, ncy+0) + ky = zeros(Dat, ncx+0, ncy+1) + H = ones(Dat, ncx , ncy ) + # Initialisation + xc, yc = LinRange(-Lx/2+Δx/2, Lx/2-Δx/2, ncx+0), LinRange(-Ly/2+Δy/2, Ly/2-Δy/2, ncy+0) + xce, yce = LinRange(-Lx/2-Δx/2, Lx/2+Δx/2, ncx+2), LinRange(-Ly/2-Δy/2, Ly/2+Δy/2, ncy+2) + xv, yv = LinRange(-Lx/2, Lx/2, ncx+1), LinRange(-Ly/2, Ly/2, ncy+1) + (xv2,yv2) = ([x for x=xv,y=yv], [y for x=xv,y=yv]) + below = yv2 .< xv2.*tand.(slope) + kv[below] .= k2 + kx .= ( 0.5./kv[:,1:end-1] .+ 0.5./kv[:,2:end-0]).^(-1) + ky .= ( 0.5./kv[1:end-1,:] .+ 0.5./kv[2:end-0,:]).^(-1) + kc = ( 0.25./kv[1:end-1,1:end-1] .+ 0.25./kv[1:end-1,2:end-0] .+ 0.25./kv[2:end-0,1:end-1] .+ 0.25./kv[2:end-0,2:end-0]).^(-1) + for it = 1:nsm + kv[2:end-1,2:end-1] .= av(kc) + kc = av(kv) + end + # Time loop + it=1; iter=1; err=2*ε; err_evo1=[]; err_evo2=[]; + while (err>ε && iter<=iterMax) + # BCs + T[:,1] .= 2*T_South .- T[:,2] # S + T[:,end] .= 2*T_North .- T[:,end-1] # N + T[1,:] .= 2*T_West .- T[2,:] # W + T[end,:] .= 2*T_East .- T[end-1,:] # E + # Kinematics + ∂T∂x .= diff(T[:,2:end-1], dims=1)./Δx + ∂T∂y .= diff(T[2:end-1,:], dims=2)./Δy + # Stresses + qx .= -kx.*∂T∂x + qy .= -ky.*∂T∂y + # Residuals + RT .= .-diff(qx, dims=1)./Δx .- diff(qy, dims=2)./Δy + H + # PT time step ----------------------------------------------- + Δτc .= ρ*min(Δx,Δy)^2 ./ kc ./ 4.1 * cfl + # Calculate rate update -------------------------------------- + dTdτ .= (1-ρ) .* dTdτ .+ RT + # Update velocity and pressure ------------------------------- + T[2:end-1,2:end-1] .+= Δτc ./ ρ .* dTdτ + # convergence check + if mod(iter, nout)==0 + norm_RT = norm(RT)/sqrt(length(RT)) + err = maximum([norm_RT]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %03d, iter = %04d, err = %1.3e norm[RT=%1.3e] \n", it, itg, err, norm_RT) + end + iter+=1; global itg=iter + end + # Plotting + p1 = heatmap(xce, yce, T', aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), c=:turbo, title="T") + p2 = heatmap( xc, yv, log10.(ky)', aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), c=:turbo, title="ky") + p3 = heatmap( xc, yc, log10.(kc)', aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), c=:turbo, title="kc") + y_int = xv.*tand.(slope) + p4 = plot(xv, y_int, aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), color=:black, label=:none) + # lines + for j=1:ncy+1 + y_line = yv[j]*ones(size(xv)) + p4 = plot!(xv, y_line, aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), color=:gray, label=:none) + end + for i=1:ncx+1 + x_line = xv[i]*ones(size(yv)) + p4 = plot!(x_line, yv, aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), color=:gray, label=:none) + end + display(plot(p1, p2, p3, p4)) + return +end + +Poisson2D() From 9b9761d6cf8006263dc27a61a4338fabd14b9856 Mon Sep 17 00:00:00 2001 From: Duretz Thibault Date: Sun, 9 Oct 2022 21:47:48 +0200 Subject: [PATCH 04/49] clean up --- GeoParams_PT_examples/.DS_Store | Bin 6148 -> 0 bytes GeoParams_PT_examples/.gitignore | 2 ++ 2 files changed, 2 insertions(+) delete mode 100644 GeoParams_PT_examples/.DS_Store create mode 100644 GeoParams_PT_examples/.gitignore diff --git a/GeoParams_PT_examples/.DS_Store b/GeoParams_PT_examples/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Sun, 9 Oct 2022 21:49:00 +0200 Subject: [PATCH 05/49] add scripts --- .../scripts/Poisson2D_PT_v0.jl | 113 +++++++++ .../scripts/Poisson2D_PT_v1.jl | 213 ++++++++++++++++ .../scripts/Stokes2D_VE_bench_GeoParams.jl | 152 ++++++++++++ .../Stokes2D_VE_inclusion_GeoParams.jl | 158 ++++++++++++ .../scripts/Stokes2D_vep_bench_GeoParams.jl | 142 +++++++++++ .../scripts/Stokes2D_vep_reg_vc_GeoParams.jl | 227 ++++++++++++++++++ 6 files changed, 1005 insertions(+) create mode 100644 GeoParams_PT_examples/scripts/Poisson2D_PT_v0.jl create mode 100644 GeoParams_PT_examples/scripts/Poisson2D_PT_v1.jl create mode 100644 GeoParams_PT_examples/scripts/Stokes2D_VE_bench_GeoParams.jl create mode 100644 GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams.jl create mode 100644 GeoParams_PT_examples/scripts/Stokes2D_vep_bench_GeoParams.jl create mode 100644 GeoParams_PT_examples/scripts/Stokes2D_vep_reg_vc_GeoParams.jl diff --git a/GeoParams_PT_examples/scripts/Poisson2D_PT_v0.jl b/GeoParams_PT_examples/scripts/Poisson2D_PT_v0.jl new file mode 100644 index 0000000..89546f1 --- /dev/null +++ b/GeoParams_PT_examples/scripts/Poisson2D_PT_v0.jl @@ -0,0 +1,113 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +@views avh(A) = ( 0.25./A[1:end-1,1:end-1] .+ 0.25./A[1:end-1,2:end-0] .+ 0.25./A[2:end-0,1:end-1] .+ 0.25./A[2:end-0,2:end-0]).^(-1) +# 2D Poisson routine +@views function Poisson2D() + # Physics + Lx, Ly = 6.0, 6.0 # domain size + T_West = 0.0 + T_East = 0.0 + T_South = 0.0 + T_North = 0.0 + slope = -15. + k1 = 1 + k2 = 1e4 + # Numerics + ncx, ncy = 51, 51 # numerical grid resolution + ε = 1e-6 # nonlinear tolerence + iterMax = 1e4 # max number of iters + nout = 500 # check frequency + # Iterative parameters ------------------------------------------- + Reopt = 0.625*π + cfl = 0.32 + ρ = cfl*Reopt/ncx + nsm = 5 + # Reopt = 0.625*π /3 + # cfl = 0.3*4 + # ρ = cfl*Reopt/ncx + # nsm = 10 + # Preprocessing + Δx, Δy = Lx/ncx, Ly/ncy + # Array initialisation + T = zeros(Dat, ncx+2, ncy+2) + ∂T∂x = zeros(Dat, ncx+1, ncy ) + ∂T∂y = zeros(Dat, ncx , ncy+1) + qx = zeros(Dat, ncx+1, ncy ) + qy = zeros(Dat, ncx , ncy+1) + RT = zeros(Dat, ncx , ncy ) + dTdτ = zeros(Dat, ncx , ncy ) + Δτc = zeros(Dat, ncx , ncy ) + kv = k1*ones(Dat, ncx+1, ncy+1) + kx = zeros(Dat, ncx+1, ncy+0) + ky = zeros(Dat, ncx+0, ncy+1) + H = ones(Dat, ncx , ncy ) + # Initialisation + xc, yc = LinRange(-Lx/2+Δx/2, Lx/2-Δx/2, ncx+0), LinRange(-Ly/2+Δy/2, Ly/2-Δy/2, ncy+0) + xce, yce = LinRange(-Lx/2-Δx/2, Lx/2+Δx/2, ncx+2), LinRange(-Ly/2-Δy/2, Ly/2+Δy/2, ncy+2) + xv, yv = LinRange(-Lx/2, Lx/2, ncx+1), LinRange(-Ly/2, Ly/2, ncy+1) + (xv2,yv2) = ([x for x=xv,y=yv], [y for x=xv,y=yv]) + below = yv2 .< xv2.*tand.(slope) + kv[below] .= k2 + kx .= ( 0.5./kv[:,1:end-1] .+ 0.5./kv[:,2:end-0]).^(-1) + ky .= ( 0.5./kv[1:end-1,:] .+ 0.5./kv[2:end-0,:]).^(-1) + kc = ( 0.25./kv[1:end-1,1:end-1] .+ 0.25./kv[1:end-1,2:end-0] .+ 0.25./kv[2:end-0,1:end-1] .+ 0.25./kv[2:end-0,2:end-0]).^(-1) + for it = 1:nsm + kv[2:end-1,2:end-1] .= av(kc) + kc = av(kv) + end + # Time loop + it=1; iter=1; err=2*ε; err_evo1=[]; err_evo2=[]; + while (err>ε && iter<=iterMax) + # BCs + T[:,1] .= 2*T_South .- T[:,2] # S + T[:,end] .= 2*T_North .- T[:,end-1] # N + T[1,:] .= 2*T_West .- T[2,:] # W + T[end,:] .= 2*T_East .- T[end-1,:] # E + # Kinematics + ∂T∂x .= diff(T[:,2:end-1], dims=1)./Δx + ∂T∂y .= diff(T[2:end-1,:], dims=2)./Δy + # Stresses + qx .= -kx.*∂T∂x + qy .= -ky.*∂T∂y + # Residuals + RT .= .-diff(qx, dims=1)./Δx .- diff(qy, dims=2)./Δy + H + # PT time step ----------------------------------------------- + Δτc .= ρ*min(Δx,Δy)^2 ./ kc ./ 4.1 * cfl + # Calculate rate update -------------------------------------- + dTdτ .= (1-ρ) .* dTdτ .+ RT + # Update velocity and pressure ------------------------------- + T[2:end-1,2:end-1] .+= Δτc ./ ρ .* dTdτ + # convergence check + if mod(iter, nout)==0 + norm_RT = norm(RT)/sqrt(length(RT)) + err = maximum([norm_RT]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %03d, iter = %04d, err = %1.3e norm[RT=%1.3e] \n", it, itg, err, norm_RT) + end + iter+=1; global itg=iter + end + # Plotting + p1 = heatmap(xce, yce, T', aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), c=:turbo, title="T") + p2 = heatmap( xc, yv, log10.(ky)', aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), c=:turbo, title="ky") + p3 = heatmap( xc, yc, log10.(kc)', aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), c=:turbo, title="kc") + y_int = xv.*tand.(slope) + p4 = plot(xv, y_int, aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), color=:black, label=:none) + # lines + for j=1:ncy+1 + y_line = yv[j]*ones(size(xv)) + p4 = plot!(xv, y_line, aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), color=:gray, label=:none) + end + for i=1:ncx+1 + x_line = xv[i]*ones(size(yv)) + p4 = plot!(x_line, yv, aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), color=:gray, label=:none) + end + display(plot(p1, p2, p3, p4)) + return +end + +Poisson2D() diff --git a/GeoParams_PT_examples/scripts/Poisson2D_PT_v1.jl b/GeoParams_PT_examples/scripts/Poisson2D_PT_v1.jl new file mode 100644 index 0000000..869c0f8 --- /dev/null +++ b/GeoParams_PT_examples/scripts/Poisson2D_PT_v1.jl @@ -0,0 +1,213 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +@views avh(A) = ( 0.25./A[1:end-1,1:end-1] .+ 0.25./A[1:end-1,2:end-0] .+ 0.25./A[2:end-0,1:end-1] .+ 0.25./A[2:end-0,2:end-0]).^(-1) +# 2D Poisson routine +@views function Poisson2D() + # Physics + Lx, Ly = 6.0, 6.0 # domain size + T_West = 0.0 + T_East = 0.0 + T_South = 0.0 + T_North = 0.0 + slope = -15. + k1 = 1 + k2 = 1e4 + # Numerics + ncx, ncy = 11, 11 # numerical grid resolution + ε = 1e-6 # nonlinear tolerence + iterMax = 1e4 # max number of iters + nout = 500 # check frequency + # Iterative parameters ------------------------------------------- + Reopt = 0.625*π + cfl = 0.32 + ρ = cfl*Reopt/ncx + nsm = 5 + # Reopt = 0.625*π /3 + # cfl = 0.3*4 + # ρ = cfl*Reopt/ncx + # nsm = 10 + # Preprocessing + Δx, Δy = Lx/ncx, Ly/ncy + # Array initialisation + T = zeros(Dat, ncx+2, ncy+2) + ∂T∂x = zeros(Dat, ncx+1, ncy ) + ∂T∂y = zeros(Dat, ncx , ncy+1) + qx = zeros(Dat, ncx+1, ncy ) + qy = zeros(Dat, ncx , ncy+1) + RT = zeros(Dat, ncx , ncy ) + dTdτ = zeros(Dat, ncx , ncy ) + Δτc = zeros(Dat, ncx , ncy ) + kv = k1*ones(Dat, ncx+1, ncy+1) + kx = zeros(Dat, ncx+1, ncy+0) + ky = zeros(Dat, ncx+0, ncy+1) + H = ones(Dat, ncx , ncy ) + # Initialisation + xc, yc = LinRange(-Lx/2+Δx/2, Lx/2-Δx/2, ncx+0), LinRange(-Ly/2+Δy/2, Ly/2-Δy/2, ncy+0) + xce, yce = LinRange(-Lx/2-Δx/2, Lx/2+Δx/2, ncx+2), LinRange(-Ly/2-Δy/2, Ly/2+Δy/2, ncy+2) + xv, yv = LinRange(-Lx/2, Lx/2, ncx+1), LinRange(-Ly/2, Ly/2, ncy+1) + (xv2,yv2) = ([x for x=xv,y=yv], [y for x=xv,y=yv]) + (xc2,yc2) = ([x for x=xc,y=yc], [y for x=xc,y=yc]) + (xqx2,yqx2) = ([x for x=xv,y=yc], [y for x=xv,y=yc]) + (xqy2,yqy2) = ([x for x=xc,y=yv], [y for x=xc,y=yv]) + below = yv2 .< xv2.*tand.(slope) + kv[below] .= k2 + kx .= ( 0.5./kv[:,1:end-1] .+ 0.5./kv[:,2:end-0]).^(-1) + ky .= ( 0.5./kv[1:end-1,:] .+ 0.5./kv[2:end-0,:]).^(-1) + kc = ( 0.25./kv[1:end-1,1:end-1] .+ 0.25./kv[1:end-1,2:end-0] .+ 0.25./kv[2:end-0,1:end-1] .+ 0.25./kv[2:end-0,2:end-0]).^(-1) + for it = 1:nsm + kv[2:end-1,2:end-1] .= av(kc) + kc = av(kv) + end + # Adapt mesh + nc = ncx*ncy + XC = xc2[:] + YC = yc2[:] + num = reshape(1:ncx*ncy, ncx, ncy) + iS = zeros(size(xc2)); iS[:,2:end-0] = num[:,1:end-1] + iN = zeros(size(xc2)); iN[:,1:end-1] = num[:,2:end-0] + IS = iS[:] + IN = iN[:] + vertx = [ xv2[1:end-1,1:end-1][:] xv2[2:end-0,1:end-1][:] xv2[2:end-0,2:end-0][:] xv2[1:end-1,2:end-0][:] ] + verty = [ yv2[1:end-1,1:end-1][:] yv2[2:end-0,1:end-1][:] yv2[2:end-0,2:end-0][:] yv2[1:end-1,2:end-0][:] ] + for ic=1:nc + y_int = XC[ic].*tand.(slope) + @show y_int-YC[ic] + @show Δy/2 + if abs(y_int-YC[ic]) < Δy/2 + println("found interface - adjust top") + if YC[ic] < y_int + println("adjust top") + verty[ic,3] = vertx[ic,3][ic].*tand.(slope) + verty[ic,4] = vertx[ic,4][ic].*tand.(slope) + end + if YC[ic] > y_int + println("adjust bottom") + verty[ic,1] = vertx[ic,1][ic].*tand.(slope) + verty[ic,2] = vertx[ic,2][ic].*tand.(slope) + end + end + end + xqx = zeros(nc,2) + yqx = zeros(nc,2) + xqy = zeros(nc,2) + yqy = zeros(nc,2) + for ic=1:nc + xqx[ic,1] = 0.5*( vertx[ic,1] + vertx[ic,4] ) + yqx[ic,1] = 0.5*( verty[ic,1] + verty[ic,4] ) + xqx[ic,2] = 0.5*( vertx[ic,2] + vertx[ic,3] ) + yqx[ic,2] = 0.5*( verty[ic,2] + verty[ic,3] ) + xqy[ic,1] = 0.5*( vertx[ic,1] + vertx[ic,2] ) + yqy[ic,1] = 0.5*( verty[ic,1] + verty[ic,2] ) + xqy[ic,2] = 0.5*( vertx[ic,3] + vertx[ic,4] ) + yqy[ic,2] = 0.5*( verty[ic,3] + verty[ic,4] ) + end + # Back to 2D table + xc3 = reshape(XC, ncx, ncy) + yc3 = reshape(YC, ncx, ncy) + xv3 = zeros( ncx+1, ncy+1 ) + yv3 = zeros( ncx+1, ncy+1 ) + xv3[1:end-1, 1:end-1] .= reshape(vertx[:,1], ncx, ncy) + xv3[2:end-0, 1:end-1] .= reshape(vertx[:,2], ncx, ncy) + xv3[2:end-0, 2:end-0] .= reshape(vertx[:,3], ncx, ncy) + xv3[1:end-1, 2:end-0] .= reshape(vertx[:,4], ncx, ncy) + yv3[1:end-1, 1:end-1] .= reshape(verty[:,1], ncx, ncy) + yv3[2:end-0, 1:end-1] .= reshape(verty[:,2], ncx, ncy) + yv3[2:end-0, 2:end-0] .= reshape(verty[:,3], ncx, ncy) + yv3[1:end-1, 2:end-0] .= reshape(verty[:,4], ncx, ncy) + xqx3 = zeros( ncx+1, ncy ) + yqx3 = zeros( ncx+1, ncy ) + xqy3 = zeros( ncx, ncy+1 ) + yqy3 = zeros( ncx, ncy+1 ) + xqx3[1:end-1, :] .= reshape(xqx[:,1], ncx, ncy) + xqx3[2:end-0, :] .= reshape(xqx[:,2], ncx, ncy) + yqx3[1:end-1, :] .= reshape(yqx[:,1], ncx, ncy) + yqx3[2:end-0, :] .= reshape(yqx[:,2], ncx, ncy) + xqy3[:, 1:end-1] .= reshape(xqy[:,1], ncx, ncy) + xqy3[:, 2:end-0] .= reshape(xqy[:,2], ncx, ncy) + yqy3[:, 1:end-1] .= reshape(yqy[:,1], ncx, ncy) + yqy3[:, 2:end-0] .= reshape(yqy[:,2], ncx, ncy) + @show norm(xc2.-xc3) + @show norm(yc2.-yc3) + @show norm(xv2.-xv3) + @show norm(yv2.-yv3) + @show norm(xv2.-xv3) + @show norm(xqx3.-xqx2) + @show norm(yqx3.-yqx2) + @show norm(xqy3.-xqy2) + @show norm(yqy3.-yqy2) + Δx_∂T∂x = zeros(ncx+1,ncy) + Δy_∂T∂y = zeros(ncx,ncy+1) + Δx_∂T∂x[2:end-1,:] = diff(xc3, dims=1); Δx_∂T∂x[1,:] = Δx_∂T∂x[2,:]; Δx_∂T∂x[end,:] = Δx_∂T∂x[end-1,:] + Δy_∂T∂y[:,2:end-1] = diff(yc3, dims=2); Δy_∂T∂y[:,1] = Δy_∂T∂y[:,2]; Δy_∂T∂y[:,end] = Δy_∂T∂y[:,end-1] + Δx_∂q∂x = diff(xqx3, dims=1) + Δy_∂q∂y = diff(yqy3, dims=2) + # Time loop + it=1; iter=1; err=2*ε; err_evo1=[]; err_evo2=[]; + # while (err>ε && iter<=iterMax) + # # BCs + # T[:,1] .= 2*T_South .- T[:,2] # S + # T[:,end] .= 2*T_North .- T[:,end-1] # N + # T[1,:] .= 2*T_West .- T[2,:] # W + # T[end,:] .= 2*T_East .- T[end-1,:] # E + # # Kinematics + # ∂T∂x .= diff(T[:,2:end-1], dims=1)./Δx_∂T∂x + # ∂T∂y .= diff(T[2:end-1,:], dims=2)./Δy_∂T∂y + # # Stresses + # qx .= -kx.*∂T∂x + # qy .= -ky.*∂T∂y + # # Residuals + # RT .= .-diff(qx, dims=1)./Δx_∂q∂x .- diff(qy, dims=2)./Δy_∂q∂y + H + # # PT time step ----------------------------------------------- + # Δτc .= ρ*min(Δx,Δy)^2 ./ kc ./ 4.1 * cfl + # # Calculate rate update -------------------------------------- + # dTdτ .= (1-ρ) .* dTdτ .+ RT + # # Update velocity and pressure ------------------------------- + # T[2:end-1,2:end-1] .+= Δτc ./ ρ .* dTdτ + # # convergence check + # if mod(iter, nout)==0 + # norm_RT = norm(RT)/sqrt(length(RT)) + # err = maximum([norm_RT]) + # push!(err_evo1, err); push!(err_evo2, itg) + # @printf("it = %03d, iter = %04d, err = %1.3e norm[RT=%1.3e] \n", it, itg, err, norm_RT) + # end + # iter+=1; global itg=iter + # end + # Plotting + p1 = heatmap(xce, yce, T', aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), c=:turbo, title="T") + p2 = heatmap( xc, yv, log10.(ky)', aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), c=:turbo, title="ky") + p3 = heatmap( xc, yc, log10.(kc)', aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), c=:turbo, title="kc") + y_int = xv.*tand.(slope) + p4 = plot(xv, y_int, aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), color=:black, label=:none) + ied1 = [ 1 2 3 4] + ied2 = [ 2 3 4 1] + for ic=1:length(XC) + for ied=1:4 + edgex = [vertx[ic, ied1[ied]]; vertx[ic, ied2[ied]]] + edgey = [verty[ic, ied1[ied]]; verty[ic, ied2[ied]]] + p4 = plot!( edgex, edgey, color=:red, label=:none) + end + end + p4 = plot!( XC, YC , marker=:circle, linewidth=0, color=:green, label=:none) + p4 = plot!( xqx3, yqx3, marker=:cross, linewidth=0, color=:green, label=:none) + p4 = plot!( xqy3, yqy3, marker=:cross, linewidth=0, color=:blue, label=:none) + # lines + # for j=1:ncy+1 + # y_line = yv[j]*ones(size(xv)) + # p4 = plot!(xv, y_line, aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), color=:gray, label=:none) + # end + # for i=1:ncx+1 + # x_line = xv[i]*ones(size(yv)) + # p4 = plot!(x_line, yv, aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), color=:gray, label=:none) + # end + # p4 = plot!( xc2, yc2, marker=:circle, linewidth=0, color=:green, label=:none) + display(plot(p1, p2, p3, p4)) + display(plot(p4)) + return +end + +Poisson2D() diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VE_bench_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VE_bench_GeoParams.jl new file mode 100644 index 0000000..3b7b7f2 --- /dev/null +++ b/GeoParams_PT_examples/scripts/Stokes2D_VE_bench_GeoParams.jl @@ -0,0 +1,152 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra, GeoParams +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +# Rheology +@views function UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt ) + ε̇iic = ones(size(ε̇xx)) + ε̇iiv = ones(size(ε̇xy)) + τii0c = sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) + τii0v = zeros(size(ε̇xy)) + τii0v[2:end-1,2:end-1] = sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) + Phase = 1 + # Centroids + for i in eachindex(τxx) + v = MatParam[Phase].CompositeRheology[1] + args = (; τII_old = τii0c[i], dt=Δt) + η_eff = computeViscosity_εII(v, ε̇iic[i], args) + τxx[i] = 2*η_eff*ε̇xx[i] + τyy[i] = 2*η_eff*ε̇yy[i] + end + # Vertices + for i in eachindex(τxy) + v = MatParam[Phase].CompositeRheology[1] + args = (; τII_old = τii0v[i], dt=Δt) + η_eff = computeViscosity_εII(v, ε̇iiv[i], args) + τxy[i] = 2*η_eff*ε̇xy[i] + end +end +# 2D Stokes routine +@views function Stokes2D_VE_benchmark() + # Physics + Lx, Ly = 1.0, 1.0 # domain size + ξ = 10.0 # Maxwell relaxation time + η0 = 1.0 # viscous viscosity + G = 1.0 # elastic shear modulus + εbg = 1.0 # background strain-rate + + MatParam = (SetMaterialParams(Name="Matrix", Phase=1, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G),LinearViscous(η=η0))),) + + # Numerics + nt = 1 # number of time steps + ncx, ncy = 31, 31 # numerical grid resolution + ε = 1e-6 # nonlinear tolerence + iterMax = 1e5 # max number of iters + nout = 200 # check frequency + # Iterative parameters ------------------------------------------- + Reopt = 5π + cfl = 0.5 + ρ = 1#cfl*Reopt/ncx + # Preprocessing + Δx, Δy = Lx/ncx, Ly/ncy + Δt = η0/(G*ξ + 1e-15) + # Array initialisation + Pt = zeros(Dat, ncx ,ncy ) + ∇V = zeros(Dat, ncx ,ncy ) + Vx = zeros(Dat, ncx+1,ncy+2) + Vy = zeros(Dat, ncx+2,ncy+1) + ε̇xx = zeros(Dat, ncx ,ncy ) + ε̇yy = zeros(Dat, ncx ,ncy ) + ε̇xy = zeros(Dat, ncx+1,ncy+1) + τxx = zeros(Dat, ncx ,ncy ) + τyy = zeros(Dat, ncx ,ncy ) + τxy = zeros(Dat, ncx+1,ncy+1) + τxx0 = zeros(Dat, ncx ,ncy ) + τyy0 = zeros(Dat, ncx ,ncy ) + τxy0 = zeros(Dat, ncx+1,ncy+1) + Rx = zeros(Dat, ncx+1,ncy ) + Ry = zeros(Dat, ncx ,ncy+1) + Rp = zeros(Dat, ncx ,ncy ) + dVxdτ = zeros(Dat, ncx+1,ncy ) + dVydτ = zeros(Dat, ncx ,ncy+1) + dPdτ = zeros(Dat, ncx ,ncy ) + Δτv = zeros(Dat, ncx+1,ncy+1) + Δτvx = zeros(Dat, ncx+1,ncy ) + Δτvy = zeros(Dat, ncx ,ncy+1) + κΔτp = zeros(Dat, ncx ,ncy ) + Rog = zeros(Dat, ncx ,ncy ) + ηc = η0*ones(Dat, ncx, ncy) + ηv = η0*ones(Dat, ncx+1, ncy+1) + # Initialisation + xc, yc = LinRange( Δx/2, Lx-Δx/2, ncx+0), LinRange( Δy/2, Ly-Δy/2, ncy+0) + xce, yce = LinRange(-Δx/2, Lx+Δx/2, ncx+2), LinRange(-Δy/2, Ly+Δy/2, ncy+2) + xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) + (Xvx,Yvx) = ([x for x=xv,y=yce], [y for x=xv,y=yce]) + (Xvy,Yvy) = ([x for x=xce,y=yv], [y for x=xce,y=yv]) + Vx .= εbg.*Xvx + Vy .= .-εbg.*Yvy + # Time loop + t=0.0; evo_t=[]; evo_τxx=[] + for it = 1:nt + iter=1; err=2*ε; err_evo1=[]; err_evo2=[]; + τxx0.=τxx; τyy0.=τyy; τxy0.=τxy + while (err>ε && iter<=iterMax) + # BCs + Vx[:,1] .= Vx[:,2] # S + Vx[:,end] .= Vx[:,end-1] # N + Vy[1,:] .= Vy[2,:] # W + Vy[end,:] .= Vy[end-1,:] # E + # Kinematics + ∇V .= diff(Vx[:,2:end-1], dims=1)./Δx .+ diff(Vy[2:end-1,:], dims=2)./Δy + ε̇xx .= diff(Vx[:,2:end-1], dims=1)./Δx .- 1.0/3.0*∇V + ε̇yy .= diff(Vy[2:end-1,:], dims=2)./Δy .- 1.0/3.0*∇V + ε̇xy .= 0.5.*(diff(Vx, dims=2)./Δy .+ diff(Vy, dims=1)./Δx) + # Stresses + UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt ) + if iter==1 + display(τxx') + end + # Residuals + Rx[2:end-1,:] .= .-diff(Pt, dims=1)./Δx .+ diff(τxx, dims=1)./Δx .+ diff(τxy[2:end-1,:], dims=2)./Δy + Ry[:,2:end-1] .= .-diff(Pt, dims=2)./Δy .+ diff(τyy, dims=2)./Δy .+ diff(τxy[:,2:end-1], dims=1)./Δx #.+ av_ya(Rog) + Rp .= .-∇V + # PT time step ----------------------------------------------- + Δτv .= ρ*min(Δx,Δy)^2 ./ ηv ./ 4.1 * cfl + Δτvx .= (Δτv[:,1:end-1] .+ Δτv[:,2:end]) / 2. + Δτvy .= (Δτv[1:end-1,:] .+ Δτv[2:end,:]) / 2. + κΔτp .= cfl .* ηc .* Δx ./ Lx + # Calculate rate update -------------------------------------- + dVxdτ .= (1-ρ) .* dVxdτ .+ Rx + dVydτ .= (1-ρ) .* dVydτ .+ Ry + dPdτ .= Rp + # Update velocity and pressure ------------------------------- + Vx[:,2:end-1] .+= Δτvx ./ ρ .* dVxdτ + Vy[2:end-1,:] .+= Δτvy ./ ρ .* dVydτ + Pt .+= κΔτp .* dPdτ + # convergence check + if mod(iter, nout)==0 + norm_Rx = norm(Rx)/sqrt(length(Rx)); norm_Ry = norm(Ry)/sqrt(length(Ry)); norm_∇V = norm(∇V)/sqrt(length(∇V)) + err = maximum([norm_Rx, norm_Ry, norm_∇V]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %03d, iter = %04d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V) + end + iter+=1; global itg=iter + end + t = t + Δt + push!(evo_t, t); push!(evo_τxx, maximum(τxx)) + # Plotting + p1 = heatmap(xv, yc, Vx[:,2:end-1]', aspect_ratio=1, xlims=(0, Lx), ylims=(Δy/2, Ly-Δy/2), c=:inferno, title="Vx") + p2 = heatmap(xc, yv, Vy[2:end-1,:]', aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p3 = heatmap(xc, yc, ε̇xx' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="P") + p4 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewiΔth=0, markershape=:circle, framestyle=:box, markersize=3) + p4 = plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewiΔth=2.0) # analytical solution + display(plot(p1, p2, p3, p4)) + end + return +end + +Stokes2D_VE_benchmark() diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams.jl new file mode 100644 index 0000000..ba3d781 --- /dev/null +++ b/GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams.jl @@ -0,0 +1,158 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra, GeoParams +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +# Rheology +@views function UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt, Phasec, Phasev ) + ε̇iic = ones(size(ε̇xx)) + ε̇iiv = ones(size(ε̇xy)) + τii0c = sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) + τii0v = zeros(size(ε̇xy)) + τii0v[2:end-1,2:end-1] = sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) + # Centroids + for i in eachindex(τxx) + v = MatParam[Phasec[i]].CompositeRheology[1] + args = (; τII_old = τii0c[i], dt=Δt) + ηc[i] = computeViscosity_εII(v, ε̇iic[i], args) + τxx[i] = 2*ηc[i]*ε̇xx[i] + τyy[i] = 2*ηc[i]*ε̇yy[i] + end + # Vertices + for i in eachindex(τxy) + v = MatParam[Phasev[i]].CompositeRheology[1] + args = (; τII_old = τii0v[i], dt=Δt) + ηv[i] = computeViscosity_εII(v, ε̇iiv[i], args) + τxy[i] = 2*ηv[i]*ε̇xy[i] + end +end +# 2D Stokes routine +@views function Stokes2D_VE_inclusion() + # Physics + Lx, Ly = 1.0, 1.0 # domain size + ξ = 10.0 # Maxwell relaxation time + η0 = 1.0 # viscous viscosity + G = 1.0 # elastic shear modulus + εbg = 1.0 # background strain-rate + radi = 0.01 + + MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G),LinearViscous(η=η0))), + SetMaterialParams(Name="Inclusion", Phase=2, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G*0.1),LinearViscous(η=η0*0.1))), + ) + + # Numerics + nt = 10 # number of time steps + ncx, ncy = 51, 51 # numerical grid resolution + ε = 1e-6 # nonlinear tolerence + iterMax = 1e4 # max number of iters + nout = 500 # check frequency + # Iterative parameters ------------------------------------------- + Reopt = 5π + cfl = 0.5 + ρ = cfl*Reopt/ncx + # Preprocessing + Δx, Δy = Lx/ncx, Ly/ncy + Δt = η0/(G*ξ + 1e-15) + # Array initialisation + Pt = zeros(Dat, ncx ,ncy ) + ∇V = zeros(Dat, ncx ,ncy ) + Vx = zeros(Dat, ncx+1,ncy+2) + Vy = zeros(Dat, ncx+2,ncy+1) + ε̇xx = zeros(Dat, ncx ,ncy ) + ε̇yy = zeros(Dat, ncx ,ncy ) + ε̇xy = zeros(Dat, ncx+1,ncy+1) + τxx = zeros(Dat, ncx ,ncy ) + τyy = zeros(Dat, ncx ,ncy ) + τxy = zeros(Dat, ncx+1,ncy+1) + τxx0 = zeros(Dat, ncx ,ncy ) + τyy0 = zeros(Dat, ncx ,ncy ) + τxy0 = zeros(Dat, ncx+1,ncy+1) + Rx = zeros(Dat, ncx+1,ncy ) + Ry = zeros(Dat, ncx ,ncy+1) + Rp = zeros(Dat, ncx ,ncy ) + dVxdτ = zeros(Dat, ncx+1,ncy ) + dVydτ = zeros(Dat, ncx ,ncy+1) + dPdτ = zeros(Dat, ncx ,ncy ) + Δτv = zeros(Dat, ncx+1,ncy+1) + Δτvx = zeros(Dat, ncx+1,ncy ) + Δτvy = zeros(Dat, ncx ,ncy+1) + κΔτp = zeros(Dat, ncx ,ncy ) + Rog = zeros(Dat, ncx ,ncy ) + ηc = η0*ones(Dat, ncx, ncy) + ηv = η0*ones(Dat, ncx+1, ncy+1) + Phasec = ones(Int, ncx ,ncy ) + Phasev = ones(Int, ncx+1,ncy+1) + # Initialisation + xce, yce = LinRange(-Δx/2, Lx+Δx/2, ncx+2), LinRange(-Δy/2, Ly+Δy/2, ncy+2) + xc, yc = LinRange(Δx/2, Lx-Δx/2, ncx), LinRange(Δy/2, Ly-Δy/2, ncy) + xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + Phasec[radc.ε && iter<=iterMax) + # BCs + Vx[:,1] .= Vx[:,2] # S + Vx[:,end] .= Vx[:,end-1] # N + Vy[1,:] .= Vy[2,:] # W + Vy[end,:] .= Vy[end-1,:] # E + # Kinematics + ∇V .= diff(Vx[:,2:end-1], dims=1)./Δx .+ diff(Vy[2:end-1,:], dims=2)./Δy + ε̇xx .= diff(Vx[:,2:end-1], dims=1)./Δx .- 1.0/3.0*∇V + ε̇yy .= diff(Vy[2:end-1,:], dims=2)./Δy .- 1.0/3.0*∇V + ε̇xy .= 0.5.*(diff(Vx, dims=2)./Δy .+ diff(Vy, dims=1)./Δx) + # Stresses + UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt, Phasec, Phasev ) + # Residuals + Rx[2:end-1,:] .= .-diff(Pt, dims=1)./Δx .+ diff(τxx, dims=1)./Δx .+ diff(τxy[2:end-1,:], dims=2)./Δy + Ry[:,2:end-1] .= .-diff(Pt, dims=2)./Δy .+ diff(τyy, dims=2)./Δy .+ diff(τxy[:,2:end-1], dims=1)./Δx #.+ av_ya(Rog) + Rp .= .-∇V + # PT time step ----------------------------------------------- + Δτv .= ρ*min(Δx,Δy)^2 ./ ηv ./ 4.1 * cfl + Δτvx .= (Δτv[:,1:end-1] .+ Δτv[:,2:end]) / 2. + Δτvy .= (Δτv[1:end-1,:] .+ Δτv[2:end,:]) / 2. + κΔτp .= cfl .* ηc .* Δx ./ Lx + # Calculate rate update -------------------------------------- + dVxdτ .= (1-ρ) .* dVxdτ .+ Rx + dVydτ .= (1-ρ) .* dVydτ .+ Ry + dPdτ .= Rp + # Update velocity and pressure ------------------------------- + Vx[:,2:end-1] .+= Δτvx ./ ρ .* dVxdτ + Vy[2:end-1,:] .+= Δτvy ./ ρ .* dVydτ + Pt .+= κΔτp .* dPdτ + # convergence check + if mod(iter, nout)==0 + norm_Rx = norm(Rx)/sqrt(length(Rx)); norm_Ry = norm(Ry)/sqrt(length(Ry)); norm_∇V = norm(∇V)/sqrt(length(∇V)) + err = maximum([norm_Rx, norm_Ry, norm_∇V]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %03d, iter = %04d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V) + end + iter+=1; global itg=iter + end + t = t + Δt + push!(evo_t, t); push!(evo_τxx, maximum(τxx)) + # Plotting + p1 = heatmap(xv, yc, Vx[:,2:end-1]', aspect_ratio=1, xlims=(0, Lx), ylims=(Δy/2, Ly-Δy/2), c=:inferno, title="Vx") + p2 = heatmap(xc, yv, Vy[2:end-1,:]', aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p3 = heatmap(xc, yc, Pt' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="P") + p4 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + p4 = plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewidth=2.0) # analytical solution + display(plot(p1, p2, p3, p4)) + end + return +end + +Stokes2D_VE_inclusion() \ No newline at end of file diff --git a/GeoParams_PT_examples/scripts/Stokes2D_vep_bench_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_vep_bench_GeoParams.jl new file mode 100644 index 0000000..9a65f9f --- /dev/null +++ b/GeoParams_PT_examples/scripts/Stokes2D_vep_bench_GeoParams.jl @@ -0,0 +1,142 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra, GeoParams +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +# Rheology +# @views function UpdateStress!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, ηc, ηv, Xc, Xv ) +# τxx .= τxx0.*Xc./(Xc.+1.0) .+ 2.0.*ηc.*ε̇xx./(Xc.+1.0) +# τyy .= τyy0.*Xc./(Xc.+1.0) .+ 2.0.*ηc.*ε̇yy./(Xc.+1.0) +# τxy .= τxy0.*Xv./(Xv.+1.0) .+ 2.0.*ηv.*ε̇xy./(Xv.+1.0) +# end +@views function UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, dt ) + ε̇iic = ones(size(ε̇xx)) # dummy strain rate (linear) + ε̇iiv = ones(size(ε̇xy)) # dummy strain rate (linear) + τii0c = sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) + τii0v = zeros(size(ε̇xy)) + τii0v[2:end-1,2:end-1] = sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) + # Update centroids + Phase = 1; + for i in eachindex(τxx) + v = MatParam[Phase].CompositeRheology[1] + args = (; τII_old = τii0c[i], dt=dt, P=0.0) + η_eff = computeViscosity_εII(v, ε̇iic[i], args) + τxx[i] = 2*η_eff*ε̇xx[i] + τyy[i] = 2*η_eff*ε̇yy[i] + end + # Update vertices + for i in eachindex(τxy) + v = MatParam[Phase].CompositeRheology[1] + args = (; τII_old = τii0v[i], dt=dt) + η_eff = computeViscosity_εII(v, ε̇iiv[i], args, P=0.0) + τxy[i] = 2*η_eff*ε̇xy[i] + end +end + +# 2D Stokes routine +@views function Stokes2D_ve() + # Physics + Lx, Ly = 1.0, 1.0 # domain size + ξ = 10.0 # Maxwell relaxation time + η0 = 1.0 # viscous viscosity + G = 1.0 # elastic shear modulus + εbg = 1.0 # background strain-rate + + MatParam = (SetMaterialParams(Name="Matrix", Phase=1, + CompositeRheology = CompositeRheology( + ConstantElasticity(G=G), + LinearViscous(η=η0), + DruckerPrager(C=1.5, ϕ=0))),) + + # Numerics + nt = 50 # number of time steps + ncx, ncy = 31, 31 # numerical grid resolution + Vdmp = 4.0 # convergence acceleration (damping) + Ptsc = 8.0 # iterative time step limiter + ε = 1e-6 # nonlinear tolerence + iterMax = 1e5 # max number of iters + nout = 200 # check frequency + # Preprocessing + dx, dy = Lx/ncx, Ly/ncy + dt = η0/(G*ξ + 1e-15) + # Array initialisation + Pt = zeros(Dat, ncx ,ncy ) + ∇V = zeros(Dat, ncx ,ncy ) + Vx = zeros(Dat, ncx+1,ncy ) + Vy = zeros(Dat, ncx ,ncy+1) + ε̇xx = zeros(Dat, ncx ,ncy ) + ε̇yy = zeros(Dat, ncx ,ncy ) + ε̇xy = zeros(Dat, ncx+1,ncy+1) + τxx = zeros(Dat, ncx ,ncy ) + τyy = zeros(Dat, ncx ,ncy ) + τxy = zeros(Dat, ncx+1,ncy+1) + τxx0 = zeros(Dat, ncx ,ncy ) + τyy0 = zeros(Dat, ncx ,ncy ) + τxy0 = zeros(Dat, ncx+1,ncy+1) + Rx = zeros(Dat, ncx-1,ncy ) + Ry = zeros(Dat, ncx ,ncy-1) + dVxdt = zeros(Dat, ncx-1,ncy ) + dVydt = zeros(Dat, ncx ,ncy-1) + Rog = zeros(Dat, ncx ,ncy ) + Xc = ξ*ones(Dat, ncx, ncy) + Xv = ξ*ones(Dat, ncx+1, ncy+1) + ηc = η0*ones(Dat, ncx, ncy) + ηv = η0*ones(Dat, ncx+1, ncy+1) + # Initialisation + xc, yc = LinRange(dx/2, Lx-dx/2, ncx), LinRange(dy/2, Ly-dy/2, ncy) + xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) + (Xvx,Yvx) = ([x for x=xv,y=yc], [y for x=xv,y=yc]) + (Xvy,Yvy) = ([x for x=xc,y=yv], [y for x=xc,y=yv]) + Vx .= εbg.*Xvx + Vy .= .-εbg.*Yvy + dtVx = min(dx,dy)^2.0./av_xa(ηc)./4.1 + dtVy = min(dx,dy)^2.0./av_ya(ηc)./4.1 + dtPt = 4.1*ηc/max(ncx,ncy)/Ptsc + # Time loop + t=0.0; evo_t=[]; evo_τxx=[] + for it = 1:nt + iter=1; err=2*ε; err_evo1=[]; err_evo2=[]; + τxx0.=τxx; τyy0.=τyy; τxy0.=τxy + while (err>ε && iter<=iterMax) + # divergence - pressure + ∇V .= diff(Vx, dims=1)./dx .+ diff(Vy, dims=2)./dy + Pt .= Pt .- dtPt.*∇V + # strain rates + ε̇xx .= diff(Vx, dims=1)./dx .- 1.0/3.0*∇V + ε̇yy .= diff(Vy, dims=2)./dy .- 1.0/3.0*∇V + ε̇xy[2:end-1,2:end-1] .= 0.5.*(diff(Vx[2:end-1,:], dims=2)./dy .+ diff(Vy[:,2:end-1], dims=1)./dx) + # stresses + UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, dt ) + # UpdateStress!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, ηc, ηv, Xc, Xv ) + # velocities + Rx .= .-diff(Pt, dims=1)./dx .+ diff(τxx, dims=1)./dx .+ diff(τxy[2:end-1,:], dims=2)./dy + Ry .= .-diff(Pt, dims=2)./dy .+ diff(τyy, dims=2)./dy .+ diff(τxy[:,2:end-1], dims=1)./dx .+ av_ya(Rog) + dVxdt .= dVxdt.*(1-Vdmp/ncx) .+ Rx + dVydt .= dVydt.*(1-Vdmp/ncy) .+ Ry + Vx[2:end-1,:] .= Vx[2:end-1,:] .+ dVxdt.*dtVx + Vy[:,2:end-1] .= Vy[:,2:end-1] .+ dVydt.*dtVy + # convergence check + if mod(iter, nout)==0 + norm_Rx = norm(Rx)/length(Rx); norm_Ry = norm(Ry)/length(Ry); norm_∇V = norm(∇V)/length(∇V) + err = maximum([norm_Rx, norm_Ry, norm_∇V]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %d, iter = %d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V) + + end + iter+=1; global itg=iter + end + t = t + dt + push!(evo_t, t); push!(evo_τxx, maximum(τxx)) + # Plotting + p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") + p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p3 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewidth=2.0) # analytical solution + display(plot(p1, p2, p3)) + end + return +end + +Stokes2D_ve() diff --git a/GeoParams_PT_examples/scripts/Stokes2D_vep_reg_vc_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_vep_reg_vc_GeoParams.jl new file mode 100644 index 0000000..3794779 --- /dev/null +++ b/GeoParams_PT_examples/scripts/Stokes2D_vep_reg_vc_GeoParams.jl @@ -0,0 +1,227 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +# Rheology +function UpdateStressVEVP!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xyc, ε̇xxv, ε̇yyv, ε̇xy, τxx0, τyy0, τxy0, τxxv0, τyyv0, τxyv0, ε̇xx1, ε̇yy1, ε̇xy1, ε̇xxv1, ε̇yyv1, ε̇xyv1, τii, τiiv, Pt, Ptv, τ_y, sinϕ, η_ve, η_vev, η_reg, dQdτxx, dQdτyy, dQdτxy, dQdτxxv, dQdτyyv, dQdτxyv, η_e, η_ev, ε̇ii, ε̇iiv ) + # visco-elastic strain rates + ε̇xx1 .= ε̇xx .+ τxx0 ./2.0./η_e + ε̇yy1 .= ε̇yy .+ τyy0 ./2.0./η_e + ε̇xy1 .= ε̇xyc .+ τxy0 ./2.0./η_e + ε̇ii .= sqrt.(0.5*(ε̇xx1.^2 .+ ε̇yy1.^2) .+ ε̇xy1.^2) + # visco-elastic strain rates vertices + ε̇xxv1 .= ε̇xxv .+ τxxv0./2.0./η_ev + ε̇yyv1 .= ε̇yyv .+ τyyv0./2.0./η_ev + ε̇xyv1 .= ε̇xyv .+ τxyv0./2.0./η_ev + ε̇iiv .= sqrt.(0.5*(ε̇xxv1.^2 .+ ε̇yyv1.^2) .+ ε̇xyv1.^2) + # trial stress + τxx .= 2.0.*η_ve.*ε̇xx1 + τyy .= 2.0.*η_ve.*ε̇yy1 + τxy .= 2.0.*η_ve.*ε̇xy1 + τii .= sqrt.(0.5*(τxx.^2 .+ τyy.^2) .+ τxy.^2) + # trial stress vertices + τxxv .= 2.0.*η_vev.*ε̇xxv1 + τyyv .= 2.0.*η_vev.*ε̇yyv1 + τxyv .= 2.0.*η_vev.*ε̇xyv1 + τiiv .= sqrt.(0.5*(τxxv.^2 .+ τyyv.^2) .+ τxyv.^2) + # yield function + F .= τii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(η_ve .+ η_reg) + dQdτxx .= 0.5.*τxx./τii + dQdτyy .= 0.5.*τyy./τii + dQdτxy .= τxy./τii + # yield function vertices + Fv .= τiiv .- τ_y .- Ptv.*sinϕ + Plav .= 0.0 + Plav .= Fv .> 0.0 + λv .= Plav.*Fv./(η_vev .+ η_reg) + dQdτxxv.= 0.5.*τxxv./τiiv + dQdτyyv.= 0.5.*τyyv./τiiv + dQdτxyv.= τxyv./τiiv + # plastic corrections + τxx .= 2.0.*η_ve.*(ε̇xx1 .- λ.*dQdτxx) + τyy .= 2.0.*η_ve.*(ε̇yy1 .- λ.*dQdτyy) + τxy .= 2.0.*η_ve.*(ε̇xy1 .- 0.5.*λ.*dQdτxy) + τii .= sqrt.(0.5*(τxx.^2 .+ τyy.^2) .+ τxy.^2) + Fchk .= τii .- τ_y .- Pt.*sinϕ .- λ.*η_reg + η_vep .= τii./2.0./ε̇ii + # plastic corrections vertices + τxxv .= 2.0.*η_vev.*(ε̇xxv1 .- λv.*dQdτxxv) + τyyv .= 2.0.*η_vev.*(ε̇yyv1 .- λv.*dQdτyyv) + τxyv .= 2.0.*η_vev.*(ε̇xyv1 .- 0.5.*λv.*dQdτxyv) + τiiv .= sqrt.(0.5*(τxxv.^2 .+ τyyv.^2) .+ τxyv.^2) + Fchkv .= τiiv .- τ_y .- Ptv.*sinϕ .- λv.*η_reg + η_vepv .= τiiv./2.0./ε̇iiv +end +# 2D Stokes routine +@views function Stokes2D_vep() + do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) + η_reg = 1.2e-2 # regularisation "viscosity" + # Physics + Lx, Ly = 1.0, 1.0 # domain size + radi = 0.01 # inclusion radius + τ_y = 1.6 # yield stress. If do_DP=true, τ_y stand for the cohesion: c*cos(ϕ) + sinϕ = sind(30)*do_DP # sinus of the friction angle + η0 = 1.0 # viscous viscosity + G0 = 1.0 # elastic shear modulus + Gi = G0/(6.0-4.0*do_DP) # elastic shear modulus perturbation + εbg = 1.0 # background strain-rate + # Numerics + nt = 10 # number of time steps + ncx, ncy = 63, 63 # numerical grid resolution + Vdmp = 4.0 # convergence acceleration (damping) + Vsc = 2.0 # iterative time step limiter + Ptsc = 6.0 # iterative time step limiter + ε = 1e-6 # nonlinear tolerence + iterMax = 3e4 # max number of iters + nout = 200 # check frequency + # Preprocessing + dx, dy = Lx/ncx, Ly/ncy + dt = η0/G0/4.0 # assumes Maxwell time of 4 + # Array initialisation + Pt = zeros(Dat, ncx ,ncy ) + ∇V = zeros(Dat, ncx ,ncy ) + Vx = zeros(Dat, ncx+1,ncy ) + Vy = zeros(Dat, ncx ,ncy+1) + ε̇xx = zeros(Dat, ncx ,ncy ) + ε̇yy = zeros(Dat, ncx ,ncy ) + ε̇xyv = zeros(Dat, ncx+1,ncy+1) + ε̇xy = zeros(Dat, ncx ,ncy ) + ε̇xx1 = zeros(Dat, ncx ,ncy ) + ε̇yy1 = zeros(Dat, ncx ,ncy ) + ε̇xy1 = zeros(Dat, ncx ,ncy ) + ε̇xyv1 = zeros(Dat, ncx+1,ncy+1) + τxx = zeros(Dat, ncx ,ncy ) + τyy = zeros(Dat, ncx ,ncy ) + τxy = zeros(Dat, ncx ,ncy ) + τxyv = zeros(Dat, ncx+1,ncy+1) + τxx0 = zeros(Dat, ncx ,ncy ) + τyy0 = zeros(Dat, ncx ,ncy ) + τxy0 = zeros(Dat, ncx ,ncy ) + τxyv0 = zeros(Dat, ncx+1,ncy+1) + # for vertices implementation + Ptv = zeros(Dat, ncx+1,ncy+1) + ε̇xxv = zeros(Dat, ncx+1,ncy+1) + ε̇yyv = zeros(Dat, ncx+1,ncy+1) + ε̇xxv1 = zeros(Dat, ncx+1,ncy+1) + ε̇yyv1 = zeros(Dat, ncx+1,ncy+1) + τxxv = zeros(Dat, ncx+1,ncy+1) + τyyv = zeros(Dat, ncx+1,ncy+1) + τxxv0 = zeros(Dat, ncx+1,ncy+1) + τyyv0 = zeros(Dat, ncx+1,ncy+1) + Fchkv = zeros(Dat, ncx+1,ncy+1) + Fv = zeros(Dat, ncx+1,ncy+1) + Plav = zeros(Dat, ncx+1,ncy+1) + λv = zeros(Dat, ncx+1,ncy+1) + dQdτxxv = zeros(Dat, ncx+1,ncy+1) + dQdτyyv = zeros(Dat, ncx+1,ncy+1) + dQdτxyv = zeros(Dat, ncx+1,ncy+1) + τiiv = zeros(Dat, ncx+1,ncy+1) + ε̇iiv = zeros(Dat, ncx+1,ncy+1) + # for vertices implementation + τii = zeros(Dat, ncx ,ncy ) + ε̇ii = zeros(Dat, ncx ,ncy ) + F = zeros(Dat, ncx ,ncy ) + Fchk = zeros(Dat, ncx ,ncy ) + Pla = zeros(Dat, ncx ,ncy ) + λ = zeros(Dat, ncx ,ncy ) + dQdτxx = zeros(Dat, ncx ,ncy ) + dQdτyy = zeros(Dat, ncx ,ncy ) + dQdτxy = zeros(Dat, ncx ,ncy ) + Rx = zeros(Dat, ncx-1,ncy ) + Ry = zeros(Dat, ncx ,ncy-1) + dVxdt = zeros(Dat, ncx-1,ncy ) + dVydt = zeros(Dat, ncx ,ncy-1) + dtPt = zeros(Dat, ncx ,ncy ) + dtVx = zeros(Dat, ncx-1,ncy ) + dtVy = zeros(Dat, ncx ,ncy-1) + Rog = zeros(Dat, ncx ,ncy ) + η_v = η0*ones(Dat, ncx ,ncy ) + η_e = dt*G0*ones(Dat, ncx ,ncy ) + η_ev = dt*G0*ones(Dat, ncx+1,ncy+1) + η_ve = ones(Dat, ncx ,ncy ) + η_vep = ones(Dat, ncx ,ncy ) + η_vepv = ones(Dat, ncx+1,ncy+1) + η_vev = ones(Dat, ncx+1,ncy+1) # for vertices implementation + η_vv = η0*ones(Dat, ncx+1,ncy+1) # for vertices implementation + # Initial condition + xc, yc = LinRange(dx/2, Lx-dx/2, ncx), LinRange(dy/2, Ly-dy/2, ncy) + xc, yc = LinRange(dx/2, Lx-dx/2, ncx), LinRange(dy/2, Ly-dy/2, ncy) + xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) + (Xvx,Yvx) = ([x for x=xv,y=yc], [y for x=xv,y=yc]) + (Xvy,Yvy) = ([x for x=xc,y=yv], [y for x=xc,y=yv]) + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + Phasec = ones(Int, ncx ,ncy ) + Phasev = ones(Int, ncx+1,ncy+1) + Phasec[radc.ε && iter<=iterMax) + # divergence - pressure + ∇V .= diff(Vx, dims=1)./dx .+ diff(Vy, dims=2)./dy + Pt .= Pt .- dtPt.*∇V + # strain rates + ε̇xx .= diff(Vx, dims=1)./dx .- 1.0/3.0*∇V + ε̇yy .= diff(Vy, dims=2)./dy .- 1.0/3.0*∇V + ε̇xyv[2:end-1,2:end-1] .= 0.5.*(diff(Vx[2:end-1,:], dims=2)./dy .+ diff(Vy[:,2:end-1], dims=1)./dx) + ε̇xxv[2:end-1,2:end-1] .= av(ε̇xx); ε̇xxv[1,:].=ε̇xxv[2,:]; ε̇xxv[end,:].=ε̇xxv[end-1,:]; ε̇xxv[:,1].=ε̇xxv[:,2]; ε̇xxv[:,end].=ε̇xxv[:,end-1] + ε̇yyv[2:end-1,2:end-1] .= av(ε̇yy); ε̇yyv[1,:].=ε̇yyv[2,:]; ε̇yyv[end,:].=ε̇yyv[end-1,:]; ε̇yyv[:,1].=ε̇yyv[:,2]; ε̇yyv[:,end].=ε̇yyv[:,end-1] + Ptv[2:end-1,2:end-1] .= av(Pt); Ptv[1,:].= Ptv[2,:]; Ptv[end,:].= Ptv[end-1,:]; Ptv[:,1].= Ptv[:,2]; Ptv[:,end].= Ptv[:,end-1] + ε̇xy .= av(ε̇xyv) + # Rheology + UpdateStressVEVP!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, ε̇xxv, ε̇yyv, ε̇xy, τxx0, τyy0, τxy0, τxxv0, τyyv0, τxyv0, ε̇xx1, ε̇yy1, ε̇xy1, ε̇xxv1, ε̇yyv1, ε̇xyv1, τii, τiiv, Pt, Ptv, τ_y, sinϕ, η_ve, η_vev, η_reg, dQdτxx, dQdτyy, dQdτxy, dQdτxxv, dQdτyyv, dQdτxyv, η_e, η_ev, ε̇ii, ε̇iiv ) + # PT timestep + dtVx .= min(dx,dy)^2.0./av_xa(η_vep)./4.1./Vsc + dtVy .= min(dx,dy)^2.0./av_ya(η_vep)./4.1./Vsc + dtPt .= 4.1.*η_vep./max(ncx,ncy)./Ptsc + # velocities + Rx .= .-diff(Pt, dims=1)./dx .+ diff(τxx, dims=1)./dx .+ diff(τxyv[2:end-1,:], dims=2)./dy + Ry .= .-diff(Pt, dims=2)./dy .+ diff(τyy, dims=2)./dy .+ diff(τxyv[:,2:end-1], dims=1)./dx .+ av_ya(Rog) + dVxdt .= dVxdt.*(1-Vdmp/ncx) .+ Rx + dVydt .= dVydt.*(1-Vdmp/ncy) .+ Ry + Vx[2:end-1,:] .= Vx[2:end-1,:] .+ dVxdt.*dtVx + Vy[:,2:end-1] .= Vy[:,2:end-1] .+ dVydt.*dtVy + # convergence check + if mod(iter, nout)==0 + norm_Rx = norm(Rx)/length(Rx); norm_Ry = norm(Ry)/length(Ry); norm_∇V = norm(∇V)/length(∇V) + err = maximum([norm_Rx, norm_Ry, norm_∇V]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %d, iter = %d, err = %1.2e norm[Rx=%1.2e, Ry=%1.2e, ∇V=%1.2e] (Fchk=%1.2e - Fchkv=%1.2e) \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V, maximum(Fchk), maximum(Fchkv)) + end + iter+=1; itg=iter + end + t = t + dt + push!(evo_t, t); push!(evo_τxx, maximum(τxx)) + # Plotting + p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") + # p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p2 = heatmap(xc, yc, η_vep' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="η_vep") + p3 = heatmap(xc, yc, τii' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="τii") + p4 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G0./η0)), linewidth=2.0) # analytical solution for VE loading + plot!(evo_t, 2.0.*εbg.*η0.*ones(size(evo_t)), linewidth=2.0) # viscous flow stress + if !do_DP plot!(evo_t, τ_y*ones(size(evo_t)), linewidth=2.0) end # von Mises yield stress + display(plot(p1, p2, p3, p4)) + end + return +end + +Stokes2D_vep() From 34c076f04e9e2115747641ce7b861c958ad0a778 Mon Sep 17 00:00:00 2001 From: Duretz Thibault Date: Sun, 9 Oct 2022 21:50:44 +0200 Subject: [PATCH 06/49] remove.vscode --- GeoParams_PT_examples/.vscode/settings.json | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 GeoParams_PT_examples/.vscode/settings.json diff --git a/GeoParams_PT_examples/.vscode/settings.json b/GeoParams_PT_examples/.vscode/settings.json deleted file mode 100644 index 7a73a41..0000000 --- a/GeoParams_PT_examples/.vscode/settings.json +++ /dev/null @@ -1,2 +0,0 @@ -{ -} \ No newline at end of file From f067dd7c22d0963b65086ff334e7c9d983422c0d Mon Sep 17 00:00:00 2001 From: Duretz Thibault Date: Sun, 9 Oct 2022 21:52:30 +0200 Subject: [PATCH 07/49] remove src --- GeoParams_PT_examples/src/Poisson2D_PT_v0.jl | 113 --------- .../src/Stokes2D_VE_bench_GeoParams.jl | 152 ------------ .../src/Stokes2D_VE_inclusion_GeoParams.jl | 158 ------------ .../src/Stokes2D_vep_bench_GeoParams.jl | 142 ----------- .../src/Stokes2D_vep_reg_vc_GeoParams.jl | 227 ------------------ 5 files changed, 792 deletions(-) delete mode 100644 GeoParams_PT_examples/src/Poisson2D_PT_v0.jl delete mode 100644 GeoParams_PT_examples/src/Stokes2D_VE_bench_GeoParams.jl delete mode 100644 GeoParams_PT_examples/src/Stokes2D_VE_inclusion_GeoParams.jl delete mode 100644 GeoParams_PT_examples/src/Stokes2D_vep_bench_GeoParams.jl delete mode 100644 GeoParams_PT_examples/src/Stokes2D_vep_reg_vc_GeoParams.jl diff --git a/GeoParams_PT_examples/src/Poisson2D_PT_v0.jl b/GeoParams_PT_examples/src/Poisson2D_PT_v0.jl deleted file mode 100644 index 89546f1..0000000 --- a/GeoParams_PT_examples/src/Poisson2D_PT_v0.jl +++ /dev/null @@ -1,113 +0,0 @@ -# Initialisation -using Plots, Printf, Statistics, LinearAlgebra -Dat = Float64 # Precision (double=Float64 or single=Float32) -# Macros -@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) -@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) -@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) -@views avh(A) = ( 0.25./A[1:end-1,1:end-1] .+ 0.25./A[1:end-1,2:end-0] .+ 0.25./A[2:end-0,1:end-1] .+ 0.25./A[2:end-0,2:end-0]).^(-1) -# 2D Poisson routine -@views function Poisson2D() - # Physics - Lx, Ly = 6.0, 6.0 # domain size - T_West = 0.0 - T_East = 0.0 - T_South = 0.0 - T_North = 0.0 - slope = -15. - k1 = 1 - k2 = 1e4 - # Numerics - ncx, ncy = 51, 51 # numerical grid resolution - ε = 1e-6 # nonlinear tolerence - iterMax = 1e4 # max number of iters - nout = 500 # check frequency - # Iterative parameters ------------------------------------------- - Reopt = 0.625*π - cfl = 0.32 - ρ = cfl*Reopt/ncx - nsm = 5 - # Reopt = 0.625*π /3 - # cfl = 0.3*4 - # ρ = cfl*Reopt/ncx - # nsm = 10 - # Preprocessing - Δx, Δy = Lx/ncx, Ly/ncy - # Array initialisation - T = zeros(Dat, ncx+2, ncy+2) - ∂T∂x = zeros(Dat, ncx+1, ncy ) - ∂T∂y = zeros(Dat, ncx , ncy+1) - qx = zeros(Dat, ncx+1, ncy ) - qy = zeros(Dat, ncx , ncy+1) - RT = zeros(Dat, ncx , ncy ) - dTdτ = zeros(Dat, ncx , ncy ) - Δτc = zeros(Dat, ncx , ncy ) - kv = k1*ones(Dat, ncx+1, ncy+1) - kx = zeros(Dat, ncx+1, ncy+0) - ky = zeros(Dat, ncx+0, ncy+1) - H = ones(Dat, ncx , ncy ) - # Initialisation - xc, yc = LinRange(-Lx/2+Δx/2, Lx/2-Δx/2, ncx+0), LinRange(-Ly/2+Δy/2, Ly/2-Δy/2, ncy+0) - xce, yce = LinRange(-Lx/2-Δx/2, Lx/2+Δx/2, ncx+2), LinRange(-Ly/2-Δy/2, Ly/2+Δy/2, ncy+2) - xv, yv = LinRange(-Lx/2, Lx/2, ncx+1), LinRange(-Ly/2, Ly/2, ncy+1) - (xv2,yv2) = ([x for x=xv,y=yv], [y for x=xv,y=yv]) - below = yv2 .< xv2.*tand.(slope) - kv[below] .= k2 - kx .= ( 0.5./kv[:,1:end-1] .+ 0.5./kv[:,2:end-0]).^(-1) - ky .= ( 0.5./kv[1:end-1,:] .+ 0.5./kv[2:end-0,:]).^(-1) - kc = ( 0.25./kv[1:end-1,1:end-1] .+ 0.25./kv[1:end-1,2:end-0] .+ 0.25./kv[2:end-0,1:end-1] .+ 0.25./kv[2:end-0,2:end-0]).^(-1) - for it = 1:nsm - kv[2:end-1,2:end-1] .= av(kc) - kc = av(kv) - end - # Time loop - it=1; iter=1; err=2*ε; err_evo1=[]; err_evo2=[]; - while (err>ε && iter<=iterMax) - # BCs - T[:,1] .= 2*T_South .- T[:,2] # S - T[:,end] .= 2*T_North .- T[:,end-1] # N - T[1,:] .= 2*T_West .- T[2,:] # W - T[end,:] .= 2*T_East .- T[end-1,:] # E - # Kinematics - ∂T∂x .= diff(T[:,2:end-1], dims=1)./Δx - ∂T∂y .= diff(T[2:end-1,:], dims=2)./Δy - # Stresses - qx .= -kx.*∂T∂x - qy .= -ky.*∂T∂y - # Residuals - RT .= .-diff(qx, dims=1)./Δx .- diff(qy, dims=2)./Δy + H - # PT time step ----------------------------------------------- - Δτc .= ρ*min(Δx,Δy)^2 ./ kc ./ 4.1 * cfl - # Calculate rate update -------------------------------------- - dTdτ .= (1-ρ) .* dTdτ .+ RT - # Update velocity and pressure ------------------------------- - T[2:end-1,2:end-1] .+= Δτc ./ ρ .* dTdτ - # convergence check - if mod(iter, nout)==0 - norm_RT = norm(RT)/sqrt(length(RT)) - err = maximum([norm_RT]) - push!(err_evo1, err); push!(err_evo2, itg) - @printf("it = %03d, iter = %04d, err = %1.3e norm[RT=%1.3e] \n", it, itg, err, norm_RT) - end - iter+=1; global itg=iter - end - # Plotting - p1 = heatmap(xce, yce, T', aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), c=:turbo, title="T") - p2 = heatmap( xc, yv, log10.(ky)', aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), c=:turbo, title="ky") - p3 = heatmap( xc, yc, log10.(kc)', aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), c=:turbo, title="kc") - y_int = xv.*tand.(slope) - p4 = plot(xv, y_int, aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), color=:black, label=:none) - # lines - for j=1:ncy+1 - y_line = yv[j]*ones(size(xv)) - p4 = plot!(xv, y_line, aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), color=:gray, label=:none) - end - for i=1:ncx+1 - x_line = xv[i]*ones(size(yv)) - p4 = plot!(x_line, yv, aspect_ratio=1, xlims=(-Lx/2, Lx/2), ylims=(-Ly/2, Ly/2), color=:gray, label=:none) - end - display(plot(p1, p2, p3, p4)) - return -end - -Poisson2D() diff --git a/GeoParams_PT_examples/src/Stokes2D_VE_bench_GeoParams.jl b/GeoParams_PT_examples/src/Stokes2D_VE_bench_GeoParams.jl deleted file mode 100644 index 3b7b7f2..0000000 --- a/GeoParams_PT_examples/src/Stokes2D_VE_bench_GeoParams.jl +++ /dev/null @@ -1,152 +0,0 @@ -# Initialisation -using Plots, Printf, Statistics, LinearAlgebra, GeoParams -Dat = Float64 # Precision (double=Float64 or single=Float32) -# Macros -@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) -@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) -@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) -# Rheology -@views function UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt ) - ε̇iic = ones(size(ε̇xx)) - ε̇iiv = ones(size(ε̇xy)) - τii0c = sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) - τii0v = zeros(size(ε̇xy)) - τii0v[2:end-1,2:end-1] = sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) - Phase = 1 - # Centroids - for i in eachindex(τxx) - v = MatParam[Phase].CompositeRheology[1] - args = (; τII_old = τii0c[i], dt=Δt) - η_eff = computeViscosity_εII(v, ε̇iic[i], args) - τxx[i] = 2*η_eff*ε̇xx[i] - τyy[i] = 2*η_eff*ε̇yy[i] - end - # Vertices - for i in eachindex(τxy) - v = MatParam[Phase].CompositeRheology[1] - args = (; τII_old = τii0v[i], dt=Δt) - η_eff = computeViscosity_εII(v, ε̇iiv[i], args) - τxy[i] = 2*η_eff*ε̇xy[i] - end -end -# 2D Stokes routine -@views function Stokes2D_VE_benchmark() - # Physics - Lx, Ly = 1.0, 1.0 # domain size - ξ = 10.0 # Maxwell relaxation time - η0 = 1.0 # viscous viscosity - G = 1.0 # elastic shear modulus - εbg = 1.0 # background strain-rate - - MatParam = (SetMaterialParams(Name="Matrix", Phase=1, - CompositeRheology = CompositeRheology(ConstantElasticity(G=G),LinearViscous(η=η0))),) - - # Numerics - nt = 1 # number of time steps - ncx, ncy = 31, 31 # numerical grid resolution - ε = 1e-6 # nonlinear tolerence - iterMax = 1e5 # max number of iters - nout = 200 # check frequency - # Iterative parameters ------------------------------------------- - Reopt = 5π - cfl = 0.5 - ρ = 1#cfl*Reopt/ncx - # Preprocessing - Δx, Δy = Lx/ncx, Ly/ncy - Δt = η0/(G*ξ + 1e-15) - # Array initialisation - Pt = zeros(Dat, ncx ,ncy ) - ∇V = zeros(Dat, ncx ,ncy ) - Vx = zeros(Dat, ncx+1,ncy+2) - Vy = zeros(Dat, ncx+2,ncy+1) - ε̇xx = zeros(Dat, ncx ,ncy ) - ε̇yy = zeros(Dat, ncx ,ncy ) - ε̇xy = zeros(Dat, ncx+1,ncy+1) - τxx = zeros(Dat, ncx ,ncy ) - τyy = zeros(Dat, ncx ,ncy ) - τxy = zeros(Dat, ncx+1,ncy+1) - τxx0 = zeros(Dat, ncx ,ncy ) - τyy0 = zeros(Dat, ncx ,ncy ) - τxy0 = zeros(Dat, ncx+1,ncy+1) - Rx = zeros(Dat, ncx+1,ncy ) - Ry = zeros(Dat, ncx ,ncy+1) - Rp = zeros(Dat, ncx ,ncy ) - dVxdτ = zeros(Dat, ncx+1,ncy ) - dVydτ = zeros(Dat, ncx ,ncy+1) - dPdτ = zeros(Dat, ncx ,ncy ) - Δτv = zeros(Dat, ncx+1,ncy+1) - Δτvx = zeros(Dat, ncx+1,ncy ) - Δτvy = zeros(Dat, ncx ,ncy+1) - κΔτp = zeros(Dat, ncx ,ncy ) - Rog = zeros(Dat, ncx ,ncy ) - ηc = η0*ones(Dat, ncx, ncy) - ηv = η0*ones(Dat, ncx+1, ncy+1) - # Initialisation - xc, yc = LinRange( Δx/2, Lx-Δx/2, ncx+0), LinRange( Δy/2, Ly-Δy/2, ncy+0) - xce, yce = LinRange(-Δx/2, Lx+Δx/2, ncx+2), LinRange(-Δy/2, Ly+Δy/2, ncy+2) - xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) - (Xvx,Yvx) = ([x for x=xv,y=yce], [y for x=xv,y=yce]) - (Xvy,Yvy) = ([x for x=xce,y=yv], [y for x=xce,y=yv]) - Vx .= εbg.*Xvx - Vy .= .-εbg.*Yvy - # Time loop - t=0.0; evo_t=[]; evo_τxx=[] - for it = 1:nt - iter=1; err=2*ε; err_evo1=[]; err_evo2=[]; - τxx0.=τxx; τyy0.=τyy; τxy0.=τxy - while (err>ε && iter<=iterMax) - # BCs - Vx[:,1] .= Vx[:,2] # S - Vx[:,end] .= Vx[:,end-1] # N - Vy[1,:] .= Vy[2,:] # W - Vy[end,:] .= Vy[end-1,:] # E - # Kinematics - ∇V .= diff(Vx[:,2:end-1], dims=1)./Δx .+ diff(Vy[2:end-1,:], dims=2)./Δy - ε̇xx .= diff(Vx[:,2:end-1], dims=1)./Δx .- 1.0/3.0*∇V - ε̇yy .= diff(Vy[2:end-1,:], dims=2)./Δy .- 1.0/3.0*∇V - ε̇xy .= 0.5.*(diff(Vx, dims=2)./Δy .+ diff(Vy, dims=1)./Δx) - # Stresses - UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt ) - if iter==1 - display(τxx') - end - # Residuals - Rx[2:end-1,:] .= .-diff(Pt, dims=1)./Δx .+ diff(τxx, dims=1)./Δx .+ diff(τxy[2:end-1,:], dims=2)./Δy - Ry[:,2:end-1] .= .-diff(Pt, dims=2)./Δy .+ diff(τyy, dims=2)./Δy .+ diff(τxy[:,2:end-1], dims=1)./Δx #.+ av_ya(Rog) - Rp .= .-∇V - # PT time step ----------------------------------------------- - Δτv .= ρ*min(Δx,Δy)^2 ./ ηv ./ 4.1 * cfl - Δτvx .= (Δτv[:,1:end-1] .+ Δτv[:,2:end]) / 2. - Δτvy .= (Δτv[1:end-1,:] .+ Δτv[2:end,:]) / 2. - κΔτp .= cfl .* ηc .* Δx ./ Lx - # Calculate rate update -------------------------------------- - dVxdτ .= (1-ρ) .* dVxdτ .+ Rx - dVydτ .= (1-ρ) .* dVydτ .+ Ry - dPdτ .= Rp - # Update velocity and pressure ------------------------------- - Vx[:,2:end-1] .+= Δτvx ./ ρ .* dVxdτ - Vy[2:end-1,:] .+= Δτvy ./ ρ .* dVydτ - Pt .+= κΔτp .* dPdτ - # convergence check - if mod(iter, nout)==0 - norm_Rx = norm(Rx)/sqrt(length(Rx)); norm_Ry = norm(Ry)/sqrt(length(Ry)); norm_∇V = norm(∇V)/sqrt(length(∇V)) - err = maximum([norm_Rx, norm_Ry, norm_∇V]) - push!(err_evo1, err); push!(err_evo2, itg) - @printf("it = %03d, iter = %04d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V) - end - iter+=1; global itg=iter - end - t = t + Δt - push!(evo_t, t); push!(evo_τxx, maximum(τxx)) - # Plotting - p1 = heatmap(xv, yc, Vx[:,2:end-1]', aspect_ratio=1, xlims=(0, Lx), ylims=(Δy/2, Ly-Δy/2), c=:inferno, title="Vx") - p2 = heatmap(xc, yv, Vy[2:end-1,:]', aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="Vy") - p3 = heatmap(xc, yc, ε̇xx' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="P") - p4 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewiΔth=0, markershape=:circle, framestyle=:box, markersize=3) - p4 = plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewiΔth=2.0) # analytical solution - display(plot(p1, p2, p3, p4)) - end - return -end - -Stokes2D_VE_benchmark() diff --git a/GeoParams_PT_examples/src/Stokes2D_VE_inclusion_GeoParams.jl b/GeoParams_PT_examples/src/Stokes2D_VE_inclusion_GeoParams.jl deleted file mode 100644 index ba3d781..0000000 --- a/GeoParams_PT_examples/src/Stokes2D_VE_inclusion_GeoParams.jl +++ /dev/null @@ -1,158 +0,0 @@ -# Initialisation -using Plots, Printf, Statistics, LinearAlgebra, GeoParams -Dat = Float64 # Precision (double=Float64 or single=Float32) -# Macros -@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) -@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) -@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) -# Rheology -@views function UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt, Phasec, Phasev ) - ε̇iic = ones(size(ε̇xx)) - ε̇iiv = ones(size(ε̇xy)) - τii0c = sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) - τii0v = zeros(size(ε̇xy)) - τii0v[2:end-1,2:end-1] = sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) - # Centroids - for i in eachindex(τxx) - v = MatParam[Phasec[i]].CompositeRheology[1] - args = (; τII_old = τii0c[i], dt=Δt) - ηc[i] = computeViscosity_εII(v, ε̇iic[i], args) - τxx[i] = 2*ηc[i]*ε̇xx[i] - τyy[i] = 2*ηc[i]*ε̇yy[i] - end - # Vertices - for i in eachindex(τxy) - v = MatParam[Phasev[i]].CompositeRheology[1] - args = (; τII_old = τii0v[i], dt=Δt) - ηv[i] = computeViscosity_εII(v, ε̇iiv[i], args) - τxy[i] = 2*ηv[i]*ε̇xy[i] - end -end -# 2D Stokes routine -@views function Stokes2D_VE_inclusion() - # Physics - Lx, Ly = 1.0, 1.0 # domain size - ξ = 10.0 # Maxwell relaxation time - η0 = 1.0 # viscous viscosity - G = 1.0 # elastic shear modulus - εbg = 1.0 # background strain-rate - radi = 0.01 - - MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, - CompositeRheology = CompositeRheology(ConstantElasticity(G=G),LinearViscous(η=η0))), - SetMaterialParams(Name="Inclusion", Phase=2, - CompositeRheology = CompositeRheology(ConstantElasticity(G=G*0.1),LinearViscous(η=η0*0.1))), - ) - - # Numerics - nt = 10 # number of time steps - ncx, ncy = 51, 51 # numerical grid resolution - ε = 1e-6 # nonlinear tolerence - iterMax = 1e4 # max number of iters - nout = 500 # check frequency - # Iterative parameters ------------------------------------------- - Reopt = 5π - cfl = 0.5 - ρ = cfl*Reopt/ncx - # Preprocessing - Δx, Δy = Lx/ncx, Ly/ncy - Δt = η0/(G*ξ + 1e-15) - # Array initialisation - Pt = zeros(Dat, ncx ,ncy ) - ∇V = zeros(Dat, ncx ,ncy ) - Vx = zeros(Dat, ncx+1,ncy+2) - Vy = zeros(Dat, ncx+2,ncy+1) - ε̇xx = zeros(Dat, ncx ,ncy ) - ε̇yy = zeros(Dat, ncx ,ncy ) - ε̇xy = zeros(Dat, ncx+1,ncy+1) - τxx = zeros(Dat, ncx ,ncy ) - τyy = zeros(Dat, ncx ,ncy ) - τxy = zeros(Dat, ncx+1,ncy+1) - τxx0 = zeros(Dat, ncx ,ncy ) - τyy0 = zeros(Dat, ncx ,ncy ) - τxy0 = zeros(Dat, ncx+1,ncy+1) - Rx = zeros(Dat, ncx+1,ncy ) - Ry = zeros(Dat, ncx ,ncy+1) - Rp = zeros(Dat, ncx ,ncy ) - dVxdτ = zeros(Dat, ncx+1,ncy ) - dVydτ = zeros(Dat, ncx ,ncy+1) - dPdτ = zeros(Dat, ncx ,ncy ) - Δτv = zeros(Dat, ncx+1,ncy+1) - Δτvx = zeros(Dat, ncx+1,ncy ) - Δτvy = zeros(Dat, ncx ,ncy+1) - κΔτp = zeros(Dat, ncx ,ncy ) - Rog = zeros(Dat, ncx ,ncy ) - ηc = η0*ones(Dat, ncx, ncy) - ηv = η0*ones(Dat, ncx+1, ncy+1) - Phasec = ones(Int, ncx ,ncy ) - Phasev = ones(Int, ncx+1,ncy+1) - # Initialisation - xce, yce = LinRange(-Δx/2, Lx+Δx/2, ncx+2), LinRange(-Δy/2, Ly+Δy/2, ncy+2) - xc, yc = LinRange(Δx/2, Lx-Δx/2, ncx), LinRange(Δy/2, Ly-Δy/2, ncy) - xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) - radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 - radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 - Phasec[radc.ε && iter<=iterMax) - # BCs - Vx[:,1] .= Vx[:,2] # S - Vx[:,end] .= Vx[:,end-1] # N - Vy[1,:] .= Vy[2,:] # W - Vy[end,:] .= Vy[end-1,:] # E - # Kinematics - ∇V .= diff(Vx[:,2:end-1], dims=1)./Δx .+ diff(Vy[2:end-1,:], dims=2)./Δy - ε̇xx .= diff(Vx[:,2:end-1], dims=1)./Δx .- 1.0/3.0*∇V - ε̇yy .= diff(Vy[2:end-1,:], dims=2)./Δy .- 1.0/3.0*∇V - ε̇xy .= 0.5.*(diff(Vx, dims=2)./Δy .+ diff(Vy, dims=1)./Δx) - # Stresses - UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt, Phasec, Phasev ) - # Residuals - Rx[2:end-1,:] .= .-diff(Pt, dims=1)./Δx .+ diff(τxx, dims=1)./Δx .+ diff(τxy[2:end-1,:], dims=2)./Δy - Ry[:,2:end-1] .= .-diff(Pt, dims=2)./Δy .+ diff(τyy, dims=2)./Δy .+ diff(τxy[:,2:end-1], dims=1)./Δx #.+ av_ya(Rog) - Rp .= .-∇V - # PT time step ----------------------------------------------- - Δτv .= ρ*min(Δx,Δy)^2 ./ ηv ./ 4.1 * cfl - Δτvx .= (Δτv[:,1:end-1] .+ Δτv[:,2:end]) / 2. - Δτvy .= (Δτv[1:end-1,:] .+ Δτv[2:end,:]) / 2. - κΔτp .= cfl .* ηc .* Δx ./ Lx - # Calculate rate update -------------------------------------- - dVxdτ .= (1-ρ) .* dVxdτ .+ Rx - dVydτ .= (1-ρ) .* dVydτ .+ Ry - dPdτ .= Rp - # Update velocity and pressure ------------------------------- - Vx[:,2:end-1] .+= Δτvx ./ ρ .* dVxdτ - Vy[2:end-1,:] .+= Δτvy ./ ρ .* dVydτ - Pt .+= κΔτp .* dPdτ - # convergence check - if mod(iter, nout)==0 - norm_Rx = norm(Rx)/sqrt(length(Rx)); norm_Ry = norm(Ry)/sqrt(length(Ry)); norm_∇V = norm(∇V)/sqrt(length(∇V)) - err = maximum([norm_Rx, norm_Ry, norm_∇V]) - push!(err_evo1, err); push!(err_evo2, itg) - @printf("it = %03d, iter = %04d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V) - end - iter+=1; global itg=iter - end - t = t + Δt - push!(evo_t, t); push!(evo_τxx, maximum(τxx)) - # Plotting - p1 = heatmap(xv, yc, Vx[:,2:end-1]', aspect_ratio=1, xlims=(0, Lx), ylims=(Δy/2, Ly-Δy/2), c=:inferno, title="Vx") - p2 = heatmap(xc, yv, Vy[2:end-1,:]', aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="Vy") - p3 = heatmap(xc, yc, Pt' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="P") - p4 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) - p4 = plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewidth=2.0) # analytical solution - display(plot(p1, p2, p3, p4)) - end - return -end - -Stokes2D_VE_inclusion() \ No newline at end of file diff --git a/GeoParams_PT_examples/src/Stokes2D_vep_bench_GeoParams.jl b/GeoParams_PT_examples/src/Stokes2D_vep_bench_GeoParams.jl deleted file mode 100644 index 9a65f9f..0000000 --- a/GeoParams_PT_examples/src/Stokes2D_vep_bench_GeoParams.jl +++ /dev/null @@ -1,142 +0,0 @@ -# Initialisation -using Plots, Printf, Statistics, LinearAlgebra, GeoParams -Dat = Float64 # Precision (double=Float64 or single=Float32) -# Macros -@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) -@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) -@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) -# Rheology -# @views function UpdateStress!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, ηc, ηv, Xc, Xv ) -# τxx .= τxx0.*Xc./(Xc.+1.0) .+ 2.0.*ηc.*ε̇xx./(Xc.+1.0) -# τyy .= τyy0.*Xc./(Xc.+1.0) .+ 2.0.*ηc.*ε̇yy./(Xc.+1.0) -# τxy .= τxy0.*Xv./(Xv.+1.0) .+ 2.0.*ηv.*ε̇xy./(Xv.+1.0) -# end -@views function UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, dt ) - ε̇iic = ones(size(ε̇xx)) # dummy strain rate (linear) - ε̇iiv = ones(size(ε̇xy)) # dummy strain rate (linear) - τii0c = sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) - τii0v = zeros(size(ε̇xy)) - τii0v[2:end-1,2:end-1] = sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) - # Update centroids - Phase = 1; - for i in eachindex(τxx) - v = MatParam[Phase].CompositeRheology[1] - args = (; τII_old = τii0c[i], dt=dt, P=0.0) - η_eff = computeViscosity_εII(v, ε̇iic[i], args) - τxx[i] = 2*η_eff*ε̇xx[i] - τyy[i] = 2*η_eff*ε̇yy[i] - end - # Update vertices - for i in eachindex(τxy) - v = MatParam[Phase].CompositeRheology[1] - args = (; τII_old = τii0v[i], dt=dt) - η_eff = computeViscosity_εII(v, ε̇iiv[i], args, P=0.0) - τxy[i] = 2*η_eff*ε̇xy[i] - end -end - -# 2D Stokes routine -@views function Stokes2D_ve() - # Physics - Lx, Ly = 1.0, 1.0 # domain size - ξ = 10.0 # Maxwell relaxation time - η0 = 1.0 # viscous viscosity - G = 1.0 # elastic shear modulus - εbg = 1.0 # background strain-rate - - MatParam = (SetMaterialParams(Name="Matrix", Phase=1, - CompositeRheology = CompositeRheology( - ConstantElasticity(G=G), - LinearViscous(η=η0), - DruckerPrager(C=1.5, ϕ=0))),) - - # Numerics - nt = 50 # number of time steps - ncx, ncy = 31, 31 # numerical grid resolution - Vdmp = 4.0 # convergence acceleration (damping) - Ptsc = 8.0 # iterative time step limiter - ε = 1e-6 # nonlinear tolerence - iterMax = 1e5 # max number of iters - nout = 200 # check frequency - # Preprocessing - dx, dy = Lx/ncx, Ly/ncy - dt = η0/(G*ξ + 1e-15) - # Array initialisation - Pt = zeros(Dat, ncx ,ncy ) - ∇V = zeros(Dat, ncx ,ncy ) - Vx = zeros(Dat, ncx+1,ncy ) - Vy = zeros(Dat, ncx ,ncy+1) - ε̇xx = zeros(Dat, ncx ,ncy ) - ε̇yy = zeros(Dat, ncx ,ncy ) - ε̇xy = zeros(Dat, ncx+1,ncy+1) - τxx = zeros(Dat, ncx ,ncy ) - τyy = zeros(Dat, ncx ,ncy ) - τxy = zeros(Dat, ncx+1,ncy+1) - τxx0 = zeros(Dat, ncx ,ncy ) - τyy0 = zeros(Dat, ncx ,ncy ) - τxy0 = zeros(Dat, ncx+1,ncy+1) - Rx = zeros(Dat, ncx-1,ncy ) - Ry = zeros(Dat, ncx ,ncy-1) - dVxdt = zeros(Dat, ncx-1,ncy ) - dVydt = zeros(Dat, ncx ,ncy-1) - Rog = zeros(Dat, ncx ,ncy ) - Xc = ξ*ones(Dat, ncx, ncy) - Xv = ξ*ones(Dat, ncx+1, ncy+1) - ηc = η0*ones(Dat, ncx, ncy) - ηv = η0*ones(Dat, ncx+1, ncy+1) - # Initialisation - xc, yc = LinRange(dx/2, Lx-dx/2, ncx), LinRange(dy/2, Ly-dy/2, ncy) - xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) - (Xvx,Yvx) = ([x for x=xv,y=yc], [y for x=xv,y=yc]) - (Xvy,Yvy) = ([x for x=xc,y=yv], [y for x=xc,y=yv]) - Vx .= εbg.*Xvx - Vy .= .-εbg.*Yvy - dtVx = min(dx,dy)^2.0./av_xa(ηc)./4.1 - dtVy = min(dx,dy)^2.0./av_ya(ηc)./4.1 - dtPt = 4.1*ηc/max(ncx,ncy)/Ptsc - # Time loop - t=0.0; evo_t=[]; evo_τxx=[] - for it = 1:nt - iter=1; err=2*ε; err_evo1=[]; err_evo2=[]; - τxx0.=τxx; τyy0.=τyy; τxy0.=τxy - while (err>ε && iter<=iterMax) - # divergence - pressure - ∇V .= diff(Vx, dims=1)./dx .+ diff(Vy, dims=2)./dy - Pt .= Pt .- dtPt.*∇V - # strain rates - ε̇xx .= diff(Vx, dims=1)./dx .- 1.0/3.0*∇V - ε̇yy .= diff(Vy, dims=2)./dy .- 1.0/3.0*∇V - ε̇xy[2:end-1,2:end-1] .= 0.5.*(diff(Vx[2:end-1,:], dims=2)./dy .+ diff(Vy[:,2:end-1], dims=1)./dx) - # stresses - UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, dt ) - # UpdateStress!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, ηc, ηv, Xc, Xv ) - # velocities - Rx .= .-diff(Pt, dims=1)./dx .+ diff(τxx, dims=1)./dx .+ diff(τxy[2:end-1,:], dims=2)./dy - Ry .= .-diff(Pt, dims=2)./dy .+ diff(τyy, dims=2)./dy .+ diff(τxy[:,2:end-1], dims=1)./dx .+ av_ya(Rog) - dVxdt .= dVxdt.*(1-Vdmp/ncx) .+ Rx - dVydt .= dVydt.*(1-Vdmp/ncy) .+ Ry - Vx[2:end-1,:] .= Vx[2:end-1,:] .+ dVxdt.*dtVx - Vy[:,2:end-1] .= Vy[:,2:end-1] .+ dVydt.*dtVy - # convergence check - if mod(iter, nout)==0 - norm_Rx = norm(Rx)/length(Rx); norm_Ry = norm(Ry)/length(Ry); norm_∇V = norm(∇V)/length(∇V) - err = maximum([norm_Rx, norm_Ry, norm_∇V]) - push!(err_evo1, err); push!(err_evo2, itg) - @printf("it = %d, iter = %d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V) - - end - iter+=1; global itg=iter - end - t = t + dt - push!(evo_t, t); push!(evo_τxx, maximum(τxx)) - # Plotting - p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") - p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") - p3 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) - plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewidth=2.0) # analytical solution - display(plot(p1, p2, p3)) - end - return -end - -Stokes2D_ve() diff --git a/GeoParams_PT_examples/src/Stokes2D_vep_reg_vc_GeoParams.jl b/GeoParams_PT_examples/src/Stokes2D_vep_reg_vc_GeoParams.jl deleted file mode 100644 index 3794779..0000000 --- a/GeoParams_PT_examples/src/Stokes2D_vep_reg_vc_GeoParams.jl +++ /dev/null @@ -1,227 +0,0 @@ -# Initialisation -using Plots, Printf, Statistics, LinearAlgebra -Dat = Float64 # Precision (double=Float64 or single=Float32) -# Macros -@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) -@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) -@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) -# Rheology -function UpdateStressVEVP!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xyc, ε̇xxv, ε̇yyv, ε̇xy, τxx0, τyy0, τxy0, τxxv0, τyyv0, τxyv0, ε̇xx1, ε̇yy1, ε̇xy1, ε̇xxv1, ε̇yyv1, ε̇xyv1, τii, τiiv, Pt, Ptv, τ_y, sinϕ, η_ve, η_vev, η_reg, dQdτxx, dQdτyy, dQdτxy, dQdτxxv, dQdτyyv, dQdτxyv, η_e, η_ev, ε̇ii, ε̇iiv ) - # visco-elastic strain rates - ε̇xx1 .= ε̇xx .+ τxx0 ./2.0./η_e - ε̇yy1 .= ε̇yy .+ τyy0 ./2.0./η_e - ε̇xy1 .= ε̇xyc .+ τxy0 ./2.0./η_e - ε̇ii .= sqrt.(0.5*(ε̇xx1.^2 .+ ε̇yy1.^2) .+ ε̇xy1.^2) - # visco-elastic strain rates vertices - ε̇xxv1 .= ε̇xxv .+ τxxv0./2.0./η_ev - ε̇yyv1 .= ε̇yyv .+ τyyv0./2.0./η_ev - ε̇xyv1 .= ε̇xyv .+ τxyv0./2.0./η_ev - ε̇iiv .= sqrt.(0.5*(ε̇xxv1.^2 .+ ε̇yyv1.^2) .+ ε̇xyv1.^2) - # trial stress - τxx .= 2.0.*η_ve.*ε̇xx1 - τyy .= 2.0.*η_ve.*ε̇yy1 - τxy .= 2.0.*η_ve.*ε̇xy1 - τii .= sqrt.(0.5*(τxx.^2 .+ τyy.^2) .+ τxy.^2) - # trial stress vertices - τxxv .= 2.0.*η_vev.*ε̇xxv1 - τyyv .= 2.0.*η_vev.*ε̇yyv1 - τxyv .= 2.0.*η_vev.*ε̇xyv1 - τiiv .= sqrt.(0.5*(τxxv.^2 .+ τyyv.^2) .+ τxyv.^2) - # yield function - F .= τii .- τ_y .- Pt.*sinϕ - Pla .= 0.0 - Pla .= F .> 0.0 - λ .= Pla.*F./(η_ve .+ η_reg) - dQdτxx .= 0.5.*τxx./τii - dQdτyy .= 0.5.*τyy./τii - dQdτxy .= τxy./τii - # yield function vertices - Fv .= τiiv .- τ_y .- Ptv.*sinϕ - Plav .= 0.0 - Plav .= Fv .> 0.0 - λv .= Plav.*Fv./(η_vev .+ η_reg) - dQdτxxv.= 0.5.*τxxv./τiiv - dQdτyyv.= 0.5.*τyyv./τiiv - dQdτxyv.= τxyv./τiiv - # plastic corrections - τxx .= 2.0.*η_ve.*(ε̇xx1 .- λ.*dQdτxx) - τyy .= 2.0.*η_ve.*(ε̇yy1 .- λ.*dQdτyy) - τxy .= 2.0.*η_ve.*(ε̇xy1 .- 0.5.*λ.*dQdτxy) - τii .= sqrt.(0.5*(τxx.^2 .+ τyy.^2) .+ τxy.^2) - Fchk .= τii .- τ_y .- Pt.*sinϕ .- λ.*η_reg - η_vep .= τii./2.0./ε̇ii - # plastic corrections vertices - τxxv .= 2.0.*η_vev.*(ε̇xxv1 .- λv.*dQdτxxv) - τyyv .= 2.0.*η_vev.*(ε̇yyv1 .- λv.*dQdτyyv) - τxyv .= 2.0.*η_vev.*(ε̇xyv1 .- 0.5.*λv.*dQdτxyv) - τiiv .= sqrt.(0.5*(τxxv.^2 .+ τyyv.^2) .+ τxyv.^2) - Fchkv .= τiiv .- τ_y .- Ptv.*sinϕ .- λv.*η_reg - η_vepv .= τiiv./2.0./ε̇iiv -end -# 2D Stokes routine -@views function Stokes2D_vep() - do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) - η_reg = 1.2e-2 # regularisation "viscosity" - # Physics - Lx, Ly = 1.0, 1.0 # domain size - radi = 0.01 # inclusion radius - τ_y = 1.6 # yield stress. If do_DP=true, τ_y stand for the cohesion: c*cos(ϕ) - sinϕ = sind(30)*do_DP # sinus of the friction angle - η0 = 1.0 # viscous viscosity - G0 = 1.0 # elastic shear modulus - Gi = G0/(6.0-4.0*do_DP) # elastic shear modulus perturbation - εbg = 1.0 # background strain-rate - # Numerics - nt = 10 # number of time steps - ncx, ncy = 63, 63 # numerical grid resolution - Vdmp = 4.0 # convergence acceleration (damping) - Vsc = 2.0 # iterative time step limiter - Ptsc = 6.0 # iterative time step limiter - ε = 1e-6 # nonlinear tolerence - iterMax = 3e4 # max number of iters - nout = 200 # check frequency - # Preprocessing - dx, dy = Lx/ncx, Ly/ncy - dt = η0/G0/4.0 # assumes Maxwell time of 4 - # Array initialisation - Pt = zeros(Dat, ncx ,ncy ) - ∇V = zeros(Dat, ncx ,ncy ) - Vx = zeros(Dat, ncx+1,ncy ) - Vy = zeros(Dat, ncx ,ncy+1) - ε̇xx = zeros(Dat, ncx ,ncy ) - ε̇yy = zeros(Dat, ncx ,ncy ) - ε̇xyv = zeros(Dat, ncx+1,ncy+1) - ε̇xy = zeros(Dat, ncx ,ncy ) - ε̇xx1 = zeros(Dat, ncx ,ncy ) - ε̇yy1 = zeros(Dat, ncx ,ncy ) - ε̇xy1 = zeros(Dat, ncx ,ncy ) - ε̇xyv1 = zeros(Dat, ncx+1,ncy+1) - τxx = zeros(Dat, ncx ,ncy ) - τyy = zeros(Dat, ncx ,ncy ) - τxy = zeros(Dat, ncx ,ncy ) - τxyv = zeros(Dat, ncx+1,ncy+1) - τxx0 = zeros(Dat, ncx ,ncy ) - τyy0 = zeros(Dat, ncx ,ncy ) - τxy0 = zeros(Dat, ncx ,ncy ) - τxyv0 = zeros(Dat, ncx+1,ncy+1) - # for vertices implementation - Ptv = zeros(Dat, ncx+1,ncy+1) - ε̇xxv = zeros(Dat, ncx+1,ncy+1) - ε̇yyv = zeros(Dat, ncx+1,ncy+1) - ε̇xxv1 = zeros(Dat, ncx+1,ncy+1) - ε̇yyv1 = zeros(Dat, ncx+1,ncy+1) - τxxv = zeros(Dat, ncx+1,ncy+1) - τyyv = zeros(Dat, ncx+1,ncy+1) - τxxv0 = zeros(Dat, ncx+1,ncy+1) - τyyv0 = zeros(Dat, ncx+1,ncy+1) - Fchkv = zeros(Dat, ncx+1,ncy+1) - Fv = zeros(Dat, ncx+1,ncy+1) - Plav = zeros(Dat, ncx+1,ncy+1) - λv = zeros(Dat, ncx+1,ncy+1) - dQdτxxv = zeros(Dat, ncx+1,ncy+1) - dQdτyyv = zeros(Dat, ncx+1,ncy+1) - dQdτxyv = zeros(Dat, ncx+1,ncy+1) - τiiv = zeros(Dat, ncx+1,ncy+1) - ε̇iiv = zeros(Dat, ncx+1,ncy+1) - # for vertices implementation - τii = zeros(Dat, ncx ,ncy ) - ε̇ii = zeros(Dat, ncx ,ncy ) - F = zeros(Dat, ncx ,ncy ) - Fchk = zeros(Dat, ncx ,ncy ) - Pla = zeros(Dat, ncx ,ncy ) - λ = zeros(Dat, ncx ,ncy ) - dQdτxx = zeros(Dat, ncx ,ncy ) - dQdτyy = zeros(Dat, ncx ,ncy ) - dQdτxy = zeros(Dat, ncx ,ncy ) - Rx = zeros(Dat, ncx-1,ncy ) - Ry = zeros(Dat, ncx ,ncy-1) - dVxdt = zeros(Dat, ncx-1,ncy ) - dVydt = zeros(Dat, ncx ,ncy-1) - dtPt = zeros(Dat, ncx ,ncy ) - dtVx = zeros(Dat, ncx-1,ncy ) - dtVy = zeros(Dat, ncx ,ncy-1) - Rog = zeros(Dat, ncx ,ncy ) - η_v = η0*ones(Dat, ncx ,ncy ) - η_e = dt*G0*ones(Dat, ncx ,ncy ) - η_ev = dt*G0*ones(Dat, ncx+1,ncy+1) - η_ve = ones(Dat, ncx ,ncy ) - η_vep = ones(Dat, ncx ,ncy ) - η_vepv = ones(Dat, ncx+1,ncy+1) - η_vev = ones(Dat, ncx+1,ncy+1) # for vertices implementation - η_vv = η0*ones(Dat, ncx+1,ncy+1) # for vertices implementation - # Initial condition - xc, yc = LinRange(dx/2, Lx-dx/2, ncx), LinRange(dy/2, Ly-dy/2, ncy) - xc, yc = LinRange(dx/2, Lx-dx/2, ncx), LinRange(dy/2, Ly-dy/2, ncy) - xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) - (Xvx,Yvx) = ([x for x=xv,y=yc], [y for x=xv,y=yc]) - (Xvy,Yvy) = ([x for x=xc,y=yv], [y for x=xc,y=yv]) - radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 - radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 - Phasec = ones(Int, ncx ,ncy ) - Phasev = ones(Int, ncx+1,ncy+1) - Phasec[radc.ε && iter<=iterMax) - # divergence - pressure - ∇V .= diff(Vx, dims=1)./dx .+ diff(Vy, dims=2)./dy - Pt .= Pt .- dtPt.*∇V - # strain rates - ε̇xx .= diff(Vx, dims=1)./dx .- 1.0/3.0*∇V - ε̇yy .= diff(Vy, dims=2)./dy .- 1.0/3.0*∇V - ε̇xyv[2:end-1,2:end-1] .= 0.5.*(diff(Vx[2:end-1,:], dims=2)./dy .+ diff(Vy[:,2:end-1], dims=1)./dx) - ε̇xxv[2:end-1,2:end-1] .= av(ε̇xx); ε̇xxv[1,:].=ε̇xxv[2,:]; ε̇xxv[end,:].=ε̇xxv[end-1,:]; ε̇xxv[:,1].=ε̇xxv[:,2]; ε̇xxv[:,end].=ε̇xxv[:,end-1] - ε̇yyv[2:end-1,2:end-1] .= av(ε̇yy); ε̇yyv[1,:].=ε̇yyv[2,:]; ε̇yyv[end,:].=ε̇yyv[end-1,:]; ε̇yyv[:,1].=ε̇yyv[:,2]; ε̇yyv[:,end].=ε̇yyv[:,end-1] - Ptv[2:end-1,2:end-1] .= av(Pt); Ptv[1,:].= Ptv[2,:]; Ptv[end,:].= Ptv[end-1,:]; Ptv[:,1].= Ptv[:,2]; Ptv[:,end].= Ptv[:,end-1] - ε̇xy .= av(ε̇xyv) - # Rheology - UpdateStressVEVP!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, ε̇xxv, ε̇yyv, ε̇xy, τxx0, τyy0, τxy0, τxxv0, τyyv0, τxyv0, ε̇xx1, ε̇yy1, ε̇xy1, ε̇xxv1, ε̇yyv1, ε̇xyv1, τii, τiiv, Pt, Ptv, τ_y, sinϕ, η_ve, η_vev, η_reg, dQdτxx, dQdτyy, dQdτxy, dQdτxxv, dQdτyyv, dQdτxyv, η_e, η_ev, ε̇ii, ε̇iiv ) - # PT timestep - dtVx .= min(dx,dy)^2.0./av_xa(η_vep)./4.1./Vsc - dtVy .= min(dx,dy)^2.0./av_ya(η_vep)./4.1./Vsc - dtPt .= 4.1.*η_vep./max(ncx,ncy)./Ptsc - # velocities - Rx .= .-diff(Pt, dims=1)./dx .+ diff(τxx, dims=1)./dx .+ diff(τxyv[2:end-1,:], dims=2)./dy - Ry .= .-diff(Pt, dims=2)./dy .+ diff(τyy, dims=2)./dy .+ diff(τxyv[:,2:end-1], dims=1)./dx .+ av_ya(Rog) - dVxdt .= dVxdt.*(1-Vdmp/ncx) .+ Rx - dVydt .= dVydt.*(1-Vdmp/ncy) .+ Ry - Vx[2:end-1,:] .= Vx[2:end-1,:] .+ dVxdt.*dtVx - Vy[:,2:end-1] .= Vy[:,2:end-1] .+ dVydt.*dtVy - # convergence check - if mod(iter, nout)==0 - norm_Rx = norm(Rx)/length(Rx); norm_Ry = norm(Ry)/length(Ry); norm_∇V = norm(∇V)/length(∇V) - err = maximum([norm_Rx, norm_Ry, norm_∇V]) - push!(err_evo1, err); push!(err_evo2, itg) - @printf("it = %d, iter = %d, err = %1.2e norm[Rx=%1.2e, Ry=%1.2e, ∇V=%1.2e] (Fchk=%1.2e - Fchkv=%1.2e) \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V, maximum(Fchk), maximum(Fchkv)) - end - iter+=1; itg=iter - end - t = t + dt - push!(evo_t, t); push!(evo_τxx, maximum(τxx)) - # Plotting - p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") - # p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") - p2 = heatmap(xc, yc, η_vep' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="η_vep") - p3 = heatmap(xc, yc, τii' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="τii") - p4 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) - plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G0./η0)), linewidth=2.0) # analytical solution for VE loading - plot!(evo_t, 2.0.*εbg.*η0.*ones(size(evo_t)), linewidth=2.0) # viscous flow stress - if !do_DP plot!(evo_t, τ_y*ones(size(evo_t)), linewidth=2.0) end # von Mises yield stress - display(plot(p1, p2, p3, p4)) - end - return -end - -Stokes2D_vep() From a40ccece5ae65b9b52e01696d8dcd81c414fb053 Mon Sep 17 00:00:00 2001 From: Boris Kaus Date: Thu, 20 Oct 2022 12:43:37 -0300 Subject: [PATCH 08/49] added example with plasticity --- .../Stokes2D_VEP_inclusion_GeoParams.jl | 158 ++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams.jl diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams.jl new file mode 100644 index 0000000..3bac7f9 --- /dev/null +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams.jl @@ -0,0 +1,158 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra, GeoParams +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +# Rheology +@views function UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt, Phasec, Phasev ) + ε̇iic = ones(size(ε̇xx)) + ε̇iiv = ones(size(ε̇xy)) + τii0c = sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) + τii0v = zeros(size(ε̇xy)) + τii0v[2:end-1,2:end-1] = sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) + # Centroids + for i in eachindex(τxx) + v = MatParam[Phasec[i]].CompositeRheology[1] + args = (; τII_old = τii0c[i], dt=Δt) + ηc[i] = computeViscosity_εII(v, ε̇iic[i], args) + τxx[i] = 2*ηc[i]*ε̇xx[i] + τyy[i] = 2*ηc[i]*ε̇yy[i] + end + # Vertices + for i in eachindex(τxy) + v = MatParam[Phasev[i]].CompositeRheology[1] + args = (; τII_old = τii0v[i], dt=Δt) + ηv[i] = computeViscosity_εII(v, ε̇iiv[i], args) + τxy[i] = 2*ηv[i]*ε̇xy[i] + end +end +# 2D Stokes routine +@views function Stokes2D_VE_inclusion() + # Physics + Lx, Ly = 1.0, 1.0 # domain size + ξ = 10.0 # Maxwell relaxation time + η0 = 1.0 # viscous viscosity + G = 1.0 # elastic shear modulus + εbg = 1.0 # background strain-rate + radi = 0.01 + + MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G),LinearViscous(η=η0), DruckerPrager(C=1.0, ϕ=0))), + SetMaterialParams(Name="Inclusion", Phase=2, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G*0.1),LinearViscous(η=η0*0.1), DruckerPrager(C=1.0, ϕ=0))), + ) + + # Numerics + nt = 30 # number of time steps + ncx, ncy = 51, 51 # numerical grid resolution + ε = 1e-6 # nonlinear tolerence + iterMax = 1e4 # max number of iters + nout = 500 # check frequency + # Iterative parameters ------------------------------------------- + Reopt = 5π + cfl = 0.5 + ρ = cfl*Reopt/ncx + # Preprocessing + Δx, Δy = Lx/ncx, Ly/ncy + Δt = η0/(G*ξ + 1e-15) + # Array initialisation + Pt = zeros(Dat, ncx ,ncy ) + ∇V = zeros(Dat, ncx ,ncy ) + Vx = zeros(Dat, ncx+1,ncy+2) + Vy = zeros(Dat, ncx+2,ncy+1) + ε̇xx = zeros(Dat, ncx ,ncy ) + ε̇yy = zeros(Dat, ncx ,ncy ) + ε̇xy = zeros(Dat, ncx+1,ncy+1) + τxx = zeros(Dat, ncx ,ncy ) + τyy = zeros(Dat, ncx ,ncy ) + τxy = zeros(Dat, ncx+1,ncy+1) + τxx0 = zeros(Dat, ncx ,ncy ) + τyy0 = zeros(Dat, ncx ,ncy ) + τxy0 = zeros(Dat, ncx+1,ncy+1) + Rx = zeros(Dat, ncx+1,ncy ) + Ry = zeros(Dat, ncx ,ncy+1) + Rp = zeros(Dat, ncx ,ncy ) + dVxdτ = zeros(Dat, ncx+1,ncy ) + dVydτ = zeros(Dat, ncx ,ncy+1) + dPdτ = zeros(Dat, ncx ,ncy ) + Δτv = zeros(Dat, ncx+1,ncy+1) + Δτvx = zeros(Dat, ncx+1,ncy ) + Δτvy = zeros(Dat, ncx ,ncy+1) + κΔτp = zeros(Dat, ncx ,ncy ) + Rog = zeros(Dat, ncx ,ncy ) + ηc = η0*ones(Dat, ncx, ncy) + ηv = η0*ones(Dat, ncx+1, ncy+1) + Phasec = ones(Int, ncx ,ncy ) + Phasev = ones(Int, ncx+1,ncy+1) + # Initialisation + xce, yce = LinRange(-Δx/2, Lx+Δx/2, ncx+2), LinRange(-Δy/2, Ly+Δy/2, ncy+2) + xc, yc = LinRange(Δx/2, Lx-Δx/2, ncx), LinRange(Δy/2, Ly-Δy/2, ncy) + xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + Phasec[radc.ε && iter<=iterMax) + # BCs + Vx[:,1] .= Vx[:,2] # S + Vx[:,end] .= Vx[:,end-1] # N + Vy[1,:] .= Vy[2,:] # W + Vy[end,:] .= Vy[end-1,:] # E + # Kinematics + ∇V .= diff(Vx[:,2:end-1], dims=1)./Δx .+ diff(Vy[2:end-1,:], dims=2)./Δy + ε̇xx .= diff(Vx[:,2:end-1], dims=1)./Δx .- 1.0/3.0*∇V + ε̇yy .= diff(Vy[2:end-1,:], dims=2)./Δy .- 1.0/3.0*∇V + ε̇xy .= 0.5.*(diff(Vx, dims=2)./Δy .+ diff(Vy, dims=1)./Δx) + # Stresses + UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt, Phasec, Phasev ) + # Residuals + Rx[2:end-1,:] .= .-diff(Pt, dims=1)./Δx .+ diff(τxx, dims=1)./Δx .+ diff(τxy[2:end-1,:], dims=2)./Δy + Ry[:,2:end-1] .= .-diff(Pt, dims=2)./Δy .+ diff(τyy, dims=2)./Δy .+ diff(τxy[:,2:end-1], dims=1)./Δx #.+ av_ya(Rog) + Rp .= .-∇V + # PT time step ----------------------------------------------- + Δτv .= ρ*min(Δx,Δy)^2 ./ ηv ./ 4.1 * cfl + Δτvx .= (Δτv[:,1:end-1] .+ Δτv[:,2:end]) / 2. + Δτvy .= (Δτv[1:end-1,:] .+ Δτv[2:end,:]) / 2. + κΔτp .= cfl .* ηc .* Δx ./ Lx + # Calculate rate update -------------------------------------- + dVxdτ .= (1-ρ) .* dVxdτ .+ Rx + dVydτ .= (1-ρ) .* dVydτ .+ Ry + dPdτ .= Rp + # Update velocity and pressure ------------------------------- + Vx[:,2:end-1] .+= Δτvx ./ ρ .* dVxdτ + Vy[2:end-1,:] .+= Δτvy ./ ρ .* dVydτ + Pt .+= κΔτp .* dPdτ + # convergence check + if mod(iter, nout)==0 + norm_Rx = norm(Rx)/sqrt(length(Rx)); norm_Ry = norm(Ry)/sqrt(length(Ry)); norm_∇V = norm(∇V)/sqrt(length(∇V)) + err = maximum([norm_Rx, norm_Ry, norm_∇V]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %03d, iter = %04d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V) + end + iter+=1; global itg=iter + end + t = t + Δt + push!(evo_t, t); push!(evo_τxx, maximum(τxx)) + # Plotting + p1 = heatmap(xv, yc, Vx[:,2:end-1]', aspect_ratio=1, xlims=(0, Lx), ylims=(Δy/2, Ly-Δy/2), c=:inferno, title="Vx") + p2 = heatmap(xc, yv, Vy[2:end-1,:]', aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p3 = heatmap(xc, yc, Pt' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="P") + p4 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + p4 = plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewidth=2.0) # analytical solution + display(plot(p1, p2, p3, p4)) + end + return +end + +Stokes2D_VE_inclusion() \ No newline at end of file From 42ddf3970e43ec541ab9fbaa0853714e00285945 Mon Sep 17 00:00:00 2001 From: Boris Kaus Date: Thu, 20 Oct 2022 12:52:16 -0300 Subject: [PATCH 09/49] plot strain rate invariant --- .../scripts/Stokes2D_VEP_inclusion_GeoParams.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams.jl index 3bac7f9..8a09f2e 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams.jl @@ -144,9 +144,13 @@ end end t = t + Δt push!(evo_t, t); push!(evo_τxx, maximum(τxx)) + + ε̇II = sqrt.(0.5*ε̇xx.*ε̇xx + 0.5*ε̇yy.*ε̇yy + av(ε̇xy.*ε̇xy)) + # Plotting p1 = heatmap(xv, yc, Vx[:,2:end-1]', aspect_ratio=1, xlims=(0, Lx), ylims=(Δy/2, Ly-Δy/2), c=:inferno, title="Vx") - p2 = heatmap(xc, yv, Vy[2:end-1,:]', aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="Vy") + #p2 = heatmap(xc, yv, Vy[2:end-1,:]', aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p2 = heatmap(xc, yc, ε̇II', aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="ε̇II") p3 = heatmap(xc, yc, Pt' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="P") p4 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) p4 = plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewidth=2.0) # analytical solution From 9c6d908a59d8dbde12d7ef353365961720fa912d Mon Sep 17 00:00:00 2001 From: Boris Kaus Date: Thu, 20 Oct 2022 13:43:28 -0300 Subject: [PATCH 10/49] added P-dependent plasticity --- .../Stokes2D_VEP_inclusion_GeoParams.jl | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams.jl index 8a09f2e..ed96bcb 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams.jl @@ -6,24 +6,33 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) @views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) @views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) # Rheology -@views function UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt, Phasec, Phasev ) +@views function UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt, Pt, Phasec, Phasev ) ε̇iic = ones(size(ε̇xx)) ε̇iiv = ones(size(ε̇xy)) τii0c = sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) τii0v = zeros(size(ε̇xy)) τii0v[2:end-1,2:end-1] = sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) + + P_v = zeros(size(ε̇xy)) + P_v[2:end-1,2:end-1] = av(Pt) + P_v[:,1] = P_v[:,2]; P_v[:,end] = P_v[:,end-1]; + P_v[1,:] = P_v[2,:]; P_v[end,:] = P_v[end-1,:]; + P_v[1,1] = P_v[2,2]; P_v[end,1] = P_v[end,2]; + P_v[end,end] = P_v[end-1,end-1]; P_v[1,end] = P_v[1,end-1]; + # Centroids for i in eachindex(τxx) v = MatParam[Phasec[i]].CompositeRheology[1] - args = (; τII_old = τii0c[i], dt=Δt) + args = (; τII_old = τii0c[i], dt=Δt, P=Pt[i]) ηc[i] = computeViscosity_εII(v, ε̇iic[i], args) τxx[i] = 2*ηc[i]*ε̇xx[i] τyy[i] = 2*ηc[i]*ε̇yy[i] end + # Vertices for i in eachindex(τxy) v = MatParam[Phasev[i]].CompositeRheology[1] - args = (; τII_old = τii0v[i], dt=Δt) + args = (; τII_old = τii0v[i], dt=Δt, P=P_v[i]) ηv[i] = computeViscosity_εII(v, ε̇iiv[i], args) τxy[i] = 2*ηv[i]*ε̇xy[i] end @@ -39,9 +48,9 @@ end radi = 0.01 MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, - CompositeRheology = CompositeRheology(ConstantElasticity(G=G),LinearViscous(η=η0), DruckerPrager(C=1.0, ϕ=0))), + CompositeRheology = CompositeRheology(ConstantElasticity(G=G),LinearViscous(η=η0), DruckerPrager(C=1.0, ϕ=30))), SetMaterialParams(Name="Inclusion", Phase=2, - CompositeRheology = CompositeRheology(ConstantElasticity(G=G*0.1),LinearViscous(η=η0*0.1), DruckerPrager(C=1.0, ϕ=0))), + CompositeRheology = CompositeRheology(ConstantElasticity(G=G*0.1),LinearViscous(η=η0*0.1), DruckerPrager(C=1.0, ϕ=30))), ) # Numerics @@ -115,7 +124,7 @@ end ε̇yy .= diff(Vy[2:end-1,:], dims=2)./Δy .- 1.0/3.0*∇V ε̇xy .= 0.5.*(diff(Vx, dims=2)./Δy .+ diff(Vy, dims=1)./Δx) # Stresses - UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt, Phasec, Phasev ) + UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt, Pt, Phasec, Phasev ) # Residuals Rx[2:end-1,:] .= .-diff(Pt, dims=1)./Δx .+ diff(τxx, dims=1)./Δx .+ diff(τxy[2:end-1,:], dims=2)./Δy Ry[:,2:end-1] .= .-diff(Pt, dims=2)./Δy .+ diff(τyy, dims=2)./Δy .+ diff(τxy[:,2:end-1], dims=1)./Δx #.+ av_ya(Rog) From 7ced7aa6193afce185496cbacc9b4a5c3d10f8d2 Mon Sep 17 00:00:00 2001 From: Boris Kaus Date: Thu, 20 Oct 2022 14:02:33 -0300 Subject: [PATCH 11/49] example using Thibaults parameters (not working) --- .../Stokes2D_VEP_inclusion_GeoParams.jl | 18 ++++++++++++++---- Project.toml | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams.jl index ed96bcb..de78232 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams.jl @@ -13,6 +13,7 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) τii0v = zeros(size(ε̇xy)) τii0v[2:end-1,2:end-1] = sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) + # P_v = zeros(size(ε̇xy)) P_v[2:end-1,2:end-1] = av(Pt) P_v[:,1] = P_v[:,2]; P_v[:,end] = P_v[:,end-1]; @@ -40,21 +41,30 @@ end # 2D Stokes routine @views function Stokes2D_VE_inclusion() # Physics + do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) Lx, Ly = 1.0, 1.0 # domain size ξ = 10.0 # Maxwell relaxation time η0 = 1.0 # viscous viscosity - G = 1.0 # elastic shear modulus + G0 = 1.0 # elastic shear modulus εbg = 1.0 # background strain-rate radi = 0.01 + τ_y = 1.6 + Gi = G0/(6.0-4.0*do_DP) # inclusion shear modulus + η_reg = 1.2e-2 # regularisation "viscosity" + ϕ = 30*do_DP + Coh = 1.6/cosd(ϕ) # cohesion + + #pl = DruckerPrager(C=1.0, ϕ=30) # non-regularized plasticity + pl = Parallel(DruckerPrager(C=Coh, ϕ=ϕ), LinearViscous(η=η_reg)) MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, - CompositeRheology = CompositeRheology(ConstantElasticity(G=G),LinearViscous(η=η0), DruckerPrager(C=1.0, ϕ=30))), + CompositeRheology = CompositeRheology(ConstantElasticity(G=G0),LinearViscous(η=η0),pl)), SetMaterialParams(Name="Inclusion", Phase=2, - CompositeRheology = CompositeRheology(ConstantElasticity(G=G*0.1),LinearViscous(η=η0*0.1), DruckerPrager(C=1.0, ϕ=30))), + CompositeRheology = CompositeRheology(ConstantElasticity(G=Gi),LinearViscous(η=η0), pl)), ) # Numerics - nt = 30 # number of time steps + nt = 20 # number of time steps ncx, ncy = 51, 51 # numerical grid resolution ε = 1e-6 # nonlinear tolerence iterMax = 1e4 # max number of iters diff --git a/Project.toml b/Project.toml index 8722983..6636111 100644 --- a/Project.toml +++ b/Project.toml @@ -1,3 +1,4 @@ [deps] GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" +GeoParams = "e018b62d-d9de-4a26-8697-af89c310ae38" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" From 910d1d87b7fef703aaf9fad647128d5fa51dcc0e Mon Sep 17 00:00:00 2001 From: tduretz Date: Fri, 21 Oct 2022 10:02:12 +0200 Subject: [PATCH 12/49] back to visco-elasticity: the visco-elastic inclusion test with GeoParams=false/true gives different results --- .../Stokes2D_VE_inclusion_GeoParams.jl | 36 +++++++++++++++---- .../src/GeoParams_PT_examples.jl | 0 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 GeoParams_PT_examples/src/GeoParams_PT_examples.jl diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams.jl index ba3d781..fc8a321 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams.jl @@ -28,8 +28,11 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) τxy[i] = 2*ηv[i]*ε̇xy[i] end end + # 2D Stokes routine @views function Stokes2D_VE_inclusion() + # Switches + UseGeoParams = false # Physics Lx, Ly = 1.0, 1.0 # domain size ξ = 10.0 # Maxwell relaxation time @@ -41,18 +44,18 @@ end MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, CompositeRheology = CompositeRheology(ConstantElasticity(G=G),LinearViscous(η=η0))), SetMaterialParams(Name="Inclusion", Phase=2, - CompositeRheology = CompositeRheology(ConstantElasticity(G=G*0.1),LinearViscous(η=η0*0.1))), + CompositeRheology = CompositeRheology(ConstantElasticity(G=G/6),LinearViscous(η=η0))), ) # Numerics nt = 10 # number of time steps - ncx, ncy = 51, 51 # numerical grid resolution + ncx, ncy = 31, 31 # numerical grid resolution ε = 1e-6 # nonlinear tolerence iterMax = 1e4 # max number of iters nout = 500 # check frequency # Iterative parameters ------------------------------------------- Reopt = 5π - cfl = 0.5 + cfl = 0.50 ρ = cfl*Reopt/ncx # Preprocessing Δx, Δy = Lx/ncx, Ly/ncy @@ -86,14 +89,28 @@ end ηv = η0*ones(Dat, ncx+1, ncy+1) Phasec = ones(Int, ncx ,ncy ) Phasev = ones(Int, ncx+1,ncy+1) + # For non-geoparams version + η, G = 1.0, 1.0 + ηe_c = Δt*G.*ones(Dat, ncx ,ncy ) + ηe_v = Δt*G.*ones(Dat, ncx+1,ncy+1) + ηve_c = zeros(Dat, ncx ,ncy ) + ηve_v = zeros(Dat, ncx+1,ncy+1) # Initialisation xce, yce = LinRange(-Δx/2, Lx+Δx/2, ncx+2), LinRange(-Δy/2, Ly+Δy/2, ncy+2) xc, yc = LinRange(Δx/2, Lx-Δx/2, ncx), LinRange(Δy/2, Ly-Δy/2, ncy) xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + # For non-geoparams version Phasec[radc. Date: Fri, 21 Oct 2022 23:45:40 +0200 Subject: [PATCH 13/49] fix GeoParams stress update --- .../scripts/Stokes2D_VE_bench_GeoParams.jl | 99 ++++++++++++------- 1 file changed, 65 insertions(+), 34 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VE_bench_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VE_bench_GeoParams.jl index 3b7b7f2..3e1092c 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VE_bench_GeoParams.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VE_bench_GeoParams.jl @@ -6,54 +6,61 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) @views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) @views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) # Rheology -@views function UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt ) - ε̇iic = ones(size(ε̇xx)) +@views function UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt, Phasec, Phasev ) ε̇iiv = ones(size(ε̇xy)) τii0c = sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) + ε̇iic = sqrt.(1//2 .*(ε̇xx.^2 .+ ε̇yy.^2) .+ av(ε̇xy).^2) + ε̇iiv[2:end-1,2:end-1] .= sqrt.(1//2 .*( av(ε̇xx).^2 .+ av(ε̇yy).^2) .+ ε̇xy[2:end-1,2:end-1].^2) τii0v = zeros(size(ε̇xy)) - τii0v[2:end-1,2:end-1] = sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) - Phase = 1 + τii0v[2:end-1,2:end-1] .= sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) # Centroids for i in eachindex(τxx) - v = MatParam[Phase].CompositeRheology[1] - args = (; τII_old = τii0c[i], dt=Δt) - η_eff = computeViscosity_εII(v, ε̇iic[i], args) - τxx[i] = 2*η_eff*ε̇xx[i] - τyy[i] = 2*η_eff*ε̇yy[i] + v = MatParam[Phasec[i]].CompositeRheology[1] + args = (; τII_old = τii0c[i], dt=Δt) + ηc[i] = computeViscosity_εII(v, ε̇iic[i], args) + τxx[i] = 2*ηc[i]*ε̇xx[i] + τyy[i] = 2*ηc[i]*ε̇yy[i] end # Vertices for i in eachindex(τxy) - v = MatParam[Phase].CompositeRheology[1] + v = MatParam[Phasev[i]].CompositeRheology[1] args = (; τII_old = τii0v[i], dt=Δt) - η_eff = computeViscosity_εII(v, ε̇iiv[i], args) - τxy[i] = 2*η_eff*ε̇xy[i] + ηv[i] = computeViscosity_εII(v, ε̇iiv[i], args) + τxy[i] = 2*ηv[i]*ε̇xy[i] end end + # 2D Stokes routine -@views function Stokes2D_VE_benchmark() +@views function Stokes2D_VE_inclusion() + # Switches + UseGeoParams = true # Physics Lx, Ly = 1.0, 1.0 # domain size ξ = 10.0 # Maxwell relaxation time η0 = 1.0 # viscous viscosity G = 1.0 # elastic shear modulus εbg = 1.0 # background strain-rate + radi = 0.01 - MatParam = (SetMaterialParams(Name="Matrix", Phase=1, - CompositeRheology = CompositeRheology(ConstantElasticity(G=G),LinearViscous(η=η0))),) + MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G),LinearViscous(η=η0))), + SetMaterialParams(Name="Inclusion", Phase=2, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G/6),LinearViscous(η=η0))), + ) # Numerics - nt = 1 # number of time steps + nt = 10 # number of time steps ncx, ncy = 31, 31 # numerical grid resolution ε = 1e-6 # nonlinear tolerence - iterMax = 1e5 # max number of iters - nout = 200 # check frequency + iterMax = 1e4 # max number of iters + nout = 500 # check frequency # Iterative parameters ------------------------------------------- Reopt = 5π - cfl = 0.5 - ρ = 1#cfl*Reopt/ncx + cfl = 0.50 + ρ = cfl*Reopt/ncx # Preprocessing - Δx, Δy = Lx/ncx, Ly/ncy - Δt = η0/(G*ξ + 1e-15) + Δx, Δy = Lx/ncx, Ly/ncy + Δt = η0/(G*ξ + 1e-15) # Array initialisation Pt = zeros(Dat, ncx ,ncy ) ∇V = zeros(Dat, ncx ,ncy ) @@ -81,17 +88,37 @@ end Rog = zeros(Dat, ncx ,ncy ) ηc = η0*ones(Dat, ncx, ncy) ηv = η0*ones(Dat, ncx+1, ncy+1) + Phasec = ones(Int, ncx ,ncy ) + Phasev = ones(Int, ncx+1,ncy+1) + # For non-geoparams version + η, G = 1.0, 1.0 + ηe_c = Δt*G.*ones(Dat, ncx ,ncy ) + ηe_v = Δt*G.*ones(Dat, ncx+1,ncy+1) + ηve_c = zeros(Dat, ncx ,ncy ) + ηve_v = zeros(Dat, ncx+1,ncy+1) # Initialisation - xc, yc = LinRange( Δx/2, Lx-Δx/2, ncx+0), LinRange( Δy/2, Ly-Δy/2, ncy+0) xce, yce = LinRange(-Δx/2, Lx+Δx/2, ncx+2), LinRange(-Δy/2, Ly+Δy/2, ncy+2) - xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) + xc, yc = LinRange(Δx/2, Lx-Δx/2, ncx), LinRange(Δy/2, Ly-Δy/2, ncy) + xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + # For non-geoparams version + Phasec[radc.ε && iter<=iterMax) @@ -106,19 +133,22 @@ end ε̇yy .= diff(Vy[2:end-1,:], dims=2)./Δy .- 1.0/3.0*∇V ε̇xy .= 0.5.*(diff(Vx, dims=2)./Δy .+ diff(Vy, dims=1)./Δx) # Stresses - UpdateStressGeoParams!( τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt ) - if iter==1 - display(τxx') + if UseGeoParams + UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt, Phasec, Phasev ) + else + τxx .= 2 .* ηve_c .* ( ε̇xx .+ τxx0./(2 .* ηe_c) ) + τyy .= 2 .* ηve_c .* ( ε̇yy .+ τyy0./(2 .* ηe_c) ) + τxy .= 2 .* ηve_v .* ( ε̇xy .+ τxy0./(2 .* ηe_v) ) end # Residuals Rx[2:end-1,:] .= .-diff(Pt, dims=1)./Δx .+ diff(τxx, dims=1)./Δx .+ diff(τxy[2:end-1,:], dims=2)./Δy Ry[:,2:end-1] .= .-diff(Pt, dims=2)./Δy .+ diff(τyy, dims=2)./Δy .+ diff(τxy[:,2:end-1], dims=1)./Δx #.+ av_ya(Rog) Rp .= .-∇V # PT time step ----------------------------------------------- - Δτv .= ρ*min(Δx,Δy)^2 ./ ηv ./ 4.1 * cfl + Δτv .= ρ*min(Δx,Δy)^2 ./ ηv ./ 4.1 * cfl Δτvx .= (Δτv[:,1:end-1] .+ Δτv[:,2:end]) / 2. Δτvy .= (Δτv[1:end-1,:] .+ Δτv[2:end,:]) / 2. - κΔτp .= cfl .* ηc .* Δx ./ Lx + κΔτp .= cfl .* ηc .* Δx ./ Lx # Calculate rate update -------------------------------------- dVxdτ .= (1-ρ) .* dVxdτ .+ Rx dVydτ .= (1-ρ) .* dVydτ .+ Ry @@ -141,12 +171,13 @@ end # Plotting p1 = heatmap(xv, yc, Vx[:,2:end-1]', aspect_ratio=1, xlims=(0, Lx), ylims=(Δy/2, Ly-Δy/2), c=:inferno, title="Vx") p2 = heatmap(xc, yv, Vy[2:end-1,:]', aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="Vy") - p3 = heatmap(xc, yc, ε̇xx' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="P") - p4 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewiΔth=0, markershape=:circle, framestyle=:box, markersize=3) - p4 = plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewiΔth=2.0) # analytical solution + p3 = heatmap(xc, yc, Pt' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="P") + # p3 = heatmap(xv, yv, τxy' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="τxy") + p4 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + p4 = plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewidth=2.0) # analytical solution display(plot(p1, p2, p3, p4)) end return end -Stokes2D_VE_benchmark() +Stokes2D_VE_inclusion() \ No newline at end of file From 6cfdb9f8784d5b38f01da413b56510e8431567d6 Mon Sep 17 00:00:00 2001 From: Duretz Thibault Date: Sat, 22 Oct 2022 14:11:17 +0200 Subject: [PATCH 14/49] add Eii computation, still weird behaviour --- .../Stokes2D_VE_inclusion_GeoParams.jl | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams.jl index fc8a321..ce5b951 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams.jl @@ -6,12 +6,11 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) @views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) @views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) # Rheology -@views function UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt, Phasec, Phasev ) - ε̇iic = ones(size(ε̇xx)) - ε̇iiv = ones(size(ε̇xy)) - τii0c = sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) - τii0v = zeros(size(ε̇xy)) - τii0v[2:end-1,2:end-1] = sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) +@views function UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, MatParam, Δt, Phasec, Phasev ) + ε̇iic .= sqrt.(1//2 .*(ε̇xx.^2 .+ ε̇yy.^2) .+ av(ε̇xy).^2) + ε̇iiv[2:end-1,2:end-1] .= sqrt.(1//2 .*( av(ε̇xx).^2 .+ av(ε̇yy).^2) .+ ε̇xy[2:end-1,2:end-1].^2) + τii0c .= sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) + τii0v[2:end-1,2:end-1] .= sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) # Centroids for i in eachindex(τxx) v = MatParam[Phasec[i]].CompositeRheology[1] @@ -32,7 +31,7 @@ end # 2D Stokes routine @views function Stokes2D_VE_inclusion() # Switches - UseGeoParams = false + UseGeoParams = true # Physics Lx, Ly = 1.0, 1.0 # domain size ξ = 10.0 # Maxwell relaxation time @@ -89,6 +88,11 @@ end ηv = η0*ones(Dat, ncx+1, ncy+1) Phasec = ones(Int, ncx ,ncy ) Phasev = ones(Int, ncx+1,ncy+1) + # For geoparams + τii0c = zeros(size(ε̇xx)) + τii0v = zeros(size(ε̇xy)) + ε̇iic = zeros(size(ε̇xx)) + ε̇iiv = zeros(size(ε̇xy)) # For non-geoparams version η, G = 1.0, 1.0 ηe_c = Δt*G.*ones(Dat, ncx ,ncy ) @@ -133,7 +137,7 @@ end ε̇xy .= 0.5.*(diff(Vx, dims=2)./Δy .+ diff(Vy, dims=1)./Δx) # Stresses if UseGeoParams - UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, MatParam, Δt, Phasec, Phasev ) + UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, MatParam, Δt, Phasec, Phasev ) else τxx .= 2 .* ηve_c .* ( ε̇xx .+ τxx0./(2 .* ηe_c) ) τyy .= 2 .* ηve_c .* ( ε̇yy .+ τyy0./(2 .* ηe_c) ) @@ -157,7 +161,7 @@ end Vy[2:end-1,:] .+= Δτvy ./ ρ .* dVydτ Pt .+= κΔτp .* dPdτ # convergence check - if mod(iter, nout)==0 + if mod(iter, nout)==0 || iter==1 norm_Rx = norm(Rx)/sqrt(length(Rx)); norm_Ry = norm(Ry)/sqrt(length(Ry)); norm_∇V = norm(∇V)/sqrt(length(∇V)) err = maximum([norm_Rx, norm_Ry, norm_∇V]) push!(err_evo1, err); push!(err_evo2, itg) From e81ecc513659d738a68702a28b425399e1121ad9 Mon Sep 17 00:00:00 2001 From: Duretz Thibault Date: Wed, 26 Oct 2022 11:32:11 +0200 Subject: [PATCH 15/49] Add Albert fix start with timing comparison --- .../Stokes2D_VE_inclusion_GeoParams.jl | 52 ++++- .../Stokes2D_VE_inclusion_GeoParams_v2.jl | 204 ++++++++++++++++++ 2 files changed, 249 insertions(+), 7 deletions(-) create mode 100644 GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams_v2.jl diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams.jl index ce5b951..03f645f 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams.jl @@ -1,11 +1,48 @@ # Initialisation using Plots, Printf, Statistics, LinearAlgebra, GeoParams -Dat = Float64 # Precision (double=Float64 or single=Float32) +Dat = Float64 # Precision (double=Float64 or single=Float32) # Macros @views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) @views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) @views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +@generated function phase_viscosity(v::NTuple{N,Any}, ε̇ii, phase, args) where N + quote + Base.@_inline_meta + Base.@nexprs $N i -> v[i].Phase === phase && return computeViscosity_εII(v[i].CompositeRheology[1], ε̇ii, args) + end +end # Rheology +# @views function UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, MatParam, Δt, Phasec, Phasev ) +# # ε̇iic .= sqrt.(1//2 .*(ε̇xx.^2 .+ ε̇yy.^2) .+ av(ε̇xy).^2) +# # ε̇iiv[2:end-1,2:end-1] .= sqrt.(1//2 .*( av(ε̇xx).^2 .+ av(ε̇yy).^2) .+ ε̇xy[2:end-1,2:end-1].^2) +# # τii0c .= sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) +# # τii0v[2:end-1,2:end-1] .= sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) +# # Centroids +# for j ∈ axes(ε̇xx,2), i ∈ axes(ε̇xx,1) +# # v = MatParam[Phasec[i]].CompositeRheology[1] # indexation of MatParam with Phasec[i] causes allocation +# τxy0c = .25*(τxy0[i,j] + τxy0[i+1,j] + τxy0[i,j+1] + τxy0[i+1,j+1]) +# ε̇xyc = .25*( ε̇xy[i,j] + ε̇xy[i+1,j] + ε̇xy[i,j+1] + ε̇xy[i+1,j+1]) +# τii0 = sqrt.(0.5 *(τxx0[i,j]^2 + τyy0[i,j]^2) + τxy0c^2) +# ε̇ii = sqrt.(0.5 *( ε̇xx[i,j]^2 + ε̇yy[i,j]^2) + ε̇xyc^2) +# args = (; τII_old = τii0, dt=Δt) +# ηc[i,j] = phase_viscosity(MatParam, ε̇ii, Phasec[i,j], args) +# τxx[i,j] = 2*ηc[i,j]*ε̇xx[i,j] +# τyy[i,j] = 2*ηc[i,j]*ε̇yy[i,j] +# end +# # Vertices +# for j ∈ 2:size(ε̇xy,2)-1, i ∈ 2:size(ε̇xy,1)-1 +# τxx0c = .25*(τxx0[i,j] + τxx0[i-1,j] + τxx0[i,j-1] + τxx0[i-1,j-1]) +# τyy0c = .25*(τyy0[i,j] + τyy0[i-1,j] + τyy0[i,j-1] + τyy0[i-1,j-1]) +# ε̇xxc = .25*( ε̇xx[i,j] + ε̇xx[i-1,j] + ε̇xx[i,j-1] + ε̇xx[i-1,j-1]) +# ε̇yyc = .25*( ε̇yy[i,j] + ε̇yy[i-1,j] + ε̇yy[i,j-1] + ε̇yy[i-1,j-1]) +# τii0 = sqrt.(0.5 *(τxx0c^2 + τyy0c^2) + τxy0[i,j]^2) +# ε̇ii = sqrt.(0.5 *( ε̇xxc^2 + ε̇yyc^2) + ε̇xy[i,j]^2) +# args = (; τII_old = τii0, dt=Δt) +# ηv[i,j] = phase_viscosity(MatParam, ε̇ii, Phasev[i,j], args) +# τxy[i,j] = 2*ηv[i,j]*ε̇xy[i,j] +# end +# end + @views function UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, MatParam, Δt, Phasec, Phasev ) ε̇iic .= sqrt.(1//2 .*(ε̇xx.^2 .+ ε̇yy.^2) .+ av(ε̇xy).^2) ε̇iiv[2:end-1,2:end-1] .= sqrt.(1//2 .*( av(ε̇xx).^2 .+ av(ε̇yy).^2) .+ ε̇xy[2:end-1,2:end-1].^2) @@ -20,11 +57,11 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) τyy[i] = 2*ηc[i]*ε̇yy[i] end # Vertices - for i in eachindex(τxy) - v = MatParam[Phasev[i]].CompositeRheology[1] - args = (; τII_old = τii0v[i], dt=Δt) - ηv[i] = computeViscosity_εII(v, ε̇iiv[i], args) - τxy[i] = 2*ηv[i]*ε̇xy[i] + for j ∈ 2:size(ε̇xy,2)-1, i ∈ 2:size(ε̇xy,1)-1 + v = MatParam[Phasev[i,j]].CompositeRheology[1] + args = (; τII_old = τii0v[i,j], dt=Δt) + ηv[i,j] = computeViscosity_εII(v, ε̇iiv[i,j], args) + τxy[i,j] = 2*ηv[i,j]*ε̇xy[i,j] end end @@ -120,7 +157,8 @@ end Vx .= εbg.*Xvx Vy .= .-εbg.*Yvy # Time loop - t=0.0; evo_t=[]; evo_τxx=[] + t=0.0; evo_t=[]; evo_τxx=[]; + global itg = 1 for it = 1:nt iter=1; err=2*ε; err_evo1=[]; err_evo2=[]; τxx0.=τxx; τyy0.=τyy; τxy0.=τxy diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams_v2.jl b/GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams_v2.jl new file mode 100644 index 0000000..48f3465 --- /dev/null +++ b/GeoParams_PT_examples/scripts/Stokes2D_VE_inclusion_GeoParams_v2.jl @@ -0,0 +1,204 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra, GeoParams +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +@generated function phase_viscosity(v::NTuple{N,Any}, ε̇ii, phase, args) where N + quote + Base.@_inline_meta + Base.@nexprs $N i -> v[i].Phase === phase && return computeViscosity_εII(v[i].CompositeRheology[1], ε̇ii, args) + end +end +# Rheology +@views function UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, MatParam, Δt, Phasec, Phasev ) + # ε̇iic .= sqrt.(1//2 .*(ε̇xx.^2 .+ ε̇yy.^2) .+ av(ε̇xy).^2) + # ε̇iiv[2:end-1,2:end-1] .= sqrt.(1//2 .*( av(ε̇xx).^2 .+ av(ε̇yy).^2) .+ ε̇xy[2:end-1,2:end-1].^2) + # τii0c .= sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) + # τii0v[2:end-1,2:end-1] .= sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) + # Centroids + for j ∈ axes(ε̇xx,2), i ∈ axes(ε̇xx,1) + # v = MatParam[Phasec[i]].CompositeRheology[1] # indexation of MatParam with Phasec[i] causes allocation + τxy0c = .25*(τxy0[i,j] + τxy0[i+1,j] + τxy0[i,j+1] + τxy0[i+1,j+1]) + ε̇xyc = .25*( ε̇xy[i,j] + ε̇xy[i+1,j] + ε̇xy[i,j+1] + ε̇xy[i+1,j+1]) + τii0 = sqrt.(0.5 *(τxx0[i,j]^2 + τyy0[i,j]^2) + τxy0c^2) + ε̇ii = sqrt.(0.5 *( ε̇xx[i,j]^2 + ε̇yy[i,j]^2) + ε̇xyc^2) + args = (; τII_old = τii0, dt=Δt) + ηc[i,j] = phase_viscosity(MatParam, ε̇ii, Phasec[i,j], args) + τxx[i,j] = 2*ηc[i,j]*ε̇xx[i,j] + τyy[i,j] = 2*ηc[i,j]*ε̇yy[i,j] + end + # Vertices + for j ∈ 2:size(ε̇xy,2)-1, i ∈ 2:size(ε̇xy,1)-1 + τxx0c = .25*(τxx0[i,j] + τxx0[i-1,j] + τxx0[i,j-1] + τxx0[i-1,j-1]) + τyy0c = .25*(τyy0[i,j] + τyy0[i-1,j] + τyy0[i,j-1] + τyy0[i-1,j-1]) + ε̇xxc = .25*( ε̇xx[i,j] + ε̇xx[i-1,j] + ε̇xx[i,j-1] + ε̇xx[i-1,j-1]) + ε̇yyc = .25*( ε̇yy[i,j] + ε̇yy[i-1,j] + ε̇yy[i,j-1] + ε̇yy[i-1,j-1]) + τii0 = sqrt.(0.5 *(τxx0c^2 + τyy0c^2) + τxy0[i,j]^2) + ε̇ii = sqrt.(0.5 *( ε̇xxc^2 + ε̇yyc^2) + ε̇xy[i,j]^2) + args = (; τII_old = τii0, dt=Δt) + ηv[i,j] = phase_viscosity(MatParam, ε̇ii, Phasev[i,j], args) + τxy[i,j] = 2*ηv[i,j]*ε̇xy[i,j] + end +end + +# 2D Stokes routine +@views function Stokes2D_VE_inclusion(UseGeoParams) + # Physics + Lx, Ly = 1.0, 1.0 # domain size + ξ = 10.0 # Maxwell relaxation time + η0 = 1.0 # viscous viscosity + G = 1.0 # elastic shear modulus + εbg = 1.0 # background strain-rate + radi = 0.01 + + MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G),LinearViscous(η=η0))), + SetMaterialParams(Name="Inclusion", Phase=2, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G/6),LinearViscous(η=η0))), + ) + + # Numerics + nt = 10 # number of time steps + ncx, ncy = 31, 31 # numerical grid resolution + ε = 1e-6 # nonlinear tolerence + iterMax = 1e4 # max number of iters + nout = 500 # check frequency + # Iterative parameters ------------------------------------------- + Reopt = 5π + cfl = 0.50 + ρ = cfl*Reopt/ncx + # Preprocessing + Δx, Δy = Lx/ncx, Ly/ncy + Δt = η0/(G*ξ + 1e-15) + # Array initialisation + Pt = zeros(Dat, ncx ,ncy ) + ∇V = zeros(Dat, ncx ,ncy ) + Vx = zeros(Dat, ncx+1,ncy+2) + Vy = zeros(Dat, ncx+2,ncy+1) + ε̇xx = zeros(Dat, ncx ,ncy ) + ε̇yy = zeros(Dat, ncx ,ncy ) + ε̇xy = zeros(Dat, ncx+1,ncy+1) + τxx = zeros(Dat, ncx ,ncy ) + τyy = zeros(Dat, ncx ,ncy ) + τxy = zeros(Dat, ncx+1,ncy+1) + τxx0 = zeros(Dat, ncx ,ncy ) + τyy0 = zeros(Dat, ncx ,ncy ) + τxy0 = zeros(Dat, ncx+1,ncy+1) + Rx = zeros(Dat, ncx+1,ncy ) + Ry = zeros(Dat, ncx ,ncy+1) + Rp = zeros(Dat, ncx ,ncy ) + dVxdτ = zeros(Dat, ncx+1,ncy ) + dVydτ = zeros(Dat, ncx ,ncy+1) + dPdτ = zeros(Dat, ncx ,ncy ) + Δτv = zeros(Dat, ncx+1,ncy+1) + Δτvx = zeros(Dat, ncx+1,ncy ) + Δτvy = zeros(Dat, ncx ,ncy+1) + κΔτp = zeros(Dat, ncx ,ncy ) + Rog = zeros(Dat, ncx ,ncy ) + ηc = η0*ones(Dat, ncx, ncy) + ηv = η0*ones(Dat, ncx+1, ncy+1) + Phasec = ones(Int, ncx ,ncy ) + Phasev = ones(Int, ncx+1,ncy+1) + # For geoparams + τii0c = zeros(size(ε̇xx)) + τii0v = zeros(size(ε̇xy)) + ε̇iic = zeros(size(ε̇xx)) + ε̇iiv = zeros(size(ε̇xy)) + # For non-geoparams version + η, G = 1.0, 1.0 + ηe_c = Δt*G.*ones(Dat, ncx ,ncy ) + ηe_v = Δt*G.*ones(Dat, ncx+1,ncy+1) + ηve_c = zeros(Dat, ncx ,ncy ) + ηve_v = zeros(Dat, ncx+1,ncy+1) + # Initialisation + xce, yce = LinRange(-Δx/2, Lx+Δx/2, ncx+2), LinRange(-Δy/2, Ly+Δy/2, ncy+2) + xc, yc = LinRange(Δx/2, Lx-Δx/2, ncx), LinRange(Δy/2, Ly-Δy/2, ncy) + xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + # For non-geoparams version + Phasec[radc.ε && iter<=iterMax) + # BCs + Vx[:,1] .= Vx[:,2] # S + Vx[:,end] .= Vx[:,end-1] # N + Vy[1,:] .= Vy[2,:] # W + Vy[end,:] .= Vy[end-1,:] # E + # Kinematics + ∇V .= diff(Vx[:,2:end-1], dims=1)./Δx .+ diff(Vy[2:end-1,:], dims=2)./Δy + ε̇xx .= diff(Vx[:,2:end-1], dims=1)./Δx .- 1.0/3.0*∇V + ε̇yy .= diff(Vy[2:end-1,:], dims=2)./Δy .- 1.0/3.0*∇V + ε̇xy .= 0.5.*(diff(Vx, dims=2)./Δy .+ diff(Vy, dims=1)./Δx) + # Stresses + if UseGeoParams + UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, MatParam, Δt, Phasec, Phasev ) + else + τxx .= 2 .* ηve_c .* ( ε̇xx .+ τxx0./(2 .* ηe_c) ) + τyy .= 2 .* ηve_c .* ( ε̇yy .+ τyy0./(2 .* ηe_c) ) + τxy .= 2 .* ηve_v .* ( ε̇xy .+ τxy0./(2 .* ηe_v) ) + end + # Residuals + Rx[2:end-1,:] .= .-diff(Pt, dims=1)./Δx .+ diff(τxx, dims=1)./Δx .+ diff(τxy[2:end-1,:], dims=2)./Δy + Ry[:,2:end-1] .= .-diff(Pt, dims=2)./Δy .+ diff(τyy, dims=2)./Δy .+ diff(τxy[:,2:end-1], dims=1)./Δx #.+ av_ya(Rog) + Rp .= .-∇V + # PT time step ----------------------------------------------- + Δτv .= ρ*min(Δx,Δy)^2 ./ ηv ./ 4.1 * cfl + Δτvx .= (Δτv[:,1:end-1] .+ Δτv[:,2:end]) / 2. + Δτvy .= (Δτv[1:end-1,:] .+ Δτv[2:end,:]) / 2. + κΔτp .= cfl .* ηc .* Δx ./ Lx + # Calculate rate update -------------------------------------- + dVxdτ .= (1-ρ) .* dVxdτ .+ Rx + dVydτ .= (1-ρ) .* dVydτ .+ Ry + dPdτ .= Rp + # Update velocity and pressure ------------------------------- + Vx[:,2:end-1] .+= Δτvx ./ ρ .* dVxdτ + Vy[2:end-1,:] .+= Δτvy ./ ρ .* dVydτ + Pt .+= κΔτp .* dPdτ + # convergence check + if mod(iter, nout)==0 || iter==1 + norm_Rx = norm(Rx)/sqrt(length(Rx)); norm_Ry = norm(Ry)/sqrt(length(Ry)); norm_∇V = norm(∇V)/sqrt(length(∇V)) + err = maximum([norm_Rx, norm_Ry, norm_∇V]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %03d, iter = %04d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V) + end + iter+=1; global itg=iter + end + # t = t + Δt + # push!(evo_t, t); push!(evo_τxx, maximum(τxx)) + # Plotting + # p1 = heatmap(xv, yc, Vx[:,2:end-1]', aspect_ratio=1, xlims=(0, Lx), ylims=(Δy/2, Ly-Δy/2), c=:inferno, title="Vx") + # p2 = heatmap(xc, yv, Vy[2:end-1,:]', aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="Vy") + # p3 = heatmap(xc, yc, Pt' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="P") + # # p3 = heatmap(xv, yv, τxy' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="τxy") + # p4 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + # p4 = plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewidth=2.0) # analytical solution + # display(plot(p1, p2, p3, p4)) + end + return +end + +for i=1:2 + println("step $i") + @time Stokes2D_VE_inclusion(false) + @time Stokes2D_VE_inclusion(true) +end \ No newline at end of file From 74b91339c2db6f9adf2272c7e946948557d0a39b Mon Sep 17 00:00:00 2001 From: Boris Kaus Date: Wed, 26 Oct 2022 14:11:27 -0300 Subject: [PATCH 16/49] example with (regularised) Drucker-Prager plasticity used through GeoParams --- .../Stokes2D_VEP_inclusion_GeoParams_v2.jl | 223 ++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100644 GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v2.jl diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v2.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v2.jl new file mode 100644 index 0000000..9b92a93 --- /dev/null +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v2.jl @@ -0,0 +1,223 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra, GeoParams +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +@generated function phase_viscosity(v::NTuple{N,Any}, ε̇ii, phase, args) where N + quote + Base.@_inline_meta + Base.@nexprs $N i -> v[i].Phase === phase && return computeViscosity_εII(v[i].CompositeRheology[1], ε̇ii, args) + end +end +# Rheology +@views function UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, Pt, MatParam, Δt, Phasec, Phasev ) + # ε̇iic .= sqrt.(1//2 .*(ε̇xx.^2 .+ ε̇yy.^2) .+ av(ε̇xy).^2) + # ε̇iiv[2:end-1,2:end-1] .= sqrt.(1//2 .*( av(ε̇xx).^2 .+ av(ε̇yy).^2) .+ ε̇xy[2:end-1,2:end-1].^2) + # τii0c .= sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) + # τii0v[2:end-1,2:end-1] .= sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) + # Centroids + for j ∈ axes(ε̇xx,2), i ∈ axes(ε̇xx,1) + # v = MatParam[Phasec[i]].CompositeRheology[1] # indexation of MatParam with Phasec[i] causes allocation + τxy0c_2 = .25*(τxy0[i,j]^2 + τxy0[i+1,j]^2 + τxy0[i,j+1]^2 + τxy0[i+1,j+1]^2) # you need to average squares! + ε̇xyc_2 = .25*( ε̇xy[i,j]^2 + ε̇xy[i+1,j]^2 + ε̇xy[i,j+1]^2 + ε̇xy[i+1,j+1]^2) + τii0 = sqrt.(0.5 *(τxx0[i,j]^2 + τyy0[i,j]^2) + τxy0c_2) + ε̇ii = sqrt.(0.5 *( ε̇xx[i,j]^2 + ε̇yy[i,j]^2) + ε̇xyc_2) + args = (; τII_old = τii0, dt=Δt, P=Pt[i,j]) + ηc[i,j] = phase_viscosity(MatParam, ε̇ii, Phasec[i,j], args) + τxx[i,j] = 2*ηc[i,j]*ε̇xx[i,j] + τyy[i,j] = 2*ηc[i,j]*ε̇yy[i,j] + end + # Vertices + for j ∈ 2:size(ε̇xy,2)-1, i ∈ 2:size(ε̇xy,1)-1 + τxx0c_2 = .25*(τxx0[i,j]^2 + τxx0[i-1,j]^2 + τxx0[i,j-1]^2 + τxx0[i-1,j-1]^2) + τyy0c_2 = .25*(τyy0[i,j]^2 + τyy0[i-1,j]^2 + τyy0[i,j-1]^2 + τyy0[i-1,j-1]^2) + ε̇xxc_2 = .25*( ε̇xx[i,j]^2 + ε̇xx[i-1,j]^2 + ε̇xx[i,j-1]^2 + ε̇xx[i-1,j-1]^2) + ε̇yyc_2 = .25*( ε̇yy[i,j]^2 + ε̇yy[i-1,j]^2 + ε̇yy[i,j-1]^2 + ε̇yy[i-1,j-1]^2) + Pc = .25*( Pt[i,j] + Pt[i-1,j] + Pt[i,j-1] + Pt[i-1,j-1]) + + τii0 = sqrt.(0.5 *(τxx0c_2 + τyy0c_2) + τxy0[i,j]^2) + ε̇ii = sqrt.(0.5 *( ε̇xxc_2 + ε̇yyc_2) + ε̇xy[i,j]^2) + args = (; τII_old = τii0, dt=Δt, P=Pc) + ηv[i,j] = phase_viscosity(MatParam, ε̇ii, Phasev[i,j], args) + τxy[i,j] = 2*ηv[i,j]*ε̇xy[i,j] + end +end + +# 2D Stokes routine +@views function Stokes2D_VE_inclusion(UseGeoParams, doPlot = false) + # Physics + do_DP = true + Lx, Ly = 1.0, 1.0 # domain size + ξ = 10.0 # Maxwell relaxation time + η0 = 1.0 # viscous viscosity + G0 = 1.0 # elastic shear modulus + εbg = 1.0 # background strain-rate + radi = 0.01 + τ_y = 1.6 + Gi = G0/(6.0-4.0*do_DP) # inclusion shear modulus + η_reg = 1.2e-2 # regularisation "viscosity" + ϕ = 30*do_DP + Coh = 1.6/cosd(ϕ) # cohesion + + #pl = DruckerPrager(C=Coh, ϕ=30) # non-regularized plasticity + #pl = Parallel(DruckerPrager(C=Coh, ϕ=ϕ), LinearViscous(η=η_reg)) + pl = DruckerPrager_regularised(C=Coh, ϕ=30, η_vp=η_reg) # non-regularized plasticity + + MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G0),LinearViscous(η=η0), pl)), + SetMaterialParams(Name="Inclusion", Phase=2, + CompositeRheology = CompositeRheology(ConstantElasticity(G=Gi),LinearViscous(η=η0), pl)), + ) + + # Numerics + nt = 20 # number of time steps + ncx, ncy = 31, 31 # numerical grid resolution + ε = 1e-6 # nonlinear tolerence + iterMax = 1e4 # max number of iters + nout = 500 # check frequency + # Iterative parameters ------------------------------------------- + Reopt = 5π + cfl = 0.50 + ρ = cfl*Reopt/ncx + # Preprocessing + Δx, Δy = Lx/ncx, Ly/ncy + Δt = η0/(G0*ξ + 1e-15) + # Array initialisation + Pt = zeros(Dat, ncx ,ncy ) + ∇V = zeros(Dat, ncx ,ncy ) + Vx = zeros(Dat, ncx+1,ncy+2) + Vy = zeros(Dat, ncx+2,ncy+1) + ε̇xx = zeros(Dat, ncx ,ncy ) + ε̇yy = zeros(Dat, ncx ,ncy ) + ε̇xy = zeros(Dat, ncx+1,ncy+1) + τxx = zeros(Dat, ncx ,ncy ) + τyy = zeros(Dat, ncx ,ncy ) + τxy = zeros(Dat, ncx+1,ncy+1) + τxx0 = zeros(Dat, ncx ,ncy ) + τyy0 = zeros(Dat, ncx ,ncy ) + τxy0 = zeros(Dat, ncx+1,ncy+1) + Rx = zeros(Dat, ncx+1,ncy ) + Ry = zeros(Dat, ncx ,ncy+1) + Rp = zeros(Dat, ncx ,ncy ) + dVxdτ = zeros(Dat, ncx+1,ncy ) + dVydτ = zeros(Dat, ncx ,ncy+1) + dPdτ = zeros(Dat, ncx ,ncy ) + Δτv = zeros(Dat, ncx+1,ncy+1) + Δτvx = zeros(Dat, ncx+1,ncy ) + Δτvy = zeros(Dat, ncx ,ncy+1) + κΔτp = zeros(Dat, ncx ,ncy ) + Rog = zeros(Dat, ncx ,ncy ) + ηc = η0*ones(Dat, ncx, ncy) + ηv = η0*ones(Dat, ncx+1, ncy+1) + Phasec = ones(Int, ncx ,ncy ) + Phasev = ones(Int, ncx+1,ncy+1) + # For geoparams + τii0c = zeros(size(ε̇xx)) + τii0v = zeros(size(ε̇xy)) + ε̇iic = zeros(size(ε̇xx)) + ε̇iiv = zeros(size(ε̇xy)) + # For non-geoparams version + η, G = 1.0, 1.0 + ηe_c = Δt*G.*ones(Dat, ncx ,ncy ) + ηe_v = Δt*G.*ones(Dat, ncx+1,ncy+1) + ηve_c = zeros(Dat, ncx ,ncy ) + ηve_v = zeros(Dat, ncx+1,ncy+1) + # Initialisation + xce, yce = LinRange(-Δx/2, Lx+Δx/2, ncx+2), LinRange(-Δy/2, Ly+Δy/2, ncy+2) + xc, yc = LinRange(Δx/2, Lx-Δx/2, ncx), LinRange(Δy/2, Ly-Δy/2, ncy) + xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + # For non-geoparams version + Phasec[radc.ε && iter<=iterMax) + # BCs + Vx[:,1] .= Vx[:,2] # S + Vx[:,end] .= Vx[:,end-1] # N + Vy[1,:] .= Vy[2,:] # W + Vy[end,:] .= Vy[end-1,:] # E + # Kinematics + ∇V .= diff(Vx[:,2:end-1], dims=1)./Δx .+ diff(Vy[2:end-1,:], dims=2)./Δy + ε̇xx .= diff(Vx[:,2:end-1], dims=1)./Δx .- 1.0/3.0*∇V + ε̇yy .= diff(Vy[2:end-1,:], dims=2)./Δy .- 1.0/3.0*∇V + ε̇xy .= 0.5.*(diff(Vx, dims=2)./Δy .+ diff(Vy, dims=1)./Δx) + # Stresses + if UseGeoParams + UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, Pt, MatParam, Δt, Phasec, Phasev ) + else + τxx .= 2 .* ηve_c .* ( ε̇xx .+ τxx0./(2 .* ηe_c) ) + τyy .= 2 .* ηve_c .* ( ε̇yy .+ τyy0./(2 .* ηe_c) ) + τxy .= 2 .* ηve_v .* ( ε̇xy .+ τxy0./(2 .* ηe_v) ) + end + # Residuals + Rx[2:end-1,:] .= .-diff(Pt, dims=1)./Δx .+ diff(τxx, dims=1)./Δx .+ diff(τxy[2:end-1,:], dims=2)./Δy + Ry[:,2:end-1] .= .-diff(Pt, dims=2)./Δy .+ diff(τyy, dims=2)./Δy .+ diff(τxy[:,2:end-1], dims=1)./Δx #.+ av_ya(Rog) + Rp .= .-∇V + # PT time step ----------------------------------------------- + Δτv .= ρ*min(Δx,Δy)^2 ./ ηv ./ 4.1 * cfl + Δτvx .= (Δτv[:,1:end-1] .+ Δτv[:,2:end]) / 2. + Δτvy .= (Δτv[1:end-1,:] .+ Δτv[2:end,:]) / 2. + κΔτp .= cfl .* ηc .* Δx ./ Lx + # Calculate rate update -------------------------------------- + dVxdτ .= (1-ρ) .* dVxdτ .+ Rx + dVydτ .= (1-ρ) .* dVydτ .+ Ry + dPdτ .= Rp + # Update velocity and pressure ------------------------------- + Vx[:,2:end-1] .+= Δτvx ./ ρ .* dVxdτ + Vy[2:end-1,:] .+= Δτvy ./ ρ .* dVydτ + Pt .+= κΔτp .* dPdτ + # convergence check + if mod(iter, nout)==0 || iter==1 + norm_Rx = norm(Rx)/sqrt(length(Rx)); norm_Ry = norm(Ry)/sqrt(length(Ry)); norm_∇V = norm(∇V)/sqrt(length(∇V)) + err = maximum([norm_Rx, norm_Ry, norm_∇V]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %03d, iter = %04d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V) + end + iter+=1; global itg=iter + end + t = t + Δt + push!(evo_t, t); push!(evo_τxx, maximum(τxx)) + + if doPlot + # Plotting + p1 = heatmap(xv, yc, Vx[:,2:end-1]', aspect_ratio=1, xlims=(0, Lx), ylims=(Δy/2, Ly-Δy/2), c=:inferno, title="Vx") + p2 = heatmap(xc, yv, Vy[2:end-1,:]', aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p3 = heatmap(xc, yc, Pt' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="P") + #p3 = heatmap(xv, yv, τxy' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="τxy") + p4 = plot(evo_t, evo_τxx , xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, markersize=3) + p4 = plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewidth=2.0) # analytical solution + display(plot(p1, p2, p3, p4)) + end + end + return +end + +for i=1:1 + println("step $i") + #@time Stokes2D_VE_inclusion(false, false) + @time Stokes2D_VE_inclusion(true, true) +end \ No newline at end of file From 11079720001bd4f93e74f7b9758f2e57b1a1e784 Mon Sep 17 00:00:00 2001 From: Boris Kaus Date: Wed, 26 Oct 2022 19:38:39 -0300 Subject: [PATCH 17/49] added Manifest file (so you have the correct version of GeoParams) --- GeoParams_PT_examples/Manifest.toml | 1068 +++++++++++++++++++++++++++ 1 file changed, 1068 insertions(+) create mode 100644 GeoParams_PT_examples/Manifest.toml diff --git a/GeoParams_PT_examples/Manifest.toml b/GeoParams_PT_examples/Manifest.toml new file mode 100644 index 0000000..7a4b09c --- /dev/null +++ b/GeoParams_PT_examples/Manifest.toml @@ -0,0 +1,1068 @@ +# This file is machine-generated - editing it directly is not advised + +julia_version = "1.7.2" +manifest_format = "2.0" + +[[deps.Adapt]] +deps = ["LinearAlgebra"] +git-tree-sha1 = "195c5505521008abea5aee4f96930717958eac6f" +uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" +version = "3.4.0" + +[[deps.ArgTools]] +uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" + +[[deps.Artifacts]] +uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" + +[[deps.AxisAlgorithms]] +deps = ["LinearAlgebra", "Random", "SparseArrays", "WoodburyMatrices"] +git-tree-sha1 = "66771c8d21c8ff5e3a93379480a2307ac36863f7" +uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950" +version = "1.0.1" + +[[deps.Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[deps.BibTeX]] +git-tree-sha1 = "e16505bdc7c0177d0a1709022d4ac41d51c5181d" +uuid = "7b0aa2c9-049f-5cec-894a-2b6b781bb25e" +version = "0.1.0" + +[[deps.BitFlags]] +git-tree-sha1 = "84259bb6172806304b9101094a7cc4bc6f56dbc6" +uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35" +version = "0.1.5" + +[[deps.Bzip2_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "19a35467a82e236ff51bc17a3a44b69ef35185a2" +uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0" +version = "1.0.8+0" + +[[deps.Cairo_jll]] +deps = ["Artifacts", "Bzip2_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"] +git-tree-sha1 = "4b859a208b2397a7a623a03449e4636bdb17bcf2" +uuid = "83423d85-b0ee-5818-9007-b63ccbeb887a" +version = "1.16.1+1" + +[[deps.ChainRulesCore]] +deps = ["Compat", "LinearAlgebra", "SparseArrays"] +git-tree-sha1 = "e7ff6cadf743c098e08fca25c91103ee4303c9bb" +uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" +version = "1.15.6" + +[[deps.ChangesOfVariables]] +deps = ["ChainRulesCore", "LinearAlgebra", "Test"] +git-tree-sha1 = "38f7a08f19d8810338d4f5085211c7dfa5d5bdd8" +uuid = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0" +version = "0.1.4" + +[[deps.CodecZlib]] +deps = ["TranscodingStreams", "Zlib_jll"] +git-tree-sha1 = "ded953804d019afa9a3f98981d99b33e3db7b6da" +uuid = "944b1d66-785c-5afd-91f1-9de20f533193" +version = "0.7.0" + +[[deps.ColorSchemes]] +deps = ["ColorTypes", "ColorVectorSpace", "Colors", "FixedPointNumbers", "Random"] +git-tree-sha1 = "1fd869cc3875b57347f7027521f561cf46d1fcd8" +uuid = "35d6a980-a343-548e-a6ea-1d62b119f2f4" +version = "3.19.0" + +[[deps.ColorTypes]] +deps = ["FixedPointNumbers", "Random"] +git-tree-sha1 = "eb7f0f8307f71fac7c606984ea5fb2817275d6e4" +uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" +version = "0.11.4" + +[[deps.ColorVectorSpace]] +deps = ["ColorTypes", "FixedPointNumbers", "LinearAlgebra", "SpecialFunctions", "Statistics", "TensorCore"] +git-tree-sha1 = "d08c20eef1f2cbc6e60fd3612ac4340b89fea322" +uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4" +version = "0.9.9" + +[[deps.Colors]] +deps = ["ColorTypes", "FixedPointNumbers", "Reexport"] +git-tree-sha1 = "417b0ed7b8b838aa6ca0a87aadf1bb9eb111ce40" +uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" +version = "0.12.8" + +[[deps.CommonSolve]] +git-tree-sha1 = "9441451ee712d1aec22edad62db1a9af3dc8d852" +uuid = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2" +version = "0.2.3" + +[[deps.CommonSubexpressions]] +deps = ["MacroTools", "Test"] +git-tree-sha1 = "7b8a93dba8af7e3b42fecabf646260105ac373f7" +uuid = "bbf7d656-a473-5ed7-a52c-81e309532950" +version = "0.3.0" + +[[deps.Compat]] +deps = ["Dates", "LinearAlgebra", "UUIDs"] +git-tree-sha1 = "3ca828fe1b75fa84b021a7860bd039eaea84d2f2" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "4.3.0" + +[[deps.CompilerSupportLibraries_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" + +[[deps.ConstructionBase]] +deps = ["LinearAlgebra"] +git-tree-sha1 = "fb21ddd70a051d882a1686a5a550990bbe371a95" +uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9" +version = "1.4.1" + +[[deps.Contour]] +git-tree-sha1 = "d05d9e7b7aedff4e5b51a029dced05cfb6125781" +uuid = "d38c429a-6771-53c6-b99e-75d170b6e991" +version = "0.6.2" + +[[deps.DataAPI]] +git-tree-sha1 = "46d2680e618f8abd007bce0c3026cb0c4a8f2032" +uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" +version = "1.12.0" + +[[deps.DataStructures]] +deps = ["Compat", "InteractiveUtils", "OrderedCollections"] +git-tree-sha1 = "d1fff3a548102f48987a52a2e0d114fa97d730f0" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.18.13" + +[[deps.Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[deps.DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[deps.DiffResults]] +deps = ["StaticArraysCore"] +git-tree-sha1 = "782dd5f4561f5d267313f23853baaaa4c52ea621" +uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5" +version = "1.1.0" + +[[deps.DiffRules]] +deps = ["IrrationalConstants", "LogExpFunctions", "NaNMath", "Random", "SpecialFunctions"] +git-tree-sha1 = "8b7a4d23e22f5d44883671da70865ca98f2ebf9d" +uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" +version = "1.12.0" + +[[deps.Distances]] +deps = ["LinearAlgebra", "SparseArrays", "Statistics", "StatsAPI"] +git-tree-sha1 = "3258d0659f812acde79e8a74b11f17ac06d0ca04" +uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7" +version = "0.10.7" + +[[deps.Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[deps.DocStringExtensions]] +deps = ["LibGit2"] +git-tree-sha1 = "c36550cb29cbe373e95b3f40486b9a4148f89ffd" +uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" +version = "0.9.2" + +[[deps.Downloads]] +deps = ["ArgTools", "LibCURL", "NetworkOptions"] +uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" + +[[deps.Expat_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "bad72f730e9e91c08d9427d5e8db95478a3c323d" +uuid = "2e619515-83b5-522b-bb60-26c02a35a201" +version = "2.4.8+0" + +[[deps.FFMPEG]] +deps = ["FFMPEG_jll"] +git-tree-sha1 = "b57e3acbe22f8484b4b5ff66a7499717fe1a9cc8" +uuid = "c87230d0-a227-11e9-1b43-d7ebe4e7570a" +version = "0.4.1" + +[[deps.FFMPEG_jll]] +deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "JLLWrappers", "LAME_jll", "Libdl", "Ogg_jll", "OpenSSL_jll", "Opus_jll", "PCRE2_jll", "Pkg", "Zlib_jll", "libaom_jll", "libass_jll", "libfdk_aac_jll", "libvorbis_jll", "x264_jll", "x265_jll"] +git-tree-sha1 = "74faea50c1d007c85837327f6775bea60b5492dd" +uuid = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5" +version = "4.4.2+2" + +[[deps.FixedPointNumbers]] +deps = ["Statistics"] +git-tree-sha1 = "335bfdceacc84c5cdf16aadc768aa5ddfc5383cc" +uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" +version = "0.8.4" + +[[deps.Fontconfig_jll]] +deps = ["Artifacts", "Bzip2_jll", "Expat_jll", "FreeType2_jll", "JLLWrappers", "Libdl", "Libuuid_jll", "Pkg", "Zlib_jll"] +git-tree-sha1 = "21efd19106a55620a188615da6d3d06cd7f6ee03" +uuid = "a3f928ae-7b40-5064-980b-68af3947d34b" +version = "2.13.93+0" + +[[deps.Formatting]] +deps = ["Printf"] +git-tree-sha1 = "8339d61043228fdd3eb658d86c926cb282ae72a8" +uuid = "59287772-0a20-5a39-b81b-1366585eb4c0" +version = "0.4.2" + +[[deps.ForwardDiff]] +deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "LinearAlgebra", "LogExpFunctions", "NaNMath", "Preferences", "Printf", "Random", "SpecialFunctions", "StaticArrays"] +git-tree-sha1 = "187198a4ed8ccd7b5d99c41b69c679269ea2b2d4" +uuid = "f6369f11-7733-5829-9624-2563aa707210" +version = "0.10.32" + +[[deps.FreeType2_jll]] +deps = ["Artifacts", "Bzip2_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"] +git-tree-sha1 = "87eb71354d8ec1a96d4a7636bd57a7347dde3ef9" +uuid = "d7e528f0-a631-5988-bf34-fe36492bcfd7" +version = "2.10.4+0" + +[[deps.FriBidi_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "aa31987c2ba8704e23c6c8ba8a4f769d5d7e4f91" +uuid = "559328eb-81f9-559d-9380-de523a88c83c" +version = "1.0.10+0" + +[[deps.Future]] +deps = ["Random"] +uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820" + +[[deps.GLFW_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Libglvnd_jll", "Pkg", "Xorg_libXcursor_jll", "Xorg_libXi_jll", "Xorg_libXinerama_jll", "Xorg_libXrandr_jll"] +git-tree-sha1 = "d972031d28c8c8d9d7b41a536ad7bb0c2579caca" +uuid = "0656b61e-2033-5cc2-a64a-77c0f6c09b89" +version = "3.3.8+0" + +[[deps.GR]] +deps = ["Base64", "DelimitedFiles", "GR_jll", "HTTP", "JSON", "Libdl", "LinearAlgebra", "Pkg", "Preferences", "Printf", "Random", "Serialization", "Sockets", "Test", "UUIDs"] +git-tree-sha1 = "00a9d4abadc05b9476e937a5557fcce476b9e547" +uuid = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" +version = "0.69.5" + +[[deps.GR_jll]] +deps = ["Artifacts", "Bzip2_jll", "Cairo_jll", "FFMPEG_jll", "Fontconfig_jll", "GLFW_jll", "JLLWrappers", "JpegTurbo_jll", "Libdl", "Libtiff_jll", "Pixman_jll", "Pkg", "Qt5Base_jll", "Zlib_jll", "libpng_jll"] +git-tree-sha1 = "bc9f7725571ddb4ab2c4bc74fa397c1c5ad08943" +uuid = "d2c73de3-f751-5644-a686-071e5b155ba9" +version = "0.69.1+0" + +[[deps.GeoParams]] +deps = ["BibTeX", "DelimitedFiles", "ForwardDiff", "Interpolations", "KernelDensitySJ", "LaTeXStrings", "Loess", "Parameters", "Requires", "Roots", "Setfield", "SpecialFunctions", "Static", "StaticArrays", "Statistics", "StatsBase", "UnPack", "Unidecode", "Unitful"] +git-tree-sha1 = "406f395a4e093ac5b79dd8da37d7854de1fa9fa8" +repo-rev = "adm-cuda-check" +repo-url = "https://github.com/JuliaGeodynamics/GeoParams.jl.git" +uuid = "e018b62d-d9de-4a26-8697-af89c310ae38" +version = "0.4.1" + +[[deps.Gettext_jll]] +deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "XML2_jll"] +git-tree-sha1 = "9b02998aba7bf074d14de89f9d37ca24a1a0b046" +uuid = "78b55507-aeef-58d4-861c-77aaff3498b1" +version = "0.21.0+0" + +[[deps.Glib_jll]] +deps = ["Artifacts", "Gettext_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Libiconv_jll", "Libmount_jll", "PCRE2_jll", "Pkg", "Zlib_jll"] +git-tree-sha1 = "fb83fbe02fe57f2c068013aa94bcdf6760d3a7a7" +uuid = "7746bdde-850d-59dc-9ae8-88ece973131d" +version = "2.74.0+1" + +[[deps.Graphite2_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "344bf40dcab1073aca04aa0df4fb092f920e4011" +uuid = "3b182d85-2403-5c21-9c21-1e1f0cc25472" +version = "1.3.14+0" + +[[deps.Grisu]] +git-tree-sha1 = "53bb909d1151e57e2484c3d1b53e19552b887fb2" +uuid = "42e2da0e-8278-4e71-bc24-59509adca0fe" +version = "1.0.2" + +[[deps.HTTP]] +deps = ["Base64", "CodecZlib", "Dates", "IniFile", "Logging", "LoggingExtras", "MbedTLS", "NetworkOptions", "OpenSSL", "Random", "SimpleBufferStream", "Sockets", "URIs", "UUIDs"] +git-tree-sha1 = "a97d47758e933cd5fe5ea181d178936a9fc60427" +uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3" +version = "1.5.1" + +[[deps.HarfBuzz_jll]] +deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "Graphite2_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg"] +git-tree-sha1 = "129acf094d168394e80ee1dc4bc06ec835e510a3" +uuid = "2e76f6c2-a576-52d4-95c1-20adfe4de566" +version = "2.8.1+1" + +[[deps.IfElse]] +git-tree-sha1 = "debdd00ffef04665ccbb3e150747a77560e8fad1" +uuid = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173" +version = "0.1.1" + +[[deps.IniFile]] +git-tree-sha1 = "f550e6e32074c939295eb5ea6de31849ac2c9625" +uuid = "83e8ac13-25f8-5344-8a64-a9f2b223428f" +version = "0.5.1" + +[[deps.InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[deps.Interpolations]] +deps = ["Adapt", "AxisAlgorithms", "ChainRulesCore", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "Requires", "SharedArrays", "SparseArrays", "StaticArrays", "WoodburyMatrices"] +git-tree-sha1 = "842dd89a6cb75e02e85fdd75c760cdc43f5d6863" +uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" +version = "0.14.6" + +[[deps.InverseFunctions]] +deps = ["Test"] +git-tree-sha1 = "49510dfcb407e572524ba94aeae2fced1f3feb0f" +uuid = "3587e190-3f89-42d0-90ee-14403ec27112" +version = "0.1.8" + +[[deps.IrrationalConstants]] +git-tree-sha1 = "7fd44fd4ff43fc60815f8e764c0f352b83c49151" +uuid = "92d709cd-6900-40b7-9082-c6be49f344b6" +version = "0.1.1" + +[[deps.JLFzf]] +deps = ["Pipe", "REPL", "Random", "fzf_jll"] +git-tree-sha1 = "f377670cda23b6b7c1c0b3893e37451c5c1a2185" +uuid = "1019f520-868f-41f5-a6de-eb00f4b6a39c" +version = "0.1.5" + +[[deps.JLLWrappers]] +deps = ["Preferences"] +git-tree-sha1 = "abc9885a7ca2052a736a600f7fa66209f96506e1" +uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" +version = "1.4.1" + +[[deps.JSON]] +deps = ["Dates", "Mmap", "Parsers", "Unicode"] +git-tree-sha1 = "3c837543ddb02250ef42f4738347454f95079d4e" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.21.3" + +[[deps.JpegTurbo_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "b53380851c6e6664204efb2e62cd24fa5c47e4ba" +uuid = "aacddb02-875f-59d6-b918-886e6ef4fbf8" +version = "2.1.2+0" + +[[deps.KernelDensitySJ]] +deps = ["DataStructures", "Roots", "Statistics"] +git-tree-sha1 = "e698e449fef8863e3b1d589829ee131cc63987c2" +uuid = "49dc5b4e-6806-4504-b2cc-a81764e7a38b" +version = "0.2.1" + +[[deps.LAME_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "f6250b16881adf048549549fba48b1161acdac8c" +uuid = "c1c5ebd0-6772-5130-a774-d5fcae4a789d" +version = "3.100.1+0" + +[[deps.LERC_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "bf36f528eec6634efc60d7ec062008f171071434" +uuid = "88015f11-f218-50d7-93a8-a6af411a945d" +version = "3.0.0+1" + +[[deps.LZO_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "e5b909bcf985c5e2605737d2ce278ed791b89be6" +uuid = "dd4b983a-f0e5-5f8d-a1b7-129d4a5fb1ac" +version = "2.10.1+0" + +[[deps.LaTeXStrings]] +git-tree-sha1 = "f2355693d6778a178ade15952b7ac47a4ff97996" +uuid = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" +version = "1.3.0" + +[[deps.Latexify]] +deps = ["Formatting", "InteractiveUtils", "LaTeXStrings", "MacroTools", "Markdown", "OrderedCollections", "Printf", "Requires"] +git-tree-sha1 = "ab9aa169d2160129beb241cb2750ca499b4e90e9" +uuid = "23fbe1c1-3f47-55db-b15f-69d7ec21a316" +version = "0.15.17" + +[[deps.LibCURL]] +deps = ["LibCURL_jll", "MozillaCACerts_jll"] +uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" + +[[deps.LibCURL_jll]] +deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] +uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" + +[[deps.LibGit2]] +deps = ["Base64", "NetworkOptions", "Printf", "SHA"] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[deps.LibSSH2_jll]] +deps = ["Artifacts", "Libdl", "MbedTLS_jll"] +uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" + +[[deps.Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[deps.Libffi_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "0b4a5d71f3e5200a7dff793393e09dfc2d874290" +uuid = "e9f186c6-92d2-5b65-8a66-fee21dc1b490" +version = "3.2.2+1" + +[[deps.Libgcrypt_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgpg_error_jll", "Pkg"] +git-tree-sha1 = "64613c82a59c120435c067c2b809fc61cf5166ae" +uuid = "d4300ac3-e22c-5743-9152-c294e39db1e4" +version = "1.8.7+0" + +[[deps.Libglvnd_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll", "Xorg_libXext_jll"] +git-tree-sha1 = "7739f837d6447403596a75d19ed01fd08d6f56bf" +uuid = "7e76a0d4-f3c7-5321-8279-8d96eeed0f29" +version = "1.3.0+3" + +[[deps.Libgpg_error_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "c333716e46366857753e273ce6a69ee0945a6db9" +uuid = "7add5ba3-2f88-524e-9cd5-f83b8a55f7b8" +version = "1.42.0+0" + +[[deps.Libiconv_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "42b62845d70a619f063a7da093d995ec8e15e778" +uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531" +version = "1.16.1+1" + +[[deps.Libmount_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "9c30530bf0effd46e15e0fdcf2b8636e78cbbd73" +uuid = "4b2f31a3-9ecc-558c-b454-b3730dcb73e9" +version = "2.35.0+0" + +[[deps.Libtiff_jll]] +deps = ["Artifacts", "JLLWrappers", "JpegTurbo_jll", "LERC_jll", "Libdl", "Pkg", "Zlib_jll", "Zstd_jll"] +git-tree-sha1 = "3eb79b0ca5764d4799c06699573fd8f533259713" +uuid = "89763e89-9b03-5906-acba-b20f662cd828" +version = "4.4.0+0" + +[[deps.Libuuid_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "7f3efec06033682db852f8b3bc3c1d2b0a0ab066" +uuid = "38a345b3-de98-5d2b-a5d3-14cd9215e700" +version = "2.36.0+0" + +[[deps.LinearAlgebra]] +deps = ["Libdl", "libblastrampoline_jll"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[deps.Loess]] +deps = ["Distances", "LinearAlgebra", "Statistics"] +git-tree-sha1 = "46efcea75c890e5d820e670516dc156689851722" +uuid = "4345ca2d-374a-55d4-8d30-97f9976e7612" +version = "0.5.4" + +[[deps.LogExpFunctions]] +deps = ["ChainRulesCore", "ChangesOfVariables", "DocStringExtensions", "InverseFunctions", "IrrationalConstants", "LinearAlgebra"] +git-tree-sha1 = "94d9c52ca447e23eac0c0f074effbcd38830deb5" +uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688" +version = "0.3.18" + +[[deps.Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[deps.LoggingExtras]] +deps = ["Dates", "Logging"] +git-tree-sha1 = "5d4d2d9904227b8bd66386c1138cf4d5ffa826bf" +uuid = "e6f89c97-d47a-5376-807f-9c37f3926c36" +version = "0.4.9" + +[[deps.MacroTools]] +deps = ["Markdown", "Random"] +git-tree-sha1 = "42324d08725e200c23d4dfb549e0d5d89dede2d2" +uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +version = "0.5.10" + +[[deps.Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[deps.MbedTLS]] +deps = ["Dates", "MbedTLS_jll", "MozillaCACerts_jll", "Random", "Sockets"] +git-tree-sha1 = "03a9b9718f5682ecb107ac9f7308991db4ce395b" +uuid = "739be429-bea8-5141-9913-cc70e7f3736d" +version = "1.1.7" + +[[deps.MbedTLS_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" + +[[deps.Measures]] +git-tree-sha1 = "e498ddeee6f9fdb4551ce855a46f54dbd900245f" +uuid = "442fdcdd-2543-5da2-b0f3-8c86c306513e" +version = "0.3.1" + +[[deps.Missings]] +deps = ["DataAPI"] +git-tree-sha1 = "bf210ce90b6c9eed32d25dbcae1ebc565df2687f" +uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" +version = "1.0.2" + +[[deps.Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[deps.MozillaCACerts_jll]] +uuid = "14a3606d-f60d-562e-9121-12d972cd8159" + +[[deps.NaNMath]] +deps = ["OpenLibm_jll"] +git-tree-sha1 = "a7c3d1da1189a1c2fe843a3bfa04d18d20eb3211" +uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" +version = "1.0.1" + +[[deps.NetworkOptions]] +uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" + +[[deps.OffsetArrays]] +deps = ["Adapt"] +git-tree-sha1 = "f71d8950b724e9ff6110fc948dff5a329f901d64" +uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" +version = "1.12.8" + +[[deps.Ogg_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "887579a3eb005446d514ab7aeac5d1d027658b8f" +uuid = "e7412a2a-1a6e-54c0-be00-318e2571c051" +version = "1.3.5+1" + +[[deps.OpenBLAS_jll]] +deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"] +uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" + +[[deps.OpenLibm_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "05823500-19ac-5b8b-9628-191a04bc5112" + +[[deps.OpenSSL]] +deps = ["BitFlags", "Dates", "MozillaCACerts_jll", "OpenSSL_jll", "Sockets"] +git-tree-sha1 = "3c3c4a401d267b04942545b1e964a20279587fd7" +uuid = "4d8831e6-92b7-49fb-bdf8-b643e874388c" +version = "1.3.0" + +[[deps.OpenSSL_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "e60321e3f2616584ff98f0a4f18d98ae6f89bbb3" +uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95" +version = "1.1.17+0" + +[[deps.OpenSpecFun_jll]] +deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "13652491f6856acfd2db29360e1bbcd4565d04f1" +uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e" +version = "0.5.5+0" + +[[deps.Opus_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "51a08fb14ec28da2ec7a927c4337e4332c2a4720" +uuid = "91d4177d-7536-5919-b921-800302f37372" +version = "1.3.2+0" + +[[deps.OrderedCollections]] +git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.4.1" + +[[deps.PCRE2_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "efcefdf7-47ab-520b-bdef-62a2eaa19f15" + +[[deps.Parameters]] +deps = ["OrderedCollections", "UnPack"] +git-tree-sha1 = "34c0e9ad262e5f7fc75b10a9952ca7692cfc5fbe" +uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a" +version = "0.12.3" + +[[deps.Parsers]] +deps = ["Dates"] +git-tree-sha1 = "6c01a9b494f6d2a9fc180a08b182fcb06f0958a0" +uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" +version = "2.4.2" + +[[deps.Pipe]] +git-tree-sha1 = "6842804e7867b115ca9de748a0cf6b364523c16d" +uuid = "b98c9c47-44ae-5843-9183-064241ee97a0" +version = "1.3.0" + +[[deps.Pixman_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "b4f5d02549a10e20780a24fce72bea96b6329e29" +uuid = "30392449-352a-5448-841d-b1acce4e97dc" +version = "0.40.1+0" + +[[deps.Pkg]] +deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[deps.PlotThemes]] +deps = ["PlotUtils", "Statistics"] +git-tree-sha1 = "1f03a2d339f42dca4a4da149c7e15e9b896ad899" +uuid = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a" +version = "3.1.0" + +[[deps.PlotUtils]] +deps = ["ColorSchemes", "Colors", "Dates", "Printf", "Random", "Reexport", "SnoopPrecompile", "Statistics"] +git-tree-sha1 = "21303256d239f6b484977314674aef4bb1fe4420" +uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043" +version = "1.3.1" + +[[deps.Plots]] +deps = ["Base64", "Contour", "Dates", "Downloads", "FFMPEG", "FixedPointNumbers", "GR", "JLFzf", "JSON", "LaTeXStrings", "Latexify", "LinearAlgebra", "Measures", "NaNMath", "Pkg", "PlotThemes", "PlotUtils", "Printf", "REPL", "Random", "RecipesBase", "RecipesPipeline", "Reexport", "RelocatableFolders", "Requires", "Scratch", "Showoff", "SnoopPrecompile", "SparseArrays", "Statistics", "StatsBase", "UUIDs", "UnicodeFun", "Unzip"] +git-tree-sha1 = "0a56829d264eb1bc910cf7c39ac008b5bcb5a0d9" +uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +version = "1.35.5" + +[[deps.Preferences]] +deps = ["TOML"] +git-tree-sha1 = "47e5f437cc0e7ef2ce8406ce1e7e24d44915f88d" +uuid = "21216c6a-2e73-6563-6e65-726566657250" +version = "1.3.0" + +[[deps.Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[deps.Qt5Base_jll]] +deps = ["Artifacts", "CompilerSupportLibraries_jll", "Fontconfig_jll", "Glib_jll", "JLLWrappers", "Libdl", "Libglvnd_jll", "OpenSSL_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libxcb_jll", "Xorg_xcb_util_image_jll", "Xorg_xcb_util_keysyms_jll", "Xorg_xcb_util_renderutil_jll", "Xorg_xcb_util_wm_jll", "Zlib_jll", "xkbcommon_jll"] +git-tree-sha1 = "c6c0f690d0cc7caddb74cef7aa847b824a16b256" +uuid = "ea2cea3b-5b76-57ae-a6ef-0a8af62496e1" +version = "5.15.3+1" + +[[deps.REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[deps.Random]] +deps = ["SHA", "Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[deps.Ratios]] +deps = ["Requires"] +git-tree-sha1 = "dc84268fe0e3335a62e315a3a7cf2afa7178a734" +uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439" +version = "0.4.3" + +[[deps.RecipesBase]] +deps = ["SnoopPrecompile"] +git-tree-sha1 = "d12e612bba40d189cead6ff857ddb67bd2e6a387" +uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" +version = "1.3.1" + +[[deps.RecipesPipeline]] +deps = ["Dates", "NaNMath", "PlotUtils", "RecipesBase", "SnoopPrecompile"] +git-tree-sha1 = "9b1c0c8e9188950e66fc28f40bfe0f8aac311fe0" +uuid = "01d81517-befc-4cb6-b9ec-a95719d0359c" +version = "0.6.7" + +[[deps.Reexport]] +git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b" +uuid = "189a3867-3050-52da-a836-e630ba90ab69" +version = "1.2.2" + +[[deps.RelocatableFolders]] +deps = ["SHA", "Scratch"] +git-tree-sha1 = "90bc7a7c96410424509e4263e277e43250c05691" +uuid = "05181044-ff0b-4ac5-8273-598c1e38db00" +version = "1.0.0" + +[[deps.Requires]] +deps = ["UUIDs"] +git-tree-sha1 = "838a3a4188e2ded87a4f9f184b4b0d78a1e91cb7" +uuid = "ae029012-a4dd-5104-9daa-d747884805df" +version = "1.3.0" + +[[deps.Roots]] +deps = ["ChainRulesCore", "CommonSolve", "Printf", "Setfield"] +git-tree-sha1 = "a3db467ce768343235032a1ca0830fc64158dadf" +uuid = "f2b01f46-fcfa-551c-844a-d8ac1e96c665" +version = "2.0.8" + +[[deps.SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[deps.Scratch]] +deps = ["Dates"] +git-tree-sha1 = "f94f779c94e58bf9ea243e77a37e16d9de9126bd" +uuid = "6c6a2e73-6563-6170-7368-637461726353" +version = "1.1.1" + +[[deps.Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[deps.Setfield]] +deps = ["ConstructionBase", "Future", "MacroTools", "StaticArraysCore"] +git-tree-sha1 = "e2cc6d8c88613c05e1defb55170bf5ff211fbeac" +uuid = "efcf1570-3423-57d1-acb7-fd33fddbac46" +version = "1.1.1" + +[[deps.SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[deps.Showoff]] +deps = ["Dates", "Grisu"] +git-tree-sha1 = "91eddf657aca81df9ae6ceb20b959ae5653ad1de" +uuid = "992d4aef-0814-514b-bc4d-f2e9a6c4116f" +version = "1.0.3" + +[[deps.SimpleBufferStream]] +git-tree-sha1 = "874e8867b33a00e784c8a7e4b60afe9e037b74e1" +uuid = "777ac1f9-54b0-4bf8-805c-2214025038e7" +version = "1.1.0" + +[[deps.SnoopPrecompile]] +git-tree-sha1 = "f604441450a3c0569830946e5b33b78c928e1a85" +uuid = "66db9d55-30c0-4569-8b51-7e840670fc0c" +version = "1.0.1" + +[[deps.Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[deps.SortingAlgorithms]] +deps = ["DataStructures"] +git-tree-sha1 = "b3363d7460f7d098ca0912c69b082f75625d7508" +uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" +version = "1.0.1" + +[[deps.SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[deps.SpecialFunctions]] +deps = ["ChainRulesCore", "IrrationalConstants", "LogExpFunctions", "OpenLibm_jll", "OpenSpecFun_jll"] +git-tree-sha1 = "d75bda01f8c31ebb72df80a46c88b25d1c79c56d" +uuid = "276daf66-3868-5448-9aa4-cd146d93841b" +version = "2.1.7" + +[[deps.Static]] +deps = ["IfElse"] +git-tree-sha1 = "de4f0a4f049a4c87e4948c04acff37baf1be01a6" +uuid = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" +version = "0.7.7" + +[[deps.StaticArrays]] +deps = ["LinearAlgebra", "Random", "StaticArraysCore", "Statistics"] +git-tree-sha1 = "f86b3a049e5d05227b10e15dbb315c5b90f14988" +uuid = "90137ffa-7385-5640-81b9-e52037218182" +version = "1.5.9" + +[[deps.StaticArraysCore]] +git-tree-sha1 = "6b7ba252635a5eff6a0b0664a41ee140a1c9e72a" +uuid = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" +version = "1.4.0" + +[[deps.Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[deps.StatsAPI]] +deps = ["LinearAlgebra"] +git-tree-sha1 = "f9af7f195fb13589dd2e2d57fdb401717d2eb1f6" +uuid = "82ae8749-77ed-4fe6-ae5f-f523153014b0" +version = "1.5.0" + +[[deps.StatsBase]] +deps = ["DataAPI", "DataStructures", "LinearAlgebra", "LogExpFunctions", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"] +git-tree-sha1 = "d1bf48bfcc554a3761a133fe3a9bb01488e06916" +uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +version = "0.33.21" + +[[deps.TOML]] +deps = ["Dates"] +uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" + +[[deps.Tar]] +deps = ["ArgTools", "SHA"] +uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" + +[[deps.TensorCore]] +deps = ["LinearAlgebra"] +git-tree-sha1 = "1feb45f88d133a655e001435632f019a9a1bcdb6" +uuid = "62fd8b95-f654-4bbd-a8a5-9c27f68ccd50" +version = "0.1.1" + +[[deps.Test]] +deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[deps.TranscodingStreams]] +deps = ["Random", "Test"] +git-tree-sha1 = "8a75929dcd3c38611db2f8d08546decb514fcadf" +uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" +version = "0.9.9" + +[[deps.URIs]] +git-tree-sha1 = "e59ecc5a41b000fa94423a578d29290c7266fc10" +uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4" +version = "1.4.0" + +[[deps.UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[deps.UnPack]] +git-tree-sha1 = "387c1f73762231e86e0c9c5443ce3b4a0a9a0c2b" +uuid = "3a884ed6-31ef-47d7-9d2a-63182c4928ed" +version = "1.0.2" + +[[deps.Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[deps.UnicodeFun]] +deps = ["REPL"] +git-tree-sha1 = "53915e50200959667e78a92a418594b428dffddf" +uuid = "1cfade01-22cf-5700-b092-accc4b62d6e1" +version = "0.4.1" + +[[deps.Unidecode]] +deps = ["REPL", "Test", "Unicode"] +git-tree-sha1 = "2264362f72926965e708ee26f58824b929c72637" +uuid = "967fb449-e509-55aa-8007-234b4096b967" +version = "1.1.0" + +[[deps.Unitful]] +deps = ["ConstructionBase", "Dates", "LinearAlgebra", "Random"] +git-tree-sha1 = "d57a4ed70b6f9ff1da6719f5f2713706d57e0d66" +uuid = "1986cc42-f94f-5a68-af5c-568840ba703d" +version = "1.12.0" + +[[deps.Unzip]] +git-tree-sha1 = "ca0969166a028236229f63514992fc073799bb78" +uuid = "41fe7b60-77ed-43a1-b4f0-825fd5a5650d" +version = "0.2.0" + +[[deps.Wayland_jll]] +deps = ["Artifacts", "Expat_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg", "XML2_jll"] +git-tree-sha1 = "3e61f0b86f90dacb0bc0e73a0c5a83f6a8636e23" +uuid = "a2964d1f-97da-50d4-b82a-358c7fce9d89" +version = "1.19.0+0" + +[[deps.Wayland_protocols_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "4528479aa01ee1b3b4cd0e6faef0e04cf16466da" +uuid = "2381bf8a-dfd0-557d-9999-79630e7b1b91" +version = "1.25.0+0" + +[[deps.WoodburyMatrices]] +deps = ["LinearAlgebra", "SparseArrays"] +git-tree-sha1 = "de67fa59e33ad156a590055375a30b23c40299d3" +uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6" +version = "0.5.5" + +[[deps.XML2_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "Zlib_jll"] +git-tree-sha1 = "58443b63fb7e465a8a7210828c91c08b92132dff" +uuid = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a" +version = "2.9.14+0" + +[[deps.XSLT_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgcrypt_jll", "Libgpg_error_jll", "Libiconv_jll", "Pkg", "XML2_jll", "Zlib_jll"] +git-tree-sha1 = "91844873c4085240b95e795f692c4cec4d805f8a" +uuid = "aed1982a-8fda-507f-9586-7b0439959a61" +version = "1.1.34+0" + +[[deps.Xorg_libX11_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libxcb_jll", "Xorg_xtrans_jll"] +git-tree-sha1 = "5be649d550f3f4b95308bf0183b82e2582876527" +uuid = "4f6342f7-b3d2-589e-9d20-edeb45f2b2bc" +version = "1.6.9+4" + +[[deps.Xorg_libXau_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "4e490d5c960c314f33885790ed410ff3a94ce67e" +uuid = "0c0b7dd1-d40b-584c-a123-a41640f87eec" +version = "1.0.9+4" + +[[deps.Xorg_libXcursor_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXfixes_jll", "Xorg_libXrender_jll"] +git-tree-sha1 = "12e0eb3bc634fa2080c1c37fccf56f7c22989afd" +uuid = "935fb764-8cf2-53bf-bb30-45bb1f8bf724" +version = "1.2.0+4" + +[[deps.Xorg_libXdmcp_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "4fe47bd2247248125c428978740e18a681372dd4" +uuid = "a3789734-cfe1-5b06-b2d0-1dd0d9d62d05" +version = "1.1.3+4" + +[[deps.Xorg_libXext_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"] +git-tree-sha1 = "b7c0aa8c376b31e4852b360222848637f481f8c3" +uuid = "1082639a-0dae-5f34-9b06-72781eeb8cb3" +version = "1.3.4+4" + +[[deps.Xorg_libXfixes_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"] +git-tree-sha1 = "0e0dc7431e7a0587559f9294aeec269471c991a4" +uuid = "d091e8ba-531a-589c-9de9-94069b037ed8" +version = "5.0.3+4" + +[[deps.Xorg_libXi_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXext_jll", "Xorg_libXfixes_jll"] +git-tree-sha1 = "89b52bc2160aadc84d707093930ef0bffa641246" +uuid = "a51aa0fd-4e3c-5386-b890-e753decda492" +version = "1.7.10+4" + +[[deps.Xorg_libXinerama_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXext_jll"] +git-tree-sha1 = "26be8b1c342929259317d8b9f7b53bf2bb73b123" +uuid = "d1454406-59df-5ea1-beac-c340f2130bc3" +version = "1.1.4+4" + +[[deps.Xorg_libXrandr_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll"] +git-tree-sha1 = "34cea83cb726fb58f325887bf0612c6b3fb17631" +uuid = "ec84b674-ba8e-5d96-8ba1-2a689ba10484" +version = "1.5.2+4" + +[[deps.Xorg_libXrender_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"] +git-tree-sha1 = "19560f30fd49f4d4efbe7002a1037f8c43d43b96" +uuid = "ea2f1a96-1ddc-540d-b46f-429655e07cfa" +version = "0.9.10+4" + +[[deps.Xorg_libpthread_stubs_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "6783737e45d3c59a4a4c4091f5f88cdcf0908cbb" +uuid = "14d82f49-176c-5ed1-bb49-ad3f5cbd8c74" +version = "0.1.0+3" + +[[deps.Xorg_libxcb_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "XSLT_jll", "Xorg_libXau_jll", "Xorg_libXdmcp_jll", "Xorg_libpthread_stubs_jll"] +git-tree-sha1 = "daf17f441228e7a3833846cd048892861cff16d6" +uuid = "c7cfdc94-dc32-55de-ac96-5a1b8d977c5b" +version = "1.13.0+3" + +[[deps.Xorg_libxkbfile_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"] +git-tree-sha1 = "926af861744212db0eb001d9e40b5d16292080b2" +uuid = "cc61e674-0454-545c-8b26-ed2c68acab7a" +version = "1.1.0+4" + +[[deps.Xorg_xcb_util_image_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_xcb_util_jll"] +git-tree-sha1 = "0fab0a40349ba1cba2c1da699243396ff8e94b97" +uuid = "12413925-8142-5f55-bb0e-6d7ca50bb09b" +version = "0.4.0+1" + +[[deps.Xorg_xcb_util_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libxcb_jll"] +git-tree-sha1 = "e7fd7b2881fa2eaa72717420894d3938177862d1" +uuid = "2def613f-5ad1-5310-b15b-b15d46f528f5" +version = "0.4.0+1" + +[[deps.Xorg_xcb_util_keysyms_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_xcb_util_jll"] +git-tree-sha1 = "d1151e2c45a544f32441a567d1690e701ec89b00" +uuid = "975044d2-76e6-5fbe-bf08-97ce7c6574c7" +version = "0.4.0+1" + +[[deps.Xorg_xcb_util_renderutil_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_xcb_util_jll"] +git-tree-sha1 = "dfd7a8f38d4613b6a575253b3174dd991ca6183e" +uuid = "0d47668e-0667-5a69-a72c-f761630bfb7e" +version = "0.3.9+1" + +[[deps.Xorg_xcb_util_wm_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_xcb_util_jll"] +git-tree-sha1 = "e78d10aab01a4a154142c5006ed44fd9e8e31b67" +uuid = "c22f9ab0-d5fe-5066-847c-f4bb1cd4e361" +version = "0.4.1+1" + +[[deps.Xorg_xkbcomp_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libxkbfile_jll"] +git-tree-sha1 = "4bcbf660f6c2e714f87e960a171b119d06ee163b" +uuid = "35661453-b289-5fab-8a00-3d9160c6a3a4" +version = "1.4.2+4" + +[[deps.Xorg_xkeyboard_config_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_xkbcomp_jll"] +git-tree-sha1 = "5c8424f8a67c3f2209646d4425f3d415fee5931d" +uuid = "33bec58e-1273-512f-9401-5d533626f822" +version = "2.27.0+4" + +[[deps.Xorg_xtrans_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "79c31e7844f6ecf779705fbc12146eb190b7d845" +uuid = "c5fb5394-a638-5e4d-96e5-b29de1b5cf10" +version = "1.4.0+3" + +[[deps.Zlib_jll]] +deps = ["Libdl"] +uuid = "83775a58-1f1d-513f-b197-d71354ab007a" + +[[deps.Zstd_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "e45044cd873ded54b6a5bac0eb5c971392cf1927" +uuid = "3161d3a3-bdf6-5164-811a-617609db77b4" +version = "1.5.2+0" + +[[deps.fzf_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "868e669ccb12ba16eaf50cb2957ee2ff61261c56" +uuid = "214eeab7-80f7-51ab-84ad-2988db7cef09" +version = "0.29.0+0" + +[[deps.libaom_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "3a2ea60308f0996d26f1e5354e10c24e9ef905d4" +uuid = "a4ae2306-e953-59d6-aa16-d00cac43593b" +version = "3.4.0+0" + +[[deps.libass_jll]] +deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "HarfBuzz_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"] +git-tree-sha1 = "5982a94fcba20f02f42ace44b9894ee2b140fe47" +uuid = "0ac62f75-1d6f-5e53-bd7c-93b484bb37c0" +version = "0.15.1+0" + +[[deps.libblastrampoline_jll]] +deps = ["Artifacts", "Libdl", "OpenBLAS_jll"] +uuid = "8e850b90-86db-534c-a0d3-1478176c7d93" + +[[deps.libfdk_aac_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "daacc84a041563f965be61859a36e17c4e4fcd55" +uuid = "f638f0a6-7fb0-5443-88ba-1cc74229b280" +version = "2.0.2+0" + +[[deps.libpng_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"] +git-tree-sha1 = "94d180a6d2b5e55e447e2d27a29ed04fe79eb30c" +uuid = "b53b4c65-9356-5827-b1ea-8c7a1a84506f" +version = "1.6.38+0" + +[[deps.libvorbis_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Ogg_jll", "Pkg"] +git-tree-sha1 = "b910cb81ef3fe6e78bf6acee440bda86fd6ae00c" +uuid = "f27f6e37-5d2b-51aa-960f-b287f2bc3b7a" +version = "1.3.7+1" + +[[deps.nghttp2_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" + +[[deps.p7zip_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" + +[[deps.x264_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "4fea590b89e6ec504593146bf8b988b2c00922b2" +uuid = "1270edf5-f2f9-52d2-97e9-ab00b5d0237a" +version = "2021.5.5+0" + +[[deps.x265_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "ee567a171cce03570d77ad3a43e90218e38937a9" +uuid = "dfaa095f-4041-5dcd-9319-2fabd8486b76" +version = "3.5.0+0" + +[[deps.xkbcommon_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Wayland_jll", "Wayland_protocols_jll", "Xorg_libxcb_jll", "Xorg_xkeyboard_config_jll"] +git-tree-sha1 = "9ebfc140cc56e8c2156a15ceac2f0302e327ac0a" +uuid = "d8fb68d0-12a3-5cfd-a85a-d49703b185fd" +version = "1.4.1+0" From b34f495a3e5198271400ac8221b4c89f4c6edb7e Mon Sep 17 00:00:00 2001 From: Boris Kaus Date: Wed, 26 Oct 2022 19:45:56 -0300 Subject: [PATCH 18/49] the previous comparison between GeoParams & the native implementation was not entirely fair, as the GeoParams version was updating both vertices and centers whereas the native version only updated centers. This code makes them more similar (and timings are more similar as well). Yet there appears to be a bug in the "native" VEP version as it explodes even in the purely viscoelastic case. I don't see where I go wrong, so save the current effort --- .../Stokes2D_VEP_inclusion_GeoParams_v2.jl | 177 ++++++++++++++---- 1 file changed, 141 insertions(+), 36 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v2.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v2.jl index 9b92a93..7d158c8 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v2.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v2.jl @@ -5,6 +5,12 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) @views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) @views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) @views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) + +@views function cen2ver!(Av, Ac) # extrapolate center -> vertex + Av[2:end-1,2:end-1] .= av(Ac); Av[1,:].=Av[2,:]; Av[end,:].=Av[end-1,:]; Av[:,1].=Av[:,2]; Av[:,end].=Av[:,end-1] + return nothing +end + @generated function phase_viscosity(v::NTuple{N,Any}, ε̇ii, phase, args) where N quote Base.@_inline_meta @@ -12,63 +18,118 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) end end # Rheology -@views function UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, Pt, MatParam, Δt, Phasec, Phasev ) +@views function UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, τxy_c, ε̇xx, ε̇yy, ε̇xy, ε̇xy_c, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, Pt, MatParam, Δt, Phasec, Phasev ) # ε̇iic .= sqrt.(1//2 .*(ε̇xx.^2 .+ ε̇yy.^2) .+ av(ε̇xy).^2) # ε̇iiv[2:end-1,2:end-1] .= sqrt.(1//2 .*( av(ε̇xx).^2 .+ av(ε̇yy).^2) .+ ε̇xy[2:end-1,2:end-1].^2) # τii0c .= sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) # τii0v[2:end-1,2:end-1] .= sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) + ε̇xy_c .= av(ε̇xy) + # Centroids for j ∈ axes(ε̇xx,2), i ∈ axes(ε̇xx,1) - # v = MatParam[Phasec[i]].CompositeRheology[1] # indexation of MatParam with Phasec[i] causes allocation - τxy0c_2 = .25*(τxy0[i,j]^2 + τxy0[i+1,j]^2 + τxy0[i,j+1]^2 + τxy0[i+1,j+1]^2) # you need to average squares! - ε̇xyc_2 = .25*( ε̇xy[i,j]^2 + ε̇xy[i+1,j]^2 + ε̇xy[i,j+1]^2 + ε̇xy[i+1,j+1]^2) - τii0 = sqrt.(0.5 *(τxx0[i,j]^2 + τyy0[i,j]^2) + τxy0c_2) - ε̇ii = sqrt.(0.5 *( ε̇xx[i,j]^2 + ε̇yy[i,j]^2) + ε̇xyc_2) + # compute second invariants from surrounding points + τii0 = second_invariant_staggered( (τxx0[i,j],τyy0[i,j]), (τxy0[i,j], τxy0[i+1,j], τxy0[i,j+1], τxy0[i+1,j+1])) + ε̇ii = second_invariant_staggered( (ε̇xx[i,j], ε̇yy[i,j] ), (ε̇xy[i,j], ε̇xy[i+1,j], ε̇xy[i,j+1], ε̇xy[i+1,j+1])) args = (; τII_old = τii0, dt=Δt, P=Pt[i,j]) ηc[i,j] = phase_viscosity(MatParam, ε̇ii, Phasec[i,j], args) - τxx[i,j] = 2*ηc[i,j]*ε̇xx[i,j] - τyy[i,j] = 2*ηc[i,j]*ε̇yy[i,j] + τxx[i,j] = 2*ηc[i,j]*ε̇xx[i,j] + τyy[i,j] = 2*ηc[i,j]*ε̇yy[i,j] + + τxy_c[i,j] = 2*ηc[i,j]*ε̇xy_c[i,j] end + cen2ver!(ηv, ηc) # extrapolate from centers -> vertices + # Vertices for j ∈ 2:size(ε̇xy,2)-1, i ∈ 2:size(ε̇xy,1)-1 - τxx0c_2 = .25*(τxx0[i,j]^2 + τxx0[i-1,j]^2 + τxx0[i,j-1]^2 + τxx0[i-1,j-1]^2) - τyy0c_2 = .25*(τyy0[i,j]^2 + τyy0[i-1,j]^2 + τyy0[i,j-1]^2 + τyy0[i-1,j-1]^2) - ε̇xxc_2 = .25*( ε̇xx[i,j]^2 + ε̇xx[i-1,j]^2 + ε̇xx[i,j-1]^2 + ε̇xx[i-1,j-1]^2) - ε̇yyc_2 = .25*( ε̇yy[i,j]^2 + ε̇yy[i-1,j]^2 + ε̇yy[i,j-1]^2 + ε̇yy[i-1,j-1]^2) - Pc = .25*( Pt[i,j] + Pt[i-1,j] + Pt[i,j-1] + Pt[i-1,j-1]) - - τii0 = sqrt.(0.5 *(τxx0c_2 + τyy0c_2) + τxy0[i,j]^2) - ε̇ii = sqrt.(0.5 *( ε̇xxc_2 + ε̇yyc_2) + ε̇xy[i,j]^2) - args = (; τII_old = τii0, dt=Δt, P=Pc) - ηv[i,j] = phase_viscosity(MatParam, ε̇ii, Phasev[i,j], args) τxy[i,j] = 2*ηv[i,j]*ε̇xy[i,j] end + + return nothing end +@views function UpdateStressNative_VE!(ηe_c, ηe_v, ηve_c, ηve_v, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0) + + # purely viscoelastic correction + τxx .= 2 .* ηve_c .* ( ε̇xx .+ τxx0./(2 .* ηe_c) ) + τyy .= 2 .* ηve_c .* ( ε̇yy .+ τyy0./(2 .* ηe_c) ) + τxy .= 2 .* ηve_v .* ( ε̇xy .+ τxy0./(2 .* ηe_v) ) + + return nothing +end + + +@views function UpdateStressNative_VEP!(ηe_c, ηe_v, ηve_c, ηve_v, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, + ε̇xx1, ε̇yy1, ε̇xy1, ε̇xy1_c, τxy0_c, ε̇ii, τxy_c, τii, F, τ_y, Pt, sinϕ, η_reg, Pla, λ, dQdTxx, dQdTyy, dQdTxy, Fchk, ηvep_c, ηvep_v) + + # visco-elastic strain rates + ε̇xx1 .= ε̇xx .+ τxx0 ./2.0./ηe_c + ε̇yy1 .= ε̇yy .+ τyy0 ./2.0./ηe_c + ε̇xy1 .= ε̇xy .+ τxy0 ./2.0./ηe_v + ε̇xy1_c .= av(ε̇xy) .+ τxy0_c./2.0./ηe_c + ε̇ii .= sqrt.(0.5*(ε̇xx1.^2 .+ ε̇yy1.^2) .+ ε̇xy1_c.^2) + + # trial stress + τxx .= 2.0.*ηve_c.*ε̇xx1 + τyy .= 2.0.*ηve_c.*ε̇yy1 + τxy_c .= 2.0.*ηve_c.*ε̇xy1_c + τii .= sqrt.(0.5*(τxx.^2 .+ τyy.^2) .+ τxy_c.^2) + + # yield function + F .= τii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(ηve_c .+ η_reg) + dQdTxx .= 0.5.*τxx./τii + dQdTyy .= 0.5.*τyy./τii + dQdTxy .= τxy_c./τii + + # plastic corrections + τxx .= 2.0.*ηve_c.*(ε̇xx1 .- λ.*dQdTxx) + τyy .= 2.0.*ηve_c.*(ε̇yy1 .- λ.*dQdTyy) + τxy_c .= 2.0.*ηve_c.*(ε̇xy1_c .- 0.5.*λ.*dQdTxy) + τii .= sqrt.(0.5*(τxx.^2 .+ τyy.^2) .+ τxy_c.^2) + Fchk .= τii .- τ_y .- Pt.*sinϕ .- λ.*η_reg + + ηvep_c .= τii./2.0./ε̇ii + cen2ver!(ηvep_v, ηvep_c) + + τxy .= 2.0.*ηvep_v.*ε̇xy1 + + # purely viscoelastic correction + # τxx .= 2 .* ηve_c .* ( ε̇xx .+ τxx0./(2 .* ηe_c) ) + # τyy .= 2 .* ηve_c .* ( ε̇yy .+ τyy0./(2 .* ηe_c) ) + # τxy .= 2 .* ηve_v .* ( ε̇xy1 ) + + + return nothing +end + + # 2D Stokes routine @views function Stokes2D_VE_inclusion(UseGeoParams, doPlot = false) # Physics - do_DP = true + do_DP = false Lx, Ly = 1.0, 1.0 # domain size ξ = 10.0 # Maxwell relaxation time η0 = 1.0 # viscous viscosity G0 = 1.0 # elastic shear modulus εbg = 1.0 # background strain-rate radi = 0.01 - τ_y = 1.6 + τ_y = 1.6 Gi = G0/(6.0-4.0*do_DP) # inclusion shear modulus η_reg = 1.2e-2 # regularisation "viscosity" - ϕ = 30*do_DP - Coh = 1.6/cosd(ϕ) # cohesion + ϕ = 30*do_DP + sinϕ = sind(ϕ)*do_DP + Coh = τ_y/cosd(ϕ) # cohesion - #pl = DruckerPrager(C=Coh, ϕ=30) # non-regularized plasticity + #pl = DruckerPrager(C=Coh, ϕ=ϕ) # non-regularized plasticity #pl = Parallel(DruckerPrager(C=Coh, ϕ=ϕ), LinearViscous(η=η_reg)) - pl = DruckerPrager_regularised(C=Coh, ϕ=30, η_vp=η_reg) # non-regularized plasticity + pl = DruckerPrager_regularised(C=Coh, ϕ=ϕ, η_vp=η_reg) # non-regularized plasticity MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, - CompositeRheology = CompositeRheology(ConstantElasticity(G=G0),LinearViscous(η=η0), pl)), + CompositeRheology = CompositeRheology(ConstantElasticity(G=G0),LinearViscous(η=η0),pl)), SetMaterialParams(Name="Inclusion", Phase=2, - CompositeRheology = CompositeRheology(ConstantElasticity(G=Gi),LinearViscous(η=η0), pl)), + CompositeRheology = CompositeRheology(ConstantElasticity(G=Gi),LinearViscous(η=η0),pl)), ) # Numerics @@ -92,12 +153,22 @@ end ε̇xx = zeros(Dat, ncx ,ncy ) ε̇yy = zeros(Dat, ncx ,ncy ) ε̇xy = zeros(Dat, ncx+1,ncy+1) + + ε̇xx1 = zeros(Dat, ncx ,ncy ) + ε̇yy1 = zeros(Dat, ncx ,ncy ) + ε̇xy1 = zeros(Dat, ncx+1,ncy+1) + ε̇xy1_c = zeros(Dat, ncx ,ncy ) + τxx = zeros(Dat, ncx ,ncy ) τyy = zeros(Dat, ncx ,ncy ) τxy = zeros(Dat, ncx+1,ncy+1) + τxy_c = zeros(Dat, ncx ,ncy ) + τxx0 = zeros(Dat, ncx ,ncy ) τyy0 = zeros(Dat, ncx ,ncy ) τxy0 = zeros(Dat, ncx+1,ncy+1) + τxy0_c = zeros(Dat, ncx ,ncy ) + Rx = zeros(Dat, ncx+1,ncy ) Ry = zeros(Dat, ncx ,ncy+1) Rp = zeros(Dat, ncx ,ncy ) @@ -113,17 +184,39 @@ end ηv = η0*ones(Dat, ncx+1, ncy+1) Phasec = ones(Int, ncx ,ncy ) Phasev = ones(Int, ncx+1,ncy+1) + + # For native plastic version + F = zeros(Dat, ncx ,ncy ) + Fchk = zeros(Dat, ncx ,ncy ) + τxy2_c = zeros(Dat, ncx ,ncy ) + τxy_c = zeros(Dat, ncx ,ncy ) + ε̇xy2_c = zeros(Dat, ncx ,ncy ) + ε̇xy_c = zeros(Dat, ncx ,ncy ) + τii = zeros(size(ε̇xx)) + ε̇ii = zeros(size(ε̇xx)) + λ = zeros(size(ε̇xx)) + Pla = zeros(size(ε̇xx)) + dQdTxx = zeros(size(ε̇xx)) + dQdTyy = zeros(size(ε̇xx)) + dQdTxy = zeros(size(ε̇xx)) + ηvep_v = ones(Dat, ncx+1, ncy+1) + ηvep_c = ones(Dat, ncx , ncy ) + # For geoparams τii0c = zeros(size(ε̇xx)) τii0v = zeros(size(ε̇xy)) ε̇iic = zeros(size(ε̇xx)) ε̇iiv = zeros(size(ε̇xy)) + # For non-geoparams version η, G = 1.0, 1.0 ηe_c = Δt*G.*ones(Dat, ncx ,ncy ) ηe_v = Δt*G.*ones(Dat, ncx+1,ncy+1) ηve_c = zeros(Dat, ncx ,ncy ) ηve_v = zeros(Dat, ncx+1,ncy+1) + η_vep = ones(Dat, ncx ,ncy ) + η_vep_v = ones(Dat, ncx+1,ncy+1) + # Initialisation xce, yce = LinRange(-Δx/2, Lx+Δx/2, ncx+2), LinRange(-Δy/2, Ly+Δy/2, ncy+2) xc, yc = LinRange(Δx/2, Lx-Δx/2, ncx), LinRange(Δy/2, Ly-Δy/2, ncy) @@ -167,11 +260,14 @@ end ε̇xy .= 0.5.*(diff(Vx, dims=2)./Δy .+ diff(Vy, dims=1)./Δx) # Stresses if UseGeoParams - UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, Pt, MatParam, Δt, Phasec, Phasev ) + #UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, τxy_c, ε̇xx, ε̇yy, ε̇xy, ε̇xy_c, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, Pt, MatParam, Δt, Phasec, Phasev ) + UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, τxy_c, ε̇xx, ε̇yy, ε̇xy, ε̇xy_c, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, Pt, MatParam, Δt, Phasec, Phasev ) + else - τxx .= 2 .* ηve_c .* ( ε̇xx .+ τxx0./(2 .* ηe_c) ) - τyy .= 2 .* ηve_c .* ( ε̇yy .+ τyy0./(2 .* ηe_c) ) - τxy .= 2 .* ηve_v .* ( ε̇xy .+ τxy0./(2 .* ηe_v) ) + #UpdateStressNative_VE!(ηe_c, ηe_v, ηve_c, ηve_v, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0) + UpdateStressNative_VEP!(ηe_c, ηe_v, ηve_c, ηve_v, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, + ε̇xx1, ε̇yy1, ε̇xy1, ε̇xy1_c, τxy0_c, ε̇ii, τxy_c, τii, F, τ_y, Pt, sinϕ, η_reg, Pla, λ, dQdTxx, dQdTyy, dQdTxy, Fchk, ηvep_c, ηvep_v) + end # Residuals Rx[2:end-1,:] .= .-diff(Pt, dims=1)./Δx .+ diff(τxx, dims=1)./Δx .+ diff(τxy[2:end-1,:], dims=2)./Δy @@ -195,7 +291,7 @@ end norm_Rx = norm(Rx)/sqrt(length(Rx)); norm_Ry = norm(Ry)/sqrt(length(Ry)); norm_∇V = norm(∇V)/sqrt(length(∇V)) err = maximum([norm_Rx, norm_Ry, norm_∇V]) push!(err_evo1, err); push!(err_evo2, itg) - @printf("it = %03d, iter = %04d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V) + @printf("it = %03d, iter = %04d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] Fchk = %1.3e \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V, maximum(Fchk)) end iter+=1; global itg=iter end @@ -204,11 +300,20 @@ end if doPlot # Plotting - p1 = heatmap(xv, yc, Vx[:,2:end-1]', aspect_ratio=1, xlims=(0, Lx), ylims=(Δy/2, Ly-Δy/2), c=:inferno, title="Vx") - p2 = heatmap(xc, yv, Vy[2:end-1,:]', aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="Vy") + #p1 = heatmap(xv, yc, Vx[:,2:end-1]', aspect_ratio=1, xlims=(0, Lx), ylims=(Δy/2, Ly-Δy/2), c=:inferno, title="Vx") + p1 = heatmap(xv, yv, τxy', aspect_ratio=1, xlims=(0, Lx), ylims=(Δy/2, Ly-Δy/2), c=:inferno, title="τxy") + + #p2 = heatmap(xc, yv, Vy[2:end-1,:]', aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="Vy") + # p2 = heatmap(xv, yv, η_vep_v', aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="Vy") + #p2 = heatmap(xv, yv, ηv' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="η_vep") + p2 = heatmap(xv, yv, ηv' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="η_vep") + + + + p3 = heatmap(xc, yc, Pt' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="P") #p3 = heatmap(xv, yv, τxy' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="τxy") - p4 = plot(evo_t, evo_τxx , xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, markersize=3) + p4 = plot(evo_t, evo_τxx , xlabel="time", ylabel="max(τxx)", legend=false, linewidth=0, markershape=:circle, markersize=3) p4 = plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewidth=2.0) # analytical solution display(plot(p1, p2, p3, p4)) end @@ -218,6 +323,6 @@ end for i=1:1 println("step $i") - #@time Stokes2D_VE_inclusion(false, false) - @time Stokes2D_VE_inclusion(true, true) + @time Stokes2D_VE_inclusion(false, true) + #@time Stokes2D_VE_inclusion(true, true) end \ No newline at end of file From d0dbd0c016c026fab7af149bcc58b0c03ba0bccb Mon Sep 17 00:00:00 2001 From: Boris Kaus Date: Wed, 26 Oct 2022 23:13:09 -0300 Subject: [PATCH 19/49] added a version that computes plasticity using invariants; times between the GeoParams and native implementation are much closer now & results the same --- .../Stokes2D_VEP_inclusion_GeoParams_v3.jl | 390 ++++++++++++++++++ 1 file changed, 390 insertions(+) create mode 100644 GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl new file mode 100644 index 0000000..968aea4 --- /dev/null +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl @@ -0,0 +1,390 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra, GeoParams +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) + + +@views function average_c!(Ac::AbstractArray{N,T}, Av::AbstractArray{N,T}) where {N,T} # extrapolate vertex -> center + + for I in CartesianIndices(Ac) + i,j = I[1], I[2]; + Ac[I] = 0.25*(Av[i,j] + Av[i+1,j] + Av[i,j+1] + Av[i+1,j+1]) + end + + return nothing +end + + +@views function cen2ver!(Av::Array{N,T}, Ac::Array{N,T}) where {N,T} # extrapolate center -> vertex + average_c!( Av[2:end-1,2:end-1], Ac) + Av[1,:].=Av[2,:]; + Av[end,:].=Av[end-1,:]; + Av[:,1].=Av[:,2]; + Av[:,end].=Av[:,end-1] + return nothing +end + +@generated function phase_viscosity(v::NTuple{N,Any}, ε̇ii, phase, args) where N + quote + Base.@_inline_meta + Base.@nexprs $N i -> v[i].Phase === phase && return computeViscosity_εII(v[i].CompositeRheology[1], ε̇ii, args) + end +end +# Rheology +@views function UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, τxy_c, ε̇xx, ε̇yy, ε̇xy, ε̇xy_c, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, Pt, MatParam, Δt, Phasec, Phasev ) + # ε̇iic .= sqrt.(1//2 .*(ε̇xx.^2 .+ ε̇yy.^2) .+ av(ε̇xy).^2) + # ε̇iiv[2:end-1,2:end-1] .= sqrt.(1//2 .*( av(ε̇xx).^2 .+ av(ε̇yy).^2) .+ ε̇xy[2:end-1,2:end-1].^2) + # τii0c .= sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) + # τii0v[2:end-1,2:end-1] .= sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) + + average_c!(ε̇xy_c, ε̇xy) # average vertices -> centers + + # Centroids + for j ∈ axes(ε̇xx,2), i ∈ axes(ε̇xx,1) + # compute second invariants from surrounding points + τii0 = second_invariant_staggered( (τxx0[i,j],τyy0[i,j]), (τxy0[i,j], τxy0[i+1,j], τxy0[i,j+1], τxy0[i+1,j+1])) + ε̇ii = second_invariant_staggered( (ε̇xx[i,j], ε̇yy[i,j] ), (ε̇xy[i,j], ε̇xy[i+1,j], ε̇xy[i,j+1], ε̇xy[i+1,j+1])) + args = (; τII_old = τii0, dt=Δt, P=Pt[i,j]) + ηc[i,j] = phase_viscosity(MatParam, ε̇ii, Phasec[i,j], args) + τxx[i,j] = 2*ηc[i,j]*ε̇xx[i,j] + τyy[i,j] = 2*ηc[i,j]*ε̇yy[i,j] + + τxy_c[i,j] = 2*ηc[i,j]*ε̇xy_c[i,j] + end + cen2ver!(ηv, ηc) # extrapolate from centers -> vertices + + # Vertices + for j ∈ 2:size(ε̇xy,2)-1, i ∈ 2:size(ε̇xy,1)-1 + τxy[i,j] = 2*ηv[i,j]*ε̇xy[i,j] + end + + return nothing +end + +@views function UpdateStressNative_VE!(ηe_c, ηe_v, ηve_c, ηve_v, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0) + + # purely viscoelastic correction + τxx .= 2 .* ηve_c .* ( ε̇xx .+ τxx0./(2 .* ηe_c) ) + τyy .= 2 .* ηve_c .* ( ε̇yy .+ τyy0./(2 .* ηe_c) ) + τxy .= 2 .* ηve_v .* ( ε̇xy .+ τxy0./(2 .* ηe_v) ) + + return nothing +end + +@views function UpdateStressNative_VEP_invariants!(ηe_c, ηe_v, ηve_c, ηve_v, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, + ε̇ii, τii, τii0, ε̇xy_c, τxy_c,ε̇xy2_c, τxy2_c, F, τ_y, Pt, sinϕ, η_reg, Pla, λ, ε̇ii_pl, Fchk, ηc, ηv) + + # visco-elastic strain rates + average_c!(τxy2_c, τxy0.^2) + average_c!(ε̇xy2_c, ε̇xy.^2) + + τii0 .= sqrt.( 0.5.*(τxx0.^2 .+ τyy0.^2) .+ τxy2_c) # watch out - name is misleading + ε̇ii .= sqrt.( 0.5.*(ε̇xx.^2 .+ ε̇yy.^2) .+ ε̇xy2_c) # strain rate invariant @ center + τii .= 2.0.*ηve_c.*(ε̇ii .+ τii0./(2.0.*ηe_c) ) # trial stress + + #ε̇xy_c .= av(ε̇xy) + average_c!(ε̇xy_c, ε̇xy) + + # Compute plasticity @ center + F .= τii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(ηve_c .+ η_reg) + ε̇ii_pl .= λ*0.5 # 2nd invariant of plastic strainrate (check!) + τii .= 2.0.*ηve_c.*(ε̇ii .+ τii0./(2.0*ηe_c) .- ε̇ii_pl) # updated stress @ center + Fchk .= τii .- τ_y .- Pt.*sinϕ .- λ.*η_reg + + # Update stress components + ηc .= τii./(2.0*ε̇ii) + τxx .= 2.0.*ηc.*ε̇xx + τyy .= 2.0.*ηc.*ε̇yy + τxy_c .= 2.0.*ηc.*ε̇xy_c + + cen2ver!(ηv, ηc) # extrapolate from centers -> vertices + + τxy .= 2.0.*ηv.*ε̇xy # update stress @ vertexes + + + return nothing +end + + +@views function UpdateStressNative_VEP!(ηe_c, ηe_v, ηve_c, ηve_v, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, + ε̇xx1, ε̇yy1, ε̇xy1, ε̇xy1_c, τxy0_c, ε̇ii, τxy_c, τii, F, τ_y, Pt, sinϕ, η_reg, Pla, λ, dQdTxx, dQdTyy, dQdTxy, Fchk, ηvep_c, ηvep_v) + + # visco-elastic strain rates + ε̇xx1 .= ε̇xx .+ τxx0 ./2.0./ηe_c + ε̇yy1 .= ε̇yy .+ τyy0 ./2.0./ηe_c + ε̇xy1 .= ε̇xy .+ τxy0 ./2.0./ηe_v + ε̇xy1_c .= av(ε̇xy) .+ τxy0_c./2.0./ηe_c + ε̇ii .= sqrt.(0.5*(ε̇xx1.^2 .+ ε̇yy1.^2) .+ ε̇xy1_c.^2) + + # trial stress + τxx .= 2.0.*ηve_c.*ε̇xx1 + τyy .= 2.0.*ηve_c.*ε̇yy1 + τxy_c .= 2.0.*ηve_c.*ε̇xy1_c + τii .= sqrt.(0.5*(τxx.^2 .+ τyy.^2) .+ τxy_c.^2) + + # yield function + F .= τii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(ηve_c .+ η_reg) + dQdTxx .= 0.5.*τxx./τii + dQdTyy .= 0.5.*τyy./τii + dQdTxy .= τxy_c./τii + + # plastic corrections + τxx .= 2.0.*ηve_c.*(ε̇xx1 .- λ.*dQdTxx) + τyy .= 2.0.*ηve_c.*(ε̇yy1 .- λ.*dQdTyy) + τxy_c .= 2.0.*ηve_c.*(ε̇xy1_c .- 0.5.*λ.*dQdTxy) + τii .= sqrt.(0.5*(τxx.^2 .+ τyy.^2) .+ τxy_c.^2) + Fchk .= τii .- τ_y .- Pt.*sinϕ .- λ.*η_reg + + ηvep_c .= τii./2.0./ε̇ii + cen2ver!(ηvep_v, ηvep_c) + + τxy .= 2.0.*ηvep_v.*ε̇xy1 + + # purely viscoelastic correction + # τxx .= 2 .* ηve_c .* ( ε̇xx .+ τxx0./(2 .* ηe_c) ) + # τyy .= 2 .* ηve_c .* ( ε̇yy .+ τyy0./(2 .* ηe_c) ) + # τxy .= 2 .* ηve_v .* ( ε̇xy1 ) + + + return nothing +end + + +# 2D Stokes routine +@views function Stokes2D_VE_inclusion(UseGeoParams, doPlot = false) + # Physics + do_DP = false + Lx, Ly = 1.0, 1.0 # domain size + ξ = 10.0 # Maxwell relaxation time + η0 = 1.0 # viscous viscosity + G0 = 1.0 # elastic shear modulus + εbg = 1.0 # background strain-rate + radi = 0.01 + τ_y = 1.6 + Gi = G0/(6.0-4.0*do_DP) # inclusion shear modulus + η_reg = 1.2e-2 # regularisation "viscosity" + ϕ = 30*do_DP + sinϕ = sind(ϕ)*do_DP + Coh = τ_y/cosd(ϕ) # cohesion + + #pl = DruckerPrager(C=Coh, ϕ=ϕ) # non-regularized plasticity + #pl = Parallel(DruckerPrager(C=Coh, ϕ=ϕ), LinearViscous(η=η_reg)) + pl = DruckerPrager_regularised(C=Coh, ϕ=ϕ, η_vp=η_reg) # non-regularized plasticity + + MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G0),LinearViscous(η=η0),pl)), + SetMaterialParams(Name="Inclusion", Phase=2, + CompositeRheology = CompositeRheology(ConstantElasticity(G=Gi),LinearViscous(η=η0),pl)), + ) + + # Numerics + nt = 20 # number of time steps + ncx, ncy = 31, 31 # numerical grid resolution + #ncx, ncy = 63, 63 # numerical grid resolution + + ε = 1e-6 # nonlinear tolerence + iterMax = 1e4 # max number of iters + nout = 500 # check frequency + # Iterative parameters ------------------------------------------- + Reopt = 5π + cfl = 0.50 + ρ = cfl*Reopt/ncx + # Preprocessing + Δx, Δy = Lx/ncx, Ly/ncy + Δt = η0/(G0*ξ + 1e-15) + # Array initialisation + Pt = zeros(Dat, ncx ,ncy ) + ∇V = zeros(Dat, ncx ,ncy ) + Vx = zeros(Dat, ncx+1,ncy+2) + Vy = zeros(Dat, ncx+2,ncy+1) + ε̇xx = zeros(Dat, ncx ,ncy ) + ε̇yy = zeros(Dat, ncx ,ncy ) + ε̇xy = zeros(Dat, ncx+1,ncy+1) + + ε̇xx1 = zeros(Dat, ncx ,ncy ) + ε̇yy1 = zeros(Dat, ncx ,ncy ) + ε̇xy1 = zeros(Dat, ncx+1,ncy+1) + ε̇xy1_c = zeros(Dat, ncx ,ncy ) + + τxx = zeros(Dat, ncx ,ncy ) + τyy = zeros(Dat, ncx ,ncy ) + τxy = zeros(Dat, ncx+1,ncy+1) + τxy_c = zeros(Dat, ncx ,ncy ) + τxy2_c = zeros(Dat, ncx ,ncy ) + + τxx0 = zeros(Dat, ncx ,ncy ) + τyy0 = zeros(Dat, ncx ,ncy ) + τxy0 = zeros(Dat, ncx+1,ncy+1) + τxy0_c = zeros(Dat, ncx ,ncy ) + + Rx = zeros(Dat, ncx+1,ncy ) + Ry = zeros(Dat, ncx ,ncy+1) + Rp = zeros(Dat, ncx ,ncy ) + dVxdτ = zeros(Dat, ncx+1,ncy ) + dVydτ = zeros(Dat, ncx ,ncy+1) + dPdτ = zeros(Dat, ncx ,ncy ) + Δτv = zeros(Dat, ncx+1,ncy+1) + Δτvx = zeros(Dat, ncx+1,ncy ) + Δτvy = zeros(Dat, ncx ,ncy+1) + κΔτp = zeros(Dat, ncx ,ncy ) + Rog = zeros(Dat, ncx ,ncy ) + ηc = η0*ones(Dat, ncx, ncy) + ηv = η0*ones(Dat, ncx+1, ncy+1) + Phasec = ones(Int, ncx ,ncy ) + Phasev = ones(Int, ncx+1,ncy+1) + + # For native plastic version + F = zeros(Dat, ncx ,ncy ) + Fchk = zeros(Dat, ncx ,ncy ) + τxy2_c = zeros(Dat, ncx ,ncy ) + τxy_c = zeros(Dat, ncx ,ncy ) + ε̇xy1_c = zeros(Dat, ncx ,ncy ) + ε̇xy2_c = zeros(Dat, ncx ,ncy ) + ε̇xy_c = zeros(Dat, ncx ,ncy ) + τii = zeros(size(ε̇xx)) + ε̇ii = zeros(size(ε̇xx)) + λ = zeros(size(ε̇xx)) + Pla = zeros(size(ε̇xx)) + dQdTxx = zeros(size(ε̇xx)) + dQdTyy = zeros(size(ε̇xx)) + dQdTxy = zeros(size(ε̇xx)) + ηvep_v = ones(Dat, ncx+1, ncy+1) + ηvep_c = ones(Dat, ncx , ncy ) + + # For geoparams + τii0 = zeros(size(ε̇xx)) + ε̇ii_pl = zeros(size(ε̇xx)) + + τii0c = zeros(size(ε̇xx)) + τii0v = zeros(size(ε̇xy)) + ε̇iic = zeros(size(ε̇xx)) + ε̇iiv = zeros(size(ε̇xy)) + + # For non-geoparams version + η, G = 1.0, 1.0 + ηe_c = Δt*G.*ones(Dat, ncx ,ncy ) + ηe_v = Δt*G.*ones(Dat, ncx+1,ncy+1) + ηve_c = zeros(Dat, ncx ,ncy ) + ηve_v = zeros(Dat, ncx+1,ncy+1) + η_vep = ones(Dat, ncx ,ncy ) + η_vep_v = ones(Dat, ncx+1,ncy+1) + + # Initialisation + xce, yce = LinRange(-Δx/2, Lx+Δx/2, ncx+2), LinRange(-Δy/2, Ly+Δy/2, ncy+2) + xc, yc = LinRange(Δx/2, Lx-Δx/2, ncx), LinRange(Δy/2, Ly-Δy/2, ncy) + xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + # For non-geoparams version + Phasec[radc.ε && iter<=iterMax) + # BCs + Vx[:,1] .= Vx[:,2] # S + Vx[:,end] .= Vx[:,end-1] # N + Vy[1,:] .= Vy[2,:] # W + Vy[end,:] .= Vy[end-1,:] # E + # Kinematics + ∇V .= diff(Vx[:,2:end-1], dims=1)./Δx .+ diff(Vy[2:end-1,:], dims=2)./Δy + ε̇xx .= diff(Vx[:,2:end-1], dims=1)./Δx .- 1.0/3.0*∇V + ε̇yy .= diff(Vy[2:end-1,:], dims=2)./Δy .- 1.0/3.0*∇V + ε̇xy .= 0.5.*(diff(Vx, dims=2)./Δy .+ diff(Vy, dims=1)./Δx) + # Stresses + if UseGeoParams + #UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, τxy_c, ε̇xx, ε̇yy, ε̇xy, ε̇xy_c, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, Pt, MatParam, Δt, Phasec, Phasev ) + UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, τxy_c, ε̇xx, ε̇yy, ε̇xy, ε̇xy_c, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, Pt, MatParam, Δt, Phasec, Phasev ) + + else + #UpdateStressNative_VE!(ηe_c, ηe_v, ηve_c, ηve_v, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0) + #UpdateStressNative_VEP!(ηe_c, ηe_v, ηve_c, ηve_v, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, + # ε̇xx1, ε̇yy1, ε̇xy1, ε̇xy1_c, ε̇xy2_c, τxy0_c, ε̇ii, τxy_c, τxy2_c, τii, F, τ_y, Pt, sinϕ, η_reg, Pla, λ, dQdTxx, dQdTyy, dQdTxy, Fchk, ηvep_c, ηvep_v, ηc, ηv) + + UpdateStressNative_VEP_invariants!(ηe_c, ηe_v, ηve_c, ηve_v, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, + ε̇ii, τii, τii0, ε̇xy_c, τxy_c, ε̇xy2_c, τxy2_c, F, τ_y, Pt, sinϕ, η_reg, Pla, λ, ε̇ii_pl, Fchk, ηc, ηv) + + end + # Residuals + Rx[2:end-1,:] .= .-diff(Pt, dims=1)./Δx .+ diff(τxx, dims=1)./Δx .+ diff(τxy[2:end-1,:], dims=2)./Δy + Ry[:,2:end-1] .= .-diff(Pt, dims=2)./Δy .+ diff(τyy, dims=2)./Δy .+ diff(τxy[:,2:end-1], dims=1)./Δx #.+ av_ya(Rog) + Rp .= .-∇V + # PT time step ----------------------------------------------- + Δτv .= ρ*min(Δx,Δy)^2 ./ ηv ./ 4.1 * cfl + Δτvx .= (Δτv[:,1:end-1] .+ Δτv[:,2:end]) / 2. + Δτvy .= (Δτv[1:end-1,:] .+ Δτv[2:end,:]) / 2. + κΔτp .= cfl .* ηc .* Δx ./ Lx + # Calculate rate update -------------------------------------- + dVxdτ .= (1-ρ) .* dVxdτ .+ Rx + dVydτ .= (1-ρ) .* dVydτ .+ Ry + dPdτ .= Rp + # Update velocity and pressure ------------------------------- + Vx[:,2:end-1] .+= Δτvx ./ ρ .* dVxdτ + Vy[2:end-1,:] .+= Δτvy ./ ρ .* dVydτ + Pt .+= κΔτp .* dPdτ + # convergence check + if mod(iter, nout)==0 || iter==1 + norm_Rx = norm(Rx)/sqrt(length(Rx)); norm_Ry = norm(Ry)/sqrt(length(Ry)); norm_∇V = norm(∇V)/sqrt(length(∇V)) + err = maximum([norm_Rx, norm_Ry, norm_∇V]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %03d, iter = %04d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] Fchk = %1.3e \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V, maximum(Fchk)) + end + iter+=1; global itg=iter + end + t = t + Δt + push!(evo_t, t); push!(evo_τxx, maximum(τxx)) + + if doPlot + # Plotting + #p1 = heatmap(xv, yc, Vx[:,2:end-1]', aspect_ratio=1, xlims=(0, Lx), ylims=(Δy/2, Ly-Δy/2), c=:inferno, title="Vx") + p1 = heatmap(xv, yv, τxy', aspect_ratio=1, xlims=(0, Lx), ylims=(Δy/2, Ly-Δy/2), c=:inferno, title="τxy") + + #p2 = heatmap(xc, yv, Vy[2:end-1,:]', aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="Vy") + # p2 = heatmap(xv, yv, η_vep_v', aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="Vy") + #p2 = heatmap(xv, yv, ηv' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="η_vep") + p2 = heatmap(xv, yv, ηv' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="η_vep") + + p3 = heatmap(xc, yc, Pt' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="P") + #p3 = heatmap(xv, yv, τxy' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="τxy") + p4 = plot(evo_t, evo_τxx , xlabel="time", ylabel="max(τxx)", legend=false, linewidth=0, markershape=:circle, markersize=3) + p4 = plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G./η0)), linewidth=2.0) # analytical solution + display(plot(p1, p2, p3, p4)) + end + end + return +end + +for i=1:1 + println("step $i") + doPlots = true + @time Stokes2D_VE_inclusion(false, doPlots) + @time Stokes2D_VE_inclusion(true, doPlots) +end \ No newline at end of file From a87f0893f32a16e9e95d7c6df8c7ec314c9e7c0b Mon Sep 17 00:00:00 2001 From: Boris Kaus Date: Wed, 26 Oct 2022 23:26:42 -0300 Subject: [PATCH 20/49] code clarity; reduce allocations --- .../Stokes2D_VEP_inclusion_GeoParams_v3.jl | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl index 968aea4..fce6192 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl @@ -6,6 +6,13 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) @views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) @views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +@inline function av_c(A, i, j) + return 0.25*(A[i,j] + A[i+1,j] + A[i,j+1] + A[i+1,j+1]) +end + +@inline function av_v(A, i, j) + return 0.25*(A[i,j] + A[i-1,j] + A[i,j-1] + A[i-1,j-1]) +end @views function average_c!(Ac::AbstractArray{N,T}, Av::AbstractArray{N,T}) where {N,T} # extrapolate vertex -> center @@ -43,21 +50,21 @@ end average_c!(ε̇xy_c, ε̇xy) # average vertices -> centers # Centroids - for j ∈ axes(ε̇xx,2), i ∈ axes(ε̇xx,1) + @inbounds for j ∈ axes(ε̇xx,2), i ∈ axes(ε̇xx,1) # compute second invariants from surrounding points - τii0 = second_invariant_staggered( (τxx0[i,j],τyy0[i,j]), (τxy0[i,j], τxy0[i+1,j], τxy0[i,j+1], τxy0[i+1,j+1])) - ε̇ii = second_invariant_staggered( (ε̇xx[i,j], ε̇yy[i,j] ), (ε̇xy[i,j], ε̇xy[i+1,j], ε̇xy[i,j+1], ε̇xy[i+1,j+1])) - args = (; τII_old = τii0, dt=Δt, P=Pt[i,j]) - ηc[i,j] = phase_viscosity(MatParam, ε̇ii, Phasec[i,j], args) - τxx[i,j] = 2*ηc[i,j]*ε̇xx[i,j] - τyy[i,j] = 2*ηc[i,j]*ε̇yy[i,j] - - τxy_c[i,j] = 2*ηc[i,j]*ε̇xy_c[i,j] + τii0 = sqrt(0.5 *(τxx0[i,j]^2 + τyy0[i,j]^2) + av_c(τxy0,i,j)^2) + ε̇ii = sqrt(0.5 *( ε̇xx[i,j]^2 + ε̇yy[i,j]^2) + av_c(ε̇xy,i,j)^2) + + args = (; τII_old = τii0, dt=Δt, P=Pt[i,j]) + η = ηc[i,j] = phase_viscosity(MatParam, ε̇ii, Phasec[i,j], args) + τxx[i,j] = 2*η*ε̇xx[i,j] + τyy[i,j] = 2*η*ε̇yy[i,j] + τxy_c[i,j] = 2*η*ε̇xy_c[i,j] end cen2ver!(ηv, ηc) # extrapolate from centers -> vertices # Vertices - for j ∈ 2:size(ε̇xy,2)-1, i ∈ 2:size(ε̇xy,1)-1 + @inbounds for j ∈ 2:size(ε̇xy,2)-1, i ∈ 2:size(ε̇xy,1)-1 τxy[i,j] = 2*ηv[i,j]*ε̇xy[i,j] end @@ -305,6 +312,8 @@ end # Time loop t=0.0; evo_t=[]; evo_τxx=[]; global itg = 1 + global it_total = 0 + for it = 1:nt iter=1; err=2*ε; err_evo1=[]; err_evo2=[]; τxx0.=τxx; τyy0.=τyy; τxy0.=τxy @@ -357,8 +366,9 @@ end push!(err_evo1, err); push!(err_evo2, itg) @printf("it = %03d, iter = %04d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] Fchk = %1.3e \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V, maximum(Fchk)) end - iter+=1; global itg=iter + iter+=1; global itg = iter; end + global it_total += itg t = t + Δt push!(evo_t, t); push!(evo_τxx, maximum(τxx)) @@ -379,12 +389,13 @@ end display(plot(p1, p2, p3, p4)) end end + @show it_total return end for i=1:1 println("step $i") - doPlots = true + doPlots = false @time Stokes2D_VE_inclusion(false, doPlots) @time Stokes2D_VE_inclusion(true, doPlots) end \ No newline at end of file From cfd2970d7812b20bc6b1a5db501e79eb05b71a7a Mon Sep 17 00:00:00 2001 From: Boris Kaus Date: Fri, 28 Oct 2022 18:53:18 -0300 Subject: [PATCH 21/49] debugging: compare the values of the "native" and GP versions. Identical for von Mises (after eliminating a pow2 bug) --- .../Stokes2D_VEP_inclusion_GeoParams_v3.jl | 102 +++++++++++++----- 1 file changed, 76 insertions(+), 26 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl index fce6192..7fbc3c0 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl @@ -1,6 +1,6 @@ # Initialisation using Plots, Printf, Statistics, LinearAlgebra, GeoParams -Dat = Float64 # Precision (double=Float64 or single=Float32) +const Dat = Float64 # Precision (double=Float64 or single=Float32) # Macros @views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) @views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) @@ -10,15 +10,24 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) return 0.25*(A[i,j] + A[i+1,j] + A[i,j+1] + A[i+1,j+1]) end +# Average square of the 4 vertex points +@inline function av2_c(A, i, j) + return 0.25*(A[i,j]^2 + A[i+1,j]^2 + A[i,j+1]^2 + A[i+1,j+1]^2) +end + @inline function av_v(A, i, j) return 0.25*(A[i,j] + A[i-1,j] + A[i,j-1] + A[i-1,j-1]) end +@inline function av2_v(A, i, j) + return 0.25*(A[i,j]^2 + A[i-1,j]^2 + A[i,j-1]^2 + A[i-1,j-1]^2) +end + + @views function average_c!(Ac::AbstractArray{N,T}, Av::AbstractArray{N,T}) where {N,T} # extrapolate vertex -> center - for I in CartesianIndices(Ac) - i,j = I[1], I[2]; - Ac[I] = 0.25*(Av[i,j] + Av[i+1,j] + Av[i,j+1] + Av[i+1,j+1]) + for j ∈ axes(Ac,2), i ∈ axes(Ac,1) + Ac[i,j] = av_c(Av,i,j) end return nothing @@ -41,7 +50,7 @@ end end end # Rheology -@views function UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, τxy_c, ε̇xx, ε̇yy, ε̇xy, ε̇xy_c, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, Pt, MatParam, Δt, Phasec, Phasev ) +@views function UpdateStressGeoParams!( ηc, ηv, τii, τxx, τyy, τxy, τxy_c, ε̇xx, ε̇yy, ε̇xy, ε̇xy_c, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, Pt, MatParam, Δt, Phasec, Phasev ) # ε̇iic .= sqrt.(1//2 .*(ε̇xx.^2 .+ ε̇yy.^2) .+ av(ε̇xy).^2) # ε̇iiv[2:end-1,2:end-1] .= sqrt.(1//2 .*( av(ε̇xx).^2 .+ av(ε̇yy).^2) .+ ε̇xy[2:end-1,2:end-1].^2) # τii0c .= sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) @@ -52,22 +61,30 @@ end # Centroids @inbounds for j ∈ axes(ε̇xx,2), i ∈ axes(ε̇xx,1) # compute second invariants from surrounding points - τii0 = sqrt(0.5 *(τxx0[i,j]^2 + τyy0[i,j]^2) + av_c(τxy0,i,j)^2) - ε̇ii = sqrt(0.5 *( ε̇xx[i,j]^2 + ε̇yy[i,j]^2) + av_c(ε̇xy,i,j)^2) + τii0 = sqrt(0.5 *(τxx0[i,j]^2 + τyy0[i,j]^2) + av2_c(τxy0,i,j)) + ε̇ii = sqrt(0.5 *( ε̇xx[i,j]^2 + ε̇yy[i,j]^2) + av2_c(ε̇xy,i,j)) args = (; τII_old = τii0, dt=Δt, P=Pt[i,j]) + η = ηc[i,j] = phase_viscosity(MatParam, ε̇ii, Phasec[i,j], args) τxx[i,j] = 2*η*ε̇xx[i,j] τyy[i,j] = 2*η*ε̇yy[i,j] τxy_c[i,j] = 2*η*ε̇xy_c[i,j] + + # τii[i,j] = 2*η*ε̇ii # mostly for debugging + + τii[i,j] = first(compute_τII(MatParam[Phasec[i,j]].CompositeRheology[1], ε̇ii, args)) + end cen2ver!(ηv, ηc) # extrapolate from centers -> vertices # Vertices - @inbounds for j ∈ 2:size(ε̇xy,2)-1, i ∈ 2:size(ε̇xy,1)-1 - τxy[i,j] = 2*ηv[i,j]*ε̇xy[i,j] - end + # @inbounds for j ∈ 2:size(ε̇xy,2)-1, i ∈ 2:size(ε̇xy,1)-1 + # τxy[i,j] = 2*ηv[i,j]*ε̇xy[i,j] + # end + cen2ver!(τxy, τxy_c) # extrapolate from centers -> vertices + return nothing end @@ -85,14 +102,13 @@ end ε̇ii, τii, τii0, ε̇xy_c, τxy_c,ε̇xy2_c, τxy2_c, F, τ_y, Pt, sinϕ, η_reg, Pla, λ, ε̇ii_pl, Fchk, ηc, ηv) # visco-elastic strain rates - average_c!(τxy2_c, τxy0.^2) - average_c!(ε̇xy2_c, ε̇xy.^2) + average_c!(τxy2_c, τxy0.^2) # average squares! + average_c!(ε̇xy2_c, ε̇xy.^2 ) - τii0 .= sqrt.( 0.5.*(τxx0.^2 .+ τyy0.^2) .+ τxy2_c) # watch out - name is misleading - ε̇ii .= sqrt.( 0.5.*(ε̇xx.^2 .+ ε̇yy.^2) .+ ε̇xy2_c) # strain rate invariant @ center - τii .= 2.0.*ηve_c.*(ε̇ii .+ τii0./(2.0.*ηe_c) ) # trial stress + τii0 .= sqrt.( 0.5.*(τxx0.^2 .+ τyy0.^2) .+ τxy2_c) # old stress invariant @ cente + ε̇ii .= sqrt.( 0.5.*(ε̇xx.^2 .+ ε̇yy.^2) .+ ε̇xy2_c) # strain rate invariant @ center + τii .= 2.0.*ηve_c.*(ε̇ii .+ τii0./(2.0.*ηe_c) ) # trial stress - #ε̇xy_c .= av(ε̇xy) average_c!(ε̇xy_c, ε̇xy) # Compute plasticity @ center @@ -111,9 +127,9 @@ end τxy_c .= 2.0.*ηc.*ε̇xy_c cen2ver!(ηv, ηc) # extrapolate from centers -> vertices + cen2ver!(τxy, τxy_c) # extrapolate from centers -> vertices - τxy .= 2.0.*ηv.*ε̇xy # update stress @ vertexes - +# τxy .= 2.0.*ηv.*ε̇xy # update stress @ vertexes return nothing end @@ -135,6 +151,7 @@ end τxy_c .= 2.0.*ηve_c.*ε̇xy1_c τii .= sqrt.(0.5*(τxx.^2 .+ τyy.^2) .+ τxy_c.^2) + # yield function F .= τii .- τ_y .- Pt.*sinϕ Pla .= 0.0 @@ -161,7 +178,6 @@ end # τyy .= 2 .* ηve_c .* ( ε̇yy .+ τyy0./(2 .* ηe_c) ) # τxy .= 2 .* ηve_v .* ( ε̇xy1 ) - return nothing end @@ -178,7 +194,7 @@ end radi = 0.01 τ_y = 1.6 Gi = G0/(6.0-4.0*do_DP) # inclusion shear modulus - η_reg = 1.2e-2 # regularisation "viscosity" + η_reg = 2*1.2e-2 # regularisation "viscosity" ϕ = 30*do_DP sinϕ = sind(ϕ)*do_DP Coh = τ_y/cosd(ϕ) # cohesion @@ -199,7 +215,7 @@ end #ncx, ncy = 63, 63 # numerical grid resolution ε = 1e-6 # nonlinear tolerence - iterMax = 1e4 # max number of iters + iterMax = 1e5 # max number of iters nout = 500 # check frequency # Iterative parameters ------------------------------------------- Reopt = 5π @@ -303,6 +319,15 @@ end ηc1 = copy(ηc) ηv1 = copy(ηv) + + + # for checking + ηc_check = zeros(size(ηc)) + ηv_check = zeros(size(ηv)) + τii_check = zeros(size(τii)) + τxx_check = zeros(size(τxx)) + τyy_check = zeros(size(τyy)) + τxy_check = zeros(size(τxy)) # Velocity (Xvx,Yvx) = ([x for x=xv,y=yce], [y for x=xv,y=yce]) @@ -328,11 +353,35 @@ end ε̇xx .= diff(Vx[:,2:end-1], dims=1)./Δx .- 1.0/3.0*∇V ε̇yy .= diff(Vy[2:end-1,:], dims=2)./Δy .- 1.0/3.0*∇V ε̇xy .= 0.5.*(diff(Vx, dims=2)./Δy .+ diff(Vy, dims=1)./Δx) + # Stresses if UseGeoParams - #UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, τxy_c, ε̇xx, ε̇yy, ε̇xy, ε̇xy_c, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, Pt, MatParam, Δt, Phasec, Phasev ) - UpdateStressGeoParams!( ηc, ηv, τxx, τyy, τxy, τxy_c, ε̇xx, ε̇yy, ε̇xy, ε̇xy_c, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, Pt, MatParam, Δt, Phasec, Phasev ) + UpdateStressGeoParams!( ηc, ηv, τii, τxx, τyy, τxy, τxy_c, ε̇xx, ε̇yy, ε̇xy, ε̇xy_c, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, Pt, MatParam, Δt, Phasec, Phasev ) + + if 1==1 + # for debugging: do the exact same with the "native" routine and check that the values are identical + + # Do the same calculation with native routine + UpdateStressNative_VEP_invariants!(ηe_c, ηe_v, ηve_c, ηve_v, τxx_check, τyy_check, τxy_check, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, + ε̇ii, τii_check, τii0, ε̇xy_c, τxy_c, ε̇xy2_c, τxy2_c, F, τ_y, Pt, sinϕ, η_reg, Pla, λ, ε̇ii_pl, Fchk, ηc_check, ηv_check) + #UpdateStressNative_VE!(ηe_c, ηe_v, ηve_c, ηve_v, τxx_check, τyy_check, τxy_check, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0) + + error_τii = norm(τii .- τii_check) + error_τxx = norm(τxx .- τxx_check) + error_τxy = norm(τxy .- τxy_check) + error_ηc = norm(ηc .- ηc_check) + error_ηv = norm(ηv .- ηv_check) + + if norm(error_τii)>1e-10 + @show error_τii, error_τxx, error_τxy, error_ηc, error_ηv τii[100]-τii_check[100] + error("stop - difference too large") + end + + if mod(iter, nout)==0 + @show error_τii, error_τxx, error_τxy, error_ηc, error_ηv τii[100]-τii_check[100] + end + end else #UpdateStressNative_VE!(ηe_c, ηe_v, ηve_c, ηve_v, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0) #UpdateStressNative_VEP!(ηe_c, ηe_v, ηve_c, ηve_v, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, @@ -368,10 +417,11 @@ end end iter+=1; global itg = iter; end + # error("stop here") + global it_total += itg t = t + Δt push!(evo_t, t); push!(evo_τxx, maximum(τxx)) - if doPlot # Plotting #p1 = heatmap(xv, yc, Vx[:,2:end-1]', aspect_ratio=1, xlims=(0, Lx), ylims=(Δy/2, Ly-Δy/2), c=:inferno, title="Vx") @@ -395,7 +445,7 @@ end for i=1:1 println("step $i") - doPlots = false - @time Stokes2D_VE_inclusion(false, doPlots) + doPlots = true + # @time Stokes2D_VE_inclusion(false, doPlots) @time Stokes2D_VE_inclusion(true, doPlots) end \ No newline at end of file From cbc97b51927502eb43c8bb9dd552ef73ea60837b Mon Sep 17 00:00:00 2001 From: Boris Kaus Date: Fri, 28 Oct 2022 20:28:11 -0300 Subject: [PATCH 22/49] bug found; helps if we set the same material properties in both cases... --- .../Stokes2D_VEP_inclusion_GeoParams_v3.jl | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl index 7fbc3c0..c603788 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl @@ -71,10 +71,7 @@ end τyy[i,j] = 2*η*ε̇yy[i,j] τxy_c[i,j] = 2*η*ε̇xy_c[i,j] - # τii[i,j] = 2*η*ε̇ii # mostly for debugging - - τii[i,j] = first(compute_τII(MatParam[Phasec[i,j]].CompositeRheology[1], ε̇ii, args)) - + τii[i,j] = 2*η*ε̇ii # mostly for debugging end cen2ver!(ηv, ηc) # extrapolate from centers -> vertices @@ -185,7 +182,7 @@ end # 2D Stokes routine @views function Stokes2D_VE_inclusion(UseGeoParams, doPlot = false) # Physics - do_DP = false + do_DP = true Lx, Ly = 1.0, 1.0 # domain size ξ = 10.0 # Maxwell relaxation time η0 = 1.0 # viscous viscosity @@ -310,8 +307,8 @@ end # For non-geoparams version Phasec[radc.1e-10 - @show error_τii, error_τxx, error_τxy, error_ηc, error_ηv τii[100]-τii_check[100] + @show error_τii, error_τxx, error_τxy, error_ηc, error_ηv τii[100]-τii_check[100], F[100] error("stop - difference too large") end @@ -445,7 +442,7 @@ end for i=1:1 println("step $i") - doPlots = true - # @time Stokes2D_VE_inclusion(false, doPlots) + doPlots = false + @time Stokes2D_VE_inclusion(false, doPlots) @time Stokes2D_VE_inclusion(true, doPlots) end \ No newline at end of file From 7455783ccf98916ec1ae63989647568bb5aab78b Mon Sep 17 00:00:00 2001 From: tduretz Date: Mon, 31 Oct 2022 13:05:24 +0100 Subject: [PATCH 23/49] One should now restart from the original script: Stokes2D_vep_reg_ctau.jl --- .../Stokes2D_VEP_inclusion_GeoParams_v4.jl | 466 ++++++++++++++++++ 1 file changed, 466 insertions(+) create mode 100644 GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v4.jl diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v4.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v4.jl new file mode 100644 index 0000000..92592e5 --- /dev/null +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v4.jl @@ -0,0 +1,466 @@ +# Code just does not converge properly, there is something wrong. +# One should now restart from the original script: Stokes2D_vep_reg_ctau.jl +# and make sure we get same results using GeoParams +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra, GeoParams +const Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) + +@inline function av_c(A, i, j) + return 0.25*(A[i,j] + A[i+1,j] + A[i,j+1] + A[i+1,j+1]) +end + +# Average square of the 4 vertex points +@inline function av2_c(A, i, j) + return 0.25*(A[i,j]^2 + A[i+1,j]^2 + A[i,j+1]^2 + A[i+1,j+1]^2) +end + +@inline function av_v(A, i, j) + return 0.25*(A[i,j] + A[i-1,j] + A[i,j-1] + A[i-1,j-1]) +end + +@inline function av2_v(A, i, j) + return 0.25*(A[i,j]^2 + A[i-1,j]^2 + A[i,j-1]^2 + A[i-1,j-1]^2) +end + + +@views function average_c!(Ac::AbstractArray{N,T}, Av::AbstractArray{N,T}) where {N,T} # extrapolate vertex -> center + + for j ∈ axes(Ac,2), i ∈ axes(Ac,1) + Ac[i,j] = av_c(Av,i,j) + end + + return nothing +end + + +@views function cen2ver!(Av::Array{N,T}, Ac::Array{N,T}) where {N,T} # extrapolate center -> vertex + average_c!( Av[2:end-1,2:end-1], Ac) + # Av[1,:].=Av[2,:]; + # Av[end,:].=Av[end-1,:]; + # Av[:,1].=Av[:,2]; + # Av[:,end].=Av[:,end-1] + return nothing +end + +@generated function phase_viscosity(v::NTuple{N,Any}, ε̇ii, phase, args) where N + quote + Base.@_inline_meta + Base.@nexprs $N i -> v[i].Phase === phase && return computeViscosity_εII(v[i].CompositeRheology[1], ε̇ii, args) + end +end +# Rheology +@views function UpdateStressGeoParams!( ηc, ηv, τii, τxx, τyy, τxy, τxy_c, ε̇xx, ε̇yy, ε̇xy, ε̇xy_c, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, Pt, MatParam, Δt, Phasec, Phasev ) + # ε̇iic .= sqrt.(1//2 .*(ε̇xx.^2 .+ ε̇yy.^2) .+ av(ε̇xy).^2) + # ε̇iiv[2:end-1,2:end-1] .= sqrt.(1//2 .*( av(ε̇xx).^2 .+ av(ε̇yy).^2) .+ ε̇xy[2:end-1,2:end-1].^2) + # τii0c .= sqrt.(1//2 .*(τxx0.^2 .+ τyy0.^2) .+ av(τxy0).^2) + # τii0v[2:end-1,2:end-1] .= sqrt.(1//2 .*( av(τxx0).^2 .+ av(τyy0).^2) .+ τxy0[2:end-1,2:end-1].^2) + + average_c!(ε̇xy_c, ε̇xy) # average vertices -> centers + + # Centroids + @inbounds for j ∈ axes(ε̇xx,2), i ∈ axes(ε̇xx,1) + # compute second invariants from surrounding points + τii0 = sqrt(0.5 *(τxx0[i,j]^2 + τyy0[i,j]^2) + av2_c(τxy0,i,j)) + ε̇ii = sqrt(0.5 *( ε̇xx[i,j]^2 + ε̇yy[i,j]^2) + av2_c(ε̇xy,i,j)) + + args = (; τII_old = τii0, dt=Δt, P=Pt[i,j]) + + η = ηc[i,j] = phase_viscosity(MatParam, ε̇ii, Phasec[i,j], args) + τxx[i,j] = 2*η*ε̇xx[i,j] + τyy[i,j] = 2*η*ε̇yy[i,j] + τxy_c[i,j] = 2*η*ε̇xy_c[i,j] + + τii[i,j] = 2*η*ε̇ii # mostly for debugging + end + cen2ver!(ηv, ηc) # extrapolate from centers -> vertices + + # Vertices + # @inbounds for j ∈ 2:size(ε̇xy,2)-1, i ∈ 2:size(ε̇xy,1)-1 + # τxy[i,j] = 2*ηv[i,j]*ε̇xy[i,j] + # end + cen2ver!(τxy, τxy_c) # extrapolate from centers -> vertices + + + return nothing +end + +@views function UpdateStressNative_VE!(ηe_c, ηe_v, ηve_c, ηve_v, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0) + + # Viscoelastic trial stress + τxx .= 2 .* ηve_c .* ( ε̇xx .+ τxx0./(2 .* ηe_c) ) + τyy .= 2 .* ηve_c .* ( ε̇yy .+ τyy0./(2 .* ηe_c) ) + τxy .= 2 .* ηve_v .* ( ε̇xy .+ τxy0./(2 .* ηe_v) ) + + return nothing +end + +@views function UpdateStressNative_VEP_invariants!(ηe_c, ηe_v, ηve_c, ηve_v, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, + ε̇ii, τii, τii0, ε̇xy_c, τxy_c,ε̇xy2_c, τxy2_c, F, τ_y, Pt, sinϕ, η_reg, Pla, λ, λ_phys, λ_rel, ε̇ii_pl, Fchk, ηc, ηv) + + # Visco-elastic strain rates + average_c!(τxy2_c, τxy0.^2) # average squares! + average_c!(ε̇xy2_c, ε̇xy.^2 ) + + τii0 .= sqrt.( 0.5.*(τxx0.^2 .+ τyy0.^2) .+ τxy2_c) # old stress invariant @ cente + ε̇ii .= sqrt.( 0.5.*(ε̇xx.^2 .+ ε̇yy.^2) .+ ε̇xy2_c) # strain rate invariant @ center + τii .= 2.0.*ηve_c.*(ε̇ii .+ τii0./(2.0.*ηe_c) ) # trial stress + + average_c!(ε̇xy_c, ε̇xy) + + # Compute plasticity @ center + F .= τii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ_phys .= Pla.*F./(ηve_c .+ η_reg) + λ .= λ_rel*λ_phys .+ (1.0.-λ_rel).*λ + ε̇ii_pl .= λ*0.5 # 2nd invariant of plastic strainrate (check!) + τii .= 2.0.*ηve_c.*(ε̇ii .+ τii0./(2.0*ηe_c) .- ε̇ii_pl) # updated stress @ center + Fchk .= τii .- τ_y .- Pt.*sinϕ .- λ.*η_reg + + # Update stress components + ηc .= τii./(2.0*ε̇ii) + τxx .= 2.0.*ηc.*ε̇xx + τyy .= 2.0.*ηc.*ε̇yy + τxy_c .= 2.0.*ηc.*ε̇xy_c + + cen2ver!(ηv, ηc) # extrapolate from centers -> vertices + cen2ver!(τxy, τxy_c) # extrapolate from centers -> vertices + +# τxy .= 2.0.*ηv.*ε̇xy # update stress @ vertexes + + return nothing +end + + +@views function UpdateStressNative_VEP!(ηe_c, ηe_v, ηve_c, ηve_v, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, + ε̇xx1, ε̇yy1, ε̇xy1, ε̇xy1_c, τxy0_c, ε̇ii, τxy_c, τii, F, τ_y, Pt, sinϕ, η_reg, Pla, λ, dQdTxx, dQdTyy, dQdTxy, Fchk, ηvep_c, ηvep_v) + + # visco-elastic strain rates + ε̇xx1 .= ε̇xx .+ τxx0 ./2.0./ηe_c + ε̇yy1 .= ε̇yy .+ τyy0 ./2.0./ηe_c + ε̇xy1 .= ε̇xy .+ τxy0 ./2.0./ηe_v + ε̇xy1_c .= av(ε̇xy) .+ τxy0_c./2.0./ηe_c + ε̇ii .= sqrt.(0.5*(ε̇xx1.^2 .+ ε̇yy1.^2) .+ ε̇xy1_c.^2) + + # trial stress + τxx .= 2.0.*ηve_c.*ε̇xx1 + τyy .= 2.0.*ηve_c.*ε̇yy1 + τxy_c .= 2.0.*ηve_c.*ε̇xy1_c + τii .= sqrt.(0.5*(τxx.^2 .+ τyy.^2) .+ τxy_c.^2) + + + # yield function + F .= τii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(ηve_c .+ η_reg) + dQdTxx .= 0.5.*τxx./τii + dQdTyy .= 0.5.*τyy./τii + dQdTxy .= τxy_c./τii + + # plastic corrections + τxx .= 2.0.*ηve_c.*(ε̇xx1 .- λ.*dQdTxx) + τyy .= 2.0.*ηve_c.*(ε̇yy1 .- λ.*dQdTyy) + τxy_c .= 2.0.*ηve_c.*(ε̇xy1_c .- 0.5.*λ.*dQdTxy) + τii .= sqrt.(0.5*(τxx.^2 .+ τyy.^2) .+ τxy_c.^2) + Fchk .= τii .- τ_y .- Pt.*sinϕ .- λ.*η_reg + + ηvep_c .= τii./2.0./ε̇ii + cen2ver!(ηvep_v, ηvep_c) + + τxy .= 2.0.*ηvep_v.*ε̇xy1 + + # purely viscoelastic correction + # τxx .= 2 .* ηve_c .* ( ε̇xx .+ τxx0./(2 .* ηe_c) ) + # τyy .= 2 .* ηve_c .* ( ε̇yy .+ τyy0./(2 .* ηe_c) ) + # τxy .= 2 .* ηve_v .* ( ε̇xy1 ) + + return nothing +end + + +# 2D Stokes routine +@views function Stokes2D_VE_inclusion(UseGeoParams, doPlot = false) + # Physics + do_DP = true + Lx, Ly = 1.0, 1.0 # domain size + ξ = 10.0 # Maxwell relaxation time + η0 = 1.0 # viscous viscosity + G0 = 1.0 # elastic shear modulus + εbg = 1.0 # background strain-rate + radi = 0.01 + τ_y = 1.6 + Gi = G0/(6.0-4.0*do_DP) # inclusion shear modulus + η_reg = 8.0e-3 # regularisation "viscosity" + ϕ = 30*do_DP + sinϕ = sind(ϕ)*do_DP + Coh = τ_y/cosd(ϕ) # cohesion + + + #pl = DruckerPrager(C=Coh, ϕ=ϕ) # non-regularized plasticity + #pl = Parallel(DruckerPrager(C=Coh, ϕ=ϕ), LinearViscous(η=η_reg)) + pl = DruckerPrager_regularised(C=Coh, ϕ=ϕ, η_vp=η_reg) # non-regularized plasticity + + MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G0),LinearViscous(η=η0),pl)), + SetMaterialParams(Name="Inclusion", Phase=2, + CompositeRheology = CompositeRheology(ConstantElasticity(G=Gi),LinearViscous(η=η0),pl)), + ) + + # Numerics + nt = 10 # number of time steps + # ncx, ncy = 31, 31 # numerical grid resolution + ncx, ncy = 63, 63 # numerical grid resolution + + ε = 1e-6 # nonlinear tolerence + iterMax = 1e5 # max number of iters + nout = 200 # check frequency + # Iterative parameters ------------------------------------------- + λ_rel = 1.0 + Reopt = 4π + cfl = 0.50 + ρ = cfl*Reopt/ncx + + + Vdmp = 4.0 # convergence acceleration (damping) + Vsc = 2.0 # iterative time step limiter + Ptsc = 6.0 # iterative time step limiter + + # Preprocessing + Δx, Δy = Lx/ncx, Ly/ncy + Δt = η0/G0/4.0 + # Array initialisation + Pt = zeros(Dat, ncx ,ncy ) + ∇V = zeros(Dat, ncx ,ncy ) + Vx = zeros(Dat, ncx+1,ncy+2) + Vy = zeros(Dat, ncx+2,ncy+1) + ε̇xx = zeros(Dat, ncx ,ncy ) + ε̇yy = zeros(Dat, ncx ,ncy ) + ε̇xy = zeros(Dat, ncx+1,ncy+1) + + ε̇xx1 = zeros(Dat, ncx ,ncy ) + ε̇yy1 = zeros(Dat, ncx ,ncy ) + ε̇xy1 = zeros(Dat, ncx+1,ncy+1) + ε̇xy1_c = zeros(Dat, ncx ,ncy ) + + τxx = zeros(Dat, ncx ,ncy ) + τyy = zeros(Dat, ncx ,ncy ) + τxy = zeros(Dat, ncx+1,ncy+1) + τxy_c = zeros(Dat, ncx ,ncy ) + τxy2_c = zeros(Dat, ncx ,ncy ) + + τxx0 = zeros(Dat, ncx ,ncy ) + τyy0 = zeros(Dat, ncx ,ncy ) + τxy0 = zeros(Dat, ncx+1,ncy+1) + τxy0_c = zeros(Dat, ncx ,ncy ) + + Rx = zeros(Dat, ncx+1,ncy ) + Ry = zeros(Dat, ncx ,ncy+1) + Rp = zeros(Dat, ncx ,ncy ) + dVxdτ = zeros(Dat, ncx+1,ncy ) + dVydτ = zeros(Dat, ncx ,ncy+1) + dPdτ = zeros(Dat, ncx ,ncy ) + Δτv = zeros(Dat, ncx+1,ncy+1) + Δτvx = zeros(Dat, ncx+1,ncy ) + Δτvy = zeros(Dat, ncx ,ncy+1) + κΔτp = zeros(Dat, ncx ,ncy ) + Rog = zeros(Dat, ncx ,ncy ) + ηc = η0*ones(Dat, ncx, ncy) + ηv = η0*ones(Dat, ncx+1, ncy+1) + Phasec = ones(Int, ncx ,ncy ) + Phasev = ones(Int, ncx+1,ncy+1) + + # For native plastic version + F = zeros(Dat, ncx ,ncy ) + Fchk = zeros(Dat, ncx ,ncy ) + τxy2_c = zeros(Dat, ncx ,ncy ) + τxy_c = zeros(Dat, ncx ,ncy ) + ε̇xy1_c = zeros(Dat, ncx ,ncy ) + ε̇xy2_c = zeros(Dat, ncx ,ncy ) + ε̇xy_c = zeros(Dat, ncx ,ncy ) + τii = zeros(size(ε̇xx)) + ε̇ii = zeros(size(ε̇xx)) + λ = zeros(size(ε̇xx)) + λ_phys = zeros(size(ε̇xx)) + Pla = zeros(size(ε̇xx)) + dQdTxx = zeros(size(ε̇xx)) + dQdTyy = zeros(size(ε̇xx)) + dQdTxy = zeros(size(ε̇xx)) + ηvep_v = ones(Dat, ncx+1, ncy+1) + ηvep_c = ones(Dat, ncx , ncy ) + + # For geoparams + τii0 = zeros(size(ε̇xx)) + ε̇ii_pl = zeros(size(ε̇xx)) + + τii0c = zeros(size(ε̇xx)) + τii0v = zeros(size(ε̇xy)) + ε̇iic = zeros(size(ε̇xx)) + ε̇iiv = zeros(size(ε̇xy)) + + # For non-geoparams version + η, G = 1.0, 1.0 + ηe_c = Δt*G.*ones(Dat, ncx ,ncy ) + ηe_v = Δt*G.*ones(Dat, ncx+1,ncy+1) + ηve_c = zeros(Dat, ncx ,ncy ) + ηve_v = zeros(Dat, ncx+1,ncy+1) + η_vep = ones(Dat, ncx ,ncy ) + η_vep_v = ones(Dat, ncx+1,ncy+1) + + # Initialisation + xce, yce = LinRange(-Δx/2, Lx+Δx/2, ncx+2), LinRange(-Δy/2, Ly+Δy/2, ncy+2) + xc, yc = LinRange(Δx/2, Lx-Δx/2, ncx), LinRange(Δy/2, Ly-Δy/2, ncy) + xv, yv = LinRange(0.0, Lx, ncx+1), LinRange(0.0, Ly, ncy+1) + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + # For non-geoparams version + Phasec[radc.ε && iter<=iterMax) + # BCs + Vx[:,1] .= Vx[:,2] # S + Vx[:,end] .= Vx[:,end-1] # N + Vy[1,:] .= Vy[2,:] # W + Vy[end,:] .= Vy[end-1,:] # E + # Kinematics + ∇V .= diff(Vx[:,2:end-1], dims=1)./Δx .+ diff(Vy[2:end-1,:], dims=2)./Δy + ε̇xx .= diff(Vx[:,2:end-1], dims=1)./Δx .- 1.0/3.0*∇V + ε̇yy .= diff(Vy[2:end-1,:], dims=2)./Δy .- 1.0/3.0*∇V + ε̇xy .= 0.5.*(diff(Vx, dims=2)./Δy .+ diff(Vy, dims=1)./Δx) + + # Stresses + if UseGeoParams + UpdateStressGeoParams!( ηc, ηv, τii, τxx, τyy, τxy, τxy_c, ε̇xx, ε̇yy, ε̇xy, ε̇xy_c, ε̇iic, ε̇iiv, τxx0, τyy0, τxy0, τii0c, τii0v, Pt, MatParam, Δt, Phasec, Phasev ) + + if 1==0 + # for debugging: do the exact same with the "native" routine and check that the values are identical + + # Do the same calculation with native routine + UpdateStressNative_VEP_invariants!(ηe_c, ηe_v, ηve_c, ηve_v, τxx_check, τyy_check, τxy_check, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, + ε̇ii, τii_check, τii0, ε̇xy_c, τxy_c, ε̇xy2_c, τxy2_c, F, τ_y, Pt, sinϕ, η_reg, Pla, λ, ε̇ii_pl, Fchk, ηc_check, ηv_check) + + #UpdateStressNative_VE!(ηe_c, ηe_v, ηve_c, ηve_v, τxx_check, τyy_check, τxy_check, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0) + + error_τii = norm(τii .- τii_check) + error_τxx = norm(τxx .- τxx_check) + error_τxy = norm(τxy .- τxy_check) + error_ηc = norm(ηc .- ηc_check) + error_ηv = norm(ηv .- ηv_check) + + if norm(error_τii)>1e-10 + @show error_τii, error_τxx, error_τxy, error_ηc, error_ηv τii[100]-τii_check[100], F[100] + error("stop - difference too large") + end + + if mod(iter, nout)==0 + @show error_τii, error_τxx, error_τxy, error_ηc, error_ηv τii[100]-τii_check[100] + end + end + else + #UpdateStressNative_VE!(ηe_c, ηe_v, ηve_c, ηve_v, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0) + #UpdateStressNative_VEP!(ηe_c, ηe_v, ηve_c, ηve_v, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, + # ε̇xx1, ε̇yy1, ε̇xy1, ε̇xy1_c, ε̇xy2_c, τxy0_c, ε̇ii, τxy_c, τxy2_c, τii, F, τ_y, Pt, sinϕ, η_reg, Pla, λ, dQdTxx, dQdTyy, dQdTxy, Fchk, ηvep_c, ηvep_v, ηc, ηv) + + UpdateStressNative_VEP_invariants!(ηe_c, ηe_v, ηve_c, ηve_v, τxx, τyy, τxy, ε̇xx, ε̇yy, ε̇xy, τxx0, τyy0, τxy0, + ε̇ii, τii, τii0, ε̇xy_c, τxy_c, ε̇xy2_c, τxy2_c, F, τ_y, Pt, sinϕ, η_reg, Pla, λ, λ_phys, λ_rel, ε̇ii_pl, Fchk, ηc, ηv) + + end + # Residuals + Rx[2:end-1,:] .= .-diff(Pt, dims=1)./Δx .+ diff(τxx, dims=1)./Δx .+ diff(τxy[2:end-1,:], dims=2)./Δy + Ry[:,2:end-1] .= .-diff(Pt, dims=2)./Δy .+ diff(τyy, dims=2)./Δy .+ diff(τxy[:,2:end-1], dims=1)./Δx #.+ av_ya(Rog) + Rp .= .-∇V + # # PT time step ----------------------------------------------- + # Δτv .= ρ*min(Δx,Δy)^2 ./ ηv ./ 4.1 * cfl + # Δτvx .= (Δτv[:,1:end-1] .+ Δτv[:,2:end]) / 2. + # Δτvy .= (Δτv[1:end-1,:] .+ Δτv[2:end,:]) / 2. + # κΔτp .= cfl .* ηc .* Δx ./ Lx + # PT timestep + Δτvx[2:end-1,:] .= min(Δx,Δy)^2.0./av_xa(ηc)./4.1./Vsc + Δτvy[:,2:end-1] .= min(Δx,Δy)^2.0./av_ya(ηc)./4.1./Vsc + κΔτp .= 4.1.*ηc./max(ncx,ncy)./Ptsc + # Calculate rate update -------------------------------------- + # dVxdτ .= (1-ρ) .* dVxdτ .+ Rx + # dVydτ .= (1-ρ) .* dVydτ .+ Ry + dVxdτ .= (1-Vdmp/ncx) .* dVxdτ .+ Rx + dVydτ .= (1-Vdmp/ncy) .* dVydτ .+ Ry + dPdτ .= Rp + # Update velocity and pressure ------------------------------- + # Vx[:,2:end-1] .+= Δτvx ./ ρ .* dVxdτ + # Vy[2:end-1,:] .+= Δτvy ./ ρ .* dVydτ + Vx[:,2:end-1] .+= Δτvx .* dVxdτ + Vy[2:end-1,:] .+= Δτvy .* dVydτ + Pt .+= κΔτp .* dPdτ + # convergence check + if mod(iter, nout)==0 || iter==1 + norm_Rx = norm(Rx)/sqrt(length(Rx)); norm_Ry = norm(Ry)/sqrt(length(Ry)); norm_∇V = norm(∇V)/sqrt(length(∇V)) + err = maximum([norm_Rx, norm_Ry, norm_∇V]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %03d, iter = %04d, err = %1.3e norm[Rx=%1.3e, Ry=%1.3e, ∇V=%1.3e] Fchk = %1.3e \n", it, iter, err, norm_Rx, norm_Ry, norm_∇V, maximum(Fchk)) + end + iter+=1; global itg = iter; + end + # error("stop here") + + global it_total += itg + t = t + Δt + push!(evo_t, t); push!(evo_τxx, maximum(τxx)) + if doPlot + # Plotting + p1 = heatmap(xv, yc, Vx[:,2:end-1]' , aspect_ratio=1, xlims=(0, Lx), ylims=(Δy/2, Ly-Δy/2), c=:inferno, title="Vx") + # p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p2 = heatmap(xc, yc, ηc' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="η_vep") + p3 = heatmap(xc, yc, τii' , aspect_ratio=1, xlims=(Δx/2, Lx-Δx/2), ylims=(0, Ly), c=:inferno, title="τii") + p4 = plot(evo_t, evo_τxx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + plot!(evo_t, 2.0.*εbg.*η0.*(1.0.-exp.(.-evo_t.*G0./η0)), linewidth=2.0) # analytical solution for VE loading + plot!(evo_t, 2.0.*εbg.*η0.*ones(size(evo_t)), linewidth=2.0) # viscous flow stress + if !do_DP plot!(evo_t, τ_y*ones(size(evo_t)), linewidth=2.0) end # von Mises yield stress + display(plot(p1,p2,p3,p4)) + end + end + @show it_total + return +end + +for i=1:1 + println("step $i") + doPlots = true + @time Stokes2D_VE_inclusion(false, doPlots) + # @time Stokes2D_VE_inclusion(true, doPlots) +end \ No newline at end of file From 0f6ea3e9b6228cc180cec04948d00b5d92f6edf6 Mon Sep 17 00:00:00 2001 From: tduretz Date: Wed, 2 Nov 2022 11:51:45 +0100 Subject: [PATCH 24/49] fresh restart for VEVP --- .../Stokes2D_VEP_reg_ctau_GeoParams.jl | 195 ++++++++++++++++++ .../Stokes2D_VEP_inclusion_GeoParams.jl | 0 .../Stokes2D_VEP_inclusion_GeoParams_v2.jl | 0 .../Stokes2D_VEP_inclusion_GeoParams_v3.jl | 10 +- .../Stokes2D_VEP_inclusion_GeoParams_v4.jl | 0 .../Stokes2D_vep_bench_GeoParams.jl | 0 .../Stokes2D_vep_reg_vc_GeoParams.jl | 0 7 files changed, 200 insertions(+), 5 deletions(-) create mode 100644 GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_GeoParams.jl rename GeoParams_PT_examples/scripts/{ => history}/Stokes2D_VEP_inclusion_GeoParams.jl (100%) rename GeoParams_PT_examples/scripts/{ => history}/Stokes2D_VEP_inclusion_GeoParams_v2.jl (100%) rename GeoParams_PT_examples/scripts/{ => history}/Stokes2D_VEP_inclusion_GeoParams_v3.jl (98%) rename GeoParams_PT_examples/scripts/{ => history}/Stokes2D_VEP_inclusion_GeoParams_v4.jl (100%) rename GeoParams_PT_examples/scripts/{ => history}/Stokes2D_vep_bench_GeoParams.jl (100%) rename GeoParams_PT_examples/scripts/{ => history}/Stokes2D_vep_reg_vc_GeoParams.jl (100%) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_GeoParams.jl new file mode 100644 index 0000000..77217ef --- /dev/null +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_GeoParams.jl @@ -0,0 +1,195 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra, GeoParams +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +# 2D Stokes routine +@views function Stokes2D_vep(UseGeoParams) + do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) + η_reg = 8.0e-3 # regularisation "viscosity" + # Physics + Lx, Ly = 1.0, 1.0 # domain size + radi = 0.01 # inclusion radius + τ_y = 1.6 # yield stress. If do_DP=true, τ_y stand for the cohesion: c*cos(ϕ) + ϕ = 30.0 + sinϕ = sind(ϕ)*do_DP # sinus of the friction angle + μ0 = 1.0 # viscous viscosity + G0 = 1.0 # elastic shear modulus + Gi = G0/(6.0-4.0*do_DP) # elastic shear modulus perturbation + εbg = 1.0 # background strain-rate + Coh = τ_y/cosd(ϕ) # cohesion + # Geoparams initialisation + pl = DruckerPrager_regularised(C=Coh, ϕ=ϕ, η_vp=η_reg) # non-regularized plasticity + MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G0),LinearViscous(η=μ0),pl)), + SetMaterialParams(Name="Inclusion", Phase=2, + CompositeRheology = CompositeRheology(ConstantElasticity(G=Gi),LinearViscous(η=μ0),pl)), + ) + # Numerics + nt = 10 # number of time steps + nx, ny = 63, 63 # numerical grid resolution + Vdmp = 4.0 # convergence acceleration (damping) + Vsc = 2.0 # iterative time step limiter + Ptsc = 6.0 # iterative time step limiter + ε = 1e-6 # nonlinear tolerence + iterMax = 3e4 # max number of iters + nout = 200 # check frequency + # Preprocessing + dx, dy = Lx/nx, Ly/ny + dt = μ0/G0/4.0 # assumes Maxwell time of 4 + # Array initialisation + Pt = zeros(Dat, nx ,ny ) + ∇V = zeros(Dat, nx ,ny ) + Vx = zeros(Dat, nx+1,ny ) + Vy = zeros(Dat, nx ,ny+1) + Exx = zeros(Dat, nx ,ny ) + Eyy = zeros(Dat, nx ,ny ) + Exy = zeros(Dat, nx ,ny ) + Exyv = zeros(Dat, nx+1,ny+1) + Exx1 = zeros(Dat, nx ,ny ) + Eyy1 = zeros(Dat, nx ,ny ) + Exy1 = zeros(Dat, nx ,ny ) + Exyv1 = zeros(Dat, nx+1,ny+1) + Txx = zeros(Dat, nx ,ny ) + Tyy = zeros(Dat, nx ,ny ) + Txy = zeros(Dat, nx ,ny ) + Txyv = zeros(Dat, nx+1,ny+1) + Txx_o = zeros(Dat, nx ,ny ) + Tyy_o = zeros(Dat, nx ,ny ) + Txy_o = zeros(Dat, nx ,ny ) + Txyv_o = zeros(Dat, nx+1,ny+1) + Tii = zeros(Dat, nx ,ny ) + Eii = zeros(Dat, nx ,ny ) + F = zeros(Dat, nx ,ny ) + Fchk = zeros(Dat, nx ,ny ) + Pla = zeros(Dat, nx ,ny ) + λ = zeros(Dat, nx ,ny ) + dQdTxx = zeros(Dat, nx ,ny ) + dQdTyy = zeros(Dat, nx ,ny ) + dQdTxy = zeros(Dat, nx ,ny ) + Rx = zeros(Dat, nx-1,ny ) + Ry = zeros(Dat, nx ,ny-1) + dVxdt = zeros(Dat, nx-1,ny ) + dVydt = zeros(Dat, nx ,ny-1) + dtPt = zeros(Dat, nx ,ny ) + dtVx = zeros(Dat, nx-1,ny ) + dtVy = zeros(Dat, nx ,ny-1) + Rog = zeros(Dat, nx ,ny ) + η_v = μ0*ones(Dat, nx, ny) + η_e = dt*G0*ones(Dat, nx, ny) + η_ev = dt*G0*ones(Dat, nx+1, ny+1) + η_ve = ones(Dat, nx, ny) + η_vep = ones(Dat, nx, ny) + η_vepv = ones(Dat, nx+1, ny+1) + Phasec = ones(Int, nx ,ny ) + # Initial condition + xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) + xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) + xv, yv = LinRange(0.0, Lx, nx+1), LinRange(0.0, Ly, ny+1) + (Xvx,Yvx) = ([x for x=xv,y=yc], [y for x=xv,y=yc]) + (Xvy,Yvy) = ([x for x=xc,y=yv], [y for x=xc,y=yv]) + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + η_e[radc.ε && iter<=iterMax) + # divergence - pressure + ∇V .= diff(Vx, dims=1)./dx .+ diff(Vy, dims=2)./dy + Pt .= Pt .- dtPt.*∇V + # strain rates + Exx .= diff(Vx, dims=1)./dx .- 1.0/3.0*∇V + Eyy .= diff(Vy, dims=2)./dy .- 1.0/3.0*∇V + Exyv[2:end-1,2:end-1] .= 0.5.*(diff(Vx[2:end-1,:], dims=2)./dy .+ diff(Vy[:,2:end-1], dims=1)./dx) + Exy .= av(Exyv) + # visco-elastic strain rates + Exx1 .= Exx .+ Txx_o ./2.0./η_e + Eyy1 .= Eyy .+ Tyy_o ./2.0./η_e + Exy1 .= Exy .+ Txy_o ./2.0./η_e + Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ Exy1.^2) + if UseGeoParams + @inbounds for j ∈ axes(Exx,2), i ∈ axes(Exx,1) + # compute second invariants from surrounding points + τii0 = sqrt(0.5 *(Txx_o[i,j]^2 + Tyy_o[i,j]^2) + Txy_o[i,j]^2) + ε̇ii = sqrt(0.5 *( Exx[i,j]^2 + Eyy[i,j]^2) + Exy[i,j]^2) + args = (; τII_old = τii0, dt=dt, P=Pt[i,j]) + η_vep[i,j] = phase_viscosity(MatParam, ε̇ii, Phasec[i,j], args) + Txx[i,j] = 2*η_vep[i,j]*Exx[i,j] + Tyy[i,j] = 2*η_vep[i,j]*Eyy[i,j] + Txy[i,j] = 2*η_vep[i,j]*Exy[i,j] + Tii[i,j] = 2*η_vep[i,j]*ε̇ii # mostly for debugging + η_vep[i,j] = Txx[i,j]/2/Exx1[i,j] # should be same as native? + end + else + # trial stress + Txx .= 2.0.*η_ve.*Exx1 + Tyy .= 2.0.*η_ve.*Eyy1 + Txy .= 2.0.*η_ve.*Exy1 + Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) + # yield function + F .= Tii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(η_ve .+ η_reg) + dQdTxx .= 0.5.*Txx./Tii + dQdTyy .= 0.5.*Tyy./Tii + dQdTxy .= Txy./Tii + # plastic corrections + Txx .= 2.0.*η_ve.*(Exx1 .- λ.*dQdTxx) + Tyy .= 2.0.*η_ve.*(Eyy1 .- λ.*dQdTyy) + Txy .= 2.0.*η_ve.*(Exy1 .- 0.5.*λ.*dQdTxy) + Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) + Fchk .= Tii .- τ_y .- Pt.*sinϕ .- λ.*η_reg + η_vep .= Tii./2.0./Eii + end + Txyv[2:end-1,2:end-1].=av(Txy) # Txyv=0 on boundaries ! + # PT timestep + dtVx .= min(dx,dy)^2.0./av_xa(η_vep)./4.1./Vsc + dtVy .= min(dx,dy)^2.0./av_ya(η_vep)./4.1./Vsc + dtPt .= 4.1.*η_vep./max(nx,ny)./Ptsc + # velocities + Rx .= .-diff(Pt, dims=1)./dx .+ diff(Txx, dims=1)./dx .+ diff(Txyv[2:end-1,:], dims=2)./dy + Ry .= .-diff(Pt, dims=2)./dy .+ diff(Tyy, dims=2)./dy .+ diff(Txyv[:,2:end-1], dims=1)./dx .+ av_ya(Rog) + dVxdt .= dVxdt.*(1-Vdmp/nx) .+ Rx + dVydt .= dVydt.*(1-Vdmp/ny) .+ Ry + Vx[2:end-1,:] .= Vx[2:end-1,:] .+ dVxdt.*dtVx + Vy[:,2:end-1] .= Vy[:,2:end-1] .+ dVydt.*dtVy + # convergence check + if mod(iter, nout)==0 + norm_Rx = norm(Rx)/length(Rx); norm_Ry = norm(Ry)/length(Ry); norm_∇V = norm(∇V)/length(∇V) + err = maximum([norm_Rx, norm_Ry, norm_∇V]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %d, iter = %d, err = %1.2e norm[Rx=%1.2e, Ry=%1.2e, ∇V=%1.2e] (Fchk=%1.2e) \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V, maximum(Fchk)) + end + iter+=1; itg=iter + end + t = t + dt + push!(evo_t, t); push!(evo_Txx, maximum(Txx)) + # Plotting + p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") + # p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p2 = heatmap(xc, yc, η_vep' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="η_vep") + p3 = heatmap(xc, yc, Tii' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="τii") + p4 = plot(evo_t, evo_Txx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + plot!(evo_t, 2.0.*εbg.*μ0.*(1.0.-exp.(.-evo_t.*G0./μ0)), linewidth=2.0) # analytical solution for VE loading + plot!(evo_t, 2.0.*εbg.*μ0.*ones(size(evo_t)), linewidth=2.0) # viscous flow stress + if !do_DP plot!(evo_t, τ_y*ones(size(evo_t)), linewidth=2.0) end # von Mises yield stress + display(plot(p1, p2, p3, p4)) + end + return +end + + +# Stokes2D_vep(true) +Stokes2D_vep(false) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams.jl b/GeoParams_PT_examples/scripts/history/Stokes2D_VEP_inclusion_GeoParams.jl similarity index 100% rename from GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams.jl rename to GeoParams_PT_examples/scripts/history/Stokes2D_VEP_inclusion_GeoParams.jl diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v2.jl b/GeoParams_PT_examples/scripts/history/Stokes2D_VEP_inclusion_GeoParams_v2.jl similarity index 100% rename from GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v2.jl rename to GeoParams_PT_examples/scripts/history/Stokes2D_VEP_inclusion_GeoParams_v2.jl diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl b/GeoParams_PT_examples/scripts/history/Stokes2D_VEP_inclusion_GeoParams_v3.jl similarity index 98% rename from GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl rename to GeoParams_PT_examples/scripts/history/Stokes2D_VEP_inclusion_GeoParams_v3.jl index c603788..22416a2 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v3.jl +++ b/GeoParams_PT_examples/scripts/history/Stokes2D_VEP_inclusion_GeoParams_v3.jl @@ -208,14 +208,14 @@ end # Numerics nt = 20 # number of time steps - ncx, ncy = 31, 31 # numerical grid resolution - #ncx, ncy = 63, 63 # numerical grid resolution + # ncx, ncy = 31, 31 # numerical grid resolution + ncx, ncy = 63, 63 # numerical grid resolution ε = 1e-6 # nonlinear tolerence iterMax = 1e5 # max number of iters nout = 500 # check frequency # Iterative parameters ------------------------------------------- - Reopt = 5π + Reopt = 4π cfl = 0.50 ρ = cfl*Reopt/ncx # Preprocessing @@ -442,7 +442,7 @@ end for i=1:1 println("step $i") - doPlots = false + doPlots = true @time Stokes2D_VE_inclusion(false, doPlots) - @time Stokes2D_VE_inclusion(true, doPlots) + # @time Stokes2D_VE_inclusion(true, doPlots) end \ No newline at end of file diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v4.jl b/GeoParams_PT_examples/scripts/history/Stokes2D_VEP_inclusion_GeoParams_v4.jl similarity index 100% rename from GeoParams_PT_examples/scripts/Stokes2D_VEP_inclusion_GeoParams_v4.jl rename to GeoParams_PT_examples/scripts/history/Stokes2D_VEP_inclusion_GeoParams_v4.jl diff --git a/GeoParams_PT_examples/scripts/Stokes2D_vep_bench_GeoParams.jl b/GeoParams_PT_examples/scripts/history/Stokes2D_vep_bench_GeoParams.jl similarity index 100% rename from GeoParams_PT_examples/scripts/Stokes2D_vep_bench_GeoParams.jl rename to GeoParams_PT_examples/scripts/history/Stokes2D_vep_bench_GeoParams.jl diff --git a/GeoParams_PT_examples/scripts/Stokes2D_vep_reg_vc_GeoParams.jl b/GeoParams_PT_examples/scripts/history/Stokes2D_vep_reg_vc_GeoParams.jl similarity index 100% rename from GeoParams_PT_examples/scripts/Stokes2D_vep_reg_vc_GeoParams.jl rename to GeoParams_PT_examples/scripts/history/Stokes2D_vep_reg_vc_GeoParams.jl From cd83aa1ccde69e05eb2844202bf29b15fb3a50ca Mon Sep 17 00:00:00 2001 From: Duretz Thibault Date: Fri, 4 Nov 2022 08:16:27 +0100 Subject: [PATCH 25/49] 50 shades of VEP stag implementations started... --- .../Stokes2D_VEP_reg_ctau_inv_GeoParams.jl | 220 ++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl new file mode 100644 index 0000000..aa64dc7 --- /dev/null +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl @@ -0,0 +1,220 @@ +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra, GeoParams +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av2(A) = 0.25*(A[1:end-1,1:end-1].^2 .+ A[2:end,1:end-1].^2 .+ A[1:end-1,2:end].^2 .+ A[2:end,2:end].^2) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +# 2D Stokes routine +@views function Stokes2D_vep(UseGeoParams) + pl_correction = :native_naïve + pl_correction = :native_inv1 + do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) + η_reg = 8.0e-3 # regularisation "viscosity" + # Physics + Lx, Ly = 1.0, 1.0 # domain size + radi = 0.01 # inclusion radius + τ_y = 1.6 # yield stress. If do_DP=true, τ_y stand for the cohesion: c*cos(ϕ) + ϕ = 30.0 + sinϕ = sind(ϕ)*do_DP # sinus of the friction angle + μ0 = 1.0 # viscous viscosity + G0 = 1.0 # elastic shear modulus + Gi = G0/(6.0-4.0*do_DP) # elastic shear modulus perturbation + εbg = 1.0 # background strain-rate + Coh = τ_y/cosd(ϕ) # cohesion + # Geoparams initialisation + pl = DruckerPrager_regularised(C=Coh, ϕ=ϕ, η_vp=η_reg) # non-regularized plasticity + MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, + CompositeRheology = CompositeRheology(ConstantElasticity(G=G0),LinearViscous(η=μ0),pl)), + SetMaterialParams(Name="Inclusion", Phase=2, + CompositeRheology = CompositeRheology(ConstantElasticity(G=Gi),LinearViscous(η=μ0),pl)), + ) + # Numerics + nt = 10 # number of time steps + nx, ny = 63, 63 # numerical grid resolution + Vdmp = 4.0 # convergence acceleration (damping) + Vsc = 2.0 # iterative time step limiter + Ptsc = 6.0 # iterative time step limiter + ε = 1e-6 # nonlinear tolerence + iterMax = 3e4 # max number of iters + nout = 200 # check frequency + # Preprocessing + dx, dy = Lx/nx, Ly/ny + dt = μ0/G0/4.0 # assumes Maxwell time of 4 + # Array initialisation + Pt = zeros(Dat, nx ,ny ) + ∇V = zeros(Dat, nx ,ny ) + Vx = zeros(Dat, nx+1,ny ) + Vy = zeros(Dat, nx ,ny+1) + Exx = zeros(Dat, nx ,ny ) + Eyy = zeros(Dat, nx ,ny ) + Exy = zeros(Dat, nx ,ny ) + Exyv = zeros(Dat, nx+1,ny+1) + Exx1 = zeros(Dat, nx ,ny ) + Eyy1 = zeros(Dat, nx ,ny ) + Exy1 = zeros(Dat, nx ,ny ) + Exyv1 = zeros(Dat, nx+1,ny+1) + Txx = zeros(Dat, nx ,ny ) + Tyy = zeros(Dat, nx ,ny ) + Txy = zeros(Dat, nx ,ny ) + Txyv = zeros(Dat, nx+1,ny+1) + Txx_o = zeros(Dat, nx ,ny ) + Tii_o = zeros(Dat, nx ,ny ) + Tyy_o = zeros(Dat, nx ,ny ) + Txy_o = zeros(Dat, nx ,ny ) + Txyv_o = zeros(Dat, nx+1,ny+1) + Tii = zeros(Dat, nx ,ny ) + Eii = zeros(Dat, nx ,ny ) + F = zeros(Dat, nx ,ny ) + Fchk = zeros(Dat, nx ,ny ) + Pla = zeros(Dat, nx ,ny ) + λ = zeros(Dat, nx ,ny ) + dQdTxx = zeros(Dat, nx ,ny ) + dQdTyy = zeros(Dat, nx ,ny ) + dQdTxy = zeros(Dat, nx ,ny ) + Rx = zeros(Dat, nx-1,ny ) + Ry = zeros(Dat, nx ,ny-1) + dVxdt = zeros(Dat, nx-1,ny ) + dVydt = zeros(Dat, nx ,ny-1) + dtPt = zeros(Dat, nx ,ny ) + dtVx = zeros(Dat, nx-1,ny ) + dtVy = zeros(Dat, nx ,ny-1) + Rog = zeros(Dat, nx ,ny ) + η_v = μ0*ones(Dat, nx, ny) + η_e = dt*G0*ones(Dat, nx, ny) + η_ev = dt*G0*ones(Dat, nx+1, ny+1) + η_ve = ones(Dat, nx, ny) + η_vep = ones(Dat, nx, ny) + η_vepv = ones(Dat, nx+1, ny+1) + Phasec = ones(Int, nx ,ny ) + # Initial condition + xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) + xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) + xv, yv = LinRange(0.0, Lx, nx+1), LinRange(0.0, Ly, ny+1) + (Xvx,Yvx) = ([x for x=xv,y=yc], [y for x=xv,y=yc]) + (Xvy,Yvy) = ([x for x=xc,y=yv], [y for x=xc,y=yv]) + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + η_e[radc.ε && iter<=iterMax) + # divergence - pressure + ∇V .= diff(Vx, dims=1)./dx .+ diff(Vy, dims=2)./dy + Pt .= Pt .- dtPt.*∇V + # strain rates + Exx .= diff(Vx, dims=1)./dx .- 1.0/3.0*∇V + Eyy .= diff(Vy, dims=2)./dy .- 1.0/3.0*∇V + Exyv[2:end-1,2:end-1] .= 0.5.*(diff(Vx[2:end-1,:], dims=2)./dy .+ diff(Vy[:,2:end-1], dims=1)./dx) + Exy .= av(Exyv) + # visco-elastic strain rates + Exx1 .= Exx .+ Txx_o ./2.0./η_e + Eyy1 .= Eyy .+ Tyy_o ./2.0./η_e + Exy1 .= Exy .+ Txy_o ./2.0./η_e # like this? + Exyv1 .= Exyv .+ Txyv_o ./2.0./η_ev + Exy1 .= av(Exyv1) # or like that? + # if UseGeoParams + # @inbounds for j ∈ axes(Exx,2), i ∈ axes(Exx,1) + # # compute second invariants from surrounding points + # τii0 = sqrt(0.5 *(Txx_o[i,j]^2 + Tyy_o[i,j]^2) + Txy_o[i,j]^2) + # ε̇ii = sqrt(0.5 *( Exx[i,j]^2 + Eyy[i,j]^2) + Exy[i,j]^2) + # args = (; τII_old = τii0, dt=dt, P=Pt[i,j]) + # η_vep[i,j] = phase_viscosity(MatParam, ε̇ii, Phasec[i,j], args) + # Txx[i,j] = 2*η_vep[i,j]*Exx[i,j] + # Tyy[i,j] = 2*η_vep[i,j]*Eyy[i,j] + # Txy[i,j] = 2*η_vep[i,j]*Exy[i,j] + # Tii[i,j] = 2*η_vep[i,j]*ε̇ii # mostly for debugging + # η_vep[i,j] = Txx[i,j]/2/Exx1[i,j] # should be same as native? + # end + if pl_correction == :native_naïve + # Effective strain rate invariant + Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ Exy1.^2) + # trial stress + Txx .= 2.0.*η_ve.*Exx1 + Tyy .= 2.0.*η_ve.*Eyy1 + Txy .= 2.0.*η_ve.*Exy1 + Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) + # yield function + F .= Tii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(η_ve .+ η_reg) + dQdTxx .= 0.5.*Txx./Tii + dQdTyy .= 0.5.*Tyy./Tii + dQdTxy .= Txy./Tii + # plastic corrections + Txx .= 2.0.*η_ve.*(Exx1 .- λ.*dQdTxx) + Tyy .= 2.0.*η_ve.*(Eyy1 .- λ.*dQdTyy) + Txy .= 2.0.*η_ve.*(Exy1 .- 0.5.*λ.*dQdTxy) + Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) + Fchk .= Tii .- τ_y .- Pt.*sinϕ .- λ.*η_reg + η_vep .= Tii./2.0./Eii + elseif pl_correction == :native_inv1 + # trial stress + Txx .= 2.0.*η_ve.*Exx1 + Tyy .= 2.0.*η_ve.*Eyy1 + Txy .= 2.0.*η_ve.*Exy1 + # Effective strain rate invariant + Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ Exy1.^2) + Tii .= 2.0.*η_ve.*Eii + # yield function + F .= Tii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(η_ve .+ η_reg) + Fchk .= (Tii .- η_ve.*λ) .- τ_y .- Pt.*sinϕ .- λ.*η_reg + Txx .= 2.0.*η_ve.*(Exx1 .- 0.5.*λ.*Txx./Tii) + Tyy .= 2.0.*η_ve.*(Eyy1 .- 0.5.*λ.*Txx./Tii) + Txy .= 2.0.*η_ve.*(Exy1 .- 0.5.*λ.*Txy./Tii) # Here we need the component for centroid update + η_vep .= Tii./2.0./Eii + end + Txyv[2:end-1,2:end-1].=av(Txy) # Txyv=0 on boundaries ! + # PT timestep + dtVx .= min(dx,dy)^2.0./av_xa(η_vep)./4.1./Vsc + dtVy .= min(dx,dy)^2.0./av_ya(η_vep)./4.1./Vsc + dtPt .= 4.1.*η_vep./max(nx,ny)./Ptsc + # velocities + Rx .= .-diff(Pt, dims=1)./dx .+ diff(Txx, dims=1)./dx .+ diff(Txyv[2:end-1,:], dims=2)./dy + Ry .= .-diff(Pt, dims=2)./dy .+ diff(Tyy, dims=2)./dy .+ diff(Txyv[:,2:end-1], dims=1)./dx .+ av_ya(Rog) + dVxdt .= dVxdt.*(1-Vdmp/nx) .+ Rx + dVydt .= dVydt.*(1-Vdmp/ny) .+ Ry + Vx[2:end-1,:] .= Vx[2:end-1,:] .+ dVxdt.*dtVx + Vy[:,2:end-1] .= Vy[:,2:end-1] .+ dVydt.*dtVy + # convergence check + if mod(iter, nout)==0 + norm_Rx = norm(Rx)/length(Rx); norm_Ry = norm(Ry)/length(Ry); norm_∇V = norm(∇V)/length(∇V) + err = maximum([norm_Rx, norm_Ry, norm_∇V]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %d, iter = %d, err = %1.2e norm[Rx=%1.2e, Ry=%1.2e, ∇V=%1.2e] (Fchk=%1.2e) \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V, maximum(Fchk)) + end + iter+=1; itg=iter + end + t = t + dt + push!(evo_t, t); push!(evo_Txx, maximum(Txx)) + # Plotting + p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") + # p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p2 = heatmap(xc, yc, η_vep' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="η_vep") + p3 = heatmap(xc, yc, Tii' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="τii") + p4 = plot(evo_t, evo_Txx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + plot!(evo_t, 2.0.*εbg.*μ0.*(1.0.-exp.(.-evo_t.*G0./μ0)), linewidth=2.0) # analytical solution for VE loading + plot!(evo_t, 2.0.*εbg.*μ0.*ones(size(evo_t)), linewidth=2.0) # viscous flow stress + if !do_DP plot!(evo_t, τ_y*ones(size(evo_t)), linewidth=2.0) end # von Mises yield stress + display(plot(p1, p2, p3, p4)) + end + return +end + + +# Stokes2D_vep(true) +Stokes2D_vep(false) From a8f5248e363479f20e21e4fc7b9db37aac5b2055 Mon Sep 17 00:00:00 2001 From: Boris Kaus Date: Fri, 4 Nov 2022 08:40:49 +0100 Subject: [PATCH 26/49] adding another shade & correcting bug --- .../Stokes2D_VEP_reg_ctau_inv_GeoParams.jl | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl index aa64dc7..8248276 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl @@ -10,6 +10,8 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) @views function Stokes2D_vep(UseGeoParams) pl_correction = :native_naïve pl_correction = :native_inv1 + pl_correction = :native_inv2 + do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) η_reg = 8.0e-3 # regularisation "viscosity" # Physics @@ -82,9 +84,11 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) dtVy = zeros(Dat, nx ,ny-1) Rog = zeros(Dat, nx ,ny ) η_v = μ0*ones(Dat, nx, ny) + η_vv = μ0*ones(Dat, nx+1, ny+1) η_e = dt*G0*ones(Dat, nx, ny) η_ev = dt*G0*ones(Dat, nx+1, ny+1) η_ve = ones(Dat, nx, ny) + η_vev = ones(Dat, nx+1, ny+1) η_vep = ones(Dat, nx, ny) η_vepv = ones(Dat, nx+1, ny+1) Phasec = ones(Int, nx ,ny ) @@ -100,6 +104,7 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) η_ev[radv. 0.0 λ .= Pla.*F./(η_ve .+ η_reg) - Fchk .= (Tii .- η_ve.*λ) .- τ_y .- Pt.*sinϕ .- λ.*η_reg + Fchk .= (Tii .- η_ve.*λ) .- τ_y .- Pt.*sinϕ .- λ.*η_reg Txx .= 2.0.*η_ve.*(Exx1 .- 0.5.*λ.*Txx./Tii) - Tyy .= 2.0.*η_ve.*(Eyy1 .- 0.5.*λ.*Txx./Tii) + Tyy .= 2.0.*η_ve.*(Eyy1 .- 0.5.*λ.*Tyy./Tii) Txy .= 2.0.*η_ve.*(Exy1 .- 0.5.*λ.*Txy./Tii) # Here we need the component for centroid update + Tii .= Tii .- η_ve.*λ + η_vep .= Tii./2.0./Eii + + elseif pl_correction == :native_inv2 + # trial stress + Txx .= 2.0.*η_ve.*Exx1 + Tyy .= 2.0.*η_ve.*Eyy1 + Txyv .= 2.0.*η_vev.*Exyv1 + Txy .= av(Txyv) + # Invariants + Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ av(Exyv1.^2)) + Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ av(Txyv.^2)) + # yield function + F .= Tii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(η_ve .+ η_reg) + Fchk .= (Tii .- η_ve.*λ) .- τ_y .- Pt.*sinϕ .- λ.*η_reg + Txx .= Txx .- η_ve.*λ.*Txx./Tii + Tyy .= Tyy .- η_ve.*λ.*Tyy./Tii + Txy .= Txy .- η_ve.*λ.*Txy./Tii # Here we need the component for centroid update + Tii .= Tii .- η_ve.*λ η_vep .= Tii./2.0./Eii end Txyv[2:end-1,2:end-1].=av(Txy) # Txyv=0 on boundaries ! From 682e12559c4cebbf054c1922c05b1b1fbda81bf8 Mon Sep 17 00:00:00 2001 From: Boris Kaus Date: Fri, 4 Nov 2022 09:10:38 +0100 Subject: [PATCH 27/49] another shade --- .../Stokes2D_VEP_reg_ctau_inv_GeoParams.jl | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl index 8248276..f871b0f 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl @@ -11,6 +11,7 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) pl_correction = :native_naïve pl_correction = :native_inv1 pl_correction = :native_inv2 + pl_correction = :native_inv3 do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) η_reg = 8.0e-3 # regularisation "viscosity" @@ -68,6 +69,7 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) Txyv_o = zeros(Dat, nx+1,ny+1) Tii = zeros(Dat, nx ,ny ) Eii = zeros(Dat, nx ,ny ) + Eii_f = zeros(Dat, nx ,ny ) F = zeros(Dat, nx ,ny ) Fchk = zeros(Dat, nx ,ny ) Pla = zeros(Dat, nx ,ny ) @@ -91,6 +93,7 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) η_vev = ones(Dat, nx+1, ny+1) η_vep = ones(Dat, nx, ny) η_vepv = ones(Dat, nx+1, ny+1) + ηc = ones(Dat,nx,ny) Phasec = ones(Int, nx ,ny ) # Initial condition xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) @@ -204,8 +207,26 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) Txy .= Txy .- η_ve.*λ.*Txy./Tii # Here we need the component for centroid update Tii .= Tii .- η_ve.*λ η_vep .= Tii./2.0./Eii + + elseif pl_correction == :native_inv3 + # Invariants + Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ av(Exyv1.^2)) + Tii .= 2.0.*η_ve.*Eii + + # yield function + F .= Tii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(η_ve .+ η_reg) + Tii .= Tii .- η_ve.*λ # correct invariant + Fchk .= Tii .- τ_y .- Pt.*sinϕ .- λ.*η_reg + + η_vep .= Tii./2.0./Eii + Txx .= 2*η_vep.*Exx1 + Tyy .= 2*η_vep.*Eyy1 + Txy .= 2*η_vep.*Exy1 end - Txyv[2:end-1,2:end-1].=av(Txy) # Txyv=0 on boundaries ! + Txyv[2:end-1,2:end-1].=av(Txy) # Txyv=0 on boundaries ! # PT timestep dtVx .= min(dx,dy)^2.0./av_xa(η_vep)./4.1./Vsc dtVy .= min(dx,dy)^2.0./av_ya(η_vep)./4.1./Vsc From eac103fafa66071f214bab4943af5835008f747a Mon Sep 17 00:00:00 2001 From: albert-de-montserrat Date: Mon, 7 Nov 2022 15:47:43 +0100 Subject: [PATCH 28/49] centers version with GP (branch #adm-tuples) --- .../Stokes2D_VEP_reg_ctau_inv_GeoParams.jl | 230 ++++++++++-------- 1 file changed, 123 insertions(+), 107 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl index f871b0f..1f8248b 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl @@ -1,17 +1,31 @@ # Initialisation using Plots, Printf, Statistics, LinearAlgebra, GeoParams -Dat = Float64 # Precision (double=Float64 or single=Float32) +const Dat = Float64 # Precision (double=Float64 or single=Float32) # Macros @views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) @views av2(A) = 0.25*(A[1:end-1,1:end-1].^2 .+ A[2:end,1:end-1].^2 .+ A[1:end-1,2:end].^2 .+ A[2:end,2:end].^2) @views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) @views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) + +function update_stress_GP!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txy_o, Exx, Eyy, Exy, η_vep, Pt, Phasec, MatParam, dt) + @inbounds for j ∈ axes(Exx,2), i ∈ axes(Exx,1) + # compute second invariants from surrounding points + args = (; dt=dt, P=Pt[i,j]) + εij = (Exx[i,j], Eyy[i,j], Exy[i,j]) + τij_o = (Txx_o[i,j], Tyy_o[i,j], Txy_o[i,j]) + Tij, Tii[i,j], η_vep[i,j] = compute_τij(MatParam, εij, args, τij_o, Phasec[i,j]) + Txx[i,j] = Tij[1] + Tyy[i,j] = Tij[2] + Txy[i,j] = Tij[3] + end +end + # 2D Stokes routine -@views function Stokes2D_vep(UseGeoParams) - pl_correction = :native_naïve - pl_correction = :native_inv1 - pl_correction = :native_inv2 - pl_correction = :native_inv3 +function Stokes2D_vep(UseGeoParams, nt) + pl_correction = :native_naive + # pl_correction = :native_inv1 + # pl_correction = :native_inv2 + # pl_correction = :native_inv3 do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) η_reg = 8.0e-3 # regularisation "viscosity" @@ -26,6 +40,7 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) Gi = G0/(6.0-4.0*do_DP) # elastic shear modulus perturbation εbg = 1.0 # background strain-rate Coh = τ_y/cosd(ϕ) # cohesion + # Coh = Inf # Geoparams initialisation pl = DruckerPrager_regularised(C=Coh, ϕ=ϕ, η_vp=η_reg) # non-regularized plasticity MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, @@ -34,7 +49,7 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) CompositeRheology = CompositeRheology(ConstantElasticity(G=Gi),LinearViscous(η=μ0),pl)), ) # Numerics - nt = 10 # number of time steps + # nt = 10 # number of time steps nx, ny = 63, 63 # numerical grid resolution Vdmp = 4.0 # convergence acceleration (damping) Vsc = 2.0 # iterative time step limiter @@ -111,9 +126,9 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) Vx .= εbg.*Xvx Vy .= .-εbg.*Yvy # Time loop - t=0.0; evo_t=[]; evo_Txx=[] + t=0.0; evo_t=Float64[]; evo_Txx=Float64[] for it = 1:nt - iter=1; err=2*ε; err_evo1=[]; err_evo2=[] + iter=1; err=2*ε; err_evo1=Float64[]; err_evo2=Float64[] Txx_o.=Txx; Tyy_o.=Tyy; Txy_o.=av(Txyv); Txyv_o.=Txyv; λ.=0.0 local itg while (err>ε && iter<=iterMax) @@ -131,100 +146,102 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) Exy1 .= Exy .+ Txy_o ./2.0./η_e # like this? Exyv1 .= Exyv .+ Txyv_o ./2.0./η_ev Exy1 .= av(Exyv1) # or like that? - # if UseGeoParams - # @inbounds for j ∈ axes(Exx,2), i ∈ axes(Exx,1) - # # compute second invariants from surrounding points - # τii0 = sqrt(0.5 *(Txx_o[i,j]^2 + Tyy_o[i,j]^2) + Txy_o[i,j]^2) - # ε̇ii = sqrt(0.5 *( Exx[i,j]^2 + Eyy[i,j]^2) + Exy[i,j]^2) - # args = (; τII_old = τii0, dt=dt, P=Pt[i,j]) - # η_vep[i,j] = phase_viscosity(MatParam, ε̇ii, Phasec[i,j], args) - # Txx[i,j] = 2*η_vep[i,j]*Exx[i,j] - # Tyy[i,j] = 2*η_vep[i,j]*Eyy[i,j] - # Txy[i,j] = 2*η_vep[i,j]*Exy[i,j] - # Tii[i,j] = 2*η_vep[i,j]*ε̇ii # mostly for debugging - # η_vep[i,j] = Txx[i,j]/2/Exx1[i,j] # should be same as native? - # end - if pl_correction == :native_naïve - # Effective strain rate invariant - Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ Exy1.^2) - # trial stress - Txx .= 2.0.*η_ve.*Exx1 - Tyy .= 2.0.*η_ve.*Eyy1 - Txy .= 2.0.*η_ve.*Exy1 - Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) - # yield function - F .= Tii .- τ_y .- Pt.*sinϕ - Pla .= 0.0 - Pla .= F .> 0.0 - λ .= Pla.*F./(η_ve .+ η_reg) - dQdTxx .= 0.5.*Txx./Tii - dQdTyy .= 0.5.*Tyy./Tii - dQdTxy .= Txy./Tii - # plastic corrections - Txx .= 2.0.*η_ve.*(Exx1 .- λ.*dQdTxx) - Tyy .= 2.0.*η_ve.*(Eyy1 .- λ.*dQdTyy) - Txy .= 2.0.*η_ve.*(Exy1 .- 0.5.*λ.*dQdTxy) - Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) - Fchk .= Tii .- τ_y .- Pt.*sinϕ .- λ.*η_reg - η_vep .= Tii./2.0./Eii - elseif pl_correction == :native_inv1 - # trial stress - Txx .= 2.0.*η_ve.*Exx1 - Tyy .= 2.0.*η_ve.*Eyy1 - Txy .= 2.0.*η_ve.*Exy1 - # Effective strain rate invariant - Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ Exy1.^2) - Tii .= 2.0.*η_ve.*Eii - # yield function - F .= Tii .- τ_y .- Pt.*sinϕ - Pla .= 0.0 - Pla .= F .> 0.0 - λ .= Pla.*F./(η_ve .+ η_reg) - Fchk .= (Tii .- η_ve.*λ) .- τ_y .- Pt.*sinϕ .- λ.*η_reg - Txx .= 2.0.*η_ve.*(Exx1 .- 0.5.*λ.*Txx./Tii) - Tyy .= 2.0.*η_ve.*(Eyy1 .- 0.5.*λ.*Tyy./Tii) - Txy .= 2.0.*η_ve.*(Exy1 .- 0.5.*λ.*Txy./Tii) # Here we need the component for centroid update - Tii .= Tii .- η_ve.*λ - η_vep .= Tii./2.0./Eii - - elseif pl_correction == :native_inv2 - # trial stress - Txx .= 2.0.*η_ve.*Exx1 - Tyy .= 2.0.*η_ve.*Eyy1 - Txyv .= 2.0.*η_vev.*Exyv1 - Txy .= av(Txyv) - # Invariants - Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ av(Exyv1.^2)) - Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ av(Txyv.^2)) - # yield function - F .= Tii .- τ_y .- Pt.*sinϕ - Pla .= 0.0 - Pla .= F .> 0.0 - λ .= Pla.*F./(η_ve .+ η_reg) - Fchk .= (Tii .- η_ve.*λ) .- τ_y .- Pt.*sinϕ .- λ.*η_reg - Txx .= Txx .- η_ve.*λ.*Txx./Tii - Tyy .= Tyy .- η_ve.*λ.*Tyy./Tii - Txy .= Txy .- η_ve.*λ.*Txy./Tii # Here we need the component for centroid update - Tii .= Tii .- η_ve.*λ - η_vep .= Tii./2.0./Eii - - elseif pl_correction == :native_inv3 - # Invariants - Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ av(Exyv1.^2)) - Tii .= 2.0.*η_ve.*Eii - - # yield function - F .= Tii .- τ_y .- Pt.*sinϕ - Pla .= 0.0 - Pla .= F .> 0.0 - λ .= Pla.*F./(η_ve .+ η_reg) - Tii .= Tii .- η_ve.*λ # correct invariant - Fchk .= Tii .- τ_y .- Pt.*sinϕ .- λ.*η_reg - - η_vep .= Tii./2.0./Eii - Txx .= 2*η_vep.*Exx1 - Tyy .= 2*η_vep.*Eyy1 - Txy .= 2*η_vep.*Exy1 + if UseGeoParams + update_stress_GP!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txy_o, Exx, Eyy, Exy, η_vep, Pt, Phasec, MatParam, dt) + # @inbounds for j ∈ axes(Exx,2), i ∈ axes(Exx,1) + # # compute second invariants from surrounding points + # args = (; dt=dt, P=Pt[i,j]) + # εij = (Exx[i,j], Eyy[i,j], Exy[i,j]) + # τij_o = (Txx_o[i,j], Tyy_o[i,j], Txy_o[i,j]) + # Tij, Tii[i,j], η_vep[i,j] = compute_τij(MatParam, εij, args, τij_o, Phasec[i,j]) + # Txx[i,j] = Tij[1] + # Tyy[i,j] = Tij[2] + # Txy[i,j] = Tij[3] + # # η_vep[i,j] = Txx[i,j]/2/Exx1[i,j] # should be same as native? + # end + else + if pl_correction == :native_naive + # Effective strain rate invariant + Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ Exy1.^2) + # trial stress + Txx .= 2.0.*η_ve.*Exx1 + Tyy .= 2.0.*η_ve.*Eyy1 + Txy .= 2.0.*η_ve.*Exy1 + Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) + # yield function + F .= Tii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(η_ve .+ η_reg) + dQdTxx .= 0.5.*Txx./Tii + dQdTyy .= 0.5.*Tyy./Tii + dQdTxy .= Txy./Tii + # plastic corrections + Txx .= 2.0.*η_ve.*(Exx1 .- λ.*dQdTxx) + Tyy .= 2.0.*η_ve.*(Eyy1 .- λ.*dQdTyy) + Txy .= 2.0.*η_ve.*(Exy1 .- 0.5.*λ.*dQdTxy) + Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) + Fchk .= Tii .- τ_y .- Pt.*sinϕ .- λ.*η_reg + η_vep .= Tii./2.0./Eii + elseif pl_correction == :native_inv1 + # trial stress + Txx .= 2.0.*η_ve.*Exx1 + Tyy .= 2.0.*η_ve.*Eyy1 + Txy .= 2.0.*η_ve.*Exy1 + # Effective strain rate invariant + Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ Exy1.^2) + Tii .= 2.0.*η_ve.*Eii + # yield function + F .= Tii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(η_ve .+ η_reg) + Fchk .= (Tii .- η_ve.*λ) .- τ_y .- Pt.*sinϕ .- λ.*η_reg + Txx .= 2.0.*η_ve.*(Exx1 .- 0.5.*λ.*Txx./Tii) + Tyy .= 2.0.*η_ve.*(Eyy1 .- 0.5.*λ.*Tyy./Tii) + Txy .= 2.0.*η_ve.*(Exy1 .- 0.5.*λ.*Txy./Tii) # Here we need the component for centroid update + Tii .= Tii .- η_ve.*λ + η_vep .= Tii./2.0./Eii + + elseif pl_correction == :native_inv2 + # trial stress + Txx .= 2.0.*η_ve.*Exx1 + Tyy .= 2.0.*η_ve.*Eyy1 + Txyv .= 2.0.*η_vev.*Exyv1 + Txy .= av(Txyv) + # Invariants + Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ av(Exyv1.^2)) + Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ av(Txyv.^2)) + # yield function + F .= Tii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(η_ve .+ η_reg) + Fchk .= (Tii .- η_ve.*λ) .- τ_y .- Pt.*sinϕ .- λ.*η_reg + Txx .= Txx .- η_ve.*λ.*Txx./Tii + Tyy .= Tyy .- η_ve.*λ.*Tyy./Tii + Txy .= Txy .- η_ve.*λ.*Txy./Tii # Here we need the component for centroid update + Tii .= Tii .- η_ve.*λ + η_vep .= Tii./2.0./Eii + + elseif pl_correction == :native_inv3 + # Invariants + Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ av(Exyv1.^2)) + Tii .= 2.0.*η_ve.*Eii + + # yield function + F .= Tii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(η_ve .+ η_reg) + Tii .= Tii .- η_ve.*λ # correct invariant + Fchk .= Tii .- τ_y .- Pt.*sinϕ .- λ.*η_reg + + η_vep .= Tii./2.0./Eii + Txx .= 2*η_vep.*Exx1 + Tyy .= 2*η_vep.*Eyy1 + Txy .= 2*η_vep.*Exy1 + end end Txyv[2:end-1,2:end-1].=av(Txy) # Txyv=0 on boundaries ! # PT timestep @@ -260,9 +277,8 @@ Dat = Float64 # Precision (double=Float64 or single=Float32) if !do_DP plot!(evo_t, τ_y*ones(size(evo_t)), linewidth=2.0) end # von Mises yield stress display(plot(p1, p2, p3, p4)) end - return + return evo_t, evo_Txx end - -# Stokes2D_vep(true) -Stokes2D_vep(false) +@time evo_t, evo_Txx = Stokes2D_vep(false, 10) # 2nd argument = timesteps 7.311026 seconds (2.91 M allocations: 16.403 GiB, 16.54% gc time) +@time evo_t, evo_Txx_GP = Stokes2D_vep(true, 10) # 2nd argument = timesteps 9.368483 seconds (2.73 M allocations: 13.804 GiB, 8.24% gc time) \ No newline at end of file From 567ea29762d7df3c98138768267f10c77a2c4311 Mon Sep 17 00:00:00 2001 From: albert-de-montserrat Date: Tue, 8 Nov 2022 14:53:48 +0100 Subject: [PATCH 29/49] vertex->center shade with GP (bug somewhere) --- .../Stokes2D_VEP_reg_ctau_inv_GeoParams.jl | 240 +++++++++++------- 1 file changed, 144 insertions(+), 96 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl index 1f8248b..97c683d 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl @@ -1,5 +1,5 @@ # Initialisation -using Plots, Printf, Statistics, LinearAlgebra, GeoParams +using Plots, Printf, Statistics, LinearAlgebra, GeoParams, TimerOutputs const Dat = Float64 # Precision (double=Float64 or single=Float32) # Macros @views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) @@ -8,9 +8,9 @@ const Dat = Float64 # Precision (double=Float64 or single=Float32) @views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) function update_stress_GP!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txy_o, Exx, Eyy, Exy, η_vep, Pt, Phasec, MatParam, dt) - @inbounds for j ∈ axes(Exx,2), i ∈ axes(Exx,1) + @inbounds for j in axes(Exx,2), i in axes(Exx,1) # compute second invariants from surrounding points - args = (; dt=dt, P=Pt[i,j]) + args = (; dt=dt, P=Pt[i,j], τII_old=0.0) εij = (Exx[i,j], Eyy[i,j], Exy[i,j]) τij_o = (Txx_o[i,j], Tyy_o[i,j], Txy_o[i,j]) Tij, Tii[i,j], η_vep[i,j] = compute_τij(MatParam, εij, args, τij_o, Phasec[i,j]) @@ -20,8 +20,28 @@ function update_stress_GP!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txy_o, Exx, Eyy, Ex end end +function update_stress_GP2!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, Exyv, η_vep, Pt, Phasec, Phasev, MatParam, dt) + @inbounds for j in axes(Exx,2), i in axes(Exx,1) + args = (; dt=dt, P=Pt[i,j], τII_old=0.0) + # gather strain rate + εij_v = (Exyv[i,j], Exyv[i+1,j], Exyv[i+1,j], Exyv[i,j+1]) # gather vertices around ij center + εij_p = (Exx[i,j], Eyy[i,j], εij_v) + # gather deviatoric stress + τij_v = (Txyv_o[i,j], Txyv_o[i+1,j], Txyv_o[i+1,j], Txyv_o[i,j+1]) # gather vertices around ij center + τij_p_o = (Txx_o[i,j], Tyy_o[i,j], τij_v) + # gathermaterial phases + phases_v = (Phasev[i,j], Phasev[i+1,j], Phasev[i+1,j], Phasev[i,j+1]) # gather vertices around ij center + phases = (Phasec[i,j], Phasec[i,j], phases_v) + # update stress and effective viscosity + Tij, Tii[i,j], η_vep[i,j] = compute_τij(MatParam, εij_p, args, τij_p_o, phases) + Txx[i,j] = Tij[1] + Tyy[i,j] = Tij[2] + Txy[i,j] = Tij[3] + end +end + # 2D Stokes routine -function Stokes2D_vep(UseGeoParams, nt) +@views function Stokes2D_vep(UseGeoParams, nt) pl_correction = :native_naive # pl_correction = :native_inv1 # pl_correction = :native_inv2 @@ -110,6 +130,7 @@ function Stokes2D_vep(UseGeoParams, nt) η_vepv = ones(Dat, nx+1, ny+1) ηc = ones(Dat,nx,ny) Phasec = ones(Int, nx ,ny ) + Phasev = ones(Int, nx+1,ny+1) # Initial condition xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) @@ -121,12 +142,14 @@ function Stokes2D_vep(UseGeoParams, nt) η_e[radc. 0.0 - λ .= Pla.*F./(η_ve .+ η_reg) - dQdTxx .= 0.5.*Txx./Tii - dQdTyy .= 0.5.*Tyy./Tii - dQdTxy .= Txy./Tii - # plastic corrections - Txx .= 2.0.*η_ve.*(Exx1 .- λ.*dQdTxx) - Tyy .= 2.0.*η_ve.*(Eyy1 .- λ.*dQdTyy) - Txy .= 2.0.*η_ve.*(Exy1 .- 0.5.*λ.*dQdTxy) - Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) - Fchk .= Tii .- τ_y .- Pt.*sinϕ .- λ.*η_reg - η_vep .= Tii./2.0./Eii - elseif pl_correction == :native_inv1 - # trial stress - Txx .= 2.0.*η_ve.*Exx1 - Tyy .= 2.0.*η_ve.*Eyy1 - Txy .= 2.0.*η_ve.*Exy1 - # Effective strain rate invariant - Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ Exy1.^2) - Tii .= 2.0.*η_ve.*Eii - # yield function - F .= Tii .- τ_y .- Pt.*sinϕ - Pla .= 0.0 - Pla .= F .> 0.0 - λ .= Pla.*F./(η_ve .+ η_reg) - Fchk .= (Tii .- η_ve.*λ) .- τ_y .- Pt.*sinϕ .- λ.*η_reg - Txx .= 2.0.*η_ve.*(Exx1 .- 0.5.*λ.*Txx./Tii) - Tyy .= 2.0.*η_ve.*(Eyy1 .- 0.5.*λ.*Tyy./Tii) - Txy .= 2.0.*η_ve.*(Exy1 .- 0.5.*λ.*Txy./Tii) # Here we need the component for centroid update - Tii .= Tii .- η_ve.*λ - η_vep .= Tii./2.0./Eii - - elseif pl_correction == :native_inv2 - # trial stress - Txx .= 2.0.*η_ve.*Exx1 - Tyy .= 2.0.*η_ve.*Eyy1 - Txyv .= 2.0.*η_vev.*Exyv1 - Txy .= av(Txyv) - # Invariants - Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ av(Exyv1.^2)) - Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ av(Txyv.^2)) - # yield function - F .= Tii .- τ_y .- Pt.*sinϕ - Pla .= 0.0 - Pla .= F .> 0.0 - λ .= Pla.*F./(η_ve .+ η_reg) - Fchk .= (Tii .- η_ve.*λ) .- τ_y .- Pt.*sinϕ .- λ.*η_reg - Txx .= Txx .- η_ve.*λ.*Txx./Tii - Tyy .= Tyy .- η_ve.*λ.*Tyy./Tii - Txy .= Txy .- η_ve.*λ.*Txy./Tii # Here we need the component for centroid update - Tii .= Tii .- η_ve.*λ - η_vep .= Tii./2.0./Eii - - elseif pl_correction == :native_inv3 - # Invariants - Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ av(Exyv1.^2)) - Tii .= 2.0.*η_ve.*Eii - - # yield function - F .= Tii .- τ_y .- Pt.*sinϕ - Pla .= 0.0 - Pla .= F .> 0.0 - λ .= Pla.*F./(η_ve .+ η_reg) - Tii .= Tii .- η_ve.*λ # correct invariant - Fchk .= Tii .- τ_y .- Pt.*sinϕ .- λ.*η_reg - - η_vep .= Tii./2.0./Eii - Txx .= 2*η_vep.*Exx1 - Tyy .= 2*η_vep.*Eyy1 - Txy .= 2*η_vep.*Exy1 + @timeit to "non GP update" begin + # visco-elastic strain rates + Exx1 .= Exx .+ Txx_o ./2.0./η_e + Eyy1 .= Eyy .+ Tyy_o ./2.0./η_e + Exy1 .= Exy .+ Txy_o ./2.0./η_e # like this? + Exyv1 .= Exyv .+ Txyv_o ./2.0./η_ev + Exy1 .= av(Exyv1) # or like that? + if pl_correction == :native_naive + # Effective strain rate invariant + Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ Exy1.^2) + # trial stress + Txx .= 2.0.*η_ve.*Exx1 + Tyy .= 2.0.*η_ve.*Eyy1 + Txy .= 2.0.*η_ve.*Exy1 + Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) + # yield function + F .= Tii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(η_ve .+ η_reg) + dQdTxx .= 0.5.*Txx./Tii + dQdTyy .= 0.5.*Tyy./Tii + dQdTxy .= Txy./Tii + # plastic corrections + Txx .= 2.0.*η_ve.*(Exx1 .- λ.*dQdTxx) + Tyy .= 2.0.*η_ve.*(Eyy1 .- λ.*dQdTyy) + Txy .= 2.0.*η_ve.*(Exy1 .- 0.5.*λ.*dQdTxy) + Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) + Fchk .= Tii .- τ_y .- Pt.*sinϕ .- λ.*η_reg + η_vep .= Tii./2.0./Eii + elseif pl_correction == :native_inv1 + # trial stress + Txx .= 2.0.*η_ve.*Exx1 + Tyy .= 2.0.*η_ve.*Eyy1 + Txy .= 2.0.*η_ve.*Exy1 + # Effective strain rate invariant + Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ Exy1.^2) + Tii .= 2.0.*η_ve.*Eii + # yield function + F .= Tii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(η_ve .+ η_reg) + Fchk .= (Tii .- η_ve.*λ) .- τ_y .- Pt.*sinϕ .- λ.*η_reg + Txx .= 2.0.*η_ve.*(Exx1 .- 0.5.*λ.*Txx./Tii) + Tyy .= 2.0.*η_ve.*(Eyy1 .- 0.5.*λ.*Tyy./Tii) + Txy .= 2.0.*η_ve.*(Exy1 .- 0.5.*λ.*Txy./Tii) # Here we need the component for centroid update + Tii .= Tii .- η_ve.*λ + η_vep .= Tii./2.0./Eii + + elseif pl_correction == :native_inv2 + # trial stress + Txx .= 2.0.*η_ve.*Exx1 + Tyy .= 2.0.*η_ve.*Eyy1 + Txyv .= 2.0.*η_vev.*Exyv1 + Txy .= av(Txyv) + # Invariants + Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ av(Exyv1.^2)) + Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ av(Txyv.^2)) + # yield function + F .= Tii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(η_ve .+ η_reg) + Fchk .= (Tii .- η_ve.*λ) .- τ_y .- Pt.*sinϕ .- λ.*η_reg + Txx .= Txx .- η_ve.*λ.*Txx./Tii + Tyy .= Tyy .- η_ve.*λ.*Tyy./Tii + Txy .= Txy .- η_ve.*λ.*Txy./Tii # Here we need the component for centroid update + Tii .= Tii .- η_ve.*λ + η_vep .= Tii./2.0./Eii + + elseif pl_correction == :native_inv3 + + # visco-elastic strain rates + Exx1 .= Exx .+ Txx_o ./2.0./η_e + Eyy1 .= Eyy .+ Tyy_o ./2.0./η_e + Exy1 .= Exy .+ Txy_o ./2.0./η_e # like this? + Exyv1 .= Exyv .+ Txyv_o ./2.0./η_ev + Exy1 .= av(Exyv1) # or like that? + + # Invariants + Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ av(Exyv1.^2)) + Tii .= 2.0.*η_ve.*Eii + + # yield function + F .= Tii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(η_ve .+ η_reg) + Tii .= Tii .- η_ve.*λ # correct invariant + Fchk .= Tii .- τ_y .- Pt.*sinϕ .- λ.*η_reg + + η_vep .= Tii./2.0./Eii + Txx .= 2*η_vep.*Exx1 + Tyy .= 2*η_vep.*Eyy1 + Txy .= 2*η_vep.*Exy1 + end end end + Txyv[2:end-1,2:end-1].=av(Txy) # Txyv=0 on boundaries ! # PT timestep dtVx .= min(dx,dy)^2.0./av_xa(η_vep)./4.1./Vsc @@ -277,8 +312,21 @@ function Stokes2D_vep(UseGeoParams, nt) if !do_DP plot!(evo_t, τ_y*ones(size(evo_t)), linewidth=2.0) end # von Mises yield stress display(plot(p1, p2, p3, p4)) end - return evo_t, evo_Txx + return evo_t, evo_Txx, to end -@time evo_t, evo_Txx = Stokes2D_vep(false, 10) # 2nd argument = timesteps 7.311026 seconds (2.91 M allocations: 16.403 GiB, 16.54% gc time) -@time evo_t, evo_Txx_GP = Stokes2D_vep(true, 10) # 2nd argument = timesteps 9.368483 seconds (2.73 M allocations: 13.804 GiB, 8.24% gc time) \ No newline at end of file +@time evo_t, evo_Txx, to = Stokes2D_vep(false, 5) # 2nd argument = timesteps 7.311026 seconds (2.91 M allocations: 16.403 GiB, 16.54% gc time) +@time evo_t, evo_Txx_GP, to_GP = Stokes2D_vep(true, 5) # 2nd argument = timesteps 9.368483 seconds (2.73 M allocations: 13.804 GiB, 8.24% gc time) + + +foo(a,b,c) = a + b/2.0./c + +a = rand(4) +b = rand(4) +c = rand(4) + +av(x)=sum(x)/length(x) + +sum(foo.(a,b,c))/4 +foo(av(a),av(b),av(c)) + From ead02814262a9a2706e8e4921003d6d523e3e420 Mon Sep 17 00:00:00 2001 From: albert-de-montserrat Date: Tue, 8 Nov 2022 14:58:52 +0100 Subject: [PATCH 30/49] fix index bug --- .../Stokes2D_VEP_reg_ctau_inv_GeoParams.jl | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl index 97c683d..d54ec0a 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl @@ -24,13 +24,28 @@ function update_stress_GP2!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, @inbounds for j in axes(Exx,2), i in axes(Exx,1) args = (; dt=dt, P=Pt[i,j], τII_old=0.0) # gather strain rate - εij_v = (Exyv[i,j], Exyv[i+1,j], Exyv[i+1,j], Exyv[i,j+1]) # gather vertices around ij center + εij_v = ( + Exyv[i ,j ], + Exyv[i+1,j ], + Exyv[i ,j+1], + Exyv[i+1,j+1] + ) # gather vertices around ij center εij_p = (Exx[i,j], Eyy[i,j], εij_v) # gather deviatoric stress - τij_v = (Txyv_o[i,j], Txyv_o[i+1,j], Txyv_o[i+1,j], Txyv_o[i,j+1]) # gather vertices around ij center + τij_v = ( + Txyv_o[i ,j ], + Txyv_o[i+1,j ], + Txyv_o[i ,j+1], + Txyv_o[i+1,j+1] + ) # gather vertices around ij center τij_p_o = (Txx_o[i,j], Tyy_o[i,j], τij_v) # gathermaterial phases - phases_v = (Phasev[i,j], Phasev[i+1,j], Phasev[i+1,j], Phasev[i,j+1]) # gather vertices around ij center + phases_v = ( + Phasev[i ,j ], + Phasev[i+1,j ], + Phasev[i ,j+1], + Phasev[i+1,j+1] + ) # gather vertices around ij center phases = (Phasec[i,j], Phasec[i,j], phases_v) # update stress and effective viscosity Tij, Tii[i,j], η_vep[i,j] = compute_τij(MatParam, εij_p, args, τij_p_o, phases) @@ -164,7 +179,7 @@ end Exyv[2:end-1,2:end-1] .= 0.5.*(diff(Vx[2:end-1,:], dims=2)./dy .+ diff(Vy[:,2:end-1], dims=1)./dx) Exy .= av(Exyv) if UseGeoParams - @timeit to "GP update" update_stress_GP!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txy_o, Exx, Eyy, Exy, η_vep, Pt, Phasec, MatParam, dt) + # @timeit to "GP update" update_stress_GP!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txy_o, Exx, Eyy, Exy, η_vep, Pt, Phasec, MatParam, dt) @timeit to "GP update" update_stress_GP2!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, Exyv, η_vep, Pt, Phasec, Phasev, MatParam, dt) # @inbounds for j in axes(Exx,2), i in axes(Exx,1) # # compute second invariants from surrounding points @@ -315,18 +330,5 @@ end return evo_t, evo_Txx, to end -@time evo_t, evo_Txx, to = Stokes2D_vep(false, 5) # 2nd argument = timesteps 7.311026 seconds (2.91 M allocations: 16.403 GiB, 16.54% gc time) +# @time evo_t, evo_Txx, to = Stokes2D_vep(false, 5) # 2nd argument = timesteps 7.311026 seconds (2.91 M allocations: 16.403 GiB, 16.54% gc time) @time evo_t, evo_Txx_GP, to_GP = Stokes2D_vep(true, 5) # 2nd argument = timesteps 9.368483 seconds (2.73 M allocations: 13.804 GiB, 8.24% gc time) - - -foo(a,b,c) = a + b/2.0./c - -a = rand(4) -b = rand(4) -c = rand(4) - -av(x)=sum(x)/length(x) - -sum(foo.(a,b,c))/4 -foo(av(a),av(b),av(c)) - From 982b6b009de44c072ee83b137060463a5ed14bda Mon Sep 17 00:00:00 2001 From: albert-de-montserrat Date: Tue, 8 Nov 2022 15:14:42 +0100 Subject: [PATCH 31/49] compare against :inv3 --- .../Stokes2D_VEP_reg_ctau_inv_GeoParams.jl | 47 ++++++++----------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl index d54ec0a..39fd3b4 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl @@ -58,9 +58,9 @@ end # 2D Stokes routine @views function Stokes2D_vep(UseGeoParams, nt) pl_correction = :native_naive - # pl_correction = :native_inv1 - # pl_correction = :native_inv2 - # pl_correction = :native_inv3 + pl_correction = :native_inv1 + pl_correction = :native_inv2 + pl_correction = :native_inv3 do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) η_reg = 8.0e-3 # regularisation "viscosity" @@ -181,17 +181,6 @@ end if UseGeoParams # @timeit to "GP update" update_stress_GP!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txy_o, Exx, Eyy, Exy, η_vep, Pt, Phasec, MatParam, dt) @timeit to "GP update" update_stress_GP2!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, Exyv, η_vep, Pt, Phasec, Phasev, MatParam, dt) - # @inbounds for j in axes(Exx,2), i in axes(Exx,1) - # # compute second invariants from surrounding points - # args = (; dt=dt, P=Pt[i,j]) - # εij = (Exx[i,j], Eyy[i,j], Exy[i,j]) - # τij_o = (Txx_o[i,j], Tyy_o[i,j], Txy_o[i,j]) - # Tij, Tii[i,j], η_vep[i,j] = compute_τij(MatParam, εij, args, τij_o, Phasec[i,j]) - # Txx[i,j] = Tij[1] - # Tyy[i,j] = Tij[2] - # Txy[i,j] = Tij[3] - # # η_vep[i,j] = Txx[i,j]/2/Exx1[i,j] # should be same as native? - # end else @timeit to "non GP update" begin # visco-elastic strain rates @@ -309,26 +298,28 @@ end if mod(iter, nout)==0 norm_Rx = norm(Rx)/length(Rx); norm_Ry = norm(Ry)/length(Ry); norm_∇V = norm(∇V)/length(∇V) err = maximum([norm_Rx, norm_Ry, norm_∇V]) - push!(err_evo1, err); push!(err_evo2, itg) - @printf("it = %d, iter = %d, err = %1.2e norm[Rx=%1.2e, Ry=%1.2e, ∇V=%1.2e] (Fchk=%1.2e) \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V, maximum(Fchk)) + # push!(err_evo1, err); push!(err_evo2, itg) + # @printf("it = %d, iter = %d, err = %1.2e norm[Rx=%1.2e, Ry=%1.2e, ∇V=%1.2e] (Fchk=%1.2e) \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V, maximum(Fchk)) end iter+=1; itg=iter end t = t + dt push!(evo_t, t); push!(evo_Txx, maximum(Txx)) - # Plotting - p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") - # p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") - p2 = heatmap(xc, yc, η_vep' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="η_vep") - p3 = heatmap(xc, yc, Tii' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="τii") - p4 = plot(evo_t, evo_Txx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) - plot!(evo_t, 2.0.*εbg.*μ0.*(1.0.-exp.(.-evo_t.*G0./μ0)), linewidth=2.0) # analytical solution for VE loading - plot!(evo_t, 2.0.*εbg.*μ0.*ones(size(evo_t)), linewidth=2.0) # viscous flow stress - if !do_DP plot!(evo_t, τ_y*ones(size(evo_t)), linewidth=2.0) end # von Mises yield stress - display(plot(p1, p2, p3, p4)) + # # Plotting + # p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") + # # p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") + # p2 = heatmap(xc, yc, η_vep' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="η_vep") + # p3 = heatmap(xc, yc, Tii' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="τii") + # p4 = plot(evo_t, evo_Txx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + # plot!(evo_t, 2.0.*εbg.*μ0.*(1.0.-exp.(.-evo_t.*G0./μ0)), linewidth=2.0) # analytical solution for VE loading + # plot!(evo_t, 2.0.*εbg.*μ0.*ones(size(evo_t)), linewidth=2.0) # viscous flow stress + # if !do_DP plot!(evo_t, τ_y*ones(size(evo_t)), linewidth=2.0) end # von Mises yield stress + # display(plot(p1, p2, p3, p4)) end return evo_t, evo_Txx, to end -# @time evo_t, evo_Txx, to = Stokes2D_vep(false, 5) # 2nd argument = timesteps 7.311026 seconds (2.91 M allocations: 16.403 GiB, 16.54% gc time) -@time evo_t, evo_Txx_GP, to_GP = Stokes2D_vep(true, 5) # 2nd argument = timesteps 9.368483 seconds (2.73 M allocations: 13.804 GiB, 8.24% gc time) +@time evo_t, evo_Txx, to = Stokes2D_vep(false, 12) # 2nd argument = timesteps 7.311026 seconds (2.91 M allocations: 16.403 GiB, 16.54% gc time) +@time evo_t, evo_Txx_GP, to_GP = Stokes2D_vep(true, 12) # 2nd argument = timesteps 9.368483 seconds (2.73 M allocations: 13.804 GiB, 8.24% gc time) + +plot(evo_t, @.((evo_Txx-evo_Txx_GP)/evo_Txx*100), ylabel="error (%)", xlabel="time" ) \ No newline at end of file From 5d9c8d7232d6910b40a739acab4030752620bed2 Mon Sep 17 00:00:00 2001 From: Boris Kaus Date: Tue, 8 Nov 2022 16:50:20 +0100 Subject: [PATCH 32/49] update Manifest & required packages --- GeoParams_PT_examples/Manifest.toml | 15 +++++++++++++-- GeoParams_PT_examples/Project.toml | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/GeoParams_PT_examples/Manifest.toml b/GeoParams_PT_examples/Manifest.toml index 7a4b09c..60866f7 100644 --- a/GeoParams_PT_examples/Manifest.toml +++ b/GeoParams_PT_examples/Manifest.toml @@ -177,6 +177,11 @@ git-tree-sha1 = "bad72f730e9e91c08d9427d5e8db95478a3c323d" uuid = "2e619515-83b5-522b-bb60-26c02a35a201" version = "2.4.8+0" +[[deps.ExprTools]] +git-tree-sha1 = "56559bbef6ca5ea0c0818fa5c90320398a6fbf8d" +uuid = "e2ba6199-217a-4e67-a87a-7c52f15ade04" +version = "0.1.8" + [[deps.FFMPEG]] deps = ["FFMPEG_jll"] git-tree-sha1 = "b57e3acbe22f8484b4b5ff66a7499717fe1a9cc8" @@ -249,8 +254,8 @@ version = "0.69.1+0" [[deps.GeoParams]] deps = ["BibTeX", "DelimitedFiles", "ForwardDiff", "Interpolations", "KernelDensitySJ", "LaTeXStrings", "Loess", "Parameters", "Requires", "Roots", "Setfield", "SpecialFunctions", "Static", "StaticArrays", "Statistics", "StatsBase", "UnPack", "Unidecode", "Unitful"] -git-tree-sha1 = "406f395a4e093ac5b79dd8da37d7854de1fa9fa8" -repo-rev = "adm-cuda-check" +git-tree-sha1 = "03f4e085458c87c6db289461c0901679e6ffdb10" +repo-rev = "adm-tuples" repo-url = "https://github.com/JuliaGeodynamics/GeoParams.jl.git" uuid = "e018b62d-d9de-4a26-8697-af89c310ae38" version = "0.4.1" @@ -789,6 +794,12 @@ version = "0.1.1" deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +[[deps.TimerOutputs]] +deps = ["ExprTools", "Printf"] +git-tree-sha1 = "9dfcb767e17b0849d6aaf85997c98a5aea292513" +uuid = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" +version = "0.5.21" + [[deps.TranscodingStreams]] deps = ["Random", "Test"] git-tree-sha1 = "8a75929dcd3c38611db2f8d08546decb514fcadf" diff --git a/GeoParams_PT_examples/Project.toml b/GeoParams_PT_examples/Project.toml index 37d68b4..3b26e59 100644 --- a/GeoParams_PT_examples/Project.toml +++ b/GeoParams_PT_examples/Project.toml @@ -9,3 +9,4 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" +TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" From 6b16f320773c71cb01d719bbddbfdc5028535f22 Mon Sep 17 00:00:00 2001 From: Boris Kaus Date: Thu, 10 Nov 2022 21:46:53 +0100 Subject: [PATCH 33/49] update script to directly use the GeoParams routine to update deviatoric stresses --- GeoParams_PT_examples/Manifest.toml | 72 ++++++++++++------- .../Stokes2D_VEP_reg_ctau_inv_GeoParams.jl | 58 +++++++++------ 2 files changed, 84 insertions(+), 46 deletions(-) diff --git a/GeoParams_PT_examples/Manifest.toml b/GeoParams_PT_examples/Manifest.toml index 60866f7..e64d0b2 100644 --- a/GeoParams_PT_examples/Manifest.toml +++ b/GeoParams_PT_examples/Manifest.toml @@ -1,7 +1,8 @@ # This file is machine-generated - editing it directly is not advised -julia_version = "1.7.2" +julia_version = "1.8.2" manifest_format = "2.0" +project_hash = "3acd3157c619d661bbd583bb97bd1c274825a665" [[deps.Adapt]] deps = ["LinearAlgebra"] @@ -11,6 +12,7 @@ version = "3.4.0" [[deps.ArgTools]] uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" +version = "1.1.1" [[deps.Artifacts]] uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" @@ -30,9 +32,9 @@ uuid = "7b0aa2c9-049f-5cec-894a-2b6b781bb25e" version = "0.1.0" [[deps.BitFlags]] -git-tree-sha1 = "84259bb6172806304b9101094a7cc4bc6f56dbc6" +git-tree-sha1 = "629c6e4a7be8f427d268cebef2a5e3de6c50d462" uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35" -version = "0.1.5" +version = "0.1.6" [[deps.Bzip2_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] @@ -108,6 +110,7 @@ version = "4.3.0" [[deps.CompilerSupportLibraries_jll]] deps = ["Artifacts", "Libdl"] uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" +version = "0.5.2+0" [[deps.ConstructionBase]] deps = ["LinearAlgebra"] @@ -121,9 +124,9 @@ uuid = "d38c429a-6771-53c6-b99e-75d170b6e991" version = "0.6.2" [[deps.DataAPI]] -git-tree-sha1 = "46d2680e618f8abd007bce0c3026cb0c4a8f2032" +git-tree-sha1 = "e08915633fcb3ea83bf9d6126292e5bc5c739922" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" -version = "1.12.0" +version = "1.13.0" [[deps.DataStructures]] deps = ["Compat", "InteractiveUtils", "OrderedCollections"] @@ -147,9 +150,9 @@ version = "1.1.0" [[deps.DiffRules]] deps = ["IrrationalConstants", "LogExpFunctions", "NaNMath", "Random", "SpecialFunctions"] -git-tree-sha1 = "8b7a4d23e22f5d44883671da70865ca98f2ebf9d" +git-tree-sha1 = "9a95659c283c9018ea99e017aa9e13b7e89fadd2" uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" -version = "1.12.0" +version = "1.12.1" [[deps.Distances]] deps = ["LinearAlgebra", "SparseArrays", "Statistics", "StatsAPI"] @@ -168,8 +171,9 @@ uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" version = "0.9.2" [[deps.Downloads]] -deps = ["ArgTools", "LibCURL", "NetworkOptions"] +deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"] uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" +version = "1.6.0" [[deps.Expat_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] @@ -194,6 +198,9 @@ git-tree-sha1 = "74faea50c1d007c85837327f6775bea60b5492dd" uuid = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5" version = "4.4.2+2" +[[deps.FileWatching]] +uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" + [[deps.FixedPointNumbers]] deps = ["Statistics"] git-tree-sha1 = "335bfdceacc84c5cdf16aadc768aa5ddfc5383cc" @@ -254,7 +261,7 @@ version = "0.69.1+0" [[deps.GeoParams]] deps = ["BibTeX", "DelimitedFiles", "ForwardDiff", "Interpolations", "KernelDensitySJ", "LaTeXStrings", "Loess", "Parameters", "Requires", "Roots", "Setfield", "SpecialFunctions", "Static", "StaticArrays", "Statistics", "StatsBase", "UnPack", "Unidecode", "Unitful"] -git-tree-sha1 = "03f4e085458c87c6db289461c0901679e6ffdb10" +git-tree-sha1 = "52b20f3408c80ad6d351b4c4e82ee09d83192e5a" repo-rev = "adm-tuples" repo-url = "https://github.com/JuliaGeodynamics/GeoParams.jl.git" uuid = "e018b62d-d9de-4a26-8697-af89c310ae38" @@ -285,9 +292,9 @@ version = "1.0.2" [[deps.HTTP]] deps = ["Base64", "CodecZlib", "Dates", "IniFile", "Logging", "LoggingExtras", "MbedTLS", "NetworkOptions", "OpenSSL", "Random", "SimpleBufferStream", "Sockets", "URIs", "UUIDs"] -git-tree-sha1 = "a97d47758e933cd5fe5ea181d178936a9fc60427" +git-tree-sha1 = "8c7e6b82abd41364b8ffe40ffc63b33e590c8722" uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3" -version = "1.5.1" +version = "1.5.3" [[deps.HarfBuzz_jll]] deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "Graphite2_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg"] @@ -388,10 +395,12 @@ version = "0.15.17" [[deps.LibCURL]] deps = ["LibCURL_jll", "MozillaCACerts_jll"] uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" +version = "0.6.3" [[deps.LibCURL_jll]] deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" +version = "7.84.0+0" [[deps.LibGit2]] deps = ["Base64", "NetworkOptions", "Printf", "SHA"] @@ -400,6 +409,7 @@ uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" [[deps.LibSSH2_jll]] deps = ["Artifacts", "Libdl", "MbedTLS_jll"] uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" +version = "1.10.2+0" [[deps.Libdl]] uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" @@ -496,6 +506,7 @@ version = "1.1.7" [[deps.MbedTLS_jll]] deps = ["Artifacts", "Libdl"] uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" +version = "2.28.0+0" [[deps.Measures]] git-tree-sha1 = "e498ddeee6f9fdb4551ce855a46f54dbd900245f" @@ -513,6 +524,7 @@ uuid = "a63ad114-7e13-5084-954f-fe012c677804" [[deps.MozillaCACerts_jll]] uuid = "14a3606d-f60d-562e-9121-12d972cd8159" +version = "2022.2.1" [[deps.NaNMath]] deps = ["OpenLibm_jll"] @@ -522,6 +534,7 @@ version = "1.0.1" [[deps.NetworkOptions]] uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" +version = "1.2.0" [[deps.OffsetArrays]] deps = ["Adapt"] @@ -538,22 +551,24 @@ version = "1.3.5+1" [[deps.OpenBLAS_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"] uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" +version = "0.3.20+0" [[deps.OpenLibm_jll]] deps = ["Artifacts", "Libdl"] uuid = "05823500-19ac-5b8b-9628-191a04bc5112" +version = "0.8.1+0" [[deps.OpenSSL]] deps = ["BitFlags", "Dates", "MozillaCACerts_jll", "OpenSSL_jll", "Sockets"] -git-tree-sha1 = "3c3c4a401d267b04942545b1e964a20279587fd7" +git-tree-sha1 = "5628f092c6186a80484bfefdf89ff64efdaec552" uuid = "4d8831e6-92b7-49fb-bdf8-b643e874388c" -version = "1.3.0" +version = "1.3.1" [[deps.OpenSSL_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "e60321e3f2616584ff98f0a4f18d98ae6f89bbb3" +git-tree-sha1 = "f6e9dba33f9f2c44e08a020b0caf6903be540004" uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95" -version = "1.1.17+0" +version = "1.1.19+0" [[deps.OpenSpecFun_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"] @@ -575,6 +590,7 @@ version = "1.4.1" [[deps.PCRE2_jll]] deps = ["Artifacts", "Libdl"] uuid = "efcefdf7-47ab-520b-bdef-62a2eaa19f15" +version = "10.40.0+0" [[deps.Parameters]] deps = ["OrderedCollections", "UnPack"] @@ -583,10 +599,10 @@ uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a" version = "0.12.3" [[deps.Parsers]] -deps = ["Dates"] -git-tree-sha1 = "6c01a9b494f6d2a9fc180a08b182fcb06f0958a0" +deps = ["Dates", "SnoopPrecompile"] +git-tree-sha1 = "cceb0257b662528ecdf0b4b4302eb00e767b38e7" uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -version = "2.4.2" +version = "2.5.0" [[deps.Pipe]] git-tree-sha1 = "6842804e7867b115ca9de748a0cf6b364523c16d" @@ -602,6 +618,7 @@ version = "0.40.1+0" [[deps.Pkg]] deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" +version = "1.8.0" [[deps.PlotThemes]] deps = ["PlotUtils", "Statistics"] @@ -633,9 +650,9 @@ uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" [[deps.Qt5Base_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "Fontconfig_jll", "Glib_jll", "JLLWrappers", "Libdl", "Libglvnd_jll", "OpenSSL_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libxcb_jll", "Xorg_xcb_util_image_jll", "Xorg_xcb_util_keysyms_jll", "Xorg_xcb_util_renderutil_jll", "Xorg_xcb_util_wm_jll", "Zlib_jll", "xkbcommon_jll"] -git-tree-sha1 = "c6c0f690d0cc7caddb74cef7aa847b824a16b256" +git-tree-sha1 = "0c03844e2231e12fda4d0086fd7cbe4098ee8dc5" uuid = "ea2cea3b-5b76-57ae-a6ef-0a8af62496e1" -version = "5.15.3+1" +version = "5.15.3+2" [[deps.REPL]] deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] @@ -659,9 +676,9 @@ version = "1.3.1" [[deps.RecipesPipeline]] deps = ["Dates", "NaNMath", "PlotUtils", "RecipesBase", "SnoopPrecompile"] -git-tree-sha1 = "9b1c0c8e9188950e66fc28f40bfe0f8aac311fe0" +git-tree-sha1 = "a030182cccc5c461386c6f055c36ab8449ef1340" uuid = "01d81517-befc-4cb6-b9ec-a95719d0359c" -version = "0.6.7" +version = "0.6.10" [[deps.Reexport]] git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b" @@ -688,6 +705,7 @@ version = "2.0.8" [[deps.SHA]] uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" +version = "0.7.0" [[deps.Scratch]] deps = ["Dates"] @@ -745,9 +763,9 @@ version = "2.1.7" [[deps.Static]] deps = ["IfElse"] -git-tree-sha1 = "de4f0a4f049a4c87e4948c04acff37baf1be01a6" +git-tree-sha1 = "03170c1e8a94732c1d835ce4c5b904b4b52cba1c" uuid = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" -version = "0.7.7" +version = "0.7.8" [[deps.StaticArrays]] deps = ["LinearAlgebra", "Random", "StaticArraysCore", "Statistics"] @@ -779,10 +797,12 @@ version = "0.33.21" [[deps.TOML]] deps = ["Dates"] uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" +version = "1.0.0" [[deps.Tar]] deps = ["ArgTools", "SHA"] uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" +version = "1.10.1" [[deps.TensorCore]] deps = ["LinearAlgebra"] @@ -1005,6 +1025,7 @@ version = "1.4.0+3" [[deps.Zlib_jll]] deps = ["Libdl"] uuid = "83775a58-1f1d-513f-b197-d71354ab007a" +version = "1.2.12+3" [[deps.Zstd_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] @@ -1033,6 +1054,7 @@ version = "0.15.1+0" [[deps.libblastrampoline_jll]] deps = ["Artifacts", "Libdl", "OpenBLAS_jll"] uuid = "8e850b90-86db-534c-a0d3-1478176c7d93" +version = "5.1.1+0" [[deps.libfdk_aac_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] @@ -1055,10 +1077,12 @@ version = "1.3.7+1" [[deps.nghttp2_jll]] deps = ["Artifacts", "Libdl"] uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" +version = "1.48.0+0" [[deps.p7zip_jll]] deps = ["Artifacts", "Libdl"] uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" +version = "17.4.0+0" [[deps.x264_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl index 39fd3b4..5686999 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl @@ -1,3 +1,4 @@ +# This script implements plasticity with and w/out invariants & shows how to use GeoParams to do the local stress update # Initialisation using Plots, Printf, Statistics, LinearAlgebra, GeoParams, TimerOutputs const Dat = Float64 # Precision (double=Float64 or single=Float32) @@ -61,6 +62,10 @@ end pl_correction = :native_inv1 pl_correction = :native_inv2 pl_correction = :native_inv3 + + gp_correction = :loop + #gp_correction = :native_gp + do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) η_reg = 8.0e-3 # regularisation "viscosity" @@ -76,15 +81,16 @@ end εbg = 1.0 # background strain-rate Coh = τ_y/cosd(ϕ) # cohesion # Coh = Inf + # Geoparams initialisation - pl = DruckerPrager_regularised(C=Coh, ϕ=ϕ, η_vp=η_reg) # non-regularized plasticity + pl = DruckerPrager_regularised(C=Coh, ϕ=ϕ, η_vp=η_reg, Ψ=0) # non-regularized plasticity MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, - CompositeRheology = CompositeRheology(ConstantElasticity(G=G0),LinearViscous(η=μ0),pl)), + CompositeRheology = CompositeRheology(SetConstantElasticity(G=G0, ν=0.5),LinearViscous(η=μ0), pl)), SetMaterialParams(Name="Inclusion", Phase=2, - CompositeRheology = CompositeRheology(ConstantElasticity(G=Gi),LinearViscous(η=μ0),pl)), + CompositeRheology = CompositeRheology(SetConstantElasticity(G=Gi, ν=0.5),LinearViscous(η=μ0), pl)), ) # Numerics - # nt = 10 # number of time steps + # nt = 10 # number of time steps nx, ny = 63, 63 # numerical grid resolution Vdmp = 4.0 # convergence acceleration (damping) Vsc = 2.0 # iterative time step limiter @@ -97,6 +103,7 @@ end dt = μ0/G0/4.0 # assumes Maxwell time of 4 # Array initialisation Pt = zeros(Dat, nx ,ny ) + P_o = zeros(Dat, nx, ny ) ∇V = zeros(Dat, nx ,ny ) Vx = zeros(Dat, nx+1,ny ) Vy = zeros(Dat, nx ,ny+1) @@ -167,7 +174,7 @@ end to = TimerOutput() for it = 1:nt iter=1; err=2*ε; err_evo1=Float64[]; err_evo2=Float64[] - Txx_o.=Txx; Tyy_o.=Tyy; Txy_o.=av(Txyv); Txyv_o.=Txyv; λ.=0.0 + Txx_o.=Txx; Tyy_o.=Tyy; Txy_o.=av(Txyv); Txyv_o.=Txyv; λ.=0.0; P_o .= Pt local itg while (err>ε && iter<=iterMax) # divergence - pressure @@ -179,8 +186,14 @@ end Exyv[2:end-1,2:end-1] .= 0.5.*(diff(Vx[2:end-1,:], dims=2)./dy .+ diff(Vy[:,2:end-1], dims=1)./dx) Exy .= av(Exyv) if UseGeoParams - # @timeit to "GP update" update_stress_GP!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txy_o, Exx, Eyy, Exy, η_vep, Pt, Phasec, MatParam, dt) - @timeit to "GP update" update_stress_GP2!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, Exyv, η_vep, Pt, Phasec, Phasev, MatParam, dt) + # This uses the build-in GeoParams function to update stresses + @timeit to "GP update" begin + if gp_correction == :native_gp + compute_τij_stagcenter!(Txx, Tyy, Txy, Tii, η_vep, Exx, Eyy, Exyv, Pt, Txx_o, Tyy_o, Txyv_o, Phasec, Phasev, MatParam, dt) + elseif gp_correction == :loop + update_stress_GP2!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, Exyv, η_vep, Pt, Phasec, Phasev, MatParam, dt) + end + end else @timeit to "non GP update" begin # visco-elastic strain rates @@ -281,7 +294,6 @@ end end end end - Txyv[2:end-1,2:end-1].=av(Txy) # Txyv=0 on boundaries ! # PT timestep dtVx .= min(dx,dy)^2.0./av_xa(η_vep)./4.1./Vsc @@ -298,28 +310,30 @@ end if mod(iter, nout)==0 norm_Rx = norm(Rx)/length(Rx); norm_Ry = norm(Ry)/length(Ry); norm_∇V = norm(∇V)/length(∇V) err = maximum([norm_Rx, norm_Ry, norm_∇V]) - # push!(err_evo1, err); push!(err_evo2, itg) - # @printf("it = %d, iter = %d, err = %1.2e norm[Rx=%1.2e, Ry=%1.2e, ∇V=%1.2e] (Fchk=%1.2e) \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V, maximum(Fchk)) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %d, iter = %d, err = %1.2e norm[Rx=%1.2e, Ry=%1.2e, ∇V=%1.2e] (Fchk=%1.2e) \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V, maximum(Fchk)) end iter+=1; itg=iter end t = t + dt push!(evo_t, t); push!(evo_Txx, maximum(Txx)) - # # Plotting - # p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") - # # p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") - # p2 = heatmap(xc, yc, η_vep' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="η_vep") - # p3 = heatmap(xc, yc, Tii' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="τii") - # p4 = plot(evo_t, evo_Txx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) - # plot!(evo_t, 2.0.*εbg.*μ0.*(1.0.-exp.(.-evo_t.*G0./μ0)), linewidth=2.0) # analytical solution for VE loading - # plot!(evo_t, 2.0.*εbg.*μ0.*ones(size(evo_t)), linewidth=2.0) # viscous flow stress - # if !do_DP plot!(evo_t, τ_y*ones(size(evo_t)), linewidth=2.0) end # von Mises yield stress - # display(plot(p1, p2, p3, p4)) + + # Plotting + p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") + # p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p2 = heatmap(xc, yc, η_vep' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="η_vep") + p3 = heatmap(xc, yc, Tii' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="τii") + p4 = plot(evo_t, evo_Txx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + plot!(evo_t, 2.0.*εbg.*μ0.*(1.0.-exp.(.-evo_t.*G0./μ0)), linewidth=2.0) # analytical solution for VE loading + plot!(evo_t, 2.0.*εbg.*μ0.*ones(size(evo_t)), linewidth=2.0) # viscous flow stress + if !do_DP plot!(evo_t, τ_y*ones(size(evo_t)), linewidth=2.0) end # von Mises yield stress + display(plot(p1, p2, p3, p4)) + end return evo_t, evo_Txx, to end -@time evo_t, evo_Txx, to = Stokes2D_vep(false, 12) # 2nd argument = timesteps 7.311026 seconds (2.91 M allocations: 16.403 GiB, 16.54% gc time) +#@time evo_t, evo_Txx, to = Stokes2D_vep(false, 12) # 2nd argument = timesteps 7.311026 seconds (2.91 M allocations: 16.403 GiB, 16.54% gc time) @time evo_t, evo_Txx_GP, to_GP = Stokes2D_vep(true, 12) # 2nd argument = timesteps 9.368483 seconds (2.73 M allocations: 13.804 GiB, 8.24% gc time) -plot(evo_t, @.((evo_Txx-evo_Txx_GP)/evo_Txx*100), ylabel="error (%)", xlabel="time" ) \ No newline at end of file +#plot(evo_t, @.((evo_Txx-evo_Txx_GP)/evo_Txx*100), ylabel="error (%)", xlabel="time" ) \ No newline at end of file From 28e1536a2b5a65f163457dc0798d6bae596d699a Mon Sep 17 00:00:00 2001 From: Boris Kaus Date: Thu, 10 Nov 2022 23:06:59 +0100 Subject: [PATCH 34/49] using dimensional values --- .../Stokes2D_VEP_reg_ctau_GP_dimensional.jl | 185 ++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_GP_dimensional.jl diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_GP_dimensional.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_GP_dimensional.jl new file mode 100644 index 0000000..cf1443c --- /dev/null +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_GP_dimensional.jl @@ -0,0 +1,185 @@ +# This script implements plasticity with and w/out invariants & shows how to use GeoParams to do the local stress update +# Initialisation +using Plots, Printf, Statistics, LinearAlgebra, GeoParams, TimerOutputs +const Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av2(A) = 0.25*(A[1:end-1,1:end-1].^2 .+ A[2:end,1:end-1].^2 .+ A[1:end-1,2:end].^2 .+ A[2:end,2:end].^2) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) + +# 2D Stokes routine +@views function Stokes2D_vep(doPlot, nt) + CharDim = GEO_units(length=100km) + do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) + η_reg = 1.5e20Pas # regularisation "viscosity" + # Physics + Lx, Ly = 100km,100km # domain size + radi = 1km # inclusion radius + τ_y = 35MPa # yield stress. If do_DP=true, τ_y stand for the cohesion: c*cos(ϕ) + ϕ = 30.0*do_DP + μ0 = 1e23Pas # viscous viscosity + G0 = 1e10Pa # elastic shear modulus + Gi = G0/(6.0-4.0*do_DP) # elastic shear modulus perturbation + εbg = 1e-15/s # background strain-rate + Coh = τ_y/cosd(ϕ) # cohesion + # Coh = Inf + + # Geoparams initialisation + pl = DruckerPrager_regularised(C=Coh, ϕ=ϕ, η_vp=η_reg, Ψ=0) # non-regularized plasticity + MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, + CompositeRheology = CompositeRheology(SetConstantElasticity(G=G0, ν=0.5),LinearViscous(η=μ0), pl), CharDim=CharDim), + SetMaterialParams(Name="Inclusion", Phase=2, + CompositeRheology = CompositeRheology(SetConstantElasticity(G=Gi, ν=0.5),LinearViscous(η=μ0), pl), CharDim=CharDim), + ) + + # Nondimensionalize + Lx, Ly = nondimensionalize([Lx, Ly], CharDim) + radi = nondimensionalize(radi, CharDim) + εbg = nondimensionalize(εbg, CharDim) + μ0 = nondimensionalize(μ0, CharDim) + G0 = nondimensionalize(G0, CharDim) + Gi = nondimensionalize(Gi, CharDim) + τ_y = nondimensionalize(τ_y, CharDim) + + # Numerics + # nt = 10 # number of time steps + nx, ny = 63, 63 # numerical grid resolution + # nx, ny = 128, 128 # numerical grid resolution + + Vdmp = 4.0 # convergence acceleration (damping) + Vsc = 2.0 # iterative time step limiter + Ptsc = 6.0 # iterative time step limiter + ε = 1e-6 # nonlinear tolerence + iterMax = 3e4 # max number of iters + nout = 200 # check frequency + # Preprocessing + dx, dy = Lx/nx, Ly/ny + dt = μ0/G0/30.0 # assumes Maxwell time of 4 + # Array initialisation + Pt = zeros(Dat, nx ,ny ) + P_o = zeros(Dat, nx, ny ) + ∇V = zeros(Dat, nx ,ny ) + Vx = zeros(Dat, nx+1,ny ) + Vy = zeros(Dat, nx ,ny+1) + Exx = zeros(Dat, nx ,ny ) + Eyy = zeros(Dat, nx ,ny ) + Exy = zeros(Dat, nx ,ny ) + Exyv = zeros(Dat, nx+1,ny+1) + Exx1 = zeros(Dat, nx ,ny ) + Eyy1 = zeros(Dat, nx ,ny ) + Exy1 = zeros(Dat, nx ,ny ) + Exyv1 = zeros(Dat, nx+1,ny+1) + Txx = zeros(Dat, nx ,ny ) + Tyy = zeros(Dat, nx ,ny ) + Txy = zeros(Dat, nx ,ny ) + Txyv = zeros(Dat, nx+1,ny+1) + Txx_o = zeros(Dat, nx ,ny ) + Tii_o = zeros(Dat, nx ,ny ) + Tyy_o = zeros(Dat, nx ,ny ) + Txy_o = zeros(Dat, nx ,ny ) + Txyv_o = zeros(Dat, nx+1,ny+1) + Tii = zeros(Dat, nx ,ny ) + Eii = zeros(Dat, nx ,ny ) + Eii_f = zeros(Dat, nx ,ny ) + F = zeros(Dat, nx ,ny ) + Fchk = zeros(Dat, nx ,ny ) + Pla = zeros(Dat, nx ,ny ) + λ = zeros(Dat, nx ,ny ) + dQdTxx = zeros(Dat, nx ,ny ) + dQdTyy = zeros(Dat, nx ,ny ) + dQdTxy = zeros(Dat, nx ,ny ) + Rx = zeros(Dat, nx-1,ny ) + Ry = zeros(Dat, nx ,ny-1) + dVxdt = zeros(Dat, nx-1,ny ) + dVydt = zeros(Dat, nx ,ny-1) + dtPt = zeros(Dat, nx ,ny ) + dtVx = zeros(Dat, nx-1,ny ) + dtVy = zeros(Dat, nx ,ny-1) + Rog = zeros(Dat, nx ,ny ) + η_v = μ0*ones(Dat, nx, ny) + η_vv = μ0*ones(Dat, nx+1, ny+1) + η_e = dt*G0*ones(Dat, nx, ny) + η_ev = dt*G0*ones(Dat, nx+1, ny+1) + η_ve = ones(Dat, nx, ny) + η_vev = ones(Dat, nx+1, ny+1) + η_vep = ones(Dat, nx, ny) + η_vepv = ones(Dat, nx+1, ny+1) + ηc = ones(Dat,nx,ny) + Phasec = ones(Int, nx ,ny ) + Phasev = ones(Int, nx+1,ny+1) + # Initial condition + xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) + xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) + xv, yv = LinRange(0.0, Lx, nx+1), LinRange(0.0, Ly, ny+1) + (Xvx,Yvx) = ([x for x=xv,y=yc], [y for x=xv,y=yc]) + (Xvy,Yvy) = ([x for x=xc,y=yv], [y for x=xc,y=yv]) + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + η_e[radc.ε && iter<=iterMax) + # divergence - pressure + ∇V .= diff(Vx, dims=1)./dx .+ diff(Vy, dims=2)./dy + Pt .= Pt .- dtPt.*∇V + # strain rates + Exx .= diff(Vx, dims=1)./dx .- 1.0/3.0*∇V + Eyy .= diff(Vy, dims=2)./dy .- 1.0/3.0*∇V + Exyv[2:end-1,2:end-1] .= 0.5.*(diff(Vx[2:end-1,:], dims=2)./dy .+ diff(Vy[:,2:end-1], dims=1)./dx) + Exy .= av(Exyv) + # Update stresses using GeoParams + compute_τij_stagcenter!(Txx, Tyy, Txy, Tii, η_vep, Exx, Eyy, Exyv, Pt, Txx_o, Tyy_o, Txyv_o, Phasec, Phasev, MatParam, dt) + Txyv[2:end-1,2:end-1].=av(Txy) # Txyv=0 on boundaries ! + # PT timestep + dtVx .= min(dx,dy)^2.0./av_xa(η_vep)./4.1./Vsc + dtVy .= min(dx,dy)^2.0./av_ya(η_vep)./4.1./Vsc + dtPt .= 4.1.*η_vep./max(nx,ny)./Ptsc + # velocities + Rx .= .-diff(Pt, dims=1)./dx .+ diff(Txx, dims=1)./dx .+ diff(Txyv[2:end-1,:], dims=2)./dy + Ry .= .-diff(Pt, dims=2)./dy .+ diff(Tyy, dims=2)./dy .+ diff(Txyv[:,2:end-1], dims=1)./dx .+ av_ya(Rog) + dVxdt .= dVxdt.*(1-Vdmp/nx) .+ Rx + dVydt .= dVydt.*(1-Vdmp/ny) .+ Ry + Vx[2:end-1,:] .= Vx[2:end-1,:] .+ dVxdt.*dtVx + Vy[:,2:end-1] .= Vy[:,2:end-1] .+ dVydt.*dtVy + # convergence check + if mod(iter, nout)==0 + norm_Rx = norm(Rx)/length(Rx); norm_Ry = norm(Ry)/length(Ry); norm_∇V = norm(∇V)/length(∇V) + err = maximum([norm_Rx, norm_Ry, norm_∇V]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %d, iter = %d, err = %1.2e norm[Rx=%1.2e, Ry=%1.2e, ∇V=%1.2e] (Fchk=%1.2e) \n", it, itg, err, norm_Rx, norm_Ry, norm_∇V, maximum(Fchk)) + end + iter+=1; itg=iter + end + t = t + dt + push!(evo_t, t); push!(evo_Txx, maximum(Txx)) + + if doPlot + # Plotting + p1 = heatmap(xv*CharDim.length, yc*CharDim.length, Vx' , aspect_ratio=1, xlims=(0, Lx).*CharDim.length, ylims=(dy/2, Ly-dy/2).*CharDim.length, c=:inferno, title="Vx") + # p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p2 = heatmap(xc*CharDim.length, yc*CharDim.length, (η_vep.*CharDim.viscosity)' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2).*CharDim.length, ylims=(0, Ly).*CharDim.length, c=:inferno, title="η_vep") + p3 = heatmap(xc*CharDim.length, yc*CharDim.length, (Tii.*CharDim.stress)' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2).*CharDim.length, ylims=(0, Ly).*CharDim.length, c=:inferno, title="τii") + p4 = plot(evo_t.*CharDim.time, evo_Txx.*CharDim.stress , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + plot!(evo_t.*CharDim.time, CharDim.stress*2.0.*εbg.*μ0.*(1.0.-exp.(.-evo_t.*G0./μ0)), linewidth=2.0) # analytical solution for VE loading + # plot!(evo_t.*CharDim.time, CharDim.stress*2.0.*εbg.*μ0.*ones(size(evo_t)), linewidth=2.0) # viscous flow stress + if !do_DP plot!(evo_t.*CharDim.time, CharDim.stress*τ_y*ones(size(evo_t)), linewidth=2.0) end # von Mises yield stress + display(plot(p1, p2, p3, p4)) + end + end + return evo_t, evo_Txx, to +end + +@time evo_t, evo_Txx_GP, to_GP = Stokes2D_vep(true, 10) # 2nd argument = timesteps 9.368483 seconds (2.73 M allocations: 13.804 GiB, 8.24% gc time) From d417c2a86c833d7ff1638cfd6a1e9ce1b0e48032 Mon Sep 17 00:00:00 2001 From: Boris Kaus Date: Fri, 11 Nov 2022 09:45:15 +0100 Subject: [PATCH 35/49] added dilatant rheologies as option for GP (not working!) --- .../scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl index 5686999..de5903f 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl @@ -63,8 +63,9 @@ end pl_correction = :native_inv2 pl_correction = :native_inv3 - gp_correction = :loop - #gp_correction = :native_gp + #gp_correction = :loop + gp_correction = :native_gp + #gp_correction = :native_gp_dilation do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) @@ -192,6 +193,8 @@ end compute_τij_stagcenter!(Txx, Tyy, Txy, Tii, η_vep, Exx, Eyy, Exyv, Pt, Txx_o, Tyy_o, Txyv_o, Phasec, Phasev, MatParam, dt) elseif gp_correction == :loop update_stress_GP2!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, Exyv, η_vep, Pt, Phasec, Phasev, MatParam, dt) + elseif gp_correction == :native_gp_dilation + compute_p_τij_stagcenter!(Txx, Tyy, Txy, Tii, η_vep, Pt, Exx, Eyy, Exyv, P_o, Txx_o, Tyy_o, Txyv_o, Phasec, Phasev, MatParam, dt) end end else From 81eb3c7c5cc253f95d21101d3697b96a65a9c154 Mon Sep 17 00:00:00 2001 From: albert-de-montserrat Date: Fri, 11 Nov 2022 11:25:27 +0100 Subject: [PATCH 36/49] inclusion test with damping v3.0 (linear rheology) --- ...kes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl | 336 ++++++++++++++++++ 1 file changed, 336 insertions(+) create mode 100644 GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl new file mode 100644 index 0000000..97d126f --- /dev/null +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl @@ -0,0 +1,336 @@ +using ElasticArrays,Printf +using Plots,Plots.Measures +default(size=(800,500),framestyle=:box,label=false,grid=false,margin=3mm,lw=6,labelfontsize=11,tickfontsize=11,titlefontsize=11) + +@inline amean(a,b) = 0.5*(a + b) +@inline hmean(a,b) = 2.0/(1.0/a + 1.0/b) +@inline amean4(a,b,c,d) = 0.25*(a+b+c+d) +@inline hmean4(a,b,c,d) = 4.0/(1.0/a+1.0/b+1.0/c+1.0/d) +const av = amean +const av4 = amean4 +@views amean1(A) = 0.5.*(A[1:end-1] .+ A[2:end]) +@views avx(A) = av.(A[1:end-1,:], A[2:end,:]) +@views avy(A) = av.(A[:,1:end-1], A[:,2:end]) +@views avxy(A) = av4.(A[1:end-1,1:end-1],A[2:end,1:end-1],A[1:end-1,2:end],A[2:end,2:end]) +@views ameanx(A) = amean.(A[1:end-1,:], A[2:end,:]) +@views ameany(A) = amean.(A[:,1:end-1], A[:,2:end]) +@views ameanxy(A) = amean4.(A[1:end-1,1:end-1],A[2:end,1:end-1],A[1:end-1,2:end],A[2:end,2:end]) +@views hmeanx(A) = hmean.(A[1:end-1,:], A[2:end,:]) +@views hmeany(A) = hmean.(A[:,1:end-1], A[:,2:end]) +@views hmeanxy(A) = hmean4.(A[1:end-1,1:end-1],A[2:end,1:end-1],A[1:end-1,2:end],A[2:end,2:end]) +@views maxloc(A) = max.(A[1:end-2,1:end-2],A[1:end-2,2:end-1],A[1:end-2,3:end], + A[2:end-1,1:end-2],A[2:end-1,2:end-1],A[2:end-1,3:end], + A[3:end ,1:end-2],A[3:end ,2:end-1],A[3:end ,3:end]) +@views bc2!(A) = begin A[[1,end],:]=A[[2,end-1],:]; A[:,[1,end]]=A[:,[2,end-1]]; end + +@views function update_old!(Txx_o,Tyy_o,Txy_o,Pr_old,Txx,Tyy,Txy,Pr) + Txx_o .= Txx + Tyy_o .= Tyy + Txy_o .= Txy + # Pr .= Pr_c + Pr_old .= Pr + # λ .= 0.0 + return +end + +@views function update_iteration_params!(η,ητ) + ητ[2:end-1,2:end-1] .= maxloc(η); bc2!(ητ) + return +end + +# @views function update_stresses!((;Pr,Pr_old,Pr_c,dPr,K,Txx,Tyy,Txy,dτxx,dτyy,dτxy,τxyv,Txx_o,Tyy_o,Txy_o,dQdτxx,dQdτyy,dQdτxy,Fchk,TII,F,λ,Exx,Eyy,Exy,Exyv,Exx_ve,Eyy_ve,Exy_ve,EII_ve,η_vep,Vx,Vy,∇V,η,G,dτ_r),τ_y,sinϕ,sinψ,η_reg,relλ,dt,re_mech,vdτ,lτ,r,dx,dy,iter) +# θ_dτ = lτ*(r+2.0)/(re_mech*vdτ) +# dτ_r .= 1.0./(θ_dτ .+ η./(G.*dt) .+ 1.0) +# ∇V .= diff(Vx,dims=1)./dx .+ diff(Vy,dims=2)./dy +# # dPr .= .-∇V +# dPr .= .-∇V .- (Pr .- Pr_old)./K./dt +# # Pr .+= (r/θ_dτ).*η.*dPr +# Pr .+= dPr./(1.0./(r/θ_dτ.*η) .+ 1.0./K./dt) +# Exx .= diff(Vx,dims=1)./dx .- ∇V./3.0 +# Eyy .= diff(Vy,dims=2)./dy .- ∇V./3.0 +# Exyv[2:end-1,2:end-1] .= 0.5*(diff(Vx[2:end-1,:],dims=2)./dy .+ diff(Vy[:,2:end-1],dims=1)./dx) +# Exy .= ameanxy(Exyv) +# # visco-elastic strain rates +# Exx_ve .= Exx .+ 0.5.*Txx_o./(G.*dt) +# Eyy_ve .= Eyy .+ 0.5.*Tyy_o./(G.*dt) +# Exy_ve .= Exy .+ 0.5.*Txy_o./(G.*dt) +# EII_ve .= sqrt.(0.5.*(Exx_ve.^2 .+ Eyy_ve.^2) .+ Exy_ve.^2) +# # stress increments +# dτxx .= (.-(Txx .- Txx_o).*η./(G.*dt) .- Txx .+ 2.0.*η.*Exx).*dτ_r +# dτyy .= (.-(Tyy .- Tyy_o).*η./(G.*dt) .- Tyy .+ 2.0.*η.*Eyy).*dτ_r +# dτxy .= (.-(Txy .- Txy_o).*η./(G.*dt) .- Txy .+ 2.0.*η.*Exy).*dτ_r +# TII .= sqrt.(0.5.*((Txx.+dτxx).^2 .+ (Tyy.+dτyy).^2) .+ (Txy.+dτxy).^2) +# # # yield function +# F .= TII .- τ_y .- Pr.*sinϕ +# if iter>100 +# λ .= (1.0 .- relλ).*λ .+ relλ.*(max.(F,0.0)./(dτ_r.*η .+ η_reg .+ K.*dt.*sinϕ.*sinψ)) +# dQdτxx .= 0.5.*(Txx.+dτxx)./TII +# dQdτyy .= 0.5.*(Tyy.+dτyy)./TII +# dQdτxy .= (Txy.+dτxy)./TII +# end +# Pr_c .= Pr .+ K.*dt.*λ.*sinψ +# Txx .+= (.-(Txx .- Txx_o).*η./(G.*dt) .- Txx .+ 2.0.*η.*(Exx .- λ.*dQdτxx)).*dτ_r +# Tyy .+= (.-(Tyy .- Tyy_o).*η./(G.*dt) .- Tyy .+ 2.0.*η.*(Eyy .- λ.*dQdτyy)).*dτ_r +# Txy .+= (.-(Txy .- Txy_o).*η./(G.*dt) .- Txy .+ 2.0.*η.*(Exy .- 0.5.*λ.*dQdτxy)).*dτ_r +# τxyv[2:end-1,2:end-1] .= ameanxy(Txy) +# TII .= sqrt.(0.5.*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) +# Fchk .= TII .- τ_y .- Pr_c.*sinϕ .- λ.*η_reg +# η_vep .= TII ./ 2.0 ./ EII_ve +# return +# end + + +@views function update_stresses!(Pr,Pr_old,dPr,K,Txx,Tyy,Txy,Txx_o,Tyy_o,Txy_o,TII,Exx,Eyy,Exy,Exyv,Exx_ve,Eyy_ve,Exy_ve,EII_ve,η_vep,Vx,Vy,∇V,η,G,dτ_r,dt,re_mech,vdτ,lτ,r,dx,dy) + θ_dτ = lτ*(r+2.0)/(re_mech*vdτ) + dτ_r .= 1.0./(θ_dτ .+ η./(G.*dt) .+ 1.0) + ∇V .= diff(Vx,dims=1)./dx .+ diff(Vy,dims=2)./dy + # dPr .= .-∇V + dPr .= .-∇V .- (Pr .- Pr_old)./K./dt + # Pr .+= (r/θ_dτ).*η.*dPr + Pr .+= dPr./(1.0./(r/θ_dτ.*η) .+ 1.0./K./dt) + Exx .= diff(Vx,dims=1)./dx .- ∇V./3.0 + Eyy .= diff(Vy,dims=2)./dy .- ∇V./3.0 + Exyv[2:end-1,2:end-1] .= 0.5*(diff(Vx[2:end-1,:],dims=2)./dy .+ diff(Vy[:,2:end-1],dims=1)./dx) + Exy .= ameanxy(Exyv) + # visco-elastic strain rates + Exx_ve .= Exx .+ 0.5.*Txx_o./(G.*dt) + Eyy_ve .= Eyy .+ 0.5.*Tyy_o./(G.*dt) + Exy_ve .= Exy .+ 0.5.*Txy_o./(G.*dt) + EII_ve .= sqrt.(0.5.*(Exx_ve.^2 .+ Eyy_ve.^2) .+ Exy_ve.^2) + # stress increments + Txx .+= (.-(Txx .- Txx_o).*η./(G.*dt) .- Txx .+ 2.0.*η.*Exx).*dτ_r + Tyy .+= (.-(Tyy .- Tyy_o).*η./(G.*dt) .- Tyy .+ 2.0.*η.*Eyy).*dτ_r + Txy .+= (.-(Txy .- Txy_o).*η./(G.*dt) .- Txy .+ 2.0.*η.*Exy).*dτ_r + TII .= sqrt.(0.5.*((Txx).^2 .+ (Tyy).^2) .+ (Txy).^2) + η_vep .= TII ./ 2.0 ./ EII_ve + return +end + +@views function update_velocities!(Vx,Vy,Pr_c,Txx,Tyy,Txyv,ητ,ρgx,ρgy,vdτ,lτ,re_mech,dx,dy) + ηdτ = vdτ*lτ/re_mech + Vx[2:end-1,:] .+= (diff(.-Pr_c.+Txx,dims=1)./dx .+ diff(Txyv[2:end-1,:],dims=2)./dy .- ρgx).*ηdτ./avx(ητ) + Vy[:,2:end-1] .+= (diff(.-Pr_c.+Tyy,dims=2)./dy .+ diff(Txyv[:,2:end-1],dims=1)./dx .- ρgy).*ηdτ./avy(ητ) + return +end + +@views function compute_residuals!(r_Vx,r_Vy,Pr_c,Txx,Tyy,τxyv,ρgx,ρgy,dx,dy) + r_Vx .= diff(.-Pr_c[:,2:end-1].+Txx[:,2:end-1],dims=1)./dx .+ diff(τxyv[2:end-1,2:end-1],dims=2)./dy .- ρgx[:,2:end-1] + r_Vy .= diff(.-Pr_c[2:end-1,:].+Tyy[2:end-1,:],dims=2)./dy .+ diff(τxyv[2:end-1,2:end-1],dims=1)./dx .- ρgy[2:end-1,:] + return +end + +@views function compte_η_G_ρg!((;K,η,G,ρgy_c,phase,ηb),K0,η0,G0,ρg0,xc,yc,x0,y0c,y0d,r_cav,r_dep,δ_sd) + Threads.@threads for iy in axes(η,2) + for ix in axes(η,1) + sd_air = min(sqrt((xc[ix]-x0)^2 + 2*(yc[iy]-y0c)^2)-r_cav, + sqrt((xc[ix]-x0)^2 + 5*(yc[iy]-y0d)^2)-r_dep) + t_air = 0.5*(tanh(-sd_air/δ_sd) + 1) + t_ice = 1.0 - t_air + η[ix,iy] = t_ice*η0.ice + t_air*η0.air + G[ix,iy] = t_ice*G0.ice + t_air*G0.air + K[ix,iy] = t_ice*K0.ice + t_air*K0.air + ρgy_c[ix,iy] = t_ice*ρg0.ice + t_air*ρg0.air + phase[ix,iy] = 1.0 - t_air + ηb[ix,iy] = (1.0 - t_air)*1e12 + t_air*1.0 + end + end + return +end + +function main() + pl_correction = :native_naive + pl_correction = :native_inv1 + pl_correction = :native_inv2 + pl_correction = :native_inv3 + + #gp_correction = :loop + gp_correction = :native_gp + # gp_correction = :native_gp_dilation + + + do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) + η_reg = 8.0e-3 # regularisation "viscosity" + # Physics + Lx, Ly = 1.0, 1.0 # domain size + radi = 0.01 # inclusion radius + τ_y = 1.6 # yield stress. If do_DP=true, τ_y stand for the cohesion: c*cos(ϕ) + ϕ = 30.0 + sinϕ = sind(ϕ)*do_DP # sinus of the friction angle + μ0 = 1.0 # viscous viscosity + G0 = 1.0 # elastic shear modulus + Gi = G0/(6.0-4.0*do_DP) # elastic shear modulus perturbation + εbg = 1.0 # background strain-rate + Coh = τ_y/cosd(ϕ) # cohesion + # Coh = Inf + + # Geoparams initialisation + pl = DruckerPrager_regularised(C=Coh, ϕ=ϕ, η_vp=η_reg, Ψ=0) # non-regularized plasticity + MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, + CompositeRheology = CompositeRheology(SetConstantElasticity(G=G0, ν=0.5),LinearViscous(η=μ0), pl)), + SetMaterialParams(Name="Inclusion", Phase=2, + CompositeRheology = CompositeRheology(SetConstantElasticity(G=Gi, ν=0.5),LinearViscous(η=μ0), pl)), + ) + # Numerics + # nt = 10 # number of time steps + nx, ny = 63, 63 # numerical grid resolution + Vdmp = 4.0 # convergence acceleration (damping) + Vsc = 2.0 # iterative time step limiter + Ptsc = 6.0 # iterative time step limiter + ε = 1e-6 # nonlinear tolerence + iterMax = 3e4 # max number of iters + nout = 200 # check frequency + re_mech = 3π + lτ = min(Lx,Ly) + dx, dy = Lx/nx, Ly/ny + vdτ = 0.5*min(dx,dy)/√2.1 + r = 0.7 + # Preprocessing + dx, dy = Lx/nx, Ly/ny + dt = μ0/G0/4.0 # assumes Maxwell time of 4 + # Array initialisation + Pt = zeros(nx ,ny ) + dPt = zeros(nx ,ny ) + Pt_c = zeros(nx ,ny ) + P_o = zeros(nx, ny ) + ∇V = zeros(nx ,ny ) + Vx = zeros(nx+1,ny ) + Vy = zeros(nx ,ny+1) + Exx = zeros(nx ,ny ) + Eyy = zeros(nx ,ny ) + Exy = zeros(nx ,ny ) + Exx_ve = zeros(nx ,ny ) + Eyy_ve = zeros(nx ,ny ) + Exy_ve = zeros(nx ,ny ) + EII_ve = zeros(nx ,ny ) + Exyv = zeros(nx+1,ny+1) + Exx1 = zeros(nx ,ny ) + Eyy1 = zeros(nx ,ny ) + Exy1 = zeros(nx ,ny ) + Exyv1 = zeros(nx+1,ny+1) + Txx = zeros(nx ,ny ) + Tyy = zeros(nx ,ny ) + Txy = zeros(nx ,ny ) + Txyv = zeros(nx+1,ny+1) + Txx_o = zeros(nx ,ny ) + TII_o = zeros(nx ,ny ) + Tyy_o = zeros(nx ,ny ) + Txy_o = zeros(nx ,ny ) + Txyv_o = zeros(nx+1,ny+1) + TII = zeros(nx ,ny ) + EII = zeros(nx ,ny ) + EII_f = zeros(nx ,ny ) + F = zeros(nx ,ny ) + Fchk = zeros(nx ,ny ) + Pla = zeros(nx ,ny ) + λ = zeros(nx ,ny ) + dQdTxx = zeros(nx ,ny ) + dQdTyy = zeros(nx ,ny ) + dQdTxy = zeros(nx ,ny ) + r_Vx = zeros(nx-1,ny-2) + r_Vy = zeros(nx-2,ny-1) + dVxdt = zeros(nx-1,ny ) + dVydt = zeros(nx ,ny-1) + dtPt = zeros(nx ,ny ) + dtVx = zeros(nx-1,ny ) + dtVy = zeros(nx ,ny-1) + Rog = zeros(nx ,ny ) + η_v = μ0*ones(nx, ny) + η_vv = μ0*ones(nx+1, ny+1) + η_e = dt*G0*ones(nx, ny) + η_ev = dt*G0*ones(nx+1, ny+1) + η_ve = ones(nx, ny) + η_vev = ones(nx+1, ny+1) + η_vep = ones(nx, ny) + η_vepv = ones(nx+1, ny+1) + ητ = zeros(nx ,ny ) + dτ_r = zeros(nx ,ny ) + + η = ones(nx,ny) + Phasec = ones(Int, nx ,ny ) + Phasev = ones(Int, nx+1,ny+1) + # Initial condition + xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) + xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) + xv, yv = LinRange(0.0, Lx, nx+1), LinRange(0.0, Ly, ny+1) + (Xvx,Yvx) = ([x for x=xv,y=yc], [y for x=xv,y=yc]) + (Xvy,Yvy) = ([x for x=xc,y=yv], [y for x=xc,y=yv]) + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + η_e[radc.= ϵtol) && iter <= maxiter + update_iteration_params!(η,ητ) + # update_stresses!(fields,τ_y,sinϕ,sinψ,η_reg,relλ,dt,re_mech,vdτ,lτ,r,dx,dy,iter) + update_stresses!(Pt,Pt_old,dPt,Kb,Txx,Tyy,Txy,Txx_o,Tyy_o,Txy_o,TII,Exx,Eyy,Exy,Exyv,Exx_ve,Eyy_ve,Exy_ve,EII_ve,η_vep,Vx,Vy,∇V,η,G,dτ_r,dt,re_mech,vdτ,lτ,r,dx,dy) + update_velocities!(Vx,Vy,Pt,Txx,Tyy,Txyv,ητ,ρgx,ρgy,vdτ,lτ,re_mech,dx,dy) + + # update_velocities!(fields,vdτ,lτ,re_mech,dx,dy) + if iter % ncheck == 0 + # update residuals + compute_residuals!(r_Vx,r_Vy,Pt,Txx,Tyy,Txyv,ρgx,ρgy,dx,dy) + + errs = maximum.((abs.(r_Vx),abs.(r_Vy),abs.(dPt))) + push!(iter_evo,iter/max(nx,ny));append!(errs_evo,errs) + @printf(" iter/nx=%.3f,errs=[ %1.3e, %1.3e, %1.3e ] \n",iter/max(nx,ny),errs...) + end + iter += 1 + end + t += dt + push!(evo_t,t); push!(evo_τxx,maximum(Txx)) + # visualisation + # mask .= fields.phase; mask[mask.<0.7].=NaN + # fields.Vmag .= sqrt.(ameanx(fields.Vx).^2 + ameany(fields.Vy).^2) + # fields.TII .= sqrt.(0.5.*(fields.Txx.^2 .+ fields.Tyy.^2) .+ fields.Txy.^2) + # # p1=heatmap(xc,yc,log10.(fields.η)',title="log10(η)";opts...) + # p1=heatmap(xc,yc,mask' .* fields.Pr',title="Pressure";opts...) + # p3=heatmap(xc,yc,mask' .* fields.TII',title="TII";opts...) + # p2=heatmap(xc,yc,mask' .* fields.η_vep',title="η_vep";opts...) + # # p2=heatmap(xc,yc,#=mask' .*=# fields.F',title="F";opts...) + # # p3=heatmap(xc[2:end-1],yc[2:end-1],mask[2:end-1,2:end-1]' .* ameany(fields.r_Vy)',title="Vmag";opts...) + # p4=heatmap(xc,yc,mask' .* fields.Vmag',title="Vmag";opts...) + # # p4=plot(evo_t,evo_τxx,legend=false,xlabel="time",ylabel="max(Txx)",linewidth=0,markershape=:circle,markersize=3,framestyle=:box) + # display(plot(p1,p2,p3,p4,layout=(2,2))) + # png(plot(p1,p2,p3,p4,layout=(2,2)),@sprintf("anim/%04d.png",iframe+=1)) + + # TII .= sqrt.(0.5.*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) + # p2=heatmap(xc,yc, Tii',title="η_vep") + # display(p2) + end + return evo_t, evo_τxx +end + +evo_t, evo_τxx = main() +plot(evo_t, evo_τxx) \ No newline at end of file From cc9f03b94db62e943a260eea3aad141ca2e3292d Mon Sep 17 00:00:00 2001 From: albert-de-montserrat Date: Fri, 11 Nov 2022 17:09:54 +0100 Subject: [PATCH 37/49] visco-elasticity working with GP --- ...kes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl | 121 +++++++++++++----- 1 file changed, 87 insertions(+), 34 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl index 97d126f..b34ae33 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl @@ -1,6 +1,6 @@ -using ElasticArrays,Printf +using ElasticArrays, Printf, GeoParams using Plots,Plots.Measures -default(size=(800,500),framestyle=:box,label=false,grid=false,margin=3mm,lw=6,labelfontsize=11,tickfontsize=11,titlefontsize=11) +default(size=(800,500),framestyle=:box,label=false,grid=false,lw=6,labelfontsize=11,tickfontsize=11,titlefontsize=11) @inline amean(a,b) = 0.5*(a + b) @inline hmean(a,b) = 2.0/(1.0/a + 1.0/b) @@ -79,6 +79,50 @@ end # return # end +function update_stress_GP2!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, Exyv, η, η_vep, Pt, Phasec, Phasev, MatParam, dt, G, lτ, r, re_mech, vdτ) + θ_dτ = lτ*(r+2.0)/(re_mech*vdτ) + @inbounds for j in axes(Exx,2), i in axes(Exx,1) + dτ_r = 1.0/(θ_dτ + 1/η_vep[i,j]) # equivalent to dτ_r = @. 1.0/(θ_dτ + η/(G*dt) + 1.0) + args = (; dt=dt, P=Pt[i,j], τII_old=0.0) + # # gather strain rate + εij_v = ( + Exyv[i ,j ], + Exyv[i+1,j ], + Exyv[i ,j+1], + Exyv[i+1,j+1] + ) # gather vertices around ij center + + εij_p = (Exx[i,j], Eyy[i,j], εij_v) + # gather deviatoric stress + τij_v = ( + Txyv_o[i ,j ], + Txyv_o[i+1,j ], + Txyv_o[i ,j+1], + Txyv_o[i+1,j+1] + ) # gather vertices around ij center + τij_p_o = (Txx_o[i,j], Tyy_o[i,j], τij_v) + # gathermaterial phases + phases_v = ( + Phasev[i ,j ], + Phasev[i+1,j ], + Phasev[i ,j+1], + Phasev[i+1,j+1] + ) # gather vertices around ij center + phases = (Phasec[i,j], Phasec[i,j], phases_v) + # update stress and effective viscosity + Tij, Tii[i,j], η_vep[i,j] = compute_τij(MatParam, εij_p, args, τij_p_o, phases) + + # need to compute τij/η_ve(p?) in + # Txx[i,j] += dτ_r * (-(Txx[i,j])/(G[i,j]*dt) - Txx[i,j]/η[i,j] + 2*ε_eff[1]) + # Tyy[i,j] += dτ_r * (-(Tyy[i,j])/(G[i,j]*dt) - Tyy[i,j]/η[i,j] + 2*ε_eff[2]) + # Txy[i,j] += dτ_r * (-(Txy[i,j])/(G[i,j]*dt) - Txy[i,j]/η[i,j] + 2*ε_eff[3]) + + Txx[i,j] += dτ_r * (-(Txx[i,j]) + Tij[1] ) / η_vep[i,j] # NOTE: from GP Tij = 2*η_vep * εij + Tyy[i,j] += dτ_r * (-(Tyy[i,j]) + Tij[2] ) / η_vep[i,j] + Txy[i,j] += dτ_r * (-(Txy[i,j]) + Tij[3] ) / η_vep[i,j] + + end +end @views function update_stresses!(Pr,Pr_old,dPr,K,Txx,Tyy,Txy,Txx_o,Tyy_o,Txy_o,TII,Exx,Eyy,Exy,Exyv,Exx_ve,Eyy_ve,Exy_ve,EII_ve,η_vep,Vx,Vy,∇V,η,G,dτ_r,dt,re_mech,vdτ,lτ,r,dx,dy) θ_dτ = lτ*(r+2.0)/(re_mech*vdτ) @@ -98,11 +142,26 @@ end Exy_ve .= Exy .+ 0.5.*Txy_o./(G.*dt) EII_ve .= sqrt.(0.5.*(Exx_ve.^2 .+ Eyy_ve.^2) .+ Exy_ve.^2) # stress increments - Txx .+= (.-(Txx .- Txx_o).*η./(G.*dt) .- Txx .+ 2.0.*η.*Exx).*dτ_r - Tyy .+= (.-(Tyy .- Tyy_o).*η./(G.*dt) .- Tyy .+ 2.0.*η.*Eyy).*dτ_r - Txy .+= (.-(Txy .- Txy_o).*η./(G.*dt) .- Txy .+ 2.0.*η.*Exy).*dτ_r - TII .= sqrt.(0.5.*((Txx).^2 .+ (Tyy).^2) .+ (Txy).^2) - η_vep .= TII ./ 2.0 ./ EII_ve + Txx .+= (.-(Txx .- Txx_o)./(G.*dt) .- Txx./η .+ 2.0.*Exx).*dτ_r + Tyy .+= (.-(Tyy .- Tyy_o)./(G.*dt) .- Tyy./η .+ 2.0.*Eyy).*dτ_r + Txy .+= (.-(Txy .- Txy_o)./(G.*dt) .- Txy./η .+ 2.0.*Exy).*dτ_r + TII .= sqrt.(0.5.*((Txx).^2 .+ (Tyy).^2) .+ (Txy).^2) + η_vep .= TII ./ 2.0 ./ EII_ve + return +end + +@views function update_P_strain!(Pr,Pr_old,dPr,K,Exx,Eyy,Exy,Exyv,Vx,Vy,∇V,η,G,dτ_r,dt,re_mech,vdτ,lτ,r,dx,dy) + θ_dτ = lτ*(r+2.0)/(re_mech*vdτ) + dτ_r .= 1.0./(θ_dτ .+ η./(G.*dt) .+ 1.0) + ∇V .= diff(Vx,dims=1)./dx .+ diff(Vy,dims=2)./dy + # dPr .= .-∇V + dPr .= .-∇V .- (Pr .- Pr_old)./K./dt + # Pr .+= (r/θ_dτ).*η.*dPr + Pr .+= dPr./(1.0./(r/θ_dτ.*η) .+ 1.0./K./dt) + Exx .= diff(Vx,dims=1)./dx .- ∇V./3.0 + Eyy .= diff(Vy,dims=2)./dy .- ∇V./3.0 + Exyv[2:end-1,2:end-1] .= 0.5*(diff(Vx[2:end-1,:],dims=2)./dy .+ diff(Vy[:,2:end-1],dims=1)./dx) + Exy .= ameanxy(Exyv) return end @@ -119,25 +178,8 @@ end return end -@views function compte_η_G_ρg!((;K,η,G,ρgy_c,phase,ηb),K0,η0,G0,ρg0,xc,yc,x0,y0c,y0d,r_cav,r_dep,δ_sd) - Threads.@threads for iy in axes(η,2) - for ix in axes(η,1) - sd_air = min(sqrt((xc[ix]-x0)^2 + 2*(yc[iy]-y0c)^2)-r_cav, - sqrt((xc[ix]-x0)^2 + 5*(yc[iy]-y0d)^2)-r_dep) - t_air = 0.5*(tanh(-sd_air/δ_sd) + 1) - t_ice = 1.0 - t_air - η[ix,iy] = t_ice*η0.ice + t_air*η0.air - G[ix,iy] = t_ice*G0.ice + t_air*G0.air - K[ix,iy] = t_ice*K0.ice + t_air*K0.air - ρgy_c[ix,iy] = t_ice*ρg0.ice + t_air*ρg0.air - phase[ix,iy] = 1.0 - t_air - ηb[ix,iy] = (1.0 - t_air)*1e12 + t_air*1.0 - end - end - return -end -function main() +function main(UseGP) pl_correction = :native_naive pl_correction = :native_inv1 pl_correction = :native_inv2 @@ -147,7 +189,6 @@ function main() gp_correction = :native_gp # gp_correction = :native_gp_dilation - do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) η_reg = 8.0e-3 # regularisation "viscosity" # Physics @@ -161,7 +202,7 @@ function main() Gi = G0/(6.0-4.0*do_DP) # elastic shear modulus perturbation εbg = 1.0 # background strain-rate Coh = τ_y/cosd(ϕ) # cohesion - # Coh = Inf + Coh = Inf # Geoparams initialisation pl = DruckerPrager_regularised(C=Coh, ϕ=ϕ, η_vp=η_reg, Ψ=0) # non-regularized plasticity @@ -260,7 +301,7 @@ function main() η_ev[radv.= ϵtol) && iter <= maxiter update_iteration_params!(η,ητ) - # update_stresses!(fields,τ_y,sinϕ,sinψ,η_reg,relλ,dt,re_mech,vdτ,lτ,r,dx,dy,iter) - update_stresses!(Pt,Pt_old,dPt,Kb,Txx,Tyy,Txy,Txx_o,Tyy_o,Txy_o,TII,Exx,Eyy,Exy,Exyv,Exx_ve,Eyy_ve,Exy_ve,EII_ve,η_vep,Vx,Vy,∇V,η,G,dτ_r,dt,re_mech,vdτ,lτ,r,dx,dy) + + if UseGP + update_P_strain!(Pt,Pt_old,dPt,Kb,Exx,Eyy,Exy,Exyv,Vx,Vy,∇V,η,G,dτ_r,dt,re_mech,vdτ,lτ,r,dx,dy) + update_stress_GP2!(Txx, Tyy, Txy, TII, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, Exyv, η, η_vep, Pt, Phasec, Phasev, MatParam, dt,G, lτ, r, re_mech, vdτ) + else + update_stresses!(Pt,Pt_old,dPt,Kb,Txx,Tyy,Txy,Txx_o,Tyy_o,Txy_o,TII,Exx,Eyy,Exy,Exyv,Exx_ve,Eyy_ve,Exy_ve,EII_ve,η_vep,Vx,Vy,∇V,η,G,dτ_r,dt,re_mech,vdτ,lτ,r,dx,dy) + end update_velocities!(Vx,Vy,Pt,Txx,Tyy,Txyv,ητ,ρgx,ρgy,vdτ,lτ,re_mech,dx,dy) # update_velocities!(fields,vdτ,lτ,re_mech,dx,dy) @@ -329,8 +375,15 @@ function main() # p2=heatmap(xc,yc, Tii',title="η_vep") # display(p2) end - return evo_t, evo_τxx + return evo_t, evo_τxx, iter_evo end -evo_t, evo_τxx = main() -plot(evo_t, evo_τxx) \ No newline at end of file +@time evo_t, evo_τxx_GP, iter_evo_GP = main(true) +@time evo_t, evo_τxx, iter_evo = main(false) + +# sol = @. 2.0*1*1*(1.0-exp(-evo_t*1/1)) +# plot(evo_t, evo_τxx, color=:black) +# plot!(evo_t, evo_τxx_GP, color=:red) +# scatter!(evo_t, sol) + +plot(evo_t, @.((evo_τxx-evo_τxx_GP)/evo_τxx*100), color=:black) From f10d89362b6bba4c0e88c4a3b569de24cfa6e20f Mon Sep 17 00:00:00 2001 From: albert-de-montserrat Date: Fri, 11 Nov 2022 17:35:05 +0100 Subject: [PATCH 38/49] bugfix & working plasticity --- ...kes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl | 82 ++++++++----------- 1 file changed, 34 insertions(+), 48 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl index b34ae33..5491e76 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl @@ -38,7 +38,7 @@ end return end -# @views function update_stresses!((;Pr,Pr_old,Pr_c,dPr,K,Txx,Tyy,Txy,dτxx,dτyy,dτxy,τxyv,Txx_o,Tyy_o,Txy_o,dQdτxx,dQdτyy,dQdτxy,Fchk,TII,F,λ,Exx,Eyy,Exy,Exyv,Exx_ve,Eyy_ve,Exy_ve,EII_ve,η_vep,Vx,Vy,∇V,η,G,dτ_r),τ_y,sinϕ,sinψ,η_reg,relλ,dt,re_mech,vdτ,lτ,r,dx,dy,iter) +# @views function update_stresses!((;Pr,Pr_old,Pr_c,dPr,K,Txx,Tyy,Txy,dτxx,dτyy,dTxyv,Txyv,Txx_o,Tyy_o,Txy_o,dQdτxx,dQdτyy,dQdTxyv,Fchk,TII,F,λ,Exx,Eyy,Exy,Exyv,Exx_ve,Eyy_ve,Exy_ve,EII_ve,η_vep,Vx,Vy,∇V,η,G,dτ_r),τ_y,sinϕ,sinψ,η_reg,relλ,dt,re_mech,vdτ,lτ,r,dx,dy,iter) # θ_dτ = lτ*(r+2.0)/(re_mech*vdτ) # dτ_r .= 1.0./(θ_dτ .+ η./(G.*dt) .+ 1.0) # ∇V .= diff(Vx,dims=1)./dx .+ diff(Vy,dims=2)./dy @@ -58,28 +58,28 @@ end # # stress increments # dτxx .= (.-(Txx .- Txx_o).*η./(G.*dt) .- Txx .+ 2.0.*η.*Exx).*dτ_r # dτyy .= (.-(Tyy .- Tyy_o).*η./(G.*dt) .- Tyy .+ 2.0.*η.*Eyy).*dτ_r -# dτxy .= (.-(Txy .- Txy_o).*η./(G.*dt) .- Txy .+ 2.0.*η.*Exy).*dτ_r -# TII .= sqrt.(0.5.*((Txx.+dτxx).^2 .+ (Tyy.+dτyy).^2) .+ (Txy.+dτxy).^2) +# dTxyv .= (.-(Txy .- Txy_o).*η./(G.*dt) .- Txy .+ 2.0.*η.*Exy).*dτ_r +# TII .= sqrt.(0.5.*((Txx.+dτxx).^2 .+ (Tyy.+dτyy).^2) .+ (Txy.+dTxyv).^2) # # # yield function # F .= TII .- τ_y .- Pr.*sinϕ # if iter>100 # λ .= (1.0 .- relλ).*λ .+ relλ.*(max.(F,0.0)./(dτ_r.*η .+ η_reg .+ K.*dt.*sinϕ.*sinψ)) # dQdτxx .= 0.5.*(Txx.+dτxx)./TII # dQdτyy .= 0.5.*(Tyy.+dτyy)./TII -# dQdτxy .= (Txy.+dτxy)./TII +# dQdTxyv .= (Txy.+dTxyv)./TII # end # Pr_c .= Pr .+ K.*dt.*λ.*sinψ # Txx .+= (.-(Txx .- Txx_o).*η./(G.*dt) .- Txx .+ 2.0.*η.*(Exx .- λ.*dQdτxx)).*dτ_r # Tyy .+= (.-(Tyy .- Tyy_o).*η./(G.*dt) .- Tyy .+ 2.0.*η.*(Eyy .- λ.*dQdτyy)).*dτ_r -# Txy .+= (.-(Txy .- Txy_o).*η./(G.*dt) .- Txy .+ 2.0.*η.*(Exy .- 0.5.*λ.*dQdτxy)).*dτ_r -# τxyv[2:end-1,2:end-1] .= ameanxy(Txy) +# Txy .+= (.-(Txy .- Txy_o).*η./(G.*dt) .- Txy .+ 2.0.*η.*(Exy .- 0.5.*λ.*dQdTxyv)).*dτ_r +# Txyv[2:end-1,2:end-1] .= ameanxy(Txy) # TII .= sqrt.(0.5.*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) # Fchk .= TII .- τ_y .- Pr_c.*sinϕ .- λ.*η_reg # η_vep .= TII ./ 2.0 ./ EII_ve # return # end -function update_stress_GP2!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, Exyv, η, η_vep, Pt, Phasec, Phasev, MatParam, dt, G, lτ, r, re_mech, vdτ) +function update_stress_GP2!(Txx, Tyy, Txy, Txyv, Tii, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, Exyv, η, η_vep, Pt, Phasec, Phasev, MatParam, dt, G, lτ, r, re_mech, vdτ) θ_dτ = lτ*(r+2.0)/(re_mech*vdτ) @inbounds for j in axes(Exx,2), i in axes(Exx,1) dτ_r = 1.0/(θ_dτ + 1/η_vep[i,j]) # equivalent to dτ_r = @. 1.0/(θ_dτ + η/(G*dt) + 1.0) @@ -120,11 +120,12 @@ function update_stress_GP2!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, Txx[i,j] += dτ_r * (-(Txx[i,j]) + Tij[1] ) / η_vep[i,j] # NOTE: from GP Tij = 2*η_vep * εij Tyy[i,j] += dτ_r * (-(Tyy[i,j]) + Tij[2] ) / η_vep[i,j] Txy[i,j] += dτ_r * (-(Txy[i,j]) + Tij[3] ) / η_vep[i,j] - end + Txyv[2:end-1,2:end-1] .= ameanxy(Txy) + end -@views function update_stresses!(Pr,Pr_old,dPr,K,Txx,Tyy,Txy,Txx_o,Tyy_o,Txy_o,TII,Exx,Eyy,Exy,Exyv,Exx_ve,Eyy_ve,Exy_ve,EII_ve,η_vep,Vx,Vy,∇V,η,G,dτ_r,dt,re_mech,vdτ,lτ,r,dx,dy) +@views function update_stresses!(Pr,Pr_old,dPr,K,Txx,Tyy,Txy,Txyv,Txx_o,Tyy_o,Txy_o,TII,Exx,Eyy,Exy,Exyv,Exx_ve,Eyy_ve,Exy_ve,EII_ve,η_vep,Vx,Vy,∇V,η,G,dτ_r,dt,re_mech,vdτ,lτ,r,dx,dy) θ_dτ = lτ*(r+2.0)/(re_mech*vdτ) dτ_r .= 1.0./(θ_dτ .+ η./(G.*dt) .+ 1.0) ∇V .= diff(Vx,dims=1)./dx .+ diff(Vy,dims=2)./dy @@ -145,6 +146,7 @@ end Txx .+= (.-(Txx .- Txx_o)./(G.*dt) .- Txx./η .+ 2.0.*Exx).*dτ_r Tyy .+= (.-(Tyy .- Tyy_o)./(G.*dt) .- Tyy./η .+ 2.0.*Eyy).*dτ_r Txy .+= (.-(Txy .- Txy_o)./(G.*dt) .- Txy./η .+ 2.0.*Exy).*dτ_r + Txyv[2:end-1,2:end-1] .= ameanxy(Txy) TII .= sqrt.(0.5.*((Txx).^2 .+ (Tyy).^2) .+ (Txy).^2) η_vep .= TII ./ 2.0 ./ EII_ve return @@ -172,13 +174,12 @@ end return end -@views function compute_residuals!(r_Vx,r_Vy,Pr_c,Txx,Tyy,τxyv,ρgx,ρgy,dx,dy) - r_Vx .= diff(.-Pr_c[:,2:end-1].+Txx[:,2:end-1],dims=1)./dx .+ diff(τxyv[2:end-1,2:end-1],dims=2)./dy .- ρgx[:,2:end-1] - r_Vy .= diff(.-Pr_c[2:end-1,:].+Tyy[2:end-1,:],dims=2)./dy .+ diff(τxyv[2:end-1,2:end-1],dims=1)./dx .- ρgy[2:end-1,:] +@views function compute_residuals!(r_Vx,r_Vy,Pr_c,Txx,Tyy,Txyv,ρgx,ρgy,dx,dy) + r_Vx .= diff(.-Pr_c[:,2:end-1].+Txx[:,2:end-1],dims=1)./dx .+ diff(Txyv[2:end-1,2:end-1],dims=2)./dy .- ρgx[:,2:end-1] + r_Vy .= diff(.-Pr_c[2:end-1,:].+Tyy[2:end-1,:],dims=2)./dy .+ diff(Txyv[2:end-1,2:end-1],dims=1)./dx .- ρgy[2:end-1,:] return end - function main(UseGP) pl_correction = :native_naive pl_correction = :native_inv1 @@ -202,7 +203,7 @@ function main(UseGP) Gi = G0/(6.0-4.0*do_DP) # elastic shear modulus perturbation εbg = 1.0 # background strain-rate Coh = τ_y/cosd(ϕ) # cohesion - Coh = Inf + # Coh = Inf # Geoparams initialisation pl = DruckerPrager_regularised(C=Coh, ϕ=ϕ, η_vp=η_reg, Ψ=0) # non-regularized plasticity @@ -244,10 +245,6 @@ function main(UseGP) Exy_ve = zeros(nx ,ny ) EII_ve = zeros(nx ,ny ) Exyv = zeros(nx+1,ny+1) - Exx1 = zeros(nx ,ny ) - Eyy1 = zeros(nx ,ny ) - Exy1 = zeros(nx ,ny ) - Exyv1 = zeros(nx+1,ny+1) Txx = zeros(nx ,ny ) Tyy = zeros(nx ,ny ) Txy = zeros(nx ,ny ) @@ -269,20 +266,10 @@ function main(UseGP) dQdTxy = zeros(nx ,ny ) r_Vx = zeros(nx-1,ny-2) r_Vy = zeros(nx-2,ny-1) - dVxdt = zeros(nx-1,ny ) - dVydt = zeros(nx ,ny-1) - dtPt = zeros(nx ,ny ) - dtVx = zeros(nx-1,ny ) - dtVy = zeros(nx ,ny-1) - Rog = zeros(nx ,ny ) η_v = μ0*ones(nx, ny) - η_vv = μ0*ones(nx+1, ny+1) η_e = dt*G0*ones(nx, ny) η_ev = dt*G0*ones(nx+1, ny+1) - η_ve = ones(nx, ny) - η_vev = ones(nx+1, ny+1) η_vep = ones(nx, ny) - η_vepv = ones(nx+1, ny+1) ητ = zeros(nx ,ny ) dτ_r = zeros(nx ,ny ) @@ -293,21 +280,20 @@ function main(UseGP) xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) xv, yv = LinRange(0.0, Lx, nx+1), LinRange(0.0, Ly, ny+1) - (Xvx,Yvx) = ([x for x=xv,y=yc], [y for x=xv,y=yc]) - (Xvy,Yvy) = ([x for x=xc,y=yv], [y for x=xc,y=yv]) - radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 - radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + Xvx = [x for x=xv,y=yc] + Yvy = [y for x=xc,y=yv] + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 η_e[radc. Date: Fri, 11 Nov 2022 18:17:12 +0100 Subject: [PATCH 39/49] Auto stash before merge of "add-GeoParams-examples" and "origin/add-GeoParams-examples" --- GeoParams_PT_examples/Manifest.toml | 10 +++++++-- GeoParams_PT_examples/Project.toml | 1 + .../Stokes2D_VEP_reg_ctau_GP_dimensional.jl | 4 ++-- .../Stokes2D_VEP_reg_ctau_inv_GeoParams.jl | 22 ++++++++++++++----- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/GeoParams_PT_examples/Manifest.toml b/GeoParams_PT_examples/Manifest.toml index e64d0b2..ed3b682 100644 --- a/GeoParams_PT_examples/Manifest.toml +++ b/GeoParams_PT_examples/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.8.2" manifest_format = "2.0" -project_hash = "3acd3157c619d661bbd583bb97bd1c274825a665" +project_hash = "cb9741e83719ef7e84184b6d1f7936282dd3e190" [[deps.Adapt]] deps = ["LinearAlgebra"] @@ -175,6 +175,12 @@ deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"] uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" version = "1.6.0" +[[deps.ElasticArrays]] +deps = ["Adapt"] +git-tree-sha1 = "d1933fd3e53e01e2d0ae98b8f7f65784e2d5430b" +uuid = "fdbdab4c-e67f-52f5-8c3f-e7b388dad3d4" +version = "1.2.10" + [[deps.Expat_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "bad72f730e9e91c08d9427d5e8db95478a3c323d" @@ -261,7 +267,7 @@ version = "0.69.1+0" [[deps.GeoParams]] deps = ["BibTeX", "DelimitedFiles", "ForwardDiff", "Interpolations", "KernelDensitySJ", "LaTeXStrings", "Loess", "Parameters", "Requires", "Roots", "Setfield", "SpecialFunctions", "Static", "StaticArrays", "Statistics", "StatsBase", "UnPack", "Unidecode", "Unitful"] -git-tree-sha1 = "52b20f3408c80ad6d351b4c4e82ee09d83192e5a" +git-tree-sha1 = "e84aa62d2813f28e5241bbe88b327a266cc889f0" repo-rev = "adm-tuples" repo-url = "https://github.com/JuliaGeodynamics/GeoParams.jl.git" uuid = "e018b62d-d9de-4a26-8697-af89c310ae38" diff --git a/GeoParams_PT_examples/Project.toml b/GeoParams_PT_examples/Project.toml index 3b26e59..3b833f7 100644 --- a/GeoParams_PT_examples/Project.toml +++ b/GeoParams_PT_examples/Project.toml @@ -4,6 +4,7 @@ authors = ["Duretz Thibault "] version = "0.1.0" [deps] +ElasticArrays = "fdbdab4c-e67f-52f5-8c3f-e7b388dad3d4" GeoParams = "e018b62d-d9de-4a26-8697-af89c310ae38" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_GP_dimensional.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_GP_dimensional.jl index cf1443c..2fe1962 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_GP_dimensional.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_GP_dimensional.jl @@ -14,8 +14,8 @@ const Dat = Float64 # Precision (double=Float64 or single=Float32) do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) η_reg = 1.5e20Pas # regularisation "viscosity" # Physics - Lx, Ly = 100km,100km # domain size - radi = 1km # inclusion radius + Lx, Ly = 100km,50km # domain size + radi = 1km # inclusion radius τ_y = 35MPa # yield stress. If do_DP=true, τ_y stand for the cohesion: c*cos(ϕ) ϕ = 30.0*do_DP μ0 = 1e23Pas # viscous viscosity diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl index de5903f..bf90c5f 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams.jl @@ -56,6 +56,14 @@ function update_stress_GP2!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, end end +# Update sum of volumetric strainrate @ every point +function update_Evol!(Evol, Pt, P_o, Phasec, MatParam, dt) + @inbounds for j in axes(Evol,2), i in axes(Evol,1) + args = (; dt=dt, τII_old=0.0, P_old=P_o[i,j]) + Evol[i,j] = GeoParams.nphase(vi -> compute_εvol(vi.CompositeRheology[1], Pt[i,j], args), Phasec[i,j], MatParam) + end +end + # 2D Stokes routine @views function Stokes2D_vep(UseGeoParams, nt) pl_correction = :native_naive @@ -64,8 +72,8 @@ end pl_correction = :native_inv3 #gp_correction = :loop - gp_correction = :native_gp - #gp_correction = :native_gp_dilation + #gp_correction = :native_gp + gp_correction = :native_gp_dilation do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) @@ -110,6 +118,7 @@ end Vy = zeros(Dat, nx ,ny+1) Exx = zeros(Dat, nx ,ny ) Eyy = zeros(Dat, nx ,ny ) + Evol = zeros(Dat, nx ,ny ) Exy = zeros(Dat, nx ,ny ) Exyv = zeros(Dat, nx+1,ny+1) Exx1 = zeros(Dat, nx ,ny ) @@ -175,12 +184,12 @@ end to = TimerOutput() for it = 1:nt iter=1; err=2*ε; err_evo1=Float64[]; err_evo2=Float64[] - Txx_o.=Txx; Tyy_o.=Tyy; Txy_o.=av(Txyv); Txyv_o.=Txyv; λ.=0.0; P_o .= Pt + Txx_o.=Txx; Tyy_o.=Tyy; Txy_o.=av(Txyv); Txyv_o.=Txyv; λ.=0.0; P_o .= Pt; Evol .= 0.0 local itg while (err>ε && iter<=iterMax) # divergence - pressure ∇V .= diff(Vx, dims=1)./dx .+ diff(Vy, dims=2)./dy - Pt .= Pt .- dtPt.*∇V + Pt .= Pt .- dtPt.*(∇V .- Evol) # strain rates Exx .= diff(Vx, dims=1)./dx .- 1.0/3.0*∇V Eyy .= diff(Vy, dims=2)./dy .- 1.0/3.0*∇V @@ -195,6 +204,9 @@ end update_stress_GP2!(Txx, Tyy, Txy, Tii, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, Exyv, η_vep, Pt, Phasec, Phasev, MatParam, dt) elseif gp_correction == :native_gp_dilation compute_p_τij_stagcenter!(Txx, Tyy, Txy, Tii, η_vep, Pt, Exx, Eyy, Exyv, P_o, Txx_o, Tyy_o, Txyv_o, Phasec, Phasev, MatParam, dt) + + update_Evol!(Evol, Pt, P_o, Phasec, MatParam, dt) # compute volumetrix strainrates @ every cell + @show maximum(Evol) end end else @@ -337,6 +349,6 @@ end end #@time evo_t, evo_Txx, to = Stokes2D_vep(false, 12) # 2nd argument = timesteps 7.311026 seconds (2.91 M allocations: 16.403 GiB, 16.54% gc time) -@time evo_t, evo_Txx_GP, to_GP = Stokes2D_vep(true, 12) # 2nd argument = timesteps 9.368483 seconds (2.73 M allocations: 13.804 GiB, 8.24% gc time) +@time evo_t, evo_Txx_GP, to_GP = Stokes2D_vep(true, 2) # 2nd argument = timesteps 9.368483 seconds (2.73 M allocations: 13.804 GiB, 8.24% gc time) #plot(evo_t, @.((evo_Txx-evo_Txx_GP)/evo_Txx*100), ylabel="error (%)", xlabel="time" ) \ No newline at end of file From c8e305751d39b8fd9d1b8efdace0bd48445b7ad8 Mon Sep 17 00:00:00 2001 From: albert-de-montserrat Date: Fri, 11 Nov 2022 19:59:08 +0100 Subject: [PATCH 40/49] geting closer (stress slightly lower) --- ...kes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl | 81 ++++++++++++------- 1 file changed, 53 insertions(+), 28 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl index 5491e76..9edffce 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl @@ -23,16 +23,18 @@ const av4 = amean4 A[3:end ,1:end-2],A[3:end ,2:end-1],A[3:end ,3:end]) @views bc2!(A) = begin A[[1,end],:]=A[[2,end-1],:]; A[:,[1,end]]=A[:,[2,end-1]]; end -@views function update_old!(Txx_o,Tyy_o,Txy_o,Pr_old,Txx,Tyy,Txy,Pr) - Txx_o .= Txx - Tyy_o .= Tyy - Txy_o .= Txy +@views function update_old!(Txx_o,Tyy_o,Txy_o,Txyv_o,Pr_old,Txx,Tyy,Txy,Txyv,Pr) + copyto!(Txx_o , Txx) + copyto!(Tyy_o , Tyy) + copyto!(Txy_o , Txy) + copyto!(Txyv_o, Txyv) + copyto!(Pr_old, Pr) # Pr .= Pr_c - Pr_old .= Pr # λ .= 0.0 return end + @views function update_iteration_params!(η,ητ) ητ[2:end-1,2:end-1] .= maxloc(η); bc2!(ητ) return @@ -79,9 +81,11 @@ end # return # end -function update_stress_GP2!(Txx, Tyy, Txy, Txyv, Tii, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, Exyv, η, η_vep, Pt, Phasec, Phasev, MatParam, dt, G, lτ, r, re_mech, vdτ) + +function update_stress_GP2!(Txx, Tyy, Txy, Txyv, Tii, Txx_o, Tyy_o, Txy_o, Txyv_o, Exx, Eyy, Exyv, η, η_vep, Pt, Phasec, Phasev, MatParam, dt, G, lτ, r, re_mech, vdτ) θ_dτ = lτ*(r+2.0)/(re_mech*vdτ) - @inbounds for j in axes(Exx,2), i in axes(Exx,1) + for j in axes(Exx,2), i in axes(Exx,1) + # dτ_r = 1.0/(θ_dτ + η[i,j]/(G[i,j]*dt) + 1.0) dτ_r = 1.0/(θ_dτ + 1/η_vep[i,j]) # equivalent to dτ_r = @. 1.0/(θ_dτ + η/(G*dt) + 1.0) args = (; dt=dt, P=Pt[i,j], τII_old=0.0) # # gather strain rate @@ -93,13 +97,20 @@ function update_stress_GP2!(Txx, Tyy, Txy, Txyv, Tii, Txx_o, Tyy_o, Txyv_o, Exx, ) # gather vertices around ij center εij_p = (Exx[i,j], Eyy[i,j], εij_v) - # gather deviatoric stress + # # gather deviatoric stress + # τij_v = ( + # Txyv_o[i ,j ], + # Txyv_o[i+1,j ], + # Txyv_o[i ,j+1], + # Txyv_o[i+1,j+1] + # ) # gather vertices around ij center + # τij_p_o = (Txx_o[i,j], Tyy_o[i,j], τij_v) τij_v = ( - Txyv_o[i ,j ], - Txyv_o[i+1,j ], - Txyv_o[i ,j+1], - Txyv_o[i+1,j+1] - ) # gather vertices around ij center + Txy_o[i,j], + Txy_o[i,j], + Txy_o[i,j], + Txy_o[i,j] + ) τij_p_o = (Txx_o[i,j], Tyy_o[i,j], τij_v) # gathermaterial phases phases_v = ( @@ -111,15 +122,29 @@ function update_stress_GP2!(Txx, Tyy, Txy, Txyv, Tii, Txx_o, Tyy_o, Txyv_o, Exx, phases = (Phasec[i,j], Phasec[i,j], phases_v) # update stress and effective viscosity Tij, Tii[i,j], η_vep[i,j] = compute_τij(MatParam, εij_p, args, τij_p_o, phases) - + Exy = sum(εij_v)*0.25 + xyv_o = sum(τij_v)*0.25 + # need to compute τij/η_ve(p?) in + # Txx[i,j] += dτ_r * (-(Txx[i,j] - Txx_o[i,j])/(G[i,j]*dt) - Txx[i,j]/η[i,j] + 2*Exx[i,j]) + # Tyy[i,j] += dτ_r * (-(Tyy[i,j] - Tyy_o[i,j])/(G[i,j]*dt) - Tyy[i,j]/η[i,j] + 2*Eyy[i,j]) + # Txy[i,j] += dτ_r * (-(Txy[i,j] - xyv_o)/(G[i,j]*dt) - Txy[i,j]/η[i,j] + 2*sum(εij_v)/4) + + Txx[i,j] += dτ_r * (-Txx[i,j] /(G[i,j]*dt) - Txx[i,j]/η[i,j] + Tij[1] / η_vep[i,j]) + Tyy[i,j] += dτ_r * (-Tyy[i,j] /(G[i,j]*dt) - Tyy[i,j]/η[i,j] + Tij[2] / η_vep[i,j]) + Txy[i,j] += dτ_r * (-Txy[i,j] /(G[i,j]*dt) - Txy[i,j]/η[i,j] + Tij[3] / η_vep[i,j]) + # Txx[i,j] += dτ_r * (-(Txx[i,j])/(G[i,j]*dt) - Txx[i,j]/η[i,j] + 2*ε_eff[1]) # Tyy[i,j] += dτ_r * (-(Tyy[i,j])/(G[i,j]*dt) - Tyy[i,j]/η[i,j] + 2*ε_eff[2]) # Txy[i,j] += dτ_r * (-(Txy[i,j])/(G[i,j]*dt) - Txy[i,j]/η[i,j] + 2*ε_eff[3]) - Txx[i,j] += dτ_r * (-(Txx[i,j]) + Tij[1] ) / η_vep[i,j] # NOTE: from GP Tij = 2*η_vep * εij - Tyy[i,j] += dτ_r * (-(Tyy[i,j]) + Tij[2] ) / η_vep[i,j] - Txy[i,j] += dτ_r * (-(Txy[i,j]) + Tij[3] ) / η_vep[i,j] + # Txx[i,j] += dτ_r * (-(Txx[i,j])/(G[i,j]*dt) - Txx[i,j]/η[i,j] + Tij[1] / η_vep[i,j]) + # Tyy[i,j] += dτ_r * (-(Tyy[i,j])/(G[i,j]*dt) - Tyy[i,j]/η[i,j] + Tij[2] / η_vep[i,j]) + # Txy[i,j] += dτ_r * (-(Txy[i,j])/(G[i,j]*dt) - Txy[i,j]/η[i,j] + Tij[3] / η_vep[i,j]) + + # Txx[i,j] += dτ_r * (-(Txx[i,j]) + Tij[1] ) / η_vep[i,j] # NOTE: from GP Tij = 2*η_vep * εij + # Tyy[i,j] += dτ_r * (-(Tyy[i,j]) + Tij[2] ) / η_vep[i,j] + # Txy[i,j] += dτ_r * (-(Txy[i,j]) + Tij[3] ) / η_vep[i,j] end Txyv[2:end-1,2:end-1] .= ameanxy(Txy) @@ -180,7 +205,7 @@ end return end -function main(UseGP) +function main(UseGP, nt) pl_correction = :native_naive pl_correction = :native_inv1 pl_correction = :native_inv2 @@ -298,7 +323,7 @@ function main(UseGP) ρgx = zeros(nx-1,ny) ρgy = zeros(nx,ny-1) Pt_old = deepcopy(Pt) - ϵtol = 1e-4 + ϵtol = 1e-6 # Time loop t=0.0; evo_t=Float64[]; evo_Txx=Float64[] @@ -310,12 +335,12 @@ function main(UseGP) t = 0.0; evo_t=[]; evo_τxx=[] # ispath("anim")&&rm("anim",recursive=true);mkdir("anim");iframe = -1 # time loop - nt = 10 + # nt = 10 maxiter = 10e3 ncheck = 100 for it = 1:nt @printf("it=%d\n",it) - update_old!(Txx_o,Tyy_o,Txy_o,Pt_old,Txx,Tyy,Txy,Pt) + update_old!(Txx_o,Tyy_o,Txy_o,Txyv_o,Pt_old,Txx,Tyy,Txy,Txy,Pt) errs = 2.0.*ϵtol; iter = 1 resize!(iter_evo,0); resize!(errs_evo,length(ϵtol),0) while any(errs .>= ϵtol) && iter <= maxiter @@ -323,7 +348,7 @@ function main(UseGP) if UseGP update_P_strain!(Pt,Pt_old,dPt,Kb,Exx,Eyy,Exy,Exyv,Vx,Vy,∇V,η,G,dτ_r,dt,re_mech,vdτ,lτ,r,dx,dy) - update_stress_GP2!(Txx, Tyy, Txy, Txyv, TII, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, Exyv, η, η_vep, Pt, Phasec, Phasev, MatParam, dt,G, lτ, r, re_mech, vdτ) + update_stress_GP2!(Txx, Tyy, Txy, Txyv, TII, Txx_o, Tyy_o, Txy_o, Txyv_o, Exx, Eyy, Exyv, η, η_vep, Pt, Phasec, Phasev, MatParam, dt,G, lτ, r, re_mech, vdτ) else update_stresses!(Pt,Pt_old,dPt,Kb,Txx,Tyy,Txy,Txyv,Txx_o,Tyy_o,Txy_o,TII,Exx,Eyy,Exy,Exyv,Exx_ve,Eyy_ve,Exy_ve,EII_ve,η_vep,Vx,Vy,∇V,η,G,dτ_r,dt,re_mech,vdτ,lτ,r,dx,dy) end @@ -357,19 +382,19 @@ function main(UseGP) # display(plot(p1,p2,p3,p4,layout=(2,2))) # png(plot(p1,p2,p3,p4,layout=(2,2)),@sprintf("anim/%04d.png",iframe+=1)) - # TII .= sqrt.(0.5.*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) - p2=heatmap(xc,yc, η_vep',title="η_vep") + TII .= sqrt.(0.5.*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) + p2=heatmap(xc,yc, Txy',title="η_vep") display(p2) end return evo_t, evo_τxx, iter_evo, TII, η_vep end -@time evo_t, evo_τxx_GP, iter_evo_GP, TII, η_vep = main(true) -@time evo_t, evo_τxx, iter_evo, TII, η_vep = main(false) +@time evo_t, evo_τxx_GP, iter_evo_GP, TII, η_vep = main(true, 5) +@time evo_t, evo_τxx, iter_evo, TII, η_vep = main(false, 5) sol = @. 2.0*1*1*(1.0-exp(-evo_t*1/1)) scatter(evo_t, sol) -plot!(evo_t, evo_τxx, color=:black) plot!(evo_t, evo_τxx_GP, color=:red) +plot!(evo_t, evo_τxx, color=:black) -# plot(evo_t, @.((evo_τxx-evo_τxx_GP)/evo_τxx*100), color=:black) +plot(evo_t, @.((evo_τxx_GP-evo_τxx)/evo_τxx*100), color=:black) From 92a04ef26d2e62f57bd5ff45f42cf9785401c837 Mon Sep 17 00:00:00 2001 From: Duretz Thibault Date: Sun, 13 Nov 2022 15:39:06 +0100 Subject: [PATCH 41/49] bulk elasticity v0 --- .../scripts/Stokes2D_vep_reg_ctau_comp_v0.jl | 176 ++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 GeoParams_PT_examples/scripts/Stokes2D_vep_reg_ctau_comp_v0.jl diff --git a/GeoParams_PT_examples/scripts/Stokes2D_vep_reg_ctau_comp_v0.jl b/GeoParams_PT_examples/scripts/Stokes2D_vep_reg_ctau_comp_v0.jl new file mode 100644 index 0000000..4191dfb --- /dev/null +++ b/GeoParams_PT_examples/scripts/Stokes2D_vep_reg_ctau_comp_v0.jl @@ -0,0 +1,176 @@ +# Initialisation +# Add bulk elasticity in basic shear banding script +using Plots, Printf, Statistics, LinearAlgebra +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +# 2D Stokes routine +@views function Stokes2D_vep() + do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) + η_reg = 8.0e-3 # regularisation "viscosity" + # Physics + Lx, Ly = 1.0, 1.0 # domain size + radi = 0.01 # inclusion radius + τ_y = 1.6 # yield stress. If do_DP=true, τ_y stand for the cohesion: c*cos(ϕ) + sinϕ = sind(30)*do_DP # sinus of the friction angle + μ0 = 1.0 # viscous viscosity + G0 = 1.0 # elastic shear modulus + Gi = G0/(6.0-4.0*do_DP) # elastic shear modulus perturbation + εbg = 1.0 # background strain-rate + Κ = 1.0 + Δt = 1.0 + # Numerics + nt = 10 # number of time steps + nx, ny = 63, 63 # numerical grid resolution + Vdmp = 4.0 # convergence acceleration (damping) + Vsc = 2.0 # iterative time step limiter + Ptsc = 6.0 # iterative time step limiter + ε = 1e-6 # nonlinear tolerence + iterMax = 3e4 # max number of iters + nout = 200 # check frequency + # Preprocessing + dx, dy = Lx/nx, Ly/ny + dt = μ0/G0/4.0 # assumes Maxwell time of 4 + # Array initialisation + Pt = zeros(Dat, nx ,ny ) + ∇V = zeros(Dat, nx ,ny ) + Vx = zeros(Dat, nx+1,ny ) + Vy = zeros(Dat, nx ,ny+1) + Exx = zeros(Dat, nx ,ny ) + Eyy = zeros(Dat, nx ,ny ) + Exyv = zeros(Dat, nx+1,ny+1) + Exx1 = zeros(Dat, nx ,ny ) + Eyy1 = zeros(Dat, nx ,ny ) + Exy1 = zeros(Dat, nx ,ny ) + Exyv1 = zeros(Dat, nx+1,ny+1) + Txx = zeros(Dat, nx ,ny ) + Tyy = zeros(Dat, nx ,ny ) + Txy = zeros(Dat, nx ,ny ) + Txyv = zeros(Dat, nx+1,ny+1) + Txx_o = zeros(Dat, nx ,ny ) + Tyy_o = zeros(Dat, nx ,ny ) + Txy_o = zeros(Dat, nx ,ny ) + Txyv_o = zeros(Dat, nx+1,ny+1) + Tii = zeros(Dat, nx ,ny ) + Eii = zeros(Dat, nx ,ny ) + F = zeros(Dat, nx ,ny ) + Fchk = zeros(Dat, nx ,ny ) + Pla = zeros(Dat, nx ,ny ) + λ = zeros(Dat, nx ,ny ) + dQdTxx = zeros(Dat, nx ,ny ) + dQdTyy = zeros(Dat, nx ,ny ) + dQdTxy = zeros(Dat, nx ,ny ) + Rx = zeros(Dat, nx-1,ny ) + Ry = zeros(Dat, nx ,ny-1) + dVxdt = zeros(Dat, nx-1,ny ) + dVydt = zeros(Dat, nx ,ny-1) + dtPt = zeros(Dat, nx ,ny ) + dtVx = zeros(Dat, nx-1,ny ) + dtVy = zeros(Dat, nx ,ny-1) + Rog = zeros(Dat, nx ,ny ) + η_v = μ0*ones(Dat, nx, ny) + η_e = dt*G0*ones(Dat, nx, ny) + η_ev = dt*G0*ones(Dat, nx+1, ny+1) + η_ve = ones(Dat, nx, ny) + η_vep = ones(Dat, nx, ny) + η_vepv = ones(Dat, nx+1, ny+1) + RPt = zeros(Dat, nx ,ny ) + Pt_o = zeros(Dat, nx ,ny ) + # Initial condition + xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) + xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) + xv, yv = LinRange(0.0, Lx, nx+1), LinRange(0.0, Ly, ny+1) + (Xvx,Yvx) = ([x for x=xv,y=yc], [y for x=xv,y=yc]) + (Xvy,Yvy) = ([x for x=xc,y=yv], [y for x=xc,y=yv]) + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + η_e[radc.ε && iter<=iterMax) + # divergence - pressure + ∇V .= diff(Vx, dims=1)./dx .+ diff(Vy, dims=2)./dy + # strain rates + Exx .= diff(Vx, dims=1)./dx .- 1.0/3.0*∇V + Eyy .= diff(Vy, dims=2)./dy .- 1.0/3.0*∇V + Exyv[2:end-1,2:end-1] .= 0.5.*(diff(Vx[2:end-1,:], dims=2)./dy .+ diff(Vy[:,2:end-1], dims=1)./dx) + # visco-elastic strain rates + Exx1 .= Exx .+ Txx_o ./2.0./η_e + Eyy1 .= Eyy .+ Tyy_o ./2.0./η_e + # Exyv1 .= Exyv .+ Txyv_o./2.0./η_ev + Exy1 .= av(Exyv) .+ Txy_o ./2.0./η_e + Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ Exy1.^2) + # trial stress + Txx .= 2.0.*η_ve.*Exx1 + Tyy .= 2.0.*η_ve.*Eyy1 + Txy .= 2.0.*η_ve.*Exy1 + Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) + # yield function + F .= Tii .- τ_y .- Pt.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(η_ve .+ η_reg) + dQdTxx .= 0.5.*Txx./Tii + dQdTyy .= 0.5.*Tyy./Tii + dQdTxy .= Txy./Tii + # plastic corrections + Txx .= 2.0.*η_ve.*(Exx1 .- λ.*dQdTxx) + Tyy .= 2.0.*η_ve.*(Eyy1 .- λ.*dQdTyy) + Txy .= 2.0.*η_ve.*(Exy1 .- 0.5.*λ.*dQdTxy) + Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) + Fchk .= Tii .- τ_y .- Pt.*sinϕ .- λ.*η_reg + η_vep .= Tii./2.0./Eii + # η_vepv[2:end-1,2:end-1] .= av(η_vep); η_vepv[1,:].=η_vepv[2,:]; η_vepv[end,:].=η_vepv[end-1,:]; η_vepv[:,1].=η_vepv[:,2]; η_vepv[:,end].=η_vepv[:,end-1] + # Txyv .= 2.0.*η_vepv.*Exyv1 + Txyv[2:end-1,2:end-1].=av(Txy) # Txyv=0 on boundaries ! + # PT timestep + dtVx .= min(dx,dy)^2.0./av_xa(η_vep)./4.1./Vsc + dtVy .= min(dx,dy)^2.0./av_ya(η_vep)./4.1./Vsc + dtPt .= 4.1.*η_vep./max(nx,ny)./Ptsc + # Residuals + Rx .= .-diff(Pt, dims=1)./dx .+ diff(Txx, dims=1)./dx .+ diff(Txyv[2:end-1,:], dims=2)./dy + Ry .= .-diff(Pt, dims=2)./dy .+ diff(Tyy, dims=2)./dy .+ diff(Txyv[:,2:end-1], dims=1)./dx .+ av_ya(Rog) + RPt .= .-∇V .- (Pt.-Pt_o)./(Κ*Δt) + # Damping of momentum residuals + dVxdt .= dVxdt.*(1-Vdmp/nx) .+ Rx + dVydt .= dVydt.*(1-Vdmp/ny) .+ Ry + # Updates + Pt .= Pt .+ dtPt.*RPt + Vx[2:end-1,:] .= Vx[2:end-1,:] .+ dVxdt.*dtVx + Vy[:,2:end-1] .= Vy[:,2:end-1] .+ dVydt.*dtVy + # convergence check + if mod(iter, nout)==0 + norm_Rx = norm(Rx)/length(Rx); norm_Ry = norm(Ry)/length(Ry); norm_RPt = norm(RPt)/length(RPt) + err = maximum([norm_Rx, norm_Ry, norm_RPt]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %d, iter = %d, err = %1.2e norm[Rx=%1.2e, Ry=%1.2e, RPt=%1.2e] (Fchk=%1.2e) \n", it, itg, err, norm_Rx, norm_Ry, norm_RPt, maximum(Fchk)) + end + iter+=1; itg=iter + end + t = t + dt + push!(evo_t, t); push!(evo_Txx, maximum(Txx)) + # Plotting + p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") + # p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p2 = heatmap(xc, yc, η_vep' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="η_vep") + p3 = heatmap(xc, yc, Tii' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="τii") + p4 = plot(evo_t, evo_Txx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + plot!(evo_t, 2.0.*εbg.*μ0.*(1.0.-exp.(.-evo_t.*G0./μ0)), linewidth=2.0) # analytical solution for VE loading + plot!(evo_t, 2.0.*εbg.*μ0.*ones(size(evo_t)), linewidth=2.0) # viscous flow stress + if !do_DP plot!(evo_t, τ_y*ones(size(evo_t)), linewidth=2.0) end # von Mises yield stress + display(plot(p1, p2, p3, p4)) + end + return +end + +Stokes2D_vep() From 19941a8cb37829f7b6ca807a90275dd9baadaefc Mon Sep 17 00:00:00 2001 From: Duretz Thibault Date: Sun, 13 Nov 2022 15:53:01 +0100 Subject: [PATCH 42/49] add v1, should be GP friendly ;) --- .../scripts/Stokes2D_vep_reg_ctau_comp_v1.jl | 181 ++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 GeoParams_PT_examples/scripts/Stokes2D_vep_reg_ctau_comp_v1.jl diff --git a/GeoParams_PT_examples/scripts/Stokes2D_vep_reg_ctau_comp_v1.jl b/GeoParams_PT_examples/scripts/Stokes2D_vep_reg_ctau_comp_v1.jl new file mode 100644 index 0000000..ce5895d --- /dev/null +++ b/GeoParams_PT_examples/scripts/Stokes2D_vep_reg_ctau_comp_v1.jl @@ -0,0 +1,181 @@ +# Initialisation +# Add bulk elasticity in basic shear banding script +using Plots, Printf, Statistics, LinearAlgebra +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +# 2D Stokes routine +@views function Stokes2D_vep() + do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) + η_reg = 8.0e-3 # regularisation "viscosity" + # Physics + Lx, Ly = 1.0, 1.0 # domain size + radi = 0.01 # inclusion radius + τ_y = 1.6 # yield stress. If do_DP=true, τ_y stand for the cohesion: c*cos(ϕ) + sinϕ = sind(30)*do_DP # sinus of the friction angle + μ0 = 1.0 # viscous viscosity + G0 = 1.0 # elastic shear modulus + Gi = G0/(6.0-4.0*do_DP) # elastic shear modulus perturbation + εbg = 1.0 # background strain-rate + Κ = 1.0 + Δt = 1.0 + # Numerics + nt = 10 # number of time steps + nx, ny = 63, 63 # numerical grid resolution + Vdmp = 4.0 # convergence acceleration (damping) + Vsc = 2.0 # iterative time step limiter + Ptsc = 6.0 # iterative time step limiter + ε = 1e-6 # nonlinear tolerence + iterMax = 3e4 # max number of iters + nout = 200 # check frequency + # Preprocessing + dx, dy = Lx/nx, Ly/ny + dt = μ0/G0/4.0 # assumes Maxwell time of 4 + # Array initialisation + Pt = zeros(Dat, nx ,ny ) + ∇V = zeros(Dat, nx ,ny ) + Vx = zeros(Dat, nx+1,ny ) + Vy = zeros(Dat, nx ,ny+1) + Exx = zeros(Dat, nx ,ny ) + Eyy = zeros(Dat, nx ,ny ) + Exyv = zeros(Dat, nx+1,ny+1) + Exx1 = zeros(Dat, nx ,ny ) + Eyy1 = zeros(Dat, nx ,ny ) + Exy1 = zeros(Dat, nx ,ny ) + Exyv1 = zeros(Dat, nx+1,ny+1) + Txx = zeros(Dat, nx ,ny ) + Tyy = zeros(Dat, nx ,ny ) + Txy = zeros(Dat, nx ,ny ) + Txyv = zeros(Dat, nx+1,ny+1) + Txx_o = zeros(Dat, nx ,ny ) + Tyy_o = zeros(Dat, nx ,ny ) + Txy_o = zeros(Dat, nx ,ny ) + Txyv_o = zeros(Dat, nx+1,ny+1) + Tii = zeros(Dat, nx ,ny ) + Eii = zeros(Dat, nx ,ny ) + F = zeros(Dat, nx ,ny ) + Fchk = zeros(Dat, nx ,ny ) + Pla = zeros(Dat, nx ,ny ) + λ = zeros(Dat, nx ,ny ) + dQdTxx = zeros(Dat, nx ,ny ) + dQdTyy = zeros(Dat, nx ,ny ) + dQdTxy = zeros(Dat, nx ,ny ) + Rx = zeros(Dat, nx-1,ny ) + Ry = zeros(Dat, nx ,ny-1) + dVxdt = zeros(Dat, nx-1,ny ) + dVydt = zeros(Dat, nx ,ny-1) + dtPt = zeros(Dat, nx ,ny ) + dtVx = zeros(Dat, nx-1,ny ) + dtVy = zeros(Dat, nx ,ny-1) + Rog = zeros(Dat, nx ,ny ) + η_v = μ0*ones(Dat, nx, ny) + η_e = dt*G0*ones(Dat, nx, ny) + η_ev = dt*G0*ones(Dat, nx+1, ny+1) + η_ve = ones(Dat, nx, ny) + η_vep = ones(Dat, nx, ny) + η_vepv = ones(Dat, nx+1, ny+1) + RPt = zeros(Dat, nx ,ny ) + Pt_o = zeros(Dat, nx ,ny ) + Pt_it = zeros(Dat, nx ,ny ) + # Initial condition + xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) + xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) + xv, yv = LinRange(0.0, Lx, nx+1), LinRange(0.0, Ly, ny+1) + (Xvx,Yvx) = ([x for x=xv,y=yc], [y for x=xv,y=yc]) + (Xvy,Yvy) = ([x for x=xc,y=yv], [y for x=xc,y=yv]) + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + η_e[radc.ε && iter<=iterMax) + # divergence - pressure + ∇V .= diff(Vx, dims=1)./dx .+ diff(Vy, dims=2)./dy + # strain rates + Exx .= diff(Vx, dims=1)./dx .- 1.0/3.0*∇V + Eyy .= diff(Vy, dims=2)./dy .- 1.0/3.0*∇V + Exyv[2:end-1,2:end-1] .= 0.5.*(diff(Vx[2:end-1,:], dims=2)./dy .+ diff(Vy[:,2:end-1], dims=1)./dx) + # visco-elastic strain rates + Exx1 .= Exx .+ Txx_o ./2.0./η_e + Eyy1 .= Eyy .+ Tyy_o ./2.0./η_e + # Exyv1 .= Exyv .+ Txyv_o./2.0./η_ev + Exy1 .= av(Exyv) .+ Txy_o ./2.0./η_e + Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ Exy1.^2) + # trial stress + Txx .= 2.0.*η_ve.*Exx1 + Tyy .= 2.0.*η_ve.*Eyy1 + Txy .= 2.0.*η_ve.*Exy1 + Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) + # Assume this comes from GP (sets local P residual to 0.0) + Pt .= Pt_o - Κ*Δt*∇V + # yield function + F .= Tii .- τ_y .- Pt_it.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(η_ve .+ η_reg) + dQdTxx .= 0.5.*Txx./Tii + dQdTyy .= 0.5.*Tyy./Tii + dQdTxy .= Txy./Tii + # plastic corrections + Txx .= 2.0.*η_ve.*(Exx1 .- λ.*dQdTxx) + Tyy .= 2.0.*η_ve.*(Eyy1 .- λ.*dQdTyy) + Txy .= 2.0.*η_ve.*(Exy1 .- 0.5.*λ.*dQdTxy) + Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) + Fchk .= Tii .- τ_y .- Pt_it.*sinϕ .- λ.*η_reg + η_vep .= Tii./2.0./Eii + # η_vepv[2:end-1,2:end-1] .= av(η_vep); η_vepv[1,:].=η_vepv[2,:]; η_vepv[end,:].=η_vepv[end-1,:]; η_vepv[:,1].=η_vepv[:,2]; η_vepv[:,end].=η_vepv[:,end-1] + # Txyv .= 2.0.*η_vepv.*Exyv1 + Txyv[2:end-1,2:end-1].=av(Txy) # Txyv=0 on boundaries ! + # PT timestep + dtVx .= min(dx,dy)^2.0./av_xa(η_vep)./4.1./Vsc + dtVy .= min(dx,dy)^2.0./av_ya(η_vep)./4.1./Vsc + dtPt .= 4.1.*η_vep./max(nx,ny)./Ptsc + # Residuals + Rx .= .-diff(Pt_it, dims=1)./dx .+ diff(Txx, dims=1)./dx .+ diff(Txyv[2:end-1,:], dims=2)./dy + Ry .= .-diff(Pt_it, dims=2)./dy .+ diff(Tyy, dims=2)./dy .+ diff(Txyv[:,2:end-1], dims=1)./dx .+ av_ya(Rog) + # You still need to update pressure iteratively + # one possibility is to iterate pressure until it is equal to GP value + RPt .= (Pt.-Pt_it) + # Damping of momentum residuals + dVxdt .= dVxdt.*(1-Vdmp/nx) .+ Rx + dVydt .= dVydt.*(1-Vdmp/ny) .+ Ry + # Updates + Pt_it .= Pt_it .+ dtPt.*RPt + Vx[2:end-1,:] .= Vx[2:end-1,:] .+ dVxdt.*dtVx + Vy[:,2:end-1] .= Vy[:,2:end-1] .+ dVydt.*dtVy + # convergence check + if mod(iter, nout)==0 + norm_Rx = norm(Rx)/length(Rx); norm_Ry = norm(Ry)/length(Ry); norm_RPt = norm(RPt)/length(RPt) + err = maximum([norm_Rx, norm_Ry, norm_RPt]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %d, iter = %d, err = %1.2e norm[Rx=%1.2e, Ry=%1.2e, RPt=%1.2e] (Fchk=%1.2e) \n", it, itg, err, norm_Rx, norm_Ry, norm_RPt, maximum(Fchk)) + end + iter+=1; itg=iter + end + t = t + dt + push!(evo_t, t); push!(evo_Txx, maximum(Txx)) + # Plotting + p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") + # p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p2 = heatmap(xc, yc, η_vep' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="η_vep") + p3 = heatmap(xc, yc, Tii' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="τii") + p4 = plot(evo_t, evo_Txx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + plot!(evo_t, 2.0.*εbg.*μ0.*(1.0.-exp.(.-evo_t.*G0./μ0)), linewidth=2.0) # analytical solution for VE loading + plot!(evo_t, 2.0.*εbg.*μ0.*ones(size(evo_t)), linewidth=2.0) # viscous flow stress + if !do_DP plot!(evo_t, τ_y*ones(size(evo_t)), linewidth=2.0) end # von Mises yield stress + display(plot(p1, p2, p3, p4)) + end + return +end + +Stokes2D_vep() From 527b3d941ad4655f70485e6cef65e8d609b57a84 Mon Sep 17 00:00:00 2001 From: Duretz Thibault Date: Mon, 14 Nov 2022 09:29:48 +0100 Subject: [PATCH 43/49] first version with plastic dilation --- needs relaxation applied to lambda --- .../Stokes2D_vep_reg_ctau_comp_dil_v1.jl | 188 ++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 GeoParams_PT_examples/scripts/Stokes2D_vep_reg_ctau_comp_dil_v1.jl diff --git a/GeoParams_PT_examples/scripts/Stokes2D_vep_reg_ctau_comp_dil_v1.jl b/GeoParams_PT_examples/scripts/Stokes2D_vep_reg_ctau_comp_dil_v1.jl new file mode 100644 index 0000000..60cb918 --- /dev/null +++ b/GeoParams_PT_examples/scripts/Stokes2D_vep_reg_ctau_comp_dil_v1.jl @@ -0,0 +1,188 @@ +# Initialisation +# Add bulk elasticity in basic shear banding script +using Plots, Printf, Statistics, LinearAlgebra +Dat = Float64 # Precision (double=Float64 or single=Float32) +# Macros +@views av(A) = 0.25*(A[1:end-1,1:end-1].+A[2:end,1:end-1].+A[1:end-1,2:end].+A[2:end,2:end]) +@views av_xa(A) = 0.5*(A[1:end-1,:].+A[2:end,:]) +@views av_ya(A) = 0.5*(A[:,1:end-1].+A[:,2:end]) +# 2D Stokes routine +@views function Stokes2D_vep() + do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) + η_reg = 8.0e-3 # regularisation "viscosity" + # Physics + Lx, Ly = 1.0, 1.0 # domain size + radi = 0.01 # inclusion radius + τ_y = 1.6 # yield stress. If do_DP=true, τ_y stand for the cohesion: c*cos(ϕ) + sinϕ = sind(30)*do_DP # sinus of the friction angle + μ0 = 1.0 # viscous viscosity + G0 = 1.0 # elastic shear modulus + Gi = G0/(6.0-4.0*do_DP) # elastic shear modulus perturbation + εbg = 1.0 # background strain-rate + Κ = 1.0 + Δt = 1.0 + sinψ = sind(5) + rel = 0.25 + # Numerics + nt = 10 # number of time steps + nx, ny = 63, 63 # numerical grid resolution + Vdmp = 4.0 # convergence acceleration (damping) + Vsc = 2.0 # iterative time step limiter + Ptsc = 6.0 # iterative time step limiter + ε = 1e-6 # nonlinear tolerence + iterMax = 3e4 # max number of iters + nout = 200 # check frequency + # Preprocessing + dx, dy = Lx/nx, Ly/ny + dt = μ0/G0/4.0 # assumes Maxwell time of 4 + # Array initialisation + Pt = zeros(Dat, nx ,ny ) + ∇V = zeros(Dat, nx ,ny ) + Vx = zeros(Dat, nx+1,ny ) + Vy = zeros(Dat, nx ,ny+1) + Exx = zeros(Dat, nx ,ny ) + Eyy = zeros(Dat, nx ,ny ) + Exyv = zeros(Dat, nx+1,ny+1) + Exx1 = zeros(Dat, nx ,ny ) + Eyy1 = zeros(Dat, nx ,ny ) + Exy1 = zeros(Dat, nx ,ny ) + Exyv1 = zeros(Dat, nx+1,ny+1) + Txx = zeros(Dat, nx ,ny ) + Tyy = zeros(Dat, nx ,ny ) + Txy = zeros(Dat, nx ,ny ) + Txyv = zeros(Dat, nx+1,ny+1) + Txx_o = zeros(Dat, nx ,ny ) + Tyy_o = zeros(Dat, nx ,ny ) + Txy_o = zeros(Dat, nx ,ny ) + Txyv_o = zeros(Dat, nx+1,ny+1) + Tii = zeros(Dat, nx ,ny ) + Eii = zeros(Dat, nx ,ny ) + F = zeros(Dat, nx ,ny ) + Fchk = zeros(Dat, nx ,ny ) + Pla = zeros(Dat, nx ,ny ) + λ = zeros(Dat, nx ,ny ) + dQdTxx = zeros(Dat, nx ,ny ) + dQdTyy = zeros(Dat, nx ,ny ) + dQdTxy = zeros(Dat, nx ,ny ) + Rx = zeros(Dat, nx-1,ny ) + Ry = zeros(Dat, nx ,ny-1) + dVxdt = zeros(Dat, nx-1,ny ) + dVydt = zeros(Dat, nx ,ny-1) + dtPt = zeros(Dat, nx ,ny ) + dtVx = zeros(Dat, nx-1,ny ) + dtVy = zeros(Dat, nx ,ny-1) + Rog = zeros(Dat, nx ,ny ) + η_v = μ0*ones(Dat, nx, ny) + η_e = dt*G0*ones(Dat, nx, ny) + η_ev = dt*G0*ones(Dat, nx+1, ny+1) + η_ve = ones(Dat, nx, ny) + η_vep = ones(Dat, nx, ny) + η_vepv = ones(Dat, nx+1, ny+1) + RPt = zeros(Dat, nx ,ny ) + Pt_o = zeros(Dat, nx ,ny ) + Pt_it = zeros(Dat, nx ,ny ) + ∇Vp = zeros(Dat, nx ,ny ) + λ1 = zeros(Dat, nx ,ny ) + # Initial condition + xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) + xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) + xv, yv = LinRange(0.0, Lx, nx+1), LinRange(0.0, Ly, ny+1) + (Xvx,Yvx) = ([x for x=xv,y=yc], [y for x=xv,y=yc]) + (Xvy,Yvy) = ([x for x=xc,y=yv], [y for x=xc,y=yv]) + radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 + radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 + η_e[radc.ε && iter<=iterMax) + # divergence - pressure + ∇V .= diff(Vx, dims=1)./dx .+ diff(Vy, dims=2)./dy + # strain rates + Exx .= diff(Vx, dims=1)./dx .- 1.0/3.0*∇V + Eyy .= diff(Vy, dims=2)./dy .- 1.0/3.0*∇V + Exyv[2:end-1,2:end-1] .= 0.5.*(diff(Vx[2:end-1,:], dims=2)./dy .+ diff(Vy[:,2:end-1], dims=1)./dx) + # visco-elastic strain rates + Exx1 .= Exx .+ Txx_o ./2.0./η_e + Eyy1 .= Eyy .+ Tyy_o ./2.0./η_e + # Exyv1 .= Exyv .+ Txyv_o./2.0./η_ev + Exy1 .= av(Exyv) .+ Txy_o ./2.0./η_e + Eii .= sqrt.(0.5*(Exx1.^2 .+ Eyy1.^2) .+ Exy1.^2) + # trial stress + Txx .= 2.0.*η_ve.*Exx1 + Tyy .= 2.0.*η_ve.*Eyy1 + Txy .= 2.0.*η_ve.*Exy1 + Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) + # Assume this comes from GP (sets local P residual to 0.0) + Pt .= Pt_o - Κ*Δt*∇V + # yield function + F .= Tii .- τ_y .- Pt_it.*sinϕ + Pla .= 0.0 + Pla .= F .> 0.0 + λ .= Pla.*F./(η_ve .+ η_reg .+ Κ*Δt*sinψ*sinϕ) + dQdTxx .= 0.5.*Txx./Tii + dQdTyy .= 0.5.*Tyy./Tii + dQdTxy .= Txy./Tii + # plastic corrections + λ1 .= rel.*λ + (1.0-rel).*λ1 + Txx .= 2.0.*η_ve.*(Exx1 .- λ1.*dQdTxx) + Tyy .= 2.0.*η_ve.*(Eyy1 .- λ1.*dQdTyy) + Txy .= 2.0.*η_ve.*(Exy1 .- 0.5.*λ1.*dQdTxy) + Tii .= sqrt.(0.5*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) + # Assume this comes from GP (sets local P residual to 0.0) + # Pt .= Pt_o .- Κ*Δt*(∇V .- ∇Vp) + ∇Vp .= λ1*sinψ + Tii .= Tii .- λ1.*η_reg + Fchk .= Tii .- τ_y .- (Pt_it .+ Κ.*Δt.*∇Vp).*sinϕ + η_vep .= Tii./2.0./Eii + Txyv[2:end-1,2:end-1] .= av(Txy) # Txyv=0 on boundaries ! + # PT timestep + dtVx .= min(dx,dy)^2.0./av_xa(η_vep)./4.1./Vsc + dtVy .= min(dx,dy)^2.0./av_ya(η_vep)./4.1./Vsc + dtPt .= 4.1.*η_vep./max(nx,ny)./Ptsc + # You still need to update pressure iteratively + # one possibility is to iterate pressure until it is equal to GP value + RPt .= (Pt .- Pt_it) + Pt_it .= Pt_it .+ dtPt.*RPt + # Residuals + Rx .= .-diff(Pt_it .+ Κ.*Δt.*∇Vp, dims=1)./dx .+ diff(Txx, dims=1)./dx .+ diff(Txyv[2:end-1,:], dims=2)./dy + Ry .= .-diff(Pt_it .+ Κ.*Δt.*∇Vp, dims=2)./dy .+ diff(Tyy, dims=2)./dy .+ diff(Txyv[:,2:end-1], dims=1)./dx .+ av_ya(Rog) + # Damping of momentum residuals + dVxdt .= dVxdt.*(1-Vdmp/nx) .+ Rx + dVydt .= dVydt.*(1-Vdmp/ny) .+ Ry + # Updates + Vx[2:end-1,:] .= Vx[2:end-1,:] .+ dVxdt.*dtVx + Vy[:,2:end-1] .= Vy[:,2:end-1] .+ dVydt.*dtVy + # convergence check + if mod(iter, nout)==0 + norm_Rx = norm(Rx)/length(Rx); norm_Ry = norm(Ry)/length(Ry); norm_RPt = norm(RPt)/length(RPt) + err = maximum([norm_Rx, norm_Ry, norm_RPt]) + push!(err_evo1, err); push!(err_evo2, itg) + @printf("it = %d, iter = %d, err = %1.2e norm[Rx=%1.2e, Ry=%1.2e, RPt=%1.2e] (Fchk=%1.2e) \n", it, itg, err, norm_Rx, norm_Ry, norm_RPt, maximum(Fchk)) + end + iter+=1; itg=iter + end + t = t + dt + push!(evo_t, t); push!(evo_Txx, maximum(Txx)) + # Plotting + p1 = heatmap(xv, yc, Vx' , aspect_ratio=1, xlims=(0, Lx), ylims=(dy/2, Ly-dy/2), c=:inferno, title="Vx") + # p2 = heatmap(xc, yv, Vy' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="Vy") + p2 = heatmap(xc, yc, η_vep' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="η_vep") + p3 = heatmap(xc, yc, Tii' , aspect_ratio=1, xlims=(dx/2, Lx-dx/2), ylims=(0, Ly), c=:inferno, title="τii") + p4 = plot(evo_t, evo_Txx , legend=false, xlabel="time", ylabel="max(τxx)", linewidth=0, markershape=:circle, framestyle=:box, markersize=3) + plot!(evo_t, 2.0.*εbg.*μ0.*(1.0.-exp.(.-evo_t.*G0./μ0)), linewidth=2.0) # analytical solution for VE loading + plot!(evo_t, 2.0.*εbg.*μ0.*ones(size(evo_t)), linewidth=2.0) # viscous flow stress + if !do_DP plot!(evo_t, τ_y*ones(size(evo_t)), linewidth=2.0) end # von Mises yield stress + display(plot(p1, p2, p3, p4)) + end + return +end + +Stokes2D_vep() From ccf044e7f4b951aebed9fa47dba7598eceb86eaf Mon Sep 17 00:00:00 2001 From: albert-de-montserrat Date: Mon, 14 Nov 2022 13:13:07 +0100 Subject: [PATCH 44/49] GP_v3 now matches _v2 --- ...kes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl | 750 +++++++++++------- 1 file changed, 485 insertions(+), 265 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl index 9edffce..c9ce961 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl @@ -1,43 +1,85 @@ using ElasticArrays, Printf, GeoParams -using Plots,Plots.Measures -default(size=(800,500),framestyle=:box,label=false,grid=false,lw=6,labelfontsize=11,tickfontsize=11,titlefontsize=11) +using Plots, Plots.Measures +# default(size=(800,500),framestyle=:box,label=false,grid=false,lw=6,labelfontsize=11,tickfontsize=11,titlefontsize=11) -@inline amean(a,b) = 0.5*(a + b) -@inline hmean(a,b) = 2.0/(1.0/a + 1.0/b) -@inline amean4(a,b,c,d) = 0.25*(a+b+c+d) -@inline hmean4(a,b,c,d) = 4.0/(1.0/a+1.0/b+1.0/c+1.0/d) -const av = amean -const av4 = amean4 -@views amean1(A) = 0.5.*(A[1:end-1] .+ A[2:end]) -@views avx(A) = av.(A[1:end-1,:], A[2:end,:]) -@views avy(A) = av.(A[:,1:end-1], A[:,2:end]) -@views avxy(A) = av4.(A[1:end-1,1:end-1],A[2:end,1:end-1],A[1:end-1,2:end],A[2:end,2:end]) -@views ameanx(A) = amean.(A[1:end-1,:], A[2:end,:]) -@views ameany(A) = amean.(A[:,1:end-1], A[:,2:end]) -@views ameanxy(A) = amean4.(A[1:end-1,1:end-1],A[2:end,1:end-1],A[1:end-1,2:end],A[2:end,2:end]) -@views hmeanx(A) = hmean.(A[1:end-1,:], A[2:end,:]) -@views hmeany(A) = hmean.(A[:,1:end-1], A[:,2:end]) -@views hmeanxy(A) = hmean4.(A[1:end-1,1:end-1],A[2:end,1:end-1],A[1:end-1,2:end],A[2:end,2:end]) -@views maxloc(A) = max.(A[1:end-2,1:end-2],A[1:end-2,2:end-1],A[1:end-2,3:end], - A[2:end-1,1:end-2],A[2:end-1,2:end-1],A[2:end-1,3:end], - A[3:end ,1:end-2],A[3:end ,2:end-1],A[3:end ,3:end]) -@views bc2!(A) = begin A[[1,end],:]=A[[2,end-1],:]; A[:,[1,end]]=A[:,[2,end-1]]; end +@inline amean(a, b) = 0.5 * (a + b) +@inline hmean(a, b) = 2.0 / (1.0 / a + 1.0 / b) +@inline amean4(a, b, c, d) = 0.25 * (a + b + c + d) +@inline hmean4(a, b, c, d) = 4.0 / (1.0 / a + 1.0 / b + 1.0 / c + 1.0 / d) +# const av = amean +# const av4 = amean4 +@views amean1(A) = 0.5 .* (A[1:(end - 1)] .+ A[2:end]) +@views avx(A) = amean.(A[1:(end - 1), :], A[2:end, :]) +@views avy(A) = amean.(A[:, 1:(end - 1)], A[:, 2:end]) +@views function avxy(A) + return amean4.( + A[1:(end - 1), 1:(end - 1)], + A[2:end, 1:(end - 1)], + A[1:(end - 1), 2:end], + A[2:end, 2:end], + ) +end +@views ameanx(A) = amean.(A[1:(end - 1), :], A[2:end, :]) +@views ameany(A) = amean.(A[:, 1:(end - 1)], A[:, 2:end]) +@views function ameanxy(A) + return amean4.( + A[1:(end - 1), 1:(end - 1)], + A[2:end, 1:(end - 1)], + A[1:(end - 1), 2:end], + A[2:end, 2:end], + ) +end +@views function ameanxy_pow2(A) + @. amean4( + A[1:(end - 1), 1:(end - 1)]^2, + A[2:end, 1:(end - 1)]^2, + A[1:(end - 1), 2:end]^2, + A[2:end, 2:end]^2, + ) +end +@views hmeanx(A) = hmean.(A[1:(end - 1), :], A[2:end, :]) +@views hmeany(A) = hmean.(A[:, 1:(end - 1)], A[:, 2:end]) +@views function hmeanxy(A) + return hmean4.( + A[1:(end - 1), 1:(end - 1)], + A[2:end, 1:(end - 1)], + A[1:(end - 1), 2:end], + A[2:end, 2:end], + ) +end +@views function maxloc(A) + return max.( + A[1:(end - 2), 1:(end - 2)], + A[1:(end - 2), 2:(end - 1)], + A[1:(end - 2), 3:end], + A[2:(end - 1), 1:(end - 2)], + A[2:(end - 1), 2:(end - 1)], + A[2:(end - 1), 3:end], + A[3:end, 1:(end - 2)], + A[3:end, 2:(end - 1)], + A[3:end, 3:end], + ) +end +@views bc2!(A) = begin + A[[1, end], :] = A[[2, end - 1], :] + A[:, [1, end]] = A[:, [2, end - 1]] +end -@views function update_old!(Txx_o,Tyy_o,Txy_o,Txyv_o,Pr_old,Txx,Tyy,Txy,Txyv,Pr) - copyto!(Txx_o , Txx) - copyto!(Tyy_o , Tyy) - copyto!(Txy_o , Txy) +@views function update_old!(Txx_o, Tyy_o, Txy_o, Txyv_o, Pr_old, Txx, Tyy, Txy, Txyv, Pr) + copyto!(Txx_o, Txx) + copyto!(Tyy_o, Tyy) + copyto!(Txy_o, Txy) copyto!(Txyv_o, Txyv) copyto!(Pr_old, Pr) # Pr .= Pr_c # λ .= 0.0 - return + return nothing end - -@views function update_iteration_params!(η,ητ) - ητ[2:end-1,2:end-1] .= maxloc(η); bc2!(ητ) - return +@views function update_iteration_params!(η, ητ) + ητ[2:(end - 1), 2:(end - 1)] .= maxloc(η) + bc2!(ητ) + return nothing end # @views function update_stresses!((;Pr,Pr_old,Pr_c,dPr,K,Txx,Tyy,Txy,dτxx,dτyy,dTxyv,Txyv,Txx_o,Tyy_o,Txy_o,dQdτxx,dQdτyy,dQdTxyv,Fchk,TII,F,λ,Exx,Eyy,Exy,Exyv,Exx_ve,Eyy_ve,Exy_ve,EII_ve,η_vep,Vx,Vy,∇V,η,G,dτ_r),τ_y,sinϕ,sinψ,η_reg,relλ,dt,re_mech,vdτ,lτ,r,dx,dy,iter) @@ -81,128 +123,200 @@ end # return # end +function update_stress_GP2!( + Txx, + Tyy, + Txy, + Txyv, + TII, + Txx_o, + Tyy_o, + Txy_o, + Txyv_o, + Exx, + Eyy, + Exyv, + η, + η_vep, + Pt, + Phasec, + Phasev, + MatParam, + dt, + G, + lτ, + r, + re_mech, + vdτ, +) + θ_dτ = lτ * (r + 2.0) / (re_mech * vdτ) + Threads.@threads for j in axes(Exx, 2) + @inbounds for i in axes(Exx, 1) + # dτ_r = 1.0/(θ_dτ + η[i,j]/(G[i,j]*dt) + 1.0) + dτ_r = 1.0 / (θ_dτ + 1 / η_vep[i, j]) # equivalent to dτ_r = @. 1.0/(θ_dτ + η/(G*dt) + 1.0) + args = (; dt=dt, P=Pt[i, j], τII_old=0.0) + # # gather strain rate + εij_v = (Exyv[i, j], Exyv[i + 1, j], Exyv[i, j + 1], Exyv[i + 1, j + 1]) # gather vertices around ij center + εij_p = (Exx[i, j], Eyy[i, j], εij_v) + # # gather deviatoric stress + τij_v = ( + Txyv_o[i ,j ], + Txyv_o[i+1,j ], + Txyv_o[i ,j+1], + Txyv_o[i+1,j+1] + ) # gather vertices around ij center + τij_p_o = (Txx_o[i,j], Tyy_o[i,j], τij_v) + # gathermaterial phases + phases_v = (Phasev[i, j], Phasev[i + 1, j], Phasev[i, j + 1], Phasev[i + 1, j + 1]) # gather vertices around ij center + phases = (Phasec[i, j], Phasec[i, j], phases_v) + # update stress and effective viscosity + Tij, TII[i, j], η_vep[i, j] = compute_τij(MatParam, εij_p, args, τij_p_o, phases) -function update_stress_GP2!(Txx, Tyy, Txy, Txyv, Tii, Txx_o, Tyy_o, Txy_o, Txyv_o, Exx, Eyy, Exyv, η, η_vep, Pt, Phasec, Phasev, MatParam, dt, G, lτ, r, re_mech, vdτ) - θ_dτ = lτ*(r+2.0)/(re_mech*vdτ) - for j in axes(Exx,2), i in axes(Exx,1) - # dτ_r = 1.0/(θ_dτ + η[i,j]/(G[i,j]*dt) + 1.0) - dτ_r = 1.0/(θ_dτ + 1/η_vep[i,j]) # equivalent to dτ_r = @. 1.0/(θ_dτ + η/(G*dt) + 1.0) - args = (; dt=dt, P=Pt[i,j], τII_old=0.0) - # # gather strain rate - εij_v = ( - Exyv[i ,j ], - Exyv[i+1,j ], - Exyv[i ,j+1], - Exyv[i+1,j+1] - ) # gather vertices around ij center - - εij_p = (Exx[i,j], Eyy[i,j], εij_v) - # # gather deviatoric stress - # τij_v = ( - # Txyv_o[i ,j ], - # Txyv_o[i+1,j ], - # Txyv_o[i ,j+1], - # Txyv_o[i+1,j+1] - # ) # gather vertices around ij center - # τij_p_o = (Txx_o[i,j], Tyy_o[i,j], τij_v) - τij_v = ( - Txy_o[i,j], - Txy_o[i,j], - Txy_o[i,j], - Txy_o[i,j] - ) - τij_p_o = (Txx_o[i,j], Tyy_o[i,j], τij_v) - # gathermaterial phases - phases_v = ( - Phasev[i ,j ], - Phasev[i+1,j ], - Phasev[i ,j+1], - Phasev[i+1,j+1] - ) # gather vertices around ij center - phases = (Phasec[i,j], Phasec[i,j], phases_v) - # update stress and effective viscosity - Tij, Tii[i,j], η_vep[i,j] = compute_τij(MatParam, εij_p, args, τij_p_o, phases) - Exy = sum(εij_v)*0.25 - xyv_o = sum(τij_v)*0.25 - - # need to compute τij/η_ve(p?) in - # Txx[i,j] += dτ_r * (-(Txx[i,j] - Txx_o[i,j])/(G[i,j]*dt) - Txx[i,j]/η[i,j] + 2*Exx[i,j]) - # Tyy[i,j] += dτ_r * (-(Tyy[i,j] - Tyy_o[i,j])/(G[i,j]*dt) - Tyy[i,j]/η[i,j] + 2*Eyy[i,j]) - # Txy[i,j] += dτ_r * (-(Txy[i,j] - xyv_o)/(G[i,j]*dt) - Txy[i,j]/η[i,j] + 2*sum(εij_v)/4) - - Txx[i,j] += dτ_r * (-Txx[i,j] /(G[i,j]*dt) - Txx[i,j]/η[i,j] + Tij[1] / η_vep[i,j]) - Tyy[i,j] += dτ_r * (-Tyy[i,j] /(G[i,j]*dt) - Tyy[i,j]/η[i,j] + Tij[2] / η_vep[i,j]) - Txy[i,j] += dτ_r * (-Txy[i,j] /(G[i,j]*dt) - Txy[i,j]/η[i,j] + Tij[3] / η_vep[i,j]) - - # Txx[i,j] += dτ_r * (-(Txx[i,j])/(G[i,j]*dt) - Txx[i,j]/η[i,j] + 2*ε_eff[1]) - # Tyy[i,j] += dτ_r * (-(Tyy[i,j])/(G[i,j]*dt) - Tyy[i,j]/η[i,j] + 2*ε_eff[2]) - # Txy[i,j] += dτ_r * (-(Txy[i,j])/(G[i,j]*dt) - Txy[i,j]/η[i,j] + 2*ε_eff[3]) - - # Txx[i,j] += dτ_r * (-(Txx[i,j])/(G[i,j]*dt) - Txx[i,j]/η[i,j] + Tij[1] / η_vep[i,j]) - # Tyy[i,j] += dτ_r * (-(Tyy[i,j])/(G[i,j]*dt) - Tyy[i,j]/η[i,j] + Tij[2] / η_vep[i,j]) - # Txy[i,j] += dτ_r * (-(Txy[i,j])/(G[i,j]*dt) - Txy[i,j]/η[i,j] + Tij[3] / η_vep[i,j]) - - # Txx[i,j] += dτ_r * (-(Txx[i,j]) + Tij[1] ) / η_vep[i,j] # NOTE: from GP Tij = 2*η_vep * εij - # Tyy[i,j] += dτ_r * (-(Tyy[i,j]) + Tij[2] ) / η_vep[i,j] - # Txy[i,j] += dτ_r * (-(Txy[i,j]) + Tij[3] ) / η_vep[i,j] + # need to compute τij/η_ve(p?) in + # Txx[i,j] += dτ_r * (-(Txx[i,j] - Txx_o[i,j])/(G[i,j]*dt) - Txx[i,j]/η[i,j] + 2*Exx[i,j]) + # Tyy[i,j] += dτ_r * (-(Tyy[i,j] - Tyy_o[i,j])/(G[i,j]*dt) - Tyy[i,j]/η[i,j] + 2*Eyy[i,j]) + # Txy[i,j] += dτ_r * (-(Txy[i,j] - xyv_o)/(G[i,j]*dt) - Txy[i,j]/η[i,j] + 2*sum(εij_v)/4) + Txx[i,j] += dτ_r * (-(Txx[i,j]) + Tij[1] ) / η_vep[i,j] # NOTE: from GP Tij = 2*η_vep * εij + Tyy[i,j] += dτ_r * (-(Tyy[i,j]) + Tij[2] ) / η_vep[i,j] + Txy[i,j] += dτ_r * (-(Txy[i,j]) + Tij[3] ) / η_vep[i,j] + end end - Txyv[2:end-1,2:end-1] .= ameanxy(Txy) - + return Txyv[2:(end - 1), 2:(end - 1)] .= ameanxy(Txy) end -@views function update_stresses!(Pr,Pr_old,dPr,K,Txx,Tyy,Txy,Txyv,Txx_o,Tyy_o,Txy_o,TII,Exx,Eyy,Exy,Exyv,Exx_ve,Eyy_ve,Exy_ve,EII_ve,η_vep,Vx,Vy,∇V,η,G,dτ_r,dt,re_mech,vdτ,lτ,r,dx,dy) - θ_dτ = lτ*(r+2.0)/(re_mech*vdτ) - dτ_r .= 1.0./(θ_dτ .+ η./(G.*dt) .+ 1.0) - ∇V .= diff(Vx,dims=1)./dx .+ diff(Vy,dims=2)./dy +@views function update_stresses!( + Pr, + Pr_old, + dPr, + K, + Txx, + Tyy, + Txy, + Txyv, + Txx_o, + Tyy_o, + Txy_o, + Txyv_o, + TII, + Exx, + Eyy, + Exy, + Exyv, + Exx_ve, + Eyy_ve, + Exy_ve, + EII_ve, + η_vep, + Vx, + Vy, + ∇V, + η, + G, + Gv, + dτ_r, + dt, + re_mech, + vdτ, + lτ, + r, + dx, + dy, +) + θ_dτ = lτ * (r + 2.0) / (re_mech * vdτ) + dτ_r .= 1.0 ./ (θ_dτ .+ η ./ (G .* dt) .+ 1.0) + ∇V .= diff(Vx; dims=1) ./ dx .+ diff(Vy; dims=2) ./ dy # dPr .= .-∇V - dPr .= .-∇V .- (Pr .- Pr_old)./K./dt + dPr .= .-∇V .- (Pr .- Pr_old) ./ K ./ dt # Pr .+= (r/θ_dτ).*η.*dPr - Pr .+= dPr./(1.0./(r/θ_dτ.*η) .+ 1.0./K./dt) - Exx .= diff(Vx,dims=1)./dx .- ∇V./3.0 - Eyy .= diff(Vy,dims=2)./dy .- ∇V./3.0 - Exyv[2:end-1,2:end-1] .= 0.5*(diff(Vx[2:end-1,:],dims=2)./dy .+ diff(Vy[:,2:end-1],dims=1)./dx) - Exy .= ameanxy(Exyv) + Pr .+= dPr ./ (1.0 ./ (r / θ_dτ .* η) .+ 1.0 ./ K ./ dt) + Exx .= diff(Vx; dims=1) ./ dx .- ∇V ./ 3.0 + Eyy .= diff(Vy; dims=2) ./ dy .- ∇V ./ 3.0 + Exyv[2:(end - 1), 2:(end - 1)] .= + 0.5 * + (diff(Vx[2:(end - 1), :]; dims=2) ./ dy .+ diff(Vy[:, 2:(end - 1)]; dims=1) ./ dx) + Exy .= ameanxy(Exyv) # visco-elastic strain rates - Exx_ve .= Exx .+ 0.5.*Txx_o./(G.*dt) - Eyy_ve .= Eyy .+ 0.5.*Tyy_o./(G.*dt) - Exy_ve .= Exy .+ 0.5.*Txy_o./(G.*dt) - EII_ve .= sqrt.(0.5.*(Exx_ve.^2 .+ Eyy_ve.^2) .+ Exy_ve.^2) + Exx_ve .= Exx .+ 0.5 .* Txx_o ./ (G .* dt) + Eyy_ve .= Eyy .+ 0.5 .* Tyy_o ./ (G .* dt) + Exy_ve .= Exy .+ 0.5 .* Txy_o ./ (G .* dt) + Exyv_ve = Exyv .+ 0.5 .* Txyv_o ./ (Gv .* dt) + # EII_ve .= sqrt.(0.5.*(Exx_ve.^2 .+ Eyy_ve.^2) .+ Exy_ve.^2) + EII_ve .= sqrt.(0.5 .* (Exx_ve .^ 2 .+ Eyy_ve .^ 2) .+ ameanxy_pow2(Exyv_ve)) # stress increments - Txx .+= (.-(Txx .- Txx_o)./(G.*dt) .- Txx./η .+ 2.0.*Exx).*dτ_r - Tyy .+= (.-(Tyy .- Tyy_o)./(G.*dt) .- Tyy./η .+ 2.0.*Eyy).*dτ_r - Txy .+= (.-(Txy .- Txy_o)./(G.*dt) .- Txy./η .+ 2.0.*Exy).*dτ_r - Txyv[2:end-1,2:end-1] .= ameanxy(Txy) - TII .= sqrt.(0.5.*((Txx).^2 .+ (Tyy).^2) .+ (Txy).^2) + Txx .+= (.-(Txx .- Txx_o) ./ (G .* dt) .- Txx ./ η .+ 2.0 .* Exx) .* dτ_r + Tyy .+= (.-(Tyy .- Tyy_o) ./ (G .* dt) .- Tyy ./ η .+ 2.0 .* Eyy) .* dτ_r + Txy .+= (.-(Txy .- Txy_o) ./ (G .* dt) .- Txy ./ η .+ 2.0 .* Exy) .* dτ_r + Txyv[2:(end - 1), 2:(end - 1)] .= ameanxy(Txy) + # TII .= sqrt.(0.5.*((Txx).^2 .+ (Tyy).^2) .+ (Txy).^2) + TII .= sqrt.(0.5 .* ((Txx) .^ 2 .+ (Tyy) .^ 2) .+ ameanxy_pow2(Txyv)) η_vep .= TII ./ 2.0 ./ EII_ve - return + return nothing end -@views function update_P_strain!(Pr,Pr_old,dPr,K,Exx,Eyy,Exy,Exyv,Vx,Vy,∇V,η,G,dτ_r,dt,re_mech,vdτ,lτ,r,dx,dy) - θ_dτ = lτ*(r+2.0)/(re_mech*vdτ) - dτ_r .= 1.0./(θ_dτ .+ η./(G.*dt) .+ 1.0) - ∇V .= diff(Vx,dims=1)./dx .+ diff(Vy,dims=2)./dy +@views function update_P_strain!( + Pr, + Pr_old, + dPr, + K, + Exx, + Eyy, + Exy, + Exyv, + Vx, + Vy, + ∇V, + η, + G, + dτ_r, + dt, + re_mech, + vdτ, + lτ, + r, + dx, + dy, +) + θ_dτ = lτ * (r + 2.0) / (re_mech * vdτ) + dτ_r .= 1.0 ./ (θ_dτ .+ η ./ (G .* dt) .+ 1.0) + ∇V .= diff(Vx; dims=1) ./ dx .+ diff(Vy; dims=2) ./ dy # dPr .= .-∇V - dPr .= .-∇V .- (Pr .- Pr_old)./K./dt + dPr .= .-∇V .- (Pr .- Pr_old) ./ K ./ dt # Pr .+= (r/θ_dτ).*η.*dPr - Pr .+= dPr./(1.0./(r/θ_dτ.*η) .+ 1.0./K./dt) - Exx .= diff(Vx,dims=1)./dx .- ∇V./3.0 - Eyy .= diff(Vy,dims=2)./dy .- ∇V./3.0 - Exyv[2:end-1,2:end-1] .= 0.5*(diff(Vx[2:end-1,:],dims=2)./dy .+ diff(Vy[:,2:end-1],dims=1)./dx) - Exy .= ameanxy(Exyv) - return + Pr .+= dPr ./ (1.0 ./ (r / θ_dτ .* η) .+ 1.0 ./ K ./ dt) + Exx .= diff(Vx; dims=1) ./ dx .- ∇V ./ 3.0 + Eyy .= diff(Vy; dims=2) ./ dy .- ∇V ./ 3.0 + Exyv[2:(end - 1), 2:(end - 1)] .= + 0.5 * + (diff(Vx[2:(end - 1), :]; dims=2) ./ dy .+ diff(Vy[:, 2:(end - 1)]; dims=1) ./ dx) + Exy .= ameanxy(Exyv) + return nothing end -@views function update_velocities!(Vx,Vy,Pr_c,Txx,Tyy,Txyv,ητ,ρgx,ρgy,vdτ,lτ,re_mech,dx,dy) - ηdτ = vdτ*lτ/re_mech - Vx[2:end-1,:] .+= (diff(.-Pr_c.+Txx,dims=1)./dx .+ diff(Txyv[2:end-1,:],dims=2)./dy .- ρgx).*ηdτ./avx(ητ) - Vy[:,2:end-1] .+= (diff(.-Pr_c.+Tyy,dims=2)./dy .+ diff(Txyv[:,2:end-1],dims=1)./dx .- ρgy).*ηdτ./avy(ητ) - return +@views function update_velocities!( + Vx, Vy, Pr_c, Txx, Tyy, Txyv, ητ, ρgx, ρgy, vdτ, lτ, re_mech, dx, dy +) + ηdτ = vdτ * lτ / re_mech + Vx[2:(end - 1), :] .+= + ( + diff(.-Pr_c .+ Txx; dims=1) ./ dx .+ diff(Txyv[2:(end - 1), :]; dims=2) ./ dy .- + ρgx + ) .* ηdτ ./ avx(ητ) + Vy[:, 2:(end - 1)] .+= + ( + diff(.-Pr_c .+ Tyy; dims=2) ./ dy .+ diff(Txyv[:, 2:(end - 1)]; dims=1) ./ dx .- + ρgy + ) .* ηdτ ./ avy(ητ) + return nothing end -@views function compute_residuals!(r_Vx,r_Vy,Pr_c,Txx,Tyy,Txyv,ρgx,ρgy,dx,dy) - r_Vx .= diff(.-Pr_c[:,2:end-1].+Txx[:,2:end-1],dims=1)./dx .+ diff(Txyv[2:end-1,2:end-1],dims=2)./dy .- ρgx[:,2:end-1] - r_Vy .= diff(.-Pr_c[2:end-1,:].+Tyy[2:end-1,:],dims=2)./dy .+ diff(Txyv[2:end-1,2:end-1],dims=1)./dx .- ρgy[2:end-1,:] - return +@views function compute_residuals!(r_Vx, r_Vy, Pr_c, Txx, Tyy, Txyv, ρgx, ρgy, dx, dy) + r_Vx .= + diff(.-Pr_c[:, 2:(end - 1)] .+ Txx[:, 2:(end - 1)]; dims=1) ./ dx .+ + diff(Txyv[2:(end - 1), 2:(end - 1)]; dims=2) ./ dy .- ρgx[:, 2:(end - 1)] + r_Vy .= + diff(.-Pr_c[2:(end - 1), :] .+ Tyy[2:(end - 1), :]; dims=2) ./ dy .+ + diff(Txyv[2:(end - 1), 2:(end - 1)]; dims=1) ./ dx .- ρgy[2:(end - 1), :] + return nothing end function main(UseGP, nt) @@ -214,159 +328,272 @@ function main(UseGP, nt) #gp_correction = :loop gp_correction = :native_gp # gp_correction = :native_gp_dilation - - do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) - η_reg = 8.0e-3 # regularisation "viscosity" + + do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) + η_reg = 8.0e-3 # regularisation "viscosity" # Physics - Lx, Ly = 1.0, 1.0 # domain size - radi = 0.01 # inclusion radius - τ_y = 1.6 # yield stress. If do_DP=true, τ_y stand for the cohesion: c*cos(ϕ) - ϕ = 30.0 - sinϕ = sind(ϕ)*do_DP # sinus of the friction angle - μ0 = 1.0 # viscous viscosity - G0 = 1.0 # elastic shear modulus - Gi = G0/(6.0-4.0*do_DP) # elastic shear modulus perturbation - εbg = 1.0 # background strain-rate - Coh = τ_y/cosd(ϕ) # cohesion - # Coh = Inf + Lx, Ly = 1.0, 1.0 # domain size + radi = 0.01 # inclusion radius + τ_y = 1.6 # yield stress. If do_DP=true, τ_y stand for the cohesion: c*cos(ϕ) + ϕ = 30.0 + sinϕ = sind(ϕ) * do_DP # sinus of the friction angle + μ0 = 1.0 # viscous viscosity + G0 = 1.0 # elastic shear modulus + Gi = G0 / (6.0 - 4.0 * do_DP) # elastic shear modulus perturbation + εbg = 1.0 # background strain-rate + Coh = τ_y / cosd(ϕ) # cohesion + Coh = Inf # Geoparams initialisation - pl = DruckerPrager_regularised(C=Coh, ϕ=ϕ, η_vp=η_reg, Ψ=0) # non-regularized plasticity - MatParam = (SetMaterialParams(Name="Matrix" , Phase=1, - CompositeRheology = CompositeRheology(SetConstantElasticity(G=G0, ν=0.5),LinearViscous(η=μ0), pl)), - SetMaterialParams(Name="Inclusion", Phase=2, - CompositeRheology = CompositeRheology(SetConstantElasticity(G=Gi, ν=0.5),LinearViscous(η=μ0), pl)), - ) + pl = DruckerPrager_regularised(; C=Coh, ϕ=ϕ, η_vp=η_reg, Ψ=0) # non-regularized plasticity + MatParam = ( + SetMaterialParams(; + Name="Matrix", + Phase=1, + CompositeRheology=CompositeRheology( + SetConstantElasticity(; G=G0, ν=0.5), LinearViscous(; η=μ0), pl + ), + ), + SetMaterialParams(; + Name="Inclusion", + Phase=2, + CompositeRheology=CompositeRheology( + SetConstantElasticity(; G=Gi, ν=0.5), LinearViscous(; η=μ0), pl + ), + ), + ) # Numerics # nt = 10 # number of time steps - nx, ny = 63, 63 # numerical grid resolution - Vdmp = 4.0 # convergence acceleration (damping) - Vsc = 2.0 # iterative time step limiter - Ptsc = 6.0 # iterative time step limiter - ε = 1e-6 # nonlinear tolerence + nx, ny = 63, 63 # numerical grid resolution + Vdmp = 4.0 # convergence acceleration (damping) + Vsc = 2.0 # iterative time step limiter + Ptsc = 6.0 # iterative time step limiter + ε = 1e-6 # nonlinear tolerence iterMax = 3e4 # max number of iters - nout = 200 # check frequency + nout = 200 # check frequency re_mech = 3π - lτ = min(Lx,Ly) - dx, dy = Lx/nx, Ly/ny - vdτ = 0.5*min(dx,dy)/√2.1 - r = 0.7 + lτ = min(Lx, Ly) + dx, dy = Lx / nx, Ly / ny + vdτ = min(dx, dy) / √2.0 #* 0.5 + r = 0.7 # Preprocessing - dx, dy = Lx/nx, Ly/ny - dt = μ0/G0/4.0 # assumes Maxwell time of 4 + dx, dy = Lx / nx, Ly / ny + dt = μ0 / G0 / 4.0 # assumes Maxwell time of 4 # Array initialisation - Pt = zeros(nx ,ny ) - dPt = zeros(nx ,ny ) - Pt_c = zeros(nx ,ny ) - P_o = zeros(nx, ny ) - ∇V = zeros(nx ,ny ) - Vx = zeros(nx+1,ny ) - Vy = zeros(nx ,ny+1) - Exx = zeros(nx ,ny ) - Eyy = zeros(nx ,ny ) - Exy = zeros(nx ,ny ) - Exx_ve = zeros(nx ,ny ) - Eyy_ve = zeros(nx ,ny ) - Exy_ve = zeros(nx ,ny ) - EII_ve = zeros(nx ,ny ) - Exyv = zeros(nx+1,ny+1) - Txx = zeros(nx ,ny ) - Tyy = zeros(nx ,ny ) - Txy = zeros(nx ,ny ) - Txyv = zeros(nx+1,ny+1) - Txx_o = zeros(nx ,ny ) - TII_o = zeros(nx ,ny ) - Tyy_o = zeros(nx ,ny ) - Txy_o = zeros(nx ,ny ) - Txyv_o = zeros(nx+1,ny+1) - TII = zeros(nx ,ny ) - EII = zeros(nx ,ny ) - EII_f = zeros(nx ,ny ) - F = zeros(nx ,ny ) - Fchk = zeros(nx ,ny ) - Pla = zeros(nx ,ny ) - λ = zeros(nx ,ny ) - dQdTxx = zeros(nx ,ny ) - dQdTyy = zeros(nx ,ny ) - dQdTxy = zeros(nx ,ny ) - r_Vx = zeros(nx-1,ny-2) - r_Vy = zeros(nx-2,ny-1) - η_v = μ0*ones(nx, ny) - η_e = dt*G0*ones(nx, ny) - η_ev = dt*G0*ones(nx+1, ny+1) - η_vep = ones(nx, ny) - ητ = zeros(nx ,ny ) - dτ_r = zeros(nx ,ny ) + Pt = zeros(nx, ny) + dPt = zeros(nx, ny) + Pt_c = zeros(nx, ny) + P_o = zeros(nx, ny) + ∇V = zeros(nx, ny) + Vx = zeros(nx + 1, ny) + Vy = zeros(nx, ny + 1) + Exx = zeros(nx, ny) + Eyy = zeros(nx, ny) + Exy = zeros(nx, ny) + Exx_ve = zeros(nx, ny) + Eyy_ve = zeros(nx, ny) + Exy_ve = zeros(nx, ny) + EII_ve = zeros(nx, ny) + Exyv = zeros(nx + 1, ny + 1) + Txx = zeros(nx, ny) + Tyy = zeros(nx, ny) + Txy = zeros(nx, ny) + Txyv = zeros(nx + 1, ny + 1) + Txx_o = zeros(nx, ny) + TII_o = zeros(nx, ny) + Tyy_o = zeros(nx, ny) + Txy_o = zeros(nx, ny) + Txyv_o = zeros(nx + 1, ny + 1) + TII = zeros(nx, ny) + EII = zeros(nx, ny) + EII_f = zeros(nx, ny) + F = zeros(nx, ny) + Fchk = zeros(nx, ny) + Pla = zeros(nx, ny) + λ = zeros(nx, ny) + dQdTxx = zeros(nx, ny) + dQdTyy = zeros(nx, ny) + dQdTxy = zeros(nx, ny) + r_Vx = zeros(nx - 1, ny - 2) + r_Vy = zeros(nx - 2, ny - 1) + η_v = μ0 * ones(nx, ny) + η_e = dt * G0 * ones(nx, ny) + η_ev = dt * G0 * ones(nx + 1, ny + 1) + η_vep = ones(nx, ny) + ητ = zeros(nx, ny) + dτ_r = zeros(nx, ny) - η = ones(nx,ny) - Phasec = ones(Int, nx ,ny ) - Phasev = ones(Int, nx+1,ny+1) + η = ones(nx, ny) + Phasec = ones(Int, nx, ny) + Phasev = ones(Int, nx + 1, ny + 1) # Initial condition - xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) - xc, yc = LinRange(dx/2, Lx-dx/2, nx), LinRange(dy/2, Ly-dy/2, ny) - xv, yv = LinRange(0.0, Lx, nx+1), LinRange(0.0, Ly, ny+1) - Xvx = [x for x=xv,y=yc] - Yvy = [y for x=xc,y=yv] - radc = (xc.-Lx./2).^2 .+ (yc'.-Ly./2).^2 - radv = (xv.-Lx./2).^2 .+ (yv'.-Ly./2).^2 - η_e[radc.= ϵtol) && iter <= maxiter - update_iteration_params!(η,ητ) + update_iteration_params!(η, ητ) if UseGP - update_P_strain!(Pt,Pt_old,dPt,Kb,Exx,Eyy,Exy,Exyv,Vx,Vy,∇V,η,G,dτ_r,dt,re_mech,vdτ,lτ,r,dx,dy) - update_stress_GP2!(Txx, Tyy, Txy, Txyv, TII, Txx_o, Tyy_o, Txy_o, Txyv_o, Exx, Eyy, Exyv, η, η_vep, Pt, Phasec, Phasev, MatParam, dt,G, lτ, r, re_mech, vdτ) + update_P_strain!( + Pt, + Pt_old, + dPt, + Kb, + Exx, + Eyy, + Exy, + Exyv, + Vx, + Vy, + ∇V, + η, + G, + dτ_r, + dt, + re_mech, + vdτ, + lτ, + r, + dx, + dy, + ) + update_stress_GP2!( + Txx, + Tyy, + Txy, + Txyv, + TII, + Txx_o, + Tyy_o, + Txy_o, + Txyv_o, + Exx, + Eyy, + Exyv, + η, + η_vep, + Pt, + Phasec, + Phasev, + MatParam, + dt, + G, + lτ, + r, + re_mech, + vdτ, + ) else - update_stresses!(Pt,Pt_old,dPt,Kb,Txx,Tyy,Txy,Txyv,Txx_o,Tyy_o,Txy_o,TII,Exx,Eyy,Exy,Exyv,Exx_ve,Eyy_ve,Exy_ve,EII_ve,η_vep,Vx,Vy,∇V,η,G,dτ_r,dt,re_mech,vdτ,lτ,r,dx,dy) - end - update_velocities!(Vx,Vy,Pt,Txx,Tyy,Txyv,ητ,ρgx,ρgy,vdτ,lτ,re_mech,dx,dy) - + update_stresses!( + Pt, + Pt_old, + dPt, + Kb, + Txx, + Tyy, + Txy, + Txyv, + Txx_o, + Tyy_o, + Txy_o, + Txyv_o, + TII, + Exx, + Eyy, + Exy, + Exyv, + Exx_ve, + Eyy_ve, + Exy_ve, + EII_ve, + η_vep, + Vx, + Vy, + ∇V, + η, + G, + Gv, + dτ_r, + dt, + re_mech, + vdτ, + lτ, + r, + dx, + dy, + ) + end + update_velocities!( + Vx, Vy, Pt, Txx, Tyy, Txyv, ητ, ρgx, ρgy, vdτ, lτ, re_mech, dx, dy + ) + # update_velocities!(fields,vdτ,lτ,re_mech,dx,dy) if iter % ncheck == 0 # update residuals - compute_residuals!(r_Vx,r_Vy,Pt,Txx,Tyy,Txyv,ρgx,ρgy,dx,dy) + compute_residuals!(r_Vx, r_Vy, Pt, Txx, Tyy, Txyv, ρgx, ρgy, dx, dy) - errs = maximum.((abs.(r_Vx),abs.(r_Vy),abs.(dPt))) - push!(iter_evo,iter/max(nx,ny));append!(errs_evo,errs) - @printf(" iter/nx=%.3f,errs=[ %1.3e, %1.3e, %1.3e ] \n",iter/max(nx,ny),errs...) + errs = maximum.((abs.(r_Vx), abs.(r_Vy), abs.(dPt))) + # push!(iter_evo, iter / max(nx, ny)) + append!(errs_evo, errs) + # @printf( + # " iter/nx=%.3f,errs=[ %1.3e, %1.3e, %1.3e ] \n", + # iter / max(nx, ny), + # errs... + # ) end iter += 1 end t += dt - push!(evo_t,t); push!(evo_τxx,maximum(Txx)) + push!(evo_t, t) + push!(evo_τxx, maximum(Txx)) + push!(iter_evo, iter-1) + # visualisation # mask .= fields.phase; mask[mask.<0.7].=NaN # fields.Vmag .= sqrt.(ameanx(fields.Vx).^2 + ameany(fields.Vy).^2) @@ -382,19 +609,12 @@ function main(UseGP, nt) # display(plot(p1,p2,p3,p4,layout=(2,2))) # png(plot(p1,p2,p3,p4,layout=(2,2)),@sprintf("anim/%04d.png",iframe+=1)) - TII .= sqrt.(0.5.*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) - p2=heatmap(xc,yc, Txy',title="η_vep") - display(p2) + # TII .= sqrt.(0.5.*(Txx.^2 .+ Tyy.^2) .+ Txy.^2) + # p2=heatmap(xc,yc, Txy',title="η_vep") + # display(p2) end return evo_t, evo_τxx, iter_evo, TII, η_vep end -@time evo_t, evo_τxx_GP, iter_evo_GP, TII, η_vep = main(true, 5) -@time evo_t, evo_τxx, iter_evo, TII, η_vep = main(false, 5) - -sol = @. 2.0*1*1*(1.0-exp(-evo_t*1/1)) -scatter(evo_t, sol) -plot!(evo_t, evo_τxx_GP, color=:red) -plot!(evo_t, evo_τxx, color=:black) - -plot(evo_t, @.((evo_τxx_GP-evo_τxx)/evo_τxx*100), color=:black) +@time evo_t, evo_τxx, iter_evo, TII, η_vep = main(false, 25); +@time evo_t, evo_τxx_GP, iter_evo_GP, TII, η_vep = main(true, 25); From 9e4faff36b314dd2e4349f87c8f208fb1e93a535 Mon Sep 17 00:00:00 2001 From: albert-de-montserrat Date: Tue, 15 Nov 2022 12:29:18 +0100 Subject: [PATCH 45/49] ParallelStencil version of damp_V3 with GP --- ...2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl | 298 ++++++++++++++++++ 1 file changed, 298 insertions(+) create mode 100644 GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl new file mode 100644 index 0000000..b6f060c --- /dev/null +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl @@ -0,0 +1,298 @@ +using ElasticArrays, Printf, GeoParams +using Plots, Plots.Measures + +using ParallelStencil +using ParallelStencil.FiniteDifferences2D +@init_parallel_stencil(Threads, Float64, 2) + +plot_opts() = (aspect_ratio = 1, xlims = (0.007936507936507936, 0.9920634920634921), ylims = (0.007936507936507936, 0.9920634920634921), c = cgrad(:roma, rev=true), framestyle = :box) + +@parallel function update_old!(Txx_o, Tyy_o, Txy_o, Txyv_o, Pr_old, Txx, Tyy, Txy, Txyv, Pr) + @all(Txx_o) = @all(Txx) + @all(Tyy_o) = @all(Tyy) + @all(Txy_o) = @all(Txy) + @all(Txyv_o) = @all(Txyv) + @all(Pr_old) = @all(Pr) + return nothing +end + +@views function update_iteration_params!(η, ητ) + ητ[2:(end - 1), 2:(end - 1)] .= maxloc(η) + bc2!(ητ) + return nothing +end + +@parallel_indices (i,j) function update_iteration_params!(η, ητ) + + @inbounds @inline function maxloc(A) + max( + A[i-1, j-1], + A[i , j-1], + A[i+1, j-1], + A[i-1, j ], + A[i , j ], + A[i+1, j ], + A[i-1, j+1], + A[i , j+1], + A[i+1, j+1], + ) + end + + ητ[i, j] = maxloc(η) + + return nothing +end + +function bc2!(ητ) + nx, ny = size(ητ) + @parallel (1:nx) bc2_x!(ητ) + @parallel (1:ny) bc2_y!(ητ) +end + +@parallel_indices (j) function bc2_y!(A) + nx = size(A, 1) + A[1 , j] = A[2 , j] + A[nx, j] = A[nx-1, j] + return nothing +end + +@parallel_indices (i) function bc2_x!(A) + ny = size(A, 2) + A[i, 1] = A[i, 2 ] + A[i, ny] = A[i, ny-1] + return nothing +end + +@parallel_indices (i, j) function update_stress_GP_ps!(Txx, Tyy, Txy, TII, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, Exyv, η_vep, Pt, Phasec, Phasev, MatParam, dt, lτ, r, re_mech, vdτ) + + # convinience closure (note here that i, j are captured because the closure is defined inside the loop when @parallel_indices is expanded) + @inbounds @inline gather(A) = A[i, j], A[i + 1, j], A[i, j + 1], A[i + 1, j + 1] + + # numerics + θ_dτ = lτ * (r + 2.0) / (re_mech * vdτ) + dτ_r = 1.0 / (θ_dτ + 1 / η_vep[i, j]) # equivalent to dτ_r = @. 1.0/(θ_dτ + η/(G*dt) + 1.0) + # Setup up input for GeoParams.jl + args = (; dt=dt, P=Pt[i, j], τII_old=0.0) + εij_p = (Exx[i, j], Eyy[i, j], gather(Exyv)) + τij_p_o = (Txx_o[i,j], Tyy_o[i,j], gather(Txyv_o)) + phases = (Phasec[i, j], Phasec[i, j], gather(Phasev)) + # update stress and effective viscosity + Tij, TII[i, j], ηᵢ = compute_τij(MatParam, εij_p, args, τij_p_o, phases) + Txx[i,j] += dτ_r * (-(Txx[i,j]) + Tij[1] ) / ηᵢ # NOTE: from GP Tij = 2*η_vep * εij + Tyy[i,j] += dτ_r * (-(Tyy[i,j]) + Tij[2] ) / ηᵢ + Txy[i,j] += dτ_r * (-(Txy[i,j]) + Tij[3] ) / ηᵢ + η_vep[i, j] = ηᵢ + + return +end + +@parallel function vertex2center!(center, vertex) + @all(center) = @av(vertex) + return nothing +end + +@parallel function center2vertex!(vertex, center) + @inn(vertex) = @av(center) + return nothing +end + +@parallel function compute_∇V!(∇V, Vx, Vy, dx, dy) + @all(∇V) = @d_xa(Vx) / dx + @d_ya(Vy) / dy + return nothing +end + +@parallel function compute_P!(P, P_old, ∇V, η, K, dt, r, θ_dτ) + @all(P) = @all(P) + (-@all(∇V) - (@all(P) - @all(P_old)) / (@all(K) * dt)) / (1.0 / (r / θ_dτ * @all(η)) + 1.0 /(@all(K) * dt)) + return nothing +end + +@parallel function compute_strain_rate!(∇V, εxx, εyy, εxyv, Vx, Vy, dx, dy) + @all(εxx) = @d_xa(Vx) / dx - @all(∇V) / 3.0 + @all(εyy) = @d_ya(Vy) / dy - @all(∇V) / 3.0 + @inn(εxyv) = 0.5 * (@d_yi(Vx) / dy + @d_xi(Vy) / dx) + return nothing +end + +@parallel_indices (i, j) function update_velocities!(Vx, Vy, P, τxx, τyy, τxyv, ηdτ, ρgx, ρgy, ητ, dx, dy) + + # Again, indices i, j are captured by the closure + @inbounds @inline d_xa(A) = (A[i+1, j ] - A[i , j ]) / dx + @inbounds @inline d_ya(A) = (A[i , j+1] - A[i , j ]) / dy + @inbounds @inline d_xi(A) = (A[i+1, j+1] - A[i , j+1]) / dx + @inbounds @inline d_yi(A) = (A[i+1, j+1] - A[i+1, j ]) / dy + @inbounds @inline av_xa(A) = (A[i , j ] + A[i+1, j ]) * 0.5 + @inbounds @inline av_ya(A) = (A[i , j ] + A[i , j+1]) * 0.5 + + if i ≤ size(P, 1) - 1 + Vx[i+1, j] += (-d_xa(P) + d_xa(τxx) + d_yi(τxyv) - ρgx[i, j]) * ηdτ / av_xa(ητ) + end + if j ≤ size(P, 2) - 1 + Vy[i, j+1] += (-d_ya(P) + d_ya(τyy) + d_xi(τxyv) - ρgy[i, j]) * ηdτ / av_ya(ητ) + end + + return nothing +end + +@parallel function compute_residuals!(Rx, Ry, P, τxx, τyy, τxy, ρgx, ρgy, dx, dy) + @all(Rx) = @d_xa(τxx) / dx + @d_yi(τxy) / dy - @d_xa(P) / dx + @inn_y(ρgx) + @all(Ry) = @d_ya(τyy) / dy + @d_xi(τxy) / dx - @d_ya(P) / dy + @inn_x(ρgy) + return nothing +end + +function main(nt) + # Physics + do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) + η_reg = 8.0e-3 # regularisation "viscosity" + Lx, Ly = 1.0, 1.0 # domain size + radi = 0.01 # inclusion radius + τ_y = 1.6 # yield stress. If do_DP=true, τ_y stand for the cohesion: c*cos(ϕ) + ϕ = 30.0 # friction angle + μ0 = 1.0 # viscous viscosity + G0 = 1.0 # elastic shear modulus + Gi = G0 / (6.0 - 4.0 * do_DP) # elastic shear modulus perturbation + εbg = 1.0 # background strain-rate + Coh = τ_y / cosd(ϕ) # cohesion; if we let Coh = Inf, we recover visco-elastic problem + # Geoparams initialisation + pl = DruckerPrager_regularised(; C=Coh, ϕ=ϕ, η_vp=η_reg, Ψ=0) # non-regularized plasticity + MatParam = ( + SetMaterialParams(; + Name="Matrix", + Phase=1, + CompositeRheology=CompositeRheology( + SetConstantElasticity(; G=G0, ν=0.5), LinearViscous(; η=μ0), pl + ), + ), + SetMaterialParams(; + Name="Inclusion", + Phase=2, + CompositeRheology=CompositeRheology( + SetConstantElasticity(; G=Gi, ν=0.5), LinearViscous(; η=μ0), pl + ), + ), + ) + # Numerics + nx, ny = 63, 63 # numerical grid resolution + Vdmp = 4.0 # convergence acceleration (damping) + Vsc = 2.0 # iterative time step limiter + Ptsc = 6.0 # iterative time step limiter + ε = 1e-6 # nonlinear tolerence + iterMax = 3e4 # max number of iters + nout = 200 # check frequency + re_mech = 3π + lτ = min(Lx, Ly) + dx, dy = Lx / nx, Ly / ny + vdτ = min(dx, dy) / √2.0 #* 0.5 + r = 0.7 + θ_dτ = lτ * (r + 2.0) / (re_mech * vdτ) + ηdτ = vdτ * lτ / re_mech + # Preprocessing + dx, dy = Lx / nx, Ly / ny + dt = μ0 / G0 / 4.0 # assumes Maxwell time of 4 + # Array initialisation + Pt = zeros(nx, ny) + dPt = zeros(nx, ny) + Pt_old = zeros(nx, ny) + ∇V = zeros(nx, ny) + Vx = zeros(nx + 1, ny) + Vy = zeros(nx, ny + 1) + Exx = zeros(nx, ny) + Eyy = zeros(nx, ny) + Exy = zeros(nx, ny) + Exyv = zeros(nx + 1, ny + 1) + Txx = zeros(nx, ny) + Tyy = zeros(nx, ny) + Txy = zeros(nx, ny) + Txyv = zeros(nx + 1, ny + 1) + Txx_o = zeros(nx, ny) + Tyy_o = zeros(nx, ny) + Txy_o = zeros(nx, ny) + Txyv_o = zeros(nx + 1, ny + 1) + TII = zeros(nx, ny) + Rx = zeros(nx - 1, ny - 2) + Ry = zeros(nx - 2, ny - 1) + η_vep = ones(nx, ny) + η = ones(nx, ny) + ητ = zeros(nx, ny) + Phasec = ones(Int, nx, ny) + Phasev = ones(Int, nx + 1, ny + 1) + ρgx = zeros(nx - 1, ny ) + ρgy = zeros(nx , ny - 1) + Kb = fill(Inf, nx, ny) + # Initial condition + xc, yc = LinRange(dx / 2, Lx - dx / 2, nx), LinRange(dy / 2, Ly - dy / 2, ny) + xc, yc = LinRange(dx / 2, Lx - dx / 2, nx), LinRange(dy / 2, Ly - dy / 2, ny) + xv, yv = LinRange(0.0, Lx, nx + 1), LinRange(0.0, Ly, ny + 1) + Xvx = [x for x in xv, y in yc] + Yvy = [y for x in xc, y in yv] + radc = (xc .- Lx ./ 2) .^ 2 .+ (yc' .- Ly ./ 2) .^ 2 + radv = (xv .- Lx ./ 2) .^ 2 .+ (yv' .- Ly ./ 2) .^ 2 + η_e[radc .< radi] .= dt * Gi + η_ev[radv .< radi] .= dt * Gi + Phasec[radc .< radi] .= 2 + Phasev[radv .< radi] .= 2 + η_vep .= (1.0 ./ η_e + 1.0 ./ η_v) .^ -1 + Vx .= εbg .* Xvx + Vy .= .-εbg .* Yvy + # Time loop + t = 0.0 + maxiter = 10e3 + ncheck = 500 + ϵtol = 1e-6 + evo_t = Float64[] + iter_evo = Int64[] + evo_t = Float64[] + evo_τxx = Float64[] + errs_evo = ElasticMatrix{Float64}(undef, length(ϵtol), 0) + for it in 1:nt + @printf("it=%d\n", it) + @parallel update_old!(Txx_o, Tyy_o, Txy_o, Txyv_o, Pt_old, Txx, Tyy, Txy, Txyv, Pt) + errs = 2.0 .* ϵtol + iter = 1 + # resize!(iter_evo, 0) + resize!(errs_evo, length(ϵtol), 0) + while any(errs .>= ϵtol) && iter <= maxiter + # update_iteration_params!(η, ητ) + @parallel (2:nx-1, 2:ny-1) update_iteration_params!(η, ητ) + bc2!(ητ) + + @parallel compute_∇V!(∇V, Vx, Vy, dx, dy) + @parallel compute_P!(Pt, Pt_old, ∇V, η, Kb, dt, r, θ_dτ) + @parallel compute_strain_rate!(∇V, Exx, Eyy, Exyv, Vx, Vy, dx, dy) + @parallel vertex2center!(Exy, Exyv) + @parallel (1:nx, 1:ny) update_stress_GP_ps!(Txx, Tyy, Txy, TII, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, Exyv, η_vep, Pt, Phasec, Phasev, MatParam, dt, lτ, r, re_mech, vdτ) + @parallel center2vertex!(Txyv, Txy) + + @parallel (1:nx, 1:ny) update_velocities!(Vx, Vy, Pt, Txx, Tyy, Txyv, ηdτ, ρgx, ρgy, ητ, dx, dy) + + if iter % ncheck == 0 + # update residuals + @parallel compute_residuals!(Rx, Ry, Pt, Txx, Tyy, Txyv, ρgx, ρgy, dx, dy) + errs = max(abs.(Rx), abs.(Ry), abs.(dPt)) + # push!(iter_evo, iter / max(nx, ny)) + append!(errs_evo, errs) + @printf( + " iter/nx=%.3f,errs=[ %1.3e, %1.3e, %1.3e ] \n", + iter / max(nx, ny), + errs... + ) + end + iter += 1 + end + t += dt + push!(evo_t, t) + push!(evo_τxx, maximum(Txx)) + push!(iter_evo, iter-1) + + # visualisation + p1 = heatmap(xc, yc, Pt' , title="Pressure"; plot_opts()...) + p3 = heatmap(xc, yc, TII' , title="TII" ; plot_opts()...) + p2 = heatmap(xc, yc, η_vep', title="η_vep" ; plot_opts()...) + p4 = plot(evo_t,evo_τxx,legend=false,xlabel="time",ylabel="max(Txx)",linewidth=0,markershape=:circle,markersize=3,framestyle=:box) + display(plot(p1,p2,p3,p4,layout=(2,2))) + # png(plot(p1,p2,p3,p4,layout=(2,2)),@sprintf("anim/%04d.png",iframe+=1)) + end + return +end + +nt = 12 # number of time steps +@time main(nt); \ No newline at end of file From 26dc251eeae0c772180268dcc7f462d8c4fee8ea Mon Sep 17 00:00:00 2001 From: albert-de-montserrat Date: Tue, 15 Nov 2022 13:21:00 +0100 Subject: [PATCH 46/49] GPU friendly & cosmetic changes --- ...2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl | 144 ++++++++---------- 1 file changed, 64 insertions(+), 80 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl index b6f060c..d95d455 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl @@ -1,24 +1,17 @@ using ElasticArrays, Printf, GeoParams using Plots, Plots.Measures - using ParallelStencil using ParallelStencil.FiniteDifferences2D -@init_parallel_stencil(Threads, Float64, 2) +@init_parallel_stencil(CUDA, Float64, 2) plot_opts() = (aspect_ratio = 1, xlims = (0.007936507936507936, 0.9920634920634921), ylims = (0.007936507936507936, 0.9920634920634921), c = cgrad(:roma, rev=true), framestyle = :box) -@parallel function update_old!(Txx_o, Tyy_o, Txy_o, Txyv_o, Pr_old, Txx, Tyy, Txy, Txyv, Pr) - @all(Txx_o) = @all(Txx) - @all(Tyy_o) = @all(Tyy) - @all(Txy_o) = @all(Txy) - @all(Txyv_o) = @all(Txyv) - @all(Pr_old) = @all(Pr) - return nothing -end - -@views function update_iteration_params!(η, ητ) - ητ[2:(end - 1), 2:(end - 1)] .= maxloc(η) - bc2!(ητ) +@parallel function update_old!(τxx_o, Tyy_o, τxy_o, τxyv_o, Pt_old, τxx, τyy, τxy, τxyv, Pt) + @all(τxx_o) = @all(τxx) + @all(Tyy_o) = @all(τyy) + @all(τxy_o) = @all(τxy) + @all(τxyv_o) = @all(τxyv) + @all(Pt_old) = @all(Pt) return nothing end @@ -63,7 +56,7 @@ end return nothing end -@parallel_indices (i, j) function update_stress_GP_ps!(Txx, Tyy, Txy, TII, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, Exyv, η_vep, Pt, Phasec, Phasev, MatParam, dt, lτ, r, re_mech, vdτ) +@parallel_indices (i, j) function update_stress_GP_ps!(τxx, τyy, τxy, TII, τxx_o, Tyy_o, τxyv_o, εxx, εyy, εxyv, η_vep, Pt, Phasec, Phasev, MatParam, dt, lτ, r, re_mech, vdτ) # convinience closure (note here that i, j are captured because the closure is defined inside the loop when @parallel_indices is expanded) @inbounds @inline gather(A) = A[i, j], A[i + 1, j], A[i, j + 1], A[i + 1, j + 1] @@ -73,14 +66,14 @@ end dτ_r = 1.0 / (θ_dτ + 1 / η_vep[i, j]) # equivalent to dτ_r = @. 1.0/(θ_dτ + η/(G*dt) + 1.0) # Setup up input for GeoParams.jl args = (; dt=dt, P=Pt[i, j], τII_old=0.0) - εij_p = (Exx[i, j], Eyy[i, j], gather(Exyv)) - τij_p_o = (Txx_o[i,j], Tyy_o[i,j], gather(Txyv_o)) + εij_p = (εxx[i, j], εyy[i, j], gather(εxyv)) + τij_p_o = (τxx_o[i,j], Tyy_o[i,j], gather(τxyv_o)) phases = (Phasec[i, j], Phasec[i, j], gather(Phasev)) # update stress and effective viscosity Tij, TII[i, j], ηᵢ = compute_τij(MatParam, εij_p, args, τij_p_o, phases) - Txx[i,j] += dτ_r * (-(Txx[i,j]) + Tij[1] ) / ηᵢ # NOTE: from GP Tij = 2*η_vep * εij - Tyy[i,j] += dτ_r * (-(Tyy[i,j]) + Tij[2] ) / ηᵢ - Txy[i,j] += dτ_r * (-(Txy[i,j]) + Tij[3] ) / ηᵢ + τxx[i,j] += dτ_r * (-(τxx[i,j]) + Tij[1] ) / ηᵢ # NOTE: from GP Tij = 2*η_vep * εij + τyy[i,j] += dτ_r * (-(τyy[i,j]) + Tij[2] ) / ηᵢ + τxy[i,j] += dτ_r * (-(τxy[i,j]) + Tij[3] ) / ηᵢ η_vep[i, j] = ηᵢ return @@ -101,8 +94,9 @@ end return nothing end -@parallel function compute_P!(P, P_old, ∇V, η, K, dt, r, θ_dτ) - @all(P) = @all(P) + (-@all(∇V) - (@all(P) - @all(P_old)) / (@all(K) * dt)) / (1.0 / (r / θ_dτ * @all(η)) + 1.0 /(@all(K) * dt)) +@parallel function compute_P!(P, P_old, RP, ∇V, η, K, dt, r, θ_dτ) + @all(RP) = (-@all(∇V) - (@all(P) - @all(P_old)) / (@all(K) * dt)) + @all(P) = @all(P) + (-@all(∇V) - (@all(P) - @all(P_old)) / (@all(K) * dt)) / (1.0 / (r / θ_dτ * @all(η)) + 1.0 /(@all(K) * dt)) return nothing end @@ -171,17 +165,11 @@ function main(nt) ), ) # Numerics - nx, ny = 63, 63 # numerical grid resolution - Vdmp = 4.0 # convergence acceleration (damping) - Vsc = 2.0 # iterative time step limiter - Ptsc = 6.0 # iterative time step limiter - ε = 1e-6 # nonlinear tolerence - iterMax = 3e4 # max number of iters - nout = 200 # check frequency + nx, ny = 255, 255 # numerical grid resolution re_mech = 3π lτ = min(Lx, Ly) dx, dy = Lx / nx, Ly / ny - vdτ = min(dx, dy) / √2.0 #* 0.5 + vdτ = min(dx, dy) / √2.1 #* 0.5 r = 0.7 θ_dτ = lτ * (r + 2.0) / (re_mech * vdτ) ηdτ = vdτ * lτ / re_mech @@ -189,48 +177,45 @@ function main(nt) dx, dy = Lx / nx, Ly / ny dt = μ0 / G0 / 4.0 # assumes Maxwell time of 4 # Array initialisation - Pt = zeros(nx, ny) - dPt = zeros(nx, ny) - Pt_old = zeros(nx, ny) - ∇V = zeros(nx, ny) - Vx = zeros(nx + 1, ny) - Vy = zeros(nx, ny + 1) - Exx = zeros(nx, ny) - Eyy = zeros(nx, ny) - Exy = zeros(nx, ny) - Exyv = zeros(nx + 1, ny + 1) - Txx = zeros(nx, ny) - Tyy = zeros(nx, ny) - Txy = zeros(nx, ny) - Txyv = zeros(nx + 1, ny + 1) - Txx_o = zeros(nx, ny) - Tyy_o = zeros(nx, ny) - Txy_o = zeros(nx, ny) - Txyv_o = zeros(nx + 1, ny + 1) - TII = zeros(nx, ny) - Rx = zeros(nx - 1, ny - 2) - Ry = zeros(nx - 2, ny - 1) - η_vep = ones(nx, ny) - η = ones(nx, ny) - ητ = zeros(nx, ny) - Phasec = ones(Int, nx, ny) - Phasev = ones(Int, nx + 1, ny + 1) - ρgx = zeros(nx - 1, ny ) - ρgy = zeros(nx , ny - 1) - Kb = fill(Inf, nx, ny) + Pt = @zeros(nx, ny) + Pt_old = @zeros(nx, ny) + RP = @zeros(nx, ny) + ∇V = @zeros(nx, ny) + Vx = @zeros(nx + 1, ny) + Vy = @zeros(nx, ny + 1) + εxx = @zeros(nx, ny) + εyy = @zeros(nx, ny) + Exy = @zeros(nx, ny) + εxyv = @zeros(nx + 1, ny + 1) + τxx = @zeros(nx, ny) + τyy = @zeros(nx, ny) + τxy = @zeros(nx, ny) + τxyv = @zeros(nx + 1, ny + 1) + τxx_o = @zeros(nx, ny) + Tyy_o = @zeros(nx, ny) + τxy_o = @zeros(nx, ny) + τxyv_o = @zeros(nx + 1, ny + 1) + TII = @zeros(nx, ny) + Rx = @zeros(nx - 1, ny - 2) + Ry = @zeros(nx - 2, ny - 1) + η_vep = @ones(nx, ny) + η = @ones(nx, ny) + ητ = @zeros(nx, ny) + Phasec = Int.(@ones(nx, ny)) + Phasev = Int.(@ones(nx + 1, ny + 1)) + ρgx = @zeros(nx - 1, ny ) + ρgy = @zeros(nx , ny - 1) + Kb = @fill(Inf, nx, ny) # Initial condition xc, yc = LinRange(dx / 2, Lx - dx / 2, nx), LinRange(dy / 2, Ly - dy / 2, ny) xc, yc = LinRange(dx / 2, Lx - dx / 2, nx), LinRange(dy / 2, Ly - dy / 2, ny) xv, yv = LinRange(0.0, Lx, nx + 1), LinRange(0.0, Ly, ny + 1) - Xvx = [x for x in xv, y in yc] - Yvy = [y for x in xc, y in yv] + Xvx = Data.Array([x for x in xv, y in yc]) + Yvy = Data.Array([y for x in xc, y in yv]) radc = (xc .- Lx ./ 2) .^ 2 .+ (yc' .- Ly ./ 2) .^ 2 radv = (xv .- Lx ./ 2) .^ 2 .+ (yv' .- Ly ./ 2) .^ 2 - η_e[radc .< radi] .= dt * Gi - η_ev[radv .< radi] .= dt * Gi Phasec[radc .< radi] .= 2 Phasev[radv .< radi] .= 2 - η_vep .= (1.0 ./ η_e + 1.0 ./ η_v) .^ -1 Vx .= εbg .* Xvx Vy .= .-εbg .* Yvy # Time loop @@ -245,29 +230,28 @@ function main(nt) errs_evo = ElasticMatrix{Float64}(undef, length(ϵtol), 0) for it in 1:nt @printf("it=%d\n", it) - @parallel update_old!(Txx_o, Tyy_o, Txy_o, Txyv_o, Pt_old, Txx, Tyy, Txy, Txyv, Pt) + @parallel update_old!(τxx_o, Tyy_o, τxy_o, τxyv_o, Pt_old, τxx, τyy, τxy, τxyv, Pt) errs = 2.0 .* ϵtol iter = 1 # resize!(iter_evo, 0) resize!(errs_evo, length(ϵtol), 0) while any(errs .>= ϵtol) && iter <= maxiter - # update_iteration_params!(η, ητ) @parallel (2:nx-1, 2:ny-1) update_iteration_params!(η, ητ) bc2!(ητ) @parallel compute_∇V!(∇V, Vx, Vy, dx, dy) - @parallel compute_P!(Pt, Pt_old, ∇V, η, Kb, dt, r, θ_dτ) - @parallel compute_strain_rate!(∇V, Exx, Eyy, Exyv, Vx, Vy, dx, dy) - @parallel vertex2center!(Exy, Exyv) - @parallel (1:nx, 1:ny) update_stress_GP_ps!(Txx, Tyy, Txy, TII, Txx_o, Tyy_o, Txyv_o, Exx, Eyy, Exyv, η_vep, Pt, Phasec, Phasev, MatParam, dt, lτ, r, re_mech, vdτ) - @parallel center2vertex!(Txyv, Txy) + @parallel compute_P!(Pt, Pt_old, RP, ∇V, η, Kb, dt, r, θ_dτ) + @parallel compute_strain_rate!(∇V, εxx, εyy, εxyv, Vx, Vy, dx, dy) + @parallel vertex2center!(Exy, εxyv) + @parallel (1:nx, 1:ny) update_stress_GP_ps!(τxx, τyy, τxy, TII, τxx_o, Tyy_o, τxyv_o, εxx, εyy, εxyv, η_vep, Pt, Phasec, Phasev, MatParam, dt, lτ, r, re_mech, vdτ) + @parallel center2vertex!(τxyv, τxy) - @parallel (1:nx, 1:ny) update_velocities!(Vx, Vy, Pt, Txx, Tyy, Txyv, ηdτ, ρgx, ρgy, ητ, dx, dy) + @parallel (1:nx, 1:ny) update_velocities!(Vx, Vy, Pt, τxx, τyy, τxyv, ηdτ, ρgx, ρgy, ητ, dx, dy) if iter % ncheck == 0 # update residuals - @parallel compute_residuals!(Rx, Ry, Pt, Txx, Tyy, Txyv, ρgx, ρgy, dx, dy) - errs = max(abs.(Rx), abs.(Ry), abs.(dPt)) + @parallel compute_residuals!(Rx, Ry, Pt, τxx, τyy, τxyv, ρgx, ρgy, dx, dy) + errs = maximum.((abs.(Rx), abs.(Ry), abs.(RP))) # push!(iter_evo, iter / max(nx, ny)) append!(errs_evo, errs) @printf( @@ -280,14 +264,14 @@ function main(nt) end t += dt push!(evo_t, t) - push!(evo_τxx, maximum(Txx)) + push!(evo_τxx, maximum(τxx)) push!(iter_evo, iter-1) # visualisation - p1 = heatmap(xc, yc, Pt' , title="Pressure"; plot_opts()...) - p3 = heatmap(xc, yc, TII' , title="TII" ; plot_opts()...) - p2 = heatmap(xc, yc, η_vep', title="η_vep" ; plot_opts()...) - p4 = plot(evo_t,evo_τxx,legend=false,xlabel="time",ylabel="max(Txx)",linewidth=0,markershape=:circle,markersize=3,framestyle=:box) + p1 = heatmap(xc, yc, Array(Pt)' , title="Pressure"; plot_opts()...) + p3 = heatmap(xc, yc, Array(TII)' , title="TII" ; plot_opts()...) + p2 = heatmap(xc, yc, Array(η_vep)', title="η_vep" ; plot_opts()...) + p4 = plot(evo_t,evo_τxx,legend=false,xlabel="time",ylabel="max(τxx)",linewidth=0,markershape=:circle,markersize=3,framestyle=:box) display(plot(p1,p2,p3,p4,layout=(2,2))) # png(plot(p1,p2,p3,p4,layout=(2,2)),@sprintf("anim/%04d.png",iframe+=1)) end @@ -295,4 +279,4 @@ function main(nt) end nt = 12 # number of time steps -@time main(nt); \ No newline at end of file +@time main(nt); From ba4b4ee9eceff9f4d13755d6005a0d8a1f0ea291 Mon Sep 17 00:00:00 2001 From: albert-de-montserrat Date: Tue, 15 Nov 2022 16:26:34 +0100 Subject: [PATCH 47/49] fix BC kernel --- ...Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl index c9ce961..bfa9201 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampv3.jl @@ -618,3 +618,19 @@ end @time evo_t, evo_τxx, iter_evo, TII, η_vep = main(false, 25); @time evo_t, evo_τxx_GP, iter_evo_GP, TII, η_vep = main(true, 25); + + +sol = @. 2.0 * 1 * 1 * (1.0 - exp(-evo_t * 1 / 1)) +scatter(evo_t, sol) +plot!(evo_t, evo_τxx; color=:black, label="native v3", legend=:topleft) +plot!(evo_t, evo_τxx_GP; color=:orange, label="GP v3") + +# plot!(evo_t, evo_Txx_v2; linestyle=:dash, color=:black, label="native v2") +# plot!(evo_t, evo_Txx_GP_v2; linestyle=:dash, color=:orange, label="GP v2") + +# plot(evo_t, zeros(size(evo_t)), color=:gray, linestyle=:dash, xlabel="time", ylabel="error (%)", legend=:bottomright ) +# plot!(evo_t, @.((evo_τxx-sol)/sol*100), label="native v3", xlabel="time", ylabel="error (%)" ) +# plot!(evo_t, @.((evo_τxx_GP-sol)/sol*100), label="GP v3", xlabel="time", ylabel="error (%)" ) + +# plot!(evo_t, @.((evo_Txx_v2-sol)/sol*100), linestyle=:dash, label="native v2", xlabel="time", ylabel="error (%)" ) +# plot!(evo_t, @.((evo_Txx_GP_v2-sol)/sol*100), linestyle=:dash, label="GP v2", xlabel="time", ylabel="error (%)" ) \ No newline at end of file From 4968251d238ee9d4ff5de6e3881a9860ce9297f6 Mon Sep 17 00:00:00 2001 From: albert-de-montserrat Date: Wed, 16 Nov 2022 09:44:19 +0100 Subject: [PATCH 48/49] fix bcs kernels --- .../Stokes2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl index d95d455..0d7ffb5 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl @@ -38,18 +38,18 @@ end function bc2!(ητ) nx, ny = size(ητ) - @parallel (1:nx) bc2_x!(ητ) - @parallel (1:ny) bc2_y!(ητ) + @parallel (1:ny) bc2_x!(ητ) + @parallel (1:nx) bc2_y!(ητ) end -@parallel_indices (j) function bc2_y!(A) +@parallel_indices (j) function bc2_x!(A) nx = size(A, 1) A[1 , j] = A[2 , j] A[nx, j] = A[nx-1, j] return nothing end -@parallel_indices (i) function bc2_x!(A) +@parallel_indices (i) function bc2_y!(A) ny = size(A, 2) A[i, 1] = A[i, 2 ] A[i, ny] = A[i, ny-1] @@ -275,8 +275,9 @@ function main(nt) display(plot(p1,p2,p3,p4,layout=(2,2))) # png(plot(p1,p2,p3,p4,layout=(2,2)),@sprintf("anim/%04d.png",iframe+=1)) end + return end nt = 12 # number of time steps -@time main(nt); +@time main(nt); \ No newline at end of file From c664ea2f0f7c80bf656bbb2815234e4d0afc694e Mon Sep 17 00:00:00 2001 From: albert-de-montserrat Date: Tue, 29 Nov 2022 15:09:41 +0100 Subject: [PATCH 49/49] fix a couple of bugs --- ...2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl index 0d7ffb5..05b627c 100644 --- a/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl +++ b/GeoParams_PT_examples/scripts/Stokes2D_VEP_reg_ctau_inv_GeoParams_dampV3_ps.jl @@ -2,7 +2,7 @@ using ElasticArrays, Printf, GeoParams using Plots, Plots.Measures using ParallelStencil using ParallelStencil.FiniteDifferences2D -@init_parallel_stencil(CUDA, Float64, 2) +@init_parallel_stencil(Threads, Float64, 2) plot_opts() = (aspect_ratio = 1, xlims = (0.007936507936507936, 0.9920634920634921), ylims = (0.007936507936507936, 0.9920634920634921), c = cgrad(:roma, rev=true), framestyle = :box) @@ -56,14 +56,15 @@ end return nothing end -@parallel_indices (i, j) function update_stress_GP_ps!(τxx, τyy, τxy, TII, τxx_o, Tyy_o, τxyv_o, εxx, εyy, εxyv, η_vep, Pt, Phasec, Phasev, MatParam, dt, lτ, r, re_mech, vdτ) +@parallel_indices (i, j) function update_stress_GP_ps!(τxx, τyy, τxy, TII, τxx_o, Tyy_o, τxyv_o, εxx, εyy, εxyv, G, η, η_vep, Pt, Phasec, Phasev, MatParam, dt, lτ, r, re_mech, vdτ) # convinience closure (note here that i, j are captured because the closure is defined inside the loop when @parallel_indices is expanded) @inbounds @inline gather(A) = A[i, j], A[i + 1, j], A[i, j + 1], A[i + 1, j + 1] # numerics θ_dτ = lτ * (r + 2.0) / (re_mech * vdτ) - dτ_r = 1.0 / (θ_dτ + 1 / η_vep[i, j]) # equivalent to dτ_r = @. 1.0/(θ_dτ + η/(G*dt) + 1.0) + # dτ_r = 1.0 / (θ_dτ + 1 / η_vep[i, j]) # equivalent to dτ_r = @. 1.0/(θ_dτ + η/(G*dt) + 1.0) + dτ_r = 1.0 / (θ_dτ / η[i, j] + 1 / η_vep[i, j]) # equivalent to dτ_r = @. 1.0/(θ_dτ + η/(G*dt) + 1.0) # Setup up input for GeoParams.jl args = (; dt=dt, P=Pt[i, j], τII_old=0.0) εij_p = (εxx[i, j], εyy[i, j], gather(εxyv)) @@ -127,12 +128,24 @@ end return nothing end -@parallel function compute_residuals!(Rx, Ry, P, τxx, τyy, τxy, ρgx, ρgy, dx, dy) - @all(Rx) = @d_xa(τxx) / dx + @d_yi(τxy) / dy - @d_xa(P) / dx + @inn_y(ρgx) - @all(Ry) = @d_ya(τyy) / dy + @d_xi(τxy) / dx - @d_ya(P) / dy + @inn_x(ρgy) +@parallel_indices (i, j) function compute_residuals!(Rx, Ry, P, τxx, τyy, τxy, ρgx, ρgy, dx, dy) + + # Again, indices i, j are captured by the closure + @inbounds @inline d_xa(A) = (A[i+1, j+1] - A[i , j+1]) / dx + @inbounds @inline d_ya(A) = (A[i+1, j+1] - A[i+1, j ]) / dy + @inbounds @inline d_xi(A) = (A[i+2, j+1] - A[i+1, j+1]) / dy + @inbounds @inline d_yi(A) = (A[i+1, j+2] - A[i+1, j+1]) / dx + + if i ≤ size(Rx, 1) && j ≤ size(Rx, 2) + Rx[i, j] = d_xa(τxx) + d_yi(τxy) - d_xa(P) - ρgx[i , j+1] + end# + if i ≤ size(Ry, 1) && j ≤ size(Ry, 2)# + Ry[i, j] = d_ya(τyy) + d_xi(τxy) - d_ya(P) - ρgy[i+1, j ] + end return nothing end + function main(nt) # Physics do_DP = true # do_DP=false: Von Mises, do_DP=true: Drucker-Prager (friction angle) @@ -146,6 +159,7 @@ function main(nt) Gi = G0 / (6.0 - 4.0 * do_DP) # elastic shear modulus perturbation εbg = 1.0 # background strain-rate Coh = τ_y / cosd(ϕ) # cohesion; if we let Coh = Inf, we recover visco-elastic problem + # Coh =Inf # cohesion; if we let Coh = Inf, we recover visco-elastic problem # Geoparams initialisation pl = DruckerPrager_regularised(; C=Coh, ϕ=ϕ, η_vp=η_reg, Ψ=0) # non-regularized plasticity MatParam = ( @@ -165,7 +179,7 @@ function main(nt) ), ) # Numerics - nx, ny = 255, 255 # numerical grid resolution + nx, ny = 63, 63 # numerical grid resolution re_mech = 3π lτ = min(Lx, Ly) dx, dy = Lx / nx, Ly / ny @@ -216,6 +230,11 @@ function main(nt) radv = (xv .- Lx ./ 2) .^ 2 .+ (yv' .- Ly ./ 2) .^ 2 Phasec[radc .< radi] .= 2 Phasev[radv .< radi] .= 2 + η_e = dt * G0 * @ones(nx, ny) + η_e[radc .< radi] .= dt * Gi + η_vep .= (1.0 ./ η_e + 1.0 ./ η) .^ -1 + Gc = @fill(G0, nx, ny) + Gc[radc .< radi] .= Gi Vx .= εbg .* Xvx Vy .= .-εbg .* Yvy # Time loop @@ -243,14 +262,14 @@ function main(nt) @parallel compute_P!(Pt, Pt_old, RP, ∇V, η, Kb, dt, r, θ_dτ) @parallel compute_strain_rate!(∇V, εxx, εyy, εxyv, Vx, Vy, dx, dy) @parallel vertex2center!(Exy, εxyv) - @parallel (1:nx, 1:ny) update_stress_GP_ps!(τxx, τyy, τxy, TII, τxx_o, Tyy_o, τxyv_o, εxx, εyy, εxyv, η_vep, Pt, Phasec, Phasev, MatParam, dt, lτ, r, re_mech, vdτ) + @parallel (1:nx, 1:ny) update_stress_GP_ps!(τxx, τyy, τxy, TII, τxx_o, Tyy_o, τxyv_o, εxx, εyy, εxyv, Gc, η, η_vep, Pt, Phasec, Phasev, MatParam, dt, lτ, r, re_mech, vdτ) @parallel center2vertex!(τxyv, τxy) @parallel (1:nx, 1:ny) update_velocities!(Vx, Vy, Pt, τxx, τyy, τxyv, ηdτ, ρgx, ρgy, ητ, dx, dy) if iter % ncheck == 0 # update residuals - @parallel compute_residuals!(Rx, Ry, Pt, τxx, τyy, τxyv, ρgx, ρgy, dx, dy) + @parallel (1:nx, 1:ny) compute_residuals!(Rx, Ry, Pt, τxx, τyy, τxyv, ρgx, ρgy, dx, dy) errs = maximum.((abs.(Rx), abs.(Ry), abs.(RP))) # push!(iter_evo, iter / max(nx, ny)) append!(errs_evo, errs) @@ -279,5 +298,5 @@ function main(nt) return end -nt = 12 # number of time steps +nt = 15 # number of time steps @time main(nt); \ No newline at end of file