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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1828 - (show annotations)
Thu Oct 2 04:52:11 2008 UTC (11 years, 10 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
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
54 class DataAbstract : public REFCOUNT_BASE_CLASS(DataAbstract)
55 {
56
57 public:
58
59 typedef DataTypes::ValueType ValueType;
60 typedef DataTypes::ShapeType ShapeType;
61
62
63 DataAbstract_ptr getPtr();
64 const_DataAbstract_ptr getPtr() const;
65
66 /**
67 \brief
68 Constructor for DataAbstract.
69
70 Description:
71 Constructor for DataAbstract.
72
73 \param what - Input - A description of what this data represents.
74 */
75 ESCRIPT_DLL_API
76 DataAbstract(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty=false);
77
78 /**
79 \brief
80 Destructor for DataAbstract.
81 */
82 ESCRIPT_DLL_API
83 virtual
84 ~DataAbstract();
85
86 /**
87 \brief
88 Write the data as a string.
89 */
90 ESCRIPT_DLL_API
91 virtual
92 std::string
93 toString() const = 0;
94
95 /**
96 \brief Return a deep copy of the current object.
97 */
98 ESCRIPT_DLL_API
99 virtual
100 DataAbstract*
101 deepCopy()=0;
102
103 /**
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 /**
113 \brief
114 Return the number of data points per sample.
115 */
116 ESCRIPT_DLL_API
117 int
118 getNumDPPSample() const;
119
120 /**
121 \brief
122 Return the number of samples.
123 */
124 ESCRIPT_DLL_API
125 int
126 getNumSamples() const;
127
128 /**
129 \brief
130 Return the shape information for the point data.
131
132 The omission of a non-constant form is deliberate.
133 */
134 ESCRIPT_DLL_API
135 const DataTypes::ShapeType&
136 getShape() const;
137
138 /**
139 \brief
140 Return the rank information for the point data.
141 */
142 ESCRIPT_DLL_API
143 int
144 getRank() const;
145
146
147
148 /**
149 \brief
150 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 \param sampleNo - Input - sample number.
155 \param dataPointNo - Input - data point number.
156 */
157 ESCRIPT_DLL_API
158 virtual
159 ValueType::size_type
160 getPointOffset(int sampleNo,
161 int dataPointNo) const = 0;
162
163 // /**
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 /**
178 \brief
179 Return the sample data for the given sample number.
180 */
181 ESCRIPT_DLL_API
182 double*
183 getSampleData(ValueType::size_type sampleNo);
184
185 /**
186 \brief
187 Return the number of doubles stored for this Data object.
188 */
189 ESCRIPT_DLL_API
190 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 ESCRIPT_DLL_API
200 virtual
201 double*
202 getSampleDataByTag(int tag);
203
204
205 /**
206 \brief
207 Check this and the given RHS operands are compatible. Throws
208 an exception if they aren't.
209
210 \param right - Input - The right hand side.
211 */
212 ESCRIPT_DLL_API
213 void
214 operandCheck(const DataAbstract& right) const;
215
216 /**
217 \brief
218 Return true if a valid sample point number.
219 */
220 ESCRIPT_DLL_API
221 bool
222 validSamplePointNo(int samplePointNo) const;
223
224 /**
225 \brief
226 Return true if a valid sample number.
227 */
228 ESCRIPT_DLL_API
229 bool
230 validSampleNo(int sampleNo) const;
231
232
233 /**
234 \brief
235 Return the function space associated with this Data object.
236 */
237 ESCRIPT_DLL_API
238 const
239 FunctionSpace&
240 getFunctionSpace() const;
241
242 /**
243 \brief
244 Return the given slice from this object.
245
246 NB: The caller is responsible for managing the object created.
247 */
248 ESCRIPT_DLL_API
249 virtual
250 DataAbstract*
251 getSlice(const DataTypes::RegionType& region) const = 0;
252
253 /**
254 \brief
255 Copy the specified region from the given object.
256
257 \param value - Input - Data to copy from
258 \param region - Input - Region to copy.
259 */
260 ESCRIPT_DLL_API
261 virtual
262 void
263 setSlice(const DataAbstract* value,
264 const DataTypes::RegionType& region) = 0;
265
266 /**
267 \brief
268 setTaggedValue
269
270 Description:
271 Assign the given value to the given tag.
272
273 NB: If the data isn't tagged an exception will be thrown.
274
275 \param tagKey - Input - Integer key.
276 \param pointshape - Input - the shape of the value parameter.
277 \param value - Input -
278 */
279 ESCRIPT_DLL_API
280 virtual
281 void
282 setTaggedValue(int tagKey,
283 const DataTypes::ShapeType& pointshape,
284 const DataTypes::ValueType& value,
285 int dataOffset=0);
286
287
288
289
290 /**
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 ESCRIPT_DLL_API
300 virtual void
301 copyAll(const boost::python::numeric::array& value);
302
303 /**
304 \brief
305 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 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 Return the tag number associated with the given data-point number.
337
338 If the object cannot be referenced by tag numbers, an exception
339 will be thrown.
340 */
341 ESCRIPT_DLL_API
342 virtual
343 int
344 getTagNumber(int dpno);
345
346 /**
347 \brief
348 Computes a symmetric matrix (A + AT) / 2
349
350 \param ev - Output - a symmetric matrix
351
352 */
353 ESCRIPT_DLL_API
354 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 ESCRIPT_DLL_API
365 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 ESCRIPT_DLL_API
376 virtual void
377 trace(DataAbstract* ev, int axis_offset);
378
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 ESCRIPT_DLL_API
387 virtual void
388 transpose(DataAbstract* ev, int axis_offset);
389
390 /**
391 \brief
392 swaps components axis0 and axis1
393
394 \param ev - Output - swapped components
395
396 */
397 ESCRIPT_DLL_API
398 virtual void
399 swapaxes(DataAbstract* ev, int axis0, int axis1);
400 /**
401 \brief
402 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 ESCRIPT_DLL_API
408 virtual void
409 eigenvalues(DataAbstract* ev);
410
411 /**
412 \brief
413 sets values to zero
414
415 */
416 ESCRIPT_DLL_API
417 virtual void
418 setToZero();
419
420 /**
421 \brief
422 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 ESCRIPT_DLL_API
432 virtual void
433 eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
434
435 /**
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
446
447 /**
448 \brief
449 Return the number of values in the shape for this object.
450 */
451 ESCRIPT_DLL_API
452 int
453 getNoValues() const;
454
455
456
457 /**
458 \brief get a reference to the beginning of a data point
459 */
460 ESCRIPT_DLL_API
461 DataTypes::ValueType::const_reference
462 getDataAtOffset(DataTypes::ValueType::size_type i) const;
463
464
465 ESCRIPT_DLL_API
466 DataTypes::ValueType::reference
467 getDataAtOffset(DataTypes::ValueType::size_type i);
468
469
470 /**
471 \brief Provide access to underlying storage. Internal use only!
472 */
473 ESCRIPT_DLL_API
474 virtual DataTypes::ValueType&
475 getVector()=0;
476
477 ESCRIPT_DLL_API
478 virtual const DataTypes::ValueType&
479 getVector() const=0;
480
481 protected:
482
483 bool isEmpty() const; // a fast test to determine if this object is an instance of DataEmpty
484
485
486
487
488 private:
489
490 //
491 // The number of samples in this Data object.
492 // This is derived directly from the FunctionSpace.
493 int m_noSamples;
494
495 //
496 // 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 FunctionSpace m_functionSpace;
504
505 //
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 //
518 // Is this an instance of DataEmpty?
519 bool m_isempty;
520 };
521
522
523 inline
524 bool
525 DataAbstract::isEmpty() const
526 {
527 return m_isempty;
528 }
529
530
531 inline
532 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 bool
548 DataAbstract::validSamplePointNo(int samplePointNo) const
549 {
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 // return &(m_pointDataView->getData(getPointOffset(sampleNo,0)));
565 return &(getVector()[getPointOffset(sampleNo,0)]);
566 }
567
568 inline
569 int
570 DataAbstract::getNumDPPSample() const
571 {
572 if (isEmpty())
573 {
574 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
575 }
576 return m_noDataPointsPerSample;
577 }
578
579 inline
580 int
581 DataAbstract::getNumSamples() const
582 {
583 if (isEmpty())
584 {
585 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
586 }
587 return m_noSamples;
588 }
589
590 inline
591 const
592 FunctionSpace&
593 DataAbstract::getFunctionSpace() const
594 {
595 return m_functionSpace;
596 }
597
598 inline
599 const DataTypes::ShapeType&
600 DataAbstract::getShape() const
601 {
602 if (isEmpty())
603 {
604 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
605 }
606 return m_shape;
607 }
608
609 inline
610 int
611 DataAbstract::getRank() const
612 {
613 if (isEmpty())
614 {
615 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
616 }
617 return m_rank;
618 }
619
620 inline
621 int
622 DataAbstract::getNoValues() const
623 {
624 if (isEmpty())
625 {
626 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
627 }
628 return m_novalues;
629 }
630
631
632 } // end of namespace
633
634 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26