/[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 1312 by ksteube, Mon Sep 24 06:18:44 2007 UTC
# Line 1  Line 1 
1  // $Id$  
2  /*  /* $Id$ */
3   ************************************************************  
4   *          Copyright 2006 by ACcESS MNRF                   *  /*******************************************************
5   *                                                          *   *
6   *              http://www.access.edu.au                    *   *           Copyright 2003-2007 by ACceSS MNRF
7   *       Primary Business: Queensland, Australia            *   *       Copyright 2007 by University of Queensland
8   *  Licensed under the Open Software License version 3.0    *   *
9   *     http://www.opensource.org/licenses/osl-3.0.php       *   *                http://esscc.uq.edu.au
10   *                                                          *   *        Primary Business: Queensland, Australia
11   ************************************************************   *  Licensed under the Open Software License version 3.0
12  */   *     http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16  /** \file Data.h */  /** \file Data.h */
17    
# Line 26  Line 28 
28    
29  extern "C" {  extern "C" {
30  #include "DataC.h"  #include "DataC.h"
31  #include "paso/Paso.h"  /* #include "paso/Paso.h" doesn't belong in this file...causes trouble for BruceFactory.cpp */
32  }  }
33    
34    #include "esysmpi.h"
35  #include <string>  #include <string>
36  #include <algorithm>  #include <algorithm>
37    
# Line 66  class Data { Line 69  class Data {
69    typedef double (*UnaryDFunPtr)(double);    typedef double (*UnaryDFunPtr)(double);
70    typedef double (*BinaryDFunPtr)(double,double);    typedef double (*BinaryDFunPtr)(double,double);
71    
72    
73    /**    /**
74       Constructors.       Constructors.
75    */    */
# Line 234  class Data { Line 238  class Data {
238    
239    /**    /**
240       \brief       \brief
241       Return the values of all data-points as a single python numarray object.       switches on update protection
242    
243    */    */
244    ESCRIPT_DLL_API    ESCRIPT_DLL_API
245    const boost::python::numeric::array    void
246    convertToNumArray();    setProtection();
247    
248    /**    /**
249       \brief       \brief
250       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
251    
252    */    */
253    ESCRIPT_DLL_API    ESCRIPT_DLL_API
254    const boost::python::numeric::array    bool
255    convertToNumArrayFromSampleNo(int sampleNo);    isProtected() const;
256    
257    /**    /**
258       \brief       \brief
259       Return the value of the specified data-point as a single python numarray object.       Return the values of a data point on this process
260    */    */
261    ESCRIPT_DLL_API    ESCRIPT_DLL_API
262    const boost::python::numeric::array    const boost::python::numeric::array
263    convertToNumArrayFromDPNo(int sampleNo,    getValueOfDataPoint(int dataPointNo);
                             int dataPointNo);  
264    
265    /**    /**
266       \brief       \brief
267       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
268    */    */
269    ESCRIPT_DLL_API    ESCRIPT_DLL_API
270    void    void
271    fillFromNumArray(const boost::python::numeric::array);    setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object);
272    
273      /**
274         \brief
275         sets the values of a data-point from a numarray object on this process
276      */
277      ESCRIPT_DLL_API
278      void
279      setValueOfDataPointToArray(int dataPointNo, const boost::python::numeric::array&);
280    
281      /**
282         \brief
283         sets the values of a data-point on this process
284      */
285      ESCRIPT_DLL_API
286      void
287      setValueOfDataPoint(int dataPointNo, const double);
288    
289      /**
290         \brief
291         Return the value of the specified data-point across all processors
292      */
293      ESCRIPT_DLL_API
294      const boost::python::numeric::array
295      getValueOfGlobalDataPoint(int procNo, int dataPointNo);
296    
297    /**    /**
298       \brief       \brief
# Line 423  class Data { Line 452  class Data {
452    
453    /**    /**
454       \brief       \brief
455         Return the number of data points
456      */
457      ESCRIPT_DLL_API
458      inline
459      int
460      getNumDataPoints() const
461      {
462        return getNumSamples() * getNumDataPointsPerSample();
463      }
464      /**
465         \brief
466       Return the number of samples.       Return the number of samples.
467    */    */
468    ESCRIPT_DLL_API    ESCRIPT_DLL_API
# Line 444  class Data { Line 484  class Data {
484    {    {
485      return m_data->getNumDPPSample();      return m_data->getNumDPPSample();
486    }    }
487      /**
488         \brief
489         dumps the object into a netCDF file
490      */
491      ESCRIPT_DLL_API
492      void
493      dump(const std::string fileName) const;
494    /**    /**
495       \brief       \brief
496       Return the sample data for the given sample no. This is not the       Return the sample data for the given sample no. This is not the
# Line 475  class Data { Line 521  class Data {
521    
522    /**    /**
523       \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  
524       Return a view into the data for the data point specified.       Return a view into the data for the data point specified.
525       NOTE: Construction of the DataArrayView is a relatively expensive       NOTE: Construction of the DataArrayView is a relatively expensive
526       operation.       operation.
# Line 528  class Data { Line 533  class Data {
533    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
534                 int dataPointNo)                 int dataPointNo)
535    {    {
536      return m_data->getDataPoint(sampleNo,dataPointNo);          return m_data->getDataPoint(sampleNo,dataPointNo);
537    }    }
538    
539    /**    /**
# Line 564  class Data { Line 569  class Data {
569    DataArrayView::ValueType::size_type    DataArrayView::ValueType::size_type
570    getLength() const;    getLength() const;
571    
572    
573    
574      /**
575         \brief
576         Assign the given value to the tag assocciated with name. Implicitly converts this
577         object to type DataTagged. Throws an exception if this object
578         cannot be converted to a DataTagged object or name cannot be mapped onto a tag key.
579         \param tagKey - Input - Integer key.
580         \param value - Input - Value to associate with given key.
581        ==>*
582      */
583      ESCRIPT_DLL_API
584      void
585      setTaggedValueByName(std::string name,
586                           const boost::python::object& value);
587    
588    /**    /**
589       \brief       \brief
590       Assign the given value to the tag. Implicitly converts this       Assign the given value to the tag. Implicitly converts this
# Line 607  class Data { Line 628  class Data {
628    
629    /**    /**
630       \brief       \brief
631         set all values to zero
632         *
633      */
634      ESCRIPT_DLL_API
635      void
636      setToZero();
637    
638      /**
639         \brief
640       Interpolates this onto the given functionspace and returns       Interpolates this onto the given functionspace and returns
641       the result as a Data object.       the result as a Data object.
642       *       *
# Line 614  class Data { Line 644  class Data {
644    ESCRIPT_DLL_API    ESCRIPT_DLL_API
645    Data    Data
646    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
   
647    /**    /**
648       \brief       \brief
649       Calculates the gradient of the data at the data points of functionspace.       Calculates the gradient of the data at the data points of functionspace.
# Line 640  class Data { Line 669  class Data {
669    
670    /**    /**
671       \brief       \brief
672         Returns 1./ Data object
673         *
674      */
675      ESCRIPT_DLL_API
676      Data
677      oneOver() const;
678      /**
679         \brief
680       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.
681       *       *
682    */    */
# Line 703  class Data { Line 740  class Data {
740    
741    /**    /**
742       \brief       \brief
      Return the minimum absolute value of this Data object.  
      *  
   */  
   ESCRIPT_DLL_API  
   double  
   Linf() const;  
   
   /**  
      \brief  
743       Return the maximum value of this Data object.       Return the maximum value of this Data object.
744       *       *
745    */    */
# Line 762  class Data { Line 790  class Data {
790    */    */
791    ESCRIPT_DLL_API    ESCRIPT_DLL_API
792    const boost::python::tuple    const boost::python::tuple
793    mindp() const;    minGlobalDataPoint() const;
794    
795    ESCRIPT_DLL_API    ESCRIPT_DLL_API
796    void    void
797    calc_mindp(int& SampleNo,    calc_minGlobalDataPoint(int& ProcNo,  int& DataPointNo) const;
              int& DataPointNo) const;  
   
