meshImport3D.hh

Go to the documentation of this file.
1 
8 #ifndef meshImport3D_hh
9 #define meshImport3D_hh
10 
11 #include <vector>
12 #include <map>
13 #include "toolbox/hashMap.hh"
14 #include "mesh.hh"
15 #include "toolbox/array.hh"
16 
17 namespace concepts {
23  struct Index {
33  void sort_();
34 
35  Index(const uint n0);
36  Index(const uint n0, const uint n1);
38  Index(const uint n0, const uint n1, const uint n2);
40  Index(const uint n0, const uint n1, const uint n2, const uint n3);
42  Index(const Index& i) : n_(i.n_) {}
44  uint size() const { return n_.size(); }
46  uint operator[](const uint i) const { return n_[i]; }
48  uint& operator[](const uint i) { return n_[i]; }
50  bool operator<(const concepts::Index& y) const;
52  bool operator==(const concepts::Index& y) const;
53  };
54 }
55 
56 namespace std {
58  size_t hash_value(const concepts::Index& i);
59 
61  template<>
62  struct hash<concepts::Index> {
64  size_t operator()(const concepts::Index& x) const {
65  return hash_value(x); }
66  };
67 
69  struct IndexEqual {
70  bool operator()(const concepts::Index& x, const concepts::Index& y) const {
71  return x == y;
72  }
73  };
74 } // namespace std
75 
76 namespace concepts {
77 
78  // ********************************************************** Import3dMesh **
79 
94  class Import3dMesh : public Mesh3 {
95  public:
136  Import3dMesh(const std::string coord, const std::string elms,
137  const std::string boundary, const uint idxStart = 1,
138  const bool leftHand = false, const uint elmtyp = 0);
139  virtual ~Import3dMesh();
140  virtual uint ncell() const { return cell_.size(); }
141  virtual Scan3* scan() { return new S(cell_); }
142 
143  class NodeCell;
144  class NodeTetrahedron;
145  class NodeHexahedron;
146  protected:
147  virtual std::ostream& info(std::ostream& os) const;
148  private:
150  class S : public Scan<Cell3> {
151  public:
152  inline S(std::vector<Cell3*>& cell) :
153  idx_(cell.begin()), cell_(cell) {}
154  inline S(const S& scan) : idx_(scan.idx_), cell_(scan.cell_) {}
155  inline bool eos() const { return idx_ == cell_.end(); }
156  inline Cell3& operator++(int) { return *(*idx_++); }
157  inline Scan3* clone() const { return new S(*this); }
158  private:
159  std::vector<Cell3*>::iterator idx_;
160  std::vector<Cell3*>& cell_;
161  };
163  std::vector<Vertex*> vtx_;
165  std::vector<Edge*> edg_;
167  std::unordered_map<Index, Triangle*, std::hash<Index>,
170  std::unordered_map<Index, Quad*, std::hash<Index>,
173  std::vector<Cell3*> cell_;
174 
178  uint readInts_(const std::string& i, std::vector<int>& v) const;
179 
181  void clear_(std::vector<NodeCell*>& cells) const;
182 
193  void createEdge_(uint ix, uint iy,
194  std::map<uint, std::map<uint, Edge*> >& edges,
195  Attribute attr = 0, Edge** e = 0);
204  std::map<uint, std::map<uint, Edge*> >& edges,
205  Attribute attr = 0);
213  Quad* createQuad_(const Index& I,
214  std::map<uint, std::map<uint, Edge*> >& edges,
215  Attribute attr = 0);
216  };
217 
222  protected:
225  public:
230  NodeCell(const uint size) : nodes_(size) {}
231  virtual ~NodeCell();
233  uint operator[](const uint i) const { return nodes_[i]; }
235  uint size() const { return nodes_.size(); }
236 
238  virtual uint nofaces() const = 0;
240  virtual Index faceIndex(const uint i) = 0;
242  virtual Quad** quad(const uint i) = 0;
244  virtual Triangle** triangle(const uint i) = 0;
246  virtual Cell3* cell(const std::vector<Real3d>& vertices) const = 0;
247  };
248 
253  private:
256  public:
260  NodeTetrahedron(const uint one, const uint two, const uint three,
261  const uint four, const bool leftHand = false);
262  virtual ~NodeTetrahedron();
263  virtual uint nofaces() const { return 4; }
264  virtual Index faceIndex(const uint i);
265  virtual Tetrahedron3d* cell(const std::vector<Real3d>& vertices) const;
266  virtual Quad** quad(const uint i) { return 0; }
267  virtual Triangle** triangle(const uint i) { return &(faces_[i]); }
268  };
269 
274  private:
278  uint elmType_;
279  public:
283  NodeHexahedron(const uint one, const uint two, const uint three,
284  const uint four, const uint five, const uint six,
285  const uint seven, const uint eight, const uint elmType = 0);
286  virtual ~NodeHexahedron();
287  virtual uint nofaces() const { return 6; }
288  virtual Index faceIndex(const uint i);
289  virtual Cell3* cell(const std::vector<Real3d>& vertices) const;
290  virtual Quad** quad(const uint i) { return &(faces_[i]); }
291  virtual Triangle** triangle(const uint i) { return 0; }
292  };
293 
294 } // namespace concepts
295 
296 #endif // meshImport3D_hh
Stores the nodes and edges of a cell to be created.
uint size() const
Returns the requested size of the array.
Definition: array.hh:259
size_t hash_value(const concepts::Index &i)
Computes a hash for i.
std::vector< Cell3 * > cell_
List of cells.
virtual Tetrahedron3d * cell(const std::vector< Real3d > &vertices) const
Creates and returns the cell.
std::unordered_map< Index, Quad *, std::hash< Index >, std::IndexEqual > quad_
List of quads.
Stores the nodes and faces of a hexahedral cell to be created.
Index(const uint n0, const uint n1, const uint n2)
Constructor for use in a triangle.
virtual Scan3 * scan()
Returns a scanner over the cells of the mesh.
std::unordered_map< Index, Triangle *, std::hash< Index >, std::IndexEqual > tri_
List of triangles.
virtual Index faceIndex(const uint i)
Returns the indices of the nodes which define the face i.
Stores a number of indices in a ordered fashion.
Definition: meshImport3D.hh:23
virtual Index faceIndex(const uint i)
Returns the indices of the nodes which define the face i.
A scanner for a 3D mesh.
Definition: mesh.hh:52
Array< uint > nodes_
Node numbers of the cell.
A quadrilateral in the topology.
Definition: topology.hh:272
An abstract class for 3D meshes.
Definition: mesh.hh:112
std::vector< Edge * > edg_
List of edges.
Index(const Index &i)
Copy constructor.
Definition: meshImport3D.hh:42
Three dimensional cell.
Definition: cell.hh:112
uint operator[](const uint i) const
Returns the node with index i.
std::vector< Cell3 * > & cell_
virtual Quad ** quad(const uint i)=0
Returns the face with index i.
virtual uint nofaces() const =0
Returns the number of faces.
void createEdge_(uint ix, uint iy, std::map< uint, std::map< uint, Edge * > > &edges, Attribute attr=0, Edge **e=0)
Creates the edge with vertices ix and iy using edges as repository.
void clear_(std::vector< NodeCell * > &cells) const
Deletes the content of cells.
bool operator==(const concepts::Index &y) const
== operator
S(std::vector< Cell3 * > &cell)
virtual Cell3 * cell(const std::vector< Real3d > &vertices) const
Creates and returns the cell.
NodeCell(const uint size)
Constructor.
void sort_()
Sorts the data somewhat.
uint size() const
Returns the number of nodes.
virtual Triangle ** triangle(const uint i)
Returns the face with index i.
Key equal function class.
Definition: meshImport3D.hh:69
Scanner class for Import3dMesh.
Cell3 & operator++(int)
Returns the next cell.
virtual Cell3 * cell(const std::vector< Real3d > &vertices) const =0
Creates and returns the cell.
Import3dMesh(const std::string coord, const std::string elms, const std::string boundary, const uint idxStart=1, const bool leftHand=false, const uint elmtyp=0)
Constructor.
size_t operator()(const concepts::Index &x) const
Computes the hash function value for x.
Definition: meshImport3D.hh:64
NodeHexahedron(const uint one, const uint two, const uint three, const uint four, const uint five, const uint six, const uint seven, const uint eight, const uint elmType=0)
Constructor.
uint readInts_(const std::string &i, std::vector< int > &v) const
Reads integers from the string.
Quad * createQuad_(const Index &I, std::map< uint, std::map< uint, Edge * > > &edges, Attribute attr=0)
Creates a quad.
An abstract class for scanning a mesh (a set of cells) or a space (a set of elements).
Index(const uint n0)
Array< uint > n_
Stores the data.
Definition: meshImport3D.hh:25
Triangle * createTriangle_(const Index &I, std::map< uint, std::map< uint, Edge * > > &edges, Attribute attr=0)
Creates a triangle.
NodeTetrahedron(const uint one, const uint two, const uint three, const uint four, const bool leftHand=false)
Constructor.
virtual uint nofaces() const
Returns the number of faces.
Array< Quad * > faces_
Faces of the cell.
Array< Triangle * > faces_
Faces of the cell.
std::vector< Cell3 * >::iterator idx_
A 3D cell: tetrahedron.
Definition: cell3D.hh:47
std::vector< Vertex * > vtx_
List of vertices.
Imports 3D mesh with tetrahedra and hexahedra.
Definition: meshImport3D.hh:94
virtual Triangle ** triangle(const uint i)
Returns the face with index i.
Index(const uint n0, const uint n1)
Index(const uint n0, const uint n1, const uint n2, const uint n3)
Constructor for use in a quad.
virtual Index faceIndex(const uint i)=0
Returns the indices of the nodes which define the face i.
uint size() const
Returns number of entries in n_.
Definition: meshImport3D.hh:44
bool operator<(const concepts::Index &y) const
< operator for
uint & operator[](const uint i)
Returns the ith entry of n_.
Definition: meshImport3D.hh:48
uint elmType_
Type of element to construct.
uint operator[](const uint i) const
Returns the ith entry of n_.
Definition: meshImport3D.hh:46
An edge in the topology.
Definition: topology.hh:73
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
A triangle in the topology.
Definition: topology.hh:193
virtual Quad ** quad(const uint i)
Returns the face with index i.
virtual Quad ** quad(const uint i)
Returns the face with index i.
Stores the nodes and faces of a tetrahedral cell to be created.
bool operator()(const concepts::Index &x, const concepts::Index &y) const
Definition: meshImport3D.hh:70
Attributes for elements of the topology.
Definition: connector.hh:22
virtual Triangle ** triangle(const uint i)=0
Returns the face with index i.
virtual uint ncell() const
Returns the number of cells in the mesh.
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
virtual uint nofaces() const
Returns the number of faces.
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich