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 
709  int
710  getDataPointSize() const;
711 
717  getLength() const;
718 
723  bool
724  hasNoSamples() const
725  {
726  return m_data->getNumSamples()==0;
727  }
728 
737  void
738  setTaggedValueByName(std::string name,
739  const boost::python::object& value);
740 
750  void
751  setTaggedValue(int tagKey,
752  const boost::python::object& value);
753 
764  void
765  setTaggedValueFromCPP(int tagKey,
766  const DataTypes::ShapeType& pointshape,
767  const DataTypes::RealVectorType& value,
768  int dataOffset=0);
769 
770 
771  void
772  setTaggedValueFromCPP(int tagKey,
773  const DataTypes::ShapeType& pointshape,
774  const DataTypes::CplxVectorType& value,
775  int dataOffset=0);
776 
781  void
782  copyWithMask(const Data& other,
783  const Data& mask);
784 
794  void
795  setToZero();
796 
803  Data
804  interpolate(const FunctionSpace& functionspace) const;
805 
806  Data
808  DataTypes::real_t undef, Data& B, DataTypes::real_t Bmin, DataTypes::real_t Bstep, Data& C,
809  DataTypes::real_t Cmin, DataTypes::real_t Cstep, bool check_boundaries);
810 
811  Data
813  DataTypes::real_t undef, Data& B, DataTypes::real_t Bmin, DataTypes::real_t Bstep,bool check_boundaries);
814 
815  Data
817  DataTypes::real_t undef,bool check_boundaries);
818 
819 
820  Data
821  interpolateFromTable3DP(boost::python::object table, DataTypes::real_t Amin, DataTypes::real_t Astep,
822  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);
823 
824 
825  Data
826  interpolateFromTable2DP(boost::python::object table, DataTypes::real_t Amin, DataTypes::real_t Astep,
827  Data& B, DataTypes::real_t Bmin, DataTypes::real_t Bstep, DataTypes::real_t undef,bool check_boundaries);
828 
829  Data
830  interpolateFromTable1DP(boost::python::object table, DataTypes::real_t Amin, DataTypes::real_t Astep,
831  DataTypes::real_t undef,bool check_boundaries);
832 
833  Data
834  nonuniforminterp(boost::python::object in, boost::python::object out, bool check_boundaries);
835 
836  Data
837  nonuniformslope(boost::python::object in, boost::python::object out, bool check_boundaries);
838 
845  Data
846  gradOn(const FunctionSpace& functionspace) const;
847 
848  Data
849  grad() const;
850 
855  boost::python::object
856  integrateToTuple_const() const;
857 
858 
863  boost::python::object
865 
866 
867 
873  Data
874  oneOver() const;
880  Data
881  wherePositive() const;
882 
888  Data
889  whereNegative() const;
890 
896  Data
897  whereNonNegative() const;
898 
904  Data
905  whereNonPositive() const;
906 
912  Data
913  whereZero(DataTypes::real_t tol=0.0) const;
914 
920  Data
921  whereNonZero(DataTypes::real_t tol=0.0) const;
922 
935  Lsup();
936 
938  Lsup_const() const;
939 
940 
953  sup();
954 
956  sup_const() const;
957 
958 
971  inf();
972 
974  inf_const() const;
975 
976 
977 
983  Data
984  abs() const;
985 
991  Data
992  phase() const;
993 
994 
1000  Data
1001  maxval() const;
1002 
1008  Data
1009  minval() const;
1010 
1018  const boost::python::tuple
1019  minGlobalDataPoint() const;
1020 
1028  const boost::python::tuple
1029  maxGlobalDataPoint() const;
1030 
1031 
1032 
1039  Data
1040  sign() const;
1041 
1047  Data
1048  symmetric() const;
1049 
1055  Data
1056  antisymmetric() const;
1057 
1058 
1064  Data
1065  hermitian() const;
1066 
1072  Data
1073  antihermitian() const;
1074 
1080  Data
1081  trace(int axis_offset) const;
1082 
1088  Data
1089  transpose(int axis_offset) const;
1090 
1097  Data
1098  eigenvalues() const;
1099 
1109  const boost::python::tuple
1110  eigenvalues_and_eigenvectors(const DataTypes::real_t tol=1.e-12) const;
1111 
1117  Data
1118  swapaxes(const int axis0, const int axis1) const;
1119 
1125  Data
1126  erf() const;
1127 
1128 
1134  Data
1135  conjugate() const;
1136 
1137  Data
1138  real() const;
1139 
1140  Data
1141  imag() const;
1142 
1148  Data
1149  sin() const;
1150 
1156  Data
1157  cos() const;
1158 
1164  Data
1165  bessel(int order, DataTypes::real_t (*besselfunc) (int,DataTypes::real_t) );
1166 
1167 
1173  Data
1174  besselFirstKind(int order);
1175 
1181  Data
1182  besselSecondKind(int order);
1183 
1184 
1190  Data
1191  tan() const;
1192 
1198  Data
1199  asin() const;
1200 
1206  Data
1207  acos() const;
1208 
1214  Data
1215  atan() const;
1216 
1222  Data
1223  sinh() const;
1224 
1230  Data
1231  cosh() const;
1232 
1238  Data
1239  tanh() const;
1240 
1246  Data
1247  asinh() const;
1248 
1254  Data
1255  acosh() const;
1256 
1262  Data
1263  atanh() const;
1264 
1270  Data
1271  log10() const;
1272 
1278  Data
1279  log() const;
1280 
1286  Data
1287  exp() const;
1288 
1294  Data
1295  sqrt() const;
1296 
1302  Data
1303  neg() const;
1304 
1311  Data
1312  pos() const;
1313 
1321  Data
1322  powD(const Data& right) const;
1323 
1331  Data
1332  powO(const boost::python::object& right) const;
1333 
1342  Data
1343  rpowO(const boost::python::object& left) const;
1344 
1351  Data& operator+=(const Data& right);
1352  Data& operator+=(const boost::python::object& right);
1353 
1354  Data& operator=(const Data& other);
1355 
1362  Data& operator-=(const Data& right);
1363  Data& operator-=(const boost::python::object& right);
1364 
1371  Data& operator*=(const Data& right);
1372  Data& operator*=(const boost::python::object& right);
1373 
1380  Data& operator/=(const Data& right);
1381  Data& operator/=(const boost::python::object& right);
1382 
1387  Data truedivD(const Data& right);
1388 
1393  Data truedivO(const boost::python::object& right);
1394 
1399  Data rtruedivO(const boost::python::object& left);
1400 
1405  boost::python::object __add__(const boost::python::object& right);
1406 
1407 
1412  boost::python::object __sub__(const boost::python::object& right);
1413 
1418  boost::python::object __rsub__(const boost::python::object& right);
1419 
1424  boost::python::object __mul__(const boost::python::object& right);
1425 
1430  boost::python::object __div__(const boost::python::object& right);
1431 
1436  boost::python::object __rdiv__(const boost::python::object& right);
1437 
1441  Data
1442  matrixInverse() const;
1443 
1448  bool
1449  probeInterpolation(const FunctionSpace& functionspace) const;
1450 
1466  Data
1467  getItem(const boost::python::object& key) const;
1468 
1480  void
1481  setItemD(const boost::python::object& key,
1482  const Data& value);
1483 
1484  void
1485  setItemO(const boost::python::object& key,
1486  const boost::python::object& value);
1487 
1488  // These following public methods should be treated as private.
1489 
1495  template <class UnaryFunction>
1496  inline
1497  void
1498  unaryOp2(UnaryFunction operation);
1499 
1507  Data
1508  getSlice(const DataTypes::RegionType& region) const;
1509 
1518  void
1519  setSlice(const Data& value,
1520  const DataTypes::RegionType& region);
1521 
1526  void
1527  print(void);
1528 
1535  int
1536  get_MPIRank(void) const;
1537 
1544  int
1545  get_MPISize(void) const;
1546 
1552  MPI_Comm
1553  get_MPIComm(void) const;
1554 
1560  DataAbstract*
1561  borrowData(void) const;
1562 
1564  borrowDataPtr(void) const;
1565 
1567  borrowReadyPtr(void) const;
1568 
1569 
1570 
1580 
1583 
1586 
1589 
1590 
1602 
1605 
1606 
1611  size_t
1612  getNumberOfTaggedValues() const;
1613 
1614  /*
1615  * \brief make the data complex
1616  */
1617  void complicate();
1618 
1619  protected:
1620 
1621  private:
1622  void init_from_data_and_fs(const Data& inData,
1623  const FunctionSpace& functionspace);
1624 
1625  template <typename S>
1626  void
1627  maskWorker(Data& other2, Data& mask2, S sentinel);
1628 
1629  template <class BinaryOp>
1631 #ifdef ESYS_MPI
1632  lazyAlgWorker(DataTypes::real_t init, MPI_Op mpiop_type);
1633 #else
1635 #endif
1636 
1638  LsupWorker() const;
1639 
1641  supWorker() const;
1642 
1644  infWorker() const;
1645 
1646  template<typename Scalar>
1647  boost::python::object
1648  integrateWorker() const;
1649 
1650  void
1651  calc_minGlobalDataPoint(int& ProcNo, int& DataPointNo) const;
1652 
1653  void
1654  calc_maxGlobalDataPoint(int& ProcNo, int& DataPointNo) const;
1655 
1656  // For internal use in Data.cpp only!
1657  // other uses should call the main entry points and allow laziness
1658  Data
1659  minval_nonlazy() const;
1660 
1661  // For internal use in Data.cpp only!
1662  Data
1663  maxval_nonlazy() const;
1664 
1665 
1672  inline
1673  void
1674  operandCheck(const Data& right) const
1675  {
1676  return m_data->operandCheck(*(right.m_data.get()));
1677  }
1678 
1684  template <class BinaryFunction>
1685  inline
1687  reduction(BinaryFunction operation,
1688  DataTypes::real_t initial_value) const;
1689 
1697  template <class BinaryFunction>
1698  inline
1699  Data
1700  dp_algorithm(BinaryFunction operation,
1701  DataTypes::real_t initial_value) const;
1702 
1708  void
1709  typeMatchLeft(Data& right) const;
1710 
1716  void
1717  typeMatchRight(const Data& right);
1718 
1724  void
1726  const DataTypes::ShapeType& shape,
1727  const FunctionSpace& what,
1728  bool expanded);
1729 
1730  void
1732  const DataTypes::ShapeType& shape,
1733  const FunctionSpace& what,
1734  bool expanded);
1735 
1736  void
1737  initialise(const WrappedArray& value,
1738  const FunctionSpace& what,
1739  bool expanded);
1740 
1741  void
1742  initialise(const DataTypes::real_t value,
1743  const DataTypes::ShapeType& shape,
1744  const FunctionSpace& what,
1745  bool expanded);
1746 
1747  void
1748  initialise(const DataTypes::cplx_t value,
1749  const DataTypes::ShapeType& shape,
1750  const FunctionSpace& what,
1751  bool expanded);
1752  //
1753  // flag to protect the data object against any update
1755  bool m_lazy;
1756 
1757  //
1758  // pointer to the actual data object
1759 // boost::shared_ptr<DataAbstract> m_data;
1761 
1762 // If possible please use getReadyPtr instead.
1763 // But see warning below.
1764  const DataReady*
1765  getReady() const
1766 {
1767  const DataReady* dr=dynamic_cast<const DataReady*>(m_data.get());
1768  ESYS_ASSERT(dr!=0, "error casting to DataReady.");
1769  return dr;
1770 }
1771 
1772  DataReady*
1774 {
1775  DataReady* dr=dynamic_cast<DataReady*>(m_data.get());
1776  ESYS_ASSERT(dr!=0, "error casting to DataReady.");
1777  return dr;
1778 }
1779 
1780 
1781 // Be wary of using this for local operations since it (temporarily) increases reference count.
1782 // If you are just using this to call a method on DataReady instead of DataAbstract consider using
1783 // getReady() instead
1786 {
1787  DataReady_ptr dr=REFCOUNTNS::dynamic_pointer_cast<DataReady>(m_data);
1788  ESYS_ASSERT(dr.get()!=0, "error casting to DataReady.");
1789  return dr;
1790 }
1791 
1793  getReadyPtr() const
1794 {
1795  const_DataReady_ptr dr=REFCOUNTNS::dynamic_pointer_cast<const DataReady>(m_data);
1796  ESYS_ASSERT(dr.get()!=0, "error casting to DataReady.");
1797  return dr;
1798 }
1799 
1800  // In the isShared() method below:
1801  // A problem would occur if m_data (the address pointed to) were being modified
1802  // while the call m_data->is_shared is being executed.
1803  //
1804  // Q: So why do I think this code can be thread safe/correct?
1805  // A: We need to make some assumptions.
1806  // 1. We assume it is acceptable to return true under some conditions when we aren't shared.
1807  // 2. We assume that no constructions or assignments which will share previously unshared
1808  // will occur while this call is executing. This is consistent with the way Data:: and C are written.
1809  //
1810  // This means that the only transition we need to consider, is when a previously shared object is
1811  // not shared anymore. ie. the other objects have been destroyed or a deep copy has been made.
1812  // In those cases the m_shared flag changes to false after m_data has completed changing.
1813  // For any threads executing before the flag switches they will assume the object is still shared.
1814  bool isShared() const
1815  {
1816 #ifdef SLOWSHARECHECK
1817  return m_data->isShared(); // single threadsafe check for this
1818 #else
1819  return !m_data.unique();
1820 #endif
1821  }
1822 
1824  {
1825  if (isLazy())
1826  {
1827  #ifdef _OPENMP
1828  if (omp_in_parallel())
1829  { // Yes this is throwing an exception out of an omp thread which is forbidden.
1830  throw DataException("Please do not call forceResolve() in a parallel region.");
1831  }
1832  #endif
1833  resolve();
1834  }
1835  }
1836 
1842  {
1843 #ifdef _OPENMP
1844  if (omp_in_parallel())
1845  {
1846  throw DataException("Programming error. Please do not run exclusiveWrite() in multi-threaded sections.");
1847  }
1848 #endif
1849  forceResolve();
1850  if (isShared())
1851  {
1852  DataAbstract* t=m_data->deepCopy();
1854  }
1855 #ifdef EXWRITECHK
1856  m_data->exclusivewritecalled=true;
1857 #endif
1858  }
1859 
1864  {
1865  if (isLazy() || isShared())
1866  {
1867  std::ostringstream oss;
1868  oss << "Programming error. ExclusiveWrite required - please call requireWrite() isLazy=" << isLazy() << " isShared()=" << isShared();
1869  throw DataException(oss.str());
1870  }
1871  }
1872 
1879  void set_m_data(DataAbstract_ptr p);
1880 
1881 
1882  void TensorSelfUpdateBinaryOperation(const Data& right, escript::ES_optype operation);
1883 
1884  friend class DataAbstract; // To allow calls to updateShareStatus
1885  friend class TestDomain; // so its getX will work quickly
1886 #ifdef IKNOWWHATIMDOING
1887  friend Data applyBinaryCFunction(boost::python::object cfunc, boost::python::tuple shape, escript::Data& d, escript::Data& e);
1888 #endif
1889  template <typename S>
1890  friend Data condEvalWorker(escript::Data& mask, escript::Data& trueval, escript::Data& falseval, S sentinel);
1891  friend Data randomData(const boost::python::tuple& shape, const FunctionSpace& what, long seed, const boost::python::tuple& filter);
1892 
1893 };
1894 
1895 
1896 #ifdef IKNOWWHATIMDOING
1897 Data
1898 applyBinaryCFunction(boost::python::object func, boost::python::tuple shape, escript::Data& d, escript::Data& e);
1899 #endif
1900 
1901 Data
1902 condEval(escript::Data& mask, escript::Data& trueval, escript::Data& falseval);
1903 
1904 
1905 
1909 Data randomData(const boost::python::tuple& shape,
1910  const FunctionSpace& what,
1911  long seed, const boost::python::tuple& filter);
1912 
1913 
1914 } // end namespace escript
1915 
1916 
1917 // No, this is not supposed to be at the top of the file
1918 // DataAbstact needs to be declared first, then DataReady needs to be fully declared
1919 // so that I can dynamic cast between them below.
1920 #include "DataReady.h"
1921 #include "DataLazy.h"
1922 #include "DataExpanded.h"
1923 #include "DataConstant.h"
1924 #include "DataTagged.h"
1925 
1926 namespace escript
1927 {
1928 
1929 
1930 
1931 inline
1934 {
1935  if (isLazy())
1936  {
1937  throw DataException("Error, attempt to acquire RW access to lazy data. Please call requireWrite() first.");
1938  }
1939 #ifdef EXWRITECHK
1940  if (!getReady()->exclusivewritecalled)
1941  {
1942  throw DataException("Error, call to Data::getSampleDataRW without a preceeding call to requireWrite/exclusiveWrite.");
1943  }
1944 #endif
1945  return getReady()->getSampleDataRW(sampleNo, dummy);
1946 }
1947 
1948 inline
1951 {
1952  if (isLazy())
1953  {
1954  throw DataException("Error, attempt to acquire RW access to lazy data. Please call requireWrite() first.");
1955  }
1956 #ifdef EXWRITECHK
1957  if (!getReady()->exclusivewritecalled)
1958  {
1959  throw DataException("Error, call to Data::getSampleDataRW without a preceeding call to requireWrite/exclusiveWrite.");
1960  }
1961 #endif
1962  return getReady()->getSampleDataRW(sampleNo, dummy);
1963 }
1964 
1965 
1966 inline
1967 const DataTypes::real_t*
1969 {
1970  DataLazy* l=dynamic_cast<DataLazy*>(m_data.get());
1971  if (l!=0)
1972  {
1973  size_t offset=0;
1974  const DataTypes::RealVectorType* res=l->resolveSample(sampleNo,offset);
1975  return &((*res)[offset]);
1976  }
1977  return getReady()->getSampleDataRO(sampleNo, dummy);
1978 }
1979 
1980 inline
1981 const DataTypes::cplx_t*
1983 {
1984  DataLazy* l=dynamic_cast<DataLazy*>(m_data.get());
1985  if (l!=0)
1986  {
1987  throw DataException("Programming error: complex lazy objects are not supported.");
1988  }
1989  return getReady()->getSampleDataRO(sampleNo, dummy);
1990 }
1991 
1992 
1993 inline
1994 const DataTypes::real_t*
1996 {
1997  if (isLazy())
1998  {
1999  throw DataException("Programmer error - getDataRO must not be called on Lazy Data.");
2000  }
2001  if (getNumSamples()==0)
2002  {
2003  return 0;
2004  }
2005  else
2006  {
2007  return &(getReady()->getTypedVectorRO(0)[0]);
2008  }
2009 }
2010 
2011 inline
2012 const DataTypes::cplx_t*
2014 {
2015  if (isLazy())
2016  {
2017  throw DataException("Programmer error - getDataRO must not be called on Lazy Data.");
2018  }
2019  if (getNumSamples()==0)
2020  {
2021  return 0;
2022  }
2023  else
2024  {
2025  return &(getReady()->getTypedVectorRO(dummy)[0]);
2026  }
2027 }
2028 
2029 
2034 {
2035  return pow(y,x);
2036 }
2037 
2043 Data operator+(const Data& left, const Data& right);
2044 
2050 Data operator-(const Data& left, const Data& right);
2051 
2057 Data operator*(const Data& left, const Data& right);
2058 
2064 Data operator/(const Data& left, const Data& right);
2065 
2072 Data operator+(const Data& left, const boost::python::object& 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 boost::python::object& left, const Data& 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 
2130 
2131 
2136 std::ostream& operator<<(std::ostream& o, const Data& data);
2137 
2146 Data
2148  Data& arg_1,
2149  int axis_offset=0,
2150  int transpose=0);
2151 
2157 inline
2158 Data
2159 Data::truedivD(const Data& right)
2160 {
2161  return *this / right;
2162 }
2163 
2169 inline
2170 Data
2171 Data::truedivO(const boost::python::object& right)
2172 {
2173  Data tmp(right, getFunctionSpace(), false);
2174  return truedivD(tmp);
2175 }
2176 
2182 inline
2183 Data
2184 Data::rtruedivO(const boost::python::object& left)
2185 {
2186  Data tmp(left, getFunctionSpace(), false);
2187  return tmp.truedivD(*this);
2188 }
2189 
2190 
2191 
2199 template <class BinaryFunction>
2200 inline
2202 Data::reduction(BinaryFunction operation, DataTypes::real_t initial_value) const
2203 {
2204  if (isExpanded()) {
2205  DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
2206  ESYS_ASSERT(leftC!=0, "Programming error - casting to DataExpanded.");
2207 
2208  DataExpanded& data=*leftC;
2209  int i,j;
2210  int numDPPSample=data.getNumDPPSample();
2211  int numSamples=data.getNumSamples();
2212  DataTypes::real_t global_current_value=initial_value;
2213  DataTypes::real_t local_current_value;
2214  const auto& vec=data.getTypedVectorRO(typename BinaryFunction::first_argument_type(0));
2215  const DataTypes::ShapeType& shape=data.getShape();
2216  // calculate the reduction operation value for each data point
2217  // reducing the result for each data-point into the current_value variables
2218  #pragma omp parallel private(local_current_value)
2219  {
2220  local_current_value=initial_value;
2221  #pragma omp for private(i,j) schedule(static)
2222  for (i=0;i<numSamples;i++) {
2223  for (j=0;j<numDPPSample;j++) {
2224  local_current_value=operation(local_current_value,escript::reductionOpVector(vec,shape,data.getPointOffset(i,j),operation,initial_value));
2225 
2226  }
2227  }
2228  #pragma omp critical
2229  global_current_value=operation(global_current_value,local_current_value);
2230  }
2231  return global_current_value;
2232  } else if (isTagged()) {
2233  DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
2234  ESYS_ASSERT(leftC!=0, "Programming error - casting to DataTagged.");
2235 
2236  DataTagged& data=*leftC;
2237  DataTypes::real_t current_value=initial_value;
2238 
2239  const auto& vec=data.getTypedVectorRO(typename BinaryFunction::first_argument_type(0));
2240  const DataTypes::ShapeType& shape=data.getShape();
2241  const DataTagged::DataMapType& lookup=data.getTagLookup();
2242  const std::list<int> used=data.getFunctionSpace().getListOfTagsSTL();
2243  for (std::list<int>::const_iterator i=used.begin();i!=used.end();++i)
2244  {
2245  int tag=*i;
2246  DataTagged::DataMapType::const_iterator it=lookup.find(tag);
2247  if ((tag==0) || (it==lookup.end())) // check for the default tag
2248  {
2249  current_value=operation(current_value,escript::reductionOpVector(vec,shape,data.getDefaultOffset(),operation,initial_value));
2250  }
2251  else
2252  {
2253  current_value=operation(current_value,escript::reductionOpVector(vec,shape,it->second,operation,initial_value));
2254  }
2255  }
2256  return current_value;
2257  } else if (isConstant()) {
2258  DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
2259  ESYS_ASSERT(leftC!=0, "Programming error - casting to DataConstant.");
2260  return escript::reductionOpVector(leftC->getTypedVectorRO(typename BinaryFunction::first_argument_type(0)),leftC->getShape(),0,operation,initial_value);
2261  } else if (isEmpty()) {
2262  throw DataException("Error - Operations (algorithm) not permitted on instances of DataEmpty.");
2263  } else if (isLazy()) {
2264  throw DataException("Error - Operations not permitted on instances of DataLazy.");
2265  } else {
2266  throw DataException("Error - Data encapsulates an unknown type.");
2267  }
2268 }
2269 
2278 template <class BinaryFunction>
2279 inline
2280 Data
2281 Data::dp_algorithm(BinaryFunction operation, DataTypes::real_t initial_value) const
2282 {
2283  if (isEmpty()) {
2284  throw DataException("Error - Operations (dp_algorithm) not permitted on instances of DataEmpty.");
2285  }
2286  else if (isExpanded()) {
2288  DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
2289  DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
2290  ESYS_ASSERT(dataE!=0, "Programming error - casting data to DataExpanded.");
2291  ESYS_ASSERT(resultE!=0, "Programming error - casting result to DataExpanded.");
2292 
2293 
2294 
2295  int i,j;
2296  int numSamples=dataE->getNumSamples();
2297  int numDPPSample=dataE->getNumDPPSample();
2298  // DataArrayView dataView=data.getPointDataView();
2299  // DataArrayView resultView=result.getPointDataView();
2300  const auto& dataVec=dataE->getTypedVectorRO(initial_value);
2301  const DataTypes::ShapeType& shape=dataE->getShape();
2302  auto& resultVec=resultE->getTypedVectorRW(initial_value);
2303  // perform the operation on each data-point and assign
2304  // this to the corresponding element in result
2305  #pragma omp parallel for private(i,j) schedule(static)
2306  for (i=0;i<numSamples;i++) {
2307  for (j=0;j<numDPPSample;j++) {
2308  resultVec[resultE->getPointOffset(i,j)] =
2309  escript::reductionOpVector(dataVec, shape, dataE->getPointOffset(i,j),operation,initial_value);
2310 
2311  }
2312  }
2313  //escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
2314  return result;
2315  }
2316  else if (isTagged()) {
2317  DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
2318  ESYS_ASSERT(dataT!=0, "Programming error - casting data to DataTagged.");
2319  DataTypes::RealVectorType defval(1);
2320  defval[0]=0;
2321  DataTagged* resultT=new DataTagged(getFunctionSpace(), DataTypes::scalarShape, defval, dataT);
2322 
2323 
2324  const DataTypes::ShapeType& shape=dataT->getShape();
2325  const auto& vec=dataT->getTypedVectorRO(initial_value);
2326  const DataTagged::DataMapType& lookup=dataT->getTagLookup();
2327  for (DataTagged::DataMapType::const_iterator i=lookup.begin(); i!=lookup.end(); i++) {
2328  resultT->getDataByTagRW(i->first,0) =
2329  escript::reductionOpVector(vec,shape,dataT->getOffsetForTag(i->first),operation,initial_value);
2330  }
2331  resultT->getTypedVectorRW(initial_value)[resultT->getDefaultOffset()] = escript::reductionOpVector(dataT->getTypedVectorRO(initial_value),dataT->getShape(),dataT->getDefaultOffset(),operation,initial_value);
2332 
2333 
2334 
2335 
2336  //escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
2337  return Data(resultT); // note: the Data object now owns the resultT pointer
2338  }
2339  else if (isConstant()) {
2341  DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
2342  DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
2343  ESYS_ASSERT(dataC!=0, "Programming error - casting data to DataConstant.");
2344  ESYS_ASSERT(resultC!=0, "Programming error - casting result to DataConstant.");
2345 
2346  DataConstant& data=*dataC;
2347  resultC->getTypedVectorRW(initial_value)[0] =
2348  escript::reductionOpVector(data.getTypedVectorRO(initial_value),data.getShape(),0,operation,initial_value);
2349 
2350  //escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
2351  return result;
2352  } else if (isLazy()) {
2353  throw DataException("Error - Operations not permitted on instances of DataLazy.");
2354  } else {
2355  throw DataException("Error - Data encapsulates an unknown type.");
2356  }
2357 }
2358 
2359 
2367 Data
2368 C_TensorBinaryOperation(Data const &arg_0,
2369  Data const &arg_1,
2370  ES_optype operation);
2371 
2372 
2373 Data
2374 C_TensorUnaryOperation(Data const &arg_0,
2375  escript::ES_optype operation,
2376  DataTypes::real_t tol=0);
2377 
2378 } // namespace escript
2379 
2380 #endif // __ESCRIPT_DATA_H__
2381 
Definition: FunctionSpace.h:34
std::ostream & operator<<(std::ostream &o, const Data &data)
Output operator.
Definition: Data.cpp:3647
void typeMatchLeft(Data &right) const
Convert the data type of the RHS to match this.
Definition: Data.cpp:3493
DataAbstract_ptr m_data
Definition: Data.h:1760
DataTypes::RealVectorType::size_type getLength() const
Return the number of doubles stored for this Data.
Definition: Data.cpp:1349
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:1360
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:2162
void setItemO(const boost::python::object &key, const boost::python::object &value)
Definition: Data.cpp:3454
Data antihermitian() const
Return the anti-hermitian part of a matrix which is half the matrix minus its hermitian.
Definition: Data.cpp:2772
Data interpolateFromTable1D(const WrappedArray &table, DataTypes::real_t Amin, DataTypes::real_t Astep, DataTypes::real_t undef, bool check_boundaries)
Definition: Data.cpp:4729
boost::python::object __add__(const boost::python::object &right)
wrapper for python add operation
Definition: Data.cpp:5876
const_DataReady_ptr getReadyPtr() const
Definition: Data.h:1793
void checkExclusiveWrite()
checks if caller can have exclusive write to the object
Definition: Data.h:1863
boost::python::object __rsub__(const boost::python::object &right)
wrapper for python reverse subtract operation
Definition: Data.cpp:5924
std::string toString() const
Write the data as a string. For large amounts of data, a summary is printed.
Definition: Data.cpp:4607
void setToZero()
set all values to zero
Definition: Data.cpp:797
DataTypes::real_t rpow(DataTypes::real_t x, DataTypes::real_t y)
Definition: Data.h:2033
ElementType & reference
Definition: DataVectorAlt.h:50
DataTypes::real_t inf()
Return the minimum value of this Data object.
Definition: Data.cpp:2267
void replaceNaN(DataTypes::real_t value)
replaces all NaN values with value
Definition: Data.cpp:2364
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:2398
Data delay()
produce a delayed evaluation version of this Data.
Definition: Data.cpp:768
Data & operator*=(const Data &right)
Overloaded operator *=.
Definition: Data.cpp:3201
void tag()
If possible convert this Data to DataTagged. This will only allow Constant data to be converted to ta...
Definition: Data.cpp:1186
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:1748
Data getSlice(const DataTypes::RegionType &region) const
Return a Data object containing the specified slice of this Data object.
Definition: Data.cpp:3446
DataTypes::real_t supWorker() const
Definition: Data.cpp:2501
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:2121
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:1342
Definition: AbstractContinuousDomain.cpp:22
Data imag() const
Definition: Data.cpp:1967
Data atan() const
Return the atan of each data point of this Data object.
Definition: Data.cpp:2046
Data log10() const
Return the log to base 10 of each data point of this Data object.
Definition: Data.cpp:2107
Data pos() const
Return the identity of each data point of this Data object. Simply returns this object unmodified...
Definition: Data.cpp:2143
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:3462
Data operator-(const Data &left, const Data &right)
Operator- Takes two Data objects.
Definition: Data.cpp:3323
void replaceInfPython(boost::python::object obj)
Definition: Data.cpp:2429
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:5427
DataTypes::real_t sup_const() const
Definition: Data.cpp:2214
Data besselSecondKind(int order)
Return the Bessel function of the second kind for each data point of this Data object.
Definition: Data.cpp:1828
void print(void)
print the data values to stdout. Used for debugging
Definition: Data.cpp:5351
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:4701
void typeMatchRight(const Data &right)
Convert the data type of this to match the RHS.
Definition: Data.cpp:3513
void setSlice(const Data &value, const DataTypes::RegionType &region)
Copy the specified slice from the given value into this Data object.
Definition: Data.cpp:3478
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:1541
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:4677
bool isLazy() const
Return true if this Data is lazy.
Definition: Data.cpp:1128
Data C_TensorUnaryOperation(Data const &arg_0, escript::ES_optype operation, DataTypes::real_t tol=0)
Definition: Data.cpp:6043
DataAbstract_ptr borrowDataPtr(void) const
Definition: Data.cpp:4592
Data real() const
Definition: Data.cpp:1948
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:3541
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:2053
Data atanh() const
Return the atanh of each data point of this Data object.
Definition: Data.cpp:2100
DataReady_ptr getReadyPtr()
Definition: Data.h:1785
void TensorSelfUpdateBinaryOperation(const Data &right, escript::ES_optype operation)
Definition: Data.cpp:6495
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:3287
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:4720
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:3598
Data nonuniformslope(boost::python::object in, boost::python::object out, bool check_boundaries)
Definition: Data.cpp:5272
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:5900
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:4711
Data acos() const
Return the acos of each data point of this Data object.
Definition: Data.cpp:2038
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:1299
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:1987
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:3432
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:2611
void setValueOfDataPointC(int dataPointNo, const DataTypes::cplx_t)
Definition: Data.cpp:1658
Data cos() const
Return the cos of each data point of this Data object.
Definition: Data.cpp:2017
const DataTypes::real_t * getDataRO(DataTypes::real_t dummy=0) const
Return a pointer to the beginning of the underlying data.
Definition: Data.h:1995
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:3654
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:4654
bool m_protected
Definition: Data.h:1754
Data cosh() const
Return the cosh of each data point of this Data object.
Definition: Data.cpp:2060
void setValueOfDataPoint(int dataPointNo, const DataTypes::real_t)
sets the values of a data-point on this process
Definition: Data.cpp:1637
Data interpolate(const FunctionSpace &functionspace) const
Interpolates this onto the given functionspace and returns the result as a Data object.
Definition: Data.cpp:1293
Data matrixInverse() const
return inverse of matricies.
Definition: Data.cpp:3259
Data & operator/=(const Data &right)
Overloaded operator /=.
Definition: Data.cpp:3228
DataReady * getReady()
Definition: Data.h:1773
Data copySelf() const
Return a pointer to a deep copy of this object.
Definition: Data.cpp:752
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:1212
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:1114
Data tanh() const
Return the tanh of each data point of this Data object.
Definition: Data.cpp:2067
void calc_minGlobalDataPoint(int &ProcNo, int &DataPointNo) const
Definition: Data.cpp:2961
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:1674
DataAbstract * borrowData(void) const
return the object produced by the factory, which is a DataConstant or DataExpanded TODO Ownership of ...
Definition: Data.cpp:4585
Data erf() const
Return the error function erf of each data point of this Data object.
Definition: Data.cpp:2075
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:2544
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:2184
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:3047
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:1968
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:3301
void replaceNaNPython(boost::python::object obj)
replaces all NaN values with value
Definition: Data.cpp:2384
Data trace(int axis_offset) const
Return the trace of a matrix.
Definition: Data.cpp:2812
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:2944
Data minval_nonlazy() const
Definition: Data.cpp:2589
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:5403
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:779
Data transpose(int axis_offset) const
Transpose each data point of this Data object around the given axis.
Definition: Data.cpp:2867
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:5415
void expand()
Whatever the current Data type make this into a DataExpanded.
Definition: Data.cpp:1162
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:2202
Data operator+(const Data &left, const Data &right)
Operator+ Takes two Data objects.
Definition: Data.cpp:3313
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:1279
DataTypes::RealVectorType::reference getDataPointRW(int sampleNo, int dataPointNo)
Return a reference into the DataVector which points to the specified data point.
Definition: Data.cpp:4693
Data asinh() const
Return the asinh of each data point of this Data object.
Definition: Data.cpp:2086
void maskWorker(Data &other2, Data &mask2, S sentinel)
Definition: Data.cpp:936
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:4646
ES_optype
Definition: ES_optype.h:26
Data asin() const
Return the asin of each data point of this Data object.
Definition: Data.cpp:2031
void replaceInf(DataTypes::real_t value)
Definition: Data.cpp:2409
bool isConstant() const
Return true if this Data is constant.
Definition: Data.cpp:1121
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:1594
bool isComplex() const
True if components of this data are stored as complex.
Definition: Data.cpp:1142
bool isShared() const
Definition: Data.h:1814
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:4599
Data acosh() const
Return the acosh of each data point of this Data object.
Definition: Data.cpp:2093
Data wherePositive() const
Return a Data with a 1 for +ive values and a 0 for 0 or -ive values.
Definition: Data.cpp:1235
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:1100
Data & operator=(const Data &other)
Definition: Data.cpp:3166
void forceResolve()
Definition: Data.h:1823
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:1221
DataTypes::real_t Lsup_const() const
Definition: Data.cpp:2169
int getNumDataPointsPerSample() const
Return the number of data points per sample.
Definition: Data.h:531
const DataReady * getReady() const
Definition: Data.h:1765
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:1933
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:2745
friend Data condEvalWorker(escript::Data &mask, escript::Data &trueval, escript::Data &falseval, S sentinel)
Data oneOver() const
Returns 1./ Data object.
Definition: Data.cpp:1228
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:2444
Data minval() const
Return the minimum value of each data point of this Data object.
Definition: Data.cpp:2620
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:6319
bool m_lazy
Definition: Data.h:1755
DataTypes::real_t sup()
Return the maximum value of this Data object.
Definition: Data.cpp:2228
void setTupleForGlobalDataPoint(int id, int proc, boost::python::object)
Set the value of a global data point.
Definition: Data.cpp:1549
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:5973
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:2129
Data grad() const
Definition: Data.cpp:1332
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:2281
void copy(const Data &other)
Make this object a deep copy of "other".
Definition: Data.cpp:759
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:2253
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:2918
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:3637
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:6021
Data nonuniforminterp(boost::python::object in, boost::python::object out, bool check_boundaries)
Definition: Data.cpp:5196
virtual const DataTypes::RealVectorType & getTypedVectorRO(DataTypes::real_t dummy) const
Definition: DataExpanded.cpp:1531
Data maxval_nonlazy() const
Definition: Data.cpp:2600
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:1393
Data condEval(escript::Data &mask, escript::Data &trueval, escript::Data &falseval)
Definition: Data.cpp:5612
Data powO(const boost::python::object &right) const
Return the given power of each data point of this boost python object.
Definition: Data.cpp:3294
Data whereNonNegative() const
Return a Data with a 1 for +ive or 0 values and a 0 for -ive values.
Definition: Data.cpp:1257
Data exp() const
Return the exponential function of each data point of this Data object.
Definition: Data.cpp:2155
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:1841
Data whereNegative() const
Return a Data with a 1 for -ive values and a 0 for +ive or 0 values.
Definition: Data.cpp:1246
bool isTagged() const
Return true if this Data is tagged.
Definition: Data.cpp:1107
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:724
Data conjugate() const
For complex values return the conjugate values. For non-complex data return a copy.
Definition: Data.cpp:1928
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:4857
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:5381
void setProtection()
switches on update protection
Definition: Data.cpp:1148
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:1821
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:5997
bool hasNaN()
returns return true if data contains NaN.
Definition: Data.cpp:2353
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:3342
bool isExpanded() const
Return true if this Data is expanded.
Definition: Data.cpp:1093
Data whereNonPositive() const
Return a Data with a 1 for -ive or 0 values and a 0 for +ive values.
Definition: Data.cpp:1268
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:833
boost::python::object __mul__(const boost::python::object &right)
wrapper for python multiply operation
Definition: Data.cpp:5949
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:5823
Data neg() const
Return the negation of each data point of this Data object.
Definition: Data.cpp:2136
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:2171
bool isReady() const
Return true if this data is ready.
Definition: Data.cpp:1135
Data symmetric() const
Return the symmetric part of a matrix which is half the matrix plus its transpose.
Definition: Data.cpp:2686
#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:5805
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:2709
Data sin() const
Return the sin of each data point of this Data object.
Definition: Data.cpp:2010
~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:1305
const boost::python::object getValueOfDataPointAsTuple(int dataPointNo)
Return the value of a data point as a python tuple.
Definition: Data.cpp:1502
#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:5013
bool isProtected() const
Returns true, if the data object is protected against update.
Definition: Data.cpp:1154
Data log() const
Return the natural log of each data point of this Data object.
Definition: Data.cpp:2114
Data truedivD(const Data &right)
Newer style division operator for python.
Definition: Data.h:2159
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:1286
DataTypes::real_t Lsup()
Return the maximum absolute value of this Data object.
Definition: Data.cpp:2179
Data & operator-=(const Data &right)
Overloaded operator -=.
Definition: Data.cpp:3174
boost::python::object integrateToTuple_const() const
Calculate the integral over the function space domain as a python tuple.
Definition: Data.cpp:1734
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:3057
Data eigenvalues() const
Return the eigenvalues of the symmetric part at each data point of this Data object in increasing val...
Definition: Data.cpp:2891
Data bessel(int order, DataTypes::real_t(*besselfunc)(int, DataTypes::real_t))
Bessel worker function.
Definition: Data.cpp:1835
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:3558
const boost::python::object getValueOfGlobalDataPointAsTuple(int procNo, int dataPointNo)
Return a data point across all processors as a python tuple.
Definition: Data.cpp:1681
Data swapaxes(const int axis0, const int axis1) const
swaps the components axis0 and axis1
Definition: Data.cpp:2629
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:2024
Data & operator+=(const Data &right)
Overloaded operator +=.
Definition: Data.cpp:3138