/[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

temp/escript/src/Data.cpp revision 1387 by trankine, Fri Jan 11 07:45:26 2008 UTC trunk/escript/src/Data.cpp revision 1799 by jfenwick, Wed Sep 17 06:33:18 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 243  Data::getShapeTuple() const Line 413  Data::getShapeTuple() const
413          throw DataException("Error - illegal Data rank.");          throw DataException("Error - illegal Data rank.");
414    }    }
415  }  }
416    
417    
418    // The different name is needed because boost has trouble with overloaded functions.
419    // It can't work out what type the function is based soley on its name.
420    // There are ways to fix this involving creating function pointer variables for each form
421    // but there doesn't seem to be a need given that the methods have the same name from the python point of view
422    Data*
423    Data::copySelf()
424    {
425       DataAbstract* temp=m_data->deepCopy();
426       return new Data(temp);
427    }
428    
429  void  void
430  Data::copy(const Data& other)  Data::copy(const Data& other)
431  {  {
432    //    DataAbstract* temp=other.m_data->deepCopy();
433    // Perform a deep copy    shared_ptr<DataAbstract> temp_data(temp);
434    {    m_data=temp_data;
     DataExpanded* temp=dynamic_cast<DataExpanded*>(other.m_data.get());  
     if (temp!=0) {  
       //  
       // Construct a DataExpanded copy  
       DataAbstract* newData=new DataExpanded(*temp);  
       shared_ptr<DataAbstract> temp_data(newData);  
       m_data=temp_data;  
       return;  
     }  
   }  
   {  
     DataTagged* temp=dynamic_cast<DataTagged*>(other.m_data.get());  
     if (temp!=0) {  
       //  
       // Construct a DataTagged copy  
       DataAbstract* newData=new DataTagged(*temp);  
       shared_ptr<DataAbstract> temp_data(newData);  
       m_data=temp_data;  
       return;  
     }  
   }  
   {  
     DataConstant* temp=dynamic_cast<DataConstant*>(other.m_data.get());  
     if (temp!=0) {  
       //  
       // Construct a DataConstant copy  
       DataAbstract* newData=new DataConstant(*temp);  
       shared_ptr<DataAbstract> temp_data(newData);  
       m_data=temp_data;  
       return;  
     }  
   }  
   {  
     DataEmpty* temp=dynamic_cast<DataEmpty*>(other.m_data.get());  
     if (temp!=0) {  
       //  
       // Construct a DataEmpty copy  
       DataAbstract* newData=new DataEmpty();  
       shared_ptr<DataAbstract> temp_data(newData);  
       m_data=temp_data;  
       return;  
     }  
   }  
   throw DataException("Error - Copy not implemented for this Data type.");  
435  }  }
436    
437    
# Line 495  Data::gradOn(const FunctionSpace& functi Line 634  Data::gradOn(const FunctionSpace& functi
634    double blocktimer_start = blocktimer_time();    double blocktimer_start = blocktimer_time();
635    if (functionspace.getDomain()!=getDomain())    if (functionspace.getDomain()!=getDomain())
636      throw DataException("Error - gradient cannot be calculated on different domains.");      throw DataException("Error - gradient cannot be calculated on different domains.");
637    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();    DataTypes::ShapeType grad_shape=getDataPointShape();
638    grad_shape.push_back(functionspace.getDim());    grad_shape.push_back(functionspace.getDim());
639    Data out(0.0,grad_shape,functionspace,true);    Data out(0.0,grad_shape,functionspace,true);
640    getDomain().setToGradient(out,*this);    getDomain().setToGradient(out,*this);
# Line 512  Data::grad() const Line 651  Data::grad() const
651  int  int
652  Data::getDataPointSize() const  Data::getDataPointSize() const
653  {  {
654    return getPointDataView().noValues();    return m_data->getNoValues();
655  }  }
656    
657  DataArrayView::ValueType::size_type  DataTypes::ValueType::size_type
658  Data::getLength() const  Data::getLength() const
659  {  {
660    return m_data->getLength();    return m_data->getLength();
661  }  }
662    
663  const DataArrayView::ShapeType&  // const DataTypes::ShapeType&
664  Data::getDataPointShape() const  // Data::getDataPointShape() const
665  {  // {
666    return getPointDataView().getShape();  //   return getPointDataView().getShape();
667  }  // }
668    
669    
670    
671    
# Line 538  Data:: getValueOfDataPoint(int dataPoint Line 678  Data:: getValueOfDataPoint(int dataPoint
678    //    //
679    // determine the rank and shape of each data point    // determine the rank and shape of each data point
680    int dataPointRank = getDataPointRank();    int dataPointRank = getDataPointRank();
681    DataArrayView::ShapeType dataPointShape = getDataPointShape();    const DataTypes::ShapeType& dataPointShape = getDataPointShape();
682    
683    //    //
684    // create the numeric array to be returned    // create the numeric array to be returned
# Line 548  Data:: getValueOfDataPoint(int dataPoint Line 688  Data:: getValueOfDataPoint(int dataPoint
688    // the shape of the returned numeric array will be the same    // the shape of the returned numeric array will be the same
689    // as that of the data point    // as that of the data point
690    int arrayRank = dataPointRank;    int arrayRank = dataPointRank;
691    DataArrayView::ShapeType arrayShape = dataPointShape;    const DataTypes::ShapeType& arrayShape = dataPointShape;
692    
693    //    //
694    // 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 724  Data:: getValueOfDataPoint(int dataPoint
724         }         }
725         // TODO: global error handling         // TODO: global error handling
726         // create a view of the data if it is stored locally         // create a view of the data if it is stored locally
727         DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);  //       DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);
728           DataTypes::ValueType::size_type offset=getDataOffset(sampleNo, dataPointNoInSample);
729    
730    
731         switch( dataPointRank ){         switch( dataPointRank ){
732              case 0 :              case 0 :
733                  numArray[0] = dataPointView();                  numArray[0] = getDataAtOffset(offset);
734                  break;                  break;
735              case 1 :              case 1 :
736                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
737                      numArray[i]=dataPointView(i);                      numArray[i]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i));
738                  break;                  break;
739              case 2 :              case 2 :
740                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
741                      for( j=0; j<dataPointShape[1]; j++)                      for( j=0; j<dataPointShape[1]; j++)
742                          numArray[make_tuple(i,j)]=dataPointView(i,j);                          numArray[make_tuple(i,j)]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j));
743                  break;                  break;
744              case 3 :              case 3 :
745                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
746                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
747                          for( k=0; k<dataPointShape[2]; k++)                          for( k=0; k<dataPointShape[2]; k++)
748                              numArray[make_tuple(i,j,k)]=dataPointView(i,j,k);                              numArray[make_tuple(i,j,k)]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j,k));
749                  break;                  break;
750              case 4 :              case 4 :
751                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
752                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
753                          for( k=0; k<dataPointShape[2]; k++ )                          for( k=0; k<dataPointShape[2]; k++ )
754                              for( l=0; l<dataPointShape[3]; l++)                              for( l=0; l<dataPointShape[3]; l++)
755                                  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));
756                  break;                  break;
757      }      }
758    }    }
# Line 619  Data:: getValueOfDataPoint(int dataPoint Line 761  Data:: getValueOfDataPoint(int dataPoint
761    return numArray;    return numArray;
762    
763  }  }
764    
765  void  void
766  Data::setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object)  Data::setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object)
767  {  {
# Line 689  Data::getValueOfGlobalDataPoint(int proc Line 832  Data::getValueOfGlobalDataPoint(int proc
832    //    //
833    // determine the rank and shape of each data point    // determine the rank and shape of each data point
834    int dataPointRank = getDataPointRank();    int dataPointRank = getDataPointRank();
835    DataArrayView::ShapeType dataPointShape = getDataPointShape();    const DataTypes::ShapeType& dataPointShape = getDataPointShape();
836    
837    //    //
838    // create the numeric array to be returned    // create the numeric array to be returned
# Line 699  Data::getValueOfGlobalDataPoint(int proc Line 842  Data::getValueOfGlobalDataPoint(int proc
842    // the shape of the returned numeric array will be the same    // the shape of the returned numeric array will be the same
843    // as that of the data point    // as that of the data point
844    int arrayRank = dataPointRank;    int arrayRank = dataPointRank;
845    DataArrayView::ShapeType arrayShape = dataPointShape;    const DataTypes::ShapeType& arrayShape = dataPointShape;
846    
847    //    //
848    // 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 888  Data::getValueOfGlobalDataPoint(int proc
888                  }                  }
889                  // TODO: global error handling                  // TODO: global error handling
890          // create a view of the data if it is stored locally          // create a view of the data if it is stored locally
891          DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);          //DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);
892            DataTypes::ValueType::size_type offset=getDataOffset(sampleNo, dataPointNoInSample);
893    
894          // pack the data from the view into tmpData for MPI communication          // pack the data from the view into tmpData for MPI communication
895          pos=0;          pos=0;
896          switch( dataPointRank ){          switch( dataPointRank ){
897              case 0 :              case 0 :
898                  tmpData[0] = dataPointView();                  tmpData[0] = getDataAtOffset(offset);
899                  break;                  break;
900              case 1 :              case 1 :
901                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
902                      tmpData[i]=dataPointView(i);                      tmpData[i]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i));
903                  break;                  break;
904              case 2 :              case 2 :
905                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
906                      for( j=0; j<dataPointShape[1]; j++, pos++ )                      for( j=0; j<dataPointShape[1]; j++, pos++ )
907                          tmpData[pos]=dataPointView(i,j);                          tmpData[pos]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j));
908                  break;                  break;
909              case 3 :              case 3 :
910                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
911                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
912                          for( k=0; k<dataPointShape[2]; k++, pos++ )                          for( k=0; k<dataPointShape[2]; k++, pos++ )
913                              tmpData[pos]=dataPointView(i,j,k);                              tmpData[pos]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j,k));
914                  break;                  break;
915              case 4 :              case 4 :
916                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
917                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
918                          for( k=0; k<dataPointShape[2]; k++ )                          for( k=0; k<dataPointShape[2]; k++ )
919                              for( l=0; l<dataPointShape[3]; l++, pos++ )                              for( l=0; l<dataPointShape[3]; l++, pos++ )
920                                  tmpData[pos]=dataPointView(i,j,k,l);                                  tmpData[pos]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j,k,l));
921                  break;                  break;
922          }          }
923              }              }
# Line 825  Data::integrate() const Line 969  Data::integrate() const
969  {  {
970    int index;    int index;
971    int rank = getDataPointRank();    int rank = getDataPointRank();
972    DataArrayView::ShapeType shape = getDataPointShape();    DataTypes::ShapeType shape = getDataPointShape();
973    int dataPointSize = getDataPointSize();    int dataPointSize = getDataPointSize();
974    
975    //    //
# Line 1052  Data::sqrt() const Line 1196  Data::sqrt() const
1196  double  double
1197  Data::Lsup() const  Data::Lsup() const
1198  {  {
1199    double localValue, globalValue;    double localValue;
1200    //    //
1201    // set the initial absolute maximum value to zero    // set the initial absolute maximum value to zero
1202    
1203    AbsMax abs_max_func;    AbsMax abs_max_func;
1204    localValue = algorithm(abs_max_func,0);    localValue = algorithm(abs_max_func,0);
1205  #ifdef PASO_MPI  #ifdef PASO_MPI
1206      double globalValue;
1207    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
1208    return globalValue;    return globalValue;
1209  #else  #else
# Line 1069  Data::Lsup() const Line 1214  Data::Lsup() const
1214  double  double
1215  Data::sup() const  Data::sup() const
1216  {  {
1217    double localValue, globalValue;    double localValue;
1218    //    //
1219    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1220    FMax fmax_func;    FMax fmax_func;
1221    localValue = algorithm(fmax_func,numeric_limits<double>::max()*-1);    localValue = algorithm(fmax_func,numeric_limits<double>::max()*-1);
1222  #ifdef PASO_MPI  #ifdef PASO_MPI
1223      double globalValue;
1224    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
1225    return globalValue;    return globalValue;
1226  #else  #else
# Line 1085  Data::sup() const Line 1231  Data::sup() const
1231  double  double
1232  Data::inf() const  Data::inf() const
1233  {  {
1234    double localValue, globalValue;    double localValue;
1235    //    //
1236    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1237    FMin fmin_func;    FMin fmin_func;
1238    localValue = algorithm(fmin_func,numeric_limits<double>::max());    localValue = algorithm(fmin_func,numeric_limits<double>::max());
1239  #ifdef PASO_MPI  #ifdef PASO_MPI
1240      double globalValue;
1241    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD );    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD );
1242    return globalValue;    return globalValue;
1243  #else  #else
# Line 1122  Data Line 1269  Data
1269  Data::swapaxes(const int axis0, const int axis1) const  Data::swapaxes(const int axis0, const int axis1) const
1270  {  {
1271       int axis0_tmp,axis1_tmp;       int axis0_tmp,axis1_tmp;
1272       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1273       DataArrayView::ShapeType ev_shape;       DataTypes::ShapeType ev_shape;
1274       // 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]
1275       // 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)
1276       int rank=getDataPointRank();       int rank=getDataPointRank();
# Line 1166  Data Line 1313  Data
1313  Data::symmetric() const  Data::symmetric() const
1314  {  {
1315       // check input       // check input
1316       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1317       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1318          if(s[0] != s[1])          if(s[0] != s[1])
1319             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 1188  Data Line 1335  Data
1335  Data::nonsymmetric() const  Data::nonsymmetric() const
1336  {  {
1337       // check input       // check input
1338       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1339       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1340          if(s[0] != s[1])          if(s[0] != s[1])
1341             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.");
1342          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1343          ev_shape.push_back(s[0]);          ev_shape.push_back(s[0]);
1344          ev_shape.push_back(s[1]);          ev_shape.push_back(s[1]);
1345          Data ev(0.,ev_shape,getFunctionSpace());          Data ev(0.,ev_shape,getFunctionSpace());
# Line 1203  Data::nonsymmetric() const Line 1350  Data::nonsymmetric() const
1350       else if (getDataPointRank()==4) {       else if (getDataPointRank()==4) {
1351          if(!(s[0] == s[2] && s[1] == s[3]))          if(!(s[0] == s[2] && s[1] == s[3]))
1352             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.");
1353          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1354          ev_shape.push_back(s[0]);          ev_shape.push_back(s[0]);
1355          ev_shape.push_back(s[1]);          ev_shape.push_back(s[1]);
1356          ev_shape.push_back(s[2]);          ev_shape.push_back(s[2]);
# Line 1221  Data::nonsymmetric() const Line 1368  Data::nonsymmetric() const
1368  Data  Data
1369  Data::trace(int axis_offset) const  Data::trace(int axis_offset) const
1370  {  {
1371       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1372       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1373          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1374          Data ev(0.,ev_shape,getFunctionSpace());          Data ev(0.,ev_shape,getFunctionSpace());
1375          ev.typeMatchRight(*this);          ev.typeMatchRight(*this);
1376          m_data->trace(ev.m_data.get(), axis_offset);          m_data->trace(ev.m_data.get(), axis_offset);
1377          return ev;          return ev;
1378       }       }
1379       if (getDataPointRank()==3) {       if (getDataPointRank()==3) {
1380          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1381          if (axis_offset==0) {          if (axis_offset==0) {
1382            int s2=s[2];            int s2=s[2];
1383            ev_shape.push_back(s2);            ev_shape.push_back(s2);
# Line 1245  Data::trace(int axis_offset) const Line 1392  Data::trace(int axis_offset) const
1392          return ev;          return ev;
1393       }       }
1394       if (getDataPointRank()==4) {       if (getDataPointRank()==4) {
1395          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1396          if (axis_offset==0) {          if (axis_offset==0) {
1397            ev_shape.push_back(s[2]);            ev_shape.push_back(s[2]);
1398            ev_shape.push_back(s[3]);            ev_shape.push_back(s[3]);
# Line 1271  Data::trace(int axis_offset) const Line 1418  Data::trace(int axis_offset) const
1418  Data  Data
1419  Data::transpose(int axis_offset) const  Data::transpose(int axis_offset) const
1420  {  {
1421       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1422       DataArrayView::ShapeType ev_shape;       DataTypes::ShapeType ev_shape;
1423       // 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]
1424       // 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)
1425       int rank=getDataPointRank();       int rank=getDataPointRank();
# Line 1293  Data Line 1440  Data
1440  Data::eigenvalues() const  Data::eigenvalues() const
1441  {  {
1442       // check input       // check input
1443       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1444       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
1445          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.");
1446       if(s[0] != s[1])       if(s[0] != s[1])
1447          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.");
1448       // create return       // create return
1449       DataArrayView::ShapeType ev_shape(1,s[0]);       DataTypes::ShapeType ev_shape(1,s[0]);
1450       Data ev(0.,ev_shape,getFunctionSpace());       Data ev(0.,ev_shape,getFunctionSpace());
1451       ev.typeMatchRight(*this);       ev.typeMatchRight(*this);
1452       m_data->eigenvalues(ev.m_data.get());       m_data->eigenvalues(ev.m_data.get());
# Line 1309  Data::eigenvalues() const Line 1456  Data::eigenvalues() const
1456  const boost::python::tuple  const boost::python::tuple
1457  Data::eigenvalues_and_eigenvectors(const double tol) const  Data::eigenvalues_and_eigenvectors(const double tol) const
1458  {  {
1459       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1460       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
1461          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.");
1462       if(s[0] != s[1])       if(s[0] != s[1])
1463          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.");
1464       // create return       // create return
1465       DataArrayView::ShapeType ev_shape(1,s[0]);       DataTypes::ShapeType ev_shape(1,s[0]);
1466       Data ev(0.,ev_shape,getFunctionSpace());       Data ev(0.,ev_shape,getFunctionSpace());
1467       ev.typeMatchRight(*this);       ev.typeMatchRight(*this);
1468       DataArrayView::ShapeType V_shape(2,s[0]);       DataTypes::ShapeType V_shape(2,s[0]);
1469       Data V(0.,V_shape,getFunctionSpace());       Data V(0.,V_shape,getFunctionSpace());
1470       V.typeMatchRight(*this);       V.typeMatchRight(*this);
1471       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 1360  Data::calc_minGlobalDataPoint(int& ProcN Line 1507  Data::calc_minGlobalDataPoint(int& ProcN
1507      #pragma omp for private(i,j) schedule(static)      #pragma omp for private(i,j) schedule(static)
1508      for (i=0; i<numSamples; i++) {      for (i=0; i<numSamples; i++) {
1509        for (j=0; j<numDPPSample; j++) {        for (j=0; j<numDPPSample; j++) {
1510          next=temp.getDataPoint(i,j)();          next=temp.getDataAtOffset(temp.getDataOffset(i,j));
1511          if (next<local_min) {          if (next<local_min) {
1512            local_min=next;            local_min=next;
1513            local_lowi=i;            local_lowi=i;
# Line 1378  Data::calc_minGlobalDataPoint(int& ProcN Line 1525  Data::calc_minGlobalDataPoint(int& ProcN
1525    
1526  #ifdef PASO_MPI  #ifdef PASO_MPI
1527      // determine the processor on which the minimum occurs      // determine the processor on which the minimum occurs
1528      next = temp.getDataPoint(lowi,lowj)();      next = temp.getDataPoint(lowi,lowj);
1529      int lowProc = 0;      int lowProc = 0;
1530      double *globalMins = new double[get_MPISize()+1];      double *globalMins = new double[get_MPISize()+1];
1531      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 1663  escript::operator/(const boost::python:: Line 1810  escript::operator/(const boost::python::
1810  Data  Data
1811  Data::getItem(const boost::python::object& key) const  Data::getItem(const boost::python::object& key) const
1812  {  {
1813    const DataArrayView& view=getPointDataView();  //  const DataArrayView& view=getPointDataView();
1814    
1815    DataArrayView::RegionType slice_region=view.getSliceRegion(key);    DataTypes::RegionType slice_region=DataTypes::getSliceRegion(getDataPointShape(),key);
1816    
1817    if (slice_region.size()!=view.getRank()) {    if (slice_region.size()!=getDataPointRank()) {
1818      throw DataException("Error - slice size does not match Data rank.");      throw DataException("Error - slice size does not match Data rank.");
1819    }    }
1820    
# Line 1677  Data::getItem(const boost::python::objec Line 1824  Data::getItem(const boost::python::objec
1824  /* TODO */  /* TODO */
1825  /* global reduction */  /* global reduction */
1826  Data  Data
1827  Data::getSlice(const DataArrayView::RegionType& region) const  Data::getSlice(const DataTypes::RegionType& region) const
1828  {  {
1829    return Data(*this,region);    return Data(*this,region);
1830  }  }
# Line 1696  void Line 1843  void
1843  Data::setItemD(const boost::python::object& key,  Data::setItemD(const boost::python::object& key,
1844                 const Data& value)                 const Data& value)
1845  {  {
1846    const DataArrayView& view=getPointDataView();  //  const DataArrayView& view=getPointDataView();
1847    
1848    DataArrayView::RegionType slice_region=view.getSliceRegion(key);    DataTypes::RegionType slice_region=DataTypes::getSliceRegion(getDataPointShape(),key);
1849    if (slice_region.size()!=view.getRank()) {    if (slice_region.size()!=getDataPointRank()) {
1850      throw DataException("Error - slice size does not match Data rank.");      throw DataException("Error - slice size does not match Data rank.");
1851    }    }
1852    if (getFunctionSpace()!=value.getFunctionSpace()) {    if (getFunctionSpace()!=value.getFunctionSpace()) {
# Line 1711  Data::setItemD(const boost::python::obje Line 1858  Data::setItemD(const boost::python::obje
1858    
1859  void  void
1860  Data::setSlice(const Data& value,  Data::setSlice(const Data& value,
1861                 const DataArrayView::RegionType& region)                 const DataTypes::RegionType& region)
1862  {  {
1863    if (isProtected()) {    if (isProtected()) {
1864          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
# Line 1774  Data::setTaggedValue(int tagKey, Line 1921  Data::setTaggedValue(int tagKey,
1921    
1922    
1923    // extract the shape of the numarray    // extract the shape of the numarray
1924    DataArrayView::ShapeType tempShape;    DataTypes::ShapeType tempShape;
1925    for (int i=0; i < asNumArray.getrank(); i++) {    for (int i=0; i < asNumArray.getrank(); i++) {
1926      tempShape.push_back(extract<int>(asNumArray.getshape()[i]));      tempShape.push_back(extract<int>(asNumArray.getshape()[i]));
1927    }    }
1928    
1929    // get the space for the data vector    // get the space for the data vector
1930    int len = DataArrayView::noValues(tempShape);  //   int len = DataTypes::noValues(tempShape);
1931    DataVector temp_data(len, 0.0, len);  //   DataVector temp_data(len, 0.0, len);
1932    DataArrayView temp_dataView(temp_data, tempShape);  //   DataArrayView temp_dataView(temp_data, tempShape);
1933    temp_dataView.copy(asNumArray);  //   temp_dataView.copy(asNumArray);
1934    
1935      DataVector temp_data2;
1936      temp_data2.copyFromNumArray(asNumArray);
1937    
1938    //    //
1939    // Call DataAbstract::setTaggedValue    // Call DataAbstract::setTaggedValue
1940    m_data->setTaggedValue(tagKey,temp_dataView);    //m_data->setTaggedValue(tagKey,temp_dataView);
1941    
1942        m_data->setTaggedValue(tagKey,tempShape, temp_data2);
1943  }  }
1944    
1945    // void
1946    // Data::setTaggedValueFromCPP(int tagKey,
1947    //                             const DataArrayView& value)
1948    // {
1949    //   if (isProtected()) {
1950    //         throw DataException("Error - attempt to update protected Data object.");
1951    //   }
1952    //   //
1953    //   // Ensure underlying data object is of type DataTagged
1954    //   if (isConstant()) tag();
1955    //
1956    //   //
1957    //   // Call DataAbstract::setTaggedValue
1958    //   m_data->setTaggedValue(tagKey,value);
1959    // }
1960    
1961  void  void
1962  Data::setTaggedValueFromCPP(int tagKey,  Data::setTaggedValueFromCPP(int tagKey,
1963                              const DataArrayView& value)                  const DataTypes::ShapeType& pointshape,
1964                                const DataTypes::ValueType& value,
1965                    int dataOffset)
1966  {  {
1967    if (isProtected()) {    if (isProtected()) {
1968          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
# Line 1803  Data::setTaggedValueFromCPP(int tagKey, Line 1973  Data::setTaggedValueFromCPP(int tagKey,
1973    
1974    //    //
1975    // Call DataAbstract::setTaggedValue    // Call DataAbstract::setTaggedValue
1976    m_data->setTaggedValue(tagKey,value);    m_data->setTaggedValue(tagKey,pointshape, value, dataOffset);
1977  }  }
1978    
1979  int  int
1980  Data::getTagNumber(int dpno)  Data::getTagNumber(int dpno)
1981  {  {
1982    return getFunctionSpace().getTagFromSampleNo(dpno);    return getFunctionSpace().getTagFromDataPointNo(dpno);
1983  }  }
1984    
 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;  
 }  
1985    
1986  ostream& escript::operator<<(ostream& o, const Data& data)  ostream& escript::operator<<(ostream& o, const Data& data)
1987  {  {
# Line 2183  escript::C_GeneralTensorProduct(Data& ar Line 2019  escript::C_GeneralTensorProduct(Data& ar
2019    // Get rank and shape of inputs    // Get rank and shape of inputs
2020    int rank0 = arg_0_Z.getDataPointRank();    int rank0 = arg_0_Z.getDataPointRank();
2021    int rank1 = arg_1_Z.getDataPointRank();    int rank1 = arg_1_Z.getDataPointRank();
2022    DataArrayView::ShapeType shape0 = arg_0_Z.getDataPointShape();    const DataTypes::ShapeType& shape0 = arg_0_Z.getDataPointShape();
2023    DataArrayView::ShapeType shape1 = arg_1_Z.getDataPointShape();    const DataTypes::ShapeType& shape1 = arg_1_Z.getDataPointShape();
2024    
2025    // Prepare for the loops of the product and verify compatibility of shapes    // Prepare for the loops of the product and verify compatibility of shapes
2026    int start0=0, start1=0;    int start0=0, start1=0;
# Line 2193  escript::C_GeneralTensorProduct(Data& ar Line 2029  escript::C_GeneralTensorProduct(Data& ar
2029    else if (transpose == 2)  { start1 = rank1-axis_offset; }    else if (transpose == 2)  { start1 = rank1-axis_offset; }
2030    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"); }
2031    
2032    
2033    // Adjust the shapes for transpose    // Adjust the shapes for transpose
2034    DataArrayView::ShapeType tmpShape0;    DataTypes::ShapeType tmpShape0(rank0);    // pre-sizing the vectors rather
2035    DataArrayView::ShapeType tmpShape1;    DataTypes::ShapeType tmpShape1(rank1);    // than using push_back
2036    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]; }
2037    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]; }
2038    
2039  #if 0  #if 0
2040    // For debugging: show shape after transpose    // For debugging: show shape after transpose
# Line 2228  escript::C_GeneralTensorProduct(Data& ar Line 2065  escript::C_GeneralTensorProduct(Data& ar
2065      SR *= tmpShape1[i];      SR *= tmpShape1[i];
2066    }    }
2067    
2068    // Define the shape of the output    // Define the shape of the output (rank of shape is the sum of the loop ranges below)
2069    DataArrayView::ShapeType shape2;    DataTypes::ShapeType shape2(rank0+rank1-2*axis_offset);  
2070    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
2071    for (int i=axis_offset; i<rank1; i++)   { shape2.push_back(tmpShape1[i]); } // Last part of arg_1_Z       int out_index=0;
2072         for (int i=0; i<rank0-axis_offset; i++, ++out_index) { shape2[out_index]=tmpShape0[i]; } // First part of arg_0_Z
2073         for (int i=axis_offset; i<rank1; i++, ++out_index)   { shape2[out_index]=tmpShape1[i]; } // Last part of arg_1_Z
2074      }
2075    
2076    // Declare output Data object    // Declare output Data object
2077    Data res;    Data res;
2078    
2079    if      (arg_0_Z.isConstant()   && arg_1_Z.isConstant()) {    if      (arg_0_Z.isConstant()   && arg_1_Z.isConstant()) {
2080      res = Data(0.0, shape2, arg_1_Z.getFunctionSpace());    // DataConstant output      res = Data(0.0, shape2, arg_1_Z.getFunctionSpace());    // DataConstant output
2081      double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[0]);      double *ptr_0 = &(arg_0_Z.getDataAtOffset(0));
2082      double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[0]);      double *ptr_1 = &(arg_1_Z.getDataAtOffset(0));
2083      double *ptr_2 = &((res.getPointDataView().getData())[0]);      double *ptr_2 = &(res.getDataAtOffset(0));
2084      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);
2085    }    }
2086    else if (arg_0_Z.isConstant()   && arg_1_Z.isTagged()) {    else if (arg_0_Z.isConstant()   && arg_1_Z.isTagged()) {
# Line 2261  escript::C_GeneralTensorProduct(Data& ar Line 2101  escript::C_GeneralTensorProduct(Data& ar
2101    
2102      // Prepare offset into DataConstant      // Prepare offset into DataConstant
2103      int offset_0 = tmp_0->getPointOffset(0,0);      int offset_0 = tmp_0->getPointOffset(0,0);
2104      double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);      double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2105      // Get the views      // Get the views
2106      DataArrayView view_1 = tmp_1->getDefaultValue();  //     DataArrayView view_1 = tmp_1->getDefaultValue();
2107      DataArrayView view_2 = tmp_2->getDefaultValue();  //     DataArrayView view_2 = tmp_2->getDefaultValue();
2108      // Get the pointers to the actual data  //     // Get the pointers to the actual data
2109      double *ptr_1 = &((view_1.getData())[0]);  //     double *ptr_1 = &((view_1.getData())[0]);
2110      double *ptr_2 = &((view_2.getData())[0]);  //     double *ptr_2 = &((view_2.getData())[0]);
2111    
2112        double *ptr_1 = &(tmp_1->getDefaultValue(0));
2113        double *ptr_2 = &(tmp_2->getDefaultValue(0));
2114    
2115    
2116      // Compute an MVP for the default      // Compute an MVP for the default
2117      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);
2118      // Compute an MVP for each tag      // Compute an MVP for each tag
2119      const DataTagged::DataMapType& lookup_1=tmp_1->getTagLookup();      const DataTagged::DataMapType& lookup_1=tmp_1->getTagLookup();
2120      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
2121      for (i=lookup_1.begin();i!=lookup_1.end();i++) {      for (i=lookup_1.begin();i!=lookup_1.end();i++) {
2122        tmp_2->addTaggedValue(i->first,tmp_2->getDefaultValue());        tmp_2->addTag(i->first);
2123        DataArrayView view_1 = tmp_1->getDataPointByTag(i->first);  //       DataArrayView view_1 = tmp_1->getDataPointByTag(i->first);
2124        DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);  //       DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);
2125        double *ptr_1 = &view_1.getData(0);  //       double *ptr_1 = &view_1.getData(0);
2126        double *ptr_2 = &view_2.getData(0);  //       double *ptr_2 = &view_2.getData(0);
2127    
2128          double *ptr_1 = &(tmp_1->getDataByTag(i->first,0));
2129          double *ptr_2 = &(tmp_2->getDataByTag(i->first,0));
2130        
2131        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);
2132      }      }
2133    
# Line 2301  escript::C_GeneralTensorProduct(Data& ar Line 2150  escript::C_GeneralTensorProduct(Data& ar
2150        for (dataPointNo_1 = 0; dataPointNo_1 < numDataPointsPerSample_1; dataPointNo_1++) {        for (dataPointNo_1 = 0; dataPointNo_1 < numDataPointsPerSample_1; dataPointNo_1++) {
2151          int offset_1 = tmp_1->getPointOffset(sampleNo_1,dataPointNo_1);          int offset_1 = tmp_1->getPointOffset(sampleNo_1,dataPointNo_1);
2152          int offset_2 = tmp_2->getPointOffset(sampleNo_1,dataPointNo_1);          int offset_2 = tmp_2->getPointOffset(sampleNo_1,dataPointNo_1);
2153          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2154          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);          double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2155          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2156          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);
2157        }        }
2158      }      }
# Line 2327  escript::C_GeneralTensorProduct(Data& ar Line 2176  escript::C_GeneralTensorProduct(Data& ar
2176    
2177      // Prepare offset into DataConstant      // Prepare offset into DataConstant
2178      int offset_1 = tmp_1->getPointOffset(0,0);      int offset_1 = tmp_1->getPointOffset(0,0);
2179      double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);      double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2180      // Get the views      // Get the views
2181      DataArrayView view_0 = tmp_0->getDefaultValue();  //     DataArrayView view_0 = tmp_0->getDefaultValue();
2182      DataArrayView view_2 = tmp_2->getDefaultValue();  //     DataArrayView view_2 = tmp_2->getDefaultValue();
2183      // Get the pointers to the actual data  //     // Get the pointers to the actual data
2184      double *ptr_0 = &((view_0.getData())[0]);  //     double *ptr_0 = &((view_0.getData())[0]);
2185      double *ptr_2 = &((view_2.getData())[0]);  //     double *ptr_2 = &((view_2.getData())[0]);
2186    
2187        double *ptr_0 = &(tmp_0->getDefaultValue(0));
2188        double *ptr_2 = &(tmp_2->getDefaultValue(0));
2189    
2190      // Compute an MVP for the default      // Compute an MVP for the default
2191      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);
2192      // Compute an MVP for each tag      // Compute an MVP for each tag
2193      const DataTagged::DataMapType& lookup_0=tmp_0->getTagLookup();      const DataTagged::DataMapType& lookup_0=tmp_0->getTagLookup();
2194      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
2195      for (i=lookup_0.begin();i!=lookup_0.end();i++) {      for (i=lookup_0.begin();i!=lookup_0.end();i++) {
2196        tmp_2->addTaggedValue(i->first,tmp_2->getDefaultValue());  //      tmp_2->addTaggedValue(i->first,tmp_2->getDefaultValue());
2197        DataArrayView view_0 = tmp_0->getDataPointByTag(i->first);  //       DataArrayView view_0 = tmp_0->getDataPointByTag(i->first);
2198        DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);  //       DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);
2199        double *ptr_0 = &view_0.getData(0);  //       double *ptr_0 = &view_0.getData(0);
2200        double *ptr_2 = &view_2.getData(0);  //       double *ptr_2 = &view_2.getData(0);
2201    
2202          tmp_2->addTag(i->first);
2203          double *ptr_0 = &(tmp_0->getDataByTag(i->first,0));
2204          double *ptr_2 = &(tmp_2->getDataByTag(i->first,0));
2205        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);
2206      }      }
2207    
# Line 2365  escript::C_GeneralTensorProduct(Data& ar Line 2222  escript::C_GeneralTensorProduct(Data& ar
2222      DataTagged* tmp_2=dynamic_cast<DataTagged*>(res.borrowData());      DataTagged* tmp_2=dynamic_cast<DataTagged*>(res.borrowData());
2223      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataTagged."); }      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataTagged."); }
2224    
2225      // Get the views  //     // Get the views
2226      DataArrayView view_0 = tmp_0->getDefaultValue();  //     DataArrayView view_0 = tmp_0->getDefaultValue();
2227      DataArrayView view_1 = tmp_1->getDefaultValue();  //     DataArrayView view_1 = tmp_1->getDefaultValue();
2228      DataArrayView view_2 = tmp_2->getDefaultValue();  //     DataArrayView view_2 = tmp_2->getDefaultValue();
2229      // Get the pointers to the actual data  //     // Get the pointers to the actual data
2230      double *ptr_0 = &((view_0.getData())[0]);  //     double *ptr_0 = &((view_0.getData())[0]);
2231      double *ptr_1 = &((view_1.getData())[0]);  //     double *ptr_1 = &((view_1.getData())[0]);
2232      double *ptr_2 = &((view_2.getData())[0]);  //     double *ptr_2 = &((view_2.getData())[0]);
2233    
2234        double *ptr_0 = &(tmp_0->getDefaultValue(0));
2235        double *ptr_1 = &(tmp_1->getDefaultValue(0));
2236        double *ptr_2 = &(tmp_2->getDefaultValue(0));
2237    
2238    
2239      // Compute an MVP for the default      // Compute an MVP for the default
2240      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);
2241      // Merge the tags      // Merge the tags
# Line 2380  escript::C_GeneralTensorProduct(Data& ar Line 2243  escript::C_GeneralTensorProduct(Data& ar
2243      const DataTagged::DataMapType& lookup_0=tmp_0->getTagLookup();      const DataTagged::DataMapType& lookup_0=tmp_0->getTagLookup();
2244      const DataTagged::DataMapType& lookup_1=tmp_1->getTagLookup();      const DataTagged::DataMapType& lookup_1=tmp_1->getTagLookup();
2245      for (i=lookup_0.begin();i!=lookup_0.end();i++) {      for (i=lookup_0.begin();i!=lookup_0.end();i++) {
2246        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
2247      }      }
2248      for (i=lookup_1.begin();i!=lookup_1.end();i++) {      for (i=lookup_1.begin();i!=lookup_1.end();i++) {
2249        tmp_2->addTaggedValue(i->first,tmp_2->getDefaultValue());        tmp_2->addTag(i->first);
2250      }      }
2251      // Compute an MVP for each tag      // Compute an MVP for each tag
2252      const DataTagged::DataMapType& lookup_2=tmp_2->getTagLookup();      const DataTagged::DataMapType& lookup_2=tmp_2->getTagLookup();
2253      for (i=lookup_2.begin();i!=lookup_2.end();i++) {      for (i=lookup_2.begin();i!=lookup_2.end();i++) {
2254        DataArrayView view_0 = tmp_0->getDataPointByTag(i->first);  //       DataArrayView view_0 = tmp_0->getDataPointByTag(i->first);
2255        DataArrayView view_1 = tmp_1->getDataPointByTag(i->first);  //       DataArrayView view_1 = tmp_1->getDataPointByTag(i->first);
2256        DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);  //       DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);
2257        double *ptr_0 = &view_0.getData(0);  //       double *ptr_0 = &view_0.getData(0);
2258        double *ptr_1 = &view_1.getData(0);  //       double *ptr_1 = &view_1.getData(0);
2259        double *ptr_2 = &view_2.getData(0);  //       double *ptr_2 = &view_2.getData(0);
2260    
2261          double *ptr_0 = &(tmp_0->getDataByTag(i->first,0));
2262          double *ptr_1 = &(tmp_1->getDataByTag(i->first,0));
2263          double *ptr_2 = &(tmp_2->getDataByTag(i->first,0));
2264    
2265        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);
2266      }      }
2267    
# Line 2414  escript::C_GeneralTensorProduct(Data& ar Line 2282  escript::C_GeneralTensorProduct(Data& ar
2282      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)
2283      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {
2284        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
2285        double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);        double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2286        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {
2287          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);
2288          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2289          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);          double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2290          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2291          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);
2292        }        }
2293      }      }
# Line 2443  escript::C_GeneralTensorProduct(Data& ar Line 2311  escript::C_GeneralTensorProduct(Data& ar
2311        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {
2312          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);
2313          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2314          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2315          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);          double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2316          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2317          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);
2318        }        }
2319      }      }
# Line 2468  escript::C_GeneralTensorProduct(Data& ar Line 2336  escript::C_GeneralTensorProduct(Data& ar
2336      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)
2337      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {
2338        int offset_1 = tmp_1->getPointOffset(sampleNo_0,0);        int offset_1 = tmp_1->getPointOffset(sampleNo_0,0);
2339        double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);        double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2340        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {
2341          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);
2342          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2343          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2344          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2345          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);
2346        }        }
2347      }      }
# Line 2498  escript::C_GeneralTensorProduct(Data& ar Line 2366  escript::C_GeneralTensorProduct(Data& ar
2366          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);
2367          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);
2368          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2369          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2370          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);          double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2371          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2372          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);
2373        }        }
2374      }      }
# Line 2519  Data::borrowData() const Line 2387  Data::borrowData() const
2387    return m_data.get();    return m_data.get();
2388  }  }
2389    
2390    
2391    std::string
2392    Data::toString() const
2393    {
2394        static const DataTypes::ValueType::size_type TOO_MANY_POINTS=80;
2395        if (getNumDataPoints()*getDataPointSize()>TOO_MANY_POINTS)
2396        {
2397        stringstream temp;
2398        temp << "Summary: inf="<< inf() << " sup=" << sup() << " data points=" << getNumDataPoints();
2399        return  temp.str();
2400        }
2401        return m_data->toString();
2402    }
2403    
2404    
2405    
2406    DataTypes::ValueType::const_reference
2407    Data::getDataAtOffset(DataTypes::ValueType::size_type i) const
2408    {
2409        return m_data->getDataAtOffset(i);
2410    }
2411    
2412    
2413    DataTypes::ValueType::reference
2414    Data::getDataAtOffset(DataTypes::ValueType::size_type i)
2415    {
2416        return m_data->getDataAtOffset(i);
2417    }
2418    
2419    DataTypes::ValueType::const_reference
2420    Data::getDataPoint(int sampleNo, int dataPointNo) const
2421    {
2422        return m_data->getDataAtOffset(m_data->getPointOffset(sampleNo, dataPointNo));
2423    }
2424    
2425    
2426    DataTypes::ValueType::reference
2427    Data::getDataPoint(int sampleNo, int dataPointNo)
2428    {
2429        return m_data->getDataAtOffset(m_data->getPointOffset(sampleNo, dataPointNo));
2430    }
2431    
2432    
2433  /* Member functions specific to the MPI implementation */  /* Member functions specific to the MPI implementation */
2434    
2435  void  void
# Line 2551  Data::dump(const std::string fileName) c Line 2462  Data::dump(const std::string fileName) c
2462  int  int
2463  Data::get_MPISize() const  Data::get_MPISize() const
2464  {  {
2465      int error, size;      int size;
2466  #ifdef PASO_MPI  #ifdef PASO_MPI
2467        int error;
2468      error = MPI_Comm_size( get_MPIComm(), &size );      error = MPI_Comm_size( get_MPIComm(), &size );
2469  #else  #else
2470      size = 1;      size = 1;
# Line 2563  Data::get_MPISize() const Line 2475  Data::get_MPISize() const
2475  int  int
2476  Data::get_MPIRank() const  Data::get_MPIRank() const
2477  {  {
2478      int error, rank;      int rank;
2479  #ifdef PASO_MPI  #ifdef PASO_MPI
2480        int error;
2481      error = MPI_Comm_rank( get_MPIComm(), &rank );      error = MPI_Comm_rank( get_MPIComm(), &rank );
2482  #else  #else
2483      rank = 0;      rank = 0;
# Line 2582  Data::get_MPIComm() const Line 2495  Data::get_MPIComm() const
2495  #endif  #endif
2496  }  }
2497    
2498    

Legend:
Removed from v.1387  
changed lines
  Added in v.1799

  ViewVC Help
Powered by ViewVC 1.1.26