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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 854 - (show annotations)
Thu Sep 21 05:29:42 2006 UTC (13 years, 2 months ago) by gross
File MIME type: text/plain
File size: 11867 byte(s)
Some modifications to the binary operations +,-,*/, pow. 
The code is a bit simpler now and more efficient has there is
no reseising required now. the resizing method has been removed as
it is very, very inefficient. Even serial code should be faster now.
It is now forbidden to do an inplace update of scalar data object with an object 
of rank >0 as this is very slow (and does not make much sense). 


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 #include "system_dep.h"
18
19 #include "DataArrayView.h"
20 #include "DataArray.h"
21 #include "FunctionSpace.h"
22
23 #include <boost/scoped_ptr.hpp>
24 #include <boost/python/numeric.hpp>
25
26 #include <string>
27 #include <fstream>
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 ESCRIPT_DLL_API
62 DataAbstract(const FunctionSpace& what);
63
64 /**
65 \brief
66 Destructor for DataAbstract.
67 */
68 ESCRIPT_DLL_API
69 virtual
70 ~DataAbstract();
71
72 /**
73 \brief
74 Write the data as a string.
75 */
76 ESCRIPT_DLL_API
77 virtual
78 std::string
79 toString() const = 0;
80
81 /**
82 \brief
83 Return the number of data points per sample.
84 */
85 ESCRIPT_DLL_API
86 int
87 getNumDPPSample() const;
88
89 /**
90 \brief
91 Return the number of samples.
92 */
93 ESCRIPT_DLL_API
94 int
95 getNumSamples() const;
96
97 /**
98 \brief
99 Return the DataArrayView of the point data. This essentially contains
100 the shape information for each data point although it also may be used
101 to manipulate the point data.
102 */
103 ESCRIPT_DLL_API
104 DataArrayView&
105 getPointDataView();
106
107 ESCRIPT_DLL_API
108 const DataArrayView&
109 getPointDataView() const;
110
111 /**
112 \brief
113 Return the offset for the given sample. This returns the offset for the given
114 point into the container holding the point data. Only really necessary to
115 avoid creating many DataArrayView objects.
116
117 \param sampleNo - Input - sample number.
118 \param dataPointNo - Input - data point number.
119 */
120 ESCRIPT_DLL_API
121 virtual
122 ValueType::size_type
123 getPointOffset(int sampleNo,
124 int dataPointNo) const = 0;
125
126 /**
127 \brief
128 Return the sample data for the given sample number.
129 */
130 ESCRIPT_DLL_API
131 double*
132 getSampleData(ValueType::size_type sampleNo);
133
134 /**
135 \brief
136 Return the number of doubles stored for this Data object.
137 */
138 ESCRIPT_DLL_API
139 virtual
140 ValueType::size_type
141 getLength() const = 0;
142
143 /**
144 \brief
145 Return the sample data for the given tag key.
146 NB: If the data isn't tagged an exception will be thrown.
147 */
148 ESCRIPT_DLL_API
149 virtual
150 double*
151 getSampleDataByTag(int tag);
152
153 /**
154 \brief
155 Assign the given value to the data-points(s) referenced by the given
156 reference number.
157
158 If this Data object cannot be accessed by reference numbers an
159 exception will be thrown.
160
161 \param ref - Input - reference number.
162 \param value - Input - value to assign to data-points associated with
163 the given reference number.
164 */
165 ESCRIPT_DLL_API
166 virtual
167 void
168 setRefValue(int ref,
169 const DataArray& value);
170
171 /**
172 \brief
173 Return the values associated with the data-point(s) referenced by the given
174 reference number.
175
176 If this Data object cannot be accessed by reference numbers an
177 exception will be thrown.
178
179 \param ref - Input - reference number.
180 \param value - Output - object to receive data-points associated with
181 the given reference number.
182 */
183 ESCRIPT_DLL_API
184 virtual
185 void
186 getRefValue(int ref,
187 DataArray& value);
188
189 /**
190 \brief
191 Check this and the given RHS operands are compatible. Throws
192 an exception if they aren't.
193
194 \param right - Input - The right hand side.
195 */
196 ESCRIPT_DLL_API
197 void
198 operandCheck(const DataAbstract& right) const;
199
200 /**
201 \brief
202 Return true if a valid sample point number.
203 */
204 ESCRIPT_DLL_API
205 bool
206 validSamplePointNo(int samplePointNo) const;
207
208 /**
209 \brief
210 Return true if a valid sample number.
211 */
212 ESCRIPT_DLL_API
213 bool
214 validSampleNo(int sampleNo) const;
215
216 /**
217 \brief
218 Return a view into the data for the data point specified.
219 NOTE: Construction of the DataArrayView is a relatively expensive
220 operation.
221
222 \param sampleNo - Input - the sample number.
223 \param dataPointNo - Input - the data point number.
224 */
225 ESCRIPT_DLL_API
226 virtual
227 DataArrayView
228 getDataPoint(int sampleNo,
229 int dataPointNo) = 0;
230
231 /**
232 \brief
233 Return the function space associated with this Data object.
234 */
235 ESCRIPT_DLL_API
236 const
237 FunctionSpace&
238 getFunctionSpace() const;
239
240 /**
241 \brief
242 Return the given slice from this object.
243
244 NB: The caller is responsible for managing the object created.
245 */
246 ESCRIPT_DLL_API
247 virtual
248 DataAbstract*
249 getSlice(const DataArrayView::RegionType& region) const = 0;
250
251 /**
252 \brief
253 Copy the specified region from the given object.
254
255 \param value - Input - Data to copy from
256 \param region - Input - Region to copy.
257 */
258 ESCRIPT_DLL_API
259 virtual
260 void
261 setSlice(const DataAbstract* value,
262 const DataArrayView::RegionType& region) = 0;
263
264
265 /**
266 \brief
267 setTaggedValue
268
269 Description:
270 Assign the given value to the given tag.
271
272 NB: If the data isn't tagged an exception will be thrown.
273
274 \param tagKey - Input - Integer key.
275 \param value - Input - Single DataArrayView value to be assigned to the tag.
276 */
277 ESCRIPT_DLL_API
278 virtual
279 void
280 setTaggedValue(int tagKey,
281 const DataArrayView& value);
282
283 /**
284 \brief
285 Archive the underlying data values to the file referenced
286 by ofstream. A count of the number of values expected to be written
287 is provided as a cross-check.
288
289 The return value indicates success (0) or otherwise (1).
290 */
291 ESCRIPT_DLL_API
292 virtual
293 int
294 archiveData(std::ofstream& archiveFile,
295 const ValueType::size_type noValues) const;
296
297 /**
298 \brief
299 Extract the number of values specified by noValues from the file
300 referenced by ifstream to the underlying data structure.
301
302 The return value indicates success (0) or otherwise (1).
303 */
304 ESCRIPT_DLL_API
305 virtual
306 int
307 extractData(std::ifstream& archiveFile,
308 const ValueType::size_type noValues);
309
310 /**
311 \brief
312 Copy the numarray object to the data points in this object.
313
314 Description:
315 Copy the numarray object to the data points in this object.
316
317 \param value Input - new values for the data points
318 */
319 ESCRIPT_DLL_API
320 virtual void
321 copyAll(const boost::python::numeric::array& value);
322
323 /**
324 \brief
325 Return the tag number associated with the given data-point number.
326
327 If the object cannot be referenced by tag numbers, an exception
328 will be thrown.
329 */
330 ESCRIPT_DLL_API
331 virtual
332 int
333 getTagNumber(int dpno);
334
335 /**
336 \brief
337 Computes a symmetric matrix (A + AT) / 2
338
339 \param ev - Output - a symmetric matrix
340
341 */
342 ESCRIPT_DLL_API
343 virtual void
344 symmetric(DataAbstract* ev);
345
346 /**
347 \brief
348 Computes a nonsymmetric matrix (A - AT) / 2
349
350 \param ev - Output - a nonsymmetric matrix
351
352 */
353 ESCRIPT_DLL_API
354 virtual void
355 nonsymmetric(DataAbstract* ev);
356
357 /**
358 \brief
359 Computes the trace of a matrix
360
361 \param ev - Output - the trace of a matrix
362
363 */
364 ESCRIPT_DLL_API
365 virtual void
366 trace(DataAbstract* ev, int axis_offset);
367
368 /**
369 \brief
370 Transpose each data point of this Data object around the given axis.
371
372 \param ev - Output - the transpose of a matrix
373
374 */
375 ESCRIPT_DLL_API
376 virtual void
377 transpose(DataAbstract* ev, int axis_offset);
378
379 /**
380 \brief
381 swaps components axis0 and axis1
382
383 \param ev - Output - swapped components
384
385 */
386 ESCRIPT_DLL_API
387 virtual void
388 swapaxes(DataAbstract* ev, int axis0, int axis1);
389 /**
390 \brief
391 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
392
393 \param ev - Output - eigenvalues in increasing order at each data point
394
395 */
396 ESCRIPT_DLL_API
397 virtual void
398 eigenvalues(DataAbstract* ev);
399
400 /**
401 \brief
402 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
403
404 \param ev - Output - eigenvalues in increasing order at each data point
405 \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
406 and the first nonzero component is positive.
407 \param tol - Input - eigenvalue with relative distance tol are treated as equal.
408
409 */
410
411 ESCRIPT_DLL_API
412 virtual void
413 eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
414
415 protected:
416
417 /**
418 \brief
419 Set the pointDataView DataArrayView associated with this object.
420
421 \param input - Input - The point data view. DataAbstract takes ownership
422 of the DataArrayView provided. It will delete it when it is destructed.
423 */
424 ESCRIPT_DLL_API
425 void
426 setPointDataView(const DataArrayView& input);
427
428 ESCRIPT_DLL_API
429 void
430 resetPointDataView();
431
432 private:
433
434 //
435 // The number of samples in this Data object.
436 // This is derived directly from the FunctionSpace.
437 int m_noSamples;
438
439 //
440 // The number of data points per sample in this Data object.
441 // This is derived directly from the FunctionSpace.
442 int m_noDataPointsPerSample;
443
444 //
445 // The DataArrayView of the data array associated with this object.
446 // The data array is defined only in child classes of this class, it
447 // is not defined in this abstract parent class.
448 boost::scoped_ptr<DataArrayView> m_pointDataView;
449
450 //
451 // A FunctionSpace which provides a description of the data associated
452 // with this Data object.
453 FunctionSpace m_functionSpace;
454
455 };
456
457 inline
458 bool
459 DataAbstract::validSamplePointNo(int samplePointNo) const
460 {
461 return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
462 }
463
464 inline
465 bool
466 DataAbstract::validSampleNo(int sampleNo) const
467 {
468 return ((0 <= sampleNo) && (sampleNo < m_noSamples));
469 }
470
471 inline
472 DataAbstract::ValueType::value_type*
473 DataAbstract::getSampleData(ValueType::size_type sampleNo)
474 {
475 return &(m_pointDataView->getData(getPointOffset(sampleNo,0)));
476 }
477
478 inline
479 int
480 DataAbstract::getNumDPPSample() const
481 {
482 return m_noDataPointsPerSample;
483 }
484
485 inline
486 int
487 DataAbstract::getNumSamples() const
488 {
489 return m_noSamples;
490 }
491
492 inline
493 const
494 FunctionSpace&
495 DataAbstract::getFunctionSpace() const
496 {
497 return m_functionSpace;
498 }
499
500 inline
501 const
502 DataArrayView&
503 DataAbstract::getPointDataView() const
504 {
505 return *(m_pointDataView.get());
506 }
507
508 inline
509 DataArrayView&
510 DataAbstract::getPointDataView()
511 {
512 return *(m_pointDataView.get());
513 }
514 } // end of namespace
515
516 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26