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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1388 - (hide annotations)
Fri Jan 11 07:45:58 2008 UTC (11 years, 9 months ago) by trankine
File MIME type: text/plain
File size: 11846 byte(s)
And get the *(&(*&(* name right
1 ksteube 1312 /* $Id$ */
2 jgs 478
3 ksteube 1312 /*******************************************************
4     *
5     * Copyright 2003-2007 by ACceSS MNRF
6     * Copyright 2007 by University of Queensland
7     *
8     * http://esscc.uq.edu.au
9     * Primary Business: Queensland, Australia
10     * Licensed under the Open Software License version 3.0
11     * http://www.opensource.org/licenses/osl-3.0.php
12     *
13     *******************************************************/
14    
15 jgs 106 #if !defined escript_DataAbstract_20040315_H
16 jgs 82 #define escript_DataAbstract_20040315_H
17 woo409 757 #include "system_dep.h"
18 jgs 82
19 jgs 474 #include "DataArrayView.h"
20     #include "FunctionSpace.h"
21 jgs 82
22     #include <boost/scoped_ptr.hpp>
23 jgs 478 #include <boost/python/numeric.hpp>
24 jgs 480
25 jgs 82 #include <string>
26 jgs 480 #include <fstream>
27 jgs 82
28     namespace escript {
29    
30     /**
31     \brief
32 jgs 117 DataAbstract provides an abstract interface for the class of containers
33 matt 1325 which hold ESyS data.
34 jgs 82
35     Description:
36 jgs 117 DataAbstract provides an abstract interface for the class of containers
37 jgs 82 which hold ESyS data. The container may be thought of as a 2 dimensional
38 jgs 117 array of data points where one dimension corresponds to the number of samples
39     and the other to the number of data points per sample as defined by the function
40     space associated with each Data object. The data points themselves are arrays of
41     doubles of rank 0-4.
42 jgs 82 */
43    
44     class DataAbstract {
45    
46     public:
47    
48     typedef DataArrayView::ValueType ValueType;
49     typedef DataArrayView::ShapeType ShapeType;
50    
51     /**
52     \brief
53     Constructor for DataAbstract.
54    
55     Description:
56     Constructor for DataAbstract.
57 jgs 117
58 jgs 82 \param what - Input - A description of what this data represents.
59     */
60 woo409 757 ESCRIPT_DLL_API
61 jgs 82 DataAbstract(const FunctionSpace& what);
62    
63     /**
64     \brief
65     Destructor for DataAbstract.
66     */
67 woo409 757 ESCRIPT_DLL_API
68 jgs 106 virtual
69     ~DataAbstract();
70 jgs 82
71     /**
72     \brief
73     Write the data as a string.
74     */
75 woo409 757 ESCRIPT_DLL_API
76 jgs 82 virtual
77     std::string
78     toString() const = 0;
79    
80 gross 950 /**
81     \brief
82     dumps the object into a netCDF file
83     */
84     ESCRIPT_DLL_API
85     virtual
86     void
87     dump(const std::string fileName) const;
88    
89 jgs 82 /**
90     \brief
91     Return the number of data points per sample.
92     */
93 woo409 757 ESCRIPT_DLL_API
94 jgs 82 int
95     getNumDPPSample() const;
96    
97     /**
98     \brief
99     Return the number of samples.
100     */
101 woo409 757 ESCRIPT_DLL_API
102 jgs 82 int
103     getNumSamples() const;
104    
105     /**
106     \brief
107 matt 1325 Return the DataArrayView of the point data. This essentially contains
108 jgs 82 the shape information for each data point although it also may be used
109     to manipulate the point data.
110     */
111 woo409 757 ESCRIPT_DLL_API
112 jgs 117 DataArrayView&
113     getPointDataView();
114    
115 woo409 757 ESCRIPT_DLL_API
116 jgs 82 const DataArrayView&
117     getPointDataView() const;
118    
119     /**
120     \brief
121 jgs 117 Return the offset for the given sample. This returns the offset for the given
122     point into the container holding the point data. Only really necessary to
123     avoid creating many DataArrayView objects.
124    
125 jgs 82 \param sampleNo - Input - sample number.
126 jgs 117 \param dataPointNo - Input - data point number.
127 jgs 82 */
128 woo409 757 ESCRIPT_DLL_API
129 jgs 82 virtual
130     ValueType::size_type
131     getPointOffset(int sampleNo,
132     int dataPointNo) const = 0;
133    
134     /**
135     \brief
136 jgs 117 Return the sample data for the given sample number.
137 jgs 82 */
138 woo409 757 ESCRIPT_DLL_API
139 jgs 82 double*
140     getSampleData(ValueType::size_type sampleNo);
141    
142     /**
143     \brief
144 jgs 117 Return the number of doubles stored for this Data object.
145 jgs 82 */
146 woo409 757 ESCRIPT_DLL_API
147 jgs 82 virtual
148     ValueType::size_type
149     getLength() const = 0;
150    
151     /**
152     \brief
153     Return the sample data for the given tag key.
154     NB: If the data isn't tagged an exception will be thrown.
155     */
156 woo409 757 ESCRIPT_DLL_API
157 jgs 82 virtual
158     double*
159     getSampleDataByTag(int tag);
160    
161 jgs 110
162     /**
163     \brief
164 jgs 117 Check this and the given RHS operands are compatible. Throws
165 jgs 82 an exception if they aren't.
166 jgs 117
167 jgs 82 \param right - Input - The right hand side.
168     */
169 woo409 757 ESCRIPT_DLL_API
170 jgs 82 void
171     operandCheck(const DataAbstract& right) const;
172    
173     /**
174     \brief
175     Return true if a valid sample point number.
176     */
177 woo409 757 ESCRIPT_DLL_API
178 jgs 82 bool
179     validSamplePointNo(int samplePointNo) const;
180    
181     /**
182     \brief
183 jgs 117 Return true if a valid sample number.
184 jgs 82 */
185 woo409 757 ESCRIPT_DLL_API
186 jgs 82 bool
187     validSampleNo(int sampleNo) const;
188 matt 1325
189 jgs 82 /**
190     \brief
191     Return a view into the data for the data point specified.
192 matt 1325 NOTE: Construction of the DataArrayView is a relatively expensive
193 jgs 82 operation.
194 jgs 117
195     \param sampleNo - Input - the sample number.
196     \param dataPointNo - Input - the data point number.
197 jgs 82 */
198 woo409 757 ESCRIPT_DLL_API
199 jgs 82 virtual
200 jgs 106 DataArrayView
201 jgs 117 getDataPoint(int sampleNo,
202 jgs 106 int dataPointNo) = 0;
203 jgs 82
204     /**
205     \brief
206 jgs 117 Return the function space associated with this Data object.
207 jgs 82 */
208 woo409 757 ESCRIPT_DLL_API
209 jgs 117 const
210     FunctionSpace&
211 jgs 82 getFunctionSpace() const;
212    
213     /**
214     \brief
215 jgs 117 Return the given slice from this object.
216    
217     NB: The caller is responsible for managing the object created.
218 jgs 82 */
219 woo409 757 ESCRIPT_DLL_API
220 jgs 82 virtual
221     DataAbstract*
222     getSlice(const DataArrayView::RegionType& region) const = 0;
223    
224     /**
225     \brief
226 jgs 117 Copy the specified region from the given object.
227    
228 jgs 82 \param value - Input - Data to copy from
229     \param region - Input - Region to copy.
230     */
231 woo409 757 ESCRIPT_DLL_API
232 jgs 82 virtual
233     void
234     setSlice(const DataAbstract* value,
235     const DataArrayView::RegionType& region) = 0;
236    
237    
238     /**
239     \brief
240     setTaggedValue
241 matt 1325
242 jgs 82 Description:
243     Assign the given value to the given tag.
244 jgs 117
245     NB: If the data isn't tagged an exception will be thrown.
246    
247 jgs 82 \param tagKey - Input - Integer key.
248     \param value - Input - Single DataArrayView value to be assigned to the tag.
249     */
250 woo409 757 ESCRIPT_DLL_API
251 jgs 82 virtual
252     void
253     setTaggedValue(int tagKey,
254     const DataArrayView& value);
255    
256 jgs 123 /**
257     \brief
258     Archive the underlying data values to the file referenced
259     by ofstream. A count of the number of values expected to be written
260     is provided as a cross-check.
261    
262     The return value indicates success (0) or otherwise (1).
263     */
264 woo409 757 ESCRIPT_DLL_API
265 jgs 123 virtual
266     int
267     archiveData(std::ofstream& archiveFile,
268     const ValueType::size_type noValues) const;
269    
270     /**
271     \brief
272     Extract the number of values specified by noValues from the file
273     referenced by ifstream to the underlying data structure.
274    
275     The return value indicates success (0) or otherwise (1).
276     */
277 woo409 757 ESCRIPT_DLL_API
278 jgs 123 virtual
279     int
280     extractData(std::ifstream& archiveFile,
281     const ValueType::size_type noValues);
282    
283 jgs 126 /**
284     \brief
285     Copy the numarray object to the data points in this object.
286    
287     Description:
288     Copy the numarray object to the data points in this object.
289    
290     \param value Input - new values for the data points
291     */
292 woo409 757 ESCRIPT_DLL_API
293 jgs 126 virtual void
294     copyAll(const boost::python::numeric::array& value);
295    
296 jgs 149 /**
297     \brief
298 gross 922 Copy a double value to the data point dataPointNo of sample sampleNo in this object.
299    
300     Description:
301     Copy a double value to the data point dataPointNo of sample sampleNo in this object.
302    
303     \param sampleNo Input - sample number
304     \param dataPointNo Input - data point of the sample
305     \param value Input - new values for the data point
306     */
307     ESCRIPT_DLL_API
308     virtual void
309     copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
310    
311     /**
312     \brief
313 gross 921 Copy the numarray object to the data point dataPointNo of sample sampleNo in this object.
314    
315     Description:
316     Copy the numarray object to the data point dataPointNo of sample sampleNo in this object.
317    
318     \param sampleNo Input - sample number
319     \param dataPointNo Input - data point of the sample
320     \param value Input - new values for the data point
321     */
322     ESCRIPT_DLL_API
323     virtual void
324     copyToDataPoint(const int sampleNo, const int dataPointNo, const boost::python::numeric::array& value);
325    
326    
327     /**
328     \brief
329 jgs 149 Return the tag number associated with the given data-point number.
330 jgs 126
331 jgs 149 If the object cannot be referenced by tag numbers, an exception
332     will be thrown.
333     */
334 woo409 757 ESCRIPT_DLL_API
335 jgs 149 virtual
336     int
337     getTagNumber(int dpno);
338    
339 gross 576 /**
340     \brief
341 ksteube 775 Computes a symmetric matrix (A + AT) / 2
342    
343     \param ev - Output - a symmetric matrix
344    
345     */
346 gross 800 ESCRIPT_DLL_API
347 ksteube 775 virtual void
348     symmetric(DataAbstract* ev);
349    
350     /**
351     \brief
352     Computes a nonsymmetric matrix (A - AT) / 2
353    
354     \param ev - Output - a nonsymmetric matrix
355    
356     */
357 gross 800 ESCRIPT_DLL_API
358 ksteube 775 virtual void
359     nonsymmetric(DataAbstract* ev);
360    
361     /**
362     \brief
363     Computes the trace of a matrix
364    
365     \param ev - Output - the trace of a matrix
366    
367     */
368 gross 800 ESCRIPT_DLL_API
369 ksteube 775 virtual void
370 gross 800 trace(DataAbstract* ev, int axis_offset);
371 ksteube 775
372     /**
373     \brief
374     Transpose each data point of this Data object around the given axis.
375    
376     \param ev - Output - the transpose of a matrix
377    
378     */
379 gross 800 ESCRIPT_DLL_API
380 ksteube 775 virtual void
381     transpose(DataAbstract* ev, int axis_offset);
382    
383     /**
384     \brief
385 gross 804 swaps components axis0 and axis1
386 gross 800
387     \param ev - Output - swapped components
388    
389     */
390     ESCRIPT_DLL_API
391     virtual void
392 gross 804 swapaxes(DataAbstract* ev, int axis0, int axis1);
393 gross 800 /**
394     \brief
395 gross 576 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
396    
397     \param ev - Output - eigenvalues in increasing order at each data point
398    
399     */
400 woo409 757 ESCRIPT_DLL_API
401 gross 576 virtual void
402     eigenvalues(DataAbstract* ev);
403    
404     /**
405     \brief
406 gross 1118 sets values to zero
407    
408     */
409     ESCRIPT_DLL_API
410     virtual void
411     setToZero();
412    
413     /**
414     \brief
415 gross 576 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
416    
417     \param ev - Output - eigenvalues in increasing order at each data point
418     \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
419     and the first nonzero component is positive.
420     \param tol - Input - eigenvalue with relative distance tol are treated as equal.
421    
422     */
423    
424 woo409 757 ESCRIPT_DLL_API
425 gross 576 virtual void
426     eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
427    
428 jgs 82 protected:
429    
430     /**
431     \brief
432 jgs 117 Set the pointDataView DataArrayView associated with this object.
433    
434 jgs 121 \param input - Input - The point data view. DataAbstract takes ownership
435 jgs 82 of the DataArrayView provided. It will delete it when it is destructed.
436     */
437 woo409 757 ESCRIPT_DLL_API
438 jgs 82 void
439     setPointDataView(const DataArrayView& input);
440    
441 woo409 757 ESCRIPT_DLL_API
442 jgs 119 void
443     resetPointDataView();
444    
445 jgs 82 private:
446    
447 jgs 117 //
448     // The number of samples in this Data object.
449     // This is derived directly from the FunctionSpace.
450 jgs 82 int m_noSamples;
451    
452     //
453 jgs 117 // The number of data points per sample in this Data object.
454     // This is derived directly from the FunctionSpace.
455     int m_noDataPointsPerSample;
456    
457     //
458     // The DataArrayView of the data array associated with this object.
459     // The data array is defined only in child classes of this class, it
460     // is not defined in this abstract parent class.
461 jgs 82 boost::scoped_ptr<DataArrayView> m_pointDataView;
462    
463     //
464 jgs 117 // A FunctionSpace which provides a description of the data associated
465     // with this Data object.
466 jgs 82 FunctionSpace m_functionSpace;
467    
468     };
469    
470     inline
471     bool
472 matt 1325 DataAbstract::validSamplePointNo(int samplePointNo) const
473 jgs 82 {
474     return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
475     }
476    
477     inline
478     bool
479     DataAbstract::validSampleNo(int sampleNo) const
480     {
481     return ((0 <= sampleNo) && (sampleNo < m_noSamples));
482     }
483    
484     inline
485     DataAbstract::ValueType::value_type*
486     DataAbstract::getSampleData(ValueType::size_type sampleNo)
487     {
488     return &(m_pointDataView->getData(getPointOffset(sampleNo,0)));
489     }
490    
491     inline
492     int
493 matt 1325 DataAbstract::getNumDPPSample() const
494 jgs 82 {
495     return m_noDataPointsPerSample;
496     }
497    
498     inline
499     int
500     DataAbstract::getNumSamples() const
501     {
502     return m_noSamples;
503     }
504    
505     inline
506 jgs 106 const
507     FunctionSpace&
508 jgs 82 DataAbstract::getFunctionSpace() const
509     {
510     return m_functionSpace;
511     }
512    
513     inline
514 jgs 106 const
515     DataArrayView&
516 jgs 82 DataAbstract::getPointDataView() const
517     {
518     return *(m_pointDataView.get());
519     }
520    
521     inline
522     DataArrayView&
523     DataAbstract::getPointDataView()
524     {
525     return *(m_pointDataView.get());
526     }
527     } // end of namespace
528 jgs 117
529 jgs 82 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26