/[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 1118 by gross, Tue Apr 24 08:55:04 2007 UTC revision 1796 by jfenwick, Wed Sep 17 01:45:46 2008 UTC
# Line 1  Line 1 
 // $Id$  
1    
2  /*  /* $Id$ */
3   ************************************************************  
4   *          Copyright 2006 by ACcESS MNRF                   *  /*******************************************************
5   *                                                          *   *
6   *              http://www.access.edu.au                    *   *           Copyright 2003-2007 by ACceSS MNRF
7   *       Primary Business: Queensland, Australia            *   *       Copyright 2007 by University of Queensland
8   *  Licensed under the Open Software License version 3.0    *   *
9   *     http://www.opensource.org/licenses/osl-3.0.php       *   *                http://esscc.uq.edu.au
10   *                                                          *   *        Primary Business: Queensland, Australia
11   ************************************************************   *  Licensed under the Open Software License version 3.0
12  */   *     http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16  #include "Data.h"  #include "Data.h"
17    
18  #include "DataExpanded.h"  #include "DataExpanded.h"
19  #include "DataConstant.h"  #include "DataConstant.h"
20  #include "DataTagged.h"  #include "DataTagged.h"
21  #include "DataEmpty.h"  #include "DataEmpty.h"
 #include "DataArray.h"  
 #include "DataArrayView.h"  
 #include "DataProf.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" {
28    #include "escript/blocktimer.h"
29    }
30    
31  #include <fstream>  #include <fstream>
32  #include <algorithm>  #include <algorithm>
# Line 53  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    DataArray temp(dataPointShape,value);  
65    initialise(temp.getView(),what,expanded);    int len = DataTypes::noValues(dataPointShape);
66      DataVector temp_data(len,value,len);
67    //   DataArrayView temp_dataView(temp_data, dataPointShape);
68    
69    //   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    DataArray temp(dataPointShape,value);    int len = DataTypes::noValues(dataPointShape);
81    pair<int,int> dataShape=what.getDataShape();  
82    initialise(temp.getView(),what,expanded);    DataVector temp_data(len,value,len);
83    //   DataArrayView temp_dataView(temp_data, dataPointShape);
84    
85    //   initialise(temp_dataView, what, expanded);
86      initialise(temp_data, dataPointShape, what, expanded);
87    
88    m_protected=false;    m_protected=false;
89  }  }
90    
# Line 79  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 95  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 112  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 134  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 152  Data::Data(const object& value, Line 193  Data::Data(const object& value,
193    m_protected=false;    m_protected=false;
194  }  }
195    
196    
197  Data::Data(const object& value,  Data::Data(const object& value,
198             const Data& other)             const Data& other)
199  {  {
200      numeric::array asNumArray(value);
201    
202      // extract the shape of the numarray
203      DataTypes::ShapeType tempShape=DataTypes::shapeFromNumArray(asNumArray);
204    // /*  for (int i=0; i < asNumArray.getrank(); i++) {
205    //     tempShape.push_back(extract<int>(asNumArray.getshape()[i]));
206    //   }*/
207    //   // get the space for the data vector
208    //   int len = DataTypes::noValues(tempShape);
209    //   DataVector temp_data(len, 0.0, len);
210    // /*  DataArrayView temp_dataView(temp_data, tempShape);
211    //   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    DataArray temp(value);  
219    if (temp.getView().getRank()==0) {    if (DataTypes::getRank(tempShape)/*temp_dataView.getRank()*/==0) {
220      //  
221      // Create a DataArray with the scalar value for all elements  
222      DataArray temp2(other.getPointDataView().getShape(),temp.getView()());      // get the space for the data vector
223      initialise(temp2.getView(),other.getFunctionSpace(),false);      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    
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.getView(),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 178  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 197  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 339  Data::isConstant() const Line 539  Data::isConstant() const
539  }  }
540    
541  void  void
542  Data::setProtection()  Data::setProtection()
543  {  {
544     m_protected=true;     m_protected=true;
545  }  }
546    
547  bool  bool
548  Data::isProtected() const  Data::isProtected() const
549  {  {
550     return m_protected;     return m_protected;
551  }  }
552    
# Line 397  Data::tag() Line 597  Data::tag()
597  Data  Data
598  Data::oneOver() const  Data::oneOver() const
599  {  {
600    return escript::unaryOp(*this,bind1st(divides<double>(),1.));    return C_TensorUnaryOperation(*this, bind1st(divides<double>(),1.));
601  }  }
602    
603  Data  Data
604  Data::wherePositive() const  Data::wherePositive() const
605  {  {
606    return escript::unaryOp(*this,bind2nd(greater<double>(),0.0));    return C_TensorUnaryOperation(*this, bind2nd(greater<double>(),0.0));
607  }  }
608    
609  Data  Data
610  Data::whereNegative() const  Data::whereNegative() const
611  {  {
612    return escript::unaryOp(*this,bind2nd(less<double>(),0.0));    return C_TensorUnaryOperation(*this, bind2nd(less<double>(),0.0));
613  }  }
614    
615  Data  Data
616  Data::whereNonNegative() const  Data::whereNonNegative() const
617  {  {
618    return escript::unaryOp(*this,bind2nd(greater_equal<double>(),0.0));    return C_TensorUnaryOperation(*this, bind2nd(greater_equal<double>(),0.0));
619  }  }
620    
621  Data  Data
622  Data::whereNonPositive() const  Data::whereNonPositive() const
623  {  {
624    return escript::unaryOp(*this,bind2nd(less_equal<double>(),0.0));    return C_TensorUnaryOperation(*this, bind2nd(less_equal<double>(),0.0));
625  }  }
626    
627  Data  Data
628  Data::whereZero(double tol) const  Data::whereZero(double tol) const
629  {  {
630    Data dataAbs=abs();    Data dataAbs=abs();
631    return escript::unaryOp(dataAbs,bind2nd(less_equal<double>(),tol));    return C_TensorUnaryOperation(dataAbs, bind2nd(less_equal<double>(),tol));
632  }  }
633    
634  Data  Data
635  Data::whereNonZero(double tol) const  Data::whereNonZero(double tol) const
636  {  {
637    Data dataAbs=abs();    Data dataAbs=abs();
638    return escript::unaryOp(dataAbs,bind2nd(greater<double>(),tol));    return C_TensorUnaryOperation(dataAbs, bind2nd(greater<double>(),tol));
639  }  }
640    
641  Data  Data
# Line 462  Data::probeInterpolation(const FunctionS Line 662  Data::probeInterpolation(const FunctionS
662  Data  Data
663  Data::gradOn(const FunctionSpace& functionspace) const  Data::gradOn(const FunctionSpace& functionspace) const
664  {  {
665      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);
672      blocktimer_increment("grad()", blocktimer_start);
673    return out;    return out;
674  }  }
675    
# Line 480  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  const  
703    const
704  boost::python::numeric::array  boost::python::numeric::array
705  Data:: getValueOfDataPoint(int dataPointNo)  Data:: getValueOfDataPoint(int dataPointNo)
706  {  {
707    size_t length=0;    size_t length=0;
708    int i, j, k, l;    int i, j, k, l;
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 516  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 544  Data:: getValueOfDataPoint(int dataPoint Line 747  Data:: getValueOfDataPoint(int dataPoint
747         if ((sampleNo >= getNumSamples()) || (sampleNo < 0 )) {         if ((sampleNo >= getNumSamples()) || (sampleNo < 0 )) {
748             throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");             throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");
749         }         }
750                  
751         //         //
752         // Check a valid data point number has been supplied         // Check a valid data point number has been supplied
753         if ((dataPointNoInSample >= getNumDataPointsPerSample()) || (dataPointNoInSample < 0)) {         if ((dataPointNoInSample >= getNumDataPointsPerSample()) || (dataPointNoInSample < 0)) {
# Line 552  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 587  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  {  {
799      // this will throw if the value cannot be represented      // this will throw if the value cannot be represented
800      boost::python::numeric::array num_array(py_object);      boost::python::numeric::array num_array(py_object);
# Line 605  Data::setValueOfDataPointToArray(int dat Line 811  Data::setValueOfDataPointToArray(int dat
811    }    }
812    //    //
813    // check rank    // check rank
814    if (num_array.getrank()<getDataPointRank())    if (num_array.getrank()<getDataPointRank())
815        throw DataException("Rank of numarray does not match Data object rank");        throw DataException("Rank of numarray does not match Data object rank");
816    
817    //    //
# Line 648  Data::setValueOfDataPoint(int dataPointN Line 854  Data::setValueOfDataPoint(int dataPointN
854    }    }
855  }  }
856    
857  const  const
858  boost::python::numeric::array  boost::python::numeric::array
859  Data::getValueOfGlobalDataPoint(int procNo, int dataPointNo)  Data::getValueOfGlobalDataPoint(int procNo, int dataPointNo)
860  {  {
861    size_t length=0;    size_t length=0;
862    int i, j, k, l, pos;    int i, j, k, l, pos;
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 667  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 705  Data::getValueOfGlobalDataPoint(int proc Line 911  Data::getValueOfGlobalDataPoint(int proc
911                  if ((sampleNo >= getNumSamples()) || (sampleNo < 0 )) {                  if ((sampleNo >= getNumSamples()) || (sampleNo < 0 )) {
912                    throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");                    throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");
913                  }                  }
914                  
915                  //                  //
916                  // Check a valid data point number has been supplied                  // Check a valid data point number has been supplied
917                  if ((dataPointNoInSample >= getNumDataPointsPerSample()) || (dataPointNoInSample < 0)) {                  if ((dataPointNoInSample >= getNumDataPointsPerSample()) || (dataPointNoInSample < 0)) {
# Line 713  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              }              }
955      }      }
956          #ifdef PASO_MPI          #ifdef PASO_MPI
957          // broadcast the data to all other processes          // broadcast the data to all other processes
958      MPI_Bcast( tmpData, length, MPI_DOUBLE, procNo, get_MPIComm() );      MPI_Bcast( tmpData, length, MPI_DOUBLE, procNo, get_MPIComm() );
959          #endif          #endif
# Line 756  Data::getValueOfGlobalDataPoint(int proc Line 963  Data::getValueOfGlobalDataPoint(int proc
963          case 0 :          case 0 :
964              numArray[0]=tmpData[0];              numArray[0]=tmpData[0];
965              break;              break;
966          case 1 :                  case 1 :
967              for( i=0; i<dataPointShape[0]; i++ )              for( i=0; i<dataPointShape[0]; i++ )
968                  numArray[i]=tmpData[i];                  numArray[i]=tmpData[i];
969              break;              break;
970          case 2 :                  case 2 :
971              for( i=0; i<dataPointShape[0]; i++ )              for( i=0; i<dataPointShape[0]; i++ )
972                  for( j=0; j<dataPointShape[1]; j++ )                  for( j=0; j<dataPointShape[1]; j++ )
973                     numArray[make_tuple(i,j)]=tmpData[i+j*dataPointShape[0]];                     numArray[make_tuple(i,j)]=tmpData[i+j*dataPointShape[0]];
974              break;              break;
975          case 3 :                  case 3 :
976              for( i=0; i<dataPointShape[0]; i++ )              for( i=0; i<dataPointShape[0]; i++ )
977                  for( j=0; j<dataPointShape[1]; j++ )                  for( j=0; j<dataPointShape[1]; j++ )
978                      for( k=0; k<dataPointShape[2]; k++ )                      for( k=0; k<dataPointShape[2]; k++ )
# Line 780  Data::getValueOfGlobalDataPoint(int proc Line 987  Data::getValueOfGlobalDataPoint(int proc
987              break;              break;
988      }      }
989    
990      delete [] tmpData;        delete [] tmpData;
991    //    //
992    // return the loaded array    // return the loaded array
993    return numArray;    return numArray;
# Line 793  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();
1005    
1006    //    //
1007    // calculate the integral values    // calculate the integral values
1008    vector<double> integrals(getDataPointSize());    vector<double> integrals(dataPointSize);
1009      vector<double> integrals_local(dataPointSize);
1010    #ifdef PASO_MPI
1011      AbstractContinuousDomain::asAbstractContinuousDomain(getDomain()).setToIntegrals(integrals_local,*this);
1012      // Global sum: use an array instead of a vector because elements of array are guaranteed to be contiguous in memory
1013      double *tmp = new double[dataPointSize];
1014      double *tmp_local = new double[dataPointSize];
1015      for (int i=0; i<dataPointSize; i++) { tmp_local[i] = integrals_local[i]; }
1016      MPI_Allreduce( &tmp_local[0], &tmp[0], dataPointSize, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
1017      for (int i=0; i<dataPointSize; i++) { integrals[i] = tmp[i]; }
1018      delete[] tmp;
1019      delete[] tmp_local;
1020    #else
1021    AbstractContinuousDomain::asAbstractContinuousDomain(getDomain()).setToIntegrals(integrals,*this);    AbstractContinuousDomain::asAbstractContinuousDomain(getDomain()).setToIntegrals(integrals,*this);
1022    #endif
1023    
1024    //    //
1025    // create the numeric array to be returned    // create the numeric array to be returned
# Line 859  Data::integrate() const Line 1079  Data::integrate() const
1079  Data  Data
1080  Data::sin() const  Data::sin() const
1081  {  {
1082    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sin);    return C_TensorUnaryOperation<double (*)(double)>(*this, ::sin);
1083  }  }
1084    
1085  Data  Data
1086  Data::cos() const  Data::cos() const
1087  {  {
1088    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cos);    return C_TensorUnaryOperation<double (*)(double)>(*this, ::cos);
1089  }  }
1090    
1091  Data  Data
1092  Data::tan() const  Data::tan() const
1093  {  {
1094    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tan);    return C_TensorUnaryOperation<double (*)(double)>(*this, ::tan);
1095  }  }
1096    
1097  Data  Data
1098  Data::asin() const  Data::asin() const
1099  {  {
1100    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asin);    return C_TensorUnaryOperation<double (*)(double)>(*this, ::asin);
1101  }  }
1102    
1103  Data  Data
1104  Data::acos() const  Data::acos() const
1105  {  {
1106    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acos);    return C_TensorUnaryOperation<double (*)(double)>(*this, ::acos);
1107  }  }
1108    
1109    
1110  Data  Data
1111  Data::atan() const  Data::atan() const
1112  {  {
1113    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atan);    return C_TensorUnaryOperation<double (*)(double)>(*this, ::atan);
1114  }  }
1115    
1116  Data  Data
1117  Data::sinh() const  Data::sinh() const
1118  {  {
1119    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sinh);      return C_TensorUnaryOperation<double (*)(double)>(*this, ::sinh);
1120    
1121  }  }
1122    
1123  Data  Data
1124  Data::cosh() const  Data::cosh() const
1125  {  {
1126    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cosh);      return C_TensorUnaryOperation<double (*)(double)>(*this, ::cosh);
1127  }  }
1128    
1129  Data  Data
1130  Data::tanh() const  Data::tanh() const
1131  {  {
1132    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tanh);      return C_TensorUnaryOperation<double (*)(double)>(*this, ::tanh);
1133  }  }
1134    
1135    
# Line 918  Data::erf() const Line 1139  Data::erf() const
1139  #ifdef _WIN32  #ifdef _WIN32
1140    throw DataException("Error - Data:: erf function is not supported on _WIN32 platforms.");    throw DataException("Error - Data:: erf function is not supported on _WIN32 platforms.");
1141  #else  #else
1142    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::erf);    return C_TensorUnaryOperation(*this, ::erf);
1143  #endif  #endif
1144  }  }
1145    
# Line 926  Data Line 1147  Data
1147  Data::asinh() const  Data::asinh() const
1148  {  {
1149  #ifdef _WIN32  #ifdef _WIN32
1150    return escript::unaryOp(*this,escript::asinh_substitute);    return C_TensorUnaryOperation(*this, escript::asinh_substitute);
1151  #else  #else
1152    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asinh);    return C_TensorUnaryOperation(*this, ::asinh);
1153  #endif  #endif
1154  }  }
1155    
# Line 936  Data Line 1157  Data
1157  Data::acosh() const  Data::acosh() const
1158  {  {
1159  #ifdef _WIN32  #ifdef _WIN32
1160    return escript::unaryOp(*this,escript::acosh_substitute);    return C_TensorUnaryOperation(*this, escript::acosh_substitute);
1161  #else  #else
1162    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acosh);    return C_TensorUnaryOperation(*this, ::acosh);
1163  #endif  #endif
1164  }  }
1165    
# Line 946  Data Line 1167  Data
1167  Data::atanh() const  Data::atanh() const
1168  {  {
1169  #ifdef _WIN32  #ifdef _WIN32
1170    return escript::unaryOp(*this,escript::atanh_substitute);    return C_TensorUnaryOperation(*this, escript::atanh_substitute);
1171  #else  #else
1172    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atanh);    return C_TensorUnaryOperation(*this, ::atanh);
1173  #endif  #endif
1174  }  }
1175    
1176  Data  Data
1177  Data::log10() const  Data::log10() const
1178  {  {
1179    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log10);    return C_TensorUnaryOperation<double (*)(double)>(*this, ::log10);
1180  }  }
1181    
1182  Data  Data
1183  Data::log() const  Data::log() const
1184  {  {
1185    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);    return C_TensorUnaryOperation<double (*)(double)>(*this, ::log);
1186  }  }
1187    
1188  Data  Data
1189  Data::sign() const  Data::sign() const
1190  {  {
1191    return escript::unaryOp(*this,escript::fsign);    return C_TensorUnaryOperation(*this, escript::fsign);
1192  }  }
1193    
1194  Data  Data
1195  Data::abs() const  Data::abs() const
1196  {  {
1197    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);    return C_TensorUnaryOperation<double (*)(double)>(*this, ::fabs);
1198  }  }
1199    
1200  Data  Data
1201  Data::neg() const  Data::neg() const
1202  {  {
1203    return escript::unaryOp(*this,negate<double>());    return C_TensorUnaryOperation(*this, negate<double>());
1204  }  }
1205    
1206  Data  Data
# Line 994  Data::pos() const Line 1215  Data::pos() const
1215  Data  Data
1216  Data::exp() const  Data::exp() const
1217  {  {
1218    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);    return C_TensorUnaryOperation<double (*)(double)>(*this, ::exp);
1219  }  }
1220    
1221  Data  Data
1222  Data::sqrt() const  Data::sqrt() const
1223  {  {
1224    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);    return C_TensorUnaryOperation<double (*)(double)>(*this, ::sqrt);
1225  }  }
1226    
1227  double  double
1228  Data::Lsup() const  Data::Lsup() const
1229  {  {
1230    double localValue, globalValue;    double localValue;
1231    //    //
1232    // set the initial absolute maximum value to zero    // set the initial absolute maximum value to zero
1233    
1234    AbsMax abs_max_func;    AbsMax abs_max_func;
1235    localValue = algorithm(abs_max_func,0);    localValue = algorithm(abs_max_func,0);
1236  #ifdef PASO_MPI  #ifdef PASO_MPI
1237      double globalValue;
1238    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
1239    return globalValue;    return globalValue;
1240  #else  #else
# Line 1021  Data::Lsup() const Line 1243  Data::Lsup() const
1243  }  }
1244    
1245  double  double
 Data::Linf() const  
 {  
   double localValue, globalValue;  
   //  
   // set the initial absolute minimum value to max double  
   AbsMin abs_min_func;  
   localValue = algorithm(abs_min_func,numeric_limits<double>::max());  
   
 #ifdef PASO_MPI  
   MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD );  
   return globalValue;  
 #else  
   return localValue;  
 #endif  
 }  
   
 double  
