1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2020 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
19
20 #ifndef LIBMESH_TETGEN_IO_H
21 #define LIBMESH_TETGEN_IO_H
22
23 // Local includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/mesh_input.h"
26 #include "libmesh/mesh_output.h"
27
28 // C++ includes
29 #include <cstddef>
30 #include <map>
31
32 namespace libMesh
33 {
34
35 // Forward declarations
36 class MeshBase;
37
38
39 /**
40 * This class implements reading and writing meshes in the TetGen format.
41 * Format description:
42 * cf. <a href="http://tetgen.berlios.de/">TetGen home page</a>.
43 *
44 * \author Benjamin S. Kirk
45 * \date 2004
46 */
47 class TetGenIO : public MeshInput<MeshBase>,
48 public MeshOutput<MeshBase>
49 {
50 public:
51
52 /**
53 * Constructor. Takes a writable reference to a mesh object.
54 * This is the constructor required to read a mesh.
55 */
56 explicit
57 TetGenIO (MeshBase & mesh);
58
59 /**
60 * Constructor. Takes a read-only reference to a mesh object.
61 * This is the constructor required to write a mesh.
62 */
63 explicit
64 TetGenIO (const MeshBase & mesh);
65
66 /**
67 * This method implements reading a mesh from a specified file
68 * in TetGen format.
69 */
70 virtual void read (const std::string &) override;
71
72 /**
73 * This method implements writing a mesh to a specified ".poly" file.
74 * ".poly" files defines so called Piecewise Linear Complex (PLC).
75 */
76 virtual void write (const std::string &) override;
77
78 /**
79 * Data structure to hold node attributes read in from file.
80 * What you do with these is up to you!
81 */
82 std::vector<std::vector<Real>> node_attributes;
83
84 private:
85
86
87 //-------------------------------------------------------------
88 // read support methods
89
90 /**
91 * Reads a mesh (nodes & elements) from the file
92 * provided through \p node_stream and ele_stream.
93 */
94 void read_nodes_and_elem (std::istream & node_stream,
95 std::istream & ele_stream);
96
97 /**
98 * Method reads nodes from \p node_stream and stores them in
99 * vector<Node *> \p nodes in the order they come in.
100 * The original node labels are being stored in the
101 * map \p _assign_nodes in order to assign the elements to
102 * the right nodes later.
103 */
104 void node_in (std::istream & node_stream);
105
106 /**
107 * Method reads elements and stores them in
108 * vector<Elem *> \p elements in the same order as they
109 * come in. Within \p TetGenMeshInterface, element labels are
110 * ignored.
111 */
112 void element_in (std::istream & ele_stream);
113
114 //-------------------------------------------------------------
115 // local data
116
117 /**
118 * stores new positions of nodes. Used when reading.
119 */
120 std::map<dof_id_type,dof_id_type> _assign_nodes;
121
122 /**
123 * total number of nodes. Primarily used when reading.
124 */
125 dof_id_type _num_nodes;
126
127 /**
128 * total number of elements. Primarily used when reading.
129 */
130 dof_id_type _num_elements;
131 };
132
133
134
135 // ------------------------------------------------------------
136 // TetGenIO inline members
137 inline
TetGenIO(MeshBase & mesh)138 TetGenIO::TetGenIO (MeshBase & mesh) :
139 MeshInput<MeshBase> (mesh),
140 MeshOutput<MeshBase>(mesh)
141 {
142 }
143
144
145
146 inline
TetGenIO(const MeshBase & mesh)147 TetGenIO::TetGenIO (const MeshBase & mesh) :
148 MeshOutput<MeshBase>(mesh)
149 {
150 }
151
152
153 } // namespace libMesh
154
155
156 #endif // LIBMESH_TETGEN_IO_H
157