/[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 783 by gross, Tue Jul 18 01:32:50 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      ESCRIPT_DLL_API
273      const boost::python::numeric::array
274      convertToNumArrayFromDPNo(int sampleNo,
275                                int dataPointNo);
276    
277      /**
278         \brief
279         Fills the expanded Data object from values of a python numarray object.
280      */
281      ESCRIPT_DLL_API
282      void
283      fillFromNumArray(const boost::python::numeric::array);
284    
285      /**
286         \brief
287         Return the tag number associated with the given data-point.
288    
289         The data-point number here corresponds to the data-point number in the
290         numarray returned by convertToNumArray.
291      */
292      ESCRIPT_DLL_API
293      int
294      getTagNumber(int dpno);
295    
296      /**
297         \brief
298       Return the C wrapper for the Data object.       Return the C wrapper for the Data object.
299    */    */
300      ESCRIPT_DLL_API
301    escriptDataC    escriptDataC
302    getDataC();    getDataC();
303    
# Line 229  class Data { Line 305  class Data {
305       \brief       \brief
306       Return the C wrapper for the Data object - const version.       Return the C wrapper for the Data object - const version.
307    */    */
308      ESCRIPT_DLL_API
309    escriptDataC    escriptDataC
310    getDataC() const;    getDataC() const;
311    
# Line 236  class Data { Line 313  class Data {
313       \brief       \brief
314       Write the data as a string.       Write the data as a string.
315    */    */
316      ESCRIPT_DLL_API
317    inline    inline
318    std::string    std::string
319    toString() const    toString() const
# Line 249  class Data { Line 327  class Data {
327       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
328       to manipulate the point data.       to manipulate the point data.
329    */    */
330      ESCRIPT_DLL_API
331    inline    inline
332    const DataArrayView&    const DataArrayView&
333    getPointDataView() const    getPointDataView() const
# Line 260  class Data { Line 339  class Data {
339       \brief       \brief
340       Whatever the current Data type make this into a DataExpanded.       Whatever the current Data type make this into a DataExpanded.
341    */    */
342      ESCRIPT_DLL_API
343    void    void
344    expand();    expand();
345    
# Line 268  class Data { Line 348  class Data {
348       If possible convert this Data to DataTagged. This will only allow       If possible convert this Data to DataTagged. This will only allow
349       Constant data to be converted to tagged. An attempt to convert       Constant data to be converted to tagged. An attempt to convert
350       Expanded data to tagged will throw an exception.       Expanded data to tagged will throw an exception.
351        ==>*
352    */    */
353      ESCRIPT_DLL_API
354    void    void
355    tag();    tag();
356    
# Line 276  class Data { Line 358  class Data {
358       \brief       \brief
359       Return true if this Data is expanded.       Return true if this Data is expanded.
360    */    */
361      ESCRIPT_DLL_API
362    bool    bool
363    isExpanded() const;    isExpanded() const;
364    
# Line 283  class Data { Line 366  class Data {
366       \brief       \brief
367       Return true if this Data is tagged.       Return true if this Data is tagged.
368    */    */
369      ESCRIPT_DLL_API
370    bool    bool
371    isTagged() const;    isTagged() const;
372    
# Line 290  class Data { Line 374  class Data {
374       \brief       \brief
375       Return true if this Data is constant.       Return true if this Data is constant.
376    */    */
377      ESCRIPT_DLL_API
378    bool    bool
379    isConstant() const;    isConstant() const;
380    
# Line 297  class Data { Line 382  class Data {
382       \brief       \brief
383       Return true if this Data is empty.       Return true if this Data is empty.
384    */    */
385      ESCRIPT_DLL_API
386    bool    bool
387    isEmpty() const;    isEmpty() const;
388    
# Line 304  class Data { Line 390  class Data {
390       \brief       \brief
391       Return the function space.       Return the function space.
392    */    */
393      ESCRIPT_DLL_API
394    inline    inline
395    const FunctionSpace&    const FunctionSpace&
396    getFunctionSpace() const    getFunctionSpace() const
# Line 315  class Data { Line 402  class Data {
402       \brief       \brief
403       Return a copy of the function space.       Return a copy of the function space.
404    */    */
405      ESCRIPT_DLL_API
406    const FunctionSpace    const FunctionSpace
407    getCopyOfFunctionSpace() const;    getCopyOfFunctionSpace() const;
408    
# Line 322  class Data { Line 410  class Data {
410       \brief       \brief
411       Return the domain.       Return the domain.
412    */    */
413      ESCRIPT_DLL_API
414    inline    inline
415    const AbstractDomain&    const AbstractDomain&
416    getDomain() const    getDomain() const
# Line 333  class Data { Line 422  class Data {
422       \brief       \brief
423       Return a copy of the domain.       Return a copy of the domain.
424    */    */
425      ESCRIPT_DLL_API
426    const AbstractDomain    const AbstractDomain
427    getCopyOfDomain() const;    getCopyOfDomain() const;
428    
# Line 340  class Data { Line 430  class Data {
430       \brief       \brief
431       Return the rank of the point data.       Return the rank of the point data.
432    */    */
433      ESCRIPT_DLL_API
434    inline    inline
435    int    int
436    getDataPointRank() const    getDataPointRank() const
# Line 351  class Data { Line 442  class Data {
442       \brief       \brief
443       Return the number of samples.       Return the number of samples.
444    */    */
445      ESCRIPT_DLL_API
446    inline    inline
447    int    int
448    getNumSamples() const    getNumSamples() const
# Line 362  class Data { Line 454  class Data {
454       \brief       \brief
455       Return the number of data points per sample.       Return the number of data points per sample.
456    */    */
457      ESCRIPT_DLL_API
458    inline    inline
459    int    int
460    getNumDataPointsPerSample() const    getNumDataPointsPerSample() const
# Line 375  class Data { Line 468  class Data {
468       preferred interface but is provided for use by C code.       preferred interface but is provided for use by C code.
469       \param sampleNo - Input - the given sample no.       \param sampleNo - Input - the given sample no.
470    */    */
471      ESCRIPT_DLL_API
472    inline    inline
473    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
474    getSampleData(DataAbstract::ValueType::size_type sampleNo)    getSampleData(DataAbstract::ValueType::size_type sampleNo)
# Line 388  class Data { Line 482  class Data {
482       access data that isn't tagged an exception will be thrown.       access data that isn't tagged an exception will be thrown.
483       \param tag - Input - the tag key.       \param tag - Input - the tag key.
484    */    */
485      ESCRIPT_DLL_API
486    inline    inline
487    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
488    getSampleDataByTag(int tag)    getSampleDataByTag(int tag)
# Line 397  class Data { Line 492  class Data {
492    
493    /**    /**
494       \brief       \brief
495         Assign the given value to the data-points referenced by the given
496         reference number.
497    
498         The value supplied is a python numarray object.  The data from this numarray
499         is unpacked into a DataArray, and this is used to set the corresponding
500         data-points in the underlying Data object.
501    
502         If the underlying Data object cannot be accessed via reference numbers, an
503         exception will be thrown.
504    
505         \param ref - Input - reference number.
506         \param value - Input - value to assign to data-points associated with
507                                the given reference number.
508      */
509      ESCRIPT_DLL_API
510      void
511      setRefValue(int ref,
512                  const boost::python::numeric::array& value);
513    
514      /**
515         \brief
516         Return the values associated with the data-points referenced by the given
517         reference number.
518    
519         The value supplied is a python numarray object. The data from the corresponding
520         data-points in this Data object are packed into the given numarray object.
521    
522         If the underlying Data object cannot be accessed via reference numbers, an
523         exception will be thrown.
524    
525         \param ref - Input - reference number.
526         \param value - Output - object to receive values from data-points
527                                 associated with the given reference number.
528      */
529      ESCRIPT_DLL_API
530      void
531      getRefValue(int ref,
532                  boost::python::numeric::array& value);
533    
534      /**
535         \brief
536       Return a view into the data for the data point specified.       Return a view into the data for the data point specified.
537       NOTE: Construction of the DataArrayView is a relatively expensive       NOTE: Construction of the DataArrayView is a relatively expensive
538       operation.       operation.
539       \param sampleNo - Input -       \param sampleNo - Input -
540       \param dataPointNo - Input -       \param dataPointNo - Input -
541    */    */
542      ESCRIPT_DLL_API
543    inline    inline
544    DataArrayView    DataArrayView
545    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
# Line 415  class Data { Line 552  class Data {
552       \brief       \brief
553       Return a reference to the data point shape.       Return a reference to the data point shape.
554    */    */
555      ESCRIPT_DLL_API
556    const DataArrayView::ShapeType&    const DataArrayView::ShapeType&
557    getDataPointShape() const;    getDataPointShape() const;
558    
# Line 422  class Data { Line 560  class Data {
560       \brief       \brief
561       Return the data point shape as a tuple of integers.       Return the data point shape as a tuple of integers.
562    */    */
563    boost::python::tuple    ESCRIPT_DLL_API
564      const boost::python::tuple
565    getShapeTuple() const;    getShapeTuple() const;
566    
567    /**    /**
# Line 430  class Data { Line 569  class Data {
569       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
570       data point shape dimensions.       data point shape dimensions.
571    */    */
572      ESCRIPT_DLL_API
573    int    int
574    getDataPointSize() const;    getDataPointSize() const;
575    
# Line 437  class Data { Line 577  class Data {
577       \brief       \brief
578       Return the number of doubles stored for this Data.       Return the number of doubles stored for this Data.
579    */    */
580      ESCRIPT_DLL_API
581    DataArrayView::ValueType::size_type    DataArrayView::ValueType::size_type
582    getLength() const;    getLength() const;
583    
# Line 447  class Data { Line 588  class Data {
588       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
589       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
590       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
591        ==>*
592    */    */
593      ESCRIPT_DLL_API
594    void    void
595    setTaggedValue(int tagKey,    setTaggedValue(int tagKey,
596                   const boost::python::object& value);                   const boost::python::object& value);
# Line 459  class Data { Line 602  class Data {
602       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
603       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
604       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
605       Note: removed for now - this version not needed, and breaks escript.cpp      ==>*
606    */    */
607    /*    ESCRIPT_DLL_API
608    void    void
609    setTaggedValue(int tagKey,    setTaggedValueFromCPP(int tagKey,
610                   const DataArrayView& value);                          const DataArrayView& value);
   */  
611    
612    /**    /**
613      \brief      \brief
614      Copy other Data object into this Data object where mask is positive.      Copy other Data object into this Data object where mask is positive.
615    */    */
616      ESCRIPT_DLL_API
617    void    void
618    copyWithMask(const Data& other,    copyWithMask(const Data& other,
619                 const Data& mask);                 const Data& mask);
# Line 483  class Data { Line 626  class Data {
626       \brief       \brief
627       Interpolates this onto the given functionspace and returns       Interpolates this onto the given functionspace and returns
628       the result as a Data object.       the result as a Data object.
629         *
630    */    */
631      ESCRIPT_DLL_API
632    Data    Data
633    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
634    
# Line 491  class Data { Line 636  class Data {
636       \brief       \brief
637       Calculates the gradient of the data at the data points of functionspace.       Calculates the gradient of the data at the data points of functionspace.
638       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.
639         *
640    */    */
641      ESCRIPT_DLL_API
642    Data    Data
643    gradOn(const FunctionSpace& functionspace) const;    gradOn(const FunctionSpace& functionspace) const;
644    
645      ESCRIPT_DLL_API
646    Data    Data
647    grad() const;    grad() const;
648    
649    /**    /**
650       \brief       \brief
651       Calculate the integral over the function space domain.       Calculate the integral over the function space domain.
652         *
653    */    */
654      ESCRIPT_DLL_API
655    boost::python::numeric::array    boost::python::numeric::array
656    integrate() const;    integrate() const;
657    
658    /**    /**
659       \brief       \brief
660       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.
661         *
662    */    */
663      ESCRIPT_DLL_API
664    Data    Data
665    wherePositive() const;    wherePositive() const;
666    
667    /**    /**
668       \brief       \brief
669       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.
670         *
671    */    */
672      ESCRIPT_DLL_API
673    Data    Data
674    whereNegative() const;    whereNegative() const;
675    
676    /**    /**
677       \brief       \brief
678       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.
679         *
680    */    */
681      ESCRIPT_DLL_API
682    Data    Data
683    whereNonNegative() const;    whereNonNegative() 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    whereNonPositive() const;    whereNonPositive() const;
693    
694    /**    /**
695       \brief       \brief
696       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.
697         *
698    */    */
699      ESCRIPT_DLL_API
700    Data    Data
701    whereZero() const;    whereZero(double tol=0.0) const;
702    
703    /**    /**
704       \brief       \brief
705       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.
706         *
707      */
708      ESCRIPT_DLL_API
709      Data
710      whereNonZero(double tol=0.0) const;
711    
712      /**
713         \brief
714         Return the maximum absolute value of this Data object.
715         *
716      */
717      ESCRIPT_DLL_API
718      double
719      Lsup() const;
720    
721      /**
722         \brief
723         Return the minimum absolute value of this Data object.
724         *
725      */
726      ESCRIPT_DLL_API
727      double
728      Linf() const;
729    
730      /**
731         \brief
732         Return the maximum value of this Data object.
733         *
734      */
735      ESCRIPT_DLL_API
736      double
737      sup() const;
738    
739      /**
740         \brief
741         Return the minimum value of this Data object.
742         *
743      */
744      ESCRIPT_DLL_API
745      double
746      inf() const;
747    
748      /**
749         \brief
750         Return the absolute value of each data point of this Data object.
751         *
752      */
753      ESCRIPT_DLL_API
754      Data
755      abs() const;
756    
757      /**
758         \brief
759         Return the maximum value of each data point of this Data object.
760         *
761      */
762      ESCRIPT_DLL_API
763      Data
764      maxval() const;
765    
766      /**
767         \brief
768         Return the minimum value of each data point of this Data object.
769         *
770      */
771      ESCRIPT_DLL_API
772      Data
773      minval() const;
774    
775      /**
776         \brief
777         Return the (sample number, data-point number) of the data point with
778         the minimum value in this Data object.
779      */
780      ESCRIPT_DLL_API
781      const boost::python::tuple
782      mindp() const;
783    
784      ESCRIPT_DLL_API
785      void
786    #ifndef PASO_MPI
787      calc_mindp(int& SampleNo,
788                 int& DataPointNo) const;
789    #else
790      calc_mindp(int& ProcNo,
791                            int& SampleNo,  
792                 int& DataPointNo) const;
793    #endif
794      /**
795         \brief
796         Return the sign of each data point of this Data object.
797         -1 for negative values, zero for zero values, 1 for positive values.
798         *
799      */
800      ESCRIPT_DLL_API
801      Data
802      sign() const;
803    
804      /**
805         \brief
806         Return the symmetric part of a matrix which is half the matrix plus its transpose.
807         *
808      */
809      ESCRIPT_DLL_API
810      Data
811      symmetric() const;
812    
813      /**
814         \brief
815         Return the nonsymmetric part of a matrix which is half the matrix minus its transpose.
816         *
817      */
818      ESCRIPT_DLL_API
819      Data
820      nonsymmetric() const;
821    
822      /**
823         \brief
824         Return the trace of a matrix
825         *
826    */    */
827      ESCRIPT_DLL_API
828    Data    Data
829    whereNonZero() const;    matrixtrace(int axis_offset) const;
830    
831      /**
832         \brief
833         Transpose each data point of this Data object around the given axis.
834         *
835      */
836      ESCRIPT_DLL_API
837      Data
838      transpose(int axis_offset) const;
839    
840      /**
841         \brief
842         Return the eigenvalues of the symmetric part at each data point of this Data object in increasing values.
843         Currently this function is restricted to rank 2, square shape, and dimension 3.
844         *
845      */
846      ESCRIPT_DLL_API
847      Data
848      eigenvalues() const;
849    
850      /**
851         \brief
852         Return the eigenvalues and corresponding eigenvcetors of the symmetric part at each data point of this Data object.
853         the eigenvalues are ordered in increasing size where eigenvalues with relative difference less than
854         tol are treated as equal. The eigenvectors are orthogonal, normalized and the sclaed such that the
855         first non-zero entry is positive.
856         Currently this function is restricted to rank 2, square shape, and dimension 3
857         *
858      */
859      ESCRIPT_DLL_API
860      const boost::python::tuple
861      eigenvalues_and_eigenvectors(const double tol=1.e-12) const;
862    
863      /**
864         \brief
865         Calculate the trace of each data point of this Data object.
866         *
867      */
868      ESCRIPT_DLL_API
869      Data
870      trace() const;
871    
872    /**    /**
873       \brief       \brief
874       Return the sin of each data point of this Data object.       Return the sin of each data point of this Data object.
875         *
876    */    */
877      ESCRIPT_DLL_API
878    Data    Data
879    sin() const;    sin() const;
880    
881    /**    /**
882       \brief       \brief
883       Return the cos of each data point of this Data object.       Return the cos of each data point of this Data object.
884         *
885    */    */
886      ESCRIPT_DLL_API
887    Data    Data
888    cos() const;    cos() const;
889    
890    /**    /**
891       \brief       \brief
892       Return the tan of each data point of this Data object.       Return the tan of each data point of this Data object.
893         *
894    */    */
895      ESCRIPT_DLL_API
896    Data    Data
897    tan() const;    tan() const;
898    
899    /**    /**
900       \brief       \brief
901       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.
902         *
903    */    */
904      ESCRIPT_DLL_API
905    Data    Data
906    log() const;    asin() const;
907    
908    /**    /**
909       \brief       \brief
910       Return the natural log of each data point of this Data object.       Return the acos of each data point of this Data object.
911         *
912    */    */
913      ESCRIPT_DLL_API
914    Data    Data
915    ln() const;    acos() const;
916    
917    /**    /**
918       \brief       \brief
919       Return the maximum absolute value of this Data object.       Return the atan of each data point of this Data object.
920         *
921    */    */
922    double    ESCRIPT_DLL_API
923    Lsup() const;    Data
924      atan() const;
925    
926    /**    /**
927       \brief       \brief
928       Return the maximum value of this Data object.       Return the sinh of each data point of this Data object.
929         *
930    */    */
931    double    ESCRIPT_DLL_API
932    sup() const;    Data
933      sinh() const;
934    
935    /**    /**
936       \brief       \brief
937       Return the minimum value of this Data object.       Return the cosh of each data point of this Data object.
938         *
939    */    */
940    double    ESCRIPT_DLL_API
941    inf() const;    Data
942      cosh() const;
943    
944    /**    /**
945       \brief       \brief
946       Return the absolute value of each data point of this Data object.       Return the tanh of each data point of this Data object.
947         *
948    */    */
949      ESCRIPT_DLL_API
950    Data    Data
951    abs() const;    tanh() const;
952    
953    /**    /**
954       \brief       \brief
955       Return the maximum value of each data point of this Data object.       Return the asinh of each data point of this Data object.
956         *
957    */    */
958      ESCRIPT_DLL_API
959    Data    Data
960    maxval() const;    asinh() const;
961    
962    /**    /**
963       \brief       \brief
964       Return the minimum value of each data point of this Data object.       Return the acosh of each data point of this Data object.
965         *
966    */    */
967      ESCRIPT_DLL_API
968    Data    Data
969    minval() const;    acosh() const;
970    
971    /**    /**
972       \brief       \brief
973       Return the length of each data point of this Data object.       Return the atanh of each data point of this Data object.
974       sqrt(sum(A[i,j,k,l]^2))       *
975    */    */
976      ESCRIPT_DLL_API
977    Data    Data
978    length() const;    atanh() const;
979    
980    /**    /**
981       \brief       \brief
982       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.
983       -1 for negative values, zero for zero values, 1 for positive values.       *
984    */    */
985      ESCRIPT_DLL_API
986    Data    Data
987    sign() const;    log10() const;
988    
989    /**    /**
990      \transpose       \brief
991      Transpose each data point of this Data object around the given axis.       Return the natural log of each data point of this Data object.
992         *
993    */    */
994      ESCRIPT_DLL_API
995    Data    Data
996    transpose(int axis) const;    log() const;
997    
998    /**    /**
999      \trace       \brief
1000      Calculate the trace of each data point of this Data object.       Return the exponential function of each data point of this Data object.
1001      sum(A[i,i,i,i])       *
1002    */    */
1003      ESCRIPT_DLL_API
1004    Data    Data
1005    trace() const;    exp() const;
1006    
1007    /**    /**
1008      \exp       \brief
1009      Return the exponential function of each data point of this Data object.       Return the square root of each data point of this Data object.
1010         *
1011    */    */
1012      ESCRIPT_DLL_API
1013    Data    Data
1014    exp() const;    sqrt() const;
1015    
1016    /**    /**
1017      \sqrt       \brief
1018      Return the square root of each data point of this Data object.       Return the negation of each data point of this Data object.
1019         *
1020    */    */
1021      ESCRIPT_DLL_API
1022    Data    Data
1023    sqrt() const;    neg() const;
1024    
1025      /**
1026         \brief
1027         Return the identity of each data point of this Data object.
1028         Simply returns this object unmodified.
1029         *
1030      */
1031      ESCRIPT_DLL_API
1032      Data
1033      pos() const;
1034    
1035    /**    /**
1036       \brief       \brief
1037       Return the given power of each data point of this Data object.       Return the given power of each data point of this Data object.
1038    
1039         \param right Input - the power to raise the object to.
1040         *
1041    */    */
1042      ESCRIPT_DLL_API
1043    Data    Data
1044    powD(const Data& right) const;    powD(const Data& right) const;
1045    
1046      /**
1047         \brief
1048         Return the given power of each data point of this boost python object.
1049        
1050         \param right Input - the power to raise the object to.
1051         *
1052       */
1053      ESCRIPT_DLL_API
1054    Data    Data
1055    powO(const boost::python::object& right) const;    powO(const boost::python::object& right) const;
1056    
1057    /**    /**
1058      \brief       \brief
1059      Return the negation of each data point of this Data object.       Return the given power of each data point of this boost python object.
1060    */      
1061         \param left Input - the bases
1062         *
1063       */
1064    
1065      ESCRIPT_DLL_API
1066    Data    Data
1067    neg() const;    rpowO(const boost::python::object& left) const;
1068    
1069    /**    /**
1070      \brief       \brief
1071      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.  
1072    */    */
1073    Data    ESCRIPT_DLL_API
1074    pos() const;    void
1075      saveDX(std::string fileName) const;
1076    
1077      /**
1078         \brief
1079         writes the object to a file in the VTK file format
1080      */
1081      ESCRIPT_DLL_API
1082      void
1083      saveVTK(std::string fileName) const;
1084    
1085    /**    /**
1086       \brief       \brief
1087       Overloaded operator +=       Overloaded operator +=
1088       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1089         *
1090    */    */
1091      ESCRIPT_DLL_API
1092    Data& operator+=(const Data& right);    Data& operator+=(const Data& right);
1093      ESCRIPT_DLL_API
1094    Data& operator+=(const boost::python::object& right);    Data& operator+=(const boost::python::object& right);
1095    
1096    /**    /**
1097       \brief       \brief
1098       Overloaded operator -=       Overloaded operator -=
1099       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1100         *
1101    */    */
1102      ESCRIPT_DLL_API
1103    Data& operator-=(const Data& right);    Data& operator-=(const Data& right);
1104      ESCRIPT_DLL_API
1105    Data& operator-=(const boost::python::object& right);    Data& operator-=(const boost::python::object& right);
1106    
1107   /**   /**
1108       \brief       \brief
1109       Overloaded operator *=       Overloaded operator *=
1110       \param right - Input - The right hand side.       \param right - Input - The right hand side.
1111         *
1112    */    */
1113      ESCRIPT_DLL_API
1114    Data& operator*=(const Data& right);    Data& operator*=(const Data& right);
1115      ESCRIPT_DLL_API
1116    Data& operator*=(const boost::python::object& right);    Data& operator*=(const boost::python::object& right);
1117    
1118   /**   /**
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       Returns true if this can be interpolated to functionspace.       Returns true if this can be interpolated to functionspace.
1132    */    */
1133      ESCRIPT_DLL_API
1134    bool    bool
1135    probeInterpolation(const FunctionSpace& functionspace) const;    probeInterpolation(const FunctionSpace& functionspace) const;
1136    
# Line 748  class Data { Line 1149  class Data {
1149       \param key - Input - python slice tuple specifying       \param key - Input - python slice tuple specifying
1150       slice to return.       slice to return.
1151    */    */
1152      ESCRIPT_DLL_API
1153    Data    Data
1154    getItem(const boost::python::object& key) const;    getItem(const boost::python::object& key) const;
1155    
# Line 755  class Data { Line 1157  class Data {
1157       \brief       \brief
1158       Copies slice from value into this Data object.       Copies slice from value into this Data object.
1159    
      \description  
1160       Implements the [] set operator in python.       Implements the [] set operator in python.
1161       Calls setSlice.       Calls setSlice.
1162    
# Line 763  class Data { Line 1164  class Data {
1164       slice to copy from value.       slice to copy from value.
1165       \param value - Input - Data object to copy from.       \param value - Input - Data object to copy from.
1166    */    */
1167      ESCRIPT_DLL_API
1168    void    void
1169    setItemD(const boost::python::object& key,    setItemD(const boost::python::object& key,
1170             const Data& value);             const Data& value);
1171    
1172      ESCRIPT_DLL_API
1173    void    void
1174    setItemO(const boost::python::object& key,    setItemO(const boost::python::object& key,
1175             const boost::python::object& value);             const boost::python::object& value);
# Line 779  class Data { Line 1182  class Data {
1182       this Data object.       this Data object.
1183    */    */
1184    template <class UnaryFunction>    template <class UnaryFunction>
1185      ESCRIPT_DLL_API
1186    inline    inline
1187    void    void
1188    unaryOp(UnaryFunction operation);    unaryOp(UnaryFunction operation);
# Line 788  class Data { Line 1192  class Data {
1192       Return a Data object containing the specified slice of       Return a Data object containing the specified slice of
1193       this Data object.       this Data object.
1194       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1195         *
1196    */    */
1197      ESCRIPT_DLL_API
1198    Data    Data
1199    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataArrayView::RegionType& region) const;
1200    
# Line 798  class Data { Line 1204  class Data {
1204       Data object.       Data object.
1205       \param value - Input - Data to copy from.       \param value - Input - Data to copy from.
1206       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1207         *
1208    */    */
1209      ESCRIPT_DLL_API
1210    void    void
1211    setSlice(const Data& value,    setSlice(const Data& value,
1212             const DataArrayView::RegionType& region);             const DataArrayView::RegionType& region);
1213    
1214      /**
1215         \brief
1216         Archive the current Data object to the given file.
1217         \param fileName - Input - file to archive to.
1218      */
1219      ESCRIPT_DLL_API
1220      void
1221      archiveData(const std::string fileName);
1222    
1223      /**
1224         \brief
1225         Extract the Data object archived in the given file, overwriting
1226         the current Data object.
1227         Note - the current object must be of type DataEmpty.
1228         \param fileName - Input - file to extract from.
1229         \param fspace - Input - a suitable FunctionSpace descibing the data.
1230      */
1231      ESCRIPT_DLL_API
1232      void
1233      extractData(const std::string fileName,
1234                  const FunctionSpace& fspace);
1235    
1236    
1237    #ifdef PASO_MPI
1238      /**
1239         \brief
1240         print the data values to stdout. Used for debugging
1241      */
1242      ESCRIPT_DLL_API
1243      void
1244        print(void);
1245    
1246      /**
1247         \brief
1248         return the MPI rank number of the local data
1249             MPI_COMM_WORLD is assumed and the result of MPI_Comm_size()
1250             is returned
1251      */
1252      ESCRIPT_DLL_API
1253        int
1254        get_MPIRank(void) const;
1255    
1256      /**
1257         \brief
1258         return the MPI rank number of the local data
1259             MPI_COMM_WORLD is assumed and the result of MPI_Comm_rank()
1260             is returned
1261      */
1262      ESCRIPT_DLL_API
1263        int
1264        get_MPISize(void) const;
1265    
1266      /**
1267         \brief
1268         return the MPI rank number of the local data
1269             MPI_COMM_WORLD is assumed and returned.
1270      */
1271      ESCRIPT_DLL_API
1272        MPI_Comm
1273        get_MPIComm(void) const;
1274    #endif
1275        
1276   protected:   protected:
1277    
1278   private:   private:
# Line 823  class Data { Line 1293  class Data {
1293    /**    /**
1294       \brief       \brief
1295       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
1296       this Data object and return the single double value result.       this Data object according to the given function and return the single value result.
1297    */    */
1298    template <class UnaryFunction>    template <class BinaryFunction>
1299    inline    inline
1300    double    double
1301    algorithm(UnaryFunction operation) const;    algorithm(BinaryFunction operation,
1302                double initial_value) const;
1303    
1304      /**
1305         \brief
1306         Reduce each data-point in this Data object using the given operation. Return a Data
1307         object with the same number of data-points, but with each data-point containing only
1308         one value - the result of the reduction operation on the corresponding data-point in
1309         this Data object
1310      */
1311      template <class BinaryFunction>
1312      inline
1313      Data
1314      dp_algorithm(BinaryFunction operation,
1315                   double initial_value) const;
1316    
1317    /**    /**
1318       \brief       \brief
# Line 892  class Data { Line 1376  class Data {
1376    reshapeDataPoint(const DataArrayView::ShapeType& shape);    reshapeDataPoint(const DataArrayView::ShapeType& shape);
1377    
1378    //    //
1379      // flag to protect the data object against any update
1380      bool m_protected;
1381    
1382      //
1383    // pointer to the actual data object    // pointer to the actual data object
1384    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
1385    
1386      //
1387      // pointer to the internal profiling data
1388      struct profDataEntry *profData;
1389    
1390  };  };
1391    
1392  template <class IValueType>  template <class IValueType>
# Line 928  Data::initialise(const IValueType& value Line 1420  Data::initialise(const IValueType& value
1420    Operator+    Operator+
1421    Takes two Data objects.    Takes two Data objects.
1422  */  */
1423  Data operator+(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator+(const Data& left, const Data& right);
1424    
1425  /**  /**
1426    \brief    \brief
1427    Operator-    Operator-
1428    Takes two Data objects.    Takes two Data objects.
1429  */  */
1430  Data operator-(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator-(const Data& left, const Data& right);
1431    
1432  /**  /**
1433    \brief    \brief
1434    Operator*    Operator*
1435    Takes two Data objects.    Takes two Data objects.
1436  */  */
1437  Data operator*(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator*(const Data& left, const Data& right);
1438    
1439  /**  /**
1440    \brief    \brief
1441    Operator/    Operator/
1442    Takes two Data objects.    Takes two Data objects.
1443  */  */
1444  Data operator/(const Data& left, const Data& right);  ESCRIPT_DLL_API Data operator/(const Data& left, const Data& right);
1445    
1446  /**  /**
1447    \brief    \brief
# Line 957  Data operator/(const Data& left, const D Line 1449  Data operator/(const Data& left, const D
1449    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1450    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1451  */  */
1452  Data operator+(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator+(const Data& left, const boost::python::object& right);
1453    
1454  /**  /**
1455    \brief    \brief
# Line 965  Data operator+(const Data& left, const b Line 1457  Data operator+(const Data& left, const b
1457    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1458    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1459  */  */
1460  Data operator-(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator-(const Data& left, const boost::python::object& right);
1461    
1462  /**  /**
1463    \brief    \brief
# Line 973  Data operator-(const Data& left, const b Line 1465  Data operator-(const Data& left, const b
1465    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1466    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1467  */  */
1468  Data operator*(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator*(const Data& left, const boost::python::object& right);
1469    
1470  /**  /**
1471    \brief    \brief
# Line 981  Data operator*(const Data& left, const b Line 1473  Data operator*(const Data& left, const b
1473    Takes LHS Data object and RHS python::object.    Takes LHS Data object and RHS python::object.
1474    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1475  */  */
1476  Data operator/(const Data& left, const boost::python::object& right);  ESCRIPT_DLL_API Data operator/(const Data& left, const boost::python::object& right);
1477    
1478  /**  /**
1479    \brief    \brief
# Line 989  Data operator/(const Data& left, const b Line 1481  Data operator/(const Data& left, const b
1481    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1482    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1483  */  */
1484  Data operator+(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator+(const boost::python::object& left, const Data& right);
1485    
1486  /**  /**
1487    \brief    \brief
# Line 997  Data operator+(const boost::python::obje Line 1489  Data operator+(const boost::python::obje
1489    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1490    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1491  */  */
1492  Data operator-(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator-(const boost::python::object& left, const Data& right);
1493    
1494  /**  /**
1495    \brief    \brief
# Line 1005  Data operator-(const boost::python::obje Line 1497  Data operator-(const boost::python::obje
1497    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1498    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1499  */  */
1500  Data operator*(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator*(const boost::python::object& left, const Data& right);
1501    
1502  /**  /**
1503    \brief    \brief
# Line 1013  Data operator*(const boost::python::obje Line 1505  Data operator*(const boost::python::obje
1505    Takes LHS python::object and RHS Data object.    Takes LHS python::object and RHS Data object.
1506    python::object must be convertable to Data type.    python::object must be convertable to Data type.
1507  */  */
1508  Data operator/(const boost::python::object& left, const Data& right);  ESCRIPT_DLL_API Data operator/(const boost::python::object& left, const Data& right);
1509    
1510  /**  /**
1511    \brief    \brief
1512    Output operator    Output operator
1513  */  */
1514  std::ostream& operator<<(std::ostream& o, const Data& data);  ESCRIPT_DLL_API std::ostream& operator<<(std::ostream& o, const Data& data);
1515    
1516  /**  /**
1517    \brief    \brief
# Line 1027  std::ostream& operator<<(std::ostream& o Line 1519  std::ostream& operator<<(std::ostream& o
1519    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
1520    be relied on. Requires further implementation.    be relied on. Requires further implementation.
1521  */  */
1522  //bool operator==(const Data& left, const Data& right);  //ESCRIPT_DLL_API bool operator==(const Data& left, const Data& right);
1523    
1524  /**  /**
1525    \brief    \brief
# Line 1190  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 1219  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  dp_algorithm(const Data& data,  Data::dp_algorithm(BinaryFunction operation, double initial_value) const
              UnaryFunction operation)  
1718  {  {
1719    Data result(0,DataArrayView::ShapeType(),data.getFunctionSpace(),data.isExpanded());    if (isExpanded()) {
1720    if (data.isExpanded()) {      Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1721      DataExpanded* dataE=dynamic_cast<DataExpanded*>(data.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    } else if (data.isTagged()) {      return result;
1727      DataTagged* dataT=dynamic_cast<DataTagged*>(data.m_data.get());    } else if (isTagged()) {
1728        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    } else if (data.isConstant()) {      return result;
1746      DataConstant* dataC=dynamic_cast<DataConstant*>(data.m_data.get());    } else if (isConstant()) {
1747        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1748        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.97  
changed lines
  Added in v.783

  ViewVC Help
Powered by ViewVC 1.1.26