Skip to content

Commit

Permalink
Merge pull request #112 from vavrines/dev
Browse files Browse the repository at this point in the history
Adopt new format style
  • Loading branch information
vavrines authored Oct 19, 2024
2 parents 54574f5 + fd73e77 commit 55f6abf
Show file tree
Hide file tree
Showing 114 changed files with 1,936 additions and 3,118 deletions.
9 changes: 8 additions & 1 deletion .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
format_docstrings = true
always_for_in = true
remove_extra_newlines = true
always_use_return = true
whitespace_in_kwargs = false
format_docstrings = true
separate_kwargs_with_semicolon = true
disallow_single_arg_nesting = true
format_markdown = true
24 changes: 12 additions & 12 deletions benchmark/parallel_distribute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ dt = ks.ps.dx[1] / (5.0 + KitBase.sound_speed(ks.ib.primL, ks.gas.γ))
nt = floor(ks.set.maxTime / dt) |> Int

#--- parallel ---#
wp = SharedArray{Float64}((ks.ps.nx, 3), init = A -> (A = zeros(ks.ps.nx, 3)))
for i = 1:ks.ps.nx
wp = SharedArray{Float64}((ks.ps.nx, 3); init=A -> (A = zeros(ks.ps.nx, 3)))
for i in 1:ks.ps.nx
if i <= ks.ps.nx ÷ 2
wp[i, :] .= ks.ib.wL
else
wp[i, :] .= ks.ib.wR
end
end
fwp = SharedArray{Float64}((ks.ps.nx + 1, 3), init = A -> (A = zeros(ks.ps.nx + 1, 3)))
fwp = SharedArray{Float64}((ks.ps.nx + 1, 3); init=A -> (A = zeros(ks.ps.nx + 1, 3)))

