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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 615 - (hide annotations)
Wed Mar 22 02:12:00 2006 UTC (13 years, 7 months ago) by elspeth
File MIME type: text/plain
File size: 10634 byte(s)
More copyright information.

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    
18 jgs 474 #include "DataArrayView.h"
19     #include "DataArray.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 jgs 82 which hold ESyS data.
34    
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     DataAbstract(const FunctionSpace& what);
61    
62     /**
63     \brief
64     Destructor for DataAbstract.
65     */
66 jgs 106 virtual
67     ~DataAbstract();
68 jgs 82
69     /**
70     \brief
71     Write the data as a string.
72     */
73     virtual
74     std::string
75     toString() const = 0;
76    
77     /**
78     \brief
79     Return the number of data points per sample.
80     */
81     int
82     getNumDPPSample() const;
83    
84     /**
85     \brief
86     Return the number of samples.
87     */
88     int
89     getNumSamples() const;
90    
91     /**
92     \brief
93     Return the DataArrayView of the point data. This essentially contains
94     the shape information for each data point although it also may be used
95     to manipulate the point data.
96     */
97 jgs 117 DataArrayView&
98     getPointDataView();
99    
100 jgs 82 const DataArrayView&
101     getPointDataView() const;
102    
103     /**
104     \brief
105 jgs 117 Return the offset for the given sample. This returns the offset for the given
106     point into the container holding the point data. Only really necessary to
107     avoid creating many DataArrayView objects.
108    
109 jgs 82 \param sampleNo - Input - sample number.
110 jgs 117 \param dataPointNo - Input - data point number.
111 jgs 82 */
112     virtual
113     ValueType::size_type
114     getPointOffset(int sampleNo,
115     int dataPointNo) const = 0;
116    
117     /**
118     \brief
119 jgs 117 Return the sample data for the given sample number.
120 jgs 82 */
121     double*
122     getSampleData(ValueType::size_type sampleNo);
123    
124     /**
125     \brief
126 jgs 117 Return the number of doubles stored for this Data object.
127 jgs 82 */
128     virtual
129     ValueType::size_type
130     getLength() const = 0;
131    
132     /**
133     \brief
134     Return the sample data for the given tag key.
135     NB: If the data isn't tagged an exception will be thrown.
136     */
137     virtual
138     double*
139     getSampleDataByTag(int tag);
140    
141     /**
142     \brief
143 jgs 110 Assign the given value to the data-points(s) referenced by the given
144     reference number.
145    
146     If this Data object cannot be accessed by reference numbers an
147     exception will be thrown.
148    
149     \param ref - Input - reference number.
150     \param value - Input - value to assign to data-points associated with
151     the given reference number.
152     */
153     virtual
154     void
155     setRefValue(int ref,
156     const DataArray& value);
157    
158     /**
159     \brief
160     Return the values associated with the data-point(s) referenced by the given
161     reference number.
162    
163     If this Data object cannot be accessed by reference numbers an
164     exception will be thrown.
165    
166     \param ref - Input - reference number.
167     \param value - Output - object to receive data-points associated with
168     the given reference number.
169     */
170     virtual
171     void
172     getRefValue(int ref,
173     DataArray& value);
174    
175     /**
176     \brief
177 jgs 117 Check this and the given RHS operands are compatible. Throws
178 jgs 82 an exception if they aren't.
179 jgs 117
180 jgs 82 \param right - Input - The right hand side.
181     */
182     void
183     operandCheck(const DataAbstract& right) const;
184    
185     /**
186     \brief
187     Return true if a valid sample point number.
188     */
189     bool
190     validSamplePointNo(int samplePointNo) const;
191    
192     /**
193     \brief
194 jgs 117 Return true if a valid sample number.
195 jgs 82 */
196     bool
197     validSampleNo(int sampleNo) const;
198    
199     /**
200     \brief
201     Return a view into the data for the data point specified.
202     NOTE: Construction of the DataArrayView is a relatively expensive
203     operation.
204 jgs 117
205     \param sampleNo - Input - the sample number.
206     \param dataPointNo - Input - the data point number.
207 jgs 82 */
208     virtual
209 jgs 106 DataArrayView
210 jgs 117 getDataPoint(int sampleNo,
211 jgs 106 int dataPointNo) = 0;
212 jgs 82
213     /**
214     \brief
215 jgs 117 Return the function space associated with this Data object.
216 jgs 82 */
217 jgs 117 const
218     FunctionSpace&
219 jgs 82 getFunctionSpace() const;
220    
221     /**
222     \brief
223 jgs 117 Return the given slice from this object.
224    
225     NB: The caller is responsible for managing the object created.
226 jgs 82 */
227     virtual
228     DataAbstract*
229     getSlice(const DataArrayView::RegionType& region) const = 0;
230    
231     /**
232     \brief
233 jgs 117 Copy the specified region from the given object.
234    
235 jgs 82 \param value - Input - Data to copy from
236     \param region - Input - Region to copy.
237     */
238     virtual
239     void
240     setSlice(const DataAbstract* value,
241     const DataArrayView::RegionType& region) = 0;
242    
243     /**
244     \brief
245 jgs 117 Reshape the data points if they are currently rank 0.
246 jgs 82 Will throw an exception if the data points are not rank 0.
247     The original data point value is used for all values of the new
248     data point.
249     */
250     virtual
251     void
252 jgs 117 reshapeDataPoint(const ShapeType& shape) = 0;
253 jgs 82
254     /**
255     \brief
256     setTaggedValue
257    
258     Description:
259     Assign the given value to the given tag.
260 jgs 117
261     NB: If the data isn't tagged an exception will be thrown.
262    
263 jgs 82 \param tagKey - Input - Integer key.
264     \param value - Input - Single DataArrayView value to be assigned to the tag.
265     */
266     virtual
267     void
268     setTaggedValue(int tagKey,
269     const DataArrayView& value);
270    
271 jgs 123 /**
272     \brief
273     Archive the underlying data values to the file referenced
274     by ofstream. A count of the number of values expected to be written
275     is provided as a cross-check.
276    
277     The return value indicates success (0) or otherwise (1).
278     */
279     virtual
280     int
281     archiveData(std::ofstream& archiveFile,
282     const ValueType::size_type noValues) const;
283    
284     /**
285     \brief
286     Extract the number of values specified by noValues from the file
287     referenced by ifstream to the underlying data structure.
288    
289     The return value indicates success (0) or otherwise (1).
290     */
291     virtual
292     int
293     extractData(std::ifstream& archiveFile,
294     const ValueType::size_type noValues);
295    
296 jgs 126 /**
297     \brief
298     Copy the numarray object to the data points in this object.
299    
300     Description:
301     Copy the numarray object to the data points in this object.
302    
303     \param value Input - new values for the data points
304     */
305     virtual void
306     copyAll(const boost::python::numeric::array& value);
307    
308 jgs 149 /**
309     \brief
310     Return the tag number associated with the given data-point number.
311 jgs 126
312 jgs 149 If the object cannot be referenced by tag numbers, an exception
313     will be thrown.
314     */
315     virtual
316     int
317     getTagNumber(int dpno);
318    
319 gross 576 /**
320     \brief
321     solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
322    
323     \param ev - Output - eigenvalues in increasing order at each data point
324    
325     */
326     virtual void
327     eigenvalues(DataAbstract* ev);
328    
329     /**
330     \brief
331     solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
332    
333     \param ev - Output - eigenvalues in increasing order at each data point
334     \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
335     and the first nonzero component is positive.
336     \param tol - Input - eigenvalue with relative distance tol are treated as equal.
337    
338     */
339    
340     virtual void
341     eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
342    
343 jgs 82 protected:
344    
345     /**
346     \brief
347 jgs 117 Set the pointDataView DataArrayView associated with this object.
348    
349 jgs 121 \param input - Input - The point data view. DataAbstract takes ownership
350 jgs 82 of the DataArrayView provided. It will delete it when it is destructed.
351     */
352     void
353     setPointDataView(const DataArrayView& input);
354    
355 jgs 119 void
356     resetPointDataView();
357    
358 jgs 82 private:
359    
360 jgs 117 //
361     // The number of samples in this Data object.
362     // This is derived directly from the FunctionSpace.
363 jgs 82 int m_noSamples;
364    
365     //
366 jgs 117 // The number of data points per sample in this Data object.
367     // This is derived directly from the FunctionSpace.
368     int m_noDataPointsPerSample;
369    
370     //
371     // The DataArrayView of the data array associated with this object.
372     // The data array is defined only in child classes of this class, it
373     // is not defined in this abstract parent class.
374 jgs 82 boost::scoped_ptr<DataArrayView> m_pointDataView;
375    
376     //
377 jgs 117 // A FunctionSpace which provides a description of the data associated
378     // with this Data object.
379 jgs 82 FunctionSpace m_functionSpace;
380    
381     };
382    
383     inline
384     bool
385 jgs 106 DataAbstract::validSamplePointNo(int samplePointNo) const
386 jgs 82 {
387     return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
388     }
389    
390     inline
391     bool
392     DataAbstract::validSampleNo(int sampleNo) const
393     {
394     return ((0 <= sampleNo) && (sampleNo < m_noSamples));
395     }
396    
397     inline
398     DataAbstract::ValueType::value_type*
399     DataAbstract::getSampleData(ValueType::size_type sampleNo)
400     {
401     return &(m_pointDataView->getData(getPointOffset(sampleNo,0)));
402     }
403    
404     inline
405     int
406     DataAbstract::getNumDPPSample() const
407     {
408     return m_noDataPointsPerSample;
409     }
410    
411     inline
412     int
413     DataAbstract::getNumSamples() const
414     {
415     return m_noSamples;
416     }
417    
418     inline
419 jgs 106 const
420     FunctionSpace&
421 jgs 82 DataAbstract::getFunctionSpace() const
422     {
423     return m_functionSpace;
424     }
425    
426     inline
427 jgs 106 const
428     DataArrayView&
429 jgs 82 DataAbstract::getPointDataView() const
430     {
431     return *(m_pointDataView.get());
432     }
433    
434     inline
435     DataArrayView&
436     DataAbstract::getPointDataView()
437     {
438     return *(m_pointDataView.get());
439     }
440     } // end of namespace
441 jgs 117
442 jgs 82 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26