Escript  Revision_4320
DataAbstract.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
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 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15 
16 
17 #if !defined escript_DataAbstract_20040315_H
18 #define escript_DataAbstract_20040315_H
19 #include "system_dep.h"
20 
21 #include "DataTypes.h"
22 #include "FunctionSpace.h"
23 
24 #include <boost/scoped_ptr.hpp>
25 
26 #include "DataException.h"
27 
28 #include <string>
29 #include <fstream>
30 #include <vector>
31 
32 #include "Pointers.h"
33 
34 namespace escript {
35 
51 
54 
55 class DataReady;
56 
57 typedef POINTER_WRAPPER_CLASS(DataReady) DataReady_ptr;
58 typedef POINTER_WRAPPER_CLASS(const DataReady) const_DataReady_ptr;
59 
61 {
62 
63  public:
64 
67 
83  DataAbstract_ptr getPtr();
85  const_DataAbstract_ptr getPtr() const;
86 
87 
88 
98  DataAbstract(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty=false);
99 
105  virtual
106  ~DataAbstract();
107 
113  virtual
114  std::string
115  toString() const = 0;
116 
121  virtual
122  DataAbstract*
123  deepCopy()=0;
124 
129  virtual
130  DataReady_ptr
131  resolve()=0;
132 
138  virtual
139  void
140  dump(const std::string fileName) const;
141 
147  int
148  getNumDPPSample() const;
149 
155  int
156  getNumSamples() const;
157 
165  const DataTypes::ShapeType&
166  getShape() const;
167 
173  unsigned int
174  getRank() const;
175 
176 
177 
187  virtual
189  getPointOffset(int sampleNo,
190  int dataPointNo) const = 0;
191 
193  virtual
195  getPointOffset(int sampleNo,
196  int dataPointNo) = 0;
197 
198 
204  virtual
206  getLength() const = 0;
207 
214  virtual
215  double*
216  getSampleDataByTag(int tag);
217 
226  void
227  operandCheck(const DataAbstract& right) const;
228 
234  bool
235  validSamplePointNo(int samplePointNo) const;
236 
242  bool
243  validSampleNo(int sampleNo) const;
244 
245 
251  const
253  getFunctionSpace() const;
254 
262  virtual
263  DataAbstract*
264  getSlice(const DataTypes::RegionType& region) const = 0;
265 
266 
267 
286  virtual
287  void
288  setTaggedValue(int tagKey,
289  const DataTypes::ShapeType& pointshape,
290  const DataTypes::ValueType& value,
291  int dataOffset=0);
292 
293 
306  virtual void
307  copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
308 
318  virtual void
319  copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value);
320 
321 
330  virtual
331  int
332  getTagNumber(int dpno);
333 
342  virtual void
343  symmetric(DataAbstract* ev);
344 
353  virtual void
354  nonsymmetric(DataAbstract* ev);
355 
364  virtual void
365  trace(DataAbstract* ev, int axis_offset);
366 
375  virtual void
376  transpose(DataAbstract* ev, int axis_offset);
377 
387  virtual void
388  swapaxes(DataAbstract* ev, int axis0, int axis1);
397  virtual void
398  eigenvalues(DataAbstract* ev);
399 
406  virtual int
407  matrixInverse(DataAbstract* out) const;
408 
415  virtual void
416  setToZero();
417 
430  virtual void
431  eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
432 
440  virtual void
441  reorderByReferenceIDs(int *reference_ids);
442 
443 
444 
450  unsigned int
451  getNoValues() const;
452 
453 
455  bool isLazy() const; // a test to determine if this object is an instance of DataLazy
456 
458  virtual
459  bool
460  isConstant() const {return false;}
461 
463  virtual
464  bool
465  isExpanded() const {return false;}
466 
467 
474  virtual
475  bool
476  actsExpanded() const {return false;}
477 
479  virtual
480  bool
481  isTagged() const {return false;}
482 
484  bool isEmpty() const; // a fast test to determine if this object is an instance of DataEmpty
485 
486 
490  void
491  addOwner(Data*);
492 
496  void
497  removeOwner(Data*);
498 
503  bool
504  isShared() const
505  {
506  return m_lazyshared || (m_owners.size()>1);
507  }
508 
509  protected:
510 
516  bool checkNoSharing() const;
517 
522  void
523  makeLazyShared();
524 
525  friend class DataLazy;
526 
527  private:
528 
529  //
530  // The number of samples in this Data object.
531  // This is derived directly from the FunctionSpace.
533 
534  //
535  // The number of data points per sample in this Data object.
536  // This is derived directly from the FunctionSpace.
538 
539  //
540  // A FunctionSpace which provides a description of the data associated
541  // with this Data object.
543 
544  //
545  // The shape of the points stored in this view
547 
548  //
549  // The number of values in each point
550  unsigned int m_novalues;
551 
552  //
553  // The rank of the points stored in this view
554  unsigned int m_rank;
555 
556  //
557  // Is this an instance of DataEmpty?
558  bool m_isempty;
559 
560 public: // these should be private once I have finished debugging
561  std::vector<Data*> m_owners;
563 };
564 
565 inline
566 bool
568 {
569  return m_isempty;
570 }
571 
572 inline
573 bool
574 DataAbstract::validSamplePointNo(int samplePointNo) const
575 {
576  return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
577 }
578 
579 inline
580 bool
581 DataAbstract::validSampleNo(int sampleNo) const
582 {
583  return ((0 <= sampleNo) && (sampleNo < m_noSamples));
584 }
585 
586 inline
587 int
589 {
590  if (isEmpty())
591  {
592  throw DataException("Error - Operations not permitted on instances of DataEmpty.");
593  }
595 }
596 
597 inline
598 int
600 {
601  if (isEmpty())
602  {
603  throw DataException("Error - Operations not permitted on instances of DataEmpty.");
604  }
605  return m_noSamples;
606 }
607 
608 inline
609 const
612 {
613  return m_functionSpace;
614 }
615 
616 inline
617 const DataTypes::ShapeType&
619 {
620  if (isEmpty())
621  {
622  throw DataException("Error - Operations not permitted on instances of DataEmpty.");
623  }
624  return m_shape;
625 }
626 
627 inline
628 unsigned int
630 {
631  if (isEmpty())
632  {
633  throw DataException("Error - Operations not permitted on instances of DataEmpty.");
634  }
635  return m_rank;
636 }
637 
638 inline
639 unsigned int
641 {
642  if (isEmpty())
643  {
644  throw DataException("Error - Operations not permitted on instances of DataEmpty.");
645  }
646  return m_novalues;
647 }
648 
649 
650 } // end of namespace
651 
652 #endif