/[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 804 by gross, Thu Aug 10 01:12:16 2006 UTC revision 950 by gross, Tue Feb 6 07:01:11 2007 UTC
# Line 70  class Data { Line 70  class Data {
70    typedef double (*UnaryDFunPtr)(double);    typedef double (*UnaryDFunPtr)(double);
71    typedef double (*BinaryDFunPtr)(double,double);    typedef double (*BinaryDFunPtr)(double,double);
72    
73    
74    /**    /**
75       Constructors.       Constructors.
76    */    */
# Line 263  class Data { Line 264  class Data {
264    
265    /**    /**
266       \brief       \brief
267       Return the values of all data-points for the given sample as a single python numarray object.       Fills the expanded Data object from values of a python numarray object.
268    */    */
269    ESCRIPT_DLL_API    ESCRIPT_DLL_API
270    const boost::python::numeric::array    void
271    convertToNumArrayFromSampleNo(int sampleNo);    fillFromNumArray(const boost::python::numeric::array);
272    
273    /**    /**
274       \brief       \brief
275       Return the value of the specified data-point as a single python numarray object.       Return the values of a data point on this process
276    */    */
 #ifndef PASO_MPI    
   ESCRIPT_DLL_API  
   const boost::python::numeric::array  
   convertToNumArrayFromDPNo(int ProcNo,  
                                                         int sampleNo,  
                             int dataPointNo);  
 #else  
277    ESCRIPT_DLL_API    ESCRIPT_DLL_API
278    const boost::python::numeric::array    const boost::python::numeric::array
279    convertToNumArrayFromDPNo(int procNo,    getValueOfDataPoint(int dataPointNo);
                 int sampleNo,  
                 int dataPointNo);  
 #endif  
280    
281      /**
282         \brief
283         sets the values of a data-point on this process
284      */
285      ESCRIPT_DLL_API
286      void
287      setValueOfDataPointToArray(int dataPointNo, const boost::python::numeric::array);
288    
289    /**    /**
290       \brief       \brief
291       Fills the expanded Data object from values of a python numarray object.       sets the values of a data-point on this process
292    */    */
293    ESCRIPT_DLL_API    ESCRIPT_DLL_API
294    void    void
295    fillFromNumArray(const boost::python::numeric::array);    setValueOfDataPoint(int dataPointNo, const double);
296    
297      /**
298         \brief
299         Return the value of the specified data-point across all processors
300      */
301      ESCRIPT_DLL_API
302      const boost::python::numeric::array
303      getValueOfGlobalDataPoint(int procNo, int dataPointNo);
304    
305    /**    /**
306       \brief       \brief
# Line 454  class Data { Line 460  class Data {
460    
461    /**    /**
462       \brief       \brief
463         Return the number of data points
464      */
465      ESCRIPT_DLL_API
466      inline
467      int
468      getNumDataPoints() const
469      {
470        return getNumSamples() * getNumDataPointsPerSample();
471      }
472      /**
473         \brief
474       Return the number of samples.       Return the number of samples.
475    */    */
476    ESCRIPT_DLL_API    ESCRIPT_DLL_API
# Line 475  class Data { Line 492  class Data {
492    {    {
493      return m_data->getNumDPPSample();      return m_data->getNumDPPSample();
494    }    }
495      /**
496         \brief
497         dumps the object into a netCDF file
498      */
499      ESCRIPT_DLL_API
500      inline
501      void
502      dump(const std::string fileName) const
503      {
504        return m_data->dump(fileName);
505      }
506    
507    /**    /**
508       \brief       \brief
# Line 522  class Data { Line 550  class Data {
550    */    */
551    ESCRIPT_DLL_API    ESCRIPT_DLL_API
552    void    void
553    setRefValue(int ref,    setValueByReferenceNumber(int ref,
554                const boost::python::numeric::array& value);                              const boost::python::numeric::array& value);
555    
556    /**    /**
557       \brief       \brief
# Line 542  class Data { Line 570  class Data {
570    */    */
571    ESCRIPT_DLL_API    ESCRIPT_DLL_API
572    void    void
573    getRefValue(int ref,    getValueByReferenceNumber(int ref,
574                boost::python::numeric::array& value);                              boost::python::numeric::array& value);
575    
576    /**    /**
577       \brief       \brief
# Line 671  class Data { Line 699  class Data {
699    
700    /**    /**
701       \brief       \brief
702         Returns 1./ Data object
703         *
704      */
705      ESCRIPT_DLL_API
706      Data
707      oneOver() const;
708      /**
709         \brief
710       Return a Data with a 1 for +ive values and a 0 for 0 or -ive values.       Return a Data with a 1 for +ive values and a 0 for 0 or -ive values.
711       *       *
712    */    */
# Line 793  class Data { Line 829  class Data {
829    */    */
830    ESCRIPT_DLL_API    ESCRIPT_DLL_API
831    const boost::python::tuple    const boost::python::tuple
832    mindp() const;    minGlobalDataPoint() const;
833    
834    ESCRIPT_DLL_API    ESCRIPT_DLL_API
835    void    void
836    calc_mindp(int& ProcNo,    calc_minGlobalDataPoint(int& ProcNo,  int& DataPointNo) const;
                         int& SampleNo,    
              int& DataPointNo) const;  
837    /**    /**
838       \brief       \brief
839       Return the sign of each data point of this Data object.       Return the sign of each data point of this Data object.
# Line 880  class Data { Line 914  class Data {
914    
915    /**    /**
916       \brief       \brief
917         Return the error function erf of each data point of this Data object.
918         *
919      */
920      ESCRIPT_DLL_API
921      Data
922      erf() const;
923    
924      /**
925         \brief
926       Return the sin of each data point of this Data object.       Return the sin of each data point of this Data object.
927       *       *
928    */    */
# Line 1279  class Data { Line 1322  class Data {
1322    ESCRIPT_DLL_API    ESCRIPT_DLL_API
1323      MPI_Comm      MPI_Comm
1324      get_MPIComm(void) const;      get_MPIComm(void) const;
1325        
1326      /**
1327         \brief
1328         return the object produced by the factory, which is a DataConstant or DataExpanded
1329      */
1330      ESCRIPT_DLL_API
1331        DataAbstract*
1332        borrowData(void) const;
1333    
1334   protected:   protected:
1335    
1336   private:   private:
# Line 1337  class Data { Line 1388  class Data {
1388    
1389    /**    /**
1390       \brief       \brief
      Perform the given binary operation on all of the data's elements.  
      RHS is a boost::python object.  
   */  
   template <class BinaryFunction>  
   inline  
   void  
   binaryOp(const boost::python::object& right,  
            BinaryFunction operation);  
   
   /**  
      \brief  
1391       Convert the data type of the RHS to match this.       Convert the data type of the RHS to match this.
1392       \param right - Input - data type to match.       \param right - Input - data type to match.
1393    */    */
# Line 1372  class Data { Line 1412  class Data {
1412               const FunctionSpace& what,               const FunctionSpace& what,
1413               bool expanded);               bool expanded);
1414    
   /**  
      \brief  
      Reshape the data point if the data point is currently rank 0.  
      Will throw an exception if the data points are not rank 0.  
      The original data point value is used for all values of the new  
      data point.  
   */  
   void  
   reshapeDataPoint(const DataArrayView::ShapeType& shape);  
   
