/[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 757 by woo409, Mon Jun 26 13:12:56 2006 UTC revision 1141 by gross, Tue May 15 04:24:51 2007 UTC
# Line 29  extern "C" { Line 29  extern "C" {
29  #include "paso/Paso.h"  #include "paso/Paso.h"
30  }  }
31    
32    #ifndef PASO_MPI
33    #define MPI_Comm long
34    #endif
35    
36  #include <string>  #include <string>
37  #include <algorithm>  #include <algorithm>
38    
# Line 66  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 234  class Data { Line 239  class Data {
239    
240    /**    /**
241       \brief       \brief
242       Return the values of all data-points as a single python numarray object.       switches on update protection
243    
244    */    */
245    ESCRIPT_DLL_API    ESCRIPT_DLL_API
246    const boost::python::numeric::array    void
247    convertToNumArray();    setProtection();
248    
249    /**    /**
250       \brief       \brief
251       Return the values of all data-points for the given sample as a single python numarray object.       Returns trueif the data object is protected against update
252    
253    */    */
254    ESCRIPT_DLL_API    ESCRIPT_DLL_API
255    const boost::python::numeric::array    bool
256    convertToNumArrayFromSampleNo(int sampleNo);    isProtected() const;
257    
258    /**    /**
259       \brief       \brief
260       Return the value of the specified data-point as a single python numarray object.       Return the values of a data point on this process
261    */    */
262    ESCRIPT_DLL_API    ESCRIPT_DLL_API
263    const boost::python::numeric::array    const boost::python::numeric::array
264    convertToNumArrayFromDPNo(int sampleNo,    getValueOfDataPoint(int dataPointNo);
265                              int dataPointNo);  
266      /**
267         \brief
268         sets the values of a data-point from a python object on this process
269      */
270      ESCRIPT_DLL_API
271      void
272      setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object);
273    
274      /**
275         \brief
276         sets the values of a data-point from a numarray object on this process
277      */
278      ESCRIPT_DLL_API
279      void
280      setValueOfDataPointToArray(int dataPointNo, const boost::python::numeric::array&);
281    
282    /**    /**
283       \brief       \brief
284       Fills the expanded Data object from values of a python numarray object.       sets the values of a data-point on this process
285    */    */
286    ESCRIPT_DLL_API    ESCRIPT_DLL_API
287    void    void
288    fillFromNumArray(const boost::python::numeric::array);    setValueOfDataPoint(int dataPointNo, const double);
289    
290      /**
291         \brief
292         Return the value of the specified data-point across all processors
293      */
294      ESCRIPT_DLL_API
295      const boost::python::numeric::array
296      getValueOfGlobalDataPoint(int procNo, int dataPointNo);
297    
298    /**    /**
299       \brief       \brief
# Line 303  class Data { Line 333  class Data {
333    {    {
334      return m_data->toString();      return m_data->toString();
335    }    }
336      
337      /**
338         \brief
339         Return a description for this domain for python.
340      */
341      ESCRIPT_DLL_API
342      const boost::python::str str() const;
343    
344    /**    /**
345       \brief       \brief
# Line 423  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 444  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      void
501      dump(const std::string fileName) const;
502    /**    /**
503       \brief       \brief
504       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 475  class Data { Line 529  class Data {
529    
530    /**    /**
531       \brief       \brief
      Assign the given value to the data-points referenced by the given  
      reference number.  
   
      The value supplied is a python numarray object.  The data from this numarray  
      is unpacked into a DataArray, and this is used to set the corresponding  
      data-points in the underlying Data object.  
   
      If the underlying Data object cannot be accessed via reference numbers, an  
      exception will be thrown.  
   
      \param ref - Input - reference number.  
      \param value - Input - value to assign to data-points associated with  
                             the given reference number.  
   */  
   ESCRIPT_DLL_API  
   void  
   setRefValue(int ref,  
               const boost::python::numeric::array& value);  
   
   /**  
      \brief  
      Return the values associated with the data-points referenced by the given  
      reference number.  
   
      The value supplied is a python numarray object. The data from the corresponding  
      data-points in this Data object are packed into the given numarray object.  
   
      If the underlying Data object cannot be accessed via reference numbers, an  
      exception will be thrown.  
   
      \param ref - Input - reference number.  
      \param value - Output - object to receive values from data-points  
                              associated with the given reference number.  
   */  
   ESCRIPT_DLL_API  
   void  
   getRefValue(int ref,  
               boost::python::numeric::array& value);  
   
   /**  
      \brief  
532       Return a view into the data for the data point specified.       Return a view into the data for the data point specified.
533       NOTE: Construction of the DataArrayView is a relatively expensive       NOTE: Construction of the DataArrayView is a relatively expensive
534       operation.       operation.
# Line 528  class Data { Line 541  class Data {
541    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
542                 int dataPointNo)                 int dataPointNo)
543    {    {
544      return m_data->getDataPoint(sampleNo,dataPointNo);          return m_data->getDataPoint(sampleNo,dataPointNo);
545    }    }
546    
547    /**    /**
# Line 564  class Data { Line 577  class Data {
577    DataArrayView::ValueType::size_type    DataArrayView::ValueType::size_type
578    getLength() const;    getLength() const;
579    
580    
581    
582      /**
583         \brief
584         Assign the given value to the tag assocciated with name. Implicitly converts this
585         object to type DataTagged. Throws an exception if this object
586         cannot be converted to a DataTagged object or name cannot be mapped onto a tag key.
587         \param tagKey - Input - Integer key.
588         \param value - Input - Value to associate with given key.
589        ==>*
590      */
591      ESCRIPT_DLL_API
592      void
593      setTaggedValueByName(std::string name,
594                           const boost::python::object& value);
595    
596    /**    /**
597       \brief       \brief
598       Assign the given value to the tag. Implicitly converts this       Assign the given value to the tag. Implicitly converts this
# Line 607  class Data { Line 636  class Data {
636    
637    /**    /**
638       \brief       \brief
639         set all values to zero
640         *
641      */
642      ESCRIPT_DLL_API
643      void
644      setToZero();
645    
646      /**
647         \brief
648       Interpolates this onto the given functionspace and returns       Interpolates this onto the given functionspace and returns
649       the result as a Data object.       the result as a Data object.
650       *       *
# Line 614  class Data { Line 652  class Data {
652    ESCRIPT_DLL_API    ESCRIPT_DLL_API
653    Data    Data
654    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
   
655    /**    /**
656       \brief       \brief
657       Calculates the gradient of the data at the data points of functionspace.       Calculates the gradient of the data at the data points of functionspace.
# Line 640  class Data { Line 677  class Data {
677    
678    /**    /**
679       \brief       \brief
680         Returns 1./ Data object
681         *
682      */
683      ESCRIPT_DLL_API
684      Data
685      oneOver() const;
686      /**
687         \brief
688       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.
689       *       *
690    */    */
# Line 762  class Data { Line 807  class Data {
807    */    */
808    ESCRIPT_DLL_API    ESCRIPT_DLL_API
809    const boost::python::tuple    const boost::python::tuple
810    mindp() const;    minGlobalDataPoint() const;
811    
812    ESCRIPT_DLL_API    ESCRIPT_DLL_API
813    void    void
814    calc_mindp(int& SampleNo,    calc_minGlobalDataPoint(int& ProcNo,  int& DataPointNo) const;
              int& DataPointNo) const;  
   
