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

Annotation of /branches/more_shared_ptrs_from_1812/escript/src/DataAbstract.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1828 - (hide annotations)
Thu Oct 2 04:52:11 2008 UTC (11 years, 11 months ago) by jfenwick
File MIME type: text/plain
File size: 13140 byte(s)
Branch commit.
Added getPtr to DataAbstract.
Passes all unit tests.


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26