1 |
// $Id$ |
// $Id$ |
2 |
/*============================================================================= |
/* |
3 |
|
************************************************************ |
4 |
****************************************************************************** |
* Copyright 2006 by ACcESS MNRF * |
5 |
* * |
* * |
6 |
* COPYRIGHT ACcESS 2004 - All Rights Reserved * |
* http://www.access.edu.au * |
7 |
* * |
* Primary Business: Queensland, Australia * |
8 |
* This software is the property of ACcESS. No part of this code * |
* Licensed under the Open Software License version 3.0 * |
9 |
* may be copied in any form or by any means without the expressed written * |
* http://www.opensource.org/licenses/osl-3.0.php * |
10 |
* consent of ACcESS. Copying, use or modification of this software * |
* * |
11 |
* by any unauthorised person is illegal unless that * |
************************************************************ |
12 |
* person has a software license agreement with ACcESS. * |
*/ |
|
* * |
|
|
****************************************************************************** |
|
13 |
|
|
14 |
******************************************************************************/ |
/** \file Data.h */ |
15 |
|
|
16 |
#ifndef DATA_H |
#ifndef DATA_H |
17 |
#define DATA_H |
#define DATA_H |
18 |
|
|
19 |
#include "escript/Data/DataAbstract.h" |
#include "DataAbstract.h" |
20 |
#include "escript/Data/DataTagged.h" |
#include "DataAlgorithm.h" |
21 |
#include "escript/Data/FunctionSpace.h" |
#include "FunctionSpace.h" |
22 |
#include "escript/Data/BinaryOp.h" |
#include "BinaryOp.h" |
23 |
#include "escript/Data/UnaryOp.h" |
#include "UnaryOp.h" |
24 |
|
#include "DataException.h" |
25 |
|
|
26 |
extern "C" { |
extern "C" { |
27 |
#include "escript/Data/DataC.h" |
#include "DataC.h" |
28 |
} |
} |
29 |
|
|
|
#include <iostream> |
|
30 |
#include <string> |
#include <string> |
|
#include <memory> |
|
31 |
#include <algorithm> |
#include <algorithm> |
32 |
|
|
33 |
#include <boost/shared_ptr.hpp> |
#include <boost/shared_ptr.hpp> |
34 |
#include <boost/python/object.hpp> |
#include <boost/python/object.hpp> |
|
#include <boost/python/list.hpp> |
|
35 |
#include <boost/python/tuple.hpp> |
#include <boost/python/tuple.hpp> |
36 |
#include <boost/python/numeric.hpp> |
#include <boost/python/numeric.hpp> |
37 |
|
|
38 |
|
namespace escript { |
39 |
|
|
40 |
|
// |
41 |
|
// Forward declaration for various implementations of Data. |
42 |
|
class DataConstant; |
43 |
|
class DataTagged; |
44 |
|
class DataExpanded; |
45 |
|
|
46 |
/** |
/** |
47 |
\brief |
\brief |
48 |
Data is essentially a factory class which creates the appropriate Data |
Data creates the appropriate Data object for the given construction |
49 |
object for the given construction arguments. It retains control over |
arguments. |
|
the object created for the lifetime of the object. |
|
|
The type of Data object referred to may change during the lifetime of |
|
|
the Data object. |
|
50 |
|
|
51 |
Description: |
Description: |
52 |
Data is essentially a factory class which creates the appropriate Data |
Data is essentially a factory class which creates the appropriate Data |
55 |
The type of Data object referred to may change during the lifetime of |
The type of Data object referred to may change during the lifetime of |
56 |
the Data object. |
the Data object. |
57 |
*/ |
*/ |
|
|
|
|
namespace escript { |
|
|
|
|
|
// |
|
|
// Forward declaration for various implimentations of Data. |
|
|
class DataEmpty; |
|
|
class DataConstant; |
|
|
class DataTagged; |
|
|
class DataExpanded; |
|
|
|
|
58 |
class Data { |
class Data { |
59 |
|
|
60 |
public: |
public: |
61 |
|
|
62 |
|
// These typedefs allow function names to be cast to pointers |
63 |
|
// to functions of the appropriate type when calling unaryOp etc. |
64 |
typedef double (*UnaryDFunPtr)(double); |
typedef double (*UnaryDFunPtr)(double); |
65 |
typedef double (*BinaryDFunPtr)(double,double); |
typedef double (*BinaryDFunPtr)(double,double); |
66 |
|
|
143 |
\param what - Input - A description of what this data represents. |
\param what - Input - A description of what this data represents. |
144 |
\param expanded - Input - Flag, if true fill the entire container with |
\param expanded - Input - Flag, if true fill the entire container with |
145 |
the appropriate values. |
the appropriate values. |
146 |
|
==>* |
147 |
*/ |
*/ |
148 |
Data(const DataTagged::TagListType& tagKeys, |
Data(const DataTagged::TagListType& tagKeys, |
149 |
const DataTagged::ValueListType& values, |
const DataTagged::ValueListType& values, |
200 |
const boost::python::tuple& shape=boost::python::make_tuple(), |
const boost::python::tuple& shape=boost::python::make_tuple(), |
201 |
const FunctionSpace& what=FunctionSpace(), |
const FunctionSpace& what=FunctionSpace(), |
202 |
bool expanded=false); |
bool expanded=false); |
203 |
|
/** |
204 |
|
\brief |
205 |
|
Destructor |
206 |
|
*/ |
207 |
|
~Data(); |
208 |
|
|
209 |
/** |
/** |
210 |
\brief |
\brief |
219 |
|
|
220 |
/** |
/** |
221 |
\brief |
\brief |
222 |
|
Return the values of all data-points as a single python numarray object. |
223 |
|
*/ |
224 |
|
const boost::python::numeric::array |
225 |
|
convertToNumArray(); |
226 |
|
|
227 |
|
/** |
228 |
|
\brief |
229 |
|
Return the values of all data-points for the given sample as a single python numarray object. |
230 |
|
*/ |
231 |
|
const boost::python::numeric::array |
232 |
|
convertToNumArrayFromSampleNo(int sampleNo); |
233 |
|
|
234 |
|
/** |
235 |
|
\brief |
236 |
|
Return the value of the specified data-point as a single python numarray object. |
237 |
|
*/ |
238 |
|
const boost::python::numeric::array |
239 |
|
convertToNumArrayFromDPNo(int sampleNo, |
240 |
|
int dataPointNo); |
241 |
|
|
242 |
|
/** |
243 |
|
\brief |
244 |
|
Fills the expanded Data object from values of a python numarray object. |
245 |
|
*/ |
246 |
|
void |
247 |
|
fillFromNumArray(const boost::python::numeric::array); |
248 |
|
|
249 |
|
/** |
250 |
|
\brief |
251 |
|
Return the tag number associated with the given data-point. |
252 |
|
|
253 |
|
The data-point number here corresponds to the data-point number in the |
254 |
|
numarray returned by convertToNumArray. |
255 |
|
*/ |
256 |
|
int |
257 |
|
getTagNumber(int dpno); |
258 |
|
|
259 |
|
/** |
260 |
|
\brief |
261 |
Return the C wrapper for the Data object. |
Return the C wrapper for the Data object. |
262 |
*/ |
*/ |
263 |
escriptDataC |
escriptDataC |
306 |
If possible convert this Data to DataTagged. This will only allow |
If possible convert this Data to DataTagged. This will only allow |
307 |
Constant data to be converted to tagged. An attempt to convert |
Constant data to be converted to tagged. An attempt to convert |
308 |
Expanded data to tagged will throw an exception. |
Expanded data to tagged will throw an exception. |
309 |
|
==>* |
310 |
*/ |
*/ |
311 |
void |
void |
312 |
tag(); |
tag(); |
436 |
|
|
437 |
/** |
/** |
438 |
\brief |
\brief |
439 |
|
Assign the given value to the data-points referenced by the given |
440 |
|
reference number. |
441 |
|
|
442 |
|
The value supplied is a python numarray object. The data from this numarray |
443 |
|
is unpacked into a DataArray, and this is used to set the corresponding |
444 |
|
data-points in the underlying Data object. |
445 |
|
|
446 |
|
If the underlying Data object cannot be accessed via reference numbers, an |
447 |
|
exception will be thrown. |
448 |
|
|
449 |
|
\param ref - Input - reference number. |
450 |
|
\param value - Input - value to assign to data-points associated with |
451 |
|
the given reference number. |
452 |
|
*/ |
453 |
|
void |
454 |
|
setRefValue(int ref, |
455 |
|
const boost::python::numeric::array& value); |
456 |
|
|
457 |
|
/** |
458 |
|
\brief |
459 |
|
Return the values associated with the data-points referenced by the given |
460 |
|
reference number. |
461 |
|
|
462 |
|
The value supplied is a python numarray object. The data from the corresponding |
463 |
|
data-points in this Data object are packed into the given numarray object. |
464 |
|
|
465 |
|
If the underlying Data object cannot be accessed via reference numbers, an |
466 |
|
exception will be thrown. |
467 |
|
|
468 |
|
\param ref - Input - reference number. |
469 |
|
\param value - Output - object to receive values from data-points |
470 |
|
associated with the given reference number. |
471 |
|
*/ |
472 |
|
void |
473 |
|
getRefValue(int ref, |
474 |
|
boost::python::numeric::array& value); |
475 |
|
|
476 |
|
/** |
477 |
|
\brief |
478 |
Return a view into the data for the data point specified. |
Return a view into the data for the data point specified. |
479 |
NOTE: Construction of the DataArrayView is a relatively expensive |
NOTE: Construction of the DataArrayView is a relatively expensive |
480 |
operation. |
operation. |
500 |
\brief |
\brief |
501 |
Return the data point shape as a tuple of integers. |
Return the data point shape as a tuple of integers. |
502 |
*/ |
*/ |
503 |
boost::python::tuple |
const boost::python::tuple |
504 |
getShapeTuple() const; |
getShapeTuple() const; |
505 |
|
|
506 |
/** |
/** |
525 |
cannot be converted to a DataTagged object. |
cannot be converted to a DataTagged object. |
526 |
\param tagKey - Input - Integer key. |
\param tagKey - Input - Integer key. |
527 |
\param value - Input - Value to associate with given key. |
\param value - Input - Value to associate with given key. |
528 |
|
==>* |
529 |
*/ |
*/ |
530 |
void |
void |
531 |
setTaggedValue(int tagKey, |
setTaggedValue(int tagKey, |
538 |
cannot be converted to a DataTagged object. |
cannot be converted to a DataTagged object. |
539 |
\param tagKey - Input - Integer key. |
\param tagKey - Input - Integer key. |
540 |
\param value - Input - Value to associate with given key. |
\param value - Input - Value to associate with given key. |
541 |
Note: removed for now - this version not needed, and breaks escript.cpp |
==>* |
542 |
*/ |
*/ |
|
/* |
|
543 |
void |
void |
544 |
setTaggedValue(int tagKey, |
setTaggedValueFromCPP(int tagKey, |
545 |
const DataArrayView& value); |
const DataArrayView& value); |
|
*/ |
|
546 |
|
|
547 |
/** |
/** |
548 |
\brief |
\brief |
560 |
\brief |
\brief |
561 |
Interpolates this onto the given functionspace and returns |
Interpolates this onto the given functionspace and returns |
562 |
the result as a Data object. |
the result as a Data object. |
563 |
|
* |
564 |
*/ |
*/ |
565 |
Data |
Data |
566 |
interpolate(const FunctionSpace& functionspace) const; |
interpolate(const FunctionSpace& functionspace) const; |
569 |
\brief |
\brief |
570 |
Calculates the gradient of the data at the data points of functionspace. |
Calculates the gradient of the data at the data points of functionspace. |
571 |
If functionspace is not present the function space of Function(getDomain()) is used. |
If functionspace is not present the function space of Function(getDomain()) is used. |
572 |
|
* |
573 |
*/ |
*/ |
574 |
Data |
Data |
575 |
gradOn(const FunctionSpace& functionspace) const; |
gradOn(const FunctionSpace& functionspace) const; |
580 |
/** |
/** |
581 |
\brief |
\brief |
582 |
Calculate the integral over the function space domain. |
Calculate the integral over the function space domain. |
583 |
|
* |
584 |
*/ |
*/ |
585 |
boost::python::numeric::array |
boost::python::numeric::array |
586 |
integrate() const; |
integrate() const; |
588 |
/** |
/** |
589 |
\brief |
\brief |
590 |
Return a Data with a 1 for +ive values and a 0 for 0 or -ive values. |
Return a Data with a 1 for +ive values and a 0 for 0 or -ive values. |
591 |
|
* |
592 |
*/ |
*/ |
593 |
Data |
Data |
594 |
wherePositive() const; |
wherePositive() const; |
596 |
/** |
/** |
597 |
\brief |
\brief |
598 |
Return a Data with a 1 for -ive values and a 0 for +ive or 0 values. |
Return a Data with a 1 for -ive values and a 0 for +ive or 0 values. |
599 |
|
* |
600 |
*/ |
*/ |
601 |
Data |
Data |
602 |
whereNegative() const; |
whereNegative() const; |
604 |
/** |
/** |
605 |
\brief |
\brief |
606 |
Return a Data with a 1 for +ive or 0 values and a 0 for -ive values. |
Return a Data with a 1 for +ive or 0 values and a 0 for -ive values. |
607 |
|
* |
608 |
*/ |
*/ |
609 |
Data |
Data |
610 |
whereNonNegative() const; |
whereNonNegative() const; |
612 |
/** |
/** |
613 |
\brief |
\brief |
614 |
Return a Data with a 1 for -ive or 0 values and a 0 for +ive values. |
Return a Data with a 1 for -ive or 0 values and a 0 for +ive values. |
615 |
|
* |
616 |
*/ |
*/ |
617 |
Data |
Data |
618 |
whereNonPositive() const; |
whereNonPositive() const; |
620 |
/** |
/** |
621 |
\brief |
\brief |
622 |
Return a Data with a 1 for 0 values and a 0 for +ive or -ive values. |
Return a Data with a 1 for 0 values and a 0 for +ive or -ive values. |
623 |
|
* |
624 |
*/ |
*/ |
625 |
Data |
Data |
626 |
whereZero() const; |
whereZero(double tol=0.0) const; |
627 |
|
|
628 |
/** |
/** |
629 |
\brief |
\brief |
630 |
Return a Data with a 0 for 0 values and a 1 for +ive or -ive values. |
Return a Data with a 0 for 0 values and a 1 for +ive or -ive values. |
631 |
|
* |
632 |
*/ |
*/ |
633 |
Data |
Data |
634 |
whereNonZero() const; |
whereNonZero(double tol=0.0) const; |
635 |
|
|
636 |
|
/** |
637 |
|
\brief |
638 |
|
Return the maximum absolute value of this Data object. |
639 |
|
* |
640 |
|
*/ |
641 |
|
double |
642 |
|
Lsup() const; |
643 |
|
|
644 |
|
/** |
645 |
|
\brief |
646 |
|
Return the minimum absolute value of this Data object. |
647 |
|
* |
648 |
|
*/ |
649 |
|
double |
650 |
|
Linf() const; |
651 |
|
|
652 |
|
/** |
653 |
|
\brief |
654 |
|
Return the maximum value of this Data object. |
655 |
|
* |
656 |
|
*/ |
657 |
|
double |
658 |
|
sup() const; |
659 |
|
|
660 |
|
/** |
661 |
|
\brief |
662 |
|
Return the minimum value of this Data object. |
663 |
|
* |
664 |
|
*/ |
665 |
|
double |
666 |
|
inf() const; |
667 |
|
|
668 |
|
/** |
669 |
|
\brief |
670 |
|
Return the absolute value of each data point of this Data object. |
671 |
|
* |
672 |
|
*/ |
673 |
|
Data |
674 |
|
abs() const; |
675 |
|
|
676 |
|
/** |
677 |
|
\brief |
678 |
|
Return the maximum value of each data point of this Data object. |
679 |
|
* |
680 |
|
*/ |
681 |
|
Data |
682 |
|
maxval() const; |
683 |
|
|
684 |
|
/** |
685 |
|
\brief |
686 |
|
Return the minimum value of each data point of this Data object. |
687 |
|
* |
688 |
|
*/ |
689 |
|
Data |
690 |
|
minval() const; |
691 |
|
|
692 |
|
/** |
693 |
|
\brief |
694 |
|
Return the (sample number, data-point number) of the data point with |
695 |
|
the minimum value in this Data object. |
696 |
|
*/ |
697 |
|
const boost::python::tuple |
698 |
|
mindp() const; |
699 |
|
|
700 |
|
void |
701 |
|
calc_mindp(int& SampleNo, |
702 |
|
int& DataPointNo) const; |
703 |
|
|
704 |
|
/** |
705 |
|
\brief |
706 |
|
Return the sign of each data point of this Data object. |
707 |
|
-1 for negative values, zero for zero values, 1 for positive values. |
708 |
|
* |
709 |
|
*/ |
710 |
|
Data |
711 |
|
sign() const; |
712 |
|
|
713 |
|
/** |
714 |
|
\brief |
715 |
|
Return the eigenvalues of the symmetric part at each data point of this Data object in increasing values. |
716 |
|
Currently this function is restricted to rank 2, square shape, and dimension 3. |
717 |
|
* |
718 |
|
*/ |
719 |
|
Data |
720 |
|
eigenvalues() const; |
721 |
|
|
722 |
|
/** |
723 |
|
\brief |
724 |
|
Return the eigenvalues and corresponding eigenvcetors of the symmetric part at each data point of this Data object. |
725 |
|
the eigenvalues are ordered in increasing size where eigenvalues with relative difference less than |
726 |
|
tol are treated as equal. The eigenvectors are orthogonal, normalized and the sclaed such that the |
727 |
|
first non-zero entry is positive. |
728 |
|
Currently this function is restricted to rank 2, square shape, and dimension 3 |
729 |
|
* |
730 |
|
*/ |
731 |
|
const boost::python::tuple |
732 |
|
eigenvalues_and_eigenvectors(const double tol=1.e-12) const; |
733 |
|
|
734 |
|
/** |
735 |
|
\brief |
736 |
|
Transpose each data point of this Data object around the given axis. |
737 |
|
--* not implemented yet *-- |
738 |
|
* |
739 |
|
*/ |
740 |
|
Data |
741 |
|
transpose(int axis) const; |
742 |
|
|
743 |
|
/** |
744 |
|
\brief |
745 |
|
Calculate the trace of each data point of this Data object. |
746 |
|
* |
747 |
|
*/ |
748 |
|
Data |
749 |
|
trace() const; |
750 |
|
|
751 |
/** |
/** |
752 |
\brief |
\brief |
753 |
Return the sin of each data point of this Data object. |
Return the sin of each data point of this Data object. |
754 |
|
* |
755 |
*/ |
*/ |
756 |
Data |
Data |
757 |
sin() const; |
sin() const; |
759 |
/** |
/** |
760 |
\brief |
\brief |
761 |
Return the cos of each data point of this Data object. |
Return the cos of each data point of this Data object. |
762 |
|
* |
763 |
*/ |
*/ |
764 |
Data |
Data |
765 |
cos() const; |
cos() const; |
767 |
/** |
/** |
768 |
\brief |
\brief |
769 |
Return the tan of each data point of this Data object. |
Return the tan of each data point of this Data object. |
770 |
|
* |
771 |
*/ |
*/ |
772 |
Data |
Data |
773 |
tan() const; |
tan() const; |
774 |
|
|
775 |
/** |
/** |
776 |
\brief |
\brief |
777 |
Return the log to base 10 of each data point of this Data object. |
Return the asin of each data point of this Data object. |
778 |
|
* |
779 |
*/ |
*/ |
780 |
Data |
Data |
781 |
log() const; |
asin() const; |
782 |
|
|
783 |
/** |
/** |
784 |
\brief |
\brief |
785 |
Return the natural log of each data point of this Data object. |
Return the acos of each data point of this Data object. |
786 |
|
* |
787 |
*/ |
*/ |
788 |
Data |
Data |
789 |
ln() const; |
acos() const; |
790 |
|
|
791 |
/** |
/** |
792 |
\brief |
\brief |
793 |
Return the maximum absolute value of this Data object. |
Return the atan of each data point of this Data object. |
794 |
|
* |
795 |
*/ |
*/ |
796 |
double |
Data |
797 |
Lsup() const; |
atan() const; |
798 |
|
|
799 |
/** |
/** |
800 |
\brief |
\brief |
801 |
Return the maximum value of this Data object. |
Return the sinh of each data point of this Data object. |
802 |
|
* |
803 |
*/ |
*/ |
804 |
double |
Data |
805 |
sup() const; |
sinh() const; |
806 |
|
|
807 |
/** |
/** |
808 |
\brief |
\brief |
809 |
Return the minimum value of this Data object. |
Return the cosh of each data point of this Data object. |
810 |
|
* |
811 |
*/ |
*/ |
812 |
double |
Data |
813 |
inf() const; |
cosh() const; |
814 |
|
|
815 |
/** |
/** |
816 |
\brief |
\brief |
817 |
Return the absolute value of each data point of this Data object. |
Return the tanh of each data point of this Data object. |
818 |
|
* |
819 |
*/ |
*/ |
820 |
Data |
Data |
821 |
abs() const; |
tanh() const; |
822 |
|
|
823 |
/** |
/** |
824 |
\brief |
\brief |
825 |
Return the maximum value of each data point of this Data object. |
Return the asinh of each data point of this Data object. |
826 |
|
* |
827 |
*/ |
*/ |
828 |
Data |
Data |
829 |
maxval() const; |
asinh() const; |
830 |
|
|
831 |
/** |
/** |
832 |
\brief |
\brief |
833 |
Return the minimum value of each data point of this Data object. |
Return the acosh of each data point of this Data object. |
834 |
|
* |
835 |
*/ |
*/ |
836 |
Data |
Data |
837 |
minval() const; |
acosh() const; |
838 |
|
|
839 |
/** |
/** |
840 |
\brief |
\brief |
841 |
Return the length of each data point of this Data object. |
Return the atanh of each data point of this Data object. |
842 |
sqrt(sum(A[i,j,k,l]^2)) |
* |
843 |
*/ |
*/ |
844 |
Data |
Data |
845 |
length() const; |
atanh() const; |
846 |
|
|
847 |
/** |
/** |
848 |
\brief |
\brief |
849 |
Return the sign of each data point of this Data object. |
Return the log to base 10 of each data point of this Data object. |
850 |
-1 for negative values, zero for zero values, 1 for positive values. |
* |
851 |
*/ |
*/ |
852 |
Data |
Data |
853 |
sign() const; |
log10() const; |
854 |
|
|
855 |
/** |
/** |
856 |
\transpose |
\brief |
857 |
Transpose each data point of this Data object around the given axis. |
Return the natural log of each data point of this Data object. |
858 |
|
* |
859 |
*/ |
*/ |
860 |
Data |
Data |
861 |
transpose(int axis) const; |
log() const; |
862 |
|
|
863 |
/** |
/** |
864 |
\trace |
\brief |
865 |
Calculate the trace of each data point of this Data object. |
Return the exponential function of each data point of this Data object. |
866 |
sum(A[i,i,i,i]) |
* |
867 |
*/ |
*/ |
868 |
Data |
Data |
869 |
trace() const; |
exp() const; |
870 |
|
|
871 |
/** |
/** |
872 |
\exp |
\brief |
873 |
Return the exponential function of each data point of this Data object. |
Return the square root of each data point of this Data object. |
874 |
|
* |
875 |
*/ |
*/ |
876 |
Data |
Data |
877 |
exp() const; |
sqrt() const; |
878 |
|
|
879 |
/** |
/** |
880 |
\sqrt |
\brief |
881 |
Return the square root of each data point of this Data object. |
Return the negation of each data point of this Data object. |
882 |
|
* |
883 |
*/ |
*/ |
884 |
Data |
Data |
885 |
sqrt() const; |
neg() const; |
886 |
|
|
887 |
|
/** |
888 |
|
\brief |
889 |
|
Return the identity of each data point of this Data object. |
890 |
|
Simply returns this object unmodified. |
891 |
|
* |
892 |
|
*/ |
893 |
|
Data |
894 |
|
pos() const; |
895 |
|
|
896 |
/** |
/** |
897 |
\brief |
\brief |
898 |
Return the given power of each data point of this Data object. |
Return the given power of each data point of this Data object. |
899 |
|
|
900 |
|
\param right Input - the power to raise the object to. |
901 |
|
* |
902 |
*/ |
*/ |
903 |
Data |
Data |
904 |
powD(const Data& right) const; |
powD(const Data& right) const; |
905 |
|
|
906 |
|
/** |
907 |
|
\brief |
908 |
|
Return the given power of each data point of this boost python object. |
909 |
|
|
910 |
|
\param right Input - the power to raise the object to. |
911 |
|
* |
912 |
|
*/ |
913 |
Data |
Data |
914 |
powO(const boost::python::object& right) const; |
powO(const boost::python::object& right) const; |
915 |
|
|
916 |
/** |
/** |
917 |
\brief |
\brief |
918 |
writes the object to a file in the DX file format |
writes the object to a file in the DX file format |
919 |
*/ |
*/ |
920 |
void |
void |
921 |
saveDX(std::string fileName) const; |
saveDX(std::string fileName) const; |
922 |
|
|
923 |
/** |
/** |
924 |
\brief |
\brief |
925 |
Return the negation of each data point of this Data object. |
writes the object to a file in the VTK file format |
|
*/ |
|
|
Data |
|
|
neg() const; |
|
|
|
|
|
/** |
|
|
\brief |
|
|
Return the identity of each data point of this Data object. |
|
|
Simply returns this object unmodified. |
|
926 |
*/ |
*/ |
927 |
Data |
void |
928 |
pos() const; |
saveVTK(std::string fileName) const; |
929 |
|
|
930 |
/** |
/** |
931 |
\brief |
\brief |
932 |
Overloaded operator += |
Overloaded operator += |
933 |
\param right - Input - The right hand side. |
\param right - Input - The right hand side. |
934 |
|
* |
935 |
*/ |
*/ |
936 |
Data& operator+=(const Data& right); |
Data& operator+=(const Data& right); |
937 |
Data& operator+=(const boost::python::object& right); |
Data& operator+=(const boost::python::object& right); |
940 |
\brief |
\brief |
941 |
Overloaded operator -= |
Overloaded operator -= |
942 |
\param right - Input - The right hand side. |
\param right - Input - The right hand side. |
943 |
|
* |
944 |
*/ |
*/ |
945 |
Data& operator-=(const Data& right); |
Data& operator-=(const Data& right); |
946 |
Data& operator-=(const boost::python::object& right); |
Data& operator-=(const boost::python::object& right); |
949 |
\brief |
\brief |
950 |
Overloaded operator *= |
Overloaded operator *= |
951 |
\param right - Input - The right hand side. |
\param right - Input - The right hand side. |
952 |
|
* |
953 |
*/ |
*/ |
954 |
Data& operator*=(const Data& right); |
Data& operator*=(const Data& right); |
955 |
Data& operator*=(const boost::python::object& right); |
Data& operator*=(const boost::python::object& right); |
958 |
\brief |
\brief |
959 |
Overloaded operator /= |
Overloaded operator /= |
960 |
\param right - Input - The right hand side. |
\param right - Input - The right hand side. |
961 |
|
* |
962 |
*/ |
*/ |
963 |
Data& operator/=(const Data& right); |
Data& operator/=(const Data& right); |
964 |
Data& operator/=(const boost::python::object& right); |
Data& operator/=(const boost::python::object& right); |
992 |
\brief |
\brief |
993 |
Copies slice from value into this Data object. |
Copies slice from value into this Data object. |
994 |
|
|
|
\description |
|
995 |
Implements the [] set operator in python. |
Implements the [] set operator in python. |
996 |
Calls setSlice. |
Calls setSlice. |
997 |
|
|
1024 |
Return a Data object containing the specified slice of |
Return a Data object containing the specified slice of |
1025 |
this Data object. |
this Data object. |
1026 |
\param region - Input - Region to copy. |
\param region - Input - Region to copy. |
1027 |
|
* |
1028 |
*/ |
*/ |
1029 |
Data |
Data |
1030 |
getSlice(const DataArrayView::RegionType& region) const; |
getSlice(const DataArrayView::RegionType& region) const; |
1035 |
Data object. |
Data object. |
1036 |
\param value - Input - Data to copy from. |
\param value - Input - Data to copy from. |
1037 |
\param region - Input - Region to copy. |
\param region - Input - Region to copy. |
1038 |
|
* |
1039 |
*/ |
*/ |
1040 |
void |
void |
1041 |
setSlice(const Data& value, |
setSlice(const Data& value, |
1042 |
const DataArrayView::RegionType& region); |
const DataArrayView::RegionType& region); |
1043 |
|
|
1044 |
|
/** |
1045 |
|
\brief |
1046 |
|
Archive the current Data object to the given file. |
1047 |
|
\param fileName - Input - file to archive to. |
1048 |
|
*/ |
1049 |
|
void |
1050 |
|
archiveData(const std::string fileName); |
1051 |
|
|
1052 |
|
/** |
1053 |
|
\brief |
1054 |
|
Extract the Data object archived in the given file, overwriting |
1055 |
|
the current Data object. |
1056 |
|
Note - the current object must be of type DataEmpty. |
1057 |
|
\param fileName - Input - file to extract from. |
1058 |
|
\param fspace - Input - a suitable FunctionSpace descibing the data. |
1059 |
|
*/ |
1060 |
|
void |
1061 |
|
extractData(const std::string fileName, |
1062 |
|
const FunctionSpace& fspace); |
1063 |
|
|
1064 |
protected: |
protected: |
1065 |
|
|
1066 |
private: |
private: |
1081 |
/** |
/** |
1082 |
\brief |
\brief |
1083 |
Perform the specified reduction algorithm on every element of every data point in |
Perform the specified reduction algorithm on every element of every data point in |
1084 |
this Data object and return the single double value result. |
this Data object according to the given function and return the single value result. |
1085 |
*/ |
*/ |
1086 |
template <class UnaryFunction> |
template <class BinaryFunction> |
1087 |
inline |
inline |
1088 |
double |
double |
1089 |
algorithm(UnaryFunction operation) const; |
algorithm(BinaryFunction operation, |
1090 |
|
double initial_value) const; |
1091 |
|
|
1092 |
|
/** |
1093 |
|
\brief |
1094 |
|
Reduce each data-point in this Data object using the given operation. Return a Data |
1095 |
|
object with the same number of data-points, but with each data-point containing only |
1096 |
|
one value - the result of the reduction operation on the corresponding data-point in |
1097 |
|
this Data object |
1098 |
|
*/ |
1099 |
|
template <class BinaryFunction> |
1100 |
|
inline |
1101 |
|
Data |
1102 |
|
dp_algorithm(BinaryFunction operation, |
1103 |
|
double initial_value) const; |
1104 |
|
|
1105 |
/** |
/** |
1106 |
\brief |
\brief |
1167 |
// pointer to the actual data object |
// pointer to the actual data object |
1168 |
boost::shared_ptr<DataAbstract> m_data; |
boost::shared_ptr<DataAbstract> m_data; |
1169 |
|
|
1170 |
|
// |
1171 |
|
// pointer to the internal profiling data |
1172 |
|
struct profDataEntry *profData; |
1173 |
|
|
1174 |
}; |
}; |
1175 |
|
|
1176 |
template <class IValueType> |
template <class IValueType> |
1466 |
object (*this) is a rank n Data object, and returned object is a scalar. |
object (*this) is a rank n Data object, and returned object is a scalar. |
1467 |
Calls escript::algorithm. |
Calls escript::algorithm. |
1468 |
*/ |
*/ |
1469 |
template <class UnaryFunction> |
template <class BinaryFunction> |
1470 |
inline |
inline |
1471 |
double |
double |
1472 |
Data::algorithm(UnaryFunction operation) const |
Data::algorithm(BinaryFunction operation, double initial_value) const |
1473 |
{ |
{ |
1474 |
if (isExpanded()) { |
if (isExpanded()) { |
1475 |
DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get()); |
DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get()); |
1476 |
EsysAssert((leftC!=0), "Programming error - casting to DataExpanded."); |
EsysAssert((leftC!=0), "Programming error - casting to DataExpanded."); |
1477 |
return escript::algorithm(*leftC,operation); |
return escript::algorithm(*leftC,operation,initial_value); |
1478 |
} else if (isTagged()) { |
} else if (isTagged()) { |
1479 |
DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get()); |
DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get()); |
1480 |
EsysAssert((leftC!=0), "Programming error - casting to DataTagged."); |
EsysAssert((leftC!=0), "Programming error - casting to DataTagged."); |
1481 |
return escript::algorithm(*leftC,operation); |
return escript::algorithm(*leftC,operation,initial_value); |
1482 |
} else if (isConstant()) { |
} else if (isConstant()) { |
1483 |
DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get()); |
DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get()); |
1484 |
EsysAssert((leftC!=0), "Programming error - casting to DataConstant."); |
EsysAssert((leftC!=0), "Programming error - casting to DataConstant."); |
1485 |
return escript::algorithm(*leftC,operation); |
return escript::algorithm(*leftC,operation,initial_value); |
1486 |
} |
} |
1487 |
return 0; |
return 0; |
1488 |
} |
} |
1495 |
rank 0 Data object. |
rank 0 Data object. |
1496 |
Calls escript::dp_algorithm. |
Calls escript::dp_algorithm. |
1497 |
*/ |
*/ |
1498 |
template <class UnaryFunction> |
template <class BinaryFunction> |
1499 |
inline |
inline |
1500 |
Data |
Data |
1501 |
dp_algorithm(const Data& data, |
Data::dp_algorithm(BinaryFunction operation, double initial_value) const |
|
UnaryFunction operation) |
|
1502 |
{ |
{ |
1503 |
Data result(0,DataArrayView::ShapeType(),data.getFunctionSpace(),data.isExpanded()); |
if (isExpanded()) { |
1504 |
if (data.isExpanded()) { |
Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded()); |
1505 |
DataExpanded* dataE=dynamic_cast<DataExpanded*>(data.m_data.get()); |
DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get()); |
1506 |
DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get()); |
DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get()); |
1507 |
EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded."); |
EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded."); |
1508 |
EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded."); |
EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded."); |
1509 |
escript::dp_algorithm(*dataE,*resultE,operation); |
escript::dp_algorithm(*dataE,*resultE,operation,initial_value); |
1510 |
} else if (data.isTagged()) { |
return result; |
1511 |
DataTagged* dataT=dynamic_cast<DataTagged*>(data.m_data.get()); |
} else if (isTagged()) { |
1512 |
|
DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get()); |
1513 |
|
DataArrayView::ShapeType viewShape; |
1514 |
|
DataArrayView::ValueType viewData(1); |
1515 |
|
viewData[0]=0; |
1516 |
|
DataArrayView defaultValue(viewData,viewShape); |
1517 |
|
DataTagged::TagListType keys; |
1518 |
|
DataTagged::ValueListType values; |
1519 |
|
DataTagged::DataMapType::const_iterator i; |
1520 |
|
for (i=dataT->getTagLookup().begin();i!=dataT->getTagLookup().end();i++) { |
1521 |
|
keys.push_back(i->first); |
1522 |
|
values.push_back(defaultValue); |
1523 |
|
} |
1524 |
|
Data result(keys,values,defaultValue,getFunctionSpace()); |
1525 |
DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get()); |
DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get()); |
1526 |
EsysAssert((dataT!=0), "Programming error - casting data to DataTagged."); |
EsysAssert((dataT!=0), "Programming error - casting data to DataTagged."); |
1527 |
EsysAssert((resultT!=0), "Programming error - casting result to DataTagged."); |
EsysAssert((resultT!=0), "Programming error - casting result to DataTagged."); |
1528 |
escript::dp_algorithm(*dataT,*resultT,operation); |
escript::dp_algorithm(*dataT,*resultT,operation,initial_value); |
1529 |
} else if (data.isConstant()) { |
return result; |
1530 |
DataConstant* dataC=dynamic_cast<DataConstant*>(data.m_data.get()); |
} else if (isConstant()) { |
1531 |
|
Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded()); |
1532 |
|
DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get()); |
1533 |
DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get()); |
DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get()); |
1534 |
EsysAssert((dataC!=0), "Programming error - casting data to DataConstant."); |
EsysAssert((dataC!=0), "Programming error - casting data to DataConstant."); |
1535 |
EsysAssert((resultC!=0), "Programming error - casting result to DataConstant."); |
EsysAssert((resultC!=0), "Programming error - casting result to DataConstant."); |
1536 |
escript::dp_algorithm(*dataC,*resultC,operation); |
escript::dp_algorithm(*dataC,*resultC,operation,initial_value); |
1537 |
|
return result; |
1538 |
} |
} |
1539 |
return result; |
Data falseRetVal; // to keep compiler quiet |
1540 |
|
return falseRetVal; |
1541 |
} |
} |
1542 |
|
|
1543 |
} |
} |