Skip to content

Commit

Permalink
ad unit test for revise
Browse files Browse the repository at this point in the history
  • Loading branch information
omlins committed Dec 6, 2024
1 parent 88a2694 commit d0e9cc4
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/test_projects/Diffusion3D_Revise/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name = "Diffusion3D_Revise"
uuid = "763c5dee-143d-409d-8529-7cbbae6ea527"
authors = ["Samuel Omlin <[email protected]>"]
version = "0.1.0"

[deps]
ParallelStencil = "94395366-693c-11ea-3b26-d9b7aac5d958"

[compat]
ParallelStencil = ">= 0.4.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Diffusion3D_Revise
using ParallelStencil
using ParallelStencil.FiniteDifferences3D
@init_parallel_stencil(Threads, Float64, 3)
include(joinpath(@__DIR__, "diffusion3D_tmp.jl"))
end
39 changes: 39 additions & 0 deletions test/test_projects/Diffusion3D_Revise/src/diffusion3D_tmp.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@parallel function diffusion3D_step!(T2, T, Ci, lam, dt, dx, dy, dz)
@inn(T2) = @inn(T) + dt*(lam*@inn(Ci)*(@d2_xi(T)/dx^2 + @d2_yi(T)/dy^2 + @d2_zi(T)/dz^2));
return
end

function diffusion3D()
# Physics
lam = 1.0; # Thermal conductivity
cp_min = 1.0; # Minimal heat capacity
lx, ly, lz = 10.0, 10.0, 10.0; # Length of computational domain in dimension x, y and z

# Numerics
nx, ny, nz = 8, 8, 8; # Number of gridpoints in dimensions x, y and z
nt = 3; # Number of time steps
dx = lx/(nx-1); # Space step in x-dimension
dy = ly/(ny-1); # Space step in y-dimension
dz = lz/(nz-1); # Space step in z-dimension

# Array initializations
T = @zeros(nx, ny, nz);
T2 = @zeros(nx, ny, nz);
Ci = @zeros(nx, ny, nz);

# Initial conditions (heat capacity and temperature with two Gaussian anomalies each)
Ci .= 1.0./( cp_min .+ Data.Array([5*exp(-(((ix-1)*dx-lx/1.5))^2-(((iy-1)*dy-ly/2))^2-(((iz-1)*dz-lz/1.5))^2) +
5*exp(-(((ix-1)*dx-lx/3.0))^2-(((iy-1)*dy-ly/2))^2-(((iz-1)*dz-lz/1.5))^2) for ix=1:size(T,1), iy=1:size(T,2), iz=1:size(T,3)]) )
T .= Data.Array([100*exp(-(((ix-1)*dx-lx/2)/2)^2-(((iy-1)*dy-ly/2)/2)^2-(((iz-1)*dz-lz/3.0)/2)^2) +
50*exp(-(((ix-1)*dx-lx/2)/2)^2-(((iy-1)*dy-ly/2)/2)^2-(((iz-1)*dz-lz/1.5)/2)^2) for ix=1:size(T,1), iy=1:size(T,2), iz=1:size(T,3)])
T2 .= T; # Assign also T2 to get correct boundary conditions.

# Time loop
dt = min(dx^2,dy^2,dz^2)*cp_min/lam/8.1; # Time step for the 3D Heat diffusion
for it = 1:nt
@parallel diffusion3D_step!(T2, T, Ci, lam, dt, dx, dy, dz);
T, T2 = T2, T;
end

return false
end

0 comments on commit d0e9cc4

Please sign in to comment.