6#ifndef DUNE_GRID_IO_FILE_GMSHREADER_HH 
    7#define DUNE_GRID_IO_FILE_GMSHREADER_HH 
   18#include <dune/grid/io/file/gmsh/gmsh2parser.hh> 
   19#include <dune/grid/io/file/gmsh/gmsh4reader.hh> 
   20#include <dune/grid/io/file/gmsh/utility/version.hh> 
   54      insertBoundarySegments = 2,
 
   63        static_cast<int>(a) | 
static_cast<int>(b)
 
   70      return static_cast<int>(a) & 
static_cast<int>(b);
 
   85  template <
typename Gr
idType>
 
   86  using GmshReaderParser [[deprecated(
"Use Impl::Gmsh::Gmsh2Parser directly")]] = Impl::Gmsh::Gmsh2Parser<GridType>;
 
  104  template<
typename Gr
idType>
 
  128                       const std::string &fileName,
 
  129                       std::vector<int>& boundarySegmentToPhysicalEntity,
 
  130                       std::vector<int>& elementToPhysicalEntity,
 
  131                       bool verbose, 
bool insertBoundarySegments)
 
  135      Impl::Gmsh::GmshReaderQuadraticBoundarySegment< Grid::dimension, Grid::dimensionworld >::registerFactory();
 
  145        Impl::Gmsh::Gmsh2Parser<Grid> parser(factory,verbose,insertBoundarySegments);
 
  146        parser.read(fileName);
 
  148        boundarySegmentToPhysicalEntity = std::move(parser.boundaryIdMap());
 
  149        elementToPhysicalEntity = std::move(parser.elementIndexMap());
 
  153        boundarySegmentToPhysicalEntity = {};
 
  154        elementToPhysicalEntity = {};
 
  179    static T &discarded(T &&value) { 
return static_cast<T&
>(value); }
 
  182      std::vector<int> *data_ = 
nullptr;
 
  183      DataArg(std::vector<int> &data) : data_(&data) {}
 
  184      DataArg(
const decltype(std::ignore)&) {}
 
  188    struct DataFlagArg : DataArg {
 
  190      using DataArg::DataArg;
 
  191      DataFlagArg(
bool flag) : flag_(flag) {}
 
  195    typedef GridType Grid;
 
  199    static std::unique_ptr<Grid> 
read (
const std::string& fileName, 
bool verbose = 
true, 
bool insertBoundarySegments=
true)
 
  204      read(factory, fileName, verbose, insertBoundarySegments);
 
  232    static std::unique_ptr<Grid> 
read (
const std::string& fileName,
 
  233                       std::vector<int>& boundarySegmentToPhysicalEntity,
 
  234                       std::vector<int>& elementToPhysicalEntity,
 
  235                       bool verbose = 
true, 
bool insertBoundarySegments=
true)
 
  240      if (Impl::Gmsh::fileVersion(fileName)[0]==4)
 
  242        Impl::Gmsh::Gmsh4Reader<Grid>::fillFactory(factory, fileName);
 
  247        factory, fileName, boundarySegmentToPhysicalEntity,
 
  248        elementToPhysicalEntity, verbose, insertBoundarySegments
 
  260                      bool verbose = 
true, 
bool insertBoundarySegments=
true)
 
  262      if (Impl::Gmsh::fileVersion(fileName)[0]==4)
 
  264        Impl::Gmsh::Gmsh4Reader<Grid>::fillFactory(factory, fileName);
 
  269        factory, fileName, discarded(std::vector<int>{}),
 
  270        discarded(std::vector<int>{}), verbose, insertBoundarySegments
 
  302                      const std::string &fileName,
 
  303                      DataFlagArg boundarySegmentData,
 
  307      if (Impl::Gmsh::fileVersion(fileName)[0]==4)
 
  309        Impl::Gmsh::Gmsh4Reader<Grid>::fillFactory(factory, fileName);
 
  315        boundarySegmentData.data_
 
  316          ? *boundarySegmentData.data_ : discarded(std::vector<int>{}),
 
  318          ? *
elementData.data_ : discarded(std::vector<int>{}),
 
  320        boundarySegmentData.flag_ || boundarySegmentData.data_
 
  349                      const std::string& fileName,
 
  350                      std::vector<int>& boundarySegmentToPhysicalEntity,
 
  351                      std::vector<int>& elementToPhysicalEntity,
 
  352                      bool verbose, 
