Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions opm/grid/CpGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ namespace Dune
/// Set whether we want to have unique boundary ids.
/// \param uids if true, each boundary intersection will have a unique boundary id.
void setUniqueBoundaryIds(bool uids);


// --- Dune interface below ---

Expand All @@ -345,7 +345,7 @@ namespace Dune
/// It's the same as the class name.
/// What did you expect, something funny?
std::string name() const;

/// Return maximum level defined in this grid. Levels are 0 and 1, maxlevel = 1 (not counting leafview), 0 = the coarsest level.
int maxLevel() const;

Expand All @@ -355,7 +355,7 @@ namespace Dune
/// one past the end on this level
template<int codim>
typename Traits::template Codim<codim>::LevelIterator lend (int level) const;

/// Iterator to first entity of given codim on level and PartitionIteratorType
template<int codim, PartitionIteratorType PiType>
typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lbegin (int level) const;
Expand Down Expand Up @@ -394,7 +394,7 @@ namespace Dune

/// \brief Access to the LocalIdSet
const Traits::LocalIdSet& localIdSet() const;

/// \brief Access to the LevelIndexSets
const Traits::LevelIndexSet& levelIndexSet(int level) const;

Expand Down Expand Up @@ -626,10 +626,10 @@ namespace Dune
const int& cell_count) const;

/// @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
/// refined level grid, and leaf_to_level_cells_ for the updated leaf grid view.
/// refined level grid, and leaf_to_level_cells_ for the updated leaf grid view.
///
/// @param [in] elemLgrAndElemLgrCell_to_refinedLevelAdRefinedCell: Each marked element has been refined in its "own elemLgr". Refined entities should be stored in
/// the corresponding assigned refined level grid. To keep track of the cell index relation, we
/// the corresponding assigned refined level grid. To keep track of the cell index relation, we
/// associate each
/// { marked element index ("elemLgr"), refined cell index in the auxiliary single-cell-refinement } with
/// { refined level grid assigned for the marked element, refined cell index in refined level grid }.
Expand Down Expand Up @@ -761,7 +761,7 @@ namespace Dune
/// @param [out] adaptedFace_to_elemLgrAndElemLgrFace: Each marked element has been refined in its "own elemLgr". Refined corners should be stored in
/// the corresponding assigned refined level grid. To keep track of the face index relation, we associate each
/// face index in the leaf grid view (or adapted grid) with
/// { marked element index ("elemLgr"), refined corner index in the auxiliary single-cell-refinement }.
/// { marked element index ("elemLgr"), refined corner index in the auxiliary single-cell-refinement }.
/// @param [out] face_count: Total amount of faces on the leaf grid view (or adapted grid).
/// @param [in] markedElem_to_itsLgr
/// @param [in] assignRefinedLevel
Expand Down Expand Up @@ -814,7 +814,8 @@ namespace Dune
const int& preAdaptMaxLevel,
const std::map<std::array<int,2>,int>& markedElemAndEquivRefinedCorn_to_corner,
const std::vector<std::vector<std::array<int,2>>>& cornerInMarkedElemWithEquivRefinedCorner,
const std::vector<std::array<int,3>>& cells_per_dim_vec) const;
const std::vector<std::array<int,3>>& cells_per_dim_vec,
const std::vector<Dune::cpgrid::EntityVariableBase<cpgrid::Geometry<0,3>>>& refined_corners_vec) const;

