/[escript]/branches/schroedinger/escript/src/DataAbstract.h
ViewVC logotype

Contents of /branches/schroedinger/escript/src/DataAbstract.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1935 - (show annotations)
Mon Oct 27 06:06:39 2008 UTC (11 years, 8 months ago) by jfenwick
File MIME type: text/plain
File size: 14060 byte(s)
Branch commit
More cleanup of DataTestCase - still don't have all the LazyTests in 
there yet.
Added tests to make sure the resolve() operation does what it is 
supposed to.
Added non-constant versions of getPointOffset to DataAbstract 
classes.
Fixed a bug in deepCopy on DataLazy.
Changed setToZero to not check the type of the data.

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2008 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
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 "DataTypes.h"
20 #include "FunctionSpace.h"
21
22 #include <boost/scoped_ptr.hpp>
23 #include <boost/python/numeric.hpp>
24
25 #include "DataException.h"
26
27 #include <string>
28 #include <fstream>
29
30 #include "Pointers.h"
31
32 namespace escript {
33
34 /**
35 \brief
36 DataAbstract provides an abstract interface for the class of containers
37 which hold ESyS data.
38
39 Description:
40 DataAbstract provides an abstract interface for the class of containers
41 which hold ESyS data. The container may be thought of as a 2 dimensional
42 array of data points where one dimension corresponds to the number of samples
43 and the other to the number of data points per sample as defined by the function
44 space associated with each Data object. The data points themselves are arrays of
45 doubles of rank 0-4.
46 */
47
48 class DataAbstract;
49
50 typedef POINTER_WRAPPER_CLASS(DataAbstract) DataAbstract_ptr;
51 typedef POINTER_WRAPPER_CLASS(const DataAbstract) const_DataAbstract_ptr;
52
53 class DataReady;
54
55 typedef POINTER_WRAPPER_CLASS(DataReady) DataReady_ptr;
56 typedef POINTER_WRAPPER_CLASS(const DataReady) const_DataReady_ptr;
57
58 class DataAbstract : public REFCOUNT_BASE_CLASS(DataAbstract)
59 {
60
61 public:
62
63 typedef DataTypes::ValueType ValueType;
64 typedef DataTypes::ShapeType ShapeType;
65
66 ESCRIPT_DLL_API
67 DataAbstract_ptr getPtr();
68 ESCRIPT_DLL_API
69 const_DataAbstract_ptr getPtr() const;
70
71 /**
72 \brief
73 Constructor for DataAbstract.
74
75 Description:
76 Constructor for DataAbstract.
77
78 \param what - Input - A description of what this data represents.
79 */
80 ESCRIPT_DLL_API
81 DataAbstract(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty=false);
82
83 /**
84 \brief
85 Destructor for DataAbstract.
86 */
87 ESCRIPT_DLL_API
88 virtual
89 ~DataAbstract();
90
91 /**
92 \brief
93 Write the data as a string.
94 */
95 ESCRIPT_DLL_API
96 virtual
97 std::string
98 toString() const = 0;
99
100 /**
101 \brief Return a deep copy of the current object.
102 */
103 ESCRIPT_DLL_API
104 virtual
105 DataAbstract*
106 deepCopy()=0;
107
108 /**
109 \brief Return a data object with all points resolved.
110 */
111 ESCRIPT_DLL_API
112 virtual
113 DataReady_ptr
114 resolve()=0;
115
116 /**
117 \brief
118 dumps the object into a netCDF file
119 */
120 ESCRIPT_DLL_API
121 virtual
122 void
123 dump(const std::string fileName) const;
124
125 /**
126 \brief
127 Return the number of data points per sample.
128 */
129 ESCRIPT_DLL_API
130 int
131 getNumDPPSample() const;
132
133 /**
134 \brief
135 Return the number of samples.
136 */
137 ESCRIPT_DLL_API
138 int
139 getNumSamples() const;
140
141 /**
142 \brief
143 Return the shape information for the point data.
144
145 The omission of a non-constant form is deliberate.
146 */
147 ESCRIPT_DLL_API
148 const DataTypes::ShapeType&
149 getShape() const;
150
151 /**
152 \brief
153 Return the rank information for the point data.
154 */
155 ESCRIPT_DLL_API
156 int
157 getRank() const;
158
159
160
161 /**
162 \brief
163 Return the offset for the given sample. This returns the offset for the given
164 point into the container holding the point data.
165
166 \param sampleNo - Input - sample number.
167 \param dataPointNo - Input - data point number.
168 */
169 ESCRIPT_DLL_API
170 virtual
171 ValueType::size_type
172 getPointOffset(int sampleNo,
173 int dataPointNo) const = 0;
174
175 ESCRIPT_DLL_API
176 virtual
177 ValueType::size_type
178 getPointOffset(int sampleNo,
179 int dataPointNo) = 0;
180
181 // /**
182 // return the container storing points for this object
183 // */
184 // ESCRIPT_DLL_API
185 // virtual
186 // ValueType&
187 // getVector();
188 //
189 // ESCRIPT_DLL_API
190 // virtual
191 // const ValueType&
192 // getVector() const;
193
194
195 // /**
196 // \brief
197 // Return the sample data for the given sample number.
198 // */
199 // ESCRIPT_DLL_API
200 // double*
201 // getSampleData(ValueType::size_type sampleNo);
202
203 /**
204 \brief
205 Return the number of doubles stored for this Data object.
206 */
207 ESCRIPT_DLL_API
208 virtual
209 ValueType::size_type
210 getLength() const = 0;
211
212 /**
213 \brief
214 Return the sample data for the given tag key.
215 NB: If the data isn't tagged an exception will be thrown.
216 */
217 ESCRIPT_DLL_API
218 virtual
219 double*
220 getSampleDataByTag(int tag);
221
222
223 /**
224 \brief
225 Check this and the given RHS operands are compatible. Throws
226 an exception if they aren't.
227
228 \param right - Input - The right hand side.
229 */
230 ESCRIPT_DLL_API
231 void
232 operandCheck(const DataAbstract& right) const;
233
234 /**
235 \brief
236 Return true if a valid sample point number.
237 */
238 ESCRIPT_DLL_API
239 bool
240 validSamplePointNo(int samplePointNo) const;
241
242 /**
243 \brief
244 Return true if a valid sample number.
245 */
246 ESCRIPT_DLL_API
247 bool
248 validSampleNo(int sampleNo) const;
249
250
251 /**
252 \brief
253 Return the function space associated with this Data object.
254 */
255 ESCRIPT_DLL_API
256 const
257 FunctionSpace&
258 getFunctionSpace() const;
259
260 /**
261 \brief
262 Return the given slice from this object.
263
264 NB: The caller is responsible for managing the object created.
265 */
266 ESCRIPT_DLL_API
267 virtual
268 DataAbstract*
269 getSlice(const DataTypes::RegionType& region) const = 0;
270
271 // /**
272 // \brief
273 // Copy the specified region from the given object.
274 //
275 // \param value - Input - Data to copy from
276 // \param region - Input - Region to copy.
277 // */
278 // ESCRIPT_DLL_API
279 // virtual
280 // void
281 // setSlice(const DataAbstract* value,
282 // const DataTypes::RegionType& region) = 0;
283
284 /**
285 \brief
286 setTaggedValue
287
288 Description:
289 Assign the given value to the given tag.
290
291 NB: If the data isn't tagged an exception will be thrown.
292
293 \param tagKey - Input - Integer key.
294 \param pointshape - Input - the shape of the value parameter.
295 \param value - Input -
296 */
297 ESCRIPT_DLL_API
298 virtual
299 void
300 setTaggedValue(int tagKey,
301 const DataTypes::ShapeType& pointshape,
302 const DataTypes::ValueType& value,
303 int dataOffset=0);
304
305
306
307
308 /**
309 \brief
310 Copy the numarray object to the data points in this object.
311
312 Description:
313 Copy the numarray object to the data points in this object.
314
315 \param value Input - new values for the data points
316 */
317 ESCRIPT_DLL_API
318 virtual void
319 copyAll(const boost::python::numeric::array& value);
320
321 /**
322 \brief
323 Copy a double value to the data point dataPointNo of sample sampleNo in this object.
324
325 Description:
326 Copy a double value to the data point dataPointNo of sample sampleNo in this object.
327
328 \param sampleNo Input - sample number
329 \param dataPointNo Input - data point of the sample
330 \param value Input - new values for the data point
331 */
332 ESCRIPT_DLL_API
333 virtual void
334 copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
335
336 /**
337 \brief
338 Copy the numarray object to the data point dataPointNo of sample sampleNo in this object.
339
340 Description:
341 Copy the numarray object to the data point dataPointNo of sample sampleNo in this object.
342
343 \param sampleNo Input - sample number
344 \param dataPointNo Input - data point of the sample
345 \param value Input - new values for the data point
346 */
347 ESCRIPT_DLL_API
348 virtual void
349 copyToDataPoint(const int sampleNo, const int dataPointNo, const boost::python::numeric::array& value);
350
351
352 /**
353 \brief
354 Return the tag number associated with the given data-point number.
355
356 If the object cannot be referenced by tag numbers, an exception
357 will be thrown.
358 */
359 ESCRIPT_DLL_API
360 virtual
361 int
362 getTagNumber(int dpno);
363
364 /**
365 \brief
366 Computes a symmetric matrix (A + AT) / 2
367
368 \param ev - Output - a symmetric matrix
369
370 */
371 ESCRIPT_DLL_API
372 virtual void
373 symmetric(DataAbstract* ev);
374
375 /**
376 \brief
377 Computes a nonsymmetric matrix (A - AT) / 2
378
379 \param ev - Output - a nonsymmetric matrix
380
381 */
382 ESCRIPT_DLL_API
383 virtual void
384 nonsymmetric(DataAbstract* ev);
385
386 /**
387 \brief
388 Computes the trace of a matrix
389
390 \param ev - Output - the trace of a matrix
391
392 */
393 ESCRIPT_DLL_API
394 virtual void
395 trace(DataAbstract* ev, int axis_offset);
396
397 /**
398 \brief
399 Transpose each data point of this Data object around the given axis.
400
401 \param ev - Output - the transpose of a matrix
402
403 */
404 ESCRIPT_DLL_API
405 virtual void
406 transpose(DataAbstract* ev, int axis_offset);
407
408 /**
409 \brief
410 swaps components axis0 and axis1
411
412 \param ev - Output - swapped components
413
414 */
415 ESCRIPT_DLL_API
416 virtual void
417 swapaxes(DataAbstract* ev, int axis0, int axis1);
418 /**
419 \brief
420 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
421
422 \param ev - Output - eigenvalues in increasing order at each data point
423
424 */
425 ESCRIPT_DLL_API
426 virtual void
427 eigenvalues(DataAbstract* ev);
428
429 /**
430 \brief
431 sets values to zero
432
433 */
434 ESCRIPT_DLL_API
435 virtual void
436 setToZero();
437
438 /**
439 \brief
440 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
441
442 \param ev - Output - eigenvalues in increasing order at each data point
443 \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
444 and the first nonzero component is positive.
445 \param tol - Input - eigenvalue with relative distance tol are treated as equal.
446
447 */
448
449 ESCRIPT_DLL_API
450 virtual void
451 eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
452
453 /**
454 \brief
455 reorders data sample ordered by reference_ids to the ordering of the functions space
456
457 \param reference_ids - Input - reference_ids used for current ordering
458 */
459 ESCRIPT_DLL_API
460 virtual void
461 reorderByReferenceIDs(int *reference_ids);
462
463
464
465 /**
466 \brief
467 Return the number of values in the shape for this object.
468 */
469 ESCRIPT_DLL_API
470 int
471 getNoValues() const;
472
473
474
475 // /**
476 // \brief get a reference to the beginning of a data point
477 // */
478 // ESCRIPT_DLL_API
479 // DataTypes::ValueType::const_reference
480 // getDataAtOffset(DataTypes::ValueType::size_type i) const;
481 //
482 //
483 // ESCRIPT_DLL_API
484 // DataTypes::ValueType::reference
485 // getDataAtOffset(DataTypes::ValueType::size_type i);
486
487
488 // /**
489 // \brief Provide access to underlying storage. Internal use only!
490 // */
491 // ESCRIPT_DLL_API
492 // virtual DataTypes::ValueType&
493 // getVector()=0;
494 //
495 // ESCRIPT_DLL_API
496 // virtual const DataTypes::ValueType&
497 // getVector() const=0;
498
499 bool isLazy() const; // a test to determine if this object is an instance of DataLazy
500
501 virtual
502 bool
503 isConstant() const {return false;}
504
505 virtual
506 bool
507 isExpanded() const {return false;}
508
509 virtual
510 bool
511 isTagged() const {return false;}
512
513
514 protected:
515
516 bool isEmpty() const; // a fast test to determine if this object is an instance of DataEmpty
517
518 private:
519
520 //
521 // The number of samples in this Data object.
522 // This is derived directly from the FunctionSpace.
523 int m_noSamples;
524
525 //
526 // The number of data points per sample in this Data object.
527 // This is derived directly from the FunctionSpace.
528 int m_noDataPointsPerSample;
529
530 //
531 // A FunctionSpace which provides a description of the data associated
532 // with this Data object.
533 FunctionSpace m_functionSpace;
534
535 //
536 // The shape of the points stored in this view
537 DataTypes::ShapeType m_shape;
538
539 //
540 // The number of values in each point
541 int m_novalues;
542
543 //
544 // The rank of the points stored in this view
545 int m_rank;
546
547 //
548 // Is this an instance of DataEmpty?
549 bool m_isempty;
550 };
551
552 inline
553 bool
554 DataAbstract::isEmpty() const
555 {
556 return m_isempty;
557 }
558
559 // inline
560 // DataTypes::ValueType::const_reference
561 // DataAbstract::getDataAtOffset(DataTypes::ValueType::size_type i) const
562 // {
563 // if (isLazy())
564 // {
565 // throw DataException("Programmer error - getDataAtOffset() not permitted on Lazy Data.");
566 // }
567 // DataReady* d;
568 // return (dynamic_cast<const DataReady*>(this))->getVector()[i];
569 // // return getVector()[i];
570 // }
571
572 // inline
573 // DataTypes::ValueType::reference
574 // DataAbstract::getDataAtOffset(DataTypes::ValueType::size_type i)
575 // {
576 // if (isLazy())
577 // {
578 // throw DataException("Programmer error - getDataAtOffset() not permitted on Lazy Data.");
579 // }
580 // return dynamic_cast<DataReady*>(this)->getVector()[i];
581 // // return getVector()[i];
582 // }
583
584
585 inline
586 bool
587 DataAbstract::validSamplePointNo(int samplePointNo) const
588 {
589 return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
590 }
591
592 inline
593 bool
594 DataAbstract::validSampleNo(int sampleNo) const
595 {
596 return ((0 <= sampleNo) && (sampleNo < m_noSamples));
597 }
598
599 inline
600 int
601 DataAbstract::getNumDPPSample() const
602 {
603 if (isEmpty())
604 {
605 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
606 }
607 return m_noDataPointsPerSample;
608 }
609
610 inline
611 int
612 DataAbstract::getNumSamples() const
613 {
614 if (isEmpty())
615 {
616 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
617 }
618 return m_noSamples;
619 }
620
621 inline
622 const
623 FunctionSpace&
624 DataAbstract::getFunctionSpace() const
625 {
626 return m_functionSpace;
627 }
628
629 inline
630 const DataTypes::ShapeType&
631 DataAbstract::getShape() const
632 {
633 if (isEmpty())
634 {
635 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
636 }
637 return m_shape;
638 }
639
640 inline
641 int
642 DataAbstract::getRank() const
643 {
644 if (isEmpty())
645 {
646 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
647 }
648 return m_rank;
649 }
650
651 inline
652 int
653 DataAbstract::getNoValues() const
654 {
655 if (isEmpty())
656 {
657 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
658 }
659 return m_novalues;
660 }
661
662
663 } // end of namespace
664
665 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26