bool insertBoundarySegments)
 
  354      if (Impl::Gmsh::fileVersion(fileName)[0]==4)
 
  356        Impl::Gmsh::Gmsh4Reader<Grid>::fillFactory(factory, fileName);
 
  361        factory, fileName, boundarySegmentToPhysicalEntity,
 
  362        elementToPhysicalEntity, verbose, insertBoundarySegments
 
  371    static constexpr Opts defaultOpts =
 
  372      Opts::verbose | Opts::insertBoundarySegments | Opts::readElementData | Opts::readBoundaryData;
 
  403      gridFactory_ = std::make_unique<Dune::GridFactory<Grid>>();
 
  404      readGridFile(fileName, *gridFactory_, options);
 
  418      readGridFile(fileName, factory, options);
 
  425      return elementIndexToGmshPhysicalEntity_;
 
  432      return boundarySegmentIndexToGmshPhysicalEntity_;
 
  440    { 
return hasElementData_ && !extractedElementData_; }
 
  447    { 
return hasBoundaryData_ && !extractedBoundaryData_; }
 
  453      extractedElementData_ = 
true;
 
  454      return std::move(elementIndexToGmshPhysicalEntity_);
 
  461      extractedBoundaryData_ = 
true;
 
  462      return std::move(boundarySegmentIndexToGmshPhysicalEntity_);
 
  470          "This GmshReader has been constructed with a Dune::GridFactory. " 
  471          << 
"This grid factory has been filled with all information to create a grid. " 
  472          << 
"Please use this factory to create the grid by calling factory.createGrid(). " 
  473          << 
"Alternatively use the constructor without passing the factory in combination with this member function." 
  476      return gridFactory_->createGrid();
 
  482    void checkElementData ()
 const 
  484      if (!hasElementData_)
 
  486          "This GmshReader has been constructed without the option 'readElementData'. " 
  487          << 
"Please enable reading element data by passing the option 'Gmsh::ReaderOpts::readElementData' " 
  488          << 
"to the constructor of this class." 
  491      if (extractedElementData_)
 
  493          "The element data has already been extracted from this GmshReader " 
  494          << 
"via a function call to reader.extractElementData(). Use the extracted data or " 
  495          << 
"read the grid data from file again by constructing a new reader." 
  499    void checkBoundaryData ()
 const 
  501      if (!hasBoundaryData_)
 
  503          "This GmshReader has been constructed without the option 'readBoundaryData'. " 
  504          << 
"Please enable reading boundary data by passing the option 'Gmsh::ReaderOpts::readBoundaryData' " 
  505          << 
"to the constructor of this class." 
  508      if (extractedBoundaryData_)
 
  510          "The boundary data has already been extracted from this GmshReader " 
  511          << 
"via a function call to reader.extractBoundaryData(). Use the extracted data or " 
  512          << 
"read the grid data from file again by constructing a new reader." 
  516    void readGridFile (
const std::string& fileName, GridFactory<Grid>& factory, 
Gmsh::ReaderOptions options)
 
  518      if (Impl::Gmsh::fileVersion(fileName)[0]==4)
 
  520        Impl::Gmsh::Gmsh4Reader<Grid>::fillFactory(factory, fileName);
 
  524      const bool verbose = options & Opts::verbose;
 
  525      const bool insertBoundarySegments = options & Opts::insertBoundarySegments;
 
  526      const bool readBoundaryData = options & Opts::readBoundaryData;
 
  527      const bool readElementData = options & Opts::readElementData;
 
  530        factory, fileName, boundarySegmentIndexToGmshPhysicalEntity_,
 
  531        elementIndexToGmshPhysicalEntity_, verbose,
 
  532        readBoundaryData || insertBoundarySegments
 
  536      if (!readBoundaryData)
 
  537          boundarySegmentIndexToGmshPhysicalEntity_ = std::vector<int>{};
 
  538      if (!readElementData)
 
  539          elementIndexToGmshPhysicalEntity_ = std::vector<int>{};
 
  541      hasElementData_ = readElementData;
 
  542      hasBoundaryData_ = readBoundaryData;
 
  545    std::unique_ptr<Dune::GridFactory<Grid>> gridFactory_;
 
  547    std::vector<int> elementIndexToGmshPhysicalEntity_;
 
  548    std::vector<int> boundarySegmentIndexToGmshPhysicalEntity_;
 
  550    bool hasElementData_ = 
