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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 964 - (hide annotations)
Tue Feb 13 05:10:26 2007 UTC (12 years, 8 months ago) by gross
File MIME type: text/plain
File size: 12044 byte(s)
The set/getRefVal functions of Data objects have been removed (mainly to avoid later problems with MPI).
Moreover, a faster access to the reference id of samples has been introduced. I don't think that anybody will
profit form this at this stage but it will allow a faster dump of data objects.


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26