/[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 971 by ksteube, Wed Feb 14 04:40:49 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 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      inline
501      void
502      dump(const std::string fileName) const
503      {
504        return m_data->dump(fileName);
505      }
506    
507    /**    /**
508       \brief       \brief
# Line 475  class Data { Line 534  class Data {
534    
535    /**    /**
536       \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  
537       Return a view into the data for the data point specified.       Return a view into the data for the data point specified.
538       NOTE: Construction of the DataArrayView is a relatively expensive       NOTE: Construction of the DataArrayView is a relatively expensive
539       operation.       operation.
# Line 528  class Data { Line 546  class Data {
546    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
547                 int dataPointNo)                 int dataPointNo)
548    {    {
549      return m_data->getDataPoint(sampleNo,dataPointNo);          return m_data->getDataPoint(sampleNo,dataPointNo);
550    }    }
551    
552    /**    /**
# Line 640  class Data { Line 658  class Data {
658    
659    /**    /**
660       \brief       \brief
661         Returns 1./ Data object
662         *
663      */
664      ESCRIPT_DLL_API
665      Data
666      oneOver() const;
667      /**
668         \brief
669       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.
670       *       *
671    */    */
# Line 762  class Data { Line 788  class Data {
788    */    */
789    ESCRIPT_DLL_API    ESCRIPT_DLL_API
790    const boost::python::tuple    const boost::python::tuple
791    mindp() const;    minGlobalDataPoint() const;
792    
793    ESCRIPT_DLL_API    ESCRIPT_DLL_API
794    void    void
795    calc_mindp(int& SampleNo,    calc_minGlobalDataPoint(int& ProcNo,  int& DataPointNo) const;
              int& DataPointNo) const;  
   
796    /**    /**
797       \brief       \brief
798       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 805  class Data {
805    
806    /**    /**
807       \brief       \brief
808         Return the symmetric part of a matrix which is half the matrix plus its transpose.
809         *
810      */
811      ESCRIPT_DLL_API
812      Data
813      symmetric() const;
814    
815      /**
816         \brief
817         Return the nonsymmetric part of a matrix which is half the matrix minus its transpose.
818         *
819      */
820      ESCRIPT_DLL_API
821      Data
822      nonsymmetric() const;
823    
824      /**
825         \brief
826         Return the trace of a matrix
827         *
828      */
829      ESCRIPT_DLL_API
830      Data
831      trace(int axis_offset) const;
832    
833      /**
834         \brief
835         Transpose each data point of this Data object around the given axis.
836         *
837      */
838      ESCRIPT_DLL_API
839      Data
840      transpose(int axis_offset) const;
841    
842      /**
843         \brief
844       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.
845       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.
846       *       *
# Line 804  class Data { Line 864  class Data {
864    
865    /**    /**
866       \brief       \brief
867       Transpose each data point of this Data object around the given axis.       swaps the components axis0 and axis1
      --* not implemented yet *--  
868       *       *
869    */    */
870    ESCRIPT_DLL_API    ESCRIPT_DLL_API
871    Data    Data
872    transpose(int axis) const;    swapaxes(const int axis0, const int axis1) const;
873    
874    /**    /**
875       \brief       \brief
876       Calculate the trace of each data point of this Data object.       Return the error function erf of each data point of this Data object.
877       *       *
878    */    */
879    ESCRIPT_DLL_API    ESCRIPT_DLL_API
880    Data    Data
881    trace() const;    erf() const;
882    
883    /**    /**
884       \brief       \brief
# Line 1190  class Data { Line 1249  class Data {
1249       \brief       \brief
1250       print the data values to stdout. Used for debugging       print the data values to stdout. Used for debugging
1251    */    */
1252    void print();    ESCRIPT_DLL_API
1253      void
1254        print(void);
1255    
1256      /**
1257         \brief
1258         return the MPI rank number of the local data
1259             MPI_COMM_WORLD is assumed and the result of MPI_Comm_size()
1260             is returned
1261      */
1262      ESCRIPT_DLL_API
1263        int
1264        get_MPIRank(void) const;
1265    
1266      /**
1267         \brief
1268         return the MPI rank number of the local data
1269             MPI_COMM_WORLD is assumed and the result of MPI_Comm_rank()
1270             is returned
1271      */
1272      ESCRIPT_DLL_API
1273        int
1274        get_MPISize(void) const;
1275    
1276      /**
1277         \brief
1278         return the MPI rank number of the local data
1279             MPI_COMM_WORLD is assumed and returned.
1280      */
1281      ESCRIPT_DLL_API
1282        MPI_Comm
1283        get_MPIComm(void) const;
1284    
1285      /**
1286         \brief
1287         return the object produced by the factory, which is a DataConstant or DataExpanded
1288      */
1289      ESCRIPT_DLL_API
1290        DataAbstract*
1291        borrowData(void) const;
1292    
1293   protected:   protected:
1294    
# Line 1249  class Data { Line 1347  class Data {
1347    
1348    /**    /**
1349       \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  
1350       Convert the data type of the RHS to match this.       Convert the data type of the RHS to match this.
1351       \param right - Input - data type to match.       \param right - Input - data type to match.
1352    */    */
# Line 1284  class Data { Line 1371  class Data {
1371               const FunctionSpace& what,               const FunctionSpace& what,
1372               bool expanded);               bool expanded);
1373    
1374    /**    //
1375       \brief    // flag to protect the data object against any update
1376       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);  
1377    
1378    //    //
1379    // pointer to the actual data object    // pointer to the actual data object
# Line 1329  Data::initialise(const IValueType& value Line 1410  Data::initialise(const IValueType& value
1410  /**  /**
1411     Binary Data object operators.     Binary Data object operators.
1412  */  */
1413    inline double rpow(double x,double y)
1414    {
1415        return pow(y,x);
1416    };
1417    
1418  /**  /**
1419    \brief    \brief
# Line 1430  ESCRIPT_DLL_API std::ostream& operator<< Line 1515  ESCRIPT_DLL_API std::ostream& operator<<
1515    
1516  /**  /**
1517    \brief    \brief
1518      Compute a tensor product of two Data objects
1519      \param arg0 - Input - Data object
1520      \param arg1 - Input - Data object
1521      \param axis_offset - Input - axis offset
1522      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1523    */
1524    ESCRIPT_DLL_API
1525    Data
1526    C_GeneralTensorProduct(Data& arg0,
1527                         Data& arg1,
1528                         int axis_offset=0,
1529                         int transpose=0);
1530    
1531    /**
1532      \brief
1533    Return true if operands are equivalent, else return false.    Return true if operands are equivalent, else return false.
1534    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
1535    be relied on. Requires further implementation.    be relied on. Requires further implementation.
# Line 1450  Data::binaryOp(const Data& right, Line 1550  Data::binaryOp(const Data& right,
1550     //     //
1551     // 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
1552     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1553       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1554     }     }
1555     //     //
1556     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1502  Data::binaryOp(const Data& right, Line 1602  Data::binaryOp(const Data& right,
1602       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");
1603       escript::binaryOp(*leftC,*rightC,operation);       escript::binaryOp(*leftC,*rightC,operation);
1604     }     }
1605  }     #if defined DOPROF
1606       profData->binary++;
1607  /**     #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);  
    }  
1608  }  }
1609    
1610  /**  /**

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

  ViewVC Help
Powered by ViewVC 1.1.26