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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 474 - (hide annotations)
Mon Jan 30 04:23:44 2006 UTC (13 years, 9 months ago) by jgs
File MIME type: text/plain
File size: 10285 byte(s)
restructure escript source tree
move src/Data/* -> src
remove inc
modify #includes and cpppath settings accordingly

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26