/[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 1034 by gross, Wed Mar 14 23:49:20 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);
                             int dataPointNo);  
265    
266    /**    /**
267       \brief       \brief
268       Fills the expanded Data object from values of a python numarray object.       sets the values of a data-point from a python object on this process
269    */    */
270    ESCRIPT_DLL_API    ESCRIPT_DLL_API
271    void    void
272    fillFromNumArray(const boost::python::numeric::array);    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
284         sets the values of a data-point on this process
285      */
286      ESCRIPT_DLL_API
287      void
288      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 423  class Data { Line 453  class Data {
453    
454    /**    /**
455       \brief       \brief
456         Return the number of data points
457      */
458      ESCRIPT_DLL_API
459      inline
460      int
461      getNumDataPoints() const
462      {
463        return getNumSamples() * getNumDataPointsPerSample();
464      }
465      /**
466         \brief
467       Return the number of samples.       Return the number of samples.
468    */    */
469    ESCRIPT_DLL_API    ESCRIPT_DLL_API
# Line 444  class Data { Line 485  class Data {
485    {    {
486      return m_data->getNumDPPSample();      return m_data->getNumDPPSample();
487    }    }
488      /**
489         \brief
490         dumps the object into a netCDF file
491      */
492      ESCRIPT_DLL_API
493      inline
494      void
495      dump(const std::string fileName) const
496      {
497        return m_data->dump(fileName);
498      }
499    
500    /**    /**
501       \brief       \brief
# Line 475  class Data { Line 527  class Data {
527    
528    /**    /**
529       \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  
530       Return a view into the data for the data point specified.       Return a view into the data for the data point specified.
531       NOTE: Construction of the DataArrayView is a relatively expensive       NOTE: Construction of the DataArrayView is a relatively expensive
532       operation.       operation.
# Line 528  class Data { Line 539  class Data {
539    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
540                 int dataPointNo)                 int dataPointNo)
541    {    {
542      return m_data->getDataPoint(sampleNo,dataPointNo);          return m_data->getDataPoint(sampleNo,dataPointNo);
543    }    }
544    
545    /**    /**
# Line 640  class Data { Line 651  class Data {
651    
652    /**    /**
653       \brief       \brief
654         Returns 1./ Data object
655         *
656      */
657      ESCRIPT_DLL_API
658      Data
659      oneOver() const;
660      /**
661         \brief
662       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.
663       *       *
664    */    */
# Line 762  class Data { Line 781  class Data {
781    */    */
782    ESCRIPT_DLL_API    ESCRIPT_DLL_API
783    const boost::python::tuple    const boost::python::tuple
784    mindp() const;    minGlobalDataPoint() const;
785    
786    ESCRIPT_DLL_API    ESCRIPT_DLL_API
787    void    void
788    calc_mindp(int& SampleNo,    calc_minGlobalDataPoint(int& ProcNo,  int& DataPointNo) const;
              int& DataPointNo) const;  
   
789    /**    /**
790       \brief       \brief
791       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 798  class Data {
798    
799    /**    /**
800       \brief       \brief
801         Return the symmetric part of a matrix which is half the matrix plus its transpose.
802         *
803      */
804      ESCRIPT_DLL_API
805      Data
806      symmetric() const;
807    
808      /**
809         \brief
810         Return the nonsymmetric part of a matrix which is half the matrix minus its transpose.
811         *
812      */
813      ESCRIPT_DLL_API
814      Data
815      nonsymmetric() const;
816    
817      /**
818         \brief
819         Return the trace of a matrix
820         *
821      */
822      ESCRIPT_DLL_API
823      Data
824      trace(int axis_offset) const;
825    
826      /**
827         \brief
828         Transpose each data point of this Data object around the given axis.
829         *
830      */
831      ESCRIPT_DLL_API
832      Data
833      transpose(int axis_offset) const;
834    
835      /**
836         \brief
837       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.
838       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.
839       *       *
# Line 804  class Data { Line 857  class Data {
857    
858    /**    /**
859       \brief       \brief
860       Transpose each data point of this Data object around the given axis.       swaps the components axis0 and axis1
      --* not implemented yet *--  
861       *       *
862    */    */
863    ESCRIPT_DLL_API    ESCRIPT_DLL_API
864    Data    Data
865    transpose(int axis) const;    swapaxes(const int axis0, const int axis1) const;
866    
867    /**    /**
868       \brief       \brief
869       Calculate the trace of each data point of this Data object.       Return the error function erf of each data point of this Data object.
870       *       *
871    */    */
872    ESCRIPT_DLL_API    ESCRIPT_DLL_API
873    Data    Data
874    trace() const;    erf() const;
875    
876    /**    /**
877       \brief       \brief
# Line 1190  class Data { Line 1242  class Data {
1242       \brief       \brief
1243       print the data values to stdout. Used for debugging       print the data values to stdout. Used for debugging
1244    */    */
1245    void print();    ESCRIPT_DLL_API
1246      void
1247        print(void);
1248    
1249      /**
1250         \brief
1251         return the MPI rank number of the local data
1252             MPI_COMM_WORLD is assumed and the result of MPI_Comm_size()
1253             is returned
1254      */
1255      ESCRIPT_DLL_API
1256        int
1257        get_MPIRank(void) const;
1258    
1259      /**
1260         \brief
1261         return the MPI rank number of the local data
1262             MPI_COMM_WORLD is assumed and the result of MPI_Comm_rank()
1263             is returned
1264      */
1265      ESCRIPT_DLL_API
1266        int
1267        get_MPISize(void) const;
1268    
1269      /**
1270         \brief
1271         return the MPI rank number of the local data
1272             MPI_COMM_WORLD is assumed and returned.
1273      */
1274      ESCRIPT_DLL_API
1275        MPI_Comm
1276        get_MPIComm(void) const;
1277    
1278      /**
1279         \brief
1280         return the object produced by the factory, which is a DataConstant or DataExpanded
1281      */
1282      ESCRIPT_DLL_API
1283        DataAbstract*
1284        borrowData(void) const;
1285    
1286   protected:   protected:
1287    
# Line 1249  class Data { Line 1340  class Data {
1340    
1341    /**    /**
1342       \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  
1343       Convert the data type of the RHS to match this.       Convert the data type of the RHS to match this.
1344       \param right - Input - data type to match.       \param right - Input - data type to match.
1345    */    */
# Line 1284  class Data { Line 1364  class Data {
1364               const FunctionSpace& what,               const FunctionSpace& what,
1365               bool expanded);               bool expanded);
1366    
1367    /**    //
1368       \brief    // flag to protect the data object against any update
1369       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);  
1370    
1371    //    //
1372    // pointer to the actual data object    // pointer to the actual data object
# Line 1329  Data::initialise(const IValueType& value Line 1403  Data::initialise(const IValueType& value
1403  /**  /**
1404     Binary Data object operators.     Binary Data object operators.
1405  */  */
1406    inline double rpow(double x,double y)
1407    {
1408        return pow(y,x);
1409    }
1410    
1411  /**  /**
1412    \brief    \brief
# Line 1430  ESCRIPT_DLL_API std::ostream& operator<< Line 1508  ESCRIPT_DLL_API std::ostream& operator<<
1508    
1509  /**  /**
1510    \brief    \brief
1511      Compute a tensor product of two Data objects
1512      \param arg0 - Input - Data object
1513      \param arg1 - Input - Data object
1514      \param axis_offset - Input - axis offset
1515      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1516    */
1517    ESCRIPT_DLL_API
1518    Data
1519    C_GeneralTensorProduct(Data& arg0,
1520                         Data& arg1,
1521                         int axis_offset=0,
1522                         int transpose=0);
1523    
1524    /**
1525      \brief
1526    Return true if operands are equivalent, else return false.    Return true if operands are equivalent, else return false.
1527    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
1528    be relied on. Requires further implementation.    be relied on. Requires further implementation.
# Line 1450  Data::binaryOp(const Data& right, Line 1543  Data::binaryOp(const Data& right,
1543     //     //
1544     // 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
1545     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1546       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1547     }     }
1548     //     //
1549     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1502  Data::binaryOp(const Data& right, Line 1595  Data::binaryOp(const Data& right,
1595       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");
1596       escript::binaryOp(*leftC,*rightC,operation);       escript::binaryOp(*leftC,*rightC,operation);
1597     }     }
1598  }     #if defined DOPROF
1599       profData->binary++;
1600  /**     #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);  
    }  
1601  }  }
1602    
1603  /**  /**

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

  ViewVC Help
Powered by ViewVC 1.1.26