Skip to content
Merged
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
15 changes: 8 additions & 7 deletions opm/grid/cpgrid/CpGridData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ struct Cell2PointsDataHandle
const auto& points = globalCell2Points_[i];
std::ranges::for_each(points,
[&buffer, this](const int& point)
{ buffer.write(globalIds_.id(EntityRep<3>(point, true))); });
{ buffer.write(globalIds_.idLevelZero(EntityRep<3>(point, true))); });
for (const auto& point: globalAdditionalPointIds_[i])
{
buffer.write(point);
Expand Down Expand Up @@ -707,7 +707,7 @@ struct SparseTableDataHandle
const auto& entries = global_[t.index()];
std::ranges::for_each(entries,
[&buffer, this](const DataType& i)
{ buffer.write(globalIds_.id(EntityRep<3>(i, true))); });
{ buffer.write(globalIds_.idLevelZero(EntityRep<3>(i, true))); });
}
template<class B, class T>
void scatter(B& buffer, const T& t, std::size_t )
Expand Down Expand Up @@ -779,7 +779,7 @@ struct OrientedEntityTableDataHandle
std::ranges::for_each(entries,
[&buffer, this](const ToEntity& i)
{
int id = globalIds_->id(i);
int id = globalIds_->idLevelZero(i);
if (!i.orientation()) {
id = ~id;
}
Expand Down Expand Up @@ -853,8 +853,9 @@ struct IndexSet2IdSet
for (const auto& entry: indexSet)
map_[entry.local()] = entry.global();
}
template<class T>
int id(const T& t) const

template<int dim>
int idLevelZero(const EntityRep<dim>& t) const
{
return map_[t.index()];
}
Expand Down Expand Up @@ -1371,7 +1372,7 @@ std::vector<std::set<int> > computeAdditionalFacePoints(const std::vector<std::a
const auto candidate = std::ranges::find(points, point);
if (candidate == points.end()) {
// point is not a corner of the cell
additionalFacePoints[c].insert(globalIds.id(EntityRep<3>(point,true)));
additionalFacePoints[c].insert(globalIds.idLevelZero(EntityRep<3>(point,true)));
}
}
}
Expand Down Expand Up @@ -1475,7 +1476,7 @@ std::map<int,int> computeCell2Point(const CpGrid& grid,
createInterfaceList<true>(procCellLists, globalCell2Points,
globalAdditionalPoints,
[&globalIds](int i){
return globalIds.id(EntityRep<3>(i, true));
return globalIds.idLevelZero(EntityRep<3>(i, true));
},
globalMap2Local,
pointInterfaces[procCellLists.first]);
Expand Down
43 changes: 37 additions & 6 deletions opm/grid/cpgrid/Entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,41 @@ namespace Dune
namespace cpgrid
{

template <int codim>
class Entity;

namespace Impl {
// Forward declaration of traits class for codimensions.
template <int codim>
struct CodimTraits;

// Specialization of traits class for codimension 0 (cells).
template<>
struct CodimTraits<0>
{
using Entity = ::Dune::cpgrid::Entity<0>;
};

#if DUNE_VERSION_LT(DUNE_GRID, 2, 11)
// Specialization of traits class for codimension 1 (faces).
// This is only needed for DUNE < 2.11, as the face entity type was needed for the VTK writer, which was fixed in DUNE 2.11.
// See: https://gitlab.dune-project.org/core/dune-grid/-/merge_requests/793
template<>
struct CodimTraits<1>
{
using Entity = ::Dune::cpgrid::Entity<1>;
};
#endif

// Specialization of traits class for codimension 3 (vertices).
template<>
struct CodimTraits<3>
{
using Entity = ::Dune::cpgrid::Entity<3>;
};

}

template<int,int> class Geometry;
template<int,PartitionIteratorType> class Iterator;
class IntersectionIterator;
Expand Down Expand Up @@ -93,11 +128,7 @@ class Entity : public EntityRep<codim>

/** \brief Export supported entity types */
template <int cd>
struct Codim
{
using Entity = ::Dune::cpgrid::Entity<cd>;
};

using Codim = typename Impl::CodimTraits<cd>;

typedef cpgrid::Geometry<3-codim,3> Geometry;
typedef Geometry LocalGeometry;
Expand Down Expand Up @@ -387,7 +418,7 @@ unsigned int Entity<codim>::subEntities ( const unsigned int cc ) const
return 8;
}
}
return 0;
DUNE_THROW(NotImplemented, "subEntities not implemented for this codimension");
}

