Skip to content

Commit ad10be0

Browse files
committed
moves CUDA functionality implementation in AddCudaFunctionalityTracerAdvDiff
1 parent 236d781 commit ad10be0

File tree

3 files changed

+53
-107
lines changed

3 files changed

+53
-107
lines changed

examples/cudaexamples/cu_cellularflow.jl

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/physics/traceradvdiff.jl

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function ConstDiffSteadyFlowParams(eta, kap, kaph, nkaph, u::Function, v::Functi
100100
end
101101

102102
ConstDiffSteadyFlowParams(eta, kap, kaph, nkaph, u, v,
103-
g) = ConstDiffSteadyFlowParams{typeof(eta)}(eta, kap, kaph, nkaph, u, v)
103+
g) = ConstDiffSteadyFlowParams{typeof(eta)}(eta, kap, kaph, nkaph, u, v)
104104
ConstDiffSteadyFlowParams(eta, kap, u, v, g) = ConstDiffSteadyFlowParams(eta, kap, 0eta, 0, u, v, g)
105105

106106

@@ -148,46 +148,6 @@ function Vars(g)
148148
end
149149

150150

151-
# --
152-
# CUDA functionality
153-
# --
154-
155-
@require CuArrays begin
156-
157-
using CuArrays
158-
159-
function CuProblem(; stepper="RK4", kwargs...)
160-
prob = Problem(; kwargs...)
161-
162-
dt = prob.ts.dt
163-
g = CuTwoDGrid(prob.grid)
164-
pr = CuParams(prob.params)
165-
vs = CuVars(prob.vars)
166-
eq = CuEquation(prob.eqn)
167-
ts = FourierFlows.autoconstructtimestepper(stepper, dt, eq.LC, g)
168-
169-
FourierFlows.CuProblem(g, vs, pr, eq, ts)
170-
end
171-
172-
eval(FourierFlows.structvarsexpr(:CuVars, physicalvars, transformvars, arraytype=:CuArray))
173-
174-
struct CuConstDiffSteadyFlowParams{T} <: AbstractSteadyFlowParams
175-
eta::T # Constant horizontal diffusivity
176-
kap::T # Constant vertical diffusivity
177-
kaph::T # Constant isotropic hyperdiffusivity
178-
nkaph::Int # Constant isotropic hyperdiffusivity order
179-
u::CuArray{T,2} # Advecting x-velocity
180-
v::CuArray{T,2} # Advecting y-velocity
181-
end
182-
183-
CuVars(v) = CuVars(getfield.(v, fieldnames(v))...)
184-
CuVars(g::AbstractGrid) = CuVars(Vars(g))
185-
186-
CuParams(p::ConstDiffSteadyFlowParams) = CuConstDiffSteadyFlowParams(getfield.(p, fieldnames(p))...)
187-
CuParams(p::ConstDiffParams) = p
188-
189-
end # CUDA stuff
190-
191151

192152
# --
193153
# Solvers

test/test_traceradvdiff.jl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,55 @@ function test_diffusion(stepper, dt, tfinal; steadyflow = true)
113113
end
114114

115115

116+
"""
117+
test_hyperdiffusion(; kwargs...)
118+
119+
Diffuses a gaussian concentration c0(x, y, t) using hyperdiffusivity and
120+
compares the final state with the analytic solution of the heat equation, cfinal
121+
"""
122+
function test_hyperdiffusion(stepper, dt, tfinal; steadyflow = true)
123+
124+
nx = 128
125+
Lx = 2π
126+
kap = 0.0 # no diffusivity
127+
eta = kap # no diffusivity
128+
kaph = 0.01 # hyperdiffusivity coeff
129+
nkaph = 1 # nkaph=1 converts hyperdiffusivity to plain diffusivity
130+
# so we can compare with the analytic solution of heat equation
131+
132+
nsteps = round(Int, tfinal/dt)
133+
134+
if !isapprox(tfinal, nsteps*dt, rtol=1e-12)
135+
error("tfinal is not multiple of dt")
136+
end
137+
138+
139+
g = TwoDGrid(nx, Lx)
140+
141+
u, v = 0*g.X, 0*g.X
142+
143+
vs = TracerAdvDiff.Vars(g)
144+
pr = TracerAdvDiff.ConstDiffSteadyFlowParams(eta, kap, kaph, nkaph, u, v, g)
145+
eq = TracerAdvDiff.Equation(pr, g)
146+
ts = FourierFlows.autoconstructtimestepper(stepper, dt, eq.LC, g)
147+
prob = FourierFlows.Problem(g, vs, pr, eq, ts)
148+
149+
c0ampl, σ = 0.1, 0.1
150+
c0func(x, y) = c0ampl*exp.(-(x.^2+y.^2)/(2σ^2))
151+
152+
c0 = c0func.(g.X, g.Y)
153+
tfinal = nsteps*dt
154+
σt = sqrt(2*kaph*tfinal + σ^2)
155+
cfinal = c0ampl*σ^2/σt^2 * exp.(-(g.X.^2 + g.Y.^2)/(2*σt^2))
156+
157+
TracerAdvDiff.set_c!(prob, c0)
158+
159+
stepforward!(prob, nsteps)
160+
TracerAdvDiff.updatevars!(prob)
161+
162+
isapprox(cfinal, vs.c, rtol=g.nx*g.ny*nsteps*1e-12)
163+
end
164+
116165

117166
# --
118167
# Run tests
@@ -131,3 +180,6 @@ dt, tfinal = 0.005, 0.1
131180

132181
dt, tfinal = 0.005, 0.1
133182
@test test_diffusion(stepper, dt, tfinal; steadyflow=false)
183+
184+
dt, tfinal = 0.005, 0.1
185+
@test test_hyperdiffusion(stepper, dt, tfinal; steadyflow=true)

0 commit comments

Comments
 (0)