/// @brief Set geometrical and topological attributes for each refined level grid.
void setRefinedLevelGridsGeometries( /* Refined corner arguments */
Expand Down Expand Up @@ -1087,7 +1088,7 @@ namespace Dune
int getParentFaceWhereNewRefinedFaceLiesOn(const std::array<int,3>& cells_per_dim, int faceIdxInLgr,
const std::shared_ptr<cpgrid::CpGridData>& elemLgr_ptr,
int elemLgr) const;

/// --------------- Auxiliary methods to support Adaptivity (end) ---------------

/// @brief Check if there are non neighboring connections on blocks of cells selected for refinement.
Expand Down Expand Up @@ -1712,7 +1713,7 @@ namespace Dune
/// cell due the face being part of the grid boundary or the
/// cell being stored on another process.
int faceCell(int face, int local_index, int level = -1) const;

/// \brief Get the sum of all faces attached to all cells.
///
/// Each face identified by a unique index is counted as often
Expand Down Expand Up @@ -1743,28 +1744,28 @@ 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.
double faceArea(int face) const;

/// \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.
double cellVolume(int cell) const;

/// \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.
Expand Down
50 changes: 26 additions & 24 deletions opm/grid/cpgrid/CpGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,7 @@ const Dune::FieldVector<double,3> CpGrid::faceAreaNormalEcl(int face) const
}
}

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

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

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

