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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1889 - (show annotations)
Thu Oct 16 05:57:09 2008 UTC (11 years, 7 months ago) by jfenwick
File MIME type: text/plain
File size: 21116 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_DataTagged_20040615_H
16 #define escript_DataTagged_20040615_H
17 #include "system_dep.h"
18
19 #include "DataReady.h"
20 #include "DataTypes.h"
21
22 #include <vector>
23 #include <map>
24
25 namespace escript {
26
27 class DataConstant;
28
29 /**
30 \brief
31 Simulates a full dataset accessible via sampleNo and dataPointNo.
32
33 Description:
34 Each data-point has an associated tag number, and a given tag can represent a
35 range of dataPointNo and sampleNo. Each tag indexes only a single data-point.
36 Thus only a single data-point needs to be stored for a range of sampleNo and
37 dataPointNo values.
38 */
39
40 class DataTagged : public DataReady {
41 typedef DataReady parent;
42 public:
43
44 //
45 // Types for the lists of tags and values.
46 typedef std::vector<int> TagListType;
47 // typedef std::vector<DataArrayView> ValueListType;
48 typedef DataTypes::ValueType ValueType;
49 typedef std::vector<ValueType::ElementType> ValueBatchType;
50
51 //
52 // Map from a tag to an offset into the data array.
53 typedef std::map<int, int> DataMapType;
54
55 /**
56 \brief
57 Default constructor for DataTagged.
58
59 Description:
60 Default constructor for DataTagged. Creates a DataTagged object for which
61 the default data-point is a scalar data-point with value 0.0, and no other
62 tag values are stored.
63 T
64 */
65 ESCRIPT_DLL_API
66 DataTagged();
67
68 // /**
69 // \brief
70 // Constructor for DataTagged.
71 //
72 // Description:
73 // Constructor for DataTagged.
74 // \param tagKeys - Input - A vector of integer tags.
75 // \param values - Input - A vector of DataArrayViews. If this is empty
76 // all tag values will be assigned a scalar data-point of value
77 // 0. If it contains one value all tag values will be assigned
78 // this value. Otherwise consecutive tags will be assigned
79 // consecutive values. If there is a mismatch between the
80 // number of keys and the number of values an exception
81 // will be generated.
82 // \param defaultValue - Input - Value returned if a requested tag doesn't exist.
83 // \param what - Input - A description of what this data represents.
84 // T
85 // */
86 // ESCRIPT_DLL_API
87 // DataTagged(const TagListType& tagKeys,
88 // const ValueListType& values,
89 // const DataArrayView& defaultValue,
90 // const FunctionSpace& what);
91
92 /**
93 \brief
94 Alternative Constructor for DataTagged.
95
96 Description:
97 Alternative Constructor for DataTagged.
98 \param what - Input - A description of what this data object represents.
99 \param shape - Input - The shape of each data-point.
100 \param tags - Input - An array of tags, one for each sample number (starts at tag[1]).
101 \param data - The data values for each tag.
102 NB: no unit testing yet
103 */
104 ESCRIPT_DLL_API
105 DataTagged(const FunctionSpace& what,
106 const DataTypes::ShapeType &shape,
107 const int tags[],
108 const ValueType& data);
109
110 /**
111 \brief
112 Alternative Constructor for DataTagged.
113
114 Description:
115 Alternative Constructor for DataTagged.
116 \param what - Input - A description of what this data object represents.
117 \param shape - Input - The shape of each data-point.
118 \param tags - Input - An vector of tags, one for each sample number.
119 \param data - The data values for each tag.
120 TODO Make sure to document the relationship between tags and data, ie: data also contains the default value
121 */
122 ESCRIPT_DLL_API
123 DataTagged(const FunctionSpace& what,
124 const DataTypes::ShapeType &shape,
125 const TagListType& tags,
126 const ValueType& data);
127
128 /**
129 \brief
130 Copy Constructor for DataTagged.
131 Performs a deep copy from the given DataTagged object.
132 T
133 */
134 ESCRIPT_DLL_API
135 DataTagged(const DataTagged& other);
136
137 /**
138 \brief
139 Copy Constructor for DataTagged.
140 Construct a DataTagged object from a DataConstant object.
141 The default value will be the value of the DataConstant object.
142 T
143 */
144 ESCRIPT_DLL_API
145 DataTagged(const DataConstant& other);
146
147 /**
148 \brief
149 Copies the tags from a DataTagged into a new Data Tagged and assigns them the default value. ** Not unit tested **
150
151 This is different from a deep copy because we are not copying shape or other information, just tags.
152 \param what - Input - FunctionSpace for the new DataTagged
153 \param shape - Input - Shape for points in the new DataTagged
154 \param defaultvalue - Input - Default value for new DataTagged
155 \param tagsource - Input - A DataTagged object which supplies the tags.
156 */
157 ESCRIPT_DLL_API
158 DataTagged(const FunctionSpace& what,
159 const DataTypes::ShapeType& shape,
160 const DataTypes::ValueType& defaultvalue,
161 const DataTagged* tagsource=0);
162
163 /**
164 \brief
165 Destructor
166 */
167 ESCRIPT_DLL_API
168 inline virtual
169 ~DataTagged() {};
170
171 ESCRIPT_DLL_API
172 bool
173 isTagged() const
174 {
175 return true;
176 };
177
178
179 /**
180 \brief Return a deep copy of the current object.
181 */
182 ESCRIPT_DLL_API
183 virtual
184 DataAbstract*
185 deepCopy();
186
187
188 /**
189 \brief
190 getSampleDataByTag
191
192 Description:
193 Return the data-point for the given tag. All of the data for the
194 sample will be visible via the returned pointer.
195
196 ** This provides an interface into the data suitable for legacy C code.
197 ** NB: need to do array bounds checking when accessing returned value!
198 T
199 */
200 ESCRIPT_DLL_API
201 virtual
202 double*
203 getSampleDataByTag(int tag);
204
205 /**
206 \brief
207 Write the data as a string.
208 Writes out each tag, including the default, and the data-point which is
209 associated with each tag.
210 T
211 */
212 ESCRIPT_DLL_API
213 virtual
214 std::string
215 toString() const;
216 /**
217 \brief
218 dumps the object into a netCDF file
219 */
220 ESCRIPT_DLL_API
221 virtual
222 void
223 dump(const std::string fileName) const;
224
225 /**
226 \brief
227 sets all values to zero
228 */
229 ESCRIPT_DLL_API
230 virtual
231 void
232 setToZero();
233
234 /**
235 \brief
236 Return the tag number associated with the given data-point number
237 according to the associated function space.
238 T
239 */
240 ESCRIPT_DLL_API
241 virtual
242 int
243 getTagNumber(int dpno);
244
245 /**
246 \brief
247 getPointOffset
248
249 Description:
250 Return the offset to the given data-point value in the underlying
251 data vector.
252
253 \param sampleNo - Input - sample number.
254 \param dataPointNo - Input - data-point number.
255 T
256 */
257 ESCRIPT_DLL_API
258 virtual
259 ValueType::size_type
260 getPointOffset(int sampleNo,
261 int dataPointNo) const;
262
263
264
265 // /**
266 // \brief
267 // addTaggedValues
268 //
269 // Description:
270 // Add the given tags and values to this DataTagged object.
271 // \param tagKeys - Input - A vector of integer tags.
272 // \param values - Input - A vector of DataArrayViews. If this is empty
273 // all tag values will be assigned a scalar data-point of value
274 // 0. If it contains one value all tag values will be assigned
275 // this value. Otherwise consecutive tags will be assigned
276 // consecutive values. If there is a mismatch between the
277 // number of keys and the number of values an exception
278 // will be generated.
279 // T
280 // */
281 // ESCRIPT_DLL_API
282 // void
283 // addTaggedValues(const TagListType& tagKeys,
284 // const ValueListType& values);
285
286 // /**
287 // \brief
288 // addTaggedValue
289 //
290 // Description:
291 // Add a single tag and value to this DataTagged object. If this tag already has
292 // a value associated with it, setTaggedValue will be used to update this value.
293 // \param tagKey - Input - Integer tag.
294 // \param value - Input - Single DataArrayView value to be assigned to the tag.
295 // T
296 // */
297 // ESCRIPT_DLL_API
298 // void
299 // addTaggedValue(int tagKey,
300 // const DataArrayView& value);
301
302
303
304 /**
305 \brief
306 addTaggedValues
307
308 Description:
309 Add the given tags and values to this DataTagged object.
310 \param tagKeys - Input - A vector of integer tags.
311 \param values - Input - A vector of doubles. If this is empty, the default value for
312 this DataTagged will be used for all tags.
313 If it contains one value all tag values will be assigned
314 this value. Otherwise consecutive tags will be assigned
315 consecutive values. If there is a mismatch between the
316 number of keys and the number of values an exception
317 will be generated.
318 \param vShape - shape of the datapoints in "values"
319 T
320 */
321 ESCRIPT_DLL_API
322 void
323 addTaggedValues(const TagListType& tagKeys,
324 const ValueBatchType& values,
325 const ShapeType& vShape);
326
327
328 /**
329 Description:
330 Add the given tags and values to this DataTagged object.
331 \param tagKeys - Input - A vector of integer tags.
332 \param values - Input - A DataVector containing the datapoints.
333 If this is empty, the default value for
334 this DataTagged will be used for all tags.
335 If it contains one value all tag values will be assigned
336 this value. Otherwise consecutive tags will be assigned
337 consecutive values. If there is a mismatch between the
338 number of keys and the number of values an exception
339 will be generated.
340 \param vShape - shape of the datapoints in "values"
341
342 TODO Makesure this is properly unit tested
343 */
344 ESCRIPT_DLL_API
345 void
346 addTaggedValues(const TagListType& tagKeys,
347 const ValueType& values,
348 const ShapeType& vShape);
349
350
351
352
353 /**
354 \brief
355 addTaggedValue
356
357 Description:
358 Add a single tag and value to this DataTagged object. If this tag already has
359 a value associated with it, setTaggedValue will be used to update this value.
360 \param tagKey - Input - Integer tag.
361 \param pointshape - Shape of the value parameter
362 \param value - Input - Single DataArrayView value to be assigned to the tag.
363 \param dataOffset - Input - Offset of the beginning of the point in the value parameter
364 */
365 ESCRIPT_DLL_API
366 void
367 addTaggedValue(int tagKey,
368 const DataTypes::ShapeType& pointshape,
369 const ValueType& value,
370 int dataOffset=0);
371
372 /**
373 \brief
374 addTag - does not modify the default value for this object. ** Not unit tested **
375
376 Description:
377 Add a single tag. The default value for this DataTagged will be associated with the tag.
378 If this tag already has a value associated with it, then no change will be made.
379 \param tagKey - Input - Integer tag.
380 TODO: Make sure this is unit tested
381 */
382 ESCRIPT_DLL_API
383 void
384 addTag(int tagKey);
385
386
387 // /**
388 // \brief
389 // setTaggedValues
390 //
391 // Description:
392 // Set the given tags to the given values in this DataTagged object.
393 // \param tagKeys - Input - A vector of integer tag.
394 // \param values - Input - A vector of DataArrayViews. If this is empty
395 // all tag values will be assigned a scalar data-point of value
396 // 0. If it contains one value all tag values will be assigned
397 // this value. Otherwise consecutive tags will be assigned
398 // consecutive values. If there is a mismatch between the
399 // number of keys and the number of values an exception
400 // will be generated.
401 // T
402 // */
403 // ESCRIPT_DLL_API
404 // void
405 // setTaggedValues(const TagListType& tagKeys,
406 // const ValueListType& values);
407
408 // /**
409 // \brief
410 // setTaggedValue
411 //
412 // Description:
413 // Assign the given value to the given tag.
414 // \param tagKey - Input - Integer tag.
415 // \param value - Input - Single DataArrayView value to be assigned to the tag.
416 // T
417 // */
418 // ESCRIPT_DLL_API
419 // virtual
420 // void
421 // setTaggedValue(int tagKey,
422 // const DataArrayView& value);
423
424 /**
425 \brief
426 setTaggedValue
427
428 Description:
429 Assign the given value to the given tag.
430 \param tagKey - Input - Integer tag.
431 \param pointshape - the shape of the value parameter
432 \param value - Input - Vector storing the datapoint to be assigned to the tag.
433 \param dataOffset - beginning of the datapoint within "value".
434 T
435 */
436 ESCRIPT_DLL_API
437 void
438 setTaggedValue(int tagKey,
439 const DataTypes::ShapeType& pointshape,
440 const ValueType& value,
441 int dataOffset=0);
442
443
444 // /**
445 // \brief
446 // getDataPointByTag
447 //
448 // Description:
449 // Return data-point associated with the given tag as a DataArrayView.
450 // \param tag - Input - Integer key.
451 // T
452 // */
453 // ESCRIPT_DLL_API
454 // DataArrayView
455 // getDataPointByTag(int tag) const;
456
457 /**
458 \brief
459 getDataByTag
460
461 Return a pointer to the beginning of the datapoint with the specified tag.
462 TODO Eventually these should be inlined.
463 \param tag - Input - Integer key.
464 \param i - position in the underlying datastructure
465 T
466 */
467 ESCRIPT_DLL_API
468 DataTypes::ValueType::const_reference
469 getDataByTag(int tag, DataTypes::ValueType::size_type i) const;
470
471 ESCRIPT_DLL_API
472 DataTypes::ValueType::reference
473 getDataByTag(int tag, DataTypes::ValueType::size_type i);
474
475
476 /**
477 \brief
478 getOffsetForTag
479
480 \param tag
481 \return the offset of the beginning of the datapoint corresponding to tag.
482
483 Note: If the tag is not valid, the offset of the default value is returned instead.
484 */
485 ESCRIPT_DLL_API
486 DataTypes::ValueType::size_type
487 getOffsetForTag(int tag) const;
488
489 // /**
490 // \brief
491 // getDataPoint
492 //
493 // Description:
494 // Return the data-point specified by the given sample and data-point
495 // numbers as a DataArrayView.
496 // \param sampleNo - Input.
497 // \param dataPointNo - Input.
498 // T
499 // */
500 // ESCRIPT_DLL_API
501 // virtual
502 // DataArrayView
503 // getDataPoint(int sampleNo,
504 // int dataPointNo);
505
506
507 /**
508 \brief
509 Return a reference to the underlying DataVector.
510 */
511
512 ESCRIPT_DLL_API
513 DataTypes::ValueType&
514 getVector();
515
516 ESCRIPT_DLL_API
517 const DataTypes::ValueType&
518 getVector() const;
519
520
521
522 /**
523 \brief
524 getData
525
526 Description:
527 Return pointer to the data
528 T
529 */
530 // ESCRIPT_DLL_API
531 // const DataTypes::ValueType::ElementType*
532 // getData() const;
533
534 /**
535 \brief
536 getTagLookup
537
538 Description:
539 Return a reference to the tag offset lookup table.
540 T
541 */
542 ESCRIPT_DLL_API
543 const DataMapType&
544 getTagLookup() const;
545
546 /**
547 \brief
548 isCurrentTag
549
550 Description:
551 Return true if the given tag exists within the DataTagged tag map.
552
553 *** NB: The DataTagged tag map does not necessarily coincide with the tag
554 keys in the associated function space.
555 T
556 */
557 ESCRIPT_DLL_API
558 bool
559 isCurrentTag(int tag) const;
560
561 // /**
562 // \brief
563 // getDefaultValue
564 //
565 // Description:
566 // Return the default value. This value is associated with any tag which
567 // is not explicitly recorded in this DataTagged object's tag map.
568 // T
569 // */
570 // ESCRIPT_DLL_API
571 // DataArrayView&
572 // getDefaultValue();
573 //
574 // ESCRIPT_DLL_API
575 // const DataArrayView&
576 // getDefaultValue() const;
577
578 /**
579 \brief
580 getDefaultValue
581
582 Description:
583 Return the default value. This value is associated with any tag which
584 is not explicitly recorded in this DataTagged object's tag map.
585 \param i - position in the underlying datastructure
586 T
587 */
588 ESCRIPT_DLL_API
589 DataTypes::ValueType::reference
590 getDefaultValue(DataTypes::ValueType::size_type i);
591
592 ESCRIPT_DLL_API
593 DataTypes::ValueType::const_reference
594 getDefaultValue(DataTypes::ValueType::size_type i) const;
595
596
597
598
599 /**
600 \brief
601 getLength
602
603 Description:
604 Return the total number of doubles stored for this DataTagged object.
605 T
606 */
607 ESCRIPT_DLL_API
608 virtual
609 ValueType::size_type
610 getLength() const;
611
612 /**
613 \brief
614 getSlice
615
616 Description:
617 Factory method that returns a newly created DataTagged object generated
618 by taking the specified slice from this DataTagged object.
619 The caller is reponsible for managing the returned object.
620 T
621 */
622 ESCRIPT_DLL_API
623 virtual
624 DataAbstract*
625 getSlice(const DataTypes::RegionType& region) const;
626
627 /**
628 \brief
629 Slice Constructor for DataTagged.
630
631 Description:
632 Creates a DataTagged object which is the specified slice
633 from the given DataTagged object.
634 \param other - Input - DataTagged object to slice from.
635 \param region - Input - Region to slice.
636 T
637 */
638 ESCRIPT_DLL_API
639 DataTagged(const DataTagged& other,
640 const DataTypes::RegionType& region);
641
642 /**
643 \brief
644 setSlice
645
646 Description:
647 Copy the given Data object into the specified region in this object.
648 \param other - Input - Data object to copy from.
649 \param region - Input - Region to copy into (NB: must have same shape as other!).
650 T
651 */
652 ESCRIPT_DLL_API
653 virtual
654 void
655 setSlice(const DataAbstract* other,
656 const DataTypes::RegionType& region);
657
658
659 /**
660 \brief
661 Computes a symmetric matrix (A + AT) / 2
662
663 \param ev - Output - symmetric matrix
664
665 */
666 ESCRIPT_DLL_API
667 virtual void
668 symmetric(DataAbstract* ev);
669
670 /**
671 \brief
672 Computes a nonsymmetric matrix (A - AT) / 2
673
674 \param ev - Output - nonsymmetric matrix
675
676 */
677 ESCRIPT_DLL_API
678 virtual void
679 nonsymmetric(DataAbstract* ev);
680
681 /**
682 \brief
683 Computes the trace of a matrix
684
685 \param ev - Output - the trace of a matrix
686
687 */
688 ESCRIPT_DLL_API
689 virtual void
690 trace(DataAbstract* ev, int axis_offset);
691
692 /**
693 \brief
694 swaps components axis0 and axis1
695
696 \param ev - Output - swapped components
697
698 */
699 ESCRIPT_DLL_API
700 virtual void
701 swapaxes(DataAbstract* ev, int axis0, int axis1);
702
703 /**
704 \brief
705 Transpose each data point of this Data object around the given axis.
706
707 \param ev - Output - the transpose of a matrix
708
709 */
710 ESCRIPT_DLL_API
711 virtual void
712 transpose(DataAbstract* ev, int axis_offset);
713
714 /**
715 \brief
716 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
717
718 \param ev - Output - eigenvalues in increasing order at each data point
719
720 */
721 ESCRIPT_DLL_API
722 virtual void
723 eigenvalues(DataAbstract* ev);
724
725 /**
726 \brief
727 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
728
729 \param ev - Output - eigenvalues in increasing order at each data point
730 \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
731 and the first nonzero component is positive.
732 \param tol - Input - eigenvalue with relative distance tol are treated as equal.
733
734 */
735
736 ESCRIPT_DLL_API
737 virtual void
738 eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
739
740
741 /**
742 \brief Returns the offset in the structure which stores the default value
743 */
744 ESCRIPT_DLL_API
745 DataTypes::ValueType::size_type
746 getDefaultOffset() const;
747
748 protected:
749
750 private:
751
752 //
753 // The offset lookup table
754 DataMapType m_offsetLookup;
755
756 //
757 // the offset to the default value
758 static const int m_defaultValueOffset = 0;
759
760 //
761 // The actual data
762 ValueType m_data;
763
764 };
765
766 inline
767 bool
768 DataTagged::isCurrentTag(int tag) const
769 {
770 DataMapType::const_iterator pos(m_offsetLookup.find(tag));
771 return (pos!=m_offsetLookup.end());
772 }
773
774 // inline
775 // DataArrayView&
776 // DataTagged::getDefaultValue()
777 // {
778 // // The default value is always the first value.
779 // return getPointDataView();
780 // }
781
782 // inline
783 // const DataArrayView&
784 // DataTagged::getDefaultValue() const
785 // {
786 // // The default value is always the first value.
787 // return getPointDataView();
788 // }
789
790
791 inline
792 DataTypes::ValueType::size_type
793 DataTagged::getDefaultOffset() const
794 {
795 return m_defaultValueOffset;
796 }
797
798 inline
799 DataTypes::ValueType::reference
800 DataTagged::getDefaultValue(DataTypes::ValueType::size_type i)
801 {
802 return getVector()[i];
803 }
804
805 inline
806 DataTypes::ValueType::const_reference
807 DataTagged::getDefaultValue(DataTypes::ValueType::size_type i) const
808 {
809 return getVector()[i];
810 }
811
812
813
814
815 // inline
816 // const DataTypes::ValueType::ElementType*
817 // DataTagged::getData() const
818 // {
819 // return &(m_data[0]);
820 // }
821
822 inline
823 const DataTagged::DataMapType&
824 DataTagged::getTagLookup() const
825 {
826 return m_offsetLookup;
827 }
828
829 inline
830 DataTypes::ValueType::size_type
831 DataTagged::getLength() const
832 {
833 return m_data.size();
834 }
835
836 } // end of namespace
837
838 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26