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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 615 - (hide annotations)
Wed Mar 22 02:12:00 2006 UTC (13 years, 7 months ago) by elspeth
File MIME type: text/plain
File size: 12670 byte(s)
More copyright information.

1 jgs 82 // $Id$
2 jgs 121
3     /*
4 elspeth 615 ************************************************************
5     * Copyright 2006 by ACcESS MNRF *
6     * *
7     * http://www.access.edu.au *
8     * Primary Business: Queensland, Australia *
9     * Licensed under the Open Software License version 3.0 *
10     * http://www.opensource.org/licenses/osl-3.0.php *
11     * *
12     ************************************************************
13 jgs 82 */
14 jgs 121
15 jgs 82 #if !defined escript_DataTagged_20040615_H
16     #define escript_DataTagged_20040615_H
17    
18 jgs 474 #include "DataAbstract.h"
19     #include "DataArrayView.h"
20 jgs 82
21     #include <vector>
22     #include <map>
23    
24     namespace escript {
25    
26     class DataConstant;
27    
28     /**
29     \brief
30 jgs 496 Simulates a full dataset accessible via sampleNo and dataPointNo.
31 jgs 82
32     Description:
33 jgs 496 Each data-point has an associated tag number, and a given tag can represent a
34     range of dataPointNo and sampleNo. Each tag indexes only a single data-point.
35 jgs 82 Thus only a single data-point needs to be stored for a range of sampleNo and
36     dataPointNo values.
37     */
38    
39     class DataTagged : public DataAbstract {
40    
41     public:
42    
43 jgs 119 //
44 jgs 496 // Types for the lists of tags and values.
45 jgs 121 typedef std::vector<int> TagListType;
46 jgs 82 typedef std::vector<DataArrayView> ValueListType;
47 jgs 121 typedef DataArrayView::ValueType ValueType;
48 jgs 82
49     //
50 jgs 496 // Map from a tag to an offset into the data array.
51 jgs 82 typedef std::map<int, int> DataMapType;
52    
53     /**
54     \brief
55     Default constructor for DataTagged.
56    
57     Description:
58     Default constructor for DataTagged. Creates a DataTagged object for which
59 jgs 509 the default data-point is a scalar data-point with value 0.0, and no other
60     tag values are stored.
61 jgs 507 T
62 jgs 82 */
63     DataTagged();
64    
65     /**
66     \brief
67     Constructor for DataTagged.
68    
69     Description:
70     Constructor for DataTagged.
71 jgs 509 \param tagKeys - Input - A vector of integer tags.
72 jgs 82 \param values - Input - A vector of DataArrayViews. If this is empty
73 jgs 509 all tag values will be assigned a scalar data-point of value
74     0. If it contains one value all tag values will be assigned
75     this value. Otherwise consecutive tags will be assigned
76     consecutive values. If there is a mismatch between the
77     number of keys and the number of values an exception
78 jgs 496 will be generated.
79 jgs 82 \param defaultValue - Input - Value returned if a requested tag doesn't exist.
80     \param what - Input - A description of what this data represents.
81 jgs 507 T
82 jgs 82 */
83     DataTagged(const TagListType& tagKeys,
84     const ValueListType& values,
85     const DataArrayView& defaultValue,
86     const FunctionSpace& what);
87    
88     /**
89     \brief
90 jgs 496 Alternative Constructor for DataTagged.
91 jgs 119
92     Description:
93 jgs 496 Alternative Constructor for DataTagged.
94 jgs 119 \param what - Input - A description of what this data object represents.
95 jgs 496 \param shape - Input - The shape of each data-point.
96     \param tags - Input - An array of tags, one for each sample number.
97     \param data - The data values for each tag.
98 jgs 535 NB: no unit testing yet
99 jgs 119 */
100     DataTagged(const FunctionSpace& what,
101     const DataArrayView::ShapeType &shape,
102     const int tags[],
103 jgs 500 const ValueType& data);
104 jgs 119
105     /**
106     \brief
107 jgs 496 Copy Constructor for DataTagged.
108 jgs 82 Performs a deep copy from the given DataTagged object.
109 jgs 507 T
110 jgs 82 */
111     DataTagged(const DataTagged& other);
112    
113     /**
114     \brief
115 jgs 496 Copy Constructor for DataTagged.
116 jgs 509 Construct a DataTagged object from a DataConstant object.
117     The default value will be the value of the DataConstant object.
118 jgs 507 T
119 jgs 82 */
120     DataTagged(const DataConstant& other);
121    
122     /**
123     \brief
124     getSampleDataByTag
125    
126     Description:
127 jgs 496 Return the data-point for the given tag. All of the data for the
128     sample will be visible via the returned pointer.
129    
130     ** This provides an interface into the data suitable for legacy C code.
131 jgs 507 ** NB: need to do array bounds checking when accessing returned value!
132     T
133 jgs 82 */
134     virtual
135     double*
136     getSampleDataByTag(int tag);
137    
138     /**
139     \brief
140     Write the data as a string.
141     Writes out each tag, including the default, and the data-point which is
142     associated with each tag.
143 jgs 507 T
144 jgs 82 */
145     virtual
146     std::string
147     toString() const;
148    
149     /**
150     \brief
151 jgs 496 Return the tag number associated with the given data-point number
152     according to the associated function space.
153 jgs 507 T
154 jgs 149 */
155     virtual
156     int
157     getTagNumber(int dpno);
158    
159     /**
160     \brief
161 jgs 82 getPointOffset
162    
163     Description:
164 jgs 496 Return the offset to the given data-point value in the underlying
165     data vector.
166 jgs 82
167     \param sampleNo - Input - sample number.
168     \param dataPointNo - Input - data-point number.
169 jgs 507 T
170     */
171 jgs 82 virtual
172 jgs 121 ValueType::size_type
173 jgs 82 getPointOffset(int sampleNo,
174     int dataPointNo) const;
175    
176     /**
177     \brief
178     addTaggedValues
179    
180     Description:
181 jgs 509 Add the given tags and values to this DataTagged object.
182 jgs 507 \param tagKeys - Input - A vector of integer tags.
183 jgs 82 \param values - Input - A vector of DataArrayViews. If this is empty
184 jgs 509 all tag values will be assigned a scalar data-point of value
185     0. If it contains one value all tag values will be assigned
186     this value. Otherwise consecutive tags will be assigned
187     consecutive values. If there is a mismatch between the
188     number of keys and the number of values an exception
189     will be generated.
190 jgs 507 T
191 jgs 82 */
192     void
193     addTaggedValues(const TagListType& tagKeys,
194     const ValueListType& values);
195    
196     /**
197     \brief
198     addTaggedValue
199    
200     Description:
201 jgs 121 Add a single tag and value to this DataTagged object. If this tag already has
202     a value associated with it, setTaggedValue will be used to update this value.
203 jgs 509 \param tagKey - Input - Integer tag.
204 jgs 121 \param value - Input - Single DataArrayView value to be assigned to the tag.
205 jgs 507 T
206 jgs 82 */
207     void
208     addTaggedValue(int tagKey,
209     const DataArrayView& value);
210    
211     /**
212     \brief
213     setTaggedValues
214    
215     Description:
216 jgs 509 Set the given tags to the given values in this DataTagged object.
217     \param tagKeys - Input - A vector of integer tag.
218 jgs 82 \param values - Input - A vector of DataArrayViews. If this is empty
219 jgs 509 all tag values will be assigned a scalar data-point of value
220     0. If it contains one value all tag values will be assigned
221     this value. Otherwise consecutive tags will be assigned
222     consecutive values. If there is a mismatch between the
223     number of keys and the number of values an exception
224     will be generated.
225 jgs 507 T
226 jgs 82 */
227     void
228     setTaggedValues(const TagListType& tagKeys,
229     const ValueListType& values);
230    
231     /**
232     \brief
233     setTaggedValue
234    
235     Description:
236 jgs 509 Assign the given value to the given tag.
237     \param tagKey - Input - Integer tag.
238 jgs 82 \param value - Input - Single DataArrayView value to be assigned to the tag.
239 jgs 507 T
240 jgs 82 */
241     virtual
242     void
243     setTaggedValue(int tagKey,
244     const DataArrayView& value);
245    
246     /**
247     \brief
248     getDataPointByTag
249    
250     Description:
251 jgs 509 Return data-point associated with the given tag as a DataArrayView.
252 jgs 82 \param tag - Input - Integer key.
253 jgs 507 T
254 jgs 82 */
255     DataArrayView
256     getDataPointByTag(int tag) const;
257    
258     /**
259     \brief
260     getDataPoint
261    
262     Description:
263 jgs 509 Return the data-point specified by the given sample and data-point
264     numbers as a DataArrayView.
265 jgs 82 \param sampleNo - Input.
266     \param dataPointNo - Input.
267 jgs 507 T
268 jgs 82 */
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 jgs 507 T
281 jgs 82 */
282     const DataMapType&
283     getTagLookup() const;
284    
285     /**
286     \brief
287     isCurrentTag
288    
289     Description:
290 jgs 496 Return true if the given tag exists within the DataTagged tag map.
291    
292 jgs 509 *** NB: The DataTagged tag map does not necessarily coincide with the tag
293 jgs 496 keys in the associated function space.
294 jgs 507 T
295     */
296 jgs 82 bool
297     isCurrentTag(int tag) const;
298    
299     /**
300     \brief
301     getDefaultValue
302    
303     Description:
304     Return the default value. This value is associated with any tag which
305 jgs 496 is not explicitly recorded in this DataTagged object's tag map.
306 jgs 507 T
307 jgs 82 */
308     DataArrayView&
309     getDefaultValue();
310    
311     const DataArrayView&
312     getDefaultValue() const;
313    
314     /**
315     \brief
316     getLength
317    
318     Description:
319 jgs 509 Return the total number of doubles stored for this DataTagged object.
320 jgs 507 T
321 jgs 82 */
322     virtual
323     ValueType::size_type
324     getLength() const;
325    
326     /**
327     \brief
328     getSlice
329    
330     Description:
331 jgs 513 Factory method that returns a newly created DataTagged object generated
332     by taking the specified slice from this DataTagged object.
333     The caller is reponsible for managing the returned object.
334 jgs 535 T
335 jgs 82 */
336     virtual
337     DataAbstract*
338     getSlice(const DataArrayView::RegionType& region) const;
339    
340     /**
341     \brief
342 jgs 513 Slice Constructor for DataTagged.
343 jgs 82
344     Description:
345 jgs 513 Creates a DataTagged object which is the specified slice
346 jgs 519 from the given DataTagged object.
347     \param other - Input - DataTagged object to slice from.
348     \param region - Input - Region to slice.
349 jgs 535 T
350 jgs 82 */
351 jgs 513 DataTagged(const DataTagged& other,
352     const DataArrayView::RegionType& region);
353    
354     /**
355     \brief
356     setSlice
357    
358     Description:
359 jgs 519 Copy the given Data object into the specified region in this object.
360 jgs 513 \param other - Input - Data object to copy from.
361 jgs 519 \param region - Input - Region to copy into (NB: must have same shape as other!).
362 jgs 535 T
363 jgs 513 */
364 jgs 82 virtual
365     void
366 jgs 513 setSlice(const DataAbstract* other,
367 jgs 82 const DataArrayView::RegionType& region);
368    
369     /**
370     \brief
371     reshapeDataPoint
372    
373     Description:
374 jgs 509 Reshape each data-point in this object to the given shape, only
375     if current data-points are scalars. An exception is thrown if
376     the current data-points have rank other than 0.
377     The original values of the data-points are used for all values
378     of the new data-points.
379     T
380 jgs 82 */
381     void
382     reshapeDataPoint(const DataArrayView::ShapeType& shape);
383    
384 jgs 123 /**
385 jgs 509 \brief
386     Archive the underlying data values to the file referenced
387     by ofstream. A count of the number of values expected to be written
388     is provided as a cross-check.
389 jgs 123
390 jgs 509 The return value indicates success (0) or otherwise (1).
391 jgs 123 */
392     int
393     archiveData(std::ofstream& archiveFile,
394     const DataArrayView::ValueType::size_type noValues) const;
395    
396     /**
397 jgs 509 \brief
398     Extract the number of values specified by noValues from the file
399     referenced by ifstream to the underlying data structure.
400 jgs 123
401 jgs 509 The return value indicates success (0) or otherwise (1).
402 jgs 123 */
403     int
404     extractData(std::ifstream& archiveFile,
405     const DataArrayView::ValueType::size_type noValues);
406    
407 gross 580 /**
408     \brief
409     solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
410    
411     \param ev - Output - eigenvalues in increasing order at each data point
412    
413     */
414     virtual void
415     eigenvalues(DataAbstract* ev);
416    
417     /**
418     \brief
419     solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
420    
421     \param ev - Output - eigenvalues in increasing order at each data point
422     \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
423     and the first nonzero component is positive.
424     \param tol - Input - eigenvalue with relative distance tol are treated as equal.
425    
426     */
427    
428     virtual void
429     eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
430    
431    
432 jgs 82 protected:
433    
434     private:
435    
436     //
437     // The offset lookup table
438     DataMapType m_offsetLookup;
439    
440     //
441 jgs 496 // the offset to the default value
442 jgs 119 static const int m_defaultValueOffset = 0;
443    
444     //
445 jgs 82 // The actual data
446 jgs 121 ValueType m_data;
447 jgs 82
448     };
449    
450     inline
451     bool
452     DataTagged::isCurrentTag(int tag) const
453     {
454     DataMapType::const_iterator pos(m_offsetLookup.find(tag));
455     return (pos!=m_offsetLookup.end());
456     }
457    
458     inline
459     DataArrayView&
460     DataTagged::getDefaultValue()
461     {
462     // The default value is always the first value.
463     return getPointDataView();
464     }
465    
466     inline
467     const DataArrayView&
468     DataTagged::getDefaultValue() const
469     {
470     // The default value is always the first value.
471     return getPointDataView();
472     }
473    
474 jgs 496 inline
475     const DataTagged::DataMapType&
476     DataTagged::getTagLookup() const
477     {
478     return m_offsetLookup;
479     }
480    
481     inline
482     DataArrayView::ValueType::size_type
483     DataTagged::getLength() const
484     {
485     return m_data.size();
486     }
487    
488 jgs 82 } // end of namespace
489    
490     #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26