Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI test for writing vtk files #81

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions test/forest/test_write_vtk.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This file tests the writing of data to vtk files.
# All t8code eclasses are tested with a basic forest with elements of level 0 to 3.
@testset "test_write_vtk" begin
outdir = "out_test"
isdir(outdir) && rm(outdir, recursive = true)
mkpath(outdir)

for eclass in T8_ECLASS_ZERO:t8_eclass(T8_ECLASS_COUNT - 1)
@testset "eclass $eclass" begin
for level in 0:3
scheme = t8_scheme_new_default_cxx()
cmesh = t8_cmesh_new_hypercube(t8_eclass(eclass), comm, 0, 0, 0)
forest = t8_forest_new_uniform(cmesh, scheme, level, 0, comm)

num_elements = t8_forest_get_local_num_elements(forest)

data = rand(num_elements)

vtk_data = t8_vtk_data_field_t(T8_VTK_SCALAR,
NTuple{8192, Cchar}(rpad("data_1)\0", 8192,
' ')),
pointer(data))

# The number of user defined data fields to write.
num_data = 1

# Write user defined data to vtu file.
write_treeid = 1
write_mpirank = 1
write_level = 1
write_element_id = 1
write_ghosts = 0
file = joinpath(outdir, "data_" * string(eclass) * "_" * string(level))
t8_forest_write_vtk_ext(forest, file, write_treeid, write_mpirank,
write_level, write_element_id, write_ghosts,
0, 0, num_data, Ref(vtk_data))
# TODO: Add MPI barrier
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests fail on one rank because writing the file is not yet finished on the other.

@test isfile(file * ".pvtu")
@test isfile(file * "_0000.vtu")
# TODO: Check file * "0001.vtu" for MPI parallel run
Copy link
Contributor Author

@bennibolm bennibolm Feb 6, 2025

Choose a reason for hiding this comment

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

If wanted, we could also test the file * "_0001.vtu" for the MPI run


t8_forest_unref(Ref(forest))
end
end
end

@test_nowarn rm(outdir, recursive = true)
end
1 change: 1 addition & 0 deletions test/test_all.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ end

@testset "forest" begin
include("forest/test_element_volume.jl")
include("forest/test_write_vtk.jl")
end

end # module
Loading