escript  Revision_Unversioneddirectory
DataTagged.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
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 #ifndef __ESCRIPT_DATATAGGED_H__
19 #define __ESCRIPT_DATATAGGED_H__
20 
21 #include "system_dep.h"
22 
23 #include "DataReady.h"
24 #include "DataTypes.h"
25 
26 #include <map>
27 #include <vector>
28 
29 namespace escript {
30 
31 class DataConstant;
32 
45 {
46  typedef DataReady parent;
47  public:
48 
49  //
50  // Types for the lists of tags and values.
51  typedef std::vector<int> TagListType;
53  typedef std::vector<ValueType::ElementType> ValueBatchType;
54 
55  //
56  // Map from a tag to an offset into the data array.
57  typedef std::map<int, int> DataMapType;
58 
69  DataTagged();
70 
83  DataTagged(const FunctionSpace& what,
84  const DataTypes::ShapeType &shape,
85  const int tags[],
86  const ValueType& data);
87 
100  DataTagged(const FunctionSpace& what,
101  const DataTypes::ShapeType &shape,
102  const TagListType& tags,
103  const ValueType& data);
104 
111  DataTagged(const DataTagged& other);
112 
120  DataTagged(const DataConstant& other);
121 
132  DataTagged(const FunctionSpace& what,
133  const DataTypes::ShapeType& shape,
134  const DataTypes::ValueType& defaultvalue,
135  const DataTagged* tagsource=0);
136 
141  inline virtual
143 
144  bool
145  isTagged() const
146  {
147  return true;
148  };
149 
153  bool
154  hasNaN() const;
155 
159  void
160  replaceNaN(double value);
161 
165  virtual
166  DataAbstract*
167  deepCopy();
168 
169 
182  virtual
183  double*
184  getSampleDataByTag(int tag);
185 
193  virtual
194  std::string
195  toString() const;
200  virtual
201  void
202  dump(const std::string fileName) const;
203 
209  virtual int
210  matrixInverse(DataAbstract* out) const;
211 
216  virtual
217  void
218  setToZero();
219 
226  virtual
227  int
228  getTagNumber(int dpno);
229 
242  virtual
244  getPointOffset(int sampleNo,
245  int dataPointNo) const;
246 
247  virtual
249  getPointOffset(int sampleNo,
250  int dataPointNo);
251 
269  void
270  addTaggedValues(const TagListType& tagKeys,
271  const ValueBatchType& values,
272  const ShapeType& vShape);
273 
274 
291  void
292  addTaggedValues(const TagListType& tagKeys,
293  const ValueType& values,
294  const ShapeType& vShape);
295 
296 
297 
298 
311  void
312  addTaggedValue(int tagKey,
313  const DataTypes::ShapeType& pointshape,
314  const ValueType& value,
315  int dataOffset=0);
316 
327  void
328  addTag(int tagKey);
329 
342  void
343  setTaggedValue(int tagKey,
344  const DataTypes::ShapeType& pointshape,
345  const ValueType& value,
346  int dataOffset=0);
347 
359  getDataByTagRW(int tag, DataTypes::ValueType::size_type i);
360 
362  getDataByTagRO(int tag, DataTypes::ValueType::size_type i) const;
363 
364 
365 
376  getOffsetForTag(int tag) const;
377 
378 
385  getVectorRW();
386 
387  const DataTypes::ValueType&
388  getVectorRO() const;
389 
390 
391 
400  const DataMapType&
401  getTagLookup() const;
402 
414  bool
415  isCurrentTag(int tag) const;
416 
427  getDefaultValueRW(DataTypes::ValueType::size_type i);
428 
430  getDefaultValueRO(DataTypes::ValueType::size_type i) const;
431 
432 
433 
434 
435 
444  virtual
446  getLength() const;
447 
458  virtual
459  DataAbstract*
460  getSlice(const DataTypes::RegionType& region) const;
461 
473  DataTagged(const DataTagged& other,
474  const DataTypes::RegionType& region);
475 
486  virtual
487  void
488  setSlice(const DataAbstract* other,
489  const DataTypes::RegionType& region);
490 
491 
499  virtual void
500  symmetric(DataAbstract* ev);
501 
509  virtual void
511 
519  virtual void
520  trace(DataAbstract* ev, int axis_offset);
521 
530  virtual void
531  swapaxes(DataAbstract* ev, int axis0, int axis1);
532 
540  virtual void
541  transpose(DataAbstract* ev, int axis_offset);
542 
550  virtual void
552 
564  virtual void
565  eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
566 
567 
572  getDefaultOffset() const;
573 
577  size_t
578  getTagCount() const;
579 
580  protected:
581 
582  private:
583 
584  //
585  // The offset lookup table
586  DataMapType m_offsetLookup;
587 
588  //
589  // the offset to the default value
590  static const int m_defaultValueOffset = 0;
591 
592  //
593  // The actual data
594  ValueType m_data;
595 
596 };
597 
598 inline
599 bool
601 {
602  DataMapType::const_iterator pos(m_offsetLookup.find(tag));
603  return (pos!=m_offsetLookup.end());
604 }
605 
606 inline
609 {
610  return m_defaultValueOffset;
611 }
612 
613 inline
616 {
617  return getVectorRW()[i]; // getVectorRW has exclusive write checks
618 }
619 
620 inline
623 {
624  return getVectorRO()[i];
625 }
626 
627 inline
630 {
631  return m_offsetLookup;
632 }
633 
634 inline
637 {
638  return m_data.size();
639 }
640 
641 } // end of namespace
642 
643 #endif // __ESCRIPT_DATATAGGED_H__
644 
Definition: FunctionSpace.h:34
DataVector implements an arbitrarily long vector of data values. DataVector is the underlying data co...
Definition: DataVector.h:44
bool isCurrentTag(int tag) const
isCurrentTag
Definition: DataTagged.h:600
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:608
ValueType m_data
Definition: DataTagged.h:594
Definition: DataReady.h:35
std::vector< std::pair< int, int > > RegionType
Definition: DataTypes.h:39
Definition: AbstractContinuousDomain.cpp:24
int getLength(const escript::Data *data)
Definition: DataC.cpp:92
void transpose(const DataTypes::ValueType &in, const DataTypes::ShapeType &inShape, DataTypes::ValueType::size_type inOffset, DataTypes::ValueType &ev, const DataTypes::ShapeType &evShape, DataTypes::ValueType::size_type evOffset, int axis_offset)
Transpose each data point of this Data object around the given axis.
Definition: DataMaths.h:394
DataConstant stores a single data point which represents the entire function space.
Definition: DataConstant.h:37
const DataMapType & getTagLookup() const
getTagLookup
Definition: DataTagged.h:629
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:38
void swapaxes(const DataTypes::ValueType &in, const DataTypes::ShapeType &inShape, DataTypes::ValueType::size_type inOffset, DataTypes::ValueType &ev, const DataTypes::ShapeType &evShape, DataTypes::ValueType::size_type evOffset, int axis0, int axis1)
swaps the components axis0 and axis1.
Definition: DataMaths.h:538
Simulates a full dataset accessible via sampleNo and dataPointNo.
Definition: DataTagged.h:44
void eigenvalues(const DataTypes::ValueType &in, const DataTypes::ShapeType &inShape, DataTypes::ValueType::size_type inOffset, DataTypes::ValueType &ev, const DataTypes::ShapeType &evShape, DataTypes::ValueType::size_type evOffset)
solves a local eigenvalue problem
Definition: DataMaths.h:689
void symmetric(const DataTypes::ValueType &in, const DataTypes::ShapeType &inShape, DataTypes::ValueType::size_type inOffset, DataTypes::ValueType &ev, const DataTypes::ShapeType &evShape, DataTypes::ValueType::size_type evOffset)
computes a symmetric matrix from your square matrix A: (A + transpose(A)) / 2
Definition: DataMaths.h:197
std::vector< ValueType::ElementType > ValueBatchType
Definition: DataTagged.h:53
bool isTagged() const
Definition: DataTagged.h:145
std::map< int, int > DataMapType
Definition: DataTagged.h:57
const ElementType & const_reference
Definition: DataVector.h:62
DataMapType m_offsetLookup
Definition: DataTagged.h:586
virtual ValueType::size_type getLength() const
getLength
Definition: DataTagged.h:636
void eigenvalues_and_eigenvectors(const DataTypes::ValueType &in, const DataTypes::ShapeType &inShape, DataTypes::ValueType::size_type inOffset, DataTypes::ValueType &ev, const DataTypes::ShapeType &evShape, DataTypes::ValueType::size_type evOffset, DataTypes::ValueType &V, const DataTypes::ShapeType &VShape, DataTypes::ValueType::size_type VOffset, const double tol=1.e-13)
solves a local eigenvalue problem
Definition: DataMaths.h:750
DataTypes::ValueType::reference getDefaultValueRW(DataTypes::ValueType::size_type i)
getDefaultValue
Definition: DataTagged.h:615
DataTypes::ValueType::const_reference getDefaultValueRO(DataTypes::ValueType::size_type i) const
Definition: DataTagged.h:622
#define V(_K_, _I_)
Definition: ShapeFunctions.cpp:120
std::vector< int > TagListType
Definition: DataTagged.h:51
#define ESCRIPT_DLL_API
Definition: escriptcore/src/system_dep.h:54
ElementType & reference
Definition: DataVector.h:61
DataReady parent
Definition: DataTagged.h:46
Definition: DataAbstract.h:61
void nonsymmetric(const DataTypes::ValueType &in, const DataTypes::ShapeType &inShape, DataTypes::ValueType::size_type inOffset, DataTypes::ValueType &ev, const DataTypes::ShapeType &evShape, DataTypes::ValueType::size_type evOffset)
computes a nonsymmetric matrix from your square matrix A: (A - transpose(A)) / 2
Definition: DataMaths.h:246
DataTypes::ValueType ValueType
Definition: DataTagged.h:52
long size_type
Definition: DataVector.h:60
virtual ~DataTagged()
Destructor.
Definition: DataTagged.h:142
void trace(const DataTypes::ValueType &in, const DataTypes::ShapeType &inShape, DataTypes::ValueType::size_type inOffset, DataTypes::ValueType &ev, const DataTypes::ShapeType &evShape, DataTypes::ValueType::size_type evOffset, int axis_offset)
computes the trace of a matrix
Definition: DataMaths.h:295