Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
9619869
add files
lenaploetzke May 19, 2025
8b3fa7e
iterator
lenaploetzke May 20, 2025
ccc4dad
indent ...
lenaploetzke May 20, 2025
4264e15
some progress
lenaploetzke May 20, 2025
27ee532
added test
lenaploetzke May 26, 2025
758e9e3
Merge branch 'main' into 1655-define-structure-of-the-unstructured-me…
lenaploetzke Jul 24, 2025
9f6ded1
define end and begin
lenaploetzke Jul 31, 2025
9f3a411
first test working
lenaploetzke Aug 5, 2025
f5c7efa
make unstructured mesh element a template parameter
lenaploetzke Aug 11, 2025
83bac71
Added documentation
lenaploetzke Aug 11, 2025
2e8c994
add cache for level
lenaploetzke Aug 11, 2025
38fb9a4
missing docu
lenaploetzke Aug 12, 2025
9b89bc3
changes before restructuring
lenaploetzke Aug 15, 2025
e4886e5
Apply suggestions from code review
lenaploetzke Aug 15, 2025
ac439be
review comments
lenaploetzke Aug 15, 2025
7eed40a
Merge branch 'main' into 1655-define-structure-of-the-unstructured-me…
lenaploetzke Aug 15, 2025
0cd5d28
new concept
lenaploetzke Aug 15, 2025
cdda8a2
remove wrong access to vector
lenaploetzke Aug 15, 2025
b514275
minimal working structure
lenaploetzke Aug 21, 2025
8d8e4de
calculate in element
lenaploetzke Aug 21, 2025
3f3960d
rlly use cache
lenaploetzke Aug 22, 2025
3351e35
begin cleanup
lenaploetzke Aug 22, 2025
381a852
begin documenting
lenaploetzke Sep 10, 2025
d9291b4
Merge branch 'main' into 1655-define-structure-of-the-unstructured-me…
lenaploetzke Sep 10, 2025
4fb3807
second competence
lenaploetzke Sep 10, 2025
ad9fcc1
add test with two competences
lenaploetzke Sep 11, 2025
e8fc7bc
added documentation
lenaploetzke Sep 11, 2025
af4a010
own file for element
lenaploetzke Sep 12, 2025
3de92ec
add brackets
lenaploetzke Sep 15, 2025
0c60828
use helper function
lenaploetzke Sep 15, 2025
af052d7
renaming
lenaploetzke Sep 15, 2025
4128c9b
Use array instead of pointer and optional for cache
lenaploetzke Sep 16, 2025
a654195
add coordinates function
lenaploetzke Sep 16, 2025
0d4c0b2
add push back
lenaploetzke Sep 16, 2025
ffbc948
rename test file, delete cache level, add vertex coord cache
lenaploetzke Sep 18, 2025
aadcc32
add _serial
lenaploetzke Sep 19, 2025
3d60de8
Apply suggestions from code review
lenaploetzke Sep 22, 2025
054dd77
Suggestions README
lenaploetzke Sep 22, 2025
140be0c
add CRTP to description
lenaploetzke Sep 22, 2025
189a976
add getter for element and tree class
lenaploetzke Sep 22, 2025
1dd40f5
Merge branch 'main' into 1655-define-structure-of-the-unstructured-me…
lenaploetzke Sep 22, 2025
3ad6d6a
add getter for element and tree class
lenaploetzke Sep 23, 2025
78b2f50
add cxx file to cmake
lenaploetzke Sep 24, 2025
65283ad
avoid duplication for vertex coordinates
lenaploetzke Sep 24, 2025
5c99b9d
avoid duplication for centroid
lenaploetzke Sep 24, 2025
1a81fc8
handle empty forests
lenaploetzke Sep 24, 2025
7594d4c
delete cxx file
lenaploetzke Sep 29, 2025
d2f005e
clean up includes
lenaploetzke Sep 29, 2025
6ea4849
Merge branch 'improve-codecov-for-templated-code' into 1655-define-st…
lenaploetzke Oct 6, 2025
af5aef7
Merge branch 'main' into 1655-define-structure-of-the-unstructured-me…
lenaploetzke Oct 7, 2025
f6ad307
Apply suggestions from code review
lenaploetzke Oct 7, 2025
891db2e
code review
lenaploetzke Oct 7, 2025
8f0e9a3
Apply suggestions from code review
lenaploetzke Oct 7, 2025
83638ee
code review
lenaploetzke Oct 7, 2025
c22fbd9
Apply suggestions from code review
lenaploetzke Oct 7, 2025
7a128c4
add missing consts
lenaploetzke Oct 10, 2025
131a295
flat vector and delete iterator
lenaploetzke Oct 10, 2025
b207f1f
use t8_3d_vec instead of array
lenaploetzke Oct 10, 2025
b9642e5
implement [] operator
lenaploetzke Oct 10, 2025
bcb8c38
rm const from operator
lenaploetzke Oct 14, 2025
41a9782
Merge pull request #1892 from DLR-AMR/unstructured-use-flat-vector-fo…
lenaploetzke Oct 14, 2025
cebf72b
added test with custom competence
lenaploetzke Oct 15, 2025
1a17965
correct access specifier in competence and easier use of members.
lenaploetzke Oct 15, 2025
4b4acb7
faster unstructured mesh test
lenaploetzke Oct 15, 2025
c7c6464
added missing !
lenaploetzke Oct 16, 2025
a1f62c6
Apply suggestions from code review
lenaploetzke Oct 20, 2025
552cc29
first ideas
lenaploetzke Oct 20, 2025
ad5c5eb
Merge branch '1655-define-structure-of-the-unstructured-mesh-class' o…
lenaploetzke Oct 20, 2025
5cef37a
undo things for another branch, dont know what happened here
lenaploetzke Oct 20, 2025
f18eba9
indent
lenaploetzke Oct 20, 2025
05d9698
documentation for cache function variables
lenaploetzke Oct 20, 2025
2051314
add constant iterator
lenaploetzke Oct 20, 2025
0cd9d49
add mutable keyword
lenaploetzke Oct 20, 2025
4e293dc
Apply suggestions from code review
lenaploetzke Oct 21, 2025
24fdfc2
cmakefiles
lenaploetzke Oct 21, 2025
4dfa67d
added cxx file
lenaploetzke Oct 21, 2025
9f6ace0
code review
lenaploetzke Oct 21, 2025
945b6cd
Merge branch '1655-define-structure-of-the-unstructured-mesh-class' i…
lenaploetzke Oct 21, 2025
ce8c142
change location of add_subdir
lenaploetzke Oct 21, 2025
a69417e
typoin cmake test
lenaploetzke Oct 22, 2025
13360ae
add has_..._cache functions
lenaploetzke Oct 22, 2025
0d538bf
review
lenaploetzke Oct 22, 2025
c906f7b
Merge pull request #1895 from DLR-AMR/interface-custom-competence-test
lenaploetzke Oct 22, 2025
eeb3e12
Merge branch '1655-define-structure-of-the-unstructured-mesh-class' i…
lenaploetzke Oct 22, 2025
99c5133
new location of interface
lenaploetzke Oct 22, 2025
113be94
move tests to api
lenaploetzke Oct 22, 2025
35ea103
add mesh interface to api test
lenaploetzke Oct 23, 2025
4063c6e
add option to codecov and valgrind
lenaploetzke Oct 23, 2025
a466b6d
parallel instead of serial test
lenaploetzke Oct 23, 2025
2d80444
rename files
lenaploetzke Oct 23, 2025
8de5b00
rename classes etc
lenaploetzke Oct 23, 2025
030bfc5
rename to mesh_handle and use namespaces
lenaploetzke Oct 28, 2025
70bb807
indent comments
lenaploetzke Oct 28, 2025
2327a2a
review
lenaploetzke Oct 31, 2025
c4265f8
Merge pull request #1914 from DLR-AMR/interface-as-cmake-library
lenaploetzke Nov 5, 2025
fcfe285
Merge branch '1655-define-structure-of-the-unstructured-mesh-class' i…
lenaploetzke Nov 5, 2025
81bdee1
add handle to doxygen and resolve doxygen errors
lenaploetzke Nov 5, 2025
139e0f4
formatting
lenaploetzke Nov 5, 2025
29e7aef
Merge pull request #1923 from DLR-AMR/rename-unstructured-mesh-interface
lenaploetzke Nov 6, 2025
d2bee70
Merge branch 'main' into 1655-define-structure-of-the-unstructured-me…
lenaploetzke Nov 6, 2025
1f13cf7
Apply suggestions from code review
lenaploetzke Nov 21, 2025
d5952b2
Merge branch 'main' into 1655-define-structure-of-the-unstructured-me…
lenaploetzke Nov 21, 2025
34297c5
code review
lenaploetzke Nov 21, 2025
5147546
adapt cmake according to review
lenaploetzke Nov 21, 2025
7a6e040
delete unnecessary include and make public inheritance explicit
lenaploetzke Nov 24, 2025
2d786dc
Apply suggestions from code review
lenaploetzke Nov 25, 2025
954f9a7
review
lenaploetzke Nov 25, 2025
5f38e06
access operator and iterator const
lenaploetzke Nov 25, 2025
7b7d424
last forgotten interface
lenaploetzke Nov 25, 2025
bc913ab
moved file locations
lenaploetzke Nov 25, 2025
8ec1bb7
adapt cmake
lenaploetzke Nov 25, 2025
74a34f4
Merge branch 'main' into 1655-define-structure-of-the-unstructured-me…
sandro-elsweijer Nov 26, 2025
90401ed
Update include path for t8_cmesh header
sandro-elsweijer Nov 26, 2025
7f65c1a
Update include path for t8_cmesh header
sandro-elsweijer Nov 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
run: export TEST_LEVEL_FLAG="-DT8CODE_TEST_LEVEL=${{ inputs.TEST_LEVEL }}"
&& echo TEST_LEVEL_FLAG="$TEST_LEVEL_FLAG" >> $GITHUB_ENV
- name: build config variables
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"
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"
&& echo CONFIG_OPTIONS="$CONFIG_OPTIONS" >> $GITHUB_ENV
# cmake
- name: echo cmake line
Expand Down
30 changes: 14 additions & 16 deletions .github/workflows/tests_cmake_t8code_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,37 +85,35 @@ jobs:
run: export TEST_LEVEL_FLAG="-DT8CODE_TEST_LEVEL=${{ inputs.TEST_LEVEL }}"
&& echo TEST_LEVEL_FLAG="$TEST_LEVEL_FLAG" >> $GITHUB_ENV
- name: build config variables
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"
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"
&& echo CONFIG_OPTIONS="$CONFIG_OPTIONS" >> $GITHUB_ENV
# cmake and test with fortran
- name: check fortran
run: echo "Checking fortran"
# cmake and test with api options
- name: echo cmake line
run: echo cmake ../ $CONFIG_OPTIONS
- name: cmake MPI fortran debug
run: mkdir build_fortran && cd build_fortran && cmake ../ $CONFIG_OPTIONS
- name: cmake
run: mkdir build_api && cd build_api && cmake ../ $CONFIG_OPTIONS
- name: OnFailUploadLog
if: failure()
uses: actions/upload-artifact@v5
with:
name: cmake_${{ inputs.BUILD_TYPE }}_MPI_${{ inputs.MPI }}_fortran.log
path: build_fortran/CMakeFiles/CMakeOutput.log
- name: make
run: cd build_fortran && ninja $MAKEFLAGS
name: cmake_${{ inputs.BUILD_TYPE }}_MPI_${{ inputs.MPI }}_api.log
path: build_api/CMakeFiles/CMakeOutput.log
- name: ninja
run: cd build_api && ninja $MAKEFLAGS
- name: ninja install
run: cd build_fortran && ninja install $MAKEFLAGS
run: cd build_api && ninja install $MAKEFLAGS
- name: serial tests (if MPI is enabled)
run: cd build_fortran && ctest $MAKEFLAGS -R _serial
run: cd build_api && ctest $MAKEFLAGS -R _serial
if: ${{ inputs.MPI == 'ON' }}
- name: parallel tests (if MPI is enabled)
run: cd build_fortran && ctest -R _parallel
run: cd build_api && ctest -R _parallel
if: ${{ inputs.MPI == 'ON' }}
- name: tests (if MPI is disabled)
run: cd build_fortran && ctest $MAKEFLAGS
run: cd build_api && ctest $MAKEFLAGS
if: ${{ inputs.MPI == 'OFF' }}
- name: OnFailUploadLog
if: failure()
uses: actions/upload-artifact@v5
with:
name: test-suite_${{ inputs.BUILD_TYPE }}_MPI_${{ inputs.MPI }}_fortran.log
path: build_fortran/Testing/Temporary/LastTest.log
name: test-suite_${{ inputs.BUILD_TYPE }}_MPI_${{ inputs.MPI }}_api.log
path: build_api/Testing/Temporary/LastTest.log
2 changes: 1 addition & 1 deletion .github/workflows/tests_cmake_valgrind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
run: export TEST_LEVEL_FLAG="-DT8CODE_TEST_LEVEL=${{ inputs.TEST_LEVEL }}"
&& echo TEST_LEVEL_FLAG="$TEST_LEVEL_FLAG" >> $GITHUB_ENV
- name: build config variables
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"
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"
&& echo CONFIG_OPTIONS="$CONFIG_OPTIONS" >> $GITHUB_ENV
# cmake
- name: echo cmake line
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ cmake_dependent_option( T8CODE_BUILD_TPL_EXAMPLES "Build the examples from libsc

option( T8CODE_BUILD_TUTORIALS "Build t8code's tutorials" ON )
option( T8CODE_BUILD_BENCHMARKS "Build t8code's benchmarks" ON )
option( T8CODE_BUILD_MESH_HANDLE "Build t8code's mesh handle" OFF )
option( T8CODE_BUILD_FORTRAN_INTERFACE "Build t8code's Fortran interface" OFF )

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

add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/src )

