Adaptive mesh refinement
AMR is the core functionality of KitAMR.jl. An integrated interface is provided
KitAMR.adaptive_mesh_refinement! — Function
adaptive_mesh_refinement!(
p4est::Union{Ptr{KitAMR.P4est.LibP4est.p4est}, Ptr{KitAMR.P4est.LibP4est.p8est}},
ka::KA;
ps_interval,
vs_interval,
partition_interval
)
Physical space
In physical space, a forest of quadtrees (for 2D) or octrees (for 3D) is constructed and managed with p4est.
KitAMR.ps_adaptive_mesh_refinement! — Function
ps_adaptive_mesh_refinement!(
p4est::Union{Ptr{KitAMR.P4est.LibP4est.p4est}, Ptr{KitAMR.P4est.LibP4est.p8est}},
ka::KA
)
Outer function of AMR in physical space.
KitAMR.ps_refine! — Function
ps_refine!(
p4est::Ptr{KitAMR.P4est.LibP4est.p4est},
ka::KA;
recursive
)
ps_refine!(
p4est::Ptr{KitAMR.P4est.LibP4est.p8est},
ka::KA;
recursive
)
Refine cells satisfying criteria in physical space.
KitAMR.ps_coarsen! — Function
ps_coarsen!(
p4est::Ptr{KitAMR.P4est.LibP4est.p4est};
recursive
)
ps_coarsen!(
p4est::Ptr{KitAMR.P4est.LibP4est.p8est};
recursive
)
Coarsen cells satisfying criteria in physical space.
KitAMR.ps_balance! — Function
ps_balance!(p4est::Ptr{KitAMR.P4est.LibP4est.p4est})
Balance mesh in physical space after refinement and coarsening. It ensures that the difference between the refinement levels of neighboring cells is not larger than 1.
In an AMR process, it is crucial to construct variables in newly generated cell (a larger one or a smaller one). Related methods are
KitAMR.ps_replace! — Method
ps_replace!(
_::Val{1},
out_quad,
in_quads,
which_tree,
ka::KA{DIM}
)
Replacement function in a refinement process.
KitAMR.ps_replace! — Method
ps_replace!(
_::Union{Val{4}, Val{8}},
out_quad,
in_quads,
which_tree,
ka::KA{DIM, NDF}
)
Replacement function in a coarsening process.
AMR criteria in physical space are defined by
KitAMR.ps_refine_flag — Method
ps_refine_flag(
ps_data::PsData{DIM},
ka::KA{DIM},
qp::Union{KitAMR.P4est.PointerWrappers.PointerWrapper{KitAMR.P4est.LibP4est.p4est_quadrant}, KitAMR.P4est.PointerWrappers.PointerWrapper{KitAMR.P4est.LibP4est.p8est_quadrant}}
) -> Int32
KitAMR.ps_coarsen_flag — Method
ps_coarsen_flag(
ps_datas::Vector{PsData},
levels::Vector{Int64},
ka::KA{DIM, NDF}
) -> Int32
Currently, KitAMR.jl decides according to the relative macroscopic gradient. To compute this, a globally maximum gradient is obtained by
KitAMR.update_gradmax! — Function
update_gradmax!(ka::KA{DIM})
Update the globally maximum gradients of conserved variables as a referrence of the AMR in physical space.
Velocity space
In velocity space, considering the enormous number of the phase grids, constructing a forest in velocity space for every physical cell is impossible. Hence, the AMR in velocity space is more elaborately designed.
Related functions are
KitAMR.vs_adaptive_mesh_refinement! — Function
vs_adaptive_mesh_refinement!(ka)
KitAMR.vs_refine! — Function
vs_refine!(
va_data::KitAMR.Velocity_Adaptive_Data,
ka::KA{DIM, NDF}
)
KitAMR.vs_coarsen! — Function
vs_coarsen!(
va_data::KitAMR.Velocity_Adaptive_Data,
ka::KA{DIM, NDF}
)
The replacement functions are more particular and are planted inside the adaptation functions.
Compared with the AMR in physical space, the conservation is not automatically maintained in velocity space. Hence, a correction is required
KitAMR.vs_conserved_correction! — Function
vs_conserved_correction!(
va_data::KitAMR.Velocity_Adaptive_Data,
ka
)
The refinement and coarsening in velocity space are decided according to the relative contribution of the velocity cell to the macroscopic quantities. Currently, mass and energy are considered.
KitAMR.contribution_refine_flag — Function
contribution_refine_flag(
w::AbstractVector,
U::AbstractVector,
midpoint::AbstractVector,
df::AbstractVector,
weight::Float64,
vr::KitAMR.Velocity_Resolution,
kinfo::KInfo
) -> Any
KitAMR.contribution_coarsen_flag — Function
contribution_coarsen_flag(
w::AbstractVector,
U::AbstractVector,
midpoint::AbstractMatrix,
df::AbstractMatrix,
weight::AbstractVector,
vr::KitAMR.Velocity_Resolution,
kinfo::KInfo
) -> Bool
The contribution is measured from two points of view. The global one is related to the globally maximum resolution of a velocity cell. The local one tells the proportion in the conserved variables in the local physical cell.
Recovery
After an AMR process, the mesh has been changed a lot. The ghost layers, neighbor relations, immersed boundaries, and faces are required to be reconstructed.
KitAMR.amr_recover! — Function
amr_recover!(
p4est::Union{Ptr{KitAMR.P4est.LibP4est.p4est}, Ptr{KitAMR.P4est.LibP4est.p8est}},
ka::KA
)
Recover the ghost layers, neighbor relations, immersed boundaries, and faces after an AMR or partition process.
Currently, the recovery function is yet to be optimized for higher efficiency. However, the overhead is negligible.