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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1889 - (show annotations)
Thu Oct 16 05:57:09 2008 UTC (10 years, 8 months ago) by jfenwick
File MIME type: text/plain
File size: 13938 byte(s)
Branch commit
Rewrote resolve to take into account Tagged and Constant Data.
Mixing expanded and Tagged does not work yet.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26