if( T8CODE_BUILD_MESH_HANDLE )
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/mesh_handle )
endif()

if ( T8CODE_BUILD_TESTS )
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/test )
endif()
Expand Down
1 change: 1 addition & 0 deletions doc/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@ WARN_LOGFILE =
# Note: If this tag is empty the current directory is searched.

INPUT = @top_srcdir@/src \
@top_srcdir@/mesh_handle \
@top_srcdir@/doc/mainpage.dox

# This tag can be used to specify the character encoding of the source files
Expand Down
54 changes: 54 additions & 0 deletions mesh_handle/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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) 2025 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.

# Define own library for mesh handle.
if ( T8CODE_BUILD_AS_SHARED_LIBRARY )
add_library( T8_MESH_HANDLE SHARED )
set_target_properties( T8_MESH_HANDLE PROPERTIES POSITION_INDEPENDENT_CODE ON )
else()
add_library( T8_MESH_HANDLE STATIC )
endif()

add_library( T8CODE::T8_MESH_HANDLE ALIAS T8_MESH_HANDLE )
set_target_properties(T8_MESH_HANDLE PROPERTIES OUTPUT_NAME mesh_handle)

target_include_directories( T8_MESH_HANDLE PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/..>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include/mesh_handle>
)

target_sources(T8_MESH_HANDLE PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/mesh.cxx)
install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DESTINATION include/
FILES_MATCHING PATTERN "*.hxx"
)

