/[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 1795 by jfenwick, Fri Aug 8 04:22:58 2008 UTC revision 1796 by jfenwick, Wed Sep 17 01:45:46 2008 UTC
# Line 19  Line 19 
19  #include "DataConstant.h"  #include "DataConstant.h"
20  #include "DataTagged.h"  #include "DataTagged.h"
21  #include "DataEmpty.h"  #include "DataEmpty.h"
 #include "DataArrayView.h"  
22  #include "FunctionSpaceFactory.h"  #include "FunctionSpaceFactory.h"
23  #include "AbstractContinuousDomain.h"  #include "AbstractContinuousDomain.h"
24  #include "UnaryFuncs.h"  #include "UnaryFuncs.h"
25    #include "FunctionSpaceException.h"
26    
27  extern "C" {  extern "C" {
28  #include "escript/blocktimer.h"  #include "escript/blocktimer.h"
29  }  }
# Line 56  Data::Data(double value, Line 57  Data::Data(double value,
57             const FunctionSpace& what,             const FunctionSpace& what,
58             bool expanded)             bool expanded)
59  {  {
60    DataArrayView::ShapeType dataPointShape;    DataTypes::ShapeType dataPointShape;
61    for (int i = 0; i < shape.attr("__len__")(); ++i) {    for (int i = 0; i < shape.attr("__len__")(); ++i) {
62      dataPointShape.push_back(extract<const int>(shape[i]));      dataPointShape.push_back(extract<const int>(shape[i]));
63    }    }
64    
65    int len = DataArrayView::noValues(dataPointShape);    int len = DataTypes::noValues(dataPointShape);
66    DataVector temp_data(len,value,len);    DataVector temp_data(len,value,len);
67    DataArrayView temp_dataView(temp_data, dataPointShape);  //   DataArrayView temp_dataView(temp_data, dataPointShape);
68    
69    initialise(temp_dataView, what, expanded);  //   initialise(temp_dataView, what, expanded);
70      initialise(temp_data, dataPointShape, what, expanded);
71    
72    m_protected=false;    m_protected=false;
73  }  }
74    
75  Data::Data(double value,  Data::Data(double value,
76         const DataArrayView::ShapeType& dataPointShape,         const DataTypes::ShapeType& dataPointShape,
77         const FunctionSpace& what,         const FunctionSpace& what,
78             bool expanded)             bool expanded)
79  {  {
80    int len = DataArrayView::noValues(dataPointShape);    int len = DataTypes::noValues(dataPointShape);
81    
82    DataVector temp_data(len,value,len);    DataVector temp_data(len,value,len);
83    DataArrayView temp_dataView(temp_data, dataPointShape);  //   DataArrayView temp_dataView(temp_data, dataPointShape);
84    
85    initialise(temp_dataView, what, expanded);  //   initialise(temp_dataView, what, expanded);
86      initialise(temp_data, dataPointShape, what, expanded);
87    
88    m_protected=false;    m_protected=false;
89  }  }
# Line 91  Data::Data(const Data& inData) Line 94  Data::Data(const Data& inData)
94    m_protected=inData.isProtected();    m_protected=inData.isProtected();
95  }  }
96    
97    
98  Data::Data(const Data& inData,  Data::Data(const Data& inData,
99             const DataArrayView::RegionType& region)             const DataTypes::RegionType& region)
100  {  {
101    //    //
102    // Create Data which is a slice of another Data    // Create Data which is a slice of another Data
# Line 107  Data::Data(const Data& inData, Line 111  Data::Data(const Data& inData,
111  {  {
112    if (inData.getFunctionSpace()==functionspace) {    if (inData.getFunctionSpace()==functionspace) {
113      m_data=inData.m_data;      m_data=inData.m_data;
114      } else if (inData.isConstant()) { // for a constant function, we just need to use the new function space
115        if (!inData.probeInterpolation(functionspace))
116        {           // Even though this is constant, we still need to check whether interpolation is allowed
117        throw FunctionSpaceException("Call to probeInterpolation returned false for DataConstant.");
118        }
119        DataConstant* dc=new DataConstant(functionspace,inData.m_data->getShape(),inData.m_data->getVector());  
120        m_data=shared_ptr<DataAbstract>(dc);
121    } else {    } else {
122      Data tmp(0,inData.getPointDataView().getShape(),functionspace,true);      Data tmp(0,inData.getDataPointShape(),functionspace,true);
123      // Note: Must use a reference or pointer to a derived object      // Note: Must use a reference or pointer to a derived object
124      // in order to get polymorphic behaviour. Shouldn't really      // in order to get polymorphic behaviour. Shouldn't really
125      // be able to create an instance of AbstractDomain but that was done      // be able to create an instance of AbstractDomain but that was done
# Line 124  Data::Data(const Data& inData, Line 135  Data::Data(const Data& inData,
135    m_protected=false;    m_protected=false;
136  }  }
137    
138  Data::Data(const DataTagged::TagListType& tagKeys,  // Data::Data(const DataTagged::TagListType& tagKeys,
139             const DataTagged::ValueListType & values,  //            const DataTagged::ValueListType & values,
140             const DataArrayView& defaultValue,  //            const DataArrayView& defaultValue,
141             const FunctionSpace& what,  //            const FunctionSpace& what,
142             bool expanded)  //            bool expanded)
143    // {
144    //   DataAbstract* temp=new DataTagged(tagKeys,values,defaultValue,what);
145    //   shared_ptr<DataAbstract> temp_data(temp);
146    //   m_data=temp_data;
147    //   m_protected=false;
148    //   if (expanded) {
149    //     expand();
150    //   }
151    // }
152    
153    
154    
155    Data::Data(DataAbstract* underlyingdata)
156  {  {
157    DataAbstract* temp=new DataTagged(tagKeys,values,defaultValue,what);      m_data=shared_ptr<DataAbstract>(underlyingdata);
158    shared_ptr<DataAbstract> temp_data(temp);      m_protected=false;
   m_data=temp_data;  
   m_protected=false;  
   if (expanded) {  
     expand();  
   }  
159  }  }
160    
161  Data::Data(const numeric::array& value,  Data::Data(const numeric::array& value,
# Line 146  Data::Data(const numeric::array& value, Line 165  Data::Data(const numeric::array& value,
165    initialise(value,what,expanded);    initialise(value,what,expanded);
166    m_protected=false;    m_protected=false;
167  }  }
168    /*
169  Data::Data(const DataArrayView& value,  Data::Data(const DataArrayView& value,
170         const FunctionSpace& what,         const FunctionSpace& what,
171             bool expanded)             bool expanded)
172  {  {
173    initialise(value,what,expanded);    initialise(value,what,expanded);
174    m_protected=false;    m_protected=false;
175    }*/
176    
177    Data::Data(const DataTypes::ValueType& value,
178             const DataTypes::ShapeType& shape,
179                     const FunctionSpace& what,
180                     bool expanded)
181    {
182       initialise(value,shape,what,expanded);
183       m_protected=false;
184  }  }
185    
186    
187  Data::Data(const object& value,  Data::Data(const object& value,
188         const FunctionSpace& what,         const FunctionSpace& what,
189             bool expanded)             bool expanded)
# Line 168  Data::Data(const object& value, Line 197  Data::Data(const object& value,
197  Data::Data(const object& value,  Data::Data(const object& value,
198             const Data& other)             const Data& other)
199  {  {
   
200    numeric::array asNumArray(value);    numeric::array asNumArray(value);
201    
   
202    // extract the shape of the numarray    // extract the shape of the numarray
203    DataArrayView::ShapeType tempShape;    DataTypes::ShapeType tempShape=DataTypes::shapeFromNumArray(asNumArray);
204    for (int i=0; i < asNumArray.getrank(); i++) {  // /*  for (int i=0; i < asNumArray.getrank(); i++) {
205      tempShape.push_back(extract<int>(asNumArray.getshape()[i]));  //     tempShape.push_back(extract<int>(asNumArray.getshape()[i]));
206    }  //   }*/
207    // get the space for the data vector  //   // get the space for the data vector
208    int len = DataArrayView::noValues(tempShape);  //   int len = DataTypes::noValues(tempShape);
209    DataVector temp_data(len, 0.0, len);  //   DataVector temp_data(len, 0.0, len);
210    DataArrayView temp_dataView(temp_data, tempShape);  // /*  DataArrayView temp_dataView(temp_data, tempShape);
211    temp_dataView.copy(asNumArray);  //   temp_dataView.copy(asNumArray);*/
212    //   temp_data.copyFromNumArray(asNumArray);
213    
214    //    //
215    // Create DataConstant using the given value and all other parameters    // Create DataConstant using the given value and all other parameters
216    // copied from other. If value is a rank 0 object this Data    // copied from other. If value is a rank 0 object this Data
217    // will assume the point data shape of other.    // will assume the point data shape of other.
218    
219    if (temp_dataView.getRank()==0) {    if (DataTypes::getRank(tempShape)/*temp_dataView.getRank()*/==0) {
220      int len = DataArrayView::noValues(other.getPointDataView().getShape());  
221    
222        // get the space for the data vector
223        int len1 = DataTypes::noValues(tempShape);
224        DataVector temp_data(len1, 0.0, len1);
225        temp_data.copyFromNumArray(asNumArray);
226    
227        int len = DataTypes::noValues(other.getDataPointShape());
228    
229        DataVector temp2_data(len, temp_data[0]/*temp_dataView()*/, len);
230        //DataArrayView temp2_dataView(temp2_data, other.getPointDataView().getShape());
231    //     initialise(temp2_dataView, other.getFunctionSpace(), false);
232    
233        DataConstant* t=new DataConstant(other.getFunctionSpace(),other.getDataPointShape(),temp2_data);
234        boost::shared_ptr<DataAbstract> sp(t);
235        m_data=sp;
236    
     DataVector temp2_data(len, temp_dataView(), len);  
     DataArrayView temp2_dataView(temp2_data, other.getPointDataView().getShape());  
     initialise(temp2_dataView, other.getFunctionSpace(), false);  
237    
238    } else {    } else {
239      //      //
240      // Create a DataConstant with the same sample shape as other      // Create a DataConstant with the same sample shape as other
241      initialise(temp_dataView, other.getFunctionSpace(), false);  //     initialise(temp_dataView, other.getFunctionSpace(), false);
242        DataConstant* t=new DataConstant(asNumArray,other.getFunctionSpace());
243        boost::shared_ptr<DataAbstract> sp(t);
244        m_data=sp;
245    }    }
246    m_protected=false;    m_protected=false;
247  }  }
# Line 208  Data::~Data() Line 251  Data::~Data()
251    
252  }  }
253    
254    
255    
256    void
257    Data::initialise(const boost::python::numeric::array& value,
258                     const FunctionSpace& what,
259                     bool expanded)
260    {
261      //
262      // Construct a Data object of the appropriate type.
263      // Construct the object first as there seems to be a bug which causes
264      // undefined behaviour if an exception is thrown during construction
265      // within the shared_ptr constructor.
266      if (expanded) {
267        DataAbstract* temp=new DataExpanded(value, what);
268        boost::shared_ptr<DataAbstract> temp_data(temp);
269        m_data=temp_data;
270      } else {
271        DataAbstract* temp=new DataConstant(value, what);
272        boost::shared_ptr<DataAbstract> temp_data(temp);
273        m_data=temp_data;
274      }
275    }
276    
277    
278    void
279    Data::initialise(const DataTypes::ValueType& value,
280             const DataTypes::ShapeType& shape,
281                     const FunctionSpace& what,
282                     bool expanded)
283    {
284      //
285      // Construct a Data object of the appropriate type.
286      // Construct the object first as there seems to be a bug which causes
287      // undefined behaviour if an exception is thrown during construction
288      // within the shared_ptr constructor.
289      if (expanded) {
290        DataAbstract* temp=new DataExpanded(what, shape, value);
291        boost::shared_ptr<DataAbstract> temp_data(temp);
292        m_data=temp_data;
293      } else {
294        DataAbstract* temp=new DataConstant(what, shape, value);
295        boost::shared_ptr<DataAbstract> temp_data(temp);
296        m_data=temp_data;
297      }
298    }
299    
300    
301    // void
302    // Data::CompareDebug(const Data& rd)
303    // {
304    //  using namespace std;
305    //  bool mismatch=false;
306    //  std::cout << "Comparing left and right" << endl;
307    //  const DataTagged* left=dynamic_cast<DataTagged*>(m_data.get());
308    //  const DataTagged* right=dynamic_cast<DataTagged*>(rd.m_data.get());
309    //  
310    //  if (left==0)
311    //  {
312    //      cout << "left arg is not a DataTagged\n";
313    //      return;
314    //  }
315    //  
316    //  if (right==0)
317    //  {
318    //      cout << "right arg is not a DataTagged\n";
319    //      return;
320    //  }
321    //  cout << "Num elements=" << left->getVector().size() << ":" << right->getVector().size() << std::endl;
322    //  cout << "Shapes ";
323    //  if (left->getShape()==right->getShape())
324    //  {
325    //      cout << "ok\n";
326    //  }
327    //  else
328    //  {
329    //      cout << "Problem: shapes do not match\n";
330    //      mismatch=true;
331    //  }
332    //  int lim=left->getVector().size();
333    //  if (right->getVector().size()) lim=right->getVector().size();
334    //  for (int i=0;i<lim;++i)
335    //  {
336    //      if (left->getVector()[i]!=right->getVector()[i])
337    //      {
338    //          cout << "[" << i << "] value mismatch " << left->getVector()[i] << ":" << right->getVector()[i] << endl;
339    //          mismatch=true;
340    //      }
341    //  }
342    //
343    //  // still need to check the tag map
344    //  // also need to watch what is happening to function spaces, are they copied or what?
345    //
346    //  const DataTagged::DataMapType& mapleft=left->getTagLookup();
347    //  const DataTagged::DataMapType& mapright=right->getTagLookup();
348    //
349    //  if (mapleft.size()!=mapright.size())
350    //  {
351    //      cout << "Maps are different sizes " << mapleft.size() << ":" << mapright.size() << endl;
352    //      mismatch=true;
353    //      cout << "Left map\n";
354    //      DataTagged::DataMapType::const_iterator i,j;
355    //      for (i=mapleft.begin();i!=mapleft.end();++i) {
356    //          cout << "(" << i->first << "=>" << i->second << ")\n";
357    //      }
358    //      cout << "Right map\n";
359    //      for (i=mapright.begin();i!=mapright.end();++i) {
360    //          cout << "(" << i->first << "=>" << i->second << ")\n";
361    //      }
362    //      cout << "End map\n";
363    //
364    //  }
365    //
366    //  DataTagged::DataMapType::const_iterator i,j;
367    //  for (i=mapleft.begin(),j=mapright.begin();i!=mapleft.end() && j!=mapright.end();++i,++j) {
368    //     if ((i->first!=j->first) || (i->second!=j->second))
369    //     {
370    //      cout << "(" << i->first << "=>" << i->second << ")";
371    //      cout << ":(" << j->first << "=>" << j->second << ") ";
372    //      mismatch=true;
373    //            }
374    //  }
375    //  if (mismatch)
376    //  {
377    //      cout << "#Mismatch\n";
378    //  }
379    // }
380    
381  escriptDataC  escriptDataC
382  Data::getDataC()  Data::getDataC()
383  {  {
# Line 227  Data::getDataC() const Line 397  Data::getDataC() const
397  const boost::python::tuple  const boost::python::tuple
398  Data::getShapeTuple() const  Data::getShapeTuple() const
399  {  {
400    const DataArrayView::ShapeType& shape=getDataPointShape();    const DataTypes::ShapeType& shape=getDataPointShape();
401    switch(getDataPointRank()) {    switch(getDataPointRank()) {
402       case 0:       case 0:
403          return make_tuple();          return make_tuple();
# Line 495  Data::gradOn(const FunctionSpace& functi Line 665  Data::gradOn(const FunctionSpace& functi
665    double blocktimer_start = blocktimer_time();    double blocktimer_start = blocktimer_time();
666    if (functionspace.getDomain()!=getDomain())    if (functionspace.getDomain()!=getDomain())
667      throw DataException("Error - gradient cannot be calculated on different domains.");      throw DataException("Error - gradient cannot be calculated on different domains.");
668    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();    DataTypes::ShapeType grad_shape=getDataPointShape();
669    grad_shape.push_back(functionspace.getDim());    grad_shape.push_back(functionspace.getDim());
670    Data out(0.0,grad_shape,functionspace,true);    Data out(0.0,grad_shape,functionspace,true);
671    getDomain().setToGradient(out,*this);    getDomain().setToGradient(out,*this);
# Line 512  Data::grad() const Line 682  Data::grad() const
682  int  int
683  Data::getDataPointSize() const  Data::getDataPointSize() const
684  {  {
685    return getPointDataView().noValues();    return m_data->getNoValues();
686  }  }
687    
688  DataArrayView::ValueType::size_type  DataTypes::ValueType::size_type
689  Data::getLength() const  Data::getLength() const
690  {  {
691    return m_data->getLength();    return m_data->getLength();
692  }  }
693    
694  const DataArrayView::ShapeType&  // const DataTypes::ShapeType&
695  Data::getDataPointShape() const  // Data::getDataPointShape() const
696  {  // {
697    return getPointDataView().getShape();  //   return getPointDataView().getShape();
698  }  // }
699    
700    
701    
702    
# Line 538  Data:: getValueOfDataPoint(int dataPoint Line 709  Data:: getValueOfDataPoint(int dataPoint
709    //    //
710    // determine the rank and shape of each data point    // determine the rank and shape of each data point
711    int dataPointRank = getDataPointRank();    int dataPointRank = getDataPointRank();
712    DataArrayView::ShapeType dataPointShape = getDataPointShape();    const DataTypes::ShapeType& dataPointShape = getDataPointShape();
713    
714    //    //
715    // create the numeric array to be returned    // create the numeric array to be returned
# Line 548  Data:: getValueOfDataPoint(int dataPoint Line 719  Data:: getValueOfDataPoint(int dataPoint
719    // the shape of the returned numeric array will be the same    // the shape of the returned numeric array will be the same
720    // as that of the data point    // as that of the data point
721    int arrayRank = dataPointRank;    int arrayRank = dataPointRank;
722    DataArrayView::ShapeType arrayShape = dataPointShape;    const DataTypes::ShapeType& arrayShape = dataPointShape;
723    
724    //    //
725    // resize the numeric array to the shape just calculated    // resize the numeric array to the shape just calculated
# Line 584  Data:: getValueOfDataPoint(int dataPoint Line 755  Data:: getValueOfDataPoint(int dataPoint
755         }         }
756         // TODO: global error handling         // TODO: global error handling
757         // create a view of the data if it is stored locally         // create a view of the data if it is stored locally
758         DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);  //       DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);
759           DataTypes::ValueType::size_type offset=getDataOffset(sampleNo, dataPointNoInSample);
760    
761    
762         switch( dataPointRank ){         switch( dataPointRank ){
763              case 0 :              case 0 :
764                  numArray[0] = dataPointView();                  numArray[0] = getDataAtOffset(offset);
765                  break;                  break;
766              case 1 :              case 1 :
767                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
768                      numArray[i]=dataPointView(i);                      numArray[i]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i));
769                  break;                  break;
770              case 2 :              case 2 :
771                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
772                      for( j=0; j<dataPointShape[1]; j++)                      for( j=0; j<dataPointShape[1]; j++)
773                          numArray[make_tuple(i,j)]=dataPointView(i,j);                          numArray[make_tuple(i,j)]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j));
774                  break;                  break;
775              case 3 :              case 3 :
776                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
777                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
778                          for( k=0; k<dataPointShape[2]; k++)                          for( k=0; k<dataPointShape[2]; k++)
779                              numArray[make_tuple(i,j,k)]=dataPointView(i,j,k);                              numArray[make_tuple(i,j,k)]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j,k));
780                  break;                  break;
781              case 4 :              case 4 :
782                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
783                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
784                          for( k=0; k<dataPointShape[2]; k++ )                          for( k=0; k<dataPointShape[2]; k++ )
785                              for( l=0; l<dataPointShape[3]; l++)                              for( l=0; l<dataPointShape[3]; l++)
786                                  numArray[make_tuple(i,j,k,l)]=dataPointView(i,j,k,l);                                  numArray[make_tuple(i,j,k,l)]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j,k,l));
787                  break;                  break;
788      }      }
789    }    }
# Line 619  Data:: getValueOfDataPoint(int dataPoint Line 792  Data:: getValueOfDataPoint(int dataPoint
792    return numArray;    return numArray;
793    
794  }  }
795    
796  void  void
797  Data::setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object)  Data::setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object)
798  {  {
# Line 689  Data::getValueOfGlobalDataPoint(int proc Line 863  Data::getValueOfGlobalDataPoint(int proc
863    //    //
864    // determine the rank and shape of each data point    // determine the rank and shape of each data point
865    int dataPointRank = getDataPointRank();    int dataPointRank = getDataPointRank();
866    DataArrayView::ShapeType dataPointShape = getDataPointShape();    const DataTypes::ShapeType& dataPointShape = getDataPointShape();
867    
868    //    //
869    // create the numeric array to be returned    // create the numeric array to be returned
# Line 699  Data::getValueOfGlobalDataPoint(int proc Line 873  Data::getValueOfGlobalDataPoint(int proc
873    // the shape of the returned numeric array will be the same    // the shape of the returned numeric array will be the same
874    // as that of the data point    // as that of the data point
875    int arrayRank = dataPointRank;    int arrayRank = dataPointRank;
876    DataArrayView::ShapeType arrayShape = dataPointShape;    const DataTypes::ShapeType& arrayShape = dataPointShape;
877    
878    //    //
879    // resize the numeric array to the shape just calculated    // resize the numeric array to the shape just calculated
# Line 745  Data::getValueOfGlobalDataPoint(int proc Line 919  Data::getValueOfGlobalDataPoint(int proc
919                  }                  }
920                  // TODO: global error handling                  // TODO: global error handling
921          // create a view of the data if it is stored locally          // create a view of the data if it is stored locally
922          DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);          //DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);
923            DataTypes::ValueType::size_type offset=getDataOffset(sampleNo, dataPointNoInSample);
924    
925          // pack the data from the view into tmpData for MPI communication          // pack the data from the view into tmpData for MPI communication
926          pos=0;          pos=0;
927          switch( dataPointRank ){          switch( dataPointRank ){
928              case 0 :              case 0 :
929                  tmpData[0] = dataPointView();                  tmpData[0] = getDataAtOffset(offset);
930                  break;                  break;
931              case 1 :              case 1 :
932                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
933                      tmpData[i]=dataPointView(i);                      tmpData[i]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i));
934                  break;                  break;
935              case 2 :              case 2 :
936                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
937                      for( j=0; j<dataPointShape[1]; j++, pos++ )                      for( j=0; j<dataPointShape[1]; j++, pos++ )
938                          tmpData[pos]=dataPointView(i,j);                          tmpData[pos]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j));
939                  break;                  break;
940              case 3 :              case 3 :
941                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
942                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
943                          for( k=0; k<dataPointShape[2]; k++, pos++ )                          for( k=0; k<dataPointShape[2]; k++, pos++ )
944                              tmpData[pos]=dataPointView(i,j,k);                              tmpData[pos]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j,k));
945                  break;                  break;
946              case 4 :              case 4 :
947                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
948                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
949                          for( k=0; k<dataPointShape[2]; k++ )                          for( k=0; k<dataPointShape[2]; k++ )
950                              for( l=0; l<dataPointShape[3]; l++, pos++ )                              for( l=0; l<dataPointShape[3]; l++, pos++ )
951                                  tmpData[pos]=dataPointView(i,j,k,l);                                  tmpData[pos]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j,k,l));
952                  break;                  break;
953          }          }
954              }              }
# Line 825  Data::integrate() const Line 1000  Data::integrate() const
1000  {  {
1001    int index;    int index;
1002    int rank = getDataPointRank();    int rank = getDataPointRank();
1003    DataArrayView::ShapeType shape = getDataPointShape();    DataTypes::ShapeType shape = getDataPointShape();
1004    int dataPointSize = getDataPointSize();    int dataPointSize = getDataPointSize();
1005    
1006    //    //
# Line 1125  Data Line 1300  Data
1300  Data::swapaxes(const int axis0, const int axis1) const  Data::swapaxes(const int axis0, const int axis1) const
1301  {  {
1302       int axis0_tmp,axis1_tmp;       int axis0_tmp,axis1_tmp;
1303       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1304       DataArrayView::ShapeType ev_shape;       DataTypes::ShapeType ev_shape;
1305       // Here's the equivalent of python s_out=s[axis_offset:]+s[:axis_offset]       // Here's the equivalent of python s_out=s[axis_offset:]+s[:axis_offset]
1306       // which goes thru all shape vector elements starting with axis_offset (at index=rank wrap around to 0)       // which goes thru all shape vector elements starting with axis_offset (at index=rank wrap around to 0)
1307       int rank=getDataPointRank();       int rank=getDataPointRank();
# Line 1169  Data Line 1344  Data
1344  Data::symmetric() const  Data::symmetric() const
1345  {  {
1346       // check input       // check input
1347       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1348       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1349          if(s[0] != s[1])          if(s[0] != s[1])
1350             throw DataException("Error - Data::symmetric can only be calculated for rank 2 object with equal first and second dimension.");             throw DataException("Error - Data::symmetric can only be calculated for rank 2 object with equal first and second dimension.");
# Line 1191  Data Line 1366  Data
1366  Data::nonsymmetric() const  Data::nonsymmetric() const
1367  {  {
1368       // check input       // check input
1369       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1370       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1371          if(s[0] != s[1])          if(s[0] != s[1])
1372             throw DataException("Error - Data::nonsymmetric can only be calculated for rank 2 object with equal first and second dimension.");             throw DataException("Error - Data::nonsymmetric can only be calculated for rank 2 object with equal first and second dimension.");
1373          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1374          ev_shape.push_back(s[0]);          ev_shape.push_back(s[0]);
1375          ev_shape.push_back(s[1]);          ev_shape.push_back(s[1]);
1376          Data ev(0.,ev_shape,getFunctionSpace());          Data ev(0.,ev_shape,getFunctionSpace());
# Line 1206  Data::nonsymmetric() const Line 1381  Data::nonsymmetric() const
1381       else if (getDataPointRank()==4) {       else if (getDataPointRank()==4) {
1382          if(!(s[0] == s[2] && s[1] == s[3]))          if(!(s[0] == s[2] && s[1] == s[3]))
1383             throw DataException("Error - Data::nonsymmetric can only be calculated for rank 4 object with dim0==dim2 and dim1==dim3.");             throw DataException("Error - Data::nonsymmetric can only be calculated for rank 4 object with dim0==dim2 and dim1==dim3.");
1384          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1385          ev_shape.push_back(s[0]);          ev_shape.push_back(s[0]);
1386          ev_shape.push_back(s[1]);          ev_shape.push_back(s[1]);
1387          ev_shape.push_back(s[2]);          ev_shape.push_back(s[2]);
# Line 1224  Data::nonsymmetric() const Line 1399  Data::nonsymmetric() const
1399  Data  Data
1400  Data::trace(int axis_offset) const  Data::trace(int axis_offset) const
1401  {  {
1402       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1403       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1404          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1405          Data ev(0.,ev_shape,getFunctionSpace());          Data ev(0.,ev_shape,getFunctionSpace());
1406          ev.typeMatchRight(*this);          ev.typeMatchRight(*this);
1407          m_data->trace(ev.m_data.get(), axis_offset);          m_data->trace(ev.m_data.get(), axis_offset);
1408          return ev;          return ev;
1409       }       }
1410       if (getDataPointRank()==3) {       if (getDataPointRank()==3) {
1411          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1412          if (axis_offset==0) {          if (axis_offset==0) {
1413            int s2=s[2];            int s2=s[2];
1414            ev_shape.push_back(s2);            ev_shape.push_back(s2);
# Line 1248  Data::trace(int axis_offset) const Line 1423  Data::trace(int axis_offset) const
1423          return ev;          return ev;
1424       }       }
1425       if (getDataPointRank()==4) {       if (getDataPointRank()==4) {
1426          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1427          if (axis_offset==0) {          if (axis_offset==0) {
1428            ev_shape.push_back(s[2]);            ev_shape.push_back(s[2]);
1429            ev_shape.push_back(s[3]);            ev_shape.push_back(s[3]);
# Line 1274  Data::trace(int axis_offset) const Line 1449  Data::trace(int axis_offset) const
1449  Data  Data
1450  Data::transpose(int axis_offset) const  Data::transpose(int axis_offset) const
1451  {  {
1452       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1453       DataArrayView::ShapeType ev_shape;       DataTypes::ShapeType ev_shape;
1454       // Here's the equivalent of python s_out=s[axis_offset:]+s[:axis_offset]       // Here's the equivalent of python s_out=s[axis_offset:]+s[:axis_offset]
1455       // which goes thru all shape vector elements starting with axis_offset (at index=rank wrap around to 0)       // which goes thru all shape vector elements starting with axis_offset (at index=rank wrap around to 0)
1456       int rank=getDataPointRank();       int rank=getDataPointRank();
# Line 1296  Data Line 1471  Data
1471  Data::eigenvalues() const  Data::eigenvalues() const
1472  {  {
1473       // check input       // check input
1474       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1475       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
1476          throw DataException("Error - Data::eigenvalues can only be calculated for rank 2 object.");          throw DataException("Error - Data::eigenvalues can only be calculated for rank 2 object.");
1477       if(s[0] != s[1])       if(s[0] != s[1])
1478          throw DataException("Error - Data::eigenvalues can only be calculated for object with equal first and second dimension.");          throw DataException("Error - Data::eigenvalues can only be calculated for object with equal first and second dimension.");
1479       // create return       // create return
1480       DataArrayView::ShapeType ev_shape(1,s[0]);       DataTypes::ShapeType ev_shape(1,s[0]);
1481       Data ev(0.,ev_shape,getFunctionSpace());       Data ev(0.,ev_shape,getFunctionSpace());
1482       ev.typeMatchRight(*this);       ev.typeMatchRight(*this);
1483       m_data->eigenvalues(ev.m_data.get());       m_data->eigenvalues(ev.m_data.get());
# Line 1312  Data::eigenvalues() const Line 1487  Data::eigenvalues() const
1487  const boost::python::tuple  const boost::python::tuple
1488  Data::eigenvalues_and_eigenvectors(const double tol) const  Data::eigenvalues_and_eigenvectors(const double tol) const
1489  {  {
1490       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1491       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
1492          throw DataException("Error - Data::eigenvalues and eigenvectors can only be calculated for rank 2 object.");          throw DataException("Error - Data::eigenvalues and eigenvectors can only be calculated for rank 2 object.");
1493       if(s[0] != s[1])       if(s[0] != s[1])
1494          throw DataException("Error - Data::eigenvalues and eigenvectors can only be calculated for object with equal first and second dimension.");          throw DataException("Error - Data::eigenvalues and eigenvectors can only be calculated for object with equal first and second dimension.");
1495       // create return       // create return
1496       DataArrayView::ShapeType ev_shape(1,s[0]);       DataTypes::ShapeType ev_shape(1,s[0]);
1497       Data ev(0.,ev_shape,getFunctionSpace());       Data ev(0.,ev_shape,getFunctionSpace());
1498       ev.typeMatchRight(*this);       ev.typeMatchRight(*this);
1499       DataArrayView::ShapeType V_shape(2,s[0]);       DataTypes::ShapeType V_shape(2,s[0]);
1500       Data V(0.,V_shape,getFunctionSpace());       Data V(0.,V_shape,getFunctionSpace());
1501       V.typeMatchRight(*this);       V.typeMatchRight(*this);
1502       m_data->eigenvalues_and_eigenvectors(ev.m_data.get(),V.m_data.get(),tol);       m_data->eigenvalues_and_eigenvectors(ev.m_data.get(),V.m_data.get(),tol);
# Line 1363  Data::calc_minGlobalDataPoint(int& ProcN Line 1538  Data::calc_minGlobalDataPoint(int& ProcN
1538      #pragma omp for private(i,j) schedule(static)      #pragma omp for private(i,j) schedule(static)
1539      for (i=0; i<numSamples; i++) {      for (i=0; i<numSamples; i++) {
1540        for (j=0; j<numDPPSample; j++) {        for (j=0; j<numDPPSample; j++) {
1541          next=temp.getDataPoint(i,j)();          next=temp.getDataAtOffset(temp.getDataOffset(i,j));
1542          if (next<local_min) {          if (next<local_min) {
1543            local_min=next;            local_min=next;
1544            local_lowi=i;            local_lowi=i;
# Line 1381  Data::calc_minGlobalDataPoint(int& ProcN Line 1556  Data::calc_minGlobalDataPoint(int& ProcN
1556    
1557  #ifdef PASO_MPI  #ifdef PASO_MPI
1558      // determine the processor on which the minimum occurs      // determine the processor on which the minimum occurs
1559      next = temp.getDataPoint(lowi,lowj)();      next = temp.getDataPoint(lowi,lowj);
1560      int lowProc = 0;      int lowProc = 0;
1561      double *globalMins = new double[get_MPISize()+1];      double *globalMins = new double[get_MPISize()+1];
1562      int error = MPI_Gather ( &next, 1, MPI_DOUBLE, globalMins, 1, MPI_DOUBLE, 0, get_MPIComm() );      int error = MPI_Gather ( &next, 1, MPI_DOUBLE, globalMins, 1, MPI_DOUBLE, 0, get_MPIComm() );
# Line 1666  escript::operator/(const boost::python:: Line 1841  escript::operator/(const boost::python::
1841  Data  Data
1842  Data::getItem(const boost::python::object& key) const  Data::getItem(const boost::python::object& key) const
1843  {  {
1844    const DataArrayView& view=getPointDataView();  //  const DataArrayView& view=getPointDataView();
1845    
1846    DataArrayView::RegionType slice_region=view.getSliceRegion(key);    DataTypes::RegionType slice_region=DataTypes::getSliceRegion(getDataPointShape(),key);
1847    
1848    if (slice_region.size()!=view.getRank()) {    if (slice_region.size()!=getDataPointRank()) {
1849      throw DataException("Error - slice size does not match Data rank.");      throw DataException("Error - slice size does not match Data rank.");
1850    }    }
1851    
# Line 1680  Data::getItem(const boost::python::objec Line 1855  Data::getItem(const boost::python::objec
1855  /* TODO */  /* TODO */
1856  /* global reduction */  /* global reduction */
1857  Data  Data
1858  Data::getSlice(const DataArrayView::RegionType& region) const  Data::getSlice(const DataTypes::RegionType& region) const
1859  {  {
1860    return Data(*this,region);    return Data(*this,region);
1861  }  }
# Line 1699  void Line 1874  void
1874  Data::setItemD(const boost::python::object& key,  Data::setItemD(const boost::python::object& key,
1875                 const Data& value)                 const Data& value)
1876  {  {
1877    const DataArrayView& view=getPointDataView();  //  const DataArrayView& view=getPointDataView();
1878    
1879    DataArrayView::RegionType slice_region=view.getSliceRegion(key);    DataTypes::RegionType slice_region=DataTypes::getSliceRegion(getDataPointShape(),key);
1880    if (slice_region.size()!=view.getRank()) {    if (slice_region.size()!=getDataPointRank()) {
1881      throw DataException("Error - slice size does not match Data rank.");      throw DataException("Error - slice size does not match Data rank.");
1882    }    }
1883    if (getFunctionSpace()!=value.getFunctionSpace()) {    if (getFunctionSpace()!=value.getFunctionSpace()) {
# Line 1714  Data::setItemD(const boost::python::obje Line 1889  Data::setItemD(const boost::python::obje
1889    
1890  void  void
1891  Data::setSlice(const Data& value,  Data::setSlice(const Data& value,
1892                 const DataArrayView::RegionType& region)                 const DataTypes::RegionType& region)
1893  {  {
1894    if (isProtected()) {    if (isProtected()) {
1895          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
# Line 1777  Data::setTaggedValue(int tagKey, Line 1952  Data::setTaggedValue(int tagKey,
1952    
1953    
1954    // extract the shape of the numarray    // extract the shape of the numarray
1955    DataArrayView::ShapeType tempShape;    DataTypes::ShapeType tempShape;
1956    for (int i=0; i < asNumArray.getrank(); i++) {    for (int i=0; i < asNumArray.getrank(); i++) {
1957      tempShape.push_back(extract<int>(asNumArray.getshape()[i]));      tempShape.push_back(extract<int>(asNumArray.getshape()[i]));
1958    }    }
1959    
1960    // get the space for the data vector    // get the space for the data vector
1961    int len = DataArrayView::noValues(tempShape);  //   int len = DataTypes::noValues(tempShape);
1962    DataVector temp_data(len, 0.0, len);  //   DataVector temp_data(len, 0.0, len);
1963    DataArrayView temp_dataView(temp_data, tempShape);  //   DataArrayView temp_dataView(temp_data, tempShape);
1964    temp_dataView.copy(asNumArray);  //   temp_dataView.copy(asNumArray);
1965    
1966      DataVector temp_data2;
1967      temp_data2.copyFromNumArray(asNumArray);
1968    
1969    //    //
1970    // Call DataAbstract::setTaggedValue    // Call DataAbstract::setTaggedValue
1971    m_data->setTaggedValue(tagKey,temp_dataView);    //m_data->setTaggedValue(tagKey,temp_dataView);
1972    
1973        m_data->setTaggedValue(tagKey,tempShape, temp_data2);
1974  }  }
1975    
1976    // void
1977    // Data::setTaggedValueFromCPP(int tagKey,
1978    //                             const DataArrayView& value)
1979    // {
1980    //   if (isProtected()) {
1981    //         throw DataException("Error - attempt to update protected Data object.");
1982    //   }
1983    //   //
1984    //   // Ensure underlying data object is of type DataTagged
1985    //   if (isConstant()) tag();
1986    //
1987    //   //
1988    //   // Call DataAbstract::setTaggedValue
1989    //   m_data->setTaggedValue(tagKey,value);
1990    // }
1991    
1992  void  void
1993  Data::setTaggedValueFromCPP(int tagKey,  Data::setTaggedValueFromCPP(int tagKey,
1994                              const DataArrayView& value)                  const DataTypes::ShapeType& pointshape,
1995                                const DataTypes::ValueType& value,
1996                    int dataOffset)
1997  {  {
1998    if (isProtected()) {    if (isProtected()) {
1999          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
# Line 1806  Data::setTaggedValueFromCPP(int tagKey, Line 2004  Data::setTaggedValueFromCPP(int tagKey,
2004    
2005    //    //
2006    // Call DataAbstract::setTaggedValue    // Call DataAbstract::setTaggedValue
2007    m_data->setTaggedValue(tagKey,value);    m_data->setTaggedValue(tagKey,pointshape, value, dataOffset);
2008  }  }
2009    
2010  int  int
# Line 1815  Data::getTagNumber(int dpno) Line 2013  Data::getTagNumber(int dpno)
2013    return getFunctionSpace().getTagFromDataPointNo(dpno);    return getFunctionSpace().getTagFromDataPointNo(dpno);
2014  }  }
2015    
 void  
 Data::archiveData(const std::string fileName)  
 {  
   cout << "Archiving Data object to: " << fileName << endl;  
   
   //  
   // Determine type of this Data object  
   int dataType = -1;  
   
   if (isEmpty()) {  
     dataType = 0;  
     cout << "\tdataType: DataEmpty" << endl;  
   }  
   if (isConstant()) {  
     dataType = 1;  
     cout << "\tdataType: DataConstant" << endl;  
   }  
   if (isTagged()) {  
     dataType = 2;  
     cout << "\tdataType: DataTagged" << endl;  
   }  
   if (isExpanded()) {  
     dataType = 3;  
     cout << "\tdataType: DataExpanded" << endl;  
   }  
   
   if (dataType == -1) {  
     throw DataException("archiveData Error: undefined dataType");  
   }  
   
   //  
   // Collect data items common to all Data types  
   int noSamples = getNumSamples();  
   int noDPPSample = getNumDataPointsPerSample();  
   int functionSpaceType = getFunctionSpace().getTypeCode();  
   int dataPointRank = getDataPointRank();  
   int dataPointSize = getDataPointSize();  
   int dataLength = getLength();  
   DataArrayView::ShapeType dataPointShape = getDataPointShape();  
   vector<int> referenceNumbers(noSamples);  
   for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {  
     referenceNumbers[sampleNo] = getFunctionSpace().getReferenceIDOfSample(sampleNo);  
   }  
   vector<int> tagNumbers(noSamples);  
   if (isTagged()) {  
     for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {  
       tagNumbers[sampleNo] = getFunctionSpace().getTagFromSampleNo(sampleNo);  
     }  
   }  
   
   cout << "\tnoSamples: " << noSamples << " noDPPSample: " << noDPPSample << endl;  
   cout << "\tfunctionSpaceType: " << functionSpaceType << endl;  
   cout << "\trank: " << dataPointRank << " size: " << dataPointSize << " length: " << dataLength << endl;  
   
   //  
   // Flatten Shape to an array of integers suitable for writing to file  
   int flatShape[4] = {0,0,0,0};  
   cout << "\tshape: < ";  
   for (int dim=0; dim<dataPointRank; dim++) {  
     flatShape[dim] = dataPointShape[dim];  
     cout << dataPointShape[dim] << " ";  
   }  
   cout << ">" << endl;  
   
   //  
   // Open archive file  
   ofstream archiveFile;  
   archiveFile.open(fileName.data(), ios::out);  
   
   if (!archiveFile.good()) {  
     throw DataException("archiveData Error: problem opening archive file");  
   }  
   
   //  
   // Write common data items to archive file  
   archiveFile.write(reinterpret_cast<char *>(&dataType),sizeof(int));  
   archiveFile.write(reinterpret_cast<char *>(&noSamples),sizeof(int));  
   archiveFile.write(reinterpret_cast<char *>(&noDPPSample),sizeof(int));  
   archiveFile.write(reinterpret_cast<char *>(&functionSpaceType),sizeof(int));  
   archiveFile.write(reinterpret_cast<char *>(&dataPointRank),sizeof(int));  
   archiveFile.write(reinterpret_cast<char *>(&dataPointSize),sizeof(int));  
   archiveFile.write(reinterpret_cast<char *>(&dataLength),sizeof(int));  
   for (int dim = 0; dim < 4; dim++) {  
     archiveFile.write(reinterpret_cast<char *>(&flatShape[dim]),sizeof(int));  
   }  
   for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {  
     archiveFile.write(reinterpret_cast<char *>(&referenceNumbers[sampleNo]),sizeof(int));  
   }  
   if (isTagged()) {  
     for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {  
       archiveFile.write(reinterpret_cast<char *>(&tagNumbers[sampleNo]),sizeof(int));  
     }  
   }  
   
   if (!archiveFile.good()) {  
     throw DataException("archiveData Error: problem writing to archive file");  
   }  
   
   //  
   // Archive underlying data values for each Data type  
   int noValues;  
   switch (dataType) {  
     case 0:  
       // DataEmpty  
       noValues = 0;  
       archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));  
       cout << "\tnoValues: " << noValues << endl;  
       break;  
     case 1:  
       // DataConstant  
       noValues = m_data->getLength();  
       archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));  
       cout << "\tnoValues: " << noValues << endl;  
       if (m_data->archiveData(archiveFile,noValues)) {  
         throw DataException("archiveData Error: problem writing data to archive file");  
       }  
       break;  
     case 2:  
       // DataTagged  
       noValues = m_data->getLength();  
       archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));  
       cout << "\tnoValues: " << noValues << endl;  
       if (m_data->archiveData(archiveFile,noValues)) {  
         throw DataException("archiveData Error: problem writing data to archive file");  
       }  
       break;  
     case 3:  
       // DataExpanded  
       noValues = m_data->getLength();  
       archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));  
       cout << "\tnoValues: " << noValues << endl;  
       if (m_data->archiveData(archiveFile,noValues)) {  
         throw DataException("archiveData Error: problem writing data to archive file");  
       }  
       break;  
   }  
   
   if (!archiveFile.good()) {  
     throw DataException("archiveData Error: problem writing data to archive file");  
   }  
   
   //  
   // Close archive file  
   archiveFile.close();  
   
   if (!archiveFile.good()) {  
     throw DataException("archiveData Error: problem closing archive file");  
   }  
   
 }  
   
 void  
 Data::extractData(const std::string fileName,  
                   const FunctionSpace& fspace)  
 {  
   //  
   // Can only extract Data to an object which is initially DataEmpty  
   if (!isEmpty()) {  
     throw DataException("extractData Error: can only extract to DataEmpty object");  
   }  
   
   cout << "Extracting Data object from: " << fileName << endl;  
   
   int dataType;  
   int noSamples;  
   int noDPPSample;  
   int functionSpaceType;  
   int dataPointRank;  
   int dataPointSize;  
   int dataLength;  
   DataArrayView::ShapeType dataPointShape;  
   int flatShape[4];  
   
   //  
   // Open the archive file  
   ifstream archiveFile;  
   archiveFile.open(fileName.data(), ios::in);  
   
   if (!archiveFile.good()) {  
     throw DataException("extractData Error: problem opening archive file");  
   }  
   
   //  
   // Read common data items from archive file  
   archiveFile.read(reinterpret_cast<char *>(&dataType),sizeof(int));  
   archiveFile.read(reinterpret_cast<char *>(&noSamples),sizeof(int));  
   archiveFile.read(reinterpret_cast<char *>(&noDPPSample),sizeof(int));  
   archiveFile.read(reinterpret_cast<char *>(&functionSpaceType),sizeof(int));  
   archiveFile.read(reinterpret_cast<char *>(&dataPointRank),sizeof(int));  
   archiveFile.read(reinterpret_cast<char *>(&dataPointSize),sizeof(int));  
   archiveFile.read(reinterpret_cast<char *>(&dataLength),sizeof(int));  
   for (int dim = 0; dim < 4; dim++) {  
     archiveFile.read(reinterpret_cast<char *>(&flatShape[dim]),sizeof(int));  
     if (flatShape[dim]>0) {  
       dataPointShape.push_back(flatShape[dim]);  
     }  
   }  
   vector<int> referenceNumbers(noSamples);  
   for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {  
     archiveFile.read(reinterpret_cast<char *>(&referenceNumbers[sampleNo]),sizeof(int));  
   }  
   vector<int> tagNumbers(noSamples);  
   if (dataType==2) {  
     for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {  
       archiveFile.read(reinterpret_cast<char *>(&tagNumbers[sampleNo]),sizeof(int));  
     }  
   }  
   
   if (!archiveFile.good()) {  
     throw DataException("extractData Error: problem reading from archive file");  
   }  
   
   //  
   // Verify the values just read from the archive file  
   switch (dataType) {  
     case 0:  
       cout << "\tdataType: DataEmpty" << endl;  
       break;  
     case 1:  
       cout << "\tdataType: DataConstant" << endl;  
       break;  
     case 2:  
       cout << "\tdataType: DataTagged" << endl;  
       break;  
     case 3:  
       cout << "\tdataType: DataExpanded" << endl;  
       break;  
     default:  
       throw DataException("extractData Error: undefined dataType read from archive file");  
       break;  
   }  
   
   cout << "\tnoSamples: " << noSamples << " noDPPSample: " << noDPPSample << endl;  
   cout << "\tfunctionSpaceType: " << functionSpaceType << endl;  
   cout << "\trank: " << dataPointRank << " size: " << dataPointSize << " length: " << dataLength << endl;  
   cout << "\tshape: < ";  
   for (int dim = 0; dim < dataPointRank; dim++) {  
     cout << dataPointShape[dim] << " ";  
   }  
   cout << ">" << endl;  
   
   //  
   // Verify that supplied FunctionSpace object is compatible with this Data object.  
   if ( (fspace.getTypeCode()!=functionSpaceType) ||  
        (fspace.getNumSamples()!=noSamples) ||  
        (fspace.getNumDPPSample()!=noDPPSample)  
      ) {  
     throw DataException("extractData Error: incompatible FunctionSpace");  
   }  
   for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {  
     if (referenceNumbers[sampleNo] != fspace.getReferenceIDOfSample(sampleNo)) {  
       throw DataException("extractData Error: incompatible FunctionSpace");  
     }  
   }  
   if (dataType==2) {  
     for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {  
       if (tagNumbers[sampleNo] != fspace.getTagFromSampleNo(sampleNo)) {  
         throw DataException("extractData Error: incompatible FunctionSpace");  
       }  
     }  
   }  
   
   //  
   // Construct a DataVector to hold underlying data values  
   DataVector dataVec(dataLength);  
   
   //  
   // Load this DataVector with the appropriate values  
   int noValues;  
   archiveFile.read(reinterpret_cast<char *>(&noValues),sizeof(int));  
   cout << "\tnoValues: " << noValues << endl;  
   switch (dataType) {  
     case 0:  
       // DataEmpty  
       if (noValues != 0) {  
         throw DataException("extractData Error: problem reading data from archive file");  
       }  
       break;  
     case 1:  
       // DataConstant  
       if (dataVec.extractData(archiveFile,noValues)) {  
         throw DataException("extractData Error: problem reading data from archive file");  
       }  
       break;  
     case 2:  
       // DataTagged  
       if (dataVec.extractData(archiveFile,noValues)) {  
         throw DataException("extractData Error: problem reading data from archive file");  
       }  
       break;  
     case 3:  
       // DataExpanded  
       if (dataVec.extractData(archiveFile,noValues)) {  
         throw DataException("extractData Error: problem reading data from archive file");  
       }  
       break;  
   }  
   
   if (!archiveFile.good()) {  
     throw DataException("extractData Error: problem reading from archive file");  
   }  
   
   //  
   // Close archive file  
   archiveFile.close();  
   
   if (!archiveFile.good()) {  
     throw DataException("extractData Error: problem closing archive file");  
   }  
   
   //  
   // Construct an appropriate Data object  
   DataAbstract* tempData;  
   switch (dataType) {  
     case 0:  
       // DataEmpty  
       tempData=new DataEmpty();  
       break;  
     case 1:  
       // DataConstant  
       tempData=new DataConstant(fspace,dataPointShape,dataVec);  
       break;  
     case 2:  
       // DataTagged  
       tempData=new DataTagged(fspace,dataPointShape,tagNumbers,dataVec);  
       break;  
     case 3:  
       // DataExpanded  
       tempData=new DataExpanded(fspace,dataPointShape,dataVec);  
       break;  
   }  
   shared_ptr<DataAbstract> temp_data(tempData);  
   m_data=temp_data;  
 }  
2016    
2017  ostream& escript::operator<<(ostream& o, const Data& data)  ostream& escript::operator<<(ostream& o, const Data& data)
2018  {  {
# Line 2186  escript::C_GeneralTensorProduct(Data& ar Line 2050  escript::C_GeneralTensorProduct(Data& ar
2050    // Get rank and shape of inputs    // Get rank and shape of inputs
2051    int rank0 = arg_0_Z.getDataPointRank();    int rank0 = arg_0_Z.getDataPointRank();
2052    int rank1 = arg_1_Z.getDataPointRank();    int rank1 = arg_1_Z.getDataPointRank();
2053    DataArrayView::ShapeType shape0 = arg_0_Z.getDataPointShape();    const DataTypes::ShapeType& shape0 = arg_0_Z.getDataPointShape();
2054    DataArrayView::ShapeType shape1 = arg_1_Z.getDataPointShape();    const DataTypes::ShapeType& shape1 = arg_1_Z.getDataPointShape();
2055    
2056    // Prepare for the loops of the product and verify compatibility of shapes    // Prepare for the loops of the product and verify compatibility of shapes
2057    int start0=0, start1=0;    int start0=0, start1=0;
# Line 2196  escript::C_GeneralTensorProduct(Data& ar Line 2060  escript::C_GeneralTensorProduct(Data& ar
2060    else if (transpose == 2)  { start1 = rank1-axis_offset; }    else if (transpose == 2)  { start1 = rank1-axis_offset; }
2061    else              { throw DataException("C_GeneralTensorProduct: Error - transpose should be 0, 1 or 2"); }    else              { throw DataException("C_GeneralTensorProduct: Error - transpose should be 0, 1 or 2"); }
2062    
2063    
2064    // Adjust the shapes for transpose    // Adjust the shapes for transpose
2065    DataArrayView::ShapeType tmpShape0;    DataTypes::ShapeType tmpShape0(rank0);    // pre-sizing the vectors rather
2066    DataArrayView::ShapeType tmpShape1;    DataTypes::ShapeType tmpShape1(rank1);    // than using push_back
2067    for (int i=0; i<rank0; i++)   { tmpShape0.push_back( shape0[(i+start0)%rank0] ); }    for (int i=0; i<rank0; i++)   { tmpShape0[i]=shape0[(i+start0)%rank0]; }
2068    for (int i=0; i<rank1; i++)   { tmpShape1.push_back( shape1[(i+start1)%rank1] ); }    for (int i=0; i<rank1; i++)   { tmpShape1[i]=shape1[(i+start1)%rank1]; }
2069    
2070  #if 0  #if 0
2071    // For debugging: show shape after transpose    // For debugging: show shape after transpose
# Line 2231  escript::C_GeneralTensorProduct(Data& ar Line 2096  escript::C_GeneralTensorProduct(Data& ar
2096      SR *= tmpShape1[i];      SR *= tmpShape1[i];
2097    }    }
2098    
2099    // Define the shape of the output    // Define the shape of the output (rank of shape is the sum of the loop ranges below)
2100    DataArrayView::ShapeType shape2;    DataTypes::ShapeType shape2(rank0+rank1-2*axis_offset);  
2101    for (int i=0; i<rank0-axis_offset; i++) { shape2.push_back(tmpShape0[i]); } // First part of arg_0_Z    {         // block to limit the scope of out_index
2102    for (int i=axis_offset; i<rank1; i++)   { shape2.push_back(tmpShape1[i]); } // Last part of arg_1_Z       int out_index=0;
2103         for (int i=0; i<rank0-axis_offset; i++, ++out_index) { shape2[out_index]=tmpShape0[i]; } // First part of arg_0_Z
2104         for (int i=axis_offset; i<rank1; i++, ++out_index)   { shape2[out_index]=tmpShape1[i]; } // Last part of arg_1_Z
2105      }
2106    
2107    // Declare output Data object    // Declare output Data object
2108    Data res;    Data res;
2109    
2110    if      (arg_0_Z.isConstant()   && arg_1_Z.isConstant()) {    if      (arg_0_Z.isConstant()   && arg_1_Z.isConstant()) {
2111      res = Data(0.0, shape2, arg_1_Z.getFunctionSpace());    // DataConstant output      res = Data(0.0, shape2, arg_1_Z.getFunctionSpace());    // DataConstant output
2112      double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[0]);      double *ptr_0 = &(arg_0_Z.getDataAtOffset(0));
2113      double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[0]);      double *ptr_1 = &(arg_1_Z.getDataAtOffset(0));
2114      double *ptr_2 = &((res.getPointDataView().getData())[0]);      double *ptr_2 = &(res.getDataAtOffset(0));
2115      matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);      matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2116    }    }
2117    else if (arg_0_Z.isConstant()   && arg_1_Z.isTagged()) {    else if (arg_0_Z.isConstant()   && arg_1_Z.isTagged()) {
# Line 2264  escript::C_GeneralTensorProduct(Data& ar Line 2132  escript::C_GeneralTensorProduct(Data& ar
2132    
2133      // Prepare offset into DataConstant      // Prepare offset into DataConstant
2134      int offset_0 = tmp_0->getPointOffset(0,0);      int offset_0 = tmp_0->getPointOffset(0,0);
2135      double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);      double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2136      // Get the views      // Get the views
2137      DataArrayView view_1 = tmp_1->getDefaultValue();  //     DataArrayView view_1 = tmp_1->getDefaultValue();
2138      DataArrayView view_2 = tmp_2->getDefaultValue();  //     DataArrayView view_2 = tmp_2->getDefaultValue();
2139      // Get the pointers to the actual data  //     // Get the pointers to the actual data
2140      double *ptr_1 = &((view_1.getData())[0]);  //     double *ptr_1 = &((view_1.getData())[0]);
2141      double *ptr_2 = &((view_2.getData())[0]);  //     double *ptr_2 = &((view_2.getData())[0]);
2142    
2143        double *ptr_1 = &(tmp_1->getDefaultValue(0));
2144        double *ptr_2 = &(tmp_2->getDefaultValue(0));
2145    
2146    
2147      // Compute an MVP for the default      // Compute an MVP for the default
2148      matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);      matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2149      // Compute an MVP for each tag      // Compute an MVP for each tag
2150      const DataTagged::DataMapType& lookup_1=tmp_1->getTagLookup();      const DataTagged::DataMapType& lookup_1=tmp_1->getTagLookup();
2151      DataTagged::DataMapType::const_iterator i; // i->first is a tag, i->second is an offset into memory      DataTagged::DataMapType::const_iterator i; // i->first is a tag, i->second is an offset into memory
2152      for (i=lookup_1.begin();i!=lookup_1.end();i++) {      for (i=lookup_1.begin();i!=lookup_1.end();i++) {
2153        tmp_2->addTaggedValue(i->first,tmp_2->getDefaultValue());        tmp_2->addTag(i->first);
2154        DataArrayView view_1 = tmp_1->getDataPointByTag(i->first);  //       DataArrayView view_1 = tmp_1->getDataPointByTag(i->first);
2155        DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);  //       DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);
2156        double *ptr_1 = &view_1.getData(0);  //       double *ptr_1 = &view_1.getData(0);
2157        double *ptr_2 = &view_2.getData(0);  //       double *ptr_2 = &view_2.getData(0);
2158    
2159          double *ptr_1 = &(tmp_1->getDataByTag(i->first,0));
2160          double *ptr_2 = &(tmp_2->getDataByTag(i->first,0));
2161        
2162        matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);        matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2163      }      }
2164    
# Line 2304  escript::C_GeneralTensorProduct(Data& ar Line 2181  escript::C_GeneralTensorProduct(Data& ar
2181        for (dataPointNo_1 = 0; dataPointNo_1 < numDataPointsPerSample_1; dataPointNo_1++) {        for (dataPointNo_1 = 0; dataPointNo_1 < numDataPointsPerSample_1; dataPointNo_1++) {
2182          int offset_1 = tmp_1->getPointOffset(sampleNo_1,dataPointNo_1);          int offset_1 = tmp_1->getPointOffset(sampleNo_1,dataPointNo_1);
2183          int offset_2 = tmp_2->getPointOffset(sampleNo_1,dataPointNo_1);          int offset_2 = tmp_2->getPointOffset(sampleNo_1,dataPointNo_1);
2184          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2185          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);          double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2186          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2187          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2188        }        }
2189      }      }
# Line 2330  escript::C_GeneralTensorProduct(Data& ar Line 2207  escript::C_GeneralTensorProduct(Data& ar
2207    
2208      // Prepare offset into DataConstant      // Prepare offset into DataConstant
2209      int offset_1 = tmp_1->getPointOffset(0,0);      int offset_1 = tmp_1->getPointOffset(0,0);
2210      double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);      double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2211      // Get the views      // Get the views
2212      DataArrayView view_0 = tmp_0->getDefaultValue();  //     DataArrayView view_0 = tmp_0->getDefaultValue();
2213      DataArrayView view_2 = tmp_2->getDefaultValue();  //     DataArrayView view_2 = tmp_2->getDefaultValue();
2214      // Get the pointers to the actual data  //     // Get the pointers to the actual data
2215      double *ptr_0 = &((view_0.getData())[0]);  //     double *ptr_0 = &((view_0.getData())[0]);
2216      double *ptr_2 = &((view_2.getData())[0]);  //     double *ptr_2 = &((view_2.getData())[0]);
2217    
2218        double *ptr_0 = &(tmp_0->getDefaultValue(0));
2219        double *ptr_2 = &(tmp_2->getDefaultValue(0));
2220    
2221      // Compute an MVP for the default      // Compute an MVP for the default
2222      matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);      matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2223      // Compute an MVP for each tag      // Compute an MVP for each tag
2224      const DataTagged::DataMapType& lookup_0=tmp_0->getTagLookup();      const DataTagged::DataMapType& lookup_0=tmp_0->getTagLookup();
2225      DataTagged::DataMapType::const_iterator i; // i->first is a tag, i->second is an offset into memory      DataTagged::DataMapType::const_iterator i; // i->first is a tag, i->second is an offset into memory
2226      for (i=lookup_0.begin();i!=lookup_0.end();i++) {      for (i=lookup_0.begin();i!=lookup_0.end();i++) {
2227        tmp_2->addTaggedValue(i->first,tmp_2->getDefaultValue());  //      tmp_2->addTaggedValue(i->first,tmp_2->getDefaultValue());
2228        DataArrayView view_0 = tmp_0->getDataPointByTag(i->first);  //       DataArrayView view_0 = tmp_0->getDataPointByTag(i->first);
2229        DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);  //       DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);
2230        double *ptr_0 = &view_0.getData(0);  //       double *ptr_0 = &view_0.getData(0);
2231        double *ptr_2 = &view_2.getData(0);  //       double *ptr_2 = &view_2.getData(0);
2232    
2233          tmp_2->addTag(i->first);
2234          double *ptr_0 = &(tmp_0->getDataByTag(i->first,0));
2235          double *ptr_2 = &(tmp_2->getDataByTag(i->first,0));
2236        matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);        matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2237      }      }
2238    
# Line 2368  escript::C_GeneralTensorProduct(Data& ar Line 2253  escript::C_GeneralTensorProduct(Data& ar
2253      DataTagged* tmp_2=dynamic_cast<DataTagged*>(res.borrowData());      DataTagged* tmp_2=dynamic_cast<DataTagged*>(res.borrowData());
2254      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataTagged."); }      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataTagged."); }
2255    
2256      // Get the views  //     // Get the views
2257      DataArrayView view_0 = tmp_0->getDefaultValue();  //     DataArrayView view_0 = tmp_0->getDefaultValue();
2258      DataArrayView view_1 = tmp_1->getDefaultValue();  //     DataArrayView view_1 = tmp_1->getDefaultValue();
2259      DataArrayView view_2 = tmp_2->getDefaultValue();  //     DataArrayView view_2 = tmp_2->getDefaultValue();
2260      // Get the pointers to the actual data  //     // Get the pointers to the actual data
2261      double *ptr_0 = &((view_0.getData())[0]);  //     double *ptr_0 = &((view_0.getData())[0]);
2262      double *ptr_1 = &((view_1.getData())[0]);  //     double *ptr_1 = &((view_1.getData())[0]);
2263      double *ptr_2 = &((view_2.getData())[0]);  //     double *ptr_2 = &((view_2.getData())[0]);
2264    
2265        double *ptr_0 = &(tmp_0->getDefaultValue(0));
2266        double *ptr_1 = &(tmp_1->getDefaultValue(0));
2267        double *ptr_2 = &(tmp_2->getDefaultValue(0));
2268    
2269    
2270      // Compute an MVP for the default      // Compute an MVP for the default
2271      matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);      matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2272      // Merge the tags      // Merge the tags
# Line 2383  escript::C_GeneralTensorProduct(Data& ar Line 2274  escript::C_GeneralTensorProduct(Data& ar
2274      const DataTagged::DataMapType& lookup_0=tmp_0->getTagLookup();      const DataTagged::DataMapType& lookup_0=tmp_0->getTagLookup();
2275      const DataTagged::DataMapType& lookup_1=tmp_1->getTagLookup();      const DataTagged::DataMapType& lookup_1=tmp_1->getTagLookup();
2276      for (i=lookup_0.begin();i!=lookup_0.end();i++) {      for (i=lookup_0.begin();i!=lookup_0.end();i++) {
2277        tmp_2->addTaggedValue(i->first,tmp_2->getDefaultValue()); // use tmp_2 to get correct shape        tmp_2->addTag(i->first); // use tmp_2 to get correct shape
2278      }      }
2279      for (i=lookup_1.begin();i!=lookup_1.end();i++) {      for (i=lookup_1.begin();i!=lookup_1.end();i++) {
2280        tmp_2->addTaggedValue(i->first,tmp_2->getDefaultValue());        tmp_2->addTag(i->first);
2281      }      }
2282      // Compute an MVP for each tag      // Compute an MVP for each tag
2283      const DataTagged::DataMapType& lookup_2=tmp_2->getTagLookup();      const DataTagged::DataMapType& lookup_2=tmp_2->getTagLookup();
2284      for (i=lookup_2.begin();i!=lookup_2.end();i++) {      for (i=lookup_2.begin();i!=lookup_2.end();i++) {
2285        DataArrayView view_0 = tmp_0->getDataPointByTag(i->first);  //       DataArrayView view_0 = tmp_0->getDataPointByTag(i->first);
2286        DataArrayView view_1 = tmp_1->getDataPointByTag(i->first);  //       DataArrayView view_1 = tmp_1->getDataPointByTag(i->first);
2287        DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);  //       DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);
2288        double *ptr_0 = &view_0.getData(0);  //       double *ptr_0 = &view_0.getData(0);
2289        double *ptr_1 = &view_1.getData(0);  //       double *ptr_1 = &view_1.getData(0);
2290        double *ptr_2 = &view_2.getData(0);  //       double *ptr_2 = &view_2.getData(0);
2291    
2292          double *ptr_0 = &(tmp_0->getDataByTag(i->first,0));
2293          double *ptr_1 = &(tmp_1->getDataByTag(i->first,0));
2294          double *ptr_2 = &(tmp_2->getDataByTag(i->first,0));
2295    
2296        matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);        matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2297      }      }
2298    
# Line 2417  escript::C_GeneralTensorProduct(Data& ar Line 2313  escript::C_GeneralTensorProduct(Data& ar
2313      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)
2314      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {
2315        int offset_0 = tmp_0->getPointOffset(sampleNo_0,0); // They're all the same, so just use #0        int offset_0 = tmp_0->getPointOffset(sampleNo_0,0); // They're all the same, so just use #0
2316        double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);        double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2317        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {
2318          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);
2319          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2320          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);          double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2321          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2322          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2323        }        }
2324      }      }
# Line 2446  escript::C_GeneralTensorProduct(Data& ar Line 2342  escript::C_GeneralTensorProduct(Data& ar
2342        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {
2343          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);
2344          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2345          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2346          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);          double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2347          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2348          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2349        }        }
2350      }      }
# Line 2471  escript::C_GeneralTensorProduct(Data& ar Line 2367  escript::C_GeneralTensorProduct(Data& ar
2367      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)
2368      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {
2369        int offset_1 = tmp_1->getPointOffset(sampleNo_0,0);        int offset_1 = tmp_1->getPointOffset(sampleNo_0,0);
2370        double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);        double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2371        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {
2372          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);
2373          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2374          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2375          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2376          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2377        }        }
2378      }      }
# Line 2501  escript::C_GeneralTensorProduct(Data& ar Line 2397  escript::C_GeneralTensorProduct(Data& ar
2397          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);
2398          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);
2399          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2400          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2401          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);          double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2402          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2403          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2404        }        }
2405      }      }
# Line 2526  Data::borrowData() const Line 2422  Data::borrowData() const
2422  std::string  std::string
2423  Data::toString() const  Data::toString() const
2424  {  {
2425      static const DataArrayView::ValueType::size_type TOO_MANY_POINTS=80;      static const DataTypes::ValueType::size_type TOO_MANY_POINTS=80;
2426      if (getNumDataPoints()*getDataPointSize()>TOO_MANY_POINTS)      if (getNumDataPoints()*getDataPointSize()>TOO_MANY_POINTS)
2427      {      {
2428      stringstream temp;      stringstream temp;
# Line 2537  Data::toString() const Line 2433  Data::toString() const
2433  }  }
2434    
2435    
2436    
2437    DataTypes::ValueType::const_reference
2438    Data::getDataAtOffset(DataTypes::ValueType::size_type i) const
2439    {
2440        return m_data->getDataAtOffset(i);
2441    }
2442    
2443    
2444    DataTypes::ValueType::reference
2445    Data::getDataAtOffset(DataTypes::ValueType::size_type i)
2446    {
2447        return m_data->getDataAtOffset(i);
2448    }
2449    
2450    DataTypes::ValueType::const_reference
2451    Data::getDataPoint(int sampleNo, int dataPointNo) const
2452    {
2453        return m_data->getDataAtOffset(m_data->getPointOffset(sampleNo, dataPointNo));
2454    }
2455    
2456    
2457    DataTypes::ValueType::reference
2458    Data::getDataPoint(int sampleNo, int dataPointNo)
2459    {
2460        return m_data->getDataAtOffset(m_data->getPointOffset(sampleNo, dataPointNo));
2461    }
2462    
2463    
2464  /* Member functions specific to the MPI implementation */  /* Member functions specific to the MPI implementation */
2465    
2466  void  void

Legend:
Removed from v.1795  
changed lines
  Added in v.1796

  ViewVC Help
Powered by ViewVC 1.1.26