/[escript]/branches/more_shared_ptrs_from_1812/escript/src/Data.h
ViewVC logotype

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

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

  ViewVC Help
Powered by ViewVC 1.1.26