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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 921 - (hide annotations)
Fri Jan 5 00:54:37 2007 UTC (12 years, 3 months ago) by gross
File MIME type: text/plain
File size: 42013 byte(s)
I have done some clarification on functions that allow to access individual data point values in a Data object. 
The term "data point number" is always local on a MPI process and referes to the value (data_point_in_sample, sample)
as a single identifyer (data_point_in_sample + sample * number_data_points_per_sample). a "global data point number"
referes to a tuple of a processour id and local data point number.

The function convertToNumArrayFromSampleNo has been removed now and convertToNumArrayFromDPNo renamed to getValueOfDataPoint.
There are two new functions:

   getNumberOfDataPoints
   setValueOfDataPoint

This allows you to do things like:

  in=Data(..)
  out=Data(..)
   for i in xrange(in.getNumberOfDataPoints())
       in_loc=in.getValueOfDataPoint(i)
       out_loc=< some operations on in_loc>
       out.setValueOfDataPoint(i,out_loc)


Also mindp  is renamed to  minGlobalDataPoint and there is a new function getValueOfGlobalDataPoint. While in MPI the functions getNumberOfDataPoints and getValueOfDataPoint are working locally on each process (so the code above is executed in parallel).
the latter allows getting a single value across all processors. 


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26