From d0dc4704cdde35265f7f9451de0daed79b5218bb Mon Sep 17 00:00:00 2001 From: Vincent Schmitt <136984538+Vyp3er@users.noreply.github.com> Date: Fri, 17 Jul 2026 10:14:54 +0200 Subject: [PATCH 01/20] Apply suggestion from @lenaploetzke Co-authored-by: lenaploetzke <70579874+lenaploetzke@users.noreply.github.com> --- tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx b/tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx index 8e1bf1bffe..2c8f8e731b 100644 --- a/tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx +++ b/tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx @@ -3,7 +3,7 @@ t8code is a C library to manage a collection (a forest) of multiple connected adaptive space-trees of general element types in parallel. - Copyright (C) 2015 the developers + Copyright (C) 2026 the developers t8code is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by From ca472bddeaf8278c2db9b7413315bb2b03a52e9f Mon Sep 17 00:00:00 2001 From: Schmitt Date: Fri, 17 Jul 2026 10:29:03 +0200 Subject: [PATCH 02/20] Documentation Changes and Renaming --- .../mesh_handle/t8_mesh_step3_adapt_mesh.cxx | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx diff --git a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx new file mode 100644 index 0000000000..6f94aac0cf --- /dev/null +++ b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx @@ -0,0 +1,138 @@ +/* + This file is part of t8code. + t8code is a C library to manage a collection (a forest) of multiple + connected adaptive space-trees of general element types in parallel. + + Copyright (C) 2026 the developers + + t8code is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + t8code is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with t8code; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +/** \file t8_mesh_step3_adapt_mesh.cxx + * This is the same as general/t8_step3_adapt_forest.cxx but using the mesh handle interface instead of the forest + * interface. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* The data that determines the adaptation characteristics of our algorithm. + * In this example we want to adapt in a spherical shape around a given point. */ +struct adapt_data +{ + t8_3D_vec midpoint; /**< midpoint of our sphere. */ + double refine_radius; /**< We refine inside this radius of our sphere.*/ + double coarsen_radius; /**< We coarsen outside this radius of our sphere. */ +}; + +/** The adaption callback function. This will refine elements inside of a given sphere and coarsen the elements + * outside of a given sphere. + * \tparam TMeshClass The mesh handle class. + * \param [in] mesh The mesh that should be adapted. + * \param [in] elements One element or a family of elements to consider for adaptation. + * \param [in] adapt_data The user data to be used during the adaptation process. + * \returns 1 if the first entry in \a elements should be refined, + * -1 if the family of elements should be coarsened, + * 0 else. +*/ +template +int +adapt_callback ([[maybe_unused]] const TMeshClass &mesh, std::span elements, + const adapt_data &adapt_data) +{ + auto element_centroid = elements[0].get_centroid (); + double dist = t8_dist (element_centroid, adapt_data.midpoint); + if (dist < adapt_data.refine_radius) { + return 1; /**< Refine. */ + } /** First check if there is a family, and only if yes coarsen. */ + else if ((elements.size () > 1) && (dist > adapt_data.coarsen_radius)) { + return -1; /**< Coarsen. */ + } + return 0; /**< Do Nothing. */ +} + +/** Build our adapted mesh by transferring the adaption parameters and adapting once with our \ref adapt_callback function. + * \tparam TMeshClass The mesh handle class. + * \param sc_MPI_Comm The MPI Communicator. + * \param level The initial uniform refinement level. + * \returns Unique pointer to the adapted mesh. + */ +template +std::unique_ptr +build_mesh (sc_MPI_Comm comm, int level) +{ + /*Generate a hybrid hypercube, made out of cubes, prisms etc. */ + auto mesh = t8_mesh_handle::handle_hypercube_hybrid_uniform_default (level, comm); + /*Defining the adaption parameters. */ + struct adapt_data adapt_params = { { 0.5, 0.5, 1.0 }, 0.2, 0.4 }; + mesh->set_balance (); + mesh->set_partition (); + /*Adapting once with our adapt_callback function. */ + mesh->set_adapt ( + TMeshClass::template mesh_adapt_callback_wrapper (adapt_callback, adapt_params)); + mesh->set_ghost (); + mesh->commit (); + return mesh; +} + +/** Entry point of the program. */ +int +main (int argc, char **argv) +{ + /*Initialize MPI. This has to happen before we initialize sc or t8code. */ + int mpiret = sc_MPI_Init (&argc, &argv); + /*Error check the MPI return value. */ + SC_CHECK_MPI (mpiret); + /* Initialize the sc library, has to happen before we initialize t8code. */ + sc_init (sc_MPI_COMM_WORLD, 1, 1, NULL, SC_LP_ESSENTIAL); + /* Initialize t8code with log level SC_LP_PRODUCTION. See sc.h for more info on the log levels. */ + t8_init (SC_LP_PRODUCTION); + /* We will use MPI_COMM_WORLD as a communicator. */ + sc_MPI_Comm comm = sc_MPI_COMM_WORLD; + + /* Print a starting message. */ + t8_global_productionf (" [tutorial] \n"); + t8_global_productionf (" [tutorial] Hello, this is the mesh adaptation example of t8code using the mesh handle.\n"); + t8_global_productionf (" [tutorial] In this example we will adapt a mesh in a spherical shape around a given point " + "and write the adapted mesh to a vtu file.\n"); + t8_global_productionf (" [tutorial] \n"); + + using mesh_type = t8_mesh_handle::mesh<>; + + t8_global_productionf (" [tutorial] \n"); + t8_global_productionf (" [tutorial] Creating an adapted mesh.\n"); + t8_global_productionf (" [tutorial] \n"); + /* The initial uniform refinement level. */ + int uniform_level = 3; + /* Building the mesh. */ + auto mesh = build_mesh (comm, uniform_level); + /* Write the mesh to a vtu file. */ + t8_global_productionf (" [tutorial] \n"); + t8_global_productionf (" [tutorial] Writing adapted mesh to vtu file: step3_adapted_mesh.vtu\n"); + t8_global_productionf (" [tutorial] \n"); + t8_mesh_handle::write_mesh_to_vtk (*mesh, "step3_adapted_mesh.vtu"); + + sc_finalize (); + mpiret = sc_MPI_Finalize (); + SC_CHECK_MPI (mpiret); + return 0; +} From 989601173a4e9ebee251f5a0ae430aa5c43268f7 Mon Sep 17 00:00:00 2001 From: Schmitt Date: Mon, 20 Jul 2026 10:24:13 +0200 Subject: [PATCH 03/20] added documentation and comments --- tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx b/tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx index 2c8f8e731b..8e1bf1bffe 100644 --- a/tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx +++ b/tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx @@ -3,7 +3,7 @@ t8code is a C library to manage a collection (a forest) of multiple connected adaptive space-trees of general element types in parallel. - Copyright (C) 2026 the developers + Copyright (C) 2015 the developers t8code is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by From a05095c63e7c93d86f64455ecdd1c742164ed2af Mon Sep 17 00:00:00 2001 From: Schmitt Date: Mon, 20 Jul 2026 10:50:05 +0200 Subject: [PATCH 04/20] Added Scope into main to prevent deletion Error --- tutorials/CMakeLists.txt | 2 +- .../t8_mesh_step3_adapt_forest.cxx | 138 ------------------ .../mesh_handle/t8_mesh_step3_adapt_mesh.cxx | 15 +- 3 files changed, 9 insertions(+), 146 deletions(-) delete mode 100644 tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx diff --git a/tutorials/CMakeLists.txt b/tutorials/CMakeLists.txt index daa0bc8146..667ce7f946 100644 --- a/tutorials/CMakeLists.txt +++ b/tutorials/CMakeLists.txt @@ -86,7 +86,7 @@ if( T8CODE_BUILD_MESH_HANDLE ) endif() if( T8CODE_BUILD_MESH_HANDLE ) - add_mesh_handle_tutorial( NAME t8_mesh_step3_adapt_forest SOURCES mesh_handle/t8_mesh_step3_adapt_forest.cxx ) + add_mesh_handle_tutorial( NAME t8_mesh_step3_adapt_mesh SOURCES mesh_handle/t8_mesh_step3_adapt_mesh.cxx ) endif() if( T8CODE_BUILD_MESH_HANDLE ) diff --git a/tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx b/tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx deleted file mode 100644 index 8e1bf1bffe..0000000000 --- a/tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx +++ /dev/null @@ -1,138 +0,0 @@ -/* - This file is part of t8code. - t8code is a C library to manage a collection (a forest) of multiple - connected adaptive space-trees of general element types in parallel. - - Copyright (C) 2015 the developers - - t8code is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - t8code is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with t8code; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -/** \file t8_mesh_step3_adapt_forest.cxx - * This is the same as general/t8_step3_adapt_forest.cxx but using the mesh handle interface instead of the forest - * interface. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* The data that determines the adaptation characteristics of our algorithm. - * In this example we want to adapt in a spherical shape around a given point. */ -struct adapt_data -{ - std::array midpoint; /**< midpoint of our sphere. */ - double refine_radius; /**< We refine inside this radius of our sphere.*/ - double coarsen_radius; /**< We coarsen outside this radius of our sphere. */ -}; - -/** The adaption callback function. This will refine elements inside of a given sphere and coarsen the elements - * outside of a given sphere. - * \tparam TMeshClass The mesh handle class. - * \param [in] mesh The mesh that should be adapted. - * \param [in] elements One element or a family of elements to consider for adaptation. - * \param [in] adapt_data The user data to be used during the adaptation process. - * \returns 1 if the first entry in \a elements should be refined, - * -1 if the family of elements should be coarsened, - * 0 else. -*/ -template -int -adapt_callback ([[maybe_unused]] const TMeshClass &mesh, std::span elements, - const adapt_data &adapt_data) -{ - auto element_centroid = elements[0].get_centroid (); - double dist = t8_dist (element_centroid, adapt_data.midpoint); - if (dist < adapt_data.refine_radius) { - return 1; // refine - } //first check if there is a family, and only if yes check if we should coarsen. - else if ((elements.size () > 1) && (dist > adapt_data.coarsen_radius)) { - return -1; // coarsen - } - return 0; // do nothing -} - -/** Build our adapted mesh by transferring the adaption parameters and adapting once with our adapt_callback function. - * \tparam TMeshClass The mesh handle class. - * \param sc_MPI_Comm The MPI Communicator. - * \param level The initial uniform refinement level. - * \returns Unique pointer to the adapted mesh. - */ -template -std::unique_ptr -build_mesh (sc_MPI_Comm comm, int level) -{ - /*Generate a hybrid hypercube, made out of cubes, prisms etc. */ - auto mesh = t8_mesh_handle::handle_hypercube_hybrid_uniform_default (level, comm); - /*Defining the adaption parameters. */ - struct adapt_data adapt_params = { { 0.5, 0.5, 1.0 }, 0.2, 0.4 }; - mesh->set_balance (); - mesh->set_partition (); - /*Adapting once with our adapt_callback function. */ - mesh->set_adapt ( - TMeshClass::template mesh_adapt_callback_wrapper (adapt_callback, adapt_params)); - mesh->set_ghost (); - mesh->commit (); - return mesh; -} - -/** Entry point of the program. */ -int -main (int argc, char **argv) -{ - /*Initialize MPI. This has to happen before we initialize sc or t8code. */ - int mpiret = sc_MPI_Init (&argc, &argv); - /*Error check the MPI return value. */ - SC_CHECK_MPI (mpiret); - /* Initialize the sc library, has to happen before we initialize t8code. */ - sc_init (sc_MPI_COMM_WORLD, 1, 1, NULL, SC_LP_ESSENTIAL); - /* Initialize t8code with log level SC_LP_PRODUCTION. See sc.h for more info on the log levels. */ - t8_init (SC_LP_PRODUCTION); - /* We will use MPI_COMM_WORLD as a communicator. */ - sc_MPI_Comm comm = sc_MPI_COMM_WORLD; - - /* Print a starting message. */ - t8_global_productionf (" [tutorial] \n"); - t8_global_productionf (" [tutorial] Hello, this is the mesh adaptation example of t8code using the mesh handle.\n"); - t8_global_productionf (" [tutorial] In this example we will adapt a mesh in a spherical shape around a given point " - "and write the adapted mesh to a vtu file.\n"); - t8_global_productionf (" [tutorial] \n"); - - using mesh_type = t8_mesh_handle::mesh<>; - - t8_global_productionf (" [tutorial] \n"); - t8_global_productionf (" [tutorial] Creating an adapted mesh.\n"); - t8_global_productionf (" [tutorial] \n"); - /* The initial uniform refinement level. */ - int uniform_level = 3; - /* Building the Mesh*/ - auto mesh = build_mesh (comm, uniform_level); - /* Write the mesh to a vtu file. */ - t8_global_productionf (" [tutorial] \n"); - t8_global_productionf (" [tutorial] Writing adapted mesh to vtu file: adapted_mesh.vtu\n"); - t8_global_productionf (" [tutorial] \n"); - t8_mesh_handle::write_mesh_to_vtk (*mesh, "adapted_mesh.vtu"); - - sc_finalize (); - mpiret = sc_MPI_Finalize (); - SC_CHECK_MPI (mpiret); - return 0; -} diff --git a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx index 6f94aac0cf..1dd3fba82a 100644 --- a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx +++ b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx @@ -124,13 +124,14 @@ main (int argc, char **argv) /* The initial uniform refinement level. */ int uniform_level = 3; /* Building the mesh. */ - auto mesh = build_mesh (comm, uniform_level); - /* Write the mesh to a vtu file. */ - t8_global_productionf (" [tutorial] \n"); - t8_global_productionf (" [tutorial] Writing adapted mesh to vtu file: step3_adapted_mesh.vtu\n"); - t8_global_productionf (" [tutorial] \n"); - t8_mesh_handle::write_mesh_to_vtk (*mesh, "step3_adapted_mesh.vtu"); - + { /** Scope to ensure mesh is deleted properly. */ + auto mesh = build_mesh (comm, uniform_level); + /* Write the mesh to a vtu file. */ + t8_global_productionf (" [tutorial] \n"); + t8_global_productionf (" [tutorial] Writing adapted mesh to vtu file: step3_adapted_mesh.vtu\n"); + t8_global_productionf (" [tutorial] \n"); + t8_mesh_handle::write_mesh_to_vtk (*mesh, "step3_adapted_mesh.vtu"); + } sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); From bfe57f823f4ebb12a350f187e853dc636e176119 Mon Sep 17 00:00:00 2001 From: Schmitt Date: Mon, 20 Jul 2026 14:52:36 +0200 Subject: [PATCH 05/20] Integrated Review and cleaned up the comments. --- tutorials/CMakeLists.txt | 6 -- .../mesh_handle/default_adapt_callback.hxx | 87 +++++++++++++++++++ .../mesh_handle/t8_mesh_element_data.cxx | 61 ++++--------- .../mesh_handle/t8_mesh_step3_adapt_mesh.cxx | 69 +++++---------- .../t8_mesh_step4_partition_balance_ghost.cxx | 60 +++---------- 5 files changed, 140 insertions(+), 143 deletions(-) create mode 100644 tutorials/mesh_handle/default_adapt_callback.hxx diff --git a/tutorials/CMakeLists.txt b/tutorials/CMakeLists.txt index 667ce7f946..79d631bbb5 100644 --- a/tutorials/CMakeLists.txt +++ b/tutorials/CMakeLists.txt @@ -83,13 +83,7 @@ copy_tutorial_file (features/t8_features_curved_meshes_generate_cmesh_tri.geo) if( T8CODE_BUILD_MESH_HANDLE ) add_mesh_handle_tutorial( NAME t8_mesh_element_data SOURCES mesh_handle/t8_mesh_element_data.cxx ) -endif() - -if( T8CODE_BUILD_MESH_HANDLE ) add_mesh_handle_tutorial( NAME t8_mesh_step3_adapt_mesh SOURCES mesh_handle/t8_mesh_step3_adapt_mesh.cxx ) -endif() - -if( T8CODE_BUILD_MESH_HANDLE ) add_mesh_handle_tutorial( NAME t8_mesh_step4_partition_balance_ghost SOURCES mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx ) endif() diff --git a/tutorials/mesh_handle/default_adapt_callback.hxx b/tutorials/mesh_handle/default_adapt_callback.hxx new file mode 100644 index 0000000000..090a34f822 --- /dev/null +++ b/tutorials/mesh_handle/default_adapt_callback.hxx @@ -0,0 +1,87 @@ +/* + This file is part of t8code. + t8code is a C library to manage a collection (a forest) of multiple + connected adaptive space-trees of general element types in parallel. + + Copyright (C) 2026 the developers + + t8code is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + t8code is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with t8code; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +/** \file default_adapt_callback.hxx + * This is the default adaptation callback function that can be used to refine and coarsen a mesh in a spherical shape around a given point. + * It is used in step 3, 4 and 5 in the mesh_handle tutorials. + */ + +#ifndef DEFAULT_ADAPT_CALLBACK_HXX +#define DEFAULT_ADAPT_CALLBACK_HXX + +#include /** General t8code header. Always include this. */ + +#include /** General Mesh header. Always needed for mesh_handle code. */ +#include /** t8 vector dataclass. */ +#include +#include + +/* The data that determines the adaptation characteristics of our algorithm. + * In this example we want to adapt in a spherical shape around a given point. */ +struct adapt_data +{ + t8_3D_vec midpoint; /**< midpoint of our sphere. */ + double refine_radius; /**< We refine inside this radius of our sphere.*/ + double coarsen_radius; /**< We coarsen outside this radius of our sphere. */ +}; + +/** + * The default adaptation callback function. + * + * This will refine elements inside of a given sphere and coarsen elements + * outside of a given sphere. + * + * \tparam mesh_type The mesh handle class. + * \param[in] mesh The mesh that should be adapted. + * \param[in] elements One element or a family of elements to consider. + * \param[in] adapt_data The user data used during adaptation. + * + * \return + * 1 if the first element should be refined, + * -1 if the family of elements should be coarsened, + * 0 otherwise. + */ +template +int +default_adapt_callback ([[maybe_unused]] const mesh_type& mesh, + std::span elements, const adapt_data& adapt_data) +{ + auto element_centroid = elements[0].get_centroid (); + + double dist = t8_dist (element_centroid, adapt_data.midpoint); + + if ( + dist + < adapt_data + .refine_radius) { /**< When this if Statement returns true, we are inside the set radius of our "refinement Sphere" of our point and therefor need to refine. */ + return 1; /**< Refine. */ + } + + /** Only coarsen if we actually have a complete family. */ + if ((elements.size () > 1) && (dist > adapt_data.coarsen_radius)) { + return -1; /**< Coarsen. */ + } + + return 0; /**< Do nothing. */ +} + +#endif // DEFAULT_ADAPT_CALLBACK_HXX diff --git a/tutorials/mesh_handle/t8_mesh_element_data.cxx b/tutorials/mesh_handle/t8_mesh_element_data.cxx index 03249f0002..a4dcbdf60f 100644 --- a/tutorials/mesh_handle/t8_mesh_element_data.cxx +++ b/tutorials/mesh_handle/t8_mesh_element_data.cxx @@ -21,18 +21,26 @@ */ /** \file t8_mesh_element_data.cxx - * This is the same as general/t8_step5_element_data.cxx but using the mesh handle interface instead of the forest + * This is step5 of the t8code tutorials. + * Therefor, this is the same as general/t8_step5_element_data.cxx but using the mesh handle interface instead of the forest * interface. + * In the following we will store data in the individual elements of our mesh. + * To do this, we will again create a uniform mesh, which will get adapted as in step4, + * with the difference that we partition, balance and create ghost elements all in the same step. + * After adapting the mesh we will learn how to build a data array and gather data for + * the local elements. Furthermore, we exchange the data values of the ghost elements and + * output the volume data to vtu. */ -#include +#include /** General t8code header. Always include this. */ -#include -#include -#include -#include +#include /** General Mesh header. Always needed for mesh_handle code. */ +#include /** Competence Pack for basic mesh_handle features. Look into tutorials/mesh_handle/t8_mesh_competences for more information. */ +#include /** Wrapper for basic Cmesh to mesh_handle conversions. */ +#include /** Used to export mesh to vtk files. */ #include -#include +#include /** t8 vector dataclass. */ +#include "default_adapt_callback.hxx" /** Default adaption function. */ #include #include @@ -44,41 +52,6 @@ struct data_per_element_type double volume; /**< Volume of the element. */ }; -/** User data type we will pass to the adapt callback. */ -struct user_data -{ - t8_3D_vec midpoint; /**< The midpoint of our sphere. */ - double refine_if_inside_radius; /**< If an element's center is smaller than this value, we refine the element. */ - double coarsen_if_outside_radius; /**< If an element's center is larger this value, we coarsen its family. */ -}; - -/** The adaptation callback function. This will refine elements inside of a given sphere and coarsen the elements - * outside of a given sphere. - * \tparam TMeshClass The mesh handle class. - * \param [in] mesh The mesh that should be adapted. - * \param [in] elements One element or a family of elements to consider for adaptation. - * \param [in] user_data The user data to be used during the adaptation process. - * \return 1 if the first entry in \a elements should be refined, - * -1 if the family \a elements shall be coarsened, - * 0 else. - */ -template -int -adapt_callback ([[maybe_unused]] const TMeshClass &mesh, std::span elements, - const user_data &user_data) -{ - auto element_centroid = elements[0].get_centroid (); - double dist = t8_dist (element_centroid, user_data.midpoint); - if (dist < user_data.refine_if_inside_radius) { - return 1; - } - // Check if we got a family and if yes, if we should coarsen. - if ((elements.size () > 1) && (dist > user_data.coarsen_if_outside_radius)) { - return -1; - } - return 0; -} - /** Build a mesh with initial uniform refinement level \a level which is adapted according to \ref adapt_callback, * partitioned and balanced afterwards, and ghost elements are set. * \tparam TMeshClass The mesh handle class. @@ -91,7 +64,7 @@ std::unique_ptr build_mesh (sc_MPI_Comm comm, int level) { auto mesh_handle = t8_mesh_handle::handle_hypercube_hybrid_uniform_default (level, comm); - struct user_data adapt_data = { + struct adapt_data adapt_params = { { 0.5, 0.5, 1 }, /* Midpoint of the sphere. */ 0.2, /* Refine if inside this radius. */ 0.4 /* Coarsen if outside this radius. */ @@ -100,7 +73,7 @@ build_mesh (sc_MPI_Comm comm, int level) mesh_handle->set_balance (); mesh_handle->set_partition (); mesh_handle->set_adapt ( - TMeshClass::template mesh_adapt_callback_wrapper (adapt_callback, adapt_data)); + TMeshClass::template mesh_adapt_callback_wrapper (&default_adapt_callback, adapt_params)); mesh_handle->set_ghost (); mesh_handle->commit (); return mesh_handle; diff --git a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx index 1dd3fba82a..c8a014cc4d 100644 --- a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx +++ b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx @@ -21,55 +21,32 @@ */ /** \file t8_mesh_step3_adapt_mesh.cxx - * This is the same as general/t8_step3_adapt_forest.cxx but using the mesh handle interface instead of the forest + * This is step3 of the t8code mesh handle tutorials. + * Therefore, this is the same as general/t8_step3_adapt_forest.cxx but using the mesh handle interface instead of the forest * interface. + * After generating a coarse mesh (step1) and building a uniform mesh + * on it (step2), we will now adapt (= refine and coarsen) the mesh + * according to our own criterion. + * + * The geometry (coarse mesh) is again a cube, this time modelled with + * 6 tetrahedra, 6 prisms and 4 cubes. + * We refine an element if its midpoint is within a sphere of given radius + * around the point (0.5, 0.5, 1) and we coarsen outside of a given radius. + * We will use non-recursive refinement, that means that the refinement level + * of any element will change by at most +-1. */ -#include -#include -#include -#include -#include +#include /** General t8code header. Always include this. */ +#include /** General Mesh header. Always needed for mesh_handle code. */ +#include /** Competence Pack for basic mesh_handle features. Look into tutorials/mesh_handle/t8_mesh_competences for more information. */ +#include /** Wrapper for basic Cmesh to mesh_handle conversions. */ +#include /** Used to export mesh to vtk files. */ #include -#include +#include /** t8 vector dataclass. */ +#include "default_adapt_callback.hxx" /** Default adaption function. */ #include #include -/* The data that determines the adaptation characteristics of our algorithm. - * In this example we want to adapt in a spherical shape around a given point. */ -struct adapt_data -{ - t8_3D_vec midpoint; /**< midpoint of our sphere. */ - double refine_radius; /**< We refine inside this radius of our sphere.*/ - double coarsen_radius; /**< We coarsen outside this radius of our sphere. */ -}; - -/** The adaption callback function. This will refine elements inside of a given sphere and coarsen the elements - * outside of a given sphere. - * \tparam TMeshClass The mesh handle class. - * \param [in] mesh The mesh that should be adapted. - * \param [in] elements One element or a family of elements to consider for adaptation. - * \param [in] adapt_data The user data to be used during the adaptation process. - * \returns 1 if the first entry in \a elements should be refined, - * -1 if the family of elements should be coarsened, - * 0 else. -*/ -template -int -adapt_callback ([[maybe_unused]] const TMeshClass &mesh, std::span elements, - const adapt_data &adapt_data) -{ - auto element_centroid = elements[0].get_centroid (); - double dist = t8_dist (element_centroid, adapt_data.midpoint); - if (dist < adapt_data.refine_radius) { - return 1; /**< Refine. */ - } /** First check if there is a family, and only if yes coarsen. */ - else if ((elements.size () > 1) && (dist > adapt_data.coarsen_radius)) { - return -1; /**< Coarsen. */ - } - return 0; /**< Do Nothing. */ -} - /** Build our adapted mesh by transferring the adaption parameters and adapting once with our \ref adapt_callback function. * \tparam TMeshClass The mesh handle class. * \param sc_MPI_Comm The MPI Communicator. @@ -80,15 +57,15 @@ template std::unique_ptr build_mesh (sc_MPI_Comm comm, int level) { - /*Generate a hybrid hypercube, made out of cubes, prisms etc. */ + /* Generate a hybrid hypercube, made out of cubes, prisms etc. */ auto mesh = t8_mesh_handle::handle_hypercube_hybrid_uniform_default (level, comm); - /*Defining the adaption parameters. */ + /* Defining the adaption parameters. */ struct adapt_data adapt_params = { { 0.5, 0.5, 1.0 }, 0.2, 0.4 }; mesh->set_balance (); mesh->set_partition (); - /*Adapting once with our adapt_callback function. */ + /* Adapting once with our adapt_callback function. */ mesh->set_adapt ( - TMeshClass::template mesh_adapt_callback_wrapper (adapt_callback, adapt_params)); + TMeshClass::template mesh_adapt_callback_wrapper (default_adapt_callback, adapt_params)); mesh->set_ghost (); mesh->commit (); return mesh; diff --git a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx index 586b66bff3..9259ef6b7c 100644 --- a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx +++ b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx @@ -21,59 +21,25 @@ */ /** \file t8_mesh_element_data.cxx - * This is the same as general/t8_step4_partition_balance_ghost.cxx but using the mesh handle interface instead of the forest + * This is step4 of the t8code mesh handle tutorials. + * Therefor, this is the same as general/t8_step4_partition_balance_ghost.cxx but using the mesh handle interface instead of the forest * interface. + * After generating a coarse mesh (step1), building a uniform mesh + * on it (step2) and adapting this mesh (step3) + * we will now learn how to control the mesh creation in more detail, + * how to partition and balance a mesh and how to generate a layer of ghost elements. */ -#include -#include -#include -#include +#include /** General t8code header. Always include this. */ +#include /** General Mesh header. Always needed for mesh_handle code. */ +#include /** Used to export mesh to vtk files. */ +#include /** Wrapper for basic Cmesh to mesh_handle conversions. */ #include -#include -#include -#include +#include /** t8 vector dataclass. */ +#include "default_adapt_callback.hxx" /** Default adaption function. */ #include #include -/** (This is the same as in tutorial step 3) - * The data that determines the adaptation characteristics of our algorithm. - * In this example we want to adapt in a spherical shape around a given point. -*/ -struct adapt_data -{ - std::array midpoint; /**< midpoint of our sphere. */ - double refine_radius; /**< We refine inside this radius of our sphere.*/ - double coarsen_radius; /**< We coarsen outside this radius of our sphere. */ -}; - -/** (This is the same as in tutorial step 3) - * The adaption callback function. This will refine elements inside of a given sphere and coarsen the elements - * outside of a given sphere. - * \tparam TMeshClass The mesh handle class. - * \param [in] mesh The mesh that should be adapted. - * \param [in] elements One element or a family of elements to consider for adaptation. - * \param [in] adapt_data The user data to be used during the adaptation process. - * \returns 1 if the first entry in \a elements should be refined, - * -1 if the family of elements should be coarsened, - * 0 else. -*/ -template -int -adapt_callback ([[maybe_unused]] const mesh_type &mesh, std::span elements, - const adapt_data &adapt_data) -{ - auto element_centroid = elements[0].get_centroid (); - double dist = t8_dist (element_centroid, adapt_data.midpoint); - if (dist < adapt_data.refine_radius) { - return 1; // refine - } //first check if there is a family, and only if yes check if we should coarsen. - else if ((elements.size () > 1) && (dist > adapt_data.coarsen_radius)) { - return -1; // coarsen - } - return 0; // do nothing -} - /** Helper function to print the total number of elements in the mesh after each step. * \param mesh The mesh handle to get the number of elements from. * \param stage The stage of the mesh (e.g. "Initial mesh", "Adapted mesh", etc.) to print in the output. @@ -158,7 +124,7 @@ main (int argc, char **argv) /* Adapting the mesh once with our adapt_callback function from step 3 and the parameters defined above. */ mesh_adapt->set_adapt ( - mesh_type::template mesh_adapt_callback_wrapper (&adapt_callback, adapt_params)); + mesh_type::template mesh_adapt_callback_wrapper (&default_adapt_callback, adapt_params)); /* Committing the adapted mesh. */ mesh_adapt->commit (); From b79b1d6227586b8605362aeba36aa16facd90a5f Mon Sep 17 00:00:00 2001 From: Schmitt Date: Mon, 20 Jul 2026 16:40:42 +0200 Subject: [PATCH 06/20] Adapted to comments. --- .../mesh_handle/t8_mesh_element_data.cxx | 4 ++-- .../mesh_handle/t8_mesh_step3_adapt_mesh.cxx | 4 ++-- .../t8_mesh_step4_partition_balance_ghost.cxx | 4 ++-- ...lback.hxx => t8_mesh_tutorials_common.hxx} | 23 +++++++------------ 4 files changed, 14 insertions(+), 21 deletions(-) rename tutorials/mesh_handle/{default_adapt_callback.hxx => t8_mesh_tutorials_common.hxx} (80%) diff --git a/tutorials/mesh_handle/t8_mesh_element_data.cxx b/tutorials/mesh_handle/t8_mesh_element_data.cxx index a4dcbdf60f..1bc8161d85 100644 --- a/tutorials/mesh_handle/t8_mesh_element_data.cxx +++ b/tutorials/mesh_handle/t8_mesh_element_data.cxx @@ -39,8 +39,8 @@ #include /** Wrapper for basic Cmesh to mesh_handle conversions. */ #include /** Used to export mesh to vtk files. */ #include -#include /** t8 vector dataclass. */ -#include "default_adapt_callback.hxx" /** Default adaption function. */ +#include /** t8 vector dataclass. */ +#include "t8_mesh_tutorials_common.hxx" /** Default adaption function. */ #include #include diff --git a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx index c8a014cc4d..026988d85c 100644 --- a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx +++ b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx @@ -42,8 +42,8 @@ #include /** Wrapper for basic Cmesh to mesh_handle conversions. */ #include /** Used to export mesh to vtk files. */ #include -#include /** t8 vector dataclass. */ -#include "default_adapt_callback.hxx" /** Default adaption function. */ +#include /** t8 vector dataclass. */ +#include "t8_mesh_tutorials_common.hxx" /** Default adaption function. */ #include #include diff --git a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx index 9259ef6b7c..4569d3b514 100644 --- a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx +++ b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx @@ -35,8 +35,8 @@ #include /** Used to export mesh to vtk files. */ #include /** Wrapper for basic Cmesh to mesh_handle conversions. */ #include -#include /** t8 vector dataclass. */ -#include "default_adapt_callback.hxx" /** Default adaption function. */ +#include /** t8 vector dataclass. */ +#include "t8_mesh_tutorials_common.hxx" /** Default adaption function. */ #include #include diff --git a/tutorials/mesh_handle/default_adapt_callback.hxx b/tutorials/mesh_handle/t8_mesh_tutorials_common.hxx similarity index 80% rename from tutorials/mesh_handle/default_adapt_callback.hxx rename to tutorials/mesh_handle/t8_mesh_tutorials_common.hxx index 090a34f822..0ce7605756 100644 --- a/tutorials/mesh_handle/default_adapt_callback.hxx +++ b/tutorials/mesh_handle/t8_mesh_tutorials_common.hxx @@ -25,17 +25,15 @@ * It is used in step 3, 4 and 5 in the mesh_handle tutorials. */ -#ifndef DEFAULT_ADAPT_CALLBACK_HXX -#define DEFAULT_ADAPT_CALLBACK_HXX +#pragma once #include /** General t8code header. Always include this. */ -#include /** General Mesh header. Always needed for mesh_handle code. */ -#include /** t8 vector dataclass. */ +#include /** Mesh concepts header. */ +#include /** t8 vector dataclass. */ #include -#include -/* The data that determines the adaptation characteristics of our algorithm. +/** The data that determines the adaptation characteristics of our algorithm. * In this example we want to adapt in a spherical shape around a given point. */ struct adapt_data { @@ -45,7 +43,7 @@ struct adapt_data }; /** - * The default adaptation callback function. + * Exemplary adaption callback function for the mesh handle. * * This will refine elements inside of a given sphere and coarsen elements * outside of a given sphere. @@ -68,12 +66,9 @@ default_adapt_callback ([[maybe_unused]] const mesh_type& mesh, auto element_centroid = elements[0].get_centroid (); double dist = t8_dist (element_centroid, adapt_data.midpoint); - - if ( - dist - < adapt_data - .refine_radius) { /**< When this if Statement returns true, we are inside the set radius of our "refinement Sphere" of our point and therefor need to refine. */ - return 1; /**< Refine. */ + /**< When this if Statement returns true, we are inside the set radius of our "refinement Sphere" of our point and therefor need to refine. */ + if (dist < adapt_data.refine_radius) { + return 1; /**< Refine. */ } /** Only coarsen if we actually have a complete family. */ @@ -83,5 +78,3 @@ default_adapt_callback ([[maybe_unused]] const mesh_type& mesh, return 0; /**< Do nothing. */ } - -#endif // DEFAULT_ADAPT_CALLBACK_HXX From 7b316f318e1cda860faf5b0587e7911e8d671500 Mon Sep 17 00:00:00 2001 From: Schmitt Date: Mon, 20 Jul 2026 16:42:25 +0200 Subject: [PATCH 07/20] renamed element data tutorial to step 5 --- .../{t8_mesh_element_data.cxx => t8_mesh_step5_element_data.cxx} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tutorials/mesh_handle/{t8_mesh_element_data.cxx => t8_mesh_step5_element_data.cxx} (100%) diff --git a/tutorials/mesh_handle/t8_mesh_element_data.cxx b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx similarity index 100% rename from tutorials/mesh_handle/t8_mesh_element_data.cxx rename to tutorials/mesh_handle/t8_mesh_step5_element_data.cxx From 8ba48ac6a6adbeb0a02169d9b99a1f1607a10cc3 Mon Sep 17 00:00:00 2001 From: Schmitt Date: Tue, 4 Aug 2026 09:08:27 +0200 Subject: [PATCH 08/20] Fixed Pull Requested changes --- tutorials/CMakeLists.txt | 2 +- .../mesh_handle/t8_mesh_step3_adapt_mesh.cxx | 35 ++-- .../t8_mesh_step4_partition_balance_ghost.cxx | 150 +++++++++++------- .../t8_mesh_step5_element_data.cxx | 35 ++-- 4 files changed, 131 insertions(+), 91 deletions(-) diff --git a/tutorials/CMakeLists.txt b/tutorials/CMakeLists.txt index 79d631bbb5..27d84996de 100644 --- a/tutorials/CMakeLists.txt +++ b/tutorials/CMakeLists.txt @@ -82,8 +82,8 @@ copy_tutorial_file (features/t8_features_curved_meshes_generate_cmesh_tet.geo) copy_tutorial_file (features/t8_features_curved_meshes_generate_cmesh_tri.geo) if( T8CODE_BUILD_MESH_HANDLE ) - add_mesh_handle_tutorial( NAME t8_mesh_element_data SOURCES mesh_handle/t8_mesh_element_data.cxx ) add_mesh_handle_tutorial( NAME t8_mesh_step3_adapt_mesh SOURCES mesh_handle/t8_mesh_step3_adapt_mesh.cxx ) add_mesh_handle_tutorial( NAME t8_mesh_step4_partition_balance_ghost SOURCES mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx ) + add_mesh_handle_tutorial( NAME t8_mesh_step5_element_data SOURCES mesh_handle/t8_mesh_step5_element_data.cxx ) endif() diff --git a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx index 026988d85c..73e2d079f9 100644 --- a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx +++ b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx @@ -41,11 +41,9 @@ #include /** Competence Pack for basic mesh_handle features. Look into tutorials/mesh_handle/t8_mesh_competences for more information. */ #include /** Wrapper for basic Cmesh to mesh_handle conversions. */ #include /** Used to export mesh to vtk files. */ -#include -#include /** t8 vector dataclass. */ -#include "t8_mesh_tutorials_common.hxx" /** Default adaption function. */ +#include /** Include this to use c++ concepts related to the mesh handle. This can be used to constraint the template parameters to only allow mesh handle classes. */ +#include "t8_mesh_tutorials_common.hxx" /** Adaption function definition used for this tutorial. */ #include -#include /** Build our adapted mesh by transferring the adaption parameters and adapting once with our \ref adapt_callback function. * \tparam TMeshClass The mesh handle class. @@ -60,13 +58,10 @@ build_mesh (sc_MPI_Comm comm, int level) /* Generate a hybrid hypercube, made out of cubes, prisms etc. */ auto mesh = t8_mesh_handle::handle_hypercube_hybrid_uniform_default (level, comm); /* Defining the adaption parameters. */ - struct adapt_data adapt_params = { { 0.5, 0.5, 1.0 }, 0.2, 0.4 }; - mesh->set_balance (); - mesh->set_partition (); + adapt_data adapt_params = { { 0.5, 0.5, 1.0 }, 0.2, 0.4 }; /* Adapting once with our adapt_callback function. */ mesh->set_adapt ( TMeshClass::template mesh_adapt_callback_wrapper (default_adapt_callback, adapt_params)); - mesh->set_ghost (); mesh->commit (); return mesh; } @@ -87,26 +82,28 @@ main (int argc, char **argv) sc_MPI_Comm comm = sc_MPI_COMM_WORLD; /* Print a starting message. */ - t8_global_productionf (" [tutorial] \n"); - t8_global_productionf (" [tutorial] Hello, this is the mesh adaptation example of t8code using the mesh handle.\n"); - t8_global_productionf (" [tutorial] In this example we will adapt a mesh in a spherical shape around a given point " - "and write the adapted mesh to a vtu file.\n"); - t8_global_productionf (" [tutorial] \n"); + t8_global_productionf (" [t8 step 3 Mesh handle] \n"); + t8_global_productionf ( + " [t8 step 3 Mesh handle] Hello, this is the mesh adaptation example of t8code using the mesh handle.\n"); + t8_global_productionf ( + " [t8 step 3 Mesh handle] In this example we will adapt a mesh in a spherical shape around a given point " + "and write the adapted mesh to a vtu file.\n"); + t8_global_productionf (" [t8 step 3 Mesh handle] \n"); using mesh_type = t8_mesh_handle::mesh<>; - t8_global_productionf (" [tutorial] \n"); - t8_global_productionf (" [tutorial] Creating an adapted mesh.\n"); - t8_global_productionf (" [tutorial] \n"); + t8_global_productionf (" [t8 step 3 Mesh handle] \n"); + t8_global_productionf (" [t8 step 3 Mesh handle] Creating an adapted mesh.\n"); + t8_global_productionf (" [t8 step 3 Mesh handle] \n"); /* The initial uniform refinement level. */ int uniform_level = 3; /* Building the mesh. */ { /** Scope to ensure mesh is deleted properly. */ auto mesh = build_mesh (comm, uniform_level); /* Write the mesh to a vtu file. */ - t8_global_productionf (" [tutorial] \n"); - t8_global_productionf (" [tutorial] Writing adapted mesh to vtu file: step3_adapted_mesh.vtu\n"); - t8_global_productionf (" [tutorial] \n"); + t8_global_productionf (" [t8 step 3 Mesh handle] \n"); + t8_global_productionf (" [t8 step 3 Mesh handle] Writing adapted mesh to vtu file: step3_adapted_mesh.vtu\n"); + t8_global_productionf (" [t8 step 3 Mesh handle] \n"); t8_mesh_handle::write_mesh_to_vtk (*mesh, "step3_adapted_mesh.vtu"); } sc_finalize (); diff --git a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx index 4569d3b514..c0e204f7d6 100644 --- a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx +++ b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx @@ -34,19 +34,21 @@ #include /** General Mesh header. Always needed for mesh_handle code. */ #include /** Used to export mesh to vtk files. */ #include /** Wrapper for basic Cmesh to mesh_handle conversions. */ -#include -#include /** t8 vector dataclass. */ +#include /** Include this to use c++ concepts related to the mesh handle. This can be used to constraint the template parameters to only allow mesh handle classes. */ +#include /** t8 vector dataclass. */ #include "t8_mesh_tutorials_common.hxx" /** Default adaption function. */ #include #include +using mesh_type = t8_mesh_handle::mesh<>; /**< To simplify the Code. */ + /** Helper function to print the total number of elements in the mesh after each step. * \param mesh The mesh handle to get the number of elements from. * \param stage The stage of the mesh (e.g. "Initial mesh", "Adapted mesh", etc.) to print in the output. * \param comm The MPI communicator to use for the reduction and printing. */ void -print_mesh_stats (const std::unique_ptr> &mesh, const char *stage, sc_MPI_Comm comm) +print_mesh_stats (const std::unique_ptr& mesh, const char* stage, sc_MPI_Comm comm) { int local_elements = mesh->get_num_local_elements (); int global_elements = 0; @@ -60,9 +62,71 @@ print_mesh_stats (const std::unique_ptr> &mesh, const cha } } +/** Helper function to create an adapted mesh from an initial mesh. + * \param mesh The initial mesh to adapt. + * \param adapt_params The adaptation parameters to use for the adaptation. + * \return A unique pointer to the adapted mesh. +*/ +std::unique_ptr +create_adapted_mesh (const std::unique_ptr& mesh, const adapt_data& adapt_params) +{ + /* Creating the adapted mesh as a copy of the given mesh*/ + auto mesh_adapt = std::make_unique (*mesh); + + /* Adapting the mesh once with our adapt_callback function from step 3 and the parameters defined above. */ + mesh_adapt->set_adapt ( + mesh_type::template mesh_adapt_callback_wrapper (&default_adapt_callback, adapt_params)); + /* Committing the adapted mesh. */ + mesh_adapt->commit (); + + return mesh_adapt; +} + +/** Helper function to create a partitioned and balanced mesh from an initial mesh. + * \param mesh The initial mesh to adapt. + * \param adapt_params The adaptation parameters to use for the adaptation. + * \return A unique pointer to the partitioned and balanced mesh. +*/ +std::unique_ptr +create_partitioned_balanced_mesh (const std::unique_ptr& mesh) +{ + /* Creating the partition and balance mesh as a copy of the given mesh. */ + auto mesh_partition_balance = std::make_unique (*mesh); + + /* Partitioning the mesh.*/ + mesh_partition_balance->set_partition (); + + /* Balancing the mesh. */ + mesh_partition_balance->set_balance (); + + /* Committing the partitioned and balanced mesh. */ + mesh_partition_balance->commit (); + + return mesh_partition_balance; +} + +/** Helper function to create a ghost mesh from an initial mesh. + * \param mesh The initial mesh to adapt. + * \return A unique pointer to the new mesh with ghost layers. +*/ +std::unique_ptr +create_ghost_mesh (const std::unique_ptr& mesh) +{ + /* Creating the ghost mesh as a copy of the given mesh. */ + auto mesh_ghost = std::make_unique (*mesh); + + /* Creating the ghost layers. */ + mesh_ghost->set_ghost (); + + /* Committing the ghost mesh. */ + mesh_ghost->commit (); + + return mesh_ghost; +} + /** Entry point of the program. */ int -main (int argc, char **argv) +main (int argc, char** argv) { /* Initialize MPI. This has to happen before we initialize sc or t8code. */ @@ -77,10 +141,11 @@ main (int argc, char **argv) sc_MPI_Comm comm = sc_MPI_COMM_WORLD; /* Print a starting message. */ - t8_global_productionf (" [tutorial] \n"); - t8_global_productionf (" [tutorial] Hello, this is the mesh adaptation example of t8code using the mesh handle.\n"); - t8_global_productionf (" [tutorial] In this example we will Us\n"); - t8_global_productionf (" [tutorial] \n"); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + t8_global_productionf ( + " [t8 step 4 Mesh handle] Hello, this is the mesh adaptation example of t8code using the mesh handle.\n"); + t8_global_productionf (" [t8 step 4 Mesh handle] In this example we will Us\n"); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); /* The initial uniform refinement level. */ int uniform_level = 3; @@ -88,22 +153,17 @@ main (int argc, char **argv) /* Parameters for the adaption step. */ struct adapt_data adapt_params = { { 0.5, 0.5, 1.0 }, 0.2, 0.4 }; - using mesh_type = t8_mesh_handle::mesh<>; - /** * INITIAL MESH */ - t8_global_productionf (" [tutorial] \n"); - t8_global_productionf (" [tutorial] Creating initial mesh.\n"); - t8_global_productionf (" [tutorial] \n"); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + t8_global_productionf (" [t8 step 4 Mesh handle] Creating initial mesh.\n"); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); /* Creating the initial mesh with uniform refinement. */ auto mesh = t8_mesh_handle::handle_hypercube_hybrid_uniform_default (uniform_level, comm); - /* Committing the initial mesh. */ - mesh->commit (); - /* Printing the mesh information. */ print_mesh_stats (mesh, "Initial mesh", comm); @@ -115,18 +175,12 @@ main (int argc, char **argv) * ADAPTED MESH */ - t8_global_productionf (" [tutorial] \n"); - t8_global_productionf (" [tutorial] Creating adapted mesh.\n"); - t8_global_productionf (" [tutorial] \n"); - - /* Creating the adapted mesh as a copy of the initial mesh (Initial mesh can't be refined because it is already committed.) */ - auto mesh_adapt = std::make_unique (*mesh); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + t8_global_productionf (" [t8 step 4 Mesh handle] Creating adapted mesh.\n"); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); - /* Adapting the mesh once with our adapt_callback function from step 3 and the parameters defined above. */ - mesh_adapt->set_adapt ( - mesh_type::template mesh_adapt_callback_wrapper (&default_adapt_callback, adapt_params)); - /* Committing the adapted mesh. */ - mesh_adapt->commit (); + /** Call creation function. */ + auto mesh_adapt = create_adapted_mesh (mesh, adapt_params); /* Printing the mesh information. */ print_mesh_stats (mesh_adapt, "Adapted mesh", comm); @@ -139,21 +193,15 @@ main (int argc, char **argv) * PARTITIONED, BALANCED MESH */ - t8_global_productionf (" [tutorial] \n"); - t8_global_productionf (" [tutorial] Creating partitioned and balanced mesh.\n"); - t8_global_productionf (" [tutorial] \n"); - - /* Creating the partition and balance mesh as a copy of the adapted mesh. */ - auto mesh_partition_balance = std::make_unique (*mesh_adapt); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + t8_global_productionf (" [t8 step 4 Mesh handle] Creating partitioned and balanced mesh.\n"); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); - /* Partitioning the mesh.*/ - mesh_partition_balance->set_partition (); + /** Adapting the mesh from above a second time to see a difference when balancing. */ + auto mesh_adapt_second = create_adapted_mesh (mesh_adapt, adapt_params); - /* Balancing the mesh. */ - mesh_partition_balance->set_balance (); - - /* Committing the partitioned and balanced mesh. */ - mesh_partition_balance->commit (); + /** Call creation function. */ + auto mesh_partition_balance = create_partitioned_balanced_mesh (mesh_adapt_second); /* Printing the mesh information. */ print_mesh_stats (mesh_partition_balance, "Partitioned and Balanced mesh", comm); @@ -166,18 +214,12 @@ main (int argc, char **argv) * GHOST MESH */ - t8_global_productionf (" [tutorial] \n"); - t8_global_productionf (" [tutorial] Creating ghost mesh.\n"); - t8_global_productionf (" [tutorial] \n"); - - /* Creating the ghost mesh as a copy of the partitioned and balanced mesh. */ - auto mesh_ghost = std::make_unique (*mesh_partition_balance); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + t8_global_productionf (" [t8 step 4 Mesh handle] Creating ghost mesh.\n"); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); - /* Creating the ghost layers. */ - mesh_ghost->set_ghost (); - - /* Committing the ghost mesh. */ - mesh_ghost->commit (); + /** Call creation function. */ + auto mesh_ghost = create_ghost_mesh (mesh_partition_balance); /* Printing the mesh information*/ print_mesh_stats (mesh_ghost, "Ghost mesh", comm); @@ -186,9 +228,9 @@ main (int argc, char **argv) t8_mesh_handle::write_mesh_to_vtk_ext (*mesh_ghost, "ghost_mesh.vtu", 0, nullptr, true, true, true, true, true, false, false); - t8_global_productionf (" [tutorial] \n"); - t8_global_productionf (" [tutorial] Finished all steps successfully.\n"); - t8_global_productionf (" [tutorial] \n"); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + t8_global_productionf (" [t8 step 4 Mesh handle] Finished all steps successfully.\n"); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); sc_finalize (); mpiret = sc_MPI_Finalize (); diff --git a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx index 1bc8161d85..4bbd2fc443 100644 --- a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx +++ b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx @@ -21,8 +21,8 @@ */ /** \file t8_mesh_element_data.cxx - * This is step5 of the t8code tutorials. - * Therefor, this is the same as general/t8_step5_element_data.cxx but using the mesh handle interface instead of the forest + * This is step5 of the mesh handle tutorials. + * Therefore, this is the same as general/t8_step5_element_data.cxx but using the mesh handle interface instead of the forest * interface. * In the following we will store data in the individual elements of our mesh. * To do this, we will again create a uniform mesh, which will get adapted as in step4, @@ -38,8 +38,8 @@ #include /** Competence Pack for basic mesh_handle features. Look into tutorials/mesh_handle/t8_mesh_competences for more information. */ #include /** Wrapper for basic Cmesh to mesh_handle conversions. */ #include /** Used to export mesh to vtk files. */ -#include -#include /** t8 vector dataclass. */ +#include /** Include this to use c++ concepts related to the mesh handle. This can be used to constraint the template parameters to only allow mesh handle classes. */ +#include /** t8 vector dataclass. */ #include "t8_mesh_tutorials_common.hxx" /** Default adaption function. */ #include #include @@ -164,16 +164,17 @@ main (int argc, char **argv) sc_MPI_Comm comm = sc_MPI_COMM_WORLD; /* Print a message on the root process. */ - t8_global_productionf (" [tutorial] \n"); - t8_global_productionf (" [tutorial] Hello, this is the element data example of t8code using the mesh handle.\n"); + t8_global_productionf (" [t8 Step 5 Mesh handle] \n"); t8_global_productionf ( - " [tutorial] In this example we will store data on our elements and exchange the data of ghost elements.\n"); - t8_global_productionf (" [tutorial] \n"); + " [t8 Step 5 Mesh handle] Hello, this is the element data example of t8code using the mesh handle.\n"); + t8_global_productionf (" [t8 Step 5 Mesh handle] In this example we will store data on our elements and exchange the " + "data of ghost elements.\n"); + t8_global_productionf (" [t8 Step 5 Mesh handle] \n"); /* Setup: Build cmesh and adapt uniformly. */ - t8_global_productionf (" [tutorial] \n"); - t8_global_productionf (" [tutorial] Creating an adapted mesh.\n"); - t8_global_productionf (" [tutorial] \n"); + t8_global_productionf (" [t8 Step 5 Mesh handle] \n"); + t8_global_productionf (" [t8 Step 5 Mesh handle] Creating an adapted mesh.\n"); + t8_global_productionf (" [t8 Step 5 Mesh handle] \n"); { /* We put the mesh in its own scope so that it is automatically destroyed at the end of the scope. * This is only necessary because sc_finalize checks if there are leftover references. * This unique pointer would have been destroyed automatically at the end of the programme. */ @@ -182,30 +183,30 @@ main (int argc, char **argv) auto mesh = build_mesh (comm, level); t8_mesh_handle::write_mesh_to_vtk (*mesh, prefix_mesh); - t8_global_productionf (" [tutorial] Wrote mesh to vtu files: %s*\n", prefix_mesh); + t8_global_productionf (" [t8 Step 5 Mesh handle] Wrote mesh to vtu files: %s*\n", prefix_mesh); set_element_data_mesh (*mesh); - t8_global_productionf (" [tutorial] Computed level and volume data for local elements.\n"); + t8_global_productionf (" [t8 Step 5 Mesh handle] Computed level and volume data for local elements.\n"); if (mesh->get_num_local_elements () > 0) { /* Output the stored data of the first local element (if it exists). */ - t8_global_productionf (" [tutorial] Element 0 has level %i and volume %e.\n", + t8_global_productionf (" [t8 Step 5 Mesh handle] Element 0 has level %i and volume %e.\n", ((*mesh)[0]).get_element_data ().level, ((*mesh)[0]).get_element_data ().volume); } /* Exchange the data values of the ghost elements. */ exchange_ghost_data_mesh (*mesh); - t8_global_productionf (" [tutorial] Exchanged ghost data.\n"); + t8_global_productionf (" [t8 Step 5 Mesh handle] Exchanged ghost data.\n"); if (mesh->get_num_ghosts () > 0) { /* Output the data of the first ghost element (if it exists). */ t8_locidx_t first_ghost_index = mesh->get_num_local_elements (); - t8_global_productionf (" [tutorial] Ghost 0 has level %i and volume %e.\n", + t8_global_productionf (" [t8 Step 5 Mesh handle] Ghost 0 has level %i and volume %e.\n", ((*mesh)[first_ghost_index]).get_element_data ().level, ((*mesh)[first_ghost_index]).get_element_data ().volume); } /* Output the volume data to vtu. */ output_data_to_vtu (*mesh, prefix_mesh_with_data); - t8_global_productionf (" [tutorial] Wrote mesh and volume data to %s*.\n", prefix_mesh_with_data); + t8_global_productionf (" [t8 Step 5 Mesh handle] Wrote mesh and volume data to %s*.\n", prefix_mesh_with_data); /* Cleanup. */ } // End scope of mesh From 0d60c0e07f01470a66c6096e777540e99b3170c5 Mon Sep 17 00:00:00 2001 From: Vincent Schmitt <136984538+Vyp3er@users.noreply.github.com> Date: Mon, 10 Aug 2026 13:43:54 +0200 Subject: [PATCH 09/20] Apply suggestions from code review Co-authored-by: lenaploetzke <70579874+lenaploetzke@users.noreply.github.com> --- .../mesh_handle/t8_mesh_step3_adapt_mesh.cxx | 14 +++++++------- .../t8_mesh_step4_partition_balance_ghost.cxx | 15 +++++++-------- .../mesh_handle/t8_mesh_step5_element_data.cxx | 6 +++--- .../mesh_handle/t8_mesh_tutorials_common.hxx | 6 +++--- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx index 73e2d079f9..5c8897767b 100644 --- a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx +++ b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx @@ -37,9 +37,9 @@ */ #include /** General t8code header. Always include this. */ -#include /** General Mesh header. Always needed for mesh_handle code. */ -#include /** Competence Pack for basic mesh_handle features. Look into tutorials/mesh_handle/t8_mesh_competences for more information. */ -#include /** Wrapper for basic Cmesh to mesh_handle conversions. */ +#include /** General mesh header. Always needed for mesh_handle code. */ +#include /** Competence pack for basic mesh_handle features. Look into tutorials/mesh_handle/t8_mesh_competences for more information. */ +#include /** Wrapper for basic cmesh to mesh_handle conversions. */ #include /** Used to export mesh to vtk files. */ #include /** Include this to use c++ concepts related to the mesh handle. This can be used to constraint the template parameters to only allow mesh handle classes. */ #include "t8_mesh_tutorials_common.hxx" /** Adaption function definition used for this tutorial. */ @@ -47,7 +47,7 @@ /** Build our adapted mesh by transferring the adaption parameters and adapting once with our \ref adapt_callback function. * \tparam TMeshClass The mesh handle class. - * \param sc_MPI_Comm The MPI Communicator. + * \param sc_MPI_Comm The MPI communicator. * \param level The initial uniform refinement level. * \returns Unique pointer to the adapted mesh. */ @@ -59,7 +59,7 @@ build_mesh (sc_MPI_Comm comm, int level) auto mesh = t8_mesh_handle::handle_hypercube_hybrid_uniform_default (level, comm); /* Defining the adaption parameters. */ adapt_data adapt_params = { { 0.5, 0.5, 1.0 }, 0.2, 0.4 }; - /* Adapting once with our adapt_callback function. */ + /* Adapting once using our adapt callback. */ mesh->set_adapt ( TMeshClass::template mesh_adapt_callback_wrapper (default_adapt_callback, adapt_params)); mesh->commit (); @@ -70,9 +70,9 @@ build_mesh (sc_MPI_Comm comm, int level) int main (int argc, char **argv) { - /*Initialize MPI. This has to happen before we initialize sc or t8code. */ + /* Initialize MPI. This has to happen before we initialize sc or t8code. */ int mpiret = sc_MPI_Init (&argc, &argv); - /*Error check the MPI return value. */ + /* Error check the MPI return value. */ SC_CHECK_MPI (mpiret); /* Initialize the sc library, has to happen before we initialize t8code. */ sc_init (sc_MPI_COMM_WORLD, 1, 1, NULL, SC_LP_ESSENTIAL); diff --git a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx index c0e204f7d6..b252a7d88b 100644 --- a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx +++ b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx @@ -22,7 +22,7 @@ /** \file t8_mesh_element_data.cxx * This is step4 of the t8code mesh handle tutorials. - * Therefor, this is the same as general/t8_step4_partition_balance_ghost.cxx but using the mesh handle interface instead of the forest + * Therefore, this is the same as general/t8_step4_partition_balance_ghost.cxx but using the mesh handle interface instead of the forest * interface. * After generating a coarse mesh (step1), building a uniform mesh * on it (step2) and adapting this mesh (step3) @@ -40,7 +40,7 @@ #include #include -using mesh_type = t8_mesh_handle::mesh<>; /**< To simplify the Code. */ +using mesh_type = t8_mesh_handle::mesh<>; /**< Mesh class used in this tutorial. We define it globally to get rid of the function templates to simplify the code. */ /** Helper function to print the total number of elements in the mesh after each step. * \param mesh The mesh handle to get the number of elements from. @@ -84,7 +84,6 @@ create_adapted_mesh (const std::unique_ptr& mesh, const adapt_data& a /** Helper function to create a partitioned and balanced mesh from an initial mesh. * \param mesh The initial mesh to adapt. - * \param adapt_params The adaptation parameters to use for the adaptation. * \return A unique pointer to the partitioned and balanced mesh. */ std::unique_ptr @@ -105,9 +104,9 @@ create_partitioned_balanced_mesh (const std::unique_ptr& mesh) return mesh_partition_balance; } -/** Helper function to create a ghost mesh from an initial mesh. +/** Helper function to create a mesh with ghosts from an initial mesh. * \param mesh The initial mesh to adapt. - * \return A unique pointer to the new mesh with ghost layers. + * \return A unique pointer to the new mesh with a ghost layer. */ std::unique_ptr create_ghost_mesh (const std::unique_ptr& mesh) @@ -167,7 +166,7 @@ main (int argc, char** argv) /* Printing the mesh information. */ print_mesh_stats (mesh, "Initial mesh", comm); - /* Writing the Mesh to vtu and pvtu files, using the extended version of the function to ensure additional data like ghost elements, treeid etc. to be written into the files. */ + /* Writing the mesh to vtu and pvtu files, using the extended version of the function to ensure additional data like ghost elements, treeid etc. to be written into the files. */ t8_mesh_handle::write_mesh_to_vtk_ext (*mesh, "initial_mesh.vtu", 0, nullptr, true, true, true, true, true, false, false); @@ -215,13 +214,13 @@ main (int argc, char** argv) */ t8_global_productionf (" [t8 step 4 Mesh handle] \n"); - t8_global_productionf (" [t8 step 4 Mesh handle] Creating ghost mesh.\n"); + t8_global_productionf (" [t8 step 4 Mesh handle] Creating ghost layer for mesh.\n"); t8_global_productionf (" [t8 step 4 Mesh handle] \n"); /** Call creation function. */ auto mesh_ghost = create_ghost_mesh (mesh_partition_balance); - /* Printing the mesh information*/ + /* Printing the mesh information. */ print_mesh_stats (mesh_ghost, "Ghost mesh", comm); /* Writing the mesh to vtu and pvtu files using the extended version of the function. */ diff --git a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx index 4bbd2fc443..9573dc2656 100644 --- a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx +++ b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx @@ -34,9 +34,9 @@ #include /** General t8code header. Always include this. */ -#include /** General Mesh header. Always needed for mesh_handle code. */ -#include /** Competence Pack for basic mesh_handle features. Look into tutorials/mesh_handle/t8_mesh_competences for more information. */ -#include /** Wrapper for basic Cmesh to mesh_handle conversions. */ +#include /** General mesh header. Always needed for mesh_handle code. */ +#include /** Competence pack for basic mesh_handle features. Look into tutorials/mesh_handle/t8_mesh_competences for more information. */ +#include /** Wrapper for basic cmesh to mesh_handle conversions. */ #include /** Used to export mesh to vtk files. */ #include /** Include this to use c++ concepts related to the mesh handle. This can be used to constraint the template parameters to only allow mesh handle classes. */ #include /** t8 vector dataclass. */ diff --git a/tutorials/mesh_handle/t8_mesh_tutorials_common.hxx b/tutorials/mesh_handle/t8_mesh_tutorials_common.hxx index 0ce7605756..530310c77b 100644 --- a/tutorials/mesh_handle/t8_mesh_tutorials_common.hxx +++ b/tutorials/mesh_handle/t8_mesh_tutorials_common.hxx @@ -20,7 +20,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/** \file default_adapt_callback.hxx +/** \file t8_mesh_tutorials_common.hxx * This is the default adaptation callback function that can be used to refine and coarsen a mesh in a spherical shape around a given point. * It is used in step 3, 4 and 5 in the mesh_handle tutorials. */ @@ -37,7 +37,7 @@ * In this example we want to adapt in a spherical shape around a given point. */ struct adapt_data { - t8_3D_vec midpoint; /**< midpoint of our sphere. */ + t8_3D_vec midpoint; /**< Midpoint of our sphere. */ double refine_radius; /**< We refine inside this radius of our sphere.*/ double coarsen_radius; /**< We coarsen outside this radius of our sphere. */ }; @@ -66,7 +66,7 @@ default_adapt_callback ([[maybe_unused]] const mesh_type& mesh, auto element_centroid = elements[0].get_centroid (); double dist = t8_dist (element_centroid, adapt_data.midpoint); - /**< When this if Statement returns true, we are inside the set radius of our "refinement Sphere" of our point and therefor need to refine. */ + /** When this if statement returns true, we are inside the set radius of our "refinement sphere" of our point and therefore need to refine. */ if (dist < adapt_data.refine_radius) { return 1; /**< Refine. */ } From c411a76ea86913c52f3cc007e57ca1b923f18350 Mon Sep 17 00:00:00 2001 From: Schmitt Date: Mon, 10 Aug 2026 14:58:23 +0200 Subject: [PATCH 10/20] Fixed errors marked in pull request --- .../mesh_handle/t8_mesh_step3_adapt_mesh.cxx | 40 ++-- .../t8_mesh_step4_partition_balance_ghost.cxx | 182 ++++++++---------- .../t8_mesh_step5_element_data.cxx | 10 +- .../mesh_handle/t8_mesh_tutorials_common.hxx | 14 +- 4 files changed, 115 insertions(+), 131 deletions(-) diff --git a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx index 5c8897767b..d0942e43ae 100644 --- a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx +++ b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx @@ -37,9 +37,9 @@ */ #include /** General t8code header. Always include this. */ -#include /** General mesh header. Always needed for mesh_handle code. */ -#include /** Competence pack for basic mesh_handle features. Look into tutorials/mesh_handle/t8_mesh_competences for more information. */ -#include /** Wrapper for basic cmesh to mesh_handle conversions. */ +#include /** General mesh header. Always needed for mesh_handle code. */ +#include /** Competence pack for basic mesh_handle features. Look into tutorials/mesh_handle/t8_mesh_competences for more information. */ +#include /** Wrapper for basic cmesh to mesh_handle conversions. */ #include /** Used to export mesh to vtk files. */ #include /** Include this to use c++ concepts related to the mesh handle. This can be used to constraint the template parameters to only allow mesh handle classes. */ #include "t8_mesh_tutorials_common.hxx" /** Adaption function definition used for this tutorial. */ @@ -47,7 +47,7 @@ /** Build our adapted mesh by transferring the adaption parameters and adapting once with our \ref adapt_callback function. * \tparam TMeshClass The mesh handle class. - * \param sc_MPI_Comm The MPI communicator. + * \param sc_MPI_Comm The MPI communicator. * \param level The initial uniform refinement level. * \returns Unique pointer to the adapted mesh. */ @@ -59,9 +59,13 @@ build_mesh (sc_MPI_Comm comm, int level) auto mesh = t8_mesh_handle::handle_hypercube_hybrid_uniform_default (level, comm); /* Defining the adaption parameters. */ adapt_data adapt_params = { { 0.5, 0.5, 1.0 }, 0.2, 0.4 }; - /* Adapting once using our adapt callback. */ + /** Adapting once using our adapt callback. + * set_adapt() only records how the mesh should be changed, it does not modify anything yet. + * commit() is the function that actually builds the new, adapted mesh from these settings. + * This "configure, then commit" split let's t8code carry out several mesh operations together in one efficient pass, rather than one at a time. + */ mesh->set_adapt ( - TMeshClass::template mesh_adapt_callback_wrapper (default_adapt_callback, adapt_params)); + TMeshClass::template mesh_adapt_callback_wrapper (adapt_callback_sphere, adapt_params)); mesh->commit (); return mesh; } @@ -70,9 +74,9 @@ build_mesh (sc_MPI_Comm comm, int level) int main (int argc, char **argv) { - /* Initialize MPI. This has to happen before we initialize sc or t8code. */ + /* Initialize MPI. This has to happen before we initialize sc or t8code. */ int mpiret = sc_MPI_Init (&argc, &argv); - /* Error check the MPI return value. */ + /* Error check the MPI return value. */ SC_CHECK_MPI (mpiret); /* Initialize the sc library, has to happen before we initialize t8code. */ sc_init (sc_MPI_COMM_WORLD, 1, 1, NULL, SC_LP_ESSENTIAL); @@ -82,28 +86,28 @@ main (int argc, char **argv) sc_MPI_Comm comm = sc_MPI_COMM_WORLD; /* Print a starting message. */ - t8_global_productionf (" [t8 step 3 Mesh handle] \n"); + t8_global_productionf (" [mesh_step3] \n"); t8_global_productionf ( - " [t8 step 3 Mesh handle] Hello, this is the mesh adaptation example of t8code using the mesh handle.\n"); + " [mesh_step3] Hello, this is the mesh adaptation tutorial of t8code using the mesh handle.\n"); t8_global_productionf ( - " [t8 step 3 Mesh handle] In this example we will adapt a mesh in a spherical shape around a given point " + " [mesh_step3] In this tutorial we will adapt a mesh in a spherical shape around a given point " "and write the adapted mesh to a vtu file.\n"); - t8_global_productionf (" [t8 step 3 Mesh handle] \n"); + t8_global_productionf (" [mesh_step3] \n"); using mesh_type = t8_mesh_handle::mesh<>; - t8_global_productionf (" [t8 step 3 Mesh handle] \n"); - t8_global_productionf (" [t8 step 3 Mesh handle] Creating an adapted mesh.\n"); - t8_global_productionf (" [t8 step 3 Mesh handle] \n"); + t8_global_productionf (" [mesh_step3] \n"); + t8_global_productionf (" [mesh_step3] Creating an adapted mesh.\n"); + t8_global_productionf (" [mesh_step3] \n"); /* The initial uniform refinement level. */ int uniform_level = 3; /* Building the mesh. */ { /** Scope to ensure mesh is deleted properly. */ auto mesh = build_mesh (comm, uniform_level); /* Write the mesh to a vtu file. */ - t8_global_productionf (" [t8 step 3 Mesh handle] \n"); - t8_global_productionf (" [t8 step 3 Mesh handle] Writing adapted mesh to vtu file: step3_adapted_mesh.vtu\n"); - t8_global_productionf (" [t8 step 3 Mesh handle] \n"); + t8_global_productionf (" [mesh_step3] \n"); + t8_global_productionf (" [mesh_step3] Writing adapted mesh to vtu file: step3_adapted_mesh.vtu\n"); + t8_global_productionf (" [mesh_step3] \n"); t8_mesh_handle::write_mesh_to_vtk (*mesh, "step3_adapted_mesh.vtu"); } sc_finalize (); diff --git a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx index b252a7d88b..d18e09be79 100644 --- a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx +++ b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx @@ -22,7 +22,7 @@ /** \file t8_mesh_element_data.cxx * This is step4 of the t8code mesh handle tutorials. - * Therefore, this is the same as general/t8_step4_partition_balance_ghost.cxx but using the mesh handle interface instead of the forest + * Therefore, this is the same as general/t8_step4_partition_balance_ghost.cxx but using the mesh handle interface instead of the forest * interface. * After generating a coarse mesh (step1), building a uniform mesh * on it (step2) and adapting this mesh (step3) @@ -31,16 +31,17 @@ */ #include /** General t8code header. Always include this. */ -#include /** General Mesh header. Always needed for mesh_handle code. */ +#include /** General mesh header. Always needed for mesh_handle code. */ #include /** Used to export mesh to vtk files. */ -#include /** Wrapper for basic Cmesh to mesh_handle conversions. */ +#include /** Wrapper for basic cmesh to mesh_handle conversions. */ #include /** Include this to use c++ concepts related to the mesh handle. This can be used to constraint the template parameters to only allow mesh handle classes. */ #include /** t8 vector dataclass. */ #include "t8_mesh_tutorials_common.hxx" /** Default adaption function. */ #include #include -using mesh_type = t8_mesh_handle::mesh<>; /**< Mesh class used in this tutorial. We define it globally to get rid of the function templates to simplify the code. */ +using mesh_type = t8_mesh_handle:: + mesh<>; /**< Mesh class used in this tutorial. We define it globally to get rid of the function templates to simplify the code. */ /** Helper function to print the total number of elements in the mesh after each step. * \param mesh The mesh handle to get the number of elements from. @@ -54,73 +55,51 @@ print_mesh_stats (const std::unique_ptr& mesh, const char* stage, sc_ int global_elements = 0; MPI_Allreduce (&local_elements, &global_elements, 1, MPI_INT, MPI_SUM, comm); - int rank = 0; - MPI_Comm_rank (comm, &rank); - if (rank == 0) { - std::cout << "=== " << stage << " ===" << std::endl; - std::cout << "Total elements: " << global_elements << std::endl; - } + t8_global_productionf (" [mesh_step4] === %s === \n", stage); + t8_global_productionf (" [mesh_step4] Total elements: %i \n", global_elements); } /** Helper function to create an adapted mesh from an initial mesh. * \param mesh The initial mesh to adapt. * \param adapt_params The adaptation parameters to use for the adaptation. - * \return A unique pointer to the adapted mesh. */ -std::unique_ptr -create_adapted_mesh (const std::unique_ptr& mesh, const adapt_data& adapt_params) +void +create_adapted_mesh (std::unique_ptr& mesh, const adapt_data& adapt_params) { - /* Creating the adapted mesh as a copy of the given mesh*/ - auto mesh_adapt = std::make_unique (*mesh); - - /* Adapting the mesh once with our adapt_callback function from step 3 and the parameters defined above. */ - mesh_adapt->set_adapt ( - mesh_type::template mesh_adapt_callback_wrapper (&default_adapt_callback, adapt_params)); + /* Adapting the mesh once with our adapt_callback_sphere function from step 3 and the adapt_params. Both can be found in the file \ref t8_mesh_tutorials_common.hxx. */ + mesh->set_adapt ( + mesh_type::template mesh_adapt_callback_wrapper (&adapt_callback_sphere, adapt_params)); /* Committing the adapted mesh. */ - mesh_adapt->commit (); - - return mesh_adapt; + mesh->commit (); } /** Helper function to create a partitioned and balanced mesh from an initial mesh. * \param mesh The initial mesh to adapt. - * \return A unique pointer to the partitioned and balanced mesh. */ -std::unique_ptr +void create_partitioned_balanced_mesh (const std::unique_ptr& mesh) { - /* Creating the partition and balance mesh as a copy of the given mesh. */ - auto mesh_partition_balance = std::make_unique (*mesh); - - /* Partitioning the mesh.*/ - mesh_partition_balance->set_partition (); - - /* Balancing the mesh. */ - mesh_partition_balance->set_balance (); + /* Calculate partition information.*/ + mesh->set_partition (); - /* Committing the partitioned and balanced mesh. */ - mesh_partition_balance->commit (); + /* Calculate balancing information. */ + mesh->set_balance (); - return mesh_partition_balance; + /* Committing the mesh --> modifying the mesh according to the precalculated information. */ + mesh->commit (); } -/** Helper function to create a mesh with ghosts from an initial mesh. +/** Helper function to create a mesh with ghosts from an initial mesh. * \param mesh The initial mesh to adapt. - * \return A unique pointer to the new mesh with a ghost layer. */ -std::unique_ptr +void create_ghost_mesh (const std::unique_ptr& mesh) { - /* Creating the ghost mesh as a copy of the given mesh. */ - auto mesh_ghost = std::make_unique (*mesh); - /* Creating the ghost layers. */ - mesh_ghost->set_ghost (); + mesh->set_ghost (); /* Committing the ghost mesh. */ - mesh_ghost->commit (); - - return mesh_ghost; + mesh->commit (); } /** Entry point of the program. */ @@ -143,7 +122,8 @@ main (int argc, char** argv) t8_global_productionf (" [t8 step 4 Mesh handle] \n"); t8_global_productionf ( " [t8 step 4 Mesh handle] Hello, this is the mesh adaptation example of t8code using the mesh handle.\n"); - t8_global_productionf (" [t8 step 4 Mesh handle] In this example we will Us\n"); + t8_global_productionf (" [t8 step 4 Mesh handle] In this example we will create a mesh, adapt, partition, balance " + "and create a ghost layer on it. \n"); t8_global_productionf (" [t8 step 4 Mesh handle] \n"); /* The initial uniform refinement level. */ @@ -153,84 +133,84 @@ main (int argc, char** argv) struct adapt_data adapt_params = { { 0.5, 0.5, 1.0 }, 0.2, 0.4 }; /** - * INITIAL MESH - */ + * INITIAL MESH + */ t8_global_productionf (" [t8 step 4 Mesh handle] \n"); t8_global_productionf (" [t8 step 4 Mesh handle] Creating initial mesh.\n"); t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + { /** Mesh scope begin. */ + /* Creating the initial mesh with uniform refinement. */ + auto mesh = t8_mesh_handle::handle_hypercube_hybrid_uniform_default (uniform_level, comm); - /* Creating the initial mesh with uniform refinement. */ - auto mesh = t8_mesh_handle::handle_hypercube_hybrid_uniform_default (uniform_level, comm); + /* Printing the mesh information. */ + print_mesh_stats (mesh, "Initial mesh", comm); - /* Printing the mesh information. */ - print_mesh_stats (mesh, "Initial mesh", comm); + /* Writing the mesh to vtu and pvtu files, using the extended version of the function to ensure additional data like ghost elements, treeid etc. to be written into the files. */ + t8_mesh_handle::write_mesh_to_vtk_ext (*mesh, "initial_mesh.vtu", 0, nullptr, true, true, true, true, true, false, + false); - /* Writing the mesh to vtu and pvtu files, using the extended version of the function to ensure additional data like ghost elements, treeid etc. to be written into the files. */ - t8_mesh_handle::write_mesh_to_vtk_ext (*mesh, "initial_mesh.vtu", 0, nullptr, true, true, true, true, true, false, - false); + /** + * ADAPTED MESH + */ - /** - * ADAPTED MESH - */ + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + t8_global_productionf (" [t8 step 4 Mesh handle] Creating adapted mesh.\n"); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); - t8_global_productionf (" [t8 step 4 Mesh handle] Creating adapted mesh.\n"); - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + /** Call adaption helper function. */ + create_adapted_mesh (mesh, adapt_params); - /** Call creation function. */ - auto mesh_adapt = create_adapted_mesh (mesh, adapt_params); + /* Printing the mesh information. */ + print_mesh_stats (mesh, "Adapted mesh", comm); - /* Printing the mesh information. */ - print_mesh_stats (mesh_adapt, "Adapted mesh", comm); + /* Writing the mesh to vtu and pvtu files using the extended version of the function. */ + t8_mesh_handle::write_mesh_to_vtk_ext (*mesh, "adapted_mesh.vtu", 0, nullptr, true, true, true, true, true, false, + false); - /* Writing the mesh to vtu and pvtu files using the extended version of the function. */ - t8_mesh_handle::write_mesh_to_vtk_ext (*mesh_adapt, "adapted_mesh.vtu", 0, nullptr, true, true, true, true, true, - false, false); + /** + * PARTITIONED, BALANCED MESH + */ - /** - * PARTITIONED, BALANCED MESH - */ - - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); - t8_global_productionf (" [t8 step 4 Mesh handle] Creating partitioned and balanced mesh.\n"); - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); - - /** Adapting the mesh from above a second time to see a difference when balancing. */ - auto mesh_adapt_second = create_adapted_mesh (mesh_adapt, adapt_params); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + t8_global_productionf (" [t8 step 4 Mesh handle] Creating partitioned and balanced mesh.\n"); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); - /** Call creation function. */ - auto mesh_partition_balance = create_partitioned_balanced_mesh (mesh_adapt_second); + /** Adapting the mesh from above a second time to see a difference when balancing. */ + create_adapted_mesh (mesh, adapt_params); - /* Printing the mesh information. */ - print_mesh_stats (mesh_partition_balance, "Partitioned and Balanced mesh", comm); + /** Call partitioning and balancing helper function. */ + create_partitioned_balanced_mesh (mesh); - /* Writing the mesh to vtu and pvtu files using the extended version of the function. */ - t8_mesh_handle::write_mesh_to_vtk_ext (*mesh_partition_balance, "partition_balance_mesh.vtu", 0, nullptr, true, true, - true, true, true, false, false); + /* Printing the mesh information. */ + print_mesh_stats (mesh, "Partitioned and Balanced mesh", comm); - /** - * GHOST MESH - */ + /* Writing the mesh to vtu and pvtu files using the extended version of the function. */ + t8_mesh_handle::write_mesh_to_vtk_ext (*mesh, "partition_balance_mesh.vtu", 0, nullptr, true, true, true, true, + true, false, false); - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); - t8_global_productionf (" [t8 step 4 Mesh handle] Creating ghost layer for mesh.\n"); - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + /** + * GHOST MESH + */ - /** Call creation function. */ - auto mesh_ghost = create_ghost_mesh (mesh_partition_balance); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + t8_global_productionf (" [t8 step 4 Mesh handle] Creating ghost layer for mesh.\n"); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); - /* Printing the mesh information. */ - print_mesh_stats (mesh_ghost, "Ghost mesh", comm); + /** Call ghost helper function. */ + create_ghost_mesh (mesh); - /* Writing the mesh to vtu and pvtu files using the extended version of the function. */ - t8_mesh_handle::write_mesh_to_vtk_ext (*mesh_ghost, "ghost_mesh.vtu", 0, nullptr, true, true, true, true, true, false, - false); + /* Printing the mesh information. */ + print_mesh_stats (mesh, "Ghost mesh", comm); - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); - t8_global_productionf (" [t8 step 4 Mesh handle] Finished all steps successfully.\n"); - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + /* Writing the mesh to vtu and pvtu files using the extended version of the function. */ + t8_mesh_handle::write_mesh_to_vtk_ext (*mesh, "ghost_mesh.vtu", 0, nullptr, true, true, true, true, true, false, + false); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + t8_global_productionf (" [t8 step 4 Mesh handle] Finished all steps successfully.\n"); + t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + } /** Mesh scope end. */ sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); diff --git a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx index 9573dc2656..81f7c46091 100644 --- a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx +++ b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx @@ -20,7 +20,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/** \file t8_mesh_element_data.cxx +/** \file t8_mesh_step5_element_data.cxx * This is step5 of the mesh handle tutorials. * Therefore, this is the same as general/t8_step5_element_data.cxx but using the mesh handle interface instead of the forest * interface. @@ -34,9 +34,9 @@ #include /** General t8code header. Always include this. */ -#include /** General mesh header. Always needed for mesh_handle code. */ -#include /** Competence pack for basic mesh_handle features. Look into tutorials/mesh_handle/t8_mesh_competences for more information. */ -#include /** Wrapper for basic cmesh to mesh_handle conversions. */ +#include /** General mesh header. Always needed for mesh_handle code. */ +#include /** Competence pack for basic mesh_handle features. Look into tutorials/mesh_handle/t8_mesh_competences for more information. */ +#include /** Wrapper for basic cmesh to mesh_handle conversions. */ #include /** Used to export mesh to vtk files. */ #include /** Include this to use c++ concepts related to the mesh handle. This can be used to constraint the template parameters to only allow mesh handle classes. */ #include /** t8 vector dataclass. */ @@ -73,7 +73,7 @@ build_mesh (sc_MPI_Comm comm, int level) mesh_handle->set_balance (); mesh_handle->set_partition (); mesh_handle->set_adapt ( - TMeshClass::template mesh_adapt_callback_wrapper (&default_adapt_callback, adapt_params)); + TMeshClass::template mesh_adapt_callback_wrapper (&adapt_callback_sphere, adapt_params)); mesh_handle->set_ghost (); mesh_handle->commit (); return mesh_handle; diff --git a/tutorials/mesh_handle/t8_mesh_tutorials_common.hxx b/tutorials/mesh_handle/t8_mesh_tutorials_common.hxx index 530310c77b..19c910e2c3 100644 --- a/tutorials/mesh_handle/t8_mesh_tutorials_common.hxx +++ b/tutorials/mesh_handle/t8_mesh_tutorials_common.hxx @@ -20,7 +20,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/** \file t8_mesh_tutorials_common.hxx +/** \file t8_mesh_tutorials_common.hxx * This is the default adaptation callback function that can be used to refine and coarsen a mesh in a spherical shape around a given point. * It is used in step 3, 4 and 5 in the mesh_handle tutorials. */ @@ -37,7 +37,7 @@ * In this example we want to adapt in a spherical shape around a given point. */ struct adapt_data { - t8_3D_vec midpoint; /**< Midpoint of our sphere. */ + t8_3D_vec midpoint; /**< Midpoint of our sphere. */ double refine_radius; /**< We refine inside this radius of our sphere.*/ double coarsen_radius; /**< We coarsen outside this radius of our sphere. */ }; @@ -48,7 +48,7 @@ struct adapt_data * This will refine elements inside of a given sphere and coarsen elements * outside of a given sphere. * - * \tparam mesh_type The mesh handle class. + * \tparam TMeshClass The mesh handle class. * \param[in] mesh The mesh that should be adapted. * \param[in] elements One element or a family of elements to consider. * \param[in] adapt_data The user data used during adaptation. @@ -58,15 +58,15 @@ struct adapt_data * -1 if the family of elements should be coarsened, * 0 otherwise. */ -template +template int -default_adapt_callback ([[maybe_unused]] const mesh_type& mesh, - std::span elements, const adapt_data& adapt_data) +adapt_callback_sphere ([[maybe_unused]] const TMeshClass& mesh, + std::span elements, const adapt_data& adapt_data) { auto element_centroid = elements[0].get_centroid (); double dist = t8_dist (element_centroid, adapt_data.midpoint); - /** When this if statement returns true, we are inside the set radius of our "refinement sphere" of our point and therefore need to refine. */ + /** When this if statement returns true, we are inside the set radius of our "refinement sphere" of our point and therefore need to refine. */ if (dist < adapt_data.refine_radius) { return 1; /**< Refine. */ } From 4ab1785206edb5000a07f6fea25add897b4df740 Mon Sep 17 00:00:00 2001 From: Schmitt Date: Mon, 10 Aug 2026 16:44:13 +0200 Subject: [PATCH 11/20] change print labels --- .../t8_mesh_step4_partition_balance_ghost.cxx | 39 +++++++++---------- .../t8_mesh_step5_element_data.cxx | 27 +++++++------ 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx index d18e09be79..7c48b38e47 100644 --- a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx +++ b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx @@ -119,12 +119,11 @@ main (int argc, char** argv) sc_MPI_Comm comm = sc_MPI_COMM_WORLD; /* Print a starting message. */ - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); - t8_global_productionf ( - " [t8 step 4 Mesh handle] Hello, this is the mesh adaptation example of t8code using the mesh handle.\n"); - t8_global_productionf (" [t8 step 4 Mesh handle] In this example we will create a mesh, adapt, partition, balance " + t8_global_productionf (" [mesh_step4] \n"); + t8_global_productionf (" [mesh_step4] Hello, this is the mesh adaptation example of t8code using the mesh handle.\n"); + t8_global_productionf (" [mesh_step4] In this example we will create a mesh, adapt, partition, balance " "and create a ghost layer on it. \n"); - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + t8_global_productionf (" [mesh_step4] \n"); /* The initial uniform refinement level. */ int uniform_level = 3; @@ -136,9 +135,9 @@ main (int argc, char** argv) * INITIAL MESH */ - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); - t8_global_productionf (" [t8 step 4 Mesh handle] Creating initial mesh.\n"); - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + t8_global_productionf (" [mesh_step4] \n"); + t8_global_productionf (" [mesh_step4] Creating initial mesh.\n"); + t8_global_productionf (" [mesh_step4] \n"); { /** Mesh scope begin. */ /* Creating the initial mesh with uniform refinement. */ auto mesh = t8_mesh_handle::handle_hypercube_hybrid_uniform_default (uniform_level, comm); @@ -154,9 +153,9 @@ main (int argc, char** argv) * ADAPTED MESH */ - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); - t8_global_productionf (" [t8 step 4 Mesh handle] Creating adapted mesh.\n"); - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + t8_global_productionf (" [mesh_step4] \n"); + t8_global_productionf (" [mesh_step4] Creating adapted mesh.\n"); + t8_global_productionf (" [mesh_step4] \n"); /** Call adaption helper function. */ create_adapted_mesh (mesh, adapt_params); @@ -172,9 +171,9 @@ main (int argc, char** argv) * PARTITIONED, BALANCED MESH */ - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); - t8_global_productionf (" [t8 step 4 Mesh handle] Creating partitioned and balanced mesh.\n"); - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + t8_global_productionf (" [mesh_step4] \n"); + t8_global_productionf (" [mesh_step4] Creating partitioned and balanced mesh.\n"); + t8_global_productionf (" [mesh_step4] \n"); /** Adapting the mesh from above a second time to see a difference when balancing. */ create_adapted_mesh (mesh, adapt_params); @@ -193,9 +192,9 @@ main (int argc, char** argv) * GHOST MESH */ - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); - t8_global_productionf (" [t8 step 4 Mesh handle] Creating ghost layer for mesh.\n"); - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + t8_global_productionf (" [mesh_step4] \n"); + t8_global_productionf (" [mesh_step4] Creating ghost layer for mesh.\n"); + t8_global_productionf (" [mesh_step4] \n"); /** Call ghost helper function. */ create_ghost_mesh (mesh); @@ -207,9 +206,9 @@ main (int argc, char** argv) t8_mesh_handle::write_mesh_to_vtk_ext (*mesh, "ghost_mesh.vtu", 0, nullptr, true, true, true, true, true, false, false); - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); - t8_global_productionf (" [t8 step 4 Mesh handle] Finished all steps successfully.\n"); - t8_global_productionf (" [t8 step 4 Mesh handle] \n"); + t8_global_productionf (" [mesh_step4] \n"); + t8_global_productionf (" [mesh_step4] Finished all steps successfully.\n"); + t8_global_productionf (" [mesh_step4] \n"); } /** Mesh scope end. */ sc_finalize (); mpiret = sc_MPI_Finalize (); diff --git a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx index 81f7c46091..bda91a69c8 100644 --- a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx +++ b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx @@ -164,17 +164,16 @@ main (int argc, char **argv) sc_MPI_Comm comm = sc_MPI_COMM_WORLD; /* Print a message on the root process. */ - t8_global_productionf (" [t8 Step 5 Mesh handle] \n"); - t8_global_productionf ( - " [t8 Step 5 Mesh handle] Hello, this is the element data example of t8code using the mesh handle.\n"); - t8_global_productionf (" [t8 Step 5 Mesh handle] In this example we will store data on our elements and exchange the " + t8_global_productionf (" [mesh_step5] \n"); + t8_global_productionf (" [mesh_step5] Hello, this is the element data example of t8code using the mesh handle.\n"); + t8_global_productionf (" [mesh_step5] In this example we will store data on our elements and exchange the " "data of ghost elements.\n"); - t8_global_productionf (" [t8 Step 5 Mesh handle] \n"); + t8_global_productionf (" [mesh_step5] \n"); /* Setup: Build cmesh and adapt uniformly. */ - t8_global_productionf (" [t8 Step 5 Mesh handle] \n"); - t8_global_productionf (" [t8 Step 5 Mesh handle] Creating an adapted mesh.\n"); - t8_global_productionf (" [t8 Step 5 Mesh handle] \n"); + t8_global_productionf (" [mesh_step5] \n"); + t8_global_productionf (" [mesh_step5] Creating an adapted mesh.\n"); + t8_global_productionf (" [mesh_step5] \n"); { /* We put the mesh in its own scope so that it is automatically destroyed at the end of the scope. * This is only necessary because sc_finalize checks if there are leftover references. * This unique pointer would have been destroyed automatically at the end of the programme. */ @@ -183,30 +182,30 @@ main (int argc, char **argv) auto mesh = build_mesh (comm, level); t8_mesh_handle::write_mesh_to_vtk (*mesh, prefix_mesh); - t8_global_productionf (" [t8 Step 5 Mesh handle] Wrote mesh to vtu files: %s*\n", prefix_mesh); + t8_global_productionf (" [mesh_step5] Wrote mesh to vtu files: %s*\n", prefix_mesh); set_element_data_mesh (*mesh); - t8_global_productionf (" [t8 Step 5 Mesh handle] Computed level and volume data for local elements.\n"); + t8_global_productionf (" [mesh_step5] Computed level and volume data for local elements.\n"); if (mesh->get_num_local_elements () > 0) { /* Output the stored data of the first local element (if it exists). */ - t8_global_productionf (" [t8 Step 5 Mesh handle] Element 0 has level %i and volume %e.\n", + t8_global_productionf (" [mesh_step5] Element 0 has level %i and volume %e.\n", ((*mesh)[0]).get_element_data ().level, ((*mesh)[0]).get_element_data ().volume); } /* Exchange the data values of the ghost elements. */ exchange_ghost_data_mesh (*mesh); - t8_global_productionf (" [t8 Step 5 Mesh handle] Exchanged ghost data.\n"); + t8_global_productionf (" [mesh_step5] Exchanged ghost data.\n"); if (mesh->get_num_ghosts () > 0) { /* Output the data of the first ghost element (if it exists). */ t8_locidx_t first_ghost_index = mesh->get_num_local_elements (); - t8_global_productionf (" [t8 Step 5 Mesh handle] Ghost 0 has level %i and volume %e.\n", + t8_global_productionf (" [mesh_step5] Ghost 0 has level %i and volume %e.\n", ((*mesh)[first_ghost_index]).get_element_data ().level, ((*mesh)[first_ghost_index]).get_element_data ().volume); } /* Output the volume data to vtu. */ output_data_to_vtu (*mesh, prefix_mesh_with_data); - t8_global_productionf (" [t8 Step 5 Mesh handle] Wrote mesh and volume data to %s*.\n", prefix_mesh_with_data); + t8_global_productionf (" [mesh_step5] Wrote mesh and volume data to %s*.\n", prefix_mesh_with_data); /* Cleanup. */ } // End scope of mesh From a06cc2dec28ad260d3a82dba44dec635911c0d63 Mon Sep 17 00:00:00 2001 From: Schmitt Date: Sun, 23 Aug 2026 10:57:49 +0200 Subject: [PATCH 12/20] Fixing comments --- .../mesh_handle/t8_mesh_step3_adapt_mesh.cxx | 16 +++--- .../t8_mesh_step4_partition_balance_ghost.cxx | 54 +++++++++---------- .../t8_mesh_step5_element_data.cxx | 2 +- 3 files changed, 38 insertions(+), 34 deletions(-) diff --git a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx index d0942e43ae..8b7e685fb7 100644 --- a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx +++ b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx @@ -36,13 +36,15 @@ * of any element will change by at most +-1. */ -#include /** General t8code header. Always include this. */ -#include /** General mesh header. Always needed for mesh_handle code. */ -#include /** Competence pack for basic mesh_handle features. Look into tutorials/mesh_handle/t8_mesh_competences for more information. */ +#include /** General t8code header. Always include this. */ +#include /** General mesh header. Always needed for mesh_handle code. */ +#include /** Competence pack for basic mesh_handle features. + * Look into tutorials/mesh_handle/t8_mesh_competences for more information. */ #include /** Wrapper for basic cmesh to mesh_handle conversions. */ #include /** Used to export mesh to vtk files. */ -#include /** Include this to use c++ concepts related to the mesh handle. This can be used to constraint the template parameters to only allow mesh handle classes. */ -#include "t8_mesh_tutorials_common.hxx" /** Adaption function definition used for this tutorial. */ +#include /** Include this to use c++ concepts related to the mesh handle. + * This can be used to constraint the template parameters to only allow mesh handle classes. */ +#include "t8_mesh_tutorials_common.hxx" /** Adaption function definition used for this tutorial. */ #include /** Build our adapted mesh by transferring the adaption parameters and adapting once with our \ref adapt_callback function. @@ -57,6 +59,8 @@ build_mesh (sc_MPI_Comm comm, int level) { /* Generate a hybrid hypercube, made out of cubes, prisms etc. */ auto mesh = t8_mesh_handle::handle_hypercube_hybrid_uniform_default (level, comm); + /* Saving the initial mesh to vtu files to compare them later. */ + t8_mesh_handle::write_mesh_to_vtk (*mesh, "step3_initial_uniform_mesh.vtu"); /* Defining the adaption parameters. */ adapt_data adapt_params = { { 0.5, 0.5, 1.0 }, 0.2, 0.4 }; /** Adapting once using our adapt callback. @@ -100,7 +104,7 @@ main (int argc, char **argv) t8_global_productionf (" [mesh_step3] Creating an adapted mesh.\n"); t8_global_productionf (" [mesh_step3] \n"); /* The initial uniform refinement level. */ - int uniform_level = 3; + const int uniform_level = 3; /* Building the mesh. */ { /** Scope to ensure mesh is deleted properly. */ auto mesh = build_mesh (comm, uniform_level); diff --git a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx index 7c48b38e47..d6007f4ac1 100644 --- a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx +++ b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx @@ -20,14 +20,13 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/** \file t8_mesh_element_data.cxx +/** \file t8_mesh_step4_partition_balance_ghost.cxx * This is step4 of the t8code mesh handle tutorials. * Therefore, this is the same as general/t8_step4_partition_balance_ghost.cxx but using the mesh handle interface instead of the forest * interface. * After generating a coarse mesh (step1), building a uniform mesh * on it (step2) and adapting this mesh (step3) - * we will now learn how to control the mesh creation in more detail, - * how to partition and balance a mesh and how to generate a layer of ghost elements. + * we will now learn how to partition and balance a mesh and how to generate a layer of ghost elements. */ #include /** General t8code header. Always include this. */ @@ -36,9 +35,8 @@ #include /** Wrapper for basic cmesh to mesh_handle conversions. */ #include /** Include this to use c++ concepts related to the mesh handle. This can be used to constraint the template parameters to only allow mesh handle classes. */ #include /** t8 vector dataclass. */ -#include "t8_mesh_tutorials_common.hxx" /** Default adaption function. */ +#include "t8_mesh_tutorials_common.hxx" /** Adaption function definition used for this tutorial. */ #include -#include using mesh_type = t8_mesh_handle:: mesh<>; /**< Mesh class used in this tutorial. We define it globally to get rid of the function templates to simplify the code. */ @@ -49,43 +47,43 @@ using mesh_type = t8_mesh_handle:: * \param comm The MPI communicator to use for the reduction and printing. */ void -print_mesh_stats (const std::unique_ptr& mesh, const char* stage, sc_MPI_Comm comm) +print_mesh_stats (const std::unique_ptr& mesh, const char* stage) { int local_elements = mesh->get_num_local_elements (); - int global_elements = 0; - MPI_Allreduce (&local_elements, &global_elements, 1, MPI_INT, MPI_SUM, comm); + int global_elements = mesh->get_num_global_elements (); t8_global_productionf (" [mesh_step4] === %s === \n", stage); + t8_global_productionf (" [mesh_step4] Local elements on this process: %i \n", local_elements); t8_global_productionf (" [mesh_step4] Total elements: %i \n", global_elements); } -/** Helper function to create an adapted mesh from an initial mesh. +/** Helper function to adapt a given mesh using the predefined adaption callback function. * \param mesh The initial mesh to adapt. * \param adapt_params The adaptation parameters to use for the adaptation. */ void create_adapted_mesh (std::unique_ptr& mesh, const adapt_data& adapt_params) { - /* Adapting the mesh once with our adapt_callback_sphere function from step 3 and the adapt_params. Both can be found in the file \ref t8_mesh_tutorials_common.hxx. */ + /* Setting the adapt-flag with our adapt_callback_sphere function from step 3 and the adapt_params. Both can be found in the file \ref t8_mesh_tutorials_common.hxx. */ mesh->set_adapt ( mesh_type::template mesh_adapt_callback_wrapper (&adapt_callback_sphere, adapt_params)); - /* Committing the adapted mesh. */ + /* Committing the mesh. */ mesh->commit (); } -/** Helper function to create a partitioned and balanced mesh from an initial mesh. +/** Helper function to partition and balance a given mesh. * \param mesh The initial mesh to adapt. */ void create_partitioned_balanced_mesh (const std::unique_ptr& mesh) { - /* Calculate partition information.*/ + /* Setting partition flag.*/ mesh->set_partition (); - /* Calculate balancing information. */ + /* Setting balancing flag. */ mesh->set_balance (); - /* Committing the mesh --> modifying the mesh according to the precalculated information. */ + /* Committing the mesh. */ mesh->commit (); } @@ -126,10 +124,10 @@ main (int argc, char** argv) t8_global_productionf (" [mesh_step4] \n"); /* The initial uniform refinement level. */ - int uniform_level = 3; + const int uniform_level = 3; /* Parameters for the adaption step. */ - struct adapt_data adapt_params = { { 0.5, 0.5, 1.0 }, 0.2, 0.4 }; + adapt_data adapt_params = { { 0.5, 0.5, 1.0 }, 0.2, 0.4 }; /** * INITIAL MESH @@ -143,15 +141,15 @@ main (int argc, char** argv) auto mesh = t8_mesh_handle::handle_hypercube_hybrid_uniform_default (uniform_level, comm); /* Printing the mesh information. */ - print_mesh_stats (mesh, "Initial mesh", comm); + print_mesh_stats (mesh, "Initial mesh"); /* Writing the mesh to vtu and pvtu files, using the extended version of the function to ensure additional data like ghost elements, treeid etc. to be written into the files. */ t8_mesh_handle::write_mesh_to_vtk_ext (*mesh, "initial_mesh.vtu", 0, nullptr, true, true, true, true, true, false, false); /** - * ADAPTED MESH - */ + * ADAPTED MESH + */ t8_global_productionf (" [mesh_step4] \n"); t8_global_productionf (" [mesh_step4] Creating adapted mesh.\n"); @@ -161,15 +159,15 @@ main (int argc, char** argv) create_adapted_mesh (mesh, adapt_params); /* Printing the mesh information. */ - print_mesh_stats (mesh, "Adapted mesh", comm); + print_mesh_stats (mesh, "Adapted mesh"); /* Writing the mesh to vtu and pvtu files using the extended version of the function. */ t8_mesh_handle::write_mesh_to_vtk_ext (*mesh, "adapted_mesh.vtu", 0, nullptr, true, true, true, true, true, false, false); /** - * PARTITIONED, BALANCED MESH - */ + * PARTITIONED, BALANCED MESH + */ t8_global_productionf (" [mesh_step4] \n"); t8_global_productionf (" [mesh_step4] Creating partitioned and balanced mesh.\n"); @@ -182,15 +180,15 @@ main (int argc, char** argv) create_partitioned_balanced_mesh (mesh); /* Printing the mesh information. */ - print_mesh_stats (mesh, "Partitioned and Balanced mesh", comm); + print_mesh_stats (mesh, "Partitioned and Balanced mesh"); /* Writing the mesh to vtu and pvtu files using the extended version of the function. */ t8_mesh_handle::write_mesh_to_vtk_ext (*mesh, "partition_balance_mesh.vtu", 0, nullptr, true, true, true, true, true, false, false); /** - * GHOST MESH - */ + * GHOST MESH + */ t8_global_productionf (" [mesh_step4] \n"); t8_global_productionf (" [mesh_step4] Creating ghost layer for mesh.\n"); @@ -200,7 +198,9 @@ main (int argc, char** argv) create_ghost_mesh (mesh); /* Printing the mesh information. */ - print_mesh_stats (mesh, "Ghost mesh", comm); + print_mesh_stats (mesh, "Ghost mesh"); + int ghost_elements = mesh->get_num_ghosts (); + t8_global_productionf (" [mesh_step4] Number of ghost elements: %i \n", ghost_elements); /* Writing the mesh to vtu and pvtu files using the extended version of the function. */ t8_mesh_handle::write_mesh_to_vtk_ext (*mesh, "ghost_mesh.vtu", 0, nullptr, true, true, true, true, true, false, diff --git a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx index edf6407aa4..f210ea46a3 100644 --- a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx +++ b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx @@ -64,7 +64,7 @@ std::unique_ptr build_mesh (sc_MPI_Comm comm, int level) { auto mesh_handle = t8_mesh_handle::handle_hypercube_hybrid_uniform_default (level, comm); - struct adapt_data adapt_params = { + adapt_data adapt_params = { { 0.5, 0.5, 1 }, /* Midpoint of the sphere. */ 0.2, /* Refine if inside this radius. */ 0.4 /* Coarsen if outside this radius. */ From 8500924d30ee23fe0ceb03eddd2436052c201254 Mon Sep 17 00:00:00 2001 From: Schmitt Date: Sun, 23 Aug 2026 11:41:22 +0200 Subject: [PATCH 13/20] Fixed Doxygen errorrs --- tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx | 4 ++-- .../mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx index 8b7e685fb7..d496736c93 100644 --- a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx +++ b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx @@ -47,9 +47,9 @@ #include "t8_mesh_tutorials_common.hxx" /** Adaption function definition used for this tutorial. */ #include -/** Build our adapted mesh by transferring the adaption parameters and adapting once with our \ref adapt_callback function. +/** Build our adapted mesh by transferring the adaption parameters and adapting once with our \ref adapt_callback_sphere function. * \tparam TMeshClass The mesh handle class. - * \param sc_MPI_Comm The MPI communicator. + * \param comm The MPI communicator. * \param level The initial uniform refinement level. * \returns Unique pointer to the adapted mesh. */ diff --git a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx index d6007f4ac1..6ae236c6a5 100644 --- a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx +++ b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx @@ -44,7 +44,6 @@ using mesh_type = t8_mesh_handle:: /** Helper function to print the total number of elements in the mesh after each step. * \param mesh The mesh handle to get the number of elements from. * \param stage The stage of the mesh (e.g. "Initial mesh", "Adapted mesh", etc.) to print in the output. - * \param comm The MPI communicator to use for the reduction and printing. */ void print_mesh_stats (const std::unique_ptr& mesh, const char* stage) From c800745350a695110a72ee2c4ae6630aaffd4d34 Mon Sep 17 00:00:00 2001 From: Schmitt Date: Sun, 23 Aug 2026 11:52:52 +0200 Subject: [PATCH 14/20] Fixed Doxygen errors --- tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx | 2 +- tutorials/mesh_handle/t8_mesh_step5_element_data.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx index d496736c93..78cdd4bdbd 100644 --- a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx +++ b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx @@ -47,7 +47,7 @@ #include "t8_mesh_tutorials_common.hxx" /** Adaption function definition used for this tutorial. */ #include -/** Build our adapted mesh by transferring the adaption parameters and adapting once with our \ref adapt_callback_sphere function. +/** Build our adapted mesh by transferring the adaption parameters and adapting once with our \ref t8_mesh_tutorials_common::adapt_callback_sphere function. * \tparam TMeshClass The mesh handle class. * \param comm The MPI communicator. * \param level The initial uniform refinement level. diff --git a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx index f210ea46a3..fa27f74049 100644 --- a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx +++ b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx @@ -52,7 +52,7 @@ struct data_per_element_type double volume; /**< Volume of the element. */ }; -/** Build a mesh with initial uniform refinement level \a level which is adapted according to \ref adapt_callback, +/** Build a mesh with initial uniform refinement level \a level which is adapted according to \ref t8_mesh_tutorials_common::adapt_callback_sphere, * partitioned and balanced afterwards, and ghost elements are set. * \tparam TMeshClass The mesh handle class. * \param [in] comm MPI communicator to use. From 695c841e8eda50a0352691656e8fa7e392d731f1 Mon Sep 17 00:00:00 2001 From: Schmitt Date: Sun, 23 Aug 2026 12:27:14 +0200 Subject: [PATCH 15/20] Doxygen errors --- tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx | 2 +- tutorials/mesh_handle/t8_mesh_step5_element_data.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx index 78cdd4bdbd..ea66615789 100644 --- a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx +++ b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx @@ -47,7 +47,7 @@ #include "t8_mesh_tutorials_common.hxx" /** Adaption function definition used for this tutorial. */ #include -/** Build our adapted mesh by transferring the adaption parameters and adapting once with our \ref t8_mesh_tutorials_common::adapt_callback_sphere function. +/** Build our adapted mesh by transferring the adaption parameters and adapting once with our adapt_callback_sphere function from \ref t8_mesh_tutorials_common. * \tparam TMeshClass The mesh handle class. * \param comm The MPI communicator. * \param level The initial uniform refinement level. diff --git a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx index fa27f74049..0b7817463f 100644 --- a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx +++ b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx @@ -52,7 +52,7 @@ struct data_per_element_type double volume; /**< Volume of the element. */ }; -/** Build a mesh with initial uniform refinement level \a level which is adapted according to \ref t8_mesh_tutorials_common::adapt_callback_sphere, +/** Build a mesh with initial uniform refinement level \a level which is adapted according to the adapt_callback_sphere function from \ref t8_mesh_tutorials_common, * partitioned and balanced afterwards, and ghost elements are set. * \tparam TMeshClass The mesh handle class. * \param [in] comm MPI communicator to use. From a0c918c5bb6aa837776115653a74c1c3ae364a5a Mon Sep 17 00:00:00 2001 From: Schmitt Date: Sun, 23 Aug 2026 12:30:51 +0200 Subject: [PATCH 16/20] Doxygen errors --- tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx | 2 +- tutorials/mesh_handle/t8_mesh_step5_element_data.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx index ea66615789..303b5e8ac0 100644 --- a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx +++ b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx @@ -47,7 +47,7 @@ #include "t8_mesh_tutorials_common.hxx" /** Adaption function definition used for this tutorial. */ #include -/** Build our adapted mesh by transferring the adaption parameters and adapting once with our adapt_callback_sphere function from \ref t8_mesh_tutorials_common. +/** Build our adapted mesh by transferring the adaption parameters and adapting once with our adapt_callback_sphere function. * \tparam TMeshClass The mesh handle class. * \param comm The MPI communicator. * \param level The initial uniform refinement level. diff --git a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx index 0b7817463f..9e176e654e 100644 --- a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx +++ b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx @@ -52,7 +52,7 @@ struct data_per_element_type double volume; /**< Volume of the element. */ }; -/** Build a mesh with initial uniform refinement level \a level which is adapted according to the adapt_callback_sphere function from \ref t8_mesh_tutorials_common, +/** Build a mesh with initial uniform refinement level \a level which is adapted according to the adapt_callback_sphere function, * partitioned and balanced afterwards, and ghost elements are set. * \tparam TMeshClass The mesh handle class. * \param [in] comm MPI communicator to use. From 6a44696f9241a64741296dad2fb95e4a7eda4cd2 Mon Sep 17 00:00:00 2001 From: Schmitt Date: Wed, 30 Sep 2026 16:52:29 +0200 Subject: [PATCH 17/20] Changed comments and mesh creation in step 3 --- .../mesh_handle/t8_mesh_step3_adapt_mesh.cxx | 25 +++++++++++-------- .../t8_mesh_step4_partition_balance_ghost.cxx | 20 +++++++-------- .../t8_mesh_step5_element_data.cxx | 2 +- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx index 303b5e8ac0..8d85237ddb 100644 --- a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx +++ b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx @@ -29,7 +29,7 @@ * according to our own criterion. * * The geometry (coarse mesh) is again a cube, this time modelled with - * 6 tetrahedra, 6 prisms and 4 cubes. + * 6 tetrahedra, 6 prisms and 4 hexahedra. * We refine an element if its midpoint is within a sphere of given radius * around the point (0.5, 0.5, 1) and we coarsen outside of a given radius. * We will use non-recursive refinement, that means that the refinement level @@ -47,7 +47,7 @@ #include "t8_mesh_tutorials_common.hxx" /** Adaption function definition used for this tutorial. */ #include -/** Build our adapted mesh by transferring the adaption parameters and adapting once with our adapt_callback_sphere function. +/** Build our adapted mesh by transferring the adaption parameters and adapting once with the adapt_callback_sphere function defined in \ref t8_mesh_tutorials_common.hxx. * \tparam TMeshClass The mesh handle class. * \param comm The MPI communicator. * \param level The initial uniform refinement level. @@ -55,12 +55,12 @@ */ template std::unique_ptr -build_mesh (sc_MPI_Comm comm, int level) +build_adapted_mesh (std::unique_ptr mesh) { - /* Generate a hybrid hypercube, made out of cubes, prisms etc. */ - auto mesh = t8_mesh_handle::handle_hypercube_hybrid_uniform_default (level, comm); + /* Setting file name for vtk export. */ + const char *prefix_initial = "step3_initial_uniform_mesh"; /* Saving the initial mesh to vtu files to compare them later. */ - t8_mesh_handle::write_mesh_to_vtk (*mesh, "step3_initial_uniform_mesh.vtu"); + t8_mesh_handle::write_mesh_to_vtk (*mesh, prefix_initial); /* Defining the adaption parameters. */ adapt_data adapt_params = { { 0.5, 0.5, 1.0 }, 0.2, 0.4 }; /** Adapting once using our adapt callback. @@ -78,6 +78,8 @@ build_mesh (sc_MPI_Comm comm, int level) int main (int argc, char **argv) { + /* Set file name for vtk export. */ + const char *prefix_adapted = "step3_adapted_mesh"; /* Initialize MPI. This has to happen before we initialize sc or t8code. */ int mpiret = sc_MPI_Init (&argc, &argv); /* Error check the MPI return value. */ @@ -106,13 +108,16 @@ main (int argc, char **argv) /* The initial uniform refinement level. */ const int uniform_level = 3; /* Building the mesh. */ - { /** Scope to ensure mesh is deleted properly. */ - auto mesh = build_mesh (comm, uniform_level); + { /* Scope to ensure mesh is deleted properly. */ + /* Generate a hybrid hypercube, made out of hexahedra, prisms etc. */ + auto mesh = t8_mesh_handle::handle_hypercube_hybrid_uniform_default (uniform_level, comm); + /* Call the function that handles the adaption. */ + mesh = build_adapted_mesh (std::move (mesh)); /* Write the mesh to a vtu file. */ t8_global_productionf (" [mesh_step3] \n"); - t8_global_productionf (" [mesh_step3] Writing adapted mesh to vtu file: step3_adapted_mesh.vtu\n"); + t8_global_productionf (" [mesh_step3] Writing adapted mesh to vtu files: %s*\n", prefix_adapted); t8_global_productionf (" [mesh_step3] \n"); - t8_mesh_handle::write_mesh_to_vtk (*mesh, "step3_adapted_mesh.vtu"); + t8_mesh_handle::write_mesh_to_vtk (*mesh, prefix_adapted); } sc_finalize (); mpiret = sc_MPI_Finalize (); diff --git a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx index 6ae236c6a5..60aa3f32cf 100644 --- a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx +++ b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx @@ -52,7 +52,7 @@ print_mesh_stats (const std::unique_ptr& mesh, const char* stage) int global_elements = mesh->get_num_global_elements (); t8_global_productionf (" [mesh_step4] === %s === \n", stage); - t8_global_productionf (" [mesh_step4] Local elements on this process: %i \n", local_elements); + t8_global_productionf (" [mesh_step4] Local elements on the root process: %i \n", local_elements); t8_global_productionf (" [mesh_step4] Total elements: %i \n", global_elements); } @@ -61,7 +61,7 @@ print_mesh_stats (const std::unique_ptr& mesh, const char* stage) * \param adapt_params The adaptation parameters to use for the adaptation. */ void -create_adapted_mesh (std::unique_ptr& mesh, const adapt_data& adapt_params) +step4_adapt_mesh (std::unique_ptr& mesh, const adapt_data& adapt_params) { /* Setting the adapt-flag with our adapt_callback_sphere function from step 3 and the adapt_params. Both can be found in the file \ref t8_mesh_tutorials_common.hxx. */ mesh->set_adapt ( @@ -74,7 +74,7 @@ create_adapted_mesh (std::unique_ptr& mesh, const adapt_data& adapt_p * \param mesh The initial mesh to adapt. */ void -create_partitioned_balanced_mesh (const std::unique_ptr& mesh) +step4_partition_balance_mesh (const std::unique_ptr& mesh) { /* Setting partition flag.*/ mesh->set_partition (); @@ -90,9 +90,9 @@ create_partitioned_balanced_mesh (const std::unique_ptr& mesh) * \param mesh The initial mesh to adapt. */ void -create_ghost_mesh (const std::unique_ptr& mesh) +step4_ghost_mesh (const std::unique_ptr& mesh) { - /* Creating the ghost layers. */ + /* Set flag such that ghost layer is created on commit. */ mesh->set_ghost (); /* Committing the ghost mesh. */ @@ -155,7 +155,7 @@ main (int argc, char** argv) t8_global_productionf (" [mesh_step4] \n"); /** Call adaption helper function. */ - create_adapted_mesh (mesh, adapt_params); + step4_adapt_mesh (mesh, adapt_params); /* Printing the mesh information. */ print_mesh_stats (mesh, "Adapted mesh"); @@ -173,10 +173,10 @@ main (int argc, char** argv) t8_global_productionf (" [mesh_step4] \n"); /** Adapting the mesh from above a second time to see a difference when balancing. */ - create_adapted_mesh (mesh, adapt_params); + step4_adapt_mesh (mesh, adapt_params); /** Call partitioning and balancing helper function. */ - create_partitioned_balanced_mesh (mesh); + step4_partition_balance_mesh (mesh); /* Printing the mesh information. */ print_mesh_stats (mesh, "Partitioned and Balanced mesh"); @@ -186,7 +186,7 @@ main (int argc, char** argv) true, false, false); /** - * GHOST MESH + * GHOST LAYER */ t8_global_productionf (" [mesh_step4] \n"); @@ -194,7 +194,7 @@ main (int argc, char** argv) t8_global_productionf (" [mesh_step4] \n"); /** Call ghost helper function. */ - create_ghost_mesh (mesh); + step4_ghost_mesh (mesh); /* Printing the mesh information. */ print_mesh_stats (mesh, "Ghost mesh"); diff --git a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx index 9e176e654e..52f04cc03f 100644 --- a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx +++ b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx @@ -40,7 +40,7 @@ #include /** Used to export mesh to vtk files. */ #include /** Include this to use c++ concepts related to the mesh handle. This can be used to constraint the template parameters to only allow mesh handle classes. */ #include /** t8 vector dataclass. */ -#include "t8_mesh_tutorials_common.hxx" /** Default adaption function. */ +#include "t8_mesh_tutorials_common.hxx" /** Adaption function definition used for this tutorial. */ #include #include From ff03b4809f957d884d20ef3a39927b30bd282637 Mon Sep 17 00:00:00 2001 From: Schmitt Date: Thu, 1 Oct 2026 15:15:37 +0200 Subject: [PATCH 18/20] Doxygen fix --- tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx index 8d85237ddb..f5c9b5240a 100644 --- a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx +++ b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx @@ -49,8 +49,7 @@ /** Build our adapted mesh by transferring the adaption parameters and adapting once with the adapt_callback_sphere function defined in \ref t8_mesh_tutorials_common.hxx. * \tparam TMeshClass The mesh handle class. - * \param comm The MPI communicator. - * \param level The initial uniform refinement level. + * \param mesh The mesh that should be adapted. * \returns Unique pointer to the adapted mesh. */ template From 11e15a7904d0f77d0b8f02fc97b52cde1a265d3a Mon Sep 17 00:00:00 2001 From: Schmitt Date: Mon, 5 Oct 2026 16:21:58 +0200 Subject: [PATCH 19/20] fixed pr - temporary, step 3 has run error --- .../mesh_handle/t8_mesh_step5_element_data.cxx | 8 ++++++-- .../mesh_handle/t8_mesh_tutorials_common.hxx | 16 ++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx index f23da65ee7..674ad71cbf 100644 --- a/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx +++ b/tutorials/mesh_handle/t8_mesh_step5_element_data.cxx @@ -35,10 +35,10 @@ #include /** General t8code header. Always include this. */ #include /** General mesh header. Always needed for mesh_handle code. */ -#include /** Competence pack for basic mesh_handle features. Look into tutorials/mesh_handle/t8_mesh_competences for more information. */ +#include /** Competence pack for basic mesh_handle features. Look into tutorials/mesh_handle/t8_mesh_stepA_competences for more information. */ #include /** Wrapper for basic cmesh to mesh_handle conversions. */ #include /** Used to export mesh to vtk files. */ -#include /** Include this to use c++ concepts related to the mesh handle. This can be used to constraint the template parameters to only allow mesh handle classes. */ +#include /** Include this to use c++ concepts related to the mesh handle. This can be used to constrain the template parameters to only allow mesh handle classes. */ #include /** t8 vector dataclass. */ #include "t8_mesh_tutorials_common.hxx" /** Adaption function definition used for this tutorial. */ #include @@ -70,6 +70,10 @@ build_mesh (sc_MPI_Comm comm, int level) 0.4 /* Coarsen if outside this radius. */ }; /* Adapt, partition, balance and create ghost elements. */ + /** This is not doing anything here, because we only adapt once before this line, + * so the difference between elements is +1 or -1 at most. + * We still include it here for demonstration purposes. + */ mesh_handle->set_balance (); mesh_handle->set_partition (); mesh_handle->set_adapt ( diff --git a/tutorials/mesh_handle/t8_mesh_tutorials_common.hxx b/tutorials/mesh_handle/t8_mesh_tutorials_common.hxx index 19c910e2c3..85dccaeea2 100644 --- a/tutorials/mesh_handle/t8_mesh_tutorials_common.hxx +++ b/tutorials/mesh_handle/t8_mesh_tutorials_common.hxx @@ -51,7 +51,7 @@ struct adapt_data * \tparam TMeshClass The mesh handle class. * \param[in] mesh The mesh that should be adapted. * \param[in] elements One element or a family of elements to consider. - * \param[in] adapt_data The user data used during adaptation. + * \param[in] adapt_params The user data used during adaptation. * * \return * 1 if the first element should be refined, @@ -61,20 +61,20 @@ struct adapt_data template int adapt_callback_sphere ([[maybe_unused]] const TMeshClass& mesh, - std::span elements, const adapt_data& adapt_data) + std::span elements, const adapt_data& adapt_params) { auto element_centroid = elements[0].get_centroid (); - double dist = t8_dist (element_centroid, adapt_data.midpoint); + double dist = t8_dist (element_centroid, adapt_params.midpoint); /** When this if statement returns true, we are inside the set radius of our "refinement sphere" of our point and therefore need to refine. */ - if (dist < adapt_data.refine_radius) { - return 1; /**< Refine. */ + if (dist < adapt_params.refine_radius) { + return 1; /* Refine. */ } /** Only coarsen if we actually have a complete family. */ - if ((elements.size () > 1) && (dist > adapt_data.coarsen_radius)) { - return -1; /**< Coarsen. */ + if ((elements.size () > 1) && (dist > adapt_params.coarsen_radius)) { + return -1; /* Coarsen. */ } - return 0; /**< Do nothing. */ + return 0; /* Do nothing. */ } From 80cbf78caa71a650528059131ab3af60b1faa7ab Mon Sep 17 00:00:00 2001 From: Schmitt Date: Thu, 8 Oct 2026 10:27:39 +0200 Subject: [PATCH 20/20] Fixed unknown error and finished requested changes --- .../mesh_handle/t8_mesh_step3_adapt_mesh.cxx | 21 +++++----- .../t8_mesh_step4_partition_balance_ghost.cxx | 40 +++++++++---------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx index 12bf7912db..280c288b8e 100644 --- a/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx +++ b/tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx @@ -36,18 +36,18 @@ * of any element will change by at most +-1. */ -#include /** General t8code header. Always include this. */ -#include /** General mesh header. Always needed for mesh_handle code. */ -#include /** Used to export mesh to vtk files. */ -#include /** Include this to use c++ concepts related to the mesh handle. - * This can be used to constrain the template parameters to only allow mesh handle classes. */ -#include "t8_mesh_tutorials_common.hxx" /** Adaption function definition used for this tutorial. */ +#include /** General t8code header. Always include this. */ +#include /** General mesh header. Always needed for mesh_handle code. */ +#include /** Used to export mesh to vtk files. */ +#include /** Wrapper for basic cmesh to mesh_handle conversions. */ +#include /** Include this to use c++ concepts related to the mesh handle. + * This can be used to constrain the template parameters to only allow mesh handle classes. */ +#include "t8_mesh_tutorials_common.hxx" /** Adaption function definition used for this tutorial. */ #include /** Build our adapted mesh by transferring the adaption parameters and adapting once with the adapt_callback_sphere function defined in \ref t8_mesh_tutorials_common.hxx. * \tparam TMeshClass The mesh handle class. * \param [in] mesh The mesh that should be adapted. - * \returns Unique pointer to the adapted mesh. */ template void @@ -60,10 +60,9 @@ step3_adapt_mesh (TMeshClass &mesh) * commit() is the function that actually builds the new, adapted mesh from these settings. * This "configure, then commit" split lets t8code carry out several mesh operations together in one efficient pass, rather than one at a time. */ - mesh->set_adapt ( + mesh.set_adapt ( TMeshClass::template mesh_adapt_callback_wrapper (&adapt_callback_sphere, adapt_params)); - mesh->commit (); - return mesh; + mesh.commit (); } /** Entry point of the program. */ @@ -109,7 +108,7 @@ main (int argc, char **argv) t8_mesh_handle::write_mesh_to_vtk (*mesh, prefix_initial); /* Call the function that handles the adaption. */ - mesh = step3_adapt_mesh (std::move (mesh)); + step3_adapt_mesh (*mesh); /* Write the mesh to a vtu file. */ t8_global_productionf (" [mesh_step3] Writing adapted mesh to vtu files: %s*\n", prefix_adapted); t8_global_productionf (" [mesh_step3] \n"); diff --git a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx index 5faa38a2e0..c2b1bef11b 100644 --- a/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx +++ b/tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx @@ -48,19 +48,20 @@ using mesh_type = t8_mesh_handle:: /** Helper function to print the total number of elements in the mesh after each step. * \param [in] mesh The mesh handle to get the number of elements from. * \param [in] stage The stage of the mesh (e.g. "Initial mesh", "Adapted mesh", etc.) to print in the output. + * \param [in] prefix The prefix for the filename of the exported vtk files. */ void print_stats_and_export (mesh_type& mesh, const char* stage, const char* prefix) { - t8_locidx_t local_elements = mesh->get_num_local_elements (); - t8_gloidx_t global_elements = mesh->get_num_global_elements (); + t8_locidx_t local_elements = mesh.get_num_local_elements (); + t8_gloidx_t global_elements = mesh.get_num_global_elements (); t8_global_productionf (" [mesh_step4] === %s === \n", stage); t8_global_productionf (" [mesh_step4] Local elements on the root process: %i \n", local_elements); - t8_global_productionf (" [mesh_step4] Total elements: %i \n", global_elements); + t8_global_productionf (" [mesh_step4] Total elements: %li \n", global_elements); /* Writing the mesh to vtu and pvtu files, using the extended version of the function to ensure additional data like ghost elements, treeid etc. to be written into the files. */ - t8_mesh_handle::write_mesh_to_vtk_ext (*mesh, prefix, 0, nullptr, true, true, true, true, true, false, false); + t8_mesh_handle::write_mesh_to_vtk_ext (mesh, prefix, 0, nullptr, true, true, true, true, true, false, false); } /** Helper function to adapt a given mesh using the predefined adaption callback function. @@ -72,10 +73,9 @@ void step4_adapt_mesh (mesh_type& mesh, const adapt_data& adapt_params) { /* Setting the adapt-flag with our adapt_callback_sphere function from step 3 and the adapt_params. Both can be found in the file \ref t8_mesh_tutorials_common.hxx. */ - mesh->set_adapt ( - mesh_type::mesh_adapt_callback_wrapper (&adapt_callback_sphere, adapt_params)); + mesh.set_adapt (mesh_type::mesh_adapt_callback_wrapper (&adapt_callback_sphere, adapt_params)); /* Committing the mesh. */ - mesh->commit (); + mesh.commit (); } /** Helper function to partition and balance a given mesh. @@ -86,13 +86,13 @@ void step4_partition_balance_mesh (mesh_type& mesh) { /* Setting partition flag.*/ - mesh->set_partition (); + mesh.set_partition (); /* Setting balancing flag. */ - mesh->set_balance (); + mesh.set_balance (); /* Committing the mesh. */ - mesh->commit (); + mesh.commit (); } /** Helper function to add a layer of ghost elements to an initial mesh. @@ -102,10 +102,10 @@ void step4_ghost_mesh (mesh_type& mesh) { /* Set flag such that ghost layer is created on commit. */ - mesh->set_ghost (); + mesh.set_ghost (); /* Committing the mesh. */ - mesh->commit (); + mesh.commit (); } /** Entry point of the program. */ @@ -153,7 +153,7 @@ main (int argc, char** argv) auto mesh = t8_mesh_handle::handle_hypercube_hybrid_uniform_default (uniform_level, comm); /* Printing the mesh information. */ - print_stats_and_export (mesh, "Initial mesh", prefix_initial); + print_stats_and_export (*mesh, "Initial mesh", prefix_initial); /** * ADAPT MESH @@ -164,10 +164,10 @@ main (int argc, char** argv) t8_global_productionf (" [mesh_step4] \n"); /** Call adaption helper function. */ - step4_adapt_mesh (mesh, adapt_params); + step4_adapt_mesh (*mesh, adapt_params); /* Printing the mesh information. */ - print_stats_and_export (mesh, "Adapted mesh", prefix_adapt); + print_stats_and_export (*mesh, "Adapted mesh", prefix_adapt); /** * PARTITION, BALANCE MESH @@ -178,13 +178,13 @@ main (int argc, char** argv) t8_global_productionf (" [mesh_step4] \n"); /** Adapting the mesh from above a second time to see a difference when balancing. */ - step4_adapt_mesh (mesh, adapt_params); + step4_adapt_mesh (*mesh, adapt_params); /** Call partitioning and balancing helper function. */ - step4_partition_balance_mesh (mesh); + step4_partition_balance_mesh (*mesh); /* Printing the mesh information. */ - print_stats_and_export (mesh, "Partitioned and Balanced mesh", prefix_partition_balance); + print_stats_and_export (*mesh, "Partitioned and Balanced mesh", prefix_partition_balance); /** * GHOST LAYER @@ -195,10 +195,10 @@ main (int argc, char** argv) t8_global_productionf (" [mesh_step4] \n"); /** Call ghost helper function. */ - step4_ghost_mesh (mesh); + step4_ghost_mesh (*mesh); /* Printing the mesh information. */ - print_stats_and_export (mesh, "Ghost mesh", prefix_ghost); + print_stats_and_export (*mesh, "Ghost mesh", prefix_ghost); int ghost_elements = mesh->get_num_ghosts (); t8_global_productionf (" [mesh_step4] Number of ghost elements: %i \n", ghost_elements);