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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 119 - (hide annotations)
Tue Apr 12 04:45:05 2005 UTC (14 years, 10 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/DataTagged.h
File MIME type: text/plain
File size: 11337 byte(s)
*** empty log message ***

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26