Skip to content

Commit

Permalink
Merge pull request #70 from vavrines/dev
Browse files Browse the repository at this point in the history
- Fix head in 1D tecplot writer
- Rm default rotation indicator in maxwell boundary
- Loose annotation in maxwell boundary flux
- Add VDF for dispatch
- Clean gauss_moments
- Add julia formatter config file
- Add step support for unstructured velocity
- Adopt extract_last in flux functions
- Split fn and st in update methods
- Unify boundary treatments in flux & update
  • Loading branch information
vavrines authored Aug 1, 2022
2 parents 14d7946 + 2d86939 commit ab8c1bb
Show file tree
Hide file tree
Showing 28 changed files with 1,942 additions and 2,065 deletions.
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
format_docstrings = true
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "KitBase"
uuid = "86eed249-3a28-466f-8d3a-596821e1af9a"
authors = ["Tianbai Xiao <[email protected]>"]
version = "0.9.1"
version = "0.9.2"

[deps]
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
Expand Down
1 change: 1 addition & 0 deletions src/Data/data_alias.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const AV = AbstractVector
const AM = AbstractMatrix
const AA = AbstractArray
const AVOM = AbstractVecOrMat
const IN = Integer
const RN = Real
const FN = AbstractFloat
206 changes: 59 additions & 147 deletions src/Flux/flux_boundary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,14 @@ Maxwell's diffusive boundary flux
1D continuum
# Arguments
* ``fw``: fluxes for conservative variables
* ``bc``: boundary condition for primitive variables
* ``w``: conservative variables
* ``inK``: internal degrees of freedom
* ``dt``: time step
* ``rot``: rotation indicator (1/-1)
"""
function flux_boundary_maxwell!(
fw::AV,
bc::AV,
w::AV,
inK,
γ,
dt,
rot, # 1 / -1
)
function flux_boundary_maxwell!(fw, bc::AV, w, inK, γ, dt, rot)

@assert length(bc) == 3

Expand All @@ -45,45 +36,64 @@ end
"""
$(SIGNATURES)
1D2F1V
1D2F1V & 1F3V
"""
function flux_boundary_maxwell!(
fw::AV,
fh::T1,
fb::T1,
bc::AV,
h::T2,
b::T2,
u::T3,
ω::T3,
inK,
dt,
rot = 1,
) where {T1<:AV,T2<:AV,T3<:AV}
function flux_boundary_maxwell!(fw::AV, a1, a2, a3, a4, a5, a6, a7, a8, a9, rot)

@assert length(bc) == 3
if length(fw) == 3
fh, fb, bc, h, b, u, ω, inK, dt = a1, a2, a3, a4, a5, a6, a7, a8, a9

δ = heaviside.(u .* rot)
SF = sum.* u .* h .* (1.0 .- δ))
SG = (bc[end] / π)^0.5 * sum.* u .* exp.(-bc[end] .* (u .- bc[2]) .^ 2) .* δ)
prim = [-SF / SG; bc[2:end]]
δ = heaviside.(u .* rot)
SF = sum.* u .* h .* (1.0 .- δ))
SG = (bc[end] / π)^0.5 * sum.* u .* exp.(-bc[end] .* (u .- bc[2]) .^ 2) .* δ)
prim = [-SF / SG; bc[2:end]]

H = maxwellian(u, prim)
B = H .* inK ./ (2.0 * prim[end])
H = maxwellian(u, prim)
B = H .* inK ./ (2.0 * prim[end])

hWall = H .* δ .+ h .* (1.0 .- δ)
bWall = B .* δ .+ b .* (1.0 .- δ)
hWall = H .* δ .+ h .* (1.0 .- δ)
bWall = B .* δ .+ b .* (1.0 .- δ)

fw[1] = discrete_moments(hWall, u, ω, 1) * dt
fw[2] = discrete_moments(hWall, u, ω, 2) * dt
fw[3] =
(
0.5 * discrete_moments(hWall .* u .^ 2, u, ω, 1) +
0.5 * discrete_moments(bWall, u, ω, 1)
) * dt
fw[1] = discrete_moments(hWall, u, ω, 1) * dt
fw[2] = discrete_moments(hWall, u, ω, 2) * dt
fw[3] =
(
0.5 * discrete_moments(hWall .* u .^ 2, u, ω, 1) +
0.5 * discrete_moments(bWall, u, ω, 1)
) * dt

@. fh = u * hWall * dt
@. fb = u * bWall * dt
elseif length(fw) == 5
ff, bc, f, u, v, w, ω, dt, area = a1, a2, a3, a4, a5, a6, a7, a8, a9

δ = heaviside.(u .* rot)
SF = sum.* u .* f .* (1.0 .- δ))
SG =
(bc[end] / π)^1.5 * sum(
ω .* u .*
exp.(
-bc[end] .*
((u .- bc[2]) .^ 2 .+ (v .- bc[3]) .^ 2 .+ (w .- bc[4]) .^ 2),
) .* δ,
)
prim = [-SF / SG; bc[2:end]]

M = maxwellian(u, v, w, prim)
fWall = M .* δ .+ f .* (1.0 .- δ)

fw[1] = discrete_moments(fWall, u, ω, 1) * area * dt
fw[2] = discrete_moments(fWall, u, ω, 2) * area * dt
fw[3] = discrete_moments(fWall .* u, v, ω, 1) * area * dt
fw[4] = discrete_moments(fWall .* u, w, ω, 1) * area * dt
fw[5] =
(0.5 * discrete_moments(fWall .* (u .^ 2 .+ v .^ 2 + w .^ 2), u, ω, 1)) *
area *
dt

@. ff = u * fWall * area * dt
end

@. fh = u * hWall * dt
@. fb = u * bWall * dt

return nothing

Expand All @@ -92,21 +102,9 @@ end
"""
$(SIGNATURES)
Mixture
1D2F1V mixture
"""
function flux_boundary_maxwell!(
fw::AM,
fh::T1,
fb::T1,
bc::AM,
h::T2,
b::T2,
u::T3,
ω::T3,
inK,
dt,
rot = 1,
) where {T1<:AM,T2<:AM,T3<:AM}
function flux_boundary_maxwell!(fw::AM, fh, fb, bc, h, b, u, ω, inK, dt, rot)

@assert size(bc, 1) == 3

Expand Down Expand Up @@ -152,7 +150,7 @@ $(SIGNATURES)
2D Continuum
"""
function flux_boundary_maxwell!(fw::AV, bc::AV, w::AV, inK, γ, dt, len, rot)
function flux_boundary_maxwell!(fw, bc::AV, w, inK, γ, dt, len, rot)

