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

Diff of /trunk/escript/src/Data.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 121 by jgs, Fri May 6 04:26:16 2005 UTC revision 126 by jgs, Fri Jul 22 03:53:08 2005 UTC
# Line 35  Line 35 
35  #include "escript/Data/DataTagged.h"  #include "escript/Data/DataTagged.h"
36  #include "escript/Data/DataEmpty.h"  #include "escript/Data/DataEmpty.h"
37  #include "escript/Data/DataArray.h"  #include "escript/Data/DataArray.h"
38  #include "escript/Data/DataAlgorithm.h"  #include "escript/Data/DataProf.h"
39  #include "escript/Data/FunctionSpaceFactory.h"  #include "escript/Data/FunctionSpaceFactory.h"
40  #include "escript/Data/AbstractContinuousDomain.h"  #include "escript/Data/AbstractContinuousDomain.h"
41  #include "escript/Data/UnaryFuncs.h"  #include "escript/Data/UnaryFuncs.h"
# Line 45  using namespace boost::python; Line 45  using namespace boost::python;
45  using namespace boost;  using namespace boost;
46  using namespace escript;  using namespace escript;
47    
48    //
49    // global table of profiling data for all Data objects
50    DataProf dataProfTable;
51    
52  Data::Data()  Data::Data()
53  {  {
54    //    //
# Line 52  Data::Data() Line 56  Data::Data()
56    DataAbstract* temp=new DataEmpty();    DataAbstract* temp=new DataEmpty();
57    shared_ptr<DataAbstract> temp_data(temp);    shared_ptr<DataAbstract> temp_data(temp);
58    m_data=temp_data;    m_data=temp_data;
59      // create entry in global profiling table for this object
60      profData = dataProfTable.newData();
61  }  }
62    
63  Data::Data(double value,  Data::Data(double value,
# Line 65  Data::Data(double value, Line 71  Data::Data(double value,
71    }    }
72    DataArray temp(dataPointShape,value);    DataArray temp(dataPointShape,value);
73    initialise(temp.getView(),what,expanded);    initialise(temp.getView(),what,expanded);
74      // create entry in global profiling table for this object
75      profData = dataProfTable.newData();
76  }  }
77    
78  Data::Data(double value,  Data::Data(double value,
# Line 75  Data::Data(double value, Line 83  Data::Data(double value,
83    DataArray temp(dataPointShape,value);    DataArray temp(dataPointShape,value);
84    pair<int,int> dataShape=what.getDataShape();    pair<int,int> dataShape=what.getDataShape();
85    initialise(temp.getView(),what,expanded);    initialise(temp.getView(),what,expanded);
86      // create entry in global profiling table for this object
87      profData = dataProfTable.newData();
88  }  }
89    
90  Data::Data(const Data& inData)  Data::Data(const Data& inData)
91  {  {
92    m_data=inData.m_data;    m_data=inData.m_data;
93      // create entry in global profiling table for this object
94      profData = dataProfTable.newData();
95  }  }
96    
97  Data::Data(const Data& inData,  Data::Data(const Data& inData,
# Line 90  Data::Data(const Data& inData, Line 102  Data::Data(const Data& inData,
102    DataAbstract* tmp = inData.m_data->getSlice(region);    DataAbstract* tmp = inData.m_data->getSlice(region);
103    shared_ptr<DataAbstract> temp_data(tmp);    shared_ptr<DataAbstract> temp_data(tmp);
104    m_data=temp_data;    m_data=temp_data;
105      // create entry in global profiling table for this object
106      profData = dataProfTable.newData();
107  }  }
108    
109  Data::Data(const Data& inData,  Data::Data(const Data& inData,
# Line 99  Data::Data(const Data& inData, Line 113  Data::Data(const Data& inData,
113      m_data=inData.m_data;      m_data=inData.m_data;
114    } else {    } else {
115      Data tmp(0,inData.getPointDataView().getShape(),functionspace,true);      Data tmp(0,inData.getPointDataView().getShape(),functionspace,true);
116      // Note for Lutz, Must use a reference or pointer to a derived object      // Note: Must use a reference or pointer to a derived object
117      // in order to get polymorphic behaviour. Shouldn't really      // in order to get polymorphic behaviour. Shouldn't really
118      // be able to create an instance of AbstractDomain but that was done      // be able to create an instance of AbstractDomain but that was done
119      // as a boost python work around which may no longer be required.      // as a boost:python work around which may no longer be required.
120      const AbstractDomain& inDataDomain=inData.getDomain();      const AbstractDomain& inDataDomain=inData.getDomain();
121      if  (inDataDomain==functionspace.getDomain()) {      if  (inDataDomain==functionspace.getDomain()) {
122        inDataDomain.interpolateOnDomain(tmp,inData);        inDataDomain.interpolateOnDomain(tmp,inData);
# Line 111  Data::Data(const Data& inData, Line 125  Data::Data(const Data& inData,
125      }      }
126      m_data=tmp.m_data;      m_data=tmp.m_data;
127    }    }
128      // create entry in global profiling table for this object
129      profData = dataProfTable.newData();
130  }  }
131    
132  Data::Data(const DataTagged::TagListType& tagKeys,  Data::Data(const DataTagged::TagListType& tagKeys,
# Line 125  Data::Data(const DataTagged::TagListType Line 141  Data::Data(const DataTagged::TagListType
141    if (expanded) {    if (expanded) {
142      expand();      expand();
143    }    }
144      // create entry in global profiling table for this object
145      profData = dataProfTable.newData();
146  }  }
147    
148  Data::Data(const numeric::array& value,  Data::Data(const numeric::array& value,
# Line 132  Data::Data(const numeric::array& value, Line 150  Data::Data(const numeric::array& value,
150             bool expanded)             bool expanded)
151  {  {
152    initialise(value,what,expanded);    initialise(value,what,expanded);
153      // create entry in global profiling table for this object
154      profData = dataProfTable.newData();
155  }  }
156    
157  Data::Data(const DataArrayView& value,  Data::Data(const DataArrayView& value,
# Line 139  Data::Data(const DataArrayView& value, Line 159  Data::Data(const DataArrayView& value,
159             bool expanded)             bool expanded)
160  {  {
161    initialise(value,what,expanded);    initialise(value,what,expanded);
162      // create entry in global profiling table for this object
163      profData = dataProfTable.newData();
164  }  }
165    
166  Data::Data(const object& value,  Data::Data(const object& value,
# Line 147  Data::Data(const object& value, Line 169  Data::Data(const object& value,
169  {  {
170    numeric::array asNumArray(value);    numeric::array asNumArray(value);
171    initialise(asNumArray,what,expanded);    initialise(asNumArray,what,expanded);
172      // create entry in global profiling table for this object
173      profData = dataProfTable.newData();
174  }  }
175    
176  Data::Data(const object& value,  Data::Data(const object& value,
# Line 167  Data::Data(const object& value, Line 191  Data::Data(const object& value,
191      // Create a DataConstant with the same sample shape as other      // Create a DataConstant with the same sample shape as other
192      initialise(temp.getView(),other.getFunctionSpace(),false);      initialise(temp.getView(),other.getFunctionSpace(),false);
193    }    }
194      // create entry in global profiling table for this object
195      profData = dataProfTable.newData();
196  }  }
197    
198  escriptDataC  escriptDataC
# Line 353  Data::reshapeDataPoint(const DataArrayVi Line 379  Data::reshapeDataPoint(const DataArrayVi
379  Data  Data
380  Data::wherePositive() const  Data::wherePositive() const
381  {  {
382      profData->where++;
383    return escript::unaryOp(*this,bind2nd(greater<double>(),0.0));    return escript::unaryOp(*this,bind2nd(greater<double>(),0.0));
384  }  }
385    
386  Data  Data
387  Data::whereNegative() const  Data::whereNegative() const
388  {  {
389      profData->where++;
390    return escript::unaryOp(*this,bind2nd(less<double>(),0.0));    return escript::unaryOp(*this,bind2nd(less<double>(),0.0));
391  }  }
392    
393  Data  Data
394  Data::whereNonNegative() const  Data::whereNonNegative() const
395  {  {
396      profData->where++;
397    return escript::unaryOp(*this,bind2nd(greater_equal<double>(),0.0));    return escript::unaryOp(*this,bind2nd(greater_equal<double>(),0.0));
398  }  }
399    
400  Data  Data
401  Data::whereNonPositive() const  Data::whereNonPositive() const
402  {  {
403      profData->where++;
404    return escript::unaryOp(*this,bind2nd(less_equal<double>(),0.0));    return escript::unaryOp(*this,bind2nd(less_equal<double>(),0.0));
405  }  }
406    
407  Data  Data
408  Data::whereZero() const  Data::whereZero() const
409  {  {
410      profData->where++;
411    return escript::unaryOp(*this,bind2nd(equal_to<double>(),0.0));    return escript::unaryOp(*this,bind2nd(equal_to<double>(),0.0));
412  }  }
413    
414  Data  Data
415  Data::whereNonZero() const  Data::whereNonZero() const
416  {  {
417      profData->where++;
418    return escript::unaryOp(*this,bind2nd(not_equal_to<double>(),0.0));    return escript::unaryOp(*this,bind2nd(not_equal_to<double>(),0.0));
419  }  }
420    
421  Data  Data
422  Data::interpolate(const FunctionSpace& functionspace) const  Data::interpolate(const FunctionSpace& functionspace) const
423  {  {
424      profData->interpolate++;
425    return Data(*this,functionspace);    return Data(*this,functionspace);
426  }  }
427    
# Line 410  Data::probeInterpolation(const FunctionS Line 443  Data::probeInterpolation(const FunctionS
443  Data  Data
444  Data::gradOn(const FunctionSpace& functionspace) const  Data::gradOn(const FunctionSpace& functionspace) const
445  {  {
446      profData->grad++;
447    if (functionspace.getDomain()!=getDomain())    if (functionspace.getDomain()!=getDomain())
448      throw DataException("Error - gradient cannot be calculated on different domains.");      throw DataException("Error - gradient cannot be calculated on different domains.");
449    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();
# Line 443  Data::getDataPointShape() const Line 477  Data::getDataPointShape() const
477    return getPointDataView().getShape();    return getPointDataView().getShape();
478  }  }
479    
480    void
481    Data::fillFromNumArray(const boost::python::numeric::array num_array)
482    {
483      //
484      // check rank:
485      if (num_array.getrank()<getDataPointRank())
486          throw DataException("Rank of numarray does not match Data object rank");
487      //
488      // check rank of num_array
489      for (int i=0; i<getDataPointRank(); i++) {
490        if (extract<int>(num_array.getshape()[i+1])!=getDataPointShape()[i])
491           throw DataException("Shape of numarray does not match Data object rank");
492      }
493      //
494      // make sure data is expanded:
495      if (! isExpanded()) expand();
496      //
497      // and copy over:
498      m_data->copyAll(num_array);
499      //
500      // the rank of the returned numeric array will be the rank of
501      // the data points, plus one. Where the rank of the array is n,
502      // the last n-1 dimensions will be equal to the shape of the
503      // data points, whilst the first dimension will be equal to the
504      // total number of data points. Thus the array will consist of
505      // a serial vector of the data points.
506      // int arrayRank = dataPointRank + 1;
507      // DataArrayView::ShapeType arrayShape;
508      // arrayShape.push_back(numDataPoints);
509      // for (int d=0; d<dataPointRank; d++) {
510      //    arrayShape.push_back(dataPointShape[d]);
511      // }
512    
513      //
514      // resize the numeric array to the shape just calculated
515      // if (arrayRank==1) {
516      //   numArray.resize(arrayShape[0]);
517      // }
518      // if (arrayRank==2) {
519      //   numArray.resize(arrayShape[0],arrayShape[1]);
520      // }
521      // if (arrayRank==3) {
522      //   numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2]);
523      // }
524      // if (arrayRank==4) {
525      //   numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3]);
526      // }
527      // if (arrayRank==5) {
528      //   numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3],arrayShape[4]);
529      // }
530    
531      //
532      // loop through each data point in turn, loading the values for that data point
533      // into the numeric array.
534      // int dataPoint = 0;
535      // for (int sampleNo = 0; sampleNo < numSamples; sampleNo++) {
536      //   for (int dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
537      //     DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);
538      //     if (dataPointRank==0) {
539      //       dataPointView()=numArray[dataPoint];
540      //     }
541      //     if (dataPointRank==1) {
542      //       for (int i=0; i<dataPointShape[0]; i++) {
543      //         dataPointView(i)=numArray[dataPoint][i];
544      //       }
545      //     }
546      //     if (dataPointRank==2) {
547      //       for (int i=0; i<dataPointShape[0]; i++) {
548      //         for (int j=0; j<dataPointShape[1]; j++) {
549      //           numArray[dataPoint][i][j] = dataPointView(i,j);
550      //         }
551      //       }
552      //     }
553      //     if (dataPointRank==3) {
554      //       for (int i=0; i<dataPointShape[0]; i++) {
555      //         for (int j=0; j<dataPointShape[1]; j++) {
556      //           for (int k=0; k<dataPointShape[2]; k++) {
557      //             numArray[dataPoint][i][j][k]=dataPointView(i,j,k);
558      //           }
559      //         }
560      //       }
561      //     }
562      //     if (dataPointRank==4) {
563      //       for (int i=0; i<dataPointShape[0]; i++) {
564      //         for (int j=0; j<dataPointShape[1]; j++) {
565      //           for (int k=0; k<dataPointShape[2]; k++) {
566      //             for (int l=0; l<dataPointShape[3]; l++) {
567      //               numArray[dataPoint][i][j][k][l]=dataPointView(i,j,k,l);
568      //             }
569      //           }
570      //         }
571      //       }
572      //     }
573      //     dataPoint++;
574      //   }
575      // }
576    
577      //
578      // return the loaded array
579      // return numArray;
580    
581    }
582    
583  const  const
584  boost::python::numeric::array  boost::python::numeric::array
585  Data::convertToNumArray()  Data::convertToNumArray()
# Line 748  Data::integrate() const Line 885  Data::integrate() const
885    int rank = getDataPointRank();    int rank = getDataPointRank();
886    DataArrayView::ShapeType shape = getDataPointShape();    DataArrayView::ShapeType shape = getDataPointShape();
887    
888      profData->integrate++;
889    
890    //    //
891    // calculate the integral values    // calculate the integral values
892    vector<double> integrals(getDataPointSize());    vector<double> integrals(getDataPointSize());
# Line 811  Data::integrate() const Line 950  Data::integrate() const
950  Data  Data
951  Data::sin() const  Data::sin() const
952  {  {
953      profData->unary++;
954    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sin);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sin);
955  }  }
956    
957  Data  Data
958  Data::cos() const  Data::cos() const
959  {  {
960      profData->unary++;
961    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cos);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cos);
962  }  }
963    
964  Data  Data
965  Data::tan() const  Data::tan() const
966  {  {
967      profData->unary++;
968    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tan);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tan);
969  }  }
970    
971  Data  Data
972  Data::log() const  Data::log() const
973  {  {
974      profData->unary++;
975    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log10);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log10);
976  }  }
977    
978  Data  Data
979  Data::ln() const  Data::ln() const
980  {  {
981      profData->unary++;
982    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);
983  }  }
984    
985  Data  Data
986  Data::sign() const  Data::sign() const
987  {  {
988      profData->unary++;
989    return escript::unaryOp(*this,escript::fsign);    return escript::unaryOp(*this,escript::fsign);
990  }  }
991    
992  Data  Data
993  Data::abs() const  Data::abs() const
994  {  {
995      profData->unary++;
996    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);
997  }  }
998    
999  Data  Data
1000  Data::neg() const  Data::neg() const
1001  {  {
1002      profData->unary++;
1003    return escript::unaryOp(*this,negate<double>());    return escript::unaryOp(*this,negate<double>());
1004  }  }
1005    
1006  Data  Data
1007  Data::pos() const  Data::pos() const
1008  {  {
1009      profData->unary++;
1010    return (*this);    return (*this);
1011  }  }
1012    
1013  Data  Data
1014  Data::exp() const  Data::exp() const
1015  {  {
1016      profData->unary++;
1017    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);
1018  }  }
1019    
1020  Data  Data
1021  Data::sqrt() const  Data::sqrt() const
1022  {  {
1023      profData->unary++;
1024    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);
1025  }  }
1026    
1027  double  double
1028  Data::Lsup() const  Data::Lsup() const
1029  {  {
1030      profData->reduction1++;
1031    //    //
1032    // set the initial absolute maximum value to zero    // set the initial absolute maximum value to zero
1033    return algorithm(DataAlgorithmAdapter<AbsMax>(0));    return algorithm(DataAlgorithmAdapter<AbsMax>(0));
# Line 885  Data::Lsup() const Line 1036  Data::Lsup() const
1036  double  double
1037  Data::Linf() const  Data::Linf() const
1038  {  {
1039      profData->reduction1++;
1040    //    //
1041    // set the initial absolute minimum value to max double    // set the initial absolute minimum value to max double
1042    return algorithm(DataAlgorithmAdapter<AbsMin>(numeric_limits<double>::max()));    return algorithm(DataAlgorithmAdapter<AbsMin>(numeric_limits<double>::max()));
# Line 893  Data::Linf() const Line 1045  Data::Linf() const
1045  double  double
1046  Data::sup() const  Data::sup() const
1047  {  {
1048      profData->reduction1++;
1049    //    //
1050    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1051    return algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));    return algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));
# Line 901  Data::sup() const Line 1054  Data::sup() const
1054  double  double
1055  Data::inf() const  Data::inf() const
1056  {  {
1057      profData->reduction1++;
1058    //    //
1059    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1060    return algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));    return algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));
# Line 909  Data::inf() const Line 1063  Data::inf() const
1063  Data  Data
1064  Data::maxval() const  Data::maxval() const
1065  {  {
1066      profData->reduction2++;
1067    //    //
1068    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1069    return dp_algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));    return dp_algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));
# Line 917  Data::maxval() const Line 1072  Data::maxval() const
1072  Data  Data
1073  Data::minval() const  Data::minval() const
1074  {  {
1075      profData->reduction2++;
1076    //    //
1077    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1078    return dp_algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));    return dp_algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));
1079  }  }
1080    
1081    Data
1082    Data::length() const
1083    {
1084      profData->reduction2++;
1085      return dp_algorithm(DataAlgorithmAdapter<Length>(0));
1086    }
1087    
1088    Data
1089    Data::trace() const
1090    {
1091      profData->reduction2++;
1092      return dp_algorithm(DataAlgorithmAdapter<Trace>(0));
1093    }
1094    
1095    Data
1096    Data::transpose(int axis) const
1097    {
1098      profData->reduction2++;
1099      // not implemented
1100      throw DataException("Error - Data::transpose not implemented yet.");
1101      return Data();
1102    }
1103    
1104  const boost::python::tuple  const boost::python::tuple
1105  Data::mindp() const  Data::mindp() const
1106  {  {
# Line 947  Data::mindp() const Line 1126  Data::mindp() const
1126    return make_tuple(lowi,lowj);    return make_tuple(lowi,lowj);
1127  }  }
1128    
 Data  
 Data::length() const  
 {  
   return dp_algorithm(DataAlgorithmAdapter<Length>(0));  
 }  
   
 Data  
 Data::trace() const  
 {  
   return dp_algorithm(DataAlgorithmAdapter<Trace>(0));  
 }  
   
 Data  
 Data::transpose(int axis) const  
 {  
   // not implemented  
   throw DataException("Error - Data::transpose not implemented yet.");  
   return Data();  
 }  
   
