Commit e6a25e28 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

redesign of readers and grid creators, parallel traversal restricted to interor+border

parent 938c9f1e
*.vtu
*.pvtu
*.vti
*.pvti
*.vtr
*.pvtr
*.vtp
*.pvtp
*.vts
*.pvts
build*/
*.log
*.tmp
\ No newline at end of file
...@@ -5,10 +5,21 @@ ...@@ -5,10 +5,21 @@
namespace Dune { namespace Dune {
template <class GridView, class Derived> template <class GridView, class Derived, class Partition>
class DataCollectorInterface class DataCollectorInterface
{ {
public: public:
/// The partitionset to collect data from
static constexpr auto partition = Partition{};
/// The dimension of the grid
enum { dim = GridView::dimension };
/// The dimension of the world
enum { dow = GridView::dimensionworld };
public:
/// Store a copy of the GridView
DataCollectorInterface (GridView const& gridView) DataCollectorInterface (GridView const& gridView)
: gridView_(gridView) : gridView_(gridView)
{} {}
...@@ -25,7 +36,13 @@ public: ...@@ -25,7 +36,13 @@ public:
return asDerived().ghostLevelImpl(); return asDerived().ghostLevelImpl();
} }
/// Return the number of points in the grid /// \brief Return the number of cells in (this partition of the) grid
std::uint64_t numCells () const
{
return asDerived().numCellsImpl();
}
/// Return the number of points in (this partition of the) grid
std::uint64_t numPoints () const std::uint64_t numPoints () const
{ {
return asDerived().numPointsImpl(); return asDerived().numPointsImpl();
...@@ -59,8 +76,9 @@ public: ...@@ -59,8 +76,9 @@ public:
return asDerived().template pointDataImpl<T>(fct); return asDerived().template pointDataImpl<T>(fct);
} }
/// Return a flat vector of function values evaluated at the cells. \see pointData. /// Return a flat vector of function values evaluated at the cells in the order of traversal.
/** /**
* \see pointData.
* Note: Cells might be descibred explicitly by connectivity, offsets, and types, e.g. in * Note: Cells might be descibred explicitly by connectivity, offsets, and types, e.g. in
* an UnstructuredGrid, or might be described implicitly by the grid type, e.g. in * an UnstructuredGrid, or might be described implicitly by the grid type, e.g. in
* StructuredGrid. * StructuredGrid.
...@@ -95,7 +113,7 @@ public: // default implementations ...@@ -95,7 +113,7 @@ public: // default implementations
return gridView_.overlapSize(0); return gridView_.overlapSize(0);
} }
// Evaluate `fct` in center of cell // Evaluate `fct` in center of cell.
template <class T, class VtkFunction> template <class T, class VtkFunction>
std::vector<T> cellDataImpl (VtkFunction const& fct) const; std::vector<T> cellDataImpl (VtkFunction const& fct) const;
......
...@@ -6,20 +6,20 @@ ...@@ -6,20 +6,20 @@
namespace Dune { namespace Dune {
template <class GridView, class Derived> template <class GV, class D, class P>
template <class T, class VtkFunction> template <class T, class VtkFunction>
std::vector<T> DataCollectorInterface<GridView, Derived> std::vector<T> DataCollectorInterface<GV,D,P>
::cellDataImpl (VtkFunction const& fct) const ::cellDataImpl (VtkFunction const& fct) const
{ {
std::vector<T> data(gridView_.size(0) * fct.ncomps()); std::vector<T> data;
MultipleCodimMultipleGeomTypeMapper<GridView> mapper(gridView_, mcmgElementLayout()); data.reserve(this->numCells() * fct.ncomps());
auto localFct = localFunction(fct); auto localFct = localFunction(fct);
for (auto const& e : elements(gridView_, Partitions::all)) { for (auto const& e : elements(gridView_, partition)) {
localFct.bind(e); localFct.bind(e);
auto refElem = referenceElement<T,GridView::dimension>(e.type()); auto refElem = referenceElement<T,dim>(e.type());
std::size_t idx = fct.ncomps() * mapper.index(e);
for (int comp = 0; comp < fct.ncomps(); ++comp) for (int comp = 0; comp < fct.ncomps(); ++comp)
data[idx + comp] = T(localFct.evaluate(comp, refElem.position(0,0))); data.emplace_back(localFct.evaluate(comp, refElem.position(0,0)));
localFct.unbind(); localFct.unbind();
} }
return data; return data;
......
...@@ -9,39 +9,57 @@ namespace Dune ...@@ -9,39 +9,57 @@ namespace Dune
{ {
/// Implementation of \ref DataCollector for linear cells, with continuous data. /// Implementation of \ref DataCollector for linear cells, with continuous data.
template <class GridView> template <class GridView, class Partition>
class ContinuousDataCollector class ContinuousDataCollector
: public UnstructuredDataCollectorInterface<GridView, ContinuousDataCollector<GridView>> : public UnstructuredDataCollectorInterface<GridView, ContinuousDataCollector<GridView,Partition>, Partition>
{ {
enum { dim = GridView::dimension };
using Self = ContinuousDataCollector; using Self = ContinuousDataCollector;
using Super = UnstructuredDataCollectorInterface<GridView, Self>; using Super = UnstructuredDataCollectorInterface<GridView, Self, Partition>;
public:
using Super::dim;
using Super::partition;
public: public:
ContinuousDataCollector (GridView const& gridView) ContinuousDataCollector (GridView const& gridView)
: Super(gridView) : Super(gridView)
{} {}
/// Collect the vertex indices
void updateImpl ()
{
numPoints_ = 0;
indexMap_.resize(gridView_.size(dim));
auto const& indexSet = gridView_.indexSet();
for (auto const& vertex : vertices(gridView_, partition))
indexMap_[indexSet.index(vertex)] = std::int64_t(numPoints_++);
if (gridView_.comm().size() > 1) {
auto&& e = elements(gridView_, partition);
numCells_ = std::distance(std::begin(e), std::end(e));
} else {
numCells_ = gridView_.size(0);
}
}
/// Return number of grid vertices /// Return number of grid vertices
std::uint64_t numPointsImpl () const std::uint64_t numPointsImpl () const
{ {
return gridView_.size(dim); return numPoints_;
} }
/// Return the coordinates of all grid vertices in the order given by the indexSet /// Return the coordinates of all grid vertices in the order given by the indexSet
template <class T> template <class T>
std::vector<T> pointsImpl () const std::vector<T> pointsImpl () const
{ {
std::vector<T> data(gridView_.size(dim) * 3); std::vector<T> data;
auto const& indexSet = gridView_.indexSet(); data.reserve(numPoints_ * 3);
for (auto const& vertex : vertices(gridView_, Partitions::all)) { for (auto const& vertex : vertices(gridView_, partition)) {
std::size_t idx = 3 * indexSet.index(vertex);
auto v = vertex.geometry().center(); auto v = vertex.geometry().center();
for (std::size_t j = 0; j < v.size(); ++j) for (std::size_t j = 0; j < v.size(); ++j)
data[idx + j] = T(v[j]); data.emplace_back(v[j]);
for (std::size_t j = v.size(); j < 3u; ++j) for (std::size_t j = v.size(); j < 3u; ++j)
data[idx + j] = T(0); data.emplace_back(0);
} }
return data; return data;
} }
...@@ -49,11 +67,12 @@ public: ...@@ -49,11 +67,12 @@ public:
/// Return a vector of global unique ids of the points /// Return a vector of global unique ids of the points
std::vector<std::uint64_t> pointIdsImpl () const std::vector<std::uint64_t> pointIdsImpl () const
{ {
std::vector<std::uint64_t> data(gridView_.size(dim)); std::vector<std::uint64_t> data;
data.reserve(numPoints_);
GlobalIndexSet<GridView> globalIndexSet(gridView_, dim); GlobalIndexSet<GridView> globalIndexSet(gridView_, dim);
auto const& indexSet = gridView_.indexSet(); auto const& indexSet = gridView_.indexSet();
for (auto const& vertex : vertices(gridView_, Partitions::all)) { for (auto const& vertex : vertices(gridView_, partition)) {
data[indexSet.index(vertex)] = std::uint64_t(globalIndexSet.index(vertex)); data.emplace_back(globalIndexSet.index(vertex));
} }
return data; return data;
} }
...@@ -61,7 +80,7 @@ public: ...@@ -61,7 +80,7 @@ public:
/// Return number of grid cells /// Return number of grid cells
std::uint64_t numCellsImpl () const std::uint64_t numCellsImpl () const
{ {
return gridView_.size(0); return numCells_;
} }
/// Return the types, offsets and connectivity of the cells, using the same connectivity as /// Return the types, offsets and connectivity of the cells, using the same connectivity as
...@@ -76,15 +95,15 @@ public: ...@@ -76,15 +95,15 @@ public:
}); });
Cells cells; Cells cells;
cells.connectivity.reserve(gridView_.size(0) * maxVertices); cells.connectivity.reserve(numCells_ * maxVertices);
cells.offsets.reserve(gridView_.size(0)); cells.offsets.reserve(numCells_);
cells.types.reserve(gridView_.size(0)); cells.types.reserve(numCells_);
std::int64_t old_o = 0; std::int64_t old_o = 0;
for (auto const& c : elements(gridView_, Partitions::all)) { for (auto const& c : elements(gridView_, partition)) {
Vtk::CellType cellType(c.type()); Vtk::CellType cellType(c.type());
for (unsigned int j = 0; j < c.subEntities(dim); ++j) for (unsigned int j = 0; j < c.subEntities(dim); ++j)
cells.connectivity.push_back( std::int64_t(indexSet.subIndex(c,cellType.permutation(j),dim)) ); cells.connectivity.emplace_back(indexMap_[indexSet.subIndex(c,cellType.permutation(j),dim)]);
cells.offsets.push_back(old_o += c.subEntities(dim)); cells.offsets.push_back(old_o += c.subEntities(dim));
cells.types.push_back(cellType.type()); cells.types.push_back(cellType.type());
} }
...@@ -95,15 +114,15 @@ public: ...@@ -95,15 +114,15 @@ public:
template <class T, class GlobalFunction> template <class T, class GlobalFunction>
std::vector<T> pointDataImpl (GlobalFunction const& fct) const std::vector<T> pointDataImpl (GlobalFunction const& fct) const
{ {
std::vector<T> data(gridView_.size(dim) * fct.ncomps()); std::vector<T> data(numPoints_ * fct.ncomps());
auto const& indexSet = gridView_.indexSet(); auto const& indexSet = gridView_.indexSet();
auto localFct = localFunction(fct); auto localFct = localFunction(fct);
for (auto const& e : elements(gridView_, Partitions::all)) { for (auto const& e : elements(gridView_, partition)) {
localFct.bind(e); localFct.bind(e);
Vtk::CellType cellType{e.type()}; Vtk::CellType cellType{e.type()};
auto refElem = referenceElement(e.geometry()); auto refElem = referenceElement(e.geometry());
for (unsigned int j = 0; j < e.subEntities(dim); ++j) { for (unsigned int j = 0; j < e.subEntities(dim); ++j) {
std::size_t idx = fct.ncomps() * indexSet.subIndex(e,cellType.permutation(j),dim); std::size_t idx = fct.ncomps() * indexMap_[indexSet.subIndex(e,cellType.permutation(j),dim)];
for (int comp = 0; comp < fct.ncomps(); ++comp) for (int comp = 0; comp < fct.ncomps(); ++comp)
data[idx + comp] = T(localFct.evaluate(comp, refElem.position(cellType.permutation(j),dim))); data[idx + comp] = T(localFct.evaluate(comp, refElem.position(cellType.permutation(j),dim)));
} }
...@@ -114,6 +133,9 @@ public: ...@@ -114,6 +133,9 @@ public:
protected: protected:
using Super::gridView_; using Super::gridView_;
std::uint64_t numPoints_ = 0;
std::uint64_t numCells_ = 0;
std::vector<std::int64_t> indexMap_;
}; };
} // end namespace Dune } // end namespace Dune
...@@ -6,14 +6,16 @@ namespace Dune ...@@ -6,14 +6,16 @@ namespace Dune
{ {
/// Implementation of \ref DataCollector for linear cells, with discontinuous data. /// Implementation of \ref DataCollector for linear cells, with discontinuous data.
template <class GridView> template <class GridView, class Partition>
class DiscontinuousDataCollector class DiscontinuousDataCollector
: public UnstructuredDataCollectorInterface<GridView, DiscontinuousDataCollector<GridView>> : public UnstructuredDataCollectorInterface<GridView, DiscontinuousDataCollector<GridView,Partition>, Partition>
{ {
enum { dim = GridView::dimension };
using Self = DiscontinuousDataCollector; using Self = DiscontinuousDataCollector;
using Super = UnstructuredDataCollectorInterface<GridView, Self>; using Super = UnstructuredDataCollectorInterface<GridView, Self, Partition>;
public:
using Super::dim;
using Super::partition;
public: public:
DiscontinuousDataCollector (GridView const& gridView) DiscontinuousDataCollector (GridView const& gridView)
...@@ -24,10 +26,12 @@ public: ...@@ -24,10 +26,12 @@ public:
void updateImpl () void updateImpl ()
{ {
numPoints_ = 0; numPoints_ = 0;
numCells_ = 0;
indexMap_.resize(gridView_.size(dim)); indexMap_.resize(gridView_.size(dim));
std::int64_t vertex_idx = 0; std::int64_t vertex_idx = 0;
auto const& indexSet = gridView_.indexSet(); auto const& indexSet = gridView_.indexSet();
for (auto const& c : elements(gridView_, Partitions::interior)) { for (auto const& c : elements(gridView_, partition)) {
numCells_++;
numPoints_ += c.subEntities(dim); numPoints_ += c.subEntities(dim);
for (unsigned int i = 0; i < c.subEntities(dim); ++i) for (unsigned int i = 0; i < c.subEntities(dim); ++i)
indexMap_[indexSet.subIndex(c, i, dim)] = vertex_idx++; indexMap_[indexSet.subIndex(c, i, dim)] = vertex_idx++;
...@@ -46,7 +50,7 @@ public: ...@@ -46,7 +50,7 @@ public:
{ {
std::vector<T> data(numPoints_ * 3); std::vector<T> data(numPoints_ * 3);
auto const& indexSet = gridView_.indexSet(); auto const& indexSet = gridView_.indexSet();
for (auto const& element : elements(gridView_, Partitions::interior)) { for (auto const& element : elements(gridView_, partition)) {
for (unsigned int i = 0; i < element.subEntities(dim); ++i) { for (unsigned int i = 0; i < element.subEntities(dim); ++i) {
std::size_t idx = 3 * indexMap_[indexSet.subIndex(element, i, dim)]; std::size_t idx = 3 * indexMap_[indexSet.subIndex(element, i, dim)];
auto v = element.geometry().corner(i); auto v = element.geometry().corner(i);
...@@ -62,7 +66,7 @@ public: ...@@ -62,7 +66,7 @@ public:
/// Return number of grid cells /// Return number of grid cells
std::uint64_t numCellsImpl () const std::uint64_t numCellsImpl () const
{ {
return gridView_.size(0); return numCells_;
} }
/// Connect the corners of each cell. The leads to a global discontinuous grid /// Connect the corners of each cell. The leads to a global discontinuous grid
...@@ -70,12 +74,12 @@ public: ...@@ -70,12 +74,12 @@ public:
{ {
Cells cells; Cells cells;
cells.connectivity.reserve(numPoints_); cells.connectivity.reserve(numPoints_);
cells.offsets.reserve(gridView_.size(0)); cells.offsets.reserve(numCells_);
cells.types.reserve(gridView_.size(0)); cells.types.reserve(numCells_);
std::int64_t old_o = 0; std::int64_t old_o = 0;
auto const& indexSet = gridView_.indexSet(); auto const& indexSet = gridView_.indexSet();
for (auto const& c : elements(gridView_, Partitions::interior)) { for (auto const& c : elements(gridView_, partition)) {
Vtk::CellType cellType(c.type()); Vtk::CellType cellType(c.type());
for (unsigned int j = 0; j < c.subEntities(dim); ++j) { for (unsigned int j = 0; j < c.subEntities(dim); ++j) {
std::int64_t vertex_idx = indexMap_[indexSet.subIndex(c,cellType.permutation(j),dim)]; std::int64_t vertex_idx = indexMap_[indexSet.subIndex(c,cellType.permutation(j),dim)];
...@@ -95,7 +99,7 @@ public: ...@@ -95,7 +99,7 @@ public:
std::vector<T> data(numPoints_ * fct.ncomps()); std::vector<T> data(numPoints_ * fct.ncomps());
auto const& indexSet = gridView_.indexSet(); auto const& indexSet = gridView_.indexSet();
auto localFct = localFunction(fct); auto localFct = localFunction(fct);
for (auto const& e : elements(gridView_, Partitions::interior)) { for (auto const& e : elements(gridView_, partition)) {
localFct.bind(e); localFct.bind(e);
Vtk::CellType cellType{e.type()}; Vtk::CellType cellType{e.type()};
auto refElem = referenceElement(e.geometry()); auto refElem = referenceElement(e.geometry());
...@@ -111,6 +115,7 @@ public: ...@@ -111,6 +115,7 @@ public:
protected: protected:
using Super::gridView_; using Super::gridView_;
std::uint64_t numCells_ = 0;
std::uint64_t numPoints_ = 0; std::uint64_t numPoints_ = 0;
std::vector<std::int64_t> indexMap_; std::vector<std::int64_t> indexMap_;
}; };
......
...@@ -8,12 +8,14 @@ namespace Dune ...@@ -8,12 +8,14 @@ namespace Dune
/// Implementation of \ref DataCollector for quadratic cells, with continuous data. /// Implementation of \ref DataCollector for quadratic cells, with continuous data.
template <class GridView> template <class GridView>
class QuadraticDataCollector class QuadraticDataCollector
: public UnstructuredDataCollectorInterface<GridView, QuadraticDataCollector<GridView>> : public UnstructuredDataCollectorInterface<GridView, QuadraticDataCollector<GridView>, Partitions::All>
{ {
enum { dim = GridView::dimension };
using Self = QuadraticDataCollector; using Self = QuadraticDataCollector;
using Super = UnstructuredDataCollectorInterface<GridView, Self>; using Super = UnstructuredDataCollectorInterface<GridView, Self, Partitions::All>;
public:
using Super::dim;
using Super::partition; // NOTE: quadratic data-collector currently implemented for the All partition only
public: public:
QuadraticDataCollector (GridView const& gridView) QuadraticDataCollector (GridView const& gridView)
...@@ -36,7 +38,7 @@ public: ...@@ -36,7 +38,7 @@ public:
{ {
std::vector<T> data(this->numPoints() * 3); std::vector<T> data(this->numPoints() * 3);
auto const& indexSet = gridView_.indexSet(); auto const& indexSet = gridView_.indexSet();
for (auto const& element : elements(gridView_, Partitions::interior)) { for (auto const& element : elements(gridView_, partition)) {
auto geometry = element.geometry(); auto geometry = element.geometry();
auto refElem = referenceElement<T,dim>(element.type()); auto refElem = referenceElement<T,dim>(element.type());
...@@ -82,7 +84,7 @@ public: ...@@ -82,7 +84,7 @@ public:
std::int64_t old_o = 0; std::int64_t old_o = 0;
auto const& indexSet = gridView_.indexSet(); auto const& indexSet = gridView_.indexSet();
for (auto const& c : elements(gridView_, Partitions::interior)) { for (auto const& c : elements(gridView_, partition)) {
Vtk::CellType cellType(c.type(), Vtk::QUADRATIC); Vtk::CellType cellType(c.type(), Vtk::QUADRATIC);
for (unsigned int j = 0; j < c.subEntities(dim); ++j) { for (unsigned int j = 0; j < c.subEntities(dim); ++j) {
int k = cellType.permutation(j); int k = cellType.permutation(j);
...@@ -107,7 +109,7 @@ public: ...@@ -107,7 +109,7 @@ public:
std::vector<T> data(this->numPoints() * fct.ncomps()); std::vector<T> data(this->numPoints() * fct.ncomps());
auto const& indexSet = gridView_.indexSet(); auto const& indexSet = gridView_.indexSet();
auto localFct = localFunction(fct); auto localFct = localFunction(fct);
for (auto const& e : elements(gridView_, Partitions::interior)) { for (auto const& e : elements(gridView_, partition)) {
localFct.bind(e); localFct.bind(e);
Vtk::CellType cellType{e.type(), Vtk::QUADRATIC}; Vtk::CellType cellType{e.type(), Vtk::QUADRATIC};
auto refElem = referenceElement(e.geometry()); auto refElem = referenceElement(e.geometry());
......
...@@ -15,12 +15,14 @@ template <class GridView> ...@@ -15,12 +15,14 @@ template <class GridView>
class SPDataCollector class SPDataCollector
: public StructuredDataCollectorInterface<GridView, SPDataCollector<GridView>> : public StructuredDataCollectorInterface<GridView, SPDataCollector<GridView>>
{ {
enum { dim = GridView::dimension };
using Self = SPDataCollector; using Self = SPDataCollector;
using Super = StructuredDataCollectorInterface<GridView, Self>; using Super = StructuredDataCollectorInterface<GridView, Self>;
using ctype = typename GridView::ctype; using ctype = typename GridView::ctype;
public:
using Super::dim;
using Super::partition;
public: public:
SPDataCollector (GridView const& gridView) SPDataCollector (GridView const& gridView)
: Super(gridView) : Super(gridView)
......
...@@ -19,6 +19,10 @@ protected: ...@@ -19,6 +19,10 @@ protected:
using SubDataCollector = ContinuousDataCollector<GridView>; using SubDataCollector = ContinuousDataCollector<GridView>;
using ctype = typename GridView::ctype; using ctype = typename GridView::ctype;
public:
using Super::dim;
using Super::partition;
public: public:
StructuredDataCollectorInterface (GridView const& gridView) StructuredDataCollectorInterface (GridView const& gridView)
: Super(gridView) : Super(gridView)
...@@ -103,6 +107,16 @@ public: // default implementation: ...@@ -103,6 +107,16 @@ public: // default implementation:
#endif #endif
} }
/// Return number of grid cells
std::uint64_t numCellsImpl () const
{
auto extent = this->extent();
std::uint64_t num = 1;
for (int d = 0; d < dim; ++d)
num *= extent[2*d+1] - extent[2*d];
return num;
}
/// Return number of grid vertices /// Return number of grid vertices
std::uint64_t numPointsImpl () const std::uint64_t numPointsImpl () const
{