/[escript]/trunk/escript/src/Data.h
ViewVC logotype

Diff of /trunk/escript/src/Data.h

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

revision 1952 by jfenwick, Thu Oct 30 06:16:00 2008 UTC revision 2005 by jfenwick, Mon Nov 10 01:21:39 2008 UTC
# Line 202  class Data { Line 202  class Data {
202      Once you have passed the pointer, do not delete it.      Once you have passed the pointer, do not delete it.
203    */    */
204    ESCRIPT_DLL_API    ESCRIPT_DLL_API
205    Data(DataAbstract* underlyingdata);    explicit Data(DataAbstract* underlyingdata);
206    
207      /**
208        \brief Create a Data based on the supplied DataAbstract
209      */
210      ESCRIPT_DLL_API
211      explicit Data(DataAbstract_ptr underlyingdata);
212    
213    /**    /**
214       \brief       \brief
# Line 227  class Data { Line 232  class Data {
232    copySelf();    copySelf();
233    
234    
235      /**
236         \brief produce a delayed evaluation version of this Data.
237      */
238      ESCRIPT_DLL_API
239      Data
240      delay();
241    
242      /**
243         \brief convert the current data into lazy data.
244      */
245      ESCRIPT_DLL_API
246      void
247      delaySelf();
248    
249    
250    /**    /**
# Line 335  class Data { Line 353  class Data {
353    std::string    std::string
354    toString() const;    toString() const;
355    
   
 //  /**  
 /*     \brief  
      Return the DataArrayView of the point data. This essentially contains  
      the shape information for each data point although it also may be used  
      to manipulate the point data.*/  
 //  */  
 //   ESCRIPT_DLL_API  
 //   inline  
 //   const DataArrayView&  
 //   getPointDataView() const  
 //   {  
 //      return m_data->getPointDataView();  
 //   }  
   
356    /**    /**
357       \brief       \brief
358       Whatever the current Data type make this into a DataExpanded.       Whatever the current Data type make this into a DataExpanded.
# Line 363  class Data { Line 366  class Data {
366       If possible convert this Data to DataTagged. This will only allow       If possible convert this Data to DataTagged. This will only allow
367       Constant data to be converted to tagged. An attempt to convert       Constant data to be converted to tagged. An attempt to convert
368       Expanded data to tagged will throw an exception.       Expanded data to tagged will throw an exception.
     ==>*  
369    */    */
370    ESCRIPT_DLL_API    ESCRIPT_DLL_API
371    void    void
372    tag();    tag();
373    
374    /**    /**
375        \brief If this data is lazy, then convert it to ready data.
376        What type of ready data depends on the expression. For example, Constant+Tagged==Tagged.
377      */
378      ESCRIPT_DLL_API
379      void
380      resolve();
381    
382    
383      /**
384       \brief       \brief
385       Return true if this Data is expanded.       Return true if this Data is expanded.
386    */    */
# Line 394  class Data { Line 405  class Data {
405    isConstant() const;    isConstant() const;
406    
407    /**    /**
408         \brief Return true if this Data is lazy.
409      */
410      ESCRIPT_DLL_API
411      bool
412      isLazy() const;
413    
414      /**
415         \brief Return true if this data is ready.
416      */
417      ESCRIPT_DLL_API
418      bool
419      isReady() const;
420    
421      /**
422       \brief       \brief
423       Return true if this Data holds an instance of DataEmpty. This is _not_ the same as asking if the object       Return true if this Data holds an instance of DataEmpty. This is _not_ the same as asking if the object
424  contains datapoints.  contains datapoints.
# Line 525  contains datapoints. Line 550  contains datapoints.
550    ESCRIPT_DLL_API    ESCRIPT_DLL_API
551    void    void
552    dump(const std::string fileName) const;    dump(const std::string fileName) const;
553    
554    /**    /**
555       \brief       \brief
556       Return the sample data for the given sample no. This is not the       Return the sample data for the given sample no. This is not the
# Line 534  contains datapoints. Line 560  contains datapoints.
560    ESCRIPT_DLL_API    ESCRIPT_DLL_API
561    inline    inline
562    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
563    getSampleData(DataAbstract::ValueType::size_type sampleNo)    getSampleData(DataAbstract::ValueType::size_type sampleNo);
   {  
     return m_data->getSampleData(sampleNo);  
   }  
564    
565    /**    /**
566       \brief       \brief
# Line 553  contains datapoints. Line 576  contains datapoints.
576      return m_data->getSampleDataByTag(tag);      return m_data->getSampleDataByTag(tag);
577    }    }
578    
 //  /**  
 /*     \brief  
      Return a view into the data for the data point specified.  
      NOTE: Construction of the DataArrayView is a relatively expensive  
      operation.  
      \param sampleNo - Input -  
      \param dataPointNo - Input -*/  
 //  */  
 //   ESCRIPT_DLL_API  
 //   inline  
 //   DataArrayView  
 //   getDataPoint(int sampleNo,  
 //                int dataPointNo)  
 //   {  
 //                 return m_data->getDataPoint(sampleNo,dataPointNo);  
 //   }  
   
   
