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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26