1129  void  void
1130  Data::saveDX(std::string fileName) const  Data::saveDX(std::string fileName) const
1131  {  {
# Line 984  Data::saveVTK(std::string fileName) cons Line 1143  Data::saveVTK(std::string fileName) cons
1143  Data&  Data&
1144  Data::operator+=(const Data& right)  Data::operator+=(const Data& right)
1145  {  {
1146      profData->binary++;
1147    binaryOp(right,plus<double>());    binaryOp(right,plus<double>());
1148    return (*this);    return (*this);
1149  }  }
# Line 991  Data::operator+=(const Data& right) Line 1151  Data::operator+=(const Data& right)
1151  Data&  Data&
1152  Data::operator+=(const boost::python::object& right)  Data::operator+=(const boost::python::object& right)
1153  {  {
1154      profData->binary++;
1155    binaryOp(right,plus<double>());    binaryOp(right,plus<double>());
1156    return (*this);    return (*this);
1157  }  }
# Line 998  Data::operator+=(const boost::python::ob Line 1159  Data::operator+=(const boost::python::ob
1159  Data&  Data&
1160  Data::operator-=(const Data& right)  Data::operator-=(const Data& right)
1161  {  {
1162      profData->binary++;
1163    binaryOp(right,minus<double>());    binaryOp(right,minus<double>());
1164    return (*this);    return (*this);
1165  }  }
# Line 1005  Data::operator-=(const Data& right) Line 1167  Data::operator-=(const Data& right)
1167  Data&  Data&
1168  Data::operator-=(const boost::python::object& right)  Data::operator-=(const boost::python::object& right)
1169  {  {
1170      profData->binary++;
1171    binaryOp(right,minus<double>());    binaryOp(right,minus<double>());
1172    return (*this);    return (*this);
1173  }  }
# Line 1012  Data::operator-=(const boost::python::ob Line 1175  Data::operator-=(const boost::python::ob
1175  Data&  Data&
1176  Data::operator*=(const Data& right)  Data::operator*=(const Data& right)
1177  {  {
1178      profData->binary++;
1179    binaryOp(right,multiplies<double>());    binaryOp(right,multiplies<double>());
1180    return (*this);    return (*this);
1181  }  }
# Line 1019  Data::operator*=(const Data& right) Line 1183  Data::operator*=(const Data& right)
1183  Data&  Data&
1184  Data::operator*=(const boost::python::object& right)  Data::operator*=(const boost::python::object& right)
1185  {  {
1186      profData->binary++;
1187    binaryOp(right,multiplies<double>());    binaryOp(right,multiplies<double>());
1188    return (*this);    return (*this);
1189  }  }
# Line 1026  Data::operator*=(const boost::python::ob Line 1191  Data::operator*=(const boost::python::ob
1191  Data&  Data&
1192  Data::operator/=(const Data& right)  Data::operator/=(const Data& right)
1193  {  {
1194      profData->binary++;
1195    binaryOp(right,divides<double>());    binaryOp(right,divides<double>());
1196    return (*this);    return (*this);
1197  }  }
# Line 1033  Data::operator/=(const Data& right) Line 1199  Data::operator/=(const Data& right)
1199  Data&  Data&
1200  Data::operator/=(const boost::python::object& right)  Data::operator/=(const boost::python::object& right)
1201  {  {
1202      profData->binary++;
1203    binaryOp(right,divides<double>());    binaryOp(right,divides<double>());
1204    return (*this);    return (*this);
1205  }  }
# Line 1040  Data::operator/=(const boost::python::ob Line 1207  Data::operator/=(const boost::python::ob
1207  Data  Data
1208  Data::powO(const boost::python::object& right) const  Data::powO(const boost::python::object& right) const
1209  {  {
1210      profData->binary++;
1211    Data result;    Data result;
1212    result.copy(*this);    result.copy(*this);
1213    result.binaryOp(right,(Data::BinaryDFunPtr)::pow);    result.binaryOp(right,(Data::BinaryDFunPtr)::pow);
# Line 1049  Data::powO(const boost::python::object& Line 1217  Data::powO(const boost::python::object&
1217  Data  Data
1218  Data::powD(const Data& right) const  Data::powD(const Data& right) const
1219  {  {
1220      profData->binary++;
1221    Data result;    Data result;
1222    result.copy(*this);    result.copy(*this);
1223    result.binaryOp(right,(Data::BinaryDFunPtr)::pow);    result.binaryOp(right,(Data::BinaryDFunPtr)::pow);
# Line 1056  Data::powD(const Data& right) const Line 1225  Data::powD(const Data& right) const
1225  }  }
1226    
1227  //  //
1228  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1229  Data  Data
1230  escript::operator+(const Data& left, const Data& right)  escript::operator+(const Data& left, const Data& right)
1231  {  {
# Line 1069  escript::operator+(const Data& left, con Line 1238  escript::operator+(const Data& left, con
1238  }  }
1239    
1240  //  //
1241  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1242  Data  Data
1243  escript::operator-(const Data& left, const Data& right)  escript::operator-(const Data& left, const Data& right)
1244  {  {
# Line 1082  escript::operator-(const Data& left, con Line 1251  escript::operator-(const Data& left, con
1251  }  }
1252    
1253  //  //
1254  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1255  Data  Data
1256  escript::operator*(const Data& left, const Data& right)  escript::operator*(const Data& left, const Data& right)
1257  {  {
# Line 1095  escript::operator*(const Data& left, con Line 1264  escript::operator*(const Data& left, con
1264  }  }
1265    
1266  //  //
1267  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1268  Data  Data
1269  escript::operator/(const Data& left, const Data& right)  escript::operator/(const Data& left, const Data& right)
1270  {  {
# Line 1108  escript::operator/(const Data& left, con Line 1277  escript::operator/(const Data& left, con
1277  }  }
1278    
1279  //  //
1280  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1281  Data  Data
1282  escript::operator+(const Data& left, const boost::python::object& right)  escript::operator+(const Data& left, const boost::python::object& right)
1283  {  {
# Line 1124  escript::operator+(const Data& left, con Line 1293  escript::operator+(const Data& left, con
1293  }  }
1294    
1295  //  //
1296  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1297  Data  Data
1298  escript::operator-(const Data& left, const boost::python::object& right)  escript::operator-(const Data& left, const boost::python::object& right)
1299  {  {
# Line 1140  escript::operator-(const Data& left, con Line 1309  escript::operator-(const Data& left, con
1309  }  }
1310    
1311  //  //
1312  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1313  Data  Data
1314  escript::operator*(const Data& left, const boost::python::object& right)  escript::operator*(const Data& left, const boost::python::object& right)
1315  {  {
# Line 1156  escript::operator*(const Data& left, con Line 1325  escript::operator*(const Data& left, con
1325  }  }
1326    
1327  //  //
1328  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1329  Data  Data
1330  escript::operator/(const Data& left, const boost::python::object& right)  escript::operator/(const Data& left, const boost::python::object& right)
1331  {  {
# Line 1172  escript::operator/(const Data& left, con Line 1341  escript::operator/(const Data& left, con
1341  }  }
1342    
1343  //  //
1344  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1345  Data  Data
1346  escript::operator+(const boost::python::object& left, const Data& right)  escript::operator+(const boost::python::object& left, const Data& right)
1347  {  {
# Line 1185  escript::operator+(const boost::python:: Line 1354  escript::operator+(const boost::python::
1354  }  }
1355    
1356  //  //
1357  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1358  Data  Data
1359  escript::operator-(const boost::python::object& left, const Data& right)  escript::operator-(const boost::python::object& left, const Data& right)
1360  {  {
# Line 1198  escript::operator-(const boost::python:: Line 1367  escript::operator-(const boost::python::
1367  }  }
1368    
1369  //  //
1370  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1371  Data  Data
1372  escript::operator*(const boost::python::object& left, const Data& right)  escript::operator*(const boost::python::object& left, const Data& right)
1373  {  {
# Line 1211  escript::operator*(const boost::python:: Line 1380  escript::operator*(const boost::python::
1380  }  }
1381    
1382  //  //
1383  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1384  Data  Data
1385  escript::operator/(const boost::python::object& left, const Data& right)  escript::operator/(const boost::python::object& left, const Data& right)
1386  {  {
# Line 1224  escript::operator/(const boost::python:: Line 1393  escript::operator/(const boost::python::
1393  }  }
1394    
1395  //  //
 // NOTE: It is essential to specify the namepsace this operator belongs to  
1396  //bool escript::operator==(const Data& left, const Data& right)  //bool escript::operator==(const Data& left, const Data& right)
1397  //{  //{
1398  //  /*  //  /*
# Line 1286  Data::getItem(const boost::python::objec Line 1454  Data::getItem(const boost::python::objec
1454  Data  Data
1455  Data::getSlice(const DataArrayView::RegionType& region) const  Data::getSlice(const DataArrayView::RegionType& region) const
1456  {  {
1457      profData->slicing++;
1458    return Data(*this,region);    return Data(*this,region);
1459  }  }
1460    
# Line 1302  Data::setItemD(const boost::python::obje Line 1471  Data::setItemD(const boost::python::obje
1471                 const Data& value)                 const Data& value)
1472  {  {
1473    const DataArrayView& view=getPointDataView();    const DataArrayView& view=getPointDataView();
1474    
1475    DataArrayView::RegionType slice_region=view.getSliceRegion(key);    DataArrayView::RegionType slice_region=view.getSliceRegion(key);
1476    if (slice_region.size()!=view.getRank()) {    if (slice_region.size()!=view.getRank()) {
1477      throw DataException("Error - slice size does not match Data rank.");      throw DataException("Error - slice size does not match Data rank.");
# Line 1317  void Line 1487  void
1487  Data::setSlice(const Data& value,  Data::setSlice(const Data& value,
1488                 const DataArrayView::RegionType& region)                 const DataArrayView::RegionType& region)
1489  {  {
1490      profData->slicing++;
1491    Data tempValue(value);    Data tempValue(value);
1492    typeMatchLeft(tempValue);    typeMatchLeft(tempValue);
1493    typeMatchRight(tempValue);    typeMatchRight(tempValue);
# Line 1428  Data::getRefValue(int ref, Line 1599  Data::getRefValue(int ref,
1599    DataArrayView valueView = valueDataArray.getView();    DataArrayView valueView = valueDataArray.getView();
1600    
1601    if (rank==0) {    if (rank==0) {
1602      throw DataException("Data::getRefValue error: only rank 1 data handled for now.");        boost::python::numeric::array temp_numArray(valueView());
1603          value = temp_numArray;
1604    }    }
1605    if (rank==1) {    if (rank==1) {
1606      for (int i=0; i < shape[0]; i++) {      for (int i=0; i < shape[0]; i++) {
# Line 1436  Data::getRefValue(int ref, Line 1608  Data::getRefValue(int ref,
1608      }      }
1609    }    }
1610    if (rank==2) {    if (rank==2) {
1611      throw DataException("Data::getRefValue error: only rank 1 data handled for now.");      for (int i=0; i < shape[0]; i++) {
1612          for (int j=0; j < shape[1]; j++) {
1613            value[i][j] = valueView(i,j);
1614          }
1615        }
1616    }    }
1617    if (rank==3) {    if (rank==3) {
1618      throw DataException("Data::getRefValue error: only rank 1 data handled for now.");      for (int i=0; i < shape[0]; i++) {
1619          for (int j=0; j < shape[1]; j++) {
1620            for (int k=0; k < shape[2]; k++) {
1621              value[i][j][k] = valueView(i,j,k);
1622            }
1623          }
1624        }
1625    }    }
1626    if (rank==4) {    if (rank==4) {
1627      throw DataException("Data::getRefValue error: only rank 1 data handled for now.");      for (int i=0; i < shape[0]; i++) {
1628          for (int j=0; j < shape[1]; j++) {
1629            for (int k=0; k < shape[2]; k++) {
1630              for (int l=0; l < shape[3]; l++) {
1631                value[i][j][k][l] = valueView(i,j,k,l);
1632              }
1633            }
1634          }
1635        }
1636    }    }
1637    
1638  }  }
# Line 1472  Data::archiveData(const std::string file Line 1662  Data::archiveData(const std::string file
1662      dataType = 3;      dataType = 3;
1663      cout << "\tdataType: DataExpanded" << endl;      cout << "\tdataType: DataExpanded" << endl;
1664    }    }
1665    
1666    if (dataType == -1) {    if (dataType == -1) {
1667      throw DataException("archiveData Error: undefined dataType");      throw DataException("archiveData Error: undefined dataType");
1668    }    }
# Line 1511  Data::archiveData(const std::string file Line 1702  Data::archiveData(const std::string file
1702    cout << ">" << endl;    cout << ">" << endl;
1703    
1704    //    //
1705    // Write common data items to archive file    // Open archive file
1706    ofstream archiveFile;    ofstream archiveFile;
1707    archiveFile.open(fileName.data(), ios::out);    archiveFile.open(fileName.data(), ios::out);
1708    
# Line 1519  Data::archiveData(const std::string file Line 1710  Data::archiveData(const std::string file
1710      throw DataException("archiveData Error: problem opening archive file");      throw DataException("archiveData Error: problem opening archive file");
1711    }    }
1712    
1713      //
1714      // Write common data items to archive file
1715    archiveFile.write(reinterpret_cast<char *>(&dataType),sizeof(int));    archiveFile.write(reinterpret_cast<char *>(&dataType),sizeof(int));
1716    archiveFile.write(reinterpret_cast<char *>(&noSamples),sizeof(int));    archiveFile.write(reinterpret_cast<char *>(&noSamples),sizeof(int));
1717    archiveFile.write(reinterpret_cast<char *>(&noDPPSample),sizeof(int));    archiveFile.write(reinterpret_cast<char *>(&noDPPSample),sizeof(int));
# Line 1542  Data::archiveData(const std::string file Line 1735  Data::archiveData(const std::string file
1735      throw DataException("archiveData Error: problem writing to archive file");      throw DataException("archiveData Error: problem writing to archive file");
1736    }    }
1737    
   archiveFile.close();  
   
   if (!archiveFile.good()) {  
     throw DataException("archiveData Error: problem closing archive file");  
   }  
   
