/[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 1863 by jfenwick, Wed Oct 8 00:28:28 2008 UTC revision 1864 by jfenwick, Thu Oct 9 03:09:30 2008 UTC
# Line 18  Line 18 
18  #include "DataConstant.h"  #include "DataConstant.h"
19  #include "DataTagged.h"  #include "DataTagged.h"
20  #include "DataEmpty.h"  #include "DataEmpty.h"
21    #include "DataLazy.h"
22  #include "FunctionSpaceFactory.h"  #include "FunctionSpaceFactory.h"
23  #include "AbstractContinuousDomain.h"  #include "AbstractContinuousDomain.h"
24  #include "UnaryFuncs.h"  #include "UnaryFuncs.h"
# Line 106  Data::Data(const Data& inData, Line 107  Data::Data(const Data& inData,
107    {    {
108      throw DataException("Error - will not interpolate for instances of DataEmpty.");      throw DataException("Error - will not interpolate for instances of DataEmpty.");
109    }    }
110      if (inData.isLazy())
111      {
112        throw DataException("Error - will not interpolate for instances of DataLazy - yet.");
113      }
114    if (inData.getFunctionSpace()==functionspace) {    if (inData.getFunctionSpace()==functionspace) {
115      m_data=inData.m_data;      m_data=inData.m_data;
116    } else if (inData.isConstant()) { // for a constant function, we just need to use the new function space    }
117      if (!inData.probeInterpolation(functionspace))    else
118      {           // Even though this is constant, we still need to check whether interpolation is allowed    {             // this cast is safe for ref count because the class holds a reference
119        const DataReady* dr=dynamic_cast<const DataReady*>(inData.m_data.get());
120        if (inData.isConstant()) {  // for a constant function, we just need to use the new function space
121          if (!inData.probeInterpolation(functionspace))
122          {           // Even though this is constant, we still need to check whether interpolation is allowed
123      throw FunctionSpaceException("Call to probeInterpolation returned false for DataConstant.");      throw FunctionSpaceException("Call to probeInterpolation returned false for DataConstant.");
124      }        }
125      DataConstant* dc=new DataConstant(functionspace,inData.m_data->getShape(),inData.m_data->getVector());          DataConstant* dc=new DataConstant(functionspace,inData.m_data->getShape(),dr->getVector());  
126      m_data=DataAbstract_ptr(dc);        m_data=DataAbstract_ptr(dc);
   } else {  
     Data tmp(0,inData.getDataPointShape(),functionspace,true);  
     // Note: Must use a reference or pointer to a derived object  
     // in order to get polymorphic behaviour. Shouldn't really  
     // be able to create an instance of AbstractDomain but that was done  
     // as a boost:python work around which may no longer be required.  
     /*const AbstractDomain& inDataDomain=inData.getDomain();*/  
     const_Domain_ptr inDataDomain=inData.getDomain();  
     if  (inDataDomain==functionspace.getDomain()) {  
       inDataDomain->interpolateOnDomain(tmp,inData);  
127      } else {      } else {
128        inDataDomain->interpolateACross(tmp,inData);        Data tmp(0,inData.getDataPointShape(),functionspace,true);
129          // Note: Must use a reference or pointer to a derived object
130          // in order to get polymorphic behaviour. Shouldn't really
131          // be able to create an instance of AbstractDomain but that was done
132          // as a boost:python work around which may no longer be required.
133          /*const AbstractDomain& inDataDomain=inData.getDomain();*/
134          const_Domain_ptr inDataDomain=inData.getDomain();
135          if  (inDataDomain==functionspace.getDomain()) {
136            inDataDomain->interpolateOnDomain(tmp,inData);
137          } else {
138            inDataDomain->interpolateACross(tmp,inData);
139          }
140          m_data=tmp.m_data;
141      }      }
     m_data=tmp.m_data;  
142    }    }
143    m_protected=false;    m_protected=false;
144  }  }
# Line 422  Data::copy(const Data& other) Line 432  Data::copy(const Data& other)
432  }  }
433    
434    
435    Data
436    Data::delay()
437    {
438      DataLazy* dl=new DataLazy(m_data);
439      return Data(dl);
440    }
441    
442  void  void
443  Data::setToZero()  Data::setToZero()
444  {  {
# Line 501  Data::isConstant() const Line 518  Data::isConstant() const
518    return (temp!=0);    return (temp!=0);
519  }  }
520    
521    bool
522    Data::isLazy() const
523    {
524      return m_data->isLazy();
525    }
526    
527    
528  void  void
529  Data::setProtection()  Data::setProtection()
530  {  {
# Line 1867  Data::setSlice(const Data& value, Line 1891  Data::setSlice(const Data& value,
1891    if (isProtected()) {    if (isProtected()) {
1892          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
1893    }    }
1894      if (isLazy())
1895      {
1896        throw DataException("Error - setSlice not permitted on lazy data.");
1897      }
1898    Data tempValue(value);    Data tempValue(value);
1899    typeMatchLeft(tempValue);    typeMatchLeft(tempValue);
1900    typeMatchRight(tempValue);    typeMatchRight(tempValue);
1901    m_data->setSlice(tempValue.m_data.get(),region);    getReady()->setSlice(tempValue.m_data.get(),region);
1902  }  }
1903    
1904  void  void
# Line 2399  Data::toString() const Line 2427  Data::toString() const
2427  DataTypes::ValueType::const_reference  DataTypes::ValueType::const_reference
2428  Data::getDataAtOffset(DataTypes::ValueType::size_type i) const  Data::getDataAtOffset(DataTypes::ValueType::size_type i) const
2429  {  {
2430      return m_data->getDataAtOffset(i);      if (isLazy())
2431        {
2432        throw DataException("getDataAtOffset not permitted on lazy data.");
2433        }
2434        return getReady()->getDataAtOffset(i);
2435  }  }
2436    
2437    
2438  DataTypes::ValueType::reference  DataTypes::ValueType::reference
2439  Data::getDataAtOffset(DataTypes::ValueType::size_type i)  Data::getDataAtOffset(DataTypes::ValueType::size_type i)
2440  {  {
2441      return m_data->getDataAtOffset(i);      if (isLazy())
2442        {
2443        throw DataException("getDataAtOffset not permitted on lazy data.");
2444        }
2445        return getReady()->getDataAtOffset(i);
2446  }  }
2447    
2448  DataTypes::ValueType::const_reference  DataTypes::ValueType::const_reference
2449  Data::getDataPoint(int sampleNo, int dataPointNo) const  Data::getDataPoint(int sampleNo, int dataPointNo) const
2450  {  {
2451      return m_data->getDataAtOffset(m_data->getPointOffset(sampleNo, dataPointNo));    if (isLazy())
2452      {
2453        throw DataException("Programmer error - getDataPoint() not permitted on Lazy Data.");
2454      }
2455      else
2456      {
2457        const DataReady* dr=getReady();
2458        return dr->getDataAtOffset(dr->getPointOffset(sampleNo, dataPointNo));
2459      }
2460  }  }
2461    
2462    
2463  DataTypes::ValueType::reference  DataTypes::ValueType::reference
2464  Data::getDataPoint(int sampleNo, int dataPointNo)  Data::getDataPoint(int sampleNo, int dataPointNo)
2465  {  {
2466      return m_data->getDataAtOffset(m_data->getPointOffset(sampleNo, dataPointNo));    if (isLazy())
2467      {
2468        throw DataException("Programmer error - getDataPoint() not permitted on Lazy Data.");
2469      }
2470      else
2471      {
2472        DataReady* dr=getReady();
2473        return dr->getDataAtOffset(dr->getPointOffset(sampleNo, dataPointNo));
2474      }
2475  }  }
2476    
2477    

Legend:
Removed from v.1863  
changed lines
  Added in v.1864

  ViewVC Help
Powered by ViewVC 1.1.26