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

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

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

trunk/esys2/escript/src/Data/Data.h revision 97 by jgs, Tue Dec 14 05:39:33 2004 UTC trunk/escript/src/Data.h revision 789 by dhawcroft, Wed Jul 26 05:41:11 2006 UTC
# Line 1  Line 1 
1  // $Id$  // $Id$
2  /*=============================================================================  /*
3     ************************************************************
4   ******************************************************************************   *          Copyright 2006 by ACcESS MNRF                   *
5   *                                                                            *   *                                                          *
6   *       COPYRIGHT ACcESS 2004 -  All Rights Reserved                         *   *              http://www.access.edu.au                    *
7   *                                                                            *   *       Primary Business: Queensland, Australia            *
8   * This software is the property of ACcESS.  No part of this code             *   *  Licensed under the Open Software License version 3.0    *
9   * may be copied in any form or by any means without the expressed written    *   *     http://www.opensource.org/licenses/osl-3.0.php       *
10   * consent of ACcESS.  Copying, use or modification of this software          *   *                                                          *
11   * by any unauthorised person is illegal unless that                          *   ************************************************************
12   * person has a software license agreement with ACcESS.                       *  */
  *                                                                            *  
  ******************************************************************************  
13    
14  ******************************************************************************/  /** \file Data.h */
15    
16  #ifndef DATA_H  #ifndef DATA_H
17  #define DATA_H  #define DATA_H
18    #include "system_dep.h"
19    
20  #include "escript/Data/DataAbstract.h"  #include "DataAbstract.h"
21  #include "escript/Data/DataTagged.h"  #include "DataAlgorithm.h"
22  #include "escript/Data/FunctionSpace.h"  #include "FunctionSpace.h"
23  #include "escript/Data/BinaryOp.h"  #include "BinaryOp.h"
24  #include "escript/Data/UnaryOp.h"  #include "UnaryOp.h"
25    #include "DataException.h"
26    
27  extern "C" {  extern "C" {
28  #include "escript/Data/DataC.h"  #include "DataC.h"
29    #include "paso/Paso.h"
30  }  }
31    
 #include <iostream>  
32  #include <string>  #include <string>
 #include <memory>  
33  #include <algorithm>  #include <algorithm>
34    
35  #include <boost/shared_ptr.hpp>  #include <boost/shared_ptr.hpp>
36  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
 #include <boost/python/list.hpp>  
