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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 971 - (hide annotations)
Wed Feb 14 04:40:49 2007 UTC (12 years, 4 months ago) by ksteube
File MIME type: text/plain
File size: 40944 byte(s)
Had to undo commit to new MPI branch. The changes went into the original and
not the branch. The files committed here are exactly the same as revision 969.


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26