Skip to content

Improvement: Mesh handle tutorials - #2348

Open
Vyp3er wants to merge 20 commits into
DLR-AMR:mainfrom
Vyp3er:mesh_handle_tutorials
Open

Improvement: Mesh handle tutorials#2348
Vyp3er wants to merge 20 commits into
DLR-AMR:mainfrom
Vyp3er:mesh_handle_tutorials

Conversation

@Vyp3er

@Vyp3er Vyp3er commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Describe your changes here:

All these boxes must be checked by the AUTHOR before requesting review:

  • The PR is small enough to be reviewed easily. If not, consider splitting up the changes in multiple PRs.
  • The title starts with one of the following prefixes: Documentation:, Bugfix:, Feature:, Improvement: or Other:.
  • If the PR is related to an issue, make sure to link it.
  • The author made sure that, as a reviewer, he/she would check all boxes below.

All these boxes must be checked by the REVIEWERS before merging the pull request:

As a reviewer please read through all the code lines and make sure that the code is fully understood, bug free, well-documented and well-structured.

General

  • The reviewer executed the new code features at least once and checked the results manually.
  • The code follows the t8code coding guidelines.
  • New source/header files are properly added to the CMake files.
  • The code is well documented. In particular, all function declarations, structs/classes and their members have a proper doxygen documentation. Make sure to add a file documentation for each file!
  • README.md files are updated if necessary.
  • All new algorithms and data structures are sufficiently optimal in terms of memory and runtime (If this should be merged, but there is still potential for optimization, create a new issue).

Tests

  • The code is covered in an existing or new test case using Google Test.
  • The code coverage of the project (reported in the CI) should not decrease. If coverage is decreased, make sure that this is reasonable and acceptable.
  • Valgrind doesn't find any bugs in the new code. This script can be used to check for errors; see also this wiki article.

If the Pull request introduces code that is not covered by the github action (for example coupling with a new library):

  • Should this use case be added to the github action?
  • If not, does the specific use case compile and all tests pass (check manually).

Scripts and Wiki

  • If a new directory with source files is added, it must be covered by the scripts/internal/find_all_source_files.sh to check the indentation of these files.
  • If this PR introduces a new feature, it must be covered in an example or tutorial and a Wiki article.

License

  • The author added a BSD statement to doc/ (or already has one).

@Vyp3er Vyp3er changed the title Mesh handle tutorials Improvement: Mesh handle tutorials Jul 1, 2026
@Vyp3er
Vyp3er marked this pull request as ready for review July 1, 2026 08:46
@lenaploetzke
lenaploetzke self-requested a review July 1, 2026 08:52
@lenaploetzke lenaploetzke self-assigned this Jul 1, 2026
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.28%. Comparing base (66cd94f) to head (c411a76).
⚠️ Report is 33 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2348   +/-   ##
=======================================
  Coverage   82.28%   82.28%           
=======================================
  Files         125      125           
  Lines       20701    20701           
=======================================
  Hits        17033    17033           
  Misses       3668     3668           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lenaploetzke lenaploetzke left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Partial review. Thank you for your work, this is really nice and my comments are mainly documentation! :)

Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx Outdated
Comment thread tutorials/CMakeLists.txt
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_forest.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

/** \file t8_mesh_element_data.cxx

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please adapt :)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you please adapt this?

Comment thread tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx Outdated

@lenaploetzke lenaploetzke left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review adapt callback file

Comment thread tutorials/mesh_handle/t8_mesh_tutorials_common.hxx Outdated
Comment thread tutorials/mesh_handle/default_adapt_callback.hxx Outdated
Comment thread tutorials/mesh_handle/default_adapt_callback.hxx Outdated
Comment thread tutorials/mesh_handle/default_adapt_callback.hxx Outdated
Comment thread tutorials/mesh_handle/default_adapt_callback.hxx Outdated
Comment thread tutorials/mesh_handle/default_adapt_callback.hxx Outdated
Comment thread tutorials/mesh_handle/default_adapt_callback.hxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step5_element_data.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step5_element_data.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step5_element_data.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step5_element_data.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step5_element_data.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx Outdated
@lenaploetzke

lenaploetzke commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Could you please have a look at the failing workflows?
Please also make sure in the future to try your code once before committing.

Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step3_adapt_mesh.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx Outdated
@lenaploetzke lenaploetzke assigned Vyp3er and unassigned lenaploetzke Jul 22, 2026

@lenaploetzke lenaploetzke left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Most things are just typos and capitalization.

Comment thread tutorials/mesh_handle/t8_mesh_step5_element_data.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step5_element_data.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step5_element_data.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_tutorials_common.hxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_tutorials_common.hxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx
Comment thread tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx Outdated
Comment thread tutorials/mesh_handle/t8_mesh_step4_partition_balance_ghost.cxx Outdated
@lenaploetzke lenaploetzke removed their assignment Aug 6, 2026
Vyp3er and others added 2 commits August 10, 2026 13:43
Co-authored-by: lenaploetzke <70579874+lenaploetzke@users.noreply.github.com>
@Vyp3er Vyp3er assigned lenaploetzke and unassigned Vyp3er Aug 10, 2026
Comment on lines +57 to +62
int rank = 0;
MPI_Comm_rank (comm, &rank);
if (rank == 0) {
std::cout << "=== " << stage << " ===" << std::endl;
std::cout << "Total elements: " << global_elements << std::endl;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah i know, but some pverhead here. get_num_global_elements is merged now so you are ready to use it here :)

#include <mesh_handle/competence_pack.hxx> /** Competence Pack for basic mesh_handle features. Look into tutorials/mesh_handle/t8_mesh_competences for more information. */
#include <mesh_handle/constructor_wrappers.hxx> /** Wrapper for basic Cmesh to mesh_handle conversions. */
#include <mesh_handle/mesh_io.hxx> /** Used to export mesh to vtk files. */
#include <mesh_handle/concepts.hxx> /** 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. */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This line is too long and i think you can remove some line breaks in the file descriptions . If you want to i can show you how to add a helper for this in vscode :)


