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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1803 - (hide annotations)
Wed Sep 24 06:20:29 2008 UTC (10 years, 11 months ago) by jfenwick
File MIME type: text/plain
File size: 13126 byte(s)
All about making DataEmpty instances throw.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Exposed getDim from AbstractDomain to python to fix bug.

Added isEmpty member to DataAbstract to allow it to throw is queries are 
made about a DataEmpty instance.


Added exceptions to DataAbstract, DataEmpty and Data to prevent calls 
being made against DataEmpty objects.
The following still work as expected on DataEmpty instances

copy, getDomain, getFunctionSpace, isEmpty, isExpanded, isProtected, 
isTagged, setprotection.

You can also call interpolate, however it should throw if you try to 
change FunctionSpaces.


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26