579    /**    /**
580       \brief       \brief
581       Return a view into the data for the data point specified.       Return a view into the data for the data point specified.
# Line 600  contains datapoints. Line 605  contains datapoints.
605    getDataOffset(int sampleNo,    getDataOffset(int sampleNo,
606                 int dataPointNo)                 int dataPointNo)
607    {    {
608                  return m_data->getPointOffset(sampleNo,dataPointNo);        return m_data->getPointOffset(sampleNo,dataPointNo);
609    }    }
610    
611    /**    /**
# Line 670  contains datapoints. Line 675  contains datapoints.
675    setTaggedValue(int tagKey,    setTaggedValue(int tagKey,
676                   const boost::python::object& value);                   const boost::python::object& value);
677    
   
 //  /**  
 //     \brief  
 //     Assign the given value to the tag. Implicitly converts this  
 //     object to type DataTagged if it is constant.  
 //  
 //     \param tagKey - Input - Integer key.  
 //     \param value - Input - Value to associate with given key.  
 //    ==>*  
 //  */  
 //   ESCRIPT_DLL_API  
 //   void  
 //   setTaggedValueFromCPP(int tagKey,  
 //                         const DataArrayView& value);  
   
678    /**    /**
679       \brief       \brief
680       Assign the given value to the tag. Implicitly converts this       Assign the given value to the tag. Implicitly converts this
# Line 756  contains datapoints. Line 746  contains datapoints.
746    */    */
747    ESCRIPT_DLL_API    ESCRIPT_DLL_API
748    boost::python::numeric::array    boost::python::numeric::array
749    integrate() const;    integrate_const() const;
750    
751      ESCRIPT_DLL_API
752      boost::python::numeric::array
753      integrate();
754    
755    /**    /**
756       \brief       \brief
# Line 823  contains datapoints. Line 817  contains datapoints.
817    /**    /**
818       \brief       \brief
819       Return the maximum absolute value of this Data object.       Return the maximum absolute value of this Data object.
820    
821         The method is not const because lazy data needs to be expanded before Lsup can be computed.
822         The _const form can be used when the Data object is const, however this will only work for
823         Data which is not Lazy.
824    
825       For Data which contain no samples (or tagged Data for which no tags in use have a value)       For Data which contain no samples (or tagged Data for which no tags in use have a value)
826       zero is returned.       zero is returned.
      *  
827    */    */
828    ESCRIPT_DLL_API    ESCRIPT_DLL_API
829    double    double
830    Lsup() const;    Lsup();
831    
832      ESCRIPT_DLL_API
833      double
834      Lsup_const() const;
835    
836    
837    /**    /**
838       \brief       \brief
839       Return the maximum value of this Data object.       Return the maximum value of this Data object.
840    
841         The method is not const because lazy data needs to be expanded before sup can be computed.
842         The _const form can be used when the Data object is const, however this will only work for
843         Data which is not Lazy.
844    
845       For Data which contain no samples (or tagged Data for which no tags in use have a value)       For Data which contain no samples (or tagged Data for which no tags in use have a value)
846       a large negative value is returned.       a large negative value is returned.
847    */    */
848    ESCRIPT_DLL_API    ESCRIPT_DLL_API
849    double    double
850    sup() const;    sup();
851    
852      ESCRIPT_DLL_API
853      double
854      sup_const() const;
855    
856    
857    /**    /**
858       \brief       \brief
859       Return the minimum value of this Data object.       Return the minimum value of this Data object.
860    
861         The method is not const because lazy data needs to be expanded before inf can be computed.
862         The _const form can be used when the Data object is const, however this will only work for
863         Data which is not Lazy.
864    
865       For Data which contain no samples (or tagged Data for which no tags in use have a value)       For Data which contain no samples (or tagged Data for which no tags in use have a value)
866       a large positive value is returned.       a large positive value is returned.
      *  
867    */    */
868    ESCRIPT_DLL_API    ESCRIPT_DLL_API
869    double    double
870    inf() const;    inf();
871    
872      ESCRIPT_DLL_API
873      double
874      inf_const() const;
875    
876    
877    
878    /**    /**
879       \brief       \brief
# Line 1369  contains datapoints. Line 1392  contains datapoints.
1392          DataAbstract*          DataAbstract*
1393          borrowData(void) const;          borrowData(void) const;
1394    
1395      ESCRIPT_DLL_API
1396            DataAbstract_ptr
1397            borrowDataPtr(void) const;
1398    
1399      ESCRIPT_DLL_API
1400            DataReady_ptr
1401            borrowReadyPtr(void) const;
1402    
1403    
1404    
1405    /**    /**
1406       \brief       \brief
# Line 1389  contains datapoints. Line 1421  contains datapoints.
1421    
1422   private:   private:
1423    
1424      double
1425      LsupWorker() const;
1426    
1427      double
1428      supWorker() const;
1429    
1430      double
1431      infWorker() const;
1432    
1433      boost::python::numeric::array
1434      integrateWorker() const;
1435    
1436    /**    /**
1437       \brief       \brief
1438       Check *this and the right operand are compatible. Throws       Check *this and the right operand are compatible. Throws
# Line 1481  contains datapoints. Line 1525  contains datapoints.
1525  //   boost::shared_ptr<DataAbstract> m_data;  //   boost::shared_ptr<DataAbstract> m_data;
1526    DataAbstract_ptr m_data;    DataAbstract_ptr m_data;
1527    
1528    // If possible please use getReadyPtr instead
1529      const DataReady*
1530      getReady() const;
1531    
1532      DataReady*
1533      getReady();
1534    
1535      DataReady_ptr
1536      getReadyPtr();
1537    
1538      const_DataReady_ptr
1539      getReadyPtr() const;
1540    
1541    
1542  };  };
1543    
1544    }   // end namespace escript
1545    
1546    
1547    // No, this is not supposed to be at the top of the file
1548    // DataAbstact needs to be declared first, then DataReady needs to be fully declared
1549    // so that I can dynamic cast between them below.
1550    #include "DataReady.h"
1551    
1552    namespace escript
1553    {
1554    
1555    inline
1556    const DataReady*
1557    Data::getReady() const
1558    {
1559       const DataReady* dr=dynamic_cast<const DataReady*>(m_data.get());
1560       EsysAssert((dr!=0), "Error - casting to DataReady.");
1561       return dr;
1562    }
1563    
1564    inline
1565    DataReady*
1566    Data::getReady()
1567    {
1568       DataReady* dr=dynamic_cast<DataReady*>(m_data.get());
1569       EsysAssert((dr!=0), "Error - casting to DataReady.");
1570       return dr;
1571    }
1572    
1573    inline
1574    DataReady_ptr
1575    Data::getReadyPtr()
1576    {
1577       DataReady_ptr dr=boost::dynamic_pointer_cast<DataReady>(m_data);
1578       EsysAssert((dr.get()!=0), "Error - casting to DataReady.");
1579       return dr;
1580    }
1581    
1582    
1583    inline
1584    const_DataReady_ptr
1585    Data::getReadyPtr() const
1586    {
1587       const_DataReady_ptr dr=boost::dynamic_pointer_cast<const DataReady>(m_data);
1588       EsysAssert((dr.get()!=0), "Error - casting to DataReady.");
1589       return dr;
1590    }
1591    
1592    inline
1593    DataAbstract::ValueType::value_type*
1594    Data::getSampleData(DataAbstract::ValueType::size_type sampleNo)
1595    {
1596       if (isLazy())
1597       {
1598        resolve();
1599       }
1600       return getReady()->getSampleData(sampleNo);
1601    }
1602    
1603    
1604  /**  /**
# Line 1613  C_GeneralTensorProduct(Data& arg0, Line 1729  C_GeneralTensorProduct(Data& arg0,
1729                       int axis_offset=0,                       int axis_offset=0,
1730                       int transpose=0);                       int transpose=0);
1731    
   
   
 // /**  
 /*  \brief  
   Return true if operands are equivalent, else return false.  
   NB: this operator does very little at this point, and isn't to  
   be relied on. Requires further implementation.*/  
 //*/  
 // ESCRIPT_DLL_API bool operator==(const Data& left, const Data& right);  
   
