diff --git a/src/t8_unstructured_mesh/t8_element_competences.hxx b/src/t8_unstructured_mesh/t8_element_competences.hxx index 4d8d2058fe..ead2f83aa7 100644 --- a/src/t8_unstructured_mesh/t8_element_competences.hxx +++ b/src/t8_unstructured_mesh/t8_element_competences.hxx @@ -53,28 +53,18 @@ along with t8code; if not, write to the Free Software Foundation, Inc., template struct t8_cache_vertex_coordinates: t8_crtp_operator { - private: + public: /** - * Returns the previously cached vector with the vertex coordinates of the unstructured mesh element. - * \return Constant reference to the cached vector with the vertex coordinates. + * 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. */ - const std::vector& - get_vertex_coordinates_cached () const + bool + vertex_cache_filled () const { - return m_vertex_coordinates; - } - - /** - * Setter for the cache. - * \param [in] new_vertex_coordinates Vector with the coordinates of the vertices of the - * unstructured mesh element that should be cached. - */ - void - set_vertex_coordinates_cached (std::vector&& new_vertex_coordinates) - { - m_vertex_coordinates = std::move (new_vertex_coordinates); + return !m_vertex_coordinates.empty (); } + protected: mutable std::vector m_vertex_coordinates; /**< Cache for the vector of vertex coordinate arrays. Empty vector if not filled. */ }; @@ -86,30 +76,20 @@ struct t8_cache_vertex_coordinates: t8_crtp_operator struct t8_cache_centroid: t8_crtp_operator { - private: - /** - * Returns an optional with the centroid coordinates for an unstructured mesh element if previously cached. - * \return Optional with coordinates of the centroid of the unstructured mesh element. - */ - std::optional - get_centroid_cached () const - { - return m_coordinates; - } - + public: /** - * Setter for the cache. - * \param [in] new_centroid_coordinates Array with the coordinates of the centroid of the - * unstructured mesh element that should be cached. + * 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. */ - void - set_centroid_cached (t8_3D_vec new_centroid_coordinates) + bool + centroid_cache_filled () const { - m_coordinates = new_centroid_coordinates; + return m_centroid.has_value (); } + protected: mutable std::optional - m_coordinates; /**< Cache for the coordinates of the centroid. Use optional to allow no value if cache is not filled. */ + m_centroid; /**< Cache for the coordinates of the centroid. Use optional to allow no value if cache is not filled. */ }; #endif /* !T8_ELEMENT_COMPETENCES_HXX */ diff --git a/src/t8_unstructured_mesh/t8_unstructured_element.hxx b/src/t8_unstructured_mesh/t8_unstructured_element.hxx index a249673b99..d348085f2f 100644 --- a/src/t8_unstructured_mesh/t8_unstructured_element.hxx +++ b/src/t8_unstructured_mesh/t8_unstructured_element.hxx @@ -65,34 +65,33 @@ class t8_unstructured_mesh_element: public TCompetence class T> static constexpr bool - has_get_vertex_coordinates_cached () + vertex_cache_defined () { - return requires (T& competence) { competence.get_vertex_coordinates_cached (); }; + return requires (T& competence) { competence.vertex_cache_filled (); }; } /* This variable is true if any of the given competences \ref TCompetence implements - a function get_vertex_coordinates_cached. */ - static constexpr bool get_vertex_coordinates_defined - = (false || ... || has_get_vertex_coordinates_cached ()); + a function vertex_cache_filled */ + static constexpr bool vertex_cache_exists = (false || ... || vertex_cache_defined ()); - /** Helper function to check if class T implements the function get_centroid_cached. + /** Helper function to check if class T implements the function centroid_cache_filled. * \tparam T The competence to be checked. * \return true if T implements the function, false if not. */ template