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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 480 - (hide annotations)
Wed Feb 1 05:15:12 2006 UTC (13 years, 9 months ago) by jgs
File MIME type: text/plain
File size: 10178 byte(s)
rationalise #includes and forward declarations

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26