/[escript]/trunk/escript/src/Data.h
ViewVC logotype

Diff of /trunk/escript/src/Data.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

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

  ViewVC Help
Powered by ViewVC 1.1.26