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
)
source

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.

source

KitAMR.ps_refine!Function
ps_refine!(
    p4est::Ptr{KitAMR.P4est.LibP4est.p4est},
    ka::KA;
    recursive
)
source
ps_refine!(
    p4est::Ptr{KitAMR.P4est.LibP4est.p8est},
    ka::KA;
    recursive
)
source

Refine cells satisfying criteria in physical space.


KitAMR.ps_coarsen!Function
ps_coarsen!(
    p4est::Ptr{KitAMR.P4est.LibP4est.p4est};
    recursive
)
source
ps_coarsen!(
    p4est::Ptr{KitAMR.P4est.LibP4est.p8est};
    recursive
)
source

Coarsen cells satisfying criteria in physical space.


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.

source
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.

source

AMR criteria in physical space are defined by

KitAMR.ps_refine_flagMethod
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
source

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.

source

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

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

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_flagFunction
contribution_refine_flag(
    w::AbstractVector,
    U::AbstractVector,
    midpoint::AbstractVector,
    df::AbstractVector,
    weight::Float64,
    vr::KitAMR.Velocity_Resolution,
    kinfo::KInfo
) -> Any
source
KitAMR.contribution_coarsen_flagFunction
contribution_coarsen_flag(
    w::AbstractVector,
    U::AbstractVector,
    midpoint::AbstractMatrix,
    df::AbstractMatrix,
    weight::AbstractVector,
    vr::KitAMR.Velocity_Resolution,
    kinfo::KInfo
) -> Bool
source

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.

source

Currently, the recovery function is yet to be optimized for higher efficiency. However, the overhead is negligible.