const Dune::FieldVector<double,3>& CpGrid::cellCentroid(int cell) const
Dune::FieldVector<double,3> CpGrid::cellCentroid(int cell) const
{
return current_view_data_->geomVector<0>()[cpgrid::EntityRep<0>(cell, true)].center();
}
Expand Down Expand Up @@ -2863,10 +2863,10 @@ void CpGrid::refineAndProvideMarkedRefinedRelations( /* Marked elements paramete
int& cell_count,
std::vector<std::vector<int>>& preAdapt_level_to_leaf_cells_vec,
/* Additional parameters */
const std::vector<std::array<int,3>>& cells_per_dim_vec) const
const std::vector<std::array<int,3>>& 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
Expand All @@ -2884,7 +2884,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) {
Expand Down Expand Up @@ -2920,7 +2920,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});
Expand All @@ -2940,7 +2940,7 @@ CpGrid::defineChildToParentAndIdxInParentCell(const std::map<std::array<int,2>,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.
Expand Down Expand Up @@ -3310,7 +3310,7 @@ void CpGrid::identifyLeafGridCorners(std::map<std::array<int,2>,int>& elemLgrAnd
const std::vector<std::array<int,3>>& 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
Expand Down Expand Up @@ -3464,8 +3464,8 @@ void CpGrid::identifyLeafGridFaces(std::map<std::array<int,2>,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) {
Expand Down Expand Up @@ -3526,7 +3526,7 @@ void CpGrid::populateLeafGridCorners(Dune::cpgrid::EntityVariableBase<cpgrid::Ge
const std::unordered_map<int,std::array<int,2>>& 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);
Expand Down Expand Up @@ -3567,7 +3567,7 @@ void CpGrid::populateLeafGridFaces(Dune::cpgrid::EntityVariableBase<cpgrid::Geom
const int& preAdaptMaxLevel) const
{
// If the (level zero) grid has been distributed, then the preAdaptGrid is data_[0]. Otherwise, preApaptGrid is current_view_data_.

adapted_faces.resize(face_count);
mutable_face_tags.resize(face_count);
mutable_face_normals.resize(face_count);
Expand Down Expand Up @@ -3747,7 +3747,7 @@ void CpGrid::populateLeafGridCells(Dune::cpgrid::EntityVariableBase<cpgrid::Geom
const int& preAdaptMaxLevel) const
{
// If the (level zero) grid has been distributed, then the preAdaptGrid is data_[0]. Otherwise, preApaptGrid is current_view_data_.

// --- Adapted cells ---
// Store the adapted cells. Main difficulty: to lookup correctly the indices of the corners and faces of each cell.
adapted_cells.resize(cell_count);
Expand Down Expand Up @@ -3851,7 +3851,7 @@ void CpGrid::populateLeafGridCells(Dune::cpgrid::EntityVariableBase<cpgrid::Geom

// Create a pointer to the first element of "adapted_cell_to_point" (required as the fourth argement to construct a Geometry<3,3> type object).
int* indices_storage_ptr = adapted_cell_to_point[cell].data();
adapted_cells[cell] = cpgrid::Geometry<3,3>(cellGeom.center(), cellGeom.volume(), allCorners, indices_storage_ptr);
adapted_cells[cell] = cpgrid::Geometry<3,3>(cellGeom.center(), cellGeom.volume(), allCorners.get(), indices_storage_ptr);
} // adapted_cells

// Adapted/Leaf-grid-view face to cell.
Expand All @@ -3876,16 +3876,19 @@ void CpGrid::populateRefinedCells(std::vector<Dune::cpgrid::EntityVariableBase<c
const int& preAdaptMaxLevel,
const std::map<std::array<int,2>,int>& markedElemAndEquivRefinedCorn_to_corner,
const std::vector<std::vector<std::array<int,2>>>& cornerInMarkedElemWithEquivRefinedCorner,
const std::vector<std::array<int,3>>& cells_per_dim_vec) const
{
const std::vector<std::array<int,3>>& cells_per_dim_vec,
const std::vector<Dune::cpgrid::EntityVariableBase<cpgrid::Geometry<0,3>>>& refined_corners_vec) const
{
// --- Refined cells ---
for (std::size_t shiftedLevel = 0; shiftedLevel < refined_cell_count_vec.size(); ++shiftedLevel) {

refined_cells_vec[shiftedLevel].resize(refined_cell_count_vec[shiftedLevel]);
refined_cell_to_point_vec[shiftedLevel].resize(refined_cell_count_vec[shiftedLevel]);
refined_global_cell_vec[shiftedLevel].resize(refined_cell_count_vec[shiftedLevel]);

const auto& allLevelCorners = refined_geometries_vec[shiftedLevel].geomVector(std::integral_constant<int,3>());
auto copyCorners = refined_corners_vec[shiftedLevel];
auto allLevelCorners = *refined_geometries_vec[shiftedLevel].geomVector(std::integral_constant<int,3>());
allLevelCorners.swap(copyCorners);

for (int cell = 0; cell < refined_cell_count_vec[shiftedLevel]; ++cell) {

Expand Down Expand Up @@ -3972,7 +3975,7 @@ void CpGrid::populateRefinedCells(std::vector<Dune::cpgrid::EntityVariableBase<c

// Create a pointer to the first element of "refined_cell_to_point" (required as the fourth argement to construct a Geometry<3,3> type object).
int* indices_storage_ptr = refined_cell_to_point_vec[shiftedLevel][cell].data();
refined_cells_vec[shiftedLevel][cell] = cpgrid::Geometry<3,3>(elemLgrGeom.center(), elemLgrGeom.volume(), allLevelCorners, indices_storage_ptr);
refined_cells_vec[shiftedLevel][cell] = cpgrid::Geometry<3,3>(elemLgrGeom.center(), elemLgrGeom.volume(), &allLevelCorners, indices_storage_ptr);
} // refined_cells
// Refined face to cell.
refined_cell_to_face_vec[shiftedLevel].makeInverseRelation(refined_face_to_cell_vec[shiftedLevel]);
Expand Down Expand Up @@ -4048,7 +4051,8 @@ void CpGrid::setRefinedLevelGridsGeometries( /* Refined corner arguments */
preAdaptMaxLevel,
markedElemAndEquivRefinedCorn_to_corner,
cornerInMarkedElemWithEquivRefinedCorner,
cells_per_dim_vec);
cells_per_dim_vec,
refined_corners_vec);

}

Expand Down Expand Up @@ -4143,7 +4147,7 @@ void CpGrid::updateCornerHistoryLevels(const std::vector<std::vector<std::array<
currentData()[refinedLevel]->corner_history_[refinedCorner] = preAdaptGrid_corner_history.empty() ? std::array<int,2>{{0, static_cast<int>(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);
Expand Down Expand Up @@ -4670,5 +4674,3 @@ int CpGrid::replaceLgr1FaceIdxByLgr2FaceIdx(const std::array<int,3>& cells_per_d
}

} // namespace Dune


Loading