/[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 117 by jgs, Fri Apr 1 05:48:57 2005 UTC trunk/escript/src/Data.h revision 914 by gross, Thu Dec 14 04:38:18 2006 UTC
# Line 1  Line 1 
1  // $Id$  // $Id$
2  /*=============================================================================  /*
3     ************************************************************
4   ******************************************************************************   *          Copyright 2006 by ACcESS MNRF                   *
5   *                                                                            *   *                                                          *
6   *       COPYRIGHT ACcESS 2004 -  All Rights Reserved                         *   *              http://www.access.edu.au                    *
7   *                                                                            *   *       Primary Business: Queensland, Australia            *
8   * This software is the property of ACcESS.  No part of this code             *   *  Licensed under the Open Software License version 3.0    *
9   * may be copied in any form or by any means without the expressed written    *   *     http://www.opensource.org/licenses/osl-3.0.php       *
10   * consent of ACcESS.  Copying, use or modification of this software          *   *                                                          *
11   * by any unauthorised person is illegal unless that                          *   ************************************************************
12   * person has a software license agreement with ACcESS.                       *  */
  *                                                                            *  
  ******************************************************************************  
13    
14  ******************************************************************************/  /** \file Data.h */
15    
16  #ifndef DATA_H  #ifndef DATA_H
17  #define DATA_H  #define DATA_H
18    #include "system_dep.h"
19    
20  #include "escript/Data/DataAbstract.h"  #include "DataAbstract.h"
21  #include "escript/Data/DataTagged.h"  #include "DataAlgorithm.h"
22  #include "escript/Data/FunctionSpace.h"  #include "FunctionSpace.h"
23  #include "escript/Data/BinaryOp.h"  #include "BinaryOp.h"
24  #include "escript/Data/UnaryOp.h"  #include "UnaryOp.h"
25  #include "escript/Data/DataException.h"  #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 55  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:
# Line 74  class Data { Line 70  class Data {
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.       Constructors.
76    */    */
# Line 83  class Data { Line 80  class Data {
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 90  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    /**    /**
# Line 98  class Data { Line 97  class Data {
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 111  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 126  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 138  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 153  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 170  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 185  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 198  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 205  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
223         Destructor
224      */
225      ESCRIPT_DLL_API
226      ~Data();
227    
228    /**    /**
229       \brief       \brief
230       Perform a deep copy.       Perform a deep copy.
231    */    */
232      ESCRIPT_DLL_API
233    void    void
234    copy(const Data& other);    copy(const Data& other);
235    
# Line 223  class Data { Line 239  class Data {
239    
240    /**    /**
241       \brief       \brief
242       Return the values of all data-points in a single python numarray object.       switches on update protection
243    
244    */    */
245    boost::python::numeric::array    ESCRIPT_DLL_API
246      void
247      setProtection();
248    
249      /**
250         \brief
251         Returns trueif the data object is protected against update
252    
253      */
254      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();    convertToNumArray();
264    
265    /**    /**
266       \brief       \brief
267         Return the values of all data-points for the given sample as a single python numarray object.
268      */
269      ESCRIPT_DLL_API
270      const boost::python::numeric::array
271      convertToNumArrayFromSampleNo(int sampleNo);
272    
273      /**
274         \brief
275         Return the value of the specified data-point as a single python numarray object.
276      */
277      ESCRIPT_DLL_API
278      const boost::python::numeric::array
279      convertToNumArrayFromDPNo(int procNo,
280                    int sampleNo,
281                    int dataPointNo);
282      /**
283         \brief
284         Fills the expanded Data object from values of a python numarray object.
285      */
286      ESCRIPT_DLL_API
287      void
288      fillFromNumArray(const boost::python::numeric::array);
289    
290      /**
291         \brief
292         Return the tag number associated with the given data-point.
293    
294         The data-point number here corresponds to the data-point number in the
295         numarray returned by convertToNumArray.
296      */
297      ESCRIPT_DLL_API
298      int
299      getTagNumber(int dpno);
300    
301      /**
302         \brief
303       Return the C wrapper for the Data object.       Return the C wrapper for the Data object.
304    */    */
305      ESCRIPT_DLL_API
306    escriptDataC    escriptDataC
307    getDataC();    getDataC();
308    
# Line 239  class Data { Line 310  class Data {
310       \brief       \brief
311       Return the C wrapper for the Data object - const version.       Return the C wrapper for the Data object - const version.
312    */    */
313      ESCRIPT_DLL_API
314    escriptDataC    escriptDataC
315    getDataC() const;    getDataC() const;
316    
# Line 246  class Data { Line 318  class Data {
318       \brief       \brief
319       Write the data as a string.       Write the data as a string.
320    */    */
321      ESCRIPT_DLL_API
322    inline    inline
323    std::string    std::string
324    toString() const    toString() const
# Line 259  class Data { Line 332  class Data {
332       the shape information for each data point although it also may be used       the shape information for each data point although it also may be used
333       to manipulate the point data.       to manipulate the point data.
334    */    */
335      ESCRIPT_DLL_API
336    inline    inline
337    const DataArrayView&    const DataArrayView&
338    getPointDataView() const    getPointDataView() const
# Line 270  class Data { Line 344  class Data {
344       \brief       \brief
345       Whatever the current Data type make this into a DataExpanded.       Whatever the current Data type make this into a DataExpanded.
346    */    */
347      ESCRIPT_DLL_API
348    void    void
349    expand();    expand();
350    
# Line 278  class Data { Line 353  class Data {
353       If possible convert this Data to DataTagged. This will only allow       If possible convert this Data to DataTagged. This will only allow
354       Constant data to be converted to tagged. An attempt to convert       Constant data to be converted to tagged. An attempt to convert
355       Expanded data to tagged will throw an exception.       Expanded data to tagged will throw an exception.
356        ==>*
357    */    */
358      ESCRIPT_DLL_API
359    void    void
360    tag();    tag();
361    
# Line 286  class Data { Line 363  class Data {
363       \brief       \brief
364       Return true if this Data is expanded.       Return true if this Data is expanded.
365    */    */
366      ESCRIPT_DLL_API
367    bool    bool
368    isExpanded() const;    isExpanded() const;
369    
# Line 293  class Data { Line 371  class Data {
371       \brief       \brief
372       Return true if this Data is tagged.       Return true if this Data is tagged.
373    */    */
374      ESCRIPT_DLL_API
375    bool    bool
376    isTagged() const;    isTagged() const;
377    
# Line 300  class Data { Line 379  class Data {
379       \brief       \brief
380       Return true if this Data is constant.       Return true if this Data is constant.
381    */    */
382      ESCRIPT_DLL_API
383    bool    bool
384    isConstant() const;    isConstant() const;
385    
# Line 307  class Data { Line 387  class Data {
387       \brief       \brief
388       Return true if this Data is empty.       Return true if this Data is empty.
389    */    */
390      ESCRIPT_DLL_API
391    bool    bool
392    isEmpty() const;    isEmpty() const;
393    
# Line 314  class Data { Line 395  class Data {
395       \brief       \brief
396       Return the function space.       Return the function space.
397    */    */
398      ESCRIPT_DLL_API
399    inline    inline
400    const FunctionSpace&    const FunctionSpace&
401    getFunctionSpace() const    getFunctionSpace() const
# Line 325  class Data { Line 407  class Data {
407       \brief       \brief
408       Return a copy of the function space.       Return a copy of the function space.
409    */    */
410      ESCRIPT_DLL_API
411    const FunctionSpace    const FunctionSpace
412    getCopyOfFunctionSpace() const;    getCopyOfFunctionSpace() const;
413    
# Line 332  class Data { Line 415  class Data {
415       \brief       \brief
416       Return the domain.       Return the domain.
417    */    */
418      ESCRIPT_DLL_API
419    inline    inline
420    const AbstractDomain&    const AbstractDomain&
421    getDomain() const    getDomain() const
# Line 343  class Data { Line 427  class Data {
427       \brief       \brief
428       Return a copy of the domain.       Return a copy of the domain.
429    */    */
430      ESCRIPT_DLL_API
431    const AbstractDomain    const AbstractDomain
432    getCopyOfDomain() const;    getCopyOfDomain() const;
433    
# Line 350  class Data { Line 435  class Data {
435       \brief       \brief
436       Return the rank of the point data.       Return the rank of the point data.
437    */    */
438      ESCRIPT_DLL_API
439    inline    inline
440    int    int
441    getDataPointRank() const    getDataPointRank() const
# Line 361  class Data { Line 447  class Data {
447       \brief       \brief
448       Return the number of samples.       Return the number of samples.
449    */    */
450      ESCRIPT_DLL_API
451    inline    inline
452    int    int
453    getNumSamples() const    getNumSamples() const
# Line 372  class Data { Line 459  class Data {
459       \brief       \brief
460       Return the number of data points per sample.       Return the number of data points per sample.
461    */    */
462      ESCRIPT_DLL_API
463    inline    inline
464    int    int
465    getNumDataPointsPerSample() const    getNumDataPointsPerSample() const
# Line 385  class Data { Line 473  class Data {
473       preferred interface but is provided for use by C code.       preferred interface but is provided for use by C code.
474       \param sampleNo - Input - the given sample no.       \param sampleNo - Input - the given sample no.
475    */    */
476      ESCRIPT_DLL_API
477    inline    inline
478    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
479    getSampleData(DataAbstract::ValueType::size_type sampleNo)    getSampleData(DataAbstract::ValueType::size_type sampleNo)
# Line 398  class Data { Line 487  class Data {
487       access data that isn't tagged an exception will be thrown.       access data that isn't tagged an exception will be thrown.
488       \param tag - Input - the tag key.       \param tag - Input - the tag key.
489    */    */
490      ESCRIPT_DLL_API
491    inline    inline
492    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
493    getSampleDataByTag(int tag)    getSampleDataByTag(int tag)
# Line 421  class Data { Line 511  class Data {
511       \param value - Input - value to assign to data-points associated with       \param value - Input - value to assign to data-points associated with
512                              the given reference number.                              the given reference number.
513    */    */
514      ESCRIPT_DLL_API
515    void    void
516    setRefValue(int ref,    setRefValue(int ref,
517                const boost::python::numeric::array& value);                const boost::python::numeric::array& value);
# Line 440  class Data { Line 531  class Data {
531       \param value - Output - object to receive values from data-points       \param value - Output - object to receive values from data-points
532                               associated with the given reference number.                               associated with the given reference number.
533    */    */
534      ESCRIPT_DLL_API
535    void    void
536    getRefValue(int ref,    getRefValue(int ref,
537                boost::python::numeric::array& value);                boost::python::numeric::array& value);
# Line 452  class Data { Line 544  class Data {
544       \param sampleNo - Input -       \param sampleNo - Input -
545       \param dataPointNo - Input -       \param dataPointNo - Input -
546    */    */
547      ESCRIPT_DLL_API
548    inline    inline
549    DataArrayView    DataArrayView
550    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
551                 int dataPointNo)                 int dataPointNo)
552    {    {
553      return m_data->getDataPoint(sampleNo,dataPointNo);          return m_data->getDataPoint(sampleNo,dataPointNo);
554    }    }
555    
556    /**    /**
557       \brief       \brief
558       Return a reference to the data point shape.       Return a reference to the data point shape.
559    */    */
560      ESCRIPT_DLL_API
561    const DataArrayView::ShapeType&    const DataArrayView::ShapeType&
562    getDataPointShape() const;    getDataPointShape() const;
563    
# Line 471  class Data { Line 565  class Data {
565       \brief       \brief
566       Return the data point shape as a tuple of integers.       Return the data point shape as a tuple of integers.
567    */    */
568    boost::python::tuple    ESCRIPT_DLL_API
569      const boost::python::tuple
570    getShapeTuple() const;    getShapeTuple() const;
571    
572    /**    /**
# Line 479  class Data { Line 574  class Data {
574       Return the size of the data point. It is the product of the       Return the size of the data point. It is the product of the
575       data point shape dimensions.       data point shape dimensions.
576    */    */
577      ESCRIPT_DLL_API
578    int    int
579    getDataPointSize() const;    getDataPointSize() const;
580    
# Line 486  class Data { Line 582  class Data {
582       \brief       \brief
583       Return the number of doubles stored for this Data.       Return the number of doubles stored for this Data.
584    */    */
585      ESCRIPT_DLL_API
586    DataArrayView::ValueType::size_type    DataArrayView::ValueType::size_type
587    getLength() const;    getLength() const;
588    
# Line 496  class Data { Line 593  class Data {
593       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
594       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
595       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
596        ==>*
597    */    */
598      ESCRIPT_DLL_API
599    void    void
600    setTaggedValue(int tagKey,    setTaggedValue(int tagKey,
601                   const boost::python::object& value);                   const boost::python::object& value);
# Line 508  class Data { Line 607  class Data {
607       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
608       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
609       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
610       Note: removed for now - this version not needed, and breaks escript.cpp      ==>*
611    */    */
612    /*    ESCRIPT_DLL_API
613    void    void
614    setTaggedValue(int tagKey,    setTaggedValueFromCPP(int tagKey,
615                   const DataArrayView& value);                          const DataArrayView& value);
   */  
