escript
Revision_
|
00001 00002 /***************************************************************************** 00003 * 00004 * Copyright (c) 2003-2014 by University of Queensland 00005 * http://www.uq.edu.au 00006 * 00007 * Primary Business: Queensland, Australia 00008 * Licensed under the Open Software License version 3.0 00009 * http://www.opensource.org/licenses/osl-3.0.php 00010 * 00011 * Development until 2012 by Earth Systems Science Computational Center (ESSCC) 00012 * Development 2012-2013 by School of Earth Sciences 00013 * Development from 2014 by Centre for Geoscience Computing (GeoComp) 00014 * 00015 *****************************************************************************/ 00016 00017 00018 #if !defined escript_DataTagged_20040615_H 00019 #define escript_DataTagged_20040615_H 00020 #include "system_dep.h" 00021 00022 #include "DataReady.h" 00023 #include "DataTypes.h" 00024 00025 #include <vector> 00026 #include <map> 00027 00028 namespace escript { 00029 00030 class DataConstant; 00031 00043 class DataTagged : public DataReady { 00044 typedef DataReady parent; 00045 public: 00046 00047 // 00048 // Types for the lists of tags and values. 00049 typedef std::vector<int> TagListType; 00050 // typedef std::vector<DataArrayView> ValueListType; 00051 typedef DataTypes::ValueType ValueType; 00052 typedef std::vector<ValueType::ElementType> ValueBatchType; 00053 00054 // 00055 // Map from a tag to an offset into the data array. 00056 typedef std::map<int, int> DataMapType; 00057 00068 ESCRIPT_DLL_API 00069 DataTagged(); 00070 00083 ESCRIPT_DLL_API 00084 DataTagged(const FunctionSpace& what, 00085 const DataTypes::ShapeType &shape, 00086 const int tags[], 00087 const ValueType& data); 00088 00101 ESCRIPT_DLL_API 00102 DataTagged(const FunctionSpace& what, 00103 const DataTypes::ShapeType &shape, 00104 const TagListType& tags, 00105 const ValueType& data); 00106 00113 ESCRIPT_DLL_API 00114 DataTagged(const DataTagged& other); 00115 00123 ESCRIPT_DLL_API 00124 DataTagged(const DataConstant& other); 00125 00136 ESCRIPT_DLL_API 00137 DataTagged(const FunctionSpace& what, 00138 const DataTypes::ShapeType& shape, 00139 const DataTypes::ValueType& defaultvalue, 00140 const DataTagged* tagsource=0); 00141 00146 ESCRIPT_DLL_API 00147 inline virtual 00148 ~DataTagged() {}; 00149 00150 ESCRIPT_DLL_API 00151 bool 00152 isTagged() const 00153 { 00154 return true; 00155 }; 00156 00160 ESCRIPT_DLL_API 00161 bool 00162 hasNaN() const; 00163 00167 ESCRIPT_DLL_API 00168 virtual 00169 DataAbstract* 00170 deepCopy(); 00171 00172 00185 ESCRIPT_DLL_API 00186 virtual 00187 double* 00188 getSampleDataByTag(int tag); 00189 00197 ESCRIPT_DLL_API 00198 virtual 00199 std::string 00200 toString() const; 00205 ESCRIPT_DLL_API 00206 virtual 00207 void 00208 dump(const std::string fileName) const; 00209 00215 ESCRIPT_DLL_API 00216 virtual int 00217 matrixInverse(DataAbstract* out) const; 00218 00223 ESCRIPT_DLL_API 00224 virtual 00225 void 00226 setToZero(); 00227 00234 ESCRIPT_DLL_API 00235 virtual 00236 int 00237 getTagNumber(int dpno); 00238 00251 ESCRIPT_DLL_API 00252 virtual 00253 ValueType::size_type 00254 getPointOffset(int sampleNo, 00255 int dataPointNo) const; 00256 00257 ESCRIPT_DLL_API 00258 virtual 00259 ValueType::size_type 00260 getPointOffset(int sampleNo, 00261 int dataPointNo); 00262 00280 ESCRIPT_DLL_API 00281 void 00282 addTaggedValues(const TagListType& tagKeys, 00283 const ValueBatchType& values, 00284 const ShapeType& vShape); 00285 00286 00303 ESCRIPT_DLL_API 00304 void 00305 addTaggedValues(const TagListType& tagKeys, 00306 const ValueType& values, 00307 const ShapeType& vShape); 00308 00309 00310 00311 00324 ESCRIPT_DLL_API 00325 void 00326 addTaggedValue(int tagKey, 00327 const DataTypes::ShapeType& pointshape, 00328 const ValueType& value, 00329 int dataOffset=0); 00330 00341 ESCRIPT_DLL_API 00342 void 00343 addTag(int tagKey); 00344 00357 ESCRIPT_DLL_API 00358 void 00359 setTaggedValue(int tagKey, 00360 const DataTypes::ShapeType& pointshape, 00361 const ValueType& value, 00362 int dataOffset=0); 00363 00374 ESCRIPT_DLL_API 00375 DataTypes::ValueType::reference 00376 getDataByTagRW(int tag, DataTypes::ValueType::size_type i); 00377 00378 ESCRIPT_DLL_API 00379 DataTypes::ValueType::const_reference 00380 getDataByTagRO(int tag, DataTypes::ValueType::size_type i) const; 00381 00382 00383 00393 ESCRIPT_DLL_API 00394 DataTypes::ValueType::size_type 00395 getOffsetForTag(int tag) const; 00396 00397 00403 ESCRIPT_DLL_API 00404 DataTypes::ValueType& 00405 getVectorRW(); 00406 00407 ESCRIPT_DLL_API 00408 const DataTypes::ValueType& 00409 getVectorRO() const; 00410 00411 00412 00421 ESCRIPT_DLL_API 00422 const DataMapType& 00423 getTagLookup() const; 00424 00436 ESCRIPT_DLL_API 00437 bool 00438 isCurrentTag(int tag) const; 00439 00449 ESCRIPT_DLL_API 00450 DataTypes::ValueType::reference 00451 getDefaultValueRW(DataTypes::ValueType::size_type i); 00452 00453 ESCRIPT_DLL_API 00454 DataTypes::ValueType::const_reference 00455 getDefaultValueRO(DataTypes::ValueType::size_type i) const; 00456 00457 00458 00459 00460 00469 ESCRIPT_DLL_API 00470 virtual 00471 ValueType::size_type 00472 getLength() const; 00473 00484 ESCRIPT_DLL_API 00485 virtual 00486 DataAbstract* 00487 getSlice(const DataTypes::RegionType& region) const; 00488 00500 ESCRIPT_DLL_API 00501 DataTagged(const DataTagged& other, 00502 const DataTypes::RegionType& region); 00503 00514 ESCRIPT_DLL_API 00515 virtual 00516 void 00517 setSlice(const DataAbstract* other, 00518 const DataTypes::RegionType& region); 00519 00520 00528 ESCRIPT_DLL_API 00529 virtual void 00530 symmetric(DataAbstract* ev); 00531 00539 ESCRIPT_DLL_API 00540 virtual void 00541 nonsymmetric(DataAbstract* ev); 00542 00550 ESCRIPT_DLL_API 00551 virtual void 00552 trace(DataAbstract* ev, int axis_offset); 00553 00562 ESCRIPT_DLL_API 00563 virtual void 00564 swapaxes(DataAbstract* ev, int axis0, int axis1); 00565 00573 ESCRIPT_DLL_API 00574 virtual void 00575 transpose(DataAbstract* ev, int axis_offset); 00576 00584 ESCRIPT_DLL_API 00585 virtual void 00586 eigenvalues(DataAbstract* ev); 00587 00599 ESCRIPT_DLL_API 00600 virtual void 00601 eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13); 00602 00603 00607 ESCRIPT_DLL_API 00608 DataTypes::ValueType::size_type 00609 getDefaultOffset() const; 00610 00611 protected: 00612 00613 private: 00614 00615 // 00616 // The offset lookup table 00617 DataMapType m_offsetLookup; 00618 00619 // 00620 // the offset to the default value 00621 static const int m_defaultValueOffset = 0; 00622 00623 // 00624 // The actual data 00625 ValueType m_data; 00626 00627 }; 00628 00629 inline 00630 bool 00631 DataTagged::isCurrentTag(int tag) const 00632 { 00633 DataMapType::const_iterator pos(m_offsetLookup.find(tag)); 00634 return (pos!=m_offsetLookup.end()); 00635 } 00636 00637 inline 00638 DataTypes::ValueType::size_type 00639 DataTagged::getDefaultOffset() const 00640 { 00641 return m_defaultValueOffset; 00642 } 00643 00644 inline 00645 DataTypes::ValueType::reference 00646 DataTagged::getDefaultValueRW(DataTypes::ValueType::size_type i) 00647 { 00648 return getVectorRW()[i]; // getVectorRW has exclusive write checks 00649 } 00650 00651 inline 00652 DataTypes::ValueType::const_reference 00653 DataTagged::getDefaultValueRO(DataTypes::ValueType::size_type i) const 00654 { 00655 return getVectorRO()[i]; 00656 } 00657 00658 inline 00659 const DataTagged::DataMapType& 00660 DataTagged::getTagLookup() const 00661 { 00662 return m_offsetLookup; 00663 } 00664 00665 inline 00666 DataTypes::ValueType::size_type 00667 DataTagged::getLength() const 00668 { 00669 return m_data.size(); 00670 } 00671 00672 } // end of namespace 00673 00674 #endif