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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 480 - (hide annotations)
Wed Feb 1 05:15:12 2006 UTC (13 years, 8 months ago) by jgs
File MIME type: text/plain
File size: 11865 byte(s)
rationalise #includes and forward declarations

1 jgs 82 // $Id$
2 jgs 121
3     /*
4 jgs 82 ******************************************************************************
5     * *
6     * COPYRIGHT ACcESS 2004 - All Rights Reserved *
7     * *
8     * This software is the property of ACcESS. No part of this code *
9     * may be copied in any form or by any means without the expressed written *
10     * consent of ACcESS. Copying, use or modification of this software *
11     * by any unauthorised person is illegal unless that person has a software *
12     * license agreement with ACcESS. *
13     * *
14     ******************************************************************************
15     */
16 jgs 121
17 jgs 82 #if !defined escript_DataTagged_20040615_H
18     #define escript_DataTagged_20040615_H
19    
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     Creates the illusion of a full dataset accessible via sampleNo and dataPointNo.
33    
34     Description:
35     Creates the illusion of a full dataset accessible via sampleNo and
36     dataPointNo. In reality a much smaller number of data-points is stored.
37     Each data-point has an associated key, thus a given key represents a specific
38     range of dataPointNo and sampleNo. Each key indexes a single data-point.
39     Thus only a single data-point needs to be stored for a range of sampleNo and
40     dataPointNo values.
41     */
42    
43     class DataTagged : public DataAbstract {
44    
45     public:
46    
47 jgs 119 //
48     // Types for the lists of tags and values
49 jgs 121 typedef std::vector<int> TagListType;
50 jgs 82 typedef std::vector<DataArrayView> ValueListType;
51 jgs 121 typedef DataArrayView::ValueType ValueType;
52 jgs 82
53     //
54 jgs 119 // Map from the tag to an offset the the data array.
55 jgs 82 typedef std::map<int, int> DataMapType;
56    
57     /**
58     \brief
59     Default constructor for DataTagged.
60    
61     Description:
62     Default constructor for DataTagged. Creates a DataTagged object for which
63     the default data-point is a scalar data-point with value 0.0. Any given tag
64     will map to this data-point.
65     */
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 keys.
75     \param values - Input - A vector of DataArrayViews. If this is empty
76     all tag values will be assigned a value of zero. If
77     it contains one value all tag values will be assigned the
78     same value. Otherwise if there is a mismatch between
79     the number of keys and the number of values an exception
80     will be generated.
81     \param defaultValue - Input - Value returned if a requested tag doesn't exist.
82     \param what - Input - A description of what this data represents.
83     */
84     DataTagged(const TagListType& tagKeys,
85     const ValueListType& values,
86     const DataArrayView& defaultValue,
87     const FunctionSpace& what);
88    
89     /**
90     \brief
91 jgs 119 Alternative constructor for DataTagged objects.
92    
93     Description:
94     Alternative Constructor for DataTagged objects.
95     \param what - Input - A description of what this data object represents.
96     \param shape - Input - the shape of each data-point.
97     \param tags - Input - array of tags, one for each sample number
98     \param data - the data values for each data-point.
99     */
100     DataTagged(const FunctionSpace& what,
101     const DataArrayView::ShapeType &shape,
102     const int tags[],
103 jgs 121 const ValueType &data);
104 jgs 119
105     /**
106     \brief
107 jgs 82 Slice constructor for DataTagged.
108    
109     Description:
110     Slice constructor for DataTagged.
111     Copies a slice from another DataTagged object.
112     \param other - Input - DataTagged object to copy from.
113     \param region - Input - region to copy.
114     */
115     DataTagged(const DataTagged& other,
116     const DataArrayView::RegionType& region);
117    
118     /**
119     \brief
120     Copy constructorfor DataTagged.
121     Performs a deep copy from the given DataTagged object.
122     */
123     DataTagged(const DataTagged& other);
124    
125     /**
126     \brief
127     Construct a tagged data from a DataConstant object.
128     The default data-point will be that held by the DataConstant object.
129     */
130     DataTagged(const DataConstant& other);
131    
132     /**
133     \brief
134     getSampleDataByTag
135    
136     Description:
137     Return the data-point for the given tag. All of the data for the entire
138     sample should be visable via the returned pointer. This provides an
139     interface into the data suitable for legacy C code.
140     */
141     virtual
142     double*
143     getSampleDataByTag(int tag);
144    
145     /**
146     \brief
147     Write the data as a string.
148     Writes out each tag, including the default, and the data-point which is
149     associated with each tag.
150     */
151     virtual
152     std::string
153     toString() const;
154    
155     /**
156     \brief
157 jgs 149 Return the tag number associated with the given data-point number.
158     */
159     virtual
160     int
161     getTagNumber(int dpno);
162    
163     /**
164     \brief
165 jgs 82 getPointOffset
166    
167     Description:
168     Return the offset to the given data-point. This is somewhat artificial,
169     but returns the offset for the given point in the DataTagged object.
170     Only really necessary to avoid many DataArrayView objects.
171    
172     \param sampleNo - Input - sample number.
173     \param dataPointNo - Input - data-point number.
174     */
175     virtual
176 jgs 121 ValueType::size_type
177 jgs 82 getPointOffset(int sampleNo,
178     int dataPointNo) const;
179    
180     /**
181     \brief
182     addTaggedValues
183    
184     Description:
185 jgs 121 Add the given tags and values to this DataTagged object, by repeatedly
186     using addTaggedValue for each given tag/value pair.
187 jgs 82 \param tagKeys - Input - A vector of integer keys.
188     \param values - Input - A vector of DataArrayViews. If this is empty
189 jgs 121 then all given tags will be assigned a value of zero. If
190     it contains one value all tags will be assigned the same value.
191     Otherwise if there is a mismatch between the number of tags and
192     the number of values an exception will be generated.
193 jgs 82 */
194     void
195     addTaggedValues(const TagListType& tagKeys,
196     const ValueListType& values);
197    
198     /**
199     \brief
200     addTaggedValue
201    
202     Description:
203 jgs 121 Add a single tag and value to this DataTagged object. If this tag already has
204     a value associated with it, setTaggedValue will be used to update this value.
205 jgs 82 \param tagKey - Input - Integer key.
206 jgs 121 \param value - Input - Single DataArrayView value to be assigned to the tag.
207 jgs 82 */
208     void
209     addTaggedValue(int tagKey,
210     const DataArrayView& value);
211    
212     /**
213     \brief
214     setTaggedValues
215    
216     Description:
217 jgs 121 Set the given tags to the given values in this DataTagged object, by repeatedly
218     using setTaggedValue for each given tag/value pair.
219 jgs 82 \param tagKeys - Input - A vector of integer keys.
220     \param values - Input - A vector of DataArrayViews. If this is empty
221     then all given tags will be assigned a value of zero. If
222     it contains one value all tag values will be assigned the same value.
223     Otherwise if there is a mismatch between the number of keys and
224     the number of values an exception will be generated.
225     */
226     void
227     setTaggedValues(const TagListType& tagKeys,
228     const ValueListType& values);
229    
230     /**
231     \brief
232     setTaggedValue
233    
234     Description:
235 jgs 121 Assign the given value to the given tag. If this tag does not already have a value
236     associated with it, addTaggedValue will be used to add this tag/value pair.
237 jgs 82 \param tagKey - Input - Integer key.
238     \param value - Input - Single DataArrayView value to be assigned to the tag.
239     */
240     virtual
241     void
242     setTaggedValue(int tagKey,
243     const DataArrayView& value);
244    
245     /**
246     \brief
247     getDataPointByTag
248    
249     Description:
250     Return a view into the data-point associated with the given tag.
251     \param tag - Input - Integer key.
252     */
253     DataArrayView
254     getDataPointByTag(int tag) const;
255    
256     /**
257     \brief
258     getDataPoint
259    
260     Description:
261     Return a view into the data-point specified by the given sample
262     and data-point numbers.
263     NOTE: Construction of the DataArrayView is a relatively expensive
264     operation.
265     \param sampleNo - Input.
266     \param dataPointNo - Input.
267     */
268     virtual
269     DataArrayView
270     getDataPoint(int sampleNo,
271     int dataPointNo);
272    
273     /**
274     \brief
275     getTagLookup
276    
277     Description:
278     Return a reference to the tag offset lookup table.
279     */
280     const DataMapType&
281     getTagLookup() const;
282    
283     /**
284     \brief
285     isCurrentTag
286    
287     Description:
288     Return true if the given tag exists within the DataTagged tag keys.
289     NOTE: The DataTagged keys do not necessarily coincide with the tag
290     keys for the function space.
291     */
292     bool
293     isCurrentTag(int tag) const;
294    
295     /**
296     \brief
297     getDefaultValue
298    
299     Description:
300     Return the default value. This value is associated with any tag which
301     is not explicitly recorded in this DataTagged object.
302     */
303     DataArrayView&
304     getDefaultValue();
305    
306     const DataArrayView&
307     getDefaultValue() const;
308    
309     /**
310     \brief
311     getLength
312    
313     Description:
314     Return the number of doubles stored for the Data.
315     */
316     virtual
317     ValueType::size_type
318     getLength() const;
319    
320     /**
321     \brief
322     getSlice
323    
324     Description:
325 jgs 102 Factory method that returns a newly created DataTagged object.
326 jgs 82 The caller is reponsible for managing the object created.
327     */
328     virtual
329     DataAbstract*
330     getSlice(const DataArrayView::RegionType& region) const;
331    
332     /**
333     \brief
334     setSlice
335    
336     Description:
337 jgs 102 Copy the specified region from the given value into this object.
338 jgs 82 \param value - Input - Data to copy from.
339     \param region - Input - Region to copy.
340     */
341     virtual
342     void
343     setSlice(const DataAbstract* value,
344     const DataArrayView::RegionType& region);
345    
346     /**
347     \brief
348     reshapeDataPoint
349    
350     Description:
351     Reshape the data point only if the data-point is currently rank 0.
352     An exception is thrown if the data-point has rank other than 0.
353     The original data point value is used for all values of the new
354     data point.
355     */
356     void
357     reshapeDataPoint(const DataArrayView::ShapeType& shape);
358    
359 jgs 123 /**
360     \brief
361     Archive the underlying data values to the file referenced
362     by ofstream. A count of the number of values expected to be written
363     is provided as a cross-check.
364    
365     The return value indicates success (0) or otherwise (1).
366     */
367     int
368     archiveData(std::ofstream& archiveFile,
369     const DataArrayView::ValueType::size_type noValues) const;
370    
371     /**
372     \brief
373     Extract the number of values specified by noValues from the file
374     referenced by ifstream to the underlying data structure.
375    
376     The return value indicates success (0) or otherwise (1).
377     */
378     int
379     extractData(std::ifstream& archiveFile,
380     const DataArrayView::ValueType::size_type noValues);
381    
382 jgs 82 protected:
383    
384     private:
385    
386     //
387     // The offset lookup table
388     DataMapType m_offsetLookup;
389    
390     //
391 jgs 119 // the default value offset
392     static const int m_defaultValueOffset = 0;
393    
394     //
395 jgs 82 // The actual data
396 jgs 121 ValueType m_data;
397 jgs 82
398     };
399    
400     inline
401     bool
402     DataTagged::isCurrentTag(int tag) const
403     {
404     DataMapType::const_iterator pos(m_offsetLookup.find(tag));
405     return (pos!=m_offsetLookup.end());
406     }
407    
408     inline
409     DataArrayView&
410     DataTagged::getDefaultValue()
411     {
412     // The default value is always the first value.
413     return getPointDataView();
414     }
415    
416     inline
417     const DataArrayView&
418     DataTagged::getDefaultValue() const
419     {
420     // The default value is always the first value.
421     return getPointDataView();
422     }
423    
424     } // end of namespace
425    
426     #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26