616    
617    /**    /**
618      \brief      \brief
619      Copy other Data object into this Data object where mask is positive.      Copy other Data object into this Data object where mask is positive.
620    */    */
621      ESCRIPT_DLL_API
622    void    void
623    copyWithMask(const Data& other,    copyWithMask(const Data& other,
624                 const Data& mask);                 const Data& mask);
# Line 532  class Data { Line 631  class Data {
631       \brief       \brief
632       Interpolates this onto the given functionspace and returns       Interpolates this onto the given functionspace and returns
633       the result as a Data object.       the result as a Data object.
634         *
635    */    */
636      ESCRIPT_DLL_API
637    Data    Data
638    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
639    
# Line 540  class Data { Line 641  class Data {
641       \brief       \brief
642       Calculates the gradient of the data at the data points of functionspace.       Calculates the gradient of the data at the data points of functionspace.
643       If functionspace is not present the function space of Function(getDomain()) is used.       If functionspace is not present the function space of Function(getDomain()) is used.
644         *
645    */    */
646      ESCRIPT_DLL_API
647    Data    Data
648    gradOn(const FunctionSpace& functionspace) const;    gradOn(const FunctionSpace& functionspace) const;
649    
650      ESCRIPT_DLL_API
651    Data    Data
652    grad() const;    grad() const;
653    
654    /**    /**
655       \brief       \brief
656       Calculate the integral over the function space domain.       Calculate the integral over the function space domain.
657         *
658    */    */
659      ESCRIPT_DLL_API
660    boost::python::numeric::array    boost::python::numeric::array
661    integrate() const;    integrate() const;
662    
663    /**    /**
664       \brief       \brief
665         Returns 1./ Data object
666         *
667      */
668      ESCRIPT_DLL_API
669      Data
670      oneOver() const;
671      /**
672         \brief
673       Return a Data with a 1 for +ive values and a 0 for 0 or -ive values.       Return a Data with a 1 for +ive values and a 0 for 0 or -ive values.
674         *
675    */    */
676      ESCRIPT_DLL_API
677    Data    Data
678    wherePositive() const;    wherePositive() const;
679    
680    /**    /**
681       \brief       \brief
682       Return a Data with a 1 for -ive values and a 0 for +ive or 0 values.       Return a Data with a 1 for -ive values and a 0 for +ive or 0 values.
683         *
684    */    */
685      ESCRIPT_DLL_API
686    Data    Data
687    whereNegative() const;    whereNegative() const;
688    
689    /**    /**
690       \brief       \brief
691       Return a Data with a 1 for +ive or 0 values and a 0 for -ive values.       Return a Data with a 1 for +ive or 0 values and a 0 for -ive values.
692         *
693    */    */
694      ESCRIPT_DLL_API
695    Data    Data
696    whereNonNegative() const;    whereNonNegative() const;
697    
698    /**    /**
699       \brief       \brief
700       Return a Data with a 1 for -ive or 0 values and a 0 for +ive values.       Return a Data with a 1 for -ive or 0 values and a 0 for +ive values.
701         *
702    */    */
703      ESCRIPT_DLL_API
704    Data    Data
705    whereNonPositive() const;    whereNonPositive() const;
706    
707    /**    /**
708       \brief       \brief
709       Return a Data with a 1 for 0 values and a 0 for +ive or -ive values.       Return a Data with a 1 for 0 values and a 0 for +ive or -ive values.
710         *
711    */    */
712      ESCRIPT_DLL_API
713    Data    Data
714    whereZero() const;    whereZero(double tol=0.0) const;
715    
716    /**    /**
717       \brief       \brief
718       Return a Data with a 0 for 0 values and a 1 for +ive or -ive values.       Return a Data with a 0 for 0 values and a 1 for +ive or -ive values.
719         *
720      */
721      ESCRIPT_DLL_API
722      Data
723      whereNonZero(double tol=0.0) const;
724    
725      /**
726         \brief
727         Return the maximum absolute value of this Data object.
728         *
729      */
730      ESCRIPT_DLL_API
731      double
732      Lsup() const;
733    
734      /**
735         \brief
736         Return the minimum absolute value of this Data object.
737         *
738      */
739      ESCRIPT_DLL_API
740      double
741      Linf() const;
742    
743      /**
744         \brief
745         Return the maximum value of this Data object.
746         *
747      */
748      ESCRIPT_DLL_API
749      double
750      sup() const;
751    
752      /**
753         \brief
754         Return the minimum value of this Data object.
755         *
756      */
757      ESCRIPT_DLL_API
758      double
759      inf() const;
760    
761      /**
762         \brief
763         Return the absolute value of each data point of this Data object.
764         *
765      */
766      ESCRIPT_DLL_API
767      Data
768      abs() const;
769    
770      /**
771         \brief
772         Return the maximum value of each data point of this Data object.
773         *
774      */
775      ESCRIPT_DLL_API
776      Data
777      maxval() const;
778    
779      /**
780         \brief
781         Return the minimum value of each data point of this Data object.
782         *
783      */
784      ESCRIPT_DLL_API
785      Data
786      minval() const;
787    
788      /**
789         \brief
790         Return the (sample number, data-point number) of the data point with
791         the minimum value in this Data object.
792      */
793      ESCRIPT_DLL_API
794      const boost::python::tuple
795      mindp() const;
796    
797      ESCRIPT_DLL_API
798      void
799      calc_mindp(int& ProcNo,
800                            int& SampleNo,  
801                 int& DataPointNo) const;
802      /**
803         \brief
804         Return the sign of each data point of this Data object.
805         -1 for negative values, zero for zero values, 1 for positive values.
806         *
807      */
808      ESCRIPT_DLL_API
809      Data
810      sign() const;
811    
812      /**
813         \brief
814         Return the symmetric part of a matrix which is half the matrix plus its transpose.
815         *
816      */
817      ESCRIPT_DLL_API
818      Data
819      symmetric() const;
820    
821      /**
822         \brief
823         Return the nonsymmetric part of a matrix which is half the matrix minus its transpose.
824         *
825      */
826      ESCRIPT_DLL_API
827      Data
828      nonsymmetric() const;
829    
830      /**
831         \brief
832         Return the trace of a matrix
833         *
834      */
835      ESCRIPT_DLL_API
836      Data
837      trace(int axis_offset) const;
838    
839      /**
840         \brief
841         Transpose each data point of this Data object around the given axis.
842         *
843      */
844      ESCRIPT_DLL_API
845      Data
846      transpose(int axis_offset) const;
847    
848      /**
849         \brief
850         Return the eigenvalues of the symmetric part at each data point of this Data object in increasing values.
851         Currently this function is restricted to rank 2, square shape, and dimension 3.
852         *
853      */
854      ESCRIPT_DLL_API
855      Data
856      eigenvalues() const;
857    
858      /**
859         \brief
860         Return the eigenvalues and corresponding eigenvcetors of the symmetric part at each data point of this Data object.
861         the eigenvalues are ordered in increasing size where eigenvalues with relative difference less than
862         tol are treated as equal. The eigenvectors are orthogonal, normalized and the sclaed such that the
863         first non-zero entry is positive.
864         Currently this function is restricted to rank 2, square shape, and dimension 3
865         *
866      */
867      ESCRIPT_DLL_API
868      const boost::python::tuple
869      eigenvalues_and_eigenvectors(const double tol=1.e-12) const;
870    
871      /**
872         \brief
873         swaps the components axis0 and axis1
874         *
875    */    */
876      ESCRIPT_DLL_API
877    Data    Data
878    whereNonZero() const;    swapaxes(const int axis0, const int axis1) const;
879    
880      /**
881         \brief
882         Return the error function erf of each data point of this Data object.
883         *
884      */
885      ESCRIPT_DLL_API
886      Data
887      erf() const;
888    
889    /**    /**
890       \brief       \brief
891       Return the sin of each data point of this Data object.       Return the sin of each data point of this Data object.
892         *
893    */    */
894      ESCRIPT_DLL_API
895    Data    Data
896    sin() const;    sin() const;
897    
898    /**    /**
899       \brief       \brief
900       Return the cos of each data point of this Data object.       Return the cos of each data point of this Data object.
901         *
902    */    */
903      ESCRIPT_DLL_API
904    Data    Data
905    cos() const;    cos() const;
906    
907    /**    /**
908       \brief       \brief
909       Return the tan of each data point of this Data object.       Return the tan of each data point of this Data object.
910         *
911    */    */
912      ESCRIPT_DLL_API
913    Data    Data
914    tan() const;    tan() const;
915    
916    /**    /**
917       \brief       \brief
918       Return the log to base 10 of each data point of this Data object.       Return the asin of each data point of this Data object.
919         *
920    */    */
921      ESCRIPT_DLL_API
922    Data    Data
923    log() const;    asin() const;
924    
925    /**    /**
926       \brief       \brief
927       Return the natural log of each data point of this Data object.       Return the acos of each data point of this Data object.
928         *
929    */    */
930      ESCRIPT_DLL_API
931    Data    Data
932    ln() const;    acos() const;
933    
934    /**    /**
935       \brief       \brief
936       Return the maximum absolute value of this Data object.       Return the atan of each data point of this Data object.
937         *
938    */    */
939    double    ESCRIPT_DLL_API
940    Lsup() const;    Data
941      atan() const;
942    
943    /**    /**
944       \brief       \brief
945       Return the minimum absolute value of this Data object.       Return the sinh of each data point of this Data object.
946         *
947    */    */
948    double    ESCRIPT_DLL_API
949    Linf() const;    Data
950      sinh() const;
951    
952    /**    /**
953       \brief       \brief
954       Return the maximum value of this Data object.       Return the cosh of each data point of this Data object.
955         *
956    */    */
957    double    ESCRIPT_DLL_API
958    sup() const;    Data
959      cosh() const;
960    
961    /**    /**
962       \brief       \brief
963       Return the minimum value of this Data object.       Return the tanh of each data point of this Data object.
964         *
965    */    */
966    double    ESCRIPT_DLL_API
967    inf() const;    Data
968      tanh() const;
969    
970    /**    /**
971       \brief       \brief
972       Return the absolute value of each data point of this Data object.       Return the asinh of each data point of this Data object.
973         *
974    */    */
975      ESCRIPT_DLL_API
976    Data    Data
977    abs() const;    asinh() const;
978    
979    /**    /**
980       \brief       \brief
981       Return the maximum value of each data point of this Data object.       Return the acosh of each data point of this Data object.
982         *
983    */    */
984      ESCRIPT_DLL_API
985    Data    Data
986    maxval() const;    acosh() const;
987    
988    /**    /**
989       \brief       \brief
990       Return the minimum value of each data point of this Data object.       Return the atanh of each data point of this Data object.
991         *
992    */    */
993      ESCRIPT_DLL_API
994    Data    Data
995    minval() const;    atanh() const;
996    
997    /**    /**
998       \brief       \brief
999       Return the length of each data point of this Data object.       Return the log to base 10 of each data point of this Data object.
1000       sqrt(sum(A[i,j,k,l]^2))       *
1001    */    */
1002      ESCRIPT_DLL_API
1003    Data    Data
1004    length() const;    log10() const;
1005    
1006    /**    /**
1007       \brief       \brief
1008       Return the sign of each data point of this Data object.       Return the natural log of each data point of this Data object.
1009       -1 for negative values, zero for zero values, 1 for positive values.       *
1010    */    */
1011      ESCRIPT_DLL_API
1012    Data    Data
1013    sign() const;    log() const;
1014    
1015    /**    /**
1016      \transpose       \brief
1017      Transpose each data point of this Data object around the given axis.       Return the exponential function of each data point of this Data object.
1018      --* not implemented yet *--       *
1019    */    */
1020      ESCRIPT_DLL_API
1021    Data    Data
1022    transpose(int axis) const;    exp() const;
1023    
1024    /**    /**
1025      \trace       \brief
1026      Calculate the trace of each data point of this Data object.       Return the square root of each data point of this Data object.
1027      sum(A[i,i,i,i])       *
1028    */    */
1029      ESCRIPT_DLL_API
1030    Data    Data
1031    trace() const;    sqrt() const;
1032    
1033    /**    /**
1034      \exp       \brief
1035      Return the exponential function of each data point of this Data object.       Return the negation of each data point of this Data object.
1036         *
1037    */    */
1038      ESCRIPT_DLL_API
1039    Data    Data
1040    exp() const;    neg() const;
1041    
1042    /**    /**
1043      \sqrt       \brief
1044      Return the square root of each data point of this Data object.       Return the identity of each data point of this Data object.
1045         Simply returns this object unmodified.
1046         *
1047    */    */
1048      ESCRIPT_DLL_API
1049    Data    Data
1050    sqrt() const;    pos() const;
1051    
1052    /**    /**
1053       \brief       \brief
1054       Return the given power of each data point of this Data object.       Return the given power of each data point of this Data object.
1055    
1056         \param right Input - the power to raise the object to.
1057         *
1058    */    */
1059      ESCRIPT_DLL_API
1060    Data    Data
1061    powD(const Data& right) const;    powD(const Data& right) const;
1062    
1063      /**
1064         \brief
1065         Return the given power of each data point of this boost python object.
1066        
1067         \param right Input - the power to raise the object to.
1068         *
1069       */
1070      ESCRIPT_DLL_API
1071    Data    Data
1072    powO(const boost::python::object& right) const;    powO(const boost::python::object& right) const;
1073    
1074    /**    /**
1075      \brief       \brief
1076      writes the object to a file in the DX file format       Return the given power of each data point of this boost python object.
1077        
1078         \param left Input - the bases
1079         *
1080       */
1081    
1082      ESCRIPT_DLL_API
1083      Data
1084      rpowO(const boost::python::object& left) const;
1085    
1086      /**
1087         \brief
1088         writes the object to a file in the DX file format
1089    */    */
1090      ESCRIPT_DLL_API
1091    void    void
1092    saveDX(std::string fileName) const;    saveDX(std::string fileName) const;
1093    
1094    /**    /**
1095      \brief       \brief
1096      writes the object to a file in the VTK file format       writes the object to a file in the VTK file format
1097    */    */
1098      ESCRIPT_DLL_API
1099    void    void
1100    saveVTK(std::string fileName) const;    saveVTK(std::string fileName) const;
1101    
1102    /**    /**
     \brief  
     Return the negation of each data point of this Data object.  
   */  
   Data  
   neg() const;  
   
   /**  
     \brief  
     Return the identity of each data point of this Data object.  
     Simply returns this object unmodified.  
   */  
   Data  
   pos() const;  
   
   /**  
1103       \brief       \brief
1104       Overloaded operator +=       Overloaded operator +=
1105       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1106         *
1107    */    */
1108      ESCRIPT_DLL_API
1109    Data& operator+=(const Data& right);    Data& operator+=(const Data& right);
1110      ESCRIPT_DLL_API
1111    Data& operator+=(const boost::python::object& right);    Data& operator+=(const boost::python::object& right);
1112    
1113    /**    /**
1114       \brief       \brief
1115       Overloaded operator -=       Overloaded operator -=
1116       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1117         *
1118    */    */
1119      ESCRIPT_DLL_API
1120    Data& operator-=(const Data& right);    Data& operator-=(const Data& right);
1121      ESCRIPT_DLL_API
1122    Data& operator-=(const boost::python::object& right);    Data& operator-=(const boost::python::object& right);
1123    
1124   /**   /**
1125       \brief       \brief
1126       Overloaded operator *=       Overloaded operator *=
1127       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1128         *
1129    */    */
1130      ESCRIPT_DLL_API
1131    Data& operator*=(const Data& right);    Data& operator*=(const Data& right);
1132      ESCRIPT_DLL_API
1133    Data& operator*=(const boost::python::object& right);    Data& operator*=(const boost::python::object& right);
1134    
1135   /**   /**
1136       \brief       \brief
1137       Overloaded operator /=       Overloaded operator /=
1138       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1139         *
1140    */    */
1141      ESCRIPT_DLL_API
1142    Data& operator/=(const Data& right);    Data& operator/=(const Data& right);
1143      ESCRIPT_DLL_API
1144    Data& operator/=(const boost::python::object& right);    Data& operator/=(const boost::python::object& right);
1145    
1146    /**    /**
1147       \brief       \brief
1148       Returns true if this can be interpolated to functionspace.       Returns true if this can be interpolated to functionspace.
1149    */    */
1150      ESCRIPT_DLL_API
1151    bool    bool
1152    probeInterpolation(const FunctionSpace& functionspace) const;    probeInterpolation(const FunctionSpace& functionspace) const;
1153    
# Line 819  class Data { Line 1166  class Data {
1166       \param key - Input - python slice tuple specifying       \param key - Input - python slice tuple specifying
1167       slice to return.       slice to return.
1168    */    */
1169      ESCRIPT_DLL_API
1170    Data    Data
1171    getItem(const boost::python::object& key) const;    getItem(const boost::python::object& key) const;
1172    
# Line 826  class Data { Line 1174  class Data {
1174       \brief       \brief
1175       Copies slice from value into this Data object.       Copies slice from value into this Data object.
1176    
      \description  
