From 3318750c571bcc449b671ca245c588b22e396f19 Mon Sep 17 00:00:00 2001 From: vavrines Date: Mon, 23 Mar 2026 02:33:54 +0000 Subject: [PATCH] Format .jl files --- deprecated/flux.jl | 9 +- deprecated/flux_UGKS.jl | 172 +- deprecated/flux_copy.jl | 50 +- deprecated/gaussian_weight.jl | 38 +- deprecated/maxwellian.jl | 457 +- deprecated/postprocess.jl | 294 +- deprecated/solid_cells.jl | 10 +- deprecated/test.jl | 20 +- deprecated/test_RayCasting.jl | 14 +- deprecated/test_corner.jl | 18 +- deprecated/test_effi.jl | 20 +- deprecated/test_pvtu.jl | 56 +- deprecated/test_typevar.jl | 6 +- deprecated/test_vo_fn.jl | 36 +- deprecated/test_vtk.jl | 16 +- deprecated/test_vtu.jl | 9 +- deprecated/test_write_vtk.jl | 76 +- deprecated/test_write_vtk_redundant.jl | 28 +- deprecated/types.jl | 60 +- docs/make.jl | 14 +- example/X38/X38_julia.jl | 72 +- example/X38/X38_text.jl | 29 +- example/X38/X38_udf.jl | 14 +- example/X38/model_transform.jl | 16 +- example/airfoil/airfoil.jl | 72 +- example/airfoil/airfoil_udf.jl | 4 +- example/cylinder/cylinder.jl | 64 +- example/cylinder/cylinder_udf.jl | 37 +- example/profile/strong_scaling.jl | 57 +- example/profile/weak_scaling_n32.jl | 17 +- example/r2v.jl | 30 +- example/sphere/sphere.jl | 69 +- example/sphere/sphere_udf.jl | 42 +- lib/KitCore/2D.jl | 12 +- lib/KitCore/2D2F.jl | 129 +- lib/KitCore/3D.jl | 9 +- lib/KitCore/3D1F.jl | 50 +- lib/KitCore/KitCore.jl | 36 +- lib/P4est/src/LibP4est.jl | 7900 ++++++++++++++++++------ lib/P4est/src/P4est.jl | 10 +- lib/P4est/src/pointerwrappers.jl | 17 +- lib/P4estTypes/src/connectivity.jl | 98 +- lib/P4estTypes/src/ghost.jl | 4 +- lib/P4estTypes/src/lnodes.jl | 4 +- lib/P4estTypes/src/pxest.jl | 26 +- src/Abstract/Types.jl | 111 +- src/Boundary/Boundary.jl | 8 +- src/Boundary/Circle.jl | 143 +- src/Boundary/Immersed_boundary.jl | 815 ++- src/Boundary/Period.jl | 34 +- src/Boundary/Triangles.jl | 381 +- src/Boundary/Types.jl | 154 +- src/Boundary/Vertices.jl | 111 +- src/Flux/CAIDVM.jl | 274 +- src/Flux/DVM.jl | 205 +- src/Flux/Flux.jl | 364 +- src/Flux/Slope.jl | 77 +- src/Flux/UGKS.jl | 325 +- src/Gas/Gas.jl | 2 +- src/Gas/Model.jl | 7 +- src/Gas/Types.jl | 26 +- src/IO/Check.jl | 196 +- src/IO/IO.jl | 4 +- src/IO/Input.jl | 4 +- src/IO/Output.jl | 1075 ++-- src/IO/Restart.jl | 114 +- src/IO/Types.jl | 61 +- src/KitAMR.jl | 4 +- src/Mesh/Connectivity.jl | 83 +- src/Mesh/Mesh.jl | 2 +- src/Mesh/Neighbor.jl | 50 +- src/P4est/P4est.jl | 2 +- src/P4est/P4est_wrap.jl | 151 +- src/Parallel/Ghost.jl | 232 +- src/Parallel/Parallel.jl | 2 +- src/Parallel/Partition.jl | 258 +- src/Physical_space/AMR.jl | 375 +- src/Physical_space/Criteria.jl | 59 +- src/Physical_space/Physical_space.jl | 20 +- src/Physical_space/Types.jl | 67 +- src/Solver/AMR.jl | 35 +- src/Solver/Auxiliary.jl | 12 +- src/Solver/Finalize.jl | 17 +- src/Solver/Initialize.jl | 412 +- src/Solver/Solver.jl | 8 +- src/Solver/Types.jl | 293 +- src/Theory/Iterate.jl | 41 +- src/Theory/Math.jl | 246 +- src/Theory/Theory.jl | 2 +- src/Velocity_space/AMR.jl | 356 +- src/Velocity_space/Criteria.jl | 252 +- src/Velocity_space/Cut_cell.jl | 242 +- src/Velocity_space/Initialize.jl | 42 +- src/Velocity_space/Types.jl | 84 +- src/Velocity_space/Velocity_space.jl | 7 +- test/runtests.jl | 50 +- test/test_cut_cube.jl | 206 +- test/test_flux.jl | 32 +- test/test_meshio.jl | 337 +- test/test_mpi.jl | 24 +- test/test_mpi_bool.jl | 23 +- test/test_pvtu.jl | 59 +- test/test_reduce.jl | 34 +- test/test_surface_plot.jl | 38 +- 104 files changed, 12946 insertions(+), 5923 deletions(-) diff --git a/deprecated/flux.jl b/deprecated/flux.jl index 3c67ad8..336421e 100644 --- a/deprecated/flux.jl +++ b/deprecated/flux.jl @@ -27,7 +27,12 @@ function calc_flux!(::Val{1}, ::Val{0}, face::Face, AMR_2D::KitAMR_Data_2D, face # end @. vs_data.flux[:, 2] += vn * rot * ps_data.ds[dir] * gas.Δt * B end -function make_face_data(ps_data::PS_Data_2D, nps_data::AbstractPsData, rot::Float64, dir::Int) +function make_face_data( + ps_data::PS_Data_2D, + nps_data::AbstractPsData, + rot::Float64, + dir::Int, +) vs_data = ps_data.vs_data midpoint_L = vs_data.midpoint vs_data_n = nps_data.vs_data @@ -328,7 +333,7 @@ function calc_flux!(::Val{0}, ::Val{2}, face::Face, AMR_2D::KitAMR_Data_2D, face # @show ps_data.neighbor.data[faceid][2].midpoint # end fw_test = zeros(DIM + 2) - for i = 1:2^(DIM-1) + for i = 1:(2^(DIM-1)) nps_data = ps_data.neighbor.data[faceid][i] vs_data_n = nps_data.vs_data ds = nps_data.ds[dir] diff --git a/deprecated/flux_UGKS.jl b/deprecated/flux_UGKS.jl index 3be0eb7..8297d6a 100644 --- a/deprecated/flux_UGKS.jl +++ b/deprecated/flux_UGKS.jl @@ -4,7 +4,12 @@ end function face_area(ps_data::AbstractPsData{3}, DIR::Integer) return reduce(*, @view(ps_data.ds[FAT[2][DIR]])) end -function calc_flux!(domain::Domain{Maxwellian},ps_data::PS_Data{2,2},faceid::Integer,amr::KitAMR_Data{2,2}) +function calc_flux!( + domain::Domain{Maxwellian}, + ps_data::PS_Data{2,2}, + faceid::Integer, + amr::KitAMR_Data{2,2}, +) global_data = amr.global_data DIR = get_dir(faceid) ROT = get_rot(faceid) @@ -24,45 +29,64 @@ function calc_flux!(domain::Domain{Maxwellian},ps_data::PS_Data{2,2},faceid::Int @. vs_data.flux[:, 1] += vn * ROT * dsf * Δt * @view(F[:, 1]) @. vs_data.flux[:, 2] += vn * ROT * dsf * Δt * @view(F[:, 2]) end -function make_face_data(ps_data::PS_Data{DIM,NDF},domain::Domain{Inflow},global_data::Global_Data,ROT,DIR)where{DIM,NDF} +function make_face_data( + ps_data::PS_Data{DIM,NDF}, + domain::Domain{Inflow}, + global_data::Global_Data, + ROT, + DIR, +) where {DIM,NDF} vs_data = ps_data.vs_data - vn = @view(vs_data.midpoint[:,DIR]) - df_n = Matrix{Float64}(undef,vs_data.vs_num,NDF) - sdf_n = Matrix{Float64}(undef,vs_data.vs_num,NDF) + vn = @view(vs_data.midpoint[:, DIR]) + df_n = Matrix{Float64}(undef, vs_data.vs_num, NDF) + sdf_n = Matrix{Float64}(undef, vs_data.vs_num, NDF) bc = domain.bc - bit_L = [x<=0. for x in ROT.*vn] + bit_L = [x<=0.0 for x in ROT .* vn] offset = 0 - for i in axes(df_n,1) + for i in axes(df_n, 1) @inbounds if bit_L[i] - @inbounds df_n[i,:] .= @view(vs_data.df[i,:]) - @inbounds sdf_n[i,:] .= @view(vs_data.sdf[i,:,DIR]) + @inbounds df_n[i, :] .= @view(vs_data.df[i, :]) + @inbounds sdf_n[i, :] .= @view(vs_data.sdf[i, :, DIR]) offset+=1 else - @inbounds df_n[i,:].= discrete_maxwell(@view(vs_data.midpoint[i,:]),bc,global_data) - @inbounds sdf_n[i,:] .= 0. + @inbounds df_n[i, :] .= + discrete_maxwell(@view(vs_data.midpoint[i, :]), bc, global_data) + @inbounds sdf_n[i, :] .= 0.0 end end - return Face_VS_Data{DIM,NDF}(vs_data.weight,vs_data.midpoint,vn,df_n,sdf_n),offset + return Face_VS_Data{DIM,NDF}(vs_data.weight, vs_data.midpoint, vn, df_n, sdf_n), offset end -function make_face_data(ps_data::PS_Data{DIM,NDF},::Domain{Outflow},::Global_Data,ROT,DIR)where{DIM,NDF} +function make_face_data( + ps_data::PS_Data{DIM,NDF}, + ::Domain{Outflow}, + ::Global_Data, + ROT, + DIR, +) where {DIM,NDF} vs_data = ps_data.vs_data - vn = @view(vs_data.midpoint[:,DIR]) - sdf_n = zeros(vs_data.vs_num,NDF) - return Face_VS_Data{DIM,NDF}(vs_data.weight,vs_data.midpoint,vn,vs_data.df,sdf_n),vs_data.vs_num + vn = @view(vs_data.midpoint[:, DIR]) + sdf_n = zeros(vs_data.vs_num, NDF) + return Face_VS_Data{DIM,NDF}(vs_data.weight, vs_data.midpoint, vn, vs_data.df, sdf_n), + vs_data.vs_num end -function calc_flux!(domain::Domain{Inflow},ps_data::PS_Data{2,2},faceid,amr::KitAMR_Data{2,2}) +function calc_flux!( + domain::Domain{Inflow}, + ps_data::PS_Data{2,2}, + faceid, + amr::KitAMR_Data{2,2}, +) DIR = get_dir(faceid) ROT = get_rot(faceid) # Left: -1, Right: 1 global_data = amr.global_data gas = global_data.config.gas ds = ps_data.ds[DIR] vs_data = ps_data.vs_data - f_vs_data,offset = make_face_data(ps_data,domain,global_data,ROT,DIR) + f_vs_data, offset = make_face_data(ps_data, domain, global_data, ROT, DIR) w0 = calc_w0(f_vs_data) # nps_data.bound_enc < 0 && (@show vs_data.sdf[:,2,DIR] vs_data_n.sdf[:,2,DIR] vs_data_n.weight) prim0 = get_prim(w0, global_data) qf0 = calc_qf(f_vs_data, prim0) - domain_w = get_conserved(domain.bc,global_data) + domain_w = get_conserved(domain.bc, global_data) aL, aR = calc_a(w0, prim0, ps_data.w, domain_w, ds, ds, global_data, ROT) Mu, Mv, Mξ, Mu_L, Mu_R = moment_u(prim0, global_data, ROT, DIR) A = calc_A(prim0, aL, aR, Mu, Mv, Mξ, Mu_L, Mu_R, global_data, DIR) @@ -76,16 +100,21 @@ function calc_flux!(domain::Domain{Inflow},ps_data::PS_Data{2,2},faceid,amr::Kit fw .*= dsf * ROT ps_data.flux .+= fw micro_flux = calc_micro_flux(f_vs_data, F, F⁺, aL, aR, A, Mξ, Mt, offset, dsf) - vs_data.flux += ROT.*micro_flux + vs_data.flux += ROT .* micro_flux end -function calc_flux!(domain::Domain{Outflow},ps_data::PS_Data{2,2},faceid,amr::KitAMR_Data{2,2}) +function calc_flux!( + domain::Domain{Outflow}, + ps_data::PS_Data{2,2}, + faceid, + amr::KitAMR_Data{2,2}, +) DIR = get_dir(faceid) ROT = get_rot(faceid) # Left: -1, Right: 1 global_data = amr.global_data gas = global_data.config.gas ds = ps_data.ds[DIR] vs_data = ps_data.vs_data - f_vs_data,offset = make_face_data(ps_data,domain,global_data,ROT,DIR) + f_vs_data, offset = make_face_data(ps_data, domain, global_data, ROT, DIR) w0 = calc_w0(f_vs_data) # nps_data.bound_enc < 0 && (@show vs_data.sdf[:,2,DIR] vs_data_n.sdf[:,2,DIR] vs_data_n.weight) prim0 = get_prim(w0, global_data) @@ -103,13 +132,13 @@ function calc_flux!(domain::Domain{Outflow},ps_data::PS_Data{2,2},faceid,amr::Ki fw .*= dsf * ROT ps_data.flux .+= fw micro_flux = calc_micro_flux(f_vs_data, F, F⁺, aL, aR, A, Mξ, Mt, offset, dsf) - vs_data.flux += ROT.*micro_flux + vs_data.flux += ROT .* micro_flux end -function calc_flux!(::BoundaryNeighbor,face::Face{BoundaryFace},amr::KitAMR_Data{2,2}) +function calc_flux!(::BoundaryNeighbor, face::Face{BoundaryFace}, amr::KitAMR_Data{2,2}) ps_data = face.data faceid = face.faceid domain = amr.global_data.config.domain[faceid] - calc_flux!(domain,ps_data,faceid,amr) + calc_flux!(domain, ps_data, faceid, amr) end function calc_flux!(::BoundaryNeighbor, face::Face{BoundaryFace}, amr::KitAMR_Data{3,1}) ps_data = face.data @@ -334,14 +363,15 @@ function make_face_data( faceid::Int, ROT::Float64, DIR::Int, -)where{NDF} +) where {NDF} vs_data = ps_data.vs_data midpoint_L = vs_data.midpoint vs_data_n = nps_data.vs_data midpoint_R = vs_data_n.midpoint bit_L = [x <= 0.0 for x in ROT .* @view(midpoint_L[:, DIR])] bit_R = [x > 0.0 for x in ROT .* @view(midpoint_R[:, DIR])] - midpoint_n = vcat(@view(midpoint_L[bit_L, :]), @view(midpoint_R[bit_R, :])); vn = @view(midpoint_n[:,DIR]) + midpoint_n = vcat(@view(midpoint_L[bit_L, :]), @view(midpoint_R[bit_R, :])); + vn = @view(midpoint_n[:, DIR]) if ps_data.neighbor.state[faceid] == 1 df_L = @view(vs_data.df[bit_L, :]) df_R = @view(vs_data_n.df[bit_R, :]) @@ -465,13 +495,13 @@ function update_face_data_L!( bit_L = [x <= 0.0 for x in ROT .* @view(midpoint_L[:, DIR])] df_L = @view(vs_data.df[bit_L, :]) f_vs_data.midpoint = - vcat(@view(midpoint_L[bit_L, :]), @view(f_vs_data.midpoint[offset+1:end, :])) + vcat(@view(midpoint_L[bit_L, :]), @view(f_vs_data.midpoint[(offset+1):end, :])) f_vs_data.vn = @view(f_vs_data.midpoint[:, DIR]) - f_vs_data.df = vcat(df_L, @view(f_vs_data.df[offset+1:end, :])) + f_vs_data.df = vcat(df_L, @view(f_vs_data.df[(offset+1):end, :])) f_vs_data.sdf = - vcat(@view(vs_data.sdf[bit_L, :, DIR]), @view(f_vs_data.sdf[offset+1:end, :])) + vcat(@view(vs_data.sdf[bit_L, :, DIR]), @view(f_vs_data.sdf[(offset+1):end, :])) f_vs_data.weight = - vcat(@view(vs_data.weight[bit_L]), @view(f_vs_data.weight[offset+1:end])) + vcat(@view(vs_data.weight[bit_L]), @view(f_vs_data.weight[(offset+1):end])) offset = length(df_L) return (bit_L, offset) end @@ -488,18 +518,18 @@ function calc_flux!(::SameSizeNeighbor, face::Face{InnerFace}, amr::KitAMR_Data{ nps_data = ps_data.neighbor.data[faceid][1] vs_data_n = nps_data.vs_data nps_data.bound_enc < 0 && project_solid_cell_slope!(vs_data_n, vs_data, DIR) - #= - if MPI.Comm_rank(MPI.COMM_WORLD)==5&&nps_data.bound_enc<0&&isa(nps_data,Ghost_PS_Data) - @show vs_data.vs_num vs_data_n.vs_num - end - =# - if vs_data.vs_num!=vs_data_n.vs_num - @show typeof(vs_data_n) vs_data_n.vs_num vs_data.vs_num - end + #= + if MPI.Comm_rank(MPI.COMM_WORLD)==5&&nps_data.bound_enc<0&&isa(nps_data,Ghost_PS_Data) + @show vs_data.vs_num vs_data_n.vs_num + end + =# + if vs_data.vs_num!=vs_data_n.vs_num + @show typeof(vs_data_n) vs_data_n.vs_num vs_data.vs_num + end f_vs_data, offset, bit_L, _ = make_face_data(ps_data, nps_data, faceid, ROT, DIR) reconstruct_vs!(f_vs_data, ds, ds, offset, ROT) w0 = calc_w0(f_vs_data) - any(x->isnan(x),w0)&&(@show nps_data.bound_enc nps_data.ds f_vs_data.sdf) + any(x->isnan(x), w0)&&(@show nps_data.bound_enc nps_data.ds f_vs_data.sdf) # nps_data.bound_enc < 0 && (@show vs_data.sdf[:,2,DIR] vs_data_n.sdf[:,2,DIR] vs_data_n.weight) prim0 = get_prim(w0, global_data) qf0 = calc_qf(f_vs_data, prim0) @@ -570,7 +600,9 @@ function calc_flux!(::HalfSizeNeighbor, face::Face, amr::KitAMR_Data{2,2}) gas = global_data.config.gas ds = ps_data.ds[DIR] vs_data = ps_data.vs_data - f_vs_data = nothing; offset = 0; bit_L = nothing + f_vs_data = nothing; + offset = 0; + bit_L = nothing for i = 1:2 nps_data = ps_data.neighbor.data[faceid][i] vs_data_n = nps_data.vs_data @@ -585,7 +617,9 @@ function calc_flux!(::HalfSizeNeighbor, face::Face, amr::KitAMR_Data{2,2}) w0 = calc_w0(f_vs_data) prim0 = get_prim(w0, global_data) qf0 = calc_qf(f_vs_data, prim0) - wL = @. ps_data.w+(nps_data.midpoint[FAT[1][DIR]]-ps_data.midpoint[FAT[1][DIR]])*ps_data.sw[:,FAT[1][DIR]] + wL = @. ps_data.w+( + nps_data.midpoint[FAT[1][DIR]]-ps_data.midpoint[FAT[1][DIR]] + )*ps_data.sw[:, FAT[1][DIR]] aL, aR = calc_a(w0, prim0, wL, nps_data.w, ds, 0.5 * ds, global_data, ROT) Mu, Mv, Mξ, Mu_L, Mu_R = moment_u(prim0, global_data, ROT, DIR) A = calc_A(prim0, aL, aR, Mu, Mv, Mξ, Mu_L, Mu_R, global_data, DIR) @@ -616,7 +650,9 @@ function calc_flux!(::HalfSizeNeighbor, face::Face, amr::KitAMR_Data{3,1}) gas = global_data.config.gas ds = ps_data.ds[DIR] vs_data = ps_data.vs_data - f_vs_data = nothing; offset = 0; bit_L = nothing + f_vs_data = nothing; + offset = 0; + bit_L = nothing for i = 1:4 nps_data = ps_data.neighbor.data[faceid][i] vs_data_n = nps_data.vs_data @@ -631,9 +667,11 @@ function calc_flux!(::HalfSizeNeighbor, face::Face, amr::KitAMR_Data{3,1}) w0 = calc_w0(f_vs_data) prim0 = get_prim(w0, global_data) qf0 = calc_qf(f_vs_data, prim0) - wL = @. ps_data.w+(nps_data.midpoint[FAT[2][DIR][1]]-ps_data.midpoint[FAT[2][DIR][1]])* - ps_data.sw[:,FAT[2][DIR][1]]+(nps_data.midpoint[FAT[2][DIR][2]]- - ps_data.midpoint[FAT[2][DIR][2]])*ps_data.sw[:,FAT[2][DIR][2]] + wL = @. ps_data.w+( + nps_data.midpoint[FAT[2][DIR][1]]-ps_data.midpoint[FAT[2][DIR][1]] + ) * ps_data.sw[:, FAT[2][DIR][1]]+( + nps_data.midpoint[FAT[2][DIR][2]] - ps_data.midpoint[FAT[2][DIR][2]] + )*ps_data.sw[:, FAT[2][DIR][2]] aL, aR = calc_a(w0, prim0, wL, nps_data.w, ds, 0.5 * ds, global_data, ROT) Mu, Mv, Mw, Mu_L, Mu_R = moment_u(prim0, global_data, ROT, DIR) A = calc_A(prim0, aL, aR, Mu, Mv, Mw, Mu_L, Mu_R, global_data, DIR) @@ -671,11 +709,11 @@ function calc_flux!(::DoubleSizeNeighbor, face::Face, amr::KitAMR_Data{2,2}) w0 = calc_w0(f_vs_data) prim0 = get_prim(w0, global_data) qf0 = calc_qf(f_vs_data, prim0) - wR = @. nps_data.w+(ps_data.midpoint[FAT[1][DIR]]-nps_data.midpoint[FAT[1][DIR]])* - nps_data.sw[:,FAT[1][DIR]] - #if MPI.Comm_rank(MPI.COMM_WORLD)==4&&faceid==4 - #@show nps_data.sw nps_data.w w0 nps_data.prim - #end + wR = @. nps_data.w+(ps_data.midpoint[FAT[1][DIR]]-nps_data.midpoint[FAT[1][DIR]]) * + nps_data.sw[:, FAT[1][DIR]] + #if MPI.Comm_rank(MPI.COMM_WORLD)==4&&faceid==4 + #@show nps_data.sw nps_data.w w0 nps_data.prim + #end aL, aR = calc_a(w0, prim0, ps_data.w, wR, ds, 2.0 * ds, global_data, ROT) Mu, Mv, Mξ, Mu_L, Mu_R = moment_u(prim0, global_data, ROT, DIR) A = calc_A(prim0, aL, aR, Mu, Mv, Mξ, Mu_L, Mu_R, global_data, DIR) @@ -695,13 +733,15 @@ function calc_flux!(::DoubleSizeNeighbor, face::Face, amr::KitAMR_Data{2,2}) vs_data = ps_data.vs_data # bit_L, offset = update_face_data_L!(ps_data, nps_data, f_vs_data, offset, faceid, ROT, DIR) # reconstruct_vs_L!(f_vs_data, ds, offset, ROT) - if !isa(ps_data,Ghost_PS_Data) + if !isa(ps_data, Ghost_PS_Data) f_vs_data, offset, bit_L, _ = make_face_data(ps_data, nps_data, faceid, ROT, DIR) reconstruct_vs!(f_vs_data, ds, 2.0 * ds, offset, ROT) w0 = calc_w0(f_vs_data) prim0 = get_prim(w0, global_data) qf0 = calc_qf(f_vs_data, prim0) - wR = @. nps_data.w+(ps_data.midpoint[FAT[1][DIR]]-nps_data.midpoint[FAT[1][DIR]])*nps_data.sw[:,FAT[1][DIR]] + wR = @. nps_data.w+( + ps_data.midpoint[FAT[1][DIR]]-nps_data.midpoint[FAT[1][DIR]] + )*nps_data.sw[:, FAT[1][DIR]] aL, aR = calc_a(w0, prim0, ps_data.w, wR, ds, 2.0 * ds, global_data, ROT) Mu, Mv, Mξ, Mu_L, Mu_R = moment_u(prim0, global_data, ROT, DIR) A = calc_A(prim0, aL, aR, Mu, Mv, Mξ, Mu_L, Mu_R, global_data, DIR) @@ -733,9 +773,11 @@ function calc_flux!(::DoubleSizeNeighbor, face::Face, amr::KitAMR_Data{3,1}) w0 = calc_w0(f_vs_data) prim0 = get_prim(w0, global_data) qf0 = calc_qf(f_vs_data, prim0) - wR = @. nps_data.w+(ps_data.midpoint[FAT[2][DIR][1]]-nps_data.midpoint[FAT[2][DIR][1]])* - nps_data.sw[:,FAT[2][DIR][1]]+(ps_data.midpoint[FAT[2][DIR][2]]-nps_data.midpoint[FAT[2][DIR][2]])* - nps_data.sw[:,FAT[2][DIR][2]] + wR = + @. nps_data.w+(ps_data.midpoint[FAT[2][DIR][1]]-nps_data.midpoint[FAT[2][DIR][1]]) * + nps_data.sw[:, FAT[2][DIR][1]]+( + ps_data.midpoint[FAT[2][DIR][2]]-nps_data.midpoint[FAT[2][DIR][2]] + ) * nps_data.sw[:, FAT[2][DIR][2]] aL, aR = calc_a(w0, prim0, ps_data.w, wR, ds, 2.0 * ds, global_data, ROT) Mu, Mv, Mw, Mu_L, Mu_R = moment_u(prim0, global_data, ROT, DIR) A = calc_A(prim0, aL, aR, Mu, Mv, Mw, Mu_L, Mu_R, global_data, DIR) @@ -751,17 +793,25 @@ function calc_flux!(::DoubleSizeNeighbor, face::Face, amr::KitAMR_Data{3,1}) micro_flux = calc_micro_flux(f_vs_data, F, F⁺, aL, aR, A, Mt, offset, dsf) update_vs_flux!(micro_flux, bit_L, vs_data, vs_data_n, offset, ROT) for i in eachindex(face.hanging_data) - (isa(face.hanging_data[i], Ghost_PS_Data)||isa(face.hanging_data[i],MissingHangingQuad)) && continue + ( + isa( + face.hanging_data[i], + Ghost_PS_Data, + )||isa(face.hanging_data[i], MissingHangingQuad) + ) && continue ps_data = face.hanging_data[i] vs_data = ps_data.vs_data - bit_L, offset = update_face_data_L!(ps_data, nps_data, f_vs_data, offset, faceid, ROT, DIR) + bit_L, offset = + update_face_data_L!(ps_data, nps_data, f_vs_data, offset, faceid, ROT, DIR) reconstruct_vs_L!(f_vs_data, ds, offset, ROT) w0 = calc_w0(f_vs_data) prim0 = get_prim(w0, global_data) qf0 = calc_qf(f_vs_data, prim0) - wR = @. nps_data.w+(ps_data.midpoint[FAT[2][DIR][1]]-nps_data.midpoint[FAT[2][DIR][1]])* - nps_data.sw[:,FAT[2][DIR][1]]+(ps_data.midpoint[FAT[2][DIR][2]]-nps_data.midpoint[FAT[2][DIR][2]])* - nps_data.sw[:,FAT[2][DIR][2]] + wR = @. nps_data.w+( + ps_data.midpoint[FAT[2][DIR][1]]-nps_data.midpoint[FAT[2][DIR][1]] + ) * nps_data.sw[:, FAT[2][DIR][1]]+( + ps_data.midpoint[FAT[2][DIR][2]]-nps_data.midpoint[FAT[2][DIR][2]] + ) * nps_data.sw[:, FAT[2][DIR][2]] aL, aR = calc_a(w0, prim0, ps_data.w, wR, ds, 2.0 * ds, global_data, ROT) Mu, Mv, Mw, Mu_L, Mu_R = moment_u(prim0, global_data, ROT, DIR) A = calc_A(prim0, aL, aR, Mu, Mv, Mw, Mu_L, Mu_R, global_data, DIR) diff --git a/deprecated/flux_copy.jl b/deprecated/flux_copy.jl index 8c27cea..3943e86 100644 --- a/deprecated/flux_copy.jl +++ b/deprecated/flux_copy.jl @@ -341,13 +341,15 @@ function update_face_data_L!( df_L = @view(vs_data.df[bit_L, :]) end f_vs_data.midpoint = - Vcat(@view(midpoint_L[bit_L, :]), @view(f_vs_data.midpoint[offset+1:end, :])) + Vcat(@view(midpoint_L[bit_L, :]), @view(f_vs_data.midpoint[(offset+1):end, :])) f_vs_data.vn = @view(f_vs_data.midpoint[:, DIR]) - f_vs_data.df = Vcat(df_L, @view(f_vs_data.df[offset+1:end, :])) - f_vs_data.sdf = - Vcat(@view(vs_data.sdf[bit_L, :, DIR]), @view(f_vs_data.sdf[offset+1:end, :, DIR])) + f_vs_data.df = Vcat(df_L, @view(f_vs_data.df[(offset+1):end, :])) + f_vs_data.sdf = Vcat( + @view(vs_data.sdf[bit_L, :, DIR]), + @view(f_vs_data.sdf[(offset+1):end, :, DIR]) + ) f_vs_data.weight = - Vcat(@view(vs_data.weight[bit_L]), @view(f_vs_data.weight[offset+1:end])) + Vcat(@view(vs_data.weight[bit_L]), @view(f_vs_data.weight[(offset+1):end])) offset = length(df_L) return (bit_L, offset) end @@ -373,13 +375,15 @@ function update_face_data_L!( df_L = @view(vs_data.df[bit_L, :]) end f_vs_data.midpoint = - Vcat(@view(midpoint_L[bit_L, :]), @view(f_vs_data.midpoint[offset+1:end, :])) + Vcat(@view(midpoint_L[bit_L, :]), @view(f_vs_data.midpoint[(offset+1):end, :])) f_vs_data.vn = @view(f_vs_data.midpoint[:, DIR]) - f_vs_data.df = Vcat(df_L, @view(f_vs_data.df[offset+1:end, :])) - f_vs_data.sdf = - Vcat(@view(vs_data.sdf[bit_L, :, DIR]), @view(f_vs_data.sdf[offset+1:end, :, DIR])) + f_vs_data.df = Vcat(df_L, @view(f_vs_data.df[(offset+1):end, :])) + f_vs_data.sdf = Vcat( + @view(vs_data.sdf[bit_L, :, DIR]), + @view(f_vs_data.sdf[(offset+1):end, :, DIR]) + ) f_vs_data.weight = - Vcat(@view(vs_data.weight[bit_L]), @view(f_vs_data.weight[offset+1:end])) + Vcat(@view(vs_data.weight[bit_L]), @view(f_vs_data.weight[(offset+1):end])) offset = length(df_L) return (bit_L, offset) end @@ -497,7 +501,9 @@ function calc_flux!(::HalfSizeNeighbor, face::Face, amr::KitAMR_Data{3,1}) gas = global_data.config.gas ds = ps_data.ds[DIR] vs_data = ps_data.vs_data - f_vs_data = nothing; offset = 0; bit_L = nothing + f_vs_data = nothing; + offset = 0; + bit_L = nothing for i = 1:4 nps_data = ps_data.neighbor.data[faceid][i] vs_data_n = nps_data.vs_data @@ -560,9 +566,15 @@ function calc_flux!(::DoubleSizeNeighbor, face::Face, amr::KitAMR_Data{2,2}) micro_flux = calc_micro_flux(f_vs_data, F, F⁺, aL, aR, A, Mt, offset, dsf) update_vs_flux!(micro_flux, bit_L, vs_data, vs_data_n, offset, ROT) for i in eachindex(face.hanging_data) - (isa(face.hanging_data[i], Ghost_PS_Data)||isa(face.hanging_data[i],MissingHangingQuad)) && continue + ( + isa( + face.hanging_data[i], + Ghost_PS_Data, + )||isa(face.hanging_data[i], MissingHangingQuad) + ) && continue ps_data = face.hanging_data[i] - bit_L, offset = update_face_data_L!(ps_data, nps_data, f_vs_data, offset, faceid, ROT, DIR) + bit_L, offset = + update_face_data_L!(ps_data, nps_data, f_vs_data, offset, faceid, ROT, DIR) reconstruct_vs_L!(f_vs_data, ds, offset, ROT) w0 = calc_w0(f_vs_data) prim0 = get_prim(w0, global_data) @@ -612,9 +624,15 @@ function calc_flux!(::DoubleSizeNeighbor, face::Face, amr::KitAMR_Data{3,1}) micro_flux = calc_micro_flux(f_vs_data, F, F⁺, aL, aR, A, Mt, offset, dsf) update_vs_flux!(micro_flux, bit_L, vs_data, vs_data_n, offset, ROT) for i in eachindex(face.hanging_data) - (isa(face.hanging_data[i], Ghost_PS_Data)||isa(face.hanging_data[i],MissingHangingQuad)) && continue + ( + isa( + face.hanging_data[i], + Ghost_PS_Data, + )||isa(face.hanging_data[i], MissingHangingQuad) + ) && continue ps_data = face.hanging_data[i] - bit_L, offset = update_face_data_L!(ps_data, nps_data, f_vs_data, offset, faceid, ROT, DIR) + bit_L, offset = + update_face_data_L!(ps_data, nps_data, f_vs_data, offset, faceid, ROT, DIR) reconstruct_vs_L!(f_vs_data, ds, offset, ROT) w0 = calc_w0(f_vs_data) prim0 = get_prim(w0, global_data) @@ -639,4 +657,4 @@ function update_flux!(amr::KitAMR_Data) face = faces[i] calc_flux!(Val(face.data.neighbor.state[face.faceid]), face, amr) end -end \ No newline at end of file +end diff --git a/deprecated/gaussian_weight.jl b/deprecated/gaussian_weight.jl index f92dfe8..e09b6f9 100644 --- a/deprecated/gaussian_weight.jl +++ b/deprecated/gaussian_weight.jl @@ -1,17 +1,37 @@ # In gaussian weighted adaptive method, ps_data.sw and vs_data.flux[:,1] are respectively used to store prims(the aux_pointed (by fluids) one and the interpolated one) and Θ -function gaussian_weight(λ::Float64,midpoint_in::AbstractVector,midpoint_out::AbstractVector) # here, midpoint represents the thermal velocity - exp(-λ*(sum(midpoint_in.^2)-sum(midpoint_out.^2))) +function gaussian_weight( + λ::Float64, + midpoint_in::AbstractVector, + midpoint_out::AbstractVector, +) # here, midpoint represents the thermal velocity + exp(-λ*(sum(midpoint_in .^ 2)-sum(midpoint_out .^ 2))) end -function df_refine(df::AbstractVector,midpoints::AbstractMatrix,midpoint::AbstractVector,U::AbstractVector,prim::AbstractVector,::PS_Data{DIM,NDF}) where{DIM,NDF} +function df_refine( + df::AbstractVector, + midpoints::AbstractMatrix, + midpoint::AbstractVector, + U::AbstractVector, + prim::AbstractVector, + ::PS_Data{DIM,NDF}, +) where {DIM,NDF} λ = prim[end] - weights = [gaussian_weight(λ,x-U,midpoint-U) for x in eachrow(midpoints)] - df_new = [weights[i]*df[j] for i in 1:2^DIM, j in 1:NDF] + weights = [gaussian_weight(λ, x-U, midpoint-U) for x in eachrow(midpoints)] + df_new = [weights[i]*df[j] for i = 1:(2^DIM), j = 1:NDF] return df_new end -function df_coarsen(df::AbstractMatrix,midpoint::AbstractVector,midpoints::AbstractMatrix,U::AbstractVector,prim::AbstractVector) +function df_coarsen( + df::AbstractMatrix, + midpoint::AbstractVector, + midpoints::AbstractMatrix, + U::AbstractVector, + prim::AbstractVector, +) λ = prim[end] - weight = exp(-λ*sum((midpoint-U).^2))/sum([exp(-λ*sum((x-U).^2)) for x in eachrow(midpoints)]) - df_new = vec(sum(df;dims=1)*weight) + weight = + exp( + -λ*sum((midpoint-U) .^ 2), + )/sum([exp(-λ*sum((x-U) .^ 2)) for x in eachrow(midpoints)]) + df_new = vec(sum(df; dims = 1)*weight) return df_new end # function flux_coarsen_replace!(index,lnflux,::PS_Data{DIM,NDF}) where{DIM,NDF} @@ -31,4 +51,4 @@ end # for _ in 1:(NDF-1)*(2^DIM-1) # push!(0,lnflux) # end -# end \ No newline at end of file +# end diff --git a/deprecated/maxwellian.jl b/deprecated/maxwellian.jl index 7a9409f..a211ade 100644 --- a/deprecated/maxwellian.jl +++ b/deprecated/maxwellian.jl @@ -1,81 +1,87 @@ -function WLS_coeffi(interp_point::AbstractVector{T},aux_point::AbstractVector{T},points::AbstractVector{Vector{T}},R::T) where{T} # interp_point: the point to be interpolated (image_point or aux_point); R: search radius +function WLS_coeffi( + interp_point::AbstractVector{T}, + aux_point::AbstractVector{T}, + points::AbstractVector{Vector{T}}, + R::T, +) where {T} # interp_point: the point to be interpolated (image_point or aux_point); R: search radius # w_m is calculated according to the distance to the aux_point - N = length(points);DIM = length(interp_point) - w = Vector{T}(undef,N+1) + N = length(points); + DIM = length(interp_point) + w = Vector{T}(undef, N+1) # _,index = findmin(norm(interp_point.-point) for point in points) interp_point = interp_point-aux_point points = [point-aux_point for point in points] # points[1],points[index] = points[index],points[1] - for i in 1:N + for i = 1:N w[i] = 0.5*(1+cos(π*norm(points[i])/R)) end w[end] = 1.0 W = Diagonal(w) M = WLST[DIM-1] N!isa(x[1],InsideSolidData)&&x[1].bound_enc>0,nnodes) - aux_point = calc_intersect_point(circle,ps_data.midpoint) + fnnodes = findall(x->!isa(x[1], InsideSolidData)&&x[1].bound_enc>0, nnodes) + aux_point = calc_intersect_point(circle, ps_data.midpoint) image_point = 2*aux_point-ps_data.midpoint s_vs_data = ps_data.vs_data - dx = ps_data.ds[1];dy = ps_data.ds[2] + dx = ps_data.ds[1]; + dy = ps_data.ds[2] n = (aux_point-circle.center)/circle.radius # outer normal direction - aux_vs_temp = Vector{Matrix{Float64}}(undef,6) + aux_vs_temp = Vector{Matrix{Float64}}(undef, 6) dxL = norm(aux_point-image_point) dxR = norm(ps_data.midpoint-aux_point) - for i in 2:6 - aux_vs_temp[i] = zeros(Float64,s_vs_data.vs_num,NDF) + for i = 2:6 + aux_vs_temp[i] = zeros(Float64, s_vs_data.vs_num, NDF) end aux_vs_temp[1] = IB_cells.IB_nodes[i][1].vs_data.df # @assert !any(x->abs(x)>100,aux_vs_temp[1]) `IB_vs error!`,aux_vs_temp[1] ip_df = aux_vs_temp[end-1] aux_df = aux_vs_temp[end] # IB_vs = IB_cells.IB_nodes[i][1].vs_data - vn = [dot(@view(s_vs_data.midpoint[j,:]),n) for j in axes(s_vs_data.midpoint,1)] + vn = [dot(@view(s_vs_data.midpoint[j, :]), n) for j in axes(s_vs_data.midpoint, 1)] Θ = heaviside.(vn) dA = √(dx*dy) # try @@ -470,28 +562,31 @@ function update_solid_cell!(circle::Circle,solidcells::SolidCells{DIM,NDF},::Vec # A = nothing;temp_id = nothing # while true angle = abs(atan(n[2]/n[1])) - ratio = abs(ps_data.prim[end]-IB_cells.IB_nodes[i][end].prim[end])/circle.search_radius/global_data.status.gradmax[end] + ratio = + abs( + ps_data.prim[end]-IB_cells.IB_nodes[i][end].prim[end], + )/circle.search_radius/global_data.status.gradmax[end] if ratio<10 # if angle>35/180*π&&angle<55/180*π # temp_id = upwind_template(IB_cells.templates[i],IB_cells.IB_nodes[i],aux_point,IB_cells.IB_nodes[i][1].prim) # else - temp_id = IB_cells.templates[i][1] + temp_id = IB_cells.templates[i][1] # end else temp_id = IB_cells.templates[i][rand(1:length(IB_cells.templates[i]))] end - points = [IB_cells.IB_nodes[i][temp_id[j]].midpoint for j in 1:4] - A = bilinear_coeffi_2D(points...)./dA - # if rank(A)<4 - # @show A - # deleteat!(IB_cells.templates[i],id) - # else - # break - # end - # if length(IB_cells.templates[i])<1 - # @show ps_data.midpoint aux_point - # throw(`Larger search coefficient is requested!`) - # end + points = [IB_cells.IB_nodes[i][temp_id[j]].midpoint for j = 1:4] + A = bilinear_coeffi_2D(points...) ./ dA + # if rank(A)<4 + # @show A + # deleteat!(IB_cells.templates[i],id) + # else + # break + # end + # if length(IB_cells.templates[i])<1 + # @show ps_data.midpoint aux_point + # throw(`Larger search coefficient is requested!`) + # end # end # points = [IB_cells.IB_nodes[i][j].midpoint for j in 1:4] # A =bilinear_coeffi_2D(points...)./dA @@ -500,16 +595,21 @@ function update_solid_cell!(circle::Circle,solidcells::SolidCells{DIM,NDF},::Vec # throw(`Singular Error!`) # end Ainv = inv(A) - for j in 2:4 - vs_projection!(s_vs_data,IB_cells.IB_nodes[i][temp_id[j]].vs_data,aux_vs_temp[j]) + for j = 2:4 + vs_projection!( + s_vs_data, + IB_cells.IB_nodes[i][temp_id[j]].vs_data, + aux_vs_temp[j], + ) # @assert !any(x->isnan(x),aux_vs_temp[j]) `projection error!`,aux_vs_temp[j],IB_cells.IB_nodes[i][j].vs_data.df end - b = Vector{Float64}(undef,4);ip_coeffi = make_bilinear_coeffi_2D(image_point)./dA - @inbounds for j in axes(ip_df,1) + b = Vector{Float64}(undef, 4); + ip_coeffi = make_bilinear_coeffi_2D(image_point) ./ dA + @inbounds for j in axes(ip_df, 1) # V2 = @views sum(IB_vs.midpoint[j,:].^2) - for l in 1:NDF - for k in 1:4 - b[k] = aux_vs_temp[k][j,l] + for l = 1:NDF + for k = 1:4 + b[k] = aux_vs_temp[k][j, l] # temp = aux_vs_temp[k][j,l] # b[k] = temp4/ps_data.prim[end]^2 # ip_df[j,l] = dot(Ainv*(b.*V2),ip_coeffi)/V2 # else - ip_df[j,l] = dot(Ainv*b,ip_coeffi) + ip_df[j, l] = dot(Ainv*b, ip_coeffi) # end # if isnan(ip_df[j,l]) # @show b ip_coeffi Ainv # end end - end + end # aux_point interpolate by bilinear - ap_coeffi = make_bilinear_coeffi_2D(aux_point)./dA - @inbounds for j in axes(aux_df,1) - if Θ[j]==0. + ap_coeffi = make_bilinear_coeffi_2D(aux_point) ./ dA + @inbounds for j in axes(aux_df, 1) + if Θ[j]==0.0 # V2 = @views sum(IB_vs.midpoint[j,:].^2) - for l in 1:NDF + for l = 1:NDF for k = 1:4 - b[k] = aux_vs_temp[k][j,l] + b[k] = aux_vs_temp[k][j, l] # temp = aux_vs_temp[k][j,l] # b[k] = temp4/ps_data.prim[end]^2 # aux_df[j,l] = dot(Ainv*(b.*V2),ap_coeffi)/V2 # else - # aux_df[j,l] = max(dot(Ainv*b,ap_coeffi),0) - aux_df[j,l] = dot(Ainv*b,ap_coeffi) - # @assert !isnan(aux_df[j,l]) `interpolate error!`,b,Ainv,ap_coeffi,points + # aux_df[j,l] = max(dot(Ainv*b,ap_coeffi),0) + aux_df[j, l] = dot(Ainv*b, ap_coeffi) + # @assert !isnan(aux_df[j,l]) `interpolate error!`,b,Ainv,ap_coeffi,points # end end end - end - ρw = calc_IB_ρw(aux_point,circle,s_vs_data.midpoint,s_vs_data.weight,aux_df,vn,Θ) + end + ρw = calc_IB_ρw( + aux_point, + circle, + s_vs_data.midpoint, + s_vs_data.weight, + aux_df, + vn, + Θ, + ) # @assert !isnan(ρw) `ρw error`,ρw,aux_df,aux_vs_temp[1],aux_vs_temp[2],aux_vs_temp[3],aux_vs_temp[4] - aux_prim = IB_prim(circle,aux_point,ρw) - for j in axes(aux_df,1) - if Θ[j]==1. + aux_prim = IB_prim(circle, aux_point, ρw) + for j in axes(aux_df, 1) + if Θ[j]==1.0 # df = discrete_maxwell(@view(s_vs_data.midpoint[j,:]),aux_prim,global_data) # aux_df[j,:] .= df.+shakhov_part(@view(s_vs_data.midpoint[j,:]),df,aux_prim,aux_qf,global_data) - aux_df[j,:] .= discrete_maxwell(@view(s_vs_data.midpoint[j,:]),aux_prim,global_data) + aux_df[j, :] .= + discrete_maxwell(@view(s_vs_data.midpoint[j, :]), aux_prim, global_data) # @assert !any(x->isnan(x),@views aux_df[j,:]) `maxwell error!`,aux_prim end end @@ -568,90 +677,110 @@ function update_solid_cell!(circle::Circle,solidcells::SolidCells{DIM,NDF},::Vec # ps_data.sw[:,1] .= aux_fprim # ps_data.sw[:,2] .= aux_prim+(aux_prim-ip_prim)/dxL*dxR # <"type_gas.md", "Physical space"=>"type_physical_space.md", "Velocity space"=>"type_velocity_space.md", - "Output"=>"type_output.md" + "Output"=>"type_output.md", ] methods_page = [ "Initialization"=>"methods_initialize.md", @@ -19,7 +19,7 @@ methods_page = [ "Parallel"=>"methods_parallel.md", "Theory"=>"methods_theory.md", "Finalization"=>"methods_finalize.md", - "IO"=>"methods_io.md" + "IO"=>"methods_io.md", ] makedocs(; sitename = "KitAMR.jl", @@ -30,12 +30,10 @@ makedocs(; "Functions and Methods"=>methods_page, "Tutorial"=>"tutorial.md", "Index"=>"index_internal.md", - "Limitations"=>"limitations.md" - ], + "Limitations"=>"limitations.md", + ], # format = Documenter.HTML(; collapselevel=1), - checkdocs = :none + checkdocs = :none, ) -deploydocs(;devbranch = "ge", - repo = "github.com/CFDML/KitAMR.jl.git", -) \ No newline at end of file +deploydocs(; devbranch = "ge", repo = "github.com/CFDML/KitAMR.jl.git") diff --git a/example/X38/X38_julia.jl b/example/X38/X38_julia.jl index 3992461..e93b455 100644 --- a/example/X38/X38_julia.jl +++ b/example/X38/X38_julia.jl @@ -1,4 +1,4 @@ -using KitAMR,MPI +using KitAMR, MPI include("./X38_udf.jl") MPI.Init() # MPI initialization. Mandatory for a paralleled program using MPI. @@ -10,7 +10,8 @@ MPI.Init() # MPI initialization. Mandatory for a paralleled program using MPI. Configuration by directly construct `Configure` struct. =# solver = Solver(; - DIM = 3, NDF = 1, + DIM = 3, + NDF = 1, AMR_PS_MAXLEVEL = 4, AMR_DYNAMIC_PS_MAXLEVEL = 4, AMR_VS_MAXLEVEL = 3, @@ -19,46 +20,56 @@ solver = Solver(; flux = CAIDVM, time_marching = CAIDVM_Marching, ) -gas = Gas(; - K = 0.0, - Kn = 0.275, - ω = 0.81, - ωᵣ = 0.81, - T_ref = 273/56, -) +gas = Gas(; K = 0.0, Kn = 0.275, ω = 0.81, ωᵣ = 0.81, T_ref = 273/56) output = Output(solver) -udf = UDF(; - dynamic_ps_refine_flag = amr_region -) -config = Configure(solver; - geometry = [-4.0,5.0,-4.0,4.0,-4.0,4.0], - trees_num = [16,16,16], - quadrature = [-14.2,21.3,-17.75,17.75,-17.75,17.75], - vs_trees_num = [10,10,10], +udf = UDF(; dynamic_ps_refine_flag = amr_region) +config = Configure( + solver; + geometry = [-4.0, 5.0, -4.0, 4.0, -4.0, 4.0], + trees_num = [16, 16, 16], + quadrature = [-14.2, 21.3, -17.75, 17.75, -17.75, 17.75], + vs_trees_num = [10, 10, 10], IC = PCoordFn(X38_buffer_IC), domain = [ - Domain(SuperSonicInflow,1, - [1.,8.0*sqrt(5/6),0.,0.,1.0]),Domain(UniformOutflow,2),Domain(UniformOutflow,3), - Domain(UniformOutflow,4),Domain(UniformOutflow,5),Domain(UniformOutflow,6) - ], - IB = [Triangles(Maxwellian,"./example/X38/X38_normalized.stl",true,1.5,[1.,0.,0.,0.,56/300])], + Domain(SuperSonicInflow, 1, [1.0, 8.0*sqrt(5/6), 0.0, 0.0, 1.0]), + Domain(UniformOutflow, 2), + Domain(UniformOutflow, 3), + Domain(UniformOutflow, 4), + Domain(UniformOutflow, 5), + Domain(UniformOutflow, 6), + ], + IB = [ + Triangles( + Maxwellian, + "./example/X38/X38_normalized.stl", + true, + 1.5, + [1.0, 0.0, 0.0, 0.0, 56/300], + ), + ], output = output, gas = gas, - user_defined = udf + user_defined = udf, ) # ---------------------------------------------------------------------------------------------------- -ps4est,amr = initialize_KitAMR(config) # Initialization for `KitAMR_Data`. +ps4est, amr = initialize_KitAMR(config) # Initialization for `KitAMR_Data`. listen_for_save!() # Start listening for `save` input from `stdin`. -max_sim_time = 20. # Maximum simulation time. +max_sim_time = 20.0 # Maximum simulation time. nt = max_sim_time/amr.global_data.status.Δt+1.0 |> floor |> Int # Maximum number of time marching steps. #= Main loop. =# -for i in 1:nt - adaptive_mesh_refinement!(ps4est,amr;ps_interval = 40, vs_interval=40, partition_interval=40) # AMR. +for i = 1:nt + adaptive_mesh_refinement!( + ps4est, + amr; + ps_interval = 40, + vs_interval = 40, + partition_interval = 40, + ) # AMR. update_slope!(amr) # Update `sdf` in `VS_Data` and `sw` in `PS_Data`. slope_exchange!(ps4est, amr) # Update `sdf` in `Ghost_VS_Data` by MPI communication. update_solid_cell!(amr) # Update variables in solid cells in immersed boundaries. @@ -68,10 +79,9 @@ for i in 1:nt iterate!(amr) # Collision process and time marching. data_exchange!(ps4est, amr) # Update variables in ghost cells by MPI communication. check_for_convergence(amr)&&break # Check for convergence. - check!(i,ps4est,amr) # Check for save and output simulation status to `stdout`. + check!(i, ps4est, amr) # Check for save and output simulation status to `stdout`. end -save_result(ps4est,amr) # Save converging results. -finalize!(ps4est,amr) # Finalize `p4est` things. Release the memory managed by `C`. +save_result(ps4est, amr) # Save converging results. +finalize!(ps4est, amr) # Finalize `p4est` things. Release the memory managed by `C`. MPI.Finalize() # MPI finalization. Mandatory for a paralleled program using MPI. - diff --git a/example/X38/X38_text.jl b/example/X38/X38_text.jl index 45ff95e..5147809 100644 --- a/example/X38/X38_text.jl +++ b/example/X38/X38_text.jl @@ -1,28 +1,33 @@ -using KitAMR,MPI +using KitAMR, MPI include("./X38_udf.jl") MPI.Init() config = KitAMR.read_config("./example/X38/configure_X38.txt") -ps4est,amr = KitAMR.initialize_KitAMR(config); +ps4est, amr = KitAMR.initialize_KitAMR(config); KitAMR.listen_for_save!() -max_sim_time = 20. +max_sim_time = 20.0 nt = max_sim_time/amr.global_data.status.Δt+1.0 |> floor |> Int -for i in 1:nt +for i = 1:nt if MPI.Comm_rank(MPI.COMM_WORLD)==0 @show i end - KitAMR.adaptive_mesh_refinement!(ps4est,amr;ps_interval = 40, vs_interval=40,partition_interval=40) + KitAMR.adaptive_mesh_refinement!( + ps4est, + amr; + ps_interval = 40, + vs_interval = 40, + partition_interval = 40, + ) KitAMR.update_slope!(amr) - KitAMR.slope_exchange!(ps4est, amr) + KitAMR.slope_exchange!(ps4est, amr) KitAMR.update_solid_cell!(amr) KitAMR.solid_exchange!(ps4est, amr) KitAMR.update_solid_neighbor!(amr) - KitAMR.flux!(amr) - KitAMR.iterate!(amr) + KitAMR.flux!(amr) + KitAMR.iterate!(amr) KitAMR.data_exchange!(ps4est, amr) KitAMR.check_for_convergence(amr)&&break - KitAMR.check!(i,ps4est,amr) + KitAMR.check!(i, ps4est, amr) end -KitAMR.save_result(ps4est,amr) -KitAMR.finalize!(ps4est,amr) +KitAMR.save_result(ps4est, amr) +KitAMR.finalize!(ps4est, amr) MPI.Finalize() - diff --git a/example/X38/X38_udf.jl b/example/X38/X38_udf.jl index e8674ad..948610c 100644 --- a/example/X38/X38_udf.jl +++ b/example/X38/X38_udf.jl @@ -1,5 +1,5 @@ using LinearAlgebra -function amr_region(;ps_data,kwargs...) +function amr_region(; ps_data, kwargs...) midpoint = ps_data.midpoint ds = ps_data.ds L = 1.0 @@ -8,17 +8,17 @@ function amr_region(;ps_data,kwargs...) end return false end -function X38_buffer_IC(midpoint::Vector{Float64};kwargs...) +function X38_buffer_IC(midpoint::Vector{Float64}; kwargs...) global_data = kwargs[:global_data] ib = global_data.config.IB[1] - Ma = 8. + Ma = 8.0 T0 = 1.0 Tw = 300/56 - _,distance = KitAMR.nn(ib.tkdt.kdt,midpoint) + _, distance = KitAMR.nn(ib.tkdt.kdt, midpoint) R = 0.3 if distance > R - return [1.0,Ma*√(5/6),0.,0.,1/T0] + return [1.0, Ma*√(5/6), 0.0, 0.0, 1/T0] else - return [1.0,distance*Ma*√(5/6)/R,0.,0.,1.0/(T0+(R-distance)*(Tw-T0)/R)] + return [1.0, distance*Ma*√(5/6)/R, 0.0, 0.0, 1.0/(T0+(R-distance)*(Tw-T0)/R)] end -end \ No newline at end of file +end diff --git a/example/X38/model_transform.jl b/example/X38/model_transform.jl index 175df7e..3922849 100644 --- a/example/X38/model_transform.jl +++ b/example/X38/model_transform.jl @@ -1,12 +1,12 @@ using FileIO, MeshIO, GeometryBasics mesh = load("./example/X38/X38-surface-fine.stl") -points = [x[i] for i in 1:3, x in mesh.position] -mins = minimum(points,dims=2) -maxes = maximum(points,dims=2) +points = [x[i] for i = 1:3, x in mesh.position] +mins = minimum(points, dims = 2) +maxes = maximum(points, dims = 2) L = maximum(maxes-mins) α = -π/9# AOA 20 degrees -Rot = [cos(α) -sin(α) 0;sin(α) cos(α) 0;0 0 1.] -normalized_points = Rot*points./L -normalized_position = [Point(x[1],x[2],x[3]) for x in eachcol(normalized_points)] -new_mesh = Mesh(normalized_position,mesh.faces) -save("./example/X38/X38_normalized.stl",new_mesh) +Rot = [cos(α) -sin(α) 0; sin(α) cos(α) 0; 0 0 1.0] +normalized_points = Rot*points ./ L +normalized_position = [Point(x[1], x[2], x[3]) for x in eachcol(normalized_points)] +new_mesh = Mesh(normalized_position, mesh.faces) +save("./example/X38/X38_normalized.stl", new_mesh) diff --git a/example/airfoil/airfoil.jl b/example/airfoil/airfoil.jl index 5ca7f1d..953e1c2 100644 --- a/example/airfoil/airfoil.jl +++ b/example/airfoil/airfoil.jl @@ -1,9 +1,10 @@ -using KitAMR,MPI +using KitAMR, MPI include("./airfoil_udf.jl") MPI.Init() solver = Solver(; - DIM = 2, NDF = 2, + DIM = 2, + NDF = 2, AMR_PS_MAXLEVEL = 7, AMR_VS_MAXLEVEL = 0, PS_DYNAMIC_AMR = false, @@ -11,52 +12,53 @@ solver = Solver(; flux = CAIDVM, time_marching = CAIDVM_Marching, ) -gas = Gas(; - K = 1.0, - Kn = 0.026, - ω = 0.81, - ωᵣ = 0.81, -) -output = Output( +gas = Gas(; K = 1.0, Kn = 0.026, ω = 0.81, ωᵣ = 0.81) +output = Output(solver;) +udf = UDF(; static_ps_refine_flag = shock_wave_region) +config = Configure( solver; -) -udf = UDF(; - static_ps_refine_flag = shock_wave_region -) -config = Configure(solver; - geometry = [-3.,7.,-7.,7.], - trees_num = [24,32], - quadrature = [-4.,8.,-6.,6.], - vs_trees_num = [60,60], - IC = Uniform([1.,2.0*sqrt(5/6),0.,1.]), + geometry = [-3.0, 7.0, -7.0, 7.0], + trees_num = [24, 32], + quadrature = [-4.0, 8.0, -6.0, 6.0], + vs_trees_num = [60, 60], + IC = Uniform([1.0, 2.0*sqrt(5/6), 0.0, 1.0]), domain = [ - Domain(SuperSonicInflow,1,[1.,2.0*sqrt(5/6),0.,1.]), - Domain(InterpolatedOutflow,2),Domain(InterpolatedOutflow,3),Domain(InterpolatedOutflow,4) - ], - IB = [Vertices(Maxwellian,"./example/airfoil/naca0012.csv",true,4.5,[1.,0.,0.,161/290])], + Domain(SuperSonicInflow, 1, [1.0, 2.0*sqrt(5/6), 0.0, 1.0]), + Domain(InterpolatedOutflow, 2), + Domain(InterpolatedOutflow, 3), + Domain(InterpolatedOutflow, 4), + ], + IB = [ + Vertices( + Maxwellian, + "./example/airfoil/naca0012.csv", + true, + 4.5, + [1.0, 0.0, 0.0, 161/290], + ), + ], output = output, gas = gas, - user_defined = udf + user_defined = udf, ) -ps4est,amr = initialize_KitAMR(config) +ps4est, amr = initialize_KitAMR(config) listen_for_save!() -max_sim_time = 20. +max_sim_time = 20.0 nt = max_sim_time/amr.global_data.status.Δt+1.0 |> floor |> Int -for i in 1:nt - adaptive_mesh_refinement!(ps4est,amr;partition_interval=160) +for i = 1:nt + adaptive_mesh_refinement!(ps4est, amr; partition_interval = 160) update_slope!(amr) - slope_exchange!(ps4est, amr) + slope_exchange!(ps4est, amr) update_solid_cell!(amr) solid_exchange!(ps4est, amr) update_solid_neighbor!(amr) - flux!(amr) - iterate!(amr) + flux!(amr) + iterate!(amr) data_exchange!(ps4est, amr) check_for_convergence(amr)&&break - check!(i,ps4est,amr) + check!(i, ps4est, amr) end -save_result(ps4est,amr) -finalize!(ps4est,amr) +save_result(ps4est, amr) +finalize!(ps4est, amr) MPI.Finalize() - diff --git a/example/airfoil/airfoil_udf.jl b/example/airfoil/airfoil_udf.jl index fab861f..449ab72 100644 --- a/example/airfoil/airfoil_udf.jl +++ b/example/airfoil/airfoil_udf.jl @@ -1,4 +1,4 @@ -function shock_wave_region(midpoint,ds,global_data,level) +function shock_wave_region(midpoint, ds, global_data, level) if midpoint[1]>-1.0&&midpoint[1]<3.0&&midpoint[2]<1.0&&midpoint[2]>-1.0&&level<4 return true end @@ -9,4 +9,4 @@ end # return true # end # return false -# end \ No newline at end of file +# end diff --git a/example/cylinder/cylinder.jl b/example/cylinder/cylinder.jl index 291e96c..fecc6e4 100644 --- a/example/cylinder/cylinder.jl +++ b/example/cylinder/cylinder.jl @@ -1,9 +1,10 @@ -using KitAMR,MPI +using KitAMR, MPI include("./cylinder_udf.jl") MPI.Init() solver = Solver(; - DIM = 2, NDF = 2, + DIM = 2, + NDF = 2, AMR_PS_MAXLEVEL = 7, AMR_VS_MAXLEVEL = 0, PS_DYNAMIC_AMR = false, @@ -11,58 +12,51 @@ solver = Solver(; flux = CAIDVM, time_marching = CAIDVM_Marching, ) -gas = Gas(; - K = 1.0, - Kn = 0.1, - ω = 0.81, - ωᵣ = 0.81, -) -output = Output( +gas = Gas(; K = 1.0, Kn = 0.1, ω = 0.81, ωᵣ = 0.81) +output = Output(solver;) +udf = UDF(; static_ps_refine_flag = shock_wave_region) +config = Configure( solver; -) -udf = UDF(; - static_ps_refine_flag = shock_wave_region -) -config = Configure(solver; - geometry = [-16.,16.,-16.,16.], - trees_num = [25,25], - quadrature = [-10.,10.,-10.,10.], - vs_trees_num = [60,60], + geometry = [-16.0, 16.0, -16.0, 16.0], + trees_num = [25, 25], + quadrature = [-10.0, 10.0, -10.0, 10.0], + vs_trees_num = [60, 60], IC = PCoordFn(cylinder_buffer_IC), domain = [ - Domain(SuperSonicInflow,1,[1.,5.0*sqrt(5/6),0.,1.]),Domain(UniformOutflow,2), - Domain(UniformOutflow,3),Domain(UniformOutflow,4) - ], - IB = [Circle(Maxwellian,[0.,0.],1.,true,4.0,[1.,0.,0.,1.])], + Domain(SuperSonicInflow, 1, [1.0, 5.0*sqrt(5/6), 0.0, 1.0]), + Domain(UniformOutflow, 2), + Domain(UniformOutflow, 3), + Domain(UniformOutflow, 4), + ], + IB = [Circle(Maxwellian, [0.0, 0.0], 1.0, true, 4.0, [1.0, 0.0, 0.0, 1.0])], output = output, gas = gas, - user_defined = udf + user_defined = udf, ) -ps4est,amr = initialize_KitAMR(config); +ps4est, amr = initialize_KitAMR(config); listen_for_save!() -max_sim_time = 20. +max_sim_time = 20.0 nt = max_sim_time/amr.global_data.status.Δt+1.0 |> floor |> Int -for i in 1:nt - adaptive_mesh_refinement!(ps4est,amr;partition_interval=160) +for i = 1:nt + adaptive_mesh_refinement!(ps4est, amr; partition_interval = 160) update_slope!(amr) - slope_exchange!(ps4est, amr) + slope_exchange!(ps4est, amr) update_solid_cell!(amr) solid_exchange!(ps4est, amr) update_solid_neighbor!(amr) - slope_exchange!(ps4est, amr) - flux!(amr) - iterate!(amr) + slope_exchange!(ps4est, amr) + flux!(amr) + iterate!(amr) data_exchange!(ps4est, amr) check_for_convergence(amr)&&break - check!(i,ps4est,amr) + check!(i, ps4est, amr) # KitAMR.check_for_animsave!(ps4est,amr) # if amr.global_data.status.sim_time>3.0 # break # end end -save_result(ps4est,amr) -finalize!(ps4est,amr) +save_result(ps4est, amr) +finalize!(ps4est, amr) MPI.Finalize() - diff --git a/example/cylinder/cylinder_udf.jl b/example/cylinder/cylinder_udf.jl index 3b6df7b..2763315 100644 --- a/example/cylinder/cylinder_udf.jl +++ b/example/cylinder/cylinder_udf.jl @@ -1,13 +1,17 @@ using LinearAlgebra -function shock_wave_region(midpoint,ds,global_data,level) - if midpoint[1]>-5.0&&midpoint[1]<5.0&&midpoint[2]<5.0&&midpoint[2]>-5.0&&√sum(midpoint.^2)>1.0&&level<4 +function shock_wave_region(midpoint, ds, global_data, level) + if midpoint[1]>-5.0&&midpoint[1]<5.0&&midpoint[2]<5.0&&midpoint[2]>-5.0&&√sum( + midpoint .^ 2, + )>1.0&&level<4 return true end return false end -function amr_region(;ps_data,kwargs...) +function amr_region(; ps_data, kwargs...) midpoint = ps_data.midpoint - if midpoint[1]>-5.0&&midpoint[1]<5.0&&midpoint[2]<5.0&&midpoint[2]>-5.0&&√sum(midpoint.^2)>1.0 + if midpoint[1]>-5.0&&midpoint[1]<5.0&&midpoint[2]<5.0&&midpoint[2]>-5.0&&√sum( + midpoint .^ 2, + )>1.0 return true end return false @@ -19,21 +23,24 @@ function cylinder_buffer_IC(midpoint::Vector{Float64}) R = 1.0 l = 1.0 # buffer length if r>R+l - return [1.0,Ma*√(5/6),0.,1.0] + return [1.0, Ma*√(5/6), 0.0, 1.0] else - return [1.0,(r-R)*Ma*√(5/6),0.,Tw-(r-R)/l*(Tw-1.0)] + return [1.0, (r-R)*Ma*√(5/6), 0.0, Tw-(r-R)/l*(Tw-1.0)] end end -function vs_output_flag(;ps_data,kwargs...) - midpoint = ps_data.midpoint;ds = ps_data.ds - tps = Vector{Vector{Float64}}(undef,5) - tps[1] = [-1.4589554070669333,0.05709202822871219];tps[2] = [-1.3786385660534994,0.05709202822871219] - tps[3] = [1.7311,3.3467];tps[4] = [-0.9037743267386753,0.45412464859673063] - tps[5] = [0.9361902761835246,0.9787846953422692] +function vs_output_flag(; ps_data, kwargs...) + midpoint = ps_data.midpoint; + ds = ps_data.ds + tps = Vector{Vector{Float64}}(undef, 5) + tps[1] = [-1.4589554070669333, 0.05709202822871219]; + tps[2] = [-1.3786385660534994, 0.05709202822871219] + tps[3] = [1.7311, 3.3467]; + tps[4] = [-0.9037743267386753, 0.45412464859673063] + tps[5] = [0.9361902761835246, 0.9787846953422692] for i in eachindex(tps) if midpoint[1]-0.5ds[1]tps[i][1]&&midpoint[2]-0.5ds[2]tps[i][2] - return i,true + return i, true end end - return 0,false -end \ No newline at end of file + return 0, false +end diff --git a/example/profile/strong_scaling.jl b/example/profile/strong_scaling.jl index 923475f..cca8dee 100644 --- a/example/profile/strong_scaling.jl +++ b/example/profile/strong_scaling.jl @@ -1,9 +1,10 @@ Pkg.add(NVTX) -using KitAMR,MPI,NVTX +using KitAMR, MPI, NVTX MPI.Init() solver = Solver(; - DIM = 3, NDF = 1, + DIM = 3, + NDF = 1, AMR_PS_MAXLEVEL = 0, AMR_VS_MAXLEVEL = 0, PS_DYNAMIC_AMR = false, @@ -11,45 +12,44 @@ solver = Solver(; flux = CAIDVM, time_marching = CAIDVM_Marching, ) -gas = Gas(; - K = 0.0, - Kn = 0.075, - ω = 0.81, - ωᵣ = 0.81, -) +gas = Gas(; K = 0.0, Kn = 0.075, ω = 0.81, ωᵣ = 0.81) output = Output(solver) udf = UDF() -config = Configure(solver; - geometry = [-0.5,0.5,-0.5,0.5,-0.5,0.5], - trees_num = [32,32,32], - quadrature = [-5.0,5.0,-5.0,5.0,-5.0,5.0], - vs_trees_num = [24,24,24], - IC = Uniform([1.,0.,0.,0.,1.]), +config = Configure( + solver; + geometry = [-0.5, 0.5, -0.5, 0.5, -0.5, 0.5], + trees_num = [32, 32, 32], + quadrature = [-5.0, 5.0, -5.0, 5.0, -5.0, 5.0], + vs_trees_num = [24, 24, 24], + IC = Uniform([1.0, 0.0, 0.0, 0.0, 1.0]), domain = [ - Domain(Maxwellian,1,[1.,0.,0.,0.,1.]), - Domain(Maxwellian,2,[1.,1.0*sqrt(5/6),0.,0.,1.0]),Domain(Period,3), - Domain(Period,4),Domain(Period,5),Domain(Period,6) - ], + Domain(Maxwellian, 1, [1.0, 0.0, 0.0, 0.0, 1.0]), + Domain(Maxwellian, 2, [1.0, 1.0*sqrt(5/6), 0.0, 0.0, 1.0]), + Domain(Period, 3), + Domain(Period, 4), + Domain(Period, 5), + Domain(Period, 6), + ], output = output, gas = gas, - user_defined = udf + user_defined = udf, ) -ps4est,amr = initialize_KitAMR(config); +ps4est, amr = initialize_KitAMR(config); KitAMR.listen_for_save!() -max_sim_time = 20. +max_sim_time = 20.0 nt = max_sim_time/amr.global_data.status.Δt+1.0 |> floor |> Int -for i in 1:10 +for i = 1:10 # adaptive_mesh_refinement!(ps4est,amr) if MPI.Comm_rank(MPI.COMM_WORLD)==0 - @show i + @show i end NVTX.@range "update_slope" begin update_slope!(amr) end MPI.Barrier(MPI.COMM_WORLD) NVTX.@range "slope_exchange" begin - slope_exchange!(ps4est, amr) + slope_exchange!(ps4est, amr) end NVTX.@range "update_solid_cell" begin update_solid_cell!(amr) @@ -61,19 +61,18 @@ for i in 1:10 update_solid_neighbor!(amr) end NVTX.@range "flux" begin - flux!(amr) + flux!(amr) end NVTX.@range "iterate" begin - iterate!(amr) + iterate!(amr) end MPI.Barrier(MPI.COMM_WORLD) NVTX.@range "data_exchange" begin data_exchange!(ps4est, amr) end check_for_convergence(amr)&&break - check!(i,ps4est,amr) + check!(i, ps4est, amr) end # save_result(ps4est,amr) -finalize!(ps4est,amr) +finalize!(ps4est, amr) MPI.Finalize() - diff --git a/example/profile/weak_scaling_n32.jl b/example/profile/weak_scaling_n32.jl index 8e0dd15..ea57437 100644 --- a/example/profile/weak_scaling_n32.jl +++ b/example/profile/weak_scaling_n32.jl @@ -1,16 +1,15 @@ -using KitAMR,MPI +using KitAMR, MPI MPI.Init() config = KitAMR.read_config("./example/cavity/configure_cavity_3D_32.txt") -ps4est,amr = KitAMR.initialize_KitAMR(config); -max_sim_time = 20. +ps4est, amr = KitAMR.initialize_KitAMR(config); +max_sim_time = 20.0 nt = max_sim_time/amr.global_data.status.Δt+1.0 |> floor |> Int -for i in 1:200 +for i = 1:200 KitAMR.update_slope!(amr) - KitAMR.slope_exchange!(ps4est, amr) - KitAMR.flux!(amr) - KitAMR.iterate!(amr) + KitAMR.slope_exchange!(ps4est, amr) + KitAMR.flux!(amr) + KitAMR.iterate!(amr) KitAMR.data_exchange!(ps4est, amr) end -KitAMR.finalize!(ps4est,amr) +KitAMR.finalize!(ps4est, amr) MPI.Finalize() - diff --git a/example/r2v.jl b/example/r2v.jl index 2685470..34cf769 100644 --- a/example/r2v.jl +++ b/example/r2v.jl @@ -2,21 +2,21 @@ using KitAMR include("convergence_ps_TC/convergence_ps_udf.jl") include("artificial_interpolation/convergence_ps_udf.jl") include("cylinder/cylinder_udf.jl") -KitAMR.result2vtk("result2025-01-09_21-43","modified1_UGKS_vtk") -KitAMR.result2vtk("result2025-08-17_19-27","test_period") -KitAMR.result2vtk("result2025-01-11_22-34","test_vs_vtk") -KitAMR.result2vtk("result2025-01-10_21-28","test_non-vs_vtk") -KitAMR.result2vtk("result2025-01-11_21-29","test_non-adapt_vtk") -KitAMR.result2vtk("result2025-01-14_16-09","test_DVM_vtk") -KitAMR.result2vtk("v100","v100") -KitAMR.result2vtk("result2025-07-25_18-16","hypersonic_cylinder_vuniform_vanleer") -KitAMR.result2vtk("result2025-08-24_16-59","test cylinder_Kn0p01 downwind_reduce")#11600steps with 1TOLERANCE -KitAMR.result2vtk("result2025-06-17_11-43","test cylinder_conserved")#7000steps with 100TOLERANCE -KitAMR.result2vtk("result2025-07-11_06-03","naca0012_vuniform") -KitAMR.result2vtk("result2025-07-10_23-44","hypersonic_cylinder_vuniform") -for i in [64,128,256] +KitAMR.result2vtk("result2025-01-09_21-43", "modified1_UGKS_vtk") +KitAMR.result2vtk("result2025-08-17_19-27", "test_period") +KitAMR.result2vtk("result2025-01-11_22-34", "test_vs_vtk") +KitAMR.result2vtk("result2025-01-10_21-28", "test_non-vs_vtk") +KitAMR.result2vtk("result2025-01-11_21-29", "test_non-adapt_vtk") +KitAMR.result2vtk("result2025-01-14_16-09", "test_DVM_vtk") +KitAMR.result2vtk("v100", "v100") +KitAMR.result2vtk("result2025-07-25_18-16", "hypersonic_cylinder_vuniform_vanleer") +KitAMR.result2vtk("result2025-08-24_16-59", "test cylinder_Kn0p01 downwind_reduce")#11600steps with 1TOLERANCE +KitAMR.result2vtk("result2025-06-17_11-43", "test cylinder_conserved")#7000steps with 100TOLERANCE +KitAMR.result2vtk("result2025-07-11_06-03", "naca0012_vuniform") +KitAMR.result2vtk("result2025-07-10_23-44", "hypersonic_cylinder_vuniform") +for i in [64, 128, 256] dir = "result_interp_p"*string(i) name = "interp_p"*string(i) - KitAMR.boundary_result2csv(dir,name) + KitAMR.boundary_result2csv(dir, name) end -KitAMR.boundary_result2csv("result2025-12-08_23-36","cylinder_vanleer") \ No newline at end of file +KitAMR.boundary_result2csv("result2025-12-08_23-36", "cylinder_vanleer") diff --git a/example/sphere/sphere.jl b/example/sphere/sphere.jl index aae3c8a..6705ca4 100644 --- a/example/sphere/sphere.jl +++ b/example/sphere/sphere.jl @@ -1,9 +1,10 @@ -using KitAMR,MPI +using KitAMR, MPI include("./sphere_udf.jl") MPI.Init() solver = Solver(; - DIM = 3, NDF = 1, + DIM = 3, + NDF = 1, AMR_PS_MAXLEVEL = 4, AMR_VS_MAXLEVEL = 2, PS_DYNAMIC_AMR = false, @@ -11,56 +12,62 @@ solver = Solver(; flux = CAIDVM, time_marching = CAIDVM_Marching, ) -gas = Gas(; - K = 0.0, - Kn = 0.03, - ω = 0.75, - ωᵣ = 0.75, - μᵣ = 5.0*√π/16.0*0.03 -) +gas = Gas(; K = 0.0, Kn = 0.03, ω = 0.75, ωᵣ = 0.75, μᵣ = 5.0*√π/16.0*0.03) output = Output(solver) udf = UDF(; static_ps_refine_flag = shock_wave_region, - static_vs_refine_flag = vs_refine_region + static_vs_refine_flag = vs_refine_region, ) -config = Configure(solver; - geometry = [-4.,4.,-4.,4.,-4.,4.], - trees_num = [16,16,16], - quadrature = [-7.28,7.28,-7.28,7.28,-7.28,7.28], # 3σ: 3√Ts - vs_trees_num = [16,16,16], +config = Configure( + solver; + geometry = [-4.0, 4.0, -4.0, 4.0, -4.0, 4.0], + trees_num = [16, 16, 16], + quadrature = [-7.28, 7.28, -7.28, 7.28, -7.28, 7.28], # 3σ: 3√Ts + vs_trees_num = [16, 16, 16], IC = PCoordFn(sphere_buffer_IC), domain = [ - Domain(SuperSonicInflow,1,[1.,3.834*sqrt(5/6),0.,0.,1.]), - Domain(UniformOutflow,2),Domain(UniformOutflow,3),Domain(UniformOutflow,4), - Domain(UniformOutflow,5),Domain(UniformOutflow,6) + Domain(SuperSonicInflow, 1, [1.0, 3.834*sqrt(5/6), 0.0, 0.0, 1.0]), + Domain(UniformOutflow, 2), + Domain(UniformOutflow, 3), + Domain(UniformOutflow, 4), + Domain(UniformOutflow, 5), + Domain(UniformOutflow, 6), + ], + IB = [ + Sphere( + Maxwellian, + [0.0, 0.0, 0.0], + 0.5, + true, + 1.5, + [1.0, 0.0, 0.0, 0.0, 1.0/(1.0+(5/3-1)*0.5*3.834^2)], + ), ], - IB = [Sphere(Maxwellian,[0.,0.,0.],0.5,true,1.5,[1.,0.,0.,0., 1.0/(1.0+(5/3-1)*0.5*3.834^2)])], output = output, gas = gas, - user_defined = udf + user_defined = udf, ) -ps4est,amr = initialize_KitAMR(config); +ps4est, amr = initialize_KitAMR(config); listen_for_save!() -max_sim_time = 20. +max_sim_time = 20.0 nt = max_sim_time/amr.global_data.status.Δt+1.0 |> floor |> Int -for i in 1:nt +for i = 1:nt if MPI.Comm_rank(MPI.COMM_WORLD)==0 @show i end - adaptive_mesh_refinement!(ps4est,amr;vs_interval=10,partition_interval=40) + adaptive_mesh_refinement!(ps4est, amr; vs_interval = 10, partition_interval = 40) update_slope!(amr) - slope_exchange!(ps4est, amr) + slope_exchange!(ps4est, amr) update_solid_cell!(amr) solid_exchange!(ps4est, amr) update_solid_neighbor!(amr) - flux!(amr) - iterate!(amr) + flux!(amr) + iterate!(amr) data_exchange!(ps4est, amr) check_for_convergence(amr)&&break - check!(i,ps4est,amr) + check!(i, ps4est, amr) end -save_result(ps4est,amr) -finalize!(ps4est,amr) +save_result(ps4est, amr) +finalize!(ps4est, amr) MPI.Finalize() - diff --git a/example/sphere/sphere_udf.jl b/example/sphere/sphere_udf.jl index 0fac125..d1426f0 100644 --- a/example/sphere/sphere_udf.jl +++ b/example/sphere/sphere_udf.jl @@ -1,36 +1,48 @@ using LinearAlgebra -function shock_wave_region(midpoint,ds,global_data,level) +function shock_wave_region(midpoint, ds, global_data, level) refine_level = 4 - if midpoint[1]>-1.2&&midpoint[1]<1.2&&midpoint[2]<1.2&&midpoint[2]>-1.2&&√sum(midpoint.^2)>0.5&&midpoint[3]>-1.2&&midpoint[3]<1.2&&level-1.2&&midpoint[1]<1.2&&midpoint[2]<1.2&&midpoint[2]>-1.2&&√sum( + midpoint .^ 2, + )>0.5&&midpoint[3]>-1.2&&midpoint[3]<1.2&&level-0.8&&midpoint[1]<0.8&&midpoint[2]<0.8&&midpoint[2]>-0.8&&√sum(midpoint.^2)>0.5&&midpoint[3]>-0.8&&midpoint[3]<0.8&&level-0.8&&midpoint[1]<0.8&&midpoint[2]<0.8&&midpoint[2]>-0.8&&√sum( + midpoint .^ 2, + )>0.5&&midpoint[3]>-0.8&&midpoint[3]<0.8&&level1.0 - return [1.0,Ma*√(5/6),0.,0.,1.0] + return [1.0, Ma*√(5/6), 0.0, 0.0, 1.0] else - return [1.0,(r-0.5)/(1.0-0.5)*Ma*√(5/6),0.,0.,1.0/(Tw-(r-0.5)*(Tw-1.0))] + return [1.0, (r-0.5)/(1.0-0.5)*Ma*√(5/6), 0.0, 0.0, 1.0/(Tw-(r-0.5)*(Tw-1.0))] end end -function vs_refine_region(midpoint;kwargs...) +function vs_refine_region(midpoint; kwargs...) level = kwargs[:level] du = kwargs[:du] - refine_level = 2;DIM = 3 + refine_level = 2; + DIM = 3 Ma = 3.834 Ts = 1.0+(5/3-1)*0.5*Ma^2 - U_av = [0.5*Ma*√(5/6),0.,0.] + U_av = [0.5*Ma*√(5/6), 0.0, 0.0] sn = sign.(U_av-midpoint) - midpoint_new = midpoint+0.25*du.*sn - flag1 = levelU_av[i]-2.0*sqrt(Ts)&&midpoint_new[i]U_av[i]-1.0*sqrt(Ts)&&midpoint_new[i]U_av[i]-2.0*sqrt(Ts)&&midpoint_new[i]U_av[i]-1.0*sqrt(Ts)&&midpoint_new[i]=1 calculate _>0 _<0 <ξ^4> +function moment_u_2D2F(U::T, V::Real, λ::Real, n::Integer, m::Integer, K::Real) where {T} # n>=1 calculate _>0 _<0 <ξ^4> Mu_L = Vector{T}(undef, n + 1) Mu = Vector{T}(undef, n + 1) Mu_R = Vector{T}(undef, n + 1) @inbounds begin Mu_L[1] = 0.5 * erfc(-√(λ) * U) - Mu_L[2] = - U * Mu_L[1] + 0.5 * exp(-λ * U^2) / (√(π * λ)) - Mu_R[1] = 0.5 * erfc(√(λ) * U) - Mu_R[2] = - U * Mu_R[1] - 0.5 * exp(-λ * U^2) / (√(π * λ)) - for i = 1:n-1 - Mu_L[i+2] = U * Mu_L[i+1] + 0.5 * i / λ * Mu_L[i] - Mu_R[i+2] = U * Mu_R[i+1] + 0.5 * i / λ * Mu_R[i] - end - Mu = @. Mu_L + Mu_R - Mv = Vector{T}(undef, m + 1) - Mv[1] = one(T) - Mv[2] = V - for i = 1:m-1 - Mv[i+2] = V * Mv[i+1] + 0.5 * i * Mv[i] / λ - end - Mξ2 = 0.5 * K / (λ) - Mξ4 = (K^2 + 2.0 * K) / (4.0 * λ^2) - Mξ = [one(Mξ2), Mξ2, Mξ4] - end - return (Mu, Mv, Mξ, Mu_L, Mu_R) - end + Mu_L[2] = U * Mu_L[1] + 0.5 * exp(-λ * U^2) / (√(π * λ)) + Mu_R[1] = 0.5 * erfc(√(λ) * U) + Mu_R[2] = U * Mu_R[1] - 0.5 * exp(-λ * U^2) / (√(π * λ)) + for i = 1:(n-1) + Mu_L[i+2] = U * Mu_L[i+1] + 0.5 * i / λ * Mu_L[i] + Mu_R[i+2] = U * Mu_R[i+1] + 0.5 * i / λ * Mu_R[i] + end + Mu = @. Mu_L + Mu_R + Mv = Vector{T}(undef, m + 1) + Mv[1] = one(T) + Mv[2] = V + for i = 1:(m-1) + Mv[i+2] = V * Mv[i+1] + 0.5 * i * Mv[i] / λ + end + Mξ2 = 0.5 * K / (λ) + Mξ4 = (K^2 + 2.0 * K) / (4.0 * λ^2) + Mξ = [one(Mξ2), Mξ2, Mξ4] + end + return (Mu, Mv, Mξ, Mu_L, Mu_R) +end - function moment_uv_2D2F(Mu::AbstractVector{T}, Mv, Mξ, α::Integer, β::Integer, δ::Integer) where{T} # calc - Muv = Vector{T}(undef, 4) - @inbounds begin - Muv[1] = Mu[α+1] * Mv[β+1] * Mξ[Int(δ / 2 + 1)] - Muv[2] = Mu[α+2] * Mv[β+1] * Mξ[Int(δ / 2 + 1)] - Muv[3] = Mu[α+1] * Mv[β+2] * Mξ[Int(δ / 2 + 1)] - Muv[4] = - 0.5 * ( - Mu[α+3] * Mv[β+1] * Mξ[Int(δ / 2 + 1)] + - Mu[α+1] * Mv[β+3] * Mξ[Int(δ / 2 + 1)] + - Mu[α+1] * Mv[β+1] * Mξ[Int(δ / 2 + 2)] - ) - end - return Muv - end +function moment_uv_2D2F( + Mu::AbstractVector{T}, + Mv, + Mξ, + α::Integer, + β::Integer, + δ::Integer, +) where {T} # calc + Muv = Vector{T}(undef, 4) + @inbounds begin + Muv[1] = Mu[α+1] * Mv[β+1] * Mξ[Int(δ / 2 + 1)] + Muv[2] = Mu[α+2] * Mv[β+1] * Mξ[Int(δ / 2 + 1)] + Muv[3] = Mu[α+1] * Mv[β+2] * Mξ[Int(δ / 2 + 1)] + Muv[4] = + 0.5 * ( + Mu[α+3] * Mv[β+1] * Mξ[Int(δ / 2 + 1)] + + Mu[α+1] * Mv[β+3] * Mξ[Int(δ / 2 + 1)] + + Mu[α+1] * Mv[β+1] * Mξ[Int(δ / 2 + 2)] + ) + end + return Muv +end - function moment_au_2D2F(a, Mu, Mv, Mξ, α::Integer, β::Integer)# calc - @inbounds a[1] * moment_uv_2D2F(Mu, Mv, Mξ, α, β, 0) + - a[2] * moment_uv_2D2F(Mu, Mv, Mξ, α + 1, β, 0) + - a[3] * moment_uv_2D2F(Mu, Mv, Mξ, α, β + 1, 0) + - 0.5 * a[4] * moment_uv_2D2F(Mu, Mv, Mξ, α + 2, β, 0) + - 0.5 * a[4] * moment_uv_2D2F(Mu, Mv, Mξ, α, β + 2, 0) + - 0.5 * a[4] * moment_uv_2D2F(Mu, Mv, Mξ, α, β, 2) - end +function moment_au_2D2F(a, Mu, Mv, Mξ, α::Integer, β::Integer)# calc + @inbounds a[1] * moment_uv_2D2F(Mu, Mv, Mξ, α, β, 0) + + a[2] * moment_uv_2D2F(Mu, Mv, Mξ, α + 1, β, 0) + + a[3] * moment_uv_2D2F(Mu, Mv, Mξ, α, β + 1, 0) + + 0.5 * a[4] * moment_uv_2D2F(Mu, Mv, Mξ, α + 2, β, 0) + + 0.5 * a[4] * moment_uv_2D2F(Mu, Mv, Mξ, α, β + 2, 0) + + 0.5 * a[4] * moment_uv_2D2F(Mu, Mv, Mξ, α, β, 2) +end diff --git a/lib/KitCore/3D.jl b/lib/KitCore/3D.jl index c999206..62c919a 100644 --- a/lib/KitCore/3D.jl +++ b/lib/KitCore/3D.jl @@ -15,7 +15,8 @@ function get_prim_3D(w::AbstractVector, γ::Real) @inbounds prim[2] = w[2] / w[1] @inbounds prim[3] = w[3] / w[1] @inbounds prim[4] = w[4] / w[1] - @inbounds prim[5] = 0.5 * w[1] / (γ - 1.0) / (w[5] - 0.5 * (w[2]^2 + w[3]^2 + w[4]^2) / w[1]) + @inbounds prim[5] = + 0.5 * w[1] / (γ - 1.0) / (w[5] - 0.5 * (w[2]^2 + w[3]^2 + w[4]^2) / w[1]) return prim end function micro_slope_3D(sw::AbstractVector{T}, prim::AbstractVector, K::Real) where {T} @@ -34,8 +35,8 @@ function micro_slope_3D(sw::AbstractVector{T}, prim::AbstractVector, K::Real) wh 0.5 * (prim[2]^2 + prim[3]^2 + prim[4]^2 + 0.5 * (K + 3.0) / prim[5]) * a[5] return a end -function pressure_3D(u::AbstractVector{T},v,w,h,weight) where{T} - p = Vector{T}(undef,6) +function pressure_3D(u::AbstractVector{T}, v, w, h, weight) where {T} + p = Vector{T}(undef, 6) p[1] = sum(@. u^2*h*weight) # p11 p[2] = sum(@. u*v*h*weight) # p12 p[3] = sum(@.u*w*h*weight) # p13 @@ -43,4 +44,4 @@ function pressure_3D(u::AbstractVector{T},v,w,h,weight) where{T} p[5] = sum(@. v*w*h*weight) # p23 p[6] = sum(@. w^2*h*weight) # p33 return p -end \ No newline at end of file +end diff --git a/lib/KitCore/3D1F.jl b/lib/KitCore/3D1F.jl index 8c3ba45..c02a7d6 100644 --- a/lib/KitCore/3D1F.jl +++ b/lib/KitCore/3D1F.jl @@ -4,22 +4,17 @@ function discrete_maxwell_3D1F( w::AbstractVector, prim::AbstractVector, ) where {T} - M = Matrix{T}(undef, length(u),1) + M = Matrix{T}(undef, length(u), 1) @inbounds @. M = prim[1] * (prim[5] / π)^(3 / 2) * exp(-prim[5] * ((u - prim[2])^2 + (v - prim[3])^2 + (w - prim[4])^2)) return M end -function discrete_maxwell_3D1F( - u::Real, - v::Real, - w::Real, - prim::AbstractVector, -) - prim[1] * - (prim[5] / π)^(3 / 2) * - exp(-prim[5] * ((u - prim[2])^2 + (v - prim[3])^2 + (w - prim[4])^2)) +function discrete_maxwell_3D1F(u::Real, v::Real, w::Real, prim::AbstractVector) + prim[1] * + (prim[5] / π)^(3 / 2) * + exp(-prim[5] * ((u - prim[2])^2 + (v - prim[3])^2 + (w - prim[4])^2)) end function shakhov_part_3D1F( u::AbstractVector{T}, @@ -30,7 +25,7 @@ function shakhov_part_3D1F( qf::AbstractVector, Pr::Real, ) where {T} - M⁺ = Matrix{T}(undef, length(u),1) + M⁺ = Matrix{T}(undef, length(u), 1) @inbounds @. M⁺ = 0.8 * (1 - Pr) * prim[5]^2 / prim[1] * ((u - prim[2]) * qf[1] + (v - prim[3]) * qf[2] + (w - prim[4]) * qf[3]) * @@ -45,7 +40,7 @@ function heat_flux_3D1F( h::AbstractVector, prim::AbstractVector, weight::AbstractVector, -) where{T} +) where {T} q = Vector{T}(undef, 3) @inbounds q[1] = 0.5 * (sum( @@ -122,18 +117,24 @@ function micro_to_macro_3D1F( return W end -function moment_u_3D1F(U::T,V::Real,W::Real,λ::Real,n::Integer,m::Integer,δ::Integer) where{T} # n>=1 calculate _>0 _<0 +function moment_u_3D1F( + U::T, + V::Real, + W::Real, + λ::Real, + n::Integer, + m::Integer, + δ::Integer, +) where {T} # n>=1 calculate _>0 _<0 Mu_L = Vector{T}(undef, n + 1) Mu = Vector{T}(undef, n + 1) Mu_R = Vector{T}(undef, n + 1) @inbounds begin Mu_L[1] = 0.5 * erfc(-√(λ) * U) - Mu_L[2] = - U * Mu_L[1] + 0.5 * exp(-λ * U^2) / (√(π * λ)) + Mu_L[2] = U * Mu_L[1] + 0.5 * exp(-λ * U^2) / (√(π * λ)) Mu_R[1] = 0.5 * erfc(√(λ) * U) - Mu_R[2] = - U * Mu_R[1] - 0.5 * exp(-λ * U^2) / (√(π * λ)) - for i = 1:n-1 + Mu_R[2] = U * Mu_R[1] - 0.5 * exp(-λ * U^2) / (√(π * λ)) + for i = 1:(n-1) Mu_L[i+2] = U * Mu_L[i+1] + 0.5 * i / λ * Mu_L[i] Mu_R[i+2] = U * Mu_R[i+1] + 0.5 * i / λ * Mu_R[i] end @@ -141,20 +142,27 @@ function moment_u_3D1F(U::T,V::Real,W::Real,λ::Real,n::Integer,m::Integer,δ::I Mv = Vector{T}(undef, m + 1) Mv[1] = one(T) Mv[2] = V - for i = 1:m-1 + for i = 1:(m-1) Mv[i+2] = V * Mv[i+1] + 0.5 * i * Mv[i] / λ end Mw = Vector{T}(undef, δ + 1) Mw[1] = one(T) Mw[2] = W - for i = 1:δ-1 + for i = 1:(δ-1) Mw[i+2] = W * Mw[i+1] + 0.5 * i * Mw[i] / λ end end return (Mu, Mv, Mw, Mu_L, Mu_R) end -function moment_uv_3D1F(Mu::AbstractVector{T},Mv,Mw,α::Integer, β::Integer, δ::Integer) where{T}# calc +function moment_uv_3D1F( + Mu::AbstractVector{T}, + Mv, + Mw, + α::Integer, + β::Integer, + δ::Integer, +) where {T}# calc Muv = Vector{T}(undef, 5) @inbounds begin Muv[1] = Mu[α+1] * Mv[β+1] * Mw[δ+1] diff --git a/lib/KitCore/KitCore.jl b/lib/KitCore/KitCore.jl index 4a48ee6..66ad314 100644 --- a/lib/KitCore/KitCore.jl +++ b/lib/KitCore/KitCore.jl @@ -1,21 +1,21 @@ module KitCore - using SpecialFunctions - using ExportAll - include("2D.jl") - include("2D2F.jl") - include("3D.jl") - include("3D1F.jl") - function time_int(τ::T, Δt)where{T} - Mt = Vector{T}(undef, 5) - @inbounds begin - Mt[4] = τ * (1.0 - exp(-Δt / τ)) - Mt[5] = -τ * Δt * exp(-Δt / τ) + τ * Mt[4] - Mt[1] = Δt - Mt[4] - Mt[2] = -τ * Mt[1] + Mt[5] - Mt[3] = 0.5 * Δt^2 - τ * Mt[1] - end - return Mt +using SpecialFunctions +using ExportAll +include("2D.jl") +include("2D2F.jl") +include("3D.jl") +include("3D1F.jl") +function time_int(τ::T, Δt) where {T} + Mt = Vector{T}(undef, 5) + @inbounds begin + Mt[4] = τ * (1.0 - exp(-Δt / τ)) + Mt[5] = -τ * Δt * exp(-Δt / τ) + τ * Mt[4] + Mt[1] = Δt - Mt[4] + Mt[2] = -τ * Mt[1] + Mt[5] + Mt[3] = 0.5 * Δt^2 - τ * Mt[1] end - - @exportAll() + return Mt +end + +@exportAll() end # module KitCore diff --git a/lib/P4est/src/LibP4est.jl b/lib/P4est/src/LibP4est.jl index 118ec67..6e20288 100644 --- a/lib/P4est/src/LibP4est.jl +++ b/lib/P4est/src/LibP4est.jl @@ -3,9 +3,10 @@ module LibP4est using CEnum to_c_type(t::Type) = t -to_c_type_pairs(va_list) = map(enumerate(to_c_type.(va_list))) do (ind, type) - :(va_list[$ind]::$type) -end +to_c_type_pairs(va_list) = + map(enumerate(to_c_type.(va_list))) do (ind, type) + :(va_list[$ind]::$type) + end using P4est_jll: P4est_jll export P4est_jll @@ -66,6 +67,7 @@ const INT64_MAX = typemax(Clonglong) Print a message to stderr and then call [`sc_abort`](@ref) (). ### Prototype + ```c void sc_abort_verbose (const char *filename, int lineno, const char *msg) __attribute__ ((noreturn)); ``` @@ -76,13 +78,21 @@ end # automatic type deduction for variadic arguments may not be what you want, please use with caution @generated function sc_abort_verbosef(filename, lineno, fmt, va_list...) - :(@ccall(libsc.sc_abort_verbosef(filename::Cstring, lineno::Cint, fmt::Cstring; $(to_c_type_pairs(va_list)...))::Cvoid)) - end + :(@ccall( + libsc.sc_abort_verbosef( + filename::Cstring, + lineno::Cint, + fmt::Cstring; + $(to_c_type_pairs(va_list)...), + )::Cvoid + )) +end """ sc_malloc(package, size) ### Prototype + ```c void *sc_malloc (int package, size_t size); ``` @@ -95,6 +105,7 @@ end sc_calloc(package, nmemb, size) ### Prototype + ```c void *sc_calloc (int package, size_t nmemb, size_t size); ``` @@ -107,6 +118,7 @@ end sc_realloc(package, ptr, size) ### Prototype + ```c void *sc_realloc (int package, void *ptr, size_t size); ``` @@ -119,6 +131,7 @@ end sc_strdup(package, s) ### Prototype + ```c char *sc_strdup (int package, const char *s); ``` @@ -131,6 +144,7 @@ end sc_free(package, ptr) ### Prototype + ```c void sc_free (int package, void *ptr); ``` @@ -145,34 +159,54 @@ end The central log function to be called by all packages. Dispatches the log calls by package and filters by category and priority. ### Parameters -* `package`:\\[in\\] Must be a registered package id or -1. -* `category`:\\[in\\] Must be `SC_LC_NORMAL` or `SC_LC_GLOBAL`. -* `priority`:\\[in\\] Must be > `SC_LP_ALWAYS` and < `SC_LP_SILENT`. + + - `package`:\\[in\\] Must be a registered package id or -1. + - `category`:\\[in\\] Must be `SC_LC_NORMAL` or `SC_LC_GLOBAL`. + - `priority`:\\[in\\] Must be > `SC_LP_ALWAYS` and < `SC_LP_SILENT`. + ### Prototype + ```c void sc_log (const char *filename, int lineno, int package, int category, int priority, const char *msg); ``` """ function sc_log(filename, lineno, package, category, priority, msg) - @ccall libsc.sc_log(filename::Cstring, lineno::Cint, package::Cint, category::Cint, priority::Cint, msg::Cstring)::Cvoid + @ccall libsc.sc_log( + filename::Cstring, + lineno::Cint, + package::Cint, + category::Cint, + priority::Cint, + msg::Cstring, + )::Cvoid end # automatic type deduction for variadic arguments may not be what you want, please use with caution @generated function sc_logf(filename, lineno, package, category, priority, fmt, va_list...) - :(@ccall(libsc.sc_logf(filename::Cstring, lineno::Cint, package::Cint, category::Cint, priority::Cint, fmt::Cstring; $(to_c_type_pairs(va_list)...))::Cvoid)) - end + :(@ccall( + libsc.sc_logf( + filename::Cstring, + lineno::Cint, + package::Cint, + category::Cint, + priority::Cint, + fmt::Cstring; + $(to_c_type_pairs(va_list)...), + )::Cvoid + )) +end """ sc_array The [`sc_array`](@ref) object provides a dynamic array of equal-size elements. Elements are accessed by their 0-based index. Their address may change. The number of elements (== elem\\_count) of the array can be changed by sc_array_resize and sc_array_rewind. Elements can be sorted with sc_array_sort. If the array is sorted, it can be searched with sc_array_bsearch. A priority queue is implemented with pqueue\\_add and pqueue\\_pop (untested). -| Field | Note | -| :----------- | :---------------------------------------------------------------------------------------------------------------------------------------------- | -| elem\\_size | size of a single element | -| elem\\_count | number of valid elements | -| byte\\_alloc | number of allocated bytes or -(number of viewed bytes + 1) if this is a view: the "+ 1" distinguishes an array of size 0 from a view of size 0 | -| array | linear array to store elements | +| Field | Note | +|:------------ |:---------------------------------------------------------------------------------------------------------------------------------------------- | +| elem\\_size | size of a single element | +| elem\\_count | number of valid elements | +| byte\\_alloc | number of allocated bytes or -(number of viewed bytes + 1) if this is a view: the "+ 1" distinguishes an array of size 0 from a view of size 0 | +| array | linear array to store elements | """ struct sc_array elem_size::Csize_t @@ -181,7 +215,9 @@ struct sc_array array::Ptr{Int8} end -"""The [`sc_array`](@ref) object provides a dynamic array of equal-size elements. Elements are accessed by their 0-based index. Their address may change. The number of elements (== elem\\_count) of the array can be changed by sc_array_resize and sc_array_rewind. Elements can be sorted with sc_array_sort. If the array is sorted, it can be searched with sc_array_bsearch. A priority queue is implemented with pqueue\\_add and pqueue\\_pop (untested).""" +""" +The [`sc_array`](@ref) object provides a dynamic array of equal-size elements. Elements are accessed by their 0-based index. Their address may change. The number of elements (== elem\\_count) of the array can be changed by sc_array_resize and sc_array_rewind. Elements can be sorted with sc_array_sort. If the array is sorted, it can be searched with sc_array_bsearch. A priority queue is implemented with pqueue\\_add and pqueue\\_pop (untested). +""" const sc_array_t = sc_array """ @@ -190,23 +226,32 @@ const sc_array_t = sc_array Creates a new array structure with a given length (number of elements). ### Parameters -* `elem_size`:\\[in\\] Size of one array element in bytes. -* `elem_count`:\\[in\\] Initial number of array elements. + + - `elem_size`:\\[in\\] Size of one array element in bytes. + - `elem_count`:\\[in\\] Initial number of array elements. + ### Returns + Return an allocated array with allocated but uninitialized elements. + ### Prototype + ```c sc_array_t *sc_array_new_count (size_t elem_size, size_t elem_count); ``` """ function sc_array_new_count(elem_size, elem_count) - @ccall libsc.sc_array_new_count(elem_size::Csize_t, elem_count::Csize_t)::Ptr{sc_array_t} + @ccall libsc.sc_array_new_count( + elem_size::Csize_t, + elem_count::Csize_t, + )::Ptr{sc_array_t} end """ sc_int32_compare(v1, v2) ### Prototype + ```c int sc_int32_compare (const void *v1, const void *v2); ``` @@ -215,19 +260,26 @@ function sc_int32_compare(v1, v2) @ccall libsc.sc_int32_compare(v1::Ptr{Cvoid}, v2::Ptr{Cvoid})::Cint end -"""Typedef for quadrant coordinates.""" +""" +Typedef for quadrant coordinates. +""" const p4est_qcoord_t = Int32 -"""Typedef for counting topological entities (trees, tree vertices).""" +""" +Typedef for counting topological entities (trees, tree vertices). +""" const p4est_topidx_t = Int32 -"""Typedef for processor-local indexing of quadrants and nodes.""" +""" +Typedef for processor-local indexing of quadrants and nodes. +""" const p4est_locidx_t = Int32 """ sc_int64_compare(v1, v2) ### Prototype + ```c int sc_int64_compare (const void *v1, const void *v2); ``` @@ -236,11 +288,13 @@ function sc_int64_compare(v1, v2) @ccall libsc.sc_int64_compare(v1::Ptr{Cvoid}, v2::Ptr{Cvoid})::Cint end -"""Typedef for globally unique indexing of quadrants.""" +""" +Typedef for globally unique indexing of quadrants. +""" const p4est_gloidx_t = Int64 struct p4est_quadrant_data - data::NTuple{8, UInt8} + data::NTuple{8,UInt8} end function Base.getproperty(x::Ptr{p4est_quadrant_data}, f::Symbol) @@ -270,17 +324,17 @@ end The 2D quadrant datatype -| Field | Note | -| :---- | :------------------------------------------------- | -| x | coordinates | -| y | | -| level | level of refinement | -| pad8 | padding | -| pad16 | | -| p | a union of additional data attached to a quadrant | +| Field | Note | +|:----- |:------------------------------------------------- | +| x | coordinates | +| y | | +| level | level of refinement | +| pad8 | padding | +| pad16 | | +| p | a union of additional data attached to a quadrant | """ struct p4est_quadrant - data::NTuple{24, UInt8} + data::NTuple{24,UInt8} end function Base.getproperty(x::Ptr{p4est_quadrant}, f::Symbol) @@ -304,7 +358,9 @@ function Base.setproperty!(x::Ptr{p4est_quadrant}, f::Symbol, v) unsafe_store!(getproperty(x, f), v) end -"""The 2D quadrant datatype""" +""" +The 2D quadrant datatype +""" const p4est_quadrant_t = p4est_quadrant @cenum sc_tag_t::UInt32 begin @@ -335,6 +391,7 @@ end sc_mpi_sizeof(t) ### Prototype + ```c size_t sc_mpi_sizeof (sc_MPI_Datatype t); ``` @@ -347,18 +404,23 @@ end sc_mpi_comm_attach_node_comms(comm, processes_per_node) ### Prototype + ```c void sc_mpi_comm_attach_node_comms (sc_MPI_Comm comm, int processes_per_node); ``` """ function sc_mpi_comm_attach_node_comms(comm, processes_per_node) - @ccall libsc.sc_mpi_comm_attach_node_comms(comm::MPI_Comm, processes_per_node::Cint)::Cvoid + @ccall libsc.sc_mpi_comm_attach_node_comms( + comm::MPI_Comm, + processes_per_node::Cint, + )::Cvoid end """ sc_mpi_comm_detach_node_comms(comm) ### Prototype + ```c void sc_mpi_comm_detach_node_comms (sc_MPI_Comm comm); ``` @@ -371,18 +433,24 @@ end sc_mpi_comm_get_node_comms(comm, intranode, internode) ### Prototype + ```c void sc_mpi_comm_get_node_comms (sc_MPI_Comm comm, sc_MPI_Comm * intranode, sc_MPI_Comm * internode); ``` """ function sc_mpi_comm_get_node_comms(comm, intranode, internode) - @ccall libsc.sc_mpi_comm_get_node_comms(comm::MPI_Comm, intranode::Ptr{MPI_Comm}, internode::Ptr{MPI_Comm})::Cvoid + @ccall libsc.sc_mpi_comm_get_node_comms( + comm::MPI_Comm, + intranode::Ptr{MPI_Comm}, + internode::Ptr{MPI_Comm}, + )::Cvoid end """ sc_mpi_comm_get_and_attach(comm) ### Prototype + ```c int sc_mpi_comm_get_and_attach (sc_MPI_Comm comm); ``` @@ -404,6 +472,7 @@ const sc_abort_handler_t = Ptr{Cvoid} sc_memory_status(package) ### Prototype + ```c int sc_memory_status (int package); ``` @@ -416,6 +485,7 @@ end sc_memory_check(package) ### Prototype + ```c void sc_memory_check (int package); ``` @@ -430,6 +500,7 @@ end Return error count or zero if all is ok. ### Prototype + ```c int sc_memory_check_noerr (int package); ``` @@ -442,6 +513,7 @@ end sc_int_compare(v1, v2) ### Prototype + ```c int sc_int_compare (const void *v1, const void *v2); ``` @@ -454,6 +526,7 @@ end sc_int8_compare(v1, v2) ### Prototype + ```c int sc_int8_compare (const void *v1, const void *v2); ``` @@ -466,6 +539,7 @@ end sc_int16_compare(v1, v2) ### Prototype + ```c int sc_int16_compare (const void *v1, const void *v2); ``` @@ -478,6 +552,7 @@ end sc_double_compare(v1, v2) ### Prototype + ```c int sc_double_compare (const void *v1, const void *v2); ``` @@ -492,10 +567,15 @@ end Safe version of the standard library atoi (3) function. ### Parameters -* `nptr`:\\[in\\] NUL-terminated string. + + - `nptr`:\\[in\\] NUL-terminated string. + ### Returns + Converted integer value. 0 if no valid number. INT\\_MAX on overflow, INT\\_MIN on underflow. + ### Prototype + ```c int sc_atoi (const char *nptr); ``` @@ -510,10 +590,15 @@ end Safe version of the standard library atol (3) function. ### Parameters -* `nptr`:\\[in\\] NUL-terminated string. + + - `nptr`:\\[in\\] NUL-terminated string. + ### Returns + Converted long value. 0 if no valid number. LONG\\_MAX on overflow, LONG\\_MIN on underflow. + ### Prototype + ```c long sc_atol (const char *nptr); ``` @@ -528,16 +613,23 @@ end Controls the default SC log behavior. ### Parameters -* `log_stream`:\\[in\\] Set stream to use by `sc_logf` (or NULL for stdout). -* `log_handler`:\\[in\\] Set default SC log handler (NULL selects builtin). -* `log_threshold`:\\[in\\] Set default SC log threshold (or `SC_LP_DEFAULT`). May be `SC_LP_ALWAYS` or `SC_LP_SILENT`. + + - `log_stream`:\\[in\\] Set stream to use by `sc_logf` (or NULL for stdout). + - `log_handler`:\\[in\\] Set default SC log handler (NULL selects builtin). + - `log_threshold`:\\[in\\] Set default SC log threshold (or `SC_LP_DEFAULT`). May be `SC_LP_ALWAYS` or `SC_LP_SILENT`. + ### Prototype + ```c void sc_set_log_defaults (FILE * log_stream, sc_log_handler_t log_handler, int log_thresold); ``` """ function sc_set_log_defaults(log_stream, log_handler, log_thresold) - @ccall libsc.sc_set_log_defaults(log_stream::Ptr{Libc.FILE}, log_handler::sc_log_handler_t, log_thresold::Cint)::Cvoid + @ccall libsc.sc_set_log_defaults( + log_stream::Ptr{Libc.FILE}, + log_handler::sc_log_handler_t, + log_thresold::Cint, + )::Cvoid end """ @@ -546,8 +638,11 @@ end Controls the default SC abort behavior. ### Parameters -* `abort_handler`:\\[in\\] Set default SC above handler (NULL selects builtin). ***This function should not return!*** + + - `abort_handler`:\\[in\\] Set default SC above handler (NULL selects builtin). ***This function should not return!*** + ### Prototype + ```c void sc_set_abort_handler (sc_abort_handler_t abort_handler); ``` @@ -562,6 +657,7 @@ end Add spaces to the start of a package's default log format. ### Prototype + ```c void sc_log_indent_push_count (int package, int count); ``` @@ -576,6 +672,7 @@ end Remove spaces from the start of a package's default log format. ### Prototype + ```c void sc_log_indent_pop_count (int package, int count); ``` @@ -590,6 +687,7 @@ end Add one space to the start of sc's default log format. ### Prototype + ```c void sc_log_indent_push (void); ``` @@ -604,6 +702,7 @@ end Remove one space from the start of a sc's default log format. ### Prototype + ```c void sc_log_indent_pop (void); ``` @@ -618,6 +717,7 @@ end Print a stack trace, call the abort handler and then call abort (). ### Prototype + ```c void sc_abort (void) __attribute__ ((noreturn)); ``` @@ -632,6 +732,7 @@ end Collective abort where only root prints a message ### Prototype + ```c void sc_abort_collective (const char *msg) __attribute__ ((noreturn)); ``` @@ -646,14 +747,22 @@ end Register a software package with SC. This function must only be called before additional threads are created. The logging parameters are as in [`sc_set_log_defaults`](@ref). ### Returns + Returns a unique package id. + ### Prototype + ```c int sc_package_register (sc_log_handler_t log_handler, int log_threshold, const char *name, const char *full); ``` """ function sc_package_register(log_handler, log_threshold, name, full) - @ccall libsc.sc_package_register(log_handler::sc_log_handler_t, log_threshold::Cint, name::Cstring, full::Cstring)::Cint + @ccall libsc.sc_package_register( + log_handler::sc_log_handler_t, + log_threshold::Cint, + name::Cstring, + full::Cstring, + )::Cint end """ @@ -662,10 +771,15 @@ end Query whether an identifier matches a registered package. ### Parameters -* `package_id`:\\[in\\] Only a non-negative id can be registered. + + - `package_id`:\\[in\\] Only a non-negative id can be registered. + ### Returns + True if and only if the package id is non-negative and package is registered. + ### Prototype + ```c int sc_package_is_registered (int package_id); ``` @@ -680,8 +794,11 @@ end Acquire a pthread mutex lock. If configured without --enable-pthread, this function does nothing. This function must be followed with a matching sc_package_unlock. ### Parameters -* `package_id`:\\[in\\] Either -1 for an undefined package or an id returned from sc_package_register. Depending on the value, the appropriate mutex is chosen. Thus, we may overlap locking calls with distinct package\\_id. + + - `package_id`:\\[in\\] Either -1 for an undefined package or an id returned from sc_package_register. Depending on the value, the appropriate mutex is chosen. Thus, we may overlap locking calls with distinct package\\_id. + ### Prototype + ```c void sc_package_lock (int package_id); ``` @@ -696,8 +813,11 @@ end Release a pthread mutex lock. If configured without --enable-pthread, this function does nothing. This function must be follow a matching sc_package_lock. ### Parameters -* `package_id`:\\[in\\] Either -1 for an undefined package or an id returned from sc_package_register. Depending on the value, the appropriate mutex is chosen. Thus, we may overlap locking calls with distinct package\\_id. + + - `package_id`:\\[in\\] Either -1 for an undefined package or an id returned from sc_package_register. Depending on the value, the appropriate mutex is chosen. Thus, we may overlap locking calls with distinct package\\_id. + ### Prototype + ```c void sc_package_unlock (int package_id); ``` @@ -712,8 +832,11 @@ end Set the logging verbosity of a registered package. This can be called at any point in the program, any number of times. It can only lower the verbosity at and below the value of `SC_LP_THRESHOLD`. ### Parameters -* `package_id`:\\[in\\] Must be a registered package identifier. + + - `package_id`:\\[in\\] Must be a registered package identifier. + ### Prototype + ```c void sc_package_set_verbosity (int package_id, int log_priority); ``` @@ -728,15 +851,21 @@ end Set the unregister behavior of [`sc_package_unregister`](@ref)(). ### Parameters -* `package_id`:\\[in\\] Must be -1 for the default package or the identifier of a registered package. -* `set_abort`:\\[in\\] True if [`sc_package_unregister`](@ref)() should abort if the number of allocs does not match the number of frees; false otherwise. + + - `package_id`:\\[in\\] Must be -1 for the default package or the identifier of a registered package. + - `set_abort`:\\[in\\] True if [`sc_package_unregister`](@ref)() should abort if the number of allocs does not match the number of frees; false otherwise. + ### Prototype + ```c void sc_package_set_abort_alloc_mismatch (int package_id, int set_abort); ``` """ function sc_package_set_abort_alloc_mismatch(package_id, set_abort) - @ccall libsc.sc_package_set_abort_alloc_mismatch(package_id::Cint, set_abort::Cint)::Cvoid + @ccall libsc.sc_package_set_abort_alloc_mismatch( + package_id::Cint, + set_abort::Cint, + )::Cvoid end """ @@ -745,6 +874,7 @@ end Unregister a software package with SC. This function must only be called after additional threads are finished. ### Prototype + ```c void sc_package_unregister (int package_id); ``` @@ -759,8 +889,11 @@ end Print a summary of all packages registered with SC. Uses the `SC_LC_GLOBAL` log category which by default only prints on rank 0. ### Parameters -* `log_priority`:\\[in\\] Priority passed to sc log functions. + + - `log_priority`:\\[in\\] Priority passed to sc log functions. + ### Prototype + ```c void sc_package_print_summary (int log_priority); ``` @@ -773,12 +906,19 @@ end sc_init(mpicomm, catch_signals, print_backtrace, log_handler, log_threshold) ### Prototype + ```c void sc_init (sc_MPI_Comm mpicomm, int catch_signals, int print_backtrace, sc_log_handler_t log_handler, int log_threshold); ``` """ function sc_init(mpicomm, catch_signals, print_backtrace, log_handler, log_threshold) - @ccall libsc.sc_init(mpicomm::MPI_Comm, catch_signals::Cint, print_backtrace::Cint, log_handler::sc_log_handler_t, log_threshold::Cint)::Cvoid + @ccall libsc.sc_init( + mpicomm::MPI_Comm, + catch_signals::Cint, + print_backtrace::Cint, + log_handler::sc_log_handler_t, + log_threshold::Cint, + )::Cvoid end """ @@ -787,6 +927,7 @@ end Unregisters all packages, runs the memory check, removes the signal handlers and resets sc\\_identifier and sc\\_root\\_*. This function aborts on any inconsistency found unless the global variable default\\_abort\\_mismatch is false. This function is optional. This function does not require [`sc_init`](@ref) to be called first. ### Prototype + ```c void sc_finalize (void); ``` @@ -801,8 +942,11 @@ end Unregisters all packages, runs the memory check, removes the signal handlers and resets sc\\_identifier and sc\\_root\\_*. This function never aborts but returns the number of errors encountered. This function is optional. This function does not require [`sc_init`](@ref) to be called first. ### Returns + 0 when everything is consistent, nonzero otherwise. + ### Prototype + ```c int sc_finalize_noabort (void); ``` @@ -817,8 +961,11 @@ end Identify the root process. Only meaningful between [`sc_init`](@ref) and [`sc_finalize`](@ref) and with a communicator that is not `sc_MPI_COMM_NULL` (otherwise always true). ### Returns + Return true for the root process and false otherwise. + ### Prototype + ```c int sc_is_root (void); ``` @@ -833,12 +980,17 @@ end Provide a string copy function. ### Parameters -* `dest`:\\[out\\] Buffer of length at least *size*. On output, not touched if NULL or *size* == 0. -* `size`:\\[in\\] Allocation length of *dest*. -* `src`:\\[in\\] Null-terminated string. + + - `dest`:\\[out\\] Buffer of length at least *size*. On output, not touched if NULL or *size* == 0. + - `size`:\\[in\\] Allocation length of *dest*. + - `src`:\\[in\\] Null-terminated string. + ### Returns + Equivalent to sc_snprintf (dest, size, "s", src). + ### Prototype + ```c void sc_strcopy (char *dest, size_t size, const char *src); ``` @@ -849,8 +1001,15 @@ end # automatic type deduction for variadic arguments may not be what you want, please use with caution @generated function sc_snprintf(str, size, format, va_list...) - :(@ccall(libsc.sc_snprintf(str::Cstring, size::Csize_t, format::Cstring; $(to_c_type_pairs(va_list)...))::Cvoid)) - end + :(@ccall( + libsc.sc_snprintf( + str::Cstring, + size::Csize_t, + format::Cstring; + $(to_c_type_pairs(va_list)...), + )::Cvoid + )) +end """ sc_version() @@ -858,8 +1017,11 @@ end Return the full version of libsc. ### Returns + Return the version of libsc using the format `VERSION\\_MAJOR.VERSION\\_MINOR.VERSION\\_POINT`, where `VERSION_POINT` can contain dots and characters, e.g. to indicate the additional number of commits and a git commit hash. + ### Prototype + ```c const char *sc_version (void); ``` @@ -874,8 +1036,11 @@ end Return the major version of libsc. ### Returns + Return the major version of libsc. + ### Prototype + ```c int sc_version_major (void); ``` @@ -890,8 +1055,11 @@ end Return the minor version of libsc. ### Returns + Return the minor version of libsc. + ### Prototype + ```c int sc_version_minor (void); ``` @@ -905,9 +1073,12 @@ end Function to compute a hash value of an object. ### Parameters -* `v`:\\[in\\] The object to hash. -* `u`:\\[in\\] Arbitrary user data. + + - `v`:\\[in\\] The object to hash. + - `u`:\\[in\\] Arbitrary user data. + ### Returns + Returns an unsigned integer. """ const sc_hash_function_t = Ptr{Cvoid} @@ -917,8 +1088,11 @@ const sc_hash_function_t = Ptr{Cvoid} Function to check equality of two objects. ### Parameters -* `u`:\\[in\\] Arbitrary user data. + + - `u`:\\[in\\] Arbitrary user data. + ### Returns + Returns false if *v1 is unequal *v2 and true otherwise. """ const sc_equal_function_t = Ptr{Cvoid} @@ -928,9 +1102,12 @@ const sc_equal_function_t = Ptr{Cvoid} Function to call on every data item of a hash table. ### Parameters -* `v`:\\[in\\] The address of the pointer to the current object. -* `u`:\\[in\\] Arbitrary user data. + + - `v`:\\[in\\] The address of the pointer to the current object. + - `u`:\\[in\\] Arbitrary user data. + ### Returns + Return true if the traversal should continue, false to stop. """ const sc_hash_foreach_t = Ptr{Cvoid} @@ -941,11 +1118,16 @@ const sc_hash_foreach_t = Ptr{Cvoid} Calculate the memory used by an array. ### Parameters -* `array`:\\[in\\] The array. -* `is_dynamic`:\\[in\\] True if created with [`sc_array_new`](@ref), false if initialized with [`sc_array_init`](@ref) + + - `array`:\\[in\\] The array. + - `is_dynamic`:\\[in\\] True if created with [`sc_array_new`](@ref), false if initialized with [`sc_array_init`](@ref) + ### Returns + Memory used in bytes. + ### Prototype + ```c size_t sc_array_memory_used (sc_array_t * array, int is_dynamic); ``` @@ -960,10 +1142,15 @@ end Creates a new array structure with 0 elements. ### Parameters -* `elem_size`:\\[in\\] Size of one array element in bytes. + + - `elem_size`:\\[in\\] Size of one array element in bytes. + ### Returns + Return an allocated array of zero length. + ### Prototype + ```c sc_array_t *sc_array_new (size_t elem_size); ``` @@ -978,16 +1165,23 @@ end Creates a new view of an existing [`sc_array_t`](@ref). ### Parameters -* `array`:\\[in\\] The array must not be resized while view is alive. -* `offset`:\\[in\\] The offset of the viewed section in element units. This offset cannot be changed until the view is reset. -* `length`:\\[in\\] The length of the viewed section in element units. The view cannot be resized to exceed this length. + + - `array`:\\[in\\] The array must not be resized while view is alive. + - `offset`:\\[in\\] The offset of the viewed section in element units. This offset cannot be changed until the view is reset. + - `length`:\\[in\\] The length of the viewed section in element units. The view cannot be resized to exceed this length. + ### Prototype + ```c sc_array_t *sc_array_new_view (sc_array_t * array, size_t offset, size_t length); ``` """ function sc_array_new_view(array, offset, length) - @ccall libsc.sc_array_new_view(array::Ptr{sc_array_t}, offset::Csize_t, length::Csize_t)::Ptr{sc_array_t} + @ccall libsc.sc_array_new_view( + array::Ptr{sc_array_t}, + offset::Csize_t, + length::Csize_t, + )::Ptr{sc_array_t} end """ @@ -996,16 +1190,23 @@ end Creates a new view of an existing plain C array. ### Parameters -* `base`:\\[in\\] The data must not be moved while view is alive. -* `elem_size`:\\[in\\] Size of one array element in bytes. -* `elem_count`:\\[in\\] The length of the view in element units. The view cannot be resized to exceed this length. + + - `base`:\\[in\\] The data must not be moved while view is alive. + - `elem_size`:\\[in\\] Size of one array element in bytes. + - `elem_count`:\\[in\\] The length of the view in element units. The view cannot be resized to exceed this length. + ### Prototype + ```c sc_array_t *sc_array_new_data (void *base, size_t elem_size, size_t elem_count); ``` """ function sc_array_new_data(base, elem_size, elem_count) - @ccall libsc.sc_array_new_data(base::Ptr{Cvoid}, elem_size::Csize_t, elem_count::Csize_t)::Ptr{sc_array_t} + @ccall libsc.sc_array_new_data( + base::Ptr{Cvoid}, + elem_size::Csize_t, + elem_count::Csize_t, + )::Ptr{sc_array_t} end """ @@ -1014,8 +1215,11 @@ end Destroys an array structure. ### Parameters -* `array`:\\[in\\] The array to be destroyed. + + - `array`:\\[in\\] The array to be destroyed. + ### Prototype + ```c void sc_array_destroy (sc_array_t * array); ``` @@ -1030,8 +1234,11 @@ end Destroys an array structure and sets the pointer to NULL. ### Parameters -* `parray`:\\[in,out\\] Pointer to address of array to be destroyed. On output, *parray is NULL. + + - `parray`:\\[in,out\\] Pointer to address of array to be destroyed. On output, *parray is NULL. + ### Prototype + ```c void sc_array_destroy_null (sc_array_t ** parray); ``` @@ -1046,9 +1253,12 @@ end Initializes an already allocated (or static) array structure. ### Parameters -* `array`:\\[in,out\\] Array structure to be initialized. -* `elem_size`:\\[in\\] Size of one array element in bytes. + + - `array`:\\[in,out\\] Array structure to be initialized. + - `elem_size`:\\[in\\] Size of one array element in bytes. + ### Prototype + ```c void sc_array_init (sc_array_t * array, size_t elem_size); ``` @@ -1063,16 +1273,23 @@ end Initializes an already allocated (or static) array structure and allocates a given number of elements. Deprecated: use sc_array_init_count. ### Parameters -* `array`:\\[in,out\\] Array structure to be initialized. -* `elem_size`:\\[in\\] Size of one array element in bytes. -* `elem_count`:\\[in\\] Number of initial array elements. + + - `array`:\\[in,out\\] Array structure to be initialized. + - `elem_size`:\\[in\\] Size of one array element in bytes. + - `elem_count`:\\[in\\] Number of initial array elements. + ### Prototype + ```c void sc_array_init_size (sc_array_t * array, size_t elem_size, size_t elem_count); ``` """ function sc_array_init_size(array, elem_size, elem_count) - @ccall libsc.sc_array_init_size(array::Ptr{sc_array_t}, elem_size::Csize_t, elem_count::Csize_t)::Cvoid + @ccall libsc.sc_array_init_size( + array::Ptr{sc_array_t}, + elem_size::Csize_t, + elem_count::Csize_t, + )::Cvoid end """ @@ -1081,16 +1298,23 @@ end Initializes an already allocated (or static) array structure and allocates a given number of elements. This function supersedes sc_array_init_size. ### Parameters -* `array`:\\[in,out\\] Array structure to be initialized. -* `elem_size`:\\[in\\] Size of one array element in bytes. -* `elem_count`:\\[in\\] Number of initial array elements. + + - `array`:\\[in,out\\] Array structure to be initialized. + - `elem_size`:\\[in\\] Size of one array element in bytes. + - `elem_count`:\\[in\\] Number of initial array elements. + ### Prototype + ```c void sc_array_init_count (sc_array_t * array, size_t elem_size, size_t elem_count); ``` """ function sc_array_init_count(array, elem_size, elem_count) - @ccall libsc.sc_array_init_count(array::Ptr{sc_array_t}, elem_size::Csize_t, elem_count::Csize_t)::Cvoid + @ccall libsc.sc_array_init_count( + array::Ptr{sc_array_t}, + elem_size::Csize_t, + elem_count::Csize_t, + )::Cvoid end """ @@ -1099,17 +1323,25 @@ end Initializes an already allocated (or static) view from existing [`sc_array_t`](@ref). The array view returned does not require [`sc_array_reset`](@ref) (doesn't hurt though). ### Parameters -* `view`:\\[in,out\\] Array structure to be initialized. -* `array`:\\[in\\] The array must not be resized while view is alive. -* `offset`:\\[in\\] The offset of the viewed section in element units. This offset cannot be changed until the view is reset. -* `length`:\\[in\\] The length of the view in element units. The view cannot be resized to exceed this length. It is not necessary to call [`sc_array_reset`](@ref) later. + + - `view`:\\[in,out\\] Array structure to be initialized. + - `array`:\\[in\\] The array must not be resized while view is alive. + - `offset`:\\[in\\] The offset of the viewed section in element units. This offset cannot be changed until the view is reset. + - `length`:\\[in\\] The length of the view in element units. The view cannot be resized to exceed this length. It is not necessary to call [`sc_array_reset`](@ref) later. + ### Prototype + ```c void sc_array_init_view (sc_array_t * view, sc_array_t * array, size_t offset, size_t length); ``` """ function sc_array_init_view(view, array, offset, length) - @ccall libsc.sc_array_init_view(view::Ptr{sc_array_t}, array::Ptr{sc_array_t}, offset::Csize_t, length::Csize_t)::Cvoid + @ccall libsc.sc_array_init_view( + view::Ptr{sc_array_t}, + array::Ptr{sc_array_t}, + offset::Csize_t, + length::Csize_t, + )::Cvoid end """ @@ -1118,17 +1350,25 @@ end Initializes an already allocated (or static) view from given plain C data. The array view returned does not require [`sc_array_reset`](@ref) (doesn't hurt though). ### Parameters -* `view`:\\[in,out\\] Array structure to be initialized. -* `base`:\\[in\\] The data must not be moved while view is alive. -* `elem_size`:\\[in\\] Size of one array element in bytes. -* `elem_count`:\\[in\\] The length of the view in element units. The view cannot be resized to exceed this length. It is not necessary to call [`sc_array_reset`](@ref) later. + + - `view`:\\[in,out\\] Array structure to be initialized. + - `base`:\\[in\\] The data must not be moved while view is alive. + - `elem_size`:\\[in\\] Size of one array element in bytes. + - `elem_count`:\\[in\\] The length of the view in element units. The view cannot be resized to exceed this length. It is not necessary to call [`sc_array_reset`](@ref) later. + ### Prototype + ```c void sc_array_init_data (sc_array_t * view, void *base, size_t elem_size, size_t elem_count); ``` """ function sc_array_init_data(view, base, elem_size, elem_count) - @ccall libsc.sc_array_init_data(view::Ptr{sc_array_t}, base::Ptr{Cvoid}, elem_size::Csize_t, elem_count::Csize_t)::Cvoid + @ccall libsc.sc_array_init_data( + view::Ptr{sc_array_t}, + base::Ptr{Cvoid}, + elem_size::Csize_t, + elem_count::Csize_t, + )::Cvoid end """ @@ -1137,9 +1377,12 @@ end Run memset on the array storage. We pass the character to memset unchanged. Thus, care must be taken when setting values below -1 or above 127, just as with standard memset (3). ### Parameters -* `array`:\\[in,out\\] This array's storage will be overwritten. -* `c`:\\[in\\] Character to overwrite every byte with. + + - `array`:\\[in,out\\] This array's storage will be overwritten. + - `c`:\\[in\\] Character to overwrite every byte with. + ### Prototype + ```c void sc_array_memset (sc_array_t * array, int c); ``` @@ -1158,8 +1401,11 @@ Sets the array count to zero and frees all elements. This function turns a view Calling [`sc_array_init`](@ref), then any array operations, then [`sc_array_reset`](@ref) is memory neutral. As an exception, the two functions [`sc_array_init_view`](@ref) and [`sc_array_init_data`](@ref) do not require a subsequent call to [`sc_array_reset`](@ref). Regardless, it is legal to call [`sc_array_reset`](@ref) anyway. ### Parameters -* `array`:\\[in,out\\] Array structure to be reset. + + - `array`:\\[in,out\\] Array structure to be reset. + ### Prototype + ```c void sc_array_reset (sc_array_t * array); ``` @@ -1178,8 +1424,11 @@ Sets the array count to zero, but does not free elements. Not allowed for views. This is intended to allow an [`sc_array`](@ref) to be used as a reusable buffer, where the "high water mark" of the buffer is preserved, so that O(log (max n)) reallocs occur over the life of the buffer. ### Parameters -* `array`:\\[in,out\\] Array structure to be truncated. + + - `array`:\\[in,out\\] Array structure to be truncated. + ### Prototype + ```c void sc_array_truncate (sc_array_t * array); ``` @@ -1194,9 +1443,12 @@ end Shorten an array without reallocating it. ### Parameters -* `array`:\\[in,out\\] The element count of this array is modified. -* `new_count`:\\[in\\] Must be less or equal than the **array**'s count. If it is less, the number of elements in the array is reduced without reallocating memory. The exception is a **new_count** of zero specified for an array that is not a view: In this case sc_array_reset is equivalent. + + - `array`:\\[in,out\\] The element count of this array is modified. + - `new_count`:\\[in\\] Must be less or equal than the **array**'s count. If it is less, the number of elements in the array is reduced without reallocating memory. The exception is a **new_count** of zero specified for an array that is not a view: In this case sc_array_reset is equivalent. + ### Prototype + ```c void sc_array_rewind (sc_array_t * array, size_t new_count); ``` @@ -1211,9 +1463,12 @@ end Sets the element count to new\\_count. If the array is not a view, reallocation takes place occasionally. If the array is a view, new\\_count must not be greater than the element count of the view when it was created. The original offset of the view cannot be changed. ### Parameters -* `array`:\\[in,out\\] The element count and address is modified. -* `new_count`:\\[in\\] New element count of the array. If it is zero and the array is not a view, the effect equals sc_array_reset. + + - `array`:\\[in,out\\] The element count and address is modified. + - `new_count`:\\[in\\] New element count of the array. If it is zero and the array is not a view, the effect equals sc_array_reset. + ### Prototype + ```c void sc_array_resize (sc_array_t * array, size_t new_count); ``` @@ -1228,9 +1483,12 @@ end Copy the contents of one array into another. Both arrays must have equal element sizes. The source array may be a view. We use memcpy (3): If the two arrays overlap, results are undefined. ### Parameters -* `dest`:\\[in\\] Array (not a view) will be resized and get new data. -* `src`:\\[in\\] Array used as source of new data, will not be changed. + + - `dest`:\\[in\\] Array (not a view) will be resized and get new data. + - `src`:\\[in\\] Array used as source of new data, will not be changed. + ### Prototype + ```c void sc_array_copy (sc_array_t * dest, sc_array_t * src); ``` @@ -1245,16 +1503,23 @@ end Copy the contents of one array into some portion of another. Both arrays must have equal element sizes. Either array may be a view. The destination array must be large enough. We use memcpy (3): If the two arrays overlap, results are undefined. ### Parameters -* `dest`:\\[in\\] Array will be written into. Its element count must be at least **dest_offset** + **src**->elem_count. -* `dest_offset`:\\[in\\] First index in **dest** array to be overwritten. As every index, it refers to elements, not bytes. -* `src`:\\[in\\] Array used as source of new data, will not be changed. + + - `dest`:\\[in\\] Array will be written into. Its element count must be at least **dest_offset** + **src**->elem_count. + - `dest_offset`:\\[in\\] First index in **dest** array to be overwritten. As every index, it refers to elements, not bytes. + - `src`:\\[in\\] Array used as source of new data, will not be changed. + ### Prototype + ```c void sc_array_copy_into (sc_array_t * dest, size_t dest_offset, sc_array_t * src); ``` """ function sc_array_copy_into(dest, dest_offset, src) - @ccall libsc.sc_array_copy_into(dest::Ptr{sc_array_t}, dest_offset::Csize_t, src::Ptr{sc_array_t})::Cvoid + @ccall libsc.sc_array_copy_into( + dest::Ptr{sc_array_t}, + dest_offset::Csize_t, + src::Ptr{sc_array_t}, + )::Cvoid end """ @@ -1263,18 +1528,27 @@ end Copy part of one array into another using memmove (3). Both arrays must have equal element sizes. Either array may be a view. The destination array must be large enough. We use memmove (3): The two arrays may overlap. ### Parameters -* `dest`:\\[in\\] Array will be written into. Its element count must be at least **dest_offset** + **count**. -* `dest_offset`:\\[in\\] First index in **dest** array to be overwritten. As every index, it refers to elements, not bytes. -* `src`:\\[in\\] Array will be read from. Its element count must be at least **src_offset** + **count**. -* `src_offset`:\\[in\\] First index in **src** array to be used. As every index, it refers to elements, not bytes. -* `count`:\\[in\\] Number of entries copied. + + - `dest`:\\[in\\] Array will be written into. Its element count must be at least **dest_offset** + **count**. + - `dest_offset`:\\[in\\] First index in **dest** array to be overwritten. As every index, it refers to elements, not bytes. + - `src`:\\[in\\] Array will be read from. Its element count must be at least **src_offset** + **count**. + - `src_offset`:\\[in\\] First index in **src** array to be used. As every index, it refers to elements, not bytes. + - `count`:\\[in\\] Number of entries copied. + ### Prototype + ```c void sc_array_move_part (sc_array_t * dest, size_t dest_offset, sc_array_t * src, size_t src_offset, size_t count); ``` """ function sc_array_move_part(dest, dest_offset, src, src_offset, count) - @ccall libsc.sc_array_move_part(dest::Ptr{sc_array_t}, dest_offset::Csize_t, src::Ptr{sc_array_t}, src_offset::Csize_t, count::Csize_t)::Cvoid + @ccall libsc.sc_array_move_part( + dest::Ptr{sc_array_t}, + dest_offset::Csize_t, + src::Ptr{sc_array_t}, + src_offset::Csize_t, + count::Csize_t, + )::Cvoid end """ @@ -1283,9 +1557,12 @@ end Sorts the array in ascending order wrt. the comparison function. ### Parameters -* `array`:\\[in\\] The array to sort. -* `compar`:\\[in\\] The comparison function to be used. + + - `array`:\\[in\\] The array to sort. + - `compar`:\\[in\\] The comparison function to be used. + ### Prototype + ```c void sc_array_sort (sc_array_t * array, int (*compar) (const void *, const void *)); ``` @@ -1300,11 +1577,16 @@ end Check whether the array is sorted wrt. the comparison function. ### Parameters -* `array`:\\[in\\] The array to check. -* `compar`:\\[in\\] The comparison function to be used. + + - `array`:\\[in\\] The array to check. + - `compar`:\\[in\\] The comparison function to be used. + ### Returns + True if array is sorted, false otherwise. + ### Prototype + ```c int sc_array_is_sorted (sc_array_t * array, int (*compar) (const void *, const void *)); ``` @@ -1319,11 +1601,16 @@ end Check whether two arrays have equal size, count, and content. Either array may be a view. Both arrays will not be changed. ### Parameters -* `array`:\\[in\\] One array to be compared. -* `other`:\\[in\\] A second array to be compared. + + - `array`:\\[in\\] One array to be compared. + - `other`:\\[in\\] A second array to be compared. + ### Returns + True if array and other are equal, false otherwise. + ### Prototype + ```c int sc_array_is_equal (sc_array_t * array, sc_array_t * other); ``` @@ -1338,9 +1625,12 @@ end Removed duplicate entries from a sorted array. This function is not allowed for views. ### Parameters -* `array`:\\[in,out\\] The array size will be reduced as necessary. -* `compar`:\\[in\\] The comparison function to be used. + + - `array`:\\[in,out\\] The array size will be reduced as necessary. + - `compar`:\\[in\\] The comparison function to be used. + ### Prototype + ```c void sc_array_uniq (sc_array_t * array, int (*compar) (const void *, const void *)); ``` @@ -1355,18 +1645,27 @@ end Performs a binary search on an array. The array must be sorted. ### Parameters -* `array`:\\[in\\] A sorted array to search in. -* `key`:\\[in\\] An element to be searched for. -* `compar`:\\[in\\] The comparison function to be used. + + - `array`:\\[in\\] A sorted array to search in. + - `key`:\\[in\\] An element to be searched for. + - `compar`:\\[in\\] The comparison function to be used. + ### Returns + Returns the index into array for the item found, or -1. + ### Prototype + ```c ssize_t sc_array_bsearch (sc_array_t * array, const void *key, int (*compar) (const void *, const void *)); ``` """ function sc_array_bsearch(array, key, compar) - @ccall libsc.sc_array_bsearch(array::Ptr{sc_array_t}, key::Ptr{Cvoid}, compar::Ptr{Cvoid})::Cssize_t + @ccall libsc.sc_array_bsearch( + array::Ptr{sc_array_t}, + key::Ptr{Cvoid}, + compar::Ptr{Cvoid}, + )::Cssize_t end # typedef size_t ( * sc_array_type_t ) ( sc_array_t * array , size_t index , void * data ) @@ -1374,9 +1673,10 @@ end Function to determine the enumerable type of an object in an array. ### Parameters -* `array`:\\[in\\] Array containing the object. -* `index`:\\[in\\] The location of the object. -* `data`:\\[in\\] Arbitrary user data. + + - `array`:\\[in\\] Array containing the object. + - `index`:\\[in\\] The location of the object. + - `data`:\\[in\\] Arbitrary user data. """ const sc_array_type_t = Ptr{Cvoid} @@ -1386,18 +1686,27 @@ const sc_array_type_t = Ptr{Cvoid} Compute the offsets of groups of enumerable types in an array. ### Parameters -* `array`:\\[in\\] Array that is sorted in ascending order by type. If k indexes *array*, then 0 <= *type_fn* (*array*, k, *data*) < *num_types*. -* `offsets`:\\[in,out\\] An initialized array of type size\\_t that is resized to *num_types* + 1 entries. The indices j of *array* that contain objects of type k are *offsets*[k] <= j < *offsets*[k + 1]. If there are no objects of type k, then *offsets*[k] = *offset*[k + 1]. -* `num_types`:\\[in\\] The number of possible types of objects in *array*. -* `type_fn`:\\[in\\] Returns the type of an object in the array. -* `data`:\\[in\\] Arbitrary user data passed to *type_fn*. + + - `array`:\\[in\\] Array that is sorted in ascending order by type. If k indexes *array*, then 0 <= *type_fn* (*array*, k, *data*) < *num_types*. + - `offsets`:\\[in,out\\] An initialized array of type size\\_t that is resized to *num_types* + 1 entries. The indices j of *array* that contain objects of type k are *offsets*[k] <= j < *offsets*[k + 1]. If there are no objects of type k, then *offsets*[k] = *offset*[k + 1]. + - `num_types`:\\[in\\] The number of possible types of objects in *array*. + - `type_fn`:\\[in\\] Returns the type of an object in the array. + - `data`:\\[in\\] Arbitrary user data passed to *type_fn*. + ### Prototype + ```c void sc_array_split (sc_array_t * array, sc_array_t * offsets, size_t num_types, sc_array_type_t type_fn, void *data); ``` """ function sc_array_split(array, offsets, num_types, type_fn, data) - @ccall libsc.sc_array_split(array::Ptr{sc_array_t}, offsets::Ptr{sc_array_t}, num_types::Csize_t, type_fn::sc_array_type_t, data::Ptr{Cvoid})::Cvoid + @ccall libsc.sc_array_split( + array::Ptr{sc_array_t}, + offsets::Ptr{sc_array_t}, + num_types::Csize_t, + type_fn::sc_array_type_t, + data::Ptr{Cvoid}, + )::Cvoid end """ @@ -1406,10 +1715,15 @@ end Determine whether *array* is an array of size\\_t's whose entries include every integer 0 <= i < array->elem\\_count. ### Parameters -* `array`:\\[in\\] An array. + + - `array`:\\[in\\] An array. + ### Returns + Returns 1 if array contains size\\_t elements whose entries include every integer 0 <= i < *array*->elem_count, 0 otherwise. + ### Prototype + ```c int sc_array_is_permutation (sc_array_t * array); ``` @@ -1424,16 +1738,23 @@ end Given permutation *newindices*, permute *array* in place. The data that on input is contained in *array*[i] will be contained in *array*[newindices[i]] on output. The entries of newindices will be altered unless *keepperm* is true. ### Parameters -* `array`:\\[in,out\\] An array. -* `newindices`:\\[in,out\\] Permutation array (see [`sc_array_is_permutation`](@ref)). -* `keepperm`:\\[in\\] If true, *newindices* will be unchanged by the algorithm; if false, *newindices* will be the identity permutation on output, but the algorithm will only use O(1) space. + + - `array`:\\[in,out\\] An array. + - `newindices`:\\[in,out\\] Permutation array (see [`sc_array_is_permutation`](@ref)). + - `keepperm`:\\[in\\] If true, *newindices* will be unchanged by the algorithm; if false, *newindices* will be the identity permutation on output, but the algorithm will only use O(1) space. + ### Prototype + ```c void sc_array_permute (sc_array_t * array, sc_array_t * newindices, int keepperm); ``` """ function sc_array_permute(array, newindices, keepperm) - @ccall libsc.sc_array_permute(array::Ptr{sc_array_t}, newindices::Ptr{sc_array_t}, keepperm::Cint)::Cvoid + @ccall libsc.sc_array_permute( + array::Ptr{sc_array_t}, + newindices::Ptr{sc_array_t}, + keepperm::Cint, + )::Cvoid end """ @@ -1442,6 +1763,7 @@ end Computes the adler32 checksum of array data (see zlib documentation). This is a faster checksum than crc32, and it works with zeros as data. ### Prototype + ```c unsigned int sc_array_checksum (sc_array_t * array); ``` @@ -1460,17 +1782,26 @@ Adds an element to a priority queue. PQUEUE FUNCTIONS ARE UNTESTED AND CURRENTLY If the return value is zero for all elements in an array, the array is sorted linearly and unchanged. ### Parameters -* `temp`:\\[in\\] Pointer to unused allocated memory of elem\\_size. -* `compar`:\\[in\\] The comparison function to be used. + + - `temp`:\\[in\\] Pointer to unused allocated memory of elem\\_size. + - `compar`:\\[in\\] The comparison function to be used. + ### Returns + Returns the number of swap operations. + ### Prototype + ```c size_t sc_array_pqueue_add (sc_array_t * array, void *temp, int (*compar) (const void *, const void *)); ``` """ function sc_array_pqueue_add(array, temp, compar) - @ccall libsc.sc_array_pqueue_add(array::Ptr{sc_array_t}, temp::Ptr{Cvoid}, compar::Ptr{Cvoid})::Csize_t + @ccall libsc.sc_array_pqueue_add( + array::Ptr{sc_array_t}, + temp::Ptr{Cvoid}, + compar::Ptr{Cvoid}, + )::Csize_t end """ @@ -1483,17 +1814,26 @@ Pops the smallest element from a priority queue. PQUEUE FUNCTIONS ARE UNTESTED A This function resizes the array to elem\\_count-1. ### Parameters -* `result`:\\[out\\] Pointer to unused allocated memory of elem\\_size. -* `compar`:\\[in\\] The comparison function to be used. + + - `result`:\\[out\\] Pointer to unused allocated memory of elem\\_size. + - `compar`:\\[in\\] The comparison function to be used. + ### Returns + Returns the number of swap operations. + ### Prototype + ```c size_t sc_array_pqueue_pop (sc_array_t * array, void *result, int (*compar) (const void *, const void *)); ``` """ function sc_array_pqueue_pop(array, result, compar) - @ccall libsc.sc_array_pqueue_pop(array::Ptr{sc_array_t}, result::Ptr{Cvoid}, compar::Ptr{Cvoid})::Csize_t + @ccall libsc.sc_array_pqueue_pop( + array::Ptr{sc_array_t}, + result::Ptr{Cvoid}, + compar::Ptr{Cvoid}, + )::Csize_t end """ @@ -1501,14 +1841,14 @@ end A data container to create memory items of the same size. Allocations are bundled so it's fast for small memory sizes. The items created will remain valid until the container is destroyed. There is no option to return an item to the container. See sc_mempool_t for that purpose. -| Field | Note | -| :----------- | :------------------------------ | -| elem\\_size | Input parameter: size per item | -| per\\_stamp | Number of items per stamp | -| stamp\\_size | Bytes allocated in a stamp | -| cur\\_snext | Next number within a stamp | -| current | Memory of current stamp | -| remember | Collects all stamps | +| Field | Note | +|:------------ |:------------------------------ | +| elem\\_size | Input parameter: size per item | +| per\\_stamp | Number of items per stamp | +| stamp\\_size | Bytes allocated in a stamp | +| cur\\_snext | Next number within a stamp | +| current | Memory of current stamp | +| remember | Collects all stamps | """ struct sc_mstamp elem_size::Csize_t @@ -1519,7 +1859,9 @@ struct sc_mstamp remember::sc_array_t end -"""A data container to create memory items of the same size. Allocations are bundled so it's fast for small memory sizes. The items created will remain valid until the container is destroyed. There is no option to return an item to the container. See sc_mempool_t for that purpose.""" +""" +A data container to create memory items of the same size. Allocations are bundled so it's fast for small memory sizes. The items created will remain valid until the container is destroyed. There is no option to return an item to the container. See sc_mempool_t for that purpose. +""" const sc_mstamp_t = sc_mstamp """ @@ -1528,16 +1870,23 @@ const sc_mstamp_t = sc_mstamp Initialize a memory stamp container. We provide allocation of fixed-size memory items without allocating new memory in every request. Instead we block the allocations in what we call a stamp of multiple items. Even if no allocations are done, the container's internal memory must be freed eventually by sc_mstamp_reset. ### Parameters -* `mst`:\\[in,out\\] Legal pointer to a stamp structure. -* `stamp_unit`:\\[in\\] Size of each memory block that we allocate. If it is larger than the element size, we may place more than one element in it. Passing 0 is legal and forces stamps that hold one item each. -* `elem_size`:\\[in\\] Size of each item. Passing 0 is legal. In that case, sc_mstamp_alloc returns NULL. + + - `mst`:\\[in,out\\] Legal pointer to a stamp structure. + - `stamp_unit`:\\[in\\] Size of each memory block that we allocate. If it is larger than the element size, we may place more than one element in it. Passing 0 is legal and forces stamps that hold one item each. + - `elem_size`:\\[in\\] Size of each item. Passing 0 is legal. In that case, sc_mstamp_alloc returns NULL. + ### Prototype + ```c void sc_mstamp_init (sc_mstamp_t * mst, size_t stamp_unit, size_t elem_size); ``` """ function sc_mstamp_init(mst, stamp_unit, elem_size) - @ccall libsc.sc_mstamp_init(mst::Ptr{sc_mstamp_t}, stamp_unit::Csize_t, elem_size::Csize_t)::Cvoid + @ccall libsc.sc_mstamp_init( + mst::Ptr{sc_mstamp_t}, + stamp_unit::Csize_t, + elem_size::Csize_t, + )::Cvoid end """ @@ -1546,8 +1895,11 @@ end Free all memory in a stamp structure and all items previously returned. ### Parameters -* `Properly`:\\[in,out\\] initialized stamp container. On output, the structure is undefined. + + - `Properly`:\\[in,out\\] initialized stamp container. On output, the structure is undefined. + ### Prototype + ```c void sc_mstamp_reset (sc_mstamp_t * mst); ``` @@ -1562,8 +1914,11 @@ end Free all memory in a stamp structure and initialize it anew. Equivalent to calling sc_mstamp_reset followed by sc_mstamp_init with the same stamp\\_unit and elem\\_size. ### Parameters -* `Properly`:\\[in,out\\] initialized stamp container. On output, its elements have been freed and it is ready for further use. + + - `Properly`:\\[in,out\\] initialized stamp container. On output, its elements have been freed and it is ready for further use. + ### Prototype + ```c void sc_mstamp_truncate (sc_mstamp_t * mst); ``` @@ -1578,10 +1933,15 @@ end Return a new item. The memory returned will stay legal until container is destroyed or truncated. ### Parameters -* `Properly`:\\[in,out\\] initialized stamp container. + + - `Properly`:\\[in,out\\] initialized stamp container. + ### Returns + Pointer to an item ready to use. Legal until sc_stamp_destroy or sc_stamp_truncate is called on mst. + ### Prototype + ```c void *sc_mstamp_alloc (sc_mstamp_t * mst); ``` @@ -1596,10 +1956,15 @@ end Return memory size in bytes of all data allocated in the container. ### Parameters -* `Properly`:\\[in\\] initialized stamp container. + + - `Properly`:\\[in\\] initialized stamp container. + ### Returns + Total container memory size in bytes. + ### Prototype + ```c size_t sc_mstamp_memory_used (sc_mstamp_t * mst); ``` @@ -1613,13 +1978,13 @@ end The [`sc_mempool`](@ref) object provides a large pool of equal-size elements. The pool grows dynamically for element allocation. Elements are referenced by their address which never changes. Elements can be freed (that is, returned to the pool) and are transparently reused. If the zero\\_and\\_persist option is selected, new elements are initialized to all zeros on creation, and the contents of an element are not touched between freeing and re-returning it. -| Field | Note | -| :------------------- | :------------------------------- | -| elem\\_size | size of a single element | -| elem\\_count | number of valid elements | -| zero\\_and\\_persist | Boolean; is set in constructor. | -| mstamp | fixed-size chunk allocator | -| freed | buffers the freed elements | +| Field | Note | +|:-------------------- |:------------------------------- | +| elem\\_size | size of a single element | +| elem\\_count | number of valid elements | +| zero\\_and\\_persist | Boolean; is set in constructor. | +| mstamp | fixed-size chunk allocator | +| freed | buffers the freed elements | """ struct sc_mempool elem_size::Csize_t @@ -1629,19 +1994,26 @@ struct sc_mempool freed::sc_array_t end -"""The [`sc_mempool`](@ref) object provides a large pool of equal-size elements. The pool grows dynamically for element allocation. Elements are referenced by their address which never changes. Elements can be freed (that is, returned to the pool) and are transparently reused. If the zero\\_and\\_persist option is selected, new elements are initialized to all zeros on creation, and the contents of an element are not touched between freeing and re-returning it.""" -const sc_mempool_t = sc_mempool - +""" +The [`sc_mempool`](@ref) object provides a large pool of equal-size elements. The pool grows dynamically for element allocation. Elements are referenced by their address which never changes. Elements can be freed (that is, returned to the pool) and are transparently reused. If the zero\\_and\\_persist option is selected, new elements are initialized to all zeros on creation, and the contents of an element are not touched between freeing and re-returning it. +""" +const sc_mempool_t = sc_mempool + """ sc_mempool_memory_used(mempool) Calculate the memory used by a memory pool. ### Parameters -* `array`:\\[in\\] The memory pool. + + - `array`:\\[in\\] The memory pool. + ### Returns + Memory used in bytes. + ### Prototype + ```c size_t sc_mempool_memory_used (sc_mempool_t * mempool); ``` @@ -1656,10 +2028,15 @@ end Creates a new mempool structure with the zero\\_and\\_persist option off. The contents of any elements returned by sc\\_mempool\\_alloc are undefined. ### Parameters -* `elem_size`:\\[in\\] Size of one element in bytes. + + - `elem_size`:\\[in\\] Size of one element in bytes. + ### Returns + Returns an allocated and initialized memory pool. + ### Prototype + ```c sc_mempool_t *sc_mempool_new (size_t elem_size); ``` @@ -1674,10 +2051,15 @@ end Creates a new mempool structure with the zero\\_and\\_persist option on. The memory of newly created elements is zero'd out, and the contents of an element are not touched between freeing and re-returning it. ### Parameters -* `elem_size`:\\[in\\] Size of one element in bytes. + + - `elem_size`:\\[in\\] Size of one element in bytes. + ### Returns + Returns an allocated and initialized memory pool. + ### Prototype + ```c sc_mempool_t *sc_mempool_new_zero_and_persist (size_t elem_size); ``` @@ -1692,6 +2074,7 @@ end Same as [`sc_mempool_new`](@ref), but for an already allocated [`sc_mempool_t`](@ref) pointer. ### Prototype + ```c void sc_mempool_init (sc_mempool_t * mempool, size_t elem_size); ``` @@ -1706,8 +2089,11 @@ end Destroy a mempool structure. All elements that are still in use are invalidated. ### Parameters -* `mempool`:\\[in,out\\] Its memory is freed. + + - `mempool`:\\[in,out\\] Its memory is freed. + ### Prototype + ```c void sc_mempool_destroy (sc_mempool_t * mempool); ``` @@ -1722,8 +2108,11 @@ end Destroy a mempool structure. All elements that are still in use are invalidated. ### Parameters -* `pmempool`:\\[in,out\\] Address of pointer to memory pool. Its memory is freed, pointer is NULLed. + + - `pmempool`:\\[in,out\\] Address of pointer to memory pool. Its memory is freed, pointer is NULLed. + ### Prototype + ```c void sc_mempool_destroy_null (sc_mempool_t ** pmempool); ``` @@ -1738,6 +2127,7 @@ end Same as [`sc_mempool_destroy`](@ref), but does not free the pointer ### Prototype + ```c void sc_mempool_reset (sc_mempool_t * mempool); ``` @@ -1752,6 +2142,7 @@ end Invalidates all previously returned pointers, resets count to 0. ### Prototype + ```c void sc_mempool_truncate (sc_mempool_t * mempool); ``` @@ -1770,7 +2161,9 @@ struct sc_link next::Ptr{sc_link} end -"""The [`sc_link`](@ref) structure is one link of a linked list.""" +""" +The [`sc_link`](@ref) structure is one link of a linked list. +""" const sc_link_t = sc_link """ @@ -1786,7 +2179,9 @@ struct sc_list allocator::Ptr{sc_mempool_t} end -"""The [`sc_list`](@ref) object provides a linked list.""" +""" +The [`sc_list`](@ref) object provides a linked list. +""" const sc_list_t = sc_list """ @@ -1795,11 +2190,16 @@ const sc_list_t = sc_list Calculate the total memory used by a list. ### Parameters -* `list`:\\[in\\] The list. -* `is_dynamic`:\\[in\\] True if created with [`sc_list_new`](@ref), false if initialized with [`sc_list_init`](@ref) + + - `list`:\\[in\\] The list. + - `is_dynamic`:\\[in\\] True if created with [`sc_list_new`](@ref), false if initialized with [`sc_list_init`](@ref) + ### Returns + Memory used in bytes. + ### Prototype + ```c size_t sc_list_memory_used (sc_list_t * list, int is_dynamic); ``` @@ -1814,10 +2214,15 @@ end Allocate a new, empty linked list. ### Parameters -* `allocator`:\\[in\\] Memory allocator for [`sc_link_t`](@ref), can be NULL in which case an internal allocator is created. + + - `allocator`:\\[in\\] Memory allocator for [`sc_link_t`](@ref), can be NULL in which case an internal allocator is created. + ### Returns + Pointer to a newly allocated, empty list object. + ### Prototype + ```c sc_list_t *sc_list_new (sc_mempool_t * allocator); ``` @@ -1836,8 +2241,11 @@ Destroy a linked list structure in O(N). If allocator was provided in [`sc_list_new`](@ref), it will not be destroyed. ### Parameters -* `list`:\\[in,out\\] All memory allocated for this list is freed. + + - `list`:\\[in,out\\] All memory allocated for this list is freed. + ### Prototype + ```c void sc_list_destroy (sc_list_t * list); ``` @@ -1852,9 +2260,12 @@ end Initialize a list object with an external link allocator. ### Parameters -* `list`:\\[in,out\\] List structure to be initialized. -* `allocator`:\\[in\\] External memory allocator for [`sc_link_t`](@ref), which must exist already. + + - `list`:\\[in,out\\] List structure to be initialized. + - `allocator`:\\[in\\] External memory allocator for [`sc_link_t`](@ref), which must exist already. + ### Prototype + ```c void sc_list_init (sc_list_t * list, sc_mempool_t * allocator); ``` @@ -1873,8 +2284,11 @@ Remove all elements from a list in O(N). Calling [`sc_list_init`](@ref), then any list operations, then [`sc_list_reset`](@ref) is memory neutral. ### Parameters -* `list`:\\[in,out\\] List structure to be emptied. + + - `list`:\\[in,out\\] List structure to be emptied. + ### Prototype + ```c void sc_list_reset (sc_list_t * list); ``` @@ -1889,8 +2303,11 @@ end Unlink all list elements without returning them to the mempool. This runs in O(1) but is dangerous because the link memory stays alive. ### Parameters -* `list`:\\[in,out\\] List structure to be unlinked. + + - `list`:\\[in,out\\] List structure to be unlinked. + ### Prototype + ```c void sc_list_unlink (sc_list_t * list); ``` @@ -1905,11 +2322,16 @@ end Insert a list element at the beginning of the list. ### Parameters -* `list`:\\[in,out\\] Valid list object. -* `data`:\\[in\\] A new link is created holding this data. + + - `list`:\\[in,out\\] Valid list object. + - `data`:\\[in\\] A new link is created holding this data. + ### Returns + The link that has been created for data. + ### Prototype + ```c sc_link_t *sc_list_prepend (sc_list_t * list, void *data); ``` @@ -1924,11 +2346,16 @@ end Insert a list element at the end of the list. ### Parameters -* `list`:\\[in,out\\] Valid list object. -* `data`:\\[in\\] A new link is created holding this data. + + - `list`:\\[in,out\\] Valid list object. + - `data`:\\[in\\] A new link is created holding this data. + ### Returns + The link that has been created for data. + ### Prototype + ```c sc_link_t *sc_list_append (sc_list_t * list, void *data); ``` @@ -1943,18 +2370,27 @@ end Insert an element after a given list position. ### Parameters -* `list`:\\[in,out\\] Valid list object. -* `pred`:\\[in,out\\] The predecessor of the element to be inserted. -* `data`:\\[in\\] A new link is created holding this data. + + - `list`:\\[in,out\\] Valid list object. + - `pred`:\\[in,out\\] The predecessor of the element to be inserted. + - `data`:\\[in\\] A new link is created holding this data. + ### Returns + The link that has been created for data. + ### Prototype + ```c sc_link_t *sc_list_insert (sc_list_t * list, sc_link_t * pred, void *data); ``` """ function sc_list_insert(list, pred, data) - @ccall libsc.sc_list_insert(list::Ptr{sc_list_t}, pred::Ptr{sc_link_t}, data::Ptr{Cvoid})::Ptr{sc_link_t} + @ccall libsc.sc_list_insert( + list::Ptr{sc_list_t}, + pred::Ptr{sc_link_t}, + data::Ptr{Cvoid}, + )::Ptr{sc_link_t} end """ @@ -1963,11 +2399,16 @@ end Remove an element after a given list position. ### Parameters -* `list`:\\[in,out\\] Valid, non-empty list object. -* `pred`:\\[in\\] The predecessor of the element to be removed. If *pred* == NULL, the first element is removed, which is equivalent to calling [`sc_list_pop`](@ref) (list). + + - `list`:\\[in,out\\] Valid, non-empty list object. + - `pred`:\\[in\\] The predecessor of the element to be removed. If *pred* == NULL, the first element is removed, which is equivalent to calling [`sc_list_pop`](@ref) (list). + ### Returns + The data of the removed and freed link. + ### Prototype + ```c void *sc_list_remove (sc_list_t * list, sc_link_t * pred); ``` @@ -1982,10 +2423,15 @@ end Remove an element from the front of the list. ### Parameters -* `list`:\\[in,out\\] Valid, non-empty list object. + + - `list`:\\[in,out\\] Valid, non-empty list object. + ### Returns + Returns the data of the removed first list element. + ### Prototype + ```c void *sc_list_pop (sc_list_t * list); ``` @@ -1999,12 +2445,12 @@ end The [`sc_hash`](@ref) implements a hash table. It uses an array which has linked lists as elements. -| Field | Note | -| :----------- | :------------------------------------- | -| elem\\_count | total number of objects contained | -| slots | the slot count is slots->elem\\_count | -| user\\_data | user data passed to hash function | -| allocator | must allocate [`sc_link_t`](@ref) | +| Field | Note | +|:------------ |:------------------------------------- | +| elem\\_count | total number of objects contained | +| slots | the slot count is slots->elem\\_count | +| user\\_data | user data passed to hash function | +| allocator | must allocate [`sc_link_t`](@ref) | """ struct sc_hash elem_count::Csize_t @@ -2018,7 +2464,9 @@ struct sc_hash allocator::Ptr{sc_mempool_t} end -"""The [`sc_hash`](@ref) implements a hash table. It uses an array which has linked lists as elements.""" +""" +The [`sc_hash`](@ref) implements a hash table. It uses an array which has linked lists as elements. +""" const sc_hash_t = sc_hash """ @@ -2027,11 +2475,16 @@ const sc_hash_t = sc_hash Compute a hash value from a null-terminated string. This hash function is NOT cryptographically safe! Use libcrypt then. ### Parameters -* `s`:\\[in\\] Null-terminated string to be hashed. -* `u`:\\[in\\] Not used. + + - `s`:\\[in\\] Null-terminated string to be hashed. + - `u`:\\[in\\] Not used. + ### Returns + The computed hash value as an unsigned integer. + ### Prototype + ```c unsigned int sc_hash_function_string (const void *s, const void *u); ``` @@ -2046,10 +2499,15 @@ end Calculate the memory used by a hash table. ### Parameters -* `hash`:\\[in\\] The hash table. + + - `hash`:\\[in\\] The hash table. + ### Returns + Memory used in bytes. + ### Prototype + ```c size_t sc_hash_memory_used (sc_hash_t * hash); ``` @@ -2064,17 +2522,25 @@ end Create a new hash table. The number of hash slots is chosen dynamically. ### Parameters -* `hash_fn`:\\[in\\] Function to compute the hash value. -* `equal_fn`:\\[in\\] Function to test two objects for equality. -* `user_data`:\\[in\\] User data passed through to the hash function. -* `allocator`:\\[in\\] Memory allocator for [`sc_link_t`](@ref), can be NULL. + + - `hash_fn`:\\[in\\] Function to compute the hash value. + - `equal_fn`:\\[in\\] Function to test two objects for equality. + - `user_data`:\\[in\\] User data passed through to the hash function. + - `allocator`:\\[in\\] Memory allocator for [`sc_link_t`](@ref), can be NULL. + ### Prototype + ```c sc_hash_t *sc_hash_new (sc_hash_function_t hash_fn, sc_equal_function_t equal_fn, void *user_data, sc_mempool_t * allocator); ``` """ function sc_hash_new(hash_fn, equal_fn, user_data, allocator) - @ccall libsc.sc_hash_new(hash_fn::sc_hash_function_t, equal_fn::sc_equal_function_t, user_data::Ptr{Cvoid}, allocator::Ptr{sc_mempool_t})::Ptr{sc_hash_t} + @ccall libsc.sc_hash_new( + hash_fn::sc_hash_function_t, + equal_fn::sc_equal_function_t, + user_data::Ptr{Cvoid}, + allocator::Ptr{sc_mempool_t}, + )::Ptr{sc_hash_t} end """ @@ -2089,6 +2555,7 @@ If the allocator is owned, this runs in O(1), otherwise in O(N). If allocator was provided in [`sc_hash_new`](@ref), it will not be destroyed. ### Prototype + ```c void sc_hash_destroy (sc_hash_t * hash); ``` @@ -2103,8 +2570,11 @@ end Destroy a hash table and set its pointer to NULL. Destruction is done using sc_hash_destroy. ### Parameters -* `phash`:\\[in,out\\] Address of pointer to hash table. On output, pointer is NULLed. + + - `phash`:\\[in,out\\] Address of pointer to hash table. On output, pointer is NULLed. + ### Prototype + ```c void sc_hash_destroy_null (sc_hash_t ** phash); ``` @@ -2121,6 +2591,7 @@ Remove all entries from a hash table in O(N). If the allocator is owned, it calls [`sc_hash_unlink`](@ref) and [`sc_mempool_truncate`](@ref). Otherwise, it calls [`sc_list_reset`](@ref) on every hash slot which is slower. ### Prototype + ```c void sc_hash_truncate (sc_hash_t * hash); ``` @@ -2137,8 +2608,11 @@ Unlink all hash elements without returning them to the mempool. If the allocator is not owned, this runs faster than [`sc_hash_truncate`](@ref), but is dangerous because of potential memory leaks. ### Parameters -* `hash`:\\[in,out\\] Hash structure to be unlinked. + + - `hash`:\\[in,out\\] Hash structure to be unlinked. + ### Prototype + ```c void sc_hash_unlink (sc_hash_t * hash); ``` @@ -2153,8 +2627,11 @@ end Same effect as unlink and destroy, but in O(1). This is dangerous because of potential memory leaks. ### Parameters -* `hash`:\\[in\\] Hash structure to be unlinked and destroyed. + + - `hash`:\\[in\\] Hash structure to be unlinked and destroyed. + ### Prototype + ```c void sc_hash_unlink_destroy (sc_hash_t * hash); ``` @@ -2169,17 +2646,26 @@ end Check if an object is contained in the hash table. ### Parameters -* `v`:\\[in\\] The object to be looked up. -* `found`:\\[out\\] If found != NULL, *found is set to the address of the pointer to the already contained object if the object is found. You can assign to **found to override. + + - `v`:\\[in\\] The object to be looked up. + - `found`:\\[out\\] If found != NULL, *found is set to the address of the pointer to the already contained object if the object is found. You can assign to **found to override. + ### Returns + Returns true if object is found, false otherwise. + ### Prototype + ```c int sc_hash_lookup (sc_hash_t * hash, void *v, void ***found); ``` """ function sc_hash_lookup(hash, v, found) - @ccall libsc.sc_hash_lookup(hash::Ptr{sc_hash_t}, v::Ptr{Cvoid}, found::Ptr{Ptr{Ptr{Cvoid}}})::Cint + @ccall libsc.sc_hash_lookup( + hash::Ptr{sc_hash_t}, + v::Ptr{Cvoid}, + found::Ptr{Ptr{Ptr{Cvoid}}}, + )::Cint end """ @@ -2188,17 +2674,26 @@ end Insert an object into a hash table if it is not contained already. ### Parameters -* `v`:\\[in\\] The object to be inserted. -* `found`:\\[out\\] If found != NULL, *found is set to the address of the pointer to the already contained, or if not present, the new object. You can assign to **found to override. + + - `v`:\\[in\\] The object to be inserted. + - `found`:\\[out\\] If found != NULL, *found is set to the address of the pointer to the already contained, or if not present, the new object. You can assign to **found to override. + ### Returns + Returns true if object is added, false if it is already contained. + ### Prototype + ```c int sc_hash_insert_unique (sc_hash_t * hash, void *v, void ***found); ``` """ function sc_hash_insert_unique(hash, v, found) - @ccall libsc.sc_hash_insert_unique(hash::Ptr{sc_hash_t}, v::Ptr{Cvoid}, found::Ptr{Ptr{Ptr{Cvoid}}})::Cint + @ccall libsc.sc_hash_insert_unique( + hash::Ptr{sc_hash_t}, + v::Ptr{Cvoid}, + found::Ptr{Ptr{Ptr{Cvoid}}}, + )::Cint end """ @@ -2207,17 +2702,26 @@ end Remove an object from a hash table. ### Parameters -* `v`:\\[in\\] The object to be removed. -* `found`:\\[out\\] If found != NULL, *found is set to the object that is removed if that exists. + + - `v`:\\[in\\] The object to be removed. + - `found`:\\[out\\] If found != NULL, *found is set to the object that is removed if that exists. + ### Returns + Returns true if object is found, false if is not contained. + ### Prototype + ```c int sc_hash_remove (sc_hash_t * hash, void *v, void **found); ``` """ function sc_hash_remove(hash, v, found) - @ccall libsc.sc_hash_remove(hash::Ptr{sc_hash_t}, v::Ptr{Cvoid}, found::Ptr{Ptr{Cvoid}})::Cint + @ccall libsc.sc_hash_remove( + hash::Ptr{sc_hash_t}, + v::Ptr{Cvoid}, + found::Ptr{Ptr{Cvoid}}, + )::Cint end """ @@ -2226,6 +2730,7 @@ end Invoke a callback for every member of the hash table. The functions hash\\_fn and equal\\_fn are not called by this function. ### Prototype + ```c void sc_hash_foreach (sc_hash_t * hash, sc_hash_foreach_t fn); ``` @@ -2240,12 +2745,17 @@ end Compute and print statistical information about the occupancy. ### Prototype + ```c void sc_hash_print_statistics (int package_id, int log_priority, sc_hash_t * hash); ``` """ function sc_hash_print_statistics(package_id, log_priority, hash) - @ccall libsc.sc_hash_print_statistics(package_id::Cint, log_priority::Cint, hash::Ptr{sc_hash_t})::Cvoid + @ccall libsc.sc_hash_print_statistics( + package_id::Cint, + log_priority::Cint, + hash::Ptr{sc_hash_t}, + )::Cvoid end struct sc_hash_array_data @@ -2269,7 +2779,9 @@ struct sc_hash_array h::Ptr{sc_hash_t} end -"""The [`sc_hash_array`](@ref) implements an array backed up by a hash table. This enables O(1) access for array elements.""" +""" +The [`sc_hash_array`](@ref) implements an array backed up by a hash table. This enables O(1) access for array elements. +""" const sc_hash_array_t = sc_hash_array """ @@ -2278,10 +2790,15 @@ const sc_hash_array_t = sc_hash_array Calculate the memory used by a hash array. ### Parameters -* `ha`:\\[in\\] The hash array. + + - `ha`:\\[in\\] The hash array. + ### Returns + Memory used in bytes. + ### Prototype + ```c size_t sc_hash_array_memory_used (sc_hash_array_t * ha); ``` @@ -2296,16 +2813,24 @@ end Create a new hash array. ### Parameters -* `elem_size`:\\[in\\] Size of one array element in bytes. -* `hash_fn`:\\[in\\] Function to compute the hash value. -* `equal_fn`:\\[in\\] Function to test two objects for equality. + + - `elem_size`:\\[in\\] Size of one array element in bytes. + - `hash_fn`:\\[in\\] Function to compute the hash value. + - `equal_fn`:\\[in\\] Function to test two objects for equality. + ### Prototype + ```c sc_hash_array_t *sc_hash_array_new (size_t elem_size, sc_hash_function_t hash_fn, sc_equal_function_t equal_fn, void *user_data); ``` """ function sc_hash_array_new(elem_size, hash_fn, equal_fn, user_data) - @ccall libsc.sc_hash_array_new(elem_size::Csize_t, hash_fn::sc_hash_function_t, equal_fn::sc_equal_function_t, user_data::Ptr{Cvoid})::Ptr{sc_hash_array_t} + @ccall libsc.sc_hash_array_new( + elem_size::Csize_t, + hash_fn::sc_hash_function_t, + equal_fn::sc_equal_function_t, + user_data::Ptr{Cvoid}, + )::Ptr{sc_hash_array_t} end """ @@ -2314,6 +2839,7 @@ end Destroy a hash array. ### Prototype + ```c void sc_hash_array_destroy (sc_hash_array_t * hash_array); ``` @@ -2328,6 +2854,7 @@ end Check the internal consistency of a hash array. ### Prototype + ```c int sc_hash_array_is_valid (sc_hash_array_t * hash_array); ``` @@ -2342,8 +2869,11 @@ end Remove all elements from the hash array. ### Parameters -* `hash_array`:\\[in,out\\] Hash array to truncate. + + - `hash_array`:\\[in,out\\] Hash array to truncate. + ### Prototype + ```c void sc_hash_array_truncate (sc_hash_array_t * hash_array); ``` @@ -2358,17 +2888,26 @@ end Check if an object is contained in a hash array. ### Parameters -* `v`:\\[in\\] A pointer to the object. -* `position`:\\[out\\] If position != NULL, *position is set to the array position of the already contained object if found. + + - `v`:\\[in\\] A pointer to the object. + - `position`:\\[out\\] If position != NULL, *position is set to the array position of the already contained object if found. + ### Returns + Returns true if object is found, false otherwise. + ### Prototype + ```c int sc_hash_array_lookup (sc_hash_array_t * hash_array, void *v, size_t *position); ``` """ function sc_hash_array_lookup(hash_array, v, position) - @ccall libsc.sc_hash_array_lookup(hash_array::Ptr{sc_hash_array_t}, v::Ptr{Cvoid}, position::Ptr{Csize_t})::Cint + @ccall libsc.sc_hash_array_lookup( + hash_array::Ptr{sc_hash_array_t}, + v::Ptr{Cvoid}, + position::Ptr{Csize_t}, + )::Cint end """ @@ -2377,17 +2916,26 @@ end Insert an object into a hash array if it is not contained already. The object is not copied into the array. Use the return value for that. New objects are guaranteed to be added at the end of the array. ### Parameters -* `v`:\\[in\\] A pointer to the object. Used for search only. -* `position`:\\[out\\] If position != NULL, *position is set to the array position of the already contained, or if not present, the new object. + + - `v`:\\[in\\] A pointer to the object. Used for search only. + - `position`:\\[out\\] If position != NULL, *position is set to the array position of the already contained, or if not present, the new object. + ### Returns + Returns NULL if the object is already contained. Otherwise returns its new address in the array. + ### Prototype + ```c void *sc_hash_array_insert_unique (sc_hash_array_t * hash_array, void *v, size_t *position); ``` """ function sc_hash_array_insert_unique(hash_array, v, position) - @ccall libsc.sc_hash_array_insert_unique(hash_array::Ptr{sc_hash_array_t}, v::Ptr{Cvoid}, position::Ptr{Csize_t})::Ptr{Cvoid} + @ccall libsc.sc_hash_array_insert_unique( + hash_array::Ptr{sc_hash_array_t}, + v::Ptr{Cvoid}, + position::Ptr{Csize_t}, + )::Ptr{Cvoid} end """ @@ -2396,15 +2944,21 @@ end Extract the array data from a hash array and destroy everything else. ### Parameters -* `hash_array`:\\[in\\] The hash array is destroyed after extraction. -* `rip`:\\[in\\] Array structure that will be overwritten. All previous array data (if any) will be leaked. The filled array can be freed with [`sc_array_reset`](@ref). + + - `hash_array`:\\[in\\] The hash array is destroyed after extraction. + - `rip`:\\[in\\] Array structure that will be overwritten. All previous array data (if any) will be leaked. The filled array can be freed with [`sc_array_reset`](@ref). + ### Prototype + ```c void sc_hash_array_rip (sc_hash_array_t * hash_array, sc_array_t * rip); ``` """ function sc_hash_array_rip(hash_array, rip) - @ccall libsc.sc_hash_array_rip(hash_array::Ptr{sc_hash_array_t}, rip::Ptr{sc_array_t})::Cvoid + @ccall libsc.sc_hash_array_rip( + hash_array::Ptr{sc_hash_array_t}, + rip::Ptr{sc_array_t}, + )::Cvoid end """ @@ -2433,14 +2987,20 @@ const sc_recycle_array_t = sc_recycle_array Initialize a recycle array. ### Parameters -* `elem_size`:\\[in\\] Size of the objects to be stored in the array. + + - `elem_size`:\\[in\\] Size of the objects to be stored in the array. + ### Prototype + ```c void sc_recycle_array_init (sc_recycle_array_t * rec_array, size_t elem_size); ``` """ function sc_recycle_array_init(rec_array, elem_size) - @ccall libsc.sc_recycle_array_init(rec_array::Ptr{sc_recycle_array_t}, elem_size::Csize_t)::Cvoid + @ccall libsc.sc_recycle_array_init( + rec_array::Ptr{sc_recycle_array_t}, + elem_size::Csize_t, + )::Cvoid end """ @@ -2451,6 +3011,7 @@ Reset a recycle array. As with all \\_reset functions, calling \\_init, then any array operations, then \\_reset is memory neutral. ### Prototype + ```c void sc_recycle_array_reset (sc_recycle_array_t * rec_array); ``` @@ -2465,16 +3026,24 @@ end Insert an object into the recycle array. The object is not copied into the array. Use the return value for that. ### Parameters -* `position`:\\[out\\] If position != NULL, *position is set to the array position of the inserted object. + + - `position`:\\[out\\] If position != NULL, *position is set to the array position of the inserted object. + ### Returns + Returns the new address of the object in the array. + ### Prototype + ```c void *sc_recycle_array_insert (sc_recycle_array_t * rec_array, size_t *position); ``` """ function sc_recycle_array_insert(rec_array, position) - @ccall libsc.sc_recycle_array_insert(rec_array::Ptr{sc_recycle_array_t}, position::Ptr{Csize_t})::Ptr{Cvoid} + @ccall libsc.sc_recycle_array_insert( + rec_array::Ptr{sc_recycle_array_t}, + position::Ptr{Csize_t}, + )::Ptr{Cvoid} end """ @@ -2483,16 +3052,24 @@ end Remove an object from the recycle array. It must be valid. ### Parameters -* `position`:\\[in\\] Index into the array for the object to remove. + + - `position`:\\[in\\] Index into the array for the object to remove. + ### Returns + The pointer to the removed object. Will be valid as long as no other function is called on this recycle array. + ### Prototype + ```c void *sc_recycle_array_remove (sc_recycle_array_t * rec_array, size_t position); ``` """ function sc_recycle_array_remove(rec_array, position) - @ccall libsc.sc_recycle_array_remove(rec_array::Ptr{sc_recycle_array_t}, position::Csize_t)::Ptr{Cvoid} + @ccall libsc.sc_recycle_array_remove( + rec_array::Ptr{sc_recycle_array_t}, + position::Csize_t, + )::Ptr{Cvoid} end """ @@ -2500,11 +3077,11 @@ end Error values for io. -| Enumerator | Note | -| :---------------------- | :--------------------------------------------------------------------------- | -| SC\\_IO\\_ERROR\\_NONE | The value of zero means no error. | -| SC\\_IO\\_ERROR\\_FATAL | The io object is now disfunctional. | -| SC\\_IO\\_ERROR\\_AGAIN | Another io operation may resolve it. The function just returned was a noop. | +| Enumerator | Note | +|:----------------------- |:--------------------------------------------------------------------------- | +| SC\\_IO\\_ERROR\\_NONE | The value of zero means no error. | +| SC\\_IO\\_ERROR\\_FATAL | The io object is now disfunctional. | +| SC\\_IO\\_ERROR\\_AGAIN | Another io operation may resolve it. The function just returned was a noop. | """ @cenum sc_io_error_t::Int32 begin SC_IO_ERROR_NONE = 0 @@ -2515,11 +3092,11 @@ end """ sc_io_mode_t -| Enumerator | Note | -| :---------------------- | :--------------------------- | -| SC\\_IO\\_MODE\\_WRITE | Semantics as "w" in fopen. | -| SC\\_IO\\_MODE\\_APPEND | Semantics as "a" in fopen. | -| SC\\_IO\\_MODE\\_LAST | Invalid entry to close list | +| Enumerator | Note | +|:----------------------- |:--------------------------- | +| SC\\_IO\\_MODE\\_WRITE | Semantics as "w" in fopen. | +| SC\\_IO\\_MODE\\_APPEND | Semantics as "a" in fopen. | +| SC\\_IO\\_MODE\\_LAST | Invalid entry to close list | """ @cenum sc_io_mode_t::UInt32 begin SC_IO_MODE_WRITE = 0 @@ -2530,9 +3107,9 @@ end """ sc_io_encode_t -| Enumerator | Note | -| :---------------------- | :--------------------------- | -| SC\\_IO\\_ENCODE\\_LAST | Invalid entry to close list | +| Enumerator | Note | +|:----------------------- |:--------------------------- | +| SC\\_IO\\_ENCODE\\_LAST | Invalid entry to close list | """ @cenum sc_io_encode_t::UInt32 begin SC_IO_ENCODE_NONE = 0 @@ -2542,9 +3119,9 @@ end """ sc_io_type_t -| Enumerator | Note | -| :-------------------- | :--------------------------- | -| SC\\_IO\\_TYPE\\_LAST | Invalid entry to close list | +| Enumerator | Note | +|:--------------------- |:--------------------------- | +| SC\\_IO\\_TYPE\\_LAST | Invalid entry to close list | """ @cenum sc_io_type_t::UInt32 begin SC_IO_TYPE_BUFFER = 0 @@ -2556,9 +3133,9 @@ end """ sc_io_sink -| Field | Note | -| :------------- | :---------------------------- | -| buffer\\_bytes | distinguish from array elems | +| Field | Note | +|:-------------- |:---------------------------- | +| buffer\\_bytes | distinguish from array elems | """ struct sc_io_sink iotype::sc_io_type_t @@ -2576,9 +3153,9 @@ const sc_io_sink_t = sc_io_sink """ sc_io_source -| Field | Note | -| :------------- | :---------------------------- | -| buffer\\_bytes | distinguish from array elems | +| Field | Note | +|:-------------- |:---------------------------- | +| buffer\\_bytes | distinguish from array elems | """ struct sc_io_source iotype::sc_io_type_t @@ -2596,8 +3173,15 @@ const sc_io_source_t = sc_io_source # automatic type deduction for variadic arguments may not be what you want, please use with caution @generated function sc_io_sink_new(iotype, mode, encode, va_list...) - :(@ccall(libsc.sc_io_sink_new(iotype::sc_io_type_t, mode::sc_io_mode_t, encode::sc_io_encode_t; $(to_c_type_pairs(va_list)...))::Ptr{sc_io_sink_t})) - end + :(@ccall( + libsc.sc_io_sink_new( + iotype::sc_io_type_t, + mode::sc_io_mode_t, + encode::sc_io_encode_t; + $(to_c_type_pairs(va_list)...), + )::Ptr{sc_io_sink_t} + )) +end """ sc_io_sink_destroy(sink) @@ -2605,10 +3189,15 @@ const sc_io_source_t = sc_io_source Free data sink. Calls [`sc_io_sink_complete`](@ref) and discards the final counts. Errors from complete lead to SC\\_IO\\_ERROR\\_FATAL returned from this function. Call [`sc_io_sink_complete`](@ref) yourself if bytes\\_out is of interest. ### Parameters -* `sink`:\\[in,out\\] The sink object to complete and free. + + - `sink`:\\[in,out\\] The sink object to complete and free. + ### Returns + 0 on success, nonzero on error. + ### Prototype + ```c int sc_io_sink_destroy (sc_io_sink_t * sink); ``` @@ -2623,18 +3212,27 @@ end Write data to a sink. Data may be buffered and sunk in a later call. The internal counters sink->bytes\\_in and sink->bytes\\_out are updated. ### Parameters -* `sink`:\\[in,out\\] The sink object to write to. -* `data`:\\[in\\] Data passed into sink. -* `bytes_avail`:\\[in\\] Number of data bytes passed in. + + - `sink`:\\[in,out\\] The sink object to write to. + - `data`:\\[in\\] Data passed into sink. + - `bytes_avail`:\\[in\\] Number of data bytes passed in. + ### Returns + 0 on success, nonzero on error. + ### Prototype + ```c int sc_io_sink_write (sc_io_sink_t * sink, const void *data, size_t bytes_avail); ``` """ function sc_io_sink_write(sink, data, bytes_avail) - @ccall libsc.sc_io_sink_write(sink::Ptr{sc_io_sink_t}, data::Ptr{Cvoid}, bytes_avail::Csize_t)::Cint + @ccall libsc.sc_io_sink_write( + sink::Ptr{sc_io_sink_t}, + data::Ptr{Cvoid}, + bytes_avail::Csize_t, + )::Cint end """ @@ -2643,18 +3241,27 @@ end Flush all buffered output data to sink. This function may return SC\\_IO\\_ERROR\\_AGAIN if another write is required. Currently this may happen if BUFFER requires an integer multiple of bytes. If successful, the updated value of bytes read and written is returned in bytes\\_in/out, and the sink status is reset as if the sink had just been created. In particular, the bytes counters are reset to zero. The internal state of the sink is not changed otherwise. It is legal to continue writing to the sink hereafter. The sink actions taken depend on its type. BUFFER, FILEFILE: none. FILENAME: call fclose on sink->file. ### Parameters -* `sink`:\\[in,out\\] The sink object to write to. -* `bytes_in`:\\[in,out\\] Bytes received since the last new or complete call. May be NULL. -* `bytes_out`:\\[in,out\\] Bytes written since the last new or complete call. May be NULL. + + - `sink`:\\[in,out\\] The sink object to write to. + - `bytes_in`:\\[in,out\\] Bytes received since the last new or complete call. May be NULL. + - `bytes_out`:\\[in,out\\] Bytes written since the last new or complete call. May be NULL. + ### Returns + 0 if completed, nonzero on error. + ### Prototype + ```c int sc_io_sink_complete (sc_io_sink_t * sink, size_t * bytes_in, size_t * bytes_out); ``` """ function sc_io_sink_complete(sink, bytes_in, bytes_out) - @ccall libsc.sc_io_sink_complete(sink::Ptr{sc_io_sink_t}, bytes_in::Ptr{Csize_t}, bytes_out::Ptr{Csize_t})::Cint + @ccall libsc.sc_io_sink_complete( + sink::Ptr{sc_io_sink_t}, + bytes_in::Ptr{Csize_t}, + bytes_out::Ptr{Csize_t}, + )::Cint end """ @@ -2663,11 +3270,16 @@ end Align sink to a byte boundary by writing zeros. ### Parameters -* `sink`:\\[in,out\\] The sink object to align. -* `bytes_align`:\\[in\\] Byte boundary. + + - `sink`:\\[in,out\\] The sink object to align. + - `bytes_align`:\\[in\\] Byte boundary. + ### Returns + 0 on success, nonzero on error. + ### Prototype + ```c int sc_io_sink_align (sc_io_sink_t * sink, size_t bytes_align); ``` @@ -2678,8 +3290,14 @@ end # automatic type deduction for variadic arguments may not be what you want, please use with caution @generated function sc_io_source_new(iotype, encode, va_list...) - :(@ccall(libsc.sc_io_source_new(iotype::sc_io_type_t, encode::sc_io_encode_t; $(to_c_type_pairs(va_list)...))::Ptr{sc_io_source_t})) - end + :(@ccall( + libsc.sc_io_source_new( + iotype::sc_io_type_t, + encode::sc_io_encode_t; + $(to_c_type_pairs(va_list)...), + )::Ptr{sc_io_source_t} + )) +end """ sc_io_source_destroy(source) @@ -2687,10 +3305,15 @@ end Free data source. Calls [`sc_io_source_complete`](@ref) and requires it to return no error. This is to avoid discarding buffered data that has not been passed to read. ### Parameters -* `source`:\\[in,out\\] The source object to free. + + - `source`:\\[in,out\\] The source object to free. + ### Returns + 0 on success. Nonzero if an error is encountered or is\\_complete returns one. + ### Prototype + ```c int sc_io_source_destroy (sc_io_source_t * source); ``` @@ -2705,19 +3328,29 @@ end Read data from a source. The internal counters source->bytes\\_in and source->bytes\\_out are updated. Data is read until the data buffer has not enough room anymore, or source becomes empty. It is possible that data already read internally remains in the source object for the next call. Call [`sc_io_source_complete`](@ref) and check its return value to find out. Returns an error if bytes\\_out is NULL and less than bytes\\_avail are read. ### Parameters -* `source`:\\[in,out\\] The source object to read from. -* `data`:\\[in\\] Data buffer for reading from sink. If NULL the output data will be thrown away. -* `bytes_avail`:\\[in\\] Number of bytes available in data buffer. -* `bytes_out`:\\[in,out\\] If not NULL, byte count read into data buffer. Otherwise, requires to read exactly bytes\\_avail. + + - `source`:\\[in,out\\] The source object to read from. + - `data`:\\[in\\] Data buffer for reading from sink. If NULL the output data will be thrown away. + - `bytes_avail`:\\[in\\] Number of bytes available in data buffer. + - `bytes_out`:\\[in,out\\] If not NULL, byte count read into data buffer. Otherwise, requires to read exactly bytes\\_avail. + ### Returns + 0 on success, nonzero on error. + ### Prototype + ```c int sc_io_source_read (sc_io_source_t * source, void *data, size_t bytes_avail, size_t * bytes_out); ``` """ function sc_io_source_read(source, data, bytes_avail, bytes_out) - @ccall libsc.sc_io_source_read(source::Ptr{sc_io_source_t}, data::Ptr{Cvoid}, bytes_avail::Csize_t, bytes_out::Ptr{Csize_t})::Cint + @ccall libsc.sc_io_source_read( + source::Ptr{sc_io_source_t}, + data::Ptr{Cvoid}, + bytes_avail::Csize_t, + bytes_out::Ptr{Csize_t}, + )::Cint end """ @@ -2726,18 +3359,27 @@ end Determine whether all data buffered from source has been returned by read. If it returns SC\\_IO\\_ERROR\\_AGAIN, another [`sc_io_source_read`](@ref) is required. If the call returns no error, the internal counters source->bytes\\_in and source->bytes\\_out are returned to the caller if requested, and reset to 0. The internal state of the source is not changed otherwise. It is legal to continue reading from the source hereafter. ### Parameters -* `source`:\\[in,out\\] The source object to read from. -* `bytes_in`:\\[in,out\\] If not NULL and true is returned, the total size of the data sourced. -* `bytes_out`:\\[in,out\\] If not NULL and true is returned, total bytes passed out by source\\_read. + + - `source`:\\[in,out\\] The source object to read from. + - `bytes_in`:\\[in,out\\] If not NULL and true is returned, the total size of the data sourced. + - `bytes_out`:\\[in,out\\] If not NULL and true is returned, total bytes passed out by source\\_read. + ### Returns + SC\\_IO\\_ERROR\\_AGAIN if buffered data remaining. Otherwise return ERROR\\_NONE and reset counters. + ### Prototype + ```c int sc_io_source_complete (sc_io_source_t * source, size_t * bytes_in, size_t * bytes_out); ``` """ function sc_io_source_complete(source, bytes_in, bytes_out) - @ccall libsc.sc_io_source_complete(source::Ptr{sc_io_source_t}, bytes_in::Ptr{Csize_t}, bytes_out::Ptr{Csize_t})::Cint + @ccall libsc.sc_io_source_complete( + source::Ptr{sc_io_source_t}, + bytes_in::Ptr{Csize_t}, + bytes_out::Ptr{Csize_t}, + )::Cint end """ @@ -2746,11 +3388,16 @@ end Align source to a byte boundary by skipping. ### Parameters -* `source`:\\[in,out\\] The source object to align. -* `bytes_align`:\\[in\\] Byte boundary. + + - `source`:\\[in,out\\] The source object to align. + - `bytes_align`:\\[in\\] Byte boundary. + ### Returns + 0 on success, nonzero on error. + ### Prototype + ```c int sc_io_source_align (sc_io_source_t * source, size_t bytes_align); ``` @@ -2765,10 +3412,15 @@ end Activate a buffer that mirrors (i.e., stores) the data that was read. ### Parameters -* `source`:\\[in,out\\] The source object to activate mirror in. + + - `source`:\\[in,out\\] The source object to activate mirror in. + ### Returns + 0 on success, nonzero on error. + ### Prototype + ```c int sc_io_source_activate_mirror (sc_io_source_t * source); ``` @@ -2783,16 +3435,26 @@ end Read data from the source's mirror. Same behaviour as [`sc_io_source_read`](@ref). ### Parameters -* `source`:\\[in,out\\] The source object to read mirror data from. + + - `source`:\\[in,out\\] The source object to read mirror data from. + ### Returns + 0 on success, nonzero on error. + ### Prototype + ```c int sc_io_source_read_mirror (sc_io_source_t * source, void *data, size_t bytes_avail, size_t * bytes_out); ``` """ function sc_io_source_read_mirror(source, data, bytes_avail, bytes_out) - @ccall libsc.sc_io_source_read_mirror(source::Ptr{sc_io_source_t}, data::Ptr{Cvoid}, bytes_avail::Csize_t, bytes_out::Ptr{Csize_t})::Cint + @ccall libsc.sc_io_source_read_mirror( + source::Ptr{sc_io_source_t}, + data::Ptr{Cvoid}, + bytes_avail::Csize_t, + bytes_out::Ptr{Csize_t}, + )::Cint end """ @@ -2801,18 +3463,27 @@ end This function writes numeric binary data in VTK base64 encoding. ### Parameters -* `vtkfile`: Stream opened for writing. -* `numeric_data`: A pointer to a numeric data array. -* `byte_length`: The length of the data array in bytes. + + - `vtkfile`: Stream opened for writing. + - `numeric_data`: A pointer to a numeric data array. + - `byte_length`: The length of the data array in bytes. + ### Returns + Returns 0 on success, -1 on file error. + ### Prototype + ```c int sc_vtk_write_binary (FILE * vtkfile, char *numeric_data, size_t byte_length); ``` """ function sc_vtk_write_binary(vtkfile, numeric_data, byte_length) - @ccall libsc.sc_vtk_write_binary(vtkfile::Ptr{Libc.FILE}, numeric_data::Cstring, byte_length::Csize_t)::Cint + @ccall libsc.sc_vtk_write_binary( + vtkfile::Ptr{Libc.FILE}, + numeric_data::Cstring, + byte_length::Csize_t, + )::Cint end """ @@ -2821,18 +3492,27 @@ end This function writes numeric binary data in VTK compressed format. ### Parameters -* `vtkfile`: Stream opened for writing. -* `numeric_data`: A pointer to a numeric data array. -* `byte_length`: The length of the data array in bytes. + + - `vtkfile`: Stream opened for writing. + - `numeric_data`: A pointer to a numeric data array. + - `byte_length`: The length of the data array in bytes. + ### Returns + Returns 0 on success, -1 on file error. + ### Prototype + ```c int sc_vtk_write_compressed (FILE * vtkfile, char *numeric_data, size_t byte_length); ``` """ function sc_vtk_write_compressed(vtkfile, numeric_data, byte_length) - @ccall libsc.sc_vtk_write_compressed(vtkfile::Ptr{Libc.FILE}, numeric_data::Cstring, byte_length::Csize_t)::Cint + @ccall libsc.sc_vtk_write_compressed( + vtkfile::Ptr{Libc.FILE}, + numeric_data::Cstring, + byte_length::Csize_t, + )::Cint end """ @@ -2845,18 +3525,27 @@ Write memory content to a file. This function aborts on file errors. ### Parameters -* `ptr`:\\[in\\] Data array to write to disk. -* `size`:\\[in\\] Size of one array member. -* `nmemb`:\\[in\\] Number of array members. -* `file`:\\[in,out\\] File pointer, must be opened for writing. -* `errmsg`:\\[in\\] Error message passed to `SC_CHECK_ABORT`. + + - `ptr`:\\[in\\] Data array to write to disk. + - `size`:\\[in\\] Size of one array member. + - `nmemb`:\\[in\\] Number of array members. + - `file`:\\[in,out\\] File pointer, must be opened for writing. + - `errmsg`:\\[in\\] Error message passed to `SC_CHECK_ABORT`. + ### Prototype + ```c void sc_fwrite (const void *ptr, size_t size, size_t nmemb, FILE * file, const char *errmsg); ``` """ function sc_fwrite(ptr, size, nmemb, file, errmsg) - @ccall libsc.sc_fwrite(ptr::Ptr{Cvoid}, size::Csize_t, nmemb::Csize_t, file::Ptr{Libc.FILE}, errmsg::Cstring)::Cvoid + @ccall libsc.sc_fwrite( + ptr::Ptr{Cvoid}, + size::Csize_t, + nmemb::Csize_t, + file::Ptr{Libc.FILE}, + errmsg::Cstring, + )::Cvoid end """ @@ -2869,18 +3558,27 @@ Read file content into memory. This function aborts on file errors. ### Parameters -* `ptr`:\\[out\\] Data array to read from disk. -* `size`:\\[in\\] Size of one array member. -* `nmemb`:\\[in\\] Number of array members. -* `file`:\\[in,out\\] File pointer, must be opened for reading. -* `errmsg`:\\[in\\] Error message passed to `SC_CHECK_ABORT`. + + - `ptr`:\\[out\\] Data array to read from disk. + - `size`:\\[in\\] Size of one array member. + - `nmemb`:\\[in\\] Number of array members. + - `file`:\\[in,out\\] File pointer, must be opened for reading. + - `errmsg`:\\[in\\] Error message passed to `SC_CHECK_ABORT`. + ### Prototype + ```c void sc_fread (void *ptr, size_t size, size_t nmemb, FILE * file, const char *errmsg); ``` """ function sc_fread(ptr, size, nmemb, file, errmsg) - @ccall libsc.sc_fread(ptr::Ptr{Cvoid}, size::Csize_t, nmemb::Csize_t, file::Ptr{Libc.FILE}, errmsg::Cstring)::Cvoid + @ccall libsc.sc_fread( + ptr::Ptr{Cvoid}, + size::Csize_t, + nmemb::Csize_t, + file::Ptr{Libc.FILE}, + errmsg::Cstring, + )::Cvoid end """ @@ -2889,8 +3587,11 @@ end Best effort to flush a file's data to disc and close it. ### Parameters -* `file`:\\[in,out\\] File open for writing. + + - `file`:\\[in,out\\] File open for writing. + ### Prototype + ```c void sc_fflush_fsync_fclose (FILE * file); ``` @@ -2933,7 +3634,9 @@ Tags for MPI messages P4EST_COMM_TAG_LAST = 319 end -"""Tags for MPI messages""" +""" +Tags for MPI messages +""" const p4est_comm_tag_t = p4est_comm_tag """ @@ -2942,6 +3645,7 @@ const p4est_comm_tag_t = p4est_comm_tag Registers `p4est` with the SC Library and sets the logging behavior. This function is optional. This function must only be called before additional threads are created. If this function is not called or called with log\\_handler == NULL, the default SC log handler will be used. If this function is not called or called with log\\_threshold == `SC_LP_DEFAULT`, the default SC log threshold will be used. The default SC log settings can be changed with [`sc_set_log_defaults`](@ref) (). ### Prototype + ```c void p4est_init (sc_log_handler_t log_handler, int log_threshold); ``` @@ -2956,8 +3660,11 @@ end Return the full version of `p4est`. ### Returns + Return the version of `p4est` using the format `VERSION\\_MAJOR.VERSION\\_MINOR.VERSION\\_POINT`, where `VERSION_POINT` can contain dots and characters, e.g. to indicate the additional number of commits and a git commit hash. + ### Prototype + ```c const char *p4est_version (void); ``` @@ -2972,8 +3679,11 @@ end Return the major version of `p4est`. ### Returns + Return the major version of `p4est`. + ### Prototype + ```c int p4est_version_major (void); ``` @@ -2988,8 +3698,11 @@ end Return the minor version of `p4est`. ### Returns + Return the minor version of `p4est`. + ### Prototype + ```c int p4est_version_minor (void); ``` @@ -3016,9 +3729,9 @@ end Typedef for serialization method. -| Enumerator | Note | -| :--------------------------- | :-------------------------------- | -| P4EST\\_CONN\\_ENCODE\\_LAST | Invalid entry to close the list. | +| Enumerator | Note | +|:---------------------------- |:-------------------------------- | +| P4EST\\_CONN\\_ENCODE\\_LAST | Invalid entry to close the list. | """ @cenum p4est_connectivity_encode_t::UInt32 begin P4EST_CONN_ENCODE_NONE = 0 @@ -3031,10 +3744,15 @@ end Convert the [`p4est_connect_type_t`](@ref) into a number. ### Parameters -* `btype`:\\[in\\] The balance type to convert. -### Returns + + - `btype`:\\[in\\] The balance type to convert. + +### Returns + Returns 1 or 2. + ### Prototype + ```c int p4est_connect_type_int (p4est_connect_type_t btype); ``` @@ -3049,10 +3767,15 @@ end Convert the [`p4est_connect_type_t`](@ref) into a const string. ### Parameters -* `btype`:\\[in\\] The balance type to convert. + + - `btype`:\\[in\\] The balance type to convert. + ### Returns + Returns a pointer to a constant string. + ### Prototype + ```c const char *p4est_connect_type_string (p4est_connect_type_t btype); ``` @@ -3078,21 +3801,21 @@ The arrays corner\\_to\\_* store a variable number of entries per corner. For co The *\\_to\\_attr arrays may have arbitrary contents defined by the user. -| Field | Note | -| :------------------- | :----------------------------------------------------------------------------------- | -| num\\_vertices | the number of vertices that define the *embedding* of the forest (not the topology) | -| num\\_trees | the number of trees | -| num\\_corners | the number of corners that help define topology | -| vertices | an array of size (3 * *num_vertices*) | -| tree\\_to\\_vertex | embed each tree into ```c++ R^3 ``` for e.g. visualization (see p4est\\_vtk.h) | -| tree\\_attr\\_bytes | bytes per tree in tree\\_to\\_attr | -| tree\\_to\\_attr | not touched by `p4est` | -| tree\\_to\\_tree | (4 * *num_trees*) neighbors across faces | -| tree\\_to\\_face | (4 * *num_trees*) face to face+orientation (see description) | -| tree\\_to\\_corner | (4 * *num_trees*) or NULL (see description) | -| ctt\\_offset | corner to offset in *corner_to_tree* and *corner_to_corner* | -| corner\\_to\\_tree | list of trees that meet at a corner | -| corner\\_to\\_corner | list of tree-corners that meet at a corner | +| Field | Note | +|:-------------------- |:----------------------------------------------------------------------------------- | +| num\\_vertices | the number of vertices that define the *embedding* of the forest (not the topology) | +| num\\_trees | the number of trees | +| num\\_corners | the number of corners that help define topology | +| vertices | an array of size (3 * *num_vertices*) | +| tree\\_to\\_vertex | embed each tree into `c++ R^3 ` for e.g. visualization (see p4est\\_vtk.h) | +| tree\\_attr\\_bytes | bytes per tree in tree\\_to\\_attr | +| tree\\_to\\_attr | not touched by `p4est` | +| tree\\_to\\_tree | (4 * *num_trees*) neighbors across faces | +| tree\\_to\\_face | (4 * *num_trees*) face to face+orientation (see description) | +| tree\\_to\\_corner | (4 * *num_trees*) or NULL (see description) | +| ctt\\_offset | corner to offset in *corner_to_tree* and *corner_to_corner* | +| corner\\_to\\_tree | list of trees that meet at a corner | +| corner\\_to\\_corner | list of tree-corners that meet at a corner | """ struct p4est_connectivity num_vertices::p4est_topidx_t @@ -3133,10 +3856,15 @@ const p4est_connectivity_t = p4est_connectivity Calculate memory usage of a connectivity structure. ### Parameters -* `conn`:\\[in\\] Connectivity structure. + + - `conn`:\\[in\\] Connectivity structure. + ### Returns + Memory used in bytes. + ### Prototype + ```c size_t p4est_connectivity_memory_used (p4est_connectivity_t * conn); ``` @@ -3161,19 +3889,29 @@ end Transform a face corner across one of the adjacent faces into a neighbor tree. This version expects the neighbor face and orientation separately. ### Parameters -* `fc`:\\[in\\] A face corner number in 0..1. -* `f`:\\[in\\] A face that the face corner number *fc* is relative to. -* `nf`:\\[in\\] A neighbor face that is on the other side of . -* `o`:\\[in\\] The orientation between tree boundary faces *f* and . + + - `fc`:\\[in\\] A face corner number in 0..1. + - `f`:\\[in\\] A face that the face corner number *fc* is relative to. + - `nf`:\\[in\\] A neighbor face that is on the other side of . + - `o`:\\[in\\] The orientation between tree boundary faces *f* and . + ### Returns + The face corner number relative to the neighbor's face. + ### Prototype + ```c int p4est_connectivity_face_neighbor_face_corner (int fc, int f, int nf, int o); ``` """ function p4est_connectivity_face_neighbor_face_corner(fc, f, nf, o) - @ccall libp4est.p4est_connectivity_face_neighbor_face_corner(fc::Cint, f::Cint, nf::Cint, o::Cint)::Cint + @ccall libp4est.p4est_connectivity_face_neighbor_face_corner( + fc::Cint, + f::Cint, + nf::Cint, + o::Cint, + )::Cint end """ @@ -3182,19 +3920,29 @@ end Transform a corner across one of the adjacent faces into a neighbor tree. This version expects the neighbor face and orientation separately. ### Parameters -* `c`:\\[in\\] A corner number in 0..3. -* `f`:\\[in\\] A face number that touches the corner *c*. -* `nf`:\\[in\\] A neighbor face that is on the other side of . -* `o`:\\[in\\] The orientation between tree boundary faces *f* and . + + - `c`:\\[in\\] A corner number in 0..3. + - `f`:\\[in\\] A face number that touches the corner *c*. + - `nf`:\\[in\\] A neighbor face that is on the other side of . + - `o`:\\[in\\] The orientation between tree boundary faces *f* and . + ### Returns + The number of the corner seen from the neighbor tree. + ### Prototype + ```c int p4est_connectivity_face_neighbor_corner (int c, int f, int nf, int o); ``` """ function p4est_connectivity_face_neighbor_corner(c, f, nf, o) - @ccall libp4est.p4est_connectivity_face_neighbor_corner(c::Cint, f::Cint, nf::Cint, o::Cint)::Cint + @ccall libp4est.p4est_connectivity_face_neighbor_corner( + c::Cint, + f::Cint, + nf::Cint, + o::Cint, + )::Cint end """ @@ -3203,19 +3951,29 @@ end Allocate a connectivity structure. The attribute fields are initialized to NULL. ### Parameters -* `num_vertices`:\\[in\\] Number of total vertices (i.e. geometric points). -* `num_trees`:\\[in\\] Number of trees in the forest. -* `num_corners`:\\[in\\] Number of tree-connecting corners. -* `num_ctt`:\\[in\\] Number of total trees in corner\\_to\\_tree array. + + - `num_vertices`:\\[in\\] Number of total vertices (i.e. geometric points). + - `num_trees`:\\[in\\] Number of trees in the forest. + - `num_corners`:\\[in\\] Number of tree-connecting corners. + - `num_ctt`:\\[in\\] Number of total trees in corner\\_to\\_tree array. + ### Returns + A connectivity structure with allocated arrays. + ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_new (p4est_topidx_t num_vertices, p4est_topidx_t num_trees, p4est_topidx_t num_corners, p4est_topidx_t num_ctt); ``` """ function p4est_connectivity_new(num_vertices, num_trees, num_corners, num_ctt) - @ccall libp4est.p4est_connectivity_new(num_vertices::p4est_topidx_t, num_trees::p4est_topidx_t, num_corners::p4est_topidx_t, num_ctt::p4est_topidx_t)::Ptr{p4est_connectivity_t} + @ccall libp4est.p4est_connectivity_new( + num_vertices::p4est_topidx_t, + num_trees::p4est_topidx_t, + num_corners::p4est_topidx_t, + num_ctt::p4est_topidx_t, + )::Ptr{p4est_connectivity_t} end """ @@ -3224,31 +3982,65 @@ end Allocate a connectivity structure and populate from constants. The attribute fields are initialized to NULL. ### Parameters -* `num_vertices`:\\[in\\] Number of total vertices (i.e. geometric points). -* `num_trees`:\\[in\\] Number of trees in the forest. -* `num_corners`:\\[in\\] Number of tree-connecting corners. -* `coff`:\\[in\\] Corner-to-tree offsets (num\\_corners + 1 values). This must always be non-NULL; in trivial cases it is just a pointer to a p4est\\_topix value of 0. + + - `num_vertices`:\\[in\\] Number of total vertices (i.e. geometric points). + - `num_trees`:\\[in\\] Number of trees in the forest. + - `num_corners`:\\[in\\] Number of tree-connecting corners. + - `coff`:\\[in\\] Corner-to-tree offsets (num\\_corners + 1 values). This must always be non-NULL; in trivial cases it is just a pointer to a p4est\\_topix value of 0. + ### Returns + The connectivity is checked for validity. + ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_new_copy (p4est_topidx_t num_vertices, p4est_topidx_t num_trees, p4est_topidx_t num_corners, const double *vertices, const p4est_topidx_t * ttv, const p4est_topidx_t * ttt, const int8_t * ttf, const p4est_topidx_t * ttc, const p4est_topidx_t * coff, const p4est_topidx_t * ctt, const int8_t * ctc); ``` """ -function p4est_connectivity_new_copy(num_vertices, num_trees, num_corners, vertices, ttv, ttt, ttf, ttc, coff, ctt, ctc) - @ccall libp4est.p4est_connectivity_new_copy(num_vertices::p4est_topidx_t, num_trees::p4est_topidx_t, num_corners::p4est_topidx_t, vertices::Ptr{Cdouble}, ttv::Ptr{p4est_topidx_t}, ttt::Ptr{p4est_topidx_t}, ttf::Ptr{Int8}, ttc::Ptr{p4est_topidx_t}, coff::Ptr{p4est_topidx_t}, ctt::Ptr{p4est_topidx_t}, ctc::Ptr{Int8})::Ptr{p4est_connectivity_t} +function p4est_connectivity_new_copy( + num_vertices, + num_trees, + num_corners, + vertices, + ttv, + ttt, + ttf, + ttc, + coff, + ctt, + ctc, +) + @ccall libp4est.p4est_connectivity_new_copy( + num_vertices::p4est_topidx_t, + num_trees::p4est_topidx_t, + num_corners::p4est_topidx_t, + vertices::Ptr{Cdouble}, + ttv::Ptr{p4est_topidx_t}, + ttt::Ptr{p4est_topidx_t}, + ttf::Ptr{Int8}, + ttc::Ptr{p4est_topidx_t}, + coff::Ptr{p4est_topidx_t}, + ctt::Ptr{p4est_topidx_t}, + ctc::Ptr{Int8}, + )::Ptr{p4est_connectivity_t} end """ p4est_connectivity_bcast(conn_in, root, comm) ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_bcast (p4est_connectivity_t * conn_in, int root, sc_MPI_Comm comm); ``` """ function p4est_connectivity_bcast(conn_in, root, comm) - @ccall libp4est.p4est_connectivity_bcast(conn_in::Ptr{p4est_connectivity_t}, root::Cint, comm::MPI_Comm)::Ptr{p4est_connectivity_t} + @ccall libp4est.p4est_connectivity_bcast( + conn_in::Ptr{p4est_connectivity_t}, + root::Cint, + comm::MPI_Comm, + )::Ptr{p4est_connectivity_t} end """ @@ -3257,12 +4049,15 @@ end Destroy a connectivity structure. Also destroy all attributes. ### Prototype + ```c void p4est_connectivity_destroy (p4est_connectivity_t * connectivity); ``` """ function p4est_connectivity_destroy(connectivity) - @ccall libp4est.p4est_connectivity_destroy(connectivity::Ptr{p4est_connectivity_t})::Cvoid + @ccall libp4est.p4est_connectivity_destroy( + connectivity::Ptr{p4est_connectivity_t}, + )::Cvoid end """ @@ -3271,15 +4066,21 @@ end Allocate or free the attribute fields in a connectivity. ### Parameters -* `conn`:\\[in,out\\] The conn->*\\_to\\_attr fields must either be NULL or previously be allocated by this function. -* `bytes_per_tree`:\\[in\\] If 0, tree\\_to\\_attr is freed (being NULL is ok). If positive, requested space is allocated. + + - `conn`:\\[in,out\\] The conn->*\\_to\\_attr fields must either be NULL or previously be allocated by this function. + - `bytes_per_tree`:\\[in\\] If 0, tree\\_to\\_attr is freed (being NULL is ok). If positive, requested space is allocated. + ### Prototype + ```c void p4est_connectivity_set_attr (p4est_connectivity_t * conn, size_t bytes_per_tree); ``` """ function p4est_connectivity_set_attr(conn, bytes_per_tree) - @ccall libp4est.p4est_connectivity_set_attr(conn::Ptr{p4est_connectivity_t}, bytes_per_tree::Csize_t)::Cvoid + @ccall libp4est.p4est_connectivity_set_attr( + conn::Ptr{p4est_connectivity_t}, + bytes_per_tree::Csize_t, + )::Cvoid end """ @@ -3288,14 +4089,19 @@ end Examine a connectivity structure. ### Returns + Returns true if structure is valid, false otherwise. + ### Prototype + ```c int p4est_connectivity_is_valid (p4est_connectivity_t * connectivity); ``` """ function p4est_connectivity_is_valid(connectivity) - @ccall libp4est.p4est_connectivity_is_valid(connectivity::Ptr{p4est_connectivity_t})::Cint + @ccall libp4est.p4est_connectivity_is_valid( + connectivity::Ptr{p4est_connectivity_t}, + )::Cint end """ @@ -3304,14 +4110,20 @@ end Check two connectivity structures for equality. ### Returns + Returns true if structures are equal, false otherwise. + ### Prototype + ```c int p4est_connectivity_is_equal (p4est_connectivity_t * conn1, p4est_connectivity_t * conn2); ``` """ function p4est_connectivity_is_equal(conn1, conn2) - @ccall libp4est.p4est_connectivity_is_equal(conn1::Ptr{p4est_connectivity_t}, conn2::Ptr{p4est_connectivity_t})::Cint + @ccall libp4est.p4est_connectivity_is_equal( + conn1::Ptr{p4est_connectivity_t}, + conn2::Ptr{p4est_connectivity_t}, + )::Cint end """ @@ -3320,17 +4132,25 @@ end Write connectivity to a sink object. ### Parameters -* `conn`:\\[in\\] The connectivity to be written. -* `sink`:\\[in,out\\] The connectivity is written into this sink. + + - `conn`:\\[in\\] The connectivity to be written. + - `sink`:\\[in,out\\] The connectivity is written into this sink. + ### Returns + 0 on success, nonzero on error. + ### Prototype + ```c int p4est_connectivity_sink (p4est_connectivity_t * conn, sc_io_sink_t * sink); ``` """ function p4est_connectivity_sink(conn, sink) - @ccall libp4est.p4est_connectivity_sink(conn::Ptr{p4est_connectivity_t}, sink::Ptr{sc_io_sink_t})::Cint + @ccall libp4est.p4est_connectivity_sink( + conn::Ptr{p4est_connectivity_t}, + sink::Ptr{sc_io_sink_t}, + )::Cint end """ @@ -3339,17 +4159,25 @@ end Allocate memory and store the connectivity information there. ### Parameters -* `conn`:\\[in\\] The connectivity structure to be exported to memory. -* `code`:\\[in\\] Encoding and compression method for serialization. + + - `conn`:\\[in\\] The connectivity structure to be exported to memory. + - `code`:\\[in\\] Encoding and compression method for serialization. + ### Returns + Newly created array that contains the information. + ### Prototype + ```c sc_array_t *p4est_connectivity_deflate (p4est_connectivity_t * conn, p4est_connectivity_encode_t code); ``` """ function p4est_connectivity_deflate(conn, code) - @ccall libp4est.p4est_connectivity_deflate(conn::Ptr{p4est_connectivity_t}, code::p4est_connectivity_encode_t)::Ptr{sc_array_t} + @ccall libp4est.p4est_connectivity_deflate( + conn::Ptr{p4est_connectivity_t}, + code::p4est_connectivity_encode_t, + )::Ptr{sc_array_t} end """ @@ -3358,17 +4186,25 @@ end Save a connectivity structure to disk. ### Parameters -* `filename`:\\[in\\] Name of the file to write. -* `connectivity`:\\[in\\] Valid connectivity structure. + + - `filename`:\\[in\\] Name of the file to write. + - `connectivity`:\\[in\\] Valid connectivity structure. + ### Returns + Returns 0 on success, nonzero on file error. + ### Prototype + ```c int p4est_connectivity_save (const char *filename, p4est_connectivity_t * connectivity); ``` """ function p4est_connectivity_save(filename, connectivity) - @ccall libp4est.p4est_connectivity_save(filename::Cstring, connectivity::Ptr{p4est_connectivity_t})::Cint + @ccall libp4est.p4est_connectivity_save( + filename::Cstring, + connectivity::Ptr{p4est_connectivity_t}, + )::Cint end """ @@ -3377,16 +4213,23 @@ end Read connectivity from a source object. ### Parameters -* `source`:\\[in,out\\] The connectivity is read from this source. + + - `source`:\\[in,out\\] The connectivity is read from this source. + ### Returns + The newly created connectivity, or NULL on error. + ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_source (sc_io_source_t * source); ``` """ function p4est_connectivity_source(source) - @ccall libp4est.p4est_connectivity_source(source::Ptr{sc_io_source_t})::Ptr{p4est_connectivity_t} + @ccall libp4est.p4est_connectivity_source( + source::Ptr{sc_io_source_t}, + )::Ptr{p4est_connectivity_t} end """ @@ -3395,16 +4238,23 @@ end Create new connectivity from a memory buffer. ### Parameters -* `buffer`:\\[in\\] The connectivity is created from this memory buffer. + + - `buffer`:\\[in\\] The connectivity is created from this memory buffer. + ### Returns + The newly created connectivity, or NULL on error. + ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_inflate (sc_array_t * buffer); ``` """ function p4est_connectivity_inflate(buffer) - @ccall libp4est.p4est_connectivity_inflate(buffer::Ptr{sc_array_t})::Ptr{p4est_connectivity_t} + @ccall libp4est.p4est_connectivity_inflate( + buffer::Ptr{sc_array_t}, + )::Ptr{p4est_connectivity_t} end """ @@ -3413,17 +4263,25 @@ end Load a connectivity structure from disk. ### Parameters -* `filename`:\\[in\\] Name of the file to read. -* `bytes`:\\[in,out\\] Size in bytes of connectivity on disk or NULL. + + - `filename`:\\[in\\] Name of the file to read. + - `bytes`:\\[in,out\\] Size in bytes of connectivity on disk or NULL. + ### Returns + Returns valid connectivity, or NULL on file error. + ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_load (const char *filename, size_t *bytes); ``` """ function p4est_connectivity_load(filename, bytes) - @ccall libp4est.p4est_connectivity_load(filename::Cstring, bytes::Ptr{Csize_t})::Ptr{p4est_connectivity_t} + @ccall libp4est.p4est_connectivity_load( + filename::Cstring, + bytes::Ptr{Csize_t}, + )::Ptr{p4est_connectivity_t} end """ @@ -3432,6 +4290,7 @@ end Create a connectivity structure for the unit square. ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_new_unitsquare (void); ``` @@ -3446,6 +4305,7 @@ end Create a connectivity structure for an all-periodic unit square. ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_new_periodic (void); ``` @@ -3460,6 +4320,7 @@ end Create a connectivity structure for a periodic unit square. The left and right faces are identified, and bottom and top opposite. ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_new_rotwrap (void); ``` @@ -3474,16 +4335,23 @@ end Create a connectivity structure for two trees being rotated w.r.t. each other in a user-defined way ### Parameters -* `l_face`:\\[in\\] index of left face -* `r_face`:\\[in\\] index of right face -* `orientation`:\\[in\\] orientation of trees w.r.t. each other + + - `l_face`:\\[in\\] index of left face + - `r_face`:\\[in\\] index of right face + - `orientation`:\\[in\\] orientation of trees w.r.t. each other + ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_new_twotrees (int l_face, int r_face, int orientation); ``` """ function p4est_connectivity_new_twotrees(l_face, r_face, orientation) - @ccall libp4est.p4est_connectivity_new_twotrees(l_face::Cint, r_face::Cint, orientation::Cint)::Ptr{p4est_connectivity_t} + @ccall libp4est.p4est_connectivity_new_twotrees( + l_face::Cint, + r_face::Cint, + orientation::Cint, + )::Ptr{p4est_connectivity_t} end """ @@ -3492,6 +4360,7 @@ end Create a connectivity structure for a three-tree mesh around a corner. ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_new_corner (void); ``` @@ -3506,6 +4375,7 @@ end Create a connectivity structure for two trees on top of each other. ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_new_pillow (void); ``` @@ -3520,6 +4390,7 @@ end Create a connectivity structure for a five-tree moebius band. ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_new_moebius (void); ``` @@ -3534,6 +4405,7 @@ end Create a connectivity structure for a six-tree star. ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_new_star (void); ``` @@ -3548,6 +4420,7 @@ end Create a connectivity structure for the six sides of a unit cube. The ordering of the trees is as follows: 0 1 2 3 <-- 3: axis-aligned top side 4 5. This choice has been made for maximum symmetry (see tree\\_to\\_* in .c file). ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_new_cubed (void); ``` @@ -3562,8 +4435,11 @@ end Create a connectivity structure for a five-tree flat spherical disk. This disk can just as well be used as a square to test non-Cartesian maps. Without any mapping this connectivity covers the square [-3, 3]**2. ### Returns + Initialized and usable connectivity. + ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_new_disk_nonperiodic (void); ``` @@ -3588,17 +4464,25 @@ The outside x faces may be identified topologically. The outside y faces may be When setting *periodic_a* and *periodic_b* to false, the result is the same as that of p4est_connectivity_new_disk_nonperiodic. ### Parameters -* `periodic_a`:\\[in\\] Bool to make disk periodic in x direction. -* `periodic_b`:\\[in\\] Bool to make disk periodic in y direction. + + - `periodic_a`:\\[in\\] Bool to make disk periodic in x direction. + - `periodic_b`:\\[in\\] Bool to make disk periodic in y direction. + ### Returns + Initialized and usable connectivity. + ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_new_disk (int periodic_a, int periodic_b); ``` """ function p4est_connectivity_new_disk(periodic_a, periodic_b) - @ccall libp4est.p4est_connectivity_new_disk(periodic_a::Cint, periodic_b::Cint)::Ptr{p4est_connectivity_t} + @ccall libp4est.p4est_connectivity_new_disk( + periodic_a::Cint, + periodic_b::Cint, + )::Ptr{p4est_connectivity_t} end # no prototype is found for this function at p4est_connectivity.h:475:23, please use with caution @@ -3622,6 +4506,7 @@ Tree numbering: 0 2 4 6 8 1 3 5 7 9 ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_new_icosahedron (); ``` @@ -3636,6 +4521,7 @@ end Create a connectivity structure that builds a 2d spherical shell. p8est_connectivity_new_shell ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_new_shell2d (void); ``` @@ -3652,6 +4538,7 @@ Create a connectivity structure that maps a 2d disk. This is a 5 trees connectivity meant to be used together with p4est_geometry_new_disk2d to map the disk. ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_new_disk2d (void); ``` @@ -3666,12 +4553,18 @@ end A rectangular m by n array of trees with configurable periodicity. The brick is periodic in x and y if periodic\\_a and periodic\\_b are true, respectively. ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_new_brick (int mi, int ni, int periodic_a, int periodic_b); ``` """ function p4est_connectivity_new_brick(mi, ni, periodic_a, periodic_b) - @ccall libp4est.p4est_connectivity_new_brick(mi::Cint, ni::Cint, periodic_a::Cint, periodic_b::Cint)::Ptr{p4est_connectivity_t} + @ccall libp4est.p4est_connectivity_new_brick( + mi::Cint, + ni::Cint, + periodic_a::Cint, + periodic_b::Cint, + )::Ptr{p4est_connectivity_t} end """ @@ -3680,10 +4573,15 @@ end Create connectivity structure from predefined catalogue. ### Parameters -* `name`:\\[in\\] Invokes connectivity\\_new\\_* function. brick23 brick (2, 3, 0, 0) corner corner cubed cubed disk disk moebius moebius periodic periodic pillow pillow rotwrap rotwrap star star unit unitsquare + + - `name`:\\[in\\] Invokes connectivity\\_new\\_* function. brick23 brick (2, 3, 0, 0) corner corner cubed cubed disk disk moebius moebius periodic periodic pillow pillow rotwrap rotwrap star star unit unitsquare + ### Returns + An initialized connectivity if name is defined, NULL else. + ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_new_byname (const char *name); ``` @@ -3698,17 +4596,25 @@ end Uniformly refine a connectivity. This is useful if you would like to uniformly refine by something other than a power of 2. ### Parameters -* `conn`:\\[in\\] A valid connectivity -* `num_per_edge`:\\[in\\] The number of new trees in each direction. Must use no more than P4EST_OLD_QMAXLEVEL bits. + + - `conn`:\\[in\\] A valid connectivity + - `num_per_edge`:\\[in\\] The number of new trees in each direction. Must use no more than P4EST_OLD_QMAXLEVEL bits. + ### Returns + a refined connectivity. + ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_refine (p4est_connectivity_t * conn, int num_per_edge); ``` """ function p4est_connectivity_refine(conn, num_per_edge) - @ccall libp4est.p4est_connectivity_refine(conn::Ptr{p4est_connectivity_t}, num_per_edge::Cint)::Ptr{p4est_connectivity_t} + @ccall libp4est.p4est_connectivity_refine( + conn::Ptr{p4est_connectivity_t}, + num_per_edge::Cint, + )::Ptr{p4est_connectivity_t} end """ @@ -3717,16 +4623,23 @@ end Fill an array with the axis combination of a face neighbor transform. ### Parameters -* `iface`:\\[in\\] The number of the originating face. -* `nface`:\\[in\\] Encoded as nface = r * 4 + nf, where nf = 0..3 is the neigbbor's connecting face number and r = 0..1 is the relative orientation to the neighbor's face. This encoding matches [`p4est_connectivity_t`](@ref). -* `ftransform`:\\[out\\] This array holds 9 integers. [0,2] The coordinate axis sequence of the origin face, the first referring to the tangential and the second to the normal. A permutation of (0, 1). [3,5] The coordinate axis sequence of the target face. [6,8] Edge reversal flag for tangential axis (boolean); face code in [0, 3] for the normal coordinate q: 0: q' = -q 1: q' = q + 1 2: q' = q - 1 3: q' = 2 - q [1,4,7] 0 (unused for compatibility with 3D). + + - `iface`:\\[in\\] The number of the originating face. + - `nface`:\\[in\\] Encoded as nface = r * 4 + nf, where nf = 0..3 is the neigbbor's connecting face number and r = 0..1 is the relative orientation to the neighbor's face. This encoding matches [`p4est_connectivity_t`](@ref). + - `ftransform`:\\[out\\] This array holds 9 integers. [0,2] The coordinate axis sequence of the origin face, the first referring to the tangential and the second to the normal. A permutation of (0, 1). [3,5] The coordinate axis sequence of the target face. [6,8] Edge reversal flag for tangential axis (boolean); face code in [0, 3] for the normal coordinate q: 0: q' = -q 1: q' = q + 1 2: q' = q - 1 3: q' = 2 - q [1,4,7] 0 (unused for compatibility with 3D). + ### Prototype + ```c void p4est_expand_face_transform (int iface, int nface, int ftransform[]); ``` """ function p4est_expand_face_transform(iface, nface, ftransform) - @ccall libp4est.p4est_expand_face_transform(iface::Cint, nface::Cint, ftransform::Ptr{Cint})::Cvoid + @ccall libp4est.p4est_expand_face_transform( + iface::Cint, + nface::Cint, + ftransform::Ptr{Cint}, + )::Cvoid end """ @@ -3735,18 +4648,28 @@ end Fill an array with the axis combinations of a tree neighbor transform. ### Parameters -* `itree`:\\[in\\] The number of the originating tree. -* `iface`:\\[in\\] The number of the originating tree's face. -* `ftransform`:\\[out\\] This array holds 9 integers. [0,2] The coordinate axis sequence of the origin face. [3,5] The coordinate axis sequence of the target face. [6,8] Edge reverse flag for axis t; face code for axis n. [1,4,7] 0 (unused for compatibility with 3D). + + - `itree`:\\[in\\] The number of the originating tree. + - `iface`:\\[in\\] The number of the originating tree's face. + - `ftransform`:\\[out\\] This array holds 9 integers. [0,2] The coordinate axis sequence of the origin face. [3,5] The coordinate axis sequence of the target face. [6,8] Edge reverse flag for axis t; face code for axis n. [1,4,7] 0 (unused for compatibility with 3D). + ### Returns + The face neighbor tree if it exists, -1 otherwise. + ### Prototype + ```c p4est_topidx_t p4est_find_face_transform (p4est_connectivity_t * connectivity, p4est_topidx_t itree, int iface, int ftransform[]); ``` """ function p4est_find_face_transform(connectivity, itree, iface, ftransform) - @ccall libp4est.p4est_find_face_transform(connectivity::Ptr{p4est_connectivity_t}, itree::p4est_topidx_t, iface::Cint, ftransform::Ptr{Cint})::p4est_topidx_t + @ccall libp4est.p4est_find_face_transform( + connectivity::Ptr{p4est_connectivity_t}, + itree::p4est_topidx_t, + iface::Cint, + ftransform::Ptr{Cint}, + )::p4est_topidx_t end """ @@ -3755,16 +4678,24 @@ end Fills an array with information about corner neighbors. ### Parameters -* `itree`:\\[in\\] The number of the originating tree. -* `icorner`:\\[in\\] The number of the originating corner. -* `ci`:\\[in,out\\] A `p4est_corner_info_t` structure with initialized array. + + - `itree`:\\[in\\] The number of the originating tree. + - `icorner`:\\[in\\] The number of the originating corner. + - `ci`:\\[in,out\\] A `p4est_corner_info_t` structure with initialized array. + ### Prototype + ```c void p4est_find_corner_transform (p4est_connectivity_t * connectivity, p4est_topidx_t itree, int icorner, p4est_corner_info_t * ci); ``` """ function p4est_find_corner_transform(connectivity, itree, icorner, ci) - @ccall libp4est.p4est_find_corner_transform(connectivity::Ptr{p4est_connectivity_t}, itree::p4est_topidx_t, icorner::Cint, ci::Ptr{p4est_corner_info_t})::Cvoid + @ccall libp4est.p4est_find_corner_transform( + connectivity::Ptr{p4est_connectivity_t}, + itree::p4est_topidx_t, + icorner::Cint, + ci::Ptr{p4est_corner_info_t}, + )::Cvoid end """ @@ -3773,8 +4704,11 @@ end Internally connect a connectivity based on tree\\_to\\_vertex information. Periodicity that is not inherent in the list of vertices will be lost. ### Parameters -* `conn`:\\[in,out\\] The connectivity needs to have proper vertices and tree\\_to\\_vertex fields. The tree\\_to\\_tree and tree\\_to\\_face fields must be allocated and satisfy [`p4est_connectivity_is_valid`](@ref) (conn) but will be overwritten. The corner fields will be freed and allocated anew. + + - `conn`:\\[in,out\\] The connectivity needs to have proper vertices and tree\\_to\\_vertex fields. The tree\\_to\\_tree and tree\\_to\\_face fields must be allocated and satisfy [`p4est_connectivity_is_valid`](@ref) (conn) but will be overwritten. The corner fields will be freed and allocated anew. + ### Prototype + ```c void p4est_connectivity_complete (p4est_connectivity_t * conn); ``` @@ -3789,8 +4723,11 @@ end Removes corner information of a connectivity such that enough information is left to run [`p4est_connectivity_complete`](@ref) successfully. The reduced connectivity still passes [`p4est_connectivity_is_valid`](@ref). ### Parameters -* `conn`:\\[in,out\\] The connectivity to be reduced. + + - `conn`:\\[in,out\\] The connectivity to be reduced. + ### Prototype + ```c void p4est_connectivity_reduce (p4est_connectivity_t * conn); ``` @@ -3805,16 +4742,23 @@ end [`p4est_connectivity_permute`](@ref) Given a permutation *perm* of the trees in a connectivity *conn*, permute the trees of *conn* in place and update *conn* to match. ### Parameters -* `conn`:\\[in,out\\] The connectivity whose trees are permuted. -* `perm`:\\[in\\] A permutation array, whose elements are size\\_t's. -* `is_current_to_new`:\\[in\\] if true, the jth entry of perm is the new index for the entry whose current index is j, otherwise the jth entry of perm is the current index of the tree whose index will be j after the permutation. + + - `conn`:\\[in,out\\] The connectivity whose trees are permuted. + - `perm`:\\[in\\] A permutation array, whose elements are size\\_t's. + - `is_current_to_new`:\\[in\\] if true, the jth entry of perm is the new index for the entry whose current index is j, otherwise the jth entry of perm is the current index of the tree whose index will be j after the permutation. + ### Prototype + ```c void p4est_connectivity_permute (p4est_connectivity_t * conn, sc_array_t * perm, int is_current_to_new); ``` """ function p4est_connectivity_permute(conn, perm, is_current_to_new) - @ccall libp4est.p4est_connectivity_permute(conn::Ptr{p4est_connectivity_t}, perm::Ptr{sc_array_t}, is_current_to_new::Cint)::Cvoid + @ccall libp4est.p4est_connectivity_permute( + conn::Ptr{p4est_connectivity_t}, + perm::Ptr{sc_array_t}, + is_current_to_new::Cint, + )::Cvoid end """ @@ -3823,19 +4767,36 @@ end [`p4est_connectivity_join_faces`](@ref) This function takes an existing valid connectivity *conn* and modifies it by joining two tree faces that are currently boundary faces. ### Parameters -* `conn`:\\[in,out\\] connectivity that will be altered. -* `tree_left`:\\[in\\] tree that will be on the left side of the joined faces. -* `tree_right`:\\[in\\] tree that will be on the right side of the joined faces. -* `face_left`:\\[in\\] face of *tree_left* that will be joined. -* `face_right`:\\[in\\] face of *tree_right* that will be joined. -* `orientation`:\\[in\\] the orientation of *face_left* and *face_right* once joined (see the description of [`p4est_connectivity_t`](@ref) to understand orientation). + + - `conn`:\\[in,out\\] connectivity that will be altered. + - `tree_left`:\\[in\\] tree that will be on the left side of the joined faces. + - `tree_right`:\\[in\\] tree that will be on the right side of the joined faces. + - `face_left`:\\[in\\] face of *tree_left* that will be joined. + - `face_right`:\\[in\\] face of *tree_right* that will be joined. + - `orientation`:\\[in\\] the orientation of *face_left* and *face_right* once joined (see the description of [`p4est_connectivity_t`](@ref) to understand orientation). + ### Prototype + ```c void p4est_connectivity_join_faces (p4est_connectivity_t * conn, p4est_topidx_t tree_left, p4est_topidx_t tree_right, int face_left, int face_right, int orientation); ``` """ -function p4est_connectivity_join_faces(conn, tree_left, tree_right, face_left, face_right, orientation) - @ccall libp4est.p4est_connectivity_join_faces(conn::Ptr{p4est_connectivity_t}, tree_left::p4est_topidx_t, tree_right::p4est_topidx_t, face_left::Cint, face_right::Cint, orientation::Cint)::Cvoid +function p4est_connectivity_join_faces( + conn, + tree_left, + tree_right, + face_left, + face_right, + orientation, +) + @ccall libp4est.p4est_connectivity_join_faces( + conn::Ptr{p4est_connectivity_t}, + tree_left::p4est_topidx_t, + tree_right::p4est_topidx_t, + face_left::Cint, + face_right::Cint, + orientation::Cint, + )::Cvoid end """ @@ -3844,15 +4805,21 @@ end [`p4est_connectivity_is_equivalent`](@ref) This function compares two connectivities for equivalence: it returns *true* if they are the same connectivity, or if they have the same topology. The definition of topological sameness is strict: there is no attempt made to determine whether permutation and/or rotation of the trees makes the connectivities equivalent. ### Parameters -* `conn1`:\\[in\\] a valid connectivity -* `conn2`:\\[out\\] a valid connectivity + + - `conn1`:\\[in\\] a valid connectivity + - `conn2`:\\[out\\] a valid connectivity + ### Prototype + ```c int p4est_connectivity_is_equivalent (p4est_connectivity_t * conn1, p4est_connectivity_t * conn2); ``` """ function p4est_connectivity_is_equivalent(conn1, conn2) - @ccall libp4est.p4est_connectivity_is_equivalent(conn1::Ptr{p4est_connectivity_t}, conn2::Ptr{p4est_connectivity_t})::Cint + @ccall libp4est.p4est_connectivity_is_equivalent( + conn1::Ptr{p4est_connectivity_t}, + conn2::Ptr{p4est_connectivity_t}, + )::Cint end """ @@ -3897,20 +4864,37 @@ and in 3D they are given as: This code can be called two ways. The first, when `vertex`==NULL and `tree_to_vertex`==NULL, is used to count the number of trees and vertices in the connectivity to be generated by the `.inp` mesh in the *stream*. The second, when `vertices`!=NULL and `tree_to_vertex`!=NULL, fill `vertices` and `tree_to_vertex`. In this case `num_vertices` and `num_trees` need to be set to the maximum number of entries allocated in `vertices` and `tree_to_vertex`. ### Parameters -* `stream`:\\[in,out\\] file stream to read the connectivity from -* `num_vertices`:\\[in,out\\] the number of vertices in the connectivity -* `num_trees`:\\[in,out\\] the number of trees in the connectivity -* `vertices`:\\[out\\] the list of `vertices` of the connectivity -* `tree_to_vertex`:\\[out\\] the `tree_to_vertex` map of the connectivity + + - `stream`:\\[in,out\\] file stream to read the connectivity from + - `num_vertices`:\\[in,out\\] the number of vertices in the connectivity + - `num_trees`:\\[in,out\\] the number of trees in the connectivity + - `vertices`:\\[out\\] the list of `vertices` of the connectivity + - `tree_to_vertex`:\\[out\\] the `tree_to_vertex` map of the connectivity + ### Returns + 0 if successful and nonzero if not + ### Prototype + ```c int p4est_connectivity_read_inp_stream (FILE * stream, p4est_topidx_t * num_vertices, p4est_topidx_t * num_trees, double *vertices, p4est_topidx_t * tree_to_vertex); ``` """ -function p4est_connectivity_read_inp_stream(stream, num_vertices, num_trees, vertices, tree_to_vertex) - @ccall libp4est.p4est_connectivity_read_inp_stream(stream::Ptr{Libc.FILE}, num_vertices::Ptr{p4est_topidx_t}, num_trees::Ptr{p4est_topidx_t}, vertices::Ptr{Cdouble}, tree_to_vertex::Ptr{p4est_topidx_t})::Cint +function p4est_connectivity_read_inp_stream( + stream, + num_vertices, + num_trees, + vertices, + tree_to_vertex, +) + @ccall libp4est.p4est_connectivity_read_inp_stream( + stream::Ptr{Libc.FILE}, + num_vertices::Ptr{p4est_topidx_t}, + num_trees::Ptr{p4est_topidx_t}, + vertices::Ptr{Cdouble}, + tree_to_vertex::Ptr{p4est_topidx_t}, + )::Cint end """ @@ -3955,16 +4939,23 @@ and in 3D they are given as: This function reads a mesh from *filename* and returns an associated `p4est` connectivity. ### Parameters -* `filename`:\\[in\\] file to read the connectivity from + + - `filename`:\\[in\\] file to read the connectivity from + ### Returns + an allocated connectivity associated with the mesh in *filename* or NULL if an error occurred. + ### Prototype + ```c p4est_connectivity_t *p4est_connectivity_read_inp (const char *filename); ``` """ function p4est_connectivity_read_inp(filename) - @ccall libp4est.p4est_connectivity_read_inp(filename::Cstring)::Ptr{p4est_connectivity_t} + @ccall libp4est.p4est_connectivity_read_inp( + filename::Cstring, + )::Ptr{p4est_connectivity_t} end """ @@ -3972,24 +4963,26 @@ end The `p4est` tree datatype -| Field | Note | -| :----------------- | :----------------------------------------------------------------- | -| quadrants | locally stored quadrants | -| first\\_desc | first local descendant | -| last\\_desc | last local descendant | -| quadrants\\_offset | cumulative sum over earlier trees on this processor (locals only) | -| maxlevel | highest local quadrant level | +| Field | Note | +|:------------------ |:----------------------------------------------------------------- | +| quadrants | locally stored quadrants | +| first\\_desc | first local descendant | +| last\\_desc | last local descendant | +| quadrants\\_offset | cumulative sum over earlier trees on this processor (locals only) | +| maxlevel | highest local quadrant level | """ struct p4est_tree quadrants::sc_array_t first_desc::p4est_quadrant_t last_desc::p4est_quadrant_t quadrants_offset::p4est_locidx_t - quadrants_per_level::NTuple{31, p4est_locidx_t} + quadrants_per_level::NTuple{31,p4est_locidx_t} maxlevel::Int8 end -"""The `p4est` tree datatype""" +""" +The `p4est` tree datatype +""" const p4est_tree_t = p4est_tree """ @@ -3999,15 +4992,15 @@ Data pertaining to selecting, inspecting, and profiling algorithms. A pointer to The balance\\_ranges and balance\\_notify* times are collected whenever an inspect structure is present in `p4est`. -| Field | Note | -| :------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------ | -| use\\_balance\\_ranges | Use sc\\_ranges to determine the asymmetric communication pattern. If *use_balance_ranges* is false (the default), sc\\_notify is used. | -| use\\_balance\\_ranges\\_notify | If true, call both sc\\_ranges and sc\\_notify and verify consistency. Which is actually used is still determined by *use_balance_ranges*. | -| use\\_balance\\_verify | Verify sc\\_ranges and/or sc\\_notify as applicable. | -| balance\\_max\\_ranges | If positive and smaller than p4est\\_num ranges, overrides it | -| balance\\_ranges | time spent in sc\\_ranges | -| balance\\_notify | time spent in sc\\_notify | -| balance\\_notify\\_allgather | time spent in sc\\_notify\\_allgather | +| Field | Note | +|:------------------------------- |:------------------------------------------------------------------------------------------------------------------------------------------ | +| use\\_balance\\_ranges | Use sc\\_ranges to determine the asymmetric communication pattern. If *use_balance_ranges* is false (the default), sc\\_notify is used. | +| use\\_balance\\_ranges\\_notify | If true, call both sc\\_ranges and sc\\_notify and verify consistency. Which is actually used is still determined by *use_balance_ranges*. | +| use\\_balance\\_verify | Verify sc\\_ranges and/or sc\\_notify as applicable. | +| balance\\_max\\_ranges | If positive and smaller than p4est\\_num ranges, overrides it | +| balance\\_ranges | time spent in sc\\_ranges | +| balance\\_notify | time spent in sc\\_notify | +| balance\\_notify\\_allgather | time spent in sc\\_notify\\_allgather | """ struct p4est_inspect use_balance_ranges::Cint @@ -4020,8 +5013,8 @@ struct p4est_inspect balance_comm_nzpeers::Csize_t balance_B_count_in::Csize_t balance_B_count_out::Csize_t - balance_zero_sends::NTuple{2, Csize_t} - balance_zero_receives::NTuple{2, Csize_t} + balance_zero_sends::NTuple{2,Csize_t} + balance_zero_receives::NTuple{2,Csize_t} balance_A::Cdouble balance_comm::Cdouble balance_B::Cdouble @@ -4031,31 +5024,33 @@ struct p4est_inspect use_B::Cint end -"""Data pertaining to selecting, inspecting, and profiling algorithms. A pointer to this structure is hooked into the `p4est` main structure. Declared in p4est\\_extended.h. Used to profile important algorithms.""" +""" +Data pertaining to selecting, inspecting, and profiling algorithms. A pointer to this structure is hooked into the `p4est` main structure. Declared in p4est\\_extended.h. Used to profile important algorithms. +""" const p4est_inspect_t = p4est_inspect """ p4est -| Field | Note | -| :------------------------ | :--------------------------------------------------------------------------------------------------------------- | -| mpisize | number of MPI processes | -| mpirank | this process's MPI rank | -| mpicomm\\_owned | flag if communicator is owned | -| data\\_size | size of per-quadrant p.user\\_data (see [`p4est_quadrant_t`](@ref)::[`p4est_quadrant_data`](@ref)::user\\_data) | -| user\\_pointer | convenience pointer for users, never touched by `p4est` | -| revision | Gets bumped on mesh change | -| first\\_local\\_tree | 0-based index of first local tree, must be -1 for an empty processor | -| last\\_local\\_tree | 0-based index of last local tree, must be -2 for an empty processor | -| local\\_num\\_quadrants | number of quadrants on all trees on this processor | -| global\\_num\\_quadrants | number of quadrants on all trees on all processors | -| global\\_first\\_quadrant | first global quadrant index for each process and 1 beyond | -| global\\_first\\_position | first smallest possible quad for each process and 1 beyond | -| connectivity | connectivity structure, not owned | -| trees | array of all trees | -| user\\_data\\_pool | memory allocator for user data | -| quadrant\\_pool | memory allocator for temporary quadrants | -| inspect | algorithmic switches | +| Field | Note | +|:------------------------- |:--------------------------------------------------------------------------------------------------------------- | +| mpisize | number of MPI processes | +| mpirank | this process's MPI rank | +| mpicomm\\_owned | flag if communicator is owned | +| data\\_size | size of per-quadrant p.user\\_data (see [`p4est_quadrant_t`](@ref)::[`p4est_quadrant_data`](@ref)::user\\_data) | +| user\\_pointer | convenience pointer for users, never touched by `p4est` | +| revision | Gets bumped on mesh change | +| first\\_local\\_tree | 0-based index of first local tree, must be -1 for an empty processor | +| last\\_local\\_tree | 0-based index of last local tree, must be -2 for an empty processor | +| local\\_num\\_quadrants | number of quadrants on all trees on this processor | +| global\\_num\\_quadrants | number of quadrants on all trees on all processors | +| global\\_first\\_quadrant | first global quadrant index for each process and 1 beyond | +| global\\_first\\_position | first smallest possible quad for each process and 1 beyond | +| connectivity | connectivity structure, not owned | +| trees | array of all trees | +| user\\_data\\_pool | memory allocator for user data | +| quadrant\\_pool | memory allocator for temporary quadrants | +| inspect | algorithmic switches | """ struct p4est mpicomm::MPI_Comm @@ -4078,7 +5073,9 @@ struct p4est inspect::Ptr{p4est_inspect_t} end -"""The `p4est` forest datatype""" +""" +The `p4est` forest datatype +""" const p4est_t = p4est """ @@ -4087,10 +5084,15 @@ const p4est_t = p4est Calculate local memory usage of a forest structure. Not collective. The memory used on the current rank is returned. The connectivity structure is not counted since it is not owned; use p4est\\_connectivity\\_memory\\_usage (`p4est`->connectivity). ### Parameters -* `p4est`:\\[in\\] Valid forest structure. + + - `p4est`:\\[in\\] Valid forest structure. + ### Returns + Memory used in bytes. + ### Prototype + ```c size_t p4est_memory_used (p4est_t * p4est); ``` @@ -4105,10 +5107,15 @@ end Return the revision counter of the forest. Not collective, even though the revision value is the same on all ranks. A newly created forest starts with a revision counter of zero. Every refine, coarsen, partition, and balance that actually changes the mesh increases the counter by one. Operations with no effect keep the old value. ### Parameters -* `p8est`:\\[in\\] The forest must be valid. + + - `p8est`:\\[in\\] The forest must be valid. + ### Returns + Non-negative number. + ### Prototype + ```c long p4est_revision (p4est_t * p4est); ``` @@ -4122,9 +5129,10 @@ end Callback function prototype to initialize the quadrant's user data. ### Parameters -* `p4est`:\\[in\\] the forest -* `which_tree`:\\[in\\] the tree containing *quadrant* -* `quadrant`:\\[in,out\\] the quadrant to be initialized: if data\\_size > 0, the data to be initialized is at *quadrant*->p.user_data; otherwise, the non-pointer user data (such as *quadrant*->p.user_int) can be initialized + + - `p4est`:\\[in\\] the forest + - `which_tree`:\\[in\\] the tree containing *quadrant* + - `quadrant`:\\[in,out\\] the quadrant to be initialized: if data\\_size > 0, the data to be initialized is at *quadrant*->p.user_data; otherwise, the non-pointer user data (such as *quadrant*->p.user_int) can be initialized """ const p4est_init_t = Ptr{Cvoid} @@ -4133,10 +5141,13 @@ const p4est_init_t = Ptr{Cvoid} Callback function prototype to decide for refinement. ### Parameters -* `p4est`:\\[in\\] the forest -* `which_tree`:\\[in\\] the tree containing *quadrant* -* `quadrant`:\\[in\\] the quadrant that may be refined + + - `p4est`:\\[in\\] the forest + - `which_tree`:\\[in\\] the tree containing *quadrant* + - `quadrant`:\\[in\\] the quadrant that may be refined + ### Returns + nonzero if the quadrant shall be refined. """ const p4est_refine_t = Ptr{Cvoid} @@ -4146,10 +5157,13 @@ const p4est_refine_t = Ptr{Cvoid} Callback function prototype to decide for coarsening. ### Parameters -* `p4est`:\\[in\\] the forest -* `which_tree`:\\[in\\] the tree containing *quadrant* -* `quadrants`:\\[in\\] Pointers to 4 siblings in Morton ordering. + + - `p4est`:\\[in\\] the forest + - `which_tree`:\\[in\\] the tree containing *quadrant* + - `quadrants`:\\[in\\] Pointers to 4 siblings in Morton ordering. + ### Returns + nonzero if the quadrants shall be replaced with their parent. """ const p4est_coarsen_t = Ptr{Cvoid} @@ -4163,9 +5177,12 @@ Callback function prototype to calculate weights for partitioning. Global sum of weights must fit into a 64bit integer. ### Parameters -* `p4est`:\\[in\\] the forest -* `which_tree`:\\[in\\] the tree containing *quadrant* + + - `p4est`:\\[in\\] the forest + - `which_tree`:\\[in\\] the tree containing *quadrant* + ### Returns + a 32bit integer >= 0 as the quadrant weight. """ const p4est_weight_t = Ptr{Cvoid} @@ -4176,29 +5193,45 @@ const p4est_weight_t = Ptr{Cvoid} Transform a quadrant coordinate into the space spanned by tree vertices. ### Parameters -* `connectivity`:\\[in\\] Connectivity must provide the vertices. -* `treeid`:\\[in\\] Identify the tree that contains x, y. -* `x,`:\\[in\\] y Quadrant coordinates relative to treeid. -* `vxyz`:\\[out\\] Transformed coordinates in vertex space. + + - `connectivity`:\\[in\\] Connectivity must provide the vertices. + - `treeid`:\\[in\\] Identify the tree that contains x, y. + - `x,`:\\[in\\] y Quadrant coordinates relative to treeid. + - `vxyz`:\\[out\\] Transformed coordinates in vertex space. + ### Prototype + ```c void p4est_qcoord_to_vertex (p4est_connectivity_t * connectivity, p4est_topidx_t treeid, p4est_qcoord_t x, p4est_qcoord_t y, double vxyz[3]); ``` """ function p4est_qcoord_to_vertex(connectivity, treeid, x, y, vxyz) - @ccall libp4est.p4est_qcoord_to_vertex(connectivity::Ptr{p4est_connectivity_t}, treeid::p4est_topidx_t, x::p4est_qcoord_t, y::p4est_qcoord_t, vxyz::Ptr{Cdouble})::Cvoid + @ccall libp4est.p4est_qcoord_to_vertex( + connectivity::Ptr{p4est_connectivity_t}, + treeid::p4est_topidx_t, + x::p4est_qcoord_t, + y::p4est_qcoord_t, + vxyz::Ptr{Cdouble}, + )::Cvoid end """ p4est_new(mpicomm, connectivity, data_size, init_fn, user_pointer) ### Prototype + ```c p4est_t *p4est_new (sc_MPI_Comm mpicomm, p4est_connectivity_t * connectivity, size_t data_size, p4est_init_t init_fn, void *user_pointer); ``` """ function p4est_new(mpicomm, connectivity, data_size, init_fn, user_pointer) - @ccall libp4est.p4est_new(mpicomm::MPI_Comm, connectivity::Ptr{p4est_connectivity_t}, data_size::Csize_t, init_fn::p4est_init_t, user_pointer::Ptr{Cvoid})::Ptr{p4est_t} + @ccall libp4est.p4est_new( + mpicomm::MPI_Comm, + connectivity::Ptr{p4est_connectivity_t}, + data_size::Csize_t, + init_fn::p4est_init_t, + user_pointer::Ptr{Cvoid}, + )::Ptr{p4est_t} end """ @@ -4211,6 +5244,7 @@ Destroy a `p4est`. The connectivity structure is not destroyed with the `p4est`. ### Prototype + ```c void p4est_destroy (p4est_t * p4est); ``` @@ -4225,10 +5259,15 @@ end Make a deep copy of a `p4est`. The connectivity is not duplicated. Copying of quadrant user data is optional. If old and new data sizes are 0, the user\\_data field is copied regardless. The inspect member of the copy is set to NULL. The revision counter of the copy is set to zero. ### Parameters -* `copy_data`:\\[in\\] If true, data are copied. If false, data\\_size is set to 0. + + - `copy_data`:\\[in\\] If true, data are copied. If false, data\\_size is set to 0. + ### Returns + Returns a valid `p4est` that does not depend on the input, except for borrowing the same connectivity. Its revision counter is 0. + ### Prototype + ```c p4est_t *p4est_copy (p4est_t * input, int copy_data); ``` @@ -4243,16 +5282,24 @@ end Reset user pointer and element data. When the data size is changed the quadrant data is freed and allocated. The initialization callback is invoked on each quadrant. Old user\\_data content is disregarded. ### Parameters -* `data_size`:\\[in\\] This is the size of data for each quadrant which can be zero. Then user\\_data\\_pool is set to NULL. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. May be NULL. -* `user_pointer`:\\[in\\] Assign to the user\\_pointer member of the `p4est` before init\\_fn is called the first time. + + - `data_size`:\\[in\\] This is the size of data for each quadrant which can be zero. Then user\\_data\\_pool is set to NULL. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. May be NULL. + - `user_pointer`:\\[in\\] Assign to the user\\_pointer member of the `p4est` before init\\_fn is called the first time. + ### Prototype + ```c void p4est_reset_data (p4est_t * p4est, size_t data_size, p4est_init_t init_fn, void *user_pointer); ``` """ function p4est_reset_data(p4est_, data_size, init_fn, user_pointer) - @ccall libp4est.p4est_reset_data(p4est_::Ptr{p4est_t}, data_size::Csize_t, init_fn::p4est_init_t, user_pointer::Ptr{Cvoid})::Cvoid + @ccall libp4est.p4est_reset_data( + p4est_::Ptr{p4est_t}, + data_size::Csize_t, + init_fn::p4est_init_t, + user_pointer::Ptr{Cvoid}, + )::Cvoid end """ @@ -4261,17 +5308,25 @@ end Refine a forest. ### Parameters -* `p4est`:\\[in,out\\] The forest is changed in place. -* `refine_recursive`:\\[in\\] Boolean to decide on recursive refinement. -* `refine_fn`:\\[in\\] Callback function that must return true if a quadrant shall be refined. If refine\\_recursive is true, refine\\_fn is called for every existing and newly created quadrant. Otherwise, it is called for every existing quadrant. It is possible that a refinement request made by the callback is ignored. To catch this case, you can examine whether init\\_fn gets called, or use [`p4est_refine_ext`](@ref) in p4est\\_extended.h and examine whether replace\\_fn gets called. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data of newly created quadrants, which is already allocated. This function pointer may be NULL. + + - `p4est`:\\[in,out\\] The forest is changed in place. + - `refine_recursive`:\\[in\\] Boolean to decide on recursive refinement. + - `refine_fn`:\\[in\\] Callback function that must return true if a quadrant shall be refined. If refine\\_recursive is true, refine\\_fn is called for every existing and newly created quadrant. Otherwise, it is called for every existing quadrant. It is possible that a refinement request made by the callback is ignored. To catch this case, you can examine whether init\\_fn gets called, or use [`p4est_refine_ext`](@ref) in p4est\\_extended.h and examine whether replace\\_fn gets called. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data of newly created quadrants, which is already allocated. This function pointer may be NULL. + ### Prototype + ```c void p4est_refine (p4est_t * p4est, int refine_recursive, p4est_refine_t refine_fn, p4est_init_t init_fn); ``` """ function p4est_refine(p4est_, refine_recursive, refine_fn, init_fn) - @ccall libp4est.p4est_refine(p4est_::Ptr{p4est_t}, refine_recursive::Cint, refine_fn::p4est_refine_t, init_fn::p4est_init_t)::Cvoid + @ccall libp4est.p4est_refine( + p4est_::Ptr{p4est_t}, + refine_recursive::Cint, + refine_fn::p4est_refine_t, + init_fn::p4est_init_t, + )::Cvoid end """ @@ -4280,17 +5335,25 @@ end Coarsen a forest. ### Parameters -* `p4est`:\\[in,out\\] The forest is changed in place. -* `coarsen_recursive`:\\[in\\] Boolean to decide on recursive coarsening. -* `coarsen_fn`:\\[in\\] Callback function that returns true if a family of quadrants shall be coarsened -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + + - `p4est`:\\[in,out\\] The forest is changed in place. + - `coarsen_recursive`:\\[in\\] Boolean to decide on recursive coarsening. + - `coarsen_fn`:\\[in\\] Callback function that returns true if a family of quadrants shall be coarsened + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + ### Prototype + ```c void p4est_coarsen (p4est_t * p4est, int coarsen_recursive, p4est_coarsen_t coarsen_fn, p4est_init_t init_fn); ``` """ function p4est_coarsen(p4est_, coarsen_recursive, coarsen_fn, init_fn) - @ccall libp4est.p4est_coarsen(p4est_::Ptr{p4est_t}, coarsen_recursive::Cint, coarsen_fn::p4est_coarsen_t, init_fn::p4est_init_t)::Cvoid + @ccall libp4est.p4est_coarsen( + p4est_::Ptr{p4est_t}, + coarsen_recursive::Cint, + coarsen_fn::p4est_coarsen_t, + init_fn::p4est_init_t, + )::Cvoid end """ @@ -4299,16 +5362,23 @@ end 2:1 balance the size differences of neighboring elements in a forest. ### Parameters -* `p4est`:\\[in,out\\] The `p4est` to be worked on. -* `btype`:\\[in\\] Balance type (face or corner/full). Corner balance is almost never required when discretizing a PDE; just causes smoother mesh grading. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + + - `p4est`:\\[in,out\\] The `p4est` to be worked on. + - `btype`:\\[in\\] Balance type (face or corner/full). Corner balance is almost never required when discretizing a PDE; just causes smoother mesh grading. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + ### Prototype + ```c void p4est_balance (p4est_t * p4est, p4est_connect_type_t btype, p4est_init_t init_fn); ``` """ function p4est_balance(p4est_, btype, init_fn) - @ccall libp4est.p4est_balance(p4est_::Ptr{p4est_t}, btype::p4est_connect_type_t, init_fn::p4est_init_t)::Cvoid + @ccall libp4est.p4est_balance( + p4est_::Ptr{p4est_t}, + btype::p4est_connect_type_t, + init_fn::p4est_init_t, + )::Cvoid end """ @@ -4321,16 +5391,23 @@ The forest will be partitioned between processors such that they have an approxi On one process, the function noops and does not call the weight callback. Otherwise, the weight callback is called once per quadrant in order. ### Parameters -* `p4est`:\\[in,out\\] The forest that will be partitioned. -* `allow_for_coarsening`:\\[in\\] Slightly modify partition such that quadrant families are not split between ranks. -* `weight_fn`:\\[in\\] A weighting function or NULL for uniform partitioning. When running with mpisize == 1, never called. Otherwise, called in order for all quadrants if not NULL. A weighting function with constant weight 1 on each quadrant is equivalent to weight\\_fn == NULL but other constant weightings may result in different uniform partitionings. + + - `p4est`:\\[in,out\\] The forest that will be partitioned. + - `allow_for_coarsening`:\\[in\\] Slightly modify partition such that quadrant families are not split between ranks. + - `weight_fn`:\\[in\\] A weighting function or NULL for uniform partitioning. When running with mpisize == 1, never called. Otherwise, called in order for all quadrants if not NULL. A weighting function with constant weight 1 on each quadrant is equivalent to weight\\_fn == NULL but other constant weightings may result in different uniform partitionings. + ### Prototype + ```c void p4est_partition (p4est_t * p4est, int allow_for_coarsening, p4est_weight_t weight_fn); ``` """ function p4est_partition(p4est_, allow_for_coarsening, weight_fn) - @ccall libp4est.p4est_partition(p4est_::Ptr{p4est_t}, allow_for_coarsening::Cint, weight_fn::p4est_weight_t)::Cvoid + @ccall libp4est.p4est_partition( + p4est_::Ptr{p4est_t}, + allow_for_coarsening::Cint, + weight_fn::p4est_weight_t, + )::Cvoid end """ @@ -4339,8 +5416,11 @@ end Compute the checksum for a forest. Based on quadrant arrays only. It is independent of partition and mpisize. ### Returns + Returns the checksum on processor 0 only. 0 on other processors. + ### Prototype + ```c unsigned p4est_checksum (p4est_t * p4est); ``` @@ -4355,8 +5435,11 @@ end Compute a partition-dependent checksum for a forest. ### Returns + Returns the checksum on processor 0 only. 0 on other processors. + ### Prototype + ```c unsigned p4est_checksum_partition (p4est_t * p4est); ``` @@ -4385,28 +5468,43 @@ The revision counter is not saved to the file, since that would make files diffe If `p4est` is not configured to use MPI-IO, some processes return from this function before the file is complete, in which case immediate read-access to the file may require a call to `sc_MPI_Barrier`. ### Parameters -* `filename`:\\[in\\] Name of the file to write. -* `p4est`:\\[in\\] Valid forest structure. -* `save_data`:\\[in\\] If true, the element data is saved. Otherwise, a data size of 0 is saved. + + - `filename`:\\[in\\] Name of the file to write. + - `p4est`:\\[in\\] Valid forest structure. + - `save_data`:\\[in\\] If true, the element data is saved. Otherwise, a data size of 0 is saved. + ### Prototype + ```c void p4est_save (const char *filename, p4est_t * p4est, int save_data); ``` """ function p4est_save(filename, p4est_, save_data) - @ccall libp4est.p4est_save(filename::Cstring, p4est_::Ptr{p4est_t}, save_data::Cint)::Cvoid + @ccall libp4est.p4est_save( + filename::Cstring, + p4est_::Ptr{p4est_t}, + save_data::Cint, + )::Cvoid end """ p4est_load(filename, mpicomm, data_size, load_data, user_pointer, connectivity) ### Prototype + ```c p4est_t *p4est_load (const char *filename, sc_MPI_Comm mpicomm, size_t data_size, int load_data, void *user_pointer, p4est_connectivity_t ** connectivity); ``` """ function p4est_load(filename, mpicomm, data_size, load_data, user_pointer, connectivity) - @ccall libp4est.p4est_load(filename::Cstring, mpicomm::MPI_Comm, data_size::Csize_t, load_data::Cint, user_pointer::Ptr{Cvoid}, connectivity::Ptr{Ptr{p4est_connectivity_t}})::Ptr{p4est_t} + @ccall libp4est.p4est_load( + filename::Cstring, + mpicomm::MPI_Comm, + data_size::Csize_t, + load_data::Cint, + user_pointer::Ptr{Cvoid}, + connectivity::Ptr{Ptr{p4est_connectivity_t}}, + )::Ptr{p4est_t} end """ @@ -4414,18 +5512,18 @@ end quadrants that neighbor the local domain -| Field | Note | -| :------------------------------ | :----------------------------------------------------------------------------------------------------------------------------- | -| btype | which neighbors are in the ghost layer | -| ghosts | array of [`p4est_quadrant_t`](@ref) type | -| tree\\_offsets | num\\_trees + 1 ghost indices | -| proc\\_offsets | mpisize + 1 ghost indices | -| mirrors | array of [`p4est_quadrant_t`](@ref) type | -| mirror\\_tree\\_offsets | num\\_trees + 1 mirror indices | -| mirror\\_proc\\_mirrors | indices into mirrors grouped by outside processor rank and ascending within each rank | -| mirror\\_proc\\_offsets | mpisize + 1 indices into mirror\\_proc\\_mirrors | -| mirror\\_proc\\_fronts | like mirror\\_proc\\_mirrors, but limited to the outermost octants. This is NULL until [`p4est_ghost_expand`](@ref) is called | -| mirror\\_proc\\_front\\_offsets | NULL until [`p4est_ghost_expand`](@ref) is called | +| Field | Note | +|:------------------------------- |:----------------------------------------------------------------------------------------------------------------------------- | +| btype | which neighbors are in the ghost layer | +| ghosts | array of [`p4est_quadrant_t`](@ref) type | +| tree\\_offsets | num\\_trees + 1 ghost indices | +| proc\\_offsets | mpisize + 1 ghost indices | +| mirrors | array of [`p4est_quadrant_t`](@ref) type | +| mirror\\_tree\\_offsets | num\\_trees + 1 mirror indices | +| mirror\\_proc\\_mirrors | indices into mirrors grouped by outside processor rank and ascending within each rank | +| mirror\\_proc\\_offsets | mpisize + 1 indices into mirror\\_proc\\_mirrors | +| mirror\\_proc\\_fronts | like mirror\\_proc\\_mirrors, but limited to the outermost octants. This is NULL until [`p4est_ghost_expand`](@ref) is called | +| mirror\\_proc\\_front\\_offsets | NULL until [`p4est_ghost_expand`](@ref) is called | """ struct p4est_ghost_t mpisize::Cint @@ -4450,17 +5548,25 @@ Examine if a ghost structure is valid. Test if within a ghost-structure the arra Test if the [`p4est_locidx_t`](@ref) arrays are in ascending order (for mirror\\_proc\\_mirrors ascending within each rank) ### Parameters -* `p4est`:\\[in\\] the forest. -* `ghost`:\\[in\\] Ghost layer structure. + + - `p4est`:\\[in\\] the forest. + - `ghost`:\\[in\\] Ghost layer structure. + ### Returns + true if *ghost* is valid + ### Prototype + ```c int p4est_ghost_is_valid (p4est_t * p4est, p4est_ghost_t * ghost); ``` """ function p4est_ghost_is_valid(p4est_, ghost) - @ccall libp4est.p4est_ghost_is_valid(p4est_::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t})::Cint + @ccall libp4est.p4est_ghost_is_valid( + p4est_::Ptr{p4est_t}, + ghost::Ptr{p4est_ghost_t}, + )::Cint end """ @@ -4469,10 +5575,15 @@ end Calculate the memory usage of the ghost layer. ### Parameters -* `ghost`:\\[in\\] Ghost layer structure. + + - `ghost`:\\[in\\] Ghost layer structure. + ### Returns + Memory used in bytes. + ### Prototype + ```c size_t p4est_ghost_memory_used (p4est_ghost_t * ghost); ``` @@ -4491,19 +5602,29 @@ Gets the processor id of a quadrant's owner. The quadrant can lie outside of a t Does not work for tree edge or corner neighbors. ### Parameters -* `p4est`:\\[in\\] The forest in which to search for a quadrant. -* `treeid`:\\[in\\] The tree to which the quadrant belongs. -* `face`:\\[in\\] Supply a face direction if known, or -1 otherwise. -* `q`:\\[in\\] The quadrant that is being searched for. + + - `p4est`:\\[in\\] The forest in which to search for a quadrant. + - `treeid`:\\[in\\] The tree to which the quadrant belongs. + - `face`:\\[in\\] Supply a face direction if known, or -1 otherwise. + - `q`:\\[in\\] The quadrant that is being searched for. + ### Returns + Processor id of the owner or -1 if the quadrant lies outside of the mesh. + ### Prototype + ```c int p4est_quadrant_find_owner (p4est_t * p4est, p4est_topidx_t treeid, int face, const p4est_quadrant_t * q); ``` """ function p4est_quadrant_find_owner(p4est_, treeid, face, q) - @ccall libp4est.p4est_quadrant_find_owner(p4est_::Ptr{p4est_t}, treeid::p4est_topidx_t, face::Cint, q::Ptr{p4est_quadrant_t})::Cint + @ccall libp4est.p4est_quadrant_find_owner( + p4est_::Ptr{p4est_t}, + treeid::p4est_topidx_t, + face::Cint, + q::Ptr{p4est_quadrant_t}, + )::Cint end """ @@ -4514,17 +5635,25 @@ Builds the ghost layer. This will gather the quadrants from each neighboring proc to build one layer of face and corner based ghost elements around the ones they own. ### Parameters -* `p4est`:\\[in\\] The forest for which the ghost layer will be generated. -* `btype`:\\[in\\] Which ghosts to include (across face, corner or full). + + - `p4est`:\\[in\\] The forest for which the ghost layer will be generated. + - `btype`:\\[in\\] Which ghosts to include (across face, corner or full). + ### Returns + A fully initialized ghost layer. + ### Prototype + ```c p4est_ghost_t *p4est_ghost_new (p4est_t * p4est, p4est_connect_type_t btype); ``` """ function p4est_ghost_new(p4est_, btype) - @ccall libp4est.p4est_ghost_new(p4est_::Ptr{p4est_t}, btype::p4est_connect_type_t)::Ptr{p4est_ghost_t} + @ccall libp4est.p4est_ghost_new( + p4est_::Ptr{p4est_t}, + btype::p4est_connect_type_t, + )::Ptr{p4est_ghost_t} end """ @@ -4533,6 +5662,7 @@ end Frees all memory used for the ghost layer. ### Prototype + ```c void p4est_ghost_destroy (p4est_ghost_t * ghost); ``` @@ -4547,19 +5677,29 @@ end Conduct binary search for exact match on a range of the ghost layer. ### Parameters -* `ghost`:\\[in\\] The ghost layer. -* `which_proc`:\\[in\\] The owner of the searched quadrant. Can be -1. -* `which_tree`:\\[in\\] The tree of the searched quadrant. Can be -1. -* `q`:\\[in\\] Valid quadrant is searched in the ghost layer. + + - `ghost`:\\[in\\] The ghost layer. + - `which_proc`:\\[in\\] The owner of the searched quadrant. Can be -1. + - `which_tree`:\\[in\\] The tree of the searched quadrant. Can be -1. + - `q`:\\[in\\] Valid quadrant is searched in the ghost layer. + ### Returns + Offset in the ghost layer, or -1 if not found. + ### Prototype + ```c ssize_t p4est_ghost_bsearch (p4est_ghost_t * ghost, int which_proc, p4est_topidx_t which_tree, const p4est_quadrant_t * q); ``` """ function p4est_ghost_bsearch(ghost, which_proc, which_tree, q) - @ccall libp4est.p4est_ghost_bsearch(ghost::Ptr{p4est_ghost_t}, which_proc::Cint, which_tree::p4est_topidx_t, q::Ptr{p4est_quadrant_t})::Cssize_t + @ccall libp4est.p4est_ghost_bsearch( + ghost::Ptr{p4est_ghost_t}, + which_proc::Cint, + which_tree::p4est_topidx_t, + q::Ptr{p4est_quadrant_t}, + )::Cssize_t end """ @@ -4568,19 +5708,29 @@ end Conduct binary search for ancestor on range of the ghost layer. ### Parameters -* `ghost`:\\[in\\] The ghost layer. -* `which_proc`:\\[in\\] The owner of the searched quadrant. Can be -1. -* `which_tree`:\\[in\\] The tree of the searched quadrant. Can be -1. -* `q`:\\[in\\] Valid quadrant's ancestor is searched. + + - `ghost`:\\[in\\] The ghost layer. + - `which_proc`:\\[in\\] The owner of the searched quadrant. Can be -1. + - `which_tree`:\\[in\\] The tree of the searched quadrant. Can be -1. + - `q`:\\[in\\] Valid quadrant's ancestor is searched. + ### Returns + Offset in the ghost layer, or -1 if not found. + ### Prototype + ```c ssize_t p4est_ghost_contains (p4est_ghost_t * ghost, int which_proc, p4est_topidx_t which_tree, const p4est_quadrant_t * q); ``` """ function p4est_ghost_contains(ghost, which_proc, which_tree, q) - @ccall libp4est.p4est_ghost_contains(ghost::Ptr{p4est_ghost_t}, which_proc::Cint, which_tree::p4est_topidx_t, q::Ptr{p4est_quadrant_t})::Cssize_t + @ccall libp4est.p4est_ghost_contains( + ghost::Ptr{p4est_ghost_t}, + which_proc::Cint, + which_tree::p4est_topidx_t, + q::Ptr{p4est_quadrant_t}, + )::Cssize_t end """ @@ -4591,22 +5741,35 @@ Checks if quadrant exists in the local forest or the ghost layer. For quadrants across tree boundaries it checks if the quadrant exists across any face, but not across corners. ### Parameters -* `p4est`:\\[in\\] The forest in which to search for *q*. -* `ghost`:\\[in\\] The ghost layer in which to search for *q*. -* `treeid`:\\[in\\] The tree to which *q* belongs. -* `q`:\\[in\\] The quadrant that is being searched for. -* `face`:\\[in,out\\] On input, face id across which *q* was created. On output, the neighbor's face number augmented by orientation, so face is in 0..7. -* `hang`:\\[in,out\\] If not NULL, signals that q is bigger than the quadrant it came from. The child id of that originating quadrant is passed into hang. On output, hang holds the hanging face number of *q* that is in contact with its originator. -* `owner_rank`:\\[out\\] Filled with the rank of the owner if it is found and undefined otherwise. + + - `p4est`:\\[in\\] The forest in which to search for *q*. + - `ghost`:\\[in\\] The ghost layer in which to search for *q*. + - `treeid`:\\[in\\] The tree to which *q* belongs. + - `q`:\\[in\\] The quadrant that is being searched for. + - `face`:\\[in,out\\] On input, face id across which *q* was created. On output, the neighbor's face number augmented by orientation, so face is in 0..7. + - `hang`:\\[in,out\\] If not NULL, signals that q is bigger than the quadrant it came from. The child id of that originating quadrant is passed into hang. On output, hang holds the hanging face number of *q* that is in contact with its originator. + - `owner_rank`:\\[out\\] Filled with the rank of the owner if it is found and undefined otherwise. + ### Returns + Returns the local number of *q* if the quadrant exists in the local forest or in the ghost\\_layer. Otherwise, returns -2 for a domain boundary and -1 if not found. + ### Prototype + ```c p4est_locidx_t p4est_face_quadrant_exists (p4est_t * p4est, p4est_ghost_t * ghost, p4est_topidx_t treeid, const p4est_quadrant_t * q, int *face, int *hang, int *owner_rank); ``` """ function p4est_face_quadrant_exists(p4est_, ghost, treeid, q, face, hang, owner_rank) - @ccall libp4est.p4est_face_quadrant_exists(p4est_::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t}, treeid::p4est_topidx_t, q::Ptr{p4est_quadrant_t}, face::Ptr{Cint}, hang::Ptr{Cint}, owner_rank::Ptr{Cint})::p4est_locidx_t + @ccall libp4est.p4est_face_quadrant_exists( + p4est_::Ptr{p4est_t}, + ghost::Ptr{p4est_ghost_t}, + treeid::p4est_topidx_t, + q::Ptr{p4est_quadrant_t}, + face::Ptr{Cint}, + hang::Ptr{Cint}, + owner_rank::Ptr{Cint}, + )::p4est_locidx_t end """ @@ -4617,22 +5780,35 @@ Checks if quadrant exists in the local forest or the ghost layer. For quadrants across tree corners it checks if the quadrant exists in any of the corner neighbors, thus it can execute multiple queries. ### Parameters -* `p4est`:\\[in\\] The forest in which to search for *q* -* `ghost`:\\[in\\] The ghost layer in which to search for *q* -* `treeid`:\\[in\\] The tree to which *q* belongs (can be extended). -* `q`:\\[in\\] The quadrant that is being searched for. -* `exists_arr`:\\[in,out\\] Must exist and be of of elem\\_size = sizeof (int) for inter-tree corner cases. Is resized by this function to one entry for each corner search and set to true/false depending on its existence in the local forest or ghost\\_layer. -* `rproc_arr`:\\[in,out\\] If not NULL is filled with one rank per query. -* `rquad_arr`:\\[in,out\\] If not NULL is filled with one quadrant per query. Its piggy3 member is defined as well. + + - `p4est`:\\[in\\] The forest in which to search for *q* + - `ghost`:\\[in\\] The ghost layer in which to search for *q* + - `treeid`:\\[in\\] The tree to which *q* belongs (can be extended). + - `q`:\\[in\\] The quadrant that is being searched for. + - `exists_arr`:\\[in,out\\] Must exist and be of of elem\\_size = sizeof (int) for inter-tree corner cases. Is resized by this function to one entry for each corner search and set to true/false depending on its existence in the local forest or ghost\\_layer. + - `rproc_arr`:\\[in,out\\] If not NULL is filled with one rank per query. + - `rquad_arr`:\\[in,out\\] If not NULL is filled with one quadrant per query. Its piggy3 member is defined as well. + ### Returns + true if the quadrant exists in the local forest or in the ghost\\_layer, and false if doesn't exist in either. + ### Prototype + ```c int p4est_quadrant_exists (p4est_t * p4est, p4est_ghost_t * ghost, p4est_topidx_t treeid, const p4est_quadrant_t * q, sc_array_t * exists_arr, sc_array_t * rproc_arr, sc_array_t * rquad_arr); ``` """ function p4est_quadrant_exists(p4est_, ghost, treeid, q, exists_arr, rproc_arr, rquad_arr) - @ccall libp4est.p4est_quadrant_exists(p4est_::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t}, treeid::p4est_topidx_t, q::Ptr{p4est_quadrant_t}, exists_arr::Ptr{sc_array_t}, rproc_arr::Ptr{sc_array_t}, rquad_arr::Ptr{sc_array_t})::Cint + @ccall libp4est.p4est_quadrant_exists( + p4est_::Ptr{p4est_t}, + ghost::Ptr{p4est_ghost_t}, + treeid::p4est_topidx_t, + q::Ptr{p4est_quadrant_t}, + exists_arr::Ptr{sc_array_t}, + rproc_arr::Ptr{sc_array_t}, + rquad_arr::Ptr{sc_array_t}, + )::Cint end """ @@ -4643,17 +5819,25 @@ Check a forest to see if it is balanced. This function builds the ghost layer and discards it when done. ### Parameters -* `p4est`:\\[in\\] The `p4est` to be tested. -* `btype`:\\[in\\] Balance type (face, corner or default, full). + + - `p4est`:\\[in\\] The `p4est` to be tested. + - `btype`:\\[in\\] Balance type (face, corner or default, full). + ### Returns + Returns true if balanced, false otherwise. + ### Prototype + ```c int p4est_is_balanced (p4est_t * p4est, p4est_connect_type_t btype); ``` """ function p4est_is_balanced(p4est_, btype) - @ccall libp4est.p4est_is_balanced(p4est_::Ptr{p4est_t}, btype::p4est_connect_type_t)::Cint + @ccall libp4est.p4est_is_balanced( + p4est_::Ptr{p4est_t}, + btype::p4est_connect_type_t, + )::Cint end """ @@ -4662,17 +5846,25 @@ end Compute the parallel checksum of a ghost layer. ### Parameters -* `p4est`:\\[in\\] The MPI information of this `p4est` will be used. -* `ghost`:\\[in\\] A ghost layer obtained from the `p4est`. + + - `p4est`:\\[in\\] The MPI information of this `p4est` will be used. + - `ghost`:\\[in\\] A ghost layer obtained from the `p4est`. + ### Returns + Parallel checksum on rank 0, 0 otherwise. + ### Prototype + ```c unsigned p4est_ghost_checksum (p4est_t * p4est, p4est_ghost_t * ghost); ``` """ function p4est_ghost_checksum(p4est_, ghost) - @ccall libp4est.p4est_ghost_checksum(p4est_::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t})::Cuint + @ccall libp4est.p4est_ghost_checksum( + p4est_::Ptr{p4est_t}, + ghost::Ptr{p4est_ghost_t}, + )::Cuint end """ @@ -4681,16 +5873,23 @@ end Transfer data for local quadrants that are ghosts to other processors. Send the data stored in the quadrant's user\\_data. This is either the pointer variable itself if `p4est`->data_size is 0, or the content of the referenced memory field if `p4est`->data\\_size is positive. ### Parameters -* `p4est`:\\[in\\] The forest used for reference. -* `ghost`:\\[in\\] The ghost layer used for reference. -* `ghost_data`:\\[in,out\\] Pre-allocated contiguous data for all ghost quadrants in sequence. If `p4est`->data\\_size is 0, must at least hold sizeof (void *) bytes for each, otherwise `p4est`->data\\_size each. + + - `p4est`:\\[in\\] The forest used for reference. + - `ghost`:\\[in\\] The ghost layer used for reference. + - `ghost_data`:\\[in,out\\] Pre-allocated contiguous data for all ghost quadrants in sequence. If `p4est`->data\\_size is 0, must at least hold sizeof (void *) bytes for each, otherwise `p4est`->data\\_size each. + ### Prototype + ```c void p4est_ghost_exchange_data (p4est_t * p4est, p4est_ghost_t * ghost, void *ghost_data); ``` """ function p4est_ghost_exchange_data(p4est_, ghost, ghost_data) - @ccall libp4est.p4est_ghost_exchange_data(p4est_::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t}, ghost_data::Ptr{Cvoid})::Cvoid + @ccall libp4est.p4est_ghost_exchange_data( + p4est_::Ptr{p4est_t}, + ghost::Ptr{p4est_ghost_t}, + ghost_data::Ptr{Cvoid}, + )::Cvoid end """ @@ -4698,12 +5897,12 @@ end Transient storage for asynchronous ghost exchange. -| Field | Note | -| :---------- | :--------------------------------------------- | -| is\\_custom | False for [`p4est_ghost_exchange_data`](@ref) | -| is\\_levels | Are we restricted to levels or not | -| minlevel | Meaningful with is\\_levels | -| maxlevel | | +| Field | Note | +|:----------- |:--------------------------------------------- | +| is\\_custom | False for [`p4est_ghost_exchange_data`](@ref) | +| is\\_levels | Are we restricted to levels or not | +| minlevel | Meaningful with is\\_levels | +| maxlevel | | """ struct p4est_ghost_exchange is_custom::Cint @@ -4722,7 +5921,9 @@ struct p4est_ghost_exchange rbuffers::sc_array_t end -"""Transient storage for asynchronous ghost exchange.""" +""" +Transient storage for asynchronous ghost exchange. +""" const p4est_ghost_exchange_t = p4est_ghost_exchange """ @@ -4731,16 +5932,25 @@ const p4est_ghost_exchange_t = p4est_ghost_exchange Begin an asynchronous ghost data exchange by posting messages. The arguments are identical to [`p4est_ghost_exchange_data`](@ref). The return type is always non-NULL and must be passed to [`p4est_ghost_exchange_data_end`](@ref) to complete the exchange. The ghost data must not be accessed before completion. ### Parameters -* `ghost_data`:\\[in,out\\] Must stay alive into the completion call. + + - `ghost_data`:\\[in,out\\] Must stay alive into the completion call. + ### Returns + Transient storage for messages in progress. + ### Prototype + ```c p4est_ghost_exchange_t *p4est_ghost_exchange_data_begin (p4est_t * p4est, p4est_ghost_t * ghost, void *ghost_data); ``` """ function p4est_ghost_exchange_data_begin(p4est_, ghost, ghost_data) - @ccall libp4est.p4est_ghost_exchange_data_begin(p4est_::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t}, ghost_data::Ptr{Cvoid})::Ptr{p4est_ghost_exchange_t} + @ccall libp4est.p4est_ghost_exchange_data_begin( + p4est_::Ptr{p4est_t}, + ghost::Ptr{p4est_ghost_t}, + ghost_data::Ptr{Cvoid}, + )::Ptr{p4est_ghost_exchange_t} end """ @@ -4749,8 +5959,11 @@ end Complete an asynchronous ghost data exchange. This function waits for all pending MPI communications. ### Parameters -* `Data`:\\[in,out\\] created ONLY by [`p4est_ghost_exchange_data_begin`](@ref). It is deallocated before this function returns. + + - `Data`:\\[in,out\\] created ONLY by [`p4est_ghost_exchange_data_begin`](@ref). It is deallocated before this function returns. + ### Prototype + ```c void p4est_ghost_exchange_data_end (p4est_ghost_exchange_t * exc); ``` @@ -4765,18 +5978,27 @@ end Transfer data for local quadrants that are ghosts to other processors. The data size is the same for all quadrants and can be chosen arbitrarily. ### Parameters -* `p4est`:\\[in\\] The forest used for reference. -* `ghost`:\\[in\\] The ghost layer used for reference. -* `data_size`:\\[in\\] The data size to transfer per quadrant. -* `mirror_data`:\\[in\\] One data pointer per mirror quadrant as input. -* `ghost_data`:\\[in,out\\] Pre-allocated contiguous data for all ghosts in sequence, which must hold at least `data_size` for each ghost. + + - `p4est`:\\[in\\] The forest used for reference. + - `ghost`:\\[in\\] The ghost layer used for reference. + - `data_size`:\\[in\\] The data size to transfer per quadrant. + - `mirror_data`:\\[in\\] One data pointer per mirror quadrant as input. + - `ghost_data`:\\[in,out\\] Pre-allocated contiguous data for all ghosts in sequence, which must hold at least `data_size` for each ghost. + ### Prototype + ```c void p4est_ghost_exchange_custom (p4est_t * p4est, p4est_ghost_t * ghost, size_t data_size, void **mirror_data, void *ghost_data); ``` """ function p4est_ghost_exchange_custom(p4est_, ghost, data_size, mirror_data, ghost_data) - @ccall libp4est.p4est_ghost_exchange_custom(p4est_::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t}, data_size::Csize_t, mirror_data::Ptr{Ptr{Cvoid}}, ghost_data::Ptr{Cvoid})::Cvoid + @ccall libp4est.p4est_ghost_exchange_custom( + p4est_::Ptr{p4est_t}, + ghost::Ptr{p4est_ghost_t}, + data_size::Csize_t, + mirror_data::Ptr{Ptr{Cvoid}}, + ghost_data::Ptr{Cvoid}, + )::Cvoid end """ @@ -4785,17 +6007,34 @@ end Begin an asynchronous ghost data exchange by posting messages. The arguments are identical to [`p4est_ghost_exchange_custom`](@ref). The return type is always non-NULL and must be passed to [`p4est_ghost_exchange_custom_end`](@ref) to complete the exchange. The ghost data must not be accessed before completion. The mirror data can be safely discarded right after this function returns since it is copied into internal send buffers. ### Parameters -* `mirror_data`:\\[in\\] Not required to stay alive any longer. -* `ghost_data`:\\[in,out\\] Must stay alive into the completion call. + + - `mirror_data`:\\[in\\] Not required to stay alive any longer. + - `ghost_data`:\\[in,out\\] Must stay alive into the completion call. + ### Returns + Transient storage for messages in progress. + ### Prototype + ```c p4est_ghost_exchange_t *p4est_ghost_exchange_custom_begin (p4est_t * p4est, p4est_ghost_t * ghost, size_t data_size, void **mirror_data, void *ghost_data); ``` """ -function p4est_ghost_exchange_custom_begin(p4est_, ghost, data_size, mirror_data, ghost_data) - @ccall libp4est.p4est_ghost_exchange_custom_begin(p4est_::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t}, data_size::Csize_t, mirror_data::Ptr{Ptr{Cvoid}}, ghost_data::Ptr{Cvoid})::Ptr{p4est_ghost_exchange_t} +function p4est_ghost_exchange_custom_begin( + p4est_, + ghost, + data_size, + mirror_data, + ghost_data, +) + @ccall libp4est.p4est_ghost_exchange_custom_begin( + p4est_::Ptr{p4est_t}, + ghost::Ptr{p4est_ghost_t}, + data_size::Csize_t, + mirror_data::Ptr{Ptr{Cvoid}}, + ghost_data::Ptr{Cvoid}, + )::Ptr{p4est_ghost_exchange_t} end """ @@ -4804,8 +6043,11 @@ end Complete an asynchronous ghost data exchange. This function waits for all pending MPI communications. ### Parameters -* `Data`:\\[in,out\\] created ONLY by [`p4est_ghost_exchange_custom_begin`](@ref). It is deallocated before this function returns. + + - `Data`:\\[in,out\\] created ONLY by [`p4est_ghost_exchange_custom_begin`](@ref). It is deallocated before this function returns. + ### Prototype + ```c void p4est_ghost_exchange_custom_end (p4est_ghost_exchange_t * exc); ``` @@ -4820,20 +6062,39 @@ end Transfer data for local quadrants that are ghosts to other processors. The data size is the same for all quadrants and can be chosen arbitrarily. This function restricts the transfer to a range of refinement levels. The memory for quadrants outside the level range is not dereferenced. ### Parameters -* `p4est`:\\[in\\] The forest used for reference. -* `ghost`:\\[in\\] The ghost layer used for reference. -* `minlevel`:\\[in\\] Level of the largest quads to be exchanged. Use <= 0 for no restriction. -* `maxlevel`:\\[in\\] Level of the smallest quads to be exchanged. Use >= `P4EST_QMAXLEVEL` for no restriction. -* `data_size`:\\[in\\] The data size to transfer per quadrant. -* `mirror_data`:\\[in\\] One data pointer per mirror quadrant as input. -* `ghost_data`:\\[in,out\\] Pre-allocated contiguous data for all ghosts in sequence, which must hold at least `data_size` for each ghost. + + - `p4est`:\\[in\\] The forest used for reference. + - `ghost`:\\[in\\] The ghost layer used for reference. + - `minlevel`:\\[in\\] Level of the largest quads to be exchanged. Use <= 0 for no restriction. + - `maxlevel`:\\[in\\] Level of the smallest quads to be exchanged. Use >= `P4EST_QMAXLEVEL` for no restriction. + - `data_size`:\\[in\\] The data size to transfer per quadrant. + - `mirror_data`:\\[in\\] One data pointer per mirror quadrant as input. + - `ghost_data`:\\[in,out\\] Pre-allocated contiguous data for all ghosts in sequence, which must hold at least `data_size` for each ghost. + ### Prototype + ```c void p4est_ghost_exchange_custom_levels (p4est_t * p4est, p4est_ghost_t * ghost, int minlevel, int maxlevel, size_t data_size, void **mirror_data, void *ghost_data); ``` """ -function p4est_ghost_exchange_custom_levels(p4est_, ghost, minlevel, maxlevel, data_size, mirror_data, ghost_data) - @ccall libp4est.p4est_ghost_exchange_custom_levels(p4est_::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t}, minlevel::Cint, maxlevel::Cint, data_size::Csize_t, mirror_data::Ptr{Ptr{Cvoid}}, ghost_data::Ptr{Cvoid})::Cvoid +function p4est_ghost_exchange_custom_levels( + p4est_, + ghost, + minlevel, + maxlevel, + data_size, + mirror_data, + ghost_data, +) + @ccall libp4est.p4est_ghost_exchange_custom_levels( + p4est_::Ptr{p4est_t}, + ghost::Ptr{p4est_ghost_t}, + minlevel::Cint, + maxlevel::Cint, + data_size::Csize_t, + mirror_data::Ptr{Ptr{Cvoid}}, + ghost_data::Ptr{Cvoid}, + )::Cvoid end """ @@ -4842,17 +6103,38 @@ end Begin an asynchronous ghost data exchange by posting messages. The arguments are identical to [`p4est_ghost_exchange_custom_levels`](@ref). The return type is always non-NULL and must be passed to [`p4est_ghost_exchange_custom_levels_end`](@ref) to complete the exchange. The ghost data must not be accessed before completion. The mirror data can be safely discarded right after this function returns since it is copied into internal send buffers. ### Parameters -* `mirror_data`:\\[in\\] Not required to stay alive any longer. -* `ghost_data`:\\[in,out\\] Must stay alive into the completion call. + + - `mirror_data`:\\[in\\] Not required to stay alive any longer. + - `ghost_data`:\\[in,out\\] Must stay alive into the completion call. + ### Returns + Transient storage for messages in progress. + ### Prototype + ```c p4est_ghost_exchange_t *p4est_ghost_exchange_custom_levels_begin (p4est_t * p4est, p4est_ghost_t * ghost, int minlevel, int maxlevel, size_t data_size, void **mirror_data, void *ghost_data); ``` """ -function p4est_ghost_exchange_custom_levels_begin(p4est_, ghost, minlevel, maxlevel, data_size, mirror_data, ghost_data) - @ccall libp4est.p4est_ghost_exchange_custom_levels_begin(p4est_::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t}, minlevel::Cint, maxlevel::Cint, data_size::Csize_t, mirror_data::Ptr{Ptr{Cvoid}}, ghost_data::Ptr{Cvoid})::Ptr{p4est_ghost_exchange_t} +function p4est_ghost_exchange_custom_levels_begin( + p4est_, + ghost, + minlevel, + maxlevel, + data_size, + mirror_data, + ghost_data, +) + @ccall libp4est.p4est_ghost_exchange_custom_levels_begin( + p4est_::Ptr{p4est_t}, + ghost::Ptr{p4est_ghost_t}, + minlevel::Cint, + maxlevel::Cint, + data_size::Csize_t, + mirror_data::Ptr{Ptr{Cvoid}}, + ghost_data::Ptr{Cvoid}, + )::Ptr{p4est_ghost_exchange_t} end """ @@ -4861,14 +6143,19 @@ end Complete an asynchronous ghost data exchange. This function waits for all pending MPI communications. ### Parameters -* `Data`:\\[in,out\\] created ONLY by [`p4est_ghost_exchange_custom_levels_begin`](@ref). It is deallocated before this function returns. + + - `Data`:\\[in,out\\] created ONLY by [`p4est_ghost_exchange_custom_levels_begin`](@ref). It is deallocated before this function returns. + ### Prototype + ```c void p4est_ghost_exchange_custom_levels_end (p4est_ghost_exchange_t * exc); ``` """ function p4est_ghost_exchange_custom_levels_end(exc) - @ccall libp4est.p4est_ghost_exchange_custom_levels_end(exc::Ptr{p4est_ghost_exchange_t})::Cvoid + @ccall libp4est.p4est_ghost_exchange_custom_levels_end( + exc::Ptr{p4est_ghost_exchange_t}, + )::Cvoid end """ @@ -4877,15 +6164,21 @@ end Expand the size of the ghost layer and mirrors by one additional layer of adjacency. ### Parameters -* `p4est`:\\[in\\] The forest from which the ghost layer was generated. -* `ghost`:\\[in,out\\] The ghost layer to be expanded. + + - `p4est`:\\[in\\] The forest from which the ghost layer was generated. + - `ghost`:\\[in,out\\] The ghost layer to be expanded. + ### Prototype + ```c void p4est_ghost_expand (p4est_t * p4est, p4est_ghost_t * ghost); ``` """ function p4est_ghost_expand(p4est_, ghost) - @ccall libp4est.p4est_ghost_expand(p4est_::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t})::Cvoid + @ccall libp4est.p4est_ghost_expand( + p4est_::Ptr{p4est_t}, + ghost::Ptr{p4est_ghost_t}, + )::Cvoid end """ @@ -4909,14 +6202,14 @@ Corners with no diagonal neighbor at all are assigned the value -3. This only ha TODO: In case of an inter-tree corner neighbor relation in a brick-like situation (exactly one neighbor, diagonally opposite corner number), use the same encoding as for corners within a tree. -| Field | Note | -| :---------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| quad\\_to\\_tree | tree index for each local quad. Is NULL by default, but may be enabled by p4est_mesh_new_ext. | -| ghost\\_to\\_proc | processor for each ghost quad | -| quad\\_to\\_quad | one index for each of the 4 faces | -| quad\\_to\\_face | encodes orientation/2:1 status | -| quad\\_to\\_half | stores half-size neighbors | -| quad\\_level | Stores lists of per-level quads. The array has entries indexed by 0..`P4EST_QMAXLEVEL` inclusive that are arrays of local quadrant ids. Is NULL by default, but may be enabled by p4est_mesh_new_ext. | +| Field | Note | +|:----------------- |:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| quad\\_to\\_tree | tree index for each local quad. Is NULL by default, but may be enabled by p4est_mesh_new_ext. | +| ghost\\_to\\_proc | processor for each ghost quad | +| quad\\_to\\_quad | one index for each of the 4 faces | +| quad\\_to\\_face | encodes orientation/2:1 status | +| quad\\_to\\_half | stores half-size neighbors | +| quad\\_level | Stores lists of per-level quads. The array has entries indexed by 0..`P4EST_QMAXLEVEL` inclusive that are arrays of local quadrant ids. Is NULL by default, but may be enabled by p4est_mesh_new_ext. | """ struct p4est_mesh_t local_num_quadrants::p4est_locidx_t @@ -4957,10 +6250,15 @@ end Calculate the memory usage of the mesh structure. ### Parameters -* `mesh`:\\[in\\] Mesh structure. + + - `mesh`:\\[in\\] Mesh structure. + ### Returns + Memory used in bytes. + ### Prototype + ```c size_t p4est_mesh_memory_used (p4est_mesh_t * mesh); ``` @@ -4975,18 +6273,27 @@ end Create a p4est\\_mesh structure. This function does not populate the quad\\_to\\_tree and quad\\_level fields. To populate them, use p4est_mesh_new_ext. ### Parameters -* `p4est`:\\[in\\] A forest that is fully 2:1 balanced. -* `ghost`:\\[in\\] The ghost layer created from the provided `p4est`. -* `btype`:\\[in\\] Determines the highest codimension of neighbors. + + - `p4est`:\\[in\\] A forest that is fully 2:1 balanced. + - `ghost`:\\[in\\] The ghost layer created from the provided `p4est`. + - `btype`:\\[in\\] Determines the highest codimension of neighbors. + ### Returns + A fully allocated mesh structure. + ### Prototype + ```c p4est_mesh_t *p4est_mesh_new (p4est_t * p4est, p4est_ghost_t * ghost, p4est_connect_type_t btype); ``` """ function p4est_mesh_new(p4est_, ghost, btype) - @ccall libp4est.p4est_mesh_new(p4est_::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t}, btype::p4est_connect_type_t)::Ptr{p4est_mesh_t} + @ccall libp4est.p4est_mesh_new( + p4est_::Ptr{p4est_t}, + ghost::Ptr{p4est_ghost_t}, + btype::p4est_connect_type_t, + )::Ptr{p4est_mesh_t} end """ @@ -4995,8 +6302,11 @@ end Destroy a p4est\\_mesh structure. ### Parameters -* `mesh`:\\[in\\] Mesh structure previously created by [`p4est_mesh_new`](@ref). + + - `mesh`:\\[in\\] Mesh structure previously created by [`p4est_mesh_new`](@ref). + ### Prototype + ```c void p4est_mesh_destroy (p4est_mesh_t * mesh); ``` @@ -5011,18 +6321,27 @@ end Access a process-local quadrant inside a forest. Needs a mesh with populated quad\\_to\\_tree array. This is a special case of p4est_mesh_quadrant_cumulative. ### Parameters -* `p4est`:\\[in\\] The forest. -* `mesh`:\\[in\\] The mesh. -* `qid`:\\[in\\] Process-local id of the quadrant (cumulative over trees). + + - `p4est`:\\[in\\] The forest. + - `mesh`:\\[in\\] The mesh. + - `qid`:\\[in\\] Process-local id of the quadrant (cumulative over trees). + ### Returns + A pointer to the requested quadrant. + ### Prototype + ```c p4est_quadrant_t *p4est_mesh_get_quadrant (p4est_t * p4est, p4est_mesh_t * mesh, p4est_locidx_t qid); ``` """ function p4est_mesh_get_quadrant(p4est_, mesh, qid) - @ccall libp4est.p4est_mesh_get_quadrant(p4est_::Ptr{p4est_t}, mesh::Ptr{p4est_mesh_t}, qid::p4est_locidx_t)::Ptr{p4est_quadrant_t} + @ccall libp4est.p4est_mesh_get_quadrant( + p4est_::Ptr{p4est_t}, + mesh::Ptr{p4est_mesh_t}, + qid::p4est_locidx_t, + )::Ptr{p4est_quadrant_t} end """ @@ -5031,21 +6350,42 @@ end Lookup neighboring quads of quadrant in a specific direction. ### Parameters -* `p4est`:\\[in\\] Forest to be worked with. -* `ghost`:\\[in\\] Ghost layer. -* `mesh`:\\[in\\] Mesh structure. -* `curr_quad_id`:\\[in\\] Process-local id of current quad. -* `direction`:\\[in\\] Direction i in which to look for adjacent quadrants is encoded as follows: 0 .. 3 neighbor(-s) across face i, 4 .. 7 neighbor(-s) across corner i-4. TODO: Allow any combination of empty output arrays. -* `neighboring_quads`:\\[out\\] Array containing neighboring quad(-s). Needs to be empty on input, size of [`p4est_quadrant_t`](@ref) *. May be NULL, then **neighboring_qids** must not be NULL. -* `neighboring_qids`:\\[out\\] Array containing quadrant ids for neighboring quadrants. May be NULL, then no neighboring qids are collected. If non-NULL the array needs to be empty and will contain int. CAUTION: Note, that the encodings differ from the encodings saved in the mesh. TODO: Encodings are the same as in p4est\\_mesh for all quadrants. TODO: Ghosts can be encoded by returning the quad\\_to\\_quad convention in qid. For ghost quadrants, we add -300 to the values in p4est\\_mesh. This means that values below -100 belong to ghosts, values above to locals. Positive values are for local quadrants, negative values indicate ghost quadrants. Faces: 1 .. 8 => same size neighbor (r * 4 + nf) + 1; nf = 0 .. 3 face index; r = 0 .. 1 relative orientation 9 .. 24 => double size neighbor 9 + h * 8 + r * 4 + nf; h = 0 .. 1 number of the subface; r, nf as above 25 .. 32 => half-size neighbors 25 + r * 4 + nf; r, nf as above Corners: 1 .. 4 => size not encoded for corners nc + 1; nc = 0 .. 3 corner index -* `neighboring_encs`:\\[out\\] Array containing encodings for neighboring quads. Needs to be empty, contains int. + + - `p4est`:\\[in\\] Forest to be worked with. + - `ghost`:\\[in\\] Ghost layer. + - `mesh`:\\[in\\] Mesh structure. + - `curr_quad_id`:\\[in\\] Process-local id of current quad. + - `direction`:\\[in\\] Direction i in which to look for adjacent quadrants is encoded as follows: 0 .. 3 neighbor(-s) across face i, 4 .. 7 neighbor(-s) across corner i-4. TODO: Allow any combination of empty output arrays. + - `neighboring_quads`:\\[out\\] Array containing neighboring quad(-s). Needs to be empty on input, size of [`p4est_quadrant_t`](@ref) *. May be NULL, then **neighboring_qids** must not be NULL. + - `neighboring_qids`:\\[out\\] Array containing quadrant ids for neighboring quadrants. May be NULL, then no neighboring qids are collected. If non-NULL the array needs to be empty and will contain int. CAUTION: Note, that the encodings differ from the encodings saved in the mesh. TODO: Encodings are the same as in p4est\\_mesh for all quadrants. TODO: Ghosts can be encoded by returning the quad\\_to\\_quad convention in qid. For ghost quadrants, we add -300 to the values in p4est\\_mesh. This means that values below -100 belong to ghosts, values above to locals. Positive values are for local quadrants, negative values indicate ghost quadrants. Faces: 1 .. 8 => same size neighbor (r * 4 + nf) + 1; nf = 0 .. 3 face index; r = 0 .. 1 relative orientation 9 .. 24 => double size neighbor 9 + h * 8 + r * 4 + nf; h = 0 .. 1 number of the subface; r, nf as above 25 .. 32 => half-size neighbors 25 + r * 4 + nf; r, nf as above Corners: 1 .. 4 => size not encoded for corners nc + 1; nc = 0 .. 3 corner index + - `neighboring_encs`:\\[out\\] Array containing encodings for neighboring quads. Needs to be empty, contains int. + ### Prototype + ```c p4est_locidx_t p4est_mesh_get_neighbors (p4est_t * p4est, p4est_ghost_t * ghost, p4est_mesh_t * mesh, p4est_locidx_t curr_quad_id, p4est_locidx_t direction, sc_array_t * neighboring_quads, sc_array_t * neighboring_encs, sc_array_t * neighboring_qids); ``` """ -function p4est_mesh_get_neighbors(p4est_, ghost, mesh, curr_quad_id, direction, neighboring_quads, neighboring_encs, neighboring_qids) - @ccall libp4est.p4est_mesh_get_neighbors(p4est_::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t}, mesh::Ptr{p4est_mesh_t}, curr_quad_id::p4est_locidx_t, direction::p4est_locidx_t, neighboring_quads::Ptr{sc_array_t}, neighboring_encs::Ptr{sc_array_t}, neighboring_qids::Ptr{sc_array_t})::p4est_locidx_t +function p4est_mesh_get_neighbors( + p4est_, + ghost, + mesh, + curr_quad_id, + direction, + neighboring_quads, + neighboring_encs, + neighboring_qids, +) + @ccall libp4est.p4est_mesh_get_neighbors( + p4est_::Ptr{p4est_t}, + ghost::Ptr{p4est_ghost_t}, + mesh::Ptr{p4est_mesh_t}, + curr_quad_id::p4est_locidx_t, + direction::p4est_locidx_t, + neighboring_quads::Ptr{sc_array_t}, + neighboring_encs::Ptr{sc_array_t}, + neighboring_qids::Ptr{sc_array_t}, + )::p4est_locidx_t end """ @@ -5054,20 +6394,37 @@ end Find a quadrant based on its cumulative number in the local forest. If the quad\\_to\\_tree field of the mesh structure exists, this is O(1). Otherwise, we perform a binary search over the processor-local trees. ### Parameters -* `p4est`:\\[in\\] Forest to be worked with. -* `mesh`:\\[in\\] A mesh derived from the forest. -* `cumulative_id`:\\[in\\] Cumulative index over all trees of quadrant. Must refer to a local (non-ghost) quadrant. -* `which_tree`:\\[in,out\\] If not NULL, the input value can be -1 or an initial guess for the quadrant's tree and output is the tree of returned quadrant. -* `quadrant_id`:\\[out\\] If not NULL, the number of quadrant in tree. + + - `p4est`:\\[in\\] Forest to be worked with. + - `mesh`:\\[in\\] A mesh derived from the forest. + - `cumulative_id`:\\[in\\] Cumulative index over all trees of quadrant. Must refer to a local (non-ghost) quadrant. + - `which_tree`:\\[in,out\\] If not NULL, the input value can be -1 or an initial guess for the quadrant's tree and output is the tree of returned quadrant. + - `quadrant_id`:\\[out\\] If not NULL, the number of quadrant in tree. + ### Returns + The identified quadrant. + ### Prototype + ```c p4est_quadrant_t *p4est_mesh_quadrant_cumulative (p4est_t * p4est, p4est_mesh_t * mesh, p4est_locidx_t cumulative_id, p4est_topidx_t * which_tree, p4est_locidx_t * quadrant_id); ``` """ -function p4est_mesh_quadrant_cumulative(p4est_, mesh, cumulative_id, which_tree, quadrant_id) - @ccall libp4est.p4est_mesh_quadrant_cumulative(p4est_::Ptr{p4est_t}, mesh::Ptr{p4est_mesh_t}, cumulative_id::p4est_locidx_t, which_tree::Ptr{p4est_topidx_t}, quadrant_id::Ptr{p4est_locidx_t})::Ptr{p4est_quadrant_t} +function p4est_mesh_quadrant_cumulative( + p4est_, + mesh, + cumulative_id, + which_tree, + quadrant_id, +) + @ccall libp4est.p4est_mesh_quadrant_cumulative( + p4est_::Ptr{p4est_t}, + mesh::Ptr{p4est_mesh_t}, + cumulative_id::p4est_locidx_t, + which_tree::Ptr{p4est_topidx_t}, + quadrant_id::Ptr{p4est_locidx_t}, + )::Ptr{p4est_quadrant_t} end """ @@ -5076,16 +6433,26 @@ end Initialize a mesh neighbor iterator by quadrant index. ### Parameters -* `mfn`:\\[out\\] A [`p4est_mesh_face_neighbor_t`](@ref) to be initialized. -* `which_tree`:\\[in\\] Tree of quadrant whose neighbors are looped over. -* `quadrant_id`:\\[in\\] Index relative to which\\_tree of quadrant. + + - `mfn`:\\[out\\] A [`p4est_mesh_face_neighbor_t`](@ref) to be initialized. + - `which_tree`:\\[in\\] Tree of quadrant whose neighbors are looped over. + - `quadrant_id`:\\[in\\] Index relative to which\\_tree of quadrant. + ### Prototype + ```c void p4est_mesh_face_neighbor_init2 (p4est_mesh_face_neighbor_t * mfn, p4est_t * p4est, p4est_ghost_t * ghost, p4est_mesh_t * mesh, p4est_topidx_t which_tree, p4est_locidx_t quadrant_id); ``` """ function p4est_mesh_face_neighbor_init2(mfn, p4est_, ghost, mesh, which_tree, quadrant_id) - @ccall libp4est.p4est_mesh_face_neighbor_init2(mfn::Ptr{p4est_mesh_face_neighbor_t}, p4est_::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t}, mesh::Ptr{p4est_mesh_t}, which_tree::p4est_topidx_t, quadrant_id::p4est_locidx_t)::Cvoid + @ccall libp4est.p4est_mesh_face_neighbor_init2( + mfn::Ptr{p4est_mesh_face_neighbor_t}, + p4est_::Ptr{p4est_t}, + ghost::Ptr{p4est_ghost_t}, + mesh::Ptr{p4est_mesh_t}, + which_tree::p4est_topidx_t, + quadrant_id::p4est_locidx_t, + )::Cvoid end """ @@ -5094,16 +6461,26 @@ end Initialize a mesh neighbor iterator by quadrant pointer. ### Parameters -* `mfn`:\\[out\\] A [`p4est_mesh_face_neighbor_t`](@ref) to be initialized. -* `which_tree`:\\[in\\] Tree of quadrant whose neighbors are looped over. -* `quadrant`:\\[in\\] Pointer to quadrant contained in which\\_tree. + + - `mfn`:\\[out\\] A [`p4est_mesh_face_neighbor_t`](@ref) to be initialized. + - `which_tree`:\\[in\\] Tree of quadrant whose neighbors are looped over. + - `quadrant`:\\[in\\] Pointer to quadrant contained in which\\_tree. + ### Prototype + ```c void p4est_mesh_face_neighbor_init (p4est_mesh_face_neighbor_t * mfn, p4est_t * p4est, p4est_ghost_t * ghost, p4est_mesh_t * mesh, p4est_topidx_t which_tree, p4est_quadrant_t * quadrant); ``` """ function p4est_mesh_face_neighbor_init(mfn, p4est_, ghost, mesh, which_tree, quadrant) - @ccall libp4est.p4est_mesh_face_neighbor_init(mfn::Ptr{p4est_mesh_face_neighbor_t}, p4est_::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t}, mesh::Ptr{p4est_mesh_t}, which_tree::p4est_topidx_t, quadrant::Ptr{p4est_quadrant_t})::Cvoid + @ccall libp4est.p4est_mesh_face_neighbor_init( + mfn::Ptr{p4est_mesh_face_neighbor_t}, + p4est_::Ptr{p4est_t}, + ghost::Ptr{p4est_ghost_t}, + mesh::Ptr{p4est_mesh_t}, + which_tree::p4est_topidx_t, + quadrant::Ptr{p4est_quadrant_t}, + )::Cvoid end """ @@ -5112,20 +6489,31 @@ end Move the iterator forward to loop around neighbors of the quadrant. ### Parameters -* `mfn`:\\[in,out\\] Internal status of the iterator. -* `ntree`:\\[out\\] If not NULL, the tree number of the neighbor. -* `nquad`:\\[out\\] If not NULL, the quadrant number within tree. For ghosts instead the number in ghost layer. -* `nface`:\\[out\\] If not NULL, neighbor's face as in [`p4est_mesh_t`](@ref). -* `nrank`:\\[out\\] If not NULL, the owner process of the neighbor. + + - `mfn`:\\[in,out\\] Internal status of the iterator. + - `ntree`:\\[out\\] If not NULL, the tree number of the neighbor. + - `nquad`:\\[out\\] If not NULL, the quadrant number within tree. For ghosts instead the number in ghost layer. + - `nface`:\\[out\\] If not NULL, neighbor's face as in [`p4est_mesh_t`](@ref). + - `nrank`:\\[out\\] If not NULL, the owner process of the neighbor. + ### Returns + Either a real quadrant or one from the ghost layer. Returns NULL when the iterator is done. + ### Prototype + ```c p4est_quadrant_t *p4est_mesh_face_neighbor_next (p4est_mesh_face_neighbor_t * mfn, p4est_topidx_t * ntree, p4est_locidx_t * nquad, int *nface, int *nrank); ``` """ function p4est_mesh_face_neighbor_next(mfn, ntree, nquad, nface, nrank) - @ccall libp4est.p4est_mesh_face_neighbor_next(mfn::Ptr{p4est_mesh_face_neighbor_t}, ntree::Ptr{p4est_topidx_t}, nquad::Ptr{p4est_locidx_t}, nface::Ptr{Cint}, nrank::Ptr{Cint})::Ptr{p4est_quadrant_t} + @ccall libp4est.p4est_mesh_face_neighbor_next( + mfn::Ptr{p4est_mesh_face_neighbor_t}, + ntree::Ptr{p4est_topidx_t}, + nquad::Ptr{p4est_locidx_t}, + nface::Ptr{Cint}, + nrank::Ptr{Cint}, + )::Ptr{p4est_quadrant_t} end """ @@ -5134,17 +6522,25 @@ end Get the user data for the current face neighbor. ### Parameters -* `mfn`:\\[in\\] Internal status of the iterator. -* `ghost_data`:\\[in\\] Data for the ghost quadrants that has been synchronized with [`p4est_ghost_exchange_data`](@ref). + + - `mfn`:\\[in\\] Internal status of the iterator. + - `ghost_data`:\\[in\\] Data for the ghost quadrants that has been synchronized with [`p4est_ghost_exchange_data`](@ref). + ### Returns + A pointer to the user data for the current neighbor. + ### Prototype + ```c void *p4est_mesh_face_neighbor_data (p4est_mesh_face_neighbor_t * mfn, void *ghost_data); ``` """ function p4est_mesh_face_neighbor_data(mfn, ghost_data) - @ccall libp4est.p4est_mesh_face_neighbor_data(mfn::Ptr{p4est_mesh_face_neighbor_t}, ghost_data::Ptr{Cvoid})::Ptr{Cvoid} + @ccall libp4est.p4est_mesh_face_neighbor_data( + mfn::Ptr{p4est_mesh_face_neighbor_t}, + ghost_data::Ptr{Cvoid}, + )::Ptr{Cvoid} end """ @@ -5154,11 +6550,11 @@ The information that is available to the user-defined [`p4est_iter_volume_t`](@r *treeid* gives the index in `p4est`->trees of the tree to which *quad* belongs. *quadid* gives the index of *quad* within *tree*'s quadrants array. -| Field | Note | -| :----- | :------------------------------------------------------ | -| quad | the quadrant of the callback | -| quadid | id in *quad*'s tree array (see [`p4est_tree_t`](@ref)) | -| treeid | the tree containing *quad* | +| Field | Note | +|:------ |:------------------------------------------------------ | +| quad | the quadrant of the callback | +| quadid | id in *quad*'s tree array (see [`p4est_tree_t`](@ref)) | +| treeid | the tree containing *quad* | """ struct p4est_iter_volume_info p4est::Ptr{p4est_t} @@ -5180,13 +6576,14 @@ const p4est_iter_volume_info_t = p4est_iter_volume_info The prototype for a function that [`p4est_iterate`](@ref) will execute at every quadrant local to the current process. ### Parameters -* `info`:\\[in\\] information about a quadrant provided to the user -* `user_data`:\\[in,out\\] the user context passed to [`p4est_iterate`](@ref)() + + - `info`:\\[in\\] information about a quadrant provided to the user + - `user_data`:\\[in,out\\] the user context passed to [`p4est_iterate`](@ref)() """ const p4est_iter_volume_t = Ptr{Cvoid} struct p4est_iter_face_side_data - data::NTuple{32, UInt8} + data::NTuple{32,UInt8} end function Base.getproperty(x::Ptr{p4est_iter_face_side_data}, f::Symbol) @@ -5213,14 +6610,14 @@ Information about one side of a face in the forest. If a *quad* is local (*is_ghost* is false), then its *quadid* indexes the tree's quadrant array; otherwise, it indexes the ghosts array. If the face is hanging, then the quadrants are listed in z-order. If a quadrant should be present, but it is not included in the ghost layer, then quad = NULL, is\\_ghost is true, and quadid = -1. -| Field | Note | -| :----------- | :--------------------------------------------------- | -| treeid | the tree on this side | -| face | which quadrant side the face touches | -| is\\_hanging | boolean: one full quad (0) or two smaller quads (1) | +| Field | Note | +|:------------ |:--------------------------------------------------- | +| treeid | the tree on this side | +| face | which quadrant side the face touches | +| is\\_hanging | boolean: one full quad (0) or two smaller quads (1) | """ struct p4est_iter_face_side - data::NTuple{40, UInt8} + data::NTuple{40,UInt8} end function Base.getproperty(x::Ptr{p4est_iter_face_side}, f::Symbol) @@ -5256,10 +6653,10 @@ The information that is available to the user-defined [`p4est_iter_face_t`](@ref The orientation is 0 if the face is within one tree; otherwise, it is the same as the orientation value between the two trees given in the connectivity. If the face is on the outside boundary of the forest, then there is only one side. If tree\\_boundary is false, the face is on the interior of a tree. When tree\\_boundary is false, sides[0] contains the lowest z-order quadrant that touches the face. When tree\\_boundary is true, its value is P4EST\\_CONNECT\\_FACE. -| Field | Note | -| :-------------- | :-------------------------------------------------------------------------------------------------- | -| orientation | the orientation of the sides to each other, as in the definition of [`p4est_connectivity_t`](@ref) | -| tree\\_boundary | boolean: interior face (0), tree boundary face (true) | +| Field | Note | +|:--------------- |:-------------------------------------------------------------------------------------------------- | +| orientation | the orientation of the sides to each other, as in the definition of [`p4est_connectivity_t`](@ref) | +| tree\\_boundary | boolean: interior face (0), tree boundary face (true) | """ struct p4est_iter_face_info p4est::Ptr{p4est_t} @@ -5285,8 +6682,9 @@ The prototype for a function that [`p4est_iterate`](@ref) will execute wherever the forest must be face balanced for [`p4est_iterate`](@ref)() to execute a callback function on faces (see [`p4est_balance`](@ref)()). ### Parameters -* `info`:\\[in\\] information about a quadrant provided to the user -* `user_data`:\\[in,out\\] the user context passed to [`p4est_iterate`](@ref)() + + - `info`:\\[in\\] information about a quadrant provided to the user + - `user_data`:\\[in,out\\] the user context passed to [`p4est_iterate`](@ref)() """ const p4est_iter_face_t = Ptr{Cvoid} @@ -5297,13 +6695,13 @@ Information about one side of a corner in the forest. If a *quad* is local (*is_ the *faces* field provides some additional information about the local topology: if side[i]->faces[j] == side[k]->faces[l], this indicates that there is a common face between these two sides of the corner. -| Field | Note | -| :--------- | :--------------------------------------------------- | -| treeid | the tree that contains *quad* | -| corner | which of the quadrant's corners touches this corner | -| is\\_ghost | boolean: local (0) or ghost (1) | -| quadid | the index in the tree or ghost array | -| faces | internal work data | +| Field | Note | +|:---------- |:--------------------------------------------------- | +| treeid | the tree that contains *quad* | +| corner | which of the quadrant's corners touches this corner | +| is\\_ghost | boolean: local (0) or ghost (1) | +| quadid | the index in the tree or ghost array | +| faces | internal work data | """ struct p4est_iter_corner_side treeid::p4est_topidx_t @@ -5311,7 +6709,7 @@ struct p4est_iter_corner_side is_ghost::Int8 quad::Ptr{p4est_quadrant_t} quadid::p4est_locidx_t - faces::NTuple{2, Int8} + faces::NTuple{2,Int8} end """ @@ -5328,10 +6726,10 @@ The information that is available to the user-defined [`p4est_iter_corner_t`](@r If tree\\_boundary is false, the corner is on the interior of a tree. When tree\\_boundary is false, sides[0] contains the lowest z-order quadrant that touches the corner. When tree\\_boundary is true, its value is P4EST\\_CONNECT\\_FACE/CORNER depending on the location of the corner relative to the tree. -| Field | Note | -| :-------------- | :----------------------------------------------------- | -| tree\\_boundary | boolean: interior face (0), tree boundary face (true) | -| sides | array of type [`p4est_iter_corner_side_t`](@ref) type | +| Field | Note | +|:--------------- |:----------------------------------------------------- | +| tree\\_boundary | boolean: interior face (0), tree boundary face (true) | +| sides | array of type [`p4est_iter_corner_side_t`](@ref) type | """ struct p4est_iter_corner_info p4est::Ptr{p4est_t} @@ -5358,8 +6756,9 @@ i.e. the callback will not execute on a hanging corner. the forest does not need to be corner balanced for [`p4est_iterate`](@ref)() to correctly execute a callback function at corners, only face balanced (see [`p4est_balance`](@ref)()). ### Parameters -* `info`:\\[in\\] information about a quadrant provided to the user -* `user_data`:\\[in,out\\] the user context passed to [`p4est_iterate`](@ref)() + + - `info`:\\[in\\] information about a quadrant provided to the user + - `user_data`:\\[in,out\\] the user context passed to [`p4est_iterate`](@ref)() """ const p4est_iter_corner_t = Ptr{Cvoid} @@ -5370,22 +6769,32 @@ Execute user supplied callbacks at every volume, face, and corner in the local f [`p4est_iterate`](@ref) executes the user-supplied callback functions at every volume, face, and corner in the local forest. The ghost\\_layer may be NULL. The *user_data* pointer is not touched by [`p4est_iterate`](@ref), but is passed to each of the callbacks. Any of the callbacks may be NULL. The callback functions are interspersed with each other, i.e. some face callbacks will occur between volume callbacks, and some corner callbacks will occur between face callbacks: -1) volume callbacks occur in the sorted Morton-index order. 2) a face callback is not executed until after the volume callbacks have been executed for the quadrants that share it. 3) a corner callback is not executed until the face callbacks have been executed for all faces that touch the corner. 4) it is not always the case that every face callback for a given quadrant is executed before any of the corner callbacks. 5) callbacks are not executed at faces or corners that only involve ghost quadrants, i.e. that are not adjacent in the local section of the forest. + 1. volume callbacks occur in the sorted Morton-index order. 2) a face callback is not executed until after the volume callbacks have been executed for the quadrants that share it. 3) a corner callback is not executed until the face callbacks have been executed for all faces that touch the corner. 4) it is not always the case that every face callback for a given quadrant is executed before any of the corner callbacks. 5) callbacks are not executed at faces or corners that only involve ghost quadrants, i.e. that are not adjacent in the local section of the forest. ### Parameters -* `p4est`:\\[in\\] the forest -* `ghost_layer`:\\[in\\] optional: when not given, callbacks at the boundaries of the local partition cannot provide quadrant data about ghost quadrants: missing ([`p4est_quadrant_t`](@ref) *) pointers are set to NULL, missing indices are set to -1. -* `user_data`:\\[in,out\\] optional context to supply to each callback -* `iter_volume`:\\[in\\] callback function for every quadrant's interior -* `iter_face`:\\[in\\] callback function for every face between quadrants -* `iter_corner`:\\[in\\] callback function for every corner between quadrants + + - `p4est`:\\[in\\] the forest + - `ghost_layer`:\\[in\\] optional: when not given, callbacks at the boundaries of the local partition cannot provide quadrant data about ghost quadrants: missing ([`p4est_quadrant_t`](@ref) *) pointers are set to NULL, missing indices are set to -1. + - `user_data`:\\[in,out\\] optional context to supply to each callback + - `iter_volume`:\\[in\\] callback function for every quadrant's interior + - `iter_face`:\\[in\\] callback function for every face between quadrants + - `iter_corner`:\\[in\\] callback function for every corner between quadrants + ### Prototype + ```c void p4est_iterate (p4est_t * p4est, p4est_ghost_t * ghost_layer, void *user_data, p4est_iter_volume_t iter_volume, p4est_iter_face_t iter_face, p4est_iter_corner_t iter_corner); ``` """ function p4est_iterate(p4est_, ghost_layer, user_data, iter_volume, iter_face, iter_corner) - @ccall libp4est.p4est_iterate(p4est_::Ptr{p4est_t}, ghost_layer::Ptr{p4est_ghost_t}, user_data::Ptr{Cvoid}, iter_volume::p4est_iter_volume_t, iter_face::p4est_iter_face_t, iter_corner::p4est_iter_corner_t)::Cvoid + @ccall libp4est.p4est_iterate( + p4est_::Ptr{p4est_t}, + ghost_layer::Ptr{p4est_ghost_t}, + user_data::Ptr{Cvoid}, + iter_volume::p4est_iter_volume_t, + iter_face::p4est_iter_face_t, + iter_corner::p4est_iter_corner_t, + )::Cvoid end const p4est_lnodes_code_t = Int8 @@ -5467,18 +6876,24 @@ const p4est_lnodes_rank_t = p4est_lnodes_rank p4est_lnodes_new(p4est_, ghost_layer, degree) ### Prototype + ```c p4est_lnodes_t *p4est_lnodes_new (p4est_t * p4est, p4est_ghost_t * ghost_layer, int degree); ``` """ function p4est_lnodes_new(p4est_, ghost_layer, degree) - @ccall libp4est.p4est_lnodes_new(p4est_::Ptr{p4est_t}, ghost_layer::Ptr{p4est_ghost_t}, degree::Cint)::Ptr{p4est_lnodes_t} + @ccall libp4est.p4est_lnodes_new( + p4est_::Ptr{p4est_t}, + ghost_layer::Ptr{p4est_ghost_t}, + degree::Cint, + )::Ptr{p4est_lnodes_t} end """ p4est_lnodes_destroy(lnodes) ### Prototype + ```c void p4est_lnodes_destroy (p4est_lnodes_t * lnodes); ``` @@ -5493,16 +6908,23 @@ end Expand the ghost layer to include the support of all nodes supported on the local partition. ### Parameters -* `p4est`:\\[in\\] The forest from which the ghost layer was generated. -* `lnodes`:\\[in\\] The nodes to support. -* `ghost`:\\[in,out\\] The ghost layer to be expanded. + + - `p4est`:\\[in\\] The forest from which the ghost layer was generated. + - `lnodes`:\\[in\\] The nodes to support. + - `ghost`:\\[in,out\\] The ghost layer to be expanded. + ### Prototype + ```c void p4est_ghost_support_lnodes (p4est_t * p4est, p4est_lnodes_t * lnodes, p4est_ghost_t * ghost); ``` """ function p4est_ghost_support_lnodes(p4est_, lnodes, ghost) - @ccall libp4est.p4est_ghost_support_lnodes(p4est_::Ptr{p4est_t}, lnodes::Ptr{p4est_lnodes_t}, ghost::Ptr{p4est_ghost_t})::Cvoid + @ccall libp4est.p4est_ghost_support_lnodes( + p4est_::Ptr{p4est_t}, + lnodes::Ptr{p4est_lnodes_t}, + ghost::Ptr{p4est_ghost_t}, + )::Cvoid end """ @@ -5511,16 +6933,23 @@ end Expand the ghost layer as in [`p4est_ghost_expand`](@ref)(), but use node support to define adjacency instead of geometric adjacency. ### Parameters -* `p4est`:\\[in\\] The forest from which the ghost layer was generated. -* `lnodes`:\\[in\\] The nodes to support. -* `ghost`:\\[in,out\\] The ghost layer to be expanded. + + - `p4est`:\\[in\\] The forest from which the ghost layer was generated. + - `lnodes`:\\[in\\] The nodes to support. + - `ghost`:\\[in,out\\] The ghost layer to be expanded. + ### Prototype + ```c void p4est_ghost_expand_by_lnodes (p4est_t * p4est, p4est_lnodes_t * lnodes, p4est_ghost_t * ghost); ``` """ function p4est_ghost_expand_by_lnodes(p4est_, lnodes, ghost) - @ccall libp4est.p4est_ghost_expand_by_lnodes(p4est_::Ptr{p4est_t}, lnodes::Ptr{p4est_lnodes_t}, ghost::Ptr{p4est_ghost_t})::Cvoid + @ccall libp4est.p4est_ghost_expand_by_lnodes( + p4est_::Ptr{p4est_t}, + lnodes::Ptr{p4est_lnodes_t}, + ghost::Ptr{p4est_ghost_t}, + )::Cvoid end """ @@ -5529,17 +6958,25 @@ end Partition using weights based on the number of nodes assigned to each element in lnodes ### Parameters -* `p4est`:\\[in,out\\] the forest to be repartitioned -* `ghost`:\\[in\\] the ghost layer -* `degree`:\\[in\\] the degree that would be passed to [`p4est_lnodes_new`](@ref)() -* `partition_for_coarsening`:\\[in\\] whether the partition should allow coarsening (i.e. group siblings who might merge) + + - `p4est`:\\[in,out\\] the forest to be repartitioned + - `ghost`:\\[in\\] the ghost layer + - `degree`:\\[in\\] the degree that would be passed to [`p4est_lnodes_new`](@ref)() + - `partition_for_coarsening`:\\[in\\] whether the partition should allow coarsening (i.e. group siblings who might merge) + ### Prototype + ```c void p4est_partition_lnodes (p4est_t * p4est, p4est_ghost_t * ghost, int degree, int partition_for_coarsening); ``` """ function p4est_partition_lnodes(p4est_, ghost, degree, partition_for_coarsening) - @ccall libp4est.p4est_partition_lnodes(p4est_::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t}, degree::Cint, partition_for_coarsening::Cint)::Cvoid + @ccall libp4est.p4est_partition_lnodes( + p4est_::Ptr{p4est_t}, + ghost::Ptr{p4est_ghost_t}, + degree::Cint, + partition_for_coarsening::Cint, + )::Cvoid end """ @@ -5548,12 +6985,27 @@ end Partition using weights that are broken down by where they reside: in volumes, on faces, or on corners. ### Prototype + ```c void p4est_partition_lnodes_detailed (p4est_t * p4est, p4est_ghost_t * ghost, int nodes_per_volume, int nodes_per_face, int nodes_per_corner, int partition_for_coarsening); ``` """ -function p4est_partition_lnodes_detailed(p4est_, ghost, nodes_per_volume, nodes_per_face, nodes_per_corner, partition_for_coarsening) - @ccall libp4est.p4est_partition_lnodes_detailed(p4est_::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t}, nodes_per_volume::Cint, nodes_per_face::Cint, nodes_per_corner::Cint, partition_for_coarsening::Cint)::Cvoid +function p4est_partition_lnodes_detailed( + p4est_, + ghost, + nodes_per_volume, + nodes_per_face, + nodes_per_corner, + partition_for_coarsening, +) + @ccall libp4est.p4est_partition_lnodes_detailed( + p4est_::Ptr{p4est_t}, + ghost::Ptr{p4est_ghost_t}, + nodes_per_volume::Cint, + nodes_per_face::Cint, + nodes_per_corner::Cint, + partition_for_coarsening::Cint, + )::Cvoid end """ @@ -5590,18 +7042,23 @@ const p4est_lnodes_buffer_t = p4est_lnodes_buffer To be memory neutral, the *buffer* created by [`p4est_lnodes_share_owned_begin`](@ref) must be destroying with [`p4est_lnodes_buffer_destroy`](@ref) (it is not destroyed by [`p4est_lnodes_share_owned_end`](@ref)). ### Prototype + ```c p4est_lnodes_buffer_t *p4est_lnodes_share_owned_begin (sc_array_t * node_data, p4est_lnodes_t * lnodes); ``` """ function p4est_lnodes_share_owned_begin(node_data, lnodes) - @ccall libp4est.p4est_lnodes_share_owned_begin(node_data::Ptr{sc_array_t}, lnodes::Ptr{p4est_lnodes_t})::Ptr{p4est_lnodes_buffer_t} + @ccall libp4est.p4est_lnodes_share_owned_begin( + node_data::Ptr{sc_array_t}, + lnodes::Ptr{p4est_lnodes_t}, + )::Ptr{p4est_lnodes_buffer_t} end """ p4est_lnodes_share_owned_end(buffer) ### Prototype + ```c void p4est_lnodes_share_owned_end (p4est_lnodes_buffer_t * buffer); ``` @@ -5616,12 +7073,16 @@ end Equivalent to calling [`p4est_lnodes_share_owned_end`](@ref) directly after [`p4est_lnodes_share_owned_begin`](@ref). Use if there is no local work that can be done to mask the communication cost. ### Prototype + ```c void p4est_lnodes_share_owned (sc_array_t * node_data, p4est_lnodes_t * lnodes); ``` """ function p4est_lnodes_share_owned(node_data, lnodes) - @ccall libp4est.p4est_lnodes_share_owned(node_data::Ptr{sc_array_t}, lnodes::Ptr{p4est_lnodes_t})::Cvoid + @ccall libp4est.p4est_lnodes_share_owned( + node_data::Ptr{sc_array_t}, + lnodes::Ptr{p4est_lnodes_t}, + )::Cvoid end """ @@ -5634,18 +7095,23 @@ end Values of *node_data* are not guaranteed to be sent, and *buffer*->recv_buffer entries are not guaranteed to be received until the *buffer* created by [`p4est_lnodes_share_all_begin`](@ref) is passed to [`p4est_lnodes_share_all_end`](@ref). ### Prototype + ```c p4est_lnodes_buffer_t *p4est_lnodes_share_all_begin (sc_array_t * node_data, p4est_lnodes_t * lnodes); ``` """ function p4est_lnodes_share_all_begin(node_data, lnodes) - @ccall libp4est.p4est_lnodes_share_all_begin(node_data::Ptr{sc_array_t}, lnodes::Ptr{p4est_lnodes_t})::Ptr{p4est_lnodes_buffer_t} + @ccall libp4est.p4est_lnodes_share_all_begin( + node_data::Ptr{sc_array_t}, + lnodes::Ptr{p4est_lnodes_t}, + )::Ptr{p4est_lnodes_buffer_t} end """ p4est_lnodes_share_all_end(buffer) ### Prototype + ```c void p4est_lnodes_share_all_end (p4est_lnodes_buffer_t * buffer); ``` @@ -5660,20 +7126,27 @@ end Equivalent to calling [`p4est_lnodes_share_all_end`](@ref) directly after [`p4est_lnodes_share_all_begin`](@ref). Use if there is no local work that can be done to mask the communication cost. ### Returns + A fully initialized buffer that contains the received data. After processing this data, the buffer must be freed with [`p4est_lnodes_buffer_destroy`](@ref). + ### Prototype + ```c p4est_lnodes_buffer_t *p4est_lnodes_share_all (sc_array_t * node_data, p4est_lnodes_t * lnodes); ``` """ function p4est_lnodes_share_all(node_data, lnodes) - @ccall libp4est.p4est_lnodes_share_all(node_data::Ptr{sc_array_t}, lnodes::Ptr{p4est_lnodes_t})::Ptr{p4est_lnodes_buffer_t} + @ccall libp4est.p4est_lnodes_share_all( + node_data::Ptr{sc_array_t}, + lnodes::Ptr{p4est_lnodes_t}, + )::Ptr{p4est_lnodes_buffer_t} end """ p4est_lnodes_buffer_destroy(buffer) ### Prototype + ```c void p4est_lnodes_buffer_destroy (p4est_lnodes_buffer_t * buffer); ``` @@ -5682,7 +7155,9 @@ function p4est_lnodes_buffer_destroy(buffer) @ccall libp4est.p4est_lnodes_buffer_destroy(buffer::Ptr{p4est_lnodes_buffer_t})::Cvoid end -"""A datatype to handle the linear id in 2D.""" +""" +A datatype to handle the linear id in 2D. +""" const p4est_lid_t = UInt64 # typedef void ( * p4est_replace_t ) ( p4est_t * p4est , p4est_topidx_t which_tree , int num_outgoing , p4est_quadrant_t * outgoing [ ] , int num_incoming , p4est_quadrant_t * incoming [ ] ) @@ -5694,10 +7169,11 @@ This is used by extended routines when the quadrants of an existing, valid `p4es If the mesh is being refined, num\\_outgoing will be 1 and num\\_incoming will be 4, and vice versa if the mesh is being coarsened. ### Parameters -* `num_outgoing`:\\[in\\] The number of outgoing quadrants. -* `outgoing`:\\[in\\] The outgoing quadrants: after the callback, the user\\_data, if `p4est`->data_size is nonzero, will be destroyed. -* `num_incoming`:\\[in\\] The number of incoming quadrants. -* `incoming`:\\[in,out\\] The incoming quadrants: prior to the callback, the user\\_data, if `p4est`->data_size is nonzero, is allocated, and the [`p4est_init_t`](@ref) callback, if it has been provided, will be called. + + - `num_outgoing`:\\[in\\] The number of outgoing quadrants. + - `outgoing`:\\[in\\] The outgoing quadrants: after the callback, the user\\_data, if `p4est`->data_size is nonzero, will be destroyed. + - `num_incoming`:\\[in\\] The number of incoming quadrants. + - `incoming`:\\[in,out\\] The incoming quadrants: prior to the callback, the user\\_data, if `p4est`->data_size is nonzero, is allocated, and the [`p4est_init_t`](@ref) callback, if it has been provided, will be called. """ const p4est_replace_t = Ptr{Cvoid} @@ -5707,11 +7183,16 @@ const p4est_replace_t = Ptr{Cvoid} Compare the [`p4est_lid_t`](@ref) *a* and the [`p4est_lid_t`](@ref) *b*. ### Parameters -* `a`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). -* `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + + - `a`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + - `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + ### Returns + Returns -1 if a < b, 1 if a > b and 0 if a == b. + ### Prototype + ```c int p4est_lid_compare (const p4est_lid_t * a, const p4est_lid_t * b); ``` @@ -5726,11 +7207,16 @@ end Checks if the [`p4est_lid_t`](@ref) *a* and the [`p4est_lid_t`](@ref) *b* are equal. ### Parameters -* `a`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). -* `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + + - `a`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + - `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + ### Returns + Returns a true value if *a* and *b* are equal, false otherwise + ### Prototype + ```c int p4est_lid_is_equal (const p4est_lid_t * a, const p4est_lid_t * b); ``` @@ -5745,16 +7231,23 @@ end Initializes an unsigned 64 bit integer. *high* is just a a placeholder to use the same interface in 3D. ### Parameters -* `input`:\\[in,out\\] A pointer to a [`p4est_lid_t`](@ref) that will be intialized. -* `high`:\\[in\\] The given high bits must be zero. -* `low`:\\[in\\] The given low bits to initialize *input*. + + - `input`:\\[in,out\\] A pointer to a [`p4est_lid_t`](@ref) that will be intialized. + - `high`:\\[in\\] The given high bits must be zero. + - `low`:\\[in\\] The given low bits to initialize *input*. + ### Prototype + ```c void p4est_lid_init (p4est_lid_t * input, uint64_t high, uint64_t low); ``` """ function p4est_lid_init(input, high, low) - @ccall libp4est.p4est_lid_init(input::Ptr{p4est_lid_t}, high::UInt64, low::UInt64)::Cvoid + @ccall libp4est.p4est_lid_init( + input::Ptr{p4est_lid_t}, + high::UInt64, + low::UInt64, + )::Cvoid end """ @@ -5763,8 +7256,11 @@ end Initializes a linear index to zero. ### Parameters -* `input`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref) that will be intialized. + + - `input`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref) that will be intialized. + ### Prototype + ```c void p4est_lid_set_zero (p4est_lid_t * input); ``` @@ -5779,8 +7275,11 @@ end Initializes a linear index to one. ### Parameters -* `input`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref) that will be intialized. + + - `input`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref) that will be intialized. + ### Prototype + ```c void p4est_lid_set_one (p4est_lid_t * input); ``` @@ -5795,8 +7294,11 @@ end Initializes a linear index to an unsigned 64 bit integer. ### Parameters -* `input`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref) that will be intialized. + + - `input`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref) that will be intialized. + ### Prototype + ```c void p4est_lid_set_uint64 (p4est_lid_t * input, uint64_t u); ``` @@ -5811,11 +7313,16 @@ end Returns the bit\\_number-th bit of *input*. This function checks a bit of an existing, initialized value. ### Parameters -* `input`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). -* `bit_number`:\\[in\\] The bit (counted from the right hand side) that is checked by logical and. Require 0 <= *bit_number* < 64. + + - `input`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + - `bit_number`:\\[in\\] The bit (counted from the right hand side) that is checked by logical and. Require 0 <= *bit_number* < 64. + ### Returns + True if bit is set, false if not. + ### Prototype + ```c int p4est_lid_chk_bit (const p4est_lid_t * input, int bit_number); ``` @@ -5830,9 +7337,12 @@ end Sets the exponent-th bit of *a* to one. This function modifies an existing, initialized value. ### Parameters -* `input`:\\[in,out\\] A pointer to a [`p4est_lid_t`](@ref). -* `bit_number`:\\[in\\] The bit (counted from the right hand side) that is set to one by logical or. Require 0 <= *bit_number* < 64. + + - `input`:\\[in,out\\] A pointer to a [`p4est_lid_t`](@ref). + - `bit_number`:\\[in\\] The bit (counted from the right hand side) that is set to one by logical or. Require 0 <= *bit_number* < 64. + ### Prototype + ```c void p4est_lid_set_bit (p4est_lid_t * input, int bit_number); ``` @@ -5847,9 +7357,12 @@ end Copies an initialized [`p4est_lid_t`](@ref) to a [`p4est_lid_t`](@ref). ### Parameters -* `input`:\\[in\\] A pointer to the [`p4est_lid_t`](@ref) that is copied. -* `output`:\\[in,out\\] A pointer to a [`p4est_lid_t`](@ref). The low bits of *output* will be set to the low bits of *input* and high bits are ignored. + + - `input`:\\[in\\] A pointer to the [`p4est_lid_t`](@ref) that is copied. + - `output`:\\[in,out\\] A pointer to a [`p4est_lid_t`](@ref). The low bits of *output* will be set to the low bits of *input* and high bits are ignored. + ### Prototype + ```c void p4est_lid_copy (const p4est_lid_t * input, p4est_lid_t * output); ``` @@ -5864,16 +7377,23 @@ end Adds the uint128\\_t *b* to the uint128\\_t *a*. *result* == *a* or *result* == *b* is not allowed. *a* == *b* is allowed. ### Parameters -* `a`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). -* `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). -* `result`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref). The sum *a* + *b* will be saved in *result*. + + - `a`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + - `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + - `result`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref). The sum *a* + *b* will be saved in *result*. + ### Prototype + ```c void p4est_lid_add (const p4est_lid_t * a, const p4est_lid_t * b, p4est_lid_t * result); ``` """ function p4est_lid_add(a, b, result) - @ccall libp4est.p4est_lid_add(a::Ptr{p4est_lid_t}, b::Ptr{p4est_lid_t}, result::Ptr{p4est_lid_t})::Cvoid + @ccall libp4est.p4est_lid_add( + a::Ptr{p4est_lid_t}, + b::Ptr{p4est_lid_t}, + result::Ptr{p4est_lid_t}, + )::Cvoid end """ @@ -5882,16 +7402,23 @@ end Substracts the [`p4est_lid_t`](@ref) *b* from the [`p4est_lid_t`](@ref) *a*. This function assumes that the result is >= 0. *result* == *a* or *result* == *b* is not allowed. *a* == *b* is allowed. ### Parameters -* `a`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). -* `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). -* `result`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref). The difference *a* - *b* will be saved in *result*. + + - `a`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + - `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + - `result`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref). The difference *a* - *b* will be saved in *result*. + ### Prototype + ```c void p4est_lid_sub (const p4est_lid_t * a, const p4est_lid_t * b, p4est_lid_t * result); ``` """ function p4est_lid_sub(a, b, result) - @ccall libp4est.p4est_lid_sub(a::Ptr{p4est_lid_t}, b::Ptr{p4est_lid_t}, result::Ptr{p4est_lid_t})::Cvoid + @ccall libp4est.p4est_lid_sub( + a::Ptr{p4est_lid_t}, + b::Ptr{p4est_lid_t}, + result::Ptr{p4est_lid_t}, + )::Cvoid end """ @@ -5900,15 +7427,21 @@ end Calculates the bitwise negation of the uint128\\_t *a*. *a* == *result* is allowed. ### Parameters -* `a`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). -* `result`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref). The bitwise negation of *a* will be saved in *result*. + + - `a`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + - `result`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref). The bitwise negation of *a* will be saved in *result*. + ### Prototype + ```c void p4est_lid_bitwise_neg (const p4est_lid_t * a, p4est_lid_t * result); ``` """ function p4est_lid_bitwise_neg(a, result) - @ccall libp4est.p4est_lid_bitwise_neg(a::Ptr{p4est_lid_t}, result::Ptr{p4est_lid_t})::Cvoid + @ccall libp4est.p4est_lid_bitwise_neg( + a::Ptr{p4est_lid_t}, + result::Ptr{p4est_lid_t}, + )::Cvoid end """ @@ -5917,16 +7450,23 @@ end Calculates the bitwise or of the uint128\\_t *a* and *b*. *a* == *result* is allowed. Furthermore, *a* == *result* and/or *b* == *result* is allowed. ### Parameters -* `a`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). -* `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). -* `result`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref). The bitwise or of *a* and *b* will be saved in *result*. + + - `a`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + - `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + - `result`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref). The bitwise or of *a* and *b* will be saved in *result*. + ### Prototype + ```c void p4est_lid_bitwise_or (const p4est_lid_t * a, const p4est_lid_t * b, p4est_lid_t * result); ``` """ function p4est_lid_bitwise_or(a, b, result) - @ccall libp4est.p4est_lid_bitwise_or(a::Ptr{p4est_lid_t}, b::Ptr{p4est_lid_t}, result::Ptr{p4est_lid_t})::Cvoid + @ccall libp4est.p4est_lid_bitwise_or( + a::Ptr{p4est_lid_t}, + b::Ptr{p4est_lid_t}, + result::Ptr{p4est_lid_t}, + )::Cvoid end """ @@ -5935,16 +7475,23 @@ end Calculates the bitwise and of the uint128\\_t *a* and the uint128\\_t *b*. *a* == *result* is allowed. Furthermore, *a* == *result* and/or *b* == *result* is allowed. ### Parameters -* `a`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). -* `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). -* `result`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref). The bitwise and of *a* and *b* will be saved. in *result*. + + - `a`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + - `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + - `result`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref). The bitwise and of *a* and *b* will be saved. in *result*. + ### Prototype + ```c void p4est_lid_bitwise_and (const p4est_lid_t * a, const p4est_lid_t * b, p4est_lid_t * result); ``` """ function p4est_lid_bitwise_and(a, b, result) - @ccall libp4est.p4est_lid_bitwise_and(a::Ptr{p4est_lid_t}, b::Ptr{p4est_lid_t}, result::Ptr{p4est_lid_t})::Cvoid + @ccall libp4est.p4est_lid_bitwise_and( + a::Ptr{p4est_lid_t}, + b::Ptr{p4est_lid_t}, + result::Ptr{p4est_lid_t}, + )::Cvoid end """ @@ -5953,16 +7500,23 @@ end Calculates the bit right shift of uint128\\_t *input* by shift\\_count bits. We shift in zeros from the left. If *shift_count* >= 64, *result* is 0. All bits right from the zeroth bit (counted from the right hand side) drop out. *input* == *result* is allowed. ### Parameters -* `input`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). -* `shift_count`:\\[in\\] Bits to shift. *shift_count* >= 0. -* `result`:\\[in,out\\] A pointer to a [`p4est_lid_t`](@ref). The right shifted number will be saved in *result*. + + - `input`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + - `shift_count`:\\[in\\] Bits to shift. *shift_count* >= 0. + - `result`:\\[in,out\\] A pointer to a [`p4est_lid_t`](@ref). The right shifted number will be saved in *result*. + ### Prototype + ```c void p4est_lid_shift_right (const p4est_lid_t * input, unsigned shift_count, p4est_lid_t * result); ``` """ function p4est_lid_shift_right(input, shift_count, result) - @ccall libp4est.p4est_lid_shift_right(input::Ptr{p4est_lid_t}, shift_count::Cuint, result::Ptr{p4est_lid_t})::Cvoid + @ccall libp4est.p4est_lid_shift_right( + input::Ptr{p4est_lid_t}, + shift_count::Cuint, + result::Ptr{p4est_lid_t}, + )::Cvoid end """ @@ -5971,16 +7525,23 @@ end Calculates the bit left shift of uint128\\_t *input* by shift\\_count bits. We shift in zeros from the right. If *shift_count* >= 64, *result* is 0. All bits left from the 63th bit (counted zero based from the right hand side) drop out. *input* == *result* is allowed. ### Parameters -* `input`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). -* `shift_count`:\\[in\\] Bits to shift. *shift_count* >= 0. -* `result`:\\[in,out\\] A pointer to a [`p4est_lid_t`](@ref). The left shifted number will be saved in *result*. + + - `input`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + - `shift_count`:\\[in\\] Bits to shift. *shift_count* >= 0. + - `result`:\\[in,out\\] A pointer to a [`p4est_lid_t`](@ref). The left shifted number will be saved in *result*. + ### Prototype + ```c void p4est_lid_shift_left (const p4est_lid_t * input, unsigned shift_count, p4est_lid_t * result); ``` """ function p4est_lid_shift_left(input, shift_count, result) - @ccall libp4est.p4est_lid_shift_left(input::Ptr{p4est_lid_t}, shift_count::Cuint, result::Ptr{p4est_lid_t})::Cvoid + @ccall libp4est.p4est_lid_shift_left( + input::Ptr{p4est_lid_t}, + shift_count::Cuint, + result::Ptr{p4est_lid_t}, + )::Cvoid end """ @@ -5989,9 +7550,12 @@ end Adds the [`p4est_lid_t`](@ref) *b* to the [`p4est_lid_t`](@ref) *a*. The result is saved in *a*. *a* == *b* is allowed. ### Parameters -* `a`:\\[in,out\\] A pointer to a [`p4est_lid_t`](@ref). *a* will be overwritten by *a* + *b*. -* `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + + - `a`:\\[in,out\\] A pointer to a [`p4est_lid_t`](@ref). *a* will be overwritten by *a* + *b*. + - `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + ### Prototype + ```c void p4est_lid_add_inplace (p4est_lid_t * a, const p4est_lid_t * b); ``` @@ -6006,9 +7570,12 @@ end Substracts the uint128\\_t *b* from the uint128\\_t *a*. The result is saved in *a*. *a* == *b* is allowed. This function assumes that the result is >= 0. ### Parameters -* `a`:\\[in,out\\] A pointer to a [`p4est_lid_t`](@ref). *a* will be overwritten by *a* - *b*. -* `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + + - `a`:\\[in,out\\] A pointer to a [`p4est_lid_t`](@ref). *a* will be overwritten by *a* - *b*. + - `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + ### Prototype + ```c void p4est_lid_sub_inplace (p4est_lid_t * a, const p4est_lid_t * b); ``` @@ -6023,15 +7590,21 @@ end Calculates the bitwise or of the uint128\\_t *a* and the uint128\\_t *b*. *a* == *b* is allowed. ### Parameters -* `a`:\\[in,out\\] A pointer to a [`p4est_lid_t`](@ref). The bitwise or will be saved in *a*. -* `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + + - `a`:\\[in,out\\] A pointer to a [`p4est_lid_t`](@ref). The bitwise or will be saved in *a*. + - `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + ### Prototype + ```c void p4est_lid_bitwise_or_inplace (p4est_lid_t * a, const p4est_lid_t * b); ``` """ function p4est_lid_bitwise_or_inplace(a, b) - @ccall libp4est.p4est_lid_bitwise_or_inplace(a::Ptr{p4est_lid_t}, b::Ptr{p4est_lid_t})::Cvoid + @ccall libp4est.p4est_lid_bitwise_or_inplace( + a::Ptr{p4est_lid_t}, + b::Ptr{p4est_lid_t}, + )::Cvoid end """ @@ -6040,15 +7613,21 @@ end Calculates the bitwise and of the uint128\\_t *a* and the uint128\\_t *b*. *a* == *b* is allowed. ### Parameters -* `a`:\\[in,out\\] A pointer to a [`p4est_lid_t`](@ref). The bitwise and will be saved in *a*. -* `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + + - `a`:\\[in,out\\] A pointer to a [`p4est_lid_t`](@ref). The bitwise and will be saved in *a*. + - `b`:\\[in\\] A pointer to a [`p4est_lid_t`](@ref). + ### Prototype + ```c void p4est_lid_bitwise_and_inplace (p4est_lid_t * a, const p4est_lid_t * b); ``` """ function p4est_lid_bitwise_and_inplace(a, b) - @ccall libp4est.p4est_lid_bitwise_and_inplace(a::Ptr{p4est_lid_t}, b::Ptr{p4est_lid_t})::Cvoid + @ccall libp4est.p4est_lid_bitwise_and_inplace( + a::Ptr{p4est_lid_t}, + b::Ptr{p4est_lid_t}, + )::Cvoid end """ @@ -6061,16 +7640,23 @@ Computes the linear position as [`p4est_lid_t`](@ref) of a quadrant in a uniform The user\\_data of *quadrant* is never modified. ### Parameters -* `quadrant`:\\[in\\] Quadrant whose linear index will be computed. If the quadrant is smaller than the grid (has a higher quadrant->level), the result is computed from its ancestor at the grid's level. If the quadrant has a smaller level than the grid (it is bigger than a grid cell), the grid cell sharing its lower left corner is used as reference. -* `level`:\\[in\\] The level of the regular grid compared to which the linear position is to be computed. -* `id`:\\[in,out\\] A pointer to an allocated or static [`p4est_lid_t`](@ref). id will be the linear position of this quadrant on a uniform grid. + + - `quadrant`:\\[in\\] Quadrant whose linear index will be computed. If the quadrant is smaller than the grid (has a higher quadrant->level), the result is computed from its ancestor at the grid's level. If the quadrant has a smaller level than the grid (it is bigger than a grid cell), the grid cell sharing its lower left corner is used as reference. + - `level`:\\[in\\] The level of the regular grid compared to which the linear position is to be computed. + - `id`:\\[in,out\\] A pointer to an allocated or static [`p4est_lid_t`](@ref). id will be the linear position of this quadrant on a uniform grid. + ### Prototype + ```c void p4est_quadrant_linear_id_ext128 (const p4est_quadrant_t * quadrant, int level, p4est_lid_t * id); ``` """ function p4est_quadrant_linear_id_ext128(quadrant, level, id) - @ccall libp4est.p4est_quadrant_linear_id_ext128(quadrant::Ptr{p4est_quadrant_t}, level::Cint, id::Ptr{p4est_lid_t})::Cvoid + @ccall libp4est.p4est_quadrant_linear_id_ext128( + quadrant::Ptr{p4est_quadrant_t}, + level::Cint, + id::Ptr{p4est_lid_t}, + )::Cvoid end """ @@ -6083,28 +7669,54 @@ Set quadrant Morton indices based on linear position given as [`p4est_lid_t`](@r The user\\_data of *quadrant* is never modified. ### Parameters -* `quadrant`:\\[in,out\\] Quadrant whose Morton indices will be set. -* `level`:\\[in\\] Level of the grid and of the resulting quadrant. -* `id`:\\[in\\] Linear index of the quadrant on a uniform grid. + + - `quadrant`:\\[in,out\\] Quadrant whose Morton indices will be set. + - `level`:\\[in\\] Level of the grid and of the resulting quadrant. + - `id`:\\[in\\] Linear index of the quadrant on a uniform grid. + ### Prototype + ```c void p4est_quadrant_set_morton_ext128 (p4est_quadrant_t * quadrant, int level, const p4est_lid_t * id); ``` """ function p4est_quadrant_set_morton_ext128(quadrant, level, id) - @ccall libp4est.p4est_quadrant_set_morton_ext128(quadrant::Ptr{p4est_quadrant_t}, level::Cint, id::Ptr{p4est_lid_t})::Cvoid + @ccall libp4est.p4est_quadrant_set_morton_ext128( + quadrant::Ptr{p4est_quadrant_t}, + level::Cint, + id::Ptr{p4est_lid_t}, + )::Cvoid end """ p4est_new_ext(mpicomm, connectivity, min_quadrants, min_level, fill_uniform, data_size, init_fn, user_pointer) ### Prototype + ```c p4est_t *p4est_new_ext (sc_MPI_Comm mpicomm, p4est_connectivity_t * connectivity, p4est_locidx_t min_quadrants, int min_level, int fill_uniform, size_t data_size, p4est_init_t init_fn, void *user_pointer); ``` """ -function p4est_new_ext(mpicomm, connectivity, min_quadrants, min_level, fill_uniform, data_size, init_fn, user_pointer) - @ccall libp4est.p4est_new_ext(mpicomm::MPI_Comm, connectivity::Ptr{p4est_connectivity_t}, min_quadrants::p4est_locidx_t, min_level::Cint, fill_uniform::Cint, data_size::Csize_t, init_fn::p4est_init_t, user_pointer::Ptr{Cvoid})::Ptr{p4est_t} +function p4est_new_ext( + mpicomm, + connectivity, + min_quadrants, + min_level, + fill_uniform, + data_size, + init_fn, + user_pointer, +) + @ccall libp4est.p4est_new_ext( + mpicomm::MPI_Comm, + connectivity::Ptr{p4est_connectivity_t}, + min_quadrants::p4est_locidx_t, + min_level::Cint, + fill_uniform::Cint, + data_size::Csize_t, + init_fn::p4est_init_t, + user_pointer::Ptr{Cvoid}, + )::Ptr{p4est_t} end """ @@ -6113,20 +7725,31 @@ end Create a new mesh. ### Parameters -* `p4est`:\\[in\\] A forest that is fully 2:1 balanced. -* `ghost`:\\[in\\] The ghost layer created from the provided `p4est`. -* `compute_tree_index`:\\[in\\] Boolean to decide whether to allocate and compute the quad\\_to\\_tree list. -* `compute_level_lists`:\\[in\\] Boolean to decide whether to compute the level lists in quad\\_level. -* `btype`:\\[in\\] Currently ignored, only face neighbors are stored. + + - `p4est`:\\[in\\] A forest that is fully 2:1 balanced. + - `ghost`:\\[in\\] The ghost layer created from the provided `p4est`. + - `compute_tree_index`:\\[in\\] Boolean to decide whether to allocate and compute the quad\\_to\\_tree list. + - `compute_level_lists`:\\[in\\] Boolean to decide whether to compute the level lists in quad\\_level. + - `btype`:\\[in\\] Currently ignored, only face neighbors are stored. + ### Returns + A fully allocated mesh structure. + ### Prototype + ```c p4est_mesh_t *p4est_mesh_new_ext (p4est_t * p4est, p4est_ghost_t * ghost, int compute_tree_index, int compute_level_lists, p4est_connect_type_t btype); ``` """ function p4est_mesh_new_ext(p4est_, ghost, compute_tree_index, compute_level_lists, btype) - @ccall libp4est.p4est_mesh_new_ext(p4est_::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t}, compute_tree_index::Cint, compute_level_lists::Cint, btype::p4est_connect_type_t)::Ptr{p4est_mesh_t} + @ccall libp4est.p4est_mesh_new_ext( + p4est_::Ptr{p4est_t}, + ghost::Ptr{p4est_ghost_t}, + compute_tree_index::Cint, + compute_level_lists::Cint, + btype::p4est_connect_type_t, + )::Ptr{p4est_mesh_t} end """ @@ -6135,17 +7758,26 @@ end Make a deep copy of a `p4est`. The connectivity is not duplicated. Copying of quadrant user data is optional. If old and new data sizes are 0, the user\\_data field is copied regardless. The inspect member of the copy is set to NULL. The revision counter of the copy is set to zero. ### Parameters -* `copy_data`:\\[in\\] If true, data are copied. If false, data\\_size is set to 0. -* `duplicate_mpicomm`:\\[in\\] If true, MPI communicator is copied. + + - `copy_data`:\\[in\\] If true, data are copied. If false, data\\_size is set to 0. + - `duplicate_mpicomm`:\\[in\\] If true, MPI communicator is copied. + ### Returns + Returns a valid `p4est` that does not depend on the input, except for borrowing the same connectivity. Its revision counter is 0. + ### Prototype + ```c p4est_t *p4est_copy_ext (p4est_t * input, int copy_data, int duplicate_mpicomm); ``` """ function p4est_copy_ext(input, copy_data, duplicate_mpicomm) - @ccall libp4est.p4est_copy_ext(input::Ptr{p4est_t}, copy_data::Cint, duplicate_mpicomm::MPI_Comm)::Ptr{p4est_t} + @ccall libp4est.p4est_copy_ext( + input::Ptr{p4est_t}, + copy_data::Cint, + duplicate_mpicomm::MPI_Comm, + )::Ptr{p4est_t} end """ @@ -6154,19 +7786,36 @@ end Refine a forest with a bounded refinement level and a replace option. ### Parameters -* `p4est`:\\[in,out\\] The forest is changed in place. -* `refine_recursive`:\\[in\\] Boolean to decide on recursive refinement. -* `maxlevel`:\\[in\\] Maximum allowed refinement level (inclusive). If this is negative the level is restricted only by the compile-time constant QMAXLEVEL in `p4est.h`. -* `refine_fn`:\\[in\\] Callback function that must return true if a quadrant shall be refined. If refine\\_recursive is true, refine\\_fn is called for every existing and newly created quadrant. Otherwise, it is called for every existing quadrant. It is possible that a refinement request made by the callback is ignored. To catch this case, you can examine whether init\\_fn or replace\\_fn gets called. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data for newly created quadrants, which is guaranteed to be allocated. This function pointer may be NULL. -* `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace; may be NULL. + + - `p4est`:\\[in,out\\] The forest is changed in place. + - `refine_recursive`:\\[in\\] Boolean to decide on recursive refinement. + - `maxlevel`:\\[in\\] Maximum allowed refinement level (inclusive). If this is negative the level is restricted only by the compile-time constant QMAXLEVEL in `p4est.h`. + - `refine_fn`:\\[in\\] Callback function that must return true if a quadrant shall be refined. If refine\\_recursive is true, refine\\_fn is called for every existing and newly created quadrant. Otherwise, it is called for every existing quadrant. It is possible that a refinement request made by the callback is ignored. To catch this case, you can examine whether init\\_fn or replace\\_fn gets called. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data for newly created quadrants, which is guaranteed to be allocated. This function pointer may be NULL. + - `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace; may be NULL. + ### Prototype + ```c void p4est_refine_ext (p4est_t * p4est, int refine_recursive, int maxlevel, p4est_refine_t refine_fn, p4est_init_t init_fn, p4est_replace_t replace_fn); ``` """ -function p4est_refine_ext(p4est_, refine_recursive, maxlevel, refine_fn, init_fn, replace_fn) - @ccall libp4est.p4est_refine_ext(p4est_::Ptr{p4est_t}, refine_recursive::Cint, maxlevel::Cint, refine_fn::p4est_refine_t, init_fn::p4est_init_t, replace_fn::p4est_replace_t)::Cvoid +function p4est_refine_ext( + p4est_, + refine_recursive, + maxlevel, + refine_fn, + init_fn, + replace_fn, +) + @ccall libp4est.p4est_refine_ext( + p4est_::Ptr{p4est_t}, + refine_recursive::Cint, + maxlevel::Cint, + refine_fn::p4est_refine_t, + init_fn::p4est_init_t, + replace_fn::p4est_replace_t, + )::Cvoid end """ @@ -6175,19 +7824,36 @@ end Coarsen a forest. ### Parameters -* `p4est`:\\[in,out\\] The forest is changed in place. -* `coarsen_recursive`:\\[in\\] Boolean to decide on recursive coarsening. -* `callback_orphans`:\\[in\\] Boolean to enable calling coarsen\\_fn even on non-families. In this case, the second quadrant pointer in the argument list of the callback is NULL, subsequent pointers are undefined, and the return value is ignored. If coarsen\\_recursive is true, it is possible that a quadrant is called once or more as an orphan and eventually becomes part of a family. With coarsen\\_recursive false and callback\\_orphans true, it is guaranteed that every quadrant is passed exactly once into the coarsen\\_fn callback. -* `coarsen_fn`:\\[in\\] Callback function that returns true if a family of quadrants shall be coarsened. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. -* `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace. + + - `p4est`:\\[in,out\\] The forest is changed in place. + - `coarsen_recursive`:\\[in\\] Boolean to decide on recursive coarsening. + - `callback_orphans`:\\[in\\] Boolean to enable calling coarsen\\_fn even on non-families. In this case, the second quadrant pointer in the argument list of the callback is NULL, subsequent pointers are undefined, and the return value is ignored. If coarsen\\_recursive is true, it is possible that a quadrant is called once or more as an orphan and eventually becomes part of a family. With coarsen\\_recursive false and callback\\_orphans true, it is guaranteed that every quadrant is passed exactly once into the coarsen\\_fn callback. + - `coarsen_fn`:\\[in\\] Callback function that returns true if a family of quadrants shall be coarsened. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + - `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace. + ### Prototype + ```c void p4est_coarsen_ext (p4est_t * p4est, int coarsen_recursive, int callback_orphans, p4est_coarsen_t coarsen_fn, p4est_init_t init_fn, p4est_replace_t replace_fn); ``` """ -function p4est_coarsen_ext(p4est_, coarsen_recursive, callback_orphans, coarsen_fn, init_fn, replace_fn) - @ccall libp4est.p4est_coarsen_ext(p4est_::Ptr{p4est_t}, coarsen_recursive::Cint, callback_orphans::Cint, coarsen_fn::p4est_coarsen_t, init_fn::p4est_init_t, replace_fn::p4est_replace_t)::Cvoid +function p4est_coarsen_ext( + p4est_, + coarsen_recursive, + callback_orphans, + coarsen_fn, + init_fn, + replace_fn, +) + @ccall libp4est.p4est_coarsen_ext( + p4est_::Ptr{p4est_t}, + coarsen_recursive::Cint, + callback_orphans::Cint, + coarsen_fn::p4est_coarsen_t, + init_fn::p4est_init_t, + replace_fn::p4est_replace_t, + )::Cvoid end """ @@ -6196,29 +7862,44 @@ end 2:1 balance the size differences of neighboring elements in a forest. ### Parameters -* `p4est`:\\[in,out\\] The `p4est` to be worked on. -* `btype`:\\[in\\] Balance type (face or corner/full). Corner balance is almost never required when discretizing a PDE; just causes smoother mesh grading. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. -* `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace. + + - `p4est`:\\[in,out\\] The `p4est` to be worked on. + - `btype`:\\[in\\] Balance type (face or corner/full). Corner balance is almost never required when discretizing a PDE; just causes smoother mesh grading. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + - `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace. + ### Prototype + ```c void p4est_balance_ext (p4est_t * p4est, p4est_connect_type_t btype, p4est_init_t init_fn, p4est_replace_t replace_fn); ``` """ function p4est_balance_ext(p4est_, btype, init_fn, replace_fn) - @ccall libp4est.p4est_balance_ext(p4est_::Ptr{p4est_t}, btype::p4est_connect_type_t, init_fn::p4est_init_t, replace_fn::p4est_replace_t)::Cvoid + @ccall libp4est.p4est_balance_ext( + p4est_::Ptr{p4est_t}, + btype::p4est_connect_type_t, + init_fn::p4est_init_t, + replace_fn::p4est_replace_t, + )::Cvoid end """ p4est_balance_subtree_ext(p4est_, btype, which_tree, init_fn, replace_fn) ### Prototype + ```c void p4est_balance_subtree_ext (p4est_t * p4est, p4est_connect_type_t btype, p4est_topidx_t which_tree, p4est_init_t init_fn, p4est_replace_t replace_fn); ``` """ function p4est_balance_subtree_ext(p4est_, btype, which_tree, init_fn, replace_fn) - @ccall libp4est.p4est_balance_subtree_ext(p4est_::Ptr{p4est_t}, btype::p4est_connect_type_t, which_tree::p4est_topidx_t, init_fn::p4est_init_t, replace_fn::p4est_replace_t)::Cvoid + @ccall libp4est.p4est_balance_subtree_ext( + p4est_::Ptr{p4est_t}, + btype::p4est_connect_type_t, + which_tree::p4est_topidx_t, + init_fn::p4est_init_t, + replace_fn::p4est_replace_t, + )::Cvoid end """ @@ -6229,18 +7910,27 @@ Repartition the forest. The forest is partitioned between processors such that each processor has an approximately equal number of quadrants (or weight). ### Parameters -* `p4est`:\\[in,out\\] The forest that will be partitioned. -* `partition_for_coarsening`:\\[in\\] If true, the partition is modified to allow one level of coarsening. -* `weight_fn`:\\[in\\] A weighting function or NULL for uniform partitioning. A weighting function with constant weight 1 on each quadrant is equivalent to weight\\_fn == NULL but other constant weightings may result in different uniform partitionings. + + - `p4est`:\\[in,out\\] The forest that will be partitioned. + - `partition_for_coarsening`:\\[in\\] If true, the partition is modified to allow one level of coarsening. + - `weight_fn`:\\[in\\] A weighting function or NULL for uniform partitioning. A weighting function with constant weight 1 on each quadrant is equivalent to weight\\_fn == NULL but other constant weightings may result in different uniform partitionings. + ### Returns + The global number of shipped quadrants + ### Prototype + ```c p4est_gloidx_t p4est_partition_ext (p4est_t * p4est, int partition_for_coarsening, p4est_weight_t weight_fn); ``` """ function p4est_partition_ext(p4est_, partition_for_coarsening, weight_fn) - @ccall libp4est.p4est_partition_ext(p4est_::Ptr{p4est_t}, partition_for_coarsening::Cint, weight_fn::p4est_weight_t)::p4est_gloidx_t + @ccall libp4est.p4est_partition_ext( + p4est_::Ptr{p4est_t}, + partition_for_coarsening::Cint, + weight_fn::p4est_weight_t, + )::p4est_gloidx_t end """ @@ -6249,17 +7939,25 @@ end Correct partition to allow one level of coarsening. ### Parameters -* `p4est`:\\[in\\] forest whose partition is corrected -* `num_quadrants_in_proc`:\\[in,out\\] partition that will be corrected + + - `p4est`:\\[in\\] forest whose partition is corrected + - `num_quadrants_in_proc`:\\[in,out\\] partition that will be corrected + ### Returns + absolute number of moved quadrants + ### Prototype + ```c p4est_gloidx_t p4est_partition_for_coarsening (p4est_t * p4est, p4est_locidx_t * num_quadrants_in_proc); ``` """ function p4est_partition_for_coarsening(p4est_, num_quadrants_in_proc) - @ccall libp4est.p4est_partition_for_coarsening(p4est_::Ptr{p4est_t}, num_quadrants_in_proc::Ptr{p4est_locidx_t})::p4est_gloidx_t + @ccall libp4est.p4est_partition_for_coarsening( + p4est_::Ptr{p4est_t}, + num_quadrants_in_proc::Ptr{p4est_locidx_t}, + )::p4est_gloidx_t end """ @@ -6268,12 +7966,29 @@ end [`p4est_iterate_ext`](@ref) adds the option *remote*: if this is false, then it is the same as [`p4est_iterate`](@ref); if this is true, then corner callbacks are also called on corners for hanging faces touched by local quadrants. ### Prototype + ```c void p4est_iterate_ext (p4est_t * p4est, p4est_ghost_t * ghost_layer, void *user_data, p4est_iter_volume_t iter_volume, p4est_iter_face_t iter_face, p4est_iter_corner_t iter_corner, int remote); ``` """ -function p4est_iterate_ext(p4est_, ghost_layer, user_data, iter_volume, iter_face, iter_corner, remote) - @ccall libp4est.p4est_iterate_ext(p4est_::Ptr{p4est_t}, ghost_layer::Ptr{p4est_ghost_t}, user_data::Ptr{Cvoid}, iter_volume::p4est_iter_volume_t, iter_face::p4est_iter_face_t, iter_corner::p4est_iter_corner_t, remote::Cint)::Cvoid +function p4est_iterate_ext( + p4est_, + ghost_layer, + user_data, + iter_volume, + iter_face, + iter_corner, + remote, +) + @ccall libp4est.p4est_iterate_ext( + p4est_::Ptr{p4est_t}, + ghost_layer::Ptr{p4est_ghost_t}, + user_data::Ptr{Cvoid}, + iter_volume::p4est_iter_volume_t, + iter_face::p4est_iter_face_t, + iter_corner::p4est_iter_corner_t, + remote::Cint, + )::Cvoid end """ @@ -6286,41 +8001,87 @@ Save the complete connectivity/`p4est` data to disk. This is a collective operat Aborts on file errors. ### Parameters -* `filename`:\\[in\\] Name of the file to write. -* `p4est`:\\[in\\] Valid forest structure. -* `save_data`:\\[in\\] If true, the element data is saved. Otherwise, a data size of 0 is saved. -* `save_partition`:\\[in\\] If false, save file as if 1 core was used. If true, save core count and partition. Advantage: Partition can be recovered on loading with same mpisize and autopartition false. Disadvantage: Makes the file depend on mpisize. Either way the file can be loaded with autopartition true. + + - `filename`:\\[in\\] Name of the file to write. + - `p4est`:\\[in\\] Valid forest structure. + - `save_data`:\\[in\\] If true, the element data is saved. Otherwise, a data size of 0 is saved. + - `save_partition`:\\[in\\] If false, save file as if 1 core was used. If true, save core count and partition. Advantage: Partition can be recovered on loading with same mpisize and autopartition false. Disadvantage: Makes the file depend on mpisize. Either way the file can be loaded with autopartition true. + ### Prototype + ```c void p4est_save_ext (const char *filename, p4est_t * p4est, int save_data, int save_partition); ``` """ function p4est_save_ext(filename, p4est_, save_data, save_partition) - @ccall libp4est.p4est_save_ext(filename::Cstring, p4est_::Ptr{p4est_t}, save_data::Cint, save_partition::Cint)::Cvoid + @ccall libp4est.p4est_save_ext( + filename::Cstring, + p4est_::Ptr{p4est_t}, + save_data::Cint, + save_partition::Cint, + )::Cvoid end """ p4est_load_ext(filename, mpicomm, data_size, load_data, autopartition, broadcasthead, user_pointer, connectivity) ### Prototype + ```c p4est_t *p4est_load_ext (const char *filename, sc_MPI_Comm mpicomm, size_t data_size, int load_data, int autopartition, int broadcasthead, void *user_pointer, p4est_connectivity_t ** connectivity); ``` """ -function p4est_load_ext(filename, mpicomm, data_size, load_data, autopartition, broadcasthead, user_pointer, connectivity) - @ccall libp4est.p4est_load_ext(filename::Cstring, mpicomm::MPI_Comm, data_size::Csize_t, load_data::Cint, autopartition::Cint, broadcasthead::Cint, user_pointer::Ptr{Cvoid}, connectivity::Ptr{Ptr{p4est_connectivity_t}})::Ptr{p4est_t} +function p4est_load_ext( + filename, + mpicomm, + data_size, + load_data, + autopartition, + broadcasthead, + user_pointer, + connectivity, +) + @ccall libp4est.p4est_load_ext( + filename::Cstring, + mpicomm::MPI_Comm, + data_size::Csize_t, + load_data::Cint, + autopartition::Cint, + broadcasthead::Cint, + user_pointer::Ptr{Cvoid}, + connectivity::Ptr{Ptr{p4est_connectivity_t}}, + )::Ptr{p4est_t} end """ p4est_source_ext(src, mpicomm, data_size, load_data, autopartition, broadcasthead, user_pointer, connectivity) ### Prototype + ```c p4est_t *p4est_source_ext (sc_io_source_t * src, sc_MPI_Comm mpicomm, size_t data_size, int load_data, int autopartition, int broadcasthead, void *user_pointer, p4est_connectivity_t ** connectivity); ``` """ -function p4est_source_ext(src, mpicomm, data_size, load_data, autopartition, broadcasthead, user_pointer, connectivity) - @ccall libp4est.p4est_source_ext(src::Ptr{sc_io_source_t}, mpicomm::MPI_Comm, data_size::Csize_t, load_data::Cint, autopartition::Cint, broadcasthead::Cint, user_pointer::Ptr{Cvoid}, connectivity::Ptr{Ptr{p4est_connectivity_t}})::Ptr{p4est_t} +function p4est_source_ext( + src, + mpicomm, + data_size, + load_data, + autopartition, + broadcasthead, + user_pointer, + connectivity, +) + @ccall libp4est.p4est_source_ext( + src::Ptr{sc_io_source_t}, + mpicomm::MPI_Comm, + data_size::Csize_t, + load_data::Cint, + autopartition::Cint, + broadcasthead::Cint, + user_pointer::Ptr{Cvoid}, + connectivity::Ptr{Ptr{p4est_connectivity_t}}, + )::Ptr{p4est_t} end """ @@ -6331,30 +8092,69 @@ Create the data necessary to create a PETsc DMPLEX representation of a forest, a All arrays should be initialized to hold sizeof ([`p4est_locidx_t`](@ref)), except for *out_remotes*, which should be initialized to hold (2 * sizeof ([`p4est_locidx_t`](@ref))). ### Parameters -* `p4est`:\\[in\\] the forest -* `ghost`:\\[out\\] the ghost layer -* `lnodes`:\\[out\\] the lnodes -* `ctype`:\\[in\\] the type of adjacency for the overlap -* `overlap`:\\[in\\] the number of layers of overlap (zero is acceptable) -* `first_local_quad`:\\[out\\] the local quadrants are assigned contiguous plex indices, starting with this index -* `out_points_per_dim`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() -* `out_cone_sizes`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() -* `out_cones`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() -* `out_cone_orientations`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() -* `out_vertex_coords`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() -* `out_children`:\\[in,out\\] filled with argument for DMPlexSetTree() -* `out_parents`:\\[in,out\\] filled with argument for DMPlexSetTree() -* `out_childids`:\\[in,out\\] filled with argument for DMPlexSetTree() -* `out_leaves`:\\[in,out\\] filled with argument for PetscSFSetGraph() -* `out_remotes`:\\[in,out\\] filled with argument for PetscSFSetGraph() -* `custom_numbering`:\\[in\\] Whether or use the default numbering (0) of DMPlex child ids or the custom (1). + + - `p4est`:\\[in\\] the forest + - `ghost`:\\[out\\] the ghost layer + - `lnodes`:\\[out\\] the lnodes + - `ctype`:\\[in\\] the type of adjacency for the overlap + - `overlap`:\\[in\\] the number of layers of overlap (zero is acceptable) + - `first_local_quad`:\\[out\\] the local quadrants are assigned contiguous plex indices, starting with this index + - `out_points_per_dim`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() + - `out_cone_sizes`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() + - `out_cones`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() + - `out_cone_orientations`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() + - `out_vertex_coords`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() + - `out_children`:\\[in,out\\] filled with argument for DMPlexSetTree() + - `out_parents`:\\[in,out\\] filled with argument for DMPlexSetTree() + - `out_childids`:\\[in,out\\] filled with argument for DMPlexSetTree() + - `out_leaves`:\\[in,out\\] filled with argument for PetscSFSetGraph() + - `out_remotes`:\\[in,out\\] filled with argument for PetscSFSetGraph() + - `custom_numbering`:\\[in\\] Whether or use the default numbering (0) of DMPlex child ids or the custom (1). + ### Prototype + ```c void p4est_get_plex_data_ext (p4est_t * p4est, p4est_ghost_t ** ghost, p4est_lnodes_t ** lnodes, p4est_connect_type_t ctype, int overlap, p4est_locidx_t * first_local_quad, sc_array_t * out_points_per_dim, sc_array_t * out_cone_sizes, sc_array_t * out_cones, sc_array_t * out_cone_orientations, sc_array_t * out_vertex_coords, sc_array_t * out_children, sc_array_t * out_parents, sc_array_t * out_childids, sc_array_t * out_leaves, sc_array_t * out_remotes, int custom_numbering); ``` """ -function p4est_get_plex_data_ext(p4est_, ghost, lnodes, ctype, overlap, first_local_quad, out_points_per_dim, out_cone_sizes, out_cones, out_cone_orientations, out_vertex_coords, out_children, out_parents, out_childids, out_leaves, out_remotes, custom_numbering) - @ccall libp4est.p4est_get_plex_data_ext(p4est_::Ptr{p4est_t}, ghost::Ptr{Ptr{p4est_ghost_t}}, lnodes::Ptr{Ptr{p4est_lnodes_t}}, ctype::p4est_connect_type_t, overlap::Cint, first_local_quad::Ptr{p4est_locidx_t}, out_points_per_dim::Ptr{sc_array_t}, out_cone_sizes::Ptr{sc_array_t}, out_cones::Ptr{sc_array_t}, out_cone_orientations::Ptr{sc_array_t}, out_vertex_coords::Ptr{sc_array_t}, out_children::Ptr{sc_array_t}, out_parents::Ptr{sc_array_t}, out_childids::Ptr{sc_array_t}, out_leaves::Ptr{sc_array_t}, out_remotes::Ptr{sc_array_t}, custom_numbering::Cint)::Cvoid +function p4est_get_plex_data_ext( + p4est_, + ghost, + lnodes, + ctype, + overlap, + first_local_quad, + out_points_per_dim, + out_cone_sizes, + out_cones, + out_cone_orientations, + out_vertex_coords, + out_children, + out_parents, + out_childids, + out_leaves, + out_remotes, + custom_numbering, +) + @ccall libp4est.p4est_get_plex_data_ext( + p4est_::Ptr{p4est_t}, + ghost::Ptr{Ptr{p4est_ghost_t}}, + lnodes::Ptr{Ptr{p4est_lnodes_t}}, + ctype::p4est_connect_type_t, + overlap::Cint, + first_local_quad::Ptr{p4est_locidx_t}, + out_points_per_dim::Ptr{sc_array_t}, + out_cone_sizes::Ptr{sc_array_t}, + out_cones::Ptr{sc_array_t}, + out_cone_orientations::Ptr{sc_array_t}, + out_vertex_coords::Ptr{sc_array_t}, + out_children::Ptr{sc_array_t}, + out_parents::Ptr{sc_array_t}, + out_childids::Ptr{sc_array_t}, + out_leaves::Ptr{sc_array_t}, + out_remotes::Ptr{sc_array_t}, + custom_numbering::Cint, + )::Cvoid end """ @@ -6363,19 +8163,29 @@ end Binary search in partition array. Given two targets *my_begin* and *my_end*, find offsets such that `search\\_in[begin] >= my\\_begin`, `my\\_end <= search\\_in[end]`. If more than one index satisfies the conditions, then the minimal index is the result. If there is no index that satisfies the conditions, then *begin* and *end* are tried to set equal such that `search\\_in[begin] >= my\\_end`. If *my_begin* is less or equal than the smallest value of *search_in* *begin* is set to 0 and if *my_end* is bigger or equal than the largest value of *search_in* *end* is set to *num_procs* - 1. If none of the above conditions is satisfied, the output is not well defined. We require `my\\_begin <= my\\_begin'. ### Parameters -* `num_procs`:\\[in\\] Number of processes to get the length of *search_in*. -* `search_in`:\\[in\\] The sorted array (ascending) in that the function will search. If `k` indexes search\\_in, then `0 <= k < num\\_procs`. -* `my_begin`:\\[in\\] The first target that defines the start of the search window. -* `my_end`:\\[in\\] The second target that defines the end of the search window. -* `begin`:\\[in,out\\] The first offset such that `search\\_in[begin] >= my\\_begin`. -* `end`:\\[in,out\\] The second offset such that `my\\_end <= search\\_in[end]`. + + - `num_procs`:\\[in\\] Number of processes to get the length of *search_in*. + - `search_in`:\\[in\\] The sorted array (ascending) in that the function will search. If `k` indexes search\\_in, then `0 <= k < num\\_procs`. + - `my_begin`:\\[in\\] The first target that defines the start of the search window. + - `my_end`:\\[in\\] The second target that defines the end of the search window. + - `begin`:\\[in,out\\] The first offset such that `search\\_in[begin] >= my\\_begin`. + - `end`:\\[in,out\\] The second offset such that `my\\_end <= search\\_in[end]`. + ### Prototype + ```c void p4est_find_partition (const int num_procs, p4est_gloidx_t * search_in, p4est_gloidx_t my_begin, p4est_gloidx_t my_end, p4est_gloidx_t * begin, p4est_gloidx_t * end); ``` """ function p4est_find_partition(num_procs, search_in, my_begin, my_end, _begin, _end) - @ccall libp4est.p4est_find_partition(num_procs::Cint, search_in::Ptr{p4est_gloidx_t}, my_begin::p4est_gloidx_t, my_end::p4est_gloidx_t, _begin::Ptr{p4est_gloidx_t}, _end::Ptr{p4est_gloidx_t})::Cvoid + @ccall libp4est.p4est_find_partition( + num_procs::Cint, + search_in::Ptr{p4est_gloidx_t}, + my_begin::p4est_gloidx_t, + my_end::p4est_gloidx_t, + _begin::Ptr{p4est_gloidx_t}, + _end::Ptr{p4est_gloidx_t}, + )::Cvoid end """ @@ -6384,14 +8194,21 @@ end Find the lowest position tq in a quadrant array such that tq >= q. ### Returns + Returns the id of the matching quadrant or -1 if array < q or the array is empty. + ### Prototype + ```c ssize_t p4est_find_lower_bound (sc_array_t * array, const p4est_quadrant_t * q, size_t guess); ``` """ function p4est_find_lower_bound(array, q, guess) - @ccall libp4est.p4est_find_lower_bound(array::Ptr{sc_array_t}, q::Ptr{p4est_quadrant_t}, guess::Csize_t)::Cssize_t + @ccall libp4est.p4est_find_lower_bound( + array::Ptr{sc_array_t}, + q::Ptr{p4est_quadrant_t}, + guess::Csize_t, + )::Cssize_t end """ @@ -6400,14 +8217,21 @@ end Find the highest position tq in a quadrant array such that tq <= q. ### Returns + Returns the id of the matching quadrant or -1 if array > q or the array is empty. + ### Prototype + ```c ssize_t p4est_find_higher_bound (sc_array_t * array, const p4est_quadrant_t * q, size_t guess); ``` """ function p4est_find_higher_bound(array, q, guess) - @ccall libp4est.p4est_find_higher_bound(array::Ptr{sc_array_t}, q::Ptr{p4est_quadrant_t}, guess::Csize_t)::Cssize_t + @ccall libp4est.p4est_find_higher_bound( + array::Ptr{sc_array_t}, + q::Ptr{p4est_quadrant_t}, + guess::Csize_t, + )::Cssize_t end """ @@ -6418,19 +8242,29 @@ Search a local quadrant by its cumulative number in the forest. We perform a binary search over the processor-local trees, which means that it is advisable NOT to use this function if possible, and to try to maintain O(1) tree context information in the calling code. ### Parameters -* `p4est`:\\[in\\] Forest to be worked with. -* `cumulative_id`:\\[in\\] Cumulative index over all trees of quadrant. -* `which_tree`:\\[in,out\\] If not NULL, the input value can be -1 or an initial guess for the quadrant's tree. An initial guess must be the index of a nonempty local tree. Output is the tree of returned quadrant. -* `quadrant_id`:\\[out\\] If not NULL, the number of quadrant in tree. + + - `p4est`:\\[in\\] Forest to be worked with. + - `cumulative_id`:\\[in\\] Cumulative index over all trees of quadrant. + - `which_tree`:\\[in,out\\] If not NULL, the input value can be -1 or an initial guess for the quadrant's tree. An initial guess must be the index of a nonempty local tree. Output is the tree of returned quadrant. + - `quadrant_id`:\\[out\\] If not NULL, the number of quadrant in tree. + ### Returns + The identified quadrant. + ### Prototype + ```c p4est_quadrant_t *p4est_find_quadrant_cumulative (p4est_t * p4est, p4est_locidx_t cumulative_id, p4est_topidx_t * which_tree, p4est_locidx_t * quadrant_id); ``` """ function p4est_find_quadrant_cumulative(p4est_, cumulative_id, which_tree, quadrant_id) - @ccall libp4est.p4est_find_quadrant_cumulative(p4est_::Ptr{p4est_t}, cumulative_id::p4est_locidx_t, which_tree::Ptr{p4est_topidx_t}, quadrant_id::Ptr{p4est_locidx_t})::Ptr{p4est_quadrant_t} + @ccall libp4est.p4est_find_quadrant_cumulative( + p4est_::Ptr{p4est_t}, + cumulative_id::p4est_locidx_t, + which_tree::Ptr{p4est_topidx_t}, + quadrant_id::Ptr{p4est_locidx_t}, + )::Ptr{p4est_quadrant_t} end """ @@ -6441,16 +8275,23 @@ Split an array of quadrants by the children of an ancestor. Given a sorted **array** of quadrants that have a common ancestor at level **level**, compute the **indices** of the first quadrant in each of the common ancestor's children at level **level** + 1. ### Parameters -* `array`:\\[in\\] The sorted array of quadrants of level > **level**. -* `level`:\\[in\\] The level at which there is a common ancestor. -* `indices`:\\[in,out\\] The indices of the first quadrant in each of the ancestors's children, plus an additional index on the end. The quadrants of **array** that are descendants of child i have indices between indices[i] and indices[i + 1] - 1. If indices[i] = indices[i+1], this indicates that no quadrant in the array is contained in child i. + + - `array`:\\[in\\] The sorted array of quadrants of level > **level**. + - `level`:\\[in\\] The level at which there is a common ancestor. + - `indices`:\\[in,out\\] The indices of the first quadrant in each of the ancestors's children, plus an additional index on the end. The quadrants of **array** that are descendants of child i have indices between indices[i] and indices[i + 1] - 1. If indices[i] = indices[i+1], this indicates that no quadrant in the array is contained in child i. + ### Prototype + ```c void p4est_split_array (sc_array_t * array, int level, size_t indices[]); ``` """ function p4est_split_array(array, level, indices) - @ccall libp4est.p4est_split_array(array::Ptr{sc_array_t}, level::Cint, indices::Ptr{Csize_t})::Cvoid + @ccall libp4est.p4est_split_array( + array::Ptr{sc_array_t}, + level::Cint, + indices::Ptr{Csize_t}, + )::Cvoid end """ @@ -6461,20 +8302,31 @@ Find the boundary points touched by a range of quadrants. Given two smallest quadrants, **lq** and **uq**, that mark the first and the last quadrant in a range of quadrants, determine which portions of the tree boundary the range touches. ### Parameters -* `lq`:\\[in\\] The smallest quadrant at the start of the range: if NULL, the tree's first quadrant is taken to be the start of the range. -* `uq`:\\[in\\] The smallest quadrant at the end of the range: if NULL, the tree's last quadrant is taken to be the end of the range. -* `level`:\\[in\\] The level of the containing quadrant whose boundaries are tested: 0 if we want to test the boundaries of the whole tree. -* `faces`:\\[in,out\\] An array of size 4 that is filled: faces[i] is true if the range touches that face. -* `corners`:\\[in,out\\] An array of size 4 that is filled: corners[i] is true if the range touches that corner. **faces** or **corners** may be NULL. + + - `lq`:\\[in\\] The smallest quadrant at the start of the range: if NULL, the tree's first quadrant is taken to be the start of the range. + - `uq`:\\[in\\] The smallest quadrant at the end of the range: if NULL, the tree's last quadrant is taken to be the end of the range. + - `level`:\\[in\\] The level of the containing quadrant whose boundaries are tested: 0 if we want to test the boundaries of the whole tree. + - `faces`:\\[in,out\\] An array of size 4 that is filled: faces[i] is true if the range touches that face. + - `corners`:\\[in,out\\] An array of size 4 that is filled: corners[i] is true if the range touches that corner. **faces** or **corners** may be NULL. + ### Returns + Returns an int32\\_t encoded with the same information in **faces** and **corners**: the first (least) four bits represent the four faces, the next four bits represent the four corners. + ### Prototype + ```c int32_t p4est_find_range_boundaries (p4est_quadrant_t * lq, p4est_quadrant_t * uq, int level, int faces[], int corners[]); ``` """ function p4est_find_range_boundaries(lq, uq, level, faces, corners) - @ccall libp4est.p4est_find_range_boundaries(lq::Ptr{p4est_quadrant_t}, uq::Ptr{p4est_quadrant_t}, level::Cint, faces::Ptr{Cint}, corners::Ptr{Cint})::Int32 + @ccall libp4est.p4est_find_range_boundaries( + lq::Ptr{p4est_quadrant_t}, + uq::Ptr{p4est_quadrant_t}, + level::Cint, + faces::Ptr{Cint}, + corners::Ptr{Cint}, + )::Int32 end # typedef int ( * p4est_search_local_t ) ( p4est_t * p4est , p4est_topidx_t which_tree , p4est_quadrant_t * quadrant , p4est_locidx_t local_num , void * point ) @@ -6484,17 +8336,22 @@ Callback function to query the match of a "point" with a quadrant. This function can be called in two roles: Per-quadrant, in which case the parameter **point** is NULL, or per-point, possibly many times per quadrant. ### Parameters -* `p4est`:\\[in\\] The forest to be queried. -* `which_tree`:\\[in\\] The tree id under consideration. -* `quadrant`:\\[in\\] The quadrant under consideration. This quadrant may be coarser than the quadrants that are contained in the forest (an ancestor), in which case it is a temporary variable and not part of the forest storage. Otherwise, it is a leaf and points directly into the forest storage. -* `local_num`:\\[in\\] If the quadrant is not a leaf, this is < 0. Otherwise it is the (non-negative) index of the quadrant relative to the processor-local storage. -* `point`:\\[in\\] Representation of a "point"; user-defined. If **point** is NULL, the callback may be used to prepare quadrant-related search meta data. + + - `p4est`:\\[in\\] The forest to be queried. + - `which_tree`:\\[in\\] The tree id under consideration. + - `quadrant`:\\[in\\] The quadrant under consideration. This quadrant may be coarser than the quadrants that are contained in the forest (an ancestor), in which case it is a temporary variable and not part of the forest storage. Otherwise, it is a leaf and points directly into the forest storage. + - `local_num`:\\[in\\] If the quadrant is not a leaf, this is < 0. Otherwise it is the (non-negative) index of the quadrant relative to the processor-local storage. + - `point`:\\[in\\] Representation of a "point"; user-defined. If **point** is NULL, the callback may be used to prepare quadrant-related search meta data. + ### Returns + If **point** is NULL, true if the search confined to **quadrant** should be executed, false to skip it. Else, true if point may be contained in the quadrant and false otherwise; the return value has no effect on a leaf. """ const p4est_search_local_t = Ptr{Cvoid} -"""This typedef is provided for backwards compatibility.""" +""" +This typedef is provided for backwards compatibility. +""" const p4est_search_query_t = p4est_search_local_t """ @@ -6511,18 +8368,27 @@ If points are present and the first quadrant callback returned true, we execute If the points are a NULL array, they are ignored and the recursion proceeds by querying the per-quadrant callback. If the points are not NULL but an empty array, the recursion will stop immediately! ### Parameters -* `p4est`:\\[in\\] The forest to be searched. -* `call_post`:\\[in\\] If true, call quadrant callback both pre and post. -* `quadrant_fn`:\\[in\\] Executed once when a quadrant is entered, and once when it is left (the second time only if points are present and the first call returned true). This quadrant is always local, if not completely then at least one descendant of it. If the callback returns false, this quadrant and its descendants are excluded from the search recursion. Its **point** argument is always NULL. Callback may be NULL in which case it is ignored. -* `point_fn`:\\[in\\] If **points** is not NULL, must be not NULL. Shall return true for any possible matching point. If **points** is NULL, this callback is ignored. -* `points`:\\[in\\] User-defined array of "points". If NULL, only the **quadrant_fn** callback is executed. If that is NULL, this function noops. If not NULL, the **point_fn** is called on its members during the search. + + - `p4est`:\\[in\\] The forest to be searched. + - `call_post`:\\[in\\] If true, call quadrant callback both pre and post. + - `quadrant_fn`:\\[in\\] Executed once when a quadrant is entered, and once when it is left (the second time only if points are present and the first call returned true). This quadrant is always local, if not completely then at least one descendant of it. If the callback returns false, this quadrant and its descendants are excluded from the search recursion. Its **point** argument is always NULL. Callback may be NULL in which case it is ignored. + - `point_fn`:\\[in\\] If **points** is not NULL, must be not NULL. Shall return true for any possible matching point. If **points** is NULL, this callback is ignored. + - `points`:\\[in\\] User-defined array of "points". If NULL, only the **quadrant_fn** callback is executed. If that is NULL, this function noops. If not NULL, the **point_fn** is called on its members during the search. + ### Prototype + ```c void p4est_search_local (p4est_t * p4est, int call_post, p4est_search_local_t quadrant_fn, p4est_search_local_t point_fn, sc_array_t * points); ``` """ function p4est_search_local(p4est_, call_post, quadrant_fn, point_fn, points) - @ccall libp4est.p4est_search_local(p4est_::Ptr{p4est_t}, call_post::Cint, quadrant_fn::p4est_search_local_t, point_fn::p4est_search_local_t, points::Ptr{sc_array_t})::Cvoid + @ccall libp4est.p4est_search_local( + p4est_::Ptr{p4est_t}, + call_post::Cint, + quadrant_fn::p4est_search_local_t, + point_fn::p4est_search_local_t, + points::Ptr{sc_array_t}, + )::Cvoid end """ @@ -6531,12 +8397,18 @@ end This function is provided for backwards compatibility. We call p4est_search_local with call\\_post = 0. ### Prototype + ```c void p4est_search (p4est_t * p4est, p4est_search_query_t quadrant_fn, p4est_search_query_t point_fn, sc_array_t * points); ``` """ function p4est_search(p4est_, quadrant_fn, point_fn, points) - @ccall libp4est.p4est_search(p4est_::Ptr{p4est_t}, quadrant_fn::p4est_search_query_t, point_fn::p4est_search_query_t, points::Ptr{sc_array_t})::Cvoid + @ccall libp4est.p4est_search( + p4est_::Ptr{p4est_t}, + quadrant_fn::p4est_search_query_t, + point_fn::p4est_search_query_t, + points::Ptr{sc_array_t}, + )::Cvoid end # typedef int ( * p4est_search_partition_t ) ( p4est_t * p4est , p4est_topidx_t which_tree , p4est_quadrant_t * quadrant , int pfirst , int plast , void * point ) @@ -6544,13 +8416,16 @@ end Callback function for the partition recursion. ### Parameters -* `p4est`:\\[in\\] The forest to traverse. Its local quadrants are never accessed. -* `which_tree`:\\[in\\] The tree number under consideration. -* `quadrant`:\\[in\\] This quadrant is not from local forest storage, and its user data is undefined. It represents the branch of the forest in the top-down recursion. -* `pfirst`:\\[in\\] The lowest processor that owns part of **quadrant**. Guaranteed to be non-empty. -* `plast`:\\[in\\] The highest processor that owns part of **quadrant**. Guaranteed to be non-empty. If this is equal to **pfirst**, then the recursion will stop for **quadrant**'s branch after this function returns. -* `point`:\\[in,out\\] Pointer to a user-defined point object. If called per-quadrant, this is NULL. + + - `p4est`:\\[in\\] The forest to traverse. Its local quadrants are never accessed. + - `which_tree`:\\[in\\] The tree number under consideration. + - `quadrant`:\\[in\\] This quadrant is not from local forest storage, and its user data is undefined. It represents the branch of the forest in the top-down recursion. + - `pfirst`:\\[in\\] The lowest processor that owns part of **quadrant**. Guaranteed to be non-empty. + - `plast`:\\[in\\] The highest processor that owns part of **quadrant**. Guaranteed to be non-empty. If this is equal to **pfirst**, then the recursion will stop for **quadrant**'s branch after this function returns. + - `point`:\\[in,out\\] Pointer to a user-defined point object. If called per-quadrant, this is NULL. + ### Returns + If false, the recursion at quadrant is terminated. If true, it continues if **pfirst** < **plast**. """ const p4est_search_partition_t = Ptr{Cvoid} @@ -6565,18 +8440,27 @@ Traverse the global partition top-down. We proceed top-down through the partitio Traversing the whole processor partition will be at least O(P), so sensible use of the callback function is advised to cut it short. ### Parameters -* `p4est`:\\[in\\] The forest to traverse. Its local quadrants are never accessed. -* `call_post`:\\[in\\] If true, call quadrant callback both pre and post. -* `quadrant_fn`:\\[in\\] This function controls the recursion, which only continues deeper if this callback returns true for a branch quadrant. It is allowed to set this to NULL. -* `point_fn`:\\[in\\] This function decides per-point whether it is followed down the recursion. Must be non-NULL if **points** are not NULL. -* `points`:\\[in\\] User-provided array of **points** that are passed to the callback **point_fn**. See p4est_search_local for details. + + - `p4est`:\\[in\\] The forest to traverse. Its local quadrants are never accessed. + - `call_post`:\\[in\\] If true, call quadrant callback both pre and post. + - `quadrant_fn`:\\[in\\] This function controls the recursion, which only continues deeper if this callback returns true for a branch quadrant. It is allowed to set this to NULL. + - `point_fn`:\\[in\\] This function decides per-point whether it is followed down the recursion. Must be non-NULL if **points** are not NULL. + - `points`:\\[in\\] User-provided array of **points** that are passed to the callback **point_fn**. See p4est_search_local for details. + ### Prototype + ```c void p4est_search_partition (p4est_t * p4est, int call_post, p4est_search_partition_t quadrant_fn, p4est_search_partition_t point_fn, sc_array_t * points); ``` """ function p4est_search_partition(p4est_, call_post, quadrant_fn, point_fn, points) - @ccall libp4est.p4est_search_partition(p4est_::Ptr{p4est_t}, call_post::Cint, quadrant_fn::p4est_search_partition_t, point_fn::p4est_search_partition_t, points::Ptr{sc_array_t})::Cvoid + @ccall libp4est.p4est_search_partition( + p4est_::Ptr{p4est_t}, + call_post::Cint, + quadrant_fn::p4est_search_partition_t, + point_fn::p4est_search_partition_t, + points::Ptr{sc_array_t}, + )::Cvoid end # typedef int ( * p4est_search_all_t ) ( p4est_t * p4est , p4est_topidx_t which_tree , p4est_quadrant_t * quadrant , int pfirst , int plast , p4est_locidx_t local_num , void * point ) @@ -6584,14 +8468,17 @@ end Callback function for the top-down search through the whole forest. ### Parameters -* `p4est`:\\[in\\] The forest to search. We recurse through the trees one after another. -* `which_tree`:\\[in\\] The current tree number. -* `quadrant`:\\[in\\] The current quadrant in the recursion. This quadrant is either a non-leaf tree branch or a leaf. If the quadrant is contained in the local partition, we know which, otherwise we don't. Let us first consider the situation when **quadrant** is local, which is indicated by both **pfirst** and **plast** being equal to `p4est`->mpirank. Then the parameter **local_num** is negative for non-leaves and the number of the quadrant as a leaf in local storage otherwise. Only if the quadrant is a local leaf, it points to the actual local storage and can be used to access user data etc., and the recursion terminates. The other possibility is that **pfirst** < **plast**, in which case we proceed with the recursion, or both are equal to the same remote rank, in which case the recursion terminates. Either way, the quadrant is not from local forest storage. -* `pfirst`:\\[in\\] The lowest processor that owns part of **quadrant**. Guaranteed to be non-empty. -* `plast`:\\[in\\] The highest processor that owns part of **quadrant**. Guaranteed to be non-empty. -* `local_num`:\\[in\\] If **quadrant** is a local leaf, this number is the index of the leaf in local quadrant storage. Else, this is a negative value. -* `point`:\\[in,out\\] User-defined representation of a point. This parameter distinguishes two uses of the callback. For each quadrant, the callback is first called with a NULL point, and if this callback returns true, once for each point tracked in this branch. The return value for a point determines whether it shall be tracked further down the branch or not, and has no effect on a local leaf. The call with a NULL point is intended to prepare quadrant-related search meta data that is common to all points, and/or to efficiently terminate the recursion for all points in the branch in one call. + + - `p4est`:\\[in\\] The forest to search. We recurse through the trees one after another. + - `which_tree`:\\[in\\] The current tree number. + - `quadrant`:\\[in\\] The current quadrant in the recursion. This quadrant is either a non-leaf tree branch or a leaf. If the quadrant is contained in the local partition, we know which, otherwise we don't. Let us first consider the situation when **quadrant** is local, which is indicated by both **pfirst** and **plast** being equal to `p4est`->mpirank. Then the parameter **local_num** is negative for non-leaves and the number of the quadrant as a leaf in local storage otherwise. Only if the quadrant is a local leaf, it points to the actual local storage and can be used to access user data etc., and the recursion terminates. The other possibility is that **pfirst** < **plast**, in which case we proceed with the recursion, or both are equal to the same remote rank, in which case the recursion terminates. Either way, the quadrant is not from local forest storage. + - `pfirst`:\\[in\\] The lowest processor that owns part of **quadrant**. Guaranteed to be non-empty. + - `plast`:\\[in\\] The highest processor that owns part of **quadrant**. Guaranteed to be non-empty. + - `local_num`:\\[in\\] If **quadrant** is a local leaf, this number is the index of the leaf in local quadrant storage. Else, this is a negative value. + - `point`:\\[in,out\\] User-defined representation of a point. This parameter distinguishes two uses of the callback. For each quadrant, the callback is first called with a NULL point, and if this callback returns true, once for each point tracked in this branch. The return value for a point determines whether it shall be tracked further down the branch or not, and has no effect on a local leaf. The call with a NULL point is intended to prepare quadrant-related search meta data that is common to all points, and/or to efficiently terminate the recursion for all points in the branch in one call. + ### Returns + If false, the recursion at **quadrant** terminates. If true, it continues if **pfirst** < **plast** or if they are both equal to `p4est`->mpirank and the recursion has not reached a leaf yet. """ const p4est_search_all_t = Ptr{Cvoid} @@ -6622,26 +8509,39 @@ Note that in the remote case (a), we may terminate the recursion even if the qua This function works fine when used for the special cases that either the partition or the local quadrants are not of interest. However, in the case of querying only local information we expect that p4est_search_local will be faster since it employs specific local optimizations. ### Parameters -* `p4est`:\\[in\\] The forest to be searched. -* `call_post`:\\[in\\] If true, call quadrant callback both pre and post. -* `quadrant_fn`:\\[in\\] Executed once for each quadrant that is entered. If the callback returns false, this quadrant and its descendants are excluded from the search, and the points in this branch are not queried further. Its **point** argument is always NULL. Callback may be NULL in which case it is ignored. -* `point_fn`:\\[in\\] Executed once for each point that is relevant for a quadrant of the search. If it returns true, the point is tracked further down that branch, else it is discarded from the queries for the children. If **points** is not NULL, this callback must be not NULL. If **points** is NULL, it is not called. -* `points`:\\[in\\] User-defined array of points. We do not interpret a point, just pass it into the callbacks. If NULL, only the **quadrant_fn** callback is executed. If that is NULL, the whole function noops. If not NULL, the **point_fn** is called on its members during the search. + + - `p4est`:\\[in\\] The forest to be searched. + - `call_post`:\\[in\\] If true, call quadrant callback both pre and post. + - `quadrant_fn`:\\[in\\] Executed once for each quadrant that is entered. If the callback returns false, this quadrant and its descendants are excluded from the search, and the points in this branch are not queried further. Its **point** argument is always NULL. Callback may be NULL in which case it is ignored. + - `point_fn`:\\[in\\] Executed once for each point that is relevant for a quadrant of the search. If it returns true, the point is tracked further down that branch, else it is discarded from the queries for the children. If **points** is not NULL, this callback must be not NULL. If **points** is NULL, it is not called. + - `points`:\\[in\\] User-defined array of points. We do not interpret a point, just pass it into the callbacks. If NULL, only the **quadrant_fn** callback is executed. If that is NULL, the whole function noops. If not NULL, the **point_fn** is called on its members during the search. + ### Prototype + ```c void p4est_search_all (p4est_t * p4est, int call_post, p4est_search_all_t quadrant_fn, p4est_search_all_t point_fn, sc_array_t * points); ``` """ function p4est_search_all(p4est_, call_post, quadrant_fn, point_fn, points) - @ccall libp4est.p4est_search_all(p4est_::Ptr{p4est_t}, call_post::Cint, quadrant_fn::p4est_search_all_t, point_fn::p4est_search_all_t, points::Ptr{sc_array_t})::Cvoid + @ccall libp4est.p4est_search_all( + p4est_::Ptr{p4est_t}, + call_post::Cint, + quadrant_fn::p4est_search_all_t, + point_fn::p4est_search_all_t, + points::Ptr{sc_array_t}, + )::Cvoid end # typedef void ( * p4est_geometry_X_t ) ( p4est_geometry_t * geom , p4est_topidx_t which_tree , const double abc [ 3 ] , double xyz [ 3 ] ) -"""Forward transformation from the reference unit square to physical space. Note that the two-dimensional connectivities have 3D vertex coordinates that can be used in the transformation if so desired. The physical space "xyz" is user-defined, currently used for VTK output.""" +""" +Forward transformation from the reference unit square to physical space. Note that the two-dimensional connectivities have 3D vertex coordinates that can be used in the transformation if so desired. The physical space "xyz" is user-defined, currently used for VTK output. +""" const p4est_geometry_X_t = Ptr{Cvoid} # typedef void ( * p4est_geometry_destroy_t ) ( p4est_geometry_t * geom ) -"""Destructor prototype for a user-allocated [`p4est_geometry_t`](@ref). It is invoked by [`p4est_geometry_destroy`](@ref). If the user chooses to reserve the structure statically, simply don't call [`p4est_geometry_destroy`](@ref).""" +""" +Destructor prototype for a user-allocated [`p4est_geometry_t`](@ref). It is invoked by [`p4est_geometry_destroy`](@ref). If the user chooses to reserve the structure statically, simply don't call [`p4est_geometry_destroy`](@ref). +""" const p4est_geometry_destroy_t = Ptr{Cvoid} """ @@ -6649,12 +8549,12 @@ const p4est_geometry_destroy_t = Ptr{Cvoid} This structure can be filled or allocated by the user. `p4est` will never change its contents. -| Field | Note | -| :------ | :----------------------------------------------------------------------------------------------- | -| name | User's choice is arbitrary. | -| user | | -| X | Coordinate transformation. | -| destroy | Destructor called by [`p4est_geometry_destroy`](@ref). If NULL, [`P4EST_FREE`](@ref) is called. | +| Field | Note | +|:------- |:----------------------------------------------------------------------------------------------- | +| name | User's choice is arbitrary. | +| user | | +| X | Coordinate transformation. | +| destroy | Destructor called by [`p4est_geometry_destroy`](@ref). If NULL, [`P4EST_FREE`](@ref) is called. | """ struct p4est_geometry name::Cstring @@ -6663,7 +8563,9 @@ struct p4est_geometry destroy::p4est_geometry_destroy_t end -"""This object encapsulates a custom geometry transformation.""" +""" +This object encapsulates a custom geometry transformation. +""" const p4est_geometry_t = p4est_geometry """ @@ -6672,6 +8574,7 @@ const p4est_geometry_t = p4est_geometry Can be used to conveniently destroy a geometry structure. The user is free not to call this function at all if they handle the memory of the [`p4est_geometry_t`](@ref) in their own way. ### Prototype + ```c void p4est_geometry_destroy (p4est_geometry_t * geom); ``` @@ -6686,16 +8589,23 @@ end Create a geometry structure based on the vertices in a connectivity. The transformation is constructed using bilinear interpolation. ### Parameters -* `conn`:\\[in\\] A [`p4est_connectivity_t`](@ref) with valid vertices. We do NOT take ownership and expect this structure to stay alive. + + - `conn`:\\[in\\] A [`p4est_connectivity_t`](@ref) with valid vertices. We do NOT take ownership and expect this structure to stay alive. + ### Returns + Geometry structure; use with [`p4est_geometry_destroy`](@ref). + ### Prototype + ```c p4est_geometry_t *p4est_geometry_new_connectivity (p4est_connectivity_t * conn); ``` """ function p4est_geometry_new_connectivity(conn) - @ccall libp4est.p4est_geometry_new_connectivity(conn::Ptr{p4est_connectivity_t})::Ptr{p4est_geometry_t} + @ccall libp4est.p4est_geometry_new_connectivity( + conn::Ptr{p4est_connectivity_t}, + )::Ptr{p4est_geometry_t} end """ @@ -6704,12 +8614,16 @@ end Create a geometry for mapping the 3d sphere using 2d connectivity icosahedron. ### Prototype + ```c p4est_geometry_t *p4est_geometry_new_icosahedron (p4est_connectivity_t * conn, double R); ``` """ function p4est_geometry_new_icosahedron(conn, R) - @ccall libp4est.p4est_geometry_new_icosahedron(conn::Ptr{p4est_connectivity_t}, R::Cdouble)::Ptr{p4est_geometry_t} + @ccall libp4est.p4est_geometry_new_icosahedron( + conn::Ptr{p4est_connectivity_t}, + R::Cdouble, + )::Ptr{p4est_geometry_t} end """ @@ -6718,12 +8632,17 @@ end Create a geometry for mapping 2d shell. This a direct adaptation of geometric shell in 3d. ### Prototype + ```c p4est_geometry_t *p4est_geometry_new_shell2d (p4est_connectivity_t * conn, double R2, double R1); ``` """ function p4est_geometry_new_shell2d(conn, R2, R1) - @ccall libp4est.p4est_geometry_new_shell2d(conn::Ptr{p4est_connectivity_t}, R2::Cdouble, R1::Cdouble)::Ptr{p4est_geometry_t} + @ccall libp4est.p4est_geometry_new_shell2d( + conn::Ptr{p4est_connectivity_t}, + R2::Cdouble, + R1::Cdouble, + )::Ptr{p4est_geometry_t} end """ @@ -6734,20 +8653,29 @@ disk2d geometry associated to disk2d connectivity. This geometry is meant to be used with the disk2d connectivity, p4est_connectivity_new_disk2d which is a 5-tree connectivty to map the disk. ### Parameters -* `R0`:\\[in\\] radius of the inner circle -* `R1`:\\[in\\] radius of the outer circle (external border) + + - `R0`:\\[in\\] radius of the inner circle + - `R1`:\\[in\\] radius of the outer circle (external border) + ### Prototype + ```c p4est_geometry_t *p4est_geometry_new_disk2d (p4est_connectivity_t * conn, double R0, double R1); ``` """ function p4est_geometry_new_disk2d(conn, R0, R1) - @ccall libp4est.p4est_geometry_new_disk2d(conn::Ptr{p4est_connectivity_t}, R0::Cdouble, R1::Cdouble)::Ptr{p4est_geometry_t} + @ccall libp4est.p4est_geometry_new_disk2d( + conn::Ptr{p4est_connectivity_t}, + R0::Cdouble, + R1::Cdouble, + )::Ptr{p4est_geometry_t} end mutable struct p4est_vtk_context end -"""Opaque context type for writing VTK output with multiple function calls.""" +""" +Opaque context type for writing VTK output with multiple function calls. +""" const p4est_vtk_context_t = p4est_vtk_context """ @@ -6758,16 +8686,23 @@ Write the `p4est` in VTK format. This is a convenience function for the special case of writing out the tree id, quadrant level, and MPI rank of each quadrant as cell data. One file is written per MPI rank, and one meta file on rank 0. The quadrants are scaled to length .95; see p4est_vtk_write_header. This function will abort if there is a file error. ### Parameters -* `p4est`:\\[in\\] The `p4est` to be written. -* `geom`:\\[in\\] A [`p4est_geometry_t`](@ref) structure or NULL for vertex space as defined by `p4est`->connectivity. -* `filename`:\\[in\\] The first part of the file name which will have the MPI rank appended to it: The output file will be filename\\_rank.vtu, and the meta file filename.pvtu. + + - `p4est`:\\[in\\] The `p4est` to be written. + - `geom`:\\[in\\] A [`p4est_geometry_t`](@ref) structure or NULL for vertex space as defined by `p4est`->connectivity. + - `filename`:\\[in\\] The first part of the file name which will have the MPI rank appended to it: The output file will be filename\\_rank.vtu, and the meta file filename.pvtu. + ### Prototype + ```c void p4est_vtk_write_file (p4est_t * p4est, p4est_geometry_t * geom, const char *filename); ``` """ function p4est_vtk_write_file(p4est_, geom, filename) - @ccall libp4est.p4est_vtk_write_file(p4est_::Ptr{p4est_t}, geom::Ptr{p4est_geometry_t}, filename::Cstring)::Cvoid + @ccall libp4est.p4est_vtk_write_file( + p4est_::Ptr{p4est_t}, + geom::Ptr{p4est_geometry_t}, + filename::Cstring, + )::Cvoid end """ @@ -6778,17 +8713,25 @@ The first call to write a VTK file using individual functions. Writing a VTK file is split into multiple functions that keep a context. This is the first function that allocates the opaque context structure. After allocation, further parameters can be set for the context. Then, the header, possible data fields, and the footer must be written. The process can be aborted any time by destroying the context. In this case, open files are closed cleanly with only partially written content. ### Parameters -* `p4est`: The `p4est` to be written. If no geometry is specified in p4est_vtk_context_set_geom, we require `p4est`->connectivity to have valid vertex arrays. -* `filename`: The first part of the name which will have the processor number appended to it (i.e., the output file will be filename\\_rank.vtu). The parallel meta-files for Paraview and Visit use this basename, too. We copy this filename to internal storage, so it is not needed to remain alive after calling this function. + + - `p4est`: The `p4est` to be written. If no geometry is specified in p4est_vtk_context_set_geom, we require `p4est`->connectivity to have valid vertex arrays. + - `filename`: The first part of the name which will have the processor number appended to it (i.e., the output file will be filename\\_rank.vtu). The parallel meta-files for Paraview and Visit use this basename, too. We copy this filename to internal storage, so it is not needed to remain alive after calling this function. + ### Returns + A VTK context for further use. + ### Prototype + ```c p4est_vtk_context_t *p4est_vtk_context_new (p4est_t * p4est, const char *filename); ``` """ function p4est_vtk_context_new(p4est_, filename) - @ccall libp4est.p4est_vtk_context_new(p4est_::Ptr{p4est_t}, filename::Cstring)::Ptr{p4est_vtk_context_t} + @ccall libp4est.p4est_vtk_context_new( + p4est_::Ptr{p4est_t}, + filename::Cstring, + )::Ptr{p4est_vtk_context_t} end """ @@ -6797,15 +8740,21 @@ end Modify the geometry transformation registered in the context. After p4est_vtk_context_new, it is at the default NULL. ### Parameters -* `cont`:\\[in,out\\] The context is modified. It must not yet have been used to start writing in p4est_vtk_write_header. -* `geom`: A p4est_geometry_t structure, or NULL for vertex space. If NULL, `p4est`->connectivity->vertices and **tree_to_vertex** must be non-NULL. + + - `cont`:\\[in,out\\] The context is modified. It must not yet have been used to start writing in p4est_vtk_write_header. + - `geom`: A p4est_geometry_t structure, or NULL for vertex space. If NULL, `p4est`->connectivity->vertices and **tree_to_vertex** must be non-NULL. + ### Prototype + ```c void p4est_vtk_context_set_geom (p4est_vtk_context_t * cont, p4est_geometry_t * geom); ``` """ function p4est_vtk_context_set_geom(cont, geom) - @ccall libp4est.p4est_vtk_context_set_geom(cont::Ptr{p4est_vtk_context_t}, geom::Ptr{p4est_geometry_t})::Cvoid + @ccall libp4est.p4est_vtk_context_set_geom( + cont::Ptr{p4est_vtk_context_t}, + geom::Ptr{p4est_geometry_t}, + )::Cvoid end """ @@ -6814,15 +8763,21 @@ end Modify the context parameter for scaling the quadrants. A scale < 1 places a visual gap between adjacent quadrants. After p4est_vtk_context_new, it is at the default 0.95. ### Parameters -* `cont`:\\[in,out\\] The context is modified. It must not yet have been used to start writing in p4est_vtk_write_header. -* `scale`:\\[in\\] Scale parameter must be in (0, 1]. + + - `cont`:\\[in,out\\] The context is modified. It must not yet have been used to start writing in p4est_vtk_write_header. + - `scale`:\\[in\\] Scale parameter must be in (0, 1]. + ### Prototype + ```c void p4est_vtk_context_set_scale (p4est_vtk_context_t * cont, double scale); ``` """ function p4est_vtk_context_set_scale(cont, scale) - @ccall libp4est.p4est_vtk_context_set_scale(cont::Ptr{p4est_vtk_context_t}, scale::Cdouble)::Cvoid + @ccall libp4est.p4est_vtk_context_set_scale( + cont::Ptr{p4est_vtk_context_t}, + scale::Cdouble, + )::Cvoid end """ @@ -6831,15 +8786,21 @@ end Modify the context parameter for expecting continuous point data. If set to true, the point data is understood as a continuous field. In this case, we can significantly reduce the file size when scale == 1. For discontinuous point data, it should be set to false. After p4est_vtk_context_new, it is at the default false. ### Parameters -* `cont`:\\[in,out\\] The context is modified. It must not yet have been used to start writing in p4est_vtk_write_header. -* `continuous`:\\[in\\] Boolean parameter. + + - `cont`:\\[in,out\\] The context is modified. It must not yet have been used to start writing in p4est_vtk_write_header. + - `continuous`:\\[in\\] Boolean parameter. + ### Prototype + ```c void p4est_vtk_context_set_continuous (p4est_vtk_context_t * cont, int continuous); ``` """ function p4est_vtk_context_set_continuous(cont, continuous) - @ccall libp4est.p4est_vtk_context_set_continuous(cont::Ptr{p4est_vtk_context_t}, continuous::Cint)::Cvoid + @ccall libp4est.p4est_vtk_context_set_continuous( + cont::Ptr{p4est_vtk_context_t}, + continuous::Cint, + )::Cvoid end """ @@ -6850,8 +8811,11 @@ Cleanly destroy a p4est_vtk_context_t structure. This function closes all the file pointers and frees the context. It can be called even if the VTK output has only been partially written, the files' content will be incomplete. ### Parameters -* `context`:\\[in\\] The VTK file context to be destroyed. + + - `context`:\\[in\\] The VTK file context to be destroyed. + ### Prototype + ```c void p4est_vtk_context_destroy (p4est_vtk_context_t * context); ``` @@ -6874,16 +8838,23 @@ Each of these functions opens and closes files as necessary. Generally, each out This function writes point positions for the quadrants' vertices and the maps of elements to types and vertices as required by VTK. ### Parameters -* `cont`:\\[in,out\\] A VTK context created by p4est_vtk_context_new. None of the vtk\\_write functions must have been called. This context is the return value if no error occurs. + + - `cont`:\\[in,out\\] A VTK context created by p4est_vtk_context_new. None of the vtk\\_write functions must have been called. This context is the return value if no error occurs. + ### Returns + On success, an opaque context ([`p4est_vtk_context_t`](@ref)) pointer that must be passed to subsequent p4est\\_vtk calls. It is required to call p4est_vtk_write_footer eventually with this value. Returns NULL on error. + ### Prototype + ```c p4est_vtk_context_t *p4est_vtk_write_header (p4est_vtk_context_t * cont); ``` """ function p4est_vtk_write_header(cont) - @ccall libp4est.p4est_vtk_write_header(cont::Ptr{p4est_vtk_context_t})::Ptr{p4est_vtk_context_t} + @ccall libp4est.p4est_vtk_write_header( + cont::Ptr{p4est_vtk_context_t}, + )::Ptr{p4est_vtk_context_t} end """ @@ -6898,35 +8869,92 @@ Writing a VTK file is split into a few routines. This allows there to be an arbi The number of doubles in each [`sc_array`](@ref) must be exactly `p4est`->local_num_quadrants for scalar data and *3**p4est->local_num_quadrants for vector data. The cell scalar data come first, followed by the cell vector data. ### Parameters -* `cont`:\\[in,out\\] A VTK context created by p4est_vtk_context_new. -* `write_tree`:\\[in\\] Boolean to determine if the tree id should be output. -* `write_level`:\\[in\\] Boolean to determine if the tree levels should be output. -* `write_rank`:\\[in\\] Boolean to determine if the MPI rank should be output. -* `wrap_rank`:\\[in\\] Number to wrap around the rank with a modulo operation. Can be 0 for no wrapping. -* `num_cell_scalars`:\\[in\\] Number of cell scalar datasets to output. -* `num_cell_vectors`:\\[in\\] Number of cell vector datasets to output. -* `fieldnames`:\\[in\\] Array of char strings containing the name of each data field. -* `values`:\\[in\\] Array of pointers to [`sc_array_t`](@ref) holding variables of type double, one value (scalar data) or three values (vector data) for each local quadrant. + + - `cont`:\\[in,out\\] A VTK context created by p4est_vtk_context_new. + - `write_tree`:\\[in\\] Boolean to determine if the tree id should be output. + - `write_level`:\\[in\\] Boolean to determine if the tree levels should be output. + - `write_rank`:\\[in\\] Boolean to determine if the MPI rank should be output. + - `wrap_rank`:\\[in\\] Number to wrap around the rank with a modulo operation. Can be 0 for no wrapping. + - `num_cell_scalars`:\\[in\\] Number of cell scalar datasets to output. + - `num_cell_vectors`:\\[in\\] Number of cell vector datasets to output. + - `fieldnames`:\\[in\\] Array of char strings containing the name of each data field. + - `values`:\\[in\\] Array of pointers to [`sc_array_t`](@ref) holding variables of type double, one value (scalar data) or three values (vector data) for each local quadrant. + ### Returns + On success, the context that has been passed in. On failure, returns NULL and deallocates the context. + ### Prototype + ```c p4est_vtk_context_t *p4est_vtk_write_cell_data (p4est_vtk_context_t * cont, int write_tree, int write_level, int write_rank, int wrap_rank, int num_cell_scalars, int num_cell_vectors, const char *fieldnames[], sc_array_t * values[]); ``` """ -function p4est_vtk_write_cell_data(cont, write_tree, write_level, write_rank, wrap_rank, num_cell_scalars, num_cell_vectors, fieldnames, values) - @ccall libp4est.p4est_vtk_write_cell_data(cont::Ptr{p4est_vtk_context_t}, write_tree::Cint, write_level::Cint, write_rank::Cint, wrap_rank::Cint, num_cell_scalars::Cint, num_cell_vectors::Cint, fieldnames::Ptr{Cstring}, values::Ptr{Ptr{sc_array_t}})::Ptr{p4est_vtk_context_t} +function p4est_vtk_write_cell_data( + cont, + write_tree, + write_level, + write_rank, + wrap_rank, + num_cell_scalars, + num_cell_vectors, + fieldnames, + values, +) + @ccall libp4est.p4est_vtk_write_cell_data( + cont::Ptr{p4est_vtk_context_t}, + write_tree::Cint, + write_level::Cint, + write_rank::Cint, + wrap_rank::Cint, + num_cell_scalars::Cint, + num_cell_vectors::Cint, + fieldnames::Ptr{Cstring}, + values::Ptr{Ptr{sc_array_t}}, + )::Ptr{p4est_vtk_context_t} end # automatic type deduction for variadic arguments may not be what you want, please use with caution -@generated function p4est_vtk_write_cell_dataf(cont, write_tree, write_level, write_rank, wrap_rank, num_cell_scalars, num_cell_vectors, va_list...) - :(@ccall(libp4est.p4est_vtk_write_cell_dataf(cont::Ptr{p4est_vtk_context_t}, write_tree::Cint, write_level::Cint, write_rank::Cint, wrap_rank::Cint, num_cell_scalars::Cint, num_cell_vectors::Cint; $(to_c_type_pairs(va_list)...))::Ptr{p4est_vtk_context_t})) - end +@generated function p4est_vtk_write_cell_dataf( + cont, + write_tree, + write_level, + write_rank, + wrap_rank, + num_cell_scalars, + num_cell_vectors, + va_list..., +) + :(@ccall( + libp4est.p4est_vtk_write_cell_dataf( + cont::Ptr{p4est_vtk_context_t}, + write_tree::Cint, + write_level::Cint, + write_rank::Cint, + wrap_rank::Cint, + num_cell_scalars::Cint, + num_cell_vectors::Cint; + $(to_c_type_pairs(va_list)...), + )::Ptr{p4est_vtk_context_t} + )) +end # automatic type deduction for variadic arguments may not be what you want, please use with caution -@generated function p4est_vtk_write_point_dataf(cont, num_point_scalars, num_point_vectors, va_list...) - :(@ccall(libp4est.p4est_vtk_write_point_dataf(cont::Ptr{p4est_vtk_context_t}, num_point_scalars::Cint, num_point_vectors::Cint; $(to_c_type_pairs(va_list)...))::Ptr{p4est_vtk_context_t})) - end +@generated function p4est_vtk_write_point_dataf( + cont, + num_point_scalars, + num_point_vectors, + va_list..., +) + :(@ccall( + libp4est.p4est_vtk_write_point_dataf( + cont::Ptr{p4est_vtk_context_t}, + num_point_scalars::Cint, + num_point_vectors::Cint; + $(to_c_type_pairs(va_list)...), + )::Ptr{p4est_vtk_context_t} + )) +end """ p4est_vtk_write_footer(cont) @@ -6936,10 +8964,15 @@ Write the VTU footer and clean up. Writing a VTK file is split into a few routines. This function writes the footer information to the VTK file and cleanly destroys the VTK context. ### Parameters -* `cont`:\\[in\\] Context is deallocated before the function returns. + + - `cont`:\\[in\\] Context is deallocated before the function returns. + ### Returns + This returns 0 if no error and -1 if there is an error. + ### Prototype + ```c int p4est_vtk_write_footer (p4est_vtk_context_t * cont); ``` @@ -6949,7 +8982,7 @@ function p4est_vtk_write_footer(cont) end struct p6est_quadrant_data - data::NTuple{8, UInt8} + data::NTuple{8,UInt8} end function Base.getproperty(x::Ptr{p6est_quadrant_data}, f::Symbol) @@ -6979,16 +9012,16 @@ end A 1D quadrant datatype: this is used to encode a "layer" of a column in the 2D+1D AMR scheme. -| Field | Note | -| :---- | :---------------------------------------------- | -| z | vertical coordinate | -| level | level of refinement | -| pad8 | padding | -| pad16 | | -| p | a union of additional data attached to a layer | +| Field | Note | +|:----- |:---------------------------------------------- | +| z | vertical coordinate | +| level | level of refinement | +| pad8 | padding | +| pad16 | | +| p | a union of additional data attached to a layer | """ struct p2est_quadrant - data::NTuple{16, UInt8} + data::NTuple{16,UInt8} end function Base.getproperty(x::Ptr{p2est_quadrant}, f::Symbol) @@ -7011,7 +9044,9 @@ function Base.setproperty!(x::Ptr{p2est_quadrant}, f::Symbol, v) unsafe_store!(getproperty(x, f), v) end -"""A 1D quadrant datatype: this is used to encode a "layer" of a column in the 2D+1D AMR scheme.""" +""" +A 1D quadrant datatype: this is used to encode a "layer" of a column in the 2D+1D AMR scheme. +""" const p2est_quadrant_t = p2est_quadrant """ @@ -7033,9 +9068,9 @@ end Typedef for serialization method. -| Enumerator | Note | -| :--------------------------- | :-------------------------------- | -| P8EST\\_CONN\\_ENCODE\\_LAST | Invalid entry to close the list. | +| Enumerator | Note | +|:---------------------------- |:-------------------------------- | +| P8EST\\_CONN\\_ENCODE\\_LAST | Invalid entry to close the list. | """ @cenum p8est_connectivity_encode_t::UInt32 begin P8EST_CONN_ENCODE_NONE = 0 @@ -7048,10 +9083,15 @@ end Convert the [`p8est_connect_type_t`](@ref) into a number. ### Parameters -* `btype`:\\[in\\] The balance type to convert. + + - `btype`:\\[in\\] The balance type to convert. + ### Returns + Returns 1, 2 or 3. + ### Prototype + ```c int p8est_connect_type_int (p8est_connect_type_t btype); ``` @@ -7066,10 +9106,15 @@ end Convert the [`p8est_connect_type_t`](@ref) into a const string. ### Parameters -* `btype`:\\[in\\] The balance type to convert. + + - `btype`:\\[in\\] The balance type to convert. + ### Returns + Returns a pointer to a constant string. + ### Prototype + ```c const char *p8est_connect_type_string (p8est_connect_type_t btype); ``` @@ -7099,26 +9144,26 @@ The arrays corner\\_to\\_* store a variable number of entries per corner. For co The *\\_to\\_attr arrays may have arbitrary contents defined by the user. -| Field | Note | -| :------------------- | :----------------------------------------------------------------------------------- | -| num\\_vertices | the number of vertices that define the *embedding* of the forest (not the topology) | -| num\\_trees | the number of trees | -| num\\_edges | the number of edges that help define the topology | -| num\\_corners | the number of corners that help define the topology | -| vertices | an array of size (3 * *num_vertices*) | -| tree\\_to\\_vertex | embed each tree into ```c++ R^3 ``` for e.g. visualization (see p8est\\_vtk.h) | -| tree\\_attr\\_bytes | bytes per tree in tree\\_to\\_attr | -| tree\\_to\\_attr | not touched by `p4est` | -| tree\\_to\\_tree | (6 * *num_trees*) neighbors across faces | -| tree\\_to\\_face | (6 * *num_trees*) face to face+orientation (see description) | -| tree\\_to\\_edge | (12 * *num_trees*) or NULL (see description) | -| ett\\_offset | edge to offset in *edge_to_tree* and *edge_to_edge* | -| edge\\_to\\_tree | list of trees that meet at an edge | -| edge\\_to\\_edge | list of tree-edges+orientations that meet at an edge (see description) | -| tree\\_to\\_corner | (8 * *num_trees*) or NULL (see description) | -| ctt\\_offset | corner to offset in *corner_to_tree* and *corner_to_corner* | -| corner\\_to\\_tree | list of trees that meet at a corner | -| corner\\_to\\_corner | list of tree-corners that meet at a corner | +| Field | Note | +|:-------------------- |:----------------------------------------------------------------------------------- | +| num\\_vertices | the number of vertices that define the *embedding* of the forest (not the topology) | +| num\\_trees | the number of trees | +| num\\_edges | the number of edges that help define the topology | +| num\\_corners | the number of corners that help define the topology | +| vertices | an array of size (3 * *num_vertices*) | +| tree\\_to\\_vertex | embed each tree into `c++ R^3 ` for e.g. visualization (see p8est\\_vtk.h) | +| tree\\_attr\\_bytes | bytes per tree in tree\\_to\\_attr | +| tree\\_to\\_attr | not touched by `p4est` | +| tree\\_to\\_tree | (6 * *num_trees*) neighbors across faces | +| tree\\_to\\_face | (6 * *num_trees*) face to face+orientation (see description) | +| tree\\_to\\_edge | (12 * *num_trees*) or NULL (see description) | +| ett\\_offset | edge to offset in *edge_to_tree* and *edge_to_edge* | +| edge\\_to\\_tree | list of trees that meet at an edge | +| edge\\_to\\_edge | list of tree-edges+orientations that meet at an edge (see description) | +| tree\\_to\\_corner | (8 * *num_trees*) or NULL (see description) | +| ctt\\_offset | corner to offset in *corner_to_tree* and *corner_to_corner* | +| corner\\_to\\_tree | list of trees that meet at a corner | +| corner\\_to\\_corner | list of tree-corners that meet at a corner | """ struct p8est_connectivity num_vertices::p4est_topidx_t @@ -7168,10 +9213,15 @@ const p8est_connectivity_t = p8est_connectivity Calculate memory usage of a connectivity structure. ### Parameters -* `conn`:\\[in\\] Connectivity structure. + + - `conn`:\\[in\\] Connectivity structure. + ### Returns + Memory used in bytes. + ### Prototype + ```c size_t p8est_connectivity_memory_used (p8est_connectivity_t * conn); ``` @@ -7183,7 +9233,7 @@ end struct p8est_edge_transform_t ntree::p4est_topidx_t nedge::Int8 - naxis::NTuple{3, Int8} + naxis::NTuple{3,Int8} nflip::Int8 corners::Int8 end @@ -7209,19 +9259,29 @@ end Transform a corner across one of the adjacent faces into a neighbor tree. It expects a face permutation index that has been precomputed. ### Parameters -* `c`:\\[in\\] A corner number in 0..7. -* `f`:\\[in\\] A face number that touches the corner *c*. -* `nf`:\\[in\\] A neighbor face that is on the other side of . -* `set`:\\[in\\] A value from *p8est_face_permutation_sets* that is obtained using *f*, *nf*, and a valid orientation: ref = p8est\\_face\\_permutation\\_refs[f][nf]; set = p8est\\_face\\_permutation\\_sets[ref][orientation]; + + - `c`:\\[in\\] A corner number in 0..7. + - `f`:\\[in\\] A face number that touches the corner *c*. + - `nf`:\\[in\\] A neighbor face that is on the other side of . + - `set`:\\[in\\] A value from *p8est_face_permutation_sets* that is obtained using *f*, *nf*, and a valid orientation: ref = p8est\\_face\\_permutation\\_refs[f][nf]; set = p8est\\_face\\_permutation\\_sets[ref][orientation]; + ### Returns + The corner number in 0..7 seen from the other face. + ### Prototype + ```c int p8est_connectivity_face_neighbor_corner_set (int c, int f, int nf, int set); ``` """ function p8est_connectivity_face_neighbor_corner_set(c, f, nf, set) - @ccall libp4est.p8est_connectivity_face_neighbor_corner_set(c::Cint, f::Cint, nf::Cint, set::Cint)::Cint + @ccall libp4est.p8est_connectivity_face_neighbor_corner_set( + c::Cint, + f::Cint, + nf::Cint, + set::Cint, + )::Cint end """ @@ -7230,19 +9290,29 @@ end Transform a face corner across one of the adjacent faces into a neighbor tree. This version expects the neighbor face and orientation separately. ### Parameters -* `fc`:\\[in\\] A face corner number in 0..3. -* `f`:\\[in\\] A face that the face corner *fc* is relative to. -* `nf`:\\[in\\] A neighbor face that is on the other side of . -* `o`:\\[in\\] The orientation between tree boundary faces *f* and . + + - `fc`:\\[in\\] A face corner number in 0..3. + - `f`:\\[in\\] A face that the face corner *fc* is relative to. + - `nf`:\\[in\\] A neighbor face that is on the other side of . + - `o`:\\[in\\] The orientation between tree boundary faces *f* and . + ### Returns + The face corner number relative to the neighbor's face. + ### Prototype + ```c int p8est_connectivity_face_neighbor_face_corner (int fc, int f, int nf, int o); ``` """ function p8est_connectivity_face_neighbor_face_corner(fc, f, nf, o) - @ccall libp4est.p8est_connectivity_face_neighbor_face_corner(fc::Cint, f::Cint, nf::Cint, o::Cint)::Cint + @ccall libp4est.p8est_connectivity_face_neighbor_face_corner( + fc::Cint, + f::Cint, + nf::Cint, + o::Cint, + )::Cint end """ @@ -7251,19 +9321,29 @@ end Transform a corner across one of the adjacent faces into a neighbor tree. This version expects the neighbor face and orientation separately. ### Parameters -* `c`:\\[in\\] A corner number in 0..7. -* `f`:\\[in\\] A face number that touches the corner *c*. -* `nf`:\\[in\\] A neighbor face that is on the other side of . -* `o`:\\[in\\] The orientation between tree boundary faces *f* and . + + - `c`:\\[in\\] A corner number in 0..7. + - `f`:\\[in\\] A face number that touches the corner *c*. + - `nf`:\\[in\\] A neighbor face that is on the other side of . + - `o`:\\[in\\] The orientation between tree boundary faces *f* and . + ### Returns + The number of the corner seen from the neighbor tree. + ### Prototype + ```c int p8est_connectivity_face_neighbor_corner (int c, int f, int nf, int o); ``` """ function p8est_connectivity_face_neighbor_corner(c, f, nf, o) - @ccall libp4est.p8est_connectivity_face_neighbor_corner(c::Cint, f::Cint, nf::Cint, o::Cint)::Cint + @ccall libp4est.p8est_connectivity_face_neighbor_corner( + c::Cint, + f::Cint, + nf::Cint, + o::Cint, + )::Cint end """ @@ -7272,19 +9352,29 @@ end Transform a face-edge across one of the adjacent faces into a neighbor tree. This version expects the neighbor face and orientation separately. ### Parameters -* `fe`:\\[in\\] A face edge number in 0..3. -* `f`:\\[in\\] A face number that touches the edge *e*. -* `nf`:\\[in\\] A neighbor face that is on the other side of . -* `o`:\\[in\\] The orientation between tree boundary faces *f* and . + + - `fe`:\\[in\\] A face edge number in 0..3. + - `f`:\\[in\\] A face number that touches the edge *e*. + - `nf`:\\[in\\] A neighbor face that is on the other side of . + - `o`:\\[in\\] The orientation between tree boundary faces *f* and . + ### Returns + The face edge number seen from the neighbor tree. + ### Prototype + ```c int p8est_connectivity_face_neighbor_face_edge (int fe, int f, int nf, int o); ``` """ function p8est_connectivity_face_neighbor_face_edge(fe, f, nf, o) - @ccall libp4est.p8est_connectivity_face_neighbor_face_edge(fe::Cint, f::Cint, nf::Cint, o::Cint)::Cint + @ccall libp4est.p8est_connectivity_face_neighbor_face_edge( + fe::Cint, + f::Cint, + nf::Cint, + o::Cint, + )::Cint end """ @@ -7293,19 +9383,29 @@ end Transform an edge across one of the adjacent faces into a neighbor tree. This version expects the neighbor face and orientation separately. ### Parameters -* `e`:\\[in\\] A edge number in 0..11. -* `f`:\\[in\\] A face 0..5 that touches the edge *e*. -* `nf`:\\[in\\] A neighbor face that is on the other side of . -* `o`:\\[in\\] The orientation between tree boundary faces *f* and . + + - `e`:\\[in\\] A edge number in 0..11. + - `f`:\\[in\\] A face 0..5 that touches the edge *e*. + - `nf`:\\[in\\] A neighbor face that is on the other side of . + - `o`:\\[in\\] The orientation between tree boundary faces *f* and . + ### Returns + The edge's number seen from the neighbor. + ### Prototype + ```c int p8est_connectivity_face_neighbor_edge (int e, int f, int nf, int o); ``` """ function p8est_connectivity_face_neighbor_edge(e, f, nf, o) - @ccall libp4est.p8est_connectivity_face_neighbor_edge(e::Cint, f::Cint, nf::Cint, o::Cint)::Cint + @ccall libp4est.p8est_connectivity_face_neighbor_edge( + e::Cint, + f::Cint, + nf::Cint, + o::Cint, + )::Cint end """ @@ -7314,11 +9414,16 @@ end Transform an edge corner across one of the adjacent edges into a neighbor tree. ### Parameters -* `ec`:\\[in\\] An edge corner number in 0..1. -* `o`:\\[in\\] The orientation of a tree boundary edge connection. + + - `ec`:\\[in\\] An edge corner number in 0..1. + - `o`:\\[in\\] The orientation of a tree boundary edge connection. + ### Returns + The edge corner number seen from the other tree. + ### Prototype + ```c int p8est_connectivity_edge_neighbor_edge_corner (int ec, int o); ``` @@ -7333,19 +9438,29 @@ end Transform a corner across one of the adjacent edges into a neighbor tree. This version expects the neighbor edge and orientation separately. ### Parameters -* `c`:\\[in\\] A corner number in 0..7. -* `e`:\\[in\\] An edge 0..11 that touches the corner *c*. -* `ne`:\\[in\\] A neighbor edge that is on the other side of *.* -* `o`:\\[in\\] The orientation between tree boundary edges *e* and . + + - `c`:\\[in\\] A corner number in 0..7. + - `e`:\\[in\\] An edge 0..11 that touches the corner *c*. + - `ne`:\\[in\\] A neighbor edge that is on the other side of *.* + - `o`:\\[in\\] The orientation between tree boundary edges *e* and . + ### Returns + Corner number seen from the neighbor. + ### Prototype + ```c int p8est_connectivity_edge_neighbor_corner (int c, int e, int ne, int o); ``` """ function p8est_connectivity_edge_neighbor_corner(c, e, ne, o) - @ccall libp4est.p8est_connectivity_edge_neighbor_corner(c::Cint, e::Cint, ne::Cint, o::Cint)::Cint + @ccall libp4est.p8est_connectivity_edge_neighbor_corner( + c::Cint, + e::Cint, + ne::Cint, + o::Cint, + )::Cint end """ @@ -7354,21 +9469,40 @@ end Allocate a connectivity structure. The attribute fields are initialized to NULL. ### Parameters -* `num_vertices`:\\[in\\] Number of total vertices (i.e. geometric points). -* `num_trees`:\\[in\\] Number of trees in the forest. -* `num_edges`:\\[in\\] Number of tree-connecting edges. -* `num_ett`:\\[in\\] Number of total trees in edge\\_to\\_tree array. -* `num_corners`:\\[in\\] Number of tree-connecting corners. -* `num_ctt`:\\[in\\] Number of total trees in corner\\_to\\_tree array. + + - `num_vertices`:\\[in\\] Number of total vertices (i.e. geometric points). + - `num_trees`:\\[in\\] Number of trees in the forest. + - `num_edges`:\\[in\\] Number of tree-connecting edges. + - `num_ett`:\\[in\\] Number of total trees in edge\\_to\\_tree array. + - `num_corners`:\\[in\\] Number of tree-connecting corners. + - `num_ctt`:\\[in\\] Number of total trees in corner\\_to\\_tree array. + ### Returns + A connectivity structure with allocated arrays. + ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_new (p4est_topidx_t num_vertices, p4est_topidx_t num_trees, p4est_topidx_t num_edges, p4est_topidx_t num_ett, p4est_topidx_t num_corners, p4est_topidx_t num_ctt); ``` """ -function p8est_connectivity_new(num_vertices, num_trees, num_edges, num_ett, num_corners, num_ctt) - @ccall libp4est.p8est_connectivity_new(num_vertices::p4est_topidx_t, num_trees::p4est_topidx_t, num_edges::p4est_topidx_t, num_ett::p4est_topidx_t, num_corners::p4est_topidx_t, num_ctt::p4est_topidx_t)::Ptr{p8est_connectivity_t} +function p8est_connectivity_new( + num_vertices, + num_trees, + num_edges, + num_ett, + num_corners, + num_ctt, +) + @ccall libp4est.p8est_connectivity_new( + num_vertices::p4est_topidx_t, + num_trees::p4est_topidx_t, + num_edges::p4est_topidx_t, + num_ett::p4est_topidx_t, + num_corners::p4est_topidx_t, + num_ctt::p4est_topidx_t, + )::Ptr{p8est_connectivity_t} end """ @@ -7377,33 +9511,77 @@ end Allocate a connectivity structure and populate from constants. The attribute fields are initialized to NULL. ### Parameters -* `num_vertices`:\\[in\\] Number of total vertices (i.e. geometric points). -* `num_trees`:\\[in\\] Number of trees in the forest. -* `num_edges`:\\[in\\] Number of tree-connecting edges. -* `num_corners`:\\[in\\] Number of tree-connecting corners. -* `eoff`:\\[in\\] Edge-to-tree offsets (num\\_edges + 1 values). This must always be non-NULL; in trivial cases it is just a pointer to a p4est\\_topix value of 0. -* `coff`:\\[in\\] Corner-to-tree offsets (num\\_corners + 1 values). This must always be non-NULL; in trivial cases it is just a pointer to a p4est\\_topix value of 0. + + - `num_vertices`:\\[in\\] Number of total vertices (i.e. geometric points). + - `num_trees`:\\[in\\] Number of trees in the forest. + - `num_edges`:\\[in\\] Number of tree-connecting edges. + - `num_corners`:\\[in\\] Number of tree-connecting corners. + - `eoff`:\\[in\\] Edge-to-tree offsets (num\\_edges + 1 values). This must always be non-NULL; in trivial cases it is just a pointer to a p4est\\_topix value of 0. + - `coff`:\\[in\\] Corner-to-tree offsets (num\\_corners + 1 values). This must always be non-NULL; in trivial cases it is just a pointer to a p4est\\_topix value of 0. + ### Returns + The connectivity is checked for validity. + ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_new_copy (p4est_topidx_t num_vertices, p4est_topidx_t num_trees, p4est_topidx_t num_edges, p4est_topidx_t num_corners, const double *vertices, const p4est_topidx_t * ttv, const p4est_topidx_t * ttt, const int8_t * ttf, const p4est_topidx_t * tte, const p4est_topidx_t * eoff, const p4est_topidx_t * ett, const int8_t * ete, const p4est_topidx_t * ttc, const p4est_topidx_t * coff, const p4est_topidx_t * ctt, const int8_t * ctc); ``` """ -function p8est_connectivity_new_copy(num_vertices, num_trees, num_edges, num_corners, vertices, ttv, ttt, ttf, tte, eoff, ett, ete, ttc, coff, ctt, ctc) - @ccall libp4est.p8est_connectivity_new_copy(num_vertices::p4est_topidx_t, num_trees::p4est_topidx_t, num_edges::p4est_topidx_t, num_corners::p4est_topidx_t, vertices::Ptr{Cdouble}, ttv::Ptr{p4est_topidx_t}, ttt::Ptr{p4est_topidx_t}, ttf::Ptr{Int8}, tte::Ptr{p4est_topidx_t}, eoff::Ptr{p4est_topidx_t}, ett::Ptr{p4est_topidx_t}, ete::Ptr{Int8}, ttc::Ptr{p4est_topidx_t}, coff::Ptr{p4est_topidx_t}, ctt::Ptr{p4est_topidx_t}, ctc::Ptr{Int8})::Ptr{p8est_connectivity_t} +function p8est_connectivity_new_copy( + num_vertices, + num_trees, + num_edges, + num_corners, + vertices, + ttv, + ttt, + ttf, + tte, + eoff, + ett, + ete, + ttc, + coff, + ctt, + ctc, +) + @ccall libp4est.p8est_connectivity_new_copy( + num_vertices::p4est_topidx_t, + num_trees::p4est_topidx_t, + num_edges::p4est_topidx_t, + num_corners::p4est_topidx_t, + vertices::Ptr{Cdouble}, + ttv::Ptr{p4est_topidx_t}, + ttt::Ptr{p4est_topidx_t}, + ttf::Ptr{Int8}, + tte::Ptr{p4est_topidx_t}, + eoff::Ptr{p4est_topidx_t}, + ett::Ptr{p4est_topidx_t}, + ete::Ptr{Int8}, + ttc::Ptr{p4est_topidx_t}, + coff::Ptr{p4est_topidx_t}, + ctt::Ptr{p4est_topidx_t}, + ctc::Ptr{Int8}, + )::Ptr{p8est_connectivity_t} end """ p8est_connectivity_bcast(conn_in, root, comm) ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_bcast (p8est_connectivity_t * conn_in, int root, sc_MPI_Comm comm); ``` """ function p8est_connectivity_bcast(conn_in, root, comm) - @ccall libp4est.p8est_connectivity_bcast(conn_in::Ptr{p8est_connectivity_t}, root::Cint, comm::MPI_Comm)::Ptr{p8est_connectivity_t} + @ccall libp4est.p8est_connectivity_bcast( + conn_in::Ptr{p8est_connectivity_t}, + root::Cint, + comm::MPI_Comm, + )::Ptr{p8est_connectivity_t} end """ @@ -7412,12 +9590,15 @@ end Destroy a connectivity structure. Also destroy all attributes. ### Prototype + ```c void p8est_connectivity_destroy (p8est_connectivity_t * connectivity); ``` """ function p8est_connectivity_destroy(connectivity) - @ccall libp4est.p8est_connectivity_destroy(connectivity::Ptr{p8est_connectivity_t})::Cvoid + @ccall libp4est.p8est_connectivity_destroy( + connectivity::Ptr{p8est_connectivity_t}, + )::Cvoid end """ @@ -7426,15 +9607,21 @@ end Allocate or free the attribute fields in a connectivity. ### Parameters -* `conn`:\\[in,out\\] The conn->*\\_to\\_attr fields must either be NULL or previously be allocated by this function. -* `bytes_per_tree`:\\[in\\] If 0, tree\\_to\\_attr is freed (being NULL is ok). If positive, requested space is allocated. + + - `conn`:\\[in,out\\] The conn->*\\_to\\_attr fields must either be NULL or previously be allocated by this function. + - `bytes_per_tree`:\\[in\\] If 0, tree\\_to\\_attr is freed (being NULL is ok). If positive, requested space is allocated. + ### Prototype + ```c void p8est_connectivity_set_attr (p8est_connectivity_t * conn, size_t bytes_per_tree); ``` """ function p8est_connectivity_set_attr(conn, bytes_per_tree) - @ccall libp4est.p8est_connectivity_set_attr(conn::Ptr{p8est_connectivity_t}, bytes_per_tree::Csize_t)::Cvoid + @ccall libp4est.p8est_connectivity_set_attr( + conn::Ptr{p8est_connectivity_t}, + bytes_per_tree::Csize_t, + )::Cvoid end """ @@ -7443,14 +9630,19 @@ end Examine a connectivity structure. ### Returns + Returns true if structure is valid, false otherwise. + ### Prototype + ```c int p8est_connectivity_is_valid (p8est_connectivity_t * connectivity); ``` """ function p8est_connectivity_is_valid(connectivity) - @ccall libp4est.p8est_connectivity_is_valid(connectivity::Ptr{p8est_connectivity_t})::Cint + @ccall libp4est.p8est_connectivity_is_valid( + connectivity::Ptr{p8est_connectivity_t}, + )::Cint end """ @@ -7459,14 +9651,20 @@ end Check two connectivity structures for equality. ### Returns + Returns true if structures are equal, false otherwise. + ### Prototype + ```c int p8est_connectivity_is_equal (p8est_connectivity_t * conn1, p8est_connectivity_t * conn2); ``` """ function p8est_connectivity_is_equal(conn1, conn2) - @ccall libp4est.p8est_connectivity_is_equal(conn1::Ptr{p8est_connectivity_t}, conn2::Ptr{p8est_connectivity_t})::Cint + @ccall libp4est.p8est_connectivity_is_equal( + conn1::Ptr{p8est_connectivity_t}, + conn2::Ptr{p8est_connectivity_t}, + )::Cint end """ @@ -7475,17 +9673,25 @@ end Write connectivity to a sink object. ### Parameters -* `conn`:\\[in\\] The connectivity to be written. -* `sink`:\\[in,out\\] The connectivity is written into this sink. + + - `conn`:\\[in\\] The connectivity to be written. + - `sink`:\\[in,out\\] The connectivity is written into this sink. + ### Returns + 0 on success, nonzero on error. + ### Prototype + ```c int p8est_connectivity_sink (p8est_connectivity_t * conn, sc_io_sink_t * sink); ``` """ function p8est_connectivity_sink(conn, sink) - @ccall libp4est.p8est_connectivity_sink(conn::Ptr{p8est_connectivity_t}, sink::Ptr{sc_io_sink_t})::Cint + @ccall libp4est.p8est_connectivity_sink( + conn::Ptr{p8est_connectivity_t}, + sink::Ptr{sc_io_sink_t}, + )::Cint end """ @@ -7494,17 +9700,25 @@ end Allocate memory and store the connectivity information there. ### Parameters -* `conn`:\\[in\\] The connectivity structure to be exported to memory. -* `code`:\\[in\\] Encoding and compression method for serialization. + + - `conn`:\\[in\\] The connectivity structure to be exported to memory. + - `code`:\\[in\\] Encoding and compression method for serialization. + ### Returns + Newly created array that contains the information. + ### Prototype + ```c sc_array_t *p8est_connectivity_deflate (p8est_connectivity_t * conn, p8est_connectivity_encode_t code); ``` """ function p8est_connectivity_deflate(conn, code) - @ccall libp4est.p8est_connectivity_deflate(conn::Ptr{p8est_connectivity_t}, code::p8est_connectivity_encode_t)::Ptr{sc_array_t} + @ccall libp4est.p8est_connectivity_deflate( + conn::Ptr{p8est_connectivity_t}, + code::p8est_connectivity_encode_t, + )::Ptr{sc_array_t} end """ @@ -7513,17 +9727,25 @@ end Save a connectivity structure to disk. ### Parameters -* `filename`:\\[in\\] Name of the file to write. -* `connectivity`:\\[in\\] Valid connectivity structure. + + - `filename`:\\[in\\] Name of the file to write. + - `connectivity`:\\[in\\] Valid connectivity structure. + ### Returns + Returns 0 on success, nonzero on file error. + ### Prototype + ```c int p8est_connectivity_save (const char *filename, p8est_connectivity_t * connectivity); ``` """ function p8est_connectivity_save(filename, connectivity) - @ccall libp4est.p8est_connectivity_save(filename::Cstring, connectivity::Ptr{p8est_connectivity_t})::Cint + @ccall libp4est.p8est_connectivity_save( + filename::Cstring, + connectivity::Ptr{p8est_connectivity_t}, + )::Cint end """ @@ -7532,16 +9754,23 @@ end Read connectivity from a source object. ### Parameters -* `source`:\\[in,out\\] The connectivity is read from this source. + + - `source`:\\[in,out\\] The connectivity is read from this source. + ### Returns + The newly created connectivity, or NULL on error. + ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_source (sc_io_source_t * source); ``` """ function p8est_connectivity_source(source) - @ccall libp4est.p8est_connectivity_source(source::Ptr{sc_io_source_t})::Ptr{p8est_connectivity_t} + @ccall libp4est.p8est_connectivity_source( + source::Ptr{sc_io_source_t}, + )::Ptr{p8est_connectivity_t} end """ @@ -7550,16 +9779,23 @@ end Create new connectivity from a memory buffer. ### Parameters -* `buffer`:\\[in\\] The connectivity is created from this memory buffer. + + - `buffer`:\\[in\\] The connectivity is created from this memory buffer. + ### Returns + The newly created connectivity, or NULL on error. + ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_inflate (sc_array_t * buffer); ``` """ function p8est_connectivity_inflate(buffer) - @ccall libp4est.p8est_connectivity_inflate(buffer::Ptr{sc_array_t})::Ptr{p8est_connectivity_t} + @ccall libp4est.p8est_connectivity_inflate( + buffer::Ptr{sc_array_t}, + )::Ptr{p8est_connectivity_t} end """ @@ -7568,17 +9804,25 @@ end Load a connectivity structure from disk. ### Parameters -* `filename`:\\[in\\] Name of the file to read. -* `bytes`:\\[out\\] Size in bytes of connectivity on disk or NULL. + + - `filename`:\\[in\\] Name of the file to read. + - `bytes`:\\[out\\] Size in bytes of connectivity on disk or NULL. + ### Returns + Returns valid connectivity, or NULL on file error. + ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_load (const char *filename, size_t *bytes); ``` """ function p8est_connectivity_load(filename, bytes) - @ccall libp4est.p8est_connectivity_load(filename::Cstring, bytes::Ptr{Csize_t})::Ptr{p8est_connectivity_t} + @ccall libp4est.p8est_connectivity_load( + filename::Cstring, + bytes::Ptr{Csize_t}, + )::Ptr{p8est_connectivity_t} end """ @@ -7587,6 +9831,7 @@ end Create a connectivity structure for the unit cube. ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_new_unitcube (void); ``` @@ -7601,6 +9846,7 @@ end Create a connectivity structure for an all-periodic unit cube. ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_new_periodic (void); ``` @@ -7615,6 +9861,7 @@ end Create a connectivity structure for a mostly periodic unit cube. The left and right faces are identified, and bottom and top rotated. Front and back are not identified. ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_new_rotwrap (void); ``` @@ -7629,6 +9876,7 @@ end Create a connectivity structure that contains two cubes. ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_new_twocubes (void); ``` @@ -7643,16 +9891,23 @@ end Create a connectivity structure for two trees being rotated w.r.t. each other in a user-defined way. ### Parameters -* `l_face`:\\[in\\] index of left face -* `r_face`:\\[in\\] index of right face -* `orientation`:\\[in\\] orientation of trees w.r.t. each other + + - `l_face`:\\[in\\] index of left face + - `r_face`:\\[in\\] index of right face + - `orientation`:\\[in\\] orientation of trees w.r.t. each other + ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_new_twotrees (int l_face, int r_face, int orientation); ``` """ function p8est_connectivity_new_twotrees(l_face, r_face, orientation) - @ccall libp4est.p8est_connectivity_new_twotrees(l_face::Cint, r_face::Cint, orientation::Cint)::Ptr{p8est_connectivity_t} + @ccall libp4est.p8est_connectivity_new_twotrees( + l_face::Cint, + r_face::Cint, + orientation::Cint, + )::Ptr{p8est_connectivity_t} end """ @@ -7661,6 +9916,7 @@ end Create a connectivity structure that contains two cubes where the two far ends are identified periodically. ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_new_twowrap (void); ``` @@ -7675,6 +9931,7 @@ end Create a connectivity structure that contains a few cubes. These are rotated against each other to stress the topology routines. ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_new_rotcubes (void); ``` @@ -7689,12 +9946,20 @@ end An m by n by p array with periodicity in x, y, and z if periodic\\_a, periodic\\_b, and periodic\\_c are true, respectively. ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_new_brick (int m, int n, int p, int periodic_a, int periodic_b, int periodic_c); ``` """ function p8est_connectivity_new_brick(m, n, p, periodic_a, periodic_b, periodic_c) - @ccall libp4est.p8est_connectivity_new_brick(m::Cint, n::Cint, p::Cint, periodic_a::Cint, periodic_b::Cint, periodic_c::Cint)::Ptr{p8est_connectivity_t} + @ccall libp4est.p8est_connectivity_new_brick( + m::Cint, + n::Cint, + p::Cint, + periodic_a::Cint, + periodic_b::Cint, + periodic_c::Cint, + )::Ptr{p8est_connectivity_t} end """ @@ -7703,6 +9968,7 @@ end Create a connectivity structure that builds a spherical shell. It is made up of six connected parts [-1,1]x[-1,1]x[1,2]. This connectivity reuses vertices and relies on a geometry transformation. It is thus not suitable for [`p8est_connectivity_complete`](@ref). ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_new_shell (void); ``` @@ -7717,6 +9983,7 @@ end Create a connectivity structure that builds a solid sphere. It is made up of two layers and a cube in the center. This connectivity reuses vertices and relies on a geometry transformation. It is thus not suitable for [`p8est_connectivity_complete`](@ref). ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_new_sphere (void); ``` @@ -7737,8 +10004,11 @@ This connectivity reuses ideas from disk2d connectivity. More precisely the toru This connectivity is meant to be used with p8est_geometry_new_torus ### Parameters -* `nSegments`:\\[in\\] number of trees along the great circle + + - `nSegments`:\\[in\\] number of trees along the great circle + ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_new_torus (int nSegments); ``` @@ -7753,10 +10023,15 @@ end Create connectivity structure from predefined catalogue. ### Parameters -* `name`:\\[in\\] Invokes connectivity\\_new\\_* function. brick235 brick (2, 3, 5, 0, 0, 0) periodic periodic rotcubes rotcubes rotwrap rotwrap shell shell sphere sphere twocubes twocubes twowrap twowrap unit unitcube + + - `name`:\\[in\\] Invokes connectivity\\_new\\_* function. brick235 brick (2, 3, 5, 0, 0, 0) periodic periodic rotcubes rotcubes rotwrap rotwrap shell shell sphere sphere twocubes twocubes twowrap twowrap unit unitcube + ### Returns + An initialized connectivity if name is defined, NULL else. + ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_new_byname (const char *name); ``` @@ -7771,17 +10046,25 @@ end Uniformly refine a connectivity. This is useful if you would like to uniformly refine by something other than a power of 2. ### Parameters -* `conn`:\\[in\\] A valid connectivity -* `num_per_edge`:\\[in\\] The number of new trees in each direction. Must use no more than P8EST_OLD_QMAXLEVEL bits. + + - `conn`:\\[in\\] A valid connectivity + - `num_per_edge`:\\[in\\] The number of new trees in each direction. Must use no more than P8EST_OLD_QMAXLEVEL bits. + ### Returns + a refined connectivity. + ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_refine (p8est_connectivity_t * conn, int num_per_edge); ``` """ function p8est_connectivity_refine(conn, num_per_edge) - @ccall libp4est.p8est_connectivity_refine(conn::Ptr{p8est_connectivity_t}, num_per_edge::Cint)::Ptr{p8est_connectivity_t} + @ccall libp4est.p8est_connectivity_refine( + conn::Ptr{p8est_connectivity_t}, + num_per_edge::Cint, + )::Ptr{p8est_connectivity_t} end """ @@ -7790,16 +10073,23 @@ end Fill an array with the axis combination of a face neighbor transform. ### Parameters -* `iface`:\\[in\\] The number of the originating face. -* `nface`:\\[in\\] Encoded as nface = r * 6 + nf, where nf = 0..5 is the neigbbor's connecting face number and r = 0..3 is the relative orientation to the neighbor's face. This encoding matches [`p8est_connectivity_t`](@ref). -* `ftransform`:\\[out\\] This array holds 9 integers. [0]..[2] The coordinate axis sequence of the origin face, the first two referring to the tangentials and the third to the normal. A permutation of (0, 1, 2). [3]..[5] The coordinate axis sequence of the target face. [6]..[8] Edge reversal flags for tangential axes (boolean); face code in [0, 3] for the normal coordinate q: 0: q' = -q 1: q' = q + 1 2: q' = q - 1 3: q' = 2 - q + + - `iface`:\\[in\\] The number of the originating face. + - `nface`:\\[in\\] Encoded as nface = r * 6 + nf, where nf = 0..5 is the neigbbor's connecting face number and r = 0..3 is the relative orientation to the neighbor's face. This encoding matches [`p8est_connectivity_t`](@ref). + - `ftransform`:\\[out\\] This array holds 9 integers. [0]..[2] The coordinate axis sequence of the origin face, the first two referring to the tangentials and the third to the normal. A permutation of (0, 1, 2). [3]..[5] The coordinate axis sequence of the target face. [6]..[8] Edge reversal flags for tangential axes (boolean); face code in [0, 3] for the normal coordinate q: 0: q' = -q 1: q' = q + 1 2: q' = q - 1 3: q' = 2 - q + ### Prototype + ```c void p8est_expand_face_transform (int iface, int nface, int ftransform[]); ``` """ function p8est_expand_face_transform(iface, nface, ftransform) - @ccall libp4est.p8est_expand_face_transform(iface::Cint, nface::Cint, ftransform::Ptr{Cint})::Cvoid + @ccall libp4est.p8est_expand_face_transform( + iface::Cint, + nface::Cint, + ftransform::Ptr{Cint}, + )::Cvoid end """ @@ -7808,18 +10098,28 @@ end Fill an array with the axis combination of a face neighbor transform. ### Parameters -* `itree`:\\[in\\] The number of the originating tree. -* `iface`:\\[in\\] The number of the originating tree's face. -* `ftransform`:\\[out\\] This array holds 9 integers. [0]..[2] The coordinate axis sequence of the origin face. [3]..[5] The coordinate axis sequence of the target face. [6]..[8] Edge reverse flag for axes t1, t2; face code for n. + + - `itree`:\\[in\\] The number of the originating tree. + - `iface`:\\[in\\] The number of the originating tree's face. + - `ftransform`:\\[out\\] This array holds 9 integers. [0]..[2] The coordinate axis sequence of the origin face. [3]..[5] The coordinate axis sequence of the target face. [6]..[8] Edge reverse flag for axes t1, t2; face code for n. + ### Returns + The face neighbor tree if it exists, -1 otherwise. + ### Prototype + ```c p4est_topidx_t p8est_find_face_transform (p8est_connectivity_t * connectivity, p4est_topidx_t itree, int iface, int ftransform[]); ``` """ function p8est_find_face_transform(connectivity, itree, iface, ftransform) - @ccall libp4est.p8est_find_face_transform(connectivity::Ptr{p8est_connectivity_t}, itree::p4est_topidx_t, iface::Cint, ftransform::Ptr{Cint})::p4est_topidx_t + @ccall libp4est.p8est_find_face_transform( + connectivity::Ptr{p8est_connectivity_t}, + itree::p4est_topidx_t, + iface::Cint, + ftransform::Ptr{Cint}, + )::p4est_topidx_t end """ @@ -7828,16 +10128,24 @@ end Fills an array with information about edge neighbors. ### Parameters -* `itree`:\\[in\\] The number of the originating tree. -* `iedge`:\\[in\\] The number of the originating edge. -* `ei`:\\[in,out\\] A `p8est_edge_info_t` structure with initialized array. + + - `itree`:\\[in\\] The number of the originating tree. + - `iedge`:\\[in\\] The number of the originating edge. + - `ei`:\\[in,out\\] A `p8est_edge_info_t` structure with initialized array. + ### Prototype + ```c void p8est_find_edge_transform (p8est_connectivity_t * connectivity, p4est_topidx_t itree, int iedge, p8est_edge_info_t * ei); ``` """ function p8est_find_edge_transform(connectivity, itree, iedge, ei) - @ccall libp4est.p8est_find_edge_transform(connectivity::Ptr{p8est_connectivity_t}, itree::p4est_topidx_t, iedge::Cint, ei::Ptr{p8est_edge_info_t})::Cvoid + @ccall libp4est.p8est_find_edge_transform( + connectivity::Ptr{p8est_connectivity_t}, + itree::p4est_topidx_t, + iedge::Cint, + ei::Ptr{p8est_edge_info_t}, + )::Cvoid end """ @@ -7846,16 +10154,24 @@ end Fills an array with information about corner neighbors. ### Parameters -* `itree`:\\[in\\] The number of the originating tree. -* `icorner`:\\[in\\] The number of the originating corner. -* `ci`:\\[in,out\\] A `p8est_corner_info_t` structure with initialized array. + + - `itree`:\\[in\\] The number of the originating tree. + - `icorner`:\\[in\\] The number of the originating corner. + - `ci`:\\[in,out\\] A `p8est_corner_info_t` structure with initialized array. + ### Prototype + ```c void p8est_find_corner_transform (p8est_connectivity_t * connectivity, p4est_topidx_t itree, int icorner, p8est_corner_info_t * ci); ``` """ function p8est_find_corner_transform(connectivity, itree, icorner, ci) - @ccall libp4est.p8est_find_corner_transform(connectivity::Ptr{p8est_connectivity_t}, itree::p4est_topidx_t, icorner::Cint, ci::Ptr{p8est_corner_info_t})::Cvoid + @ccall libp4est.p8est_find_corner_transform( + connectivity::Ptr{p8est_connectivity_t}, + itree::p4est_topidx_t, + icorner::Cint, + ci::Ptr{p8est_corner_info_t}, + )::Cvoid end """ @@ -7864,8 +10180,11 @@ end Internally connect a connectivity based on tree\\_to\\_vertex information. Periodicity that is not inherent in the list of vertices will be lost. ### Parameters -* `conn`:\\[in,out\\] The connectivity needs to have proper vertices and tree\\_to\\_vertex fields. The tree\\_to\\_tree and tree\\_to\\_face fields must be allocated and satisfy [`p8est_connectivity_is_valid`](@ref) (conn) but will be overwritten. The edge and corner fields will be freed and allocated anew. + + - `conn`:\\[in,out\\] The connectivity needs to have proper vertices and tree\\_to\\_vertex fields. The tree\\_to\\_tree and tree\\_to\\_face fields must be allocated and satisfy [`p8est_connectivity_is_valid`](@ref) (conn) but will be overwritten. The edge and corner fields will be freed and allocated anew. + ### Prototype + ```c void p8est_connectivity_complete (p8est_connectivity_t * conn); ``` @@ -7880,8 +10199,11 @@ end Removes corner and edge information of a connectivity such that enough information is left to run [`p8est_connectivity_complete`](@ref) successfully. The reduced connectivity still passes [`p8est_connectivity_is_valid`](@ref). ### Parameters -* `conn`:\\[in,out\\] The connectivity to be reduced. + + - `conn`:\\[in,out\\] The connectivity to be reduced. + ### Prototype + ```c void p8est_connectivity_reduce (p8est_connectivity_t * conn); ``` @@ -7896,16 +10218,23 @@ end [`p8est_connectivity_permute`](@ref) Given a permutation *perm* of the trees in a connectivity *conn*, permute the trees of *conn* in place and update *conn* to match. ### Parameters -* `conn`:\\[in,out\\] The connectivity whose trees are permuted. -* `perm`:\\[in\\] A permutation array, whose elements are size\\_t's. -* `is_current_to_new`:\\[in\\] if true, the jth entry of perm is the new index for the entry whose current index is j, otherwise the jth entry of perm is the current index of the tree whose index will be j after the permutation. + + - `conn`:\\[in,out\\] The connectivity whose trees are permuted. + - `perm`:\\[in\\] A permutation array, whose elements are size\\_t's. + - `is_current_to_new`:\\[in\\] if true, the jth entry of perm is the new index for the entry whose current index is j, otherwise the jth entry of perm is the current index of the tree whose index will be j after the permutation. + ### Prototype + ```c void p8est_connectivity_permute (p8est_connectivity_t * conn, sc_array_t * perm, int is_current_to_new); ``` """ function p8est_connectivity_permute(conn, perm, is_current_to_new) - @ccall libp4est.p8est_connectivity_permute(conn::Ptr{p8est_connectivity_t}, perm::Ptr{sc_array_t}, is_current_to_new::Cint)::Cvoid + @ccall libp4est.p8est_connectivity_permute( + conn::Ptr{p8est_connectivity_t}, + perm::Ptr{sc_array_t}, + is_current_to_new::Cint, + )::Cvoid end """ @@ -7914,19 +10243,36 @@ end [`p8est_connectivity_join_faces`](@ref) This function takes an existing valid connectivity *conn* and modifies it by joining two tree faces that are currently boundary faces. ### Parameters -* `conn`:\\[in,out\\] connectivity that will be altered. -* `tree_left`:\\[in\\] tree that will be on the left side of the joined faces. -* `tree_right`:\\[in\\] tree that will be on the right side of the joined faces. -* `face_left`:\\[in\\] face of *tree_left* that will be joined. -* `face_right`:\\[in\\] face of *tree_right* that will be joined. -* `orientation`:\\[in\\] the orientation of *face_left* and *face_right* once joined (see the description of [`p8est_connectivity_t`](@ref) to understand orientation). + + - `conn`:\\[in,out\\] connectivity that will be altered. + - `tree_left`:\\[in\\] tree that will be on the left side of the joined faces. + - `tree_right`:\\[in\\] tree that will be on the right side of the joined faces. + - `face_left`:\\[in\\] face of *tree_left* that will be joined. + - `face_right`:\\[in\\] face of *tree_right* that will be joined. + - `orientation`:\\[in\\] the orientation of *face_left* and *face_right* once joined (see the description of [`p8est_connectivity_t`](@ref) to understand orientation). + ### Prototype + ```c void p8est_connectivity_join_faces (p8est_connectivity_t * conn, p4est_topidx_t tree_left, p4est_topidx_t tree_right, int face_left, int face_right, int orientation); ``` """ -function p8est_connectivity_join_faces(conn, tree_left, tree_right, face_left, face_right, orientation) - @ccall libp4est.p8est_connectivity_join_faces(conn::Ptr{p8est_connectivity_t}, tree_left::p4est_topidx_t, tree_right::p4est_topidx_t, face_left::Cint, face_right::Cint, orientation::Cint)::Cvoid +function p8est_connectivity_join_faces( + conn, + tree_left, + tree_right, + face_left, + face_right, + orientation, +) + @ccall libp4est.p8est_connectivity_join_faces( + conn::Ptr{p8est_connectivity_t}, + tree_left::p4est_topidx_t, + tree_right::p4est_topidx_t, + face_left::Cint, + face_right::Cint, + orientation::Cint, + )::Cvoid end """ @@ -7935,15 +10281,21 @@ end [`p8est_connectivity_is_equivalent`](@ref) This function compares two connectivities for equivalence: it returns *true* if they are the same connectivity, or if they have the same topology. The definition of topological sameness is strict: there is no attempt made to determine whether permutation and/or rotation of the trees makes the connectivities equivalent. ### Parameters -* `conn1`:\\[in\\] a valid connectivity -* `conn2`:\\[out\\] a valid connectivity + + - `conn1`:\\[in\\] a valid connectivity + - `conn2`:\\[out\\] a valid connectivity + ### Prototype + ```c int p8est_connectivity_is_equivalent (p8est_connectivity_t * conn1, p8est_connectivity_t * conn2); ``` """ function p8est_connectivity_is_equivalent(conn1, conn2) - @ccall libp4est.p8est_connectivity_is_equivalent(conn1::Ptr{p8est_connectivity_t}, conn2::Ptr{p8est_connectivity_t})::Cint + @ccall libp4est.p8est_connectivity_is_equivalent( + conn1::Ptr{p8est_connectivity_t}, + conn2::Ptr{p8est_connectivity_t}, + )::Cint end """ @@ -8006,20 +10358,37 @@ and in 3D they are given as: This code can be called two ways. The first, when `vertex`==NULL and `tree_to_vertex`==NULL, is used to count the number of trees and vertices in the connectivity to be generated by the `.inp` mesh in the *stream*. The second, when `vertices`!=NULL and `tree_to_vertex`!=NULL, fill `vertices` and `tree_to_vertex`. In this case `num_vertices` and `num_trees` need to be set to the maximum number of entries allocated in `vertices` and `tree_to_vertex`. ### Parameters -* `stream`:\\[in,out\\] file stream to read the connectivity from -* `num_vertices`:\\[in,out\\] the number of vertices in the connectivity -* `num_trees`:\\[in,out\\] the number of trees in the connectivity -* `vertices`:\\[out\\] the list of `vertices` of the connectivity -* `tree_to_vertex`:\\[out\\] the `tree_to_vertex` map of the connectivity + + - `stream`:\\[in,out\\] file stream to read the connectivity from + - `num_vertices`:\\[in,out\\] the number of vertices in the connectivity + - `num_trees`:\\[in,out\\] the number of trees in the connectivity + - `vertices`:\\[out\\] the list of `vertices` of the connectivity + - `tree_to_vertex`:\\[out\\] the `tree_to_vertex` map of the connectivity + ### Returns + 0 if successful and nonzero if not + ### Prototype + ```c int p8est_connectivity_read_inp_stream (FILE * stream, p4est_topidx_t * num_vertices, p4est_topidx_t * num_trees, double *vertices, p4est_topidx_t * tree_to_vertex); ``` """ -function p8est_connectivity_read_inp_stream(stream, num_vertices, num_trees, vertices, tree_to_vertex) - @ccall libp4est.p8est_connectivity_read_inp_stream(stream::Ptr{Libc.FILE}, num_vertices::Ptr{p4est_topidx_t}, num_trees::Ptr{p4est_topidx_t}, vertices::Ptr{Cdouble}, tree_to_vertex::Ptr{p4est_topidx_t})::Cint +function p8est_connectivity_read_inp_stream( + stream, + num_vertices, + num_trees, + vertices, + tree_to_vertex, +) + @ccall libp4est.p8est_connectivity_read_inp_stream( + stream::Ptr{Libc.FILE}, + num_vertices::Ptr{p4est_topidx_t}, + num_trees::Ptr{p4est_topidx_t}, + vertices::Ptr{Cdouble}, + tree_to_vertex::Ptr{p4est_topidx_t}, + )::Cint end """ @@ -8082,16 +10451,23 @@ and in 3D they are given as: This function reads a mesh from *filename* and returns an associated `p4est` connectivity. ### Parameters -* `filename`:\\[in\\] file to read the connectivity from + + - `filename`:\\[in\\] file to read the connectivity from + ### Returns + an allocated connectivity associated with the mesh in *filename* + ### Prototype + ```c p8est_connectivity_t *p8est_connectivity_read_inp (const char *filename); ``` """ function p8est_connectivity_read_inp(filename) - @ccall libp4est.p8est_connectivity_read_inp(filename::Cstring)::Ptr{p8est_connectivity_t} + @ccall libp4est.p8est_connectivity_read_inp( + filename::Cstring, + )::Ptr{p8est_connectivity_t} end """ @@ -8099,19 +10475,21 @@ end This structure holds the 2D+1D inter-tree connectivity information. It is essentially a wrapper of the 2D p4est\\_connecitivity\\_t datatype, with some additional information about how the third dimension is embedded. -| Field | Note | -| :------------- | :--------------------------------------------------------------------------------------------------------------------------------------------- | -| conn4 | the 2D connecitvity; owned; vertices interpreted as the vertices of the bottom of the sheet | -| top\\_vertices | if NULL, uniform vertical profile, otherwise the vertices of the top of the sheet: should be the same size as *conn4*->tree_to_vertex; owned. | -| height | if *top_vertices* == NULL, this gives the offset from the bottom of the sheet to the top | +| Field | Note | +|:-------------- |:--------------------------------------------------------------------------------------------------------------------------------------------- | +| conn4 | the 2D connecitvity; owned; vertices interpreted as the vertices of the bottom of the sheet | +| top\\_vertices | if NULL, uniform vertical profile, otherwise the vertices of the top of the sheet: should be the same size as *conn4*->tree_to_vertex; owned. | +| height | if *top_vertices* == NULL, this gives the offset from the bottom of the sheet to the top | """ struct p6est_connectivity conn4::Ptr{p4est_connectivity_t} top_vertices::Ptr{Cdouble} - height::NTuple{3, Cdouble} + height::NTuple{3,Cdouble} end -"""This structure holds the 2D+1D inter-tree connectivity information. It is essentially a wrapper of the 2D p4est\\_connecitivity\\_t datatype, with some additional information about how the third dimension is embedded.""" +""" +This structure holds the 2D+1D inter-tree connectivity information. It is essentially a wrapper of the 2D p4est\\_connecitivity\\_t datatype, with some additional information about how the third dimension is embedded. +""" const p6est_connectivity_t = p6est_connectivity """ @@ -8120,18 +10498,27 @@ const p6est_connectivity_t = p6est_connectivity Create a [`p6est_connectivity_t`](@ref) from a [`p4est_connectivity_t`](@ref). All fields are copied, so all inputs can be safey destroyed. ### Parameters -* `conn4`:\\[in\\] the 2D connectivity -* `top_vertices`:\\[in\\] if NULL, then the sheet has a uniform vertical profile; otherwise, *top_vertices* gives teh vertices of the top of the sheet; should be the same size as *conn4*->tree_to_vertex -* `height`:\\[in\\] if *top_vertices* == NULL, then this gives the offset fro the bottom of the sheet to the top. + + - `conn4`:\\[in\\] the 2D connectivity + - `top_vertices`:\\[in\\] if NULL, then the sheet has a uniform vertical profile; otherwise, *top_vertices* gives teh vertices of the top of the sheet; should be the same size as *conn4*->tree_to_vertex + - `height`:\\[in\\] if *top_vertices* == NULL, then this gives the offset fro the bottom of the sheet to the top. + ### Returns + the 2D+1D connectivity information. + ### Prototype + ```c p6est_connectivity_t *p6est_connectivity_new (p4est_connectivity_t * conn4, double *top_vertices, double height[3]); ``` """ function p6est_connectivity_new(conn4, top_vertices, height) - @ccall libp4est.p6est_connectivity_new(conn4::Ptr{p4est_connectivity_t}, top_vertices::Ptr{Cdouble}, height::Ptr{Cdouble})::Ptr{p6est_connectivity_t} + @ccall libp4est.p6est_connectivity_new( + conn4::Ptr{p4est_connectivity_t}, + top_vertices::Ptr{Cdouble}, + height::Ptr{Cdouble}, + )::Ptr{p6est_connectivity_t} end """ @@ -8140,6 +10527,7 @@ end Destroy a [`p6est_connectivity`](@ref) structure ### Prototype + ```c void p6est_connectivity_destroy (p6est_connectivity_t * conn); ``` @@ -8154,16 +10542,23 @@ end Get the vertices of the corners of a tree. ### Parameters -* `conn`:\\[in\\] the 2D+1D connectivity structure -* `which_tree`:\\[in\\] a tree in the forest -* `vertices`:\\[out\\] the coordinates of the corners of the tree + + - `conn`:\\[in\\] the 2D+1D connectivity structure + - `which_tree`:\\[in\\] a tree in the forest + - `vertices`:\\[out\\] the coordinates of the corners of the tree + ### Prototype + ```c void p6est_tree_get_vertices (p6est_connectivity_t * conn, p4est_topidx_t which_tree, double vertices[24]); ``` """ function p6est_tree_get_vertices(conn, which_tree, vertices) - @ccall libp4est.p6est_tree_get_vertices(conn::Ptr{p6est_connectivity_t}, which_tree::p4est_topidx_t, vertices::Ptr{Cdouble})::Cvoid + @ccall libp4est.p6est_tree_get_vertices( + conn::Ptr{p6est_connectivity_t}, + which_tree::p4est_topidx_t, + vertices::Ptr{Cdouble}, + )::Cvoid end """ @@ -8172,36 +10567,46 @@ end Transform a quadrant coordinate into the space spanned by tree vertices. ### Parameters -* `connectivity`:\\[in\\] Connectivity must provide the vertices. -* `treeid`:\\[in\\] Identify the tree that contains x, y. -* `x,`:\\[in\\] y Quadrant coordinates relative to treeid. -* `vxy`:\\[out\\] Transformed coordinates in vertex space. + + - `connectivity`:\\[in\\] Connectivity must provide the vertices. + - `treeid`:\\[in\\] Identify the tree that contains x, y. + - `x,`:\\[in\\] y Quadrant coordinates relative to treeid. + - `vxy`:\\[out\\] Transformed coordinates in vertex space. + ### Prototype + ```c void p6est_qcoord_to_vertex (p6est_connectivity_t * connectivity, p4est_topidx_t treeid, p4est_qcoord_t x, p4est_qcoord_t y, p4est_qcoord_t z, double vxyz[3]); ``` """ function p6est_qcoord_to_vertex(connectivity, treeid, x, y, z, vxyz) - @ccall libp4est.p6est_qcoord_to_vertex(connectivity::Ptr{p6est_connectivity_t}, treeid::p4est_topidx_t, x::p4est_qcoord_t, y::p4est_qcoord_t, z::p4est_qcoord_t, vxyz::Ptr{Cdouble})::Cvoid + @ccall libp4est.p6est_qcoord_to_vertex( + connectivity::Ptr{p6est_connectivity_t}, + treeid::p4est_topidx_t, + x::p4est_qcoord_t, + y::p4est_qcoord_t, + z::p4est_qcoord_t, + vxyz::Ptr{Cdouble}, + )::Cvoid end """ p6est -| Field | Note | -| :--------------------- | :--------------------------------------------------------------------------------------------------------- | -| mpisize | number of MPI processes | -| mpirank | this process's MPI rank | -| mpicomm\\_owned | whether this communicator is owned by the forest | -| data\\_size | size of per-quadrant p.user\\_data (see [`p2est_quadrant_t`](@ref)::p2est\\_quadrant\\_data::user\\_data) | -| user\\_pointer | convenience pointer for users, never touched by `p4est` | -| connectivity | topology of sheet, not owned. | -| columns | 2D description of column layout built from *connectivity* | -| layers | single array that stores [`p2est_quadrant_t`](@ref) layers within columns | -| user\\_data\\_pool | memory allocator for user data | -| layer\\_pool | memory allocator for temporary layers | -| global\\_first\\_layer | first global quadrant index for each process and 1 beyond | -| root\\_len | height of the domain | +| Field | Note | +|:---------------------- |:--------------------------------------------------------------------------------------------------------- | +| mpisize | number of MPI processes | +| mpirank | this process's MPI rank | +| mpicomm\\_owned | whether this communicator is owned by the forest | +| data\\_size | size of per-quadrant p.user\\_data (see [`p2est_quadrant_t`](@ref)::p2est\\_quadrant\\_data::user\\_data) | +| user\\_pointer | convenience pointer for users, never touched by `p4est` | +| connectivity | topology of sheet, not owned. | +| columns | 2D description of column layout built from *connectivity* | +| layers | single array that stores [`p2est_quadrant_t`](@ref) layers within columns | +| user\\_data\\_pool | memory allocator for user data | +| layer\\_pool | memory allocator for temporary layers | +| global\\_first\\_layer | first global quadrant index for each process and 1 beyond | +| root\\_len | height of the domain | """ struct p6est mpicomm::MPI_Comm @@ -8219,7 +10624,9 @@ struct p6est root_len::p4est_qcoord_t end -"""The `p6est` forest datatype""" +""" +The `p6est` forest datatype +""" const p6est_t = p6est # typedef void ( * p6est_init_t ) ( p6est_t * p6est , p4est_topidx_t which_tree , p4est_quadrant_t * column , p2est_quadrant_t * layer ) @@ -8227,10 +10634,11 @@ const p6est_t = p6est Callback function prototype to initialize the layers's user data. ### Parameters -* `p6est`:\\[in\\] the forest -* `which_tree`:\\[in\\] the tree in the forest -* `column`:\\[in\\] the column in the tree in the forest -* `layer`:\\[in\\] the layer in the column in the tree in the forest, whose *user_data* is to be initialized + + - `p6est`:\\[in\\] the forest + - `which_tree`:\\[in\\] the tree in the forest + - `column`:\\[in\\] the column in the tree in the forest + - `layer`:\\[in\\] the layer in the column in the tree in the forest, whose *user_data* is to be initialized """ const p6est_init_t = Ptr{Cvoid} @@ -8241,14 +10649,15 @@ Callback function prototype to transfer information from outgoing layers to inco This is used by extended routines when the layers of an existing, valid `p6est` are changed. The callback allows the user to make changes to newly initialized layers before the layers that they replace are destroyed. ### Parameters -* `num_outcolumns`:\\[in\\] The number of columns that contain the outgoing layers: will be either 1 or 4. -* `num_outlayers`:\\[in\\] The number of outgoing layers: will be either 1 (a single layer is being refined), 2 (two layers are being vertically coarsened), or 4 (four layers are being horizontally coarsened). -* `outcolumns`:\\[in\\] The columns of the outgoing layers -* `outlayers`:\\[in\\] The outgoing layers: after the callback, the user\\_data, if `p6est`->data_size is nonzero, will be destroyed. -* `num_incolumns`:\\[in\\] The number of columns that contain the outgoing layers: will be either 1 or 4. -* `num_inlayers`:\\[in\\] The number of incoming layers: will be either 1 (coarsening), 2 (vertical refinement), or 4 (horizontal refinement) -* `incolumns`:\\[in\\] The columns of the incoming layers -* `inlayers`:\\[in,out\\] The incoming layers: prior to the callback, the user\\_data, if `p6est`->data_size is nonzero, is allocated, and the [`p6est_init_t`](@ref) callback, if it has been provided, will be called. + + - `num_outcolumns`:\\[in\\] The number of columns that contain the outgoing layers: will be either 1 or 4. + - `num_outlayers`:\\[in\\] The number of outgoing layers: will be either 1 (a single layer is being refined), 2 (two layers are being vertically coarsened), or 4 (four layers are being horizontally coarsened). + - `outcolumns`:\\[in\\] The columns of the outgoing layers + - `outlayers`:\\[in\\] The outgoing layers: after the callback, the user\\_data, if `p6est`->data_size is nonzero, will be destroyed. + - `num_incolumns`:\\[in\\] The number of columns that contain the outgoing layers: will be either 1 or 4. + - `num_inlayers`:\\[in\\] The number of incoming layers: will be either 1 (coarsening), 2 (vertical refinement), or 4 (horizontal refinement) + - `incolumns`:\\[in\\] The columns of the incoming layers + - `inlayers`:\\[in,out\\] The incoming layers: prior to the callback, the user\\_data, if `p6est`->data_size is nonzero, is allocated, and the [`p6est_init_t`](@ref) callback, if it has been provided, will be called. """ const p6est_replace_t = Ptr{Cvoid} @@ -8257,6 +10666,7 @@ const p6est_replace_t = Ptr{Cvoid} Callback function prototype to decide whether to horizontally refine a column, i.e., horizontally refine all of the layers in the column. ### Returns + nonzero if the layer shall be refined. """ const p6est_refine_column_t = Ptr{Cvoid} @@ -8266,6 +10676,7 @@ const p6est_refine_column_t = Ptr{Cvoid} Callback function prototype to decide whether to vertically refine a layer. ### Returns + nonzero if the layer shall be refined. """ const p6est_refine_layer_t = Ptr{Cvoid} @@ -8275,8 +10686,11 @@ const p6est_refine_layer_t = Ptr{Cvoid} Callback function prototype to decide for horizontal coarsening. ### Parameters -* `columns`:\\[in\\] Pointers to 4 sibling columns. + + - `columns`:\\[in\\] Pointers to 4 sibling columns. + ### Returns + nonzero if the columns shall be replaced with their parent. """ const p6est_coarsen_column_t = Ptr{Cvoid} @@ -8286,8 +10700,11 @@ const p6est_coarsen_column_t = Ptr{Cvoid} Callback function prototype to decide for vertical coarsening. ### Parameters -* `layers`:\\[in\\] Pointers to 2 vertical sibling layers. + + - `layers`:\\[in\\] Pointers to 2 vertical sibling layers. + ### Returns + nonzero if the layers shall be replaced with their parent. """ const p6est_coarsen_layer_t = Ptr{Cvoid} @@ -8301,6 +10718,7 @@ Callback function prototype to calculate weights for partitioning. Global sum of weights must fit into a 64bit integer. ### Returns + a 32bit integer >= 0 as the quadrant weight. """ const p6est_weight_t = Ptr{Cvoid} @@ -8309,12 +10727,19 @@ const p6est_weight_t = Ptr{Cvoid} p6est_new(mpicomm, connectivity, data_size, init_fn, user_pointer) ### Prototype + ```c p6est_t *p6est_new (sc_MPI_Comm mpicomm, p6est_connectivity_t * connectivity, size_t data_size, p6est_init_t init_fn, void *user_pointer); ``` """ function p6est_new(mpicomm, connectivity, data_size, init_fn, user_pointer) - @ccall libp4est.p6est_new(mpicomm::MPI_Comm, connectivity::Ptr{p6est_connectivity_t}, data_size::Csize_t, init_fn::p6est_init_t, user_pointer::Ptr{Cvoid})::Ptr{p6est_t} + @ccall libp4est.p6est_new( + mpicomm::MPI_Comm, + connectivity::Ptr{p6est_connectivity_t}, + data_size::Csize_t, + init_fn::p6est_init_t, + user_pointer::Ptr{Cvoid}, + )::Ptr{p6est_t} end """ @@ -8323,22 +10748,43 @@ end Create a new forest from an already created `p4est` that represents columns. ### Parameters -* `p4est`:\\[in\\] A valid `p4est`. A deep copy will be created, so this can be destroyed without affectin the new `p6est` object. -* `top_vertices`:\\[in\\] the same as in p6est\\_conectivity\\_new() -* `height`:\\[in\\] the same as in p6est\\_conectivity\\_new() -* `min_zlevel`:\\[in\\] the same as in [`p6est_new`](@ref)() -* `data_size`:\\[in\\] the same as in [`p6est_new`](@ref)() -* `init_fn`:\\[in\\] the same as in [`p6est_new`](@ref)() -* `user_pointer`:\\[in\\] the same as in [`p6est_new`](@ref)() + + - `p4est`:\\[in\\] A valid `p4est`. A deep copy will be created, so this can be destroyed without affectin the new `p6est` object. + - `top_vertices`:\\[in\\] the same as in p6est\\_conectivity\\_new() + - `height`:\\[in\\] the same as in p6est\\_conectivity\\_new() + - `min_zlevel`:\\[in\\] the same as in [`p6est_new`](@ref)() + - `data_size`:\\[in\\] the same as in [`p6est_new`](@ref)() + - `init_fn`:\\[in\\] the same as in [`p6est_new`](@ref)() + - `user_pointer`:\\[in\\] the same as in [`p6est_new`](@ref)() + ### Returns + This returns a valid forest. The user must destroy the connectivity for the new `p6est` independently. + ### Prototype + ```c p6est_t *p6est_new_from_p4est (p4est_t * p4est, double *top_vertices, double height[3], int min_zlevel, size_t data_size, p6est_init_t init_fn, void *user_pointer); ``` """ -function p6est_new_from_p4est(p4est_, top_vertices, height, min_zlevel, data_size, init_fn, user_pointer) - @ccall libp4est.p6est_new_from_p4est(p4est_::Ptr{p4est_t}, top_vertices::Ptr{Cdouble}, height::Ptr{Cdouble}, min_zlevel::Cint, data_size::Csize_t, init_fn::p6est_init_t, user_pointer::Ptr{Cvoid})::Ptr{p6est_t} +function p6est_new_from_p4est( + p4est_, + top_vertices, + height, + min_zlevel, + data_size, + init_fn, + user_pointer, +) + @ccall libp4est.p6est_new_from_p4est( + p4est_::Ptr{p4est_t}, + top_vertices::Ptr{Cdouble}, + height::Ptr{Cdouble}, + min_zlevel::Cint, + data_size::Csize_t, + init_fn::p6est_init_t, + user_pointer::Ptr{Cvoid}, + )::Ptr{p6est_t} end """ @@ -8351,6 +10797,7 @@ Destroy a `p6est`. The connectivity structure is not destroyed with the `p6est`. ### Prototype + ```c void p6est_destroy (p6est_t * p6est); ``` @@ -8365,10 +10812,15 @@ end Make a deep copy of a `p6est`. The connectivity is not duplicated. Copying of quadrant user data is optional. If old and new data sizes are 0, the user\\_data field is copied regardless. ### Parameters -* `copy_data`:\\[in\\] If true, data are copied. If false, data\\_size is set to 0. + + - `copy_data`:\\[in\\] If true, data are copied. If false, data\\_size is set to 0. + ### Returns + Returns a valid `p6est` that does not depend on the input. + ### Prototype + ```c p6est_t *p6est_copy (p6est_t * input, int copy_data); ``` @@ -8383,16 +10835,24 @@ end Reset user pointer and element data. When the data size is changed the quadrant data is freed and allocated. The initialization callback is invoked on each quadrant. Old user\\_data content is disregarded. ### Parameters -* `data_size`:\\[in\\] This is the size of data for each quadrant which can be zero. Then user\\_data\\_pool is set to NULL. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. -* `user_pointer`:\\[in\\] Assign to the user\\_pointer member of the `p6est` before init\\_fn is called the first time. + + - `data_size`:\\[in\\] This is the size of data for each quadrant which can be zero. Then user\\_data\\_pool is set to NULL. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + - `user_pointer`:\\[in\\] Assign to the user\\_pointer member of the `p6est` before init\\_fn is called the first time. + ### Prototype + ```c void p6est_reset_data (p6est_t * p6est, size_t data_size, p6est_init_t init_fn, void *user_pointer); ``` """ function p6est_reset_data(p6est_, data_size, init_fn, user_pointer) - @ccall libp4est.p6est_reset_data(p6est_::Ptr{p6est_t}, data_size::Csize_t, init_fn::p6est_init_t, user_pointer::Ptr{Cvoid})::Cvoid + @ccall libp4est.p6est_reset_data( + p6est_::Ptr{p6est_t}, + data_size::Csize_t, + init_fn::p6est_init_t, + user_pointer::Ptr{Cvoid}, + )::Cvoid end """ @@ -8401,17 +10861,25 @@ end Refine the columns of a sheet. ### Parameters -* `p6est`:\\[in,out\\] The forest is changed in place. -* `refine_recursive`:\\[in\\] Boolean to decide on recursive refinement. -* `refine_fn`:\\[in\\] Callback function that must return true if a column shall be refined into smaller columns. If refine\\_recursive is true, refine\\_fn is called for every existing and newly created column. Otherwise, it is called for every existing column. It is possible that a refinement request made by the callback is ignored. To catch this case, you can examine whether init\\_fn gets called, or use [`p6est_refine_columns_ext`](@ref) in p6est\\_extended.h and examine whether replace\\_fn gets called. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data of newly created layers within columns, which are already allocated. This function pointer may be NULL. + + - `p6est`:\\[in,out\\] The forest is changed in place. + - `refine_recursive`:\\[in\\] Boolean to decide on recursive refinement. + - `refine_fn`:\\[in\\] Callback function that must return true if a column shall be refined into smaller columns. If refine\\_recursive is true, refine\\_fn is called for every existing and newly created column. Otherwise, it is called for every existing column. It is possible that a refinement request made by the callback is ignored. To catch this case, you can examine whether init\\_fn gets called, or use [`p6est_refine_columns_ext`](@ref) in p6est\\_extended.h and examine whether replace\\_fn gets called. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data of newly created layers within columns, which are already allocated. This function pointer may be NULL. + ### Prototype + ```c void p6est_refine_columns (p6est_t * p6est, int refine_recursive, p6est_refine_column_t refine_fn, p6est_init_t init_fn); ``` """ function p6est_refine_columns(p6est_, refine_recursive, refine_fn, init_fn) - @ccall libp4est.p6est_refine_columns(p6est_::Ptr{p6est_t}, refine_recursive::Cint, refine_fn::p6est_refine_column_t, init_fn::p6est_init_t)::Cvoid + @ccall libp4est.p6est_refine_columns( + p6est_::Ptr{p6est_t}, + refine_recursive::Cint, + refine_fn::p6est_refine_column_t, + init_fn::p6est_init_t, + )::Cvoid end """ @@ -8420,17 +10888,25 @@ end Refine the layers within the columns of a sheet. ### Parameters -* `p6est`:\\[in,out\\] The forest is changed in place. -* `refine_recursive`:\\[in\\] Boolean to decide on recursive refinement. -* `refine_fn`:\\[in\\] Callback function that must return true if a layer shall be refined into smaller layers. If refine\\_recursive is true, refine\\_fn is called for every existing and newly created layer. Otherwise, it is called for every existing layer. It is possible that a refinement request made by the callback is ignored. To catch this case, you can examine whether init\\_fn gets called, or use [`p6est_refine_layers_ext`](@ref) in p6est\\_extended.h and examine whether replace\\_fn gets called. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data of newly created layers, which are already allocated. This function pointer may be NULL. + + - `p6est`:\\[in,out\\] The forest is changed in place. + - `refine_recursive`:\\[in\\] Boolean to decide on recursive refinement. + - `refine_fn`:\\[in\\] Callback function that must return true if a layer shall be refined into smaller layers. If refine\\_recursive is true, refine\\_fn is called for every existing and newly created layer. Otherwise, it is called for every existing layer. It is possible that a refinement request made by the callback is ignored. To catch this case, you can examine whether init\\_fn gets called, or use [`p6est_refine_layers_ext`](@ref) in p6est\\_extended.h and examine whether replace\\_fn gets called. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data of newly created layers, which are already allocated. This function pointer may be NULL. + ### Prototype + ```c void p6est_refine_layers (p6est_t * p6est, int refine_recursive, p6est_refine_layer_t refine_fn, p6est_init_t init_fn); ``` """ function p6est_refine_layers(p6est_, refine_recursive, refine_fn, init_fn) - @ccall libp4est.p6est_refine_layers(p6est_::Ptr{p6est_t}, refine_recursive::Cint, refine_fn::p6est_refine_layer_t, init_fn::p6est_init_t)::Cvoid + @ccall libp4est.p6est_refine_layers( + p6est_::Ptr{p6est_t}, + refine_recursive::Cint, + refine_fn::p6est_refine_layer_t, + init_fn::p6est_init_t, + )::Cvoid end """ @@ -8439,17 +10915,25 @@ end Coarsen the columns of a sheet. ### Parameters -* `p6est`:\\[in,out\\] The forest is changed in place. -* `coarsen_recursive`:\\[in\\] Boolean to decide on recursive coarsening. -* `coarsen_fn`:\\[in\\] Callback function that returns true if a family of columns shall be coarsened -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + + - `p6est`:\\[in,out\\] The forest is changed in place. + - `coarsen_recursive`:\\[in\\] Boolean to decide on recursive coarsening. + - `coarsen_fn`:\\[in\\] Callback function that returns true if a family of columns shall be coarsened + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + ### Prototype + ```c void p6est_coarsen_columns (p6est_t * p6est, int coarsen_recursive, p6est_coarsen_column_t coarsen_fn, p6est_init_t init_fn); ``` """ function p6est_coarsen_columns(p6est_, coarsen_recursive, coarsen_fn, init_fn) - @ccall libp4est.p6est_coarsen_columns(p6est_::Ptr{p6est_t}, coarsen_recursive::Cint, coarsen_fn::p6est_coarsen_column_t, init_fn::p6est_init_t)::Cvoid + @ccall libp4est.p6est_coarsen_columns( + p6est_::Ptr{p6est_t}, + coarsen_recursive::Cint, + coarsen_fn::p6est_coarsen_column_t, + init_fn::p6est_init_t, + )::Cvoid end """ @@ -8458,17 +10942,25 @@ end Coarsen the layers of a sheet. ### Parameters -* `p6est`:\\[in,out\\] The forest is changed in place. -* `coarsen_recursive`:\\[in\\] Boolean to decide on recursive coarsening. -* `coarsen_fn`:\\[in\\] Callback function that returns true if a family of layers shall be coarsened -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + + - `p6est`:\\[in,out\\] The forest is changed in place. + - `coarsen_recursive`:\\[in\\] Boolean to decide on recursive coarsening. + - `coarsen_fn`:\\[in\\] Callback function that returns true if a family of layers shall be coarsened + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + ### Prototype + ```c void p6est_coarsen_layers (p6est_t * p6est, int coarsen_recursive, p6est_coarsen_layer_t coarsen_fn, p6est_init_t init_fn); ``` """ function p6est_coarsen_layers(p6est_, coarsen_recursive, coarsen_fn, init_fn) - @ccall libp4est.p6est_coarsen_layers(p6est_::Ptr{p6est_t}, coarsen_recursive::Cint, coarsen_fn::p6est_coarsen_layer_t, init_fn::p6est_init_t)::Cvoid + @ccall libp4est.p6est_coarsen_layers( + p6est_::Ptr{p6est_t}, + coarsen_recursive::Cint, + coarsen_fn::p6est_coarsen_layer_t, + init_fn::p6est_init_t, + )::Cvoid end """ @@ -8477,16 +10969,23 @@ end Balance a forest. ### Parameters -* `p6est`:\\[in\\] The `p6est` to be worked on. -* `btype`:\\[in\\] Balance type (face, corner or default, full). -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + + - `p6est`:\\[in\\] The `p6est` to be worked on. + - `btype`:\\[in\\] Balance type (face, corner or default, full). + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + ### Prototype + ```c void p6est_balance (p6est_t * p6est, p8est_connect_type_t btype, p6est_init_t init_fn); ``` """ function p6est_balance(p6est_, btype, init_fn) - @ccall libp4est.p6est_balance(p6est_::Ptr{p6est_t}, btype::p8est_connect_type_t, init_fn::p6est_init_t)::Cvoid + @ccall libp4est.p6est_balance( + p6est_::Ptr{p6est_t}, + btype::p8est_connect_type_t, + init_fn::p6est_init_t, + )::Cvoid end @cenum p6est_comm_tag_t::UInt32 begin @@ -8505,75 +11004,103 @@ The forest will be partitioned between processors where they each have an approx Note that `p6est`->layers and `p6est`->global_first_layers may change during this call. Address pointers referencing these objects from before [`p6est_partition`](@ref) is called become invalid. ### Parameters -* `p6est`:\\[in,out\\] The forest that will be partitioned. -* `weight_fn`:\\[in\\] A weighting function or NULL for uniform partitioning. + + - `p6est`:\\[in,out\\] The forest that will be partitioned. + - `weight_fn`:\\[in\\] A weighting function or NULL for uniform partitioning. + ### Prototype + ```c p4est_gloidx_t p6est_partition (p6est_t * p6est, p6est_weight_t weight_fn); ``` """ function p6est_partition(p6est_, weight_fn) - @ccall libp4est.p6est_partition(p6est_::Ptr{p6est_t}, weight_fn::p6est_weight_t)::p4est_gloidx_t + @ccall libp4est.p6est_partition( + p6est_::Ptr{p6est_t}, + weight_fn::p6est_weight_t, + )::p4est_gloidx_t end """ p6est_partition_correct(p6est_, num_layers_in_proc) ### Prototype + ```c void p6est_partition_correct (p6est_t * p6est, p4est_locidx_t * num_layers_in_proc); ``` """ function p6est_partition_correct(p6est_, num_layers_in_proc) - @ccall libp4est.p6est_partition_correct(p6est_::Ptr{p6est_t}, num_layers_in_proc::Ptr{p4est_locidx_t})::Cvoid + @ccall libp4est.p6est_partition_correct( + p6est_::Ptr{p6est_t}, + num_layers_in_proc::Ptr{p4est_locidx_t}, + )::Cvoid end """ p6est_partition_to_p4est_partition(p6est_, num_layers_in_proc, num_columns_in_proc) ### Prototype + ```c void p6est_partition_to_p4est_partition (p6est_t * p6est, p4est_locidx_t * num_layers_in_proc, p4est_locidx_t * num_columns_in_proc); ``` """ function p6est_partition_to_p4est_partition(p6est_, num_layers_in_proc, num_columns_in_proc) - @ccall libp4est.p6est_partition_to_p4est_partition(p6est_::Ptr{p6est_t}, num_layers_in_proc::Ptr{p4est_locidx_t}, num_columns_in_proc::Ptr{p4est_locidx_t})::Cvoid + @ccall libp4est.p6est_partition_to_p4est_partition( + p6est_::Ptr{p6est_t}, + num_layers_in_proc::Ptr{p4est_locidx_t}, + num_columns_in_proc::Ptr{p4est_locidx_t}, + )::Cvoid end """ p4est_partition_to_p6est_partition(p6est_, num_columns_in_proc, num_layers_in_proc) ### Prototype + ```c void p4est_partition_to_p6est_partition (p6est_t * p6est, p4est_locidx_t * num_columns_in_proc, p4est_locidx_t * num_layers_in_proc); ``` """ function p4est_partition_to_p6est_partition(p6est_, num_columns_in_proc, num_layers_in_proc) - @ccall libp4est.p4est_partition_to_p6est_partition(p6est_::Ptr{p6est_t}, num_columns_in_proc::Ptr{p4est_locidx_t}, num_layers_in_proc::Ptr{p4est_locidx_t})::Cvoid + @ccall libp4est.p4est_partition_to_p6est_partition( + p6est_::Ptr{p6est_t}, + num_columns_in_proc::Ptr{p4est_locidx_t}, + num_layers_in_proc::Ptr{p4est_locidx_t}, + )::Cvoid end """ p6est_partition_for_coarsening(p6est_, num_layers_in_proc) ### Prototype + ```c p4est_gloidx_t p6est_partition_for_coarsening (p6est_t * p6est, p4est_locidx_t * num_layers_in_proc); ``` """ function p6est_partition_for_coarsening(p6est_, num_layers_in_proc) - @ccall libp4est.p6est_partition_for_coarsening(p6est_::Ptr{p6est_t}, num_layers_in_proc::Ptr{p4est_locidx_t})::p4est_gloidx_t + @ccall libp4est.p6est_partition_for_coarsening( + p6est_::Ptr{p6est_t}, + num_layers_in_proc::Ptr{p4est_locidx_t}, + )::p4est_gloidx_t end """ p6est_partition_given(p6est_, num_layers_in_proc) ### Prototype + ```c p4est_gloidx_t p6est_partition_given (p6est_t * p6est, p4est_locidx_t * num_layers_in_proc); ``` """ function p6est_partition_given(p6est_, num_layers_in_proc) - @ccall libp4est.p6est_partition_given(p6est_::Ptr{p6est_t}, num_layers_in_proc::Ptr{p4est_locidx_t})::p4est_gloidx_t + @ccall libp4est.p6est_partition_given( + p6est_::Ptr{p6est_t}, + num_layers_in_proc::Ptr{p4est_locidx_t}, + )::p4est_gloidx_t end """ @@ -8582,8 +11109,11 @@ end Compute the checksum for a forest. Based on quadrant arrays only. It is independent of partition and mpisize. ### Returns + Returns the checksum on processor 0 only. 0 on other processors. + ### Prototype + ```c unsigned p6est_checksum (p6est_t * p6est); ``` @@ -8604,34 +11134,50 @@ operation that all MPI processes need to call. All processes write into the same Aborts on file errors. ### Parameters -* `filename`:\\[in\\] Name of the file to write. -* `p6est`:\\[in\\] Valid forest structure. -* `save_data`:\\[in\\] If true, the element data is saved. Otherwise, a data size of 0 is saved. + + - `filename`:\\[in\\] Name of the file to write. + - `p6est`:\\[in\\] Valid forest structure. + - `save_data`:\\[in\\] If true, the element data is saved. Otherwise, a data size of 0 is saved. + ### Prototype + ```c void p6est_save (const char *filename, p6est_t * p6est, int save_data); ``` """ function p6est_save(filename, p6est_, save_data) - @ccall libp4est.p6est_save(filename::Cstring, p6est_::Ptr{p6est_t}, save_data::Cint)::Cvoid + @ccall libp4est.p6est_save( + filename::Cstring, + p6est_::Ptr{p6est_t}, + save_data::Cint, + )::Cvoid end """ p6est_load(filename, mpicomm, data_size, load_data, user_pointer, connectivity) ### Prototype + ```c p6est_t *p6est_load (const char *filename, sc_MPI_Comm mpicomm, size_t data_size, int load_data, void *user_pointer, p6est_connectivity_t ** connectivity); ``` """ function p6est_load(filename, mpicomm, data_size, load_data, user_pointer, connectivity) - @ccall libp4est.p6est_load(filename::Cstring, mpicomm::MPI_Comm, data_size::Csize_t, load_data::Cint, user_pointer::Ptr{Cvoid}, connectivity::Ptr{Ptr{p6est_connectivity_t}})::Ptr{p6est_t} + @ccall libp4est.p6est_load( + filename::Cstring, + mpicomm::MPI_Comm, + data_size::Csize_t, + load_data::Cint, + user_pointer::Ptr{Cvoid}, + connectivity::Ptr{Ptr{p6est_connectivity_t}}, + )::Ptr{p6est_t} end """ p6est_compress_columns(p6est_) ### Prototype + ```c void p6est_compress_columns (p6est_t * p6est); ``` @@ -8644,6 +11190,7 @@ end p6est_update_offsets(p6est_) ### Prototype + ```c void p6est_update_offsets (p6est_t * p6est); ``` @@ -8656,12 +11203,35 @@ end p6est_new_ext(mpicomm, connectivity, min_quadrants, min_level, min_zlevel, num_zroot, fill_uniform, data_size, init_fn, user_pointer) ### Prototype + ```c p6est_t *p6est_new_ext (sc_MPI_Comm mpicomm, p6est_connectivity_t * connectivity, p4est_locidx_t min_quadrants, int min_level, int min_zlevel, int num_zroot, int fill_uniform, size_t data_size, p6est_init_t init_fn, void *user_pointer); ``` """ -function p6est_new_ext(mpicomm, connectivity, min_quadrants, min_level, min_zlevel, num_zroot, fill_uniform, data_size, init_fn, user_pointer) - @ccall libp4est.p6est_new_ext(mpicomm::MPI_Comm, connectivity::Ptr{p6est_connectivity_t}, min_quadrants::p4est_locidx_t, min_level::Cint, min_zlevel::Cint, num_zroot::Cint, fill_uniform::Cint, data_size::Csize_t, init_fn::p6est_init_t, user_pointer::Ptr{Cvoid})::Ptr{p6est_t} +function p6est_new_ext( + mpicomm, + connectivity, + min_quadrants, + min_level, + min_zlevel, + num_zroot, + fill_uniform, + data_size, + init_fn, + user_pointer, +) + @ccall libp4est.p6est_new_ext( + mpicomm::MPI_Comm, + connectivity::Ptr{p6est_connectivity_t}, + min_quadrants::p4est_locidx_t, + min_level::Cint, + min_zlevel::Cint, + num_zroot::Cint, + fill_uniform::Cint, + data_size::Csize_t, + init_fn::p6est_init_t, + user_pointer::Ptr{Cvoid}, + )::Ptr{p6est_t} end """ @@ -8670,17 +11240,26 @@ end Make a deep copy of a `p6est`. The connectivity is not duplicated. Copying of quadrant user data is optional. If old and new data sizes are 0, the user\\_data field is copied regardless. The inspect member of the copy is set to NULL. ### Parameters -* `copy_data`:\\[in\\] If true, data are copied. If false, data\\_size is set to 0. -* `duplicate_mpicomm`:\\[in\\] If true, MPI communicator is copied. + + - `copy_data`:\\[in\\] If true, data are copied. If false, data\\_size is set to 0. + - `duplicate_mpicomm`:\\[in\\] If true, MPI communicator is copied. + ### Returns + Returns a valid `p6est` that does not depend on the input. + ### Prototype + ```c p6est_t *p6est_copy_ext (p6est_t * input, int copy_data, int duplicate_mpicomm); ``` """ function p6est_copy_ext(input, copy_data, duplicate_mpicomm) - @ccall libp4est.p6est_copy_ext(input::Ptr{p6est_t}, copy_data::Cint, duplicate_mpicomm::MPI_Comm)::Ptr{p6est_t} + @ccall libp4est.p6est_copy_ext( + input::Ptr{p6est_t}, + copy_data::Cint, + duplicate_mpicomm::MPI_Comm, + )::Ptr{p6est_t} end """ @@ -8695,29 +11274,56 @@ This is a collective operation that all MPI processes need to call. All processe Aborts on file errors. ### Parameters -* `filename`:\\[in\\] Name of the file to write. -* `p6est`:\\[in\\] Valid forest structure. -* `save_data`:\\[in\\] If true, the element data is saved. Otherwise, a data size of 0 is saved. -* `save_partition`:\\[in\\] If false, save file as if 1 core was used. If true, save core count and partition. Advantage: Partition can be recovered on loading with same mpisize and autopartition false. Disadvantage: Makes the file depend on mpisize. Either way the file can be loaded with autopartition true. + + - `filename`:\\[in\\] Name of the file to write. + - `p6est`:\\[in\\] Valid forest structure. + - `save_data`:\\[in\\] If true, the element data is saved. Otherwise, a data size of 0 is saved. + - `save_partition`:\\[in\\] If false, save file as if 1 core was used. If true, save core count and partition. Advantage: Partition can be recovered on loading with same mpisize and autopartition false. Disadvantage: Makes the file depend on mpisize. Either way the file can be loaded with autopartition true. + ### Prototype + ```c void p6est_save_ext (const char *filename, p6est_t * p6est, int save_data, int save_partition); ``` """ function p6est_save_ext(filename, p6est_, save_data, save_partition) - @ccall libp4est.p6est_save_ext(filename::Cstring, p6est_::Ptr{p6est_t}, save_data::Cint, save_partition::Cint)::Cvoid + @ccall libp4est.p6est_save_ext( + filename::Cstring, + p6est_::Ptr{p6est_t}, + save_data::Cint, + save_partition::Cint, + )::Cvoid end """ p6est_load_ext(filename, mpicomm, data_size, load_data, autopartition, broadcasthead, user_pointer, connectivity) ### Prototype + ```c p6est_t *p6est_load_ext (const char *filename, sc_MPI_Comm mpicomm, size_t data_size, int load_data, int autopartition, int broadcasthead, void *user_pointer, p6est_connectivity_t ** connectivity); ``` """ -function p6est_load_ext(filename, mpicomm, data_size, load_data, autopartition, broadcasthead, user_pointer, connectivity) - @ccall libp4est.p6est_load_ext(filename::Cstring, mpicomm::MPI_Comm, data_size::Csize_t, load_data::Cint, autopartition::Cint, broadcasthead::Cint, user_pointer::Ptr{Cvoid}, connectivity::Ptr{Ptr{p6est_connectivity_t}})::Ptr{p6est_t} +function p6est_load_ext( + filename, + mpicomm, + data_size, + load_data, + autopartition, + broadcasthead, + user_pointer, + connectivity, +) + @ccall libp4est.p6est_load_ext( + filename::Cstring, + mpicomm::MPI_Comm, + data_size::Csize_t, + load_data::Cint, + autopartition::Cint, + broadcasthead::Cint, + user_pointer::Ptr{Cvoid}, + connectivity::Ptr{Ptr{p6est_connectivity_t}}, + )::Ptr{p6est_t} end """ @@ -8726,19 +11332,36 @@ end Horizontally refine a forest with a bounded refinement level and a replace option. ### Parameters -* `p6est`:\\[in,out\\] The forest is changed in place. -* `refine_recursive`:\\[in\\] Boolean to decide on recursive refinement. -* `maxlevel`:\\[in\\] Maximum allowed refinement level (inclusive). If this is negative the level is restricted only by the compile-time constant QMAXLEVEL in `p4est.h`. -* `refine_fn`:\\[in\\] Callback function that must return true if a quadrant shall be refined. If refine\\_recursive is true, refine\\_fn is called for every existing and newly created quadrant. Otherwise, it is called for every existing quadrant. It is possible that a refinement request made by the callback is ignored. To catch this case, you can examine whether init\\_fn or replace\\_fn gets called. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data for newly created quadrants, which is guaranteed to be allocated. This function pointer may be NULL. -* `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace; may be NULL. + + - `p6est`:\\[in,out\\] The forest is changed in place. + - `refine_recursive`:\\[in\\] Boolean to decide on recursive refinement. + - `maxlevel`:\\[in\\] Maximum allowed refinement level (inclusive). If this is negative the level is restricted only by the compile-time constant QMAXLEVEL in `p4est.h`. + - `refine_fn`:\\[in\\] Callback function that must return true if a quadrant shall be refined. If refine\\_recursive is true, refine\\_fn is called for every existing and newly created quadrant. Otherwise, it is called for every existing quadrant. It is possible that a refinement request made by the callback is ignored. To catch this case, you can examine whether init\\_fn or replace\\_fn gets called. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data for newly created quadrants, which is guaranteed to be allocated. This function pointer may be NULL. + - `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace; may be NULL. + ### Prototype + ```c void p6est_refine_columns_ext (p6est_t * p6est, int refine_recursive, int maxlevel, p6est_refine_column_t refine_fn, p6est_init_t init_fn, p6est_replace_t replace_fn); ``` """ -function p6est_refine_columns_ext(p6est_, refine_recursive, maxlevel, refine_fn, init_fn, replace_fn) - @ccall libp4est.p6est_refine_columns_ext(p6est_::Ptr{p6est_t}, refine_recursive::Cint, maxlevel::Cint, refine_fn::p6est_refine_column_t, init_fn::p6est_init_t, replace_fn::p6est_replace_t)::Cvoid +function p6est_refine_columns_ext( + p6est_, + refine_recursive, + maxlevel, + refine_fn, + init_fn, + replace_fn, +) + @ccall libp4est.p6est_refine_columns_ext( + p6est_::Ptr{p6est_t}, + refine_recursive::Cint, + maxlevel::Cint, + refine_fn::p6est_refine_column_t, + init_fn::p6est_init_t, + replace_fn::p6est_replace_t, + )::Cvoid end """ @@ -8747,19 +11370,36 @@ end Vertically refine a forest with a bounded refinement level and a replace option. ### Parameters -* `p6est`:\\[in,out\\] The forest is changed in place. -* `refine_recursive`:\\[in\\] Boolean to decide on recursive refinement. -* `maxlevel`:\\[in\\] Maximum allowed refinement level (inclusive). If this is negative the level is restricted only by the compile-time constant QMAXLEVEL in `p4est.h`. -* `refine_fn`:\\[in\\] Callback function that must return true if a quadrant shall be refined. If refine\\_recursive is true, refine\\_fn is called for every existing and newly created quadrant. Otherwise, it is called for every existing quadrant. It is possible that a refinement request made by the callback is ignored. To catch this case, you can examine whether init\\_fn or replace\\_fn gets called. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data for newly created quadrants, which is guaranteed to be allocated. This function pointer may be NULL. -* `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace; may be NULL. + + - `p6est`:\\[in,out\\] The forest is changed in place. + - `refine_recursive`:\\[in\\] Boolean to decide on recursive refinement. + - `maxlevel`:\\[in\\] Maximum allowed refinement level (inclusive). If this is negative the level is restricted only by the compile-time constant QMAXLEVEL in `p4est.h`. + - `refine_fn`:\\[in\\] Callback function that must return true if a quadrant shall be refined. If refine\\_recursive is true, refine\\_fn is called for every existing and newly created quadrant. Otherwise, it is called for every existing quadrant. It is possible that a refinement request made by the callback is ignored. To catch this case, you can examine whether init\\_fn or replace\\_fn gets called. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data for newly created quadrants, which is guaranteed to be allocated. This function pointer may be NULL. + - `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace; may be NULL. + ### Prototype + ```c void p6est_refine_layers_ext (p6est_t * p6est, int refine_recursive, int maxlevel, p6est_refine_layer_t refine_fn, p6est_init_t init_fn, p6est_replace_t replace_fn); ``` """ -function p6est_refine_layers_ext(p6est_, refine_recursive, maxlevel, refine_fn, init_fn, replace_fn) - @ccall libp4est.p6est_refine_layers_ext(p6est_::Ptr{p6est_t}, refine_recursive::Cint, maxlevel::Cint, refine_fn::p6est_refine_layer_t, init_fn::p6est_init_t, replace_fn::p6est_replace_t)::Cvoid +function p6est_refine_layers_ext( + p6est_, + refine_recursive, + maxlevel, + refine_fn, + init_fn, + replace_fn, +) + @ccall libp4est.p6est_refine_layers_ext( + p6est_::Ptr{p6est_t}, + refine_recursive::Cint, + maxlevel::Cint, + refine_fn::p6est_refine_layer_t, + init_fn::p6est_init_t, + replace_fn::p6est_replace_t, + )::Cvoid end """ @@ -8768,19 +11408,36 @@ end Horizontally coarsen a forest. ### Parameters -* `p6est`:\\[in,out\\] The forest is changed in place. -* `coarsen_recursive`:\\[in\\] Boolean to decide on recursive coarsening. -* `callback_orphans`:\\[in\\] Boolean to enable calling coarsen\\_fn even on non-families. In this case, the second quadrant pointer in the argument list of the callback is NULL, subsequent pointers are undefined, and the return value is ignored. If coarsen\\_recursive is true, it is possible that a quadrant is called once or more as an orphan and eventually becomes part of a family. -* `coarsen_fn`:\\[in\\] Callback function that returns true if a family of quadrants shall be coarsened. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. -* `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace. + + - `p6est`:\\[in,out\\] The forest is changed in place. + - `coarsen_recursive`:\\[in\\] Boolean to decide on recursive coarsening. + - `callback_orphans`:\\[in\\] Boolean to enable calling coarsen\\_fn even on non-families. In this case, the second quadrant pointer in the argument list of the callback is NULL, subsequent pointers are undefined, and the return value is ignored. If coarsen\\_recursive is true, it is possible that a quadrant is called once or more as an orphan and eventually becomes part of a family. + - `coarsen_fn`:\\[in\\] Callback function that returns true if a family of quadrants shall be coarsened. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + - `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace. + ### Prototype + ```c void p6est_coarsen_columns_ext (p6est_t * p6est, int coarsen_recursive, int callback_orphans, p6est_coarsen_column_t coarsen_fn, p6est_init_t init_fn, p6est_replace_t replace_fn); ``` """ -function p6est_coarsen_columns_ext(p6est_, coarsen_recursive, callback_orphans, coarsen_fn, init_fn, replace_fn) - @ccall libp4est.p6est_coarsen_columns_ext(p6est_::Ptr{p6est_t}, coarsen_recursive::Cint, callback_orphans::Cint, coarsen_fn::p6est_coarsen_column_t, init_fn::p6est_init_t, replace_fn::p6est_replace_t)::Cvoid +function p6est_coarsen_columns_ext( + p6est_, + coarsen_recursive, + callback_orphans, + coarsen_fn, + init_fn, + replace_fn, +) + @ccall libp4est.p6est_coarsen_columns_ext( + p6est_::Ptr{p6est_t}, + coarsen_recursive::Cint, + callback_orphans::Cint, + coarsen_fn::p6est_coarsen_column_t, + init_fn::p6est_init_t, + replace_fn::p6est_replace_t, + )::Cvoid end """ @@ -8789,19 +11446,36 @@ end Vertically coarsen a forest. ### Parameters -* `p6est`:\\[in,out\\] The forest is changed in place. -* `coarsen_recursive`:\\[in\\] Boolean to decide on recursive coarsening. -* `callback_orphans`:\\[in\\] Boolean to enable calling coarsen\\_fn even on non-families. In this case, the second quadrant pointer in the argument list of the callback is NULL, subsequent pointers are undefined, and the return value is ignored. If coarsen\\_recursive is true, it is possible that a quadrant is called once or more as an orphan and eventually becomes part of a family. -* `coarsen_fn`:\\[in\\] Callback function that returns true if a family of quadrants shall be coarsened. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. -* `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace. + + - `p6est`:\\[in,out\\] The forest is changed in place. + - `coarsen_recursive`:\\[in\\] Boolean to decide on recursive coarsening. + - `callback_orphans`:\\[in\\] Boolean to enable calling coarsen\\_fn even on non-families. In this case, the second quadrant pointer in the argument list of the callback is NULL, subsequent pointers are undefined, and the return value is ignored. If coarsen\\_recursive is true, it is possible that a quadrant is called once or more as an orphan and eventually becomes part of a family. + - `coarsen_fn`:\\[in\\] Callback function that returns true if a family of quadrants shall be coarsened. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + - `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace. + ### Prototype + ```c void p6est_coarsen_layers_ext (p6est_t * p6est, int coarsen_recursive, int callback_orphans, p6est_coarsen_layer_t coarsen_fn, p6est_init_t init_fn, p6est_replace_t replace_fn); ``` """ -function p6est_coarsen_layers_ext(p6est_, coarsen_recursive, callback_orphans, coarsen_fn, init_fn, replace_fn) - @ccall libp4est.p6est_coarsen_layers_ext(p6est_::Ptr{p6est_t}, coarsen_recursive::Cint, callback_orphans::Cint, coarsen_fn::p6est_coarsen_layer_t, init_fn::p6est_init_t, replace_fn::p6est_replace_t)::Cvoid +function p6est_coarsen_layers_ext( + p6est_, + coarsen_recursive, + callback_orphans, + coarsen_fn, + init_fn, + replace_fn, +) + @ccall libp4est.p6est_coarsen_layers_ext( + p6est_::Ptr{p6est_t}, + coarsen_recursive::Cint, + callback_orphans::Cint, + coarsen_fn::p6est_coarsen_layer_t, + init_fn::p6est_init_t, + replace_fn::p6est_replace_t, + )::Cvoid end """ @@ -8812,18 +11486,27 @@ Repartition the forest. The forest is partitioned between processors such that each processor has an approximately equal number of quadrants (or weight). ### Parameters -* `p6est`:\\[in,out\\] The forest that will be partitioned. -* `partition_for_coarsening`:\\[in\\] If true, the partition is modified to allow one level of coarsening. -* `weight_fn`:\\[in\\] A weighting function or NULL for uniform partitioning. + + - `p6est`:\\[in,out\\] The forest that will be partitioned. + - `partition_for_coarsening`:\\[in\\] If true, the partition is modified to allow one level of coarsening. + - `weight_fn`:\\[in\\] A weighting function or NULL for uniform partitioning. + ### Returns + The global number of shipped quadrants + ### Prototype + ```c p4est_gloidx_t p6est_partition_ext (p6est_t * p6est, int partition_for_coarsening, p6est_weight_t weight_fn); ``` """ function p6est_partition_ext(p6est_, partition_for_coarsening, weight_fn) - @ccall libp4est.p6est_partition_ext(p6est_::Ptr{p6est_t}, partition_for_coarsening::Cint, weight_fn::p6est_weight_t)::p4est_gloidx_t + @ccall libp4est.p6est_partition_ext( + p6est_::Ptr{p6est_t}, + partition_for_coarsening::Cint, + weight_fn::p6est_weight_t, + )::p4est_gloidx_t end """ @@ -8832,23 +11515,33 @@ end 2:1 balance the size differences of neighboring elements in a forest. ### Parameters -* `p6est`:\\[in,out\\] The `p6est` to be worked on. -* `btype`:\\[in\\] Balance type (face or corner/full). Corner balance is almost never required when discretizing a PDE; just causes smoother mesh grading. -* `max_diff`:\\[in\\] The maximum difference between the horizontal refinement level and the vertical refinement level -* `min_diff`:\\[in\\] The minimum difference between the horizontal refinement level and the vertical refinement level -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. -* `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace. + + - `p6est`:\\[in,out\\] The `p6est` to be worked on. + - `btype`:\\[in\\] Balance type (face or corner/full). Corner balance is almost never required when discretizing a PDE; just causes smoother mesh grading. + - `max_diff`:\\[in\\] The maximum difference between the horizontal refinement level and the vertical refinement level + - `min_diff`:\\[in\\] The minimum difference between the horizontal refinement level and the vertical refinement level + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + - `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace. + ### Prototype + ```c void p6est_balance_ext (p6est_t * p6est, p8est_connect_type_t btype, int max_diff, int min_diff, p6est_init_t init_fn, p6est_replace_t replace_fn); ``` """ function p6est_balance_ext(p6est_, btype, max_diff, min_diff, init_fn, replace_fn) - @ccall libp4est.p6est_balance_ext(p6est_::Ptr{p6est_t}, btype::p8est_connect_type_t, max_diff::Cint, min_diff::Cint, init_fn::p6est_init_t, replace_fn::p6est_replace_t)::Cvoid + @ccall libp4est.p6est_balance_ext( + p6est_::Ptr{p6est_t}, + btype::p8est_connect_type_t, + max_diff::Cint, + min_diff::Cint, + init_fn::p6est_init_t, + replace_fn::p6est_replace_t, + )::Cvoid end struct p8est_quadrant_data - data::NTuple{8, UInt8} + data::NTuple{8,UInt8} end function Base.getproperty(x::Ptr{p8est_quadrant_data}, f::Symbol) @@ -8878,18 +11571,18 @@ end The 3D quadrant (i.e., octant) datatype -| Field | Note | -| :---- | :------------------------------------------------- | -| x | coordinates | -| y | | -| z | | -| level | level of refinement | -| pad8 | padding | -| pad16 | | -| p | a union of additional data attached to a quadrant | +| Field | Note | +|:----- |:------------------------------------------------- | +| x | coordinates | +| y | | +| z | | +| level | level of refinement | +| pad8 | padding | +| pad16 | | +| p | a union of additional data attached to a quadrant | """ struct p8est_quadrant - data::NTuple{24, UInt8} + data::NTuple{24,UInt8} end function Base.getproperty(x::Ptr{p8est_quadrant}, f::Symbol) @@ -8914,7 +11607,9 @@ function Base.setproperty!(x::Ptr{p8est_quadrant}, f::Symbol, v) unsafe_store!(getproperty(x, f), v) end -"""The 3D quadrant (i.e., octant) datatype""" +""" +The 3D quadrant (i.e., octant) datatype +""" const p8est_quadrant_t = p8est_quadrant """ @@ -8922,38 +11617,40 @@ const p8est_quadrant_t = p8est_quadrant The `p8est` tree datatype -| Field | Note | -| :----------------- | :----------------------------------------------------------------- | -| quadrants | locally stored quadrants | -| first\\_desc | first local descendant | -| last\\_desc | last local descendant | -| quadrants\\_offset | cumulative sum over earlier trees on this processor (locals only) | -| maxlevel | highest local quadrant level | +| Field | Note | +|:------------------ |:----------------------------------------------------------------- | +| quadrants | locally stored quadrants | +| first\\_desc | first local descendant | +| last\\_desc | last local descendant | +| quadrants\\_offset | cumulative sum over earlier trees on this processor (locals only) | +| maxlevel | highest local quadrant level | """ struct p8est_tree quadrants::sc_array_t first_desc::p8est_quadrant_t last_desc::p8est_quadrant_t quadrants_offset::p4est_locidx_t - quadrants_per_level::NTuple{31, p4est_locidx_t} + quadrants_per_level::NTuple{31,p4est_locidx_t} maxlevel::Int8 end -"""The `p8est` tree datatype""" +""" +The `p8est` tree datatype +""" const p8est_tree_t = p8est_tree """ p8est_inspect -| Field | Note | -| :------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------ | -| use\\_balance\\_ranges | Use sc\\_ranges to determine the asymmetric communication pattern. If *use_balance_ranges* is false (the default), sc\\_notify is used. | -| use\\_balance\\_ranges\\_notify | If true, call both sc\\_ranges and sc\\_notify and verify consistency. Which is actually used is still determined by *use_balance_ranges*. | -| use\\_balance\\_verify | Verify sc\\_ranges and/or sc\\_notify as applicable. | -| balance\\_max\\_ranges | If positive and smaller than p8est\\_num ranges, overrides it | -| balance\\_ranges | time spent in sc\\_ranges | -| balance\\_notify | time spent in sc\\_notify | -| balance\\_notify\\_allgather | time spent in sc\\_notify\\_allgather | +| Field | Note | +|:------------------------------- |:------------------------------------------------------------------------------------------------------------------------------------------ | +| use\\_balance\\_ranges | Use sc\\_ranges to determine the asymmetric communication pattern. If *use_balance_ranges* is false (the default), sc\\_notify is used. | +| use\\_balance\\_ranges\\_notify | If true, call both sc\\_ranges and sc\\_notify and verify consistency. Which is actually used is still determined by *use_balance_ranges*. | +| use\\_balance\\_verify | Verify sc\\_ranges and/or sc\\_notify as applicable. | +| balance\\_max\\_ranges | If positive and smaller than p8est\\_num ranges, overrides it | +| balance\\_ranges | time spent in sc\\_ranges | +| balance\\_notify | time spent in sc\\_notify | +| balance\\_notify\\_allgather | time spent in sc\\_notify\\_allgather | """ struct p8est_inspect use_balance_ranges::Cint @@ -8966,8 +11663,8 @@ struct p8est_inspect balance_comm_nzpeers::Csize_t balance_B_count_in::Csize_t balance_B_count_out::Csize_t - balance_zero_sends::NTuple{2, Csize_t} - balance_zero_receives::NTuple{2, Csize_t} + balance_zero_sends::NTuple{2,Csize_t} + balance_zero_receives::NTuple{2,Csize_t} balance_A::Cdouble balance_comm::Cdouble balance_B::Cdouble @@ -8977,31 +11674,33 @@ struct p8est_inspect use_B::Cint end -"""Data pertaining to selecting, inspecting, and profiling algorithms. A pointer to this structure is hooked into the `p8est` main structure. Declared in p8est\\_extended.h. Used to profile important algorithms.""" +""" +Data pertaining to selecting, inspecting, and profiling algorithms. A pointer to this structure is hooked into the `p8est` main structure. Declared in p8est\\_extended.h. Used to profile important algorithms. +""" const p8est_inspect_t = p8est_inspect """ p8est -| Field | Note | -| :------------------------ | :--------------------------------------------------------------------------------------------------------------- | -| mpisize | number of MPI processes | -| mpirank | this process's MPI rank | -| mpicomm\\_owned | flag if communicator is owned | -| data\\_size | size of per-quadrant p.user\\_data (see [`p8est_quadrant_t`](@ref)::[`p8est_quadrant_data`](@ref)::user\\_data) | -| user\\_pointer | convenience pointer for users, never touched by `p4est` | -| revision | Gets bumped on mesh change | -| first\\_local\\_tree | 0-based index of first local tree, must be -1 for an empty processor | -| last\\_local\\_tree | 0-based index of last local tree, must be -2 for an empty processor | -| local\\_num\\_quadrants | number of quadrants on all trees on this processor | -| global\\_num\\_quadrants | number of quadrants on all trees on all processors | -| global\\_first\\_quadrant | first global quadrant index for each process and 1 beyond | -| global\\_first\\_position | first smallest possible quad for each process and 1 beyond | -| connectivity | connectivity structure, not owned | -| trees | array of all trees | -| user\\_data\\_pool | memory allocator for user data | -| quadrant\\_pool | memory allocator for temporary quadrants | -| inspect | algorithmic switches | +| Field | Note | +|:------------------------- |:--------------------------------------------------------------------------------------------------------------- | +| mpisize | number of MPI processes | +| mpirank | this process's MPI rank | +| mpicomm\\_owned | flag if communicator is owned | +| data\\_size | size of per-quadrant p.user\\_data (see [`p8est_quadrant_t`](@ref)::[`p8est_quadrant_data`](@ref)::user\\_data) | +| user\\_pointer | convenience pointer for users, never touched by `p4est` | +| revision | Gets bumped on mesh change | +| first\\_local\\_tree | 0-based index of first local tree, must be -1 for an empty processor | +| last\\_local\\_tree | 0-based index of last local tree, must be -2 for an empty processor | +| local\\_num\\_quadrants | number of quadrants on all trees on this processor | +| global\\_num\\_quadrants | number of quadrants on all trees on all processors | +| global\\_first\\_quadrant | first global quadrant index for each process and 1 beyond | +| global\\_first\\_position | first smallest possible quad for each process and 1 beyond | +| connectivity | connectivity structure, not owned | +| trees | array of all trees | +| user\\_data\\_pool | memory allocator for user data | +| quadrant\\_pool | memory allocator for temporary quadrants | +| inspect | algorithmic switches | """ struct p8est mpicomm::MPI_Comm @@ -9024,7 +11723,9 @@ struct p8est inspect::Ptr{p8est_inspect_t} end -"""The `p8est` forest datatype""" +""" +The `p8est` forest datatype +""" const p8est_t = p8est """ @@ -9033,10 +11734,15 @@ const p8est_t = p8est Calculate local memory usage of a forest structure. Not collective. The memory used on the current rank is returned. The connectivity structure is not counted since it is not owned; use p8est\\_connectivity\\_memory\\_usage (`p8est`->connectivity). ### Parameters -* `p8est`:\\[in\\] Valid forest structure. + + - `p8est`:\\[in\\] Valid forest structure. + ### Returns + Memory used in bytes. + ### Prototype + ```c size_t p8est_memory_used (p8est_t * p8est); ``` @@ -9051,10 +11757,15 @@ end Return the revision counter of the forest. Not collective, even though the revision value is the same on all ranks. A newly created forest starts with a revision counter of zero. Every refine, coarsen, partition, and balance that actually changes the mesh increases the counter by one. Operations with no effect keep the old value. ### Parameters -* `p8est`:\\[in\\] The forest must be valid. + + - `p8est`:\\[in\\] The forest must be valid. + ### Returns + Non-negative number. + ### Prototype + ```c long p8est_revision (p8est_t * p8est); ``` @@ -9068,9 +11779,10 @@ end Callback function prototype to initialize the quadrant's user data. ### Parameters -* `p8est`:\\[in\\] the forest -* `which_tree`:\\[in\\] the tree containing *quadrant* -* `quadrant`:\\[in,out\\] the quadrant to be initialized: if data\\_size > 0, the data to be initialized is at *quadrant*->p.user_data; otherwise, the non-pointer user data (such as *quadrant*->p.user_int) can be initialized + + - `p8est`:\\[in\\] the forest + - `which_tree`:\\[in\\] the tree containing *quadrant* + - `quadrant`:\\[in,out\\] the quadrant to be initialized: if data\\_size > 0, the data to be initialized is at *quadrant*->p.user_data; otherwise, the non-pointer user data (such as *quadrant*->p.user_int) can be initialized """ const p8est_init_t = Ptr{Cvoid} @@ -9079,10 +11791,13 @@ const p8est_init_t = Ptr{Cvoid} Callback function prototype to decide for refinement. ### Parameters -* `p8est`:\\[in\\] the forest -* `which_tree`:\\[in\\] the tree containing *quadrant* -* `quadrant`:\\[in\\] the quadrant that may be refined + + - `p8est`:\\[in\\] the forest + - `which_tree`:\\[in\\] the tree containing *quadrant* + - `quadrant`:\\[in\\] the quadrant that may be refined + ### Returns + nonzero if the quadrant shall be refined. """ const p8est_refine_t = Ptr{Cvoid} @@ -9092,10 +11807,13 @@ const p8est_refine_t = Ptr{Cvoid} Callback function prototype to decide for coarsening. ### Parameters -* `p8est`:\\[in\\] the forest -* `which_tree`:\\[in\\] the tree containing *quadrant* -* `quadrants`:\\[in\\] Pointers to 8 siblings in Morton ordering. + + - `p8est`:\\[in\\] the forest + - `which_tree`:\\[in\\] the tree containing *quadrant* + - `quadrants`:\\[in\\] Pointers to 8 siblings in Morton ordering. + ### Returns + nonzero if the quadrants shall be replaced with their parent. """ const p8est_coarsen_t = Ptr{Cvoid} @@ -9109,9 +11827,12 @@ Callback function prototype to calculate weights for partitioning. Global sum of weights must fit into a 64bit integer. ### Parameters -* `p8est`:\\[in\\] the forest -* `which_tree`:\\[in\\] the tree containing *quadrant* + + - `p8est`:\\[in\\] the forest + - `which_tree`:\\[in\\] the tree containing *quadrant* + ### Returns + a 32bit integer >= 0 as the quadrant weight. """ const p8est_weight_t = Ptr{Cvoid} @@ -9122,29 +11843,46 @@ const p8est_weight_t = Ptr{Cvoid} Transform a quadrant coordinate into the space spanned by tree vertices. ### Parameters -* `connectivity`:\\[in\\] Connectivity must provide the vertices. -* `treeid`:\\[in\\] Identify the tree that contains x, y, z. -* `x,`:\\[in\\] y, z Quadrant coordinates relative to treeid. -* `vxyz`:\\[out\\] Transformed coordinates in vertex space. + + - `connectivity`:\\[in\\] Connectivity must provide the vertices. + - `treeid`:\\[in\\] Identify the tree that contains x, y, z. + - `x,`:\\[in\\] y, z Quadrant coordinates relative to treeid. + - `vxyz`:\\[out\\] Transformed coordinates in vertex space. + ### Prototype + ```c void p8est_qcoord_to_vertex (p8est_connectivity_t * connectivity, p4est_topidx_t treeid, p4est_qcoord_t x, p4est_qcoord_t y, p4est_qcoord_t z, double vxyz[3]); ``` """ function p8est_qcoord_to_vertex(connectivity, treeid, x, y, z, vxyz) - @ccall libp4est.p8est_qcoord_to_vertex(connectivity::Ptr{p8est_connectivity_t}, treeid::p4est_topidx_t, x::p4est_qcoord_t, y::p4est_qcoord_t, z::p4est_qcoord_t, vxyz::Ptr{Cdouble})::Cvoid + @ccall libp4est.p8est_qcoord_to_vertex( + connectivity::Ptr{p8est_connectivity_t}, + treeid::p4est_topidx_t, + x::p4est_qcoord_t, + y::p4est_qcoord_t, + z::p4est_qcoord_t, + vxyz::Ptr{Cdouble}, + )::Cvoid end """ p8est_new(mpicomm, connectivity, data_size, init_fn, user_pointer) ### Prototype + ```c p8est_t *p8est_new (sc_MPI_Comm mpicomm, p8est_connectivity_t * connectivity, size_t data_size, p8est_init_t init_fn, void *user_pointer); ``` """ function p8est_new(mpicomm, connectivity, data_size, init_fn, user_pointer) - @ccall libp4est.p8est_new(mpicomm::MPI_Comm, connectivity::Ptr{p8est_connectivity_t}, data_size::Csize_t, init_fn::p8est_init_t, user_pointer::Ptr{Cvoid})::Ptr{p8est_t} + @ccall libp4est.p8est_new( + mpicomm::MPI_Comm, + connectivity::Ptr{p8est_connectivity_t}, + data_size::Csize_t, + init_fn::p8est_init_t, + user_pointer::Ptr{Cvoid}, + )::Ptr{p8est_t} end """ @@ -9157,6 +11895,7 @@ Destroy a `p8est`. The connectivity structure is not destroyed with the `p8est`. ### Prototype + ```c void p8est_destroy (p8est_t * p8est); ``` @@ -9171,10 +11910,15 @@ end Make a deep copy of a `p8est`. The connectivity is not duplicated. Copying of quadrant user data is optional. If old and new data sizes are 0, the user\\_data field is copied regardless. The inspect member of the copy is set to NULL. The revision counter of the copy is set to zero. ### Parameters -* `copy_data`:\\[in\\] If true, data are copied. If false, data\\_size is set to 0. + + - `copy_data`:\\[in\\] If true, data are copied. If false, data\\_size is set to 0. + ### Returns + Returns a valid `p8est` that does not depend on the input, except for borrowing the same connectivity. Its revision counter is 0. + ### Prototype + ```c p8est_t *p8est_copy (p8est_t * input, int copy_data); ``` @@ -9189,16 +11933,24 @@ end Reset user pointer and element data. When the data size is changed the quadrant data is freed and allocated. The initialization callback is invoked on each quadrant. Old user\\_data content is disregarded. ### Parameters -* `data_size`:\\[in\\] This is the size of data for each quadrant which can be zero. Then user\\_data\\_pool is set to NULL. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. May be NULL. -* `user_pointer`:\\[in\\] Assign to the user\\_pointer member of the `p8est` before init\\_fn is called the first time. + + - `data_size`:\\[in\\] This is the size of data for each quadrant which can be zero. Then user\\_data\\_pool is set to NULL. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. May be NULL. + - `user_pointer`:\\[in\\] Assign to the user\\_pointer member of the `p8est` before init\\_fn is called the first time. + ### Prototype + ```c void p8est_reset_data (p8est_t * p8est, size_t data_size, p8est_init_t init_fn, void *user_pointer); ``` """ function p8est_reset_data(p8est_, data_size, init_fn, user_pointer) - @ccall libp4est.p8est_reset_data(p8est_::Ptr{p8est_t}, data_size::Csize_t, init_fn::p8est_init_t, user_pointer::Ptr{Cvoid})::Cvoid + @ccall libp4est.p8est_reset_data( + p8est_::Ptr{p8est_t}, + data_size::Csize_t, + init_fn::p8est_init_t, + user_pointer::Ptr{Cvoid}, + )::Cvoid end """ @@ -9207,17 +11959,25 @@ end Refine a forest. ### Parameters -* `p8est`:\\[in,out\\] The forest is changed in place. -* `refine_recursive`:\\[in\\] Boolean to decide on recursive refinement. -* `refine_fn`:\\[in\\] Callback function that must return true if a quadrant shall be refined. If refine\\_recursive is true, refine\\_fn is called for every existing and newly created quadrant. Otherwise, it is called for every existing quadrant. It is possible that a refinement request made by the callback is ignored. To catch this case, you can examine whether init\\_fn gets called, or use [`p8est_refine_ext`](@ref) in p8est\\_extended.h and examine whether replace\\_fn gets called. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data of newly created quadrants, which is already allocated. This function pointer may be NULL. + + - `p8est`:\\[in,out\\] The forest is changed in place. + - `refine_recursive`:\\[in\\] Boolean to decide on recursive refinement. + - `refine_fn`:\\[in\\] Callback function that must return true if a quadrant shall be refined. If refine\\_recursive is true, refine\\_fn is called for every existing and newly created quadrant. Otherwise, it is called for every existing quadrant. It is possible that a refinement request made by the callback is ignored. To catch this case, you can examine whether init\\_fn gets called, or use [`p8est_refine_ext`](@ref) in p8est\\_extended.h and examine whether replace\\_fn gets called. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data of newly created quadrants, which is already allocated. This function pointer may be NULL. + ### Prototype + ```c void p8est_refine (p8est_t * p8est, int refine_recursive, p8est_refine_t refine_fn, p8est_init_t init_fn); ``` """ function p8est_refine(p8est_, refine_recursive, refine_fn, init_fn) - @ccall libp4est.p8est_refine(p8est_::Ptr{p8est_t}, refine_recursive::Cint, refine_fn::p8est_refine_t, init_fn::p8est_init_t)::Cvoid + @ccall libp4est.p8est_refine( + p8est_::Ptr{p8est_t}, + refine_recursive::Cint, + refine_fn::p8est_refine_t, + init_fn::p8est_init_t, + )::Cvoid end """ @@ -9226,17 +11986,25 @@ end Coarsen a forest. ### Parameters -* `p8est`:\\[in,out\\] The forest is changed in place. -* `coarsen_recursive`:\\[in\\] Boolean to decide on recursive coarsening. -* `coarsen_fn`:\\[in\\] Callback function that returns true if a family of quadrants shall be coarsened -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + + - `p8est`:\\[in,out\\] The forest is changed in place. + - `coarsen_recursive`:\\[in\\] Boolean to decide on recursive coarsening. + - `coarsen_fn`:\\[in\\] Callback function that returns true if a family of quadrants shall be coarsened + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + ### Prototype + ```c void p8est_coarsen (p8est_t * p8est, int coarsen_recursive, p8est_coarsen_t coarsen_fn, p8est_init_t init_fn); ``` """ function p8est_coarsen(p8est_, coarsen_recursive, coarsen_fn, init_fn) - @ccall libp4est.p8est_coarsen(p8est_::Ptr{p8est_t}, coarsen_recursive::Cint, coarsen_fn::p8est_coarsen_t, init_fn::p8est_init_t)::Cvoid + @ccall libp4est.p8est_coarsen( + p8est_::Ptr{p8est_t}, + coarsen_recursive::Cint, + coarsen_fn::p8est_coarsen_t, + init_fn::p8est_init_t, + )::Cvoid end """ @@ -9245,16 +12013,23 @@ end 2:1 balance the size differences of neighboring elements in a forest. ### Parameters -* `p8est`:\\[in,out\\] The `p8est` to be worked on. -* `btype`:\\[in\\] Balance type (face, edge, or corner/full). Examples: Finite volume or discontinuous Galerkin methods only require face balance. Continuous finite element methods usually require edge balance. Corner balance is almost never required mathematically; it just produces a smoother mesh grading. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + + - `p8est`:\\[in,out\\] The `p8est` to be worked on. + - `btype`:\\[in\\] Balance type (face, edge, or corner/full). Examples: Finite volume or discontinuous Galerkin methods only require face balance. Continuous finite element methods usually require edge balance. Corner balance is almost never required mathematically; it just produces a smoother mesh grading. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + ### Prototype + ```c void p8est_balance (p8est_t * p8est, p8est_connect_type_t btype, p8est_init_t init_fn); ``` """ function p8est_balance(p8est_, btype, init_fn) - @ccall libp4est.p8est_balance(p8est_::Ptr{p8est_t}, btype::p8est_connect_type_t, init_fn::p8est_init_t)::Cvoid + @ccall libp4est.p8est_balance( + p8est_::Ptr{p8est_t}, + btype::p8est_connect_type_t, + init_fn::p8est_init_t, + )::Cvoid end """ @@ -9267,16 +12042,23 @@ The forest will be partitioned between processors such that they have an approxi On one process, the function noops and does not call the weight callback. Otherwise, the weight callback is called once per quadrant in order. ### Parameters -* `p8est`:\\[in,out\\] The forest that will be partitioned. -* `allow_for_coarsening`:\\[in\\] Slightly modify partition such that quadrant families are not split between ranks. -* `weight_fn`:\\[in\\] A weighting function or NULL for uniform partitioning. When running with mpisize == 1, never called. Otherwise, called in order for all quadrants if not NULL. A weighting function with constant weight 1 on each quadrant is equivalent to weight\\_fn == NULL but other constant weightings may result in different uniform partitionings. + + - `p8est`:\\[in,out\\] The forest that will be partitioned. + - `allow_for_coarsening`:\\[in\\] Slightly modify partition such that quadrant families are not split between ranks. + - `weight_fn`:\\[in\\] A weighting function or NULL for uniform partitioning. When running with mpisize == 1, never called. Otherwise, called in order for all quadrants if not NULL. A weighting function with constant weight 1 on each quadrant is equivalent to weight\\_fn == NULL but other constant weightings may result in different uniform partitionings. + ### Prototype + ```c void p8est_partition (p8est_t * p8est, int allow_for_coarsening, p8est_weight_t weight_fn); ``` """ function p8est_partition(p8est_, allow_for_coarsening, weight_fn) - @ccall libp4est.p8est_partition(p8est_::Ptr{p8est_t}, allow_for_coarsening::Cint, weight_fn::p8est_weight_t)::Cvoid + @ccall libp4est.p8est_partition( + p8est_::Ptr{p8est_t}, + allow_for_coarsening::Cint, + weight_fn::p8est_weight_t, + )::Cvoid end """ @@ -9285,8 +12067,11 @@ end Compute the checksum for a forest. Based on quadrant arrays only. It is independent of partition and mpisize. ### Returns + Returns the checksum on processor 0 only. 0 on other processors. + ### Prototype + ```c unsigned p8est_checksum (p8est_t * p8est); ``` @@ -9301,8 +12086,11 @@ end Compute a partition-dependent checksum for a forest. ### Returns + Returns the checksum on processor 0 only. 0 on other processors. + ### Prototype + ```c unsigned p8est_checksum_partition (p8est_t * p8est); ``` @@ -9331,28 +12119,43 @@ The revision counter is not saved to the file, since that would make files diffe If `p4est` is not configured to use MPI-IO, some processes return from this function before the file is complete, in which case immediate read-access to the file may require a call to `sc_MPI_Barrier`. ### Parameters -* `filename`:\\[in\\] Name of the file to write. -* `p8est`:\\[in\\] Valid forest structure. -* `save_data`:\\[in\\] If true, the element data is saved. Otherwise, a data size of 0 is saved. + + - `filename`:\\[in\\] Name of the file to write. + - `p8est`:\\[in\\] Valid forest structure. + - `save_data`:\\[in\\] If true, the element data is saved. Otherwise, a data size of 0 is saved. + ### Prototype + ```c void p8est_save (const char *filename, p8est_t * p8est, int save_data); ``` """ function p8est_save(filename, p8est_, save_data) - @ccall libp4est.p8est_save(filename::Cstring, p8est_::Ptr{p8est_t}, save_data::Cint)::Cvoid + @ccall libp4est.p8est_save( + filename::Cstring, + p8est_::Ptr{p8est_t}, + save_data::Cint, + )::Cvoid end """ p8est_load(filename, mpicomm, data_size, load_data, user_pointer, connectivity) ### Prototype + ```c p8est_t *p8est_load (const char *filename, sc_MPI_Comm mpicomm, size_t data_size, int load_data, void *user_pointer, p8est_connectivity_t ** connectivity); ``` """ function p8est_load(filename, mpicomm, data_size, load_data, user_pointer, connectivity) - @ccall libp4est.p8est_load(filename::Cstring, mpicomm::MPI_Comm, data_size::Csize_t, load_data::Cint, user_pointer::Ptr{Cvoid}, connectivity::Ptr{Ptr{p8est_connectivity_t}})::Ptr{p8est_t} + @ccall libp4est.p8est_load( + filename::Cstring, + mpicomm::MPI_Comm, + data_size::Csize_t, + load_data::Cint, + user_pointer::Ptr{Cvoid}, + connectivity::Ptr{Ptr{p8est_connectivity_t}}, + )::Ptr{p8est_t} end """ @@ -9360,18 +12163,18 @@ end quadrants that neighbor the local domain -| Field | Note | -| :------------------------------ | :----------------------------------------------------------------------------------------------------------------------------- | -| btype | which neighbors are in the ghost layer | -| ghosts | array of [`p8est_quadrant_t`](@ref) type | -| tree\\_offsets | num\\_trees + 1 ghost indices | -| proc\\_offsets | mpisize + 1 ghost indices | -| mirrors | array of [`p8est_quadrant_t`](@ref) type | -| mirror\\_tree\\_offsets | num\\_trees + 1 mirror indices | -| mirror\\_proc\\_mirrors | indices into mirrors grouped by outside processor rank and ascending within each rank | -| mirror\\_proc\\_offsets | mpisize + 1 indices into mirror\\_proc\\_mirrors | -| mirror\\_proc\\_fronts | like mirror\\_proc\\_mirrors, but limited to the outermost octants. This is NULL until [`p8est_ghost_expand`](@ref) is called | -| mirror\\_proc\\_front\\_offsets | NULL until [`p8est_ghost_expand`](@ref) is called | +| Field | Note | +|:------------------------------- |:----------------------------------------------------------------------------------------------------------------------------- | +| btype | which neighbors are in the ghost layer | +| ghosts | array of [`p8est_quadrant_t`](@ref) type | +| tree\\_offsets | num\\_trees + 1 ghost indices | +| proc\\_offsets | mpisize + 1 ghost indices | +| mirrors | array of [`p8est_quadrant_t`](@ref) type | +| mirror\\_tree\\_offsets | num\\_trees + 1 mirror indices | +| mirror\\_proc\\_mirrors | indices into mirrors grouped by outside processor rank and ascending within each rank | +| mirror\\_proc\\_offsets | mpisize + 1 indices into mirror\\_proc\\_mirrors | +| mirror\\_proc\\_fronts | like mirror\\_proc\\_mirrors, but limited to the outermost octants. This is NULL until [`p8est_ghost_expand`](@ref) is called | +| mirror\\_proc\\_front\\_offsets | NULL until [`p8est_ghost_expand`](@ref) is called | """ struct p8est_ghost_t mpisize::Cint @@ -9396,17 +12199,25 @@ Examine if a ghost structure is valid as desribed above. Test if within a ghost- Test if the [`p4est_locidx_t`](@ref) arrays are in ascending order (for mirror\\_proc\\_mirrors ascending within each rank) ### Parameters -* `p8est`:\\[in\\] the forest. -* `ghost`:\\[in\\] Ghost layer structure. + + - `p8est`:\\[in\\] the forest. + - `ghost`:\\[in\\] Ghost layer structure. + ### Returns + true if *ghost* is valid + ### Prototype + ```c int p8est_ghost_is_valid (p8est_t * p8est, p8est_ghost_t * ghost); ``` """ function p8est_ghost_is_valid(p8est_, ghost) - @ccall libp4est.p8est_ghost_is_valid(p8est_::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t})::Cint + @ccall libp4est.p8est_ghost_is_valid( + p8est_::Ptr{p8est_t}, + ghost::Ptr{p8est_ghost_t}, + )::Cint end """ @@ -9415,10 +12226,15 @@ end Calculate the memory usage of the ghost layer. ### Parameters -* `ghost`:\\[in\\] Ghost layer structure. + + - `ghost`:\\[in\\] Ghost layer structure. + ### Returns + Memory used in bytes. + ### Prototype + ```c size_t p8est_ghost_memory_used (p8est_ghost_t * ghost); ``` @@ -9437,19 +12253,29 @@ Gets the processor id of a quadrant's owner. The quadrant can lie outside of a t Does not work for tree edge or corner neighbors. ### Parameters -* `p8est`:\\[in\\] The forest in which to search for a quadrant. -* `treeid`:\\[in\\] The tree to which the quadrant belongs. -* `face`:\\[in\\] Supply a face direction if known, or -1 otherwise. -* `q`:\\[in\\] The quadrant that is being searched for. + + - `p8est`:\\[in\\] The forest in which to search for a quadrant. + - `treeid`:\\[in\\] The tree to which the quadrant belongs. + - `face`:\\[in\\] Supply a face direction if known, or -1 otherwise. + - `q`:\\[in\\] The quadrant that is being searched for. + ### Returns + Processor id of the owner or -1 if the quadrant lies outside of the mesh. + ### Prototype + ```c int p8est_quadrant_find_owner (p8est_t * p8est, p4est_topidx_t treeid, int face, const p8est_quadrant_t * q); ``` """ function p8est_quadrant_find_owner(p8est_, treeid, face, q) - @ccall libp4est.p8est_quadrant_find_owner(p8est_::Ptr{p8est_t}, treeid::p4est_topidx_t, face::Cint, q::Ptr{p8est_quadrant_t})::Cint + @ccall libp4est.p8est_quadrant_find_owner( + p8est_::Ptr{p8est_t}, + treeid::p4est_topidx_t, + face::Cint, + q::Ptr{p8est_quadrant_t}, + )::Cint end """ @@ -9460,17 +12286,25 @@ Builds the ghost layer. This will gather the quadrants from each neighboring proc to build one layer of face, edge and corner based ghost elements around the ones they own. ### Parameters -* `p8est`:\\[in\\] The forest for which the ghost layer will be generated. -* `btype`:\\[in\\] Which ghosts to include (across face, edge, or corner/full). + + - `p8est`:\\[in\\] The forest for which the ghost layer will be generated. + - `btype`:\\[in\\] Which ghosts to include (across face, edge, or corner/full). + ### Returns + A fully initialized ghost layer. + ### Prototype + ```c p8est_ghost_t *p8est_ghost_new (p8est_t * p8est, p8est_connect_type_t btype); ``` """ function p8est_ghost_new(p8est_, btype) - @ccall libp4est.p8est_ghost_new(p8est_::Ptr{p8est_t}, btype::p8est_connect_type_t)::Ptr{p8est_ghost_t} + @ccall libp4est.p8est_ghost_new( + p8est_::Ptr{p8est_t}, + btype::p8est_connect_type_t, + )::Ptr{p8est_ghost_t} end """ @@ -9479,6 +12313,7 @@ end Frees all memory used for the ghost layer. ### Prototype + ```c void p8est_ghost_destroy (p8est_ghost_t * ghost); ``` @@ -9493,19 +12328,29 @@ end Conduct binary search for exact match on a range of the ghost layer. ### Parameters -* `ghost`:\\[in\\] The ghost layer. -* `which_proc`:\\[in\\] The owner of the searched quadrant. Can be -1. -* `which_tree`:\\[in\\] The tree of the searched quadrant. Can be -1. -* `q`:\\[in\\] Valid quadrant is searched in the ghost layer. + + - `ghost`:\\[in\\] The ghost layer. + - `which_proc`:\\[in\\] The owner of the searched quadrant. Can be -1. + - `which_tree`:\\[in\\] The tree of the searched quadrant. Can be -1. + - `q`:\\[in\\] Valid quadrant is searched in the ghost layer. + ### Returns + Offset in the ghost layer, or -1 if not found. + ### Prototype + ```c ssize_t p8est_ghost_bsearch (p8est_ghost_t * ghost, int which_proc, p4est_topidx_t which_tree, const p8est_quadrant_t * q); ``` """ function p8est_ghost_bsearch(ghost, which_proc, which_tree, q) - @ccall libp4est.p8est_ghost_bsearch(ghost::Ptr{p8est_ghost_t}, which_proc::Cint, which_tree::p4est_topidx_t, q::Ptr{p8est_quadrant_t})::Cssize_t + @ccall libp4est.p8est_ghost_bsearch( + ghost::Ptr{p8est_ghost_t}, + which_proc::Cint, + which_tree::p4est_topidx_t, + q::Ptr{p8est_quadrant_t}, + )::Cssize_t end """ @@ -9514,19 +12359,29 @@ end Conduct binary search for ancestor on range of the ghost layer. ### Parameters -* `ghost`:\\[in\\] The ghost layer. -* `which_proc`:\\[in\\] The owner of the searched quadrant. Can be -1. -* `which_tree`:\\[in\\] The tree of the searched quadrant. Can be -1. -* `q`:\\[in\\] Valid quadrant's ancestor is searched. + + - `ghost`:\\[in\\] The ghost layer. + - `which_proc`:\\[in\\] The owner of the searched quadrant. Can be -1. + - `which_tree`:\\[in\\] The tree of the searched quadrant. Can be -1. + - `q`:\\[in\\] Valid quadrant's ancestor is searched. + ### Returns + Offset in the ghost layer, or -1 if not found. + ### Prototype + ```c ssize_t p8est_ghost_tree_contains (p8est_ghost_t * ghost, int which_proc, p4est_topidx_t which_tree, const p8est_quadrant_t * q); ``` """ function p8est_ghost_tree_contains(ghost, which_proc, which_tree, q) - @ccall libp4est.p8est_ghost_tree_contains(ghost::Ptr{p8est_ghost_t}, which_proc::Cint, which_tree::p4est_topidx_t, q::Ptr{p8est_quadrant_t})::Cssize_t + @ccall libp4est.p8est_ghost_tree_contains( + ghost::Ptr{p8est_ghost_t}, + which_proc::Cint, + which_tree::p4est_topidx_t, + q::Ptr{p8est_quadrant_t}, + )::Cssize_t end """ @@ -9537,22 +12392,35 @@ Checks if quadrant exists in the local forest or the ghost layer. For quadrants across tree boundaries it checks if the quadrant exists across any face, but not across edges or corners. ### Parameters -* `p8est`:\\[in\\] The forest in which to search for *q*. -* `ghost`:\\[in\\] The ghost layer in which to search for *q*. -* `treeid`:\\[in\\] The tree to which *q* belongs. -* `q`:\\[in\\] The quadrant that is being searched for. -* `face`:\\[in,out\\] On input, face id across which *q* was created. On output, the neighbor's face number augmented by orientation, so face is in 0..23. -* `hang`:\\[in,out\\] If not NULL, signals that q is bigger than the quadrant it came from. The child id of that originating quadrant is passed into hang. On output, hang holds the hanging face number of *q* that is in contact with its originator. -* `owner_rank`:\\[out\\] Filled with the rank of the owner if it is found and undefined otherwise. + + - `p8est`:\\[in\\] The forest in which to search for *q*. + - `ghost`:\\[in\\] The ghost layer in which to search for *q*. + - `treeid`:\\[in\\] The tree to which *q* belongs. + - `q`:\\[in\\] The quadrant that is being searched for. + - `face`:\\[in,out\\] On input, face id across which *q* was created. On output, the neighbor's face number augmented by orientation, so face is in 0..23. + - `hang`:\\[in,out\\] If not NULL, signals that q is bigger than the quadrant it came from. The child id of that originating quadrant is passed into hang. On output, hang holds the hanging face number of *q* that is in contact with its originator. + - `owner_rank`:\\[out\\] Filled with the rank of the owner if it is found and undefined otherwise. + ### Returns + Returns the local number of *q* if the quadrant exists in the local forest or in the ghost\\_layer. Otherwise, returns -2 for a domain boundary and -1 if not found. + ### Prototype + ```c p4est_locidx_t p8est_face_quadrant_exists (p8est_t * p8est, p8est_ghost_t * ghost, p4est_topidx_t treeid, const p8est_quadrant_t * q, int *face, int *hang, int *owner_rank); ``` """ function p8est_face_quadrant_exists(p8est_, ghost, treeid, q, face, hang, owner_rank) - @ccall libp4est.p8est_face_quadrant_exists(p8est_::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t}, treeid::p4est_topidx_t, q::Ptr{p8est_quadrant_t}, face::Ptr{Cint}, hang::Ptr{Cint}, owner_rank::Ptr{Cint})::p4est_locidx_t + @ccall libp4est.p8est_face_quadrant_exists( + p8est_::Ptr{p8est_t}, + ghost::Ptr{p8est_ghost_t}, + treeid::p4est_topidx_t, + q::Ptr{p8est_quadrant_t}, + face::Ptr{Cint}, + hang::Ptr{Cint}, + owner_rank::Ptr{Cint}, + )::p4est_locidx_t end """ @@ -9563,22 +12431,35 @@ Checks if quadrant exists in the local forest or the ghost layer. For quadrants across tree corners it checks if the quadrant exists in any of the corner neighbors, thus it can execute multiple queries. ### Parameters -* `p8est`:\\[in\\] The forest in which to search for *q* -* `ghost`:\\[in\\] The ghost layer in which to search for *q* -* `treeid`:\\[in\\] The tree to which *q* belongs (can be extended). -* `q`:\\[in\\] The quadrant that is being searched for. -* `exists_arr`:\\[in,out\\] Must exist and be of of elem\\_size = sizeof (int) for inter-tree corner cases. Is resized by this function to one entry for each corner search and set to true/false depending on its existence in the local forest or ghost\\_layer. -* `rproc_arr`:\\[in,out\\] If not NULL is filled with one rank per query. -* `rquad_arr`:\\[in,out\\] If not NULL is filled with one quadrant per query. Its piggy3 member is defined as well. + + - `p8est`:\\[in\\] The forest in which to search for *q* + - `ghost`:\\[in\\] The ghost layer in which to search for *q* + - `treeid`:\\[in\\] The tree to which *q* belongs (can be extended). + - `q`:\\[in\\] The quadrant that is being searched for. + - `exists_arr`:\\[in,out\\] Must exist and be of of elem\\_size = sizeof (int) for inter-tree corner cases. Is resized by this function to one entry for each corner search and set to true/false depending on its existence in the local forest or ghost\\_layer. + - `rproc_arr`:\\[in,out\\] If not NULL is filled with one rank per query. + - `rquad_arr`:\\[in,out\\] If not NULL is filled with one quadrant per query. Its piggy3 member is defined as well. + ### Returns + true if the quadrant exists in the local forest or in the ghost\\_layer, and false if doesn't exist in either. + ### Prototype + ```c int p8est_quadrant_exists (p8est_t * p8est, p8est_ghost_t * ghost, p4est_topidx_t treeid, const p8est_quadrant_t * q, sc_array_t * exists_arr, sc_array_t * rproc_arr, sc_array_t * rquad_arr); ``` """ function p8est_quadrant_exists(p8est_, ghost, treeid, q, exists_arr, rproc_arr, rquad_arr) - @ccall libp4est.p8est_quadrant_exists(p8est_::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t}, treeid::p4est_topidx_t, q::Ptr{p8est_quadrant_t}, exists_arr::Ptr{sc_array_t}, rproc_arr::Ptr{sc_array_t}, rquad_arr::Ptr{sc_array_t})::Cint + @ccall libp4est.p8est_quadrant_exists( + p8est_::Ptr{p8est_t}, + ghost::Ptr{p8est_ghost_t}, + treeid::p4est_topidx_t, + q::Ptr{p8est_quadrant_t}, + exists_arr::Ptr{sc_array_t}, + rproc_arr::Ptr{sc_array_t}, + rquad_arr::Ptr{sc_array_t}, + )::Cint end """ @@ -9589,17 +12470,25 @@ Check a forest to see if it is balanced. This function builds the ghost layer and discards it when done. ### Parameters -* `p8est`:\\[in\\] The `p8est` to be tested. -* `btype`:\\[in\\] Balance type (face, edge, corner or default, full). + + - `p8est`:\\[in\\] The `p8est` to be tested. + - `btype`:\\[in\\] Balance type (face, edge, corner or default, full). + ### Returns + Returns true if balanced, false otherwise. + ### Prototype + ```c int p8est_is_balanced (p8est_t * p8est, p8est_connect_type_t btype); ``` """ function p8est_is_balanced(p8est_, btype) - @ccall libp4est.p8est_is_balanced(p8est_::Ptr{p8est_t}, btype::p8est_connect_type_t)::Cint + @ccall libp4est.p8est_is_balanced( + p8est_::Ptr{p8est_t}, + btype::p8est_connect_type_t, + )::Cint end """ @@ -9608,17 +12497,25 @@ end Compute the parallel checksum of a ghost layer. ### Parameters -* `p8est`:\\[in\\] The MPI information of this `p8est` will be used. -* `ghost`:\\[in\\] A ghost layer obtained from the `p8est`. + + - `p8est`:\\[in\\] The MPI information of this `p8est` will be used. + - `ghost`:\\[in\\] A ghost layer obtained from the `p8est`. + ### Returns + Parallel checksum on rank 0, 0 otherwise. + ### Prototype + ```c unsigned p8est_ghost_checksum (p8est_t * p8est, p8est_ghost_t * ghost); ``` """ function p8est_ghost_checksum(p8est_, ghost) - @ccall libp4est.p8est_ghost_checksum(p8est_::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t})::Cuint + @ccall libp4est.p8est_ghost_checksum( + p8est_::Ptr{p8est_t}, + ghost::Ptr{p8est_ghost_t}, + )::Cuint end """ @@ -9627,16 +12524,23 @@ end Transfer data for local quadrants that are ghosts to other processors. Send the data stored in the quadrant's user\\_data. This is either the pointer variable itself if `p8est`->data_size is 0, or the content of the referenced memory field if `p8est`->data\\_size is positive. ### Parameters -* `p8est`:\\[in\\] The forest used for reference. -* `ghost`:\\[in\\] The ghost layer used for reference. -* `ghost_data`:\\[in,out\\] Pre-allocated contiguous data for all ghost quadrants in sequence. If `p8est`->data\\_size is 0, must at least hold sizeof (void *) bytes for each, otherwise `p8est`->data\\_size each. + + - `p8est`:\\[in\\] The forest used for reference. + - `ghost`:\\[in\\] The ghost layer used for reference. + - `ghost_data`:\\[in,out\\] Pre-allocated contiguous data for all ghost quadrants in sequence. If `p8est`->data\\_size is 0, must at least hold sizeof (void *) bytes for each, otherwise `p8est`->data\\_size each. + ### Prototype + ```c void p8est_ghost_exchange_data (p8est_t * p8est, p8est_ghost_t * ghost, void *ghost_data); ``` """ function p8est_ghost_exchange_data(p8est_, ghost, ghost_data) - @ccall libp4est.p8est_ghost_exchange_data(p8est_::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t}, ghost_data::Ptr{Cvoid})::Cvoid + @ccall libp4est.p8est_ghost_exchange_data( + p8est_::Ptr{p8est_t}, + ghost::Ptr{p8est_ghost_t}, + ghost_data::Ptr{Cvoid}, + )::Cvoid end """ @@ -9644,12 +12548,12 @@ end Transient storage for asynchronous ghost exchange. -| Field | Note | -| :---------- | :--------------------------------------------- | -| is\\_custom | False for [`p8est_ghost_exchange_data`](@ref) | -| is\\_levels | Are we restricted to levels or not | -| minlevel | Meaningful with is\\_levels | -| maxlevel | | +| Field | Note | +|:----------- |:--------------------------------------------- | +| is\\_custom | False for [`p8est_ghost_exchange_data`](@ref) | +| is\\_levels | Are we restricted to levels or not | +| minlevel | Meaningful with is\\_levels | +| maxlevel | | """ struct p8est_ghost_exchange is_custom::Cint @@ -9668,7 +12572,9 @@ struct p8est_ghost_exchange rbuffers::sc_array_t end -"""Transient storage for asynchronous ghost exchange.""" +""" +Transient storage for asynchronous ghost exchange. +""" const p8est_ghost_exchange_t = p8est_ghost_exchange """ @@ -9677,16 +12583,25 @@ const p8est_ghost_exchange_t = p8est_ghost_exchange Begin an asynchronous ghost data exchange by posting messages. The arguments are identical to [`p8est_ghost_exchange_data`](@ref). The return type is always non-NULL and must be passed to [`p8est_ghost_exchange_data_end`](@ref) to complete the exchange. The ghost data must not be accessed before completion. ### Parameters -* `ghost_data`:\\[in,out\\] Must stay alive into the completion call. + + - `ghost_data`:\\[in,out\\] Must stay alive into the completion call. + ### Returns + Transient storage for messages in progress. + ### Prototype + ```c p8est_ghost_exchange_t *p8est_ghost_exchange_data_begin (p8est_t * p8est, p8est_ghost_t * ghost, void *ghost_data); ``` """ function p8est_ghost_exchange_data_begin(p8est_, ghost, ghost_data) - @ccall libp4est.p8est_ghost_exchange_data_begin(p8est_::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t}, ghost_data::Ptr{Cvoid})::Ptr{p8est_ghost_exchange_t} + @ccall libp4est.p8est_ghost_exchange_data_begin( + p8est_::Ptr{p8est_t}, + ghost::Ptr{p8est_ghost_t}, + ghost_data::Ptr{Cvoid}, + )::Ptr{p8est_ghost_exchange_t} end """ @@ -9695,8 +12610,11 @@ end Complete an asynchronous ghost data exchange. This function waits for all pending MPI communications. ### Parameters -* `exc`:\\[in,out\\] Created ONLY by [`p8est_ghost_exchange_data_begin`](@ref). It is deallocated before this function returns. + + - `exc`:\\[in,out\\] Created ONLY by [`p8est_ghost_exchange_data_begin`](@ref). It is deallocated before this function returns. + ### Prototype + ```c void p8est_ghost_exchange_data_end (p8est_ghost_exchange_t * exc); ``` @@ -9711,18 +12629,27 @@ end Transfer data for local quadrants that are ghosts to other processors. The data size is the same for all quadrants and can be chosen arbitrarily. ### Parameters -* `p8est`:\\[in\\] The forest used for reference. -* `ghost`:\\[in\\] The ghost layer used for reference. -* `data_size`:\\[in\\] The data size to transfer per quadrant. -* `mirror_data`:\\[in\\] One data pointer per mirror quadrant. -* `ghost_data`:\\[in,out\\] Pre-allocated contiguous data for all ghosts in sequence, which must hold at least `data_size` for each ghost. + + - `p8est`:\\[in\\] The forest used for reference. + - `ghost`:\\[in\\] The ghost layer used for reference. + - `data_size`:\\[in\\] The data size to transfer per quadrant. + - `mirror_data`:\\[in\\] One data pointer per mirror quadrant. + - `ghost_data`:\\[in,out\\] Pre-allocated contiguous data for all ghosts in sequence, which must hold at least `data_size` for each ghost. + ### Prototype + ```c void p8est_ghost_exchange_custom (p8est_t * p8est, p8est_ghost_t * ghost, size_t data_size, void **mirror_data, void *ghost_data); ``` """ function p8est_ghost_exchange_custom(p8est_, ghost, data_size, mirror_data, ghost_data) - @ccall libp4est.p8est_ghost_exchange_custom(p8est_::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t}, data_size::Csize_t, mirror_data::Ptr{Ptr{Cvoid}}, ghost_data::Ptr{Cvoid})::Cvoid + @ccall libp4est.p8est_ghost_exchange_custom( + p8est_::Ptr{p8est_t}, + ghost::Ptr{p8est_ghost_t}, + data_size::Csize_t, + mirror_data::Ptr{Ptr{Cvoid}}, + ghost_data::Ptr{Cvoid}, + )::Cvoid end """ @@ -9731,17 +12658,34 @@ end Begin an asynchronous ghost data exchange by posting messages. The arguments are identical to [`p8est_ghost_exchange_custom`](@ref). The return type is always non-NULL and must be passed to [`p8est_ghost_exchange_custom_end`](@ref) to complete the exchange. The ghost data must not be accessed before completion. The mirror data can be safely discarded right after this function returns since it is copied into internal send buffers. ### Parameters -* `mirror_data`:\\[in\\] Not required to stay alive any longer. -* `ghost_data`:\\[in,out\\] Must stay alive into the completion call. + + - `mirror_data`:\\[in\\] Not required to stay alive any longer. + - `ghost_data`:\\[in,out\\] Must stay alive into the completion call. + ### Returns + Transient storage for messages in progress. + ### Prototype + ```c p8est_ghost_exchange_t *p8est_ghost_exchange_custom_begin (p8est_t * p8est, p8est_ghost_t * ghost, size_t data_size, void **mirror_data, void *ghost_data); ``` """ -function p8est_ghost_exchange_custom_begin(p8est_, ghost, data_size, mirror_data, ghost_data) - @ccall libp4est.p8est_ghost_exchange_custom_begin(p8est_::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t}, data_size::Csize_t, mirror_data::Ptr{Ptr{Cvoid}}, ghost_data::Ptr{Cvoid})::Ptr{p8est_ghost_exchange_t} +function p8est_ghost_exchange_custom_begin( + p8est_, + ghost, + data_size, + mirror_data, + ghost_data, +) + @ccall libp4est.p8est_ghost_exchange_custom_begin( + p8est_::Ptr{p8est_t}, + ghost::Ptr{p8est_ghost_t}, + data_size::Csize_t, + mirror_data::Ptr{Ptr{Cvoid}}, + ghost_data::Ptr{Cvoid}, + )::Ptr{p8est_ghost_exchange_t} end """ @@ -9750,8 +12694,11 @@ end Complete an asynchronous ghost data exchange. This function waits for all pending MPI communications. ### Parameters -* `Data`:\\[in,out\\] created ONLY by [`p8est_ghost_exchange_custom_begin`](@ref). It is deallocated before this function returns. + + - `Data`:\\[in,out\\] created ONLY by [`p8est_ghost_exchange_custom_begin`](@ref). It is deallocated before this function returns. + ### Prototype + ```c void p8est_ghost_exchange_custom_end (p8est_ghost_exchange_t * exc); ``` @@ -9766,20 +12713,39 @@ end Transfer data for local quadrants that are ghosts to other processors. The data size is the same for all quadrants and can be chosen arbitrarily. This function restricts the transfer to a range of refinement levels. The memory for quadrants outside the level range is not dereferenced. ### Parameters -* `p8est`:\\[in\\] The forest used for reference. -* `ghost`:\\[in\\] The ghost layer used for reference. -* `minlevel`:\\[in\\] Level of the largest quads to be exchanged. Use <= 0 for no restriction. -* `maxlevel`:\\[in\\] Level of the smallest quads to be exchanged. Use >= `P8EST_QMAXLEVEL` for no restriction. -* `data_size`:\\[in\\] The data size to transfer per quadrant. -* `mirror_data`:\\[in\\] One data pointer per mirror quadrant as input. -* `ghost_data`:\\[in,out\\] Pre-allocated contiguous data for all ghosts in sequence, which must hold at least `data_size` for each ghost. + + - `p8est`:\\[in\\] The forest used for reference. + - `ghost`:\\[in\\] The ghost layer used for reference. + - `minlevel`:\\[in\\] Level of the largest quads to be exchanged. Use <= 0 for no restriction. + - `maxlevel`:\\[in\\] Level of the smallest quads to be exchanged. Use >= `P8EST_QMAXLEVEL` for no restriction. + - `data_size`:\\[in\\] The data size to transfer per quadrant. + - `mirror_data`:\\[in\\] One data pointer per mirror quadrant as input. + - `ghost_data`:\\[in,out\\] Pre-allocated contiguous data for all ghosts in sequence, which must hold at least `data_size` for each ghost. + ### Prototype + ```c void p8est_ghost_exchange_custom_levels (p8est_t * p8est, p8est_ghost_t * ghost, int minlevel, int maxlevel, size_t data_size, void **mirror_data, void *ghost_data); ``` """ -function p8est_ghost_exchange_custom_levels(p8est_, ghost, minlevel, maxlevel, data_size, mirror_data, ghost_data) - @ccall libp4est.p8est_ghost_exchange_custom_levels(p8est_::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t}, minlevel::Cint, maxlevel::Cint, data_size::Csize_t, mirror_data::Ptr{Ptr{Cvoid}}, ghost_data::Ptr{Cvoid})::Cvoid +function p8est_ghost_exchange_custom_levels( + p8est_, + ghost, + minlevel, + maxlevel, + data_size, + mirror_data, + ghost_data, +) + @ccall libp4est.p8est_ghost_exchange_custom_levels( + p8est_::Ptr{p8est_t}, + ghost::Ptr{p8est_ghost_t}, + minlevel::Cint, + maxlevel::Cint, + data_size::Csize_t, + mirror_data::Ptr{Ptr{Cvoid}}, + ghost_data::Ptr{Cvoid}, + )::Cvoid end """ @@ -9788,17 +12754,38 @@ end Begin an asynchronous ghost data exchange by posting messages. The arguments are identical to [`p8est_ghost_exchange_custom_levels`](@ref). The return type is always non-NULL and must be passed to [`p8est_ghost_exchange_custom_levels_end`](@ref) to complete the exchange. The ghost data must not be accessed before completion. The mirror data can be safely discarded right after this function returns since it is copied into internal send buffers. ### Parameters -* `mirror_data`:\\[in\\] Not required to stay alive any longer. -* `ghost_data`:\\[in,out\\] Must stay alive into the completion call. + + - `mirror_data`:\\[in\\] Not required to stay alive any longer. + - `ghost_data`:\\[in,out\\] Must stay alive into the completion call. + ### Returns + Transient storage for messages in progress. + ### Prototype + ```c p8est_ghost_exchange_t *p8est_ghost_exchange_custom_levels_begin (p8est_t * p8est, p8est_ghost_t * ghost, int minlevel, int maxlevel, size_t data_size, void **mirror_data, void *ghost_data); ``` """ -function p8est_ghost_exchange_custom_levels_begin(p8est_, ghost, minlevel, maxlevel, data_size, mirror_data, ghost_data) - @ccall libp4est.p8est_ghost_exchange_custom_levels_begin(p8est_::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t}, minlevel::Cint, maxlevel::Cint, data_size::Csize_t, mirror_data::Ptr{Ptr{Cvoid}}, ghost_data::Ptr{Cvoid})::Ptr{p8est_ghost_exchange_t} +function p8est_ghost_exchange_custom_levels_begin( + p8est_, + ghost, + minlevel, + maxlevel, + data_size, + mirror_data, + ghost_data, +) + @ccall libp4est.p8est_ghost_exchange_custom_levels_begin( + p8est_::Ptr{p8est_t}, + ghost::Ptr{p8est_ghost_t}, + minlevel::Cint, + maxlevel::Cint, + data_size::Csize_t, + mirror_data::Ptr{Ptr{Cvoid}}, + ghost_data::Ptr{Cvoid}, + )::Ptr{p8est_ghost_exchange_t} end """ @@ -9807,14 +12794,19 @@ end Complete an asynchronous ghost data exchange. This function waits for all pending MPI communications. ### Parameters -* `exc`:\\[in,out\\] created ONLY by [`p8est_ghost_exchange_custom_levels_begin`](@ref). It is deallocated before this function returns. + + - `exc`:\\[in,out\\] created ONLY by [`p8est_ghost_exchange_custom_levels_begin`](@ref). It is deallocated before this function returns. + ### Prototype + ```c void p8est_ghost_exchange_custom_levels_end (p8est_ghost_exchange_t * exc); ``` """ function p8est_ghost_exchange_custom_levels_end(exc) - @ccall libp4est.p8est_ghost_exchange_custom_levels_end(exc::Ptr{p8est_ghost_exchange_t})::Cvoid + @ccall libp4est.p8est_ghost_exchange_custom_levels_end( + exc::Ptr{p8est_ghost_exchange_t}, + )::Cvoid end """ @@ -9823,15 +12815,21 @@ end Expand the size of the ghost layer and mirrors by one additional layer of adjacency. ### Parameters -* `p8est`:\\[in\\] The forest from which the ghost layer was generated. -* `ghost`:\\[in,out\\] The ghost layer to be expanded. + + - `p8est`:\\[in\\] The forest from which the ghost layer was generated. + - `ghost`:\\[in,out\\] The ghost layer to be expanded. + ### Prototype + ```c void p8est_ghost_expand (p8est_t * p8est, p8est_ghost_t * ghost); ``` """ function p8est_ghost_expand(p8est_, ghost) - @ccall libp4est.p8est_ghost_expand(p8est_::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t})::Cvoid + @ccall libp4est.p8est_ghost_expand( + p8est_::Ptr{p8est_t}, + ghost::Ptr{p8est_ghost_t}, + )::Cvoid end """ @@ -9861,19 +12859,19 @@ Corners with no diagonal neighbor at all are assigned the value -3. This only ha TODO: In case of an inter-tree neighbor relation in a brick-like situation (one same-size neighbor, diagonally opposite edge/corner), use the same encoding as for edges/corners within a tree. -| Field | Note | -| :------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| quad\\_to\\_tree | tree index for each local quad. Is NULL by default, but may be enabled by p8est_mesh_new_ext. | -| ghost\\_to\\_proc | processor for each ghost quad | -| quad\\_to\\_quad | one index for each of the 6 faces | -| quad\\_to\\_face | encodes orientation/2:1 status | -| quad\\_to\\_half | stores half-size neighbors | -| quad\\_level | Stores lists of per-level quads. The array has entries indexed by 0..`P4EST_QMAXLEVEL` inclusive that are arrays of local quadrant ids. Is NULL by default, but may be enabled by p8est_mesh_new_ext. | -| local\\_num\\_edges | unsame-size and tree-boundary edges | -| quad\\_to\\_edge | 12 indices for each local quad | -| edge\\_offset | local\\_num\\_edges + 1 entries | -| edge\\_quad | edge\\_offset indexes into this | -| edge\\_edge | and this one too (type int8\\_t) | +| Field | Note | +|:------------------- |:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| quad\\_to\\_tree | tree index for each local quad. Is NULL by default, but may be enabled by p8est_mesh_new_ext. | +| ghost\\_to\\_proc | processor for each ghost quad | +| quad\\_to\\_quad | one index for each of the 6 faces | +| quad\\_to\\_face | encodes orientation/2:1 status | +| quad\\_to\\_half | stores half-size neighbors | +| quad\\_level | Stores lists of per-level quads. The array has entries indexed by 0..`P4EST_QMAXLEVEL` inclusive that are arrays of local quadrant ids. Is NULL by default, but may be enabled by p8est_mesh_new_ext. | +| local\\_num\\_edges | unsame-size and tree-boundary edges | +| quad\\_to\\_edge | 12 indices for each local quad | +| edge\\_offset | local\\_num\\_edges + 1 entries | +| edge\\_quad | edge\\_offset indexes into this | +| edge\\_edge | and this one too (type int8\\_t) | """ struct p8est_mesh_t local_num_quadrants::p4est_locidx_t @@ -9919,10 +12917,15 @@ end Calculate the memory usage of the mesh structure. ### Parameters -* `mesh`:\\[in\\] Mesh structure. + + - `mesh`:\\[in\\] Mesh structure. + ### Returns + Memory used in bytes. + ### Prototype + ```c size_t p8est_mesh_memory_used (p8est_mesh_t * mesh); ``` @@ -9937,18 +12940,27 @@ end Create a p8est\\_mesh structure. This function does not populate the quad\\_to\\_tree and quad\\_level fields. To populate them, use p8est_mesh_new_ext. ### Parameters -* `p8est`:\\[in\\] A forest that is fully 2:1 balanced. -* `ghost`:\\[in\\] The ghost layer created from the provided `p4est`. -* `btype`:\\[in\\] Determines the highest codimension of neighbors. + + - `p8est`:\\[in\\] A forest that is fully 2:1 balanced. + - `ghost`:\\[in\\] The ghost layer created from the provided `p4est`. + - `btype`:\\[in\\] Determines the highest codimension of neighbors. + ### Returns + A fully allocated mesh structure. + ### Prototype + ```c p8est_mesh_t *p8est_mesh_new (p8est_t * p8est, p8est_ghost_t * ghost, p8est_connect_type_t btype); ``` """ function p8est_mesh_new(p8est_, ghost, btype) - @ccall libp4est.p8est_mesh_new(p8est_::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t}, btype::p8est_connect_type_t)::Ptr{p8est_mesh_t} + @ccall libp4est.p8est_mesh_new( + p8est_::Ptr{p8est_t}, + ghost::Ptr{p8est_ghost_t}, + btype::p8est_connect_type_t, + )::Ptr{p8est_mesh_t} end """ @@ -9957,8 +12969,11 @@ end Destroy a p8est\\_mesh structure. ### Parameters -* `mesh`:\\[in\\] Mesh structure previously created by [`p8est_mesh_new`](@ref). + + - `mesh`:\\[in\\] Mesh structure previously created by [`p8est_mesh_new`](@ref). + ### Prototype + ```c void p8est_mesh_destroy (p8est_mesh_t * mesh); ``` @@ -9973,18 +12988,27 @@ end Access a process-local quadrant inside a forest. Needs a mesh with populated quad\\_to\\_tree array. This is a special case of p8est_mesh_quadrant_cumulative. ### Parameters -* `p4est`:\\[in\\] The forest. -* `mesh`:\\[in\\] The mesh. -* `qid`:\\[in\\] Process-local id of the quadrant (cumulative over trees). + + - `p4est`:\\[in\\] The forest. + - `mesh`:\\[in\\] The mesh. + - `qid`:\\[in\\] Process-local id of the quadrant (cumulative over trees). + ### Returns + A pointer to the requested quadrant. + ### Prototype + ```c p8est_quadrant_t *p8est_mesh_get_quadrant (p8est_t * p4est, p8est_mesh_t * mesh, p4est_locidx_t qid); ``` """ function p8est_mesh_get_quadrant(p4est_, mesh, qid) - @ccall libp4est.p8est_mesh_get_quadrant(p4est_::Ptr{p8est_t}, mesh::Ptr{p8est_mesh_t}, qid::p4est_locidx_t)::Ptr{p8est_quadrant_t} + @ccall libp4est.p8est_mesh_get_quadrant( + p4est_::Ptr{p8est_t}, + mesh::Ptr{p8est_mesh_t}, + qid::p4est_locidx_t, + )::Ptr{p8est_quadrant_t} end """ @@ -9993,21 +13017,42 @@ end Lookup neighboring quads of quadrant in a specific direction ### Parameters -* `p4est`:\\[in\\] Forest to be worked with. -* `ghost`:\\[in\\] Ghost quadrants. -* `mesh`:\\[in\\] Mesh structure. -* `curr_quad_id`:\\[in\\] Process-local ID of current quad. -* `direction`:\\[in\\] Direction in which to look for adjacent quadrants is encoded as follows: 0 .. 5 neighbor(-s) across f\\_i, 6 .. 17 neighbor(-s) across e\\_{i-6} 18 .. 25 neighbor(-s) across c\\_{i-18} -* `neighboring_quads`:\\[out\\] Array containing neighboring quad(-s) Needs to be empty, contains [`p4est_quadrant_t`](@ref)*. May be NULL, then neighboring_qids must not be NULL. -* `neighboring_encs`:\\[out\\] Array containing encodings for neighboring quads as described below Needs to be empty, contains int. CAUTION: Note, that the encodings differ from the encodings saved in the mesh. Positive values are for local quadrants, negative values indicate ghost quadrants. Faces: 1 .. 24 => same size neighbor (r * 6 + nf) + 1; nf = 0 .. 5 face index; r = 0 .. 3 relative orientation 25 .. 120 => double size neighbor 25 + h * 24 + r * 6 + nf; h = 0 .. 3 number of the subface; r, nf as above 121 .. 144 => half size neighbors 121 + r * 6 + nf; r, nf as above Edges: 1 .. 24 => same size neighbor r * 12 + ne + 1; ne = 0 .. 11 edge index; r = 0 .. 1 relative orientation 25 .. 72 => double size neighbor 25 + h * 24 + r * 12 + ne; h = 0 .. 1 number of the subedge; r, ne as above 73 .. 96 => half size neighbors 73 + r * 12 + ne; r, ne as above Corners: 1 .. 8 => nc + 1; nc = 0 .. 7 corner index -* `neighboring_qids`:\\[out\\] Array containing quadrant ids for neighboring quadrants. May be NULL, then no neighboring qids are collected. If non-NULL the array needs to be empty and will contain int. + + - `p4est`:\\[in\\] Forest to be worked with. + - `ghost`:\\[in\\] Ghost quadrants. + - `mesh`:\\[in\\] Mesh structure. + - `curr_quad_id`:\\[in\\] Process-local ID of current quad. + - `direction`:\\[in\\] Direction in which to look for adjacent quadrants is encoded as follows: 0 .. 5 neighbor(-s) across f\\_i, 6 .. 17 neighbor(-s) across e\\_{i-6} 18 .. 25 neighbor(-s) across c\\_{i-18} + - `neighboring_quads`:\\[out\\] Array containing neighboring quad(-s) Needs to be empty, contains [`p4est_quadrant_t`](@ref)*. May be NULL, then neighboring_qids must not be NULL. + - `neighboring_encs`:\\[out\\] Array containing encodings for neighboring quads as described below Needs to be empty, contains int. CAUTION: Note, that the encodings differ from the encodings saved in the mesh. Positive values are for local quadrants, negative values indicate ghost quadrants. Faces: 1 .. 24 => same size neighbor (r * 6 + nf) + 1; nf = 0 .. 5 face index; r = 0 .. 3 relative orientation 25 .. 120 => double size neighbor 25 + h * 24 + r * 6 + nf; h = 0 .. 3 number of the subface; r, nf as above 121 .. 144 => half size neighbors 121 + r * 6 + nf; r, nf as above Edges: 1 .. 24 => same size neighbor r * 12 + ne + 1; ne = 0 .. 11 edge index; r = 0 .. 1 relative orientation 25 .. 72 => double size neighbor 25 + h * 24 + r * 12 + ne; h = 0 .. 1 number of the subedge; r, ne as above 73 .. 96 => half size neighbors 73 + r * 12 + ne; r, ne as above Corners: 1 .. 8 => nc + 1; nc = 0 .. 7 corner index + - `neighboring_qids`:\\[out\\] Array containing quadrant ids for neighboring quadrants. May be NULL, then no neighboring qids are collected. If non-NULL the array needs to be empty and will contain int. + ### Prototype + ```c p4est_locidx_t p8est_mesh_get_neighbors (p8est_t * p4est, p8est_ghost_t * ghost, p8est_mesh_t * mesh, p4est_locidx_t curr_quad_id, p4est_locidx_t direction, sc_array_t * neighboring_quads, sc_array_t * neighboring_encs, sc_array_t * neighboring_qids); ``` """ -function p8est_mesh_get_neighbors(p4est_, ghost, mesh, curr_quad_id, direction, neighboring_quads, neighboring_encs, neighboring_qids) - @ccall libp4est.p8est_mesh_get_neighbors(p4est_::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t}, mesh::Ptr{p8est_mesh_t}, curr_quad_id::p4est_locidx_t, direction::p4est_locidx_t, neighboring_quads::Ptr{sc_array_t}, neighboring_encs::Ptr{sc_array_t}, neighboring_qids::Ptr{sc_array_t})::p4est_locidx_t +function p8est_mesh_get_neighbors( + p4est_, + ghost, + mesh, + curr_quad_id, + direction, + neighboring_quads, + neighboring_encs, + neighboring_qids, +) + @ccall libp4est.p8est_mesh_get_neighbors( + p4est_::Ptr{p8est_t}, + ghost::Ptr{p8est_ghost_t}, + mesh::Ptr{p8est_mesh_t}, + curr_quad_id::p4est_locidx_t, + direction::p4est_locidx_t, + neighboring_quads::Ptr{sc_array_t}, + neighboring_encs::Ptr{sc_array_t}, + neighboring_qids::Ptr{sc_array_t}, + )::p4est_locidx_t end """ @@ -10016,20 +13061,37 @@ end Find a quadrant based on its cumulative number in the local forest. If the quad\\_to\\_tree field of the mesh structure exists, this is O(1). Otherwise, we perform a binary search over the processor-local trees. ### Parameters -* `p8est`:\\[in\\] Forest to be worked with. -* `mesh`:\\[in\\] A mesh derived from the forest. -* `cumulative_id`:\\[in\\] Cumulative index over all trees of quadrant. Must refer to a local (non-ghost) quadrant. -* `which_tree`:\\[in,out\\] If not NULL, the input value can be -1 or an initial guess for the quadrant's tree and output is the tree of returned quadrant. -* `quadrant_id`:\\[out\\] If not NULL, the number of quadrant in tree. + + - `p8est`:\\[in\\] Forest to be worked with. + - `mesh`:\\[in\\] A mesh derived from the forest. + - `cumulative_id`:\\[in\\] Cumulative index over all trees of quadrant. Must refer to a local (non-ghost) quadrant. + - `which_tree`:\\[in,out\\] If not NULL, the input value can be -1 or an initial guess for the quadrant's tree and output is the tree of returned quadrant. + - `quadrant_id`:\\[out\\] If not NULL, the number of quadrant in tree. + ### Returns + The identified quadrant. + ### Prototype + ```c p8est_quadrant_t *p8est_mesh_quadrant_cumulative (p8est_t * p8est, p8est_mesh_t * mesh, p4est_locidx_t cumulative_id, p4est_topidx_t * which_tree, p4est_locidx_t * quadrant_id); ``` """ -function p8est_mesh_quadrant_cumulative(p8est_, mesh, cumulative_id, which_tree, quadrant_id) - @ccall libp4est.p8est_mesh_quadrant_cumulative(p8est_::Ptr{p8est_t}, mesh::Ptr{p8est_mesh_t}, cumulative_id::p4est_locidx_t, which_tree::Ptr{p4est_topidx_t}, quadrant_id::Ptr{p4est_locidx_t})::Ptr{p8est_quadrant_t} +function p8est_mesh_quadrant_cumulative( + p8est_, + mesh, + cumulative_id, + which_tree, + quadrant_id, +) + @ccall libp4est.p8est_mesh_quadrant_cumulative( + p8est_::Ptr{p8est_t}, + mesh::Ptr{p8est_mesh_t}, + cumulative_id::p4est_locidx_t, + which_tree::Ptr{p4est_topidx_t}, + quadrant_id::Ptr{p4est_locidx_t}, + )::Ptr{p8est_quadrant_t} end """ @@ -10038,16 +13100,26 @@ end Initialize a mesh neighbor iterator by quadrant index. ### Parameters -* `mfn`:\\[out\\] A [`p8est_mesh_face_neighbor_t`](@ref) to be initialized. -* `which_tree`:\\[in\\] Tree of quadrant whose neighbors are looped over. -* `quadrant_id`:\\[in\\] Index relative to which\\_tree of quadrant. + + - `mfn`:\\[out\\] A [`p8est_mesh_face_neighbor_t`](@ref) to be initialized. + - `which_tree`:\\[in\\] Tree of quadrant whose neighbors are looped over. + - `quadrant_id`:\\[in\\] Index relative to which\\_tree of quadrant. + ### Prototype + ```c void p8est_mesh_face_neighbor_init2 (p8est_mesh_face_neighbor_t * mfn, p8est_t * p8est, p8est_ghost_t * ghost, p8est_mesh_t * mesh, p4est_topidx_t which_tree, p4est_locidx_t quadrant_id); ``` """ function p8est_mesh_face_neighbor_init2(mfn, p8est_, ghost, mesh, which_tree, quadrant_id) - @ccall libp4est.p8est_mesh_face_neighbor_init2(mfn::Ptr{p8est_mesh_face_neighbor_t}, p8est_::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t}, mesh::Ptr{p8est_mesh_t}, which_tree::p4est_topidx_t, quadrant_id::p4est_locidx_t)::Cvoid + @ccall libp4est.p8est_mesh_face_neighbor_init2( + mfn::Ptr{p8est_mesh_face_neighbor_t}, + p8est_::Ptr{p8est_t}, + ghost::Ptr{p8est_ghost_t}, + mesh::Ptr{p8est_mesh_t}, + which_tree::p4est_topidx_t, + quadrant_id::p4est_locidx_t, + )::Cvoid end """ @@ -10056,16 +13128,26 @@ end Initialize a mesh neighbor iterator by quadrant pointer. ### Parameters -* `mfn`:\\[out\\] A [`p8est_mesh_face_neighbor_t`](@ref) to be initialized. -* `which_tree`:\\[in\\] Tree of quadrant whose neighbors are looped over. -* `quadrant`:\\[in\\] Pointer to quadrant contained in which\\_tree. + + - `mfn`:\\[out\\] A [`p8est_mesh_face_neighbor_t`](@ref) to be initialized. + - `which_tree`:\\[in\\] Tree of quadrant whose neighbors are looped over. + - `quadrant`:\\[in\\] Pointer to quadrant contained in which\\_tree. + ### Prototype + ```c void p8est_mesh_face_neighbor_init (p8est_mesh_face_neighbor_t * mfn, p8est_t * p8est, p8est_ghost_t * ghost, p8est_mesh_t * mesh, p4est_topidx_t which_tree, p8est_quadrant_t * quadrant); ``` """ function p8est_mesh_face_neighbor_init(mfn, p8est_, ghost, mesh, which_tree, quadrant) - @ccall libp4est.p8est_mesh_face_neighbor_init(mfn::Ptr{p8est_mesh_face_neighbor_t}, p8est_::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t}, mesh::Ptr{p8est_mesh_t}, which_tree::p4est_topidx_t, quadrant::Ptr{p8est_quadrant_t})::Cvoid + @ccall libp4est.p8est_mesh_face_neighbor_init( + mfn::Ptr{p8est_mesh_face_neighbor_t}, + p8est_::Ptr{p8est_t}, + ghost::Ptr{p8est_ghost_t}, + mesh::Ptr{p8est_mesh_t}, + which_tree::p4est_topidx_t, + quadrant::Ptr{p8est_quadrant_t}, + )::Cvoid end """ @@ -10074,20 +13156,31 @@ end Move the iterator forward to loop around neighbors of the quadrant. ### Parameters -* `mfn`:\\[in,out\\] Internal status of the iterator. -* `ntree`:\\[out\\] If not NULL, the tree number of the neighbor. -* `nquad`:\\[out\\] If not NULL, the quadrant number within tree. For ghosts instead the number in ghost layer. -* `nface`:\\[out\\] If not NULL, neighbor's face as in [`p8est_mesh_t`](@ref). -* `nrank`:\\[out\\] If not NULL, the owner process of the neighbor. + + - `mfn`:\\[in,out\\] Internal status of the iterator. + - `ntree`:\\[out\\] If not NULL, the tree number of the neighbor. + - `nquad`:\\[out\\] If not NULL, the quadrant number within tree. For ghosts instead the number in ghost layer. + - `nface`:\\[out\\] If not NULL, neighbor's face as in [`p8est_mesh_t`](@ref). + - `nrank`:\\[out\\] If not NULL, the owner process of the neighbor. + ### Returns + Either a real quadrant or one from the ghost layer. Returns NULL when the iterator is done. + ### Prototype + ```c p8est_quadrant_t *p8est_mesh_face_neighbor_next (p8est_mesh_face_neighbor_t * mfn, p4est_topidx_t * ntree, p4est_locidx_t * nquad, int *nface, int *nrank); ``` """ function p8est_mesh_face_neighbor_next(mfn, ntree, nquad, nface, nrank) - @ccall libp4est.p8est_mesh_face_neighbor_next(mfn::Ptr{p8est_mesh_face_neighbor_t}, ntree::Ptr{p4est_topidx_t}, nquad::Ptr{p4est_locidx_t}, nface::Ptr{Cint}, nrank::Ptr{Cint})::Ptr{p8est_quadrant_t} + @ccall libp4est.p8est_mesh_face_neighbor_next( + mfn::Ptr{p8est_mesh_face_neighbor_t}, + ntree::Ptr{p4est_topidx_t}, + nquad::Ptr{p4est_locidx_t}, + nface::Ptr{Cint}, + nrank::Ptr{Cint}, + )::Ptr{p8est_quadrant_t} end """ @@ -10096,17 +13189,25 @@ end Get the user data for the current face neighbor. ### Parameters -* `mfn`:\\[in\\] Internal status of the iterator. -* `ghost_data`:\\[in\\] Data for the ghost quadrants that has been synchronized with [`p4est_ghost_exchange_data`](@ref). + + - `mfn`:\\[in\\] Internal status of the iterator. + - `ghost_data`:\\[in\\] Data for the ghost quadrants that has been synchronized with [`p4est_ghost_exchange_data`](@ref). + ### Returns + A pointer to the user data for the current neighbor. + ### Prototype + ```c void *p8est_mesh_face_neighbor_data (p8est_mesh_face_neighbor_t * mfn, void *ghost_data); ``` """ function p8est_mesh_face_neighbor_data(mfn, ghost_data) - @ccall libp4est.p8est_mesh_face_neighbor_data(mfn::Ptr{p8est_mesh_face_neighbor_t}, ghost_data::Ptr{Cvoid})::Ptr{Cvoid} + @ccall libp4est.p8est_mesh_face_neighbor_data( + mfn::Ptr{p8est_mesh_face_neighbor_t}, + ghost_data::Ptr{Cvoid}, + )::Ptr{Cvoid} end """ @@ -10116,11 +13217,11 @@ The information that is available to the user-defined [`p8est_iter_volume_t`](@r *treeid* gives the index in `p4est`->trees of the tree to which *quad* belongs. *quadid* gives the index of *quad* within *tree*'s quadrants array. -| Field | Note | -| :----- | :------------------------------------------------------ | -| quad | the quadrant of the callback | -| quadid | id in *quad*'s tree array (see [`p8est_tree_t`](@ref)) | -| treeid | the tree containing *quad* | +| Field | Note | +|:------ |:------------------------------------------------------ | +| quad | the quadrant of the callback | +| quadid | id in *quad*'s tree array (see [`p8est_tree_t`](@ref)) | +| treeid | the tree containing *quad* | """ struct p8est_iter_volume_info p4est::Ptr{p8est_t} @@ -10142,13 +13243,14 @@ const p8est_iter_volume_info_t = p8est_iter_volume_info The prototype for a function that [`p8est_iterate`](@ref)() will execute at every quadrant local to the current process. ### Parameters -* `info`:\\[in\\] information about a quadrant provided to the user -* `user_data`:\\[in,out\\] the user context passed to [`p8est_iterate`](@ref)() + + - `info`:\\[in\\] information about a quadrant provided to the user + - `user_data`:\\[in,out\\] the user context passed to [`p8est_iterate`](@ref)() """ const p8est_iter_volume_t = Ptr{Cvoid} struct p8est_iter_face_side_data - data::NTuple{56, UInt8} + data::NTuple{56,UInt8} end function Base.getproperty(x::Ptr{p8est_iter_face_side_data}, f::Symbol) @@ -10173,14 +13275,14 @@ end Information about one side of a face in the forest. If a *quad* is local (*is_ghost* is false), then its *quadid* indexes the tree's quadrant array; otherwise, it indexes the ghosts array. If the face is hanging, then the quadrants are listed in z-order. If a quadrant should be present, but it is not included in the ghost layer, then quad = NULL, is\\_ghost is true, and quadid = -1. -| Field | Note | -| :----------- | :---------------------------------------------------- | -| treeid | the tree on this side | -| face | which quadrant side the face touches | -| is\\_hanging | boolean: one full quad (0) or four smaller quads (1) | +| Field | Note | +|:------------ |:---------------------------------------------------- | +| treeid | the tree on this side | +| face | which quadrant side the face touches | +| is\\_hanging | boolean: one full quad (0) or four smaller quads (1) | """ struct p8est_iter_face_side - data::NTuple{64, UInt8} + data::NTuple{64,UInt8} end function Base.getproperty(x::Ptr{p8est_iter_face_side}, f::Symbol) @@ -10202,7 +13304,9 @@ function Base.setproperty!(x::Ptr{p8est_iter_face_side}, f::Symbol, v) unsafe_store!(getproperty(x, f), v) end -"""Information about one side of a face in the forest. If a *quad* is local (*is_ghost* is false), then its *quadid* indexes the tree's quadrant array; otherwise, it indexes the ghosts array. If the face is hanging, then the quadrants are listed in z-order. If a quadrant should be present, but it is not included in the ghost layer, then quad = NULL, is\\_ghost is true, and quadid = -1.""" +""" +Information about one side of a face in the forest. If a *quad* is local (*is_ghost* is false), then its *quadid* indexes the tree's quadrant array; otherwise, it indexes the ghosts array. If the face is hanging, then the quadrants are listed in z-order. If a quadrant should be present, but it is not included in the ghost layer, then quad = NULL, is\\_ghost is true, and quadid = -1. +""" const p8est_iter_face_side_t = p8est_iter_face_side """ @@ -10212,10 +13316,10 @@ The information that is available to the user-defined [`p8est_iter_face_t`](@ref The orientation is 0 if the face is within one tree; otherwise, it is the same as the orientation value between the two trees given in the connectivity. If the face is on the outside of the forest, then there is only one side. If tree\\_boundary is false, the face is on the interior of a tree. When tree\\_boundary false, sides[0] contains the lowest z-order quadrant that touches the face. When tree\\_boundary is true, its value is P8EST\\_CONNECT\\_FACE. -| Field | Note | -| :-------------- | :-------------------------------------------------------------------------------------------------- | -| orientation | the orientation of the sides to each other, as in the definition of [`p8est_connectivity_t`](@ref) | -| tree\\_boundary | boolean: interior face (0), tree boundary face (true) | +| Field | Note | +|:--------------- |:-------------------------------------------------------------------------------------------------- | +| orientation | the orientation of the sides to each other, as in the definition of [`p8est_connectivity_t`](@ref) | +| tree\\_boundary | boolean: interior face (0), tree boundary face (true) | """ struct p8est_iter_face_info p4est::Ptr{p8est_t} @@ -10241,13 +13345,14 @@ The prototype for a function that [`p8est_iterate`](@ref)() will execute whereve the forest must be face balanced for [`p8est_iterate`](@ref)() to execute a callback function on faces (see [`p8est_balance`](@ref)()). ### Parameters -* `info`:\\[in\\] information about a quadrant provided to the user -* `user_data`:\\[in,out\\] the user context passed to [`p8est_iterate`](@ref)() + + - `info`:\\[in\\] information about a quadrant provided to the user + - `user_data`:\\[in,out\\] the user context passed to [`p8est_iterate`](@ref)() """ const p8est_iter_face_t = Ptr{Cvoid} struct p8est_iter_edge_side_data - data::NTuple{32, UInt8} + data::NTuple{32,UInt8} end function Base.getproperty(x::Ptr{p8est_iter_edge_side_data}, f::Symbol) @@ -10270,15 +13375,15 @@ end """ p8est_iter_edge_side -| Field | Note | -| :----------- | :-------------------------------------------------------------------------------------------------------------- | -| treeid | the tree on this side | -| edge | which quadrant side the edge touches | -| orientation | the orientation of each quadrant relative to this edge, as in the definition of [`p8est_connectivity_t`](@ref) | -| is\\_hanging | boolean: one full quad (0) or two smaller quads (1) | +| Field | Note | +|:------------ |:-------------------------------------------------------------------------------------------------------------- | +| treeid | the tree on this side | +| edge | which quadrant side the edge touches | +| orientation | the orientation of each quadrant relative to this edge, as in the definition of [`p8est_connectivity_t`](@ref) | +| is\\_hanging | boolean: one full quad (0) or two smaller quads (1) | """ struct p8est_iter_edge_side - data::NTuple{48, UInt8} + data::NTuple{48,UInt8} end function Base.getproperty(x::Ptr{p8est_iter_edge_side}, f::Symbol) @@ -10287,7 +13392,7 @@ function Base.getproperty(x::Ptr{p8est_iter_edge_side}, f::Symbol) f === :orientation && return Ptr{Int8}(x + 5) f === :is_hanging && return Ptr{Int8}(x + 6) f === :is && return Ptr{p8est_iter_edge_side_data}(x + 8) - f === :faces && return Ptr{NTuple{2, Int8}}(x + 40) + f === :faces && return Ptr{NTuple{2,Int8}}(x + 40) return getfield(x, f) end @@ -10309,10 +13414,10 @@ const p8est_iter_edge_side_t = p8est_iter_edge_side The information about all sides of an edge in the forest. If tree\\_boundary is false, the edge is on the interior of a tree. When tree\\_boundary is false, sides[0] contains the lowest z-order quadrant that touches the edge. When tree\\_boundary is true, its value is P8EST\\_CONNECT\\_FACE/EDGE depending on the location of the edge relative to the tree. -| Field | Note | -| :-------------- | :----------------------------------------------------- | -| tree\\_boundary | boolean: interior face (0), tree boundary face (true) | -| sides | array of `p8est_iter_edge_side_t` type | +| Field | Note | +|:--------------- |:----------------------------------------------------- | +| tree\\_boundary | boolean: interior face (0), tree boundary face (true) | +| sides | array of `p8est_iter_edge_side_t` type | """ struct p8est_iter_edge_info p4est::Ptr{p8est_t} @@ -10321,7 +13426,9 @@ struct p8est_iter_edge_info sides::sc_array_t end -"""The information about all sides of an edge in the forest. If tree\\_boundary is false, the edge is on the interior of a tree. When tree\\_boundary is false, sides[0] contains the lowest z-order quadrant that touches the edge. When tree\\_boundary is true, its value is P8EST\\_CONNECT\\_FACE/EDGE depending on the location of the edge relative to the tree.""" +""" +The information about all sides of an edge in the forest. If tree\\_boundary is false, the edge is on the interior of a tree. When tree\\_boundary is false, sides[0] contains the lowest z-order quadrant that touches the edge. When tree\\_boundary is true, its value is P8EST\\_CONNECT\\_FACE/EDGE depending on the location of the edge relative to the tree. +""" const p8est_iter_edge_info_t = p8est_iter_edge_info # typedef void ( * p8est_iter_edge_t ) ( p8est_iter_edge_info_t * info , void * user_data ) @@ -10333,22 +13440,23 @@ The prototype for a function that [`p8est_iterate`](@ref) will execute wherever the forest must be edge balanced for [`p8est_iterate`](@ref)() to execute a callback function on edges. ### Parameters -* `info`:\\[in\\] information about a quadrant provided to the user -* `user_data`:\\[in,out\\] the user context passed to [`p8est_iterate`](@ref)() + + - `info`:\\[in\\] information about a quadrant provided to the user + - `user_data`:\\[in,out\\] the user context passed to [`p8est_iterate`](@ref)() """ const p8est_iter_edge_t = Ptr{Cvoid} """ p8est_iter_corner_side -| Field | Note | -| :--------- | :--------------------------------------------------- | -| treeid | the tree that contains *quad* | -| corner | which of the quadrant's corners touches this corner | -| is\\_ghost | boolean: local (0) or ghost (1) | -| quadid | the index in the tree or ghost array | -| faces | internal work data | -| edges | | +| Field | Note | +|:---------- |:--------------------------------------------------- | +| treeid | the tree that contains *quad* | +| corner | which of the quadrant's corners touches this corner | +| is\\_ghost | boolean: local (0) or ghost (1) | +| quadid | the index in the tree or ghost array | +| faces | internal work data | +| edges | | """ struct p8est_iter_corner_side treeid::p4est_topidx_t @@ -10356,8 +13464,8 @@ struct p8est_iter_corner_side is_ghost::Int8 quad::Ptr{p8est_quadrant_t} quadid::p4est_locidx_t - faces::NTuple{3, Int8} - edges::NTuple{3, Int8} + faces::NTuple{3,Int8} + edges::NTuple{3,Int8} end const p8est_iter_corner_side_t = p8est_iter_corner_side @@ -10369,10 +13477,10 @@ The information that is availalbe to the user-defined [`p8est_iter_corner_t`](@r If tree\\_boundary is false, the corner is on the interior of a tree. When tree\\_boundary is false, sides[0] contains the lowest z-order quadrant that touches the corner. When tree\\_boundary is true, its value is P8EST\\_CONNECT\\_FACE/EDGE/CORNER depending on the location of the corner relative to the tree. -| Field | Note | -| :-------------- | :----------------------------------------------------- | -| tree\\_boundary | boolean: interior face (0), tree boundary face (true) | -| sides | array of `p8est_iter_corner_side_t` type | +| Field | Note | +|:--------------- |:----------------------------------------------------- | +| tree\\_boundary | boolean: interior face (0), tree boundary face (true) | +| sides | array of `p8est_iter_corner_side_t` type | """ struct p8est_iter_corner_info p4est::Ptr{p8est_t} @@ -10399,8 +13507,9 @@ i.e. the callback will not execute on a corner that sits on a hanging face or ed the forest does not need to be corner balanced for [`p8est_iterate`](@ref)() to execute a callback function at corners, only face and edge balanced. ### Parameters -* `info`:\\[in\\] information about a quadrant provided to the user -* `user_data`:\\[in,out\\] the user context passed to [`p8est_iterate`](@ref)() + + - `info`:\\[in\\] information about a quadrant provided to the user + - `user_data`:\\[in,out\\] the user context passed to [`p8est_iterate`](@ref)() """ const p8est_iter_corner_t = Ptr{Cvoid} @@ -10411,23 +13520,42 @@ Execute the user-supplied callback functions at every volume, face, edge and cor The ghost\\_layer may be NULL. The *user_data* pointer is not touched by [`p8est_iterate`](@ref), but is passed to each of the callbacks. Any of the callback functions may be NULL. The callback functions are interspersed with each other, i.e. some face callbacks will occur between volume callbacks, and some edge callbacks will occur between face callbacks, etc.: -1) volume callbacks occur in the sorted Morton-index order. 2) a face callback is not executed until after the volume callbacks have been executed for the quadrants that share it. 3) an edge callback is not executed until the face callbacks have been executed for all faces that touch the edge. 4) a corner callback is not executed until the edge callbacks have been executed for all edges that touch the corner. 5) it is not always the case that every face callback for a given quadrant is executed before any of the edge or corner callbacks, and it is not always the case that every edge callback for a given quadrant is executed before any of the corner callbacks. 6) callbacks are not executed at faces, edges or corners that only involve ghost quadrants, i.e. that are not adjacent in the local section of the forest. + 1. volume callbacks occur in the sorted Morton-index order. 2) a face callback is not executed until after the volume callbacks have been executed for the quadrants that share it. 3) an edge callback is not executed until the face callbacks have been executed for all faces that touch the edge. 4) a corner callback is not executed until the edge callbacks have been executed for all edges that touch the corner. 5) it is not always the case that every face callback for a given quadrant is executed before any of the edge or corner callbacks, and it is not always the case that every edge callback for a given quadrant is executed before any of the corner callbacks. 6) callbacks are not executed at faces, edges or corners that only involve ghost quadrants, i.e. that are not adjacent in the local section of the forest. ### Parameters -* `p4est`:\\[in\\] the forest -* `ghost_layer`:\\[in\\] optional: when not given, callbacks at the boundaries of the local partition cannot provide quadrant data about ghost quadrants: missing ([`p8est_quadrant_t`](@ref) *) pointers are set to NULL, missing indices are set to -1. -* `user_data`:\\[in,out\\] optional context to supply to each callback -* `iter_volume`:\\[in\\] callback function for every quadrant's interior -* `iter_face`:\\[in\\] callback function for every face between quadrants -* `iter_edge`:\\[in\\] callback function for every edge between quadrants -* `iter_corner`:\\[in\\] callback function for every corner between quadrants + + - `p4est`:\\[in\\] the forest + - `ghost_layer`:\\[in\\] optional: when not given, callbacks at the boundaries of the local partition cannot provide quadrant data about ghost quadrants: missing ([`p8est_quadrant_t`](@ref) *) pointers are set to NULL, missing indices are set to -1. + - `user_data`:\\[in,out\\] optional context to supply to each callback + - `iter_volume`:\\[in\\] callback function for every quadrant's interior + - `iter_face`:\\[in\\] callback function for every face between quadrants + - `iter_edge`:\\[in\\] callback function for every edge between quadrants + - `iter_corner`:\\[in\\] callback function for every corner between quadrants + ### Prototype + ```c void p8est_iterate (p8est_t * p4est, p8est_ghost_t * ghost_layer, void *user_data, p8est_iter_volume_t iter_volume, p8est_iter_face_t iter_face, p8est_iter_edge_t iter_edge, p8est_iter_corner_t iter_corner); ``` """ -function p8est_iterate(p4est_, ghost_layer, user_data, iter_volume, iter_face, iter_edge, iter_corner) - @ccall libp4est.p8est_iterate(p4est_::Ptr{p8est_t}, ghost_layer::Ptr{p8est_ghost_t}, user_data::Ptr{Cvoid}, iter_volume::p8est_iter_volume_t, iter_face::p8est_iter_face_t, iter_edge::p8est_iter_edge_t, iter_corner::p8est_iter_corner_t)::Cvoid +function p8est_iterate( + p4est_, + ghost_layer, + user_data, + iter_volume, + iter_face, + iter_edge, + iter_corner, +) + @ccall libp4est.p8est_iterate( + p4est_::Ptr{p8est_t}, + ghost_layer::Ptr{p8est_ghost_t}, + user_data::Ptr{Cvoid}, + iter_volume::p8est_iter_volume_t, + iter_face::p8est_iter_face_t, + iter_edge::p8est_iter_edge_t, + iter_corner::p8est_iter_corner_t, + )::Cvoid end const p8est_lnodes_code_t = Int16 @@ -10503,18 +13631,24 @@ const p8est_lnodes_rank_t = p8est_lnodes_rank p8est_lnodes_new(p8est_, ghost_layer, degree) ### Prototype + ```c p8est_lnodes_t *p8est_lnodes_new (p8est_t * p8est, p8est_ghost_t * ghost_layer, int degree); ``` """ function p8est_lnodes_new(p8est_, ghost_layer, degree) - @ccall libp4est.p8est_lnodes_new(p8est_::Ptr{p8est_t}, ghost_layer::Ptr{p8est_ghost_t}, degree::Cint)::Ptr{p8est_lnodes_t} + @ccall libp4est.p8est_lnodes_new( + p8est_::Ptr{p8est_t}, + ghost_layer::Ptr{p8est_ghost_t}, + degree::Cint, + )::Ptr{p8est_lnodes_t} end """ p8est_lnodes_destroy(lnodes) ### Prototype + ```c void p8est_lnodes_destroy (p8est_lnodes_t * lnodes); ``` @@ -10529,17 +13663,25 @@ end Partition using weights based on the number of nodes assigned to each element in lnodes ### Parameters -* `p8est`:\\[in,out\\] the forest to be repartitioned -* `ghost`:\\[in\\] the ghost layer -* `degree`:\\[in\\] the degree that would be passed to [`p8est_lnodes_new`](@ref)() -* `partition_for_coarsening`:\\[in\\] whether the partition should allow coarsening (i.e. group siblings who might merge) + + - `p8est`:\\[in,out\\] the forest to be repartitioned + - `ghost`:\\[in\\] the ghost layer + - `degree`:\\[in\\] the degree that would be passed to [`p8est_lnodes_new`](@ref)() + - `partition_for_coarsening`:\\[in\\] whether the partition should allow coarsening (i.e. group siblings who might merge) + ### Prototype + ```c void p8est_partition_lnodes (p8est_t * p8est, p8est_ghost_t * ghost, int degree, int partition_for_coarsening); ``` """ function p8est_partition_lnodes(p8est_, ghost, degree, partition_for_coarsening) - @ccall libp4est.p8est_partition_lnodes(p8est_::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t}, degree::Cint, partition_for_coarsening::Cint)::Cvoid + @ccall libp4est.p8est_partition_lnodes( + p8est_::Ptr{p8est_t}, + ghost::Ptr{p8est_ghost_t}, + degree::Cint, + partition_for_coarsening::Cint, + )::Cvoid end """ @@ -10548,12 +13690,29 @@ end Partition using weights that are broken down by where they reside: in volumes, on faces, on edges, or on corners. ### Prototype + ```c void p8est_partition_lnodes_detailed (p8est_t * p4est, p8est_ghost_t * ghost, int nodes_per_volume, int nodes_per_face, int nodes_per_edge, int nodes_per_corner, int partition_for_coarsening); ``` """ -function p8est_partition_lnodes_detailed(p4est_, ghost, nodes_per_volume, nodes_per_face, nodes_per_edge, nodes_per_corner, partition_for_coarsening) - @ccall libp4est.p8est_partition_lnodes_detailed(p4est_::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t}, nodes_per_volume::Cint, nodes_per_face::Cint, nodes_per_edge::Cint, nodes_per_corner::Cint, partition_for_coarsening::Cint)::Cvoid +function p8est_partition_lnodes_detailed( + p4est_, + ghost, + nodes_per_volume, + nodes_per_face, + nodes_per_edge, + nodes_per_corner, + partition_for_coarsening, +) + @ccall libp4est.p8est_partition_lnodes_detailed( + p4est_::Ptr{p8est_t}, + ghost::Ptr{p8est_ghost_t}, + nodes_per_volume::Cint, + nodes_per_face::Cint, + nodes_per_edge::Cint, + nodes_per_corner::Cint, + partition_for_coarsening::Cint, + )::Cvoid end """ @@ -10562,16 +13721,23 @@ end Expand the ghost layer to include the support of all nodes supported on the local partition. ### Parameters -* `p8est`:\\[in\\] The forest from which the ghost layer was generated. -* `lnodes`:\\[in\\] The nodes to support. -* `ghost`:\\[in,out\\] The ghost layer to be expanded. + + - `p8est`:\\[in\\] The forest from which the ghost layer was generated. + - `lnodes`:\\[in\\] The nodes to support. + - `ghost`:\\[in,out\\] The ghost layer to be expanded. + ### Prototype + ```c void p8est_ghost_support_lnodes (p8est_t * p8est, p8est_lnodes_t * lnodes, p8est_ghost_t * ghost); ``` """ function p8est_ghost_support_lnodes(p8est_, lnodes, ghost) - @ccall libp4est.p8est_ghost_support_lnodes(p8est_::Ptr{p8est_t}, lnodes::Ptr{p8est_lnodes_t}, ghost::Ptr{p8est_ghost_t})::Cvoid + @ccall libp4est.p8est_ghost_support_lnodes( + p8est_::Ptr{p8est_t}, + lnodes::Ptr{p8est_lnodes_t}, + ghost::Ptr{p8est_ghost_t}, + )::Cvoid end """ @@ -10580,16 +13746,23 @@ end Expand the ghost layer as in [`p8est_ghost_expand`](@ref)(), but use node support to define adjacency instead of geometric adjacency. ### Parameters -* `p8est`:\\[in\\] The forest from which the ghost layer was generated. -* `lnodes`:\\[in\\] The nodes to support. -* `ghost`:\\[in,out\\] The ghost layer to be expanded. + + - `p8est`:\\[in\\] The forest from which the ghost layer was generated. + - `lnodes`:\\[in\\] The nodes to support. + - `ghost`:\\[in,out\\] The ghost layer to be expanded. + ### Prototype + ```c void p8est_ghost_expand_by_lnodes (p8est_t * p4est, p8est_lnodes_t * lnodes, p8est_ghost_t * ghost); ``` """ function p8est_ghost_expand_by_lnodes(p4est_, lnodes, ghost) - @ccall libp4est.p8est_ghost_expand_by_lnodes(p4est_::Ptr{p8est_t}, lnodes::Ptr{p8est_lnodes_t}, ghost::Ptr{p8est_ghost_t})::Cvoid + @ccall libp4est.p8est_ghost_expand_by_lnodes( + p4est_::Ptr{p8est_t}, + lnodes::Ptr{p8est_lnodes_t}, + ghost::Ptr{p8est_ghost_t}, + )::Cvoid end """ @@ -10626,18 +13799,23 @@ const p8est_lnodes_buffer_t = p8est_lnodes_buffer To be memory neutral, the *buffer* created by [`p8est_lnodes_share_owned_begin`](@ref) must be destroying with [`p8est_lnodes_buffer_destroy`](@ref) (it is not destroyed by [`p8est_lnodes_share_owned_end`](@ref)). ### Prototype + ```c p8est_lnodes_buffer_t *p8est_lnodes_share_owned_begin (sc_array_t * node_data, p8est_lnodes_t * lnodes); ``` """ function p8est_lnodes_share_owned_begin(node_data, lnodes) - @ccall libp4est.p8est_lnodes_share_owned_begin(node_data::Ptr{sc_array_t}, lnodes::Ptr{p8est_lnodes_t})::Ptr{p8est_lnodes_buffer_t} + @ccall libp4est.p8est_lnodes_share_owned_begin( + node_data::Ptr{sc_array_t}, + lnodes::Ptr{p8est_lnodes_t}, + )::Ptr{p8est_lnodes_buffer_t} end """ p8est_lnodes_share_owned_end(buffer) ### Prototype + ```c void p8est_lnodes_share_owned_end (p8est_lnodes_buffer_t * buffer); ``` @@ -10652,12 +13830,16 @@ end Equivalent to calling [`p8est_lnodes_share_owned_end`](@ref) directly after [`p8est_lnodes_share_owned_begin`](@ref). Use if there is no local work that can be done to mask the communication cost. ### Prototype + ```c void p8est_lnodes_share_owned (sc_array_t * node_data, p8est_lnodes_t * lnodes); ``` """ function p8est_lnodes_share_owned(node_data, lnodes) - @ccall libp4est.p8est_lnodes_share_owned(node_data::Ptr{sc_array_t}, lnodes::Ptr{p8est_lnodes_t})::Cvoid + @ccall libp4est.p8est_lnodes_share_owned( + node_data::Ptr{sc_array_t}, + lnodes::Ptr{p8est_lnodes_t}, + )::Cvoid end """ @@ -10670,18 +13852,23 @@ end Values of *node_data* are not guaranteed to be send, and *buffer*->recv_buffer entries are not guaranteed to be received until the *buffer* created by [`p8est_lnodes_share_all_begin`](@ref) is passed to [`p8est_lnodes_share_all_end`](@ref). ### Prototype + ```c p8est_lnodes_buffer_t *p8est_lnodes_share_all_begin (sc_array_t * node_data, p8est_lnodes_t * lnodes); ``` """ function p8est_lnodes_share_all_begin(node_data, lnodes) - @ccall libp4est.p8est_lnodes_share_all_begin(node_data::Ptr{sc_array_t}, lnodes::Ptr{p8est_lnodes_t})::Ptr{p8est_lnodes_buffer_t} + @ccall libp4est.p8est_lnodes_share_all_begin( + node_data::Ptr{sc_array_t}, + lnodes::Ptr{p8est_lnodes_t}, + )::Ptr{p8est_lnodes_buffer_t} end """ p8est_lnodes_share_all_end(buffer) ### Prototype + ```c void p8est_lnodes_share_all_end (p8est_lnodes_buffer_t * buffer); ``` @@ -10696,20 +13883,27 @@ end Equivalend to calling [`p8est_lnodes_share_all_end`](@ref) directly after [`p8est_lnodes_share_all_begin`](@ref). Use if there is no local work that can be done to mask the communication cost. ### Returns + A fully initialized buffer that contains the received data. After processing this data, the buffer must be freed with [`p8est_lnodes_buffer_destroy`](@ref). + ### Prototype + ```c p8est_lnodes_buffer_t *p8est_lnodes_share_all (sc_array_t * node_data, p8est_lnodes_t * lnodes); ``` """ function p8est_lnodes_share_all(node_data, lnodes) - @ccall libp4est.p8est_lnodes_share_all(node_data::Ptr{sc_array_t}, lnodes::Ptr{p8est_lnodes_t})::Ptr{p8est_lnodes_buffer_t} + @ccall libp4est.p8est_lnodes_share_all( + node_data::Ptr{sc_array_t}, + lnodes::Ptr{p8est_lnodes_t}, + )::Ptr{p8est_lnodes_buffer_t} end """ p8est_lnodes_buffer_destroy(buffer) ### Prototype + ```c void p8est_lnodes_buffer_destroy (p8est_lnodes_buffer_t * buffer); ``` @@ -10723,17 +13917,19 @@ end An unsigned 128 bit integer represented as two uint64\\_t. -| Field | Note | -| :---------- | :----------------------------- | -| high\\_bits | The more significant 64 bits. | -| low\\_bits | The less significant 64 bits. | +| Field | Note | +|:----------- |:----------------------------- | +| high\\_bits | The more significant 64 bits. | +| low\\_bits | The less significant 64 bits. | """ struct sc_uint128 high_bits::UInt64 low_bits::UInt64 end -"""An unsigned 128 bit integer represented as two uint64\\_t.""" +""" +An unsigned 128 bit integer represented as two uint64\\_t. +""" const sc_uint128_t = sc_uint128 """ @@ -10742,11 +13938,16 @@ const sc_uint128_t = sc_uint128 Compare the [`sc_uint128_t`](@ref) *a* and the [`sc_uint128_t`](@ref) *b*. ### Parameters -* `a`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). -* `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + + - `a`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + - `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + ### Returns + Returns -1 if a < b, 1 if a > b and 0 if a == b. + ### Prototype + ```c int sc_uint128_compare (const void *a, const void *b); ``` @@ -10761,11 +13962,16 @@ end Checks if the [`sc_uint128_t`](@ref) *a* and the [`sc_uint128_t`](@ref) *b* are equal. ### Parameters -* `a`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). -* `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + + - `a`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + - `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + ### Returns + Returns a true value if *a* and *b* are equal, false otherwise. + ### Prototype + ```c int sc_uint128_is_equal (const sc_uint128_t * a, const sc_uint128_t * b); ``` @@ -10780,10 +13986,13 @@ end Initializes an unsigned 128 bit integer to a given value. ### Parameters -* `a`:\\[in,out\\] A pointer to the [`sc_uint128_t`](@ref) that will be initialized. -* `high`:\\[in\\] The given high bits to initialize *a*. -* `low`:\\[in\\] The given low bits to initialize *a*. + + - `a`:\\[in,out\\] A pointer to the [`sc_uint128_t`](@ref) that will be initialized. + - `high`:\\[in\\] The given high bits to initialize *a*. + - `low`:\\[in\\] The given low bits to initialize *a*. + ### Prototype + ```c void sc_uint128_init (sc_uint128_t * a, uint64_t high, uint64_t low); ``` @@ -10798,11 +14007,16 @@ end Returns the bit\\_number-th bit of *input*. This function checks a bit of an existing, initialized value. ### Parameters -* `input`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). -* `bit_number`:\\[in\\] The bit (counted from the right hand side) that is checked by logical and. Require 0 <= *bit_number* < 128. + + - `input`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + - `bit_number`:\\[in\\] The bit (counted from the right hand side) that is checked by logical and. Require 0 <= *bit_number* < 128. + ### Returns + True if the checked bit is set, false if not. + ### Prototype + ```c int sc_uint128_chk_bit (const sc_uint128_t * input, int exponent); ``` @@ -10817,9 +14031,12 @@ end Sets the exponent-th bit of *a* to one and keep all other bits. This function modifies an existing, initialized value. ### Parameters -* `a`:\\[in,out\\] A pointer to a [`sc_uint128_t`](@ref). -* `exponent`:\\[in\\] The bit (0-based from the rightmost bit) that is set to one by logical or. 0 <= *exponent* < 128. + + - `a`:\\[in,out\\] A pointer to a [`sc_uint128_t`](@ref). + - `exponent`:\\[in\\] The bit (0-based from the rightmost bit) that is set to one by logical or. 0 <= *exponent* < 128. + ### Prototype + ```c void sc_uint128_set_bit (sc_uint128_t * a, int exponent); ``` @@ -10834,9 +14051,12 @@ end Copies an initialized [`sc_uint128_t`](@ref) to a [`sc_uint128_t`](@ref). ### Parameters -* `input`:\\[in\\] A pointer to the [`sc_uint128`](@ref) that is copied. -* `output`:\\[in,out\\] A pointer to a [`sc_uint128_t`](@ref). The high and low bits of *output* will be set to the high and low bits of *input*, respectively. + + - `input`:\\[in\\] A pointer to the [`sc_uint128`](@ref) that is copied. + - `output`:\\[in,out\\] A pointer to a [`sc_uint128_t`](@ref). The high and low bits of *output* will be set to the high and low bits of *input*, respectively. + ### Prototype + ```c void sc_uint128_copy (const sc_uint128_t * input, sc_uint128_t * output); ``` @@ -10851,16 +14071,23 @@ end Adds the uint128\\_t *b* to the uint128\\_t *a*. *result* == *a* or *result* == *b* is not allowed. *a* == *b* is allowed. ### Parameters -* `a`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). -* `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). -* `result`:\\[out\\] A pointer to a [`sc_uint128_t`](@ref). The sum *a* + *b* will be saved in *result*. + + - `a`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + - `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + - `result`:\\[out\\] A pointer to a [`sc_uint128_t`](@ref). The sum *a* + *b* will be saved in *result*. + ### Prototype + ```c void sc_uint128_add (const sc_uint128_t * a, const sc_uint128_t * b, sc_uint128_t * result); ``` """ function sc_uint128_add(a, b, result) - @ccall libsc.sc_uint128_add(a::Ptr{sc_uint128_t}, b::Ptr{sc_uint128_t}, result::Ptr{sc_uint128_t})::Cvoid + @ccall libsc.sc_uint128_add( + a::Ptr{sc_uint128_t}, + b::Ptr{sc_uint128_t}, + result::Ptr{sc_uint128_t}, + )::Cvoid end """ @@ -10869,16 +14096,23 @@ end Subtracts the uint128\\_t *b* from the uint128\\_t *a*. This function assumes that the result is >= 0. *result* == *a* or *result* == *b* is not allowed. *a* == *b* is allowed. ### Parameters -* `a`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). -* `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). -* `result`:\\[out\\] A pointer to a [`sc_uint128_t`](@ref). The difference *a* - *b* will be saved in *result*. + + - `a`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + - `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + - `result`:\\[out\\] A pointer to a [`sc_uint128_t`](@ref). The difference *a* - *b* will be saved in *result*. + ### Prototype + ```c void sc_uint128_sub (const sc_uint128_t * a, const sc_uint128_t * b, sc_uint128_t * result); ``` """ function sc_uint128_sub(a, b, result) - @ccall libsc.sc_uint128_sub(a::Ptr{sc_uint128_t}, b::Ptr{sc_uint128_t}, result::Ptr{sc_uint128_t})::Cvoid + @ccall libsc.sc_uint128_sub( + a::Ptr{sc_uint128_t}, + b::Ptr{sc_uint128_t}, + result::Ptr{sc_uint128_t}, + )::Cvoid end """ @@ -10887,15 +14121,21 @@ end Calculates the bitwise negation of the uint128\\_t *a*. *a* == *result* is allowed. ### Parameters -* `a`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). -* `result`:\\[out\\] A pointer to a [`sc_uint128_t`](@ref). The bitwise negation of *a* will be saved in *result*. + + - `a`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + - `result`:\\[out\\] A pointer to a [`sc_uint128_t`](@ref). The bitwise negation of *a* will be saved in *result*. + ### Prototype + ```c void sc_uint128_bitwise_neg (const sc_uint128_t * a, sc_uint128_t * result); ``` """ function sc_uint128_bitwise_neg(a, result) - @ccall libsc.sc_uint128_bitwise_neg(a::Ptr{sc_uint128_t}, result::Ptr{sc_uint128_t})::Cvoid + @ccall libsc.sc_uint128_bitwise_neg( + a::Ptr{sc_uint128_t}, + result::Ptr{sc_uint128_t}, + )::Cvoid end """ @@ -10904,16 +14144,23 @@ end Calculates the bitwise or of the uint128\\_t *a* and *b*. *a* == *result* is allowed. Furthermore, *a* == *result* and/or *b* == *result* is allowed. ### Parameters -* `a`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). -* `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). -* `result`:\\[out\\] A pointer to a [`sc_uint128_t`](@ref). The bitwise or of *a* and *b* will be saved in *result*. + + - `a`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + - `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + - `result`:\\[out\\] A pointer to a [`sc_uint128_t`](@ref). The bitwise or of *a* and *b* will be saved in *result*. + ### Prototype + ```c void sc_uint128_bitwise_or (const sc_uint128_t * a, const sc_uint128_t * b, sc_uint128_t * result); ``` """ function sc_uint128_bitwise_or(a, b, result) - @ccall libsc.sc_uint128_bitwise_or(a::Ptr{sc_uint128_t}, b::Ptr{sc_uint128_t}, result::Ptr{sc_uint128_t})::Cvoid + @ccall libsc.sc_uint128_bitwise_or( + a::Ptr{sc_uint128_t}, + b::Ptr{sc_uint128_t}, + result::Ptr{sc_uint128_t}, + )::Cvoid end """ @@ -10922,16 +14169,23 @@ end Calculates the bitwise and of the uint128\\_t *a* and the uint128\\_t *b*. *a* == *result* is allowed. Furthermore, *a* == *result* and/or *b* == *result* is allowed. ### Parameters -* `a`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). -* `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). -* `result`:\\[out\\] A pointer to a [`sc_uint128_t`](@ref). The bitwise and of *a* and *b* will be saved. in *result*. + + - `a`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + - `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + - `result`:\\[out\\] A pointer to a [`sc_uint128_t`](@ref). The bitwise and of *a* and *b* will be saved. in *result*. + ### Prototype + ```c void sc_uint128_bitwise_and (const sc_uint128_t * a, const sc_uint128_t * b, sc_uint128_t * result); ``` """ function sc_uint128_bitwise_and(a, b, result) - @ccall libsc.sc_uint128_bitwise_and(a::Ptr{sc_uint128_t}, b::Ptr{sc_uint128_t}, result::Ptr{sc_uint128_t})::Cvoid + @ccall libsc.sc_uint128_bitwise_and( + a::Ptr{sc_uint128_t}, + b::Ptr{sc_uint128_t}, + result::Ptr{sc_uint128_t}, + )::Cvoid end """ @@ -10940,16 +14194,23 @@ end Calculates the bit right shift of uint128\\_t *input* by shift\\_count bits. We shift in zeros from the left. If *shift_count* >= 128, *result* is 0. All bits right from the zeroth bit (counted from the right hand side) drop out. *input* == *result* is allowed. ### Parameters -* `input`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). -* `shift_count`:\\[in\\] Bits to shift. *shift_count* >= 0. -* `result`:\\[in,out\\] A pointer to a [`sc_uint128_t`](@ref). The right shifted number will be saved in *result*. + + - `input`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + - `shift_count`:\\[in\\] Bits to shift. *shift_count* >= 0. + - `result`:\\[in,out\\] A pointer to a [`sc_uint128_t`](@ref). The right shifted number will be saved in *result*. + ### Prototype + ```c void sc_uint128_shift_right (const sc_uint128_t * input, int shift_count, sc_uint128_t * result); ``` """ function sc_uint128_shift_right(input, shift_count, result) - @ccall libsc.sc_uint128_shift_right(input::Ptr{sc_uint128_t}, shift_count::Cint, result::Ptr{sc_uint128_t})::Cvoid + @ccall libsc.sc_uint128_shift_right( + input::Ptr{sc_uint128_t}, + shift_count::Cint, + result::Ptr{sc_uint128_t}, + )::Cvoid end """ @@ -10958,16 +14219,23 @@ end Calculates the bit left shift of uint128\\_t *input* by shift\\_count bits. We shift in zeros from the right. If *shift_count* >= 128, *result* is 0. All bits left from the 127th bit (counted zero based from the right hand side) drop out. *input* == *result* is allowed. ### Parameters -* `input`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). -* `shift_count`:\\[in\\] Bits to shift. *shift_count* >= 0. -* `result`:\\[in,out\\] A pointer to a [`sc_uint128_t`](@ref). The left shifted number will be saved in *result*. + + - `input`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + - `shift_count`:\\[in\\] Bits to shift. *shift_count* >= 0. + - `result`:\\[in,out\\] A pointer to a [`sc_uint128_t`](@ref). The left shifted number will be saved in *result*. + ### Prototype + ```c void sc_uint128_shift_left (const sc_uint128_t * input, int shift_count, sc_uint128_t * result); ``` """ function sc_uint128_shift_left(input, shift_count, result) - @ccall libsc.sc_uint128_shift_left(input::Ptr{sc_uint128_t}, shift_count::Cint, result::Ptr{sc_uint128_t})::Cvoid + @ccall libsc.sc_uint128_shift_left( + input::Ptr{sc_uint128_t}, + shift_count::Cint, + result::Ptr{sc_uint128_t}, + )::Cvoid end """ @@ -10976,9 +14244,12 @@ end Adds the uint128 *b* to the uint128\\_t *a*. The result is saved in *a*. *a* == *b* is allowed. ### Parameters -* `a`:\\[in,out\\] A pointer to a [`sc_uint128_t`](@ref). *a* will be overwritten by *a* + *b*. -* `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + + - `a`:\\[in,out\\] A pointer to a [`sc_uint128_t`](@ref). *a* will be overwritten by *a* + *b*. + - `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + ### Prototype + ```c void sc_uint128_add_inplace (sc_uint128_t * a, const sc_uint128_t * b); ``` @@ -10993,9 +14264,12 @@ end Subtracts the uint128\\_t *b* from the uint128\\_t *a*. The result is saved in *a*. *a* == *b* is allowed. This function assumes that the result is >= 0. ### Parameters -* `a`:\\[in,out\\] A pointer to a [`sc_uint128_t`](@ref). *a* will be overwritten by *a* - *b*. -* `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + + - `a`:\\[in,out\\] A pointer to a [`sc_uint128_t`](@ref). *a* will be overwritten by *a* - *b*. + - `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + ### Prototype + ```c void sc_uint128_sub_inplace (sc_uint128_t * a, const sc_uint128_t * b); ``` @@ -11010,15 +14284,21 @@ end Calculates the bitwise or of the uint128\\_t *a* and the uint128\\_t *b*. *a* == *b* is allowed. ### Parameters -* `a`:\\[in,out\\] A pointer to a [`sc_uint128_t`](@ref). The bitwise or will be saved in *a*. -* `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + + - `a`:\\[in,out\\] A pointer to a [`sc_uint128_t`](@ref). The bitwise or will be saved in *a*. + - `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + ### Prototype + ```c void sc_uint128_bitwise_or_inplace (sc_uint128_t * a, const sc_uint128_t * b); ``` """ function sc_uint128_bitwise_or_inplace(a, b) - @ccall libsc.sc_uint128_bitwise_or_inplace(a::Ptr{sc_uint128_t}, b::Ptr{sc_uint128_t})::Cvoid + @ccall libsc.sc_uint128_bitwise_or_inplace( + a::Ptr{sc_uint128_t}, + b::Ptr{sc_uint128_t}, + )::Cvoid end """ @@ -11027,18 +14307,26 @@ end Calculates the bitwise and of the uint128\\_t *a* and the uint128\\_t *b*. *a* == *b* is allowed. ### Parameters -* `a`:\\[in,out\\] A pointer to a [`sc_uint128_t`](@ref). The bitwise and will be saved in *a*. -* `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + + - `a`:\\[in,out\\] A pointer to a [`sc_uint128_t`](@ref). The bitwise and will be saved in *a*. + - `b`:\\[in\\] A pointer to a [`sc_uint128_t`](@ref). + ### Prototype + ```c void sc_uint128_bitwise_and_inplace (sc_uint128_t * a, const sc_uint128_t * b); ``` """ function sc_uint128_bitwise_and_inplace(a, b) - @ccall libsc.sc_uint128_bitwise_and_inplace(a::Ptr{sc_uint128_t}, b::Ptr{sc_uint128_t})::Cvoid + @ccall libsc.sc_uint128_bitwise_and_inplace( + a::Ptr{sc_uint128_t}, + b::Ptr{sc_uint128_t}, + )::Cvoid end -"""A datatype to handle the linear id in 3D. We use the implementation of unsigned 128 bit integer in libsc, i.e., a struct with the members high\\_bits and low\\_bits (both uint64\\_t).""" +""" +A datatype to handle the linear id in 3D. We use the implementation of unsigned 128 bit integer in libsc, i.e., a struct with the members high\\_bits and low\\_bits (both uint64\\_t). +""" const p8est_lid_t = sc_uint128_t # typedef void ( * p8est_replace_t ) ( p8est_t * p8est , p4est_topidx_t which_tree , int num_outgoing , p8est_quadrant_t * outgoing [ ] , int num_incoming , p8est_quadrant_t * incoming [ ] ) @@ -11050,10 +14338,11 @@ This is used by extended routines when the quadrants of an existing, valid `p8es If the mesh is being refined, num\\_outgoing will be 1 and num\\_incoming will be 8, and vice versa if the mesh is being coarsened. ### Parameters -* `num_outgoing`:\\[in\\] The number of outgoing quadrants. -* `outgoing`:\\[in\\] The outgoing quadrants: after the callback, the user\\_data, if `p8est`->data_size is nonzero, will be destroyed. -* `num_incoming`:\\[in\\] The number of incoming quadrants. -* `incoming`:\\[in,out\\] The incoming quadrants: prior to the callback, the user\\_data, if `p8est`->data_size is nonzero, is allocated, and the [`p8est_init_t`](@ref) callback, if it has been provided, will be called. + + - `num_outgoing`:\\[in\\] The number of outgoing quadrants. + - `outgoing`:\\[in\\] The outgoing quadrants: after the callback, the user\\_data, if `p8est`->data_size is nonzero, will be destroyed. + - `num_incoming`:\\[in\\] The number of incoming quadrants. + - `incoming`:\\[in,out\\] The incoming quadrants: prior to the callback, the user\\_data, if `p8est`->data_size is nonzero, is allocated, and the [`p8est_init_t`](@ref) callback, if it has been provided, will be called. """ const p8est_replace_t = Ptr{Cvoid} @@ -11063,11 +14352,16 @@ const p8est_replace_t = Ptr{Cvoid} Compare the [`p8est_lid_t`](@ref) *a* and the [`p8est_lid_t`](@ref) *b*. ### Parameters -* `a`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). -* `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + + - `a`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + - `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + ### Returns + Returns -1 if a < b, 1 if a > b and 0 if a == b. + ### Prototype + ```c int p8est_lid_compare (const p8est_lid_t * a, const p8est_lid_t * b); ``` @@ -11082,11 +14376,16 @@ end Checks if the [`p8est_lid_t`](@ref) *a* and the [`p8est_lid_t`](@ref) *b* are equal. ### Parameters -* `a`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). -* `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + + - `a`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + - `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + ### Returns + Returns a true value if *a* and *b* are equal, false otherwise + ### Prototype + ```c int p8est_lid_is_equal (const p8est_lid_t * a, const p8est_lid_t * b); ``` @@ -11101,16 +14400,23 @@ end Initializes a linear index to a given value. ### Parameters -* `a`:\\[in,out\\] A pointer to the [`p8est_lid_t`](@ref) that will be initialized. -* `high`:\\[in\\] The given high bits to intialize *a*. -* `low`:\\[in\\] The given low bits to initialize *a*. + + - `a`:\\[in,out\\] A pointer to the [`p8est_lid_t`](@ref) that will be initialized. + - `high`:\\[in\\] The given high bits to intialize *a*. + - `low`:\\[in\\] The given low bits to initialize *a*. + ### Prototype + ```c void p8est_lid_init (p8est_lid_t * input, uint64_t high, uint64_t low); ``` """ function p8est_lid_init(input, high, low) - @ccall libp4est.p8est_lid_init(input::Ptr{p8est_lid_t}, high::UInt64, low::UInt64)::Cvoid + @ccall libp4est.p8est_lid_init( + input::Ptr{p8est_lid_t}, + high::UInt64, + low::UInt64, + )::Cvoid end """ @@ -11119,8 +14425,11 @@ end Initializes a linear index to zero. ### Parameters -* `input`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref) that will be intialized. + + - `input`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref) that will be intialized. + ### Prototype + ```c void p8est_lid_set_zero (p8est_lid_t * input); ``` @@ -11135,8 +14444,11 @@ end Initializes a linear index to one. ### Parameters -* `input`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref) that will be intialized. + + - `input`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref) that will be intialized. + ### Prototype + ```c void p8est_lid_set_one (p8est_lid_t * input); ``` @@ -11151,8 +14463,11 @@ end Initializes a linear index to an unsigned 64 bit integer. ### Parameters -* `input`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref) that will be intialized. + + - `input`:\\[out\\] A pointer to a [`p4est_lid_t`](@ref) that will be intialized. + ### Prototype + ```c void p8est_lid_set_uint64 (p8est_lid_t * input, uint64_t u); ``` @@ -11167,11 +14482,16 @@ end Returns the bit\\_number-th bit of *input*. This function checks a bit of an existing, initialized value. ### Parameters -* `input`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). -* `bit_number`:\\[in\\] The bit (counted from the right hand side) that is checked by logical and. Require 0 <= *bit_number* < 128. + + - `input`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + - `bit_number`:\\[in\\] The bit (counted from the right hand side) that is checked by logical and. Require 0 <= *bit_number* < 128. + ### Returns + True if bit is set, false if not. + ### Prototype + ```c int p8est_lid_chk_bit (const p8est_lid_t * input, int bit_number); ``` @@ -11186,9 +14506,12 @@ end Sets the exponent-th bit of *input* to one. This function modifies an existing, initialized value. ### Parameters -* `input`:\\[in,out\\] A pointer to a [`p8est_lid_t`](@ref). -* `bit_number`:\\[in\\] The bit (counted from the right hand side) that is set to one by logical or. Require 0 <= *bit_number* < 128. + + - `input`:\\[in,out\\] A pointer to a [`p8est_lid_t`](@ref). + - `bit_number`:\\[in\\] The bit (counted from the right hand side) that is set to one by logical or. Require 0 <= *bit_number* < 128. + ### Prototype + ```c void p8est_lid_set_bit (p8est_lid_t * input, int bit_number); ``` @@ -11203,9 +14526,12 @@ end Copies an initialized [`p8est_lid_t`](@ref) to a [`p8est_lid_t`](@ref). ### Parameters -* `input`:\\[in\\] A pointer to the [`sc_uint128`](@ref) that is copied. -* `output`:\\[in,out\\] A pointer to a [`p8est_lid_t`](@ref). The high and low bits of *output* will be set to the high and low bits of *input*, respectively. + + - `input`:\\[in\\] A pointer to the [`sc_uint128`](@ref) that is copied. + - `output`:\\[in,out\\] A pointer to a [`p8est_lid_t`](@ref). The high and low bits of *output* will be set to the high and low bits of *input*, respectively. + ### Prototype + ```c void p8est_lid_copy (const p8est_lid_t * input, p8est_lid_t * output); ``` @@ -11220,16 +14546,23 @@ end Adds the uint128\\_t *b* to the uint128\\_t *a*. *result* == *a* or *result* == *b* is not allowed. *a* == *b* is allowed. ### Parameters -* `a`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). -* `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). -* `result`:\\[out\\] A pointer to a [`p8est_lid_t`](@ref). The sum *a* + *b* will be saved in *result*. + + - `a`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + - `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + - `result`:\\[out\\] A pointer to a [`p8est_lid_t`](@ref). The sum *a* + *b* will be saved in *result*. + ### Prototype + ```c void p8est_lid_add (const p8est_lid_t * a, const p8est_lid_t * b, p8est_lid_t * result); ``` """ function p8est_lid_add(a, b, result) - @ccall libp4est.p8est_lid_add(a::Ptr{p8est_lid_t}, b::Ptr{p8est_lid_t}, result::Ptr{p8est_lid_t})::Cvoid + @ccall libp4est.p8est_lid_add( + a::Ptr{p8est_lid_t}, + b::Ptr{p8est_lid_t}, + result::Ptr{p8est_lid_t}, + )::Cvoid end """ @@ -11238,16 +14571,23 @@ end Substracts the [`p8est_lid_t`](@ref) *b* from the [`p8est_lid_t`](@ref) *a*. This function assumes that the result is >= 0. *result* == *a* or *result* == *b* is not allowed. *a* == *b* is allowed. ### Parameters -* `a`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). -* `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). -* `result`:\\[out\\] A pointer to a [`p8est_lid_t`](@ref). The difference *a* - *b* will be saved in *result*. + + - `a`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + - `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + - `result`:\\[out\\] A pointer to a [`p8est_lid_t`](@ref). The difference *a* - *b* will be saved in *result*. + ### Prototype + ```c void p8est_lid_sub (const p8est_lid_t * a, const p8est_lid_t * b, p8est_lid_t * result); ``` """ function p8est_lid_sub(a, b, result) - @ccall libp4est.p8est_lid_sub(a::Ptr{p8est_lid_t}, b::Ptr{p8est_lid_t}, result::Ptr{p8est_lid_t})::Cvoid + @ccall libp4est.p8est_lid_sub( + a::Ptr{p8est_lid_t}, + b::Ptr{p8est_lid_t}, + result::Ptr{p8est_lid_t}, + )::Cvoid end """ @@ -11256,15 +14596,21 @@ end Calculates the bitwise negation of the uint128\\_t *a*. *a* == *result* is allowed. ### Parameters -* `a`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). -* `result`:\\[out\\] A pointer to a [`p8est_lid_t`](@ref). The bitwise negation of *a* will be saved in *result*. + + - `a`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + - `result`:\\[out\\] A pointer to a [`p8est_lid_t`](@ref). The bitwise negation of *a* will be saved in *result*. + ### Prototype + ```c void p8est_lid_bitwise_neg (const p8est_lid_t * a, p8est_lid_t * result); ``` """ function p8est_lid_bitwise_neg(a, result) - @ccall libp4est.p8est_lid_bitwise_neg(a::Ptr{p8est_lid_t}, result::Ptr{p8est_lid_t})::Cvoid + @ccall libp4est.p8est_lid_bitwise_neg( + a::Ptr{p8est_lid_t}, + result::Ptr{p8est_lid_t}, + )::Cvoid end """ @@ -11273,16 +14619,23 @@ end Calculates the bitwise or of the uint128\\_t *a* and *b*. *a* == *result* is allowed. Furthermore, *a* == *result* and/or *b* == *result* is allowed. ### Parameters -* `a`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). -* `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). -* `result`:\\[out\\] A pointer to a [`p8est_lid_t`](@ref). The bitwise or of *a* and *b* will be saved in *result*. + + - `a`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + - `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + - `result`:\\[out\\] A pointer to a [`p8est_lid_t`](@ref). The bitwise or of *a* and *b* will be saved in *result*. + ### Prototype + ```c void p8est_lid_bitwise_or (const p8est_lid_t * a, const p8est_lid_t * b, p8est_lid_t * result); ``` """ function p8est_lid_bitwise_or(a, b, result) - @ccall libp4est.p8est_lid_bitwise_or(a::Ptr{p8est_lid_t}, b::Ptr{p8est_lid_t}, result::Ptr{p8est_lid_t})::Cvoid + @ccall libp4est.p8est_lid_bitwise_or( + a::Ptr{p8est_lid_t}, + b::Ptr{p8est_lid_t}, + result::Ptr{p8est_lid_t}, + )::Cvoid end """ @@ -11291,16 +14644,23 @@ end Calculates the bitwise and of the uint128\\_t *a* and the uint128\\_t *b*. *a* == *result* is allowed. Furthermore, *a* == *result* and/or *b* == *result* is allowed. ### Parameters -* `a`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). -* `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). -* `result`:\\[out\\] A pointer to a [`p8est_lid_t`](@ref). The bitwise and of *a* and *b* will be saved. in *result*. + + - `a`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + - `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + - `result`:\\[out\\] A pointer to a [`p8est_lid_t`](@ref). The bitwise and of *a* and *b* will be saved. in *result*. + ### Prototype + ```c void p8est_lid_bitwise_and (const p8est_lid_t * a, const p8est_lid_t * b, p8est_lid_t * result); ``` """ function p8est_lid_bitwise_and(a, b, result) - @ccall libp4est.p8est_lid_bitwise_and(a::Ptr{p8est_lid_t}, b::Ptr{p8est_lid_t}, result::Ptr{p8est_lid_t})::Cvoid + @ccall libp4est.p8est_lid_bitwise_and( + a::Ptr{p8est_lid_t}, + b::Ptr{p8est_lid_t}, + result::Ptr{p8est_lid_t}, + )::Cvoid end """ @@ -11309,16 +14669,23 @@ end Calculates the bit right shift of uint128\\_t *input* by shift\\_count bits. We shift in zeros from the left. If *shift_count* >= 128, *result* is 0. All bits right from the zeroth bit (counted from the right hand side) drop out. *input* == *result* is allowed. ### Parameters -* `input`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). -* `shift_count`:\\[in\\] Bits to shift. *shift_count* >= 0. -* `result`:\\[in,out\\] A pointer to a [`p8est_lid_t`](@ref). The right shifted number will be saved in *result*. + + - `input`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + - `shift_count`:\\[in\\] Bits to shift. *shift_count* >= 0. + - `result`:\\[in,out\\] A pointer to a [`p8est_lid_t`](@ref). The right shifted number will be saved in *result*. + ### Prototype + ```c void p8est_lid_shift_right (const p8est_lid_t * input, unsigned shift_count, p8est_lid_t * result); ``` """ function p8est_lid_shift_right(input, shift_count, result) - @ccall libp4est.p8est_lid_shift_right(input::Ptr{p8est_lid_t}, shift_count::Cuint, result::Ptr{p8est_lid_t})::Cvoid + @ccall libp4est.p8est_lid_shift_right( + input::Ptr{p8est_lid_t}, + shift_count::Cuint, + result::Ptr{p8est_lid_t}, + )::Cvoid end """ @@ -11327,16 +14694,23 @@ end Calculates the bit left shift of uint128\\_t *input* by shift\\_count bits. We shift in zeros from the right. If *shift_count* >= 128, *result* is 0. All bits left from the 127th bit (counted zero based from the right hand side) drop out. *input* == *result* is allowed. ### Parameters -* `input`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). -* `shift_count`:\\[in\\] Bits to shift. *shift_count* >= 0. -* `result`:\\[in,out\\] A pointer to a [`p8est_lid_t`](@ref). The left shifted number will be saved in *result*. + + - `input`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + - `shift_count`:\\[in\\] Bits to shift. *shift_count* >= 0. + - `result`:\\[in,out\\] A pointer to a [`p8est_lid_t`](@ref). The left shifted number will be saved in *result*. + ### Prototype + ```c void p8est_lid_shift_left (const p8est_lid_t * input, unsigned shift_count, p8est_lid_t * result); ``` """ function p8est_lid_shift_left(input, shift_count, result) - @ccall libp4est.p8est_lid_shift_left(input::Ptr{p8est_lid_t}, shift_count::Cuint, result::Ptr{p8est_lid_t})::Cvoid + @ccall libp4est.p8est_lid_shift_left( + input::Ptr{p8est_lid_t}, + shift_count::Cuint, + result::Ptr{p8est_lid_t}, + )::Cvoid end """ @@ -11345,9 +14719,12 @@ end Adds the [`p8est_lid_t`](@ref) *b* to the [`p8est_lid_t`](@ref) *a*. The result is saved in *a*. *a* == *b* is allowed. ### Parameters -* `a`:\\[in,out\\] A pointer to a [`p8est_lid_t`](@ref). *a* will be overwritten by *a* + *b*. -* `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + + - `a`:\\[in,out\\] A pointer to a [`p8est_lid_t`](@ref). *a* will be overwritten by *a* + *b*. + - `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + ### Prototype + ```c void p8est_lid_add_inplace (p8est_lid_t * a, const p8est_lid_t * b); ``` @@ -11362,9 +14739,12 @@ end Substracts the uint128\\_t *b* from the uint128\\_t *a*. The result is saved in *a*. *a* == *b* is allowed. This function assumes that the result is >= 0. ### Parameters -* `a`:\\[in,out\\] A pointer to a [`p8est_lid_t`](@ref). *a* will be overwritten by *a* - *b*. -* `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + + - `a`:\\[in,out\\] A pointer to a [`p8est_lid_t`](@ref). *a* will be overwritten by *a* - *b*. + - `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + ### Prototype + ```c void p8est_lid_sub_inplace (p8est_lid_t * a, const p8est_lid_t * b); ``` @@ -11379,15 +14759,21 @@ end Calculates the bitwise or of the uint128\\_t *a* and the uint128\\_t *b*. *a* == *b* is allowed. ### Parameters -* `a`:\\[in,out\\] A pointer to a [`p8est_lid_t`](@ref). The bitwise or will be saved in *a*. -* `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + + - `a`:\\[in,out\\] A pointer to a [`p8est_lid_t`](@ref). The bitwise or will be saved in *a*. + - `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + ### Prototype + ```c void p8est_lid_bitwise_or_inplace (p8est_lid_t * a, const p8est_lid_t * b); ``` """ function p8est_lid_bitwise_or_inplace(a, b) - @ccall libp4est.p8est_lid_bitwise_or_inplace(a::Ptr{p8est_lid_t}, b::Ptr{p8est_lid_t})::Cvoid + @ccall libp4est.p8est_lid_bitwise_or_inplace( + a::Ptr{p8est_lid_t}, + b::Ptr{p8est_lid_t}, + )::Cvoid end """ @@ -11396,15 +14782,21 @@ end Calculates the bitwise and of the uint128\\_t *a* and the uint128\\_t *b*. *a* == *b* is allowed. ### Parameters -* `a`:\\[in,out\\] A pointer to a [`p8est_lid_t`](@ref). The bitwise and will be saved in *a*. -* `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + + - `a`:\\[in,out\\] A pointer to a [`p8est_lid_t`](@ref). The bitwise and will be saved in *a*. + - `b`:\\[in\\] A pointer to a [`p8est_lid_t`](@ref). + ### Prototype + ```c void p8est_lid_bitwise_and_inplace (p8est_lid_t * a, const p8est_lid_t * b); ``` """ function p8est_lid_bitwise_and_inplace(a, b) - @ccall libp4est.p8est_lid_bitwise_and_inplace(a::Ptr{p8est_lid_t}, b::Ptr{p8est_lid_t})::Cvoid + @ccall libp4est.p8est_lid_bitwise_and_inplace( + a::Ptr{p8est_lid_t}, + b::Ptr{p8est_lid_t}, + )::Cvoid end """ @@ -11417,16 +14809,23 @@ Computes the linear position as [`p8est_lid_t`](@ref) of a quadrant in a uniform The user\\_data of *quadrant* is never modified. ### Parameters -* `quadrant`:\\[in\\] Quadrant whose linear index will be computed. If the quadrant is smaller than the grid (has a higher quadrant->level), the result is computed from its ancestor at the grid's level. If the quadrant has a smaller level than the grid (it is bigger than a grid cell), the grid cell sharing its lower left corner is used as reference. -* `level`:\\[in\\] The level of the regular grid compared to which the linear position is to be computed. -* `id`:\\[in,out\\] A pointer to an allocated or static [`p8est_lid_t`](@ref). id will be the linear position of this quadrant on a uniform grid. + + - `quadrant`:\\[in\\] Quadrant whose linear index will be computed. If the quadrant is smaller than the grid (has a higher quadrant->level), the result is computed from its ancestor at the grid's level. If the quadrant has a smaller level than the grid (it is bigger than a grid cell), the grid cell sharing its lower left corner is used as reference. + - `level`:\\[in\\] The level of the regular grid compared to which the linear position is to be computed. + - `id`:\\[in,out\\] A pointer to an allocated or static [`p8est_lid_t`](@ref). id will be the linear position of this quadrant on a uniform grid. + ### Prototype + ```c void p8est_quadrant_linear_id_ext128 (const p8est_quadrant_t * quadrant, int level, p8est_lid_t * id); ``` """ function p8est_quadrant_linear_id_ext128(quadrant, level, id) - @ccall libp4est.p8est_quadrant_linear_id_ext128(quadrant::Ptr{p8est_quadrant_t}, level::Cint, id::Ptr{p8est_lid_t})::Cvoid + @ccall libp4est.p8est_quadrant_linear_id_ext128( + quadrant::Ptr{p8est_quadrant_t}, + level::Cint, + id::Ptr{p8est_lid_t}, + )::Cvoid end """ @@ -11439,28 +14838,54 @@ Set quadrant Morton indices based on linear position given as [`p8est_lid_t`](@r The user\\_data of *quadrant* is never modified. ### Parameters -* `quadrant`:\\[in,out\\] Quadrant whose Morton indices will be set. -* `level`:\\[in\\] Level of the grid and of the resulting quadrant. -* `id`:\\[in\\] Linear index of the quadrant on a uniform grid. + + - `quadrant`:\\[in,out\\] Quadrant whose Morton indices will be set. + - `level`:\\[in\\] Level of the grid and of the resulting quadrant. + - `id`:\\[in\\] Linear index of the quadrant on a uniform grid. + ### Prototype + ```c void p8est_quadrant_set_morton_ext128 (p8est_quadrant_t * quadrant, int level, const p8est_lid_t * id); ``` """ function p8est_quadrant_set_morton_ext128(quadrant, level, id) - @ccall libp4est.p8est_quadrant_set_morton_ext128(quadrant::Ptr{p8est_quadrant_t}, level::Cint, id::Ptr{p8est_lid_t})::Cvoid + @ccall libp4est.p8est_quadrant_set_morton_ext128( + quadrant::Ptr{p8est_quadrant_t}, + level::Cint, + id::Ptr{p8est_lid_t}, + )::Cvoid end """ p8est_new_ext(mpicomm, connectivity, min_quadrants, min_level, fill_uniform, data_size, init_fn, user_pointer) ### Prototype + ```c p8est_t *p8est_new_ext (sc_MPI_Comm mpicomm, p8est_connectivity_t * connectivity, p4est_locidx_t min_quadrants, int min_level, int fill_uniform, size_t data_size, p8est_init_t init_fn, void *user_pointer); ``` """ -function p8est_new_ext(mpicomm, connectivity, min_quadrants, min_level, fill_uniform, data_size, init_fn, user_pointer) - @ccall libp4est.p8est_new_ext(mpicomm::MPI_Comm, connectivity::Ptr{p8est_connectivity_t}, min_quadrants::p4est_locidx_t, min_level::Cint, fill_uniform::Cint, data_size::Csize_t, init_fn::p8est_init_t, user_pointer::Ptr{Cvoid})::Ptr{p8est_t} +function p8est_new_ext( + mpicomm, + connectivity, + min_quadrants, + min_level, + fill_uniform, + data_size, + init_fn, + user_pointer, +) + @ccall libp4est.p8est_new_ext( + mpicomm::MPI_Comm, + connectivity::Ptr{p8est_connectivity_t}, + min_quadrants::p4est_locidx_t, + min_level::Cint, + fill_uniform::Cint, + data_size::Csize_t, + init_fn::p8est_init_t, + user_pointer::Ptr{Cvoid}, + )::Ptr{p8est_t} end """ @@ -11469,20 +14894,31 @@ end Create a new mesh. ### Parameters -* `p8est`:\\[in\\] A forest that is fully 2:1 balanced. -* `ghost`:\\[in\\] The ghost layer created from the provided `p4est`. -* `compute_tree_index`:\\[in\\] Boolean to decide whether to allocate and compute the quad\\_to\\_tree list. -* `compute_level_lists`:\\[in\\] Boolean to decide whether to compute the level lists in quad\\_level. -* `btype`:\\[in\\] Currently ignored, only face neighbors are stored. + + - `p8est`:\\[in\\] A forest that is fully 2:1 balanced. + - `ghost`:\\[in\\] The ghost layer created from the provided `p4est`. + - `compute_tree_index`:\\[in\\] Boolean to decide whether to allocate and compute the quad\\_to\\_tree list. + - `compute_level_lists`:\\[in\\] Boolean to decide whether to compute the level lists in quad\\_level. + - `btype`:\\[in\\] Currently ignored, only face neighbors are stored. + ### Returns + A fully allocated mesh structure. + ### Prototype + ```c p8est_mesh_t *p8est_mesh_new_ext (p8est_t * p4est, p8est_ghost_t * ghost, int compute_tree_index, int compute_level_lists, p8est_connect_type_t btype); ``` """ function p8est_mesh_new_ext(p4est_, ghost, compute_tree_index, compute_level_lists, btype) - @ccall libp4est.p8est_mesh_new_ext(p4est_::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t}, compute_tree_index::Cint, compute_level_lists::Cint, btype::p8est_connect_type_t)::Ptr{p8est_mesh_t} + @ccall libp4est.p8est_mesh_new_ext( + p4est_::Ptr{p8est_t}, + ghost::Ptr{p8est_ghost_t}, + compute_tree_index::Cint, + compute_level_lists::Cint, + btype::p8est_connect_type_t, + )::Ptr{p8est_mesh_t} end """ @@ -11491,17 +14927,26 @@ end Make a deep copy of a `p8est`. The connectivity is not duplicated. Copying of quadrant user data is optional. If old and new data sizes are 0, the user\\_data field is copied regardless. The inspect member of the copy is set to NULL. The revision counter of the copy is set to zero. ### Parameters -* `copy_data`:\\[in\\] If true, data are copied. If false, data\\_size is set to 0. -* `duplicate_mpicomm`:\\[in\\] If true, MPI communicator is copied. + + - `copy_data`:\\[in\\] If true, data are copied. If false, data\\_size is set to 0. + - `duplicate_mpicomm`:\\[in\\] If true, MPI communicator is copied. + ### Returns + Returns a valid `p8est` that does not depend on the input, except for borrowing the same connectivity. Its revision counter is 0. + ### Prototype + ```c p8est_t *p8est_copy_ext (p8est_t * input, int copy_data, int duplicate_mpicomm); ``` """ function p8est_copy_ext(input, copy_data, duplicate_mpicomm) - @ccall libp4est.p8est_copy_ext(input::Ptr{p8est_t}, copy_data::Cint, duplicate_mpicomm::MPI_Comm)::Ptr{p8est_t} + @ccall libp4est.p8est_copy_ext( + input::Ptr{p8est_t}, + copy_data::Cint, + duplicate_mpicomm::MPI_Comm, + )::Ptr{p8est_t} end """ @@ -11510,19 +14955,36 @@ end Refine a forest with a bounded refinement level and a replace option. ### Parameters -* `p8est`:\\[in,out\\] The forest is changed in place. -* `refine_recursive`:\\[in\\] Boolean to decide on recursive refinement. -* `maxlevel`:\\[in\\] Maximum allowed refinement level (inclusive). If this is negative the level is restricted only by the compile-time constant QMAXLEVEL in `p8est.h`. -* `refine_fn`:\\[in\\] Callback function that must return true if a quadrant shall be refined. If refine\\_recursive is true, refine\\_fn is called for every existing and newly created quadrant. Otherwise, it is called for every existing quadrant. It is possible that a refinement request made by the callback is ignored. To catch this case, you can examine whether init\\_fn or replace\\_fn gets called. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data for newly created quadrants, which is guaranteed to be allocated. This function pointer may be NULL. -* `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace; may be NULL. + + - `p8est`:\\[in,out\\] The forest is changed in place. + - `refine_recursive`:\\[in\\] Boolean to decide on recursive refinement. + - `maxlevel`:\\[in\\] Maximum allowed refinement level (inclusive). If this is negative the level is restricted only by the compile-time constant QMAXLEVEL in `p8est.h`. + - `refine_fn`:\\[in\\] Callback function that must return true if a quadrant shall be refined. If refine\\_recursive is true, refine\\_fn is called for every existing and newly created quadrant. Otherwise, it is called for every existing quadrant. It is possible that a refinement request made by the callback is ignored. To catch this case, you can examine whether init\\_fn or replace\\_fn gets called. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data for newly created quadrants, which is guaranteed to be allocated. This function pointer may be NULL. + - `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace; may be NULL. + ### Prototype + ```c void p8est_refine_ext (p8est_t * p8est, int refine_recursive, int maxlevel, p8est_refine_t refine_fn, p8est_init_t init_fn, p8est_replace_t replace_fn); ``` """ -function p8est_refine_ext(p8est_, refine_recursive, maxlevel, refine_fn, init_fn, replace_fn) - @ccall libp4est.p8est_refine_ext(p8est_::Ptr{p8est_t}, refine_recursive::Cint, maxlevel::Cint, refine_fn::p8est_refine_t, init_fn::p8est_init_t, replace_fn::p8est_replace_t)::Cvoid +function p8est_refine_ext( + p8est_, + refine_recursive, + maxlevel, + refine_fn, + init_fn, + replace_fn, +) + @ccall libp4est.p8est_refine_ext( + p8est_::Ptr{p8est_t}, + refine_recursive::Cint, + maxlevel::Cint, + refine_fn::p8est_refine_t, + init_fn::p8est_init_t, + replace_fn::p8est_replace_t, + )::Cvoid end """ @@ -11531,19 +14993,36 @@ end Coarsen a forest. ### Parameters -* `p8est`:\\[in,out\\] The forest is changed in place. -* `coarsen_recursive`:\\[in\\] Boolean to decide on recursive coarsening. -* `callback_orphans`:\\[in\\] Boolean to enable calling coarsen\\_fn even on non-families. In this case, the second quadrant pointer in the argument list of the callback is NULL, subsequent pointers are undefined, and the return value is ignored. If coarsen\\_recursive is true, it is possible that a quadrant is called once or more as an orphan and eventually becomes part of a family. With coarsen\\_recursive false and callback\\_orphans true, it is guaranteed that every quadrant is passed exactly once into the coarsen\\_fn callback. -* `coarsen_fn`:\\[in\\] Callback function that returns true if a family of quadrants shall be coarsened. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. -* `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace. + + - `p8est`:\\[in,out\\] The forest is changed in place. + - `coarsen_recursive`:\\[in\\] Boolean to decide on recursive coarsening. + - `callback_orphans`:\\[in\\] Boolean to enable calling coarsen\\_fn even on non-families. In this case, the second quadrant pointer in the argument list of the callback is NULL, subsequent pointers are undefined, and the return value is ignored. If coarsen\\_recursive is true, it is possible that a quadrant is called once or more as an orphan and eventually becomes part of a family. With coarsen\\_recursive false and callback\\_orphans true, it is guaranteed that every quadrant is passed exactly once into the coarsen\\_fn callback. + - `coarsen_fn`:\\[in\\] Callback function that returns true if a family of quadrants shall be coarsened. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + - `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace. + ### Prototype + ```c void p8est_coarsen_ext (p8est_t * p8est, int coarsen_recursive, int callback_orphans, p8est_coarsen_t coarsen_fn, p8est_init_t init_fn, p8est_replace_t replace_fn); ``` """ -function p8est_coarsen_ext(p8est_, coarsen_recursive, callback_orphans, coarsen_fn, init_fn, replace_fn) - @ccall libp4est.p8est_coarsen_ext(p8est_::Ptr{p8est_t}, coarsen_recursive::Cint, callback_orphans::Cint, coarsen_fn::p8est_coarsen_t, init_fn::p8est_init_t, replace_fn::p8est_replace_t)::Cvoid +function p8est_coarsen_ext( + p8est_, + coarsen_recursive, + callback_orphans, + coarsen_fn, + init_fn, + replace_fn, +) + @ccall libp4est.p8est_coarsen_ext( + p8est_::Ptr{p8est_t}, + coarsen_recursive::Cint, + callback_orphans::Cint, + coarsen_fn::p8est_coarsen_t, + init_fn::p8est_init_t, + replace_fn::p8est_replace_t, + )::Cvoid end """ @@ -11552,29 +15031,44 @@ end 2:1 balance the size differences of neighboring elements in a forest. ### Parameters -* `p8est`:\\[in,out\\] The `p8est` to be worked on. -* `btype`:\\[in\\] Balance type (face, edge, or corner/full). Corner balance is almost never required when discretizing a PDE; just causes smoother mesh grading. -* `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. -* `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace. + + - `p8est`:\\[in,out\\] The `p8est` to be worked on. + - `btype`:\\[in\\] Balance type (face, edge, or corner/full). Corner balance is almost never required when discretizing a PDE; just causes smoother mesh grading. + - `init_fn`:\\[in\\] Callback function to initialize the user\\_data which is already allocated automatically. + - `replace_fn`:\\[in\\] Callback function that allows the user to change incoming quadrants based on the quadrants they replace. + ### Prototype + ```c void p8est_balance_ext (p8est_t * p8est, p8est_connect_type_t btype, p8est_init_t init_fn, p8est_replace_t replace_fn); ``` """ function p8est_balance_ext(p8est_, btype, init_fn, replace_fn) - @ccall libp4est.p8est_balance_ext(p8est_::Ptr{p8est_t}, btype::p8est_connect_type_t, init_fn::p8est_init_t, replace_fn::p8est_replace_t)::Cvoid + @ccall libp4est.p8est_balance_ext( + p8est_::Ptr{p8est_t}, + btype::p8est_connect_type_t, + init_fn::p8est_init_t, + replace_fn::p8est_replace_t, + )::Cvoid end """ p8est_balance_subtree_ext(p8est_, btype, which_tree, init_fn, replace_fn) ### Prototype + ```c void p8est_balance_subtree_ext (p8est_t * p8est, p8est_connect_type_t btype, p4est_topidx_t which_tree, p8est_init_t init_fn, p8est_replace_t replace_fn); ``` """ function p8est_balance_subtree_ext(p8est_, btype, which_tree, init_fn, replace_fn) - @ccall libp4est.p8est_balance_subtree_ext(p8est_::Ptr{p8est_t}, btype::p8est_connect_type_t, which_tree::p4est_topidx_t, init_fn::p8est_init_t, replace_fn::p8est_replace_t)::Cvoid + @ccall libp4est.p8est_balance_subtree_ext( + p8est_::Ptr{p8est_t}, + btype::p8est_connect_type_t, + which_tree::p4est_topidx_t, + init_fn::p8est_init_t, + replace_fn::p8est_replace_t, + )::Cvoid end """ @@ -11585,18 +15079,27 @@ Repartition the forest. The forest is partitioned between processors such that each processor has an approximately equal number of quadrants (or weight). ### Parameters -* `p8est`:\\[in,out\\] The forest that will be partitioned. -* `partition_for_coarsening`:\\[in\\] If true, the partition is modified to allow one level of coarsening. -* `weight_fn`:\\[in\\] A weighting function or NULL for uniform partitioning. A weighting function with constant weight 1 on each quadrant is equivalent to weight\\_fn == NULL but other constant weightings may result in different uniform partitionings. + + - `p8est`:\\[in,out\\] The forest that will be partitioned. + - `partition_for_coarsening`:\\[in\\] If true, the partition is modified to allow one level of coarsening. + - `weight_fn`:\\[in\\] A weighting function or NULL for uniform partitioning. A weighting function with constant weight 1 on each quadrant is equivalent to weight\\_fn == NULL but other constant weightings may result in different uniform partitionings. + ### Returns + The global number of shipped quadrants + ### Prototype + ```c p4est_gloidx_t p8est_partition_ext (p8est_t * p8est, int partition_for_coarsening, p8est_weight_t weight_fn); ``` """ function p8est_partition_ext(p8est_, partition_for_coarsening, weight_fn) - @ccall libp4est.p8est_partition_ext(p8est_::Ptr{p8est_t}, partition_for_coarsening::Cint, weight_fn::p8est_weight_t)::p4est_gloidx_t + @ccall libp4est.p8est_partition_ext( + p8est_::Ptr{p8est_t}, + partition_for_coarsening::Cint, + weight_fn::p8est_weight_t, + )::p4est_gloidx_t end """ @@ -11605,17 +15108,25 @@ end Correct partition to allow one level of coarsening. ### Parameters -* `p8est`:\\[in\\] forest whose partition is corrected -* `num_quadrants_in_proc`:\\[in,out\\] partition that will be corrected + + - `p8est`:\\[in\\] forest whose partition is corrected + - `num_quadrants_in_proc`:\\[in,out\\] partition that will be corrected + ### Returns + absolute number of moved quadrants + ### Prototype + ```c p4est_gloidx_t p8est_partition_for_coarsening (p8est_t * p8est, p4est_locidx_t * num_quadrants_in_proc); ``` """ function p8est_partition_for_coarsening(p8est_, num_quadrants_in_proc) - @ccall libp4est.p8est_partition_for_coarsening(p8est_::Ptr{p8est_t}, num_quadrants_in_proc::Ptr{p4est_locidx_t})::p4est_gloidx_t + @ccall libp4est.p8est_partition_for_coarsening( + p8est_::Ptr{p8est_t}, + num_quadrants_in_proc::Ptr{p4est_locidx_t}, + )::p4est_gloidx_t end """ @@ -11624,12 +15135,31 @@ end [`p8est_iterate_ext`](@ref) adds the option *remote*: if this is false, then it is the same as [`p8est_iterate`](@ref); if this is true, then corner/edge callbacks are also called on corners/edges for hanging faces/edges touched by local quadrants. ### Prototype + ```c void p8est_iterate_ext (p8est_t * p8est, p8est_ghost_t * ghost_layer, void *user_data, p8est_iter_volume_t iter_volume, p8est_iter_face_t iter_face, p8est_iter_edge_t iter_edge, p8est_iter_corner_t iter_corner, int remote); ``` """ -function p8est_iterate_ext(p8est_, ghost_layer, user_data, iter_volume, iter_face, iter_edge, iter_corner, remote) - @ccall libp4est.p8est_iterate_ext(p8est_::Ptr{p8est_t}, ghost_layer::Ptr{p8est_ghost_t}, user_data::Ptr{Cvoid}, iter_volume::p8est_iter_volume_t, iter_face::p8est_iter_face_t, iter_edge::p8est_iter_edge_t, iter_corner::p8est_iter_corner_t, remote::Cint)::Cvoid +function p8est_iterate_ext( + p8est_, + ghost_layer, + user_data, + iter_volume, + iter_face, + iter_edge, + iter_corner, + remote, +) + @ccall libp4est.p8est_iterate_ext( + p8est_::Ptr{p8est_t}, + ghost_layer::Ptr{p8est_ghost_t}, + user_data::Ptr{Cvoid}, + iter_volume::p8est_iter_volume_t, + iter_face::p8est_iter_face_t, + iter_edge::p8est_iter_edge_t, + iter_corner::p8est_iter_corner_t, + remote::Cint, + )::Cvoid end """ @@ -11642,41 +15172,87 @@ Save the complete connectivity/`p8est` data to disk. This is a collective operat Aborts on file errors. ### Parameters -* `filename`:\\[in\\] Name of the file to write. -* `p8est`:\\[in\\] Valid forest structure. -* `save_data`:\\[in\\] If true, the element data is saved. Otherwise, a data size of 0 is saved. -* `save_partition`:\\[in\\] If false, save file as if 1 core was used. If true, save core count and partition. Advantage: Partition can be recovered on loading with same mpisize and autopartition false. Disadvantage: Makes the file depend on mpisize. Either way the file can be loaded with autopartition true. + + - `filename`:\\[in\\] Name of the file to write. + - `p8est`:\\[in\\] Valid forest structure. + - `save_data`:\\[in\\] If true, the element data is saved. Otherwise, a data size of 0 is saved. + - `save_partition`:\\[in\\] If false, save file as if 1 core was used. If true, save core count and partition. Advantage: Partition can be recovered on loading with same mpisize and autopartition false. Disadvantage: Makes the file depend on mpisize. Either way the file can be loaded with autopartition true. + ### Prototype + ```c void p8est_save_ext (const char *filename, p8est_t * p8est, int save_data, int save_partition); ``` """ function p8est_save_ext(filename, p8est_, save_data, save_partition) - @ccall libp4est.p8est_save_ext(filename::Cstring, p8est_::Ptr{p8est_t}, save_data::Cint, save_partition::Cint)::Cvoid + @ccall libp4est.p8est_save_ext( + filename::Cstring, + p8est_::Ptr{p8est_t}, + save_data::Cint, + save_partition::Cint, + )::Cvoid end """ p8est_load_ext(filename, mpicomm, data_size, load_data, autopartition, broadcasthead, user_pointer, connectivity) ### Prototype + ```c p8est_t *p8est_load_ext (const char *filename, sc_MPI_Comm mpicomm, size_t data_size, int load_data, int autopartition, int broadcasthead, void *user_pointer, p8est_connectivity_t ** connectivity); ``` """ -function p8est_load_ext(filename, mpicomm, data_size, load_data, autopartition, broadcasthead, user_pointer, connectivity) - @ccall libp4est.p8est_load_ext(filename::Cstring, mpicomm::MPI_Comm, data_size::Csize_t, load_data::Cint, autopartition::Cint, broadcasthead::Cint, user_pointer::Ptr{Cvoid}, connectivity::Ptr{Ptr{p8est_connectivity_t}})::Ptr{p8est_t} +function p8est_load_ext( + filename, + mpicomm, + data_size, + load_data, + autopartition, + broadcasthead, + user_pointer, + connectivity, +) + @ccall libp4est.p8est_load_ext( + filename::Cstring, + mpicomm::MPI_Comm, + data_size::Csize_t, + load_data::Cint, + autopartition::Cint, + broadcasthead::Cint, + user_pointer::Ptr{Cvoid}, + connectivity::Ptr{Ptr{p8est_connectivity_t}}, + )::Ptr{p8est_t} end """ p8est_source_ext(src, mpicomm, data_size, load_data, autopartition, broadcasthead, user_pointer, connectivity) ### Prototype + ```c p8est_t *p8est_source_ext (sc_io_source_t * src, sc_MPI_Comm mpicomm, size_t data_size, int load_data, int autopartition, int broadcasthead, void *user_pointer, p8est_connectivity_t ** connectivity); ``` """ -function p8est_source_ext(src, mpicomm, data_size, load_data, autopartition, broadcasthead, user_pointer, connectivity) - @ccall libp4est.p8est_source_ext(src::Ptr{sc_io_source_t}, mpicomm::MPI_Comm, data_size::Csize_t, load_data::Cint, autopartition::Cint, broadcasthead::Cint, user_pointer::Ptr{Cvoid}, connectivity::Ptr{Ptr{p8est_connectivity_t}})::Ptr{p8est_t} +function p8est_source_ext( + src, + mpicomm, + data_size, + load_data, + autopartition, + broadcasthead, + user_pointer, + connectivity, +) + @ccall libp4est.p8est_source_ext( + src::Ptr{sc_io_source_t}, + mpicomm::MPI_Comm, + data_size::Csize_t, + load_data::Cint, + autopartition::Cint, + broadcasthead::Cint, + user_pointer::Ptr{Cvoid}, + connectivity::Ptr{Ptr{p8est_connectivity_t}}, + )::Ptr{p8est_t} end """ @@ -11687,30 +15263,69 @@ Create the data necessary to create a PETsc DMPLEX representation of a forest, a All arrays should be initialized to hold sizeof ([`p4est_locidx_t`](@ref)), except for *out_remotes*, which should be initialized to hold (2 * sizeof ([`p4est_locidx_t`](@ref))). ### Parameters -* `p8est`:\\[in\\] the forest -* `ghost`:\\[out\\] the ghost layer -* `lnodes`:\\[out\\] the lnodes -* `ctype`:\\[in\\] the type of adjacency for the overlap -* `overlap`:\\[in\\] the number of layers of overlap (zero is acceptable) -* `first_local_quad`:\\[out\\] the local quadrants are assigned contiguous plex indices, starting with this index -* `out_points_per_dim`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() -* `out_cone_sizes`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() -* `out_cones`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() -* `out_cone_orientations`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() -* `out_vertex_coords`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() -* `out_children`:\\[in,out\\] filled with argument for DMPlexSetTree() -* `out_parents`:\\[in,out\\] filled with argument for DMPlexSetTree() -* `out_childids`:\\[in,out\\] filled with argument for DMPlexSetTree() -* `out_leaves`:\\[in,out\\] filled with argument for PetscSFSetGraph() -* `out_remotes`:\\[in,out\\] filled with argument for PetscSFSetGraph() -* `custom_numbering`:\\[in\\] Whether or use the default numbering (0) of DMPlex child ids or the custom (1). + + - `p8est`:\\[in\\] the forest + - `ghost`:\\[out\\] the ghost layer + - `lnodes`:\\[out\\] the lnodes + - `ctype`:\\[in\\] the type of adjacency for the overlap + - `overlap`:\\[in\\] the number of layers of overlap (zero is acceptable) + - `first_local_quad`:\\[out\\] the local quadrants are assigned contiguous plex indices, starting with this index + - `out_points_per_dim`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() + - `out_cone_sizes`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() + - `out_cones`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() + - `out_cone_orientations`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() + - `out_vertex_coords`:\\[in,out\\] filled with argument for DMPlexCreateFromDAG() + - `out_children`:\\[in,out\\] filled with argument for DMPlexSetTree() + - `out_parents`:\\[in,out\\] filled with argument for DMPlexSetTree() + - `out_childids`:\\[in,out\\] filled with argument for DMPlexSetTree() + - `out_leaves`:\\[in,out\\] filled with argument for PetscSFSetGraph() + - `out_remotes`:\\[in,out\\] filled with argument for PetscSFSetGraph() + - `custom_numbering`:\\[in\\] Whether or use the default numbering (0) of DMPlex child ids or the custom (1). + ### Prototype + ```c void p8est_get_plex_data_ext (p8est_t * p8est, p8est_ghost_t ** ghost, p8est_lnodes_t ** lnodes, p8est_connect_type_t ctype, int overlap, p4est_locidx_t * first_local_quad, sc_array_t * out_points_per_dim, sc_array_t * out_cone_sizes, sc_array_t * out_cones, sc_array_t * out_cone_orientations, sc_array_t * out_vertex_coords, sc_array_t * out_children, sc_array_t * out_parents, sc_array_t * out_childids, sc_array_t * out_leaves, sc_array_t * out_remotes, int custom_numbering); ``` """ -function p8est_get_plex_data_ext(p8est_, ghost, lnodes, ctype, overlap, first_local_quad, out_points_per_dim, out_cone_sizes, out_cones, out_cone_orientations, out_vertex_coords, out_children, out_parents, out_childids, out_leaves, out_remotes, custom_numbering) - @ccall libp4est.p8est_get_plex_data_ext(p8est_::Ptr{p8est_t}, ghost::Ptr{Ptr{p8est_ghost_t}}, lnodes::Ptr{Ptr{p8est_lnodes_t}}, ctype::p8est_connect_type_t, overlap::Cint, first_local_quad::Ptr{p4est_locidx_t}, out_points_per_dim::Ptr{sc_array_t}, out_cone_sizes::Ptr{sc_array_t}, out_cones::Ptr{sc_array_t}, out_cone_orientations::Ptr{sc_array_t}, out_vertex_coords::Ptr{sc_array_t}, out_children::Ptr{sc_array_t}, out_parents::Ptr{sc_array_t}, out_childids::Ptr{sc_array_t}, out_leaves::Ptr{sc_array_t}, out_remotes::Ptr{sc_array_t}, custom_numbering::Cint)::Cvoid +function p8est_get_plex_data_ext( + p8est_, + ghost, + lnodes, + ctype, + overlap, + first_local_quad, + out_points_per_dim, + out_cone_sizes, + out_cones, + out_cone_orientations, + out_vertex_coords, + out_children, + out_parents, + out_childids, + out_leaves, + out_remotes, + custom_numbering, +) + @ccall libp4est.p8est_get_plex_data_ext( + p8est_::Ptr{p8est_t}, + ghost::Ptr{Ptr{p8est_ghost_t}}, + lnodes::Ptr{Ptr{p8est_lnodes_t}}, + ctype::p8est_connect_type_t, + overlap::Cint, + first_local_quad::Ptr{p4est_locidx_t}, + out_points_per_dim::Ptr{sc_array_t}, + out_cone_sizes::Ptr{sc_array_t}, + out_cones::Ptr{sc_array_t}, + out_cone_orientations::Ptr{sc_array_t}, + out_vertex_coords::Ptr{sc_array_t}, + out_children::Ptr{sc_array_t}, + out_parents::Ptr{sc_array_t}, + out_childids::Ptr{sc_array_t}, + out_leaves::Ptr{sc_array_t}, + out_remotes::Ptr{sc_array_t}, + custom_numbering::Cint, + )::Cvoid end """ @@ -11719,19 +15334,29 @@ end Binary search in partition array. Given two targets *my_begin* and *my_end*, find offsets such that `search\\_in[begin] >= my\\_begin`, `my\\_end <= search\\_in[end]`. If more than one index satisfies the conditions, then the minimal index is the result. If there is no index that satisfies the conditions, then *begin* and *end* are tried to set equal such that `search\\_in[begin] >= my\\_end`. If *my_begin* is less or equal than the smallest value of *search_in* *begin* is set to 0 and if *my_end* is bigger or equal than the largest value of *search_in* *end* is set to *num_procs* - 1. If none of the above conditions is satisfied, the output is not well defined. We require `my\\_begin <= my\\_begin'. ### Parameters -* `num_procs`:\\[in\\] Number of processes to get the length of *search_in*. -* `search_in`:\\[in\\] The sorted array (ascending) in that the function will search. If `k` indexes search\\_in, then `0 <= k < num\\_procs`. -* `my_begin`:\\[in\\] The first target that defines the start of the search window. -* `my_end`:\\[in\\] The second target that defines the end of the search window. -* `begin`:\\[in,out\\] The first offset such that `search\\_in[begin] >= my\\_begin`. -* `end`:\\[in,out\\] The second offset such that `my\\_end <= search\\_in[end]`. + + - `num_procs`:\\[in\\] Number of processes to get the length of *search_in*. + - `search_in`:\\[in\\] The sorted array (ascending) in that the function will search. If `k` indexes search\\_in, then `0 <= k < num\\_procs`. + - `my_begin`:\\[in\\] The first target that defines the start of the search window. + - `my_end`:\\[in\\] The second target that defines the end of the search window. + - `begin`:\\[in,out\\] The first offset such that `search\\_in[begin] >= my\\_begin`. + - `end`:\\[in,out\\] The second offset such that `my\\_end <= search\\_in[end]`. + ### Prototype + ```c void p8est_find_partition (const int num_procs, p4est_gloidx_t * search_in, p4est_gloidx_t my_begin, p4est_gloidx_t my_end, p4est_gloidx_t * begin, p4est_gloidx_t * end); ``` """ function p8est_find_partition(num_procs, search_in, my_begin, my_end, _begin, _end) - @ccall libp4est.p8est_find_partition(num_procs::Cint, search_in::Ptr{p4est_gloidx_t}, my_begin::p4est_gloidx_t, my_end::p4est_gloidx_t, _begin::Ptr{p4est_gloidx_t}, _end::Ptr{p4est_gloidx_t})::Cvoid + @ccall libp4est.p8est_find_partition( + num_procs::Cint, + search_in::Ptr{p4est_gloidx_t}, + my_begin::p4est_gloidx_t, + my_end::p4est_gloidx_t, + _begin::Ptr{p4est_gloidx_t}, + _end::Ptr{p4est_gloidx_t}, + )::Cvoid end """ @@ -11740,14 +15365,21 @@ end Find the lowest position tq in a quadrant array such that tq >= q. ### Returns + Returns the id of the matching quadrant or -1 if array < q or the array is empty. + ### Prototype + ```c ssize_t p8est_find_lower_bound (sc_array_t * array, const p8est_quadrant_t * q, size_t guess); ``` """ function p8est_find_lower_bound(array, q, guess) - @ccall libp4est.p8est_find_lower_bound(array::Ptr{sc_array_t}, q::Ptr{p8est_quadrant_t}, guess::Csize_t)::Cssize_t + @ccall libp4est.p8est_find_lower_bound( + array::Ptr{sc_array_t}, + q::Ptr{p8est_quadrant_t}, + guess::Csize_t, + )::Cssize_t end """ @@ -11756,14 +15388,21 @@ end Find the highest position tq in a quadrant array such that tq <= q. ### Returns + Returns the id of the matching quadrant or -1 if array > q or the array is empty. + ### Prototype + ```c ssize_t p8est_find_higher_bound (sc_array_t * array, const p8est_quadrant_t * q, size_t guess); ``` """ function p8est_find_higher_bound(array, q, guess) - @ccall libp4est.p8est_find_higher_bound(array::Ptr{sc_array_t}, q::Ptr{p8est_quadrant_t}, guess::Csize_t)::Cssize_t + @ccall libp4est.p8est_find_higher_bound( + array::Ptr{sc_array_t}, + q::Ptr{p8est_quadrant_t}, + guess::Csize_t, + )::Cssize_t end """ @@ -11774,19 +15413,29 @@ Search a local quadrant by its cumulative number in the forest. We perform a binary search over the processor-local trees, which means that it is advisable NOT to use this function if possible, and to try to maintain O(1) tree context information in the calling code. ### Parameters -* `p8est`:\\[in\\] Forest to be worked with. -* `cumulative_id`:\\[in\\] Cumulative index over all trees of quadrant. -* `which_tree`:\\[in,out\\] If not NULL, the input value can be -1 or an initial guess for the quadrant's tree. An initial guess must be the index of a nonempty local tree. Output is the tree of returned quadrant. -* `quadrant_id`:\\[out\\] If not NULL, the number of quadrant in tree. + + - `p8est`:\\[in\\] Forest to be worked with. + - `cumulative_id`:\\[in\\] Cumulative index over all trees of quadrant. + - `which_tree`:\\[in,out\\] If not NULL, the input value can be -1 or an initial guess for the quadrant's tree. An initial guess must be the index of a nonempty local tree. Output is the tree of returned quadrant. + - `quadrant_id`:\\[out\\] If not NULL, the number of quadrant in tree. + ### Returns + The identified quadrant. + ### Prototype + ```c p8est_quadrant_t *p8est_find_quadrant_cumulative (p8est_t * p8est, p4est_locidx_t cumulative_id, p4est_topidx_t * which_tree, p4est_locidx_t * quadrant_id); ``` """ function p8est_find_quadrant_cumulative(p8est_, cumulative_id, which_tree, quadrant_id) - @ccall libp4est.p8est_find_quadrant_cumulative(p8est_::Ptr{p8est_t}, cumulative_id::p4est_locidx_t, which_tree::Ptr{p4est_topidx_t}, quadrant_id::Ptr{p4est_locidx_t})::Ptr{p8est_quadrant_t} + @ccall libp4est.p8est_find_quadrant_cumulative( + p8est_::Ptr{p8est_t}, + cumulative_id::p4est_locidx_t, + which_tree::Ptr{p4est_topidx_t}, + quadrant_id::Ptr{p4est_locidx_t}, + )::Ptr{p8est_quadrant_t} end """ @@ -11797,16 +15446,23 @@ Split an array of quadrants by the children of an ancestor. Given a sorted **array** of quadrants that have a common ancestor at level **level**, compute the **indices** of the first quadrant in each of the common ancestor's children at level **level** + 1. ### Parameters -* `array`:\\[in\\] The sorted array of quadrants of level > **level**. -* `level`:\\[in\\] The level at which there is a common ancestor. -* `indices`:\\[in,out\\] The indices of the first quadrant in each of the ancestors's children, plus an additional index on the end. The quadrants of **array** that are descendants of child i have indices between indices[i] and indices[i + 1] - 1. If indices[i] = indices[i+1], this indicates that no quadrant in the array is contained in child i. + + - `array`:\\[in\\] The sorted array of quadrants of level > **level**. + - `level`:\\[in\\] The level at which there is a common ancestor. + - `indices`:\\[in,out\\] The indices of the first quadrant in each of the ancestors's children, plus an additional index on the end. The quadrants of **array** that are descendants of child i have indices between indices[i] and indices[i + 1] - 1. If indices[i] = indices[i+1], this indicates that no quadrant in the array is contained in child i. + ### Prototype + ```c void p8est_split_array (sc_array_t * array, int level, size_t indices[]); ``` """ function p8est_split_array(array, level, indices) - @ccall libp4est.p8est_split_array(array::Ptr{sc_array_t}, level::Cint, indices::Ptr{Csize_t})::Cvoid + @ccall libp4est.p8est_split_array( + array::Ptr{sc_array_t}, + level::Cint, + indices::Ptr{Csize_t}, + )::Cvoid end """ @@ -11817,21 +15473,33 @@ Find the boundary points touched by a range of quadrants. Given two smallest quadrants, **lq** and **uq**, that mark the first and the last quadrant in a range of quadrants, determine which portions of the tree boundary the range touches. ### Parameters -* `lq`:\\[in\\] The smallest quadrant at the start of the range: if NULL, the tree's first quadrant is taken to be the start of the range. -* `uq`:\\[in\\] The smallest quadrant at the end of the range: if NULL, the tree's last quadrant is taken to be the end of the range. -* `level`:\\[in\\] The level of the containing quadrant whose boundaries are tested: 0 if we want to test the boundaries of the whole tree. -* `faces`:\\[in,out\\] An array of size 6 that is filled: faces[i] is true if the range touches that face. -* `edges`:\\[in,out\\] An array of size 12 that is filled: edges[i] is true if the range touches that edge. -* `corners`:\\[in,out\\] An array of size 8 that is filled: corners[i] is true if the range touches that corner. **faces**, **edges** or **corners** may be NULL. + + - `lq`:\\[in\\] The smallest quadrant at the start of the range: if NULL, the tree's first quadrant is taken to be the start of the range. + - `uq`:\\[in\\] The smallest quadrant at the end of the range: if NULL, the tree's last quadrant is taken to be the end of the range. + - `level`:\\[in\\] The level of the containing quadrant whose boundaries are tested: 0 if we want to test the boundaries of the whole tree. + - `faces`:\\[in,out\\] An array of size 6 that is filled: faces[i] is true if the range touches that face. + - `edges`:\\[in,out\\] An array of size 12 that is filled: edges[i] is true if the range touches that edge. + - `corners`:\\[in,out\\] An array of size 8 that is filled: corners[i] is true if the range touches that corner. **faces**, **edges** or **corners** may be NULL. + ### Returns + Returns an int32\\_t encoded with the same information in **faces**, **edges** and **corners**: the first (least) six bits represent the six faces, the next twelve bits represent the twelve edges, the next eight bits represent the eight corners. + ### Prototype + ```c int32_t p8est_find_range_boundaries (p8est_quadrant_t * lq, p8est_quadrant_t * uq, int level, int faces[], int edges[], int corners[]); ``` """ function p8est_find_range_boundaries(lq, uq, level, faces, edges, corners) - @ccall libp4est.p8est_find_range_boundaries(lq::Ptr{p8est_quadrant_t}, uq::Ptr{p8est_quadrant_t}, level::Cint, faces::Ptr{Cint}, edges::Ptr{Cint}, corners::Ptr{Cint})::Int32 + @ccall libp4est.p8est_find_range_boundaries( + lq::Ptr{p8est_quadrant_t}, + uq::Ptr{p8est_quadrant_t}, + level::Cint, + faces::Ptr{Cint}, + edges::Ptr{Cint}, + corners::Ptr{Cint}, + )::Int32 end # typedef int ( * p8est_search_local_t ) ( p8est_t * p4est , p4est_topidx_t which_tree , p8est_quadrant_t * quadrant , p4est_locidx_t local_num , void * point ) @@ -11841,17 +15509,22 @@ Callback function to query the match of a "point" with a quadrant. This function can be called in two roles: Per-quadrant, in which case the parameter **point** is NULL, or per-point, possibly many times per quadrant. ### Parameters -* `p4est`:\\[in\\] The forest to be queried. -* `which_tree`:\\[in\\] The tree id under consideration. -* `quadrant`:\\[in\\] The quadrant under consideration. This quadrant may be coarser than the quadrants that are contained in the forest (an ancestor), in which case it is a temporary variable and not part of the forest storage. Otherwise, it is a leaf and points directly into the forest storage. -* `local_num`:\\[in\\] If the quadrant is not a leaf, this is < 0. Otherwise it is the (non-negative) index of the quadrant relative to the processor-local storage. -* `point`:\\[in\\] Representation of a "point"; user-defined. If **point** is NULL, the callback may be used to prepare quadrant-related search meta data. + + - `p4est`:\\[in\\] The forest to be queried. + - `which_tree`:\\[in\\] The tree id under consideration. + - `quadrant`:\\[in\\] The quadrant under consideration. This quadrant may be coarser than the quadrants that are contained in the forest (an ancestor), in which case it is a temporary variable and not part of the forest storage. Otherwise, it is a leaf and points directly into the forest storage. + - `local_num`:\\[in\\] If the quadrant is not a leaf, this is < 0. Otherwise it is the (non-negative) index of the quadrant relative to the processor-local storage. + - `point`:\\[in\\] Representation of a "point"; user-defined. If **point** is NULL, the callback may be used to prepare quadrant-related search meta data. + ### Returns + If **point** is NULL, true if the search confined to **quadrant** should be executed, false to skip it. Else, true if point may be contained in the quadrant and false otherwise; the return value has no effect on a leaf. """ const p8est_search_local_t = Ptr{Cvoid} -"""This typedef is provided for backwards compatibility.""" +""" +This typedef is provided for backwards compatibility. +""" const p8est_search_query_t = p8est_search_local_t """ @@ -11868,18 +15541,27 @@ If points are present and the first quadrant callback returned true, we execute If the points are a NULL array, they are ignored and the recursion proceeds by querying the per-quadrant callback. If the points are not NULL but an empty array, the recursion will stop immediately! ### Parameters -* `p4est`:\\[in\\] The forest to be searched. -* `call_post`:\\[in\\] If true, call quadrant callback both pre and post. -* `quadrant_fn`:\\[in\\] Executed once when a quadrant is entered, and once when it is left (the second time only if points are present and the first call returned true). This quadrant is always local, if not completely than at least one descendant of it. If the callback returns false, this quadrant and its descendants are excluded from the search recursion. Its **point** argument is always NULL. Callback may be NULL in which case it is ignored. -* `point_fn`:\\[in\\] If **points** is not NULL, must be not NULL. Shall return true for any possible matching point. If **points** is NULL, this callback is ignored. -* `points`:\\[in\\] User-defined array of "points". If NULL, only the **quadrant_fn** callback is executed. If that is NULL, this function noops. If not NULL, the **point_fn** is called on its members during the search. + + - `p4est`:\\[in\\] The forest to be searched. + - `call_post`:\\[in\\] If true, call quadrant callback both pre and post. + - `quadrant_fn`:\\[in\\] Executed once when a quadrant is entered, and once when it is left (the second time only if points are present and the first call returned true). This quadrant is always local, if not completely than at least one descendant of it. If the callback returns false, this quadrant and its descendants are excluded from the search recursion. Its **point** argument is always NULL. Callback may be NULL in which case it is ignored. + - `point_fn`:\\[in\\] If **points** is not NULL, must be not NULL. Shall return true for any possible matching point. If **points** is NULL, this callback is ignored. + - `points`:\\[in\\] User-defined array of "points". If NULL, only the **quadrant_fn** callback is executed. If that is NULL, this function noops. If not NULL, the **point_fn** is called on its members during the search. + ### Prototype + ```c void p8est_search_local (p8est_t * p4est, int call_post, p8est_search_local_t quadrant_fn, p8est_search_local_t point_fn, sc_array_t * points); ``` """ function p8est_search_local(p4est_, call_post, quadrant_fn, point_fn, points) - @ccall libp4est.p8est_search_local(p4est_::Ptr{p8est_t}, call_post::Cint, quadrant_fn::p8est_search_local_t, point_fn::p8est_search_local_t, points::Ptr{sc_array_t})::Cvoid + @ccall libp4est.p8est_search_local( + p4est_::Ptr{p8est_t}, + call_post::Cint, + quadrant_fn::p8est_search_local_t, + point_fn::p8est_search_local_t, + points::Ptr{sc_array_t}, + )::Cvoid end """ @@ -11888,12 +15570,18 @@ end This function is provided for backwards compatibility. We call p8est_search_local with call\\_post = 0. ### Prototype + ```c void p8est_search (p8est_t * p4est, p8est_search_query_t quadrant_fn, p8est_search_query_t point_fn, sc_array_t * points); ``` """ function p8est_search(p4est_, quadrant_fn, point_fn, points) - @ccall libp4est.p8est_search(p4est_::Ptr{p8est_t}, quadrant_fn::p8est_search_query_t, point_fn::p8est_search_query_t, points::Ptr{sc_array_t})::Cvoid + @ccall libp4est.p8est_search( + p4est_::Ptr{p8est_t}, + quadrant_fn::p8est_search_query_t, + point_fn::p8est_search_query_t, + points::Ptr{sc_array_t}, + )::Cvoid end # typedef int ( * p8est_search_partition_t ) ( p8est_t * p4est , p4est_topidx_t which_tree , p8est_quadrant_t * quadrant , int pfirst , int plast , void * point ) @@ -11901,13 +15589,16 @@ end Callback function for the partition recursion. ### Parameters -* `p4est`:\\[in\\] The forest to traverse. Its local quadrants are never accessed. -* `which_tree`:\\[in\\] The tree number under consideration. -* `quadrant`:\\[in\\] This quadrant is not from local forest storage, and its user data is undefined. It represents the branch of the forest in the top-down recursion. -* `pfirst`:\\[in\\] The lowest processor that owns part of **quadrant**. Guaranteed to be non-empty. -* `plast`:\\[in\\] The highest processor that owns part of **quadrant**. Guaranteed to be non-empty. If this is equal to **pfirst**, then the recursion will stop for **quadrant**'s branch after this function returns. -* `point`:\\[in,out\\] Pointer to a user-defined point object. If called per-quadrant, this is NULL. + + - `p4est`:\\[in\\] The forest to traverse. Its local quadrants are never accessed. + - `which_tree`:\\[in\\] The tree number under consideration. + - `quadrant`:\\[in\\] This quadrant is not from local forest storage, and its user data is undefined. It represents the branch of the forest in the top-down recursion. + - `pfirst`:\\[in\\] The lowest processor that owns part of **quadrant**. Guaranteed to be non-empty. + - `plast`:\\[in\\] The highest processor that owns part of **quadrant**. Guaranteed to be non-empty. If this is equal to **pfirst**, then the recursion will stop for **quadrant**'s branch after this function returns. + - `point`:\\[in,out\\] Pointer to a user-defined point object. If called per-quadrant, this is NULL. + ### Returns + If false, the recursion at quadrant is terminated. If true, it continues if **pfirst** < **plast**. """ const p8est_search_partition_t = Ptr{Cvoid} @@ -11922,18 +15613,27 @@ Traverse the global partition top-down. We proceed top-down through the partitio Traversing the whole processor partition will be at least O(P), so sensible use of the callback function is advised to cut it short. ### Parameters -* `p4est`:\\[in\\] The forest to traverse. Its local quadrants are never accessed. -* `call_post`:\\[in\\] If true, call quadrant callback both pre and post. -* `quadrant_fn`:\\[in\\] This function controls the recursion, which only continues deeper if this callback returns true for a branch quadrant. It is allowed to set this to NULL. -* `point_fn`:\\[in\\] This function decides per-point whether it is followed down the recursion. Must be non-NULL if **points** are not NULL. -* `points`:\\[in\\] User-provided array of **points** that are passed to the callback **point_fn**. See p8est_search_local for details. + + - `p4est`:\\[in\\] The forest to traverse. Its local quadrants are never accessed. + - `call_post`:\\[in\\] If true, call quadrant callback both pre and post. + - `quadrant_fn`:\\[in\\] This function controls the recursion, which only continues deeper if this callback returns true for a branch quadrant. It is allowed to set this to NULL. + - `point_fn`:\\[in\\] This function decides per-point whether it is followed down the recursion. Must be non-NULL if **points** are not NULL. + - `points`:\\[in\\] User-provided array of **points** that are passed to the callback **point_fn**. See p8est_search_local for details. + ### Prototype + ```c void p8est_search_partition (p8est_t * p4est, int call_post, p8est_search_partition_t quadrant_fn, p8est_search_partition_t point_fn, sc_array_t * points); ``` """ function p8est_search_partition(p4est_, call_post, quadrant_fn, point_fn, points) - @ccall libp4est.p8est_search_partition(p4est_::Ptr{p8est_t}, call_post::Cint, quadrant_fn::p8est_search_partition_t, point_fn::p8est_search_partition_t, points::Ptr{sc_array_t})::Cvoid + @ccall libp4est.p8est_search_partition( + p4est_::Ptr{p8est_t}, + call_post::Cint, + quadrant_fn::p8est_search_partition_t, + point_fn::p8est_search_partition_t, + points::Ptr{sc_array_t}, + )::Cvoid end # typedef int ( * p8est_search_all_t ) ( p8est_t * p8est , p4est_topidx_t which_tree , p8est_quadrant_t * quadrant , int pfirst , int plast , p4est_locidx_t local_num , void * point ) @@ -11941,14 +15641,17 @@ end Callback function for the top-down search through the whole forest. ### Parameters -* `p4est`:\\[in\\] The forest to search. We recurse through the trees one after another. -* `which_tree`:\\[in\\] The current tree number. -* `quadrant`:\\[in\\] The current quadrant in the recursion. This quadrant is either a non-leaf tree branch or a leaf. If the quadrant is contained in the local partition, we know which, otherwise we don't. Let us first consider the situation when **quadrant** is local, which is indicated by both **pfirst** and **plast** being equal to `p4est`->mpirank. Then the parameter **local_num** is negative for non-leaves and the number of the quadrant as a leaf in local storage otherwise. Only if the quadrant is a local leaf, it points to the actual local storage and can be used to access user data etc., and the recursion terminates. The other possibility is that **pfirst** < **plast**, in which case we proceed with the recursion, or both are equal to the same remote rank, in which case the recursion terminates. Either way, the quadrant is not from local forest storage. -* `pfirst`:\\[in\\] The lowest processor that owns part of **quadrant**. Guaranteed to be non-empty. -* `plast`:\\[in\\] The highest processor that owns part of **quadrant**. Guaranteed to be non-empty. -* `local_num`:\\[in\\] If **quadrant** is a local leaf, this number is the index of the leaf in local quadrant storage. Else, this is a negative value. -* `point`:\\[in,out\\] User-defined representation of a point. This parameter distinguishes two uses of the callback. For each quadrant, the callback is first called with a NULL point, and if this callback returns true, once for each point tracked in this branch. The return value for a point determines whether it shall be tracked further down the branch or not, and has no effect on a local leaf. The call with a NULL point is intended to prepare quadrant-related search meta data that is common to all points, and/or to efficiently terminate the recursion for all points in the branch in one call. + + - `p4est`:\\[in\\] The forest to search. We recurse through the trees one after another. + - `which_tree`:\\[in\\] The current tree number. + - `quadrant`:\\[in\\] The current quadrant in the recursion. This quadrant is either a non-leaf tree branch or a leaf. If the quadrant is contained in the local partition, we know which, otherwise we don't. Let us first consider the situation when **quadrant** is local, which is indicated by both **pfirst** and **plast** being equal to `p4est`->mpirank. Then the parameter **local_num** is negative for non-leaves and the number of the quadrant as a leaf in local storage otherwise. Only if the quadrant is a local leaf, it points to the actual local storage and can be used to access user data etc., and the recursion terminates. The other possibility is that **pfirst** < **plast**, in which case we proceed with the recursion, or both are equal to the same remote rank, in which case the recursion terminates. Either way, the quadrant is not from local forest storage. + - `pfirst`:\\[in\\] The lowest processor that owns part of **quadrant**. Guaranteed to be non-empty. + - `plast`:\\[in\\] The highest processor that owns part of **quadrant**. Guaranteed to be non-empty. + - `local_num`:\\[in\\] If **quadrant** is a local leaf, this number is the index of the leaf in local quadrant storage. Else, this is a negative value. + - `point`:\\[in,out\\] User-defined representation of a point. This parameter distinguishes two uses of the callback. For each quadrant, the callback is first called with a NULL point, and if this callback returns true, once for each point tracked in this branch. The return value for a point determines whether it shall be tracked further down the branch or not, and has no effect on a local leaf. The call with a NULL point is intended to prepare quadrant-related search meta data that is common to all points, and/or to efficiently terminate the recursion for all points in the branch in one call. + ### Returns + If false, the recursion at **quadrant** terminates. If true, it continues if **pfirst** < **plast** or if they are both equal to `p4est`->mpirank and the recursion has not reached a leaf yet. """ const p8est_search_all_t = Ptr{Cvoid} @@ -11979,26 +15682,39 @@ Note that in the remote case (a), we may terminate the recursion even if the qua This function works fine when used for the special cases that either the partition or the local quadrants are not of interest. However, in the case of querying only local information we expect that p4est_search_local will be faster since it employs specific local optimizations. ### Parameters -* `p4est`:\\[in\\] The forest to be searched. -* `call_post`:\\[in\\] If true, call quadrant callback both pre and post. -* `quadrant_fn`:\\[in\\] Executed once for each quadrant that is entered. If the callback returns false, this quadrant and its descendants are excluded from the search, and the points in this branch are not queried further. Its **point** argument is always NULL. Callback may be NULL in which case it is ignored. -* `point_fn`:\\[in\\] Executed once for each point that is relevant for a quadrant of the search. If it returns true, the point is tracked further down that branch, else it is discarded from the queries for the children. If **points** is not NULL, this callback must be not NULL. If **points** is NULL, it is not called. -* `points`:\\[in\\] User-defined array of points. We do not interpret a point, just pass it into the callbacks. If NULL, only the **quadrant_fn** callback is executed. If that is NULL, the whole function noops. If not NULL, the **point_fn** is called on its members during the search. + + - `p4est`:\\[in\\] The forest to be searched. + - `call_post`:\\[in\\] If true, call quadrant callback both pre and post. + - `quadrant_fn`:\\[in\\] Executed once for each quadrant that is entered. If the callback returns false, this quadrant and its descendants are excluded from the search, and the points in this branch are not queried further. Its **point** argument is always NULL. Callback may be NULL in which case it is ignored. + - `point_fn`:\\[in\\] Executed once for each point that is relevant for a quadrant of the search. If it returns true, the point is tracked further down that branch, else it is discarded from the queries for the children. If **points** is not NULL, this callback must be not NULL. If **points** is NULL, it is not called. + - `points`:\\[in\\] User-defined array of points. We do not interpret a point, just pass it into the callbacks. If NULL, only the **quadrant_fn** callback is executed. If that is NULL, the whole function noops. If not NULL, the **point_fn** is called on its members during the search. + ### Prototype + ```c void p8est_search_all (p8est_t * p4est, int call_post, p8est_search_all_t quadrant_fn, p8est_search_all_t point_fn, sc_array_t * points); ``` """ function p8est_search_all(p4est_, call_post, quadrant_fn, point_fn, points) - @ccall libp4est.p8est_search_all(p4est_::Ptr{p8est_t}, call_post::Cint, quadrant_fn::p8est_search_all_t, point_fn::p8est_search_all_t, points::Ptr{sc_array_t})::Cvoid + @ccall libp4est.p8est_search_all( + p4est_::Ptr{p8est_t}, + call_post::Cint, + quadrant_fn::p8est_search_all_t, + point_fn::p8est_search_all_t, + points::Ptr{sc_array_t}, + )::Cvoid end # typedef void ( * p8est_geometry_X_t ) ( p8est_geometry_t * geom , p4est_topidx_t which_tree , const double abc [ 3 ] , double xyz [ 3 ] ) -"""Forward transformation from the reference unit square to physical space. The physical space "xyz" is user-defined, currently used for VTK output.""" +""" +Forward transformation from the reference unit square to physical space. The physical space "xyz" is user-defined, currently used for VTK output. +""" const p8est_geometry_X_t = Ptr{Cvoid} # typedef void ( * p8est_geometry_destroy_t ) ( p8est_geometry_t * geom ) -"""Destructor prototype for a user-allocated [`p8est_geometry_t`](@ref). It is invoked by [`p8est_geometry_destroy`](@ref). If the user chooses to reserve the structure statically, simply don't call [`p4est_geometry_destroy`](@ref).""" +""" +Destructor prototype for a user-allocated [`p8est_geometry_t`](@ref). It is invoked by [`p8est_geometry_destroy`](@ref). If the user chooses to reserve the structure statically, simply don't call [`p4est_geometry_destroy`](@ref). +""" const p8est_geometry_destroy_t = Ptr{Cvoid} """ @@ -12006,12 +15722,12 @@ const p8est_geometry_destroy_t = Ptr{Cvoid} This structure can be created by the user, `p4est` will never change its contents. -| Field | Note | -| :------ | :----------------------------------------------------------------------------------------------- | -| name | User's choice is arbitrary. | -| user | | -| X | Coordinate transformation. | -| destroy | Destructor called by [`p8est_geometry_destroy`](@ref). If NULL, [`P4EST_FREE`](@ref) is called. | +| Field | Note | +|:------- |:----------------------------------------------------------------------------------------------- | +| name | User's choice is arbitrary. | +| user | | +| X | Coordinate transformation. | +| destroy | Destructor called by [`p8est_geometry_destroy`](@ref). If NULL, [`P4EST_FREE`](@ref) is called. | """ struct p8est_geometry name::Cstring @@ -12020,7 +15736,9 @@ struct p8est_geometry destroy::p8est_geometry_destroy_t end -"""This object encapsulates a custom geometry transformation.""" +""" +This object encapsulates a custom geometry transformation. +""" const p8est_geometry_t = p8est_geometry """ @@ -12029,6 +15747,7 @@ const p8est_geometry_t = p8est_geometry Can be used to conveniently destroy a geometry structure. The user is free not to call this function at all if they handle the memory of the [`p8est_geometry_t`](@ref) in their own way. ### Prototype + ```c void p8est_geometry_destroy (p8est_geometry_t * geom); ``` @@ -12043,16 +15762,23 @@ end Create a geometry structure based on the vertices in a connectivity. The transformation is constructed using trilinear interpolation. ### Parameters -* `conn`:\\[in\\] A [`p8est_connectivity_t`](@ref) with valid vertices. We do NOT take ownership and expect this structure to stay alive. + + - `conn`:\\[in\\] A [`p8est_connectivity_t`](@ref) with valid vertices. We do NOT take ownership and expect this structure to stay alive. + ### Returns + Geometry structure; use with [`p4est_geometry_destroy`](@ref). + ### Prototype + ```c p8est_geometry_t *p8est_geometry_new_connectivity (p8est_connectivity_t * conn); ``` """ function p8est_geometry_new_connectivity(conn) - @ccall libp4est.p8est_geometry_new_connectivity(conn::Ptr{p8est_connectivity_t})::Ptr{p8est_geometry_t} + @ccall libp4est.p8est_geometry_new_connectivity( + conn::Ptr{p8est_connectivity_t}, + )::Ptr{p8est_geometry_t} end """ @@ -12061,18 +15787,27 @@ end Create a geometry structure for the spherical shell of 24 trees. ### Parameters -* `conn`:\\[in\\] Result of [`p8est_connectivity_new_shell`](@ref) or equivalent. We do NOT take ownership and expect it to stay alive. -* `R2`:\\[in\\] The outer radius of the shell. -* `R1`:\\[in\\] The inner radius of the shell. + + - `conn`:\\[in\\] Result of [`p8est_connectivity_new_shell`](@ref) or equivalent. We do NOT take ownership and expect it to stay alive. + - `R2`:\\[in\\] The outer radius of the shell. + - `R1`:\\[in\\] The inner radius of the shell. + ### Returns + Geometry structure; use with [`p4est_geometry_destroy`](@ref). + ### Prototype + ```c p8est_geometry_t *p8est_geometry_new_shell (p8est_connectivity_t * conn, double R2, double R1); ``` """ function p8est_geometry_new_shell(conn, R2, R1) - @ccall libp4est.p8est_geometry_new_shell(conn::Ptr{p8est_connectivity_t}, R2::Cdouble, R1::Cdouble)::Ptr{p8est_geometry_t} + @ccall libp4est.p8est_geometry_new_shell( + conn::Ptr{p8est_connectivity_t}, + R2::Cdouble, + R1::Cdouble, + )::Ptr{p8est_geometry_t} end """ @@ -12081,19 +15816,29 @@ end Create a geometry structure for the solid sphere of 13 trees. ### Parameters -* `conn`:\\[in\\] Result of [`p8est_connectivity_new_sphere`](@ref) or equivalent. We do NOT take ownership and expect it to stay alive. -* `R2`:\\[in\\] The outer radius of the sphere. -* `R1`:\\[in\\] The outer radius of the inner shell. -* `R0`:\\[in\\] The inner radius of the inner shell. + + - `conn`:\\[in\\] Result of [`p8est_connectivity_new_sphere`](@ref) or equivalent. We do NOT take ownership and expect it to stay alive. + - `R2`:\\[in\\] The outer radius of the sphere. + - `R1`:\\[in\\] The outer radius of the inner shell. + - `R0`:\\[in\\] The inner radius of the inner shell. + ### Returns + Geometry structure; use with [`p4est_geometry_destroy`](@ref). + ### Prototype + ```c p8est_geometry_t *p8est_geometry_new_sphere (p8est_connectivity_t * conn, double R2, double R1, double R0); ``` """ function p8est_geometry_new_sphere(conn, R2, R1, R0) - @ccall libp4est.p8est_geometry_new_sphere(conn::Ptr{p8est_connectivity_t}, R2::Cdouble, R1::Cdouble, R0::Cdouble)::Ptr{p8est_geometry_t} + @ccall libp4est.p8est_geometry_new_sphere( + conn::Ptr{p8est_connectivity_t}, + R2::Cdouble, + R1::Cdouble, + R0::Cdouble, + )::Ptr{p8est_geometry_t} end """ @@ -12106,24 +15851,36 @@ This geometry maps a revolution torus, obtained using p8est_connectivity_new_tor The torus is divided into into segments arround the revolution axis, each segments is made of 5 trees; so here we provided the geometric transformation in a piecewise manner for each tree of the connectivity. ### Parameters -* `conn`:\\[in\\] Result of [`p8est_connectivity_new_torus`](@ref) or equivalent. We do NOT take ownership and expect it to stay alive. -* `R0`:\\[in\\] The inner radius of the 2d disk slice. -* `R1`:\\[in\\] The outer radius of the 2d disk slice. -* `R2`:\\[in\\] The outer radius of the torus. + + - `conn`:\\[in\\] Result of [`p8est_connectivity_new_torus`](@ref) or equivalent. We do NOT take ownership and expect it to stay alive. + - `R0`:\\[in\\] The inner radius of the 2d disk slice. + - `R1`:\\[in\\] The outer radius of the 2d disk slice. + - `R2`:\\[in\\] The outer radius of the torus. + ### Returns + Geometry structure; use with [`p4est_geometry_destroy`](@ref). + ### Prototype + ```c p8est_geometry_t *p8est_geometry_new_torus (p8est_connectivity_t * conn, double R0, double R1, double R2); ``` """ function p8est_geometry_new_torus(conn, R0, R1, R2) - @ccall libp4est.p8est_geometry_new_torus(conn::Ptr{p8est_connectivity_t}, R0::Cdouble, R1::Cdouble, R2::Cdouble)::Ptr{p8est_geometry_t} + @ccall libp4est.p8est_geometry_new_torus( + conn::Ptr{p8est_connectivity_t}, + R0::Cdouble, + R1::Cdouble, + R2::Cdouble, + )::Ptr{p8est_geometry_t} end mutable struct p8est_vtk_context end -"""Opaque context type for writing VTK output with multiple function calls.""" +""" +Opaque context type for writing VTK output with multiple function calls. +""" const p8est_vtk_context_t = p8est_vtk_context """ @@ -12134,16 +15891,23 @@ Write the `p8est` in VTK format. This is a convenience function for the special case of writing out the tree id, quadrant level, and MPI rank of each quadrant as cell data. One file is written per MPI rank, and one meta file on rank 0. The quadrants are scaled to length .95; see p8est_vtk_write_header. This function will abort if there is a file error. ### Parameters -* `p8est`:\\[in\\] The `p8est` to be written. -* `geom`:\\[in\\] A [`p8est_geometry_t`](@ref) structure or NULL for vertex space as defined by `p8est`->connectivity. -* `filename`:\\[in\\] The first part of the file name which will have the MPI rank appended to it: The output file will be filename\\_rank.vtu, and the meta file filename.pvtu. + + - `p8est`:\\[in\\] The `p8est` to be written. + - `geom`:\\[in\\] A [`p8est_geometry_t`](@ref) structure or NULL for vertex space as defined by `p8est`->connectivity. + - `filename`:\\[in\\] The first part of the file name which will have the MPI rank appended to it: The output file will be filename\\_rank.vtu, and the meta file filename.pvtu. + ### Prototype + ```c void p8est_vtk_write_file (p8est_t * p8est, p8est_geometry_t * geom, const char *filename); ``` """ function p8est_vtk_write_file(p8est_, geom, filename) - @ccall libp4est.p8est_vtk_write_file(p8est_::Ptr{p8est_t}, geom::Ptr{p8est_geometry_t}, filename::Cstring)::Cvoid + @ccall libp4est.p8est_vtk_write_file( + p8est_::Ptr{p8est_t}, + geom::Ptr{p8est_geometry_t}, + filename::Cstring, + )::Cvoid end """ @@ -12154,17 +15918,25 @@ The first call to write a VTK file using individual functions. Writing a VTK file is split into multiple functions that keep a context. This is the first function that allocates the opaque context structure. After allocation, further parameters can be set for the context. Then, the header, possible data fields, and the footer must be written. The process can be aborted any time by destroying the context. In this case, open files are closed cleanly with only partially written content. ### Parameters -* `p4est`: The `p8est` to be written. If no geometry is specified in p8est_vtk_context_set_geom, we require `p8est`->connectivity to have valid vertex arrays. -* `filename`: The first part of the name which will have the processor number appended to it (i.e., the output file will be filename\\_rank.vtu). The parallel meta-files for Paraview and Visit use this basename too. We copy this filename to internal storage, so it is not needed to remain alive after calling this function. + + - `p4est`: The `p8est` to be written. If no geometry is specified in p8est_vtk_context_set_geom, we require `p8est`->connectivity to have valid vertex arrays. + - `filename`: The first part of the name which will have the processor number appended to it (i.e., the output file will be filename\\_rank.vtu). The parallel meta-files for Paraview and Visit use this basename too. We copy this filename to internal storage, so it is not needed to remain alive after calling this function. + ### Returns + A VTK context fur further use. + ### Prototype + ```c p8est_vtk_context_t *p8est_vtk_context_new (p8est_t * p4est, const char *filename); ``` """ function p8est_vtk_context_new(p4est_, filename) - @ccall libp4est.p8est_vtk_context_new(p4est_::Ptr{p8est_t}, filename::Cstring)::Ptr{p8est_vtk_context_t} + @ccall libp4est.p8est_vtk_context_new( + p4est_::Ptr{p8est_t}, + filename::Cstring, + )::Ptr{p8est_vtk_context_t} end """ @@ -12173,15 +15945,21 @@ end Modify the geometry transformation registered in the context. After p8est_vtk_context_new, it is at the default NULL. ### Parameters -* `cont`:\\[in,out\\] The context is modified. It must not yet have been used to start writing in p8est_vtk_write_header. -* `geom`: A p8est_geometry_t structure, or NULL for vertex space. If NULL, `p8est`->connectivity->vertices and **tree_to_vertex** must be non-NULL. + + - `cont`:\\[in,out\\] The context is modified. It must not yet have been used to start writing in p8est_vtk_write_header. + - `geom`: A p8est_geometry_t structure, or NULL for vertex space. If NULL, `p8est`->connectivity->vertices and **tree_to_vertex** must be non-NULL. + ### Prototype + ```c void p8est_vtk_context_set_geom (p8est_vtk_context_t * cont, p8est_geometry_t * geom); ``` """ function p8est_vtk_context_set_geom(cont, geom) - @ccall libp4est.p8est_vtk_context_set_geom(cont::Ptr{p8est_vtk_context_t}, geom::Ptr{p8est_geometry_t})::Cvoid + @ccall libp4est.p8est_vtk_context_set_geom( + cont::Ptr{p8est_vtk_context_t}, + geom::Ptr{p8est_geometry_t}, + )::Cvoid end """ @@ -12190,15 +15968,21 @@ end Modify the context parameter for scaling the quadrants. A scale < 1 places a visual gap between adjacent quadrants. After p8est_vtk_context_new, it is at the default 0.95. ### Parameters -* `cont`:\\[in,out\\] The context is modified. It must not yet have been used to start writing in p8est_vtk_write_header. -* `scale`:\\[in\\] Scale parameter must be in (0, 1]. + + - `cont`:\\[in,out\\] The context is modified. It must not yet have been used to start writing in p8est_vtk_write_header. + - `scale`:\\[in\\] Scale parameter must be in (0, 1]. + ### Prototype + ```c void p8est_vtk_context_set_scale (p8est_vtk_context_t * cont, double scale); ``` """ function p8est_vtk_context_set_scale(cont, scale) - @ccall libp4est.p8est_vtk_context_set_scale(cont::Ptr{p8est_vtk_context_t}, scale::Cdouble)::Cvoid + @ccall libp4est.p8est_vtk_context_set_scale( + cont::Ptr{p8est_vtk_context_t}, + scale::Cdouble, + )::Cvoid end """ @@ -12207,15 +15991,21 @@ end Modify the context parameter for expecting continuous point data. If set to true, the point data is understood as a continuous field. In this case, we can significantly reduce the file size when scale == 1. For discontinuous point data, it should be set to false. After p8est_vtk_context_new, it is at the default false. ### Parameters -* `cont`:\\[in,out\\] The context is modified. It must not yet have been used to start writing in p8est_vtk_write_header. -* `continuous`:\\[in\\] Boolean parameter. + + - `cont`:\\[in,out\\] The context is modified. It must not yet have been used to start writing in p8est_vtk_write_header. + - `continuous`:\\[in\\] Boolean parameter. + ### Prototype + ```c void p8est_vtk_context_set_continuous (p8est_vtk_context_t * cont, int continuous); ``` """ function p8est_vtk_context_set_continuous(cont, continuous) - @ccall libp4est.p8est_vtk_context_set_continuous(cont::Ptr{p8est_vtk_context_t}, continuous::Cint)::Cvoid + @ccall libp4est.p8est_vtk_context_set_continuous( + cont::Ptr{p8est_vtk_context_t}, + continuous::Cint, + )::Cvoid end """ @@ -12226,8 +16016,11 @@ Cleanly destroy a p8est_vtk_context_t structure. This function closes all the file pointers and frees the context. Tt can be called even if the VTK output has only been partially written, the files' content will be incomplete. ### Parameters -* `context`:\\[in\\] The VTK file context to be destroyed. + + - `context`:\\[in\\] The VTK file context to be destroyed. + ### Prototype + ```c void p8est_vtk_context_destroy (p8est_vtk_context_t * context); ``` @@ -12250,16 +16043,23 @@ Each of these functions opens and closes files as necessary. Generally, each out This function writes point positions for the quadrants' vertices and the maps of elements to types and vertices as required by VTK. ### Parameters -* `cont`:\\[in,out\\] A VTK context created by p8est_vtk_context_new. None of the vtk\\_write functions must have been called. This context is the return value if no error occurs. + + - `cont`:\\[in,out\\] A VTK context created by p8est_vtk_context_new. None of the vtk\\_write functions must have been called. This context is the return value if no error occurs. + ### Returns + On success, an opaque context ([`p8est_vtk_context_t`](@ref)) pointer that must be passed to subsequent p8est\\_vtk calls. It is required to call p8est_vtk_write_footer eventually with this value. Returns NULL on error. + ### Prototype + ```c p8est_vtk_context_t *p8est_vtk_write_header (p8est_vtk_context_t * cont); ``` """ function p8est_vtk_write_header(cont) - @ccall libp4est.p8est_vtk_write_header(cont::Ptr{p8est_vtk_context_t})::Ptr{p8est_vtk_context_t} + @ccall libp4est.p8est_vtk_write_header( + cont::Ptr{p8est_vtk_context_t}, + )::Ptr{p8est_vtk_context_t} end """ @@ -12274,35 +16074,92 @@ Writing a VTK file is split into a few routines. This allows there to be an arbi The number of doubles in each [`sc_array`](@ref) must be exactly `p8est`->local_num_quadrants for scalar data and *3**p8est->local_num_quadrants for vector data. The cell scalar data come first, followed by the cell vector data. ### Parameters -* `cont`:\\[in,out\\] A VTK context created by p8est_vtk_context_new. -* `write_tree`:\\[in\\] Boolean to determine if the tree id should be output. -* `write_level`:\\[in\\] Boolean to determine if the tree levels should be output. -* `write_rank`:\\[in\\] Boolean to determine if the MPI rank should be output. -* `wrap_rank`:\\[in\\] Number to wrap around the rank with a modulo operation. Can be 0 for no wrapping. -* `num_cell_scalars`:\\[in\\] Number of cell scalar datasets to output. -* `num_cell_vectors`:\\[in\\] Number of cell vector datasets to output. -* `fieldnames`:\\[in\\] Array of char strings containing the name of each data field. -* `values`:\\[in\\] Array of pointers to [`sc_array_t`](@ref) holding variables of type double, one value (scalar data) or three values (vector data) for each local quadrant. + + - `cont`:\\[in,out\\] A VTK context created by p8est_vtk_context_new. + - `write_tree`:\\[in\\] Boolean to determine if the tree id should be output. + - `write_level`:\\[in\\] Boolean to determine if the tree levels should be output. + - `write_rank`:\\[in\\] Boolean to determine if the MPI rank should be output. + - `wrap_rank`:\\[in\\] Number to wrap around the rank with a modulo operation. Can be 0 for no wrapping. + - `num_cell_scalars`:\\[in\\] Number of cell scalar datasets to output. + - `num_cell_vectors`:\\[in\\] Number of cell vector datasets to output. + - `fieldnames`:\\[in\\] Array of char strings containing the name of each data field. + - `values`:\\[in\\] Array of pointers to [`sc_array_t`](@ref) holding variables of type double, one value (scalar data) or three values (vector data) for each local quadrant. + ### Returns + On success, the context that has been passed in. On failure, returns NULL and deallocates the context. + ### Prototype + ```c p8est_vtk_context_t *p8est_vtk_write_cell_data (p8est_vtk_context_t * cont, int write_tree, int write_level, int write_rank, int wrap_rank, int num_cell_scalars, int num_cell_vectors, const char *fieldnames[], sc_array_t * values[]); ``` """ -function p8est_vtk_write_cell_data(cont, write_tree, write_level, write_rank, wrap_rank, num_cell_scalars, num_cell_vectors, fieldnames, values) - @ccall libp4est.p8est_vtk_write_cell_data(cont::Ptr{p8est_vtk_context_t}, write_tree::Cint, write_level::Cint, write_rank::Cint, wrap_rank::Cint, num_cell_scalars::Cint, num_cell_vectors::Cint, fieldnames::Ptr{Cstring}, values::Ptr{Ptr{sc_array_t}})::Ptr{p8est_vtk_context_t} +function p8est_vtk_write_cell_data( + cont, + write_tree, + write_level, + write_rank, + wrap_rank, + num_cell_scalars, + num_cell_vectors, + fieldnames, + values, +) + @ccall libp4est.p8est_vtk_write_cell_data( + cont::Ptr{p8est_vtk_context_t}, + write_tree::Cint, + write_level::Cint, + write_rank::Cint, + wrap_rank::Cint, + num_cell_scalars::Cint, + num_cell_vectors::Cint, + fieldnames::Ptr{Cstring}, + values::Ptr{Ptr{sc_array_t}}, + )::Ptr{p8est_vtk_context_t} end # automatic type deduction for variadic arguments may not be what you want, please use with caution -@generated function p8est_vtk_write_cell_dataf(cont, write_tree, write_level, write_rank, wrap_rank, num_cell_scalars, num_cell_vectors, va_list...) - :(@ccall(libp4est.p8est_vtk_write_cell_dataf(cont::Ptr{p8est_vtk_context_t}, write_tree::Cint, write_level::Cint, write_rank::Cint, wrap_rank::Cint, num_cell_scalars::Cint, num_cell_vectors::Cint; $(to_c_type_pairs(va_list)...))::Ptr{p8est_vtk_context_t})) - end +@generated function p8est_vtk_write_cell_dataf( + cont, + write_tree, + write_level, + write_rank, + wrap_rank, + num_cell_scalars, + num_cell_vectors, + va_list..., +) + :(@ccall( + libp4est.p8est_vtk_write_cell_dataf( + cont::Ptr{p8est_vtk_context_t}, + write_tree::Cint, + write_level::Cint, + write_rank::Cint, + wrap_rank::Cint, + num_cell_scalars::Cint, + num_cell_vectors::Cint; + $(to_c_type_pairs(va_list)...), + )::Ptr{p8est_vtk_context_t} + )) +end # automatic type deduction for variadic arguments may not be what you want, please use with caution -@generated function p8est_vtk_write_point_dataf(cont, num_point_scalars, num_point_vectors, va_list...) - :(@ccall(libp4est.p8est_vtk_write_point_dataf(cont::Ptr{p8est_vtk_context_t}, num_point_scalars::Cint, num_point_vectors::Cint; $(to_c_type_pairs(va_list)...))::Ptr{p8est_vtk_context_t})) - end +@generated function p8est_vtk_write_point_dataf( + cont, + num_point_scalars, + num_point_vectors, + va_list..., +) + :(@ccall( + libp4est.p8est_vtk_write_point_dataf( + cont::Ptr{p8est_vtk_context_t}, + num_point_scalars::Cint, + num_point_vectors::Cint; + $(to_c_type_pairs(va_list)...), + )::Ptr{p8est_vtk_context_t} + )) +end """ p8est_vtk_write_footer(cont) @@ -12312,10 +16169,15 @@ Write the VTU footer and clean up. Writing a VTK file is split into a few routines. This function writes the footer information to the VTK file and cleanly destroys the VTK context. ### Parameters -* `cont`:\\[in\\] Context is deallocated before the function returns. + + - `cont`:\\[in\\] Context is deallocated before the function returns. + ### Returns + This returns 0 if no error and -1 if there is an error. + ### Prototype + ```c int p8est_vtk_write_footer (p8est_vtk_context_t * cont); ``` @@ -12393,11 +16255,11 @@ end """ __JL_Ctag_225 -| Field | Note | -| :--------- | :------------------------------- | -| is\\_ghost | boolean: local (0) or ghost (1) | -| quad | the actual quadrant | -| quadid | index in tree or ghost array | +| Field | Note | +|:---------- |:------------------------------- | +| is\\_ghost | boolean: local (0) or ghost (1) | +| quad | the actual quadrant | +| quadid | index in tree or ghost array | """ struct __JL_Ctag_225 is_ghost::Int8 @@ -12426,21 +16288,21 @@ end """ __JL_Ctag_226 -| Field | Note | -| :--------- | :------------------------------- | -| is\\_ghost | boolean: local (0) or ghost (1) | -| quad | the actual quadrant | -| quadid | index in tree or ghost array | +| Field | Note | +|:---------- |:------------------------------- | +| is\\_ghost | boolean: local (0) or ghost (1) | +| quad | the actual quadrant | +| quadid | index in tree or ghost array | """ struct __JL_Ctag_226 - is_ghost::NTuple{2, Int8} - quad::NTuple{2, Ptr{p4est_quadrant_t}} - quadid::NTuple{2, p4est_locidx_t} + is_ghost::NTuple{2,Int8} + quad::NTuple{2,Ptr{p4est_quadrant_t}} + quadid::NTuple{2,p4est_locidx_t} end function Base.getproperty(x::Ptr{__JL_Ctag_226}, f::Symbol) - f === :is_ghost && return Ptr{NTuple{2, Int8}}(x + 0) - f === :quad && return Ptr{NTuple{2, Ptr{p4est_quadrant_t}}}(x + 8) - f === :quadid && return Ptr{NTuple{2, p4est_locidx_t}}(x + 24) + f === :is_ghost && return Ptr{NTuple{2,Int8}}(x + 0) + f === :quad && return Ptr{NTuple{2,Ptr{p4est_quadrant_t}}}(x + 8) + f === :quadid && return Ptr{NTuple{2,p4est_locidx_t}}(x + 24) return getfield(x, f) end @@ -12591,11 +16453,11 @@ end """ __JL_Ctag_233 -| Field | Note | -| :--------- | :------------------------------- | -| is\\_ghost | boolean: local (0) or ghost (1) | -| quad | the actual quadrant | -| quadid | index in tree or ghost array | +| Field | Note | +|:---------- |:------------------------------- | +| is\\_ghost | boolean: local (0) or ghost (1) | +| quad | the actual quadrant | +| quadid | index in tree or ghost array | """ struct __JL_Ctag_233 is_ghost::Int8 @@ -12624,21 +16486,21 @@ end """ __JL_Ctag_234 -| Field | Note | -| :--------- | :------------------------------- | -| is\\_ghost | boolean: local (0) or ghost (1) | -| quad | the actual quadrant | -| quadid | index in tree or ghost array | +| Field | Note | +|:---------- |:------------------------------- | +| is\\_ghost | boolean: local (0) or ghost (1) | +| quad | the actual quadrant | +| quadid | index in tree or ghost array | """ struct __JL_Ctag_234 - is_ghost::NTuple{4, Int8} - quad::NTuple{4, Ptr{p8est_quadrant_t}} - quadid::NTuple{4, p4est_locidx_t} + is_ghost::NTuple{4,Int8} + quad::NTuple{4,Ptr{p8est_quadrant_t}} + quadid::NTuple{4,p4est_locidx_t} end function Base.getproperty(x::Ptr{__JL_Ctag_234}, f::Symbol) - f === :is_ghost && return Ptr{NTuple{4, Int8}}(x + 0) - f === :quad && return Ptr{NTuple{4, Ptr{p8est_quadrant_t}}}(x + 8) - f === :quadid && return Ptr{NTuple{4, p4est_locidx_t}}(x + 40) + f === :is_ghost && return Ptr{NTuple{4,Int8}}(x + 0) + f === :quad && return Ptr{NTuple{4,Ptr{p8est_quadrant_t}}}(x + 8) + f === :quadid && return Ptr{NTuple{4,p4est_locidx_t}}(x + 40) return getfield(x, f) end @@ -12657,11 +16519,11 @@ end """ __JL_Ctag_235 -| Field | Note | -| :--------- | :------------------------------- | -| is\\_ghost | boolean: local (0) or ghost (1) | -| quad | the actual quadrant | -| quadid | index in tree or ghost array | +| Field | Note | +|:---------- |:------------------------------- | +| is\\_ghost | boolean: local (0) or ghost (1) | +| quad | the actual quadrant | +| quadid | index in tree or ghost array | """ struct __JL_Ctag_235 is_ghost::Int8 @@ -12690,21 +16552,21 @@ end """ __JL_Ctag_236 -| Field | Note | -| :--------- | :------------------------------- | -| is\\_ghost | boolean: local (0) or ghost (1) | -| quad | the actual quadrant | -| quadid | index in tree or ghost array | +| Field | Note | +|:---------- |:------------------------------- | +| is\\_ghost | boolean: local (0) or ghost (1) | +| quad | the actual quadrant | +| quadid | index in tree or ghost array | """ struct __JL_Ctag_236 - is_ghost::NTuple{2, Int8} - quad::NTuple{2, Ptr{p8est_quadrant_t}} - quadid::NTuple{2, p4est_locidx_t} + is_ghost::NTuple{2,Int8} + quad::NTuple{2,Ptr{p8est_quadrant_t}} + quadid::NTuple{2,p4est_locidx_t} end function Base.getproperty(x::Ptr{__JL_Ctag_236}, f::Symbol) - f === :is_ghost && return Ptr{NTuple{2, Int8}}(x + 0) - f === :quad && return Ptr{NTuple{2, Ptr{p8est_quadrant_t}}}(x + 8) - f === :quadid && return Ptr{NTuple{2, p4est_locidx_t}}(x + 24) + f === :is_ghost && return Ptr{NTuple{2,Int8}}(x + 0) + f === :quad && return Ptr{NTuple{2,Ptr{p8est_quadrant_t}}}(x + 8) + f === :quadid && return Ptr{NTuple{2,p4est_locidx_t}}(x + 24) return getfield(x, f) end @@ -13090,7 +16952,7 @@ P8EST_LAST_OFFSET(l) = P8EST_ROOT_LEN - P8EST_QUADRANT_LEN(l) # exports const PREFIXES = ["p4est_", "p6est_", "p8est_", "sc_", "P4EST_", "P6EST_", "P8EST_", "SC_"] -for name in names(@__MODULE__; all=true), prefix in PREFIXES +for name in names(@__MODULE__; all = true), prefix in PREFIXES if startswith(string(name), prefix) @eval export $name end diff --git a/lib/P4est/src/P4est.jl b/lib/P4est/src/P4est.jl index 857d608..a7d980f 100644 --- a/lib/P4est/src/P4est.jl +++ b/lib/P4est/src/P4est.jl @@ -24,9 +24,7 @@ include("pointerwrappers.jl") """ P4est.uses_mpi() -Is intended to return `true`` if the `p4est` library was compiled with MPI -enabled. Since P4est.jl currently only supports `p4est` with MPI enabled, -this may always return `true`. +Is intended to return ```true`` if the ```p4est`library was compiled with MPI enabled. Since P4est.jl currently only supports`p4est`with MPI enabled, this may always return`true`. """ uses_mpi() = isdefined(@__MODULE__, :P4EST_ENABLE_MPI) @@ -108,8 +106,8 @@ path_sc_library() = _PREFERENCE_LIBSC Returns `false` if a system-provided MPI installation is set via the MPIPreferences, but not a system-provided `p4est` installation. In this case, P4est.jl is not usable. """ -preferences_set_correctly() = !(_PREFERENCE_LIBP4EST == "P4est_jll" && - MPIPreferences.binary == "system") +preferences_set_correctly() = + !(_PREFERENCE_LIBP4EST == "P4est_jll" && MPIPreferences.binary == "system") """ P4est.init(log_handler, log_threshold) @@ -119,9 +117,11 @@ nothing. Thus, `P4est.init` can safely be called multiple times. To use the default log handler and suppress most output created by default by `p4est`, call this function as + ```julia P4est.init(C_NULL, SC_LP_ERROR) ``` + before calling other functions from `p4est`. """ function init(log_handler, log_threshold) diff --git a/lib/P4est/src/pointerwrappers.jl b/lib/P4est/src/pointerwrappers.jl index 4d24b25..e9b2bcf 100644 --- a/lib/P4est/src/pointerwrappers.jl +++ b/lib/P4est/src/pointerwrappers.jl @@ -13,6 +13,7 @@ to having to load/store the entire struct when accessing only a single field. Th be helpful especially when accessing data in nested structures. ### Example + ```repl julia> using P4est, MPI @@ -78,8 +79,10 @@ function Base.setproperty!(pw::PointerWrapper{T}, name::Symbol, v) where {T} # see https://github.com/trixi-framework/P4est.jl/issues/72 and https://github.com/trixi-framework/P4est.jl/issues/79 return Base.setproperty!(pointer(pw), name, v) end - return unsafe_store!(reinterpret(Ptr{fieldtype(T, i)}, pointer(pw) + fieldoffset(T, i)), - v) + return unsafe_store!( + reinterpret(Ptr{fieldtype(T, i)}, pointer(pw) + fieldoffset(T, i)), + v, + ) end # `[]` allows one to access the actual underlying data and @@ -91,10 +94,12 @@ Base.setindex!(pw::PointerWrapper, value, i::Integer = 1) = unsafe_store!(pw, va Base.unsafe_load(pw::PointerWrapper, i::Integer = 1) = unsafe_load(pointer(pw), i) # When `unsafe_wrap`ping a PointerWrapper object, we really want to wrap the underlying array -function Base.unsafe_wrap(AType::Union{Type{Array}, Type{Array{T}}, Type{Array{T, N}}}, - pw::PointerWrapper, - dims::Union{NTuple{N, Int}, Integer}; - own::Bool = false,) where {T, N} +function Base.unsafe_wrap( + AType::Union{Type{Array},Type{Array{T}},Type{Array{T,N}}}, + pw::PointerWrapper, + dims::Union{NTuple{N,Int},Integer}; + own::Bool = false, +) where {T,N} unsafe_wrap(AType, pointer(pw), dims; own) end diff --git a/lib/P4estTypes/src/connectivity.jl b/lib/P4estTypes/src/connectivity.jl index 4a2589d..24f13e6 100755 --- a/lib/P4estTypes/src/connectivity.jl +++ b/lib/P4estTypes/src/connectivity.jl @@ -6,6 +6,7 @@ the roots of `Pxest` quadtrees or octrees. The parameter `X` is 4 if the roots are quads (2D aka p4est) and 8 if they are hexes (3D aka p8est). # Fields + $(DocStringExtensions.FIELDS) # Usage @@ -15,23 +16,23 @@ $(DocStringExtensions.FIELDS) Construct a connectivity mesh for the roots of a forest-of-quadtrees using p4est's built-in mesh connectivities. Valid values for `name` are -- `:unitsquare`: the unit square. -- `:periodic`: all-periodic unit square. -- `:rotwrap`: periodic unit square (the left and right faces are identified, - and bottom and top opposite). -- `:corner`: three-tree mesh around a corner. -- `:pillow`: two trees on top of each other. -- `:moebius`: a five-tree moebius band. -- `:star`: six-tree star. -- `:cubed`: six sides of a unit cube. -- `:disk_nonperiodic`: five-tree flat spherical disk. -- `:icosahedron`: for mapping the sphere using an icosahedron (see - `@doc P4estTypes.P4est.p4est_connectivity_new_icosahedron` for more info). -- `:shell2d`: 2D spherical shell. -- `:disk2d`: maps a 2D disk. - - ---- + - `:unitsquare`: the unit square. + - `:periodic`: all-periodic unit square. + - `:rotwrap`: periodic unit square (the left and right faces are identified, + and bottom and top opposite). + - `:corner`: three-tree mesh around a corner. + - `:pillow`: two trees on top of each other. + - `:moebius`: a five-tree moebius band. + - `:star`: six-tree star. + - `:cubed`: six sides of a unit cube. + - `:disk_nonperiodic`: five-tree flat spherical disk. + - `:icosahedron`: for mapping the sphere using an icosahedron (see + `@doc P4estTypes.P4est.p4est_connectivity_new_icosahedron` for more info). + - `:shell2d`: 2D spherical shell. + - `:disk2d`: maps a 2D disk. + +* * * + Connectivity{4}(:disk, periodic_x::Bool, periodic_y::Bool) Create a connectivity structure for a five-tree flat spherical disk. The @@ -40,26 +41,28 @@ the x and y directions, respectively. See `@doc P4estTypes.P4est.p4est_connectivity_new_disk` for detailed information. ---- +* * * + Connectivity{8}(name::Symbol) Construct a connectivity mesh for the roots of a forest-of-octrees using p8est's built-in mesh connectivities. Valid values for `name` are -- `:unitcube`: the unit cube. -- `:periodic`: an all-periodic unit cube. -- `:rotcubes`: contains a few cubes (these are rotated against each other to - stress the topology routines). -- `:rotwrap`: a mostly periodic unit cube (see - `@doc P4estTypes.P4est.p8est_connectivity_new_rotwrap`). -- `:shell`: a spherical shell (see - `@doc P4estTypes.P4est.p8est_connectivity_new_shell`). -- `:sphere`: a solid sphere (see - `@doc P4estTypes.P4est.p8est_connectivity_new_sphere`). -- `:twocubes`: two cubes. -- `:twowrap`: two cubes where the two far ends are identified periodically. - ---- + - `:unitcube`: the unit cube. + - `:periodic`: an all-periodic unit cube. + - `:rotcubes`: contains a few cubes (these are rotated against each other to + stress the topology routines). + - `:rotwrap`: a mostly periodic unit cube (see + `@doc P4estTypes.P4est.p8est_connectivity_new_rotwrap`). + - `:shell`: a spherical shell (see + `@doc P4estTypes.P4est.p8est_connectivity_new_shell`). + - `:sphere`: a solid sphere (see + `@doc P4estTypes.P4est.p8est_connectivity_new_sphere`). + - `:twocubes`: two cubes. + - `:twowrap`: two cubes where the two far ends are identified periodically. + +* * * + Connectivity{8}(:torus, nsegments) Create a connectivity structure that builds a revolution torus. Here @@ -68,7 +71,8 @@ Create a connectivity structure that builds a revolution torus. Here See `@doc P4estTypes.P4est.p8est_connectivity_new_torus` for detailed information. ---- +* * * + Connectivity{8}(:torus, nsegments) Create a connectivity structure that builds a revolution torus. Here @@ -77,7 +81,8 @@ Create a connectivity structure that builds a revolution torus. Here See `@doc P4estTypes.P4est.p8est_connectivity_new_torus` for detailed information. ---- +* * * + Connectivity{X}(:twotrees, l_face, r_face, orientation) where {X} Create a connectivity structure (`X=4` for quadtrees and `X=8` for octrees) for @@ -86,20 +91,22 @@ two trees being rotated with respect to each other in a user-defined way. Here respectively. The argument `orientation` gives the orientation code of the trees with respect to each other. ---- +* * * + Connectivity{X}(vertices, elements) where {X} Creates a connectivity from the given list of vertices and element-to-vertex connectivity. The parameter set to `X=4` is for quads and `X=8` for hexes. -- `vertices`: should be a number-of-vertices by 3 matrix where the columns - correspond to x, y, and z coordinates (typically the `z` coordinate will be - zero for a 2D forest). -- `elements`: should be a number-of-vertices by 4 or 8 matrix where the columns - vertex indices used to define each element. Note that z-ordering should be - used, and it should use zero-indexing. + - `vertices`: should be a number-of-vertices by 3 matrix where the columns + correspond to x, y, and z coordinates (typically the `z` coordinate will be + zero for a 2D forest). + - `elements`: should be a number-of-vertices by 4 or 8 matrix where the columns + vertex indices used to define each element. Note that z-ordering should be + used, and it should use zero-indexing. + +* * * ---- Connectivity{X}(filename::String) where {X} Create a connectivity from an ABAQUS input at `filename`. The parameter set to @@ -110,9 +117,10 @@ See `@doc P4estTypes.P4est.p4est_connectivity_read_inp` and files. # See also -- [`brick`](@ref): a function to create a rectangular [`Connectivity`](@ref). -- [`connectivity`](@ref): a function to get the connectivity of a [`Pxest`](@ref). -- [`refine`](@ref): a function to create a refined [`Connectivity`](@ref). + + - [`brick`](@ref): a function to create a rectangular [`Connectivity`](@ref). + - [`connectivity`](@ref): a function to get the connectivity of a [`Pxest`](@ref). + - [`refine`](@ref): a function to create a refined [`Connectivity`](@ref). """ mutable struct Connectivity{X,P} """The pointer (of type `P`) can be a pointer to either a diff --git a/lib/P4estTypes/src/ghost.jl b/lib/P4estTypes/src/ghost.jl index a1f7a01..7602c99 100644 --- a/lib/P4estTypes/src/ghost.jl +++ b/lib/P4estTypes/src/ghost.jl @@ -6,10 +6,12 @@ for a `Pxest{X}`. Also stores the corresponding local domain quadrants, mirrors, that are in other rank's ghost layers. # Fields + $(DocStringExtensions.FIELDS) # See also -- [`ghostlayer`](@ref): a function used to construct a `GhostLayer` + + - [`ghostlayer`](@ref): a function used to construct a `GhostLayer` """ mutable struct GhostLayer{X,P} """The pointer (of type `P`) can be a pointer to either a diff --git a/lib/P4estTypes/src/lnodes.jl b/lib/P4estTypes/src/lnodes.jl index a2543a9..8e16e04 100644 --- a/lib/P4estTypes/src/lnodes.jl +++ b/lib/P4estTypes/src/lnodes.jl @@ -4,10 +4,12 @@ Stores a parallel numbering of Lobatto nodes for a `Pxest{X}`. # Fields + $(DocStringExtensions.FIELDS) # See also -- [`lnodes`](@ref): a function used to construct `LNodes` + + - [`lnodes`](@ref): a function used to construct `LNodes` """ mutable struct LNodes{X,P} """The pointer (of type `P`) can be a pointer to either a diff --git a/lib/P4estTypes/src/pxest.jl b/lib/P4estTypes/src/pxest.jl index a1fbcfe..7ed2858 100644 --- a/lib/P4estTypes/src/pxest.jl +++ b/lib/P4estTypes/src/pxest.jl @@ -213,6 +213,7 @@ and `X=8` indicates an octant; quadrant is used both as the general term and the term for the 2D object). # Fields + $(DocStringExtensions.FIELDS) """ struct QuadrantWrapper{X,P} @@ -308,6 +309,7 @@ end Stores the quadrants in a tree of a Pxest{X}. # Fields + $(DocStringExtensions.FIELDS) """ struct Tree{X,P,Q} <: AbstractArray{QuadrantWrapper,1} @@ -357,19 +359,21 @@ So, each rank will only have access to the quadrants it owns.) Second, using forest via callback functions. # Fields + $(DocStringExtensions.FIELDS) # See also -- [`pxest`](@ref): a function that constructs a `Pxest` from a [`Connectivity`](@ref). -- [`iterateforest`](@ref): a function to iterate over the volumes, faces, edges, and - corners of the forest. -- [`refine!`](@ref): refine the quadrants of the forest. -- [`coarsen!`](@ref): coarsen the quadrants of the forest. -- [`balance!`](@ref): two-to-one balance the quadrants of the forest. -- [`partition!`](@ref): partition the quadrants of the forest. -- [`ghostlayer`](@ref): get the ghost layer of quadrants for the forest. -- [`lnodes`](@ref): get a global node numbering. -- [`P4estTypes.savevtk`](@ref): save a VTK representation of the forest. + + - [`pxest`](@ref): a function that constructs a `Pxest` from a [`Connectivity`](@ref). + - [`iterateforest`](@ref): a function to iterate over the volumes, faces, edges, and + corners of the forest. + - [`refine!`](@ref): refine the quadrants of the forest. + - [`coarsen!`](@ref): coarsen the quadrants of the forest. + - [`balance!`](@ref): two-to-one balance the quadrants of the forest. + - [`partition!`](@ref): partition the quadrants of the forest. + - [`ghostlayer`](@ref): get the ghost layer of quadrants for the forest. + - [`lnodes`](@ref): get a global node numbering. + - [`P4estTypes.savevtk`](@ref): save a VTK representation of the forest. """ mutable struct Pxest{X,P,C} <: AbstractArray{Tree,1} """The pointer (of type `P`) can be a pointer to either a @@ -1051,9 +1055,11 @@ The keyword arguments (`kw...`) for the balancing are: + `P4estTypes.CONNECT_EDGE(Val(8))`: enforce across face and edge. + `P4estTypes.CONNECT_CORNER(Val(4))`: enforce across face and corner. + `P4estTypes.CONNECT_CORNER(Val(8))`: enforce across face, edge, and corner. + - `init = nothing`: callback function with prototype `init(forest, treeid, quadrant)` called for each quadrant created to initialized the user data. + - `replace = nothing`: callback function with prototype `replace(forest, treeid, outgoing, incoming)` called for each `outgoing` quadrant with their associated `incoming` quadrants. Note both diff --git a/src/Abstract/Types.jl b/src/Abstract/Types.jl index 12f4f62..7e7a010 100644 --- a/src/Abstract/Types.jl +++ b/src/Abstract/Types.jl @@ -11,40 +11,88 @@ const REDUNDANT_STEPS_NUM = 100 const TIME_STEP_CONTRACT_RATIO = 0.2 const face_num_2d = 4 const face_num_3d = 6 -const WLST = [6,10] -const RFT = [[],[[2, 4], [1, 4], [3, 2], [1, 3]],[[-1,-1,-1],[1,-1,-1],[-1,1,-1],[1,1,-1],[-1,-1,1],[1,-1,1],[-1,1,1],[1,1,1]]] # refine face table -const RMT = [[],[[-1, -1], [1, -1], [-1, 1], [1, 1]],[[-1,-1,-1],[1,-1,-1],[-1,1,-1],[1,1,-1],[-1,-1,1],[1,-1,1],[-1,1,1],[1,1,1]]] # refine midpoint table -const ANTIVT = [[],[[-1, -1], [1, -1], [1, 1], [-1, 1]],[[-1,-1,-1],[1,-1,-1],[-1,1,-1],[1,1,-1],[-1,-1,1],[1,-1,1],[-1,1,1],[1,1,1]]] # anticlock vertices table -const NMT = [[],[[-1,0],[1,0],[0,-1],[0,1]],[[-1,0,0],[1,0,0],[0,-1,0],[0,1,0],[0,0,-1],[0,0,1]]] # neighbor midpoint table -const FAT = [[2,1],[[2,3],[1,3],[1,2]]]# face area table -const CLP = [1,3,5,7] # Vertices' indices in cut_rect -const CTN = [[],[[1,3],[2,3],[1,4],[2,4]],[]] # Corner target neighbor DIM{Corner_id{possible faces}} -const pxest_ts = [p4est_t,p8est_t] -const pxest_quadrant_ts = [p4est_quadrant_t,p8est_quadrant_t] -const pxest_ghost_ts = [p4est_ghost_t,p8est_ghost_t] -const pxest_mesh_ts = [p4est_mesh_t,p8est_mesh_t] -const pxest_iter_volume_info_ts = [p4est_iter_volume_info_t,p8est_iter_volume_info_t] -const pxest_iter_face_info_ts = [p4est_iter_face_info_t,p8est_iter_face_info_t] -const pxest_iter_face_side_ts = [p4est_iter_face_side_t,p8est_iter_face_side_t] +const WLST = [6, 10] +const RFT = [ + [], + [[2, 4], [1, 4], [3, 2], [1, 3]], + [ + [-1, -1, -1], + [1, -1, -1], + [-1, 1, -1], + [1, 1, -1], + [-1, -1, 1], + [1, -1, 1], + [-1, 1, 1], + [1, 1, 1], + ], +] # refine face table +const RMT = [ + [], + [[-1, -1], [1, -1], [-1, 1], [1, 1]], + [ + [-1, -1, -1], + [1, -1, -1], + [-1, 1, -1], + [1, 1, -1], + [-1, -1, 1], + [1, -1, 1], + [-1, 1, 1], + [1, 1, 1], + ], +] # refine midpoint table +const ANTIVT = [ + [], + [[-1, -1], [1, -1], [1, 1], [-1, 1]], + [ + [-1, -1, -1], + [1, -1, -1], + [-1, 1, -1], + [1, 1, -1], + [-1, -1, 1], + [1, -1, 1], + [-1, 1, 1], + [1, 1, 1], + ], +] # anticlock vertices table +const NMT = [ + [], + [[-1, 0], [1, 0], [0, -1], [0, 1]], + [[-1, 0, 0], [1, 0, 0], [0, -1, 0], [0, 1, 0], [0, 0, -1], [0, 0, 1]], +] # neighbor midpoint table +const FAT = [[2, 1], [[2, 3], [1, 3], [1, 2]]]# face area table +const CLP = [1, 3, 5, 7] # Vertices' indices in cut_rect +const CTN = [[], [[1, 3], [2, 3], [1, 4], [2, 4]], []] # Corner target neighbor DIM{Corner_id{possible faces}} +const pxest_ts = [p4est_t, p8est_t] +const pxest_quadrant_ts = [p4est_quadrant_t, p8est_quadrant_t] +const pxest_ghost_ts = [p4est_ghost_t, p8est_ghost_t] +const pxest_mesh_ts = [p4est_mesh_t, p8est_mesh_t] +const pxest_iter_volume_info_ts = [p4est_iter_volume_info_t, p8est_iter_volume_info_t] +const pxest_iter_face_info_ts = [p4est_iter_face_info_t, p8est_iter_face_info_t] +const pxest_iter_face_side_ts = [p4est_iter_face_side_t, p8est_iter_face_side_t] pxest_t = Union{p4est_t,p8est_t} pxest_ghost_t = Union{p4est_ghost_t,p8est_ghost_t} pxest_mesh_t = Union{p4est_mesh_t,p8est_mesh_t} -P_pxest_t = Union{Ptr{p4est_t}, Ptr{p8est_t}} -P_pxest_ghost_t = Union{Ptr{p4est_ghost_t}, Ptr{p8est_ghost_t}} -P_pxest_mesh_t = Union{Ptr{p4est_mesh_t}, Ptr{p8est_mesh_t}} -P_pxest_quadrant_t = Union{Ptr{p4est_quadrant_t}, Ptr{p8est_quadrant_t}} -P_pxest_iter_volume_info_t = Union{Ptr{p4est_iter_volume_info_t}, Ptr{p8est_iter_volume_info_t}} -P_pxest_iter_face_info_t = Union{Ptr{p4est_iter_face_info_t}, Ptr{p8est_iter_face_info_t}} +P_pxest_t = Union{Ptr{p4est_t},Ptr{p8est_t}} +P_pxest_ghost_t = Union{Ptr{p4est_ghost_t},Ptr{p8est_ghost_t}} +P_pxest_mesh_t = Union{Ptr{p4est_mesh_t},Ptr{p8est_mesh_t}} +P_pxest_quadrant_t = Union{Ptr{p4est_quadrant_t},Ptr{p8est_quadrant_t}} +P_pxest_iter_volume_info_t = + Union{Ptr{p4est_iter_volume_info_t},Ptr{p8est_iter_volume_info_t}} +P_pxest_iter_face_info_t = Union{Ptr{p4est_iter_face_info_t},Ptr{p8est_iter_face_info_t}} -PW_pxest_t = Union{PointerWrapper{p4est_t}, PointerWrapper{p8est_t}} -PW_pxest_ghost_t = Union{PointerWrapper{p4est_ghost_t}, PointerWrapper{p8est_ghost_t}} -PW_pxest_mesh_t = Union{PointerWrapper{p4est_mesh_t}, PointerWrapper{p8est_mesh_t}} -PW_pxest_quadrant_t = Union{PointerWrapper{p4est_quadrant_t}, PointerWrapper{p8est_quadrant_t}} -PW_pxest_iter_volume_info_t = Union{PointerWrapper{p4est_iter_volume_info_t}, PointerWrapper{p8est_iter_volume_info_t}} -PW_pxest_iter_face_info_t = Union{PointerWrapper{p4est_iter_face_info_t},PointerWrapper{p8est_iter_face_info_t}} -PW_pxest_iter_face_side_t = Union{PointerWrapper{p4est_iter_face_side_t},PointerWrapper{p8est_iter_face_side_t}} +PW_pxest_t = Union{PointerWrapper{p4est_t},PointerWrapper{p8est_t}} +PW_pxest_ghost_t = Union{PointerWrapper{p4est_ghost_t},PointerWrapper{p8est_ghost_t}} +PW_pxest_mesh_t = Union{PointerWrapper{p4est_mesh_t},PointerWrapper{p8est_mesh_t}} +PW_pxest_quadrant_t = + Union{PointerWrapper{p4est_quadrant_t},PointerWrapper{p8est_quadrant_t}} +PW_pxest_iter_volume_info_t = + Union{PointerWrapper{p4est_iter_volume_info_t},PointerWrapper{p8est_iter_volume_info_t}} +PW_pxest_iter_face_info_t = + Union{PointerWrapper{p4est_iter_face_info_t},PointerWrapper{p8est_iter_face_info_t}} +PW_pxest_iter_face_side_t = + Union{PointerWrapper{p4est_iter_face_side_t},PointerWrapper{p8est_iter_face_side_t}} """ $(TYPEDEF) @@ -94,7 +142,7 @@ const MicroFlux = Union{DVM} const HybridFlux = Union{UGKS,CAIDVM} # to add more... -abstract type Euler <:AbstractTimeMarchingType end +abstract type Euler <: AbstractTimeMarchingType end abstract type UGKS_Marching<:AbstractTimeMarchingType end """ $(TYPEDEF) @@ -167,10 +215,11 @@ include("../Boundary/Types.jl") include("../Solver/Types.jl") include("../IO/Types.jl") -export SuperSonicInflow, SuperSonicOutflow, UniformOutflow, InterpolatedOutflow, Period, Maxwellian +export SuperSonicInflow, + SuperSonicOutflow, UniformOutflow, InterpolatedOutflow, Period, Maxwellian export AbstractInitCondType, AbstractBoundCondType, AbstractBoundaryType export Pixel, Voxel, Triangle, Tetra export AbstractPsData, AbstractFace export AbstractVsData export AbstractFluxType, AbstractDVMFluxType, CAIDVM -export AbstractTimeMarchingType, CAIDVM_Marching \ No newline at end of file +export AbstractTimeMarchingType, CAIDVM_Marching diff --git a/src/Boundary/Boundary.jl b/src/Boundary/Boundary.jl index e980922..30d10f1 100644 --- a/src/Boundary/Boundary.jl +++ b/src/Boundary/Boundary.jl @@ -3,11 +3,11 @@ include("Immersed_boundary.jl") include("Vertices.jl") include("Period.jl") include("Triangles.jl") -get_bc(bc::AbstractVector;kwargs...) = copy(bc) -function get_bc(bc::Function;intersect_point,ib,kwargs...) - bc(;intersect_point,ib) +get_bc(bc::AbstractVector; kwargs...) = copy(bc) +function get_bc(bc::Function; intersect_point, ib, kwargs...) + bc(; intersect_point, ib) end export Domain, Circle, Sphere, Vertices, Triangles, TriangleKDT export DomainFace -export initialize_solid_neighbor!, update_solid_neighbor!, update_solid_cell! \ No newline at end of file +export initialize_solid_neighbor!, update_solid_neighbor!, update_solid_cell! diff --git a/src/Boundary/Circle.jl b/src/Boundary/Circle.jl index 0e448a6..715a765 100644 --- a/src/Boundary/Circle.jl +++ b/src/Boundary/Circle.jl @@ -1,85 +1,144 @@ -function pre_ps_refine_flag(boundary::AbstractCircle,midpoint::AbstractVector,ds::AbstractVector,global_data::Global_Data) # Circle type IB boundary flag - boundary_flag(boundary,midpoint,ds,global_data) +function pre_ps_refine_flag( + boundary::AbstractCircle, + midpoint::AbstractVector, + ds::AbstractVector, + global_data::Global_Data, +) # Circle type IB boundary flag + boundary_flag(boundary, midpoint, ds, global_data) end -function boundary_flag(boundary::Circle,midpoint::AbstractVector,ds::AbstractVector,::Global_Data) # Circle type IB boundary flag +function boundary_flag( + boundary::Circle, + midpoint::AbstractVector, + ds::AbstractVector, + ::Global_Data, +) # Circle type IB boundary flag flag = 0 for i = 1:4 - flag += norm(midpoint.+ds.*NMT[2][i].-boundary.center)>boundary.radius ? 1 : -1 # any neighbor cross boundary? + flag += + norm(midpoint .+ ds .* NMT[2][i] .- boundary.center)>boundary.radius ? 1 : -1 # any neighbor cross boundary? end abs(flag)==4 && return false return true end -function boundary_flag(boundary::Sphere,midpoint::AbstractVector,ds::AbstractVector,::Global_Data) # Circle type IB boundary flag +function boundary_flag( + boundary::Sphere, + midpoint::AbstractVector, + ds::AbstractVector, + ::Global_Data, +) # Circle type IB boundary flag flag = 0 for i = 1:6 - flag += norm(midpoint.+ds.*NMT[3][i].-boundary.center)>boundary.radius ? 1 : -1 # any neighbor cross boundary? + flag += + norm(midpoint .+ ds .* NMT[3][i] .- boundary.center)>boundary.radius ? 1 : -1 # any neighbor cross boundary? end abs(flag)==6 && return false return true end -function solid_flag(boundary::AbstractCircle,midpoint::AbstractVector) # Does midpoint locate at solid? - return xor(norm(midpoint.-boundary.center)>boundary.radius,boundary.solid) +function solid_flag(boundary::AbstractCircle, midpoint::AbstractVector) # Does midpoint locate at solid? + return xor(norm(midpoint .- boundary.center)>boundary.radius, boundary.solid) end -function solid_cell_flag(boundary::AbstractCircle,midpoint::AbstractVector,ds::AbstractVector,global_data::Global_Data,inside::Bool) # Ghost nodes, those are inside solid domain and immediately adjacent the boundary. - (boundary_flag(boundary,midpoint,ds,global_data) && inside) && return true +function solid_cell_flag( + boundary::AbstractCircle, + midpoint::AbstractVector, + ds::AbstractVector, + global_data::Global_Data, + inside::Bool, +) # Ghost nodes, those are inside solid domain and immediately adjacent the boundary. + (boundary_flag(boundary, midpoint, ds, global_data) && inside) && return true return false end -function calc_IB_ρw(aux_point::AbstractVector,bound::Circle,midpoint::AbstractMatrix,weight::AbstractVector,df::AbstractMatrix,vn::AbstractVector,Θ::AbstractVector) - calc_IB_ρw_2D(aux_point,bound.bc,midpoint,weight,df,vn,Θ) +function calc_IB_ρw( + aux_point::AbstractVector, + bound::Circle, + midpoint::AbstractMatrix, + weight::AbstractVector, + df::AbstractMatrix, + vn::AbstractVector, + Θ::AbstractVector, +) + calc_IB_ρw_2D(aux_point, bound.bc, midpoint, weight, df, vn, Θ) end -function calc_IB_ρw(aux_point::AbstractVector,bound::Sphere,midpoint::AbstractMatrix,weight::AbstractVector,df::AbstractMatrix,vn::AbstractVector,Θ::AbstractVector) - calc_IB_ρw_3D(aux_point,bound.bc,midpoint,weight,df,vn,Θ) +function calc_IB_ρw( + aux_point::AbstractVector, + bound::Sphere, + midpoint::AbstractMatrix, + weight::AbstractVector, + df::AbstractMatrix, + vn::AbstractVector, + Θ::AbstractVector, +) + calc_IB_ρw_3D(aux_point, bound.bc, midpoint, weight, df, vn, Θ) end -function IB_prim(circle::AbstractCircle,aux_point::AbstractVector,ρw::Real) - IB_prim(circle.bc,aux_point,ρw) +function IB_prim(circle::AbstractCircle, aux_point::AbstractVector, ρw::Real) + IB_prim(circle.bc, aux_point, ρw) end -function calc_intersect(f_midpoint,s_midpoint,::Vector,::Int,circle::Circle) - c = circle.center;r = circle.radius +function calc_intersect(f_midpoint, s_midpoint, ::Vector, ::Int, circle::Circle) + c = circle.center; + r = circle.radius if abs(f_midpoint[1]-s_midpoint[1])c[2] - ap = [r*cos(t),r*sin(t)];n=ap./(circle.solid ? r : -r) + ap = [r*cos(t), r*sin(t)]; + n=ap ./ (circle.solid ? r : -r) else - ap = [r*cos(t),-r*sin(t)];n = ap./(circle.solid ? r : -r) + ap = [r*cos(t), -r*sin(t)]; + n = ap ./ (circle.solid ? r : -r) end else t = asin((f_midpoint[2]-c[2])/r) if f_midpoint[1]>c[1] - ap = [r*cos(t),r*sin(t)];n = ap./ (circle.solid ? r : -r) + ap = [r*cos(t), r*sin(t)]; + n = ap ./ (circle.solid ? r : -r) else - ap = [-r*cos(t),r*sin(t)];n = ap./ (circle.solid ? r : -r) + ap = [-r*cos(t), r*sin(t)]; + n = ap ./ (circle.solid ? r : -r) end end - return ap,n + return ap, n end -function calc_intersect(f_midpoint,s_midpoint,::Vector,::Int,circle::Sphere) - c = circle.center;r = circle.radius - dir = findfirst(x->x>EPS,abs.(f_midpoint-s_midpoint)) +function calc_intersect(f_midpoint, s_midpoint, ::Vector, ::Int, circle::Sphere) + c = circle.center; + r = circle.radius + dir = findfirst(x->x>EPS, abs.(f_midpoint-s_midpoint)) r_midpoint = f_midpoint-c - x = r_midpoint[dir%3+1]; y =r_midpoint[(dir+1)%3+1] - ap = copy(f_midpoint);n = copy(f_midpoint) + x = r_midpoint[dir%3+1]; + y = r_midpoint[(dir+1)%3+1] + ap = copy(f_midpoint); + n = copy(f_midpoint) rz = sqrt(r^2-x^2-y^2) - dz = abs((rz-r_midpoint[dir])/(s_midpoint[dir]-f_midpoint[dir])) < 1 ? rz-r_midpoint[dir] : -rz-r_midpoint[dir] - ap[dir] = dz+f_midpoint[dir];n[dir] = dz+r_midpoint[dir];n/=(circle.solid ? r : -r) - return ap,n + dz = + abs((rz-r_midpoint[dir])/(s_midpoint[dir]-f_midpoint[dir])) < 1 ? + rz-r_midpoint[dir] : -rz-r_midpoint[dir] + ap[dir] = dz+f_midpoint[dir]; + n[dir] = dz+r_midpoint[dir]; + n/=(circle.solid ? r : -r) + return ap, n end -function pre_partition_box_flag(midpoint,ds,ib::AbstractCircle) +function pre_partition_box_flag(midpoint, ds, ib::AbstractCircle) r = ib.search_radius - hyper_rec = HyperRectangle(SVector{3,Float64}(ib.center.-ib.radius.-r),SVector{3,Float64}(ib.center.+ib.radius.+r)) - lower = midpoint-0.5*ds;upper = midpoint+0.5*ds - if overlap_test(lower,upper,hyper_rec) + hyper_rec = HyperRectangle( + SVector{3,Float64}(ib.center .- ib.radius .- r), + SVector{3,Float64}(ib.center .+ ib.radius .+ r), + ) + lower = midpoint-0.5*ds; + upper = midpoint+0.5*ds + if overlap_test(lower, upper, hyper_rec) return true else return false end end -function search_radius_refine_flag!(i::Int,ib::AbstractCircle,midpoint,ds,mesh_data) +function search_radius_refine_flag!(i::Int, ib::AbstractCircle, midpoint, ds, mesh_data) r = ib.search_radius - hyper_rec = HyperRectangle(SVector{3,Float64}(ib.center.-ib.radius.-r),SVector{3,Float64}(ib.center.+ib.radius.+r)) - lower = midpoint-0.5*ds;upper = midpoint+0.5*ds - if overlap_test(lower,upper,hyper_rec) + hyper_rec = HyperRectangle( + SVector{3,Float64}(ib.center .- ib.radius .- r), + SVector{3,Float64}(ib.center .+ ib.radius .+ r), + ) + lower = midpoint-0.5*ds; + upper = midpoint+0.5*ds + if overlap_test(lower, upper, hyper_rec) mesh_data.in_box = i distance = abs(norm(midpoint-ib.center)-ib.radius) if distanceib.radius ? 1 : -1 # any neighbor cross boundary? + flag += norm(midpoint .+ ds .* NMT[3][i] .- ib.center)>ib.radius ? 1 : -1 # any neighbor cross boundary? end abs(flag)==6 && return false return true -end \ No newline at end of file +end diff --git a/src/Boundary/Immersed_boundary.jl b/src/Boundary/Immersed_boundary.jl index f4c0365..384e331 100644 --- a/src/Boundary/Immersed_boundary.jl +++ b/src/Boundary/Immersed_boundary.jl @@ -1,169 +1,281 @@ -function calc_IB_ρw_2D(::AbstractVector,bc::AbstractVector,midpoint::AbstractMatrix,weight::AbstractVector,df::AbstractMatrix,vn::AbstractVector,Θ::AbstractVector) - maxwellian_density_2D2F(@view(midpoint[:,1]),@view(midpoint[:,2]),@view(df[:,1]), bc, weight, Θ, vn) -end -function calc_IB_ρw_3D(::AbstractVector,bc::AbstractVector,midpoint::AbstractMatrix,weight::AbstractVector,df::AbstractMatrix,vn::AbstractVector,Θ::AbstractVector) - maxwellian_density_3D1F(@view(midpoint[:,1]),@view(midpoint[:,2]),@view(midpoint[:,3]),@view(df[:,1]), bc, weight, Θ, vn) -end -function IB_prim(bc::AbstractVector,::AbstractVector,ρw::Real) +function calc_IB_ρw_2D( + ::AbstractVector, + bc::AbstractVector, + midpoint::AbstractMatrix, + weight::AbstractVector, + df::AbstractMatrix, + vn::AbstractVector, + Θ::AbstractVector, +) + maxwellian_density_2D2F( + @view(midpoint[:, 1]), + @view(midpoint[:, 2]), + @view(df[:, 1]), + bc, + weight, + Θ, + vn, + ) +end +function calc_IB_ρw_3D( + ::AbstractVector, + bc::AbstractVector, + midpoint::AbstractMatrix, + weight::AbstractVector, + df::AbstractMatrix, + vn::AbstractVector, + Θ::AbstractVector, +) + maxwellian_density_3D1F( + @view(midpoint[:, 1]), + @view(midpoint[:, 2]), + @view(midpoint[:, 3]), + @view(df[:, 1]), + bc, + weight, + Θ, + vn, + ) +end +function IB_prim(bc::AbstractVector, ::AbstractVector, ρw::Real) prim = copy(bc) prim[1] = ρw return prim end -function save_boundary_result!(ib::AbstractBoundaryType,ps_data,solid_neighbor::SolidNeighbor{DIM,NDF},boundary_results,amr::KitAMR_Data{DIM,NDF};dir_path="") where{DIM,NDF} +function save_boundary_result!( + ib::AbstractBoundaryType, + ps_data, + solid_neighbor::SolidNeighbor{DIM,NDF}, + boundary_results, + amr::KitAMR_Data{DIM,NDF}; + dir_path = "", +) where {DIM,NDF} global_data = amr.global_data vs_data = ps_data.vs_data - aux_point = solid_neighbor.aux_point;n = solid_neighbor.normal + aux_point = solid_neighbor.aux_point; + n = solid_neighbor.normal faceid = solid_neighbor.faceid dir = get_dir(faceid) - solid_cell = solid_neighbor.solid_cell;s_vs_data = solid_cell.vs_data - vn = @views [dot(v,n) for v in eachrow(ps_data.vs_data.midpoint)] - aux_df = zeros(vs_data.vs_num,NDF) + solid_cell = solid_neighbor.solid_cell; + s_vs_data = solid_cell.vs_data + vn = @views [dot(v, n) for v in eachrow(ps_data.vs_data.midpoint)] + aux_df = zeros(vs_data.vs_num, NDF) ib_point = aux_point+ps_data.midpoint-solid_cell.midpoint - ib_df = image_df(ps_data,ib_point,amr) + ib_df = image_df(ps_data, ib_point, amr) Θ = heaviside.(vn) - ssdf = @views solid_neighbor.vs_data.sdf[:,:,dir] - boundary_slope!(ssdf,vs_data.level,s_vs_data.level,ib_df,vs_data.df, - s_vs_data.df,ib_point[dir]-ps_data.midpoint[dir],ps_data.midpoint[dir]-solid_neighbor.midpoint[dir],amr) + ssdf = @views solid_neighbor.vs_data.sdf[:, :, dir] + boundary_slope!( + ssdf, + vs_data.level, + s_vs_data.level, + ib_df, + vs_data.df, + s_vs_data.df, + ib_point[dir]-ps_data.midpoint[dir], + ps_data.midpoint[dir]-solid_neighbor.midpoint[dir], + amr, + ) @. aux_df = ib_df+ssdf*(aux_point[dir]-ib_point[dir]) - cvc_gas_correction!(aux_df,solid_neighbor) - aux_prim = get_bc(ib.bc;intersect_point=aux_point,ib);aux_prim[1] = 1. - M = discrete_maxwell(vs_data.midpoint,aux_prim,global_data) - _,Mu_R = @views cvc_Mu(M[:,1],vn,Θ,solid_neighbor) - ρw = cvc_density(aux_df,vn,Θ,solid_neighbor,Mu_R) + cvc_gas_correction!(aux_df, solid_neighbor) + aux_prim = get_bc(ib.bc; intersect_point = aux_point, ib); + aux_prim[1] = 1.0 + M = discrete_maxwell(vs_data.midpoint, aux_prim, global_data) + _, Mu_R = @views cvc_Mu(M[:, 1], vn, Θ, solid_neighbor) + ρw = cvc_density(aux_df, vn, Θ, solid_neighbor, Mu_R) aux_prim[1] = ρw M .*= aux_prim[1] - for i in 1:vs_data.vs_num - if Θ[i]==1. - for j in axes(aux_df,2) - aux_df[i,j] = M[i,j] + for i = 1:vs_data.vs_num + if Θ[i]==1.0 + for j in axes(aux_df, 2) + aux_df[i, j] = M[i, j] end end end - cvc_correction!(aux_df,M,solid_neighbor,amr) - aux_w = calc_w0(vs_data.midpoint,aux_df,vs_data.weight,global_data) - aux_prim = get_prim(aux_w,global_data) - aux_qf = calc_qf(vs_data.midpoint,aux_df,vs_data.weight,aux_prim,global_data) - aux_p = calc_pressure(vs_data.midpoint,aux_df,vs_data.weight,global_data) - push!(boundary_results[ps_data.bound_enc].midpoints,aux_point) - push!(boundary_results[ps_data.bound_enc].normal,n) - push!(boundary_results[ps_data.bound_enc].ps_solutions,Boundary_PS_Solution(aux_prim,aux_qf,aux_p)) + cvc_correction!(aux_df, M, solid_neighbor, amr) + aux_w = calc_w0(vs_data.midpoint, aux_df, vs_data.weight, global_data) + aux_prim = get_prim(aux_w, global_data) + aux_qf = calc_qf(vs_data.midpoint, aux_df, vs_data.weight, aux_prim, global_data) + aux_p = calc_pressure(vs_data.midpoint, aux_df, vs_data.weight, global_data) + push!(boundary_results[ps_data.bound_enc].midpoints, aux_point) + push!(boundary_results[ps_data.bound_enc].normal, n) + push!( + boundary_results[ps_data.bound_enc].ps_solutions, + Boundary_PS_Solution(aux_prim, aux_qf, aux_p), + ) if NDF==2 - @suppress write_vs_VTK(aux_df,vs_data,amr,dir_path*"/"*string(ps_data.midpoint)*string(n),["h","b"],fieldvalues_fn) + @suppress write_vs_VTK( + aux_df, + vs_data, + amr, + dir_path*"/"*string(ps_data.midpoint)*string(n), + ["h", "b"], + fieldvalues_fn, + ) elseif NDF==1 - @suppress write_vs_VTK(aux_df,vs_data,amr,dir_path*"/"*string(ps_data.midpoint)*string(n),["df"],fieldvalues_fn) + @suppress write_vs_VTK( + aux_df, + vs_data, + amr, + dir_path*"/"*string(ps_data.midpoint)*string(n), + ["df"], + fieldvalues_fn, + ) end end -function save_boundary_result!(ib::AbstractBoundaryType,ps_data::PS_Data{DIM,NDF},boundary_results::Vector{Boundary_Solution},amr::KitAMR_Data{DIM,NDF};dir_path="") where{DIM,NDF} - solid_neighbors = findall(x->isa(x[1],SolidNeighbor),ps_data.neighbor.data) +function save_boundary_result!( + ib::AbstractBoundaryType, + ps_data::PS_Data{DIM,NDF}, + boundary_results::Vector{Boundary_Solution}, + amr::KitAMR_Data{DIM,NDF}; + dir_path = "", +) where {DIM,NDF} + solid_neighbors = findall(x->isa(x[1], SolidNeighbor), ps_data.neighbor.data) for i in solid_neighbors - save_boundary_result!(ib,ps_data,ps_data.neighbor.data[i][1],boundary_results,amr;dir_path) + save_boundary_result!( + ib, + ps_data, + ps_data.neighbor.data[i][1], + boundary_results, + amr; + dir_path, + ) end end -function solid_cell_index_encoder!(solid_cell_index::Vector{Int},now_index::Int) - id = findfirst(x->x==0,solid_cell_index) +function solid_cell_index_encoder!(solid_cell_index::Vector{Int}, now_index::Int) + id = findfirst(x->x==0, solid_cell_index) isnothing(id) && (@error `A larger SOLID_CELL_ID_NUM is needed!`) solid_cell_index[id]=now_index end function solid_cell_index_decoder(solid_cell_index::Vector{Int}) - ids = findall(x->x!=0,solid_cell_index) + ids = findall(x->x!=0, solid_cell_index) return solid_cell_index[ids] end -function solid_cell_index2ranks(indices::Vector,quadids::Vector,gfq::Vector) # give the 1-based ranks containing solid_cells in indices +function solid_cell_index2ranks(indices::Vector, quadids::Vector, gfq::Vector) # give the 1-based ranks containing solid_cells in indices qids = quadids[indices] lrank = MPI.Comm_rank(MPI.COMM_WORLD)+1 - ranks = Int[];lids = Int[] + ranks = Int[]; + lids = Int[] for i in eachindex(qids) - rank = findfirst(x->x>qids[i],gfq)-1 - !(rank==lrank||in(rank,ranks))&&push!(ranks,rank) - rank==lrank&&push!(lids,indices[i]) + rank = findfirst(x->x>qids[i], gfq)-1 + !(rank==lrank||in(rank, ranks))&&push!(ranks, rank) + rank==lrank&&push!(lids, indices[i]) end - return ranks,lids + return ranks, lids end -function solid_flag(::Domain,::AbstractVector) # Does midpoint locate at solid? +function solid_flag(::Domain, ::AbstractVector) # Does midpoint locate at solid? return false end -function solid_flag(midpoint,global_data::Global_Data) +function solid_flag(midpoint, global_data::Global_Data) for boundary in global_data.config.IB - solid_flag(boundary,midpoint) && return true + solid_flag(boundary, midpoint) && return true end for domain in global_data.config.domain - solid_flag(domain,midpoint) && return true + solid_flag(domain, midpoint) && return true end return false end -function solid_cell_flag(boundaries::Vector{AbstractBoundaryType},midpoint::AbstractVector,ds::AbstractVector,global_data::Global_Data) +function solid_cell_flag( + boundaries::Vector{AbstractBoundaryType}, + midpoint::AbstractVector, + ds::AbstractVector, + global_data::Global_Data, +) for boundary in boundaries - solid_cell_flag(boundary,midpoint,ds,global_data,solid_flag(boundary,midpoint))&& return true + solid_cell_flag( + boundary, + midpoint, + ds, + global_data, + solid_flag(boundary, midpoint), + ) && return true end return false end -function InsideSolid_flag(boundary::AbstractBoundaryType,midpoint::AbstractVector,ds::AbstractVector,global_data::Global_Data) - inside = solid_flag(boundary,midpoint) - (solid_flag(boundary,midpoint)&&!solid_cell_flag(boundary,midpoint,ds,global_data,inside))&& return true # In solid region and not the ghost cell( a.k.a. solid cell) +function InsideSolid_flag( + boundary::AbstractBoundaryType, + midpoint::AbstractVector, + ds::AbstractVector, + global_data::Global_Data, +) + inside = solid_flag(boundary, midpoint) + ( + solid_flag( + boundary, + midpoint, + )&&!solid_cell_flag(boundary, midpoint, ds, global_data, inside) + ) && return true # In solid region and not the ghost cell( a.k.a. solid cell) return false end -function InsideSolid_flag(boundaries::Vector{AbstractBoundaryType},midpoint::AbstractVector,ds::AbstractVector,global_data::Global_Data) +function InsideSolid_flag( + boundaries::Vector{AbstractBoundaryType}, + midpoint::AbstractVector, + ds::AbstractVector, + global_data::Global_Data, +) for boundary in boundaries - InsideSolid_flag(boundary,midpoint,ds,global_data) && return true + InsideSolid_flag(boundary, midpoint, ds, global_data) && return true end return false end function pre_broadcast_boundary_points(boundary_points::Vector) Nb = length(boundary_points) - numbers = Vector{Int}(undef,Nb) + numbers = Vector{Int}(undef, Nb) for i in eachindex(boundary_points) numbers[i] = length(boundary_points[i]) end - Numbers = Vector{Vector{Int}}(undef,MPI.Comm_size(MPI.COMM_WORLD)) + Numbers = Vector{Vector{Int}}(undef, MPI.Comm_size(MPI.COMM_WORLD)) for i in eachindex(Numbers) if i-1 == MPI.Comm_rank(MPI.COMM_WORLD) Numbers[i] = numbers else - Numbers[i] = Vector{Int}(undef,Nb) + Numbers[i] = Vector{Int}(undef, Nb) end end for i in eachindex(Numbers) - MPI.Bcast!(Numbers[i],i-1,MPI.COMM_WORLD) + MPI.Bcast!(Numbers[i], i-1, MPI.COMM_WORLD) end return Numbers end -function broadcast_boundary_midpoints!(boundary_points::Vector{Vector{Vector{Float64}}},::Global_Data{DIM})where{DIM} +function broadcast_boundary_midpoints!( + boundary_points::Vector{Vector{Vector{Float64}}}, + ::Global_Data{DIM}, +) where {DIM} Numbers = pre_broadcast_boundary_points(boundary_points) - rbuffer = Vector{Vector{Vector{Float64}}}(undef,length(boundary_points)) # boundaries{ranks{points}} - sbuffer = Vector{Vector{Float64}}(undef,length(boundary_points)) # boundaries{points} + rbuffer = Vector{Vector{Vector{Float64}}}(undef, length(boundary_points)) # boundaries{ranks{points}} + sbuffer = Vector{Vector{Float64}}(undef, length(boundary_points)) # boundaries{points} for i in eachindex(boundary_points) - buffer = Vector{Float64}(undef,DIM*length(boundary_points[i])) + buffer = Vector{Float64}(undef, DIM*length(boundary_points[i])) for j in eachindex(boundary_points[i]) - buffer[DIM*(j-1)+1:DIM*j] .= boundary_points[i][j] + buffer[(DIM*(j-1)+1):(DIM*j)] .= boundary_points[i][j] end sbuffer[i] = buffer end for i in eachindex(boundary_points) - rbuffer[i] = Vector{Vector{Float64}}(undef,MPI.Comm_size(MPI.COMM_WORLD)) + rbuffer[i] = Vector{Vector{Float64}}(undef, MPI.Comm_size(MPI.COMM_WORLD)) for j in eachindex(Numbers) - if j-1==MPI.Comm_rank(MPI.COMM_WORLD) + if j-1==MPI.Comm_rank(MPI.COMM_WORLD) rbuffer[i][j] = sbuffer[i] else - rbuffer[i][j] = Vector{Float64}(undef,DIM*Numbers[j][i]) + rbuffer[i][j] = Vector{Float64}(undef, DIM*Numbers[j][i]) end end end for i in eachindex(boundary_points) for j in eachindex(Numbers) - MPI.Bcast!(rbuffer[i][j],j-1,MPI.COMM_WORLD) + MPI.Bcast!(rbuffer[i][j], j-1, MPI.COMM_WORLD) end end MPI.Barrier(MPI.COMM_WORLD) - solid_points_global = Vector{Vector{Vector{Float64}}}(undef,length(boundary_points)) + solid_points_global = Vector{Vector{Vector{Float64}}}(undef, length(boundary_points)) for i in eachindex(boundary_points) solid_points_global[i] = Vector{Float64}[] for j in eachindex(Numbers) if j-1 == MPI.Comm_rank(MPI.COMM_WORLD) - append!(solid_points_global[i],boundary_points[i]) + append!(solid_points_global[i], boundary_points[i]) else - for k in 1:Int(length(rbuffer[i][j])/DIM) - push!(solid_points_global[i],rbuffer[i][j][DIM*(k-1)+1:DIM*k]) + for k = 1:Int(length(rbuffer[i][j])/DIM) + push!(solid_points_global[i], rbuffer[i][j][(DIM*(k-1)+1):(DIM*k)]) end end end @@ -172,24 +284,31 @@ function broadcast_boundary_midpoints!(boundary_points::Vector{Vector{Vector{Flo end -function IB_flag(boundary::AbstractBoundaryType,aux_point::AbstractVector,midpoint::AbstractVector,ds::AbstractVector,level::Integer,global_data::Global_Data{DIM}) where{DIM} +function IB_flag( + boundary::AbstractBoundaryType, + aux_point::AbstractVector, + midpoint::AbstractVector, + ds::AbstractVector, + level::Integer, + global_data::Global_Data{DIM}, +) where {DIM} r = boundary.search_radius if level==global_data.config.solver.AMR_PS_MAXLEVEL return norm(midpoint-aux_point)r+R+0.5*norm(ds)||rx!isnothing(x[1])&&!isa(x[1],AbstractInsideSolidData)&&x[1].bound_enc>=0,ps_data.neighbor.data) + ps_data.prim = get_prim(ps_data, amr.global_data) +end +function update_solid_cell!( + ps_data::PS_Data{DIM,NDF}, + amr::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} + fluid_dirs = findall( + x->!isnothing(x[1])&&!isa(x[1], AbstractInsideSolidData)&&x[1].bound_enc>=0, + ps_data.neighbor.data, + ) fluid_cells = [ps_data.neighbor.data[i][1] for i in fluid_dirs] - update_solid_cell!(amr.global_data.config.solver.flux,ps_data,fluid_cells,amr) + update_solid_cell!(amr.global_data.config.solver.flux, ps_data, fluid_cells, amr) end """ @@ -311,8 +494,8 @@ Update `solid_cell` in [`SolidNeighbor`](@ref) with interpolation. function update_solid_cell!(amr::KitAMR_Data) for tree in amr.field.trees.data for ps_data in tree - (isa(ps_data,InsideSolidData)||ps_data.bound_enc>=0)&&continue - update_solid_cell!(ps_data,amr) + (isa(ps_data, InsideSolidData)||ps_data.bound_enc>=0)&&continue + update_solid_cell!(ps_data, amr) end end end @@ -323,109 +506,197 @@ $(TYPEDSIGNATURES) function initialize_solid_neighbor!(amr::KitAMR_Data) for tree in amr.field.trees.data for ps_data in tree - (isa(ps_data,InsideSolidData)||ps_data.bound_enc<0)&&continue - initialize_solid_neighbor!(ps_data,amr) + (isa(ps_data, InsideSolidData)||ps_data.bound_enc<0)&&continue + initialize_solid_neighbor!(ps_data, amr) end end end -function initialize_cutted_velocity_cell(n::Vector{Float64},vs_data::VS_Data{2},amr::KitAMR_Data{2,NDF}) where{NDF} - any(x->abs(x)<1e-6,n)&&(return CuttedVelocityCells(Int[],copy(vs_data.weight),Matrix{Float64}(undef,0,0),Matrix{Float64}(undef,0,0),Float64[],Float64[])) +function initialize_cutted_velocity_cell( + n::Vector{Float64}, + vs_data::VS_Data{2}, + amr::KitAMR_Data{2,NDF}, +) where {NDF} + any( + x->abs(x)<1e-6, + n, + )&&( + return CuttedVelocityCells( + Int[], + copy(vs_data.weight), + Matrix{Float64}(undef, 0, 0), + Matrix{Float64}(undef, 0, 0), + Float64[], + Float64[], + ) + ) global_data = amr.global_data - du = [(global_data.config.quadrature[2*i] - global_data.config.quadrature[2*i-1]) / - global_data.config.vs_trees_num[i] for i in 1:2] - vertices = [zeros(2) for _ in 1:4] - index = Int[];solid_weights = Float64[];gas_weights = Float64[] - for i in 1:vs_data.vs_num - ddu = du./2^(vs_data.level[i]) - @views abs(dot(vs_data.midpoint[i,:],n))>0.5*norm(ddu)&&continue + du = [ + (global_data.config.quadrature[2*i] - global_data.config.quadrature[2*i-1]) / + global_data.config.vs_trees_num[i] for i = 1:2 + ] + vertices = [zeros(2) for _ = 1:4] + index = Int[]; + solid_weights = Float64[]; + gas_weights = Float64[] + for i = 1:vs_data.vs_num + ddu = du ./ 2^(vs_data.level[i]) + @views abs(dot(vs_data.midpoint[i, :], n))>0.5*norm(ddu)&&continue for j in eachindex(vertices) - vertices[j] .= @views 0.5*ANTIVT[2][j].*ddu+vs_data.midpoint[i,:] + vertices[j] .= @views 0.5*ANTIVT[2][j] .* ddu+vs_data.midpoint[i, :] end - flag,gas_weight,solid_weight = cut_rect(n,vertices) + flag, gas_weight, solid_weight = cut_rect(n, vertices) if flag - push!(index,i);push!(solid_weights,solid_weight);push!(gas_weights,gas_weight) + push!(index, i); + push!(solid_weights, solid_weight); + push!(gas_weights, gas_weight) end end N = length(index) - gas_dfs = zeros(N,NDF);solid_dfs = zeros(N,NDF) + gas_dfs = zeros(N, NDF); + solid_dfs = zeros(N, NDF) weight = copy(vs_data.weight) - weight[index].=0. - return CuttedVelocityCells(index,weight,gas_dfs,solid_dfs,gas_weights,solid_weights) -end -function initialize_cutted_velocity_cell(n::AbstractVector,vs_data::VS_Data{3},amr::KitAMR_Data{3,NDF}) where{NDF} - l = findall(x->abs(x)<1e-6,n) - length(l)>1 && - (return CuttedVelocityCells(Int[],copy(vs_data.weight),Matrix{Float64}(undef,0,0),Matrix{Float64}(undef,0,0),Float64[],Float64[])) + weight[index].=0.0 + return CuttedVelocityCells( + index, + weight, + gas_dfs, + solid_dfs, + gas_weights, + solid_weights, + ) +end +function initialize_cutted_velocity_cell( + n::AbstractVector, + vs_data::VS_Data{3}, + amr::KitAMR_Data{3,NDF}, +) where {NDF} + l = findall(x->abs(x)<1e-6, n) + length(l)>1 && ( + return CuttedVelocityCells( + Int[], + copy(vs_data.weight), + Matrix{Float64}(undef, 0, 0), + Matrix{Float64}(undef, 0, 0), + Float64[], + Float64[], + ) + ) global_data = amr.global_data - du = [(global_data.config.quadrature[2*i] - global_data.config.quadrature[2*i-1]) / - global_data.config.vs_trees_num[i] for i in 1:3] - vertices = zeros(3,8) - index = Int[];solid_weights = Float64[];gas_weights = Float64[] + du = [ + (global_data.config.quadrature[2*i] - global_data.config.quadrature[2*i-1]) / + global_data.config.vs_trees_num[i] for i = 1:3 + ] + vertices = zeros(3, 8) + index = Int[]; + solid_weights = Float64[]; + gas_weights = Float64[] C = cut_cube_rotate(n) - for i in 1:vs_data.vs_num - ddu = du./2^(vs_data.level[i]) - midpoint = vs_data.midpoint[i,:] - abs(dot(midpoint,n))>0.5*norm(ddu)&&continue - for j in axes(vertices,2) - vertices[:,j] .= 0.5*ANTIVT[3][j].*ddu+midpoint + for i = 1:vs_data.vs_num + ddu = du ./ 2^(vs_data.level[i]) + midpoint = vs_data.midpoint[i, :] + abs(dot(midpoint, n))>0.5*norm(ddu)&&continue + for j in axes(vertices, 2) + vertices[:, j] .= 0.5*ANTIVT[3][j] .* ddu+midpoint end - flag,gas_weight,solid_weight = cut_cube(n,C,midpoint,ddu,vertices) + flag, gas_weight, solid_weight = cut_cube(n, C, midpoint, ddu, vertices) if flag - push!(index,i);push!(solid_weights,solid_weight);push!(gas_weights,gas_weight) + push!(index, i); + push!(solid_weights, solid_weight); + push!(gas_weights, gas_weight) end end N = length(index) - gas_dfs = zeros(N,NDF);solid_dfs = zeros(N,NDF) + gas_dfs = zeros(N, NDF); + solid_dfs = zeros(N, NDF) weight = copy(vs_data.weight) - weight[index].=0. - return CuttedVelocityCells(index,weight,gas_dfs,solid_dfs,gas_weights,solid_weights) + weight[index].=0.0 + return CuttedVelocityCells( + index, + weight, + gas_dfs, + solid_dfs, + gas_weights, + solid_weights, + ) end """ $(TYPEDSIGNATURES) """ -function initialize_solid_neighbor!(ps_data::PS_Data{DIM,NDF},amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} - solid_dirs = findall(x->!isnothing(x[1])&&x[1].bound_enc<0,ps_data.neighbor.data[1:2*DIM]) +function initialize_solid_neighbor!( + ps_data::PS_Data{DIM,NDF}, + amr::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} + solid_dirs = + findall(x->!isnothing(x[1])&&x[1].bound_enc<0, ps_data.neighbor.data[1:(2*DIM)]) vs_data = ps_data.vs_data for i in solid_dirs solid_cell = ps_data.neighbor.data[i][1] ps_data.bound_enc = -solid_cell.bound_enc ib = amr.global_data.config.IB[-solid_cell.bound_enc] - aux_point,normal = calc_intersect(ps_data.midpoint,solid_cell.midpoint,ps_data.ds,get_dir(i),ib) + aux_point, normal = calc_intersect( + ps_data.midpoint, + solid_cell.midpoint, + ps_data.ds, + get_dir(i), + ib, + ) svsdata = VS_Data{DIM,NDF}( vs_data.vs_num, vs_data.level, vs_data.weight, vs_data.midpoint, copy(vs_data.df), - zeros(vs_data.vs_num,NDF,DIM), - Matrix{Float64}(undef,0,0) + zeros(vs_data.vs_num, NDF, DIM), + Matrix{Float64}(undef, 0, 0), ) - cvc = initialize_cutted_velocity_cell(normal,svsdata,amr) # heavy overhead + cvc = initialize_cutted_velocity_cell(normal, svsdata, amr) # heavy overhead ps_data.neighbor.data[i][1] = SolidNeighbor{DIM,NDF}( - solid_cell.bound_enc,i,0,aux_point,normal,solid_cell,solid_cell.midpoint,solid_cell.ds,zeros(DIM+2),zeros(DIM+2,DIM),cvc,svsdata + solid_cell.bound_enc, + i, + 0, + aux_point, + normal, + solid_cell, + solid_cell.midpoint, + solid_cell.ds, + zeros(DIM+2), + zeros(DIM+2, DIM), + cvc, + svsdata, ) end return nothing end -function vs_interpolate!(f_df::AbstractMatrix,f_level::AbstractVector{Int8},fx,s_df,s_level,sx,b_df,bx,::KitAMR_Data{DIM,NDF}) where{DIM,NDF} - j = 1;flag = 0.0 - @inbounds for i in axes(f_df,1) +function vs_interpolate!( + f_df::AbstractMatrix, + f_level::AbstractVector{Int8}, + fx, + s_df, + s_level, + sx, + b_df, + bx, + ::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} + j = 1; + flag = 0.0 + @inbounds for i in axes(f_df, 1) if f_level[i] == s_level[j] - @. b_df[i, :] = @views f_df[i,:]+(s_df[j, :]-f_df[i,:])/(sx-fx)*(bx-fx) + @. b_df[i, :] = @views f_df[i, :]+(s_df[j, :]-f_df[i, :])/(sx-fx)*(bx-fx) j += 1 elseif f_level[i] < s_level[j] - @. b_df[i,:] = @views -f_df[i,:] + @. b_df[i, :] = @views -f_df[i, :] while flag != 1.0 - @. b_df[i, :] += @views s_df[j,:]/ 2^(DIM * (s_level[j] - f_level[i])) + @. b_df[i, :] += @views s_df[j, :] / 2^(DIM * (s_level[j] - f_level[i])) flag += 1 / 2^(DIM * (s_level[j] - f_level[i])) j += 1 end - @. b_df[i,:]*=(bx-fx)/(sx-fx) - @. b_df[i,:] += @views f_df[i,:] + @. b_df[i, :]*=(bx-fx)/(sx-fx) + @. b_df[i, :] += @views f_df[i, :] flag = 0.0 else - @. b_df[i, :] += @views f_df[i,:]+(s_df[j, :]-f_df[i,:])/(sx-fx)*(bx-fx) + @. b_df[i, :] += @views f_df[i, :]+(s_df[j, :]-f_df[i, :])/(sx-fx)*(bx-fx) flag += 1 / 2^(DIM * (f_level[i] - s_level[j])) if flag == 1.0 j += 1 @@ -434,24 +705,30 @@ function vs_interpolate!(f_df::AbstractMatrix,f_level::AbstractVector{Int8},fx,s end end end -function cvc_gas_correction!(aux_df,solid_neighbor::SolidNeighbor{DIM,NDF}) where{DIM,NDF} +function cvc_gas_correction!(aux_df, solid_neighbor::SolidNeighbor{DIM,NDF}) where {DIM,NDF} cvc = solid_neighbor.cvc for i in eachindex(cvc.indices) - cvc.gas_dfs[i,:] .= @views aux_df[cvc.indices[i],:] + cvc.gas_dfs[i, :] .= @views aux_df[cvc.indices[i], :] end end -function cvc_density(aux_df,vn::AbstractVector,Θ,solid_neighbor::SolidNeighbor,MuR::Real) +function cvc_density( + aux_df, + vn::AbstractVector, + Θ, + solid_neighbor::SolidNeighbor, + MuR::Real, +) cvc = solid_neighbor.cvc - @inbounds @views SF = sum(@. cvc.weight * vn * aux_df[:,1] * (1.0 - Θ)) + @inbounds @views SF = sum(@. cvc.weight * vn * aux_df[:, 1] * (1.0 - Θ)) for i in eachindex(cvc.indices) cvc_vn = vn[cvc.indices[i]] - SF += cvc.gas_weights[i]*cvc_vn*cvc.gas_dfs[i,1] + SF += cvc.gas_weights[i]*cvc_vn*cvc.gas_dfs[i, 1] end return -SF/MuR end -function cvc_Mu(M::AbstractVector,vn,Θ,solid_neighbor) +function cvc_Mu(M::AbstractVector, vn, Θ, solid_neighbor) cvc = solid_neighbor.cvc - Mu_cvc = @. @views cvc.weight * vn *M + Mu_cvc = @. @views cvc.weight * vn * M MuL = sum(@. Mu_cvc*(1.0-Θ)) MuR = sum(@. Mu_cvc * Θ) for i in eachindex(cvc.indices) @@ -459,52 +736,84 @@ function cvc_Mu(M::AbstractVector,vn,Θ,solid_neighbor) MuL += cvc.gas_weights[i]*cvc_vn*M[cvc.indices[i]] MuR += cvc.solid_weights[i]*cvc_vn*M[cvc.indices[i]] end - return MuL,MuR + return MuL, MuR end -function cvc_correction!(aux_df,F::AbstractMatrix,solid_neighbor,amr) +function cvc_correction!(aux_df, F::AbstractMatrix, solid_neighbor, amr) cvc = solid_neighbor.cvc for i in eachindex(cvc.indices) - cvc.solid_dfs[i,:] .= @views F[cvc.indices[i],:] - @views @. aux_df[cvc.indices[i],:] = (cvc.gas_weights[i]*cvc.gas_dfs[i,:]+cvc.solid_weights[i]*cvc.solid_dfs[i,:])/(cvc.gas_weights[i]+cvc.solid_weights[i]) - end -end -function image_df(ps_data,ip,amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} - fluid_dirs = findall(x->!isnothing(x[1])&&!isa(x[1],AbstractInsideSolidData)&&x[1].bound_enc>=0,ps_data.neighbor.data) - fluid_cells = Vector{AbstractPsData{DIM,NDF}}(undef,length(fluid_dirs)+1) + cvc.solid_dfs[i, :] .= @views F[cvc.indices[i], :] + @views @. aux_df[cvc.indices[i], :] = + ( + cvc.gas_weights[i]*cvc.gas_dfs[ + i, + :, + ]+cvc.solid_weights[i]*cvc.solid_dfs[i, :] + )/(cvc.gas_weights[i]+cvc.solid_weights[i]) + end +end +function image_df(ps_data, ip, amr::KitAMR_Data{DIM,NDF}) where {DIM,NDF} + fluid_dirs = findall( + x->!isnothing(x[1])&&!isa(x[1], AbstractInsideSolidData)&&x[1].bound_enc>=0, + ps_data.neighbor.data, + ) + fluid_cells = Vector{AbstractPsData{DIM,NDF}}(undef, length(fluid_dirs)+1) for i in eachindex(fluid_dirs) fluid_cells[i] = ps_data.neighbor.data[fluid_dirs[i]][1] end fluid_cells[end]=ps_data - image_df(ps_data,fluid_cells,ip,amr) + image_df(ps_data, fluid_cells, ip, amr) end -function image_df(ps_data::PS_Data{DIM,NDF},fluid_cells,ip,amr) where{DIM,NDF} +function image_df(ps_data::PS_Data{DIM,NDF}, fluid_cells, ip, amr) where {DIM,NDF} vs_data = ps_data.vs_data - image_df = zeros(vs_data.vs_num,NDF) - weights = Matrix{Float64}(undef,vs_data.vs_num,length(fluid_cells)) + image_df = zeros(vs_data.vs_num, NDF) + weights = Matrix{Float64}(undef, vs_data.vs_num, length(fluid_cells)) for i in eachindex(fluid_cells) - l = ip-fluid_cells[i].midpoint;l/=norm(l) - weights[:,i] .= [max(0.,dot(u,l)/norm(u))^2 for u in eachrow(vs_data.midpoint)] + l = ip-fluid_cells[i].midpoint; + l/=norm(l) + weights[:, i] .= [max(0.0, dot(u, l)/norm(u))^2 for u in eachrow(vs_data.midpoint)] end - weight_i = Vector{Float64}(undef,vs_data.vs_num) - weight_sum = sum(weights,dims=2) + weight_i = Vector{Float64}(undef, vs_data.vs_num) + weight_sum = sum(weights, dims = 2) for i in eachindex(fluid_cells) f_vs_data = fluid_cells[i].vs_data for j in eachindex(weight_i) - weight_i[j] = weight_sum[j]==0. ? 1.0/length(fluid_cells) : weights[j,i]/weight_sum[j] + weight_i[j] = + weight_sum[j]==0.0 ? 1.0/length(fluid_cells) : weights[j, i]/weight_sum[j] end - fdf = f_vs_data.df;fsdf = f_vs_data.sdf;dx = ip-fluid_cells[i].midpoint - vs_extrapolate!(fdf,fsdf,f_vs_data.level,image_df,vs_data.level,dx,weight_i,amr) + fdf = f_vs_data.df; + fsdf = f_vs_data.sdf; + dx = ip-fluid_cells[i].midpoint + vs_extrapolate!( + fdf, + fsdf, + f_vs_data.level, + image_df, + vs_data.level, + dx, + weight_i, + amr, + ) end return image_df end -function boundary_slope!(sdf::AbstractMatrix,level,level_n,sp_df,dc_df,sc_df,dxf::Float64,dxs::Float64,::KitAMR_Data{DIM,NDF}) where{DIM,NDF} - sL = zeros(size(sdf,1),NDF) +function boundary_slope!( + sdf::AbstractMatrix, + level, + level_n, + sp_df, + dc_df, + sc_df, + dxf::Float64, + dxs::Float64, + ::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} + sL = zeros(size(sdf, 1), NDF) index = 1 flag = 0.0 df = dc_df dfn = sc_df - @inbounds for i in axes(sL,1) + @inbounds for i in axes(sL, 1) if level[i] == level_n[index] for j = 1:NDF sL[i, j] = (df[i, j] - dfn[index, j]) / dxs @@ -532,70 +841,98 @@ function boundary_slope!(sdf::AbstractMatrix,level,level_n,sp_df,dc_df,sc_df,dxf end end end - for j in axes(sdf,2) - for i in axes(sdf,1) - sdf[i,j] = minmod(sL[i,j],(sp_df[i,j]-dc_df[i,j])/dxf) + for j in axes(sdf, 2) + for i in axes(sdf, 1) + sdf[i, j] = minmod(sL[i, j], (sp_df[i, j]-dc_df[i, j])/dxf) end end end -function update_solid_neighbor!(::Type{T},ps_data::PS_Data{DIM,NDF},solid_neighbor::SolidNeighbor{DIM,NDF},amr::KitAMR_Data) where{DIM,NDF,T<:AbstractFluxType} - global_data = amr.global_data;ib = global_data.config.IB[ps_data.bound_enc] +function update_solid_neighbor!( + ::Type{T}, + ps_data::PS_Data{DIM,NDF}, + solid_neighbor::SolidNeighbor{DIM,NDF}, + amr::KitAMR_Data, +) where {DIM,NDF,T<:AbstractFluxType} + global_data = amr.global_data; + ib = global_data.config.IB[ps_data.bound_enc] vs_data = ps_data.vs_data - aux_point = solid_neighbor.aux_point;n = solid_neighbor.normal + aux_point = solid_neighbor.aux_point; + n = solid_neighbor.normal faceid = solid_neighbor.faceid dir = get_dir(faceid) - solid_cell = solid_neighbor.solid_cell;s_vs_data = solid_cell.vs_data - vn = @views [dot(v,n) for v in eachrow(ps_data.vs_data.midpoint)] - aux_df = zeros(vs_data.vs_num,NDF) + solid_cell = solid_neighbor.solid_cell; + s_vs_data = solid_cell.vs_data + vn = @views [dot(v, n) for v in eachrow(ps_data.vs_data.midpoint)] + aux_df = zeros(vs_data.vs_num, NDF) ib_point = aux_point+ps_data.midpoint-solid_cell.midpoint - ib_df = image_df(ps_data,ib_point,amr) + ib_df = image_df(ps_data, ib_point, amr) Θ = heaviside.(vn) - ssdf = @views solid_neighbor.vs_data.sdf[:,:,dir] - boundary_slope!(ssdf,vs_data.level,s_vs_data.level,ib_df,vs_data.df, - s_vs_data.df,ib_point[dir]-ps_data.midpoint[dir],ps_data.midpoint[dir]-solid_neighbor.midpoint[dir],amr) + ssdf = @views solid_neighbor.vs_data.sdf[:, :, dir] + boundary_slope!( + ssdf, + vs_data.level, + s_vs_data.level, + ib_df, + vs_data.df, + s_vs_data.df, + ib_point[dir]-ps_data.midpoint[dir], + ps_data.midpoint[dir]-solid_neighbor.midpoint[dir], + amr, + ) @. aux_df = ib_df+ssdf*(aux_point[dir]-ib_point[dir]) - cvc_gas_correction!(aux_df,solid_neighbor) - aux_prim = get_bc(ib.bc;intersect_point=aux_point,ib);aux_prim[1] = 1. - M = discrete_maxwell(vs_data.midpoint,aux_prim,global_data) - _,Mu_R = @views cvc_Mu(M[:,1],vn,Θ,solid_neighbor) - ρw = cvc_density(aux_df,vn,Θ,solid_neighbor,Mu_R) + cvc_gas_correction!(aux_df, solid_neighbor) + aux_prim = get_bc(ib.bc; intersect_point = aux_point, ib); + aux_prim[1] = 1.0 + M = discrete_maxwell(vs_data.midpoint, aux_prim, global_data) + _, Mu_R = @views cvc_Mu(M[:, 1], vn, Θ, solid_neighbor) + ρw = cvc_density(aux_df, vn, Θ, solid_neighbor, Mu_R) aux_prim[1] = ρw M .*= aux_prim[1] - for i in 1:vs_data.vs_num - if Θ[i]==1. - for j in axes(aux_df,2) - aux_df[i,j] = M[i,j] + for i = 1:vs_data.vs_num + if Θ[i]==1.0 + for j in axes(aux_df, 2) + aux_df[i, j] = M[i, j] end end end - cvc_correction!(aux_df,M,solid_neighbor,amr) - @. solid_neighbor.vs_data.df = aux_df+ssdf*(solid_neighbor.midpoint[dir]-aux_point[dir]) - for i in axes(ssdf,1) - for j in axes(ssdf,2) - ssdf[i,j] = vs_data.sdf[i,j,dir] + cvc_correction!(aux_df, M, solid_neighbor, amr) + @. solid_neighbor.vs_data.df = aux_df+ssdf*(solid_neighbor.midpoint[dir]-aux_point[dir]) + for i in axes(ssdf, 1) + for j in axes(ssdf, 2) + ssdf[i, j] = vs_data.sdf[i, j, dir] end end - solid_neighbor.w = calc_w0(vs_data.midpoint,solid_neighbor.vs_data.df,vs_data.weight,global_data) - solid_neighbor.sw[:,dir] .= (solid_neighbor.w-ps_data.w)./(solid_neighbor.midpoint[dir]-ps_data.midpoint[dir]) + solid_neighbor.w = + calc_w0(vs_data.midpoint, solid_neighbor.vs_data.df, vs_data.weight, global_data) + solid_neighbor.sw[:, dir] .= + (solid_neighbor.w-ps_data.w) ./ (solid_neighbor.midpoint[dir]-ps_data.midpoint[dir]) end -function update_solid_neighbor!(ps_data::PS_Data{DIM,NDF},amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} - solid_neighbors = findall(x->isa(x[1],SolidNeighbor),ps_data.neighbor.data) +function update_solid_neighbor!( + ps_data::PS_Data{DIM,NDF}, + amr::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} + solid_neighbors = findall(x->isa(x[1], SolidNeighbor), ps_data.neighbor.data) for i in solid_neighbors - update_solid_neighbor!(amr.global_data.config.solver.flux,ps_data,ps_data.neighbor.data[i][1],amr) + update_solid_neighbor!( + amr.global_data.config.solver.flux, + ps_data, + ps_data.neighbor.data[i][1], + amr, + ) end end """ $(TYPEDSIGNATURES) Update [`VS_Data`](@ref) variables in [`SolidNeighbor`](@ref) with the immersed boundary method. """ -function update_solid_neighbor!(amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function update_solid_neighbor!(amr::KitAMR_Data{DIM,NDF}) where {DIM,NDF} for tree in amr.field.trees.data for ps_data in tree - (isa(ps_data,InsideSolidData)||ps_data.bound_enc<=0)&&continue - update_solid_neighbor!(ps_data,amr) + (isa(ps_data, InsideSolidData)||ps_data.bound_enc<=0)&&continue + update_solid_neighbor!(ps_data, amr) end end end -function update_solid!(amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function update_solid!(amr::KitAMR_Data{DIM,NDF}) where {DIM,NDF} initialize_solid_neighbor!(amr) -end \ No newline at end of file +end diff --git a/src/Boundary/Period.jl b/src/Boundary/Period.jl index 92a759f..cb0100c 100644 --- a/src/Boundary/Period.jl +++ b/src/Boundary/Period.jl @@ -1,19 +1,35 @@ -function periodic_ghost_cell(midpoint::Vector,ps_data::AbstractPsData{DIM,NDF}) where{DIM,NDF} +function periodic_ghost_cell( + midpoint::Vector, + ps_data::AbstractPsData{DIM,NDF}, +) where {DIM,NDF} # PS_Data{DIM,NDF}(ps_data.quadid,ps_data.bound_enc,ps_data.solid_cell_index, # ps_data.ds,midpoint,ps_data.qf,ps_data.w,ps_data.sw,ps_data.prim,ps_data.flux,ps_data.vs_data, # ps_data.neighbor # ) - PS_Data(ps_data;midpoint) + PS_Data(ps_data; midpoint) end -function periodic_ghost_cell(midpoint::Vector,ps_data::AbstractGhostPsData{DIM,NDF}) where{DIM,NDF} - Ghost_PS_Data{DIM,NDF}(ps_data.owner_rank,ps_data.quadid,ps_data.bound_enc, - ps_data.ds,midpoint,ps_data.w,ps_data.sw,ps_data.vs_data +function periodic_ghost_cell( + midpoint::Vector, + ps_data::AbstractGhostPsData{DIM,NDF}, +) where {DIM,NDF} + Ghost_PS_Data{DIM,NDF}( + ps_data.owner_rank, + ps_data.quadid, + ps_data.bound_enc, + ps_data.ds, + midpoint, + ps_data.w, + ps_data.sw, + ps_data.vs_data, ) end -function periodic_ghost_cell(midpoints::Vector{Vector{Float64}},ps_datas::Vector{T}) where{T<:AbstractPsData{DIM,NDF} where{DIM,NDF}} - datas = Vector{AbstractPsData{DIM,NDF}}(undef,length(midpoints)) +function periodic_ghost_cell( + midpoints::Vector{Vector{Float64}}, + ps_datas::Vector{T}, +) where {T<:AbstractPsData{DIM,NDF} where {DIM,NDF}} + datas = Vector{AbstractPsData{DIM,NDF}}(undef, length(midpoints)) for i in eachindex(midpoints) - datas[i] = periodic_ghost_cell(midpiont[i],ps_datas[i]) + datas[i] = periodic_ghost_cell(midpiont[i], ps_datas[i]) end return datas -end \ No newline at end of file +end diff --git a/src/Boundary/Triangles.jl b/src/Boundary/Triangles.jl index 5817622..bfb7b49 100644 --- a/src/Boundary/Triangles.jl +++ b/src/Boundary/Triangles.jl @@ -1,86 +1,94 @@ -function triangle_box_table(kdt::KDTree,mesh::Mesh) +function triangle_box_table(kdt::KDTree, mesh::Mesh) tree_data = kdt.tree_data n_nodes = tree_data.n_internal_nodes n_leaves = tree_data.n_leafs - table = Vector{HyperRectangle{SVector{3,Float64}}}(undef,n_nodes+n_leaves) + table = Vector{HyperRectangle{SVector{3,Float64}}}(undef, n_nodes+n_leaves) lv = leaves(kdt) - lower = Inf*ones(3);upper = -Inf*ones(3) + lower = Inf*ones(3); + upper = -Inf*ones(3) for node in lv id = node.index ids = leaf_point_indices(node) for j in eachindex(ids) vertices = mesh.position[mesh.faces[ids[j]]] - for k in 1:3 - lower.=min.(lower,vertices[k]) - upper.=max.(upper,vertices[k]) + for k = 1:3 + lower.=min.(lower, vertices[k]) + upper.=max.(upper, vertices[k]) end end - table[id] = HyperRectangle(SVector{3,Float64}(lower),SVector{3,Float64}(upper)) - lower.=Inf;upper.=-Inf + table[id] = HyperRectangle(SVector{3,Float64}(lower), SVector{3,Float64}(upper)) + lower.=Inf; + upper.=-Inf end for node in PostOrderDFS(treeroot(kdt)) isempty(children(node))&&continue # is a leaf? - left_child,right_child = children(node) - lid = left_child.index;rid = right_child.index - lower.=min.(table[lid].mins,table[rid].mins) - upper.=max.(table[lid].maxes,table[rid].maxes) - table[node.index] = HyperRectangle(SVector{3,Float64}(lower),SVector{3,Float64}(upper)) - lower .= Inf;upper .= -Inf + left_child, right_child = children(node) + lid = left_child.index; + rid = right_child.index + lower.=min.(table[lid].mins, table[rid].mins) + upper.=max.(table[lid].maxes, table[rid].maxes) + table[node.index] = + HyperRectangle(SVector{3,Float64}(lower), SVector{3,Float64}(upper)) + lower .= Inf; + upper .= -Inf end return table end function triangle_recs(mesh::Mesh) - recs = Vector{HyperRectangle{SVector{3,Float64}}}(undef,length(mesh.faces)) - lower = Inf*ones(3);upper = -Inf*ones(3) + recs = Vector{HyperRectangle{SVector{3,Float64}}}(undef, length(mesh.faces)) + lower = Inf*ones(3); + upper = -Inf*ones(3) for i in eachindex(recs) vertices = mesh.position[mesh.faces[i]] - for j in 1:3 - lower .= min.(lower,vertices[j]) - upper .= max.(upper,vertices[j]) + for j = 1:3 + lower .= min.(lower, vertices[j]) + upper .= max.(upper, vertices[j]) end - recs[i] = HyperRectangle(SVector{3,Float64}(lower),SVector{3,Float64}(upper)) - lower .= Inf; upper .= -Inf + recs[i] = HyperRectangle(SVector{3,Float64}(lower), SVector{3,Float64}(upper)) + lower .= Inf; + upper .= -Inf end return recs end function triangle_edges(mesh::Mesh) - edges = Vector{Vector{SVector{3,Float64}}}(undef,length(mesh.faces)) + edges = Vector{Vector{SVector{3,Float64}}}(undef, length(mesh.faces)) for i in eachindex(mesh.faces) vertices = mesh.position[mesh.faces[i]] - edges[i] = Vector{SVector{3,Float64}}(undef,3) - for j in 1:3 + edges[i] = Vector{SVector{3,Float64}}(undef, 3) + for j = 1:3 edges[i][j] = SVector{3,Float64}(vertices[j%3+1]-vertices[j]) end end return edges end -function overlap_test(lower,upper,hyper_rec::HyperRectangle) +function overlap_test(lower, upper, hyper_rec::HyperRectangle) for i = 1:3 - (upper[i]hyper_rec.maxes[i])&& return false + (upper[i]hyper_rec.maxes[i]) && return false end return true end -function SAT_test_1(h,C,edge,V0) - n = cross(edge[1],edge[2]) - l = dot(h,abs.(n)) - s = abs(dot(n,V0-C)) +function SAT_test_1(h, C, edge, V0) + n = cross(edge[1], edge[2]) + l = dot(h, abs.(n)) + s = abs(dot(n, V0-C)) s>l && return false return true end -function SAT_test_2(a,edge,h,V) # note that V are vertices relative to the midpoint of the cell - dij = zeros(3);p = zeros(3) - for j in 1:3 - for i in 1:3 - dij .= cross(a[i],edge[j]) - for k in 1:3 - p[k] = dot(dij,V[k]) +function SAT_test_2(a, edge, h, V) # note that V are vertices relative to the midpoint of the cell + dij = zeros(3); + p = zeros(3) + for j = 1:3 + for i = 1:3 + dij .= cross(a[i], edge[j]) + for k = 1:3 + p[k] = dot(dij, V[k]) end - for k in 1:3 + for k = 1:3 dij[k] = abs(dij[k]) end - r = dot(dij,h) + r = dot(dij, h) if minimum(p) > r||maximum(p) < -r # TBD: replace with min/max return false end @@ -91,37 +99,42 @@ end -function any_intersect_test(midpoint,ds,tkdt::TriangleKDT) - lower = midpoint-0.5*ds;upper = midpoint+0.5*ds - any_recursion_test(treeroot(tkdt.kdt),midpoint,ds,lower,upper,tkdt) +function any_intersect_test(midpoint, ds, tkdt::TriangleKDT) + lower = midpoint-0.5*ds; + upper = midpoint+0.5*ds + any_recursion_test(treeroot(tkdt.kdt), midpoint, ds, lower, upper, tkdt) end -function any_recursion_test(node::TreeNode,midpoint,ds,lower,upper,tkdt) - table = tkdt.table;mesh = tkdt.mesh - recs = tkdt.triangle_recs;edges = tkdt.triangle_edges +function any_recursion_test(node::TreeNode, midpoint, ds, lower, upper, tkdt) + table = tkdt.table; + mesh = tkdt.mesh + recs = tkdt.triangle_recs; + edges = tkdt.triangle_edges id = node.index - if overlap_test(lower,upper,table[id]) # kernel intersect test + if overlap_test(lower, upper, table[id]) # kernel intersect test if isempty(children(node)) ids = leaf_point_indices(node) for i in ids - if overlap_test(lower,upper,recs[i]) - h = 0.5*ds;V = mesh.position[mesh.faces[i]] - if SAT_test_1(h,midpoint,edges[i],V[1]) + if overlap_test(lower, upper, recs[i]) + h = 0.5*ds; + V = mesh.position[mesh.faces[i]] + if SAT_test_1(h, midpoint, edges[i], V[1]) a = [ - SVector{3,Float64}([1,0,0]), - SVector{3,Float64}([0,1,0]), - SVector{3,Float64}([0,0,1]) + SVector{3,Float64}([1, 0, 0]), + SVector{3,Float64}([0, 1, 0]), + SVector{3,Float64}([0, 0, 1]), ] v = [x-midpoint for x in V] - if SAT_test_2(a,edges[i],h,v) + if SAT_test_2(a, edges[i], h, v) return true end end end end else - lc,rc = children(node) - any_intersect_recursion_test(lc,midpoint,ds,lower,upper,tkdt) && return true - return any_intersect_recursion_test(rc,midpoint,ds,lower,upper,tkdt) + lc, rc = children(node) + any_intersect_recursion_test(lc, midpoint, ds, lower, upper, tkdt) && + return true + return any_intersect_recursion_test(rc, midpoint, ds, lower, upper, tkdt) end else return false @@ -129,39 +142,75 @@ function any_recursion_test(node::TreeNode,midpoint,ds,lower,upper,tkdt) end -function all_intersect_test(midpoint,ds,tkdt::TriangleKDT) - lower = midpoint-0.5*ds;upper = midpoint+0.5*ds +function all_intersect_test(midpoint, ds, tkdt::TriangleKDT) + lower = midpoint-0.5*ds; + upper = midpoint+0.5*ds intersect_ids = Int[] - all_intersect_recursion_test!(treeroot(tkdt.kdt),midpoint,ds,lower,upper,tkdt,intersect_ids) + all_intersect_recursion_test!( + treeroot(tkdt.kdt), + midpoint, + ds, + lower, + upper, + tkdt, + intersect_ids, + ) return intersect_ids end -function all_intersect_recursion_test!(node::TreeNode,midpoint,ds,lower,upper,tkdt,intersect_ids::Vector{Int}) - table = tkdt.table;mesh = tkdt.mesh - recs = tkdt.triangle_recs;edges = tkdt.triangle_edges +function all_intersect_recursion_test!( + node::TreeNode, + midpoint, + ds, + lower, + upper, + tkdt, + intersect_ids::Vector{Int}, +) + table = tkdt.table; + mesh = tkdt.mesh + recs = tkdt.triangle_recs; + edges = tkdt.triangle_edges id = node.index - if overlap_test(lower,upper,table[id]) # kernel intersect test + if overlap_test(lower, upper, table[id]) # kernel intersect test if isempty(children(node)) ids = leaf_point_indices(node) for i in ids - if overlap_test(lower,upper,recs[i]) - h = 0.5*ds;V = mesh.position[mesh.faces[i]] - if SAT_test_1(h,midpoint,edges[i],V[1]) + if overlap_test(lower, upper, recs[i]) + h = 0.5*ds; + V = mesh.position[mesh.faces[i]] + if SAT_test_1(h, midpoint, edges[i], V[1]) a = [ - SVector{3,Float64}([1,0,0]), - SVector{3,Float64}([0,1,0]), - SVector{3,Float64}([0,0,1]) + SVector{3,Float64}([1, 0, 0]), + SVector{3,Float64}([0, 1, 0]), + SVector{3,Float64}([0, 0, 1]), ] v = [x-midpoint for x in V] - if SAT_test_2(a,edges[i],h,v) - push!(intersect_ids,i) + if SAT_test_2(a, edges[i], h, v) + push!(intersect_ids, i) end end end end else - lc,rc = children(node) - all_intersect_recursion_test!(lc,midpoint,ds,lower,upper,tkdt,intersect_ids) - all_intersect_recursion_test!(rc,midpoint,ds,lower,upper,tkdt,intersect_ids) + lc, rc = children(node) + all_intersect_recursion_test!( + lc, + midpoint, + ds, + lower, + upper, + tkdt, + intersect_ids, + ) + all_intersect_recursion_test!( + rc, + midpoint, + ds, + lower, + upper, + tkdt, + intersect_ids, + ) end end return nothing @@ -170,7 +219,7 @@ end function line_plane_intersection(midpoint::Vector{Float64}, V, edges, dir) - A,B,C = cross(edges[1],edges[2]) + A, B, C = cross(edges[1], edges[2]) D = -(A*V[1][1]+B*V[1][2]+C*V[1][3]) if dir == 1 y0 = midpoint[2] @@ -198,43 +247,51 @@ function line_plane_intersection(midpoint::Vector{Float64}, V, edges, dir) return [x0, y0, t] end end -function in_triangle_test(point::Vector{Float64},V,edges) - n = cross(edges[1],edges[2]) +function in_triangle_test(point::Vector{Float64}, V, edges) + n = cross(edges[1], edges[2]) p = [point-v for v in V] for i in eachindex(p) - dot(cross(edges[i],p[i]),n)<-eps()&&return false + dot(cross(edges[i], p[i]), n)<-eps()&&return false end return true end -function calc_intersect(f_midpoint,s_midpoint,ds,dir,ib::Triangles) - tkdt = ib.tkdt;mesh = tkdt.mesh - intersect_ids = all_intersect_test(f_midpoint,2.0*ds,tkdt) +function calc_intersect(f_midpoint, s_midpoint, ds, dir, ib::Triangles) + tkdt = ib.tkdt; + mesh = tkdt.mesh + intersect_ids = all_intersect_test(f_midpoint, 2.0*ds, tkdt) for id in intersect_ids V = mesh.position[mesh.faces[id]] edges = ib.tkdt.triangle_edges[id] - intersect_point = line_plane_intersection(f_midpoint,V,edges,dir) + intersect_point = line_plane_intersection(f_midpoint, V, edges, dir) isempty(intersect_point) && continue - (intersect_point[dir]-s_midpoint[dir])*(intersect_point[dir]-f_midpoint[dir])>0 && continue + (intersect_point[dir]-s_midpoint[dir])*(intersect_point[dir]-f_midpoint[dir])>0 && + continue abs((intersect_point[dir]-f_midpoint[dir])/ds[dir])>1.0+eps() && continue - if in_triangle_test(intersect_point,V,edges) - normal = collect(cross(edges[1],edges[2])) - normal = dot(normal,f_midpoint-s_midpoint)>0 ? normal/norm(normal) : -normal/norm(normal) - return intersect_point,normal + if in_triangle_test(intersect_point, V, edges) + normal = collect(cross(edges[1], edges[2])) + normal = + dot(normal, f_midpoint-s_midpoint)>0 ? normal/norm(normal) : + -normal/norm(normal) + return intersect_point, normal end end - return Float64[],Float64[] + return Float64[], Float64[] end """ $(TYPEDSIGNATURES) Whether a quadrant is overlap with the hyper_rec of the immersed boundary. """ -function pre_partition_box_flag(midpoint,ds,ib::Triangles) +function pre_partition_box_flag(midpoint, ds, ib::Triangles) r = ib.search_radius kdt = ib.tkdt.kdt triangle_rec = ib.tkdt.table[treeroot(kdt).index] - hyper_rec = HyperRectangle(SVector{3,Float64}(triangle_rec.mins.-r),SVector{3,Float64}(triangle_rec.maxes.+r)) - lower = midpoint-0.5*ds;upper = midpoint+0.5*ds - if overlap_test(lower,upper,hyper_rec) + hyper_rec = HyperRectangle( + SVector{3,Float64}(triangle_rec.mins .- r), + SVector{3,Float64}(triangle_rec.maxes .+ r), + ) + lower = midpoint-0.5*ds; + upper = midpoint+0.5*ds + if overlap_test(lower, upper, hyper_rec) return true else return false @@ -244,15 +301,19 @@ end $(TYPEDSIGNATURES) Whether a quadrant is inside the refine radius of the immersed boundary. """ -function search_radius_refine_flag!(i::Int,ib::Triangles,midpoint,ds,mesh_data) +function search_radius_refine_flag!(i::Int, ib::Triangles, midpoint, ds, mesh_data) r = ib.search_radius kdt = ib.tkdt.kdt triangle_rec = ib.tkdt.table[treeroot(kdt).index] - hyper_rec = HyperRectangle(SVector{3,Float64}(triangle_rec.mins.-r),SVector{3,Float64}(triangle_rec.maxes.+r)) - lower = midpoint-0.5*ds;upper = midpoint+0.5*ds - if overlap_test(lower,upper,hyper_rec) + hyper_rec = HyperRectangle( + SVector{3,Float64}(triangle_rec.mins .- r), + SVector{3,Float64}(triangle_rec.maxes .+ r), + ) + lower = midpoint-0.5*ds; + upper = midpoint+0.5*ds + if overlap_test(lower, upper, hyper_rec) mesh_data.in_box = i - _,distance = nn(kdt,midpoint) + _, distance = nn(kdt, midpoint) if distance1.0+eps() && continue - in_triangle_test(intersect_point,V,edges) && return true + in_triangle_test(intersect_point, V, edges) && return true end end return false end function cell_type_decision!(p4est::Ptr{p8est_t}) - AMR_volume_iterate(p4est) do ip,data,dp - global_data,_ = unsafe_pointer_to_objref(pointer(ip.p4est.user_pointer)) + AMR_volume_iterate(p4est) do ip, data, dp + global_data, _ = unsafe_pointer_to_objref(pointer(ip.p4est.user_pointer)) mesh_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - ds,midpoint = quad_to_cell(ip.p4est,ip.treeid[],ip.quad) + ds, midpoint = quad_to_cell(ip.p4est, ip.treeid[], ip.quad) if mesh_data.in_box!=0 ib = global_data.config.IB[mesh_data.in_box] - mesh_data.in_solid = solid_flag(ib,midpoint) + mesh_data.in_solid = solid_flag(ib, midpoint) if mesh_data.in_search_radius!=0&&mesh_data.in_solid - mesh_data.is_ghost_cell = ghost_cell_flag(ib,midpoint,ds) + mesh_data.is_ghost_cell = ghost_cell_flag(ib, midpoint, ds) end else ibs = global_data.config.IB @@ -315,70 +376,89 @@ function ray_casting(ib::Triangles, midpoint) # Inside the closed surface? center = 0.5*(kdt.hyper_rec.mins[dir]+kdt.hyper_rec.maxes[dir]) is_pos = center=-eps()&&u>=-eps()&&v>=eps()&&(1.0-u-v>=-eps()) return true else return false end end -function Moller_Trumbore_line_test(midpoint,e,V) - e1 = V[2]-V[1];e2 = V[3]-V[1] - h = cross(e,e2) - a = dot(h,e1) +function Moller_Trumbore_line_test(midpoint, e, V) + e1 = V[2]-V[1]; + e2 = V[3]-V[1] + h = cross(e, e2) + a = dot(h, e1) if abs(a)=-eps()&&v>=eps()&&(1.0-u-v>=-eps()) return true @@ -386,9 +466,12 @@ function Moller_Trumbore_line_test(midpoint,e,V) return false end end -function ray_casting_rectangle_test(hyper_rec::HyperRectangle,midpoint,dir,is_pos) - dir2 = dir%3+1;dir3 = (dir+1)%3+1 - if (hyper_rec.mins[dir2]<=midpoint[dir2]<=hyper_rec.maxes[dir2])&&(hyper_rec.mins[dir3]<=midpoint[dir3]<=hyper_rec.maxes[dir3]) +function ray_casting_rectangle_test(hyper_rec::HyperRectangle, midpoint, dir, is_pos) + dir2 = dir%3+1; + dir3 = (dir+1)%3+1 + if ( + hyper_rec.mins[dir2]<=midpoint[dir2]<=hyper_rec.maxes[dir2] + )&&(hyper_rec.mins[dir3]<=midpoint[dir3]<=hyper_rec.maxes[dir3]) if is_pos flag = hyper_rec.maxes[dir]>=midpoint[dir] else @@ -400,6 +483,14 @@ function ray_casting_rectangle_test(hyper_rec::HyperRectangle,midpoint,dir,is_po end end -function calc_IB_ρw(aux_point::AbstractVector,bound::Triangles,midpoint::AbstractMatrix,weight::AbstractVector,df::AbstractMatrix,vn::AbstractVector,Θ::AbstractVector) - calc_IB_ρw_3D(aux_point,bound.bc,midpoint,weight,df,vn,Θ) -end \ No newline at end of file +function calc_IB_ρw( + aux_point::AbstractVector, + bound::Triangles, + midpoint::AbstractMatrix, + weight::AbstractVector, + df::AbstractMatrix, + vn::AbstractVector, + Θ::AbstractVector, +) + calc_IB_ρw_3D(aux_point, bound.bc, midpoint, weight, df, vn, Θ) +end diff --git a/src/Boundary/Types.jl b/src/Boundary/Types.jl index b4e56c5..72fef7d 100644 --- a/src/Boundary/Types.jl +++ b/src/Boundary/Types.jl @@ -7,7 +7,6 @@ Structure of domain boundary. ## Fields $(TYPEDFIELDS) - """ struct Domain{T<:AbstractBoundCondType} <: AbstractBoundaryType "Index of the domain boundary. From 1 to 6, it represents the boundary of `xmin`, `xmax`, `ymin`, `ymax`, `zmin`, `zmax`." @@ -16,8 +15,8 @@ struct Domain{T<:AbstractBoundCondType} <: AbstractBoundaryType refine::Bool "The boundary condition at the domain boundary." bc::AbstractBCType - Domain(T,id;refine=false) = new{T}(id,refine) - Domain(T,id,bc;refine=false) = new{T}(id,refine,bc) + Domain(T, id; refine = false) = new{T}(id, refine) + Domain(T, id, bc; refine = false) = new{T}(id, refine, bc) end """ @@ -50,14 +49,16 @@ struct Circle{T<:AbstractBoundCondType} <: AbstractBoundaryType bc::AbstractBCType "Maximum distance of the refinement region from the boundary." search_radius::Real - Circle(::Type{T},center::Vector,radius,solid,search_coeffi,bc) where{T<:AbstractBoundCondType} = new{T}(center,radius,solid,search_coeffi,bc) - Circle(c::Circle{T},ds::Float64) where{T<:AbstractBoundCondType} = new{T}(c.center, - c.radius, - c.solid, - c.search_coeffi, - c.bc, - c.search_coeffi*ds - ) + Circle( + ::Type{T}, + center::Vector, + radius, + solid, + search_coeffi, + bc, + ) where {T<:AbstractBoundCondType} = new{T}(center, radius, solid, search_coeffi, bc) + Circle(c::Circle{T}, ds::Float64) where {T<:AbstractBoundCondType} = + new{T}(c.center, c.radius, c.solid, c.search_coeffi, c.bc, c.search_coeffi*ds) end """ $(TYPEDEF) @@ -70,14 +71,16 @@ struct Sphere{T<:AbstractBoundCondType} <: AbstractBoundaryType # 3D circle search_coeffi::Real bc::AbstractBCType search_radius::Real - Sphere(::Type{T},center::Vector,radius,solid,search_coeffi,bc) where{T<:AbstractBoundCondType} = new{T}(center,radius,solid,search_coeffi,bc) - Sphere(c::Sphere{T},ds::Float64) where{T<:AbstractBoundCondType} = new{T}(c.center, - c.radius, - c.solid, - c.search_coeffi, - c.bc, - c.search_coeffi*ds - ) + Sphere( + ::Type{T}, + center::Vector, + radius, + solid, + search_coeffi, + bc, + ) where {T<:AbstractBoundCondType} = new{T}(center, radius, solid, search_coeffi, bc) + Sphere(c::Sphere{T}, ds::Float64) where {T<:AbstractBoundCondType} = + new{T}(c.center, c.radius, c.solid, c.search_coeffi, c.bc, c.search_coeffi*ds) end const AbstractCircle = Union{Circle,Sphere} @@ -97,22 +100,42 @@ struct Vertices{DIM,T<:AbstractBoundCondType} <: AbstractBoundaryType end """ $(TYPEDSIGNATURES) -- `file` is the path to the `.csv` file. + + - `file` is the path to the `.csv` file. """ -function Vertices(::Type{T},file::String,solid,refine_coeffi,bc) where{T<:AbstractBoundCondType} - s = CSV.read(file,DataFrame;header=true) +function Vertices( + ::Type{T}, + file::String, + solid, + refine_coeffi, + bc, +) where {T<:AbstractBoundCondType} + s = CSV.read(file, DataFrame; header = true) DIM = length(names(s)) - vertices = [[s.x[i],s.y[i]] for i in eachindex(s.x)] + vertices = [[s.x[i], s.y[i]] for i in eachindex(s.x)] if vertices[1]==vertices[end] - vertices = vertices[1:end-1] + vertices = vertices[1:(end-1)] end - box = [[minimum(s.x),minimum(s.y)],[maximum(s.x),maximum(s.y)]] - return Vertices{DIM,T}(vertices,solid,bc,box,refine_coeffi) + box = [[minimum(s.x), minimum(s.y)], [maximum(s.x), maximum(s.y)]] + return Vertices{DIM,T}(vertices, solid, bc, box, refine_coeffi) end -function Vertices(v::Vertices{DIM,T},config) where{DIM,T<:AbstractBoundCondType} - ds_max = maximum([(config[:geometry][2i]-config[:geometry][2i-1])/config[:trees_num][i] for i in 1:config[:DIM]]) - ds = norm([(config[:geometry][2i]-config[:geometry][2i-1])/config[:trees_num][i]/2^config[:AMR_PS_MAXLEVEL] for i in 1:config[:DIM]]) - return Vertices{DIM,T}(v.vertices,v.solid,v.bc,[v.box[1].-ds_max,v.box[2].+ds_max],v.search_radius*ds) +function Vertices(v::Vertices{DIM,T}, config) where {DIM,T<:AbstractBoundCondType} + ds_max = maximum([ + (config[:geometry][2i]-config[:geometry][2i-1])/config[:trees_num][i] for + i = 1:config[:DIM] + ]) + ds = norm([ + ( + config[:geometry][2i]-config[:geometry][2i-1] + )/config[:trees_num][i]/2^config[:AMR_PS_MAXLEVEL] for i = 1:config[:DIM] + ]) + return Vertices{DIM,T}( + v.vertices, + v.solid, + v.bc, + [v.box[1] .- ds_max, v.box[2] .+ ds_max], + v.search_radius*ds, + ) end """ @@ -127,17 +150,23 @@ struct TriangleKDT triangle_edges::Vector{Vector{SVector{3,Float64}}} # Accessed by id of mesh.faces end function TriangleKDT(mesh::Mesh) - centers = zeros(3,length(mesh.faces)) + centers = zeros(3, length(mesh.faces)) for i in eachindex(mesh.faces) vertices = mesh.position[mesh.faces[i]] - for j in 1:3 - for k in 1:3 - centers[j,i] += vertices[k][j]/3.0 + for j = 1:3 + for k = 1:3 + centers[j, i] += vertices[k][j]/3.0 end end end - kdt = KDTree(centers;leafsize = 24) - return TriangleKDT(kdt,mesh,triangle_box_table(kdt,mesh),triangle_recs(mesh),triangle_edges(mesh)) + kdt = KDTree(centers; leafsize = 24) + return TriangleKDT( + kdt, + mesh, + triangle_box_table(kdt, mesh), + triangle_recs(mesh), + triangle_edges(mesh), + ) end """ @@ -152,19 +181,37 @@ struct Triangles{T<:AbstractBoundCondType} <: AbstractBoundaryType end """ $(TYPEDSIGNATURES) -- `file` is the path to the `.stl` file. + + - `file` is the path to the `.stl` file. """ -function Triangles(::Type{T},file::String,solid,search_radius,bc) where{T<:AbstractBoundCondType} +function Triangles( + ::Type{T}, + file::String, + solid, + search_radius, + bc, +) where {T<:AbstractBoundCondType} mesh = load(file) tkdt = TriangleKDT(mesh) - return Triangles{T}(solid,bc,search_radius,tkdt) + return Triangles{T}(solid, bc, search_radius, tkdt) end -function Triangles(::Type{T},solid::Bool,search_radius,bc,tkdt::TriangleKDT,config) where{T<:AbstractBoundCondType} - ds = norm([(config[:geometry][2i]-config[:geometry][2i-1])/config[:trees_num][i]/2^config[:AMR_PS_MAXLEVEL] for i in 1:config[:DIM]]) - return Triangles{T}(solid,bc,search_radius*ds,tkdt) +function Triangles( + ::Type{T}, + solid::Bool, + search_radius, + bc, + tkdt::TriangleKDT, + config, +) where {T<:AbstractBoundCondType} + ds = norm([ + ( + config[:geometry][2i]-config[:geometry][2i-1] + )/config[:trees_num][i]/2^config[:AMR_PS_MAXLEVEL] for i = 1:config[:DIM] + ]) + return Triangles{T}(solid, bc, search_radius*ds, tkdt) end -function Triangles(ib::Triangles{T},config) where{T} - return Triangles(T,ib.solid,ib.search_radius,ib.bc,ib.tkdt,config) +function Triangles(ib::Triangles{T}, config) where {T} + return Triangles(T, ib.solid, ib.search_radius, ib.bc, ib.tkdt, config) end @@ -176,9 +223,9 @@ mutable struct SolidCells{DIM,NDF} quadids provide the information of solidcells on other processors. Only after this, the exchange of IB nodes can be executeable. =# end -function SolidCells(ps_datas::Vector{PS_Data{DIM,NDF}}) where{DIM,NDF} +function SolidCells(ps_datas::Vector{PS_Data{DIM,NDF}}) where {DIM,NDF} quadids = [x.quadid for x in ps_datas] - return SolidCells{DIM,NDF}(ps_datas,quadids) + return SolidCells{DIM,NDF}(ps_datas, quadids) end mutable struct GhostIBVSData{DIM,NDF} <: AbstractVsData{DIM,NDF} vs_num::Int @@ -198,8 +245,8 @@ mutable struct IBCells{DIM,NDF} IB_nodes::Vector{Vector{AbstractIBNodes{DIM,NDF}}} # SolidCells{IBNodes{}} templates::Vector{Vector{Vector{Int}}} # Available templates indices end -function IBCells(IB_nodes::Vector{Vector{AbstractIBNodes{DIM,NDF}}}) where{DIM,NDF} - return IBCells{DIM,NDF}(IB_nodes,Vector{Vector{Vector{Int}}}(undef,length(IB_nodes))) +function IBCells(IB_nodes::Vector{Vector{AbstractIBNodes{DIM,NDF}}}) where {DIM,NDF} + return IBCells{DIM,NDF}(IB_nodes, Vector{Vector{Vector{Int}}}(undef, length(IB_nodes))) end mutable struct IBTransferData solid_cell_indices::Matrix{Int} @@ -223,13 +270,14 @@ mutable struct Corner_Target_Neighbor_Transport ghost_datas::Vector{Vector{Float64}} ghost_ps_datas::Vector{Ghost_PS_Data} ranks_ghost_ids::Vector{Vector{Int}} # rank{ghost_datas' id} - Corner_Target_Neighbor_Transport() = (n = new(); + Corner_Target_Neighbor_Transport() = ( + n = new(); n.mirror_ps_datas = SolidNeighbor[]; - n.ranks_mirror_ids = [Int[] for _ in 1:MPI.Comm_size(MPI.COMM_WORLD)]; + n.ranks_mirror_ids = [Int[] for _ = 1:MPI.Comm_size(MPI.COMM_WORLD)]; n.ghost_ps_datas = Ghost_PS_Data[]; - n.ranks_ghost_ids = [Int[] for _ in 1:MPI.Comm_size(MPI.COMM_WORLD)]; - n.mirror_datas = Vector{Vector{Float64}}(undef,MPI.Comm_size(MPI.COMM_WORLD)); - n.ghost_datas = Vector{Vector{Float64}}(undef,MPI.Comm_size(MPI.COMM_WORLD)); + n.ranks_ghost_ids = [Int[] for _ = 1:MPI.Comm_size(MPI.COMM_WORLD)]; + n.mirror_datas = Vector{Vector{Float64}}(undef, MPI.Comm_size(MPI.COMM_WORLD)); + n.ghost_datas = Vector{Vector{Float64}}(undef, MPI.Comm_size(MPI.COMM_WORLD)); n ) end diff --git a/src/Boundary/Vertices.jl b/src/Boundary/Vertices.jl index d3655ee..81eb1a3 100644 --- a/src/Boundary/Vertices.jl +++ b/src/Boundary/Vertices.jl @@ -1,61 +1,96 @@ -function pre_ps_refine_flag(boundary::Vertices,midpoint::AbstractVector,ds::AbstractVector,global_data::Global_Data) # Circle type IB boundary flag - boundary.box[1][1]midpoint[1]&&boundary.box[1][2]midpoint[2] && return true +function pre_ps_refine_flag( + boundary::Vertices, + midpoint::AbstractVector, + ds::AbstractVector, + global_data::Global_Data, +) # Circle type IB boundary flag + boundary.box[1][1]midpoint[1]&&boundary.box[1][2]midpoint[2] && + return true return false end -function boundary_flag(boundary::Vertices,midpoint::AbstractVector,ds::AbstractVector,::Global_Data) # Circle type IB boundary flag +function boundary_flag( + boundary::Vertices, + midpoint::AbstractVector, + ds::AbstractVector, + ::Global_Data, +) # Circle type IB boundary flag # (boundary.box[1][1]>midpoint[1]||boundary.box[2][1]midpoint[2]||boundary.box[2][2]midpoint[1]&&boundary.box[1][2]midpoint[2]) - return xor(!(inbox&&ray_casting(midpoint,boundary.vertices)),boundary.solid) +function solid_flag(boundary::Vertices, midpoint::AbstractVector) # Does midpoint locate at solid? + inbox = ( + boundary.box[1][1]midpoint[1]&&boundary.box[1][2]midpoint[2] + ) + return xor(!(inbox&&ray_casting(midpoint, boundary.vertices)), boundary.solid) end -function IB_prim(circle::Vertices,aux_point::AbstractVector,ρw::Real) - IB_prim(circle.bc,aux_point,ρw) +function IB_prim(circle::Vertices, aux_point::AbstractVector, ρw::Real) + IB_prim(circle.bc, aux_point, ρw) end -function calc_IB_ρw(aux_point::AbstractVector,bound::Vertices{2},midpoint::AbstractMatrix,weight::AbstractVector,df::AbstractMatrix,vn::AbstractVector,Θ::AbstractVector) - calc_IB_ρw_2D(aux_point,bound.bc,midpoint,weight,df,vn,Θ) +function calc_IB_ρw( + aux_point::AbstractVector, + bound::Vertices{2}, + midpoint::AbstractMatrix, + weight::AbstractVector, + df::AbstractMatrix, + vn::AbstractVector, + Θ::AbstractVector, +) + calc_IB_ρw_2D(aux_point, bound.bc, midpoint, weight, df, vn, Θ) end -function calc_IB_ρw(aux_point::AbstractVector,bound::Vertices{3},midpoint::AbstractMatrix,weight::AbstractVector,df::AbstractMatrix,vn::AbstractVector,Θ::AbstractVector) - calc_IB_ρw_3D(aux_point,bound.bc,midpoint,weight,df,vn,Θ) +function calc_IB_ρw( + aux_point::AbstractVector, + bound::Vertices{3}, + midpoint::AbstractMatrix, + weight::AbstractVector, + df::AbstractMatrix, + vn::AbstractVector, + Θ::AbstractVector, +) + calc_IB_ρw_3D(aux_point, bound.bc, midpoint, weight, df, vn, Θ) end -function calc_intersect(f_midpoint,s_midpoint,::Vector,::Int,boundary::Vertices{2}) - find_intersections_2D(s_midpoint,f_midpoint,boundary.vertices) +function calc_intersect(f_midpoint, s_midpoint, ::Vector, ::Int, boundary::Vertices{2}) + find_intersections_2D(s_midpoint, f_midpoint, boundary.vertices) end -function ray_casting(point::Vector{Float64},vertices::Vector{Vector{Float64}}) # Inside the closed curve? +function ray_casting(point::Vector{Float64}, vertices::Vector{Vector{Float64}}) # Inside the closed curve? n = length(vertices) count = 0 - for i in 1:n + for i = 1:n j = (i % n) + 1 x_i, y_i = vertices[i] x_j, y_j = vertices[j] px, py = point if (py > min(y_i, y_j)) && (py <= max(y_i, y_j)) - if y_i == y_j + if y_i == y_j continue end x_intersect = (py-y_i) * (x_j - x_i) / (y_j - y_i) + x_i if x_intersect > px && (x_intersect <= max(x_i, x_j)) - count +=1 + count += 1 end end end return (count % 2) == 1 end -function calc_normal(p1,p2,s1,s2) # Calculate the unit normal vector of the vector (s2-s1), in the direction of (p2-p1). - n = [s2[2]-s1[2],s1[1]-s2[1]] +function calc_normal(p1, p2, s1, s2) # Calculate the unit normal vector of the vector (s2-s1), in the direction of (p2-p1). + n = [s2[2]-s1[2], s1[1]-s2[1]] n /= norm(n) - if dot(n,p2-p1)<0 + if dot(n, p2-p1)<0 n = -n end return n @@ -64,9 +99,9 @@ function find_horizontal_intersection(s_midpoint, f_midpoint, points) n = length(points) x_seg_min, x_seg_max = minmax(s_midpoint[1], f_midpoint[1]) y0 = s_midpoint[2] - for i in 1:n + for i = 1:n p1 = points[i] - p2 = points[i%n + 1] + p2 = points[i%n+1] x1, y1 = p1 x2, y2 = p2 if (y1 ≤ y0 ≤ y2) || (y2 ≤ y0 ≤ y1) @@ -74,7 +109,7 @@ function find_horizontal_intersection(s_midpoint, f_midpoint, points) if 0 < t < 1 x_intersect = x1 + t * (x2 - x1) if x_seg_min ≤ x_intersect ≤ x_seg_max - return [x_intersect, y0],calc_normal(s_midpoint, f_midpoint, p1, p2) + return [x_intersect, y0], calc_normal(s_midpoint, f_midpoint, p1, p2) end elseif t==1 x_intersect = x1 + t * (x2 - x1) @@ -82,23 +117,24 @@ function find_horizontal_intersection(s_midpoint, f_midpoint, points) p3 = points[i%n+2] n1 = calc_normal(s_midpoint, f_midpoint, p1, p2) n2 = calc_normal(s_midpoint, f_midpoint, p2, p3) - n0 = n1+n2;n0/=norm(n0) - return [x_intersect, y0],n0 + n0 = n1+n2; + n0/=norm(n0) + return [x_intersect, y0], n0 end end end end @show s_midpoint f_midpoint throw("Intersect error!") - return Float64[],Float64[] + return Float64[], Float64[] end function find_vertical_intersection(s_midpoint, f_midpoint, points) n = length(points) y_seg_min, y_seg_max = minmax(s_midpoint[2], f_midpoint[2]) x0 = s_midpoint[1] - for i in 1:n + for i = 1:n p1 = points[i] - p2 = points[i%n + 1] + p2 = points[i%n+1] x1, y1 = p1 x2, y2 = p2 if (x1 ≤ x0 ≤ x2) || (x2 ≤ x0 ≤ x1) @@ -106,7 +142,7 @@ function find_vertical_intersection(s_midpoint, f_midpoint, points) if 0 < t < 1 y_intersect = y1 + t * (y2 - y1) if y_seg_min ≤ y_intersect ≤ y_seg_max - return [x0, y_intersect],calc_normal(s_midpoint, f_midpoint, p1, p2) + return [x0, y_intersect], calc_normal(s_midpoint, f_midpoint, p1, p2) end elseif t==1 y_intersect = y1 + t * (y2 - y1) @@ -114,15 +150,16 @@ function find_vertical_intersection(s_midpoint, f_midpoint, points) p3 = points[i%n+2] n1 = calc_normal(s_midpoint, f_midpoint, p1, p2) n2 = calc_normal(s_midpoint, f_midpoint, p2, p3) - n0 = n1+n2;n0/=norm(n0) - return [x0, y_intersect],n0 + n0 = n1+n2; + n0/=norm(n0) + return [x0, y_intersect], n0 end end end end @show s_midpoint f_midpoint throw("Intersect error!") - return Float64[],Float64[] + return Float64[], Float64[] end function find_intersections_2D(s_midpoint, f_midpoint, closed_curve) x1, y1 = s_midpoint @@ -135,4 +172,4 @@ function find_intersections_2D(s_midpoint, f_midpoint, closed_curve) @show s_midpoint f_midpoint throw("Horizontal or vertical line segment is expected!") end -end \ No newline at end of file +end diff --git a/src/Flux/CAIDVM.jl b/src/Flux/CAIDVM.jl index 64c9c5b..500073d 100644 --- a/src/Flux/CAIDVM.jl +++ b/src/Flux/CAIDVM.jl @@ -1,132 +1,258 @@ """ $(TYPEDSIGNATURES) """ -function calc_domain_flux(::Type{CAIDVM},here_vs::Face_VS_Data,face::DomainFace{DIM,NDF,Maxwellian},amr::KitAMR_Data) where{DIM,NDF} - _,direction,midpoint,_,ps_data = unpack(face) - heavi,here_weight,here_mid,here_vn,here_df,here_sdf = unpack(here_vs) +function calc_domain_flux( + ::Type{CAIDVM}, + here_vs::Face_VS_Data, + face::DomainFace{DIM,NDF,Maxwellian}, + amr::KitAMR_Data, +) where {DIM,NDF} + _, direction, midpoint, _, ps_data = unpack(face) + heavi, here_weight, here_mid, here_vn, here_df, here_sdf = unpack(here_vs) Δt = amr.global_data.status.Δt vs_data = ps_data.vs_data nheavi = [!x for x in heavi] - there_mid = @views vs_data.midpoint[nheavi,:] + there_mid = @views vs_data.midpoint[nheavi, :] there_weight = @views vs_data.weight[nheavi] - there_vn = @views there_mid[:,direction] - @inbounds @views dx = [midpoint[j]-here_mid[i,j]*Δt-ps_data.midpoint[j] for i in axes(here_mid,1),j in axes(here_mid,2)] - @inbounds @views df = [here_df[i,j]+dot(dx[i,:],here_sdf[i,j,:]) for i in axes(here_df,1),j in axes(here_df,2)] + there_vn = @views there_mid[:, direction] + @inbounds @views dx = [ + midpoint[j]-here_mid[i, j]*Δt-ps_data.midpoint[j] for + i in axes(here_mid, 1), j in axes(here_mid, 2) + ] + @inbounds @views df = [ + here_df[i, j]+dot(dx[i, :], here_sdf[i, j, :]) for + i in axes(here_df, 1), j in axes(here_df, 2) + ] bc = get_bc(face.domain.bc) - bc[1] = calc_ρw(there_mid,df,bc,here_vn,there_vn,here_weight,there_weight,amr) - there_df = Matrix{Float64}(undef,size(there_mid,1),NDF) - for i in axes(there_df,1) - @views there_df[i,:] .= discrete_maxwell(there_mid[i,:],bc,amr.global_data) + bc[1] = calc_ρw(there_mid, df, bc, here_vn, there_vn, here_weight, there_weight, amr) + there_df = Matrix{Float64}(undef, size(there_mid, 1), NDF) + for i in axes(there_df, 1) + @views there_df[i, :] .= discrete_maxwell(there_mid[i, :], bc, amr.global_data) end - @inbounds here_micro = [df[i,j]*here_vn[i] for i in axes(df,1),j in axes(df,2)] - @inbounds there_micro = [there_df[i,j]*there_vn[i] for i in axes(there_df,1),j in axes(there_df,2)] - fw = micro_to_macro(here_micro,here_mid,here_weight,vs_data)+micro_to_macro(there_micro,there_mid,there_weight,vs_data) - return fw,[here_micro,there_micro] + @inbounds here_micro = [df[i, j]*here_vn[i] for i in axes(df, 1), j in axes(df, 2)] + @inbounds there_micro = + [there_df[i, j]*there_vn[i] for i in axes(there_df, 1), j in axes(there_df, 2)] + fw = + micro_to_macro( + here_micro, + here_mid, + here_weight, + vs_data, + )+micro_to_macro(there_micro, there_mid, there_weight, vs_data) + return fw, [here_micro, there_micro] end """ $(TYPEDSIGNATURES) """ -function calc_domain_flux(::Type{CAIDVM},here_vs::Face_VS_Data,face::DomainFace{DIM,NDF,SuperSonicInflow},amr::KitAMR_Data) where{DIM,NDF} - _,direction,midpoint,_,ps_data = unpack(face) - heavi,here_weight,here_mid,here_vn,here_df,here_sdf = unpack(here_vs) +function calc_domain_flux( + ::Type{CAIDVM}, + here_vs::Face_VS_Data, + face::DomainFace{DIM,NDF,SuperSonicInflow}, + amr::KitAMR_Data, +) where {DIM,NDF} + _, direction, midpoint, _, ps_data = unpack(face) + heavi, here_weight, here_mid, here_vn, here_df, here_sdf = unpack(here_vs) Δt = amr.global_data.status.Δt vs_data = ps_data.vs_data nheavi = [!x for x in heavi] - there_mid = @views vs_data.midpoint[nheavi,:] - there_vn = @views there_mid[:,direction] + there_mid = @views vs_data.midpoint[nheavi, :] + there_vn = @views there_mid[:, direction] there_weight = @views vs_data.weight[nheavi] - @inbounds @views dx = [midpoint[j]-here_mid[i,j]*Δt-ps_data.midpoint[j] for i in axes(here_mid,1),j in axes(here_mid,2)] - @inbounds @views df = [here_df[i,j]+dot(dx[i,:],here_sdf[i,j,:]) for i in axes(here_df,1),j in axes(here_df,2)] + @inbounds @views dx = [ + midpoint[j]-here_mid[i, j]*Δt-ps_data.midpoint[j] for + i in axes(here_mid, 1), j in axes(here_mid, 2) + ] + @inbounds @views df = [ + here_df[i, j]+dot(dx[i, :], here_sdf[i, j, :]) for + i in axes(here_df, 1), j in axes(here_df, 2) + ] bc = get_bc(face.domain.bc) - there_df = Matrix{Float64}(undef,size(there_mid,1),NDF) - for i in axes(there_df,1) - @views there_df[i,:] .= discrete_maxwell(there_mid[i,:],bc,amr.global_data) + there_df = Matrix{Float64}(undef, size(there_mid, 1), NDF) + for i in axes(there_df, 1) + @views there_df[i, :] .= discrete_maxwell(there_mid[i, :], bc, amr.global_data) end - @inbounds here_micro = [df[i,j]*here_vn[i] for i in axes(df,1),j in axes(df,2)] - @inbounds there_micro = [there_df[i,j]*there_vn[i] for i in axes(there_df,1),j in axes(there_df,2)] - fw = micro_to_macro(here_micro,here_mid,here_weight,vs_data)+micro_to_macro(there_micro,there_mid,there_weight,vs_data) - return fw,[here_micro,there_micro] + @inbounds here_micro = [df[i, j]*here_vn[i] for i in axes(df, 1), j in axes(df, 2)] + @inbounds there_micro = + [there_df[i, j]*there_vn[i] for i in axes(there_df, 1), j in axes(there_df, 2)] + fw = + micro_to_macro( + here_micro, + here_mid, + here_weight, + vs_data, + )+micro_to_macro(there_micro, there_mid, there_weight, vs_data) + return fw, [here_micro, there_micro] end """ $(TYPEDSIGNATURES) """ -function calc_domain_flux(::Type{CAIDVM},here_vs::Face_VS_Data,face::DomainFace{DIM,NDF,UniformOutflow},amr::KitAMR_Data) where{DIM,NDF} - _,direction,_,_,ps_data = unpack(face) - heavi,here_weight,here_mid,here_vn,_,_ = unpack(here_vs) +function calc_domain_flux( + ::Type{CAIDVM}, + here_vs::Face_VS_Data, + face::DomainFace{DIM,NDF,UniformOutflow}, + amr::KitAMR_Data, +) where {DIM,NDF} + _, direction, _, _, ps_data = unpack(face) + heavi, here_weight, here_mid, here_vn, _, _ = unpack(here_vs) vs_data = ps_data.vs_data nheavi = [!x for x in heavi] - there_mid = @views vs_data.midpoint[nheavi,:] - ndf = @views vs_data.df[nheavi,:] - there_vn = @views there_mid[:,direction] + there_mid = @views vs_data.midpoint[nheavi, :] + ndf = @views vs_data.df[nheavi, :] + there_vn = @views there_mid[:, direction] there_weight = @views vs_data.weight[nheavi] - df = @views vs_data.df[heavi,:] - @inbounds here_micro = [df[i,j]*here_vn[i] for i in axes(df,1),j in axes(df,2)] - @inbounds there_micro = [ndf[i,j]*there_vn[i] for i in axes(ndf,1),j in axes(ndf,2)] - fw = micro_to_macro(here_micro,here_mid,here_weight,vs_data)+micro_to_macro(there_micro,there_mid,there_weight,vs_data) - return fw,[here_micro,there_micro] + df = @views vs_data.df[heavi, :] + @inbounds here_micro = [df[i, j]*here_vn[i] for i in axes(df, 1), j in axes(df, 2)] + @inbounds there_micro = [ndf[i, j]*there_vn[i] for i in axes(ndf, 1), j in axes(ndf, 2)] + fw = + micro_to_macro( + here_micro, + here_mid, + here_weight, + vs_data, + )+micro_to_macro(there_micro, there_mid, there_weight, vs_data) + return fw, [here_micro, there_micro] end """ $(TYPEDSIGNATURES) """ -function calc_domain_flux(::Type{CAIDVM},here_vs::Face_VS_Data,face::DomainFace{2,NDF,InterpolatedOutflow},amr::KitAMR_Data) where{NDF} - _,direction,midpoint,_,ps_data = unpack(face) - heavi,here_weight,here_mid,here_vn,here_df,here_sdf = unpack(here_vs) +function calc_domain_flux( + ::Type{CAIDVM}, + here_vs::Face_VS_Data, + face::DomainFace{2,NDF,InterpolatedOutflow}, + amr::KitAMR_Data, +) where {NDF} + _, direction, midpoint, _, ps_data = unpack(face) + heavi, here_weight, here_mid, here_vn, here_df, here_sdf = unpack(here_vs) Δt = amr.global_data.status.Δt here_ps_mid = ps_data.midpoint there_ps_mid = 2.0*midpoint-here_ps_mid vs_data = ps_data.vs_data nheavi = [!x for x in heavi] @inbounds @views begin - there_mid = vs_data.midpoint[nheavi,:] - there_sdf = vs_data.sdf[nheavi,:,:] - there_df = vs_data.df[nheavi,:]+(there_ps_mid[direction]-here_ps_mid[direction])*there_sdf[:,:,direction] - there_vn = there_mid[:,direction] + there_mid = vs_data.midpoint[nheavi, :] + there_sdf = vs_data.sdf[nheavi, :, :] + there_df = + vs_data.df[ + nheavi, + :, + ]+(there_ps_mid[direction]-here_ps_mid[direction])*there_sdf[:, :, direction] + there_vn = there_mid[:, direction] there_weight = vs_data.weight[nheavi] - dx = [midpoint[j]-here_mid[i,j]*Δt-here_ps_mid[j] for i in axes(here_mid,1),j in axes(here_mid,2)] - ndx = [midpoint[j]-there_mid[i,j]*Δt-there_ps_mid[j] for i in axes(there_mid,1),j in axes(there_mid,2)] - df = [here_df[i,j]+dot(dx[i,:],here_sdf[i,j,:]) for i in axes(here_df,1),j in axes(here_df,2)] - ndf = [there_df[i,j]+dot(ndx[i,:],there_sdf[i,j,:]) for i in axes(there_df,1),j in axes(there_df,2)] - here_micro = [df[i,j]*here_vn[i] for i in axes(df,1),j in axes(df,2)] - there_micro = [ndf[i,j]*there_vn[i] for i in axes(ndf,1),j in axes(ndf,2)] + dx = [ + midpoint[j]-here_mid[i, j]*Δt-here_ps_mid[j] for + i in axes(here_mid, 1), j in axes(here_mid, 2) + ] + ndx = [ + midpoint[j]-there_mid[i, j]*Δt-there_ps_mid[j] for + i in axes(there_mid, 1), j in axes(there_mid, 2) + ] + df = [ + here_df[i, j]+dot(dx[i, :], here_sdf[i, j, :]) for + i in axes(here_df, 1), j in axes(here_df, 2) + ] + ndf = [ + there_df[i, j]+dot(ndx[i, :], there_sdf[i, j, :]) for + i in axes(there_df, 1), j in axes(there_df, 2) + ] + here_micro = [df[i, j]*here_vn[i] for i in axes(df, 1), j in axes(df, 2)] + there_micro = [ndf[i, j]*there_vn[i] for i in axes(ndf, 1), j in axes(ndf, 2)] end - fw = micro_to_macro(here_micro,here_mid,here_weight,vs_data)+micro_to_macro(there_micro,there_mid,there_weight,vs_data) - return fw,[here_micro,there_micro] + fw = + micro_to_macro( + here_micro, + here_mid, + here_weight, + vs_data, + )+micro_to_macro(there_micro, there_mid, there_weight, vs_data) + return fw, [here_micro, there_micro] end """ $(TYPEDSIGNATURES) Compute the flux across a single inner face. For [`CAIDVM`](@ref), both macro and micro fluxes are computed. """ -function calc_flux(::Type{CAIDVM},here_vs,there_vs,flux_data::Union{FullFace,FluxData},amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} # without face area and Δt - _,_,midpoint,here_data,there_data = unpack(flux_data) +function calc_flux( + ::Type{CAIDVM}, + here_vs, + there_vs, + flux_data::Union{FullFace,FluxData}, + amr::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} # without face area and Δt + _, _, midpoint, here_data, there_data = unpack(flux_data) Δt = amr.global_data.status.Δt - here_mid = here_vs.midpoint;there_mid = there_vs.midpoint - here_vn = here_vs.vn;there_vn = there_vs.vn - here_df = here_vs.df;there_df = there_vs.df - here_sdf = here_vs.sdf;there_sdf = there_vs.sdf - here_ps_mid = here_data.midpoint;there_ps_mid = there_data.midpoint + here_mid = here_vs.midpoint; + there_mid = there_vs.midpoint + here_vn = here_vs.vn; + there_vn = there_vs.vn + here_df = here_vs.df; + there_df = there_vs.df + here_sdf = here_vs.sdf; + there_sdf = there_vs.sdf + here_ps_mid = here_data.midpoint; + there_ps_mid = there_data.midpoint @inbounds @views begin - dx = [midpoint[j]-here_mid[i,j]*Δt-here_ps_mid[j] for i in axes(here_mid,1),j in axes(here_mid,2)] - ndx = [midpoint[j]-there_mid[i,j]*Δt-there_ps_mid[j] for i in axes(there_mid,1),j in axes(there_mid,2)] + dx = [ + midpoint[j]-here_mid[i, j]*Δt-here_ps_mid[j] for + i in axes(here_mid, 1), j in axes(here_mid, 2) + ] + ndx = [ + midpoint[j]-there_mid[i, j]*Δt-there_ps_mid[j] for + i in axes(there_mid, 1), j in axes(there_mid, 2) + ] if there_data.bound_enc<0 - here_micro = [(here_df[i,j]+dot(dx[i,:],here_sdf[i,j,:]))*here_vn[i] for i in axes(here_df,1),j in axes(here_df,2)] - there_micro = [(there_df[i,j]+dot(ndx[i,:],there_sdf[i,j,:]))*there_vn[i] for i in axes(there_df,1),j in axes(there_df,2)] + here_micro = [ + (here_df[i, j]+dot(dx[i, :], here_sdf[i, j, :]))*here_vn[i] for + i in axes(here_df, 1), j in axes(here_df, 2) + ] + there_micro = [ + (there_df[i, j]+dot(ndx[i, :], there_sdf[i, j, :]))*there_vn[i] for + i in axes(there_df, 1), j in axes(there_df, 2) + ] else - here_micro = positivity_preserving_reconstruct(here_df,here_sdf,here_data.ds,dx,here_vn) - there_micro = positivity_preserving_reconstruct(there_df,there_sdf,there_data.ds,ndx,there_vn) + here_micro = positivity_preserving_reconstruct( + here_df, + here_sdf, + here_data.ds, + dx, + here_vn, + ) + there_micro = positivity_preserving_reconstruct( + there_df, + there_sdf, + there_data.ds, + ndx, + there_vn, + ) end end - here_weight = here_vs.weight;there_weight = there_vs.weight - fw = micro_to_macro(here_micro,here_mid,here_weight,here_data.vs_data)+micro_to_macro(there_micro,there_mid,there_weight,here_data.vs_data) - return fw,[here_micro,there_micro] + here_weight = here_vs.weight; + there_weight = there_vs.weight + fw = + micro_to_macro( + here_micro, + here_mid, + here_weight, + here_data.vs_data, + )+micro_to_macro(there_micro, there_mid, there_weight, here_data.vs_data) + return fw, [here_micro, there_micro] end """ $(TYPEDSIGNATURES) Positivity preserving reconstruction (10.1016/j.jcp.2009.12.030). """ -function positivity_preserving_reconstruct(here_df,here_sdf,here_ds,dx,vn) # positivity preserving reconstruct (10.1016/j.jcp.2009.12.030) +function positivity_preserving_reconstruct(here_df, here_sdf, here_ds, dx, vn) # positivity preserving reconstruct (10.1016/j.jcp.2009.12.030) @views begin - micro = [(here_df[i,j]+min(abs(here_df[i,j]/(0.5*dot(here_ds,abs.(here_sdf[i,j,:]))+EPS)),1.)*dot(dx[i,:],here_sdf[i,j,:]))*vn[i] for i in axes(here_df,1),j in axes(here_df,2)] + micro = [ + ( + here_df[ + i, + j, + ]+min( + abs(here_df[i, j]/(0.5*dot(here_ds, abs.(here_sdf[i, j, :]))+EPS)), + 1.0, + )*dot(dx[i, :], here_sdf[i, j, :]) + )*vn[i] for i in axes(here_df, 1), j in axes(here_df, 2) + ] end return micro -end \ No newline at end of file +end diff --git a/src/Flux/DVM.jl b/src/Flux/DVM.jl index bacd9d7..d44c04a 100644 --- a/src/Flux/DVM.jl +++ b/src/Flux/DVM.jl @@ -1,93 +1,166 @@ -function calc_domain_flux(::DVM,here_vs::Face_VS_Data,face::DomainFace{DIM,NDF,Maxwellian},amr::KitAMR_Data) where{DIM,NDF} - _,direction,midpoint,_,ps_data = unpack(face) - heavi,here_weight,here_mid,here_vn,here_df,here_sdf = unpack(here_vs) +function calc_domain_flux( + ::DVM, + here_vs::Face_VS_Data, + face::DomainFace{DIM,NDF,Maxwellian}, + amr::KitAMR_Data, +) where {DIM,NDF} + _, direction, midpoint, _, ps_data = unpack(face) + heavi, here_weight, here_mid, here_vn, here_df, here_sdf = unpack(here_vs) Δt = amr.global_data.status.Δt vs_data = ps_data.vs_data nheavi = [!x for x in heavi] - there_mid = @views vs_data.midpoint[nheavi,:] + there_mid = @views vs_data.midpoint[nheavi, :] there_weight = @views vs_data.weight[nheavi] - there_vn = @views there_mid[:,direction] - @inbounds @views dx = [midpoint[j]-here_mid[i,j]*Δt-ps_data.midpoint[j] for i in axes(here_mid,1),j in axes(here_mid,2)] - @inbounds @views df = [here_df[i,j]+dot(dx[i,:],here_sdf[i,j,:]) for i in axes(here_df,1),j in axes(here_df,2)] + there_vn = @views there_mid[:, direction] + @inbounds @views dx = [ + midpoint[j]-here_mid[i, j]*Δt-ps_data.midpoint[j] for + i in axes(here_mid, 1), j in axes(here_mid, 2) + ] + @inbounds @views df = [ + here_df[i, j]+dot(dx[i, :], here_sdf[i, j, :]) for + i in axes(here_df, 1), j in axes(here_df, 2) + ] bc = get_bc(face.domain.bc) - bc[1] = calc_ρw(there_mid,df,bc,here_vn,there_vn,here_weight,there_weight,amr) - there_df = Matrix{Float64}(undef,size(there_mid,1),NDF) - for i in axes(there_df,1) - @views there_df[i,:] .= discrete_maxwell(there_mid[i,:],bc,amr.global_data) + bc[1] = calc_ρw(there_mid, df, bc, here_vn, there_vn, here_weight, there_weight, amr) + there_df = Matrix{Float64}(undef, size(there_mid, 1), NDF) + for i in axes(there_df, 1) + @views there_df[i, :] .= discrete_maxwell(there_mid[i, :], bc, amr.global_data) end - @inbounds here_micro = [df[i,j]*here_vn[i] for i in axes(df,1),j in axes(df,2)] - @inbounds there_micro = [there_df[i,j]*there_vn[i] for i in axes(there_df,1),j in axes(there_df,2)] - return nothing,[here_micro,there_micro] + @inbounds here_micro = [df[i, j]*here_vn[i] for i in axes(df, 1), j in axes(df, 2)] + @inbounds there_micro = + [there_df[i, j]*there_vn[i] for i in axes(there_df, 1), j in axes(there_df, 2)] + return nothing, [here_micro, there_micro] end -function calc_domain_flux(::DVM,here_vs::Face_VS_Data,face::DomainFace{DIM,NDF,SuperSonicInflow},amr::KitAMR_Data) where{DIM,NDF} - _,direction,midpoint,_,ps_data = unpack(face) - heavi,_,here_mid,here_vn,here_df,here_sdf = unpack(here_vs) +function calc_domain_flux( + ::DVM, + here_vs::Face_VS_Data, + face::DomainFace{DIM,NDF,SuperSonicInflow}, + amr::KitAMR_Data, +) where {DIM,NDF} + _, direction, midpoint, _, ps_data = unpack(face) + heavi, _, here_mid, here_vn, here_df, here_sdf = unpack(here_vs) Δt = amr.global_data.status.Δt vs_data = ps_data.vs_data nheavi = [!x for x in heavi] - there_mid = @views vs_data.midpoint[nheavi,:] - there_vn = @views there_mid[:,direction] - @inbounds @views dx = [midpoint[j]-here_mid[i,j]*Δt-ps_data.midpoint[j] for i in axes(here_mid,1),j in axes(here_mid,2)] - @inbounds @views df = [here_df[i,j]+dot(dx[i,:],here_sdf[i,j,:]) for i in axes(here_df,1),j in axes(here_df,2)] + there_mid = @views vs_data.midpoint[nheavi, :] + there_vn = @views there_mid[:, direction] + @inbounds @views dx = [ + midpoint[j]-here_mid[i, j]*Δt-ps_data.midpoint[j] for + i in axes(here_mid, 1), j in axes(here_mid, 2) + ] + @inbounds @views df = [ + here_df[i, j]+dot(dx[i, :], here_sdf[i, j, :]) for + i in axes(here_df, 1), j in axes(here_df, 2) + ] bc = get_bc(face.domain.bc) - there_df = Matrix{Float64}(undef,size(there_mid,1),NDF) - for i in axes(there_df,1) - @views there_df[i,:] .= discrete_maxwell(there_mid[i,:],bc,amr.global_data) + there_df = Matrix{Float64}(undef, size(there_mid, 1), NDF) + for i in axes(there_df, 1) + @views there_df[i, :] .= discrete_maxwell(there_mid[i, :], bc, amr.global_data) end - @inbounds here_micro = [df[i,j]*here_vn[i] for i in axes(df,1),j in axes(df,2)] - @inbounds there_micro = [there_df[i,j]*there_vn[i] for i in axes(there_df,1),j in axes(there_df,2)] - return nothing,[here_micro,there_micro] + @inbounds here_micro = [df[i, j]*here_vn[i] for i in axes(df, 1), j in axes(df, 2)] + @inbounds there_micro = + [there_df[i, j]*there_vn[i] for i in axes(there_df, 1), j in axes(there_df, 2)] + return nothing, [here_micro, there_micro] end -function calc_domain_flux(::DVM,here_vs::Face_VS_Data,face::DomainFace{DIM,NDF,UniformOutflow},amr::KitAMR_Data) where{DIM,NDF} - _,direction,_,_,ps_data = unpack(face) - heavi,_,_,here_vn,_,_ = unpack(here_vs) +function calc_domain_flux( + ::DVM, + here_vs::Face_VS_Data, + face::DomainFace{DIM,NDF,UniformOutflow}, + amr::KitAMR_Data, +) where {DIM,NDF} + _, direction, _, _, ps_data = unpack(face) + heavi, _, _, here_vn, _, _ = unpack(here_vs) vs_data = ps_data.vs_data nheavi = [!x for x in heavi] - there_mid = @views vs_data.midpoint[nheavi,:] - ndf = @views vs_data.df[nheavi,:] - there_vn = @views there_mid[:,direction] - df = @views vs_data.df[heavi,:] - @inbounds here_micro = [df[i,j]*here_vn[i] for i in axes(df,1),j in axes(df,2)] - @inbounds there_micro = [ndf[i,j]*there_vn[i] for i in axes(ndf,1),j in axes(ndf,2)] - return nothing,[here_micro,there_micro] + there_mid = @views vs_data.midpoint[nheavi, :] + ndf = @views vs_data.df[nheavi, :] + there_vn = @views there_mid[:, direction] + df = @views vs_data.df[heavi, :] + @inbounds here_micro = [df[i, j]*here_vn[i] for i in axes(df, 1), j in axes(df, 2)] + @inbounds there_micro = [ndf[i, j]*there_vn[i] for i in axes(ndf, 1), j in axes(ndf, 2)] + return nothing, [here_micro, there_micro] end -function calc_domain_flux(::DVM,here_vs::Face_VS_Data,face::DomainFace{2,NDF,InterpolatedOutflow},amr::KitAMR_Data) where{NDF} - _,direction,midpoint,_,ps_data = unpack(face) - heavi,_,here_mid,here_vn,here_df,here_sdf = unpack(here_vs) +function calc_domain_flux( + ::DVM, + here_vs::Face_VS_Data, + face::DomainFace{2,NDF,InterpolatedOutflow}, + amr::KitAMR_Data, +) where {NDF} + _, direction, midpoint, _, ps_data = unpack(face) + heavi, _, here_mid, here_vn, here_df, here_sdf = unpack(here_vs) Δt = amr.global_data.status.Δt here_ps_mid = ps_data.midpoint there_ps_mid = 2.0*midpoint-here_ps_mid vs_data = ps_data.vs_data nheavi = [!x for x in heavi] @inbounds @views begin - there_mid = vs_data.midpoint[nheavi,:] - there_sdf = vs_data.sdf[nheavi,:,:] - there_df = vs_data.df[nheavi,:]+(there_ps_mid[direction]-here_ps_mid[direction])*there_sdf[:,:,direction] - there_vn = there_mid[:,direction] - dx = [midpoint[j]-here_mid[i,j]*Δt-here_ps_mid[j] for i in axes(here_mid,1),j in axes(here_mid,2)] - ndx = [midpoint[j]-there_mid[i,j]*Δt-there_ps_mid[j] for i in axes(there_mid,1),j in axes(there_mid,2)] - df = [here_df[i,j]+dot(dx[i,:],here_sdf[i,j,:]) for i in axes(here_df,1),j in axes(here_df,2)] - ndf = [there_df[i,j]+dot(ndx[i,:],there_sdf[i,j,:]) for i in axes(there_df,1),j in axes(there_df,2)] - here_micro = [df[i,j]*here_vn[i] for i in axes(df,1),j in axes(df,2)] - there_micro = [ndf[i,j]*there_vn[i] for i in axes(ndf,1),j in axes(ndf,2)] + there_mid = vs_data.midpoint[nheavi, :] + there_sdf = vs_data.sdf[nheavi, :, :] + there_df = + vs_data.df[ + nheavi, + :, + ]+(there_ps_mid[direction]-here_ps_mid[direction])*there_sdf[:, :, direction] + there_vn = there_mid[:, direction] + dx = [ + midpoint[j]-here_mid[i, j]*Δt-here_ps_mid[j] for + i in axes(here_mid, 1), j in axes(here_mid, 2) + ] + ndx = [ + midpoint[j]-there_mid[i, j]*Δt-there_ps_mid[j] for + i in axes(there_mid, 1), j in axes(there_mid, 2) + ] + df = [ + here_df[i, j]+dot(dx[i, :], here_sdf[i, j, :]) for + i in axes(here_df, 1), j in axes(here_df, 2) + ] + ndf = [ + there_df[i, j]+dot(ndx[i, :], there_sdf[i, j, :]) for + i in axes(there_df, 1), j in axes(there_df, 2) + ] + here_micro = [df[i, j]*here_vn[i] for i in axes(df, 1), j in axes(df, 2)] + there_micro = [ndf[i, j]*there_vn[i] for i in axes(ndf, 1), j in axes(ndf, 2)] end - return nothing,[here_micro,there_micro] + return nothing, [here_micro, there_micro] end -function calc_flux(::DVM,here_vs,there_vs,flux_data::Union{FullFace,FluxData},amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} # without face area and Δt - _,_,midpoint,here_data,there_data = unpack(flux_data) +function calc_flux( + ::DVM, + here_vs, + there_vs, + flux_data::Union{FullFace,FluxData}, + amr::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} # without face area and Δt + _, _, midpoint, here_data, there_data = unpack(flux_data) Δt = amr.global_data.status.Δt - here_mid = here_vs.midpoint;there_mid = there_vs.midpoint - here_vn = here_vs.vn;there_vn = there_vs.vn - here_df = here_vs.df;there_df = there_vs.df - here_sdf = here_vs.sdf;there_sdf = there_vs.sdf - here_ps_mid = here_data.midpoint;there_ps_mid = there_data.midpoint + here_mid = here_vs.midpoint; + there_mid = there_vs.midpoint + here_vn = here_vs.vn; + there_vn = there_vs.vn + here_df = here_vs.df; + there_df = there_vs.df + here_sdf = here_vs.sdf; + there_sdf = there_vs.sdf + here_ps_mid = here_data.midpoint; + there_ps_mid = there_data.midpoint @inbounds @views begin - dx = [midpoint[j]-here_mid[i,j]*Δt-here_ps_mid[j] for i in axes(here_mid,1),j in axes(here_mid,2)] - ndx = [midpoint[j]-there_mid[i,j]*Δt-there_ps_mid[j] for i in axes(there_mid,1),j in axes(there_mid,2)] - df = [here_df[i,j]+dot(dx[i,:],here_sdf[i,j,:]) for i in axes(here_df,1),j in axes(here_df,2)] - ndf = [there_df[i,j]+dot(ndx[i,:],there_sdf[i,j,:]) for i in axes(there_df,1),j in axes(there_df,2)] - here_micro = [df[i,j]*here_vn[i] for i in axes(df,1),j in axes(df,2)] - there_micro = [ndf[i,j]*there_vn[i] for i in axes(ndf,1),j in axes(ndf,2)] + dx = [ + midpoint[j]-here_mid[i, j]*Δt-here_ps_mid[j] for + i in axes(here_mid, 1), j in axes(here_mid, 2) + ] + ndx = [ + midpoint[j]-there_mid[i, j]*Δt-there_ps_mid[j] for + i in axes(there_mid, 1), j in axes(there_mid, 2) + ] + df = [ + here_df[i, j]+dot(dx[i, :], here_sdf[i, j, :]) for + i in axes(here_df, 1), j in axes(here_df, 2) + ] + ndf = [ + there_df[i, j]+dot(ndx[i, :], there_sdf[i, j, :]) for + i in axes(there_df, 1), j in axes(there_df, 2) + ] + here_micro = [df[i, j]*here_vn[i] for i in axes(df, 1), j in axes(df, 2)] + there_micro = [ndf[i, j]*there_vn[i] for i in axes(ndf, 1), j in axes(ndf, 2)] end - return nothing,[here_micro,there_micro] -end \ No newline at end of file + return nothing, [here_micro, there_micro] +end diff --git a/src/Flux/Flux.jl b/src/Flux/Flux.jl index 511dc7a..55a4384 100644 --- a/src/Flux/Flux.jl +++ b/src/Flux/Flux.jl @@ -2,9 +2,14 @@ include("CAIDVM.jl") include("DVM.jl") include("UGKS.jl") include("Slope.jl") -export update_slope!, update_slope_inner_vs!, update_slope_bound_vs!, update_slope_inner_ps!, update_slope_bound_ps! +export update_slope!, + update_slope_inner_vs!, + update_slope_bound_vs!, + update_slope_inner_ps!, + update_slope_bound_ps! export vanleer, minmod, diff_vs! -export flux!, update_flux!, update_domain_flux!, update_micro_flux!, update_macro_flux!, make_face_vs +export flux!, + update_flux!, update_domain_flux!, update_micro_flux!, update_macro_flux!, make_face_vs export calc_flux, calc_domain_flux, positivity_preserving_reconstruct function face_area(ps_data::AbstractPsData{2}, DIR::Integer) @@ -16,44 +21,70 @@ end """ $(TYPEDSIGNATURES) """ -function flux!(face::DomainFace,amr::KitAMR_Data) +function flux!(face::DomainFace, amr::KitAMR_Data) here_vs = make_face_vs(face) - flux,micro_flux = calc_domain_flux(amr.global_data.config.solver.flux,here_vs,face,amr) - update_domain_flux!(flux,micro_flux,face,here_vs.heavi) + flux, micro_flux = + calc_domain_flux(amr.global_data.config.solver.flux, here_vs, face, amr) + update_domain_flux!(flux, micro_flux, face, here_vs.heavi) return nothing end """ $(TYPEDSIGNATURES) """ -function flux!(face::FullFace,amr::KitAMR_Data) - here_vs,there_vs = make_face_vs(face) - flux,micro_flux = calc_flux(amr.global_data.config.solver.flux,here_vs,there_vs,face,amr) - update_flux!(flux,micro_flux,face,here_vs.heavi) +function flux!(face::FullFace, amr::KitAMR_Data) + here_vs, there_vs = make_face_vs(face) + flux, micro_flux = + calc_flux(amr.global_data.config.solver.flux, here_vs, there_vs, face, amr) + update_flux!(flux, micro_flux, face, here_vs.heavi) return nothing end """ $(TYPEDSIGNATURES) """ -function flux!(face::HangingFace{DIM,NDF},amr::KitAMR_Data) where{DIM,NDF} - rot,direction,midpoint,here_data,there_data = unpack(face) - here_vs,there_vs = make_face_vs(face) +function flux!(face::HangingFace{DIM,NDF}, amr::KitAMR_Data) where {DIM,NDF} + rot, direction, midpoint, here_data, there_data = unpack(face) + here_vs, there_vs = make_face_vs(face) for i in eachindex(there_vs) - flux_data = FluxData{HangingFace{DIM,NDF}}(rot,direction,midpoint[i],here_data,there_data[i]) - flux,micro_flux = calc_flux(amr.global_data.config.solver.flux,here_vs,there_vs[i],flux_data,amr) - update_flux!(flux,micro_flux,flux_data,here_vs.heavi) + flux_data = FluxData{HangingFace{DIM,NDF}}( + rot, + direction, + midpoint[i], + here_data, + there_data[i], + ) + flux, micro_flux = calc_flux( + amr.global_data.config.solver.flux, + here_vs, + there_vs[i], + flux_data, + amr, + ) + update_flux!(flux, micro_flux, flux_data, here_vs.heavi) end return nothing end """ $(TYPEDSIGNATURES) """ -function flux!(face::BackHangingFace{DIM,NDF},amr::KitAMR_Data) where{DIM,NDF} - rot,direction,midpoint,here_data,there_data = unpack(face) - here_vs,there_vs = make_face_vs(face) +function flux!(face::BackHangingFace{DIM,NDF}, amr::KitAMR_Data) where {DIM,NDF} + rot, direction, midpoint, here_data, there_data = unpack(face) + here_vs, there_vs = make_face_vs(face) for i in eachindex(here_vs) - flux_data = FluxData{BackHangingFace{DIM,NDF}}(rot,direction,midpoint[i],here_data[i],there_data) - flux,micro_flux = calc_flux(amr.global_data.config.solver.flux,here_vs[i],there_vs,flux_data,amr) - update_flux!(flux,micro_flux,flux_data,here_vs[i].heavi) + flux_data = FluxData{BackHangingFace{DIM,NDF}}( + rot, + direction, + midpoint[i], + here_data[i], + there_data, + ) + flux, micro_flux = calc_flux( + amr.global_data.config.solver.flux, + here_vs[i], + there_vs, + flux_data, + amr, + ) + update_flux!(flux, micro_flux, flux_data, here_vs[i].heavi) end return nothing end @@ -61,59 +92,89 @@ end """ $(TYPEDSIGNATURES) """ -function update_domain_flux!(flux::AbstractVector,micro_flux::Vector{Matrix{Float64}},face::DomainFace,heavi::Vector{Bool}) - rot,direction,_,_,ps_data = unpack(face) - area = rot*face_area(ps_data,direction) - here_micro,there_micro = micro_flux +function update_domain_flux!( + flux::AbstractVector, + micro_flux::Vector{Matrix{Float64}}, + face::DomainFace, + heavi::Vector{Bool}, +) + rot, direction, _, _, ps_data = unpack(face) + area = rot*face_area(ps_data, direction) + here_micro, there_micro = micro_flux ps_data.flux .+= area*flux - ps_data.vs_data.flux[heavi,:] .+= area*here_micro - ps_data.vs_data.flux[.!heavi,:] .+= area*there_micro + ps_data.vs_data.flux[heavi, :] .+= area*here_micro + ps_data.vs_data.flux[.!heavi, :] .+= area*there_micro return nothing end """ $(TYPEDSIGNATURES) """ -function update_domain_flux!(::Nothing,micro_flux::Vector{Matrix{Float64}},face::DomainFace,heavi::Vector{Bool}) - rot,direction,_,_,ps_data = unpack(face) - area = rot*face_area(ps_data,direction) - here_micro,there_micro = micro_flux - ps_data.vs_data.flux[heavi,:] .+= area*here_micro - ps_data.vs_data.flux[.!heavi,:] .+= area*there_micro +function update_domain_flux!( + ::Nothing, + micro_flux::Vector{Matrix{Float64}}, + face::DomainFace, + heavi::Vector{Bool}, +) + rot, direction, _, _, ps_data = unpack(face) + area = rot*face_area(ps_data, direction) + here_micro, there_micro = micro_flux + ps_data.vs_data.flux[heavi, :] .+= area*here_micro + ps_data.vs_data.flux[.!heavi, :] .+= area*there_micro return nothing end -function face_area(::FluxData{HangingFace{DIM,NDF}},here_data::AbstractPsData{DIM},direction,rot) where{DIM,NDF} - face_area(here_data,direction)/2^(DIM-1)*rot +function face_area( + ::FluxData{HangingFace{DIM,NDF}}, + here_data::AbstractPsData{DIM}, + direction, + rot, +) where {DIM,NDF} + face_area(here_data, direction)/2^(DIM-1)*rot end -function face_area(::T,here_data,direction,rot) where{T<:Union{FluxData{BackHangingFace{DIM,NDF}},FullFace{DIM,NDF}} where{DIM,NDF}} - face_area(here_data,direction)*rot +function face_area( + ::T, + here_data, + direction, + rot, +) where {T<:Union{FluxData{BackHangingFace{DIM,NDF}},FullFace{DIM,NDF}} where {DIM,NDF}} + face_area(here_data, direction)*rot end """ $(TYPEDSIGNATURES) """ -function update_flux!(flux::AbstractVector,micro_flux::Vector{Matrix{Float64}},face::Union{FullFace,FluxData},heavi::Vector{Bool}) - rot,direction,_,here_data,there_data = unpack(face) - area = face_area(face,here_data,direction,rot) - here_micro,there_micro = micro_flux - update_macro_flux!(flux*area,here_data,there_data) - update_micro_flux!(here_micro*area,there_micro*area,here_data,there_data,heavi) +function update_flux!( + flux::AbstractVector, + micro_flux::Vector{Matrix{Float64}}, + face::Union{FullFace,FluxData}, + heavi::Vector{Bool}, +) + rot, direction, _, here_data, there_data = unpack(face) + area = face_area(face, here_data, direction, rot) + here_micro, there_micro = micro_flux + update_macro_flux!(flux*area, here_data, there_data) + update_micro_flux!(here_micro*area, there_micro*area, here_data, there_data, heavi) return nothing end """ $(TYPEDSIGNATURES) """ -function update_flux!(::Nothing,micro_flux::Vector{Matrix{Float64}},face::Union{FullFace,FluxData},heavi::Vector{Bool}) - rot,direction,_,here_data,there_data = unpack(face) - area = face_area(face,here_data,direction,rot) - here_micro,there_micro = micro_flux - update_micro_flux!(here_micro*area,there_micro*area,here_data,there_data,heavi) +function update_flux!( + ::Nothing, + micro_flux::Vector{Matrix{Float64}}, + face::Union{FullFace,FluxData}, + heavi::Vector{Bool}, +) + rot, direction, _, here_data, there_data = unpack(face) + area = face_area(face, here_data, direction, rot) + here_micro, there_micro = micro_flux + update_micro_flux!(here_micro*area, there_micro*area, here_data, there_data, heavi) return nothing end """ $(TYPEDSIGNATURES) """ -function update_macro_flux!(flux::Vector,here_data::PS_Data,there_data::PS_Data) +function update_macro_flux!(flux::Vector, here_data::PS_Data, there_data::PS_Data) here_data.flux .+= flux if there_data.bound_enc>=0 there_data.flux .-= flux @@ -123,49 +184,66 @@ end """ $(TYPEDSIGNATURES) """ -function update_macro_flux!(flux::Vector,here_data::PS_Data,::AbstractGhostPsData) +function update_macro_flux!(flux::Vector, here_data::PS_Data, ::AbstractGhostPsData) here_data.flux .+= flux return nothing end """ $(TYPEDSIGNATURES) """ -function update_macro_flux!(flux::Vector,here_data::PS_Data,::SolidNeighbor) +function update_macro_flux!(flux::Vector, here_data::PS_Data, ::SolidNeighbor) here_data.flux .+= flux return nothing end """ $(TYPEDSIGNATURES) """ -function update_micro_flux!(here_micro,there_micro,here_data::PS_Data{DIM},::SolidNeighbor{DIM},heavi::Vector{Bool}) where{DIM} - vs_data = here_data.vs_data;flux = vs_data.flux - @. flux[heavi,:]+= here_micro +function update_micro_flux!( + here_micro, + there_micro, + here_data::PS_Data{DIM}, + ::SolidNeighbor{DIM}, + heavi::Vector{Bool}, +) where {DIM} + vs_data = here_data.vs_data; + flux = vs_data.flux + @. flux[heavi, :] += here_micro nheavi = [!x for x in heavi] - @. flux[nheavi,:]+= there_micro + @. flux[nheavi, :] += there_micro return nothing end """ $(TYPEDSIGNATURES) """ -function update_micro_flux!(here_micro,there_micro,here_data::PS_Data{DIM,NDF},there_data::PS_Data,heavi::Vector{Bool}) where{DIM,NDF} - vs_data = here_data.vs_data;nvs_data = there_data.vs_data - level = vs_data.level;level_n = nvs_data.level - flux = vs_data.flux;flux_n = nvs_data.flux - index = j = index_n = 1;flag = 0. +function update_micro_flux!( + here_micro, + there_micro, + here_data::PS_Data{DIM,NDF}, + there_data::PS_Data, + heavi::Vector{Bool}, +) where {DIM,NDF} + vs_data = here_data.vs_data; + nvs_data = there_data.vs_data + level = vs_data.level; + level_n = nvs_data.level + flux = vs_data.flux; + flux_n = nvs_data.flux + index = j = index_n = 1; + flag = 0.0 @inbounds for i = 1:vs_data.vs_num if heavi[i] - @simd for ii in 1:NDF - flux[i, ii] +=here_micro[index, ii] + @simd for ii = 1:NDF + flux[i, ii] += here_micro[index, ii] end if level[i] == level_n[j] - @simd for ii in 1:NDF + @simd for ii = 1:NDF flux_n[j, ii] -= here_micro[index, ii] end j += 1 elseif level[i] < level_n[j] while flag != 1.0 - @simd for ii in 1:NDF + @simd for ii = 1:NDF flux_n[j, ii] -= here_micro[index, ii] end flag += 1 / 2^(DIM * (level_n[j] - level[i])) @@ -173,7 +251,7 @@ function update_micro_flux!(here_micro,there_micro,here_data::PS_Data{DIM,NDF},t end flag = 0.0 else - @simd for ii in 1:NDF + @simd for ii = 1:NDF flux_n[j, ii] -= (here_micro[index, ii]) / 2^(DIM * (level[i] - level_n[j])) end @@ -186,7 +264,7 @@ function update_micro_flux!(here_micro,there_micro,here_data::PS_Data{DIM,NDF},t index += 1 else if level[i] == level_n[j] - @simd for ii in 1:NDF + @simd for ii = 1:NDF flux_n[j, ii] -= there_micro[index_n, ii] flux[i, ii] += there_micro[index_n, ii] end @@ -194,11 +272,10 @@ function update_micro_flux!(here_micro,there_micro,here_data::PS_Data{DIM,NDF},t index_n += 1 elseif level[i] < level_n[j] while flag != 1.0 - @simd for ii in 1:NDF + @simd for ii = 1:NDF flux_n[j, ii] -= there_micro[index_n, ii] flux[i, ii] += - (there_micro[index_n, ii]) / - 2^(DIM * (level_n[j] - level[i])) + (there_micro[index_n, ii]) / 2^(DIM * (level_n[j] - level[i])) end flag += 1 / 2^(DIM * (level_n[j] - level[i])) j += 1 @@ -206,12 +283,12 @@ function update_micro_flux!(here_micro,there_micro,here_data::PS_Data{DIM,NDF},t end flag = 0.0 else - @simd for ii in 1:NDF - flux[i, ii] += there_micro[index_n, ii] + @simd for ii = 1:NDF + flux[i, ii] += there_micro[index_n, ii] end flag += 1 / 2^(DIM * (level[i] - level_n[j])) if flag == 1.0 - @simd for ii in 1:NDF + @simd for ii = 1:NDF flux_n[j, ii] -= there_micro[index_n, ii] end j += 1 @@ -226,15 +303,24 @@ end """ $(TYPEDSIGNATURES) """ -function update_micro_flux!(here_micro,there_micro,here_data::PS_Data{DIM,NDF},there_data::AbstractGhostPsData,heavi::Vector{Bool}) where{DIM,NDF} - vs_data = here_data.vs_data;nvs_data = there_data.vs_data - level = vs_data.level;level_n = nvs_data.level +function update_micro_flux!( + here_micro, + there_micro, + here_data::PS_Data{DIM,NDF}, + there_data::AbstractGhostPsData, + heavi::Vector{Bool}, +) where {DIM,NDF} + vs_data = here_data.vs_data; + nvs_data = there_data.vs_data + level = vs_data.level; + level_n = nvs_data.level flux = vs_data.flux - index = j = index_n = 1;flag = 0. + index = j = index_n = 1; + flag = 0.0 @inbounds for i = 1:vs_data.vs_num if heavi[i] - @simd for ii in 1:NDF - flux[i, ii] +=here_micro[index, ii] + @simd for ii = 1:NDF + flux[i, ii] += here_micro[index, ii] end if level[i] == level_n[j] j += 1 @@ -254,17 +340,16 @@ function update_micro_flux!(here_micro,there_micro,here_data::PS_Data{DIM,NDF},t index += 1 else if level[i] == level_n[j] - @simd for ii in 1:NDF + @simd for ii = 1:NDF flux[i, ii] += there_micro[index_n, ii] end j += 1 index_n += 1 elseif level[i] < level_n[j] while flag != 1.0 - for ii in 1:NDF + for ii = 1:NDF flux[i, ii] += - (there_micro[index_n, ii]) / - 2^(DIM * (level_n[j] - level[i])) + (there_micro[index_n, ii]) / 2^(DIM * (level_n[j] - level[i])) end flag += 1 / 2^(DIM * (level_n[j] - level[i])) j += 1 @@ -272,7 +357,7 @@ function update_micro_flux!(here_micro,there_micro,here_data::PS_Data{DIM,NDF},t end flag = 0.0 else - for ii in 1:NDF + for ii = 1:NDF flux[i, ii] += there_micro[index_n, ii] end flag += 1 / 2^(DIM * (level[i] - level_n[j])) @@ -290,81 +375,112 @@ end """ $(TYPEDSIGNATURES) """ -function make_face_vs(face::DomainFace{DIM,NDF})where{DIM,NDF} - rot,direction,_,_,ps_data = unpack(face) - vs_data = ps_data.vs_data;here_mid = vs_data.midpoint - heavi = [x<=0. for x in rot.*@views here_mid[:,direction]] +function make_face_vs(face::DomainFace{DIM,NDF}) where {DIM,NDF} + rot, direction, _, _, ps_data = unpack(face) + vs_data = ps_data.vs_data; + here_mid = vs_data.midpoint + heavi = [x<=0.0 for x in rot .* @views here_mid[:, direction]] @views here_vs = Face_VS_Data{DIM,NDF}( - heavi,vs_data.weight[heavi],here_mid[heavi,:],here_mid[heavi,direction], - vs_data.df[heavi,:],vs_data.sdf[heavi,:,:] + heavi, + vs_data.weight[heavi], + here_mid[heavi, :], + here_mid[heavi, direction], + vs_data.df[heavi, :], + vs_data.sdf[heavi, :, :], ) return here_vs end """ $(TYPEDSIGNATURES) """ -function make_face_vs(face::FullFace{DIM,NDF}) where{DIM,NDF} - rot,direction,_,here_data,there_data = unpack(face) - vs_data = here_data.vs_data;nvs_data = there_data.vs_data - here_mid = vs_data.midpoint;there_mid = nvs_data.midpoint - heavi = [x<=0. for x in rot.*@views here_mid[:,direction]] - nheavi = [x>0. for x in rot.*@views there_mid[:,direction]] +function make_face_vs(face::FullFace{DIM,NDF}) where {DIM,NDF} + rot, direction, _, here_data, there_data = unpack(face) + vs_data = here_data.vs_data; + nvs_data = there_data.vs_data + here_mid = vs_data.midpoint; + there_mid = nvs_data.midpoint + heavi = [x<=0.0 for x in rot .* @views here_mid[:, direction]] + nheavi = [x>0.0 for x in rot .* @views there_mid[:, direction]] @views here_vs = Face_VS_Data{DIM,NDF}( - heavi,vs_data.weight[heavi],here_mid[heavi,:],here_mid[heavi,direction], - vs_data.df[heavi,:],vs_data.sdf[heavi,:,:] + heavi, + vs_data.weight[heavi], + here_mid[heavi, :], + here_mid[heavi, direction], + vs_data.df[heavi, :], + vs_data.sdf[heavi, :, :], ) @views there_vs = Face_VS_Data{DIM,NDF}( - nheavi,nvs_data.weight[nheavi],there_mid[nheavi,:],there_mid[nheavi,direction], - nvs_data.df[nheavi,:],nvs_data.sdf[nheavi,:,:] + nheavi, + nvs_data.weight[nheavi], + there_mid[nheavi, :], + there_mid[nheavi, direction], + nvs_data.df[nheavi, :], + nvs_data.sdf[nheavi, :, :], ) - return here_vs,there_vs + return here_vs, there_vs end """ $(TYPEDSIGNATURES) """ -function make_face_vs(face::HangingFace{DIM,NDF}) where{DIM,NDF} - rot,direction,_,here_data,there_data = unpack(face) +function make_face_vs(face::HangingFace{DIM,NDF}) where {DIM,NDF} + rot, direction, _, here_data, there_data = unpack(face) vs_data = here_data.vs_data here_mid = vs_data.midpoint - heavi = [x<=0. for x in rot.*@views here_mid[:,direction]] + heavi = [x<=0.0 for x in rot .* @views here_mid[:, direction]] @views here_vs = Face_VS_Data{DIM,NDF}( - heavi,vs_data.weight[heavi],here_mid[heavi,:],here_mid[heavi,direction],vs_data.df[heavi,:], - vs_data.sdf[heavi,:,:] + heavi, + vs_data.weight[heavi], + here_mid[heavi, :], + here_mid[heavi, direction], + vs_data.df[heavi, :], + vs_data.sdf[heavi, :, :], ) - there_vs = Vector{Face_VS_Data{DIM,NDF}}(undef,length(there_data)) + there_vs = Vector{Face_VS_Data{DIM,NDF}}(undef, length(there_data)) for i in eachindex(there_data) nvs_data = there_data[i].vs_data there_mid = nvs_data.midpoint - nheavi = [x>0. for x in rot.*@views there_mid[:,direction]] + nheavi = [x>0.0 for x in rot .* @views there_mid[:, direction]] @views there_vs[i] = Face_VS_Data{DIM,NDF}( - nheavi,nvs_data.weight[nheavi],there_mid[nheavi,:],there_mid[nheavi,direction], - nvs_data.df[nheavi,:],nvs_data.sdf[nheavi,:,:] + nheavi, + nvs_data.weight[nheavi], + there_mid[nheavi, :], + there_mid[nheavi, direction], + nvs_data.df[nheavi, :], + nvs_data.sdf[nheavi, :, :], ) end - return here_vs,there_vs + return here_vs, there_vs end """ $(TYPEDSIGNATURES) """ -function make_face_vs(face::BackHangingFace{DIM,NDF}) where{DIM,NDF} - rot,direction,_,here_data,there_data = unpack(face) +function make_face_vs(face::BackHangingFace{DIM,NDF}) where {DIM,NDF} + rot, direction, _, here_data, there_data = unpack(face) nvs_data = there_data.vs_data - nheavi = [x>0. for x in rot.*@views nvs_data.midpoint[:,direction]] + nheavi = [x>0.0 for x in rot .* @views nvs_data.midpoint[:, direction]] @views there_vs = Face_VS_Data{DIM,NDF}( - nheavi,nvs_data.weight[nheavi],nvs_data.midpoint[nheavi,:],nvs_data.midpoint[nheavi,direction], - nvs_data.df[nheavi,:],nvs_data.sdf[nheavi,:,:] - ) - here_vs = Vector{Face_VS_Data{DIM,NDF}}(undef,length(here_data)) + nheavi, + nvs_data.weight[nheavi], + nvs_data.midpoint[nheavi, :], + nvs_data.midpoint[nheavi, direction], + nvs_data.df[nheavi, :], + nvs_data.sdf[nheavi, :, :], + ) + here_vs = Vector{Face_VS_Data{DIM,NDF}}(undef, length(here_data)) for i in eachindex(here_data) vs_data = here_data[i].vs_data here_mid = vs_data.midpoint - heavi = [x<=0. for x in rot.*@views here_mid[:,direction]] + heavi = [x<=0.0 for x in rot .* @views here_mid[:, direction]] @views here_vs[i] = Face_VS_Data{DIM,NDF}( - heavi,vs_data.weight[heavi],here_mid[heavi,:],here_mid[heavi,direction],vs_data.df[heavi,:], - vs_data.sdf[heavi,:,:] - ) + heavi, + vs_data.weight[heavi], + here_mid[heavi, :], + here_mid[heavi, direction], + vs_data.df[heavi, :], + vs_data.sdf[heavi, :, :], + ) end - return here_vs,there_vs + return here_vs, there_vs end """ @@ -374,7 +490,7 @@ Outer function for flux computation and update. The iteration is carried out thr function flux!(amr::KitAMR_Data) faces = amr.field.faces for face in faces - flux!(face,amr) + flux!(face, amr) end return nothing -end \ No newline at end of file +end diff --git a/src/Flux/Slope.jl b/src/Flux/Slope.jl index 34a39cf..f4f8090 100644 --- a/src/Flux/Slope.jl +++ b/src/Flux/Slope.jl @@ -17,16 +17,21 @@ end """ $(TYPEDSIGNATURES) """ -function minmod(sL::Real,sR::Real) +function minmod(sL::Real, sR::Real) SL = abs(sL) SR = abs(sR) - 0.5(sign(sL)+sign(sR))*min(SL,SR) + 0.5(sign(sL)+sign(sR))*min(SL, SR) end """ $(TYPEDSIGNATURES) Difference through all velocity cells in two neighboring physical cells. """ -function diff_vs!(vs_data::AbstractVsData{DIM,NDF}, vs_data_n::AbstractVsData{DIM,NDF}, dsL::Float64, sL::AbstractMatrix) where{DIM,NDF} +function diff_vs!( + vs_data::AbstractVsData{DIM,NDF}, + vs_data_n::AbstractVsData{DIM,NDF}, + dsL::Float64, + sL::AbstractMatrix, +) where {DIM,NDF} index = 1 flag = 0.0 level = vs_data.level @@ -70,7 +75,7 @@ function update_slope_bound_vs!( neighbor_datas::AbstractVector, ds::Float64, dir::Int, -) where{DIM,NDF} +) where {DIM,NDF} sdf = zeros(Float64, vs_data.vs_num, NDF) N = length(neighbor_datas) for j = 1:N @@ -90,15 +95,16 @@ function update_slope_inner_vs!( dsL::Float64, dsR::Float64, dir::Int, -) where{DIM,NDF} +) where {DIM,NDF} sL = zeros(Float64, vs_data.vs_num, NDF) sR = zeros(Float64, vs_data.vs_num, NDF) - nL = length(Ldata);nR = length(Rdata) - for j in 1:nL + nL = length(Ldata); + nR = length(Rdata) + for j = 1:nL L_data = Ldata[j].vs_data diff_vs!(vs_data, L_data, dsL, sL) end - for j in 1:nR + for j = 1:nR R_data = Rdata[j].vs_data diff_vs!(vs_data, R_data, dsR, sR) end @@ -109,24 +115,27 @@ end $(TYPEDSIGNATURES) """ function update_slope_inner_ps!( - ps_data::PS_Data{DIM,NDF}, - Ldata::AbstractVector, - Rdata::AbstractVector, - dsL::Float64, - dsR::Float64, + ps_data::PS_Data{DIM,NDF}, + Ldata::AbstractVector, + Rdata::AbstractVector, + dsL::Float64, + dsR::Float64, dir::Int, -) where{DIM,NDF} - swL = zeros(Float64,DIM+2);swR = zeros(Float64,DIM+2) - nL = length(Ldata);nR = length(Rdata) - for j in 1:nL +) where {DIM,NDF} + swL = zeros(Float64, DIM+2); + swR = zeros(Float64, DIM+2) + nL = length(Ldata); + nR = length(Rdata) + for j = 1:nL @. swL += (ps_data.w-Ldata[j].w)/dsL end - for j in 1:nR + for j = 1:nR @. swR += (ps_data.w-Rdata[j].w)/dsR end - swL/=nL;swR/=nR + swL/=nL; + swR/=nR for j in eachindex(swL) - ps_data.sw[j,dir] = abs(swL[j])>abs(swR[j]) ? swL[j] : swR[j] + ps_data.sw[j, dir] = abs(swL[j])>abs(swR[j]) ? swL[j] : swR[j] end return nothing end @@ -134,18 +143,18 @@ end $(TYPEDSIGNATURES) """ function update_slope_bound_ps!( - ps_data::PS_Data{DIM,NDF}, - Ldata::AbstractVector, - dsL::Float64, + ps_data::PS_Data{DIM,NDF}, + Ldata::AbstractVector, + dsL::Float64, dir::Int, -) where{DIM,NDF} - swL = zeros(Float64,DIM+2) +) where {DIM,NDF} + swL = zeros(Float64, DIM+2) nL = length(Ldata) - for j in 1:nL + for j = 1:nL @. swL += (ps_data.w-Ldata[j].w)/dsL end swL/=nL - ps_data.sw[:,dir] .= swL + ps_data.sw[:, dir] .= swL return nothing end @@ -164,15 +173,15 @@ function update_slope!( dir::Integer, ) where {DIM,NDF} if Ldata[1].bound_enc<0&&Rdata[1].bound_enc<0 - ps_data.vs_data.sdf[:,:,dir] .= 0. + ps_data.vs_data.sdf[:, :, dir] .= 0.0 elseif Ldata[1].bound_enc<0 ds = ps_data.midpoint[dir]-Rdata[1].midpoint[dir] - update_slope_bound_vs!(ps_data.vs_data,Rdata,ds,dir) - update_slope_bound_ps!(ps_data,Rdata,ds,dir) + update_slope_bound_vs!(ps_data.vs_data, Rdata, ds, dir) + update_slope_bound_ps!(ps_data, Rdata, ds, dir) elseif Rdata[1].bound_enc<0 ds = ps_data.midpoint[dir]-Ldata[1].midpoint[dir] - update_slope_bound_vs!(ps_data.vs_data,Ldata,ds,dir) - update_slope_bound_ps!(ps_data,Ldata,ds,dir) + update_slope_bound_vs!(ps_data.vs_data, Ldata, ds, dir) + update_slope_bound_ps!(ps_data, Ldata, ds, dir) else ds = ps_data.ds[dir] update_slope_inner_vs!(ps_data.vs_data, Ldata, Rdata, ds, -ds, dir) @@ -412,13 +421,13 @@ end """ $(TYPEDSIGNATURES) """ -function update_slope!(amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function update_slope!(amr::KitAMR_Data{DIM,NDF}) where {DIM,NDF} trees = amr.field.trees global_data = amr.global_data @inbounds for i in eachindex(trees.data) @inbounds for j in eachindex(trees.data[i]) ps_data = trees.data[i][j] - isa(ps_data,InsideSolidData) && continue + isa(ps_data, InsideSolidData) && continue ps_data.bound_enc<0 && continue # solid_cells neighbor = ps_data.neighbor for dir = 1:DIM diff --git a/src/Flux/UGKS.jl b/src/Flux/UGKS.jl index 932493e..607a03e 100644 --- a/src/Flux/UGKS.jl +++ b/src/Flux/UGKS.jl @@ -1,30 +1,48 @@ -function calc_domain_flux(::Type{UGKS},here_vs::Face_VS_Data,face::DomainFace{2,2,SuperSonicInflow},amr::KitAMR_Data) - rot,direction,midpoint,_,here_data = unpack(face) - heavi,_,_,_,here_df,here_sdf = unpack(here_vs) +function calc_domain_flux( + ::Type{UGKS}, + here_vs::Face_VS_Data, + face::DomainFace{2,2,SuperSonicInflow}, + amr::KitAMR_Data, +) + rot, direction, midpoint, _, here_data = unpack(face) + heavi, _, _, _, here_df, here_sdf = unpack(here_vs) global_data = amr.global_data gas = global_data.config.gas Δt = global_data.status.Δt vs_data = here_data.vs_data nheavi = [!x for x in heavi] - there_mid = @views vs_data.midpoint[nheavi,:] + there_mid = @views vs_data.midpoint[nheavi, :] there_weight = @views vs_data.weight[nheavi] - there_vn = @views there_mid[:,direction] - there_sdf = @views vs_data.sdf[nheavi,:,:] + there_vn = @views there_mid[:, direction] + there_sdf = @views vs_data.sdf[nheavi, :, :] dx = midpoint-here_data.midpoint bc = get_bc(face.domain.bc) - domain_w = get_conserved(bc,global_data) + domain_w = get_conserved(bc, global_data) @inbounds @views begin - df = [here_df[i,j]+dot(dx,here_sdf[i,j,:]) for i in axes(here_df,1),j in axes(here_df,2)] + df = [ + here_df[i, j]+dot(dx, here_sdf[i, j, :]) for + i in axes(here_df, 1), j in axes(here_df, 2) + ] end - ndf = Matrix{Float64}(undef,size(there_mid,1),2) - @inbounds for i in axes(ndf,1) - @views ndf[i,:] .= discrete_maxwell(there_mid[i,:],bc,global_data) + ndf = Matrix{Float64}(undef, size(there_mid, 1), 2) + @inbounds for i in axes(ndf, 1) + @views ndf[i, :] .= discrete_maxwell(there_mid[i, :], bc, global_data) end - Here_vs = Face_VS_Data(here_vs,df);There_vs = Face_VS_Data{2,2}(nheavi,there_weight,there_mid,there_vn,ndf,there_sdf) - w0 = calc_w0(Here_vs,There_vs) + Here_vs = Face_VS_Data(here_vs, df); + There_vs = Face_VS_Data{2,2}(nheavi, there_weight, there_mid, there_vn, ndf, there_sdf) + w0 = calc_w0(Here_vs, There_vs) prim0 = get_prim(w0, global_data) - qf0 = calc_qf(Here_vs,There_vs,prim0) - aL, aR = calc_a(w0, prim0, here_data.w, domain_w, here_data.ds[direction], here_data.ds[direction], global_data, rot) + qf0 = calc_qf(Here_vs, There_vs, prim0) + aL, aR = calc_a( + w0, + prim0, + here_data.w, + domain_w, + here_data.ds[direction], + here_data.ds[direction], + global_data, + rot, + ) Mu, Mv, Mξ, Mu_L, Mu_R = moment_u(prim0, global_data, rot, direction) A = calc_A(prim0, aL, aR, Mu, Mv, Mξ, Mu_L, Mu_R, global_data, direction) τ0 = get_τ(prim0, gas.μᵣ, gas.ω) @@ -37,29 +55,51 @@ function calc_domain_flux(::Type{UGKS},here_vs::Face_VS_Data,face::DomainFace{2, fw += calc_flux_f0(Here_vs, There_vs, here_F⁺, there_F⁺, Mt, direction) here_micro = calc_micro_flux(Here_vs, here_F, here_F⁺, aL, A, Mξ, Mt, direction) there_micro = calc_micro_flux(There_vs, there_F, there_F⁺, aR, A, Mξ, Mt, direction) - return fw,[here_micro,there_micro] + return fw, [here_micro, there_micro] end -function calc_domain_flux(::Type{UGKS},here_vs::Face_VS_Data,face::DomainFace{2,2,UniformOutflow},amr::KitAMR_Data) - rot,direction,midpoint,_,here_data = unpack(face) - heavi,here_weight,here_mid,here_vn,here_df,here_sdf = unpack(here_vs) +function calc_domain_flux( + ::Type{UGKS}, + here_vs::Face_VS_Data, + face::DomainFace{2,2,UniformOutflow}, + amr::KitAMR_Data, +) + rot, direction, midpoint, _, here_data = unpack(face) + heavi, here_weight, here_mid, here_vn, here_df, here_sdf = unpack(here_vs) global_data = amr.global_data gas = global_data.config.gas Δt = global_data.status.Δt vs_data = here_data.vs_data nheavi = [!x for x in heavi] - there_mid = @views vs_data.midpoint[nheavi,:] + there_mid = @views vs_data.midpoint[nheavi, :] there_weight = @views vs_data.weight[nheavi] - there_vn = @views there_mid[:,direction] - there_df = @views vs_data.df[nheavi,:] - there_sdf = @views vs_data.sdf[nheavi,:,:] + there_vn = @views there_mid[:, direction] + there_df = @views vs_data.df[nheavi, :] + there_sdf = @views vs_data.sdf[nheavi, :, :] df = here_df ndf = there_df - Here_vs = Face_VS_Data{2,2}(heavi,here_weight,here_mid,here_vn,df,zeros(size(here_sdf))) - There_vs = Face_VS_Data{2,2}(nheavi,there_weight,there_mid,there_vn,ndf,zeros(size(there_sdf))) - w0 = calc_w0(Here_vs,There_vs) + Here_vs = + Face_VS_Data{2,2}(heavi, here_weight, here_mid, here_vn, df, zeros(size(here_sdf))) + There_vs = Face_VS_Data{2,2}( + nheavi, + there_weight, + there_mid, + there_vn, + ndf, + zeros(size(there_sdf)), + ) + w0 = calc_w0(Here_vs, There_vs) prim0 = get_prim(w0, global_data) - qf0 = calc_qf(Here_vs,There_vs,prim0) - aL, aR = calc_a(w0, prim0, here_data.w, w0, here_data.ds[direction], here_data.ds[direction], global_data, rot) + qf0 = calc_qf(Here_vs, There_vs, prim0) + aL, aR = calc_a( + w0, + prim0, + here_data.w, + w0, + here_data.ds[direction], + here_data.ds[direction], + global_data, + rot, + ) Mu, Mv, Mξ, Mu_L, Mu_R = moment_u(prim0, global_data, rot, direction) A = calc_A(prim0, aL, aR, Mu, Mv, Mξ, Mu_L, Mu_R, global_data, direction) τ0 = get_τ(prim0, gas.μᵣ, gas.ω) @@ -72,34 +112,57 @@ function calc_domain_flux(::Type{UGKS},here_vs::Face_VS_Data,face::DomainFace{2, fw += calc_flux_f0(Here_vs, There_vs, here_F⁺, there_F⁺, Mt, direction) here_micro = calc_micro_flux(Here_vs, here_F, here_F⁺, aL, A, Mξ, Mt, direction) there_micro = calc_micro_flux(There_vs, there_F, there_F⁺, aR, A, Mξ, Mt, direction) - return fw,[here_micro,there_micro] + return fw, [here_micro, there_micro] end -function calc_domain_flux(::Type{UGKS},here_vs::Face_VS_Data,face::DomainFace{2,2,InterpolatedOutflow},amr::KitAMR_Data) - rot,direction,midpoint,_,here_data = unpack(face) - heavi,here_weight,here_mid,here_vn,here_df,here_sdf = unpack(here_vs) +function calc_domain_flux( + ::Type{UGKS}, + here_vs::Face_VS_Data, + face::DomainFace{2,2,InterpolatedOutflow}, + amr::KitAMR_Data, +) + rot, direction, midpoint, _, here_data = unpack(face) + heavi, here_weight, here_mid, here_vn, here_df, here_sdf = unpack(here_vs) global_data = amr.global_data gas = global_data.config.gas Δt = global_data.status.Δt vs_data = here_data.vs_data here_ps_mid = here_data.midpoint nheavi = [!x for x in heavi] - there_mid = @views vs_data.midpoint[nheavi,:] + there_mid = @views vs_data.midpoint[nheavi, :] there_weight = @views vs_data.weight[nheavi] - there_vn = @views there_mid[:,direction] - there_df = @views vs_data.df[nheavi,:]+2.0*vs_data.sdf[nheavi,:,direction]*(midpoint[direction]-here_ps_mid[direction]) - there_sdf = @views vs_data.sdf[nheavi,:,:] + there_vn = @views there_mid[:, direction] + there_df = @views vs_data.df[ + nheavi, + :, + ]+2.0*vs_data.sdf[nheavi, :, direction]*(midpoint[direction]-here_ps_mid[direction]) + there_sdf = @views vs_data.sdf[nheavi, :, :] dx = midpoint-here_ps_mid ndx = -dx @inbounds @views begin - df = [here_df[i,j]+dot(dx,here_sdf[i,j,:]) for i in axes(here_df,1),j in axes(here_df,2)] - ndf = [there_df[i,j]+dot(ndx,there_sdf[i,j,:]) for i in axes(there_df,1),j in axes(there_df,2)] + df = [ + here_df[i, j]+dot(dx, here_sdf[i, j, :]) for + i in axes(here_df, 1), j in axes(here_df, 2) + ] + ndf = [ + there_df[i, j]+dot(ndx, there_sdf[i, j, :]) for + i in axes(there_df, 1), j in axes(there_df, 2) + ] end - Here_vs = Face_VS_Data{2,2}(heavi,here_weight,here_mid,here_vn,df,here_sdf) - There_vs = Face_VS_Data{2,2}(nheavi,there_weight,there_mid,there_vn,ndf,there_sdf) - w0 = calc_w0(Here_vs,There_vs) + Here_vs = Face_VS_Data{2,2}(heavi, here_weight, here_mid, here_vn, df, here_sdf) + There_vs = Face_VS_Data{2,2}(nheavi, there_weight, there_mid, there_vn, ndf, there_sdf) + w0 = calc_w0(Here_vs, There_vs) prim0 = get_prim(w0, global_data) - qf0 = calc_qf(Here_vs,There_vs,prim0) - aL, aR = calc_a(w0, prim0, here_data.w, 2.0*w0-here_data.w, here_data.ds[direction], here_data.ds[direction], global_data, rot) + qf0 = calc_qf(Here_vs, There_vs, prim0) + aL, aR = calc_a( + w0, + prim0, + here_data.w, + 2.0*w0-here_data.w, + here_data.ds[direction], + here_data.ds[direction], + global_data, + rot, + ) Mu, Mv, Mξ, Mu_L, Mu_R = moment_u(prim0, global_data, rot, direction) A = calc_A(prim0, aL, aR, Mu, Mv, Mξ, Mu_L, Mu_R, global_data, direction) τ0 = get_τ(prim0, gas.μᵣ, gas.ω) @@ -112,52 +175,87 @@ function calc_domain_flux(::Type{UGKS},here_vs::Face_VS_Data,face::DomainFace{2, fw += calc_flux_f0(Here_vs, There_vs, here_F⁺, there_F⁺, Mt, direction) here_micro = calc_micro_flux(Here_vs, here_F, here_F⁺, aL, A, Mξ, Mt, direction) there_micro = calc_micro_flux(There_vs, there_F, there_F⁺, aR, A, Mξ, Mt, direction) - return fw,[here_micro,there_micro] + return fw, [here_micro, there_micro] end -function calc_w0(here_vs::Face_VS_Data{2,2},there_vs::Face_VS_Data) +function calc_w0(here_vs::Face_VS_Data{2,2}, there_vs::Face_VS_Data) @inbounds @views micro_to_macro_2D2F( - here_vs.midpoint[:,1],here_vs.midpoint[:,2], - here_vs.df[:,1],here_vs.df[:,2],here_vs.weight - ) + - micro_to_macro_2D2F( - there_vs.midpoint[:,1],there_vs.midpoint[:,2], - there_vs.df[:,1],there_vs.df[:,2],there_vs.weight + here_vs.midpoint[:, 1], + here_vs.midpoint[:, 2], + here_vs.df[:, 1], + here_vs.df[:, 2], + here_vs.weight, + ) + micro_to_macro_2D2F( + there_vs.midpoint[:, 1], + there_vs.midpoint[:, 2], + there_vs.df[:, 1], + there_vs.df[:, 2], + there_vs.weight, ) end -function calc_w0(here_vs::Face_VS_Data{3,1},there_vs::Face_VS_Data) +function calc_w0(here_vs::Face_VS_Data{3,1}, there_vs::Face_VS_Data) @inbounds @views micro_to_macro_3D1F( - here_vs.midpoint[:,1],here_vs.midpoint[:,2], - here_vs.df[:,1],here_vs.df[:,2],here_vs.weight - ) + - micro_to_macro_3D1F( - there_vs.midpoint[:,1],there_vs.midpoint[:,2], - there_vs.df[:,1],there_vs.df[:,2],there_vs.weight + here_vs.midpoint[:, 1], + here_vs.midpoint[:, 2], + here_vs.df[:, 1], + here_vs.df[:, 2], + here_vs.weight, + ) + micro_to_macro_3D1F( + there_vs.midpoint[:, 1], + there_vs.midpoint[:, 2], + there_vs.df[:, 1], + there_vs.df[:, 2], + there_vs.weight, ) end -function calc_qf(here_vs::Face_VS_Data{2,2},there_vs::Face_VS_Data,prim::AbstractVector) +function calc_qf(here_vs::Face_VS_Data{2,2}, there_vs::Face_VS_Data, prim::AbstractVector) @inbounds @views heat_flux_2D2F( - here_vs.midpoint[:,1],here_vs.midpoint[:,2], - here_vs.df[:,1],here_vs.df[:,2], - prim,here_vs.weight, - ) + - heat_flux_2D2F( - there_vs.midpoint[:,1],there_vs.midpoint[:,2], - there_vs.df[:,1],there_vs.df[:,2], - prim,there_vs.weight, + here_vs.midpoint[:, 1], + here_vs.midpoint[:, 2], + here_vs.df[:, 1], + here_vs.df[:, 2], + prim, + here_vs.weight, + ) + heat_flux_2D2F( + there_vs.midpoint[:, 1], + there_vs.midpoint[:, 2], + there_vs.df[:, 1], + there_vs.df[:, 2], + prim, + there_vs.weight, ) end -function calc_flux_f0(hvd::Face_VS_Data{2,2},tvd,here_F::AbstractMatrix,there_F,Mt,direction::Int) +function calc_flux_f0( + hvd::Face_VS_Data{2,2}, + tvd, + here_F::AbstractMatrix, + there_F, + Mt, + direction::Int, +) @inbounds @views calc_flux_f0_2D2F( - hvd.midpoint[:,1],hvd.midpoint[:,2], - hvd.df[:,1],hvd.df[:,2], - hvd.sdf[:,1,direction],hvd.sdf[:,2,direction], - hvd.weight,here_F[:,1],here_F[:,2],hvd.vn,Mt - ) + - calc_flux_f0_2D2F( - tvd.midpoint[:,1],tvd.midpoint[:,2], - tvd.df[:,1],tvd.df[:,2], - tvd.sdf[:,1,direction],tvd.sdf[:,2,direction], - tvd.weight,there_F[:,1],there_F[:,2],tvd.vn,Mt + hvd.midpoint[:, 1], + hvd.midpoint[:, 2], + hvd.df[:, 1], + hvd.df[:, 2], + hvd.sdf[:, 1, direction], + hvd.sdf[:, 2, direction], + hvd.weight, + here_F[:, 1], + here_F[:, 2], + hvd.vn, + Mt, + ) + calc_flux_f0_2D2F( + tvd.midpoint[:, 1], + tvd.midpoint[:, 2], + tvd.df[:, 1], + tvd.df[:, 2], + tvd.sdf[:, 1, direction], + tvd.sdf[:, 2, direction], + tvd.weight, + there_F[:, 1], + there_F[:, 2], + tvd.vn, + Mt, ) end @@ -189,7 +287,7 @@ function calc_micro_flux_2D2F( ax[2] * u * H0 + ax[3] * v * H0 + 0.5 * ax[4] * ((u^2 + v^2) * H0 + B0) - )+ + ) + Mt[3] * vn * ( @@ -237,8 +335,8 @@ function calc_micro_flux( f_vs_data.midpoint[:, 2], f_vs_data.df[:, 1], f_vs_data.df[:, 2], - f_vs_data.sdf[:, 1,direction], - f_vs_data.sdf[:, 2,direction], + f_vs_data.sdf[:, 1, direction], + f_vs_data.sdf[:, 2, direction], F0[:, 1], F0[:, 2], F⁺[:, 1], @@ -251,27 +349,53 @@ function calc_micro_flux( ) end end -function calc_flux(::Type{UGKS},here_vs,there_vs,flux_data::Union{FullFace,FluxData},amr::KitAMR_Data{2,2}) # without face area - rot,direction,midpoint,here_data,there_data = unpack(flux_data) +function calc_flux( + ::Type{UGKS}, + here_vs, + there_vs, + flux_data::Union{FullFace,FluxData}, + amr::KitAMR_Data{2,2}, +) # without face area + rot, direction, midpoint, here_data, there_data = unpack(flux_data) global_data = amr.global_data - gas = global_data.config.gas;Δt = global_data.status.Δt - here_df = here_vs.df;there_df = there_vs.df - here_sdf = here_vs.sdf;there_sdf = there_vs.sdf - here_ps_mid = here_data.midpoint;there_ps_mid = there_data.midpoint + gas = global_data.config.gas; + Δt = global_data.status.Δt + here_df = here_vs.df; + there_df = there_vs.df + here_sdf = here_vs.sdf; + there_sdf = there_vs.sdf + here_ps_mid = here_data.midpoint; + there_ps_mid = there_data.midpoint dx = midpoint-here_ps_mid ndx = midpoint-there_ps_mid @inbounds @views begin - df = [here_df[i,j]+dot(dx,here_sdf[i,j,:]) for i in axes(here_df,1),j in axes(here_df,2)] - ndf = [there_df[i,j]+dot(ndx,there_sdf[i,j,:]) for i in axes(there_df,1),j in axes(there_df,2)] + df = [ + here_df[i, j]+dot(dx, here_sdf[i, j, :]) for + i in axes(here_df, 1), j in axes(here_df, 2) + ] + ndf = [ + there_df[i, j]+dot(ndx, there_sdf[i, j, :]) for + i in axes(there_df, 1), j in axes(there_df, 2) + ] end - Here_vs = Face_VS_Data(here_vs,df);There_vs = Face_VS_Data(there_vs,ndf) - w0 = calc_w0(Here_vs,There_vs) + Here_vs = Face_VS_Data(here_vs, df); + There_vs = Face_VS_Data(there_vs, ndf) + w0 = calc_w0(Here_vs, There_vs) prim0 = get_prim(w0, global_data) if 1/prim0[end]>1e-6 - qf0 = calc_qf(Here_vs,There_vs,prim0) - wL = @. here_data.w+dx[FAT[1][direction]]*here_data.sw[:,FAT[1][direction]] - wR = @. there_data.w+ndx[FAT[1][direction]]*there_data.sw[:,FAT[1][direction]] - aL, aR = calc_a(w0, prim0, wL, wR, here_data.ds[direction], there_data.ds[direction], global_data, rot) + qf0 = calc_qf(Here_vs, There_vs, prim0) + wL = @. here_data.w+dx[FAT[1][direction]]*here_data.sw[:, FAT[1][direction]] + wR = @. there_data.w+ndx[FAT[1][direction]]*there_data.sw[:, FAT[1][direction]] + aL, aR = calc_a( + w0, + prim0, + wL, + wR, + here_data.ds[direction], + there_data.ds[direction], + global_data, + rot, + ) Mu, Mv, Mξ, Mu_L, Mu_R = moment_u(prim0, global_data, rot, direction) A = calc_A(prim0, aL, aR, Mu, Mv, Mξ, Mu_L, Mu_R, global_data, direction) τ0 = get_τ(prim0, gas.μᵣ, gas.ω) @@ -285,10 +409,11 @@ function calc_flux(::Type{UGKS},here_vs,there_vs,flux_data::Union{FullFace,FluxD here_micro = calc_micro_flux(Here_vs, here_F, here_F⁺, aL, A, Mξ, Mt, direction) there_micro = calc_micro_flux(There_vs, there_F, there_F⁺, aR, A, Mξ, Mt, direction) else - fw, microflux = calc_flux(CAIDVM,here_vs,there_vs,flux_data,amr) - here_micro,there_micro = microflux - here_micro *= global_data.status.Δt;there_micro *= global_data.status.Δt + fw, microflux = calc_flux(CAIDVM, here_vs, there_vs, flux_data, amr) + here_micro, there_micro = microflux + here_micro *= global_data.status.Δt; + there_micro *= global_data.status.Δt fw *= global_data.status.Δt end - return fw,[here_micro,there_micro] -end \ No newline at end of file + return fw, [here_micro, there_micro] +end diff --git a/src/Gas/Gas.jl b/src/Gas/Gas.jl index 1ea62a7..4718fec 100644 --- a/src/Gas/Gas.jl +++ b/src/Gas/Gas.jl @@ -1,3 +1,3 @@ include("Model.jl") -export Gas, ref_vhs_vis, get_τ \ No newline at end of file +export Gas, ref_vhs_vis, get_τ diff --git a/src/Gas/Model.jl b/src/Gas/Model.jl index d886faf..e6dba4e 100644 --- a/src/Gas/Model.jl +++ b/src/Gas/Model.jl @@ -2,8 +2,9 @@ $(TYPEDSIGNATURES) Reference viscousity obtained by VHS molecules model. """ -function ref_vhs_vis(Kn, omega, alpha = 1., T_ref = 1.) - μ_0 = 5.0 * (alpha + 1.0) * (alpha + 2.0) * √π / +function ref_vhs_vis(Kn, omega, alpha = 1.0, T_ref = 1.0) + μ_0 = + 5.0 * (alpha + 1.0) * (alpha + 2.0) * √π / (4.0 * alpha * (5.0 - 2.0 * omega) * (7.0 - 2.0 * omega)) * Kn return μ_0*(T_ref)^(0.5-omega) end @@ -11,4 +12,4 @@ end $(TYPEDSIGNATURES) Calculate collisional time. """ -get_τ(prim::AbstractVector, μ::Real, ω::Real) = μ * 2.0 * prim[end]^(1 - ω) / prim[1] \ No newline at end of file +get_τ(prim::AbstractVector, μ::Real, ω::Real) = μ * 2.0 * prim[end]^(1 - ω) / prim[1] diff --git a/src/Gas/Types.jl b/src/Gas/Types.jl index f193068..5d6ff52 100644 --- a/src/Gas/Types.jl +++ b/src/Gas/Types.jl @@ -22,17 +22,15 @@ mutable struct Gas <: AbstractGas "The reference temperature of the molecular model. Default is `1.0`." T_ref::Float64 # The reference temperature of the molecular model end -function Gas(;kwargs...) - Kn = haskey(kwargs,:Kn) ? kwargs[:Kn] : 0.05 - Pr = haskey(kwargs,:Pr) ? kwargs[:Pr] : 2/3 - K = haskey(kwargs,:K) ? kwargs[:K] : 1.0 - γ = haskey(kwargs,:γ) ? kwargs[:γ] : 5/3 - ω = haskey(kwargs,:ω) ? kwargs[:ω] : 0.5 - αᵣ = haskey(kwargs,:αᵣ) ? kwargs[:αᵣ] : 1.0 - ωᵣ = haskey(kwargs,:ωᵣ) ? kwargs[:ωᵣ] : 0.81 - μᵣ = haskey(kwargs,:μᵣ) ? kwargs[:μᵣ] : ref_vhs_vis(Kn,αᵣ,ωᵣ) - T_ref = haskey(kwargs,:T_ref) ? kwargs[:T_ref] : 1.0 - return Gas( - Kn,Pr,K,γ,ω,αᵣ,ωᵣ,μᵣ,T_ref - ) -end \ No newline at end of file +function Gas(; kwargs...) + Kn = haskey(kwargs, :Kn) ? kwargs[:Kn] : 0.05 + Pr = haskey(kwargs, :Pr) ? kwargs[:Pr] : 2/3 + K = haskey(kwargs, :K) ? kwargs[:K] : 1.0 + γ = haskey(kwargs, :γ) ? kwargs[:γ] : 5/3 + ω = haskey(kwargs, :ω) ? kwargs[:ω] : 0.5 + αᵣ = haskey(kwargs, :αᵣ) ? kwargs[:αᵣ] : 1.0 + ωᵣ = haskey(kwargs, :ωᵣ) ? kwargs[:ωᵣ] : 0.81 + μᵣ = haskey(kwargs, :μᵣ) ? kwargs[:μᵣ] : ref_vhs_vis(Kn, αᵣ, ωᵣ) + T_ref = haskey(kwargs, :T_ref) ? kwargs[:T_ref] : 1.0 + return Gas(Kn, Pr, K, γ, ω, αᵣ, ωᵣ, μᵣ, T_ref) +end diff --git a/src/IO/Check.jl b/src/IO/Check.jl index 7f49a0e..a75b25b 100644 --- a/src/IO/Check.jl +++ b/src/IO/Check.jl @@ -2,9 +2,9 @@ $(SIGNATURES) Perform a check procedure. Simulation status will be output every `RES_CHECK_INTERVAL` steps. """ -function check!(i,ps4est,amr) +function check!(i, ps4est, amr) if amr.global_data.status.residual.step%RES_CHECK_INTERVAL==0 - max_vs_num,total_phase_num = check_vs_num(amr) + max_vs_num, total_phase_num = check_vs_num(amr) if MPI.Comm_rank(MPI.COMM_WORLD) == 0 i+=1 println("Iteration: $i") @@ -21,13 +21,13 @@ function check!(i,ps4est,amr) println("Total number of phase grids: $total_phase_num") end end - check_for_save!(ps4est,amr) + check_for_save!(ps4est, amr) end """ $(SIGNATURES) Start listening for the input from command line. Must be called before calling [`check_for_save!`](@ref). """ -function listen_for_save!(;rank=0) +function listen_for_save!(; rank = 0) if MPI.Comm_rank(MPI.COMM_WORLD)==rank Base.start_reading(stdin) end @@ -37,7 +37,7 @@ end $(SIGNATURES) Check whether `save` is input during the iteration. If the result is true, a saving process will be executed. """ -function check_for_save!(ps4est::P_pxest_t,amr;rank=0) +function check_for_save!(ps4est::P_pxest_t, amr; rank = 0) save_flag = amr.global_data.status.save_flag if MPI.Comm_rank(MPI.COMM_WORLD)==rank if bytesavailable(stdin)!=0 @@ -47,63 +47,81 @@ function check_for_save!(ps4est::P_pxest_t,amr;rank=0) end end end - MPI.Bcast!(save_flag,rank,MPI.COMM_WORLD) + MPI.Bcast!(save_flag, rank, MPI.COMM_WORLD) if save_flag[] == true MPI.Comm_rank(MPI.COMM_WORLD)==rank&&println("saving...") - save_result(ps4est,amr) + save_result(ps4est, amr) MPI.Comm_rank(MPI.COMM_WORLD)==rank&&println("done.") save_flag[] = false end return nothing end -function check_for_animsave!(ps4est::Ptr{p4est_t},amr;path="./animation") +function check_for_animsave!(ps4est::Ptr{p4est_t}, amr; path = "./animation") sim_time = amr.global_data.status.sim_time output = amr.global_data.config.output - if sim_time==0. - vertices,cells,point_solutions,solutions = pvtu_data(ps4est,amr,output.vtk_celltype) - ranks = ones(Int,size(solutions,1))*MPI.Comm_rank(MPI.COMM_WORLD) + if sim_time==0.0 + vertices, cells, point_solutions, solutions = + pvtu_data(ps4est, amr, output.vtk_celltype) + ranks = ones(Int, size(solutions, 1))*MPI.Comm_rank(MPI.COMM_WORLD) step = output.anim_index if MPI.Comm_rank(MPI.COMM_WORLD)==0 - paraview_collection(path*"/full_simulation";append=step!=0) do pvd - pvtk_grid(path*"/step$step",vertices,cells;part = MPI.Comm_rank(MPI.COMM_WORLD)+1,nparts = MPI.Comm_size(MPI.COMM_WORLD)) do pvtk - pvtk["rho"] = @views solutions[:,1] - pvtk["velocity"] = @views (solutions[:,2],solutions[:,3]) - pvtk["T"] = @views solutions[:,4] - pvtk["qf"] = (solutions[:,5],solutions[:,6]) + paraview_collection(path*"/full_simulation"; append = step!=0) do pvd + pvtk_grid( + path*"/step$step", + vertices, + cells; + part = MPI.Comm_rank(MPI.COMM_WORLD)+1, + nparts = MPI.Comm_size(MPI.COMM_WORLD), + ) do pvtk + pvtk["rho"] = @views solutions[:, 1] + pvtk["velocity"] = @views (solutions[:, 2], solutions[:, 3]) + pvtk["T"] = @views solutions[:, 4] + pvtk["qf"] = (solutions[:, 5], solutions[:, 6]) pvtk["mpi_rank"] = ranks - pvtk["rho",VTKPointData()] = @views point_solutions[:,1] - pvtk["velocity",VTKPointData()] = @views (point_solutions[:,2],point_solutions[:,3]) - pvtk["T",VTKPointData()] = @views point_solutions[:,4] - pvtk["qf",VTKPointData()] = (point_solutions[:,5],point_solutions[:,6]) + pvtk["rho", VTKPointData()] = @views point_solutions[:, 1] + pvtk["velocity", VTKPointData()] = + @views (point_solutions[:, 2], point_solutions[:, 3]) + pvtk["T", VTKPointData()] = @views point_solutions[:, 4] + pvtk["qf", VTKPointData()] = + (point_solutions[:, 5], point_solutions[:, 6]) pvd[sim_time] = pvtk close(pvd) end end else - pvtk_grid(path*"/step$step",vertices,cells;part = MPI.Comm_rank(MPI.COMM_WORLD)+1,nparts = MPI.Comm_size(MPI.COMM_WORLD)) do pvtk - pvtk["rho"] = @views solutions[:,1] - pvtk["velocity"] = @views (solutions[:,2],solutions[:,3]) - pvtk["T"] = @views solutions[:,4] - pvtk["qf"] = (solutions[:,5],solutions[:,6]) + pvtk_grid( + path*"/step$step", + vertices, + cells; + part = MPI.Comm_rank(MPI.COMM_WORLD)+1, + nparts = MPI.Comm_size(MPI.COMM_WORLD), + ) do pvtk + pvtk["rho"] = @views solutions[:, 1] + pvtk["velocity"] = @views (solutions[:, 2], solutions[:, 3]) + pvtk["T"] = @views solutions[:, 4] + pvtk["qf"] = (solutions[:, 5], solutions[:, 6]) pvtk["mpi_rank"] = ranks - pvtk["rho",VTKPointData()] = @views point_solutions[:,1] - pvtk["velocity",VTKPointData()] = @views (point_solutions[:,2],point_solutions[:,3]) - pvtk["T",VTKPointData()] = @views point_solutions[:,4] - pvtk["qf",VTKPointData()] = (point_solutions[:,5],point_solutions[:,6]) + pvtk["rho", VTKPointData()] = @views point_solutions[:, 1] + pvtk["velocity", VTKPointData()] = + @views (point_solutions[:, 2], point_solutions[:, 3]) + pvtk["T", VTKPointData()] = @views point_solutions[:, 4] + pvtk["qf", VTKPointData()] = (point_solutions[:, 5], point_solutions[:, 6]) end end if output.vs_output_criterion!=null_udf trees = amr.field.trees.data for tree in trees for ps_data in tree - (isa(ps_data,InsideSolidData)||ps_data.bound_enc<0)&&continue - id,flag = output.vs_output_criterion(;ps_data,amr) + (isa(ps_data, InsideSolidData)||ps_data.bound_enc<0)&&continue + id, flag = output.vs_output_criterion(; ps_data, amr) if flag - vertices,cells,point_solutions,solutions = vtk_data(ps_data.vs_data,amr,output.vs_vtk_celltype) - paraview_collection(path*"/id$(id)vs";append=step!=0) do pvd - vtk_grid(path*"/id$(id)step$(step)vs",vertices,cells) do vtk + vertices, cells, point_solutions, solutions = + vtk_data(ps_data.vs_data, amr, output.vs_vtk_celltype) + paraview_collection(path*"/id$(id)vs"; append = step!=0) do pvd + vtk_grid(path*"/id$(id)step$(step)vs", vertices, cells) do vtk vtk["df"] = @views Tuple([v for v in eachcol(solutions)]) - vtk["df",VTKPointData()] = @views Tuple([v for v in eachcol(point_solutions)]) + vtk["df", VTKPointData()] = + @views Tuple([v for v in eachcol(point_solutions)]) pvd[sim_time] = vtk close(pvd) end @@ -112,51 +130,69 @@ function check_for_animsave!(ps4est::Ptr{p4est_t},amr;path="./animation") end end end - elseif div(sim_time,output.anim_dt)==output.anim_index+1 - vertices,cells,point_solutions,solutions = pvtu_data(ps4est,amr,output.vtk_celltype) - ranks = ones(Int,size(solutions,1))*MPI.Comm_rank(MPI.COMM_WORLD) + elseif div(sim_time, output.anim_dt)==output.anim_index+1 + vertices, cells, point_solutions, solutions = + pvtu_data(ps4est, amr, output.vtk_celltype) + ranks = ones(Int, size(solutions, 1))*MPI.Comm_rank(MPI.COMM_WORLD) step = output.anim_index+1 if MPI.Comm_rank(MPI.COMM_WORLD)==0 - paraview_collection(path*"/full_simulation";append=step!=1) do pvd - pvtk_grid(path*"/step$step",vertices,cells;part = MPI.Comm_rank(MPI.COMM_WORLD)+1,nparts = MPI.Comm_size(MPI.COMM_WORLD)) do pvtk - pvtk["rho"] = @views solutions[:,1] - pvtk["velocity"] = @views (solutions[:,2],solutions[:,3]) - pvtk["T"] = @views solutions[:,4] - pvtk["qf"] = (solutions[:,5],solutions[:,6]) + paraview_collection(path*"/full_simulation"; append = step!=1) do pvd + pvtk_grid( + path*"/step$step", + vertices, + cells; + part = MPI.Comm_rank(MPI.COMM_WORLD)+1, + nparts = MPI.Comm_size(MPI.COMM_WORLD), + ) do pvtk + pvtk["rho"] = @views solutions[:, 1] + pvtk["velocity"] = @views (solutions[:, 2], solutions[:, 3]) + pvtk["T"] = @views solutions[:, 4] + pvtk["qf"] = (solutions[:, 5], solutions[:, 6]) pvtk["mpi_rank"] = ranks - pvtk["rho",VTKPointData()] = @views point_solutions[:,1] - pvtk["velocity",VTKPointData()] = @views (point_solutions[:,2],point_solutions[:,3]) - pvtk["T",VTKPointData()] = @views point_solutions[:,4] - pvtk["qf",VTKPointData()] = (point_solutions[:,5],point_solutions[:,6]) + pvtk["rho", VTKPointData()] = @views point_solutions[:, 1] + pvtk["velocity", VTKPointData()] = + @views (point_solutions[:, 2], point_solutions[:, 3]) + pvtk["T", VTKPointData()] = @views point_solutions[:, 4] + pvtk["qf", VTKPointData()] = + (point_solutions[:, 5], point_solutions[:, 6]) pvd[sim_time] = pvtk close(pvd) end end else - pvtk_grid(path*"/step$step",vertices,cells;part = MPI.Comm_rank(MPI.COMM_WORLD)+1,nparts = MPI.Comm_size(MPI.COMM_WORLD)) do pvtk - pvtk["rho"] = @views solutions[:,1] - pvtk["velocity"] = @views (solutions[:,2],solutions[:,3]) - pvtk["T"] = @views solutions[:,4] - pvtk["qf"] = (solutions[:,5],solutions[:,6]) + pvtk_grid( + path*"/step$step", + vertices, + cells; + part = MPI.Comm_rank(MPI.COMM_WORLD)+1, + nparts = MPI.Comm_size(MPI.COMM_WORLD), + ) do pvtk + pvtk["rho"] = @views solutions[:, 1] + pvtk["velocity"] = @views (solutions[:, 2], solutions[:, 3]) + pvtk["T"] = @views solutions[:, 4] + pvtk["qf"] = (solutions[:, 5], solutions[:, 6]) pvtk["mpi_rank"] = ranks - pvtk["rho",VTKPointData()] = @views point_solutions[:,1] - pvtk["velocity",VTKPointData()] = @views (point_solutions[:,2],point_solutions[:,3]) - pvtk["T",VTKPointData()] = @views point_solutions[:,4] - pvtk["qf",VTKPointData()] = (point_solutions[:,5],point_solutions[:,6]) + pvtk["rho", VTKPointData()] = @views point_solutions[:, 1] + pvtk["velocity", VTKPointData()] = + @views (point_solutions[:, 2], point_solutions[:, 3]) + pvtk["T", VTKPointData()] = @views point_solutions[:, 4] + pvtk["qf", VTKPointData()] = (point_solutions[:, 5], point_solutions[:, 6]) end end if output.vs_output_criterion!=null_udf trees = amr.field.trees.data for tree in trees for ps_data in tree - (isa(ps_data,InsideSolidData)||ps_data.bound_enc<0)&&continue - id,flag = output.vs_output_criterion(;ps_data,amr) + (isa(ps_data, InsideSolidData)||ps_data.bound_enc<0)&&continue + id, flag = output.vs_output_criterion(; ps_data, amr) if flag - vertices,cells,point_solutions,solutions = vtk_data(ps_data.vs_data,amr,output.vs_vtk_celltype) - paraview_collection(path*"/id$(id)vs";append=step!=1) do pvd - vtk_grid(path*"/id$(id)step$(step)vs",vertices,cells) do vtk + vertices, cells, point_solutions, solutions = + vtk_data(ps_data.vs_data, amr, output.vs_vtk_celltype) + paraview_collection(path*"/id$(id)vs"; append = step!=1) do pvd + vtk_grid(path*"/id$(id)step$(step)vs", vertices, cells) do vtk vtk["df"] = @views Tuple([v for v in eachcol(solutions)]) - vtk["df",VTKPointData()] = @views Tuple([v for v in eachcol(point_solutions)]) + vtk["df", VTKPointData()] = + @views Tuple([v for v in eachcol(point_solutions)]) pvd[sim_time] = vtk close(pvd) end @@ -171,38 +207,22 @@ end function check_vs_num(amr::KitAMR_Data) trees = amr.field.trees.data - buffer = zeros(Int,2) # [max,total] + buffer = zeros(Int, 2) # [max,total] for tree in trees for ps_data in tree - isa(ps_data,InsideSolidData)&&continue + isa(ps_data, InsideSolidData)&&continue ps_data.bound_enc<0&&continue vs_num = ps_data.vs_data.vs_num - buffer[1] = max(buffer[1],vs_num) + buffer[1] = max(buffer[1], vs_num) buffer[2] += vs_num end end if MPI.Comm_rank(MPI.COMM_WORLD)==0 - buffer[1] = MPI.Reduce(buffer[1],(x,y)->( - max(x,y) - ), - MPI.COMM_WORLD - ) - buffer[2] = MPI.Reduce(buffer[1],(x,y)->( - x+y - ), - MPI.COMM_WORLD - ) + buffer[1] = MPI.Reduce(buffer[1], (x, y)->(max(x, y)), MPI.COMM_WORLD) + buffer[2] = MPI.Reduce(buffer[1], (x, y)->(x+y), MPI.COMM_WORLD) else - MPI.Reduce(buffer[1],(x,y)->( - max(x,y) - ), - MPI.COMM_WORLD - ) - MPI.Reduce(buffer[2],(x,y)->( - x+y - ), - MPI.COMM_WORLD - ) + MPI.Reduce(buffer[1], (x, y)->(max(x, y)), MPI.COMM_WORLD) + MPI.Reduce(buffer[2], (x, y)->(x+y), MPI.COMM_WORLD) end return buffer -end \ No newline at end of file +end diff --git a/src/IO/IO.jl b/src/IO/IO.jl index c8822f6..1682f34 100644 --- a/src/IO/IO.jl +++ b/src/IO/IO.jl @@ -7,8 +7,8 @@ export read_config, save_result, listen_for_save!, check_for_save!, check! function string_to_Cstring(s::String) t = codeunits(s) p = Ptr{Cstring}(malloc(sizeof(UInt8)*(length(t)+1))) - ap = Base.unsafe_wrap(Vector{UInt8},Ptr{UInt8}(p),length(t)+1) - ap[1:end-1] .= t + ap = Base.unsafe_wrap(Vector{UInt8}, Ptr{UInt8}(p), length(t)+1) + ap[1:(end-1)] .= t ap[end] = 0 return p end diff --git a/src/IO/Input.jl b/src/IO/Input.jl index 17477f3..bbc1bc8 100644 --- a/src/IO/Input.jl +++ b/src/IO/Input.jl @@ -7,7 +7,7 @@ function read_config(filename::AbstractString) @info "reading config from $filename" println("--------------------------------------------------------------") end - f = open(filename,"r";lock = false) + f = open(filename, "r"; lock = false) config_dict = Dict{Symbol,Any}() for line in eachline(f) if length(line) == 0 || line[1] == '#' @@ -27,4 +27,4 @@ function read_config(filename::AbstractString) end close(f) return config_dict -end \ No newline at end of file +end diff --git a/src/IO/Output.jl b/src/IO/Output.jl index 124e13c..79142ce 100644 --- a/src/IO/Output.jl +++ b/src/IO/Output.jl @@ -6,23 +6,29 @@ end write_VTK(ps4est,"testT",["T"],fieldvalues_fn) =# -function write_VTK(ps4est::Ptr{p4est_t},filename::String,fieldnames::Vector{String},fieldvalues_fn) - p4est_geo = p4est_geometry_new_connectivity(pointer(PointerWrapper(ps4est).connectivity)) - cont = p4est_vtk_context_new(ps4est,filename) - p4est_vtk_context_set_geom(cont,p4est_geo) - p4est_vtk_context_set_continuous(cont,1) +function write_VTK( + ps4est::Ptr{p4est_t}, + filename::String, + fieldnames::Vector{String}, + fieldvalues_fn, +) + p4est_geo = + p4est_geometry_new_connectivity(pointer(PointerWrapper(ps4est).connectivity)) + cont = p4est_vtk_context_new(ps4est, filename) + p4est_vtk_context_set_geom(cont, p4est_geo) + p4est_vtk_context_set_continuous(cont, 1) cont = p4est_vtk_write_header(cont) fp = PointerWrapper(ps4est) num_quads = fp.local_num_quadrants[] - ps = Vector{Ptr{Nothing}}(undef,length(fieldnames)) - pas = Vector{Vector{Cdouble}}(undef,length(fieldnames)) - pscs = Vector{Ptr{sc_array_t}}(undef,length(fieldnames)) + ps = Vector{Ptr{Nothing}}(undef, length(fieldnames)) + pas = Vector{Vector{Cdouble}}(undef, length(fieldnames)) + pscs = Vector{Ptr{sc_array_t}}(undef, length(fieldnames)) for i in eachindex(fieldnames) - ps[i] = sc_malloc(P4est.package_id(),num_quads*8) - pas[i] = unsafe_wrap(Vector{Cdouble},Ptr{Cdouble}(ps[i]),num_quads) - pscs[i] = sc_array_new_data(ps[i],8,num_quads) + ps[i] = sc_malloc(P4est.package_id(), num_quads*8) + pas[i] = unsafe_wrap(Vector{Cdouble}, Ptr{Cdouble}(ps[i]), num_quads) + pscs[i] = sc_array_new_data(ps[i], 8, num_quads) end - function init_cell_data_kernel(ip,data,dp) + function init_cell_data_kernel(ip, data, dp) pas = unsafe_pointer_to_objref(data) qid = local_quadid(ip)+1 ps_data = Base.unsafe_pointer_to_objref(pointer(dp.ps_data)) @@ -31,49 +37,49 @@ function write_VTK(ps4est::Ptr{p4est_t},filename::String,fieldnames::Vector{Stri pas[i][qid] = fieldvalues[i] end end - function init_cell_data(info,data) + function init_cell_data(info, data) AMR_volume_iterate(info, data, P4est_PS_Data, init_cell_data_kernel) end ppas = pointer_from_objref(pas) cfn = @cfunction($init_cell_data, Cvoid, (Ptr{p4est_iter_volume_info}, Ptr{Nothing})) # explicit cfn to avoid closure error on Windows and MacOS platforms. - GC.@preserve ps4est ppas pas p4est_iterate( - ps4est, - C_NULL, - ppas, - cfn, - C_NULL, - C_NULL, - ) - pairs = Vector{Union{Ptr{Cstring},Ptr{sc_array_t}}}(undef,2*length(fieldnames)) - p_names = Vector{Ptr{Cstring}}(undef,length(fieldnames)) + GC.@preserve ps4est ppas pas p4est_iterate(ps4est, C_NULL, ppas, cfn, C_NULL, C_NULL) + pairs = Vector{Union{Ptr{Cstring},Ptr{sc_array_t}}}(undef, 2*length(fieldnames)) + p_names = Vector{Ptr{Cstring}}(undef, length(fieldnames)) for i in eachindex(fieldnames) pairs[2*i-1] = p_names[i] = string_to_Cstring(fieldnames[i]) pairs[2*i] = pscs[i] end - cont = p4est_vtk_write_cell_dataf(cont,1,1,1,0,length(fieldnames),0,pairs...,cont) + cont = + p4est_vtk_write_cell_dataf(cont, 1, 1, 1, 0, length(fieldnames), 0, pairs..., cont) p4est_vtk_write_footer(cont) for i in eachindex(fieldnames) - sc_free(P4est.package_id(),Ptr{Nothing}(p_names[i])) - sc_free(P4est.package_id(),ps[i]) + sc_free(P4est.package_id(), Ptr{Nothing}(p_names[i])) + sc_free(P4est.package_id(), ps[i]) end end -function write_VTK(ps4est::Ptr{p8est_t},filename::String,fieldnames::Vector{String},fieldvalues_fn) - p4est_geo = p8est_geometry_new_connectivity(pointer(PointerWrapper(ps4est).connectivity)) - cont = p8est_vtk_context_new(ps4est,filename) - p8est_vtk_context_set_geom(cont,p4est_geo) - p8est_vtk_context_set_continuous(cont,1) +function write_VTK( + ps4est::Ptr{p8est_t}, + filename::String, + fieldnames::Vector{String}, + fieldvalues_fn, +) + p4est_geo = + p8est_geometry_new_connectivity(pointer(PointerWrapper(ps4est).connectivity)) + cont = p8est_vtk_context_new(ps4est, filename) + p8est_vtk_context_set_geom(cont, p4est_geo) + p8est_vtk_context_set_continuous(cont, 1) cont = p8est_vtk_write_header(cont) fp = PointerWrapper(ps4est) num_quads = fp.local_num_quadrants[] - ps = Vector{Ptr{Nothing}}(undef,length(fieldnames)) - pas = Vector{Vector{Cdouble}}(undef,length(fieldnames)) - pscs = Vector{Ptr{sc_array_t}}(undef,length(fieldnames)) + ps = Vector{Ptr{Nothing}}(undef, length(fieldnames)) + pas = Vector{Vector{Cdouble}}(undef, length(fieldnames)) + pscs = Vector{Ptr{sc_array_t}}(undef, length(fieldnames)) for i in eachindex(fieldnames) - ps[i] = sc_malloc(P4est.package_id(),num_quads*8) - pas[i] = unsafe_wrap(Vector{Cdouble},Ptr{Cdouble}(ps[i]),num_quads) - pscs[i] = sc_array_new_data(ps[i],8,num_quads) + ps[i] = sc_malloc(P4est.package_id(), num_quads*8) + pas[i] = unsafe_wrap(Vector{Cdouble}, Ptr{Cdouble}(ps[i]), num_quads) + pscs[i] = sc_array_new_data(ps[i], 8, num_quads) end - function init_cell_data_kernel(ip,data,dp) + function init_cell_data_kernel(ip, data, dp) pas = unsafe_pointer_to_objref(data) qid = local_quadid(ip)+1 ps_data = Base.unsafe_pointer_to_objref(pointer(dp.ps_data)) @@ -82,7 +88,7 @@ function write_VTK(ps4est::Ptr{p8est_t},filename::String,fieldnames::Vector{Stri pas[i][qid] = fieldvalues[i] end end - function init_cell_data(info,data) + function init_cell_data(info, data) AMR_volume_iterate(info, data, P4est_PS_Data, init_cell_data_kernel) end ppas = pointer_from_objref(pas) @@ -96,42 +102,44 @@ function write_VTK(ps4est::Ptr{p8est_t},filename::String,fieldnames::Vector{Stri C_NULL, C_NULL, ) - pairs = Vector{Union{Ptr{Cstring},Ptr{sc_array_t}}}(undef,2*length(fieldnames)) - p_names = Vector{Ptr{Cstring}}(undef,length(fieldnames)) + pairs = Vector{Union{Ptr{Cstring},Ptr{sc_array_t}}}(undef, 2*length(fieldnames)) + p_names = Vector{Ptr{Cstring}}(undef, length(fieldnames)) for i in eachindex(fieldnames) pairs[2*i-1] = p_names[i] = string_to_Cstring(fieldnames[i]) pairs[2*i] = pscs[i] end - cont = p8est_vtk_write_cell_dataf(cont,1,1,1,0,length(fieldnames),0,pairs...,cont) + cont = + p8est_vtk_write_cell_dataf(cont, 1, 1, 1, 0, length(fieldnames), 0, pairs..., cont) p8est_vtk_write_footer(cont) for i in eachindex(fieldnames) - sc_free(P4est.package_id(),Ptr{Nothing}(p_names[i])) - sc_free(P4est.package_id(),ps[i]) + sc_free(P4est.package_id(), Ptr{Nothing}(p_names[i])) + sc_free(P4est.package_id(), ps[i]) end end -function vtk_data(vs_data::VS_Data{2,NDF},amr,::Type{T}) where{NDF,T<:Pixel} +function vtk_data(vs_data::VS_Data{2,NDF}, amr, ::Type{T}) where {NDF,T<:Pixel} global_data = amr.global_data - xmin,xmax,ymin,ymax = global_data.config.quadrature - Nx,Ny = global_data.config.vs_trees_num + xmin, xmax, ymin, ymax = global_data.config.quadrature + Nx, Ny = global_data.config.vs_trees_num AMR_VS_MAXLEVEL = global_data.config.solver.AMR_VS_MAXLEVEL dx = (xmax - xmin) / Nx/2^AMR_VS_MAXLEVEL dy = (ymax - ymin) / Ny/2^AMR_VS_MAXLEVEL - D = [dx,dy] - vertices = Matrix{Float64}(undef,2,4*length(vs_data.level)) + D = [dx, dy] + vertices = Matrix{Float64}(undef, 2, 4*length(vs_data.level)) midpoint = vs_data.midpoint level = vs_data.level dlevel = -(vs_data.level .- AMR_VS_MAXLEVEL) - cells = Vector{MeshCell}(undef,length(level)) - solutions = vs_data.df;point_solutions = Matrix{Float64}(undef,4*vs_data.vs_num,NDF) + cells = Vector{MeshCell}(undef, length(level)) + solutions = vs_data.df; + point_solutions = Matrix{Float64}(undef, 4*vs_data.vs_num, NDF) for i in eachindex(level) - for j in 1:4 - @. vertices[:,(i-1)*4+j] = midpoint[i,:]+RMT[2][j]*2^dlevel[i]*D/2 - @views @. point_solutions[4*(i-1)+j,:] = vs_data.df[i,:] + for j = 1:4 + @. vertices[:, (i-1)*4+j] = midpoint[i, :]+RMT[2][j]*2^dlevel[i]*D/2 + @views @. point_solutions[4*(i-1)+j, :] = vs_data.df[i, :] end - cells[i] = MeshCell(VTKCellTypes.VTK_PIXEL,(1:4).+4*(i-1)) + cells[i] = MeshCell(VTKCellTypes.VTK_PIXEL, (1:4) .+ 4*(i-1)) end - return vertices,cells,point_solutions,solutions + return vertices, cells, point_solutions, solutions end #= example: @@ -139,94 +147,119 @@ function fieldvalues_fn(vs_data::VS_Data{3}) return [vs_data.df[:,1],vs_data.level] end =# -function write_vs_VTK(vs_data::AbstractVsData{2,2},amr::KitAMR_Data{2,2},filename::String,fieldnames::Vector{String},fieldvalues_fn) +function write_vs_VTK( + vs_data::AbstractVsData{2,2}, + amr::KitAMR_Data{2,2}, + filename::String, + fieldnames::Vector{String}, + fieldvalues_fn, +) global_data = amr.global_data - xmin,xmax,ymin,ymax = global_data.config.quadrature - Nx,Ny = global_data.config.vs_trees_num + xmin, xmax, ymin, ymax = global_data.config.quadrature + Nx, Ny = global_data.config.vs_trees_num AMR_VS_MAXLEVEL = global_data.config.solver.AMR_VS_MAXLEVEL dx = (xmax - xmin) / Nx/2^AMR_VS_MAXLEVEL dy = (ymax - ymin) / Ny/2^AMR_VS_MAXLEVEL - D = [dx,dy] - vertices = Matrix{Float64}(undef,2,4*length(vs_data.level)) + D = [dx, dy] + vertices = Matrix{Float64}(undef, 2, 4*length(vs_data.level)) midpoint = vs_data.midpoint level = vs_data.level dlevel = -(vs_data.level .- AMR_VS_MAXLEVEL) - cells = Vector{MeshCell}(undef,length(level)) + cells = Vector{MeshCell}(undef, length(level)) for i in eachindex(level) - for j in 1:4 - @. vertices[:,(i-1)*4+j] = midpoint[i,:]+RMT[2][j]*2^dlevel[i]*D/2 + for j = 1:4 + @. vertices[:, (i-1)*4+j] = midpoint[i, :]+RMT[2][j]*2^dlevel[i]*D/2 end - cells[i] = MeshCell(VTKCellTypes.VTK_PIXEL,(1:4).+4*(i-1)) + cells[i] = MeshCell(VTKCellTypes.VTK_PIXEL, (1:4) .+ 4*(i-1)) end - vtk_grid(filename,vertices,cells;append=false) do vtk + vtk_grid(filename, vertices, cells; append = false) do vtk cell_datas = fieldvalues_fn(vs_data) for i in eachindex(fieldnames) - vtk[fieldnames[i],VTKCellData()] = cell_datas[i] + vtk[fieldnames[i], VTKCellData()] = cell_datas[i] end end end -function write_vs_VTK(df::AbstractMatrix,vs_data::AbstractVsData{2,2},amr::KitAMR_Data{2,2},filename::String,fieldnames::Vector{String},fieldvalues_fn) +function write_vs_VTK( + df::AbstractMatrix, + vs_data::AbstractVsData{2,2}, + amr::KitAMR_Data{2,2}, + filename::String, + fieldnames::Vector{String}, + fieldvalues_fn, +) global_data = amr.global_data - xmin,xmax,ymin,ymax = global_data.config.quadrature - Nx,Ny = global_data.config.vs_trees_num + xmin, xmax, ymin, ymax = global_data.config.quadrature + Nx, Ny = global_data.config.vs_trees_num AMR_VS_MAXLEVEL = global_data.config.solver.AMR_VS_MAXLEVEL dx = (xmax - xmin) / Nx/2^AMR_VS_MAXLEVEL dy = (ymax - ymin) / Ny/2^AMR_VS_MAXLEVEL - D = [dx,dy] - vertices = Matrix{Float64}(undef,2,4*length(vs_data.level)) + D = [dx, dy] + vertices = Matrix{Float64}(undef, 2, 4*length(vs_data.level)) midpoint = vs_data.midpoint level = vs_data.level dlevel = -(vs_data.level .- AMR_VS_MAXLEVEL) - cells = Vector{MeshCell}(undef,length(level)) + cells = Vector{MeshCell}(undef, length(level)) for i in eachindex(level) - for j in 1:4 - @. vertices[:,(i-1)*4+j] = midpoint[i,:]+RMT[2][j]*2^dlevel[i]*D/2 + for j = 1:4 + @. vertices[:, (i-1)*4+j] = midpoint[i, :]+RMT[2][j]*2^dlevel[i]*D/2 end - cells[i] = MeshCell(VTKCellTypes.VTK_PIXEL,(1:4).+4*(i-1)) + cells[i] = MeshCell(VTKCellTypes.VTK_PIXEL, (1:4) .+ 4*(i-1)) end - vtk_grid(filename,vertices,cells;append=false) do vtk - cell_datas = fieldvalues_fn(vs_data,df) + vtk_grid(filename, vertices, cells; append = false) do vtk + cell_datas = fieldvalues_fn(vs_data, df) for i in eachindex(fieldnames) - vtk[fieldnames[i],VTKCellData()] = cell_datas[i] + vtk[fieldnames[i], VTKCellData()] = cell_datas[i] end end end -function write_vs_VTK(df::AbstractMatrix,vs_data::AbstractVsData{3,1},amr::KitAMR_Data{3,1},filename::String,fieldnames::Vector{String},fieldvalues_fn) +function write_vs_VTK( + df::AbstractMatrix, + vs_data::AbstractVsData{3,1}, + amr::KitAMR_Data{3,1}, + filename::String, + fieldnames::Vector{String}, + fieldvalues_fn, +) global_data = amr.global_data - xmin,xmax,ymin,ymax,zmin,zmax = global_data.config.quadrature - Nx,Ny,Nz = global_data.config.vs_trees_num + xmin, xmax, ymin, ymax, zmin, zmax = global_data.config.quadrature + Nx, Ny, Nz = global_data.config.vs_trees_num AMR_VS_MAXLEVEL = global_data.config.solver.AMR_VS_MAXLEVEL dx = (xmax - xmin) / Nx/2^AMR_VS_MAXLEVEL dy = (ymax - ymin) / Ny/2^AMR_VS_MAXLEVEL dz = (zmax - zmin) / Nz/2^AMR_VS_MAXLEVEL - D = [dx,dy,dz] - vertices = Matrix{Float64}(undef,3,8*length(vs_data.level)) + D = [dx, dy, dz] + vertices = Matrix{Float64}(undef, 3, 8*length(vs_data.level)) midpoint = vs_data.midpoint level = vs_data.level dlevel = -(vs_data.level .- AMR_VS_MAXLEVEL) - cells = Vector{MeshCell}(undef,length(level)) + cells = Vector{MeshCell}(undef, length(level)) for i in eachindex(level) - for j in 1:8 - @. vertices[:,(i-1)*8+j] = midpoint[i,:]+RMT[3][j]*2^dlevel[i]*D/2 + for j = 1:8 + @. vertices[:, (i-1)*8+j] = midpoint[i, :]+RMT[3][j]*2^dlevel[i]*D/2 end - cells[i] = MeshCell(VTKCellTypes.VTK_VOXEL,(1:8).+8*(i-1)) + cells[i] = MeshCell(VTKCellTypes.VTK_VOXEL, (1:8) .+ 8*(i-1)) end - vtk_grid(filename,vertices,cells;append=false) do vtk - cell_datas = fieldvalues_fn(vs_data,df) + vtk_grid(filename, vertices, cells; append = false) do vtk + cell_datas = fieldvalues_fn(vs_data, df) for i in eachindex(fieldnames) - vtk[fieldnames[i],VTKCellData()] = cell_datas[i] + vtk[fieldnames[i], VTKCellData()] = cell_datas[i] end end end -function neighbor_num(ps_data::PS_Data,::P_pxest_t,::KitAMR_Data,::Integer) +function neighbor_num(ps_data::PS_Data, ::P_pxest_t, ::KitAMR_Data, ::Integer) return abs.(ps_data.neighbor.state) end -function neighbor_num(::InsideSolidData,ps4est::P_pxest_t,amr::KitAMR_Data{DIM},quadid::Integer) where {DIM} - neighbor_num = Vector{Int}(undef,2*DIM) +function neighbor_num( + ::InsideSolidData, + ps4est::P_pxest_t, + amr::KitAMR_Data{DIM}, + quadid::Integer, +) where {DIM} + neighbor_num = Vector{Int}(undef, 2*DIM) global_data = amr.global_data ghost = global_data.forest.ghost mesh = global_data.forest.mesh - for dir = 1:2*DIM + for dir = 1:(2*DIM) neighbor_quads = sc_array_new(sizeof(P_pxest_quadrant_t)) neighbor_encs = sc_array_new(sizeof(Cint)) neighbor_qid = sc_array_new(sizeof(Cint)) @@ -247,27 +280,36 @@ function neighbor_num(::InsideSolidData,ps4est::P_pxest_t,amr::KitAMR_Data{DIM}, end return neighbor_num end -function save_vs_result(amr::KitAMR_Data{DIM,NDF};dir_path) where{DIM,NDF} +function save_vs_result(amr::KitAMR_Data{DIM,NDF}; dir_path) where {DIM,NDF} vs_solutions = VS_Solution[] vs_path = dir_path*"vs_result_"*string(MPI.Comm_rank(MPI.COMM_WORLD))*".jld2" for tree in amr.field.trees.data for ps_data in tree - (isa(ps_data,InsideSolidData)||ps_data.bound_enc<0)&&continue - x,y = ps_data.midpoint + (isa(ps_data, InsideSolidData)||ps_data.bound_enc<0)&&continue + x, y = ps_data.midpoint vs_data = ps_data.vs_data if x>-1.04-EPS&&x<-0.09+EPS&&y>-EPS&&y<0.11+EPS - push!(vs_solutions,VS_Solution(ps_data.quadid,ps_data.midpoint,vs_data.midpoint,vs_data.level,vs_data.df)) + push!( + vs_solutions, + VS_Solution( + ps_data.quadid, + ps_data.midpoint, + vs_data.midpoint, + vs_data.level, + vs_data.df, + ), + ) end end end - save_object(vs_path,vs_solutions) + save_object(vs_path, vs_solutions) end function load_vs_result(path) solverset = load_object(path*"/solverset.jld2") vs_result = VS_Solution[] for i = 1:solverset.mpi_size vr = load_object(path*"/vs_result_"*string(i-1)*".jld2") - append!(vs_result,vr) + append!(vs_result, vr) end return vs_result end @@ -276,14 +318,18 @@ end $(TYPEDSIGNATURES) Save all results to `dir_path`. If `isempty(dir_path)` is `true`, a folder named `result` will be made in current path. """ -function save_result(ps4est::Ptr{p4est_t},amr::KitAMR_Data{DIM,NDF};dir_path="") where{DIM,NDF} +function save_result( + ps4est::Ptr{p4est_t}, + amr::KitAMR_Data{DIM,NDF}; + dir_path = "", +) where {DIM,NDF} update_slope!(amr) - slope_exchange!(ps4est,amr) + slope_exchange!(ps4est, amr) update_solid_cell!(amr) - data_exchange!(ps4est,amr) + data_exchange!(ps4est, amr) fp = PointerWrapper(ps4est) - ps_solution = Vector{PS_Solution}(undef,fp.local_num_quadrants[]) - neighbor_nums = Vector{Vector{Int}}(undef,fp.local_num_quadrants[]) + ps_solution = Vector{PS_Solution}(undef, fp.local_num_quadrants[]) + neighbor_nums = Vector{Vector{Int}}(undef, fp.local_num_quadrants[]) trees = amr.field.trees.data config = amr.global_data.config index = 1 @@ -291,25 +337,25 @@ function save_result(ps4est::Ptr{p4est_t},amr::KitAMR_Data{DIM,NDF};dir_path="") for j in eachindex(trees[i]) ps_data = trees[i][j] ps_solution[index] = PS_Solution(ps_data) - neighbor_nums[index] = neighbor_num(ps_data,ps4est,amr,index-1) + neighbor_nums[index] = neighbor_num(ps_data, ps4est, amr, index-1) index+=1 end end solution = Solution(ps_solution) rank = MPI.Comm_rank(MPI.COMM_WORLD) - result = Result(solution,MeshInfo(neighbor_nums)) + result = Result(solution, MeshInfo(neighbor_nums)) if isempty(dir_path) if MPI.Comm_rank(MPI.COMM_WORLD)==0 dir_path = "./result"*Dates.format(now(), "yyyy-mm-dd_HH-MM")*"/" path_v = collect(dir_path) pl = length(path_v) - MPI.Bcast!([pl],0,MPI.COMM_WORLD) - MPI.Bcast!(path_v,0,MPI.COMM_WORLD) + MPI.Bcast!([pl], 0, MPI.COMM_WORLD) + MPI.Bcast!(path_v, 0, MPI.COMM_WORLD) else pl = [0] - MPI.Bcast!(pl,0,MPI.COMM_WORLD) - path_v = Vector{Char}(undef,first(pl)) - MPI.Bcast!(path_v,0,MPI.COMM_WORLD) + MPI.Bcast!(pl, 0, MPI.COMM_WORLD) + path_v = Vector{Char}(undef, first(pl)) + MPI.Bcast!(path_v, 0, MPI.COMM_WORLD) dir_path = String(path_v) end else @@ -322,26 +368,30 @@ function save_result(ps4est::Ptr{p4est_t},amr::KitAMR_Data{DIM,NDF};dir_path="") MPI.Barrier(MPI.COMM_WORLD) pro_path = pwd() cd(dir_path) - p4est_save_ext("p",ps4est,Cint(0),Cint(0)) + p4est_save_ext("p", ps4est, Cint(0), Cint(0)) cd(pro_path) if rank==0 size = MPI.Comm_size(MPI.COMM_WORLD) - solverset = SolverSet(ConfigureForSave(config),size) + solverset = SolverSet(ConfigureForSave(config), size) save_object(dir_path * "solverset.jld2", solverset) end - save_object(dir_path * "result_"*string(rank)*".jld2", result) - save_pvtu(dir_path*"vtk/field",ps4est,amr,amr.global_data.config.output.vtk_celltype) - save_vs_result(amr;dir_path) - save_boundary_result(dir_path,amr) + save_object(dir_path * "result_" * string(rank) * ".jld2", result) + save_pvtu(dir_path*"vtk/field", ps4est, amr, amr.global_data.config.output.vtk_celltype) + save_vs_result(amr; dir_path) + save_boundary_result(dir_path, amr) end -function save_result(ps4est::Ptr{p8est_t},amr::KitAMR_Data{DIM,NDF};dir_path="") where{DIM,NDF} +function save_result( + ps4est::Ptr{p8est_t}, + amr::KitAMR_Data{DIM,NDF}; + dir_path = "", +) where {DIM,NDF} update_slope!(amr) - slope_exchange!(ps4est,amr) + slope_exchange!(ps4est, amr) update_solid_cell!(amr) - data_exchange!(ps4est,amr) + data_exchange!(ps4est, amr) fp = PointerWrapper(ps4est) - ps_solution = Vector{PS_Solution}(undef,fp.local_num_quadrants[]) - neighbor_nums = Vector{Vector{Int}}(undef,fp.local_num_quadrants[]) + ps_solution = Vector{PS_Solution}(undef, fp.local_num_quadrants[]) + neighbor_nums = Vector{Vector{Int}}(undef, fp.local_num_quadrants[]) trees = amr.field.trees.data config = amr.global_data.config index = 1 @@ -354,19 +404,19 @@ function save_result(ps4est::Ptr{p8est_t},amr::KitAMR_Data{DIM,NDF};dir_path="") end solution = Solution(ps_solution) rank = MPI.Comm_rank(MPI.COMM_WORLD) - result = Result(solution,MeshInfo(Vector{Int}[])) + result = Result(solution, MeshInfo(Vector{Int}[])) if isempty(dir_path) if MPI.Comm_rank(MPI.COMM_WORLD)==0 dir_path = "./result"*Dates.format(now(), "yyyy-mm-dd_HH-MM")*"/" path_v = collect(dir_path) pl = length(path_v) - MPI.Bcast!([pl],0,MPI.COMM_WORLD) - MPI.Bcast!(path_v,0,MPI.COMM_WORLD) + MPI.Bcast!([pl], 0, MPI.COMM_WORLD) + MPI.Bcast!(path_v, 0, MPI.COMM_WORLD) else pl = [0] - MPI.Bcast!(pl,0,MPI.COMM_WORLD) - path_v = Vector{Char}(undef,first(pl)) - MPI.Bcast!(path_v,0,MPI.COMM_WORLD) + MPI.Bcast!(pl, 0, MPI.COMM_WORLD) + path_v = Vector{Char}(undef, first(pl)) + MPI.Bcast!(path_v, 0, MPI.COMM_WORLD) dir_path = String(path_v) end else @@ -379,360 +429,468 @@ function save_result(ps4est::Ptr{p8est_t},amr::KitAMR_Data{DIM,NDF};dir_path="") MPI.Barrier(MPI.COMM_WORLD) pro_path = pwd() cd(dir_path) - p4est_save_ext("p",ps4est,Cint(0),Cint(0)) + p4est_save_ext("p", ps4est, Cint(0), Cint(0)) cd(pro_path) if rank==0 size = MPI.Comm_size(MPI.COMM_WORLD) - solverset = SolverSet(ConfigureForSave(config),size) + solverset = SolverSet(ConfigureForSave(config), size) save_object(dir_path * "solverset.jld2", solverset) end - save_pvtu(dir_path*"vtk/field",ps4est,amr,amr.global_data.config.output.vtk_celltype) - save_object(dir_path * "result_"*string(rank)*".jld2", result) - save_boundary_result(dir_path,amr) + save_pvtu(dir_path*"vtk/field", ps4est, amr, amr.global_data.config.output.vtk_celltype) + save_object(dir_path * "result_" * string(rank) * ".jld2", result) + save_boundary_result(dir_path, amr) end -function save_pvtu(dir_path::String,p4est::Ptr{p4est_t},amr,celltype) +function save_pvtu(dir_path::String, p4est::Ptr{p4est_t}, amr, celltype) pp = PointerWrapper(p4est) gfq = Base.unsafe_wrap( Vector{Int}, pointer(pp.global_first_quadrant), MPI.Comm_size(MPI.COMM_WORLD) + 1, ) - nums = [gfq[i]-gfq[i-1] for i in 2:MPI.Comm_size(MPI.COMM_WORLD)+1] - nparts = length(findall(x->x>0,nums));part = length(findall(x->x>0,nums[1:MPI.Comm_rank(MPI.COMM_WORLD)+1])) - vertices,cells,point_solutions,solutions = pvtu_data(p4est,amr,celltype) - ranks = ones(Int,size(solutions,1))*MPI.Comm_rank(MPI.COMM_WORLD) + nums = [gfq[i]-gfq[i-1] for i = 2:(MPI.Comm_size(MPI.COMM_WORLD)+1)] + nparts = length(findall(x->x>0, nums)); + part = length(findall(x->x>0, nums[1:(MPI.Comm_rank(MPI.COMM_WORLD)+1)])) + vertices, cells, point_solutions, solutions = pvtu_data(p4est, amr, celltype) + ranks = ones(Int, size(solutions, 1))*MPI.Comm_rank(MPI.COMM_WORLD) if length(ranks)>0 - pvtk_grid(dir_path,vertices,cells;part = part,nparts = nparts) do pvtk - pvtk["rho"] = @views solutions[:,1] - pvtk["velocity"] = @views (solutions[:,2],solutions[:,3]) - pvtk["T"] = @views solutions[:,4] - pvtk["qf"] = (solutions[:,5],solutions[:,6]) + pvtk_grid(dir_path, vertices, cells; part = part, nparts = nparts) do pvtk + pvtk["rho"] = @views solutions[:, 1] + pvtk["velocity"] = @views (solutions[:, 2], solutions[:, 3]) + pvtk["T"] = @views solutions[:, 4] + pvtk["qf"] = (solutions[:, 5], solutions[:, 6]) pvtk["mpi_rank"] = ranks - pvtk["rho",VTKPointData()] = @views point_solutions[:,1] - pvtk["velocity",VTKPointData()] = @views (point_solutions[:,2],point_solutions[:,3]) - pvtk["T",VTKPointData()] = @views point_solutions[:,4] - pvtk["qf",VTKPointData()] = (point_solutions[:,5],point_solutions[:,6]) + pvtk["rho", VTKPointData()] = @views point_solutions[:, 1] + pvtk["velocity", VTKPointData()] = + @views (point_solutions[:, 2], point_solutions[:, 3]) + pvtk["T", VTKPointData()] = @views point_solutions[:, 4] + pvtk["qf", VTKPointData()] = (point_solutions[:, 5], point_solutions[:, 6]) end end end -function save_pvtu(dir_path::String,p4est::Ptr{p8est_t},amr,celltype) +function save_pvtu(dir_path::String, p4est::Ptr{p8est_t}, amr, celltype) pp = PointerWrapper(p4est) gfq = Base.unsafe_wrap( Vector{Int}, pointer(pp.global_first_quadrant), MPI.Comm_size(MPI.COMM_WORLD) + 1, ) - nums = [gfq[i]-gfq[i-1] for i in 2:MPI.Comm_size(MPI.COMM_WORLD)+1] - nparts = length(findall(x->x>0,nums));part = length(findall(x->x>0,nums[1:MPI.Comm_rank(MPI.COMM_WORLD)+1])) - vertices,cells,point_solutions,solutions = pvtu_data(p4est,amr,celltype) - ranks = ones(Int,size(solutions,1))*MPI.Comm_rank(MPI.COMM_WORLD) - if size(solutions,1)>0 - pvtk_grid(dir_path,vertices,cells;part = part,nparts = nparts) do pvtk - pvtk["rho"] = @views solutions[:,1] - pvtk["velocity"] = @views (solutions[:,2],solutions[:,3],solutions[:,4]) - pvtk["T"] = @views solutions[:,5] - pvtk["qf"] = (solutions[:,6],solutions[:,7],solutions[:,8]) + nums = [gfq[i]-gfq[i-1] for i = 2:(MPI.Comm_size(MPI.COMM_WORLD)+1)] + nparts = length(findall(x->x>0, nums)); + part = length(findall(x->x>0, nums[1:(MPI.Comm_rank(MPI.COMM_WORLD)+1)])) + vertices, cells, point_solutions, solutions = pvtu_data(p4est, amr, celltype) + ranks = ones(Int, size(solutions, 1))*MPI.Comm_rank(MPI.COMM_WORLD) + if size(solutions, 1)>0 + pvtk_grid(dir_path, vertices, cells; part = part, nparts = nparts) do pvtk + pvtk["rho"] = @views solutions[:, 1] + pvtk["velocity"] = @views (solutions[:, 2], solutions[:, 3], solutions[:, 4]) + pvtk["T"] = @views solutions[:, 5] + pvtk["qf"] = (solutions[:, 6], solutions[:, 7], solutions[:, 8]) pvtk["mpi_rank"] = ranks - pvtk["rho",VTKPointData()] = @views point_solutions[:,1] - pvtk["velocity",VTKPointData()] = @views (point_solutions[:,2],point_solutions[:,3],point_solutions[:,4]) - pvtk["T",VTKPointData()] = @views point_solutions[:,5] - pvtk["qf",VTKPointData()] = (point_solutions[:,6],point_solutions[:,7],point_solutions[:,8]) + pvtk["rho", VTKPointData()] = @views point_solutions[:, 1] + pvtk["velocity", VTKPointData()] = + @views (point_solutions[:, 2], point_solutions[:, 3], point_solutions[:, 4]) + pvtk["T", VTKPointData()] = @views point_solutions[:, 5] + pvtk["qf", VTKPointData()] = + (point_solutions[:, 6], point_solutions[:, 7], point_solutions[:, 8]) end end end -function pvtu_data(p4est,amr,::Type{T}) where{T<:Triangle} +function pvtu_data(p4est, amr, ::Type{T}) where {T<:Triangle} N = PointerWrapper(p4est).local_num_quadrants[] - tb = Vector{SVector{2,Float64}}(undef,4) - tb[1] = @SVector [-1.,-1.];tb[2] = @SVector [1.,-1.];tb[3] = @SVector [1.,1.];tb[4] = @SVector [-1.,1.] - ptb = Vector{SVector{3,Int}}(undef,4)# pixel-triangle vertices table - ptb[1] = @SVector [1,2,5];ptb[2] = @SVector [2,3,5];ptb[3] = @SVector [3,4,5];ptb[4] = @SVector [1,4,5] - vertices = Matrix{Float64}(undef,2,5*N) - cells = Vector{MeshCell}(undef,4*N) - levels = Vector{Int8}(undef,N) + tb = Vector{SVector{2,Float64}}(undef, 4) + tb[1] = @SVector [-1.0, -1.0]; + tb[2] = @SVector [1.0, -1.0]; + tb[3] = @SVector [1.0, 1.0]; + tb[4] = @SVector [-1.0, 1.0] + ptb = Vector{SVector{3,Int}}(undef, 4)# pixel-triangle vertices table + ptb[1] = @SVector [1, 2, 5]; + ptb[2] = @SVector [2, 3, 5]; + ptb[3] = @SVector [3, 4, 5]; + ptb[4] = @SVector [1, 4, 5] + vertices = Matrix{Float64}(undef, 2, 5*N) + cells = Vector{MeshCell}(undef, 4*N) + levels = Vector{Int8}(undef, N) index = 1 - data = [index,vertices,cells,levels] + data = [index, vertices, cells, levels] p_data = pointer_from_objref(data) - GC.@preserve data AMR_volume_iterate(p4est;user_data = p_data) do ip,data,dp - d = unsafe_pointer_to_objref(data);index,vertices,cells = d + GC.@preserve data AMR_volume_iterate(p4est; user_data = p_data) do ip, data, dp + d = unsafe_pointer_to_objref(data); + index, vertices, cells = d ps_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - if isa(ps_data,InsideSolidData) - ds, midpoint = quad_to_cell(ip.p4est,ip.treeid[],ip.quad) + if isa(ps_data, InsideSolidData) + ds, midpoint = quad_to_cell(ip.p4est, ip.treeid[], ip.quad) else ds = ps_data.ds midpoint = ps_data.midpoint end - for i in 1:4 - @. vertices[:,(index-1)*5+i] = midpoint+tb[i]/2*ds + for i = 1:4 + @. vertices[:, (index-1)*5+i] = midpoint+tb[i]/2*ds end - vertices[:,5*index] .= midpoint + vertices[:, 5*index] .= midpoint for i in eachindex(ptb) - cells[4*(index-1)+i] = MeshCell(VTKCellTypes.VTK_TRIANGLE,ptb[i].+5*(index-1)) + cells[4*(index-1)+i] = + MeshCell(VTKCellTypes.VTK_TRIANGLE, ptb[i] .+ 5*(index-1)) end levels[index] = ip.quad.level[] d[1]+=1 end - solutions = Matrix{Float64}(undef,4*N,6) - point_solutions = Matrix{Float64}(undef,5*N,6) + solutions = Matrix{Float64}(undef, 4*N, 6) + point_solutions = Matrix{Float64}(undef, 5*N, 6) # bound_encs = Vector{Float64}(undef,N) index = 1 for tree in amr.field.trees.data for ps_data in tree - if isa(ps_data,InsideSolidData)||ps_data.bound_enc<0 - solutions[4*(index-1)+1:4*index,:].=NaN - point_solutions[5*(index-1)+1:5*index,:] .= NaN + if isa(ps_data, InsideSolidData)||ps_data.bound_enc<0 + solutions[(4*(index-1)+1):(4*index), :].=NaN + point_solutions[(5*(index-1)+1):(5*index), :] .= NaN else - for i in 1:4 - solutions[4*(index-1)+i,1] = ps_data.prim[1] - @views solutions[4*(index-1)+i,2:3] .= ps_data.prim[2:3] - solutions[4*(index-1)+i,4] = 1.0/ps_data.prim[end] - @views solutions[4*(index-1)+i,5:6] .= ps_data.qf + for i = 1:4 + solutions[4*(index-1)+i, 1] = ps_data.prim[1] + @views solutions[4*(index-1)+i, 2:3] .= ps_data.prim[2:3] + solutions[4*(index-1)+i, 4] = 1.0/ps_data.prim[end] + @views solutions[4*(index-1)+i, 5:6] .= ps_data.qf end - + vs_data = ps_data.vs_data - β = @views [min(abs(vs_data.df[i,j]/(0.5*dot(ps_data.ds,abs.(vs_data.sdf[i,j,:]))+EPS)),1.) for i in axes(vs_data.df,1), j in axes(vs_data.df,2)] + β = @views [ + min( + abs( + vs_data.df[ + i, + j, + ]/(0.5*dot(ps_data.ds, abs.(vs_data.sdf[i, j, :]))+EPS), + ), + 1.0, + ) for i in axes(vs_data.df, 1), j in axes(vs_data.df, 2) + ] point_df = similar(vs_data.df) - for i in 1:4 + for i = 1:4 df = vs_data.df sdf = vs_data.sdf - dx = 0.5*ps_data.ds.*tb[i] - point_df .= @views df+[β[i,j]*dot(sdf[i,j,:],dx) for i in axes(df,1), j in axes(df,2)] - w = calc_w0(vs_data.midpoint,point_df,vs_data.weight,amr.global_data) - prim = get_prim(w,amr.global_data) - qf = calc_qf(vs_data.midpoint,point_df,vs_data.weight,prim,amr.global_data) - point_solutions[5*(index-1)+i,1] = prim[1] - @views point_solutions[5*(index-1)+i,2:3] .= prim[2:3] - point_solutions[5*(index-1)+i,4] = 1.0/prim[end] - @views point_solutions[5*(index-1)+i,5:6] .= qf + dx = 0.5*ps_data.ds .* tb[i] + point_df .= @views df+[ + β[i, j]*dot(sdf[i, j, :], dx) for i in axes(df, 1), j in axes(df, 2) + ] + w = calc_w0(vs_data.midpoint, point_df, vs_data.weight, amr.global_data) + prim = get_prim(w, amr.global_data) + qf = calc_qf( + vs_data.midpoint, + point_df, + vs_data.weight, + prim, + amr.global_data, + ) + point_solutions[5*(index-1)+i, 1] = prim[1] + @views point_solutions[5*(index-1)+i, 2:3] .= prim[2:3] + point_solutions[5*(index-1)+i, 4] = 1.0/prim[end] + @views point_solutions[5*(index-1)+i, 5:6] .= qf end - point_solutions[5*index,1] = ps_data.prim[1] - @views point_solutions[5*index,2:3] .= ps_data.prim[2:3] - point_solutions[5*index,4] = 1.0/ps_data.prim[end] - @views point_solutions[5*index,5:6] .= ps_data.qf + point_solutions[5*index, 1] = ps_data.prim[1] + @views point_solutions[5*index, 2:3] .= ps_data.prim[2:3] + point_solutions[5*index, 4] = 1.0/ps_data.prim[end] + @views point_solutions[5*index, 5:6] .= ps_data.qf end index += 1 end end - return vertices,cells,point_solutions,solutions + return vertices, cells, point_solutions, solutions end -function pvtu_data(p4est,amr,::Type{T}) where{T<:Pixel} +function pvtu_data(p4est, amr, ::Type{T}) where {T<:Pixel} N = PointerWrapper(p4est).local_num_quadrants[] - tb = Vector{SVector{2,Float64}}(undef,4) - tb[1] = @SVector [-1.,-1.];tb[2] = @SVector [1.,-1.];tb[3] = @SVector [-1.,1.];tb[4] = @SVector [1.,1.] - vertices = Matrix{Float64}(undef,2,4*N) - cells = Vector{MeshCell}(undef,N) - levels = Vector{Int8}(undef,N) + tb = Vector{SVector{2,Float64}}(undef, 4) + tb[1] = @SVector [-1.0, -1.0]; + tb[2] = @SVector [1.0, -1.0]; + tb[3] = @SVector [-1.0, 1.0]; + tb[4] = @SVector [1.0, 1.0] + vertices = Matrix{Float64}(undef, 2, 4*N) + cells = Vector{MeshCell}(undef, N) + levels = Vector{Int8}(undef, N) index = 1 - data = [index,vertices,cells,levels] + data = [index, vertices, cells, levels] p_data = pointer_from_objref(data) - GC.@preserve data AMR_volume_iterate(p4est;user_data = p_data) do ip,data,dp - d = unsafe_pointer_to_objref(data);index,vertices,cells = d + GC.@preserve data AMR_volume_iterate(p4est; user_data = p_data) do ip, data, dp + d = unsafe_pointer_to_objref(data); + index, vertices, cells = d ps_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - if isa(ps_data,InsideSolidData) - ds, midpoint = quad_to_cell(ip.p4est,ip.treeid[],ip.quad) + if isa(ps_data, InsideSolidData) + ds, midpoint = quad_to_cell(ip.p4est, ip.treeid[], ip.quad) else ds = ps_data.ds midpoint = ps_data.midpoint end - for i in 1:4 - @. vertices[:,(index-1)*4+i] = midpoint+tb[i]/2*ds + for i = 1:4 + @. vertices[:, (index-1)*4+i] = midpoint+tb[i]/2*ds end - cells[index] = MeshCell(VTKCellTypes.VTK_PIXEL,(1:4).+4*(index-1)) + cells[index] = MeshCell(VTKCellTypes.VTK_PIXEL, (1:4) .+ 4*(index-1)) levels[index] = ip.quad.level[] d[1]+=1 end - solutions = Matrix{Float64}(undef,N,6) - point_solutions = Matrix{Float64}(undef,4*N,6) + solutions = Matrix{Float64}(undef, N, 6) + point_solutions = Matrix{Float64}(undef, 4*N, 6) index = 1 for tree in amr.field.trees.data for ps_data in tree - if isa(ps_data,InsideSolidData)||ps_data.bound_enc<0 - solutions[index,:].=NaN - point_solutions[4*(index-1)+1:4*index,:] .= NaN + if isa(ps_data, InsideSolidData)||ps_data.bound_enc<0 + solutions[index, :].=NaN + point_solutions[(4*(index-1)+1):(4*index), :] .= NaN else - solutions[index,1] = ps_data.prim[1] - @views solutions[index,2:3] .= ps_data.prim[2:3] - solutions[index,4] = 1.0/ps_data.prim[end] - @views solutions[index,5:6] .= ps_data.qf - for i in 1:4 - point_solutions[4*(index-1)+i,1] = ps_data.prim[1] - @views point_solutions[4*(index-1)+i,2:3] .= ps_data.prim[2:3] - point_solutions[4*(index-1)+i,4] = 1.0/ps_data.prim[end] - @views point_solutions[4*(index-1)+i,5:6] .= ps_data.qf + solutions[index, 1] = ps_data.prim[1] + @views solutions[index, 2:3] .= ps_data.prim[2:3] + solutions[index, 4] = 1.0/ps_data.prim[end] + @views solutions[index, 5:6] .= ps_data.qf + for i = 1:4 + point_solutions[4*(index-1)+i, 1] = ps_data.prim[1] + @views point_solutions[4*(index-1)+i, 2:3] .= ps_data.prim[2:3] + point_solutions[4*(index-1)+i, 4] = 1.0/ps_data.prim[end] + @views point_solutions[4*(index-1)+i, 5:6] .= ps_data.qf end end index += 1 end end - return vertices,cells,point_solutions,solutions + return vertices, cells, point_solutions, solutions end -function pvtu_data(p4est,amr,::Type{T}) where{T<:Tetra} +function pvtu_data(p4est, amr, ::Type{T}) where {T<:Tetra} N = PointerWrapper(p4est).local_num_quadrants[] - tb = Vector{SVector{3,Float64}}(undef,14) - tb[1] = @SVector [-1.,-1.,-1.];tb[2] = @SVector [1.,-1.,-1.];tb[3] = @SVector [1.,1.,-1.];tb[4] = @SVector [-1.,1.,-1.] - tb[5] = @SVector [-1.,-1.,1.];tb[6] = @SVector [1.,-1.,1.];tb[7] = @SVector [1.,1.,1.];tb[8] = @SVector [-1.,1.,1.] - tb[9] = @SVector [-1.,0.,0.];tb[10] = @SVector [1.,0.,0.]; tb[11] = @SVector [0.,-1.,0.];tb[12] = @SVector [0.,1.,0.] - tb[13] = @SVector [0.,0.,-1.];tb[14] = @SVector [0.,0.,1.] - ptb = Vector{SVector{4,Int}}(undef,24)# voxel-tetra vertices table - ptb[1] = @SVector [1,2,13,15];ptb[2] = @SVector [2,3,13,15];ptb[3] = @SVector [3,4,13,15];ptb[4] = @SVector [4,1,13,15] - ptb[5] = @SVector [5,6,14,15];ptb[6] = @SVector [6,7,14,15];ptb[7] = @SVector [7,8,14,15];ptb[8] = @SVector [8,5,14,15]; - ptb[9] = @SVector [1,4,9,15];ptb[10] = @SVector [4,8,9,15];ptb[11] = @SVector [8,5,9,15];ptb[12] = @SVector [5,1,9,15]; - ptb[13] = @SVector [2,6,10,15];ptb[14] = @SVector [6,7,10,15];ptb[15] = @SVector [7,3,10,15];ptb[16] = @SVector [3,2,10,15]; - ptb[17] = @SVector [1,2,11,15];ptb[18] = @SVector [2,6,11,15];ptb[19] = @SVector [6,5,11,15];ptb[20] = @SVector [5,1,11,15]; - ptb[21] = @SVector [3,4,12,15];ptb[22] = @SVector [4,8,12,15];ptb[23] = @SVector [8,7,12,15];ptb[24] = @SVector [7,3,12,15]; + tb = Vector{SVector{3,Float64}}(undef, 14) + tb[1] = @SVector [-1.0, -1.0, -1.0]; + tb[2] = @SVector [1.0, -1.0, -1.0]; + tb[3] = @SVector [1.0, 1.0, -1.0]; + tb[4] = @SVector [-1.0, 1.0, -1.0] + tb[5] = @SVector [-1.0, -1.0, 1.0]; + tb[6] = @SVector [1.0, -1.0, 1.0]; + tb[7] = @SVector [1.0, 1.0, 1.0]; + tb[8] = @SVector [-1.0, 1.0, 1.0] + tb[9] = @SVector [-1.0, 0.0, 0.0]; + tb[10] = @SVector [1.0, 0.0, 0.0]; + tb[11] = @SVector [0.0, -1.0, 0.0]; + tb[12] = @SVector [0.0, 1.0, 0.0] + tb[13] = @SVector [0.0, 0.0, -1.0]; + tb[14] = @SVector [0.0, 0.0, 1.0] + ptb = Vector{SVector{4,Int}}(undef, 24)# voxel-tetra vertices table + ptb[1] = @SVector [1, 2, 13, 15]; + ptb[2] = @SVector [2, 3, 13, 15]; + ptb[3] = @SVector [3, 4, 13, 15]; + ptb[4] = @SVector [4, 1, 13, 15] + ptb[5] = @SVector [5, 6, 14, 15]; + ptb[6] = @SVector [6, 7, 14, 15]; + ptb[7] = @SVector [7, 8, 14, 15]; + ptb[8] = @SVector [8, 5, 14, 15]; + ptb[9] = @SVector [1, 4, 9, 15]; + ptb[10] = @SVector [4, 8, 9, 15]; + ptb[11] = @SVector [8, 5, 9, 15]; + ptb[12] = @SVector [5, 1, 9, 15]; + ptb[13] = @SVector [2, 6, 10, 15]; + ptb[14] = @SVector [6, 7, 10, 15]; + ptb[15] = @SVector [7, 3, 10, 15]; + ptb[16] = @SVector [3, 2, 10, 15]; + ptb[17] = @SVector [1, 2, 11, 15]; + ptb[18] = @SVector [2, 6, 11, 15]; + ptb[19] = @SVector [6, 5, 11, 15]; + ptb[20] = @SVector [5, 1, 11, 15]; + ptb[21] = @SVector [3, 4, 12, 15]; + ptb[22] = @SVector [4, 8, 12, 15]; + ptb[23] = @SVector [8, 7, 12, 15]; + ptb[24] = @SVector [7, 3, 12, 15]; nv = length(tb)+1 # The 15th one represents the midpoint of the voxel. nc = length(ptb) - vertices = Matrix{Float64}(undef,3,nv*N) - cells = Vector{MeshCell}(undef,nc*N) - levels = Vector{Int8}(undef,N) + vertices = Matrix{Float64}(undef, 3, nv*N) + cells = Vector{MeshCell}(undef, nc*N) + levels = Vector{Int8}(undef, N) index = 1 - data = [index,vertices,cells,levels] + data = [index, vertices, cells, levels] p_data = pointer_from_objref(data) - GC.@preserve data AMR_volume_iterate(p4est;user_data = p_data) do ip,data,dp - d = unsafe_pointer_to_objref(data);index,vertices,cells = d + GC.@preserve data AMR_volume_iterate(p4est; user_data = p_data) do ip, data, dp + d = unsafe_pointer_to_objref(data); + index, vertices, cells = d ps_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - if isa(ps_data,InsideSolidData) - ds, midpoint = quad_to_cell(ip.p4est,ip.treeid[],ip.quad) + if isa(ps_data, InsideSolidData) + ds, midpoint = quad_to_cell(ip.p4est, ip.treeid[], ip.quad) else ds = ps_data.ds midpoint = ps_data.midpoint end - for i in 1:nv-1 - vertices[:,(index-1)*nv+i] .= midpoint+0.5*tb[i].*ds + for i = 1:(nv-1) + vertices[:, (index-1)*nv+i] .= midpoint+0.5*tb[i] .* ds end - vertices[:,nv*index] .= midpoint + vertices[:, nv*index] .= midpoint for i in eachindex(ptb) - cells[nc*(index-1)+i] = MeshCell(VTKCellTypes.VTK_TETRA,ptb[i].+nv*(index-1)) + cells[nc*(index-1)+i] = MeshCell(VTKCellTypes.VTK_TETRA, ptb[i] .+ nv*(index-1)) end levels[index] = ip.quad.level[] d[1]+=1 end - solutions = Matrix{Float64}(undef,nc*N,8) - point_solutions = Matrix{Float64}(undef,nv*N,8) + solutions = Matrix{Float64}(undef, nc*N, 8) + point_solutions = Matrix{Float64}(undef, nv*N, 8) index = 1 for tree in amr.field.trees.data for ps_data in tree - if isa(ps_data,InsideSolidData)||ps_data.bound_enc<0 - solutions[nc*(index-1)+1:nc*index,:].=NaN - point_solutions[nv*(index-1)+1:nv*index,:] .= NaN + if isa(ps_data, InsideSolidData)||ps_data.bound_enc<0 + solutions[(nc*(index-1)+1):(nc*index), :].=NaN + point_solutions[(nv*(index-1)+1):(nv*index), :] .= NaN else - for i in 1:nc - solutions[nc*(index-1)+i,1] = ps_data.prim[1] - @views solutions[nc*(index-1)+i,2:4] .= ps_data.prim[2:4] - solutions[nc*(index-1)+i,5] = 1.0/ps_data.prim[end] - @views solutions[nc*(index-1)+i,6:8] .= ps_data.qf + for i = 1:nc + solutions[nc*(index-1)+i, 1] = ps_data.prim[1] + @views solutions[nc*(index-1)+i, 2:4] .= ps_data.prim[2:4] + solutions[nc*(index-1)+i, 5] = 1.0/ps_data.prim[end] + @views solutions[nc*(index-1)+i, 6:8] .= ps_data.qf end - + vs_data = ps_data.vs_data - β = @views [min(abs(vs_data.df[i,j]/(0.5*dot(ps_data.ds,abs.(vs_data.sdf[i,j,:]))+EPS)),1.) for i in axes(vs_data.df,1), j in axes(vs_data.df,2)] # positivity preserving coefficient + β = @views [ + min( + abs( + vs_data.df[ + i, + j, + ]/(0.5*dot(ps_data.ds, abs.(vs_data.sdf[i, j, :]))+EPS), + ), + 1.0, + ) for i in axes(vs_data.df, 1), j in axes(vs_data.df, 2) + ] # positivity preserving coefficient point_df = similar(vs_data.df) - for i in 1:nv-1 + for i = 1:(nv-1) df = vs_data.df sdf = vs_data.sdf - dx = 0.5*ps_data.ds.*tb[i] - point_df .= @views df+[β[i,j]*dot(sdf[i,j,:],dx) for i in axes(df,1), j in axes(df,2)] - w = calc_w0(vs_data.midpoint,point_df,vs_data.weight,amr.global_data) - prim = get_prim(w,amr.global_data) - qf = calc_qf(vs_data.midpoint,point_df,vs_data.weight,prim,amr.global_data) - point_solutions[nv*(index-1)+i,1] = prim[1] - @views point_solutions[nv*(index-1)+i,2:4] .= prim[2:4] - point_solutions[nv*(index-1)+i,5] = 1.0/prim[end] - @views point_solutions[nv*(index-1)+i,6:8] .= qf + dx = 0.5*ps_data.ds .* tb[i] + point_df .= @views df+[ + β[i, j]*dot(sdf[i, j, :], dx) for i in axes(df, 1), j in axes(df, 2) + ] + w = calc_w0(vs_data.midpoint, point_df, vs_data.weight, amr.global_data) + prim = get_prim(w, amr.global_data) + qf = calc_qf( + vs_data.midpoint, + point_df, + vs_data.weight, + prim, + amr.global_data, + ) + point_solutions[nv*(index-1)+i, 1] = prim[1] + @views point_solutions[nv*(index-1)+i, 2:4] .= prim[2:4] + point_solutions[nv*(index-1)+i, 5] = 1.0/prim[end] + @views point_solutions[nv*(index-1)+i, 6:8] .= qf end - point_solutions[nv*index,1] = ps_data.prim[1] - @views point_solutions[nv*index,2:4] .= ps_data.prim[2:4] - point_solutions[nv*index,5] = 1.0/ps_data.prim[end] - @views point_solutions[nv*index,6:8] .= ps_data.qf + point_solutions[nv*index, 1] = ps_data.prim[1] + @views point_solutions[nv*index, 2:4] .= ps_data.prim[2:4] + point_solutions[nv*index, 5] = 1.0/ps_data.prim[end] + @views point_solutions[nv*index, 6:8] .= ps_data.qf end index += 1 end end - return vertices,cells,point_solutions,solutions + return vertices, cells, point_solutions, solutions end -function pvtu_data(p4est,amr,::Type{T}) where{T<:Voxel} +function pvtu_data(p4est, amr, ::Type{T}) where {T<:Voxel} N = PointerWrapper(p4est).local_num_quadrants[] - tb = Vector{SVector{3,Float64}}(undef,8) - tb[1] = @SVector [-1.,-1.,-1.];tb[2] = @SVector [1.,-1.,-1.];tb[3] = @SVector [-1.,1.,-1.];tb[4] = @SVector [1.,1.,-1.] - tb[5] = @SVector [-1.,-1.,1.];tb[6] = @SVector [1.,-1.,1.];tb[7] = @SVector [-1.,1.,1.];tb[8] = @SVector [1.,1.,1.] - vertices = Matrix{Float64}(undef,3,8*N) - cells = Vector{MeshCell}(undef,N) - levels = Vector{Int8}(undef,N) + tb = Vector{SVector{3,Float64}}(undef, 8) + tb[1] = @SVector [-1.0, -1.0, -1.0]; + tb[2] = @SVector [1.0, -1.0, -1.0]; + tb[3] = @SVector [-1.0, 1.0, -1.0]; + tb[4] = @SVector [1.0, 1.0, -1.0] + tb[5] = @SVector [-1.0, -1.0, 1.0]; + tb[6] = @SVector [1.0, -1.0, 1.0]; + tb[7] = @SVector [-1.0, 1.0, 1.0]; + tb[8] = @SVector [1.0, 1.0, 1.0] + vertices = Matrix{Float64}(undef, 3, 8*N) + cells = Vector{MeshCell}(undef, N) + levels = Vector{Int8}(undef, N) index = 1 - data = [index,vertices,cells,levels] + data = [index, vertices, cells, levels] p_data = pointer_from_objref(data) - GC.@preserve data AMR_volume_iterate(p4est;user_data = p_data) do ip,data,dp - d = unsafe_pointer_to_objref(data);index,vertices,cells = d + GC.@preserve data AMR_volume_iterate(p4est; user_data = p_data) do ip, data, dp + d = unsafe_pointer_to_objref(data); + index, vertices, cells = d ps_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - if isa(ps_data,InsideSolidData) - ds, midpoint = quad_to_cell(ip.p4est,ip.treeid[],ip.quad) + if isa(ps_data, InsideSolidData) + ds, midpoint = quad_to_cell(ip.p4est, ip.treeid[], ip.quad) else ds = ps_data.ds midpoint = ps_data.midpoint end - for i in 1:8 - @. vertices[:,(index-1)*8+i] = midpoint+tb[i]/2*ds + for i = 1:8 + @. vertices[:, (index-1)*8+i] = midpoint+tb[i]/2*ds end - cells[index] = MeshCell(VTKCellTypes.VTK_VOXEL,(1:8).+8*(index-1)) + cells[index] = MeshCell(VTKCellTypes.VTK_VOXEL, (1:8) .+ 8*(index-1)) levels[index] = ip.quad.level[] d[1]+=1 end - solutions = Matrix{Float64}(undef,N,8) - point_solutions = Matrix{Float64}(undef,8*N,8) + solutions = Matrix{Float64}(undef, N, 8) + point_solutions = Matrix{Float64}(undef, 8*N, 8) index = 1 for tree in amr.field.trees.data for ps_data in tree - if isa(ps_data,InsideSolidData)||ps_data.bound_enc<0 - solutions[index,:].=NaN - point_solutions[8*(index-1)+1:8*index,:] .= NaN + if isa(ps_data, InsideSolidData)||ps_data.bound_enc<0 + solutions[index, :].=NaN + point_solutions[(8*(index-1)+1):(8*index), :] .= NaN else - solutions[index,1] = ps_data.prim[1] - @views solutions[index,2:4] .= ps_data.prim[2:4] - solutions[index,5] = 1.0/ps_data.prim[end] - @views solutions[index,6:8] .= ps_data.qf - for i in 1:8 - point_solutions[8*(index-1)+i,1] = ps_data.prim[1] - @views point_solutions[8*(index-1)+i,2:4] .= ps_data.prim[2:4] - point_solutions[8*(index-1)+i,5] = 1.0/ps_data.prim[end] - @views point_solutions[8*(index-1)+i,6:8] .= ps_data.qf + solutions[index, 1] = ps_data.prim[1] + @views solutions[index, 2:4] .= ps_data.prim[2:4] + solutions[index, 5] = 1.0/ps_data.prim[end] + @views solutions[index, 6:8] .= ps_data.qf + for i = 1:8 + point_solutions[8*(index-1)+i, 1] = ps_data.prim[1] + @views point_solutions[8*(index-1)+i, 2:4] .= ps_data.prim[2:4] + point_solutions[8*(index-1)+i, 5] = 1.0/ps_data.prim[end] + @views point_solutions[8*(index-1)+i, 6:8] .= ps_data.qf end end index += 1 end end - return vertices,cells,point_solutions,solutions + return vertices, cells, point_solutions, solutions end -function save_surfaces_pvtu(::String,::Vector{Boundary_Solution},amr::KitAMR_Data{2}) +function save_surfaces_pvtu(::String, ::Vector{Boundary_Solution}, amr::KitAMR_Data{2}) return nothing end -function save_surfaces_pvtu(dir_path::String,boundary_results::Vector{Boundary_Solution},amr::KitAMR_Data{3}) +function save_surfaces_pvtu( + dir_path::String, + boundary_results::Vector{Boundary_Solution}, + amr::KitAMR_Data{3}, +) np = MPI.Comm_size(MPI.COMM_WORLD) - rflags = [Ref(false) for _ in 1:np] + rflags = [Ref(false) for _ = 1:np] rank = MPI.Comm_rank(MPI.COMM_WORLD) surface_path = dir_path*"/vtk" for i in eachindex(boundary_results) boundary_solutions = boundary_results[i] rflags[rank+1][] = !isempty(boundary_solutions.ps_solutions) - reqs = Vector{MPI.Request}(undef,0) - for i in 1:np - i-1==rank&&continue - sreq = MPI.Isend(rflags[rank+1],MPI.COMM_WORLD;dest = i-1,tag = COMM_DATA_TAG+rank) - push!(reqs,sreq) - end - for i in 1:np + reqs = Vector{MPI.Request}(undef, 0) + for i = 1:np i-1==rank&&continue - rreq = MPI.Irecv!( - rflags[i], + sreq = MPI.Isend( + rflags[rank+1], MPI.COMM_WORLD; - source = i-1, - tag = COMM_DATA_TAG+i-1 + dest = i-1, + tag = COMM_DATA_TAG+rank, ) - push!(reqs,rreq) + push!(reqs, sreq) + end + for i = 1:np + i-1==rank&&continue + rreq = + MPI.Irecv!(rflags[i], MPI.COMM_WORLD; source = i-1, tag = COMM_DATA_TAG+i-1) + push!(reqs, rreq) end MPI.Waitall(reqs) if rflags[rank+1][] - nparts = length(findall(x->x[],rflags));part = length(findall(x->x[],rflags[1:rank+1])) - points = [boundary_solutions.midpoints[i][j] for i in eachindex(boundary_solutions.midpoints), j in 1:3] |> permutedims - cells = [MeshCell(VTKCellTypes.VTK_VERTEX,[i]) for i in eachindex(boundary_solutions.midpoints)] - pvtk_grid(surface_path*"/surface_"*string(i),points,cells;part = part,nparts = nparts) do pvtk + nparts = length(findall(x->x[], rflags)); + part = length(findall(x->x[], rflags[1:(rank+1)])) + points = + [ + boundary_solutions.midpoints[i][j] for + i in eachindex(boundary_solutions.midpoints), j = 1:3 + ] |> permutedims + cells = [ + MeshCell(VTKCellTypes.VTK_VERTEX, [i]) for + i in eachindex(boundary_solutions.midpoints) + ] + pvtk_grid( + surface_path*"/surface_"*string(i), + points, + cells; + part = part, + nparts = nparts, + ) do pvtk pvtk["rho"] = [x.prim[1] for x in boundary_solutions.ps_solutions] pvtk["U"] = [x.prim[2] for x in boundary_solutions.ps_solutions] pvtk["V"] = [x.prim[3] for x in boundary_solutions.ps_solutions] @@ -743,17 +901,23 @@ function save_surfaces_pvtu(dir_path::String,boundary_results::Vector{Boundary_S pvtk["p13"] = [x.p[3] for x in boundary_solutions.ps_solutions] pvtk["p22"] = [x.p[4] for x in boundary_solutions.ps_solutions] pvtk["p23"] = [x.p[5] for x in boundary_solutions.ps_solutions] - pvtk["p33"] = [x.p[6] for x in boundary_solutions.ps_solutions ] - pvtk["normal"] = ([x[1] for x in boundary_solutions.normal],[x[2] for x in boundary_solutions.normal], - [x[3] for x in boundary_solutions.normal]) + pvtk["p33"] = [x.p[6] for x in boundary_solutions.ps_solutions] + pvtk["normal"] = ( + [x[1] for x in boundary_solutions.normal], + [x[2] for x in boundary_solutions.normal], + [x[3] for x in boundary_solutions.normal], + ) end end end return nothing end -function save_boundary_result(dir_path::String,amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function save_boundary_result(dir_path::String, amr::KitAMR_Data{DIM,NDF}) where {DIM,NDF} ibs = amr.global_data.config.IB - boundary_results = [Boundary_Solution(Vector{Float64}[],Vector{Float64}[],Boundary_PS_Solution[]) for _ in eachindex(ibs)] + boundary_results = [ + Boundary_Solution(Vector{Float64}[], Vector{Float64}[], Boundary_PS_Solution[]) + for _ in eachindex(ibs) + ] for i in eachindex(ibs) if MPI.Comm_rank(MPI.COMM_WORLD)==0 vs_dir_path = dir_path*"/boundary_vs_"*string(i) @@ -763,53 +927,69 @@ function save_boundary_result(dir_path::String,amr::KitAMR_Data{DIM,NDF}) where{ MPI.Barrier(MPI.COMM_WORLD) for tree in amr.field.trees.data for ps_data in tree - (isa(ps_data,InsideSolidData)||ps_data.bound_enc<=0)&&continue + (isa(ps_data, InsideSolidData)||ps_data.bound_enc<=0)&&continue ib = ibs[ps_data.bound_enc] - save_boundary_result!(ib,ps_data,boundary_results,amr;dir_path = dir_path*"/boundary_vs_"*string(ps_data.bound_enc)) + save_boundary_result!( + ib, + ps_data, + boundary_results, + amr; + dir_path = dir_path*"/boundary_vs_"*string(ps_data.bound_enc), + ) end end rank = MPI.Comm_rank(MPI.COMM_WORLD) - save_object(dir_path*"boundary_result_"*string(rank)*".jld2",boundary_results) - save_surfaces_pvtu(dir_path,boundary_results,amr) + save_object(dir_path*"boundary_result_"*string(rank)*".jld2", boundary_results) + save_surfaces_pvtu(dir_path, boundary_results, amr) end -function boundary_write_csv(csvname,results,config::ConfigureForSave{2}) +function boundary_write_csv(csvname, results, config::ConfigureForSave{2}) for i in eachindex(config.IB) df = DataFrame() - df.x=[x[1] for x in results[i].midpoints];df.y=[x[2] for x in results[i].midpoints] - df.nx = [x[1] for x in results[i].normal];df.ny = [x[2] for x in results[i].normal] + df.x=[x[1] for x in results[i].midpoints]; + df.y=[x[2] for x in results[i].midpoints] + df.nx = [x[1] for x in results[i].normal]; + df.ny = [x[2] for x in results[i].normal] df.rho=[x.prim[1] for x in results[i].ps_solutions] df.u=[x.prim[2] for x in results[i].ps_solutions] df.v=[x.prim[3] for x in results[i].ps_solutions] df.T=[1/x.prim[4] for x in results[i].ps_solutions] - df.qfx=[x.qf[1] for x in results[i].ps_solutions];df.qfy=[x.qf[2] for x in results[i].ps_solutions] - df.p11 = [x.p[1] for x in results[i].ps_solutions];df.p12 = [x.p[2] for x in results[i].ps_solutions] + df.qfx=[x.qf[1] for x in results[i].ps_solutions]; + df.qfy=[x.qf[2] for x in results[i].ps_solutions] + df.p11 = [x.p[1] for x in results[i].ps_solutions]; + df.p12 = [x.p[2] for x in results[i].ps_solutions] df.p22 = [x.p[3] for x in results[i].ps_solutions] - CSV.write(csvname*"_"*string(i)*".csv",df) + CSV.write(csvname*"_"*string(i)*".csv", df) end end -function boundary_write_csv(csvname,results,config::ConfigureForSave{3}) +function boundary_write_csv(csvname, results, config::ConfigureForSave{3}) for i in eachindex(config.IB) df = DataFrame() - df.x=[x[1] for x in results[i].midpoints];df.y=[x[2] for x in results[i].midpoints] - df.nx = [x[1] for x in results[i].normal];df.ny = [x[2] for x in results[i].normal] + df.x=[x[1] for x in results[i].midpoints]; + df.y=[x[2] for x in results[i].midpoints] + df.nx = [x[1] for x in results[i].normal]; + df.ny = [x[2] for x in results[i].normal] df.rho=[x.prim[1] for x in results[i].ps_solutions] df.u=[x.prim[2] for x in results[i].ps_solutions] df.v=[x.prim[3] for x in results[i].ps_solutions] df.w=[x.prim[4] for x in results[i].ps_solutions] df.T=[1/x.prim[4] for x in results[i].ps_solutions] - df.qfx=[x.qf[1] for x in results[i].ps_solutions];df.qfy=[x.qf[2] for x in results[i].ps_solutions] + df.qfx=[x.qf[1] for x in results[i].ps_solutions]; + df.qfy=[x.qf[2] for x in results[i].ps_solutions] df.qfz=[x.qf[3] for x in results[i].ps_solutions] - df.p11 = [x.p[1] for x in results[i].ps_solutions];df.p12 = [x.p[2] for x in results[i].ps_solutions] - df.p13 = [x.p[3] for x in results[i].ps_solutions];df.p22 = [x.p[4] for x in results[i].ps_solutions]; - df.p23 = [x.p[5] for x in results[i].ps_solutions];df.p33 = [x.p[6] for x in results[i].ps_solutions]; - CSV.write(csvname*"_"*string(i)*".csv",df) + df.p11 = [x.p[1] for x in results[i].ps_solutions]; + df.p12 = [x.p[2] for x in results[i].ps_solutions] + df.p13 = [x.p[3] for x in results[i].ps_solutions]; + df.p22 = [x.p[4] for x in results[i].ps_solutions]; + df.p23 = [x.p[5] for x in results[i].ps_solutions]; + df.p33 = [x.p[6] for x in results[i].ps_solutions]; + CSV.write(csvname*"_"*string(i)*".csv", df) end end -function boundary_result2csv(dirname::String,csvname::String) +function boundary_result2csv(dirname::String, csvname::String) path = "./"*dirname solverset = load_object(path*"/solverset.jld2") results = nothing - for i in 1:solverset.mpi_size + for i = 1:solverset.mpi_size if i==1 results = load_object(path*"/boundary_result_"*string(i-1)*".jld2") else @@ -817,40 +997,51 @@ function boundary_result2csv(dirname::String,csvname::String) for j in eachindex(rs) r = rs[j] result = results[j] - append!(result.ps_solutions,r.ps_solutions) - append!(result.midpoints,r.midpoints) - append!(result.normal,r.normal) + append!(result.ps_solutions, r.ps_solutions) + append!(result.midpoints, r.midpoints) + append!(result.normal, r.normal) end end end - boundary_write_csv(csvname,results,solverset.config) + boundary_write_csv(csvname, results, solverset.config) end -function result2vtk(dirname::String,vtkname::String) +function result2vtk(dirname::String, vtkname::String) !MPI.Initialized() && MPI.Init() path = "./"*dirname solverset = load_object(path*"/solverset.jld2") if typeof(solverset.config).parameters[1]==2 DIM=2 - cnn = Ptr{Ptr{p4est_connectivity_t}}(Libc.malloc(sizeof(Ptr{Ptr{p4est_connectivity_t}}))) + cnn = Ptr{Ptr{p4est_connectivity_t}}( + Libc.malloc(sizeof(Ptr{Ptr{p4est_connectivity_t}})), + ) pro_path = pwd() cd(dirname) - ps4est = p4est_load_ext("p",MPI.COMM_WORLD,Cint(0),Cint(0),Cint(1),Cint(0),C_NULL,cnn) + ps4est = p4est_load_ext( + "p", + MPI.COMM_WORLD, + Cint(0), + Cint(0), + Cint(1), + Cint(0), + C_NULL, + cnn, + ) cd(pro_path) result = nothing ranks = nothing for i = 1:solverset.mpi_size if i==1 result = load_object(path*"/result_"*string(i-1)*".jld2") - ranks = zeros(Int,length(result.solution.ps_solutions)) + ranks = zeros(Int, length(result.solution.ps_solutions)) else r = load_object(path*"/result_"*string(i-1)*".jld2") - append!(result.solution.ps_solutions,r.solution.ps_solutions) - append!(result.solution.vs_solutions,r.solution.vs_solutions) - append!(result.mesh_info.neighbor_nums,r.mesh_info.neighbor_nums) - append!(ranks,ones(Int,length(r.solution.ps_solutions))*(i-1)) + append!(result.solution.ps_solutions, r.solution.ps_solutions) + append!(result.solution.vs_solutions, r.solution.vs_solutions) + append!(result.mesh_info.neighbor_nums, r.mesh_info.neighbor_nums) + append!(ranks, ones(Int, length(r.solution.ps_solutions))*(i-1)) end end - vtk_cnn = Vector{Vector{Int}}(undef,length(result.solution.ps_solutions)) + vtk_cnn = Vector{Vector{Int}}(undef, length(result.solution.ps_solutions)) neighbor_nums = result.mesh_info.neighbor_nums for i in eachindex(neighbor_nums) for j in eachindex(neighbor_nums[i]) @@ -860,29 +1051,29 @@ function result2vtk(dirname::String,vtkname::String) for i in eachindex(vtk_cnn) addi_points_num = 0 for j in eachindex(neighbor_nums[i]) - addi_points_num+= neighbor_nums[i][j]==2^(DIM-1) ? 1 : 0 + addi_points_num += neighbor_nums[i][j]==2^(DIM-1) ? 1 : 0 end - vtk_cnn[i] = Vector{Int}(undef,2^DIM+addi_points_num) + vtk_cnn[i] = Vector{Int}(undef, 2^DIM+addi_points_num) end points = Vector{Float64}[] data = Vector{Any}() - for el in (points,vtk_cnn,neighbor_nums) - push!(data,el) + for el in (points, vtk_cnn, neighbor_nums) + push!(data, el) end p_data = pointer_from_objref(data) - GC.@preserve data AMR_corner_iterate(ps4est;user_data = p_data) do ip,data - points,vtk_cnn,neighbor_nums = unsafe_pointer_to_objref(data) - DIM=isa(ip,PointerWrapper{p4est_iter_corner_info_t}) ? 2 : 3 - for i in 1:ip.sides.elem_count[] - side = iPointerWrapper(ip.sides,p4est_iter_corner_side_t,i-1) + GC.@preserve data AMR_corner_iterate(ps4est; user_data = p_data) do ip, data + points, vtk_cnn, neighbor_nums = unsafe_pointer_to_objref(data) + DIM=isa(ip, PointerWrapper{p4est_iter_corner_info_t}) ? 2 : 3 + for i = 1:ip.sides.elem_count[] + side = iPointerWrapper(ip.sides, p4est_iter_corner_side_t, i-1) cornerid = side.corner[]+1 # z-order if i==1 - ds,midpoint = quad_to_cell(ip.p4est,side.treeid[],side.quad) + ds, midpoint = quad_to_cell(ip.p4est, side.treeid[], side.quad) point = @. midpoint+0.5*ds*RMT[DIM][cornerid] - push!(points,point) + push!(points, point) end id = length(points) - quadid = local_quadid(ip,side) + quadid = local_quadid(ip, side) neighbor_num = neighbor_nums[quadid+1] cornerid==1&&(vtk_cnn[quadid+1][1]=id) cornerid==2&&(vtk_cnn[quadid+1][neighbor_num[3]+1]=id) @@ -891,65 +1082,83 @@ function result2vtk(dirname::String,vtkname::String) end return nothing end - GC.@preserve data AMR_face_iterate(ps4est;user_data = p_data) do ip,data - points,vtk_cnn,neighbor_nums = unsafe_pointer_to_objref(data) - DIM=isa(ip,PointerWrapper{p4est_iter_face_info_t}) ? 2 : 3 + GC.@preserve data AMR_face_iterate(ps4est; user_data = p_data) do ip, data + points, vtk_cnn, neighbor_nums = unsafe_pointer_to_objref(data) + DIM=isa(ip, PointerWrapper{p4est_iter_face_info_t}) ? 2 : 3 ip.sides.elem_count[]==1&&return nothing - side1 = iPointerWrapper(ip.sides,p4est_iter_face_side_t,0) - side2 = iPointerWrapper(ip.sides,p4est_iter_face_side_t,1) + side1 = iPointerWrapper(ip.sides, p4est_iter_face_side_t, 0) + side2 = iPointerWrapper(ip.sides, p4est_iter_face_side_t, 1) (side1.is_hanging[]==0&&side2.is_hanging[]==0)&&return nothing - for side in (side1,side2) - if side.is_hanging[]==0 - ds,midpoint = quad_to_cell(ip.p4est,side.treeid[],side.is.full.quad) - faceid = side.face[]+1 - point = @. midpoint+0.5*ds*NMT[DIM][faceid] - push!(points,point) - id = length(points) - quadid = local_quadid(ip.p4est,side.treeid[],side.is.full.quadid[]) - neighbor_num = neighbor_nums[quadid+1] - faceid==1&&(@inbounds vtk_cnn[quadid+1][end]=id) - faceid==2&&(@inbounds vtk_cnn[quadid+1][neighbor_num[3]+2]=id) - faceid==3&&(@inbounds vtk_cnn[quadid+1][2]=id) - faceid==4&&(@inbounds vtk_cnn[quadid+1][sum(neighbor_num[2:3])+2]=id) - end + for side in (side1, side2) + if side.is_hanging[]==0 + ds, midpoint = quad_to_cell(ip.p4est, side.treeid[], side.is.full.quad) + faceid = side.face[]+1 + point = @. midpoint+0.5*ds*NMT[DIM][faceid] + push!(points, point) + id = length(points) + quadid = local_quadid(ip.p4est, side.treeid[], side.is.full.quadid[]) + neighbor_num = neighbor_nums[quadid+1] + faceid==1&&(@inbounds vtk_cnn[quadid+1][end]=id) + faceid==2&&(@inbounds vtk_cnn[quadid+1][neighbor_num[3]+2]=id) + faceid==3&&(@inbounds vtk_cnn[quadid+1][2]=id) + faceid==4&&(@inbounds vtk_cnn[quadid+1][sum(neighbor_num[2:3])+2]=id) + end end - for side in (side1,side2) - if side.is_hanging[]==1 - faceid = side.face[]+1 - id = length(points) - quadids = side.is.hanging.quadid[] - quadid1 = local_quadid(ip.p4est,side.treeid[],quadids[1]) - quadid2 = local_quadid(ip.p4est,side.treeid[],quadids[2]) - neighbor_num1 = neighbor_nums[quadid1+1] - neighbor_num2 = neighbor_nums[quadid2+1] - faceid==1&&(@inbounds vtk_cnn[quadid1+1][end]=id;vtk_cnn[quadid2+1][1]=id) - faceid==2&&(@inbounds vtk_cnn[quadid1+1][sum(neighbor_num1[2:3])+1]=id;vtk_cnn[quadid2+1][neighbor_num2[3]+1]=id) - faceid==3&&(@inbounds vtk_cnn[quadid1+1][2]=id;vtk_cnn[quadid2+1][1]=id) - faceid==4&&(@inbounds vtk_cnn[quadid1+1][sum(neighbor_num1[2:3])+1]=id;vtk_cnn[quadid2+1][end]=id) - end + for side in (side1, side2) + if side.is_hanging[]==1 + faceid = side.face[]+1 + id = length(points) + quadids = side.is.hanging.quadid[] + quadid1 = local_quadid(ip.p4est, side.treeid[], quadids[1]) + quadid2 = local_quadid(ip.p4est, side.treeid[], quadids[2]) + neighbor_num1 = neighbor_nums[quadid1+1] + neighbor_num2 = neighbor_nums[quadid2+1] + faceid==1&&( + @inbounds vtk_cnn[quadid1+1][end]=id; + vtk_cnn[quadid2+1][1] = id + ) + faceid==2&&( + @inbounds vtk_cnn[quadid1+1][sum(neighbor_num1[2:3])+1]=id; + vtk_cnn[quadid2+1][neighbor_num2[3]+1] = id + ) + faceid==3&&( + @inbounds vtk_cnn[quadid1+1][2]=id; + vtk_cnn[quadid2+1][1] = id + ) + faceid==4&&( + @inbounds vtk_cnn[quadid1+1][sum(neighbor_num1[2:3])+1]=id; + vtk_cnn[quadid2+1][end] = id + ) + end end return nothing end - cells = [MeshCell(PolyData.Polys(),cnn) for cnn in vtk_cnn] - vertices = Matrix{Float64}(undef,2,length(points)) + cells = [MeshCell(PolyData.Polys(), cnn) for cnn in vtk_cnn] + vertices = Matrix{Float64}(undef, 2, length(points)) for i in eachindex(points) - @inbounds vertices[:,i] .= points[i] + @inbounds vertices[:, i] .= points[i] end - vtk_grid(vtkname,vertices,cells) do vtk - vtk["rho"] = [ps_solution.prim[1] for ps_solution in result.solution.ps_solutions] - vtk["velocity"] = ([ps_solution.prim[2] for ps_solution in result.solution.ps_solutions], + vtk_grid(vtkname, vertices, cells) do vtk + vtk["rho"] = + [ps_solution.prim[1] for ps_solution in result.solution.ps_solutions] + vtk["velocity"] = ( + [ps_solution.prim[2] for ps_solution in result.solution.ps_solutions], [ps_solution.prim[3] for ps_solution in result.solution.ps_solutions], - [0. for _ in result.solution.ps_solutions]) - vtk["T"] = [1/ps_solution.prim[end] for ps_solution in result.solution.ps_solutions] - vtk["qf"] = ([ps_solution.qf[1] for ps_solution in result.solution.ps_solutions], + [0.0 for _ in result.solution.ps_solutions], + ) + vtk["T"] = + [1/ps_solution.prim[end] for ps_solution in result.solution.ps_solutions] + vtk["qf"] = ( + [ps_solution.qf[1] for ps_solution in result.solution.ps_solutions], [ps_solution.qf[2] for ps_solution in result.solution.ps_solutions], - [0. for _ in result.solution.ps_solutions]) + [0.0 for _ in result.solution.ps_solutions], + ) vtk["mpi_rank"] = ranks end - fp = PointerWrapper(ps4est) + fp = PointerWrapper(ps4est) p4est_connectivity_destroy(pointer(fp.connectivity)) p4est_destroy(ps4est) else @error "Only support 2D now" end -end \ No newline at end of file +end diff --git a/src/IO/Restart.jl b/src/IO/Restart.jl index b569b81..8c2267b 100644 --- a/src/IO/Restart.jl +++ b/src/IO/Restart.jl @@ -1,15 +1,17 @@ -function pause(ps4est,amr;path::String = "pause_data",kwargs...) - save_pause_data(ps4est,amr,path) - save_pause_p4est(ps4est;path) +function pause(ps4est, amr; path::String = "pause_data", kwargs...) + save_pause_data(ps4est, amr, path) + save_pause_p4est(ps4est; path) end -function save_pause_data(ps4est,amr::KitAMR_Data{DIM,NDF},path::String) where{DIM,NDF} +function save_pause_data(ps4est, amr::KitAMR_Data{DIM,NDF}, path::String) where {DIM,NDF} fp = PointerWrapper(ps4est) - N = fp.local_num_quadrants[];rank = MPI.Comm_rank(MPI.COMM_WORLD) - vs_nums = Vector{Int}(undef,N);bound_encs = Vector{Int}(undef,N) + N = fp.local_num_quadrants[]; + rank = MPI.Comm_rank(MPI.COMM_WORLD) + vs_nums = Vector{Int}(undef, N); + bound_encs = Vector{Int}(undef, N) index = 1 for tree in amr.field.trees.data for ps_data in tree - if isa(ps_data,InsideSolidData) + if isa(ps_data, InsideSolidData) vs_nums[index] = 0 bound_encs[index] = 0 else @@ -20,24 +22,24 @@ function save_pause_data(ps4est,amr::KitAMR_Data{DIM,NDF},path::String) where{DI end end Nv = sum(vs_nums) - levels = Vector{Int8}(undef,Nv) - midpoints = Matrix{Float64}(undef,Nv,DIM) - dfs = Matrix{FLoat64}(undef,Nv,NDF) + levels = Vector{Int8}(undef, Nv) + midpoints = Matrix{Float64}(undef, Nv, DIM) + dfs = Matrix{FLoat64}(undef, Nv, NDF) index = 0 for tree in amr.field.trees.data for ps_data in tree - if !isa(ps_data,InsideSolidData) + if !isa(ps_data, InsideSolidData) vs_data = ps_data.vs_data vs_num = vs_data.vs_num - range = index+1:index+vs_num + range = (index+1):(index+vs_num) levels[range].=vs_data.level - midpoints[range,:].=vs_data.midpoint - dfs[range,:].=vs_data.df + midpoints[range, :].=vs_data.midpoint + dfs[range, :].=vs_data.df end index+=1 end end - jldopen(path*"pause_data"*string(rank)*".jld2","w";compress=true) do f + jldopen(path*"pause_data"*string(rank)*".jld2", "w"; compress = true) do f f["vs_nums"]=vs_nums f["bound_encs"]=bound_encs f["levels"]=levels @@ -45,24 +47,28 @@ function save_pause_data(ps4est,amr::KitAMR_Data{DIM,NDF},path::String) where{DI f["dfs"]=dfs end if rank==0 - jldopen(path*"pause_data_set.jld2","w") do f - f["gfq"]=unsafe_wrap(Vector{Int},pointer(fp.global_first_quadrant),MPI.Comm_size(MPI.COMM_WORLD)+1) + jldopen(path*"pause_data_set.jld2", "w") do f + f["gfq"]=unsafe_wrap( + Vector{Int}, + pointer(fp.global_first_quadrant), + MPI.Comm_size(MPI.COMM_WORLD)+1, + ) f["config"]=amr.global_data.config f["status"]=StatusForSave(amr.global_data.status) end end end -function save_pause_p4est(p4est::Ptr{p4est_t};path::String) +function save_pause_p4est(p4est::Ptr{p4est_t}; path::String) pro_path = pwd() cd(path) - GC.@preserve p4est p4est_save_ext("p",p4est,Cint(0),Cint(0)) + GC.@preserve p4est p4est_save_ext("p", p4est, Cint(0), Cint(0)) cd(pro_path) return nothing end function restart(dirname::String) set = load(dirname*"paus_data_set.jld2") - global_data = recons_global_data(set[:config],set[:status]) - ps4est = pxest_load(dirname,global_data) + global_data = recons_global_data(set[:config], set[:status]) + ps4est = pxest_load(dirname, global_data) pp = PointerWrapper(ps4est) gfq = Base.unsafe_wrap( Vector{Int}, @@ -71,43 +77,69 @@ function restart(dirname::String) ) rank = MPI.Comm_rank(MPI.COMM_WORLD) gfq_ = set[:gfq] - first_rank = findfirst(x->gfq[rank+1]<=x,gfq_)-1 - last_rank = findlast(x->gfq[rank+2]>x,gfq_)-1 - datas = [load(dirname*"pause_data"*string(x)*".jld2") for x in first_rank:last_rank] + first_rank = findfirst(x->gfq[rank+1]<=x, gfq_)-1 + last_rank = findlast(x->gfq[rank+2]>x, gfq_)-1 + datas = [load(dirname*"pause_data"*string(x)*".jld2") for x = first_rank:last_rank] first_ps_offset = gfq[rank+1]-gfq_[first_rank+1] last_ps_offset = gfq[rank+2]-gfq_[last_rank+1] - vs_nums = datas[1][:vs_nums][first_ps_offset+1:end] + vs_nums = datas[1][:vs_nums][(first_ps_offset+1):end] first_vs_offset = sum(vs_nums) - bound_encs = datas[1][:bound_encs][first_ps_offset+1:end] + bound_encs = datas[1][:bound_encs][(first_ps_offset+1):end] if length(datas)>1 - for i in 2:length(datas)-1 - append!(vs_nums,datas[i][:vs_nums]) - append!(bound_encs,datas[i][:bound_encs]) + for i = 2:(length(datas)-1) + append!(vs_nums, datas[i][:vs_nums]) + append!(bound_encs, datas[i][:bound_encs]) end last_vs_nums = datas[end][:vs_nums][1:last_ps_offset] last_vs_offset = sum(last_vs_nums) - append!(vs_nums,last_vs_nums) - append!(bound_encs,datas[end][:bound_encs][1:last_ps_offset]) + append!(vs_nums, last_vs_nums) + append!(bound_encs, datas[end][:bound_encs][1:last_ps_offset]) end - levels = datas[1][:levels][first_vs_offset+1:end] - midpoints = datas[1][:midpoints][first_vs_offset+1:end,:] - + levels = datas[1][:levels][(first_vs_offset+1):end] + midpoints = datas[1][:midpoints][(first_vs_offset+1):end, :] + end -function recons_global_data(config::Configure{DIM,NDF},stat::StatusForSave) where{DIM,NDF} +function recons_global_data(config::Configure{DIM,NDF}, stat::StatusForSave) where {DIM,NDF} global_data = Global_Data(config) global_data.status = Status(stat) return global_data end -function pxest_load(dirname::String,global_data::Global_Data{DIM,NDF};kwargs...) where{DIM,NDF} +function pxest_load( + dirname::String, + global_data::Global_Data{DIM,NDF}; + kwargs..., +) where {DIM,NDF} pro_path = pwd() cd(dirname) if DIM==2 - cnn = Ptr{Ptr{p4est_connectivity_t}}(Libc.malloc(sizeof(Ptr{Ptr{p4est_connectivity_t}}))) - ps4est = GC.@preserve cnn p4est_load_ext("p",MPI.COMM_WORLD,Cint(0),Cint(0),Cint(1),Cint(0),C_NULL,cnn) + cnn = Ptr{Ptr{p4est_connectivity_t}}( + Libc.malloc(sizeof(Ptr{Ptr{p4est_connectivity_t}})), + ) + ps4est = GC.@preserve cnn p4est_load_ext( + "p", + MPI.COMM_WORLD, + Cint(0), + Cint(0), + Cint(1), + Cint(0), + C_NULL, + cnn, + ) else - cnn = Ptr{Ptr{p8est_connectivity_t}}(Libc.malloc(sizeof(Ptr{Ptr{p8est_connectivity_t}}))) - ps4est = GC.@preserve cnn p8est_load_ext("p",MPI.COMM_WORLD,Cint(0),Cint(0),Cint(1),Cint(0),C_NULL,cnn) + cnn = Ptr{Ptr{p8est_connectivity_t}}( + Libc.malloc(sizeof(Ptr{Ptr{p8est_connectivity_t}})), + ) + ps4est = GC.@preserve cnn p8est_load_ext( + "p", + MPI.COMM_WORLD, + Cint(0), + Cint(0), + Cint(1), + Cint(0), + C_NULL, + cnn, + ) end cd(pro_path) return ps4est -end \ No newline at end of file +end diff --git a/src/IO/Types.jl b/src/IO/Types.jl index 56edb65..61f4f95 100644 --- a/src/IO/Types.jl +++ b/src/IO/Types.jl @@ -20,25 +20,46 @@ struct StatusForSave vs_adapt_step::Int partition_step::Int end -function ConfigureForSave(config::Configure{DIM,NDF}) where{DIM,NDF} +function ConfigureForSave(config::Configure{DIM,NDF}) where {DIM,NDF} return ConfigureForSave{DIM,NDF}( - config.geometry,config.trees_num,config.quadrature, - config.vs_trees_num,config.IC,config.domain, - config.IB,config.gas, + config.geometry, + config.trees_num, + config.quadrature, + config.vs_trees_num, + config.IC, + config.domain, + config.IB, + config.gas, config.solver, - config.user_defined + config.user_defined, ) end function StatusForSave(status::Status) - return StatusForSave(status.max_vs_num,status.gradmax,status.Δt, - status.Δt_ξ,status.sim_time,status.ps_adapt_step, - status.vs_adapt_step,status.partition_step + return StatusForSave( + status.max_vs_num, + status.gradmax, + status.Δt, + status.Δt_ξ, + status.sim_time, + status.ps_adapt_step, + status.vs_adapt_step, + status.partition_step, ) end function Status(status::StatusForSave) - return Status(status.max_vs_num,status.gradmax,status.Δt, - status.Δt_ξ,status.sim_time,status.ps_adapt_step, - status.vs_adapt_step,status.partition_step,Residual(DIM),Ref(false),false) + return Status( + status.max_vs_num, + status.gradmax, + status.Δt, + status.Δt_ξ, + status.sim_time, + status.ps_adapt_step, + status.vs_adapt_step, + status.partition_step, + Residual(DIM), + Ref(false), + false, + ) end struct SolverSet config::ConfigureForSave @@ -53,17 +74,21 @@ struct Boundary_PS_Solution qf::Vector{Float64} p::Vector{Float64} end -function PS_Solution(ps_data::PS_Data{DIM}) where{DIM} +function PS_Solution(ps_data::PS_Data{DIM}) where {DIM} if ps_data.bound_enc<0 - prim = Vector{Float64}(undef,DIM+2);prim.=NaN - qf = Vector{Float64}(undef,DIM);qf.=NaN + prim = Vector{Float64}(undef, DIM+2); + prim.=NaN + qf = Vector{Float64}(undef, DIM); + qf.=NaN return PS_Solution(prim, qf) end return PS_Solution(ps_data.prim, ps_data.qf) end -function PS_Solution(::InsideSolidData{DIM,NDF}) where{DIM,NDF} - prim = Vector{Float64}(undef,DIM+2);prim.=NaN - qf = Vector{Float64}(undef,DIM);qf.=NaN +function PS_Solution(::InsideSolidData{DIM,NDF}) where {DIM,NDF} + prim = Vector{Float64}(undef, DIM+2); + prim.=NaN + qf = Vector{Float64}(undef, DIM); + qf.=NaN return PS_Solution(prim, qf) end struct VS_Solution @@ -91,4 +116,4 @@ struct Boundary_Solution midpoints::Vector{Vector{Float64}} normal::Vector{Vector{Float64}} ps_solutions::Vector{Boundary_PS_Solution} -end \ No newline at end of file +end diff --git a/src/KitAMR.jl b/src/KitAMR.jl index e0ad2bc..0b7fdb6 100644 --- a/src/KitAMR.jl +++ b/src/KitAMR.jl @@ -14,8 +14,8 @@ using Reexport using CSV using DataFrames using Statistics -using FileIO,NearestNeighbors,AbstractTrees -using GeometryBasics:Mesh +using FileIO, NearestNeighbors, AbstractTrees +using GeometryBasics: Mesh using StructArrays BLAS.set_num_threads(1) diff --git a/src/Mesh/Connectivity.jl b/src/Mesh/Connectivity.jl index aa4dada..945241a 100644 --- a/src/Mesh/Connectivity.jl +++ b/src/Mesh/Connectivity.jl @@ -2,8 +2,8 @@ function Cartesian_connectivity(Nx, Ny, xmin, xmax, ymin, ymax) vertices_C = Array{NTuple{2,Float64}}(undef, Nx + 1, Ny + 1) dx = (xmax - xmin) / Nx dy = (ymax - ymin) / Ny - for j = 1:Ny+1 - for i = 1:Nx+1 + for j = 1:(Ny+1) + for i = 1:(Nx+1) vertices_C[i, j] = (xmin + (i - 1) * dx, ymin + (j - 1) * dy) end end @@ -18,15 +18,16 @@ function Cartesian_connectivity(Nx, Ny, xmin, xmax, ymin, ymax) cells = reshape(cell2ver, :) connectivity = GC.@preserve vertices cells Connectivity{4}(vertices, cells) end -function Cartesian_connectivity(Nx,Ny,Nz,xmin,xmax,ymin,ymax,zmin,zmax) +function Cartesian_connectivity(Nx, Ny, Nz, xmin, xmax, ymin, ymax, zmin, zmax) vertices_C = Array{NTuple{3,Float64}}(undef, Nx + 1, Ny + 1, Nz + 1) dx = (xmax - xmin) / Nx dy = (ymax - ymin) / Ny dz = (zmax - zmin) / Nz - for k = 1:Nz+1 - for j = 1:Ny+1 - for i = 1:Nx+1 - vertices_C[i, j, k] = (xmin + (i - 1) * dx, ymin + (j - 1) * dy, zmin + (k - 1) * dz) + for k = 1:(Nz+1) + for j = 1:(Ny+1) + for i = 1:(Nx+1) + vertices_C[i, j, k] = + (xmin + (i - 1) * dx, ymin + (j - 1) * dy, zmin + (k - 1) * dz) end end end @@ -36,34 +37,48 @@ function Cartesian_connectivity(Nx,Ny,Nz,xmin,xmax,ymin,ymax,zmin,zmax) for k in axes(cell2ver, 3) for j in axes(cell2ver, 2) for i in axes(cell2ver, 1) - cell2ver[i, j, k] = (vL[i, j, k], vL[i+1, j, k], vL[i, j+1, k], vL[i+1, j+1, k], - vL[i, j, k+1], vL[i+1, j, k+1], vL[i, j+1, k+1], vL[i+1, j+1, k+1]) + cell2ver[i, j, k] = ( + vL[i, j, k], + vL[i+1, j, k], + vL[i, j+1, k], + vL[i+1, j+1, k], + vL[i, j, k+1], + vL[i+1, j, k+1], + vL[i, j+1, k+1], + vL[i+1, j+1, k+1], + ) end end end cells = reshape(cell2ver, :) connectivity = GC.@preserve vertices cells Connectivity{8}(vertices, cells) end -function set_connectivity(global_data::Global_Data{DIM}) where{DIM} +function set_connectivity(global_data::Global_Data{DIM}) where {DIM} domain = global_data.config.domain - periodic_dirs = ntuple(i -> begin - first_boundary = (i-1)*2 + 1 # 1, 3, 5 for i = 1, 2, 3 - second_boundary = first_boundary + 1 # 3, 5, 7 for i = 1, 2, 3 - nameof(typeof(domain[first_boundary]).parameters[1]) == :Period && - nameof(typeof(domain[second_boundary]).parameters[1]) == :Period - end, DIM) - + periodic_dirs = ntuple( + i -> begin + first_boundary = (i-1)*2 + 1 # 1, 3, 5 for i = 1, 2, 3 + second_boundary = first_boundary + 1 # 3, 5, 7 for i = 1, 2, 3 + nameof(typeof(domain[first_boundary]).parameters[1]) == :Period && + nameof(typeof(domain[second_boundary]).parameters[1]) == :Period + end, + DIM, + ) + if periodic_dirs != ntuple(_ -> false, DIM) connectivity_ps = set_periodic_connectivity(global_data, periodic_dirs) else - connectivity_ps = Cartesian_connectivity(global_data.config.trees_num..., global_data.config.geometry...) + connectivity_ps = Cartesian_connectivity( + global_data.config.trees_num..., + global_data.config.geometry..., + ) end return connectivity_ps end import ..P4estTypes.unsafe_vertices -function set_periodic_connectivity(global_data::Global_Data{DIM}, periodic_dirs) where{DIM} +function set_periodic_connectivity(global_data::Global_Data{DIM}, periodic_dirs) where {DIM} geometry = global_data.config.geometry bounds = if DIM == 2 ntuple(i -> begin @@ -82,22 +97,24 @@ function set_periodic_connectivity(global_data::Global_Data{DIM}, periodic_dirs) (geometry[min_idx], geometry[max_idx]) # (xmin,xmax), (ymin,ymax), (zmin,zmax) end, 3) end - - connectivity_ps = P4estTypes.brick( - Tuple(global_data.config.trees_num), - periodic_dirs - ) + + connectivity_ps = P4estTypes.brick(Tuple(global_data.config.trees_num), periodic_dirs) vertices = unsafe_vertices(connectivity_ps) for i in eachindex(vertices) normalized_coords = vertices[i] - - vertices[i] = ntuple(j -> begin - if j <= DIM - normalized_coords[j] * (bounds[j][2] - bounds[j][1])/global_data.config.trees_num[j] + bounds[j][1] - else - 0.0 - end - end, 3) + + vertices[i] = ntuple( + j -> begin + if j <= DIM + normalized_coords[j] * + (bounds[j][2] - bounds[j][1])/global_data.config.trees_num[j] + + bounds[j][1] + else + 0.0 + end + end, + 3, + ) end return connectivity_ps -end \ No newline at end of file +end diff --git a/src/Mesh/Mesh.jl b/src/Mesh/Mesh.jl index b3a1ffd..677af98 100644 --- a/src/Mesh/Mesh.jl +++ b/src/Mesh/Mesh.jl @@ -1,3 +1,3 @@ include("Connectivity.jl") include("Neighbor.jl") -export initialize_neighbor_data! \ No newline at end of file +export initialize_neighbor_data! diff --git a/src/Mesh/Neighbor.jl b/src/Mesh/Neighbor.jl index ed275ee..6156cf4 100644 --- a/src/Mesh/Neighbor.jl +++ b/src/Mesh/Neighbor.jl @@ -6,7 +6,7 @@ function access_neighbor( global_data::Global_Data{DIM,NDF}, ghost_wrap::Array{AbstractGhostPsData}, dir::Integer, -) where{DIM,NDF} +) where {DIM,NDF} neighbor_quads = sc_array_new(sizeof(Ptr{p4est_quadrant_t})) neighbor_encs = sc_array_new(sizeof(Cint)) neighbor_qid = sc_array_new(sizeof(Cint)) @@ -73,7 +73,7 @@ function access_neighbor( global_data::Global_Data{DIM,NDF}, ghost_wrap::Array{AbstractGhostPsData}, dir::Integer, -) where{DIM,NDF} +) where {DIM,NDF} neighbor_quads = sc_array_new(sizeof(Ptr{p8est_quadrant_t})) neighbor_encs = sc_array_new(sizeof(Cint)) neighbor_qid = sc_array_new(sizeof(Cint)) @@ -141,7 +141,7 @@ $(TYPEDSIGNATURES) function initialize_neighbor_data!(ip::PointerWrapper{p4est_iter_volume_info_t}, data, dp) amr = unsafe_pointer_to_objref(data) ps_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - isa(ps_data,InsideSolidData) && return nothing + isa(ps_data, InsideSolidData) && return nothing for i = 1:face_num_2d ps_data.neighbor.data[i], ps_data.neighbor.state[i] = access_neighbor( pointer(ip.p4est), @@ -152,15 +152,16 @@ function initialize_neighbor_data!(ip::PointerWrapper{p4est_iter_volume_info_t}, ) end if ps_data.bound_enc<0 - for i in 4:7 # Corners are indexed with z-order, as well. - data,state = access_neighbor( + for i = 4:7 # Corners are indexed with z-order, as well. + data, state = access_neighbor( pointer(ip.p4est), local_quadid(ip), amr.global_data, amr.ghost.ghost_wrap, i, ) - push!(ps_data.neighbor.data,data);push!(ps_data.neighbor.state,state) + push!(ps_data.neighbor.data, data); + push!(ps_data.neighbor.state, state) end end return nothing @@ -172,7 +173,7 @@ $(TYPEDSIGNATURES) function initialize_neighbor_data!(ip::PointerWrapper{p8est_iter_volume_info_t}, data, dp) amr = unsafe_pointer_to_objref(data) ps_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - isa(ps_data,InsideSolidData) && return nothing + isa(ps_data, InsideSolidData) && return nothing for i = 1:face_num_3d ps_data.neighbor.data[i], ps_data.neighbor.state[i] = access_neighbor( pointer(ip.p4est), @@ -183,15 +184,16 @@ function initialize_neighbor_data!(ip::PointerWrapper{p8est_iter_volume_info_t}, ) end if ps_data.bound_enc<0 - for i in 6:25 # Corners are indexed with z-order, as well. - data,state = access_neighbor( + for i = 6:25 # Corners are indexed with z-order, as well. + data, state = access_neighbor( pointer(ip.p4est), local_quadid(ip), amr.global_data, amr.ghost.ghost_wrap, i, ) - push!(ps_data.neighbor.data,data);push!(ps_data.neighbor.state,state) + push!(ps_data.neighbor.data, data); + push!(ps_data.neighbor.state, state) end end return nothing @@ -222,7 +224,7 @@ face_micro_nums: 1->4时记1,只需在state=-1时+0.25即可 function update_neighbor_kernel!(ip::PointerWrapper{p4est_iter_volume_info_t}, data, dp) amr = unsafe_pointer_to_objref(data) ps_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - isa(ps_data,InsideSolidData) && return nothing + isa(ps_data, InsideSolidData) && return nothing for i = 1:face_num_2d ps_data.neighbor.data[i], ps_data.neighbor.state[i] = access_neighbor( pointer(ip.p4est), @@ -233,8 +235,8 @@ function update_neighbor_kernel!(ip::PointerWrapper{p4est_iter_volume_info_t}, d ) end if length(ps_data.neighbor.data) > 4 - for i in 4:7 - ps_data.neighbor.data[i+1],ps_data.neighbor.state[i+1] = access_neighbor( + for i = 4:7 + ps_data.neighbor.data[i+1], ps_data.neighbor.state[i+1] = access_neighbor( pointer(ip.p4est), local_quadid(ip), amr.global_data, @@ -243,15 +245,16 @@ function update_neighbor_kernel!(ip::PointerWrapper{p4est_iter_volume_info_t}, d ) end elseif ps_data.bound_enc<0 - for i in 4:7 - data,state = access_neighbor( + for i = 4:7 + data, state = access_neighbor( pointer(ip.p4est), local_quadid(ip), amr.global_data, amr.ghost.ghost_wrap, i, ) - push!(ps_data.neighbor.data,data);push!(ps_data.neighbor.state,state) + push!(ps_data.neighbor.data, data); + push!(ps_data.neighbor.state, state) end end return nothing @@ -259,7 +262,7 @@ end function update_neighbor_kernel!(ip::PointerWrapper{p8est_iter_volume_info_t}, data, dp) amr = unsafe_pointer_to_objref(data) ps_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - isa(ps_data,InsideSolidData) && return nothing + isa(ps_data, InsideSolidData) && return nothing for i = 1:face_num_3d ps_data.neighbor.data[i], ps_data.neighbor.state[i] = access_neighbor( pointer(ip.p4est), @@ -270,8 +273,8 @@ function update_neighbor_kernel!(ip::PointerWrapper{p8est_iter_volume_info_t}, d ) end if length(ps_data.neighbor.data) > 6 - for i in 6:25 #6~17: edge, 18~25: corner - ps_data.neighbor.data[i+1],ps_data.neighbor.state[i+1] = access_neighbor( + for i = 6:25 #6~17: edge, 18~25: corner + ps_data.neighbor.data[i+1], ps_data.neighbor.state[i+1] = access_neighbor( pointer(ip.p4est), local_quadid(ip), amr.global_data, @@ -280,15 +283,16 @@ function update_neighbor_kernel!(ip::PointerWrapper{p8est_iter_volume_info_t}, d ) end elseif ps_data.bound_enc<0 - for i in 6:25 - data,state = access_neighbor( + for i = 6:25 + data, state = access_neighbor( pointer(ip.p4est), local_quadid(ip), amr.global_data, amr.ghost.ghost_wrap, i, ) - push!(ps_data.neighbor.data,data);push!(ps_data.neighbor.state,state) + push!(ps_data.neighbor.data, data); + push!(ps_data.neighbor.state, state) end end return nothing @@ -310,7 +314,7 @@ function update_neighbor!(p4est::Ptr{p4est_t}, amr::KitAMR_Data) global_data = amr.global_data p4est_mesh_destroy(global_data.forest.mesh) global_data.forest.mesh = - p4est_mesh_new_ext(p4est, global_data.forest.ghost, 1, 1, P4EST_CONNECT_FULL) + p4est_mesh_new_ext(p4est, global_data.forest.ghost, 1, 1, P4EST_CONNECT_FULL) update_neighbor_kernel!(p4est, amr) end function update_neighbor!(p4est::Ptr{p8est_t}, amr::KitAMR_Data) diff --git a/src/P4est/P4est.jl b/src/P4est/P4est.jl index 3446f97..02d0a32 100644 --- a/src/P4est/P4est.jl +++ b/src/P4est/P4est.jl @@ -1,2 +1,2 @@ include("P4est_wrap.jl") -export AMR_ghost_new, AMR_mesh_new \ No newline at end of file +export AMR_ghost_new, AMR_mesh_new diff --git a/src/P4est/P4est_wrap.jl b/src/P4est/P4est_wrap.jl index 80db407..aa22dfc 100644 --- a/src/P4est/P4est_wrap.jl +++ b/src/P4est/P4est_wrap.jl @@ -44,37 +44,45 @@ function quad_to_cell( qp.z[] + halflength, mid, ) - ds = 2. * (mid - quad) + ds = 2.0 * (mid - quad) end (ds, mid) end -function iPointerWrapper(p::Ptr{T},i::Integer) where{T} +function iPointerWrapper(p::Ptr{T}, i::Integer) where {T} return PointerWrapper(p + sizeof(T) * i) end -function iPointerWrapper(pw::PointerWrapper{T},i::Integer) where{T} +function iPointerWrapper(pw::PointerWrapper{T}, i::Integer) where {T} return PointerWrapper(pointer(pw)+i*sizeof(T)) end -function iPointerWrapper(p::Ptr{sc_array_t},::Type{T},i::Integer) where{T} - return PointerWrapper(T,pointer(PointerWrapper(p).array)+i*sizeof(T)) +function iPointerWrapper(p::Ptr{sc_array_t}, ::Type{T}, i::Integer) where {T} + return PointerWrapper(T, pointer(PointerWrapper(p).array)+i*sizeof(T)) end -function iPointerWrapper(p::Ptr{sc_array_t},::Type{Ptr{T}},i::Integer) where{T} # to avoid the dereference of the Pointer-type +function iPointerWrapper(p::Ptr{sc_array_t}, ::Type{Ptr{T}}, i::Integer) where {T} # to avoid the dereference of the Pointer-type return PointerWrapper(Ptr{Ptr{T}}(pointer(PointerWrapper(p).array)+i*sizeof(Ptr{T}))) end -function iPointerWrapper(pw::PointerWrapper{sc_array_t},::Type{T},i::Integer) where{T} - return PointerWrapper(T,pointer(pw.array)+i*sizeof(T)) +function iPointerWrapper(pw::PointerWrapper{sc_array_t}, ::Type{T}, i::Integer) where {T} + return PointerWrapper(T, pointer(pw.array)+i*sizeof(T)) end -function iPointerWrapper(pw::PointerWrapper{sc_array_t},::Type{Ptr{T}},i::Integer) where{T} +function iPointerWrapper( + pw::PointerWrapper{sc_array_t}, + ::Type{Ptr{T}}, + i::Integer, +) where {T} return PointerWrapper(Ptr{Ptr{T}}(pointer(pw.array)+i*sizeof(Ptr{T}))) end -function iPointerWrapper(pw::PointerWrapper{NTuple{N,T}},::Type{T},i::Integer) where{N,T} - return PointerWrapper(T,pointer(pw)+i*sizeof(T)) +function iPointerWrapper(pw::PointerWrapper{NTuple{N,T}}, ::Type{T}, i::Integer) where {N,T} + return PointerWrapper(T, pointer(pw)+i*sizeof(T)) end -function iPointerWrapper(pw::PointerWrapper{NTuple{N,Ptr{T}}},::Type{Ptr{T}},i::Integer) where{N,T} +function iPointerWrapper( + pw::PointerWrapper{NTuple{N,Ptr{T}}}, + ::Type{Ptr{T}}, + i::Integer, +) where {N,T} return PointerWrapper(Ptr{Ptr{T}}(pointer(pw)+i*sizeof(Ptr{T}))) end -function local_quadid(p4est::PointerWrapper{p4est_t},treeid::Integer,quadid::Integer) +function local_quadid(p4est::PointerWrapper{p4est_t}, treeid::Integer, quadid::Integer) tp = iPointerWrapper(p4est.trees, p4est_tree_t, treeid) return tp.quadrants_offset[] + quadid end @@ -82,7 +90,10 @@ function local_quadid(ip::PointerWrapper{p4est_iter_volume_info_t}) tp = iPointerWrapper(ip.p4est.trees, p4est_tree_t, ip.treeid[]) return tp.quadrants_offset[] + ip.quadid[] end -function local_quadid(ip::PointerWrapper{p4est_iter_corner_info_t},side::PointerWrapper{p4est_iter_corner_side_t}) +function local_quadid( + ip::PointerWrapper{p4est_iter_corner_info_t}, + side::PointerWrapper{p4est_iter_corner_side_t}, +) tp = iPointerWrapper(ip.p4est.trees, p4est_tree_t, side.treeid[]) return tp.quadrants_offset[] + side.quadid[] end @@ -90,16 +101,19 @@ function local_quadid(ip::PointerWrapper{p8est_iter_volume_info_t}) tp = iPointerWrapper(ip.p4est.trees, p8est_tree_t, ip.treeid[]) return tp.quadrants_offset[] + ip.quadid[] end -function local_quadid(ip::PointerWrapper{p8est_iter_corner_info_t},side::PointerWrapper{p8est_iter_corner_side_t}) +function local_quadid( + ip::PointerWrapper{p8est_iter_corner_info_t}, + side::PointerWrapper{p8est_iter_corner_side_t}, +) tp = iPointerWrapper(ip.p4est.trees, p4est_tree_t, side.treeid[]) return tp.quadrants_offset[] + side.quadid[] end function global_quadid(ip::PW_pxest_iter_volume_info_t) gfq = unsafe_wrap( - Vector{Int}, - pointer(ip.p4est.global_first_quadrant), - MPI.Comm_size(MPI.COMM_WORLD) + 1, - ) + Vector{Int}, + pointer(ip.p4est.global_first_quadrant), + MPI.Comm_size(MPI.COMM_WORLD) + 1, + ) return local_quadid(ip) + gfq[MPI.Comm_rank(MPI.COMM_WORLD)+1] end @@ -305,7 +319,7 @@ function AMR_4est_volume_iterate( @cfunction($volume_iter_fn, Cvoid, (Ptr{p8est_iter_volume_info}, Ptr{Nothing})), C_NULL, C_NULL, - C_NULL + C_NULL, ) end @@ -335,7 +349,7 @@ function AMR_4est_volume_iterate( @cfunction($volume_iter_fn, Cvoid, (Ptr{p8est_iter_volume_info}, Ptr{Nothing})), C_NULL, C_NULL, - C_NULL + C_NULL, ) end @@ -381,7 +395,7 @@ function AMR_4est_face_iterate( C_NULL, face_iter_fn, C_NULL, - C_NULL + C_NULL, ) end @@ -411,7 +425,7 @@ function AMR_4est_face_iterate( C_NULL, face_iter_fn, C_NULL, - C_NULL + C_NULL, ) end @@ -440,30 +454,42 @@ function AMR_ghost_new(p4est::Ptr{p8est_t}) GC.@preserve p4est p8est_ghost_new(p4est, P8EST_CONNECT_FULL) end -function AMR_partition(p4est::Ptr{p4est_t},weight_fn::T=C_NULL) where{T<:Union{Ptr{Nothing},Base.CFunction}} +function AMR_partition( + p4est::Ptr{p4est_t}, + weight_fn::T = C_NULL, +) where {T<:Union{Ptr{Nothing},Base.CFunction}} p4est_partition(p4est, 0, weight_fn) end -function AMR_partition(weight_fn::Function,p4est::Ptr{p4est_t}) - AMR_partition(p4est,@cfunction($weight_fn,Cint,(Ptr{p4est_t},p4est_topidx_t,Ptr{p4est_quadrant_t}))) +function AMR_partition(weight_fn::Function, p4est::Ptr{p4est_t}) + AMR_partition( + p4est, + @cfunction($weight_fn, Cint, (Ptr{p4est_t}, p4est_topidx_t, Ptr{p4est_quadrant_t})) + ) end -function AMR_partition(p4est::Ptr{p8est_t},weight_fn::T=C_NULL) where{T<:Union{Ptr{Nothing},Base.CFunction}} +function AMR_partition( + p4est::Ptr{p8est_t}, + weight_fn::T = C_NULL, +) where {T<:Union{Ptr{Nothing},Base.CFunction}} p8est_partition(p4est, 0, weight_fn) end -function AMR_partition(weight_fn::Function,p4est::Ptr{p8est_t}) - AMR_partition(p4est,@cfunction($weight_fn,Cint,(Ptr{p8est_t},p4est_topidx_t,Ptr{p8est_quadrant_t}))) +function AMR_partition(weight_fn::Function, p4est::Ptr{p8est_t}) + AMR_partition( + p4est, + @cfunction($weight_fn, Cint, (Ptr{p8est_t}, p4est_topidx_t, Ptr{p8est_quadrant_t})) + ) end """ $(TYPEDSIGNATURES) """ -function AMR_mesh_new(p4est::Ptr{p4est_t},ghost::Ptr{p4est_ghost_t}) - GC.@preserve p4est ghost p4est_mesh_new_ext(p4est,ghost,1,1,P4EST_CONNECT_FULL) +function AMR_mesh_new(p4est::Ptr{p4est_t}, ghost::Ptr{p4est_ghost_t}) + GC.@preserve p4est ghost p4est_mesh_new_ext(p4est, ghost, 1, 1, P4EST_CONNECT_FULL) end """ $(TYPEDSIGNATURES) """ -function AMR_mesh_new(p4est::Ptr{p8est_t},ghost::Ptr{p8est_ghost_t}) - GC.@preserve p4est ghost p8est_mesh_new_ext(p4est,ghost,1,1,P8EST_CONNECT_FULL) +function AMR_mesh_new(p4est::Ptr{p8est_t}, ghost::Ptr{p8est_ghost_t}) + GC.@preserve p4est ghost p8est_mesh_new_ext(p4est, ghost, 1, 1, P8EST_CONNECT_FULL) end @@ -483,8 +509,14 @@ function unsafe_wrap_sc(::Type{T}, sc_array_pw::PointerWrapper{sc_array}) where return unsafe_wrap(Vector{T}, Ptr{T}(pointer(array)), elem_count) end -function AMR_volume_iterate(f::Function,forest::Ptr{p4est_t};ghost=C_NULL,user_data=C_NULL,data_type = P4est_PS_Data) - function iter_fn(info,data) +function AMR_volume_iterate( + f::Function, + forest::Ptr{p4est_t}; + ghost = C_NULL, + user_data = C_NULL, + data_type = P4est_PS_Data, +) + function iter_fn(info, data) GC.@preserve info data data_type begin ip = PointerWrapper(info) dp = PointerWrapper(data_type, ip.quad.p.user_data[]) @@ -496,13 +528,19 @@ function AMR_volume_iterate(f::Function,forest::Ptr{p4est_t};ghost=C_NULL,user_d forest, ghost, user_data, - @cfunction($iter_fn,Cvoid, (Ptr{p4est_iter_volume_info}, Ptr{Nothing})), + @cfunction($iter_fn, Cvoid, (Ptr{p4est_iter_volume_info}, Ptr{Nothing})), C_NULL, C_NULL, ) end -function AMR_volume_iterate(f::Function,forest::Ptr{p8est_t};ghost=C_NULL,user_data=C_NULL,data_type = P4est_PS_Data) - function iter_fn(info,data) +function AMR_volume_iterate( + f::Function, + forest::Ptr{p8est_t}; + ghost = C_NULL, + user_data = C_NULL, + data_type = P4est_PS_Data, +) + function iter_fn(info, data) GC.@preserve info data data_type begin ip = PointerWrapper(info) dp = PointerWrapper(data_type, ip.quad.p.user_data[]) @@ -514,14 +552,19 @@ function AMR_volume_iterate(f::Function,forest::Ptr{p8est_t};ghost=C_NULL,user_d forest, ghost, user_data, - @cfunction($iter_fn,Cvoid, (Ptr{p8est_iter_volume_info}, Ptr{Nothing})), + @cfunction($iter_fn, Cvoid, (Ptr{p8est_iter_volume_info}, Ptr{Nothing})), C_NULL, C_NULL, C_NULL, ) end -function AMR_corner_iterate(f::Function,forest::Ptr{p4est_t};ghost=C_NULL,user_data=C_NULL) - function iter_fn(info,data) +function AMR_corner_iterate( + f::Function, + forest::Ptr{p4est_t}; + ghost = C_NULL, + user_data = C_NULL, +) + function iter_fn(info, data) GC.@preserve info data begin ip = PointerWrapper(info) GC.@preserve ip f(ip, data) @@ -534,11 +577,16 @@ function AMR_corner_iterate(f::Function,forest::Ptr{p4est_t};ghost=C_NULL,user_d user_data, C_NULL, C_NULL, - @cfunction($iter_fn,Cvoid, (Ptr{p4est_iter_corner_info}, Ptr{Nothing})), + @cfunction($iter_fn, Cvoid, (Ptr{p4est_iter_corner_info}, Ptr{Nothing})), ) end -function AMR_face_iterate(f::Function,forest::Ptr{p4est_t};ghost=C_NULL,user_data=C_NULL) - function iter_fn(info,data) +function AMR_face_iterate( + f::Function, + forest::Ptr{p4est_t}; + ghost = C_NULL, + user_data = C_NULL, +) + function iter_fn(info, data) GC.@preserve info data begin ip = PointerWrapper(info) GC.@preserve ip f(ip, data) @@ -550,12 +598,17 @@ function AMR_face_iterate(f::Function,forest::Ptr{p4est_t};ghost=C_NULL,user_dat ghost, user_data, C_NULL, - @cfunction($iter_fn,Cvoid, (Ptr{p4est_iter_face_info}, Ptr{Nothing})), + @cfunction($iter_fn, Cvoid, (Ptr{p4est_iter_face_info}, Ptr{Nothing})), C_NULL, ) end -function AMR_face_iterate(f::Function,forest::Ptr{p8est_t};ghost=C_NULL,user_data=C_NULL) - function iter_fn(info,data) +function AMR_face_iterate( + f::Function, + forest::Ptr{p8est_t}; + ghost = C_NULL, + user_data = C_NULL, +) + function iter_fn(info, data) GC.@preserve info data begin ip = PointerWrapper(info) GC.@preserve ip f(ip, data) @@ -567,8 +620,8 @@ function AMR_face_iterate(f::Function,forest::Ptr{p8est_t};ghost=C_NULL,user_dat ghost, user_data, C_NULL, - @cfunction($iter_fn,Cvoid, (Ptr{p8est_iter_face_info}, Ptr{Nothing})), + @cfunction($iter_fn, Cvoid, (Ptr{p8est_iter_face_info}, Ptr{Nothing})), C_NULL, C_NULL, ) -end \ No newline at end of file +end diff --git a/src/Parallel/Ghost.jl b/src/Parallel/Ghost.jl index 37abd55..7c3f486 100644 --- a/src/Parallel/Ghost.jl +++ b/src/Parallel/Ghost.jl @@ -1,6 +1,6 @@ -size_Ghost_Data(vs_num,DIM,NDF) = 3 * DIM + 4 + NDF * vs_num -size_Ghost_Slope(vs_num,DIM,NDF) = vs_num * DIM * NDF+DIM*(DIM+2) -size_Ghost_VS_Structure(vs_num,DIM) = vs_num * (DIM + 2) +size_Ghost_Data(vs_num, DIM, NDF) = 3 * DIM + 4 + NDF * vs_num +size_Ghost_Slope(vs_num, DIM, NDF) = vs_num * DIM * NDF+DIM*(DIM+2) +size_Ghost_VS_Structure(vs_num, DIM) = vs_num * (DIM + 2) """ $(TYPEDSIGNATURES) Get the globally largest number of the velocity cells in ghost layers. @@ -8,16 +8,24 @@ Get the globally largest number of the velocity cells in ghost layers. function get_vs_num(forest::P_pxest_t, ghost::P_pxest_ghost_t) get_vs_num(PointerWrapper(forest), PointerWrapper(ghost)) end -function pw_mirror_quadrant(pp::PointerWrapper{p4est_t},gp::PointerWrapper{p4est_ghost_t},i::Integer) - pm = iPointerWrapper(gp.mirrors, p4est_quadrant_t, i - 1) - pt = iPointerWrapper(pp.trees, p4est_tree_t, pm.p.piggy3.which_tree[]) - pq = iPointerWrapper( - pt.quadrants, - p4est_quadrant_t, - pm.p.piggy3.local_num[] - pt.quadrants_offset[], - ) +function pw_mirror_quadrant( + pp::PointerWrapper{p4est_t}, + gp::PointerWrapper{p4est_ghost_t}, + i::Integer, +) + pm = iPointerWrapper(gp.mirrors, p4est_quadrant_t, i - 1) + pt = iPointerWrapper(pp.trees, p4est_tree_t, pm.p.piggy3.which_tree[]) + pq = iPointerWrapper( + pt.quadrants, + p4est_quadrant_t, + pm.p.piggy3.local_num[] - pt.quadrants_offset[], + ) end -function pw_mirror_quadrant(pp::PointerWrapper{p8est_t},gp::PointerWrapper{p8est_ghost_t},i::Integer) +function pw_mirror_quadrant( + pp::PointerWrapper{p8est_t}, + gp::PointerWrapper{p8est_ghost_t}, + i::Integer, +) pm = iPointerWrapper(gp.mirrors, p8est_quadrant_t, i - 1) pt = iPointerWrapper(pp.trees, p8est_tree_t, pm.p.piggy3.which_tree[]) pq = iPointerWrapper( @@ -29,44 +37,52 @@ end function get_vs_num(pp::PW_pxest_t, gp::PW_pxest_ghost_t) vs_num = 0 for i = 1:gp.mirrors.elem_count[] - pq = pw_mirror_quadrant(pp,gp,i) + pq = pw_mirror_quadrant(pp, gp, i) dp = PointerWrapper(P4est_PS_Data, pq.p.user_data[]) ps_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - isa(ps_data,InsideSolidData)&&continue + isa(ps_data, InsideSolidData)&&continue vs_num = max(vs_num, ps_data.vs_data.vs_num) end vs_num = MPI.Allreduce(vs_num, max, MPI.COMM_WORLD) end -function get_mirror_data_inner!(ps_data::PS_Data{DIM,NDF}, vs_temp::AbstractVector) where{DIM,NDF} +function get_mirror_data_inner!( + ps_data::PS_Data{DIM,NDF}, + vs_temp::AbstractVector, +) where {DIM,NDF} vs_data = ps_data.vs_data vs_num = vs_data.vs_num - vs_temp[1:NDF*vs_num] .= reshape(vs_data.df, vs_num * NDF) + vs_temp[1:(NDF*vs_num)] .= reshape(vs_data.df, vs_num * NDF) end # function get_mirror_data_inner!(::InsideSolidData,vs_temp::AbstractVector) # vs_temp[1] = EPS # Flag indicating InsideSolidData # end -function get_mirror_data(ps4est, global_data::Global_Data{DIM,NDF}) where{DIM,NDF} +function get_mirror_data(ps4est, global_data::Global_Data{DIM,NDF}) where {DIM,NDF} GC.@preserve ps4est global_data begin gp = PointerWrapper(global_data.forest.ghost) pp = PointerWrapper(ps4est) global_data.status.max_vs_num = vs_num = get_vs_num(pp, gp) mirror_data_pointers = Array{Ptr{Cdouble}}(undef, gp.mirrors.elem_count[]) for i = 1:gp.mirrors.elem_count[] - pq = pw_mirror_quadrant(pp,gp,i) + pq = pw_mirror_quadrant(pp, gp, i) dp = PointerWrapper(P4est_PS_Data, pq.p.user_data[]) ps_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - p = Ptr{Cdouble}(sc_malloc(P4est.package_id(), (3 * DIM + 4 + NDF * vs_num) * sizeof(Cdouble))) + p = Ptr{Cdouble}( + sc_malloc( + P4est.package_id(), + (3 * DIM + 4 + NDF * vs_num) * sizeof(Cdouble), + ), + ) ap = Base.unsafe_wrap(Vector{Cdouble}, p, 3 * DIM + 4 + NDF * vs_num) offset = 0 - if isa(ps_data,InsideSolidData) + if isa(ps_data, InsideSolidData) ap[1] = EPS else ap[1:(offset+=DIM)] .= ps_data.ds - ap[offset+1:(offset+=DIM)] .= ps_data.midpoint - ap[offset+1:(offset+=DIM+2)] .= ps_data.w + ap[(offset+1):(offset+=DIM)] .= ps_data.midpoint + ap[(offset+1):(offset+=DIM+2)] .= ps_data.w ap[offset+=1] = ps_data.vs_data.vs_num ap[offset+=1] = ps_data.bound_enc - vs_temp = @view(ap[offset+1:(offset+=NDF*vs_num)]) + vs_temp = @view(ap[(offset+1):(offset+=NDF*vs_num)]) get_mirror_data_inner!(ps_data, vs_temp) end mirror_data_pointers[i] = p @@ -74,26 +90,35 @@ function get_mirror_data(ps4est, global_data::Global_Data{DIM,NDF}) where{DIM,ND end return mirror_data_pointers end -function get_mirror_slope_inner!(ps_data::PS_Data{DIM,NDF}, vs_temp::AbstractVector) where{DIM,NDF} +function get_mirror_slope_inner!( + ps_data::PS_Data{DIM,NDF}, + vs_temp::AbstractVector, +) where {DIM,NDF} vs_data = ps_data.vs_data vs_num = size(vs_data.weight, 1) vs_temp[1:(vs_num*NDF*DIM)] .= reshape(vs_data.sdf, vs_num * NDF * DIM) - vs_temp[vs_num*NDF*DIM+1:vs_num*NDF*DIM+DIM*(DIM+2)] .= reshape(ps_data.sw, DIM*(DIM+2)) + vs_temp[(vs_num*NDF*DIM+1):(vs_num*NDF*DIM+DIM*(DIM+2))] .= + reshape(ps_data.sw, DIM*(DIM+2)) end -function get_mirror_slope_inner!(::InsideSolidData, vs_temp::AbstractVector) +function get_mirror_slope_inner!(::InsideSolidData, vs_temp::AbstractVector) vs_temp[1] = EPS end -function get_mirror_slope(ps4est, global_data::Global_Data{DIM,NDF}) where{DIM,NDF} +function get_mirror_slope(ps4est, global_data::Global_Data{DIM,NDF}) where {DIM,NDF} GC.@preserve ps4est global_data begin gp = PointerWrapper(global_data.forest.ghost) pp = PointerWrapper(ps4est) vs_num = global_data.status.max_vs_num mirror_slope_pointers = Array{Ptr{Cdouble}}(undef, gp.mirrors.elem_count[]) for i = 1:gp.mirrors.elem_count[] - pq = pw_mirror_quadrant(pp,gp,i) + pq = pw_mirror_quadrant(pp, gp, i) dp = PointerWrapper(P4est_PS_Data, pq.p.user_data[]) ps_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - p = Ptr{Cdouble}(sc_malloc(P4est.package_id(), (vs_num * DIM * NDF+DIM*(DIM+2)) * sizeof(Cdouble))) + p = Ptr{Cdouble}( + sc_malloc( + P4est.package_id(), + (vs_num * DIM * NDF+DIM*(DIM+2)) * sizeof(Cdouble), + ), + ) ap = Base.unsafe_wrap(Vector{Cdouble}, p, vs_num * DIM * NDF+DIM*(DIM+2)) get_mirror_slope_inner!(ps_data, ap) mirror_slope_pointers[i] = p @@ -101,94 +126,106 @@ function get_mirror_slope(ps4est, global_data::Global_Data{DIM,NDF}) where{DIM,N end return mirror_slope_pointers end -function get_mirror_structure_inner!(ps_data::PS_Data{DIM}, weight_temp, level_temp, midpoint_temp) where{DIM} +function get_mirror_structure_inner!( + ps_data::PS_Data{DIM}, + weight_temp, + level_temp, + midpoint_temp, +) where {DIM} vs_data = ps_data.vs_data vs_num = vs_data.vs_num weight_temp[1:vs_num] .= vs_data.weight level_temp[1:vs_num] .= vs_data.level midpoint_temp[1:(vs_num*DIM)] .= reshape(vs_data.midpoint, vs_num * DIM) end -function get_mirror_structure_inner!(::InsideSolidData, weight_temp, level_temp, midpoint_temp) +function get_mirror_structure_inner!( + ::InsideSolidData, + weight_temp, + level_temp, + midpoint_temp, +) weight_temp[1] = EPS level_temp[1] = EPS midpoint_temp[1] = EPS end -function get_mirror_structure(ps4est, global_data::Global_Data{DIM,NDF}) where{DIM,NDF} +function get_mirror_structure(ps4est, global_data::Global_Data{DIM,NDF}) where {DIM,NDF} GC.@preserve ps4est global_data begin gp = PointerWrapper(global_data.forest.ghost) pp = PointerWrapper(ps4est) vs_num = global_data.status.max_vs_num mirror_structure_pointers = Array{Ptr{Cdouble}}(undef, gp.mirrors.elem_count[]) for i = 1:gp.mirrors.elem_count[] - pq = pw_mirror_quadrant(pp,gp,i) + pq = pw_mirror_quadrant(pp, gp, i) dp = PointerWrapper(P4est_PS_Data, pq.p.user_data[]) ps_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - p = Ptr{Cdouble}(sc_malloc(P4est.package_id(), vs_num * (DIM + 2) * sizeof(Cdouble))) + p = Ptr{Cdouble}( + sc_malloc(P4est.package_id(), vs_num * (DIM + 2) * sizeof(Cdouble)), + ) ap = Base.unsafe_wrap(Vector{Cdouble}, p, vs_num * (DIM + 2)) weight_temp = @view(ap[1:vs_num]) - level_temp = @view(ap[vs_num+1:vs_num*2]) - midpoint_temp = @view(ap[vs_num*2+1:vs_num*(DIM+2)]) + level_temp = @view(ap[(vs_num+1):(vs_num*2)]) + midpoint_temp = @view(ap[(vs_num*2+1):(vs_num*(DIM+2))]) get_mirror_structure_inner!(ps_data, weight_temp, level_temp, midpoint_temp) mirror_structure_pointers[i] = p end return mirror_structure_pointers end end -function update_mirror_data!(ps4est, amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function update_mirror_data!(ps4est, amr::KitAMR_Data{DIM,NDF}) where {DIM,NDF} GC.@preserve ps4est amr begin mirror_data_pointers = amr.ghost.ghost_exchange.mirror_data_pointers vs_num = amr.global_data.status.max_vs_num gp = PointerWrapper(amr.global_data.forest.ghost) pp = PointerWrapper(ps4est) for i in eachindex(mirror_data_pointers) - pq = pw_mirror_quadrant(pp,gp,i) + pq = pw_mirror_quadrant(pp, gp, i) dp = PointerWrapper(P4est_PS_Data, pq.p.user_data[]) ps_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - isa(ps_data,InsideSolidData)&&continue + isa(ps_data, InsideSolidData)&&continue ap = Base.unsafe_wrap( Vector{Cdouble}, mirror_data_pointers[i], 3 * DIM + 4 + NDF * vs_num, ) - ap[DIM*2+1:DIM*3+2] .= ps_data.w - vs_temp = @view(ap[3*DIM+4+1:end]) + ap[(DIM*2+1):(DIM*3+2)] .= ps_data.w + vs_temp = @view(ap[(3*DIM+4+1):end]) get_mirror_data_inner!(ps_data, vs_temp) end end end -function update_solid_mirror_data!(ps4est,amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function update_solid_mirror_data!(ps4est, amr::KitAMR_Data{DIM,NDF}) where {DIM,NDF} GC.@preserve ps4est amr begin mirror_data_pointers = amr.ghost.ghost_exchange.mirror_data_pointers vs_num = amr.global_data.status.max_vs_num gp = PointerWrapper(amr.global_data.forest.ghost) pp = PointerWrapper(ps4est) for i in eachindex(mirror_data_pointers) - pq = pw_mirror_quadrant(pp,gp,i) + pq = pw_mirror_quadrant(pp, gp, i) dp = PointerWrapper(P4est_PS_Data, pq.p.user_data[]) ps_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - (isa(ps_data,InsideSolidData)||ps_data.bound_enc>=0)&&continue + (isa(ps_data, InsideSolidData)||ps_data.bound_enc>=0)&&continue ap = Base.unsafe_wrap( Vector{Cdouble}, mirror_data_pointers[i], 3 * DIM + 4 + NDF * vs_num, # ds(DIM), midpoint(DIM), w(DIM+2), vs_num(1), bound_enc(1) ) - ap[DIM*2+1:DIM*3+2] .= ps_data.w - vs_temp = @view(ap[3*DIM+4+1:end]) + ap[(DIM*2+1):(DIM*3+2)] .= ps_data.w + vs_temp = @view(ap[(3*DIM+4+1):end]) get_mirror_data_inner!(ps_data, vs_temp) end end end -function update_mirror_slope!(ps4est, amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function update_mirror_slope!(ps4est, amr::KitAMR_Data{DIM,NDF}) where {DIM,NDF} GC.@preserve ps4est amr begin mirror_slope_pointers = amr.ghost.ghost_exchange.mirror_slope_pointers vs_num = amr.global_data.status.max_vs_num gp = PointerWrapper(amr.global_data.forest.ghost) pp = PointerWrapper(ps4est) for i in eachindex(mirror_slope_pointers) - pq = pw_mirror_quadrant(pp,gp,i) + pq = pw_mirror_quadrant(pp, gp, i) dp = PointerWrapper(P4est_PS_Data, pq.p.user_data[]) ps_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - isa(ps_data,InsideSolidData)&&continue + isa(ps_data, InsideSolidData)&&continue ap = Base.unsafe_wrap( Vector{Cdouble}, mirror_slope_pointers[i], @@ -199,10 +236,20 @@ function update_mirror_slope!(ps4est, amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} end end function ghost_data_alloc(N::Int, ghost::P_pxest_ghost_t) - Ptr{Cdouble}(sc_malloc(P4est.package_id(), sizeof(Cdouble) * N * PointerWrapper(ghost).ghosts.elem_count[])) + Ptr{Cdouble}( + sc_malloc( + P4est.package_id(), + sizeof(Cdouble) * N * PointerWrapper(ghost).ghosts.elem_count[], + ), + ) end -function ghost_data_alloc(::Type{T},N::Int, ghost::P_pxest_ghost_t) where{T} - Ptr{T}(sc_malloc(P4est.package_id(), sizeof(Cdouble) * N * PointerWrapper(ghost).ghosts.elem_count[])) +function ghost_data_alloc(::Type{T}, N::Int, ghost::P_pxest_ghost_t) where {T} + Ptr{T}( + sc_malloc( + P4est.package_id(), + sizeof(Cdouble) * N * PointerWrapper(ghost).ghosts.elem_count[], + ), + ) end function amr_exchange( p4est::Ptr{p4est_t}, @@ -279,7 +326,7 @@ end $(TYPEDSIGNATURES) Update `df` in [`Ghost_VS_Data`](@ref). """ -function data_exchange!(p4est::P_pxest_t, amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function data_exchange!(p4est::P_pxest_t, amr::KitAMR_Data{DIM,NDF}) where {DIM,NDF} MPI.Comm_size(MPI.COMM_WORLD) == 1 && return nothing update_mirror_data!(p4est, amr) amr_exchange!( @@ -287,17 +334,17 @@ function data_exchange!(p4est::P_pxest_t, amr::KitAMR_Data{DIM,NDF}) where{DIM,N amr.global_data.forest.ghost, amr.ghost.ghost_exchange.ghost_datas, amr.ghost.ghost_exchange.mirror_data_pointers, - size_Ghost_Data(amr.global_data.status.max_vs_num,DIM,NDF), + size_Ghost_Data(amr.global_data.status.max_vs_num, DIM, NDF), ) end """ $(TYPEDSIGNATURES) -Update `df` in [`Ghost_VS_Data`](@ref) for the update of immersed boundaries. - Currently, the communication occurs through all ghost layers. The difference between [`data_exchange!`](@ref) - is that only immersed-boundary-related ghost cells' `mirror_data` is updated. +Update `df` in [`Ghost_VS_Data`](@ref) for the update of immersed boundaries. +Currently, the communication occurs through all ghost layers. The difference between [`data_exchange!`](@ref) +is that only immersed-boundary-related ghost cells' `mirror_data` is updated. """ -function solid_exchange!(p4est::P_pxest_t, amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function solid_exchange!(p4est::P_pxest_t, amr::KitAMR_Data{DIM,NDF}) where {DIM,NDF} MPI.Comm_size(MPI.COMM_WORLD) == 1 && return nothing isempty(amr.global_data.config.IB) && return nothing update_solid_mirror_data!(p4est, amr) @@ -306,7 +353,7 @@ function solid_exchange!(p4est::P_pxest_t, amr::KitAMR_Data{DIM,NDF}) where{DIM, amr.global_data.forest.ghost, amr.ghost.ghost_exchange.ghost_datas, amr.ghost.ghost_exchange.mirror_data_pointers, - size_Ghost_Data(amr.global_data.status.max_vs_num,DIM,NDF), + size_Ghost_Data(amr.global_data.status.max_vs_num, DIM, NDF), ) end @@ -314,7 +361,7 @@ end $(TYPEDSIGNATURES) Update `sdf` in [`Ghost_VS_Data`](@ref). """ -function slope_exchange!(p4est::P_pxest_t, amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function slope_exchange!(p4est::P_pxest_t, amr::KitAMR_Data{DIM,NDF}) where {DIM,NDF} MPI.Comm_size(MPI.COMM_WORLD) == 1 && return nothing update_mirror_slope!(p4est, amr) amr_exchange!( @@ -322,30 +369,33 @@ function slope_exchange!(p4est::P_pxest_t, amr::KitAMR_Data{DIM,NDF}) where{DIM, amr.global_data.forest.ghost, amr.ghost.ghost_exchange.ghost_slopes, amr.ghost.ghost_exchange.mirror_slope_pointers, - size_Ghost_Slope(amr.global_data.status.max_vs_num,DIM,NDF), + size_Ghost_Slope(amr.global_data.status.max_vs_num, DIM, NDF), ) end -function initialize_ghost_exchange(ps4est, global_data::Global_Data{DIM,NDF}) where{DIM,NDF} +function initialize_ghost_exchange( + ps4est, + global_data::Global_Data{DIM,NDF}, +) where {DIM,NDF} mirror_data_pointers = get_mirror_data(ps4est, global_data) ghost_datas = amr_exchange( ps4est, global_data.forest.ghost, mirror_data_pointers, - size_Ghost_Data(global_data.status.max_vs_num,DIM,NDF), + size_Ghost_Data(global_data.status.max_vs_num, DIM, NDF), ) mirror_slope_pointers = get_mirror_slope(ps4est, global_data) ghost_slopes = amr_exchange( ps4est, global_data.forest.ghost, mirror_slope_pointers, - size_Ghost_Slope(global_data.status.max_vs_num,DIM,NDF), + size_Ghost_Slope(global_data.status.max_vs_num, DIM, NDF), ) mirror_structure_pointers = get_mirror_structure(ps4est, global_data) ghost_structures = amr_exchange( ps4est, global_data.forest.ghost, mirror_structure_pointers, - size_Ghost_VS_Structure(global_data.status.max_vs_num,DIM), + size_Ghost_VS_Structure(global_data.status.max_vs_num, DIM), ) return Ghost_Exchange( ghost_datas, @@ -360,17 +410,27 @@ end function ghost_data_ptr(N::Int, ghost_data::Ptr{T}, qid::Integer) where {T} return Ptr{Cdouble}(ghost_data + qid * sizeof(T) * N) end -function initialize_ghost_wrap(global_data::Global_Data{DIM,NDF}, ghost_exchange::Ghost_Exchange) where{DIM,NDF} - ghost_wrap = - Array{AbstractGhostPsData}(undef, PointerWrapper(global_data.forest.ghost).ghosts.elem_count[]) +function initialize_ghost_wrap( + global_data::Global_Data{DIM,NDF}, + ghost_exchange::Ghost_Exchange, +) where {DIM,NDF} + ghost_wrap = Array{AbstractGhostPsData}( + undef, + PointerWrapper(global_data.forest.ghost).ghosts.elem_count[], + ) global_vs_num = global_data.status.max_vs_num for i in eachindex(ghost_wrap) - pq = iPointerWrapper(PointerWrapper(global_data.forest.ghost).ghosts, p4est_quadrant_t, i - 1) + pq = iPointerWrapper( + PointerWrapper(global_data.forest.ghost).ghosts, + p4est_quadrant_t, + i - 1, + ) owner_rank = pq.p.piggy1.owner_rank[] - which_tree = pq.p.piggy3.which_tree[];local_num = pq.p.piggy3.local_num[] + which_tree = pq.p.piggy3.which_tree[]; + local_num = pq.p.piggy3.local_num[] quadid = which_tree*2^(DIM*global_data.config.solver.AMR_PS_MAXLEVEL)+local_num p = ghost_data_ptr( - size_Ghost_Data(global_vs_num,DIM,NDF), + size_Ghost_Data(global_vs_num, DIM, NDF), ghost_exchange.ghost_datas, i - 1, ) @@ -392,14 +452,18 @@ function initialize_ghost_wrap(global_data::Global_Data{DIM,NDF}, ghost_exchange # midpoint_vs = Base.unsafe_wrap(Matrix{Cdouble},Ptr{Cdouble}(pointer(ghost_data.micro)),(vs_num,DIM)) df = Base.unsafe_wrap(Matrix{Cdouble}, p + offset * sizeof(Cdouble), (vs_num, NDF)) p = ghost_data_ptr( - size_Ghost_Slope(global_vs_num,DIM,NDF), + size_Ghost_Slope(global_vs_num, DIM, NDF), ghost_exchange.ghost_slopes, i - 1, ) sdf = Base.unsafe_wrap(Array{Cdouble}, p, (vs_num, NDF, DIM)) - sw = Base.unsafe_wrap(Matrix{Cdouble}, p + vs_num * NDF * DIM * sizeof(Cdouble), (DIM+2, DIM)) + sw = Base.unsafe_wrap( + Matrix{Cdouble}, + p + vs_num * NDF * DIM * sizeof(Cdouble), + (DIM+2, DIM), + ) p = ghost_data_ptr( - size_Ghost_VS_Structure(global_vs_num,DIM), + size_Ghost_VS_Structure(global_vs_num, DIM), ghost_exchange.ghost_structures, i - 1, ) @@ -410,8 +474,24 @@ function initialize_ghost_wrap(global_data::Global_Data{DIM,NDF}, ghost_exchange offset += global_vs_num midpoint_vs = Base.unsafe_wrap(Matrix{Cdouble}, p + offset * sizeof(Cdouble), (vs_num, DIM)) - vs_data = Ghost_VS_Data{DIM,NDF}(vs_num, Int8.(round.(level)), weight, midpoint_vs, df, sdf) - ghost_wrap[i] = Ghost_PS_Data{DIM,NDF}(owner_rank,quadid,bound_enc,ds, midpoint, w, sw, vs_data) + vs_data = Ghost_VS_Data{DIM,NDF}( + vs_num, + Int8.(round.(level)), + weight, + midpoint_vs, + df, + sdf, + ) + ghost_wrap[i] = Ghost_PS_Data{DIM,NDF}( + owner_rank, + quadid, + bound_enc, + ds, + midpoint, + w, + sw, + vs_data, + ) end return ghost_wrap end diff --git a/src/Parallel/Parallel.jl b/src/Parallel/Parallel.jl index e2c547b..e7aeb2c 100644 --- a/src/Parallel/Parallel.jl +++ b/src/Parallel/Parallel.jl @@ -2,4 +2,4 @@ include("Ghost.jl") include("Partition.jl") export data_exchange!, slope_exchange!, solid_exchange!, get_vs_num -export ps_partition!, partition_weight, partition! \ No newline at end of file +export ps_partition!, partition_weight, partition! diff --git a/src/Parallel/Partition.jl b/src/Parallel/Partition.jl index c056aae..d52165e 100644 --- a/src/Parallel/Partition.jl +++ b/src/Parallel/Partition.jl @@ -1,24 +1,24 @@ -function pre_partition_box_weight(p4est::P_pxest_t,which_tree,quadrant) +function pre_partition_box_weight(p4est::P_pxest_t, which_tree, quadrant) fp = PointerWrapper(p4est) global_data = unsafe_pointer_to_objref(pointer(fp.user_pointer)) ibs = global_data.config.IB qp = PointerWrapper(quadrant) - ds,midpoint = quad_to_cell(p4est,which_tree,qp) + ds, midpoint = quad_to_cell(p4est, which_tree, qp) for ib in ibs - if pre_partition_box_flag(midpoint,ds,ib) + if pre_partition_box_flag(midpoint, ds, ib) return Cint(1) end end return Cint(0) end -function meshed_partition!(p4est::P_pxest_t,trees_data) - src_gfq, dest_gfq, src_flt, src_llt = partition!(p4est,C_NULL) +function meshed_partition!(p4est::P_pxest_t, trees_data) + src_gfq, dest_gfq, src_flt, src_llt = partition!(p4est, C_NULL) receives, sends, receive_nums, send_nums = get_receive_send(src_gfq, dest_gfq) - s_datas = static_data_transfer_wrap(sends,send_nums,trees_data) + s_datas = static_data_transfer_wrap(sends, send_nums, trees_data) transfer_pop!(sends, send_nums, trees_data) up_datas, down_datas = static_data_partition_transfer(sends, s_datas, receives, receive_nums) - up_ps_datas,down_ps_datas = static_data_unpack_data(up_datas,down_datas) + up_ps_datas, down_ps_datas = static_data_unpack_data(up_datas, down_datas) ti_data = Transfer_Init( length(up_ps_datas), length(down_ps_datas), @@ -32,40 +32,40 @@ function meshed_partition!(p4est::P_pxest_t,trees_data) ) static_data_init_transferred_data!(p4est, ti_data, trees_data) end -function static_data_init_transferred_data!(p4est,ti_data,trees_data) - static_data_insert_trees!(p4est,ti_data,trees_data) - static_data_init_transferred_quadrant!(p4est,ti_data,trees_data) +function static_data_init_transferred_data!(p4est, ti_data, trees_data) + static_data_insert_trees!(p4est, ti_data, trees_data) + static_data_init_transferred_quadrant!(p4est, ti_data, trees_data) end -function static_data_insert_trees!(p4est,ti_data,trees::Vector{Vector{T}}) where{T} +function static_data_insert_trees!(p4est, ti_data, trees::Vector{Vector{T}}) where {T} pp = PointerWrapper(p4est) if !isempty(trees) if pp.first_local_tree[] < ti_data.old_flt - for _ = 1:ti_data.old_flt-pp.first_local_tree[] + for _ = 1:(ti_data.old_flt-pp.first_local_tree[]) pushfirst!(trees, Vector{T}(undef, 0)) end end if pp.last_local_tree[] > ti_data.old_llt - for _ = 1:pp.last_local_tree[]-ti_data.old_llt + for _ = 1:(pp.last_local_tree[]-ti_data.old_llt) push!(trees, Vector{T}(undef, 0)) end end else - for _ = 1:pp.last_local_tree[]-pp.first_local_tree[]+1 + for _ = 1:(pp.last_local_tree[]-pp.first_local_tree[]+1) push!(trees, Vector{T}(undef, 0)) end end end -function static_data_init_transferred_quadrant!(p4est, ti_data,trees) - data = [ti_data,trees] +function static_data_init_transferred_quadrant!(p4est, ti_data, trees) + data = [ti_data, trees] p_data = pointer_from_objref(data) - GC.@preserve data AMR_volume_iterate(p4est;user_data = p_data) do ip,data,dp - ti_data,trees = unsafe_pointer_to_objref(data) + GC.@preserve data AMR_volume_iterate(p4est; user_data = p_data) do ip, data, dp + ti_data, trees = unsafe_pointer_to_objref(data) treeid = ip.treeid[]-ip.p4est.first_local_tree[]+1 - static_data_init_up_quadrants!(ip,dp,ti_data,trees[treeid]) - static_data_init_down_quadrants!(ip,dp,ti_data,trees[treeid]) + static_data_init_up_quadrants!(ip, dp, ti_data, trees[treeid]) + static_data_init_down_quadrants!(ip, dp, ti_data, trees[treeid]) end end -function static_data_init_up_quadrants!(ip,dp,ti_data,tree_datas) +function static_data_init_up_quadrants!(ip, dp, ti_data, tree_datas) ti_data.up_index > ti_data.up_num && return nothing ps_data = ti_data.up_data[ti_data.up_index] dp[] = P4est_PS_Data(pointer_from_objref(ps_data)) @@ -78,9 +78,8 @@ function static_data_init_up_quadrants!(ip,dp,ti_data,tree_datas) ti_data.up_index += 1 return nothing end -function static_data_init_down_quadrants!(ip,dp,ti_data,tree_datas) - local_quadid(ip) < (ip.p4est.local_num_quadrants[] - ti_data.down_num) && - return nothing +function static_data_init_down_quadrants!(ip, dp, ti_data, tree_datas) + local_quadid(ip) < (ip.p4est.local_num_quadrants[] - ti_data.down_num) && return nothing ps_data = ti_data.down_data[ti_data.down_index] dp[] = P4est_PS_Data(pointer_from_objref(ps_data)) push!(tree_datas, ps_data) @@ -88,31 +87,35 @@ function static_data_init_down_quadrants!(ip,dp,ti_data,tree_datas) return nothing end -function static_data_unpack_data(up_datas,down_datas::Vector{StructArray{T}}) where{T} - up_ps_datas = Vector{T}(undef,0) - down_ps_datas = Vector{T}(undef,0) +function static_data_unpack_data(up_datas, down_datas::Vector{StructArray{T}}) where {T} + up_ps_datas = Vector{T}(undef, 0) + down_ps_datas = Vector{T}(undef, 0) for data in up_datas for i in eachindex(data) - push!(up_ps_datas,data[i]) + push!(up_ps_datas, data[i]) end end for data in down_datas for i in eachindex(data) - push!(down_ps_datas,data[i]) + push!(down_ps_datas, data[i]) end end - return up_ps_datas,down_ps_datas + return up_ps_datas, down_ps_datas end -function static_data_transfer_wrap(sends,send_nums,trees_data::Vector{Vector{T}}) where{T} +function static_data_transfer_wrap( + sends, + send_nums, + trees_data::Vector{Vector{T}}, +) where {T} isempty(sends) && return Vector{Vector{T}}(undef, 0) - up_datas = static_data_up_transfer_wrap(sends,send_nums,trees_data) - down_datas = static_data_down_transfer_wrap(sends,send_nums,trees_data) - append!(up_datas,down_datas) + up_datas = static_data_up_transfer_wrap(sends, send_nums, trees_data) + down_datas = static_data_down_transfer_wrap(sends, send_nums, trees_data) + append!(up_datas, down_datas) return up_datas end -function static_data_up_transfer_wrap(sends,send_nums,trees::Vector{Vector{T}}) where{T} - s_datas = Vector{Vector{T}}(undef,0) +function static_data_up_transfer_wrap(sends, send_nums, trees::Vector{Vector{T}}) where {T} + s_datas = Vector{Vector{T}}(undef, 0) send_index = 1 index = 1 up_num = length(sends) @@ -120,7 +123,7 @@ function static_data_up_transfer_wrap(sends,send_nums,trees::Vector{Vector{T}}) for i in eachindex(trees) for j in eachindex(trees[i]) sends[send_index] > MPI.Comm_rank(MPI.COMM_WORLD) + 1 && break - push!(inner_datas,trees[i][j]) + push!(inner_datas, trees[i][j]) index += 1 if index > send_nums[send_index] push!(s_datas, inner_datas) @@ -135,8 +138,12 @@ function static_data_up_transfer_wrap(sends,send_nums,trees::Vector{Vector{T}}) end return s_datas end -function static_data_down_transfer_wrap(sends, send_nums, trees::Vector{Vector{T}}) where{T} - s_datas = Vector{Vector{T}}(undef,0) +function static_data_down_transfer_wrap( + sends, + send_nums, + trees::Vector{Vector{T}}, +) where {T} + s_datas = Vector{Vector{T}}(undef, 0) send_index = length(sends) index = send_nums[send_index] inner_datas = T[] @@ -158,36 +165,41 @@ function static_data_down_transfer_wrap(sends, send_nums, trees::Vector{Vector{T end return s_datas end -function static_data_partition_transfer(sends::Vector{Int}, s_datas::Vector{Vector{T}}, receives::Vector{Int}, receive_nums::Vector{Int}) where{T} +function static_data_partition_transfer( + sends::Vector{Int}, + s_datas::Vector{Vector{T}}, + receives::Vector{Int}, + receive_nums::Vector{Int}, +) where {T} struct_arrays = [StructArray(data) for data in s_datas] - reqs = Vector{MPI.Request}(undef,0) + reqs = Vector{MPI.Request}(undef, 0) for i in eachindex(sends) data = struct_arrays[i] properties = propertynames(data) for p in properties sreq = MPI.Isend( - getproperty(data,p), + getproperty(data, p), MPI.COMM_WORLD; dest = sends[i]-1, tag = COMM_DATA_TAG + MPI.Comm_rank(MPI.COMM_WORLD), ) - push!(reqs,sreq) + push!(reqs, sreq) end end - r_datas = Vector{StructArray{T}}(undef,0) + r_datas = Vector{StructArray{T}}(undef, 0) for i in eachindex(receives) - r_data = StructArray([T() for _ in 1:receive_nums[i]]) + r_data = StructArray([T() for _ = 1:receive_nums[i]]) properties = propertynames(r_data) for p in properties rreq = MPI.Irecv!( - getproperty(r_data,p), + getproperty(r_data, p), MPI.COMM_WORLD; source = receives[i]-1, - tag = COMM_DATA_TAG+receives[i]-1 + tag = COMM_DATA_TAG+receives[i]-1, ) - push!(reqs,rreq) + push!(reqs, rreq) end - push!(r_datas,r_data) + push!(r_datas, r_data) end MPI.Waitall(reqs) up_index = [x < MPI.Comm_rank(MPI.COMM_WORLD) + 1 for x in receives] @@ -203,18 +215,18 @@ function partition_check(p4est::P_pxest_t) pointer(pp.global_first_quadrant), MPI.Comm_size(MPI.COMM_WORLD) + 1, ) - nums = [gfq[i]-gfq[i-1] for i in 2:MPI.Comm_size(MPI.COMM_WORLD)+1] + nums = [gfq[i]-gfq[i-1] for i = 2:(MPI.Comm_size(MPI.COMM_WORLD)+1)] return (maximum(nums)-minimum(nums))/minimum(nums)>0.1 end """ $(TYPEDSIGNATURES) """ -function partition_weight(p4est::P_pxest_t,which_tree,quadrant::P_pxest_quadrant_t) +function partition_weight(p4est::P_pxest_t, which_tree, quadrant::P_pxest_quadrant_t) qp = PointerWrapper(quadrant) - dp = PointerWrapper(P4est_PS_Data,qp.p.user_data[]) + dp = PointerWrapper(P4est_PS_Data, qp.p.user_data[]) ps_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - isa(ps_data,InsideSolidData)&&return Cint(0) + isa(ps_data, InsideSolidData)&&return Cint(0) # ps_data.bound_enc>0&&return Cint(2*ps_data.vs_data.vs_num) if ps_data.bound_enc>0 # sn = findall(x->isa(x[1],SolidNeighbor),ps_data.neighbor.data) @@ -225,7 +237,7 @@ end """ $(TYPEDSIGNATURES) """ -function partition!(p4est::Ptr{p4est_t},weight::Function = partition_weight) +function partition!(p4est::Ptr{p4est_t}, weight::Function = partition_weight) pp = PointerWrapper(p4est) gfq = Base.unsafe_wrap( Vector{Int}, @@ -235,13 +247,20 @@ function partition!(p4est::Ptr{p4est_t},weight::Function = partition_weight) src_gfq = copy(gfq) src_flt = pp.first_local_tree[] src_llt = pp.last_local_tree[] - p4est_partition(p4est, 0, @cfunction($weight,Cint,(Ptr{p4est_t},p4est_topidx_t,Ptr{p4est_quadrant_t}))) + p4est_partition( + p4est, + 0, + @cfunction($weight, Cint, (Ptr{p4est_t}, p4est_topidx_t, Ptr{p4est_quadrant_t})) + ) return src_gfq, gfq, src_flt, src_llt end -function partition!(p4est::Ptr{p8est_t},weight::Function = partition_weight) - partition!(p4est,@cfunction($weight,Cint,(Ptr{p8est_t},p4est_topidx_t,Ptr{p8est_quadrant_t}))) +function partition!(p4est::Ptr{p8est_t}, weight::Function = partition_weight) + partition!( + p4est, + @cfunction($weight, Cint, (Ptr{p8est_t}, p4est_topidx_t, Ptr{p8est_quadrant_t})) + ) end -function partition!(p4est::Ptr{p8est_t},weight::Union{Ptr{Nothing},Base.CFunction}) +function partition!(p4est::Ptr{p8est_t}, weight::Union{Ptr{Nothing},Base.CFunction}) pp = PointerWrapper(p4est) gfq = Base.unsafe_wrap( Vector{Int}, @@ -267,7 +286,7 @@ function get_receive_send(src_gfq::Vector, dest_gfq::Vector) r2 = MPI.Comm_rank(MPI.COMM_WORLD) == MPI.Comm_size(MPI.COMM_WORLD) - 1 ? MPI.Comm_size(MPI.COMM_WORLD) - 1 : findfirst(x -> x > llq, src_gfq) - 2 - is_receives[r1+1:r2+1] .= true + is_receives[(r1+1):(r2+1)] .= true is_receives[MPI.Comm_rank(MPI.COMM_WORLD)+1] = false if r1 == r2 receive_nums[r1+1] = llq - lfq + 1 @@ -287,7 +306,7 @@ function get_receive_send(src_gfq::Vector, dest_gfq::Vector) s2 = MPI.Comm_rank(MPI.COMM_WORLD) == MPI.Comm_size(MPI.COMM_WORLD) - 1 ? MPI.Comm_size(MPI.COMM_WORLD) - 1 : findfirst(x -> x > llq, dest_gfq) - 2 - is_sends[s1+1:s2+1] .= true + is_sends[(s1+1):(s2+1)] .= true is_sends[MPI.Comm_rank(MPI.COMM_WORLD)+1] = false if s1 == s2 send_nums[s1+1] = llq - lfq + 1 @@ -301,17 +320,17 @@ function get_receive_send(src_gfq::Vector, dest_gfq::Vector) end end end - singular = findall(x->x==0,receive_nums) + singular = findall(x->x==0, receive_nums) is_receives[singular] .= false receives = findall(is_receives) - singular = findall(x->x==0,send_nums) + singular = findall(x->x==0, send_nums) is_sends[singular] .= false sends = findall(is_sends) receive_nums = receive_nums[is_receives] send_nums = send_nums[is_sends] return receives, sends, receive_nums, send_nums end -function up_transfer_wrap(DIM::Integer,NDF::Integer,sends, send_nums, trees::Vector) +function up_transfer_wrap(DIM::Integer, NDF::Integer, sends, send_nums, trees::Vector) s_datas = Vector{Transfer_Data{DIM,NDF}}(undef, 0) s_vs_numss = Vector{Vector{Int}}(undef, 0) send_index = 1 @@ -327,14 +346,14 @@ function up_transfer_wrap(DIM::Integer,NDF::Integer,sends, send_nums, trees::Vec for j in eachindex(trees[i]) sends[send_index] > MPI.Comm_rank(MPI.COMM_WORLD) + 1 && break ps_data = trees[i][j] - if isa(ps_data,InsideSolidData) - push!(encs,0) - append!(encs,zeros(Int,SOLID_CELL_ID_NUM)) - append!(ws,zeros(DIM+2)) + if isa(ps_data, InsideSolidData) + push!(encs, 0) + append!(encs, zeros(Int, SOLID_CELL_ID_NUM)) + append!(ws, zeros(DIM+2)) s_vs_nums[index] = 0 else - push!(encs,ps_data.bound_enc) - append!(encs,ps_data.solid_cell_index) + push!(encs, ps_data.bound_enc) + append!(encs, ps_data.solid_cell_index) append!(ws, ps_data.w) append!(vs_levels, ps_data.vs_data.level) append!(vs_midpoints, reshape(ps_data.vs_data.midpoint, :)) @@ -343,7 +362,10 @@ function up_transfer_wrap(DIM::Integer,NDF::Integer,sends, send_nums, trees::Vec end index += 1 if index > send_nums[send_index] - push!(s_datas, Transfer_Data{DIM,NDF}(encs, ws, vs_levels, vs_midpoints, vs_df)) + push!( + s_datas, + Transfer_Data{DIM,NDF}(encs, ws, vs_levels, vs_midpoints, vs_df), + ) push!(s_vs_numss, s_vs_nums) index = 1 send_index += 1 @@ -361,7 +383,7 @@ function up_transfer_wrap(DIM::Integer,NDF::Integer,sends, send_nums, trees::Vec end return s_vs_numss, s_datas end -function down_transfer_wrap(DIM::Integer,NDF::Integer,sends, send_nums, trees::Vector) +function down_transfer_wrap(DIM::Integer, NDF::Integer, sends, send_nums, trees::Vector) s_datas = Vector{Transfer_Data{DIM,NDF}}(undef, 0) s_vs_numss = Vector{Vector{Int}}(undef, 0) send_index = length(sends) @@ -376,13 +398,13 @@ function down_transfer_wrap(DIM::Integer,NDF::Integer,sends, send_nums, trees::V for j in reverse(eachindex(trees[i])) sends[send_index] < MPI.Comm_rank(MPI.COMM_WORLD) + 1 && break ps_data = trees[i][j] - if isa(ps_data,InsideSolidData) - pushfirst!(encs,0) - prepend!(encs,zeros(SOLID_CELL_ID_NUM)) - prepend!(ws,zeros(DIM+2)) + if isa(ps_data, InsideSolidData) + pushfirst!(encs, 0) + prepend!(encs, zeros(SOLID_CELL_ID_NUM)) + prepend!(ws, zeros(DIM+2)) s_vs_nums[index] = 0 else - prepend!(encs,ps_data.solid_cell_index) + prepend!(encs, ps_data.solid_cell_index) pushfirst!(encs, ps_data.bound_enc) prepend!(ws, ps_data.w) prepend!(vs_levels, ps_data.vs_data.level) @@ -392,7 +414,10 @@ function down_transfer_wrap(DIM::Integer,NDF::Integer,sends, send_nums, trees::V end index -= 1 if index < 1 - pushfirst!(s_datas, Transfer_Data{DIM,NDF}(encs, ws, vs_levels, vs_midpoints, vs_df)) + pushfirst!( + s_datas, + Transfer_Data{DIM,NDF}(encs, ws, vs_levels, vs_midpoints, vs_df), + ) pushfirst!(s_vs_numss, s_vs_nums) send_index -= 1 send_index < 1 && break @@ -410,11 +435,16 @@ function down_transfer_wrap(DIM::Integer,NDF::Integer,sends, send_nums, trees::V end return s_vs_numss, s_datas end -function transfer_wrap(sends::Vector, send_nums::Vector, amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} - isempty(sends) && return Vector{Vector{Int}}(undef, 0), Vector{Transfer_Data{DIM,NDF}}(undef, 0) +function transfer_wrap( + sends::Vector, + send_nums::Vector, + amr::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} + isempty(sends) && + return Vector{Vector{Int}}(undef, 0), Vector{Transfer_Data{DIM,NDF}}(undef, 0) trees = amr.field.trees.data - up_vs_numss, up_datas = up_transfer_wrap(DIM,NDF,sends, send_nums, trees) - down_vs_numss, down_datas = down_transfer_wrap(DIM,NDF,sends, send_nums, trees) + up_vs_numss, up_datas = up_transfer_wrap(DIM, NDF, sends, send_nums, trees) + down_vs_numss, down_datas = down_transfer_wrap(DIM, NDF, sends, send_nums, trees) append!(up_vs_numss, down_vs_numss) append!(up_datas, down_datas) return up_vs_numss, up_datas @@ -472,7 +502,7 @@ function pre_transfer( dest = sends[i] - 1, tag = COMM_NUMS_TAG + MPI.Comm_rank(MPI.COMM_WORLD), ) - push!(reqs,sreq) + push!(reqs, sreq) end r_vs_numss = Vector{Vector{Int}}(undef, length(receives)) for i in eachindex(receives) @@ -483,7 +513,7 @@ function pre_transfer( source = receives[i] - 1, tag = COMM_NUMS_TAG + receives[i] - 1, ) - push!(reqs,rreq) + push!(reqs, rreq) r_vs_numss[i] = r_vs_nums end MPI.Waitall(reqs) @@ -495,7 +525,7 @@ function transfer( receives::Vector{Int}, receive_nums::Vector{Int}, r_vs_numss::Vector, -) where{DIM,NDF} +) where {DIM,NDF} reqs = Vector{MPI.Request}(undef, 0) for i in eachindex(sends) sreq = MPI.Isend( @@ -537,7 +567,7 @@ function transfer( r_datas = Vector{Transfer_Data{DIM,NDF}}(undef, 0) for i in eachindex(receives) total_vs_num = sum(r_vs_numss[i]) - r_data = Transfer_Data(DIM,NDF,receive_nums[i], total_vs_num) + r_data = Transfer_Data(DIM, NDF, receive_nums[i], total_vs_num) rreq = MPI.Irecv!( r_data.encs, MPI.COMM_WORLD; @@ -590,11 +620,11 @@ function partition_transfer( s_datas::Vector{Transfer_Data{DIM,NDF}}, receives::Vector{Int}, receive_nums::Vector{Int}, -)where{DIM,NDF} +) where {DIM,NDF} r_vs_numss = pre_transfer(sends, s_vs_numss, receives, receive_nums) transfer(sends, s_datas, receives, receive_nums, r_vs_numss) end -function unpack_data(vs_nums, data, amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function unpack_data(vs_nums, data, amr::KitAMR_Data{DIM,NDF}) where {DIM,NDF} transfer_ps_datas = Vector{AbstractPsData{DIM,NDF}}(undef, length(vs_nums)) quadrature = amr.global_data.config.quadrature vs_trees_num = reduce(*, amr.global_data.config.vs_trees_num) @@ -609,13 +639,16 @@ function unpack_data(vs_nums, data, amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} if vs_num==0 transfer_ps_datas[i] = InsideSolidData{DIM,NDF}() else - encs = data.encs[(SOLID_CELL_ID_NUM+1)*(i-1)+1:(SOLID_CELL_ID_NUM+1)*i] - w = data.w[(DIM+2)*(i-1)+1:(DIM+2)*i] - prim = get_prim(w,amr.global_data) - vs_levels = data.vs_levels[offset+1:offset+vs_num] - vs_midpoints = - reshape(data.vs_midpoints[DIM*offset+1:DIM*(offset+vs_num)], vs_num, DIM) - vs_df = reshape(data.vs_df[NDF*offset+1:NDF*(offset+vs_num)], vs_num, NDF) + encs = data.encs[((SOLID_CELL_ID_NUM+1)*(i-1)+1):((SOLID_CELL_ID_NUM+1)*i)] + w = data.w[((DIM+2)*(i-1)+1):((DIM+2)*i)] + prim = get_prim(w, amr.global_data) + vs_levels = data.vs_levels[(offset+1):(offset+vs_num)] + vs_midpoints = reshape( + data.vs_midpoints[(DIM*offset+1):(DIM*(offset+vs_num))], + vs_num, + DIM, + ) + vs_df = reshape(data.vs_df[(NDF*offset+1):(NDF*(offset+vs_num))], vs_num, NDF) vs_weight = @. tree_weight / 2.0^(DIM * vs_levels) vs_data = VS_Data{DIM,NDF}( vs_num, @@ -626,13 +659,27 @@ function unpack_data(vs_nums, data, amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} zeros(vs_num, NDF, DIM), zeros(vs_num, NDF), ) - transfer_ps_datas[i] = PS_Data(DIM,NDF;bound_enc=encs[1],solid_cell_index=encs[2:SOLID_CELL_ID_NUM+1],w, prim, vs_data) + transfer_ps_datas[i] = PS_Data( + DIM, + NDF; + bound_enc = encs[1], + solid_cell_index = encs[2:(SOLID_CELL_ID_NUM+1)], + w, + prim, + vs_data, + ) end offset += vs_num end return transfer_ps_datas end -function unpack_data(up_vs_numss, down_vs_numss, up_datas, down_datas, amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function unpack_data( + up_vs_numss, + down_vs_numss, + up_datas, + down_datas, + amr::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} up_ps_datas = Vector{AbstractPsData{DIM,NDF}}(undef, 0) down_ps_datas = Vector{AbstractPsData{DIM,NDF}}(undef, 0) for i in eachindex(up_vs_numss) @@ -646,7 +693,7 @@ end function init_up_quadrants!(ip, dp, ti_data::Transfer_Init, treeid::Integer, tree_datas) ti_data.up_index > ti_data.up_num && return nothing ps_data = ti_data.up_data[ti_data.up_index] - if !isa(ps_data,InsideSolidData) + if !isa(ps_data, InsideSolidData) ps_data.ds, ps_data.midpoint = quad_to_cell(ip.p4est, treeid, ip.quad) end dp[] = P4est_PS_Data(pointer_from_objref(ps_data)) @@ -660,10 +707,9 @@ function init_up_quadrants!(ip, dp, ti_data::Transfer_Init, treeid::Integer, tre return nothing end function init_down_quadrants!(ip, dp, ti_data::Transfer_Init, treeid::Integer, tree_datas) - local_quadid(ip) < (ip.p4est.local_num_quadrants[] - ti_data.down_num) && - return nothing + local_quadid(ip) < (ip.p4est.local_num_quadrants[] - ti_data.down_num) && return nothing ps_data = ti_data.down_data[ti_data.down_index] - if !isa(ps_data,InsideSolidData) + if !isa(ps_data, InsideSolidData) ps_data.ds, ps_data.midpoint = quad_to_cell(ip.p4est, treeid, ip.quad) end dp[] = P4est_PS_Data(pointer_from_objref(ps_data)) @@ -697,22 +743,26 @@ function init_transferred_ps!(p4est::P_pxest_t, ti_data::Transfer_Init, amr::Kit insert_trees!(p4est, ti_data, amr) init_transferred_quadrant!(p4est, ti_data, amr) end -function insert_trees!(p4est::P_pxest_t, ti_data::Transfer_Init, amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function insert_trees!( + p4est::P_pxest_t, + ti_data::Transfer_Init, + amr::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} trees = amr.field.trees.data pp = PointerWrapper(p4est) if !isempty(trees) if pp.first_local_tree[] < ti_data.old_flt - for i = 1:ti_data.old_flt-pp.first_local_tree[] + for i = 1:(ti_data.old_flt-pp.first_local_tree[]) pushfirst!(trees, Vector{AbstractPsData{DIM,NDF}}(undef, 0)) end end if pp.last_local_tree[] > ti_data.old_llt - for i = 1:pp.last_local_tree[]-ti_data.old_llt + for i = 1:(pp.last_local_tree[]-ti_data.old_llt) push!(trees, Vector{AbstractPsData{DIM,NDF}}(undef, 0)) end end else - for _ = 1:pp.last_local_tree[]-pp.first_local_tree[]+1 + for _ = 1:(pp.last_local_tree[]-pp.first_local_tree[]+1) push!(trees, Vector{AbstractPsData{DIM,NDF}}(undef, 0)) end end diff --git a/src/Physical_space/AMR.jl b/src/Physical_space/AMR.jl index af7433c..27412c9 100644 --- a/src/Physical_space/AMR.jl +++ b/src/Physical_space/AMR.jl @@ -1,19 +1,25 @@ -function vs_merge!(sdf::AbstractArray,sdf_n::AbstractArray,level::Vector,level_n::Vector,::KitAMR_Data{DIM}) where{DIM} +function vs_merge!( + sdf::AbstractArray, + sdf_n::AbstractArray, + level::Vector, + level_n::Vector, + ::KitAMR_Data{DIM}, +) where {DIM} j = 1 flag = 0.0 - for i in axes(sdf,1) + for i in axes(sdf, 1) if level[i] == level_n[j] - @. sdf[i,:,:] += @views sdf_n[j, :, :] + @. sdf[i, :, :] += @views sdf_n[j, :, :] j += 1 elseif level[i] < level_n[j] while flag != 1.0 - @. sdf[i, :, :] += @views sdf_n[j, :, :]/ 2^(DIM * (level_n[j] - level[i])) + @. sdf[i, :, :] += @views sdf_n[j, :, :] / 2^(DIM * (level_n[j] - level[i])) flag += 1 / 2^(DIM * (level_n[j] - level[i])) j += 1 end flag = 0.0 else - @. sdf[i, :, :] += @views sdf_n[j,:,:] + @. sdf[i, :, :] += @views sdf_n[j, :, :] flag += 1 / 2^(DIM * (level[i] - level_n[j])) if flag == 1.0 j += 1 @@ -22,22 +28,28 @@ function vs_merge!(sdf::AbstractArray,sdf_n::AbstractArray,level::Vector,level_n end end end -function vs_merge!(sdf::AbstractMatrix,sdf_n::AbstractMatrix,level::Vector,level_n::Vector,::KitAMR_Data{DIM}) where{DIM} +function vs_merge!( + sdf::AbstractMatrix, + sdf_n::AbstractMatrix, + level::Vector, + level_n::Vector, + ::KitAMR_Data{DIM}, +) where {DIM} j = 1 flag = 0.0 - for i in axes(sdf,1) + for i in axes(sdf, 1) if level[i] == level_n[j] - @. sdf[i,:] += @views sdf_n[j, :] + @. sdf[i, :] += @views sdf_n[j, :] j += 1 elseif level[i] < level_n[j] while flag != 1.0 - @. sdf[i, :] += @views sdf_n[j, :]/ 2^(DIM * (level_n[j] - level[i])) + @. sdf[i, :] += @views sdf_n[j, :] / 2^(DIM * (level_n[j] - level[i])) flag += 1 / 2^(DIM * (level_n[j] - level[i])) j += 1 end flag = 0.0 else - @. sdf[i, :] += @views sdf_n[j,:] + @. sdf[i, :] += @views sdf_n[j, :] flag += 1 / 2^(DIM * (level[i] - level_n[j])) if flag == 1.0 j += 1 @@ -48,7 +60,7 @@ function vs_merge!(sdf::AbstractMatrix,sdf_n::AbstractMatrix,level::Vector,level end -function user_defined_ps_refine_flag(forest::P_pxest_t,which_tree,quadrant) +function user_defined_ps_refine_flag(forest::P_pxest_t, which_tree, quadrant) GC.@preserve forest which_tree quadrant begin fp = PointerWrapper(forest) qp = PointerWrapper(quadrant) @@ -62,7 +74,7 @@ function user_defined_ps_refine_flag(forest::P_pxest_t,which_tree,quadrant) end end end -function user_defined_ps_refine!(p4est::Ptr{p8est_t},global_data::Global_Data) +function user_defined_ps_refine!(p4est::Ptr{p8est_t}, global_data::Global_Data) p8est_refine_ext( p4est, 1, @@ -77,46 +89,60 @@ function user_defined_ps_refine!(p4est::Ptr{p8est_t},global_data::Global_Data) ) end -function initialize_MeshData!(p4est::P_pxest_t,global_data::Global_Data) +function initialize_MeshData!(p4est::P_pxest_t, global_data::Global_Data) fp = PointerWrapper(p4est) - trees = [MeshData[] for _ in 1:fp.last_local_tree[]-fp.first_local_tree[]+1] + trees = [MeshData[] for _ = 1:(fp.last_local_tree[]-fp.first_local_tree[]+1)] p_data = pointer_from_objref(trees) - GC.@preserve trees AMR_volume_iterate(p4est;user_data = p_data) do ip,data,dp + GC.@preserve trees AMR_volume_iterate(p4est; user_data = p_data) do ip, data, dp treeid = ip.treeid[]-ip.p4est.first_local_tree[]+1 mesh_data = MeshData() dp[] = P4est_PS_Data(pointer_from_objref(mesh_data)) trees = unsafe_pointer_to_objref(data) - push!(trees[treeid],mesh_data) - end + push!(trees[treeid], mesh_data) + end return trees end -function search_radius_refine_flag!(forest::P_pxest_t,which_tree,quadrant) +function search_radius_refine_flag!(forest::P_pxest_t, which_tree, quadrant) GC.@preserve forest which_tree quadrant begin fp = PointerWrapper(forest) - global_data,_ = unsafe_pointer_to_objref(pointer(fp.user_pointer)) + global_data, _ = unsafe_pointer_to_objref(pointer(fp.user_pointer)) qp = PointerWrapper(quadrant) - dp = PointerWrapper(P4est_PS_Data,qp.p.user_data[]) + dp = PointerWrapper(P4est_PS_Data, qp.p.user_data[]) mesh_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) ibs = global_data.config.IB ds, midpoint = quad_to_cell(fp, which_tree, qp) for i in eachindex(ibs) - search_radius_refine_flag!(i,ibs[i],midpoint,ds,mesh_data) && return Cint(1) + search_radius_refine_flag!(i, ibs[i], midpoint, ds, mesh_data) && return Cint(1) end return Cint(0) end end -function search_radius_refine_replace(forest::P_pxest_t,which_tree,num_out,out_quads::Ptr{T},num_in,in_quads) where{T} +function search_radius_refine_replace( + forest::P_pxest_t, + which_tree, + num_out, + out_quads::Ptr{T}, + num_in, + in_quads, +) where {T} GC.@preserve forest which_tree num_out out_quads num_in in_quads begin fp = PointerWrapper(forest) - global_data,trees = unsafe_pointer_to_objref(pointer(fp.user_pointer)) + global_data, trees = unsafe_pointer_to_objref(pointer(fp.user_pointer)) out_quads_wrap = unsafe_wrap(Vector{T}, out_quads, num_out) in_quads_wrap = unsafe_wrap(Vector{T}, in_quads, num_in) - search_radius_refine_replace(forest, out_quads_wrap, in_quads_wrap, which_tree, trees, global_data) + search_radius_refine_replace( + forest, + out_quads_wrap, + in_quads_wrap, + which_tree, + trees, + global_data, + ) return nothing end end -function search_radius_refine!(p4est::Ptr{p8est_t},global_data::Global_Data) +function search_radius_refine!(p4est::Ptr{p8est_t}, global_data::Global_Data) p8est_refine_ext( p4est, 1, @@ -142,20 +168,27 @@ function search_radius_refine!(p4est::Ptr{p8est_t},global_data::Global_Data) ) end -function search_radius_refine_replace(p4est, out_quads,in_quads,which_tree,trees,global_data) +function search_radius_refine_replace( + p4est, + out_quads, + in_quads, + which_tree, + trees, + global_data, +) fp = PointerWrapper(p4est) out_qp = PointerWrapper(out_quads[1]) - dp = PointerWrapper(P4est_PS_Data,out_qp.p.user_data[]) + dp = PointerWrapper(P4est_PS_Data, out_qp.p.user_data[]) mesh_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) ib = global_data.config.IB[mesh_data.in_search_radius] treeid = which_tree - fp.first_local_tree[]+1 datas = trees[treeid] - index = findfirst(x->x===mesh_data,datas) + index = findfirst(x->x===mesh_data, datas) deleteat!(datas, index) if out_qp.level[]==global_data.config.solver.AMR_PS_MAXLEVEL-1 for i in eachindex(in_quads) qp = PointerWrapper(in_quads[i]) - dp = PointerWrapper(P4est_PS_Data,qp.p.user_data[]) + dp = PointerWrapper(P4est_PS_Data, qp.p.user_data[]) mesh_data_i = deepcopy(mesh_data) dp[] = P4est_PS_Data(pointer_from_objref(mesh_data_i)) insert!(datas, index - 1 + i, mesh_data_i) @@ -163,7 +196,7 @@ function search_radius_refine_replace(p4est, out_quads,in_quads,which_tree,trees else for i in eachindex(in_quads) qp = PointerWrapper(in_quads[i]) - dp = PointerWrapper(P4est_PS_Data,qp.p.user_data[]) + dp = PointerWrapper(P4est_PS_Data, qp.p.user_data[]) mesh_data_i = MeshData() dp[] = P4est_PS_Data(pointer_from_objref(mesh_data_i)) insert!(datas, index - 1 + i, mesh_data_i) @@ -173,73 +206,95 @@ end # function boundary_flag(::Domain,::AbstractVector,::AbstractVector,::Global_Data) # Domain boundary flag # return false # end -function boundary_flag(boundary::Domain,midpoint::AbstractVector,ds::AbstractVector,global_data::Global_Data) # Domain boundary flag +function boundary_flag( + boundary::Domain, + midpoint::AbstractVector, + ds::AbstractVector, + global_data::Global_Data, +) # Domain boundary flag !boundary.refine && return false index = Int(floor((boundary.id-1)/2))+1 - abs(midpoint[index] - global_data.config.geometry[boundary.id]) < ds[index] && return true + abs(midpoint[index] - global_data.config.geometry[boundary.id]) < ds[index] && + return true end -function domain_flag(global_data::Global_Data,midpoint::AbstractVector,ds::AbstractVector) # domain flag for physical space dynamic adaptive +function domain_flag(global_data::Global_Data, midpoint::AbstractVector, ds::AbstractVector) # domain flag for physical space dynamic adaptive domains = global_data.config.domain for domain in domains - boundary_flag(domain,midpoint,ds,global_data) && return true + boundary_flag(domain, midpoint, ds, global_data) && return true end return false end -function boundary_flag(midpoint::AbstractVector,ds::AbstractVector,global_data::Global_Data) # Is the cell at midpoint +function boundary_flag( + midpoint::AbstractVector, + ds::AbstractVector, + global_data::Global_Data, +) # Is the cell at midpoint domain = global_data.config.domain boundary = global_data.config.IB for i in eachindex(domain) - boundary_flag(domain[i],midpoint,ds,global_data) && return true + boundary_flag(domain[i], midpoint, ds, global_data) && return true end - return solid_cell_flag(boundary,midpoint,ds,global_data) + return solid_cell_flag(boundary, midpoint, ds, global_data) end -function pre_ps_refine_flag(midpoint,ds,global_data::Global_Data{DIM}) where{DIM} +function pre_ps_refine_flag(midpoint, ds, global_data::Global_Data{DIM}) where {DIM} domain = global_data.config.domain boundary = global_data.config.IB for i in eachindex(domain) - boundary_flag(domain[i],midpoint,ds,global_data) && return true + boundary_flag(domain[i], midpoint, ds, global_data) && return true end for i in eachindex(boundary) - pre_ps_refine_flag(boundary[i],midpoint,ds,global_data) && return true + pre_ps_refine_flag(boundary[i], midpoint, ds, global_data) && return true end return false end -function ps_copy(data::PS_Data{DIM,NDF}) where{DIM,NDF} - p = PS_Data(DIM,NDF; - ds=copy(data.ds), - midpoint=copy(data.midpoint), - w=copy(data.w), - sw=copy(data.sw), - vs_data=deepcopy(data.vs_data), +function ps_copy(data::PS_Data{DIM,NDF}) where {DIM,NDF} + p = PS_Data( + DIM, + NDF; + ds = copy(data.ds), + midpoint = copy(data.midpoint), + w = copy(data.w), + sw = copy(data.sw), + vs_data = deepcopy(data.vs_data), prim = copy(data.prim), flux = copy(data.flux), # neighbor = data.neighbor ) return p end -function ps_merge(Odatas::Vector,index::Int,global_data::Global_Data{DIM,NDF}) where{DIM,NDF} +function ps_merge( + Odatas::Vector, + index::Int, + global_data::Global_Data{DIM,NDF}, +) where {DIM,NDF} data = Odatas[index] - vs_data = data.vs_data;vs_num = vs_data.vs_num - w_new = [sum([x.w[i] for x in Odatas]) for i in 1:DIM+2]./2^DIM - p = PS_Data(DIM,NDF; - ds = data.ds *2.0, - midpoint = data.midpoint - 0.5 * data.ds .* RMT[DIM][index], - w = w_new, - prim = get_prim(w_new,global_data), - sw = [sum([x.sw[i,j] for x in Odatas]) for i in 1:DIM+2,j in 1:DIM]./2^DIM, - flux = [sum([x.flux[i] for x in Odatas]) for i in 1:DIM+2]./2^DIM, - vs_data = VS_Data{DIM,NDF}(vs_num,copy(vs_data.level),copy(vs_data.weight),copy(vs_data.midpoint), - zeros(vs_num,NDF),zeros(vs_num,NDF,DIM),zeros(vs_num,NDF)) - ) + vs_data = data.vs_data; + vs_num = vs_data.vs_num + w_new = [sum([x.w[i] for x in Odatas]) for i = 1:(DIM+2)] ./ 2^DIM + p = PS_Data( + DIM, + NDF; + ds = data.ds * 2.0, + midpoint = data.midpoint - 0.5 * data.ds .* RMT[DIM][index], + w = w_new, + prim = get_prim(w_new, global_data), + sw = [sum([x.sw[i, j] for x in Odatas]) for i = 1:(DIM+2), j = 1:DIM] ./ 2^DIM, + flux = [sum([x.flux[i] for x in Odatas]) for i = 1:(DIM+2)] ./ 2^DIM, + vs_data = VS_Data{DIM,NDF}( + vs_num, + copy(vs_data.level), + copy(vs_data.weight), + copy(vs_data.midpoint), + zeros(vs_num, NDF), + zeros(vs_num, NDF, DIM), + zeros(vs_num, NDF), + ), + ) p.neighbor.state[1] = BALANCE_FLAG p.neighbor.data[1] = Odatas return p end -function ps_refine_flag( - ::InsideSolidData, - ::KitAMR_Data, - ::PW_pxest_quadrant_t, -) +function ps_refine_flag(::InsideSolidData, ::KitAMR_Data, ::PW_pxest_quadrant_t) Cint(0) end function ps_refine_flag(forest::P_pxest_t, which_tree, quadrant) @@ -257,7 +312,13 @@ end $(TYPEDSIGNATURES) Replacement function in a refinement process. """ -function ps_replace!(::Val{1}, out_quad, in_quads, which_tree, amr::KitAMR_Data{DIM}) where{DIM}# refine replace +function ps_replace!( + ::Val{1}, + out_quad, + in_quads, + which_tree, + amr::KitAMR_Data{DIM}, +) where {DIM}# refine replace trees = amr.field.trees treeid = Int(which_tree) - trees.offset datas = trees.data[treeid] @@ -268,7 +329,7 @@ function ps_replace!(::Val{1}, out_quad, in_quads, which_tree, amr::KitAMR_Data{ index = findfirst(x -> x === Odata, datas) deleteat!(datas, index) flag = Odata.neighbor.state[1]==BALANCE_FLAG - for i = 1:2^DIM + for i = 1:(2^DIM) pw_in_quad = PointerWrapper(in_quads[i]) dp = PointerWrapper(P4est_PS_Data, pw_in_quad.p.user_data[]) if flag @@ -279,10 +340,11 @@ function ps_replace!(::Val{1}, out_quad, in_quads, which_tree, amr::KitAMR_Data{ vs_data = ps_data.vs_data @. ps_data.midpoint += 0.5 * ps_data.ds * RMT[DIM][i] for j = 1:DIM - @. vs_data.df += 0.5 * ps_data.ds[j] * RMT[DIM][i][j] * @view(vs_data.sdf[:, :, j]) + @. vs_data.df += + 0.5 * ps_data.ds[j] * RMT[DIM][i][j] * @view(vs_data.sdf[:, :, j]) end ps_data.w = calc_w0(ps_data) - ps_data.prim = get_prim(ps_data.w,amr.global_data) + ps_data.prim = get_prim(ps_data.w, amr.global_data) if i==1 ps_data.neighbor.state[2] = BALANCE_FLAG ps_data.neighbor.data[2] = [Odata] @@ -297,44 +359,58 @@ end $(TYPEDSIGNATURES) Replacement function in a coarsening process. """ -function ps_replace!(::ChildNum, out_quad, in_quads, which_tree, amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} # coarsen replace, average or interpolate? Currently interpolation strategy is adopted. If my memory serves me right, problems came out with average most likely due to the iterative balance process. +function ps_replace!( + ::ChildNum, + out_quad, + in_quads, + which_tree, + amr::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} # coarsen replace, average or interpolate? Currently interpolation strategy is adopted. If my memory serves me right, problems came out with average most likely due to the iterative balance process. trees = amr.field.trees treeid = Int(which_tree) - trees.offset datas = trees.data[treeid] pw_in_quad = PointerWrapper(in_quads[1]) dp = PointerWrapper(P4est_PS_Data, pw_in_quad.p.user_data[]) Odatas = Vector{AbstractPsData{DIM,NDF}}(undef, 2^DIM) - for i = 1:2^DIM + for i = 1:(2^DIM) pw_out_quad = PointerWrapper(out_quad[i]) Odatas[i] = unsafe_pointer_to_objref( pointer(PointerWrapper(P4est_PS_Data, pw_out_quad.p.user_data[]).ps_data), ) end - if any(x->x<0,[x.bound_enc for x in Odatas]) + if any(x->x<0, [x.bound_enc for x in Odatas]) @error `solid_cells coarsen!` end if Odatas[1].neighbor.state[2]==BALANCE_FLAG ps_data = first(Odatas[1].neighbor.data[2]) else - _,index = findmin([x.vs_data.vs_num for x in Odatas]) - ps_data = ps_merge(Odatas,index,amr.global_data) + _, index = findmin([x.vs_data.vs_num for x in Odatas]) + ps_data = ps_merge(Odatas, index, amr.global_data) vs_data = ps_data.vs_data for i in eachindex(Odatas) vs_data_n = Odatas[i].vs_data - vs_merge!(vs_data.sdf,vs_data_n.sdf,vs_data.level,vs_data_n.level,amr) - vs_merge!(vs_data.df,vs_data_n.df,vs_data.level,vs_data_n.level,amr) + vs_merge!(vs_data.sdf, vs_data_n.sdf, vs_data.level, vs_data_n.level, amr) + vs_merge!(vs_data.df, vs_data_n.df, vs_data.level, vs_data_n.level, amr) end - vs_data.df./=2^DIM;vs_data.sdf./=2^DIM + vs_data.df./=2^DIM; + vs_data.sdf./=2^DIM Odatas[1].neighbor.state[2] = BALANCE_FLAG Odatas[1].neighbor.data[2] = [ps_data] end index = findfirst(x -> x === Odatas[1], datas) - deleteat!(datas, index:index+2^DIM-1) + deleteat!(datas, index:(index+2^DIM-1)) insert!(datas, index, ps_data) dp[] = P4est_PS_Data(pointer_from_objref(ps_data)) return nothing end -function p4est_replace(forest::T1, which_tree, num_out, out_quads::Ptr{T2}, num_in, in_quads) where{T1<:P_pxest_t,T2<:P_pxest_quadrant_t} +function p4est_replace( + forest::T1, + which_tree, + num_out, + out_quads::Ptr{T2}, + num_in, + in_quads, +) where {T1<:P_pxest_t,T2<:P_pxest_quadrant_t} GC.@preserve forest which_tree num_out out_quads num_in in_quads begin fp = PointerWrapper(forest) amr = unsafe_pointer_to_objref(pointer(fp.user_pointer)) @@ -344,13 +420,27 @@ function p4est_replace(forest::T1, which_tree, num_out, out_quads::Ptr{T2}, num_ return nothing end end -function pre_ps_replace(forest::T1, which_tree, num_out, out_quads::Ptr{T2}, num_in, in_quads) where{T1<:P_pxest_t,T2<:P_pxest_quadrant_t} +function pre_ps_replace( + forest::T1, + which_tree, + num_out, + out_quads::Ptr{T2}, + num_in, + in_quads, +) where {T1<:P_pxest_t,T2<:P_pxest_quadrant_t} GC.@preserve forest which_tree num_out out_quads num_in in_quads begin fp = PointerWrapper(forest) - _,trees = unsafe_pointer_to_objref(pointer(fp.user_pointer)) + _, trees = unsafe_pointer_to_objref(pointer(fp.user_pointer)) out_quads_wrap = unsafe_wrap(Vector{T2}, out_quads, num_out) in_quads_wrap = unsafe_wrap(Vector{T2}, in_quads, num_in) - pre_ps_replace(Val(Int(num_out)), forest, out_quads_wrap, in_quads_wrap, which_tree, trees) + pre_ps_replace( + Val(Int(num_out)), + forest, + out_quads_wrap, + in_quads_wrap, + which_tree, + trees, + ) return nothing end end @@ -372,7 +462,14 @@ function pre_ps_replace(::Val{1}, p4est, out_quad, in_quads, which_tree, trees)# dp[] = P4est_PS_Data(pointer_from_objref(mesh_data)) end end -function pre_ps_replace(::ChildNum, p4est, out_quad, in_quads, which_tree, trees::Vector{Vector{T}}) where{T} # coarsen replace, average or interpolate? Currently interpolation strategy is adopted. If my memory serves me right, problems came out with average most likely due to the iterative balance process. +function pre_ps_replace( + ::ChildNum, + p4est, + out_quad, + in_quads, + which_tree, + trees::Vector{Vector{T}}, +) where {T} # coarsen replace, average or interpolate? Currently interpolation strategy is adopted. If my memory serves me right, problems came out with average most likely due to the iterative balance process. fp = PointerWrapper(p4est) treeid = Int(which_tree) - fp.first_local_tree[]+1 datas = trees[treeid] @@ -387,7 +484,7 @@ function pre_ps_replace(::ChildNum, p4est, out_quad, in_quads, which_tree, trees end mesh_data = deepcopy(Odatas[1]) index = findfirst(x -> x === Odatas[1], datas) - deleteat!(datas, index:index+length(out_quad)-1) + deleteat!(datas, index:(index+length(out_quad)-1)) insert!(datas, index, mesh_data) dp[] = P4est_PS_Data(pointer_from_objref(mesh_data)) end @@ -395,7 +492,7 @@ end """ $(TYPEDSIGNATURES) """ -function ps_refine!(p4est::Ptr{p4est_t},amr::KitAMR_Data; recursive = 0) +function ps_refine!(p4est::Ptr{p4est_t}, amr::KitAMR_Data; recursive = 0) p4est_refine_ext( p4est, recursive, @@ -423,7 +520,7 @@ end """ $(TYPEDSIGNATURES) """ -function ps_refine!(p4est::Ptr{p8est_t},amr::KitAMR_Data; recursive = 0) +function ps_refine!(p4est::Ptr{p8est_t}, amr::KitAMR_Data; recursive = 0) p8est_refine_ext( p4est, recursive, @@ -454,14 +551,19 @@ function pre_IB_refine_flag(forest::P_pxest_t, which_tree, quadrant) GC.@preserve forest which_tree quadrant begin fp = PointerWrapper(forest) qp = PointerWrapper(quadrant) - global_data,aux_points = unsafe_pointer_to_objref(pointer(fp.user_pointer)) - ds,midpoint = quad_to_cell(fp,which_tree,qp) - global_data.config.user_defined.static_ps_refine_flag(midpoint,ds,global_data,qp.level[]) && return Cint(1) - IB_flag(aux_points,midpoint,ds,qp.level[],global_data) && return Cint(1) + global_data, aux_points = unsafe_pointer_to_objref(pointer(fp.user_pointer)) + ds, midpoint = quad_to_cell(fp, which_tree, qp) + global_data.config.user_defined.static_ps_refine_flag( + midpoint, + ds, + global_data, + qp.level[], + ) && return Cint(1) + IB_flag(aux_points, midpoint, ds, qp.level[], global_data) && return Cint(1) end return Cint(0) end -function IB_pre_ps_refine!(p4est::Ptr{p4est_t},global_data::Global_Data) +function IB_pre_ps_refine!(p4est::Ptr{p4est_t}, global_data::Global_Data) p4est_refine_ext( p4est, 1, @@ -475,7 +577,7 @@ function IB_pre_ps_refine!(p4est::Ptr{p4est_t},global_data::Global_Data) C_NULL, ) end -function IB_pre_ps_refine!(p4est::Ptr{p8est_t},global_data::Global_Data) +function IB_pre_ps_refine!(p4est::Ptr{p8est_t}, global_data::Global_Data) p8est_refine_ext( p4est, 1, @@ -489,35 +591,51 @@ function IB_pre_ps_refine!(p4est::Ptr{p8est_t},global_data::Global_Data) C_NULL, ) end -function pre_ps_coarsen_flag(forest::Ptr{p4est_t},which_tree,quadrants) +function pre_ps_coarsen_flag(forest::Ptr{p4est_t}, which_tree, quadrants) GC.@preserve forest which_tree quadrants begin DIM = 2 fp = PointerWrapper(forest) quadrants_wrap = unsafe_wrap(Vector{Ptr{p4est_quadrant_t}}, quadrants, 2^DIM) - global_data,aux_points = unsafe_pointer_to_objref(pointer(fp.user_pointer)) - for i = 1:2^DIM + global_data, aux_points = unsafe_pointer_to_objref(pointer(fp.user_pointer)) + for i = 1:(2^DIM) quadrants_wrap[i]==C_NULL&&break qp = PointerWrapper(quadrants_wrap[i]) - ds,midpoint = quad_to_cell(fp,which_tree,qp) - (global_data.config.user_defined.static_ps_refine_flag(midpoint,ds,global_data,qp.level[]-1)&&!solid_flag(midpoint,global_data)|| - IB_flag(aux_points,midpoint,ds,qp.level[],global_data))&&return Cint(0) + ds, midpoint = quad_to_cell(fp, which_tree, qp) + ( + global_data.config.user_defined.static_ps_refine_flag( + midpoint, + ds, + global_data, + qp.level[]-1, + )&&!solid_flag(midpoint, global_data) || + IB_flag(aux_points, midpoint, ds, qp.level[], global_data) + )&&return Cint(0) end return Cint(1) end end -function pre_ps_coarsen_flag(forest::Ptr{p8est_t},which_tree,quadrants) +function pre_ps_coarsen_flag(forest::Ptr{p8est_t}, which_tree, quadrants) GC.@preserve forest which_tree quadrants begin DIM = 3 fp = PointerWrapper(forest) quadrants_wrap = unsafe_wrap(Vector{Ptr{p8est_quadrant_t}}, quadrants, 2^DIM) - global_data,_ = unsafe_pointer_to_objref(pointer(fp.user_pointer)) - for i = 1:2^DIM + global_data, _ = unsafe_pointer_to_objref(pointer(fp.user_pointer)) + for i = 1:(2^DIM) qp = PointerWrapper(quadrants_wrap[i]) - dp = PointerWrapper(P4est_PS_Data,qp.p.user_data[]) + dp = PointerWrapper(P4est_PS_Data, qp.p.user_data[]) mesh_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - ds,midpoint = quad_to_cell(fp,which_tree,qp) - (global_data.config.user_defined.static_ps_refine_flag(midpoint,ds,global_data,qp.level[]-1)&&!mesh_data.in_solid - ||mesh_data.is_ghost_cell||(mesh_data.in_search_radius!=0&&!mesh_data.in_solid))&&return Cint(0) + ds, midpoint = quad_to_cell(fp, which_tree, qp) + ( + global_data.config.user_defined.static_ps_refine_flag( + midpoint, + ds, + global_data, + qp.level[]-1, + )&&!mesh_data.in_solid || + mesh_data.is_ghost_cell||( + mesh_data.in_search_radius!=0&&!mesh_data.in_solid + ) + )&&return Cint(0) end return Cint(1) end @@ -569,11 +687,11 @@ function ps_coarsen_flag(forest::Ptr{p4est_t}, which_tree, quadrants) quadrants_wrap = unsafe_wrap(Vector{Ptr{p4est_quadrant_t}}, quadrants, 2^DIM) levels = Vector{Int}(undef, 2^DIM) ps_datas = Vector{PS_Data}(undef, 2^DIM) - for i = 1:2^DIM + for i = 1:(2^DIM) qp = PointerWrapper(quadrants_wrap[i]) dp = PointerWrapper(P4est_PS_Data, qp.p.user_data[]) ps_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - isa(ps_data,InsideSolidData)&&return Cint(0) + isa(ps_data, InsideSolidData)&&return Cint(0) levels[i] = qp.level[] ps_datas[i] = ps_data end @@ -588,11 +706,11 @@ function ps_coarsen_flag(forest::Ptr{p8est_t}, which_tree, quadrants) quadrants_wrap = unsafe_wrap(Vector{Ptr{p8est_quadrant_t}}, quadrants, 2^DIM) levels = Vector{Int}(undef, 2^DIM) ps_datas = Vector{PS_Data}(undef, 2^DIM) - for i = 1:2^DIM + for i = 1:(2^DIM) qp = PointerWrapper(quadrants_wrap[i]) dp = PointerWrapper(P4est_PS_Data, qp.p.user_data[]) ps_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) - isa(ps_data,InsideSolidData)&&return Cint(0) + isa(ps_data, InsideSolidData)&&return Cint(0) levels[i] = qp.level[] ps_datas[i] = ps_data end @@ -710,7 +828,7 @@ function pre_ps_refine_flag(forest::P_pxest_t, which_tree, quadrant) end end end -function pre_ps_refine!(p4est::Ptr{p4est_t},global_data::Global_Data) +function pre_ps_refine!(p4est::Ptr{p4est_t}, global_data::Global_Data) p4est_refine_ext( p4est, 1, @@ -724,7 +842,7 @@ function pre_ps_refine!(p4est::Ptr{p4est_t},global_data::Global_Data) C_NULL, ) end -function pre_ps_refine!(p4est::Ptr{p8est_t},global_data::Global_Data) +function pre_ps_refine!(p4est::Ptr{p8est_t}, global_data::Global_Data) p8est_refine_ext( p4est, 1, @@ -743,7 +861,10 @@ function pre_ps_balance!(p4est::Ptr{p4est_t}) p4est_balance_ext(p4est, P4EST_CONNECT_FULL, C_NULL, C_NULL) end function pre_ps_balance!(p4est::Ptr{p8est_t}) - p8est_balance_ext(p4est, P8EST_CONNECT_FULL, C_NULL, + p8est_balance_ext( + p4est, + P8EST_CONNECT_FULL, + C_NULL, @cfunction( pre_ps_replace, Cvoid, @@ -763,28 +884,30 @@ end $(TYPEDSIGNATURES) Update the globally maximum gradients of conserved variables as a referrence of the AMR in physical space. """ -function update_gradmax!(amr::KitAMR_Data{DIM}) where{DIM} - gradmax = amr.global_data.status.gradmax +function update_gradmax!(amr::KitAMR_Data{DIM}) where {DIM} + gradmax = amr.global_data.status.gradmax wmax = amr.global_data.status.wmax wmin = amr.global_data.status.wmin - gradmax .= 0.;wmax .= -Inf; wmin .= Inf + gradmax .= 0.0; + wmax .= -Inf; + wmin .= Inf trees = amr.field.trees.data for tree in trees for ps_data in tree - isa(ps_data,InsideSolidData)&&continue + isa(ps_data, InsideSolidData)&&continue ps_data.bound_enc<0&&continue - for i in 1:DIM + for i = 1:DIM for j in eachindex(gradmax) - gradmax[j] = max(gradmax[j],abs(ps_data.sw[j,i])) + gradmax[j] = max(gradmax[j], abs(ps_data.sw[j, i])) end end - wmax .= max.(wmax,ps_data.w) - wmin .= min.(wmin,ps_data.w) + wmax .= max.(wmax, ps_data.w) + wmin .= min.(wmin, ps_data.w) end end - gradmax .= MPI.Allreduce(gradmax, (x,y)->max.(x,y), MPI.COMM_WORLD) - wmax .= MPI.Allreduce(wmax, (x,y)->max.(x,y), MPI.COMM_WORLD) - wmin .= MPI.Allreduce(wmin, (x,y)->min.(x,y), MPI.COMM_WORLD) + gradmax .= MPI.Allreduce(gradmax, (x, y)->max.(x, y), MPI.COMM_WORLD) + wmax .= MPI.Allreduce(wmax, (x, y)->max.(x, y), MPI.COMM_WORLD) + wmin .= MPI.Allreduce(wmin, (x, y)->min.(x, y), MPI.COMM_WORLD) gradmax ./= (wmax-wmin) return nothing end @@ -793,10 +916,10 @@ end $(TYPEDSIGNATURES) Outer function of AMR in physical space. """ -function ps_adaptive_mesh_refinement!(ps4est::P_pxest_t,amr::KitAMR_Data) +function ps_adaptive_mesh_refinement!(ps4est::P_pxest_t, amr::KitAMR_Data) update_gradmax!(amr) - ps_refine!(ps4est,amr) + ps_refine!(ps4est, amr) ps_coarsen!(ps4est) ps_balance!(ps4est) return nothing -end \ No newline at end of file +end diff --git a/src/Physical_space/Criteria.jl b/src/Physical_space/Criteria.jl index 9d239ba..1457c9d 100644 --- a/src/Physical_space/Criteria.jl +++ b/src/Physical_space/Criteria.jl @@ -5,24 +5,31 @@ function ps_refine_flag( ps_data::PS_Data{DIM}, amr::KitAMR_Data{DIM}, qp::PW_pxest_quadrant_t, -) where{DIM} +) where {DIM} global_data = amr.global_data - if ps_data.bound_enc!=0||domain_flag(global_data,ps_data.midpoint,ps_data.ds) + if ps_data.bound_enc!=0||domain_flag(global_data, ps_data.midpoint, ps_data.ds) return Cint(1) end qp.level[]>global_data.config.solver.AMR_DYNAMIC_PS_MAXLEVEL-1&&return Cint(0) - global_data.config.user_defined.static_ps_refine_flag(ps_data.midpoint,ps_data.ds,global_data,qp.level[]) && return Cint(1) - dflag = global_data.config.user_defined.dynamic_ps_refine_flag(;ps_data) + global_data.config.user_defined.static_ps_refine_flag( + ps_data.midpoint, + ps_data.ds, + global_data, + qp.level[], + ) && return Cint(1) + dflag = global_data.config.user_defined.dynamic_ps_refine_flag(; ps_data) !dflag&&return Cint(0) agrad = zeros(DIM+2) gradmax = global_data.status.gradmax - for j in axes(ps_data.sw,1) - for k in axes(ps_data.sw,2) - agrad[j] = max(abs(ps_data.sw[j,k]),agrad[j]) + for j in axes(ps_data.sw, 1) + for k in axes(ps_data.sw, 2) + agrad[j] = max(abs(ps_data.sw[j, k]), agrad[j]) end end - rgrad = maximum(agrad./gradmax) - if rgrad > 2.0^((qp.level[] - global_data.config.solver.AMR_DYNAMIC_PS_MAXLEVEL)) * ADAPT_COEFFI_PS # 2 for second-order scheme + rgrad = maximum(agrad ./ gradmax) + if rgrad > + 2.0^((qp.level[] - global_data.config.solver.AMR_DYNAMIC_PS_MAXLEVEL)) * + ADAPT_COEFFI_PS # 2 for second-order scheme flag = Cint(1) else flag = Cint(0) @@ -32,25 +39,37 @@ end """ $(TYPEDSIGNATURES) """ -function ps_coarsen_flag(ps_datas::Vector{PS_Data}, levels::Vector{Int}, amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function ps_coarsen_flag( + ps_datas::Vector{PS_Data}, + levels::Vector{Int}, + amr::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} global_data = amr.global_data levels[1]>global_data.config.solver.AMR_DYNAMIC_PS_MAXLEVEL&&return Cint(0) agrad = zeros(DIM+2) gradmax = global_data.status.gradmax - for i = 1:2^DIM + for i = 1:(2^DIM) ps_data = ps_datas[i] - (ps_data.bound_enc!=0||domain_flag(global_data,ps_data.midpoint,ps_data.ds)) && return Cint(0) - global_data.config.user_defined.static_ps_refine_flag(ps_data.midpoint,ps_data.ds,global_data,levels[i]-1) && return Cint(0) - for j in axes(ps_data.sw,1) - for k in axes(ps_data.sw,2) - agrad[j] = max(abs(ps_data.sw[j,k]),agrad[j]) + (ps_data.bound_enc!=0||domain_flag(global_data, ps_data.midpoint, ps_data.ds)) && + return Cint(0) + global_data.config.user_defined.static_ps_refine_flag( + ps_data.midpoint, + ps_data.ds, + global_data, + levels[i]-1, + ) && return Cint(0) + for j in axes(ps_data.sw, 1) + for k in axes(ps_data.sw, 2) + agrad[j] = max(abs(ps_data.sw[j, k]), agrad[j]) end end - rgrad = maximum(agrad./gradmax) - if rgrad > 2.0^((levels[i]-1 - global_data.config.solver.AMR_DYNAMIC_PS_MAXLEVEL)) * ADAPT_COEFFI_PS # 2 for second-order scheme + rgrad = maximum(agrad ./ gradmax) + if rgrad > + 2.0^((levels[i]-1 - global_data.config.solver.AMR_DYNAMIC_PS_MAXLEVEL)) * + ADAPT_COEFFI_PS # 2 for second-order scheme return Cint(0) end - agrad.=0. + agrad.=0.0 end return Cint(1) -end \ No newline at end of file +end diff --git a/src/Physical_space/Physical_space.jl b/src/Physical_space/Physical_space.jl index 0c45c44..33d2a3f 100644 --- a/src/Physical_space/Physical_space.jl +++ b/src/Physical_space/Physical_space.jl @@ -1,4 +1,20 @@ include("AMR.jl") include("Criteria.jl") -export PS_Data, Ghost_PS_Data, InsideSolidData, GhostInsideSolidData, Neighbor, SolidNeighbor, FullFace, HangingFace, BackHangingFace, FluxData -export ps_adaptive_mesh_refinement!, ps_refine!, ps_coarsen!, ps_balance!, ps_replace!, ps_refine_flag, ps_coarsen_flag, update_gradmax! \ No newline at end of file +export PS_Data, + Ghost_PS_Data, + InsideSolidData, + GhostInsideSolidData, + Neighbor, + SolidNeighbor, + FullFace, + HangingFace, + BackHangingFace, + FluxData +export ps_adaptive_mesh_refinement!, + ps_refine!, + ps_coarsen!, + ps_balance!, + ps_replace!, + ps_refine_flag, + ps_coarsen_flag, + update_gradmax! diff --git a/src/Physical_space/Types.jl b/src/Physical_space/Types.jl index 0fe5702..5373179 100644 --- a/src/Physical_space/Types.jl +++ b/src/Physical_space/Types.jl @@ -1,4 +1,4 @@ -NeighborQuad{DIM,NDF} = Union{AbstractPsData{DIM,NDF}, Nothing} +NeighborQuad{DIM,NDF} = Union{AbstractPsData{DIM,NDF},Nothing} ChildNum = Union{Val{4},Val{8}} NeighborNum = Union{Val{2},Val{4}} @@ -15,17 +15,19 @@ $(TYPEDFIELDS) mutable struct Neighbor{DIM,NDF} data::Vector{Vector{NeighborQuad{DIM,NDF}}} state::Vector{Int} - Neighbor(DIM,NDF) = (n = new{DIM,NDF}(); - n.data = Vector{Vector{NeighborQuad{DIM,NDF}}}(undef, 2*DIM); - n.state = zeros(Int8, 2*DIM); - n) + Neighbor(DIM, NDF) = ( + n = new{DIM,NDF}(); + n.data = Vector{Vector{NeighborQuad{DIM,NDF}}}(undef, 2*DIM); + n.state = zeros(Int8, 2*DIM); + n + ) end """ $(TYPEDEF) $(TYPEDFIELDS) """ -mutable struct SolidNeighbor{DIM,NDF} <:AbstractPsData{DIM,NDF} +mutable struct SolidNeighbor{DIM,NDF} <: AbstractPsData{DIM,NDF} bound_enc::Int "Index of the face of the donor cell corresponding to this SolidNeighbor." faceid::Int # The faceid through which the neighbor is the solidneighbor. @@ -74,26 +76,43 @@ mutable struct PS_Data{DIM,NDF} <: AbstractPsData{DIM,NDF} vs_data::VS_Data{DIM,NDF} "Neighbor of the cell." neighbor::Neighbor{DIM,NDF} - PS_Data(DIM,NDF;kwargs...)=(n = new{DIM,NDF}(); - n.quadid = haskey(kwargs,:quadid) ? kwargs[:quadid] : 0; - n.bound_enc = haskey(kwargs,:bound_enc) ? kwargs[:bound_enc] : 0; - n.solid_cell_index = haskey(kwargs,:solid_cell_index) ? kwargs[:solid_cell_index] : zeros(SOLID_CELL_ID_NUM); - n.ds = haskey(kwargs,:ds) ? kwargs[:ds] : zeros(DIM); - n.midpoint = haskey(kwargs,:midpoint) ? kwargs[:midpoint] : zeros(DIM); - n.qf = haskey(kwargs,:qf) ? kwargs[:qf] : zeros(DIM); - n.w = haskey(kwargs,:w) ? kwargs[:w] : zeros(DIM+2); - n.sw = haskey(kwargs,:sw) ? kwargs[:sw] : zeros(DIM+2, DIM); - n.prim = haskey(kwargs,:prim) ? kwargs[:prim] : zeros(DIM+2); - n.flux = haskey(kwargs,:flux) ? kwargs[:flux] : zeros(DIM+2); - if haskey(kwargs,:vs_data) - n.vs_data = kwargs[:vs_data] + PS_Data( + DIM, + NDF; + kwargs..., + )=( + n = new{DIM,NDF}(); + n.quadid = haskey(kwargs, :quadid) ? kwargs[:quadid] : 0; + n.bound_enc = haskey(kwargs, :bound_enc) ? kwargs[:bound_enc] : 0; + n.solid_cell_index = haskey(kwargs, :solid_cell_index) ? kwargs[:solid_cell_index] : + zeros(SOLID_CELL_ID_NUM); + n.ds = haskey(kwargs, :ds) ? kwargs[:ds] : zeros(DIM); + n.midpoint = haskey(kwargs, :midpoint) ? kwargs[:midpoint] : zeros(DIM); + n.qf = haskey(kwargs, :qf) ? kwargs[:qf] : zeros(DIM); + n.w = haskey(kwargs, :w) ? kwargs[:w] : zeros(DIM+2); + n.sw = haskey(kwargs, :sw) ? kwargs[:sw] : zeros(DIM+2, DIM); + n.prim = haskey(kwargs, :prim) ? kwargs[:prim] : zeros(DIM+2); + n.flux = haskey(kwargs, :flux) ? kwargs[:flux] : zeros(DIM+2); + if haskey(kwargs, :vs_data) + n.vs_data = kwargs[:vs_data] end; - n.neighbor = haskey(kwargs,:neighbor) ? kwargs[:neighbor] : Neighbor(DIM,NDF); + n.neighbor = haskey(kwargs, :neighbor) ? kwargs[:neighbor] : Neighbor(DIM, NDF); n ) - PS_Data(ps_data::PS_Data{DIM,NDF};kwargs...) where{DIM,NDF}=(n = new{DIM,NDF}(); + PS_Data( + ps_data::PS_Data{DIM,NDF}; + kwargs..., + ) where { + DIM, + NDF, + }=( + n = new{DIM,NDF}(); for field in fieldnames(PS_Data{DIM,NDF}) - setfield!(n,field,haskey(kwargs,field) ? kwargs[field] : getfield(ps_data,field)) + setfield!( + n, + field, + haskey(kwargs, field) ? kwargs[field] : getfield(ps_data, field), + ) end; n ) @@ -190,5 +209,5 @@ mutable struct MeshData is_ghost_cell::Bool end function MeshData() - return MeshData(0,false,0,false) -end \ No newline at end of file + return MeshData(0, false, 0, false) +end diff --git a/src/Solver/AMR.jl b/src/Solver/AMR.jl index 84a0953..9d19d3c 100644 --- a/src/Solver/AMR.jl +++ b/src/Solver/AMR.jl @@ -1,25 +1,38 @@ """ $(TYPEDSIGNATURES) """ -function adaptive_mesh_refinement!(ps4est::P_pxest_t,amr::KitAMR_Data;ps_interval=40,vs_interval=80,partition_interval=40) +function adaptive_mesh_refinement!( + ps4est::P_pxest_t, + amr::KitAMR_Data; + ps_interval = 40, + vs_interval = 80, + partition_interval = 40, +) amr.global_data.status.residual.redundant_step>0&&(return nothing) res = maximum(amr.global_data.status.residual.residual) converge_ratio = res/TOLERANCE>100 ? 1 : Int(floor(100*TOLERANCE/res)) flag = false - if amr.global_data.config.solver.PS_DYNAMIC_AMR&&amr.global_data.status.ps_adapt_step > ps_interval*converge_ratio - ps_adaptive_mesh_refinement!(ps4est,amr) - flag = true;amr.global_data.status.ps_adapt_step = 0 + if amr.global_data.config.solver.PS_DYNAMIC_AMR&&amr.global_data.status.ps_adapt_step > + ps_interval*converge_ratio + ps_adaptive_mesh_refinement!(ps4est, amr) + flag = true; + amr.global_data.status.ps_adapt_step = 0 end - if amr.global_data.config.solver.VS_DYNAMIC_AMR&&amr.global_data.status.vs_adapt_step > vs_interval*converge_ratio + if amr.global_data.config.solver.VS_DYNAMIC_AMR&&amr.global_data.status.vs_adapt_step > + vs_interval*converge_ratio vs_adaptive_mesh_refinement!(amr) - flag = true;amr.global_data.status.vs_adapt_step=0 + flag = true; + amr.global_data.status.vs_adapt_step=0 end - if (amr.global_data.config.solver.PS_DYNAMIC_AMR||amr.global_data.config.solver.VS_DYNAMIC_AMR)&&amr.global_data.status.partition_step>partition_interval*converge_ratio + if ( + amr.global_data.config.solver.PS_DYNAMIC_AMR||amr.global_data.config.solver.VS_DYNAMIC_AMR + )&&amr.global_data.status.partition_step>partition_interval*converge_ratio ps_partition!(ps4est, amr) - flag = true;amr.global_data.status.partition_step = 0 + flag = true; + amr.global_data.status.partition_step = 0 end if flag - amr_recover!(ps4est,amr) + amr_recover!(ps4est, amr) end return nothing end @@ -32,10 +45,10 @@ end $(TYPEDSIGNATURES) Recover the ghost layers, neighbor relations, immersed boundaries, and faces after an AMR or partition process. """ -function amr_recover!(ps4est::P_pxest_t,amr::KitAMR_Data) +function amr_recover!(ps4est::P_pxest_t, amr::KitAMR_Data) update_ghost!(ps4est, amr) update_neighbor!(ps4est, amr) update_solid!(amr) update_faces!(ps4est, amr) return nothing -end \ No newline at end of file +end diff --git a/src/Solver/Auxiliary.jl b/src/Solver/Auxiliary.jl index 96cb9c8..28ad6b6 100644 --- a/src/Solver/Auxiliary.jl +++ b/src/Solver/Auxiliary.jl @@ -1,9 +1,9 @@ function unpack(t) - return (getfield(t,i) for i in 1:nfields(t)) + return (getfield(t, i) for i = 1:nfields(t)) end -function MPI_tune(f::Function,args...) - for i in 1:MPI.Comm_size(MPI.COMM_WORLD) +function MPI_tune(f::Function, args...) + for i = 1:MPI.Comm_size(MPI.COMM_WORLD) if MPI.Comm_rank(MPI.COMM_WORLD)==i-1 f(args...) end @@ -12,11 +12,11 @@ function MPI_tune(f::Function,args...) end -function fieldvalues_fn(vs_data,aux_df) +function fieldvalues_fn(vs_data, aux_df) NDF = typeof(vs_data).parameters[2] - return [aux_df[:,i] for i in 1:NDF] + return [aux_df[:, i] for i = 1:NDF] end function fieldvalues_fn(vs_data) NDF = typeof(vs_data).parameters[2] - return [vs_data.df[:,i] for i in 1:NDF] + return [vs_data.df[:, i] for i = 1:NDF] end diff --git a/src/Solver/Finalize.jl b/src/Solver/Finalize.jl index 52973b7..23c518e 100644 --- a/src/Solver/Finalize.jl +++ b/src/Solver/Finalize.jl @@ -2,10 +2,10 @@ $(TYPEDSIGNATURES) Update residuals. """ -function residual_check!(ps_data::PS_Data,prim::Vector{Float64},global_data::Global_Data) +function residual_check!(ps_data::PS_Data, prim::Vector{Float64}, global_data::Global_Data) Res = global_data.status.residual Res.step%RES_CHECK_INTERVAL!=0&&(return nothing) - @. Res.sumRes+=(prim-ps_data.prim).^2 + @. Res.sumRes+=(prim-ps_data.prim) .^ 2 @. Res.sumAvg+=abs(prim) return nothing end @@ -14,20 +14,23 @@ function residual_comm!(global_data::Global_Data) fp = PointerWrapper(global_data.forest.p4est) N = fp.global_num_quadrants[] Res.step%RES_CHECK_INTERVAL!=0&&(return nothing) - MPI.Reduce!(Res.sumRes,(x,y)->x.+y,0,MPI.COMM_WORLD) - MPI.Reduce!(Res.sumAvg,(x,y)->x.+y,0,MPI.COMM_WORLD) + MPI.Reduce!(Res.sumRes, (x, y)->x .+ y, 0, MPI.COMM_WORLD) + MPI.Reduce!(Res.sumAvg, (x, y)->x .+ y, 0, MPI.COMM_WORLD) if MPI.Comm_rank(MPI.COMM_WORLD)==0 @. Res.residual=sqrt(Res.sumRes*N)/(Res.sumAvg+EPS) end - MPI.Bcast!(Res.residual,0,MPI.COMM_WORLD) - Res.sumRes.=0.;Res.sumAvg.=0. + MPI.Bcast!(Res.residual, 0, MPI.COMM_WORLD) + Res.sumRes.=0.0; + Res.sumAvg.=0.0 end """ $(SIGNATURES) Check whether the `residual` and `redundant_step` in [`Status`](@ref) satisfies the convergence criterion. """ function check_for_convergence(amr::KitAMR_Data) - maximum(amr.global_data.status.residual.residual)REDUNDANT_STEPS_NUM end diff --git a/src/Solver/Initialize.jl b/src/Solver/Initialize.jl index 9548871..d34cbd0 100644 --- a/src/Solver/Initialize.jl +++ b/src/Solver/Initialize.jl @@ -2,96 +2,142 @@ """ $(TYPEDSIGNATURES) """ -function initialize_faces!(ps4est::Ptr{p4est_t},amr::KitAMR_Data) +function initialize_faces!(ps4est::Ptr{p4est_t}, amr::KitAMR_Data) global_data = amr.global_data p_data = pointer_from_objref(amr) - GC.@preserve amr AMR_face_iterate(ps4est;user_data = p_data,ghost = global_data.forest.ghost) do ip,data + GC.@preserve amr AMR_face_iterate( + ps4est; + user_data = p_data, + ghost = global_data.forest.ghost, + ) do ip, data amr = unsafe_pointer_to_objref(data) if ip.sides.elem_count[]==1 - initialize_domain_face!(iPointerWrapper(ip.sides,p4est_iter_face_side_t,0),amr) + initialize_domain_face!( + iPointerWrapper(ip.sides, p4est_iter_face_side_t, 0), + amr, + ) else - Aside = iPointerWrapper(ip.sides,p4est_iter_face_side_t,0) - Bside = iPointerWrapper(ip.sides,p4est_iter_face_side_t,1) + Aside = iPointerWrapper(ip.sides, p4est_iter_face_side_t, 0) + Bside = iPointerWrapper(ip.sides, p4est_iter_face_side_t, 1) if Aside.is_hanging[]==0 if Aside.is.full.is_ghost[]==0 if Bside.is_hanging[]==0 - initialize_full_face!(Aside,amr) + initialize_full_face!(Aside, amr) else - initialize_hanging_face!(Aside,amr) + initialize_hanging_face!(Aside, amr) end elseif Bside.is_hanging[]==0 - initialize_full_face!(Bside,amr) + initialize_full_face!(Bside, amr) else - initialize_back_hanging_face!(Bside,amr) + initialize_back_hanging_face!(Bside, amr) end elseif Bside.is.full.is_ghost[]==0 - initialize_hanging_face!(Bside,amr) + initialize_hanging_face!(Bside, amr) else - initialize_back_hanging_face!(Aside,amr) + initialize_back_hanging_face!(Aside, amr) end end end end -function solid_full_face_check(base_quad,faceid) +function solid_full_face_check(base_quad, faceid) neighbor = base_quad.neighbor.data[faceid][1] - (!isa(neighbor,PS_Data)||neighbor.bound_enc<0) && return true + (!isa(neighbor, PS_Data)||neighbor.bound_enc<0) && return true return false end -function solid_hanging_face_check(base_quad,faceid) - ids = findall(x->(isa(x,PS_Data)&&x.bound_enc>=0),base_quad.neighbor.data[faceid]) +function solid_hanging_face_check(base_quad, faceid) + ids = findall(x->(isa(x, PS_Data)&&x.bound_enc>=0), base_quad.neighbor.data[faceid]) return ids end -function initialize_domain_face!(side::PW_pxest_iter_face_side_t,amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function initialize_domain_face!( + side::PW_pxest_iter_face_side_t, + amr::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} faces = amr.field.faces - base_quad = - unsafe_pointer_to_objref(pointer(PointerWrapper(P4est_PS_Data, - side.is.full.quad.p.user_data[]).ps_data)) - isa(base_quad,InsideSolidData) && return nothing + base_quad = unsafe_pointer_to_objref( + pointer(PointerWrapper(P4est_PS_Data, side.is.full.quad.p.user_data[]).ps_data), + ) + isa(base_quad, InsideSolidData) && return nothing faceid = side.face[]+1 direction = get_dir(faceid) rot = get_rot(faceid) midpoint = copy(base_quad.midpoint) midpoint[direction] -= 0.5*rot*base_quad.ds[direction] domain = amr.global_data.config.domain[faceid] - push!(faces,DomainFace{DIM,NDF,typeof(domain).parameters[1]}(rot,direction,midpoint,domain,base_quad)) + push!( + faces, + DomainFace{DIM,NDF,typeof(domain).parameters[1]}( + rot, + direction, + midpoint, + domain, + base_quad, + ), + ) return nothing end -function initialize_full_face!(side::PW_pxest_iter_face_side_t,amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function initialize_full_face!( + side::PW_pxest_iter_face_side_t, + amr::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} faces = amr.field.faces - base_quad = - unsafe_pointer_to_objref(pointer(PointerWrapper(P4est_PS_Data, - side.is.full.quad.p.user_data[]).ps_data)) - isa(base_quad,InsideSolidData) && return nothing + base_quad = unsafe_pointer_to_objref( + pointer(PointerWrapper(P4est_PS_Data, side.is.full.quad.p.user_data[]).ps_data), + ) + isa(base_quad, InsideSolidData) && return nothing faceid = side.face[] + 1 if base_quad.bound_enc<0 - solid_full_face_check(base_quad,faceid) && return nothing + solid_full_face_check(base_quad, faceid) && return nothing base_quad = base_quad.neighbor.data[faceid][1] - faceid += faceid%2==0 ? -1 : 1 + faceid += faceid%2==0 ? -1 : 1 end direction = get_dir(faceid) rot = get_rot(faceid) midpoint = copy(base_quad.midpoint) midpoint[direction] -= 0.5*rot*base_quad.ds[direction] global_data = amr.global_data - if midpoint[direction] == global_data.config.geometry[2*direction-1]||midpoint[direction] == global_data.config.geometry[2*direction] - there_midpoint = copy(midpoint);there_midpoint[direction] -= 0.5*rot*base_quad.ds[direction] - push!(faces,FullFace{DIM,NDF}(rot,direction,midpoint,base_quad,periodic_ghost_cell(there_midpoint,base_quad.neighbor.data[faceid][1]))) + if midpoint[direction] == + global_data.config.geometry[2*direction-1]||midpoint[direction] == + global_data.config.geometry[2*direction] + there_midpoint = copy(midpoint); + there_midpoint[direction] -= 0.5*rot*base_quad.ds[direction] + push!( + faces, + FullFace{DIM,NDF}( + rot, + direction, + midpoint, + base_quad, + periodic_ghost_cell(there_midpoint, base_quad.neighbor.data[faceid][1]), + ), + ) else - push!(faces,FullFace{DIM,NDF}(rot,direction,midpoint,base_quad,base_quad.neighbor.data[faceid][1])) + push!( + faces, + FullFace{DIM,NDF}( + rot, + direction, + midpoint, + base_quad, + base_quad.neighbor.data[faceid][1], + ), + ) end return nothing end -function initialize_hanging_face!(side::PW_pxest_iter_face_side_t,amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function initialize_hanging_face!( + side::PW_pxest_iter_face_side_t, + amr::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} faces = amr.field.faces - base_quad = - unsafe_pointer_to_objref(pointer(PointerWrapper(P4est_PS_Data, - side.is.full.quad.p.user_data[]).ps_data)) - isa(base_quad,InsideSolidData) && return nothing + base_quad = unsafe_pointer_to_objref( + pointer(PointerWrapper(P4est_PS_Data, side.is.full.quad.p.user_data[]).ps_data), + ) + isa(base_quad, InsideSolidData) && return nothing faceid = side.face[] + 1 if base_quad.bound_enc<0 - ids = solid_hanging_face_check(base_quad,faceid) - isempty(ids) && return nothing + ids = solid_hanging_face_check(base_quad, faceid) + isempty(ids) && return nothing here_data = base_quad.neighbor.data[faceid][ids] faceid += faceid%2==0 ? -1 : 1 direction = get_dir(faceid) @@ -100,7 +146,10 @@ function initialize_hanging_face!(side::PW_pxest_iter_face_side_t,amr::KitAMR_Da for i in eachindex(midpoint) midpoint[i][direction] -= 0.5*rot*here_data[i].ds[direction] end - push!(faces,BackHangingFace{DIM,NDF}(rot,direction,midpoint,here_data,base_quad)) + push!( + faces, + BackHangingFace{DIM,NDF}(rot, direction, midpoint, here_data, base_quad), + ) return nothing end direction = get_dir(faceid) @@ -111,33 +160,50 @@ function initialize_hanging_face!(side::PW_pxest_iter_face_side_t,amr::KitAMR_Da midpoint[i][direction] += 0.5*rot*neighbor[i].ds[direction] end global_data = amr.global_data - if midpoint[1][direction] == global_data.config.geometry[2*direction-1]||midpoint[1][direction] == global_data.config.geometry[2*direction] + if midpoint[1][direction] == + global_data.config.geometry[2*direction-1]||midpoint[1][direction] == + global_data.config.geometry[2*direction] periodic_midpoints = [copy(x) for x in midpoint] for i in eachindex(periodic_midpoints) periodic_midpoints[i][direction] .+= 0.5*rot*neighbor[i].ds[direction] end - push!(faces,HangingFace{DIM,NDF}(rot,direction,midpoint,base_quad,periodic_ghost_cell(periodic_midpoints,neighbor))) + push!( + faces, + HangingFace{DIM,NDF}( + rot, + direction, + midpoint, + base_quad, + periodic_ghost_cell(periodic_midpoints, neighbor), + ), + ) else - push!(faces,HangingFace{DIM,NDF}(rot,direction,midpoint,base_quad,neighbor)) + push!(faces, HangingFace{DIM,NDF}(rot, direction, midpoint, base_quad, neighbor)) end return nothing end -function initialize_back_hanging_face!(side::PointerWrapper{p4est_iter_face_side_t},amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function initialize_back_hanging_face!( + side::PointerWrapper{p4est_iter_face_side_t}, + amr::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} faces = amr.field.faces is_ghost = Base.unsafe_wrap( Vector{Int8}, Ptr{Int8}(pointer(side.is.hanging.is_ghost)), 2^(DIM - 1), ) - ids = findall(x->x==0,is_ghost).-1 + ids = findall(x->x==0, is_ghost) .- 1 faceid = side.face[]+1 here_data = Vector{PS_Data{DIM,NDF}}() for i in ids - qp = PointerWrapper(iPointerWrapper(side.is.hanging.quad, Ptr{p4est_quadrant_t}, i)[]) - base_quad = - unsafe_pointer_to_objref(pointer(PointerWrapper(P4est_PS_Data, qp.p.user_data[]).ps_data)) - (!isa(base_quad,PS_Data)||base_quad.bound_enc<0) && continue - push!(here_data,base_quad) + qp = PointerWrapper( + iPointerWrapper(side.is.hanging.quad, Ptr{p4est_quadrant_t}, i)[], + ) + base_quad = unsafe_pointer_to_objref( + pointer(PointerWrapper(P4est_PS_Data, qp.p.user_data[]).ps_data), + ) + (!isa(base_quad, PS_Data)||base_quad.bound_enc<0) && continue + push!(here_data, base_quad) end isempty(here_data)&&return nothing direction = get_dir(faceid) @@ -147,12 +213,33 @@ function initialize_back_hanging_face!(side::PointerWrapper{p4est_iter_face_side midpoint[i][direction] -= 0.5*rot*here_data[i].ds[direction] end global_data = amr.global_data - if midpoint[1][direction] == global_data.config.geometry[2*direction-1]||midpoint[1][direction] == global_data.config.geometry[2*direction] + if midpoint[1][direction] == + global_data.config.geometry[2*direction-1]||midpoint[1][direction] == + global_data.config.geometry[2*direction] there_midpoint = copy(first(here_data).neighbor.data[faceid][1].midpoint) - there_midpoint[direction] = midpoint[1][direction] -= 0.5*rot*here_data[i].ds[direction] - push!(faces,BackHangingFace{DIM,NDF}(rot,direction,midpoint,here_data,periodic_ghost_cell(there_midpoint,base_quad.neighbor.data[faceid][1]))) + there_midpoint[direction] = + midpoint[1][direction] -= 0.5*rot*here_data[i].ds[direction] + push!( + faces, + BackHangingFace{DIM,NDF}( + rot, + direction, + midpoint, + here_data, + periodic_ghost_cell(there_midpoint, base_quad.neighbor.data[faceid][1]), + ), + ) else - push!(faces,BackHangingFace{DIM,NDF}(rot,direction,midpoint,here_data,first(here_data).neighbor.data[faceid][1])) + push!( + faces, + BackHangingFace{DIM,NDF}( + rot, + direction, + midpoint, + here_data, + first(here_data).neighbor.data[faceid][1], + ), + ) end return nothing end @@ -161,77 +248,105 @@ end """ $(TYPEDSIGNATURES) """ -function initialize_faces!(ps4est::Ptr{p8est_t},amr::KitAMR_Data) +function initialize_faces!(ps4est::Ptr{p8est_t}, amr::KitAMR_Data) global_data = amr.global_data p_data = pointer_from_objref(amr) - GC.@preserve amr AMR_face_iterate(ps4est;user_data = p_data,ghost = global_data.forest.ghost) do ip,data + GC.@preserve amr AMR_face_iterate( + ps4est; + user_data = p_data, + ghost = global_data.forest.ghost, + ) do ip, data amr = unsafe_pointer_to_objref(data) if ip.sides.elem_count[]==1 - initialize_domain_face!(iPointerWrapper(ip.sides,p8est_iter_face_side_t,0),amr) + initialize_domain_face!( + iPointerWrapper(ip.sides, p8est_iter_face_side_t, 0), + amr, + ) else - Aside = iPointerWrapper(ip.sides,p8est_iter_face_side_t,0) - Bside = iPointerWrapper(ip.sides,p8est_iter_face_side_t,1) + Aside = iPointerWrapper(ip.sides, p8est_iter_face_side_t, 0) + Bside = iPointerWrapper(ip.sides, p8est_iter_face_side_t, 1) if Aside.is_hanging[]==0 if Aside.is.full.is_ghost[]==0 if Bside.is_hanging[]==0 - initialize_full_face!(Aside,amr) + initialize_full_face!(Aside, amr) else - initialize_hanging_face!(Aside,amr) + initialize_hanging_face!(Aside, amr) end elseif Bside.is_hanging[]==0 - initialize_full_face!(Bside,amr) + initialize_full_face!(Bside, amr) else - initialize_back_hanging_face!(Bside,amr) + initialize_back_hanging_face!(Bside, amr) end elseif Bside.is.full.is_ghost[]==0 - initialize_hanging_face!(Bside,amr) + initialize_hanging_face!(Bside, amr) else - initialize_back_hanging_face!(Aside,amr) + initialize_back_hanging_face!(Aside, amr) end end end end -function initialize_back_hanging_face!(side::PointerWrapper{p8est_iter_face_side_t},amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} +function initialize_back_hanging_face!( + side::PointerWrapper{p8est_iter_face_side_t}, + amr::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} faces = amr.field.faces is_ghost = Base.unsafe_wrap( Vector{Int8}, Ptr{Int8}(pointer(side.is.hanging.is_ghost)), 2^(DIM - 1), ) - ids = findall(x->x==0,is_ghost).-1 + ids = findall(x->x==0, is_ghost) .- 1 faceid = side.face[]+1 here_data = Vector{PS_Data{DIM,NDF}}() for i in ids - qp = PointerWrapper(iPointerWrapper(side.is.hanging.quad, Ptr{p8est_quadrant_t}, i)[]) - base_quad = - unsafe_pointer_to_objref(pointer(PointerWrapper(P4est_PS_Data, qp.p.user_data[]).ps_data)) - (!isa(base_quad,PS_Data)||base_quad.bound_enc<0) && continue - push!(here_data,base_quad) + qp = PointerWrapper( + iPointerWrapper(side.is.hanging.quad, Ptr{p8est_quadrant_t}, i)[], + ) + base_quad = unsafe_pointer_to_objref( + pointer(PointerWrapper(P4est_PS_Data, qp.p.user_data[]).ps_data), + ) + (!isa(base_quad, PS_Data)||base_quad.bound_enc<0) && continue + push!(here_data, base_quad) end isempty(here_data)&&return nothing direction = get_dir(faceid) rot = get_rot(faceid) midpoint = [copy(x.midpoint) for x in here_data] - for i in eachindex(midpoint) - midpoint[i][direction] -= 0.5*rot*here_data[i].ds[direction] - end - push!(faces,BackHangingFace(rot,direction,midpoint,here_data,first(here_data).neighbor.data[faceid][1])) + for i in eachindex(midpoint) + midpoint[i][direction] -= 0.5*rot*here_data[i].ds[direction] + end + push!( + faces, + BackHangingFace( + rot, + direction, + midpoint, + here_data, + first(here_data).neighbor.data[faceid][1], + ), + ) return nothing end -function initial_prim(ic::Uniform;kwargs...) +function initial_prim(ic::Uniform; kwargs...) return ic.ic end -function initial_prim(ic::PCoordFn;midpoint::AbstractVector{Float64},kwargs...) - return ic.PCIC_fn(midpoint;kwargs...) +function initial_prim(ic::PCoordFn; midpoint::AbstractVector{Float64}, kwargs...) + return ic.PCIC_fn(midpoint; kwargs...) end function init_solid_midpoints_kernel(ip, data, dp) global_data, solid_midpoints = unsafe_pointer_to_objref(data) boundaries = global_data.config.IB ds, midpoint = quad_to_cell(ip.p4est, ip.treeid[], ip.quad) for i in eachindex(boundaries) - inside = solid_flag(boundaries[i],midpoint) - solid_cell_flag(boundaries[i],midpoint,ds,global_data,inside)&&push!(solid_midpoints[i],midpoint) + inside = solid_flag(boundaries[i], midpoint) + solid_cell_flag( + boundaries[i], + midpoint, + ds, + global_data, + inside, + )&&push!(solid_midpoints[i], midpoint) end end function init_solid_midpoints(info, data) @@ -243,14 +358,16 @@ function init_ps_p4est_kernel(ip, data, dp) boundaries = global_data.config.IB ds, midpoint = quad_to_cell(ip.p4est, ip.treeid[], ip.quad) flag = true # need to be initialized? - solid_cell_flags = Vector{Bool}(undef,length(global_data.config.IB)) - target_cell_flags = Vector{Bool}(undef,length(global_data.config.IB)) + solid_cell_flags = Vector{Bool}(undef, length(global_data.config.IB)) + target_cell_flags = Vector{Bool}(undef, length(global_data.config.IB)) for i in eachindex(boundaries) boundary = boundaries[i] - inside = solid_flag(boundary,midpoint) - bf = boundary_flag(boundary,midpoint,ds,global_data) - solid_cell_flags[i] = (bf && inside)&&ip.quad.level[]==global_data.config.solver.AMR_PS_MAXLEVEL - target_cell_flags[i] = (bf && !inside)&&ip.quad.level[]==global_data.config.solver.AMR_PS_MAXLEVEL + inside = solid_flag(boundary, midpoint) + bf = boundary_flag(boundary, midpoint, ds, global_data) + solid_cell_flags[i] = + (bf && inside)&&ip.quad.level[]==global_data.config.solver.AMR_PS_MAXLEVEL + target_cell_flags[i] = + (bf && !inside)&&ip.quad.level[]==global_data.config.solver.AMR_PS_MAXLEVEL flag = flag&&(!inside||solid_cell_flags[i]) !flag&&break end @@ -263,7 +380,7 @@ function init_ps_p4est_kernel(ip, data, dp) ps_data.quadid = global_quadid(ip) ps_data.ds .= ds ps_data.midpoint .= midpoint - ps_data.prim .= initial_prim(ic;midpoint = ps_data.midpoint) + ps_data.prim .= initial_prim(ic; midpoint = ps_data.midpoint) ps_data.w .= get_conserved(ps_data, global_data) ps_data.vs_data = init_vs(ps_data.prim, global_data) for i in eachindex(solid_cell_flags) @@ -279,7 +396,7 @@ function init_ps_p4est_kernel(ip, data, dp) else inside_quad = InsideSolidData{typeof(global_data).parameters...}() dp[] = P4est_PS_Data(pointer_from_objref(inside_quad)) - push!(trees.data[treeid],inside_quad) + push!(trees.data[treeid], inside_quad) end end function init_ps_p4est(info, data) @@ -290,36 +407,35 @@ function re_init_vs4est!(trees, global_data) for i in eachindex(trees.data) for j in eachindex(trees.data[i]) ps_data = trees.data[i][j] - isa(ps_data,InsideSolidData)&&continue + isa(ps_data, InsideSolidData)&&continue # ps_data.bound_enc<0 && continue - ps_data.vs_data.df .= - discrete_maxwell(ps_data, global_data) + ps_data.vs_data.df .= discrete_maxwell(ps_data, global_data) end end end -function init_aux_points(global_data::Global_Data,solid_midpoints::Vector) - calc_intersect_point(global_data.config.IB,solid_midpoints) +function init_aux_points(global_data::Global_Data, solid_midpoints::Vector) + calc_intersect_point(global_data.config.IB, solid_midpoints) end """ $(TYPEDSIGNATURES) """ -function pre_refine!(ps4est::Ptr{p4est_t},global_data::Global_Data) - pre_ps_refine!(ps4est,global_data) +function pre_refine!(ps4est::Ptr{p4est_t}, global_data::Global_Data) + pre_ps_refine!(ps4est, global_data) pre_ps_balance!(ps4est) - solid_midpoints = Vector{Vector{Vector{Float64}}}(undef,length(global_data.config.IB)) # boundaries{solidcells{midpoints{}}} + solid_midpoints = Vector{Vector{Vector{Float64}}}(undef, length(global_data.config.IB)) # boundaries{solidcells{midpoints{}}} for i in eachindex(solid_midpoints) solid_midpoints[i] = Vector{Float64}[] end data = [global_data, solid_midpoints] p_data = pointer_from_objref(data) GC.@preserve data AMR_4est_volume_iterate(ps4est, p_data, init_solid_midpoints) - solid_midpoints = broadcast_boundary_midpoints!(solid_midpoints,global_data) - data = [global_data,solid_midpoints] + solid_midpoints = broadcast_boundary_midpoints!(solid_midpoints, global_data) + data = [global_data, solid_midpoints] PointerWrapper(ps4est).user_pointer = pointer_from_objref(data) - GC.@preserve data begin - IB_pre_ps_refine!(ps4est,global_data) - pre_ps_coarsen!(ps4est;recursive=1) + GC.@preserve data begin + IB_pre_ps_refine!(ps4est, global_data) + pre_ps_coarsen!(ps4est; recursive = 1) end AMR_partition(ps4est) pre_ps_balance!(ps4est) @@ -327,30 +443,30 @@ end """ $(TYPEDSIGNATURES) """ -function pre_refine!(ps4est::Ptr{p8est_t},global_data::Global_Data) - user_defined_ps_refine!(ps4est,global_data) - AMR_partition(ps4est) do p4est,which_tree,quadrant +function pre_refine!(ps4est::Ptr{p8est_t}, global_data::Global_Data) + user_defined_ps_refine!(ps4est, global_data) + AMR_partition(ps4est) do p4est, which_tree, quadrant fp = PointerWrapper(p4est) global_data = unsafe_pointer_to_objref(pointer(fp.user_pointer)) ibs = global_data.config.IB qp = PointerWrapper(quadrant) - ds,midpoint = quad_to_cell(fp,which_tree,qp) + ds, midpoint = quad_to_cell(fp, which_tree, qp) for ib in ibs - if pre_partition_box_flag(midpoint,ds,ib) + if pre_partition_box_flag(midpoint, ds, ib) return Cint(1) end end return Cint(0) end - trees = initialize_MeshData!(ps4est,global_data) - data = [global_data,trees] + trees = initialize_MeshData!(ps4est, global_data) + data = [global_data, trees] PointerWrapper(ps4est).user_pointer = pointer_from_objref(data) GC.@preserve data begin - search_radius_refine!(ps4est,global_data) + search_radius_refine!(ps4est, global_data) cell_type_decision!(ps4est) pre_ps_coarsen!(ps4est) pre_ps_balance!(ps4est) - meshed_partition!(ps4est,trees) + meshed_partition!(ps4est, trees) end PointerWrapper(ps4est).user_pointer = pointer_from_objref(global_data) return trees @@ -359,15 +475,20 @@ end """ $(TYPEDSIGNATURES) """ -function initialize_ps!(ps4est::Ptr{p4est_t},global_data::Global_Data{DIM,NDF}) where{DIM,NDF} +function initialize_ps!( + ps4est::Ptr{p4est_t}, + global_data::Global_Data{DIM,NDF}, +) where {DIM,NDF} fp = PointerWrapper(ps4est) - trees_data = - Vector{Vector{AbstractPsData{DIM,NDF}}}(undef, fp.last_local_tree[] - fp.first_local_tree[] + 1) + trees_data = Vector{Vector{AbstractPsData{DIM,NDF}}}( + undef, + fp.last_local_tree[] - fp.first_local_tree[] + 1, + ) for i in eachindex(trees_data) trees_data[i] = AbstractPsData{DIM,NDF}[] end trees = PS_Trees{DIM,NDF}(trees_data, fp.first_local_tree[] - 1) - data = [global_data,trees] + data = [global_data, trees] p_data = pointer_from_objref(data) GC.@preserve data AMR_4est_volume_iterate(ps4est, p_data, init_ps_p4est) pre_vs_refine!(trees, global_data) @@ -378,13 +499,18 @@ end """ $(TYPEDSIGNATURES) """ -function initialize_ps!(p4est::Ptr{p8est_t},global_data::Global_Data{DIM,NDF}) where{DIM,NDF} +function initialize_ps!( + p4est::Ptr{p8est_t}, + global_data::Global_Data{DIM,NDF}, +) where {DIM,NDF} fp = PointerWrapper(p4est) - trees_data = [AbstractPsData{DIM,NDF}[] for _ in 1:fp.last_local_tree[] - fp.first_local_tree[] + 1] + trees_data = [ + AbstractPsData{DIM,NDF}[] for _ = 1:(fp.last_local_tree[]-fp.first_local_tree[]+1) + ] trees = PS_Trees{DIM,NDF}(trees_data, fp.first_local_tree[] - 1) - data = [global_data,trees] + data = [global_data, trees] p_data = pointer_from_objref(data) - GC.@preserve data AMR_volume_iterate(p4est;user_data = p_data) do ip,data,dp + GC.@preserve data AMR_volume_iterate(p4est; user_data = p_data) do ip, data, dp global_data, trees = unsafe_pointer_to_objref(data) ds, midpoint = quad_to_cell(ip.p4est, ip.treeid[], ip.quad) mesh_data = unsafe_pointer_to_objref(pointer(dp.ps_data)) @@ -397,7 +523,7 @@ function initialize_ps!(p4est::Ptr{p8est_t},global_data::Global_Data{DIM,NDF}) w ps_data.quadid = global_quadid(ip) ps_data.ds .= ds ps_data.midpoint .= midpoint - ps_data.prim .= initial_prim(ic;midpoint = ps_data.midpoint,global_data) + ps_data.prim .= initial_prim(ic; midpoint = ps_data.midpoint, global_data) ps_data.w .= get_conserved(ps_data, global_data) ps_data.vs_data = init_vs(ps_data.prim, global_data) if mesh_data.is_ghost_cell @@ -406,7 +532,7 @@ function initialize_ps!(p4est::Ptr{p8est_t},global_data::Global_Data{DIM,NDF}) w else inside_quad = InsideSolidData{typeof(global_data).parameters...}() dp[] = P4est_PS_Data(pointer_from_objref(inside_quad)) - push!(trees.data[treeid],inside_quad) + push!(trees.data[treeid], inside_quad) end end pre_vs_refine!(trees, global_data) @@ -418,7 +544,7 @@ end $(TYPEDSIGNATURES) Initialize field for 2D case. """ -function initialize_field!(global_data::Global_Data{DIM,NDF}) where{DIM,NDF} +function initialize_field!(global_data::Global_Data{DIM,NDF}) where {DIM,NDF} GC.@preserve global_data begin connectivity_ps = set_connectivity(global_data) ps4est = AMR_4est_new( @@ -428,8 +554,8 @@ function initialize_field!(global_data::Global_Data{DIM,NDF}) where{DIM,NDF} pointer_from_objref(global_data), ) global_data.forest.p4est = ps4est - pre_refine!(ps4est,global_data) - trees = initialize_ps!(ps4est,global_data) + pre_refine!(ps4est, global_data) + trees = initialize_ps!(ps4est, global_data) return trees, ps4est end end @@ -438,7 +564,7 @@ end $(TYPEDSIGNATURES) Initialize field for 3D case. """ -function initialize_field!(global_data::Global_Data{3,NDF}) where{NDF} +function initialize_field!(global_data::Global_Data{3,NDF}) where {NDF} GC.@preserve global_data begin connectivity_ps = set_connectivity(global_data) ps4est = AMR_4est_new( @@ -448,9 +574,9 @@ function initialize_field!(global_data::Global_Data{3,NDF}) where{NDF} pointer_from_objref(global_data), ) global_data.forest.p4est = ps4est - mesh_tree = pre_refine!(ps4est,global_data) + mesh_tree = pre_refine!(ps4est, global_data) GC.@preserve mesh_tree begin - trees = initialize_ps!(ps4est,global_data) + trees = initialize_ps!(ps4est, global_data) end return trees, ps4est end @@ -460,10 +586,10 @@ end $(TYPEDSIGNATURES) Initialize [`Ghost`](@ref) structure. """ -function initialize_ghost(p4est::P_pxest_t,global_data::Global_Data) - ghost_exchange = initialize_ghost_exchange(p4est,global_data) - ghost_wrap = initialize_ghost_wrap(global_data,ghost_exchange) - return Ghost(ghost_exchange,ghost_wrap) +function initialize_ghost(p4est::P_pxest_t, global_data::Global_Data) + ghost_exchange = initialize_ghost_exchange(p4est, global_data) + ghost_wrap = initialize_ghost_wrap(global_data, ghost_exchange) + return Ghost(ghost_exchange, ghost_wrap) end """ @@ -473,11 +599,13 @@ Initialize everthing according to `config` dictionary. function initialize_KitAMR(config::Dict) global_data = Global_Data(config) trees, ps4est = initialize_field!(global_data) - field = Field{config[:DIM],config[:NDF]}(trees,Vector{AbstractFace}(undef,0),ImmersedBoundary()) - MPI.Barrier(MPI.COMM_WORLD) - amr = KitAMR_Data( - global_data,field + field = Field{config[:DIM],config[:NDF]}( + trees, + Vector{AbstractFace}(undef, 0), + ImmersedBoundary(), ) + MPI.Barrier(MPI.COMM_WORLD) + amr = KitAMR_Data(global_data, field) PointerWrapper(ps4est).user_pointer = pointer_from_objref(amr) ps_partition!(ps4est, amr) ghost_ps = AMR_ghost_new(ps4est) @@ -488,16 +616,14 @@ function initialize_KitAMR(config::Dict) initialize_neighbor_data!(ps4est, amr) initialize_solid_neighbor!(amr) initialize_faces!(ps4est, amr) - return ps4est,amr + return ps4est, amr end -function initialize_KitAMR(config::Configure{DIM,NDF}) where{DIM,NDF} +function initialize_KitAMR(config::Configure{DIM,NDF}) where {DIM,NDF} global_data = Global_Data(config) trees, ps4est = initialize_field!(global_data) - field = Field{DIM,NDF}(trees,Vector{AbstractFace}(undef,0),ImmersedBoundary()) + field = Field{DIM,NDF}(trees, Vector{AbstractFace}(undef, 0), ImmersedBoundary()) MPI.Barrier(MPI.COMM_WORLD) - amr = KitAMR_Data( - global_data,field - ) + amr = KitAMR_Data(global_data, field) PointerWrapper(ps4est).user_pointer = pointer_from_objref(amr) ps_partition!(ps4est, amr) ghost_ps = AMR_ghost_new(ps4est) @@ -508,5 +634,5 @@ function initialize_KitAMR(config::Configure{DIM,NDF}) where{DIM,NDF} initialize_neighbor_data!(ps4est, amr) initialize_solid_neighbor!(amr) initialize_faces!(ps4est, amr) - return ps4est,amr -end \ No newline at end of file + return ps4est, amr +end diff --git a/src/Solver/Solver.jl b/src/Solver/Solver.jl index b6fb0b4..e32f60f 100644 --- a/src/Solver/Solver.jl +++ b/src/Solver/Solver.jl @@ -3,7 +3,9 @@ include("Auxiliary.jl") include("Finalize.jl") include("Initialize.jl") export Configure, Uniform, PCoordFn, Solver, Output, UDF -export KitAMR_Data, Global_Data, Forest, Status, Residual, Ghost, Ghost_Exchange, PS_Trees, Field +export KitAMR_Data, + Global_Data, Forest, Status, Residual, Ghost, Ghost_Exchange, PS_Trees, Field export residual_check!, finalize!, check_for_convergence -export initialize_KitAMR, initialize_ps!, initialize_ghost, initialize_field!, pre_refine!, initialize_faces! -export adaptive_mesh_refinement!, amr_recover! \ No newline at end of file +export initialize_KitAMR, + initialize_ps!, initialize_ghost, initialize_field!, pre_refine!, initialize_faces! +export adaptive_mesh_refinement!, amr_recover! diff --git a/src/Solver/Types.jl b/src/Solver/Types.jl index 7541534..206ebea 100644 --- a/src/Solver/Types.jl +++ b/src/Solver/Types.jl @@ -6,9 +6,8 @@ Uniform initial condition. The field will be initialized with the Maxwellian dis ## Fields $(TYPEDFIELDS) - """ -struct Uniform<:AbstractInitCondType +struct Uniform<:AbstractInitCondType ic::AbstractVector end """ @@ -20,7 +19,6 @@ The function will return primary macroscopic variables vector according to the i ## Fields $(TYPEDFIELDS) - """ struct PCoordFn<:AbstractInitCondType # A function that accepts physical coordinates and returns initial primary variable at the position. PCIC_fn::Function @@ -36,7 +34,6 @@ Structure of solver configuration. ## Fields $(TYPEDFIELDS) - """ struct Solver{DIM,NDF} "Courant-Friedrichs-Lewy number. Default is `0.4`." @@ -57,23 +54,35 @@ struct Solver{DIM,NDF} VS_DYNAMIC_AMR::Bool end function Solver(config::Dict) - return Solver{config[:DIM],config[:NDF]}(config[:CFL],config[:AMR_PS_MAXLEVEL], - haskey(config,:AMR_DYNAMIC_PS_MAXLEVEL) ? config[:AMR_DYNAMIC_PS_MAXLEVEL] : config[:AMR_PS_MAXLEVEL], - config[:AMR_VS_MAXLEVEL],config[:flux],config[:time_marching], - (haskey(config,:PS_DYNAMIC_AMR) ? config[:PS_DYNAMIC_AMR] : true), - (haskey(config,:VS_DYNAMIC_AMR) ? config[:VS_DYNAMIC_AMR] : true), - ) -end -function Solver(;kwargs...) - CFL = haskey(kwargs,:CFL) ? kwargs[:CFL] : 0.4 - AMR_DYNAMIC_PS_MAXLEVEL = haskey(kwargs,:AMR_DYNAMIC_PS_MAXLEVEL) ? kwargs[:AMR_DYNAMIC_PS_MAXLEVEL] : kwargs[:AMR_PS_MAXLEVEL] - PS_DYNAMIC_AMR = haskey(kwargs,:PS_DYNAMIC_AMR) ? kwargs[:PS_DYNAMIC_AMR] : true - VS_DYNAMIC_AMR = haskey(kwargs,:VS_DYNAMIC_AMR) ? kwargs[:VS_DYNAMIC_AMR] : true + return Solver{config[:DIM],config[:NDF]}( + config[:CFL], + config[:AMR_PS_MAXLEVEL], + haskey(config, :AMR_DYNAMIC_PS_MAXLEVEL) ? config[:AMR_DYNAMIC_PS_MAXLEVEL] : + config[:AMR_PS_MAXLEVEL], + config[:AMR_VS_MAXLEVEL], + config[:flux], + config[:time_marching], + (haskey(config, :PS_DYNAMIC_AMR) ? config[:PS_DYNAMIC_AMR] : true), + (haskey(config, :VS_DYNAMIC_AMR) ? config[:VS_DYNAMIC_AMR] : true), + ) +end +function Solver(; kwargs...) + CFL = haskey(kwargs, :CFL) ? kwargs[:CFL] : 0.4 + AMR_DYNAMIC_PS_MAXLEVEL = + haskey(kwargs, :AMR_DYNAMIC_PS_MAXLEVEL) ? kwargs[:AMR_DYNAMIC_PS_MAXLEVEL] : + kwargs[:AMR_PS_MAXLEVEL] + PS_DYNAMIC_AMR = haskey(kwargs, :PS_DYNAMIC_AMR) ? kwargs[:PS_DYNAMIC_AMR] : true + VS_DYNAMIC_AMR = haskey(kwargs, :VS_DYNAMIC_AMR) ? kwargs[:VS_DYNAMIC_AMR] : true return Solver{kwargs[:DIM],kwargs[:NDF]}( - CFL,kwargs[:AMR_PS_MAXLEVEL],AMR_DYNAMIC_PS_MAXLEVEL, - kwargs[:AMR_VS_MAXLEVEL],kwargs[:flux],kwargs[:time_marching], - PS_DYNAMIC_AMR,VS_DYNAMIC_AMR - ) + CFL, + kwargs[:AMR_PS_MAXLEVEL], + AMR_DYNAMIC_PS_MAXLEVEL, + kwargs[:AMR_VS_MAXLEVEL], + kwargs[:flux], + kwargs[:time_marching], + PS_DYNAMIC_AMR, + VS_DYNAMIC_AMR, + ) end """ @@ -84,7 +93,6 @@ Structure of user-defined-functions. ## Fields $(TYPEDFIELDS) - """ mutable struct UDF "The static AMR flag in physical space." @@ -92,18 +100,17 @@ mutable struct UDF "The dynamic AMR flag in physical space." dynamic_ps_refine_flag::Function "The static AMR flag in velocity space." - static_vs_refine_flag::Function -end -null_udf(args...;kwargs...) = false -function UDF(;kwargs...) - static_ps_refine_flag = haskey(kwargs,:static_ps_refine_flag) ? kwargs[:static_ps_refine_flag] : null_udf - dynamic_ps_refine_flag = haskey(kwargs,:dynamic_ps_refine_flag) ? kwargs[:dynamic_ps_refine_flag] : null_udf - static_vs_refine_flag = haskey(kwargs,:static_vs_refine_flag) ? kwargs[:static_vs_refine_flag] : null_udf - return UDF( - static_ps_refine_flag, - dynamic_ps_refine_flag, - static_vs_refine_flag - ) + static_vs_refine_flag::Function +end +null_udf(args...; kwargs...) = false +function UDF(; kwargs...) + static_ps_refine_flag = + haskey(kwargs, :static_ps_refine_flag) ? kwargs[:static_ps_refine_flag] : null_udf + dynamic_ps_refine_flag = + haskey(kwargs, :dynamic_ps_refine_flag) ? kwargs[:dynamic_ps_refine_flag] : null_udf + static_vs_refine_flag = + haskey(kwargs, :static_vs_refine_flag) ? kwargs[:static_vs_refine_flag] : null_udf + return UDF(static_ps_refine_flag, dynamic_ps_refine_flag, static_vs_refine_flag) end """ $(TYPEDEF) @@ -113,13 +120,12 @@ Structure of output information. ## Fields $(TYPEDFIELDS) - """ mutable struct Output "VTK cell type in physical space. Available options: `Pixel` and `Triangle` for 2D; `Voxel` and `Tetra` for 3D. Default is [`Triangle`](@ref) for 2D and [`Tetra`](@ref) for 3D." - vtk_celltype::Type{Tp} where{Tp<:AbstractVTKCellType} + vtk_celltype::Type{Tp} where {Tp<:AbstractVTKCellType} "VTK cell type in velocity space. Available options: `Pixel` for 2D." - vs_vtk_celltype::Type{Tv} where{Tv<:AbstractVTKCellType} + vs_vtk_celltype::Type{Tv} where {Tv<:AbstractVTKCellType} "Time interval between animation frames." anim_dt::Float64 "User-defined-function determining the physical cells need to output the velocity space." @@ -131,24 +137,22 @@ function Output(config::Dict) output = Output( config[:DIM]==2 ? Triangle : Tetra, config[:DIM]==2 ? Pixel : Voxel, - 0.,null_udf,0 + 0.0, + null_udf, + 0, ) for i in fieldnames(Output) - if haskey(config,i) - setfield!(n,i,config[i]) + if haskey(config, i) + setfield!(n, i, config[i]) end end return output end -function Output(solver::Solver{DIM,NDF};kwargs...) where{DIM,NDF} - output = Output( - DIM==2 ? Triangle : Tetra, - DIM==2 ? Pixel : Voxel, - 0.,null_udf,0 - ) +function Output(solver::Solver{DIM,NDF}; kwargs...) where {DIM,NDF} + output = Output(DIM==2 ? Triangle : Tetra, DIM==2 ? Pixel : Voxel, 0.0, null_udf, 0) for i in fieldnames(Output) - if haskey(kwargs,i) - setfield!(n,i,kwargs[i]) + if haskey(kwargs, i) + setfield!(n, i, kwargs[i]) end end return output @@ -163,7 +167,6 @@ This struct plays an key role in the solution process. ## Fields $(TYPEDFIELDS) - """ struct Configure{DIM,NDF} "Range of the simulated domain. As an example, for 2D case, it should be aligned as [xmin,xmax,ymin,ymax]." @@ -189,51 +192,69 @@ struct Configure{DIM,NDF} "Functions defined by users, including some criteria." user_defined::UDF end -function config_IB(ib::Circle,config::Dict) - ds = minimum([(config[:geometry][2i]-config[:geometry][2i-1])/config[:trees_num][i]/2^config[:AMR_PS_MAXLEVEL] for i in 1:config[:DIM]]) - Circle(ib,ds) +function config_IB(ib::Circle, config::Dict) + ds = minimum([ + ( + config[:geometry][2i]-config[:geometry][2i-1] + )/config[:trees_num][i]/2^config[:AMR_PS_MAXLEVEL] for i = 1:config[:DIM] + ]) + Circle(ib, ds) end -function config_IB(ib::Sphere,config::Dict) - ds = minimum([(config[:geometry][2i]-config[:geometry][2i-1])/config[:trees_num][i]/2^config[:AMR_PS_MAXLEVEL] for i in 1:config[:DIM]]) - Sphere(ib,ds) +function config_IB(ib::Sphere, config::Dict) + ds = minimum([ + ( + config[:geometry][2i]-config[:geometry][2i-1] + )/config[:trees_num][i]/2^config[:AMR_PS_MAXLEVEL] for i = 1:config[:DIM] + ]) + Sphere(ib, ds) end -function config_IB(ib::Vertices,config::Dict) - Vertices(ib,config) +function config_IB(ib::Vertices, config::Dict) + Vertices(ib, config) end -function config_IB(ib::Triangles,config::Dict) - Triangles(ib,config) +function config_IB(ib::Triangles, config::Dict) + Triangles(ib, config) end function Configure(config::Dict) gas = Gas() for i in fieldnames(Gas) - if haskey(config,i) - setfield!(gas,i,config[i]) + if haskey(config, i) + setfield!(gas, i, config[i]) end end - if !haskey(config,:μᵣ) - gas.μᵣ = ref_vhs_vis(gas.Kn,gas.αᵣ,gas.ωᵣ) + if !haskey(config, :μᵣ) + gas.μᵣ = ref_vhs_vis(gas.Kn, gas.αᵣ, gas.ωᵣ) end - IB = haskey(config,:IB) ? config[:IB] : [] + IB = haskey(config, :IB) ? config[:IB] : [] for i in eachindex(IB) - IB[i] = config_IB(IB[i],config) + IB[i] = config_IB(IB[i], config) end user_defined = UDF() for i in fieldnames(UDF) - if haskey(config,i) - setfield!(user_defined,i,config[i]) + if haskey(config, i) + setfield!(user_defined, i, config[i]) else - setfield!(user_defined,i,null_udf) + setfield!(user_defined, i, null_udf) end end - return Configure{config[:DIM],config[:NDF]}(config[:geometry],config[:trees_num], - config[:quadrature],config[:vs_trees_num],config[:IC],config[:domain],IB, - gas,Solver(config),Output(config),user_defined) + return Configure{config[:DIM],config[:NDF]}( + config[:geometry], + config[:trees_num], + config[:quadrature], + config[:vs_trees_num], + config[:IC], + config[:domain], + IB, + gas, + Solver(config), + Output(config), + user_defined, + ) end -function Configure(solver::Solver{DIM,NDF};kwargs...) where{DIM,NDF} +function Configure(solver::Solver{DIM,NDF}; kwargs...) where {DIM,NDF} geometry = kwargs[:geometry] trees_num = kwargs[:trees_num] AMR_PS_MAXLEVEL = solver.AMR_PS_MAXLEVEL - IB = haskey(kwargs,:IB) ? kwargs[:IB] : [] + IB = haskey(kwargs, :IB) ? kwargs[:IB] : [] config_dict = Dict( :DIM=>DIM, :geometry=>geometry, @@ -241,7 +262,7 @@ function Configure(solver::Solver{DIM,NDF};kwargs...) where{DIM,NDF} :AMR_PS_MAXLEVEL=>AMR_PS_MAXLEVEL, ) for i in eachindex(IB) - IB[i] = config_IB(IB[i],config_dict) + IB[i] = config_IB(IB[i], config_dict) end return Configure{DIM,NDF}( geometry, @@ -254,7 +275,7 @@ function Configure(solver::Solver{DIM,NDF};kwargs...) where{DIM,NDF} kwargs[:gas], solver, kwargs[:output], - kwargs[:user_defined] + kwargs[:user_defined], ) end """ @@ -266,11 +287,12 @@ mutable struct Forest{DIM} p4est::P_pxest_t ghost::P_pxest_ghost_t mesh::P_pxest_mesh_t - Forest(DIM) = (n = new{DIM}(); - n.p4est = Ptr{pxest_ts[DIM-1]}(C_NULL); - n.ghost = Ptr{pxest_ghost_ts[DIM-1]}(C_NULL); - n.mesh = Ptr{pxest_mesh_ts[DIM-1]}(C_NULL); - n + Forest(DIM) = ( + n = new{DIM}(); + n.p4est = Ptr{pxest_ts[DIM-1]}(C_NULL); + n.ghost = Ptr{pxest_ghost_ts[DIM-1]}(C_NULL); + n.mesh = Ptr{pxest_mesh_ts[DIM-1]}(C_NULL); + n ) end """ @@ -290,7 +312,7 @@ mutable struct Residual redundant_step::Int end function Residual(DIM::Int) - return Residual(1,ones(DIM+2),zeros(DIM+2),zeros(DIM+2),0) + return Residual(1, ones(DIM+2), zeros(DIM+2), zeros(DIM+2), 0) end """ @@ -334,24 +356,64 @@ function Status(config::Dict) geometry = config[:geometry] vs_trees_num = config[:vs_trees_num] quadrature = config[:quadrature] - ds = [(geometry[2*i]-geometry[2*i-1])/trees_num[i]/2^config[:AMR_PS_MAXLEVEL] for i in 1:DIM] - U = isa(quadrature,Vector) ? [max(quadrature[2*i],abs(quadrature[2*i-1])) - - (quadrature[2*i] - quadrature[2*i-1]) / vs_trees_num[i]/ - 2^config[:AMR_VS_MAXLEVEL] / 2 for i in 1:DIM] : [maximum(abs.(quadrature.vcoords)) for _ in 1:DIM] + ds = [ + (geometry[2*i]-geometry[2*i-1])/trees_num[i]/2^config[:AMR_PS_MAXLEVEL] for + i = 1:DIM + ] + U = + isa(quadrature, Vector) ? + [ + max(quadrature[2*i], abs(quadrature[2*i-1])) - + (quadrature[2*i] - quadrature[2*i-1]) / vs_trees_num[i] / + 2^config[:AMR_VS_MAXLEVEL] / 2 for i = 1:DIM + ] : [maximum(abs.(quadrature.vcoords)) for _ = 1:DIM] Δt_ξ = config[:CFL]*minimum(ds ./ U) - return Status(0,zeros(DIM+2),zeros(DIM+2), zeros(DIM+2), Δt_ξ,Δt_ξ,0.,1,1,1,Residual(DIM),Ref(false)) + return Status( + 0, + zeros(DIM+2), + zeros(DIM+2), + zeros(DIM+2), + Δt_ξ, + Δt_ξ, + 0.0, + 1, + 1, + 1, + Residual(DIM), + Ref(false), + ) end -function Status(config::Configure{DIM,NDF}) where{DIM,NDF} +function Status(config::Configure{DIM,NDF}) where {DIM,NDF} trees_num = config.trees_num geometry = config.geometry vs_trees_num = config.vs_trees_num quadrature = config.quadrature - ds = [(geometry[2*i]-geometry[2*i-1])/trees_num[i]/2^config.solver.AMR_PS_MAXLEVEL for i in 1:DIM] - U = isa(quadrature,Vector) ? [max(quadrature[2*i],abs(quadrature[2*i-1])) - - (quadrature[2*i] - quadrature[2*i-1]) / vs_trees_num[i]/ - 2^config.solver.AMR_VS_MAXLEVEL / 2 for i in 1:DIM] : [maximum(abs.(quadrature.vcoords)) for _ in 1:DIM] + ds = [ + (geometry[2*i]-geometry[2*i-1])/trees_num[i]/2^config.solver.AMR_PS_MAXLEVEL for + i = 1:DIM + ] + U = + isa(quadrature, Vector) ? + [ + max(quadrature[2*i], abs(quadrature[2*i-1])) - + (quadrature[2*i] - quadrature[2*i-1]) / vs_trees_num[i] / + 2^config.solver.AMR_VS_MAXLEVEL / 2 for i = 1:DIM + ] : [maximum(abs.(quadrature.vcoords)) for _ = 1:DIM] Δt_ξ = config.solver.CFL*minimum(ds ./ U) - return Status(0,zeros(DIM+2),zeros(DIM+2), zeros(DIM+2), Δt_ξ,Δt_ξ,0.,1,1,1,Residual(DIM),Ref(false)) + return Status( + 0, + zeros(DIM+2), + zeros(DIM+2), + zeros(DIM+2), + Δt_ξ, + Δt_ξ, + 0.0, + 1, + 1, + 1, + Residual(DIM), + Ref(false), + ) end """ @@ -366,17 +428,19 @@ mutable struct Global_Data{DIM,NDF} forest::Forest{DIM} "Defined by [`Status`](@ref)." status::Status - Global_Data(config::Dict) = (n = new{config[:DIM],config[:NDF]}(); - n.config = Configure(config); - n.forest = Forest(config[:DIM]); - n.status = Status(config); - n + Global_Data(config::Dict) = ( + n = new{config[:DIM],config[:NDF]}(); + n.config = Configure(config); + n.forest = Forest(config[:DIM]); + n.status = Status(config); + n ) - Global_Data(config::Configure{DIM,NDF}) where{DIM,NDF} = (n = new{DIM,NDF}(); - n.config = config; - n.forest = Forest(DIM); - n.status = Status(config); - n + Global_Data(config::Configure{DIM,NDF}) where {DIM,NDF} = ( + n = new{DIM,NDF}(); + n.config = config; + n.forest = Forest(DIM); + n.status = Status(config); + n ) end @@ -390,12 +454,12 @@ Structure of ghost data and pointers used by `p4est`. $(TYPEDFIELDS) """ mutable struct Ghost_Exchange - ghost_datas - ghost_slopes - ghost_structures - mirror_data_pointers - mirror_slope_pointers - mirror_structure_pointers + ghost_datas::Any + ghost_slopes::Any + ghost_structures::Any + mirror_data_pointers::Any + mirror_slope_pointers::Any + mirror_structure_pointers::Any end """ @@ -403,7 +467,7 @@ $(TYPEDEF) Structure of cells data managed by `Julia`. $(TYPEDFIELDS) """ -mutable struct PS_Trees{DIM,NDF} +mutable struct PS_Trees{DIM,NDF} data::Vector{Vector{AbstractPsData{DIM,NDF}}} "Offset of treeid used in partition." offset::Int @@ -441,11 +505,8 @@ mutable struct KitAMR_Data{DIM,NDF} global_data::Global_Data ghost::Ghost field::Field{DIM,NDF} - KitAMR_Data(global_data::Global_Data{DIM,NDF},field) where{DIM,NDF} = (n = new{DIM,NDF}(); - n.global_data = global_data; - n.field = field; - n - ) + KitAMR_Data(global_data::Global_Data{DIM,NDF}, field) where {DIM,NDF} = + (n = new{DIM,NDF}(); n.global_data = global_data; n.field = field; n) end # partition @@ -456,13 +517,13 @@ struct Transfer_Data{DIM,NDF} vs_midpoints::Vector{Float64} vs_df::Vector{Float64} end -function Transfer_Data(DIM::Integer,NDF::Integer,ps_num::Integer,total_vs_num::Integer) +function Transfer_Data(DIM::Integer, NDF::Integer, ps_num::Integer, total_vs_num::Integer) return Transfer_Data{DIM,NDF}( Vector{Int}(undef, (SOLID_CELL_ID_NUM+1)*ps_num), Vector{Float64}(undef, (DIM+2) * ps_num), Vector{Int8}(undef, total_vs_num), Vector{Float64}(undef, DIM * total_vs_num), - Vector{Float64}(undef, NDF * total_vs_num) + Vector{Float64}(undef, NDF * total_vs_num), ) end @@ -476,4 +537,4 @@ mutable struct Transfer_Init up_index::Int up_insert_index::Int down_index::Int -end \ No newline at end of file +end diff --git a/src/Theory/Iterate.jl b/src/Theory/Iterate.jl index 991ec28..498c8bb 100644 --- a/src/Theory/Iterate.jl +++ b/src/Theory/Iterate.jl @@ -4,7 +4,7 @@ Outer function of collision and time marching. """ function iterate!(amr::KitAMR_Data) time_marching = amr.global_data.config.solver.time_marching - iterate!(time_marching,amr) + iterate!(time_marching, amr) residual_comm!(amr.global_data) amr.global_data.status.ps_adapt_step += 1 amr.global_data.status.vs_adapt_step += 1 @@ -13,7 +13,7 @@ function iterate!(amr::KitAMR_Data) amr.global_data.status.sim_time+=amr.global_data.status.Δt return nothing end -function iterate!(::Type{UGKS_Marching},amr::KitAMR_Data) +function iterate!(::Type{UGKS_Marching}, amr::KitAMR_Data) global_data = amr.global_data gas = global_data.config.gas trees = amr.field.trees @@ -22,7 +22,7 @@ function iterate!(::Type{UGKS_Marching},amr::KitAMR_Data) @inbounds for i in eachindex(trees.data) @inbounds for j in eachindex(trees.data[i]) ps_data = trees.data[i][j] - isa(ps_data,InsideSolidData) && continue + isa(ps_data, InsideSolidData) && continue ps_data.bound_enc<0 && continue vs_data = ps_data.vs_data prim_ = get_prim(ps_data, global_data) @@ -33,14 +33,14 @@ function iterate!(::Type{UGKS_Marching},amr::KitAMR_Data) ps_data.prim .= prim = get_prim(ps_data, global_data) f = vs_data.df if 1/prim[end]<1e-6 - @. f = max(f,0.) + @. f = max(f, 0.0) ps_data.w = calc_w0(ps_data) - prim = get_prim(ps_data,global_data) + prim = get_prim(ps_data, global_data) τ = global_data.config.gas.Kn else τ = get_τ(prim, gas.μᵣ, gas.ω) end - residual_check!(ps_data,prim_,global_data) + residual_check!(ps_data, prim_, global_data) ps_data.qf .= qf = calc_qf(vs_data, prim_) F_ = discrete_maxwell(vs_data.midpoint, prim_, global_data) F = discrete_maxwell(vs_data.midpoint, prim, global_data) @@ -49,7 +49,10 @@ function iterate!(::Type{UGKS_Marching},amr::KitAMR_Data) F⁺ = shakhov_part(vs_data.midpoint, F, prim, qf, global_data) F .+= F⁺ f = vs_data.df - @inbounds @. f = abs((f + 0.5 * Δt * (F / τ + (F_ - f) / τ_)) / (1.0 + 0.5 * Δt / τ) + vs_data.flux / area / (1.0 + 0.5 * Δt / τ)) + @inbounds @. f = abs( + (f + 0.5 * Δt * (F / τ + (F_ - f) / τ_)) / (1.0 + 0.5 * Δt / τ) + + vs_data.flux / area / (1.0 + 0.5 * Δt / τ), + ) vs_data.flux .= 0.0 end end @@ -60,7 +63,7 @@ end $(TYPEDSIGNATURES) Iteration for Conserved Adaptive Implicit DVM (CAIDVM). """ -function iterate!(::Type{CAIDVM_Marching},amr::KitAMR_Data) +function iterate!(::Type{CAIDVM_Marching}, amr::KitAMR_Data) global_data = amr.global_data gas = global_data.config.gas trees = amr.field.trees @@ -68,16 +71,16 @@ function iterate!(::Type{CAIDVM_Marching},amr::KitAMR_Data) for i in eachindex(trees.data) @inbounds for j in eachindex(trees.data[i]) ps_data = trees.data[i][j] - isa(ps_data,InsideSolidData) && continue + isa(ps_data, InsideSolidData) && continue ps_data.bound_enc<0 && continue vs_data = ps_data.vs_data area = reduce(*, ps_data.ds) - ps_data.w .+= ps_data.flux .*Δt / area # Macroscopic update + ps_data.w .+= ps_data.flux .* Δt / area # Macroscopic update prim_c = get_prim(ps_data, global_data) # Conserved macroscopic variables f = vs_data.df - f.+= Δt/area*vs_data.flux # Convection first - w = calc_w0(vs_data.midpoint,f,vs_data.weight,global_data) - prim = get_prim(w,global_data) + f .+= Δt/area*vs_data.flux # Convection first + w = calc_w0(vs_data.midpoint, f, vs_data.weight, global_data) + prim = get_prim(w, global_data) τ = get_τ(prim_c, gas.μᵣ, gas.ω) # τ^{n+1} F_c = discrete_maxwell(vs_data.midpoint, prim_c, global_data) F = discrete_maxwell(vs_data.midpoint, prim, global_data) @@ -87,7 +90,7 @@ function iterate!(::Type{CAIDVM_Marching},amr::KitAMR_Data) # Collision process f .*= τ/(τ+Δt) @. f += Δt/(τ+Δt)*F_c - residual_check!(ps_data,prim_c,global_data) + residual_check!(ps_data, prim_c, global_data) ps_data.prim .= prim_c ps_data.flux .= 0.0 vs_data.flux .= 0.0 @@ -95,7 +98,7 @@ function iterate!(::Type{CAIDVM_Marching},amr::KitAMR_Data) end return nothing end -function iterate!(::Type{Euler},amr::KitAMR_Data{DIM}) where{DIM} +function iterate!(::Type{Euler}, amr::KitAMR_Data{DIM}) where {DIM} global_data = amr.global_data gas = global_data.config.gas trees = amr.field.trees @@ -104,11 +107,11 @@ function iterate!(::Type{Euler},amr::KitAMR_Data{DIM}) where{DIM} @inbounds for i in eachindex(trees.data) @inbounds for j in eachindex(trees.data[i]) ps_data = trees.data[i][j] - isa(ps_data,InsideSolidData) && continue + isa(ps_data, InsideSolidData) && continue ps_data.bound_enc<0 && continue vs_data = ps_data.vs_data area = reduce(*, ps_data.ds) - if isa(amr.global_data.config.solver.flux,MicroFlux) + if isa(amr.global_data.config.solver.flux, MicroFlux) ps_data.w = calc_w0(ps_data) else ps_data.w .+= ps_data.flux ./ area @@ -121,9 +124,9 @@ function iterate!(::Type{Euler},amr::KitAMR_Data{DIM}) where{DIM} F = discrete_maxwell(vs_data.midpoint, prim, global_data) F .+= shakhov_part(vs_data.midpoint, F, prim, qf, global_data) @. f = (τ-Δt)/τ*f+Δt/τ*F+Δt/area*vs_data.flux - residual_check!(ps_data,prim,global_data) + residual_check!(ps_data, prim, global_data) ps_data.prim .= prim vs_data.flux .= 0.0 end end -end \ No newline at end of file +end diff --git a/src/Theory/Math.jl b/src/Theory/Math.jl index 0a3cd56..bf0ad77 100644 --- a/src/Theory/Math.jl +++ b/src/Theory/Math.jl @@ -74,20 +74,14 @@ function discrete_maxwell( prim::AbstractVector, ::Global_Data{3,1}, ) - discrete_maxwell_3D1F( - midpoint[1], - midpoint[2], - midpoint[3], - prim, - ) + discrete_maxwell_3D1F(midpoint[1], midpoint[2], midpoint[3], prim) end -function discrete_maxwell(midpoint::AbstractVector,prim::AbstractVector,global_data::Global_Data{2,2}) - discrete_maxwell_2D2F( - midpoint[1], - midpoint[2], - prim, - global_data.config.gas.K, - ) +function discrete_maxwell( + midpoint::AbstractVector, + prim::AbstractVector, + global_data::Global_Data{2,2}, +) + discrete_maxwell_2D2F(midpoint[1], midpoint[2], prim, global_data.config.gas.K) end """ @@ -118,7 +112,7 @@ function shakhov_part( prim::AbstractVector, qf::AbstractVector, global_data::Global_Data{2,2}, -) where{T<:Union{Tuple,AbstractVector}} +) where {T<:Union{Tuple,AbstractVector}} shakhov_part_2D2F( midpoint[1], midpoint[2], @@ -142,7 +136,7 @@ function shakhov_part( midpoint[:, 1], midpoint[:, 2], midpoint[:, 3], - F[:,1], + F[:, 1], prim, qf, global_data.config.gas.Pr, @@ -178,23 +172,68 @@ end $(TYPEDSIGNATURES) Calculate the conserved macroscopic variables according to the microscopic distribution. """ -function calc_w0(midpoint::AbstractMatrix,df::AbstractMatrix,weight::AbstractVector,::Global_Data{2,2}) - @views micro_to_macro_2D2F(midpoint[:,1],midpoint[:,2],df[:,1],df[:,2],weight) +function calc_w0( + midpoint::AbstractMatrix, + df::AbstractMatrix, + weight::AbstractVector, + ::Global_Data{2,2}, +) + @views micro_to_macro_2D2F(midpoint[:, 1], midpoint[:, 2], df[:, 1], df[:, 2], weight) end -function calc_w0(midpoint::AbstractMatrix,df::AbstractMatrix,weight::AbstractVector,::Global_Data{3,1}) - @views micro_to_macro_3D1F(midpoint[:,1],midpoint[:,2],midpoint[:,3],df[:,1],weight) +function calc_w0( + midpoint::AbstractMatrix, + df::AbstractMatrix, + weight::AbstractVector, + ::Global_Data{3,1}, +) + @views micro_to_macro_3D1F( + midpoint[:, 1], + midpoint[:, 2], + midpoint[:, 3], + df[:, 1], + weight, + ) end -function calc_qf(midpoint::AbstractMatrix,df::AbstractMatrix,weight::AbstractVector,prim::AbstractVector,::Global_Data{2,2}) - @views heat_flux_2D2F(midpoint[:,1],midpoint[:,2],df[:,1],df[:,2],prim,weight) +function calc_qf( + midpoint::AbstractMatrix, + df::AbstractMatrix, + weight::AbstractVector, + prim::AbstractVector, + ::Global_Data{2,2}, +) + @views heat_flux_2D2F(midpoint[:, 1], midpoint[:, 2], df[:, 1], df[:, 2], prim, weight) end -function calc_qf(midpoint::AbstractMatrix,df::AbstractMatrix,weight::AbstractVector,prim::AbstractVector,::Global_Data{3,1}) - @views heat_flux_3D1F(midpoint[:,1],midpoint[:,2],midpoint[:,3],df[:,1],prim,weight) +function calc_qf( + midpoint::AbstractMatrix, + df::AbstractMatrix, + weight::AbstractVector, + prim::AbstractVector, + ::Global_Data{3,1}, +) + @views heat_flux_3D1F( + midpoint[:, 1], + midpoint[:, 2], + midpoint[:, 3], + df[:, 1], + prim, + weight, + ) end -function calc_pressure(midpoint::AbstractMatrix,df::AbstractMatrix,weight::AbstractVector,::Global_Data{2}) - @views pressure_2D(midpoint[:,1],midpoint[:,2],df[:,1],weight) +function calc_pressure( + midpoint::AbstractMatrix, + df::AbstractMatrix, + weight::AbstractVector, + ::Global_Data{2}, +) + @views pressure_2D(midpoint[:, 1], midpoint[:, 2], df[:, 1], weight) end -function calc_pressure(midpoint::AbstractMatrix,df::AbstractMatrix,weight::AbstractVector,::Global_Data{3}) - @views pressure_3D(midpoint[:,1],midpoint[:,2],midpoint[:,3],df[:,1],weight) +function calc_pressure( + midpoint::AbstractMatrix, + df::AbstractMatrix, + weight::AbstractVector, + ::Global_Data{3}, +) + @views pressure_3D(midpoint[:, 1], midpoint[:, 2], midpoint[:, 3], df[:, 1], weight) end function calc_ρw( there_midpoint::AbstractMatrix, @@ -204,12 +243,20 @@ function calc_ρw( there_vn::AbstractVector, here_weight, there_weight, - ::KitAMR_Data{2,2} + ::KitAMR_Data{2,2}, ) - @inbounds @views SF = sum(@. here_weight * here_vn * here_df[:,1]) + @inbounds @views SF = sum(@. here_weight * here_vn * here_df[:, 1]) @inbounds @views SG = - prim[4] / π * - sum(@. there_weight * there_vn * exp(-prim[4] * ((there_midpoint[:,1] - prim[2])^2 + (there_midpoint[:,2] - prim[3])^2))) + prim[4] / π * sum( + @. there_weight * + there_vn * + exp( + -prim[4] * ( + (there_midpoint[:, 1] - prim[2])^2 + + (there_midpoint[:, 2] - prim[3])^2 + ), + ) + ) return -SF / SG end function calc_ρw( @@ -220,12 +267,21 @@ function calc_ρw( there_vn::AbstractVector, here_weight, there_weight, - ::KitAMR_Data{3,1} + ::KitAMR_Data{3,1}, ) - @inbounds @views SF = sum(@. here_weight * here_vn * here_df[:,1]) + @inbounds @views SF = sum(@. here_weight * here_vn * here_df[:, 1]) @inbounds @views SG = - (prim[5] / π)^(3/2) * - sum(@. there_weight * there_vn * exp(-prim[5] * ((there_midpoint[:,1] - prim[2])^2 + (there_midpoint[:,2] - prim[3])^2+(there_midpoint[:,3] - prim[4])^2))) + (prim[5] / π)^(3/2) * sum( + @. there_weight * + there_vn * + exp( + -prim[5] * ( + (there_midpoint[:, 1] - prim[2])^2 + + (there_midpoint[:, 2] - prim[3])^2 + + (there_midpoint[:, 3] - prim[4])^2 + ), + ) + ) return -SF / SG end function calc_ρw( @@ -286,24 +342,24 @@ function calc_fwb(vs_data::VS_Data{3,1}, F::AbstractMatrix, vn::AbstractVector) end function calc_w0(ps_data::AbstractPsData{2,2}) - vs_data = ps_data.vs_data - @inbounds micro_to_macro_2D2F( - @view(vs_data.midpoint[:,1]), - @view(vs_data.midpoint[:,2]), - @view(vs_data.df[:,1]), - @view(vs_data.df[:,2]), - vs_data.weight - ) + vs_data = ps_data.vs_data + @inbounds micro_to_macro_2D2F( + @view(vs_data.midpoint[:, 1]), + @view(vs_data.midpoint[:, 2]), + @view(vs_data.df[:, 1]), + @view(vs_data.df[:, 2]), + vs_data.weight, + ) end function calc_w0(ps_data::AbstractPsData{3,1}) - vs_data = ps_data.vs_data - @inbounds @views micro_to_macro_3D1F( - vs_data.midpoint[:,1], - vs_data.midpoint[:,2], - vs_data.midpoint[:,3], - vs_data.df[:,1], - vs_data.weight - ) + vs_data = ps_data.vs_data + @inbounds @views micro_to_macro_3D1F( + vs_data.midpoint[:, 1], + vs_data.midpoint[:, 2], + vs_data.midpoint[:, 3], + vs_data.df[:, 1], + vs_data.weight, + ) end function calc_a( @@ -423,7 +479,7 @@ function calc_A( micro_slope(sw, prim, global_data) end -function calc_flux_f0_2D2F(prim,Mt,Mu,Mv,Mξ,a,A) +function calc_flux_f0_2D2F(prim, Mt, Mu, Mv, Mξ, a, A) Mau_0 = moment_uv_2D2F(Mu, Mv, Mξ, 1, 0, 0) Mau2 = moment_au_2D2F(a, Mu, Mv, Mξ, 2, 0) Mau_T = moment_au_2D2F(A, Mu, Mv, Mξ, 1, 0) @@ -465,7 +521,19 @@ function calc_flux_g0_3D1F(prim, Mt, Mu, Mv, Mw, Mu_L, Mu_R, aL, aR, A, dir) end -function calc_flux_f0_2D2F(u::AbstractVector{T}, v, h, b, sh, sb, weight, H⁺, B⁺, vn, Mt) where {T} +function calc_flux_f0_2D2F( + u::AbstractVector{T}, + v, + h, + b, + sh, + sb, + weight, + H⁺, + B⁺, + vn, + Mt, +) where {T} F = Vector{T}(undef, 4) @inbounds begin F[1] = @@ -518,11 +586,31 @@ function calc_flux_f0_3D1F(u::AbstractVector{T}, v, w, f, sf, weight, F⁺, vn, end -function calc_unified_ft(midpoint::AbstractMatrix,df::AbstractMatrix,sdf::AbstractMatrix,F::AbstractMatrix,F⁺::AbstractMatrix,ax,at,Mξ,Mt,dir,::Global_Data{2,2}) - f = similar(df);vn = @views midpoint[:,dir] - u = @views midpoint[:,1];v = @views midpoint[:,2];h = @views df[:,1];b = @views df[:,2] - sh = @views sdf[:,1]; sb = @views sdf[:,2] - H0 = @views F[:,1]; B0 = @views F[:,2]; H⁺ = @views F⁺[:,1]; B⁺ = @views F⁺[:,2] +function calc_unified_ft( + midpoint::AbstractMatrix, + df::AbstractMatrix, + sdf::AbstractMatrix, + F::AbstractMatrix, + F⁺::AbstractMatrix, + ax, + at, + Mξ, + Mt, + dir, + ::Global_Data{2,2}, +) + f = similar(df); + vn = @views midpoint[:, dir] + u = @views midpoint[:, 1]; + v = @views midpoint[:, 2]; + h = @views df[:, 1]; + b = @views df[:, 2] + sh = @views sdf[:, 1]; + sb = @views sdf[:, 2] + H0 = @views F[:, 1]; + B0 = @views F[:, 2]; + H⁺ = @views F⁺[:, 1]; + B⁺ = @views F⁺[:, 2] @inbounds begin @. f[:, 1] = Mt[1] * (H0 + H⁺) + @@ -533,9 +621,8 @@ function calc_unified_ft(midpoint::AbstractMatrix,df::AbstractMatrix,sdf::Abstra ax[2] * u * H0 + ax[3] * v * H0 + 0.5 * ax[4] * ((u^2 + v^2) * H0 + B0) - )+ - Mt[3] * - ( + ) + + Mt[3] * ( at[1] * H0 + at[2] * u * H0 + at[3] * v * H0 + @@ -543,7 +630,7 @@ function calc_unified_ft(midpoint::AbstractMatrix,df::AbstractMatrix,sdf::Abstra ) + Mt[4] * h - Mt[5] * vn * sh @. f[:, 2] = - Mt[1] * (B0 + B⁺) + + Mt[1] * (B0 + B⁺) + Mt[2] * vn * ( @@ -552,8 +639,7 @@ function calc_unified_ft(midpoint::AbstractMatrix,df::AbstractMatrix,sdf::Abstra ax[3] * v * B0 + 0.5 * ax[4] * ((u^2 + v^2) * B0 + Mξ[3] * H0) ) + - Mt[3] * - ( + Mt[3] * ( at[1] * B0 + at[2] * u * B0 + at[3] * v * B0 + @@ -702,9 +788,31 @@ function calc_micro_flux_3D1F( return micro_flux .* ds end -function micro_to_macro(df::AbstractMatrix,midpoint::AbstractMatrix,weight::AbstractVector,::AbstractVsData{2,2}) - @inbounds @views micro_to_macro_2D2F(midpoint[:,1],midpoint[:,2],df[:,1],df[:,2],weight) +function micro_to_macro( + df::AbstractMatrix, + midpoint::AbstractMatrix, + weight::AbstractVector, + ::AbstractVsData{2,2}, +) + @inbounds @views micro_to_macro_2D2F( + midpoint[:, 1], + midpoint[:, 2], + df[:, 1], + df[:, 2], + weight, + ) end -function micro_to_macro(df::AbstractMatrix,midpoint::AbstractMatrix,weight::AbstractVector,::AbstractVsData{3,1}) - @inbounds @views micro_to_macro_3D1F(midpoint[:,1],midpoint[:,2],midpoint[:,3],df[:,1],weight) -end \ No newline at end of file +function micro_to_macro( + df::AbstractMatrix, + midpoint::AbstractMatrix, + weight::AbstractVector, + ::AbstractVsData{3,1}, +) + @inbounds @views micro_to_macro_3D1F( + midpoint[:, 1], + midpoint[:, 2], + midpoint[:, 3], + df[:, 1], + weight, + ) +end diff --git a/src/Theory/Theory.jl b/src/Theory/Theory.jl index f842c93..d4abcdc 100644 --- a/src/Theory/Theory.jl +++ b/src/Theory/Theory.jl @@ -2,4 +2,4 @@ include("Iterate.jl") include("Math.jl") export iterate! -export get_prim, get_conserved, calc_w0, calc_qf, discrete_maxwell, shakhov_part \ No newline at end of file +export get_prim, get_conserved, calc_w0, calc_qf, discrete_maxwell, shakhov_part diff --git a/src/Velocity_space/AMR.jl b/src/Velocity_space/AMR.jl index edf5b9c..6c34873 100644 --- a/src/Velocity_space/AMR.jl +++ b/src/Velocity_space/AMR.jl @@ -1,16 +1,21 @@ -function pre_vs_refine!(trees::PS_Trees{DIM,NDF}, global_data::Global_Data{DIM,NDF}) where{DIM,NDF} - vr = vs_resolution(trees,global_data) - !isa(global_data.config.quadrature,Vector)&&return nothing - ds = [(global_data.config.quadrature[2*i] - global_data.config.quadrature[2*i-1]) / - global_data.config.vs_trees_num[i] for i in 1:DIM] +function pre_vs_refine!( + trees::PS_Trees{DIM,NDF}, + global_data::Global_Data{DIM,NDF}, +) where {DIM,NDF} + vr = vs_resolution(trees, global_data) + !isa(global_data.config.quadrature, Vector)&&return nothing + ds = [ + (global_data.config.quadrature[2*i] - global_data.config.quadrature[2*i-1]) / + global_data.config.vs_trees_num[i] for i = 1:DIM + ] vs_refine_udf = global_data.config.user_defined.static_vs_refine_flag for _ = 1:global_data.config.solver.AMR_VS_MAXLEVEL for i in eachindex(trees.data) for j in eachindex(trees.data[i]) ps_data = trees.data[i][j] - isa(ps_data,InsideSolidData) && continue + isa(ps_data, InsideSolidData) && continue vs_data = ps_data.vs_data - U = ps_data.prim[2:1+DIM] + U = ps_data.prim[2:(1+DIM)] lnmidpoint = reshape(vs_data.midpoint, :) lndf = reshape(vs_data.df, :) lnsdf = reshape(vs_data.sdf, :) @@ -27,16 +32,29 @@ function pre_vs_refine!(trees::PS_Trees{DIM,NDF}, global_data::Global_Data{DIM,N end midpoint = @view(lnmidpoint[midpoint_index]) df = @view(lndf[df_index]) - if vs_data.level[index] < global_data.config.solver.AMR_VS_MAXLEVEL && - ( vs_refine_udf==null_udf ? - contribution_refine_flag(ps_data.w, U, midpoint, df, vs_data.weight[index], vr, global_data) : - vs_refine_udf(midpoint;level = vs_data.level[index],du = ds./2^vs_data.level[index]) + if vs_data.level[index] < global_data.config.solver.AMR_VS_MAXLEVEL && ( + vs_refine_udf==null_udf ? + contribution_refine_flag( + ps_data.w, + U, + midpoint, + df, + vs_data.weight[index], + vr, + global_data, + ) : + vs_refine_udf( + midpoint; + level = vs_data.level[index], + du = ds ./ 2^vs_data.level[index], ) - midpoint_new = midpoint_refine(DIM,midpoint, vs_data.level[index], ds) - df_new = df_refine(DIM,midpoint, midpoint_new, df) + ) + midpoint_new = + midpoint_refine(DIM, midpoint, vs_data.level[index], ds) + df_new = df_refine(DIM, midpoint, midpoint_new, df) vs_data.vs_num += 2^DIM - 1 - level_refine_replace!(DIM,vs_data.level, index) - weight_refine_replace!(DIM,vs_data.weight, index) + level_refine_replace!(DIM, vs_data.level, index) + weight_refine_replace!(DIM, vs_data.weight, index) midpoint_refine_replace!( DIM, lnmidpoint, @@ -44,9 +62,9 @@ function pre_vs_refine!(trees::PS_Trees{DIM,NDF}, global_data::Global_Data{DIM,N vs_data.vs_num, index, ) - df_refine_replace!(DIM,NDF,lndf, df_new, vs_data.vs_num, index) - sdf_refine_replace!(DIM,NDF,lnsdf) - flux_refine_replace!(DIM,NDF,lnflux) + df_refine_replace!(DIM, NDF, lndf, df_new, vs_data.vs_num, index) + sdf_refine_replace!(DIM, NDF, lnsdf) + flux_refine_replace!(DIM, NDF, lnflux) index += 2^DIM - 1 end index += 1 @@ -60,17 +78,19 @@ function pre_vs_refine!(trees::PS_Trees{DIM,NDF}, global_data::Global_Data{DIM,N end return nothing end -function criterion_df(ps_data::AbstractPsData{DIM,NDF}) where{DIM,NDF} - vs_data = ps_data.vs_data;df = vs_data.df;sdf = vs_data.sdf +function criterion_df(ps_data::AbstractPsData{DIM,NDF}) where {DIM,NDF} + vs_data = ps_data.vs_data; + df = vs_data.df; + sdf = vs_data.sdf ds = ps_data.ds cdf = similar(vs_data.df) ddfi = zeros(DIM) - for j in axes(cdf,2) - for i in axes(cdf,1) - for k in 1:DIM - ddfi[k] = abs(sdf[i,j,k]*ds[k]) + for j in axes(cdf, 2) + for i in axes(cdf, 1) + for k = 1:DIM + ddfi[k] = abs(sdf[i, j, k]*ds[k]) end - cdf[i,j] = df[i,j]+maximum(ddfi) + cdf[i, j] = df[i, j]+maximum(ddfi) end end return cdf @@ -79,24 +99,30 @@ end """ $(TYPEDSIGNATURES) """ -function vs_refine!(va_data::Velocity_Adaptive_Data, amr::KitAMR_Data{DIM,NDF}) where{DIM,NDF} - trees = amr.field.trees;global_data = amr.global_data - !isa(global_data.config.quadrature,Vector)&&return nothing - ds = [(global_data.config.quadrature[2*i] - global_data.config.quadrature[2*i-1]) / - global_data.config.vs_trees_num[i] for i in 1:DIM] +function vs_refine!( + va_data::Velocity_Adaptive_Data, + amr::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} + trees = amr.field.trees; + global_data = amr.global_data + !isa(global_data.config.quadrature, Vector)&&return nothing + ds = [ + (global_data.config.quadrature[2*i] - global_data.config.quadrature[2*i-1]) / + global_data.config.vs_trees_num[i] for i = 1:DIM + ] va_flags = va_data.va_flags id = 0 for i in eachindex(trees.data) for j in eachindex(trees.data[i]) id += 1 ps_data = trees.data[i][j] - isa(ps_data,InsideSolidData) && continue + isa(ps_data, InsideSolidData) && continue cdf = criterion_df(ps_data) vs_data = ps_data.vs_data - U = ps_data.prim[2:1+DIM] + U = ps_data.prim[2:(1+DIM)] lnmidpoint = reshape(vs_data.midpoint, :) lndf = reshape(vs_data.df, :) - lncdf = reshape(cdf,:) + lncdf = reshape(cdf, :) lnsdf = reshape(vs_data.sdf, :) lnflux = reshape(vs_data.flux, :) index = 1 @@ -110,15 +136,24 @@ function vs_refine!(va_data::Velocity_Adaptive_Data, amr::KitAMR_Data{DIM,NDF}) df_index[i] = (i - 1) * (vs_data.vs_num) + index end midpoint = @view(lnmidpoint[midpoint_index]) - df = @view(lndf[df_index]);cdf = @view(lncdf[df_index]) + df = @view(lndf[df_index]); + cdf = @view(lncdf[df_index]) if vs_data.level[index] < global_data.config.solver.AMR_VS_MAXLEVEL && - contribution_refine_flag(ps_data.w, U, midpoint, cdf, vs_data.weight[index], va_data.vr,global_data) - midpoint_new = midpoint_refine(DIM,midpoint, vs_data.level[index], ds) - df_new = df_refine(DIM,midpoint, midpoint_new, df) - cdf_new = df_refine(DIM,midpoint,midpoint_new,df) + contribution_refine_flag( + ps_data.w, + U, + midpoint, + cdf, + vs_data.weight[index], + va_data.vr, + global_data, + ) + midpoint_new = midpoint_refine(DIM, midpoint, vs_data.level[index], ds) + df_new = df_refine(DIM, midpoint, midpoint_new, df) + cdf_new = df_refine(DIM, midpoint, midpoint_new, df) vs_data.vs_num += 2^DIM - 1 - level_refine_replace!(DIM,vs_data.level, index) - weight_refine_replace!(DIM,vs_data.weight, index) + level_refine_replace!(DIM, vs_data.level, index) + weight_refine_replace!(DIM, vs_data.weight, index) midpoint_refine_replace!( DIM, lnmidpoint, @@ -126,10 +161,10 @@ function vs_refine!(va_data::Velocity_Adaptive_Data, amr::KitAMR_Data{DIM,NDF}) vs_data.vs_num, index, ) - df_refine_replace!(DIM,NDF,lndf, df_new, vs_data.vs_num, index) - df_refine_replace!(DIM,NDF,lncdf,cdf_new,vs_data.vs_num,index) - sdf_refine_replace!(DIM,NDF,lnsdf) - flux_refine_replace!(DIM,NDF,lnflux) + df_refine_replace!(DIM, NDF, lndf, df_new, vs_data.vs_num, index) + df_refine_replace!(DIM, NDF, lncdf, cdf_new, vs_data.vs_num, index) + sdf_refine_replace!(DIM, NDF, lnsdf) + flux_refine_replace!(DIM, NDF, lnflux) index += 2^DIM - 1 !va_flags[id]&&(va_flags[id] = true) end @@ -146,10 +181,16 @@ end """ $(SIGNATURES) """ -function midpoint_refine_replace!(DIM::Integer,lnmidpoint::AbstractVector, midpoint_new::AbstractMatrix, vs_num::Int, index::Int) +function midpoint_refine_replace!( + DIM::Integer, + lnmidpoint::AbstractVector, + midpoint_new::AbstractMatrix, + vs_num::Int, + index::Int, +) for i = 1:DIM deleteat!(lnmidpoint, (i - 1) * (vs_num) + index) - for j = 2^DIM:-1:1 + for j = (2^DIM):-1:1 insert!(lnmidpoint, (i - 1) * (vs_num) + index, midpoint_new[j, i]) end end @@ -157,28 +198,35 @@ end """ $(SIGNATURES) """ -function weight_refine_replace!(DIM::Integer,weight::AbstractVector, index::Int) +function weight_refine_replace!(DIM::Integer, weight::AbstractVector, index::Int) weight_new = popat!(weight, index) / 2^DIM - for _ = 1:2^DIM + for _ = 1:(2^DIM) insert!(weight, index, weight_new) end end """ $(SIGNATURES) """ -function level_refine_replace!(DIM::Integer,level::AbstractVector, index::Int) +function level_refine_replace!(DIM::Integer, level::AbstractVector, index::Int) level_new = popat!(level, index) + 1 - for _ = 1:2^DIM + for _ = 1:(2^DIM) insert!(level, index, level_new) end end """ $(SIGNATURES) """ -function df_refine_replace!(DIM::Integer,NDF::Integer,lndf::AbstractVector, df_new::AbstractMatrix, vs_num::Int, index::Int) +function df_refine_replace!( + DIM::Integer, + NDF::Integer, + lndf::AbstractVector, + df_new::AbstractMatrix, + vs_num::Int, + index::Int, +) for i = 1:NDF deleteat!(lndf, (i - 1) * (vs_num) + index) - for j = 2^DIM:-1:1 + for j = (2^DIM):-1:1 insert!(lndf, (i - 1) * (vs_num) + index, df_new[j, i]) end end @@ -186,22 +234,27 @@ end """ $(SIGNATURES) """ -function sdf_refine_replace!(DIM::Integer,NDF::Integer,lnsdf::AbstractVector) +function sdf_refine_replace!(DIM::Integer, NDF::Integer, lnsdf::AbstractVector) append!(lnsdf, zeros((2^DIM - 1) * NDF * DIM)) end """ $(SIGNATURES) """ -function flux_refine_replace!(DIM::Integer,NDF::Integer,lnflux::AbstractVector) +function flux_refine_replace!(DIM::Integer, NDF::Integer, lnflux::AbstractVector) append!(lnflux, zeros((2^DIM - 1) * NDF)) end """ $(SIGNATURES) """ -function midpoint_refine(DIM::Integer,midpoint::AbstractVector, level::Int8, ds::AbstractVector) +function midpoint_refine( + DIM::Integer, + midpoint::AbstractVector, + level::Int8, + ds::AbstractVector, +) midpoint_new = Matrix{Float64}(undef, 2^DIM, DIM) ds_new = ds / 2^(level + 1) - for i = 1:2^DIM + for i = 1:(2^DIM) midpoint_new[i, :] .= @. midpoint + 0.5 * ds_new * RMT[DIM][i] end return midpoint_new @@ -209,14 +262,21 @@ end """ $(SIGNATURES) """ -df_refine(DIM::Integer,::AbstractVector, ::AbstractMatrix, df::AbstractVector) = ones(2^DIM) * df' +df_refine(DIM::Integer, ::AbstractVector, ::AbstractMatrix, df::AbstractVector) = + ones(2^DIM) * df' """ $(TYPEDSIGNATURES) """ -function vs_coarsen!(va_data::Velocity_Adaptive_Data,amr::KitAMR_Data{DIM,NDF})where{DIM,NDF} - trees = amr.field.trees;global_data = amr.global_data - ds = [(global_data.config.quadrature[2*i] - global_data.config.quadrature[2*i-1]) / - global_data.config.vs_trees_num[i] for i in 1:DIM] +function vs_coarsen!( + va_data::Velocity_Adaptive_Data, + amr::KitAMR_Data{DIM,NDF}, +) where {DIM,NDF} + trees = amr.field.trees; + global_data = amr.global_data + ds = [ + (global_data.config.quadrature[2*i] - global_data.config.quadrature[2*i-1]) / + global_data.config.vs_trees_num[i] for i = 1:DIM + ] va_flags = va_data.va_flags id = 0 flag = zeros(global_data.config.solver.AMR_VS_MAXLEVEL) @@ -224,49 +284,57 @@ function vs_coarsen!(va_data::Velocity_Adaptive_Data,amr::KitAMR_Data{DIM,NDF})w for j in eachindex(trees.data[i]) id += 1 ps_data = trees.data[i][j] - isa(ps_data,InsideSolidData) && continue + isa(ps_data, InsideSolidData) && continue cdf = criterion_df(ps_data) vs_data = ps_data.vs_data - U = ps_data.prim[2:1+DIM] + U = ps_data.prim[2:(1+DIM)] lnmidpoint = reshape(vs_data.midpoint, :) lndf = reshape(vs_data.df, :) - lncdf = reshape(cdf,:) + lncdf = reshape(cdf, :) lnsdf = reshape(vs_data.sdf, :) lnflux = reshape(vs_data.flux, :) - index = 1;flag.=0. + index = 1; + flag.=0.0 midpoint_index = Matrix{Int}(undef, 2^DIM, DIM) df_index = Matrix{Int}(undef, 2^DIM, NDF) while index < vs_data.vs_num + 1 first_level = vs_data.level[index] if first_level > 0 - if flag[first_level]%1==0. && - all(x -> x == first_level, @view(vs_data.level[index+1:index+2^DIM-1])) - for i in axes(midpoint_index,2) + if flag[first_level]%1==0.0 && all( + x -> x == first_level, + @view(vs_data.level[(index+1):(index+2^DIM-1)]) + ) + for i in axes(midpoint_index, 2) midpoint_index[:, i] .= - (i-1)*(vs_data.vs_num)+index:(i-1)*(vs_data.vs_num)+index+2^DIM-1 + ((i-1)*(vs_data.vs_num)+index):((i-1)*(vs_data.vs_num)+index+2^DIM-1) end - for i in axes(df_index,2) + for i in axes(df_index, 2) df_index[:, i] .= - (i-1)*(vs_data.vs_num)+index:(i-1)*(vs_data.vs_num)+index+2^DIM-1 + ((i-1)*(vs_data.vs_num)+index):((i-1)*(vs_data.vs_num)+index+2^DIM-1) end midpoint = @view(lnmidpoint[midpoint_index]) - df = @view(lndf[df_index]);cdf = @view(lncdf[df_index]) + df = @view(lndf[df_index]); + cdf = @view(lncdf[df_index]) if contribution_coarsen_flag( ps_data.w, U, midpoint, cdf, - @view(vs_data.weight[index:index+2^DIM-1]), + @view(vs_data.weight[index:(index+2^DIM-1)]), va_data.vr, - global_data + global_data, ) - midpoint_new = - midpoint_coarsen(DIM,@view(midpoint[1, :]), first_level, ds); - df_new = df_coarsen(DIM,NDF,df) - cdf_new = df_coarsen(DIM,NDF,cdf) + midpoint_new = midpoint_coarsen( + DIM, + @view(midpoint[1, :]), + first_level, + ds, + ); + df_new = df_coarsen(DIM, NDF, df) + cdf_new = df_coarsen(DIM, NDF, cdf) vs_data.vs_num -= 2^DIM - 1 - level_coarsen_replace!(DIM,vs_data.level, index) - weight_coarsen_replace!(DIM,vs_data.weight, index) + level_coarsen_replace!(DIM, vs_data.level, index) + weight_coarsen_replace!(DIM, vs_data.weight, index) midpoint_coarsen_replace!( DIM, lnmidpoint, @@ -274,16 +342,30 @@ function vs_coarsen!(va_data::Velocity_Adaptive_Data,amr::KitAMR_Data{DIM,NDF})w vs_data.vs_num, index, ) - df_coarsen_replace!(DIM,NDF,lndf, df_new, vs_data.vs_num, index) - df_coarsen_replace!(DIM,NDF,lncdf,cdf_new,vs_data.vs_num,index) - sdf_coarsen_replace!(DIM,NDF,lnsdf) - flux_coarsen_replace!(DIM,NDF,lnflux) + df_coarsen_replace!( + DIM, + NDF, + lndf, + df_new, + vs_data.vs_num, + index, + ) + df_coarsen_replace!( + DIM, + NDF, + lncdf, + cdf_new, + vs_data.vs_num, + index, + ) + sdf_coarsen_replace!(DIM, NDF, lnsdf) + flux_coarsen_replace!(DIM, NDF, lnflux) !va_flags[id]&&(va_flags[id] = true) else index += 2^DIM - 1 end if first_level > 1 - for i = 1:first_level-1 + for i = 1:(first_level-1) flag[i] += 1 / 2^(DIM * (first_level - i)) end end @@ -304,16 +386,21 @@ function vs_coarsen!(va_data::Velocity_Adaptive_Data,amr::KitAMR_Data{DIM,NDF})w return nothing end -function midpoint_coarsen(DIM::Integer,midpoint::AbstractVector, level::Int8, ds::AbstractVector) +function midpoint_coarsen( + DIM::Integer, + midpoint::AbstractVector, + level::Int8, + ds::AbstractVector, +) ds_new = ds / 2^level @. midpoint - 0.5 * ds_new * RMT[DIM][1] end """ $(SIGNATURES) """ -function df_coarsen(DIM::Integer,NDF::Integer,df::AbstractMatrix) +function df_coarsen(DIM::Integer, NDF::Integer, df::AbstractMatrix) df_new = zeros(NDF) - for i = 1:2^DIM + for i = 1:(2^DIM) df_new += @view(df[i, :]) end df_new /= 2^DIM @@ -324,8 +411,8 @@ end """ $(SIGNATURES) """ -function level_coarsen_replace!(DIM::Integer,level::AbstractVector, index::Int) - for _ = 1:2^DIM-1 +function level_coarsen_replace!(DIM::Integer, level::AbstractVector, index::Int) + for _ = 1:(2^DIM-1) deleteat!(level, index) end level[index] -= 1 @@ -333,8 +420,8 @@ end """ $(SIGNATURES) """ -function weight_coarsen_replace!(DIM::Integer,weight::AbstractVector, index::Int) - for _ = 1:2^DIM-1 +function weight_coarsen_replace!(DIM::Integer, weight::AbstractVector, index::Int) + for _ = 1:(2^DIM-1) deleteat!(weight, index) end weight[index] *= 2^DIM @@ -349,8 +436,8 @@ function midpoint_coarsen_replace!( vs_num::Int, index::Int, ) -for i = 1:DIM - for _ = 1:2^DIM-1 + for i = 1:DIM + for _ = 1:(2^DIM-1) deleteat!(lnmidpoint, (i - 1) * (vs_num) + index) end lnmidpoint[(i-1)*(vs_num)+index] = midpoint_new[i] @@ -359,9 +446,16 @@ end """ $(SIGNATURES) """ -function df_coarsen_replace!(DIM::Integer,NDF::Integer,lndf::AbstractVector, df_new::AbstractVector, vs_num::Int, index::Int) +function df_coarsen_replace!( + DIM::Integer, + NDF::Integer, + lndf::AbstractVector, + df_new::AbstractVector, + vs_num::Int, + index::Int, +) for i = 1:NDF - for _ = 1:2^DIM-1 + for _ = 1:(2^DIM-1) deleteat!(lndf, (i - 1) * (vs_num) + index) end lndf[(i-1)*(vs_num)+index] = df_new[i] @@ -370,33 +464,34 @@ end """ $(SIGNATURES) """ -function sdf_coarsen_replace!(DIM::Integer,NDF::Integer,lnsdf::AbstractVector) - deleteat!(lnsdf, 1:(2^DIM-1)*NDF*DIM) +function sdf_coarsen_replace!(DIM::Integer, NDF::Integer, lnsdf::AbstractVector) + deleteat!(lnsdf, 1:((2^DIM-1)*NDF*DIM)) end """ $(SIGNATURES) """ -function flux_coarsen_replace!(DIM::Integer,NDF::Integer,lnflux::AbstractVector) - deleteat!(lnflux, 1:(2^DIM-1)*NDF) +function flux_coarsen_replace!(DIM::Integer, NDF::Integer, lnflux::AbstractVector) + deleteat!(lnflux, 1:((2^DIM-1)*NDF)) end """ $(TYPEDSIGNATURES) """ -function vs_conserved_correction!(va_data::Velocity_Adaptive_Data,amr) +function vs_conserved_correction!(va_data::Velocity_Adaptive_Data, amr) trees = amr.field.trees global_data = amr.global_data va_flags = va_data.va_flags id = 0 @inbounds for i in eachindex(trees.data) for j in eachindex(trees.data[i]) - id+=1;!va_flags[id]&&continue + id+=1; + !va_flags[id]&&continue ps_data = trees.data[i][j] - (isa(ps_data,InsideSolidData)||ps_data.bound_enc<0)&&continue + (isa(ps_data, InsideSolidData)||ps_data.bound_enc<0)&&continue vs_data = ps_data.vs_data F_c = discrete_maxwell(vs_data.midpoint, ps_data.prim, global_data) w = calc_w0(ps_data) - prim = get_prim(w,global_data) + prim = get_prim(w, global_data) F = discrete_maxwell(vs_data.midpoint, prim, global_data) vs_data.df .+= F_c-F end @@ -405,33 +500,40 @@ end function vs_resolution(amr) trees = amr.field.trees - vs_resolution(trees,amr.global_data) + vs_resolution(trees, amr.global_data) end -function vs_resolution(trees::PS_Trees,global_data) - density_res = 0.;energy_res = 0. +function vs_resolution(trees::PS_Trees, global_data) + density_res = 0.0; + energy_res = 0.0 @inbounds for tree in trees.data for ps_data in tree - (isa(ps_data,InsideSolidData)||ps_data.bound_enc<0)&&continue - density_res_i,energy_res_i = vs_resolution(ps_data,global_data) - density_res = max(density_res_i,density_res) - energy_res = max(energy_res_i,energy_res) + (isa(ps_data, InsideSolidData)||ps_data.bound_enc<0)&&continue + density_res_i, energy_res_i = vs_resolution(ps_data, global_data) + density_res = max(density_res_i, density_res) + energy_res = max(energy_res_i, energy_res) end end - density_res = MPI.Allreduce(density_res, (x,y)->max(x,y), MPI.COMM_WORLD) - energy_res = MPI.Allreduce(energy_res, (x,y)->max(x,y), MPI.COMM_WORLD) - return Velocity_Resolution(density_res,energy_res) + density_res = MPI.Allreduce(density_res, (x, y)->max(x, y), MPI.COMM_WORLD) + energy_res = MPI.Allreduce(energy_res, (x, y)->max(x, y), MPI.COMM_WORLD) + return Velocity_Resolution(density_res, energy_res) end -function vs_resolution(ps_data::PS_Data{DIM,NDF},global_data) where{DIM,NDF} +function vs_resolution(ps_data::PS_Data{DIM,NDF}, global_data) where {DIM,NDF} vs_data = ps_data.vs_data - U = ps_data.prim[2:DIM+1] + U = ps_data.prim[2:(DIM+1)] density_max = maximum(vs_data.df) - c2 = @views [sum((U-u).^2) for u in eachrow(vs_data.midpoint)] - energy_max = NDF==1 ? 0.5*maximum(vs_data.df.*c2) : 0.5*maximum(@view(vs_data.df[:,1]).*c2+@view(vs_data.df[:,2])) + c2 = @views [sum((U-u) .^ 2) for u in eachrow(vs_data.midpoint)] + energy_max = + NDF==1 ? 0.5*maximum(vs_data.df .* c2) : + 0.5*maximum(@view(vs_data.df[:, 1]) .* c2+@view(vs_data.df[:, 2])) vs_trees_num = global_data.config.vs_trees_num quadrature = global_data.config.quadrature - du = [quadrature[2*i]-quadrature[2*i-1] for i in 1:DIM] - weight = reduce(*,du)/reduce(*,vs_trees_num)/2^(DIM*(global_data.config.solver.AMR_VS_MAXLEVEL)) - return density_max*weight,energy_max*weight + du = [quadrature[2*i]-quadrature[2*i-1] for i = 1:DIM] + weight = + reduce( + *, + du, + )/reduce(*, vs_trees_num)/2^(DIM*(global_data.config.solver.AMR_VS_MAXLEVEL)) + return density_max*weight, energy_max*weight end """ $(TYPEDSIGNATURES) @@ -439,9 +541,9 @@ $(TYPEDSIGNATURES) function vs_adaptive_mesh_refinement!(amr) vr = vs_resolution(amr) fp = PointerWrapper(amr.global_data.forest.p4est) - va_flags = zeros(Bool,fp.local_num_quadrants[]) - va_data = Velocity_Adaptive_Data(vr,va_flags) - vs_refine!(va_data,amr) - vs_coarsen!(va_data,amr) - vs_conserved_correction!(va_data,amr) -end \ No newline at end of file + va_flags = zeros(Bool, fp.local_num_quadrants[]) + va_data = Velocity_Adaptive_Data(vr, va_flags) + vs_refine!(va_data, amr) + vs_coarsen!(va_data, amr) + vs_conserved_correction!(va_data, amr) +end diff --git a/src/Velocity_space/Criteria.jl b/src/Velocity_space/Criteria.jl index a970320..4878185 100644 --- a/src/Velocity_space/Criteria.jl +++ b/src/Velocity_space/Criteria.jl @@ -1,75 +1,231 @@ """ $(TYPEDSIGNATURES) """ -function contribution_refine_flag(w::AbstractVector, U::AbstractVector, midpoint::AbstractVector, df::AbstractVector, weight::Float64, vr::Velocity_Resolution, global_data::Global_Data) - return local_contribution_refine_flag(w,U,midpoint,df,weight,global_data)||global_contribution_refine_flag(U,midpoint,df,weight,vr,global_data) +function contribution_refine_flag( + w::AbstractVector, + U::AbstractVector, + midpoint::AbstractVector, + df::AbstractVector, + weight::Float64, + vr::Velocity_Resolution, + global_data::Global_Data, +) + return local_contribution_refine_flag( + w, + U, + midpoint, + df, + weight, + global_data, + )||global_contribution_refine_flag(U, midpoint, df, weight, vr, global_data) end """ $(TYPEDSIGNATURES) """ -function contribution_coarsen_flag(w::AbstractVector, U::AbstractVector, midpoint::AbstractMatrix, df::AbstractMatrix, weight::AbstractVector, vr::Velocity_Resolution, global_data::Global_Data) - return local_contribution_coarsen_flag(w,U,midpoint,df,weight,global_data)&&global_contribution_coarsen_flag(U,midpoint,df,weight,vr,global_data) +function contribution_coarsen_flag( + w::AbstractVector, + U::AbstractVector, + midpoint::AbstractMatrix, + df::AbstractMatrix, + weight::AbstractVector, + vr::Velocity_Resolution, + global_data::Global_Data, +) + return local_contribution_coarsen_flag( + w, + U, + midpoint, + df, + weight, + global_data, + )&&global_contribution_coarsen_flag(U, midpoint, df, weight, vr, global_data) end -function local_contribution_refine_flag(w::AbstractVector, U::AbstractVector, midpoint::AbstractVector, df::AbstractVector, weight::Float64, ::Global_Data{DIM,2}) where{DIM} - max(abs(0.5 * (sum((U - midpoint) .^ 2) * df[1] + df[2])* weight) / - (w[end] - 0.5 * w[1] * sum((U) .^ 2)),df[1]*weight/w[1]) > 1e-2 ? true : false +function local_contribution_refine_flag( + w::AbstractVector, + U::AbstractVector, + midpoint::AbstractVector, + df::AbstractVector, + weight::Float64, + ::Global_Data{DIM,2}, +) where {DIM} + max( + abs(0.5 * (sum((U - midpoint) .^ 2) * df[1] + df[2]) * weight) / + (w[end] - 0.5 * w[1] * sum((U) .^ 2)), + df[1]*weight/w[1], + ) > 1e-2 ? true : false end -function local_contribution_refine_flag(w::AbstractVector, U::AbstractVector, midpoint::AbstractVector, df::AbstractVector, weight::Float64, ::Global_Data{DIM,1}) where{DIM} - max(abs(0.5 * sum((U - midpoint) .^ 2) * df[1]* weight) / - (w[end] - 0.5 * w[1] * sum((U) .^ 2)),df[1]*weight/w[1]) > 1e-2 ? true : false +function local_contribution_refine_flag( + w::AbstractVector, + U::AbstractVector, + midpoint::AbstractVector, + df::AbstractVector, + weight::Float64, + ::Global_Data{DIM,1}, +) where {DIM} + max( + abs(0.5 * sum((U - midpoint) .^ 2) * df[1] * weight) / + (w[end] - 0.5 * w[1] * sum((U) .^ 2)), + df[1]*weight/w[1], + ) > 1e-2 ? true : false end -function global_contribution_refine_flag(U::AbstractVector, midpoint::AbstractVector, df::AbstractVector, weight::Float64, vr::Velocity_Resolution, ::Global_Data{DIM,2}) where{DIM} - df[1]*weight > ADAPT_COEFFI_VS*vr.density || 0.5 * (sum((U - midpoint) .^ 2) * df[1] + df[2])* weight>vr.energy*ADAPT_COEFFI_VS +function global_contribution_refine_flag( + U::AbstractVector, + midpoint::AbstractVector, + df::AbstractVector, + weight::Float64, + vr::Velocity_Resolution, + ::Global_Data{DIM,2}, +) where {DIM} + df[1]*weight > ADAPT_COEFFI_VS*vr.density || + 0.5 * (sum((U - midpoint) .^ 2) * df[1] + df[2]) * weight>vr.energy*ADAPT_COEFFI_VS end -function global_contribution_refine_flag(U::AbstractVector, midpoint::AbstractVector, df::AbstractVector, weight::Float64, vr::Velocity_Resolution, ::Global_Data{DIM,1}) where{DIM} - df[1]*weight > vr.density*ADAPT_COEFFI_VS || 0.5 * (sum((U - midpoint) .^ 2) * df[1])* weight>vr.energy*ADAPT_COEFFI_VS +function global_contribution_refine_flag( + U::AbstractVector, + midpoint::AbstractVector, + df::AbstractVector, + weight::Float64, + vr::Velocity_Resolution, + ::Global_Data{DIM,1}, +) where {DIM} + df[1]*weight > vr.density*ADAPT_COEFFI_VS || + 0.5 * (sum((U - midpoint) .^ 2) * df[1]) * weight>vr.energy*ADAPT_COEFFI_VS end -function local_contribution_coarsen_flag(w::AbstractVector, U::AbstractVector, midpoint::AbstractMatrix, df::AbstractMatrix, weight::AbstractVector, global_data::Global_Data{DIM,2}) where{DIM} - for i = 1:2^DIM - !local_contribution_coarsen_flag(w, U, @view(midpoint[i, :]), @view(df[i, :]), weight[i], global_data) && - return false +function local_contribution_coarsen_flag( + w::AbstractVector, + U::AbstractVector, + midpoint::AbstractMatrix, + df::AbstractMatrix, + weight::AbstractVector, + global_data::Global_Data{DIM,2}, +) where {DIM} + for i = 1:(2^DIM) + !local_contribution_coarsen_flag( + w, + U, + @view(midpoint[i, :]), + @view(df[i, :]), + weight[i], + global_data, + ) && return false end return true end -function local_contribution_coarsen_flag(w::AbstractVector, U::AbstractVector, midpoint::AbstractMatrix, df::AbstractMatrix, weight::AbstractVector, global_data::Global_Data{DIM,1}) where{DIM} - for i = 1:2^DIM - !local_contribution_coarsen_flag(w, U, @view(midpoint[i, :]), @view(df[i, :]), weight[i], global_data) && - return false +function local_contribution_coarsen_flag( + w::AbstractVector, + U::AbstractVector, + midpoint::AbstractMatrix, + df::AbstractMatrix, + weight::AbstractVector, + global_data::Global_Data{DIM,1}, +) where {DIM} + for i = 1:(2^DIM) + !local_contribution_coarsen_flag( + w, + U, + @view(midpoint[i, :]), + @view(df[i, :]), + weight[i], + global_data, + ) && return false end return true end -function local_contribution_coarsen_flag(w::AbstractVector, U::AbstractVector, midpoint::AbstractVector, df::AbstractVector, weight::Float64, ::Global_Data{DIM,2}) where{DIM} - max(0.5 * (sum((U - midpoint) .^ 2) * df[1] + df[2])* weight / - (w[end] - 0.5 * w[1] * sum((U) .^ 2)),df[1]*weight/w[1]) < 1e-2/ 2^DIM +function local_contribution_coarsen_flag( + w::AbstractVector, + U::AbstractVector, + midpoint::AbstractVector, + df::AbstractVector, + weight::Float64, + ::Global_Data{DIM,2}, +) where {DIM} + max( + 0.5 * (sum((U - midpoint) .^ 2) * df[1] + df[2]) * weight / + (w[end] - 0.5 * w[1] * sum((U) .^ 2)), + df[1]*weight/w[1], + ) < 1e-2 / 2^DIM end -function local_contribution_coarsen_flag(w::AbstractVector, U::AbstractVector, midpoint::AbstractVector, df::AbstractVector, weight::Float64, ::Global_Data{DIM,1}) where{DIM} - max(0.5 * (sum((U - midpoint) .^ 2) * df[1])* weight / - (w[end] - 0.5 * w[1] * sum((U) .^ 2)),df[1]*weight/w[1]) < 1e-2/ 2^DIM +function local_contribution_coarsen_flag( + w::AbstractVector, + U::AbstractVector, + midpoint::AbstractVector, + df::AbstractVector, + weight::Float64, + ::Global_Data{DIM,1}, +) where {DIM} + max( + 0.5 * (sum((U - midpoint) .^ 2) * df[1]) * weight / + (w[end] - 0.5 * w[1] * sum((U) .^ 2)), + df[1]*weight/w[1], + ) < 1e-2 / 2^DIM end -function global_contribution_coarsen_flag(U::AbstractVector, midpoint::AbstractMatrix, df::AbstractMatrix, weight::AbstractVector, vr::Velocity_Resolution, global_data::Global_Data{DIM,2}) where{DIM} - for i = 1:2^DIM - !global_contribution_coarsen_flag(U, @view(midpoint[i, :]), @view(df[i, :]), weight[i], vr, global_data) && - return false +function global_contribution_coarsen_flag( + U::AbstractVector, + midpoint::AbstractMatrix, + df::AbstractMatrix, + weight::AbstractVector, + vr::Velocity_Resolution, + global_data::Global_Data{DIM,2}, +) where {DIM} + for i = 1:(2^DIM) + !global_contribution_coarsen_flag( + U, + @view(midpoint[i, :]), + @view(df[i, :]), + weight[i], + vr, + global_data, + ) && return false end return true end -function global_contribution_coarsen_flag(U::AbstractVector, midpoint::AbstractMatrix, df::AbstractMatrix, weight::AbstractVector, vr::Velocity_Resolution, global_data::Global_Data{DIM,1}) where{DIM} - for i = 1:2^DIM - !global_contribution_coarsen_flag(U, @view(midpoint[i, :]), @view(df[i, :]), weight[i], vr, global_data) && - return false +function global_contribution_coarsen_flag( + U::AbstractVector, + midpoint::AbstractMatrix, + df::AbstractMatrix, + weight::AbstractVector, + vr::Velocity_Resolution, + global_data::Global_Data{DIM,1}, +) where {DIM} + for i = 1:(2^DIM) + !global_contribution_coarsen_flag( + U, + @view(midpoint[i, :]), + @view(df[i, :]), + weight[i], + vr, + global_data, + ) && return false end return true end -function global_contribution_coarsen_flag(U::AbstractVector, midpoint::AbstractVector, df::AbstractVector, weight::Float64, vr::Velocity_Resolution, ::Global_Data{DIM,2}) where{DIM} - df[1]*weight < ADAPT_COEFFI_VS*vr.density/2^DIM && 0.5 * (sum((U - midpoint) .^ 2) * df[1] + df[2])* weightymin - push!(points,[xmin,y]) - push!(indices,8) + push!(points, [xmin, y]) + push!(indices, 8) i+=1 end y = -n[1]/n[2]*xmax if yymin - push!(points,[xmax,y]) - push!(indices,4) + push!(points, [xmax, y]) + push!(indices, 4) i+=1 end x = -n[2]/n[1]*ymin if xxmin - push!(points,[x,ymin]) - push!(indices,2) + push!(points, [x, ymin]) + push!(indices, 2) i+=1 end x = -n[2]/n[1]*ymax if xxmin - push!(points,[x,ymax]) - push!(indices,6) + push!(points, [x, ymax]) + push!(indices, 6) i+=1 end - clp = findall(x->dot(x,n)==0.,vertices) # Number of vertices lying on the discontinuity + clp = findall(x->dot(x, n)==0.0, vertices) # Number of vertices lying on the discontinuity if length(clp)+i<2 - return false,0.,0. + return false, 0.0, 0.0 else - append!(points,vertices) - append!(indices,CLP) # CLP is defined in dim.jl + append!(points, vertices) + append!(indices, CLP) # CLP is defined in dim.jl sid = sortperm(indices) indices = indices[sid] points = points[sid] - aid = findfirst(x->iseven(x)||in(x,CLP[clp]),indices) - bid = findlast(x->iseven(x)||in(x,CLP[clp]),indices) - A = Matrix{Float64}(undef,2,bid-aid+1);B = Matrix{Float64}(undef,2,length(indices)-(bid-aid)+1) - for i in aid:bid - A[:,i-aid+1] .= points[i] + aid = findfirst(x->iseven(x)||in(x, CLP[clp]), indices) + bid = findlast(x->iseven(x)||in(x, CLP[clp]), indices) + A = Matrix{Float64}(undef, 2, bid-aid+1); + B = Matrix{Float64}(undef, 2, length(indices)-(bid-aid)+1) + for i = aid:bid + A[:, i-aid+1] .= points[i] end - for i in 0:length(indices)-(bid-aid) + for i = 0:(length(indices)-(bid-aid)) index = bid+i>length(indices) ? (bid+i)%length(indices) : bid+i - B[:,i+1] .= points[index] + B[:, i+1] .= points[index] end l = points[bid]-points[aid] if n[1]*l[2]-n[2]*l[1]<0 gas_weight = gaussian_area(A) - return true,gas_weight,((xmax-xmin)*(ymax-ymin))-gas_weight # solid first + return true, gas_weight, ((xmax-xmin)*(ymax-ymin))-gas_weight # solid first else solid_weight = gaussian_area(A) - return true,((xmax-xmin)*(ymax-ymin))-solid_weight,solid_weight + return true, ((xmax-xmin)*(ymax-ymin))-solid_weight, solid_weight end end end @@ -80,14 +83,18 @@ end 3D cut cell. """ function cut_cube_rotate(n::Vector{Float64}) - C = zeros(2,3) - e1 = [1.,0.,0.] - e1 = cross(n,e1);e1./=norm(e1) - e2 = cross(n,e1);e2./=norm(e2) - if dot(cross(e1,e2),n)>0 - C[1,:].=e1;C[2,:].=e2 + C = zeros(2, 3) + e1 = [1.0, 0.0, 0.0] + e1 = cross(n, e1); + e1./=norm(e1) + e2 = cross(n, e1); + e2./=norm(e2) + if dot(cross(e1, e2), n)>0 + C[1, :].=e1; + C[2, :].=e2 else - C[2,:].=e1;C[1,:].=e2 + C[2, :].=e1; + C[1, :].=e2 end return C end @@ -96,108 +103,149 @@ end Calculate the flux of the vector (x,y,z)/3 through the vertical faces composed by intersecting points and vertices. Normally, the cases where the connecting line of the two neighboring intersecting pionts are parallel to grid lines should have been got rid of before the function is called. """ -function Vertical_Volume_Flux(points::AbstractVector{Vector{Float64}},midpoint::Vector{Float64},vertices::AbstractMatrix{Float64}) - H = 0.;N = length(points) +function Vertical_Volume_Flux( + points::AbstractVector{Vector{Float64}}, + midpoint::Vector{Float64}, + vertices::AbstractMatrix{Float64}, +) + H = 0.0; + N = length(points) for i in eachindex(points) - p1 = points[i%N+1];p2 = points[i] - dx= p1-p2 - id = findall(x->abs(x)<3.0*eps(),dx) + p1 = points[i%N+1]; + p2 = points[i] + dx = p1-p2 + id = findall(x->abs(x)<3.0*eps(), dx) if length(id)>1 throw(`Cut-cube Error!`) else dir = id[1] - vid = findall(x->abs(x[dir]-points[i][dir])abs(x[dir]-points[i][dir])abs(midpoint[i])≈0.5*ddu[i],1:length(midpoint)) +function vertices_sweep!(midpoint, ddu, vertices) # Clean the eps in vertices. + if any(i->abs(midpoint[i])≈0.5*ddu[i], 1:length(midpoint)) for i in eachindex(vertices) - abs(vertices[i]) < EPS && (vertices[i] = 0.) + abs(vertices[i]) < EPS && (vertices[i] = 0.0) end end return nothing end -function cut_cube(n::Vector{Float64},C::Matrix{Float64},midpoint::Vector{Float64},ddu::Vector{Float64},vertices::Matrix{Float64}) # 3.627 μs (215 allocations: 8.45 KiB). Acceptable? - vertices_sweep!(midpoint,ddu,vertices) - vltable = [[1,2],[3,4],[7,8],[5,6],[1,3],[2,4],[6,8],[5,7],[1,5],[2,6],[4,8],[3,7]] # vertices-edges table - points = Vector{Vector{Float64}}(undef,6);index = 1 +function cut_cube( + n::Vector{Float64}, + C::Matrix{Float64}, + midpoint::Vector{Float64}, + ddu::Vector{Float64}, + vertices::Matrix{Float64}, +) # 3.627 μs (215 allocations: 8.45 KiB). Acceptable? + vertices_sweep!(midpoint, ddu, vertices) + vltable = [ + [1, 2], + [3, 4], + [7, 8], + [5, 6], + [1, 3], + [2, 4], + [6, 8], + [5, 7], + [1, 5], + [2, 6], + [4, 8], + [3, 7], + ] # vertices-edges table + points = Vector{Vector{Float64}}(undef, 6); + index = 1 dirs = permutedims(vertices)*n # what if vertices[i]=0.? for i in eachindex(vltable) - d1 = dirs[vltable[i][1]]; d2 = dirs[vltable[i][2]] + d1 = dirs[vltable[i][1]]; + d2 = dirs[vltable[i][2]] flag = d1*d2 # flag==0: cut any end of the edge; flag<0: cut the edge; flag>0: not cut the edge - if min(abs(d1),abs(d2))<3.0*eps() - if cld(i,4)==1 # avoid redundancy + if min(abs(d1), abs(d2))<3.0*eps() + if cld(i, 4)==1 # avoid redundancy if abs(dirs[vltable[i][1]])<3.0*eps() # end A intersects - points[index] = vertices[:,vltable[i][1]];index+=1 + points[index] = vertices[:, vltable[i][1]]; + index+=1 else # end B intersects - points[index] = vertices[:,vltable[i][2]];index+=1 + points[index] = vertices[:, vltable[i][2]]; + index+=1 end end elseif flag<0 # intersects between the two ends - point = vertices[:,vltable[i][1]] - dir = cld(i,4);point[dir]=0. - point[dir] = -dot(point,n)/(n[dir]) - points[index] = point;index+=1 + point = vertices[:, vltable[i][1]] + dir = cld(i, 4); + point[dir]=0.0 + point[dir] = -dot(point, n)/(n[dir]) + points[index] = point; + index+=1 end end - index<4&&return false,0.,0. - points = points[1:index-1] - posid = findall(x->x>3.0*eps(),dirs) + index<4&&return false, 0.0, 0.0 + points = points[1:(index-1)] + posid = findall(x->x>3.0*eps(), dirs) pos = length(posid)<4 ? true : false # H represents solid? - if any(x->abs(x)abs(x)abs(x[dir]-vertices[dir])abs(x)abs(x)abs(x[dir]-vertices[dir])abs(x[dir]-vertices[dir])EPS,eachcol(vertices)) # all vertices share the same face with the first one, but not cut by the boundary face + vid = + findall(x->abs(x[dir]-vertices[dir])EPS, eachcol(vertices)) # all vertices share the same face with the first one, but not cut by the boundary face else - vid = findall(x->abs(x[dir]-vertices[dir])abs(x[dir]-vertices[dir])abs(centers[i]-midpoint[i])≈0.5*ddu[i],1:3) + centers = @views sum(vertices[:, posid], dims = 2) ./ 4.0 + dir = findfirst(i->abs(centers[i]-midpoint[i])≈0.5*ddu[i], 1:3) if isnothing(dir) - H = 0. + H = 0.0 else - id1 = dir%3+1;id2 = (dir+1)%3+1 - H = pos ? sign(centers[dir]-midpoint[dir])*centers[dir]*ddu[id1]*ddu[id2]/3.0 : -sign(centers[dir]-midpoint[dir])*(2.0*midpoint[dir]-centers[dir])*ddu[id1]*ddu[id2]/3.0 + id1 = dir%3+1; + id2 = (dir+1)%3+1 + H = + pos ? + sign(centers[dir]-midpoint[dir])*centers[dir]*ddu[id1]*ddu[id2]/3.0 : + -sign(centers[dir]-midpoint[dir])*(2.0*midpoint[dir]-centers[dir])*ddu[id1]*ddu[id2]/3.0 end else - H = 0. + H = 0.0 end if pos - @views H+=Vertical_Volume_Flux(points[id],midpoint,vertices[:,posid]) - return true,8*prod(midpoint-@view(vertices[:,1]))-H,H # gas first + @views H+=Vertical_Volume_Flux(points[id], midpoint, vertices[:, posid]) + return true, 8*prod(midpoint-@view(vertices[:, 1]))-H, H # gas first else - negid = findall(x->x<-3.0*eps(),dirs) - @views H+=Vertical_Volume_Flux(points[id],midpoint,vertices[:,negid]) - return true,H,8*prod(midpoint-@view(vertices[:,1]))-H + negid = findall(x->x<-3.0*eps(), dirs) + @views H+=Vertical_Volume_Flux(points[id], midpoint, vertices[:, negid]) + return true, H, 8*prod(midpoint-@view(vertices[:, 1]))-H end end -end \ No newline at end of file +end diff --git a/src/Velocity_space/Initialize.jl b/src/Velocity_space/Initialize.jl index eb41ed6..41e5dbb 100644 --- a/src/Velocity_space/Initialize.jl +++ b/src/Velocity_space/Initialize.jl @@ -1,12 +1,16 @@ -function init_vs(prim::AbstractVector,global_data::Global_Data) +function init_vs(prim::AbstractVector, global_data::Global_Data) quadrature = global_data.config.quadrature - init_vs(prim,global_data,quadrature) + init_vs(prim, global_data, quadrature) end function init_vs(vs_data::VS_Data) return deepcopy(vs_data) end -function init_vs(prim::AbstractVector,global_data::Global_Data{DIM,NDF},quadrature::Vector{Float64}) where{DIM,NDF} +function init_vs( + prim::AbstractVector, + global_data::Global_Data{DIM,NDF}, + quadrature::Vector{Float64}, +) where {DIM,NDF} trees_num = global_data.config.vs_trees_num vs_num = reduce(*, trees_num) midpoint = zeros(vs_num, DIM) @@ -22,7 +26,7 @@ function init_vs(prim::AbstractVector,global_data::Global_Data{DIM,NDF},quadratu midpoints = Base.Iterators.product(ranges...) index = 1 for point in midpoints - midpoint[index,:] .= point + midpoint[index, :] .= point index += 1 end df = discrete_maxwell(midpoint, prim, global_data) @@ -31,21 +35,31 @@ function init_vs(prim::AbstractVector,global_data::Global_Data{DIM,NDF},quadratu return VS_Data{DIM,NDF}(vs_num, zeros(Int, vs_num), weight, midpoint, df, sdf, flux) end -function init_vs(prim::AbstractVector,global_data::Global_Data{2,NDF},quadrature::Gauss_Hermite{NP};kwargs...) where{NDF,NP} +function init_vs( + prim::AbstractVector, + global_data::Global_Data{2,NDF}, + quadrature::Gauss_Hermite{NP}; + kwargs..., +) where {NDF,NP} DIM = 2 trees_num = global_data.config.vs_trees_num vs_num = reduce(*, trees_num) - index = 1;midpoint = Matrix{Float64}(undef,vs_num,DIM);weight = Vector{Float64}(undef,vs_num) - vcoords = quadrature.vcoords;weights = quadrature.weights - for i in 1:NP - for j in 1:NP - midpoint[index,1] = vcoords[i];midpoint[index,2] = vcoords[j] - weight[index] = weights[i]*exp(midpoint[index,1]^2)*weights[j]*exp(midpoint[index,2]^2) + index = 1; + midpoint = Matrix{Float64}(undef, vs_num, DIM); + weight = Vector{Float64}(undef, vs_num) + vcoords = quadrature.vcoords; + weights = quadrature.weights + for i = 1:NP + for j = 1:NP + midpoint[index, 1] = vcoords[i]; + midpoint[index, 2] = vcoords[j] + weight[index] = + weights[i]*exp(midpoint[index, 1]^2)*weights[j]*exp(midpoint[index, 2]^2) index += 1 end - end - df = haskey(kwargs,:df) ? kwargs[:df] : discrete_maxwell(midpoint, prim, global_data) + end + df = haskey(kwargs, :df) ? kwargs[:df] : discrete_maxwell(midpoint, prim, global_data) sdf = zeros(vs_num, NDF, DIM) flux = zeros(vs_num, NDF) return VS_Data{DIM,NDF}(vs_num, zeros(Int, vs_num), weight, midpoint, df, sdf, flux) -end \ No newline at end of file +end diff --git a/src/Velocity_space/Types.jl b/src/Velocity_space/Types.jl index 18c869f..a4f6733 100644 --- a/src/Velocity_space/Types.jl +++ b/src/Velocity_space/Types.jl @@ -47,8 +47,8 @@ struct Face_VS_Data{DIM,NDF} # different sides of the face combining the face-ve df::AbstractMatrix{Float64} sdf::AbstractArray{Float64} end -function Face_VS_Data(fvd::Face_VS_Data{DIM,NDF},df::AbstractMatrix) where{DIM,NDF} - return Face_VS_Data{DIM,NDF}(fvd.heavi,fvd.weight,fvd.midpoint,fvd.vn,df,fvd.sdf) +function Face_VS_Data(fvd::Face_VS_Data{DIM,NDF}, df::AbstractMatrix) where {DIM,NDF} + return Face_VS_Data{DIM,NDF}(fvd.heavi, fvd.weight, fvd.midpoint, fvd.vn, df, fvd.sdf) end struct VelocityTemplates indices::Vector{Int} # Indices of the templates @@ -85,23 +85,69 @@ struct Gauss_Hermite{NUM} <: AbstractQuadrature vcoords::AbstractVector weights::AbstractVector end -function Gauss_Hermite(;NP=28) +function Gauss_Hermite(; NP = 28) if NP==28 - vcoords = [ -0.5392407922630E+01, -0.4628038787602E+01, -0.3997895360339E+01, -0.3438309154336E+01, - -0.2926155234545E+01, -0.2450765117455E+01, -0.2007226518418E+01, -0.1594180474269E+01, - -0.1213086106429E+01, -0.8681075880846E+00, -0.5662379126244E+00, -0.3172834649517E+00, - -0.1331473976273E+00, -0.2574593750171E-01, +0.2574593750171E-01, +0.1331473976273E+00, - +0.3172834649517E+00, +0.5662379126244E+00, +0.8681075880846E+00, +0.1213086106429E+01, - +0.1594180474269E+01, +0.2007226518418E+01, +0.2450765117455E+01, +0.2926155234545E+01, - +0.3438309154336E+01, +0.3997895360339E+01, +0.4628038787602E+01, +0.5392407922630E+01 ] - weights = [ +0.2070921821819E-12, +0.3391774320172E-09, +0.6744233894962E-07, +0.3916031412192E-05, - +0.9416408715712E-04, +0.1130613659204E-02, +0.7620883072174E-02, +0.3130804321888E-01, - +0.8355201801999E-01, +0.1528864568113E+00, +0.2012086859914E+00, +0.1976903952423E+00, - +0.1450007948865E+00, +0.6573088665062E-01, +0.6573088665062E-01, +0.1450007948865E+00, - +0.1976903952423E+00, +0.2012086859914E+00, +0.1528864568113E+00, +0.8355201801999E-01, - +0.3130804321888E-01, +0.7620883072174E-02, +0.1130613659204E-02, +0.9416408715712E-04, - +0.3916031412192E-05, +0.6744233894962E-07, +0.3391774320172E-09, +0.2070921821819E-12 ] - return Gauss_Hermite{NP}(vcoords,weights) + vcoords = [ + -0.5392407922630E+01, + -0.4628038787602E+01, + -0.3997895360339E+01, + -0.3438309154336E+01, + -0.2926155234545E+01, + -0.2450765117455E+01, + -0.2007226518418E+01, + -0.1594180474269E+01, + -0.1213086106429E+01, + -0.8681075880846E+00, + -0.5662379126244E+00, + -0.3172834649517E+00, + -0.1331473976273E+00, + -0.2574593750171E-01, + +0.2574593750171E-01, + +0.1331473976273E+00, + +0.3172834649517E+00, + +0.5662379126244E+00, + +0.8681075880846E+00, + +0.1213086106429E+01, + +0.1594180474269E+01, + +0.2007226518418E+01, + +0.2450765117455E+01, + +0.2926155234545E+01, + +0.3438309154336E+01, + +0.3997895360339E+01, + +0.4628038787602E+01, + +0.5392407922630E+01, + ] + weights = [ + +0.2070921821819E-12, + +0.3391774320172E-09, + +0.6744233894962E-07, + +0.3916031412192E-05, + +0.9416408715712E-04, + +0.1130613659204E-02, + +0.7620883072174E-02, + +0.3130804321888E-01, + +0.8355201801999E-01, + +0.1528864568113E+00, + +0.2012086859914E+00, + +0.1976903952423E+00, + +0.1450007948865E+00, + +0.6573088665062E-01, + +0.6573088665062E-01, + +0.1450007948865E+00, + +0.1976903952423E+00, + +0.2012086859914E+00, + +0.1528864568113E+00, + +0.8355201801999E-01, + +0.3130804321888E-01, + +0.7620883072174E-02, + +0.1130613659204E-02, + +0.9416408715712E-04, + +0.3916031412192E-05, + +0.6744233894962E-07, + +0.3391774320172E-09, + +0.2070921821819E-12, + ] + return Gauss_Hermite{NP}(vcoords, weights) else throw(`Gauss_Hermite not defined yet.`) end @@ -115,4 +161,4 @@ end struct Velocity_Adaptive_Data vr::Velocity_Resolution va_flags::Vector{Bool} -end \ No newline at end of file +end diff --git a/src/Velocity_space/Velocity_space.jl b/src/Velocity_space/Velocity_space.jl index 4311411..0dba20f 100644 --- a/src/Velocity_space/Velocity_space.jl +++ b/src/Velocity_space/Velocity_space.jl @@ -3,4 +3,9 @@ include("Criteria.jl") include("Cut_cell.jl") include("Initialize.jl") export VS_Data, Ghost_VS_Data, Face_VS_Data, CuttedVelocityCells -export vs_adaptive_mesh_refinement!, vs_refine!, vs_coarsen!, vs_conserved_correction!, contribution_refine_flag, contribution_coarsen_flag \ No newline at end of file +export vs_adaptive_mesh_refinement!, + vs_refine!, + vs_coarsen!, + vs_conserved_correction!, + contribution_refine_flag, + contribution_coarsen_flag diff --git a/test/runtests.jl b/test/runtests.jl index d3b36ff..775463a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,7 +2,8 @@ using KitAMR, MPI MPI.Init() solver = Solver(; - DIM = 2, NDF = 2, + DIM = 2, + NDF = 2, AMR_PS_MAXLEVEL = 0, AMR_VS_MAXLEVEL = 0, PS_DYNAMIC_AMR = false, @@ -10,46 +11,43 @@ solver = Solver(; flux = CAIDVM, time_marching = CAIDVM_Marching, ) -gas = Gas(; - K = 0.0, - Kn = 0.075, - ω = 0.81, - ωᵣ = 0.81, -) +gas = Gas(; K = 0.0, Kn = 0.075, ω = 0.81, ωᵣ = 0.81) output = Output(solver) udf = UDF() -config = Configure(solver; - geometry = [-0.5,0.5,-0.5,0.5], - trees_num = [16,16], - quadrature = [-5.0,5.0,-5.0,5.0], - vs_trees_num = [16,16], - IC = Uniform([1.,0.,0.,1.]), +config = Configure( + solver; + geometry = [-0.5, 0.5, -0.5, 0.5], + trees_num = [16, 16], + quadrature = [-5.0, 5.0, -5.0, 5.0], + vs_trees_num = [16, 16], + IC = Uniform([1.0, 0.0, 0.0, 1.0]), domain = [ - Domain(Maxwellian,1,[1.,0.,0.,1.]), - Domain(Maxwellian,2,[1.,1.0*sqrt(5/6),0.,1.0]),Domain(Period,3), - Domain(Period,4) - ], + Domain(Maxwellian, 1, [1.0, 0.0, 0.0, 1.0]), + Domain(Maxwellian, 2, [1.0, 1.0*sqrt(5/6), 0.0, 1.0]), + Domain(Period, 3), + Domain(Period, 4), + ], output = output, gas = gas, - user_defined = udf + user_defined = udf, ) -ps4est,amr = initialize_KitAMR(config); -max_sim_time = 20. +ps4est, amr = initialize_KitAMR(config); +max_sim_time = 20.0 nt = max_sim_time/amr.global_data.status.Δt+1.0 |> floor |> Int -for i in 1:10 +for i = 1:10 # adaptive_mesh_refinement!(ps4est,amr) update_slope!(amr) - slope_exchange!(ps4est, amr) + slope_exchange!(ps4est, amr) update_solid_cell!(amr) solid_exchange!(ps4est, amr) update_solid_neighbor!(amr) - flux!(amr) - iterate!(amr) + flux!(amr) + iterate!(amr) data_exchange!(ps4est, amr) check_for_convergence(amr)&&break - check!(i,ps4est,amr) + check!(i, ps4est, amr) end # save_result(ps4est,amr) -finalize!(ps4est,amr) +finalize!(ps4est, amr) MPI.Finalize() diff --git a/test/test_cut_cube.jl b/test/test_cut_cube.jl index bc88430..1977e9b 100644 --- a/test/test_cut_cube.jl +++ b/test/test_cut_cube.jl @@ -1,141 +1,199 @@ using LinearAlgebra, Statistics function cut_cube_rotate(n::Vector{Float64}) - C = zeros(2,3) - e1 = [1.,0.,0.] - e1 = cross(n,e1);e1./=norm(e1) - e2 = cross(n,e1);e2./=norm(e2) - if dot(cross(e1,e2),n)>0 - C[1,:].=e1;C[2,:].=e2 + C = zeros(2, 3) + e1 = [1.0, 0.0, 0.0] + e1 = cross(n, e1); + e1./=norm(e1) + e2 = cross(n, e1); + e2./=norm(e2) + if dot(cross(e1, e2), n)>0 + C[1, :].=e1; + C[2, :].=e2 else - C[2,:].=e1;C[1,:].=e2 + C[2, :].=e1; + C[1, :].=e2 end return C end -function Vertical_Volume_Flux(points::AbstractVector{Vector{Float64}},midpoint::Vector{Float64},vertices::AbstractMatrix{Float64}) - H = 0.;N = length(points) +function Vertical_Volume_Flux( + points::AbstractVector{Vector{Float64}}, + midpoint::Vector{Float64}, + vertices::AbstractMatrix{Float64}, +) + H = 0.0; + N = length(points) for i in eachindex(points) - p1 = points[i%N+1];p2 = points[i] - dx= p1-p2 - id = findall(x->abs(x)<3.0*eps(),dx) + p1 = points[i%N+1]; + p2 = points[i] + dx = p1-p2 + id = findall(x->abs(x)<3.0*eps(), dx) if length(id)>1 throw(`Cut-cube Error!`) else dir = id[1] - vid = findall(x->abs(x[dir]-points[i][dir])abs(x[dir]-points[i][dir])abs(midpoint[i])≈0.5*ddu[i],1:length(midpoint)) +function vertices_sweep!(midpoint, ddu, vertices) # Clean the eps in vertices. + if any(i->abs(midpoint[i])≈0.5*ddu[i], 1:length(midpoint)) for i in eachindex(vertices) - abs(vertices[i]) < EPS && (vertices[i] = 0.) + abs(vertices[i]) < EPS && (vertices[i] = 0.0) end end return nothing end -function cut_cube(n::Vector{Float64},C::Matrix{Float64},midpoint::Vector{Float64},ddu::Vector{Float64},vertices::Matrix{Float64}) # 3.627 μs (215 allocations: 8.45 KiB). Acceptable? - vertices_sweep!(midpoint,ddu,vertices) - vltable = [[1,2],[3,4],[7,8],[5,6],[1,3],[2,4],[6,8],[5,7],[1,5],[2,6],[4,8],[3,7]] # vertices-edges table - points = Vector{Vector{Float64}}(undef,6);index = 1 +function cut_cube( + n::Vector{Float64}, + C::Matrix{Float64}, + midpoint::Vector{Float64}, + ddu::Vector{Float64}, + vertices::Matrix{Float64}, +) # 3.627 μs (215 allocations: 8.45 KiB). Acceptable? + vertices_sweep!(midpoint, ddu, vertices) + vltable = [ + [1, 2], + [3, 4], + [7, 8], + [5, 6], + [1, 3], + [2, 4], + [6, 8], + [5, 7], + [1, 5], + [2, 6], + [4, 8], + [3, 7], + ] # vertices-edges table + points = Vector{Vector{Float64}}(undef, 6); + index = 1 dirs = permutedims(vertices)*n # what if vertices[i]=0.? @show dirs permutedims(vertices) for i in eachindex(vltable) - d1 = dirs[vltable[i][1]]; d2 = dirs[vltable[i][2]] + d1 = dirs[vltable[i][1]]; + d2 = dirs[vltable[i][2]] flag = d1*d2 # flag==0: cut any end of the edge; flag<0: cut the edge; flag>0: not cut the edge - if min(abs(d1),abs(d2))<3.0*eps() - if cld(i,4)==1 # avoid redundancy + if min(abs(d1), abs(d2))<3.0*eps() + if cld(i, 4)==1 # avoid redundancy if abs(dirs[vltable[i][1]])<3.0*eps() # end A intersects - points[index] = vertices[:,vltable[i][1]];index+=1 + points[index] = vertices[:, vltable[i][1]]; + index+=1 else # end B intersects - points[index] = vertices[:,vltable[i][2]];index+=1 + points[index] = vertices[:, vltable[i][2]]; + index+=1 end end elseif flag<0 # intersects between the two ends - point = vertices[:,vltable[i][1]] - dir = cld(i,4);point[dir]=0. - point[dir] = -dot(point,n)/(n[dir]) - points[index] = point;index+=1 + point = vertices[:, vltable[i][1]] + dir = cld(i, 4); + point[dir]=0.0 + point[dir] = -dot(point, n)/(n[dir]) + points[index] = point; + index+=1 end end - index<4&&return false,0.,0. - points = points[1:index-1] - posid = findall(x->x>3.0*eps(),dirs) + index<4&&return false, 0.0, 0.0 + points = points[1:(index-1)] + posid = findall(x->x>3.0*eps(), dirs) pos = length(posid)<4 ? true : false # H represents solid? - if any(x->abs(x)abs(x)abs(x[dir]-vertices[dir])abs(x)abs(x)abs(x[dir]-vertices[dir])abs(x[dir]-vertices[dir])EPS,eachcol(vertices)) # all vertices share the same face with the first one, but not cut by the boundary face + vid = + findall(x->abs(x[dir]-vertices[dir])EPS, eachcol(vertices)) # all vertices share the same face with the first one, but not cut by the boundary face else - vid = findall(x->abs(x[dir]-vertices[dir])abs(x[dir]-vertices[dir])abs(centers[i]-midpoint[i])≈0.5*ddu[i],1:3) + centers = @views sum(vertices[:, posid], dims = 2) ./ 4.0 + dir = findfirst(i->abs(centers[i]-midpoint[i])≈0.5*ddu[i], 1:3) if isnothing(dir) - H = 0. + H = 0.0 else - id1 = dir%3+1;id2 = (dir+1)%3+1 - H = pos ? sign(centers[dir]-midpoint[dir])*centers[dir]*ddu[id1]*ddu[id2]/3.0 : -sign(centers[dir]-midpoint[dir])*(2.0*midpoint[dir]-centers[dir])*ddu[id1]*ddu[id2]/3.0 + id1 = dir%3+1; + id2 = (dir+1)%3+1 + H = + pos ? + sign(centers[dir]-midpoint[dir])*centers[dir]*ddu[id1]*ddu[id2]/3.0 : + -sign(centers[dir]-midpoint[dir])*(2.0*midpoint[dir]-centers[dir])*ddu[id1]*ddu[id2]/3.0 end else - H = 0. + H = 0.0 end if pos @show points[id] - @views H+=Vertical_Volume_Flux(points[id],midpoint,vertices[:,posid]) - return true,8*prod(midpoint-@view(vertices[:,1]))-H,H # gas first + @views H+=Vertical_Volume_Flux(points[id], midpoint, vertices[:, posid]) + return true, 8*prod(midpoint-@view(vertices[:, 1]))-H, H # gas first else - negid = findall(x->x<0.,dirs) - @views H+=Vertical_Volume_Flux(points[id],midpoint,vertices[:,negid]) - return true,H,8*prod(midpoint-@view(vertices[:,1]))-H + negid = findall(x->x<0.0, dirs) + @views H+=Vertical_Volume_Flux(points[id], midpoint, vertices[:, negid]) + return true, H, 8*prod(midpoint-@view(vertices[:, 1]))-H end end end function gaussian_area(A::AbstractMatrix) # DIMxN area = 0 - for i in axes(A,2) - j = i%size(A,2)+1 - area+=@views det(A[:,[i,j]]) + for i in axes(A, 2) + j = i%size(A, 2)+1 + area+=@views det(A[:, [i, j]]) end return 0.5*abs(area) end -function test_cut_cube(midpoint,ddu,n) - ANTIVT = [[],[[-1, -1], [1, -1], [1, 1], [-1, 1]],[[-1,-1,-1],[1,-1,-1],[-1,1,-1],[1,1,-1],[-1,-1,1],[1,-1,1],[-1,1,1],[1,1,1]]] # anticlock vertices table +function test_cut_cube(midpoint, ddu, n) + ANTIVT = [ + [], + [[-1, -1], [1, -1], [1, 1], [-1, 1]], + [ + [-1, -1, -1], + [1, -1, -1], + [-1, 1, -1], + [1, 1, -1], + [-1, -1, 1], + [1, -1, 1], + [-1, 1, 1], + [1, 1, 1], + ], + ] # anticlock vertices table C = cut_cube_rotate(n) - vertices = zeros(3,8) - for j in axes(vertices,2) - vertices[:,j] = 0.5*ANTIVT[3][j].*ddu+midpoint + vertices = zeros(3, 8) + for j in axes(vertices, 2) + vertices[:, j] = 0.5*ANTIVT[3][j] .* ddu+midpoint end - cut_cube(n,C,midpoint,ddu,vertices) + cut_cube(n, C, midpoint, ddu, vertices) end #= sphere bug @@ -151,4 +209,4 @@ sphere bug n = [0.65625, -0.65625, 0.37238672774415577] ddu = [0.91, 0.91, 0.91] midpoint = [-6.825, -6.825, -0.455] -test_cut_cube(midpoint,ddu,n) +test_cut_cube(midpoint, ddu, n) diff --git a/test/test_flux.jl b/test/test_flux.jl index f69be0b..87626ff 100644 --- a/test/test_flux.jl +++ b/test/test_flux.jl @@ -1,40 +1,40 @@ using BenchmarkTools, LinearAlgebra -df = rand(10000,2) -vn = rand(10000,2) +df = rand(10000, 2) +vn = rand(10000, 2) @btime @inbounds begin - for i in axes($df,1) - for j in axes($df,2) - $df[i,j]*=$vn[i] + for i in axes($df, 1) + for j in axes($df, 2) + $df[i, j]*=$vn[i] end end end @btime begin - here_micro = [$df[i,j]*$vn[i] for i in axes($df,1),j in axes($df,2)]; + here_micro = [$df[i, j]*$vn[i] for i in axes($df, 1), j in axes($df, 2)]; end @btime begin - for i in axes($df,1) - $df[i,:] *= 2. - end + for i in axes($df, 1) + $df[i, :] *= 2.0 + end end -c = zeros(length(df),1) +c = zeros(length(df), 1) @btime begin @views begin - for i in axes($df,1) - $c[i] = dot($df[i,:],$vn[i,:]) + for i in axes($df, 1) + $c[i] = dot($df[i, :], $vn[i, :]) end end end @btime begin - @views $df[:,1] .= $df[:,2] + @views $df[:, 1] .= $df[:, 2] end @btime begin - for i in axes($df,1) - $df[i,1] = $df[i,2] + for i in axes($df, 1) + $df[i, 1] = $df[i, 2] end end -@allocated using KitAMR \ No newline at end of file +@allocated using KitAMR diff --git a/test/test_meshio.jl b/test/test_meshio.jl index c81eeb2..4d1130d 100644 --- a/test/test_meshio.jl +++ b/test/test_meshio.jl @@ -1,19 +1,19 @@ using FileIO, NearestNeighbors, AbstractTrees, StaticArrays, LinearAlgebra -using NearestNeighbors:HyperRectangle -using GeometryBasics:Mesh +using NearestNeighbors: HyperRectangle +using GeometryBasics: Mesh mesh = load("./example/X38/X38-surface-coarse.stl") # face = first(mesh.faces) -centers = zeros(3,length(mesh.faces)) +centers = zeros(3, length(mesh.faces)) for i in eachindex(mesh.faces) vertices = mesh.position[mesh.faces[i]] - for j in 1:3 - for k in 1:3 - centers[j,i] += vertices[k][j]/3.0 + for j = 1:3 + for k = 1:3 + centers[j, i] += vertices[k][j]/3.0 end end end -kdt = KDTree(centers;leafsize = 25) +kdt = KDTree(centers; leafsize = 25) @@ -28,59 +28,66 @@ kdt = KDTree(centers;leafsize = 25) # treeregion(right_child) # treeregion(treeroot(kdt)) -function triangle_box_table(kdt::KDTree,mesh::Mesh) +function triangle_box_table(kdt::KDTree, mesh::Mesh) tree_data = kdt.tree_data n_nodes = tree_data.n_internal_nodes n_leaves = tree_data.n_leafs - table = Vector{HyperRectangle{SVector{3,Float64}}}(undef,n_nodes+n_leaves) + table = Vector{HyperRectangle{SVector{3,Float64}}}(undef, n_nodes+n_leaves) # lv = collect(NearestNeighbors.leaves(kdt)) lv = leaves(kdt) - lower = Inf*ones(3);upper = -Inf*ones(3) + lower = Inf*ones(3); + upper = -Inf*ones(3) for node in lv id = node.index ids = leaf_point_indices(node) for j in eachindex(ids) vertices = mesh.position[mesh.faces[ids[j]]] - for k in 1:3 - lower.=min.(lower,vertices[k]) - upper.=max.(upper,vertices[k]) + for k = 1:3 + lower.=min.(lower, vertices[k]) + upper.=max.(upper, vertices[k]) end end - table[id] = HyperRectangle(SVector{3,Float64}(lower),SVector{3,Float64}(upper)) - lower.=Inf;upper.=-Inf + table[id] = HyperRectangle(SVector{3,Float64}(lower), SVector{3,Float64}(upper)) + lower.=Inf; + upper.=-Inf end for node in PostOrderDFS(treeroot(kdt)) isempty(children(node))&&continue # is a leaf? - left_child,right_child = children(node) - lid = left_child.index;rid = right_child.index - lower.=min.(table[lid].mins,table[rid].mins) - upper.=max.(table[lid].maxes,table[rid].maxes) - table[node.index] = HyperRectangle(SVector{3,Float64}(lower),SVector{3,Float64}(upper)) - lower .= Inf;upper .= -Inf + left_child, right_child = children(node) + lid = left_child.index; + rid = right_child.index + lower.=min.(table[lid].mins, table[rid].mins) + upper.=max.(table[lid].maxes, table[rid].maxes) + table[node.index] = + HyperRectangle(SVector{3,Float64}(lower), SVector{3,Float64}(upper)) + lower .= Inf; + upper .= -Inf end return table end function triangle_recs(mesh::Mesh) - recs = Vector{HyperRectangle{SVector{3,Float64}}}(undef,length(mesh.faces)) - lower = Inf*ones(3);upper = -Inf*ones(3) + recs = Vector{HyperRectangle{SVector{3,Float64}}}(undef, length(mesh.faces)) + lower = Inf*ones(3); + upper = -Inf*ones(3) for i in eachindex(recs) vertices = mesh.position[mesh.faces[i]] - for j in 1:3 - lower .= min.(lower,vertices[j]) - upper .= max.(upper,vertices[j]) + for j = 1:3 + lower .= min.(lower, vertices[j]) + upper .= max.(upper, vertices[j]) end - recs[i] = HyperRectangle(SVector{3,Float64}(lower),SVector{3,Float64}(upper)) - lower .= Inf; upper .= -Inf + recs[i] = HyperRectangle(SVector{3,Float64}(lower), SVector{3,Float64}(upper)) + lower .= Inf; + upper .= -Inf end return recs end function triangle_edges(mesh::Mesh) - edges = Vector{Vector{SVector{3,Float64}}}(undef,length(mesh.faces)) + edges = Vector{Vector{SVector{3,Float64}}}(undef, length(mesh.faces)) for i in eachindex(mesh.faces) vertices = mesh.position[mesh.faces[i]] - edges[i] = Vector{SVector{3,Float64}}(undef,3) - for j in 1:3 + edges[i] = Vector{SVector{3,Float64}}(undef, 3) + for j = 1:3 edges[i][j] = SVector{3,Float64}(vertices[j%3+1]-vertices[j]) end end @@ -95,83 +102,94 @@ struct TriangleKDT triangle_edges::Vector{Vector{SVector{3,Float64}}} end function TriangleKDT(mesh::Mesh) - centers = zeros(3,length(mesh.faces)) + centers = zeros(3, length(mesh.faces)) for i in eachindex(mesh.faces) vertices = mesh.position[mesh.faces[i]] - for j in 1:3 - for k in 1:3 - centers[j,i] += vertices[k][j]/3.0 + for j = 1:3 + for k = 1:3 + centers[j, i] += vertices[k][j]/3.0 end end end - kdt = KDTree(centers;leafsize = 24) - return TriangleKDT(kdt,mesh,triangle_box_table(kdt,mesh),triangle_recs(mesh),triangle_edges(mesh)) + kdt = KDTree(centers; leafsize = 24) + return TriangleKDT( + kdt, + mesh, + triangle_box_table(kdt, mesh), + triangle_recs(mesh), + triangle_edges(mesh), + ) end tkdt = TriangleKDT(mesh) -function any_intersect_test(midpoint,ds,tkdt::TriangleKDT) - lower = midpoint-0.5*ds;upper = midpoint+0.5*ds - any_recursion_test(treeroot(tkdt.kdt),lower,upper,tkdt) +function any_intersect_test(midpoint, ds, tkdt::TriangleKDT) + lower = midpoint-0.5*ds; + upper = midpoint+0.5*ds + any_recursion_test(treeroot(tkdt.kdt), lower, upper, tkdt) end -function any_recursion_test(node::TreeNode,lower,upper,tkdt) - table = tkdt.table;mesh = tkdt.mesh - recs = tkdt.triangle_recs;edges = tkdt.triangle_edges +function any_recursion_test(node::TreeNode, lower, upper, tkdt) + table = tkdt.table; + mesh = tkdt.mesh + recs = tkdt.triangle_recs; + edges = tkdt.triangle_edges id = node.index - if overlap_test(lower,upper,table[id]) # kernel intersect test + if overlap_test(lower, upper, table[id]) # kernel intersect test if isempty(children(node)) ids = leaf_point_indices(node) for i in ids - if overlap_test(lower,upper,recs[i]) - h = 0.5*ds;V0 = mesh.position[mesh.faces[i]][1] - if SAT_test_1(h,midpoint,edges[i],V0) + if overlap_test(lower, upper, recs[i]) + h = 0.5*ds; + V0 = mesh.position[mesh.faces[i]][1] + if SAT_test_1(h, midpoint, edges[i], V0) V = [mesh.position[id]-midpoint for id in mesh.faces[i]] # relative position of the vertices a = [ - SVector{3,Float64}([1,0,0]), - SVector{3,Float64}([0,1,0]), - SVector{3,Float64}([0,0,1]) + SVector{3,Float64}([1, 0, 0]), + SVector{3,Float64}([0, 1, 0]), + SVector{3,Float64}([0, 0, 1]), ] - if SAT_test_2(a,edges[i],h,V) + if SAT_test_2(a, edges[i], h, V) return true end end end end else - lc,rc = children(node) - any_intersect_recursion_test(lc,lower,upper,tkdt) && return true - return any_intersect_recursion_test(rc,lower,upper,tkdt) + lc, rc = children(node) + any_intersect_recursion_test(lc, lower, upper, tkdt) && return true + return any_intersect_recursion_test(rc, lower, upper, tkdt) end else return false end end -function overlap_test(lower,upper,hyper_rec::HyperRectangle) +function overlap_test(lower, upper, hyper_rec::HyperRectangle) for i = 1:3 - (upper[i]hyper_rec.maxes[i])&& return false + (upper[i]hyper_rec.maxes[i]) && return false end return true end -function SAT_test_1(h,C,edge,V0) - n = cross(edge[1],edge[2]) - l = dot(h,abs.(n)) - s = abs(dot(n,V0-C)) +function SAT_test_1(h, C, edge, V0) + n = cross(edge[1], edge[2]) + l = dot(h, abs.(n)) + s = abs(dot(n, V0-C)) s>l && return false return true end -function SAT_test_2(a,edge,h,V) # note that V are vertices relative to the midpoint of the cell - dij = zeros(3);p = zeros(3) - for j in 1:3 - for i in 1:3 - dij .= cross(a[i],edge[j]) - for k in 1:3 - p[k] = dot(dij,V[k]) +function SAT_test_2(a, edge, h, V) # note that V are vertices relative to the midpoint of the cell + dij = zeros(3); + p = zeros(3) + for j = 1:3 + for i = 1:3 + dij .= cross(a[i], edge[j]) + for k = 1:3 + p[k] = dot(dij, V[k]) end - for k in 1:3 + for k = 1:3 dij[k] = abs(dij[k]) end - r = dot(dij,h) + r = dot(dij, h) if minimum(p) > r||maximum(p) < -r # TBD: replace with min/max return false end @@ -182,39 +200,75 @@ end -function all_intersect_test(midpoint,ds,tkdt::TriangleKDT) - lower = midpoint-0.5*ds;upper = midpoint+0.5*ds +function all_intersect_test(midpoint, ds, tkdt::TriangleKDT) + lower = midpoint-0.5*ds; + upper = midpoint+0.5*ds intersect_ids = Int[] - all_intersect_recursion_test!(treeroot(tkdt.kdt),midpoint,ds,lower,upper,tkdt,intersect_ids) + all_intersect_recursion_test!( + treeroot(tkdt.kdt), + midpoint, + ds, + lower, + upper, + tkdt, + intersect_ids, + ) return intersect_ids end -function all_intersect_recursion_test!(node::TreeNode,midpoint,ds,lower,upper,tkdt,intersect_ids::Vector{Int}) - table = tkdt.table;mesh = tkdt.mesh - recs = tkdt.triangle_recs;edges = tkdt.triangle_edges +function all_intersect_recursion_test!( + node::TreeNode, + midpoint, + ds, + lower, + upper, + tkdt, + intersect_ids::Vector{Int}, +) + table = tkdt.table; + mesh = tkdt.mesh + recs = tkdt.triangle_recs; + edges = tkdt.triangle_edges id = node.index - if overlap_test(lower,upper,table[id]) # kernel intersect test + if overlap_test(lower, upper, table[id]) # kernel intersect test if isempty(children(node)) ids = leaf_point_indices(node) for i in ids - if overlap_test(lower,upper,recs[i]) - h = 0.5*ds;V = mesh.position[mesh.faces[i]] - if SAT_test_1(h,midpoint,edges[i],V[1]) + if overlap_test(lower, upper, recs[i]) + h = 0.5*ds; + V = mesh.position[mesh.faces[i]] + if SAT_test_1(h, midpoint, edges[i], V[1]) a = [ - SVector{3,Float64}([ds[1],0,0]), - SVector{3,Float64}([0,ds[2],0]), - SVector{3,Float64}([0,0,ds[3]]) + SVector{3,Float64}([ds[1], 0, 0]), + SVector{3,Float64}([0, ds[2], 0]), + SVector{3,Float64}([0, 0, ds[3]]), ] v = [x-midpoint for x in V] - if SAT_test_2(a,edges[i],h,v) - push!(intersect_ids,i) + if SAT_test_2(a, edges[i], h, v) + push!(intersect_ids, i) end end end end else - lc,rc = children(node) - all_intersect_recursion_test!(lc,midpoint,ds,lower,upper,tkdt,intersect_ids) - all_intersect_recursion_test!(rc,midpoint,ds,lower,upper,tkdt,intersect_ids) + lc, rc = children(node) + all_intersect_recursion_test!( + lc, + midpoint, + ds, + lower, + upper, + tkdt, + intersect_ids, + ) + all_intersect_recursion_test!( + rc, + midpoint, + ds, + lower, + upper, + tkdt, + intersect_ids, + ) end end return nothing @@ -222,26 +276,28 @@ end midpoint = [5.359375, 0.0390625, 0.90625] ds = [0.1875, 0.09375, 0.125] -lower = midpoint-0.5ds;upper = midpoint+0.5ds -intersect_ids = all_intersect_test(midpoint,ds,tkdt) +lower = midpoint-0.5ds; +upper = midpoint+0.5ds +intersect_ids = all_intersect_test(midpoint, ds, tkdt) tri_id = 12209 tri = tkdt.triangle_recs[tri_id] -all(i->tri.mins[i]>lower[i],1:3) -all(i->tri.maxes[i]tri.mins[i]>lower[i], 1:3) +all(i->tri.maxes[i]0.5 && continue - if in_triangle_test(intersect_point,V,edges) + if in_triangle_test(intersect_point, V, edges) @show dir intersect_point return true end @@ -298,54 +355,68 @@ end -function ray_casting_recursion_test!(node::TreeNode,midpoint,dir::Int,is_pos::Bool,tkdt::TriangleKDT,intersect_ids) - table = tkdt.table;mesh = tkdt.mesh;edges = tkdt.triangle_edges;recs = tkdt.triangle_recs +function ray_casting_recursion_test!( + node::TreeNode, + midpoint, + dir::Int, + is_pos::Bool, + tkdt::TriangleKDT, + intersect_ids, +) + table = tkdt.table; + mesh = tkdt.mesh; + edges = tkdt.triangle_edges; + recs = tkdt.triangle_recs id = node.index hyper_rec = table[id] - if ray_casting_rectangle_test(hyper_rec,midpoint,dir,is_pos) + if ray_casting_rectangle_test(hyper_rec, midpoint, dir, is_pos) if isempty(children(node)) ids = leaf_point_indices(node) for i in ids - if ray_casting_rectangle_test(recs[i],midpoint,dir,is_pos) + if ray_casting_rectangle_test(recs[i], midpoint, dir, is_pos) edge = edges[i] V = mesh.position[mesh.faces[i]] - if ray_casting_triangle_test(edge,V,midpoint,dir,is_pos) - push!(intersect_ids,i) + if ray_casting_triangle_test(edge, V, midpoint, dir, is_pos) + push!(intersect_ids, i) end end end else - lc,rc = children(node) - ray_casting_recursion_test!(lc,midpoint,dir,is_pos,tkdt,intersect_ids) - ray_casting_recursion_test!(rc,midpoint,dir,is_pos,tkdt,intersect_ids) + lc, rc = children(node) + ray_casting_recursion_test!(lc, midpoint, dir, is_pos, tkdt, intersect_ids) + ray_casting_recursion_test!(rc, midpoint, dir, is_pos, tkdt, intersect_ids) end end return nothing end -function ray_casting_triangle_test(edge,V,midpoint,dir,is_pos) - e = zeros(3);e[dir] = is_pos ? 1. : -1. - h = cross(e,edge[2]) - a = dot(h,edge[1]) +function ray_casting_triangle_test(edge, V, midpoint, dir, is_pos) + e = zeros(3); + e[dir] = is_pos ? 1.0 : -1.0 + h = cross(e, edge[2]) + a = dot(h, edge[1]) if abs(a)1.0+eps())&&return false - - q = cross(s,edge[1]) - v = f*dot(e,q) + + q = cross(s, edge[1]) + v = f*dot(e, q) (v<-eps()||v>1.0+eps())&&return false - t = f*dot(edge[2],q) + t = f*dot(edge[2], q) t=midpoint[dir] else @@ -363,12 +434,12 @@ function ray_casting(tkdt, midpoint) # Inside the closed surface? center = 0.5*(kdt.hyper_rec.mins[dir]+kdt.hyper_rec.maxes[dir]) is_pos = center( - max(x,y) - ), - MPI.COMM_WORLD - ) - buffer[2] = MPI.Reduce( - buffer[2], - (x,y)->( - x+y - ), - MPI.COMM_WORLD - ) + buffer[1] = MPI.Reduce(buffer[1], (x, y)->(max(x, y)), MPI.COMM_WORLD) + buffer[2] = MPI.Reduce(buffer[2], (x, y)->(x+y), MPI.COMM_WORLD) @show buffer else - MPI.Reduce( - buffer[1], - (x,y)->( - max(x,y) - ), - MPI.COMM_WORLD - ) - MPI.Reduce( - buffer[2], - (x,y)->( - x+y - ), - MPI.COMM_WORLD - ) + MPI.Reduce(buffer[1], (x, y)->(max(x, y)), MPI.COMM_WORLD) + MPI.Reduce(buffer[2], (x, y)->(x+y), MPI.COMM_WORLD) end -MPI.Finalize() \ No newline at end of file +MPI.Finalize() diff --git a/test/test_surface_plot.jl b/test/test_surface_plot.jl index c9ca91d..88d2bfb 100644 --- a/test/test_surface_plot.jl +++ b/test/test_surface_plot.jl @@ -1,15 +1,26 @@ using KitAMR -boundary_solutions = KitAMR.Boundary_Solution(Vector{Float64}[],Vector{Float64}[],KitAMR.Boundary_PS_Solution[]) +boundary_solutions = KitAMR.Boundary_Solution( + Vector{Float64}[], + Vector{Float64}[], + KitAMR.Boundary_PS_Solution[], +) path = "./result2026-03-02_03-23/" -for i in 1:180 +for i = 1:180 bs = KitAMR.load_object(path*"boundary_result_"*string(i-1)*".jld2") - append!(boundary_solutions.midpoints,bs[1].midpoints) - append!(boundary_solutions.normal,bs[1].normal) - append!(boundary_solutions.ps_solutions,bs[1].ps_solutions) + append!(boundary_solutions.midpoints, bs[1].midpoints) + append!(boundary_solutions.normal, bs[1].normal) + append!(boundary_solutions.ps_solutions, bs[1].ps_solutions) end -points = [boundary_solutions.midpoints[i][j] for i in eachindex(boundary_solutions.midpoints), j in 1:3] |> permutedims -cells = [KitAMR.MeshCell(KitAMR.VTKCellTypes.VTK_VERTEX,[i]) for i in eachindex(boundary_solutions.midpoints)] -KitAMR.vtk_grid("surf_test",points,cells) do vtk +points = + [ + boundary_solutions.midpoints[i][j] for + i in eachindex(boundary_solutions.midpoints), j = 1:3 + ] |> permutedims +cells = [ + KitAMR.MeshCell(KitAMR.VTKCellTypes.VTK_VERTEX, [i]) for + i in eachindex(boundary_solutions.midpoints) +] +KitAMR.vtk_grid("surf_test", points, cells) do vtk vtk["rho"] = [x.prim[1] for x in boundary_solutions.ps_solutions] vtk["U"] = [x.prim[2] for x in boundary_solutions.ps_solutions] vtk["V"] = [x.prim[3] for x in boundary_solutions.ps_solutions] @@ -20,7 +31,10 @@ KitAMR.vtk_grid("surf_test",points,cells) do vtk vtk["p13"] = [x.p[3] for x in boundary_solutions.ps_solutions] vtk["p22"] = [x.p[4] for x in boundary_solutions.ps_solutions] vtk["p23"] = [x.p[5] for x in boundary_solutions.ps_solutions] - vtk["p33"] = [x.p[6] for x in boundary_solutions.ps_solutions ] - vtk["normal"] = ([x[1] for x in boundary_solutions.normal],[x[2] for x in boundary_solutions.normal], - [x[3] for x in boundary_solutions.normal]) -end \ No newline at end of file + vtk["p33"] = [x.p[6] for x in boundary_solutions.ps_solutions] + vtk["normal"] = ( + [x[1] for x in boundary_solutions.normal], + [x[2] for x in boundary_solutions.normal], + [x[3] for x in boundary_solutions.normal], + ) +end