-
Notifications
You must be signed in to change notification settings - Fork 69
Feature: OpenFOAM reader [1/n] - First structure #2256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sandro-elsweijer
wants to merge
7
commits into
main
Choose a base branch
from
feature-openfoam_reader_0
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+652
−34
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f95434d
add basic structure of OpenFOAM reader
sandro-elsweijer d885fcb
add an OpenFOAM reader example
sandro-elsweijer a0c86a7
fix documentation
sandro-elsweijer a612eca
makr comm as unused
sandro-elsweijer 95badc8
removed unused comm
sandro-elsweijer 440c46f
Merge branch 'main' into feature-openfoam_reader_0
sandro-elsweijer 958cd64
remove unused comm
sandro-elsweijer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| This file is part of t8code. | ||
| 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) 2026 the developers | ||
|
|
||
| t8code is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation; either version 2 of the License, or | ||
| (at your option) any later version. | ||
|
|
||
| t8code is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with t8code; if not, write to the Free Software Foundation, Inc., | ||
| 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| */ | ||
|
|
||
| /* This example shows how to read an OpenFOAM mesh and save it onto a cmesh. | ||
| * DISCLAIMER: THIS EXAMPLE IS WORK IN PROGRESS AND THE SHOWN FEATURE IS NOT YET FINISHED. | ||
| */ | ||
|
|
||
| #include <t8.h> | ||
| #include <sc_options.h> | ||
| #include <t8_vtk/t8_vtk_writer.h> | ||
| #include <t8_openfoam/t8_openfoam_reader.hxx> | ||
|
|
||
| #include <filesystem> | ||
|
|
||
| /** | ||
| * Build a cmesh from an OpenFOAM case directory and write it to vtk. | ||
| * \param [in] foamfile The path to the OpenFOAM case file (*.case) | ||
| */ | ||
| static void | ||
| build_cmesh_from_openfoam_case (const std::filesystem::path& foamfile) | ||
| { | ||
| /* Use the OpenFOAM reader to read the case. */ | ||
| t8_openfoam_reader reader (foamfile, sc_MPI_COMM_WORLD); | ||
| t8_cmesh_t cmesh = reader.read (); | ||
|
|
||
| /* If the cmesh is empty something went wrong. */ | ||
| if (!cmesh) { | ||
| t8_global_errorf ("ERROR: Failed to read OpenFOAM case %s\n", foamfile.string ().c_str ()); | ||
| return; | ||
| } | ||
|
|
||
| t8_global_productionf ("Successfully built cmesh from OpenFOAM case: %s\n", foamfile.string ().c_str ()); | ||
| t8_global_productionf ("cmesh contains %lli trees.\n", (long long) t8_cmesh_get_num_trees (cmesh)); | ||
|
|
||
| /* Write the cmesh to vtk. */ | ||
| std::string vtk_file = "t8_openfoam_mesh_" + foamfile.parent_path ().filename ().string (); | ||
| t8_cmesh_vtk_write_file (cmesh, vtk_file.c_str ()); | ||
|
|
||
| /* Destroy the cmesh. */ | ||
| t8_cmesh_destroy (&cmesh); | ||
| } | ||
|
|
||
| int | ||
| main (int argc, char* argv[]) | ||
| { | ||
| int mpiret, helpme; | ||
| sc_options_t* opt; | ||
| const char* casefile = nullptr; | ||
| char usage[BUFSIZ]; | ||
| char help[BUFSIZ]; | ||
| int sreturn; | ||
|
|
||
| /* Initialize t8code */ | ||
| mpiret = sc_MPI_Init (&argc, &argv); | ||
| SC_CHECK_MPI (mpiret); | ||
|
|
||
| sc_init (sc_MPI_COMM_WORLD, 1, 1, nullptr, SC_LP_ESSENTIAL); | ||
| t8_init (SC_LP_DEFAULT); | ||
|
|
||
| /* Set up a short help message */ | ||
| snprintf (usage, BUFSIZ, "Usage:\t%s <OPTIONS> <ARGUMENTS>", basename (argv[0])); | ||
| sreturn = snprintf (help, BUFSIZ, | ||
| "This program reads the mesh inside an OpenFOAM case " | ||
| "and constructs a t8code coarse mesh from it.\n" | ||
| "The path must lead to a OpenFOAM *.foam file inside the OpenFOAM case directory.\n" | ||
| "\n%s\n", | ||
| usage); | ||
|
|
||
| if (sreturn >= BUFSIZ) { | ||
| /* The help message was truncated */ | ||
| /* Note: gcc >= 7.1 prints a warning if we | ||
| * do not check the return value of snprintf. */ | ||
| t8_debugf ("Warning: Truncated help message to '%s'\n", help); | ||
| } | ||
|
|
||
| /* Read user options */ | ||
| opt = sc_options_new (argv[0]); | ||
| sc_options_add_switch (opt, 'h', "help", &helpme, "Display this help message."); | ||
| sc_options_add_string (opt, 'f', "foamcase", &casefile, "", "Path to the OpenFOAM case (case.foam)."); | ||
|
|
||
| const int parsed = sc_options_parse (t8_get_package_id (), SC_LP_ERROR, opt, argc, argv); | ||
| t8_global_errorf ("THE FEATURES OF THIS EXAMPLE ARE NOT FINISHED YET. THEREFORE, THIS EXAMPLE MIGHT CRASH ABRUPTLY.\n" | ||
| "THIS MESSAGE WILL BE REMOVED WHEN THE IMPLEMENTATION OF THE OPENFOAM READER IS FINISHED.\n"); | ||
| if (helpme) { | ||
| t8_global_productionf ("%s\n", help); | ||
| sc_options_print_summary (t8_get_package_id (), SC_LP_PRODUCTION, opt); | ||
| } | ||
| else if (parsed < 0 || strcmp (casefile, "") == 0) { | ||
| t8_global_productionf ("Wrong usage.\n"); | ||
| sc_options_print_usage (t8_get_package_id (), SC_LP_ERROR, opt, nullptr); | ||
| } | ||
| else { | ||
| build_cmesh_from_openfoam_case (casefile); | ||
| } | ||
|
|
||
| sc_options_destroy (opt); | ||
| sc_finalize (); | ||
| sc_MPI_Finalize (); | ||
|
|
||
| return 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add an example case file? I think it would really improve this example if the user could test it for an example file easily without having to find one him-/herself 😬