1738    //    //
1739    // Collect and archive underlying data values for each Data type    // Archive underlying data values for each Data type
1740      int noValues;
1741    switch (dataType) {    switch (dataType) {
1742      case 0:      case 0:
1743        // DataEmpty        // DataEmpty
1744          noValues = 0;
1745          archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));
1746          cout << "\tnoValues: " << noValues << endl;
1747        break;        break;
1748      case 1:      case 1:
1749        // DataConstant        // DataConstant
1750          noValues = m_data->getLength();
1751          archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));
1752          cout << "\tnoValues: " << noValues << endl;
1753          if (m_data->archiveData(archiveFile,noValues)) {
1754            throw DataException("archiveData Error: problem writing data to archive file");
1755          }
1756        break;        break;
1757      case 2:      case 2:
1758        // DataTagged        // DataTagged
1759          noValues = m_data->getLength();
1760          archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));
1761          cout << "\tnoValues: " << noValues << endl;
1762          if (m_data->archiveData(archiveFile,noValues)) {
1763            throw DataException("archiveData Error: problem writing data to archive file");
1764          }
1765        break;        break;
1766      case 3:      case 3:
1767        // DataExpanded        // DataExpanded
1768          noValues = m_data->getLength();
1769          archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));
1770          cout << "\tnoValues: " << noValues << endl;
1771          if (m_data->archiveData(archiveFile,noValues)) {
1772            throw DataException("archiveData Error: problem writing data to archive file");
1773          }
1774        break;        break;
1775    }    }
1776    
1777      if (!archiveFile.good()) {
1778        throw DataException("archiveData Error: problem writing data to archive file");
1779      }
1780    
1781      //
1782      // Close archive file
1783      archiveFile.close();
1784    
1785      if (!archiveFile.good()) {
1786        throw DataException("archiveData Error: problem closing archive file");
1787      }
1788    
1789  }  }
1790    
1791  void  void
# Line 1590  Data::extractData(const std::string file Line 1811  Data::extractData(const std::string file
1811    int flatShape[4];    int flatShape[4];
1812    
1813    //    //
1814    // Open the archive file and read common data items    // Open the archive file
1815    ifstream archiveFile;    ifstream archiveFile;
1816    archiveFile.open(fileName.data(), ios::in);    archiveFile.open(fileName.data(), ios::in);
1817    
# Line 1598  Data::extractData(const std::string file Line 1819  Data::extractData(const std::string file
1819      throw DataException("extractData Error: problem opening archive file");      throw DataException("extractData Error: problem opening archive file");
1820    }    }
1821    
1822      //
1823      // Read common data items from archive file
1824    archiveFile.read(reinterpret_cast<char *>(&dataType),sizeof(int));    archiveFile.read(reinterpret_cast<char *>(&dataType),sizeof(int));
1825    archiveFile.read(reinterpret_cast<char *>(&noSamples),sizeof(int));    archiveFile.read(reinterpret_cast<char *>(&noSamples),sizeof(int));
1826    archiveFile.read(reinterpret_cast<char *>(&noDPPSample),sizeof(int));    archiveFile.read(reinterpret_cast<char *>(&noDPPSample),sizeof(int));
# Line 1626  Data::extractData(const std::string file Line 1849  Data::extractData(const std::string file
1849      throw DataException("extractData Error: problem reading from archive file");      throw DataException("extractData Error: problem reading from archive file");
1850    }    }
1851    
1852    archiveFile.close();    //
1853      // Verify the values just read from the archive file
   if (!archiveFile.good()) {  
     throw DataException("extractData Error: problem closing archive file");  
   }  
   
