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

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

#include <dune/grid/common/gridfactory.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
{
Stenger, Florian's avatar
Stenger, Florian committed
15
  namespace Vtk
Praetorius, Simon's avatar
Praetorius, Simon committed
16
  {
Stenger, Florian's avatar
Stenger, Florian committed
17
18
19
20
    // create a distributed grid in parallel. Currently only supported by ALUGrid
    template <class Grid>
    struct ParallelGridCreator
        : public DerivedGridCreator<ContinuousGridCreator<Grid>, ParallelGridCreator<Grid>>
Praetorius, Simon's avatar
Praetorius, Simon committed
21
    {
Stenger, Florian's avatar
Stenger, Florian committed
22
23
24
25
26
27
28
29
30
31
32
33
34
      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,
35
                               std::vector<std::uint64_t> const& point_ids)
Stenger, Florian's avatar
Stenger, Florian committed
36
37
38
39
40
      {
        assert(point_ids.size() == points.size());
        for (std::size_t i = 0; i < points.size(); ++i)
          this->factory().insertVertex(points[i], VertexId(point_ids[i]));
      }
Praetorius, Simon's avatar
Praetorius, Simon committed
41

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

Stenger, Florian's avatar
Stenger, Florian committed
51
  } // end namespace Vtk
Praetorius, Simon's avatar
Praetorius, Simon committed
52
} // end namespace Dune