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

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

  ViewVC Help
Powered by ViewVC 1.1.26