diff --git a/Project.toml b/Project.toml index 4928151..d2bb0cf 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "T8code" uuid = "d0cc0030-9a40-4274-8435-baadcfd54fa1" authors = ["Johannes Markert "] -version = "0.9.1" +version = "0.9.2-DEV" [deps] CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82" diff --git a/examples/t8_step5_element_data.jl b/examples/t8_step5_element_data.jl index 526ecb9..2daf248 100644 --- a/examples/t8_step5_element_data.jl +++ b/examples/t8_step5_element_data.jl @@ -194,9 +194,10 @@ function t8_step5_output_data_to_vtu(forest, element_data, prefix) # WARNING: This code hangs for Julia v1.8.* or older. Use at least Julia v1.9. # For each user defined data field we need one t8_vtk_data_field_t variable. - vtk_data = t8_vtk_data_field_t(T8_VTK_SCALAR, # Set the type of this variable. Since we have one value per element, we pick T8_VTK_SCALAR. - NTuple{8192, Cchar}(rpad("Element volume\0", 8192, ' ')), # The name of the field as should be written to the file. - pointer(element_volumes)) + # We set the type of this variable. Since we have one value per element, we pick + # T8_VTK_SCALAR. + # We also set the name of the field as should be written to the file. + vtk_data = [t8_vtk_data_field_t(T8_VTK_SCALAR, "Element volume", element_volumes)] # To write user defined data, we need to extended output function # t8_forest_vtk_write_file from t8_forest_vtk.h. Despite writin user data, @@ -208,7 +209,7 @@ function t8_step5_output_data_to_vtu(forest, element_data, prefix) write_ghosts = 0 t8_forest_write_vtk_ext(forest, prefix, write_treeid, write_mpirank, write_level, write_element_id, write_ghosts, - 0, 0, num_data, Ref(vtk_data)) + 0, 0, num_data, pointer(vtk_data)) end # The prefix for our output files. @@ -277,11 +278,9 @@ if t8_forest_get_num_ghosts(forest) > 0 end # Output the volume data to vtu. -if !(CI_ON_WINDOWS || CI_ON_MACOS) - t8_step5_output_data_to_vtu(forest, element_data, prefix_forest_with_data) - t8_global_productionf(" [step5] Wrote forest and volume data to %s*.\n", - prefix_forest_with_data) -end +t8_step5_output_data_to_vtu(forest, element_data, prefix_forest_with_data) +t8_global_productionf(" [step5] Wrote forest and volume data to %s*.\n", + prefix_forest_with_data) # # Clean-up. diff --git a/examples/t8_step6_stencil.jl b/examples/t8_step6_stencil.jl index 6d3f338..7dfd462 100644 --- a/examples/t8_step6_stencil.jl +++ b/examples/t8_step6_stencil.jl @@ -338,15 +338,9 @@ function t8_step6_output_data_to_vtu(forest, element_data, prefix) # WARNING: This code hangs for Julia v1.8.* or older. Use at least Julia v1.9. vtk_data = [ - t8_vtk_data_field_t(T8_VTK_SCALAR, - NTuple{8192, Cchar}(rpad("height\0", 8192, ' ')), - pointer(heights)), - t8_vtk_data_field_t(T8_VTK_SCALAR, - NTuple{8192, Cchar}(rpad("schlieren\0", 8192, ' ')), - pointer(schlieren)), - t8_vtk_data_field_t(T8_VTK_SCALAR, - NTuple{8192, Cchar}(rpad("curvature\0", 8192, ' ')), - pointer(curvature)) + t8_vtk_data_field_t(T8_VTK_SCALAR, "height", heights), + t8_vtk_data_field_t(T8_VTK_SCALAR, "schlieren", schlieren), + t8_vtk_data_field_t(T8_VTK_SCALAR, "curvature", curvature) ] # The number of user defined data fields to write. @@ -402,10 +396,8 @@ t8_step6_exchange_ghost_data(forest, element_data) t8_step6_compute_stencil(forest, element_data) # Output the data to vtu files. -if !(CI_ON_WINDOWS || CI_ON_MACOS) - t8_step6_output_data_to_vtu(forest, element_data, prefix_forest_with_data) - t8_global_productionf(" Wrote forest and data to %s*.\n", prefix_forest_with_data) -end +t8_step6_output_data_to_vtu(forest, element_data, prefix_forest_with_data) +t8_global_productionf(" Wrote forest and data to %s*.\n", prefix_forest_with_data) # # Clean-up diff --git a/src/Libt8.jl b/src/Libt8.jl index 1f7aab6..af5f2c0 100644 --- a/src/Libt8.jl +++ b/src/Libt8.jl @@ -12866,9 +12866,9 @@ A data field for VTK output. This struct is used to store data that is written t | type | Describes of which type the data array is | | description | String that describes the data. | """ -struct t8_vtk_data_field_t +struct t8_vtk_data_field_t{BUFSIZ} type::t8_vtk_data_type_t - description::NTuple{8192, Cchar} + description::NTuple{BUFSIZ, Cchar} data::Ptr{Cdouble} end @@ -12880,8 +12880,8 @@ end int t8_forest_write_vtk_ext (t8_forest_t forest, const char *fileprefix, const int write_treeid, const int write_mpirank, const int write_level, const int write_element_id, const int write_ghosts, const int write_curved, int do_not_use_API, const int num_data, t8_vtk_data_field_t *data); ``` """ -function t8_forest_write_vtk_ext(forest, fileprefix, write_treeid, write_mpirank, write_level, write_element_id, write_ghosts, write_curved, do_not_use_API, num_data, data) - @ccall libt8.t8_forest_write_vtk_ext(forest::t8_forest_t, fileprefix::Cstring, write_treeid::Cint, write_mpirank::Cint, write_level::Cint, write_element_id::Cint, write_ghosts::Cint, write_curved::Cint, do_not_use_API::Cint, num_data::Cint, data::Ptr{t8_vtk_data_field_t})::Cint +function t8_forest_write_vtk_ext(forest, fileprefix, write_treeid, write_mpirank, write_level, write_element_id, write_ghosts, write_curved, do_not_use_API, num_data, data::Ptr{DataFieldType}) where DataFieldType + @ccall libt8.t8_forest_write_vtk_ext(forest::t8_forest_t, fileprefix::Cstring, write_treeid::Cint, write_mpirank::Cint, write_level::Cint, write_element_id::Cint, write_ghosts::Cint, write_curved::Cint, do_not_use_API::Cint, num_data::Cint, data::Ptr{DataFieldType})::Cint end """ diff --git a/src/T8code.jl b/src/T8code.jl index 1075d53..9c95496 100644 --- a/src/T8code.jl +++ b/src/T8code.jl @@ -258,6 +258,26 @@ macro T8_ASSERT(q) :($(esc(q)) ? nothing : throw(AssertionError($(string(q))))) end +# platform specific BUFSIZ used in t8_vtk_data_field_t +# TODO: Just a guess! +if Sys.isapple() + const T8_BUFSIZ = 1024 +elseif Sys.iswindows() + const T8_BUFSIZ = 512 +else + const T8_BUFSIZ = 8192 +end + +# convenience constructor +# - adds 0 termination and padding to description string +# - takes pointer of data +function Libt8.t8_vtk_data_field_t(type, description::String, data) + return t8_vtk_data_field_t(type, + NTuple{T8_BUFSIZ, Cchar}(rpad(description * "\0", T8_BUFSIZ, + ' ')), + pointer(data)) +end + function t8_free(ptr) Libt8.sc_free(t8_get_package_id(), ptr) end diff --git a/test/test_all.jl b/test/test_all.jl index cfc21da..db46548 100644 --- a/test/test_all.jl +++ b/test/test_all.jl @@ -12,11 +12,6 @@ MPI.Init() comm = MPI.COMM_WORLD -# Check whether we run CI in the cloud with Windows or Mac, see also -# https://docs.github.com/en/actions/learn-github-actions/environment-variables -CI_ON_WINDOWS = (get(ENV, "GITHUB_ACTIONS", false) == "true") && Sys.iswindows() -CI_ON_MACOS = (get(ENV, "GITHUB_ACTIONS", false) == "true") && Sys.isapple() - @testset "init" begin include("test_init.jl") end diff --git a/test/test_examples.jl b/test/test_examples.jl index 3637113..736c821 100644 --- a/test/test_examples.jl +++ b/test/test_examples.jl @@ -22,11 +22,8 @@ end include("../examples/t8_step4_partition_balance_ghost.jl") end -# Unfortunately, step 5 and step 6 currently crash (1.) in Windows, (2.) in MacOS, -# and (3.) with Julia older than 1.9, see related issues -# https://github.com/DLR-AMR/T8code.jl/issues/26, -# https://github.com/DLR-AMR/T8code.jl/issues/30, -# https://github.com/DLR-AMR/T8code.jl/issues/104. +# Step 5 and step 6 crash with Julia older than 1.9, see related issue +# https://github.com/DLR-AMR/T8code.jl/issues/26 @testset "t8_step5_element_data" begin include("../examples/t8_step5_element_data.jl")