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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26