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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1384 - (hide annotations)
Fri Jan 11 02:29:38 2008 UTC (11 years, 10 months ago) by phornby
Original Path: temp_trunk_copy/escript/src/DataTagged.h
File MIME type: text/plain
File size: 14737 byte(s)
Make a temp copy of the trunk before checking in the windows changes


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26