3#ifndef DUNE_GRID_IO_FILE_GMSHWRITER_HH 
    4#define DUNE_GRID_IO_FILE_GMSHWRITER_HH 
   37  template <
class Gr
idView>
 
   45    static_assert( (dimWorld <= 3), 
"GmshWriter requires dimWorld <= 3." );
 
   52    size_t nodeIndexFromIterator(
const ElementIterator& eIt, 
int i)
 const {
 
   53      return gv.
indexSet().subIndex(*eIt, i, dim)+1;
 
   59    static size_t translateDuneToGmshType(
const GeometryType& type) {
 
   95    void outputElements(std::ofstream& file,
 
   96                        const std::vector<int>* physicalEntities = 
nullptr)
 const {
 
   98      ElementIterator eIt    = gv.template begin<0>();
 
   99      ElementIterator eEndIt = gv.template end<0>();
 
  101      for (
size_t i = 1; eIt != eEndIt; ++eIt, ++i) {
 
  104          size_t element_type = translateDuneToGmshType(eIt->type());
 
  106          file << i << 
" " << element_type;
 
  108          if (physicalEntities) {
 
  109            file << 
" " << 1 << 
" " << (*physicalEntities)[elementMapper.
index(*eIt)];
 
  116          if (3 == element_type)
 
  118                 << nodeIndexFromIterator(eIt, 0) << 
" " << nodeIndexFromIterator(eIt, 1) << 
" " 
  119                 << nodeIndexFromIterator(eIt, 3) << 
" " << nodeIndexFromIterator(eIt, 2);
 
  120          else if (5 == element_type)
 
  122                 << nodeIndexFromIterator(eIt, 0) << 
" " << nodeIndexFromIterator(eIt, 1) << 
" " 
  123                 << nodeIndexFromIterator(eIt, 3) << 
" " << nodeIndexFromIterator(eIt, 2) << 
" " 
  124                 << nodeIndexFromIterator(eIt, 4) << 
" " << nodeIndexFromIterator(eIt, 5) << 
" " 
  125                 << nodeIndexFromIterator(eIt, 7) << 
" " << nodeIndexFromIterator(eIt, 6);
 
  126          else if (7 == element_type)
 
  128                 << nodeIndexFromIterator(eIt, 0) << 
" " << nodeIndexFromIterator(eIt, 1) << 
" " 
  129                 << nodeIndexFromIterator(eIt, 3) << 
" " << nodeIndexFromIterator(eIt, 2) << 
" " 
  130                 << nodeIndexFromIterator(eIt, 4);
 
  132            for (
int k = 0; k < eIt->geometry().corners(); ++k)
 
  133              file << 
" " << nodeIndexFromIterator(eIt, k);
 
  152    void outputNodes(std::ofstream& file)
 const {
 
  153      VertexIterator vIt    = gv.template begin<dim>();
 
  154      VertexIterator vEndIt = gv.template end<dim>();
 
  156      for (; vIt != vEndIt; ++vIt) {
 
  157        typename VertexIterator::Entity::Geometry::GlobalCoordinate globalCoord = vIt->geometry().center();
 
  158        int nodeIndex = gv.
indexSet().index(*vIt)+1; 
 
  161          file << nodeIndex << 
" " << globalCoord[0] << 
" " << 0 << 
" " << 0 << std::endl;
 
  162        else if (2 == dimWorld)
 
  163          file << nodeIndex << 
" " << globalCoord[0] << 
" " << globalCoord[1] << 
" " << 0 << std::endl;
 
  165          file << nodeIndex << 
" " << globalCoord[0] << 
" " << globalCoord[1] << 
" " << globalCoord[2] << std::endl;
 
  183    void writeImpl(
const std::string& fileName, 
const std::vector<int>* physicalEntities = 
nullptr)
 const {
 
  184      std::ofstream file(fileName.c_str());
 
  190      file << 
"$MeshFormat" << std::endl
 
  191           << 
"2.0 0 " << 
sizeof(double) << std::endl 
 
  192           << 
"$EndMeshFormat" << std::endl;
 
  196      const size_t number_of_nodes = gv.
size(dim);
 
  197      file << 
"$Nodes" << std::endl
 
  198           << number_of_nodes << std::endl;
 
  202      file << 
"$EndNodes" << std::endl;
 
  206      const size_t number_of_elements = gv.
size(0);
 
  207      file << 
"$Elements" << std::endl
 
  208           << number_of_elements << std::endl;
 
  210      outputElements(file, physicalEntities);
 
  212      file << 
"$EndElements" << std::endl; 
 
  236    void write(
const std::string& fileName)
 const {
 
  255    void write(
const std::string& fileName, 
const std::vector<int>& physicalEntities)
 const {
 
  256      writeImpl(fileName, &physicalEntities);
 
Base class for Dune-Exceptions.
Definition: exceptions.hh:91
 
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
 
bool isPrism() const
Return true if entity is a prism.
Definition: type.hh:296
 
bool isLine() const
Return true if entity is a line segment.
Definition: type.hh:271
 
bool isPyramid() const
Return true if entity is a pyramid.
Definition: type.hh:291
 
bool isTetrahedron() const
Return true if entity is a tetrahedron.
Definition: type.hh:286
 
bool isVertex() const
Return true if entity is a vertex.
Definition: type.hh:266
 
bool isHexahedron() const
Return true if entity is a hexahedron.
Definition: type.hh:301
 
bool isQuadrilateral() const
Return true if entity is a quadrilateral.
Definition: type.hh:281
 
bool isTriangle() const
Return true if entity is a triangle.
Definition: type.hh:276
 
Write Gmsh mesh file.
Definition: gmshwriter.hh:39
 
void write(const std::string &fileName) const
Write given grid in Gmsh 2.0 compatible ASCII file.
Definition: gmshwriter.hh:236
 
void write(const std::string &fileName, const std::vector< int > &physicalEntities) const
Write given grid in Gmsh 2.0 compatible ASCII file.
Definition: gmshwriter.hh:255
 
GmshWriter(const GridView &gridView)
Constructor expecting GridView of Grid to be written.
Definition: gmshwriter.hh:223
 
Grid view abstract base class.
Definition: gridview.hh:59
 
Default exception class for I/O errors.
Definition: exceptions.hh:256
 
Implementation class for a multiple codim and multiple geometry type mapper.
Definition: mcmgmapper.hh:104
 
Index index(const EntityType &e) const
Map entity to array index.
Definition: mcmgmapper.hh:162
 
Different resources needed by all grid implementations.
 
A few common exception classes.
 
#define DUNE_THROW(E, m)
Definition: exceptions.hh:243
 
const IndexSet & indexSet() const
obtain the index set
Definition: gridview.hh:175
 
int size(int codim) const
obtain number of entities in a given codimension
Definition: gridview.hh:181
 
@ dimension
The dimension of the grid.
Definition: gridview.hh:130
 
@ dimensionworld
The dimension of the world the grid lives in.
Definition: gridview.hh:134
 
Mapper for multiple codim and multiple geometry types.
 
Dune namespace.
Definition: alignment.hh:10
 
Static tag representing a codimension.
Definition: dimension.hh:22
 
A unique label for each type of element that can occur in a grid.