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

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

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

revision 122 by jgs, Thu Jun 9 05:38:05 2005 UTC revision 123 by jgs, Fri Jul 8 04:08:13 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/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 44  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 51  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 64  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 74  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 89  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 98  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 110  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 124  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 131  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 138  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 146  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 166  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 352  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 409  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 747  Data::integrate() const Line 782  Data::integrate() const
782    int rank = getDataPointRank();    int rank = getDataPointRank();
783    DataArrayView::ShapeType shape = getDataPointShape();    DataArrayView::ShapeType shape = getDataPointShape();
784    
785      profData->integrate++;
786    
787    //    //
788    // calculate the integral values    // calculate the integral values
789    vector<double> integrals(getDataPointSize());    vector<double> integrals(getDataPointSize());
# Line 810  Data::integrate() const Line 847  Data::integrate() const
847  Data  Data
848  Data::sin() const  Data::sin() const
849  {  {
850      profData->unary++;
851    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sin);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sin);
852  }  }
853    
854  Data  Data
855  Data::cos() const  Data::cos() const
856  {  {
857      profData->unary++;
858    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cos);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cos);
859  }  }
860    
861  Data  Data
862  Data::tan() const  Data::tan() const
863  {  {
864      profData->unary++;
865    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tan);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tan);
866  }  }
867    
868  Data  Data
869  Data::log() const  Data::log() const
870  {  {
871      profData->unary++;
872    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log10);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log10);
873  }  }
874    
875  Data  Data
876  Data::ln() const  Data::ln() const
877  {  {
878      profData->unary++;
879    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);
880  }  }
881    
882  Data  Data
883  Data::sign() const  Data::sign() const
884  {  {
885      profData->unary++;
886    return escript::unaryOp(*this,escript::fsign);    return escript::unaryOp(*this,escript::fsign);
887  }  }
888    
889  Data  Data
890  Data::abs() const  Data::abs() const
891  {  {
892      profData->unary++;
893    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);
894  }  }
895    
896  Data  Data
897  Data::neg() const  Data::neg() const
898  {  {
899      profData->unary++;
900    return escript::unaryOp(*this,negate<double>());    return escript::unaryOp(*this,negate<double>());
901  }  }
902    
903  Data  Data
904  Data::pos() const  Data::pos() const
905  {  {
906      profData->unary++;
907    return (*this);    return (*this);
908  }  }
909    
910  Data  Data
911  Data::exp() const  Data::exp() const
912  {  {
913      profData->unary++;
914    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);
915  }  }
916    
917  Data  Data
918  Data::sqrt() const  Data::sqrt() const
919  {  {
920      profData->unary++;
921    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);
922  }  }
923    
924  double  double
925  Data::Lsup() const  Data::Lsup() const
926  {  {
927      profData->reduction1++;
928    //    //
929    // set the initial absolute maximum value to zero    // set the initial absolute maximum value to zero
930    return algorithm(DataAlgorithmAdapter<AbsMax>(0));    return algorithm(DataAlgorithmAdapter<AbsMax>(0));
# Line 884  Data::Lsup() const Line 933  Data::Lsup() const
933  double  double
934  Data::Linf() const  Data::Linf() const
935  {  {
936      profData->reduction1++;
937    //    //
938    // set the initial absolute minimum value to max double    // set the initial absolute minimum value to max double
939    return algorithm(DataAlgorithmAdapter<AbsMin>(numeric_limits<double>::max()));    return algorithm(DataAlgorithmAdapter<AbsMin>(numeric_limits<double>::max()));
# Line 892  Data::Linf() const Line 942  Data::Linf() const
942  double  double
943  Data::sup() const  Data::sup() const
944  {  {
945      profData->reduction1++;
946    //    //
947    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
948    return algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));    return algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));
# Line 900  Data::sup() const Line 951  Data::sup() const
951  double  double
952  Data::inf() const  Data::inf() const
953  {  {
954      profData->reduction1++;
955    //    //
956    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
957    return algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));    return algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));
# Line 908  Data::inf() const Line 960  Data::inf() const
960  Data  Data
961  Data::maxval() const  Data::maxval() const
962  {  {
963      profData->reduction2++;
964    //    //
965    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
966    return dp_algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));    return dp_algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));
# Line 916  Data::maxval() const Line 969  Data::maxval() const
969  Data  Data
970  Data::minval() const  Data::minval() const
971  {  {
972      profData->reduction2++;
973    //    //
974    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
975    return dp_algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));    return dp_algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));
976  }  }
977    
978    Data
979    Data::length() const
980    {
981      profData->reduction2++;
982      return dp_algorithm(DataAlgorithmAdapter<Length>(0));
983    }
984    
985    Data
986    Data::trace() const
987    {
988      profData->reduction2++;
989      return dp_algorithm(DataAlgorithmAdapter<Trace>(0));
990    }
991    
992    Data
993    Data::transpose(int axis) const
994    {
995      profData->reduction2++;
996      // not implemented
997      throw DataException("Error - Data::transpose not implemented yet.");
998      return Data();
999    }
1000    
1001  const boost::python::tuple  const boost::python::tuple
1002  Data::mindp() const  Data::mindp() const
1003  {  {
# Line 946  Data::mindp() const Line 1023  Data::mindp() const
1023    return make_tuple(lowi,lowj);    return make_tuple(lowi,lowj);
1024  }  }
1025    
 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();  
 }  
   
