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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2005 - (show annotations)
Mon Nov 10 01:21:39 2008 UTC (11 years ago) by jfenwick
File MIME type: text/plain
File size: 14151 byte(s)
Bringing all changes across from schroedinger.
(Note this does not mean development is done, just that it will happen
on the trunk for now).
If anyone notices any problems please contact me.


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 unsigned 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 unsigned 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 ESCRIPT_DLL_API
500 bool isLazy() const; // a test to determine if this object is an instance of DataLazy
501
502 virtual
503 bool
504 isConstant() const {return false;}
505
506 virtual
507 bool
508 isExpanded() const {return false;}
509
510 virtual
511 bool
512 isTagged() const {return false;}
513
514 ESCRIPT_DLL_API
515 bool isEmpty() const; // a fast test to determine if this object is an instance of DataEmpty
516
517 protected:
518
519
520
521 private:
522
523 //
524 // The number of samples in this Data object.
525 // This is derived directly from the FunctionSpace.
526 int m_noSamples;
527
528 //
529 // The number of data points per sample in this Data object.
530 // This is derived directly from the FunctionSpace.
531 int m_noDataPointsPerSample;
532
533 //
534 // A FunctionSpace which provides a description of the data associated
535 // with this Data object.
536 FunctionSpace m_functionSpace;
537
538 //
539 // The shape of the points stored in this view
540 DataTypes::ShapeType m_shape;
541
542 //
543 // The number of values in each point
544 unsigned int m_novalues;
545
546 //
547 // The rank of the points stored in this view
548 unsigned int m_rank;
549
550 //
551 // Is this an instance of DataEmpty?
552 bool m_isempty;
553 };
554
555 inline
556 bool
557 DataAbstract::isEmpty() const
558 {
559 return m_isempty;
560 }
561
562 // inline
563 // DataTypes::ValueType::const_reference
564 // DataAbstract::getDataAtOffset(DataTypes::ValueType::size_type i) const
565 // {
566 // if (isLazy())
567 // {
568 // throw DataException("Programmer error - getDataAtOffset() not permitted on Lazy Data.");
569 // }
570 // DataReady* d;
571 // return (dynamic_cast<const DataReady*>(this))->getVector()[i];
572 // // return getVector()[i];
573 // }
574
575 // inline
576 // DataTypes::ValueType::reference
577 // DataAbstract::getDataAtOffset(DataTypes::ValueType::size_type i)
578 // {
579 // if (isLazy())
580 // {
581 // throw DataException("Programmer error - getDataAtOffset() not permitted on Lazy Data.");
582 // }
583 // return dynamic_cast<DataReady*>(this)->getVector()[i];
584 // // return getVector()[i];
585 // }
586
587
588 inline
589 bool
590 DataAbstract::validSamplePointNo(int samplePointNo) const
591 {
592 return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
593 }
594
595 inline
596 bool
597 DataAbstract::validSampleNo(int sampleNo) const
598 {
599 return ((0 <= sampleNo) && (sampleNo < m_noSamples));
600 }
601
602 inline
603 int
604 DataAbstract::getNumDPPSample() const
605 {
606 if (isEmpty())
607 {
608 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
609 }
610 return m_noDataPointsPerSample;
611 }
612
613 inline
614 int
615 DataAbstract::getNumSamples() const
616 {
617 if (isEmpty())
618 {
619 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
620 }
621 return m_noSamples;
622 }
623
624 inline
625 const
626 FunctionSpace&
627 DataAbstract::getFunctionSpace() const
628 {
629 return m_functionSpace;
630 }
631
632 inline
633 const DataTypes::ShapeType&
634 DataAbstract::getShape() const
635 {
636 if (isEmpty())
637 {
638 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
639 }
640 return m_shape;
641 }
642
643 inline
644 unsigned int
645 DataAbstract::getRank() const
646 {
647 if (isEmpty())
648 {
649 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
650 }
651 return m_rank;
652 }
653
654 inline
655 unsigned int
656 DataAbstract::getNoValues() const
657 {
658 if (isEmpty())
659 {
660 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
661 }
662 return m_novalues;
663 }
664
665
666 } // end of namespace
667
668 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26