I want to apply a difusion for a two- dimensional plat using the DiffEqGPU package.
when I used the Euler method as a for loop it worked.
My code looks like this
module Playground
using CUDA
using CairoMakie
using ColorSchemes
const α = 1e-4 # Diffusivity
const L = 0.1 # Length
const W = 0.1 # Width
const Nx = 66 # No.of steps in x-axis
const Ny = 66 # No.of steps in y-axis
const Δx = L/(Nx-1) # x-grid spacing
const Δy = W/(Ny-1) # y-grid spacing
const Δt = Δx^2 * Δy^2 / (2.0 * α * (Δx^2 + Δy^2)) # Largest stable time step
function diffuse!(du, u, p,t)
dijij = view(du, 2:Nx-1, 2:Ny-1)
dij = view(u, 2:Nx-1, 2:Ny-1)
di1j = view(u, 1:Nx-2, 2:Ny-1)
dij1 = view(u, 2:Nx-1, 1:Ny-2)
di2j = view(u, 3:Nx , 2:Ny-1)
dij2 = view(u, 2:Nx-1, 3:Ny ) # Stencil Computations
@. dijij = α * (
(di1j - 2 * dij + di2j)/Δx^2 +
(dij1 - 2 * dij + dij2)/Δy^2) # Apply diffusion
du[1, :] += α * (2*u[2, :] - 2*u[1, :])/Δx^2
du[Nx, :] += α * (2*u[Nx-1, :] - 2*u[Ny, :])/Δx^2
du[:, 1] += α * (2*u[:, 2]-2*u[:, 1])/Δy^2
du[:, Ny] += α * (2*u[:, Nx-1]-2*u[:, Ny])/Δy^2 # update boundary condition (Neumann BCs)
end
u_GPU= CUDA.zeros(Nx,Ny)
du_GPU = similar(u_GPU)
u_GPU[25:35, 25:35] .= 50
for i in 1:1000 # Apply the diffuse 1000 time to let the heat spread a long the rod
diffuse!(du_GPU, u_GPU,0,0)
u_GPU = u_GPU + Δt * du_GPU
end
By using the DifferentialEquations and DiffEqGPU packeges.
It works slowly with sol = solve(prob, Euler(), dt=Δt). but when I tried sol2 = solve(prob, QNDF()) I get this ERROR: DimensionMismatch(“array could not be broadcast to match destination”) , for sol3= solve(prob, FBDF()) ERROR: This object is not a GPU array, The last one which I tried was
sol4 = solve(prob, alg_hins=[:stiff], save_everystep=false) and it takes alot of time without outcomes.
using DifferentialEquations, DiffEqGPU
tspan = (0.0, 1.0)
prob = ODEProblem(diffuse!, u_GPU, tspan)
sol = solve(prob, Euler(), dt=Δt)
sol2 = solve(prob, QNDF())
sol3 = solve(prob, FBDF())
sol4 = solve(prob, alg_hins=[:stiff], save_everystep=false)
Unfortunately, no matter which solver I chose. It is so slow or it doesn’t work.
Thanks for your help
[/quote]