1
// Copyright (C) 2005-2006 Anders Logg.
2
// Licensed under the GNU LGPL Version 2.1.
4
// First added: 2005-10-02
5
// Last changed: 2006-05-23
7
#include <dolfin/dolfin_log.h>
8
//#include <dolfin/BLASFormData.h>
9
#include <dolfin/XMLBLASFormData.h>
11
using namespace dolfin;
13
//-----------------------------------------------------------------------------
14
XMLBLASFormData::XMLBLASFormData(BLASFormData& blas) :
15
XMLObject(), blas(blas), mi(0), ni(0), mb(0), nb(0), state(OUTSIDE)
19
//-----------------------------------------------------------------------------
20
void XMLBLASFormData::startElement(const xmlChar *name, const xmlChar **attrs)
22
//dolfin_debug1("Found start of element \"%s\"", (const char *) name);
28
if ( xmlStrcasecmp(name,(xmlChar *) "form") == 0 )
30
readForm(name, attrs);
38
if ( xmlStrcasecmp(name,(xmlChar *) "interior") == 0 )
40
readInterior(name, attrs);
41
state = INSIDE_INTERIOR;
43
else if ( xmlStrcasecmp(name,(xmlChar *) "boundary") == 0 )
45
readBoundary(name, attrs);
46
state = INSIDE_BOUNDARY;
53
if ( xmlStrcasecmp(name,(xmlChar *) "term") == 0 )
56
state = INSIDE_INTERIOR_TERM;
63
if ( xmlStrcasecmp(name,(xmlChar *) "term") == 0 )
66
state = INSIDE_BOUNDARY_TERM;
71
case INSIDE_INTERIOR_TERM:
73
if ( xmlStrcasecmp(name,(xmlChar *) "geometrytensor") == 0 )
75
readGeoTensor(name, attrs);
76
state = INSIDE_INTERIOR_GEOTENSOR;
78
else if ( xmlStrcasecmp(name,(xmlChar *) "referencetensor") == 0 )
80
readRefTensor(name, attrs);
81
state = INSIDE_INTERIOR_REFTENSOR;
86
case INSIDE_BOUNDARY_TERM:
88
if ( xmlStrcasecmp(name,(xmlChar *) "referencetensor") == 0 )
90
readRefTensor(name, attrs);
91
state = INSIDE_BOUNDARY_REFTENSOR;
96
case INSIDE_INTERIOR_GEOTENSOR:
99
case INSIDE_BOUNDARY_GEOTENSOR:
102
case INSIDE_INTERIOR_REFTENSOR:
104
if ( xmlStrcasecmp(name,(xmlChar *) "entry") == 0 )
106
readEntry(name, attrs);
111
case INSIDE_BOUNDARY_REFTENSOR:
113
if ( xmlStrcasecmp(name,(xmlChar *) "entry") == 0 )
115
readEntry(name, attrs);
125
//-----------------------------------------------------------------------------
126
void XMLBLASFormData::endElement(const xmlChar *name)
128
//dolfin_debug1("Found end of element \"%s\"", (const char *) name);
134
if ( xmlStrcasecmp(name,(xmlChar *) "form") == 0 )
137
data_interior.clear();
138
data_interior.clear();
144
case INSIDE_INTERIOR:
146
if ( xmlStrcasecmp(name,(xmlChar *) "interior") == 0 )
151
case INSIDE_BOUNDARY:
153
if ( xmlStrcasecmp(name,(xmlChar *) "boundary") == 0 )
158
case INSIDE_INTERIOR_TERM:
160
if ( xmlStrcasecmp(name,(xmlChar *) "term") == 0 )
161
state = INSIDE_INTERIOR;
165
case INSIDE_BOUNDARY_TERM:
167
if ( xmlStrcasecmp(name,(xmlChar *) "term") == 0 )
168
state = INSIDE_BOUNDARY;
172
case INSIDE_INTERIOR_GEOTENSOR:
174
if ( xmlStrcasecmp(name,(xmlChar *) "geometrytensor") == 0 )
175
state = INSIDE_INTERIOR_TERM;
179
case INSIDE_BOUNDARY_GEOTENSOR:
181
if ( xmlStrcasecmp(name,(xmlChar *) "geometrytensor") == 0 )
182
state = INSIDE_BOUNDARY_TERM;
186
case INSIDE_INTERIOR_REFTENSOR:
188
if ( xmlStrcasecmp(name,(xmlChar *) "referencetensor") == 0 )
189
state = INSIDE_INTERIOR_TERM;
193
case INSIDE_BOUNDARY_REFTENSOR:
195
if ( xmlStrcasecmp(name,(xmlChar *) "referencetensor") == 0 )
196
state = INSIDE_BOUNDARY_TERM;
205
//-----------------------------------------------------------------------------
206
void XMLBLASFormData::open(std::string filename)
208
message(1, "Reading form data from file \"%s\".", filename.c_str());
210
//-----------------------------------------------------------------------------
211
bool XMLBLASFormData::close()
215
//-----------------------------------------------------------------------------
216
void XMLBLASFormData::readForm(const xmlChar *name, const xmlChar **attrs)
219
data_interior.clear();
220
data_boundary.clear();
222
//-----------------------------------------------------------------------------
223
void XMLBLASFormData::readInterior(const xmlChar *name, const xmlChar **attrs)
227
//-----------------------------------------------------------------------------
228
void XMLBLASFormData::readBoundary(const xmlChar *name, const xmlChar **attrs)
232
//-----------------------------------------------------------------------------
233
void XMLBLASFormData::readTerm(const xmlChar *name, const xmlChar **attrs)
237
// Add new term and read number of rows
240
case INSIDE_INTERIOR:
241
data_interior.push_back(tensor);
242
mi = parseInt(name, attrs, "size");
244
case INSIDE_BOUNDARY:
245
data_boundary.push_back(tensor);
246
mb = parseInt(name, attrs, "size");
249
cout << state << endl;
250
error("Inconsistent state while reading XML form data.");
254
//-----------------------------------------------------------------------------
255
void XMLBLASFormData::readGeoTensor(const xmlChar *name, const xmlChar **attrs)
257
// Read number of columns
260
case INSIDE_INTERIOR_TERM:
261
ni = parseInt(name, attrs, "size");
263
case INSIDE_BOUNDARY_TERM:
264
nb = parseInt(name, attrs, "size");
267
error("Inconsistent state while reading XML form data.");
270
//-----------------------------------------------------------------------------
271
void XMLBLASFormData::readRefTensor(const xmlChar *name, const xmlChar **attrs)
275
//-----------------------------------------------------------------------------
276
void XMLBLASFormData::readEntry(const xmlChar *name, const xmlChar **attrs)
279
real value = parseReal(name, attrs, "value");
281
// Append value to tensor
284
case INSIDE_INTERIOR_REFTENSOR:
285
data_interior.back().push_back(value);
287
case INSIDE_BOUNDARY_REFTENSOR:
288
data_boundary.back().push_back(value);
291
error("Inconsistent state while reading XML data.");
294
//-----------------------------------------------------------------------------
295
void XMLBLASFormData::initForm()
297
error("XMLBLASFormData not implemented for new UFC strcuture.");
300
blas.init(mi, ni, data_interior, mb, nb, data_boundary);
303
//-----------------------------------------------------------------------------