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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 950 - (hide annotations)
Tue Feb 6 07:01:11 2007 UTC (12 years, 2 months ago) by gross
File MIME type: text/plain
File size: 42415 byte(s)
escript data objects can now be saved to netCDF files, see http://www.unidata.ucar.edu/software/netcdf/.
Currently only constant data are implemented with expanded and tagged data to follow.
There are two new functions to dump a data object

   s=Data(...)
   s.dump(<filename>)

and to recover it

   s=load(<filename>, domain)

Notice that the function space of s is recovered but domain is still need. 

dump and load will replace archive and extract.

The installation needs now the netCDF installed. 


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26