dune-vtk 2.12
Loading...
Searching...
No Matches
serialgridcreator.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3#pragma once
4
5#include <cstdint>
6#include <string>
7#include <vector>
8
9#include <dune/grid/common/gridfactory.hh>
12
13namespace Dune::Vtk
14{
15 // create a distributed grid on rank 0. Needs to be load balanced afterwards.
16 template <class Grid>
18 : public GridCreatorInterface<Grid, SerialGridCreator<Grid>>
19 {
23
24 public:
25
26 using Super::Super;
27
29 std::vector<std::uint64_t> const& /*point_ids*/)
30 {
31 shift_.push_back(points_.size());
32 points_.reserve(points_.size() + points.size());
33 points_.insert(points_.end(), points.begin(), points.end());
34 }
35
37 std::vector<std::int64_t> const& offsets,
38 std::vector<std::int64_t> const& connectivity)
39 {
40 types_.reserve(types_.size() + types.size());
41 types_.insert(types_.end(), types.begin(), types.end());
42
43 offsets_.reserve(offsets_.size() + offsets.size());
44 std::transform(offsets.begin(), offsets.end(), std::back_inserter(offsets_),
45 [shift=offsets_.empty() ? 0 : offsets_.back()](std::int64_t o) { return o + shift; });
46
47 connectivity_.reserve(connectivity_.size() + connectivity.size());
48 std::transform(connectivity.begin(), connectivity.end(), std::back_inserter(connectivity_),
49 [shift=shift_.back()](std::int64_t idx) { return idx + shift; });
50 }
51
53 {
54 if (this->comm().rank() == 0) {
56 for (std::string const& piece : pieces) {
57 pieceReader.read(piece, false);
58 pieceReader.fillGridCreator(false);
59 }
60
62 creator.insertVertices(points_, {});
63 creator.insertElements(types_, offsets_, connectivity_);
64 }
65 }
66
67 private:
71 std::vector<std::int64_t> connectivity_;
73 };
74
75 // deduction guides
76 template <class Grid>
79
80} // end namespace Dune::Vtk
Definition datacollector.hh:19
Implementation of DataCollector for cells, with continuous data.
Definition celltypedatacollector.hh:20
Base class for grid creators in a CRTP style.
Definition gridcreatorinterface.hh:25
GridFactory< Grid > & factory()
Return the associated GridFactory.
Definition gridcreatorinterface.hh:77
typename Grid::template Codim< 0 >::Entity::Geometry::GlobalCoordinate GlobalCoordinate
Definition gridcreatorinterface.hh:28
auto comm() const
Return the mpi collective communicator.
Definition gridcreatorinterface.hh:89
Definition serialgridcreator.hh:19
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:36
void insertVerticesImpl(std::vector< GlobalCoordinate > const &points, std::vector< std::uint64_t > const &)
Definition serialgridcreator.hh:28
typename Super::GlobalCoordinate GlobalCoordinate
Definition serialgridcreator.hh:22
void insertPiecesImpl(std::vector< std::string > const &pieces)
Definition serialgridcreator.hh:52
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)