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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1779 - (show annotations)
Thu Sep 11 01:06:15 2008 UTC (10 years, 10 months ago) by jfenwick
File MIME type: text/plain
File size: 21674 byte(s)
Branch commit:

Updated the doxyfile for deprecated/modified options (eg encoding is set 
to UTF-8).
Also set it not to scan directories called .svn or deprecated.

Removed #includes of DataArrayView.h
Moved DataArrayView into a new deprecated directory

Commented out setTaggedValue in DataExpanded which still referred to 
DataArrayView

Fixed some of the doxygen comments in DataMaths.h, DataTypes.h, 
DataTagged.h

Removed the empty JoelMods.cpp_

Unit tests appear to indicate that this branch is now "no more broken" 
than the version I branched from.



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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26