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

Annotation of /branches/schroedinger/escript/src/Data.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1034 - (hide annotations)
Wed Mar 14 23:49:20 2007 UTC (12 years, 7 months ago) by gross
Original Path: trunk/escript/src/Data.h
File MIME type: text/plain
File size: 40817 byte(s)
In VC++ boost has problems with numarray arguments from python. This
fixes that problem by taking python::object arguments from the python
level and converting it into python::numeric::array on the C++ level.
This hasn't been tested with VC++ yet.

Moreover the two Data methods dealing with big numarrays as argument and
return value have been removed.


1 jgs 94 // $Id$
2 jgs 121 /*
3 elspeth 615 ************************************************************
4     * Copyright 2006 by ACcESS MNRF *
5     * *
6     * http://www.access.edu.au *
7     * Primary Business: Queensland, Australia *
8     * Licensed under the Open Software License version 3.0 *
9     * http://www.opensource.org/licenses/osl-3.0.php *
10     * *
11     ************************************************************
12 jgs 121 */
13 jgs 94
14 jgs 121 /** \file Data.h */
15 jgs 94
16     #ifndef DATA_H
17     #define DATA_H
18 woo409 757 #include "system_dep.h"
19 jgs 94
20 jgs 474 #include "DataAbstract.h"
21     #include "DataAlgorithm.h"
22     #include "FunctionSpace.h"
23     #include "BinaryOp.h"
24     #include "UnaryOp.h"
25     #include "DataException.h"
26 jgs 94
27     extern "C" {
28 jgs 474 #include "DataC.h"
29 ksteube 971 #include "paso/Paso.h"
30 jgs 94 }
31    
32 bcumming 790 #ifndef PASO_MPI
33     #define MPI_Comm long
34     #endif
35    
36 jgs 94 #include <string>
37     #include <algorithm>
38    
39     #include <boost/shared_ptr.hpp>
40     #include <boost/python/object.hpp>
41     #include <boost/python/tuple.hpp>
42     #include <boost/python/numeric.hpp>
43    
44 jgs 121 namespace escript {
45    
46     //
47 jgs 149 // Forward declaration for various implementations of Data.
48 jgs 121 class DataConstant;
49     class DataTagged;
50     class DataExpanded;
51    
52 jgs 94 /**
53     \brief
54 jgs 121 Data creates the appropriate Data object for the given construction
55     arguments.
56 jgs 94
57     Description:
58     Data is essentially a factory class which creates the appropriate Data
59     object for the given construction arguments. It retains control over
60     the object created for the lifetime of the object.
61     The type of Data object referred to may change during the lifetime of
62     the Data object.
63     */
64     class Data {
65    
66     public:
67    
68 jgs 110 // These typedefs allow function names to be cast to pointers
69     // to functions of the appropriate type when calling unaryOp etc.
70 jgs 94 typedef double (*UnaryDFunPtr)(double);
71     typedef double (*BinaryDFunPtr)(double,double);
72    
73 gross 854
74 jgs 94 /**
75 jgs 102 Constructors.
76     */
77    
78     /**
79 jgs 94 \brief
80     Default constructor.
81     Creates a DataEmpty object.
82     */
83 woo409 757 ESCRIPT_DLL_API
84 jgs 94 Data();
85    
86     /**
87     \brief
88     Copy constructor.
89     WARNING: Only performs a shallow copy.
90     */
91 woo409 757 ESCRIPT_DLL_API
92 jgs 94 Data(const Data& inData);
93    
94     /**
95     \brief
96     Constructor from another Data object. If "what" is different from the
97 jgs 102 function space of inData the inData are tried to be interpolated to what,
98 jgs 94 otherwise a shallow copy of inData is returned.
99     */
100 woo409 757 ESCRIPT_DLL_API
101 jgs 94 Data(const Data& inData,
102     const FunctionSpace& what);
103    
104     /**
105     \brief
106     Constructor which copies data from a DataArrayView.
107    
108     \param value - Input - Data value for a single point.
109     \param what - Input - A description of what this data represents.
110     \param expanded - Input - Flag, if true fill the entire container with
111     the value. Otherwise a more efficient storage
112     mechanism will be used.
113     */
114 woo409 757 ESCRIPT_DLL_API
115 jgs 94 Data(const DataArrayView& value,
116     const FunctionSpace& what=FunctionSpace(),
117     bool expanded=false);
118    
119     /**
120     \brief
121     Constructor which creates a Data from a DataArrayView shape.
122    
123     \param value - Input - Single value applied to all Data.
124     \param dataPointShape - Input - The shape of each data point.
125     \param what - Input - A description of what this data represents.
126     \param expanded - Input - Flag, if true fill the entire container with
127     the given value. Otherwise a more efficient storage
128     mechanism will be used.
129     */
130 woo409 757 ESCRIPT_DLL_API
131 jgs 94 Data(double value,
132     const DataArrayView::ShapeType& dataPointShape=DataArrayView::ShapeType(),
133     const FunctionSpace& what=FunctionSpace(),
134     bool expanded=false);
135    
136     /**
137     \brief
138     Constructor which performs a deep copy of a region from another Data object.
139    
140     \param inData - Input - Input Data object.
141     \param region - Input - Region to copy.
142     */
143 woo409 757 ESCRIPT_DLL_API
144 jgs 94 Data(const Data& inData,
145     const DataArrayView::RegionType& region);
146    
147     /**
148     \brief
149     Constructor which will create Tagged data if expanded is false.
150     No attempt is made to ensure the tag keys match the tag keys
151     within the function space.
152    
153     \param tagKeys - Input - List of tag values.
154     \param values - Input - List of values, one for each tag.
155     \param defaultValue - Input - A default value, used if tag doesn't exist.
156     \param what - Input - A description of what this data represents.
157     \param expanded - Input - Flag, if true fill the entire container with
158     the appropriate values.
159 jgs 544 ==>*
160 jgs 94 */
161 woo409 757 ESCRIPT_DLL_API
162 jgs 94 Data(const DataTagged::TagListType& tagKeys,
163     const DataTagged::ValueListType& values,
164     const DataArrayView& defaultValue,
165     const FunctionSpace& what=FunctionSpace(),
166     bool expanded=false);
167    
168     /**
169     \brief
170     Constructor which copies data from a python numarray.
171    
172     \param value - Input - Data value for a single point.
173     \param what - Input - A description of what this data represents.
174     \param expanded - Input - Flag, if true fill the entire container with
175     the value. Otherwise a more efficient storage
176     mechanism will be used.
177     */
178 woo409 757 ESCRIPT_DLL_API
179 jgs 94 Data(const boost::python::numeric::array& value,
180     const FunctionSpace& what=FunctionSpace(),
181     bool expanded=false);
182    
183     /**
184     \brief
185     Constructor which copies data from any object that can be converted into
186     a python numarray.
187    
188     \param value - Input - Input data.
189     \param what - Input - A description of what this data represents.
190     \param expanded - Input - Flag, if true fill the entire container with
191     the value. Otherwise a more efficient storage
192     mechanism will be used.
193     */
194 woo409 757 ESCRIPT_DLL_API
195 jgs 94 Data(const boost::python::object& value,
196     const FunctionSpace& what=FunctionSpace(),
197     bool expanded=false);
198    
199     /**
200     \brief
201     Constructor which creates a DataConstant.
202     Copies data from any object that can be converted
203     into a numarray. All other parameters are copied from other.
204    
205     \param value - Input - Input data.
206     \param other - Input - contains all other parameters.
207     */
208 woo409 757 ESCRIPT_DLL_API
209 jgs 94 Data(const boost::python::object& value,
210     const Data& other);
211    
212     /**
213     \brief
214     Constructor which creates a DataConstant of "shape" with constant value.
215     */
216 woo409 757 ESCRIPT_DLL_API
217 jgs 94 Data(double value,
218     const boost::python::tuple& shape=boost::python::make_tuple(),
219     const FunctionSpace& what=FunctionSpace(),
220     bool expanded=false);
221 jgs 151 /**
222     \brief
223     Destructor
224     */
225 woo409 757 ESCRIPT_DLL_API
226 jgs 151 ~Data();
227 jgs 94
228     /**
229     \brief
230 jgs 102 Perform a deep copy.
231 jgs 94 */
232 woo409 757 ESCRIPT_DLL_API
233 jgs 94 void
234 jgs 102 copy(const Data& other);
235 jgs 94
236     /**
237 jgs 102 Member access methods.
238 jgs 94 */
239    
240     /**
241     \brief
242 gross 783 switches on update protection
243    
244     */
245     ESCRIPT_DLL_API
246     void
247     setProtection();
248    
249     /**
250     \brief
251     Returns trueif the data object is protected against update
252    
253     */
254     ESCRIPT_DLL_API
255     bool
256     isProtected() const;
257 gross 1034
258 gross 783 /**
259     \brief
260 gross 1034 Return the values of a data point on this process
261 jgs 117 */
262 woo409 757 ESCRIPT_DLL_API
263 jgs 121 const boost::python::numeric::array
264 gross 1034 getValueOfDataPoint(int dataPointNo);
265 jgs 117
266     /**
267     \brief
268 gross 1034 sets the values of a data-point from a python object on this process
269 jgs 121 */
270 woo409 757 ESCRIPT_DLL_API
271 gross 921 void
272 gross 1034 setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object);
273 jgs 121
274     /**
275     \brief
276 gross 1034 sets the values of a data-point from a numarray object on this process
277 jgs 121 */
278 woo409 757 ESCRIPT_DLL_API
279 jgs 149 void
280 gross 1034 setValueOfDataPointToArray(int dataPointNo, const boost::python::numeric::array&);
281 jgs 149
282     /**
283     \brief
284 gross 922 sets the values of a data-point on this process
285     */
286     ESCRIPT_DLL_API
287     void
288     setValueOfDataPoint(int dataPointNo, const double);
289    
290     /**
291     \brief
292 gross 921 Return the value of the specified data-point across all processors
293     */
294     ESCRIPT_DLL_API
295     const boost::python::numeric::array
296     getValueOfGlobalDataPoint(int procNo, int dataPointNo);
297    
298     /**
299     \brief
300 jgs 149 Return the tag number associated with the given data-point.
301    
302     The data-point number here corresponds to the data-point number in the
303     numarray returned by convertToNumArray.
304     */
305 woo409 757 ESCRIPT_DLL_API
306 jgs 149 int
307     getTagNumber(int dpno);
308    
309     /**
310     \brief
311 jgs 94 Return the C wrapper for the Data object.
312     */
313 woo409 757 ESCRIPT_DLL_API
314 jgs 102 escriptDataC
315     getDataC();
316 jgs 94
317     /**
318     \brief
319     Return the C wrapper for the Data object - const version.
320     */
321 woo409 757 ESCRIPT_DLL_API
322 jgs 102 escriptDataC
323     getDataC() const;
324 jgs 94
325     /**
326     \brief
327     Write the data as a string.
328     */
329 woo409 757 ESCRIPT_DLL_API
330 jgs 102 inline
331     std::string
332     toString() const
333     {
334     return m_data->toString();
335     }
336 jgs 94
337     /**
338     \brief
339     Return the DataArrayView of the point data. This essentially contains
340     the shape information for each data point although it also may be used
341     to manipulate the point data.
342     */
343 woo409 757 ESCRIPT_DLL_API
344 jgs 94 inline
345     const DataArrayView&
346     getPointDataView() const
347     {
348     return m_data->getPointDataView();
349     }
350    
351     /**
352     \brief
353 jgs 102 Whatever the current Data type make this into a DataExpanded.
354 jgs 94 */
355 woo409 757 ESCRIPT_DLL_API
356 jgs 94 void
357     expand();
358    
359     /**
360     \brief
361 jgs 102 If possible convert this Data to DataTagged. This will only allow
362 jgs 94 Constant data to be converted to tagged. An attempt to convert
363     Expanded data to tagged will throw an exception.
364 jgs 544 ==>*
365 jgs 94 */
366 woo409 757 ESCRIPT_DLL_API
367 jgs 94 void
368     tag();
369    
370     /**
371     \brief
372     Return true if this Data is expanded.
373     */
374 woo409 757 ESCRIPT_DLL_API
375 jgs 94 bool
376     isExpanded() const;
377    
378     /**
379     \brief
380     Return true if this Data is tagged.
381     */
382 woo409 757 ESCRIPT_DLL_API
383 jgs 94 bool
384     isTagged() const;
385    
386     /**
387     \brief
388 jgs 102 Return true if this Data is constant.
389 jgs 94 */
390 woo409 757 ESCRIPT_DLL_API
391 jgs 94 bool
392 jgs 102 isConstant() const;
393 jgs 94
394     /**
395     \brief
396 jgs 102 Return true if this Data is empty.
397 jgs 94 */
398 woo409 757 ESCRIPT_DLL_API
399 jgs 94 bool
400 jgs 102 isEmpty() const;
401 jgs 94
402     /**
403     \brief
404     Return the function space.
405     */
406 woo409 757 ESCRIPT_DLL_API
407 jgs 94 inline
408     const FunctionSpace&
409     getFunctionSpace() const
410     {
411     return m_data->getFunctionSpace();
412     }
413    
414     /**
415     \brief
416     Return a copy of the function space.
417     */
418 woo409 757 ESCRIPT_DLL_API
419 jgs 94 const FunctionSpace
420     getCopyOfFunctionSpace() const;
421    
422     /**
423     \brief
424     Return the domain.
425     */
426 woo409 757 ESCRIPT_DLL_API
427 jgs 94 inline
428     const AbstractDomain&
429     getDomain() const
430     {
431     return getFunctionSpace().getDomain();
432     }
433    
434     /**
435     \brief
436     Return a copy of the domain.
437     */
438 woo409 757 ESCRIPT_DLL_API
439 jgs 94 const AbstractDomain
440     getCopyOfDomain() const;
441    
442     /**
443     \brief
444     Return the rank of the point data.
445     */
446 woo409 757 ESCRIPT_DLL_API
447 jgs 94 inline
448     int
449     getDataPointRank() const
450     {
451     return m_data->getPointDataView().getRank();
452     }
453    
454     /**
455     \brief
456 gross 921 Return the number of data points
457     */
458     ESCRIPT_DLL_API
459     inline
460     int
461     getNumDataPoints() const
462     {
463     return getNumSamples() * getNumDataPointsPerSample();
464     }
465     /**
466     \brief
467 jgs 102 Return the number of samples.
468 jgs 94 */
469 woo409 757 ESCRIPT_DLL_API
470 jgs 94 inline
471     int
472 jgs 102 getNumSamples() const
473 jgs 94 {
474 jgs 102 return m_data->getNumSamples();
475 jgs 94 }
476    
477     /**
478     \brief
479 jgs 102 Return the number of data points per sample.
480 jgs 94 */
481 woo409 757 ESCRIPT_DLL_API
482 jgs 102 inline
483 jgs 94 int
484 jgs 102 getNumDataPointsPerSample() const
485     {
486     return m_data->getNumDPPSample();
487     }
488 gross 950 /**
489     \brief
490     dumps the object into a netCDF file
491     */
492     ESCRIPT_DLL_API
493     inline
494     void
495     dump(const std::string fileName) const
496     {
497     return m_data->dump(fileName);
498     }
499 jgs 94
500     /**
501     \brief
502     Return the sample data for the given sample no. This is not the
503     preferred interface but is provided for use by C code.
504     \param sampleNo - Input - the given sample no.
505     */
506 woo409 757 ESCRIPT_DLL_API
507 jgs 102 inline
508 jgs 94 DataAbstract::ValueType::value_type*
509 jgs 102 getSampleData(DataAbstract::ValueType::size_type sampleNo)
510     {
511     return m_data->getSampleData(sampleNo);
512     }
513 jgs 94
514     /**
515     \brief
516     Return the sample data for the given tag. If an attempt is made to
517     access data that isn't tagged an exception will be thrown.
518     \param tag - Input - the tag key.
519     */
520 woo409 757 ESCRIPT_DLL_API
521 jgs 102 inline
522 jgs 94 DataAbstract::ValueType::value_type*
523 jgs 102 getSampleDataByTag(int tag)
524     {
525     return m_data->getSampleDataByTag(tag);
526     }
527 jgs 94
528     /**
529     \brief
530     Return a view into the data for the data point specified.
531     NOTE: Construction of the DataArrayView is a relatively expensive
532     operation.
533     \param sampleNo - Input -
534     \param dataPointNo - Input -
535     */
536 woo409 757 ESCRIPT_DLL_API
537 jgs 94 inline
538     DataArrayView
539     getDataPoint(int sampleNo,
540     int dataPointNo)
541     {
542 bcumming 790 return m_data->getDataPoint(sampleNo,dataPointNo);
543 jgs 94 }
544    
545     /**
546     \brief
547     Return a reference to the data point shape.
548     */
549 woo409 757 ESCRIPT_DLL_API
550 jgs 94 const DataArrayView::ShapeType&
551     getDataPointShape() const;
552    
553     /**
554     \brief
555 jgs 102 Return the data point shape as a tuple of integers.
556 jgs 94 */
557 woo409 757 ESCRIPT_DLL_API
558 jgs 121 const boost::python::tuple
559 jgs 94 getShapeTuple() const;
560    
561     /**
562     \brief
563     Return the size of the data point. It is the product of the
564     data point shape dimensions.
565     */
566 woo409 757 ESCRIPT_DLL_API
567 jgs 94 int
568     getDataPointSize() const;
569    
570     /**
571     \brief
572 jgs 102 Return the number of doubles stored for this Data.
573 jgs 94 */
574 woo409 757 ESCRIPT_DLL_API
575 jgs 94 DataArrayView::ValueType::size_type
576     getLength() const;
577    
578     /**
579     \brief
580 jgs 102 Assign the given value to the tag. Implicitly converts this
581     object to type DataTagged. Throws an exception if this object
582     cannot be converted to a DataTagged object.
583     \param tagKey - Input - Integer key.
584     \param value - Input - Value to associate with given key.
585 jgs 544 ==>*
586 jgs 94 */
587 woo409 757 ESCRIPT_DLL_API
588 jgs 102 void
589     setTaggedValue(int tagKey,
590     const boost::python::object& value);
591    
592     /**
593     \brief
594     Assign the given value to the tag. Implicitly converts this
595     object to type DataTagged. Throws an exception if this object
596     cannot be converted to a DataTagged object.
597     \param tagKey - Input - Integer key.
598     \param value - Input - Value to associate with given key.
599 jgs 544 ==>*
600 jgs 102 */
601 woo409 757 ESCRIPT_DLL_API
602 jgs 102 void
603 jgs 121 setTaggedValueFromCPP(int tagKey,
604     const DataArrayView& value);
605 jgs 102
606     /**
607     \brief
608     Copy other Data object into this Data object where mask is positive.
609     */
610 woo409 757 ESCRIPT_DLL_API
611 jgs 102 void
612     copyWithMask(const Data& other,
613     const Data& mask);
614    
615     /**
616     Data object operation methods and operators.
617     */
618    
619     /**
620     \brief
621     Interpolates this onto the given functionspace and returns
622     the result as a Data object.
623 jgs 123 *
624 jgs 102 */
625 woo409 757 ESCRIPT_DLL_API
626 jgs 94 Data
627     interpolate(const FunctionSpace& functionspace) const;
628    
629     /**
630     \brief
631     Calculates the gradient of the data at the data points of functionspace.
632     If functionspace is not present the function space of Function(getDomain()) is used.
633 jgs 123 *
634 jgs 94 */
635 woo409 757 ESCRIPT_DLL_API
636 jgs 94 Data
637     gradOn(const FunctionSpace& functionspace) const;
638    
639 woo409 757 ESCRIPT_DLL_API
640 jgs 94 Data
641     grad() const;
642    
643     /**
644     \brief
645     Calculate the integral over the function space domain.
646 jgs 123 *
647 jgs 94 */
648 woo409 757 ESCRIPT_DLL_API
649 jgs 94 boost::python::numeric::array
650     integrate() const;
651    
652     /**
653     \brief
654 gross 854 Returns 1./ Data object
655     *
656     */
657     ESCRIPT_DLL_API
658     Data
659     oneOver() const;
660     /**
661     \brief
662 jgs 94 Return a Data with a 1 for +ive values and a 0 for 0 or -ive values.
663 jgs 123 *
664 jgs 94 */
665 woo409 757 ESCRIPT_DLL_API
666 jgs 94 Data
667 gross 698 wherePositive() const;
668 jgs 94
669     /**
670     \brief
671 jgs 102 Return a Data with a 1 for -ive values and a 0 for +ive or 0 values.
672 jgs 123 *
673 jgs 94 */
674 woo409 757 ESCRIPT_DLL_API
675 jgs 94 Data
676 gross 698 whereNegative() const;
677 jgs 102
678     /**
679     \brief
680     Return a Data with a 1 for +ive or 0 values and a 0 for -ive values.
681 jgs 123 *
682 jgs 102 */
683 woo409 757 ESCRIPT_DLL_API
684 jgs 102 Data
685 gross 698 whereNonNegative() const;
686 jgs 94
687     /**
688     \brief
689 jgs 102 Return a Data with a 1 for -ive or 0 values and a 0 for +ive values.
690 jgs 123 *
691 jgs 94 */
692 woo409 757 ESCRIPT_DLL_API
693 jgs 94 Data
694 gross 698 whereNonPositive() const;
695 jgs 94
696     /**
697     \brief
698 jgs 102 Return a Data with a 1 for 0 values and a 0 for +ive or -ive values.
699 jgs 123 *
700 jgs 94 */
701 woo409 757 ESCRIPT_DLL_API
702 jgs 94 Data
703 jgs 571 whereZero(double tol=0.0) const;
704 jgs 94
705     /**
706     \brief
707 jgs 102 Return a Data with a 0 for 0 values and a 1 for +ive or -ive values.
708 jgs 123 *
709 jgs 94 */
710 woo409 757 ESCRIPT_DLL_API
711 jgs 94 Data
712 jgs 571 whereNonZero(double tol=0.0) const;
713 jgs 102
714     /**
715     \brief
716     Return the maximum absolute value of this Data object.
717 jgs 123 *
718 jgs 94 */
719 woo409 757 ESCRIPT_DLL_API
720 jgs 102 double
721     Lsup() const;
722 jgs 94
723     /**
724     \brief
725 jgs 117 Return the minimum absolute value of this Data object.
726 jgs 123 *
727 jgs 117 */
728 woo409 757 ESCRIPT_DLL_API
729 jgs 117 double
730     Linf() const;
731    
732     /**
733     \brief
734 jgs 102 Return the maximum value of this Data object.
735 jgs 123 *
736 jgs 94 */
737 woo409 757 ESCRIPT_DLL_API
738 jgs 102 double
739     sup() const;
740 jgs 94
741     /**
742     \brief
743 jgs 102 Return the minimum value of this Data object.
744 jgs 123 *
745 jgs 94 */
746 woo409 757 ESCRIPT_DLL_API
747 jgs 94 double
748 jgs 102 inf() const;
749 jgs 94
750     /**
751     \brief
752 jgs 102 Return the absolute value of each data point of this Data object.
753 jgs 123 *
754 jgs 94 */
755 woo409 757 ESCRIPT_DLL_API
756 jgs 102 Data
757     abs() const;
758 jgs 94
759     /**
760     \brief
761 jgs 102 Return the maximum value of each data point of this Data object.
762 jgs 123 *
763 jgs 94 */
764 woo409 757 ESCRIPT_DLL_API
765 jgs 102 Data
766     maxval() const;
767 jgs 94
768     /**
769     \brief
770 jgs 102 Return the minimum value of each data point of this Data object.
771 jgs 123 *
772 jgs 94 */
773 woo409 757 ESCRIPT_DLL_API
774 jgs 94 Data
775 jgs 102 minval() const;
776 jgs 94
777     /**
778     \brief
779 jgs 121 Return the (sample number, data-point number) of the data point with
780     the minimum value in this Data object.
781     */
782 woo409 757 ESCRIPT_DLL_API
783 jgs 121 const boost::python::tuple
784 gross 921 minGlobalDataPoint() const;
785 jgs 121
786 woo409 757 ESCRIPT_DLL_API
787 jgs 148 void
788 gross 921 calc_minGlobalDataPoint(int& ProcNo, int& DataPointNo) const;
789 jgs 121 /**
790     \brief
791 jgs 102 Return the sign of each data point of this Data object.
792     -1 for negative values, zero for zero values, 1 for positive values.
793 jgs 123 *
794 jgs 94 */
795 woo409 757 ESCRIPT_DLL_API
796 jgs 102 Data
797     sign() const;
798 jgs 94
799     /**
800 jgs 123 \brief
801 ksteube 775 Return the symmetric part of a matrix which is half the matrix plus its transpose.
802     *
803     */
804     ESCRIPT_DLL_API
805     Data
806     symmetric() const;
807    
808     /**
809     \brief
810     Return the nonsymmetric part of a matrix which is half the matrix minus its transpose.
811     *
812     */
813     ESCRIPT_DLL_API
814     Data
815     nonsymmetric() const;
816    
817     /**
818     \brief
819     Return the trace of a matrix
820     *
821     */
822     ESCRIPT_DLL_API
823     Data
824 gross 800 trace(int axis_offset) const;
825 ksteube 775
826     /**
827     \brief
828     Transpose each data point of this Data object around the given axis.
829     *
830     */
831     ESCRIPT_DLL_API
832     Data
833     transpose(int axis_offset) const;
834    
835     /**
836     \brief
837 gross 576 Return the eigenvalues of the symmetric part at each data point of this Data object in increasing values.
838     Currently this function is restricted to rank 2, square shape, and dimension 3.
839     *
840     */
841 woo409 757 ESCRIPT_DLL_API
842 gross 576 Data
843     eigenvalues() const;
844    
845     /**
846     \brief
847     Return the eigenvalues and corresponding eigenvcetors of the symmetric part at each data point of this Data object.
848     the eigenvalues are ordered in increasing size where eigenvalues with relative difference less than
849     tol are treated as equal. The eigenvectors are orthogonal, normalized and the sclaed such that the
850     first non-zero entry is positive.
851     Currently this function is restricted to rank 2, square shape, and dimension 3
852     *
853     */
854 woo409 757 ESCRIPT_DLL_API
855 gross 576 const boost::python::tuple
856     eigenvalues_and_eigenvectors(const double tol=1.e-12) const;
857    
858     /**
859     \brief
860 gross 804 swaps the components axis0 and axis1
861 jgs 123 *
862 jgs 102 */
863 woo409 757 ESCRIPT_DLL_API
864 jgs 102 Data
865 gross 804 swapaxes(const int axis0, const int axis1) const;
866 jgs 102
867     /**
868 jgs 123 \brief
869 ksteube 876 Return the error function erf of each data point of this Data object.
870     *
871     */
872     ESCRIPT_DLL_API
873     Data
874     erf() const;
875    
876     /**
877     \brief
878 jgs 123 Return the sin of each data point of this Data object.
879     *
880 jgs 102 */
881 woo409 757 ESCRIPT_DLL_API
882 jgs 102 Data
883 jgs 123 sin() const;
884    
885     /**
886     \brief
887     Return the cos of each data point of this Data object.
888     *
889     */
890 woo409 757 ESCRIPT_DLL_API
891 jgs 123 Data
892     cos() const;
893    
894     /**
895     \brief
896     Return the tan of each data point of this Data object.
897     *
898     */
899 woo409 757 ESCRIPT_DLL_API
900 jgs 123 Data
901     tan() const;
902    
903     /**
904     \brief
905 jgs 150 Return the asin of each data point of this Data object.
906     *
907     */
908 woo409 757 ESCRIPT_DLL_API
909 jgs 150 Data
910     asin() const;
911    
912     /**
913     \brief
914     Return the acos of each data point of this Data object.
915     *
916     */
917 woo409 757 ESCRIPT_DLL_API
918 jgs 150 Data
919     acos() const;
920    
921     /**
922     \brief
923     Return the atan of each data point of this Data object.
924     *
925     */
926 woo409 757 ESCRIPT_DLL_API
927 jgs 150 Data
928     atan() const;
929    
930     /**
931     \brief
932     Return the sinh of each data point of this Data object.
933     *
934     */
935 woo409 757 ESCRIPT_DLL_API
936 jgs 150 Data
937     sinh() const;
938    
939     /**
940     \brief
941     Return the cosh of each data point of this Data object.
942     *
943     */
944 woo409 757 ESCRIPT_DLL_API
945 jgs 150 Data
946     cosh() const;
947    
948     /**
949     \brief
950     Return the tanh of each data point of this Data object.
951     *
952     */
953 woo409 757 ESCRIPT_DLL_API
954 jgs 150 Data
955     tanh() const;
956    
957     /**
958     \brief
959     Return the asinh of each data point of this Data object.
960     *
961     */
962 woo409 757 ESCRIPT_DLL_API
963 jgs 150 Data
964     asinh() const;
965    
966     /**
967     \brief
968     Return the acosh of each data point of this Data object.
969     *
970     */
971 woo409 757 ESCRIPT_DLL_API
972 jgs 150 Data
973     acosh() const;
974    
975     /**
976     \brief
977     Return the atanh of each data point of this Data object.
978     *
979     */
980 woo409 757 ESCRIPT_DLL_API
981 jgs 150 Data
982     atanh() const;
983    
984     /**
985     \brief
986 jgs 123 Return the log to base 10 of each data point of this Data object.
987     *
988     */
989 woo409 757 ESCRIPT_DLL_API
990 jgs 123 Data
991 gross 286 log10() const;
992 jgs 123
993     /**
994     \brief
995     Return the natural log of each data point of this Data object.
996     *
997     */
998 woo409 757 ESCRIPT_DLL_API
999 jgs 123 Data
1000 gross 286 log() const;
1001 jgs 123
1002     /**
1003     \brief
1004     Return the exponential function of each data point of this Data object.
1005     *
1006     */
1007 woo409 757 ESCRIPT_DLL_API
1008 jgs 123 Data
1009 jgs 102 exp() const;
1010    
1011     /**
1012 jgs 123 \brief
1013     Return the square root of each data point of this Data object.
1014     *
1015 jgs 102 */
1016 woo409 757 ESCRIPT_DLL_API
1017 jgs 102 Data
1018     sqrt() const;
1019    
1020     /**
1021 jgs 123 \brief
1022     Return the negation of each data point of this Data object.
1023     *
1024 jgs 121 */
1025 woo409 757 ESCRIPT_DLL_API
1026 jgs 121 Data
1027     neg() const;
1028    
1029     /**
1030 jgs 123 \brief
1031     Return the identity of each data point of this Data object.
1032     Simply returns this object unmodified.
1033     *
1034 jgs 121 */
1035 woo409 757 ESCRIPT_DLL_API
1036 jgs 121 Data
1037     pos() const;
1038    
1039     /**
1040 jgs 94 \brief
1041 jgs 102 Return the given power of each data point of this Data object.
1042 jgs 121
1043     \param right Input - the power to raise the object to.
1044 jgs 123 *
1045 jgs 102 */
1046 woo409 757 ESCRIPT_DLL_API
1047 jgs 102 Data
1048     powD(const Data& right) const;
1049    
1050 jgs 121 /**
1051 jgs 123 \brief
1052     Return the given power of each data point of this boost python object.
1053    
1054     \param right Input - the power to raise the object to.
1055     *
1056 jgs 121 */
1057 woo409 757 ESCRIPT_DLL_API
1058 jgs 102 Data
1059     powO(const boost::python::object& right) const;
1060    
1061     /**
1062 jgs 123 \brief
1063 gross 699 Return the given power of each data point of this boost python object.
1064    
1065     \param left Input - the bases
1066     *
1067     */
1068    
1069 woo409 757 ESCRIPT_DLL_API
1070 gross 699 Data
1071     rpowO(const boost::python::object& left) const;
1072    
1073     /**
1074     \brief
1075 jgs 123 writes the object to a file in the DX file format
1076 jgs 104 */
1077 woo409 757 ESCRIPT_DLL_API
1078 jgs 104 void
1079     saveDX(std::string fileName) const;
1080    
1081     /**
1082 jgs 123 \brief
1083     writes the object to a file in the VTK file format
1084 jgs 110 */
1085 woo409 757 ESCRIPT_DLL_API
1086 jgs 110 void
1087     saveVTK(std::string fileName) const;
1088    
1089     /**
1090 jgs 102 \brief
1091     Overloaded operator +=
1092     \param right - Input - The right hand side.
1093 jgs 123 *
1094 jgs 102 */
1095 woo409 757 ESCRIPT_DLL_API
1096 jgs 102 Data& operator+=(const Data& right);
1097 woo409 757 ESCRIPT_DLL_API
1098 jgs 102 Data& operator+=(const boost::python::object& right);
1099    
1100     /**
1101     \brief
1102     Overloaded operator -=
1103     \param right - Input - The right hand side.
1104 jgs 123 *
1105 jgs 102 */
1106 woo409 757 ESCRIPT_DLL_API
1107 jgs 102 Data& operator-=(const Data& right);
1108 woo409 757 ESCRIPT_DLL_API
1109 jgs 102 Data& operator-=(const boost::python::object& right);
1110    
1111     /**
1112     \brief
1113     Overloaded operator *=
1114     \param right - Input - The right hand side.
1115 jgs 123 *
1116 jgs 102 */
1117 woo409 757 ESCRIPT_DLL_API
1118 jgs 102 Data& operator*=(const Data& right);
1119 woo409 757 ESCRIPT_DLL_API
1120 jgs 102 Data& operator*=(const boost::python::object& right);
1121    
1122     /**
1123     \brief
1124     Overloaded operator /=
1125     \param right - Input - The right hand side.
1126 jgs 123 *
1127 jgs 102 */
1128 woo409 757 ESCRIPT_DLL_API
1129 jgs 102 Data& operator/=(const Data& right);
1130 woo409 757 ESCRIPT_DLL_API
1131 jgs 102 Data& operator/=(const boost::python::object& right);
1132    
1133     /**
1134     \brief
1135 jgs 94 Returns true if this can be interpolated to functionspace.
1136     */
1137 woo409 757 ESCRIPT_DLL_API
1138 jgs 94 bool
1139     probeInterpolation(const FunctionSpace& functionspace) const;
1140    
1141     /**
1142 jgs 102 Data object slicing methods.
1143     */
1144    
1145     /**
1146 jgs 94 \brief
1147 jgs 102 Returns a slice from this Data object.
1148    
1149     /description
1150     Implements the [] get operator in python.
1151     Calls getSlice.
1152    
1153     \param key - Input - python slice tuple specifying
1154     slice to return.
1155 jgs 94 */
1156 woo409 757 ESCRIPT_DLL_API
1157 jgs 102 Data
1158     getItem(const boost::python::object& key) const;
1159    
1160     /**
1161     \brief
1162     Copies slice from value into this Data object.
1163    
1164     Implements the [] set operator in python.
1165     Calls setSlice.
1166    
1167     \param key - Input - python slice tuple specifying
1168     slice to copy from value.
1169     \param value - Input - Data object to copy from.
1170     */
1171 woo409 757 ESCRIPT_DLL_API
1172 jgs 94 void
1173 jgs 102 setItemD(const boost::python::object& key,
1174     const Data& value);
1175 jgs 94
1176 woo409 757 ESCRIPT_DLL_API
1177 jgs 102 void
1178     setItemO(const boost::python::object& key,
1179     const boost::python::object& value);
1180    
1181     // These following public methods should be treated as private.
1182    
1183 jgs 94 /**
1184     \brief
1185 jgs 102 Perform the given unary operation on every element of every data point in
1186     this Data object.
1187 jgs 94 */
1188 jgs 102 template <class UnaryFunction>
1189 woo409 757 ESCRIPT_DLL_API
1190 jgs 102 inline
1191 jgs 94 void
1192 jgs 102 unaryOp(UnaryFunction operation);
1193    
1194     /**
1195     \brief
1196     Return a Data object containing the specified slice of
1197     this Data object.
1198     \param region - Input - Region to copy.
1199 jgs 123 *
1200 jgs 94 */
1201 woo409 757 ESCRIPT_DLL_API
1202 jgs 102 Data
1203     getSlice(const DataArrayView::RegionType& region) const;
1204 jgs 94
1205 jgs 102 /**
1206     \brief
1207     Copy the specified slice from the given value into this
1208     Data object.
1209     \param value - Input - Data to copy from.
1210     \param region - Input - Region to copy.
1211 jgs 123 *
1212 jgs 102 */
1213 woo409 757 ESCRIPT_DLL_API
1214 jgs 102 void
1215     setSlice(const Data& value,
1216     const DataArrayView::RegionType& region);
1217    
1218 jgs 119 /**
1219     \brief
1220     Archive the current Data object to the given file.
1221     \param fileName - Input - file to archive to.
1222     */
1223 woo409 757 ESCRIPT_DLL_API
1224 jgs 119 void
1225     archiveData(const std::string fileName);
1226    
1227     /**
1228     \brief
1229     Extract the Data object archived in the given file, overwriting
1230     the current Data object.
1231     Note - the current object must be of type DataEmpty.
1232     \param fileName - Input - file to extract from.
1233 jgs 121 \param fspace - Input - a suitable FunctionSpace descibing the data.
1234 jgs 119 */
1235 woo409 757 ESCRIPT_DLL_API
1236 jgs 119 void
1237     extractData(const std::string fileName,
1238     const FunctionSpace& fspace);
1239    
1240 bcumming 751
1241     /**
1242     \brief
1243     print the data values to stdout. Used for debugging
1244     */
1245 bcumming 782 ESCRIPT_DLL_API
1246     void
1247     print(void);
1248 bcumming 751
1249 bcumming 782 /**
1250     \brief
1251     return the MPI rank number of the local data
1252     MPI_COMM_WORLD is assumed and the result of MPI_Comm_size()
1253     is returned
1254     */
1255     ESCRIPT_DLL_API
1256     int
1257     get_MPIRank(void) const;
1258    
1259     /**
1260     \brief
1261     return the MPI rank number of the local data
1262     MPI_COMM_WORLD is assumed and the result of MPI_Comm_rank()
1263     is returned
1264     */
1265     ESCRIPT_DLL_API
1266     int
1267     get_MPISize(void) const;
1268    
1269     /**
1270     \brief
1271     return the MPI rank number of the local data
1272     MPI_COMM_WORLD is assumed and returned.
1273     */
1274     ESCRIPT_DLL_API
1275     MPI_Comm
1276     get_MPIComm(void) const;
1277 ksteube 813
1278     /**
1279     \brief
1280     return the object produced by the factory, which is a DataConstant or DataExpanded
1281     */
1282     ESCRIPT_DLL_API
1283     DataAbstract*
1284     borrowData(void) const;
1285    
1286 jgs 102 protected:
1287    
1288 jgs 94 private:
1289    
1290     /**
1291     \brief
1292 jgs 102 Check *this and the right operand are compatible. Throws
1293     an exception if they aren't.
1294     \param right - Input - The right hand side.
1295     */
1296     inline
1297     void
1298     operandCheck(const Data& right) const
1299     {
1300     return m_data->operandCheck(*(right.m_data.get()));
1301     }
1302    
1303     /**
1304     \brief
1305     Perform the specified reduction algorithm on every element of every data point in
1306 jgs 113 this Data object according to the given function and return the single value result.
1307 jgs 102 */
1308 jgs 147 template <class BinaryFunction>
1309 jgs 102 inline
1310     double
1311 jgs 147 algorithm(BinaryFunction operation,
1312     double initial_value) const;
1313 jgs 102
1314 jgs 113 /**
1315     \brief
1316     Reduce each data-point in this Data object using the given operation. Return a Data
1317     object with the same number of data-points, but with each data-point containing only
1318     one value - the result of the reduction operation on the corresponding data-point in
1319     this Data object
1320     */
1321 jgs 147 template <class BinaryFunction>
1322 jgs 106 inline
1323     Data
1324 jgs 147 dp_algorithm(BinaryFunction operation,
1325     double initial_value) const;
1326 jgs 106
1327 jgs 102 /**
1328     \brief
1329     Perform the given binary operation on all of the data's elements.
1330     The underlying type of the right hand side (right) determines the final
1331     type of *this after the operation. For example if the right hand side
1332     is expanded *this will be expanded if necessary.
1333     RHS is a Data object.
1334     */
1335     template <class BinaryFunction>
1336     inline
1337     void
1338     binaryOp(const Data& right,
1339     BinaryFunction operation);
1340    
1341     /**
1342     \brief
1343     Convert the data type of the RHS to match this.
1344     \param right - Input - data type to match.
1345     */
1346     void
1347     typeMatchLeft(Data& right) const;
1348    
1349     /**
1350     \brief
1351     Convert the data type of this to match the RHS.
1352     \param right - Input - data type to match.
1353     */
1354     void
1355     typeMatchRight(const Data& right);
1356    
1357     /**
1358     \brief
1359 jgs 94 Construct a Data object of the appropriate type.
1360     */
1361     template <class IValueType>
1362     void
1363     initialise(const IValueType& value,
1364     const FunctionSpace& what,
1365     bool expanded);
1366    
1367     //
1368 gross 783 // flag to protect the data object against any update
1369     bool m_protected;
1370    
1371     //
1372 jgs 102 // pointer to the actual data object
1373 jgs 94 boost::shared_ptr<DataAbstract> m_data;
1374    
1375 jgs 123 //
1376     // pointer to the internal profiling data
1377     struct profDataEntry *profData;
1378    
1379 jgs 94 };
1380    
1381     template <class IValueType>
1382     void
1383     Data::initialise(const IValueType& value,
1384     const FunctionSpace& what,
1385     bool expanded)
1386     {
1387     //
1388     // Construct a Data object of the appropriate type.
1389     // Construct the object first as there seems to be a bug which causes
1390     // undefined behaviour if an exception is thrown during construction
1391     // within the shared_ptr constructor.
1392     if (expanded) {
1393     DataAbstract* temp=new DataExpanded(value,what);
1394 jgs 102 boost::shared_ptr<DataAbstract> temp_data(temp);
1395     m_data=temp_data;
1396 jgs 94 } else {
1397     DataAbstract* temp=new DataConstant(value,what);
1398 jgs 102 boost::shared_ptr<DataAbstract> temp_data(temp);
1399     m_data=temp_data;
1400 jgs 94 }
1401     }
1402    
1403 jgs 102 /**
1404     Binary Data object operators.
1405     */
1406 gross 854 inline double rpow(double x,double y)
1407     {
1408     return pow(y,x);
1409 gross 1028 }
1410 jgs 94
1411     /**
1412     \brief
1413     Operator+
1414     Takes two Data objects.
1415     */
1416 woo409 757 ESCRIPT_DLL_API Data operator+(const Data& left, const Data& right);
1417 jgs 94
1418     /**
1419     \brief
1420     Operator-
1421     Takes two Data objects.
1422     */
1423 woo409 757 ESCRIPT_DLL_API Data operator-(const Data& left, const Data& right);
1424 jgs 94
1425     /**
1426     \brief
1427     Operator*
1428     Takes two Data objects.
1429     */
1430 woo409 757 ESCRIPT_DLL_API Data operator*(const Data& left, const Data& right);
1431 jgs 94
1432     /**
1433     \brief
1434     Operator/
1435     Takes two Data objects.
1436     */
1437 woo409 757 ESCRIPT_DLL_API Data operator/(const Data& left, const Data& right);
1438 jgs 94
1439     /**
1440     \brief
1441     Operator+
1442     Takes LHS Data object and RHS python::object.
1443     python::object must be convertable to Data type.
1444     */
1445 woo409 757 ESCRIPT_DLL_API Data operator+(const Data& left, const boost::python::object& right);
1446 jgs 94
1447     /**
1448     \brief
1449     Operator-
1450     Takes LHS Data object and RHS python::object.
1451     python::object must be convertable to Data type.
1452     */
1453 woo409 757 ESCRIPT_DLL_API Data operator-(const Data& left, const boost::python::object& right);
1454 jgs 94
1455     /**
1456     \brief
1457     Operator*
1458     Takes LHS Data object and RHS python::object.
1459     python::object must be convertable to Data type.
1460     */
1461 woo409 757 ESCRIPT_DLL_API Data operator*(const Data& left, const boost::python::object& right);
1462 jgs 94
1463     /**
1464     \brief
1465     Operator/
1466     Takes LHS Data object and RHS python::object.
1467     python::object must be convertable to Data type.
1468     */
1469 woo409 757 ESCRIPT_DLL_API Data operator/(const Data& left, const boost::python::object& right);
1470 jgs 94
1471     /**
1472     \brief
1473     Operator+
1474     Takes LHS python::object and RHS Data object.
1475     python::object must be convertable to Data type.
1476     */
1477 woo409 757 ESCRIPT_DLL_API Data operator+(const boost::python::object& left, const Data& right);
1478 jgs 94
1479     /**
1480     \brief
1481     Operator-
1482     Takes LHS python::object and RHS Data object.
1483     python::object must be convertable to Data type.
1484     */
1485 woo409 757 ESCRIPT_DLL_API Data operator-(const boost::python::object& left, const Data& right);
1486 jgs 94
1487     /**
1488     \brief
1489     Operator*
1490     Takes LHS python::object and RHS Data object.
1491     python::object must be convertable to Data type.
1492     */
1493 woo409 757 ESCRIPT_DLL_API Data operator*(const boost::python::object& left, const Data& right);
1494 jgs 94
1495     /**
1496     \brief
1497     Operator/
1498     Takes LHS python::object and RHS Data object.
1499     python::object must be convertable to Data type.
1500     */
1501 woo409 757 ESCRIPT_DLL_API Data operator/(const boost::python::object& left, const Data& right);
1502 jgs 94
1503     /**
1504     \brief
1505     Output operator
1506     */
1507 woo409 757 ESCRIPT_DLL_API std::ostream& operator<<(std::ostream& o, const Data& data);
1508 jgs 94
1509     /**
1510     \brief
1511 ksteube 813 Compute a tensor product of two Data objects
1512     \param arg0 - Input - Data object
1513     \param arg1 - Input - Data object
1514     \param axis_offset - Input - axis offset
1515     \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1516     */
1517     ESCRIPT_DLL_API
1518     Data
1519     C_GeneralTensorProduct(Data& arg0,
1520     Data& arg1,
1521     int axis_offset=0,
1522     int transpose=0);
1523    
1524     /**
1525     \brief
1526 jgs 94 Return true if operands are equivalent, else return false.
1527     NB: this operator does very little at this point, and isn't to
1528     be relied on. Requires further implementation.
1529     */
1530 woo409 757 //ESCRIPT_DLL_API bool operator==(const Data& left, const Data& right);
1531 jgs 94
1532 jgs 102 /**
1533     \brief
1534     Perform the given binary operation with this and right as operands.
1535     Right is a Data object.
1536     */
1537 jgs 94 template <class BinaryFunction>
1538     inline
1539     void
1540     Data::binaryOp(const Data& right,
1541     BinaryFunction operation)
1542     {
1543     //
1544     // if this has a rank of zero promote it to the rank of the RHS
1545     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1546 gross 854 throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1547 jgs 94 }
1548     //
1549     // initially make the temporary a shallow copy
1550     Data tempRight(right);
1551     if (getFunctionSpace()!=right.getFunctionSpace()) {
1552     if (right.probeInterpolation(getFunctionSpace())) {
1553     //
1554     // an interpolation is required so create a new Data
1555     tempRight=Data(right,this->getFunctionSpace());
1556     } else if (probeInterpolation(right.getFunctionSpace())) {
1557     //
1558     // interpolate onto the RHS function space
1559     Data tempLeft(*this,right.getFunctionSpace());
1560     m_data=tempLeft.m_data;
1561     }
1562     }
1563     operandCheck(tempRight);
1564     //
1565     // ensure this has the right type for the RHS
1566 jgs 102 typeMatchRight(tempRight);
1567 jgs 94 //
1568     // Need to cast to the concrete types so that the correct binaryOp
1569     // is called.
1570     if (isExpanded()) {
1571     //
1572     // Expanded data will be done in parallel, the right hand side can be
1573     // of any data type
1574     DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1575     EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1576     escript::binaryOp(*leftC,*(tempRight.m_data.get()),operation);
1577     } else if (isTagged()) {
1578     //
1579     // Tagged data is operated on serially, the right hand side can be
1580     // either DataConstant or DataTagged
1581     DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1582     EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1583     if (right.isTagged()) {
1584     DataTagged* rightC=dynamic_cast<DataTagged*>(tempRight.m_data.get());
1585     EsysAssert((rightC!=0), "Programming error - casting to DataTagged.");
1586     escript::binaryOp(*leftC,*rightC,operation);
1587     } else {
1588     DataConstant* rightC=dynamic_cast<DataConstant*>(tempRight.m_data.get());
1589     EsysAssert((rightC!=0), "Programming error - casting to DataConstant.");
1590     escript::binaryOp(*leftC,*rightC,operation);
1591     }
1592 jgs 102 } else if (isConstant()) {
1593 jgs 94 DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1594     DataConstant* rightC=dynamic_cast<DataConstant*>(tempRight.m_data.get());
1595     EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");
1596     escript::binaryOp(*leftC,*rightC,operation);
1597     }
1598 gross 854 #if defined DOPROF
1599     profData->binary++;
1600     #endif
1601 jgs 94 }
1602    
1603 jgs 102 /**
1604     \brief
1605     Perform the given unary operation on other and return the result.
1606     Given operation is performed on each element of each data point, thus
1607     argument object is a rank n Data object, and returned object is a rank n
1608     Data object.
1609     Calls Data::unaryOp.
1610     */
1611 jgs 94 template <class UnaryFunction>
1612     inline
1613 jgs 102 Data
1614     unaryOp(const Data& other,
1615     UnaryFunction operation)
1616     {
1617     Data result;
1618     result.copy(other);
1619     result.unaryOp(operation);
1620     return result;
1621     }
1622    
1623     /**
1624     \brief
1625     Perform the given unary operation on this.
1626     Given operation is performed on each element of each data point.
1627     Calls escript::unaryOp.
1628     */
1629     template <class UnaryFunction>
1630     inline
1631 jgs 94 void
1632     Data::unaryOp(UnaryFunction operation)
1633     {
1634     if (isExpanded()) {
1635     DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1636     EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1637     escript::unaryOp(*leftC,operation);
1638     } else if (isTagged()) {
1639     DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1640     EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1641     escript::unaryOp(*leftC,operation);
1642 jgs 102 } else if (isConstant()) {
1643 jgs 94 DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1644     EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1645     escript::unaryOp(*leftC,operation);
1646     }
1647     }
1648    
1649 jgs 102 /**
1650     \brief
1651     Perform the given Data object reduction algorithm on this and return the result.
1652     Given operation combines each element of each data point, thus argument
1653     object (*this) is a rank n Data object, and returned object is a scalar.
1654     Calls escript::algorithm.
1655     */
1656 jgs 147 template <class BinaryFunction>
1657 jgs 94 inline
1658     double
1659 jgs 147 Data::algorithm(BinaryFunction operation, double initial_value) const
1660 jgs 94 {
1661     if (isExpanded()) {
1662     DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1663     EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1664 jgs 147 return escript::algorithm(*leftC,operation,initial_value);
1665 jgs 102 } else if (isTagged()) {
1666 jgs 94 DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1667     EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1668 jgs 147 return escript::algorithm(*leftC,operation,initial_value);
1669 jgs 102 } else if (isConstant()) {
1670 jgs 94 DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1671     EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1672 jgs 147 return escript::algorithm(*leftC,operation,initial_value);
1673 jgs 94 }
1674 jgs 102 return 0;
1675 jgs 94 }
1676    
1677 jgs 102 /**
1678     \brief
1679     Perform the given data point reduction algorithm on data and return the result.
1680     Given operation combines each element within each data point into a scalar,
1681     thus argument object is a rank n Data object, and returned object is a
1682     rank 0 Data object.
1683     Calls escript::dp_algorithm.
1684     */
1685 jgs 147 template <class BinaryFunction>
1686 jgs 94 inline
1687     Data
1688 jgs 147 Data::dp_algorithm(BinaryFunction operation, double initial_value) const
1689 jgs 94 {
1690 jgs 106 if (isExpanded()) {
1691 jgs 559 Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1692 jgs 106 DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
1693 jgs 102 DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1694     EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1695     EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1696 jgs 147 escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
1697 jgs 559 return result;
1698 jgs 106 } else if (isTagged()) {
1699     DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1700 jgs 562 DataArrayView::ShapeType viewShape;
1701     DataArrayView::ValueType viewData(1);
1702     viewData[0]=0;
1703     DataArrayView defaultValue(viewData,viewShape);
1704 jgs 559 DataTagged::TagListType keys;
1705 jgs 562 DataTagged::ValueListType values;
1706 jgs 559 DataTagged::DataMapType::const_iterator i;
1707     for (i=dataT->getTagLookup().begin();i!=dataT->getTagLookup().end();i++) {
1708     keys.push_back(i->first);
1709 jgs 562 values.push_back(defaultValue);
1710 jgs 559 }
1711     Data result(keys,values,defaultValue,getFunctionSpace());
1712 jgs 102 DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1713     EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1714     EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1715 jgs 147 escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
1716 jgs 559 return result;
1717 jgs 106 } else if (isConstant()) {
1718 jgs 559 Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1719 jgs 106 DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1720 jgs 102 DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1721     EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1722     EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1723 jgs 147 escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
1724 jgs 559 return result;
1725 jgs 102 }
1726 jgs 559 Data falseRetVal; // to keep compiler quiet
1727     return falseRetVal;
1728 jgs 94 }
1729    
1730     }
1731     #endif

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26