Skip to content

Commit b8b09d2

Browse files
committed
Return geometry objects by value
This is to conform with the dune interface
1 parent 7733954 commit b8b09d2

File tree

7 files changed

+54
-58
lines changed

7 files changed

+54
-58
lines changed

opm/grid/CpGrid.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ namespace Dune
334334
/// Set whether we want to have unique boundary ids.
335335
/// \param uids if true, each boundary intersection will have a unique boundary id.
336336
void setUniqueBoundaryIds(bool uids);
337-
337+
338338

339339
// --- Dune interface below ---
340340

@@ -345,7 +345,7 @@ namespace Dune
345345
/// It's the same as the class name.
346346
/// What did you expect, something funny?
347347
std::string name() const;
348-
348+
349349
/// Return maximum level defined in this grid. Levels are 0 and 1, maxlevel = 1 (not counting leafview), 0 = the coarsest level.
350350
int maxLevel() const;
351351

@@ -355,7 +355,7 @@ namespace Dune
355355
/// one past the end on this level
356356
template<int codim>
357357
typename Traits::template Codim<codim>::LevelIterator lend (int level) const;
358-
358+
359359
/// Iterator to first entity of given codim on level and PartitionIteratorType
360360
template<int codim, PartitionIteratorType PiType>
361361
typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lbegin (int level) const;
@@ -394,7 +394,7 @@ namespace Dune
394394

395395
/// \brief Access to the LocalIdSet
396396
const Traits::LocalIdSet& localIdSet() const;
397-
397+
398398
/// \brief Access to the LevelIndexSets
399399
const Traits::LevelIndexSet& levelIndexSet(int level) const;
400400

@@ -626,10 +626,10 @@ namespace Dune
626626
const int& cell_count) const;
627627

628628
/// @brief Define refined level grid cells indices and leaf grid view (or adapted grid) cells indices relations. Namely, level_to_leaf_cells_ for each new
629-
/// refined level grid, and leaf_to_level_cells_ for the updated leaf grid view.
629+
/// refined level grid, and leaf_to_level_cells_ for the updated leaf grid view.
630630
///
631631
/// @param [in] elemLgrAndElemLgrCell_to_refinedLevelAdRefinedCell: Each marked element has been refined in its "own elemLgr". Refined entities should be stored in
632-
/// the corresponding assigned refined level grid. To keep track of the cell index relation, we
632+
/// the corresponding assigned refined level grid. To keep track of the cell index relation, we
633633
/// associate each
634634
/// { marked element index ("elemLgr"), refined cell index in the auxiliary single-cell-refinement } with
635635
/// { refined level grid assigned for the marked element, refined cell index in refined level grid }.
@@ -761,7 +761,7 @@ namespace Dune
761761
/// @param [out] adaptedFace_to_elemLgrAndElemLgrFace: Each marked element has been refined in its "own elemLgr". Refined corners should be stored in
762762
/// the corresponding assigned refined level grid. To keep track of the face index relation, we associate each
763763
/// face index in the leaf grid view (or adapted grid) with
764-
/// { marked element index ("elemLgr"), refined corner index in the auxiliary single-cell-refinement }.
764+
/// { marked element index ("elemLgr"), refined corner index in the auxiliary single-cell-refinement }.
765765
/// @param [out] face_count: Total amount of faces on the leaf grid view (or adapted grid).
766766
/// @param [in] markedElem_to_itsLgr
767767
/// @param [in] assignRefinedLevel
@@ -1087,7 +1087,7 @@ namespace Dune
10871087
int getParentFaceWhereNewRefinedFaceLiesOn(const std::array<int,3>& cells_per_dim, int faceIdxInLgr,
10881088
const std::shared_ptr<cpgrid::CpGridData>& elemLgr_ptr,
10891089
int elemLgr) const;
1090-
1090+
10911091
/// --------------- Auxiliary methods to support Adaptivity (end) ---------------
10921092