@assert length(bc) == 4

Expand All @@ -177,18 +175,7 @@ $(SIGNATURES)
2D1F2V
"""
function flux_boundary_maxwell!(
fw::AV,
fh::AM,
bc::AV,
h::AM,
u::T,
v::T,
ω::T,
dt,
len,
rot = 1,
) where {T<:AM}
function flux_boundary_maxwell!(fw, fh, bc::AV, h, u, v, ω, dt, len, rot)

@assert length(bc) == 4

Expand Down Expand Up @@ -220,21 +207,7 @@ $(SIGNATURES)
2D2F2V
"""
function flux_boundary_maxwell!(
fw::AV,
fh::T2,
fb::T2,
bc::AV,
h::T4,
b::T4,
u::T5,
v::T5,
ω::T5,
inK,
dt,
len,
rot = 1,
) where {T2<:AM,T4<:AM,T5<:AM}
function flux_boundary_maxwell!(fw, fh, fb, bc::AV, h, b, u, v, ω, inK, dt, len, rot)

@assert length(bc) == 4

Expand Down Expand Up @@ -270,54 +243,6 @@ function flux_boundary_maxwell!(

end

"""
$(SIGNATURES)
1F3V
"""
function flux_boundary_maxwell!(
fw::AV,
ff::AA{T1,3},
bc::AV,
f::AA{T2,3},
u::T3,
v::T3,
w::T3,
ω::T3,
dt,
area,
rot = 1,
) where {T1,T2,T3<:AA{T4,3} where {T4}}

@assert length(bc) == 5

δ = heaviside.(u .* rot)
SF = sum.* u .* f .* (1.0 .- δ))
SG =
(bc[end] / π)^1.5 * sum(
ω .* u .*
exp.(
-bc[end] .* ((u .- bc[2]) .^ 2 .+ (v .- bc[3]) .^ 2 .+ (w .- bc[4]) .^ 2),
) .* δ,
)
prim = [-SF / SG; bc[2:end]]

M = maxwellian(u, v, w, prim)
fWall = M .* δ .+ f .* (1.0 .- δ)

fw[1] = discrete_moments(fWall, u, ω, 1) * area * dt
fw[2] = discrete_moments(fWall, u, ω, 2) * area * dt
fw[3] = discrete_moments(fWall .* u, v, ω, 1) * area * dt
fw[4] = discrete_moments(fWall .* u, w, ω, 1) * area * dt
fw[5] =
(0.5 * discrete_moments(fWall .* (u .^ 2 .+ v .^ 2 + w .^ 2), u, ω, 1)) * area * dt

@. ff = u * fWall * area * dt

return nothing

end


"""
$(SIGNATURES)
Expand All @@ -326,8 +251,7 @@ Specular reflection boundary flux
1D1F1V
"""
function flux_boundary_specular!(fw::AV, ff::AV, f::AV, u::T, ω::T, dt) where {T<:AV}

