From acb022077c3cddfe6c683dcc42f1c10a1b7a08f2 Mon Sep 17 00:00:00 2001 From: bbolm Date: Fri, 31 Jan 2025 15:21:32 +0100 Subject: [PATCH 1/5] Add test for vtk writing --- test/forest/test_write_vtk.jl | 41 +++++++++++++++++++++++++++++++++++ test/test_all.jl | 1 + 2 files changed, 42 insertions(+) create mode 100644 test/forest/test_write_vtk.jl diff --git a/test/forest/test_write_vtk.jl b/test/forest/test_write_vtk.jl new file mode 100644 index 0000000..6b074a7 --- /dev/null +++ b/test/forest/test_write_vtk.jl @@ -0,0 +1,41 @@ +# 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" + mkdir(outdir) + for eclass in T8_ECLASS_ZERO:t8_eclass(T8_ECLASS_COUNT - 1) + 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)) + + @test isfile(file * "_0000.vtu") && isfile(file * ".pvtu") + + t8_forest_unref(Ref(forest)) + end + end + + rm(outdir, recursive = true) +end \ No newline at end of file diff --git a/test/test_all.jl b/test/test_all.jl index c093ac3..3add364 100644 --- a/test/test_all.jl +++ b/test/test_all.jl @@ -33,6 +33,7 @@ end @testset "forest" begin include("forest/test_element_volume.jl") + include("forest/test_write_vtk.jl") end end # module From 312471e2d05117f5ecc7dc8a3cf92ce58049a0af Mon Sep 17 00:00:00 2001 From: bbolm Date: Fri, 31 Jan 2025 15:22:31 +0100 Subject: [PATCH 2/5] Add line --- test/forest/test_write_vtk.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/forest/test_write_vtk.jl b/test/forest/test_write_vtk.jl index 6b074a7..155f8bc 100644 --- a/test/forest/test_write_vtk.jl +++ b/test/forest/test_write_vtk.jl @@ -38,4 +38,4 @@ end rm(outdir, recursive = true) -end \ No newline at end of file +end From c6c15d865fc7c2b8197585d593b6f18cf98751b5 Mon Sep 17 00:00:00 2001 From: bbolm Date: Fri, 31 Jan 2025 15:59:07 +0100 Subject: [PATCH 3/5] Adapt removing directory --- test/forest/test_write_vtk.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/forest/test_write_vtk.jl b/test/forest/test_write_vtk.jl index 155f8bc..2a9c7e7 100644 --- a/test/forest/test_write_vtk.jl +++ b/test/forest/test_write_vtk.jl @@ -2,6 +2,7 @@ # 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) mkdir(outdir) for eclass in T8_ECLASS_ZERO:t8_eclass(T8_ECLASS_COUNT - 1) for level in 0:3 @@ -37,5 +38,5 @@ end end - rm(outdir, recursive = true) + @test_nowarn rm(outdir, recursive = true) end From 7165014e87a339f5842535840416ddc2799b6faf Mon Sep 17 00:00:00 2001 From: bbolm Date: Thu, 6 Feb 2025 11:45:12 +0100 Subject: [PATCH 4/5] Adapt test --- test/forest/test_write_vtk.jl | 67 +++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/test/forest/test_write_vtk.jl b/test/forest/test_write_vtk.jl index 2a9c7e7..12e4baf 100644 --- a/test/forest/test_write_vtk.jl +++ b/test/forest/test_write_vtk.jl @@ -3,38 +3,43 @@ @testset "test_write_vtk" begin outdir = "out_test" isdir(outdir) && rm(outdir, recursive = true) - mkdir(outdir) - for eclass in T8_ECLASS_ZERO:t8_eclass(T8_ECLASS_COUNT - 1) - 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)) + mkpath(outdir) - # 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)) - - @test isfile(file * "_0000.vtu") && isfile(file * ".pvtu") - - t8_forest_unref(Ref(forest)) + 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 + @test isfile(file * ".pvtu") + @test isfile(file * "_0000.vtu") + # TODO: Check file * "0001.vtu" for MPI parallel run + + t8_forest_unref(Ref(forest)) + end end end From f6c7157896436d287d8fcf841c8fc031089d3437 Mon Sep 17 00:00:00 2001 From: bbolm Date: Thu, 6 Feb 2025 11:49:45 +0100 Subject: [PATCH 5/5] fmt --- test/forest/test_write_vtk.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/forest/test_write_vtk.jl b/test/forest/test_write_vtk.jl index 12e4baf..210879f 100644 --- a/test/forest/test_write_vtk.jl +++ b/test/forest/test_write_vtk.jl @@ -17,8 +17,9 @@ data = rand(num_elements) vtk_data = t8_vtk_data_field_t(T8_VTK_SCALAR, - NTuple{8192, Cchar}(rpad("data_1)\0", 8192, ' ')), - pointer(data)) + NTuple{8192, Cchar}(rpad("data_1)\0", 8192, + ' ')), + pointer(data)) # The number of user defined data fields to write. num_data = 1