1026  void  void
1027  Data::saveDX(std::string fileName) const  Data::saveDX(std::string fileName) const
1028  {  {
# Line 983  Data::saveVTK(std::string fileName) cons Line 1040  Data::saveVTK(std::string fileName) cons
1040  Data&  Data&
1041  Data::operator+=(const Data& right)  Data::operator+=(const Data& right)
1042  {  {
1043      profData->binary++;
1044    binaryOp(right,plus<double>());    binaryOp(right,plus<double>());
1045    return (*this);    return (*this);
1046  }  }
# Line 990  Data::operator+=(const Data& right) Line 1048  Data::operator+=(const Data& right)
1048  Data&  Data&
1049  Data::operator+=(const boost::python::object& right)  Data::operator+=(const boost::python::object& right)
1050  {  {
1051      profData->binary++;
1052    binaryOp(right,plus<double>());    binaryOp(right,plus<double>());
1053    return (*this);    return (*this);
1054  }  }
# Line 997  Data::operator+=(const boost::python::ob Line 1056  Data::operator+=(const boost::python::ob
1056  Data&  Data&
1057  Data::operator-=(const Data& right)  Data::operator-=(const Data& right)
1058  {  {
1059      profData->binary++;
1060    binaryOp(right,minus<double>());    binaryOp(right,minus<double>());
1061    return (*this);    return (*this);
1062  }  }
# Line 1004  Data::operator-=(const Data& right) Line 1064  Data::operator-=(const Data& right)
1064  Data&  Data&
1065  Data::operator-=(const boost::python::object& right)  Data::operator-=(const boost::python::object& right)
1066  {  {
1067      profData->binary++;
1068    binaryOp(right,minus<double>());    binaryOp(right,minus<double>());
1069    return (*this);    return (*this);
1070  }  }
# Line 1011  Data::operator-=(const boost::python::ob Line 1072  Data::operator-=(const boost::python::ob
1072  Data&  Data&
1073  Data::operator*=(const Data& right)  Data::operator*=(const Data& right)
1074  {  {
1075      profData->binary++;
1076    binaryOp(right,multiplies<double>());    binaryOp(right,multiplies<double>());
1077    return (*this);    return (*this);
1078  }  }
# Line 1018  Data::operator*=(const Data& right) Line 1080  Data::operator*=(const Data& right)
1080  Data&  Data&
1081  Data::operator*=(const boost::python::object& right)  Data::operator*=(const boost::python::object& right)
1082  {  {
1083      profData->binary++;
1084    binaryOp(right,multiplies<double>());    binaryOp(right,multiplies<double>());
1085    return (*this);    return (*this);
1086  }  }
# Line 1025  Data::operator*=(const boost::python::ob Line 1088  Data::operator*=(const boost::python::ob
1088  Data&  Data&
1089  Data::operator/=(const Data& right)  Data::operator/=(const Data& right)
1090  {  {
1091      profData->binary++;
1092    binaryOp(right,divides<double>());    binaryOp(right,divides<double>());
1093    return (*this);    return (*this);
1094  }  }
# Line 1032  Data::operator/=(const Data& right) Line 1096  Data::operator/=(const Data& right)
1096  Data&  Data&
1097  Data::operator/=(const boost::python::object& right)  Data::operator/=(const boost::python::object& right)
1098  {  {
1099      profData->binary++;
1100    binaryOp(right,divides<double>());    binaryOp(right,divides<double>());
1101    return (*this);    return (*this);
1102  }  }
# Line 1039  Data::operator/=(const boost::python::ob Line 1104  Data::operator/=(const boost::python::ob
1104  Data  Data
1105  Data::powO(const boost::python::object& right) const  Data::powO(const boost::python::object& right) const
1106  {  {
1107      profData->binary++;
1108    Data result;    Data result;
1109    result.copy(*this);    result.copy(*this);
1110    result.binaryOp(right,(Data::BinaryDFunPtr)::pow);    result.binaryOp(right,(Data::BinaryDFunPtr)::pow);
# Line 1048  Data::powO(const boost::python::object& Line 1114  Data::powO(const boost::python::object&
1114  Data  Data
1115  Data::powD(const Data& right) const  Data::powD(const Data& right) const
1116  {  {
1117      profData->binary++;
1118    Data result;    Data result;
1119    result.copy(*this);    result.copy(*this);
1120    result.binaryOp(right,(Data::BinaryDFunPtr)::pow);    result.binaryOp(right,(Data::BinaryDFunPtr)::pow);
# Line 1055  Data::powD(const Data& right) const Line 1122  Data::powD(const Data& right) const
1122  }  }
1123    
1124  //  //
1125  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1126  Data  Data
1127  escript::operator+(const Data& left, const Data& right)  escript::operator+(const Data& left, const Data& right)
1128  {  {
# Line 1068  escript::operator+(const Data& left, con Line 1135  escript::operator+(const Data& left, con
1135  }  }
1136    
1137  //  //
1138  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1139  Data  Data
1140  escript::operator-(const Data& left, const Data& right)  escript::operator-(const Data& left, const Data& right)
1141  {  {
# Line 1081  escript::operator-(const Data& left, con Line 1148  escript::operator-(const Data& left, con
1148  }  }
1149    
1150  //  //
1151  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1152  Data  Data
1153  escript::operator*(const Data& left, const Data& right)  escript::operator*(const Data& left, const Data& right)
1154  {  {
# Line 1094  escript::operator*(const Data& left, con Line 1161  escript::operator*(const Data& left, con
1161  }  }
1162    
1163  //  //
1164  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1165  Data  Data
1166  escript::operator/(const Data& left, const Data& right)  escript::operator/(const Data& left, const Data& right)
1167  {  {
# Line 1107  escript::operator/(const Data& left, con Line 1174  escript::operator/(const Data& left, con
1174  }  }
1175    
1176  //  //
1177  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1178  Data  Data
1179  escript::operator+(const Data& left, const boost::python::object& right)  escript::operator+(const Data& left, const boost::python::object& right)
1180  {  {
# Line 1123  escript::operator+(const Data& left, con Line 1190  escript::operator+(const Data& left, con
1190  }  }
1191    
1192  //  //
1193  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1194  Data  Data
1195  escript::operator-(const Data& left, const boost::python::object& right)  escript::operator-(const Data& left, const boost::python::object& right)
1196  {  {
# Line 1139  escript::operator-(const Data& left, con Line 1206  escript::operator-(const Data& left, con
1206  }  }
1207    
1208  //  //
1209  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1210  Data  Data
1211  escript::operator*(const Data& left, const boost::python::object& right)  escript::operator*(const Data& left, const boost::python::object& right)
1212  {  {
# Line 1155  escript::operator*(const Data& left, con Line 1222  escript::operator*(const Data& left, con
1222  }  }
1223    
1224  //  //
1225  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1226  Data  Data
1227  escript::operator/(const Data& left, const boost::python::object& right)  escript::operator/(const Data& left, const boost::python::object& right)
1228  {  {
# Line 1171  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 boost::python::object& left, const Data& right)  escript::operator+(const boost::python::object& left, const Data& right)
1244  {  {
# Line 1184  escript::operator+(const boost::python:: Line 1251  escript::operator+(const boost::python::
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 boost::python::object& left, const Data& right)  escript::operator-(const boost::python::object& left, const Data& right)
1257  {  {
# Line 1197  escript::operator-(const boost::python:: Line 1264  escript::operator-(const boost::python::
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 boost::python::object& left, const Data& right)  escript::operator*(const boost::python::object& left, const Data& right)
1270  {  {
# Line 1210  escript::operator*(const boost::python:: Line 1277  escript::operator*(const boost::python::
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 boost::python::object& left, const Data& right)  escript::operator/(const boost::python::object& left, const Data& right)
1283  {  {
# Line 1223  escript::operator/(const boost::python:: Line 1290  escript::operator/(const boost::python::
1290  }  }
1291    
1292  //  //
 // NOTE: It is essential to specify the namepsace this operator belongs to  
1293  //bool escript::operator==(const Data& left, const Data& right)  //bool escript::operator==(const Data& left, const Data& right)
1294  //{  //{
1295  //  /*  //  /*
# Line 1285  Data::getItem(const boost::python::objec Line 1351  Data::getItem(const boost::python::objec
1351  Data  Data
1352  Data::getSlice(const DataArrayView::RegionType& region) const  Data::getSlice(const DataArrayView::RegionType& region) const
1353  {  {
1354      profData->slicing++;
1355    return Data(*this,region);    return Data(*this,region);
1356  }  }
1357    
# Line 1301  Data::setItemD(const boost::python::obje Line 1368  Data::setItemD(const boost::python::obje
1368                 const Data& value)                 const Data& value)
1369  {  {
1370    const DataArrayView& view=getPointDataView();    const DataArrayView& view=getPointDataView();
1371    
1372    DataArrayView::RegionType slice_region=view.getSliceRegion(key);    DataArrayView::RegionType slice_region=view.getSliceRegion(key);
1373    if (slice_region.size()!=view.getRank()) {    if (slice_region.size()!=view.getRank()) {
1374      throw DataException("Error - slice size does not match Data rank.");      throw DataException("Error - slice size does not match Data rank.");
# Line 1316  void Line 1384  void
1384  Data::setSlice(const Data& value,  Data::setSlice(const Data& value,
1385                 const DataArrayView::RegionType& region)                 const DataArrayView::RegionType& region)
1386  {  {
1387      profData->slicing++;
1388    Data tempValue(value);    Data tempValue(value);
1389    typeMatchLeft(tempValue);    typeMatchLeft(tempValue);
1390    typeMatchRight(tempValue);    typeMatchRight(tempValue);
# Line 1471  Data::archiveData(const std::string file Line 1540  Data::archiveData(const std::string file
1540      dataType = 3;      dataType = 3;
1541      cout << "\tdataType: DataExpanded" << endl;      cout << "\tdataType: DataExpanded" << endl;
1542    }    }
1543    
1544    if (dataType == -1) {    if (dataType == -1) {
1545      throw DataException("archiveData Error: undefined dataType");      throw DataException("archiveData Error: undefined dataType");
1546    }    }
# Line 1510  Data::archiveData(const std::string file Line 1580  Data::archiveData(const std::string file
1580    cout << ">" << endl;    cout << ">" << endl;
1581    
1582    //    //
1583    // Write common data items to archive file    // Open archive file
1584    ofstream archiveFile;    ofstream archiveFile;
1585    archiveFile.open(fileName.data(), ios::out);    archiveFile.open(fileName.data(), ios::out);
1586    
# Line 1518  Data::archiveData(const std::string file Line 1588  Data::archiveData(const std::string file
1588      throw DataException("archiveData Error: problem opening archive file");      throw DataException("archiveData Error: problem opening archive file");
1589    }    }
1590    
1591      //
1592      // Write common data items to archive file
1593    archiveFile.write(reinterpret_cast<char *>(&dataType),sizeof(int));    archiveFile.write(reinterpret_cast<char *>(&dataType),sizeof(int));
1594    archiveFile.write(reinterpret_cast<char *>(&noSamples),sizeof(int));    archiveFile.write(reinterpret_cast<char *>(&noSamples),sizeof(int));
1595    archiveFile.write(reinterpret_cast<char *>(&noDPPSample),sizeof(int));    archiveFile.write(reinterpret_cast<char *>(&noDPPSample),sizeof(int));
# Line 1541  Data::archiveData(const std::string file Line 1613  Data::archiveData(const std::string file
1613      throw DataException("archiveData Error: problem writing to archive file");      throw DataException("archiveData Error: problem writing to archive file");
1614    }    }
1615    
   archiveFile.close();  
   
   if (!archiveFile.good()) {  
     throw DataException("archiveData Error: problem closing archive file");  
   }  
   
1616    //    //
1617    // Collect and archive underlying data values for each Data type    // Archive underlying data values for each Data type
1618      int noValues;
1619    switch (dataType) {    switch (dataType) {
1620      case 0:      case 0:
1621        // DataEmpty        // DataEmpty
1622          noValues = 0;
1623          archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));
1624          cout << "\tnoValues: " << noValues << endl;
1625        break;        break;
1626      case 1:      case 1:
1627        // DataConstant        // DataConstant
1628          noValues = m_data->getLength();
1629          archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));
1630          cout << "\tnoValues: " << noValues << endl;
1631          if (m_data->archiveData(archiveFile,noValues)) {
1632            throw DataException("archiveData Error: problem writing data to archive file");
1633          }
1634        break;        break;
1635      case 2:      case 2:
1636        // DataTagged        // DataTagged
1637          noValues = m_data->getLength();
1638          archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));
1639          cout << "\tnoValues: " << noValues << endl;
1640          if (m_data->archiveData(archiveFile,noValues)) {
1641            throw DataException("archiveData Error: problem writing data to archive file");
1642          }
1643        break;        break;
1644      case 3:      case 3:
1645        // DataExpanded        // DataExpanded
1646          noValues = m_data->getLength();
1647          archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));
1648          cout << "\tnoValues: " << noValues << endl;
1649          if (m_data->archiveData(archiveFile,noValues)) {
1650            throw DataException("archiveData Error: problem writing data to archive file");
1651          }
1652        break;        break;
1653    }    }
1654    
1655      if (!archiveFile.good()) {
1656        throw DataException("archiveData Error: problem writing data to archive file");
1657      }
1658    
1659      //
1660      // Close archive file
1661      archiveFile.close();
1662    
1663      if (!archiveFile.good()) {
1664        throw DataException("archiveData Error: problem closing archive file");
1665      }
1666    
1667  }  }
1668    
1669  void  void
# Line 1589  Data::extractData(const std::string file Line 1689  Data::extractData(const std::string file
1689    int flatShape[4];    int flatShape[4];
1690    
1691    //    //
1692    // Open the archive file and read common data items    // Open the archive file
1693    ifstream archiveFile;    ifstream archiveFile;
1694    archiveFile.open(fileName.data(), ios::in);    archiveFile.open(fileName.data(), ios::in);
1695    
# Line 1597  Data::extractData(const std::string file Line 1697  Data::extractData(const std::string file
1697      throw DataException("extractData Error: problem opening archive file");      throw DataException("extractData Error: problem opening archive file");
1698    }    }
1699    
1700      //
1701      // Read common data items from archive file
1702    archiveFile.read(reinterpret_cast<char *>(&dataType),sizeof(int));    archiveFile.read(reinterpret_cast<char *>(&dataType),sizeof(int));
1703    archiveFile.read(reinterpret_cast<char *>(&noSamples),sizeof(int));    archiveFile.read(reinterpret_cast<char *>(&noSamples),sizeof(int));
1704    archiveFile.read(reinterpret_cast<char *>(&noDPPSample),sizeof(int));    archiveFile.read(reinterpret_cast<char *>(&noDPPSample),sizeof(int));
# Line 1625  Data::extractData(const std::string file Line 1727  Data::extractData(const std::string file
1727      throw DataException("extractData Error: problem reading from archive file");      throw DataException("extractData Error: problem reading from archive file");
1728    }    }
1729    
1730    archiveFile.close();    //
1731      // Verify the values just read from the archive file
   if (!archiveFile.good()) {  
     throw DataException("extractData Error: problem closing archive file");  
   }  
   