37  #include <boost/python/tuple.hpp>  #include <boost/python/tuple.hpp>
38  #include <boost/python/numeric.hpp>  #include <boost/python/numeric.hpp>
39    
40    namespace escript {
41    
42    //
43    // Forward declaration for various implementations of Data.
44    class DataConstant;
45    class DataTagged;
46    class DataExpanded;
47    
48  /**  /**
49     \brief     \brief
50     Data is essentially a factory class which creates the appropriate Data     Data creates the appropriate Data object for the given construction
51     object for the given construction arguments. It retains control over     arguments.
    the object created for the lifetime of the object.  
    The type of Data object referred to may change during the lifetime of  
    the Data object.  
52    
53     Description:     Description:
54     Data is essentially a factory class which creates the appropriate Data     Data is essentially a factory class which creates the appropriate Data
# Line 54  extern "C" { Line 57  extern "C" {
57     The type of Data object referred to may change during the lifetime of     The type of Data object referred to may change during the lifetime of
58     the Data object.     the Data object.
59  */  */
   
 namespace escript {  
   
 //  
 // Forward declaration for various implimentations of Data.  
 class DataEmpty;  
 class DataConstant;  
 class DataTagged;  
 class DataExpanded;  
   
60  class Data {  class Data {
61    
62    public:    public:
63    
64      // These typedefs allow function names to be cast to pointers
65      // to functions of the appropriate type when calling unaryOp etc.
66    typedef double (*UnaryDFunPtr)(double);    typedef double (*UnaryDFunPtr)(double);
67    typedef double (*BinaryDFunPtr)(double,double);    typedef double (*BinaryDFunPtr)(double,double);
68    
# Line 80  class Data { Line 75  class Data {
75       Default constructor.       Default constructor.
76       Creates a DataEmpty object.       Creates a DataEmpty object.
77    */    */
78      ESCRIPT_DLL_API
79    Data();    Data();
80    
81    /**    /**
# Line 87  class Data { Line 83  class Data {
83       Copy constructor.       Copy constructor.
84       WARNING: Only performs a shallow copy.       WARNING: Only performs a shallow copy.
85    */    */
86      ESCRIPT_DLL_API
87    Data(const Data& inData);    Data(const Data& inData);
88    
89    /**    /**
# Line 95  class Data { Line 92  class Data {
92       function space of inData the inData are tried to be interpolated to what,       function space of inData the inData are tried to be interpolated to what,
93       otherwise a shallow copy of inData is returned.       otherwise a shallow copy of inData is returned.
94    */    */
95      ESCRIPT_DLL_API
96    Data(const Data& inData,    Data(const Data& inData,
97         const FunctionSpace& what);         const FunctionSpace& what);
98    
# Line 108  class Data { Line 106  class Data {
106                         the value. Otherwise a more efficient storage                         the value. Otherwise a more efficient storage
107                         mechanism will be used.                         mechanism will be used.
108    */    */
109      ESCRIPT_DLL_API
110    Data(const DataArrayView& value,    Data(const DataArrayView& value,
111         const FunctionSpace& what=FunctionSpace(),         const FunctionSpace& what=FunctionSpace(),
112         bool expanded=false);         bool expanded=false);
# Line 123  class Data { Line 122  class Data {
122                         the given value. Otherwise a more efficient storage                         the given value. Otherwise a more efficient storage
123                         mechanism will be used.                         mechanism will be used.
124    */    */
125      ESCRIPT_DLL_API
126    Data(double value,    Data(double value,
127         const DataArrayView::ShapeType& dataPointShape=DataArrayView::ShapeType(),         const DataArrayView::ShapeType& dataPointShape=DataArrayView::ShapeType(),
128         const FunctionSpace& what=FunctionSpace(),         const FunctionSpace& what=FunctionSpace(),
# Line 135  class Data { Line 135  class Data {
135       \param inData - Input - Input Data object.       \param inData - Input - Input Data object.
136       \param region - Input - Region to copy.       \param region - Input - Region to copy.
137    */    */
138      ESCRIPT_DLL_API
139    Data(const Data& inData,    Data(const Data& inData,
140         const DataArrayView::RegionType& region);         const DataArrayView::RegionType& region);
141    
# Line 150  class Data { Line 151  class Data {
151       \param what - Input - A description of what this data represents.       \param what - Input - A description of what this data represents.
152       \param expanded - Input - Flag, if true fill the entire container with       \param expanded - Input - Flag, if true fill the entire container with
153                         the appropriate values.                         the appropriate values.
154        ==>*
155    */    */
156      ESCRIPT_DLL_API
157    Data(const DataTagged::TagListType& tagKeys,    Data(const DataTagged::TagListType& tagKeys,
158         const DataTagged::ValueListType& values,         const DataTagged::ValueListType& values,
159         const DataArrayView& defaultValue,         const DataArrayView& defaultValue,
# Line 167  class Data { Line 170  class Data {
170                         the value. Otherwise a more efficient storage                         the value. Otherwise a more efficient storage
171                         mechanism will be used.                         mechanism will be used.
172    */    */
173      ESCRIPT_DLL_API
174    Data(const boost::python::numeric::array& value,    Data(const boost::python::numeric::array& value,
175         const FunctionSpace& what=FunctionSpace(),         const FunctionSpace& what=FunctionSpace(),
176         bool expanded=false);         bool expanded=false);
# Line 182  class Data { Line 186  class Data {
186                         the value. Otherwise a more efficient storage                         the value. Otherwise a more efficient storage
187                         mechanism will be used.                         mechanism will be used.
188    */    */
189      ESCRIPT_DLL_API
190    Data(const boost::python::object& value,    Data(const boost::python::object& value,
191         const FunctionSpace& what=FunctionSpace(),         const FunctionSpace& what=FunctionSpace(),
192         bool expanded=false);         bool expanded=false);
# Line 195  class Data { Line 200  class Data {
200       \param value - Input - Input data.       \param value - Input - Input data.
201       \param other - Input - contains all other parameters.       \param other - Input - contains all other parameters.
202    */    */
203      ESCRIPT_DLL_API
204    Data(const boost::python::object& value,    Data(const boost::python::object& value,
205         const Data& other);         const Data& other);
206    
# Line 202  class Data { Line 208  class Data {
208       \brief       \brief
209       Constructor which creates a DataConstant of "shape" with constant value.       Constructor which creates a DataConstant of "shape" with constant value.
210    */    */
211      ESCRIPT_DLL_API
212    Data(double value,    Data(double value,
213         const boost::python::tuple& shape=boost::python::make_tuple(),         const boost::python::tuple& shape=boost::python::make_tuple(),
214         const FunctionSpace& what=FunctionSpace(),         const FunctionSpace& what=FunctionSpace(),
215         bool expanded=false);         bool expanded=false);
216      /**
217         \brief
218         Destructor
219      */
220      ESCRIPT_DLL_API
221      ~Data();
222    
223    /**    /**
224       \brief       \brief
225       Perform a deep copy.       Perform a deep copy.
226    */    */
227      ESCRIPT_DLL_API
228    void    void
229    copy(const Data& other);    copy(const Data& other);
230    
# Line 220  class Data { Line 234  class Data {
234    
235    /**    /**
236       \brief       \brief
237         switches on update protection
238    
239      */
240      ESCRIPT_DLL_API
241      void
242      setProtection();
243    
244      /**
245         \brief
246         Returns trueif the data object is protected against update
247    
248      */
249      ESCRIPT_DLL_API
250      bool
251      isProtected() const;
252      /**
253         \brief
254         Return the values of all data-points as a single python numarray object.
255      */
256      ESCRIPT_DLL_API
257      const boost::python::numeric::array
258      convertToNumArray();
259    
260      /**
261         \brief
262         Return the values of all data-points for the given sample as a single python numarray object.
263      */
264      ESCRIPT_DLL_API
265      const boost::python::numeric::array
266      convertToNumArrayFromSampleNo(int sampleNo);
267    
268      /**
269         \brief
270         Return the value of the specified data-point as a single python numarray object.
271      */
272    #ifndef PASO_MPI  
273      ESCRIPT_DLL_API
274      const boost::python::numeric::array
275      convertToNumArrayFromDPNo(int sampleNo,
276                                int dataPointNo);
277    #else
278      ESCRIPT_DLL_API
279      const boost::python::numeric::array
280      convertToNumArrayFromDPNo(int procNo,
281                    int sampleNo,
282                    int dataPointNo);
283    #endif
284    
285    
286      /**
287         \brief
288         Fills the expanded Data object from values of a python numarray object.
289      */
290      ESCRIPT_DLL_API
291      void
292      fillFromNumArray(const boost::python::numeric::array);
293    
294      /**
295         \brief
296         Return the tag number associated with the given data-point.
297    
298         The data-point number here corresponds to the data-point number in the
299         numarray returned by convertToNumArray.
300      */
301      ESCRIPT_DLL_API
302      int
303      getTagNumber(int dpno);
304    
305      /**
306         \brief
307       Return the C wrapper for the Data object.       Return the C wrapper for the Data object.
308    */    */
309      ESCRIPT_DLL_API
310    escriptDataC    escriptDataC
311    getDataC();    getDataC();
312    
# Line 229  class Data { Line 314  class Data {
314       \brief       \brief
315       Return the C wrapper for the Data object - const version.       Return the C wrapper for the Data object - const version.
316    */    */
317      ESCRIPT_DLL_API
318    escriptDataC    escriptDataC
319    getDataC() const;    getDataC() const;
320    
# Line 236  class Data { Line 322  class Data {
322       \brief       \brief
323       Write the data as a string.       Write the data as a string.
324    */    */
325      ESCRIPT_DLL_API
326    inline    inline
327    std::string    std::string
328    toString() const    toString() const
# Line 249  class Data { Line 336  class Data {
336       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
337       to manipulate the point data.       to manipulate the point data.
338    */    */
339      ESCRIPT_DLL_API
340    inline    inline
341    const DataArrayView&    const DataArrayView&
342    getPointDataView() const    getPointDataView() const
# Line 260  class Data { Line 348  class Data {
348       \brief       \brief
349       Whatever the current Data type make this into a DataExpanded.       Whatever the current Data type make this into a DataExpanded.
350    */    */
351      ESCRIPT_DLL_API
352    void    void
353    expand();    expand();
354    
# Line 268  class Data { Line 357  class Data {
357       If possible convert this Data to DataTagged. This will only allow       If possible convert this Data to DataTagged. This will only allow
358       Constant data to be converted to tagged. An attempt to convert       Constant data to be converted to tagged. An attempt to convert
359       Expanded data to tagged will throw an exception.       Expanded data to tagged will throw an exception.
360        ==>*
361    */    */
362      ESCRIPT_DLL_API
363    void    void
364    tag();    tag();
365    
# Line 276  class Data { Line 367  class Data {
367       \brief       \brief
368       Return true if this Data is expanded.       Return true if this Data is expanded.
369    */    */
370      ESCRIPT_DLL_API
371    bool    bool
372    isExpanded() const;    isExpanded() const;
373    
# Line 283  class Data { Line 375  class Data {
375       \brief       \brief
376       Return true if this Data is tagged.       Return true if this Data is tagged.
377    */    */
378      ESCRIPT_DLL_API
379    bool    bool
380    isTagged() const;    isTagged() const;
381    
# Line 290  class Data { Line 383  class Data {
383       \brief       \brief
384       Return true if this Data is constant.       Return true if this Data is constant.
385    */    */
386      ESCRIPT_DLL_API
387    bool    bool
388    isConstant() const;    isConstant() const;
389    
# Line 297  class Data { Line 391  class Data {
391       \brief       \brief
392       Return true if this Data is empty.       Return true if this Data is empty.
393    */    */
394      ESCRIPT_DLL_API
395    bool    bool
396    isEmpty() const;    isEmpty() const;
397    
# Line 304  class Data { Line 399  class Data {
399       \brief       \brief
400       Return the function space.       Return the function space.
401    */    */
402      ESCRIPT_DLL_API
403    inline    inline
404    const FunctionSpace&    const FunctionSpace&
405    getFunctionSpace() const    getFunctionSpace() const
# Line 315  class Data { Line 411  class Data {
411       \brief       \brief
412       Return a copy of the function space.       Return a copy of the function space.
413    */    */
414      ESCRIPT_DLL_API
415    const FunctionSpace    const FunctionSpace
416    getCopyOfFunctionSpace() const;    getCopyOfFunctionSpace() const;
417    
# Line 322  class Data { Line 419  class Data {
419       \brief       \brief
420       Return the domain.       Return the domain.
421    */    */
422      ESCRIPT_DLL_API
423    inline    inline
424    const AbstractDomain&    const AbstractDomain&
425    getDomain() const    getDomain() const
# Line 333  class Data { Line 431  class Data {
431       \brief       \brief
432       Return a copy of the domain.       Return a copy of the domain.
433    */    */
434      ESCRIPT_DLL_API
435    const AbstractDomain    const AbstractDomain
436    getCopyOfDomain() const;    getCopyOfDomain() const;
437    
# Line 340  class Data { Line 439  class Data {
439       \brief       \brief
440       Return the rank of the point data.       Return the rank of the point data.
441    */    */
442      ESCRIPT_DLL_API
443    inline    inline
444    int    int
445    getDataPointRank() const    getDataPointRank() const
# Line 351  class Data { Line 451  class Data {
451       \brief       \brief
452       Return the number of samples.       Return the number of samples.
453    */    */
454      ESCRIPT_DLL_API
455    inline    inline
456    int    int
457    getNumSamples() const    getNumSamples() const
# Line 362  class Data { Line 463  class Data {
463       \brief       \brief
464       Return the number of data points per sample.       Return the number of data points per sample.
465    */    */
466      ESCRIPT_DLL_API
467    inline    inline
468    int    int
469    getNumDataPointsPerSample() const    getNumDataPointsPerSample() const
# Line 375  class Data { Line 477  class Data {
477       preferred interface but is provided for use by C code.       preferred interface but is provided for use by C code.
478       \param sampleNo - Input - the given sample no.       \param sampleNo - Input - the given sample no.
479    */    */
480      ESCRIPT_DLL_API
481    inline    inline
482    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
483    getSampleData(DataAbstract::ValueType::size_type sampleNo)    getSampleData(DataAbstract::ValueType::size_type sampleNo)
# Line 388  class Data { Line 491  class Data {
491       access data that isn't tagged an exception will be thrown.       access data that isn't tagged an exception will be thrown.
492       \param tag - Input - the tag key.       \param tag - Input - the tag key.
493    */    */
494      ESCRIPT_DLL_API
495    inline    inline
496    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
497    getSampleDataByTag(int tag)    getSampleDataByTag(int tag)
# Line 397  class Data { Line 501  class Data {
501    
502    /**    /**
503       \brief       \brief
504         Assign the given value to the data-points referenced by the given
505         reference number.
506    
507         The value supplied is a python numarray object.  The data from this numarray
508         is unpacked into a DataArray, and this is used to set the corresponding
509         data-points in the underlying Data object.
510    
511         If the underlying Data object cannot be accessed via reference numbers, an
512         exception will be thrown.
513    
514         \param ref - Input - reference number.
515         \param value - Input - value to assign to data-points associated with
516                                the given reference number.
517      */
518      ESCRIPT_DLL_API
519      void
520      setRefValue(int ref,
521                  const boost::python::numeric::array& value);
522    
523      /**
524         \brief
525         Return the values associated with the data-points referenced by the given
526         reference number.
527    
528         The value supplied is a python numarray object. The data from the corresponding
529         data-points in this Data object are packed into the given numarray object.
530    
531         If the underlying Data object cannot be accessed via reference numbers, an
532         exception will be thrown.
533    
534         \param ref - Input - reference number.
535         \param value - Output - object to receive values from data-points
536                                 associated with the given reference number.
537      */
538      ESCRIPT_DLL_API
539      void
540      getRefValue(int ref,
541                  boost::python::numeric::array& value);
542    
543      /**
544         \brief
545       Return a view into the data for the data point specified.       Return a view into the data for the data point specified.
546       NOTE: Construction of the DataArrayView is a relatively expensive       NOTE: Construction of the DataArrayView is a relatively expensive
547       operation.       operation.
548       \param sampleNo - Input -       \param sampleNo - Input -
549       \param dataPointNo - Input -       \param dataPointNo - Input -
550    */    */
551      ESCRIPT_DLL_API
552    inline    inline
553    DataArrayView    DataArrayView
554    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
# Line 415  class Data { Line 561  class Data {
561       \brief       \brief
562       Return a reference to the data point shape.       Return a reference to the data point shape.
563    */    */
564      ESCRIPT_DLL_API
565    const DataArrayView::ShapeType&    const DataArrayView::ShapeType&
566    getDataPointShape() const;    getDataPointShape() const;
567    
# Line 422  class Data { Line 569  class Data {
569       \brief       \brief
570       Return the data point shape as a tuple of integers.       Return the data point shape as a tuple of integers.
571    */    */
572    boost::python::tuple    ESCRIPT_DLL_API
573      const boost::python::tuple
574    getShapeTuple() const;    getShapeTuple() const;
575    
576    /**    /**
# Line 430  class Data { Line 578  class Data {
578       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
579       data point shape dimensions.       data point shape dimensions.
580    */    */
581      ESCRIPT_DLL_API
582    int    int
583    getDataPointSize() const;    getDataPointSize() const;
584    
# Line 437  class Data { Line 586  class Data {
586       \brief       \brief
587       Return the number of doubles stored for this Data.       Return the number of doubles stored for this Data.
588    */    */
589      ESCRIPT_DLL_API
590    DataArrayView::ValueType::size_type    DataArrayView::ValueType::size_type
591    getLength() const;    getLength() const;
592    
# Line 447  class Data { Line 597  class Data {
597       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
598       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
599       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
600        ==>*
601    */    */
602      ESCRIPT_DLL_API
603    void    void
604    setTaggedValue(int tagKey,    setTaggedValue(int tagKey,
605                   const boost::python::object& value);                   const boost::python::object& value);
# Line 459  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       Note: removed for now - this version not needed, and breaks escript.cpp      ==>*
615    */    */
616    /*    ESCRIPT_DLL_API
617    void    void
618    setTaggedValue(int tagKey,    setTaggedValueFromCPP(int tagKey,
619                   const DataArrayView& value);                          const DataArrayView& value);
   */  
620    
621    /**    /**
622      \brief      \brief
623      Copy other Data object into this Data object where mask is positive.      Copy other Data object into this Data object where mask is positive.
624    */    */
625      ESCRIPT_DLL_API
626    void    void
627    copyWithMask(const Data& other,    copyWithMask(const Data& other,
628                 const Data& mask);                 const Data& mask);
# Line 483  class Data { Line 635  class Data {
635       \brief       \brief
636       Interpolates this onto the given functionspace and returns       Interpolates this onto the given functionspace and returns
637       the result as a Data object.       the result as a Data object.
638         *
639    */    */
640      ESCRIPT_DLL_API
641    Data    Data
642    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
643    
# Line 491  class Data { Line 645  class Data {
645       \brief       \brief
646       Calculates the gradient of the data at the data points of functionspace.       Calculates the gradient of the data at the data points of functionspace.
647       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.
648         *
649    */    */
650      ESCRIPT_DLL_API
651    Data    Data
652    gradOn(const FunctionSpace& functionspace) const;    gradOn(const FunctionSpace& functionspace) const;
653    
654      ESCRIPT_DLL_API
655    Data    Data
656    grad() const;    grad() const;
657    
658    /**    /**
659       \brief       \brief
660       Calculate the integral over the function space domain.       Calculate the integral over the function space domain.
661         *
662    */    */
663      ESCRIPT_DLL_API
664    boost::python::numeric::array    boost::python::numeric::array
665    integrate() const;    integrate() const;
666    
667    /**    /**
668       \brief       \brief
669       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.
670         *
671    */    */
672      ESCRIPT_DLL_API
673    Data    Data
674    wherePositive() const;    wherePositive() const;
675    
676    /**    /**
677       \brief       \brief
678       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.
679         *
680    */    */
681      ESCRIPT_DLL_API
682    Data    Data
683    whereNegative() const;    whereNegative() const;
684    
685    /**    /**
686       \brief       \brief
687       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.
688         *
689    */    */
690      ESCRIPT_DLL_API
691    Data    Data
692    whereNonNegative() const;    whereNonNegative() const;
693    
694    /**    /**
695       \brief       \brief
696       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.
697         *
698    */    */
699      ESCRIPT_DLL_API
700    Data    Data
701    whereNonPositive() const;    whereNonPositive() const;
702    
703    /**    /**
704       \brief       \brief
705       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.
706         *
707    */    */
708      ESCRIPT_DLL_API
709    Data    Data
710    whereZero() const;    whereZero(double tol=0.0) const;
711    
712    /**    /**
713       \brief       \brief
714       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.
715         *
716      */
717      ESCRIPT_DLL_API
718      Data
719      whereNonZero(double tol=0.0) const;
720    
721      /**
722         \brief
723         Return the maximum absolute value of this Data object.
724         *
725      */
726      ESCRIPT_DLL_API
727      double
728      Lsup() const;
729    
730      /**
731         \brief
732         Return the minimum absolute value of this Data object.
733         *
734      */
735      ESCRIPT_DLL_API
736      double
737      Linf() const;
738    
739      /**
740         \brief
741         Return the maximum value of this Data object.
742         *
743      */
744      ESCRIPT_DLL_API
745      double
746      sup() const;
747    
748      /**
749         \brief
750         Return the minimum value of this Data object.
751         *
752      */
753      ESCRIPT_DLL_API
754      double
755      inf() const;
756    
757      /**
758         \brief
759         Return the absolute value of each data point of this Data object.
760         *
761      */
762      ESCRIPT_DLL_API
763      Data
764      abs() const;
765    
766      /**
767         \brief
768         Return the maximum value of each data point of this Data object.
769         *
770    */    */
771      ESCRIPT_DLL_API
772    Data    Data
773    whereNonZero() const;    maxval() const;
774    
775      /**
776         \brief
777         Return the minimum value of each data point of this Data object.
778         *
779      */
780      ESCRIPT_DLL_API
781      Data
782      minval() const;
783    
784      /**
785         \brief
786         Return the (sample number, data-point number) of the data point with
787         the minimum value in this Data object.
788      */
789      ESCRIPT_DLL_API
790      const boost::python::tuple
791      mindp() const;
792    
793      ESCRIPT_DLL_API
794      void
795    #ifndef PASO_MPI
796      calc_mindp(int& SampleNo,
797                 int& DataPointNo) const;
798    #else
799      calc_mindp(int& ProcNo,
800                            int& SampleNo,  
801                 int& DataPointNo) const;
802    #endif
803      /**
804         \brief
805         Return the sign of each data point of this Data object.
806         -1 for negative values, zero for zero values, 1 for positive values.
807         *
808      */
809      ESCRIPT_DLL_API
810      Data
811      sign() const;
812    
813      /**
814         \brief
815         Return the symmetric part of a matrix which is half the matrix plus its transpose.
816         *
817      */
818      ESCRIPT_DLL_API
819      Data
820      symmetric() const;
821    
822      /**
823         \brief
824         Return the nonsymmetric part of a matrix which is half the matrix minus its transpose.
825         *
826      */
827      ESCRIPT_DLL_API
828      Data
829      nonsymmetric() const;
830    
831      /**
832         \brief
833         Return the trace of a matrix
834         *
835      */
836      ESCRIPT_DLL_API
837      Data
838      matrixtrace(int axis_offset) const;
839    
840      /**
841         \brief
842         Transpose each data point of this Data object around the given axis.
843         *
844      */
845      ESCRIPT_DLL_API
846      Data
847      transpose(int axis_offset) const;
848    
849      /**
850         \brief
851         Return the eigenvalues of the symmetric part at each data point of this Data object in increasing values.
852         Currently this function is restricted to rank 2, square shape, and dimension 3.
853         *
854      */
855      ESCRIPT_DLL_API
856      Data
857      eigenvalues() const;
858    
859      /**
860         \brief
861         Return the eigenvalues and corresponding eigenvcetors of the symmetric part at each data point of this Data object.
862         the eigenvalues are ordered in increasing size where eigenvalues with relative difference less than
863         tol are treated as equal. The eigenvectors are orthogonal, normalized and the sclaed such that the
864         first non-zero entry is positive.
865         Currently this function is restricted to rank 2, square shape, and dimension 3
866         *
867      */
868      ESCRIPT_DLL_API
869      const boost::python::tuple
870      eigenvalues_and_eigenvectors(const double tol=1.e-12) const;
871    
872      /**
873         \brief
874         Calculate the trace of each data point of this Data object.
875         *
876      */
877      ESCRIPT_DLL_API
878      Data
879      trace() const;
880    
881    /**    /**
882       \brief       \brief
883       Return the sin of each data point of this Data object.       Return the sin of each data point of this Data object.
884         *
885    */    */
886      ESCRIPT_DLL_API
887    Data    Data
888    sin() const;    sin() const;
889    
890    /**    /**
891       \brief       \brief
892       Return the cos of each data point of this Data object.       Return the cos of each data point of this Data object.
893         *
894    */    */
895      ESCRIPT_DLL_API
896    Data    Data
897    cos() const;    cos() const;
898    
899    /**    /**
900       \brief       \brief
901       Return the tan of each data point of this Data object.       Return the tan of each data point of this Data object.
902         *
903    */    */
904      ESCRIPT_DLL_API
905    Data    Data
906    tan() const;    tan() const;
907    
908    /**    /**
909       \brief       \brief
910       Return the log to base 10 of each data point of this Data object.       Return the asin of each data point of this Data object.
911         *
912    */    */
913      ESCRIPT_DLL_API
914    Data    Data
915    log() const;    asin() const;
916    
917    /**    /**
918       \brief       \brief
919       Return the natural log of each data point of this Data object.       Return the acos of each data point of this Data object.
920         *
921    */    */
922      ESCRIPT_DLL_API
923    Data    Data
924    ln() const;    acos() const;
925    
926    /**    /**
927       \brief       \brief
928       Return the maximum absolute value of this Data object.       Return the atan of each data point of this Data object.
929         *
930    */    */
931    double    ESCRIPT_DLL_API
932    Lsup() const;    Data
933      atan() const;
934    
935    /**    /**
936       \brief       \brief
937       Return the maximum value of this Data object.       Return the sinh of each data point of this Data object.
938         *
939    */    */
940    double    ESCRIPT_DLL_API
941    sup() const;    Data
942      sinh() const;
943    
944    /**    /**
945       \brief       \brief
946       Return the minimum value of this Data object.       Return the cosh of each data point of this Data object.
947         *
948    */    */
949    double    ESCRIPT_DLL_API
950    inf() const;    Data
951      cosh() const;
952    
953    /**    /**
954       \brief       \brief
955       Return the absolute value of each data point of this Data object.       Return the tanh of each data point of this Data object.
956         *
957    */    */
958      ESCRIPT_DLL_API
959    Data    Data
960    abs() const;    tanh() const;
961    
962    /**    /**
963       \brief       \brief
964       Return the maximum value of each data point of this Data object.       Return the asinh of each data point of this Data object.
965         *
966    */    */
967      ESCRIPT_DLL_API
968    Data    Data
969    maxval() const;    asinh() const;
970    
971    /**    /**
972       \brief       \brief
973       Return the minimum value of each data point of this Data object.       Return the acosh of each data point of this Data object.
974         *
975    */    */
976      ESCRIPT_DLL_API
977    Data    Data
978    minval() const;    acosh() const;
979    
980    /**    /**
981       \brief       \brief
982       Return the length of each data point of this Data object.       Return the atanh of each data point of this Data object.
983       sqrt(sum(A[i,j,k,l]^2))       *
984    */    */
985      ESCRIPT_DLL_API
986    Data    Data
987    length() const;    atanh() const;
988    
989    /**    /**
990       \brief       \brief
991       Return the sign of each data point of this Data object.       Return the log to base 10 of each data point of this Data object.
992       -1 for negative values, zero for zero values, 1 for positive values.       *
993    */    */
994      ESCRIPT_DLL_API
995    Data    Data
996    sign() const;    log10() const;
997    
998    /**    /**
999      \transpose       \brief
1000      Transpose each data point of this Data object around the given axis.       Return the natural log of each data point of this Data object.
1001         *
1002    */    */
1003      ESCRIPT_DLL_API
1004    Data    Data
1005    transpose(int axis) const;    log() const;
1006    
1007    /**    /**
1008      \trace       \brief
1009      Calculate the trace of each data point of this Data object.       Return the exponential function of each data point of this Data object.
1010      sum(A[i,i,i,i])       *
1011    */    */
1012      ESCRIPT_DLL_API
1013    Data    Data
1014    trace() const;    exp() const;
1015    
1016    /**    /**
1017      \exp       \brief
1018      Return the exponential function of each data point of this Data object.       Return the square root of each data point of this Data object.
1019         *
1020    */    */
1021      ESCRIPT_DLL_API
1022    Data    Data
1023    exp() const;    sqrt() const;
1024    
1025    /**    /**
1026      \sqrt       \brief
1027      Return the square root of each data point of this Data object.       Return the negation of each data point of this Data object.
1028         *
1029    */    */
1030      ESCRIPT_DLL_API
1031    Data    Data
1032    sqrt() const;    neg() const;
1033    
1034      /**
1035         \brief
1036         Return the identity of each data point of this Data object.
1037         Simply returns this object unmodified.
1038         *
1039      */
1040      ESCRIPT_DLL_API
1041      Data
1042      pos() const;
1043    
1044    /**    /**
1045       \brief       \brief
1046       Return the given power of each data point of this Data object.       Return the given power of each data point of this Data object.
1047    
1048         \param right Input - the power to raise the object to.
1049         *
1050    */    */
1051      ESCRIPT_DLL_API
1052    Data    Data
1053    powD(const Data& right) const;    powD(const Data& right) const;
1054    
1055      /**
1056         \brief
1057         Return the given power of each data point of this boost python object.
1058        
1059         \param right Input - the power to raise the object to.
1060         *
1061       */
1062      ESCRIPT_DLL_API
1063    Data    Data
1064    powO(const boost::python::object& right) const;    powO(const boost::python::object& right) const;
1065    
1066    /**    /**
1067      \brief       \brief
1068      Return the negation of each data point of this Data object.       Return the given power of each data point of this boost python object.
1069    */      
1070         \param left Input - the bases
1071         *
1072       */
1073    
1074      ESCRIPT_DLL_API
1075    Data    Data
1076    neg() const;    rpowO(const boost::python::object& left) const;
1077    
1078    /**    /**
1079      \brief       \brief
1080      Return the identity of each data point of this Data object.       writes the object to a file in the DX file format
     Simply returns this object unmodified.  
1081    */    */
1082    Data    ESCRIPT_DLL_API
1083    pos() const;    void
1084      saveDX(std::string fileName) const;
1085    
1086      /**
1087         \brief
1088         writes the object to a file in the VTK file format
1089      */
1090      ESCRIPT_DLL_API
1091      void
1092      saveVTK(std::string fileName) const;
1093    
1094    /**    /**
1095       \brief       \brief
1096       Overloaded operator +=       Overloaded operator +=
1097       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1098         *
1099    */    */
1100      ESCRIPT_DLL_API
1101    Data& operator+=(const Data& right);    Data& operator+=(const Data& right);
1102      ESCRIPT_DLL_API
1103    Data& operator+=(const boost::python::object& right);    Data& operator+=(const boost::python::object& right);
1104    
1105    /**    /**
1106       \brief       \brief
1107       Overloaded operator -=       Overloaded operator -=
1108       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1109         *
1110    */    */
1111      ESCRIPT_DLL_API
1112    Data& operator-=(const Data& right);    Data& operator-=(const Data& right);
1113      ESCRIPT_DLL_API
1114    Data& operator-=(const boost::python::object& right);    Data& operator-=(const boost::python::object& right);
1115    
1116   /**   /**
1117       \brief       \brief
1118       Overloaded operator *=       Overloaded operator *=
1119       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1120         *
1121    */    */
1122      ESCRIPT_DLL_API
1123    Data& operator*=(const Data& right);    Data& operator*=(const Data& right);
1124      ESCRIPT_DLL_API
1125    Data& operator*=(const boost::python::object& right);    Data& operator*=(const boost::python::object& right);
1126    
1127   /**   /**
1128       \brief       \brief
1129       Overloaded operator /=       Overloaded operator /=
1130       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1131         *
1132    */    */
1133      ESCRIPT_DLL_API
1134    Data& operator/=(const Data& right);    Data& operator/=(const Data& right);
1135      ESCRIPT_DLL_API
1136    Data& operator/=(const boost::python::object& right);    Data& operator/=(const boost::python::object& right);
1137    
1138    /**    /**
1139       \brief       \brief
1140       Returns true if this can be interpolated to functionspace.       Returns true if this can be interpolated to functionspace.
1141    */    */
1142      ESCRIPT_DLL_API
1143    bool    bool
1144    probeInterpolation(const FunctionSpace& functionspace) const;    probeInterpolation(const FunctionSpace& functionspace) const;
1145    
# Line 748  class Data { Line 1158  class Data {
1158       \param key - Input - python slice tuple specifying       \param key - Input - python slice tuple specifying
1159       slice to return.       slice to return.
1160    */    */
1161      ESCRIPT_DLL_API
1162    Data    Data
1163    getItem(const boost::python::object& key) const;    getItem(const boost::python::object& key) const;
1164    
# Line 755  class Data { Line 1166  class Data {
1166       \brief       \brief
1167       Copies slice from value into this Data object.       Copies slice from value into this Data object.
1168    
      \description  
1169       Implements the [] set operator in python.       Implements the [] set operator in python.
1170       Calls setSlice.       Calls setSlice.
1171    
# Line 763  class Data { Line 1173  class Data {
1173       slice to copy from value.       slice to copy from value.
1174       \param value - Input - Data object to copy from.       \param value - Input - Data object to copy from.
1175    */    */
1176      ESCRIPT_DLL_API
1177    void    void
1178    setItemD(const boost::python::object& key,    setItemD(const boost::python::object& key,
1179             const Data& value);             const Data& value);
1180    
1181      ESCRIPT_DLL_API
1182    void    void
1183    setItemO(const boost::python::object& key,    setItemO(const boost::python::object& key,
1184             const boost::python::object& value);             const boost::python::object& value);
# Line 779  class Data { Line 1191  class Data {
1191       this Data object.       this Data object.
1192    */    */
1193    template <class UnaryFunction>    template <class UnaryFunction>
1194      ESCRIPT_DLL_API
1195    inline    inline
1196    void    void
1197    unaryOp(UnaryFunction operation);    unaryOp(UnaryFunction operation);
# Line 788  class Data { Line 1201  class Data {
1201       Return a Data object containing the specified slice of       Return a Data object containing the specified slice of
1202       this Data object.       this Data object.
1203       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1204         *
1205    */    */
1206      ESCRIPT_DLL_API
1207    Data    Data
1208    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataArrayView::RegionType& region) const;
1209    
# Line 798  class Data { Line 1213  class Data {
1213       Data object.       Data object.
1214       \param value - Input - Data to copy from.       \param value - Input - Data to copy from.
1215       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1216         *
1217    */    */
1218      ESCRIPT_DLL_API
1219    void    void
1220    setSlice(const Data& value,    setSlice(const Data& value,
1221             const DataArrayView::RegionType& region);             const DataArrayView::RegionType& region);
1222    
1223      /**
1224         \brief
1225         Archive the current Data object to the given file.
1226         \param fileName - Input - file to archive to.
1227      */
1228      ESCRIPT_DLL_API
1229      void
1230      archiveData(const std::string fileName);
1231    
1232      /**
1233         \brief
1234         Extract the Data object archived in the given file, overwriting
1235         the current Data object.
1236         Note - the current object must be of type DataEmpty.
1237         \param fileName - Input - file to extract from.
1238         \param fspace - Input - a suitable FunctionSpace descibing the data.
1239      */
1240      ESCRIPT_DLL_API
1241      void
1242      extractData(const std::string fileName,
1243                  const FunctionSpace& fspace);
1244    
1245    
1246    #ifdef PASO_MPI
1247      /**
1248         \brief
1249         print the data values to stdout. Used for debugging
1250      */
1251      ESCRIPT_DLL_API
1252      void
1253        print(void);
1254    
1255      /**
1256         \brief
1257         return the MPI rank number of the local data
1258             MPI_COMM_WORLD is assumed and the result of MPI_Comm_size()
1259             is returned
1260      */
1261      ESCRIPT_DLL_API
1262        int
1263        get_MPIRank(void) const;
1264    
1265      /**
1266         \brief
1267         return the MPI rank number of the local data
1268             MPI_COMM_WORLD is assumed and the result of MPI_Comm_rank()
1269             is returned
1270      */
1271      ESCRIPT_DLL_API
1272        int
1273        get_MPISize(void) const;
1274    
1275      /**
1276         \brief
1277         return the MPI rank number of the local data
1278             MPI_COMM_WORLD is assumed and returned.
1279      */
1280      ESCRIPT_DLL_API
1281        MPI_Comm
1282        get_MPIComm(void) const;
1283    #endif
1284        
1285   protected:   protected:
1286    
1287   private:   private:
# Line 823  class Data { Line 1302  class Data {
1302    /**    /**
1303       \brief       \brief
1304       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
1305       this Data object and return the single double value result.       this Data object according to the given function and return the single value result.
1306    */    */
1307    template <class UnaryFunction>    template <class BinaryFunction>
1308    inline    inline
1309    double    double
1310    algorithm(UnaryFunction operation) const;    algorithm(BinaryFunction operation,
1311                double initial_value) const;
1312    
1313      /**
1314         \brief
1315         Reduce each data-point in this Data object using the given operation. Return a Data
1316         object with the same number of data-points, but with each data-point containing only
1317         one value - the result of the reduction operation on the corresponding data-point in
1318         this Data object
1319      */
1320      template <class BinaryFunction>
1321      inline
1322      Data
1323      dp_algorithm(BinaryFunction operation,
1324                   double initial_value) const;
1325    
1326    /**    /**
1327       \brief       \brief
# Line 892  class Data { Line 1385  class Data {
1385    reshapeDataPoint(const DataArrayView::ShapeType& shape);    reshapeDataPoint(const DataArrayView::ShapeType& shape);
1386    
1387    //    //
1388      // flag to protect the data object against any update
1389      bool m_protected;
1390    
1391      //
1392    // pointer to the actual data object    // pointer to the actual data object
1393    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
1394    
1395      //
1396      // pointer to the internal profiling data
1397      struct profDataEntry *profData;
1398    
1399  };  };
1400    
1401  template <class IValueType>  template <class IValueType>
# Line 928  Data::initialise(const IValueType& value Line 1429  Data::initialise(const IValueType& value
1429    Operator+    Operator+
1430    Takes two Data objects.    Takes two Data objects.
1431  */  */
1432  Data operator+(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator+(const Data& left, const Data& right);
1433    
1434  /**  /**
1435    \brief    \brief
1436    Operator-    Operator-
1437    Takes two Data objects.    Takes two Data objects.
1438  */  */
1439  Data operator-(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator-(const Data& left, const Data& right);
1440    
1441  /**  /**
1442    \brief    \brief
1443    Operator*    Operator*
1444    Takes two Data objects.    Takes two Data objects.
1445  */  */
1446  Data operator*(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator*(const Data& left, const Data& right);
1447    
1448  /**  /**
1449    \brief    \brief
1450    Operator/    Operator/
1451    Takes two Data objects.    Takes two Data objects.
1452  */  */
1453  Data operator/(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator/(const Data& left, const Data& right);
1454    
1455  /**  /**
1456    \brief    \brief
# Line 957  Data operator/(const Data& left, const D Line 1458  Data operator/(const Data& left, const D
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 965  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 973  Data operator-(const Data& left, const b Line 1474  Data operator-(const Data& left, const b
1474    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1475    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1476  */  */
1477  Data operator*(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator*(const Data& left, const boost::python::object& right);
1478    
1479  /**  /**
1480    \brief    \brief
# Line 981  Data operator*(const Data& left, const b Line 1482  Data operator*(const Data& left, const b
1482    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1483    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1484  */  */
1485  Data operator/(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator/(const Data& left, const boost::python::object& right);
1486    
1487  /**  /**
1488    \brief    \brief
# Line 989  Data operator/(const Data& left, const b Line 1490  Data operator/(const Data& left, const b
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 997  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
# Line 1005  Data operator-(const boost::python::obje Line 1506  Data operator-(const boost::python::obje
1506    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1507    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1508  */  */
1509  Data operator*(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator*(const boost::python::object& left, const Data& right);
1510    
1511  /**  /**
1512    \brief    \brief
# Line 1013  Data operator*(const boost::python::obje Line 1514  Data operator*(const boost::python::obje
1514    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1515    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1516  */  */
1517  Data operator/(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator/(const boost::python::object& left, const Data& right);
1518    
1519  /**  /**
1520    \brief    \brief
1521    Output operator    Output operator
1522  */  */
1523  std::ostream& operator<<(std::ostream& o, const Data& data);  ESCRIPT_DLL_API std::ostream& operator<<(std::ostream& o, const Data& data);
1524    
1525  /**  /**
1526    \brief    \brief
# Line 1027  std::ostream& operator<<(std::ostream& o Line 1528  std::ostream& operator<<(std::ostream& o
1528    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
1529    be relied on. Requires further implementation.    be relied on. Requires further implementation.
1530  */  */
1531  //bool operator==(const Data& left, const Data& right);  //ESCRIPT_DLL_API bool operator==(const Data& left, const Data& right);
1532    
1533  /**  /**
1534    \brief    \brief
# Line 1190  Data::unaryOp(UnaryFunction operation) Line 1691  Data::unaryOp(UnaryFunction operation)
1691    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.
1692    Calls escript::algorithm.    Calls escript::algorithm.
1693  */  */
1694  template <class UnaryFunction>  template <class BinaryFunction>
1695  inline  inline
1696  double  double
1697  Data::algorithm(UnaryFunction operation) const  Data::algorithm(BinaryFunction operation, double initial_value) const
1698  {  {
1699    if (isExpanded()) {    if (isExpanded()) {
1700      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1701      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1702      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1703    } else if (isTagged()) {    } else if (isTagged()) {
1704      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1705      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1706      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1707    } else if (isConstant()) {    } else if (isConstant()) {
1708      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1709      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1710      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1711    }    }
1712    return 0;    return 0;
1713  }  }
# Line 1219  Data::algorithm(UnaryFunction operation) Line 1720  Data::algorithm(UnaryFunction operation)
1720    rank 0 Data object.    rank 0 Data object.
1721    Calls escript::dp_algorithm.    Calls escript::dp_algorithm.
1722  */  */
1723  template <class UnaryFunction>  template <class BinaryFunction>
1724  inline  inline
1725  Data  Data
1726  dp_algorithm(const Data& data,  Data::dp_algorithm(BinaryFunction operation, double initial_value) const
              UnaryFunction operation)  
1727  {  {
1728    Data result(0,DataArrayView::ShapeType(),data.getFunctionSpace(),data.isExpanded());    if (isExpanded()) {
1729    if (data.isExpanded()) {      Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1730      DataExpanded* dataE=dynamic_cast<DataExpanded*>(data.m_data.get());      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
1731      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1732      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1733      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1734      escript::dp_algorithm(*dataE,*resultE,operation);      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
1735    } else if (data.isTagged()) {      return result;
1736      DataTagged* dataT=dynamic_cast<DataTagged*>(data.m_data.get());    } else if (isTagged()) {
1737        DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1738        DataArrayView::ShapeType viewShape;
1739        DataArrayView::ValueType viewData(1);
1740        viewData[0]=0;
1741        DataArrayView defaultValue(viewData,viewShape);
1742        DataTagged::TagListType keys;
1743        DataTagged::ValueListType values;
1744        DataTagged::DataMapType::const_iterator i;
1745        for (i=dataT->getTagLookup().begin();i!=dataT->getTagLookup().end();i++) {
1746          keys.push_back(i->first);
1747          values.push_back(defaultValue);
1748        }
1749        Data result(keys,values,defaultValue,getFunctionSpace());
1750      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1751      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1752      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1753      escript::dp_algorithm(*dataT,*resultT,operation);      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
1754    } else if (data.isConstant()) {      return result;
1755      DataConstant* dataC=dynamic_cast<DataConstant*>(data.m_data.get());    } else if (isConstant()) {
1756        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1757        DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1758      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1759      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1760      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1761      escript::dp_algorithm(*dataC,*resultC,operation);      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
1762        return result;
1763    }    }
1764    return result;    Data falseRetVal; // to keep compiler quiet
1765      return falseRetVal;
1766  }  }
1767    
1768  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26