798    /**    /**
799       \brief       \brief
800       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 807  class Data {
807    
808    /**    /**
809       \brief       \brief
810         Return the symmetric part of a matrix which is half the matrix plus its transpose.
811         *
812      */
813      ESCRIPT_DLL_API
814      Data
815      symmetric() const;
816    
817      /**
818         \brief
819         Return the nonsymmetric part of a matrix which is half the matrix minus its transpose.
820         *
821      */
822      ESCRIPT_DLL_API
823      Data
824      nonsymmetric() const;
825    
826      /**
827         \brief
828         Return the trace of a matrix
829         *
830      */
831      ESCRIPT_DLL_API
832      Data
833      trace(int axis_offset) const;
834    
835      /**
836         \brief
837         Transpose each data point of this Data object around the given axis.
838         *
839      */
840      ESCRIPT_DLL_API
841      Data
842      transpose(int axis_offset) const;
843    
844      /**
845         \brief
846       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.
847       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.
848       *       *
# Line 804  class Data { Line 866  class Data {
866    
867    /**    /**
868       \brief       \brief
869       Transpose each data point of this Data object around the given axis.       swaps the components axis0 and axis1
      --* not implemented yet *--  
870       *       *
871    */    */
872    ESCRIPT_DLL_API    ESCRIPT_DLL_API
873    Data    Data
874    transpose(int axis) const;    swapaxes(const int axis0, const int axis1) const;
875    
876    /**    /**
877       \brief       \brief
878       Calculate the trace of each data point of this Data object.       Return the error function erf of each data point of this Data object.
879       *       *
880    */    */
881    ESCRIPT_DLL_API    ESCRIPT_DLL_API
882    Data    Data
883    trace() const;    erf() const;
884    
885    /**    /**
886       \brief       \brief
# Line 1045  class Data { Line 1106  class Data {
1106    ESCRIPT_DLL_API    ESCRIPT_DLL_API
1107    Data& operator+=(const boost::python::object& right);    Data& operator+=(const boost::python::object& right);
1108    
1109      ESCRIPT_DLL_API
1110      Data& operator=(const Data& other);
1111    
1112    /**    /**
1113       \brief       \brief
1114       Overloaded operator -=       Overloaded operator -=
# Line 1190  class Data { Line 1254  class Data {
1254       \brief       \brief
1255       print the data values to stdout. Used for debugging       print the data values to stdout. Used for debugging
1256    */    */
1257    void print();    ESCRIPT_DLL_API
1258      void
1259        print(void);
1260    
1261      /**
1262         \brief
1263         return the MPI rank number of the local data
1264             MPI_COMM_WORLD is assumed and the result of MPI_Comm_size()
1265             is returned
1266      */
1267      ESCRIPT_DLL_API
1268        int
1269        get_MPIRank(void) const;
1270    
1271      /**
1272         \brief
1273         return the MPI rank number of the local data
1274             MPI_COMM_WORLD is assumed and the result of MPI_Comm_rank()
1275             is returned
1276      */
1277      ESCRIPT_DLL_API
1278        int
1279        get_MPISize(void) const;
1280    
1281      /**
1282         \brief
1283         return the MPI rank number of the local data
1284             MPI_COMM_WORLD is assumed and returned.
1285      */
1286      ESCRIPT_DLL_API
1287        MPI_Comm
1288        get_MPIComm(void) const;
1289    
1290      /**
1291         \brief
1292         return the object produced by the factory, which is a DataConstant or DataExpanded
1293      */
1294      ESCRIPT_DLL_API
1295        DataAbstract*
1296        borrowData(void) const;
1297    
1298   protected:   protected:
1299    
# Line 1249  class Data { Line 1352  class Data {
1352    
1353    /**    /**
1354       \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  
1355       Convert the data type of the RHS to match this.       Convert the data type of the RHS to match this.
1356       \param right - Input - data type to match.       \param right - Input - data type to match.
1357    */    */
# Line 1284  class Data { Line 1376  class Data {
1376               const FunctionSpace& what,               const FunctionSpace& what,
1377               bool expanded);               bool expanded);
1378    
1379    /**    //
1380       \brief    // flag to protect the data object against any update
1381       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);  
1382    
1383    //    //
1384    // pointer to the actual data object    // pointer to the actual data object
1385    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
1386    
   //  
   // pointer to the internal profiling data  
   struct profDataEntry *profData;  
   
1387  };  };
1388    
1389  template <class IValueType>  template <class IValueType>
# Line 1329  Data::initialise(const IValueType& value Line 1411  Data::initialise(const IValueType& value
1411  /**  /**
1412     Binary Data object operators.     Binary Data object operators.
1413  */  */
1414    inline double rpow(double x,double y)
1415    {
1416        return pow(y,x);
1417    }
1418    
1419  /**  /**
1420    \brief    \brief
# Line 1422  ESCRIPT_DLL_API Data operator*(const boo Line 1508  ESCRIPT_DLL_API Data operator*(const boo
1508  */  */
1509  ESCRIPT_DLL_API Data operator/(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator/(const boost::python::object& left, const Data& right);
1510    
1511    
1512    
1513  /**  /**
1514    \brief    \brief
1515    Output operator    Output operator
# Line 1430  ESCRIPT_DLL_API std::ostream& operator<< Line 1518  ESCRIPT_DLL_API std::ostream& operator<<
1518    
1519  /**  /**
1520    \brief    \brief
1521      Compute a tensor product of two Data objects
1522      \param arg0 - Input - Data object
1523      \param arg1 - Input - Data object
1524      \param axis_offset - Input - axis offset
1525      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1526    */
1527    ESCRIPT_DLL_API
1528    Data
1529    C_GeneralTensorProduct(Data& arg0,
1530                         Data& arg1,
1531                         int axis_offset=0,
1532                         int transpose=0);
1533    
1534    /**
1535      \brief
1536    Return true if operands are equivalent, else return false.    Return true if operands are equivalent, else return false.
1537    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
1538    be relied on. Requires further implementation.    be relied on. Requires further implementation.
1539  */  */
1540  //ESCRIPT_DLL_API bool operator==(const Data& left, const Data& right);  // ESCRIPT_DLL_API bool operator==(const Data& left, const Data& right);
1541    
1542  /**  /**
1543    \brief    \brief
# Line 1450  Data::binaryOp(const Data& right, Line 1553  Data::binaryOp(const Data& right,
1553     //     //
1554     // 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
1555     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1556       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1557     }     }
1558     //     //
1559     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1504  Data::binaryOp(const Data& right, Line 1607  Data::binaryOp(const Data& right,
1607     }     }
1608  }  }
1609    
 /**  
   \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);  
    }  
 }  
   
1610  /**  /**
1611    \brief    \brief
1612    Perform the given unary operation on other and return the result.    Perform the given unary operation on other and return the result.

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

  ViewVC Help
Powered by ViewVC 1.1.26