123
//-----------------------------------------------------------------------------
124
void XMLMesh::reading(std::string filename)
126
cout << "Reading mesh from file \"" << filename << "\"." << endl;
128
//-----------------------------------------------------------------------------
131
//cout << "Reading mesh: " << mesh << endl;
109
//-----------------------------------------------------------------------------
110
void XMLMesh::open(std::string filename)
112
cout << "Reading mesh from file " << filename << "." << endl;
114
//-----------------------------------------------------------------------------
115
bool XMLMesh::close()
117
return state == DONE;
133
119
//-----------------------------------------------------------------------------
134
120
void XMLMesh::readMesh(const xmlChar *name, const xmlChar **attrs)
123
std::string type = parseString(name, attrs, "celltype");
124
uint gdim = parseUnsignedInt(name, attrs, "dim");
126
// Create cell type to get topological dimension
127
CellType* cell_type = CellType::create(type);
128
uint tdim = cell_type->dim();
131
// Open mesh for editing
132
editor.open(_mesh, CellType::string2type(type), tdim, gdim);
138
134
//-----------------------------------------------------------------------------
139
135
void XMLMesh::readVertices(const xmlChar *name, const xmlChar **attrs)
141
// Set default values
145
parseIntegerRequired(name, attrs, "size", size);
138
uint num_vertices = parseUnsignedInt(name, attrs, "size");
140
// Set number of vertices
141
editor.initVertices(num_vertices);
150
143
//-----------------------------------------------------------------------------
151
144
void XMLMesh::readCells(const xmlChar *name, const xmlChar **attrs)
153
// Set default values
157
parseIntegerRequired(name, attrs, "size", size);
147
uint num_cells = parseUnsignedInt(name, attrs, "size");
149
// Set number of vertices
150
editor.initCells(num_cells);
162
152
//-----------------------------------------------------------------------------
163
153
void XMLMesh::readVertex(const xmlChar *name, const xmlChar **attrs)
165
// Set default values
156
uint v = parseUnsignedInt(name, attrs, "index");
172
parseIntegerRequired(name, attrs, "name", id);
173
parseRealRequired(name, attrs, "x", x);
174
parseRealRequired(name, attrs, "y", y);
175
parseRealRequired(name, attrs, "z", z);
178
Vertex &newvertex = mesh.createVertex(x, y, z);
181
// FIXME: id of vertex is completely ignored. We assume that the
182
// vertices are in correct order.
158
// Handle differently depending on geometric dimension
159
switch ( _mesh.geometry().dim() )
163
real x = parseReal(name, attrs, "x");
164
editor.addVertex(v, x);
169
real x = parseReal(name, attrs, "x");
170
real y = parseReal(name, attrs, "y");
171
editor.addVertex(v, x, y);
176
real x = parseReal(name, attrs, "x");
177
real y = parseReal(name, attrs, "y");
178
real z = parseReal(name, attrs, "z");
179
editor.addVertex(v, x, y, z);
183
dolfin_error("Dimension of mesh must be 1, 2 or 3.");
184
186
//-----------------------------------------------------------------------------
185
void XMLMesh::readBoundaryID(const xmlChar *name, const xmlChar **attrs)
187
void XMLMesh::readInterval(const xmlChar *name, const xmlChar **attrs)
187
// Set default values
190
if ( _mesh.topology().dim() != 1 )
191
dolfin_error1("Mesh entity (interval) does not match dimension of mesh (%d).",
192
_mesh.topology().dim());
195
uint c = parseUnsignedInt(name, attrs, "index");
196
uint v0 = parseUnsignedInt(name, attrs, "v0");
197
uint v1 = parseUnsignedInt(name, attrs, "v1");
191
parseIntegerRequired(name, attrs, "name", id);
193
// Add Boundary ID to vertex
194
vertex->nbids.insert(id);
196
// FIXME: id of vertex is completely ignored. We assume that the
197
// vertices are in correct order.
200
editor.addCell(c, v0, v1);
199
202
//-----------------------------------------------------------------------------
200
203
void XMLMesh::readTriangle(const xmlChar *name, const xmlChar **attrs)
202
// Set default values
206
if ( _mesh.topology().dim() != 2 )
207
dolfin_error1("Mesh entity (triangle) does not match dimension of mesh (%d).",
208
_mesh.topology().dim());
211
uint c = parseUnsignedInt(name, attrs, "index");
212
uint v0 = parseUnsignedInt(name, attrs, "v0");
213
uint v1 = parseUnsignedInt(name, attrs, "v1");
214
uint v2 = parseUnsignedInt(name, attrs, "v2");
209
parseIntegerRequired(name, attrs, "name", id);
210
parseIntegerRequired(name, attrs, "n0", n0);
211
parseIntegerRequired(name, attrs, "n1", n1);
212
parseIntegerRequired(name, attrs, "n2", n2);
215
mesh.createCell(n0, n1, n2);
217
// FIXME: id of cell is completely ignored. We assume that the
218
// cells are in correct order.
217
editor.addCell(c, v0, v1, v2);
220
219
//-----------------------------------------------------------------------------
221
220
void XMLMesh::readTetrahedron(const xmlChar *name, const xmlChar **attrs)
223
// Set default values
223
if ( _mesh.topology().dim() != 3 )
224
dolfin_error1("Mesh entity (tetrahedron) does not match dimension of mesh (%d).",
225
_mesh.topology().dim());
228
uint c = parseUnsignedInt(name, attrs, "index");
229
uint v0 = parseUnsignedInt(name, attrs, "v0");
230
uint v1 = parseUnsignedInt(name, attrs, "v1");
231
uint v2 = parseUnsignedInt(name, attrs, "v2");
232
uint v3 = parseUnsignedInt(name, attrs, "v3");
231
parseIntegerRequired(name, attrs, "name", id);
232
parseIntegerRequired(name, attrs, "n0", n0);
233
parseIntegerRequired(name, attrs, "n1", n1);
234
parseIntegerRequired(name, attrs, "n2", n2);
235
parseIntegerRequired(name, attrs, "n3", n3);
238
mesh.createCell(n0, n1, n2, n3);
240
// FIXME: id of cell is completely ignored. We assume that the
241
// cells are in correct order.
235
editor.addCell(c, v0, v1, v2, v3);
243
237
//-----------------------------------------------------------------------------
244
void XMLMesh::initMesh()
238
void XMLMesh::closeMesh()
246
// Compute connections
249
242
//-----------------------------------------------------------------------------