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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1796 - (show annotations)
Wed Sep 17 01:45:46 2008 UTC (11 years, 1 month ago) by jfenwick
File MIME type: text/plain
File size: 14078 byte(s)
Merged noarrayview branch onto trunk.


1 /* $Id$ */
2
3 /*******************************************************
4 *
5 * Copyright 2003-2007 by ACceSS MNRF
6 * Copyright 2007 by University of Queensland
7 *
8 * http://esscc.uq.edu.au
9 * Primary Business: Queensland, Australia
10 * Licensed under the Open Software License version 3.0
11 * http://www.opensource.org/licenses/osl-3.0.php
12 *
13 *******************************************************/
14
15 #if !defined escript_DataAbstract_20040315_H
16 #define escript_DataAbstract_20040315_H
17 #include "system_dep.h"
18
19 #include "DataTypes.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 DataTypes::ValueType ValueType;
49 typedef DataTypes::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 ESCRIPT_DLL_API
61 DataAbstract(const FunctionSpace& what, const ShapeType& shape);
62
63 /**
64 \brief
65 Destructor for DataAbstract.
66 */
67 ESCRIPT_DLL_API
68 virtual
69 ~DataAbstract();
70
71 /**
72 \brief
73 Write the data as a string.
74 */
75 ESCRIPT_DLL_API
76 virtual
77 std::string
78 toString() const = 0;
79
80 /**
81 \brief
82 dumps the object into a netCDF file
83 */
84 ESCRIPT_DLL_API
85 virtual
86 void
87 dump(const std::string fileName) const;
88
89 /**
90 \brief
91 Return the number of data points per sample.
92 */
93 ESCRIPT_DLL_API
94 int
95 getNumDPPSample() const;
96
97 /**
98 \brief
99 Return the number of samples.
100 */
101 ESCRIPT_DLL_API
102 int
103 getNumSamples() const;
104
105 // /**
106 // \brief
107 // Return the DataArrayView of the point data. This essentially contains
108 // the shape information for each data point although it also may be used
109 // to manipulate the point data.
110 // */
111 // ESCRIPT_DLL_API
112 // DataArrayView&
113 // getPointDataView();
114
115 // ESCRIPT_DLL_API
116 // const DataArrayView&
117 // getPointDataView() const;
118
119 /**
120 \brief
121 Return the shape information for the point data.
122
123 The omission of a non-constant form is deliberate.
124 */
125 ESCRIPT_DLL_API
126 const DataTypes::ShapeType&
127 getShape() const;
128
129 /**
130 \brief
131 Return the rank information for the point data.
132 */
133 ESCRIPT_DLL_API
134 int
135 getRank() const;
136
137
138
139 /**
140 \brief
141 Return the offset for the given sample. This returns the offset for the given
142 point into the container holding the point data. Only really necessary to
143 avoid creating many DataArrayView objects.
144
145 \param sampleNo - Input - sample number.
146 \param dataPointNo - Input - data point number.
147 */
148 ESCRIPT_DLL_API
149 virtual
150 ValueType::size_type
151 getPointOffset(int sampleNo,
152 int dataPointNo) const = 0;
153
154 // /**
155 // return the container storing points for this object
156 // */
157 // ESCRIPT_DLL_API
158 // virtual
159 // ValueType&
160 // getVector();
161 //
162 // ESCRIPT_DLL_API
163 // virtual
164 // const ValueType&
165 // getVector() const;
166
167
168 /**
169 \brief
170 Return the sample data for the given sample number.
171 */
172 ESCRIPT_DLL_API
173 double*
174 getSampleData(ValueType::size_type sampleNo);
175
176 /**
177 \brief
178 Return the number of doubles stored for this Data object.
179 */
180 ESCRIPT_DLL_API
181 virtual
182 ValueType::size_type
183 getLength() const = 0;
184
185 /**
186 \brief
187 Return the sample data for the given tag key.
188 NB: If the data isn't tagged an exception will be thrown.
189 */
190 ESCRIPT_DLL_API
191 virtual
192 double*
193 getSampleDataByTag(int tag);
194
195
196 /**
197 \brief
198 Check this and the given RHS operands are compatible. Throws
199 an exception if they aren't.
200
201 \param right - Input - The right hand side.
202 */
203 ESCRIPT_DLL_API
204 void
205 operandCheck(const DataAbstract& right) const;
206
207 /**
208 \brief
209 Return true if a valid sample point number.
210 */
211 ESCRIPT_DLL_API
212 bool
213 validSamplePointNo(int samplePointNo) const;
214
215 /**
216 \brief
217 Return true if a valid sample number.
218 */
219 ESCRIPT_DLL_API
220 bool
221 validSampleNo(int sampleNo) const;
222
223 // /**
224 // \brief
225 // Return a view into the data for the data point specified.
226 // NOTE: Construction of the DataArrayView is a relatively expensive
227 // operation.
228 //
229 // \param sampleNo - Input - the sample number.
230 // \param dataPointNo - Input - the data point number.
231 // */
232 // ESCRIPT_DLL_API
233 // virtual
234 // DataArrayView
235 // getDataPoint(int sampleNo,
236 // int dataPointNo) = 0;
237
238 /**
239 \brief
240 Return the function space associated with this Data object.
241 */
242 ESCRIPT_DLL_API
243 const
244 FunctionSpace&
245 getFunctionSpace() const;
246
247 /**
248 \brief
249 Return the given slice from this object.
250
251 NB: The caller is responsible for managing the object created.
252 */
253 ESCRIPT_DLL_API
254 virtual
255 DataAbstract*
256 getSlice(const DataTypes::RegionType& region) const = 0;
257
258 /**
259 \brief
260 Copy the specified region from the given object.
261
262 \param value - Input - Data to copy from
263 \param region - Input - Region to copy.
264 */
265 ESCRIPT_DLL_API
266 virtual
267 void
268 setSlice(const DataAbstract* value,
269 const DataTypes::RegionType& region) = 0;
270
271
272 // /**
273 // \brief
274 // setTaggedValue
275 //
276 // Description:
277 // Assign the given value to the given tag.
278 //
279 // NB: If the data isn't tagged an exception will be thrown.
280 //
281 // \param tagKey - Input - Integer key.
282 // \param value - Input - Single DataArrayView value to be assigned to the tag.
283 // */
284 // ESCRIPT_DLL_API
285 // virtual
286 // void
287 // setTaggedValue(int tagKey,
288 // const DataArrayView& value);
289
290
291 /**
292 \brief
293 setTaggedValue
294
295 Description:
296 Assign the given value to the given tag.
297
298 NB: If the data isn't tagged an exception will be thrown.
299
300 \param tagKey - Input - Integer key.
301 \param pointshape - Input - the shape of the value parameter.
302 \param value - Input -
303 */
304 ESCRIPT_DLL_API
305 virtual
306 void
307 setTaggedValue(int tagKey,
308 const DataTypes::ShapeType& pointshape,
309 const DataTypes::ValueType& value,
310 int dataOffset=0);
311
312
313
314
315 /**
316 \brief
317 Copy the numarray object to the data points in this object.
318
319 Description:
320 Copy the numarray object to the data points in this object.
321
322 \param value Input - new values for the data points
323 */
324 ESCRIPT_DLL_API
325 virtual void
326 copyAll(const boost::python::numeric::array& value);
327
328 /**
329 \brief
330 Copy a double value to the data point dataPointNo of sample sampleNo in this object.
331
332 Description:
333 Copy a double value to the data point dataPointNo of sample sampleNo in this object.
334
335 \param sampleNo Input - sample number
336 \param dataPointNo Input - data point of the sample
337 \param value Input - new values for the data point
338 */
339 ESCRIPT_DLL_API
340 virtual void
341 copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
342
343 /**
344 \brief
345 Copy the numarray object to the data point dataPointNo of sample sampleNo in this object.
346
347 Description:
348 Copy the numarray object to the data point dataPointNo of sample sampleNo in this object.
349
350 \param sampleNo Input - sample number
351 \param dataPointNo Input - data point of the sample
352 \param value Input - new values for the data point
353 */
354 ESCRIPT_DLL_API
355 virtual void
356 copyToDataPoint(const int sampleNo, const int dataPointNo, const boost::python::numeric::array& value);
357
358
359 /**
360 \brief
361 Return the tag number associated with the given data-point number.
362
363 If the object cannot be referenced by tag numbers, an exception
364 will be thrown.
365 */
366 ESCRIPT_DLL_API
367 virtual
368 int
369 getTagNumber(int dpno);
370
371 /**
372 \brief
373 Computes a symmetric matrix (A + AT) / 2
374
375 \param ev - Output - a symmetric matrix
376
377 */
378 ESCRIPT_DLL_API
379 virtual void
380 symmetric(DataAbstract* ev);
381
382 /**
383 \brief
384 Computes a nonsymmetric matrix (A - AT) / 2
385
386 \param ev - Output - a nonsymmetric matrix
387
388 */
389 ESCRIPT_DLL_API
390 virtual void
391 nonsymmetric(DataAbstract* ev);
392
393 /**
394 \brief
395 Computes the trace of a matrix
396
397 \param ev - Output - the trace of a matrix
398
399 */
400 ESCRIPT_DLL_API
401 virtual void
402 trace(DataAbstract* ev, int axis_offset);
403
404 /**
405 \brief
406 Transpose each data point of this Data object around the given axis.
407
408 \param ev - Output - the transpose of a matrix
409
410 */
411 ESCRIPT_DLL_API
412 virtual void
413 transpose(DataAbstract* ev, int axis_offset);
414
415 /**
416 \brief
417 swaps components axis0 and axis1
418
419 \param ev - Output - swapped components
420
421 */
422 ESCRIPT_DLL_API
423 virtual void
424 swapaxes(DataAbstract* ev, int axis0, int axis1);
425 /**
426 \brief
427 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
428
429 \param ev - Output - eigenvalues in increasing order at each data point
430
431 */
432 ESCRIPT_DLL_API
433 virtual void
434 eigenvalues(DataAbstract* ev);
435
436 /**
437 \brief
438 sets values to zero
439
440 */
441 ESCRIPT_DLL_API
442 virtual void
443 setToZero();
444
445 /**
446 \brief
447 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
448
449 \param ev - Output - eigenvalues in increasing order at each data point
450 \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
451 and the first nonzero component is positive.
452 \param tol - Input - eigenvalue with relative distance tol are treated as equal.
453
454 */
455
456 ESCRIPT_DLL_API
457 virtual void
458 eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
459
460 /**
461 \brief
462 reorders data sample ordered by reference_ids to the ordering of the functions space
463
464 \param reference_ids - Input - reference_ids used for current ordering
465 */
466 ESCRIPT_DLL_API
467 virtual void
468 reorderByReferenceIDs(int *reference_ids);
469
470
471
472 /**
473 \brief
474 Return the number of values in the shape for this object.
475 */
476 ESCRIPT_DLL_API
477 int
478 getNoValues() const;
479
480
481
482 /**
483 \brief get a reference to the beginning of a data point
484 */
485 ESCRIPT_DLL_API
486 DataTypes::ValueType::const_reference
487 getDataAtOffset(DataTypes::ValueType::size_type i) const;
488
489
490 ESCRIPT_DLL_API
491 DataTypes::ValueType::reference
492 getDataAtOffset(DataTypes::ValueType::size_type i);
493
494
495 /**
496 \brief Provide access to underlying storage. Internal use only!
497 */
498 ESCRIPT_DLL_API
499 virtual DataTypes::ValueType&
500 getVector()=0;
501
502 ESCRIPT_DLL_API
503 virtual const DataTypes::ValueType&
504 getVector() const=0;
505
506 protected:
507
508 // /**
509 // \brief
510 // Set the pointDataView DataArrayView associated with this object.
511 //
512 // \param input - Input - The point data view. DataAbstract takes ownership
513 // of the DataArrayView provided. It will delete it when it is destructed.
514 // */
515 // ESCRIPT_DLL_API
516 // void
517 // setPointDataView(const DataArrayView& input);
518 //
519 // ESCRIPT_DLL_API
520 // void
521 // resetPointDataView();
522
523
524
525
526
527
528 private:
529
530 //
531 // The number of samples in this Data object.
532 // This is derived directly from the FunctionSpace.
533 int m_noSamples;
534
535 //
536 // The number of data points per sample in this Data object.
537 // This is derived directly from the FunctionSpace.
538 int m_noDataPointsPerSample;
539
540 //
541 // The DataArrayView of the data array associated with this object.
542 // The data array is defined only in child classes of this class, it
543 // is not defined in this abstract parent class.
544 // boost::scoped_ptr<DataArrayView> m_pointDataView;
545
546 //
547 // A FunctionSpace which provides a description of the data associated
548 // with this Data object.
549 FunctionSpace m_functionSpace;
550
551 //
552 // The shape of the points stored in this view
553 DataTypes::ShapeType m_shape;
554
555 //
556 // The number of values in each point
557 int m_novalues;
558
559 //
560 // The rank of the points stored in this view
561 int m_rank;
562
563 };
564
565
566 inline
567 DataTypes::ValueType::const_reference
568 DataAbstract::getDataAtOffset(DataTypes::ValueType::size_type i) const
569 {
570 return getVector()[i];
571 }
572
573 inline
574 DataTypes::ValueType::reference
575 DataAbstract::getDataAtOffset(DataTypes::ValueType::size_type i)
576 {
577 return getVector()[i];
578 }
579
580
581 inline
582 bool
583 DataAbstract::validSamplePointNo(int samplePointNo) const
584 {
585 return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
586 }
587
588 inline
589 bool
590 DataAbstract::validSampleNo(int sampleNo) const
591 {
592 return ((0 <= sampleNo) && (sampleNo < m_noSamples));
593 }
594
595 inline
596 DataAbstract::ValueType::value_type*
597 DataAbstract::getSampleData(ValueType::size_type sampleNo)
598 {
599 // return &(m_pointDataView->getData(getPointOffset(sampleNo,0)));
600 return &(getVector()[getPointOffset(sampleNo,0)]);
601 }
602
603 inline
604 int
605 DataAbstract::getNumDPPSample() const
606 {
607 return m_noDataPointsPerSample;
608 }
609
610 inline
611 int
612 DataAbstract::getNumSamples() const
613 {
614 return m_noSamples;
615 }
616
617 inline
618 const
619 FunctionSpace&
620 DataAbstract::getFunctionSpace() const
621 {
622 return m_functionSpace;
623 }
624
625 // inline
626 // const
627 // DataArrayView&
628 // DataAbstract::getPointDataView() const
629 // {
630 // return *(m_pointDataView.get());
631 // }
632
633 // inline
634 // DataArrayView&
635 // DataAbstract::getPointDataView()
636 // {
637 // return *(m_pointDataView.get());
638 // }
639
640 inline
641 const DataTypes::ShapeType&
642 DataAbstract::getShape() const
643 {
644 return m_shape;
645 }
646
647 inline
648 int
649 DataAbstract::getRank() const
650 {
651 return m_rank;
652 }
653
654 inline
655 int
656 DataAbstract::getNoValues() const
657 {
658 return m_novalues;
659 }
660
661 } // end of namespace
662
663 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26