/[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 804 by gross, Thu Aug 10 01:12:16 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  #ifndef PASO_MPI  #include "esysmpi.h"
 #define MPI_Comm long  
 #endif  
   
35  #include <string>  #include <string>
36  #include <algorithm>  #include <algorithm>
37    
# Line 70  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 253  class Data { Line 253  class Data {
253    ESCRIPT_DLL_API    ESCRIPT_DLL_API
254    bool    bool
255    isProtected() const;    isProtected() const;
256    
257    /**    /**
258       \brief       \brief
259       Return the values of all data-points 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    convertToNumArray();    getValueOfDataPoint(int dataPointNo);
264    
265    /**    /**
266       \brief       \brief
267       Return the values of all data-points for the given sample as a single 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    const boost::python::numeric::array    void
271    convertToNumArrayFromSampleNo(int sampleNo);    setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object);
272    
273    /**    /**
274       \brief       \brief
275       Return the value of the specified data-point as a single python numarray object.       sets the values of a data-point from a numarray object on this process
276    */    */
 #ifndef PASO_MPI    
   ESCRIPT_DLL_API  
   const boost::python::numeric::array  
   convertToNumArrayFromDPNo(int ProcNo,  
                                                         int sampleNo,  
                             int dataPointNo);  
 #else  
277    ESCRIPT_DLL_API    ESCRIPT_DLL_API
278    const boost::python::numeric::array    void
279    convertToNumArrayFromDPNo(int procNo,    setValueOfDataPointToArray(int dataPointNo, const boost::python::numeric::array&);
                 int sampleNo,  
                 int dataPointNo);  
 #endif  
   
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);    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 454  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 475  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 506  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 595  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 638  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 645  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 671  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 734  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 793  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& ProcNo,    calc_minGlobalDataPoint(int& ProcNo,  int& DataPointNo) const;
                         int& SampleNo,    
              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 880  class Data { Line 875  class Data {
875    
876    /**    /**
877       \brief       \brief
878         Return the error function erf of each data point of this Data object.
879         *
880      */
881      ESCRIPT_DLL_API
882      Data
883      erf() const;
884    
885      /**
886         \brief
887       Return the sin of each data point of this Data object.       Return the sin of each data point of this Data object.
888       *       *
889    */    */
# Line 1102  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 1279  class Data { Line 1286  class Data {
1286    ESCRIPT_DLL_API    ESCRIPT_DLL_API
1287      MPI_Comm      MPI_Comm
1288      get_MPIComm(void) const;      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    
1300   private:   private:
# Line 1337  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 1372  class Data { Line 1376  class Data {
1376               const FunctionSpace& what,               const FunctionSpace& what,
1377               bool expanded);               bool expanded);
1378    
   /**  
      \brief  
      Reshape the data point if the data point is currently rank 0.  
      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);  
   
1379    //    //
1380    // flag to protect the data object against any update    // flag to protect the data object against any update
1381    bool m_protected;    bool m_protected;
# Line 1390  class Data { Line 1384  class Data {
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 1421  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 1514  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 1522  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 1542  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 1596  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.804  
changed lines
  Added in v.1312

  ViewVC Help
Powered by ViewVC 1.1.26