~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to src/kernel/io/XMLBLASFormData.cpp

  • Committer: Johannes Ring
  • Date: 2008-03-05 22:43:06 UTC
  • Revision ID: johannr@simula.no-20080305224306-2npsdyhfdpl2esji
The BIG commit!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright (C) 2005-2006 Anders Logg.
2
 
// Licensed under the GNU LGPL Version 2.1.
3
 
//
4
 
// First added:  2005-10-02
5
 
// Last changed: 2006-05-23
6
 
 
7
 
#include <dolfin/dolfin_log.h>
8
 
//#include <dolfin/BLASFormData.h>
9
 
#include <dolfin/XMLBLASFormData.h>
10
 
 
11
 
using namespace dolfin;
12
 
 
13
 
//-----------------------------------------------------------------------------
14
 
XMLBLASFormData::XMLBLASFormData(BLASFormData& blas) :
15
 
  XMLObject(), blas(blas), mi(0), ni(0), mb(0), nb(0), state(OUTSIDE)
16
 
{
17
 
  // Do nothing
18
 
}
19
 
//-----------------------------------------------------------------------------
20
 
void XMLBLASFormData::startElement(const xmlChar *name, const xmlChar **attrs)
21
 
{
22
 
  //dolfin_debug1("Found start of element \"%s\"", (const char *) name);
23
 
 
24
 
  switch ( state )
25
 
  {
26
 
  case OUTSIDE:
27
 
    
28
 
    if ( xmlStrcasecmp(name,(xmlChar *) "form") == 0 )
29
 
    {
30
 
      readForm(name, attrs);
31
 
      state = INSIDE_FORM;
32
 
    }
33
 
    
34
 
    break;
35
 
 
36
 
  case INSIDE_FORM:
37
 
    
38
 
    if ( xmlStrcasecmp(name,(xmlChar *) "interior") == 0 )
39
 
    {
40
 
      readInterior(name, attrs);
41
 
      state = INSIDE_INTERIOR;
42
 
    }
43
 
    else if ( xmlStrcasecmp(name,(xmlChar *) "boundary") == 0 )
44
 
    {
45
 
      readBoundary(name, attrs);
46
 
      state = INSIDE_BOUNDARY;
47
 
    }
48
 
    
49
 
    break;
50
 
    
51
 
  case INSIDE_INTERIOR:
52
 
    
53
 
    if ( xmlStrcasecmp(name,(xmlChar *) "term") == 0 )
54
 
    {
55
 
      readTerm(name,attrs);
56
 
      state = INSIDE_INTERIOR_TERM;
57
 
    }
58
 
 
59
 
    break;
60
 
 
61
 
  case INSIDE_BOUNDARY:
62
 
    
63
 
    if ( xmlStrcasecmp(name,(xmlChar *) "term") == 0 )
64
 
    {
65
 
      readTerm(name,attrs);
66
 
      state = INSIDE_BOUNDARY_TERM;
67
 
    }
68
 
    
69
 
    break;
70
 
    
71
 
  case INSIDE_INTERIOR_TERM:
72
 
 
73
 
    if ( xmlStrcasecmp(name,(xmlChar *) "geometrytensor") == 0 )
74
 
    {
75
 
      readGeoTensor(name, attrs);
76
 
      state = INSIDE_INTERIOR_GEOTENSOR;
77
 
    }
78
 
    else if ( xmlStrcasecmp(name,(xmlChar *) "referencetensor") == 0 )
79
 
    {
80
 
      readRefTensor(name, attrs);
81
 
      state = INSIDE_INTERIOR_REFTENSOR;
82
 
    }
83
 
 
84
 
    break;
85
 
 
86
 
  case INSIDE_BOUNDARY_TERM:
87
 
    
88
 
    if ( xmlStrcasecmp(name,(xmlChar *) "referencetensor") == 0 )
89
 
    {
90
 
      readRefTensor(name, attrs);
91
 
      state = INSIDE_BOUNDARY_REFTENSOR;
92
 
    }
93
 
 
94
 
    break;
95
 
 
96
 
  case INSIDE_INTERIOR_GEOTENSOR:
97
 
    break;
98
 
 
99
 
  case INSIDE_BOUNDARY_GEOTENSOR:
100
 
    break;
101
 
 
102
 
  case INSIDE_INTERIOR_REFTENSOR:
103
 
    
104
 
    if ( xmlStrcasecmp(name,(xmlChar *) "entry") == 0 )
105
 
    {
106
 
      readEntry(name, attrs);
107
 
    }
108
 
 
109
 
    break;
110
 
 
111
 
  case INSIDE_BOUNDARY_REFTENSOR:
112
 
    
113
 
    if ( xmlStrcasecmp(name,(xmlChar *) "entry") == 0 )
114
 
    {
115
 
      readEntry(name, attrs);
116
 
    }
117
 
 
118
 
    break;
119
 
   
120
 
  default:
121
 
    ;
122
 
  }
123
 
  
124
 
}
125
 
