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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 615 - (show annotations)
Wed Mar 22 02:12:00 2006 UTC (13 years, 6 months ago) by elspeth
File MIME type: text/plain
File size: 10634 byte(s)
More copyright information.

1 // $Id$
2 /*
3 ************************************************************
4 * Copyright 2006 by ACcESS MNRF *
5 * *
6 * http://www.access.edu.au *
7 * Primary Business: Queensland, Australia *
8 * Licensed under the Open Software License version 3.0 *
9 * http://www.opensource.org/licenses/osl-3.0.php *
10 * *
11 ************************************************************
12
13 */
14
15 #if !defined escript_DataAbstract_20040315_H
16 #define escript_DataAbstract_20040315_H
17
18 #include "DataArrayView.h"
19 #include "DataArray.h"
20 #include "FunctionSpace.h"
21
22 #include <boost/scoped_ptr.hpp>
23 #include <boost/python/numeric.hpp>
24
25 #include <string>
26 #include <fstream>
27
28 namespace escript {
29
30 /**
31 \brief
32 DataAbstract provides an abstract interface for the class of containers
33 which hold ESyS data.
34
35 Description:
36 DataAbstract provides an abstract 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 where one dimension corresponds to the number of samples
39 and the other to the number of data points per sample as defined by the function
40 space associated with each Data object. The data points themselves are arrays of
41 doubles of rank 0-4.
42 */
43
44 class DataAbstract {
45
46 public:
47
48 typedef DataArrayView::ValueType ValueType;
49 typedef DataArrayView::ShapeType ShapeType;
50
51 /**
52 \brief
53 Constructor for DataAbstract.
54
55 Description:
56 Constructor for DataAbstract.
57
58 \param what - Input - A description of what this data represents.
59 */
60 DataAbstract(const FunctionSpace& what);
61
62 /**
63 \brief
64 Destructor for DataAbstract.
65 */
66 virtual
67 ~DataAbstract();
68
69 /**
70 \brief
71 Write the data as a string.
72 */
73 virtual
74 std::string
75 toString() const = 0;
76
77 /**
78 \brief
79 Return the number of data points per sample.
80 */
81 int
82 getNumDPPSample() const;
83
84 /**
85 \brief
86 Return the number of samples.
87 */
88 int
89 getNumSamples() const;
90
91 /**
92 \brief
93 Return the DataArrayView of the point data. This essentially contains
94 the shape information for each data point although it also may be used
95 to manipulate the point data.
96 */
97 DataArrayView&
98 getPointDataView();
99
100 const DataArrayView&
101 getPointDataView() const;
102
103 /**
104 \brief
105 Return the offset for the given sample. This returns the offset for the given
106 point into the container holding the point data. Only really necessary to
107 avoid creating many DataArrayView objects.
108
109 \param sampleNo - Input - sample number.
110 \param dataPointNo - Input - data point number.
111 */
112 virtual
113 ValueType::size_type
114 getPointOffset(int sampleNo,
115 int dataPointNo) const = 0;
116
117 /**
118 \brief
119 Return the sample data for the given sample number.
120 */
121 double*
122 getSampleData(ValueType::size_type sampleNo);
123
124 /**
125 \brief
126 Return the number of doubles stored for this Data object.
127 */
128 virtual
129 ValueType::size_type
130 getLength() const = 0;
131
132 /**
133 \brief
134 Return the sample data for the given tag key.
135 NB: If the data isn't tagged an exception will be thrown.
136 */
137 virtual
138 double*
139 getSampleDataByTag(int tag);
140
141 /**
142 \brief
143 Assign the given value to the data-points(s) referenced by the given
144 reference number.
145
146 If this Data object cannot be accessed by reference numbers an
147 exception will be thrown.
148
149 \param ref - Input - reference number.
150 \param value - Input - value to assign to data-points associated with
151 the given reference number.
152 */
153 virtual
154 void
155 setRefValue(int ref,
156 const DataArray& value);
157
158 /**
159 \brief
160 Return the values associated with the data-point(s) referenced by the given
161 reference number.
162
163 If this Data object cannot be accessed by reference numbers an
164 exception will be thrown.
165
166 \param ref - Input - reference number.
167 \param value - Output - object to receive data-points associated with
168 the given reference number.
169 */
170 virtual
171 void
172 getRefValue(int ref,
173 DataArray& value);
174
175 /**
176 \brief
177 Check this and the given RHS operands are compatible. Throws
178 an exception if they aren't.
179
180 \param right - Input - The right hand side.
181 */
182 void
183 operandCheck(const DataAbstract& right) const;
184
185 /**
186 \brief
187 Return true if a valid sample point number.
188 */
189 bool
190 validSamplePointNo(int samplePointNo) const;
191
192 /**
193 \brief
194 Return true if a valid sample number.
195 */
196 bool
197 validSampleNo(int sampleNo) const;
198
199 /**
200 \brief
201 Return a view into the data for the data point specified.
202 NOTE: Construction of the DataArrayView is a relatively expensive
203 operation.
204
205 \param sampleNo - Input - the sample number.
206 \param dataPointNo - Input - the data point number.
207 */
208 virtual
209 DataArrayView
210 getDataPoint(int sampleNo,
211 int dataPointNo) = 0;
212
213 /**
214 \brief
215 Return the function space associated with this Data object.
216 */
217 const
218 FunctionSpace&
219 getFunctionSpace() const;
220
221 /**
222 \brief
223 Return the given slice from this object.
224
225 NB: The caller is responsible for managing the object created.
226 */
227 virtual
228 DataAbstract*
229 getSlice(const DataArrayView::RegionType& region) const = 0;
230
231 /**
232 \brief
233 Copy the specified region from the given object.
234
235 \param value - Input - Data to copy from
236 \param region - Input - Region to copy.
237 */
238 virtual
239 void
240 setSlice(const DataAbstract* value,
241 const DataArrayView::RegionType& region) = 0;
242
243 /**
244 \brief
245 Reshape the data points if they are currently rank 0.
246 Will throw an exception if the data points are not rank 0.
247 The original data point value is used for all values of the new
248 data point.
249 */
250 virtual
251 void
252 reshapeDataPoint(const ShapeType& shape) = 0;
253
254 /**
255 \brief
256 setTaggedValue
257
258 Description:
259 Assign the given value to the given tag.
260
261 NB: If the data isn't tagged an exception will be thrown.
262
263 \param tagKey - Input - Integer key.
264 \param value - Input - Single DataArrayView value to be assigned to the tag.
265 */
266 virtual
267 void
268 setTaggedValue(int tagKey,
269 const DataArrayView& value);
270
271 /**
272 \brief
273 Archive the underlying data values to the file referenced
274 by ofstream. A count of the number of values expected to be written
275 is provided as a cross-check.
276
277 The return value indicates success (0) or otherwise (1).
278 */
279 virtual
280 int
281 archiveData(std::ofstream& archiveFile,
282 const ValueType::size_type noValues) const;
283
284 /**
285 \brief
286 Extract the number of values specified by noValues from the file
287 referenced by ifstream to the underlying data structure.
288
289 The return value indicates success (0) or otherwise (1).
290 */
291 virtual
292 int
293 extractData(std::ifstream& archiveFile,
294 const ValueType::size_type noValues);
295
296 /**
297 \brief
298 Copy the numarray object to the data points in this object.
299
300 Description:
301 Copy the numarray object to the data points in this object.
302
303 \param value Input - new values for the data points
304 */
305 virtual void
306 copyAll(const boost::python::numeric::array& value);
307
308 /**
309 \brief
310 Return the tag number associated with the given data-point number.
311
312 If the object cannot be referenced by tag numbers, an exception
313 will be thrown.
314 */
315 virtual
316 int
317 getTagNumber(int dpno);
318
319 /**
320 \brief
321 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
322
323 \param ev - Output - eigenvalues in increasing order at each data point
324
325 */
326 virtual void
327 eigenvalues(DataAbstract* ev);
328
329 /**
330 \brief
331 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
332
333 \param ev - Output - eigenvalues in increasing order at each data point
334 \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
335 and the first nonzero component is positive.
336 \param tol - Input - eigenvalue with relative distance tol are treated as equal.
337
338 */
339
340 virtual void
341 eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
342
343 protected:
344
345 /**
346 \brief
347 Set the pointDataView DataArrayView associated with this object.
348
349 \param input - Input - The point data view. DataAbstract takes ownership
350 of the DataArrayView provided. It will delete it when it is destructed.
351 */
352 void
353 setPointDataView(const DataArrayView& input);
354
355 void
356 resetPointDataView();
357
358 private:
359
360 //
361 // The number of samples in this Data object.
362 // This is derived directly from the FunctionSpace.
363 int m_noSamples;
364
365 //
366 // The number of data points per sample in this Data object.
367 // This is derived directly from the FunctionSpace.
368 int m_noDataPointsPerSample;
369
370 //
371 // The DataArrayView of the data array associated with this object.
372 // The data array is defined only in child classes of this class, it
373 // is not defined in this abstract parent class.
374 boost::scoped_ptr<DataArrayView> m_pointDataView;
375
376 //
377 // A FunctionSpace which provides a description of the data associated
378 // with this Data object.
379 FunctionSpace m_functionSpace;
380
381 };
382
383 inline
384 bool
385 DataAbstract::validSamplePointNo(int samplePointNo) const
386 {
387 return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
388 }
389
390 inline
391 bool
392 DataAbstract::validSampleNo(int sampleNo) const
393 {
394 return ((0 <= sampleNo) && (sampleNo < m_noSamples));
395 }
396
397 inline
398 DataAbstract::ValueType::value_type*
399 DataAbstract::getSampleData(ValueType::size_type sampleNo)
400 {
401 return &(m_pointDataView->getData(getPointOffset(sampleNo,0)));
402 }
403
404 inline
405 int
406 DataAbstract::getNumDPPSample() const
407 {
408 return m_noDataPointsPerSample;
409 }
410
411 inline
412 int
413 DataAbstract::getNumSamples() const
414 {
415 return m_noSamples;
416 }
417
418 inline
419 const
420 FunctionSpace&
421 DataAbstract::getFunctionSpace() const
422 {
423 return m_functionSpace;
424 }
425
426 inline
427 const
428 DataArrayView&
429 DataAbstract::getPointDataView() const
430 {
431 return *(m_pointDataView.get());
432 }
433
434 inline
435 DataArrayView&
436 DataAbstract::getPointDataView()
437 {
438 return *(m_pointDataView.get());
439 }
440 } // end of namespace
441
442 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26