/[escript]/branches/more_shared_ptrs_from_1812/escript/src/Data.h
ViewVC logotype

Diff of /branches/more_shared_ptrs_from_1812/escript/src/Data.h

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

trunk/esys2/escript/src/Data/Data.h revision 121 by jgs, Fri May 6 04:26:16 2005 UTC trunk/escript/src/Data.h revision 1034 by gross, Wed Mar 14 23:49:20 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 "escript/Data/DataAbstract.h"  #include "DataAbstract.h"
21  #include "escript/Data/DataTagged.h"  #include "DataAlgorithm.h"
22  #include "escript/Data/FunctionSpace.h"  #include "FunctionSpace.h"
23  #include "escript/Data/BinaryOp.h"  #include "BinaryOp.h"
24  #include "escript/Data/UnaryOp.h"  #include "UnaryOp.h"
25  #include "escript/Data/DataException.h"  #include "DataException.h"
26    
27  extern "C" {  extern "C" {
28  #include "escript/Data/DataC.h"  #include "DataC.h"
29    #include "paso/Paso.h"
30  }  }
31    
32  #include <iostream>  #ifndef PASO_MPI
33    #define MPI_Comm long
34    #endif
35    
36  #include <string>  #include <string>
 #include <memory>  
37  #include <algorithm>  #include <algorithm>
38    
39  #include <boost/shared_ptr.hpp>  #include <boost/shared_ptr.hpp>
40  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
 #include <boost/python/list.hpp>  