1732  /**  /**
1733    \brief    \brief
1734    Perform the given binary operation with this and right as operands.    Perform the given binary operation with this and right as operands.
# Line 1639  Data::binaryOp(const Data& right, Line 1745  Data::binaryOp(const Data& right,
1745     if (getDataPointRank()==0 && right.getDataPointRank()!=0) {     if (getDataPointRank()==0 && right.getDataPointRank()!=0) {
1746       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1747     }     }
1748    
1749       if (isLazy() || right.isLazy())
1750       {
1751         throw DataException("Programmer error - attempt to call binaryOp with Lazy Data.");
1752       }
1753     //     //
1754     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
1755     Data tempRight(right);     Data tempRight(right);
1756    
1757     if (getFunctionSpace()!=right.getFunctionSpace()) {     if (getFunctionSpace()!=right.getFunctionSpace()) {
1758       if (right.probeInterpolation(getFunctionSpace())) {       if (right.probeInterpolation(getFunctionSpace())) {
1759         //         //
# Line 1667  Data::binaryOp(const Data& right, Line 1779  Data::binaryOp(const Data& right,
1779       // of any data type       // of any data type
1780       DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());       DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1781       EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");       EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1782       escript::binaryOp(*leftC,*(tempRight.m_data.get()),operation);       escript::binaryOp(*leftC,*(tempRight.getReady()),operation);
1783     } else if (isTagged()) {     } else if (isTagged()) {
1784       //       //
1785       // Tagged data is operated on serially, the right hand side can be       // Tagged data is operated on serially, the right hand side can be
# Line 1717  Data::algorithm(BinaryFunction operation Line 1829  Data::algorithm(BinaryFunction operation
1829      return escript::algorithm(*leftC,operation,initial_value);      return escript::algorithm(*leftC,operation,initial_value);
1830    } else if (isEmpty()) {    } else if (isEmpty()) {
1831      throw DataException("Error - Operations not permitted on instances of DataEmpty.");      throw DataException("Error - Operations not permitted on instances of DataEmpty.");
1832      } else if (isLazy()) {
1833        throw DataException("Error - Operations not permitted on instances of DataLazy.");
1834      } else {
1835        throw DataException("Error - Data encapsulates an unknown type.");
1836    }    }
   return 0;  
1837  }  }
1838    
1839  /**  /**
# Line 1763  Data::dp_algorithm(BinaryFunction operat Line 1878  Data::dp_algorithm(BinaryFunction operat
1878      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1879      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
1880      return result;      return result;
1881      } else if (isLazy()) {
1882        throw DataException("Error - Operations not permitted on instances of DataLazy.");
1883      } else {
1884        throw DataException("Error - Data encapsulates an unknown type.");
1885    }    }
   Data falseRetVal; // to keep compiler quiet  
   return falseRetVal;  
1886  }  }
1887    
1888  /**  /**
# Line 1786  C_TensorBinaryOperation(Data const &arg_ Line 1903  C_TensorBinaryOperation(Data const &arg_
1903    {    {
1904       throw DataException("Error - Operations not permitted on instances of DataEmpty.");       throw DataException("Error - Operations not permitted on instances of DataEmpty.");
1905    }    }
1906      if (arg_0.isLazy() || arg_1.isLazy())
1907      {
1908         throw DataException("Error - Operations not permitted on lazy data.");
1909      }
1910    // Interpolate if necessary and find an appropriate function space    // Interpolate if necessary and find an appropriate function space
1911    Data arg_0_Z, arg_1_Z;    Data arg_0_Z, arg_1_Z;
1912    if (arg_0.getFunctionSpace()!=arg_1.getFunctionSpace()) {    if (arg_0.getFunctionSpace()!=arg_1.getFunctionSpace()) {
# Line 2699  C_TensorUnaryOperation(Data const &arg_0 Line 2820  C_TensorUnaryOperation(Data const &arg_0
2820    {    {
2821       throw DataException("Error - Operations not permitted on instances of DataEmpty.");       throw DataException("Error - Operations not permitted on instances of DataEmpty.");
2822    }    }
2823      if (arg_0.isLazy())
2824      {
2825         throw DataException("Error - Operations not permitted on lazy data.");
2826      }
2827    // Interpolate if necessary and find an appropriate function space    // Interpolate if necessary and find an appropriate function space
2828    Data arg_0_Z = Data(arg_0);    Data arg_0_Z = Data(arg_0);
2829    

Legend:
Removed from v.1952  
changed lines
  Added in v.2005

  ViewVC Help
Powered by ViewVC 1.1.26