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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1312 - (hide annotations)
Mon Sep 24 06:18:44 2007 UTC (12 years, 1 month ago) by ksteube
File MIME type: text/plain
File size: 12007 byte(s)
The MPI branch is hereby closed. All future work should be in trunk.

Previously in revision 1295 I merged the latest changes to trunk into trunk-mpi-branch.
In this revision I copied all files from trunk-mpi-branch over the corresponding
trunk files. I did not use 'svn merge', it was a copy.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26