41  #include <boost/python/tuple.hpp>  #include <boost/python/tuple.hpp>
42  #include <boost/python/numeric.hpp>  #include <boost/python/numeric.hpp>
43    
44  namespace escript {  namespace escript {
45    
46  //  //
47  // Forward declaration for various implimentations 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 70  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 79  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 86  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 94  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 107  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 122  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 134  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 149  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 166  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 181  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 194  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 201  class Data { Line 213  class Data {
213       \brief       \brief
214       Constructor which creates a DataConstant of "shape" with constant value.       Constructor which creates a DataConstant of "shape" with constant value.
215    */    */
216      ESCRIPT_DLL_API
217    Data(double value,    Data(double value,
218         const boost::python::tuple& shape=boost::python::make_tuple(),         const boost::python::tuple& shape=boost::python::make_tuple(),
219         const FunctionSpace& what=FunctionSpace(),         const FunctionSpace& what=FunctionSpace(),
220         bool expanded=false);         bool expanded=false);
221      /**
222         \brief
223         Destructor
224      */
225      ESCRIPT_DLL_API
226      ~Data();
227    
228    /**    /**
229       \brief       \brief
230       Perform a deep copy.       Perform a deep copy.
231    */    */
232      ESCRIPT_DLL_API
233    void    void
234    copy(const Data& other);    copy(const Data& other);
235    
# Line 219  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
251         Returns trueif the data object is protected against update
252    
253      */
254      ESCRIPT_DLL_API
255      bool
256      isProtected() const;
257    
258    /**    /**
259       \brief       \brief
260       Return the values of all data-points for the given sample 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    convertToNumArrayFromSampleNo(int sampleNo);    getValueOfDataPoint(int dataPointNo);
265    
266      /**
267         \brief
268         sets the values of a data-point from a python object on this process
269      */
270      ESCRIPT_DLL_API
271      void
272      setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object);
273    
274    /**    /**
275       \brief       \brief
276       Return the value of the specified data-point as a single python numarray object.       sets the values of a data-point from a numarray object on this process
277    */    */
278      ESCRIPT_DLL_API
279      void
280      setValueOfDataPointToArray(int dataPointNo, const boost::python::numeric::array&);
281    
282      /**
283         \brief
284         sets the values of a data-point on this process
285      */
286      ESCRIPT_DLL_API
287      void
288      setValueOfDataPoint(int dataPointNo, const double);
289    
290      /**
291         \brief
292         Return the value of the specified data-point across all processors
293      */
294      ESCRIPT_DLL_API
295    const boost::python::numeric::array    const boost::python::numeric::array
296    convertToNumArrayFromDPNo(int sampleNo,    getValueOfGlobalDataPoint(int procNo, int dataPointNo);
297                              int dataPointNo);  
298      /**
299         \brief
300         Return the tag number associated with the given data-point.
301    
302         The data-point number here corresponds to the data-point number in the
303         numarray returned by convertToNumArray.
304      */
305      ESCRIPT_DLL_API
306      int
307      getTagNumber(int dpno);
308    
309    /**    /**
310       \brief       \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 250  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 257  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
# Line 270  class Data { Line 340  class Data {
340       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
341       to manipulate the point data.       to manipulate the point data.
342    */    */
343      ESCRIPT_DLL_API
344    inline    inline
345    const DataArrayView&    const DataArrayView&
346    getPointDataView() const    getPointDataView() const
# Line 281  class Data { Line 352  class Data {
352       \brief       \brief
353       Whatever the current Data type make this into a DataExpanded.       Whatever the current Data type make this into a DataExpanded.
354    */    */
355      ESCRIPT_DLL_API
356    void    void
357    expand();    expand();
358    
# Line 289  class Data { Line 361  class Data {
361       If possible convert this Data to DataTagged. This will only allow       If possible convert this Data to DataTagged. This will only allow
362       Constant data to be converted to tagged. An attempt to convert       Constant data to be converted to tagged. An attempt to convert
363       Expanded data to tagged will throw an exception.       Expanded data to tagged will throw an exception.
364        ==>*
365    */    */
366      ESCRIPT_DLL_API
367    void    void
368    tag();    tag();
369    
# Line 297  class Data { Line 371  class Data {
371       \brief       \brief
372       Return true if this Data is expanded.       Return true if this Data is expanded.
373    */    */
374      ESCRIPT_DLL_API
375    bool    bool
376    isExpanded() const;    isExpanded() const;
377    
# Line 304  class Data { Line 379  class Data {
379       \brief       \brief
380       Return true if this Data is tagged.       Return true if this Data is tagged.
381    */    */
382      ESCRIPT_DLL_API
383    bool    bool
384    isTagged() const;    isTagged() const;
385    
# Line 311  class Data { Line 387  class Data {
387       \brief       \brief
388       Return true if this Data is constant.       Return true if this Data is constant.
389    */    */
390      ESCRIPT_DLL_API
391    bool    bool
392    isConstant() const;    isConstant() const;
393    
# Line 318  class Data { Line 395  class Data {
395       \brief       \brief
396       Return true if this Data is empty.       Return true if this Data is empty.
397    */    */
398      ESCRIPT_DLL_API
399    bool    bool
400    isEmpty() const;    isEmpty() const;
401    
# Line 325  class Data { Line 403  class Data {
403       \brief       \brief
404       Return the function space.       Return the function space.
405    */    */
406      ESCRIPT_DLL_API
407    inline    inline
408    const FunctionSpace&    const FunctionSpace&
409    getFunctionSpace() const    getFunctionSpace() const
# Line 336  class Data { Line 415  class Data {
415       \brief       \brief
416       Return a copy of the function space.       Return a copy of the function space.
417    */    */
418      ESCRIPT_DLL_API
419    const FunctionSpace    const FunctionSpace
420    getCopyOfFunctionSpace() const;    getCopyOfFunctionSpace() const;
421    
# Line 343  class Data { Line 423  class Data {
423       \brief       \brief
424       Return the domain.       Return the domain.
425    */    */
426      ESCRIPT_DLL_API
427    inline    inline
428    const AbstractDomain&    const AbstractDomain&
429    getDomain() const    getDomain() const
# Line 354  class Data { Line 435  class Data {
435       \brief       \brief
436       Return a copy of the domain.       Return a copy of the domain.
437    */    */
438      ESCRIPT_DLL_API
439    const AbstractDomain    const AbstractDomain
440    getCopyOfDomain() const;    getCopyOfDomain() const;
441    
# Line 361  class Data { Line 443  class Data {
443       \brief       \brief
444       Return the rank of the point data.       Return the rank of the point data.
445    */    */
446      ESCRIPT_DLL_API
447    inline    inline
448    int    int
449    getDataPointRank() const    getDataPointRank() const
# Line 370  class Data { Line 453  class Data {
453    
454    /**    /**
455       \brief       \brief
456         Return the number of data points
457      */
458      ESCRIPT_DLL_API
459      inline
460      int
461      getNumDataPoints() const
462      {
463        return getNumSamples() * getNumDataPointsPerSample();
464      }
465      /**
466         \brief
467       Return the number of samples.       Return the number of samples.
468    */    */
469      ESCRIPT_DLL_API
470    inline    inline
471    int    int
472    getNumSamples() const    getNumSamples() const
# Line 383  class Data { Line 478  class Data {
478       \brief       \brief
479       Return the number of data points per sample.       Return the number of data points per sample.
480    */    */
481      ESCRIPT_DLL_API
482    inline    inline
483    int    int
484    getNumDataPointsPerSample() const    getNumDataPointsPerSample() const
485    {    {
486      return m_data->getNumDPPSample();      return m_data->getNumDPPSample();
487    }    }
488      /**
489         \brief
490         dumps the object into a netCDF file
491      */
492      ESCRIPT_DLL_API
493      inline
494      void
495      dump(const std::string fileName) const
496      {
497        return m_data->dump(fileName);
498      }
499    
500    /**    /**
501       \brief       \brief
# Line 396  class Data { Line 503  class Data {
503       preferred interface but is provided for use by C code.       preferred interface but is provided for use by C code.
504       \param sampleNo - Input - the given sample no.       \param sampleNo - Input - the given sample no.
505    */    */
506      ESCRIPT_DLL_API
507    inline    inline
508    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
509    getSampleData(DataAbstract::ValueType::size_type sampleNo)    getSampleData(DataAbstract::ValueType::size_type sampleNo)
# Line 409  class Data { Line 517  class Data {
517       access data that isn't tagged an exception will be thrown.       access data that isn't tagged an exception will be thrown.
518       \param tag - Input - the tag key.       \param tag - Input - the tag key.
519    */    */
520      ESCRIPT_DLL_API
521    inline    inline
522    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
523    getSampleDataByTag(int tag)    getSampleDataByTag(int tag)
# Line 418  class Data { Line 527  class Data {
527    
528    /**    /**
529       \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  
530       Return a view into the data for the data point specified.       Return a view into the data for the data point specified.
531       NOTE: Construction of the DataArrayView is a relatively expensive       NOTE: Construction of the DataArrayView is a relatively expensive
532       operation.       operation.
533       \param sampleNo - Input -       \param sampleNo - Input -
534       \param dataPointNo - Input -       \param dataPointNo - Input -
535    */    */
536      ESCRIPT_DLL_API
537    inline    inline
538    DataArrayView    DataArrayView
539    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
540                 int dataPointNo)                 int dataPointNo)
541    {    {
542      return m_data->getDataPoint(sampleNo,dataPointNo);          return m_data->getDataPoint(sampleNo,dataPointNo);
543    }    }
544    
545    /**    /**
546       \brief       \brief
547       Return a reference to the data point shape.       Return a reference to the data point shape.
548    */    */
549      ESCRIPT_DLL_API
550    const DataArrayView::ShapeType&    const DataArrayView::ShapeType&
551    getDataPointShape() const;    getDataPointShape() const;
552    
# Line 482  class Data { Line 554  class Data {
554       \brief       \brief
555       Return the data point shape as a tuple of integers.       Return the data point shape as a tuple of integers.
556    */    */
557      ESCRIPT_DLL_API
558    const boost::python::tuple    const boost::python::tuple
559    getShapeTuple() const;    getShapeTuple() const;
560    
# Line 490  class Data { Line 563  class Data {
563       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
564       data point shape dimensions.       data point shape dimensions.
565    */    */
566      ESCRIPT_DLL_API
567    int    int
568    getDataPointSize() const;    getDataPointSize() const;
569    
# Line 497  class Data { Line 571  class Data {
571       \brief       \brief
572       Return the number of doubles stored for this Data.       Return the number of doubles stored for this Data.
573    */    */
574      ESCRIPT_DLL_API
575    DataArrayView::ValueType::size_type    DataArrayView::ValueType::size_type
576    getLength() const;    getLength() const;
577    
# Line 507  class Data { Line 582  class Data {
582       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
583       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
584       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
585        ==>*
586    */    */
587      ESCRIPT_DLL_API
588    void    void
589    setTaggedValue(int tagKey,    setTaggedValue(int tagKey,
590                   const boost::python::object& value);                   const boost::python::object& value);
# Line 519  class Data { Line 596  class Data {
596       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
597       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
598       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
599        ==>*
600    */    */
601      ESCRIPT_DLL_API
602    void    void
603    setTaggedValueFromCPP(int tagKey,    setTaggedValueFromCPP(int tagKey,
604                          const DataArrayView& value);                          const DataArrayView& value);
# Line 528  class Data { Line 607  class Data {
607      \brief      \brief
608      Copy other Data object into this Data object where mask is positive.      Copy other Data object into this Data object where mask is positive.
609    */    */
610      ESCRIPT_DLL_API
611    void    void
612    copyWithMask(const Data& other,    copyWithMask(const Data& other,
613                 const Data& mask);                 const Data& mask);
# Line 540  class Data { Line 620  class Data {
620       \brief       \brief
621       Interpolates this onto the given functionspace and returns       Interpolates this onto the given functionspace and returns
622       the result as a Data object.       the result as a Data object.
623         *
624    */    */
625      ESCRIPT_DLL_API
626    Data    Data
627    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
628    
# Line 548  class Data { Line 630  class Data {
630       \brief       \brief
631       Calculates the gradient of the data at the data points of functionspace.       Calculates the gradient of the data at the data points of functionspace.
632       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.
633         *
634    */    */
635      ESCRIPT_DLL_API
636    Data    Data
637    gradOn(const FunctionSpace& functionspace) const;    gradOn(const FunctionSpace& functionspace) const;
638    
639      ESCRIPT_DLL_API
640    Data    Data
641    grad() const;    grad() const;
642    
643    /**    /**
644       \brief       \brief
645       Calculate the integral over the function space domain.       Calculate the integral over the function space domain.
646         *
647    */    */
648      ESCRIPT_DLL_API
649    boost::python::numeric::array    boost::python::numeric::array
650    integrate() const;    integrate() const;
651    
652    /**    /**
653       \brief       \brief
654         Returns 1./ Data object
655         *
656      */
657      ESCRIPT_DLL_API
658      Data
659      oneOver() const;
660      /**
661         \brief
662       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.
663         *
664    */    */
665      ESCRIPT_DLL_API
666    Data    Data
667    wherePositive() const;    wherePositive() const;
668    
669    /**    /**
670       \brief       \brief
671       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.
672         *
673    */    */
674      ESCRIPT_DLL_API
675    Data    Data
676    whereNegative() const;    whereNegative() const;
677    
678    /**    /**
679       \brief       \brief
680       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.
681         *
682    */    */
683      ESCRIPT_DLL_API
684    Data    Data
685    whereNonNegative() const;    whereNonNegative() const;
686    
687    /**    /**
688       \brief       \brief
689       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.
690         *
691    */    */
692      ESCRIPT_DLL_API
693    Data    Data
694    whereNonPositive() const;    whereNonPositive() const;
695    
696    /**    /**
697       \brief       \brief
698       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.
699         *
700    */    */
701      ESCRIPT_DLL_API
702    Data    Data
703    whereZero() const;    whereZero(double tol=0.0) const;
704    
705    /**    /**
706       \brief       \brief
707       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.
708         *
709    */    */
710      ESCRIPT_DLL_API
711    Data    Data
712    whereNonZero() const;    whereNonZero(double tol=0.0) const;
713    
714    /**    /**
715       \brief       \brief
716       Return the sin of each data point of this Data object.       Return the maximum absolute value of this Data object.
717         *
718      */
719      ESCRIPT_DLL_API
720      double
721      Lsup() const;
722    
723      /**
724         \brief
725         Return the minimum absolute value of this Data object.
726         *
727      */
728      ESCRIPT_DLL_API
729      double
730      Linf() const;
731    
732      /**
733         \brief
734         Return the maximum value of this Data object.
735         *
736      */
737      ESCRIPT_DLL_API
738      double
739      sup() const;
740    
741      /**
742         \brief
743         Return the minimum value of this Data object.
744         *
745    */    */
746      ESCRIPT_DLL_API
747      double
748      inf() const;
749    
750      /**
751         \brief
752         Return the absolute value of each data point of this Data object.
753         *
754      */
755      ESCRIPT_DLL_API
756    Data    Data
757    sin() const;    abs() const;
758    
759    /**    /**
760       \brief       \brief
761       Return the cos of each data point of this Data object.       Return the maximum value of each data point of this Data object.
762         *
763    */    */
764      ESCRIPT_DLL_API
765    Data    Data
766    cos() const;    maxval() const;
767    
768    /**    /**
769       \brief       \brief
770       Return the tan of each data point of this Data object.       Return the minimum value of each data point of this Data object.
771         *
772    */    */
773      ESCRIPT_DLL_API
774    Data    Data
775    tan() const;    minval() const;
776    
777    /**    /**
778       \brief       \brief
779       Return the log to base 10 of each data point of this Data object.       Return the (sample number, data-point number) of the data point with
780         the minimum value in this Data object.
781    */    */
782      ESCRIPT_DLL_API
783      const boost::python::tuple
784      minGlobalDataPoint() const;
785    
786      ESCRIPT_DLL_API
787      void
788      calc_minGlobalDataPoint(int& ProcNo,  int& DataPointNo) const;
789      /**
790         \brief
791         Return the sign of each data point of this Data object.
792         -1 for negative values, zero for zero values, 1 for positive values.
793         *
794      */
795      ESCRIPT_DLL_API
796    Data    Data
797    log() const;    sign() const;
798    
799    /**    /**
800       \brief       \brief
801       Return the natural log of each data point of this Data object.       Return the symmetric part of a matrix which is half the matrix plus its transpose.
802         *
803    */    */
804      ESCRIPT_DLL_API
805    Data    Data
806    ln() const;    symmetric() const;
807    
808    /**    /**
809       \brief       \brief
810       Return the maximum absolute value of this Data object.       Return the nonsymmetric part of a matrix which is half the matrix minus its transpose.
811         *
812    */    */
813    double    ESCRIPT_DLL_API
814    Lsup() const;    Data
815      nonsymmetric() const;
816    
817    /**    /**
818       \brief       \brief
819       Return the minimum absolute value of this Data object.       Return the trace of a matrix
820         *
821    */    */
822    double    ESCRIPT_DLL_API
823    Linf() const;    Data
824      trace(int axis_offset) const;
825    
826    /**    /**
827       \brief       \brief
828       Return the maximum value of this Data object.       Transpose each data point of this Data object around the given axis.
829         *
830    */    */
831    double    ESCRIPT_DLL_API
832    sup() const;    Data
833      transpose(int axis_offset) const;
834    
835    /**    /**
836       \brief       \brief
837       Return the minimum value of this Data object.       Return the eigenvalues of the symmetric part at each data point of this Data object in increasing values.
838         Currently this function is restricted to rank 2, square shape, and dimension 3.
839         *
840    */    */
841    double    ESCRIPT_DLL_API
842    inf() const;    Data
843      eigenvalues() const;
844    
845    /**    /**
846       \brief       \brief
847       Return the absolute value of each data point of this Data object.       Return the eigenvalues and corresponding eigenvcetors of the symmetric part at each data point of this Data object.
848         the eigenvalues are ordered in increasing size where eigenvalues with relative difference less than
849         tol are treated as equal. The eigenvectors are orthogonal, normalized and the sclaed such that the
850         first non-zero entry is positive.
851         Currently this function is restricted to rank 2, square shape, and dimension 3
852         *
853      */
854      ESCRIPT_DLL_API
855      const boost::python::tuple
856      eigenvalues_and_eigenvectors(const double tol=1.e-12) const;
857    
858      /**
859         \brief
860         swaps the components axis0 and axis1
861         *
862    */    */
863      ESCRIPT_DLL_API
864    Data    Data
865    abs() const;    swapaxes(const int axis0, const int axis1) const;
866    
867    /**    /**
868       \brief       \brief
869       Return the maximum value of each data point of this Data object.       Return the error function erf of each data point of this Data object.
870         *
871    */    */
872      ESCRIPT_DLL_API
873    Data    Data
874    maxval() const;    erf() const;
875    
876    /**    /**
877       \brief       \brief
878       Return the minimum value of each data point of this Data object.       Return the sin of each data point of this Data object.
879         *
880    */    */
881      ESCRIPT_DLL_API
882    Data    Data
883    minval() const;    sin() const;
884    
885    /**    /**
886       \brief       \brief
887       Return the (sample number, data-point number) of the data point with       Return the cos of each data point of this Data object.
888       the minimum value in this Data object.       *
889    */    */
890    const boost::python::tuple    ESCRIPT_DLL_API
891    mindp() const;    Data
892      cos() const;
893    
894    /**    /**
895       \brief       \brief
896       Return the length of each data point of this Data object.       Return the tan of each data point of this Data object.
897       sqrt(sum(A[i,j,k,l]^2))       *
898    */    */
899      ESCRIPT_DLL_API
900    Data    Data
901    length() const;    tan() const;
902    
903    /**    /**
904       \brief       \brief
905       Return the sign of each data point of this Data object.       Return the asin of each data point of this Data object.
906       -1 for negative values, zero for zero values, 1 for positive values.       *
907    */    */
908      ESCRIPT_DLL_API
909    Data    Data
910    sign() const;    asin() const;
911    
912    /**    /**
913      \brief       \brief
914      Transpose each data point of this Data object around the given axis.       Return the acos of each data point of this Data object.
915      --* not implemented yet *--       *
916    */    */
917      ESCRIPT_DLL_API
918    Data    Data
919    transpose(int axis) const;    acos() const;
920    
921    /**    /**
922      \brief       \brief
923      Calculate the trace of each data point of this Data object.       Return the atan of each data point of this Data object.
924      sum(A[i,i,i,i])       *
925    */    */
926      ESCRIPT_DLL_API
927    Data    Data
928    trace() const;    atan() const;
929    
930    /**    /**
931      \brief       \brief
932      Return the exponential function of each data point of this Data object.       Return the sinh of each data point of this Data object.
933         *
934      */
935      ESCRIPT_DLL_API
936      Data
937      sinh() const;
938    
939      /**
940         \brief
941         Return the cosh of each data point of this Data object.
942         *
943    */    */
944      ESCRIPT_DLL_API
945      Data
946      cosh() const;
947    
948      /**
949         \brief
950         Return the tanh of each data point of this Data object.
951         *
952      */
953      ESCRIPT_DLL_API
954      Data
955      tanh() const;
956    
957      /**
958         \brief
959         Return the asinh of each data point of this Data object.
960         *
961      */
962      ESCRIPT_DLL_API
963      Data
964      asinh() const;
965    
966      /**
967         \brief
968         Return the acosh of each data point of this Data object.
969         *
970      */
971      ESCRIPT_DLL_API
972      Data
973      acosh() const;
974    
975      /**
976         \brief
977         Return the atanh of each data point of this Data object.
978         *
979      */
980      ESCRIPT_DLL_API
981      Data
982      atanh() const;
983    
984      /**
985         \brief
986         Return the log to base 10 of each data point of this Data object.
987         *
988      */
989      ESCRIPT_DLL_API
990      Data
991      log10() const;
992    
993      /**
994         \brief
995         Return the natural log of each data point of this Data object.
996         *
997      */
998      ESCRIPT_DLL_API
999      Data
1000      log() const;
1001    
1002      /**
1003         \brief
1004         Return the exponential function of each data point of this Data object.
1005         *
1006      */
1007      ESCRIPT_DLL_API
1008    Data    Data
1009    exp() const;    exp() const;
1010    
1011    /**    /**
1012      \brief       \brief
1013      Return the square root of each data point of this Data object.       Return the square root of each data point of this Data object.
1014         *
1015    */    */
1016      ESCRIPT_DLL_API
1017    Data    Data
1018    sqrt() const;    sqrt() const;
1019    
1020    /**    /**
1021      \brief       \brief
1022      Return the negation of each data point of this Data object.       Return the negation of each data point of this Data object.
1023         *
1024    */    */
1025      ESCRIPT_DLL_API
1026    Data    Data
1027    neg() const;    neg() const;
1028    
1029    /**    /**
1030      \brief       \brief
1031      Return the identity of each data point of this Data object.       Return the identity of each data point of this Data object.
1032      Simply returns this object unmodified.       Simply returns this object unmodified.
1033         *
1034    */    */
1035      ESCRIPT_DLL_API
1036    Data    Data
1037    pos() const;    pos() const;
1038    
# Line 762  class Data { Line 1041  class Data {
1041       Return the given power of each data point of this Data object.       Return the given power of each data point of this Data object.
1042    
1043       \param right Input - the power to raise the object to.       \param right Input - the power to raise the object to.
1044         *
1045    */    */
1046      ESCRIPT_DLL_API
1047    Data    Data
1048    powD(const Data& right) const;    powD(const Data& right) const;
1049    
1050    /**    /**
1051     * \brief       \brief
1052     * Return the given power of each data point of this boost python object.       Return the given power of each data point of this boost python object.
1053     *      
1054     * \param right Input - the power to raise the object to.       \param right Input - the power to raise the object to.
1055         *
1056     */     */
1057      ESCRIPT_DLL_API
1058    Data    Data
1059    powO(const boost::python::object& right) const;    powO(const boost::python::object& right) const;
1060    
1061    /**    /**
1062      \brief       \brief
1063      writes the object to a file in the DX file format       Return the given power of each data point of this boost python object.
1064        
1065         \param left Input - the bases
1066         *
1067       */
1068    
1069      ESCRIPT_DLL_API
1070      Data
1071      rpowO(const boost::python::object& left) const;
1072    
1073      /**
1074         \brief
1075         writes the object to a file in the DX file format
1076    */    */
1077      ESCRIPT_DLL_API
1078    void    void
1079    saveDX(std::string fileName) const;    saveDX(std::string fileName) const;
1080    
1081    /**    /**
1082      \brief       \brief
1083      writes the object to a file in the VTK file format       writes the object to a file in the VTK file format
1084    */    */
1085      ESCRIPT_DLL_API
1086    void    void
1087    saveVTK(std::string fileName) const;    saveVTK(std::string fileName) const;
1088    
# Line 793  class Data { Line 1090  class Data {
1090       \brief       \brief
1091       Overloaded operator +=       Overloaded operator +=
1092       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1093         *
1094    */    */
1095      ESCRIPT_DLL_API
1096    Data& operator+=(const Data& right);    Data& operator+=(const Data& right);
1097      ESCRIPT_DLL_API
1098    Data& operator+=(const boost::python::object& right);    Data& operator+=(const boost::python::object& right);
1099    
1100    /**    /**
1101       \brief       \brief
1102       Overloaded operator -=       Overloaded operator -=
1103       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1104         *
1105    */    */
1106      ESCRIPT_DLL_API
1107    Data& operator-=(const Data& right);    Data& operator-=(const Data& right);
1108      ESCRIPT_DLL_API
1109    Data& operator-=(const boost::python::object& right);    Data& operator-=(const boost::python::object& right);
1110    
1111   /**   /**
1112       \brief       \brief
1113       Overloaded operator *=       Overloaded operator *=
1114       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1115         *
1116    */    */
1117      ESCRIPT_DLL_API
1118    Data& operator*=(const Data& right);    Data& operator*=(const Data& right);
1119      ESCRIPT_DLL_API
1120    Data& operator*=(const boost::python::object& right);    Data& operator*=(const boost::python::object& right);
1121    
1122   /**   /**
1123       \brief       \brief
1124       Overloaded operator /=       Overloaded operator /=
1125       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1126         *
1127    */    */
1128      ESCRIPT_DLL_API
1129    Data& operator/=(const Data& right);    Data& operator/=(const Data& right);
1130      ESCRIPT_DLL_API
1131    Data& operator/=(const boost::python::object& right);    Data& operator/=(const boost::python::object& right);
1132    
1133    /**    /**
1134       \brief       \brief
1135       Returns true if this can be interpolated to functionspace.       Returns true if this can be interpolated to functionspace.
1136    */    */
1137      ESCRIPT_DLL_API
1138    bool    bool
1139    probeInterpolation(const FunctionSpace& functionspace) const;    probeInterpolation(const FunctionSpace& functionspace) const;
1140    
# Line 843  class Data { Line 1153  class Data {
1153       \param key - Input - python slice tuple specifying       \param key - Input - python slice tuple specifying
1154       slice to return.       slice to return.
1155    */    */
1156      ESCRIPT_DLL_API
1157    Data    Data
1158    getItem(const boost::python::object& key) const;    getItem(const boost::python::object& key) const;
1159    
# Line 857  class Data { Line 1168  class Data {
1168       slice to copy from value.       slice to copy from value.
1169       \param value - Input - Data object to copy from.       \param value - Input - Data object to copy from.
1170    */    */
1171      ESCRIPT_DLL_API
1172    void    void
1173    setItemD(const boost::python::object& key,    setItemD(const boost::python::object& key,
1174             const Data& value);             const Data& value);
1175    
1176      ESCRIPT_DLL_API
1177    void    void
1178    setItemO(const boost::python::object& key,    setItemO(const boost::python::object& key,
1179             const boost::python::object& value);             const boost::python::object& value);
# Line 873  class Data { Line 1186  class Data {
1186       this Data object.       this Data object.
1187    */    */
1188    template <class UnaryFunction>    template <class UnaryFunction>
1189      ESCRIPT_DLL_API
1190    inline    inline
1191    void    void
1192    unaryOp(UnaryFunction operation);    unaryOp(UnaryFunction operation);
# Line 882  class Data { Line 1196  class Data {
1196       Return a Data object containing the specified slice of       Return a Data object containing the specified slice of
1197       this Data object.       this Data object.
1198       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1199         *
1200    */    */
1201      ESCRIPT_DLL_API
1202    Data    Data
1203    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataArrayView::RegionType& region) const;
1204    
# Line 892  class Data { Line 1208  class Data {
1208       Data object.       Data object.
1209       \param value - Input - Data to copy from.       \param value - Input - Data to copy from.
1210       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1211         *
1212    */    */
1213      ESCRIPT_DLL_API
1214    void    void
1215    setSlice(const Data& value,    setSlice(const Data& value,
1216             const DataArrayView::RegionType& region);             const DataArrayView::RegionType& region);
# Line 902  class Data { Line 1220  class Data {
1220       Archive the current Data object to the given file.       Archive the current Data object to the given file.
1221       \param fileName - Input - file to archive to.       \param fileName - Input - file to archive to.
1222    */    */
1223      ESCRIPT_DLL_API
1224    void    void
1225    archiveData(const std::string fileName);    archiveData(const std::string fileName);
1226    
# Line 913  class Data { Line 1232  class Data {
1232       \param fileName - Input - file to extract from.       \param fileName - Input - file to extract from.
1233       \param fspace - Input - a suitable FunctionSpace descibing the data.       \param fspace - Input - a suitable FunctionSpace descibing the data.
1234    */    */
1235      ESCRIPT_DLL_API
1236    void    void
1237    extractData(const std::string fileName,    extractData(const std::string fileName,
1238                const FunctionSpace& fspace);                const FunctionSpace& fspace);
1239    
1240    
1241      /**
1242         \brief
1243         print the data values to stdout. Used for debugging
1244      */
1245      ESCRIPT_DLL_API
1246      void
1247        print(void);
1248    
1249      /**
1250         \brief
1251         return the MPI rank number of the local data
1252             MPI_COMM_WORLD is assumed and the result of MPI_Comm_size()
1253             is returned
1254      */
1255      ESCRIPT_DLL_API
1256        int
1257        get_MPIRank(void) const;
1258    
1259      /**
1260         \brief
1261         return the MPI rank number of the local data
1262             MPI_COMM_WORLD is assumed and the result of MPI_Comm_rank()
1263             is returned
1264      */
1265      ESCRIPT_DLL_API
1266        int
1267        get_MPISize(void) const;
1268    
1269      /**
1270         \brief
1271         return the MPI rank number of the local data
1272             MPI_COMM_WORLD is assumed and returned.
1273      */
1274      ESCRIPT_DLL_API
1275        MPI_Comm
1276        get_MPIComm(void) const;
1277    
1278      /**
1279         \brief
1280         return the object produced by the factory, which is a DataConstant or DataExpanded
1281      */
1282      ESCRIPT_DLL_API
1283        DataAbstract*
1284        borrowData(void) const;
1285    
1286   protected:   protected:
1287    
1288   private:   private:
# Line 939  class Data { Line 1305  class Data {
1305       Perform the specified reduction algorithm on every element of every data point in       Perform the specified reduction algorithm on every element of every data point in
1306       this Data object according to the given function and return the single value result.       this Data object according to the given function and return the single value result.
1307    */    */
1308    template <class UnaryFunction>    template <class BinaryFunction>
1309    inline    inline
1310    double    double
1311    algorithm(UnaryFunction operation) const;    algorithm(BinaryFunction operation,
1312                double initial_value) const;
1313    
1314    /**    /**
1315       \brief       \brief
# Line 951  class Data { Line 1318  class Data {
1318       one value - the result of the reduction operation on the corresponding data-point in       one value - the result of the reduction operation on the corresponding data-point in
1319       this Data object       this Data object
1320    */    */
1321    template <class UnaryFunction>    template <class BinaryFunction>
1322    inline    inline
1323    Data    Data
1324    dp_algorithm(UnaryFunction operation) const;    dp_algorithm(BinaryFunction operation,
1325                   double initial_value) const;
1326    
1327    /**    /**
1328       \brief       \brief
# Line 972  class Data { Line 1340  class Data {
1340    
1341    /**    /**
1342       \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  
1343       Convert the data type of the RHS to match this.       Convert the data type of the RHS to match this.
1344       \param right - Input - data type to match.       \param right - Input - data type to match.
1345    */    */
# Line 1007  class Data { Line 1364  class Data {
1364               const FunctionSpace& what,               const FunctionSpace& what,
1365               bool expanded);               bool expanded);
1366    
1367    /**    //
1368       \brief    // flag to protect the data object against any update
1369       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);  
1370    
1371    //    //
1372    // pointer to the actual data object    // pointer to the actual data object
1373    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
1374    
1375      //
1376      // pointer to the internal profiling data
1377      struct profDataEntry *profData;
1378    
1379  };  };
1380    
1381  template <class IValueType>  template <class IValueType>
# Line 1048  Data::initialise(const IValueType& value Line 1403  Data::initialise(const IValueType& value
1403  /**  /**
1404     Binary Data object operators.     Binary Data object operators.
1405  */  */
1406    inline double rpow(double x,double y)
1407    {
1408        return pow(y,x);
1409    }
1410    
1411  /**  /**
1412    \brief    \brief
1413    Operator+    Operator+
1414    Takes two Data objects.    Takes two Data objects.
1415  */  */
1416  Data operator+(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator+(const Data& left, const Data& right);
1417    
1418  /**  /**
1419    \brief    \brief
1420    Operator-    Operator-
1421    Takes two Data objects.    Takes two Data objects.
1422  */  */
1423  Data operator-(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator-(const Data& left, const Data& right);
1424    
1425  /**  /**
1426    \brief    \brief
1427    Operator*    Operator*
1428    Takes two Data objects.    Takes two Data objects.
1429  */  */
1430  Data operator*(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator*(const Data& left, const Data& right);
1431    
1432  /**  /**
1433    \brief    \brief
1434    Operator/    Operator/
1435    Takes two Data objects.    Takes two Data objects.
1436  */  */
1437  Data operator/(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator/(const Data& left, const Data& right);
1438    
1439  /**  /**
1440    \brief    \brief
# Line 1083  Data operator/(const Data& left, const D Line 1442  Data operator/(const Data& left, const D
1442    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1443    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1444  */  */
1445  Data operator+(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator+(const Data& left, const boost::python::object& right);
1446    
1447  /**  /**
1448    \brief    \brief
# Line 1091  Data operator+(const Data& left, const b Line 1450  Data operator+(const Data& left, const b
1450    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1451    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1452  */  */
1453  Data operator-(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator-(const Data& left, const boost::python::object& right);
1454    
1455  /**  /**
1456    \brief    \brief
# Line 1099  Data operator-(const Data& left, const b Line 1458  Data operator-(const Data& left, const b
1458    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1459    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1460  */  */
1461  Data operator*(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator*(const Data& left, const boost::python::object& right);
1462    
1463  /**  /**
1464    \brief    \brief
# Line 1107  Data operator*(const Data& left, const b Line 1466  Data operator*(const Data& left, const b
1466    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1467    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1468  */  */
1469  Data operator/(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator/(const Data& left, const boost::python::object& right);
1470    
1471  /**  /**
1472    \brief    \brief
# Line 1115  Data operator/(const Data& left, const b Line 1474  Data operator/(const Data& left, const b
1474    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1475    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1476  */  */
1477  Data operator+(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator+(const boost::python::object& left, const Data& right);
1478    
1479  /**  /**
1480    \brief    \brief
# Line 1123  Data operator+(const boost::python::obje Line 1482  Data operator+(const boost::python::obje
1482    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1483    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1484  */  */
1485  Data operator-(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator-(const boost::python::object& left, const Data& right);
1486    
1487  /**  /**
1488    \brief    \brief
# Line 1131  Data operator-(const boost::python::obje Line 1490  Data operator-(const boost::python::obje
1490    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1491    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1492  */  */
1493  Data operator*(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator*(const boost::python::object& left, const Data& right);
1494    
1495  /**  /**
1496    \brief    \brief
# Line 1139  Data operator*(const boost::python::obje Line 1498  Data operator*(const boost::python::obje
1498    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1499    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1500  */  */
1501  Data operator/(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator/(const boost::python::object& left, const Data& right);
1502    
1503  /**  /**
1504    \brief    \brief
1505    Output operator    Output operator
1506  */  */
1507  std::ostream& operator<<(std::ostream& o, const Data& data);  ESCRIPT_DLL_API std::ostream& operator<<(std::ostream& o, const Data& data);
1508    
1509    /**
1510      \brief
1511      Compute a tensor product of two Data objects
1512      \param arg0 - Input - Data object
1513      \param arg1 - Input - Data object
1514      \param axis_offset - Input - axis offset
1515      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1516    */
1517    ESCRIPT_DLL_API
1518    Data
1519    C_GeneralTensorProduct(Data& arg0,
1520                         Data& arg1,
1521                         int axis_offset=0,
1522                         int transpose=0);
1523    
1524  /**  /**
1525    \brief    \brief
# Line 1153  std::ostream& operator<<(std::ostream& o Line 1527  std::ostream& operator<<(std::ostream& o
1527    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
1528    be relied on. Requires further implementation.    be relied on. Requires further implementation.
1529  */  */
1530  //bool operator==(const Data& left, const Data& right);  //ESCRIPT_DLL_API bool operator==(const Data& left, const Data& right);
1531    
1532  /**  /**
1533    \brief    \brief
# Line 1169  Data::binaryOp(const Data& right, Line 1543  Data::binaryOp(const Data& right,
1543     //     //
1544     // 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
1545     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1546       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1547     }     }
1548     //     //
1549     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1221  Data::binaryOp(const Data& right, Line 1595  Data::binaryOp(const Data& right,
1595       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");
1596       escript::binaryOp(*leftC,*rightC,operation);       escript::binaryOp(*leftC,*rightC,operation);
1597     }     }
1598  }     #if defined DOPROF
1599       profData->binary++;
1600  /**     #endif
   \brief  
   Perform the given binary operation with this and right as operands.  
   Right is a boost::python object.  
 */  
 template <class BinaryFunction>  
 inline  
 void  
 Data::binaryOp(const boost::python::object& right,  
                BinaryFunction operation)  
 {  
    DataArray temp(right);  
    //  
    // if this has a rank of zero promote it to the rank of the RHS.  
    if (getPointDataView().getRank()==0 && temp.getView().getRank()!=0) {  
       reshapeDataPoint(temp.getView().getShape());  
    }  
    //  
    // Always allow scalar values for the RHS but check other shapes  
    if (temp.getView().getRank()!=0) {  
      if (!getPointDataView().checkShape(temp.getView().getShape())) {  
        throw DataException(getPointDataView().createShapeErrorMessage(  
                   "Error - RHS shape doesn't match LHS shape.",temp.getView().getShape()));  
      }  
    }  
    if (isExpanded()) {  
      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());  
      EsysAssert((leftC!=0),"Programming error - casting to DataExpanded.");  
      escript::binaryOp(*leftC,temp.getView(),operation);  
    } else if (isTagged()) {  
      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());  
      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");  
      escript::binaryOp(*leftC,temp.getView(),operation);  
    } else if (isConstant()) {  
      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());  
      EsysAssert((leftC!=0),"Programming error - casting to DataConstant.");  
      escript::binaryOp(*leftC,temp.getView(),operation);  
    }  
1601  }  }
1602    
1603  /**  /**
# Line 1316  Data::unaryOp(UnaryFunction operation) Line 1653  Data::unaryOp(UnaryFunction operation)
1653    object (*this) is a rank n Data object, and returned object is a scalar.    object (*this) is a rank n Data object, and returned object is a scalar.
1654    Calls escript::algorithm.    Calls escript::algorithm.
1655  */  */
1656  template <class UnaryFunction>  template <class BinaryFunction>
1657  inline  inline
1658  double  double
1659  Data::algorithm(UnaryFunction operation) const  Data::algorithm(BinaryFunction operation, double initial_value) const
1660  {  {
1661    if (isExpanded()) {    if (isExpanded()) {
1662      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1663      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1664      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1665    } else if (isTagged()) {    } else if (isTagged()) {
1666      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1667      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1668      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1669    } else if (isConstant()) {    } else if (isConstant()) {
1670      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1671      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1672      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1673    }    }
1674    return 0;    return 0;
1675  }  }
# Line 1345  Data::algorithm(UnaryFunction operation) Line 1682  Data::algorithm(UnaryFunction operation)
1682    rank 0 Data object.    rank 0 Data object.
1683    Calls escript::dp_algorithm.    Calls escript::dp_algorithm.
1684  */  */
1685  template <class UnaryFunction>  template <class BinaryFunction>
1686  inline  inline
1687  Data  Data
1688  Data::dp_algorithm(UnaryFunction operation) const  Data::dp_algorithm(BinaryFunction operation, double initial_value) const
1689  {  {
   Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());  
1690    if (isExpanded()) {    if (isExpanded()) {
1691        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1692      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
1693      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1694      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1695      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1696      escript::dp_algorithm(*dataE,*resultE,operation);      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
1697        return result;
1698    } else if (isTagged()) {    } else if (isTagged()) {
1699      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1700        DataArrayView::ShapeType viewShape;
1701        DataArrayView::ValueType viewData(1);
1702        viewData[0]=0;
1703        DataArrayView defaultValue(viewData,viewShape);
1704        DataTagged::TagListType keys;
1705        DataTagged::ValueListType values;
1706        DataTagged::DataMapType::const_iterator i;
1707        for (i=dataT->getTagLookup().begin();i!=dataT->getTagLookup().end();i++) {
1708          keys.push_back(i->first);
1709          values.push_back(defaultValue);
1710        }
1711        Data result(keys,values,defaultValue,getFunctionSpace());
1712      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1713      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1714      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1715      escript::dp_algorithm(*dataT,*resultT,operation);      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
1716        return result;
1717    } else if (isConstant()) {    } else if (isConstant()) {
1718        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1719      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1720      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1721      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1722      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1723      escript::dp_algorithm(*dataC,*resultC,operation);      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
1724        return result;
1725    }    }
1726    return result;    Data falseRetVal; // to keep compiler quiet
1727      return falseRetVal;
1728  }  }
1729    
1730  }  }

Legend:
Removed from v.121  
changed lines
  Added in v.1034

  ViewVC Help
Powered by ViewVC 1.1.26