false;
 
  551    bool hasBoundaryData_ = 
false;
 
  554    bool extractedElementData_ = 
false;
 
  555    bool extractedBoundaryData_ = 
false;
 
int rank() const
Return rank, is between 0 and size()-1.
Definition: communication.hh:114
 
int barrier() const
Wait until all processes have arrived at this point in the program.
Definition: communication.hh:267
 
Read Gmsh mesh file.
Definition: gmshreader.hh:106
 
static std::unique_ptr< Grid > read(const std::string &fileName, std::vector< int > &boundarySegmentToPhysicalEntity, std::vector< int > &elementToPhysicalEntity, bool verbose=true, bool insertBoundarySegments=true)
Read Gmsh file, possibly with data.
Definition: gmshreader.hh:232
 
const std::vector< int > & elementData() const
Access element data (maps element index to Gmsh physical entity)
Definition: gmshreader.hh:422
 
static void read(Dune::GridFactory< Grid > &factory, const std::string &fileName, DataFlagArg boundarySegmentData, DataArg elementData, bool verbose=true)
read Gmsh file, possibly with data
Definition: gmshreader.hh:301
 
static std::unique_ptr< Grid > read(const std::string &fileName, bool verbose=true, bool insertBoundarySegments=true)
Definition: gmshreader.hh:199
 
static void read(Dune::GridFactory< Grid > &factory, const std::string &fileName, bool verbose=true, bool insertBoundarySegments=true)
Read Gmsh grid file into a GridFactory object.
Definition: gmshreader.hh:259
 
std::unique_ptr< Grid > createGrid()
Create the grid.
Definition: gmshreader.hh:466
 
std::vector< int > extractBoundaryData()
Erase boundary data from reader and return the data.
Definition: gmshreader.hh:458
 
static void read(Dune::GridFactory< Grid > &factory, const std::string &fileName, std::vector< int > &boundarySegmentToPhysicalEntity, std::vector< int > &elementToPhysicalEntity, bool verbose, bool insertBoundarySegments)
Read Gmsh file, possibly with data.
Definition: gmshreader.hh:348
 
bool hasElementData() const
If element data is available.
Definition: gmshreader.hh:439
 
bool hasBoundaryData() const
If boundary data is available.
Definition: gmshreader.hh:446
 
GmshReader(const std::string &fileName, GridFactory< Grid > &factory, Gmsh::ReaderOptions options=defaultOpts)
Construct a Gmsh reader object from a file name and a grid factory.
Definition: gmshreader.hh:415
 
GmshReader(const std::string &fileName, Gmsh::ReaderOptions options=defaultOpts)
Construct a Gmsh reader object (alternatively use one of the static member functions)
Definition: gmshreader.hh:400
 
std::vector< int > extractElementData()
Erase element data from reader and return the data.
Definition: gmshreader.hh:450
 
const std::vector< int > & boundaryData() const
Access boundary data (maps boundary segment index to Gmsh physical entity)
Definition: gmshreader.hh:429
 
Communication comm() const
Return the Communication used by the grid factory.
Definition: gridfactory.hh:258
 
Provide a generic factory class for unstructured grids.
Definition: gridfactory.hh:275
 
virtual std::unique_ptr< GridType > createGrid()
Finalize grid creation and hand over the grid.
Definition: gridfactory.hh:333
 
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:375
 
Provide a generic factory class for unstructured grids.
 
A few common exception classes.
 
#define DUNE_THROW(E,...)
Definition: exceptions.hh:314
 
ReaderOptions
Options for the Gmsh mesh file reader.
Definition: gmshreader.hh:52
 
Dune namespace.
Definition: alignedallocator.hh:13
 
Impl::Gmsh::Gmsh2Parser< GridType > GmshReaderParser
The GmshReaderParser class has been renamed and moved to the Impl::Gmsh namespace.
Definition: gmshreader.hh:86
 
Options for read operation.
Definition: gmshreader.hh:36
 
GeometryOrder
Definition: gmshreader.hh:37
 
@ firstOrder
edges are straight lines.
Definition: gmshreader.hh:39