template <int codim>
Expand Down
6 changes: 0 additions & 6 deletions opm/grid/cpgrid/Indexsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ IndexSet::IndexType IndexSet::subIndex(const cpgrid::Entity<0>& e, int i, unsign
{
switch(cc) {
case 0: return index(e.subEntity<0>(i));
case 1: return index(e.subEntity<1>(i));
// case 2: return index(e.subEntity<2>(i)); // Not supported in this grid
case 3: return index(e.subEntity<3>(i));
default: OPM_THROW(std::runtime_error,
"Codimension " + std::to_string(cc) + " not supported.");
Expand All @@ -60,8 +58,6 @@ IdSet::IdType IdSet::subId(const cpgrid::Entity<0>& e, int i, int cc) const
{
switch (cc) {
case 0: return id(e.subEntity<0>(i));
case 1: return id(e.subEntity<1>(i));
// case 2: return id(e.subEntity<2>(i)); // Not supported in this grid
case 3: return id(e.subEntity<3>(i));
default: OPM_THROW(std::runtime_error,
"Cannot get subId of codimension " + std::to_string(cc));
Expand All @@ -75,8 +71,6 @@ LevelGlobalIdSet::IdType LevelGlobalIdSet::subId(const cpgrid::Entity<0>& e, int

switch (cc) {
case 0: return id(e.subEntity<0>(i));
//case 1: return id(*e.subEntity<1>(i));
//case 2: return id(*e.subEntity<2>(i));
case 3: return id(e.subEntity<3>(i));
default: OPM_THROW(std::runtime_error,
"Cannot get subId of codimension " + std::to_string(cc));
Expand Down
43 changes: 18 additions & 25 deletions opm/grid/cpgrid/Indexsets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ along with OPM. If not, see <http://www.gnu.org/licenses/>.

#include <dune/geometry/type.hh>
#include <opm/common/ErrorMacros.hpp>
#include "Entity.hpp"
#include "GlobalIdMapping.hpp"
#include "Intersection.hpp"

Expand All @@ -62,11 +63,8 @@ namespace Dune
static constexpr int dimension = 3;

/** \brief Export supported entity types */
template <int cc>
struct Codim
{
typedef cpgrid::Entity< cc > Entity;
};
template <int cd>
using Codim = typename Impl::CodimTraits<cd>;

/// @brief
/// @todo Doc me!
Expand Down Expand Up @@ -208,11 +206,8 @@ namespace Dune
static constexpr int dimension = 3;

/** \brief Export supported entity types */
template <int cc>
struct Codim
{
using Entity = ::Dune::cpgrid::Entity<cc>;
};
template <int cd>
using Codim = typename Impl::CodimTraits<cd>;

explicit IdSet(const CpGridData& grid)
: grid_(grid)
Expand All @@ -224,13 +219,11 @@ namespace Dune
{
if constexpr (cd == 0)
return computeId_cell(e);
else if constexpr (cd == 1)
return computeId(e);
else if constexpr (cd == 3)
return computeId_point(e);
else
static_assert(AlwaysFalse<index_constant<cd>>::value,
"IdSet::id not implemented for codims other thatn 0, 1, and 3.");
"IdSet::id not implemented for codims other than 0, and 3.");
}

template<class EntityType>
Expand All @@ -240,11 +233,14 @@ namespace Dune
}

template<int codim>
IdType id(const cpgrid::EntityRep<codim>& e) const
IdType idLevelZero(const cpgrid::EntityRep<codim>& e) const
{
return computeId(e);
}

template<int codim>
IdType idLevelZero(const Entity<codim>& e) const = delete;

/// return id of intersection (here face number)
IdType id( const cpgrid::Intersection& intersection ) const
{
Expand Down Expand Up @@ -377,11 +373,8 @@ namespace Dune
static constexpr int dimension = 3;

/** \brief Export supported entity types */
template <int cc>
struct Codim
{
using Entity = ::Dune::cpgrid::Entity<cc>;
};
template <int cd>
using Codim = typename Impl::CodimTraits<cd>;

void swap(std::vector<int>& cellMapping,
std::vector<int>& faceMapping,
Expand Down Expand Up @@ -414,14 +407,17 @@ namespace Dune
}

template<int codim>
IdType id(const EntityRep<codim>& e) const
IdType idLevelZero(const EntityRep<codim>& e) const
{
if(idSet_)
return idSet_->id(e);
return idSet_->idLevelZero(e);
else
return this->template getMapping<codim>()[e.index()];
}

template<int codim>
IdType idLevelZero(const Entity<codim>& e) const = delete;

template<class EntityType>
IdType id(const EntityType& e) const
{
Expand Down Expand Up @@ -493,10 +489,7 @@ namespace Dune

/** \brief Export supported entity types */
template <int cd>
struct Codim
{
using Entity = ::Dune::cpgrid::Entity<cd>;
};
using Codim = typename Impl::CodimTraits<cd>;

explicit GlobalIdSet(const CpGridData& view);

Expand Down
14 changes: 6 additions & 8 deletions tests/cpgrid/distribution_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,6 @@ BOOST_AUTO_TEST_CASE(compareWithSequential)
using namespace Dune::cpgrid;
auto face = grid.cellFace(eIt->index(), f);
auto seqFace = seqGrid.cellFace(seqEIt->index(), f);
BOOST_REQUIRE(idSet.id(Dune::createEntity<1>(grid, face, true)) ==
seqIdSet.id(Dune::createEntity<1>(seqGrid, seqFace, true)));
int vertices = grid.numFaceVertices(face);
BOOST_REQUIRE(vertices == seqGrid.numFaceVertices(seqFace));
for (int v = 0; v < vertices; ++v)
Expand Down Expand Up @@ -579,11 +577,11 @@ BOOST_AUTO_TEST_CASE(PartitionTest)
}
}
MPI_Barrier(MPI_COMM_WORLD);

if (size > 2)
{
MPI_Comm_free(&twocom);
}
}
#endif
}

Expand Down Expand Up @@ -638,7 +636,7 @@ BOOST_AUTO_TEST_CASE(PartitionTestWithCorners)
}
std::cout<<"done interior "<<(int)Dune::InteriorEntity<<" overlap "<<(int)Dune::OverlapEntity
<<" border "<<(int)Dune::BorderEntity<<" front "<<(int)Dune::FrontEntity<<std::endl;

BOOST_CHECK(cells_per_part_type.size() == 2);
BOOST_CHECK(cells_per_part_type[Dune::InteriorEntity] == 4);
BOOST_CHECK(cells_per_part_type[Dune::OverlapEntity] == 8);
Expand All @@ -659,14 +657,14 @@ BOOST_AUTO_TEST_CASE(PartitionTestWithCorners)
BOOST_CHECK(points_per_part_type[Dune::BorderEntity] == 14);
BOOST_CHECK(points_per_part_type[Dune::OverlapEntity] == 6);
BOOST_CHECK(points_per_part_type[Dune::FrontEntity] == 16);
}
}
}
MPI_Barrier(MPI_COMM_WORLD);

if (size > 2)
{
MPI_Comm_free(&twocom);
}
}
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion tests/cpgrid/lgr/id_entity_entityrep_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ std::string coincideString(bool coincide)
template<typename IdSet, typename EntityRep>
auto idRep(const IdSet& idSet, const EntityRep& entityRep)
{
return idSet.id(entityRep);
return idSet.idLevelZero(entityRep);
}

void entityRepIndexAndEntityIndexCoincide(const Dune::CpGrid& grid)
Expand Down