/** 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* \param sc_MPI_Comm The MPI Communicator.
* \param comm The MPI Communicator.

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;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
int uniform_level = 3;
const int uniform_level = 3;

Best way is to mark everything const if possible :)

auto mesh = build_mesh<mesh_type> (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");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would be better to introduce a variable for the name and reusing it! That way if you change the name, you do not have to change it everywhere :)

int uniform_level = 3;
/* Building the mesh. */
{ /** Scope to ensure mesh is deleted properly. */
auto mesh = build_mesh<mesh_type> (comm, uniform_level);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I noticed that in the general tutorial, the uniform mesh is also stored as a vtk such that you can compare them. Why did you decided against this here?

Comment on lines +29 to +30
* 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* 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 <mesh_handle/constructor_wrappers.hxx> /** Wrapper for basic Cmesh to mesh_handle conversions. */
#include <mesh_handle/concepts.hxx> /** 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_types/t8_vec.hxx> /** t8 vector dataclass. */
#include "t8_mesh_tutorials_common.hxx" /** Default adaption function. */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also not "default" here. Just use the description that you provided in step 3 pls

#include <t8_types/t8_vec.hxx> /** t8 vector dataclass. */
#include "t8_mesh_tutorials_common.hxx" /** Default adaption function. */
#include <memory>
#include <iostream>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#include <iostream>

print_mesh_stats (const std::unique_ptr<mesh_type>& mesh, const char* stage, sc_MPI_Comm comm)
{
int local_elements = mesh->get_num_local_elements ();
int global_elements = 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think i already wrote is somewhere but please use your new mesh handle function here (already merged)

t8_global_productionf (" [mesh_step4] Total elements: %i \n", global_elements);
}

/** Helper function to create an adapted mesh from an initial mesh.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Now you just adapt a mesh and dont create a new adapted mesh. Please change this

/* 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_data> (&adapt_callback_sphere<mesh_type>, adapt_params));
/* Committing the adapted mesh. */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not really. The mesh gets adapted at the commit step, so its not "the adapted mesh"

mesh->commit ();
}

/** Helper function to create a partitioned and balanced mesh from an initial mesh.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same as above

void
create_partitioned_balanced_mesh (const std::unique_ptr<mesh_type>& mesh)
{
/* Calculate partition information.*/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe it is good if you have a look at the documentation of these functions and of commit. You do not calculate something, just setting the flags such that the mesh is partitioned at commit call. We can also talk about the commit procedure if you want to, just ask.

t8_global_productionf (" [mesh_step4] \n");

/* The initial uniform refinement level. */
int uniform_level = 3;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
int uniform_level = 3;
const int uniform_level = 3;

int uniform_level = 3;

/* Parameters for the adaption step. */
struct adapt_data adapt_params = { { 0.5, 0.5, 1.0 }, 0.2, 0.4 };

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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 };

The struct is old c style

true, false, false);

/**
* GHOST MESH

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

At comments you have to pay attention to the indention please,this is not checked by the ci and not corrected by the indent script

create_ghost_mesh (mesh);

/* Printing the mesh information. */
print_mesh_stats (mesh, "Ghost mesh", comm);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe it would be nice to print also the number of ghost elements here (maybe only for one process or so).

{
auto mesh_handle = t8_mesh_handle::handle_hypercube_hybrid_uniform_default<TMeshClass> (level, comm);
struct user_data adapt_data = {
struct adapt_data adapt_params = {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
struct adapt_data adapt_params = {
adapt_data adapt_params = {

I also just copied the old C style whoopsi

@lenaploetzke lenaploetzke assigned Vyp3er and unassigned lenaploetzke Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants