dune-vtk 2.12
Loading...
Searching...
No Matches
serialgridcreator.hh
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <string>
5#include <vector>
6
7#include <dune/grid/common/gridfactory.hh>
10
11namespace Dune::Vtk
12{
13 // create a distributed grid on rank 0. Needs to be load balanced afterwards.
14 template <class Grid>
16 : public GridCreatorInterface<Grid, SerialGridCreator<Grid>>
17 {
21
22 public:
23
24 using Super::Super;
25
27 std::vector<std::uint64_t> const& /*point_ids*/)
28 {
29 shift_.push_back(points_.size());
30 points_.reserve(points_.size() + points.size());
31 points_.insert(points_.end(), points.begin(), points.end());
32 }
33
35 std::vector<std::int64_t> const& offsets,
36 std::vector<std::int64_t> const& connectivity)
37 {
38 types_.reserve(types_.size() + types.size());
39 types_.insert(types_.end(), types.begin(), types.end());
40
41 offsets_.reserve(offsets_.size() + offsets.size());
42 std::transform(offsets.begin(), offsets.end(), std::back_inserter(offsets_),
43 [shift=offsets_.empty() ? 0 : offsets_.back()](std::int64_t o) { return o + shift; });
44
45 connectivity_.reserve(connectivity_.size() + connectivity.size());
46 std::transform(connectivity.begin(), connectivity.end(), std::back_inserter(connectivity_),
47 [shift=shift_.back()](std::int64_t idx) { return idx + shift; });
48 }
49
51 {
52 if (this->comm().rank() == 0) {
53 VtkReader<Grid, Self> pieceReader(*this);
54 for (std::string const& piece : pieces) {
55 pieceReader.read(piece, false);
56 pieceReader.fillGridCreator(false);
57 }
58
60 creator.insertVertices(points_, {});
61 creator.insertElements(types_, offsets_, connectivity_);
62 }
63 }
64
65 private:
69 std::vector<std::int64_t> connectivity_;
71 };
72
73 // deduction guides
74 template <class Grid>
77
78} // end namespace Dune::Vtk
Definition writer.hh:16
Base class for grid creators in a CRTP style.
Definition gridcreatorinterface.hh:23
GridFactory< Grid > & factory()
Return the associated GridFactory.
Definition gridcreatorinterface.hh:75
typename Grid::template Codim< 0 >::Entity::Geometry::GlobalCoordinate GlobalCoordinate
Definition gridcreatorinterface.hh:26
auto comm() const
Return the mpi collective communicator.
Definition gridcreatorinterface.hh:87
void insertVertices(std::vector< GlobalCoordinate > const &points, std::vector< std::uint64_t > const &point_ids)
Insert all points as vertices into the factory.
Definition gridcreatorinterface.hh:48
void insertElements(std::vector< std::uint8_t > const &types, std::vector< std::int64_t > const &offsets, std::vector< std::int64_t > const &connectivity)
Create elements based on type and connectivity description.
Definition gridcreatorinterface.hh:55
Definition discontinuousgridcreator.hh:22
Definition serialgridcreator.hh:17
void insertElementsImpl(std::vector< std::uint8_t > const &types, std::vector< std::int64_t > const &offsets, std::vector< std::int64_t > const &connectivity)
Definition serialgridcreator.hh:34
void insertVerticesImpl(std::vector< GlobalCoordinate > const &points, std::vector< std::uint64_t > const &)
Definition serialgridcreator.hh:26
typename Super::GlobalCoordinate GlobalCoordinate
Definition serialgridcreator.hh:20
void insertPiecesImpl(std::vector< std::string > const &pieces)
Definition serialgridcreator.hh:50
File-Reader for Vtk unstructured .vtu files.
Definition vtkreader.hh:37
void read(std::string const &filename, bool fillCreator=true)
Read the grid from file with filename into the GridCreator.
Definition vtkreader.impl.hh:20
void fillGridCreator(bool insertPieces=true)
Definition vtkreader.impl.hh:684
T back(T... args)
T back_inserter(T... args)
T begin(T... args)
T empty(T... args)
T end(T... args)
T insert(T... args)
T push_back(T... args)
T reserve(T... args)
T size(T... args)
T transform(T... args)