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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (10 years, 6 months ago) by ksteube
File MIME type: text/plain
File size: 13092 byte(s)
Copyright updated in all files

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 namespace escript {
31
32 /**
33 \brief
34 DataAbstract provides an abstract interface for the class of containers
35 which hold ESyS data.
36
37 Description:
38 DataAbstract provides an abstract interface for the class of containers
39 which hold ESyS data. The container may be thought of as a 2 dimensional
40 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 */
45
46 class DataAbstract {
47
48 public:
49
50 typedef DataTypes::ValueType ValueType;
51 typedef DataTypes::ShapeType ShapeType;
52
53 /**
54 \brief
55 Constructor for DataAbstract.
56
57 Description:
58 Constructor for DataAbstract.
59
60 \param what - Input - A description of what this data represents.
61 */
62 ESCRIPT_DLL_API
63 DataAbstract(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty=false);
64
65 /**
66 \brief
67 Destructor for DataAbstract.
68 */
69 ESCRIPT_DLL_API
70 virtual
71 ~DataAbstract();
72
73 /**
74 \brief
75 Write the data as a string.
76 */
77 ESCRIPT_DLL_API
78 virtual
79 std::string
80 toString() const = 0;
81
82 /**
83 \brief Return a deep copy of the current object.
84 */
85 ESCRIPT_DLL_API
86 virtual
87 DataAbstract*
88 deepCopy()=0;
89
90 /**
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 /**
100 \brief
101 Return the number of data points per sample.
102 */
103 ESCRIPT_DLL_API
104 int
105 getNumDPPSample() const;
106
107 /**
108 \brief
109 Return the number of samples.
110 */
111 ESCRIPT_DLL_API
112 int
113 getNumSamples() const;
114
115 /**
116 \brief
117 Return the shape information for the point data.
118
119 The omission of a non-constant form is deliberate.
120 */
121 ESCRIPT_DLL_API
122 const DataTypes::ShapeType&
123 getShape() const;
124
125 /**
126 \brief
127 Return the rank information for the point data.
128 */
129 ESCRIPT_DLL_API
130 int
131 getRank() const;
132
133
134
135 /**
136 \brief
137 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 \param sampleNo - Input - sample number.
142 \param dataPointNo - Input - data point number.
143 */
144 ESCRIPT_DLL_API
145 virtual
146 ValueType::size_type
147 getPointOffset(int sampleNo,
148 int dataPointNo) const = 0;
149
150 // /**
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 /**
165 \brief
166 Return the sample data for the given sample number.
167 */
168 ESCRIPT_DLL_API
169 double*
170 getSampleData(ValueType::size_type sampleNo);
171
172 /**
173 \brief
174 Return the number of doubles stored for this Data object.
175 */
176 ESCRIPT_DLL_API
177 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 ESCRIPT_DLL_API
187 virtual
188 double*
189 getSampleDataByTag(int tag);
190
191
192 /**
193 \brief
194 Check this and the given RHS operands are compatible. Throws
195 an exception if they aren't.
196
197 \param right - Input - The right hand side.
198 */
199 ESCRIPT_DLL_API
200 void
201 operandCheck(const DataAbstract& right) const;
202
203 /**
204 \brief
205 Return true if a valid sample point number.
206 */
207 ESCRIPT_DLL_API
208 bool
209 validSamplePointNo(int samplePointNo) const;
210
211 /**
212 \brief
213 Return true if a valid sample number.
214 */
215 ESCRIPT_DLL_API
216 bool
217 validSampleNo(int sampleNo) const;
218
219
220 /**
221 \brief
222 Return the function space associated with this Data object.
223 */
224 ESCRIPT_DLL_API
225 const
226 FunctionSpace&
227 getFunctionSpace() const;
228
229 /**
230 \brief
231 Return the given slice from this object.
232
233 NB: The caller is responsible for managing the object created.
234 */
235 ESCRIPT_DLL_API
236 virtual
237 DataAbstract*
238 getSlice(const DataTypes::RegionType& region) const = 0;
239
240 /**
241 \brief
242 Copy the specified region from the given object.
243
244 \param value - Input - Data to copy from
245 \param region - Input - Region to copy.
246 */
247 ESCRIPT_DLL_API
248 virtual
249 void
250 setSlice(const DataAbstract* value,
251 const DataTypes::RegionType& region) = 0;
252
253 /**
254 \brief
255 setTaggedValue
256
257 Description:
258 Assign the given value to the given tag.
259
260 NB: If the data isn't tagged an exception will be thrown.
261
262 \param tagKey - Input - Integer key.
263 \param pointshape - Input - the shape of the value parameter.
264 \param value - Input -
265 */
266 ESCRIPT_DLL_API
267 virtual
268 void
269 setTaggedValue(int tagKey,
270 const DataTypes::ShapeType& pointshape,
271 const DataTypes::ValueType& value,
272 int dataOffset=0);
273
274
275
276
277 /**
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 ESCRIPT_DLL_API
287 virtual void
288 copyAll(const boost::python::numeric::array& value);
289
290 /**
291 \brief
292 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 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 Return the tag number associated with the given data-point number.
324
325 If the object cannot be referenced by tag numbers, an exception
326 will be thrown.
327 */
328 ESCRIPT_DLL_API
329 virtual
330 int
331 getTagNumber(int dpno);
332
333 /**
334 \brief
335 Computes a symmetric matrix (A + AT) / 2
336
337 \param ev - Output - a symmetric matrix
338
339 */
340 ESCRIPT_DLL_API
341 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 ESCRIPT_DLL_API
352 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 ESCRIPT_DLL_API
363 virtual void
364 trace(DataAbstract* ev, int axis_offset);
365
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 ESCRIPT_DLL_API
374 virtual void
375 transpose(DataAbstract* ev, int axis_offset);
376
377 /**
378 \brief
379 swaps components axis0 and axis1
380
381 \param ev - Output - swapped components
382
383 */
384 ESCRIPT_DLL_API
385 virtual void
386 swapaxes(DataAbstract* ev, int axis0, int axis1);
387 /**
388 \brief
389 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 ESCRIPT_DLL_API
395 virtual void
396 eigenvalues(DataAbstract* ev);
397
398 /**
399 \brief
400 sets values to zero
401
402 */
403 ESCRIPT_DLL_API
404 virtual void
405 setToZero();
406
407 /**
408 \brief
409 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 ESCRIPT_DLL_API
419 virtual void
420 eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
421
422 /**
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
433
434 /**
435 \brief
436 Return the number of values in the shape for this object.
437 */
438 ESCRIPT_DLL_API
439 int
440 getNoValues() const;
441
442
443
444 /**
445 \brief get a reference to the beginning of a data point
446 */
447 ESCRIPT_DLL_API
448 DataTypes::ValueType::const_reference
449 getDataAtOffset(DataTypes::ValueType::size_type i) const;
450
451
452 ESCRIPT_DLL_API
453 DataTypes::ValueType::reference
454 getDataAtOffset(DataTypes::ValueType::size_type i);
455
456
457 /**
458 \brief Provide access to underlying storage. Internal use only!
459 */
460 ESCRIPT_DLL_API
461 virtual DataTypes::ValueType&
462 getVector()=0;
463
464 ESCRIPT_DLL_API
465 virtual const DataTypes::ValueType&
466 getVector() const=0;
467
468 protected:
469
470 bool isEmpty() const; // a fast test to determine if this object is an instance of DataEmpty
471
472
473
474
475 private:
476
477 //
478 // The number of samples in this Data object.
479 // This is derived directly from the FunctionSpace.
480 int m_noSamples;
481
482 //
483 // 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 // boost::scoped_ptr<DataArrayView> m_pointDataView;
492
493 //
494 // A FunctionSpace which provides a description of the data associated
495 // with this Data object.
496 FunctionSpace m_functionSpace;
497
498 //
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 //
511 // Is this an instance of DataEmpty?
512 bool m_isempty;
513 };
514
515
516 inline
517 bool
518 DataAbstract::isEmpty() const
519 {
520 return m_isempty;
521 }
522
523
524 inline
525 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 bool
541 DataAbstract::validSamplePointNo(int samplePointNo) const
542 {
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 // return &(m_pointDataView->getData(getPointOffset(sampleNo,0)));
558 return &(getVector()[getPointOffset(sampleNo,0)]);
559 }
560
561 inline
562 int
563 DataAbstract::getNumDPPSample() const
564 {
565 if (isEmpty())
566 {
567 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
568 }
569 return m_noDataPointsPerSample;
570 }
571
572 inline
573 int
574 DataAbstract::getNumSamples() const
575 {
576 if (isEmpty())
577 {
578 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
579 }
580 return m_noSamples;
581 }
582
583 inline
584 const
585 FunctionSpace&
586 DataAbstract::getFunctionSpace() const
587 {
588 return m_functionSpace;
589 }
590
591 inline
592 const DataTypes::ShapeType&
593 DataAbstract::getShape() const
594 {
595 if (isEmpty())
596 {
597 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
598 }
599 return m_shape;
600 }
601
602 inline
603 int
604 DataAbstract::getRank() const
605 {
606 if (isEmpty())
607 {
608 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
609 }
610 return m_rank;
611 }
612
613 inline
614 int
615 DataAbstract::getNoValues() const
616 {
617 if (isEmpty())
618 {
619 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
620 }
621 return m_novalues;
622 }
623
624
625 } // end of namespace
626
627 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26