00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #if !defined escript_DataAbstract_20040315_H
00016 #define escript_DataAbstract_20040315_H
00017 #include "system_dep.h"
00018
00019 #include "DataTypes.h"
00020 #include "FunctionSpace.h"
00021
00022 #include <boost/scoped_ptr.hpp>
00023 #include <boost/python/numeric.hpp>
00024
00025 #include "DataException.h"
00026
00027 #include <string>
00028 #include <fstream>
00029 #include <vector>
00030
00031 #include "Pointers.h"
00032
00033 namespace escript {
00034
00049 class DataAbstract;
00050
00051 typedef POINTER_WRAPPER_CLASS(DataAbstract) DataAbstract_ptr;
00052 typedef POINTER_WRAPPER_CLASS(const DataAbstract) const_DataAbstract_ptr;
00053
00054 class DataReady;
00055
00056 typedef POINTER_WRAPPER_CLASS(DataReady) DataReady_ptr;
00057 typedef POINTER_WRAPPER_CLASS(const DataReady) const_DataReady_ptr;
00058
00059 class DataAbstract : public REFCOUNT_BASE_CLASS(DataAbstract)
00060 {
00061
00062 public:
00063
00064 typedef DataTypes::ValueType ValueType;
00065 typedef DataTypes::ShapeType ShapeType;
00066
00081 ESCRIPT_DLL_API
00082 DataAbstract_ptr getPtr();
00083 ESCRIPT_DLL_API
00084 const_DataAbstract_ptr getPtr() const;
00085
00086
00087
00096 ESCRIPT_DLL_API
00097 DataAbstract(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty=false);
00098
00103 ESCRIPT_DLL_API
00104 virtual
00105 ~DataAbstract();
00106
00111 ESCRIPT_DLL_API
00112 virtual
00113 std::string
00114 toString() const = 0;
00115
00119 ESCRIPT_DLL_API
00120 virtual
00121 DataAbstract*
00122 deepCopy()=0;
00123
00127 ESCRIPT_DLL_API
00128 virtual
00129 DataReady_ptr
00130 resolve()=0;
00131
00136 ESCRIPT_DLL_API
00137 virtual
00138 void
00139 dump(const std::string fileName) const;
00140
00145 ESCRIPT_DLL_API
00146 int
00147 getNumDPPSample() const;
00148
00153 ESCRIPT_DLL_API
00154 int
00155 getNumSamples() const;
00156
00163 ESCRIPT_DLL_API
00164 const DataTypes::ShapeType&
00165 getShape() const;
00166
00171 ESCRIPT_DLL_API
00172 unsigned int
00173 getRank() const;
00174
00175
00176
00185 ESCRIPT_DLL_API
00186 virtual
00187 ValueType::size_type
00188 getPointOffset(int sampleNo,
00189 int dataPointNo) const = 0;
00190
00191 ESCRIPT_DLL_API
00192 virtual
00193 ValueType::size_type
00194 getPointOffset(int sampleNo,
00195 int dataPointNo) = 0;
00196
00197
00202 ESCRIPT_DLL_API
00203 virtual
00204 ValueType::size_type
00205 getLength() const = 0;
00206
00212 ESCRIPT_DLL_API
00213 virtual
00214 double*
00215 getSampleDataByTag(int tag);
00216
00221 ESCRIPT_DLL_API
00222 virtual size_t
00223 getSampleBufferSize() const=0;
00224
00225
00226
00234 ESCRIPT_DLL_API
00235 void
00236 operandCheck(const DataAbstract& right) const;
00237
00242 ESCRIPT_DLL_API
00243 bool
00244 validSamplePointNo(int samplePointNo) const;
00245
00250 ESCRIPT_DLL_API
00251 bool
00252 validSampleNo(int sampleNo) const;
00253
00254
00259 ESCRIPT_DLL_API
00260 const
00261 FunctionSpace&
00262 getFunctionSpace() const;
00263
00270 ESCRIPT_DLL_API
00271 virtual
00272 DataAbstract*
00273 getSlice(const DataTypes::RegionType& region) const = 0;
00274
00275
00276
00294 ESCRIPT_DLL_API
00295 virtual
00296 void
00297 setTaggedValue(int tagKey,
00298 const DataTypes::ShapeType& pointshape,
00299 const DataTypes::ValueType& value,
00300 int dataOffset=0);
00301
00302
00314 ESCRIPT_DLL_API
00315 virtual void
00316 copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
00317
00326 ESCRIPT_DLL_API
00327 virtual void
00328 copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value);
00329
00330
00338 ESCRIPT_DLL_API
00339 virtual
00340 int
00341 getTagNumber(int dpno);
00342
00350 ESCRIPT_DLL_API
00351 virtual void
00352 symmetric(DataAbstract* ev);
00353
00361 ESCRIPT_DLL_API
00362 virtual void
00363 nonsymmetric(DataAbstract* ev);
00364
00372 ESCRIPT_DLL_API
00373 virtual void
00374 trace(DataAbstract* ev, int axis_offset);
00375
00383 ESCRIPT_DLL_API
00384 virtual void
00385 transpose(DataAbstract* ev, int axis_offset);
00386
00395 ESCRIPT_DLL_API
00396 virtual void
00397 swapaxes(DataAbstract* ev, int axis0, int axis1);
00405 ESCRIPT_DLL_API
00406 virtual void
00407 eigenvalues(DataAbstract* ev);
00408
00414 ESCRIPT_DLL_API
00415 virtual void
00416 setToZero();
00417
00429 ESCRIPT_DLL_API
00430 virtual void
00431 eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
00432
00439 ESCRIPT_DLL_API
00440 virtual void
00441 reorderByReferenceIDs(int *reference_ids);
00442
00443
00444
00449 ESCRIPT_DLL_API
00450 unsigned int
00451 getNoValues() const;
00452
00453
00454 ESCRIPT_DLL_API
00455 bool isLazy() const;
00456
00457 ESCRIPT_DLL_API
00458 virtual
00459 bool
00460 isConstant() const {return false;}
00461
00462 ESCRIPT_DLL_API
00463 virtual
00464 bool
00465 isExpanded() const {return false;}
00466
00467
00473 virtual
00474 bool
00475 actsExpanded() const {return false;}
00476
00477 virtual
00478 bool
00479 isTagged() const {return false;}
00480
00481 ESCRIPT_DLL_API
00482 bool isEmpty() const;
00483
00484
00488 void
00489 addOwner(Data*);
00490
00494 void
00495 removeOwner(Data*);
00496
00500 ESCRIPT_DLL_API
00501 bool
00502 isShared() const
00503 {
00504 return m_lazyshared || (m_owners.size()>1);
00505 }
00506
00507 protected:
00508
00513 ESCRIPT_DLL_API
00514 bool checkNoSharing() const;
00515
00520 void
00521 makeLazyShared();
00522
00523 friend class DataLazy;
00524
00525 private:
00526
00527
00528
00529
00530 int m_noSamples;
00531
00532
00533
00534
00535 int m_noDataPointsPerSample;
00536
00537
00538
00539
00540 FunctionSpace m_functionSpace;
00541
00542
00543
00544 DataTypes::ShapeType m_shape;
00545
00546
00547
00548 unsigned int m_novalues;
00549
00550
00551
00552 unsigned int m_rank;
00553
00554
00555
00556 bool m_isempty;
00557
00558 public:
00559 std::vector<Data*> m_owners;
00560 bool m_lazyshared;
00561 };
00562
00563 inline
00564 bool
00565 DataAbstract::isEmpty() const
00566 {
00567 return m_isempty;
00568 }
00569
00570 inline
00571 bool
00572 DataAbstract::validSamplePointNo(int samplePointNo) const
00573 {
00574 return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
00575 }
00576
00577 inline
00578 bool
00579 DataAbstract::validSampleNo(int sampleNo) const
00580 {
00581 return ((0 <= sampleNo) && (sampleNo < m_noSamples));
00582 }
00583
00584 inline
00585 int
00586 DataAbstract::getNumDPPSample() const
00587 {
00588 if (isEmpty())
00589 {
00590 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
00591 }
00592 return m_noDataPointsPerSample;
00593 }
00594
00595 inline
00596 int
00597 DataAbstract::getNumSamples() const
00598 {
00599 if (isEmpty())
00600 {
00601 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
00602 }
00603 return m_noSamples;
00604 }
00605
00606 inline
00607 const
00608 FunctionSpace&
00609 DataAbstract::getFunctionSpace() const
00610 {
00611 return m_functionSpace;
00612 }
00613
00614 inline
00615 const DataTypes::ShapeType&
00616 DataAbstract::getShape() const
00617 {
00618 if (isEmpty())
00619 {
00620 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
00621 }
00622 return m_shape;
00623 }
00624
00625 inline
00626 unsigned int
00627 DataAbstract::getRank() const
00628 {
00629 if (isEmpty())
00630 {
00631 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
00632 }
00633 return m_rank;
00634 }
00635
00636 inline
00637 unsigned int
00638 DataAbstract::getNoValues() const
00639 {
00640 if (isEmpty())
00641 {
00642 throw DataException("Error - Operations not permitted on instances of DataEmpty.");
00643 }
00644 return m_novalues;
00645 }
00646
00647
00648 }
00649
00650 #endif