/[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

trunk/esys2/escript/src/Data/Data.h revision 100 by jgs, Wed Dec 15 03:48:48 2004 UTC trunk/escript/src/Data.h revision 922 by gross, Fri Jan 5 04:23:05 2007 UTC
# Line 1  Line 1 
1  // $Id$  // $Id$
2  /*=============================================================================  /*
3     ************************************************************
4   ******************************************************************************   *          Copyright 2006 by ACcESS MNRF                   *
5   *                                                                            *   *                                                          *
6   *       COPYRIGHT ACcESS 2004 -  All Rights Reserved                         *   *              http://www.access.edu.au                    *
7   *                                                                            *   *       Primary Business: Queensland, Australia            *
8   * This software is the property of ACcESS.  No part of this code             *   *  Licensed under the Open Software License version 3.0    *
9   * may be copied in any form or by any means without the expressed written    *   *     http://www.opensource.org/licenses/osl-3.0.php       *
10   * consent of ACcESS.  Copying, use or modification of this software          *   *                                                          *
11   * by any unauthorised person is illegal unless that                          *   ************************************************************
12   * person has a software license agreement with ACcESS.                       *  */
  *                                                                            *  
  ******************************************************************************  
13    
14  ******************************************************************************/  /** \file Data.h */
15    
16  #ifndef DATA_H  #ifndef DATA_H
17  #define DATA_H  #define DATA_H
18    #include "system_dep.h"
19    
20  #include "escript/Data/DataAbstract.h"  #include "DataAbstract.h"
21  #include "escript/Data/DataTagged.h"  #include "DataAlgorithm.h"
22  #include "escript/Data/FunctionSpace.h"  #include "FunctionSpace.h"
23  #include "escript/Data/BinaryOp.h"  #include "BinaryOp.h"
24  #include "escript/Data/UnaryOp.h"  #include "UnaryOp.h"
25    #include "DataException.h"
26    
27  extern "C" {  extern "C" {
28  #include "escript/Data/DataC.h"  #include "DataC.h"
29    #include "paso/Paso.h"
30  }  }
31    
32  #include <iostream>  #ifndef PASO_MPI
33    #define MPI_Comm long
34    #endif
35    
36  #include <string>  #include <string>
 #include <memory>  
37  #include <algorithm>  #include <algorithm>
38    
39  #include <boost/shared_ptr.hpp>  #include <boost/shared_ptr.hpp>
40  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
 #include <boost/python/list.hpp>  
41  #include <boost/python/tuple.hpp>  #include <boost/python/tuple.hpp>
42  #include <boost/python/numeric.hpp>  #include <boost/python/numeric.hpp>
43    
44    namespace escript {
45    
46    //
47    // Forward declaration for various implementations of Data.
48    class DataConstant;
49    class DataTagged;
50    class DataExpanded;
51    
52  /**  /**
53     \brief     \brief
54     Data is essentially a factory class which creates the appropriate Data     Data creates the appropriate Data object for the given construction
55     object for the given construction arguments. It retains control over     arguments.
    the object created for the lifetime of the object.  
    The type of Data object referred to may change during the lifetime of  
    the Data object.  
56    
57     Description:     Description:
58     Data is essentially a factory class which creates the appropriate Data     Data is essentially a factory class which creates the appropriate Data
# Line 54  extern "C" { Line 61  extern "C" {
61     The type of Data object referred to may change during the lifetime of     The type of Data object referred to may change during the lifetime of
62     the Data object.     the Data object.
63  */  */
   
 namespace escript {  
   
 //  
 // Forward declaration for various implimentations of Data.  
 class DataEmpty;  
 class DataConstant;  
 class DataTagged;  
 class DataExpanded;  
   
64  class Data {  class Data {
65    
66    public:    public:
67    
68      // These typedefs allow function names to be cast to pointers
69      // to functions of the appropriate type when calling unaryOp etc.
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.
76      */
77    
78    /**    /**
79       \brief       \brief
80       Default constructor.       Default constructor.
81       Creates a DataEmpty object.       Creates a DataEmpty object.
82    */    */
83      ESCRIPT_DLL_API
84    Data();    Data();
85    
86    /**    /**
# Line 83  class Data { Line 88  class Data {
88       Copy constructor.       Copy constructor.
89       WARNING: Only performs a shallow copy.       WARNING: Only performs a shallow copy.
90    */    */
91      ESCRIPT_DLL_API
92    Data(const Data& inData);    Data(const Data& inData);
93    
94    /**    /**
95       \brief       \brief
96       Constructor from another Data object. If "what" is different from the       Constructor from another Data object. If "what" is different from the
97       function space of inData the inData are tried to be interpolated to what       function space of inData the inData are tried to be interpolated to what,
98       otherwise a shallow copy of inData is returned.       otherwise a shallow copy of inData is returned.
99    */    */
100      ESCRIPT_DLL_API
101    Data(const Data& inData,    Data(const Data& inData,
102         const FunctionSpace& what);         const FunctionSpace& what);
103    
# Line 104  class Data { Line 111  class Data {
111                         the value. Otherwise a more efficient storage                         the value. Otherwise a more efficient storage
112                         mechanism will be used.                         mechanism will be used.
113    */    */
114      ESCRIPT_DLL_API
115    Data(const DataArrayView& value,    Data(const DataArrayView& value,
116         const FunctionSpace& what=FunctionSpace(),         const FunctionSpace& what=FunctionSpace(),
117         bool expanded=false);         bool expanded=false);
# Line 119  class Data { Line 127  class Data {
127                         the given value. Otherwise a more efficient storage                         the given value. Otherwise a more efficient storage
128                         mechanism will be used.                         mechanism will be used.
129    */    */
130      ESCRIPT_DLL_API
131    Data(double value,    Data(double value,
132         const DataArrayView::ShapeType& dataPointShape=DataArrayView::ShapeType(),         const DataArrayView::ShapeType& dataPointShape=DataArrayView::ShapeType(),
133         const FunctionSpace& what=FunctionSpace(),         const FunctionSpace& what=FunctionSpace(),
# Line 131  class Data { Line 140  class Data {
140       \param inData - Input - Input Data object.       \param inData - Input - Input Data object.
141       \param region - Input - Region to copy.       \param region - Input - Region to copy.
142    */    */
143      ESCRIPT_DLL_API
144    Data(const Data& inData,    Data(const Data& inData,
145         const DataArrayView::RegionType& region);         const DataArrayView::RegionType& region);
146    
# Line 146  class Data { Line 156  class Data {
156       \param what - Input - A description of what this data represents.       \param what - Input - A description of what this data represents.
157       \param expanded - Input - Flag, if true fill the entire container with       \param expanded - Input - Flag, if true fill the entire container with
158                         the appropriate values.                         the appropriate values.
159        ==>*
160    */    */
161      ESCRIPT_DLL_API
162    Data(const DataTagged::TagListType& tagKeys,    Data(const DataTagged::TagListType& tagKeys,
163         const DataTagged::ValueListType& values,         const DataTagged::ValueListType& values,
164         const DataArrayView& defaultValue,         const DataArrayView& defaultValue,
# Line 163  class Data { Line 175  class Data {
175                         the value. Otherwise a more efficient storage                         the value. Otherwise a more efficient storage
176                         mechanism will be used.                         mechanism will be used.
177    */    */
178      ESCRIPT_DLL_API
179    Data(const boost::python::numeric::array& value,    Data(const boost::python::numeric::array& value,
180         const FunctionSpace& what=FunctionSpace(),         const FunctionSpace& what=FunctionSpace(),
181         bool expanded=false);         bool expanded=false);
# Line 178  class Data { Line 191  class Data {
191                         the value. Otherwise a more efficient storage                         the value. Otherwise a more efficient storage
192                         mechanism will be used.                         mechanism will be used.
193    */    */
194      ESCRIPT_DLL_API
195    Data(const boost::python::object& value,    Data(const boost::python::object& value,
196         const FunctionSpace& what=FunctionSpace(),         const FunctionSpace& what=FunctionSpace(),
197         bool expanded=false);         bool expanded=false);
# Line 191  class Data { Line 205  class Data {
205       \param value - Input - Input data.       \param value - Input - Input data.
206       \param other - Input - contains all other parameters.       \param other - Input - contains all other parameters.
207    */    */
208      ESCRIPT_DLL_API
209    Data(const boost::python::object& value,    Data(const boost::python::object& value,
210         const Data& other);         const Data& other);
211    
# Line 198  class Data { Line 213  class Data {
213       \brief       \brief
214       Constructor which creates a DataConstant of "shape" with constant value.       Constructor which creates a DataConstant of "shape" with constant value.
215    */    */
216      ESCRIPT_DLL_API
217    Data(double value,    Data(double value,
218         const boost::python::tuple& shape=boost::python::make_tuple(),         const boost::python::tuple& shape=boost::python::make_tuple(),
219         const FunctionSpace& what=FunctionSpace(),         const FunctionSpace& what=FunctionSpace(),
220         bool expanded=false);         bool expanded=false);
   
221    /**    /**
222       \brief       \brief
223       Perform the specified algorithm on the Data and return result.       Destructor
224    */    */
225    template <class UnaryFunction>    ESCRIPT_DLL_API
226    inline double    ~Data();
   algorithm(UnaryFunction operation) const;  
227    
228    /**    /**
229       \brief       \brief
230       Perform the given unary operation on all of the data's elements.       Perform a deep copy.
231    */    */
232    template <class UnaryFunction>    ESCRIPT_DLL_API
233    void    void
234    unaryOp(UnaryFunction operation);    copy(const Data& other);
235    
236      /**
237         Member access methods.
238      */
239    
240    /**    /**
241       \brief       \brief
242       Perform the given binary operation on all of the data's elements.       switches on update protection
243       The underlying type of the right hand side (right) determines the final  
      type of *this after the operation. For example if the right hand side  
      is expanded *this will be expanded if necessary.  
244    */    */
245    template <class BinaryFunction>    ESCRIPT_DLL_API
246    void    void
247    binaryOp(const Data& right,    setProtection();
            BinaryFunction operation);  
248    
249    /**    /**
250       \brief       \brief
251       Perform the given binary operation on all of the data's elements.       Returns trueif the data object is protected against update
252    
253    */    */
254    template <class BinaryFunction>    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.
260      */
261      ESCRIPT_DLL_API
262      const boost::python::numeric::array
263      convertToNumArray();
264    
265      /**
266         \brief
267         Fills the expanded Data object from values of a python numarray object.
268      */
269      ESCRIPT_DLL_API
270    void    void
271    binaryOp(const boost::python::object& right,    fillFromNumArray(const boost::python::numeric::array);
            BinaryFunction operation);  
272    
273    /**    /**
274       \brief       \brief
275       Overloaded operator +=       Return the values of a data point on this process
      \param right - Input - The right hand side.  
276    */    */
277    Data& operator+=(const Data& right);    ESCRIPT_DLL_API
278    Data& operator+=(const boost::python::object& right);    const boost::python::numeric::array
279      getValueOfDataPoint(int dataPointNo);
280    
281    /**    /**
282       \brief       \brief
283       Overloaded operator -=       sets the values of a data-point on this process
      \param right - Input - The right hand side.  
284    */    */
285    Data& operator-=(const Data& right);    ESCRIPT_DLL_API
286    Data& operator-=(const boost::python::object& right);    void
287      setValueOfDataPointToArray(int dataPointNo, const boost::python::numeric::array);
288    
289   /**    /**
290       \brief       \brief
291       Overloaded operator *=       sets the values of a data-point on this process
      \param right - Input - The right hand side.  
292    */    */
293    Data& operator*=(const Data& right);    ESCRIPT_DLL_API
294    Data& operator*=(const boost::python::object& right);    void
295      setValueOfDataPoint(int dataPointNo, const double);
296    
297   /**    /**
298       \brief       \brief
299       Overloaded operator /=       Return the value of the specified data-point across all processors
      \param right - Input - The right hand side.  
300    */    */
301    Data& operator/=(const Data& right);    ESCRIPT_DLL_API
302    Data& operator/=(const boost::python::object& right);    const boost::python::numeric::array
303      getValueOfGlobalDataPoint(int procNo, int dataPointNo);
304    
305    /**    /**
306       \brief       \brief
307       Return the power of Data.       Return the tag number associated with the given data-point.
308    
309         The data-point number here corresponds to the data-point number in the
310         numarray returned by convertToNumArray.
311    */    */
312    Data powD(const Data& right) const;    ESCRIPT_DLL_API
313    Data powO(const boost::python::object& right) const;    int
314      getTagNumber(int dpno);
315    
316    /**    /**
317       \brief       \brief
318       Return the C wrapper for the Data object.       Return the C wrapper for the Data object.
319    */    */
320    escriptDataC getDataC();    ESCRIPT_DLL_API
321      escriptDataC
322      getDataC();
323    
324    /**    /**
325       \brief       \brief
326       Return the C wrapper for the Data object - const version.       Return the C wrapper for the Data object - const version.
327    */    */
328    escriptDataC getDataC() const;    ESCRIPT_DLL_API
329      escriptDataC
330      getDataC() const;
331    
332    /**    /**
333       \brief       \brief
334       Write the data as a string.       Write the data as a string.
335    */    */
336    std::string toString() const;    ESCRIPT_DLL_API
337      inline
338      std::string
339      toString() const
340      {
341        return m_data->toString();
342      }
343    
344    /**    /**
345       \brief       \brief
# Line 303  class Data { Line 347  class Data {
347       the shape information for each data point although it also may be used       the shape information for each data point although it also may be used
348       to manipulate the point data.       to manipulate the point data.
349    */    */
350      ESCRIPT_DLL_API
351    inline    inline
352    const DataArrayView&    const DataArrayView&
353    getPointDataView() const    getPointDataView() const
# Line 312  class Data { Line 357  class Data {
357    
358    /**    /**
359       \brief       \brief
360       Perform a deep copy.       Whatever the current Data type make this into a DataExpanded.
   */  
   void  
   copy(const Data& other);  
   
   /**  
     \brief  
     Copy other Data object into this Data object where mask is positive.  
   */  
   void  
   copyWithMask(const Data& other,  
                const Data& mask);  
   
   /**  
      \brief  
      Whatever the current Data type make it expanded.  
361    */    */
362      ESCRIPT_DLL_API
363    void    void
364    expand();    expand();
365    
366    /**    /**
367       \brief       \brief
368       If possible convert the Data type to tagged. This will only allow       If possible convert this Data to DataTagged. This will only allow
369       Constant data to be converted to tagged. An attempt to convert       Constant data to be converted to tagged. An attempt to convert
370       Expanded data to tagged will throw an exception.       Expanded data to tagged will throw an exception.
371        ==>*
372    */    */
373      ESCRIPT_DLL_API
374    void    void
375    tag();    tag();
376    
# Line 345  class Data { Line 378  class Data {
378       \brief       \brief
379       Return true if this Data is expanded.       Return true if this Data is expanded.
380    */    */
381      ESCRIPT_DLL_API
382    bool    bool
383    isExpanded() const;    isExpanded() const;
384    
# Line 352  class Data { Line 386  class Data {
386       \brief       \brief
387       Return true if this Data is tagged.       Return true if this Data is tagged.
388    */    */
389      ESCRIPT_DLL_API
390    bool    bool
391    isTagged() const;    isTagged() const;
392    
393    /**    /**
394       \brief       \brief
395       Return true if this Data is empty.       Return true if this Data is constant.
396    */    */
397      ESCRIPT_DLL_API
398    bool    bool
399    isEmpty() const;    isConstant() const;
400    
401    /**    /**
402       \brief       \brief
403       Return true if this Data is constant.       Return true if this Data is empty.
404    */    */
405      ESCRIPT_DLL_API
406    bool    bool
407    isConstant() const;    isEmpty() const;
408    
409    /**    /**
410       \brief       \brief
411       Return the function space.       Return the function space.
412    */    */
413      ESCRIPT_DLL_API
414    inline    inline
415    const FunctionSpace&    const FunctionSpace&
416    getFunctionSpace() const    getFunctionSpace() const
# Line 384  class Data { Line 422  class Data {
422       \brief       \brief
423       Return a copy of the function space.       Return a copy of the function space.
424    */    */
425      ESCRIPT_DLL_API
426    const FunctionSpace    const FunctionSpace
427    getCopyOfFunctionSpace() const;    getCopyOfFunctionSpace() const;
428    
# Line 391  class Data { Line 430  class Data {
430       \brief       \brief
431       Return the domain.       Return the domain.
432    */    */
433      ESCRIPT_DLL_API
434    inline    inline
435    const AbstractDomain&    const AbstractDomain&
436    getDomain() const    getDomain() const
# Line 402  class Data { Line 442  class Data {
442       \brief       \brief
443       Return a copy of the domain.       Return a copy of the domain.
444    */    */
445      ESCRIPT_DLL_API
446    const AbstractDomain    const AbstractDomain
447    getCopyOfDomain() const;    getCopyOfDomain() const;
448    
# Line 409  class Data { Line 450  class Data {
450       \brief       \brief
451       Return the rank of the point data.       Return the rank of the point data.
452    */    */
453      ESCRIPT_DLL_API
454    inline    inline
455    int    int
456    getDataPointRank() const    getDataPointRank() const
# Line 418  class Data { Line 460  class Data {
460    
461    /**    /**
462       \brief       \brief
463       Return the number of data points per sample.       Return the number of data points
464    */    */
465      ESCRIPT_DLL_API
466    inline    inline
467    int    int
468    getNumDataPointsPerSample() const    getNumDataPoints() const
469    {    {
470      return m_data->getNumDPPSample();      return getNumSamples() * getNumDataPointsPerSample();
471    }    }
   
472    /**    /**
473       \brief       \brief
474       Return the number of samples.       Return the number of samples.
475    */    */
476      ESCRIPT_DLL_API
477      inline
478    int    int
479    getNumSamples() const;    getNumSamples() const
480      {
481        return m_data->getNumSamples();
482      }
483    
484    /**    /**
485       \brief       \brief
486       Check *this and the right operand are compatible. Throws       Return the number of data points per sample.
      an exception if they aren't.  
      \param right - Input - The right hand side.  
487    */    */
488    void    ESCRIPT_DLL_API
489    operandCheck(const Data& right) const;    inline
490      int
491      getNumDataPointsPerSample() const
492      {
493        return m_data->getNumDPPSample();
494      }
495    
496    /**    /**
497       \brief       \brief
# Line 449  class Data { Line 499  class Data {
499       preferred interface but is provided for use by C code.       preferred interface but is provided for use by C code.
500       \param sampleNo - Input - the given sample no.       \param sampleNo - Input - the given sample no.
501    */    */
502      ESCRIPT_DLL_API
503      inline
504    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
505    getSampleData(DataAbstract::ShapeType::size_type sampleNo);    getSampleData(DataAbstract::ValueType::size_type sampleNo)
506      {
507        return m_data->getSampleData(sampleNo);
508      }
509    
510    /**    /**
511       \brief       \brief
# Line 458  class Data { Line 513  class Data {
513       access data that isn't tagged an exception will be thrown.       access data that isn't tagged an exception will be thrown.
514       \param tag - Input - the tag key.       \param tag - Input - the tag key.
515    */    */
516      ESCRIPT_DLL_API
517      inline
518    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
519    getSampleDataByTag(int tag);    getSampleDataByTag(int tag)
520      {
521        return m_data->getSampleDataByTag(tag);
522      }
523    
524      /**
525         \brief
526         Assign the given value to the data-points referenced by the given
527         reference number.
528    
529         The value supplied is a python numarray object.  The data from this numarray
530         is unpacked into a DataArray, and this is used to set the corresponding
531         data-points in the underlying Data object.
532    
533         If the underlying Data object cannot be accessed via reference numbers, an
534         exception will be thrown.
535    
536         \param ref - Input - reference number.
537         \param value - Input - value to assign to data-points associated with
538                                the given reference number.
539      */
540      ESCRIPT_DLL_API
541      void
542      setRefValue(int ref,
543                  const boost::python::numeric::array& value);
544    
545      /**
546         \brief
547         Return the values associated with the data-points referenced by the given
548         reference number.
549    
550         The value supplied is a python numarray object. The data from the corresponding
551         data-points in this Data object are packed into the given numarray object.
552    
553         If the underlying Data object cannot be accessed via reference numbers, an
554         exception will be thrown.
555    
556         \param ref - Input - reference number.
557         \param value - Output - object to receive values from data-points
558                                 associated with the given reference number.
559      */
560      ESCRIPT_DLL_API
561      void
562      getRefValue(int ref,
563                  boost::python::numeric::array& value);
564    
565    /**    /**
566       \brief       \brief
# Line 469  class Data { Line 570  class Data {
570       \param sampleNo - Input -       \param sampleNo - Input -
571       \param dataPointNo - Input -       \param dataPointNo - Input -
572    */    */
573      ESCRIPT_DLL_API
574    inline    inline
575    DataArrayView    DataArrayView
576    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
577                 int dataPointNo)                 int dataPointNo)
578    {    {
579      return m_data->getDataPoint(sampleNo,dataPointNo);          return m_data->getDataPoint(sampleNo,dataPointNo);
580    }    }
581    
582    /**    /**
583       \brief       \brief
584       Return a reference to the data point shape.       Return a reference to the data point shape.
585    */    */
586      ESCRIPT_DLL_API
587    const DataArrayView::ShapeType&    const DataArrayView::ShapeType&
588    getDataPointShape() const;    getDataPointShape() const;
589    
590    /**    /**
591       \brief       \brief
592       Return data point shape as a tuple of integers:       Return the data point shape as a tuple of integers.
593    */    */
594    boost::python::tuple    ESCRIPT_DLL_API
595      const boost::python::tuple
596    getShapeTuple() const;    getShapeTuple() const;
597    
598    /**    /**
# Line 496  class Data { Line 600  class Data {
600       Return the size of the data point. It is the product of the       Return the size of the data point. It is the product of the
601       data point shape dimensions.       data point shape dimensions.
602    */    */
603      ESCRIPT_DLL_API
604    int    int
605    getDataPointSize() const;    getDataPointSize() const;
606    
607    /**    /**
608       \brief       \brief
609       Return the number of doubles stored for Data.       Return the number of doubles stored for this Data.
610    */    */
611      ESCRIPT_DLL_API
612    DataArrayView::ValueType::size_type    DataArrayView::ValueType::size_type
613    getLength() const;    getLength() const;
614    
615    /**    /**
616       \brief       \brief
617       Interpolates this onto the given functionspace and returns the result as a Data object.       Assign the given value to the tag. Implicitly converts this
618         object to type DataTagged. Throws an exception if this object
619         cannot be converted to a DataTagged object.
620         \param tagKey - Input - Integer key.
621         \param value - Input - Value to associate with given key.
622        ==>*
623      */
624      ESCRIPT_DLL_API
625      void
626      setTaggedValue(int tagKey,
627                     const boost::python::object& value);
628    
629      /**
630         \brief
631         Assign the given value to the tag. Implicitly converts this
632         object to type DataTagged. Throws an exception if this object
633         cannot be converted to a DataTagged object.
634         \param tagKey - Input - Integer key.
635         \param value - Input - Value to associate with given key.
636        ==>*
637      */
638      ESCRIPT_DLL_API
639      void
640      setTaggedValueFromCPP(int tagKey,
641                            const DataArrayView& value);
642    
643      /**
644        \brief
645        Copy other Data object into this Data object where mask is positive.
646    */    */
647      ESCRIPT_DLL_API
648      void
649      copyWithMask(const Data& other,
650                   const Data& mask);
651    
652      /**
653         Data object operation methods and operators.
654      */
655    
656      /**
657         \brief
658         Interpolates this onto the given functionspace and returns
659         the result as a Data object.
660         *
661      */
662      ESCRIPT_DLL_API
663    Data    Data
664    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
665    
# Line 517  class Data { Line 667  class Data {
667       \brief       \brief
668       Calculates the gradient of the data at the data points of functionspace.       Calculates the gradient of the data at the data points of functionspace.
669       If functionspace is not present the function space of Function(getDomain()) is used.       If functionspace is not present the function space of Function(getDomain()) is used.
670         *
671    */    */
672      ESCRIPT_DLL_API
673    Data    Data
674    gradOn(const FunctionSpace& functionspace) const;    gradOn(const FunctionSpace& functionspace) const;
675    
676      ESCRIPT_DLL_API
677    Data    Data
678    grad() const;    grad() const;
679    
680    /**    /**
681       \brief       \brief
682       Calculate the integral over the function space domain.       Calculate the integral over the function space domain.
683         *
684    */    */
685      ESCRIPT_DLL_API
686    boost::python::numeric::array    boost::python::numeric::array
687    integrate() const;    integrate() const;
688    
689    /**    /**
690       \brief       \brief
691         Returns 1./ Data object
692         *
693      */
694      ESCRIPT_DLL_API
695      Data
696      oneOver() const;
697      /**
698         \brief
699       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.
700         *
701    */    */
702      ESCRIPT_DLL_API
703    Data    Data
704    wherePositive() const;    wherePositive() const;
705    
706    /**    /**
707       \brief       \brief
708       Return a Data with a 1 for +ive values and a 0 for -ive values.       Return a Data with a 1 for -ive values and a 0 for +ive or 0 values.
709         *
710    */    */
711      ESCRIPT_DLL_API
712      Data
713      whereNegative() const;
714    
715      /**
716         \brief
717         Return a Data with a 1 for +ive or 0 values and a 0 for -ive values.
718         *
719      */
720      ESCRIPT_DLL_API
721    Data    Data
722    whereNonNegative() const;    whereNonNegative() const;
723    
724    /**    /**
725       \brief       \brief
726       Return a Data with a 1 for -ive values and a 0 for +ive or 0 values.       Return a Data with a 1 for -ive or 0 values and a 0 for +ive values.
727         *
728    */    */
729      ESCRIPT_DLL_API
730    Data    Data
731    whereNegative() const;    whereNonPositive() const;
732    
733      /**
734         \brief
735         Return a Data with a 1 for 0 values and a 0 for +ive or -ive values.
736         *
737      */
738      ESCRIPT_DLL_API
739      Data
740      whereZero(double tol=0.0) const;
741    
742      /**
743         \brief
744         Return a Data with a 0 for 0 values and a 1 for +ive or -ive values.
745         *
746      */
747      ESCRIPT_DLL_API
748      Data
749      whereNonZero(double tol=0.0) const;
750    
751      /**
752         \brief
753         Return the maximum absolute value of this Data object.
754         *
755      */
756      ESCRIPT_DLL_API
757      double
758      Lsup() const;
759    
760      /**
761         \brief
762         Return the minimum absolute value of this Data object.
763         *
764      */
765      ESCRIPT_DLL_API
766      double
767      Linf() const;
768    
769      /**
770         \brief
771         Return the maximum value of this Data object.
772         *
773      */
774      ESCRIPT_DLL_API
775      double
776      sup() const;
777    
778    /**    /**
779       \brief       \brief
780       Return a Data with a 1 for 0 values a 0 for +ive or -ive.       Return the minimum value of this Data object.
781         *
782    */    */
783      ESCRIPT_DLL_API
784      double
785      inf() const;
786    
787      /**
788         \brief
789         Return the absolute value of each data point of this Data object.
790         *
791      */
792      ESCRIPT_DLL_API
793    Data    Data
794    whereZero() const;    abs() const;
795    
796    /**    /**
797       \brief       \brief
798       Return the sin of Data.       Return the maximum value of each data point of this Data object.
799         *
800    */    */
801      ESCRIPT_DLL_API
802      Data
803      maxval() const;
804    
805      /**
806         \brief
807         Return the minimum value of each data point of this Data object.
808         *
809      */
810      ESCRIPT_DLL_API
811      Data
812      minval() const;
813    
814      /**
815         \brief
816         Return the (sample number, data-point number) of the data point with
817         the minimum value in this Data object.
818      */
819      ESCRIPT_DLL_API
820      const boost::python::tuple
821      minGlobalDataPoint() const;
822    
823      ESCRIPT_DLL_API
824      void
825      calc_minGlobalDataPoint(int& ProcNo,  int& DataPointNo) const;
826      /**
827         \brief
828         Return the sign of each data point of this Data object.
829         -1 for negative values, zero for zero values, 1 for positive values.
830         *
831      */
832      ESCRIPT_DLL_API
833      Data
834      sign() const;
835    
836      /**
837         \brief
838         Return the symmetric part of a matrix which is half the matrix plus its transpose.
839         *
840      */
841      ESCRIPT_DLL_API
842      Data
843      symmetric() const;
844    
845      /**
846         \brief
847         Return the nonsymmetric part of a matrix which is half the matrix minus its transpose.
848         *
849      */
850      ESCRIPT_DLL_API
851      Data
852      nonsymmetric() const;
853    
854      /**
855         \brief
856         Return the trace of a matrix
857         *
858      */
859      ESCRIPT_DLL_API
860      Data
861      trace(int axis_offset) const;
862    
863      /**
864         \brief
865         Transpose each data point of this Data object around the given axis.
866         *
867      */
868      ESCRIPT_DLL_API
869      Data
870      transpose(int axis_offset) const;
871    
872      /**
873         \brief
874         Return the eigenvalues of the symmetric part at each data point of this Data object in increasing values.
875         Currently this function is restricted to rank 2, square shape, and dimension 3.
876         *
877      */
878      ESCRIPT_DLL_API
879      Data
880      eigenvalues() const;
881    
882      /**
883         \brief
884         Return the eigenvalues and corresponding eigenvcetors of the symmetric part at each data point of this Data object.
885         the eigenvalues are ordered in increasing size where eigenvalues with relative difference less than
886         tol are treated as equal. The eigenvectors are orthogonal, normalized and the sclaed such that the
887         first non-zero entry is positive.
888         Currently this function is restricted to rank 2, square shape, and dimension 3
889         *
890      */
891      ESCRIPT_DLL_API
892      const boost::python::tuple
893      eigenvalues_and_eigenvectors(const double tol=1.e-12) const;
894    
895      /**
896         \brief
897         swaps the components axis0 and axis1
898         *
899      */
900      ESCRIPT_DLL_API
901      Data
902      swapaxes(const int axis0, const int axis1) const;
903    
904      /**
905         \brief
906         Return the error function erf of each data point of this Data object.
907         *
908      */
909      ESCRIPT_DLL_API
910      Data
911      erf() const;
912    
913      /**
914         \brief
915         Return the sin of each data point of this Data object.
916         *
917      */
918      ESCRIPT_DLL_API
919    Data    Data
920    sin() const;    sin() const;
921    
922    /**    /**
923       \brief       \brief
924       Return the cos of Data.       Return the cos of each data point of this Data object.
925         *
926    */    */
927      ESCRIPT_DLL_API
928    Data    Data
929    cos() const;    cos() const;
930    
931    /**    /**
932       \brief       \brief
933       Return the tan of Data.       Return the tan of each data point of this Data object.
934         *
935    */    */
936      ESCRIPT_DLL_API
937    Data    Data
938    tan() const;    tan() const;
939    
940    /**    /**
941       \brief       \brief
942       Return the log to base 10 of Data.       Return the asin of each data point of this Data object.
943         *
944    */    */
945      ESCRIPT_DLL_API
946    Data    Data
947    log() const;    asin() const;
948    
949    /**    /**
950       \brief       \brief
951       Return the natural log of Data.       Return the acos of each data point of this Data object.
952         *
953    */    */
954      ESCRIPT_DLL_API
955    Data    Data
956    ln() const;    acos() const;
957    
958    /**    /**
959       \brief       \brief
960       Return a Data containing a slice of this Data.       Return the atan of each data point of this Data object.
961         *
962    */    */
963      ESCRIPT_DLL_API
964    Data    Data
965    getSlice(const DataArrayView::RegionType& region) const;    atan() const;
966    
967    /**    /**
968       \brief       \brief
969       Copy the specified region from the given value.       Return the sinh of each data point of this Data object.
970       \param value - Input - Data to copy from.       *
      \param region - Input - Region to copy.  
971    */    */
972    void    ESCRIPT_DLL_API
973    setSlice(const Data& value,    Data
974             const DataArrayView::RegionType& region);    sinh() const;
975    
976    /**    /**
977       \brief       \brief
978       Return the maximum absolute value.       Return the cosh of each data point of this Data object.
979         *
980    */    */
981    double    ESCRIPT_DLL_API
982    Lsup() const;    Data
983      cosh() const;
984    
985    /**    /**
986       \brief       \brief
987       Return the maximum value.       Return the tanh of each data point of this Data object.
988         *
989    */    */
990    double    ESCRIPT_DLL_API
991    sup() const;    Data
992      tanh() const;
993    
994    /**    /**
995       \brief       \brief
996       Return the minimum value.       Return the asinh of each data point of this Data object.
997         *
998    */    */
999    double    ESCRIPT_DLL_API
1000    inf() const;    Data
1001      asinh() const;
1002    
1003    /**    /**
1004       \brief       \brief
1005       Returns a slice from this.       Return the acosh of each data point of this Data object.
1006         *
1007    */    */
1008      ESCRIPT_DLL_API
1009    Data    Data
1010    getItem(const boost::python::object& key) const;    acosh() const;
1011    
1012      /**
1013         \brief
1014         Return the atanh of each data point of this Data object.
1015         *
1016      */
1017      ESCRIPT_DLL_API
1018      Data
1019      atanh() const;
1020    
1021      /**
1022         \brief
1023         Return the log to base 10 of each data point of this Data object.
1024         *
1025      */
1026      ESCRIPT_DLL_API
1027      Data
1028      log10() const;
1029    
1030      /**
1031         \brief
1032         Return the natural log of each data point of this Data object.
1033         *
1034      */
1035      ESCRIPT_DLL_API
1036      Data
1037      log() const;
1038    
1039      /**
1040         \brief
1041         Return the exponential function of each data point of this Data object.
1042         *
1043      */
1044      ESCRIPT_DLL_API
1045      Data
1046      exp() const;
1047    
1048    /**    /**
1049       \brief       \brief
1050       Copies slice from value into this.       Return the square root of each data point of this Data object.
1051         *
1052    */    */
1053      ESCRIPT_DLL_API
1054      Data
1055      sqrt() const;
1056    
1057      /**
1058         \brief
1059         Return the negation of each data point of this Data object.
1060         *
1061      */
1062      ESCRIPT_DLL_API
1063      Data
1064      neg() const;
1065    
1066      /**
1067         \brief
1068         Return the identity of each data point of this Data object.
1069         Simply returns this object unmodified.
1070         *
1071      */
1072      ESCRIPT_DLL_API
1073      Data
1074      pos() const;
1075    
1076      /**
1077         \brief
1078         Return the given power of each data point of this Data object.
1079    
1080         \param right Input - the power to raise the object to.
1081         *
1082      */
1083      ESCRIPT_DLL_API
1084      Data
1085      powD(const Data& right) const;
1086    
1087      /**
1088         \brief
1089         Return the given power of each data point of this boost python object.
1090        
1091         \param right Input - the power to raise the object to.
1092         *
1093       */
1094      ESCRIPT_DLL_API
1095      Data
1096      powO(const boost::python::object& right) const;
1097    
1098      /**
1099         \brief
1100         Return the given power of each data point of this boost python object.
1101        
1102         \param left Input - the bases
1103         *
1104       */
1105    
1106      ESCRIPT_DLL_API
1107      Data
1108      rpowO(const boost::python::object& left) const;
1109    
1110      /**
1111         \brief
1112         writes the object to a file in the DX file format
1113      */
1114      ESCRIPT_DLL_API
1115    void    void
1116    setItem(const boost::python::object& key,    saveDX(std::string fileName) const;
           const Data& value);  
1117    
1118    /**    /**
1119       \brief       \brief
1120       Convert the underlying data type to match the RHS.       writes the object to a file in the VTK file format
      \param right - Input - data type to match.  
1121    */    */
1122      ESCRIPT_DLL_API
1123    void    void
1124    typeMatch(const Data& right);    saveVTK(std::string fileName) const;
1125    
1126      /**
1127         \brief
1128         Overloaded operator +=
1129         \param right - Input - The right hand side.
1130         *
1131      */
1132      ESCRIPT_DLL_API
1133      Data& operator+=(const Data& right);
1134      ESCRIPT_DLL_API
1135      Data& operator+=(const boost::python::object& right);
1136    
1137      /**
1138         \brief
1139         Overloaded operator -=
1140         \param right - Input - The right hand side.
1141         *
1142      */
1143      ESCRIPT_DLL_API
1144      Data& operator-=(const Data& right);
1145      ESCRIPT_DLL_API
1146      Data& operator-=(const boost::python::object& right);
1147    
1148     /**
1149         \brief
1150         Overloaded operator *=
1151         \param right - Input - The right hand side.
1152         *
1153      */
1154      ESCRIPT_DLL_API
1155      Data& operator*=(const Data& right);
1156      ESCRIPT_DLL_API
1157      Data& operator*=(const boost::python::object& right);
1158    
1159     /**
1160         \brief
1161         Overloaded operator /=
1162         \param right - Input - The right hand side.
1163         *
1164      */
1165      ESCRIPT_DLL_API
1166      Data& operator/=(const Data& right);
1167      ESCRIPT_DLL_API
1168      Data& operator/=(const boost::python::object& right);
1169    
1170    /**    /**
1171       \brief       \brief
1172       Returns true if this can be interpolated to functionspace.       Returns true if this can be interpolated to functionspace.
1173    */    */
1174      ESCRIPT_DLL_API
1175    bool    bool
1176    probeInterpolation(const FunctionSpace& functionspace) const;    probeInterpolation(const FunctionSpace& functionspace) const;
1177    
1178    /**    /**
1179         Data object slicing methods.
1180      */
1181    
1182      /**
1183       \brief       \brief
1184       Assign the given value to the tag. Implicitly converts this       Returns a slice from this Data object.
1185       object to type DataTagged. Throws an exception if this object  
1186       cannot be converted to a DataTagged object.       /description
1187       \param tagKey - Input - Integer key.       Implements the [] get operator in python.
1188       \param value - Input - Value to associate with given key.       Calls getSlice.
1189    
1190         \param key - Input - python slice tuple specifying
1191         slice to return.
1192      */
1193      ESCRIPT_DLL_API
1194      Data
1195      getItem(const boost::python::object& key) const;
1196    
1197      /**
1198         \brief
1199         Copies slice from value into this Data object.
1200    
1201         Implements the [] set operator in python.
1202         Calls setSlice.
1203    
1204         \param key - Input - python slice tuple specifying
1205         slice to copy from value.
1206         \param value - Input - Data object to copy from.
1207    */    */
1208      ESCRIPT_DLL_API
1209    void    void
1210    setTaggedValue(int tagKey,    setItemD(const boost::python::object& key,
1211                   const boost::python::object& value);             const Data& value);
1212    
1213      ESCRIPT_DLL_API
1214      void
1215      setItemO(const boost::python::object& key,
1216               const boost::python::object& value);
1217    
1218      // These following public methods should be treated as private.
1219    
1220    /**    /**
1221       \brief       \brief
1222       Assign the given value to the tag. Implicitly converts this       Perform the given unary operation on every element of every data point in
1223       object to type DataTagged. Throws an exception if this object       this Data object.
      cannot be converted to a DataTagged object.  
      \param tagKey - Input - Integer key.  
      \param value - Input - Value to associate with given key.  
      Note: removed for now - this version not needed, and breaks escript.cpp  
1224    */    */
1225    /*    template <class UnaryFunction>
1226      ESCRIPT_DLL_API
1227      inline
1228    void    void
1229    setTaggedValue(int tagKey,    unaryOp(UnaryFunction operation);
1230                   const DataArrayView& value);  
1231      /**
1232         \brief
1233         Return a Data object containing the specified slice of
1234         this Data object.
1235         \param region - Input - Region to copy.
1236         *
1237      */
1238      ESCRIPT_DLL_API
1239      Data
1240      getSlice(const DataArrayView::RegionType& region) const;
1241    
1242      /**
1243         \brief
1244         Copy the specified slice from the given value into this
1245         Data object.
1246         \param value - Input - Data to copy from.
1247         \param region - Input - Region to copy.
1248         *
1249      */
1250      ESCRIPT_DLL_API
1251      void
1252      setSlice(const Data& value,
1253               const DataArrayView::RegionType& region);
1254    
1255      /**
1256         \brief
1257         Archive the current Data object to the given file.
1258         \param fileName - Input - file to archive to.
1259      */
1260      ESCRIPT_DLL_API
1261      void
1262      archiveData(const std::string fileName);
1263    
1264      /**
1265         \brief
1266         Extract the Data object archived in the given file, overwriting
1267         the current Data object.
1268         Note - the current object must be of type DataEmpty.
1269         \param fileName - Input - file to extract from.
1270         \param fspace - Input - a suitable FunctionSpace descibing the data.
1271      */
1272      ESCRIPT_DLL_API
1273      void
1274      extractData(const std::string fileName,
1275                  const FunctionSpace& fspace);
1276    
1277    
1278      /**
1279         \brief
1280         print the data values to stdout. Used for debugging
1281      */
1282      ESCRIPT_DLL_API
1283      void
1284        print(void);
1285    
1286      /**
1287         \brief
1288         return the MPI rank number of the local data
1289             MPI_COMM_WORLD is assumed and the result of MPI_Comm_size()
1290             is returned
1291      */
1292      ESCRIPT_DLL_API
1293        int
1294        get_MPIRank(void) const;
1295    
1296      /**
1297         \brief
1298         return the MPI rank number of the local data
1299             MPI_COMM_WORLD is assumed and the result of MPI_Comm_rank()
1300             is returned
1301      */
1302      ESCRIPT_DLL_API
1303        int
1304        get_MPISize(void) const;
1305    
1306      /**
1307         \brief
1308         return the MPI rank number of the local data
1309             MPI_COMM_WORLD is assumed and returned.
1310      */
1311      ESCRIPT_DLL_API
1312        MPI_Comm
1313        get_MPIComm(void) const;
1314    
1315      /**
1316         \brief
1317         return the object produced by the factory, which is a DataConstant or DataExpanded
1318    */    */
1319      ESCRIPT_DLL_API
1320        DataAbstract*
1321        borrowData(void) const;
1322    
1323     protected:
1324    
1325   private:   private:
1326    
1327    /**    /**
1328       \brief       \brief
1329         Check *this and the right operand are compatible. Throws
1330         an exception if they aren't.
1331         \param right - Input - The right hand side.
1332      */
1333      inline
1334      void
1335      operandCheck(const Data& right) const
1336      {
1337        return m_data->operandCheck(*(right.m_data.get()));
1338      }
1339    
1340      /**
1341         \brief
1342         Perform the specified reduction algorithm on every element of every data point in
1343         this Data object according to the given function and return the single value result.
1344      */
1345      template <class BinaryFunction>
1346      inline
1347      double
1348      algorithm(BinaryFunction operation,
1349                double initial_value) const;
1350    
1351      /**
1352         \brief
1353         Reduce each data-point in this Data object using the given operation. Return a Data
1354         object with the same number of data-points, but with each data-point containing only
1355         one value - the result of the reduction operation on the corresponding data-point in
1356         this Data object
1357      */
1358      template <class BinaryFunction>
1359      inline
1360      Data
1361      dp_algorithm(BinaryFunction operation,
1362                   double initial_value) const;
1363    
1364      /**
1365         \brief
1366         Perform the given binary operation on all of the data's elements.
1367         The underlying type of the right hand side (right) determines the final
1368         type of *this after the operation. For example if the right hand side
1369         is expanded *this will be expanded if necessary.
1370         RHS is a Data object.
1371      */
1372      template <class BinaryFunction>
1373      inline
1374      void
1375      binaryOp(const Data& right,
1376               BinaryFunction operation);
1377    
1378      /**
1379         \brief
1380         Convert the data type of the RHS to match this.
1381         \param right - Input - data type to match.
1382      */
1383      void
1384      typeMatchLeft(Data& right) const;
1385    
1386      /**
1387         \brief
1388         Convert the data type of this to match the RHS.
1389         \param right - Input - data type to match.
1390      */
1391      void
1392      typeMatchRight(const Data& right);
1393    
1394      /**
1395         \brief
1396       Construct a Data object of the appropriate type.       Construct a Data object of the appropriate type.
1397    */    */
1398    template <class IValueType>    template <class IValueType>
# Line 701  class Data { Line 1401  class Data {
1401               const FunctionSpace& what,               const FunctionSpace& what,
1402               bool expanded);               bool expanded);
1403    
1404    /**    //
1405       \brief    // flag to protect the data object against any update
1406       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);  
1407    
1408    //    //
1409    // pointer to the actual data    // pointer to the actual data object
1410    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
1411    
1412      //
1413      // pointer to the internal profiling data
1414      struct profDataEntry *profData;
1415    
1416  };  };
1417    
1418  template <class IValueType>  template <class IValueType>
# Line 730  Data::initialise(const IValueType& value Line 1428  Data::initialise(const IValueType& value
1428    // within the shared_ptr constructor.    // within the shared_ptr constructor.
1429    if (expanded) {    if (expanded) {
1430      DataAbstract* temp=new DataExpanded(value,what);      DataAbstract* temp=new DataExpanded(value,what);
1431      m_data=boost::shared_ptr<DataAbstract>(temp);      boost::shared_ptr<DataAbstract> temp_data(temp);
1432        m_data=temp_data;
1433    } else {    } else {
1434      DataAbstract* temp=new DataConstant(value,what);      DataAbstract* temp=new DataConstant(value,what);
1435      m_data=boost::shared_ptr<DataAbstract>(temp);      boost::shared_ptr<DataAbstract> temp_data(temp);
1436        m_data=temp_data;
1437    }    }
1438  }  }
1439    
1440  inline  /**
1441  DataAbstract::ValueType::value_type*     Binary Data object operators.
1442  Data::getSampleData(DataAbstract::ValueType::size_type sampleNo)  */
1443  {  inline double rpow(double x,double y)
   return m_data->getSampleData(sampleNo);  
 }  
   
 inline  
 DataAbstract::ValueType::value_type*  
 Data::getSampleDataByTag(int tag)  
 {  
   return m_data->getSampleDataByTag(tag);  
 }  
   
 inline  
 void  
 Data::operandCheck(const Data& right) const  
 {  
   return m_data->operandCheck(*(right.m_data.get()));  
 }  
   
 inline  
 int  
 Data::getNumSamples() const  
 {  
   return m_data->getNumSamples();  
 }  
   
 inline  
 std::string  
 Data::toString() const  
1444  {  {
1445    return m_data->toString();      return pow(y,x);
1446  }  };
1447    
1448  /**  /**
1449    \brief    \brief
1450    Operator+    Operator+
1451    Takes two Data objects.    Takes two Data objects.
1452  */  */
1453  Data operator+(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator+(const Data& left, const Data& right);
1454    
1455  /**  /**
1456    \brief    \brief
1457    Operator-    Operator-
1458    Takes two Data objects.    Takes two Data objects.
1459  */  */
1460  Data operator-(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator-(const Data& left, const Data& right);
1461    
1462  /**  /**
1463    \brief    \brief
1464    Operator*    Operator*
1465    Takes two Data objects.    Takes two Data objects.
1466  */  */
1467  Data operator*(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator*(const Data& left, const Data& right);
1468    
1469  /**  /**
1470    \brief    \brief
1471    Operator/    Operator/
1472    Takes two Data objects.    Takes two Data objects.
1473  */  */
1474  Data operator/(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator/(const Data& left, const Data& right);
1475    
1476  /**  /**
1477    \brief    \brief
# Line 806  Data operator/(const Data& left, const D Line 1479  Data operator/(const Data& left, const D
1479    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1480    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1481  */  */
1482  Data operator+(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator+(const Data& left, const boost::python::object& right);
1483    
1484  /**  /**
1485    \brief    \brief
# Line 814  Data operator+(const Data& left, const b Line 1487  Data operator+(const Data& left, const b
1487    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1488    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1489  */  */
1490  Data operator-(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator-(const Data& left, const boost::python::object& right);
1491    
1492  /**  /**
1493    \brief    \brief
# Line 822  Data operator-(const Data& left, const b Line 1495  Data operator-(const Data& left, const b
1495    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1496    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1497  */  */
1498  Data operator*(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator*(const Data& left, const boost::python::object& right);
1499    
1500  /**  /**
1501    \brief    \brief
# Line 830  Data operator*(const Data& left, const b Line 1503  Data operator*(const Data& left, const b
1503    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1504    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1505  */  */
1506  Data operator/(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator/(const Data& left, const boost::python::object& right);
1507    
1508  /**  /**
1509    \brief    \brief
# Line 838  Data operator/(const Data& left, const b Line 1511  Data operator/(const Data& left, const b
1511    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1512    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1513  */  */
1514  Data operator+(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator+(const boost::python::object& left, const Data& right);
1515    
1516  /**  /**
1517    \brief    \brief
# Line 846  Data operator+(const boost::python::obje Line 1519  Data operator+(const boost::python::obje
1519    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1520    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1521  */  */
1522  Data operator-(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator-(const boost::python::object& left, const Data& right);
1523    
1524  /**  /**
1525    \brief    \brief
# Line 854  Data operator-(const boost::python::obje Line 1527  Data operator-(const boost::python::obje
1527    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1528    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1529  */  */
1530  Data operator*(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator*(const boost::python::object& left, const Data& right);
1531    
1532  /**  /**
1533    \brief    \brief
# Line 862  Data operator*(const boost::python::obje Line 1535  Data operator*(const boost::python::obje
1535    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1536    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1537  */  */
1538  Data operator/(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator/(const boost::python::object& left, const Data& right);
1539    
1540  /**  /**
1541    \brief    \brief
1542    Output operator    Output operator
1543  */  */
1544  std::ostream& operator<<(std::ostream& o, const Data& data);  ESCRIPT_DLL_API std::ostream& operator<<(std::ostream& o, const Data& data);
1545    
1546    /**
1547      \brief
1548      Compute a tensor product of two Data objects
1549      \param arg0 - Input - Data object
1550      \param arg1 - Input - Data object
1551      \param axis_offset - Input - axis offset
1552      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1553    */
1554    ESCRIPT_DLL_API
1555    Data
1556    C_GeneralTensorProduct(Data& arg0,
1557                         Data& arg1,
1558                         int axis_offset=0,
1559                         int transpose=0);
1560    
1561  /**  /**
1562    \brief    \brief
# Line 876  std::ostream& operator<<(std::ostream& o Line 1564  std::ostream& operator<<(std::ostream& o
1564    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
1565    be relied on. Requires further implementation.    be relied on. Requires further implementation.
1566  */  */
1567  bool operator==(const Data& left, const Data& right);  //ESCRIPT_DLL_API bool operator==(const Data& left, const Data& right);
1568    
1569    /**
1570      \brief
1571      Perform the given binary operation with this and right as operands.
1572      Right is a Data object.
1573    */
1574  template <class BinaryFunction>  template <class BinaryFunction>
1575  inline  inline
1576  void  void
# Line 887  Data::binaryOp(const Data& right, Line 1580  Data::binaryOp(const Data& right,
1580     //     //
1581     // 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
1582     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1583       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1584     }     }
1585     //     //
1586     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 907  Data::binaryOp(const Data& right, Line 1600  Data::binaryOp(const Data& right,
1600     operandCheck(tempRight);     operandCheck(tempRight);
1601     //     //
1602     // ensure this has the right type for the RHS     // ensure this has the right type for the RHS
1603     typeMatch(tempRight);     typeMatchRight(tempRight);
1604     //     //
1605     // Need to cast to the concrete types so that the correct binaryOp     // Need to cast to the concrete types so that the correct binaryOp
1606     // is called.     // is called.
# Line 933  Data::binaryOp(const Data& right, Line 1626  Data::binaryOp(const Data& right,
1626         EsysAssert((rightC!=0), "Programming error - casting to DataConstant.");         EsysAssert((rightC!=0), "Programming error - casting to DataConstant.");
1627         escript::binaryOp(*leftC,*rightC,operation);         escript::binaryOp(*leftC,*rightC,operation);
1628       }       }
1629     } else {     } else if (isConstant()) {
      //  
      // can only be DataConstant  
1630       DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());       DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1631       DataConstant* rightC=dynamic_cast<DataConstant*>(tempRight.m_data.get());       DataConstant* rightC=dynamic_cast<DataConstant*>(tempRight.m_data.get());
1632       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");
1633       escript::binaryOp(*leftC,*rightC,operation);       escript::binaryOp(*leftC,*rightC,operation);
1634     }     }
1635       #if defined DOPROF
1636       profData->binary++;
1637       #endif
1638  }  }
1639    
1640  template <class BinaryFunction>  /**
1641      \brief
1642      Perform the given unary operation on other and return the result.
1643      Given operation is performed on each element of each data point, thus
1644      argument object is a rank n Data object, and returned object is a rank n
1645      Data object.
1646      Calls Data::unaryOp.
1647    */
1648    template <class UnaryFunction>
1649  inline  inline
1650  void  Data
1651  Data::binaryOp(const boost::python::object& right,  unaryOp(const Data& other,
1652                 BinaryFunction operation)          UnaryFunction operation)
1653  {  {
1654     DataArray temp(right);    Data result;
1655     //    result.copy(other);
1656     // if this has a rank of zero promote it to the rank of the RHS.    result.unaryOp(operation);
1657     if (getPointDataView().getRank()==0 && temp.getView().getRank()!=0) {    return result;
       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()) {  
      //  
      // Expanded data will be done in parallel  
      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 {  
      //  
      // can only be DataConstant  
      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());  
      EsysAssert((leftC!=0),"Programming error - casting to DataConstant.");  
      escript::binaryOp(*leftC,temp.getView(),operation);  
    }  
1658  }  }
1659    
1660    /**
1661      \brief
1662      Perform the given unary operation on this.
1663      Given operation is performed on each element of each data point.
1664      Calls escript::unaryOp.
1665    */
1666  template <class UnaryFunction>  template <class UnaryFunction>
1667  inline  inline
1668  void  void
1669  Data::unaryOp(UnaryFunction operation)  Data::unaryOp(UnaryFunction operation)
1670  {  {
1671    if (isExpanded()) {    if (isExpanded()) {
     //  
     // Expanded data will be done in parallel  
1672      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1673      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1674      escript::unaryOp(*leftC,operation);      escript::unaryOp(*leftC,operation);
# Line 998  Data::unaryOp(UnaryFunction operation) Line 1676  Data::unaryOp(UnaryFunction operation)
1676      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1677      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1678      escript::unaryOp(*leftC,operation);      escript::unaryOp(*leftC,operation);
1679    } else {    } else if (isConstant()) {
1680      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1681      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1682      escript::unaryOp(*leftC,operation);      escript::unaryOp(*leftC,operation);
1683    }    }
1684  }  }
1685    
1686  template <class UnaryFunction>  /**
1687      \brief
1688      Perform the given Data object reduction algorithm on this and return the result.
1689      Given operation combines each element of each data point, thus argument
1690      object (*this) is a rank n Data object, and returned object is a scalar.
1691      Calls escript::algorithm.
1692    */
1693    template <class BinaryFunction>
1694  inline  inline
1695  double  double
1696  Data::algorithm(UnaryFunction operation) const  Data::algorithm(BinaryFunction operation, double initial_value) const
1697  {  {
1698    if (isExpanded()) {    if (isExpanded()) {
     //  
     // Expanded data will be done in parallel  
1699      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1700      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1701      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1702    }    } else if (isTagged()) {
   else if (isTagged()) {  
1703      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1704      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1705      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1706    } else {    } else if (isConstant()) {
1707      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1708      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1709      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1710    }    }
1711      return 0;
1712  }  }
1713    
1714  template <class UnaryFunction>  /**
1715      \brief
1716      Perform the given data point reduction algorithm on data and return the result.
1717      Given operation combines each element within each data point into a scalar,
1718      thus argument object is a rank n Data object, and returned object is a
1719      rank 0 Data object.
1720      Calls escript::dp_algorithm.
1721    */
1722    template <class BinaryFunction>
1723  inline  inline
1724  Data  Data
1725  unaryOp(const Data& other,  Data::dp_algorithm(BinaryFunction operation, double initial_value) const
         UnaryFunction operation)  
1726  {  {
1727    //    if (isExpanded()) {
1728    // Perform the given operation on a copy of the input data and return the result      Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1729    Data result;      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
1730    //      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1731    // perform a deep copy      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1732    result.copy(other);      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1733    result.unaryOp(operation);      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
1734    return result;      return result;
1735      } else if (isTagged()) {
1736        DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1737        DataArrayView::ShapeType viewShape;
1738        DataArrayView::ValueType viewData(1);
1739        viewData[0]=0;
1740        DataArrayView defaultValue(viewData,viewShape);
1741        DataTagged::TagListType keys;
1742        DataTagged::ValueListType values;
1743        DataTagged::DataMapType::const_iterator i;
1744        for (i=dataT->getTagLookup().begin();i!=dataT->getTagLookup().end();i++) {
1745          keys.push_back(i->first);
1746          values.push_back(defaultValue);
1747        }
1748        Data result(keys,values,defaultValue,getFunctionSpace());
1749        DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1750        EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1751        EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1752        escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
1753        return result;
1754      } else if (isConstant()) {
1755        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1756        DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1757        DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1758        EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1759        EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1760        escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
1761        return result;
1762      }
1763      Data falseRetVal; // to keep compiler quiet
1764      return falseRetVal;
1765  }  }
1766    
1767  }  }
   
1768  #endif  #endif

Legend:
Removed from v.100  
changed lines
  Added in v.922

  ViewVC Help
Powered by ViewVC 1.1.26