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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1897 - (show annotations)
Mon Oct 20 00:32:30 2008 UTC (11 years ago) by jfenwick
File MIME type: text/plain
File size: 13197 byte(s)
Modified Data::toString() so it doesn't throw on DataEmpty.
Added setEscriptParamInt and getEscriptParamInt as free functions.
At the moment all they do is allow you to set the param TOO_MANY_LINES.
This is used to determine when printing a Data object will show you the 
points and when it will print a summary.

I've set the default value back to 80 lines.
If you need to see more lines use (in python):

setEscriptParamInt("TOO_MANY_LINES",80000)


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26