10931093
/// @brief Check if there are non neighboring connections on blocks of cells selected for refinement.
@@ -1712,7 +1712,7 @@ namespace Dune
17121712
/// cell due the face being part of the grid boundary or the
17131713
/// cell being stored on another process.
17141714
int faceCell(int face, int local_index, int level = -1) const;
1715-
1715+
17161716
/// \brief Get the sum of all faces attached to all cells.
17171717
///
17181718
/// Each face identified by a unique index is counted as often
@@ -1743,28 +1743,28 @@ namespace Dune
17431743
/// \brief Get the Position of a vertex.
17441744
/// \param cell The index identifying the cell.
17451745
/// \return The coordinates of the vertex.
1746-
const Vector& vertexPosition(int vertex) const;
1746+
Vector vertexPosition(int vertex) const;
17471747

17481748
/// \brief Get the area of a face.
17491749
/// \param cell The index identifying the face.
17501750
double faceArea(int face) const;
17511751

17521752
/// \brief Get the coordinates of the center of a face.
17531753
/// \param cell The index identifying the face.
1754-
const Vector& faceCentroid(int face) const;
1754+
Vector faceCentroid(int face) const;
17551755

17561756
/// \brief Get the unit normal of a face.
17571757
/// \param cell The index identifying the face.
17581758
/// \see faceCell
1759-
const Vector& faceNormal(int face) const;
1759+
Vector faceNormal(int face) const;
17601760

17611761
/// \brief Get the volume of the cell.
17621762
/// \param cell The index identifying the cell.
17631763
double cellVolume(int cell) const;
17641764

17651765
/// \brief Get the coordinates of the center of a cell.
17661766
/// \param cell The index identifying the face.
1767-
const Vector& cellCentroid(int cell) const;
1767+
Vector cellCentroid(int cell) const;
17681768

17691769
/// \brief An iterator over the centroids of the geometry of the entities.
17701770
/// \tparam codim The co-dimension of the entities.

opm/grid/cpgrid/CpGrid.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,7 @@ const Dune::FieldVector<double,3> CpGrid::faceAreaNormalEcl(int face) const
17611761
}
17621762
}
17631763

1764-
const Dune::FieldVector<double,3>& CpGrid::vertexPosition(int vertex) const
1764+
Dune::FieldVector<double,3> CpGrid::vertexPosition(int vertex) const
17651765
{
17661766
return current_view_data_->geomVector<3>()[cpgrid::EntityRep<3>(vertex, true)].center();
17671767
}
@@ -1771,12 +1771,12 @@ double CpGrid::faceArea(int face) const
17711771
return current_view_data_->geomVector<1>()[cpgrid::EntityRep<1>(face, true)].volume();
17721772
}
17731773

1774-
const Dune::FieldVector<double,3>& CpGrid::faceCentroid(int face) const
1774+
Dune::FieldVector<double,3> CpGrid::faceCentroid(int face) const
17751775
{
17761776
return current_view_data_->geomVector<1>()[cpgrid::EntityRep<1>(face, true)].center();
17771777
}
17781778

1779-
const Dune::FieldVector<double,3>& CpGrid::faceNormal(int face) const
1779+
Dune::FieldVector<double,3> CpGrid::faceNormal(int face) const
17801780
{
17811781
return current_view_data_->face_normals_.get(face);
17821782
}
@@ -1786,7 +1786,7 @@ double CpGrid::cellVolume(int cell) const
17861786
return current_view_data_->geomVector<0>()[cpgrid::EntityRep<0>(cell, true)].volume();
17871787
}
17881788

