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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26