diff --git a/dumux/discretization/basegridgeometry.hh b/dumux/discretization/basegridgeometry.hh index c14853150c997a2b0ffaa493ad1ef9ec912aa453..ae992f926e8f514249a7e02b39559aae9da12ae0 100644 --- a/dumux/discretization/basegridgeometry.hh +++ b/dumux/discretization/basegridgeometry.hh @@ -26,7 +26,6 @@ #include <utility> #include <type_traits> -#include <mutex> #include <dune/grid/common/mcmgmapper.hh> @@ -149,34 +148,13 @@ public: * \brief Returns the bounding box tree of the grid */ const BoundingBoxTree& boundingBoxTree() const - { - if (!boundingBoxTree_) - { - std::scoped_lock{ boundingBoxTreeMutex_ }; - if (!boundingBoxTree_) - elementMap(); // make sure the element map is built - boundingBoxTree_ = std::make_unique<BoundingBoxTree>( - std::make_shared<ElementSet>(gridView_, elementMapper(), elementMap_) - ); - } - - return *boundingBoxTree_; - } + { return *boundingBoxTree_; } /*! * \brief Returns the element index to element map */ const ElementMap& elementMap() const - { - if (!elementMap_) - { - std::scoped_lock{ elementMapMutex_ }; - if (!elementMap_) - elementMap_ = std::make_shared<ElementMap>(gridView_.grid(), elementMapper_); - } - - return *elementMap_; - } + { return *elementMap_; } /*! * \brief Get an element from a global element index @@ -258,7 +236,7 @@ private: void update_() { - //! Update the mappers + // Update the mappers if constexpr (Deprecated::hasUpdateGridView<ElementMapper, GridView>()) elementMapper_.update(gridView_); else @@ -269,12 +247,17 @@ private: else Deprecated::update(vertexMapper_); - //! Compute the bounding box of the entire domain, for e.g. setting boundary conditions + // Compute the bounding box of the entire domain, for e.g. setting boundary conditions computeGlobalBoundingBox_(); - //! reset bounding box tree and the element map until requested the next time - boundingBoxTree_.release(); - elementMap_.reset(); + // update element map and bounding box tree + // always building these comes at a memory overhead but improved + // performance and thread-safe element level access (e.g. during assembly) + // for all simulation that use these features + elementMap_ = std::make_shared<ElementMap>(gridView_.grid(), elementMapper_); + boundingBoxTree_ = std::make_unique<BoundingBoxTree>( + std::make_shared<ElementSet>(gridView_, elementMapper(), elementMap_) + ); } //! the process grid view @@ -285,12 +268,10 @@ private: VertexMapper vertexMapper_; //! the bounding box tree of the grid view for efficient element intersections - mutable std::unique_ptr<BoundingBoxTree> boundingBoxTree_; - mutable std::mutex boundingBoxTreeMutex_; + std::unique_ptr<const BoundingBoxTree> boundingBoxTree_; - //! a map from element index to elements (needed in the bounding box tree and for assembling cell-centered discretization) - mutable std::shared_ptr<ElementMap> elementMap_; - mutable std::mutex elementMapMutex_; + //! a map from element index to elements + std::shared_ptr<const ElementMap> elementMap_; //! the bounding box of the whole domain GlobalCoordinate bBoxMin_;