/[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 94 by jgs, Wed Oct 27 00:45:54 2004 UTC trunk/escript/src/Data.h revision 914 by gross, Thu Dec 14 04:38:18 2006 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       \brief       Member access methods.
      Perform the given binary operation on all of the data's elements.  
      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.  
238    */    */
   template <class BinaryFunction>  
   void  
   binaryOp(const Data& right,  
            BinaryFunction operation);  
239    
240    /**    /**
241       \brief       \brief
242       Perform the given binary operation on all of the data's elements.       switches on update protection
243    
244    */    */
245    template <class BinaryFunction>    ESCRIPT_DLL_API
246    void    void
247    binaryOp(const boost::python::object& right,    setProtection();
            BinaryFunction operation);  
248    
249    /**    /**
250       \brief       \brief
251       Overloaded operator +=       Returns trueif the data object is protected against update
      \param right - Input - The right hand side.  
   */  
   Data& operator+=(const Data& right);  
   Data& operator+=(const boost::python::object& right);  
252    
253      */
254      ESCRIPT_DLL_API
255      bool
256      isProtected() const;
257    /**    /**
258       \brief       \brief
259       Overloaded operator -=       Return the values of all data-points as a single python numarray object.
      \param right - Input - The right hand side.  
260    */    */
261    Data& operator-=(const Data& right);    ESCRIPT_DLL_API
262    Data& operator-=(const boost::python::object& right);    const boost::python::numeric::array
263      convertToNumArray();
264    
265   /**    /**
266       \brief       \brief
267       Overloaded operator *=       Return the values of all data-points for the given sample as a single python numarray object.
      \param right - Input - The right hand side.  
268    */    */
269    Data& operator*=(const Data& right);    ESCRIPT_DLL_API
270    Data& operator*=(const boost::python::object& right);    const boost::python::numeric::array
271      convertToNumArrayFromSampleNo(int sampleNo);
272    
273   /**    /**
274       \brief       \brief
275       Overloaded operator /=       Return the value of the specified data-point as a single python numarray object.
      \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      convertToNumArrayFromDPNo(int procNo,
280                    int sampleNo,
281                    int dataPointNo);
282      /**
283         \brief
284         Fills the expanded Data object from values of a python numarray object.
285      */
286      ESCRIPT_DLL_API
287      void
288      fillFromNumArray(const boost::python::numeric::array);
289    
290    /**    /**
291       \brief       \brief
292       Return the power of Data.       Return the tag number associated with the given data-point.
293    
294         The data-point number here corresponds to the data-point number in the
295         numarray returned by convertToNumArray.
296    */    */
297    Data powD(const Data& right) const;    ESCRIPT_DLL_API
298    Data powO(const boost::python::object& right) const;    int
299      getTagNumber(int dpno);
300    
301    /**    /**
302       \brief       \brief
303       Return the C wrapper for the Data object.       Return the C wrapper for the Data object.
304    */    */
305    escriptDataC getDataC();    ESCRIPT_DLL_API
306      escriptDataC
307      getDataC();
308    
309    /**    /**
310       \brief       \brief
311       Return the C wrapper for the Data object - const version.       Return the C wrapper for the Data object - const version.
312    */    */
313    escriptDataC getDataC() const;    ESCRIPT_DLL_API
314      escriptDataC
315      getDataC() const;
316    
317    /**    /**
318       \brief       \brief
319       Write the data as a string.       Write the data as a string.
320    */    */
321    std::string toString() const;    ESCRIPT_DLL_API
322      inline
323      std::string
324      toString() const
325      {
326        return m_data->toString();
327      }
328    
329    /**    /**
330       \brief       \brief
# Line 303  class Data { Line 332  class Data {
332       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
333       to manipulate the point data.       to manipulate the point data.
334    */    */
335      ESCRIPT_DLL_API
336    inline    inline
337    const DataArrayView&    const DataArrayView&
338    getPointDataView() const    getPointDataView() const
# Line 312  class Data { Line 342  class Data {
342    
343    /**    /**
344       \brief       \brief
345       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.  
346    */    */
347      ESCRIPT_DLL_API
348    void    void
349    expand();    expand();
350    
351    /**    /**
352       \brief       \brief
353       If possible convert the Data type to tagged. This will only allow       If possible convert this Data to DataTagged. This will only allow
354       Constant data to be converted to tagged. An attempt to convert       Constant data to be converted to tagged. An attempt to convert
355       Expanded data to tagged will throw an exception.       Expanded data to tagged will throw an exception.
356        ==>*
357    */    */
358      ESCRIPT_DLL_API
359    void    void
360    tag();    tag();
361    
# Line 345  class Data { Line 363  class Data {
363       \brief       \brief
364       Return true if this Data is expanded.       Return true if this Data is expanded.
365    */    */
366      ESCRIPT_DLL_API
367    bool    bool
368    isExpanded() const;    isExpanded() const;
369    
# Line 352  class Data { Line 371  class Data {
371       \brief       \brief
372       Return true if this Data is tagged.       Return true if this Data is tagged.
373    */    */
374      ESCRIPT_DLL_API
375    bool    bool
376    isTagged() const;    isTagged() const;
377    
378    /**    /**
379       \brief       \brief
380       Return true if this Data is empty.       Return true if this Data is constant.
381    */    */
382      ESCRIPT_DLL_API
383    bool    bool
384    isEmpty() const;    isConstant() const;
385    
386    /**    /**
387       \brief       \brief
388       Return true if this Data is constant.       Return true if this Data is empty.
389    */    */
390      ESCRIPT_DLL_API
391    bool    bool
392    isConstant() const;    isEmpty() const;
393    
394    /**    /**
395       \brief       \brief
396       Return the function space.       Return the function space.
397    */    */
398      ESCRIPT_DLL_API
399    inline    inline
400    const FunctionSpace&    const FunctionSpace&
401    getFunctionSpace() const    getFunctionSpace() const
# Line 384  class Data { Line 407  class Data {
407       \brief       \brief
408       Return a copy of the function space.       Return a copy of the function space.
409    */    */
410      ESCRIPT_DLL_API
411    const FunctionSpace    const FunctionSpace
412    getCopyOfFunctionSpace() const;    getCopyOfFunctionSpace() const;
413    
# Line 391  class Data { Line 415  class Data {
415       \brief       \brief
416       Return the domain.       Return the domain.
417    */    */
418      ESCRIPT_DLL_API
419    inline    inline
420    const AbstractDomain&    const AbstractDomain&
421    getDomain() const    getDomain() const
# Line 402  class Data { Line 427  class Data {
427       \brief       \brief
428       Return a copy of the domain.       Return a copy of the domain.
429    */    */
430      ESCRIPT_DLL_API
431    const AbstractDomain    const AbstractDomain
432    getCopyOfDomain() const;    getCopyOfDomain() const;
433    
# Line 409  class Data { Line 435  class Data {
435       \brief       \brief
436       Return the rank of the point data.       Return the rank of the point data.
437    */    */
438      ESCRIPT_DLL_API
439    inline    inline
440    int    int
441    getDataPointRank() const    getDataPointRank() const
# Line 418  class Data { Line 445  class Data {
445    
446    /**    /**
447       \brief       \brief
448       Return the number of data points per sample.       Return the number of samples.
449    */    */
450      ESCRIPT_DLL_API
451    inline    inline
452    int    int
453    getNumDataPointsPerSample() const    getNumSamples() const
454    {    {
455      return m_data->getNumDPPSample();      return m_data->getNumSamples();
456    }    }
457    
458    /**    /**
459       \brief       \brief
460       Return the number of samples.       Return the number of data points per sample.
461    */    */
462      ESCRIPT_DLL_API
463      inline
464    int    int
465    getNumSamples() const;    getNumDataPointsPerSample() const
466      {
467    /**      return m_data->getNumDPPSample();
468       \brief    }
      Check *this and the right operand are compatible. Throws  
      an exception if they aren't.  
      \param right - Input - The right hand side.  
   */  
   void  
   operandCheck(const Data& right) const;  
469    
470    /**    /**
471       \brief       \brief
# Line 449  class Data { Line 473  class Data {
473       preferred interface but is provided for use by C code.       preferred interface but is provided for use by C code.
474       \param sampleNo - Input - the given sample no.       \param sampleNo - Input - the given sample no.
475    */    */
476      ESCRIPT_DLL_API
477      inline
478    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
479    getSampleData(DataAbstract::ShapeType::size_type sampleNo);    getSampleData(DataAbstract::ValueType::size_type sampleNo)
480      {
481        return m_data->getSampleData(sampleNo);
482      }
483    
484    /**    /**
485       \brief       \brief
# Line 458  class Data { Line 487  class Data {
487       access data that isn't tagged an exception will be thrown.       access data that isn't tagged an exception will be thrown.
488       \param tag - Input - the tag key.       \param tag - Input - the tag key.
489    */    */
490      ESCRIPT_DLL_API
491      inline
492    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
493    getSampleDataByTag(int tag);    getSampleDataByTag(int tag)
494      {
495        return m_data->getSampleDataByTag(tag);
496      }
497    
498      /**
499         \brief
500         Assign the given value to the data-points referenced by the given
501         reference number.
502    
503         The value supplied is a python numarray object.  The data from this numarray
504         is unpacked into a DataArray, and this is used to set the corresponding
505         data-points in the underlying Data object.
506    
507         If the underlying Data object cannot be accessed via reference numbers, an
508         exception will be thrown.
509    
510         \param ref - Input - reference number.
511         \param value - Input - value to assign to data-points associated with
512                                the given reference number.
513      */
514      ESCRIPT_DLL_API
515      void
516      setRefValue(int ref,
517                  const boost::python::numeric::array& value);
518    
519      /**
520         \brief
521         Return the values associated with the data-points referenced by the given
522         reference number.
523    
524         The value supplied is a python numarray object. The data from the corresponding
525         data-points in this Data object are packed into the given numarray object.
526    
527         If the underlying Data object cannot be accessed via reference numbers, an
528         exception will be thrown.
529    
530         \param ref - Input - reference number.
531         \param value - Output - object to receive values from data-points
532                                 associated with the given reference number.
533      */
534      ESCRIPT_DLL_API
535      void
536      getRefValue(int ref,
537                  boost::python::numeric::array& value);
538    
539    /**    /**
540       \brief       \brief
# Line 469  class Data { Line 544  class Data {
544       \param sampleNo - Input -       \param sampleNo - Input -
545       \param dataPointNo - Input -       \param dataPointNo - Input -
546    */    */
547      ESCRIPT_DLL_API
548    inline    inline
549    DataArrayView    DataArrayView
550    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
551                 int dataPointNo)                 int dataPointNo)
552    {    {
553      return m_data->getDataPoint(sampleNo,dataPointNo);          return m_data->getDataPoint(sampleNo,dataPointNo);
554    }    }
555    
556    /**    /**
557       \brief       \brief
558       Return a reference to the data point shape.       Return a reference to the data point shape.
559    */    */
560      ESCRIPT_DLL_API
561    const DataArrayView::ShapeType&    const DataArrayView::ShapeType&
562    getDataPointShape() const;    getDataPointShape() const;
563    
564    /**    /**
565       \brief       \brief
566       Return data point shape as a tuple of integers:       Return the data point shape as a tuple of integers.
567    */    */
568    boost::python::tuple    ESCRIPT_DLL_API
569      const boost::python::tuple
570    getShapeTuple() const;    getShapeTuple() const;
571    
572    /**    /**
# Line 496  class Data { Line 574  class Data {
574       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
575       data point shape dimensions.       data point shape dimensions.
576    */    */
577      ESCRIPT_DLL_API
578    int    int
579    getDataPointSize() const;    getDataPointSize() const;
580    
581    /**    /**
582       \brief       \brief
583       Return the number of doubles stored for Data.       Return the number of doubles stored for this Data.
584    */    */
585      ESCRIPT_DLL_API
586    DataArrayView::ValueType::size_type    DataArrayView::ValueType::size_type
587    getLength() const;    getLength() const;
588    
589    /**    /**
590       \brief       \brief
591       Interpolates this onto the given functionspace and returns the result as a Data object.       Assign the given value to the tag. Implicitly converts this
592         object to type DataTagged. Throws an exception if this object
593         cannot be converted to a DataTagged object.
594         \param tagKey - Input - Integer key.
595         \param value - Input - Value to associate with given key.
596        ==>*
597      */
598      ESCRIPT_DLL_API
599      void
600      setTaggedValue(int tagKey,
601                     const boost::python::object& value);
602    
603      /**
604         \brief
605         Assign the given value to the tag. Implicitly converts this
606         object to type DataTagged. Throws an exception if this object
607         cannot be converted to a DataTagged object.
608         \param tagKey - Input - Integer key.
609         \param value - Input - Value to associate with given key.
610        ==>*
611      */
612      ESCRIPT_DLL_API
613      void
614      setTaggedValueFromCPP(int tagKey,
615                            const DataArrayView& value);
616    
617      /**
618        \brief
619        Copy other Data object into this Data object where mask is positive.
620      */
621      ESCRIPT_DLL_API
622      void
623      copyWithMask(const Data& other,
624                   const Data& mask);
625    
626      /**
627         Data object operation methods and operators.
628      */
629    
630      /**
631         \brief
632         Interpolates this onto the given functionspace and returns
633         the result as a Data object.
634         *
635    */    */
636      ESCRIPT_DLL_API
637    Data    Data
638    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
639    
# Line 517  class Data { Line 641  class Data {
641       \brief       \brief
642       Calculates the gradient of the data at the data points of functionspace.       Calculates the gradient of the data at the data points of functionspace.
643       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.
644         *
645    */    */
646      ESCRIPT_DLL_API
647    Data    Data
648    gradOn(const FunctionSpace& functionspace) const;    gradOn(const FunctionSpace& functionspace) const;
649    
650      ESCRIPT_DLL_API
651    Data    Data
652    grad() const;    grad() const;
653    
654    /**    /**
655       \brief       \brief
656       Calculate the integral over the function space domain.       Calculate the integral over the function space domain.
657         *
658    */    */
659      ESCRIPT_DLL_API
660    boost::python::numeric::array    boost::python::numeric::array
661    integrate() const;    integrate() const;
662    
663    /**    /**
664       \brief       \brief
665         Returns 1./ Data object
666         *
667      */
668      ESCRIPT_DLL_API
669      Data
670      oneOver() const;
671      /**
672         \brief
673       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.
674         *
675    */    */
676      ESCRIPT_DLL_API
677    Data    Data
678    wherePositive() const;    wherePositive() const;
679    
680    /**    /**
681       \brief       \brief
682       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.
683         *
684    */    */
685      ESCRIPT_DLL_API
686      Data
687      whereNegative() const;
688    
689      /**
690         \brief
691         Return a Data with a 1 for +ive or 0 values and a 0 for -ive values.
692         *
693      */
694      ESCRIPT_DLL_API
695    Data    Data
696    whereNonNegative() const;    whereNonNegative() const;
697    
698    /**    /**
699       \brief       \brief
700       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.
701         *
702    */    */
703      ESCRIPT_DLL_API
704    Data    Data
705    whereNegative() const;    whereNonPositive() const;
706    
707      /**
708         \brief
709         Return a Data with a 1 for 0 values and a 0 for +ive or -ive values.
710         *
711      */
712      ESCRIPT_DLL_API
713      Data
714      whereZero(double tol=0.0) const;
715    
716      /**
717         \brief
718         Return a Data with a 0 for 0 values and a 1 for +ive or -ive values.
719         *
720      */
721      ESCRIPT_DLL_API
722      Data
723      whereNonZero(double tol=0.0) const;
724    
725      /**
726         \brief
727         Return the maximum absolute value of this Data object.
728         *
729      */
730      ESCRIPT_DLL_API
731      double
732      Lsup() const;
733    
734      /**
735         \brief
736         Return the minimum absolute value of this Data object.
737         *
738      */
739      ESCRIPT_DLL_API
740      double
741      Linf() const;
742    
743      /**
744         \brief
745         Return the maximum value of this Data object.
746         *
747      */
748      ESCRIPT_DLL_API
749      double
750      sup() const;
751    
752      /**
753         \brief
754         Return the minimum value of this Data object.
755         *
756      */
757      ESCRIPT_DLL_API
758      double
759      inf() const;
760    
761      /**
762         \brief
763         Return the absolute value of each data point of this Data object.
764         *
765      */
766      ESCRIPT_DLL_API
767      Data
768      abs() const;
769    
770      /**
771         \brief
772         Return the maximum value of each data point of this Data object.
773         *
774      */
775      ESCRIPT_DLL_API
776      Data
777      maxval() const;
778    
779      /**
780         \brief
781         Return the minimum value of each data point of this Data object.
782         *
783      */
784      ESCRIPT_DLL_API
785      Data
786      minval() const;
787    
788      /**
789         \brief
790         Return the (sample number, data-point number) of the data point with
791         the minimum value in this Data object.
792      */
793      ESCRIPT_DLL_API
794      const boost::python::tuple
795      mindp() const;
796    
797      ESCRIPT_DLL_API
798      void
799      calc_mindp(int& ProcNo,
800                            int& SampleNo,  
801                 int& DataPointNo) const;
802      /**
803         \brief
804         Return the sign of each data point of this Data object.
805         -1 for negative values, zero for zero values, 1 for positive values.
806         *
807      */
808      ESCRIPT_DLL_API
809      Data
810      sign() const;
811    
812      /**
813         \brief
814         Return the symmetric part of a matrix which is half the matrix plus its transpose.
815         *
816      */
817      ESCRIPT_DLL_API
818      Data
819      symmetric() const;
820    
821      /**
822         \brief
823         Return the nonsymmetric part of a matrix which is half the matrix minus its transpose.
824         *
825      */
826      ESCRIPT_DLL_API
827      Data
828      nonsymmetric() const;
829    
830      /**
831         \brief
832         Return the trace of a matrix
833         *
834      */
835      ESCRIPT_DLL_API
836      Data
837      trace(int axis_offset) const;
838    
839      /**
840         \brief
841         Transpose each data point of this Data object around the given axis.
842         *
843      */
844      ESCRIPT_DLL_API
845      Data
846      transpose(int axis_offset) const;
847    
848      /**
849         \brief
850         Return the eigenvalues of the symmetric part at each data point of this Data object in increasing values.
851         Currently this function is restricted to rank 2, square shape, and dimension 3.
852         *
853      */
854      ESCRIPT_DLL_API
855      Data
856      eigenvalues() const;
857    
858      /**
859         \brief
860         Return the eigenvalues and corresponding eigenvcetors of the symmetric part at each data point of this Data object.
861         the eigenvalues are ordered in increasing size where eigenvalues with relative difference less than
862         tol are treated as equal. The eigenvectors are orthogonal, normalized and the sclaed such that the
863         first non-zero entry is positive.
864         Currently this function is restricted to rank 2, square shape, and dimension 3
865         *
866      */
867      ESCRIPT_DLL_API
868      const boost::python::tuple
869      eigenvalues_and_eigenvectors(const double tol=1.e-12) const;
870    
871    /**    /**
872       \brief       \brief
873       Return a Data with a 1 for 0 values a 0 for +ive or -ive.       swaps the components axis0 and axis1
874         *
875    */    */
876      ESCRIPT_DLL_API
877    Data    Data
878    whereZero() const;    swapaxes(const int axis0, const int axis1) const;
879    
880    /**    /**
881       \brief       \brief
882       Return the sin of Data.       Return the error function erf of each data point of this Data object.
883         *
884    */    */
885      ESCRIPT_DLL_API
886      Data
887      erf() const;
888    
889      /**
890         \brief
891         Return the sin of each data point of this Data object.
892         *
893      */
894      ESCRIPT_DLL_API
895    Data    Data
896    sin() const;    sin() const;
897    
898    /**    /**
899       \brief       \brief
900       Return the cos of Data.       Return the cos of each data point of this Data object.
901         *
902    */    */
903      ESCRIPT_DLL_API
904    Data    Data
905    cos() const;    cos() const;
906    
907    /**    /**
908       \brief       \brief
909       Return the tan of Data.       Return the tan of each data point of this Data object.
910         *
911    */    */
912      ESCRIPT_DLL_API
913    Data    Data
914    tan() const;    tan() const;
915    
916    /**    /**
917       \brief       \brief
918       Return the log to base 10 of Data.       Return the asin of each data point of this Data object.
919         *
920    */    */
921      ESCRIPT_DLL_API
922    Data    Data
923    log() const;    asin() const;
924    
925    /**    /**
926       \brief       \brief
927       Return the natural log of Data.       Return the acos of each data point of this Data object.
928         *
929    */    */
930      ESCRIPT_DLL_API
931    Data    Data
932    ln() const;    acos() const;
933    
934    /**    /**
935       \brief       \brief
936       Return a Data containing a slice of this Data.       Return the atan of each data point of this Data object.
937         *
938    */    */
939      ESCRIPT_DLL_API
940    Data    Data
941    getSlice(const DataArrayView::RegionType& region) const;    atan() const;
942    
943    /**    /**
944       \brief       \brief
945       Copy the specified region from the given value.       Return the sinh of each data point of this Data object.
946       \param value - Input - Data to copy from.       *
      \param region - Input - Region to copy.  
947    */    */
948    void    ESCRIPT_DLL_API
949    setSlice(const Data& value,    Data
950             const DataArrayView::RegionType& region);    sinh() const;
951    
952    /**    /**
953       \brief       \brief
954       Return the maximum absolute value.       Return the cosh of each data point of this Data object.
955         *
956    */    */
957    double    ESCRIPT_DLL_API
958    Lsup() const;    Data
959      cosh() const;
960    
961    /**    /**
962       \brief       \brief
963       Return the maximum value.       Return the tanh of each data point of this Data object.
964         *
965    */    */
966    double    ESCRIPT_DLL_API
967    sup() const;    Data
968      tanh() const;
969    
970    /**    /**
971       \brief       \brief
972       Return the minimum value.       Return the asinh of each data point of this Data object.
973         *
974    */    */
975    double    ESCRIPT_DLL_API
976    inf() const;    Data
977      asinh() const;
978    
979    /**    /**
980       \brief       \brief
981       Returns a slice from this.       Return the acosh of each data point of this Data object.
982         *
983    */    */
984      ESCRIPT_DLL_API
985    Data    Data
986    getItem(const boost::python::object& key) const;    acosh() const;
987    
988      /**
989         \brief
990         Return the atanh of each data point of this Data object.
991         *
992      */
993      ESCRIPT_DLL_API
994      Data
995      atanh() const;
996    
997    /**    /**
998       \brief       \brief
999       Copies slice from value into this.       Return the log to base 10 of each data point of this Data object.
1000         *
1001    */    */
1002      ESCRIPT_DLL_API
1003      Data
1004      log10() const;
1005    
1006      /**
1007         \brief
1008         Return the natural log of each data point of this Data object.
1009         *
1010      */
1011      ESCRIPT_DLL_API
1012      Data
1013      log() const;
1014    
1015      /**
1016         \brief
1017         Return the exponential function of each data point of this Data object.
1018         *
1019      */
1020      ESCRIPT_DLL_API
1021      Data
1022      exp() const;
1023    
1024      /**
1025         \brief
1026         Return the square root of each data point of this Data object.
1027         *
1028      */
1029      ESCRIPT_DLL_API
1030      Data
1031      sqrt() const;
1032    
1033      /**
1034         \brief
1035         Return the negation of each data point of this Data object.
1036         *
1037      */
1038      ESCRIPT_DLL_API
1039      Data
1040      neg() const;
1041    
1042      /**
1043         \brief
1044         Return the identity of each data point of this Data object.
1045         Simply returns this object unmodified.
1046         *
1047      */
1048      ESCRIPT_DLL_API
1049      Data
1050      pos() const;
1051    
1052      /**
1053         \brief
1054         Return the given power of each data point of this Data object.
1055    
1056         \param right Input - the power to raise the object to.
1057         *
1058      */
1059      ESCRIPT_DLL_API
1060      Data
1061      powD(const Data& right) const;
1062    
1063      /**
1064         \brief
1065         Return the given power of each data point of this boost python object.
1066        
1067         \param right Input - the power to raise the object to.
1068         *
1069       */
1070      ESCRIPT_DLL_API
1071      Data
1072      powO(const boost::python::object& right) const;
1073    
1074      /**
1075         \brief
1076         Return the given power of each data point of this boost python object.
1077        
1078         \param left Input - the bases
1079         *
1080       */
1081    
1082      ESCRIPT_DLL_API
1083      Data
1084      rpowO(const boost::python::object& left) const;
1085    
1086      /**
1087         \brief
1088         writes the object to a file in the DX file format
1089      */
1090      ESCRIPT_DLL_API
1091    void    void
1092    setItem(const boost::python::object& key,    saveDX(std::string fileName) const;
           const Data& value);  
