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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 100 - (show annotations)
Wed Dec 15 03:48:48 2004 UTC (14 years, 11 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/DataTagged.h
File MIME type: text/plain
File size: 10781 byte(s)
*** empty log message ***

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26