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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 950 - (hide annotations)
Tue Feb 6 07:01:11 2007 UTC (12 years, 9 months ago) by gross
File MIME type: text/plain
File size: 13089 byte(s)
escript data objects can now be saved to netCDF files, see http://www.unidata.ucar.edu/software/netcdf/.
Currently only constant data are implemented with expanded and tagged data to follow.
There are two new functions to dump a data object

   s=Data(...)
   s.dump(<filename>)

and to recover it

   s=load(<filename>, domain)

Notice that the function space of s is recovered but domain is still need. 

dump and load will replace archive and extract.

The installation needs now the netCDF installed. 


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     /**
163     \brief
164 jgs 110 Assign the given value to the data-points(s) referenced by the given
165     reference number.
166    
167     If this Data object cannot be accessed by reference numbers an
168     exception will be thrown.
169    
170     \param ref - Input - reference number.
171     \param value - Input - value to assign to data-points associated with
172     the given reference number.
173     */
174 woo409 757 ESCRIPT_DLL_API
175 jgs 110 virtual
176     void
177 gross 950 setValueByReferenceNumber(int ref,
178     const DataArray& value);
179 jgs 110
180     /**
181     \brief
182     Return the values associated with the data-point(s) referenced by the given
183     reference number.
184    
185     If this Data object cannot be accessed by reference numbers an
186     exception will be thrown.
187    
188     \param ref - Input - reference number.
189     \param value - Output - object to receive data-points associated with
190     the given reference number.
191     */
192 woo409 757 ESCRIPT_DLL_API
193 jgs 110 virtual
194     void
195 gross 950 getValueByReferenceNumber(int ref,
196     DataArray& value);
197 jgs 110
198     /**
199     \brief
200 jgs 117 Check this and the given RHS operands are compatible. Throws
201 jgs 82 an exception if they aren't.
202 jgs 117
203 jgs 82 \param right - Input - The right hand side.
204     */
205 woo409 757 ESCRIPT_DLL_API
206 jgs 82 void
207     operandCheck(const DataAbstract& right) const;
208    
209     /**
210     \brief
211     Return true if a valid sample point number.
212     */
213 woo409 757 ESCRIPT_DLL_API
214 jgs 82 bool
215     validSamplePointNo(int samplePointNo) const;
216    
217     /**
218     \brief
219 jgs 117 Return true if a valid sample number.
220 jgs 82 */
221 woo409 757 ESCRIPT_DLL_API
222 jgs 82 bool
223     validSampleNo(int sampleNo) const;
224    
225     /**
226     \brief
227     Return a view into the data for the data point specified.
228     NOTE: Construction of the DataArrayView is a relatively expensive
229     operation.
230 jgs 117
231     \param sampleNo - Input - the sample number.
232     \param dataPointNo - Input - the data point number.
233 jgs 82 */
234 woo409 757 ESCRIPT_DLL_API
235 jgs 82 virtual
236 jgs 106 DataArrayView
237 jgs 117 getDataPoint(int sampleNo,
238 jgs 106 int dataPointNo) = 0;
239 jgs 82
240     /**
241     \brief
242 jgs 117 Return the function space associated with this Data object.
243 jgs 82 */
244 woo409 757 ESCRIPT_DLL_API
245 jgs 117 const
246     FunctionSpace&
247 jgs 82 getFunctionSpace() const;
248    
249     /**
250     \brief
251 jgs 117 Return the given slice from this object.
252    
253     NB: The caller is responsible for managing the object created.
254 jgs 82 */
255 woo409 757 ESCRIPT_DLL_API
256 jgs 82 virtual
257     DataAbstract*
258     getSlice(const DataArrayView::RegionType& region) const = 0;
259    
260     /**
261     \brief
262 jgs 117 Copy the specified region from the given object.
263    
264 jgs 82 \param value - Input - Data to copy from
265     \param region - Input - Region to copy.
266     */
267 woo409 757 ESCRIPT_DLL_API
268 jgs 82 virtual
269     void
270     setSlice(const DataAbstract* value,
271     const DataArrayView::RegionType& region) = 0;
272    
273    
274     /**
275     \brief
276     setTaggedValue
277    
278     Description:
279     Assign the given value to the given tag.
280 jgs 117
281     NB: If the data isn't tagged an exception will be thrown.
282    
283 jgs 82 \param tagKey - Input - Integer key.
284     \param value - Input - Single DataArrayView value to be assigned to the tag.
285     */
286 woo409 757 ESCRIPT_DLL_API
287 jgs 82 virtual
288     void
289     setTaggedValue(int tagKey,
290     const DataArrayView& value);
291    
292 jgs 123 /**
293     \brief
294     Archive the underlying data values to the file referenced
295     by ofstream. A count of the number of values expected to be written
296     is provided as a cross-check.
297    
298     The return value indicates success (0) or otherwise (1).
299     */
300 woo409 757 ESCRIPT_DLL_API
301 jgs 123 virtual
302     int
303     archiveData(std::ofstream& archiveFile,
304     const ValueType::size_type noValues) const;
305    
306     /**
307     \brief
308     Extract the number of values specified by noValues from the file
309     referenced by ifstream to the underlying data structure.
310    
311     The return value indicates success (0) or otherwise (1).
312     */
313 woo409 757 ESCRIPT_DLL_API
314 jgs 123 virtual
315     int
316     extractData(std::ifstream& archiveFile,
317     const ValueType::size_type noValues);
318    
319 jgs 126 /**
320     \brief
321     Copy the numarray object to the data points in this object.
322    
323     Description:
324     Copy the numarray object to the data points in this object.
325    
326     \param value Input - new values for the data points
327     */
328 woo409 757 ESCRIPT_DLL_API
329 jgs 126 virtual void
330     copyAll(const boost::python::numeric::array& value);
331    
332 jgs 149 /**
333     \brief
334 gross 922 Copy a double value to the data point dataPointNo of sample sampleNo in this object.
335    
336     Description:
337     Copy a double value to the data point dataPointNo of sample sampleNo in this object.
338    
339     \param sampleNo Input - sample number
340     \param dataPointNo Input - data point of the sample
341     \param value Input - new values for the data point
342     */
343     ESCRIPT_DLL_API
344     virtual void
345     copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
346    
347     /**
348     \brief
349 gross 921 Copy the numarray object to the data point dataPointNo of sample sampleNo in this object.
350    
351     Description:
352     Copy the numarray object to the data point dataPointNo of sample sampleNo in this object.
353    
354     \param sampleNo Input - sample number
355     \param dataPointNo Input - data point of the sample
356     \param value Input - new values for the data point
357     */
358     ESCRIPT_DLL_API
359     virtual void
360     copyToDataPoint(const int sampleNo, const int dataPointNo, const boost::python::numeric::array& value);
361    
362    
363     /**
364     \brief
365 jgs 149 Return the tag number associated with the given data-point number.
366 jgs 126
367 jgs 149 If the object cannot be referenced by tag numbers, an exception
368     will be thrown.
369     */
370 woo409 757 ESCRIPT_DLL_API
371 jgs 149 virtual
372     int
373     getTagNumber(int dpno);
374    
375 gross 576 /**
376     \brief
377 ksteube 775 Computes a symmetric matrix (A + AT) / 2
378    
379     \param ev - Output - a symmetric matrix
380    
381     */
382 gross 800 ESCRIPT_DLL_API
383 ksteube 775 virtual void
384     symmetric(DataAbstract* ev);
385    
386     /**
387     \brief
388     Computes a nonsymmetric matrix (A - AT) / 2
389    
390     \param ev - Output - a nonsymmetric matrix
391    
392     */
393 gross 800 ESCRIPT_DLL_API
394 ksteube 775 virtual void
395     nonsymmetric(DataAbstract* ev);
396    
397     /**
398     \brief
399     Computes the trace of a matrix
400    
401     \param ev - Output - the trace of a matrix
402    
403     */
404 gross 800 ESCRIPT_DLL_API
405 ksteube 775 virtual void
406 gross 800 trace(DataAbstract* ev, int axis_offset);
407 ksteube 775
408     /**
409     \brief
410     Transpose each data point of this Data object around the given axis.
411    
412     \param ev - Output - the transpose of a matrix
413    
414     */
415 gross 800 ESCRIPT_DLL_API
416 ksteube 775 virtual void
417     transpose(DataAbstract* ev, int axis_offset);
418    
419     /**
420     \brief
421 gross 804 swaps components axis0 and axis1
422 gross 800
423     \param ev - Output - swapped components
424    
425     */
426     ESCRIPT_DLL_API
427     virtual void
428 gross 804 swapaxes(DataAbstract* ev, int axis0, int axis1);
429 gross 800 /**
430     \brief
431 gross 576 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
432    
433     \param ev - Output - eigenvalues in increasing order at each data point
434    
435     */
436 woo409 757 ESCRIPT_DLL_API
437 gross 576 virtual void
438     eigenvalues(DataAbstract* ev);
439    
440     /**
441     \brief
442     solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
443    
444     \param ev - Output - eigenvalues in increasing order at each data point
445     \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
446     and the first nonzero component is positive.
447     \param tol - Input - eigenvalue with relative distance tol are treated as equal.
448    
449     */
450    
451 woo409 757 ESCRIPT_DLL_API
452 gross 576 virtual void
453     eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
454    
455 jgs 82 protected:
456    
457     /**
458     \brief
459 jgs 117 Set the pointDataView DataArrayView associated with this object.
460    
461 jgs 121 \param input - Input - The point data view. DataAbstract takes ownership
462 jgs 82 of the DataArrayView provided. It will delete it when it is destructed.
463     */
464 woo409 757 ESCRIPT_DLL_API
465 jgs 82 void
466     setPointDataView(const DataArrayView& input);
467    
468 woo409 757 ESCRIPT_DLL_API
469 jgs 119 void
470     resetPointDataView();
471    
472 jgs 82 private:
473    
474 jgs 117 //
475     // The number of samples in this Data object.
476     // This is derived directly from the FunctionSpace.
477 jgs 82 int m_noSamples;
478    
479     //
480 jgs 117 // The number of data points per sample in this Data object.
481     // This is derived directly from the FunctionSpace.
482     int m_noDataPointsPerSample;
483    
484     //
485     // The DataArrayView of the data array associated with this object.
486     // The data array is defined only in child classes of this class, it
487     // is not defined in this abstract parent class.
488 jgs 82 boost::scoped_ptr<DataArrayView> m_pointDataView;
489    
490     //
491 jgs 117 // A FunctionSpace which provides a description of the data associated
492     // with this Data object.
493 jgs 82 FunctionSpace m_functionSpace;
494    
495     };
496    
497     inline
498     bool
499 jgs 106 DataAbstract::validSamplePointNo(int samplePointNo) const
500 jgs 82 {
501     return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
502     }
503    
504     inline
505     bool
506     DataAbstract::validSampleNo(int sampleNo) const
507     {
508     return ((0 <= sampleNo) && (sampleNo < m_noSamples));
509     }
510    
511     inline
512     DataAbstract::ValueType::value_type*
513     DataAbstract::getSampleData(ValueType::size_type sampleNo)
514     {
515     return &(m_pointDataView->getData(getPointOffset(sampleNo,0)));
516     }
517    
518     inline
519     int
520     DataAbstract::getNumDPPSample() const
521     {
522     return m_noDataPointsPerSample;
523     }
524    
525     inline
526     int
527     DataAbstract::getNumSamples() const
528     {
529     return m_noSamples;
530     }
531    
532     inline
533 jgs 106 const
534     FunctionSpace&
535 jgs 82 DataAbstract::getFunctionSpace() const
536     {
537     return m_functionSpace;
538     }
539    
540     inline
541 jgs 106 const
542     DataArrayView&
543 jgs 82 DataAbstract::getPointDataView() const
544     {
545     return *(m_pointDataView.get());
546     }
547    
548     inline
549     DataArrayView&
550     DataAbstract::getPointDataView()
551     {
552     return *(m_pointDataView.get());
553     }
554     } // end of namespace
555 jgs 117
556 jgs 82 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26