Skip to content

Improvement: Mesh handle tutorials - #2348

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

Improvement: Mesh handle tutorials#2348
Vyp3er wants to merge 17 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 (8ba48ac).
⚠️ Report is 27 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
sc_MPI_Comm comm = sc_MPI_COMM_WORLD;

/* Print a starting message. */
t8_global_productionf (" [tutorial] \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.

We should also think of something different than "tutorial" here. Any ideas?

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 :)

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
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
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
@@ -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<user_data> (adapt_callback<TMeshClass>, adapt_data));
TMeshClass::template mesh_adapt_callback_wrapper<adapt_data> (&default_adapt_callback<TMeshClass>, 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.

Could you please explain shortly why the & is valid here? :) I am not saying that it is wrong, just wondering why i left it out and why it is fine this way.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

In this case it's optional, because set_adapt() uses an std::function as it's "adapt_callback_type", when you use &default_... you transfer the function pointer to create the std::function, if you leave it out (default_...) c++ automatically converts this to a function pointer implicitly to create the std::function.
So essentially, it's just implicit vs explicit handover of the function pointer.
I just added it here when i implemented the adapt_callback as its own file, because i used it in the other 2 tutorials like this aswell, so it's uniform.

@lenaploetzke lenaploetzke Aug 6, 2026

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.

Nice, thank you for the explanation. In general, explicit coding is better in most cases, so yes, & is even better! :)

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.

#include <mesh_handle/mesh_io.hxx>
#include <mesh_handle/concepts.hxx>
#include <t8_types/t8_vec.hxx>
#include <mesh_handle/mesh.hxx> /** General Mesh header. Always needed for mesh_handle code. */

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 <mesh_handle/mesh.hxx> /** General Mesh header. Always needed for mesh_handle code. */
#include <mesh_handle/mesh.hxx> /** General mesh header. Always needed for mesh_handle code. */

#include <mesh_handle/concepts.hxx>
#include <t8_types/t8_vec.hxx>
#include <mesh_handle/mesh.hxx> /** General Mesh header. Always needed for mesh_handle code. */
#include <mesh_handle/competence_pack.hxx> /** Competence Pack for basic mesh_handle features. Look into tutorials/mesh_handle/t8_mesh_competences for more 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.

Suggested change
#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/competence_pack.hxx> /** Competence pack for basic mesh_handle features. Look into tutorials/mesh_handle/t8_mesh_competences for more information. */

#include <t8_types/t8_vec.hxx>
#include <mesh_handle/mesh.hxx> /** General Mesh header. Always needed for mesh_handle code. */
#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. */

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 <mesh_handle/constructor_wrappers.hxx> /** Wrapper for basic Cmesh to mesh_handle conversions. */
#include <mesh_handle/constructor_wrappers.hxx> /** Wrapper for basic cmesh to mesh_handle conversions. */

51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

/** \file default_adapt_callback.hxx

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
/** \file default_adapt_callback.hxx
/** \file t8_mesh_tutorials_common.hxx

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

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
t8_3D_vec midpoint; /**< midpoint of our sphere. */
t8_3D_vec midpoint; /**< Midpoint of our sphere. */

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");

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 tutorial throws errors...


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

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 adapt_params The adaptation parameters to use for the adaptation.

/* Balancing the mesh. */
mesh_partition_balance->set_balance ();

/* Committing the partitioned and balanced 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. set_balance does not really balance the mesh. This is done at commiting. I think you can adapt it if you understand my comment at step 3


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

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
* \return A unique pointer to the new mesh with ghost layers.
* \return A unique pointer to the new mesh with a ghost layer.

return mesh_partition_balance;
}

/** Helper function to create a ghost 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.

Suggested change
/** Helper function to create a ghost mesh from an initial mesh.
/** Helper function to create a mesh with ghosts from an initial mesh.

@lenaploetzke lenaploetzke removed their assignment Aug 6, 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