/[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 1864 - (show annotations)
Thu Oct 9 03:09:30 2008 UTC (11 years, 5 months ago) by jfenwick
File MIME type: text/plain
File size: 14096 byte(s)
Branch commit
It compiles but doesn't do much.


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26