From cbd7659e8d22a2d67c7a5a1f16d5bc6cd63387a4 Mon Sep 17 00:00:00 2001 From: Pascal Aellig Date: Tue, 13 Aug 2024 18:13:46 +0200 Subject: [PATCH] fix docs; add interpolation test --- docs/src/man/subduction2D/rheology.md | 2 + docs/src/man/subduction2D/setup.md | 2 +- test/test_Interpolations.jl | 91 +++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 test/test_Interpolations.jl diff --git a/docs/src/man/subduction2D/rheology.md b/docs/src/man/subduction2D/rheology.md index f8a43ae4..e3ce827d 100644 --- a/docs/src/man/subduction2D/rheology.md +++ b/docs/src/man/subduction2D/rheology.md @@ -18,6 +18,8 @@ density_lithosphere = PT_Density(; ρ0=3.2e3, α = α, β = 0e0, T0 = 273+1474) We will run the case where the rheology is given by a combination of dislocation and diffusion creep for wet olivine, ```julia +using GeoParams.Dislocation +using GeoParams.Diffusion disl_wet_olivine = SetDislocationCreep(Dislocation.wet_olivine1_Hirth_2003) diff_wet_olivine = SetDiffusionCreep(Diffusion.wet_olivine_Hirth_2003) ``` diff --git a/docs/src/man/subduction2D/setup.md b/docs/src/man/subduction2D/setup.md index 71fbf685..ccabc85d 100644 --- a/docs/src/man/subduction2D/setup.md +++ b/docs/src/man/subduction2D/setup.md @@ -79,7 +79,7 @@ add_box!( Grid2D; xlim = (Lx-1430, Lx-1430-250), zlim = (-80, 0.0), - Origin = (nothing, StrikeAngle=0, DipAngle=-30), + Origin = nothing, StrikeAngle=0, DipAngle=-30, phase = LithosphericPhases(Layers=[8 72], Phases=[2 1 0]), T = HalfspaceCoolingTemp(Tsurface=20, Tmantle=Tbot, Age=80, Adiabat=0.4) ) diff --git a/test/test_Interpolations.jl b/test/test_Interpolations.jl new file mode 100644 index 00000000..5dc793f8 --- /dev/null +++ b/test/test_Interpolations.jl @@ -0,0 +1,91 @@ +push!(LOAD_PATH, "..") + +@static if ENV["JULIA_JUSTRELAX_BACKEND"] === "AMDGPU" + using AMDGPU + AMDGPU.allowscalar(true) +elseif ENV["JULIA_JUSTRELAX_BACKEND"] === "CUDA" + using CUDA + CUDA.allowscalar(true) +end + +using Test +using JustRelax, JustRelax.JustRelax2D +using ParallelStencil, ParallelStencil.FiniteDifferences2D + +const backend_JR = @static if ENV["JULIA_JUSTRELAX_BACKEND"] === "AMDGPU" + @init_parallel_stencil(AMDGPU, Float64, 2) + AMDGPUBackend +elseif ENV["JULIA_JUSTRELAX_BACKEND"] === "CUDA" + @init_parallel_stencil(CUDA, Float64, 2) + CUDABackend +else + @init_parallel_stencil(Threads, Float64, 2) + CPUBackend +end + +import JustRelax.JustRelax2D: interp_Vx∂ρ∂x_on_Vy!, interp_Vx_on_Vy! + + +@testset "Interpolations" begin + + # Set up mock data + # Physical domain ------------------------------------ + ly = 1.0 # domain length in y + lx = 1.0 # domain length in x + nx, ny, nz = 4, 4, 4 # number of cells + ni = nx, ny # number of cells + igg = IGG(init_global_grid(nx, ny, 1; init_MPI= true)...) + li = lx, ly # domain length in x- and y- + di = @. li / ni # grid step in x- and -y + origin = 0.0, -ly # origin coordinates (15km f sticky air layer) + grid = Geometry(ni, li; origin = origin) + (; xci, xvi) = grid + + + # 2D case + stokes = StokesArrays(backend_JR, ni) + thermal = ThermalArrays(backend_JR, ni) + ρg = @ones(ni) + Vx_on_Vy = @zeros(size(stokes.V.Vy)) + + stokes.viscosity.η .= @fill(1.0) + stokes.V.Vy .= @fill(10) + thermal.T .= @fill(100) + thermal.Told .= @fill(50) + stokes.τ.xy_c .= @fill(1.0) + temperature2center!(thermal) + + + @test thermal.Tc[1,1] == 100 + + thermal.ΔT .= thermal.T .- thermal.Told + vertex2center!(thermal.ΔTc, thermal.ΔT) + @test thermal.ΔTc[1,1] == 50 + + center2vertex!(stokes.τ.xy, stokes.τ.xy_c) + @test stokes.τ.xy[2,2] == 1.0 + + Vx_v = @ones(ni.+1...) + Vy_v = @ones(ni.+1...) + + velocity2vertex!(Vx_v, Vy_v, stokes.V.Vx, stokes.V.Vy) + @test Vx_v[1,1] == 0.0 + @test Vy_v[1,1] == 10.0 + + Vx_v = @ones(ni.+1...) + Vy_v = @ones(ni.+1...) + velocity2vertex!(Vx_v, Vy_v, stokes.V.Vx, stokes.V.Vy; ghost_nodes=false) + @test Vx_v[1,1] == 0.0 + @test Vy_v[1,1] == 10.0 + + @parallel (1:(size(stokes.V.Vy, 1) - 2), 1:size(stokes.V.Vy, 2)) interp_Vx_on_Vy!( + Vx_on_Vy, stokes.V.Vx + ) + @test Vx_on_Vy[2,2] == 0.0 + + @parallel (1:(size(stokes.V.Vy, 1) - 2), 1:size(stokes.V.Vy, 2)) interp_Vx∂ρ∂x_on_Vy!( + Vx_on_Vy, stokes.V.Vx, ρg, inv(di[1]) + ) + @test Vx_on_Vy[2,2] == 0.0 + +end