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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1628 - (hide annotations)
Fri Jul 11 13:12:46 2008 UTC (11 years, 2 months ago) by phornby
File MIME type: text/plain
File size: 14832 byte(s)

Merge in /branches/windows_from_1456_trunk_1620_merged_in branch.

You will find a preserved pre-merge trunk in tags under tags/trunk_at_1625.
That will be useful for diffing & checking on my stupidity.

Here is a list of the conflicts and their resolution at this
point in time.


=================================================================================
(LLWS == looks like white space).

finley/src/Assemble_addToSystemMatrix.c - resolve to branch - unused var. may be wrong.....
finley/src/CPPAdapter/SystemMatrixAdapter.cpp - resolve to branch - LLWS
finley/src/CPPAdapter/MeshAdapter.cpp - resolve to branch - LLWS
paso/src/PCG.c - resolve to branch - unused var fixes.
paso/src/SolverFCT.c - resolve to branch - LLWS
paso/src/FGMRES.c - resolve to branch - LLWS
paso/src/Common.h - resolve to trunk version. It's omp.h's include... not sure it's needed,
but for the sake of saftey.....
paso/src/Functions.c - resolve to branch version, indentation/tab removal and return error
on bad unimplemented Paso_FunctionCall.
paso/src/SolverFCT_solve.c - resolve to branch version, unused vars
paso/src/SparseMatrix_MatrixVector.c - resolve to branch version, unused vars.
escript/src/Utils.cpp - resloved to branch, needs WinSock2.h
escript/src/DataExpanded.cpp - resolved to branch version - LLWS
escript/src/DataFactory.cpp - resolve to branch version
=================================================================================

This currently passes tests on linux (debian), but is not checked on windows or Altix yet.

This checkin is to make a trunk I can check out for windows to do tests on it.

Known outstanding problem is in the operator=() method of exceptions
causing warning messages on the intel compilers.

May the God of doughnuts have mercy on my soul.


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26