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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 149 - (show annotations)
Thu Sep 1 03:31:39 2005 UTC (14 years, 2 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/DataTagged.h
File MIME type: text/plain
File size: 11927 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-09-01

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26