/[escript]/branches/schroedinger/escript/src/Data.cpp
ViewVC logotype

Diff of /branches/schroedinger/escript/src/Data.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1910 by jfenwick, Thu Oct 23 03:05:28 2008 UTC revision 1911 by jfenwick, Thu Oct 23 04:50:35 2008 UTC
# Line 43  using namespace boost; Line 43  using namespace boost;
43  using namespace escript;  using namespace escript;
44    
45  // ensure the current object is not a DataLazy  // ensure the current object is not a DataLazy
46    // The idea was that we could add an optional warning whenever a resolve is forced
47  #define FORCERESOLVE if (isLazy()) {resolve();}  #define FORCERESOLVE if (isLazy()) {resolve();}
48    
49  Data::Data()  Data::Data()
# Line 96  Data::Data(const Data& inData) Line 97  Data::Data(const Data& inData)
97  Data::Data(const Data& inData,  Data::Data(const Data& inData,
98             const DataTypes::RegionType& region)             const DataTypes::RegionType& region)
99  {  {
100      DataAbstract_ptr dat=inData.m_data;
101      if (inData.isLazy())
102      {
103        dat=inData.m_data->resolve();
104      }
105      else
106      {
107        dat=inData.m_data;
108      }
109    //    //
110    // Create Data which is a slice of another Data    // Create Data which is a slice of another Data
111    DataAbstract* tmp = inData.m_data->getSlice(region);    DataAbstract* tmp = dat->getSlice(region);
112    m_data=DataAbstract_ptr(tmp);    m_data=DataAbstract_ptr(tmp);
113    m_protected=false;    m_protected=false;
114  }  }
# Line 112  Data::Data(const Data& inData, Line 122  Data::Data(const Data& inData,
122    }    }
123    if (inData.isLazy())    if (inData.isLazy())
124    {    {
125      throw DataException("Error - will not interpolate for instances of DataLazy - yet.");      FORCERESOLVE;
126    //     throw DataException("Error - will not interpolate for instances of DataLazy - yet.");
127    }    }
128    if (inData.getFunctionSpace()==functionspace) {    if (inData.getFunctionSpace()==functionspace) {
129      m_data=inData.m_data;      m_data=inData.m_data;
# Line 1595  Data::symmetric() const Line 1606  Data::symmetric() const
1606       else {       else {
1607          throw DataException("Error - Data::symmetric can only be calculated for rank 2 or 4 object.");          throw DataException("Error - Data::symmetric can only be calculated for rank 2 or 4 object.");
1608       }       }
1609         if (isLazy())
1610         {
1611        Data temp(*this);   // to get around the fact that you can't resolve a const Data
1612        temp.resolve();
1613        return temp.symmetric();
1614         }
1615       Data ev(0.,getDataPointShape(),getFunctionSpace());       Data ev(0.,getDataPointShape(),getFunctionSpace());
1616       ev.typeMatchRight(*this);       ev.typeMatchRight(*this);
1617       m_data->symmetric(ev.m_data.get());       m_data->symmetric(ev.m_data.get());
# Line 1604  Data::symmetric() const Line 1621  Data::symmetric() const
1621  Data  Data
1622  Data::nonsymmetric() const  Data::nonsymmetric() const
1623  {  {
1624         if (isLazy())
1625         {
1626        Data temp(*this);   // to get around the fact that you can't resolve a const Data
1627        temp.resolve();
1628        return temp.nonsymmetric();
1629         }
1630       // check input       // check input
1631       DataTypes::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1632       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
# Line 1638  Data::nonsymmetric() const Line 1661  Data::nonsymmetric() const
1661  Data  Data
1662  Data::trace(int axis_offset) const  Data::trace(int axis_offset) const
1663  {  {
1664         if (isLazy())
1665         {
1666        Data temp(*this);   // to get around the fact that you can't resolve a const Data
1667        temp.resolve();
1668        return temp.trace(axis_offset);
1669         }
1670       DataTypes::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1671       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1672          DataTypes::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
# Line 1687  Data::trace(int axis_offset) const Line 1716  Data::trace(int axis_offset) const
1716    
1717  Data  Data
1718  Data::transpose(int axis_offset) const  Data::transpose(int axis_offset) const
1719  {  {    
1720         if (isLazy())
1721         {
1722        Data temp(*this);   // to get around the fact that you can't resolve a const Data
1723        temp.resolve();
1724        return temp.transpose(axis_offset);
1725         }
1726       DataTypes::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1727       DataTypes::ShapeType ev_shape;       DataTypes::ShapeType ev_shape;
1728       // Here's the equivalent of python s_out=s[axis_offset:]+s[:axis_offset]       // Here's the equivalent of python s_out=s[axis_offset:]+s[:axis_offset]
# Line 1709  Data::transpose(int axis_offset) const Line 1744  Data::transpose(int axis_offset) const
1744  Data  Data
1745  Data::eigenvalues() const  Data::eigenvalues() const
1746  {  {
1747         if (isLazy())
1748         {
1749        Data temp(*this);   // to get around the fact that you can't resolve a const Data
1750        temp.resolve();
1751        return temp.eigenvalues();
1752         }
1753       // check input       // check input
1754       DataTypes::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1755       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
# Line 1726  Data::eigenvalues() const Line 1767  Data::eigenvalues() const
1767  const boost::python::tuple  const boost::python::tuple
1768  Data::eigenvalues_and_eigenvectors(const double tol) const  Data::eigenvalues_and_eigenvectors(const double tol) const
1769  {  {
1770         if (isLazy())
1771         {
1772        Data temp(*this);   // to get around the fact that you can't resolve a const Data
1773        temp.resolve();
1774        return temp.eigenvalues_and_eigenvectors(tol);
1775         }
1776       DataTypes::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1777       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
1778          throw DataException("Error - Data::eigenvalues and eigenvectors can only be calculated for rank 2 object.");          throw DataException("Error - Data::eigenvalues and eigenvectors can only be calculated for rank 2 object.");
# Line 1759  void Line 1806  void
1806  Data::calc_minGlobalDataPoint(int& ProcNo,  Data::calc_minGlobalDataPoint(int& ProcNo,
1807                          int& DataPointNo) const                          int& DataPointNo) const
1808  {  {
1809      if (isLazy())
1810      {
1811        Data temp(*this);   // to get around the fact that you can't resolve a const Data
1812        temp.resolve();
1813        return temp.calc_minGlobalDataPoint(ProcNo,DataPointNo);
1814      }
1815    int i,j;    int i,j;
1816    int lowi=0,lowj=0;    int lowi=0,lowj=0;
1817    double min=numeric_limits<double>::max();    double min=numeric_limits<double>::max();
# Line 1825  Data::saveDX(std::string fileName) const Line 1878  Data::saveDX(std::string fileName) const
1878    {    {
1879      throw DataException("Error - Operations not permitted on instances of DataEmpty.");      throw DataException("Error - Operations not permitted on instances of DataEmpty.");
1880    }    }
1881      if (isLazy())
1882      {
1883         Data temp(*this);  // to get around the fact that you can't resolve a const Data
1884         temp.resolve();
1885         temp.saveDX(fileName);
1886         return;
1887      }
1888    boost::python::dict args;    boost::python::dict args;
1889    args["data"]=boost::python::object(this);    args["data"]=boost::python::object(this);
1890    getDomain()->saveDX(fileName,args);    getDomain()->saveDX(fileName,args);
# Line 1838  Data::saveVTK(std::string fileName) cons Line 1898  Data::saveVTK(std::string fileName) cons
1898    {    {
1899      throw DataException("Error - Operations not permitted on instances of DataEmpty.");      throw DataException("Error - Operations not permitted on instances of DataEmpty.");
1900    }    }
1901      if (isLazy())
1902      {
1903         Data temp(*this);  // to get around the fact that you can't resolve a const Data
1904         temp.resolve();
1905         temp.saveVTK(fileName);
1906         return;
1907      }
1908    boost::python::dict args;    boost::python::dict args;
1909    args["data"]=boost::python::object(this);    args["data"]=boost::python::object(this);
1910    getDomain()->saveVTK(fileName,args);    getDomain()->saveVTK(fileName,args);
# Line 2248  Data::setSlice(const Data& value, Line 2315  Data::setSlice(const Data& value,
2315    if (isProtected()) {    if (isProtected()) {
2316          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
2317    }    }
2318    if (isLazy())    FORCERESOLVE;
2319    /*  if (isLazy())
2320    {    {
2321      throw DataException("Error - setSlice not permitted on lazy data.");      throw DataException("Error - setSlice not permitted on lazy data.");
2322    }    }*/
2323    Data tempValue(value);    Data tempValue(value);
2324    typeMatchLeft(tempValue);    typeMatchLeft(tempValue);
2325    typeMatchRight(tempValue);    typeMatchRight(tempValue);
# Line 2261  Data::setSlice(const Data& value, Line 2329  Data::setSlice(const Data& value,
2329  void  void
2330  Data::typeMatchLeft(Data& right) const  Data::typeMatchLeft(Data& right) const
2331  {  {
2332      if (right.isLazy() && !isLazy())
2333      {
2334        right.resolve();
2335      }
2336    if (isExpanded()){    if (isExpanded()){
2337      right.expand();      right.expand();
2338    } else if (isTagged()) {    } else if (isTagged()) {
# Line 2273  Data::typeMatchLeft(Data& right) const Line 2345  Data::typeMatchLeft(Data& right) const
2345  void  void
2346  Data::typeMatchRight(const Data& right)  Data::typeMatchRight(const Data& right)
2347  {  {
2348      if (isLazy() && !right.isLazy())
2349      {
2350        resolve();
2351      }
2352    if (isTagged()) {    if (isTagged()) {
2353      if (right.isExpanded()) {      if (right.isExpanded()) {
2354        expand();        expand();
# Line 2366  escript::C_GeneralTensorProduct(Data& ar Line 2442  escript::C_GeneralTensorProduct(Data& ar
2442    // General tensor product: res(SL x SR) = arg_0(SL x SM) * arg_1(SM x SR)    // General tensor product: res(SL x SR) = arg_0(SL x SM) * arg_1(SM x SR)
2443    // SM is the product of the last axis_offset entries in arg_0.getShape().    // SM is the product of the last axis_offset entries in arg_0.getShape().
2444    
2445      // deal with any lazy data
2446      if (arg_0.isLazy()) {arg_0.resolve();}
2447      if (arg_1.isLazy()) {arg_1.resolve();}
2448    
2449    // Interpolate if necessary and find an appropriate function space    // Interpolate if necessary and find an appropriate function space
2450    Data arg_0_Z, arg_1_Z;    Data arg_0_Z, arg_1_Z;
2451    if (arg_0.getFunctionSpace()!=arg_1.getFunctionSpace()) {    if (arg_0.getFunctionSpace()!=arg_1.getFunctionSpace()) {

Legend:
Removed from v.1910  
changed lines
  Added in v.1911

  ViewVC Help
Powered by ViewVC 1.1.26