/[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

revision 474 by jgs, Mon Jan 30 04:23:44 2006 UTC revision 1137 by gross, Thu May 10 08:11:31 2007 UTC
# Line 1  Line 1 
1  // $Id$  // $Id$
2  /*  /*
3   ******************************************************************************   ************************************************************
4   *                                                                            *   *          Copyright 2006 by ACcESS MNRF                   *
5   *       COPYRIGHT ACcESS 2004 -  All Rights Reserved                         *   *                                                          *
6   *                                                                            *   *              http://www.access.edu.au                    *
7   * This software is the property of ACcESS.  No part of this code             *   *       Primary Business: Queensland, Australia            *
8   * may be copied in any form or by any means without the expressed written    *   *  Licensed under the Open Software License version 3.0    *
9   * consent of ACcESS.  Copying, use or modification of this software          *   *     http://www.opensource.org/licenses/osl-3.0.php       *
10   * by any unauthorised person is illegal unless that                          *   *                                                          *
11   * person has a software license agreement with ACcESS.                       *   ************************************************************
  *                                                                            *  
  ******************************************************************************  
12  */  */
13    
14  /** \file Data.h */  /** \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 "DataAbstract.h"  #include "DataAbstract.h"
 #include "DataTagged.h"  
21  #include "DataAlgorithm.h"  #include "DataAlgorithm.h"
22  #include "FunctionSpace.h"  #include "FunctionSpace.h"
23  #include "BinaryOp.h"  #include "BinaryOp.h"
# Line 28  Line 26 
26    
27  extern "C" {  extern "C" {
28  #include "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    
# Line 45  namespace escript { Line 45  namespace escript {
45    
46  //  //
47  // Forward declaration for various implementations of Data.  // Forward declaration for various implementations of Data.
 class DataEmpty;  
48  class DataConstant;  class DataConstant;
49  class DataTagged;  class DataTagged;
50  class DataExpanded;  class DataExpanded;
# Line 71  class Data { Line 70  class Data {
70    typedef double (*UnaryDFunPtr)(double);    typedef double (*UnaryDFunPtr)(double);
71    typedef double (*BinaryDFunPtr)(double,double);    typedef double (*BinaryDFunPtr)(double,double);
72    
73    
74    /**    /**
75       Constructors.       Constructors.
76    */    */
# Line 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(),
# Line 210  class Data { Line 222  class Data {
222       \brief       \brief
223       Destructor       Destructor
224    */    */
225      ESCRIPT_DLL_API
226    ~Data();    ~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 225  class Data { Line 239  class Data {
239    
240    /**    /**
241       \brief       \brief
242       Return the values of all data-points as a single python numarray object.       switches on update protection
243    
244    */    */
245    const boost::python::numeric::array    ESCRIPT_DLL_API
246    convertToNumArray();    void
247      setProtection();
248    
249    /**    /**
250       \brief       \brief
251       Return the values of all data-points for the given sample as a single python numarray object.       Returns trueif the data object is protected against update
252    
253    */    */
254    const boost::python::numeric::array    ESCRIPT_DLL_API
255    convertToNumArrayFromSampleNo(int sampleNo);    bool
256      isProtected() const;
257    
258    /**    /**
259       \brief       \brief
260       Return the value of the specified data-point as a single python numarray object.       Return the values of a data point on this process
261    */    */
262      ESCRIPT_DLL_API
263    const boost::python::numeric::array    const boost::python::numeric::array
264    convertToNumArrayFromDPNo(int sampleNo,    getValueOfDataPoint(int dataPointNo);
265                              int dataPointNo);  
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       \brief
276       Fills the expanded Data object from values of a python numarray object.       sets the values of a data-point from a numarray object on this process
277    */    */
278      ESCRIPT_DLL_API
279    void    void
280    fillFromNumArray(const boost::python::numeric::array);    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       \brief
# Line 259  class Data { Line 302  class Data {
302       The data-point number here corresponds to the data-point number in the       The data-point number here corresponds to the data-point number in the
303       numarray returned by convertToNumArray.       numarray returned by convertToNumArray.
304    */    */
305      ESCRIPT_DLL_API
306    int    int
307    getTagNumber(int dpno);    getTagNumber(int dpno);
308    
# Line 266  class Data { Line 310  class Data {
310       \brief       \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 273  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 280  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 293  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 304  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 312  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 320  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 327  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 334  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 341  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 348  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 359  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 366  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 377  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 384  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 393  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 406  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      inline
501      void
502      dump(const std::string fileName) const
503      {
504        return m_data->dump(fileName);
505      }
506    
507    /**    /**
508       \brief       \brief
# Line 419  class Data { Line 510  class Data {
510       preferred interface but is provided for use by C code.       preferred interface but is provided for use by C code.
511       \param sampleNo - Input - the given sample no.       \param sampleNo - Input - the given sample no.
512    */    */
513      ESCRIPT_DLL_API
514    inline    inline
515    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
516    getSampleData(DataAbstract::ValueType::size_type sampleNo)    getSampleData(DataAbstract::ValueType::size_type sampleNo)
# Line 432  class Data { Line 524  class Data {
524       access data that isn't tagged an exception will be thrown.       access data that isn't tagged an exception will be thrown.
525       \param tag - Input - the tag key.       \param tag - Input - the tag key.
526    */    */
527      ESCRIPT_DLL_API
528    inline    inline
529    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
530    getSampleDataByTag(int tag)    getSampleDataByTag(int tag)
# Line 441  class Data { Line 534  class Data {
534    
535    /**    /**
536       \brief       \brief
      Assign the given value to the data-points referenced by the given  
      reference number.  
   
      The value supplied is a python numarray object.  The data from this numarray  
      is unpacked into a DataArray, and this is used to set the corresponding  
      data-points in the underlying Data object.  
   
      If the underlying Data object cannot be accessed via reference numbers, an  
      exception will be thrown.  
   
      \param ref - Input - reference number.  
      \param value - Input - value to assign to data-points associated with  
                             the given reference number.  
   */  
   void  
   setRefValue(int ref,  
               const boost::python::numeric::array& value);  
   
   /**  
      \brief  
      Return the values associated with the data-points referenced by the given  
      reference number.  
   
      The value supplied is a python numarray object. The data from the corresponding  
      data-points in this Data object are packed into the given numarray object.  
   
      If the underlying Data object cannot be accessed via reference numbers, an  
      exception will be thrown.  
   
      \param ref - Input - reference number.  
      \param value - Output - object to receive values from data-points  
                              associated with the given reference number.  
   */  
   void  
   getRefValue(int ref,  
               boost::python::numeric::array& value);  
   
   /**  
      \brief  
537       Return a view into the data for the data point specified.       Return a view into the data for the data point specified.
538       NOTE: Construction of the DataArrayView is a relatively expensive       NOTE: Construction of the DataArrayView is a relatively expensive
539       operation.       operation.
540       \param sampleNo - Input -       \param sampleNo - Input -
541       \param dataPointNo - Input -       \param dataPointNo - Input -
542    */    */
543      ESCRIPT_DLL_API
544    inline    inline
545    DataArrayView    DataArrayView
546    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
547                 int dataPointNo)                 int dataPointNo)
548    {    {
549      return m_data->getDataPoint(sampleNo,dataPointNo);          return m_data->getDataPoint(sampleNo,dataPointNo);
550    }    }
551    
552    /**    /**
553       \brief       \brief
554       Return a reference to the data point shape.       Return a reference to the data point shape.
555    */    */
556      ESCRIPT_DLL_API
557    const DataArrayView::ShapeType&    const DataArrayView::ShapeType&
558    getDataPointShape() const;    getDataPointShape() const;
559    
# Line 505  class Data { Line 561  class Data {
561       \brief       \brief
562       Return the data point shape as a tuple of integers.       Return the data point shape as a tuple of integers.
563    */    */
564      ESCRIPT_DLL_API
565    const boost::python::tuple    const boost::python::tuple
566    getShapeTuple() const;    getShapeTuple() const;
567    
# Line 513  class Data { Line 570  class Data {
570       Return the size of the data point. It is the product of the       Return the size of the data point. It is the product of the
571       data point shape dimensions.       data point shape dimensions.
572    */    */
573      ESCRIPT_DLL_API
574    int    int
575    getDataPointSize() const;    getDataPointSize() const;
576    
# Line 520  class Data { Line 578  class Data {
578       \brief       \brief
579       Return the number of doubles stored for this Data.       Return the number of doubles stored for this Data.
580    */    */
581      ESCRIPT_DLL_API
582    DataArrayView::ValueType::size_type    DataArrayView::ValueType::size_type
583    getLength() const;    getLength() const;
584    
585    
586    
587      /**
588         \brief
589         Assign the given value to the tag assocciated with name. Implicitly converts this
590         object to type DataTagged. Throws an exception if this object
591         cannot be converted to a DataTagged object or name cannot be mapped onto a tag key.
592         \param tagKey - Input - Integer key.
593         \param value - Input - Value to associate with given key.
594        ==>*
595      */
596      ESCRIPT_DLL_API
597      void
598      setTaggedValueByName(std::string name,
599                           const boost::python::object& value);
600    
601    /**    /**
602       \brief       \brief
603       Assign the given value to the tag. Implicitly converts this       Assign the given value to the tag. Implicitly converts this
# Line 530  class Data { Line 605  class Data {
605       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
606       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
607       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
608        ==>*
609    */    */
610      ESCRIPT_DLL_API
611    void    void
612    setTaggedValue(int tagKey,    setTaggedValue(int tagKey,
613                   const boost::python::object& value);                   const boost::python::object& value);
# Line 542  class Data { Line 619  class Data {
619       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
620       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
621       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
622        ==>*
623    */    */
624      ESCRIPT_DLL_API
625    void    void
626    setTaggedValueFromCPP(int tagKey,    setTaggedValueFromCPP(int tagKey,
627                          const DataArrayView& value);                          const DataArrayView& value);
# Line 551  class Data { Line 630  class Data {
630      \brief      \brief
631      Copy other Data object into this Data object where mask is positive.      Copy other Data object into this Data object where mask is positive.
632    */    */
633      ESCRIPT_DLL_API
634    void    void
635    copyWithMask(const Data& other,    copyWithMask(const Data& other,
636                 const Data& mask);                 const Data& mask);
# Line 561  class Data { Line 641  class Data {
641    
642    /**    /**
643       \brief       \brief
644         set all values to zero
645         *
646      */
647      ESCRIPT_DLL_API
648      void
649      setToZero();
650    
651      /**
652         \brief
653       Interpolates this onto the given functionspace and returns       Interpolates this onto the given functionspace and returns
654       the result as a Data object.       the result as a Data object.
655       *       *
656    */    */
657      ESCRIPT_DLL_API
658    Data    Data
659    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
   
660    /**    /**
661       \brief       \brief
662       Calculates the gradient of the data at the data points of functionspace.       Calculates the gradient of the data at the data points of functionspace.
663       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.
664       *       *
665    */    */
666      ESCRIPT_DLL_API
667    Data    Data
668    gradOn(const FunctionSpace& functionspace) const;    gradOn(const FunctionSpace& functionspace) const;
669    
670      ESCRIPT_DLL_API
671    Data    Data
672    grad() const;    grad() const;
673    
# Line 585  class Data { Line 676  class Data {
676       Calculate the integral over the function space domain.       Calculate the integral over the function space domain.
677       *       *
678    */    */
679      ESCRIPT_DLL_API
680    boost::python::numeric::array    boost::python::numeric::array
681    integrate() const;    integrate() const;
682    
683    /**    /**
684       \brief       \brief
685         Returns 1./ Data object
686         *
687      */
688      ESCRIPT_DLL_API
689      Data
690      oneOver() const;
691      /**
692         \brief
693       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.
694       *       *
695    */    */
696      ESCRIPT_DLL_API
697    Data    Data
698    wherePositive() const;    wherePositive() const;
699    
# Line 601  class Data { Line 702  class Data {
702       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.
703       *       *
704    */    */
705      ESCRIPT_DLL_API
706    Data    Data
707    whereNegative() const;    whereNegative() const;
708    
# Line 609  class Data { Line 711  class Data {
711       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.
712       *       *
713    */    */
714      ESCRIPT_DLL_API
715    Data    Data
716    whereNonNegative() const;    whereNonNegative() const;
717    
# Line 617  class Data { Line 720  class Data {
720       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.
721       *       *
722    */    */
723      ESCRIPT_DLL_API
724    Data    Data
725    whereNonPositive() const;    whereNonPositive() const;
726    
# Line 625  class Data { Line 729  class Data {
729       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.
730       *       *
731    */    */
732      ESCRIPT_DLL_API
733    Data    Data
734    whereZero() const;    whereZero(double tol=0.0) const;
735    
736    /**    /**
737       \brief       \brief
738       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.
739       *       *
740    */    */
741      ESCRIPT_DLL_API
742    Data    Data
743    whereNonZero() const;    whereNonZero(double tol=0.0) const;
744    
745    /**    /**
746       \brief       \brief
747       Return the maximum absolute value of this Data object.       Return the maximum absolute value of this Data object.
748       *       *
749    */    */
750      ESCRIPT_DLL_API
751    double    double
752    Lsup() const;    Lsup() const;
753    
# Line 649  class Data { Line 756  class Data {
756       Return the minimum absolute value of this Data object.       Return the minimum absolute value of this Data object.
757       *       *
758    */    */
759      ESCRIPT_DLL_API
760    double    double
761    Linf() const;    Linf() const;
762    
# Line 657  class Data { Line 765  class Data {
765       Return the maximum value of this Data object.       Return the maximum value of this Data object.
766       *       *
767    */    */
768      ESCRIPT_DLL_API
769    double    double
770    sup() const;    sup() const;
771    
# Line 665  class Data { Line 774  class Data {
774       Return the minimum value of this Data object.       Return the minimum value of this Data object.
775       *       *
776    */    */
777      ESCRIPT_DLL_API
778    double    double
779    inf() const;    inf() const;
780    
# Line 673  class Data { Line 783  class Data {
783       Return the absolute value of each data point of this Data object.       Return the absolute value of each data point of this Data object.
784       *       *
785    */    */
786      ESCRIPT_DLL_API
787    Data    Data
788    abs() const;    abs() const;
789    
# Line 681  class Data { Line 792  class Data {
792       Return the maximum value of each data point of this Data object.       Return the maximum value of each data point of this Data object.
793       *       *
794    */    */
795      ESCRIPT_DLL_API
796    Data    Data
797    maxval() const;    maxval() const;
798    
# Line 689  class Data { Line 801  class Data {
801       Return the minimum value of each data point of this Data object.       Return the minimum value of each data point of this Data object.
802       *       *
803    */    */
804      ESCRIPT_DLL_API
805    Data    Data
806    minval() const;    minval() const;
807    
# Line 697  class Data { Line 810  class Data {
810       Return the (sample number, data-point number) of the data point with       Return the (sample number, data-point number) of the data point with
811       the minimum value in this Data object.       the minimum value in this Data object.
812    */    */
813      ESCRIPT_DLL_API
814    const boost::python::tuple    const boost::python::tuple
815    mindp() const;    minGlobalDataPoint() const;
816    
817      ESCRIPT_DLL_API
818    void    void
819    calc_mindp(int& SampleNo,    calc_minGlobalDataPoint(int& ProcNo,  int& DataPointNo) const;
              int& DataPointNo) const;  
   
820    /**    /**
821       \brief       \brief
822       Return the sign of each data point of this Data object.       Return the sign of each data point of this Data object.
823       -1 for negative values, zero for zero values, 1 for positive values.       -1 for negative values, zero for zero values, 1 for positive values.
824       *       *
825    */    */
826      ESCRIPT_DLL_API
827    Data    Data
828    sign() const;    sign() const;
829    
830    /**    /**
831       \brief       \brief
832         Return the symmetric part of a matrix which is half the matrix plus its transpose.
833         *
834      */
835      ESCRIPT_DLL_API
836      Data
837      symmetric() const;
838    
839      /**
840         \brief
841         Return the nonsymmetric part of a matrix which is half the matrix minus its transpose.
842         *
843      */
844      ESCRIPT_DLL_API
845      Data
846      nonsymmetric() const;
847    
848      /**
849         \brief
850         Return the trace of a matrix
851         *
852      */
853      ESCRIPT_DLL_API
854      Data
855      trace(int axis_offset) const;
856    
857      /**
858         \brief
859       Transpose each data point of this Data object around the given axis.       Transpose each data point of this Data object around the given axis.
      --* not implemented yet *--  
860       *       *
861    */    */
862      ESCRIPT_DLL_API
863    Data    Data
864    transpose(int axis) const;    transpose(int axis_offset) const;
865    
866    /**    /**
867       \brief       \brief
868       Calculate the trace of each data point of this Data object.       Return the eigenvalues of the symmetric part at each data point of this Data object in increasing values.
869       sum(A[i,i,i,i])       Currently this function is restricted to rank 2, square shape, and dimension 3.
870       *       *
871    */    */
872      ESCRIPT_DLL_API
873    Data    Data
874    trace() const;    eigenvalues() const;
875    
876      /**
877         \brief
878         Return the eigenvalues and corresponding eigenvcetors of the symmetric part at each data point of this Data object.
879         the eigenvalues are ordered in increasing size where eigenvalues with relative difference less than
880         tol are treated as equal. The eigenvectors are orthogonal, normalized and the sclaed such that the
881         first non-zero entry is positive.
882         Currently this function is restricted to rank 2, square shape, and dimension 3
883         *
884      */
885      ESCRIPT_DLL_API
886      const boost::python::tuple
887      eigenvalues_and_eigenvectors(const double tol=1.e-12) const;
888    
889      /**
890         \brief
891         swaps the components axis0 and axis1
892         *
893      */
894      ESCRIPT_DLL_API
895      Data
896      swapaxes(const int axis0, const int axis1) const;
897    
898      /**
899         \brief
900         Return the error function erf of each data point of this Data object.
901         *
902      */
903      ESCRIPT_DLL_API
904      Data
905      erf() const;
906    
907    /**    /**
908       \brief       \brief
909       Return the sin of each data point of this Data object.       Return the sin of each data point of this Data object.
910       *       *
911    */    */
912      ESCRIPT_DLL_API
913    Data    Data
914    sin() const;    sin() const;
915    
# Line 744  class Data { Line 918  class Data {
918       Return the cos of each data point of this Data object.       Return the cos of each data point of this Data object.
919       *       *
920    */    */
921      ESCRIPT_DLL_API
922    Data    Data
923    cos() const;    cos() const;
924    
# Line 752  class Data { Line 927  class Data {
927       Return the tan of each data point of this Data object.       Return the tan of each data point of this Data object.
928       *       *
929    */    */
930      ESCRIPT_DLL_API
931    Data    Data
932    tan() const;    tan() const;
933    
# Line 760  class Data { Line 936  class Data {
936       Return the asin of each data point of this Data object.       Return the asin of each data point of this Data object.
937       *       *
938    */    */
939      ESCRIPT_DLL_API
940    Data    Data
941    asin() const;    asin() const;
942    
# Line 768  class Data { Line 945  class Data {
945       Return the acos of each data point of this Data object.       Return the acos of each data point of this Data object.
946       *       *
947    */    */
948      ESCRIPT_DLL_API
949    Data    Data
950    acos() const;    acos() const;
951    
# Line 776  class Data { Line 954  class Data {
954       Return the atan of each data point of this Data object.       Return the atan of each data point of this Data object.
955       *       *
956    */    */
957      ESCRIPT_DLL_API
958    Data    Data
959    atan() const;    atan() const;
960    
# Line 784  class Data { Line 963  class Data {
963       Return the sinh of each data point of this Data object.       Return the sinh of each data point of this Data object.
964       *       *
965    */    */
966      ESCRIPT_DLL_API
967    Data    Data
968    sinh() const;    sinh() const;
969    
# Line 792  class Data { Line 972  class Data {
972       Return the cosh of each data point of this Data object.       Return the cosh of each data point of this Data object.
973       *       *
974    */    */
975      ESCRIPT_DLL_API
976    Data    Data
977    cosh() const;    cosh() const;
978    
# Line 800  class Data { Line 981  class Data {
981       Return the tanh of each data point of this Data object.       Return the tanh of each data point of this Data object.
982       *       *
983    */    */
984      ESCRIPT_DLL_API
985    Data    Data
986    tanh() const;    tanh() const;
987    
# Line 808  class Data { Line 990  class Data {
990       Return the asinh of each data point of this Data object.       Return the asinh of each data point of this Data object.
991       *       *
992    */    */
993      ESCRIPT_DLL_API
994    Data    Data
995    asinh() const;    asinh() const;
996    
# Line 816  class Data { Line 999  class Data {
999       Return the acosh of each data point of this Data object.       Return the acosh of each data point of this Data object.
1000       *       *
1001    */    */
1002      ESCRIPT_DLL_API
1003    Data    Data
1004    acosh() const;    acosh() const;
1005    
# Line 824  class Data { Line 1008  class Data {
1008       Return the atanh of each data point of this Data object.       Return the atanh of each data point of this Data object.
1009       *       *
1010    */    */
1011      ESCRIPT_DLL_API
1012    Data    Data
1013    atanh() const;    atanh() const;
1014    
# Line 832  class Data { Line 1017  class Data {
1017       Return the log to base 10 of each data point of this Data object.       Return the log to base 10 of each data point of this Data object.
1018       *       *
1019    */    */
1020      ESCRIPT_DLL_API
1021    Data    Data
1022    log10() const;    log10() const;
1023    
# Line 840  class Data { Line 1026  class Data {
1026       Return the natural log of each data point of this Data object.       Return the natural log of each data point of this Data object.
1027       *       *
1028    */    */
1029      ESCRIPT_DLL_API
1030    Data    Data
1031    log() const;    log() const;
1032    
# Line 848  class Data { Line 1035  class Data {
1035       Return the exponential function of each data point of this Data object.       Return the exponential function of each data point of this Data object.
1036       *       *
1037    */    */
1038      ESCRIPT_DLL_API
1039    Data    Data
1040    exp() const;    exp() const;
1041    
# Line 856  class Data { Line 1044  class Data {
1044       Return the square root of each data point of this Data object.       Return the square root of each data point of this Data object.
1045       *       *
1046    */    */
1047      ESCRIPT_DLL_API
1048    Data    Data
1049    sqrt() const;    sqrt() const;
1050    
# Line 864  class Data { Line 1053  class Data {
1053       Return the negation of each data point of this Data object.       Return the negation of each data point of this Data object.
1054       *       *
1055    */    */
1056      ESCRIPT_DLL_API
1057    Data    Data
1058    neg() const;    neg() const;
1059    
# Line 873  class Data { Line 1063  class Data {
1063       Simply returns this object unmodified.       Simply returns this object unmodified.
1064       *       *
1065    */    */
1066      ESCRIPT_DLL_API
1067    Data    Data
1068    pos() const;    pos() const;
1069    
# Line 883  class Data { Line 1074  class Data {
1074       \param right Input - the power to raise the object to.       \param right Input - the power to raise the object to.
1075       *       *
1076    */    */
1077      ESCRIPT_DLL_API
1078    Data    Data
1079    powD(const Data& right) const;    powD(const Data& right) const;
1080    
# Line 893  class Data { Line 1085  class Data {
1085       \param right Input - the power to raise the object to.       \param right Input - the power to raise the object to.
1086       *       *
1087     */     */
1088      ESCRIPT_DLL_API
1089    Data    Data
1090    powO(const boost::python::object& right) const;    powO(const boost::python::object& right) const;
1091    
1092    /**    /**
1093       \brief       \brief
1094         Return the given power of each data point of this boost python object.
1095        
1096         \param left Input - the bases
1097         *
1098       */
1099    
1100      ESCRIPT_DLL_API
1101      Data
1102      rpowO(const boost::python::object& left) const;
1103    
1104      /**
1105         \brief
1106       writes the object to a file in the DX file format       writes the object to a file in the DX file format
1107    */    */
1108      ESCRIPT_DLL_API
1109    void    void
1110    saveDX(std::string fileName) const;    saveDX(std::string fileName) const;
1111    
# Line 907  class Data { Line 1113  class Data {
1113       \brief       \brief
1114       writes the object to a file in the VTK file format       writes the object to a file in the VTK file format
1115    */    */
1116      ESCRIPT_DLL_API
1117    void    void
1118    saveVTK(std::string fileName) const;    saveVTK(std::string fileName) const;
1119    
# Line 916  class Data { Line 1123  class Data {
1123       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1124       *       *
1125    */    */
1126      ESCRIPT_DLL_API
1127    Data& operator+=(const Data& right);    Data& operator+=(const Data& right);
1128      ESCRIPT_DLL_API
1129    Data& operator+=(const boost::python::object& right);    Data& operator+=(const boost::python::object& right);
1130    
1131    /**    /**
# Line 925  class Data { Line 1134  class Data {
1134       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1135       *       *
1136    */    */
1137      ESCRIPT_DLL_API
1138    Data& operator-=(const Data& right);    Data& operator-=(const Data& right);
1139      ESCRIPT_DLL_API
1140    Data& operator-=(const boost::python::object& right);    Data& operator-=(const boost::python::object& right);
1141    
1142   /**   /**
# Line 934  class Data { Line 1145  class Data {
1145       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1146       *       *
1147    */    */
1148      ESCRIPT_DLL_API
1149    Data& operator*=(const Data& right);    Data& operator*=(const Data& right);
1150      ESCRIPT_DLL_API
1151    Data& operator*=(const boost::python::object& right);    Data& operator*=(const boost::python::object& right);
1152    
1153   /**   /**
# Line 943  class Data { Line 1156  class Data {
1156       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1157       *       *
1158    */    */
1159      ESCRIPT_DLL_API
1160    Data& operator/=(const Data& right);    Data& operator/=(const Data& right);
1161      ESCRIPT_DLL_API
1162    Data& operator/=(const boost::python::object& right);    Data& operator/=(const boost::python::object& right);
1163    
1164    /**    /**
1165       \brief       \brief
1166       Returns true if this can be interpolated to functionspace.       Returns true if this can be interpolated to functionspace.
1167    */    */
1168      ESCRIPT_DLL_API
1169    bool    bool
1170    probeInterpolation(const FunctionSpace& functionspace) const;    probeInterpolation(const FunctionSpace& functionspace) const;
1171    
# Line 968  class Data { Line 1184  class Data {
1184       \param key - Input - python slice tuple specifying       \param key - Input - python slice tuple specifying
1185       slice to return.       slice to return.
1186    */    */
1187      ESCRIPT_DLL_API
1188    Data    Data
1189    getItem(const boost::python::object& key) const;    getItem(const boost::python::object& key) const;
1190    
# Line 982  class Data { Line 1199  class Data {
1199       slice to copy from value.       slice to copy from value.
1200       \param value - Input - Data object to copy from.       \param value - Input - Data object to copy from.
1201    */    */
1202      ESCRIPT_DLL_API
1203    void    void
1204    setItemD(const boost::python::object& key,    setItemD(const boost::python::object& key,
1205             const Data& value);             const Data& value);
1206    
1207      ESCRIPT_DLL_API
1208    void    void
1209    setItemO(const boost::python::object& key,    setItemO(const boost::python::object& key,
1210             const boost::python::object& value);             const boost::python::object& value);
# Line 998  class Data { Line 1217  class Data {
1217       this Data object.       this Data object.
1218    */    */
1219    template <class UnaryFunction>    template <class UnaryFunction>
1220      ESCRIPT_DLL_API
1221    inline    inline
1222    void    void
1223    unaryOp(UnaryFunction operation);    unaryOp(UnaryFunction operation);
# Line 1009  class Data { Line 1229  class Data {
1229       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1230       *       *
1231    */    */
1232      ESCRIPT_DLL_API
1233    Data    Data
1234    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataArrayView::RegionType& region) const;
1235    
# Line 1020  class Data { Line 1241  class Data {
1241       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1242       *       *
1243    */    */
1244      ESCRIPT_DLL_API
1245    void    void
1246    setSlice(const Data& value,    setSlice(const Data& value,
1247             const DataArrayView::RegionType& region);             const DataArrayView::RegionType& region);
# Line 1029  class Data { Line 1251  class Data {
1251       Archive the current Data object to the given file.       Archive the current Data object to the given file.
1252       \param fileName - Input - file to archive to.       \param fileName - Input - file to archive to.
1253    */    */
1254      ESCRIPT_DLL_API
1255    void    void
1256    archiveData(const std::string fileName);    archiveData(const std::string fileName);
1257    
# Line 1040  class Data { Line 1263  class Data {
1263       \param fileName - Input - file to extract from.       \param fileName - Input - file to extract from.
1264       \param fspace - Input - a suitable FunctionSpace descibing the data.       \param fspace - Input - a suitable FunctionSpace descibing the data.
1265    */    */
1266      ESCRIPT_DLL_API
1267    void    void
1268    extractData(const std::string fileName,    extractData(const std::string fileName,
1269                const FunctionSpace& fspace);                const FunctionSpace& fspace);
1270    
1271    
1272      /**
1273         \brief
1274         print the data values to stdout. Used for debugging
1275      */
1276      ESCRIPT_DLL_API
1277      void
1278        print(void);
1279    
1280      /**
1281         \brief
1282         return the MPI rank number of the local data
1283             MPI_COMM_WORLD is assumed and the result of MPI_Comm_size()
1284             is returned
1285      */
1286      ESCRIPT_DLL_API
1287        int
1288        get_MPIRank(void) const;
1289    
1290      /**
1291         \brief
1292         return the MPI rank number of the local data
1293             MPI_COMM_WORLD is assumed and the result of MPI_Comm_rank()
1294             is returned
1295      */
1296      ESCRIPT_DLL_API
1297        int
1298        get_MPISize(void) const;
1299    
1300      /**
1301         \brief
1302         return the MPI rank number of the local data
1303             MPI_COMM_WORLD is assumed and returned.
1304      */
1305      ESCRIPT_DLL_API
1306        MPI_Comm
1307        get_MPIComm(void) const;
1308    
1309      /**
1310         \brief
1311         return the object produced by the factory, which is a DataConstant or DataExpanded
1312      */
1313      ESCRIPT_DLL_API
1314        DataAbstract*
1315        borrowData(void) const;
1316    
1317   protected:   protected:
1318    
1319   private:   private:
# Line 1101  class Data { Line 1371  class Data {
1371    
1372    /**    /**
1373       \brief       \brief
      Perform the given binary operation on all of the data's elements.  
      RHS is a boost::python object.  
   */  
   template <class BinaryFunction>  
   inline  
   void  
   binaryOp(const boost::python::object& right,  
            BinaryFunction operation);  
   
   /**  
      \brief  
1374       Convert the data type of the RHS to match this.       Convert the data type of the RHS to match this.
1375       \param right - Input - data type to match.       \param right - Input - data type to match.
1376    */    */
# Line 1136  class Data { Line 1395  class Data {
1395               const FunctionSpace& what,               const FunctionSpace& what,
1396               bool expanded);               bool expanded);
1397    
1398    /**    //
1399       \brief    // flag to protect the data object against any update
1400       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);  
1401    
1402    //    //
1403    // pointer to the actual data object    // pointer to the actual data object
1404    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
1405    
   //  
   // pointer to the internal profiling data  
   struct profDataEntry *profData;  
   
1406  };  };
1407    
1408  template <class IValueType>  template <class IValueType>
# Line 1181  Data::initialise(const IValueType& value Line 1430  Data::initialise(const IValueType& value
1430  /**  /**
1431     Binary Data object operators.     Binary Data object operators.
1432  */  */
1433    inline double rpow(double x,double y)
1434    {
1435        return pow(y,x);
1436    }
1437    
1438  /**  /**
1439    \brief    \brief
1440    Operator+    Operator+
1441    Takes two Data objects.    Takes two Data objects.
1442  */  */
1443  Data operator+(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator+(const Data& left, const Data& right);
1444    
1445  /**  /**
1446    \brief    \brief
1447    Operator-    Operator-
1448    Takes two Data objects.    Takes two Data objects.
1449  */  */
1450  Data operator-(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator-(const Data& left, const Data& right);
1451    
1452  /**  /**
1453    \brief    \brief
1454    Operator*    Operator*
1455    Takes two Data objects.    Takes two Data objects.
1456  */  */
1457  Data operator*(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator*(const Data& left, const Data& right);
1458    
1459  /**  /**
1460    \brief    \brief
1461    Operator/    Operator/
1462    Takes two Data objects.    Takes two Data objects.
1463  */  */
1464  Data operator/(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator/(const Data& left, const Data& right);
1465    
1466  /**  /**
1467    \brief    \brief
# Line 1216  Data operator/(const Data& left, const D Line 1469  Data operator/(const Data& left, const D
1469    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1470    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1471  */  */
1472  Data operator+(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator+(const Data& left, const boost::python::object& right);
1473    
1474  /**  /**
1475    \brief    \brief
# Line 1224  Data operator+(const Data& left, const b Line 1477  Data operator+(const Data& left, const b
1477    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1478    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1479  */  */
1480  Data operator-(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator-(const Data& left, const boost::python::object& right);
1481    
1482  /**  /**
1483    \brief    \brief
# Line 1232  Data operator-(const Data& left, const b Line 1485  Data operator-(const Data& left, const b
1485    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1486    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1487  */  */
1488  Data operator*(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator*(const Data& left, const boost::python::object& right);
1489    
1490  /**  /**
1491    \brief    \brief
# Line 1240  Data operator*(const Data& left, const b Line 1493  Data operator*(const Data& left, const b
1493    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1494    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1495  */  */
1496  Data operator/(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator/(const Data& left, const boost::python::object& right);
1497    
1498  /**  /**
1499    \brief    \brief
# Line 1248  Data operator/(const Data& left, const b Line 1501  Data operator/(const Data& left, const b
1501    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1502    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1503  */  */
1504  Data operator+(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator+(const boost::python::object& left, const Data& right);
1505    
1506  /**  /**
1507    \brief    \brief
# Line 1256  Data operator+(const boost::python::obje Line 1509  Data operator+(const boost::python::obje
1509    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1510    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1511  */  */
1512  Data operator-(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator-(const boost::python::object& left, const Data& right);
1513    
1514  /**  /**
1515    \brief    \brief
# Line 1264  Data operator-(const boost::python::obje Line 1517  Data operator-(const boost::python::obje
1517    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1518    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1519  */  */
1520  Data operator*(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator*(const boost::python::object& left, const Data& right);
1521    
1522  /**  /**
1523    \brief    \brief
# Line 1272  Data operator*(const boost::python::obje Line 1525  Data operator*(const boost::python::obje
1525    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1526    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1527  */  */
1528  Data operator/(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator/(const boost::python::object& left, const Data& right);
1529    
1530  /**  /**
1531    \brief    \brief
1532    Output operator    Output operator
1533  */  */
1534  std::ostream& operator<<(std::ostream& o, const Data& data);  ESCRIPT_DLL_API std::ostream& operator<<(std::ostream& o, const Data& data);
1535    
1536    /**
1537      \brief
1538      Compute a tensor product of two Data objects
1539      \param arg0 - Input - Data object
1540      \param arg1 - Input - Data object
1541      \param axis_offset - Input - axis offset
1542      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1543    */
1544    ESCRIPT_DLL_API
1545    Data
1546    C_GeneralTensorProduct(Data& arg0,
1547                         Data& arg1,
1548                         int axis_offset=0,
1549                         int transpose=0);
1550    
1551  /**  /**
1552    \brief    \brief
# Line 1286  std::ostream& operator<<(std::ostream& o Line 1554  std::ostream& operator<<(std::ostream& o
1554    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
1555    be relied on. Requires further implementation.    be relied on. Requires further implementation.
1556  */  */
1557  //bool operator==(const Data& left, const Data& right);  //ESCRIPT_DLL_API bool operator==(const Data& left, const Data& right);
1558    
1559  /**  /**
1560    \brief    \brief
# Line 1302  Data::binaryOp(const Data& right, Line 1570  Data::binaryOp(const Data& right,
1570     //     //
1571     // 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
1572     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1573       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1574     }     }
1575     //     //
1576     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1358  Data::binaryOp(const Data& right, Line 1626  Data::binaryOp(const Data& right,
1626    
1627  /**  /**
1628    \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  
1629    Perform the given unary operation on other and return the result.    Perform the given unary operation on other and return the result.
1630    Given operation is performed on each element of each data point, thus    Given operation is performed on each element of each data point, thus
1631    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 1483  inline Line 1711  inline
1711  Data  Data
1712  Data::dp_algorithm(BinaryFunction operation, double initial_value) const  Data::dp_algorithm(BinaryFunction operation, double initial_value) const
1713  {  {
   Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());  
1714    if (isExpanded()) {    if (isExpanded()) {
1715        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1716      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
1717      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1718      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1719      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1720      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
1721        return result;
1722    } else if (isTagged()) {    } else if (isTagged()) {
1723      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1724        DataArrayView::ShapeType viewShape;
1725        DataArrayView::ValueType viewData(1);
1726        viewData[0]=0;
1727        DataArrayView defaultValue(viewData,viewShape);
1728        DataTagged::TagListType keys;
1729        DataTagged::ValueListType values;
1730        DataTagged::DataMapType::const_iterator i;
1731        for (i=dataT->getTagLookup().begin();i!=dataT->getTagLookup().end();i++) {
1732          keys.push_back(i->first);
1733          values.push_back(defaultValue);
1734        }
1735        Data result(keys,values,defaultValue,getFunctionSpace());
1736      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1737      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1738      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1739      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
1740        return result;
1741    } else if (isConstant()) {    } else if (isConstant()) {
1742        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1743      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1744      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1745      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1746      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1747      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
1748        return result;
1749    }    }
1750    return result;    Data falseRetVal; // to keep compiler quiet
1751      return falseRetVal;
1752  }  }
1753    
1754  }  }

Legend:
Removed from v.474  
changed lines
  Added in v.1137

  ViewVC Help
Powered by ViewVC 1.1.26