Skip to content

Commit a8ed5f0

Browse files
authored
Merge pull request #1829 from DLR-AMR/1655-define-structure-of-the-unstructured-mesh-class
Feature: Very first version of the unstructured mesh interface
2 parents 52ca708 + 7f65c1a commit a8ed5f0

File tree

16 files changed

+986
-27
lines changed

16 files changed

+986
-27
lines changed

.github/workflows/code_coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
run: export TEST_LEVEL_FLAG="-DT8CODE_TEST_LEVEL=${{ inputs.TEST_LEVEL }}"
9292
&& echo TEST_LEVEL_FLAG="$TEST_LEVEL_FLAG" >> $GITHUB_ENV
9393
- name: build config variables
94-
run: export CONFIG_OPTIONS="${TEST_LEVEL_FLAG} -DT8CODE_CODE_COVERAGE=ON -DT8CODE_USE_SYSTEM_SC=ON -DT8CODE_USE_SYSTEM_P4EST=ON -DT8CODE_BUILD_PEDANTIC=ON -DT8CODE_BUILD_WALL=ON -DT8CODE_BUILD_WERROR=ON -DT8CODE_ENABLE_MPI=$MPI -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DT8CODE_BUILD_FORTRAN_INTERFACE=ON -DSC_DIR=$SC_PATH/install/cmake -DP4EST_DIR=$P4EST_PATH/install/cmake -DT8CODE_BUILD_BENCHMARKS=OFF -DT8CODE_BUILD_DOCUMENTATION=OFF -DT8CODE_BUILD_EXAMPLES=OFF -DT8CODE_BUILD_TUTORIALS=OFF"
94+
run: export CONFIG_OPTIONS="${TEST_LEVEL_FLAG} -DT8CODE_CODE_COVERAGE=ON -DT8CODE_USE_SYSTEM_SC=ON -DT8CODE_USE_SYSTEM_P4EST=ON -DT8CODE_BUILD_PEDANTIC=ON -DT8CODE_BUILD_WALL=ON -DT8CODE_BUILD_WERROR=ON -DT8CODE_ENABLE_MPI=$MPI -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DT8CODE_BUILD_FORTRAN_INTERFACE=ON -DT8CODE_BUILD_MESH_HANDLE=ON -DSC_DIR=$SC_PATH/install/cmake -DP4EST_DIR=$P4EST_PATH/install/cmake -DT8CODE_BUILD_BENCHMARKS=OFF -DT8CODE_BUILD_DOCUMENTATION=OFF -DT8CODE_BUILD_EXAMPLES=OFF -DT8CODE_BUILD_TUTORIALS=OFF"
9595
&& echo CONFIG_OPTIONS="$CONFIG_OPTIONS" >> $GITHUB_ENV
9696
# cmake
9797
- name: echo cmake line

