/[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 97 by jgs, Tue Dec 14 05:39:33 2004 UTC trunk/escript/src/Data.h revision 1141 by gross, Tue May 15 04:24:51 2007 UTC
# Line 1  Line 1 
1  // $Id$  // $Id$
2  /*=============================================================================  /*
3     ************************************************************
4   ******************************************************************************   *          Copyright 2006 by ACcESS MNRF                   *
5   *                                                                            *   *                                                          *
6   *       COPYRIGHT ACcESS 2004 -  All Rights Reserved                         *   *              http://www.access.edu.au                    *
7   *                                                                            *   *       Primary Business: Queensland, Australia            *
8   * This software is the property of ACcESS.  No part of this code             *   *  Licensed under the Open Software License version 3.0    *
9   * may be copied in any form or by any means without the expressed written    *   *     http://www.opensource.org/licenses/osl-3.0.php       *
10   * consent of ACcESS.  Copying, use or modification of this software          *   *                                                          *
11   * by any unauthorised person is illegal unless that                          *   ************************************************************
12   * person has a software license agreement with ACcESS.                       *  */
  *                                                                            *  
  ******************************************************************************  
13    
14  ******************************************************************************/  /** \file Data.h */
15    
16  #ifndef DATA_H  #ifndef DATA_H
17  #define DATA_H  #define DATA_H
18    #include "system_dep.h"
19    
20  #include "escript/Data/DataAbstract.h"  #include "DataAbstract.h"
21  #include "escript/Data/DataTagged.h"  #include "DataAlgorithm.h"
22  #include "escript/Data/FunctionSpace.h"  #include "FunctionSpace.h"
23  #include "escript/Data/BinaryOp.h"  #include "BinaryOp.h"
24  #include "escript/Data/UnaryOp.h"  #include "UnaryOp.h"
25    #include "DataException.h"
26    
27  extern "C" {  extern "C" {
28  #include "escript/Data/DataC.h"  #include "DataC.h"
29    #include "paso/Paso.h"
30  }  }
31    
32  #include <iostream>  #ifndef PASO_MPI
33    #define MPI_Comm long
34    #endif
35    
36  #include <string>  #include <string>
 #include <memory>  
37  #include <algorithm>  #include <algorithm>
38    
39  #include <boost/shared_ptr.hpp>  #include <boost/shared_ptr.hpp>
40  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
 #include <boost/python/list.hpp>  
41  #include <boost/python/tuple.hpp>  #include <boost/python/tuple.hpp>
42  #include <boost/python/numeric.hpp>  #include <boost/python/numeric.hpp>
43    
44    namespace escript {
45    
46    //
47    // Forward declaration for various implementations of Data.
48    class DataConstant;
49    class DataTagged;
50    class DataExpanded;
51    
52  /**  /**
53     \brief     \brief
54     Data is essentially a factory class which creates the appropriate Data     Data creates the appropriate Data object for the given construction
55     object for the given construction arguments. It retains control over     arguments.
    the object created for the lifetime of the object.  
    The type of Data object referred to may change during the lifetime of  
    the Data object.  
56    
57     Description:     Description:
58     Data is essentially a factory class which creates the appropriate Data     Data is essentially a factory class which creates the appropriate Data
# Line 54  extern "C" { Line 61  extern "C" {
61     The type of Data object referred to may change during the lifetime of     The type of Data object referred to may change during the lifetime of
62     the Data object.     the Data object.
63  */  */
   
 namespace escript {  
   
 //  
 // Forward declaration for various implimentations of Data.  
 class DataEmpty;  
 class DataConstant;  
 class DataTagged;  
 class DataExpanded;  
   
64  class Data {  class Data {
65    
66    public:    public:
67    
68      // These typedefs allow function names to be cast to pointers
69      // to functions of the appropriate type when calling unaryOp etc.
70    typedef double (*UnaryDFunPtr)(double);    typedef double (*UnaryDFunPtr)(double);
71    typedef double (*BinaryDFunPtr)(double,double);    typedef double (*BinaryDFunPtr)(double,double);
72    
73    
74    /**    /**
75       Constructors.       Constructors.
76    */    */
# Line 80  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 87  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 95  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 108  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 123  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 135  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 150  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 167  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 182  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 195  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 202  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 220  class Data { Line 239  class Data {
239    
240    /**    /**
241       \brief       \brief
242         switches on update protection
243    
244      */
245      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      /**
259         \brief
260         Return the values of a data point on this process
261      */
262      ESCRIPT_DLL_API
263      const boost::python::numeric::array
264      getValueOfDataPoint(int dataPointNo);
265    
266      /**
267         \brief
268         sets the values of a data-point from a python object on this process
269      */
270      ESCRIPT_DLL_API
271      void
272      setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object);
273    
274      /**
275         \brief
276         sets the values of a data-point from a numarray object on this process
277      */
278      ESCRIPT_DLL_API
279      void
280      setValueOfDataPointToArray(int dataPointNo, const boost::python::numeric::array&);
281    
282      /**
283         \brief
284         sets the values of a data-point on this process
285      */
286      ESCRIPT_DLL_API
287      void
288      setValueOfDataPoint(int dataPointNo, const double);
289    
290      /**
291         \brief
292         Return the value of the specified data-point across all processors
293      */
294      ESCRIPT_DLL_API
295      const boost::python::numeric::array
296      getValueOfGlobalDataPoint(int procNo, int dataPointNo);
297    
298      /**
299         \brief
300         Return the tag number associated with the given data-point.
301    
302         The data-point number here corresponds to the data-point number in the
303         numarray returned by convertToNumArray.
304      */
305      ESCRIPT_DLL_API
306      int
307      getTagNumber(int dpno);
308    
309      /**
310         \brief
311       Return the C wrapper for the Data object.       Return the C wrapper for the Data object.
312    */    */
313      ESCRIPT_DLL_API
314    escriptDataC    escriptDataC
315    getDataC();    getDataC();
316    
# Line 229  class Data { Line 318  class Data {
318       \brief       \brief
319       Return the C wrapper for the Data object - const version.       Return the C wrapper for the Data object - const version.
320    */    */
321      ESCRIPT_DLL_API
322    escriptDataC    escriptDataC
323    getDataC() const;    getDataC() const;
324    
# Line 236  class Data { Line 326  class Data {
326       \brief       \brief
327       Write the data as a string.       Write the data as a string.
328    */    */
329      ESCRIPT_DLL_API
330    inline    inline
331    std::string    std::string
332    toString() const    toString() const
333    {    {
334      return m_data->toString();      return m_data->toString();
335    }    }
336      
337      /**
338         \brief
339         Return a description for this domain for python.
340      */
341      ESCRIPT_DLL_API
342      const boost::python::str str() const;
343    
344    /**    /**
345       \brief       \brief
# Line 249  class Data { Line 347  class Data {
347       the shape information for each data point although it also may be used       the shape information for each data point although it also may be used
348       to manipulate the point data.       to manipulate the point data.
349    */    */
350      ESCRIPT_DLL_API
351    inline    inline
352    const DataArrayView&    const DataArrayView&
353    getPointDataView() const    getPointDataView() const
# Line 260  class Data { Line 359  class Data {
359       \brief       \brief
360       Whatever the current Data type make this into a DataExpanded.       Whatever the current Data type make this into a DataExpanded.
361    */    */
362      ESCRIPT_DLL_API
363    void    void
364    expand();    expand();
365    
# Line 268  class Data { Line 368  class Data {
368       If possible convert this Data to DataTagged. This will only allow       If possible convert this Data to DataTagged. This will only allow
369       Constant data to be converted to tagged. An attempt to convert       Constant data to be converted to tagged. An attempt to convert
370       Expanded data to tagged will throw an exception.       Expanded data to tagged will throw an exception.
371        ==>*
372    */    */
373      ESCRIPT_DLL_API
374    void    void
375    tag();    tag();
376    
# Line 276  class Data { Line 378  class Data {
378       \brief       \brief
379       Return true if this Data is expanded.       Return true if this Data is expanded.
380    */    */
381      ESCRIPT_DLL_API
382    bool    bool
383    isExpanded() const;    isExpanded() const;
384    
# Line 283  class Data { Line 386  class Data {
386       \brief       \brief
387       Return true if this Data is tagged.       Return true if this Data is tagged.
388    */    */
389      ESCRIPT_DLL_API
390    bool    bool
391    isTagged() const;    isTagged() const;
392    
# Line 290  class Data { Line 394  class Data {
394       \brief       \brief
395       Return true if this Data is constant.       Return true if this Data is constant.
396    */    */
397      ESCRIPT_DLL_API
398    bool    bool
399    isConstant() const;    isConstant() const;
400    
# Line 297  class Data { Line 402  class Data {
402       \brief       \brief
403       Return true if this Data is empty.       Return true if this Data is empty.
404    */    */
405      ESCRIPT_DLL_API
406    bool    bool
407    isEmpty() const;    isEmpty() const;
408    
# Line 304  class Data { Line 410  class Data {
410       \brief       \brief
411       Return the function space.       Return the function space.
412    */    */
413      ESCRIPT_DLL_API
414    inline    inline
415    const FunctionSpace&    const FunctionSpace&
416    getFunctionSpace() const    getFunctionSpace() const
# Line 315  class Data { Line 422  class Data {
422       \brief       \brief
423       Return a copy of the function space.       Return a copy of the function space.
424    */    */
425      ESCRIPT_DLL_API
426    const FunctionSpace    const FunctionSpace
427    getCopyOfFunctionSpace() const;    getCopyOfFunctionSpace() const;
428    
# Line 322  class Data { Line 430  class Data {
430       \brief       \brief
431       Return the domain.       Return the domain.
432    */    */
433      ESCRIPT_DLL_API
434    inline    inline
435    const AbstractDomain&    const AbstractDomain&
436    getDomain() const    getDomain() const
# Line 333  class Data { Line 442  class Data {
442       \brief       \brief
443       Return a copy of the domain.       Return a copy of the domain.
444    */    */
445      ESCRIPT_DLL_API
446    const AbstractDomain    const AbstractDomain
447    getCopyOfDomain() const;    getCopyOfDomain() const;
448    
# Line 340  class Data { Line 450  class Data {
450       \brief       \brief
451       Return the rank of the point data.       Return the rank of the point data.
452    */    */
453      ESCRIPT_DLL_API
454    inline    inline
455    int    int
456    getDataPointRank() const    getDataPointRank() const
# Line 349  class Data { Line 460  class Data {
460    
461    /**    /**
462       \brief       \brief
463         Return the number of data points
464      */
465      ESCRIPT_DLL_API
466      inline
467      int
468      getNumDataPoints() const
469      {
470        return getNumSamples() * getNumDataPointsPerSample();
471      }
472      /**
473         \brief
474       Return the number of samples.       Return the number of samples.
475    */    */
476      ESCRIPT_DLL_API
477    inline    inline
478    int    int
479    getNumSamples() const    getNumSamples() const
# Line 362  class Data { Line 485  class Data {
485       \brief       \brief
486       Return the number of data points per sample.       Return the number of data points per sample.
487    */    */
488      ESCRIPT_DLL_API
489    inline    inline
490    int    int
491    getNumDataPointsPerSample() const    getNumDataPointsPerSample() const
492    {    {
493      return m_data->getNumDPPSample();      return m_data->getNumDPPSample();
494    }    }
495      /**
496         \brief
497         dumps the object into a netCDF file
498      */
499      ESCRIPT_DLL_API
500      void
501      dump(const std::string fileName) const;
502    /**    /**
503       \brief       \brief
504       Return the sample data for the given sample no. This is not the       Return the sample data for the given sample no. This is not the
505       preferred interface but is provided for use by C code.       preferred interface but is provided for use by C code.
506       \param sampleNo - Input - the given sample no.       \param sampleNo - Input - the given sample no.
507    */    */
508      ESCRIPT_DLL_API
509    inline    inline
510    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
511    getSampleData(DataAbstract::ValueType::size_type sampleNo)    getSampleData(DataAbstract::ValueType::size_type sampleNo)
# Line 388  class Data { Line 519  class Data {
519       access data that isn't tagged an exception will be thrown.       access data that isn't tagged an exception will be thrown.
520       \param tag - Input - the tag key.       \param tag - Input - the tag key.
521    */    */
522      ESCRIPT_DLL_API
523    inline    inline
524    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
525    getSampleDataByTag(int tag)    getSampleDataByTag(int tag)
# Line 403  class Data { Line 535  class Data {
535       \param sampleNo - Input -       \param sampleNo - Input -
536       \param dataPointNo - Input -       \param dataPointNo - Input -
537    */    */
538      ESCRIPT_DLL_API
539    inline    inline
540    DataArrayView    DataArrayView
541    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
542                 int dataPointNo)                 int dataPointNo)
543    {    {
544      return m_data->getDataPoint(sampleNo,dataPointNo);          return m_data->getDataPoint(sampleNo,dataPointNo);
545    }    }
546    
547    /**    /**
548       \brief       \brief
549       Return a reference to the data point shape.       Return a reference to the data point shape.
550    */    */
551      ESCRIPT_DLL_API
552    const DataArrayView::ShapeType&    const DataArrayView::ShapeType&
553    getDataPointShape() const;    getDataPointShape() const;
554    
# Line 422  class Data { Line 556  class Data {
556       \brief       \brief
557       Return the data point shape as a tuple of integers.       Return the data point shape as a tuple of integers.
558    */    */
559    boost::python::tuple    ESCRIPT_DLL_API
560      const boost::python::tuple
561    getShapeTuple() const;    getShapeTuple() const;
562    
563    /**    /**
# Line 430  class Data { Line 565  class Data {
565       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
566       data point shape dimensions.       data point shape dimensions.
567    */    */
568      ESCRIPT_DLL_API
569    int    int
570    getDataPointSize() const;    getDataPointSize() const;
571    
# Line 437  class Data { Line 573  class Data {
573       \brief       \brief
574       Return the number of doubles stored for this Data.       Return the number of doubles stored for this Data.
575    */    */
576      ESCRIPT_DLL_API
577    DataArrayView::ValueType::size_type    DataArrayView::ValueType::size_type
578    getLength() const;    getLength() const;
579    
580    
581    
582      /**
583         \brief
584         Assign the given value to the tag assocciated with name. Implicitly converts this
585         object to type DataTagged. Throws an exception if this object
586         cannot be converted to a DataTagged object or name cannot be mapped onto a tag key.
587         \param tagKey - Input - Integer key.
588         \param value - Input - Value to associate with given key.
589        ==>*
590      */
591      ESCRIPT_DLL_API
592      void
593      setTaggedValueByName(std::string name,
594                           const boost::python::object& value);
595    
596    /**    /**
597       \brief       \brief
598       Assign the given value to the tag. Implicitly converts this       Assign the given value to the tag. Implicitly converts this
# Line 447  class Data { Line 600  class Data {
600       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
601       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
602       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
603        ==>*
604    */    */
605      ESCRIPT_DLL_API
606    void    void
607    setTaggedValue(int tagKey,    setTaggedValue(int tagKey,
608                   const boost::python::object& value);                   const boost::python::object& value);
# Line 459  class Data { Line 614  class Data {
614       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
615       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
616       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
617       Note: removed for now - this version not needed, and breaks escript.cpp      ==>*
618    */    */
619    /*    ESCRIPT_DLL_API
620    void    void
621    setTaggedValue(int tagKey,    setTaggedValueFromCPP(int tagKey,
622                   const DataArrayView& value);                          const DataArrayView& value);
   */  
623    
624    /**    /**
625      \brief      \brief
626      Copy other Data object into this Data object where mask is positive.      Copy other Data object into this Data object where mask is positive.
627    */    */
628      ESCRIPT_DLL_API
629    void    void
630    copyWithMask(const Data& other,    copyWithMask(const Data& other,
631                 const Data& mask);                 const Data& mask);
# Line 481  class Data { Line 636  class Data {
636    
637    /**    /**
638       \brief       \brief
639         set all values to zero
640         *
641      */
642      ESCRIPT_DLL_API
643      void
644      setToZero();
645    
646      /**
647         \brief
648       Interpolates this onto the given functionspace and returns       Interpolates this onto the given functionspace and returns
649       the result as a Data object.       the result as a Data object.
650         *
651    */    */
652      ESCRIPT_DLL_API
653    Data    Data
654    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
   
655    /**    /**
656       \brief       \brief
657       Calculates the gradient of the data at the data points of functionspace.       Calculates the gradient of the data at the data points of functionspace.
658       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.
659         *
660    */    */
661      ESCRIPT_DLL_API
662    Data    Data
663    gradOn(const FunctionSpace& functionspace) const;    gradOn(const FunctionSpace& functionspace) const;
664    
665      ESCRIPT_DLL_API
666    Data    Data
667    grad() const;    grad() const;
668    
669    /**    /**
670       \brief       \brief
671       Calculate the integral over the function space domain.       Calculate the integral over the function space domain.
672         *
673    */    */
674      ESCRIPT_DLL_API
675    boost::python::numeric::array    boost::python::numeric::array
676    integrate() const;    integrate() const;
677    
678    /**    /**
679       \brief       \brief
680         Returns 1./ Data object
681         *
682      */
683      ESCRIPT_DLL_API
684      Data
685      oneOver() const;
686      /**
687         \brief
688       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.
689         *
690    */    */
691      ESCRIPT_DLL_API
692    Data    Data
693    wherePositive() const;    wherePositive() const;
694    
695    /**    /**
696       \brief       \brief
697       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.
698         *
699    */    */
700      ESCRIPT_DLL_API
701    Data    Data
702    whereNegative() const;    whereNegative() const;
703    
704    /**    /**
705       \brief       \brief
706       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.
707         *
708    */    */
709      ESCRIPT_DLL_API
710    Data    Data
711    whereNonNegative() const;    whereNonNegative() const;
712    
713    /**    /**
714       \brief       \brief
715       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.
716         *
717    */    */
718      ESCRIPT_DLL_API
719    Data    Data
720    whereNonPositive() const;    whereNonPositive() const;
721    
722    /**    /**
723       \brief       \brief
724       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.
725         *
726    */    */
727      ESCRIPT_DLL_API
728    Data    Data
729    whereZero() const;    whereZero(double tol=0.0) const;
730    
731    /**    /**
732       \brief       \brief
733       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.
734         *
735    */    */
736      ESCRIPT_DLL_API
737    Data    Data
738    whereNonZero() const;    whereNonZero(double tol=0.0) const;
739    
740      /**
741         \brief
742         Return the maximum absolute value of this Data object.
743         *
744      */
745      ESCRIPT_DLL_API
746      double
747      Lsup() const;
748    
749      /**
750         \brief
751         Return the minimum absolute value of this Data object.
752         *
753      */
754      ESCRIPT_DLL_API
755      double
756      Linf() const;
757    
758      /**
759         \brief
760         Return the maximum value of this Data object.
761         *
762      */
763      ESCRIPT_DLL_API
764      double
765      sup() const;
766    
767      /**
768         \brief
769         Return the minimum value of this Data object.
770         *
771      */
772      ESCRIPT_DLL_API
773      double
774      inf() const;
775    
776      /**
777         \brief
778         Return the absolute value of each data point of this Data object.
779         *
780      */
781      ESCRIPT_DLL_API
782      Data
783      abs() const;
784    
785      /**
786         \brief
787         Return the maximum value of each data point of this Data object.
788         *
789      */
790      ESCRIPT_DLL_API
791      Data
792      maxval() const;
793    
794      /**
795         \brief
796         Return the minimum value of each data point of this Data object.
797         *
798      */
799      ESCRIPT_DLL_API
800      Data
801      minval() const;
802    
803      /**
804         \brief
805         Return the (sample number, data-point number) of the data point with
806         the minimum value in this Data object.
807      */
808      ESCRIPT_DLL_API
809      const boost::python::tuple
810      minGlobalDataPoint() const;
811    
812      ESCRIPT_DLL_API
813      void
814      calc_minGlobalDataPoint(int& ProcNo,  int& DataPointNo) const;
815      /**
816         \brief
817         Return the sign of each data point of this Data object.
818         -1 for negative values, zero for zero values, 1 for positive values.
819         *
820      */
821      ESCRIPT_DLL_API
822      Data
823      sign() const;
824    
825      /**
826         \brief
827         Return the symmetric part of a matrix which is half the matrix plus its transpose.
828         *
829      */
830      ESCRIPT_DLL_API
831      Data
832      symmetric() const;
833    
834      /**
835         \brief
836         Return the nonsymmetric part of a matrix which is half the matrix minus its transpose.
837         *
838      */
839      ESCRIPT_DLL_API
840      Data
841      nonsymmetric() const;
842    
843      /**
844         \brief
845         Return the trace of a matrix
846         *
847      */
848      ESCRIPT_DLL_API
849      Data
850      trace(int axis_offset) const;
851    
852      /**
853         \brief
854         Transpose each data point of this Data object around the given axis.
855         *
856      */
857      ESCRIPT_DLL_API
858      Data
859      transpose(int axis_offset) const;
860    
861      /**
862         \brief
863         Return the eigenvalues of the symmetric part at each data point of this Data object in increasing values.
864         Currently this function is restricted to rank 2, square shape, and dimension 3.
865         *
866      */
867      ESCRIPT_DLL_API
868      Data
869      eigenvalues() const;
870    
871      /**
872         \brief
873         Return the eigenvalues and corresponding eigenvcetors of the symmetric part at each data point of this Data object.
874         the eigenvalues are ordered in increasing size where eigenvalues with relative difference less than
875         tol are treated as equal. The eigenvectors are orthogonal, normalized and the sclaed such that the
876         first non-zero entry is positive.
877         Currently this function is restricted to rank 2, square shape, and dimension 3
878         *
879      */
880      ESCRIPT_DLL_API
881      const boost::python::tuple
882      eigenvalues_and_eigenvectors(const double tol=1.e-12) const;
883    
884      /**
885         \brief
886         swaps the components axis0 and axis1
887         *
888      */
889      ESCRIPT_DLL_API
890      Data
891      swapaxes(const int axis0, const int axis1) const;
892    
893      /**
894         \brief
895         Return the error function erf of each data point of this Data object.
896         *
897      */
898      ESCRIPT_DLL_API
899      Data
900      erf() const;
901    
902    /**    /**
903       \brief       \brief
904       Return the sin of each data point of this Data object.       Return the sin of each data point of this Data object.
905         *
906    */    */
907      ESCRIPT_DLL_API
908    Data    Data
909    sin() const;    sin() const;
910    
911    /**    /**
912       \brief       \brief
913       Return the cos of each data point of this Data object.       Return the cos of each data point of this Data object.
914         *
915    */    */
916      ESCRIPT_DLL_API
917    Data    Data
918    cos() const;    cos() const;
919    
920    /**    /**
921       \brief       \brief
922       Return the tan of each data point of this Data object.       Return the tan of each data point of this Data object.
923         *
924    */    */
925      ESCRIPT_DLL_API
926    Data    Data
927    tan() const;    tan() const;
928    
929    /**    /**
930       \brief       \brief
931       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.
932         *
933    */    */
934      ESCRIPT_DLL_API
935    Data    Data
936    log() const;    asin() const;
937    
938    /**    /**
939       \brief       \brief
940       Return the natural log of each data point of this Data object.       Return the acos of each data point of this Data object.
941         *
942    */    */
943      ESCRIPT_DLL_API
944    Data    Data
945    ln() const;    acos() const;
946    
947    /**    /**
948       \brief       \brief
949       Return the maximum absolute value of this Data object.       Return the atan of each data point of this Data object.
950         *
951    */    */
952    double    ESCRIPT_DLL_API
953    Lsup() const;    Data
954      atan() const;
955    
956    /**    /**
957       \brief       \brief
958       Return the maximum value of this Data object.       Return the sinh of each data point of this Data object.
959         *
960    */    */
961    double    ESCRIPT_DLL_API
962    sup() const;    Data
963      sinh() const;
964    
965    /**    /**
966       \brief       \brief
967       Return the minimum value of this Data object.       Return the cosh of each data point of this Data object.
968         *
969    */    */
970    double    ESCRIPT_DLL_API
971    inf() const;    Data
972      cosh() const;
973    
974    /**    /**
975       \brief       \brief
976       Return the absolute value of each data point of this Data object.       Return the tanh of each data point of this Data object.
977         *
978    */    */
979      ESCRIPT_DLL_API
980    Data    Data
981    abs() const;    tanh() const;
982    
983    /**    /**
984       \brief       \brief
985       Return the maximum value of each data point of this Data object.       Return the asinh of each data point of this Data object.
986         *
987    */    */
988      ESCRIPT_DLL_API
989    Data    Data
990    maxval() const;    asinh() const;
991    
992    /**    /**
993       \brief       \brief
994       Return the minimum value of each data point of this Data object.       Return the acosh of each data point of this Data object.
995         *
996    */    */
997      ESCRIPT_DLL_API
998    Data    Data
999    minval() const;    acosh() const;
1000    
1001    /**    /**
1002       \brief       \brief
1003       Return the length of each data point of this Data object.       Return the atanh of each data point of this Data object.
1004       sqrt(sum(A[i,j,k,l]^2))       *
1005    */    */
1006      ESCRIPT_DLL_API
1007    Data    Data
1008    length() const;    atanh() const;
1009    
1010    /**    /**
1011       \brief       \brief
1012       Return the sign of each data point of this Data object.       Return the log to base 10 of each data point of this Data object.
1013       -1 for negative values, zero for zero values, 1 for positive values.       *
1014    */    */
1015      ESCRIPT_DLL_API
1016    Data    Data
1017    sign() const;    log10() const;
1018    
1019      /**
1020         \brief
1021         Return the natural log of each data point of this Data object.
1022         *
1023      */
1024      ESCRIPT_DLL_API
1025      Data
1026      log() const;
1027    
1028    /**    /**
1029      \transpose       \brief
1030      Transpose each data point of this Data object around the given axis.       Return the exponential function of each data point of this Data object.
1031         *
1032    */    */
1033      ESCRIPT_DLL_API
1034    Data    Data
1035    transpose(int axis) const;    exp() const;
1036    
1037    /**    /**
1038      \trace       \brief
1039      Calculate the trace of each data point of this Data object.       Return the square root of each data point of this Data object.
1040      sum(A[i,i,i,i])       *
1041    */    */
1042      ESCRIPT_DLL_API
1043    Data    Data
1044    trace() const;    sqrt() const;
1045    
1046    /**    /**
1047      \exp       \brief
1048      Return the exponential function of each data point of this Data object.       Return the negation of each data point of this Data object.
1049         *
1050    */    */
1051      ESCRIPT_DLL_API
1052    Data    Data
1053    exp() const;    neg() const;
1054    
1055    /**    /**
1056      \sqrt       \brief
1057      Return the square root of each data point of this Data object.       Return the identity of each data point of this Data object.
1058         Simply returns this object unmodified.
1059         *
1060    */    */
1061      ESCRIPT_DLL_API
1062    Data    Data
1063    sqrt() const;    pos() const;
1064    
1065    /**    /**
1066       \brief       \brief
1067       Return the given power of each data point of this Data object.       Return the given power of each data point of this Data object.
1068    
1069         \param right Input - the power to raise the object to.
1070         *
1071    */    */
1072      ESCRIPT_DLL_API
1073    Data    Data
1074    powD(const Data& right) const;    powD(const Data& right) const;
1075    
1076      /**
1077         \brief
1078         Return the given power of each data point of this boost python object.
1079        
1080         \param right Input - the power to raise the object to.
1081         *
1082       */
1083      ESCRIPT_DLL_API
1084    Data    Data
1085    powO(const boost::python::object& right) const;    powO(const boost::python::object& right) const;
1086    
1087    /**    /**
1088      \brief       \brief
1089      Return the negation of each data point of this Data object.       Return the given power of each data point of this boost python object.
1090    */      
1091         \param left Input - the bases
1092         *
1093       */
1094    
1095      ESCRIPT_DLL_API
1096    Data    Data
1097    neg() const;    rpowO(const boost::python::object& left) const;
1098    
1099    /**    /**
1100      \brief       \brief
1101      Return the identity of each data point of this Data object.       writes the object to a file in the DX file format
     Simply returns this object unmodified.  
1102    */    */
1103    Data    ESCRIPT_DLL_API
1104    pos() const;    void
1105      saveDX(std::string fileName) const;
1106    
1107      /**
1108         \brief
1109         writes the object to a file in the VTK file format
1110      */
1111      ESCRIPT_DLL_API
1112      void
1113      saveVTK(std::string fileName) const;
1114    
1115    /**    /**
1116       \brief       \brief
1117       Overloaded operator +=       Overloaded operator +=
1118       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1119         *
1120    */    */
1121      ESCRIPT_DLL_API
1122    Data& operator+=(const Data& right);    Data& operator+=(const Data& right);
1123      ESCRIPT_DLL_API
1124    Data& operator+=(const boost::python::object& right);    Data& operator+=(const boost::python::object& right);
1125    
1126    /**    /**
1127       \brief       \brief
1128       Overloaded operator -=       Overloaded operator -=
1129       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1130         *
1131    */    */
1132      ESCRIPT_DLL_API
1133    Data& operator-=(const Data& right);    Data& operator-=(const Data& right);
1134      ESCRIPT_DLL_API
1135    Data& operator-=(const boost::python::object& right);    Data& operator-=(const boost::python::object& right);
1136    
1137   /**   /**
1138       \brief       \brief
1139       Overloaded operator *=       Overloaded operator *=
1140       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1141         *
1142    */    */
1143      ESCRIPT_DLL_API
1144    Data& operator*=(const Data& right);    Data& operator*=(const Data& right);
1145      ESCRIPT_DLL_API
1146    Data& operator*=(const boost::python::object& right);    Data& operator*=(const boost::python::object& right);
1147    
1148   /**   /**
1149       \brief       \brief
1150       Overloaded operator /=       Overloaded operator /=
1151       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1152         *
1153    */    */
1154      ESCRIPT_DLL_API
1155    Data& operator/=(const Data& right);    Data& operator/=(const Data& right);
1156      ESCRIPT_DLL_API
1157    Data& operator/=(const boost::python::object& right);    Data& operator/=(const boost::python::object& right);
1158    
1159    /**    /**
1160       \brief       \brief
1161       Returns true if this can be interpolated to functionspace.       Returns true if this can be interpolated to functionspace.
1162    */    */
1163      ESCRIPT_DLL_API
1164    bool    bool
1165    probeInterpolation(const FunctionSpace& functionspace) const;    probeInterpolation(const FunctionSpace& functionspace) const;
1166    
# Line 748  class Data { Line 1179  class Data {
1179       \param key - Input - python slice tuple specifying       \param key - Input - python slice tuple specifying
1180       slice to return.       slice to return.
1181    */    */
1182      ESCRIPT_DLL_API
1183    Data    Data
1184    getItem(const boost::python::object& key) const;    getItem(const boost::python::object& key) const;
1185    
# Line 755  class Data { Line 1187  class Data {
1187       \brief       \brief
1188       Copies slice from value into this Data object.       Copies slice from value into this Data object.
1189    
      \description  
1190       Implements the [] set operator in python.       Implements the [] set operator in python.
1191       Calls setSlice.       Calls setSlice.
1192    
# Line 763  class Data { Line 1194  class Data {
1194       slice to copy from value.       slice to copy from value.
1195       \param value - Input - Data object to copy from.       \param value - Input - Data object to copy from.
1196    */    */
1197      ESCRIPT_DLL_API
1198    void    void
1199    setItemD(const boost::python::object& key,    setItemD(const boost::python::object& key,
1200             const Data& value);             const Data& value);
1201    
1202      ESCRIPT_DLL_API
1203    void    void
1204    setItemO(const boost::python::object& key,    setItemO(const boost::python::object& key,
1205             const boost::python::object& value);             const boost::python::object& value);
# Line 779  class Data { Line 1212  class Data {
1212       this Data object.       this Data object.
1213    */    */
1214    template <class UnaryFunction>    template <class UnaryFunction>
1215      ESCRIPT_DLL_API
1216    inline    inline
1217    void    void
1218    unaryOp(UnaryFunction operation);    unaryOp(UnaryFunction operation);
# Line 788  class Data { Line 1222  class Data {
1222       Return a Data object containing the specified slice of       Return a Data object containing the specified slice of
1223       this Data object.       this Data object.
1224       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1225         *
1226    */    */
1227      ESCRIPT_DLL_API
1228    Data    Data
1229    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataArrayView::RegionType& region) const;
1230    
# Line 798  class Data { Line 1234  class Data {
1234       Data object.       Data object.
1235       \param value - Input - Data to copy from.       \param value - Input - Data to copy from.
1236       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1237         *
1238    */    */
1239      ESCRIPT_DLL_API
1240    void    void
1241    setSlice(const Data& value,    setSlice(const Data& value,
1242             const DataArrayView::RegionType& region);             const DataArrayView::RegionType& region);
1243    
1244      /**
1245         \brief
1246         Archive the current Data object to the given file.
1247         \param fileName - Input - file to archive to.
1248      */
1249      ESCRIPT_DLL_API
1250      void
1251      archiveData(const std::string fileName);
1252    
1253      /**
1254         \brief
1255         Extract the Data object archived in the given file, overwriting
1256         the current Data object.
1257         Note - the current object must be of type DataEmpty.
1258         \param fileName - Input - file to extract from.
1259         \param fspace - Input - a suitable FunctionSpace descibing the data.
1260      */
1261      ESCRIPT_DLL_API
1262      void
1263      extractData(const std::string fileName,
1264                  const FunctionSpace& fspace);
1265    
1266    
1267      /**
1268         \brief
1269         print the data values to stdout. Used for debugging
1270      */
1271      ESCRIPT_DLL_API
1272      void
1273        print(void);
1274    
1275      /**
1276         \brief
1277         return the MPI rank number of the local data
1278             MPI_COMM_WORLD is assumed and the result of MPI_Comm_size()
1279             is returned
1280      */
1281      ESCRIPT_DLL_API
1282        int
1283        get_MPIRank(void) const;
1284    
1285      /**
1286         \brief
1287         return the MPI rank number of the local data
1288             MPI_COMM_WORLD is assumed and the result of MPI_Comm_rank()
1289             is returned
1290      */
1291      ESCRIPT_DLL_API
1292        int
1293        get_MPISize(void) const;
1294    
1295      /**
1296         \brief
1297         return the MPI rank number of the local data
1298             MPI_COMM_WORLD is assumed and returned.
1299      */
1300      ESCRIPT_DLL_API
1301        MPI_Comm
1302        get_MPIComm(void) const;
1303    
1304      /**
1305         \brief
1306         return the object produced by the factory, which is a DataConstant or DataExpanded
1307      */
1308      ESCRIPT_DLL_API
1309        DataAbstract*
1310        borrowData(void) const;
1311    
1312   protected:   protected:
1313    
1314   private:   private:
# Line 823  class Data { Line 1329  class Data {
1329    /**    /**
1330       \brief       \brief
1331       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
1332       this Data object and return the single double value result.       this Data object according to the given function and return the single value result.
1333    */    */
1334    template <class UnaryFunction>    template <class BinaryFunction>
1335    inline    inline
1336    double    double
1337    algorithm(UnaryFunction operation) const;    algorithm(BinaryFunction operation,
1338                double initial_value) const;
1339    
1340    /**    /**
1341       \brief       \brief
1342       Perform the given binary operation on all of the data's elements.       Reduce each data-point in this Data object using the given operation. Return a Data
1343       The underlying type of the right hand side (right) determines the final       object with the same number of data-points, but with each data-point containing only
1344       type of *this after the operation. For example if the right hand side       one value - the result of the reduction operation on the corresponding data-point in
1345       is expanded *this will be expanded if necessary.       this Data object
      RHS is a Data object.  
1346    */    */
1347    template <class BinaryFunction>    template <class BinaryFunction>
1348    inline    inline
1349    void    Data
1350    binaryOp(const Data& right,    dp_algorithm(BinaryFunction operation,
1351             BinaryFunction operation);                 double initial_value) const;
1352    
1353    /**    /**
1354       \brief       \brief
1355       Perform the given binary operation on all of the data's elements.       Perform the given binary operation on all of the data's elements.
1356       RHS is a boost::python object.       The underlying type of the right hand side (right) determines the final
1357         type of *this after the operation. For example if the right hand side
1358         is expanded *this will be expanded if necessary.
1359         RHS is a Data object.
1360    */    */
1361    template <class BinaryFunction>    template <class BinaryFunction>
1362    inline    inline
1363    void    void
1364    binaryOp(const boost::python::object& right,    binaryOp(const Data& right,
1365             BinaryFunction operation);             BinaryFunction operation);
1366    
1367    /**    /**
# Line 881  class Data { Line 1390  class Data {
1390               const FunctionSpace& what,               const FunctionSpace& what,
1391               bool expanded);               bool expanded);
1392    
1393    /**    //
1394       \brief    // flag to protect the data object against any update
1395       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);  
1396    
1397    //    //
1398    // pointer to the actual data object    // pointer to the actual data object
# Line 922  Data::initialise(const IValueType& value Line 1425  Data::initialise(const IValueType& value
1425  /**  /**
1426     Binary Data object operators.     Binary Data object operators.
1427  */  */
1428    inline double rpow(double x,double y)
1429    {
1430        return pow(y,x);
1431    }
1432    
1433  /**  /**
1434    \brief    \brief
1435    Operator+    Operator+
1436    Takes two Data objects.    Takes two Data objects.
1437  */  */
1438  Data operator+(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator+(const Data& left, const Data& right);
1439    
1440  /**  /**
1441    \brief    \brief
1442    Operator-    Operator-
1443    Takes two Data objects.    Takes two Data objects.
1444  */  */
1445  Data operator-(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator-(const Data& left, const Data& right);
1446    
1447  /**  /**
1448    \brief    \brief
1449    Operator*    Operator*
1450    Takes two Data objects.    Takes two Data objects.
1451  */  */
1452  Data operator*(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator*(const Data& left, const Data& right);
1453    
1454  /**  /**
1455    \brief    \brief
1456    Operator/    Operator/
1457    Takes two Data objects.    Takes two Data objects.
1458  */  */
1459  Data operator/(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator/(const Data& left, const Data& right);
1460    
1461  /**  /**
1462    \brief    \brief
# Line 957  Data operator/(const Data& left, const D Line 1464  Data operator/(const Data& left, const D
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 965  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 973  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 981  Data operator*(const Data& left, const b Line 1488  Data operator*(const Data& left, const b
1488    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1489    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1490  */  */
1491  Data operator/(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator/(const Data& left, const boost::python::object& right);
1492    
1493  /**  /**
1494    \brief    \brief
# Line 989  Data operator/(const Data& left, const b Line 1496  Data operator/(const Data& left, const b
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 997  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 1005  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
# Line 1013  Data operator*(const boost::python::obje Line 1520  Data operator*(const boost::python::obje
1520    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1521    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1522  */  */
1523  Data operator/(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator/(const boost::python::object& left, const Data& right);
1524    
1525  /**  /**
1526    \brief    \brief
1527    Output operator    Output operator
1528  */  */
1529  std::ostream& operator<<(std::ostream& o, const Data& data);  ESCRIPT_DLL_API std::ostream& operator<<(std::ostream& o, const Data& data);
1530    
1531    /**
1532      \brief
1533      Compute a tensor product of two Data objects
1534      \param arg0 - Input - Data object
1535      \param arg1 - Input - Data object
1536      \param axis_offset - Input - axis offset
1537      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1538    */
1539    ESCRIPT_DLL_API
1540    Data
1541    C_GeneralTensorProduct(Data& arg0,
1542                         Data& arg1,
1543                         int axis_offset=0,
1544                         int transpose=0);
1545    
1546  /**  /**
1547    \brief    \brief
# Line 1027  std::ostream& operator<<(std::ostream& o Line 1549  std::ostream& operator<<(std::ostream& o
1549    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
1550    be relied on. Requires further implementation.    be relied on. Requires further implementation.
1551  */  */
1552  //bool operator==(const Data& left, const Data& right);  //ESCRIPT_DLL_API bool operator==(const Data& left, const Data& right);
1553    
1554  /**  /**
1555    \brief    \brief
# Line 1043  Data::binaryOp(const Data& right, Line 1565  Data::binaryOp(const Data& right,
1565     //     //
1566     // 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
1567     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1568       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1569     }     }
1570     //     //
1571     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1099  Data::binaryOp(const Data& right, Line 1621  Data::binaryOp(const Data& right,
1621    
1622  /**  /**
1623    \brief    \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);  
    }  
 }  
   
 /**  
   \brief  
1624    Perform the given unary operation on other and return the result.    Perform the given unary operation on other and return the result.
1625    Given operation is performed on each element of each data point, thus    Given operation is performed on each element of each data point, thus
1626    argument object is a rank n Data object, and returned object is a rank n    argument object is a rank n Data object, and returned object is a rank n
# Line 1190  Data::unaryOp(UnaryFunction operation) Line 1672  Data::unaryOp(UnaryFunction operation)
1672    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.
1673    Calls escript::algorithm.    Calls escript::algorithm.
1674  */  */
1675  template <class UnaryFunction>  template <class BinaryFunction>
1676  inline  inline
1677  double  double
1678  Data::algorithm(UnaryFunction operation) const  Data::algorithm(BinaryFunction operation, double initial_value) const
1679  {  {
1680    if (isExpanded()) {    if (isExpanded()) {
1681      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1682      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1683      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1684    } else if (isTagged()) {    } else if (isTagged()) {
1685      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1686      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1687      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1688    } else if (isConstant()) {    } else if (isConstant()) {
1689      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1690      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1691      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1692    }    }
1693    return 0;    return 0;
1694  }  }
# Line 1219  Data::algorithm(UnaryFunction operation) Line 1701  Data::algorithm(UnaryFunction operation)
1701    rank 0 Data object.    rank 0 Data object.
1702    Calls escript::dp_algorithm.    Calls escript::dp_algorithm.
1703  */  */
1704  template <class UnaryFunction>  template <class BinaryFunction>
1705  inline  inline
1706  Data  Data
1707  dp_algorithm(const Data& data,  Data::dp_algorithm(BinaryFunction operation, double initial_value) const
              UnaryFunction operation)  
1708  {  {
1709    Data result(0,DataArrayView::ShapeType(),data.getFunctionSpace(),data.isExpanded());    if (isExpanded()) {
1710    if (data.isExpanded()) {      Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1711      DataExpanded* dataE=dynamic_cast<DataExpanded*>(data.m_data.get());      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
1712      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1713      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1714      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1715      escript::dp_algorithm(*dataE,*resultE,operation);      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
1716    } else if (data.isTagged()) {      return result;
1717      DataTagged* dataT=dynamic_cast<DataTagged*>(data.m_data.get());    } else if (isTagged()) {
1718        DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1719        DataArrayView::ShapeType viewShape;
1720        DataArrayView::ValueType viewData(1);
1721        viewData[0]=0;
1722        DataArrayView defaultValue(viewData,viewShape);
1723        DataTagged::TagListType keys;
1724        DataTagged::ValueListType values;
1725        DataTagged::DataMapType::const_iterator i;
1726        for (i=dataT->getTagLookup().begin();i!=dataT->getTagLookup().end();i++) {
1727          keys.push_back(i->first);
1728          values.push_back(defaultValue);
1729        }
1730        Data result(keys,values,defaultValue,getFunctionSpace());
1731      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1732      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1733      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1734      escript::dp_algorithm(*dataT,*resultT,operation);      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
1735    } else if (data.isConstant()) {      return result;
1736      DataConstant* dataC=dynamic_cast<DataConstant*>(data.m_data.get());    } else if (isConstant()) {
1737        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1738        DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1739      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1740      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1741      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1742      escript::dp_algorithm(*dataC,*resultC,operation);      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
1743        return result;
1744    }    }
1745    return result;    Data falseRetVal; // to keep compiler quiet
1746      return falseRetVal;
1747  }  }
1748    
1749  }  }

Legend:
Removed from v.97  
changed lines
  Added in v.1141

  ViewVC Help
Powered by ViewVC 1.1.26