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