target_link_libraries(T8_MESH_HANDLE PUBLIC T8)

install( TARGETS T8_MESH_HANDLE
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)

if( T8CODE_EXPORT_COMPILE_COMMANDS )
set_target_properties( T8_MESH_HANDLE PROPERTIES EXPORT_COMPILE_COMMANDS ON )
endif( T8CODE_EXPORT_COMPILE_COMMANDS )
11 changes: 11 additions & 0 deletions mesh_handle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# mesh_handle #
**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.**

In this folder, we define a mesh handle.
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.

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.

The [mesh.hxx](mesh.hxx) defines the mesh class of the handle.
The [element.hxx](element.hxx) defines the elements used in the mesh class.
The [competences.hxx](competences.hxx) defines additional competences/functionality of an element to access additional data.
99 changes: 99 additions & 0 deletions mesh_handle/competences.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
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 classes in parallel.

Copyright (C) 2025 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.
*/

/** \file competences.hxx
* Definition of the additional competences/functionalities that can be used for the mesh class.
* Especially, competences to cache functionalities of elements instead of calculating them each time a function
* is called are provided.
*
* All competences have the same inheritance pattern:
* We use the CRTP pattern as we may need to access members of the derived class \ref t8_mesh_handle::element.
* The t8_crtp_operator is used for convenience/clear code (avoid to type a static cast explicitly each time
* we need functionality of TUnderlying).
* Especially for the competences to cache functionality, the access of members is not necessary,
* such that it is not obvious why we use the crtp. For competences that extend the functionality of the element,
* this is required.
* We use it for all competences for consistency and compatibility with the \ref t8_mesh_handle::element class.
*/

