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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 117 - (show annotations)
Fri Apr 1 05:48:57 2005 UTC (14 years, 7 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/DataAbstract.h
File MIME type: text/plain
File size: 9062 byte(s)
*** empty log message ***

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 right - 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 private:
285
286 //
287 // The number of samples in this Data object.
288 // This is derived directly from the FunctionSpace.
289 int m_noSamples;
290
291 //
292 // The number of data points per sample in this Data object.
293 // This is derived directly from the FunctionSpace.
294 int m_noDataPointsPerSample;
295
296 //
297 // The DataArrayView of the data array associated with this object.
298 // The data array is defined only in child classes of this class, it
299 // is not defined in this abstract parent class.
300 boost::scoped_ptr<DataArrayView> m_pointDataView;
301
302 //
303 // A FunctionSpace which provides a description of the data associated
304 // with this Data object.
305 FunctionSpace m_functionSpace;
306
307 };
308
309 inline
310 bool
311 DataAbstract::validSamplePointNo(int samplePointNo) const
312 {
313 return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
314 }
315
316 inline
317 bool
318 DataAbstract::validSampleNo(int sampleNo) const
319 {
320 return ((0 <= sampleNo) && (sampleNo < m_noSamples));
321 }
322
323 inline
324 DataAbstract::ValueType::value_type*
325 DataAbstract::getSampleData(ValueType::size_type sampleNo)
326 {
327 return &(m_pointDataView->getData(getPointOffset(sampleNo,0)));
328 }
329
330 inline
331 int
332 DataAbstract::getNumDPPSample() const
333 {
334 return m_noDataPointsPerSample;
335 }
336
337 inline
338 int
339 DataAbstract::getNumSamples() const
340 {
341 return m_noSamples;
342 }
343
344 inline
345 const
346 FunctionSpace&
347 DataAbstract::getFunctionSpace() const
348 {
349 return m_functionSpace;
350 }
351
352 inline
353 const
354 DataArrayView&
355 DataAbstract::getPointDataView() const
356 {
357 return *(m_pointDataView.get());
358 }
359
360 inline
361 DataArrayView&
362 DataAbstract::getPointDataView()
363 {
364 return *(m_pointDataView.get());
365 }
366
367 } // end of namespace
368
369 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26