escript  Revision_4925
DataTagged.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2014 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 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 
18 #if !defined escript_DataTagged_20040615_H
19 #define escript_DataTagged_20040615_H
20 #include "system_dep.h"
21 
22 #include "DataReady.h"
23 #include "DataTypes.h"
24 
25 #include <vector>
26 #include <map>
27 
28 namespace escript {
29 
30 class DataConstant;
31 
43 class DataTagged : public DataReady {
44 typedef DataReady parent;
45  public:
46 
47  //
48  // Types for the lists of tags and values.
49  typedef std::vector<int> TagListType;
50 // typedef std::vector<DataArrayView> ValueListType;
52  typedef std::vector<ValueType::ElementType> ValueBatchType;
53 
54  //
55  // Map from a tag to an offset into the data array.
56  typedef std::map<int, int> DataMapType;
57 
69  DataTagged();
70 
84  DataTagged(const FunctionSpace& what,
85  const DataTypes::ShapeType &shape,
86  const int tags[],
87  const ValueType& data);
88 
102  DataTagged(const FunctionSpace& what,
103  const DataTypes::ShapeType &shape,
104  const TagListType& tags,
105  const ValueType& data);
106 
114  DataTagged(const DataTagged& other);
115 
124  DataTagged(const DataConstant& other);
125 
137  DataTagged(const FunctionSpace& what,
138  const DataTypes::ShapeType& shape,
139  const DataTypes::ValueType& defaultvalue,
140  const DataTagged* tagsource=0);
141 
147  inline virtual
149 
151  bool
152  isTagged() const
153  {
154  return true;
155  };
156 
161  bool
162  hasNaN() const;
163 
168  virtual
169  DataAbstract*
170  deepCopy();
171 
172 
186  virtual
187  double*
188  getSampleDataByTag(int tag);
189 
198  virtual
199  std::string
200  toString() const;
206  virtual
207  void
208  dump(const std::string fileName) const;
209 
216  virtual int
217  matrixInverse(DataAbstract* out) const;
218 
224  virtual
225  void
226  setToZero();
227 
235  virtual
236  int
237  getTagNumber(int dpno);
238 
252  virtual
254  getPointOffset(int sampleNo,
255  int dataPointNo) const;
256 
258  virtual
260  getPointOffset(int sampleNo,
261  int dataPointNo);
262 
281  void
282  addTaggedValues(const TagListType& tagKeys,
283  const ValueBatchType& values,
284  const ShapeType& vShape);
285 
286 
304  void
305  addTaggedValues(const TagListType& tagKeys,
306  const ValueType& values,
307  const ShapeType& vShape);
308 
309 
310 
311 
325  void
326  addTaggedValue(int tagKey,
327  const DataTypes::ShapeType& pointshape,
328  const ValueType& value,
329  int dataOffset=0);
330 
342  void
343  addTag(int tagKey);
344 
358  void
359  setTaggedValue(int tagKey,
360  const DataTypes::ShapeType& pointshape,
361  const ValueType& value,
362  int dataOffset=0);
363 
377 
381 
382 
383 
395  getOffsetForTag(int tag) const;
396 
397 
405  getVectorRW();
406 
408  const DataTypes::ValueType&
409  getVectorRO() const;
410 
411 
412 
422  const DataMapType&
423  getTagLookup() const;
424 
437  bool
438  isCurrentTag(int tag) const;
439 
452 
456 
457 
458 
459 
460 
470  virtual
472  getLength() const;
473 
485  virtual
486  DataAbstract*
487  getSlice(const DataTypes::RegionType& region) const;
488 
501  DataTagged(const DataTagged& other,
502  const DataTypes::RegionType& region);
503 
515  virtual
516  void
517  setSlice(const DataAbstract* other,
518  const DataTypes::RegionType& region);
519 
520 
529  virtual void
530  symmetric(DataAbstract* ev);
531 
540  virtual void
542 
551  virtual void
552  trace(DataAbstract* ev, int axis_offset);
553 
563  virtual void
564  swapaxes(DataAbstract* ev, int axis0, int axis1);
565 
574  virtual void
575  transpose(DataAbstract* ev, int axis_offset);
576 
585  virtual void
587 
600  virtual void
601  eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
602 
603 
609  getDefaultOffset() const;
610 
611  protected:
612 
613  private:
614 
615  //
616  // The offset lookup table
618 
619  //
620  // the offset to the default value
621  static const int m_defaultValueOffset = 0;
622 
623  //
624  // The actual data
626 
627 };
628 
629 inline
630 bool
632 {
633  DataMapType::const_iterator pos(m_offsetLookup.find(tag));
634  return (pos!=m_offsetLookup.end());
635 }
636 
637 inline
640 {
641  return m_defaultValueOffset;
642 }
643 
644 inline
647 {
648  return getVectorRW()[i]; // getVectorRW has exclusive write checks
649 }
650 
651 inline
654 {
655  return getVectorRO()[i];
656 }
657 
658 inline
661 {
662  return m_offsetLookup;
663 }
664 
665 inline
668 {
669  return m_data.size();
670 }
671 
672 } // end of namespace
673 
674 #endif
Give a short description of what FunctionSpace does.
Definition: FunctionSpace.h:46
DataVector implements an arbitrarily long vector of data values. DataVector is the underlying data co...
Definition: DataVector.h:44
virtual void symmetric(DataAbstract *ev)
Computes a symmetric matrix (A + AT) / 2.
Definition: DataTagged.cpp:565
void addTag(int tagKey)
addTag - does not modify the default value for this object. ** Not unit tested ** ...
Definition: DataTagged.cpp:429
bool isCurrentTag(int tag) const
isCurrentTag
Definition: DataTagged.h:631
DataTypes::ShapeType ShapeType
Definition: DataAbstract.h:67
DataTypes::ValueType::size_type getDefaultOffset() const
Returns the offset in the structure which stores the default value.
Definition: DataTagged.h:639
DataTagged()
Default constructor for DataTagged.
Definition: DataTagged.cpp:39
ValueType m_data
Definition: DataTagged.h:625
void addTaggedValue(int tagKey, const DataTypes::ShapeType &pointshape, const ValueType &value, int dataOffset=0)
addTaggedValue
Definition: DataTagged.cpp:395
Definition: DataReady.h:35
std::vector< std::pair< int, int > > RegionType
Definition: DataTypes.h:39
virtual ValueType::size_type getPointOffset(int sampleNo, int dataPointNo) const
getPointOffset
Definition: DataTagged.cpp:505
void setTaggedValue(int tagKey, const DataTypes::ShapeType &pointshape, const ValueType &value, int dataOffset=0)
setTaggedValue
Definition: DataTagged.cpp:316
DataConstant stores a single data point which represents the entire function space.
Definition: DataConstant.h:37
size_type size() const
Return the number of elements in this DataVector.
Definition: DataVector.h:215
const DataMapType & getTagLookup() const
getTagLookup
Definition: DataTagged.h:660
DataTypes::ValueType::const_reference getDataByTagRO(int tag, DataTypes::ValueType::size_type i) const
Definition: DataTagged.cpp:542
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:38
Simulates a full dataset accessible via sampleNo and dataPointNo.
Definition: DataTagged.h:43
virtual void transpose(DataAbstract *ev, int axis_offset)
Transpose each data point of this Data object around the given axis.
Definition: DataTagged.cpp:630
bool hasNaN() const
Return true if any one of the datapoints contains a NaN.
Definition: DataTagged.cpp:472
virtual int getTagNumber(int dpno)
Return the tag number associated with the given data-point number according to the associated functio...
Definition: DataTagged.cpp:286
std::vector< ValueType::ElementType > ValueBatchType
Definition: DataTagged.h:52
DataTypes::ValueType::reference getDataByTagRW(int tag, DataTypes::ValueType::size_type i)
getDataByTag
Definition: DataTagged.cpp:553
DataTypes::ValueType & getVectorRW()
Return a reference to the underlying DataVector.
Definition: DataTagged.cpp:869
virtual void setSlice(const DataAbstract *other, const DataTypes::RegionType &region)
setSlice
Definition: DataTagged.cpp:236
static const int m_defaultValueOffset
Definition: DataTagged.h:621
bool isTagged() const
Definition: DataTagged.h:152
std::map< int, int > DataMapType
Definition: DataTagged.h:56
virtual DataAbstract * getSlice(const DataTypes::RegionType &region) const
getSlice
Definition: DataTagged.cpp:200
virtual void setToZero()
sets all values to zero
Definition: DataTagged.cpp:766
virtual void eigenvalues(DataAbstract *ev)
solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
Definition: DataTagged.cpp:672
virtual void trace(DataAbstract *ev, int axis_offset)
Computes the trace of a matrix.
Definition: DataTagged.cpp:609
virtual void nonsymmetric(DataAbstract *ev)
Computes a nonsymmetric matrix (A - AT) / 2.
Definition: DataTagged.cpp:587
virtual int matrixInverse(DataAbstract *out) const
invert square matricies
Definition: DataTagged.cpp:732
const ElementType & const_reference
Definition: DataVector.h:62
DataMapType m_offsetLookup
Definition: DataTagged.h:617
virtual void eigenvalues_and_eigenvectors(DataAbstract *ev, DataAbstract *V, const double tol=1.e-13)
solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V ...
Definition: DataTagged.cpp:694
virtual ValueType::size_type getLength() const
getLength
Definition: DataTagged.h:667
DataTypes::ValueType::reference getDefaultValueRW(DataTypes::ValueType::size_type i)
getDefaultValue
Definition: DataTagged.h:646
DataTypes::ValueType::const_reference getDefaultValueRO(DataTypes::ValueType::size_type i) const
Definition: DataTagged.h:653
#define V(_K_, _I_)
Definition: ShapeFunctions.cpp:120
std::vector< int > TagListType
Definition: DataTagged.h:49
#define ESCRIPT_DLL_API
Definition: escriptcore/src/system_dep.h:64
ElementType & reference
Definition: DataVector.h:61
DataReady parent
Definition: DataTagged.h:44
virtual void swapaxes(DataAbstract *ev, int axis0, int axis1)
swaps components axis0 and axis1
Definition: DataTagged.cpp:651
virtual void dump(const std::string fileName) const
dumps the object into a netCDF file
Definition: DataTagged.cpp:773
Definition: DataAbstract.h:61
DataTypes::ValueType ValueType
Definition: DataTagged.h:51
const DataTypes::ValueType & getVectorRO() const
Definition: DataTagged.cpp:876
virtual std::string toString() const
Write the data as a string. Writes out each tag, including the default, and the data-point which is a...
Definition: DataTagged.cpp:485
long size_type
Definition: DataVector.h:60
virtual DataAbstract * deepCopy()
Return a deep copy of the current object.
Definition: DataTagged.cpp:194
virtual ~DataTagged()
Destructor.
Definition: DataTagged.h:148
virtual double * getSampleDataByTag(int tag)
getSampleDataByTag
Definition: DataTagged.cpp:457
void addTaggedValues(const TagListType &tagKeys, const ValueBatchType &values, const ShapeType &vShape)
addTaggedValues
Definition: DataTagged.cpp:341
DataTypes::ValueType::size_type getOffsetForTag(int tag) const
getOffsetForTag
Definition: DataTagged.cpp:531