Skip to content

Improvement: Step 2 tutorial and get_num_global_elements to mesh.hxx - #2371

Open
Vyp3er wants to merge 1 commit into
DLR-AMR:mainfrom
Vyp3er:step_2_creating_uniform_mesh_tutorial
Open

Improvement: Step 2 tutorial and get_num_global_elements to mesh.hxx#2371
Vyp3er wants to merge 1 commit into
DLR-AMR:mainfrom
Vyp3er:step_2_creating_uniform_mesh_tutorial

Conversation

@Vyp3er

@Vyp3er Vyp3er commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

…mesh.hxx.

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 marked this pull request as ready for review July 20, 2026 14:02
@codecov

codecov Bot commented Jul 20, 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 (54f48b6).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2371   +/-   ##
=======================================
  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 self-assigned this Jul 21, 2026
@lenaploetzke
lenaploetzke self-requested a review July 21, 2026 07:55

@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.

Thanks for your nice work :)

Comment thread mesh_handle/mesh.hxx
Comment on lines +144 to +153
/**
* Getter for the number of global elements in the mesh.
* \return Number of global elements in the mesh.
*/
t8_gloidx_t
get_num_global_elements () const
{
return t8_forest_get_global_num_leaf_elements (m_forest);
}

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 test this function somewhere? :)
As we discussed, please open separate PRs for each feature in the future.

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

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 always adapt the year if you are creating a new file!


/** \file t8_mesh_step2_uniform_mesh.cxx
* This is step 2 of the t8code mesh handle tutorials.
* Therefor, this is the same as general/t8_step2_uniform_forest.cxx but using the mesh handle interface instead of the forest

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
* Therefor, this is the same as general/t8_step2_uniform_forest.cxx but using the mesh handle interface instead of the forest
* Therefore, this is the same as general/t8_step2_uniform_forest.cxx but using the mesh handle interface instead of the forest

* uniform (every element has the same refinement level) and can then be adapted
* later (see the following steps).
* Together with the cmesh, we also need a refinement scheme. This scheme tells the
* mesh how elements of each shape (t8_eclass_t) are refined, what their neighbor

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
* mesh how elements of each shape (t8_eclass_t) are refined, what their neighbor
* mesh how elements of each shape (t8_eclass_t) are refined, what their neighbors

* mesh how elements of each shape (t8_eclass_t) are refined, what their neighbor
* are etc.
* The default scheme in t8_schemes/t8_default/t8_default.hxx provides an implementation for
* all element shapes that t8code supports (with pyramids currently under construction).

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
* all element shapes that t8code supports (with pyramids currently under construction).
* all element shapes that t8code supports.

Where did you copy this from? Could you maybe also adapt it also there? :) The scheme for pyramids is usable :)

t8_global_productionf (" [tutorial] Wrote mesh to vtu files:\t%s*\n", prefix);

/** Destroy the mesh. */
mesh.reset ();

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.

Yes, this destroys the mesh but by resetting the unique pointer to nullptr.
I prefer the {} lifetime declaration as in the other tutorials because we have no leftover pointer :)

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.

(The cool part about the mesh is that you do not need to destroy the mesh mannually), only need the {} for the lifetime, please also explain this in a comment

* \return A uniform mesh with the given refinement level that is
* partitioned across the processes in \a comm.
*/
static std::unique_ptr<t8_mesh_handle::mesh<t8_mesh_handle::all_cache_element_competences>>

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 am not sure if its maybe better to write a templated function here.


/* Build the uniform mesh, it is automatically partitioned among the processes. */
auto mesh = t8_mesh_handle::handle_new_uniform<t8_mesh_handle::mesh<t8_mesh_handle::all_cache_element_competences>> (
cmesh, scheme, level, comm, false);

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.

As the last parameter is optional, and we want to write a tutorial that is as easy as possible, i would leave out the false here.

const t8_scheme *scheme = t8_scheme_new_default (); /** Default refinement scheme. */

/* Build the uniform mesh, it is automatically partitioned among the processes. */
auto mesh = t8_mesh_handle::handle_new_uniform<t8_mesh_handle::mesh<t8_mesh_handle::all_cache_element_competences>> (

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.

Auto is in general fine here but could you state the full type here such that it is clear why we return a unique pointer?

* \return A uniform mesh with the given refinement level that is
* partitioned across the processes in \a comm.
*/
static std::unique_ptr<t8_mesh_handle::mesh<t8_mesh_handle::all_cache_element_competences>>

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.

unique_ptr is declared in header, could you include it?

@lenaploetzke lenaploetzke assigned Vyp3er and unassigned lenaploetzke Jul 27, 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