Skip to content

Conversation

@lenaploetzke
Copy link
Collaborator

@lenaploetzke lenaploetzke commented Aug 12, 2025

Describe your changes here:

Closes #1655
This PR implements the very basic structure of the unstructured mesh interface. It provides only the level variable. Other variables should be implemented in future PRs.

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.
  • 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 script/find_all_source_files.scp 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).

@lenaploetzke lenaploetzke linked an issue Aug 12, 2025 that may be closed by this pull request
@spenke91 spenke91 self-requested a review August 12, 2025 08:56
@lenaploetzke lenaploetzke marked this pull request as ready for review August 12, 2025 08:56
@codecov
Copy link

codecov bot commented Aug 12, 2025

Codecov Report

❌ Patch coverage is 98.63014% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 76.60%. Comparing base (41a06b6) to head (7a6e040).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
api/t8_mesh_handle/mesh.hxx 96.15% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1829      +/-   ##
==========================================
+ Coverage   76.52%   76.60%   +0.08%     
==========================================
  Files         106      109       +3     
  Lines       18655    18728      +73     
==========================================
+ Hits        14275    14347      +72     
- Misses       4380     4381       +1     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Member

@sandro-elsweijer sandro-elsweijer left a comment

Choose a reason for hiding this comment

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

First part of my review :)

Copy link
Member

@sandro-elsweijer sandro-elsweijer left a comment

Choose a reason for hiding this comment

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

Looks very nice!
Mainly, the comments are about documentation and variable naming, so nothing about the general concept.

But one thing we should think about is the derefencing and the probably memory leaks.

@lenaploetzke lenaploetzke marked this pull request as draft August 12, 2025 11:24
@sandro-elsweijer
Copy link
Member

For me, the APIs of t8code are the C, Fortran, Python... APIs. So interfaces to different programming languages.
The mesh handle is more like a part of the actual library and less a separate API. At least it is different than the language APIs. So I would either put it in src or create a whole new folder. For me at least it does not fit in the api folder

@lenaploetzke
Copy link
Collaborator Author

For me, the APIs of t8code are the C, Fortran, Python... APIs. So interfaces to different programming languages. The mesh handle is more like a part of the actual library and less a separate API. At least it is different than the language APIs. So I would either put it in src or create a whole new folder. For me at least it does not fit in the api folder

It does not feel right for me to put the handle in the src folder but i am fine with putting it in its own. The idea was that the mesh handle is an api for other software so i think it is not really wrong in the folder. What do you think @spenke91 ?

*/

/** \file element.hxx
* Definition of the elements used in the mesh class.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Definition of the elements used in the mesh class.
* Definition of the elements used in the \ref t8_mesh_handle::mesh class.


namespace t8_mesh_handle
{
/* Forward declaration of the mesh class of the handle.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/* Forward declaration of the mesh class of the handle.
/* Forward declaration of the \ref t8_mesh_handle::mesh class of the handle.

Comment on lines +163 to +169
std::vector<t8_3D_point> vertex_coordinates;
vertex_coordinates.reserve (num_corners);
for (int icorner = 0; icorner < num_corners; ++icorner) {
t8_3D_point vertex;
t8_forest_element_coordinate (m_mesh->m_forest, m_tree_id, element, icorner, vertex.data ());
vertex_coordinates.push_back (vertex);
}
Copy link
Member

Choose a reason for hiding this comment

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

saves a copy/move
In the future, we can also ask for all points of an element at the same time, this should also be faster. But for now this is alright :)

Suggested change
std::vector<t8_3D_point> vertex_coordinates;
vertex_coordinates.reserve (num_corners);
for (int icorner = 0; icorner < num_corners; ++icorner) {
t8_3D_point vertex;
t8_forest_element_coordinate (m_mesh->m_forest, m_tree_id, element, icorner, vertex.data ());
vertex_coordinates.push_back (vertex);
}
std::vector<t8_3D_point> vertex_coordinates (num_corners);
for (int icorner = 0; icorner < num_corners; ++icorner) {
t8_forest_element_coordinate (m_mesh->m_forest, m_tree_id, element, icorner, vertex_coordinates[icorner].data ());
vertex_coordinates.push_back (vertex);
}

* This function uses or sets the cached version defined in TCompetence if available and calculates if not.
* \return Vector with one coordinate array for each vertex of the element.
*/
std::vector<t8_3D_point>
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we make this const? Otherwise the user can alter the coordinates in the cache.

//--- Getter for the member variables. ---
/**
* Getter for the tree id of the mesh element.
* \return The element's tree id.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* \return The element's tree id.
* \return The element's local tree id.

Comment on lines +244 to +252
/**
* Getter for the eclass of the mesh element.
* \return The element's eclass.
*/
t8_eclass_t
get_tree_class () const
{
return t8_forest_get_tree_class (m_mesh->m_forest, m_tree_id);
}
Copy link
Member

Choose a reason for hiding this comment

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

we should not confuse the eclass and element shape

Suggested change
/**
* Getter for the eclass of the mesh element.
* \return The element's eclass.
*/
t8_eclass_t
get_tree_class () const
{
return t8_forest_get_tree_class (m_mesh->m_forest, m_tree_id);
}
/**
* Getter for the eclass of the tree of the mesh element.
* \return The eclass of the element's tree.
*/
t8_eclass_t
get_tree_class () const
{
return t8_forest_get_tree_class (m_mesh->m_forest, m_tree_id);
}
/**
* Getter for the element's shape.
* \return The shape of the element.
*/
t8_element_shape
get_shape () const
{
return t8_forest_get_scheme (m_mesh->m_forest)->element_get_shape (get_tree_class(), get_element());
}

Comment on lines +74 to +92
/**
* Returns an iterator to the first (local) mesh element.
* \return Iterator to the first (local) mesh element.
*/
mesh_iterator
begin ()
{
return m_elements.begin ();
}

/**
* Returns an iterator to a mesh element following the last (local) element of the mesh.
* \return Iterator to the mesh element following the last (local) element of the mesh.
*/
mesh_iterator
end ()
{
return m_elements.end ();
}
Copy link
Member

Choose a reason for hiding this comment

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

Should we have a non-const iterator in the first place? All data is read-only and all caches are marked mutable.

Comment on lines +114 to +123
/**
* Getter for a mesh element given its local index.
* \param [in] local_index The local index of the element to access.
* \return Reference to the mesh element.
*/
TMeshElement&
operator[] (t8_locidx_t local_index)
{
return m_elements[local_index];
}
Copy link
Member

Choose a reason for hiding this comment

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

Same here, I do not think the user should get a non-const reference

Comment on lines +154 to +157
if (!m_elements.empty ()) {
m_elements.clear ();
}
m_elements.reserve (get_num_local_elements ());
Copy link
Member

Choose a reason for hiding this comment

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

this is already optimal. clear does not do anything if the vector is empty.

Suggested change
if (!m_elements.empty ()) {
m_elements.clear ();
}
m_elements.reserve (get_num_local_elements ());
m_elements.clear ();
m_elements.reserve (get_num_local_elements ());

Comment on lines +59 to +60
const t8_scheme* scheme;
t8_eclass_t eclass;
Copy link
Member

Choose a reason for hiding this comment

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

These are not used in the test and do not need to be member variables

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.

Define structure of the unstructured mesh class

4 participants