/[escript]/trunk/escript/src/DataAbstract.h
ViewVC logotype

Contents of /trunk/escript/src/DataAbstract.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 950 - (show annotations)
Tue Feb 6 07:01:11 2007 UTC (12 years, 8 months ago) by gross
File MIME type: text/plain
File size: 13089 byte(s)
escript data objects can now be saved to netCDF files, see http://www.unidata.ucar.edu/software/netcdf/.
Currently only constant data are implemented with expanded and tagged data to follow.
There are two new functions to dump a data object

   s=Data(...)
   s.dump(<filename>)

and to recover it

   s=load(<filename>, domain)

Notice that the function space of s is recovered but domain is still need. 

dump and load will replace archive and extract.

The installation needs now the netCDF installed. 


1 // $Id$
2 /*
3 ************************************************************
4 * Copyright 2006 by ACcESS MNRF *
5 * *
6 * http://www.access.edu.au *
7 * Primary Business: Queensland, Australia *
8 * Licensed under the Open Software License version 3.0 *
9 * http://www.opensource.org/licenses/osl-3.0.php *
10 * *
11 ************************************************************
12
13 */
14
15 #if !defined escript_DataAbstract_20040315_H
16 #define escript_DataAbstract_20040315_H
17 #include "system_dep.h"
18
19 #include "DataArrayView.h"
20 #include "DataArray.h"
21 #include "FunctionSpace.h"
22
23 #include <boost/scoped_ptr.hpp>
24 #include <boost/python/numeric.hpp>
25
26 #include <string>
27 #include <fstream>
28
29 namespace escript {
30
31 /**
32 \brief
33 DataAbstract provides an abstract interface for the class of containers
34 which hold ESyS data.
35
36 Description:
37 DataAbstract provides an abstract interface for the class of containers
38 which hold ESyS data. The container may be thought of as a 2 dimensional
39 array of data points where one dimension corresponds to the number of samples
40 and the other to the number of data points per sample as defined by the function
41 space associated with each Data object. The data points themselves are arrays of
42 doubles of rank 0-4.
43 */
44
45 class DataAbstract {
46
47 public:
48
49 typedef DataArrayView::ValueType ValueType;
50 typedef DataArrayView::ShapeType ShapeType;
51
52 /**
53 \brief
54 Constructor for DataAbstract.
55
56 Description:
57 Constructor for DataAbstract.
58
59 \param what - Input - A description of what this data represents.
60 */
61 ESCRIPT_DLL_API
62 DataAbstract(const FunctionSpace& what);
63
64 /**
65 \brief
66 Destructor for DataAbstract.
67 */
68 ESCRIPT_DLL_API
69 virtual
70 ~DataAbstract();
71
72 /**
73 \brief
74 Write the data as a string.
75 */
76 ESCRIPT_DLL_API
77 virtual
78 std::string
79 toString() const = 0;
80
81 /**
82 \brief
83 dumps the object into a netCDF file
84 */
85 ESCRIPT_DLL_API
86 virtual
87 void
88 dump(const std::string fileName) const;
89
90 /**
91 \brief
92 Return the number of data points per sample.
93 */
94 ESCRIPT_DLL_API
95 int
96 getNumDPPSample() const;
97
98 /**
99 \brief
100 Return the number of samples.
101 */
102 ESCRIPT_DLL_API
103 int
104 getNumSamples() const;
105
106 /**
107 \brief
108 Return the DataArrayView of the point data. This essentially contains
109 the shape information for each data point although it also may be used
110 to manipulate the point data.
111 */
112 ESCRIPT_DLL_API
113 DataArrayView&
114 getPointDataView();
115
116 ESCRIPT_DLL_API
117 const DataArrayView&
118 getPointDataView() const;
119
120 /**
121 \brief
122 Return the offset for the given sample. This returns the offset for the given
123 point into the container holding the point data. Only really necessary to
124 avoid creating many DataArrayView objects.
125
126 \param sampleNo - Input - sample number.
127 \param dataPointNo - Input - data point number.
128 */
129 ESCRIPT_DLL_API
130 virtual
131 ValueType::size_type
132 getPointOffset(int sampleNo,
133 int dataPointNo) const = 0;
134
135 /**
136 \brief
137 Return the sample data for the given sample number.
138 */
139 ESCRIPT_DLL_API
140 double*
141 getSampleData(ValueType::size_type sampleNo);
142
143 /**
144 \brief
145 Return the number of doubles stored for this Data object.
146 */
147 ESCRIPT_DLL_API
148 virtual
149 ValueType::size_type
150 getLength() const = 0;
151
152 /**
153 \brief
154 Return the sample data for the given tag key.
155 NB: If the data isn't tagged an exception will be thrown.
156 */
157 ESCRIPT_DLL_API
158 virtual
159 double*
160 getSampleDataByTag(int tag);
161
162 /**
163 \brief
164 Assign the given value to the data-points(s) referenced by the given
165 reference number.
166
167 If this Data object cannot be accessed by reference numbers an
168 exception will be thrown.
169
170 \param ref - Input - reference number.
171 \param value - Input - value to assign to data-points associated with
172 the given reference number.
173 */
174 ESCRIPT_DLL_API
175 virtual
176 void
177 setValueByReferenceNumber(int ref,
178 const DataArray& value);
179
180 /**
181 \brief
182 Return the values associated with the data-point(s) referenced by the given
183 reference number.
184
185 If this Data object cannot be accessed by reference numbers an
186 exception will be thrown.
187
188 \param ref - Input - reference number.
189 \param value - Output - object to receive data-points associated with
190 the given reference number.
191 */
192 ESCRIPT_DLL_API
193 virtual
194 void
195 getValueByReferenceNumber(int ref,
196 DataArray& value);
197
198 /**
199 \brief
200 Check this and the given RHS operands are compatible. Throws
201 an exception if they aren't.
202
203 \param right - Input - The right hand side.
204 */
205 ESCRIPT_DLL_API
206 void
207 operandCheck(const DataAbstract& right) const;
208
209 /**
210 \brief
211 Return true if a valid sample point number.
212 */
213 ESCRIPT_DLL_API
214 bool
215 validSamplePointNo(int samplePointNo) const;
216
217 /**
218 \brief
219 Return true if a valid sample number.
220 */
221 ESCRIPT_DLL_API
222 bool
223 validSampleNo(int sampleNo) const;
224
225 /**
226 \brief
227 Return a view into the data for the data point specified.
228 NOTE: Construction of the DataArrayView is a relatively expensive
229 operation.
230
231 \param sampleNo - Input - the sample number.
232 \param dataPointNo - Input - the data point number.
233 */
234 ESCRIPT_DLL_API
235 virtual
236 DataArrayView
237 getDataPoint(int sampleNo,
238 int dataPointNo) = 0;
239
240 /**
241 \brief
242 Return the function space associated with this Data object.
243 */
244 ESCRIPT_DLL_API
245 const
246 FunctionSpace&
247 getFunctionSpace() const;
248
249 /**
250 \brief
251 Return the given slice from this object.
252
253 NB: The caller is responsible for managing the object created.
254 */
255 ESCRIPT_DLL_API
256 virtual
257 DataAbstract*
258 getSlice(const DataArrayView::RegionType& region) const = 0;
259
260 /**
261 \brief
262 Copy the specified region from the given object.
263
264 \param value - Input - Data to copy from
265 \param region - Input - Region to copy.
266 */
267 ESCRIPT_DLL_API
268 virtual
269 void
270 setSlice(const DataAbstract* value,
271 const DataArrayView::RegionType& region) = 0;
272
273
274 /**
275 \brief
276 setTaggedValue
277
278 Description:
279 Assign the given value to the given tag.
280
281 NB: If the data isn't tagged an exception will be thrown.
282
283 \param tagKey - Input - Integer key.
284 \param value - Input - Single DataArrayView value to be assigned to the tag.
285 */
286 ESCRIPT_DLL_API
287 virtual
288 void
289 setTaggedValue(int tagKey,
290 const DataArrayView& value);
291
292 /**
293 \brief
294 Archive the underlying data values to the file referenced
295 by ofstream. A count of the number of values expected to be written
296 is provided as a cross-check.
297
298 The return value indicates success (0) or otherwise (1).
299 */
300 ESCRIPT_DLL_API
301 virtual
302 int
303 archiveData(std::ofstream& archiveFile,
304 const ValueType::size_type noValues) const;
305
306 /**
307 \brief
308 Extract the number of values specified by noValues from the file
309 referenced by ifstream to the underlying data structure.
310
311 The return value indicates success (0) or otherwise (1).
312 */
313 ESCRIPT_DLL_API
314 virtual
315 int
316 extractData(std::ifstream& archiveFile,
317 const ValueType::size_type noValues);
318
319 /**
320 \brief
321 Copy the numarray object to the data points in this object.
322
323 Description:
324 Copy the numarray object to the data points in this object.
325
326 \param value Input - new values for the data points
327 */
328 ESCRIPT_DLL_API
329 virtual void
330 copyAll(const boost::python::numeric::array& value);
331
332 /**
333 \brief
334 Copy a double value to the data point dataPointNo of sample sampleNo in this object.
335
336 Description:
337 Copy a double value to the data point dataPointNo of sample sampleNo in this object.
338
339 \param sampleNo Input - sample number
340 \param dataPointNo Input - data point of the sample
341 \param value Input - new values for the data point
342 */
343 ESCRIPT_DLL_API
344 virtual void
345 copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
346
347 /**
348 \brief
349 Copy the numarray object to the data point dataPointNo of sample sampleNo in this object.
350
351 Description:
352 Copy the numarray object to the data point dataPointNo of sample sampleNo in this object.
353
354 \param sampleNo Input - sample number
355 \param dataPointNo Input - data point of the sample
356 \param value Input - new values for the data point
357 */
358 ESCRIPT_DLL_API
359 virtual void
360 copyToDataPoint(const int sampleNo, const int dataPointNo, const boost::python::numeric::array& value);
361
362
363 /**
364 \brief
365 Return the tag number associated with the given data-point number.
366
367 If the object cannot be referenced by tag numbers, an exception
368 will be thrown.
369 */
370 ESCRIPT_DLL_API
371 virtual
372 int
373 getTagNumber(int dpno);
374
375 /**
376 \brief
377 Computes a symmetric matrix (A + AT) / 2
378
379 \param ev - Output - a symmetric matrix
380
381 */
382 ESCRIPT_DLL_API
383 virtual void
384 symmetric(DataAbstract* ev);
385
386 /**
387 \brief
388 Computes a nonsymmetric matrix (A - AT) / 2
389
390 \param ev - Output - a nonsymmetric matrix
391
392 */
393 ESCRIPT_DLL_API
394 virtual void
395 nonsymmetric(DataAbstract* ev);
396
397 /**
398 \brief
399 Computes the trace of a matrix
400
401 \param ev - Output - the trace of a matrix
402
403 */
404 ESCRIPT_DLL_API
405 virtual void
406 trace(DataAbstract* ev, int axis_offset);
407
408 /**
409 \brief
410 Transpose each data point of this Data object around the given axis.
411
412 \param ev - Output - the transpose of a matrix
413
414 */
415 ESCRIPT_DLL_API
416 virtual void
417 transpose(DataAbstract* ev, int axis_offset);
418
419 /**
420 \brief
421 swaps components axis0 and axis1
422
423 \param ev - Output - swapped components
424
425 */
426 ESCRIPT_DLL_API
427 virtual void
428 swapaxes(DataAbstract* ev, int axis0, int axis1);
429 /**
430 \brief
431 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
432
433 \param ev - Output - eigenvalues in increasing order at each data point
434
435 */
436 ESCRIPT_DLL_API
437 virtual void
438 eigenvalues(DataAbstract* ev);
439
440 /**
441 \brief
442 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
443
444 \param ev - Output - eigenvalues in increasing order at each data point
445 \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
446 and the first nonzero component is positive.
447 \param tol - Input - eigenvalue with relative distance tol are treated as equal.
448
449 */
450
451 ESCRIPT_DLL_API
452 virtual void
453 eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
454
455 protected:
456
457 /**
458 \brief
459 Set the pointDataView DataArrayView associated with this object.
460
461 \param input - Input - The point data view. DataAbstract takes ownership
462 of the DataArrayView provided. It will delete it when it is destructed.
463 */
464 ESCRIPT_DLL_API
465 void
466 setPointDataView(const DataArrayView& input);
467
468 ESCRIPT_DLL_API
469 void
470 resetPointDataView();
471
472 private:
473
474 //
475 // The number of samples in this Data object.
476 // This is derived directly from the FunctionSpace.
477 int m_noSamples;
478
479 //
480 // The number of data points per sample in this Data object.
481 // This is derived directly from the FunctionSpace.
482 int m_noDataPointsPerSample;
483
484 //
485 // The DataArrayView of the data array associated with this object.
486 // The data array is defined only in child classes of this class, it
487 // is not defined in this abstract parent class.
488 boost::scoped_ptr<DataArrayView> m_pointDataView;
489
490 //
491 // A FunctionSpace which provides a description of the data associated
492 // with this Data object.
493 FunctionSpace m_functionSpace;
494
495 };
496
497 inline
498 bool
499 DataAbstract::validSamplePointNo(int samplePointNo) const
500 {
501 return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
502 }
503
504 inline
505 bool
506 DataAbstract::validSampleNo(int sampleNo) const
507 {
508 return ((0 <= sampleNo) && (sampleNo < m_noSamples));
509 }
510
511 inline
512 DataAbstract::ValueType::value_type*
513 DataAbstract::getSampleData(ValueType::size_type sampleNo)
514 {
515 return &(m_pointDataView->getData(getPointOffset(sampleNo,0)));
516 }
517
518 inline
519 int
520 DataAbstract::getNumDPPSample() const
521 {
522 return m_noDataPointsPerSample;
523 }
524
525 inline
526 int
527 DataAbstract::getNumSamples() const
528 {
529 return m_noSamples;
530 }
531
532 inline
533 const
534 FunctionSpace&
535 DataAbstract::getFunctionSpace() const
536 {
537 return m_functionSpace;
538 }
539
540 inline
541 const
542 DataArrayView&
543 DataAbstract::getPointDataView() const
544 {
545 return *(m_pointDataView.get());
546 }
547
548 inline
549 DataArrayView&
550 DataAbstract::getPointDataView()
551 {
552 return *(m_pointDataView.get());
553 }
554 } // end of namespace
555
556 #endif

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26