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

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

  ViewVC Help
Powered by ViewVC 1.1.26