//-----------------------------------------------------------------------------
126
 
void XMLBLASFormData::endElement(const xmlChar *name)
127
 
{
128
 
  //dolfin_debug1("Found end of element \"%s\"", (const char *) name);
129
 
 
130
 
  switch ( state )
131
 
  {
132
 
  case INSIDE_FORM:
133
 
    
134
 
    if ( xmlStrcasecmp(name,(xmlChar *) "form") == 0 )
135
 
    {
136
 
      initForm();
137
 
      data_interior.clear();
138
 
      data_interior.clear();
139
 
      state = DONE;
140
 
    }
141
 
    
142
 
    break;
143
 
    
144
 
  case INSIDE_INTERIOR:
145
 
    
146
 
    if ( xmlStrcasecmp(name,(xmlChar *) "interior") == 0 )
147
 
      state = INSIDE_FORM;
148
 
    
149
 
    break;
150
 
 
151
 
  case INSIDE_BOUNDARY:
152
 
    
153
 
    if ( xmlStrcasecmp(name,(xmlChar *) "boundary") == 0 )
154
 
      state = INSIDE_FORM;
155
 
    
156
 
    break;
157
 
 
158
 
  case INSIDE_INTERIOR_TERM:
159
 
    
160
 
    if ( xmlStrcasecmp(name,(xmlChar *) "term") == 0 )
161
 
      state = INSIDE_INTERIOR;
162
 
    
163
 
    break;
164
 
 
165
 
  case INSIDE_BOUNDARY_TERM:
166
 
    
167
 
    if ( xmlStrcasecmp(name,(xmlChar *) "term") == 0 )
168
 
      state = INSIDE_BOUNDARY;
169
 
    
170
 
    break;
171
 
 
172
 
  case INSIDE_INTERIOR_GEOTENSOR:
173
 
         
174
 
    if ( xmlStrcasecmp(name,(xmlChar *) "geometrytensor") == 0 )
175
 
      state = INSIDE_INTERIOR_TERM;
176
 
    
177
 
    break;
178
 
 
179
 
  case INSIDE_BOUNDARY_GEOTENSOR:
180
 
         
181
 
    if ( xmlStrcasecmp(name,(xmlChar *) "geometrytensor") == 0 )
182
 
      state = INSIDE_BOUNDARY_TERM;
183
 
    
184
 
    break;
185
 
    
186
 
  case INSIDE_INTERIOR_REFTENSOR:
187
 
         
188
 
    if ( xmlStrcasecmp(name,(xmlChar *) "referencetensor") == 0 )
189
 
      state = INSIDE_INTERIOR_TERM;
190
 
    
191
 
    break;
192
 
 
193
 
  case INSIDE_BOUNDARY_REFTENSOR:
194
 
         
195
 
    if ( xmlStrcasecmp(name,(xmlChar *) "referencetensor") == 0 )
196
 
      state = INSIDE_BOUNDARY_TERM;
197
 
    
198
 
    break;
199
 
    
200
 
  default:
201
 
    ;
202
 
  }
203
 
  
204
 
}
205
 