.github/workflows/tests_cmake_t8code_api.yml

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,37 +85,35 @@ jobs:
8585
run: export TEST_LEVEL_FLAG="-DT8CODE_TEST_LEVEL=${{ inputs.TEST_LEVEL }}"
8686
&& echo TEST_LEVEL_FLAG="$TEST_LEVEL_FLAG" >> $GITHUB_ENV
8787
- name: build config variables
88-
run: export CONFIG_OPTIONS="${TEST_LEVEL_FLAG} -GNinja -DCMAKE_C_FLAGS_DEBUG=${DEBUG_CONFIG} -DCMAKE_CXX_FLAGS_DEBUG=${DEBUG_CONFIG} -DT8CODE_BUILD_FORTRAN_INTERFACE=ON -DT8CODE_USE_SYSTEM_SC=ON -DT8CODE_USE_SYSTEM_P4EST=ON -DT8CODE_BUILD_PEDANTIC=ON -DT8CODE_BUILD_WALL=ON -DT8CODE_BUILD_WERROR=ON -DT8CODE_BUILD_WEXTRA=ON -DT8CODE_ENABLE_MPI=$MPI -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSC_DIR=$SC_PATH/install/cmake -DP4EST_DIR=$P4EST_PATH/install/cmake"
88+
run: export CONFIG_OPTIONS="${TEST_LEVEL_FLAG} -GNinja -DCMAKE_C_FLAGS_DEBUG=${DEBUG_CONFIG} -DCMAKE_CXX_FLAGS_DEBUG=${DEBUG_CONFIG} -DT8CODE_BUILD_FORTRAN_INTERFACE=ON -DT8CODE_BUILD_MESH_HANDLE=ON -DT8CODE_USE_SYSTEM_SC=ON -DT8CODE_USE_SYSTEM_P4EST=ON -DT8CODE_BUILD_PEDANTIC=ON -DT8CODE_BUILD_WALL=ON -DT8CODE_BUILD_WERROR=ON -DT8CODE_BUILD_WEXTRA=ON -DT8CODE_ENABLE_MPI=$MPI -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSC_DIR=$SC_PATH/install/cmake -DP4EST_DIR=$P4EST_PATH/install/cmake"
8989
&& echo CONFIG_OPTIONS="$CONFIG_OPTIONS" >> $GITHUB_ENV
90-
# cmake and test with fortran
91-
- name: check fortran
92-
run: echo "Checking fortran"
90+
# cmake and test with api options
9391
- name: echo cmake line
9492
run: echo cmake ../ $CONFIG_OPTIONS
95-
- name: cmake MPI fortran debug
96-
run: mkdir build_fortran && cd build_fortran && cmake ../ $CONFIG_OPTIONS
93+
- name: cmake
94+
run: mkdir build_api && cd build_api && cmake ../ $CONFIG_OPTIONS
9795
- name: OnFailUploadLog
9896
if: failure()
9997
uses: actions/upload-artifact@v5
10098
with:
101-
name: cmake_${{ inputs.BUILD_TYPE }}_MPI_${{ inputs.MPI }}_fortran.log
102-
path: build_fortran/CMakeFiles/CMakeOutput.log
103-
- name: make
104-
run: cd build_fortran && ninja $MAKEFLAGS
99+
name: cmake_${{ inputs.BUILD_TYPE }}_MPI_${{ inputs.MPI }}_api.log
100+
path: build_api/CMakeFiles/CMakeOutput.log
101+
- name: ninja
102+
run: cd build_api && ninja $MAKEFLAGS
105103
- name: ninja install
106-
run: cd build_fortran && ninja install $MAKEFLAGS
104+
run: cd build_api && ninja install $MAKEFLAGS
107105
- name: serial tests (if MPI is enabled)
108-
run: cd build_fortran && ctest $MAKEFLAGS -R _serial
106+
run: cd build_api && ctest $MAKEFLAGS -R _serial
109107
if: ${{ inputs.MPI == 'ON' }}
110108
- name: parallel tests (if MPI is enabled)
111-
run: cd build_fortran && ctest -R _parallel
109+
run: cd build_api && ctest -R _parallel
112110
if: ${{ inputs.MPI == 'ON' }}
113111
- name: tests (if MPI is disabled)
114-
run: cd build_fortran && ctest $MAKEFLAGS
112+
run: cd build_api && ctest $MAKEFLAGS
115113
if: ${{ inputs.MPI == 'OFF' }}
116114
- name: OnFailUploadLog
117115
if: failure()
118116
uses: actions/upload-artifact@v5
119117
with:
120-
name: test-suite_${{ inputs.BUILD_TYPE }}_MPI_${{ inputs.MPI }}_fortran.log
121-
path: build_fortran/Testing/Temporary/LastTest.log
118+
name: test-suite_${{ inputs.BUILD_TYPE }}_MPI_${{ inputs.MPI }}_api.log
119+
path: build_api/Testing/Temporary/LastTest.log

