Skip to content

Conversation

@lenaploetzke
Copy link
Collaborator

@lenaploetzke lenaploetzke commented Nov 28, 2025

Closes #2006

Describe your changes here:
The mesh handle class is now able to handle element and user data. Template parameters are used to specify the classes (instead of the void* used in the forest for the user data). To specify them as template parameters, i needed to somehow pack the Competences into one template parameter (see parameter_pack.hxx) (because i wanted defaults for the element and user data classes but a parameter pack also always has to be the last template parameter). I think its a feature to have them all in one template parameter for the user and makes it easier to use (although slightly more complicated as a developer). Additionally, i can now provide predefined parameter packs e.g. cache_competences, where all cache competences are included.
The element data is stored in a vector in the mesh (and not in the elements). This is easier for the ghost exchange.
Additionally, the volume of the elements can now be accessed and cached. A tutorial used this as element data which is why i got inspired and also implemented the functionality for the handle. The calculation can be somehow complicated which is why i also provide a cached version.

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

@codecov
Copy link

codecov bot commented Nov 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.48%. Comparing base (4910843) to head (0c611eb).

Additional details and impacted files
@@                      Coverage Diff                      @@
##           handle-neighbor-and-ghost    #2005      +/-   ##
=============================================================
+ Coverage                      77.42%   77.48%   +0.05%     
=============================================================
  Files                            112      112              
  Lines                          19037    19086      +49     
=============================================================
+ Hits                           14739    14788      +49     
  Misses                          4298     4298              

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

* Element data for non-ghost elements can be accessed (if set) directly.
* \return Element data with data of Type mesh_class::ElementDataType.
*/
template <typename E = typename mesh_class::ElementDataType, typename = std::enable_if_t<!std::is_void<E>::value>>
Copy link
Member

Choose a reason for hiding this comment

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

Please use proper template parameter names

* \note You can only set element data for non-ghost elements.
* \param [in] element_data The element data to be set.
*/
template <typename E = typename mesh_class::ElementDataType, typename = std::enable_if_t<!std::is_void<E>::value>>
Copy link
Member

Choose a reason for hiding this comment

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

Parameter name

// Resize for the case that no data vector has been set previously.
m_mesh->m_element_data.resize (m_mesh->get_num_local_elements () + m_mesh->get_num_ghosts ());
m_mesh->m_element_data[get_element_handle_id ()] = element_data;
}
Copy link
Member

Choose a reason for hiding this comment

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

IMHO we could also overload the dereference operator. In my head it makes total sense that an element handle stores data and that you can access its data by dereferencing it.

Copy link
Member

Choose a reason for hiding this comment

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

Ah but then we cannot check if the user tries to set data for a ghost element

Comment on lines +422 to +426
const E&
get_element_data () const
{
return m_mesh->m_element_data[get_element_handle_id ()];
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we need a check if the element has data in the first place?

SC_CHECK_ABORT (!m_is_ghost_element, "Element data cannot be set for ghost elements.\n");
// Resize for the case that no data vector has been set previously.
m_mesh->m_element_data.resize (m_mesh->get_num_local_elements () + m_mesh->get_num_ghosts ());
m_mesh->m_element_data[get_element_handle_id ()] = element_data;
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
m_mesh->m_element_data[get_element_handle_id ()] = element_data;
m_mesh->m_element_data[get_element_handle_id ()] = std::move(element_data);

t8_forest_t forest = t8_forest_new_uniform (cmesh, init_scheme, level, 1, sc_MPI_COMM_WORLD);

using mesh_class = t8_mesh_handle::mesh<t8_mesh_handle::competence_pack<>, void, data_per_element>;
mesh_class mesh = mesh_class (forest);
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
mesh_class mesh = mesh_class (forest);
mesh_class mesh (forest);

using element_class = mesh_class::element_class;
mesh_class mesh = mesh_class (forest);
using element_class = typename mesh_class::element_class;
const mesh_class mesh = mesh_class (forest);
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
const mesh_class mesh = mesh_class (forest);
const mesh_class mesh (forest);

using competence_vertex_coordinates = t8_mesh_handle::competence_pack<t8_mesh_handle::cache_vertex_coordinates>;
using mesh_class_vertex = t8_mesh_handle::mesh<competence_vertex_coordinates>;
using element_class_vertex = typename mesh_class_vertex::element_class;
const mesh_class_vertex mesh_vertex = mesh_class_vertex (forest);
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
const mesh_class_vertex mesh_vertex = mesh_class_vertex (forest);
const mesh_class_vertex mesh_vertex (forest);

using competence_centroid = t8_mesh_handle::competence_pack<t8_mesh_handle::cache_centroid>;
using mesh_class_centroid = t8_mesh_handle::mesh<competence_centroid>;
using element_class_centroid = typename mesh_class_centroid::element_class;
const mesh_class_centroid mesh_centroid = mesh_class_centroid (forest);
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
const mesh_class_centroid mesh_centroid = mesh_class_centroid (forest);
const mesh_class_centroid mesh_centroid (forest);

mesh_class mesh = mesh_class (forest);
using mesh_class = t8_mesh_handle::mesh<t8_mesh_handle::cache_competences>;
using element_class = typename mesh_class::element_class;
const mesh_class mesh = mesh_class (forest);
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
const mesh_class mesh = mesh_class (forest);
const mesh_class mesh (forest);

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.

3 participants