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

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

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

trunk/esys2/escript/src/Data/Data.h revision 122 by jgs, Thu Jun 9 05:38:05 2005 UTC trunk/escript/src/Data.h revision 921 by gross, Fri Jan 5 00:54:37 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/DataAlgorithm.h"  #include "FunctionSpace.h"
23  #include "escript/Data/FunctionSpace.h"  #include "BinaryOp.h"
24  #include "escript/Data/BinaryOp.h"  #include "UnaryOp.h"
25  #include "escript/Data/UnaryOp.h"  #include "DataException.h"
 #include "escript/Data/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 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(),
220         bool expanded=false);         bool expanded=false);
221      /**
222         \brief
223         Destructor
224      */
225      ESCRIPT_DLL_API
226      ~Data();
227    
228    /**    /**
229       \brief       \brief
230       Perform a deep copy.       Perform a deep copy.
231    */    */
232      ESCRIPT_DLL_API
233    void    void
234    copy(const Data& other);    copy(const Data& other);
235    
# Line 220  class Data { Line 239  class Data {
239    
240    /**    /**
241       \brief       \brief
242         switches on update protection
243    
244      */
245      ESCRIPT_DLL_API
246      void
247      setProtection();
248    
249      /**
250         \brief
251         Returns trueif the data object is protected against update
252    
253      */
254      ESCRIPT_DLL_API
255      bool
256      isProtected() const;
257      /**
258         \brief
259       Return the values of all data-points as a single python numarray object.       Return the values of all data-points as a single python numarray object.
260    */    */
261      ESCRIPT_DLL_API
262    const boost::python::numeric::array    const boost::python::numeric::array
263    convertToNumArray();    convertToNumArray();
264    
265    /**    /**
266       \brief       \brief
267       Return the values of all data-points for the given sample as a single python numarray object.       Fills the expanded Data object from values of a python numarray object.
268      */
269      ESCRIPT_DLL_API
270      void
271      fillFromNumArray(const boost::python::numeric::array);
272    
273      /**
274         \brief
275         Return the values of a data point on this process
276    */    */
277      ESCRIPT_DLL_API
278    const boost::python::numeric::array    const boost::python::numeric::array
279    convertToNumArrayFromSampleNo(int sampleNo);    getValueOfDataPoint(int dataPointNo);
280    
281    /**    /**
282       \brief       \brief
283       Return the value of the specified data-point as a single python numarray object.       sets the values of a data-point on this process
284    */    */
285      ESCRIPT_DLL_API
286      void
287      setValueOfDataPoint(int dataPointNo, const boost::python::numeric::array);
288    
289      /**
290         \brief
291         Return the value of the specified data-point across all processors
292      */
293      ESCRIPT_DLL_API
294    const boost::python::numeric::array    const boost::python::numeric::array
295    convertToNumArrayFromDPNo(int sampleNo,    getValueOfGlobalDataPoint(int procNo, int dataPointNo);
296                              int dataPointNo);  
297      /**
298         \brief
299         Return the tag number associated with the given data-point.
300    
301         The data-point number here corresponds to the data-point number in the
302         numarray returned by convertToNumArray.
303      */
304      ESCRIPT_DLL_API
305      int
306      getTagNumber(int dpno);
307    
308    /**    /**
309       \brief       \brief
310       Return the C wrapper for the Data object.       Return the C wrapper for the Data object.
311    */    */
312      ESCRIPT_DLL_API
313    escriptDataC    escriptDataC
314    getDataC();    getDataC();
315    
# Line 251  class Data { Line 317  class Data {
317       \brief       \brief
318       Return the C wrapper for the Data object - const version.       Return the C wrapper for the Data object - const version.
319    */    */
320      ESCRIPT_DLL_API
321    escriptDataC    escriptDataC
322    getDataC() const;    getDataC() const;
323    
# Line 258  class Data { Line 325  class Data {
325       \brief       \brief
326       Write the data as a string.       Write the data as a string.
327    */    */
328      ESCRIPT_DLL_API
329    inline    inline
330    std::string    std::string
331    toString() const    toString() const
# Line 271  class Data { Line 339  class Data {
339       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
340       to manipulate the point data.       to manipulate the point data.
341    */    */
342      ESCRIPT_DLL_API
343    inline    inline
344    const DataArrayView&    const DataArrayView&
345    getPointDataView() const    getPointDataView() const
# Line 282  class Data { Line 351  class Data {
351       \brief       \brief
352       Whatever the current Data type make this into a DataExpanded.       Whatever the current Data type make this into a DataExpanded.
353    */    */
354      ESCRIPT_DLL_API
355    void    void
356    expand();    expand();
357    
# Line 290  class Data { Line 360  class Data {
360       If possible convert this Data to DataTagged. This will only allow       If possible convert this Data to DataTagged. This will only allow
361       Constant data to be converted to tagged. An attempt to convert       Constant data to be converted to tagged. An attempt to convert
362       Expanded data to tagged will throw an exception.       Expanded data to tagged will throw an exception.
363        ==>*
364    */    */
365      ESCRIPT_DLL_API
366    void    void
367    tag();    tag();
368    
# Line 298  class Data { Line 370  class Data {
370       \brief       \brief
371       Return true if this Data is expanded.       Return true if this Data is expanded.
372    */    */
373      ESCRIPT_DLL_API
374    bool    bool
375    isExpanded() const;    isExpanded() const;
376    
# Line 305  class Data { Line 378  class Data {
378       \brief       \brief
379       Return true if this Data is tagged.       Return true if this Data is tagged.
380    */    */
381      ESCRIPT_DLL_API
382    bool    bool
383    isTagged() const;    isTagged() const;
384    
# Line 312  class Data { Line 386  class Data {
386       \brief       \brief
387       Return true if this Data is constant.       Return true if this Data is constant.
388    */    */
389      ESCRIPT_DLL_API
390    bool    bool
391    isConstant() const;    isConstant() const;
392    
# Line 319  class Data { Line 394  class Data {
394       \brief       \brief
395       Return true if this Data is empty.       Return true if this Data is empty.
396    */    */
397      ESCRIPT_DLL_API
398    bool    bool
399    isEmpty() const;    isEmpty() const;
400    
# Line 326  class Data { Line 402  class Data {
402       \brief       \brief
403       Return the function space.       Return the function space.
404    */    */
405      ESCRIPT_DLL_API
406    inline    inline
407    const FunctionSpace&    const FunctionSpace&
408    getFunctionSpace() const    getFunctionSpace() const
# Line 337  class Data { Line 414  class Data {
414       \brief       \brief
415       Return a copy of the function space.       Return a copy of the function space.
416    */    */
417      ESCRIPT_DLL_API
418    const FunctionSpace    const FunctionSpace
419    getCopyOfFunctionSpace() const;    getCopyOfFunctionSpace() const;
420    
# Line 344  class Data { Line 422  class Data {
422       \brief       \brief
423       Return the domain.       Return the domain.
424    */    */
425      ESCRIPT_DLL_API
426    inline    inline
427    const AbstractDomain&    const AbstractDomain&
428    getDomain() const    getDomain() const
# Line 355  class Data { Line 434  class Data {
434       \brief       \brief
435       Return a copy of the domain.       Return a copy of the domain.
436    */    */
437      ESCRIPT_DLL_API
438    const AbstractDomain    const AbstractDomain
439    getCopyOfDomain() const;    getCopyOfDomain() const;
440    
# Line 362  class Data { Line 442  class Data {
442       \brief       \brief
443       Return the rank of the point data.       Return the rank of the point data.
444    */    */
445      ESCRIPT_DLL_API
446    inline    inline
447    int    int
448    getDataPointRank() const    getDataPointRank() const
# Line 371  class Data { Line 452  class Data {
452    
453    /**    /**
454       \brief       \brief
455         Return the number of data points
456      */
457      ESCRIPT_DLL_API
458      inline
459      int
460      getNumDataPoints() const
461      {
462        return getNumSamples() * getNumDataPointsPerSample();
463      }
464      /**
465         \brief
466       Return the number of samples.       Return the number of samples.
467    */    */
468      ESCRIPT_DLL_API
469    inline    inline
470    int    int
471    getNumSamples() const    getNumSamples() const
# Line 384  class Data { Line 477  class Data {
477       \brief       \brief
478       Return the number of data points per sample.       Return the number of data points per sample.
479    */    */
480      ESCRIPT_DLL_API
481    inline    inline
482    int    int
483    getNumDataPointsPerSample() const    getNumDataPointsPerSample() const
# Line 397  class Data { Line 491  class Data {
491       preferred interface but is provided for use by C code.       preferred interface but is provided for use by C code.
492       \param sampleNo - Input - the given sample no.       \param sampleNo - Input - the given sample no.
493    */    */
494      ESCRIPT_DLL_API
495    inline    inline
496    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
497    getSampleData(DataAbstract::ValueType::size_type sampleNo)    getSampleData(DataAbstract::ValueType::size_type sampleNo)
# Line 410  class Data { Line 505  class Data {
505       access data that isn't tagged an exception will be thrown.       access data that isn't tagged an exception will be thrown.
506       \param tag - Input - the tag key.       \param tag - Input - the tag key.
507    */    */
508      ESCRIPT_DLL_API
509    inline    inline
510    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
511    getSampleDataByTag(int tag)    getSampleDataByTag(int tag)
# Line 433  class Data { Line 529  class Data {
529       \param value - Input - value to assign to data-points associated with       \param value - Input - value to assign to data-points associated with
530                              the given reference number.                              the given reference number.
531    */    */
532      ESCRIPT_DLL_API
533    void    void
534    setRefValue(int ref,    setRefValue(int ref,
535                const boost::python::numeric::array& value);                const boost::python::numeric::array& value);
# Line 452  class Data { Line 549  class Data {
549       \param value - Output - object to receive values from data-points       \param value - Output - object to receive values from data-points
550                               associated with the given reference number.                               associated with the given reference number.
551    */    */
552      ESCRIPT_DLL_API
553    void    void
554    getRefValue(int ref,    getRefValue(int ref,
555                boost::python::numeric::array& value);                boost::python::numeric::array& value);
# Line 464  class Data { Line 562  class Data {
562       \param sampleNo - Input -       \param sampleNo - Input -
563       \param dataPointNo - Input -       \param dataPointNo - Input -
564    */    */
565      ESCRIPT_DLL_API
566    inline    inline
567    DataArrayView    DataArrayView
568    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
569                 int dataPointNo)                 int dataPointNo)
570    {    {
571      return m_data->getDataPoint(sampleNo,dataPointNo);          return m_data->getDataPoint(sampleNo,dataPointNo);
572    }    }
573    
574    /**    /**
575       \brief       \brief
576       Return a reference to the data point shape.       Return a reference to the data point shape.
577    */    */
578      ESCRIPT_DLL_API
579    const DataArrayView::ShapeType&    const DataArrayView::ShapeType&
580    getDataPointShape() const;    getDataPointShape() const;
581    
# Line 483  class Data { Line 583  class Data {
583       \brief       \brief
584       Return the data point shape as a tuple of integers.       Return the data point shape as a tuple of integers.
585    */    */
586      ESCRIPT_DLL_API
587    const boost::python::tuple    const boost::python::tuple
588    getShapeTuple() const;    getShapeTuple() const;
589    
# Line 491  class Data { Line 592  class Data {
592       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
593       data point shape dimensions.       data point shape dimensions.
594    */    */
595      ESCRIPT_DLL_API
596    int    int
597    getDataPointSize() const;    getDataPointSize() const;
598    
# Line 498  class Data { Line 600  class Data {
600       \brief       \brief
601       Return the number of doubles stored for this Data.       Return the number of doubles stored for this Data.
602    */    */
603      ESCRIPT_DLL_API
604    DataArrayView::ValueType::size_type    DataArrayView::ValueType::size_type
605    getLength() const;    getLength() const;
606    
# Line 508  class Data { Line 611  class Data {
611       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
612       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
613       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
614        ==>*
615    */    */
616      ESCRIPT_DLL_API
617    void    void
618    setTaggedValue(int tagKey,    setTaggedValue(int tagKey,
619                   const boost::python::object& value);                   const boost::python::object& value);
# Line 520  class Data { Line 625  class Data {
625       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
626       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
627       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
628        ==>*
629    */    */
630      ESCRIPT_DLL_API
631    void    void
632    setTaggedValueFromCPP(int tagKey,    setTaggedValueFromCPP(int tagKey,
633                          const DataArrayView& value);                          const DataArrayView& value);
# Line 529  class Data { Line 636  class Data {
636      \brief      \brief
637      Copy other Data object into this Data object where mask is positive.      Copy other Data object into this Data object where mask is positive.
638    */    */
639      ESCRIPT_DLL_API
640    void    void
641    copyWithMask(const Data& other,    copyWithMask(const Data& other,
642                 const Data& mask);                 const Data& mask);
# Line 541  class Data { Line 649  class Data {
649       \brief       \brief
650       Interpolates this onto the given functionspace and returns       Interpolates this onto the given functionspace and returns
651       the result as a Data object.       the result as a Data object.
652         *
653    */    */
654      ESCRIPT_DLL_API
655    Data    Data
656    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
657    
# Line 549  class Data { Line 659  class Data {
659       \brief       \brief
660       Calculates the gradient of the data at the data points of functionspace.       Calculates the gradient of the data at the data points of functionspace.
661       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.
662         *
663    */    */
664      ESCRIPT_DLL_API
665    Data    Data
666    gradOn(const FunctionSpace& functionspace) const;    gradOn(const FunctionSpace& functionspace) const;
667    
668      ESCRIPT_DLL_API
669    Data    Data
670    grad() const;    grad() const;
671    
672    /**    /**
673       \brief       \brief
674       Calculate the integral over the function space domain.       Calculate the integral over the function space domain.
675         *
676    */    */
677      ESCRIPT_DLL_API
678    boost::python::numeric::array    boost::python::numeric::array
679    integrate() const;    integrate() const;
680    
681    /**    /**
682       \brief       \brief
683         Returns 1./ Data object
684         *
685      */
686      ESCRIPT_DLL_API
687      Data
688      oneOver() const;
689      /**
690         \brief
691       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.
692         *
693    */    */
694      ESCRIPT_DLL_API
695    Data    Data
696    wherePositive() const;    wherePositive() const;
697    
698    /**    /**
699       \brief       \brief
700       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.
701         *
702    */    */
703      ESCRIPT_DLL_API
704    Data    Data
705    whereNegative() const;    whereNegative() const;
706    
707    /**    /**
708       \brief       \brief
709       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.
710         *
711    */    */
712      ESCRIPT_DLL_API
713    Data    Data
714    whereNonNegative() const;    whereNonNegative() const;
715    
716    /**    /**
717       \brief       \brief
718       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.
719         *
720    */    */
721      ESCRIPT_DLL_API
722    Data    Data
723    whereNonPositive() const;    whereNonPositive() const;
724    
725    /**    /**
726       \brief       \brief
727       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.
728         *
729    */    */
730      ESCRIPT_DLL_API
731    Data    Data
732    whereZero() const;    whereZero(double tol=0.0) const;
733    
734    /**    /**
735       \brief       \brief
736       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.
737         *
738    */    */
739      ESCRIPT_DLL_API
740    Data    Data
741    whereNonZero() const;    whereNonZero(double tol=0.0) const;
742    
743    /**    /**
744       \brief       \brief
745       Return the sin of each data point of this Data object.       Return the maximum absolute value of this Data object.
746         *
747    */    */
748      ESCRIPT_DLL_API
749      double
750      Lsup() const;
751    
752      /**
753         \brief
754         Return the minimum absolute value of this Data object.
755         *
756      */
757      ESCRIPT_DLL_API
758      double
759      Linf() const;
760    
761      /**
762         \brief
763         Return the maximum value of this Data object.
764         *
765      */
766      ESCRIPT_DLL_API
767      double
768      sup() const;
769    
770      /**
771         \brief
772         Return the minimum value of this Data object.
773         *
774      */
775      ESCRIPT_DLL_API
776      double
777      inf() const;
778    
779      /**
780         \brief
781         Return the absolute value of each data point of this Data object.
782         *
783      */
784      ESCRIPT_DLL_API
785    Data    Data
786    sin() const;    abs() const;
787    
788    /**    /**
789       \brief       \brief
790       Return the cos of each data point of this Data object.       Return the maximum value of each data point of this Data object.
791         *
792    */    */
793      ESCRIPT_DLL_API
794    Data    Data
795    cos() const;    maxval() const;
796    
797    /**    /**
798       \brief       \brief
799       Return the tan of each data point of this Data object.       Return the minimum value of each data point of this Data object.
800         *
801    */    */
802      ESCRIPT_DLL_API
803    Data    Data
804    tan() const;    minval() const;
805    
806    /**    /**
807       \brief       \brief
808       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
809         the minimum value in this Data object.
810    */    */
811      ESCRIPT_DLL_API
812      const boost::python::tuple
813      minGlobalDataPoint() const;
814    
815      ESCRIPT_DLL_API
816      void
817      calc_minGlobalDataPoint(int& ProcNo,  int& DataPointNo) const;
818      /**
819         \brief
820         Return the sign of each data point of this Data object.
821         -1 for negative values, zero for zero values, 1 for positive values.
822         *
823      */
824      ESCRIPT_DLL_API
825    Data    Data
826    log() const;    sign() const;
827    
828    /**    /**
829       \brief       \brief
830       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.
831         *
832    */    */
833      ESCRIPT_DLL_API
834    Data    Data
835    ln() const;    symmetric() const;
836    
837    /**    /**
838       \brief       \brief
839       Return the maximum absolute value of this Data object.       Return the nonsymmetric part of a matrix which is half the matrix minus its transpose.
840         *
841    */    */
842    double    ESCRIPT_DLL_API
843    Lsup() const;    Data
844      nonsymmetric() const;
845    
846    /**    /**
847       \brief       \brief
848       Return the minimum absolute value of this Data object.       Return the trace of a matrix
849         *
850    */    */
851    double    ESCRIPT_DLL_API
852    Linf() const;    Data
853      trace(int axis_offset) const;
854    
855    /**    /**
856       \brief       \brief
857       Return the maximum value of this Data object.       Transpose each data point of this Data object around the given axis.
858         *
859    */    */
860    double    ESCRIPT_DLL_API
861    sup() const;    Data
862      transpose(int axis_offset) const;
863    
864    /**    /**
865       \brief       \brief
866       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.
867         Currently this function is restricted to rank 2, square shape, and dimension 3.
868         *
869    */    */
870    double    ESCRIPT_DLL_API
871    inf() const;    Data
872      eigenvalues() const;
873    
874    /**    /**
875       \brief       \brief
876       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.
877         the eigenvalues are ordered in increasing size where eigenvalues with relative difference less than
878         tol are treated as equal. The eigenvectors are orthogonal, normalized and the sclaed such that the
879         first non-zero entry is positive.
880         Currently this function is restricted to rank 2, square shape, and dimension 3
881         *
882      */
883      ESCRIPT_DLL_API
884      const boost::python::tuple
885      eigenvalues_and_eigenvectors(const double tol=1.e-12) const;
886    
887      /**
888         \brief
889         swaps the components axis0 and axis1
890         *
891    */    */
892      ESCRIPT_DLL_API
893    Data    Data
894    abs() const;    swapaxes(const int axis0, const int axis1) const;
895    
896    /**    /**
897       \brief       \brief
898       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.
899         *
900    */    */
901      ESCRIPT_DLL_API
902    Data    Data
903    maxval() const;    erf() const;
904    
905    /**    /**
906       \brief       \brief
907       Return the minimum value of each data point of this Data object.       Return the sin of each data point of this Data object.
908         *
909    */    */
910      ESCRIPT_DLL_API
911    Data    Data
912    minval() const;    sin() const;
913    
914    /**    /**
915       \brief       \brief
916       Return the (sample number, data-point number) of the data point with       Return the cos of each data point of this Data object.
917       the minimum value in this Data object.       *
918    */    */
919    const boost::python::tuple    ESCRIPT_DLL_API
920    mindp() const;    Data
921      cos() const;
922    
923    /**    /**
924       \brief       \brief
925       Return the length of each data point of this Data object.       Return the tan of each data point of this Data object.
926       sqrt(sum(A[i,j,k,l]^2))       *
927    */    */
928      ESCRIPT_DLL_API
929    Data    Data
930    length() const;    tan() const;
931    
932    /**    /**
933       \brief       \brief
934       Return the sign of each data point of this Data object.       Return the asin of each data point of this Data object.
935       -1 for negative values, zero for zero values, 1 for positive values.       *
936    */    */
937      ESCRIPT_DLL_API
938    Data    Data
939    sign() const;    asin() const;
940    
941    /**    /**
942      \brief       \brief
943      Transpose each data point of this Data object around the given axis.       Return the acos of each data point of this Data object.
944      --* not implemented yet *--       *
945    */    */
946      ESCRIPT_DLL_API
947    Data    Data
948    transpose(int axis) const;    acos() const;
949    
950    /**    /**
951      \brief       \brief
952      Calculate the trace of each data point of this Data object.       Return the atan of each data point of this Data object.
953      sum(A[i,i,i,i])       *
954    */    */
955      ESCRIPT_DLL_API
956    Data    Data
957    trace() const;    atan() const;
958    
959    /**    /**
960      \brief       \brief
961      Return the exponential function of each data point of this Data object.       Return the sinh of each data point of this Data object.
962         *
963      */
964      ESCRIPT_DLL_API
965      Data
966      sinh() const;
967    
968      /**
969         \brief
970         Return the cosh of each data point of this Data object.
971         *
972      */
973      ESCRIPT_DLL_API
974      Data
975      cosh() const;
976    
977      /**
978         \brief
979         Return the tanh of each data point of this Data object.
980         *
981      */
982      ESCRIPT_DLL_API
983      Data
984      tanh() const;
985    
986      /**
987         \brief
988         Return the asinh of each data point of this Data object.
989         *
990      */
991      ESCRIPT_DLL_API
992      Data
993      asinh() const;
994    
995      /**
996         \brief
997         Return the acosh of each data point of this Data object.
998         *
999      */
1000      ESCRIPT_DLL_API
1001      Data
1002      acosh() const;
1003    
1004      /**
1005         \brief
1006         Return the atanh of each data point of this Data object.
1007         *
1008      */
1009      ESCRIPT_DLL_API
1010      Data
1011      atanh() const;
1012    
1013      /**
1014         \brief
1015         Return the log to base 10 of each data point of this Data object.
1016         *
1017      */
1018      ESCRIPT_DLL_API
1019      Data
1020      log10() const;
1021    
1022      /**
1023         \brief
1024         Return the natural log of each data point of this Data object.
1025         *
1026      */
1027      ESCRIPT_DLL_API
1028      Data
1029      log() const;
1030    
1031      /**
1032         \brief
1033         Return the exponential function of each data point of this Data object.
1034         *
1035    */    */
1036      ESCRIPT_DLL_API
1037    Data    Data
1038    exp() const;    exp() const;
1039    
1040    /**    /**
1041      \brief       \brief
1042      Return the square root of each data point of this Data object.       Return the square root of each data point of this Data object.
1043         *
1044    */    */
1045      ESCRIPT_DLL_API
1046    Data    Data
1047    sqrt() const;    sqrt() const;
1048    
1049    /**    /**
1050      \brief       \brief
1051      Return the negation of each data point of this Data object.       Return the negation of each data point of this Data object.
1052         *
1053    */    */
1054      ESCRIPT_DLL_API
1055    Data    Data
1056    neg() const;    neg() const;
1057    
1058    /**    /**
1059      \brief       \brief
1060      Return the identity of each data point of this Data object.       Return the identity of each data point of this Data object.
1061      Simply returns this object unmodified.       Simply returns this object unmodified.
1062         *
1063    */    */
1064      ESCRIPT_DLL_API
1065    Data    Data
1066    pos() const;    pos() const;
1067    
# Line 763  class Data { Line 1070  class Data {
1070       Return the given power of each data point of this Data object.       Return the given power of each data point of this Data object.
1071    
1072       \param right Input - the power to raise the object to.       \param right Input - the power to raise the object to.
1073         *
1074    */    */
1075      ESCRIPT_DLL_API
1076    Data    Data
1077    powD(const Data& right) const;    powD(const Data& right) const;
1078    
1079    /**    /**
1080     * \brief       \brief
1081     * 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.
1082     *      
1083     * \param right Input - the power to raise the object to.       \param right Input - the power to raise the object to.
1084         *
1085     */     */
1086      ESCRIPT_DLL_API
1087    Data    Data
1088    powO(const boost::python::object& right) const;    powO(const boost::python::object& right) const;
1089    
1090    /**    /**
1091      \brief       \brief
1092      writes the object to a file in the DX file format       Return the given power of each data point of this boost python object.
1093        
1094         \param left Input - the bases
1095         *
1096       */
1097    
1098      ESCRIPT_DLL_API
1099      Data
1100      rpowO(const boost::python::object& left) const;
1101    
1102      /**
1103         \brief
1104         writes the object to a file in the DX file format
1105    */    */
1106      ESCRIPT_DLL_API
1107    void    void
1108    saveDX(std::string fileName) const;    saveDX(std::string fileName) const;
1109    
1110    /**    /**
1111      \brief       \brief
1112      writes the object to a file in the VTK file format       writes the object to a file in the VTK file format
1113    */    */
1114      ESCRIPT_DLL_API
1115    void    void
1116    saveVTK(std::string fileName) const;    saveVTK(std::string fileName) const;
1117    
# Line 794  class Data { Line 1119  class Data {
1119       \brief       \brief
1120       Overloaded operator +=       Overloaded operator +=
1121       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1122         *
1123    */    */
1124      ESCRIPT_DLL_API
1125    Data& operator+=(const Data& right);    Data& operator+=(const Data& right);
1126      ESCRIPT_DLL_API
1127    Data& operator+=(const boost::python::object& right);    Data& operator+=(const boost::python::object& right);
1128    
1129    /**    /**
1130       \brief       \brief
1131       Overloaded operator -=       Overloaded operator -=
1132       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1133         *
1134    */    */
1135      ESCRIPT_DLL_API
1136    Data& operator-=(const Data& right);    Data& operator-=(const Data& right);
1137      ESCRIPT_DLL_API
1138    Data& operator-=(const boost::python::object& right);    Data& operator-=(const boost::python::object& right);
1139    
1140   /**   /**
1141       \brief       \brief
1142       Overloaded operator *=       Overloaded operator *=
1143       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1144         *
1145    */    */
1146      ESCRIPT_DLL_API
1147    Data& operator*=(const Data& right);    Data& operator*=(const Data& right);
1148      ESCRIPT_DLL_API
1149    Data& operator*=(const boost::python::object& right);    Data& operator*=(const boost::python::object& right);
1150    
1151   /**   /**
1152       \brief       \brief
1153       Overloaded operator /=       Overloaded operator /=
1154       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1155         *
1156    */    */
1157      ESCRIPT_DLL_API
1158    Data& operator/=(const Data& right);    Data& operator/=(const Data& right);
1159      ESCRIPT_DLL_API
1160    Data& operator/=(const boost::python::object& right);    Data& operator/=(const boost::python::object& right);
1161    
1162    /**    /**
1163       \brief       \brief
1164       Returns true if this can be interpolated to functionspace.       Returns true if this can be interpolated to functionspace.
1165    */    */
1166      ESCRIPT_DLL_API
1167    bool    bool
1168    probeInterpolation(const FunctionSpace& functionspace) const;    probeInterpolation(const FunctionSpace& functionspace) const;
1169    
# Line 844  class Data { Line 1182  class Data {
1182       \param key - Input - python slice tuple specifying       \param key - Input - python slice tuple specifying
1183       slice to return.       slice to return.
1184    */    */
1185      ESCRIPT_DLL_API
1186    Data    Data
1187    getItem(const boost::python::object& key) const;    getItem(const boost::python::object& key) const;
1188    
# Line 858  class Data { Line 1197  class Data {
1197       slice to copy from value.       slice to copy from value.
1198       \param value - Input - Data object to copy from.       \param value - Input - Data object to copy from.
1199    */    */
1200      ESCRIPT_DLL_API
1201    void    void
1202    setItemD(const boost::python::object& key,    setItemD(const boost::python::object& key,
1203             const Data& value);             const Data& value);
1204    
1205      ESCRIPT_DLL_API
1206    void    void
1207    setItemO(const boost::python::object& key,    setItemO(const boost::python::object& key,
1208             const boost::python::object& value);             const boost::python::object& value);
# Line 874  class Data { Line 1215  class Data {
1215       this Data object.       this Data object.
1216    */    */
1217    template <class UnaryFunction>    template <class UnaryFunction>
1218      ESCRIPT_DLL_API
1219    inline    inline
1220    void    void
1221    unaryOp(UnaryFunction operation);    unaryOp(UnaryFunction operation);
# Line 883  class Data { Line 1225  class Data {
1225       Return a Data object containing the specified slice of       Return a Data object containing the specified slice of
1226       this Data object.       this Data object.
1227       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1228         *
1229    */    */
1230      ESCRIPT_DLL_API
1231    Data    Data
1232    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataArrayView::RegionType& region) const;
1233    
# Line 893  class Data { Line 1237  class Data {
1237       Data object.       Data object.
1238       \param value - Input - Data to copy from.       \param value - Input - Data to copy from.
1239       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1240         *
1241    */    */
1242      ESCRIPT_DLL_API
1243    void    void
1244    setSlice(const Data& value,    setSlice(const Data& value,
1245             const DataArrayView::RegionType& region);             const DataArrayView::RegionType& region);
# Line 903  class Data { Line 1249  class Data {
1249       Archive the current Data object to the given file.       Archive the current Data object to the given file.
1250       \param fileName - Input - file to archive to.       \param fileName - Input - file to archive to.
1251    */    */
1252      ESCRIPT_DLL_API
1253    void    void
1254    archiveData(const std::string fileName);    archiveData(const std::string fileName);
1255    
# Line 914  class Data { Line 1261  class Data {
1261       \param fileName - Input - file to extract from.       \param fileName - Input - file to extract from.
1262       \param fspace - Input - a suitable FunctionSpace descibing the data.       \param fspace - Input - a suitable FunctionSpace descibing the data.
1263    */    */
1264      ESCRIPT_DLL_API
1265    void    void
1266    extractData(const std::string fileName,    extractData(const std::string fileName,
1267                const FunctionSpace& fspace);                const FunctionSpace& fspace);
1268    
1269    
1270      /**
1271         \brief
1272         print the data values to stdout. Used for debugging
1273      */
1274      ESCRIPT_DLL_API
1275      void
1276        print(void);
1277    
1278      /**
1279         \brief
1280         return the MPI rank number of the local data
1281             MPI_COMM_WORLD is assumed and the result of MPI_Comm_size()
1282             is returned
1283      */
1284      ESCRIPT_DLL_API
1285        int
1286        get_MPIRank(void) const;
1287    
1288      /**
1289         \brief
1290         return the MPI rank number of the local data
1291             MPI_COMM_WORLD is assumed and the result of MPI_Comm_rank()
1292             is returned
1293      */
1294      ESCRIPT_DLL_API
1295        int
1296        get_MPISize(void) const;
1297    
1298      /**
1299         \brief
1300         return the MPI rank number of the local data
1301             MPI_COMM_WORLD is assumed and returned.
1302      */
1303      ESCRIPT_DLL_API
1304        MPI_Comm
1305        get_MPIComm(void) const;
1306    
1307      /**
1308         \brief
1309         return the object produced by the factory, which is a DataConstant or DataExpanded
1310      */
1311      ESCRIPT_DLL_API
1312        DataAbstract*
1313        borrowData(void) const;
1314    
1315   protected:   protected:
1316    
1317   private:   private:
# Line 940  class Data { Line 1334  class Data {
1334       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
1335       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.
1336    */    */
1337    template <class UnaryFunction>    template <class BinaryFunction>
1338    inline    inline
1339    double    double
1340    algorithm(UnaryFunction operation) const;    algorithm(BinaryFunction operation,
1341                double initial_value) const;
1342    
1343    /**    /**
1344       \brief       \brief
# Line 952  class Data { Line 1347  class Data {
1347       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
1348       this Data object       this Data object
1349    */    */
1350    template <class UnaryFunction>    template <class BinaryFunction>
1351    inline    inline
1352    Data    Data
1353    dp_algorithm(UnaryFunction operation) const;    dp_algorithm(BinaryFunction operation,
1354                   double initial_value) const;
1355    
1356    /**    /**
1357       \brief       \brief
# Line 973  class Data { Line 1369  class Data {
1369    
1370    /**    /**
1371       \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  
1372       Convert the data type of the RHS to match this.       Convert the data type of the RHS to match this.
1373       \param right - Input - data type to match.       \param right - Input - data type to match.
1374    */    */
# Line 1008  class Data { Line 1393  class Data {
1393               const FunctionSpace& what,               const FunctionSpace& what,
1394               bool expanded);               bool expanded);
1395    
1396    /**    //
1397       \brief    // flag to protect the data object against any update
1398       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);  
1399    
1400    //    //
1401    // pointer to the actual data object    // pointer to the actual data object
1402    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
1403    
1404      //
1405      // pointer to the internal profiling data
1406      struct profDataEntry *profData;
1407    
1408  };  };
1409    
1410  template <class IValueType>  template <class IValueType>
# Line 1049  Data::initialise(const IValueType& value Line 1432  Data::initialise(const IValueType& value
1432  /**  /**
1433     Binary Data object operators.     Binary Data object operators.
1434  */  */
1435    inline double rpow(double x,double y)
1436    {
1437        return pow(y,x);
1438    };
1439    
1440  /**  /**
1441    \brief    \brief
1442    Operator+    Operator+
1443    Takes two Data objects.    Takes two Data objects.
1444  */  */
1445  Data operator+(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator+(const Data& left, const Data& right);
1446    
1447  /**  /**
1448    \brief    \brief
1449    Operator-    Operator-
1450    Takes two Data objects.    Takes two Data objects.
1451  */  */
1452  Data operator-(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator-(const Data& left, const Data& right);
1453    
1454  /**  /**
1455    \brief    \brief
1456    Operator*    Operator*
1457    Takes two Data objects.    Takes two Data objects.
1458  */  */
1459  Data operator*(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator*(const Data& left, const Data& right);
1460    
1461  /**  /**
1462    \brief    \brief
1463    Operator/    Operator/
1464    Takes two Data objects.    Takes two Data objects.
1465  */  */
1466  Data operator/(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator/(const Data& left, const Data& right);
1467    
1468  /**  /**
1469    \brief    \brief
# Line 1084  Data operator/(const Data& left, const D Line 1471  Data operator/(const Data& left, const D
1471    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1472    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1473  */  */
1474  Data operator+(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator+(const Data& left, const boost::python::object& right);
1475    
1476  /**  /**
1477    \brief    \brief
# Line 1092  Data operator+(const Data& left, const b Line 1479  Data operator+(const Data& left, const b
1479    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1480    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1481  */  */
1482  Data operator-(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator-(const Data& left, const boost::python::object& right);
1483    
1484  /**  /**
1485    \brief    \brief
# Line 1100  Data operator-(const Data& left, const b Line 1487  Data operator-(const Data& left, const b
1487    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1488    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1489  */  */
1490  Data operator*(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator*(const Data& left, const boost::python::object& right);
1491    
1492  /**  /**
1493    \brief    \brief
# Line 1108  Data operator*(const Data& left, const b Line 1495  Data operator*(const Data& left, const b
1495    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1496    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1497  */  */
1498  Data operator/(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator/(const Data& left, const boost::python::object& right);
1499    
1500  /**  /**
1501    \brief    \brief
# Line 1116  Data operator/(const Data& left, const b Line 1503  Data operator/(const Data& left, const b
1503    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1504    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1505  */  */
1506  Data operator+(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator+(const boost::python::object& left, const Data& right);
1507    
1508  /**  /**
1509    \brief    \brief
# Line 1124  Data operator+(const boost::python::obje Line 1511  Data operator+(const boost::python::obje
1511    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1512    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1513  */  */
1514  Data operator-(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator-(const boost::python::object& left, const Data& right);
1515    
1516  /**  /**
1517    \brief    \brief
# Line 1132  Data operator-(const boost::python::obje Line 1519  Data operator-(const boost::python::obje
1519    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1520    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1521  */  */
1522  Data operator*(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator*(const boost::python::object& left, const Data& right);
1523    
1524  /**  /**
1525    \brief    \brief
# Line 1140  Data operator*(const boost::python::obje Line 1527  Data operator*(const boost::python::obje
1527    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1528    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1529  */  */
1530  Data operator/(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator/(const boost::python::object& left, const Data& right);
1531    
1532  /**  /**
1533    \brief    \brief
1534    Output operator    Output operator
1535  */  */
1536  std::ostream& operator<<(std::ostream& o, const Data& data);  ESCRIPT_DLL_API std::ostream& operator<<(std::ostream& o, const Data& data);
1537    
1538    /**
1539      \brief
1540      Compute a tensor product of two Data objects
1541      \param arg0 - Input - Data object
1542      \param arg1 - Input - Data object
1543      \param axis_offset - Input - axis offset
1544      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1545    */
1546    ESCRIPT_DLL_API
1547    Data
1548    C_GeneralTensorProduct(Data& arg0,
1549                         Data& arg1,
1550                         int axis_offset=0,
1551                         int transpose=0);
1552    
1553  /**  /**
1554    \brief    \brief
# Line 1154  std::ostream& operator<<(std::ostream& o Line 1556  std::ostream& operator<<(std::ostream& o
1556    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
1557    be relied on. Requires further implementation.    be relied on. Requires further implementation.
1558  */  */
1559  //bool operator==(const Data& left, const Data& right);  //ESCRIPT_DLL_API bool operator==(const Data& left, const Data& right);
1560    
1561  /**  /**
1562    \brief    \brief
# Line 1170  Data::binaryOp(const Data& right, Line 1572  Data::binaryOp(const Data& right,
1572     //     //
1573     // 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
1574     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1575       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1576     }     }
1577     //     //
1578     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1222  Data::binaryOp(const Data& right, Line 1624  Data::binaryOp(const Data& right,
1624       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");
1625       escript::binaryOp(*leftC,*rightC,operation);       escript::binaryOp(*leftC,*rightC,operation);
1626     }     }
1627  }     #if defined DOPROF
1628       profData->binary++;
1629  /**     #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);  
    }  
1630  }  }
1631    
1632  /**  /**
# Line 1317  Data::unaryOp(UnaryFunction operation) Line 1682  Data::unaryOp(UnaryFunction operation)
1682    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.
1683    Calls escript::algorithm.    Calls escript::algorithm.
1684  */  */
1685  template <class UnaryFunction>  template <class BinaryFunction>
1686  inline  inline
1687  double  double
1688  Data::algorithm(UnaryFunction operation) const  Data::algorithm(BinaryFunction operation, double initial_value) const
1689  {  {
1690    if (isExpanded()) {    if (isExpanded()) {
1691      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1692      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1693      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1694    } else if (isTagged()) {    } else if (isTagged()) {
1695      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1696      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1697      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1698    } else if (isConstant()) {    } else if (isConstant()) {
1699      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1700      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1701      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1702    }    }
1703    return 0;    return 0;
1704  }  }
# Line 1346  Data::algorithm(UnaryFunction operation) Line 1711  Data::algorithm(UnaryFunction operation)
1711    rank 0 Data object.    rank 0 Data object.
1712    Calls escript::dp_algorithm.    Calls escript::dp_algorithm.
1713  */  */
1714  template <class UnaryFunction>  template <class BinaryFunction>
1715  inline  inline
1716  Data  Data
1717  Data::dp_algorithm(UnaryFunction operation) const  Data::dp_algorithm(BinaryFunction operation, double initial_value) const
1718  {  {
   Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());  
1719    if (isExpanded()) {    if (isExpanded()) {
1720        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1721      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
1722      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1723      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1724      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1725      escript::dp_algorithm(*dataE,*resultE,operation);      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
1726        return result;
1727    } else if (isTagged()) {    } else if (isTagged()) {
1728      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1729        DataArrayView::ShapeType viewShape;
1730        DataArrayView::ValueType viewData(1);
1731        viewData[0]=0;
1732        DataArrayView defaultValue(viewData,viewShape);
1733        DataTagged::TagListType keys;
1734        DataTagged::ValueListType values;
1735        DataTagged::DataMapType::const_iterator i;
1736        for (i=dataT->getTagLookup().begin();i!=dataT->getTagLookup().end();i++) {
1737          keys.push_back(i->first);
1738          values.push_back(defaultValue);
1739        }
1740        Data result(keys,values,defaultValue,getFunctionSpace());
1741      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1742      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1743      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1744      escript::dp_algorithm(*dataT,*resultT,operation);      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
1745        return result;
1746    } else if (isConstant()) {    } else if (isConstant()) {
1747        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1748      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1749      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1750      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1751      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1752      escript::dp_algorithm(*dataC,*resultC,operation);      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
1753        return result;
1754    }    }
1755    return result;    Data falseRetVal; // to keep compiler quiet
1756      return falseRetVal;
1757  }  }
1758    
1759  }  }

Legend:
Removed from v.122  
changed lines
  Added in v.921

  ViewVC Help
Powered by ViewVC 1.1.26