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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 121 - (show annotations)
Fri May 6 04:26:16 2005 UTC (14 years, 4 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/DataAbstract.h
File MIME type: text/plain
File size: 9094 byte(s)
Merge of development branch back to main trunk on 2005-05-06

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 <boost/scoped_ptr.hpp>
26 #include <functional>
27 #include <string>
28
29 namespace escript {
30
31 /**
32 \brief
33 DataAbstract provides an abstract interface for the class of containers
34 which hold ESyS data.
35
36 Description:
37 DataAbstract provides an abstract interface for the class of containers
38 which hold ESyS data. The container may be thought of as a 2 dimensional
39 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 */
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
59 \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 virtual
68 ~DataAbstract();
69
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 DataArrayView&
99 getPointDataView();
100
101 const DataArrayView&
102 getPointDataView() const;
103
104 /**
105 \brief
106 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 \param sampleNo - Input - sample number.
111 \param dataPointNo - Input - data point number.
112 */
113 virtual
114 ValueType::size_type
115 getPointOffset(int sampleNo,
116 int dataPointNo) const = 0;
117
118 /**
119 \brief
120 Return the sample data for the given sample number.
121 */
122 double*
123 getSampleData(ValueType::size_type sampleNo);
124
125 /**
126 \brief
127 Return the number of doubles stored for this Data object.
128 */
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 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 Check this and the given RHS operands are compatible. Throws
179 an exception if they aren't.
180
181 \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 Return true if a valid sample number.
196 */
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
206 \param sampleNo - Input - the sample number.
207 \param dataPointNo - Input - the data point number.
208 */
209 virtual
210 DataArrayView
211 getDataPoint(int sampleNo,
212 int dataPointNo) = 0;
213
214 /**
215 \brief
216 Return the function space associated with this Data object.
217 */
218 const
219 FunctionSpace&
220 getFunctionSpace() const;
221
222 /**
223 \brief
224 Return the given slice from this object.
225
226 NB: The caller is responsible for managing the object created.
227 */
228 virtual
229 DataAbstract*
230 getSlice(const DataArrayView::RegionType& region) const = 0;
231
232 /**
233 \brief
234 Copy the specified region from the given object.
235
236 \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 Reshape the data points if they are currently rank 0.
247 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 reshapeDataPoint(const ShapeType& shape) = 0;
254
255 /**
256 \brief
257 setTaggedValue
258
259 Description:
260 Assign the given value to the given tag.
261
262 NB: If the data isn't tagged an exception will be thrown.
263
264 \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 protected:
273
274 /**
275 \brief
276 Set the pointDataView DataArrayView associated with this object.
277
278 \param input - Input - The point data view. DataAbstract takes ownership
279 of the DataArrayView provided. It will delete it when it is destructed.
280 */
281 void
282 setPointDataView(const DataArrayView& input);
283
284 void
285 resetPointDataView();
286
287 private:
288
289 //
290 // The number of samples in this Data object.
291 // This is derived directly from the FunctionSpace.
292 int m_noSamples;
293
294 //
295 // The number of data points per sample in this Data object.
296 // This is derived directly from the FunctionSpace.
297 int m_noDataPointsPerSample;
298
299 //
300 // The DataArrayView of the data array associated with this object.
301 // The data array is defined only in child classes of this class, it
302 // is not defined in this abstract parent class.
303 boost::scoped_ptr<DataArrayView> m_pointDataView;
304
305 //
306 // A FunctionSpace which provides a description of the data associated
307 // with this Data object.
308 FunctionSpace m_functionSpace;
309
310 };
311
312 inline
313 bool
314 DataAbstract::validSamplePointNo(int samplePointNo) const
315 {
316 return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
317 }
318
319 inline
320 bool
321 DataAbstract::validSampleNo(int sampleNo) const
322 {
323 return ((0 <= sampleNo) && (sampleNo < m_noSamples));
324 }
325
326 inline
327 DataAbstract::ValueType::value_type*
328 DataAbstract::getSampleData(ValueType::size_type sampleNo)
329 {
330 return &(m_pointDataView->getData(getPointOffset(sampleNo,0)));
331 }
332
333 inline
334 int
335 DataAbstract::getNumDPPSample() const
336 {
337 return m_noDataPointsPerSample;
338 }
339
340 inline
341 int
342 DataAbstract::getNumSamples() const
343 {
344 return m_noSamples;
345 }
346
347 inline
348 const
349 FunctionSpace&
350 DataAbstract::getFunctionSpace() const
351 {
352 return m_functionSpace;
353 }
354
355 inline
356 const
357 DataArrayView&
358 DataAbstract::getPointDataView() const
359 {
360 return *(m_pointDataView.get());
361 }
362
363 inline
364 DataArrayView&
365 DataAbstract::getPointDataView()
366 {
367 return *(m_pointDataView.get());
368 }
369
370 } // end of namespace
371
372 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26