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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2653 - (show annotations)
Tue Sep 8 04:26:30 2009 UTC (10 years, 5 months ago) by jfenwick
File MIME type: text/plain
File size: 13909 byte(s)
Fix bug in maxGlobalDataPoint and minGlobalDataPoint.
They now give the correct answers and the datapoint ids returned are globally
correct.

Removed some #defines from before COW
Removed hasNoSamples() - I don't trust myself to use that properly let alone anybody else.


1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2009 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
24 #include "DataException.h"
25
26 #include <string>
27 #include <fstream>
28 #include <vector>
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 /**
67 \brief Return shared pointer managing this object.
68
69 If there is not already a shared pointer managing this object then create one.
70 Once a shared pointer is created for an object, the deallocation of the object
71 must be handled by shared_ptr.
72
73 \warning So, do not call this on an automatic object.
74 Do not call this in a method where you do not pass the shared_pointer out and
75 you need the object to outlast the method.
76
77 Note: This is _not_ equivalent to weak_ptr::lock.
78
79 */
80 ESCRIPT_DLL_API
81 DataAbstract_ptr getPtr();
82 ESCRIPT_DLL_API
83 const_DataAbstract_ptr getPtr() const;
84
85
86
87 /**
88 \brief
89 Constructor for DataAbstract.
90
91 \param what - Input - The functionspace to use.
92 \param shape - Input - Shape of each data value.
93 \param isDataEmpty - Input - Is this an instance of DataEmpty (for internal use only)
94 */
95 ESCRIPT_DLL_API
96 DataAbstract(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty=false);
97
98 /**
99 \brief
100 Destructor for DataAbstract.
101 */
102 ESCRIPT_DLL_API
103 virtual
104 ~DataAbstract();
105
106 /**
107 \brief
108 Write the data as a string.
109 */
110 ESCRIPT_DLL_API
111 virtual
112 std::string
113 toString() const = 0;
114
115 /**
116 \brief Return a deep copy of the current object.
117 */
118 ESCRIPT_DLL_API
119 virtual
120 DataAbstract*
121 deepCopy()=0;
122
123 /**
124 \brief Return a data object with all points resolved.
125 */
126 ESCRIPT_DLL_API
127 virtual
128 DataReady_ptr
129 resolve()=0;
130
131 /**
132 \brief
133 dumps the object into a netCDF file
134 */
135 ESCRIPT_DLL_API
136 virtual
137 void
138 dump(const std::string fileName) const;
139
140 /**
141 \brief
142 Return the number of data points per sample.
143 */
144 ESCRIPT_DLL_API
145 int
146 getNumDPPSample() const;
147
148 /**
149 \brief
150 Return the number of samples.
151 */
152 ESCRIPT_DLL_API
153 int
154 getNumSamples() const;
155
156 /**
157 \brief
158 Return the shape information for the point data.
159
160 The omission of a non-constant form is deliberate.
161 */
162 ESCRIPT_DLL_API
163 const DataTypes::ShapeType&
164 getShape() const;
165
166 /**
167 \brief
168 Return the rank information for the point data.
169 */
170 ESCRIPT_DLL_API
171 unsigned int
172 getRank() const;
173
174
175
176 /**
177 \brief
178 Return the offset for the given sample. This returns the offset for the given
179 point into the container holding the point data.
180
181 \param sampleNo - Input - sample number.
182 \param dataPointNo - Input - data point number.
183 */
184 ESCRIPT_DLL_API
185 virtual
186 ValueType::size_type
187 getPointOffset(int sampleNo,
188 int dataPointNo) const = 0;
189
190 ESCRIPT_DLL_API
191 virtual
192 ValueType::size_type
193 getPointOffset(int sampleNo,
194 int dataPointNo) = 0;
195
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 This method is used primarily for LazyData.
218 \return the size of the buffer required to evaulate a sample for this object.
219 */
220 ESCRIPT_DLL_API
221 virtual size_t
222 getSampleBufferSize() const=0;
223
224
225
226 /**
227 \brief
228 Check this and the given RHS operands are compatible. Throws
229 an exception if they aren't.
230
231 \param right - Input - The right hand side.
232 */
233 ESCRIPT_DLL_API
234 void
235 operandCheck(const DataAbstract& right) const;
236
237 /**
238 \brief
239 Return true if a valid sample point number.
240 */
241 ESCRIPT_DLL_API
242 bool
243 validSamplePointNo(int samplePointNo) const;
244
245 /**
246 \brief
247 Return true if a valid sample number.
248 */
249 ESCRIPT_DLL_API
250 bool
251 validSampleNo(int sampleNo) const;
252
253
254 /**
255 \brief
256 Return the function space associated with this Data object.
257 */
258 ESCRIPT_DLL_API
259 const
260 FunctionSpace&
261 getFunctionSpace() const;
262
263 /**
264 \brief
265 Return the given slice from this object.
266
267 NB: The caller is responsible for managing the object created.
268 */
269 ESCRIPT_DLL_API
270 virtual
271 DataAbstract*
272 getSlice(const DataTypes::RegionType& region) const = 0;
273
274
275
276 /**
277 \brief
278 setTaggedValue
279
280 Description:
281 Assign the given value to the given tag.
282
283 NB: If the data isn't tagged an exception will be thrown.
284
285 \param tagKey - Input - Integer key.
286 \param pointshape - Input - the shape of the value parameter.
287 \param value - Input - vector to copy data value from
288 \param dataOffset - Input - Offset within value to begin copying from
289
290 The final parameter is to allow for the case whete the vector contains
291 multiple data values.
292 */
293 ESCRIPT_DLL_API
294 virtual
295 void
296 setTaggedValue(int tagKey,
297 const DataTypes::ShapeType& pointshape,
298 const DataTypes::ValueType& value,
299 int dataOffset=0);
300
301
302 /**
303 \brief
304 Copy a double value to the data point dataPointNo of sample sampleNo in this object.
305
306 Description:
307 Copy a double value to the data point dataPointNo of sample sampleNo in this object.
308
309 \param sampleNo Input - sample number
310 \param dataPointNo Input - data point of the sample
311 \param value Input - new values for the data point
312 */
313 ESCRIPT_DLL_API
314 virtual void
315 copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
316
317 /**
318 \brief
319 Copy the array object to the data point dataPointNo of sample sampleNo in this object.
320
321 \param sampleNo Input - sample number
322 \param dataPointNo Input - data point of the sample
323 \param value Input - new values for the data point
324 */
325 ESCRIPT_DLL_API
326 virtual void
327 copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value);
328
329
330 /**
331 \brief
332 Return the tag number associated with the given data-point number.
333
334 If the object cannot be referenced by tag numbers, an exception
335 will be thrown.
336 */
337 ESCRIPT_DLL_API
338 virtual
339 int
340 getTagNumber(int dpno);
341
342 /**
343 \brief
344 Computes a symmetric matrix (A + AT) / 2
345
346 \param ev - Output - a symmetric matrix
347
348 */
349 ESCRIPT_DLL_API
350 virtual void
351 symmetric(DataAbstract* ev);
352
353 /**
354 \brief
355 Computes a nonsymmetric matrix (A - AT) / 2
356
357 \param ev - Output - a nonsymmetric matrix
358
359 */
360 ESCRIPT_DLL_API
361 virtual void
362 nonsymmetric(DataAbstract* ev);
363
364 /**
365 \brief
366 Computes the trace of a matrix
367
368 \param ev - Output - the trace of a matrix
369 \param axis_offset
370 */
371 ESCRIPT_DLL_API
372 virtual void
373 trace(DataAbstract* ev, int axis_offset);
374
375 /**
376 \brief
377 Transpose each data point of this Data object around the given axis.
378
379 \param ev - Output - the transpose of a matrix
380 \param axis_offset
381 */
382 ESCRIPT_DLL_API
383 virtual void
384 transpose(DataAbstract* ev, int axis_offset);
385
386 /**
387 \brief
388 swaps components axis0 and axis1
389
390 \param ev - Output - swapped components
391 \param axis0
392 \param axis1
393 */
394 ESCRIPT_DLL_API
395 virtual void
396 swapaxes(DataAbstract* ev, int axis0, int axis1);
397 /**
398 \brief
399 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
400
401 \param ev - Output - eigenvalues in increasing order at each data point
402
403 */
404 ESCRIPT_DLL_API
405 virtual void
406 eigenvalues(DataAbstract* ev);
407
408 /**
409 \brief
410 sets values to zero
411
412 */
413 ESCRIPT_DLL_API
414 virtual void
415 setToZero();
416
417 /**
418 \brief
419 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
420
421 \param ev - Output - eigenvalues in increasing order at each data point
422 \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
423 and the first nonzero component is positive.
424 \param tol - Input - eigenvalue with relative distance tol are treated as equal.
425
426 */
427
428 ESCRIPT_DLL_API
429 virtual void
430 eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
431
432 /**
433 \brief
434 reorders data sample ordered by reference_ids to the ordering of the functions space
435
436 \param reference_ids - Input - reference_ids used for current ordering
437 */
438 ESCRIPT_DLL_API
439 virtual void
440 reorderByReferenceIDs(int *reference_ids);
441
442
443
444 /**
445 \brief
446 Return the number of values in the shape for this object.
447 */
448 ESCRIPT_DLL_API
449 unsigned int
450 getNoValues() const;
451
452
453 ESCRIPT_DLL_API
454 bool isLazy() const; // a test to determine if this object is an instance of DataLazy
455
456 ESCRIPT_DLL_API
457 virtual
458 bool
459 isConstant() const {return false;}
460
461 ESCRIPT_DLL_API
462 virtual
463 bool
464 isExpanded() const {return false;}
465
466
467 /**
468 \brief
469 Return true if this Data is expanded or resolves to expanded.
470 That is, if it has a separate value for each datapoint in the sample.
471 */
472 ESCRIPT_DLL_API
473 virtual
474 bool
475 actsExpanded() const {return false;}
476
477 ESCRIPT_DLL_API
478 virtual
479 bool
480 isTagged() const {return false;}
481
482 ESCRIPT_DLL_API
483 bool isEmpty() const; // a fast test to determine if this object is an instance of DataEmpty
484
485
486 /**
487 \warning should only be used in single threaded code (or inside a single/critical section)
488 */
489 void
490 addOwner(Data*);
491
492 /**
493 \warning should only be used in single threaded code (or inside a single/critical section)
494 */
495 void
496 removeOwner(Data*);
497
498 /**
499 \brief Is this object owned by more than one Data object
500 */
501 ESCRIPT_DLL_API
502 bool
503 isShared() const
504 {
505 return m_lazyshared || (m_owners.size()>1);
506 }
507
508 protected:
509
510 /**
511 \brief Returns true if this object is not shared.
512 For internal use only. - It may not be particularly fast
513 */
514 ESCRIPT_DLL_API
515 bool checkNoSharing() const;
516
517 /**
518 \brief Marks this DataAbstract shared as LazyData
519 For internal use only.
520 */
521 void
522 makeLazyShared();
523
524 friend class DataLazy;
525
526 private:
527
528 //
529 // The number of samples in this Data object.
530 // This is derived directly from the FunctionSpace.
531 int m_noSamples;
532
533 //
534 // The number of data points per sample in this Data object.
535 // This is derived directly from the FunctionSpace.
536 int m_noDataPointsPerSample;
537
538 //
539 // A FunctionSpace which provides a description of the data associated
540 // with this Data object.
541 FunctionSpace m_functionSpace;
542
543 //
544 // The shape of the points stored in this view
545 DataTypes::ShapeType m_shape;
546
547 //
548 // The number of values in each point
549 unsigned int m_novalues;
550
551 //
552 // The rank of the points stored in this view
553 unsigned int m_rank;
554
555 //
556 // Is this an instance of DataEmpty?
557 bool m_isempty;
558
559 public: // these should be private once I have finished debugging
560 std::vector<Data*> m_owners;
561 bool m_lazyshared;
562 };
563
564 inline
565 bool
566 DataAbstract::isEmpty() const
567 {
568 return m_isempty;
569 }
570
571 inline
572 bool
573 DataAbstract::validSamplePointNo(int samplePointNo) const
574 {
575 return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
576 }
577
578 inline
579 bool
580 DataAbstract::validSampleNo(int sampleNo) const
581 {
582 return ((0 <= sampleNo) && (sampleNo < m_noSamples));
583 }
584
585 inline
586 int
587 DataAbstract::getNumDPPSample() const
588 {
589 if (isEmpty())
590 {
591 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
592 }
593 return m_noDataPointsPerSample;
594 }
595
596 inline
597 int
598 DataAbstract::getNumSamples() const
599 {
600 if (isEmpty())
601 {
602 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
603 }
604 return m_noSamples;
605 }
606
607 inline
608 const
609 FunctionSpace&
610 DataAbstract::getFunctionSpace() const
611 {
612 return m_functionSpace;
613 }
614
615 inline
616 const DataTypes::ShapeType&
617 DataAbstract::getShape() const
618 {
619 if (isEmpty())
620 {
621 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
622 }
623 return m_shape;
624 }
625
626 inline
627 unsigned int
628 DataAbstract::getRank() const
629 {
630 if (isEmpty())
631 {
632 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
633 }
634 return m_rank;
635 }
636
637 inline
638 unsigned int
639 DataAbstract::getNoValues() const
640 {
641 if (isEmpty())
642 {
643 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
644 }
645 return m_novalues;
646 }
647
648
649 } // end of namespace
650
651 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26