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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2005 - (hide 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 jgs 478
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
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 ksteube 1312
14 ksteube 1811
15 jgs 106 #if !defined escript_DataAbstract_20040315_H
16 jgs 82 #define escript_DataAbstract_20040315_H
17 woo409 757 #include "system_dep.h"
18 jgs 82
19 jfenwick 1796 #include "DataTypes.h"
20 jgs 474 #include "FunctionSpace.h"
21 jgs 82
22     #include <boost/scoped_ptr.hpp>
23 jgs 478 #include <boost/python/numeric.hpp>
24 jgs 480
25 jfenwick 1803 #include "DataException.h"
26    
27 jgs 82 #include <string>
28 jgs 480 #include <fstream>
29 jgs 82
30 jfenwick 1872 #include "Pointers.h"
31    
32 jgs 82 namespace escript {
33    
34     /**
35     \brief
36 jgs 117 DataAbstract provides an abstract interface for the class of containers
37 matt 1325 which hold ESyS data.
38 jgs 82
39     Description:
40 jgs 117 DataAbstract provides an abstract interface for the class of containers
41 jgs 82 which hold ESyS data. The container may be thought of as a 2 dimensional
42 jgs 117 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 jgs 82 */
47    
48 jfenwick 1872 class DataAbstract;
49 jgs 82
50 jfenwick 1872 typedef POINTER_WRAPPER_CLASS(DataAbstract) DataAbstract_ptr;
51     typedef POINTER_WRAPPER_CLASS(const DataAbstract) const_DataAbstract_ptr;
52    
53 jfenwick 2005 class DataReady;
54 jfenwick 1872
55 jfenwick 2005 typedef POINTER_WRAPPER_CLASS(DataReady) DataReady_ptr;
56     typedef POINTER_WRAPPER_CLASS(const DataReady) const_DataReady_ptr;
57    
58 jfenwick 1872 class DataAbstract : public REFCOUNT_BASE_CLASS(DataAbstract)
59     {
60    
61 jgs 82 public:
62    
63 jfenwick 1796 typedef DataTypes::ValueType ValueType;
64     typedef DataTypes::ShapeType ShapeType;
65 jgs 82
66 jfenwick 1872 ESCRIPT_DLL_API
67     DataAbstract_ptr getPtr();
68     ESCRIPT_DLL_API
69     const_DataAbstract_ptr getPtr() const;
70    
71 jgs 82 /**
72     \brief
73     Constructor for DataAbstract.
74    
75     Description:
76     Constructor for DataAbstract.
77 jgs 117
78 jgs 82 \param what - Input - A description of what this data represents.
79     */
80 woo409 757 ESCRIPT_DLL_API
81 jfenwick 1803 DataAbstract(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty=false);
82 jgs 82
83     /**
84     \brief
85     Destructor for DataAbstract.
86     */
87 woo409 757 ESCRIPT_DLL_API
88 jgs 106 virtual
89     ~DataAbstract();
90 jgs 82
91     /**
92     \brief
93     Write the data as a string.
94     */
95 woo409 757 ESCRIPT_DLL_API
96 jgs 82 virtual
97     std::string
98     toString() const = 0;
99    
100 jfenwick 1799 /**
101     \brief Return a deep copy of the current object.
102     */
103     ESCRIPT_DLL_API
104     virtual
105     DataAbstract*
106     deepCopy()=0;
107    
108 jfenwick 2005 /**
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 gross 950 /**
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 jgs 82 /**
126     \brief
127     Return the number of data points per sample.
128     */
129 woo409 757 ESCRIPT_DLL_API
130 jgs 82 int
131     getNumDPPSample() const;
132    
133     /**
134     \brief
135     Return the number of samples.
136     */
137 woo409 757 ESCRIPT_DLL_API
138 jgs 82 int
139     getNumSamples() const;
140    
141     /**
142 jfenwick 1796 \brief
143     Return the shape information for the point data.
144    
145     The omission of a non-constant form is deliberate.
146 jgs 82 */
147 woo409 757 ESCRIPT_DLL_API
148 jfenwick 1796 const DataTypes::ShapeType&
149     getShape() const;
150 jgs 117
151 jfenwick 1796 /**
152     \brief
153     Return the rank information for the point data.
154     */
155 woo409 757 ESCRIPT_DLL_API
156 jfenwick 1952 unsigned int
157 jfenwick 1796 getRank() const;
158 jgs 82
159 jfenwick 1796
160    
161 jfenwick 2005 /**
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 jgs 117
166 jfenwick 2005 \param sampleNo - Input - sample number.
167     \param dataPointNo - Input - data point number.
168     */
169 woo409 757 ESCRIPT_DLL_API
170 jgs 82 virtual
171     ValueType::size_type
172     getPointOffset(int sampleNo,
173     int dataPointNo) const = 0;
174    
175 jfenwick 2005 ESCRIPT_DLL_API
176     virtual
177     ValueType::size_type
178     getPointOffset(int sampleNo,
179     int dataPointNo) = 0;
180    
181 jfenwick 1796 // /**
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 jfenwick 2005 // /**
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 jgs 82
203     /**
204     \brief
205 jgs 117 Return the number of doubles stored for this Data object.
206 jgs 82 */
207 woo409 757 ESCRIPT_DLL_API
208 jgs 82 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 woo409 757 ESCRIPT_DLL_API
218 jgs 82 virtual
219     double*
220     getSampleDataByTag(int tag);
221    
222 jgs 110
223     /**
224     \brief
225 jgs 117 Check this and the given RHS operands are compatible. Throws
226 jgs 82 an exception if they aren't.
227 jgs 117
228 jgs 82 \param right - Input - The right hand side.
229     */
230 woo409 757 ESCRIPT_DLL_API
231 jgs 82 void
232     operandCheck(const DataAbstract& right) const;
233    
234     /**
235     \brief
236     Return true if a valid sample point number.
237     */
238 woo409 757 ESCRIPT_DLL_API
239 jgs 82 bool
240     validSamplePointNo(int samplePointNo) const;
241    
242     /**
243     \brief
244 jgs 117 Return true if a valid sample number.
245 jgs 82 */
246 woo409 757 ESCRIPT_DLL_API
247 jgs 82 bool
248     validSampleNo(int sampleNo) const;
249 matt 1325
250 jgs 117
251 jgs 82 /**
252     \brief
253 jgs 117 Return the function space associated with this Data object.
254 jgs 82 */
255 woo409 757 ESCRIPT_DLL_API
256 jgs 117 const
257     FunctionSpace&
258 jgs 82 getFunctionSpace() const;
259    
260     /**
261     \brief
262 jgs 117 Return the given slice from this object.
263    
264     NB: The caller is responsible for managing the object created.
265 jgs 82 */
266 woo409 757 ESCRIPT_DLL_API
267 jgs 82 virtual
268     DataAbstract*
269 jfenwick 1796 getSlice(const DataTypes::RegionType& region) const = 0;
270 jgs 82
271 jfenwick 2005 // /**
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 jgs 117
284 jgs 82 /**
285     \brief
286     setTaggedValue
287 matt 1325
288 jgs 82 Description:
289     Assign the given value to the given tag.
290 jgs 117
291     NB: If the data isn't tagged an exception will be thrown.
292    
293 jgs 82 \param tagKey - Input - Integer key.
294 jfenwick 1796 \param pointshape - Input - the shape of the value parameter.
295     \param value - Input -
296 jgs 82 */
297 woo409 757 ESCRIPT_DLL_API
298 jgs 82 virtual
299     void
300     setTaggedValue(int tagKey,
301 jfenwick 1796 const DataTypes::ShapeType& pointshape,
302     const DataTypes::ValueType& value,
303     int dataOffset=0);
304 jgs 82
305 jgs 123
306    
307    
308 jgs 126 /**
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 woo409 757 ESCRIPT_DLL_API
318 jgs 126 virtual void
319     copyAll(const boost::python::numeric::array& value);
320    
321 jgs 149 /**
322     \brief
323 gross 922 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 gross 921 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 jgs 149 Return the tag number associated with the given data-point number.
355 jgs 126
356 jgs 149 If the object cannot be referenced by tag numbers, an exception
357     will be thrown.
358     */
359 woo409 757 ESCRIPT_DLL_API
360 jgs 149 virtual
361     int
362     getTagNumber(int dpno);
363    
364 gross 576 /**
365     \brief
366 ksteube 775 Computes a symmetric matrix (A + AT) / 2
367    
368     \param ev - Output - a symmetric matrix
369    
370     */
371 gross 800 ESCRIPT_DLL_API
372 ksteube 775 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 gross 800 ESCRIPT_DLL_API
383 ksteube 775 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 gross 800 ESCRIPT_DLL_API
394 ksteube 775 virtual void
395 gross 800 trace(DataAbstract* ev, int axis_offset);
396 ksteube 775
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 gross 800 ESCRIPT_DLL_API
405 ksteube 775 virtual void
406     transpose(DataAbstract* ev, int axis_offset);
407    
408     /**
409     \brief
410 gross 804 swaps components axis0 and axis1
411 gross 800
412     \param ev - Output - swapped components
413    
414     */
415     ESCRIPT_DLL_API
416     virtual void
417 gross 804 swapaxes(DataAbstract* ev, int axis0, int axis1);
418 gross 800 /**
419     \brief
420 gross 576 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 woo409 757 ESCRIPT_DLL_API
426 gross 576 virtual void
427     eigenvalues(DataAbstract* ev);
428    
429     /**
430     \brief
431 gross 1118 sets values to zero
432    
433     */
434     ESCRIPT_DLL_API
435     virtual void
436     setToZero();
437    
438     /**
439     \brief
440 gross 576 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 woo409 757 ESCRIPT_DLL_API
450 gross 576 virtual void
451     eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
452    
453 gross 1487 /**
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 jgs 82
464 jfenwick 1796
465 jgs 82 /**
466 jfenwick 1796 \brief
467     Return the number of values in the shape for this object.
468     */
469     ESCRIPT_DLL_API
470 jfenwick 1981 unsigned int
471 jfenwick 1796 getNoValues() const;
472 jgs 117
473 jfenwick 1796
474    
475 jfenwick 2005 // /**
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 jgs 82
487 jfenwick 1796
488 jfenwick 2005 // /**
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 woo409 757 ESCRIPT_DLL_API
500 jfenwick 2005 bool isLazy() const; // a test to determine if this object is an instance of DataLazy
501 jgs 119
502 jfenwick 2005 virtual
503     bool
504     isConstant() const {return false;}
505 gross 1487
506 jfenwick 2005 virtual
507     bool
508     isExpanded() const {return false;}
509 gross 1487
510 jfenwick 2005 virtual
511     bool
512     isTagged() const {return false;}
513 jfenwick 1796
514 jfenwick 1897 ESCRIPT_DLL_API
515     bool isEmpty() const; // a fast test to determine if this object is an instance of DataEmpty
516    
517 jfenwick 1796 protected:
518    
519    
520    
521 jgs 82 private:
522    
523 jgs 117 //
524     // The number of samples in this Data object.
525     // This is derived directly from the FunctionSpace.
526 jgs 82 int m_noSamples;
527    
528     //
529 jgs 117 // 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 jgs 82 FunctionSpace m_functionSpace;
537    
538 jfenwick 1796 //
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 jfenwick 1981 unsigned int m_novalues;
545 jfenwick 1796
546     //
547     // The rank of the points stored in this view
548 jfenwick 1952 unsigned int m_rank;
549 jfenwick 1796
550 jfenwick 1803 //
551     // Is this an instance of DataEmpty?
552     bool m_isempty;
553 jgs 82 };
554    
555     inline
556 jfenwick 1803 bool
557     DataAbstract::isEmpty() const
558     {
559     return m_isempty;
560     }
561    
562 jfenwick 2005 // 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 jfenwick 1803
575 jfenwick 2005 // 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 jfenwick 1796
587    
588     inline
589 jgs 82 bool
590 matt 1325 DataAbstract::validSamplePointNo(int samplePointNo) const
591 jgs 82 {
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 matt 1325 DataAbstract::getNumDPPSample() const
605 jgs 82 {
606 jfenwick 1803 if (isEmpty())
607     {
608     throw DataException("Error - Operations not permitted on instances of DataEmpty.");
609     }
610 jgs 82 return m_noDataPointsPerSample;
611     }
612    
613     inline
614     int
615     DataAbstract::getNumSamples() const
616     {
617 jfenwick 1803 if (isEmpty())
618     {
619     throw DataException("Error - Operations not permitted on instances of DataEmpty.");
620     }
621 jgs 82 return m_noSamples;
622     }
623    
624     inline
625 jgs 106 const
626     FunctionSpace&
627 jgs 82 DataAbstract::getFunctionSpace() const
628     {
629     return m_functionSpace;
630     }
631    
632     inline
633 jfenwick 1796 const DataTypes::ShapeType&
634     DataAbstract::getShape() const
635 jgs 82 {
636 jfenwick 1803 if (isEmpty())
637     {
638     throw DataException("Error - Operations not permitted on instances of DataEmpty.");
639     }
640 jfenwick 1796 return m_shape;
641 jgs 82 }
642    
643 jfenwick 1796 inline
644 jfenwick 1952 unsigned int
645 jfenwick 1796 DataAbstract::getRank() const
646     {
647 jfenwick 1803 if (isEmpty())
648     {
649     throw DataException("Error - Operations not permitted on instances of DataEmpty.");
650     }
651 jfenwick 1796 return m_rank;
652     }
653    
654 jgs 82 inline
655 jfenwick 1981 unsigned int
656 jfenwick 1796 DataAbstract::getNoValues() const
657 jfenwick 1803 {
658     if (isEmpty())
659     {
660     throw DataException("Error - Operations not permitted on instances of DataEmpty.");
661     }
662 jfenwick 1796 return m_novalues;
663 jgs 82 }
664 jfenwick 1796
665 jfenwick 1803
666 jgs 82 } // end of namespace
667 jgs 117
668 jgs 82 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26