Skip to content

Commit 9c810da

Browse files
committed
UI improvements
1 parent 291c0fb commit 9c810da

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

src/physics/traceradvdiff.jl

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,47 @@ abstract type AbstractSteadyFlowParams <: AbstractParams end
1414
1515
Construct a constant diffusivity problem with steady or time-varying flow.
1616
"""
17+
noflow(args...) = 0.0
18+
1719
Problem(; kwargs...) = ConstDiffProblem(; kwargs...) # only problem defined for now
1820

21+
function flowargs(u)
22+
umethods = methods(u)
23+
length(umethods.ms) == 1 ? umethods.ms[1].nargs-1 : error("Either define steadyflow or use a flow function
24+
with only one argument.")
25+
end
26+
1927
function ConstDiffProblem(;
20-
grid = nothing,
2128
nx = 128,
2229
Lx = 2π,
2330
ny = nx,
2431
Ly = Lx,
32+
grid = TwoDGrid(nx, Lx, ny, Ly),
2533
kap = 0.1,
2634
eta = kap,
27-
u = nothing,
28-
v = nothing,
35+
u = noflow,
36+
v = noflow,
2937
dt = 0.01,
3038
stepper = "RK4",
31-
steadyflow = false
39+
steadyflow = nothing
3240
)
3341

34-
zerofunction(args...) = 0.0
35-
36-
# Defaults
37-
if u != nothing; uin = u
38-
else; uin = zerofunction
39-
end
40-
41-
if v != nothing; vin = v
42-
else; vin = zerofunction
43-
end
44-
45-
if grid == nothing; g = TwoDGrid(nx, Lx, ny, Ly)
46-
else; g = grid
42+
if steadyflow==nothing # deduce whether flow is time-dependent
43+
if (typeof(u) <: Function && flowargs(u) > 2) || (typeof(v) <: Function && flowargs(v) > 2)
44+
steadyflow = false
45+
else
46+
steadyflow = true
47+
end
4748
end
4849

49-
vs = TracerAdvDiff.Vars(g)
5050
if steadyflow; pr = TracerAdvDiff.ConstDiffSteadyFlowParams(eta, kap, uin, vin, g)
5151
else; pr = TracerAdvDiff.ConstDiffParams(eta, kap, uin, vin)
5252
end
53+
54+
vs = TracerAdvDiff.Vars(g)
5355
eq = TracerAdvDiff.Equation(pr, g)
5456
ts = FourierFlows.autoconstructtimestepper(stepper, dt, eq.LC, g)
57+
5558
FourierFlows.Problem(g, vs, pr, eq, ts)
5659
end
5760

@@ -91,14 +94,16 @@ struct ConstDiffSteadyFlowParams{T} <: AbstractSteadyFlowParams
9194
v::Array{T,2} # Advecting y-velocity
9295
end
9396

94-
function ConstDiffSteadyFlowParams(eta, kap, kaph, nkaph, u::Function, v::Function, g)
95-
ugrid = u.(g.X, g.Y)
96-
vgrid = v.(g.X, g.Y)
97+
function ConstDiffSteadyFlowParams(eta, kap, kaph, nkaph, u, v, g)
98+
if typeof(u) <: Function; ugrid = u.(g.X, g.Y)
99+
else; ugrid = u
100+
end
101+
if typeof(v) <: Function; vgrid = v.(g.X, g.Y)
102+
else; vgrid = v
103+
end
97104
ConstDiffSteadyFlowParams(eta, kap, kaph, nkaph, ugrid, vgrid)
98105
end
99106

100-
ConstDiffSteadyFlowParams(eta, kap, kaph, nkaph, u, v,
101-
g) = ConstDiffSteadyFlowParams{typeof(eta)}(eta, kap, kaph, nkaph, u, v)
102107
ConstDiffSteadyFlowParams(eta, kap, u, v, g) = ConstDiffSteadyFlowParams(eta, kap, 0eta, 0, u, v, g)
103108

104109

0 commit comments

Comments
 (0)