1854    switch (dataType) {    switch (dataType) {
1855      case 0:      case 0:
1856        cout << "\tdataType: DataEmpty" << endl;        cout << "\tdataType: DataEmpty" << endl;
# Line 1686  Data::extractData(const std::string file Line 1905  Data::extractData(const std::string file
1905    
1906    //    //
1907    // Load this DataVector with the appropriate values    // Load this DataVector with the appropriate values
1908      int noValues;
1909      archiveFile.read(reinterpret_cast<char *>(&noValues),sizeof(int));
1910      cout << "\tnoValues: " << noValues << endl;
1911    switch (dataType) {    switch (dataType) {
1912      case 0:      case 0:
1913        // DataEmpty        // DataEmpty
1914          if (noValues != 0) {
1915            throw DataException("extractData Error: problem reading data from archive file");
1916          }
1917        break;        break;
1918      case 1:      case 1:
1919        // DataConstant        // DataConstant
1920          if (dataVec.extractData(archiveFile,noValues)) {
1921            throw DataException("extractData Error: problem reading data from archive file");
1922          }
1923        break;        break;
1924      case 2:      case 2:
1925        // DataTagged        // DataTagged
1926          if (dataVec.extractData(archiveFile,noValues)) {
1927            throw DataException("extractData Error: problem reading data from archive file");
1928          }
1929        break;        break;
1930      case 3:      case 3:
1931        // DataExpanded        // DataExpanded
1932          if (dataVec.extractData(archiveFile,noValues)) {
1933            throw DataException("extractData Error: problem reading data from archive file");
1934          }
1935        break;        break;
1936    }    }
1937    
1938      if (!archiveFile.good()) {
1939        throw DataException("extractData Error: problem reading from archive file");
1940      }
1941    
1942      //
1943      // Close archive file
1944      archiveFile.close();
1945    
1946      if (!archiveFile.good()) {
1947        throw DataException("extractData Error: problem closing archive file");
1948      }
1949    
1950    //    //
1951    // Construct an appropriate Data object    // Construct an appropriate Data object
1952    DataAbstract* tempData;    DataAbstract* tempData;
# Line 1724  Data::extractData(const std::string file Line 1970  Data::extractData(const std::string file
1970    }    }
1971    shared_ptr<DataAbstract> temp_data(tempData);    shared_ptr<DataAbstract> temp_data(tempData);
1972    m_data=temp_data;    m_data=temp_data;
   
1973  }  }
1974    
1975  ostream& escript::operator<<(ostream& o, const Data& data)  ostream& escript::operator<<(ostream& o, const Data& data)

Legend:
Removed from v.121  
changed lines
  Added in v.126

  ViewVC Help
Powered by ViewVC 1.1.26