1093    
1094    /**    /**
1095       \brief       \brief
1096       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.  
1097    */    */
1098      ESCRIPT_DLL_API
1099    void    void
1100    typeMatch(const Data& right);    saveVTK(std::string fileName) const;
1101    
1102      /**
1103         \brief
1104         Overloaded operator +=
1105         \param right - Input - The right hand side.
1106         *
1107      */
1108      ESCRIPT_DLL_API
1109      Data& operator+=(const Data& right);
1110      ESCRIPT_DLL_API
1111      Data& operator+=(const boost::python::object& right);
1112    
1113      /**
1114         \brief
1115         Overloaded operator -=
1116         \param right - Input - The right hand side.
1117         *
1118      */
1119      ESCRIPT_DLL_API
1120      Data& operator-=(const Data& right);
1121      ESCRIPT_DLL_API
1122      Data& operator-=(const boost::python::object& right);
1123    
1124     /**
1125         \brief
1126         Overloaded operator *=
1127         \param right - Input - The right hand side.
1128         *
1129      */
1130      ESCRIPT_DLL_API
1131      Data& operator*=(const Data& right);
1132      ESCRIPT_DLL_API
1133      Data& operator*=(const boost::python::object& right);
1134    
1135     /**
1136         \brief
1137         Overloaded operator /=
1138         \param right - Input - The right hand side.
1139         *
1140      */
1141      ESCRIPT_DLL_API
1142      Data& operator/=(const Data& right);
1143      ESCRIPT_DLL_API
1144      Data& operator/=(const boost::python::object& right);
1145    
1146    /**    /**
1147       \brief       \brief
1148       Returns true if this can be interpolated to functionspace.       Returns true if this can be interpolated to functionspace.
1149    */    */
1150      ESCRIPT_DLL_API
1151    bool    bool
1152    probeInterpolation(const FunctionSpace& functionspace) const;    probeInterpolation(const FunctionSpace& functionspace) const;
1153    
1154    /**    /**
1155         Data object slicing methods.
1156      */
1157    
1158      /**
1159       \brief       \brief
1160       Assign the given value to the tag. Implicitly converts this       Returns a slice from this Data object.
1161       object to type DataTagged. Throws an exception if this object  
1162       cannot be converted to a DataTagged object.       /description
1163       \param tagKey - Input - Integer key.       Implements the [] get operator in python.
1164       \param value - Input - Value to associate with given key.       Calls getSlice.
1165    
1166         \param key - Input - python slice tuple specifying
1167         slice to return.
1168      */
1169      ESCRIPT_DLL_API
1170      Data
1171      getItem(const boost::python::object& key) const;
1172    
1173      /**
1174         \brief
1175         Copies slice from value into this Data object.
1176    
1177         Implements the [] set operator in python.
1178         Calls setSlice.
1179    
1180         \param key - Input - python slice tuple specifying
1181         slice to copy from value.
1182         \param value - Input - Data object to copy from.
1183    */    */
1184      ESCRIPT_DLL_API
1185    void    void
1186    setTaggedValue(int tagKey,    setItemD(const boost::python::object& key,
1187                   const boost::python::object& value);             const Data& value);
1188    
1189      ESCRIPT_DLL_API
1190      void
1191      setItemO(const boost::python::object& key,
1192               const boost::python::object& value);
1193    
1194      // These following public methods should be treated as private.
1195    
1196    /**    /**
1197       \brief       \brief
1198       Assign the given value to the tag. Implicitly converts this       Perform the given unary operation on every element of every data point in
1199       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  
1200    */    */
1201    /*    template <class UnaryFunction>
1202      ESCRIPT_DLL_API
1203      inline
1204    void    void
1205    setTaggedValue(int tagKey,    unaryOp(UnaryFunction operation);
1206                   const DataArrayView& value);  
1207      /**
1208         \brief
1209         Return a Data object containing the specified slice of
1210         this Data object.
1211         \param region - Input - Region to copy.
1212         *
1213      */
1214      ESCRIPT_DLL_API
1215      Data
1216      getSlice(const DataArrayView::RegionType& region) const;
1217    
1218      /**
1219         \brief
1220         Copy the specified slice from the given value into this
1221         Data object.
1222         \param value - Input - Data to copy from.
1223         \param region - Input - Region to copy.
1224         *
1225      */
1226      ESCRIPT_DLL_API
1227      void
1228      setSlice(const Data& value,
1229               const DataArrayView::RegionType& region);
1230    
1231      /**
1232         \brief
1233         Archive the current Data object to the given file.
1234         \param fileName - Input - file to archive to.
1235      */
1236      ESCRIPT_DLL_API
1237      void
1238      archiveData(const std::string fileName);
1239    
1240      /**
1241         \brief
1242         Extract the Data object archived in the given file, overwriting
1243         the current Data object.
1244         Note - the current object must be of type DataEmpty.
1245         \param fileName - Input - file to extract from.
1246         \param fspace - Input - a suitable FunctionSpace descibing the data.
1247      */
1248      ESCRIPT_DLL_API
1249      void
1250      extractData(const std::string fileName,
1251                  const FunctionSpace& fspace);
1252    
1253    
1254      /**
1255         \brief
1256         print the data values to stdout. Used for debugging
1257      */
1258      ESCRIPT_DLL_API
1259      void
1260        print(void);
1261    
1262      /**
1263         \brief
1264         return the MPI rank number of the local data
1265             MPI_COMM_WORLD is assumed and the result of MPI_Comm_size()
1266             is returned
1267      */
1268      ESCRIPT_DLL_API
1269        int
1270        get_MPIRank(void) const;
1271    
1272      /**
1273         \brief
1274         return the MPI rank number of the local data
1275             MPI_COMM_WORLD is assumed and the result of MPI_Comm_rank()
1276             is returned
1277      */
1278      ESCRIPT_DLL_API
1279        int
1280        get_MPISize(void) const;
1281    
1282      /**
1283         \brief
1284         return the MPI rank number of the local data
1285             MPI_COMM_WORLD is assumed and returned.
1286      */
1287      ESCRIPT_DLL_API
1288        MPI_Comm
1289        get_MPIComm(void) const;
1290    
1291      /**
1292         \brief
1293         return the object produced by the factory, which is a DataConstant or DataExpanded
1294    */    */
1295      ESCRIPT_DLL_API
1296        DataAbstract*
1297        borrowData(void) const;
1298    
1299     protected:
1300    
1301   private:   private:
1302    
1303    /**    /**
1304       \brief       \brief
1305         Check *this and the right operand are compatible. Throws
1306         an exception if they aren't.
1307         \param right - Input - The right hand side.
1308      */
1309      inline
1310      void
1311      operandCheck(const Data& right) const
1312      {
1313        return m_data->operandCheck(*(right.m_data.get()));
1314      }
1315    
1316      /**
1317         \brief
1318         Perform the specified reduction algorithm on every element of every data point in
1319         this Data object according to the given function and return the single value result.
1320      */
1321      template <class BinaryFunction>
1322      inline
1323      double
1324      algorithm(BinaryFunction operation,
1325                double initial_value) const;
1326    
1327      /**
1328         \brief
1329         Reduce each data-point in this Data object using the given operation. Return a Data
1330         object with the same number of data-points, but with each data-point containing only
1331         one value - the result of the reduction operation on the corresponding data-point in
1332         this Data object
1333      */
1334      template <class BinaryFunction>
1335      inline
1336      Data
1337      dp_algorithm(BinaryFunction operation,
1338                   double initial_value) const;
1339    
1340      /**
1341         \brief
1342         Perform the given binary operation on all of the data's elements.
1343         The underlying type of the right hand side (right) determines the final
1344         type of *this after the operation. For example if the right hand side
1345         is expanded *this will be expanded if necessary.
1346         RHS is a Data object.
1347      */
1348      template <class BinaryFunction>
1349      inline
1350      void
1351      binaryOp(const Data& right,
1352               BinaryFunction operation);
1353    
1354      /**
1355         \brief
1356         Convert the data type of the RHS to match this.
1357         \param right - Input - data type to match.
1358      */
1359      void
1360      typeMatchLeft(Data& right) const;
1361    
1362      /**
1363         \brief
1364         Convert the data type of this to match the RHS.
1365         \param right - Input - data type to match.
1366      */
1367      void
1368      typeMatchRight(const Data& right);
1369    
1370      /**
1371         \brief
1372       Construct a Data object of the appropriate type.       Construct a Data object of the appropriate type.
1373    */    */
1374    template <class IValueType>    template <class IValueType>
# Line 701  class Data { Line 1377  class Data {
1377               const FunctionSpace& what,               const FunctionSpace& what,
1378               bool expanded);               bool expanded);
1379    
1380    /**    //
1381       \brief    // flag to protect the data object against any update
1382       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);  
1383    
1384    //    //
1385    // pointer to the actual data    // pointer to the actual data object
1386    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
1387    
1388      //
1389      // pointer to the internal profiling data
1390      struct profDataEntry *profData;
1391    
1392  };  };
1393    
1394  template <class IValueType>  template <class IValueType>
# Line 730  Data::initialise(const IValueType& value Line 1404  Data::initialise(const IValueType& value
1404    // within the shared_ptr constructor.    // within the shared_ptr constructor.
1405    if (expanded) {    if (expanded) {
1406      DataAbstract* temp=new DataExpanded(value,what);      DataAbstract* temp=new DataExpanded(value,what);
1407      m_data=boost::shared_ptr<DataAbstract>(temp);      boost::shared_ptr<DataAbstract> temp_data(temp);
1408        m_data=temp_data;
1409    } else {    } else {
1410      DataAbstract* temp=new DataConstant(value,what);      DataAbstract* temp=new DataConstant(value,what);
1411      m_data=boost::shared_ptr<DataAbstract>(temp);      boost::shared_ptr<DataAbstract> temp_data(temp);
1412        m_data=temp_data;
1413    }    }
1414  }  }
1415    
1416  inline  /**
1417  DataAbstract::ValueType::value_type*     Binary Data object operators.
1418  Data::getSampleData(DataAbstract::ValueType::size_type sampleNo)  */
1419  {  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  
1420  {  {
1421    return m_data->toString();      return pow(y,x);
1422  }  };
1423    
1424  /**  /**
1425    \brief    \brief
1426    Operator+    Operator+
1427    Takes two Data objects.    Takes two Data objects.
1428  */  */
1429  Data operator+(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator+(const Data& left, const Data& right);
1430    
1431  /**  /**
1432    \brief    \brief
1433    Operator-    Operator-
1434    Takes two Data objects.    Takes two Data objects.
1435  */  */
1436  Data operator-(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator-(const Data& left, const Data& right);
1437    
1438  /**  /**
1439    \brief    \brief
1440    Operator*    Operator*
1441    Takes two Data objects.    Takes two Data objects.
1442  */  */
1443  Data operator*(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator*(const Data& left, const Data& right);
1444    
1445  /**  /**
1446    \brief    \brief
1447    Operator/    Operator/
1448    Takes two Data objects.    Takes two Data objects.
1449  */  */
1450  Data operator/(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator/(const Data& left, const Data& right);
1451    
1452  /**  /**
1453    \brief    \brief
# Line 806  Data operator/(const Data& left, const D Line 1455  Data operator/(const Data& left, const D
1455    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1456    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1457  */  */
1458  Data operator+(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator+(const Data& left, const boost::python::object& right);
1459    
1460  /**  /**
1461    \brief    \brief
# Line 814  Data operator+(const Data& left, const b Line 1463  Data operator+(const Data& left, const b
1463    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1464    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1465  */  */
1466  Data operator-(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator-(const Data& left, const boost::python::object& right);
1467    
1468  /**  /**
1469    \brief    \brief
# Line 822  Data operator-(const Data& left, const b Line 1471  Data operator-(const Data& left, const b
1471    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1472    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1473  */  */
1474  Data operator*(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator*(const Data& left, const boost::python::object& right);
1475    
1476  /**  /**
1477    \brief    \brief
# Line 830  Data operator*(const Data& left, const b Line 1479  Data operator*(const Data& left, const b
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 838  Data operator/(const Data& left, const b Line 1487  Data operator/(const Data& left, const b
1487    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1488    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1489  */  */
1490  Data operator+(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator+(const boost::python::object& left, const Data& right);
1491    
1492  /**  /**
1493    \brief    \brief
# Line 846  Data operator+(const boost::python::obje Line 1495  Data operator+(const boost::python::obje
1495    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1496    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1497  */  */
1498  Data operator-(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator-(const boost::python::object& left, const Data& right);
1499    
1500  /**  /**
1501    \brief    \brief
# Line 854  Data operator-(const boost::python::obje Line 1503  Data operator-(const boost::python::obje
1503    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1504    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1505  */  */
1506  Data operator*(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator*(const boost::python::object& left, const Data& right);
1507    
1508  /**  /**
1509    \brief    \brief
# Line 862  Data operator*(const boost::python::obje Line 1511  Data operator*(const boost::python::obje
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
1518    Output operator    Output operator
1519  */  */
1520  std::ostream& operator<<(std::ostream& o, const Data& data);  ESCRIPT_DLL_API std::ostream& operator<<(std::ostream& o, const Data& data);
1521    
1522    /**
1523      \brief
1524      Compute a tensor product of two Data objects
1525      \param arg0 - Input - Data object
1526      \param arg1 - Input - Data object
1527      \param axis_offset - Input - axis offset
1528      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1529    */
1530    ESCRIPT_DLL_API
1531    Data
1532    C_GeneralTensorProduct(Data& arg0,
1533                         Data& arg1,
1534                         int axis_offset=0,
1535                         int transpose=0);
1536    
1537  /**  /**
1538    \brief    \brief
# Line 876  std::ostream& operator<<(std::ostream& o Line 1540  std::ostream& operator<<(std::ostream& o
1540    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
1541    be relied on. Requires further implementation.    be relied on. Requires further implementation.
1542  */  */
1543  bool operator==(const Data& left, const Data& right);  //ESCRIPT_DLL_API bool operator==(const Data& left, const Data& right);
1544    
1545    /**
1546      \brief
1547      Perform the given binary operation with this and right as operands.
1548      Right is a Data object.
1549    */
1550  template <class BinaryFunction>  template <class BinaryFunction>
1551  inline  inline
1552  void  void
# Line 887  Data::binaryOp(const Data& right, Line 1556  Data::binaryOp(const Data& right,
1556     //     //
1557     // 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
1558     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1559       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1560     }     }
1561     //     //
1562     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 907  Data::binaryOp(const Data& right, Line 1576  Data::binaryOp(const Data& right,
1576     operandCheck(tempRight);     operandCheck(tempRight);
1577     //     //
1578     // ensure this has the right type for the RHS     // ensure this has the right type for the RHS
1579     typeMatch(tempRight);     typeMatchRight(tempRight);
1580     //     //
1581     // Need to cast to the concrete types so that the correct binaryOp     // Need to cast to the concrete types so that the correct binaryOp
1582     // is called.     // is called.
# Line 933  Data::binaryOp(const Data& right, Line 1602  Data::binaryOp(const Data& right,
1602         EsysAssert((rightC!=0), "Programming error - casting to DataConstant.");         EsysAssert((rightC!=0), "Programming error - casting to DataConstant.");
1603         escript::binaryOp(*leftC,*rightC,operation);         escript::binaryOp(*leftC,*rightC,operation);
1604       }       }
1605     } else {     } else if (isConstant()) {
      //  
      // can only be DataConstant  
1606       DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());       DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1607       DataConstant* rightC=dynamic_cast<DataConstant*>(tempRight.m_data.get());       DataConstant* rightC=dynamic_cast<DataConstant*>(tempRight.m_data.get());
1608       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");
1609       escript::binaryOp(*leftC,*rightC,operation);       escript::binaryOp(*leftC,*rightC,operation);
1610     }     }
1611       #if defined DOPROF
1612       profData->binary++;
1613       #endif
1614  }  }
1615    
1616  template <class BinaryFunction>  /**
1617      \brief
1618      Perform the given unary operation on other and return the result.
1619      Given operation is performed on each element of each data point, thus
1620      argument object is a rank n Data object, and returned object is a rank n
1621      Data object.
1622      Calls Data::unaryOp.
1623    */
1624    template <class UnaryFunction>
1625  inline  inline
1626  void  Data
1627  Data::binaryOp(const boost::python::object& right,  unaryOp(const Data& other,
1628                 BinaryFunction operation)          UnaryFunction operation)
1629  {  {
1630     DataArray temp(right);    Data result;
1631     //    result.copy(other);
1632     // if this has a rank of zero promote it to the rank of the RHS.    result.unaryOp(operation);
1633     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);  
    }  
1634  }  }
1635    
1636    /**
1637      \brief
1638      Perform the given unary operation on this.
1639      Given operation is performed on each element of each data point.
1640      Calls escript::unaryOp.
1641    */
1642  template <class UnaryFunction>  template <class UnaryFunction>
1643  inline  inline
1644  void  void
1645  Data::unaryOp(UnaryFunction operation)  Data::unaryOp(UnaryFunction operation)
1646  {  {
1647    if (isExpanded()) {    if (isExpanded()) {
     //  
     // Expanded data will be done in parallel  
1648      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1649      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1650      escript::unaryOp(*leftC,operation);      escript::unaryOp(*leftC,operation);
# Line 998  Data::unaryOp(UnaryFunction operation) Line 1652  Data::unaryOp(UnaryFunction operation)
1652      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1653      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1654      escript::unaryOp(*leftC,operation);      escript::unaryOp(*leftC,operation);
1655    } else {    } else if (isConstant()) {
1656      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1657      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1658      escript::unaryOp(*leftC,operation);      escript::unaryOp(*leftC,operation);
1659    }    }
1660  }  }
1661    
1662  template <class UnaryFunction>  /**
1663      \brief
1664      Perform the given Data object reduction algorithm on this and return the result.
1665      Given operation combines each element of each data point, thus argument
1666      object (*this) is a rank n Data object, and returned object is a scalar.
1667      Calls escript::algorithm.
1668    */
1669    template <class BinaryFunction>
1670  inline  inline
1671  double  double
1672  Data::algorithm(UnaryFunction operation) const  Data::algorithm(BinaryFunction operation, double initial_value) const
1673  {  {
1674    if (isExpanded()) {    if (isExpanded()) {
     //  
     // Expanded data will be done in parallel  
1675      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1676      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1677      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1678    }    } else if (isTagged()) {
   else if (isTagged()) {  
1679      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1680      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1681      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1682    } else {    } else if (isConstant()) {
1683      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1684      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1685      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1686    }    }
1687      return 0;
1688  }  }
1689    
1690  template <class UnaryFunction>  /**
1691      \brief
1692      Perform the given data point reduction algorithm on data and return the result.
1693      Given operation combines each element within each data point into a scalar,
1694      thus argument object is a rank n Data object, and returned object is a
1695      rank 0 Data object.
1696      Calls escript::dp_algorithm.
1697    */
1698    template <class BinaryFunction>
1699  inline  inline
1700  Data  Data
1701  unaryOp(const Data& other,  Data::dp_algorithm(BinaryFunction operation, double initial_value) const
         UnaryFunction operation)  
1702  {  {
1703    //    if (isExpanded()) {
1704    // Perform the given operation on a copy of the input data and return the result      Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1705    Data result;      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
1706    //      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1707    // perform a deep copy      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1708    result.copy(other);      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1709    result.unaryOp(operation);      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
1710    return result;      return result;
1711      } else if (isTagged()) {
1712        DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1713        DataArrayView::ShapeType viewShape;
1714        DataArrayView::ValueType viewData(1);
1715        viewData[0]=0;
1716        DataArrayView defaultValue(viewData,viewShape);
1717        DataTagged::TagListType keys;
1718        DataTagged::ValueListType values;
1719        DataTagged::DataMapType::const_iterator i;
1720        for (i=dataT->getTagLookup().begin();i!=dataT->getTagLookup().end();i++) {
1721          keys.push_back(i->first);
1722          values.push_back(defaultValue);
1723        }
1724        Data result(keys,values,defaultValue,getFunctionSpace());
1725        DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1726        EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1727        EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1728        escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
1729        return result;
1730      } else if (isConstant()) {
1731        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1732        DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1733        DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1734        EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1735        EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1736        escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
1737        return result;
1738      }
1739      Data falseRetVal; // to keep compiler quiet
1740      return falseRetVal;
1741  }  }
1742    
1743  }  }
   
1744  #endif  #endif

Legend:
Removed from v.94  
changed lines
  Added in v.914

  ViewVC Help
Powered by ViewVC 1.1.26