parallelgridcreator.hh 1.67 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#pragma once

#include <cstdint>
#include <string>
#include <vector>

#include <dune/grid/common/gridfactory.hh>
#include <dune/vtk/forward.hh>
#include <dune/vtk/gridcreatorinterface.hh>
#include <dune/vtk/gridcreators/common.hh>
#include <dune/vtk/gridcreators/derivedgridcreator.hh>
#include <dune/vtk/gridcreators/continuousgridcreator.hh>

namespace Dune
{
16
  // create a distributed grid in parallel. Currently only supported by ALUGrid
Praetorius, Simon's avatar
Praetorius, Simon committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  template <class Grid>
  struct ParallelGridCreator
      : public DerivedGridCreator<ContinuousGridCreator<Grid>, ParallelGridCreator<Grid>>
  {
    using Self = ParallelGridCreator;
    using Super = DerivedGridCreator<ContinuousGridCreator<Grid>, Self>;
    using GlobalCoordinate = typename Super::GlobalCoordinate;
    using VertexId = VertexId_t<GridFactory<Grid>>;

    // The GridFactory must support insertion of global vertex IDs
    static_assert(Std::is_detected<HasInsertVertex, GridFactory<Grid>, GlobalCoordinate, VertexId>{}, "");

    ParallelGridCreator (GridFactory<Grid>& factory)
      : Super(factory)
    {}

    void insertVerticesImpl (std::vector<GlobalCoordinate> const& points,
                             std::vector<std::uint64_t> const& point_ids)
    {
      assert(point_ids.size() == points.size());
      for (std::size_t i = 0; i < points.size(); ++i)
38
        this->factory().insertVertex(points[i], VertexId(point_ids[i]));
Praetorius, Simon's avatar
Praetorius, Simon committed
39
40
41
42
    }

    void insertPiecesImpl (std::vector<std::string> const& pieces)
    {
43
44
45
      if (int(pieces.size()) == this->comm().size()) {
        VtkReader<Grid, Self> pieceReader(this->factory());
        pieceReader.readFromFile(pieces[this->comm().rank()], true);
Praetorius, Simon's avatar
Praetorius, Simon committed
46
47
48
49
50
      }
    }
  };

} // end namespace Dune