From 3694ed0555c4dcf77eb0eec6ff1e14988686037d Mon Sep 17 00:00:00 2001 From: Joshua Lampert Date: Fri, 26 Jan 2024 18:16:33 +0100 Subject: [PATCH 1/5] format --- .github/workflows/FormtatCheck.yml | 38 ++ src/P4est.jl | 3 +- src/pointerwrappers.jl | 71 +-- test/configure_packages.jl | 22 +- test/runtests.jl | 42 +- test/test_nested_attributes_2d.jl | 153 +++--- test/test_nested_attributes_3d.jl | 162 +++--- test/test_p4est_balance.jl | 70 ++- test/test_p4est_qcoord_to_vertex.jl | 50 +- test/test_p4est_refine_and_p4est_coarsen.jl | 42 +- test/test_p8est_balance.jl | 91 ++-- test/test_p8est_qcoord_to_vertex.jl | 51 +- test/test_p8est_refine_and_p8est_coarsen.jl | 42 +- test/tests_basic.jl | 545 +++++++++++--------- 14 files changed, 802 insertions(+), 580 deletions(-) create mode 100644 .github/workflows/FormtatCheck.yml diff --git a/.github/workflows/FormtatCheck.yml b/.github/workflows/FormtatCheck.yml new file mode 100644 index 0000000..ba69e40 --- /dev/null +++ b/.github/workflows/FormtatCheck.yml @@ -0,0 +1,38 @@ +name: format-check + +on: + push: + branches: + - 'main' + tags: '*' + pull_request: + +jobs: + check-format: + runs-on: ${{ matrix.os }} + strategy: + matrix: + julia-version: [1] + julia-arch: [x86] + os: [ubuntu-latest] + steps: + - uses: julia-actions/setup-julia@latest + with: + version: ${{ matrix.julia-version }} + + - uses: actions/checkout@v4 + - name: Install JuliaFormatter and format + run: | + julia -e 'using Pkg; Pkg.add(PackageSpec(name = "JuliaFormatter"))' + julia -e 'using JuliaFormatter; format(["src/P4est.jl", "src/pointerwrappers.jl", "test"])' + - name: Format check + run: | + julia -e ' + out = Cmd(`git diff --name-only`) |> read |> String + if out == "" + exit(0) + else + @error "Some files have not been formatted !!!" + write(stdout, out) + exit(1) + end' diff --git a/src/P4est.jl b/src/P4est.jl index c4a0d7f..2c33132 100644 --- a/src/P4est.jl +++ b/src/P4est.jl @@ -109,7 +109,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) diff --git a/src/pointerwrappers.jl b/src/pointerwrappers.jl index 7ecfc39..b256a94 100644 --- a/src/pointerwrappers.jl +++ b/src/pointerwrappers.jl @@ -37,62 +37,73 @@ julia> p4est_pw.connectivity.num_trees[] ``` """ struct PointerWrapper{T} - pointer::Ptr{T} + pointer::Ptr{T} end # Non-pointer-type fields get wrapped as a normal PointerWrapper -PointerWrapper(::Type{T}, pointer) where T = PointerWrapper{T}(pointer) +PointerWrapper(::Type{T}, pointer) where {T} = PointerWrapper{T}(pointer) # Pointer-type fields get dereferenced such that PointerWrapper wraps the pointer to the field type -PointerWrapper(::Type{Ptr{T}}, pointer) where T = PointerWrapper{T}(unsafe_load(Ptr{Ptr{T}}(pointer))) +PointerWrapper(::Type{Ptr{T}}, pointer) where {T} = + PointerWrapper{T}(unsafe_load(Ptr{Ptr{T}}(pointer))) # Cannot use `pw.pointer` since we implement `getproperty` to return the fields of `T` itself -Base.pointer(pw::PointerWrapper{T}) where T = getfield(pw, :pointer) +Base.pointer(pw::PointerWrapper{T}) where {T} = getfield(pw, :pointer) # Allow passing a `PointerWrapper` to wrapped C functions -Base.unsafe_convert(::Type{Ptr{T}}, pw::PointerWrapper{T}) where {T} = Base.unsafe_convert(Ptr{T}, pointer(pw)) +Base.unsafe_convert(::Type{Ptr{T}}, pw::PointerWrapper{T}) where {T} = + Base.unsafe_convert(Ptr{T}, pointer(pw)) # Syntactic sugar -Base.propertynames(::PointerWrapper{T}) where T = fieldnames(T) +Base.propertynames(::PointerWrapper{T}) where {T} = fieldnames(T) # Syntactic sugar: allows one to use `pw.fieldname` to get a PointerWrapper-wrapped pointer to `fieldname` -function Base.getproperty(pw::PointerWrapper{T}, name::Symbol) where T - i = findfirst(isequal(name), fieldnames(T)) - if isnothing(i) - # For some `struct`s, `fieldnames` gives `data` and not the actual field names, but we can use `Base.getproperty` for pointers, - # see https://github.com/trixi-framework/P4est.jl/issues/72 - return PointerWrapper(Base.getproperty(pointer(pw), name)) - end - - return PointerWrapper(fieldtype(T, i), pointer(pw) + fieldoffset(T, i)) +function Base.getproperty(pw::PointerWrapper{T}, name::Symbol) where {T} + i = findfirst(isequal(name), fieldnames(T)) + if isnothing(i) + # For some `struct`s, `fieldnames` gives `data` and not the actual field names, but we can use `Base.getproperty` for pointers, + # see https://github.com/trixi-framework/P4est.jl/issues/72 + return PointerWrapper(Base.getproperty(pointer(pw), name)) + end + + return PointerWrapper(fieldtype(T, i), pointer(pw) + fieldoffset(T, i)) end # Syntactic sugar: allows one to use `pw.fieldname` to set `fieldname` -function Base.setproperty!(pw::PointerWrapper{T}, name::Symbol, v) where T - i = findfirst(isequal(name), fieldnames(T)) - if isnothing(i) - # For some `struct`s, `fieldnames` gives `data` and not the actual field names, but we can use `Base.setproperty!` for pointers, - # 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) +function Base.setproperty!(pw::PointerWrapper{T}, name::Symbol, v) where {T} + i = findfirst(isequal(name), fieldnames(T)) + if isnothing(i) + # For some `struct`s, `fieldnames` gives `data` and not the actual field names, but we can use `Base.setproperty!` for pointers, + # 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, + ) end # `[]` allows one to access the actual underlying data and # `[i]` allows one to access the actual underlying data of an array -Base.getindex(pw::PointerWrapper, i::Integer=1) = unsafe_load(pw, i) -Base.setindex!(pw::PointerWrapper, value, i::Integer=1) = unsafe_store!(pw, value, i) +Base.getindex(pw::PointerWrapper, i::Integer = 1) = unsafe_load(pw, i) +Base.setindex!(pw::PointerWrapper, value, i::Integer = 1) = unsafe_store!(pw, value, i) # When `unsafe_load`ing a PointerWrapper object, we really want to load the underlying object -Base.unsafe_load(pw::PointerWrapper, i::Integer=1) = unsafe_load(pointer(pw), i) +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 -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) +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) # If value is of the wrong type, try to convert it -Base.unsafe_store!(pw::PointerWrapper{T}, value, i::Integer=1) where T = unsafe_store!(pw, convert(T, value), i) +Base.unsafe_store!(pw::PointerWrapper{T}, value, i::Integer = 1) where {T} = + unsafe_store!(pw, convert(T, value), i) # Store value to wrapped location -Base.unsafe_store!(pw::PointerWrapper{T}, value::T, i::Integer=1) where T = unsafe_store!(pointer(pw), value, i) +Base.unsafe_store!(pw::PointerWrapper{T}, value::T, i::Integer = 1) where {T} = + unsafe_store!(pointer(pw), value, i) end diff --git a/test/configure_packages.jl b/test/configure_packages.jl index 7e08413..d64b8b9 100644 --- a/test/configure_packages.jl +++ b/test/configure_packages.jl @@ -19,19 +19,23 @@ rm(joinpath(dirname(@__DIR__), "LocalPreferences.toml"), force = true) # Next, we configure MPI.jl appropriately. @static if JULIA_P4EST_TEST == "P4EST_CUSTOM_MPI_CUSTOM" - import MPIPreferences - MPIPreferences.use_system_binary() + import MPIPreferences + MPIPreferences.use_system_binary() end # Finally, we configure P4est.jl as desired. @static if JULIA_P4EST_TEST == "P4EST_CUSTOM_MPI_CUSTOM" - import UUIDs, Preferences - Preferences.set_preferences!( - UUIDs.UUID("7d669430-f675-4ae7-b43e-fab78ec5a902"), # UUID of P4est.jl - "libp4est" => JULIA_P4EST_TEST_LIBP4EST, force = true) - Preferences.set_preferences!( - UUIDs.UUID("7d669430-f675-4ae7-b43e-fab78ec5a902"), # UUID of P4est.jl - "libsc" => JULIA_P4EST_TEST_LIBSC, force = true) + import UUIDs, Preferences + Preferences.set_preferences!( + UUIDs.UUID("7d669430-f675-4ae7-b43e-fab78ec5a902"), # UUID of P4est.jl + "libp4est" => JULIA_P4EST_TEST_LIBP4EST, + force = true, + ) + Preferences.set_preferences!( + UUIDs.UUID("7d669430-f675-4ae7-b43e-fab78ec5a902"), # UUID of P4est.jl + "libsc" => JULIA_P4EST_TEST_LIBSC, + force = true, + ) end @info "P4est.jl tests configured" JULIA_P4EST_TEST JULIA_P4EST_TEST_LIBP4EST JULIA_P4EST_TEST_LIBSC diff --git a/test/runtests.jl b/test/runtests.jl index c687c7c..770bf93 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -12,28 +12,30 @@ import MPIPreferences @time @testset "P4est.jl tests" begin - # For some weird reason, the MPI tests must come first since they fail - # otherwise with a custom MPI installation. - @time @testset "MPI" begin - # Do a dummy `@test true`: - # If the process errors out the testset would error out as well, - # cf. https://github.com/JuliaParallel/MPI.jl/pull/391 - @test true - - @info "Starting parallel tests" - - mpiexec() do cmd - run(`$cmd -n 2 $(Base.julia_cmd()) --threads=1 --check-bounds=yes --project=$(dirname(@__DIR__)) $(abspath("tests_basic.jl"))`) + # For some weird reason, the MPI tests must come first since they fail + # otherwise with a custom MPI installation. + @time @testset "MPI" begin + # Do a dummy `@test true`: + # If the process errors out the testset would error out as well, + # cf. https://github.com/JuliaParallel/MPI.jl/pull/391 + @test true + + @info "Starting parallel tests" + + mpiexec() do cmd + run( + `$cmd -n 2 $(Base.julia_cmd()) --threads=1 --check-bounds=yes --project=$(dirname(@__DIR__)) $(abspath("tests_basic.jl"))`, + ) + end + + @info "Finished parallel tests" end - @info "Finished parallel tests" - end + @time @testset "serial" begin + @info "Starting serial tests" - @time @testset "serial" begin - @info "Starting serial tests" + include("tests_basic.jl") - include("tests_basic.jl") - - @info "Finished serial tests" - end + @info "Finished serial tests" + end end diff --git a/test/test_nested_attributes_2d.jl b/test/test_nested_attributes_2d.jl index 137399a..aefe0b1 100644 --- a/test/test_nested_attributes_2d.jl +++ b/test/test_nested_attributes_2d.jl @@ -1,90 +1,105 @@ # some auxiliary functions -function unsafe_load_sc(::Type{T}, sc_array::Ptr{sc_array}, i=1) where T - sc_array_obj = unsafe_load(sc_array) - return unsafe_load_sc(T, sc_array_obj, i) +function unsafe_load_sc(::Type{T}, sc_array::Ptr{sc_array}, i = 1) where {T} + sc_array_obj = unsafe_load(sc_array) + return unsafe_load_sc(T, sc_array_obj, i) end -function unsafe_load_sc(::Type{T}, sc_array_obj::sc_array, i=1) where T - element_size = sc_array_obj.elem_size - @assert element_size == sizeof(T) +function unsafe_load_sc(::Type{T}, sc_array_obj::sc_array, i = 1) where {T} + element_size = sc_array_obj.elem_size + @assert element_size == sizeof(T) - return unsafe_load(Ptr{T}(sc_array_obj.array), i) + return unsafe_load(Ptr{T}(sc_array_obj.array), i) end -function unsafe_load_side(info::Ptr{p4est_iter_face_info_t}, i=1) - return unsafe_load_sc(p4est_iter_face_side_t, unsafe_load(info).sides, i) +function unsafe_load_side(info::Ptr{p4est_iter_face_info_t}, i = 1) + return unsafe_load_sc(p4est_iter_face_side_t, unsafe_load(info).sides, i) end function refine_fn(p4est, which_tree, quadrant) - quadrant_obj = unsafe_load(quadrant) - if quadrant_obj.x == 0 && quadrant_obj.y == 0 && quadrant_obj.level < 4 - return Cint(1) - else - return Cint(0) - end + quadrant_obj = unsafe_load(quadrant) + if quadrant_obj.x == 0 && quadrant_obj.y == 0 && quadrant_obj.level < 4 + return Cint(1) + else + return Cint(0) + end end function iter_face(info::Ptr{p4est_iter_face_info_t}, user_data) - @test unsafe_load(info).sides.elem_count isa Integer - if unsafe_load(info).sides.elem_count == 2 - sides = (unsafe_load_side(info, 1), unsafe_load_side(info, 2)) - @test sides[1].is_hanging isa Integer - @test sides[2].is_hanging isa Integer - @test sides[1].is.full.is_ghost isa Integer - @test sides[2].is.full.is_ghost isa Integer - if sides[1].is_hanging == false && sides[2].is_hanging == false # no hanging nodes - if sides[1].is.full.is_ghost == true - remote_side = 1 - local_side = 2 - elseif sides[2].is.full.is_ghost == true - remote_side = 2 - local_side = 1 - else - return nothing - end - # test nested attributes - @test sides[local_side].treeid isa Integer - @test sides[local_side].is.full.quadid isa Integer - @test unsafe_wrap(Array, - unsafe_load(unsafe_load(info).ghost_layer).proc_offsets, - MPI.Comm_size(MPI.COMM_WORLD) + 1) isa Vector{Int32} - @test sides[remote_side].is.full.quadid isa Integer - if local_side == 2 - @test unsafe_load(sides[2].is.full.quad.p.piggy3.local_num) isa Integer - end - else # hanging node - if sides[1].is_hanging == true - hanging_side = 1 - full_side = 2 - else - hanging_side = 2 - full_side = 1 - end - @test sides[hanging_side].is_hanging == true && sides[full_side].is_hanging == false - @test sides[full_side].is.full.is_ghost isa Integer - @test sides[hanging_side].is.hanging.is_ghost isa Tuple{Int8, Int8} - if sides[full_side].is.full.is_ghost == false && all(sides[hanging_side].is.hanging.is_ghost .== false) - return nothing - end + @test unsafe_load(info).sides.elem_count isa Integer + if unsafe_load(info).sides.elem_count == 2 + sides = (unsafe_load_side(info, 1), unsafe_load_side(info, 2)) + @test sides[1].is_hanging isa Integer + @test sides[2].is_hanging isa Integer + @test sides[1].is.full.is_ghost isa Integer + @test sides[2].is.full.is_ghost isa Integer + if sides[1].is_hanging == false && sides[2].is_hanging == false # no hanging nodes + if sides[1].is.full.is_ghost == true + remote_side = 1 + local_side = 2 + elseif sides[2].is.full.is_ghost == true + remote_side = 2 + local_side = 1 + else + return nothing + end + # test nested attributes + @test sides[local_side].treeid isa Integer + @test sides[local_side].is.full.quadid isa Integer + @test unsafe_wrap( + Array, + unsafe_load(unsafe_load(info).ghost_layer).proc_offsets, + MPI.Comm_size(MPI.COMM_WORLD) + 1, + ) isa Vector{Int32} + @test sides[remote_side].is.full.quadid isa Integer + if local_side == 2 + @test unsafe_load(sides[2].is.full.quad.p.piggy3.local_num) isa Integer + end + else # hanging node + if sides[1].is_hanging == true + hanging_side = 1 + full_side = 2 + else + hanging_side = 2 + full_side = 1 + end + @test sides[hanging_side].is_hanging == true && + sides[full_side].is_hanging == false + @test sides[full_side].is.full.is_ghost isa Integer + @test sides[hanging_side].is.hanging.is_ghost isa Tuple{Int8,Int8} + if sides[full_side].is.full.is_ghost == false && + all(sides[hanging_side].is.hanging.is_ghost .== false) + return nothing + end + end end - end - return nothing + return nothing end # This test is based on init_neighbor_rank_connectivity_iter_face_inner from Trixi.jl. # See https://github.com/trixi-framework/Trixi.jl/blob/main/src/solvers/dgsem_p4est/dg_parallel.jl @testset "nested attributes" begin - connectivity = @test_nowarn p4est_connectivity_new_brick(2, 2, 0, 0) - p4est = @test_nowarn p4est_new_ext(MPI.COMM_WORLD, connectivity, 0, 0, true, 0, C_NULL, C_NULL) - refine_fn_c = @cfunction(refine_fn, Cint, - (Ptr{p4est_t}, Ptr{p4est_topidx_t}, Ptr{p4est_quadrant_t})) - p4est_refine(p4est, true, refine_fn_c, C_NULL) - p4est_balance(p4est, P4EST_CONNECT_FACE, C_NULL) + connectivity = @test_nowarn p4est_connectivity_new_brick(2, 2, 0, 0) + p4est = @test_nowarn p4est_new_ext( + MPI.COMM_WORLD, + connectivity, + 0, + 0, + true, + 0, + C_NULL, + C_NULL, + ) + refine_fn_c = @cfunction( + refine_fn, + Cint, + (Ptr{p4est_t}, Ptr{p4est_topidx_t}, Ptr{p4est_quadrant_t}) + ) + p4est_refine(p4est, true, refine_fn_c, C_NULL) + p4est_balance(p4est, P4EST_CONNECT_FACE, C_NULL) - iter_face_c = @cfunction(iter_face, Cvoid, - (Ptr{p4est_iter_face_info_t}, Ptr{Cvoid})) - p4est_iterate(p4est, C_NULL, C_NULL, C_NULL, iter_face_c, C_NULL) - @test_nowarn p4est_destroy(p4est) - @test_nowarn p4est_connectivity_destroy(connectivity) + iter_face_c = @cfunction(iter_face, Cvoid, (Ptr{p4est_iter_face_info_t}, Ptr{Cvoid})) + p4est_iterate(p4est, C_NULL, C_NULL, C_NULL, iter_face_c, C_NULL) + @test_nowarn p4est_destroy(p4est) + @test_nowarn p4est_connectivity_destroy(connectivity) end diff --git a/test/test_nested_attributes_3d.jl b/test/test_nested_attributes_3d.jl index 2227e42..230f9ae 100644 --- a/test/test_nested_attributes_3d.jl +++ b/test/test_nested_attributes_3d.jl @@ -1,90 +1,114 @@ # some auxiliary functions -function unsafe_load_sc(::Type{T}, sc_array::Ptr{sc_array}, i=1) where T - sc_array_obj = unsafe_load(sc_array) - return unsafe_load_sc(T, sc_array_obj, i) +function unsafe_load_sc(::Type{T}, sc_array::Ptr{sc_array}, i = 1) where {T} + sc_array_obj = unsafe_load(sc_array) + return unsafe_load_sc(T, sc_array_obj, i) end -function unsafe_load_sc(::Type{T}, sc_array_obj::sc_array, i=1) where T - element_size = sc_array_obj.elem_size - @assert element_size == sizeof(T) +function unsafe_load_sc(::Type{T}, sc_array_obj::sc_array, i = 1) where {T} + element_size = sc_array_obj.elem_size + @assert element_size == sizeof(T) - return unsafe_load(Ptr{T}(sc_array_obj.array), i) + return unsafe_load(Ptr{T}(sc_array_obj.array), i) end -function unsafe_load_side(info::Ptr{p8est_iter_face_info_t}, i=1) - return unsafe_load_sc(p8est_iter_face_side_t, unsafe_load(info).sides, i) +function unsafe_load_side(info::Ptr{p8est_iter_face_info_t}, i = 1) + return unsafe_load_sc(p8est_iter_face_side_t, unsafe_load(info).sides, i) end function refine_fn(p4est, which_tree, quadrant) - quadrant_obj = unsafe_load(quadrant) - if quadrant_obj.x == 0 && quadrant_obj.y == 0 && quadrant_obj.level < 4 - return Cint(1) - else - return Cint(0) - end + quadrant_obj = unsafe_load(quadrant) + if quadrant_obj.x == 0 && quadrant_obj.y == 0 && quadrant_obj.level < 4 + return Cint(1) + else + return Cint(0) + end end function iter_face(info::Ptr{p8est_iter_face_info_t}, user_data) - @test unsafe_load(info).sides.elem_count isa Integer - if unsafe_load(info).sides.elem_count == 2 - sides = (unsafe_load_side(info, 1), unsafe_load_side(info, 2)) - @test sides[1].is_hanging isa Integer - @test sides[2].is_hanging isa Integer - @test sides[1].is.full.is_ghost isa Integer - @test sides[2].is.full.is_ghost isa Integer - if sides[1].is_hanging == false && sides[2].is_hanging == false # no hanging nodes - if sides[1].is.full.is_ghost == true - remote_side = 1 - local_side = 2 - elseif sides[2].is.full.is_ghost == true - remote_side = 2 - local_side = 1 - else - return nothing - end - # test nested attributes - @test sides[local_side].treeid isa Integer - @test sides[local_side].is.full.quadid isa Integer - @test unsafe_wrap(Array, - unsafe_load(unsafe_load(info).ghost_layer).proc_offsets, - MPI.Comm_size(MPI.COMM_WORLD) + 1) isa Vector{Int32} - @test sides[remote_side].is.full.quadid isa Integer - if local_side == 2 - @test unsafe_load(sides[2].is.full.quad.p.piggy3.local_num) isa Integer - end - else # hanging node - if sides[1].is_hanging == true - hanging_side = 1 - full_side = 2 - else - hanging_side = 2 - full_side = 1 - end - @test sides[hanging_side].is_hanging == true && sides[full_side].is_hanging == false - @test sides[full_side].is.full.is_ghost isa Integer - @test sides[hanging_side].is.hanging.is_ghost isa NTuple{4, Int8} - if sides[full_side].is.full.is_ghost == false && all(sides[hanging_side].is.hanging.is_ghost .== false) - return nothing - end + @test unsafe_load(info).sides.elem_count isa Integer + if unsafe_load(info).sides.elem_count == 2 + sides = (unsafe_load_side(info, 1), unsafe_load_side(info, 2)) + @test sides[1].is_hanging isa Integer + @test sides[2].is_hanging isa Integer + @test sides[1].is.full.is_ghost isa Integer + @test sides[2].is.full.is_ghost isa Integer + if sides[1].is_hanging == false && sides[2].is_hanging == false # no hanging nodes + if sides[1].is.full.is_ghost == true + remote_side = 1 + local_side = 2 + elseif sides[2].is.full.is_ghost == true + remote_side = 2 + local_side = 1 + else + return nothing + end + # test nested attributes + @test sides[local_side].treeid isa Integer + @test sides[local_side].is.full.quadid isa Integer + @test unsafe_wrap( + Array, + unsafe_load(unsafe_load(info).ghost_layer).proc_offsets, + MPI.Comm_size(MPI.COMM_WORLD) + 1, + ) isa Vector{Int32} + @test sides[remote_side].is.full.quadid isa Integer + if local_side == 2 + @test unsafe_load(sides[2].is.full.quad.p.piggy3.local_num) isa Integer + end + else # hanging node + if sides[1].is_hanging == true + hanging_side = 1 + full_side = 2 + else + hanging_side = 2 + full_side = 1 + end + @test sides[hanging_side].is_hanging == true && + sides[full_side].is_hanging == false + @test sides[full_side].is.full.is_ghost isa Integer + @test sides[hanging_side].is.hanging.is_ghost isa NTuple{4,Int8} + if sides[full_side].is.full.is_ghost == false && + all(sides[hanging_side].is.hanging.is_ghost .== false) + return nothing + end + end end - end - return nothing + return nothing end # This test is based on init_neighbor_rank_connectivity_iter_face_inner from Trixi.jl. # See https://github.com/trixi-framework/Trixi.jl/blob/main/src/solvers/dgsem_p4est/dg_parallel.jl @testset "nested attributes" begin - connectivity = @test_nowarn p8est_connectivity_new_brick(2, 2, 2, 0, 0, 0) - p4est = @test_nowarn p8est_new_ext(MPI.COMM_WORLD, connectivity, 0, 0, true, 0, C_NULL, C_NULL) + connectivity = @test_nowarn p8est_connectivity_new_brick(2, 2, 2, 0, 0, 0) + p4est = @test_nowarn p8est_new_ext( + MPI.COMM_WORLD, + connectivity, + 0, + 0, + true, + 0, + C_NULL, + C_NULL, + ) - refine_fn_c = @cfunction(refine_fn, Cint, - (Ptr{p8est_t}, Ptr{p4est_topidx_t}, Ptr{p8est_quadrant_t})) - p8est_refine(p4est, true, refine_fn_c, C_NULL) - p8est_balance(p4est, P8EST_CONNECT_FACE, C_NULL) + refine_fn_c = @cfunction( + refine_fn, + Cint, + (Ptr{p8est_t}, Ptr{p4est_topidx_t}, Ptr{p8est_quadrant_t}) + ) + p8est_refine(p4est, true, refine_fn_c, C_NULL) + p8est_balance(p4est, P8EST_CONNECT_FACE, C_NULL) - iter_face_nested_attributes_c = @cfunction(iter_face, Cvoid, - (Ptr{p8est_iter_face_info_t}, Ptr{Cvoid})) - p8est_iterate(p4est, C_NULL, C_NULL, C_NULL, iter_face_nested_attributes_c, C_NULL, C_NULL) - @test_nowarn p8est_destroy(p4est) - @test_nowarn p8est_connectivity_destroy(connectivity) + iter_face_nested_attributes_c = + @cfunction(iter_face, Cvoid, (Ptr{p8est_iter_face_info_t}, Ptr{Cvoid})) + p8est_iterate( + p4est, + C_NULL, + C_NULL, + C_NULL, + iter_face_nested_attributes_c, + C_NULL, + C_NULL, + ) + @test_nowarn p8est_destroy(p4est) + @test_nowarn p8est_connectivity_destroy(connectivity) end diff --git a/test/test_p4est_balance.jl b/test/test_p4est_balance.jl index d982ba5..9ae482c 100644 --- a/test/test_p4est_balance.jl +++ b/test/test_p4est_balance.jl @@ -1,37 +1,51 @@ # For simplicity this is a simpler refinement function than in the test from `p4est`. function refine_fn_balance(p4est, which_tree, quadrant) - quadrant_obj = unsafe_load(quadrant) - if (which_tree == 2 || which_tree == 3) && quadrant_obj.level < 3 - return Cint(1) - end - return Cint(0) + quadrant_obj = unsafe_load(quadrant) + if (which_tree == 2 || which_tree == 3) && quadrant_obj.level < 3 + return Cint(1) + end + return Cint(0) end # This test is inspired by test/test_balance_type2.c from `p4est` for 2D @testset "p4est_balance" begin - connectivity = @test_nowarn p4est_connectivity_new_star() - p4est = @test_nowarn p4est_new_ext(MPI.COMM_WORLD, connectivity, 0, 0, 0, 0, C_NULL, C_NULL) + connectivity = @test_nowarn p4est_connectivity_new_star() + p4est = + @test_nowarn p4est_new_ext(MPI.COMM_WORLD, connectivity, 0, 0, 0, 0, C_NULL, C_NULL) - refine_fn_balance_c = @cfunction(refine_fn_balance, Cint, - (Ptr{p4est_t}, Ptr{p4est_topidx_t}, Ptr{p4est_quadrant_t})) - @test_nowarn p4est_refine(p4est, 1, refine_fn_balance_c, C_NULL) - # face balance - p4estF = @test_nowarn p4est_copy(p4est, 0) - @test_nowarn p4est_balance(p4estF, P4EST_CONNECT_FACE, C_NULL) - crcF = @test_nowarn p4est_checksum(p4estF) - @test unsafe_load(p4estF).global_num_quadrants == 6 - println("Face balance with ", unsafe_load(p4estF).global_num_quadrants, " quadrants and crc ", crcF) - # corner balance - p4estC = @test_nowarn p4est_copy(p4est, 1) - @test_nowarn p4est_balance(p4estF, P4EST_CONNECT_CORNER, C_NULL) - @test_nowarn p4est_balance(p4estC, P4EST_CONNECT_CORNER, C_NULL) - crcC = @test_nowarn p4est_checksum(p4estC) - @test crcC == p4est_checksum(p4estF) - @test unsafe_load(p4estC).global_num_quadrants == 6 - println("Corner balance with ", unsafe_load(p4estC).global_num_quadrants, " quadrants and crc ", crcC) + refine_fn_balance_c = @cfunction( + refine_fn_balance, + Cint, + (Ptr{p4est_t}, Ptr{p4est_topidx_t}, Ptr{p4est_quadrant_t}) + ) + @test_nowarn p4est_refine(p4est, 1, refine_fn_balance_c, C_NULL) + # face balance + p4estF = @test_nowarn p4est_copy(p4est, 0) + @test_nowarn p4est_balance(p4estF, P4EST_CONNECT_FACE, C_NULL) + crcF = @test_nowarn p4est_checksum(p4estF) + @test unsafe_load(p4estF).global_num_quadrants == 6 + println( + "Face balance with ", + unsafe_load(p4estF).global_num_quadrants, + " quadrants and crc ", + crcF, + ) + # corner balance + p4estC = @test_nowarn p4est_copy(p4est, 1) + @test_nowarn p4est_balance(p4estF, P4EST_CONNECT_CORNER, C_NULL) + @test_nowarn p4est_balance(p4estC, P4EST_CONNECT_CORNER, C_NULL) + crcC = @test_nowarn p4est_checksum(p4estC) + @test crcC == p4est_checksum(p4estF) + @test unsafe_load(p4estC).global_num_quadrants == 6 + println( + "Corner balance with ", + unsafe_load(p4estC).global_num_quadrants, + " quadrants and crc ", + crcC, + ) - @test_nowarn p4est_destroy(p4est) - @test_nowarn p4est_destroy(p4estF) - @test_nowarn p4est_destroy(p4estC) - @test_nowarn p4est_connectivity_destroy(connectivity) + @test_nowarn p4est_destroy(p4est) + @test_nowarn p4est_destroy(p4estF) + @test_nowarn p4est_destroy(p4estC) + @test_nowarn p4est_connectivity_destroy(connectivity) end diff --git a/test/test_p4est_qcoord_to_vertex.jl b/test/test_p4est_qcoord_to_vertex.jl index 8111c6e..2fade2f 100644 --- a/test/test_p4est_qcoord_to_vertex.jl +++ b/test/test_p4est_qcoord_to_vertex.jl @@ -1,20 +1,42 @@ -function iter_volume_for_p4est_qcoord_to_vertex(info::Ptr{p4est_iter_volume_info_t}, user_data) - info_obj = unsafe_load(info) - p4est_obj = unsafe_load(info_obj.p4est) - quad_obj = unsafe_load(info_obj.quad) +function iter_volume_for_p4est_qcoord_to_vertex( + info::Ptr{p4est_iter_volume_info_t}, + user_data, +) + info_obj = unsafe_load(info) + p4est_obj = unsafe_load(info_obj.p4est) + quad_obj = unsafe_load(info_obj.quad) - vxyz = Array{Float64}(undef, 3) - p4est_qcoord_to_vertex(p4est_obj.connectivity, info_obj.treeid, quad_obj.x, quad_obj.y, vxyz) + vxyz = Array{Float64}(undef, 3) + p4est_qcoord_to_vertex( + p4est_obj.connectivity, + info_obj.treeid, + quad_obj.x, + quad_obj.y, + vxyz, + ) - println(vxyz) - return nothing + println(vxyz) + return nothing end @testset "p4est_qcoord_to_vertex" begin - iter_volume_c = @cfunction(iter_volume_for_p4est_qcoord_to_vertex, Cvoid, (Ptr{p4est_iter_volume_info_t}, Ptr{Cvoid})) - connectivity = @test_nowarn p4est_connectivity_new_brick(2, 2, 0, 0) - p4est = @test_nowarn p4est_new_ext(MPI.COMM_WORLD, connectivity, 0, 0, true, 0, C_NULL, C_NULL) - p4est_iterate(p4est, C_NULL, C_NULL, iter_volume_c, C_NULL, C_NULL) - @test_nowarn p4est_destroy(p4est) - @test_nowarn p4est_connectivity_destroy(connectivity) + iter_volume_c = @cfunction( + iter_volume_for_p4est_qcoord_to_vertex, + Cvoid, + (Ptr{p4est_iter_volume_info_t}, Ptr{Cvoid}) + ) + connectivity = @test_nowarn p4est_connectivity_new_brick(2, 2, 0, 0) + p4est = @test_nowarn p4est_new_ext( + MPI.COMM_WORLD, + connectivity, + 0, + 0, + true, + 0, + C_NULL, + C_NULL, + ) + p4est_iterate(p4est, C_NULL, C_NULL, iter_volume_c, C_NULL, C_NULL) + @test_nowarn p4est_destroy(p4est) + @test_nowarn p4est_connectivity_destroy(connectivity) end diff --git a/test/test_p4est_refine_and_p4est_coarsen.jl b/test/test_p4est_refine_and_p4est_coarsen.jl index f466799..119e8c1 100644 --- a/test/test_p4est_refine_and_p4est_coarsen.jl +++ b/test/test_p4est_refine_and_p4est_coarsen.jl @@ -1,27 +1,35 @@ function refine_fn(p4est, which_tree, quadrant) - quadrant_obj = unsafe_load(quadrant) - if quadrant_obj.level < 2 - return Cint(1) - else - return Cint(0) - end + quadrant_obj = unsafe_load(quadrant) + if quadrant_obj.level < 2 + return Cint(1) + else + return Cint(0) + end end function coarsen_fn(p4est, which_tree, quadrants) - return Cint(1) + return Cint(1) end @testset "p4est_refine and p4est_coarsen" begin - connectivity = @test_nowarn p4est_connectivity_new_periodic() - p4est = @test_nowarn p4est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) + connectivity = @test_nowarn p4est_connectivity_new_periodic() + p4est = @test_nowarn p4est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) - refine_fn_c = @cfunction(refine_fn, Cint, (Ptr{p4est_t}, Ptr{p4est_topidx_t}, Ptr{p4est_quadrant_t})) - @test_nowarn p4est_refine(p4est, true, refine_fn_c, C_NULL) - @test unsafe_load(p4est).global_num_quadrants == 16 + refine_fn_c = @cfunction( + refine_fn, + Cint, + (Ptr{p4est_t}, Ptr{p4est_topidx_t}, Ptr{p4est_quadrant_t}) + ) + @test_nowarn p4est_refine(p4est, true, refine_fn_c, C_NULL) + @test unsafe_load(p4est).global_num_quadrants == 16 - coarsen_fn_c = @cfunction(coarsen_fn, Cint, (Ptr{p4est_t}, Ptr{p4est_topidx_t}, Ptr{p4est_quadrant_t})) - @test_nowarn p4est_coarsen(p4est, true, coarsen_fn_c, C_NULL) - @test unsafe_load(p4est).global_num_quadrants == 1 - @test_nowarn p4est_destroy(p4est) - @test_nowarn p4est_connectivity_destroy(connectivity) + coarsen_fn_c = @cfunction( + coarsen_fn, + Cint, + (Ptr{p4est_t}, Ptr{p4est_topidx_t}, Ptr{p4est_quadrant_t}) + ) + @test_nowarn p4est_coarsen(p4est, true, coarsen_fn_c, C_NULL) + @test unsafe_load(p4est).global_num_quadrants == 1 + @test_nowarn p4est_destroy(p4est) + @test_nowarn p4est_connectivity_destroy(connectivity) end diff --git a/test/test_p8est_balance.jl b/test/test_p8est_balance.jl index 267bd90..613e288 100644 --- a/test/test_p8est_balance.jl +++ b/test/test_p8est_balance.jl @@ -1,45 +1,64 @@ # For simplicity this is a simpler refinement function than in the test from `p4est`. function refine_fn_balance(p4est, which_tree, quadrant) - quadrant_obj = unsafe_load(quadrant) - if (which_tree == 2 || which_tree == 3) && quadrant_obj.level < 3 - return Cint(1) - end - return Cint(0) + quadrant_obj = unsafe_load(quadrant) + if (which_tree == 2 || which_tree == 3) && quadrant_obj.level < 3 + return Cint(1) + end + return Cint(0) end # This test is inspired by test/test_balance_type2.c from `p4est` for 3D @testset "p8est_balance" begin - connectivity = @test_nowarn p8est_connectivity_new_rotcubes() - p4est = @test_nowarn p8est_new_ext(MPI.COMM_WORLD, connectivity, 0, 0, 0, 0, C_NULL, C_NULL) + connectivity = @test_nowarn p8est_connectivity_new_rotcubes() + p4est = + @test_nowarn p8est_new_ext(MPI.COMM_WORLD, connectivity, 0, 0, 0, 0, C_NULL, C_NULL) - refine_fn_balance_c = @cfunction(refine_fn_balance, Cint, - (Ptr{p8est_t}, Ptr{p4est_topidx_t}, Ptr{p8est_quadrant_t})) - @test_nowarn p8est_refine(p4est, 1, refine_fn_balance_c, C_NULL) - # face balance - p4estF = @test_nowarn p8est_copy(p4est, 0) - @test_nowarn p8est_balance(p4estF, P8EST_CONNECT_FACE, C_NULL) - crcF = @test_nowarn p8est_checksum(p4estF) - @test unsafe_load(p4estF).global_num_quadrants == 6 - println("Face balance with ", unsafe_load(p4estF).global_num_quadrants, " quadrants and crc ", crcF) - # edge balance - p4estE = @test_nowarn p8est_copy(p4est, 1) - @test_nowarn p8est_balance(p4estF, P8EST_CONNECT_FACE, C_NULL) - @test_nowarn p8est_balance(p4estE, P8EST_CONNECT_FACE, C_NULL) - crcE = @test_nowarn p8est_checksum(p4estE) - @test unsafe_load(p4estE).global_num_quadrants == 6 - println("Edge balance with ", unsafe_load(p4estE).global_num_quadrants, " quadrants and crc ", crcE) - # corner balance - p4estC = @test_nowarn p8est_copy(p4est, 1) - @test_nowarn p8est_balance(p4estF, P8EST_CONNECT_CORNER, C_NULL) - @test_nowarn p8est_balance(p4estC, P8EST_CONNECT_CORNER, C_NULL) - crcC = @test_nowarn p8est_checksum(p4estC) - @test crcC == p8est_checksum(p4estF) - @test unsafe_load(p4estC).global_num_quadrants == 6 - println("Corner balance with ", unsafe_load(p4estC).global_num_quadrants, " quadrants and crc ", crcC) + refine_fn_balance_c = @cfunction( + refine_fn_balance, + Cint, + (Ptr{p8est_t}, Ptr{p4est_topidx_t}, Ptr{p8est_quadrant_t}) + ) + @test_nowarn p8est_refine(p4est, 1, refine_fn_balance_c, C_NULL) + # face balance + p4estF = @test_nowarn p8est_copy(p4est, 0) + @test_nowarn p8est_balance(p4estF, P8EST_CONNECT_FACE, C_NULL) + crcF = @test_nowarn p8est_checksum(p4estF) + @test unsafe_load(p4estF).global_num_quadrants == 6 + println( + "Face balance with ", + unsafe_load(p4estF).global_num_quadrants, + " quadrants and crc ", + crcF, + ) + # edge balance + p4estE = @test_nowarn p8est_copy(p4est, 1) + @test_nowarn p8est_balance(p4estF, P8EST_CONNECT_FACE, C_NULL) + @test_nowarn p8est_balance(p4estE, P8EST_CONNECT_FACE, C_NULL) + crcE = @test_nowarn p8est_checksum(p4estE) + @test unsafe_load(p4estE).global_num_quadrants == 6 + println( + "Edge balance with ", + unsafe_load(p4estE).global_num_quadrants, + " quadrants and crc ", + crcE, + ) + # corner balance + p4estC = @test_nowarn p8est_copy(p4est, 1) + @test_nowarn p8est_balance(p4estF, P8EST_CONNECT_CORNER, C_NULL) + @test_nowarn p8est_balance(p4estC, P8EST_CONNECT_CORNER, C_NULL) + crcC = @test_nowarn p8est_checksum(p4estC) + @test crcC == p8est_checksum(p4estF) + @test unsafe_load(p4estC).global_num_quadrants == 6 + println( + "Corner balance with ", + unsafe_load(p4estC).global_num_quadrants, + " quadrants and crc ", + crcC, + ) - @test_nowarn p8est_destroy(p4est) - @test_nowarn p8est_destroy(p4estF) - @test_nowarn p8est_destroy(p4estE) - @test_nowarn p8est_destroy(p4estC) - @test_nowarn p8est_connectivity_destroy(connectivity) + @test_nowarn p8est_destroy(p4est) + @test_nowarn p8est_destroy(p4estF) + @test_nowarn p8est_destroy(p4estE) + @test_nowarn p8est_destroy(p4estC) + @test_nowarn p8est_connectivity_destroy(connectivity) end diff --git a/test/test_p8est_qcoord_to_vertex.jl b/test/test_p8est_qcoord_to_vertex.jl index 44861f3..c7fa392 100644 --- a/test/test_p8est_qcoord_to_vertex.jl +++ b/test/test_p8est_qcoord_to_vertex.jl @@ -1,20 +1,43 @@ -function iter_volume_for_p8est_qcoord_to_vertex(info::Ptr{p8est_iter_volume_info_t}, user_data) - info_obj = unsafe_load(info) - p4est_obj = unsafe_load(info_obj.p4est) - quad_obj = unsafe_load(info_obj.quad) +function iter_volume_for_p8est_qcoord_to_vertex( + info::Ptr{p8est_iter_volume_info_t}, + user_data, +) + info_obj = unsafe_load(info) + p4est_obj = unsafe_load(info_obj.p4est) + quad_obj = unsafe_load(info_obj.quad) - vxyz = Array{Float64}(undef, 3) - p8est_qcoord_to_vertex(p4est_obj.connectivity, info_obj.treeid, quad_obj.x, quad_obj.y, quad_obj.z, vxyz) + vxyz = Array{Float64}(undef, 3) + p8est_qcoord_to_vertex( + p4est_obj.connectivity, + info_obj.treeid, + quad_obj.x, + quad_obj.y, + quad_obj.z, + vxyz, + ) - println(vxyz) - return nothing + println(vxyz) + return nothing end @testset "p8est_qcoord_to_vertex" begin - iter_volume_c = @cfunction(iter_volume_for_p8est_qcoord_to_vertex, Cvoid, (Ptr{p8est_iter_volume_info_t}, Ptr{Cvoid})) - connectivity = @test_nowarn p8est_connectivity_new_brick(2, 2, 2, 0, 0, 0) - p4est = @test_nowarn p8est_new_ext(MPI.COMM_WORLD, connectivity, 0, 0, true, 0, C_NULL, C_NULL) - p8est_iterate(p4est, C_NULL, C_NULL, iter_volume_c, C_NULL, C_NULL, C_NULL) - @test_nowarn p8est_destroy(p4est) - @test_nowarn p8est_connectivity_destroy(connectivity) + iter_volume_c = @cfunction( + iter_volume_for_p8est_qcoord_to_vertex, + Cvoid, + (Ptr{p8est_iter_volume_info_t}, Ptr{Cvoid}) + ) + connectivity = @test_nowarn p8est_connectivity_new_brick(2, 2, 2, 0, 0, 0) + p4est = @test_nowarn p8est_new_ext( + MPI.COMM_WORLD, + connectivity, + 0, + 0, + true, + 0, + C_NULL, + C_NULL, + ) + p8est_iterate(p4est, C_NULL, C_NULL, iter_volume_c, C_NULL, C_NULL, C_NULL) + @test_nowarn p8est_destroy(p4est) + @test_nowarn p8est_connectivity_destroy(connectivity) end diff --git a/test/test_p8est_refine_and_p8est_coarsen.jl b/test/test_p8est_refine_and_p8est_coarsen.jl index 717855a..7109fa8 100644 --- a/test/test_p8est_refine_and_p8est_coarsen.jl +++ b/test/test_p8est_refine_and_p8est_coarsen.jl @@ -1,27 +1,35 @@ function refine_fn(p4est, which_tree, quadrant) - quadrant_obj = unsafe_load(quadrant) - if quadrant_obj.level < 2 - return Cint(1) - else - return Cint(0) - end + quadrant_obj = unsafe_load(quadrant) + if quadrant_obj.level < 2 + return Cint(1) + else + return Cint(0) + end end function coarsen_fn(p4est, which_tree, quadrants) - return Cint(1) + return Cint(1) end @testset "p8est_refine and p8est_coarsen" begin - connectivity = @test_nowarn p8est_connectivity_new_periodic() - p4est = @test_nowarn p8est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) + connectivity = @test_nowarn p8est_connectivity_new_periodic() + p4est = @test_nowarn p8est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) - refine_fn_c = @cfunction(refine_fn, Cint, (Ptr{p8est_t}, Ptr{p4est_topidx_t}, Ptr{p8est_quadrant_t})) - @test_nowarn p8est_refine(p4est, true, refine_fn_c, C_NULL) - @test unsafe_load(p4est).global_num_quadrants == 64 + refine_fn_c = @cfunction( + refine_fn, + Cint, + (Ptr{p8est_t}, Ptr{p4est_topidx_t}, Ptr{p8est_quadrant_t}) + ) + @test_nowarn p8est_refine(p4est, true, refine_fn_c, C_NULL) + @test unsafe_load(p4est).global_num_quadrants == 64 - coarsen_fn_c = @cfunction(coarsen_fn, Cint, (Ptr{p8est_t}, Ptr{p4est_topidx_t}, Ptr{p8est_quadrant_t})) - @test_nowarn p8est_coarsen(p4est, true, coarsen_fn_c, C_NULL) - @test unsafe_load(p4est).global_num_quadrants == 1 - @test_nowarn p8est_destroy(p4est) - @test_nowarn p8est_connectivity_destroy(connectivity) + coarsen_fn_c = @cfunction( + coarsen_fn, + Cint, + (Ptr{p8est_t}, Ptr{p4est_topidx_t}, Ptr{p8est_quadrant_t}) + ) + @test_nowarn p8est_coarsen(p4est, true, coarsen_fn_c, C_NULL) + @test unsafe_load(p4est).global_num_quadrants == 1 + @test_nowarn p8est_destroy(p4est) + @test_nowarn p8est_connectivity_destroy(connectivity) end diff --git a/test/tests_basic.jl b/test/tests_basic.jl index bd28197..eeae8ea 100644 --- a/test/tests_basic.jl +++ b/test/tests_basic.jl @@ -5,280 +5,313 @@ using MPI: MPI using P4est @testset "basic tests" begin - @test_nowarn MPI.Init() - - @testset "P4est.uses_mpi" begin - @test P4est.uses_mpi() == true - end - - @testset "P4est.init" begin - @test_nowarn P4est.init(C_NULL, SC_LP_DEFAULT) - # calling p4est_init directly a second time would error - @test_nowarn P4est.init(C_NULL, SC_LP_ERROR) - @test_nowarn P4est.init(C_NULL, SC_LP_DEFAULT) - end - - @testset "sc_ functions" begin - @test_nowarn sc_version() - @test_nowarn sc_version_major() - @test_nowarn sc_version_minor() - @test unsafe_load(cglobal((:sc_package_id, P4est.LibP4est.libsc), Cint)) == -1 - end + @test_nowarn MPI.Init() + + @testset "P4est.uses_mpi" begin + @test P4est.uses_mpi() == true + end + + @testset "P4est.init" begin + @test_nowarn P4est.init(C_NULL, SC_LP_DEFAULT) + # calling p4est_init directly a second time would error + @test_nowarn P4est.init(C_NULL, SC_LP_ERROR) + @test_nowarn P4est.init(C_NULL, SC_LP_DEFAULT) + end + + @testset "sc_ functions" begin + @test_nowarn sc_version() + @test_nowarn sc_version_major() + @test_nowarn sc_version_minor() + @test unsafe_load(cglobal((:sc_package_id, P4est.LibP4est.libsc), Cint)) == -1 + end end @testset "PointerWrapper" begin - connectivity = @test_nowarn p4est_connectivity_new_periodic() - connectivity_pw = @test_nowarn PointerWrapper(connectivity) - @test connectivity_pw.num_trees[] isa Integer - @test_nowarn propertynames(connectivity_pw) - - # passing a `PointerWrapper` to a wrapped C function - p4est = @test_nowarn p4est_new(MPI.COMM_WORLD, connectivity_pw, 0, C_NULL, C_NULL) - p4est_pw = @test_nowarn PointerWrapper(p4est) - - # test if changing the underlying data works properly - struct MyStruct - value::Float64 - end - obj = MyStruct(0.0) - ptr = Base.unsafe_convert(Ptr{MyStruct}, Ref(obj)) - pw = PointerWrapper(ptr) - @test pw.value[] == 0.0 - @test_nowarn pw.value[] = 1.0 - @test pw.value[] == 1.0 - @test pw.value[1] == 1.0 - @test_nowarn pw.value[1] = 2.0 - @test pw.value[1] == 2.0 - @test pw.value[] == 2.0 - # using `setproperty!` - @test_nowarn pw.value = 3.0 - @test pw.value[1] == 3.0 - @test pw.value[] == 3.0 - # using `setproperty!` for special `struct`s - # see https://github.com/trixi-framework/P4est.jl/issues/72 and https://github.com/trixi-framework/P4est.jl/issues/79 - @test p4est_pw.global_first_position.level[] == 29 - @test_nowarn p4est_pw.global_first_position.level = 30 - @test p4est_pw.global_first_position.level[] == 30 - @test_nowarn p4est_pw.global_first_position.level = 29 - - # test if we can set the user_pointer - p4est_pw.user_pointer = Ptr{Cvoid}(3) - @test p4est_pw.user_pointer == PointerWrapper(Ptr{Cvoid}(3)) - data = Ref((2,3)) - GC.@preserve data begin - p4est_pw.user_pointer = pointer_from_objref(data) - @test unsafe_pointer_to_objref(pointer(p4est_pw.user_pointer))[] == data[] - p4est_pw.user_pointer = C_NULL - end - - # test if accessing an underlying array works properly - @test p4est_pw.global_first_quadrant[1] isa Integer - @test p4est_pw.global_first_quadrant[2] == unsafe_load(unsafe_load(p4est).global_first_quadrant, 2) - - # test if nested accesses work properly - @test p4est_pw.connectivity isa PointerWrapper{p4est_connectivity} - @test p4est_pw.connectivity.num_trees[] isa Integer - @test p4est_pw.global_first_position.level[] isa Integer - @test p4est_pw.connectivity.num_trees isa PointerWrapper{Int32} - - @test pointer(p4est_pw) isa Ptr{P4est.LibP4est.p4est} - - # `unsafe_wrap`ping a `PointerWrapper` - n_vertices::Int = connectivity_pw.num_vertices[] - # wrapping matrices - vertices_matrix = @test_nowarn unsafe_wrap(Array, connectivity_pw.vertices, (3, n_vertices)) - @test vertices_matrix isa Array{Float64, 2} - @test unsafe_wrap(Array{Float64}, connectivity_pw.vertices, (3, n_vertices)) isa Array{Float64, 2} - @test unsafe_wrap(Array{Float64, 2}, connectivity_pw.vertices, (3, n_vertices)) isa Array{Float64, 2} - - @test size(vertices_matrix) == (3, n_vertices) - @test vertices_matrix[1, 1] == connectivity_pw.vertices[1] == 0.0 - @test_nowarn vertices_matrix[1, 1] = 1.0 - @test vertices_matrix[1, 1] == connectivity_pw.vertices[1] == 1.0 - @test_nowarn connectivity_pw.vertices[1] = 2.0 - @test vertices_matrix[1, 1] == connectivity_pw.vertices[1] == 2.0 - # wrapping vectors - vertices_vector = @test_nowarn unsafe_wrap(Array, connectivity_pw.vertices, 3 * n_vertices) - @test vertices_vector isa Array{Float64, 1} - @test unsafe_wrap(Array{Float64}, connectivity_pw.vertices, 3 * n_vertices) isa Array{Float64, 1} - @test unsafe_wrap(Array{Float64, 1}, connectivity_pw.vertices, 3 * n_vertices) isa Array{Float64, 1} - - @test_nowarn p4est_destroy(p4est_pw) - @test_nowarn p4est_connectivity_destroy(connectivity_pw) + connectivity = @test_nowarn p4est_connectivity_new_periodic() + connectivity_pw = @test_nowarn PointerWrapper(connectivity) + @test connectivity_pw.num_trees[] isa Integer + @test_nowarn propertynames(connectivity_pw) + + # passing a `PointerWrapper` to a wrapped C function + p4est = @test_nowarn p4est_new(MPI.COMM_WORLD, connectivity_pw, 0, C_NULL, C_NULL) + p4est_pw = @test_nowarn PointerWrapper(p4est) + + # test if changing the underlying data works properly + struct MyStruct + value::Float64 + end + obj = MyStruct(0.0) + ptr = Base.unsafe_convert(Ptr{MyStruct}, Ref(obj)) + pw = PointerWrapper(ptr) + @test pw.value[] == 0.0 + @test_nowarn pw.value[] = 1.0 + @test pw.value[] == 1.0 + @test pw.value[1] == 1.0 + @test_nowarn pw.value[1] = 2.0 + @test pw.value[1] == 2.0 + @test pw.value[] == 2.0 + # using `setproperty!` + @test_nowarn pw.value = 3.0 + @test pw.value[1] == 3.0 + @test pw.value[] == 3.0 + # using `setproperty!` for special `struct`s + # see https://github.com/trixi-framework/P4est.jl/issues/72 and https://github.com/trixi-framework/P4est.jl/issues/79 + @test p4est_pw.global_first_position.level[] == 29 + @test_nowarn p4est_pw.global_first_position.level = 30 + @test p4est_pw.global_first_position.level[] == 30 + @test_nowarn p4est_pw.global_first_position.level = 29 + + # test if we can set the user_pointer + p4est_pw.user_pointer = Ptr{Cvoid}(3) + @test p4est_pw.user_pointer == PointerWrapper(Ptr{Cvoid}(3)) + data = Ref((2, 3)) + GC.@preserve data begin + p4est_pw.user_pointer = pointer_from_objref(data) + @test unsafe_pointer_to_objref(pointer(p4est_pw.user_pointer))[] == data[] + p4est_pw.user_pointer = C_NULL + end + + # test if accessing an underlying array works properly + @test p4est_pw.global_first_quadrant[1] isa Integer + @test p4est_pw.global_first_quadrant[2] == + unsafe_load(unsafe_load(p4est).global_first_quadrant, 2) + + # test if nested accesses work properly + @test p4est_pw.connectivity isa PointerWrapper{p4est_connectivity} + @test p4est_pw.connectivity.num_trees[] isa Integer + @test p4est_pw.global_first_position.level[] isa Integer + @test p4est_pw.connectivity.num_trees isa PointerWrapper{Int32} + + @test pointer(p4est_pw) isa Ptr{P4est.LibP4est.p4est} + + # `unsafe_wrap`ping a `PointerWrapper` + n_vertices::Int = connectivity_pw.num_vertices[] + # wrapping matrices + vertices_matrix = + @test_nowarn unsafe_wrap(Array, connectivity_pw.vertices, (3, n_vertices)) + @test vertices_matrix isa Array{Float64,2} + @test unsafe_wrap(Array{Float64}, connectivity_pw.vertices, (3, n_vertices)) isa + Array{Float64,2} + @test unsafe_wrap(Array{Float64,2}, connectivity_pw.vertices, (3, n_vertices)) isa + Array{Float64,2} + + @test size(vertices_matrix) == (3, n_vertices) + @test vertices_matrix[1, 1] == connectivity_pw.vertices[1] == 0.0 + @test_nowarn vertices_matrix[1, 1] = 1.0 + @test vertices_matrix[1, 1] == connectivity_pw.vertices[1] == 1.0 + @test_nowarn connectivity_pw.vertices[1] = 2.0 + @test vertices_matrix[1, 1] == connectivity_pw.vertices[1] == 2.0 + # wrapping vectors + vertices_vector = + @test_nowarn unsafe_wrap(Array, connectivity_pw.vertices, 3 * n_vertices) + @test vertices_vector isa Array{Float64,1} + @test unsafe_wrap(Array{Float64}, connectivity_pw.vertices, 3 * n_vertices) isa + Array{Float64,1} + @test unsafe_wrap(Array{Float64,1}, connectivity_pw.vertices, 3 * n_vertices) isa + Array{Float64,1} + + @test_nowarn p4est_destroy(p4est_pw) + @test_nowarn p4est_connectivity_destroy(connectivity_pw) end @testset "2D tests" begin - @testset "p4est_connectivity_new_periodic" begin - connectivity = @test_nowarn p4est_connectivity_new_periodic() - @test p4est_connectivity_new_periodic() isa Ptr{p4est_connectivity} - @test_nowarn p4est_connectivity_destroy(connectivity) - end + @testset "p4est_connectivity_new_periodic" begin + connectivity = @test_nowarn p4est_connectivity_new_periodic() + @test p4est_connectivity_new_periodic() isa Ptr{p4est_connectivity} + @test_nowarn p4est_connectivity_destroy(connectivity) + end - @testset "p4est_connectivity_is_valid" begin - connectivity = @test_nowarn p4est_connectivity_new_periodic() - @test p4est_connectivity_is_valid(connectivity) == 1 - @test_nowarn p4est_connectivity_destroy(connectivity) - end + @testset "p4est_connectivity_is_valid" begin + connectivity = @test_nowarn p4est_connectivity_new_periodic() + @test p4est_connectivity_is_valid(connectivity) == 1 + @test_nowarn p4est_connectivity_destroy(connectivity) + end - @testset "unsafe_load" begin - connectivity = @test_nowarn p4est_connectivity_new_periodic() - connectivity_obj = unsafe_load(connectivity) - @test connectivity_obj.num_vertices == 4 - @test_nowarn p4est_connectivity_destroy(connectivity) - end + @testset "unsafe_load" begin + connectivity = @test_nowarn p4est_connectivity_new_periodic() + connectivity_obj = unsafe_load(connectivity) + @test connectivity_obj.num_vertices == 4 + @test_nowarn p4est_connectivity_destroy(connectivity) + end - @testset "local_num_quadrants" begin - connectivity = @test_nowarn p4est_connectivity_new_periodic() - p4est = @test_nowarn p4est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) - @test_nowarn Int(unsafe_load(p4est).local_num_quadrants) - end + @testset "local_num_quadrants" begin + connectivity = @test_nowarn p4est_connectivity_new_periodic() + p4est = @test_nowarn p4est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) + @test_nowarn Int(unsafe_load(p4est).local_num_quadrants) + end - @testset "smoke test" begin - connectivity = @test_nowarn p4est_connectivity_new_periodic() - p4est = @test_nowarn p4est_new_ext(MPI.COMM_WORLD, connectivity, 0, 2, 0, 0, C_NULL, C_NULL) - p4est_obj = @test_nowarn unsafe_load(p4est) - @test connectivity == p4est_obj.connectivity + @testset "smoke test" begin + connectivity = @test_nowarn p4est_connectivity_new_periodic() + p4est = @test_nowarn p4est_new_ext( + MPI.COMM_WORLD, + connectivity, + 0, + 2, + 0, + 0, + C_NULL, + C_NULL, + ) + p4est_obj = @test_nowarn unsafe_load(p4est) + @test connectivity == p4est_obj.connectivity + + @test_nowarn MPI.Barrier(MPI.COMM_WORLD) + rank = @test_nowarn MPI.Comm_rank(MPI.COMM_WORLD) + println( + "rank $rank: local/global num quadrants = ", + p4est_obj.local_num_quadrants, + "/", + p4est_obj.global_num_quadrants, + ) + end - @test_nowarn MPI.Barrier(MPI.COMM_WORLD) - rank = @test_nowarn MPI.Comm_rank(MPI.COMM_WORLD) - println("rank $rank: local/global num quadrants = ", - p4est_obj.local_num_quadrants, "/", p4est_obj.global_num_quadrants) - end + @testset "p4est_save and p4est_load" begin + connectivity = @test_nowarn p4est_connectivity_new_periodic() + p4est = @test_nowarn p4est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) + filename = joinpath(@__DIR__, "temp") + @test_nowarn p4est_save(filename, p4est, false) + conn_vec = Vector{Ptr{p4est_connectivity_t}}(undef, 1) + @test_nowarn p4est_load(filename, MPI.COMM_WORLD, 0, 0, C_NULL, pointer(conn_vec)) + try + rm(filename, force = true) + catch e + # On our CI systems with Windows, this sometimes throws an error + # IOError: stat("D:\\a\\P4est.jl\\P4est.jl\\test\\temp"): permission denied (EACCES) + # see, e.g., + # https://github.com/trixi-framework/P4est.jl/actions/runs/3765210932/jobs/6400451653 + if get(ENV, "CI", nothing) == "true" && Sys.iswindows() + @warn "Exception occurred" e + else + throw(e) + end + end + @test_nowarn p4est_destroy(p4est) + @test_nowarn p4est_connectivity_destroy(connectivity) + end - @testset "p4est_save and p4est_load" begin - connectivity = @test_nowarn p4est_connectivity_new_periodic() - p4est = @test_nowarn p4est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) - filename = joinpath(@__DIR__, "temp") - @test_nowarn p4est_save(filename, p4est, false) - conn_vec = Vector{Ptr{p4est_connectivity_t}}(undef, 1) - @test_nowarn p4est_load(filename, MPI.COMM_WORLD, 0, 0, C_NULL, pointer(conn_vec)) - try - rm(filename, force=true) - catch e - # On our CI systems with Windows, this sometimes throws an error - # IOError: stat("D:\\a\\P4est.jl\\P4est.jl\\test\\temp"): permission denied (EACCES) - # see, e.g., - # https://github.com/trixi-framework/P4est.jl/actions/runs/3765210932/jobs/6400451653 - if get(ENV, "CI", nothing) == "true" && Sys.iswindows() - @warn "Exception occurred" e - else - throw(e) - end + @testset "p4est_ghost" begin + connectivity = @test_nowarn p4est_connectivity_new_periodic() + p4est = @test_nowarn p4est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) + ghost_layer = @test_nowarn p4est_ghost_new(p4est, P4EST_CONNECT_FACE) + @test p4est_ghost_is_valid(p4est, ghost_layer) == 1 + @test_nowarn p4est_ghost_destroy(ghost_layer) + @test_nowarn p4est_destroy(p4est) + @test_nowarn p4est_connectivity_destroy(connectivity) end - @test_nowarn p4est_destroy(p4est) - @test_nowarn p4est_connectivity_destroy(connectivity) - end - @testset "p4est_ghost" begin - connectivity = @test_nowarn p4est_connectivity_new_periodic() - p4est = @test_nowarn p4est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) - ghost_layer = @test_nowarn p4est_ghost_new(p4est, P4EST_CONNECT_FACE) - @test p4est_ghost_is_valid(p4est, ghost_layer) == 1 - @test_nowarn p4est_ghost_destroy(ghost_layer) - @test_nowarn p4est_destroy(p4est) - @test_nowarn p4est_connectivity_destroy(connectivity) - end - - @testset "p4est_partition" begin - connectivity = @test_nowarn p4est_connectivity_new_star() - p4est = @test_nowarn p4est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) - @test_nowarn p4est_partition(p4est, 0, C_NULL) - @test_nowarn p4est_destroy(p4est) - @test_nowarn p4est_connectivity_destroy(connectivity) - end - - # Put the tests containing `@cfunction` in separate files to define the corresponding Julia functions locally. - include("test_p4est_qcoord_to_vertex.jl") - include("test_p4est_refine_and_p4est_coarsen.jl") - include("test_p4est_balance.jl") - include("test_nested_attributes_2d.jl") + @testset "p4est_partition" begin + connectivity = @test_nowarn p4est_connectivity_new_star() + p4est = @test_nowarn p4est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) + @test_nowarn p4est_partition(p4est, 0, C_NULL) + @test_nowarn p4est_destroy(p4est) + @test_nowarn p4est_connectivity_destroy(connectivity) + end + + # Put the tests containing `@cfunction` in separate files to define the corresponding Julia functions locally. + include("test_p4est_qcoord_to_vertex.jl") + include("test_p4est_refine_and_p4est_coarsen.jl") + include("test_p4est_balance.jl") + include("test_nested_attributes_2d.jl") end @testset "3D tests" begin - @testset "p8est_connectivity_new_periodic" begin - connectivity = @test_nowarn p8est_connectivity_new_periodic() - @test p8est_connectivity_new_periodic() isa Ptr{p8est_connectivity} - @test_nowarn p4est_connectivity_destroy(connectivity) - end - - @testset "p8est_connectivity_is_valid" begin - connectivity = @test_nowarn p8est_connectivity_new_periodic() - @test p8est_connectivity_is_valid(connectivity) == 1 - @test_nowarn p8est_connectivity_destroy(connectivity) - end - - @testset "unsafe_load" begin - connectivity = @test_nowarn p8est_connectivity_new_periodic() - connectivity_obj = unsafe_load(connectivity) - @test connectivity_obj.num_vertices == 8 - @test_nowarn p8est_connectivity_destroy(connectivity) - end - - @testset "local_num_quadrants" begin - connectivity = @test_nowarn p8est_connectivity_new_periodic() - p4est = @test_nowarn p8est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) - @test_nowarn Int(unsafe_load(p4est).local_num_quadrants) - end - - @testset "smoke test" begin - connectivity = @test_nowarn p8est_connectivity_new_periodic() - p8est = @test_nowarn p8est_new_ext(MPI.COMM_WORLD, connectivity, 0, 2, 0, 0, C_NULL, C_NULL) - p8est_obj = @test_nowarn unsafe_load(p8est) - @test connectivity == p8est_obj.connectivity - - @test_nowarn MPI.Barrier(MPI.COMM_WORLD) - rank = @test_nowarn MPI.Comm_rank(MPI.COMM_WORLD) - println("rank $rank: local/global num quadrants = ", - p8est_obj.local_num_quadrants, "/", p8est_obj.global_num_quadrants) - end - - @testset "p8est_save and p8est_load" begin - connectivity = @test_nowarn p8est_connectivity_new_periodic() - p4est = @test_nowarn p8est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) - filename = joinpath(@__DIR__, "temp") - @test_nowarn p8est_save(filename, p4est, false) - conn_vec = Vector{Ptr{p8est_connectivity_t}}(undef, 1) - @test_nowarn p8est_load(filename, MPI.COMM_WORLD, 0, 0, C_NULL, pointer(conn_vec)) - try - rm(filename, force=true) - catch e - # On our CI systems with Windows, this sometimes throws an error - # IOError: stat("D:\\a\\P4est.jl\\P4est.jl\\test\\temp"): permission denied (EACCES) - # see, e.g., - # https://github.com/trixi-framework/P4est.jl/actions/runs/3765210932/jobs/6400451653 - if get(ENV, "CI", nothing) == "true" && Sys.iswindows() - @warn "Exception occurred" e - else - throw(e) - end + @testset "p8est_connectivity_new_periodic" begin + connectivity = @test_nowarn p8est_connectivity_new_periodic() + @test p8est_connectivity_new_periodic() isa Ptr{p8est_connectivity} + @test_nowarn p4est_connectivity_destroy(connectivity) end - @test_nowarn p8est_destroy(p4est) - @test_nowarn p8est_connectivity_destroy(connectivity) - end - - @testset "p8est_ghost" begin - connectivity = @test_nowarn p8est_connectivity_new_periodic() - p4est = @test_nowarn p8est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) - ghost_layer = @test_nowarn p8est_ghost_new(p4est, P8EST_CONNECT_FACE) - @test p8est_ghost_is_valid(p4est, ghost_layer) == 1 - @test_nowarn p8est_ghost_destroy(ghost_layer) - @test_nowarn p8est_destroy(p4est) - @test_nowarn p8est_connectivity_destroy(connectivity) - end - - @testset "p8est_partition" begin - connectivity = @test_nowarn p8est_connectivity_new_rotcubes() - p4est = @test_nowarn p8est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) - @test_nowarn p8est_partition(p4est, 0, C_NULL) - @test_nowarn p8est_destroy(p4est) - @test_nowarn p8est_connectivity_destroy(connectivity) - end - - # Put the tests containing `@cfunction` in separate files to define the corresponding Julia functions locally. - include("test_p8est_qcoord_to_vertex.jl") - include("test_p8est_refine_and_p8est_coarsen.jl") - include("test_p8est_balance.jl") - include("test_nested_attributes_3d.jl") + + @testset "p8est_connectivity_is_valid" begin + connectivity = @test_nowarn p8est_connectivity_new_periodic() + @test p8est_connectivity_is_valid(connectivity) == 1 + @test_nowarn p8est_connectivity_destroy(connectivity) + end + + @testset "unsafe_load" begin + connectivity = @test_nowarn p8est_connectivity_new_periodic() + connectivity_obj = unsafe_load(connectivity) + @test connectivity_obj.num_vertices == 8 + @test_nowarn p8est_connectivity_destroy(connectivity) + end + + @testset "local_num_quadrants" begin + connectivity = @test_nowarn p8est_connectivity_new_periodic() + p4est = @test_nowarn p8est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) + @test_nowarn Int(unsafe_load(p4est).local_num_quadrants) + end + + @testset "smoke test" begin + connectivity = @test_nowarn p8est_connectivity_new_periodic() + p8est = @test_nowarn p8est_new_ext( + MPI.COMM_WORLD, + connectivity, + 0, + 2, + 0, + 0, + C_NULL, + C_NULL, + ) + p8est_obj = @test_nowarn unsafe_load(p8est) + @test connectivity == p8est_obj.connectivity + + @test_nowarn MPI.Barrier(MPI.COMM_WORLD) + rank = @test_nowarn MPI.Comm_rank(MPI.COMM_WORLD) + println( + "rank $rank: local/global num quadrants = ", + p8est_obj.local_num_quadrants, + "/", + p8est_obj.global_num_quadrants, + ) + end + + @testset "p8est_save and p8est_load" begin + connectivity = @test_nowarn p8est_connectivity_new_periodic() + p4est = @test_nowarn p8est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) + filename = joinpath(@__DIR__, "temp") + @test_nowarn p8est_save(filename, p4est, false) + conn_vec = Vector{Ptr{p8est_connectivity_t}}(undef, 1) + @test_nowarn p8est_load(filename, MPI.COMM_WORLD, 0, 0, C_NULL, pointer(conn_vec)) + try + rm(filename, force = true) + catch e + # On our CI systems with Windows, this sometimes throws an error + # IOError: stat("D:\\a\\P4est.jl\\P4est.jl\\test\\temp"): permission denied (EACCES) + # see, e.g., + # https://github.com/trixi-framework/P4est.jl/actions/runs/3765210932/jobs/6400451653 + if get(ENV, "CI", nothing) == "true" && Sys.iswindows() + @warn "Exception occurred" e + else + throw(e) + end + end + @test_nowarn p8est_destroy(p4est) + @test_nowarn p8est_connectivity_destroy(connectivity) + end + + @testset "p8est_ghost" begin + connectivity = @test_nowarn p8est_connectivity_new_periodic() + p4est = @test_nowarn p8est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) + ghost_layer = @test_nowarn p8est_ghost_new(p4est, P8EST_CONNECT_FACE) + @test p8est_ghost_is_valid(p4est, ghost_layer) == 1 + @test_nowarn p8est_ghost_destroy(ghost_layer) + @test_nowarn p8est_destroy(p4est) + @test_nowarn p8est_connectivity_destroy(connectivity) + end + + @testset "p8est_partition" begin + connectivity = @test_nowarn p8est_connectivity_new_rotcubes() + p4est = @test_nowarn p8est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) + @test_nowarn p8est_partition(p4est, 0, C_NULL) + @test_nowarn p8est_destroy(p4est) + @test_nowarn p8est_connectivity_destroy(connectivity) + end + + # Put the tests containing `@cfunction` in separate files to define the corresponding Julia functions locally. + include("test_p8est_qcoord_to_vertex.jl") + include("test_p8est_refine_and_p8est_coarsen.jl") + include("test_p8est_balance.jl") + include("test_nested_attributes_3d.jl") end From 5fcd3cc8b132f6ce3a51465f5caa9146c17b1351 Mon Sep 17 00:00:00 2001 From: Joshua Lampert Date: Fri, 26 Jan 2024 18:20:38 +0100 Subject: [PATCH 2/5] add .JuliaFormatter.toml --- .JuliaFormatter.toml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .JuliaFormatter.toml diff --git a/.JuliaFormatter.toml b/.JuliaFormatter.toml new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/.JuliaFormatter.toml @@ -0,0 +1 @@ + From 5ff7bec39f0671dfb8fa15b2bc3113a9be8d043c Mon Sep 17 00:00:00 2001 From: Joshua Lampert Date: Fri, 26 Jan 2024 18:22:12 +0100 Subject: [PATCH 3/5] really add .JuliaFormatter.toml --- .JuliaFormatter.toml | 9 ++- src/P4est.jl | 8 +- src/pointerwrappers.jl | 30 ++++---- test/configure_packages.jl | 16 ++-- test/runtests.jl | 5 +- test/test_nested_attributes_2d.jl | 37 ++++------ test/test_nested_attributes_3d.jl | 56 ++++++-------- test/test_p4est_balance.jl | 33 ++++----- test/test_p4est_qcoord_to_vertex.jl | 44 +++++------ test/test_p4est_refine_and_p4est_coarsen.jl | 16 ++-- test/test_p8est_balance.jl | 43 +++++------ test/test_p8est_qcoord_to_vertex.jl | 46 +++++------- test/test_p8est_refine_and_p8est_coarsen.jl | 16 ++-- test/tests_basic.jl | 81 +++++++++------------ 14 files changed, 189 insertions(+), 251 deletions(-) diff --git a/.JuliaFormatter.toml b/.JuliaFormatter.toml index 8d1c8b6..8518d20 100644 --- a/.JuliaFormatter.toml +++ b/.JuliaFormatter.toml @@ -1 +1,8 @@ - +# Use SciML style: https://github.com/SciML/SciMLStyle +style = "sciml" + +# Python style alignment. See https://github.com/domluna/JuliaFormatter.jl/pull/732. +yas_style_nesting = true + +# Align struct fields for better readability of large struct definitions +align_struct_field = true diff --git a/src/P4est.jl b/src/P4est.jl index 2c33132..30551f9 100644 --- a/src/P4est.jl +++ b/src/P4est.jl @@ -11,7 +11,6 @@ using UUIDs: UUID const _PREFERENCE_LIBP4EST = @load_preference("libp4est", "P4est_jll") const _PREFERENCE_LIBSC = @load_preference("libsc", _PREFERENCE_LIBP4EST) - # Include p4est bindings include("LibP4est.jl") @reexport using .LibP4est @@ -20,7 +19,6 @@ include("LibP4est.jl") include("pointerwrappers.jl") @reexport using .PointerWrappers: PointerWrapper - # Higher-level API defined in P4est.jl """ P4est.uses_mpi() @@ -109,8 +107,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) @@ -135,7 +133,6 @@ function init(log_handler, log_threshold) return nothing end - function __init__() # If a system-provided MPI installation with default p4est version is used, we cannot execute `P4est.version()` # because the p4est functions are not available @@ -152,5 +149,4 @@ function __init__() return nothing end - end diff --git a/src/pointerwrappers.jl b/src/pointerwrappers.jl index b256a94..6261de5 100644 --- a/src/pointerwrappers.jl +++ b/src/pointerwrappers.jl @@ -44,14 +44,16 @@ end PointerWrapper(::Type{T}, pointer) where {T} = PointerWrapper{T}(pointer) # Pointer-type fields get dereferenced such that PointerWrapper wraps the pointer to the field type -PointerWrapper(::Type{Ptr{T}}, pointer) where {T} = +function PointerWrapper(::Type{Ptr{T}}, pointer) where {T} PointerWrapper{T}(unsafe_load(Ptr{Ptr{T}}(pointer))) +end # Cannot use `pw.pointer` since we implement `getproperty` to return the fields of `T` itself Base.pointer(pw::PointerWrapper{T}) where {T} = getfield(pw, :pointer) # Allow passing a `PointerWrapper` to wrapped C functions -Base.unsafe_convert(::Type{Ptr{T}}, pw::PointerWrapper{T}) where {T} = +function Base.unsafe_convert(::Type{Ptr{T}}, pw::PointerWrapper{T}) where {T} Base.unsafe_convert(Ptr{T}, pointer(pw)) +end # Syntactic sugar Base.propertynames(::PointerWrapper{T}) where {T} = fieldnames(T) @@ -76,10 +78,8 @@ 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,19 +91,21 @@ 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 -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) +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 # If value is of the wrong type, try to convert it -Base.unsafe_store!(pw::PointerWrapper{T}, value, i::Integer = 1) where {T} = +function Base.unsafe_store!(pw::PointerWrapper{T}, value, i::Integer = 1) where {T} unsafe_store!(pw, convert(T, value), i) +end # Store value to wrapped location -Base.unsafe_store!(pw::PointerWrapper{T}, value::T, i::Integer = 1) where {T} = +function Base.unsafe_store!(pw::PointerWrapper{T}, value::T, i::Integer = 1) where {T} unsafe_store!(pointer(pw), value, i) +end end diff --git a/test/configure_packages.jl b/test/configure_packages.jl index d64b8b9..01d7669 100644 --- a/test/configure_packages.jl +++ b/test/configure_packages.jl @@ -26,16 +26,12 @@ end # Finally, we configure P4est.jl as desired. @static if JULIA_P4EST_TEST == "P4EST_CUSTOM_MPI_CUSTOM" import UUIDs, Preferences - Preferences.set_preferences!( - UUIDs.UUID("7d669430-f675-4ae7-b43e-fab78ec5a902"), # UUID of P4est.jl - "libp4est" => JULIA_P4EST_TEST_LIBP4EST, - force = true, - ) - Preferences.set_preferences!( - UUIDs.UUID("7d669430-f675-4ae7-b43e-fab78ec5a902"), # UUID of P4est.jl - "libsc" => JULIA_P4EST_TEST_LIBSC, - force = true, - ) + Preferences.set_preferences!(UUIDs.UUID("7d669430-f675-4ae7-b43e-fab78ec5a902"), # UUID of P4est.jl + "libp4est" => JULIA_P4EST_TEST_LIBP4EST, + force = true) + Preferences.set_preferences!(UUIDs.UUID("7d669430-f675-4ae7-b43e-fab78ec5a902"), # UUID of P4est.jl + "libsc" => JULIA_P4EST_TEST_LIBSC, + force = true) end @info "P4est.jl tests configured" JULIA_P4EST_TEST JULIA_P4EST_TEST_LIBP4EST JULIA_P4EST_TEST_LIBSC diff --git a/test/runtests.jl b/test/runtests.jl index 770bf93..d97bb1f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -10,7 +10,6 @@ using P4est import MPIPreferences @info "Testing P4est.jl with" MPIPreferences.binary MPIPreferences.abi - @time @testset "P4est.jl tests" begin # For some weird reason, the MPI tests must come first since they fail # otherwise with a custom MPI installation. @@ -23,9 +22,7 @@ import MPIPreferences @info "Starting parallel tests" mpiexec() do cmd - run( - `$cmd -n 2 $(Base.julia_cmd()) --threads=1 --check-bounds=yes --project=$(dirname(@__DIR__)) $(abspath("tests_basic.jl"))`, - ) + run(`$cmd -n 2 $(Base.julia_cmd()) --threads=1 --check-bounds=yes --project=$(dirname(@__DIR__)) $(abspath("tests_basic.jl"))`) end @info "Finished parallel tests" diff --git a/test/test_nested_attributes_2d.jl b/test/test_nested_attributes_2d.jl index aefe0b1..4a15ad6 100644 --- a/test/test_nested_attributes_2d.jl +++ b/test/test_nested_attributes_2d.jl @@ -15,7 +15,6 @@ function unsafe_load_side(info::Ptr{p4est_iter_face_info_t}, i = 1) return unsafe_load_sc(p4est_iter_face_side_t, unsafe_load(info).sides, i) end - function refine_fn(p4est, which_tree, quadrant) quadrant_obj = unsafe_load(quadrant) if quadrant_obj.x == 0 && quadrant_obj.y == 0 && quadrant_obj.level < 4 @@ -46,11 +45,9 @@ function iter_face(info::Ptr{p4est_iter_face_info_t}, user_data) # test nested attributes @test sides[local_side].treeid isa Integer @test sides[local_side].is.full.quadid isa Integer - @test unsafe_wrap( - Array, - unsafe_load(unsafe_load(info).ghost_layer).proc_offsets, - MPI.Comm_size(MPI.COMM_WORLD) + 1, - ) isa Vector{Int32} + @test unsafe_wrap(Array, + unsafe_load(unsafe_load(info).ghost_layer).proc_offsets, + MPI.Comm_size(MPI.COMM_WORLD) + 1) isa Vector{Int32} @test sides[remote_side].is.full.quadid isa Integer if local_side == 2 @test unsafe_load(sides[2].is.full.quad.p.piggy3.local_num) isa Integer @@ -66,7 +63,7 @@ function iter_face(info::Ptr{p4est_iter_face_info_t}, user_data) @test sides[hanging_side].is_hanging == true && sides[full_side].is_hanging == false @test sides[full_side].is.full.is_ghost isa Integer - @test sides[hanging_side].is.hanging.is_ghost isa Tuple{Int8,Int8} + @test sides[hanging_side].is.hanging.is_ghost isa Tuple{Int8, Int8} if sides[full_side].is.full.is_ghost == false && all(sides[hanging_side].is.hanging.is_ghost .== false) return nothing @@ -80,21 +77,17 @@ end # See https://github.com/trixi-framework/Trixi.jl/blob/main/src/solvers/dgsem_p4est/dg_parallel.jl @testset "nested attributes" begin connectivity = @test_nowarn p4est_connectivity_new_brick(2, 2, 0, 0) - p4est = @test_nowarn p4est_new_ext( - MPI.COMM_WORLD, - connectivity, - 0, - 0, - true, - 0, - C_NULL, - C_NULL, - ) - refine_fn_c = @cfunction( - refine_fn, - Cint, - (Ptr{p4est_t}, Ptr{p4est_topidx_t}, Ptr{p4est_quadrant_t}) - ) + p4est = @test_nowarn p4est_new_ext(MPI.COMM_WORLD, + connectivity, + 0, + 0, + true, + 0, + C_NULL, + C_NULL) + refine_fn_c = @cfunction(refine_fn, + Cint, + (Ptr{p4est_t}, Ptr{p4est_topidx_t}, Ptr{p4est_quadrant_t})) p4est_refine(p4est, true, refine_fn_c, C_NULL) p4est_balance(p4est, P4EST_CONNECT_FACE, C_NULL) diff --git a/test/test_nested_attributes_3d.jl b/test/test_nested_attributes_3d.jl index 230f9ae..3eedfbf 100644 --- a/test/test_nested_attributes_3d.jl +++ b/test/test_nested_attributes_3d.jl @@ -45,11 +45,9 @@ function iter_face(info::Ptr{p8est_iter_face_info_t}, user_data) # test nested attributes @test sides[local_side].treeid isa Integer @test sides[local_side].is.full.quadid isa Integer - @test unsafe_wrap( - Array, - unsafe_load(unsafe_load(info).ghost_layer).proc_offsets, - MPI.Comm_size(MPI.COMM_WORLD) + 1, - ) isa Vector{Int32} + @test unsafe_wrap(Array, + unsafe_load(unsafe_load(info).ghost_layer).proc_offsets, + MPI.Comm_size(MPI.COMM_WORLD) + 1) isa Vector{Int32} @test sides[remote_side].is.full.quadid isa Integer if local_side == 2 @test unsafe_load(sides[2].is.full.quad.p.piggy3.local_num) isa Integer @@ -65,7 +63,7 @@ function iter_face(info::Ptr{p8est_iter_face_info_t}, user_data) @test sides[hanging_side].is_hanging == true && sides[full_side].is_hanging == false @test sides[full_side].is.full.is_ghost isa Integer - @test sides[hanging_side].is.hanging.is_ghost isa NTuple{4,Int8} + @test sides[hanging_side].is.hanging.is_ghost isa NTuple{4, Int8} if sides[full_side].is.full.is_ghost == false && all(sides[hanging_side].is.hanging.is_ghost .== false) return nothing @@ -79,36 +77,30 @@ end # See https://github.com/trixi-framework/Trixi.jl/blob/main/src/solvers/dgsem_p4est/dg_parallel.jl @testset "nested attributes" begin connectivity = @test_nowarn p8est_connectivity_new_brick(2, 2, 2, 0, 0, 0) - p4est = @test_nowarn p8est_new_ext( - MPI.COMM_WORLD, - connectivity, - 0, - 0, - true, - 0, - C_NULL, - C_NULL, - ) + p4est = @test_nowarn p8est_new_ext(MPI.COMM_WORLD, + connectivity, + 0, + 0, + true, + 0, + C_NULL, + C_NULL) - refine_fn_c = @cfunction( - refine_fn, - Cint, - (Ptr{p8est_t}, Ptr{p4est_topidx_t}, Ptr{p8est_quadrant_t}) - ) + refine_fn_c = @cfunction(refine_fn, + Cint, + (Ptr{p8est_t}, Ptr{p4est_topidx_t}, Ptr{p8est_quadrant_t})) p8est_refine(p4est, true, refine_fn_c, C_NULL) p8est_balance(p4est, P8EST_CONNECT_FACE, C_NULL) - iter_face_nested_attributes_c = - @cfunction(iter_face, Cvoid, (Ptr{p8est_iter_face_info_t}, Ptr{Cvoid})) - p8est_iterate( - p4est, - C_NULL, - C_NULL, - C_NULL, - iter_face_nested_attributes_c, - C_NULL, - C_NULL, - ) + iter_face_nested_attributes_c = @cfunction(iter_face, Cvoid, + (Ptr{p8est_iter_face_info_t}, Ptr{Cvoid})) + p8est_iterate(p4est, + C_NULL, + C_NULL, + C_NULL, + iter_face_nested_attributes_c, + C_NULL, + C_NULL) @test_nowarn p8est_destroy(p4est) @test_nowarn p8est_connectivity_destroy(connectivity) end diff --git a/test/test_p4est_balance.jl b/test/test_p4est_balance.jl index 9ae482c..10f6981 100644 --- a/test/test_p4est_balance.jl +++ b/test/test_p4est_balance.jl @@ -10,26 +10,23 @@ end # This test is inspired by test/test_balance_type2.c from `p4est` for 2D @testset "p4est_balance" begin connectivity = @test_nowarn p4est_connectivity_new_star() - p4est = - @test_nowarn p4est_new_ext(MPI.COMM_WORLD, connectivity, 0, 0, 0, 0, C_NULL, C_NULL) + p4est = @test_nowarn p4est_new_ext(MPI.COMM_WORLD, connectivity, 0, 0, 0, 0, C_NULL, + C_NULL) - refine_fn_balance_c = @cfunction( - refine_fn_balance, - Cint, - (Ptr{p4est_t}, Ptr{p4est_topidx_t}, Ptr{p4est_quadrant_t}) - ) + refine_fn_balance_c = @cfunction(refine_fn_balance, + Cint, + (Ptr{p4est_t}, Ptr{p4est_topidx_t}, + Ptr{p4est_quadrant_t})) @test_nowarn p4est_refine(p4est, 1, refine_fn_balance_c, C_NULL) # face balance p4estF = @test_nowarn p4est_copy(p4est, 0) @test_nowarn p4est_balance(p4estF, P4EST_CONNECT_FACE, C_NULL) crcF = @test_nowarn p4est_checksum(p4estF) @test unsafe_load(p4estF).global_num_quadrants == 6 - println( - "Face balance with ", - unsafe_load(p4estF).global_num_quadrants, - " quadrants and crc ", - crcF, - ) + println("Face balance with ", + unsafe_load(p4estF).global_num_quadrants, + " quadrants and crc ", + crcF) # corner balance p4estC = @test_nowarn p4est_copy(p4est, 1) @test_nowarn p4est_balance(p4estF, P4EST_CONNECT_CORNER, C_NULL) @@ -37,12 +34,10 @@ end crcC = @test_nowarn p4est_checksum(p4estC) @test crcC == p4est_checksum(p4estF) @test unsafe_load(p4estC).global_num_quadrants == 6 - println( - "Corner balance with ", - unsafe_load(p4estC).global_num_quadrants, - " quadrants and crc ", - crcC, - ) + println("Corner balance with ", + unsafe_load(p4estC).global_num_quadrants, + " quadrants and crc ", + crcC) @test_nowarn p4est_destroy(p4est) @test_nowarn p4est_destroy(p4estF) diff --git a/test/test_p4est_qcoord_to_vertex.jl b/test/test_p4est_qcoord_to_vertex.jl index 2fade2f..6b303ed 100644 --- a/test/test_p4est_qcoord_to_vertex.jl +++ b/test/test_p4est_qcoord_to_vertex.jl @@ -1,41 +1,33 @@ -function iter_volume_for_p4est_qcoord_to_vertex( - info::Ptr{p4est_iter_volume_info_t}, - user_data, -) +function iter_volume_for_p4est_qcoord_to_vertex(info::Ptr{p4est_iter_volume_info_t}, + user_data) info_obj = unsafe_load(info) p4est_obj = unsafe_load(info_obj.p4est) quad_obj = unsafe_load(info_obj.quad) vxyz = Array{Float64}(undef, 3) - p4est_qcoord_to_vertex( - p4est_obj.connectivity, - info_obj.treeid, - quad_obj.x, - quad_obj.y, - vxyz, - ) + p4est_qcoord_to_vertex(p4est_obj.connectivity, + info_obj.treeid, + quad_obj.x, + quad_obj.y, + vxyz) println(vxyz) return nothing end @testset "p4est_qcoord_to_vertex" begin - iter_volume_c = @cfunction( - iter_volume_for_p4est_qcoord_to_vertex, - Cvoid, - (Ptr{p4est_iter_volume_info_t}, Ptr{Cvoid}) - ) + iter_volume_c = @cfunction(iter_volume_for_p4est_qcoord_to_vertex, + Cvoid, + (Ptr{p4est_iter_volume_info_t}, Ptr{Cvoid})) connectivity = @test_nowarn p4est_connectivity_new_brick(2, 2, 0, 0) - p4est = @test_nowarn p4est_new_ext( - MPI.COMM_WORLD, - connectivity, - 0, - 0, - true, - 0, - C_NULL, - C_NULL, - ) + p4est = @test_nowarn p4est_new_ext(MPI.COMM_WORLD, + connectivity, + 0, + 0, + true, + 0, + C_NULL, + C_NULL) p4est_iterate(p4est, C_NULL, C_NULL, iter_volume_c, C_NULL, C_NULL) @test_nowarn p4est_destroy(p4est) @test_nowarn p4est_connectivity_destroy(connectivity) diff --git a/test/test_p4est_refine_and_p4est_coarsen.jl b/test/test_p4est_refine_and_p4est_coarsen.jl index 119e8c1..2a6eafd 100644 --- a/test/test_p4est_refine_and_p4est_coarsen.jl +++ b/test/test_p4est_refine_and_p4est_coarsen.jl @@ -15,19 +15,15 @@ end connectivity = @test_nowarn p4est_connectivity_new_periodic() p4est = @test_nowarn p4est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) - refine_fn_c = @cfunction( - refine_fn, - Cint, - (Ptr{p4est_t}, Ptr{p4est_topidx_t}, Ptr{p4est_quadrant_t}) - ) + refine_fn_c = @cfunction(refine_fn, + Cint, + (Ptr{p4est_t}, Ptr{p4est_topidx_t}, Ptr{p4est_quadrant_t})) @test_nowarn p4est_refine(p4est, true, refine_fn_c, C_NULL) @test unsafe_load(p4est).global_num_quadrants == 16 - coarsen_fn_c = @cfunction( - coarsen_fn, - Cint, - (Ptr{p4est_t}, Ptr{p4est_topidx_t}, Ptr{p4est_quadrant_t}) - ) + coarsen_fn_c = @cfunction(coarsen_fn, + Cint, + (Ptr{p4est_t}, Ptr{p4est_topidx_t}, Ptr{p4est_quadrant_t})) @test_nowarn p4est_coarsen(p4est, true, coarsen_fn_c, C_NULL) @test unsafe_load(p4est).global_num_quadrants == 1 @test_nowarn p4est_destroy(p4est) diff --git a/test/test_p8est_balance.jl b/test/test_p8est_balance.jl index 613e288..9bd647e 100644 --- a/test/test_p8est_balance.jl +++ b/test/test_p8est_balance.jl @@ -10,38 +10,33 @@ end # This test is inspired by test/test_balance_type2.c from `p4est` for 3D @testset "p8est_balance" begin connectivity = @test_nowarn p8est_connectivity_new_rotcubes() - p4est = - @test_nowarn p8est_new_ext(MPI.COMM_WORLD, connectivity, 0, 0, 0, 0, C_NULL, C_NULL) + p4est = @test_nowarn p8est_new_ext(MPI.COMM_WORLD, connectivity, 0, 0, 0, 0, C_NULL, + C_NULL) - refine_fn_balance_c = @cfunction( - refine_fn_balance, - Cint, - (Ptr{p8est_t}, Ptr{p4est_topidx_t}, Ptr{p8est_quadrant_t}) - ) + refine_fn_balance_c = @cfunction(refine_fn_balance, + Cint, + (Ptr{p8est_t}, Ptr{p4est_topidx_t}, + Ptr{p8est_quadrant_t})) @test_nowarn p8est_refine(p4est, 1, refine_fn_balance_c, C_NULL) # face balance p4estF = @test_nowarn p8est_copy(p4est, 0) @test_nowarn p8est_balance(p4estF, P8EST_CONNECT_FACE, C_NULL) crcF = @test_nowarn p8est_checksum(p4estF) @test unsafe_load(p4estF).global_num_quadrants == 6 - println( - "Face balance with ", - unsafe_load(p4estF).global_num_quadrants, - " quadrants and crc ", - crcF, - ) + println("Face balance with ", + unsafe_load(p4estF).global_num_quadrants, + " quadrants and crc ", + crcF) # edge balance p4estE = @test_nowarn p8est_copy(p4est, 1) @test_nowarn p8est_balance(p4estF, P8EST_CONNECT_FACE, C_NULL) @test_nowarn p8est_balance(p4estE, P8EST_CONNECT_FACE, C_NULL) crcE = @test_nowarn p8est_checksum(p4estE) @test unsafe_load(p4estE).global_num_quadrants == 6 - println( - "Edge balance with ", - unsafe_load(p4estE).global_num_quadrants, - " quadrants and crc ", - crcE, - ) + println("Edge balance with ", + unsafe_load(p4estE).global_num_quadrants, + " quadrants and crc ", + crcE) # corner balance p4estC = @test_nowarn p8est_copy(p4est, 1) @test_nowarn p8est_balance(p4estF, P8EST_CONNECT_CORNER, C_NULL) @@ -49,12 +44,10 @@ end crcC = @test_nowarn p8est_checksum(p4estC) @test crcC == p8est_checksum(p4estF) @test unsafe_load(p4estC).global_num_quadrants == 6 - println( - "Corner balance with ", - unsafe_load(p4estC).global_num_quadrants, - " quadrants and crc ", - crcC, - ) + println("Corner balance with ", + unsafe_load(p4estC).global_num_quadrants, + " quadrants and crc ", + crcC) @test_nowarn p8est_destroy(p4est) @test_nowarn p8est_destroy(p4estF) diff --git a/test/test_p8est_qcoord_to_vertex.jl b/test/test_p8est_qcoord_to_vertex.jl index c7fa392..e97d7d1 100644 --- a/test/test_p8est_qcoord_to_vertex.jl +++ b/test/test_p8est_qcoord_to_vertex.jl @@ -1,42 +1,34 @@ -function iter_volume_for_p8est_qcoord_to_vertex( - info::Ptr{p8est_iter_volume_info_t}, - user_data, -) +function iter_volume_for_p8est_qcoord_to_vertex(info::Ptr{p8est_iter_volume_info_t}, + user_data) info_obj = unsafe_load(info) p4est_obj = unsafe_load(info_obj.p4est) quad_obj = unsafe_load(info_obj.quad) vxyz = Array{Float64}(undef, 3) - p8est_qcoord_to_vertex( - p4est_obj.connectivity, - info_obj.treeid, - quad_obj.x, - quad_obj.y, - quad_obj.z, - vxyz, - ) + p8est_qcoord_to_vertex(p4est_obj.connectivity, + info_obj.treeid, + quad_obj.x, + quad_obj.y, + quad_obj.z, + vxyz) println(vxyz) return nothing end @testset "p8est_qcoord_to_vertex" begin - iter_volume_c = @cfunction( - iter_volume_for_p8est_qcoord_to_vertex, - Cvoid, - (Ptr{p8est_iter_volume_info_t}, Ptr{Cvoid}) - ) + iter_volume_c = @cfunction(iter_volume_for_p8est_qcoord_to_vertex, + Cvoid, + (Ptr{p8est_iter_volume_info_t}, Ptr{Cvoid})) connectivity = @test_nowarn p8est_connectivity_new_brick(2, 2, 2, 0, 0, 0) - p4est = @test_nowarn p8est_new_ext( - MPI.COMM_WORLD, - connectivity, - 0, - 0, - true, - 0, - C_NULL, - C_NULL, - ) + p4est = @test_nowarn p8est_new_ext(MPI.COMM_WORLD, + connectivity, + 0, + 0, + true, + 0, + C_NULL, + C_NULL) p8est_iterate(p4est, C_NULL, C_NULL, iter_volume_c, C_NULL, C_NULL, C_NULL) @test_nowarn p8est_destroy(p4est) @test_nowarn p8est_connectivity_destroy(connectivity) diff --git a/test/test_p8est_refine_and_p8est_coarsen.jl b/test/test_p8est_refine_and_p8est_coarsen.jl index 7109fa8..dfbc504 100644 --- a/test/test_p8est_refine_and_p8est_coarsen.jl +++ b/test/test_p8est_refine_and_p8est_coarsen.jl @@ -15,19 +15,15 @@ end connectivity = @test_nowarn p8est_connectivity_new_periodic() p4est = @test_nowarn p8est_new(MPI.COMM_WORLD, connectivity, 0, C_NULL, C_NULL) - refine_fn_c = @cfunction( - refine_fn, - Cint, - (Ptr{p8est_t}, Ptr{p4est_topidx_t}, Ptr{p8est_quadrant_t}) - ) + refine_fn_c = @cfunction(refine_fn, + Cint, + (Ptr{p8est_t}, Ptr{p4est_topidx_t}, Ptr{p8est_quadrant_t})) @test_nowarn p8est_refine(p4est, true, refine_fn_c, C_NULL) @test unsafe_load(p4est).global_num_quadrants == 64 - coarsen_fn_c = @cfunction( - coarsen_fn, - Cint, - (Ptr{p8est_t}, Ptr{p4est_topidx_t}, Ptr{p8est_quadrant_t}) - ) + coarsen_fn_c = @cfunction(coarsen_fn, + Cint, + (Ptr{p8est_t}, Ptr{p4est_topidx_t}, Ptr{p8est_quadrant_t})) @test_nowarn p8est_coarsen(p4est, true, coarsen_fn_c, C_NULL) @test unsafe_load(p4est).global_num_quadrants == 1 @test_nowarn p8est_destroy(p4est) diff --git a/test/tests_basic.jl b/test/tests_basic.jl index eeae8ea..9f24d8e 100644 --- a/test/tests_basic.jl +++ b/test/tests_basic.jl @@ -87,13 +87,13 @@ end # `unsafe_wrap`ping a `PointerWrapper` n_vertices::Int = connectivity_pw.num_vertices[] # wrapping matrices - vertices_matrix = - @test_nowarn unsafe_wrap(Array, connectivity_pw.vertices, (3, n_vertices)) - @test vertices_matrix isa Array{Float64,2} + vertices_matrix = @test_nowarn unsafe_wrap(Array, connectivity_pw.vertices, + (3, n_vertices)) + @test vertices_matrix isa Array{Float64, 2} @test unsafe_wrap(Array{Float64}, connectivity_pw.vertices, (3, n_vertices)) isa - Array{Float64,2} - @test unsafe_wrap(Array{Float64,2}, connectivity_pw.vertices, (3, n_vertices)) isa - Array{Float64,2} + Array{Float64, 2} + @test unsafe_wrap(Array{Float64, 2}, connectivity_pw.vertices, (3, n_vertices)) isa + Array{Float64, 2} @test size(vertices_matrix) == (3, n_vertices) @test vertices_matrix[1, 1] == connectivity_pw.vertices[1] == 0.0 @@ -102,13 +102,13 @@ end @test_nowarn connectivity_pw.vertices[1] = 2.0 @test vertices_matrix[1, 1] == connectivity_pw.vertices[1] == 2.0 # wrapping vectors - vertices_vector = - @test_nowarn unsafe_wrap(Array, connectivity_pw.vertices, 3 * n_vertices) - @test vertices_vector isa Array{Float64,1} + vertices_vector = @test_nowarn unsafe_wrap(Array, connectivity_pw.vertices, + 3 * n_vertices) + @test vertices_vector isa Array{Float64, 1} @test unsafe_wrap(Array{Float64}, connectivity_pw.vertices, 3 * n_vertices) isa - Array{Float64,1} - @test unsafe_wrap(Array{Float64,1}, connectivity_pw.vertices, 3 * n_vertices) isa - Array{Float64,1} + Array{Float64, 1} + @test unsafe_wrap(Array{Float64, 1}, connectivity_pw.vertices, 3 * n_vertices) isa + Array{Float64, 1} @test_nowarn p4est_destroy(p4est_pw) @test_nowarn p4est_connectivity_destroy(connectivity_pw) @@ -142,27 +142,23 @@ end @testset "smoke test" begin connectivity = @test_nowarn p4est_connectivity_new_periodic() - p4est = @test_nowarn p4est_new_ext( - MPI.COMM_WORLD, - connectivity, - 0, - 2, - 0, - 0, - C_NULL, - C_NULL, - ) + p4est = @test_nowarn p4est_new_ext(MPI.COMM_WORLD, + connectivity, + 0, + 2, + 0, + 0, + C_NULL, + C_NULL) p4est_obj = @test_nowarn unsafe_load(p4est) @test connectivity == p4est_obj.connectivity @test_nowarn MPI.Barrier(MPI.COMM_WORLD) rank = @test_nowarn MPI.Comm_rank(MPI.COMM_WORLD) - println( - "rank $rank: local/global num quadrants = ", - p4est_obj.local_num_quadrants, - "/", - p4est_obj.global_num_quadrants, - ) + println("rank $rank: local/global num quadrants = ", + p4est_obj.local_num_quadrants, + "/", + p4est_obj.global_num_quadrants) end @testset "p4est_save and p4est_load" begin @@ -242,27 +238,23 @@ end @testset "smoke test" begin connectivity = @test_nowarn p8est_connectivity_new_periodic() - p8est = @test_nowarn p8est_new_ext( - MPI.COMM_WORLD, - connectivity, - 0, - 2, - 0, - 0, - C_NULL, - C_NULL, - ) + p8est = @test_nowarn p8est_new_ext(MPI.COMM_WORLD, + connectivity, + 0, + 2, + 0, + 0, + C_NULL, + C_NULL) p8est_obj = @test_nowarn unsafe_load(p8est) @test connectivity == p8est_obj.connectivity @test_nowarn MPI.Barrier(MPI.COMM_WORLD) rank = @test_nowarn MPI.Comm_rank(MPI.COMM_WORLD) - println( - "rank $rank: local/global num quadrants = ", - p8est_obj.local_num_quadrants, - "/", - p8est_obj.global_num_quadrants, - ) + println("rank $rank: local/global num quadrants = ", + p8est_obj.local_num_quadrants, + "/", + p8est_obj.global_num_quadrants) end @testset "p8est_save and p8est_load" begin @@ -314,5 +306,4 @@ end include("test_nested_attributes_3d.jl") end - end # module From 037cd63a18dee3bd23d4be931104549cb6a4aaf8 Mon Sep 17 00:00:00 2001 From: Joshua Lampert Date: Sat, 27 Jan 2024 10:30:52 +0100 Subject: [PATCH 4/5] add julia-actions/cache --- .github/workflows/FormtatCheck.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/FormtatCheck.yml b/.github/workflows/FormtatCheck.yml index ba69e40..29f73a7 100644 --- a/.github/workflows/FormtatCheck.yml +++ b/.github/workflows/FormtatCheck.yml @@ -19,8 +19,8 @@ jobs: - uses: julia-actions/setup-julia@latest with: version: ${{ matrix.julia-version }} - - uses: actions/checkout@v4 + - uses: julia-actions/cache@v1 - name: Install JuliaFormatter and format run: | julia -e 'using Pkg; Pkg.add(PackageSpec(name = "JuliaFormatter"))' From 82ff6871f56a5f596351b87eb916462d5ef93e60 Mon Sep 17 00:00:00 2001 From: Joshua Lampert Date: Sat, 27 Jan 2024 10:31:33 +0100 Subject: [PATCH 5/5] fix name of FormatCheck.yml --- .github/workflows/{FormtatCheck.yml => FormatCheck.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{FormtatCheck.yml => FormatCheck.yml} (100%) diff --git a/.github/workflows/FormtatCheck.yml b/.github/workflows/FormatCheck.yml similarity index 100% rename from .github/workflows/FormtatCheck.yml rename to .github/workflows/FormatCheck.yml