.github/workflows/tests_cmake_valgrind.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
run: export TEST_LEVEL_FLAG="-DT8CODE_TEST_LEVEL=${{ inputs.TEST_LEVEL }}"
8787
&& echo TEST_LEVEL_FLAG="$TEST_LEVEL_FLAG" >> $GITHUB_ENV
8888
- name: build config variables
89-
run: export CONFIG_OPTIONS="${TEST_LEVEL_FLAG} -GNinja -DT8CODE_USE_SYSTEM_SC=ON -DT8CODE_USE_SYSTEM_P4EST=ON -DT8CODE_BUILD_PEDANTIC=ON -DT8CODE_BUILD_WALL=ON -DT8CODE_BUILD_WERROR=ON -DT8CODE_ENABLE_MPI=$MPI -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSC_DIR=$SC_PATH/install/cmake -DP4EST_DIR=$P4EST_PATH/install/cmake -DT8CODE_BUILD_FORTRAN_INTERFACE=ON"
89+
run: export CONFIG_OPTIONS="${TEST_LEVEL_FLAG} -GNinja -DT8CODE_USE_SYSTEM_SC=ON -DT8CODE_USE_SYSTEM_P4EST=ON -DT8CODE_BUILD_PEDANTIC=ON -DT8CODE_BUILD_WALL=ON -DT8CODE_BUILD_WERROR=ON -DT8CODE_ENABLE_MPI=$MPI -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSC_DIR=$SC_PATH/install/cmake -DP4EST_DIR=$P4EST_PATH/install/cmake -DT8CODE_BUILD_FORTRAN_INTERFACE=ON -DT8CODE_BUILD_MESH_HANDLE=ON"
9090
&& echo CONFIG_OPTIONS="$CONFIG_OPTIONS" >> $GITHUB_ENV
9191
# cmake
9292
- name: echo cmake line

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ cmake_dependent_option( T8CODE_BUILD_TPL_EXAMPLES "Build the examples from libsc
4848

4949
option( T8CODE_BUILD_TUTORIALS "Build t8code's tutorials" ON )
5050
option( T8CODE_BUILD_BENCHMARKS "Build t8code's benchmarks" ON )
51+
option( T8CODE_BUILD_MESH_HANDLE "Build t8code's mesh handle" OFF )
5152
option( T8CODE_BUILD_FORTRAN_INTERFACE "Build t8code's Fortran interface" OFF )
5253

5354
option( T8CODE_ENABLE_MPI "Enable t8code's features which rely on MPI" ON )
@@ -247,6 +248,10 @@ endif()
247248

248249
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/src )
249250

251+
if( T8CODE_BUILD_MESH_HANDLE )
252+
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/mesh_handle )
253+
endif()
254+
250255
if ( T8CODE_BUILD_TESTS )
251256
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/test )
252257
endif()

doc/Doxyfile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,7 @@ WARN_LOGFILE =
982982
# Note: If this tag is empty the current directory is searched.
983983

984984
INPUT = @top_srcdir@/src \
985+
@top_srcdir@/mesh_handle \
985986
@top_srcdir@/doc/mainpage.dox
986987

987988
# This tag can be used to specify the character encoding of the source files

mesh_handle/CMakeLists.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# This file is part of t8code.
2+
# t8code is a C library to manage a collection (a forest) of multiple
3+
# connected adaptive space-trees of general element types in parallel.
4+
#
5+
# Copyright (C) 2025 the developers
6+
#
7+
# t8code is free software; you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation; either version 2 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# t8code is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with t8code; if not, write to the Free Software Foundation, Inc.,
19+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20+
21+
# Define own library for mesh handle.
22+
if ( T8CODE_BUILD_AS_SHARED_LIBRARY )
23+
add_library( T8_MESH_HANDLE SHARED )
24+
set_target_properties( T8_MESH_HANDLE PROPERTIES POSITION_INDEPENDENT_CODE ON )
25+
else()
26+
add_library( T8_MESH_HANDLE STATIC )
27+
endif()
28+
29+
add_library( T8CODE::T8_MESH_HANDLE ALIAS T8_MESH_HANDLE )
30+
set_target_properties(T8_MESH_HANDLE PROPERTIES OUTPUT_NAME mesh_handle)
31+
32+
target_include_directories( T8_MESH_HANDLE PUBLIC
33+
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/..>
34+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include/mesh_handle>
35+
)
36+
37+
target_sources(T8_MESH_HANDLE PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/mesh.cxx)
38+
install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
39+
DESTINATION include/
40+
FILES_MATCHING PATTERN "*.hxx"
41+
)
42+
43+
target_link_libraries(T8_MESH_HANDLE PUBLIC T8)
44+
45+
install( TARGETS T8_MESH_HANDLE
46+
EXPORT ${PROJECT_NAME}-targets
47+
ARCHIVE DESTINATION lib
48+
LIBRARY DESTINATION lib
49+
RUNTIME DESTINATION bin
50+
)
51+
52+
if( T8CODE_EXPORT_COMPILE_COMMANDS )
53+
set_target_properties( T8_MESH_HANDLE PROPERTIES EXPORT_COMPILE_COMMANDS ON )
54+
endif( T8CODE_EXPORT_COMPILE_COMMANDS )