1415    //    //
1416    // flag to protect the data object against any update    // flag to protect the data object against any update
1417    bool m_protected;    bool m_protected;
# Line 1421  Data::initialise(const IValueType& value Line 1451  Data::initialise(const IValueType& value
1451  /**  /**
1452     Binary Data object operators.     Binary Data object operators.
1453  */  */
1454    inline double rpow(double x,double y)
1455    {
1456        return pow(y,x);
1457    };
1458    
1459  /**  /**
1460    \brief    \brief
# Line 1522  ESCRIPT_DLL_API std::ostream& operator<< Line 1556  ESCRIPT_DLL_API std::ostream& operator<<
1556    
1557  /**  /**
1558    \brief    \brief
1559      Compute a tensor product of two Data objects
1560      \param arg0 - Input - Data object
1561      \param arg1 - Input - Data object
1562      \param axis_offset - Input - axis offset
1563      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1564    */
1565    ESCRIPT_DLL_API
1566    Data
1567    C_GeneralTensorProduct(Data& arg0,
1568                         Data& arg1,
1569                         int axis_offset=0,
1570                         int transpose=0);
1571    
1572    /**
1573      \brief
1574    Return true if operands are equivalent, else return false.    Return true if operands are equivalent, else return false.
1575    NB: this operator does very little at this point, and isn't to    NB: this operator does very little at this point, and isn't to
1576    be relied on. Requires further implementation.    be relied on. Requires further implementation.
# Line 1542  Data::binaryOp(const Data& right, Line 1591  Data::binaryOp(const Data& right,
1591     //     //
1592     // if this has a rank of zero promote it to the rank of the RHS     // if this has a rank of zero promote it to the rank of the RHS
1593     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1594       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1595     }     }
1596     //     //
1597     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1594  Data::binaryOp(const Data& right, Line 1643  Data::binaryOp(const Data& right,
1643       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");
1644       escript::binaryOp(*leftC,*rightC,operation);       escript::binaryOp(*leftC,*rightC,operation);
1645     }     }
1646  }     #if defined DOPROF
1647       profData->binary++;
1648  /**     #endif
   \brief  
   Perform the given binary operation with this and right as operands.  
   Right is a boost::python object.  
 */  
 template <class BinaryFunction>  
 inline  
 void  
 Data::binaryOp(const boost::python::object& right,  
                BinaryFunction operation)  
 {  
    DataArray temp(right);  
    //  
    // if this has a rank of zero promote it to the rank of the RHS.  
    if (getPointDataView().getRank()==0 && temp.getView().getRank()!=0) {  
       reshapeDataPoint(temp.getView().getShape());  
    }  
    //  
    // Always allow scalar values for the RHS but check other shapes  
    if (temp.getView().getRank()!=0) {  
      if (!getPointDataView().checkShape(temp.getView().getShape())) {  
        throw DataException(getPointDataView().createShapeErrorMessage(  
                   "Error - RHS shape doesn't match LHS shape.",temp.getView().getShape()));  
      }  
    }  
    if (isExpanded()) {  
      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());  
      EsysAssert((leftC!=0),"Programming error - casting to DataExpanded.");  
      escript::binaryOp(*leftC,temp.getView(),operation);  
    } else if (isTagged()) {  
      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());  
      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");  
      escript::binaryOp(*leftC,temp.getView(),operation);  
    } else if (isConstant()) {  
      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());  
      EsysAssert((leftC!=0),"Programming error - casting to DataConstant.");  
      escript::binaryOp(*leftC,temp.getView(),operation);  
    }  
1649  }  }
1650    
1651  /**  /**

Legend:
Removed from v.804  
changed lines
  Added in v.950

  ViewVC Help
Powered by ViewVC 1.1.26