1177       Implements the [] set operator in python.       Implements the [] set operator in python.
1178       Calls setSlice.       Calls setSlice.
1179    
# Line 834  class Data { Line 1181  class Data {
1181       slice to copy from value.       slice to copy from value.
1182       \param value - Input - Data object to copy from.       \param value - Input - Data object to copy from.
1183    */    */
1184      ESCRIPT_DLL_API
1185    void    void
1186    setItemD(const boost::python::object& key,    setItemD(const boost::python::object& key,
1187             const Data& value);             const Data& value);
1188    
1189      ESCRIPT_DLL_API
1190    void    void
1191    setItemO(const boost::python::object& key,    setItemO(const boost::python::object& key,
1192             const boost::python::object& value);             const boost::python::object& value);
# Line 850  class Data { Line 1199  class Data {
1199       this Data object.       this Data object.
1200    */    */
1201    template <class UnaryFunction>    template <class UnaryFunction>
1202      ESCRIPT_DLL_API
1203    inline    inline
1204    void    void
1205    unaryOp(UnaryFunction operation);    unaryOp(UnaryFunction operation);
# Line 859  class Data { Line 1209  class Data {
1209       Return a Data object containing the specified slice of       Return a Data object containing the specified slice of
1210       this Data object.       this Data object.
1211       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1212         *
1213    */    */
1214      ESCRIPT_DLL_API
1215    Data    Data
1216    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataArrayView::RegionType& region) const;
1217    
# Line 869  class Data { Line 1221  class Data {
1221       Data object.       Data object.
1222       \param value - Input - Data to copy from.       \param value - Input - Data to copy from.
1223       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1224         *
1225    */    */
1226      ESCRIPT_DLL_API
1227    void    void
1228    setSlice(const Data& value,    setSlice(const Data& value,
1229             const DataArrayView::RegionType& region);             const DataArrayView::RegionType& region);
1230    
1231      /**
1232         \brief
1233         Archive the current Data object to the given file.
1234         \param fileName - Input - file to archive to.
1235      */
1236      ESCRIPT_DLL_API
1237      void
1238      archiveData(const std::string fileName);
1239    
1240      /**
1241         \brief
1242         Extract the Data object archived in the given file, overwriting
1243         the current Data object.
1244         Note - the current object must be of type DataEmpty.
1245         \param fileName - Input - file to extract from.
1246         \param fspace - Input - a suitable FunctionSpace descibing the data.
1247      */
1248      ESCRIPT_DLL_API
1249      void
1250      extractData(const std::string fileName,
1251                  const FunctionSpace& fspace);
1252    
1253    
1254      /**
1255         \brief
1256         print the data values to stdout. Used for debugging
1257      */
1258      ESCRIPT_DLL_API
1259      void
1260        print(void);
1261    
1262      /**
1263         \brief
1264         return the MPI rank number of the local data
1265             MPI_COMM_WORLD is assumed and the result of MPI_Comm_size()
1266             is returned
1267      */
1268      ESCRIPT_DLL_API
1269        int
1270        get_MPIRank(void) const;
1271    
1272      /**
1273         \brief
1274         return the MPI rank number of the local data
1275             MPI_COMM_WORLD is assumed and the result of MPI_Comm_rank()
1276             is returned
1277      */
1278      ESCRIPT_DLL_API
1279        int
1280        get_MPISize(void) const;
1281    
1282      /**
1283         \brief
1284         return the MPI rank number of the local data
1285             MPI_COMM_WORLD is assumed and returned.
1286      */
1287      ESCRIPT_DLL_API
1288        MPI_Comm
1289        get_MPIComm(void) const;
1290    
1291      /**
1292         \brief
1293         return the object produced by the factory, which is a DataConstant or DataExpanded
1294      */
1295      ESCRIPT_DLL_API
1296        DataAbstract*
1297        borrowData(void) const;
1298    
1299   protected:   protected:
1300    
1301   private:   private:
# Line 896  class Data { Line 1318  class Data {
1318       Perform the specified reduction algorithm on every element of every data point in       Perform the specified reduction algorithm on every element of every data point in
1319       this Data object according to the given function and return the single value result.       this Data object according to the given function and return the single value result.
1320    */    */
1321    template <class UnaryFunction>    template <class BinaryFunction>
1322    inline    inline
1323    double    double
1324    algorithm(UnaryFunction operation) const;    algorithm(BinaryFunction operation,
1325                double initial_value) const;
1326    
1327    /**    /**
1328       \brief       \brief
# Line 908  class Data { Line 1331  class Data {
1331       one value - the result of the reduction operation on the corresponding data-point in       one value - the result of the reduction operation on the corresponding data-point in
1332       this Data object       this Data object
1333    */    */
1334    template <class UnaryFunction>    template <class BinaryFunction>
1335    inline    inline
1336    Data    Data
1337    dp_algorithm(UnaryFunction operation) const;    dp_algorithm(BinaryFunction operation,
1338                   double initial_value) const;
1339    
1340    /**    /**
1341       \brief       \brief
# Line 929  class Data { Line 1353  class Data {
1353    
1354    /**    /**
1355       \brief       \brief
      Perform the given binary operation on all of the data's elements.  
      RHS is a boost::python object.  
   */  
   template <class BinaryFunction>  
   inline  
   void  
   binaryOp(const boost::python::object& right,  
            BinaryFunction operation);  
   
   /**  
      \brief  
1356       Convert the data type of the RHS to match this.       Convert the data type of the RHS to match this.
1357       \param right - Input - data type to match.       \param right - Input - data type to match.
1358    */    */
# Line 964  class Data { Line 1377  class Data {
1377               const FunctionSpace& what,               const FunctionSpace& what,
1378               bool expanded);               bool expanded);
1379    
1380    /**    //
1381       \brief    // flag to protect the data object against any update
1382       Reshape the data point if the data point is currently rank 0.    bool m_protected;
      Will throw an exception if the data points are not rank 0.  
      The original data point value is used for all values of the new  
      data point.  
   */  
   void  
   reshapeDataPoint(const DataArrayView::ShapeType& shape);  
