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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1137 - (hide annotations)
Thu May 10 08:11:31 2007 UTC (12 years, 5 months ago) by gross
Original Path: trunk/escript/src/Data.h
File MIME type: text/plain
File size: 41423 byte(s)
This version passes the tests on windows except for 

   * vtk
   * netCDF

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26