function flux_boundary_specular!(fw, ff, f, u, ω, dt) where {T<:AV}
fWall = similar(f)
for i in eachindex(f)
fWall[i] = f[end-i+1]
Expand All @@ -340,25 +264,14 @@ function flux_boundary_specular!(fw::AV, ff::AV, f::AV, u::T, ω::T, dt) where {
@. ff = u * fWall * dt

return nothing

end

"""
$(SIGNATURES)
1D2F1V
"""
function flux_boundary_specular!(
fw::AV,
fh::T2,
fb::T2,
h::T3,
b::T3,
u::T4,
ω::T4,
dt,
) where {T2<:AV,T3<:AV,T4<:AV}

function flux_boundary_specular!(fw, fh, fb, h, b, u, ω, dt)
hWall = similar(h)
bWall = similar(b)
for i in eachindex(h)
Expand All @@ -378,5 +291,4 @@ function flux_boundary_specular!(
@. fb = u * bWall * dt

return nothing

end
20 changes: 10 additions & 10 deletions src/Flux/flux_kcu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ function flux_kcu!(
) where {T<:ControlVolume1F}

dxL, dxR, len, n, dirc = p
swL = @view ctrL.sw[:, dirc]
swR = @view ctrR.sw[:, dirc]
sfL = @view ctrL.sf[:, :, dirc]
sfR = @view ctrR.sf[:, :, dirc]
swL = extract_last(ctrL.sw, dirc; mode = :view)
swR = extract_last(ctrR.sw, dirc; mode = :view)
sfL = extract_last(ctrL.sf, dirc; mode = :view)
sfR = extract_last(ctrR.sf, dirc; mode = :view)

flux_kcu!(
face.fw,
Expand Down Expand Up @@ -163,12 +163,12 @@ function flux_kcu!(
) where {T<:ControlVolume2F}

dxL, dxR, len, n, dirc = p
swL = @view ctrL.sw[:, dirc]
swR = @view ctrR.sw[:, dirc]
shL = @view ctrL.sh[:, :, dirc]
sbL = @view ctrL.sb[:, :, dirc]
shR = @view ctrR.sh[:, :, dirc]
sbR = @view ctrR.sb[:, :, dirc]
swL = extract_last(ctrL.sw, dirc; mode = :view)
swR = extract_last(ctrR.sw, dirc; mode = :view)
shL = extract_last(ctrL.sh, dirc; mode = :view)
sbL = extract_last(ctrL.sb, dirc; mode = :view)
shR = extract_last(ctrR.sh, dirc; mode = :view)
sbR = extract_last(ctrR.sb, dirc; mode = :view)

flux_kcu!(
face.fw,
Expand Down
16 changes: 8 additions & 8 deletions src/Flux/flux_kfvs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ function flux_kfvs!(
) where {T<:ControlVolume1F}

dxL, dxR, len, n, dirc = p[1:5]
sfL = @view ctrL.sf[:, :, dirc]
sfR = @view ctrR.sf[:, :, dirc]
sfL = extract_last(ctrL.sf, dirc; mode = :view)
sfR = extract_last(ctrR.sf, dirc; mode = :view)

flux_kfvs!(
face.fw,
Expand Down Expand Up @@ -112,10 +112,10 @@ function flux_kfvs!(
) where {T<:ControlVolume2F}

dxL, dxR, len, n, dirc = p[1:5]
shL = @view ctrL.sh[:, :, dirc]
sbL = @view ctrL.sb[:, :, dirc]
shR = @view ctrR.sh[:, :, dirc]
sbR = @view ctrR.sb[:, :, dirc]
shL = extract_last(ctrL.sh, dirc; mode = :view)
sbL = extract_last(ctrL.sb, dirc; mode = :view)
shR = extract_last(ctrR.sh, dirc; mode = :view)
sbR = extract_last(ctrR.sb, dirc; mode = :view)

flux_kfvs!(
face.fw,
Expand Down Expand Up @@ -171,8 +171,8 @@ function flux_kfvs!(
)
else
len, n, dirc = p[3:5]
sfL = @view ctrL.sf[:, :, :, dirc]
sfR = @view ctrR.sf[:, :, :, dirc]
sfL = extract_last(ctrL.sf, dirc; mode = :view)
sfR = extract_last(ctrR.sf, dirc; mode = :view)

flux_kfvs!(
face.fw,
Expand Down
2 changes: 1 addition & 1 deletion src/IO/io_write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function write_tec(x::AV, sol)
end
varnm = varnm * "V" * string(len)

println(f, "VARIABLES = X, Y, " * varnm)
println(f, "VARIABLES = X, " * varnm)
println(f, "ZONE I = $nx")

dp = "DATAPACKING = BLOCK"
Expand Down
Loading

2 comments on commit ab8c1bb

@vavrines
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/65422

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.9.2 -m "<description of version>" ab8c1bbe150acf8466f73ea03bc7e3626213e6d4
git push origin v0.9.2

Please sign in to comment.