/[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 922 by gross, Fri Jan 5 04:23:05 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         switches on update protection
243    
244      */
245      ESCRIPT_DLL_API
246      void
247      setProtection();
248    
249      /**
250         \brief
251         Returns trueif the data object is protected against update
252    
253      */
254      ESCRIPT_DLL_API
255      bool
256      isProtected() const;
257      /**
258         \brief
259       Return the values of all data-points as a single python numarray object.       Return the values of all data-points as a single python numarray object.
260    */    */
261    ESCRIPT_DLL_API    ESCRIPT_DLL_API
# Line 242  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    */    */
277    ESCRIPT_DLL_API    ESCRIPT_DLL_API
278    const boost::python::numeric::array    const boost::python::numeric::array
279    convertToNumArrayFromDPNo(int sampleNo,    getValueOfDataPoint(int dataPointNo);
                             int dataPointNo);  
280    
281    /**    /**
282       \brief       \brief
283       Fills the expanded Data object from values of a python numarray object.       sets the values of a data-point on this process
284    */    */
285    ESCRIPT_DLL_API    ESCRIPT_DLL_API
286    void    void
287    fillFromNumArray(const boost::python::numeric::array);    setValueOfDataPointToArray(int dataPointNo, const boost::python::numeric::array);
288    
289      /**
290         \brief
291         sets the values of a data-point on this process
292      */
293      ESCRIPT_DLL_API
294      void
295      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 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 528  class Data { Line 576  class Data {
576    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
577                 int dataPointNo)                 int dataPointNo)
578    {    {
579      return m_data->getDataPoint(sampleNo,dataPointNo);          return m_data->getDataPoint(sampleNo,dataPointNo);
580    }    }
581    
582    /**    /**
# Line 640  class Data { Line 688  class Data {
688    
689    /**    /**
690       \brief       \brief
691         Returns 1./ Data object
692         *
693      */
694      ESCRIPT_DLL_API
695      Data
696      oneOver() const;
697      /**
698         \brief
699       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.
700       *       *
701    */    */
# Line 762  class Data { Line 818  class Data {
818    */    */
819    ESCRIPT_DLL_API    ESCRIPT_DLL_API
820    const boost::python::tuple    const boost::python::tuple
821    mindp() const;    minGlobalDataPoint() const;
822    
823    ESCRIPT_DLL_API    ESCRIPT_DLL_API
824    void    void
825    calc_mindp(int& SampleNo,    calc_minGlobalDataPoint(int& ProcNo,  int& DataPointNo) const;
              int& DataPointNo) const;  
   
826    /**    /**
827       \brief       \brief
828       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 835  class Data {
835    
836    /**    /**
837       \brief       \brief
838         Return the symmetric part of a matrix which is half the matrix plus its transpose.
839         *
840      */
841      ESCRIPT_DLL_API
842      Data
843      symmetric() const;
844    
845      /**
846         \brief
847         Return the nonsymmetric part of a matrix which is half the matrix minus its transpose.
848         *
849      */
850      ESCRIPT_DLL_API
851      Data
852      nonsymmetric() const;
853    
854      /**
855         \brief
856         Return the trace of a matrix
857         *
858      */
859      ESCRIPT_DLL_API
860      Data
861      trace(int axis_offset) const;
862    
863      /**
864         \brief
865         Transpose each data point of this Data object around the given axis.
866         *
867      */
868      ESCRIPT_DLL_API
869      Data
870      transpose(int axis_offset) const;
871    
872      /**
873         \brief
874       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.
875       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.
876       *       *
# Line 804  class Data { Line 894  class Data {
894    
895    /**    /**
896       \brief       \brief
897       Transpose each data point of this Data object around the given axis.       swaps the components axis0 and axis1
      --* not implemented yet *--  
898       *       *
899    */    */
900    ESCRIPT_DLL_API    ESCRIPT_DLL_API
901    Data    Data
902    transpose(int axis) const;    swapaxes(const int axis0, const int axis1) const;
903    
904    /**    /**
905       \brief       \brief
906       Calculate the trace of each data point of this Data object.       Return the error function erf of each data point of this Data object.
907       *       *
908    */    */
909    ESCRIPT_DLL_API    ESCRIPT_DLL_API
910    Data    Data
911    trace() const;    erf() const;
912    
913    /**    /**
914       \brief       \brief
# Line 1190  class Data { Line 1279  class Data {
1279       \brief       \brief
1280       print the data values to stdout. Used for debugging       print the data values to stdout. Used for debugging
1281    */    */
1282    void print();    ESCRIPT_DLL_API
1283      void
1284        print(void);
1285    
1286      /**
1287         \brief
1288         return the MPI rank number of the local data
1289             MPI_COMM_WORLD is assumed and the result of MPI_Comm_size()
1290             is returned
1291      */
1292      ESCRIPT_DLL_API
1293        int
1294        get_MPIRank(void) const;
1295    
1296      /**
1297         \brief
1298         return the MPI rank number of the local data
1299             MPI_COMM_WORLD is assumed and the result of MPI_Comm_rank()
1300             is returned
1301      */
1302      ESCRIPT_DLL_API
1303        int
1304        get_MPISize(void) const;
1305    
1306      /**
1307         \brief
1308         return the MPI rank number of the local data
1309             MPI_COMM_WORLD is assumed and returned.
1310      */
1311      ESCRIPT_DLL_API
1312        MPI_Comm
1313        get_MPIComm(void) const;
1314    
1315      /**
1316         \brief
1317         return the object produced by the factory, which is a DataConstant or DataExpanded
1318      */
1319      ESCRIPT_DLL_API
1320        DataAbstract*
1321        borrowData(void) const;
1322    
1323   protected:   protected:
1324    
# Line 1249  class Data { Line 1377  class Data {
1377    
1378    /**    /**
1379       \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  
1380       Convert the data type of the RHS to match this.       Convert the data type of the RHS to match this.
1381       \param right - Input - data type to match.       \param right - Input - data type to match.
1382    */    */
# Line 1284  class Data { Line 1401  class Data {
1401               const FunctionSpace& what,               const FunctionSpace& what,
1402               bool expanded);               bool expanded);
1403    
1404    /**    //
1405       \brief    // flag to protect the data object against any update
1406       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);  
1407    
1408    //    //
1409    // pointer to the actual data object    // pointer to the actual data object
# Line 1329  Data::initialise(const IValueType& value Line 1440  Data::initialise(const IValueType& value
1440  /**  /**
1441     Binary Data object operators.     Binary Data object operators.
1442  */  */
1443    inline double rpow(double x,double y)
1444    {
1445        return pow(y,x);
1446    };
1447    
1448  /**  /**
1449    \brief    \brief
# Line 1430  ESCRIPT_DLL_API std::ostream& operator<< Line 1545  ESCRIPT_DLL_API std::ostream& operator<<
1545    
1546  /**  /**
1547    \brief    \brief
1548      Compute a tensor product of two Data objects
1549      \param arg0 - Input - Data object
1550      \param arg1 - Input - Data object
1551      \param axis_offset - Input - axis offset
1552      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1553    */
1554    ESCRIPT_DLL_API
1555    Data
1556    C_GeneralTensorProduct(Data& arg0,
1557                         Data& arg1,
1558                         int axis_offset=0,
1559                         int transpose=0);
1560    
1561    /**
1562      \brief
1563    Return true if operands are equivalent, else return false.    Return true if operands are equivalent, else return false.
1564    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
1565    be relied on. Requires further implementation.    be relied on. Requires further implementation.
# Line 1450  Data::binaryOp(const Data& right, Line 1580  Data::binaryOp(const Data& right,
1580     //     //
1581     // 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
1582     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1583       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1584     }     }
1585     //     //
1586     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1502  Data::binaryOp(const Data& right, Line 1632  Data::binaryOp(const Data& right,
1632       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");
1633       escript::binaryOp(*leftC,*rightC,operation);       escript::binaryOp(*leftC,*rightC,operation);
1634     }     }
1635  }     #if defined DOPROF
1636       profData->binary++;
1637  /**     #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);  
    }  
1638  }  }
1639    
1640  /**  /**

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

  ViewVC Help
Powered by ViewVC 1.1.26