escript  Revision_
Data.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2018 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 
19 #ifndef __ESCRIPT_DATA_H__
20 #define __ESCRIPT_DATA_H__
21 
22 #include "system_dep.h"
23 #include "DataAbstract.h"
24 #include "DataException.h"
25 #include "DataTypes.h"
26 #include "EsysMPI.h"
27 #include "FunctionSpace.h"
28 #include "DataVectorOps.h"
29 #include <algorithm>
30 #include <string>
31 #include <sstream>
32 
33 #include <boost/python/object.hpp>
34 #include <boost/python/tuple.hpp>
35 #include <boost/math/special_functions/bessel.hpp>
36 
37 #ifndef ESCRIPT_MAX_DATA_RANK
38 #define ESCRIPT_MAX_DATA_RANK 4
39 #endif
40 
41 namespace escript {
42 
43 //
44 // Forward declaration for various implementations of Data.
45 class DataConstant;
46 class DataTagged;
47 class DataExpanded;
48 class DataLazy;
49 
63 class Data {
64 
65  public:
66 
76  Data();
77 
83  Data(const Data& inData);
84 
91  Data(const Data& inData,
92  const FunctionSpace& what);
93 
97  Data(const DataTypes::RealVectorType& value,
98  const DataTypes::ShapeType& shape,
99  const FunctionSpace& what,
100  bool expanded);
101 
113  Data(DataTypes::real_t value,
114  const DataTypes::ShapeType& dataPointShape,
115  const FunctionSpace& what,
116  bool expanded);
117 
129  explicit
130  Data(DataTypes::cplx_t value,
131  const DataTypes::ShapeType& dataPointShape,
132  const FunctionSpace& what,
133  bool expanded);
134 
142  Data(const Data& inData,
143  const DataTypes::RegionType& region);
144 
145 
156  Data(const WrappedArray& w, const FunctionSpace& what,
157  bool expanded);
158 
159 
169  Data(const boost::python::object& value,
170  const Data& other);
171 
192  Data(boost::python::object value,
193  boost::python::object par1=boost::python::object(),
194  boost::python::object par2=boost::python::object(),
195  boost::python::object par3=boost::python::object());
196 
197 
198 
199 
200 
205  explicit Data(DataAbstract* underlyingdata);
206 
210  explicit Data(DataAbstract_ptr underlyingdata);
211 
216  ~Data();
217 
221  void
222  copy(const Data& other);
223 
227  Data
228  copySelf() const;
229 
230 
234  Data
235  delay();
236 
240  void
241  delaySelf();
242 
243 
253  void
254  setProtection();
255 
261  bool
262  isProtected() const;
263 
264 
269  const boost::python::object
270  getValueOfDataPointAsTuple(int dataPointNo);
271 
276  void
277  setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object);
278 
283  void
284  setValueOfDataPointToArray(int dataPointNo, const boost::python::object&);
285 
290  void
291  setValueOfDataPoint(int dataPointNo, const DataTypes::real_t);
292 
293  void
294  setValueOfDataPointC(int dataPointNo, const DataTypes::cplx_t);
295 
296 
300  const boost::python::object
301  getValueOfGlobalDataPointAsTuple(int procNo, int dataPointNo);
302 
303 
307  void
308  setTupleForGlobalDataPoint(int id, int proc, boost::python::object);
309 
315  int
316  getTagNumber(int dpno);
317 
318 
323  std::string
324  toString() const;
325 
330  void
331  expand();
332 
339  void
340  tag();
341 
346  void
347  resolve();
348 
354  bool
355  hasNaN();
356 
360  void
362 
366  void
368 
372  void
373  replaceNaNPython(boost::python::object obj);
374 
375  bool
376  hasInf();
377 
378  void
380 
381  void
383 
384  void
385  replaceInfPython(boost::python::object obj);
386 
387 
395  void
396  requireWrite();
397 
403  bool
404  isExpanded() const;
405 
411  bool
412  actsExpanded() const;
413 
414 
419  bool
420  isTagged() const;
421 
426  bool
427  isConstant() const;
428 
432  bool
433  isLazy() const;
434 
438  bool
439  isReady() const;
440 
446  bool
447  isEmpty() const;
448 
453  bool
454  isComplex() const;
455 
460  inline
461  const FunctionSpace&
463  {
464  return m_data->getFunctionSpace();
465  }
466 
471  inline
472 // const AbstractDomain&
474  getDomain() const
475  {
476  return getFunctionSpace().getDomain();
477  }
478 
479 
485  inline
486 // const AbstractDomain&
487  Domain_ptr
489  {
491  }
492 
497  inline
498  unsigned int
500  {
501  return m_data->getRank();
502  }
503 
508  inline
509  int
511  {
513  }
518  inline
519  int
521  {
522  return m_data->getNumSamples();
523  }
524 
529  inline
530  int
532  {
533  return m_data->getNumDPPSample();
534  }
535 
541  inline
542  bool numSamplesEqual(int numDataPointsPerSample, int numSamples) const
543  {
544  return (isEmpty() ||
545  (numDataPointsPerSample==getNumDataPointsPerSample() && numSamples==getNumSamples()));
546  }
547 
553  inline
554  bool isDataPointShapeEqual(int rank, const int* dimensions) const
555  {
556  if (isEmpty())
557  return true;
558  const DataTypes::ShapeType givenShape(&dimensions[0],&dimensions[rank]);
559  return (getDataPointShape()==givenShape);
560  }
561 
566  int
567  getNoValues() const
568  {
569  return m_data->getNoValues();
570  }
571 
572 
577  void
578  dump(const std::string fileName) const;
579 
586  const boost::python::object
587  toListOfTuples(bool scalarastuple=true);
588 
589 
597  const DataTypes::real_t*
599 
600  const DataTypes::cplx_t*
602 
603 
613 
616 
617 
618 
625  const DataTypes::real_t*
626  getDataRO(DataTypes::real_t dummy=0) const;
627 
628  const DataTypes::cplx_t*
629  getDataRO(DataTypes::cplx_t dummy) const;
630 
631 
632 
639  inline
642  {
643  return m_data->getSampleDataByTag(tag, dummy);
644  }
645 
646  inline
649  {
650  return m_data->getSampleDataByTag(tag, dummy);
651  }
652 
653 
661  getDataPointRO(int sampleNo, int dataPointNo);
662 
670  getDataPointRW(int sampleNo, int dataPointNo);
671 
672 
673 
678  inline
680  getDataOffset(int sampleNo,
681  int dataPointNo)
682  {
683  return m_data->getPointOffset(sampleNo,dataPointNo);
684  }
685 
690  inline
691  const DataTypes::ShapeType&
693  {
694  return m_data->getShape();
695  }
696 
701  const boost::python::tuple
702  getShapeTuple() const;
703 
708  long
709  getShapeProduct() const;
710 
711 
717  int
718  getDataPointSize() const;
719 
725  getLength() const;
726 
731  bool
732  hasNoSamples() const
733  {
734  return m_data->getNumSamples()==0;
735  }
736 
745  void
746  setTaggedValueByName(std::string name,
747  const boost::python::object& value);
748 
758  void
759  setTaggedValue(int tagKey,
760  const boost::python::object& value);
761 
772  void
773  setTaggedValueFromCPP(int tagKey,
774  const DataTypes::ShapeType& pointshape,
775  const DataTypes::RealVectorType& value,
776  int dataOffset=0);
777 
778 
779  void
780  setTaggedValueFromCPP(int tagKey,
781  const DataTypes::ShapeType& pointshape,
782  const DataTypes::CplxVectorType& value,
783  int dataOffset=0);
784 
789  void
790  copyWithMask(const Data& other,
791  const Data& mask);
792 
802  void
803  setToZero();
804 
811  Data
812  interpolate(const FunctionSpace& functionspace) const;
813 
814  Data
816  DataTypes::real_t undef, Data& B, DataTypes::real_t Bmin, DataTypes::real_t Bstep, Data& C,
817  DataTypes::real_t Cmin, DataTypes::real_t Cstep, bool check_boundaries);
818 
819  Data
821  DataTypes::real_t undef, Data& B, DataTypes::real_t Bmin, DataTypes::real_t Bstep,bool check_boundaries);
822 
823  Data
825  DataTypes::real_t undef,bool check_boundaries);
826 
827 
828  Data
829  interpolateFromTable3DP(boost::python::object table, DataTypes::real_t Amin, DataTypes::real_t Astep,
830  Data& B, DataTypes::real_t Bmin, DataTypes::real_t Bstep, Data& C, DataTypes::real_t Cmin, DataTypes::real_t Cstep, DataTypes::real_t undef,bool check_boundaries);
831 
832 
833  Data
834  interpolateFromTable2DP(boost::python::object table, DataTypes::real_t Amin, DataTypes::real_t Astep,
835  Data& B, DataTypes::real_t Bmin, DataTypes::real_t Bstep, DataTypes::real_t undef,bool check_boundaries);
836 
837  Data
838  interpolateFromTable1DP(boost::python::object table, DataTypes::real_t Amin, DataTypes::real_t Astep,
839  DataTypes::real_t undef,bool check_boundaries);
840 
841  Data
842  nonuniforminterp(boost::python::object in, boost::python::object out, bool check_boundaries);
843 
844  Data
845  nonuniformslope(boost::python::object in, boost::python::object out, bool check_boundaries);
846 
853  Data
854  gradOn(const FunctionSpace& functionspace) const;
855 
856  Data
857  grad() const;
858 
863  boost::python::object
864  integrateToTuple_const() const;
865 
866 
871  boost::python::object
873 
874 
875 
881  Data
882  oneOver() const;
888  Data
889  wherePositive() const;
890 
896  Data
897  whereNegative() const;
898 
904  Data
905  whereNonNegative() const;
906 
912  Data
913  whereNonPositive() const;
914 
920  Data
921  whereZero(DataTypes::real_t tol=0.0) const;
922 
928  Data
929  whereNonZero(DataTypes::real_t tol=0.0) const;
930 
943  Lsup();
944 
946  Lsup_const() const;
947 
948 
961  sup();
962 
964  sup_const() const;
965 
966 
979  inf();
980 
982  inf_const() const;
983 
984 
985 
991  Data
992  abs() const;
993 
999  Data
1000  phase() const;
1001 
1002 
1008  Data
1009  maxval() const;
1010 
1016  Data
1017  minval() const;
1018 
1026  const boost::python::tuple
1027  minGlobalDataPoint() const;
1028 
1036  const boost::python::tuple
1037  maxGlobalDataPoint() const;
1038 
1039 
1040 
1047  Data
1048  sign() const;
1049 
1055  Data
1056  symmetric() const;
1057 
1063  Data
1064  antisymmetric() const;
1065 
1066 
1072  Data
1073  hermitian() const;
1074 
1080  Data
1081  antihermitian() const;
1082 
1088  Data
1089  trace(int axis_offset) const;
1090 
1096  Data
1097  transpose(int axis_offset) const;
1098 
1105  Data
1106  eigenvalues() const;
1107 
1117  const boost::python::tuple
1118  eigenvalues_and_eigenvectors(const DataTypes::real_t tol=1.e-12) const;
1119 
1125  Data
1126  swapaxes(const int axis0, const int axis1) const;
1127 
1133  Data
1134  erf() const;
1135 
1136 
1142  Data
1143  conjugate() const;
1144 
1145  Data
1146  real() const;
1147 
1148  Data
1149  imag() const;
1150 
1156  Data
1157  sin() const;
1158 
1164  Data
1165  cos() const;
1166 
1172  Data
1173  bessel(int order, DataTypes::real_t (*besselfunc) (int,DataTypes::real_t) );
1174 
1175 
1181  Data
1182  besselFirstKind(int order);
1183 
1189  Data
1190  besselSecondKind(int order);
1191 
1192 
1198  Data
1199  tan() const;
1200 
1206  Data
1207  asin() const;
1208 
1214  Data
1215  acos() const;
1216 
1222  Data
1223  atan() const;
1224 
1230  Data
1231  sinh() const;
1232 
1238  Data
1239  cosh() const;
1240 
1246  Data
1247  tanh() const;
1248 
1254  Data
1255  asinh() const;
1256 
1262  Data
1263  acosh() const;
1264 
1270  Data
1271  atanh() const;
1272 
1278  Data
1279  log10() const;
1280 
1286  Data
1287  log() const;
1288 
1294  Data
1295  exp() const;
1296 
1302  Data
1303  sqrt() const;
1304 
1310  Data
1311  neg() const;
1312 
1319  Data
1320  pos() const;
1321 
1329  Data
1330  powD(const Data& right) const;
1331 
1339  Data
1340  powO(const boost::python::object& right) const;
1341 
1350  Data
1351  rpowO(const boost::python::object& left) const;
1352 
1359  Data& operator+=(const Data& right);
1360  Data& operator+=(const boost::python::object& right);
1361 
1362  Data& operator=(const Data& other);
1363 
1370  Data& operator-=(const Data& right);
1371  Data& operator-=(const boost::python::object& right);
1372 
1379  Data& operator*=(const Data& right);
1380  Data& operator*=(const boost::python::object& right);
1381 
1388  Data& operator/=(const Data& right);
1389  Data& operator/=(const boost::python::object& right);
1390 
1395  Data truedivD(const Data& right);
1396 
1401  Data truedivO(const boost::python::object& right);
1402 
1407  Data rtruedivO(const boost::python::object& left);
1408 
1413  boost::python::object __add__(const boost::python::object& right);
1414 
1415 
1420  boost::python::object __sub__(const boost::python::object& right);
1421 
1426  boost::python::object __rsub__(const boost::python::object& right);
1427 
1432  boost::python::object __mul__(const boost::python::object& right);
1433 
1438  boost::python::object __div__(const boost::python::object& right);
1439 
1444  boost::python::object __rdiv__(const boost::python::object& right);
1445 
1449  Data
1450  matrixInverse() const;
1451 
1456  bool
1457  probeInterpolation(const FunctionSpace& functionspace) const;
1458 
1474  Data
1475  getItem(const boost::python::object& key) const;
1476 
1488  void
1489  setItemD(const boost::python::object& key,
1490  const Data& value);
1491 
1492  void
1493  setItemO(const boost::python::object& key,
1494  const boost::python::object& value);
1495 
1496  // These following public methods should be treated as private.
1497 
1503  template <class UnaryFunction>
1504  inline
1505  void
1506  unaryOp2(UnaryFunction operation);
1507 
1515  Data
1516  getSlice(const DataTypes::RegionType& region) const;
1517 
1526  void
1527  setSlice(const Data& value,
1528  const DataTypes::RegionType& region);
1529 
1534  void
1535  print(void);
1536 
1543  int
1544  get_MPIRank(void) const;
1545 
1552  int
1553  get_MPISize(void) const;
1554 
1560  MPI_Comm
1561  get_MPIComm(void) const;
1562 
1568  DataAbstract*
1569  borrowData(void) const;
1570 
1572  borrowDataPtr(void) const;
1573 
1575  borrowReadyPtr(void) const;
1576 
1577 
1578 
1588 
1591 
1594 
1597 
1598 
1610 
1613 
1614 
1619  size_t
1620  getNumberOfTaggedValues() const;
1621 
1622  /*
1623  * \brief make the data complex
1624  */
1625  void complicate();
1626 
1627  protected:
1628 
1629  private:
1630  void init_from_data_and_fs(const Data& inData,
1631  const FunctionSpace& functionspace);
1632 
1633  template <typename S>
1634  void
1635  maskWorker(Data& other2, Data& mask2, S sentinel);
1636 
1637  template <class BinaryOp>
1639 #ifdef ESYS_MPI
1640  lazyAlgWorker(DataTypes::real_t init, MPI_Op mpiop_type);
1641 #else
1643 #endif
1644 
1646  LsupWorker() const;
1647 
1649  supWorker() const;
1650 
1652  infWorker() const;
1653 
1654  template<typename Scalar>
1655  boost::python::object
1656  integrateWorker() const;
1657 
1658  void
1659  calc_minGlobalDataPoint(int& ProcNo, int& DataPointNo) const;
1660 
1661  void
1662  calc_maxGlobalDataPoint(int& ProcNo, int& DataPointNo) const;
1663 
1664  // For internal use in Data.cpp only!
1665  // other uses should call the main entry points and allow laziness
1666  Data
1667  minval_nonlazy() const;
1668 
1669  // For internal use in Data.cpp only!
1670  Data
1671  maxval_nonlazy() const;
1672 
1673 
1680  inline
1681  void
1682  operandCheck(const Data& right) const
1683  {
1684  return m_data->operandCheck(*(right.m_data.get()));
1685  }
1686 
1692  template <class BinaryFunction>
1693  inline
1695  reduction(BinaryFunction operation,
1696  DataTypes::real_t initial_value) const;
1697 
1705  template <class BinaryFunction>
1706  inline
1707  Data
1708  dp_algorithm(BinaryFunction operation,
1709  DataTypes::real_t initial_value) const;
1710 
1716  void
1717  typeMatchLeft(Data& right) const;
1718 
1724  void
1725  typeMatchRight(const Data& right);
1726 
1732  void
1734  const DataTypes::ShapeType& shape,
1735  const FunctionSpace& what,
1736  bool expanded);
1737 
1738  void
1740  const DataTypes::ShapeType& shape,
1741  const FunctionSpace& what,
1742  bool expanded);
1743 
1744  void
1745  initialise(const WrappedArray& value,
1746  const FunctionSpace& what,
1747  bool expanded);
1748 
1749  void
1750  initialise(const DataTypes::real_t value,
1751  const DataTypes::ShapeType& shape,
1752  const FunctionSpace& what,
1753  bool expanded);
1754 
1755  void
1756  initialise(const DataTypes::cplx_t value,
1757  const DataTypes::ShapeType& shape,
1758  const FunctionSpace& what,
1759  bool expanded);
1760  //
1761  // flag to protect the data object against any update
1763  bool m_lazy;
1764 
1765  //
1766  // pointer to the actual data object
1767 // boost::shared_ptr<DataAbstract> m_data;
1769 
1770 // If possible please use getReadyPtr instead.
1771 // But see warning below.
1772  const DataReady*
1773  getReady() const
1774 {
1775  const DataReady* dr=dynamic_cast<const DataReady*>(m_data.get());
1776  ESYS_ASSERT(dr!=0, "error casting to DataReady.");
1777  return dr;
1778 }
1779 
1780  DataReady*
1782 {
1783  DataReady* dr=dynamic_cast<DataReady*>(m_data.get());
1784  ESYS_ASSERT(dr!=0, "error casting to DataReady.");
1785  return dr;
1786 }
1787 
1788 
1789 // Be wary of using this for local operations since it (temporarily) increases reference count.
1790 // If you are just using this to call a method on DataReady instead of DataAbstract consider using
1791 // getReady() instead
1794 {
1795  DataReady_ptr dr=REFCOUNTNS::dynamic_pointer_cast<DataReady>(m_data);
1796  ESYS_ASSERT(dr.get()!=0, "error casting to DataReady.");
1797  return dr;
1798 }
1799 
1801  getReadyPtr() const
1802 {
1803  const_DataReady_ptr dr=REFCOUNTNS::dynamic_pointer_cast<const DataReady>(m_data);
1804  ESYS_ASSERT(dr.get()!=0, "error casting to DataReady.");
1805  return dr;
1806 }
1807 
1808  // In the isShared() method below:
1809  // A problem would occur if m_data (the address pointed to) were being modified
1810  // while the call m_data->is_shared is being executed.
1811  //
1812  // Q: So why do I think this code can be thread safe/correct?
1813  // A: We need to make some assumptions.
1814  // 1. We assume it is acceptable to return true under some conditions when we aren't shared.
1815  // 2. We assume that no constructions or assignments which will share previously unshared
1816  // will occur while this call is executing. This is consistent with the way Data:: and C are written.
1817  //
1818  // This means that the only transition we need to consider, is when a previously shared object is
1819  // not shared anymore. ie. the other objects have been destroyed or a deep copy has been made.
1820  // In those cases the m_shared flag changes to false after m_data has completed changing.
1821  // For any threads executing before the flag switches they will assume the object is still shared.
1822  bool isShared() const
1823  {
1824 #ifdef SLOWSHARECHECK
1825  return m_data->isShared(); // single threadsafe check for this
1826 #else
1827  return !m_data.unique();
1828 #endif
1829  }
1830 
1832  {
1833  if (isLazy())
1834  {
1835  #ifdef _OPENMP
1836  if (omp_in_parallel())
1837  { // Yes this is throwing an exception out of an omp thread which is forbidden.
1838  throw DataException("Please do not call forceResolve() in a parallel region.");
1839  }
1840  #endif
1841  resolve();
1842  }
1843  }
1844 
1850  {
1851 #ifdef _OPENMP
1852  if (omp_in_parallel())
1853  {
1854  throw DataException("Programming error. Please do not run exclusiveWrite() in multi-threaded sections.");
1855  }
1856 #endif
1857  forceResolve();
1858  if (isShared())
1859  {
1860  DataAbstract* t=m_data->deepCopy();
1862  }
1863 #ifdef EXWRITECHK
1864  m_data->exclusivewritecalled=true;
1865 #endif
1866  }
1867 
1872  {
1873  if (isLazy() || isShared())
1874  {
1875  std::ostringstream oss;
1876  oss << "Programming error. ExclusiveWrite required - please call requireWrite() isLazy=" << isLazy() << " isShared()=" << isShared();
1877  throw DataException(oss.str());
1878  }
1879  }
1880 
1887  void set_m_data(DataAbstract_ptr p);
1888 
1889 
1890  void TensorSelfUpdateBinaryOperation(const Data& right, escript::ES_optype operation);
1891 
1892  friend class DataAbstract; // To allow calls to updateShareStatus
1893  friend class TestDomain; // so its getX will work quickly
1894 #ifdef IKNOWWHATIMDOING
1895  friend Data applyBinaryCFunction(boost::python::object cfunc, boost::python::tuple shape, escript::Data& d, escript::Data& e);
1896 #endif
1897  template <typename S>
1898  friend Data condEvalWorker(escript::Data& mask, escript::Data& trueval, escript::Data& falseval, S sentinel);
1899  friend Data randomData(const boost::python::tuple& shape, const FunctionSpace& what, long seed, const boost::python::tuple& filter);
1900 
1901 };
1902 
1903 
1904 #ifdef IKNOWWHATIMDOING
1905 Data
1906 applyBinaryCFunction(boost::python::object func, boost::python::tuple shape, escript::Data& d, escript::Data& e);
1907 #endif
1908 
1909 Data
1910 condEval(escript::Data& mask, escript::Data& trueval, escript::Data& falseval);
1911 
1912 
1913 
1917 Data randomData(const boost::python::tuple& shape,
1918  const FunctionSpace& what,
1919  long seed, const boost::python::tuple& filter);
1920 
1921 
1922 } // end namespace escript
1923 
1924 
1925 // No, this is not supposed to be at the top of the file
1926 // DataAbstact needs to be declared first, then DataReady needs to be fully declared
1927 // so that I can dynamic cast between them below.
1928 #include "DataReady.h"
1929 #include "DataLazy.h"
1930 #include "DataExpanded.h"
1931 #include "DataConstant.h"
1932 #include "DataTagged.h"
1933 
1934 namespace escript
1935 {
1936 
1937 
1938 
1939 inline
1942 {
1943  if (isLazy())
1944  {
1945  throw DataException("Error, attempt to acquire RW access to lazy data. Please call requireWrite() first.");
1946  }
1947 #ifdef EXWRITECHK
1948  if (!getReady()->exclusivewritecalled)
1949  {
1950  throw DataException("Error, call to Data::getSampleDataRW without a preceeding call to requireWrite/exclusiveWrite.");
1951  }
1952 #endif
1953  return getReady()->getSampleDataRW(sampleNo, dummy);
1954 }
1955 
1956 inline
1959 {
1960  if (isLazy())
1961  {
1962  throw DataException("Error, attempt to acquire RW access to lazy data. Please call requireWrite() first.");
1963  }
1964 #ifdef EXWRITECHK
1965  if (!getReady()->exclusivewritecalled)
1966  {
1967  throw DataException("Error, call to Data::getSampleDataRW without a preceeding call to requireWrite/exclusiveWrite.");
1968  }
1969 #endif
1970  return getReady()->getSampleDataRW(sampleNo, dummy);
1971 }
1972 
1973 
1974 inline
1975 const DataTypes::real_t*
1977 {
1978  DataLazy* l=dynamic_cast<DataLazy*>(m_data.get());
1979  if (l!=0)
1980  {
1981  size_t offset=0;
1982  const DataTypes::RealVectorType* res=l->resolveSample(sampleNo,offset);
1983  return &((*res)[offset]);
1984  }
1985  return getReady()->getSampleDataRO(sampleNo, dummy);
1986 }
1987 
1988 inline
1989 const DataTypes::cplx_t*
1991 {
1992  DataLazy* l=dynamic_cast<DataLazy*>(m_data.get());
1993  if (l!=0)
1994  {
1995  throw DataException("Programming error: complex lazy objects are not supported.");
1996  }
1997  return getReady()->getSampleDataRO(sampleNo, dummy);
1998 }
1999 
2000 
2001 inline
2002 const DataTypes::real_t*
2004 {
2005  if (isLazy())
2006  {
2007  throw DataException("Programmer error - getDataRO must not be called on Lazy Data.");
2008  }
2009  if (getNumSamples()==0)
2010  {
2011  return 0;
2012  }
2013  else
2014  {
2015  return &(getReady()->getTypedVectorRO(0)[0]);
2016  }
2017 }
2018 
2019 inline
2020 const DataTypes::cplx_t*
2022 {
2023  if (isLazy())
2024  {
2025  throw DataException("Programmer error - getDataRO must not be called on Lazy Data.");
2026  }
2027  if (getNumSamples()==0)
2028  {
2029  return 0;
2030  }
2031  else
2032  {
2033  return &(getReady()->getTypedVectorRO(dummy)[0]);
2034  }
2035 }
2036 
2037 
2042 {
2043  return pow(y,x);
2044 }
2045 
2051 Data operator+(const Data& left, const Data& right);
2052 
2058 Data operator-(const Data& left, const Data& right);
2059 
2065 Data operator*(const Data& left, const Data& right);
2066 
2072 Data operator/(const Data& left, const Data& right);
2073 
2080 Data operator+(const Data& left, const boost::python::object& right);
2081 
2088 Data operator-(const Data& left, const boost::python::object& right);
2089 
2096 Data operator*(const Data& left, const boost::python::object& right);
2097 
2104 Data operator/(const Data& left, const boost::python::object& right);
2105 
2112 Data operator+(const boost::python::object& left, const Data& right);
2113 
2120 Data operator-(const boost::python::object& left, const Data& right);
2121 
2128 Data operator*(const boost::python::object& left, const Data& right);
2129 
2136 Data operator/(const boost::python::object& left, const Data& right);
2137 
2138 
2139 
2144 std::ostream& operator<<(std::ostream& o, const Data& data);
2145 
2154 Data
2156  Data& arg_1,
2157  int axis_offset=0,
2158  int transpose=0);
2159 
2165 inline
2166 Data
2167 Data::truedivD(const Data& right)
2168 {
2169  return *this / right;
2170 }
2171 
2177 inline
2178 Data
2179 Data::truedivO(const boost::python::object& right)
2180 {
2181  Data tmp(right, getFunctionSpace(), false);
2182  return truedivD(tmp);
2183 }
2184 
2190 inline
2191 Data
2192 Data::rtruedivO(const boost::python::object& left)
2193 {
2194  Data tmp(left, getFunctionSpace(), false);
2195  return tmp.truedivD(*this);
2196 }
2197 
2198 
2199 
2207 template <class BinaryFunction>
2208 inline
2210 Data::reduction(BinaryFunction operation, DataTypes::real_t initial_value) const
2211 {
2212  if (isExpanded()) {
2213  DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
2214  ESYS_ASSERT(leftC!=0, "Programming error - casting to DataExpanded.");
2215 
2216  DataExpanded& data=*leftC;
2217  int i,j;
2218  int numDPPSample=data.getNumDPPSample();
2219  int numSamples=data.getNumSamples();
2220  DataTypes::real_t global_current_value=initial_value;
2221  DataTypes::real_t local_current_value;
2222  const auto& vec=data.getTypedVectorRO(typename BinaryFunction::first_argument_type(0));
2223  const DataTypes::ShapeType& shape=data.getShape();
2224  // calculate the reduction operation value for each data point
2225  // reducing the result for each data-point into the current_value variables
2226  #pragma omp parallel private(local_current_value)
2227  {
2228  local_current_value=initial_value;
2229  #pragma omp for private(i,j) schedule(static)
2230  for (i=0;i<numSamples;i++) {
2231  for (j=0;j<numDPPSample;j++) {
2232  local_current_value=operation(local_current_value,escript::reductionOpVector(vec,shape,data.getPointOffset(i,j),operation,initial_value));
2233 
2234  }
2235  }
2236  #pragma omp critical
2237  global_current_value=operation(global_current_value,local_current_value);
2238  }
2239  return global_current_value;
2240  } else if (isTagged()) {
2241  DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
2242  ESYS_ASSERT(leftC!=0, "Programming error - casting to DataTagged.");
2243 
2244  DataTagged& data=*leftC;
2245  DataTypes::real_t current_value=initial_value;
2246 
2247  const auto& vec=data.getTypedVectorRO(typename BinaryFunction::first_argument_type(0));
2248  const DataTypes::ShapeType& shape=data.getShape();
2249  const DataTagged::DataMapType& lookup=data.getTagLookup();
2250  const std::list<int> used=data.getFunctionSpace().getListOfTagsSTL();
2251  for (std::list<int>::const_iterator i=used.begin();i!=used.end();++i)
2252  {
2253  int tag=*i;
2254  DataTagged::DataMapType::const_iterator it=lookup.find(tag);
2255  if ((tag==0) || (it==lookup.end())) // check for the default tag
2256  {
2257  current_value=operation(current_value,escript::reductionOpVector(vec,shape,data.getDefaultOffset(),operation,initial_value));
2258  }
2259  else
2260  {
2261  current_value=operation(current_value,escript::reductionOpVector(vec,shape,it->second,operation,initial_value));
2262  }
2263  }
2264  return current_value;
2265  } else if (isConstant()) {
2266  DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
2267  ESYS_ASSERT(leftC!=0, "Programming error - casting to DataConstant.");
2268  return escript::reductionOpVector(leftC->getTypedVectorRO(typename BinaryFunction::first_argument_type(0)),leftC->getShape(),0,operation,initial_value);
2269  } else if (isEmpty()) {
2270  throw DataException("Error - Operations (algorithm) not permitted on instances of DataEmpty.");
2271  } else if (isLazy()) {
2272  throw DataException("Error - Operations not permitted on instances of DataLazy.");
2273  } else {
2274  throw DataException("Error - Data encapsulates an unknown type.");
2275  }
2276 }
2277 
2286 template <class BinaryFunction>
2287 inline
2288 Data
2289 Data::dp_algorithm(BinaryFunction operation, DataTypes::real_t initial_value) const
2290 {
2291  if (isEmpty()) {
2292  throw DataException("Error - Operations (dp_algorithm) not permitted on instances of DataEmpty.");
2293  }
2294  else if (isExpanded()) {
2296  DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
2297  DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
2298  ESYS_ASSERT(dataE!=0, "Programming error - casting data to DataExpanded.");
2299  ESYS_ASSERT(resultE!=0, "Programming error - casting result to DataExpanded.");
2300 
2301 
2302 
2303  int i,j;
2304  int numSamples=dataE->getNumSamples();
2305  int numDPPSample=dataE->getNumDPPSample();
2306  // DataArrayView dataView=data.getPointDataView();
2307  // DataArrayView resultView=result.getPointDataView();
2308  const auto& dataVec=dataE->getTypedVectorRO(initial_value);
2309  const DataTypes::ShapeType& shape=dataE->getShape();
2310  auto& resultVec=resultE->getTypedVectorRW(initial_value);
2311  // perform the operation on each data-point and assign
2312  // this to the corresponding element in result
2313  #pragma omp parallel for private(i,j) schedule(static)
2314  for (i=0;i<numSamples;i++) {
2315  for (j=0;j<numDPPSample;j++) {
2316  resultVec[resultE->getPointOffset(i,j)] =
2317  escript::reductionOpVector(dataVec, shape, dataE->getPointOffset(i,j),operation,initial_value);
2318 
2319  }
2320  }
2321  //escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
2322  return result;
2323  }
2324  else if (isTagged()) {
2325  DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
2326  ESYS_ASSERT(dataT!=0, "Programming error - casting data to DataTagged.");
2327  DataTypes::RealVectorType defval(1);
2328  defval[0]=0;
2329  DataTagged* resultT=new DataTagged(getFunctionSpace(), DataTypes::scalarShape, defval, dataT);
2330 
2331 
2332  const DataTypes::ShapeType& shape=dataT->getShape();
2333  const auto& vec=dataT->getTypedVectorRO(initial_value);
2334  const DataTagged::DataMapType& lookup=dataT->getTagLookup();
2335  for (DataTagged::DataMapType::const_iterator i=lookup.begin(); i!=lookup.end(); i++) {
2336  resultT->getDataByTagRW(i->first,0) =
2337  escript::reductionOpVector(vec,shape,dataT->getOffsetForTag(i->first),operation,initial_value);
2338  }
2339  resultT->getTypedVectorRW(initial_value)[resultT->getDefaultOffset()] = escript::reductionOpVector(dataT->getTypedVectorRO(initial_value),dataT->getShape(),dataT->getDefaultOffset(),operation,initial_value);
2340 
2341 
2342 
2343 
2344  //escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
2345  return Data(resultT); // note: the Data object now owns the resultT pointer
2346  }
2347  else if (isConstant()) {
2349  DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
2350  DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
2351  ESYS_ASSERT(dataC!=0, "Programming error - casting data to DataConstant.");
2352  ESYS_ASSERT(resultC!=0, "Programming error - casting result to DataConstant.");
2353 
2354  DataConstant& data=*dataC;
2355  resultC->getTypedVectorRW(initial_value)[0] =
2356  escript::reductionOpVector(data.getTypedVectorRO(initial_value),data.getShape(),0,operation,initial_value);
2357 
2358  //escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
2359  return result;
2360  } else if (isLazy()) {
2361  throw DataException("Error - Operations not permitted on instances of DataLazy.");
2362  } else {
2363  throw DataException("Error - Data encapsulates an unknown type.");
2364  }
2365 }
2366 
2367 
2375 Data
2376 C_TensorBinaryOperation(Data const &arg_0,
2377  Data const &arg_1,
2378  ES_optype operation);
2379 
2380 
2381 Data
2382 C_TensorUnaryOperation(Data const &arg_0,
2383  escript::ES_optype operation,
2384  DataTypes::real_t tol=0);
2385 
2386 } // namespace escript
2387 
2388 #endif // __ESCRIPT_DATA_H__
2389 
Definition: FunctionSpace.h:34
std::ostream & operator<<(std::ostream &o, const Data &data)
Output operator.
Definition: Data.cpp:3686
void typeMatchLeft(Data &right) const
Convert the data type of the RHS to match this.
Definition: Data.cpp:3532
DataAbstract_ptr m_data
Definition: Data.h:1768
DataTypes::RealVectorType::size_type getLength() const
Return the number of doubles stored for this Data.
Definition: Data.cpp:1370
const boost::python::object toListOfTuples(bool scalarastuple=true)
returns the values of the object as a list of tuples (one for each datapoint).
Definition: Data.cpp:1381
DataTypes::real_t * getSampleDataByTag(int tag, DataTypes::real_t dummy=0)
Return the sample data for the given tag. If an attempt is made to access data that isn&#39;t tagged an e...
Definition: Data.h:641
Data sqrt() const
Return the square root of each data point of this Data object.
Definition: Data.cpp:2201
void setItemO(const boost::python::object &key, const boost::python::object &value)
Definition: Data.cpp:3493
Data antihermitian() const
Return the anti-hermitian part of a matrix which is half the matrix minus its hermitian.
Definition: Data.cpp:2811
Data interpolateFromTable1D(const WrappedArray &table, DataTypes::real_t Amin, DataTypes::real_t Astep, DataTypes::real_t undef, bool check_boundaries)
Definition: Data.cpp:4768
boost::python::object __add__(const boost::python::object &right)
wrapper for python add operation
Definition: Data.cpp:5915
const_DataReady_ptr getReadyPtr() const
Definition: Data.h:1801
void checkExclusiveWrite()
checks if caller can have exclusive write to the object
Definition: Data.h:1871
boost::python::object __rsub__(const boost::python::object &right)
wrapper for python reverse subtract operation
Definition: Data.cpp:5963
std::string toString() const
Write the data as a string. For large amounts of data, a summary is printed.
Definition: Data.cpp:4646
void setToZero()
set all values to zero
Definition: Data.cpp:818
DataTypes::real_t rpow(DataTypes::real_t x, DataTypes::real_t y)
Definition: Data.h:2041
ElementType & reference
Definition: DataVectorAlt.h:50
DataTypes::real_t inf()
Return the minimum value of this Data object.
Definition: Data.cpp:2306
void replaceNaN(DataTypes::real_t value)
replaces all NaN values with value
Definition: Data.cpp:2403
unsigned int getDataPointRank() const
Return the rank of the point data.
Definition: Data.h:499
int MPI_Op
Definition: EsysMPI.h:43
bool hasInf()
Definition: Data.cpp:2437
Data delay()
produce a delayed evaluation version of this Data.
Definition: Data.cpp:789
Data & operator*=(const Data &right)
Overloaded operator *=.
Definition: Data.cpp:3240
void tag()
If possible convert this Data to DataTagged. This will only allow Constant data to be converted to ta...
Definition: Data.cpp:1207
bool isDataPointShapeEqual(int rank, const int *dimensions) const
Returns true if the shape matches the vector (dimensions[0],..., dimensions[rank-1]). DataEmpty always returns true.
Definition: Data.h:554
void set_m_data(DataAbstract_ptr p)
Modify the data abstract hosted by this Data object For internal use only. Passing a pointer to null ...
Definition: Data.cpp:612
virtual DataTypes::RealVectorType & getTypedVectorRW(DataTypes::real_t dummy)
These versions use the type system rather than method name to determine return type.
Definition: DataExpanded.cpp:1525
boost::python::object integrateToTuple()
Calculate the integral over the function space domain as a python tuple.
Definition: Data.cpp:1787
Data getSlice(const DataTypes::RegionType &region) const
Return a Data object containing the specified slice of this Data object.
Definition: Data.cpp:3485
DataTypes::real_t supWorker() const
Definition: Data.cpp:2540
boost::shared_ptr< AbstractDomain > Domain_ptr
Definition: AbstractDomain.h:36
Data sign() const
Return the sign of each data point of this Data object. -1 for negative values, zero for zero values...
Definition: Data.cpp:2160
Definition: DataReady.h:35
DataTypes::vec_size_type size_type
Definition: DataVectorAlt.h:49
std::vector< std::pair< int, int > > RegionType
Definition: DataTypes.h:43
int getDataPointSize() const
Return the size of the data point. It is the product of the data point shape dimensions.
Definition: Data.cpp:1363
Definition: AbstractContinuousDomain.cpp:22
Data imag() const
Definition: Data.cpp:2006
Data atan() const
Return the atan of each data point of this Data object.
Definition: Data.cpp:2085
Data log10() const
Return the log to base 10 of each data point of this Data object.
Definition: Data.cpp:2146
Data pos() const
Return the identity of each data point of this Data object. Simply returns this object unmodified...
Definition: Data.cpp:2182
boost::shared_ptr< const DataReady > const_DataReady_ptr
Definition: DataAbstract.h:59
void setItemD(const boost::python::object &key, const Data &value)
Copies slice from value into this Data object.
Definition: Data.cpp:3501
Data operator-(const Data &left, const Data &right)
Operator- Takes two Data objects.
Definition: Data.cpp:3362
void replaceInfPython(boost::python::object obj)
Definition: Data.cpp:2468
MPI_Comm get_MPIComm(void) const
return the MPI rank number of the local data MPI_COMM_WORLD is assumed and returned.
Definition: Data.cpp:5466
DataTypes::real_t sup_const() const
Definition: Data.cpp:2253
Data besselSecondKind(int order)
Return the Bessel function of the second kind for each data point of this Data object.
Definition: Data.cpp:1867
void print(void)
print the data values to stdout. Used for debugging
Definition: Data.cpp:5390
Data interpolateFromTable3DP(boost::python::object table, DataTypes::real_t Amin, DataTypes::real_t Astep, Data &B, DataTypes::real_t Bmin, DataTypes::real_t Bstep, Data &C, DataTypes::real_t Cmin, DataTypes::real_t Cstep, DataTypes::real_t undef, bool check_boundaries)
Definition: Data.cpp:4740
void typeMatchRight(const Data &right)
Convert the data type of this to match the RHS.
Definition: Data.cpp:3552
void setSlice(const Data &value, const DataTypes::RegionType &region)
Copy the specified slice from the given value into this Data object.
Definition: Data.cpp:3517
DataConstant stores a single data point which represents the entire function space.
Definition: DataConstant.h:37
static const ShapeType scalarShape
Use this instead of creating empty shape objects for scalars.
Definition: DataTypes.h:46
void setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object &py_object)
sets the values of a data-point from a python object on this process
Definition: Data.cpp:1562
DataTypes::RealVectorType::const_reference getDataPointRO(int sampleNo, int dataPointNo)
Return a reference into the DataVector which points to the specified data point.
Definition: Data.cpp:4716
long getShapeProduct() const
Returns the product of the data point shapes.
Definition: Data.cpp:748
bool isLazy() const
Return true if this Data is lazy.
Definition: Data.cpp:1149
Data C_TensorUnaryOperation(Data const &arg_0, escript::ES_optype operation, DataTypes::real_t tol=0)
Definition: Data.cpp:6082
DataAbstract_ptr borrowDataPtr(void) const
Definition: Data.cpp:4631
Data real() const
Definition: Data.cpp:1987
virtual const DataTypes::RealVectorType & getTypedVectorRO(DataTypes::real_t dummy) const
Definition: DataConstant.cpp:871
void setTaggedValueByName(std::string name, const boost::python::object &value)
Assign the given value to the tag assocciated with name. Implicitly converts this object to type Data...
Definition: Data.cpp:3580
Give a short description of what DataExpanded does.
Definition: DataExpanded.h:43
virtual const DataTypes::RealVectorType & getTypedVectorRO(DataTypes::real_t dummy) const
Definition: DataTagged.cpp:1675
Data sinh() const
Return the sinh of each data point of this Data object.
Definition: Data.cpp:2092
Data atanh() const
Return the atanh of each data point of this Data object.
Definition: Data.cpp:2139
DataReady_ptr getReadyPtr()
Definition: Data.h:1793
void TensorSelfUpdateBinaryOperation(const Data &right, escript::ES_optype operation)
Definition: Data.cpp:6534
DataTypes::RealVectorType::reference getDataByTagRW(int tag, DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0)
getDataByTag
Definition: DataTagged.cpp:1016
const_Domain_ptr getDomain() const
Returns the function space domain.
Definition: FunctionSpace.cpp:102
Data rpowO(const boost::python::object &left) const
Return the given power of each data point of this boost python object.
Definition: Data.cpp:3326
friend Data randomData(const boost::python::tuple &shape, const FunctionSpace &what, long seed, const boost::python::tuple &filter)
Create a new Expanded Data object filled with pseudo-random data.
DataTypes::real_t lazyAlgWorker(DataTypes::real_t init)
Data interpolateFromTable1DP(boost::python::object table, DataTypes::real_t Amin, DataTypes::real_t Astep, DataTypes::real_t undef, bool check_boundaries)
Definition: Data.cpp:4759
std::list< int > getListOfTagsSTL() const
Returns an stl list of the tags used in this function space.
Definition: FunctionSpace.cpp:286
(Testing use only) Provides a domain to wrap a collection of values.
Definition: TestDomain.h:41
void setTaggedValueFromCPP(int tagKey, const DataTypes::ShapeType &pointshape, const DataTypes::RealVectorType &value, int dataOffset=0)
Assign the given value to the tag. Implicitly converts this object to type DataTagged if it is consta...
Definition: Data.cpp:3637
Data nonuniformslope(boost::python::object in, boost::python::object out, bool check_boundaries)
Definition: Data.cpp:5311
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:42
boost::python::object __sub__(const boost::python::object &right)
wrapper for python subtract operation
Definition: Data.cpp:5939
Data interpolateFromTable2DP(boost::python::object table, DataTypes::real_t Amin, DataTypes::real_t Astep, Data &B, DataTypes::real_t Bmin, DataTypes::real_t Bstep, DataTypes::real_t undef, bool check_boundaries)
Definition: Data.cpp:4750
Data acos() const
Return the acos of each data point of this Data object.
Definition: Data.cpp:2077
Simulates a full dataset accessible via sampleNo and dataPointNo.
Definition: DataTagged.h:44
bool probeInterpolation(const FunctionSpace &functionspace) const
Returns true if this can be interpolated to functionspace.
Definition: Data.cpp:1320
boost::shared_ptr< DataAbstract > DataAbstract_ptr
Definition: DataAbstract.h:51
Data phase() const
Return the phase/arg/angular-part of complex values.
Definition: Data.cpp:2026
DataTypes::real_t * getSampleDataRW(DataTypes::RealVectorType::size_type sampleNo, DataTypes::real_t dummy=0)
Return the sample data for the given sample number.
Definition: DataReady.h:203
Data getItem(const boost::python::object &key) const
Returns a slice from this Data object.
Definition: Data.cpp:3471
void initialise(const DataTypes::RealVectorType &value, const DataTypes::ShapeType &shape, const FunctionSpace &what, bool expanded)
Construct a Data object of the appropriate type.
Definition: Data.cpp:641
Data maxval() const
Return the maximum value of each data point of this Data object.
Definition: Data.cpp:2650
void setValueOfDataPointC(int dataPointNo, const DataTypes::cplx_t)
Definition: Data.cpp:1679
Data cos() const
Return the cos of each data point of this Data object.
Definition: Data.cpp:2056
const DataTypes::real_t * getDataRO(DataTypes::real_t dummy=0) const
Return a pointer to the beginning of the underlying data.
Definition: Data.h:2003
Data C_GeneralTensorProduct(Data &arg_0, Data &arg_1, int axis_offset=0, int transpose=0)
Compute a tensor product of two Data objects.
Definition: Data.cpp:3693
DataTypes::RealVectorType::const_reference getDataAtOffsetRO(DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy)
Return a pointer to the beginning of the datapoint at the specified offset. TODO Eventually these sho...
Definition: Data.cpp:4693
bool m_protected
Definition: Data.h:1762
Data cosh() const
Return the cosh of each data point of this Data object.
Definition: Data.cpp:2099
void setValueOfDataPoint(int dataPointNo, const DataTypes::real_t)
sets the values of a data-point on this process
Definition: Data.cpp:1658
Data interpolate(const FunctionSpace &functionspace) const
Interpolates this onto the given functionspace and returns the result as a Data object.
Definition: Data.cpp:1314
Data matrixInverse() const
return inverse of matricies.
Definition: Data.cpp:3298
Data & operator/=(const Data &right)
Overloaded operator /=.
Definition: Data.cpp:3267
DataReady * getReady()
Definition: Data.h:1781
Data copySelf() const
Return a pointer to a deep copy of this object.
Definition: Data.cpp:773
void resolve()
If this data is lazy, then convert it to ready data. What type of ready data depends on the expressio...
Definition: Data.cpp:1233
bool isEmpty() const
Return true if this Data holds an instance of DataEmpty. This is _not_ the same as asking if the obj...
Definition: Data.cpp:1135
Data tanh() const
Return the tanh of each data point of this Data object.
Definition: Data.cpp:2106
void calc_minGlobalDataPoint(int &ProcNo, int &DataPointNo) const
Definition: Data.cpp:3000
void operandCheck(const Data &right) const
Check *this and the right operand are compatible. Throws an exception if they aren&#39;t.
Definition: Data.h:1682
DataAbstract * borrowData(void) const
return the object produced by the factory, which is a DataConstant or DataExpanded TODO Ownership of ...
Definition: Data.cpp:4624
Data erf() const
Return the error function erf of each data point of this Data object.
Definition: Data.cpp:2114
const DataTypes::ShapeType & getShape() const
Return the shape information for the point data.
Definition: DataAbstract.h:641
int getNumSamples() const
Return the number of samples.
Definition: DataAbstract.h:622
int getNumDPPSample() const
Return the number of data points per sample.
Definition: DataAbstract.h:611
DataTypes::real_t infWorker() const
Definition: Data.cpp:2583
int getNoValues() const
Return the number of values in the shape for this object.
Definition: Data.h:567
Describes binary operations performed on DataVector.
virtual DataTypes::RealVectorType::size_type getPointOffset(int sampleNo, int dataPointNo) const
Return the offset for the given given data point. This returns the offset in bytes for the given poin...
Definition: DataExpanded.cpp:621
boost::python::object integrateWorker() const
Data rtruedivO(const boost::python::object &left)
Newer style division operator for python.
Definition: Data.h:2192
const boost::python::tuple maxGlobalDataPoint() const
Return the (sample number, data-point number) of the data point with the minimum component value in t...
Definition: Data.cpp:3086
const DataTypes::real_t * getSampleDataRO(DataTypes::RealVectorType::size_type sampleNo, DataTypes::real_t dummy=0) const
Return the sample data for the given sample no. Please do not use this unless you NEED to access samp...
Definition: Data.h:1976
std::map< int, int > DataMapType
Definition: DataTagged.h:57
Data powD(const Data &right) const
Return the given power of each data point of this Data object.
Definition: Data.cpp:3340
void replaceNaNPython(boost::python::object obj)
replaces all NaN values with value
Definition: Data.cpp:2423
Data trace(int axis_offset) const
Return the trace of a matrix.
Definition: Data.cpp:2851
DataTypes::RealVectorType::size_type getOffsetForTag(int tag) const
getOffsetForTag
Definition: DataTagged.cpp:994
const boost::python::tuple minGlobalDataPoint() const
Return the (sample number, data-point number) of the data point with the minimum component value in t...
Definition: Data.cpp:2983
Data minval_nonlazy() const
Definition: Data.cpp:2628
int get_MPISize(void) const
return the MPI rank number of the local data MPI_COMM_WORLD is assumed and the result of MPI_Comm_ran...
Definition: Data.cpp:5442
const DataTypes::ShapeType & getDataPointShape() const
Return a reference to the data point shape.
Definition: Data.h:692
const FunctionSpace & getFunctionSpace() const
Return the function space.
Definition: Data.h:462
void delaySelf()
convert the current data into lazy data.
Definition: Data.cpp:800
Data transpose(int axis_offset) const
Transpose each data point of this Data object around the given axis.
Definition: Data.cpp:2906
int get_MPIRank(void) const
return the MPI rank number of the local data MPI_COMM_WORLD is assumed and the result of MPI_Comm_siz...
Definition: Data.cpp:5454
void expand()
Whatever the current Data type make this into a DataExpanded.
Definition: Data.cpp:1183
DataTypes::real_t reduction(BinaryFunction operation, DataTypes::real_t initial_value) const
Perform the specified reduction algorithm on every element of every data point in this Data object ac...
Definition: Data.h:2210
Data operator+(const Data &left, const Data &right)
Operator+ Takes two Data objects.
Definition: Data.cpp:3352
Data represents a collection of datapoints.
Definition: Data.h:63
Data whereZero(DataTypes::real_t tol=0.0) const
Return a Data with a 1 for 0 values and a 0 for +ive or -ive values.
Definition: Data.cpp:1300
DataTypes::RealVectorType::reference getDataPointRW(int sampleNo, int dataPointNo)
Return a reference into the DataVector which points to the specified data point.
Definition: Data.cpp:4732
Data asinh() const
Return the asinh of each data point of this Data object.
Definition: Data.cpp:2125
void maskWorker(Data &other2, Data &mask2, S sentinel)
Definition: Data.cpp:957
virtual DataTypes::RealVectorType & getTypedVectorRW(DataTypes::real_t dummy)
These versions use the type system rather than method name to determine return type.
Definition: DataConstant.cpp:864
DataTypes::RealVectorType::reference getDataAtOffsetRW(DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy)
Definition: Data.cpp:4685
ES_optype
Definition: ES_optype.h:26
Data asin() const
Return the asin of each data point of this Data object.
Definition: Data.cpp:2070
void replaceInf(DataTypes::real_t value)
Definition: Data.cpp:2448
bool isConstant() const
Return true if this Data is constant.
Definition: Data.cpp:1142
void setValueOfDataPointToArray(int dataPointNo, const boost::python::object &)
sets the values of a data-point from a array-like object on this process
Definition: Data.cpp:1615
bool isComplex() const
True if components of this data are stored as complex.
Definition: Data.cpp:1163
bool isShared() const
Definition: Data.h:1822
bool numSamplesEqual(int numDataPointsPerSample, int numSamples) const
Returns true if the number of data points per sample and the number of samples match the respective a...
Definition: Data.h:542
const DataTypes::RealVectorType * resolveSample(int sampleNo, size_t &roffset) const
Compute the value of the expression for the given sample.
Definition: DataLazy.cpp:2335
DataReady_ptr borrowReadyPtr(void) const
Definition: Data.cpp:4638
Data acosh() const
Return the acosh of each data point of this Data object.
Definition: Data.cpp:2132
Data wherePositive() const
Return a Data with a 1 for +ive values and a 0 for 0 or -ive values.
Definition: Data.cpp:1256
bool actsExpanded() const
Return true if this Data is expanded or resolves to expanded. That is, if it has a separate value for...
Definition: Data.cpp:1121
Data & operator=(const Data &other)
Definition: Data.cpp:3205
void forceResolve()
Definition: Data.h:1831
DataTypes::cplx_t * getSampleDataByTag(int tag, DataTypes::cplx_t dummy)
Definition: Data.h:648
virtual DataAbstract * deepCopy() const =0
Return a deep copy of the current object.
void requireWrite()
Ensures data is ready for write access. This means that the data will be resolved if lazy and will be...
Definition: Data.cpp:1242
DataTypes::real_t Lsup_const() const
Definition: Data.cpp:2208
int getNumDataPointsPerSample() const
Return the number of data points per sample.
Definition: Data.h:531
const DataReady * getReady() const
Definition: Data.h:1773
DataTypes::RealVectorType::size_type getDefaultOffset() const
Returns the offset in the structure which stores the default value.
Definition: DataTagged.h:723
DataTypes::real_t * getSampleDataRW(DataTypes::RealVectorType::size_type sampleNo, DataTypes::real_t dummy=0)
Return the sample data for the given sample no. Please do not use this unless you NEED to access samp...
Definition: Data.h:1941
int MPI_Comm
Definition: EsysMPI.h:41
Data hermitian() const
Return the hermitian part of a matrix which is half the matrix plus its adjoint.
Definition: Data.cpp:2784
friend Data condEvalWorker(escript::Data &mask, escript::Data &trueval, escript::Data &falseval, S sentinel)
Data oneOver() const
Returns 1./ Data object.
Definition: Data.cpp:1249
virtual DataTypes::RealVectorType & getTypedVectorRW(DataTypes::real_t dummy)
These versions use the type system rather than method name to determine return type.
Definition: DataTagged.cpp:1668
DataTypes::real_t LsupWorker() const
Definition: Data.cpp:2483
Data minval() const
Return the minimum value of each data point of this Data object.
Definition: Data.cpp:2659
Data C_TensorBinaryOperation(Data const &arg_0, Data const &arg_1, ES_optype operation)
Compute a tensor operation with two Data objects.
Definition: Data.cpp:6358
bool m_lazy
Definition: Data.h:1763
DataTypes::real_t sup()
Return the maximum value of this Data object.
Definition: Data.cpp:2267
void setTupleForGlobalDataPoint(int id, int proc, boost::python::object)
Set the value of a global data point.
Definition: Data.cpp:1570
const DataTypes::real_t * getSampleDataRO(DataTypes::RealVectorType::size_type sampleNo, DataTypes::real_t dummy=0) const
Definition: DataReady.h:217
int getNumSamples() const
Return the number of samples.
Definition: Data.h:520
boost::python::object __div__(const boost::python::object &right)
wrapper for python divide operation
Definition: Data.cpp:6012
virtual const DataTypes::RealVectorType & getTypedVectorRO(DataTypes::real_t dummy) const =0
Data abs() const
Return the absolute value of each data point of this Data object.
Definition: Data.cpp:2168
Data grad() const
Definition: Data.cpp:1353
Data dp_algorithm(BinaryFunction operation, DataTypes::real_t initial_value) const
Reduce each data-point in this Data object using the given operation. Return a Data object with the s...
Definition: Data.h:2289
void copy(const Data &other)
Make this object a deep copy of "other".
Definition: Data.cpp:780
Wraps an expression tree of other DataObjects. The data will be evaluated when required.
Definition: DataLazy.h:47
std::complex< real_t > cplx_t
complex data type
Definition: DataTypes.h:53
DataTypes::real_t inf_const() const
Definition: Data.cpp:2292
const boost::python::tuple eigenvalues_and_eigenvectors(const DataTypes::real_t tol=1.e-12) const
Return the eigenvalues and corresponding eigenvcetors of the symmetric part at each data point of thi...
Definition: Data.cpp:2957
void init_from_data_and_fs(const Data &inData, const FunctionSpace &functionspace)
Definition: Data.cpp:433
int getTagNumber(int dpno)
Return the tag number associated with the given data-point.
Definition: Data.cpp:3676
Domain_ptr getDomainPython() const
Return the function space domain. Internal use only! This gets around some python difficulties by cas...
Definition: FunctionSpace.cpp:108
Definition: DataException.h:26
void complicate()
Definition: Data.cpp:6060
Data nonuniforminterp(boost::python::object in, boost::python::object out, bool check_boundaries)
Definition: Data.cpp:5235
virtual const DataTypes::RealVectorType & getTypedVectorRO(DataTypes::real_t dummy) const
Definition: DataExpanded.cpp:1531
Data maxval_nonlazy() const
Definition: Data.cpp:2639
DataTypes::real_t reductionOpVector(const DataTypes::RealVectorType &left, const DataTypes::ShapeType &leftShape, DataTypes::RealVectorType::size_type offset, BinaryFunction operation, DataTypes::real_t initial_value)
Perform the given data point reduction operation on the data point specified by the given offset into...
Definition: DataVectorOps.h:1396
Data condEval(escript::Data &mask, escript::Data &trueval, escript::Data &falseval)
Definition: Data.cpp:5651
Data powO(const boost::python::object &right) const
Return the given power of each data point of this boost python object.
Definition: Data.cpp:3333
Data whereNonNegative() const
Return a Data with a 1 for +ive or 0 values and a 0 for -ive values.
Definition: Data.cpp:1278
Data exp() const
Return the exponential function of each data point of this Data object.
Definition: Data.cpp:2194
Data operator*(const AbstractSystemMatrix &left, const Data &right)
Definition: AbstractSystemMatrix.cpp:59
void exclusiveWrite()
if another object is sharing out member data make a copy to work with instead. This code should only ...
Definition: Data.h:1849
Data whereNegative() const
Return a Data with a 1 for -ive values and a 0 for +ive or 0 values.
Definition: Data.cpp:1267
bool isTagged() const
Return true if this Data is tagged.
Definition: Data.cpp:1128
Definition: DataAbstract.h:61
bool hasNoSamples() const
Return true if this object contains no samples. This is not the same as isEmpty() ...
Definition: Data.h:732
Data conjugate() const
For complex values return the conjugate values. For non-complex data return a copy.
Definition: Data.cpp:1967
const_Domain_ptr getDomain() const
Return the domain.
Definition: Data.h:474
Data interpolateFromTable2D(const WrappedArray &table, DataTypes::real_t Amin, DataTypes::real_t Astep, DataTypes::real_t undef, Data &B, DataTypes::real_t Bmin, DataTypes::real_t Bstep, bool check_boundaries)
Definition: Data.cpp:4896
const ElementType & const_reference
Definition: DataVectorAlt.h:51
void dump(const std::string fileName) const
dumps the object into a netCDF file
Definition: Data.cpp:5420
void setProtection()
switches on update protection
Definition: Data.cpp:1169
const FunctionSpace & getFunctionSpace() const
Return the function space associated with this Data object.
Definition: DataAbstract.h:634
Data besselFirstKind(int order)
Return the Bessel function of the first kind for each data point of this Data object.
Definition: Data.cpp:1860
boost::shared_ptr< DataReady > DataReady_ptr
Definition: DataAbstract.h:56
boost::python::object __rdiv__(const boost::python::object &right)
wrapper for python reverse divide operation
Definition: Data.cpp:6036
bool hasNaN()
returns return true if data contains NaN.
Definition: Data.cpp:2392
DataTypes::RealVectorType::size_type getDataOffset(int sampleNo, int dataPointNo)
Return the offset for the given sample and point within the sample.
Definition: Data.h:680
Data operator/(const Data &left, const Data &right)
Operator/ Takes two Data objects.
Definition: Data.cpp:3381
bool isExpanded() const
Return true if this Data is expanded.
Definition: Data.cpp:1114
Data whereNonPositive() const
Return a Data with a 1 for -ive or 0 values and a 0 for +ive values.
Definition: Data.cpp:1289
Data()
Default constructor. Creates a DataEmpty object.
Definition: Data.cpp:249
void copyWithMask(const Data &other, const Data &mask)
Copy other Data object into this Data object where mask is positive.
Definition: Data.cpp:854
boost::python::object __mul__(const boost::python::object &right)
wrapper for python multiply operation
Definition: Data.cpp:5988
size_t getNumberOfTaggedValues() const
For tagged Data returns the number of tags with values. For non-tagged data will return 0 (even Data ...
Definition: Data.cpp:5862
Data neg() const
Return the negation of each data point of this Data object.
Definition: Data.cpp:2175
const boost::python::tuple getShapeTuple() const
Return the data point shape as a tuple of integers.
Definition: Data.cpp:727
const DataMapType & getTagLookup() const
getTagLookup
Definition: DataTagged.h:761
Data truedivO(const boost::python::object &right)
Newer style division operator for python.
Definition: Data.h:2179
bool isReady() const
Return true if this data is ready.
Definition: Data.cpp:1156
Data symmetric() const
Return the symmetric part of a matrix which is half the matrix plus its transpose.
Definition: Data.cpp:2725
#define ESYS_ASSERT(a, b)
EsysAssert is a MACRO that will throw an exception if the boolean condition specified is false...
Definition: Assert.h:78
Definition: WrappedArray.h:31
DataTypes::RealVectorType & getExpandedVectorReference(DataTypes::real_t dummy=0)
Ensures that the Data is expanded and returns its underlying vector Does not check for exclusive writ...
Definition: Data.cpp:5844
int getNumDataPoints() const
Return the number of data points.
Definition: Data.h:510
Data antisymmetric() const
Return the antisymmetric part of a matrix which is half the matrix minus its transpose.
Definition: Data.cpp:2748
Data sin() const
Return the sin of each data point of this Data object.
Definition: Data.cpp:2049
~Data()
Destructor.
Definition: Data.cpp:604
void unaryOp2(UnaryFunction operation)
Perform the given unary operation on every element of every data point in this Data object...
Data gradOn(const FunctionSpace &functionspace) const
Calculates the gradient of the data at the data points of functionspace. If functionspace is not pres...
Definition: Data.cpp:1326
const boost::python::object getValueOfDataPointAsTuple(int dataPointNo)
Return the value of a data point as a python tuple.
Definition: Data.cpp:1523
#define S(_J_, _I_)
Definition: ShapeFunctions.cpp:121
Data interpolateFromTable3D(const WrappedArray &table, DataTypes::real_t Amin, DataTypes::real_t Astep, DataTypes::real_t undef, Data &B, DataTypes::real_t Bmin, DataTypes::real_t Bstep, Data &C, DataTypes::real_t Cmin, DataTypes::real_t Cstep, bool check_boundaries)
Definition: Data.cpp:5052
bool isProtected() const
Returns true, if the data object is protected against update.
Definition: Data.cpp:1175
Data log() const
Return the natural log of each data point of this Data object.
Definition: Data.cpp:2153
Data truedivD(const Data &right)
Newer style division operator for python.
Definition: Data.h:2167
boost::shared_ptr< const AbstractDomain > const_Domain_ptr
Definition: AbstractDomain.h:39
Data whereNonZero(DataTypes::real_t tol=0.0) const
Return a Data with a 0 for 0 values and a 1 for +ive or -ive values.
Definition: Data.cpp:1307
DataTypes::real_t Lsup()
Return the maximum absolute value of this Data object.
Definition: Data.cpp:2218
Data & operator-=(const Data &right)
Overloaded operator -=.
Definition: Data.cpp:3213
boost::python::object integrateToTuple_const() const
Calculate the integral over the function space domain as a python tuple.
Definition: Data.cpp:1773
double real_t
type of all real-valued scalars in escript
Definition: DataTypes.h:50
void calc_maxGlobalDataPoint(int &ProcNo, int &DataPointNo) const
Definition: Data.cpp:3096
Data eigenvalues() const
Return the eigenvalues of the symmetric part at each data point of this Data object in increasing val...
Definition: Data.cpp:2930
Data bessel(int order, DataTypes::real_t(*besselfunc)(int, DataTypes::real_t))
Bessel worker function.
Definition: Data.cpp:1874
void setTaggedValue(int tagKey, const boost::python::object &value)
Assign the given value to the tag. Implicitly converts this object to type DataTagged if it is consta...
Definition: Data.cpp:3597
const boost::python::object getValueOfGlobalDataPointAsTuple(int procNo, int dataPointNo)
Return a data point across all processors as a python tuple.
Definition: Data.cpp:1702
Data swapaxes(const int axis0, const int axis1) const
swaps the components axis0 and axis1
Definition: Data.cpp:2668
Domain_ptr getDomainPython() const
Return the domain. TODO: For internal use only. This should be removed.
Definition: Data.h:488
Data tan() const
Return the tan of each data point of this Data object.
Definition: Data.cpp:2063
Data & operator+=(const Data &right)
Overloaded operator +=.
Definition: Data.cpp:3177