escript  Revision_
Data.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2017 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 
376 
377 
385  void
386  requireWrite();
387 
393  bool
394  isExpanded() const;
395 
401  bool
402  actsExpanded() const;
403 
404 
409  bool
410  isTagged() const;
411 
416  bool
417  isConstant() const;
418 
422  bool
423  isLazy() const;
424 
428  bool
429  isReady() const;
430 
436  bool
437  isEmpty() const;
438 
443  bool
444  isComplex() const;
445 
450  inline
451  const FunctionSpace&
453  {
454  return m_data->getFunctionSpace();
455  }
456 
461  inline
462 // const AbstractDomain&
464  getDomain() const
465  {
466  return getFunctionSpace().getDomain();
467  }
468 
469 
475  inline
476 // const AbstractDomain&
477  Domain_ptr
479  {
481  }
482 
487  inline
488  unsigned int
490  {
491  return m_data->getRank();
492  }
493 
498  inline
499  int
501  {
503  }
508  inline
509  int
511  {
512  return m_data->getNumSamples();
513  }
514 
519  inline
520  int
522  {
523  return m_data->getNumDPPSample();
524  }
525 
531  inline
532  bool numSamplesEqual(int numDataPointsPerSample, int numSamples) const
533  {
534  return (isEmpty() ||
535  (numDataPointsPerSample==getNumDataPointsPerSample() && numSamples==getNumSamples()));
536  }
537 
543  inline
544  bool isDataPointShapeEqual(int rank, const int* dimensions) const
545  {
546  if (isEmpty())
547  return true;
548  const DataTypes::ShapeType givenShape(&dimensions[0],&dimensions[rank]);
549  return (getDataPointShape()==givenShape);
550  }
551 
556  int
557  getNoValues() const
558  {
559  return m_data->getNoValues();
560  }
561 
562 
567  void
568  dump(const std::string fileName) const;
569 
576  const boost::python::object
577  toListOfTuples(bool scalarastuple=true);
578 
579 
587  const DataTypes::real_t*
589 
590  const DataTypes::cplx_t*
592 
593 
603 
606 
607 
608 
615  const DataTypes::real_t*
616  getDataRO(DataTypes::real_t dummy=0) const;
617 
618  const DataTypes::cplx_t*
619  getDataRO(DataTypes::cplx_t dummy) const;
620 
621 
622 
629  inline
632  {
633  return m_data->getSampleDataByTag(tag, dummy);
634  }
635 
636  inline
639  {
640  return m_data->getSampleDataByTag(tag, dummy);
641  }
642 
643 
651  getDataPointRO(int sampleNo, int dataPointNo);
652 
660  getDataPointRW(int sampleNo, int dataPointNo);
661 
662 
663 
668  inline
670  getDataOffset(int sampleNo,
671  int dataPointNo)
672  {
673  return m_data->getPointOffset(sampleNo,dataPointNo);
674  }
675 
680  inline
681  const DataTypes::ShapeType&
683  {
684  return m_data->getShape();
685  }
686 
691  const boost::python::tuple
692  getShapeTuple() const;
693 
699  int
700  getDataPointSize() const;
701 
707  getLength() const;
708 
713  bool
714  hasNoSamples() const
715  {
716  return m_data->getNumSamples()==0;
717  }
718 
727  void
728  setTaggedValueByName(std::string name,
729  const boost::python::object& value);
730 
740  void
741  setTaggedValue(int tagKey,
742  const boost::python::object& value);
743 
754  void
755  setTaggedValueFromCPP(int tagKey,
756  const DataTypes::ShapeType& pointshape,
757  const DataTypes::RealVectorType& value,
758  int dataOffset=0);
759 
760 
761  void
762  setTaggedValueFromCPP(int tagKey,
763  const DataTypes::ShapeType& pointshape,
764  const DataTypes::CplxVectorType& value,
765  int dataOffset=0);
766 
771  void
772  copyWithMask(const Data& other,
773  const Data& mask);
774 
784  void
785  setToZero();
786 
793  Data
794  interpolate(const FunctionSpace& functionspace) const;
795 
796  Data
798  DataTypes::real_t undef, Data& B, DataTypes::real_t Bmin, DataTypes::real_t Bstep, Data& C,
799  DataTypes::real_t Cmin, DataTypes::real_t Cstep, bool check_boundaries);
800 
801  Data
803  DataTypes::real_t undef, Data& B, DataTypes::real_t Bmin, DataTypes::real_t Bstep,bool check_boundaries);
804 
805  Data
807  DataTypes::real_t undef,bool check_boundaries);
808 
809 
810  Data
811  interpolateFromTable3DP(boost::python::object table, DataTypes::real_t Amin, DataTypes::real_t Astep,
812  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);
813 
814 
815  Data
816  interpolateFromTable2DP(boost::python::object table, DataTypes::real_t Amin, DataTypes::real_t Astep,
817  Data& B, DataTypes::real_t Bmin, DataTypes::real_t Bstep, DataTypes::real_t undef,bool check_boundaries);
818 
819  Data
820  interpolateFromTable1DP(boost::python::object table, DataTypes::real_t Amin, DataTypes::real_t Astep,
821  DataTypes::real_t undef,bool check_boundaries);
822 
823  Data
824  nonuniforminterp(boost::python::object in, boost::python::object out, bool check_boundaries);
825 
826  Data
827  nonuniformslope(boost::python::object in, boost::python::object out, bool check_boundaries);
828 
835  Data
836  gradOn(const FunctionSpace& functionspace) const;
837 
838  Data
839  grad() const;
840 
845  boost::python::object
846  integrateToTuple_const() const;
847 
848 
853  boost::python::object
855 
856 
857 
863  Data
864  oneOver() const;
870  Data
871  wherePositive() const;
872 
878  Data
879  whereNegative() const;
880 
886  Data
887  whereNonNegative() const;
888 
894  Data
895  whereNonPositive() const;
896 
902  Data
903  whereZero(DataTypes::real_t tol=0.0) const;
904 
910  Data
911  whereNonZero(DataTypes::real_t tol=0.0) const;
912 
925  Lsup();
926 
928  Lsup_const() const;
929 
930 
943  sup();
944 
946  sup_const() const;
947 
948 
961  inf();
962 
964  inf_const() const;
965 
966 
967 
973  Data
974  abs() const;
975 
981  Data
982  phase() const;
983 
984 
990  Data
991  maxval() const;
992 
998  Data
999  minval() const;
1000 
1008  const boost::python::tuple
1009  minGlobalDataPoint() const;
1010 
1018  const boost::python::tuple
1019  maxGlobalDataPoint() const;
1020 
1021 
1022 
1029  Data
1030  sign() const;
1031 
1037  Data
1038  symmetric() const;
1039 
1045  Data
1046  antisymmetric() const;
1047 
1048 
1054  Data
1055  hermitian() const;
1056 
1062  Data
1063  antihermitian() const;
1064 
1070  Data
1071  trace(int axis_offset) const;
1072 
1078  Data
1079  transpose(int axis_offset) const;
1080 
1087  Data
1088  eigenvalues() const;
1089 
1099  const boost::python::tuple
1100  eigenvalues_and_eigenvectors(const DataTypes::real_t tol=1.e-12) const;
1101 
1107  Data
1108  swapaxes(const int axis0, const int axis1) const;
1109 
1115  Data
1116  erf() const;
1117 
1118 
1124  Data
1125  conjugate() const;
1126 
1127  Data
1128  real() const;
1129 
1130  Data
1131  imag() const;
1132 
1138  Data
1139  sin() const;
1140 
1146  Data
1147  cos() const;
1148 
1154  Data
1155  bessel(int order, DataTypes::real_t (*besselfunc) (int,DataTypes::real_t) );
1156 
1157 
1163  Data
1164  besselFirstKind(int order);
1165 
1171  Data
1172  besselSecondKind(int order);
1173 
1174 
1180  Data
1181  tan() const;
1182 
1188  Data
1189  asin() const;
1190 
1196  Data
1197  acos() const;
1198 
1204  Data
1205  atan() const;
1206 
1212  Data
1213  sinh() const;
1214 
1220  Data
1221  cosh() const;
1222 
1228  Data
1229  tanh() const;
1230 
1236  Data
1237  asinh() const;
1238 
1244  Data
1245  acosh() const;
1246 
1252  Data
1253  atanh() const;
1254 
1260  Data
1261  log10() const;
1262 
1268  Data
1269  log() const;
1270 
1276  Data
1277  exp() const;
1278 
1284  Data
1285  sqrt() const;
1286 
1292  Data
1293  neg() const;
1294 
1301  Data
1302  pos() const;
1303 
1311  Data
1312  powD(const Data& right) const;
1313 
1321  Data
1322  powO(const boost::python::object& right) const;
1323 
1332  Data
1333  rpowO(const boost::python::object& left) const;
1334 
1341  Data& operator+=(const Data& right);
1342  Data& operator+=(const boost::python::object& right);
1343 
1344  Data& operator=(const Data& other);
1345 
1352  Data& operator-=(const Data& right);
1353  Data& operator-=(const boost::python::object& right);
1354 
1361  Data& operator*=(const Data& right);
1362  Data& operator*=(const boost::python::object& right);
1363 
1370  Data& operator/=(const Data& right);
1371  Data& operator/=(const boost::python::object& right);
1372 
1377  Data truedivD(const Data& right);
1378 
1383  Data truedivO(const boost::python::object& right);
1384 
1389  Data rtruedivO(const boost::python::object& left);
1390 
1395  boost::python::object __add__(const boost::python::object& right);
1396 
1397 
1402  boost::python::object __sub__(const boost::python::object& right);
1403 
1408  boost::python::object __rsub__(const boost::python::object& right);
1409 
1414  boost::python::object __mul__(const boost::python::object& right);
1415 
1420  boost::python::object __div__(const boost::python::object& right);
1421 
1426  boost::python::object __rdiv__(const boost::python::object& right);
1427 
1431  Data
1432  matrixInverse() const;
1433 
1438  bool
1439  probeInterpolation(const FunctionSpace& functionspace) const;
1440 
1456  Data
1457  getItem(const boost::python::object& key) const;
1458 
1470  void
1471  setItemD(const boost::python::object& key,
1472  const Data& value);
1473 
1474  void
1475  setItemO(const boost::python::object& key,
1476  const boost::python::object& value);
1477 
1478  // These following public methods should be treated as private.
1479 
1485  template <class UnaryFunction>
1486  inline
1487  void
1488  unaryOp2(UnaryFunction operation);
1489 
1497  Data
1498  getSlice(const DataTypes::RegionType& region) const;
1499 
1508  void
1509  setSlice(const Data& value,
1510  const DataTypes::RegionType& region);
1511 
1516  void
1517  print(void);
1518 
1525  int
1526  get_MPIRank(void) const;
1527 
1534  int
1535  get_MPISize(void) const;
1536 
1542  MPI_Comm
1543  get_MPIComm(void) const;
1544 
1550  DataAbstract*
1551  borrowData(void) const;
1552 
1554  borrowDataPtr(void) const;
1555 
1557  borrowReadyPtr(void) const;
1558 
1559 
1560 
1570 
1573 
1576 
1579 
1580 
1592 
1595 
1596 
1601  size_t
1602  getNumberOfTaggedValues() const;
1603 
1604  /*
1605  * \brief make the data complex
1606  */
1607  void complicate();
1608 
1609  protected:
1610 
1611  private:
1612  void init_from_data_and_fs(const Data& inData,
1613  const FunctionSpace& functionspace);
1614 
1615  template <typename S>
1616  void
1617  maskWorker(Data& other2, Data& mask2, S sentinel);
1618 
1619  template <class BinaryOp>
1621 #ifdef ESYS_MPI
1622  lazyAlgWorker(DataTypes::real_t init, MPI_Op mpiop_type);
1623 #else
1625 #endif
1626 
1628  LsupWorker() const;
1629 
1631  supWorker() const;
1632 
1634  infWorker() const;
1635 
1636  template<typename Scalar>
1637  boost::python::object
1638  integrateWorker() const;
1639 
1640  void
1641  calc_minGlobalDataPoint(int& ProcNo, int& DataPointNo) const;
1642 
1643  void
1644  calc_maxGlobalDataPoint(int& ProcNo, int& DataPointNo) const;
1645 
1646  // For internal use in Data.cpp only!
1647  // other uses should call the main entry points and allow laziness
1648  Data
1649  minval_nonlazy() const;
1650 
1651  // For internal use in Data.cpp only!
1652  Data
1653  maxval_nonlazy() const;
1654 
1655 
1662  inline
1663  void
1664  operandCheck(const Data& right) const
1665  {
1666  return m_data->operandCheck(*(right.m_data.get()));
1667  }
1668 
1674  template <class BinaryFunction>
1675  inline
1677  reduction(BinaryFunction operation,
1678  DataTypes::real_t initial_value) const;
1679 
1687  template <class BinaryFunction>
1688  inline
1689  Data
1690  dp_algorithm(BinaryFunction operation,
1691  DataTypes::real_t initial_value) const;
1692 
1698  void
1699  typeMatchLeft(Data& right) const;
1700 
1706  void
1707  typeMatchRight(const Data& right);
1708 
1714  void
1716  const DataTypes::ShapeType& shape,
1717  const FunctionSpace& what,
1718  bool expanded);
1719 
1720  void
1722  const DataTypes::ShapeType& shape,
1723  const FunctionSpace& what,
1724  bool expanded);
1725 
1726  void
1727  initialise(const WrappedArray& value,
1728  const FunctionSpace& what,
1729  bool expanded);
1730 
1731  void
1732  initialise(const DataTypes::real_t value,
1733  const DataTypes::ShapeType& shape,
1734  const FunctionSpace& what,
1735  bool expanded);
1736 
1737  void
1738  initialise(const DataTypes::cplx_t value,
1739  const DataTypes::ShapeType& shape,
1740  const FunctionSpace& what,
1741  bool expanded);
1742  //
1743  // flag to protect the data object against any update
1745  bool m_lazy;
1746 
1747  //
1748  // pointer to the actual data object
1749 // boost::shared_ptr<DataAbstract> m_data;
1751 
1752 // If possible please use getReadyPtr instead.
1753 // But see warning below.
1754  const DataReady*
1755  getReady() const
1756 {
1757  const DataReady* dr=dynamic_cast<const DataReady*>(m_data.get());
1758  ESYS_ASSERT(dr!=0, "error casting to DataReady.");
1759  return dr;
1760 }
1761 
1762  DataReady*
1764 {
1765  DataReady* dr=dynamic_cast<DataReady*>(m_data.get());
1766  ESYS_ASSERT(dr!=0, "error casting to DataReady.");
1767  return dr;
1768 }
1769 
1770 
1771 // Be wary of using this for local operations since it (temporarily) increases reference count.
1772 // If you are just using this to call a method on DataReady instead of DataAbstract consider using
1773 // getReady() instead
1776 {
1777  DataReady_ptr dr=REFCOUNTNS::dynamic_pointer_cast<DataReady>(m_data);
1778  ESYS_ASSERT(dr.get()!=0, "error casting to DataReady.");
1779  return dr;
1780 }
1781 
1783  getReadyPtr() const
1784 {
1785  const_DataReady_ptr dr=REFCOUNTNS::dynamic_pointer_cast<const DataReady>(m_data);
1786  ESYS_ASSERT(dr.get()!=0, "error casting to DataReady.");
1787  return dr;
1788 }
1789 
1790  // In the isShared() method below:
1791  // A problem would occur if m_data (the address pointed to) were being modified
1792  // while the call m_data->is_shared is being executed.
1793  //
1794  // Q: So why do I think this code can be thread safe/correct?
1795  // A: We need to make some assumptions.
1796  // 1. We assume it is acceptable to return true under some conditions when we aren't shared.
1797  // 2. We assume that no constructions or assignments which will share previously unshared
1798  // will occur while this call is executing. This is consistent with the way Data:: and C are written.
1799  //
1800  // This means that the only transition we need to consider, is when a previously shared object is
1801  // not shared anymore. ie. the other objects have been destroyed or a deep copy has been made.
1802  // In those cases the m_shared flag changes to false after m_data has completed changing.
1803  // For any threads executing before the flag switches they will assume the object is still shared.
1804  bool isShared() const
1805  {
1806 #ifdef SLOWSHARECHECK
1807  return m_data->isShared(); // single threadsafe check for this
1808 #else
1809  return !m_data.unique();
1810 #endif
1811  }
1812 
1814  {
1815  if (isLazy())
1816  {
1817  #ifdef _OPENMP
1818  if (omp_in_parallel())
1819  { // Yes this is throwing an exception out of an omp thread which is forbidden.
1820  throw DataException("Please do not call forceResolve() in a parallel region.");
1821  }
1822  #endif
1823  resolve();
1824  }
1825  }
1826 
1832  {
1833 #ifdef _OPENMP
1834  if (omp_in_parallel())
1835  {
1836  throw DataException("Programming error. Please do not run exclusiveWrite() in multi-threaded sections.");
1837  }
1838 #endif
1839  forceResolve();
1840  if (isShared())
1841  {
1842  DataAbstract* t=m_data->deepCopy();
1844  }
1845 #ifdef EXWRITECHK
1846  m_data->exclusivewritecalled=true;
1847 #endif
1848  }
1849 
1854  {
1855  if (isLazy() || isShared())
1856  {
1857  std::ostringstream oss;
1858  oss << "Programming error. ExclusiveWrite required - please call requireWrite() isLazy=" << isLazy() << " isShared()=" << isShared();
1859  throw DataException(oss.str());
1860  }
1861  }
1862 
1869  void set_m_data(DataAbstract_ptr p);
1870 
1871 
1872  void TensorSelfUpdateBinaryOperation(const Data& right, escript::ES_optype operation);
1873 
1874  friend class DataAbstract; // To allow calls to updateShareStatus
1875  friend class TestDomain; // so its getX will work quickly
1876 #ifdef IKNOWWHATIMDOING
1877  friend Data applyBinaryCFunction(boost::python::object cfunc, boost::python::tuple shape, escript::Data& d, escript::Data& e);
1878 #endif
1879  template <typename S>
1880  friend Data condEvalWorker(escript::Data& mask, escript::Data& trueval, escript::Data& falseval, S sentinel);
1881  friend Data randomData(const boost::python::tuple& shape, const FunctionSpace& what, long seed, const boost::python::tuple& filter);
1882 
1883 };
1884 
1885 
1886 #ifdef IKNOWWHATIMDOING
1887 Data
1888 applyBinaryCFunction(boost::python::object func, boost::python::tuple shape, escript::Data& d, escript::Data& e);
1889 #endif
1890 
1891 Data
1892 condEval(escript::Data& mask, escript::Data& trueval, escript::Data& falseval);
1893 
1894 
1895 
1899 Data randomData(const boost::python::tuple& shape,
1900  const FunctionSpace& what,
1901  long seed, const boost::python::tuple& filter);
1902 
1903 
1904 } // end namespace escript
1905 
1906 
1907 // No, this is not supposed to be at the top of the file
1908 // DataAbstact needs to be declared first, then DataReady needs to be fully declared
1909 // so that I can dynamic cast between them below.
1910 #include "DataReady.h"
1911 #include "DataLazy.h"
1912 #include "DataExpanded.h"
1913 #include "DataConstant.h"
1914 #include "DataTagged.h"
1915 
1916 namespace escript
1917 {
1918 
1919 
1920 
1921 inline
1924 {
1925  if (isLazy())
1926  {
1927  throw DataException("Error, attempt to acquire RW access to lazy data. Please call requireWrite() first.");
1928  }
1929 #ifdef EXWRITECHK
1930  if (!getReady()->exclusivewritecalled)
1931  {
1932  throw DataException("Error, call to Data::getSampleDataRW without a preceeding call to requireWrite/exclusiveWrite.");
1933  }
1934 #endif
1935  return getReady()->getSampleDataRW(sampleNo, dummy);
1936 }
1937 
1938 inline
1941 {
1942  if (isLazy())
1943  {
1944  throw DataException("Error, attempt to acquire RW access to lazy data. Please call requireWrite() first.");
1945  }
1946 #ifdef EXWRITECHK
1947  if (!getReady()->exclusivewritecalled)
1948  {
1949  throw DataException("Error, call to Data::getSampleDataRW without a preceeding call to requireWrite/exclusiveWrite.");
1950  }
1951 #endif
1952  return getReady()->getSampleDataRW(sampleNo, dummy);
1953 }
1954 
1955 
1956 inline
1957 const DataTypes::real_t*
1959 {
1960  DataLazy* l=dynamic_cast<DataLazy*>(m_data.get());
1961  if (l!=0)
1962  {
1963  size_t offset=0;
1964  const DataTypes::RealVectorType* res=l->resolveSample(sampleNo,offset);
1965  return &((*res)[offset]);
1966  }
1967  return getReady()->getSampleDataRO(sampleNo, dummy);
1968 }
1969 
1970 inline
1971 const DataTypes::cplx_t*
1973 {
1974  DataLazy* l=dynamic_cast<DataLazy*>(m_data.get());
1975  if (l!=0)
1976  {
1977  throw DataException("Programming error: complex lazy objects are not supported.");
1978  }
1979  return getReady()->getSampleDataRO(sampleNo, dummy);
1980 }
1981 
1982 
1983 inline
1984 const DataTypes::real_t*
1986 {
1987  if (isLazy())
1988  {
1989  throw DataException("Programmer error - getDataRO must not be called on Lazy Data.");
1990  }
1991  if (getNumSamples()==0)
1992  {
1993  return 0;
1994  }
1995  else
1996  {
1997  return &(getReady()->getTypedVectorRO(0)[0]);
1998  }
1999 }
2000 
2001 inline
2002 const DataTypes::cplx_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(dummy)[0]);
2016  }
2017 }
2018 
2019 
2024 {
2025  return pow(y,x);
2026 }
2027 
2033 Data operator+(const Data& left, const Data& right);
2034 
2040 Data operator-(const Data& left, const Data& right);
2041 
2047 Data operator*(const Data& left, const Data& right);
2048 
2054 Data operator/(const Data& left, const Data& right);
2055 
2062 Data operator+(const Data& left, const boost::python::object& right);
2063 
2070 Data operator-(const Data& left, const boost::python::object& right);
2071 
2078 Data operator*(const Data& left, const boost::python::object& right);
2079 
2086 Data operator/(const Data& left, const boost::python::object& right);
2087 
2094 Data operator+(const boost::python::object& left, const Data& right);
2095 
2102 Data operator-(const boost::python::object& left, const Data& right);
2103 
2110 Data operator*(const boost::python::object& left, const Data& right);
2111 
2118 Data operator/(const boost::python::object& left, const Data& right);
2119 
2120 
2121 
2126 std::ostream& operator<<(std::ostream& o, const Data& data);
2127 
2136 Data
2138  Data& arg_1,
2139  int axis_offset=0,
2140  int transpose=0);
2141 
2147 inline
2148 Data
2149 Data::truedivD(const Data& right)
2150 {
2151  return *this / right;
2152 }
2153 
2159 inline
2160 Data
2161 Data::truedivO(const boost::python::object& right)
2162 {
2163  Data tmp(right, getFunctionSpace(), false);
2164  return truedivD(tmp);
2165 }
2166 
2172 inline
2173 Data
2174 Data::rtruedivO(const boost::python::object& left)
2175 {
2176  Data tmp(left, getFunctionSpace(), false);
2177  return tmp.truedivD(*this);
2178 }
2179 
2180 
2181 
2189 template <class BinaryFunction>
2190 inline
2192 Data::reduction(BinaryFunction operation, DataTypes::real_t initial_value) const
2193 {
2194  if (isExpanded()) {
2195  DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
2196  ESYS_ASSERT(leftC!=0, "Programming error - casting to DataExpanded.");
2197 
2198  DataExpanded& data=*leftC;
2199  int i,j;
2200  int numDPPSample=data.getNumDPPSample();
2201  int numSamples=data.getNumSamples();
2202  DataTypes::real_t global_current_value=initial_value;
2203  DataTypes::real_t local_current_value;
2204  const auto& vec=data.getTypedVectorRO(typename BinaryFunction::first_argument_type(0));
2205  const DataTypes::ShapeType& shape=data.getShape();
2206  // calculate the reduction operation value for each data point
2207  // reducing the result for each data-point into the current_value variables
2208  #pragma omp parallel private(local_current_value)
2209  {
2210  local_current_value=initial_value;
2211  #pragma omp for private(i,j) schedule(static)
2212  for (i=0;i<numSamples;i++) {
2213  for (j=0;j<numDPPSample;j++) {
2214  local_current_value=operation(local_current_value,escript::reductionOpVector(vec,shape,data.getPointOffset(i,j),operation,initial_value));
2215 
2216  }
2217  }
2218  #pragma omp critical
2219  global_current_value=operation(global_current_value,local_current_value);
2220  }
2221  return global_current_value;
2222  } else if (isTagged()) {
2223  DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
2224  ESYS_ASSERT(leftC!=0, "Programming error - casting to DataTagged.");
2225 
2226  DataTagged& data=*leftC;
2227  DataTypes::real_t current_value=initial_value;
2228 
2229  const auto& vec=data.getTypedVectorRO(typename BinaryFunction::first_argument_type(0));
2230  const DataTypes::ShapeType& shape=data.getShape();
2231  const DataTagged::DataMapType& lookup=data.getTagLookup();
2232  const std::list<int> used=data.getFunctionSpace().getListOfTagsSTL();
2233  for (std::list<int>::const_iterator i=used.begin();i!=used.end();++i)
2234  {
2235  int tag=*i;
2236  DataTagged::DataMapType::const_iterator it=lookup.find(tag);
2237  if ((tag==0) || (it==lookup.end())) // check for the default tag
2238  {
2239  current_value=operation(current_value,escript::reductionOpVector(vec,shape,data.getDefaultOffset(),operation,initial_value));
2240  }
2241  else
2242  {
2243  current_value=operation(current_value,escript::reductionOpVector(vec,shape,it->second,operation,initial_value));
2244  }
2245  }
2246  return current_value;
2247  } else if (isConstant()) {
2248  DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
2249  ESYS_ASSERT(leftC!=0, "Programming error - casting to DataConstant.");
2250  return escript::reductionOpVector(leftC->getTypedVectorRO(typename BinaryFunction::first_argument_type(0)),leftC->getShape(),0,operation,initial_value);
2251  } else if (isEmpty()) {
2252  throw DataException("Error - Operations (algorithm) not permitted on instances of DataEmpty.");
2253  } else if (isLazy()) {
2254  throw DataException("Error - Operations not permitted on instances of DataLazy.");
2255  } else {
2256  throw DataException("Error - Data encapsulates an unknown type.");
2257  }
2258 }
2259 
2268 template <class BinaryFunction>
2269 inline
2270 Data
2271 Data::dp_algorithm(BinaryFunction operation, DataTypes::real_t initial_value) const
2272 {
2273  if (isEmpty()) {
2274  throw DataException("Error - Operations (dp_algorithm) not permitted on instances of DataEmpty.");
2275  }
2276  else if (isExpanded()) {
2278  DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
2279  DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
2280  ESYS_ASSERT(dataE!=0, "Programming error - casting data to DataExpanded.");
2281  ESYS_ASSERT(resultE!=0, "Programming error - casting result to DataExpanded.");
2282 
2283 
2284 
2285  int i,j;
2286  int numSamples=dataE->getNumSamples();
2287  int numDPPSample=dataE->getNumDPPSample();
2288  // DataArrayView dataView=data.getPointDataView();
2289  // DataArrayView resultView=result.getPointDataView();
2290  const auto& dataVec=dataE->getTypedVectorRO(initial_value);
2291  const DataTypes::ShapeType& shape=dataE->getShape();
2292  auto& resultVec=resultE->getTypedVectorRW(initial_value);
2293  // perform the operation on each data-point and assign
2294  // this to the corresponding element in result
2295  #pragma omp parallel for private(i,j) schedule(static)
2296  for (i=0;i<numSamples;i++) {
2297  for (j=0;j<numDPPSample;j++) {
2298  resultVec[resultE->getPointOffset(i,j)] =
2299  escript::reductionOpVector(dataVec, shape, dataE->getPointOffset(i,j),operation,initial_value);
2300 
2301  }
2302  }
2303  //escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
2304  return result;
2305  }
2306  else if (isTagged()) {
2307  DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
2308  ESYS_ASSERT(dataT!=0, "Programming error - casting data to DataTagged.");
2309  DataTypes::RealVectorType defval(1);
2310  defval[0]=0;
2311  DataTagged* resultT=new DataTagged(getFunctionSpace(), DataTypes::scalarShape, defval, dataT);
2312 
2313 
2314  const DataTypes::ShapeType& shape=dataT->getShape();
2315  const auto& vec=dataT->getTypedVectorRO(initial_value);
2316  const DataTagged::DataMapType& lookup=dataT->getTagLookup();
2317  for (DataTagged::DataMapType::const_iterator i=lookup.begin(); i!=lookup.end(); i++) {
2318  resultT->getDataByTagRW(i->first,0) =
2319  escript::reductionOpVector(vec,shape,dataT->getOffsetForTag(i->first),operation,initial_value);
2320  }
2321  resultT->getTypedVectorRW(initial_value)[resultT->getDefaultOffset()] = escript::reductionOpVector(dataT->getTypedVectorRO(initial_value),dataT->getShape(),dataT->getDefaultOffset(),operation,initial_value);
2322 
2323 
2324 
2325 
2326  //escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
2327  return Data(resultT); // note: the Data object now owns the resultT pointer
2328  }
2329  else if (isConstant()) {
2331  DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
2332  DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
2333  ESYS_ASSERT(dataC!=0, "Programming error - casting data to DataConstant.");
2334  ESYS_ASSERT(resultC!=0, "Programming error - casting result to DataConstant.");
2335 
2336  DataConstant& data=*dataC;
2337  resultC->getTypedVectorRW(initial_value)[0] =
2338  escript::reductionOpVector(data.getTypedVectorRO(initial_value),data.getShape(),0,operation,initial_value);
2339 
2340  //escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
2341  return result;
2342  } else if (isLazy()) {
2343  throw DataException("Error - Operations not permitted on instances of DataLazy.");
2344  } else {
2345  throw DataException("Error - Data encapsulates an unknown type.");
2346  }
2347 }
2348 
2349 
2357 Data
2358 C_TensorBinaryOperation(Data const &arg_0,
2359  Data const &arg_1,
2360  ES_optype operation);
2361 
2362 
2363 Data
2364 C_TensorUnaryOperation(Data const &arg_0,
2365  escript::ES_optype operation,
2366  DataTypes::real_t tol=0);
2367 
2368 } // namespace escript
2369 
2370 #endif // __ESCRIPT_DATA_H__
2371 
Definition: FunctionSpace.h:34
std::ostream & operator<<(std::ostream &o, const Data &data)
Output operator.
Definition: Data.cpp:3602
void typeMatchLeft(Data &right) const
Convert the data type of the RHS to match this.
Definition: Data.cpp:3448
DataAbstract_ptr m_data
Definition: Data.h:1750
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:631
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:3409
Data antihermitian() const
Return the anti-hermitian part of a matrix which is half the matrix minus its hermitian.
Definition: Data.cpp:2727
Data interpolateFromTable1D(const WrappedArray &table, DataTypes::real_t Amin, DataTypes::real_t Astep, DataTypes::real_t undef, bool check_boundaries)
Definition: Data.cpp:4684
boost::python::object __add__(const boost::python::object &right)
wrapper for python add operation
Definition: Data.cpp:5831
const_DataReady_ptr getReadyPtr() const
Definition: Data.h:1783
void checkExclusiveWrite()
checks if caller can have exclusive write to the object
Definition: Data.h:1853
boost::python::object __rsub__(const boost::python::object &right)
wrapper for python reverse subtract operation
Definition: Data.cpp:5879
std::string toString() const
Write the data as a string. For large amounts of data, a summary is printed.
Definition: Data.cpp:4562
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:2023
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:489
int MPI_Op
Definition: EsysMPI.h:43
Data delay()
produce a delayed evaluation version of this Data.
Definition: Data.cpp:768
Data & operator*=(const Data &right)
Overloaded operator *=.
Definition: Data.cpp:3156
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:544
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:1438
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:3401
DataTypes::real_t supWorker() const
Definition: Data.cpp:2456
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:3417
Data operator-(const Data &left, const Data &right)
Operator- Takes two Data objects.
Definition: Data.cpp:3278
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:5382
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:5306
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:4656
void typeMatchRight(const Data &right)
Convert the data type of this to match the RHS.
Definition: Data.cpp:3468
void setSlice(const Data &value, const DataTypes::RegionType &region)
Copy the specified slice from the given value into this Data object.
Definition: Data.cpp:3433
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:4632
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:5998
DataAbstract_ptr borrowDataPtr(void) const
Definition: Data.cpp:4547
Data real() const
Definition: Data.cpp:1948
virtual const DataTypes::RealVectorType & getTypedVectorRO(DataTypes::real_t dummy) const
Definition: DataConstant.cpp:786
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:3496
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:1591
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:1775
void TensorSelfUpdateBinaryOperation(const Data &right, escript::ES_optype operation)
Definition: Data.cpp:6450
DataTypes::RealVectorType::reference getDataByTagRW(int tag, DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0)
getDataByTag
Definition: DataTagged.cpp:932
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:3242
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:4675
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:3553
Data nonuniformslope(boost::python::object in, boost::python::object out, bool check_boundaries)
Definition: Data.cpp:5227
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:5855
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:4666
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:181
Data getItem(const boost::python::object &key) const
Returns a slice from this Data object.
Definition: Data.cpp:3387
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:2566
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:1985
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:3609
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:4609
bool m_protected
Definition: Data.h:1744
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:3214
Data & operator/=(const Data &right)
Overloaded operator /=.
Definition: Data.cpp:3183
DataReady * getReady()
Definition: Data.h:1763
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:2916
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:1664
DataAbstract * borrowData(void) const
return the object produced by the factory, which is a DataConstant or DataExpanded TODO Ownership of ...
Definition: Data.cpp:4540
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:2499
int getNoValues() const
Return the number of values in the shape for this object.
Definition: Data.h:557
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:534
boost::python::object integrateWorker() const
Data rtruedivO(const boost::python::object &left)
Newer style division operator for python.
Definition: Data.h:2174
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:3002
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:1958
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:3256
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:2767
DataTypes::RealVectorType::size_type getOffsetForTag(int tag) const
getOffsetForTag
Definition: DataTagged.cpp:910
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:2899
Data minval_nonlazy() const
Definition: Data.cpp:2544
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:5358
const DataTypes::ShapeType & getDataPointShape() const
Return a reference to the data point shape.
Definition: Data.h:682
const FunctionSpace & getFunctionSpace() const
Return the function space.
Definition: Data.h:452
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:2822
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:5370
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:2192
Data operator+(const Data &left, const Data &right)
Operator+ Takes two Data objects.
Definition: Data.cpp:3268
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:4648
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:779
DataTypes::RealVectorType::reference getDataAtOffsetRW(DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy)
Definition: Data.cpp:4601
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
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:1804
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:532
const DataTypes::RealVectorType * resolveSample(int sampleNo, size_t &roffset) const
Compute the value of the expression for the given sample.
Definition: DataLazy.cpp:2334
DataReady_ptr borrowReadyPtr(void) const
Definition: Data.cpp:4554
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:3121
void forceResolve()
Definition: Data.h:1813
DataTypes::cplx_t * getSampleDataByTag(int tag, DataTypes::cplx_t dummy)
Definition: Data.h:638
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:521
const DataReady * getReady() const
Definition: Data.h:1755
DataTypes::RealVectorType::size_type getDefaultOffset() const
Returns the offset in the structure which stores the default value.
Definition: DataTagged.h:703
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:1923
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:2700
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:1584
DataTypes::real_t LsupWorker() const
Definition: Data.cpp:2399
Data minval() const
Return the minimum value of each data point of this Data object.
Definition: Data.cpp:2575
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:6274
bool m_lazy
Definition: Data.h:1745
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:195
int getNumSamples() const
Return the number of samples.
Definition: Data.h:510
boost::python::object __div__(const boost::python::object &right)
wrapper for python divide operation
Definition: Data.cpp:5928
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:2271
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:2873
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:3592
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:5976
Data nonuniforminterp(boost::python::object in, boost::python::object out, bool check_boundaries)
Definition: Data.cpp:5151
virtual const DataTypes::RealVectorType & getTypedVectorRO(DataTypes::real_t dummy) const
Definition: DataExpanded.cpp:1444
Data maxval_nonlazy() const
Definition: Data.cpp:2555
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:5567
Data powO(const boost::python::object &right) const
Return the given power of each data point of this boost python object.
Definition: Data.cpp:3249
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:1831
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:714
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:464
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:4812
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:5336
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:5952
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:670
Data operator/(const Data &left, const Data &right)
Operator/ Takes two Data objects.
Definition: Data.cpp:3297
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:5904
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:5778
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:741
Data truedivO(const boost::python::object &right)
Newer style division operator for python.
Definition: Data.h:2161
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:2641
#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:5760
int getNumDataPoints() const
Return the number of data points.
Definition: Data.h:500
Data antisymmetric() const
Return the antisymmetric part of a matrix which is half the matrix minus its transpose.
Definition: Data.cpp:2664
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:4968
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:2149
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:3129
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:3012
Data eigenvalues() const
Return the eigenvalues of the symmetric part at each data point of this Data object in increasing val...
Definition: Data.cpp:2846
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:3513
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:2584
Domain_ptr getDomainPython() const
Return the domain. TODO: For internal use only. This should be removed.
Definition: Data.h:478
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:3093