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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (10 years, 5 months ago) by ksteube
File MIME type: text/plain
File size: 21024 byte(s)
Copyright updated in all files

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 "DataAbstract.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 DataAbstract {
41
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 /**
172 \brief Return a deep copy of the current object.
173 */
174 ESCRIPT_DLL_API
175 virtual
176 DataAbstract*
177 deepCopy();
178
179
180 /**
181 \brief
182 getSampleDataByTag
183
184 Description:
185 Return the data-point for the given tag. All of the data for the
186 sample will be visible via the returned pointer.
187
188 ** This provides an interface into the data suitable for legacy C code.
189 ** NB: need to do array bounds checking when accessing returned value!
190 T
191 */
192 ESCRIPT_DLL_API
193 virtual
194 double*
195 getSampleDataByTag(int tag);
196
197 /**
198 \brief
199 Write the data as a string.
200 Writes out each tag, including the default, and the data-point which is
201 associated with each tag.
202 T
203 */
204 ESCRIPT_DLL_API
205 virtual
206 std::string
207 toString() const;
208 /**
209 \brief
210 dumps the object into a netCDF file
211 */
212 ESCRIPT_DLL_API
213 virtual
214 void
215 dump(const std::string fileName) const;
216
217 /**
218 \brief
219 sets all values to zero
220 */
221 ESCRIPT_DLL_API
222 virtual
223 void
224 setToZero();
225
226 /**
227 \brief
228 Return the tag number associated with the given data-point number
229 according to the associated function space.
230 T
231 */
232 ESCRIPT_DLL_API
233 virtual
234 int
235 getTagNumber(int dpno);
236
237 /**
238 \brief
239 getPointOffset
240
241 Description:
242 Return the offset to the given data-point value in the underlying
243 data vector.
244
245 \param sampleNo - Input - sample number.
246 \param dataPointNo - Input - data-point number.
247 T
248 */
249 ESCRIPT_DLL_API
250 virtual
251 ValueType::size_type
252 getPointOffset(int sampleNo,
253 int dataPointNo) const;
254
255
256
257 // /**
258 // \brief
259 // addTaggedValues
260 //
261 // Description:
262 // Add the given tags and values to this DataTagged object.
263 // \param tagKeys - Input - A vector of integer tags.
264 // \param values - Input - A vector of DataArrayViews. If this is empty
265 // all tag values will be assigned a scalar data-point of value
266 // 0. If it contains one value all tag values will be assigned
267 // this value. Otherwise consecutive tags will be assigned
268 // consecutive values. If there is a mismatch between the
269 // number of keys and the number of values an exception
270 // will be generated.
271 // T
272 // */
273 // ESCRIPT_DLL_API
274 // void
275 // addTaggedValues(const TagListType& tagKeys,
276 // const ValueListType& values);
277
278 // /**
279 // \brief
280 // addTaggedValue
281 //
282 // Description:
283 // Add a single tag and value to this DataTagged object. If this tag already has
284 // a value associated with it, setTaggedValue will be used to update this value.
285 // \param tagKey - Input - Integer tag.
286 // \param value - Input - Single DataArrayView value to be assigned to the tag.
287 // T
288 // */
289 // ESCRIPT_DLL_API
290 // void
291 // addTaggedValue(int tagKey,
292 // const DataArrayView& value);
293
294
295
296 /**
297 \brief
298 addTaggedValues
299
300 Description:
301 Add the given tags and values to this DataTagged object.
302 \param tagKeys - Input - A vector of integer tags.
303 \param values - Input - A vector of doubles. If this is empty, the default value for
304 this DataTagged will be used for all tags.
305 If it contains one value all tag values will be assigned
306 this value. Otherwise consecutive tags will be assigned
307 consecutive values. If there is a mismatch between the
308 number of keys and the number of values an exception
309 will be generated.
310 \param vShape - shape of the datapoints in "values"
311 T
312 */
313 ESCRIPT_DLL_API
314 void
315 addTaggedValues(const TagListType& tagKeys,
316 const ValueBatchType& values,
317 const ShapeType& vShape);
318
319
320 /**
321 Description:
322 Add the given tags and values to this DataTagged object.
323 \param tagKeys - Input - A vector of integer tags.
324 \param values - Input - A DataVector containing the datapoints.
325 If this is empty, the default value for
326 this DataTagged will be used for all tags.
327 If it contains one value all tag values will be assigned
328 this value. Otherwise consecutive tags will be assigned
329 consecutive values. If there is a mismatch between the
330 number of keys and the number of values an exception
331 will be generated.
332 \param vShape - shape of the datapoints in "values"
333
334 TODO Makesure this is properly unit tested
335 */
336 ESCRIPT_DLL_API
337 void
338 addTaggedValues(const TagListType& tagKeys,
339 const ValueType& values,
340 const ShapeType& vShape);
341
342
343
344
345 /**
346 \brief
347 addTaggedValue
348
349 Description:
350 Add a single tag and value to this DataTagged object. If this tag already has
351 a value associated with it, setTaggedValue will be used to update this value.
352 \param tagKey - Input - Integer tag.
353 \param pointshape - Shape of the value parameter
354 \param value - Input - Single DataArrayView value to be assigned to the tag.
355 \param dataOffset - Input - Offset of the beginning of the point in the value parameter
356 */
357 ESCRIPT_DLL_API
358 void
359 addTaggedValue(int tagKey,
360 const DataTypes::ShapeType& pointshape,
361 const ValueType& value,
362 int dataOffset=0);
363
364 /**
365 \brief
366 addTag - does not modify the default value for this object. ** Not unit tested **
367
368 Description:
369 Add a single tag. The default value for this DataTagged will be associated with the tag.
370 If this tag already has a value associated with it, then no change will be made.
371 \param tagKey - Input - Integer tag.
372 TODO: Make sure this is unit tested
373 */
374 ESCRIPT_DLL_API
375 void
376 addTag(int tagKey);
377
378
379 // /**
380 // \brief
381 // setTaggedValues
382 //
383 // Description:
384 // Set the given tags to the given values in this DataTagged object.
385 // \param tagKeys - Input - A vector of integer tag.
386 // \param values - Input - A vector of DataArrayViews. If this is empty
387 // all tag values will be assigned a scalar data-point of value
388 // 0. If it contains one value all tag values will be assigned
389 // this value. Otherwise consecutive tags will be assigned
390 // consecutive values. If there is a mismatch between the
391 // number of keys and the number of values an exception
392 // will be generated.
393 // T
394 // */
395 // ESCRIPT_DLL_API
396 // void
397 // setTaggedValues(const TagListType& tagKeys,
398 // const ValueListType& values);
399
400 // /**
401 // \brief
402 // setTaggedValue
403 //
404 // Description:
405 // Assign the given value to the given tag.
406 // \param tagKey - Input - Integer tag.
407 // \param value - Input - Single DataArrayView value to be assigned to the tag.
408 // T
409 // */
410 // ESCRIPT_DLL_API
411 // virtual
412 // void
413 // setTaggedValue(int tagKey,
414 // const DataArrayView& value);
415
416 /**
417 \brief
418 setTaggedValue
419
420 Description:
421 Assign the given value to the given tag.
422 \param tagKey - Input - Integer tag.
423 \param pointshape - the shape of the value parameter
424 \param value - Input - Vector storing the datapoint to be assigned to the tag.
425 \param dataOffset - beginning of the datapoint within "value".
426 T
427 */
428 ESCRIPT_DLL_API
429 void
430 setTaggedValue(int tagKey,
431 const DataTypes::ShapeType& pointshape,
432 const ValueType& value,
433 int dataOffset=0);
434
435
436 // /**
437 // \brief
438 // getDataPointByTag
439 //
440 // Description:
441 // Return data-point associated with the given tag as a DataArrayView.
442 // \param tag - Input - Integer key.
443 // T
444 // */
445 // ESCRIPT_DLL_API
446 // DataArrayView
447 // getDataPointByTag(int tag) const;
448
449 /**
450 \brief
451 getDataByTag
452
453 Return a pointer to the beginning of the datapoint with the specified tag.
454 TODO Eventually these should be inlined.
455 \param tag - Input - Integer key.
456 \param i - position in the underlying datastructure
457 T
458 */
459 ESCRIPT_DLL_API
460 DataTypes::ValueType::const_reference
461 getDataByTag(int tag, DataTypes::ValueType::size_type i) const;
462
463 ESCRIPT_DLL_API
464 DataTypes::ValueType::reference
465 getDataByTag(int tag, DataTypes::ValueType::size_type i);
466
467
468 /**
469 \brief
470 getOffsetForTag
471
472 \param tag
473 \return the offset of the beginning of the datapoint corresponding to tag.
474
475 Note: If the tag is not valid, the offset of the default value is returned instead.
476 */
477 ESCRIPT_DLL_API
478 DataTypes::ValueType::size_type
479 getOffsetForTag(int tag) const;
480
481 // /**
482 // \brief
483 // getDataPoint
484 //
485 // Description:
486 // Return the data-point specified by the given sample and data-point
487 // numbers as a DataArrayView.
488 // \param sampleNo - Input.
489 // \param dataPointNo - Input.
490 // T
491 // */
492 // ESCRIPT_DLL_API
493 // virtual
494 // DataArrayView
495 // getDataPoint(int sampleNo,
496 // int dataPointNo);
497
498
499 /**
500 \brief
501 Return a reference to the underlying DataVector.
502 */
503
504 ESCRIPT_DLL_API
505 DataTypes::ValueType&
506 getVector();
507
508 ESCRIPT_DLL_API
509 const DataTypes::ValueType&
510 getVector() const;
511
512
513
514 /**
515 \brief
516 getData
517
518 Description:
519 Return pointer to the data
520 T
521 */
522 // ESCRIPT_DLL_API
523 // const DataTypes::ValueType::ElementType*
524 // getData() const;
525
526 /**
527 \brief
528 getTagLookup
529
530 Description:
531 Return a reference to the tag offset lookup table.
532 T
533 */
534 ESCRIPT_DLL_API
535 const DataMapType&
536 getTagLookup() const;
537
538 /**
539 \brief
540 isCurrentTag
541
542 Description:
543 Return true if the given tag exists within the DataTagged tag map.
544
545 *** NB: The DataTagged tag map does not necessarily coincide with the tag
546 keys in the associated function space.
547 T
548 */
549 ESCRIPT_DLL_API
550 bool
551 isCurrentTag(int tag) const;
552
553 // /**
554 // \brief
555 // getDefaultValue
556 //
557 // Description:
558 // Return the default value. This value is associated with any tag which
559 // is not explicitly recorded in this DataTagged object's tag map.
560 // T
561 // */
562 // ESCRIPT_DLL_API
563 // DataArrayView&
564 // getDefaultValue();
565 //
566 // ESCRIPT_DLL_API
567 // const DataArrayView&
568 // getDefaultValue() const;
569
570 /**
571 \brief
572 getDefaultValue
573
574 Description:
575 Return the default value. This value is associated with any tag which
576 is not explicitly recorded in this DataTagged object's tag map.
577 \param i - position in the underlying datastructure
578 T
579 */
580 ESCRIPT_DLL_API
581 DataTypes::ValueType::reference
582 getDefaultValue(DataTypes::ValueType::size_type i);
583
584 ESCRIPT_DLL_API
585 DataTypes::ValueType::const_reference
586 getDefaultValue(DataTypes::ValueType::size_type i) const;
587
588
589
590
591 /**
592 \brief
593 getLength
594
595 Description:
596 Return the total number of doubles stored for this DataTagged object.
597 T
598 */
599 ESCRIPT_DLL_API
600 virtual
601 ValueType::size_type
602 getLength() const;
603
604 /**
605 \brief
606 getSlice
607
608 Description:
609 Factory method that returns a newly created DataTagged object generated
610 by taking the specified slice from this DataTagged object.
611 The caller is reponsible for managing the returned object.
612 T
613 */
614 ESCRIPT_DLL_API
615 virtual
616 DataAbstract*
617 getSlice(const DataTypes::RegionType& region) const;
618
619 /**
620 \brief
621 Slice Constructor for DataTagged.
622
623 Description:
624 Creates a DataTagged object which is the specified slice
625 from the given DataTagged object.
626 \param other - Input - DataTagged object to slice from.
627 \param region - Input - Region to slice.
628 T
629 */
630 ESCRIPT_DLL_API
631 DataTagged(const DataTagged& other,
632 const DataTypes::RegionType& region);
633
634 /**
635 \brief
636 setSlice
637
638 Description:
639 Copy the given Data object into the specified region in this object.
640 \param other - Input - Data object to copy from.
641 \param region - Input - Region to copy into (NB: must have same shape as other!).
642 T
643 */
644 ESCRIPT_DLL_API
645 virtual
646 void
647 setSlice(const DataAbstract* other,
648 const DataTypes::RegionType& region);
649
650
651 /**
652 \brief
653 Computes a symmetric matrix (A + AT) / 2
654
655 \param ev - Output - symmetric matrix
656
657 */
658 ESCRIPT_DLL_API
659 virtual void
660 symmetric(DataAbstract* ev);
661
662 /**
663 \brief
664 Computes a nonsymmetric matrix (A - AT) / 2
665
666 \param ev - Output - nonsymmetric matrix
667
668 */
669 ESCRIPT_DLL_API
670 virtual void
671 nonsymmetric(DataAbstract* ev);
672
673 /**
674 \brief
675 Computes the trace of a matrix
676
677 \param ev - Output - the trace of a matrix
678
679 */
680 ESCRIPT_DLL_API
681 virtual void
682 trace(DataAbstract* ev, int axis_offset);
683
684 /**
685 \brief
686 swaps components axis0 and axis1
687
688 \param ev - Output - swapped components
689
690 */
691 ESCRIPT_DLL_API
692 virtual void
693 swapaxes(DataAbstract* ev, int axis0, int axis1);
694
695 /**
696 \brief
697 Transpose each data point of this Data object around the given axis.
698
699 \param ev - Output - the transpose of a matrix
700
701 */
702 ESCRIPT_DLL_API
703 virtual void
704 transpose(DataAbstract* ev, int axis_offset);
705
706 /**
707 \brief
708 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
709
710 \param ev - Output - eigenvalues in increasing order at each data point
711
712 */
713 ESCRIPT_DLL_API
714 virtual void
715 eigenvalues(DataAbstract* ev);
716
717 /**
718 \brief
719 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
720
721 \param ev - Output - eigenvalues in increasing order at each data point
722 \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
723 and the first nonzero component is positive.
724 \param tol - Input - eigenvalue with relative distance tol are treated as equal.
725
726 */
727
728 ESCRIPT_DLL_API
729 virtual void
730 eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
731
732
733 /**
734 \brief Returns the offset in the structure which stores the default value
735 */
736 ESCRIPT_DLL_API
737 DataTypes::ValueType::size_type
738 getDefaultOffset() const;
739
740 protected:
741
742 private:
743
744 //
745 // The offset lookup table
746 DataMapType m_offsetLookup;
747
748 //
749 // the offset to the default value
750 static const int m_defaultValueOffset = 0;
751
752 //
753 // The actual data
754 ValueType m_data;
755
756 };
757
758 inline
759 bool
760 DataTagged::isCurrentTag(int tag) const
761 {
762 DataMapType::const_iterator pos(m_offsetLookup.find(tag));
763 return (pos!=m_offsetLookup.end());
764 }
765
766 // inline
767 // DataArrayView&
768 // DataTagged::getDefaultValue()
769 // {
770 // // The default value is always the first value.
771 // return getPointDataView();
772 // }
773
774 // inline
775 // const DataArrayView&
776 // DataTagged::getDefaultValue() const
777 // {
778 // // The default value is always the first value.
779 // return getPointDataView();
780 // }
781
782
783 inline
784 DataTypes::ValueType::size_type
785 DataTagged::getDefaultOffset() const
786 {
787 return m_defaultValueOffset;
788 }
789
790 inline
791 DataTypes::ValueType::reference
792 DataTagged::getDefaultValue(DataTypes::ValueType::size_type i)
793 {
794 return getVector()[i];
795 }
796
797 inline
798 DataTypes::ValueType::const_reference
799 DataTagged::getDefaultValue(DataTypes::ValueType::size_type i) const
800 {
801 return getVector()[i];
802 }
803
804
805
806
807 // inline
808 // const DataTypes::ValueType::ElementType*
809 // DataTagged::getData() const
810 // {
811 // return &(m_data[0]);
812 // }
813
814 inline
815 const DataTagged::DataMapType&
816 DataTagged::getTagLookup() const
817 {
818 return m_offsetLookup;
819 }
820
821 inline
822 DataTypes::ValueType::size_type
823 DataTagged::getLength() const
824 {
825 return m_data.size();
826 }
827
828 } // end of namespace
829
830 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26