/[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 82 - (show annotations)
Tue Oct 26 06:53:54 2004 UTC (15 years, 1 month ago) by jgs
File MIME type: text/plain
File size: 7292 byte(s)
Initial revision

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26