dune-grid  2.9.0
parser.hh
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 // vi: set et ts=4 sw=2 sts=2:
5 #ifndef DUNE_DGF_DUNEGRIDFORMATPARSER_HH
6 #define DUNE_DGF_DUNEGRIDFORMATPARSER_HH
7 
8 #include <iostream>
9 #include <string>
10 #include <vector>
11 #include <map>
12 
14 
15 namespace Dune
16 {
17 
18  class DGFPrintInfo;
19 
23  {
25  typedef std::string type;
26 
28  static const type &defaultValue ()
29  {
30  static type value;
31  return value;
32  }
33 
35  static type convert ( const std::string & parameter )
36  {
37  return parameter;
38  }
39 
41  static const char delimiter = ':';
42  };
43 
47  {
48  public:
49  typedef enum {Simplex,Cube,General} element_t;
50 
52 
54  DuneGridFormatParser ( int rank, int size );
55 
66  static bool isDuneGridFormat ( std::istream &input );
67 
77  static bool isDuneGridFormat ( const std::string &filename );
78 
91  bool readDuneGrid( std::istream &input, int dimG, int dimW );
92 
94  void writeTetgenPoly ( const std::string &, std::string &, std::string & );
95 
96  void writeTetgenPoly ( std::ostream & out, const bool writeSegments = true );
97 
98  protected:
99  void generateBoundaries ( std::istream &, bool );
100 
101  // call to tetgen/triangle
102  void generateSimplexGrid ( std::istream & );
103  void readTetgenTriangle ( const std::string & );
104 
105  // helper methods
106  void removeCopies ();
107 
108  void setOrientation ( int use1, int use2,
109  orientation_t orientation=counterclockwise );
110 
111  void setRefinement ( int use1, int use2, int is1=-1, int is2=-1 );
112 
113  double testTriang ( int snr );
114 
115  std::vector< double > & getElParam ( int i, std::vector< double > & coord );
116 
117  std::vector< double > & getVtxParam ( int i, std::vector< double > & coord );
118 
119  static std::string temporaryFileName ();
120 
121  // dimension of world and problem: set through the readDuneGrid() method
122  int dimw, dimgrid;
123 
124  // vector of vertex coordinates
125  std::vector < std::vector < double > > vtx;
126 
127  int nofvtx;
128 
130 
131  double minVertexDistance; // min. L^1 distance of distinct points
132 
133  // vector of elements
134  std :: vector< std :: vector< unsigned int > > elements;
135 
137 
138  // vector of boundary segments + identifier
139  std::vector < std::vector < int > > bound;
140 
141  int nofbound;
142 
143  // map to generate and find boundary segments
145  typedef std::pair < int, BoundaryParameter > BndParam;
146  typedef std::map< DGFEntityKey< unsigned int >, BndParam > facemap_t;
148 
149  // true if parameters on a boundary found
151 
152  // set by generator depending on element type wanted
154 
155  // set by the readDuneGrid method depending
156  // on what type the elements were generated
158 
159  // true if grid is generated using the intervall Block
161 
162  // parameters on elements
164 
165  std::vector< std::vector< double > > vtxParams,elParams;
166 
167  // write information about generation process
169 
170  std::vector < double > emptyParam_;
171 
172 
173  private:
174  int rank_;
175  int size_;
176 
177  template< class GridType >
178  friend struct DGFGridFactory;
179 
180  template< class GridType >
181  friend struct DGFBaseFactory;
182 
183  };
184 
185 } // end namespace Dune
186 
187 #endif
Include standard header files.
Definition: agrid.hh:60
Definition: dgfgridfactory.hh:38
Definition: io/file/dgfparser/dgfparser.cc:26
Contains types for additional features.
Definition: parser.hh:23
static const char delimiter
delimiter
Definition: parser.hh:41
static const type & defaultValue()
default constructor
Definition: parser.hh:28
static type convert(const std::string &parameter)
copy from string
Definition: parser.hh:35
std::string type
type of additional boundary parameters
Definition: parser.hh:25
The DuneGridFormatParser class: reads a DGF file and stores build information in vector structures us...
Definition: parser.hh:47
int nofvtxparams
Definition: parser.hh:163
int nofbound
Definition: parser.hh:141
std::pair< int, BoundaryParameter > BndParam
Definition: parser.hh:145
void readTetgenTriangle(const std::string &)
Definition: io/file/dgfparser/dgfparser.cc:795
static bool isDuneGridFormat(std::istream &input)
check whether a stream is in DUNE grid format
Definition: io/file/dgfparser/dgfparser.cc:271
void setOrientation(int use1, int use2, orientation_t orientation=counterclockwise)
Definition: io/file/dgfparser/dgfparser.cc:910
std::vector< std::vector< double > > vtxParams
Definition: parser.hh:165
void setRefinement(int use1, int use2, int is1=-1, int is2=-1)
Definition: io/file/dgfparser/dgfparser.cc:989
friend struct DGFBaseFactory
Definition: parser.hh:181
static std::string temporaryFileName()
Definition: io/file/dgfparser/dgfparser.cc:1096
DuneGridFormatParser(int rank, int size)
constructor
Definition: io/file/dgfparser/dgfparser.cc:97
void removeCopies()
Definition: io/file/dgfparser/dgfparser.cc:464
int dimw
Definition: parser.hh:122
int dimgrid
Definition: parser.hh:122
element_t element
Definition: parser.hh:153
DGFBoundaryParameter::type BoundaryParameter
Definition: parser.hh:144
int nofelements
Definition: parser.hh:136
orientation_t
Definition: parser.hh:51
@ clockwise
Definition: parser.hh:51
@ counterclockwise
Definition: parser.hh:51
double testTriang(int snr)
Definition: io/file/dgfparser/dgfparser.cc:1050
double minVertexDistance
Definition: parser.hh:131
bool simplexgrid
Definition: parser.hh:157
std::map< DGFEntityKey< unsigned int >, BndParam > facemap_t
Definition: parser.hh:146
std::vector< std::vector< int > > bound
Definition: parser.hh:139
void generateSimplexGrid(std::istream &)
Definition: io/file/dgfparser/dgfparser.cc:624
std::vector< double > emptyParam_
Definition: parser.hh:170
int nofelparams
Definition: parser.hh:163
std::vector< std::vector< double > > elParams
Definition: parser.hh:165
facemap_t facemap
Definition: parser.hh:147
element_t
Definition: parser.hh:49
@ General
Definition: parser.hh:49
@ Cube
Definition: parser.hh:49
@ Simplex
Definition: parser.hh:49
bool cube2simplex
Definition: parser.hh:160
int nofvtx
Definition: parser.hh:127
void writeTetgenPoly(const std::string &, std::string &, std::string &)
method to write in Tetgen/Triangle Poly Format
Definition: io/file/dgfparser/dgfparser.cc:123
std::vector< std::vector< double > > vtx
Definition: parser.hh:125
int vtxoffset
Definition: parser.hh:129
bool readDuneGrid(std::istream &input, int dimG, int dimW)
parse dune grid format from stream
Definition: io/file/dgfparser/dgfparser.cc:298
std ::vector< std ::vector< unsigned int > > elements
Definition: parser.hh:134
bool haveBndParameters
Definition: parser.hh:150
DGFPrintInfo * info
Definition: parser.hh:168
void generateBoundaries(std::istream &, bool)
Definition: io/file/dgfparser/dgfparser.cc:502
std::vector< double > & getVtxParam(int i, std::vector< double > &coord)
Definition: io/file/dgfparser/dgfparser.cc:1086
std::vector< double > & getElParam(int i, std::vector< double > &coord)
Definition: io/file/dgfparser/dgfparser.cc:1070