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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1118 - (hide annotations)
Tue Apr 24 08:55:04 2007 UTC (12 years, 5 months ago) by gross
File MIME type: text/plain
File size: 14871 byte(s)
problem with reset of faulty PDE rhs fixed.
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 woo409 757 #include "system_dep.h"
18 jgs 82
19 jgs 474 #include "DataAbstract.h"
20     #include "DataArrayView.h"
21 jgs 82
22     #include <vector>
23     #include <map>
24    
25     namespace escript {
26    
27     class DataConstant;
28    
29     /**
30     \brief
31 jgs 496 Simulates a full dataset accessible via sampleNo and dataPointNo.
32 jgs 82
33     Description:
34 jgs 496 Each data-point has an associated tag number, and a given tag can represent a
35     range of dataPointNo and sampleNo. Each tag indexes only a single data-point.
36 jgs 82 Thus only a single data-point needs to be stored for a range of sampleNo and
37     dataPointNo values.
38     */
39    
40     class DataTagged : public DataAbstract {
41    
42     public:
43    
44 jgs 119 //
45 jgs 496 // Types for the lists of tags and values.
46 jgs 121 typedef std::vector<int> TagListType;
47 jgs 82 typedef std::vector<DataArrayView> ValueListType;
48 jgs 121 typedef DataArrayView::ValueType ValueType;
49 jgs 82
50     //
51 jgs 496 // Map from a tag to an offset into the data array.
52 jgs 82 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 jgs 509 the default data-point is a scalar data-point with value 0.0, and no other
61     tag values are stored.
62 jgs 507 T
63 jgs 82 */
64 woo409 757 ESCRIPT_DLL_API
65 jgs 82 DataTagged();
66    
67     /**
68     \brief
69     Constructor for DataTagged.
70    
71     Description:
72     Constructor for DataTagged.
73 jgs 509 \param tagKeys - Input - A vector of integer tags.
74 jgs 82 \param values - Input - A vector of DataArrayViews. If this is empty
75 jgs 509 all tag values will be assigned a scalar data-point of value
76     0. If it contains one value all tag values will be assigned
77     this value. Otherwise consecutive tags will be assigned
78     consecutive values. If there is a mismatch between the
79     number of keys and the number of values an exception
80 jgs 496 will be generated.
81 jgs 82 \param defaultValue - Input - Value returned if a requested tag doesn't exist.
82     \param what - Input - A description of what this data represents.
83 jgs 507 T
84 jgs 82 */
85 woo409 757 ESCRIPT_DLL_API
86 jgs 82 DataTagged(const TagListType& tagKeys,
87     const ValueListType& values,
88     const DataArrayView& defaultValue,
89     const FunctionSpace& what);
90    
91     /**
92     \brief
93 jgs 496 Alternative Constructor for DataTagged.
94 jgs 119
95     Description:
96 jgs 496 Alternative Constructor for DataTagged.
97 jgs 119 \param what - Input - A description of what this data object represents.
98 jgs 496 \param shape - Input - The shape of each data-point.
99     \param tags - Input - An array of tags, one for each sample number.
100     \param data - The data values for each tag.
101 jgs 535 NB: no unit testing yet
102 jgs 119 */
103 woo409 757 ESCRIPT_DLL_API
104 jgs 119 DataTagged(const FunctionSpace& what,
105     const DataArrayView::ShapeType &shape,
106     const int tags[],
107 jgs 500 const ValueType& data);
108 jgs 119
109     /**
110     \brief
111 woo409 757 Alternative Constructor for DataTagged.
112    
113     Description:
114     Alternative Constructor for DataTagged.
115     \param what - Input - A description of what this data object represents.
116     \param shape - Input - The shape of each data-point.
117     \param tags - Input - An vector of tags, one for each sample number.
118     \param data - The data values for each tag.
119     NB: no unit testing yet
120     */
121     ESCRIPT_DLL_API
122     DataTagged(const FunctionSpace& what,
123     const DataArrayView::ShapeType &shape,
124     const TagListType& tags,
125     const ValueType& data);
126    
127     /**
128     \brief
129 jgs 496 Copy Constructor for DataTagged.
130 jgs 82 Performs a deep copy from the given DataTagged object.
131 jgs 507 T
132 jgs 82 */
133 woo409 757 ESCRIPT_DLL_API
134 jgs 82 DataTagged(const DataTagged& other);
135    
136     /**
137     \brief
138 jgs 496 Copy Constructor for DataTagged.
139 jgs 509 Construct a DataTagged object from a DataConstant object.
140     The default value will be the value of the DataConstant object.
141 jgs 507 T
142 jgs 82 */
143 woo409 757 ESCRIPT_DLL_API
144 jgs 82 DataTagged(const DataConstant& other);
145    
146     /**
147     \brief
148     getSampleDataByTag
149    
150     Description:
151 jgs 496 Return the data-point for the given tag. All of the data for the
152     sample will be visible via the returned pointer.
153    
154     ** This provides an interface into the data suitable for legacy C code.
155 jgs 507 ** NB: need to do array bounds checking when accessing returned value!
156     T
157 jgs 82 */
158 woo409 757 ESCRIPT_DLL_API
159 jgs 82 virtual
160     double*
161     getSampleDataByTag(int tag);
162    
163     /**
164     \brief
165     Write the data as a string.
166     Writes out each tag, including the default, and the data-point which is
167     associated with each tag.
168 jgs 507 T
169 jgs 82 */
170 woo409 757 ESCRIPT_DLL_API
171 jgs 82 virtual
172     std::string
173     toString() const;
174 gross 950 /**
175     \brief
176     dumps the object into a netCDF file
177     */
178     ESCRIPT_DLL_API
179     virtual
180     void
181     dump(const std::string fileName) const;
182 jgs 82
183 gross 1118 /**
184     \brief
185     sets all values to zero
186     */
187     ESCRIPT_DLL_API
188     virtual
189     void
190     setToZero();
191    
192 jgs 82 /**
193     \brief
194 jgs 496 Return the tag number associated with the given data-point number
195     according to the associated function space.
196 jgs 507 T
197 jgs 149 */
198 woo409 757 ESCRIPT_DLL_API
199 jgs 149 virtual
200     int
201     getTagNumber(int dpno);
202    
203     /**
204     \brief
205 jgs 82 getPointOffset
206    
207     Description:
208 jgs 496 Return the offset to the given data-point value in the underlying
209     data vector.
210 jgs 82
211     \param sampleNo - Input - sample number.
212     \param dataPointNo - Input - data-point number.
213 jgs 507 T
214     */
215 woo409 757 ESCRIPT_DLL_API
216 jgs 82 virtual
217 jgs 121 ValueType::size_type
218 jgs 82 getPointOffset(int sampleNo,
219     int dataPointNo) const;
220    
221     /**
222     \brief
223     addTaggedValues
224    
225     Description:
226 jgs 509 Add the given tags and values to this DataTagged object.
227 jgs 507 \param tagKeys - Input - A vector of integer tags.
228 jgs 82 \param values - Input - A vector of DataArrayViews. If this is empty
229 jgs 509 all tag values will be assigned a scalar data-point of value
230     0. If it contains one value all tag values will be assigned
231     this value. Otherwise consecutive tags will be assigned
232     consecutive values. If there is a mismatch between the
233     number of keys and the number of values an exception
234     will be generated.
235 jgs 507 T
236 jgs 82 */
237 woo409 757 ESCRIPT_DLL_API
238 jgs 82 void
239     addTaggedValues(const TagListType& tagKeys,
240     const ValueListType& values);
241    
242     /**
243     \brief
244     addTaggedValue
245    
246     Description:
247 jgs 121 Add a single tag and value to this DataTagged object. If this tag already has
248     a value associated with it, setTaggedValue will be used to update this value.
249 jgs 509 \param tagKey - Input - Integer tag.
250 jgs 121 \param value - Input - Single DataArrayView value to be assigned to the tag.
251 jgs 507 T
252 jgs 82 */
253 woo409 757 ESCRIPT_DLL_API
254 jgs 82 void
255     addTaggedValue(int tagKey,
256     const DataArrayView& value);
257    
258     /**
259     \brief
260     setTaggedValues
261    
262     Description:
263 jgs 509 Set the given tags to the given values in this DataTagged object.
264     \param tagKeys - Input - A vector of integer tag.
265 jgs 82 \param values - Input - A vector of DataArrayViews. If this is empty
266 jgs 509 all tag values will be assigned a scalar data-point of value
267     0. If it contains one value all tag values will be assigned
268     this value. Otherwise consecutive tags will be assigned
269     consecutive values. If there is a mismatch between the
270     number of keys and the number of values an exception
271     will be generated.
272 jgs 507 T
273 jgs 82 */
274 woo409 757 ESCRIPT_DLL_API
275 jgs 82 void
276     setTaggedValues(const TagListType& tagKeys,
277     const ValueListType& values);
278    
279     /**
280     \brief
281     setTaggedValue
282    
283     Description:
284 jgs 509 Assign the given value to the given tag.
285     \param tagKey - Input - Integer tag.
286 jgs 82 \param value - Input - Single DataArrayView value to be assigned to the tag.
287 jgs 507 T
288 jgs 82 */
289 woo409 757 ESCRIPT_DLL_API
290 jgs 82 virtual
291     void
292     setTaggedValue(int tagKey,
293     const DataArrayView& value);
294    
295     /**
296     \brief
297     getDataPointByTag
298    
299     Description:
300 jgs 509 Return data-point associated with the given tag as a DataArrayView.
301 jgs 82 \param tag - Input - Integer key.
302 jgs 507 T
303 jgs 82 */
304 woo409 757 ESCRIPT_DLL_API
305 jgs 82 DataArrayView
306     getDataPointByTag(int tag) const;
307    
308     /**
309     \brief
310     getDataPoint
311    
312     Description:
313 jgs 509 Return the data-point specified by the given sample and data-point
314     numbers as a DataArrayView.
315 jgs 82 \param sampleNo - Input.
316     \param dataPointNo - Input.
317 jgs 507 T
318 jgs 82 */
319 woo409 757 ESCRIPT_DLL_API
320 jgs 82 virtual
321     DataArrayView
322     getDataPoint(int sampleNo,
323     int dataPointNo);
324    
325     /**
326 gross 983 \brief
327     getData
328    
329     Description:
330     Return pointer to the data
331     T
332     */
333     ESCRIPT_DLL_API
334     const DataArrayView::ValueType::ElementType*
335 gross 984 getData() const;
336 gross 983
337     /**
338 jgs 82 \brief
339     getTagLookup
340    
341     Description:
342     Return a reference to the tag offset lookup table.
343 jgs 507 T
344 jgs 82 */
345 woo409 757 ESCRIPT_DLL_API
346 jgs 82 const DataMapType&
347     getTagLookup() const;
348    
349     /**
350     \brief
351     isCurrentTag
352    
353     Description:
354 jgs 496 Return true if the given tag exists within the DataTagged tag map.
355    
356 jgs 509 *** NB: The DataTagged tag map does not necessarily coincide with the tag
357 jgs 496 keys in the associated function space.
358 jgs 507 T
359     */
360 woo409 757 ESCRIPT_DLL_API
361 jgs 82 bool
362     isCurrentTag(int tag) const;
363    
364     /**
365     \brief
366     getDefaultValue
367    
368     Description:
369     Return the default value. This value is associated with any tag which
370 jgs 496 is not explicitly recorded in this DataTagged object's tag map.
371 jgs 507 T
372 jgs 82 */
373 woo409 757 ESCRIPT_DLL_API
374 jgs 82 DataArrayView&
375     getDefaultValue();
376    
377 woo409 757 ESCRIPT_DLL_API
378 jgs 82 const DataArrayView&
379     getDefaultValue() const;
380    
381     /**
382     \brief
383     getLength
384    
385     Description:
386 jgs 509 Return the total number of doubles stored for this DataTagged object.
387 jgs 507 T
388 jgs 82 */
389 woo409 757 ESCRIPT_DLL_API
390 jgs 82 virtual
391     ValueType::size_type
392     getLength() const;
393    
394     /**
395     \brief
396     getSlice
397    
398     Description:
399 jgs 513 Factory method that returns a newly created DataTagged object generated
400     by taking the specified slice from this DataTagged object.
401     The caller is reponsible for managing the returned object.
402 jgs 535 T
403 jgs 82 */
404 woo409 757 ESCRIPT_DLL_API
405 jgs 82 virtual
406     DataAbstract*
407     getSlice(const DataArrayView::RegionType& region) const;
408    
409     /**
410     \brief
411 jgs 513 Slice Constructor for DataTagged.
412 jgs 82
413     Description:
414 jgs 513 Creates a DataTagged object which is the specified slice
415 jgs 519 from the given DataTagged object.
416     \param other - Input - DataTagged object to slice from.
417     \param region - Input - Region to slice.
418 jgs 535 T
419 jgs 82 */
420 woo409 757 ESCRIPT_DLL_API
421 jgs 513 DataTagged(const DataTagged& other,
422     const DataArrayView::RegionType& region);
423    
424     /**
425     \brief
426     setSlice
427    
428     Description:
429 jgs 519 Copy the given Data object into the specified region in this object.
430 jgs 513 \param other - Input - Data object to copy from.
431 jgs 519 \param region - Input - Region to copy into (NB: must have same shape as other!).
432 jgs 535 T
433 jgs 513 */
434 woo409 757 ESCRIPT_DLL_API
435 jgs 82 virtual
436     void
437 jgs 513 setSlice(const DataAbstract* other,
438 jgs 82 const DataArrayView::RegionType& region);
439    
440     /**
441     \brief
442 jgs 509 Archive the underlying data values to the file referenced
443     by ofstream. A count of the number of values expected to be written
444     is provided as a cross-check.
445 jgs 123
446 jgs 509 The return value indicates success (0) or otherwise (1).
447 jgs 123 */
448 woo409 757 ESCRIPT_DLL_API
449 jgs 123 int
450     archiveData(std::ofstream& archiveFile,
451     const DataArrayView::ValueType::size_type noValues) const;
452    
453     /**
454 jgs 509 \brief
455     Extract the number of values specified by noValues from the file
456     referenced by ifstream to the underlying data structure.
457 jgs 123
458 jgs 509 The return value indicates success (0) or otherwise (1).
459 jgs 123 */
460 woo409 757 ESCRIPT_DLL_API
461 jgs 123 int
462     extractData(std::ifstream& archiveFile,
463     const DataArrayView::ValueType::size_type noValues);
464    
465 gross 580 /**
466     \brief
467 ksteube 775 Computes a symmetric matrix (A + AT) / 2
468    
469     \param ev - Output - symmetric matrix
470    
471     */
472 gross 800 ESCRIPT_DLL_API
473 ksteube 775 virtual void
474     symmetric(DataAbstract* ev);
475    
476     /**
477     \brief
478     Computes a nonsymmetric matrix (A - AT) / 2
479    
480     \param ev - Output - nonsymmetric matrix
481    
482     */
483 gross 800 ESCRIPT_DLL_API
484 ksteube 775 virtual void
485     nonsymmetric(DataAbstract* ev);
486    
487     /**
488     \brief
489     Computes the trace of a matrix
490    
491     \param ev - Output - the trace of a matrix
492    
493     */
494 gross 800 ESCRIPT_DLL_API
495 ksteube 775 virtual void
496 gross 800 trace(DataAbstract* ev, int axis_offset);
497 ksteube 775
498     /**
499     \brief
500 gross 804 swaps components axis0 and axis1
501 gross 800
502     \param ev - Output - swapped components
503    
504     */
505     ESCRIPT_DLL_API
506     virtual void
507 gross 804 swapaxes(DataAbstract* ev, int axis0, int axis1);
508 gross 800
509     /**
510     \brief
511 ksteube 775 Transpose each data point of this Data object around the given axis.
512    
513     \param ev - Output - the transpose of a matrix
514    
515     */
516 gross 800 ESCRIPT_DLL_API
517 ksteube 775 virtual void
518     transpose(DataAbstract* ev, int axis_offset);
519    
520     /**
521     \brief
522 gross 580 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
523    
524     \param ev - Output - eigenvalues in increasing order at each data point
525    
526     */
527 woo409 757 ESCRIPT_DLL_API
528 gross 580 virtual void
529     eigenvalues(DataAbstract* ev);
530    
531     /**
532     \brief
533     solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
534    
535     \param ev - Output - eigenvalues in increasing order at each data point
536     \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
537     and the first nonzero component is positive.
538     \param tol - Input - eigenvalue with relative distance tol are treated as equal.
539    
540     */
541    
542 woo409 757 ESCRIPT_DLL_API
543 gross 580 virtual void
544     eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
545    
546    
547 jgs 82 protected:
548    
549     private:
550    
551     //
552     // The offset lookup table
553     DataMapType m_offsetLookup;
554    
555     //
556 jgs 496 // the offset to the default value
557 jgs 119 static const int m_defaultValueOffset = 0;
558    
559     //
560 jgs 82 // The actual data
561 jgs 121 ValueType m_data;
562 jgs 82
563     };
564    
565     inline
566     bool
567     DataTagged::isCurrentTag(int tag) const
568     {
569     DataMapType::const_iterator pos(m_offsetLookup.find(tag));
570     return (pos!=m_offsetLookup.end());
571     }
572    
573     inline
574     DataArrayView&
575     DataTagged::getDefaultValue()
576     {
577     // The default value is always the first value.
578     return getPointDataView();
579     }
580    
581     inline
582     const DataArrayView&
583     DataTagged::getDefaultValue() const
584     {
585     // The default value is always the first value.
586     return getPointDataView();
587     }
588    
589 jgs 496 inline
590 gross 983 const DataArrayView::ValueType::ElementType*
591     DataTagged::getData() const
592     {
593     return &(m_data[0]);
594     }
595    
596     inline
597 jgs 496 const DataTagged::DataMapType&
598     DataTagged::getTagLookup() const
599     {
600     return m_offsetLookup;
601     }
602    
603     inline
604     DataArrayView::ValueType::size_type
605     DataTagged::getLength() const
606     {
607     return m_data.size();
608     }
609    
610 jgs 82 } // end of namespace
611    
612     #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26