#ifndef T8_COMPETENCES_HXX
#define T8_COMPETENCES_HXX

#include <t8.h>
#include <t8_types/t8_operators.hxx>
#include <t8_types/t8_vec.hxx>
#include <t8_eclass.h>
#include <array>
#include <vector>
#include <optional>

namespace t8_mesh_handle
{

/**
* Competence to cache the vertex coordinates of an element at the first function call.
* \tparam TUnderlying Use the \ref element with specified competences as template parameter.
*/
template <typename TUnderlying>
struct cache_vertex_coordinates: public t8_crtp_operator<TUnderlying, cache_vertex_coordinates>
{
public:
/**
* Function that checks if the cache for the vertex coordinates has been filled.
* \return true if the cache for the vertex coordinates has been filled, false otherwise.
*/
bool
vertex_cache_filled () const
{
return !m_vertex_coordinates.empty ();
}

protected:
mutable std::vector<t8_3D_point>
m_vertex_coordinates; /**< Cache for the vector of vertex coordinate arrays. Empty vector if not filled. */
};

/**
* Competence to cache the centroid of an element at the first function call.
* \tparam TUnderlying Use the \ref element with specified competences as template parameter.
*/
template <typename TUnderlying>
struct cache_centroid: public t8_crtp_operator<TUnderlying, cache_centroid>
{
public:
/**
* Function that checks if the cache for the centroid has been filled.
* \return true if the cache for the centroid has been filled, false otherwise.
*/
bool
centroid_cache_filled () const
{
return m_centroid.has_value ();
}

protected:
mutable std::optional<t8_3D_point>
m_centroid; /**< Cache for the coordinates of the centroid. Use optional to allow no value if cache is not filled. */
};

} // namespace t8_mesh_handle
#endif /* !T8_COMPETENCES_HXX */
Loading