@time for iter = 1:nt÷3
@sync @distributed for i = 2:ks.ps.nx
@time for iter in 1:nt÷3
@sync @distributed for i in 2:ks.ps.nx
flux = @view fwp[i, :]
KitBase.flux_gks!(
flux,
Expand All @@ -68,8 +68,8 @@ fwp = SharedArray{Float64}((ks.ps.nx + 1, 3), init = A -> (A = zeros(ks.ps.nx +
)
end

@sync @distributed for i = 2:ks.ps.nx-1
for j = 1:3
@sync @distributed for i in 2:ks.ps.nx-1
for j in 1:3
wp[i, j] += (fwp[i, j] - fwp[i+1, j]) / ks.ps.dx[i]
end
end
Expand All @@ -78,7 +78,7 @@ end

#--- serial ---#
w = zeros(ks.ps.nx, 3)
for i = 1:ks.ps.nx
for i in 1:ks.ps.nx
if i <= ks.ps.nx ÷ 2
w[i, :] .= ks.ib.wL
else
Expand All @@ -87,8 +87,8 @@ for i = 1:ks.ps.nx
end
fw = zeros(ks.ps.nx + 1, 3)

@time for iter = 1:nt÷3
for i = 2:ks.ps.nx
@time for iter in 1:nt÷3
for i in 2:ks.ps.nx
flux = @view fw[i, :]
KitBase.flux_gks!(
flux,
Expand All @@ -104,8 +104,8 @@ fw = zeros(ks.ps.nx + 1, 3)
)
end

for i = 2:ks.ps.nx-1
for j = 1:3
for i in 2:ks.ps.nx-1
for j in 1:3
w[i, j] += (fw[i, j] - fw[i+1, j]) / ks.ps.dx[i]
end
end
Expand Down
4 changes: 2 additions & 2 deletions benchmark/structarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ end

ks = SolverSet(D)

ctr, a1face, a2face = KitBase.init_fvm(ks, ks.ps; structarray = true)
ctr0, a1face0, a2face0 = KitBase.init_fvm(ks, ks.ps; structarray = false)
ctr, a1face, a2face = KitBase.init_fvm(ks, ks.ps; structarray=true)
ctr0, a1face0, a2face0 = KitBase.init_fvm(ks, ks.ps; structarray=false)

using BenchmarkTools

Expand Down
24 changes: 11 additions & 13 deletions deprecated/diffeqoperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@ Note that for upwind difference, the coeff = 1/-1 can't take the default value a
function finite_difference(
y::AA,
x::AA,
coeff = 1,
uL = first(y),
uR = last(y);
method = :central,
dimension = 1,
derivative = 1,
truncation = 2,
bc = :dirichlet,
coeff=1,
uL=first(y),
uR=last(y);
method=:central,
dimension=1,
derivative=1,
truncation=2,
bc=:dirichlet,
)

oprtfn = eval(difffn[method])

i0 = firstindex(x)
Expand All @@ -69,7 +68,6 @@ function finite_difference(
end

return Δ * B * y

end

function finite_difference(y, dx::Real, args...; kwargs...)
Expand All @@ -80,6 +78,6 @@ end
# test
u = Float64[0, 1, 2, 3, 2, 1, 0]
dx = 1.0
KitBase.finite_difference(u, dx; method = :central, bc = :period)
KitBase.finite_difference(u, dx; method = :central, bc = :none)
KitBase.finite_difference(u, dx, -1; method = :upwind, bc = :none)
KitBase.finite_difference(u, dx; method=:central, bc=:period)
KitBase.finite_difference(u, dx; method=:central, bc=:none)
KitBase.finite_difference(u, dx, -1; method=:upwind, bc=:none)
8 changes: 4 additions & 4 deletions deprecated/pycall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function __init__()
@info "Kinetic will run with $(show_worker(np)) and $(show_thread(nt))"
end=#

copy!(itp, pyimport("scipy.interpolate"))
return copy!(itp, pyimport("scipy.interpolate"))
end

"""
Expand All @@ -53,7 +53,7 @@ function boltzmann_nuode!(df, f::AA{T,3}, p, t) where {T}
_df = boltzmann_fft(_f, Kn, M, phi, psi, phipsi)

curve1 = itp.RegularGridInterpolator((u1, v1, w1), _df)
df .= reshape(curve1(vnu), nu, nv, nw)
return df .= reshape(curve1(vnu), nu, nv, nw)
end

boltzmann_nuode!(
Expand All @@ -71,7 +71,7 @@ Maxwell quadrature
## Arguments
* `N`: quadrature order (MUST less than 33)
"""
function maxwell_quadrature(N::Integer, C = 1)
function maxwell_quadrature(N::Integer, C=1)
@assert N <= 33

py"""
Expand Down Expand Up @@ -110,5 +110,5 @@ function maxwell_quadrature(N::Integer, C = 1)
return (Xis, weights)
"""

p, w = py"dvGH"(N, C)
return p, w = py"dvGH"(N, C)
end
22 changes: 7 additions & 15 deletions dev/cylinder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ begin
)
ps = CSpace2D(1.0, 6.0, 20, 0.0, π, 40, 1, 1)
vs = VSpace2D(-10.0, 10.0, 36, -10.0, 10.0, 36)
gas = Gas(Kn = 5e-2, Ma = 5.0, Pr = 1.0, K = 1.0)
gas = Gas(; Kn=5e-2, Ma=5.0, Pr=1.0, K=1.0)

prim0 = [1.0, 0.0, 0.0, 1.0]
prim1 = [1.0, gas.Ma * sound_speed(1.0, gas.γ), 0.0, 1.0]
Expand Down Expand Up @@ -46,19 +46,11 @@ ctr, a1face, a2face = KitBase.init_fvm(ks, ks.ps)
t = 0.0
dt = timestep(ks, ctr, 0.0)
nt = ks.set.maxTime ÷ dt |> Int
@showprogress for iter = 1:500#nt
evolve!(ks, ctr, a1face, a2face, dt; bc = [:maxwell, :extra, :mirror, :mirror])
update!(
ks,
ctr,
a1face,
a2face,
dt,
zeros(4);
bc = [:maxwell, :extra, :mirror, :mirror],
)
@showprogress for iter in 1:500#nt
evolve!(ks, ctr, a1face, a2face, dt; bc=[:maxwell, :extra, :mirror, :mirror])
update!(ks, ctr, a1face, a2face, dt, zeros(4); bc=[:maxwell, :extra, :mirror, :mirror])

for j = ks.ps.÷2+1:ks.ps.
for j in ks.ps.÷2+1:ks.ps.
ctr[ks.ps.nr+1, j].w .= ks.ib.fw(6, 0)
ctr[ks.ps.nr+1, j].prim .= conserve_prim(ctr[ks.ps.nr+1, j].w, ks.gas.γ)
ctr[ks.ps.nr+1, j].sw .= 0.0
Expand All @@ -79,7 +71,7 @@ begin
contourf(
ps.x[1:ks.ps.nr, 1:ks.ps.nθ],
ps.y[1:ks.ps.nr, 1:ks.ps.nθ],
sol[:, :, 1],
ratio = 1,
sol[:, :, 1];
ratio=1,
)
end
4 changes: 2 additions & 2 deletions dev/hllc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ ks, ctr, face, t = initialize("config.txt")
dt = timestep(ks, ctr, t)
nt = Int(floor(ks.set.maxTime / dt))
res = zeros(3)
for iter = 1:nt
for iter in 1:nt
#reconstruct!(ks, ctr)
evolve!(ks, ctr, face, dt; mode = :hllc)
evolve!(ks, ctr, face, dt; mode=:hllc)
update!(ks, ctr, face, dt, res)
end

Expand Down
36 changes: 18 additions & 18 deletions dev/ib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ using KitBase.ProgressMeter: @showprogress
using PyCall
itp = pyimport("scipy.interpolate")

set = Setup(
case = "cylinder",
space = "2d0f0v",
boundary = ["fix", "extra", "mirror", "extra"],
limiter = "minmod",
cfl = 0.1,
maxTime = 2.0, # time
flux = "hll",
hasForce = true,
set = Setup(;
case="cylinder",
space="2d0f0v",
boundary=["fix", "extra", "mirror", "extra"],
limiter="minmod",
cfl=0.1,
maxTime=2.0, # time
flux="hll",
hasForce=true,
)
ps = PSpace2D(0, 3, 60, 0, 2, 40, 1, 1)
vs = VSpace2D(-3, 3, 28, -3, 3, 28)
gas = Gas(Kn = 1e-3, Ma = 0.1, K = 1.0)
gas = Gas(; Kn=1e-3, Ma=0.1, K=1.0)

prim0 = [1.0, 0.0, 0.0, 1.0]
prim1 = [1.0, gas.Ma * sound_speed(1.0, gas.γ), 0.0, 1.0]
Expand All @@ -38,7 +38,7 @@ ib = IB2F(fw, ff, bc, NamedTuple())

#ks = SolverSet(set, ps, vs, gas, ib)
ks = SolverSet(set, ps, nothing, gas, ib)
ctr, a1face, a2face = init_fvm(ks; structarray = true)
ctr, a1face, a2face = init_fvm(ks; structarray=true)

radius = 1
θs = linspace(0, π / 2, 30)
Expand All @@ -48,7 +48,7 @@ lps = hcat(xs, ys)
h = ps.dx[1]
ΔV = 2π * radius / 4 / length(θs) * h

scatter(xs, ys, xticks = 0:0.05:3, yticks = 0:0.05:1, ratio = 1)
scatter(xs, ys; xticks=0:0.05:3, yticks=0:0.05:1, ratio=1)

struct IB{T1,T2,T3,TF,ND}
xlp::T1 # position of Lagrangian points
Expand Down Expand Up @@ -149,8 +149,8 @@ function updatef!(KS, ctr, a1face, a2face, dt, residual;)
sumRes = zero(ctr[1].w)
sumAvg = zero(ctr[1].w)

@inbounds @threads for j 1:ny
for i 1:nx
@inbounds @threads for j in 1:ny
for i in 1:nx
stepf!(
ctr[i, j].w,
ctr[i, j].prim,
Expand All @@ -172,14 +172,14 @@ function updatef!(KS, ctr, a1face, a2face, dt, residual;)
residual[i] = sqrt(sumRes[i] * nx * ny) / (sumAvg[i] + 1.e-7)
end

KitBase.bc_extra!(ctr; dirc = :xr)
KitBase.bc_extra!(ctr; dirc = :yr)
KitBase.bc_mirror!(ctr; dirc = :yl)
KitBase.bc_extra!(ctr; dirc=:xr)
KitBase.bc_extra!(ctr; dirc=:yr)
KitBase.bc_mirror!(ctr; dirc=:yl)

return nothing
end

@showprogress for iter = 1:50#nt
@showprogress for iter in 1:50#nt
evolve!(ks, ctr, a1face, a2face, dt)
ib_force!(ks.ps, ctr, ib.xlp)
updatef!(ks, ctr, a1face, a2face, dt, res)
Expand Down
Loading

0 comments on commit 55f6abf

Please sign in to comment.