/[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 1712 - (show annotations)
Wed Aug 20 05:04:28 2008 UTC (12 years, 1 month ago) by jfenwick
File MIME type: text/plain
File size: 17265 byte(s)
Branch commit.

Finished first pass of Data.h - There is still a constructor which takes 
a DataArrayView as a parameter. Apart from that, there are no direct 
references to DataArrayView.

DataTagged has a new constructor for copying just the tags from an 
existing object.
DataTypes:: now has a scalarShape constant (to avoid creating one 
everytime you create a scalar).



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 "DataArrayView.h"
22 #include "DataTypes.h"
23
24 #include <vector>
25 #include <map>
26
27 namespace escript {
28
29 class DataConstant;
30
31 /**
32 \brief
33 Simulates a full dataset accessible via sampleNo and dataPointNo.
34
35 Description:
36 Each data-point has an associated tag number, and a given tag can represent a
37 range of dataPointNo and sampleNo. Each tag indexes only a single data-point.
38 Thus only a single data-point needs to be stored for a range of sampleNo and
39 dataPointNo values.
40 */
41
42 class DataTagged : public DataAbstract {
43
44 public:
45
46 //
47 // Types for the lists of tags and values.
48 typedef std::vector<int> TagListType;
49 typedef std::vector<DataArrayView> ValueListType;
50 typedef DataTypes::ValueType ValueType;
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.
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 NB: no unit testing yet
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);
163
164
165
166 /**
167 \brief
168 Destructor
169 */
170 ESCRIPT_DLL_API
171 inline virtual
172 ~DataTagged() {};
173
174 /**
175 \brief
176 getSampleDataByTag
177
178 Description:
179 Return the data-point for the given tag. All of the data for the
180 sample will be visible via the returned pointer.
181
182 ** This provides an interface into the data suitable for legacy C code.
183 ** NB: need to do array bounds checking when accessing returned value!
184 T
185 */
186 ESCRIPT_DLL_API
187 virtual
188 double*
189 getSampleDataByTag(int tag);
190
191 /**
192 \brief
193 Write the data as a string.
194 Writes out each tag, including the default, and the data-point which is
195 associated with each tag.
196 T
197 */
198 ESCRIPT_DLL_API
199 virtual
200 std::string
201 toString() const;
202 /**
203 \brief
204 dumps the object into a netCDF file
205 */
206 ESCRIPT_DLL_API
207 virtual
208 void
209 dump(const std::string fileName) const;
210
211 /**
212 \brief
213 sets all values to zero
214 */
215 ESCRIPT_DLL_API
216 virtual
217 void
218 setToZero();
219
220 /**
221 \brief
222 Return the tag number associated with the given data-point number
223 according to the associated function space.
224 T
225 */
226 ESCRIPT_DLL_API
227 virtual
228 int
229 getTagNumber(int dpno);
230
231 /**
232 \brief
233 getPointOffset
234
235 Description:
236 Return the offset to the given data-point value in the underlying
237 data vector.
238
239 \param sampleNo - Input - sample number.
240 \param dataPointNo - Input - data-point number.
241 T
242 */
243 ESCRIPT_DLL_API
244 virtual
245 ValueType::size_type
246 getPointOffset(int sampleNo,
247 int dataPointNo) const;
248
249
250
251 /**
252 \brief
253 addTaggedValues
254
255 Description:
256 Add the given tags and values to this DataTagged object.
257 \param tagKeys - Input - A vector of integer tags.
258 \param values - Input - A vector of DataArrayViews. If this is empty
259 all tag values will be assigned a scalar data-point of value
260 0. If it contains one value all tag values will be assigned
261 this value. Otherwise consecutive tags will be assigned
262 consecutive values. If there is a mismatch between the
263 number of keys and the number of values an exception
264 will be generated.
265 T
266 */
267 ESCRIPT_DLL_API
268 void
269 addTaggedValues(const TagListType& tagKeys,
270 const ValueListType& values);
271
272 /**
273 \brief
274 addTaggedValue
275
276 Description:
277 Add a single tag and value to this DataTagged object. If this tag already has
278 a value associated with it, setTaggedValue will be used to update this value.
279 \param tagKey - Input - Integer tag.
280 \param value - Input - Single DataArrayView value to be assigned to the tag.
281 T
282 */
283 ESCRIPT_DLL_API
284 void
285 addTaggedValue(int tagKey,
286 const DataArrayView& value);
287
288 /**
289 \brief
290 addTag - does not modify the default value for this object. ** Not unit tested **
291
292 Description:
293 Add a single tag. The default value for this DataTagged will be associated with the tag.
294 If this tag already has a value associated with it, then no change will be made.
295 \param tagKey - Input - Integer tag.
296 T
297 */
298 ESCRIPT_DLL_API
299 void
300 addTag(int tagKey);
301
302
303 /**
304 \brief
305 setTaggedValues
306
307 Description:
308 Set the given tags to the given values in this DataTagged object.
309 \param tagKeys - Input - A vector of integer tag.
310 \param values - Input - A vector of DataArrayViews. If this is empty
311 all tag values will be assigned a scalar data-point of value
312 0. If it contains one value all tag values will be assigned
313 this value. Otherwise consecutive tags will be assigned
314 consecutive values. If there is a mismatch between the
315 number of keys and the number of values an exception
316 will be generated.
317 T
318 */
319 ESCRIPT_DLL_API
320 void
321 setTaggedValues(const TagListType& tagKeys,
322 const ValueListType& values);
323
324 /**
325 \brief
326 setTaggedValue
327
328 Description:
329 Assign the given value to the given tag.
330 \param tagKey - Input - Integer tag.
331 \param value - Input - Single DataArrayView value to be assigned to the tag.
332 T
333 */
334 ESCRIPT_DLL_API
335 virtual
336 void
337 setTaggedValue(int tagKey,
338 const DataArrayView& value);
339
340 /**
341 \brief
342 getDataPointByTag
343
344 Description:
345 Return data-point associated with the given tag as a DataArrayView.
346 \param tag - Input - Integer key.
347 T
348 */
349 ESCRIPT_DLL_API
350 DataArrayView
351 getDataPointByTag(int tag) const;
352
353 /**
354 \brief
355 getDataByTag
356
357 Return a pointer to the beginning of the datapoint with the specified tag.
358 TODO Eventually these should be inlined.
359 \param tag - Input - Integer key.
360 \param i - position in the underlying datastructure
361 T
362 */
363 ESCRIPT_DLL_API
364 DataTypes::ValueType::const_reference
365 getDataByTag(int tag, DataTypes::ValueType::size_type i) const;
366
367 ESCRIPT_DLL_API
368 DataTypes::ValueType::reference
369 getDataByTag(int tag, DataTypes::ValueType::size_type i);
370
371
372 /**
373 \brief
374 getDataPoint
375
376 Description:
377 Return the data-point specified by the given sample and data-point
378 numbers as a DataArrayView.
379 \param sampleNo - Input.
380 \param dataPointNo - Input.
381 T
382 */
383 ESCRIPT_DLL_API
384 virtual
385 DataArrayView
386 getDataPoint(int sampleNo,
387 int dataPointNo);
388
389 /**
390 \brief
391 getData
392
393 Description:
394 Return pointer to the data
395 T
396 */
397 ESCRIPT_DLL_API
398 const DataTypes::ValueType::ElementType*
399 getData() const;
400
401 /**
402 \brief
403 getTagLookup
404
405 Description:
406 Return a reference to the tag offset lookup table.
407 T
408 */
409 ESCRIPT_DLL_API
410 const DataMapType&
411 getTagLookup() const;
412
413 /**
414 \brief
415 isCurrentTag
416
417 Description:
418 Return true if the given tag exists within the DataTagged tag map.
419
420 *** NB: The DataTagged tag map does not necessarily coincide with the tag
421 keys in the associated function space.
422 T
423 */
424 ESCRIPT_DLL_API
425 bool
426 isCurrentTag(int tag) const;
427
428 /**
429 \brief
430 getDefaultValue
431
432 Description:
433 Return the default value. This value is associated with any tag which
434 is not explicitly recorded in this DataTagged object's tag map.
435 T
436 */
437 ESCRIPT_DLL_API
438 DataArrayView&
439 getDefaultValue();
440
441 ESCRIPT_DLL_API
442 const DataArrayView&
443 getDefaultValue() const;
444
445 /**
446 \brief
447 getDefaultValue
448
449 Description:
450 Return the default value. This value is associated with any tag which
451 is not explicitly recorded in this DataTagged object's tag map.
452 \param i - position in the underlying datastructure
453 T
454 */
455 ESCRIPT_DLL_API
456 DataTypes::ValueType::reference
457 getDefaultValue(DataTypes::ValueType::size_type i);
458
459 ESCRIPT_DLL_API
460 DataTypes::ValueType::const_reference
461 getDefaultValue(DataTypes::ValueType::size_type i) const;
462
463
464
465
466 /**
467 \brief
468 getLength
469
470 Description:
471 Return the total number of doubles stored for this DataTagged object.
472 T
473 */
474 ESCRIPT_DLL_API
475 virtual
476 ValueType::size_type
477 getLength() const;
478
479 /**
480 \brief
481 getSlice
482
483 Description:
484 Factory method that returns a newly created DataTagged object generated
485 by taking the specified slice from this DataTagged object.
486 The caller is reponsible for managing the returned object.
487 T
488 */
489 ESCRIPT_DLL_API
490 virtual
491 DataAbstract*
492 getSlice(const DataTypes::RegionType& region) const;
493
494 /**
495 \brief
496 Slice Constructor for DataTagged.
497
498 Description:
499 Creates a DataTagged object which is the specified slice
500 from the given DataTagged object.
501 \param other - Input - DataTagged object to slice from.
502 \param region - Input - Region to slice.
503 T
504 */
505 ESCRIPT_DLL_API
506 DataTagged(const DataTagged& other,
507 const DataTypes::RegionType& region);
508
509 /**
510 \brief
511 setSlice
512
513 Description:
514 Copy the given Data object into the specified region in this object.
515 \param other - Input - Data object to copy from.
516 \param region - Input - Region to copy into (NB: must have same shape as other!).
517 T
518 */
519 ESCRIPT_DLL_API
520 virtual
521 void
522 setSlice(const DataAbstract* other,
523 const DataTypes::RegionType& region);
524
525 /**
526 \brief
527 Archive the underlying data values to the file referenced
528 by ofstream. A count of the number of values expected to be written
529 is provided as a cross-check.
530
531 The return value indicates success (0) or otherwise (1).
532 */
533 ESCRIPT_DLL_API
534 int
535 archiveData(std::ofstream& archiveFile,
536 const DataTypes::ValueType::size_type noValues) const;
537
538 /**
539 \brief
540 Extract the number of values specified by noValues from the file
541 referenced by ifstream to the underlying data structure.
542
543 The return value indicates success (0) or otherwise (1).
544 */
545 ESCRIPT_DLL_API
546 int
547 extractData(std::ifstream& archiveFile,
548 const DataTypes::ValueType::size_type noValues);
549
550 /**
551 \brief
552 Computes a symmetric matrix (A + AT) / 2
553
554 \param ev - Output - symmetric matrix
555
556 */
557 ESCRIPT_DLL_API
558 virtual void
559 symmetric(DataAbstract* ev);
560
561 /**
562 \brief
563 Computes a nonsymmetric matrix (A - AT) / 2
564
565 \param ev - Output - nonsymmetric matrix
566
567 */
568 ESCRIPT_DLL_API
569 virtual void
570 nonsymmetric(DataAbstract* ev);
571
572 /**
573 \brief
574 Computes the trace of a matrix
575
576 \param ev - Output - the trace of a matrix
577
578 */
579 ESCRIPT_DLL_API
580 virtual void
581 trace(DataAbstract* ev, int axis_offset);
582
583 /**
584 \brief
585 swaps components axis0 and axis1
586
587 \param ev - Output - swapped components
588
589 */
590 ESCRIPT_DLL_API
591 virtual void
592 swapaxes(DataAbstract* ev, int axis0, int axis1);
593
594 /**
595 \brief
596 Transpose each data point of this Data object around the given axis.
597
598 \param ev - Output - the transpose of a matrix
599
600 */
601 ESCRIPT_DLL_API
602 virtual void
603 transpose(DataAbstract* ev, int axis_offset);
604
605 /**
606 \brief
607 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
608
609 \param ev - Output - eigenvalues in increasing order at each data point
610
611 */
612 ESCRIPT_DLL_API
613 virtual void
614 eigenvalues(DataAbstract* ev);
615
616 /**
617 \brief
618 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
619
620 \param ev - Output - eigenvalues in increasing order at each data point
621 \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
622 and the first nonzero component is positive.
623 \param tol - Input - eigenvalue with relative distance tol are treated as equal.
624
625 */
626
627 ESCRIPT_DLL_API
628 virtual void
629 eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
630
631
632 protected:
633
634 private:
635
636 //
637 // The offset lookup table
638 DataMapType m_offsetLookup;
639
640 //
641 // the offset to the default value
642 static const int m_defaultValueOffset = 0;
643
644 //
645 // The actual data
646 ValueType m_data;
647
648 };
649
650 inline
651 bool
652 DataTagged::isCurrentTag(int tag) const
653 {
654 DataMapType::const_iterator pos(m_offsetLookup.find(tag));
655 return (pos!=m_offsetLookup.end());
656 }
657
658 inline
659 DataArrayView&
660 DataTagged::getDefaultValue()
661 {
662 // The default value is always the first value.
663 return getPointDataView();
664 }
665
666 inline
667 const DataArrayView&
668 DataTagged::getDefaultValue() const
669 {
670 // The default value is always the first value.
671 return getPointDataView();
672 }
673
674 inline
675 DataTypes::ValueType::reference
676 DataTagged::getDefaultValue(DataTypes::ValueType::size_type i)
677 {
678 return getPointDataView().getData()[i];
679 }
680
681 inline
682 DataTypes::ValueType::const_reference
683 DataTagged::getDefaultValue(DataTypes::ValueType::size_type i) const
684 {
685 return getPointDataView().getData()[i];
686 }
687
688
689
690
691 inline
692 const DataTypes::ValueType::ElementType*
693 DataTagged::getData() const
694 {
695 return &(m_data[0]);
696 }
697
698 inline
699 const DataTagged::DataMapType&
700 DataTagged::getTagLookup() const
701 {
702 return m_offsetLookup;
703 }
704
705 inline
706 DataTypes::ValueType::size_type
707 DataTagged::getLength() const
708 {
709 return m_data.size();
710 }
711
712 } // end of namespace
713
714 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26