1383    
1384    //    //
1385    // pointer to the actual data object    // pointer to the actual data object
1386    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
1387    
1388      //
1389      // pointer to the internal profiling data
1390      struct profDataEntry *profData;
1391    
1392  };  };
1393    
1394  template <class IValueType>  template <class IValueType>
# Line 1005  Data::initialise(const IValueType& value Line 1416  Data::initialise(const IValueType& value
1416  /**  /**
1417     Binary Data object operators.     Binary Data object operators.
1418  */  */
1419    inline double rpow(double x,double y)
1420    {
1421        return pow(y,x);
1422    };
1423    
1424  /**  /**
1425    \brief    \brief
1426    Operator+    Operator+
1427    Takes two Data objects.    Takes two Data objects.
1428  */  */
1429  Data operator+(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator+(const Data& left, const Data& right);
1430    
1431  /**  /**
1432    \brief    \brief
1433    Operator-    Operator-
1434    Takes two Data objects.    Takes two Data objects.
1435  */  */
1436  Data operator-(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator-(const Data& left, const Data& right);
1437    
1438  /**  /**
1439    \brief    \brief
1440    Operator*    Operator*
1441    Takes two Data objects.    Takes two Data objects.
1442  */  */
1443  Data operator*(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator*(const Data& left, const Data& right);
1444    
1445  /**  /**
1446    \brief    \brief
1447    Operator/    Operator/
1448    Takes two Data objects.    Takes two Data objects.
1449  */  */
1450  Data operator/(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator/(const Data& left, const Data& right);
1451    
1452  /**  /**
1453    \brief    \brief
# Line 1040  Data operator/(const Data& left, const D Line 1455  Data operator/(const Data& left, const D
1455    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1456    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1457  */  */
1458  Data operator+(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator+(const Data& left, const boost::python::object& right);
1459    
1460  /**  /**
1461    \brief    \brief
# Line 1048  Data operator+(const Data& left, const b Line 1463  Data operator+(const Data& left, const b
1463    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1464    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1465  */  */
1466  Data operator-(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator-(const Data& left, const boost::python::object& right);
1467    
1468  /**  /**
1469    \brief    \brief
# Line 1056  Data operator-(const Data& left, const b Line 1471  Data operator-(const Data& left, const b
1471    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1472    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1473  */  */
1474  Data operator*(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator*(const Data& left, const boost::python::object& right);
1475    
1476  /**  /**
1477    \brief    \brief
# Line 1064  Data operator*(const Data& left, const b Line 1479  Data operator*(const Data& left, const b
1479    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1480    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1481  */  */
1482  Data operator/(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator/(const Data& left, const boost::python::object& right);
1483    
1484  /**  /**
1485    \brief    \brief
# Line 1072  Data operator/(const Data& left, const b Line 1487  Data operator/(const Data& left, const b
1487    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1488    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1489  */  */
1490  Data operator+(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator+(const boost::python::object& left, const Data& right);
1491    
1492  /**  /**
1493    \brief    \brief
# Line 1080  Data operator+(const boost::python::obje Line 1495  Data operator+(const boost::python::obje
1495    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1496    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1497  */  */
1498  Data operator-(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator-(const boost::python::object& left, const Data& right);
1499    
1500  /**  /**
1501    \brief    \brief
# Line 1088  Data operator-(const boost::python::obje Line 1503  Data operator-(const boost::python::obje
1503    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1504    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1505  */  */
1506  Data operator*(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator*(const boost::python::object& left, const Data& right);
1507    
1508  /**  /**
1509    \brief    \brief
# Line 1096  Data operator*(const boost::python::obje Line 1511  Data operator*(const boost::python::obje
1511    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1512    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1513  */  */
1514  Data operator/(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator/(const boost::python::object& left, const Data& right);
1515    
1516  /**  /**
1517    \brief    \brief
1518    Output operator    Output operator
1519  */  */
1520  std::ostream& operator<<(std::ostream& o, const Data& data);  ESCRIPT_DLL_API std::ostream& operator<<(std::ostream& o, const Data& data);
1521    
1522    /**
1523      \brief
1524      Compute a tensor product of two Data objects
1525      \param arg0 - Input - Data object
1526      \param arg1 - Input - Data object
1527      \param axis_offset - Input - axis offset
1528      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1529    */
1530    ESCRIPT_DLL_API
1531    Data
1532    C_GeneralTensorProduct(Data& arg0,
1533                         Data& arg1,
1534                         int axis_offset=0,
1535                         int transpose=0);
1536    
1537  /**  /**
1538    \brief    \brief
# Line 1110  std::ostream& operator<<(std::ostream& o Line 1540  std::ostream& operator<<(std::ostream& o
1540    NB: this operator does very little at this point, and isn't to    NB: this operator does very little at this point, and isn't to
1541    be relied on. Requires further implementation.    be relied on. Requires further implementation.
1542  */  */
1543  //bool operator==(const Data& left, const Data& right);  //ESCRIPT_DLL_API bool operator==(const Data& left, const Data& right);
1544    
1545  /**  /**
1546    \brief    \brief
# Line 1126  Data::binaryOp(const Data& right, Line 1556  Data::binaryOp(const Data& right,
1556     //     //
1557     // if this has a rank of zero promote it to the rank of the RHS     // if this has a rank of zero promote it to the rank of the RHS
1558     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1559       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1560     }     }
1561     //     //
1562     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1178  Data::binaryOp(const Data& right, Line 1608  Data::binaryOp(const Data& right,
1608       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");
1609       escript::binaryOp(*leftC,*rightC,operation);       escript::binaryOp(*leftC,*rightC,operation);
1610     }     }
1611  }     #if defined DOPROF
1612       profData->binary++;
1613  /**     #endif
   \brief  
   Perform the given binary operation with this and right as operands.  
   Right is a boost::python object.  
 */  
 template <class BinaryFunction>  
 inline  
 void  
 Data::binaryOp(const boost::python::object& right,  
                BinaryFunction operation)  
 {  
    DataArray temp(right);  
    //  
    // if this has a rank of zero promote it to the rank of the RHS.  
    if (getPointDataView().getRank()==0 && temp.getView().getRank()!=0) {  
       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()) {  
      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 if (isConstant()) {  
      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());  
      EsysAssert((leftC!=0),"Programming error - casting to DataConstant.");  
      escript::binaryOp(*leftC,temp.getView(),operation);  
    }  
1614  }  }
1615    
1616  /**  /**
# Line 1273  Data::unaryOp(UnaryFunction operation) Line 1666  Data::unaryOp(UnaryFunction operation)
1666    object (*this) is a rank n Data object, and returned object is a scalar.    object (*this) is a rank n Data object, and returned object is a scalar.
1667    Calls escript::algorithm.    Calls escript::algorithm.
1668  */  */
1669  template <class UnaryFunction>  template <class BinaryFunction>
1670  inline  inline
1671  double  double
1672  Data::algorithm(UnaryFunction operation) const  Data::algorithm(BinaryFunction operation, double initial_value) const
1673  {  {
1674    if (isExpanded()) {    if (isExpanded()) {
1675      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1676      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1677      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1678    } else if (isTagged()) {    } else if (isTagged()) {
1679      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1680      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1681      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1682    } else if (isConstant()) {    } else if (isConstant()) {
1683      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1684      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1685      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1686    }    }
1687    return 0;    return 0;
1688  }  }
# Line 1302  Data::algorithm(UnaryFunction operation) Line 1695  Data::algorithm(UnaryFunction operation)
1695    rank 0 Data object.    rank 0 Data object.
1696    Calls escript::dp_algorithm.    Calls escript::dp_algorithm.
1697  */  */
1698  template <class UnaryFunction>  template <class BinaryFunction>
1699  inline  inline
1700  Data  Data
1701  Data::dp_algorithm(UnaryFunction operation) const  Data::dp_algorithm(BinaryFunction operation, double initial_value) const
1702  {  {
   Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());  
1703    if (isExpanded()) {    if (isExpanded()) {
1704        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1705      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
1706      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1707      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1708      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1709      escript::dp_algorithm(*dataE,*resultE,operation);      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
1710        return result;
1711    } else if (isTagged()) {    } else if (isTagged()) {
1712      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1713        DataArrayView::ShapeType viewShape;
1714        DataArrayView::ValueType viewData(1);
1715        viewData[0]=0;
1716        DataArrayView defaultValue(viewData,viewShape);
1717        DataTagged::TagListType keys;
1718        DataTagged::ValueListType values;
1719        DataTagged::DataMapType::const_iterator i;
1720        for (i=dataT->getTagLookup().begin();i!=dataT->getTagLookup().end();i++) {
1721          keys.push_back(i->first);
1722          values.push_back(defaultValue);
1723        }
1724        Data result(keys,values,defaultValue,getFunctionSpace());
1725      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1726      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1727      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1728      escript::dp_algorithm(*dataT,*resultT,operation);      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
1729        return result;
1730    } else if (isConstant()) {    } else if (isConstant()) {
1731        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1732      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1733      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1734      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1735      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1736      escript::dp_algorithm(*dataC,*resultC,operation);      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
1737        return result;
1738    }    }
1739    return result;    Data falseRetVal; // to keep compiler quiet
1740      return falseRetVal;
1741  }  }
1742    
1743  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26