1732    switch (dataType) {    switch (dataType) {
1733      case 0:      case 0:
1734        cout << "\tdataType: DataEmpty" << endl;        cout << "\tdataType: DataEmpty" << endl;
# Line 1685  Data::extractData(const std::string file Line 1783  Data::extractData(const std::string file
1783    
1784    //    //
1785    // Load this DataVector with the appropriate values    // Load this DataVector with the appropriate values
1786      int noValues;
1787      archiveFile.read(reinterpret_cast<char *>(&noValues),sizeof(int));
1788      cout << "\tnoValues: " << noValues << endl;
1789    switch (dataType) {    switch (dataType) {
1790      case 0:      case 0:
1791        // DataEmpty        // DataEmpty
1792          if (noValues != 0) {
1793            throw DataException("extractData Error: problem reading data from archive file");
1794          }
1795        break;        break;
1796      case 1:      case 1:
1797        // DataConstant        // DataConstant
1798          if (dataVec.extractData(archiveFile,noValues)) {
1799            throw DataException("extractData Error: problem reading data from archive file");
1800          }
1801        break;        break;
1802      case 2:      case 2:
1803        // DataTagged        // DataTagged
1804          if (dataVec.extractData(archiveFile,noValues)) {
1805            throw DataException("extractData Error: problem reading data from archive file");
1806          }
1807        break;        break;
1808      case 3:      case 3:
1809        // DataExpanded        // DataExpanded
1810          if (dataVec.extractData(archiveFile,noValues)) {
1811            throw DataException("extractData Error: problem reading data from archive file");
1812          }
1813        break;        break;
1814    }    }
1815    
1816      if (!archiveFile.good()) {
1817        throw DataException("extractData Error: problem reading from archive file");
1818      }
1819    
1820      //
1821      // Close archive file
1822      archiveFile.close();
1823    
1824      if (!archiveFile.good()) {
1825        throw DataException("extractData Error: problem closing archive file");
1826      }
1827    
1828    //    //
1829    // Construct an appropriate Data object    // Construct an appropriate Data object
1830    DataAbstract* tempData;    DataAbstract* tempData;

Legend:
Removed from v.122  
changed lines
  Added in v.123

  ViewVC Help
Powered by ViewVC 1.1.26