diff --git a/opm/grid/CpGrid.hpp b/opm/grid/CpGrid.hpp index 0e00a0e70..7875ddd88 100644 --- a/opm/grid/CpGrid.hpp +++ b/opm/grid/CpGrid.hpp @@ -1743,7 +1743,7 @@ namespace Dune /// \brief Get the Position of a vertex. /// \param cell The index identifying the cell. /// \return The coordinates of the vertex. - const Vector& vertexPosition(int vertex) const; + Vector vertexPosition(int vertex) const; /// \brief Get the area of a face. /// \param cell The index identifying the face. @@ -1751,12 +1751,12 @@ namespace Dune /// \brief Get the coordinates of the center of a face. /// \param cell The index identifying the face. - const Vector& faceCentroid(int face) const; + Vector faceCentroid(int face) const; /// \brief Get the unit normal of a face. /// \param cell The index identifying the face. /// \see faceCell - const Vector& faceNormal(int face) const; + Vector faceNormal(int face) const; /// \brief Get the volume of the cell. /// \param cell The index identifying the cell. @@ -1764,7 +1764,7 @@ namespace Dune /// \brief Get the coordinates of the center of a cell. /// \param cell The index identifying the face. - const Vector& cellCentroid(int cell) const; + Vector cellCentroid(int cell) const; /// \brief An iterator over the centroids of the geometry of the entities. /// \tparam codim The co-dimension of the entities. diff --git a/opm/grid/cpgrid/CpGrid.cpp b/opm/grid/cpgrid/CpGrid.cpp index 8eaac4e59..164300f24 100644 --- a/opm/grid/cpgrid/CpGrid.cpp +++ b/opm/grid/cpgrid/CpGrid.cpp @@ -1755,7 +1755,7 @@ const Dune::FieldVector CpGrid::faceAreaNormalEcl(int face) const } } -const Dune::FieldVector& CpGrid::vertexPosition(int vertex) const +Dune::FieldVector CpGrid::vertexPosition(int vertex) const { return current_view_data_->geomVector<3>()[cpgrid::EntityRep<3>(vertex, true)].center(); } @@ -1765,12 +1765,12 @@ double CpGrid::faceArea(int face) const return current_view_data_->geomVector<1>()[cpgrid::EntityRep<1>(face, true)].volume(); } -const Dune::FieldVector& CpGrid::faceCentroid(int face) const +Dune::FieldVector CpGrid::faceCentroid(int face) const { return current_view_data_->geomVector<1>()[cpgrid::EntityRep<1>(face, true)].center(); } -const Dune::FieldVector& CpGrid::faceNormal(int face) const +Dune::FieldVector CpGrid::faceNormal(int face) const { return current_view_data_->face_normals_.get(face); } @@ -1780,7 +1780,7 @@ double CpGrid::cellVolume(int cell) const return current_view_data_->geomVector<0>()[cpgrid::EntityRep<0>(cell, true)].volume(); } -const Dune::FieldVector& CpGrid::cellCentroid(int cell) const +Dune::FieldVector CpGrid::cellCentroid(int cell) const { return current_view_data_->geomVector<0>()[cpgrid::EntityRep<0>(cell, true)].center(); } @@ -2857,10 +2857,10 @@ void CpGrid::refineAndProvideMarkedRefinedRelations( /* Marked elements paramete int& cell_count, std::vector>& preAdapt_level_to_leaf_cells_vec, /* Additional parameters */ - const std::vector>& cells_per_dim_vec) const + const std::vector>& cells_per_dim_vec) const { // If the (level zero) grid has been distributed, then the preAdaptGrid is data_[0]. Otherwise, preApaptGrid is current_view_data_. - + // Each marked element for refinement (mark equal to 1), will be refined individuality, creating its own Lgr. The element index will // be also used to identify its lgr. Even though, in the end, all the refined entities will belong to a unique level grid. // For this reason, we associate "-1" with those elements that are not involved in any refinement and will appear @@ -2878,7 +2878,7 @@ void CpGrid::refineAndProvideMarkedRefinedRelations( /* Marked elements paramete cell_count +=1; preAdapt_level_to_leaf_cells_vec[element.level()][element.getLevelElem().index()] = cell_count; } - + // When the element is marked for refinement, we also mark its corners and faces // since they will get replaced by refined ones. if (getMark(element) == 1) { @@ -2914,7 +2914,7 @@ void CpGrid::refineAndProvideMarkedRefinedRelations( /* Marked elements paramete refined_cell_count_vec[shiftedLevel] +=1; } - + preAdapt_parent_to_children_cells_vec[element.level()][element.getLevelElem().index()] = std::make_pair( markedElemLevel, refinedChildrenList); for (const auto& [markedCorner, lgrEquivCorner] : parentCorners_to_equivalentRefinedCorners) { cornerInMarkedElemWithEquivRefinedCorner[markedCorner].push_back({elemIdx, lgrEquivCorner}); @@ -2934,7 +2934,7 @@ CpGrid::defineChildToParentAndIdxInParentCell(const std::map,s const int& cell_count) const { // If the (level zero) grid has been distributed, then the preAdaptGrid is data_[0]. Otherwise, preApaptGrid is current_view_data_. - + // ------------------------ Refined grid parameters // Refined child cells and their parents. Entry is {-1,-1} when cell has no father. Otherwise, {level parent cell, parent cell index} // Each entry represents a refined level. @@ -3304,7 +3304,7 @@ void CpGrid::identifyLeafGridCorners(std::map,int>& elemLgrAnd const std::vector>& cells_per_dim_vec) const { // If the (level zero) grid has been distributed, then the preAdaptGrid is data_[0]. Otherwise, preApaptGrid is current_view_data_. - + // Step 1. Select/store the corners from the starting grid not involved in any (new) LGR. // Replace the corners from level zero involved in LGR by the equivalent ones, born in LGRs. // In this case, we avoid repetition considering the last appearance of the level zero corner @@ -3458,8 +3458,8 @@ void CpGrid::identifyLeafGridFaces(std::map,int>& elemLgrAndEl // If the (level zero) grid has been distributed, then the preAdaptGrid is data_[0]. Otherwise, preApaptGrid is current_view_data_. // Max level before calling adapt. - const int& preAdaptMaxLevel = this->maxLevel(); - + const int& preAdaptMaxLevel = this->maxLevel(); + // Step 1. Add the LGR faces, for each LGR for (int elem = 0; elem < current_view_data_->size(0); ++elem) { if (markedElem_to_itsLgr[elem]!=nullptr) { @@ -3520,7 +3520,7 @@ void CpGrid::populateLeafGridCorners(Dune::cpgrid::EntityVariableBase>& adaptedCorner_to_elemLgrAndElemLgrCorner) const { // If the (level zero) grid has been distributed, then the preAdaptGrid is data_[0]. Otherwise, preApaptGrid is current_view_data_. - + adapted_corners.resize(corner_count); for (int corner = 0; corner < corner_count; ++corner) { const auto& [elemLgr, elemLgrCorner] = adaptedCorner_to_elemLgrAndElemLgrCorner.at(corner); @@ -3561,7 +3561,7 @@ void CpGrid::populateLeafGridFaces(Dune::cpgrid::EntityVariableBase,int>& markedElemAndEquivRefinedCorn_to_corner, const std::vector>>& cornerInMarkedElemWithEquivRefinedCorner, const std::vector>& cells_per_dim_vec) const -{ +{ // --- Refined cells --- for (std::size_t shiftedLevel = 0; shiftedLevel < refined_cell_count_vec.size(); ++shiftedLevel) { @@ -4137,7 +4137,7 @@ void CpGrid::updateCornerHistoryLevels(const std::vectorcorner_history_[refinedCorner] = preAdaptGrid_corner_history.empty() ? std::array{{0, static_cast(corner)}} : preAdaptGrid_corner_history[corner]; } } - + // corner_history_ leaf grid view for ( int leafCorner = 0; leafCorner < corner_count; ++leafCorner){ currentData().back()->corner_history_.resize(corner_count); @@ -4664,5 +4664,3 @@ int CpGrid::replaceLgr1FaceIdxByLgr2FaceIdx(const std::array& cells_per_d } } // namespace Dune - - diff --git a/opm/grid/cpgrid/Entity.hpp b/opm/grid/cpgrid/Entity.hpp index 169d5c5e6..26d0e44eb 100644 --- a/opm/grid/cpgrid/Entity.hpp +++ b/opm/grid/cpgrid/Entity.hpp @@ -162,7 +162,7 @@ class Entity : public EntityRep } /// @brief Return the geometry of the entity (does not depend on its orientation). - const Geometry& geometry() const; + Geometry geometry() const; /// @brief Return the level of the entity in the grid hierarchy. Level = 0 represents the coarsest grid. int level() const; @@ -387,7 +387,7 @@ unsigned int Entity::subEntities ( const unsigned int cc ) const } template -const typename Entity::Geometry& Entity::geometry() const +typename Entity::Geometry Entity::geometry() const { return pgrid_->geomVector()[*this]; } diff --git a/opm/grid/cpgrid/Geometry.hpp b/opm/grid/cpgrid/Geometry.hpp index ed21cbca1..90430d974 100644 --- a/opm/grid/cpgrid/Geometry.hpp +++ b/opm/grid/cpgrid/Geometry.hpp @@ -127,7 +127,7 @@ namespace Dune } /// Returns the position of the vertex. - const GlobalCoordinate& global(const LocalCoordinate&) const + GlobalCoordinate global(const LocalCoordinate&) const { return pos_; } @@ -172,7 +172,7 @@ namespace Dune } /// Returns the centroid of the geometry. - const GlobalCoordinate& center() const + GlobalCoordinate center() const { return pos_; } @@ -272,7 +272,7 @@ namespace Dune } /// This method is meaningless for singular geometries. - const GlobalCoordinate& global(const LocalCoordinate&) const + GlobalCoordinate global(const LocalCoordinate&) const { OPM_THROW(std::runtime_error, "Geometry::global() meaningless on singular geometry."); } @@ -319,20 +319,20 @@ namespace Dune } /// Returns the centroid of the geometry. - const GlobalCoordinate& center() const + GlobalCoordinate center() const { return pos_; } /// This method is meaningless for singular geometries. - const FieldMatrix& + FieldMatrix jacobianTransposed(const LocalCoordinate& /* local */) const { OPM_THROW(std::runtime_error, "Meaningless to call jacobianTransposed() on singular geometries."); } /// This method is meaningless for singular geometries. - const FieldMatrix& + FieldMatrix jacobianInverseTransposed(const LocalCoordinate& /*local*/) const { OPM_THROW(std::runtime_error, "Meaningless to call jacobianInverseTransposed() on singular geometries."); @@ -526,7 +526,7 @@ namespace Dune } /// Returns the centroid of the geometry. - const GlobalCoordinate& center() const + GlobalCoordinate center() const { return pos_; } @@ -537,7 +537,7 @@ namespace Dune /// and {u_i} are the reference coordinates. /// g = g(u) = (g_1(u), g_2(u), g_3(u)), u=(u_1,u_2,u_3) /// g = map from (local) reference domain to global cell - const JacobianTransposed + JacobianTransposed jacobianTransposed(const LocalCoordinate& local_coord) const { static_assert(mydimension == 3, ""); @@ -573,7 +573,7 @@ namespace Dune } /// @brief Inverse of Jacobian transposed. \see jacobianTransposed(). - const JacobianInverseTransposed + JacobianInverseTransposed jacobianInverseTransposed(const LocalCoordinate& local_coord) const { JacobianInverseTransposed Jti = jacobianTransposed(local_coord); diff --git a/opm/grid/cpgrid/GridHelpers.cpp b/opm/grid/cpgrid/GridHelpers.cpp index 6f4f49559..a13fedbcf 100644 --- a/opm/grid/cpgrid/GridHelpers.cpp +++ b/opm/grid/cpgrid/GridHelpers.cpp @@ -141,9 +141,9 @@ beginFaceCentroids(const Dune::CpGrid& grid) return FaceCentroidTraits::IteratorType(grid, 0); } -const double* cellCentroid(const Dune::CpGrid& grid, int cell_index) +Vector cellCentroid(const Dune::CpGrid& grid, int cell_index) { - return &(grid.cellCentroid(cell_index)[0]); + return grid.cellCentroid(cell_index); } double cellVolume(const Dune::CpGrid& grid, int cell_index) @@ -161,8 +161,7 @@ CellVolumeIterator endCellVolumes(const Dune::CpGrid& grid) return CellVolumeIterator(grid, numCells(grid)); } -const FaceCentroidTraits::ValueType& -faceCentroid(const Dune::CpGrid& grid, int face_index) +Vector faceCentroid(const Dune::CpGrid& grid, int face_index) { return grid.faceCentroid(face_index); } @@ -184,14 +183,14 @@ face2Vertices(const Dune::CpGrid& grid) return Dune::cpgrid::FaceVerticesContainerProxy(&grid); } -const double* vertexCoordinates(const Dune::CpGrid& grid, int index) +Vector vertexCoordinates(const Dune::CpGrid& grid, int index) { - return &(grid.vertexPosition(index)[0]); + return grid.vertexPosition(index); } -const double* faceNormal(const Dune::CpGrid& grid, int face_index) +Vector faceNormal(const Dune::CpGrid& grid, int face_index) { - return &(grid.faceNormal(face_index)[0]); + return grid.faceNormal(face_index); } double faceArea(const Dune::CpGrid& grid, int face_index) diff --git a/opm/grid/cpgrid/GridHelpers.hpp b/opm/grid/cpgrid/GridHelpers.hpp index b910a06b8..fc33f7662 100644 --- a/opm/grid/cpgrid/GridHelpers.hpp +++ b/opm/grid/cpgrid/GridHelpers.hpp @@ -328,10 +328,10 @@ struct Cell2FacesTraits typedef Dune::cpgrid::Cell2FacesContainer Type; }; /// \brief An iterator over the cell volumes. -template& (Dune::CpGrid::*Method)(int)const> +template (Dune::CpGrid::*Method)(int)const> class CpGridCentroidIterator : public Dune::RandomAccessIteratorFacade, Dune::FieldVector, - const Dune::FieldVector&, int> + Dune::FieldVector, int> { public: /// \brief Creates an iterator. @@ -341,7 +341,7 @@ class CpGridCentroidIterator : grid_(&grid), cell_index_(cell_index) {} - const Dune::FieldVector& dereference() const + Dune::FieldVector dereference() const { return std::mem_fn(Method)(*grid_, cell_index_); } @@ -349,7 +349,7 @@ class CpGridCentroidIterator { ++cell_index_; } - const Dune::FieldVector& elementAt(int n) const + Dune::FieldVector elementAt(int n) const { return std::mem_fn(Method)(*grid_, n); } @@ -430,7 +430,7 @@ double cellCentroidCoordinate(const Dune::CpGrid& grid, int cell_index, /// \brief Get the centroid of a cell. /// \param grid The grid whose cell centroid we query. /// \param cell_index The index of the corresponding cell. -const double* cellCentroid(const Dune::CpGrid& grid, int cell_index); +Vector cellCentroid(const Dune::CpGrid& grid, int cell_index); /// \brief Get vertical position of cell center ("zcorn" average). /// \brief grid The grid. @@ -531,8 +531,7 @@ beginFaceCentroids(const Dune::CpGrid& grid); /// \param grid The grid. /// \param face_index The index of the specific face. /// \param coordinate The coordinate index. -const FaceCentroidTraits::ValueType& -faceCentroid(const Dune::CpGrid& grid, int face_index); +Vector faceCentroid(const Dune::CpGrid& grid, int face_index); template<> struct FaceCellTraits @@ -559,9 +558,9 @@ face2Vertices(const Dune::CpGrid& grid); /// \brief Get the coordinates of a vertex of the grid. /// \param grid The grid the vertex is part of. /// \param index The index identifying the vertex. -const double* vertexCoordinates(const Dune::CpGrid& grid, int index); +Vector vertexCoordinates(const Dune::CpGrid& grid, int index); -const double* faceNormal(const Dune::CpGrid& grid, int face_index); +Vector faceNormal(const Dune::CpGrid& grid, int face_index); double faceArea(const Dune::CpGrid& grid, int face_index); diff --git a/opm/grid/cpgrid/Intersection.hpp b/opm/grid/cpgrid/Intersection.hpp index e7d837608..3c7290cbe 100644 --- a/opm/grid/cpgrid/Intersection.hpp +++ b/opm/grid/cpgrid/Intersection.hpp @@ -161,7 +161,7 @@ namespace Dune /// @brief /// @todo Doc me! /// @return - const LocalGeometry& geometryInInside() const + LocalGeometry geometryInInside() const { OPM_THROW(std::runtime_error, "This intersection class does not support geometryInInside()."); } @@ -171,7 +171,7 @@ namespace Dune /// @brief /// @todo Doc me! /// @return - const LocalGeometry& geometryInOutside() const + LocalGeometry geometryInOutside() const { if (boundary()) { OPM_THROW(std::runtime_error, "Cannot access geometryInOutside(), intersection is at a boundary."); diff --git a/opm/grid/transmissibility/TransTpfa_impl.hpp b/opm/grid/transmissibility/TransTpfa_impl.hpp index 9b4f4b9c3..c2cc1f9cb 100644 --- a/opm/grid/transmissibility/TransTpfa_impl.hpp +++ b/opm/grid/transmissibility/TransTpfa_impl.hpp @@ -87,7 +87,7 @@ tpfa_htrans_compute(const Grid* G, const double *perm, double *htrans) s = 2.0*(face_cells(*f, 0) == c) - 1.0; n = faceNormal(*G, *f); const double* nn=multiplyFaceNormalWithArea(*G, *f, n); - const double* fc = &(faceCentroid(*G, *f)[0]); + const auto fc = faceCentroid(*G, *f); dgemv_("No Transpose", &nrows, &ncols, &a1, K, &ldA, nn, &incx, &a2, &Kn[0], &incy); maybeFreeFaceNormal(*G, nn);