/[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 1697 - (show annotations)
Mon Aug 11 06:29:54 2008 UTC (10 years, 10 months ago) by jfenwick
File MIME type: text/plain
File size: 14811 byte(s)
Moved ValueType, ShapeType, RegionType, RegionLoopRangeType and maxRank
From DataArrayView.h to DataTypes.h

This is a simple rename but did require modifying a lot of files.


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26