//-----------------------------------------------------------------------------
206
 
void XMLBLASFormData::open(std::string filename)
207
 
{
208
 
  message(1, "Reading form data from file \"%s\".", filename.c_str());
209
 
}
210
 
//-----------------------------------------------------------------------------
211
 
bool XMLBLASFormData::close()
212
 
{
213
 
  return true;
214
 
}
215
 
//-----------------------------------------------------------------------------
216
 
void XMLBLASFormData::readForm(const xmlChar *name, const xmlChar **attrs)
217
 
{
218
 
  // Reset data
219
 
  data_interior.clear();
220
 
  data_boundary.clear();
221
 
}
222
 
//-----------------------------------------------------------------------------
223
 
void XMLBLASFormData::readInterior(const xmlChar *name, const xmlChar **attrs)
224
 
{
225
 
  // Do nothing
226
 
}
227
 
//-----------------------------------------------------------------------------
228
 
void XMLBLASFormData::readBoundary(const xmlChar *name, const xmlChar **attrs)
229
 
{
230
 
  // Do nothing
231
 
}
232
 
//-----------------------------------------------------------------------------
233
 
void XMLBLASFormData::readTerm(const xmlChar *name, const xmlChar **attrs)
234
 
{
235
 
  Array<real> tensor;
236
 
 
237
 
  // Add new term and read number of rows
238
 
  switch ( state )
239
 
  {
240
 
  case INSIDE_INTERIOR:
241
 
    data_interior.push_back(tensor);
242
 
    mi = parseInt(name, attrs, "size");
243
 
    break;
244
 
  case INSIDE_BOUNDARY:
245
 
    data_boundary.push_back(tensor);
246
 
    mb = parseInt(name, attrs, "size");
247
 
    break;
248
 
  default:
249
 
    cout << state << endl;
250
 
    error("Inconsistent state while reading XML form data.");
251
 
  }
252
 
 
253
 
}
254
 
//-----------------------------------------------------------------------------
255
 
void XMLBLASFormData::readGeoTensor(const xmlChar *name, const xmlChar **attrs)
256
 
{
257
 
  // Read number of columns
258
 
  switch ( state )
259
 
  {
260
 
  case INSIDE_INTERIOR_TERM:
261
 
    ni = parseInt(name, attrs, "size");
262
 
    break;
263
 
  case INSIDE_BOUNDARY_TERM:
264
 
    nb = parseInt(name, attrs, "size");
265
 
    break;
266
 
  default:
267
 
    error("Inconsistent state while reading XML form data.");
268
 
  }
269
 
}
270
 
//-----------------------------------------------------------------------------
271
 
void XMLBLASFormData::readRefTensor(const xmlChar *name, const xmlChar **attrs)
272
 
{
273
 
  // Do nothing
274
 
}
275
 
//-----------------------------------------------------------------------------
276
 
void XMLBLASFormData::readEntry(const xmlChar *name, const xmlChar **attrs)
277
 
{
278
 
  // Read value
279
 
  real value = parseReal(name, attrs, "value");
280
 
 
281
 
  // Append value to tensor
282
 
  switch ( state )
283
 
  {
284
 
  case INSIDE_INTERIOR_REFTENSOR:
285
 
    data_interior.back().push_back(value);
286
 
    break;
287
 
  case INSIDE_BOUNDARY_REFTENSOR:
288
 
    data_boundary.back().push_back(value);
289
 
    break;
290
 
  default:
291
 
    error("Inconsistent state while reading XML data.");
292
 
  }
293
 
}
294
 
//-----------------------------------------------------------------------------
295
 
void XMLBLASFormData::initForm()
296
 
{
297
 
  error("XMLBLASFormData not implemented for new UFC strcuture.");
298
 
/*
299
 
  // Give data to form
300
 
  blas.init(mi, ni, data_interior, mb, nb, data_boundary);
301
 
*/
302
 
}
303
 
//-----------------------------------------------------------------------------