mesh_handle/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# mesh_handle #
2+
**REMARK: Please note that this feature is still work-in-progress, so a lot of functionality is still missing, but will be added step by step.**
3+
4+
In this folder, we define a mesh handle.
5+
Some application codes are designed for unstructured or uniform meshes and cannot use t8code's tree-based structures directly. For this purpose, an iterable mesh data structure is created as an intermediate level. This frees the users from having to work with the forest-of-trees based concept and increases the usability. Please note that it is not guaranteed that the mesh is conformal and does not contain hanging nodes.
6+
7+
If you want to use the handle, note that is has its own library. Turn the option `T8CODE_BUILD_MESH_HANDLE` to `ON` and link against the target `T8_MESH_HANDLE` in addition to the usual t8code target please.
8+
9+
The [mesh.hxx](mesh.hxx) defines the mesh class of the handle.
10+
The [element.hxx](element.hxx) defines the elements used in the mesh class.
11+
The [competences.hxx](competences.hxx) defines additional competences/functionality of an element to access additional data.

mesh_handle/competences.hxx

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
This file is part of t8code.
3+
t8code is a C library to manage a collection (a forest) of multiple
4+
connected adaptive space-trees of general element classes in parallel.
5+
6+
Copyright (C) 2025 the developers
7+
8+
t8code is free software; you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation; either version 2 of the License, or
11+
(at your option) any later version.
12+
13+
t8code is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with t8code; if not, write to the Free Software Foundation, Inc.,
20+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21+
*/
22+
23+
/** \file competences.hxx
24+
* Definition of the additional competences/functionalities that can be used for the mesh class.
25+
* Especially, competences to cache functionalities of elements instead of calculating them each time a function
26+
* is called are provided.
27+
*
28+
* All competences have the same inheritance pattern:
29+
* We use the CRTP pattern as we may need to access members of the derived class \ref t8_mesh_handle::element.
30+
* The t8_crtp_operator is used for convenience/clear code (avoid to type a static cast explicitly each time
31+
* we need functionality of TUnderlying).
32+
* Especially for the competences to cache functionality, the access of members is not necessary,
33+
* such that it is not obvious why we use the crtp. For competences that extend the functionality of the element,
34+
* this is required.
35+
* We use it for all competences for consistency and compatibility with the \ref t8_mesh_handle::element class.
36+
*/
37+
38+
#ifndef T8_COMPETENCES_HXX
39+
#define T8_COMPETENCES_HXX
40+
41+
#include <t8.h>
42+
#include <t8_types/t8_operators.hxx>
43+
#include <t8_types/t8_vec.hxx>
44+
#include <t8_eclass.h>
45+
#include <array>
46+
#include <vector>
47+
#include <optional>
48+
49+
namespace t8_mesh_handle
50+
{
51+
52+
/**
53+
* Competence to cache the vertex coordinates of an element at the first function call.
54+
* \tparam TUnderlying Use the \ref element with specified competences as template parameter.
55+
*/
56+
template <typename TUnderlying>
57+
struct cache_vertex_coordinates: public t8_crtp_operator<TUnderlying, cache_vertex_coordinates>
58+
{
59+
public:
60+
/**
61+
* Function that checks if the cache for the vertex coordinates has been filled.
62+
* \return true if the cache for the vertex coordinates has been filled, false otherwise.
63+
*/
64+
bool
65+
vertex_cache_filled () const
66+
{
67+
return !m_vertex_coordinates.empty ();
68+
}
69+
70+
protected:
71+
mutable std::vector<t8_3D_point>
72+
m_vertex_coordinates; /**< Cache for the vector of vertex coordinate arrays. Empty vector if not filled. */
73+
};
74+
75+
/**
76+
* Competence to cache the centroid of an element at the first function call.
77+
* \tparam TUnderlying Use the \ref element with specified competences as template parameter.
78+
*/
79+
template <typename TUnderlying>
80+
struct cache_centroid: public t8_crtp_operator<TUnderlying, cache_centroid>
81+
{
82+
public:
83+
/**
84+
* Function that checks if the cache for the centroid has been filled.
85+
* \return true if the cache for the centroid has been filled, false otherwise.
86+
*/
87+
bool
88+
centroid_cache_filled () const
89+
{
90+
return m_centroid.has_value ();
91+
}
92+
93+
protected:
94+
mutable std::optional<t8_3D_point>
95+
m_centroid; /**< Cache for the coordinates of the centroid. Use optional to allow no value if cache is not filled. */
96+
};
97+
98+
} // namespace t8_mesh_handle
99+
#endif /* !T8_COMPETENCES_HXX */

0 commit comments

Comments
 (0)