/[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 110 - (show annotations)
Mon Feb 14 04:14:42 2005 UTC (14 years, 9 months ago) by jgs
File MIME type: text/plain
File size: 8270 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 interface for the class of containers
34 which hold ESyS data.
35
36 Description:
37 DataAbstract provides an 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. The data points themselves are arrays of rank 0-4.
40 */
41
42 class DataAbstract {
43
44 public:
45
46 typedef DataArrayView::ValueType ValueType;
47 typedef DataArrayView::ShapeType ShapeType;
48
49 /**
50 \brief
51 Constructor for DataAbstract.
52
53 Description:
54 Constructor for DataAbstract.
55 \param what - Input - A description of what this data represents.
56 */
57 DataAbstract(const FunctionSpace& what);
58
59 /**
60 \brief
61 Destructor for DataAbstract.
62 */
63 virtual
64 ~DataAbstract();
65
66 /**
67 \brief
68 Write the data as a string.
69 */
70 virtual
71 std::string
72 toString() const = 0;
73
74 /**
75 \brief
76 Return the number of data points per sample.
77 */
78 int
79 getNumDPPSample() const;
80
81 /**
82 \brief
83 Return the number of samples.
84 */
85 int
86 getNumSamples() const;
87
88 /**
89 \brief
90 Return the DataArrayView of the point data. This essentially contains
91 the shape information for each data point although it also may be used
92 to manipulate the point data.
93 */
94 const DataArrayView&
95 getPointDataView() const;
96
97 DataArrayView&
98 getPointDataView();
99
100 /**
101 \brief
102 Return the offset for the given sample. This is somewhat artificial notion
103 but returns the offset for the given point into the container
104 holding the point data. Only really necessary to avoid many DataArrayView
105 objects.
106 \param sampleNo - Input - sample number.
107 \param dataPointNo - Input - Input.
108 */
109 virtual
110 ValueType::size_type
111 getPointOffset(int sampleNo,
112 int dataPointNo) const = 0;
113
114 /**
115 \brief
116 Return the sample data for the given sample no.
117 */
118 double*
119 getSampleData(ValueType::size_type sampleNo);
120
121 /**
122 \brief
123 Return the number of doubles stored for the Data.
124 */
125 virtual
126 ValueType::size_type
127 getLength() const = 0;
128
129 /**
130 \brief
131 Return the sample data for the given tag key.
132 NB: If the data isn't tagged an exception will be thrown.
133 */
134 virtual
135 double*
136 getSampleDataByTag(int tag);
137
138 /**
139 \brief
140 Assign the given value to the data-points(s) referenced by the given
141 reference number.
142
143 If this Data object cannot be accessed by reference numbers an
144 exception will be thrown.
145
146 \param ref - Input - reference number.
147 \param value - Input - value to assign to data-points associated with
148 the given reference number.
149 */
150 virtual
151 void
152 setRefValue(int ref,
153 const DataArray& value);
154
155 /**
156 \brief
157 Return the values associated with the data-point(s) referenced by the given
158 reference number.
159
160 If this Data object cannot be accessed by reference numbers an
161 exception will be thrown.
162
163 \param ref - Input - reference number.
164 \param value - Output - object to receive data-points associated with
165 the given reference number.
166 */
167 virtual
168 void
169 getRefValue(int ref,
170 DataArray& value);
171
172 /**
173 \brief
174 Check this and the right operands are compatible. Throws
175 an exception if they aren't.
176 \param right - Input - The right hand side.
177 */
178 void
179 operandCheck(const DataAbstract& right) const;
180
181 /**
182 \brief
183 Return true if a valid sample point number.
184 */
185 bool
186 validSamplePointNo(int samplePointNo) const;
187
188 /**
189 \brief
190 Return true if a valid number.
191 */
192 bool
193 validSampleNo(int sampleNo) const;
194
195 /**
196 \brief
197 Return a view into the data for the data point specified.
198 NOTE: Construction of the DataArrayView is a relatively expensive
199 operation.
200 \param samplesNo Input
201 \param dataPointNo Input
202 */
203 virtual
204 DataArrayView
205 getDataPoint(int samplesNo,
206 int dataPointNo) = 0;
207
208 /**
209 \brief
210 Return the function space.
211 */
212 const FunctionSpace&
213 getFunctionSpace() const;
214
215 /**
216 \brief
217 Return a newly constructed DataAbstract. The caller is responsible for
218 managing the object created.
219 */
220 virtual
221 DataAbstract*
222 getSlice(const DataArrayView::RegionType& region) const = 0;
223
224 /**
225 \brief
226 Copy the specified region from the given value.
227 \param value - Input - Data to copy from
228 \param region - Input - Region to copy.
229 */
230 virtual
231 void
232 setSlice(const DataAbstract* value,
233 const DataArrayView::RegionType& region) = 0;
234
235 /**
236 \brief
237 Reshape the data point if the data point is currently rank 0.
238 Will throw an exception if the data points are not rank 0.
239 The original data point value is used for all values of the new
240 data point.
241 */
242 virtual
243 void
244 reshapeDataPoint(const DataArrayView::ShapeType& shape) = 0;
245
246 /**
247 \brief
248 setTaggedValue
249
250 Description:
251 Assign the given value to the given tag.
252 \param tagKey - Input - Integer key.
253 \param value - Input - Single DataArrayView value to be assigned to the tag.
254 NB: If the data isn't tagged an exception will be thrown.
255 */
256 virtual
257 void
258 setTaggedValue(int tagKey,
259 const DataArrayView& value);
260
261 protected:
262
263 /**
264 \brief
265 Set the pointDataView
266 \param right - Input - The point data view. DataAbstract takes ownership
267 of the DataArrayView provided. It will delete it when it is destructed.
268 */
269 void
270 setPointDataView(const DataArrayView& input);
271
272 private:
273
274 int m_noDataPointsPerSample;
275
276 int m_noSamples;
277
278 //
279 // Provides a view of the data as point data
280 boost::scoped_ptr<DataArrayView> m_pointDataView;
281
282 //
283 // function space
284 FunctionSpace m_functionSpace;
285
286 };
287
288 inline
289 bool
290 DataAbstract::validSamplePointNo(int samplePointNo) const
291 {
292 return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
293 }
294
295 inline
296 bool
297 DataAbstract::validSampleNo(int sampleNo) const
298 {
299 return ((0 <= sampleNo) && (sampleNo < m_noSamples));
300 }
301
302 inline
303 DataAbstract::ValueType::value_type*
304 DataAbstract::getSampleData(ValueType::size_type sampleNo)
305 {
306 return &(m_pointDataView->getData(getPointOffset(sampleNo,0)));
307 }
308
309 inline
310 int
311 DataAbstract::getNumDPPSample() const
312 {
313 return m_noDataPointsPerSample;
314 }
315
316 inline
317 int
318 DataAbstract::getNumSamples() const
319 {
320 return m_noSamples;
321 }
322
323 inline
324 const
325 FunctionSpace&
326 DataAbstract::getFunctionSpace() const
327 {
328 return m_functionSpace;
329 }
330
331 inline
332 const
333 DataArrayView&
334 DataAbstract::getPointDataView() const
335 {
336 return *(m_pointDataView.get());
337 }
338
339 inline
340 DataArrayView&
341 DataAbstract::getPointDataView()
342 {
343 return *(m_pointDataView.get());
344 }
345
346 } // end of namespace
347 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26