Dune Core Modules (2.11.0)

gridcreatorinterface.hh
1#pragma once
2
3#include <cstdint>
4#include <string>
5#include <vector>
6
10
11namespace Dune::Vtk
12{
14
21 template <class GridType, class DerivedType>
23 {
24 public:
25 using Grid = GridType;
26 using GlobalCoordinate = typename Grid::template Codim<0>::Entity::Geometry::GlobalCoordinate;
27 using Derived = DerivedType;
28
29 public:
33 {}
34
37 : factory_(std::move(factory))
38 {}
39
41 template <class... Args,
42 std::enable_if_t<std::is_constructible<GridFactory<Grid>, Args...>::value,int> = 0>
43 GridCreatorInterface (Args&&... args)
44 : factory_(std::make_shared<GridFactory<Grid>>(std::forward<Args>(args)...))
45 {}
46
48 void insertVertices (std::vector<GlobalCoordinate> const& points,
49 std::vector<std::uint64_t> const& point_ids)
50 {
51 asDerived().insertVerticesImpl(points, point_ids);
52 }
53
55 void insertElements (std::vector<std::uint8_t> const& types,
56 std::vector<std::int64_t> const& offsets,
57 std::vector<std::int64_t> const& connectivity)
58 {
59 asDerived().insertElementsImpl(types, offsets, connectivity);
60 }
61
63 void insertPieces (std::vector<std::string> const& pieces)
64 {
65 asDerived().insertPiecesImpl(pieces);
66 }
67
69 std::unique_ptr<Grid> createGrid () const
70 {
71 return std::unique_ptr<Grid>(factory_->createGrid());
72 }
73
76 {
77 return *factory_;
78 }
79
81 GridFactory<Grid> const& factory () const
82 {
83 return *factory_;
84 }
85
87 auto comm () const
88 {
89 return MPIHelper::getCommunication();
90 }
91
92 protected: // cast to derived type
93
94 Derived& asDerived ()
95 {
96 return static_cast<Derived&>(*this);
97 }
98
99 const Derived& asDerived () const
100 {
101 return static_cast<const Derived&>(*this);
102 }
103
104 public: // default implementations
105
106 void insertVerticesImpl (std::vector<GlobalCoordinate> const&,
107 std::vector<std::uint64_t> const&)
108 {
109 /* do nothing */
110 }
111
112 void insertElementsImpl (std::vector<std::uint8_t> const&,
113 std::vector<std::int64_t> const&,
114 std::vector<std::int64_t> const&)
115 {
116 /* do nothing */
117 }
118
119 void insertPiecesImpl (std::vector<std::string> const&)
120 {
121 /* do nothing */;
122 }
123
124 protected:
125 std::shared_ptr<GridFactory<Grid>> factory_;
126 };
127
128} // end namespace Dune::Vtk
Base class for grid creators in a CRTP style.
Definition: gridcreatorinterface.hh:23
GridCreatorInterface(Args &&... args)
Constructor. Construct a new GridFactory from the passed arguments.
Definition: gridcreatorinterface.hh:43
GridFactory< Grid > & factory()
Return the associated GridFactory.
Definition: gridcreatorinterface.hh:75
std::unique_ptr< Grid > createGrid() const
Construct the actual grid using the GridFactory.
Definition: gridcreatorinterface.hh:69
auto comm() const
Return the mpi collective communicator.
Definition: gridcreatorinterface.hh:87
void insertPieces(std::vector< std::string > const &pieces)
Insert part of a grid stored in file into factory.
Definition: gridcreatorinterface.hh:63
GridCreatorInterface(std::shared_ptr< GridFactory< Grid > > factory)
Constructor. Store the shared_ptr to the GridFactory.
Definition: gridcreatorinterface.hh:36
GridCreatorInterface(GridFactory< Grid > &factory)
Constructor. Stores a reference to the passed GridFactory.
Definition: gridcreatorinterface.hh:31
GridFactory< Grid > const & factory() const
Return the associated (const) GridFactory.
Definition: gridcreatorinterface.hh:81
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
Provide a generic factory class for unstructured grids.
Various macros to work with Dune module version numbers.
Helpers for dealing with MPI.
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:72
STL namespace.
Static tag representing a codimension.
Definition: dimension.hh:24
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Feb 14, 23:39, 2026)