Go to the documentation of this file.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
00024 #include "DataException.h"
00025
00026 #include <string>
00027 #include <fstream>
00028 #include <vector>
00029
00030 #include "Pointers.h"
00031
00032 namespace escript {
00033
00048 class DataAbstract;
00049
00050 typedef POINTER_WRAPPER_CLASS(DataAbstract) DataAbstract_ptr;
00051 typedef POINTER_WRAPPER_CLASS(const DataAbstract) const_DataAbstract_ptr;
00052
00053 class DataReady;
00054
00055 typedef POINTER_WRAPPER_CLASS(DataReady) DataReady_ptr;
00056 typedef POINTER_WRAPPER_CLASS(const DataReady) const_DataReady_ptr;
00057
00058 class DataAbstract : public REFCOUNT_BASE_CLASS(DataAbstract)
00059 {
00060
00061 public:
00062
00063 typedef DataTypes::ValueType ValueType;
00064 typedef DataTypes::ShapeType ShapeType;
00065
00080 ESCRIPT_DLL_API
00081 DataAbstract_ptr getPtr();
00082 ESCRIPT_DLL_API
00083 const_DataAbstract_ptr getPtr() const;
00084
00085
00086
00095 ESCRIPT_DLL_API
00096 DataAbstract(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty=false);
00097
00102 ESCRIPT_DLL_API
00103 virtual
00104 ~DataAbstract();
00105
00110 ESCRIPT_DLL_API
00111 virtual
00112 std::string
00113 toString() const = 0;
00114
00118 ESCRIPT_DLL_API
00119 virtual
00120 DataAbstract*
00121 deepCopy()=0;
00122
00126 ESCRIPT_DLL_API
00127 virtual
00128 DataReady_ptr
00129 resolve()=0;
00130
00135 ESCRIPT_DLL_API
00136 virtual
00137 void
00138 dump(const std::string fileName) const;
00139
00144 ESCRIPT_DLL_API
00145 int
00146 getNumDPPSample() const;
00147
00152 ESCRIPT_DLL_API
00153 int
00154 getNumSamples() const;
00155
00162 ESCRIPT_DLL_API
00163 const DataTypes::ShapeType&
00164 getShape() const;
00165
00170 ESCRIPT_DLL_API
00171 unsigned int
00172 getRank() const;
00173
00174
00175
00184 ESCRIPT_DLL_API
00185 virtual
00186 ValueType::size_type
00187 getPointOffset(int sampleNo,
00188 int dataPointNo) const = 0;
00189
00190 ESCRIPT_DLL_API
00191 virtual
00192 ValueType::size_type
00193 getPointOffset(int sampleNo,
00194 int dataPointNo) = 0;
00195
00196
00201 ESCRIPT_DLL_API
00202 virtual
00203 ValueType::size_type
00204 getLength() const = 0;
00205
00211 ESCRIPT_DLL_API
00212 virtual
00213 double*
00214 getSampleDataByTag(int tag);
00215
00223 ESCRIPT_DLL_API
00224 void
00225 operandCheck(const DataAbstract& right) const;
00226
00231 ESCRIPT_DLL_API
00232 bool
00233 validSamplePointNo(int samplePointNo) const;
00234
00239 ESCRIPT_DLL_API
00240 bool
00241 validSampleNo(int sampleNo) const;
00242
00243
00248 ESCRIPT_DLL_API
00249 const
00250 FunctionSpace&
00251 getFunctionSpace() const;
00252
00259 ESCRIPT_DLL_API
00260 virtual
00261 DataAbstract*
00262 getSlice(const DataTypes::RegionType& region) const = 0;
00263
00264
00265
00283 ESCRIPT_DLL_API
00284 virtual
00285 void
00286 setTaggedValue(int tagKey,
00287 const DataTypes::ShapeType& pointshape,
00288 const DataTypes::ValueType& value,
00289 int dataOffset=0);
00290
00291
00303 ESCRIPT_DLL_API
00304 virtual void
00305 copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
00306
00315 ESCRIPT_DLL_API
00316 virtual void
00317 copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value);
00318
00319
00327 ESCRIPT_DLL_API
00328 virtual
00329 int
00330 getTagNumber(int dpno);
00331
00339 ESCRIPT_DLL_API
00340 virtual void
00341 symmetric(DataAbstract* ev);
00342
00350 ESCRIPT_DLL_API
00351 virtual void
00352 nonsymmetric(DataAbstract* ev);
00353
00361 ESCRIPT_DLL_API
00362 virtual void
00363 trace(DataAbstract* ev, int axis_offset);
00364
00372 ESCRIPT_DLL_API
00373 virtual void
00374 transpose(DataAbstract* ev, int axis_offset);
00375
00384 ESCRIPT_DLL_API
00385 virtual void
00386 swapaxes(DataAbstract* ev, int axis0, int axis1);
00394 ESCRIPT_DLL_API
00395 virtual void
00396 eigenvalues(DataAbstract* ev);
00397
00403 ESCRIPT_DLL_API
00404 virtual int
00405 matrixInverse(DataAbstract* out) const;
00406
00412 ESCRIPT_DLL_API
00413 virtual void
00414 setToZero();
00415
00427 ESCRIPT_DLL_API
00428 virtual void
00429 eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
00430
00437 ESCRIPT_DLL_API
00438 virtual void
00439 reorderByReferenceIDs(int *reference_ids);
00440
00441
00442
00447 ESCRIPT_DLL_API
00448 unsigned int
00449 getNoValues() const;
00450
00451
00452 ESCRIPT_DLL_API
00453 bool isLazy() const;
00454
00455 ESCRIPT_DLL_API
00456 virtual
00457 bool
00458 isConstant() const {return false;}
00459
00460 ESCRIPT_DLL_API
00461 virtual
00462 bool
00463 isExpanded() const {return false;}
00464
00465
00471 ESCRIPT_DLL_API
00472 virtual
00473 bool
00474 actsExpanded() const {return false;}
00475
00476 ESCRIPT_DLL_API
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