/[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 914 by gross, Thu Dec 14 04:38:18 2006 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 254  class Data { Line 276  class Data {
276    */    */
277    ESCRIPT_DLL_API    ESCRIPT_DLL_API
278    const boost::python::numeric::array    const boost::python::numeric::array
279    convertToNumArrayFromDPNo(int sampleNo,    convertToNumArrayFromDPNo(int procNo,
280                              int dataPointNo);                  int sampleNo,
281                    int dataPointNo);
282    /**    /**
283       \brief       \brief
284       Fills the expanded Data object from values of a python numarray object.       Fills the expanded Data object from values of a python numarray object.
# Line 528  class Data { Line 550  class Data {
550    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
551                 int dataPointNo)                 int dataPointNo)
552    {    {
553      return m_data->getDataPoint(sampleNo,dataPointNo);          return m_data->getDataPoint(sampleNo,dataPointNo);
554    }    }
555    
556    /**    /**
# Line 640  class Data { Line 662  class Data {
662    
663    /**    /**
664       \brief       \brief
665         Returns 1./ Data object
666         *
667      */
668      ESCRIPT_DLL_API
669      Data
670      oneOver() const;
671      /**
672         \brief
673       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.
674       *       *
675    */    */
# Line 766  class Data { Line 796  class Data {
796    
797    ESCRIPT_DLL_API    ESCRIPT_DLL_API
798    void    void
799    calc_mindp(int& SampleNo,    calc_mindp(int& ProcNo,
800                            int& SampleNo,  
801               int& DataPointNo) const;               int& DataPointNo) const;
   
802    /**    /**
803       \brief       \brief
804       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 811  class Data {
811    
812    /**    /**
813       \brief       \brief
814         Return the symmetric part of a matrix which is half the matrix plus its transpose.
815         *
816      */
817      ESCRIPT_DLL_API
818      Data
819      symmetric() const;
820    
821      /**
822         \brief
823         Return the nonsymmetric part of a matrix which is half the matrix minus its transpose.
824         *
825      */
826      ESCRIPT_DLL_API
827      Data
828      nonsymmetric() const;
829    
830      /**
831         \brief
832         Return the trace of a matrix
833         *
834      */
835      ESCRIPT_DLL_API
836      Data
837      trace(int axis_offset) const;
838    
839      /**
840         \brief
841         Transpose each data point of this Data object around the given axis.
842         *
843      */
844      ESCRIPT_DLL_API
845      Data
846      transpose(int axis_offset) const;
847    
848      /**
849         \brief
850       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.
851       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.
852       *       *
# Line 804  class Data { Line 870  class Data {
870    
871    /**    /**
872       \brief       \brief
873       Transpose each data point of this Data object around the given axis.       swaps the components axis0 and axis1
      --* not implemented yet *--  
874       *       *
875    */    */
876    ESCRIPT_DLL_API    ESCRIPT_DLL_API
877    Data    Data
878    transpose(int axis) const;    swapaxes(const int axis0, const int axis1) const;
879    
880    /**    /**
881       \brief       \brief
882       Calculate the trace of each data point of this Data object.       Return the error function erf of each data point of this Data object.
883       *       *
884    */    */
885    ESCRIPT_DLL_API    ESCRIPT_DLL_API
886    Data    Data
887    trace() const;    erf() const;
888    
889    /**    /**
890       \brief       \brief
# Line 1190  class Data { Line 1255  class Data {
1255       \brief       \brief
1256       print the data values to stdout. Used for debugging       print the data values to stdout. Used for debugging
1257    */    */
1258    void print();    ESCRIPT_DLL_API
1259      void
1260        print(void);
1261    
1262      /**
1263         \brief
1264         return the MPI rank number of the local data
1265             MPI_COMM_WORLD is assumed and the result of MPI_Comm_size()
1266             is returned
1267      */
1268      ESCRIPT_DLL_API
1269        int
1270        get_MPIRank(void) const;
1271    
1272      /**
1273         \brief
1274         return the MPI rank number of the local data
1275             MPI_COMM_WORLD is assumed and the result of MPI_Comm_rank()
1276             is returned
1277      */
1278      ESCRIPT_DLL_API
1279        int
1280        get_MPISize(void) const;
1281    
1282      /**
1283         \brief
1284         return the MPI rank number of the local data
1285             MPI_COMM_WORLD is assumed and returned.
1286      */
1287      ESCRIPT_DLL_API
1288        MPI_Comm
1289        get_MPIComm(void) const;
1290    
1291      /**
1292         \brief
1293         return the object produced by the factory, which is a DataConstant or DataExpanded
1294      */
1295      ESCRIPT_DLL_API
1296        DataAbstract*
1297        borrowData(void) const;
1298    
1299   protected:   protected:
1300    
# Line 1249  class Data { Line 1353  class Data {
1353    
1354    /**    /**
1355       \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  
1356       Convert the data type of the RHS to match this.       Convert the data type of the RHS to match this.
1357       \param right - Input - data type to match.       \param right - Input - data type to match.
1358    */    */
# Line 1284  class Data { Line 1377  class Data {
1377               const FunctionSpace& what,               const FunctionSpace& what,
1378               bool expanded);               bool expanded);
1379    
1380    /**    //
1381       \brief    // flag to protect the data object against any update
1382       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);  
1383    
1384    //    //
1385    // pointer to the actual data object    // pointer to the actual data object
# Line 1329  Data::initialise(const IValueType& value Line 1416  Data::initialise(const IValueType& value
1416  /**  /**
1417     Binary Data object operators.     Binary Data object operators.
1418  */  */
1419    inline double rpow(double x,double y)
1420    {
1421        return pow(y,x);
1422    };
1423    
1424  /**  /**
1425    \brief    \brief
# Line 1430  ESCRIPT_DLL_API std::ostream& operator<< Line 1521  ESCRIPT_DLL_API std::ostream& operator<<
1521    
1522  /**  /**
1523    \brief    \brief
1524      Compute a tensor product of two Data objects
1525      \param arg0 - Input - Data object
1526      \param arg1 - Input - Data object
1527      \param axis_offset - Input - axis offset
1528      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1529    */
1530    ESCRIPT_DLL_API
1531    Data
1532    C_GeneralTensorProduct(Data& arg0,
1533                         Data& arg1,
1534                         int axis_offset=0,
1535                         int transpose=0);
1536    
1537    /**
1538      \brief
1539    Return true if operands are equivalent, else return false.    Return true if operands are equivalent, else return false.
1540    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
1541    be relied on. Requires further implementation.    be relied on. Requires further implementation.
# Line 1450  Data::binaryOp(const Data& right, Line 1556  Data::binaryOp(const Data& right,
1556     //     //
1557     // 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
1558     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1559       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1560     }     }
1561     //     //
1562     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1502  Data::binaryOp(const Data& right, Line 1608  Data::binaryOp(const Data& right,
1608       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");
1609       escript::binaryOp(*leftC,*rightC,operation);       escript::binaryOp(*leftC,*rightC,operation);
1610     }     }
1611  }     #if defined DOPROF
1612       profData->binary++;
1613  /**     #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);  
    }  
1614  }  }
1615    
1616  /**  /**

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

  ViewVC Help
Powered by ViewVC 1.1.26