4#ifndef DUNE_GRID_IO_FILE_GMSH_GMSH4READER_HH
5#define DUNE_GRID_IO_FILE_GMSH_GMSH4READER_HH
14#include <dune/grid/io/file/gmsh/filereader.hh>
15#include <dune/grid/io/file/gmsh/gridcreators/continuousgridcreator.hh>
17namespace Dune::Impl::Gmsh
33 template <
class Gr
id,
class Gr
idCreator = ContinuousGr
idCreator<Gr
id>,
class SizeType = std::
size_t>
35 :
public FileReader<Grid, Gmsh4Reader<Grid, GridCreator> >
39 NO_SECTION = 0, MESH_FORMAT, PHYSICAL_NAMES, ENTITIES, PARTITIONED_ENTITIES, NODES, ELEMENTS, PERIODIC,
40 GHOST_ELEMENTS, PARAMETRIZATION, NODE_DATA, ELEMENT_DATA, ELEMENT_NODE_DATA, INTERPOLATION_SCHEME
43 using Entity =
typename Grid::template Codim<0>::Entity;
44 using GlobalCoordinate =
typename Entity::Geometry::GlobalCoordinate;
47 using size_type = SizeType;
50 template <
class ... Args,
51 std::enable_if_t<std::is_constructible<GridCreator, Args...>::value,
int> = 0>
52 explicit Gmsh4Reader (Args&&... args)
53 : creator_(
std::make_shared<GridCreator>(
std::forward<Args>(args)...))
57 explicit Gmsh4Reader (GridCreator& creator)
62 explicit Gmsh4Reader (std::shared_ptr<GridCreator> creator)
63 : creator_(
std::move(creator))
72 void read (std::string
const& filename,
bool fillCreator =
true);
83 void readSerialFileFromStream (std::ifstream& input,
bool fillCreator =
true);
91 void readParallelFileFromStream (std::ifstream& input,
int rank,
int size,
bool fillCreator =
true);
95 void fillGridCreator (
bool insertPieces =
true);
100 std::vector<std::string>
const& pieces ()
const
107 static void fillFactoryImpl (GridFactory<Grid>& factory, std::string
const& filename)
109 Gmsh4Reader reader{factory};
110 reader.read(filename);
116 void readValueBinary(std::ifstream& input, T &v);
117 void readMeshFormat (std::ifstream& input,
118 double& version,
int& file_type,
int& data_size);
120 void readPhysicalNames (std::ifstream& input);
121 void readEntitiesAscii (std::ifstream& input);
122 void readEntitiesBinary (std::ifstream& input);
123 void readPartitionedEntitiesAscii (std::ifstream& input);
124 void readPartitionedEntitiesBinary (std::ifstream& input);
125 void readNodesAscii (std::ifstream& input);
126 void readNodesBinary (std::ifstream& input);
127 void readElementsAscii (std::ifstream& input);
128 void readElementsBinary (std::ifstream& input);
129 void readPeriodic (std::ifstream& input);
130 void readGhostElements (std::ifstream& input);
131 void readParametrization (std::ifstream& input);
132 void readNodeData (std::ifstream& input);
133 void readElementData (std::ifstream& input);
134 void readElementNodeData (std::ifstream& input);
135 void readInterpolationScheme (std::ifstream& input);
138 bool isSection (std::string
line,
141 Sections parent = Sections::NO_SECTION)
const
143 bool result =
line.substr(1, key.length()) == key;
144 if (result && current != parent)
149 void readString(std::istream& , std::string& name)
160 physicalNames_.clear();
168 ghostEntities_.clear();
169 partitionedPoints_.clear();
170 partitionedCurves_.clear();
171 partitionedSurfaces_.clear();
172 partitionedVolumes_.clear();
185 ghostElements_.clear();
186 parametrization_.clear();
188 elementData_.clear();
189 elementNodeData_.clear();
190 interpolationScheme_.clear();
195 return MPIHelper::getCommunication();
200 struct PhysicalNamesAttributes;
201 struct PointAttributes;
202 struct EntityAttributes;
204 template <
class Attr>
205 struct PartitionedAttributes :
public Attr
209 std::vector<int> partitions;
212 struct GhostAttributes;
213 struct NodeAttributes;
214 struct ElementAttributes;
215 struct PeriodicAttributes;
217 struct GhostElementAttributes {};
218 struct ParametrizationAttributes {};
219 struct NodeDataAttributes {};
220 struct ElementDataAttributes {};
221 struct ElementNodeDataAttributes {};
222 struct InterpolationSchemeAttributes {};
225 std::shared_ptr<GridCreator> creator_ =
nullptr;
230 std::vector<std::string> pieces_;
233 std::vector<PhysicalNamesAttributes> physicalNames_;
236 std::vector<PointAttributes> points_;
237 std::vector<EntityAttributes> curves_;
238 std::vector<EntityAttributes> surfaces_;
239 std::vector<EntityAttributes> volumes_;
242 size_type numPartitions_ = 0;
243 std::vector<GhostAttributes> ghostEntities_;
244 std::vector<PartitionedAttributes<PointAttributes> > partitionedPoints_;
245 std::vector<PartitionedAttributes<EntityAttributes> > partitionedCurves_;
246 std::vector<PartitionedAttributes<EntityAttributes> > partitionedSurfaces_;
247 std::vector<PartitionedAttributes<EntityAttributes> > partitionedVolumes_;
249 size_type numNodes_ = 0;
250 size_type minNodeTag_ = 0;
251 size_type maxNodeTag_ = 0;
252 std::vector<NodeAttributes> nodes_;
254 size_type numElements_ = 0;
255 size_type minElementTag_ = 0;
256 size_type maxElementTag_ = 0;
257 std::vector<ElementAttributes> elements_;
258 std::vector<PeriodicAttributes> periodic_;
259 std::vector<GhostElementAttributes> ghostElements_;
260 std::vector<ParametrizationAttributes> parametrization_;
261 std::vector<NodeDataAttributes> nodeData_;
262 std::vector<ElementDataAttributes> elementData_;
263 std::vector<ElementNodeDataAttributes> elementNodeData_;
264 std::vector<InterpolationSchemeAttributes> interpolationScheme_;
267 static std::map<int, size_type> elementType_;
270 static std::map<std::string, Sections> sections_;
274 template <
class Gr
id>
275 Gmsh4Reader (GridFactory<Grid>&)
276 -> Gmsh4Reader<Grid, ContinuousGridCreator<Grid> >;
278 template <
class GridCreator,
279 class = std::void_t<typename GridCreator::Grid> >
280 Gmsh4Reader (GridCreator&)
281 -> Gmsh4Reader<typename GridCreator::Grid, GridCreator>;
283 template <
class GridCreator,
284 class = std::void_t<typename GridCreator::Grid> >
285 Gmsh4Reader (std::shared_ptr<GridCreator>)
286 -> Gmsh4Reader<typename GridCreator::Grid, GridCreator>;
290#include "gmsh4reader.impl.hh"
Base class for Dune-Exceptions.
Definition: exceptions.hh:98
Default exception for dummy implementations.
Definition: exceptions.hh:357
#define DUNE_THROW(E,...)
Definition: exceptions.hh:314
constexpr GeometryType line
GeometryType representing a line.
Definition: type.hh:498
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:72
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
This file implements several utilities related to std::shared_ptr.