815    /**    /**
816       \brief       \brief
817       Return the sign of each data point of this Data object.       Return the sign of each data point of this Data object.
# Line 781  class Data { Line 824  class Data {
824    
825    /**    /**
826       \brief       \brief
827         Return the symmetric part of a matrix which is half the matrix plus its transpose.
828         *
829      */
830      ESCRIPT_DLL_API
831      Data
832      symmetric() const;
833    
834      /**
835         \brief
836         Return the nonsymmetric part of a matrix which is half the matrix minus its transpose.
837         *
838      */
839      ESCRIPT_DLL_API
840      Data
841      nonsymmetric() const;
842    
843      /**
844         \brief
845         Return the trace of a matrix
846         *
847      */
848      ESCRIPT_DLL_API
849      Data
850      trace(int axis_offset) const;
851    
852      /**
853         \brief
854         Transpose each data point of this Data object around the given axis.
855         *
856      */
857      ESCRIPT_DLL_API
858      Data
859      transpose(int axis_offset) const;
860    
861      /**
862         \brief
863       Return the eigenvalues of the symmetric part at each data point of this Data object in increasing values.       Return the eigenvalues of the symmetric part at each data point of this Data object in increasing values.
864       Currently this function is restricted to rank 2, square shape, and dimension 3.       Currently this function is restricted to rank 2, square shape, and dimension 3.
865       *       *
# Line 804  class Data { Line 883  class Data {
883    
884    /**    /**
885       \brief       \brief
886       Transpose each data point of this Data object around the given axis.       swaps the components axis0 and axis1
      --* not implemented yet *--  
887       *       *
888    */    */
889    ESCRIPT_DLL_API    ESCRIPT_DLL_API
890    Data    Data
891    transpose(int axis) const;    swapaxes(const int axis0, const int axis1) const;
892    
893    /**    /**
894       \brief       \brief
895       Calculate the trace of each data point of this Data object.       Return the error function erf of each data point of this Data object.
896       *       *
897    */    */
898    ESCRIPT_DLL_API    ESCRIPT_DLL_API
899    Data    Data
900    trace() const;    erf() const;
901    
902    /**    /**
903       \brief       \brief
# Line 1190  class Data { Line 1268  class Data {
1268       \brief       \brief
1269       print the data values to stdout. Used for debugging       print the data values to stdout. Used for debugging
1270    */    */
1271    void print();    ESCRIPT_DLL_API
1272      void
1273        print(void);
1274    
1275      /**
1276         \brief
1277         return the MPI rank number of the local data
1278             MPI_COMM_WORLD is assumed and the result of MPI_Comm_size()
1279             is returned
1280      */
1281      ESCRIPT_DLL_API
1282        int
1283        get_MPIRank(void) const;
1284    
1285      /**
1286         \brief
1287         return the MPI rank number of the local data
1288             MPI_COMM_WORLD is assumed and the result of MPI_Comm_rank()
1289             is returned
1290      */
1291      ESCRIPT_DLL_API
1292        int
1293        get_MPISize(void) const;
1294    
1295      /**
1296         \brief
1297         return the MPI rank number of the local data
1298             MPI_COMM_WORLD is assumed and returned.
1299      */
1300      ESCRIPT_DLL_API
1301        MPI_Comm
1302        get_MPIComm(void) const;
1303    
1304      /**
1305         \brief
1306         return the object produced by the factory, which is a DataConstant or DataExpanded
1307      */
1308      ESCRIPT_DLL_API
1309        DataAbstract*
1310        borrowData(void) const;
1311    
1312   protected:   protected:
1313    
# Line 1249  class Data { Line 1366  class Data {
1366    
1367    /**    /**
1368       \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  
1369       Convert the data type of the RHS to match this.       Convert the data type of the RHS to match this.
1370       \param right - Input - data type to match.       \param right - Input - data type to match.
1371    */    */
# Line 1284  class Data { Line 1390  class Data {
1390               const FunctionSpace& what,               const FunctionSpace& what,
1391               bool expanded);               bool expanded);
1392    
1393    /**    //
1394       \brief    // flag to protect the data object against any update
1395       Reshape the data point if the data point is currently rank 0.    bool m_protected;
      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);  
1396    
1397    //    //
1398    // pointer to the actual data object    // pointer to the actual data object
1399    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
1400    
   //  
   // pointer to the internal profiling data  
   struct profDataEntry *profData;  
   
1401  };  };
1402    
1403  template <class IValueType>  template <class IValueType>
# Line 1329  Data::initialise(const IValueType& value Line 1425  Data::initialise(const IValueType& value
1425  /**  /**
1426     Binary Data object operators.     Binary Data object operators.
1427  */  */
1428    inline double rpow(double x,double y)
1429    {
1430        return pow(y,x);
1431    }
1432    
1433  /**  /**
1434    \brief    \brief
# Line 1430  ESCRIPT_DLL_API std::ostream& operator<< Line 1530  ESCRIPT_DLL_API std::ostream& operator<<
1530    
1531  /**  /**
1532    \brief    \brief
1533      Compute a tensor product of two Data objects
1534      \param arg0 - Input - Data object
1535      \param arg1 - Input - Data object
1536      \param axis_offset - Input - axis offset
1537      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1538    */
1539    ESCRIPT_DLL_API
1540    Data
1541    C_GeneralTensorProduct(Data& arg0,
1542                         Data& arg1,
1543                         int axis_offset=0,
1544                         int transpose=0);
1545    
1546    /**
1547      \brief
1548    Return true if operands are equivalent, else return false.    Return true if operands are equivalent, else return false.
1549    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
1550    be relied on. Requires further implementation.    be relied on. Requires further implementation.
# Line 1450  Data::binaryOp(const Data& right, Line 1565  Data::binaryOp(const Data& right,
1565     //     //
1566     // 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
1567     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1568       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1569     }     }
1570     //     //
1571     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1504  Data::binaryOp(const Data& right, Line 1619  Data::binaryOp(const Data& right,
1619     }     }
1620  }  }
1621    
 /**  
   \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);  
    }  
 }  
   
1622  /**  /**
1623    \brief    \brief
1624    Perform the given unary operation on other and return the result.    Perform the given unary operation on other and return the result.

Legend:
Removed from v.757  
changed lines
  Added in v.1141

  ViewVC Help
Powered by ViewVC 1.1.26