Skip to content

Feature: OpenFOAM reader [2/n] - Hex meshes without connectivity#2258

Open
sandro-elsweijer wants to merge 9 commits into
mainfrom
feature_openfoam-reader_1
Open

Feature: OpenFOAM reader [2/n] - Hex meshes without connectivity#2258
sandro-elsweijer wants to merge 9 commits into
mainfrom
feature_openfoam-reader_1

Conversation

@sandro-elsweijer

@sandro-elsweijer sandro-elsweijer commented Apr 1, 2026

Copy link
Copy Markdown
Member

Closes #2259

Describe your changes here:
This PR adds the feature to read OpenFOAM hex only meshes without connectivity.
The internal data structures of the reader are used to assemble hex cells and add them to a cmesh.
The provided example can now be used to read a hex mesh like the mesh from the pitzDailySteady OpenFOAM example.

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

Base automatically changed from feature-openfoam_reader_0 to main June 23, 2026 11:23
@sandro-elsweijer
sandro-elsweijer marked this pull request as ready for review June 24, 2026 08:25
@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 142 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.21%. Comparing base (2e9b7f5) to head (dcdf556).
⚠️ Report is 84 commits behind head on main.

Files with missing lines Patch % Lines
src/t8_openfoam/t8_openfoam_reader.cxx 0.00% 98 Missing ⚠️
src/t8_openfoam/t8_openfoam_reader.hxx 0.00% 44 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2258      +/-   ##
==========================================
- Coverage   81.74%   81.21%   -0.53%     
==========================================
  Files         126      127       +1     
  Lines       20702    20836     +134     
==========================================
  Hits        16922    16922              
- Misses       3780     3914     +134     

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

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

Sorry it took so lonf until I found time for the review...

Great to see you are making progress here! 🥳
I only have a bunch of minor suggestions and questions. For the hex construction, I admit I had a hard time following every single step in detail, but I am happy to have a more detailed look next time :-)

error = error && !read_faces (case_faces_file);
error = error && !read_owner (case_owner_file);
error = error && !read_neighbor (case_neighbor_file);
bool success = 1;

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 getting used to using 0 and 1 for bool, but can't we at least use true for initializing bools? 😆

Suggested change
bool success = 1;
bool success = true;

* \return The eclass of the cell
*/
t8_eclass_t
get_cell_eclass (const size_t cell_id)

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.

Sorry to play that card again, but why is this function's implementation in the header, not the source file? 🤓

/* OpenFOAM only has 3D cells, so we do not check 0-2 dimensional cells. */
switch (m_cell_faces[cell_id].size ()) {
case 4:
/* This cell is hopefully a tet with 4*3=12 points. */

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
/* This cell is hopefully a tet with 4*3=12 points. */
/* This cell should be a tet with 4*3=12 points. */

num_points += m_face_points[face.first].size ();
}

/* OpenFOAM only has 3D cells, so we do not check 0-2 dimensional cells. */

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
/* OpenFOAM only has 3D cells, so we do not check 0-2 dimensional cells. */
// Distinguish shapes based on the number of faces and points.
// Note: OpenFOAM only has 3D cells, so we do not check 0-2 dimensional cells.

return T8_ECLASS_PYRAMID;
break;
case 6:
/* This cell is hopefully a hex with 6 * 4 = 24 points. */

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
/* This cell is hopefully a hex with 6 * 4 = 24 points. */
/* This cell should be a hex with 6 * 4 = 24 points. */

But if you prefer, you can also stick to hopefully, it is funnier ;-)

* the next vertex is vertex 1 and therefore vertex 0 of face 1. Otherwise, the previous point is vertex 0 of face 1.
* We iterate cyclic over the face vertices. So if we arrive at the end, we begin at the start. */
auto next_vertex
= (found_face_0_vertex_0 + 1) == check_face->end () ? check_face->begin () : found_face_0_vertex_0 + 1;

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
= (found_face_0_vertex_0 + 1) == check_face->end () ? check_face->begin () : found_face_0_vertex_0 + 1;
= ( (found_face_0_vertex_0 + 1) == check_face->end () ? check_face->begin () : found_face_0_vertex_0 + 1 );

* We iterate cyclic over the face vertices. So if we arrive at the end, we begin at the start. */
auto next_vertex
= (found_face_0_vertex_0 + 1) == check_face->end () ? check_face->begin () : found_face_0_vertex_0 + 1;
/* Check if face 0 contains this vertex */

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.

It looks like it is searching through face 1 though?

}
else {
const auto previous_vertex
= found_face_0_vertex_0 == check_face->begin () ? check_face->end () : found_face_0_vertex_0 - 1;

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
= found_face_0_vertex_0 == check_face->begin () ? check_face->end () : found_face_0_vertex_0 - 1;
= (found_face_0_vertex_0 == check_face->begin () ? check_face->end () : found_face_0_vertex_0 - 1);

/* ------------------------- 4. Add remaining four faces ------------------------- */

/* Lastly, we have to match the rest of the faces so we can add the boundaries to the cmesh and
* to get the orientations and faces for neighbor linkage. */

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
* to get the orientations and faces for neighbor linkage. */
* to get the orientations and faces for neighbor linkage. */

Comment on lines +528 to +529
//t8_face_normal = t8_eclass_face_orientation[eclass][1];
//orientation.second = (face_normals[*face_id] == t8_face_normal);

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_face_normal = t8_eclass_face_orientation[eclass][1];
//orientation.second = (face_normals[*face_id] == t8_face_normal);

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.

Feature: OpenFOAM reader [2/n] - Hex meshes without connectivity

2 participants