1246  Data::sup() const  Data::sup() const
1247  {  {
1248    double localValue, globalValue;    double localValue;
1249    //    //
1250    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1251    FMax fmax_func;    FMax fmax_func;
1252    localValue = algorithm(fmax_func,numeric_limits<double>::max()*-1);    localValue = algorithm(fmax_func,numeric_limits<double>::max()*-1);
1253  #ifdef PASO_MPI  #ifdef PASO_MPI
1254      double globalValue;
1255    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
1256    return globalValue;    return globalValue;
1257  #else  #else
# Line 1056  Data::sup() const Line 1262  Data::sup() const
1262  double  double
1263  Data::inf() const  Data::inf() const
1264  {  {
1265    double localValue, globalValue;    double localValue;
1266    //    //
1267    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1268    FMin fmin_func;    FMin fmin_func;
1269    localValue = algorithm(fmin_func,numeric_limits<double>::max());    localValue = algorithm(fmin_func,numeric_limits<double>::max());
1270  #ifdef PASO_MPI  #ifdef PASO_MPI
1271      double globalValue;
1272    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD );    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD );
1273    return globalValue;    return globalValue;
1274  #else  #else
# Line 1093  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 1119  Data::swapaxes(const int axis0, const in Line 1326  Data::swapaxes(const int axis0, const in
1326       }       }
1327       for (int i=0; i<rank; i++) {       for (int i=0; i<rank; i++) {
1328         if (i == axis0_tmp) {         if (i == axis0_tmp) {
1329            ev_shape.push_back(s[axis1_tmp]);            ev_shape.push_back(s[axis1_tmp]);
1330         } else if (i == axis1_tmp) {         } else if (i == axis1_tmp) {
1331            ev_shape.push_back(s[axis0_tmp]);            ev_shape.push_back(s[axis0_tmp]);
1332         } else {         } else {
1333            ev_shape.push_back(s[i]);            ev_shape.push_back(s[i]);
1334         }         }
1335       }       }
1336       Data ev(0.,ev_shape,getFunctionSpace());       Data ev(0.,ev_shape,getFunctionSpace());
# Line 1137  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.");
1351       }       }
1352       else if (getDataPointRank()==4) {       else if (getDataPointRank()==4) {
# Line 1159  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 1174  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 1192  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 1216  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 1242  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 1264  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 1280  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 1331  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 1349  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() );
1563        
1564      if( get_MPIRank()==0 ){      if( get_MPIRank()==0 ){
1565          next = globalMins[lowProc];          next = globalMins[lowProc];
1566          for( i=1; i<get_MPISize(); i++ )          for( i=1; i<get_MPISize(); i++ )
# Line 1407  Data::operator+=(const boost::python::ob Line 1614  Data::operator+=(const boost::python::ob
1614    binaryOp(tmp,plus<double>());    binaryOp(tmp,plus<double>());
1615    return (*this);    return (*this);
1616  }  }
1617    Data&
1618    Data::operator=(const Data& other)
1619    {
1620      copy(other);
1621      return (*this);
1622    }
1623    
1624  Data&  Data&
1625  Data::operator-=(const Data& right)  Data::operator-=(const Data& right)
# Line 1479  Data::powO(const boost::python::object& Line 1692  Data::powO(const boost::python::object&
1692  Data  Data
1693  Data::powD(const Data& right) const  Data::powD(const Data& right) const
1694  {  {
1695    Data result;    return C_TensorBinaryOperation<double (*)(double, double)>(*this, right, ::pow);
   if (getDataPointRank()<right.getDataPointRank()) {  
      result.copy(right);  
      result.binaryOp(*this,escript::rpow);  
   } else {  
      result.copy(*this);  
      result.binaryOp(right,(Data::BinaryDFunPtr)::pow);  
   }  
   return result;  
1696  }  }
1697    
   
1698  //  //
1699  // NOTE: It is essential to specify the namespace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1700  Data  Data
1701  escript::operator+(const Data& left, const Data& right)  escript::operator+(const Data& left, const Data& right)
1702  {  {
1703    Data result;    return C_TensorBinaryOperation(left, right, plus<double>());
   //  
   // perform a deep copy  
   if (left.getDataPointRank()<right.getDataPointRank()) {  
      result.copy(right);  
      result+=left;  
   } else {  
      result.copy(left);  
      result+=right;  
   }  
   return result;  
1704  }  }
1705    
1706  //  //
# Line 1514  escript::operator+(const Data& left, con Line 1708  escript::operator+(const Data& left, con
1708  Data  Data
1709  escript::operator-(const Data& left, const Data& right)  escript::operator-(const Data& left, const Data& right)
1710  {  {
1711    Data result;    return C_TensorBinaryOperation(left, right, minus<double>());
   //  
   // perform a deep copy  
   if (left.getDataPointRank()<right.getDataPointRank()) {  
      result=right.neg();  
      result+=left;  
   } else {  
      result.copy(left);  
      result-=right;  
   }  
   return result;  
1712  }  }
1713    
1714  //  //
# Line 1532  escript::operator-(const Data& left, con Line 1716  escript::operator-(const Data& left, con
1716  Data  Data
1717  escript::operator*(const Data& left, const Data& right)  escript::operator*(const Data& left, const Data& right)
1718  {  {
1719    Data result;    return C_TensorBinaryOperation(left, right, multiplies<double>());
   //  
   // perform a deep copy  
   if (left.getDataPointRank()<right.getDataPointRank()) {  
      result.copy(right);  
      result*=left;  
   } else {  
      result.copy(left);  
      result*=right;  
   }  
   return result;  
1720  }  }
1721    
1722  //  //
# Line 1550  escript::operator*(const Data& left, con Line 1724  escript::operator*(const Data& left, con
1724  Data  Data
1725  escript::operator/(const Data& left, const Data& right)  escript::operator/(const Data& left, const Data& right)
1726  {  {
1727    Data result;    return C_TensorBinaryOperation(left, right, divides<double>());
   //  
   // perform a deep copy  
   if (left.getDataPointRank()<right.getDataPointRank()) {  
      result=right.oneOver();  
      result*=left;  
   } else {  
      result.copy(left);  
      result/=right;  
   }  
   return result;  
1728  }  }
1729    
1730  //  //
# Line 1675  escript::operator/(const boost::python:: Line 1839  escript::operator/(const boost::python::
1839  /* TODO */  /* TODO */
1840  /* global reduction */  /* global reduction */
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 1691  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 1706  Data::setItemO(const boost::python::obje Line 1870  Data::setItemO(const boost::python::obje
1870    setItemD(key,tempData);    setItemD(key,tempData);
1871  }  }
1872    
 /* TODO */  
 /* global reduction */  
1873  void  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 1725  Data::setItemD(const boost::python::obje Line 1887  Data::setItemD(const boost::python::obje
1887    }    }
1888  }  }
1889    
 /* TODO */  
 /* global reduction */  
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 1770  Data::typeMatchRight(const Data& right) Line 1930  Data::typeMatchRight(const Data& right)
1930    
1931  void  void
1932  Data::setTaggedValueByName(std::string name,  Data::setTaggedValueByName(std::string name,
1933                             const boost::python::object& value)                             const boost::python::object& value)
1934  {  {
1935       if (getFunctionSpace().getDomain().isValidTagName(name)) {       if (getFunctionSpace().getDomain().isValidTagName(name)) {
1936          int tagKey=getFunctionSpace().getDomain().getTag(name);          int tagKey=getFunctionSpace().getDomain().getTag(name);
# Line 1786  Data::setTaggedValue(int tagKey, Line 1946  Data::setTaggedValue(int tagKey,
1946    }    }
1947    //    //
1948    // Ensure underlying data object is of type DataTagged    // Ensure underlying data object is of type DataTagged
1949    tag();    if (isConstant()) tag();
1950    
1951      numeric::array asNumArray(value);
1952    
1953    
1954    if (!isTagged()) {    // extract the shape of the numarray
1955      throw DataException("Error - DataTagged conversion failed!!");    DataTypes::ShapeType tempShape;
1956      for (int i=0; i < asNumArray.getrank(); i++) {
1957        tempShape.push_back(extract<int>(asNumArray.getshape()[i]));
1958    }    }
1959    
1960    //    // get the space for the data vector
1961    // Construct DataArray from boost::python::object input value  //   int len = DataTypes::noValues(tempShape);
1962    DataArray valueDataArray(value);  //   DataVector temp_data(len, 0.0, len);
1963    //   DataArrayView temp_dataView(temp_data, tempShape);
1964    //   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,valueDataArray.getView());    //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.");
2000    }    }
2001    //    //
2002    // Ensure underlying data object is of type DataTagged    // Ensure underlying data object is of type DataTagged
2003    tag();    if (isConstant()) tag();
2004    
   if (!isTagged()) {  
     throw DataException("Error - DataTagged conversion failed!!");  
   }  
                                                                                                                 
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
2011  Data::getTagNumber(int dpno)  Data::getTagNumber(int dpno)
2012  {  {
2013    return m_data->getTagNumber(dpno);    return getFunctionSpace().getTagFromDataPointNo(dpno);
 }  
   
 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");  
   }  
   