1789-
const Dune::FieldVector<double,3>& CpGrid::cellCentroid(int cell) const
1789+
Dune::FieldVector<double,3> CpGrid::cellCentroid(int cell) const
17901790
{
17911791
return current_view_data_->geomVector<0>()[cpgrid::EntityRep<0>(cell, true)].center();
17921792
}
@@ -2863,10 +2863,10 @@ void CpGrid::refineAndProvideMarkedRefinedRelations( /* Marked elements paramete
28632863
int& cell_count,
28642864
std::vector<std::vector<int>>& preAdapt_level_to_leaf_cells_vec,
28652865
/* Additional parameters */
2866-
const std::vector<std::array<int,3>>& cells_per_dim_vec) const
2866+
const std::vector<std::array<int,3>>& cells_per_dim_vec) const
28672867
{
28682868
// If the (level zero) grid has been distributed, then the preAdaptGrid is data_[0]. Otherwise, preApaptGrid is current_view_data_.
2869-
2869+
28702870
// Each marked element for refinement (mark equal to 1), will be refined individuality, creating its own Lgr. The element index will
28712871
// be also used to identify its lgr. Even though, in the end, all the refined entities will belong to a unique level grid.
28722872
// For this reason, we associate "-1" with those elements that are not involved in any refinement and will appear
@@ -2884,7 +2884,7 @@ void CpGrid::refineAndProvideMarkedRefinedRelations( /* Marked elements paramete
28842884
cell_count +=1;
28852885
preAdapt_level_to_leaf_cells_vec[element.level()][element.getLevelElem().index()] = cell_count;
28862886
}
2887-
2887+
28882888
// When the element is marked for refinement, we also mark its corners and faces
28892889
// since they will get replaced by refined ones.
28902890
if (getMark(element) == 1) {
@@ -2920,7 +2920,7 @@ void CpGrid::refineAndProvideMarkedRefinedRelations( /* Marked elements paramete
29202920
refined_cell_count_vec[shiftedLevel] +=1;
29212921

29222922
}
2923-
2923+
29242924
preAdapt_parent_to_children_cells_vec[element.level()][element.getLevelElem().index()] = std::make_pair( markedElemLevel, refinedChildrenList);
29252925
for (const auto& [markedCorner, lgrEquivCorner] : parentCorners_to_equivalentRefinedCorners) {
29262926
cornerInMarkedElemWithEquivRefinedCorner[markedCorner].push_back({elemIdx, lgrEquivCorner});
@@ -2940,7 +2940,7 @@ CpGrid::defineChildToParentAndIdxInParentCell(const std::map<std::array<int,2>,s
29402940
const int& cell_count) const
29412941
{
29422942
// If the (level zero) grid has been distributed, then the preAdaptGrid is data_[0]. Otherwise, preApaptGrid is current_view_data_.
2943-
2943+
29442944
// ------------------------ Refined grid parameters
29452945
// Refined child cells and their parents. Entry is {-1,-1} when cell has no father. Otherwise, {level parent cell, parent cell index}
29462946
// Each entry represents a refined level.
@@ -3310,7 +3310,7 @@ void CpGrid::identifyLeafGridCorners(std::map<std::array<int,2>,int>& elemLgrAnd
33103310
const std::vector<std::array<int,3>>& cells_per_dim_vec) const
33113311
{
33123312
// If the (level zero) grid has been distributed, then the preAdaptGrid is data_[0]. Otherwise, preApaptGrid is current_view_data_.
3313-
3313+
33143314
// Step 1. Select/store the corners from the starting grid not involved in any (new) LGR.
33153315
// Replace the corners from level zero involved in LGR by the equivalent ones, born in LGRs.
33163316
// In this case, we avoid repetition considering the last appearance of the level zero corner
@@ -3464,8 +3464,8 @@ void CpGrid::identifyLeafGridFaces(std::map<std::array<int,2>,int>& elemLgrAndEl
34643464
// If the (level zero) grid has been distributed, then the preAdaptGrid is data_[0]. Otherwise, preApaptGrid is current_view_data_.
34653465

34663466
// Max level before calling adapt.
3467-
const int& preAdaptMaxLevel = this->maxLevel();
3468-
3467+
const int& preAdaptMaxLevel = this->maxLevel();
3468+
34693469
// Step 1. Add the LGR faces, for each LGR
34703470
for (int elem = 0; elem < current_view_data_->size(0); ++elem) {
34713471
if (markedElem_to_itsLgr[elem]!=nullptr) {
@@ -3526,7 +3526,7 @@ void CpGrid::populateLeafGridCorners(Dune::cpgrid::EntityVariableBase<cpgrid::Ge
35263526
const std::unordered_map<int,std::array<int,2>>& adaptedCorner_to_elemLgrAndElemLgrCorner) const
35273527
{
35283528
// If the (level zero) grid has been distributed, then the preAdaptGrid is data_[0]. Otherwise, preApaptGrid is current_view_data_.
3529-
3529+
35303530
adapted_corners.resize(corner_count);
35313531
for (int corner = 0; corner < corner_count; ++corner) {
35323532
const auto& [elemLgr, elemLgrCorner] = adaptedCorner_to_elemLgrAndElemLgrCorner.at(corner);
@@ -3567,7 +3567,7 @@ void CpGrid::populateLeafGridFaces(Dune::cpgrid::EntityVariableBase<cpgrid::Geom
35673567
const int& preAdaptMaxLevel) const
35683568
{
35693569
// If the (level zero) grid has been distributed, then the preAdaptGrid is data_[0]. Otherwise, preApaptGrid is current_view_data_.
3570-
3570+
35713571
adapted_faces.resize(face_count);
35723572
mutable_face_tags.resize(face_count);
35733573
mutable_face_normals.resize(face_count);
@@ -3747,7 +3747,7 @@ void CpGrid::populateLeafGridCells(Dune::cpgrid::EntityVariableBase<cpgrid::Geom
37473747
const int& preAdaptMaxLevel) const
37483748
{
37493749
// If the (level zero) grid has been distributed, then the preAdaptGrid is data_[0]. Otherwise, preApaptGrid is current_view_data_.
3750-
3750+
37513751
// --- Adapted cells ---
37523752
// Store the adapted cells. Main difficulty: to lookup correctly the indices of the corners and faces of each cell.
37533753
adapted_cells.resize(cell_count);
@@ -3877,7 +3877,7 @@ void CpGrid::populateRefinedCells(std::vector<Dune::cpgrid::EntityVariableBase<c
38773877
const std::map<std::array<int,2>,int>& markedElemAndEquivRefinedCorn_to_corner,
38783878
const std::vector<std::vector<std::array<int,2>>>& cornerInMarkedElemWithEquivRefinedCorner,
38793879
const std::vector<std::array<int,3>>& cells_per_dim_vec) const
3880-
{
3880+
{
38813881
// --- Refined cells ---
38823882
for (std::size_t shiftedLevel = 0; shiftedLevel < refined_cell_count_vec.size(); ++shiftedLevel) {
38833883

@@ -4143,7 +4143,7 @@ void CpGrid::updateCornerHistoryLevels(const std::vector<std::vector<std::array<
41434143
currentData()[refinedLevel]->corner_history_[refinedCorner] = preAdaptGrid_corner_history.empty() ? std::array<int,2>{{0, static_cast<int>(corner)}} : preAdaptGrid_corner_history[corner];
41444144
}
41454145
}
4146-
4146+
41474147
// corner_history_ leaf grid view
41484148
for ( int leafCorner = 0; leafCorner < corner_count; ++leafCorner){
41494149
currentData().back()->corner_history_.resize(corner_count);
@@ -4670,5 +4670,3 @@ int CpGrid::replaceLgr1FaceIdxByLgr2FaceIdx(const std::array<int,3>& cells_per_d
46704670
}
46714671

46724672
} // namespace Dune
4673-
4674-

opm/grid/cpgrid/Entity.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class Entity : public EntityRep<codim>
163163
}
164164

165165
/// @brief Return the geometry of the entity (does not depend on its orientation).
166-
const Geometry& geometry() const;
166+
Geometry geometry() const;
167167

168168
/// @brief Return the level of the entity in the grid hierarchy. Level = 0 represents the coarsest grid.
169169
int level() const;
@@ -382,7 +382,7 @@ unsigned int Entity<codim>::subEntities ( const unsigned int cc ) const
382382
}
383383

384384
template <int codim>
385-
const typename Entity<codim>::Geometry& Entity<codim>::geometry() const
385+
typename Entity<codim>::Geometry Entity<codim>::geometry() const
386386
{
387387
return pgrid_->geomVector<codim>()[*this];
388388
}

opm/grid/cpgrid/Geometry.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ namespace Dune
127127
}
128128

129129
/// Returns the position of the vertex.
130-
const GlobalCoordinate& global(const LocalCoordinate&) const
130+
GlobalCoordinate global(const LocalCoordinate&) const
131131
{
132132
return pos_;
133133
}
@@ -172,7 +172,7 @@ namespace Dune
172172
}
173173

174174
/// Returns the centroid of the geometry.
175-
const GlobalCoordinate& center() const
175+
GlobalCoordinate center() const
176176
{
177177
return pos_;
178178
}
@@ -272,7 +272,7 @@ namespace Dune
272272
}
273273

274274
/// This method is meaningless for singular geometries.
275-
const GlobalCoordinate& global(const LocalCoordinate&) const
275+
GlobalCoordinate global(const LocalCoordinate&) const
276276
{
277277
OPM_THROW(std::runtime_error, "Geometry::global() meaningless on singular geometry.");
278278
}
@@ -319,20 +319,20 @@ namespace Dune
319319
}
320320

321321
/// Returns the centroid of the geometry.
322-
const GlobalCoordinate& center() const
322+
GlobalCoordinate center() const
323323
{
324324
return pos_;
325325
}
326326

327327
/// This method is meaningless for singular geometries.
328-
const FieldMatrix<ctype, mydimension, coorddimension>&
328+
FieldMatrix<ctype, mydimension, coorddimension>
329329
jacobianTransposed(const LocalCoordinate& /* local */) const
330330
{
331331
OPM_THROW(std::runtime_error, "Meaningless to call jacobianTransposed() on singular geometries.");
332332
}
333333

334334
/// This method is meaningless for singular geometries.
335-
const FieldMatrix<ctype, coorddimension, mydimension>&
335+
FieldMatrix<ctype, coorddimension, mydimension>
336336
jacobianInverseTransposed(const LocalCoordinate& /*local*/) const
337337
{
338338
OPM_THROW(std::runtime_error, "Meaningless to call jacobianInverseTransposed() on singular geometries.");
@@ -526,7 +526,7 @@ namespace Dune
526526
}
527527

528528
/// Returns the centroid of the geometry.
529-
const GlobalCoordinate& center() const
529+
GlobalCoordinate center() const
530530
{
531531
return pos_;
532532
}
@@ -537,7 +537,7 @@ namespace Dune
537537
/// and {u_i} are the reference coordinates.
538538
/// g = g(u) = (g_1(u), g_2(u), g_3(u)), u=(u_1,u_2,u_3)
539539
/// g = map from (local) reference domain to global cell
540-
const JacobianTransposed
540+
JacobianTransposed
541541
jacobianTransposed(const LocalCoordinate& local_coord) const
542542
{
543543
static_assert(mydimension == 3, "");
@@ -573,7 +573,7 @@ namespace Dune
573573
}
574574

575575
/// @brief Inverse of Jacobian transposed. \see jacobianTransposed().
576-
const JacobianInverseTransposed
576+
JacobianInverseTransposed
577577
jacobianInverseTransposed(const LocalCoordinate& local_coord) const
578578
{
579579
JacobianInverseTransposed Jti = jacobianTransposed(local_coord);

opm/grid/cpgrid/GridHelpers.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ CellVolumeIterator endCellVolumes(const Dune::CpGrid& grid)
161161
return CellVolumeIterator(grid, numCells(grid));
162162
}
163163

164-
const FaceCentroidTraits<Dune::CpGrid>::ValueType&
165-
faceCentroid(const Dune::CpGrid& grid, int face_index)
164+
Vector faceCentroid(const Dune::CpGrid& grid, int face_index)
166165
{
167166
return grid.faceCentroid(face_index);
168167
}
@@ -184,14 +183,14 @@ face2Vertices(const Dune::CpGrid& grid)
184183
return Dune::cpgrid::FaceVerticesContainerProxy(&grid);
185184
}
186185

187-
const double* vertexCoordinates(const Dune::CpGrid& grid, int index)
186+
Vector vertexCoordinates(const Dune::CpGrid& grid, int index)
188187
{
189-
return &(grid.vertexPosition(index)[0]);
188+
return grid.vertexPosition(index);
190189
}
191190

192-
const double* faceNormal(const Dune::CpGrid& grid, int face_index)
191+
Vector faceNormal(const Dune::CpGrid& grid, int face_index)
193192
{
194-
return &(grid.faceNormal(face_index)[0]);
193+
return grid.faceNormal(face_index);
195194
}
196195

197196
double faceArea(const Dune::CpGrid& grid, int face_index)

0 commit comments

Comments
 (0)