1
// Copyright (C) 2003-2006 Anders Logg.
1
// Copyright (C) 2003-2008 Anders Logg.
2
2
// Licensed under the GNU LGPL Version 2.1.
4
4
// First added: 2003-10-21
5
// Last changed: 2006-06-22
5
// Last changed: 2008-05-21
7
7
#include <dolfin/log/dolfin_log.h>
8
8
#include <dolfin/mesh/CellType.h>
13
13
using namespace dolfin;
15
15
//-----------------------------------------------------------------------------
16
XMLMesh::XMLMesh(Mesh& mesh) : XMLObject(), _mesh(mesh), state(OUTSIDE), f(0)
16
XMLMesh::XMLMesh(Mesh& mesh) : XMLObject(), _mesh(mesh), state(OUTSIDE), f(0), a(0)
42
44
if ( xmlStrcasecmp(name, (xmlChar *) "vertices") == 0 )
46
cout << "Reading vertices" << endl;
44
48
readVertices(name, attrs);
45
49
state = INSIDE_VERTICES;
47
51
else if ( xmlStrcasecmp(name, (xmlChar *) "cells") == 0 )
53
cout << "Reading cells" << endl;
49
55
readCells(name, attrs);
50
56
state = INSIDE_CELLS;
52
58
else if ( xmlStrcasecmp(name, (xmlChar *) "data") == 0 )
60
cout << "Reading data" << endl;
53
61
state = INSIDE_DATA;
57
66
case INSIDE_VERTICES:
77
86
if ( xmlStrcasecmp(name, (xmlChar *) "meshfunction") == 0 )
88
cout << "Reading mesh function" << endl;
79
89
readMeshFunction(name, attrs);
80
90
state = INSIDE_MESH_FUNCTION;
92
if ( xmlStrcasecmp(name, (xmlChar *) "array") == 0 )
94
cout << "Reading array" << endl;
95
readArray(name, attrs);
85
101
case INSIDE_MESH_FUNCTION:
87
103
if ( xmlStrcasecmp(name, (xmlChar *) "entity") == 0 )
88
readEntity(name, attrs);
104
readMeshEntity(name, attrs);
110
if ( xmlStrcasecmp(name, (xmlChar *) "element") == 0 )
111
readArrayElement(name, attrs);
111
135
case INSIDE_VERTICES:
113
137
if ( xmlStrcasecmp(name, (xmlChar *) "vertices") == 0 )
140
cout << "End vertices" << endl;
118
145
case INSIDE_CELLS:
120
147
if ( xmlStrcasecmp(name, (xmlChar *) "cells") == 0 )
121
149
state = INSIDE_MESH;
150
cout << "End cells" << endl;
125
155
case INSIDE_DATA:
127
157
if ( xmlStrcasecmp(name, (xmlChar *) "data") == 0 )
128
159
state = INSIDE_MESH;
160
cout << "End data" << endl;
132
165
case INSIDE_MESH_FUNCTION:
134
167
if ( xmlStrcasecmp(name, (xmlChar *) "meshfunction") == 0 )
170
cout << "End mesh function" << endl;
177
if ( xmlStrcasecmp(name, (xmlChar *) "array") == 0 )
180
cout << "End array" << endl;
275
321
const std::string id = parseString(name, attrs, "name");
276
322
const std::string type = parseString(name, attrs, "type");
277
const uint dim = parseUnsignedInt(name, attrs, "dim");
278
const uint size = parseUnsignedInt(name, attrs, "size");
323
const uint dim = parseUnsignedInt(name, attrs, "dim");
324
const uint size = parseUnsignedInt(name, attrs, "size");
280
326
// Only uint supported at this point
281
327
if (strcmp(type.c_str(), "uint") != 0)
282
328
error("Only uint-valued mesh data is currently supported.");
332
if (_mesh.size(dim) != size)
333
error("Wrong number of values for MeshFunction, expecting %d.", _mesh.size(dim));
285
f = _mesh.data().create(id, dim);
336
f = _mesh.data().createMeshFunction(id, dim);
287
339
// Set all values to zero
291
if (size >= f->size())
292
error("Wrong size of mesh data \"%s\", at most \"%d\" values may be specified.",
293
id.c_str(), f->size());
342
void XMLMesh::readArray(const xmlChar* name, const xmlChar** attrs)
345
const std::string id = parseString(name, attrs, "name");
346
const std::string type = parseString(name, attrs, "type");
347
const uint size = parseUnsignedInt(name, attrs, "size");
349
// Only uint supported at this point
350
if (strcmp(type.c_str(), "uint") != 0)
351
error("Only uint-valued mesh data is currently supported.");
354
a = _mesh.data().createArray(id, size);
295
357
//-----------------------------------------------------------------------------
296
void XMLMesh::readEntity(const xmlChar* name, const xmlChar** attrs)
358
void XMLMesh::readMeshEntity(const xmlChar* name, const xmlChar** attrs)
299
361
const uint index = parseUnsignedInt(name, attrs, "index");
305
367
f->set(index, value);
307
369
//-----------------------------------------------------------------------------
370
void XMLMesh::readArrayElement(const xmlChar* name, const xmlChar** attrs)
375
const uint index = parseUnsignedInt(name, attrs, "index");
377
// Read and set value
379
dolfin_assert(index < a->size());
380
const uint value = parseUnsignedInt(name, attrs, "value");
383
//-----------------------------------------------------------------------------
308
384
void XMLMesh::closeMesh()