/[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 854 by gross, Thu Sep 21 05:29:42 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 252  class Data { Line 274  class Data {
274       \brief       \brief
275       Return the value of the specified data-point as a single python numarray object.       Return the value of the specified data-point as a single python numarray object.
276    */    */
277    #ifndef PASO_MPI  
278    ESCRIPT_DLL_API    ESCRIPT_DLL_API
279    const boost::python::numeric::array    const boost::python::numeric::array
280    convertToNumArrayFromDPNo(int sampleNo,    convertToNumArrayFromDPNo(int ProcNo,
281                                                            int sampleNo,
282                              int dataPointNo);                              int dataPointNo);
283    #else
284      ESCRIPT_DLL_API
285      const boost::python::numeric::array
286      convertToNumArrayFromDPNo(int procNo,
287                    int sampleNo,
288                    int dataPointNo);
289    #endif
290    
291    
292    /**    /**
293       \brief       \brief
# Line 528  class Data { Line 560  class Data {
560    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
561                 int dataPointNo)                 int dataPointNo)
562    {    {
563      return m_data->getDataPoint(sampleNo,dataPointNo);          return m_data->getDataPoint(sampleNo,dataPointNo);
564    }    }
565    
566    /**    /**
# Line 640  class Data { Line 672  class Data {
672    
673    /**    /**
674       \brief       \brief
675         Returns 1./ Data object
676         *
677      */
678      ESCRIPT_DLL_API
679      Data
680      oneOver() const;
681      /**
682         \brief
683       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.
684       *       *
685    */    */
# Line 766  class Data { Line 806  class Data {
806    
807    ESCRIPT_DLL_API    ESCRIPT_DLL_API
808    void    void
809    calc_mindp(int& SampleNo,    calc_mindp(int& ProcNo,
810                            int& SampleNo,  
811               int& DataPointNo) const;               int& DataPointNo) const;
   
812    /**    /**
813       \brief       \brief
814       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 821  class Data {
821    
822    /**    /**
823       \brief       \brief
824         Return the symmetric part of a matrix which is half the matrix plus its transpose.
825         *
826      */
827      ESCRIPT_DLL_API
828      Data
829      symmetric() const;
830    
831      /**
832         \brief
833         Return the nonsymmetric part of a matrix which is half the matrix minus its transpose.
834         *
835      */
836      ESCRIPT_DLL_API
837      Data
838      nonsymmetric() const;
839    
840      /**
841         \brief
842         Return the trace of a matrix
843         *
844      */
845      ESCRIPT_DLL_API
846      Data
847      trace(int axis_offset) const;
848    
849      /**
850         \brief
851         Transpose each data point of this Data object around the given axis.
852         *
853      */
854      ESCRIPT_DLL_API
855      Data
856      transpose(int axis_offset) const;
857    
858      /**
859         \brief
860       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.
861       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.
862       *       *
# Line 804  class Data { Line 880  class Data {
880    
881    /**    /**
882       \brief       \brief
883       Transpose each data point of this Data object around the given axis.       swaps the components axis0 and axis1
      --* not implemented yet *--  
      *  
   */  
   ESCRIPT_DLL_API  
   Data  
   transpose(int axis) const;  
   
   /**  
      \brief  
      Calculate the trace of each data point of this Data object.  
884       *       *
885    */    */
886    ESCRIPT_DLL_API    ESCRIPT_DLL_API
887    Data    Data
888    trace() const;    swapaxes(const int axis0, const int axis1) const;
889    
890    /**    /**
891       \brief       \brief
# Line 1190  class Data { Line 1256  class Data {
1256       \brief       \brief
1257       print the data values to stdout. Used for debugging       print the data values to stdout. Used for debugging
1258    */    */
1259    void print();    ESCRIPT_DLL_API
1260      void
1261        print(void);
1262    
1263      /**
1264         \brief
1265         return the MPI rank number of the local data
1266             MPI_COMM_WORLD is assumed and the result of MPI_Comm_size()
1267             is returned
1268      */
1269      ESCRIPT_DLL_API
1270        int
1271        get_MPIRank(void) const;
1272    
1273      /**
1274         \brief
1275         return the MPI rank number of the local data
1276             MPI_COMM_WORLD is assumed and the result of MPI_Comm_rank()
1277             is returned
1278      */
1279      ESCRIPT_DLL_API
1280        int
1281        get_MPISize(void) const;
1282    
1283      /**
1284         \brief
1285         return the MPI rank number of the local data
1286             MPI_COMM_WORLD is assumed and returned.
1287      */
1288      ESCRIPT_DLL_API
1289        MPI_Comm
1290        get_MPIComm(void) const;
1291    
1292      /**
1293         \brief
1294         return the object produced by the factory, which is a DataConstant or DataExpanded
1295      */
1296      ESCRIPT_DLL_API
1297        DataAbstract*
1298        borrowData(void) const;
1299    
1300   protected:   protected:
1301    
# Line 1249  class Data { Line 1354  class Data {
1354    
1355    /**    /**
1356       \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  
1357       Convert the data type of the RHS to match this.       Convert the data type of the RHS to match this.
1358       \param right - Input - data type to match.       \param right - Input - data type to match.
1359    */    */
# Line 1284  class Data { Line 1378  class Data {
1378               const FunctionSpace& what,               const FunctionSpace& what,
1379               bool expanded);               bool expanded);
1380    
1381    /**    //
1382       \brief    // flag to protect the data object against any update
1383       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);  
1384    
1385    //    //
1386    // pointer to the actual data object    // pointer to the actual data object
# Line 1329  Data::initialise(const IValueType& value Line 1417  Data::initialise(const IValueType& value
1417  /**  /**
1418     Binary Data object operators.     Binary Data object operators.
1419  */  */
1420    inline double rpow(double x,double y)
1421    {
1422        return pow(y,x);
1423    };
1424    
1425  /**  /**
1426    \brief    \brief
# Line 1430  ESCRIPT_DLL_API std::ostream& operator<< Line 1522  ESCRIPT_DLL_API std::ostream& operator<<
1522    
1523  /**  /**
1524    \brief    \brief
1525      Compute a tensor product of two Data objects
1526      \param arg0 - Input - Data object
1527      \param arg1 - Input - Data object
1528      \param axis_offset - Input - axis offset
1529      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1530    */
1531    ESCRIPT_DLL_API
1532    Data
1533    C_GeneralTensorProduct(Data& arg0,
1534                         Data& arg1,
1535                         int axis_offset=0,
1536                         int transpose=0);
1537    
1538    /**
1539      \brief
1540    Return true if operands are equivalent, else return false.    Return true if operands are equivalent, else return false.
1541    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
1542    be relied on. Requires further implementation.    be relied on. Requires further implementation.
# Line 1450  Data::binaryOp(const Data& right, Line 1557  Data::binaryOp(const Data& right,
1557     //     //
1558     // 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
1559     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1560       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1561     }     }
1562     //     //
1563     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1502  Data::binaryOp(const Data& right, Line 1609  Data::binaryOp(const Data& right,
1609       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");
1610       escript::binaryOp(*leftC,*rightC,operation);       escript::binaryOp(*leftC,*rightC,operation);
1611     }     }
1612  }     #if defined DOPROF
1613       profData->binary++;
1614  /**     #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);  
    }  
1615  }  }
1616    
1617  /**  /**

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

  ViewVC Help
Powered by ViewVC 1.1.26