From 0664bbaea05bbaa1fbb734dfbc7f1e6664295092 Mon Sep 17 00:00:00 2001 From: Timo Koch <timo.koch@iws.uni-stuttgart.de> Date: Wed, 30 Nov 2022 16:42:18 +0100 Subject: [PATCH] [box] Do not store corners in scv/scvf to save memory --- dumux/discretization/box/fvelementgeometry.hh | 43 +++++++++++-------- dumux/discretization/box/fvgridgeometry.hh | 9 ++-- dumux/discretization/box/subcontrolvolume.hh | 19 ++++---- .../box/subcontrolvolumeface.hh | 30 ++++++------- .../facet/box/fvelementgeometry.hh | 2 +- dumux/multidomain/facet/box/fvgridgeometry.hh | 2 +- .../facet/box/subcontrolvolumeface.hh | 2 - 7 files changed, 57 insertions(+), 50 deletions(-) diff --git a/dumux/discretization/box/fvelementgeometry.hh b/dumux/discretization/box/fvelementgeometry.hh index 15068aa1e5..514d63759a 100644 --- a/dumux/discretization/box/fvelementgeometry.hh +++ b/dumux/discretization/box/fvelementgeometry.hh @@ -416,10 +416,12 @@ private: const auto dofIdxGlobal = gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim); // add scv to the local container - scvs_[scvLocalIdx] = SubControlVolume(geometryHelper, - scvLocalIdx, - eIdx_, - dofIdxGlobal); + scvs_[scvLocalIdx] = SubControlVolume( + geometryHelper.getScvCorners(scvLocalIdx), + scvLocalIdx, + eIdx_, + dofIdxGlobal + ); } // construct the sub control volume faces @@ -434,12 +436,16 @@ private: std::vector<LocalIndexType> localScvIndices({static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)), static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))}); - scvfs_[scvfLocalIdx] = SubControlVolumeFace(geometryHelper, - element, - elementGeometry, - scvfLocalIdx, - std::move(localScvIndices), - false); + const auto& corners = geometryHelper.getScvfCorners(scvfLocalIdx); + scvfs_[scvfLocalIdx] = SubControlVolumeFace( + corners, + geometryHelper.normal(corners, localScvIndices), + element, + elementGeometry, + scvfLocalIdx, + std::move(localScvIndices), + false + ); } // construct the sub control volume faces on the domain boundary @@ -456,13 +462,16 @@ private: const LocalIndexType insideScvIdx = static_cast<LocalIndexType>(refElement.subEntity(intersection.indexInInside(), 1, isScvfLocalIdx, dim)); std::vector<LocalIndexType> localScvIndices = {insideScvIdx, insideScvIdx}; - scvfs_.emplace_back(geometryHelper, - intersection, - isGeometry, - isScvfLocalIdx, - scvfLocalIdx, - std::move(localScvIndices), - true); + scvfs_.emplace_back( + geometryHelper.getBoundaryScvfCorners(intersection.indexInInside(), isScvfLocalIdx), + intersection.centerUnitOuterNormal(), + intersection, + isGeometry, + isScvfLocalIdx, + scvfLocalIdx, + std::move(localScvIndices), + true + ); scvfBoundaryGeometryKeys_.emplace_back(std::array<LocalIndexType, 2>{{ static_cast<LocalIndexType>(intersection.indexInInside()), diff --git a/dumux/discretization/box/fvgridgeometry.hh b/dumux/discretization/box/fvgridgeometry.hh index e2d04e72fe..0a7f13bfc6 100644 --- a/dumux/discretization/box/fvgridgeometry.hh +++ b/dumux/discretization/box/fvgridgeometry.hh @@ -277,7 +277,7 @@ private: const auto dofIdxGlobal = this->vertexMapper().subIndex(element, scvLocalIdx, dim); cache_.scvs_[eIdx][scvLocalIdx] = SubControlVolume( - geometryHelper, + geometryHelper.getScvCorners(scvLocalIdx), scvLocalIdx, eIdx, dofIdxGlobal @@ -293,8 +293,10 @@ private: std::vector<LocalIndexType> localScvIndices({static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)), static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))}); + const auto& corners = geometryHelper.getScvfCorners(scvfLocalIdx); cache_.scvfs_[eIdx][scvfLocalIdx] = SubControlVolumeFace( - geometryHelper, + corners, + geometryHelper.normal(corners, localScvIndices), element, elementGeometry, scvfLocalIdx, @@ -322,7 +324,8 @@ private: std::vector<LocalIndexType> localScvIndices = {insideScvIdx, insideScvIdx}; cache_.scvfs_[eIdx].emplace_back( - geometryHelper, + geometryHelper.getBoundaryScvfCorners(intersection.indexInInside(), isScvfLocalIdx), + intersection.centerUnitOuterNormal(), intersection, isGeometry, isScvfLocalIdx, diff --git a/dumux/discretization/box/subcontrolvolume.hh b/dumux/discretization/box/subcontrolvolume.hh index 3fcc6053f7..70b1035795 100644 --- a/dumux/discretization/box/subcontrolvolume.hh +++ b/dumux/discretization/box/subcontrolvolume.hh @@ -56,7 +56,7 @@ struct BoxDefaultScvGeometryTraits using GeometryTraits = BoxMLGeometryTraits<Scalar>; using Geometry = Dune::MultiLinearGeometry<Scalar, dim, dimWorld, GeometryTraits>; using CornerStorage = typename GeometryTraits::template CornerStorage<dim, dimWorld>::Type; - using GlobalPosition = typename CornerStorage::value_type; + using GlobalPosition = typename Geometry::GlobalCoordinate; }; /*! @@ -76,7 +76,6 @@ class BoxSubControlVolume using GridIndexType = typename T::GridIndexType; using LocalIndexType = typename T::LocalIndexType; using Scalar = typename T::Scalar; - using CornerStorage = typename T::CornerStorage; static constexpr int dim = Geometry::mydimension; public: @@ -89,20 +88,21 @@ public: BoxSubControlVolume() = default; // the constructor in the box case - template<class GeometryHelper> - BoxSubControlVolume(const GeometryHelper& geometryHelper, + template<class Corners> + BoxSubControlVolume(const Corners& corners, LocalIndexType scvIdx, GridIndexType elementIndex, GridIndexType dofIndex) - : corners_(geometryHelper.getScvCorners(scvIdx)) - , center_(Dumux::center(corners_)) + : dofPosition_(corners[0]) + , center_(Dumux::center(corners)) , elementIndex_(elementIndex) , localDofIdx_(scvIdx) , dofIndex_(dofIndex) { + // The corner list is defined such that the first entry is the vertex itself volume_ = Dumux::convexPolytopeVolume<dim>( Dune::GeometryTypes::cube(dim), - [&](unsigned int i){ return corners_[i]; } + [&](unsigned int i){ return corners[i]; } ); } @@ -140,8 +140,7 @@ public: // The position of the dof this scv is embedded in const GlobalPosition& dofPosition() const { - // The corner list is defined such that the first entry is the vertex itself - return corners_[0]; + return dofPosition_; } //! The global index of the element this scv is embedded in @@ -151,7 +150,7 @@ public: } private: - CornerStorage corners_; + GlobalPosition dofPosition_; GlobalPosition center_; Scalar volume_; GridIndexType elementIndex_; diff --git a/dumux/discretization/box/subcontrolvolumeface.hh b/dumux/discretization/box/subcontrolvolumeface.hh index 8e7c86d293..5f6c081889 100644 --- a/dumux/discretization/box/subcontrolvolumeface.hh +++ b/dumux/discretization/box/subcontrolvolumeface.hh @@ -56,7 +56,7 @@ struct BoxDefaultScvfGeometryTraits using GeometryTraits = BoxMLGeometryTraits<Scalar>; using Geometry = Dune::MultiLinearGeometry<Scalar, dim-1, dimWorld, GeometryTraits>; using CornerStorage = typename GeometryTraits::template CornerStorage<dim-1, dimWorld>::Type; - using GlobalPosition = typename CornerStorage::value_type; + using GlobalPosition = typename Geometry::GlobalCoordinate; using BoundaryFlag = Dumux::BoundaryFlag<Grid>; }; @@ -77,7 +77,6 @@ class BoxSubControlVolumeFace using GridIndexType = typename T::GridIndexType; using LocalIndexType = typename T::LocalIndexType; using Scalar = typename T::Scalar; - using CornerStorage = typename T::CornerStorage; using Geometry = typename T::Geometry; using BoundaryFlag = typename T::BoundaryFlag; static constexpr int dim = Geometry::mydimension; @@ -92,16 +91,16 @@ public: BoxSubControlVolumeFace() = default; //! Constructor for inner scvfs - template<class GeometryHelper, class Element> - BoxSubControlVolumeFace(const GeometryHelper& geometryHelper, + template<class Corners, class Element> + BoxSubControlVolumeFace(const Corners& corners, + const GlobalPosition& normal, const Element& element, const typename Element::Geometry& elemGeometry, GridIndexType scvfIndex, std::vector<LocalIndexType>&& scvIndices, bool boundary = false) - : corners_(geometryHelper.getScvfCorners(scvfIndex)) - , center_(Dumux::center(corners_)) - , unitOuterNormal_(geometryHelper.normal(corners_, scvIndices)) + : center_(Dumux::center(corners)) + , unitOuterNormal_(normal) , scvfIndex_(scvfIndex) , scvIndices_(std::move(scvIndices)) , boundary_(boundary) @@ -109,30 +108,30 @@ public: { area_ = Dumux::convexPolytopeVolume<dim>( Dune::GeometryTypes::cube(dim), - [&](unsigned int i){ return corners_[i]; } + [&](unsigned int i){ return corners[i]; } ); } //! Constructor for boundary scvfs - template<class GeometryHelper, class Intersection> - BoxSubControlVolumeFace(const GeometryHelper& geometryHelper, + template<class Corners, class Intersection> + BoxSubControlVolumeFace(const Corners& corners, + const GlobalPosition& normal, const Intersection& intersection, const typename Intersection::Geometry& isGeometry, LocalIndexType indexInIntersection, GridIndexType scvfIndex, std::vector<LocalIndexType>&& scvIndices, bool boundary = false) - : corners_(geometryHelper.getBoundaryScvfCorners(intersection.indexInInside(), indexInIntersection)) - , center_(Dumux::center(corners_)) - , unitOuterNormal_(intersection.centerUnitOuterNormal()) + : center_(Dumux::center(corners)) + , unitOuterNormal_(normal) , scvfIndex_(scvfIndex) - , scvIndices_(std:: move(scvIndices)) + , scvIndices_(std::move(scvIndices)) , boundary_(boundary) , boundaryFlag_{intersection} { area_ = Dumux::convexPolytopeVolume<dim>( Dune::GeometryTypes::cube(dim), - [&](unsigned int i){ return corners_[i]; } + [&](unsigned int i){ return corners[i]; } ); } @@ -198,7 +197,6 @@ public: } private: - CornerStorage corners_; GlobalPosition center_; GlobalPosition unitOuterNormal_; Scalar area_; diff --git a/dumux/multidomain/facet/box/fvelementgeometry.hh b/dumux/multidomain/facet/box/fvelementgeometry.hh index 3549e92e7a..2e635386d0 100644 --- a/dumux/multidomain/facet/box/fvelementgeometry.hh +++ b/dumux/multidomain/facet/box/fvelementgeometry.hh @@ -322,7 +322,7 @@ private: scvs_.reserve(elementGeometry.corners()); using LocalIndexType = typename SubControlVolumeFace::Traits::LocalIndexType; for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx) - scvs_.emplace_back(geometryHelper, + scvs_.emplace_back(geometryHelper.getScvCorners(scvLocalIdx), scvLocalIdx, eIdx_, gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim)); diff --git a/dumux/multidomain/facet/box/fvgridgeometry.hh b/dumux/multidomain/facet/box/fvgridgeometry.hh index a9aaba7a83..ea58484d8a 100644 --- a/dumux/multidomain/facet/box/fvgridgeometry.hh +++ b/dumux/multidomain/facet/box/fvgridgeometry.hh @@ -268,7 +268,7 @@ private: scvs_[eIdx].clear(); scvs_[eIdx].reserve(elementGeometry.corners()); for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx) - scvs_[eIdx].emplace_back(geometryHelper, + scvs_[eIdx].emplace_back(geometryHelper.getScvCorners(scvLocalIdx), scvLocalIdx, eIdx, this->vertexMapper().subIndex(element, scvLocalIdx, dim)); diff --git a/dumux/multidomain/facet/box/subcontrolvolumeface.hh b/dumux/multidomain/facet/box/subcontrolvolumeface.hh index c3b14ec4bd..cdbab75a42 100644 --- a/dumux/multidomain/facet/box/subcontrolvolumeface.hh +++ b/dumux/multidomain/facet/box/subcontrolvolumeface.hh @@ -51,8 +51,6 @@ template<class GV, class T = BoxDefaultScvfGeometryTraits<GV> > class BoxFacetCouplingSubControlVolumeFace : public SubControlVolumeFaceBase<BoxFacetCouplingSubControlVolumeFace<GV, T>, T> { - using ThisType = BoxSubControlVolumeFace<GV, T>; - using ParentType = SubControlVolumeFaceBase<ThisType, T>; using GridIndexType = typename T::GridIndexType; using LocalIndexType = typename T::LocalIndexType; using Scalar = typename T::Scalar; -- GitLab