2014  }  }
2015    
 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 2177  escript::C_GeneralTensorProduct(Data& ar Line 2029  escript::C_GeneralTensorProduct(Data& ar
2029    // General tensor product: res(SL x SR) = arg_0(SL x SM) * arg_1(SM x SR)    // General tensor product: res(SL x SR) = arg_0(SL x SM) * arg_1(SM x SR)
2030    // SM is the product of the last axis_offset entries in arg_0.getShape().    // SM is the product of the last axis_offset entries in arg_0.getShape().
2031    
   
2032    // Interpolate if necessary and find an appropriate function space    // Interpolate if necessary and find an appropriate function space
2033    Data arg_0_Z, arg_1_Z;    Data arg_0_Z, arg_1_Z;
2034    if (arg_0.getFunctionSpace()!=arg_1.getFunctionSpace()) {    if (arg_0.getFunctionSpace()!=arg_1.getFunctionSpace()) {
# Line 2199  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 2209  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 2244  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 2277  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 2317  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 2343  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 2381  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 2396  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 2430  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 2459  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 2484  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 2514  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 2535  Data::borrowData() const Line 2418  Data::borrowData() const
2418    return m_data.get();    return m_data.get();
2419  }  }
2420    
2421    
2422    std::string
2423    Data::toString() const
2424    {
2425        static const DataTypes::ValueType::size_type TOO_MANY_POINTS=80;
2426        if (getNumDataPoints()*getDataPointSize()>TOO_MANY_POINTS)
2427        {
2428        stringstream temp;
2429        temp << "Summary: inf="<< inf() << " sup=" << sup() << " data points=" << getNumDataPoints();
2430        return  temp.str();
2431        }
2432        return m_data->toString();
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
2467  Data::print()  Data::print()
2468  {  {
2469    int i,j;    int i,j;
2470      
2471    printf( "Data is %dX%d\n", getNumSamples(), getNumDataPointsPerSample() );    printf( "Data is %dX%d\n", getNumSamples(), getNumDataPointsPerSample() );
2472    for( i=0; i<getNumSamples(); i++ )    for( i=0; i<getNumSamples(); i++ )
2473    {    {
# Line 2551  Data::print() Line 2477  Data::print()
2477      printf( "\n" );      printf( "\n" );
2478    }    }
2479  }  }
2480    void
2481    Data::dump(const std::string fileName) const
2482    {
2483      try
2484         {
2485            return m_data->dump(fileName);
2486         }
2487         catch (exception& e)
2488         {
2489            cout << e.what() << endl;
2490         }
2491    }
2492    
2493  int  int
2494  Data::get_MPISize() const  Data::get_MPISize() const
2495  {  {
2496      int error, size;      int size;
2497  #ifdef PASO_MPI  #ifdef PASO_MPI
2498        int error;
2499      error = MPI_Comm_size( get_MPIComm(), &size );      error = MPI_Comm_size( get_MPIComm(), &size );
2500  #else  #else
2501      size = 1;      size = 1;
# Line 2567  Data::get_MPISize() const Line 2506  Data::get_MPISize() const
2506  int  int
2507  Data::get_MPIRank() const  Data::get_MPIRank() const
2508  {  {
2509      int error, rank;      int rank;
2510  #ifdef PASO_MPI  #ifdef PASO_MPI
2511        int error;
2512      error = MPI_Comm_rank( get_MPIComm(), &rank );      error = MPI_Comm_rank( get_MPIComm(), &rank );
2513  #else  #else
2514      rank = 0;      rank = 0;
# Line 2578  Data::get_MPIRank() const Line 2518  Data::get_MPIRank() const
2518    
2519  MPI_Comm  MPI_Comm
2520  Data::get_MPIComm() const  Data::get_MPIComm() const
2521  {  {
2522  #ifdef PASO_MPI  #ifdef PASO_MPI
2523      return MPI_COMM_WORLD;      return MPI_COMM_WORLD;
2524  #else  #else
# Line 2586  Data::get_MPIComm() const Line 2526  Data::get_MPIComm() const
2526  #endif  #endif
2527  }  }
2528    
2529    

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

  ViewVC Help
Powered by ViewVC 1.1.26