ESScript  Revision_4488
DataTagged.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_DataTagged_20040615_H
18 #define escript_DataTagged_20040615_H
19 #include "system_dep.h"
20 
21 #include "DataReady.h"
22 #include "DataTypes.h"
23 
24 #include <vector>
25 #include <map>
26 
27 namespace escript {
28 
29 class DataConstant;
30 
42 class DataTagged : public DataReady {
43 typedef DataReady parent;
44  public:
45 
46  //
47  // Types for the lists of tags and values.
48  typedef std::vector<int> TagListType;
49 // typedef std::vector<DataArrayView> ValueListType;
51  typedef std::vector<ValueType::ElementType> ValueBatchType;
52 
53  //
54  // Map from a tag to an offset into the data array.
55  typedef std::map<int, int> DataMapType;
56 
68  DataTagged();
69 
83  DataTagged(const FunctionSpace& what,
84  const DataTypes::ShapeType &shape,
85  const int tags[],
86  const ValueType& data);
87 
101  DataTagged(const FunctionSpace& what,
102  const DataTypes::ShapeType &shape,
103  const TagListType& tags,
104  const ValueType& data);
105 
113  DataTagged(const DataTagged& other);
114 
123  DataTagged(const DataConstant& other);
124 
136  DataTagged(const FunctionSpace& what,
137  const DataTypes::ShapeType& shape,
138  const DataTypes::ValueType& defaultvalue,
139  const DataTagged* tagsource=0);
140 
146  inline virtual
148 
150  bool
151  isTagged() const
152  {
153  return true;
154  };
155 
160  bool
161  hasNaN() const;
162 
167  virtual
168  DataAbstract*
169  deepCopy();
170 
171 
185  virtual
186  double*
187  getSampleDataByTag(int tag);
188 
197  virtual
198  std::string
199  toString() const;
205  virtual
206  void
207  dump(const std::string fileName) const;
208 
215  virtual int
216  matrixInverse(DataAbstract* out) const;
217 
223  virtual
224  void
225  setToZero();
226 
234  virtual
235  int
236  getTagNumber(int dpno);
237 
251  virtual
253  getPointOffset(int sampleNo,
254  int dataPointNo) const;
255 
257  virtual
259  getPointOffset(int sampleNo,
260  int dataPointNo);
261 
280  void
281  addTaggedValues(const TagListType& tagKeys,
282  const ValueBatchType& values,
283  const ShapeType& vShape);
284 
285 
303  void
304  addTaggedValues(const TagListType& tagKeys,
305  const ValueType& values,
306  const ShapeType& vShape);
307 
308 
309 
310 
324  void
325  addTaggedValue(int tagKey,
326  const DataTypes::ShapeType& pointshape,
327  const ValueType& value,
328  int dataOffset=0);
329 
341  void
342  addTag(int tagKey);
343 
357  void
358  setTaggedValue(int tagKey,
359  const DataTypes::ShapeType& pointshape,
360  const ValueType& value,
361  int dataOffset=0);
362 
376 
380 
381 
382 
394  getOffsetForTag(int tag) const;
395 
396 
404  getVectorRW();
405 
407  const DataTypes::ValueType&
408  getVectorRO() const;
409 
410 
411 
421  const DataMapType&
422  getTagLookup() const;
423 
436  bool
437  isCurrentTag(int tag) const;
438 
451 
455 
456 
457 
458 
459 
469  virtual
471  getLength() const;
472 
484  virtual
485  DataAbstract*
486  getSlice(const DataTypes::RegionType& region) const;
487 
500  DataTagged(const DataTagged& other,
501  const DataTypes::RegionType& region);
502 
514  virtual
515  void
516  setSlice(const DataAbstract* other,
517  const DataTypes::RegionType& region);
518 
519 
528  virtual void
529  symmetric(DataAbstract* ev);
530 
539  virtual void
541 
550  virtual void
551  trace(DataAbstract* ev, int axis_offset);
552 
562  virtual void
563  swapaxes(DataAbstract* ev, int axis0, int axis1);
564 
573  virtual void
574  transpose(DataAbstract* ev, int axis_offset);
575 
584  virtual void
586 
599  virtual void
600  eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
601 
602 
608  getDefaultOffset() const;
609 
610  protected:
611 
612  private:
613 
614  //
615  // The offset lookup table
617 
618  //
619  // the offset to the default value
620  static const int m_defaultValueOffset = 0;
621 
622  //
623  // The actual data
625 
626 };
627 
628 inline
629 bool
631 {
632  DataMapType::const_iterator pos(m_offsetLookup.find(tag));
633  return (pos!=m_offsetLookup.end());
634 }
635 
636 inline
639 {
640  return m_defaultValueOffset;
641 }
642 
643 inline
646 {
647  return getVectorRW()[i]; // getVectorRW has exclusive write checks
648 }
649 
650 inline
653 {
654  return getVectorRO()[i];
655 }
656 
657 inline
660 {
661  return m_offsetLookup;
662 }
663 
664 inline
667 {
668  return m_data.size();
669 }
670 
671 } // end of namespace
672 
673 #endif