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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26