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

Contents of /trunk/esys2/escript/src/Data/DataAbstract.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 126 - (show annotations)
Fri Jul 22 03:53:08 2005 UTC (13 years, 9 months ago) by jgs
File MIME type: text/plain
File size: 10109 byte(s)
Merge of development branch back to main trunk on 2005-07-22

1 // $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 #if !defined escript_DataAbstract_20040315_H
17 #define escript_DataAbstract_20040315_H
18
19 #include "escript/Data/DataException.h"
20 #include "escript/Data/DataArrayView.h"
21 #include "escript/Data/DataArray.h"
22 #include "escript/Data/FunctionSpace.h"
23
24 #include <iostream>
25 #include <fstream>
26 #include <boost/scoped_ptr.hpp>
27 #include <functional>
28 #include <string>
29
30 namespace escript {
31
32 /**
33 \brief
34 DataAbstract provides an abstract interface for the class of containers
35 which hold ESyS data.
36
37 Description:
38 DataAbstract provides an abstract interface for the class of containers
39 which hold ESyS data. The container may be thought of as a 2 dimensional
40 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 */
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
60 \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 virtual
69 ~DataAbstract();
70
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 DataArrayView&
100 getPointDataView();
101
102 const DataArrayView&
103 getPointDataView() const;
104
105 /**
106 \brief
107 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 \param sampleNo - Input - sample number.
112 \param dataPointNo - Input - data point number.
113 */
114 virtual
115 ValueType::size_type
116 getPointOffset(int sampleNo,
117 int dataPointNo) const = 0;
118
119 /**
120 \brief
121 Return the sample data for the given sample number.
122 */
123 double*
124 getSampleData(ValueType::size_type sampleNo);
125
126 /**
127 \brief
128 Return the number of doubles stored for this Data object.
129 */
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 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 Check this and the given RHS operands are compatible. Throws
180 an exception if they aren't.
181
182 \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 Return true if a valid sample number.
197 */
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
207 \param sampleNo - Input - the sample number.
208 \param dataPointNo - Input - the data point number.
209 */
210 virtual
211 DataArrayView
212 getDataPoint(int sampleNo,
213 int dataPointNo) = 0;
214
215 /**
216 \brief
217 Return the function space associated with this Data object.
218 */
219 const
220 FunctionSpace&
221 getFunctionSpace() const;
222
223 /**
224 \brief
225 Return the given slice from this object.
226
227 NB: The caller is responsible for managing the object created.
228 */
229 virtual
230 DataAbstract*
231 getSlice(const DataArrayView::RegionType& region) const = 0;
232
233 /**
234 \brief
235 Copy the specified region from the given object.
236
237 \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 Reshape the data points if they are currently rank 0.
248 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 reshapeDataPoint(const ShapeType& shape) = 0;
255
256 /**
257 \brief
258 setTaggedValue
259
260 Description:
261 Assign the given value to the given tag.
262
263 NB: If the data isn't tagged an exception will be thrown.
264
265 \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 /**
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 /**
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
311 protected:
312
313 /**
314 \brief
315 Set the pointDataView DataArrayView associated with this object.
316
317 \param input - Input - The point data view. DataAbstract takes ownership
318 of the DataArrayView provided. It will delete it when it is destructed.
319 */
320 void
321 setPointDataView(const DataArrayView& input);
322
323 void
324 resetPointDataView();
325
326 private:
327
328 //
329 // The number of samples in this Data object.
330 // This is derived directly from the FunctionSpace.
331 int m_noSamples;
332
333 //
334 // The number of data points per sample in this Data object.
335 // This is derived directly from the FunctionSpace.
336 int m_noDataPointsPerSample;
337
338 //
339 // The DataArrayView of the data array associated with this object.
340 // The data array is defined only in child classes of this class, it
341 // is not defined in this abstract parent class.
342 boost::scoped_ptr<DataArrayView> m_pointDataView;
343
344 //
345 // A FunctionSpace which provides a description of the data associated
346 // with this Data object.
347 FunctionSpace m_functionSpace;
348
349 };
350
351 inline
352 bool
353 DataAbstract::validSamplePointNo(int samplePointNo) const
354 {
355 return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
356 }
357
358 inline
359 bool
360 DataAbstract::validSampleNo(int sampleNo) const
361 {
362 return ((0 <= sampleNo) && (sampleNo < m_noSamples));
363 }
364
365 inline
366 DataAbstract::ValueType::value_type*
367 DataAbstract::getSampleData(ValueType::size_type sampleNo)
368 {
369 return &(m_pointDataView->getData(getPointOffset(sampleNo,0)));
370 }
371
372 inline
373 int
374 DataAbstract::getNumDPPSample() const
375 {
376 return m_noDataPointsPerSample;
377 }
378
379 inline
380 int
381 DataAbstract::getNumSamples() const
382 {
383 return m_noSamples;
384 }
385
386 inline
387 const
388 FunctionSpace&
389 DataAbstract::getFunctionSpace() const
390 {
391 return m_functionSpace;
392 }
393
394 inline
395 const
396 DataArrayView&
397 DataAbstract::getPointDataView() const
398 {
399 return *(m_pointDataView.get());
400 }
401
402 inline
403 DataArrayView&
404 DataAbstract::getPointDataView()
405 {
406 return *(m_pointDataView.get());
407 }
408
409 } // end of namespace
410
411 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26