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

trunk/escript/src/Data.cpp revision 824 by ksteube, Tue Aug 29 05:22:50 2006 UTC temp/escript/src/Data.cpp revision 1387 by trankine, Fri Jan 11 07:45:26 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"  
22  #include "DataArrayView.h"  #include "DataArrayView.h"
 #include "DataProf.h"  
23  #include "FunctionSpaceFactory.h"  #include "FunctionSpaceFactory.h"
24  #include "AbstractContinuousDomain.h"  #include "AbstractContinuousDomain.h"
25  #include "UnaryFuncs.h"  #include "UnaryFuncs.h"
26    extern "C" {
27    #include "escript/blocktimer.h"
28    }
29    
30  #include <fstream>  #include <fstream>
31  #include <algorithm>  #include <algorithm>
# Line 38  using namespace boost::python; Line 41  using namespace boost::python;
41  using namespace boost;  using namespace boost;
42  using namespace escript;  using namespace escript;
43    
 #if defined DOPROF  
 //  
 // global table of profiling data for all Data objects  
 DataProf dataProfTable;  
 #endif  
   
44  Data::Data()  Data::Data()
45  {  {
46    //    //
# Line 52  Data::Data() Line 49  Data::Data()
49    shared_ptr<DataAbstract> temp_data(temp);    shared_ptr<DataAbstract> temp_data(temp);
50    m_data=temp_data;    m_data=temp_data;
51    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
52  }  }
53    
54  Data::Data(double value,  Data::Data(double value,
# Line 67  Data::Data(double value, Line 60  Data::Data(double value,
60    for (int i = 0; i < shape.attr("__len__")(); ++i) {    for (int i = 0; i < shape.attr("__len__")(); ++i) {
61      dataPointShape.push_back(extract<const int>(shape[i]));      dataPointShape.push_back(extract<const int>(shape[i]));
62    }    }
63    DataArray temp(dataPointShape,value);  
64    initialise(temp.getView(),what,expanded);    int len = DataArrayView::noValues(dataPointShape);
65      DataVector temp_data(len,value,len);
66      DataArrayView temp_dataView(temp_data, dataPointShape);
67    
68      initialise(temp_dataView, what, expanded);
69    
70    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
71  }  }
72    
73  Data::Data(double value,  Data::Data(double value,
# Line 81  Data::Data(double value, Line 75  Data::Data(double value,
75         const FunctionSpace& what,         const FunctionSpace& what,
76             bool expanded)             bool expanded)
77  {  {
78    DataArray temp(dataPointShape,value);    int len = DataArrayView::noValues(dataPointShape);
79    pair<int,int> dataShape=what.getDataShape();  
80    initialise(temp.getView(),what,expanded);    DataVector temp_data(len,value,len);
81      DataArrayView temp_dataView(temp_data, dataPointShape);
82    
83      initialise(temp_dataView, what, expanded);
84    
85    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
86  }  }
87    
88  Data::Data(const Data& inData)  Data::Data(const Data& inData)
89  {  {
90    m_data=inData.m_data;    m_data=inData.m_data;
91    m_protected=inData.isProtected();    m_protected=inData.isProtected();
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
92  }  }
93    
94  Data::Data(const Data& inData,  Data::Data(const Data& inData,
# Line 110  Data::Data(const Data& inData, Line 100  Data::Data(const Data& inData,
100    shared_ptr<DataAbstract> temp_data(tmp);    shared_ptr<DataAbstract> temp_data(tmp);
101    m_data=temp_data;    m_data=temp_data;
102    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
103  }  }
104    
105  Data::Data(const Data& inData,  Data::Data(const Data& inData,
106             const FunctionSpace& functionspace)             const FunctionSpace& functionspace)
107  {  {
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
108    if (inData.getFunctionSpace()==functionspace) {    if (inData.getFunctionSpace()==functionspace) {
109      m_data=inData.m_data;      m_data=inData.m_data;
110    } else {    } else {
     #if defined DOPROF  
     profData->interpolate++;  
     #endif  
111      Data tmp(0,inData.getPointDataView().getShape(),functionspace,true);      Data tmp(0,inData.getPointDataView().getShape(),functionspace,true);
112      // Note: Must use a reference or pointer to a derived object      // Note: Must use a reference or pointer to a derived object
113      // in order to get polymorphic behaviour. Shouldn't really      // in order to get polymorphic behaviour. Shouldn't really
# Line 158  Data::Data(const DataTagged::TagListType Line 137  Data::Data(const DataTagged::TagListType
137    if (expanded) {    if (expanded) {
138      expand();      expand();
139    }    }
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
140  }  }
141    
142  Data::Data(const numeric::array& value,  Data::Data(const numeric::array& value,
# Line 170  Data::Data(const numeric::array& value, Line 145  Data::Data(const numeric::array& value,
145  {  {
146    initialise(value,what,expanded);    initialise(value,what,expanded);
147    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
148  }  }
149    
150  Data::Data(const DataArrayView& value,  Data::Data(const DataArrayView& value,
# Line 182  Data::Data(const DataArrayView& value, Line 153  Data::Data(const DataArrayView& value,
153  {  {
154    initialise(value,what,expanded);    initialise(value,what,expanded);
155    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
156  }  }
157    
158  Data::Data(const object& value,  Data::Data(const object& value,
# Line 195  Data::Data(const object& value, Line 162  Data::Data(const object& value,
162    numeric::array asNumArray(value);    numeric::array asNumArray(value);
163    initialise(asNumArray,what,expanded);    initialise(asNumArray,what,expanded);
164    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
165  }  }
166    
167    
168  Data::Data(const object& value,  Data::Data(const object& value,
169             const Data& other)             const Data& other)
170  {  {
171    
172      numeric::array asNumArray(value);
173    
174    
175      // extract the shape of the numarray
176      DataArrayView::ShapeType tempShape;
177      for (int i=0; i < asNumArray.getrank(); i++) {
178        tempShape.push_back(extract<int>(asNumArray.getshape()[i]));
179      }
180      // get the space for the data vector
181      int len = DataArrayView::noValues(tempShape);
182      DataVector temp_data(len, 0.0, len);
183      DataArrayView temp_dataView(temp_data, tempShape);
184      temp_dataView.copy(asNumArray);
185    
186    //    //
187    // Create DataConstant using the given value and all other parameters    // Create DataConstant using the given value and all other parameters
188    // copied from other. If value is a rank 0 object this Data    // copied from other. If value is a rank 0 object this Data
189    // will assume the point data shape of other.    // will assume the point data shape of other.
190    DataArray temp(value);  
191    if (temp.getView().getRank()==0) {    if (temp_dataView.getRank()==0) {
192      //      int len = DataArrayView::noValues(other.getPointDataView().getShape());
193      // Create a DataArray with the scalar value for all elements  
194      DataArray temp2(other.getPointDataView().getShape(),temp.getView()());      DataVector temp2_data(len, temp_dataView(), len);
195      initialise(temp2.getView(),other.getFunctionSpace(),false);      DataArrayView temp2_dataView(temp2_data, other.getPointDataView().getShape());
196        initialise(temp2_dataView, other.getFunctionSpace(), false);
197    
198    } else {    } else {
199      //      //
200      // Create a DataConstant with the same sample shape as other      // Create a DataConstant with the same sample shape as other
201      initialise(temp.getView(),other.getFunctionSpace(),false);      initialise(temp_dataView, other.getFunctionSpace(), false);
202    }    }
203    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
204  }  }
205    
206  Data::~Data()  Data::~Data()
# Line 266  Data::getShapeTuple() const Line 243  Data::getShapeTuple() const
243          throw DataException("Error - illegal Data rank.");          throw DataException("Error - illegal Data rank.");
244    }    }
245  }  }
   
246  void  void
247  Data::copy(const Data& other)  Data::copy(const Data& other)
248  {  {
# Line 319  Data::copy(const Data& other) Line 295  Data::copy(const Data& other)
295    throw DataException("Error - Copy not implemented for this Data type.");    throw DataException("Error - Copy not implemented for this Data type.");
296  }  }
297    
298    
299    void
300    Data::setToZero()
301    {
302      {
303        DataExpanded* temp=dynamic_cast<DataExpanded*>(m_data.get());
304        if (temp!=0) {
305           temp->setToZero();
306           return;
307        }
308      }
309      {
310        DataTagged* temp=dynamic_cast<DataTagged*>(m_data.get());
311        if (temp!=0) {
312          temp->setToZero();
313          return;
314        }
315      }
316      {
317        DataConstant* temp=dynamic_cast<DataConstant*>(m_data.get());
318        if (temp!=0) {
319          temp->setToZero();
320          return;
321        }
322      }
323      throw DataException("Error - Data can not be set to zero.");
324    }
325    
326  void  void
327  Data::copyWithMask(const Data& other,  Data::copyWithMask(const Data& other,
328                     const Data& mask)                     const Data& mask)
# Line 350  Data::isTagged() const Line 354  Data::isTagged() const
354    return (temp!=0);    return (temp!=0);
355  }  }
356    
 /* TODO */  
 /* global reduction -- the local data being empty does not imply that it is empty on other processers*/  
357  bool  bool
358  Data::isEmpty() const  Data::isEmpty() const
359  {  {
# Line 367  Data::isConstant() const Line 369  Data::isConstant() const
369  }  }
370    
371  void  void
372  Data::setProtection()  Data::setProtection()
373  {  {
374     m_protected=true;     m_protected=true;
375  }  }
376    
377  bool  bool
378  Data::isProtected() const  Data::isProtected() const
379  {  {
380     return m_protected;     return m_protected;
381  }  }
382    
# Line 422  Data::tag() Line 424  Data::tag()
424    }    }
425  }  }
426    
427  void  Data
428  Data::reshapeDataPoint(const DataArrayView::ShapeType& shape)  Data::oneOver() const
429  {  {
430    m_data->reshapeDataPoint(shape);    return C_TensorUnaryOperation(*this, bind1st(divides<double>(),1.));
431  }  }
432    
433  Data  Data
434  Data::wherePositive() const  Data::wherePositive() const
435  {  {
436  #if defined DOPROF    return C_TensorUnaryOperation(*this, bind2nd(greater<double>(),0.0));
   profData->where++;  
 #endif  
   return escript::unaryOp(*this,bind2nd(greater<double>(),0.0));  
437  }  }
438    
439  Data  Data
440  Data::whereNegative() const  Data::whereNegative() const
441  {  {
442  #if defined DOPROF    return C_TensorUnaryOperation(*this, bind2nd(less<double>(),0.0));
   profData->where++;  
 #endif  
   return escript::unaryOp(*this,bind2nd(less<double>(),0.0));  
443  }  }
444    
445  Data  Data
446  Data::whereNonNegative() const  Data::whereNonNegative() const
447  {  {
448  #if defined DOPROF    return C_TensorUnaryOperation(*this, bind2nd(greater_equal<double>(),0.0));
   profData->where++;  
 #endif  
   return escript::unaryOp(*this,bind2nd(greater_equal<double>(),0.0));  
449  }  }
450    
451  Data  Data
452  Data::whereNonPositive() const  Data::whereNonPositive() const
453  {  {
454  #if defined DOPROF    return C_TensorUnaryOperation(*this, bind2nd(less_equal<double>(),0.0));
   profData->where++;  
 #endif  
   return escript::unaryOp(*this,bind2nd(less_equal<double>(),0.0));  
455  }  }
456    
457  Data  Data
458  Data::whereZero(double tol) const  Data::whereZero(double tol) const
459  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
460    Data dataAbs=abs();    Data dataAbs=abs();
461    return escript::unaryOp(dataAbs,bind2nd(less_equal<double>(),tol));    return C_TensorUnaryOperation(dataAbs, bind2nd(less_equal<double>(),tol));
462  }  }
463    
464  Data  Data
465  Data::whereNonZero(double tol) const  Data::whereNonZero(double tol) const
466  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
467    Data dataAbs=abs();    Data dataAbs=abs();
468    return escript::unaryOp(dataAbs,bind2nd(greater<double>(),tol));    return C_TensorUnaryOperation(dataAbs, bind2nd(greater<double>(),tol));
469  }  }
470    
471  Data  Data
472  Data::interpolate(const FunctionSpace& functionspace) const  Data::interpolate(const FunctionSpace& functionspace) const
473  {  {
 #if defined DOPROF  
   profData->interpolate++;  
 #endif  
474    return Data(*this,functionspace);    return Data(*this,functionspace);
475  }  }
476    
# Line 511  Data::probeInterpolation(const FunctionS Line 492  Data::probeInterpolation(const FunctionS
492  Data  Data
493  Data::gradOn(const FunctionSpace& functionspace) const  Data::gradOn(const FunctionSpace& functionspace) const
494  {  {
495  #if defined DOPROF    double blocktimer_start = blocktimer_time();
   profData->grad++;  
 #endif  
496    if (functionspace.getDomain()!=getDomain())    if (functionspace.getDomain()!=getDomain())
497      throw DataException("Error - gradient cannot be calculated on different domains.");      throw DataException("Error - gradient cannot be calculated on different domains.");
498    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();
499    grad_shape.push_back(functionspace.getDim());    grad_shape.push_back(functionspace.getDim());
500    Data out(0.0,grad_shape,functionspace,true);    Data out(0.0,grad_shape,functionspace,true);
501    getDomain().setToGradient(out,*this);    getDomain().setToGradient(out,*this);
502      blocktimer_increment("grad()", blocktimer_start);
503    return out;    return out;
504  }  }
505    
# Line 547  Data::getDataPointShape() const Line 527  Data::getDataPointShape() const
527    return getPointDataView().getShape();    return getPointDataView().getShape();
528  }  }
529    
 void  
 Data::fillFromNumArray(const boost::python::numeric::array num_array)  
 {  
   if (isProtected()) {  
         throw DataException("Error - attempt to update protected Data object.");  
   }  
   //  
   // check rank  
   if (num_array.getrank()<getDataPointRank())  
       throw DataException("Rank of numarray does not match Data object rank");  
   
   //  
   // check shape of num_array  
   for (int i=0; i<getDataPointRank(); i++) {  
     if (extract<int>(num_array.getshape()[i+1])!=getDataPointShape()[i])  
        throw DataException("Shape of numarray does not match Data object rank");  
   }  
530    
   //  
   // make sure data is expanded:  
   if (!isExpanded()) {  
     expand();  
   }  
   
   //  
   // and copy over  
   m_data->copyAll(num_array);  
 }  
531    
532  const  const
533  boost::python::numeric::array  boost::python::numeric::array
534  Data::convertToNumArray()  Data:: getValueOfDataPoint(int dataPointNo)
535  {  {
536    //    size_t length=0;
537    // determine the total number of data points    int i, j, k, l;
   int numSamples = getNumSamples();  
   int numDataPointsPerSample = getNumDataPointsPerSample();  
   int numDataPoints = numSamples * numDataPointsPerSample;  
   
538    //    //
539    // determine the rank and shape of each data point    // determine the rank and shape of each data point
540    int dataPointRank = getDataPointRank();    int dataPointRank = getDataPointRank();
# Line 596  Data::convertToNumArray() Line 545  Data::convertToNumArray()
545    boost::python::numeric::array numArray(0.0);    boost::python::numeric::array numArray(0.0);
546    
547    //    //
548    // the rank of the returned numeric array will be the rank of    // the shape of the returned numeric array will be the same
549    // the data points, plus one. Where the rank of the array is n,    // as that of the data point
550    // the last n-1 dimensions will be equal to the shape of the    int arrayRank = dataPointRank;
551    // data points, whilst the first dimension will be equal to the    DataArrayView::ShapeType arrayShape = dataPointShape;
   // total number of data points. Thus the array will consist of  
   // a serial vector of the data points.  
   int arrayRank = dataPointRank + 1;  
   DataArrayView::ShapeType arrayShape;  
   arrayShape.push_back(numDataPoints);  
   for (int d=0; d<dataPointRank; d++) {  
      arrayShape.push_back(dataPointShape[d]);  
   }  
552    
553    //    //
554    // resize the numeric array to the shape just calculated    // resize the numeric array to the shape just calculated
555      if (arrayRank==0) {
556        numArray.resize(1);
557      }
558    if (arrayRank==1) {    if (arrayRank==1) {
559      numArray.resize(arrayShape[0]);      numArray.resize(arrayShape[0]);
560    }    }
# Line 623  Data::convertToNumArray() Line 567  Data::convertToNumArray()
567    if (arrayRank==4) {    if (arrayRank==4) {
568      numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3]);      numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3]);
569    }    }
   if (arrayRank==5) {  
     numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3],arrayShape[4]);  
   }  
570    
571    //    if (getNumDataPointsPerSample()>0) {
572    // loop through each data point in turn, loading the values for that data point         int sampleNo = dataPointNo/getNumDataPointsPerSample();
573    // into the numeric array.         int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();
574    int dataPoint = 0;         //
575    for (int sampleNo = 0; sampleNo < numSamples; sampleNo++) {         // Check a valid sample number has been supplied
576      for (int dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {         if ((sampleNo >= getNumSamples()) || (sampleNo < 0 )) {
577        DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);             throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");
578        if (dataPointRank==0) {         }
         numArray[dataPoint]=dataPointView();  
       }  
       if (dataPointRank==1) {  
         for (int i=0; i<dataPointShape[0]; i++) {  
           numArray[dataPoint][i]=dataPointView(i);  
         }  
       }  
       if (dataPointRank==2) {  
         for (int i=0; i<dataPointShape[0]; i++) {  
           for (int j=0; j<dataPointShape[1]; j++) {  
             numArray[dataPoint][i][j] = dataPointView(i,j);  
           }  
         }  
       }  
       if (dataPointRank==3) {  
         for (int i=0; i<dataPointShape[0]; i++) {  
           for (int j=0; j<dataPointShape[1]; j++) {  
             for (int k=0; k<dataPointShape[2]; k++) {  
               numArray[dataPoint][i][j][k]=dataPointView(i,j,k);  
             }  
           }  
         }  
       }  
       if (dataPointRank==4) {  
         for (int i=0; i<dataPointShape[0]; i++) {  
           for (int j=0; j<dataPointShape[1]; j++) {  
             for (int k=0; k<dataPointShape[2]; k++) {  
               for (int l=0; l<dataPointShape[3]; l++) {  
                 numArray[dataPoint][i][j][k][l]=dataPointView(i,j,k,l);  
               }  
             }  
           }  
         }  
       }  
       dataPoint++;  
     }  
   }  
579    
580           //
581           // Check a valid data point number has been supplied
582           if ((dataPointNoInSample >= getNumDataPointsPerSample()) || (dataPointNoInSample < 0)) {
583               throw DataException("Error - Data::convertToNumArray: invalid dataPointNoInSample.");
584           }
585           // TODO: global error handling
586           // create a view of the data if it is stored locally
587           DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);
588    
589           switch( dataPointRank ){
590                case 0 :
591                    numArray[0] = dataPointView();
592                    break;
593                case 1 :
594                    for( i=0; i<dataPointShape[0]; i++ )
595                        numArray[i]=dataPointView(i);
596                    break;
597                case 2 :
598                    for( i=0; i<dataPointShape[0]; i++ )
599                        for( j=0; j<dataPointShape[1]; j++)
600                            numArray[make_tuple(i,j)]=dataPointView(i,j);
601                    break;
602                case 3 :
603                    for( i=0; i<dataPointShape[0]; i++ )
604                        for( j=0; j<dataPointShape[1]; j++ )
605                            for( k=0; k<dataPointShape[2]; k++)
606                                numArray[make_tuple(i,j,k)]=dataPointView(i,j,k);
607                    break;
608                case 4 :
609                    for( i=0; i<dataPointShape[0]; i++ )
610                        for( j=0; j<dataPointShape[1]; j++ )
611                            for( k=0; k<dataPointShape[2]; k++ )
612                                for( l=0; l<dataPointShape[3]; l++)
613                                    numArray[make_tuple(i,j,k,l)]=dataPointView(i,j,k,l);
614                    break;
615        }
616      }
617    //    //
618    // return the loaded array    // return the array
619    return numArray;    return numArray;
 }  
620    
621  const  }
622  boost::python::numeric::array  void
623  Data::convertToNumArrayFromSampleNo(int sampleNo)  Data::setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object)
624  {  {
625    //      // this will throw if the value cannot be represented
626    // Check a valid sample number has been supplied      boost::python::numeric::array num_array(py_object);
627    if (sampleNo >= getNumSamples()) {      setValueOfDataPointToArray(dataPointNo,num_array);
     throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");  
   }  
628    
   //  
   // determine the number of data points per sample  
   int numDataPointsPerSample = getNumDataPointsPerSample();  
629    
630    //  }
   // determine the rank and shape of each data point  
   int dataPointRank = getDataPointRank();  
   DataArrayView::ShapeType dataPointShape = getDataPointShape();  
631    
632    void
633    Data::setValueOfDataPointToArray(int dataPointNo, const boost::python::numeric::array& num_array)
634    {
635      if (isProtected()) {
636            throw DataException("Error - attempt to update protected Data object.");
637      }
638    //    //
639    // create the numeric array to be returned    // check rank
640    boost::python::numeric::array numArray(0.0);    if (num_array.getrank()<getDataPointRank())
641          throw DataException("Rank of numarray does not match Data object rank");
642    
643    //    //
644    // the rank of the returned numeric array will be the rank of    // check shape of num_array
645    // the data points, plus one. Where the rank of the array is n,    for (int i=0; i<getDataPointRank(); i++) {
646    // the last n-1 dimensions will be equal to the shape of the      if (extract<int>(num_array.getshape()[i])!=getDataPointShape()[i])
647    // data points, whilst the first dimension will be equal to the         throw DataException("Shape of numarray does not match Data object rank");
   // total number of data points. Thus the array will consist of  
   // a serial vector of the data points.  
   int arrayRank = dataPointRank + 1;  
   DataArrayView::ShapeType arrayShape;  
   arrayShape.push_back(numDataPointsPerSample);  
   for (int d=0; d<dataPointRank; d++) {  
      arrayShape.push_back(dataPointShape[d]);  
648    }    }
   
649    //    //
650    // resize the numeric array to the shape just calculated    // make sure data is expanded:
651    if (arrayRank==1) {    if (!isExpanded()) {
652      numArray.resize(arrayShape[0]);      expand();
   }  
   if (arrayRank==2) {  
     numArray.resize(arrayShape[0],arrayShape[1]);  
   }  
   if (arrayRank==3) {  
     numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2]);  
   }  
   if (arrayRank==4) {  
     numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3]);  
653    }    }
654    if (arrayRank==5) {    if (getNumDataPointsPerSample()>0) {
655      numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3],arrayShape[4]);         int sampleNo = dataPointNo/getNumDataPointsPerSample();
656           int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();
657           m_data->copyToDataPoint(sampleNo, dataPointNoInSample,num_array);
658      } else {
659           m_data->copyToDataPoint(-1, 0,num_array);
660    }    }
661    }
662    
663    //  void
664    // loop through each data point in turn, loading the values for that data point  Data::setValueOfDataPoint(int dataPointNo, const double value)
665    // into the numeric array.  {
666    for (int dataPoint = 0; dataPoint < numDataPointsPerSample; dataPoint++) {    if (isProtected()) {
667      DataArrayView dataPointView = getDataPoint(sampleNo, dataPoint);          throw DataException("Error - attempt to update protected Data object.");
     if (dataPointRank==0) {  
       numArray[dataPoint]=dataPointView();  
     }  
     if (dataPointRank==1) {  
       for (int i=0; i<dataPointShape[0]; i++) {  
         numArray[dataPoint][i]=dataPointView(i);  
       }  
     }  
     if (dataPointRank==2) {  
       for (int i=0; i<dataPointShape[0]; i++) {  
         for (int j=0; j<dataPointShape[1]; j++) {  
           numArray[dataPoint][i][j] = dataPointView(i,j);  
         }  
       }  
     }  
     if (dataPointRank==3) {  
       for (int i=0; i<dataPointShape[0]; i++) {  
         for (int j=0; j<dataPointShape[1]; j++) {  
           for (int k=0; k<dataPointShape[2]; k++) {  
             numArray[dataPoint][i][j][k]=dataPointView(i,j,k);  
           }  
         }  
       }  
     }  
     if (dataPointRank==4) {  
       for (int i=0; i<dataPointShape[0]; i++) {  
         for (int j=0; j<dataPointShape[1]; j++) {  
           for (int k=0; k<dataPointShape[2]; k++) {  
             for (int l=0; l<dataPointShape[3]; l++) {  
               numArray[dataPoint][i][j][k][l]=dataPointView(i,j,k,l);  
             }  
           }  
         }  
       }  
     }  
668    }    }
   
669    //    //
670    // return the loaded array    // make sure data is expanded:
671    return numArray;    if (!isExpanded()) {
672        expand();
673      }
674      if (getNumDataPointsPerSample()>0) {
675           int sampleNo = dataPointNo/getNumDataPointsPerSample();
676           int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();
677           m_data->copyToDataPoint(sampleNo, dataPointNoInSample,value);
678      } else {
679           m_data->copyToDataPoint(-1, 0,value);
680      }
681  }  }
682    
683  const  const
684  boost::python::numeric::array  boost::python::numeric::array
685  Data::convertToNumArrayFromDPNo(int procNo,  Data::getValueOfGlobalDataPoint(int procNo, int dataPointNo)
                                 int sampleNo,  
                                                                 int dataPointNo)  
   
686  {  {
687      size_t length=0;    size_t length=0;
688      int i, j, k, l, pos;    int i, j, k, l, pos;
   
   //  
   // Check a valid sample number has been supplied  
   if (sampleNo >= getNumSamples()) {  
     throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");  
   }  
   
   //  
   // Check a valid data point number has been supplied  
   if (dataPointNo >= getNumDataPointsPerSample()) {  
     throw DataException("Error - Data::convertToNumArray: invalid dataPointNo.");  
   }  
   
689    //    //
690    // determine the rank and shape of each data point    // determine the rank and shape of each data point
691    int dataPointRank = getDataPointRank();    int dataPointRank = getDataPointRank();
# Line 835  Data::convertToNumArrayFromDPNo(int proc Line 719  Data::convertToNumArrayFromDPNo(int proc
719      numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3]);      numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3]);
720    }    }
721    
722      // added for the MPI communication    // added for the MPI communication
723      length=1;    length=1;
724      for( i=0; i<arrayRank; i++ )    for( i=0; i<arrayRank; i++ ) length *= arrayShape[i];
725          length *= arrayShape[i];    double *tmpData = new double[length];
     double *tmpData = new double[length];  
726    
727    //    //
728    // load the values for the data point into the numeric array.    // load the values for the data point into the numeric array.
729    
730      // updated for the MPI case      // updated for the MPI case
731      if( get_MPIRank()==procNo ){      if( get_MPIRank()==procNo ){
732                 if (getNumDataPointsPerSample()>0) {
733                    int sampleNo = dataPointNo/getNumDataPointsPerSample();
734                    int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();
735                    //
736                    // Check a valid sample number has been supplied
737                    if ((sampleNo >= getNumSamples()) || (sampleNo < 0 )) {
738                      throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");
739                    }
740    
741                    //
742                    // Check a valid data point number has been supplied
743                    if ((dataPointNoInSample >= getNumDataPointsPerSample()) || (dataPointNoInSample < 0)) {
744                      throw DataException("Error - Data::convertToNumArray: invalid dataPointNoInSample.");
745                    }
746                    // TODO: global error handling
747          // create a view of the data if it is stored locally          // create a view of the data if it is stored locally
748          DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);          DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);
749            
750          // pack the data from the view into tmpData for MPI communication          // pack the data from the view into tmpData for MPI communication
751          pos=0;          pos=0;
752          switch( dataPointRank ){          switch( dataPointRank ){
753              case 0 :              case 0 :
754                  tmpData[0] = dataPointView();                  tmpData[0] = dataPointView();
755                  break;                  break;
756              case 1 :                      case 1 :
757                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
758                      tmpData[i]=dataPointView(i);                      tmpData[i]=dataPointView(i);
759                  break;                  break;
760              case 2 :                      case 2 :
761                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
762                      for( j=0; j<dataPointShape[1]; j++, pos++ )                      for( j=0; j<dataPointShape[1]; j++, pos++ )
763                          tmpData[pos]=dataPointView(i,j);                          tmpData[pos]=dataPointView(i,j);
764                  break;                  break;
765              case 3 :                      case 3 :
766                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
767                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
768                          for( k=0; k<dataPointShape[2]; k++, pos++ )                          for( k=0; k<dataPointShape[2]; k++, pos++ )
# Line 878  Data::convertToNumArrayFromDPNo(int proc Line 776  Data::convertToNumArrayFromDPNo(int proc
776                                  tmpData[pos]=dataPointView(i,j,k,l);                                  tmpData[pos]=dataPointView(i,j,k,l);
777                  break;                  break;
778          }          }
779                }
780      }      }
781  #ifdef PASO_MPI          #ifdef PASO_MPI
782          // broadcast the data to all other processes          // broadcast the data to all other processes
783          MPI_Bcast( tmpData, length, MPI_DOUBLE, procNo, get_MPIComm() );      MPI_Bcast( tmpData, length, MPI_DOUBLE, procNo, get_MPIComm() );
784  #endif          #endif
785    
786      // unpack the data      // unpack the data
787      switch( dataPointRank ){      switch( dataPointRank ){
788          case 0 :          case 0 :
789              numArray[i]=tmpData[0];              numArray[0]=tmpData[0];
790              break;              break;
791          case 1 :                  case 1 :
792              for( i=0; i<dataPointShape[0]; i++ )              for( i=0; i<dataPointShape[0]; i++ )
793                  numArray[i]=tmpData[i];                  numArray[i]=tmpData[i];
794              break;              break;
795          case 2 :                  case 2 :
796              for( i=0; i<dataPointShape[0]; i++ )              for( i=0; i<dataPointShape[0]; i++ )
797                  for( j=0; j<dataPointShape[1]; j++ )                  for( j=0; j<dataPointShape[1]; j++ )
798                      tmpData[i+j*dataPointShape[0]];                     numArray[make_tuple(i,j)]=tmpData[i+j*dataPointShape[0]];
799              break;              break;
800          case 3 :                  case 3 :
801              for( i=0; i<dataPointShape[0]; i++ )              for( i=0; i<dataPointShape[0]; i++ )
802                  for( j=0; j<dataPointShape[1]; j++ )                  for( j=0; j<dataPointShape[1]; j++ )
803                      for( k=0; k<dataPointShape[2]; k++ )                      for( k=0; k<dataPointShape[2]; k++ )
804                          tmpData[i+dataPointShape[0]*(j*+k*dataPointShape[1])];                          numArray[make_tuple(i,j,k)]=tmpData[i+dataPointShape[0]*(j*+k*dataPointShape[1])];
805              break;              break;
806          case 4 :          case 4 :
807              for( i=0; i<dataPointShape[0]; i++ )              for( i=0; i<dataPointShape[0]; i++ )
808                  for( j=0; j<dataPointShape[1]; j++ )                  for( j=0; j<dataPointShape[1]; j++ )
809                      for( k=0; k<dataPointShape[2]; k++ )                      for( k=0; k<dataPointShape[2]; k++ )
810                          for( l=0; l<dataPointShape[3]; l++ )                          for( l=0; l<dataPointShape[3]; l++ )
811                              tmpData[i+dataPointShape[0]*(j*+dataPointShape[1]*(k+l*dataPointShape[2]))];                                  numArray[make_tuple(i,j,k,l)]=tmpData[i+dataPointShape[0]*(j*+dataPointShape[1]*(k+l*dataPointShape[2]))];
812              break;              break;
813      }      }
814    
815      delete [] tmpData;        delete [] tmpData;
 /*  
   if (dataPointRank==0) {  
     numArray[0]=dataPointView();  
   }  
   if (dataPointRank==1) {  
     for (int i=0; i<dataPointShape[0]; i++) {  
       numArray[i]=dataPointView(i);  
     }  
   }  
   if (dataPointRank==2) {  
     for (int i=0; i<dataPointShape[0]; i++) {  
       for (int j=0; j<dataPointShape[1]; j++) {  
         numArray[i][j] = dataPointView(i,j);  
       }  
     }  
   }  
   if (dataPointRank==3) {  
     for (int i=0; i<dataPointShape[0]; i++) {  
       for (int j=0; j<dataPointShape[1]; j++) {  
         for (int k=0; k<dataPointShape[2]; k++) {  
           numArray[i][j][k]=dataPointView(i,j,k);  
         }  
       }  
     }  
   }  
   if (dataPointRank==4) {  
     for (int i=0; i<dataPointShape[0]; i++) {  
       for (int j=0; j<dataPointShape[1]; j++) {  
         for (int k=0; k<dataPointShape[2]; k++) {  
           for (int l=0; l<dataPointShape[3]; l++) {  
             numArray[i][j][k][l]=dataPointView(i,j,k,l);  
           }  
         }  
       }  
     }  
   }  
 */  
   
816    //    //
817    // return the loaded array    // return the loaded array
818    return numArray;    return numArray;
819  }  }
820    
821    
822    
823  boost::python::numeric::array  boost::python::numeric::array
824  Data::integrate() const  Data::integrate() const
825  {  {
826    int index;    int index;
827    int rank = getDataPointRank();    int rank = getDataPointRank();
828    DataArrayView::ShapeType shape = getDataPointShape();    DataArrayView::ShapeType shape = getDataPointShape();
829      int dataPointSize = getDataPointSize();
 #if defined DOPROF  
   profData->integrate++;  
 #endif  
830    
831    //    //
832    // calculate the integral values    // calculate the integral values
833    vector<double> integrals(getDataPointSize());    vector<double> integrals(dataPointSize);
834      vector<double> integrals_local(dataPointSize);
835    #ifdef PASO_MPI
836      AbstractContinuousDomain::asAbstractContinuousDomain(getDomain()).setToIntegrals(integrals_local,*this);
837      // Global sum: use an array instead of a vector because elements of array are guaranteed to be contiguous in memory
838      double *tmp = new double[dataPointSize];
839      double *tmp_local = new double[dataPointSize];
840      for (int i=0; i<dataPointSize; i++) { tmp_local[i] = integrals_local[i]; }
841      MPI_Allreduce( &tmp_local[0], &tmp[0], dataPointSize, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
842      for (int i=0; i<dataPointSize; i++) { integrals[i] = tmp[i]; }
843      delete[] tmp;
844      delete[] tmp_local;
845    #else
846    AbstractContinuousDomain::asAbstractContinuousDomain(getDomain()).setToIntegrals(integrals,*this);    AbstractContinuousDomain::asAbstractContinuousDomain(getDomain()).setToIntegrals(integrals,*this);
847    #endif
848    
849    //    //
850    // create the numeric array to be returned    // create the numeric array to be returned
# Line 1031  Data::integrate() const Line 904  Data::integrate() const
904  Data  Data
905  Data::sin() const  Data::sin() const
906  {  {
907  #if defined DOPROF    return C_TensorUnaryOperation<double (*)(double)>(*this, ::sin);
   profData->unary++;  
 #endif  
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sin);  
908  }  }
909    
910  Data  Data
911  Data::cos() const  Data::cos() const
912  {  {
913  #if defined DOPROF    return C_TensorUnaryOperation<double (*)(double)>(*this, ::cos);
   profData->unary++;  
 #endif  
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cos);  
914  }  }
915    
916  Data  Data
917  Data::tan() const  Data::tan() const
918  {  {
919  #if defined DOPROF    return C_TensorUnaryOperation<double (*)(double)>(*this, ::tan);
   profData->unary++;  
 #endif  
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tan);  
920  }  }
921    
922  Data  Data
923  Data::asin() const  Data::asin() const
924  {  {
925  #if defined DOPROF    return C_TensorUnaryOperation<double (*)(double)>(*this, ::asin);
   profData->unary++;  
 #endif  
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asin);  
926  }  }
927    
928  Data  Data
929  Data::acos() const  Data::acos() const
930  {  {
931  #if defined DOPROF    return C_TensorUnaryOperation<double (*)(double)>(*this, ::acos);
   profData->unary++;  
 #endif  
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acos);  
932  }  }
933    
934    
935  Data  Data
936  Data::atan() const  Data::atan() const
937  {  {
938  #if defined DOPROF    return C_TensorUnaryOperation<double (*)(double)>(*this, ::atan);
   profData->unary++;  
 #endif  
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atan);  
939  }  }
940    
941  Data  Data
942  Data::sinh() const  Data::sinh() const
943  {  {
944  #if defined DOPROF      return C_TensorUnaryOperation<double (*)(double)>(*this, ::sinh);
945    profData->unary++;  
 #endif  
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sinh);  
946  }  }
947    
948  Data  Data
949  Data::cosh() const  Data::cosh() const
950  {  {
951  #if defined DOPROF      return C_TensorUnaryOperation<double (*)(double)>(*this, ::cosh);
   profData->unary++;  
 #endif  
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cosh);  
952  }  }
953    
954  Data  Data
955  Data::tanh() const  Data::tanh() const
956  {  {
957  #if defined DOPROF      return C_TensorUnaryOperation<double (*)(double)>(*this, ::tanh);
958    profData->unary++;  }
959    
960    
961    Data
962    Data::erf() const
963    {
964    #ifdef _WIN32
965      throw DataException("Error - Data:: erf function is not supported on _WIN32 platforms.");
966    #else
967      return C_TensorUnaryOperation(*this, ::erf);
968  #endif  #endif
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tanh);  
969  }  }
970    
971  Data  Data
972  Data::asinh() const  Data::asinh() const
973  {  {
974  #if defined DOPROF  #ifdef _WIN32
975    profData->unary++;    return C_TensorUnaryOperation(*this, escript::asinh_substitute);
976    #else
977      return C_TensorUnaryOperation(*this, ::asinh);
978  #endif  #endif
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asinh);  
979  }  }
980    
981  Data  Data
982  Data::acosh() const  Data::acosh() const
983  {  {
984  #if defined DOPROF  #ifdef _WIN32
985    profData->unary++;    return C_TensorUnaryOperation(*this, escript::acosh_substitute);
986    #else
987      return C_TensorUnaryOperation(*this, ::acosh);
988  #endif  #endif
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acosh);  
989  }  }
990    
991  Data  Data
992  Data::atanh() const  Data::atanh() const
993  {  {
994  #if defined DOPROF  #ifdef _WIN32
995    profData->unary++;    return C_TensorUnaryOperation(*this, escript::atanh_substitute);
996    #else
997      return C_TensorUnaryOperation(*this, ::atanh);
998  #endif  #endif
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atanh);  
999  }  }
1000    
1001  Data  Data
1002  Data::log10() const  Data::log10() const
1003  {  {
1004  #if defined DOPROF    return C_TensorUnaryOperation<double (*)(double)>(*this, ::log10);
   profData->unary++;  
 #endif  
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log10);  
1005  }  }
1006    
1007  Data  Data
1008  Data::log() const  Data::log() const
1009  {  {
1010  #if defined DOPROF    return C_TensorUnaryOperation<double (*)(double)>(*this, ::log);
   profData->unary++;  
 #endif  
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);  
1011  }  }
1012    
1013  Data  Data
1014  Data::sign() const  Data::sign() const
1015  {  {
1016  #if defined DOPROF    return C_TensorUnaryOperation(*this, escript::fsign);
   profData->unary++;  
 #endif  
   return escript::unaryOp(*this,escript::fsign);  
1017  }  }
1018    
1019  Data  Data
1020  Data::abs() const  Data::abs() const
1021  {  {
1022  #if defined DOPROF    return C_TensorUnaryOperation<double (*)(double)>(*this, ::fabs);
   profData->unary++;  
 #endif  
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);  
1023  }  }
1024    
1025  Data  Data
1026  Data::neg() const  Data::neg() const
1027  {  {
1028  #if defined DOPROF    return C_TensorUnaryOperation(*this, negate<double>());
   profData->unary++;  
 #endif  
   return escript::unaryOp(*this,negate<double>());  
1029  }  }
1030    
1031  Data  Data
1032  Data::pos() const  Data::pos() const
1033  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
1034    Data result;    Data result;
1035    // perform a deep copy    // perform a deep copy
1036    result.copy(*this);    result.copy(*this);
# Line 1196  Data::pos() const Line 1040  Data::pos() const
1040  Data  Data
1041  Data::exp() const  Data::exp() const
1042  {  {
1043  #if defined DOPROF    return C_TensorUnaryOperation<double (*)(double)>(*this, ::exp);
   profData->unary++;  
 #endif  
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);  
1044  }  }
1045    
1046  Data  Data
1047  Data::sqrt() const  Data::sqrt() const
1048  {  {
1049  #if defined DOPROF    return C_TensorUnaryOperation<double (*)(double)>(*this, ::sqrt);
   profData->unary++;  
 #endif  
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);  
1050  }  }
1051    
1052  double  double
1053  Data::Lsup() const  Data::Lsup() const
1054  {  {
1055    double localValue, globalValue;    double localValue, globalValue;
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
1056    //    //
1057    // set the initial absolute maximum value to zero    // set the initial absolute maximum value to zero
1058    
# Line 1232  Data::Lsup() const Line 1067  Data::Lsup() const
1067  }  }
1068    
1069  double  double
 Data::Linf() const  
 {  
   double localValue, globalValue;  
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
   //  
   // 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  
1070  Data::sup() const  Data::sup() const
1071  {  {
1072    double localValue, globalValue;    double localValue, globalValue;
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
1073    //    //
1074    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1075    FMax fmax_func;    FMax fmax_func;
# Line 1274  double Line 1086  double
1086  Data::inf() const  Data::inf() const
1087  {  {
1088    double localValue, globalValue;    double localValue, globalValue;
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
1089    //    //
1090    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1091    FMin fmin_func;    FMin fmin_func;
# Line 1294  Data::inf() const Line 1103  Data::inf() const
1103  Data  Data
1104  Data::maxval() const  Data::maxval() const
1105  {  {
 #if defined DOPROF  
   profData->reduction2++;  
 #endif  
1106    //    //
1107    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1108    FMax fmax_func;    FMax fmax_func;
# Line 1306  Data::maxval() const Line 1112  Data::maxval() const
1112  Data  Data
1113  Data::minval() const  Data::minval() const
1114  {  {
 #if defined DOPROF  
   profData->reduction2++;  
 #endif  
1115    //    //
1116    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1117    FMin fmin_func;    FMin fmin_func;
# Line 1319  Data Line 1122  Data
1122  Data::swapaxes(const int axis0, const int axis1) const  Data::swapaxes(const int axis0, const int axis1) const
1123  {  {
1124       int axis0_tmp,axis1_tmp;       int axis0_tmp,axis1_tmp;
      #if defined DOPROF  
      profData->unary++;  
      #endif  
1125       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1126       DataArrayView::ShapeType ev_shape;       DataArrayView::ShapeType ev_shape;
1127       // 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]
# Line 1348  Data::swapaxes(const int axis0, const in Line 1148  Data::swapaxes(const int axis0, const in
1148       }       }
1149       for (int i=0; i<rank; i++) {       for (int i=0; i<rank; i++) {
1150         if (i == axis0_tmp) {         if (i == axis0_tmp) {
1151            ev_shape.push_back(s[axis1_tmp]);            ev_shape.push_back(s[axis1_tmp]);
1152         } else if (i == axis1_tmp) {         } else if (i == axis1_tmp) {
1153            ev_shape.push_back(s[axis0_tmp]);            ev_shape.push_back(s[axis0_tmp]);
1154         } else {         } else {
1155            ev_shape.push_back(s[i]);            ev_shape.push_back(s[i]);
1156         }         }
1157       }       }
1158       Data ev(0.,ev_shape,getFunctionSpace());       Data ev(0.,ev_shape,getFunctionSpace());
# Line 1365  Data::swapaxes(const int axis0, const in Line 1165  Data::swapaxes(const int axis0, const in
1165  Data  Data
1166  Data::symmetric() const  Data::symmetric() const
1167  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1168       // check input       // check input
1169       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1170       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1171          if(s[0] != s[1])          if(s[0] != s[1])
1172             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.");
1173       }       }
1174       else if (getDataPointRank()==4) {       else if (getDataPointRank()==4) {
# Line 1390  Data::symmetric() const Line 1187  Data::symmetric() const
1187  Data  Data
1188  Data::nonsymmetric() const  Data::nonsymmetric() const
1189  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1190       // check input       // check input
1191       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1192       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1193          if(s[0] != s[1])          if(s[0] != s[1])
1194             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.");
1195          DataArrayView::ShapeType ev_shape;          DataArrayView::ShapeType ev_shape;
1196          ev_shape.push_back(s[0]);          ev_shape.push_back(s[0]);
# Line 1427  Data::nonsymmetric() const Line 1221  Data::nonsymmetric() const
1221  Data  Data
1222  Data::trace(int axis_offset) const  Data::trace(int axis_offset) const
1223  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1224       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1225       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1226          DataArrayView::ShapeType ev_shape;          DataArrayView::ShapeType ev_shape;
# Line 1480  Data::trace(int axis_offset) const Line 1271  Data::trace(int axis_offset) const
1271  Data  Data
1272  Data::transpose(int axis_offset) const  Data::transpose(int axis_offset) const
1273  {  {
      #if defined DOPROF  
      profData->unary++;  
      #endif  
1274       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1275       DataArrayView::ShapeType ev_shape;       DataArrayView::ShapeType ev_shape;
1276       // 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]
# Line 1504  Data::transpose(int axis_offset) const Line 1292  Data::transpose(int axis_offset) const
1292  Data  Data
1293  Data::eigenvalues() const  Data::eigenvalues() const
1294  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1295       // check input       // check input
1296       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1297       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
1298          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.");
1299       if(s[0] != s[1])       if(s[0] != s[1])
1300          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.");
1301       // create return       // create return
1302       DataArrayView::ShapeType ev_shape(1,s[0]);       DataArrayView::ShapeType ev_shape(1,s[0]);
# Line 1524  Data::eigenvalues() const Line 1309  Data::eigenvalues() const
1309  const boost::python::tuple  const boost::python::tuple
1310  Data::eigenvalues_and_eigenvectors(const double tol) const  Data::eigenvalues_and_eigenvectors(const double tol) const
1311  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1312       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1313       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
1314          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.");
1315       if(s[0] != s[1])       if(s[0] != s[1])
1316          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.");
1317       // create return       // create return
1318       DataArrayView::ShapeType ev_shape(1,s[0]);       DataArrayView::ShapeType ev_shape(1,s[0]);
# Line 1544  Data::eigenvalues_and_eigenvectors(const Line 1326  Data::eigenvalues_and_eigenvectors(const
1326  }  }
1327    
1328  const boost::python::tuple  const boost::python::tuple
1329  Data::mindp() const  Data::minGlobalDataPoint() const
1330  {  {
1331    // NB: calc_mindp had to be split off from mindp as boost::make_tuple causes an    // NB: calc_minGlobalDataPoint( had to be split off from minGlobalDataPoint( as boost::make_tuple causes an
1332    // abort (for unknown reasons) if there are openmp directives with it in the    // abort (for unknown reasons) if there are openmp directives with it in the
1333    // surrounding function    // surrounding function
1334    
   int SampleNo;  
1335    int DataPointNo;    int DataPointNo;
1336      int ProcNo;    int ProcNo;
1337    calc_mindp(ProcNo,SampleNo,DataPointNo);    calc_minGlobalDataPoint(ProcNo,DataPointNo);
1338    return make_tuple(ProcNo,SampleNo,DataPointNo);    return make_tuple(ProcNo,DataPointNo);
1339  }  }
1340    
1341  void  void
1342  Data::calc_mindp(   int& ProcNo,  Data::calc_minGlobalDataPoint(int& ProcNo,
1343                  int& SampleNo,                          int& DataPointNo) const
         int& DataPointNo) const  
1344  {  {
1345    int i,j;    int i,j;
1346    int lowi=0,lowj=0;    int lowi=0,lowj=0;
# Line 1602  Data::calc_mindp(  int& ProcNo, Line 1382  Data::calc_mindp(  int& ProcNo,
1382      int lowProc = 0;      int lowProc = 0;
1383      double *globalMins = new double[get_MPISize()+1];      double *globalMins = new double[get_MPISize()+1];
1384      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() );
1385        
1386      if( get_MPIRank()==0 ){      if( get_MPIRank()==0 ){
1387          next = globalMins[lowProc];          next = globalMins[lowProc];
1388          for( i=1; i<get_MPISize(); i++ )          for( i=1; i<get_MPISize(); i++ )
# Line 1618  Data::calc_mindp(  int& ProcNo, Line 1398  Data::calc_mindp(  int& ProcNo,
1398  #else  #else
1399      ProcNo = 0;      ProcNo = 0;
1400  #endif  #endif
1401    SampleNo = lowi;    DataPointNo = lowj + lowi * numDPPSample;
   DataPointNo = lowj;  
1402  }  }
1403    
1404  void  void
# Line 1646  Data::operator+=(const Data& right) Line 1425  Data::operator+=(const Data& right)
1425    if (isProtected()) {    if (isProtected()) {
1426          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
1427    }    }
 #if defined DOPROF  
   profData->binary++;  
 #endif  
1428    binaryOp(right,plus<double>());    binaryOp(right,plus<double>());
1429    return (*this);    return (*this);
1430  }  }
# Line 1656  Data::operator+=(const Data& right) Line 1432  Data::operator+=(const Data& right)
1432  Data&  Data&
1433  Data::operator+=(const boost::python::object& right)  Data::operator+=(const boost::python::object& right)
1434  {  {
1435    if (isProtected()) {    Data tmp(right,getFunctionSpace(),false);
1436          throw DataException("Error - attempt to update protected Data object.");    binaryOp(tmp,plus<double>());
1437    }    return (*this);
1438  #if defined DOPROF  }
1439    profData->binary++;  Data&
1440  #endif  Data::operator=(const Data& other)
1441    binaryOp(right,plus<double>());  {
1442      copy(other);
1443    return (*this);    return (*this);
1444  }  }
1445    
# Line 1672  Data::operator-=(const Data& right) Line 1449  Data::operator-=(const Data& right)
1449    if (isProtected()) {    if (isProtected()) {
1450          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
1451    }    }
 #if defined DOPROF  
   profData->binary++;  
 #endif  
1452    binaryOp(right,minus<double>());    binaryOp(right,minus<double>());
1453    return (*this);    return (*this);
1454  }  }
# Line 1682  Data::operator-=(const Data& right) Line 1456  Data::operator-=(const Data& right)
1456  Data&  Data&
1457  Data::operator-=(const boost::python::object& right)  Data::operator-=(const boost::python::object& right)
1458  {  {
1459    if (isProtected()) {    Data tmp(right,getFunctionSpace(),false);
1460          throw DataException("Error - attempt to update protected Data object.");    binaryOp(tmp,minus<double>());
   }  
 #if defined DOPROF  
   profData->binary++;  
 #endif  
   binaryOp(right,minus<double>());  
1461    return (*this);    return (*this);
1462  }  }
1463    
# Line 1698  Data::operator*=(const Data& right) Line 1467  Data::operator*=(const Data& right)
1467    if (isProtected()) {    if (isProtected()) {
1468          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
1469    }    }
 #if defined DOPROF  
   profData->binary++;  
 #endif  
1470    binaryOp(right,multiplies<double>());    binaryOp(right,multiplies<double>());
1471    return (*this);    return (*this);
1472  }  }
# Line 1708  Data::operator*=(const Data& right) Line 1474  Data::operator*=(const Data& right)
1474  Data&  Data&
1475  Data::operator*=(const boost::python::object& right)  Data::operator*=(const boost::python::object& right)
1476  {  {
1477    if (isProtected()) {    Data tmp(right,getFunctionSpace(),false);
1478          throw DataException("Error - attempt to update protected Data object.");    binaryOp(tmp,multiplies<double>());
   }  
 #if defined DOPROF  
   profData->binary++;  
 #endif  
   binaryOp(right,multiplies<double>());  
1479    return (*this);    return (*this);
1480  }  }
1481    
# Line 1724  Data::operator/=(const Data& right) Line 1485  Data::operator/=(const Data& right)
1485    if (isProtected()) {    if (isProtected()) {
1486          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
1487    }    }
 #if defined DOPROF  
   profData->binary++;  
 #endif  
1488    binaryOp(right,divides<double>());    binaryOp(right,divides<double>());
1489    return (*this);    return (*this);
1490  }  }
# Line 1734  Data::operator/=(const Data& right) Line 1492  Data::operator/=(const Data& right)
1492  Data&  Data&
1493  Data::operator/=(const boost::python::object& right)  Data::operator/=(const boost::python::object& right)
1494  {  {
1495    if (isProtected()) {    Data tmp(right,getFunctionSpace(),false);
1496          throw DataException("Error - attempt to update protected Data object.");    binaryOp(tmp,divides<double>());
   }  
 #if defined DOPROF  
   profData->binary++;  
 #endif  
   binaryOp(right,divides<double>());  
1497    return (*this);    return (*this);
1498  }  }
1499    
1500  Data  Data
1501  Data::rpowO(const boost::python::object& left) const  Data::rpowO(const boost::python::object& left) const
1502  {  {
   if (isProtected()) {  
         throw DataException("Error - attempt to update protected Data object.");  
   }  
 #if defined DOPROF  
   profData->binary++;  
 #endif  
1503    Data left_d(left,*this);    Data left_d(left,*this);
1504    return left_d.powD(*this);    return left_d.powD(*this);
1505  }  }
# Line 1760  Data::rpowO(const boost::python::object& Line 1507  Data::rpowO(const boost::python::object&
1507  Data  Data
1508  Data::powO(const boost::python::object& right) const  Data::powO(const boost::python::object& right) const
1509  {  {
1510  #if defined DOPROF    Data tmp(right,getFunctionSpace(),false);
1511    profData->binary++;    return powD(tmp);
 #endif  
   Data result;  
   result.copy(*this);  
   result.binaryOp(right,(Data::BinaryDFunPtr)::pow);  
   return result;  
1512  }  }
1513    
1514  Data  Data
1515  Data::powD(const Data& right) const  Data::powD(const Data& right) const
1516  {  {
1517  #if defined DOPROF    return C_TensorBinaryOperation<double (*)(double, double)>(*this, right, ::pow);
   profData->binary++;  
 #endif  
   Data result;  
   result.copy(*this);  
   result.binaryOp(right,(Data::BinaryDFunPtr)::pow);  
   return result;  
1518  }  }
1519    
   
1520  //  //
1521  // NOTE: It is essential to specify the namespace this operator belongs to  // NOTE: It is essential to specify the namespace this operator belongs to
1522  Data  Data
1523  escript::operator+(const Data& left, const Data& right)  escript::operator+(const Data& left, const Data& right)
1524  {  {
1525    Data result;    return C_TensorBinaryOperation(left, right, plus<double>());
   //  
   // perform a deep copy  
   result.copy(left);  
   result+=right;  
   return result;  
1526  }  }
1527    
1528  //  //
# Line 1800  escript::operator+(const Data& left, con Line 1530  escript::operator+(const Data& left, con
1530  Data  Data
1531  escript::operator-(const Data& left, const Data& right)  escript::operator-(const Data& left, const Data& right)
1532  {  {
1533    Data result;    return C_TensorBinaryOperation(left, right, minus<double>());
   //  
   // perform a deep copy  
   result.copy(left);  
   result-=right;  
   return result;  
1534  }  }
1535    
1536  //  //
# Line 1813  escript::operator-(const Data& left, con Line 1538  escript::operator-(const Data& left, con
1538  Data  Data
1539  escript::operator*(const Data& left, const Data& right)  escript::operator*(const Data& left, const Data& right)
1540  {  {
1541    Data result;    return C_TensorBinaryOperation(left, right, multiplies<double>());
   //  
   // perform a deep copy  
   result.copy(left);  
   result*=right;  
   return result;  
1542  }  }
1543    
1544  //  //
# Line 1826  escript::operator*(const Data& left, con Line 1546  escript::operator*(const Data& left, con
1546  Data  Data
1547  escript::operator/(const Data& left, const Data& right)  escript::operator/(const Data& left, const Data& right)
1548  {  {
1549    Data result;    return C_TensorBinaryOperation(left, right, divides<double>());
   //  
   // perform a deep copy  
   result.copy(left);  
   result/=right;  
   return result;  
1550  }  }
1551    
1552  //  //
# Line 1839  escript::operator/(const Data& left, con Line 1554  escript::operator/(const Data& left, con
1554  Data  Data
1555  escript::operator+(const Data& left, const boost::python::object& right)  escript::operator+(const Data& left, const boost::python::object& right)
1556  {  {
1557    //    return left+Data(right,left.getFunctionSpace(),false);
   // Convert to DataArray format if possible  
   DataArray temp(right);  
   Data result;  
   //  
   // perform a deep copy  
   result.copy(left);  
   result+=right;  
   return result;  
1558  }  }
1559    
1560  //  //
# Line 1855  escript::operator+(const Data& left, con Line 1562  escript::operator+(const Data& left, con
1562  Data  Data
1563  escript::operator-(const Data& left, const boost::python::object& right)  escript::operator-(const Data& left, const boost::python::object& right)
1564  {  {
1565    //    return left-Data(right,left.getFunctionSpace(),false);
   // Convert to DataArray format if possible  
   DataArray temp(right);  
   Data result;  
   //  
   // perform a deep copy  
   result.copy(left);  
   result-=right;  
   return result;  
1566  }  }
1567    
1568  //  //
# Line 1871  escript::operator-(const Data& left, con Line 1570  escript::operator-(const Data& left, con
1570  Data  Data
1571  escript::operator*(const Data& left, const boost::python::object& right)  escript::operator*(const Data& left, const boost::python::object& right)
1572  {  {
1573    //    return left*Data(right,left.getFunctionSpace(),false);
   // Convert to DataArray format if possible  
   DataArray temp(right);  
   Data result;  
   //  
   // perform a deep copy  
   result.copy(left);  
   result*=right;  
   return result;  
1574  }  }
1575    
1576  //  //
# Line 1887  escript::operator*(const Data& left, con Line 1578  escript::operator*(const Data& left, con
1578  Data  Data
1579  escript::operator/(const Data& left, const boost::python::object& right)  escript::operator/(const Data& left, const boost::python::object& right)
1580  {  {
1581    //    return left/Data(right,left.getFunctionSpace(),false);
   // Convert to DataArray format if possible  
   DataArray temp(right);  
   Data result;  
   //  
   // perform a deep copy  
   result.copy(left);  
   result/=right;  
   return result;  
1582  }  }
1583    
1584  //  //
# Line 1903  escript::operator/(const Data& left, con Line 1586  escript::operator/(const Data& left, con
1586  Data  Data
1587  escript::operator+(const boost::python::object& left, const Data& right)  escript::operator+(const boost::python::object& left, const Data& right)
1588  {  {
1589    //    return Data(left,right.getFunctionSpace(),false)+right;
   // Construct the result using the given value and the other parameters  
   // from right  
   Data result(left,right);  
   result+=right;  
   return result;  
1590  }  }
1591    
1592  //  //
# Line 1916  escript::operator+(const boost::python:: Line 1594  escript::operator+(const boost::python::
1594  Data  Data
1595  escript::operator-(const boost::python::object& left, const Data& right)  escript::operator-(const boost::python::object& left, const Data& right)
1596  {  {
1597    //    return Data(left,right.getFunctionSpace(),false)-right;
   // Construct the result using the given value and the other parameters  
   // from right  
   Data result(left,right);  
   result-=right;  
   return result;  
1598  }  }
1599    
1600  //  //
# Line 1929  escript::operator-(const boost::python:: Line 1602  escript::operator-(const boost::python::
1602  Data  Data
1603  escript::operator*(const boost::python::object& left, const Data& right)  escript::operator*(const boost::python::object& left, const Data& right)
1604  {  {
1605    //    return Data(left,right.getFunctionSpace(),false)*right;
   // Construct the result using the given value and the other parameters  
   // from right  
   Data result(left,right);  
   result*=right;  
   return result;  
1606  }  }
1607    
1608  //  //
# Line 1942  escript::operator*(const boost::python:: Line 1610  escript::operator*(const boost::python::
1610  Data  Data
1611  escript::operator/(const boost::python::object& left, const Data& right)  escript::operator/(const boost::python::object& left, const Data& right)
1612  {  {
1613    //    return Data(left,right.getFunctionSpace(),false)/right;
   // Construct the result using the given value and the other parameters  
   // from right  
   Data result(left,right);  
   result/=right;  
   return result;  
1614  }  }
1615    
1616  //  //
# Line 1998  escript::operator/(const boost::python:: Line 1661  escript::operator/(const boost::python::
1661  /* TODO */  /* TODO */
1662  /* global reduction */  /* global reduction */
1663  Data  Data
1664  Data::getItem(const boost::python::object& key) const  Data::getItem(const boost::python::object& key) const
1665  {  {
1666    const DataArrayView& view=getPointDataView();    const DataArrayView& view=getPointDataView();
1667    
# Line 2016  Data::getItem(const boost::python::objec Line 1679  Data::getItem(const boost::python::objec
1679  Data  Data
1680  Data::getSlice(const DataArrayView::RegionType& region) const  Data::getSlice(const DataArrayView::RegionType& region) const
1681  {  {
 #if defined DOPROF  
   profData->slicing++;  
 #endif  
1682    return Data(*this,region);    return Data(*this,region);
1683  }  }
1684    
# Line 2032  Data::setItemO(const boost::python::obje Line 1692  Data::setItemO(const boost::python::obje
1692    setItemD(key,tempData);    setItemD(key,tempData);
1693  }  }
1694    
 /* TODO */  
 /* global reduction */  
1695  void  void
1696  Data::setItemD(const boost::python::object& key,  Data::setItemD(const boost::python::object& key,
1697                 const Data& value)                 const Data& value)
# Line 2051  Data::setItemD(const boost::python::obje Line 1709  Data::setItemD(const boost::python::obje
1709    }    }
1710  }  }
1711    
 /* TODO */  
 /* global reduction */  
1712  void  void
1713  Data::setSlice(const Data& value,  Data::setSlice(const Data& value,
1714                 const DataArrayView::RegionType& region)                 const DataArrayView::RegionType& region)
# Line 2060  Data::setSlice(const Data& value, Line 1716  Data::setSlice(const Data& value,
1716    if (isProtected()) {    if (isProtected()) {
1717          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
1718    }    }
 #if defined DOPROF  
   profData->slicing++;  
 #endif  
1719    Data tempValue(value);    Data tempValue(value);
1720    typeMatchLeft(tempValue);    typeMatchLeft(tempValue);
1721    typeMatchRight(tempValue);    typeMatchRight(tempValue);
# Line 2097  Data::typeMatchRight(const Data& right) Line 1750  Data::typeMatchRight(const Data& right)
1750    }    }
1751  }  }
1752    
1753  /* TODO */  void
1754  /* global reduction */  Data::setTaggedValueByName(std::string name,
1755                               const boost::python::object& value)
1756    {
1757         if (getFunctionSpace().getDomain().isValidTagName(name)) {
1758            int tagKey=getFunctionSpace().getDomain().getTag(name);
1759            setTaggedValue(tagKey,value);
1760         }
1761    }
1762  void  void
1763  Data::setTaggedValue(int tagKey,  Data::setTaggedValue(int tagKey,
1764                       const boost::python::object& value)                       const boost::python::object& value)
# Line 2108  Data::setTaggedValue(int tagKey, Line 1768  Data::setTaggedValue(int tagKey,
1768    }    }
1769    //    //
1770    // Ensure underlying data object is of type DataTagged    // Ensure underlying data object is of type DataTagged
1771    tag();    if (isConstant()) tag();
1772    
1773      numeric::array asNumArray(value);
1774    
1775    if (!isTagged()) {  
1776      throw DataException("Error - DataTagged conversion failed!!");    // extract the shape of the numarray
1777      DataArrayView::ShapeType tempShape;
1778      for (int i=0; i < asNumArray.getrank(); i++) {
1779        tempShape.push_back(extract<int>(asNumArray.getshape()[i]));
1780    }    }
1781    
1782    //    // get the space for the data vector
1783    // Construct DataArray from boost::python::object input value    int len = DataArrayView::noValues(tempShape);
1784    DataArray valueDataArray(value);    DataVector temp_data(len, 0.0, len);
1785      DataArrayView temp_dataView(temp_data, tempShape);
1786      temp_dataView.copy(asNumArray);
1787    
1788    //    //
1789    // Call DataAbstract::setTaggedValue    // Call DataAbstract::setTaggedValue
1790    m_data->setTaggedValue(tagKey,valueDataArray.getView());    m_data->setTaggedValue(tagKey,temp_dataView);
1791  }  }
1792    
 /* TODO */  
 /* global reduction */  
1793  void  void
1794  Data::setTaggedValueFromCPP(int tagKey,  Data::setTaggedValueFromCPP(int tagKey,
1795                              const DataArrayView& value)                              const DataArrayView& value)
# Line 2134  Data::setTaggedValueFromCPP(int tagKey, Line 1799  Data::setTaggedValueFromCPP(int tagKey,
1799    }    }
1800    //    //
1801    // Ensure underlying data object is of type DataTagged    // Ensure underlying data object is of type DataTagged
1802    tag();    if (isConstant()) tag();
1803    
   if (!isTagged()) {  
     throw DataException("Error - DataTagged conversion failed!!");  
   }  
                                                                                                                 
1804    //    //
1805    // Call DataAbstract::setTaggedValue    // Call DataAbstract::setTaggedValue
1806    m_data->setTaggedValue(tagKey,value);    m_data->setTaggedValue(tagKey,value);
1807  }  }
1808    
 /* TODO */  
 /* global reduction */  
1809  int  int
1810  Data::getTagNumber(int dpno)  Data::getTagNumber(int dpno)
1811  {  {
1812    return m_data->getTagNumber(dpno);    return getFunctionSpace().getTagFromSampleNo(dpno);
 }  
   
 /* TODO */  
 /* global reduction */  
 void  
 Data::setRefValue(int ref,  
                   const boost::python::numeric::array& value)  
 {  
   if (isProtected()) {  
         throw DataException("Error - attempt to update protected Data object.");  
   }  
   //  
   // Construct DataArray from boost::python::object input value  
   DataArray valueDataArray(value);  
   
   //  
   // Call DataAbstract::setRefValue  
   m_data->setRefValue(ref,valueDataArray);  
 }  
   
 /* TODO */  
 /* global reduction */  
 void  
 Data::getRefValue(int ref,  
                   boost::python::numeric::array& value)  
 {  
   //  
   // Construct DataArray for boost::python::object return value  
   DataArray valueDataArray(value);  
   
   //  
   // Load DataArray with values from data-points specified by ref  
   m_data->getRefValue(ref,valueDataArray);  
   
   //  
   // Load values from valueDataArray into return numarray  
   
   // extract the shape of the numarray  
   int rank = value.getrank();  
   DataArrayView::ShapeType shape;  
   for (int i=0; i < rank; i++) {  
     shape.push_back(extract<int>(value.getshape()[i]));  
   }  
   
   // and load the numarray with the data from the DataArray  
   DataArrayView valueView = valueDataArray.getView();  
   
   if (rank==0) {  
       boost::python::numeric::array temp_numArray(valueView());  
       value = temp_numArray;  
   }  
   if (rank==1) {  
     for (int i=0; i < shape[0]; i++) {  
       value[i] = valueView(i);  
     }  
   }  
   if (rank==2) {  
     for (int i=0; i < shape[0]; i++) {  
       for (int j=0; j < shape[1]; j++) {  
         value[i][j] = valueView(i,j);  
       }  
     }  
   }  
   if (rank==3) {  
     for (int i=0; i < shape[0]; i++) {  
       for (int j=0; j < shape[1]; j++) {  
         for (int k=0; k < shape[2]; k++) {  
           value[i][j][k] = valueView(i,j,k);  
         }  
       }  
     }  
   }  
   if (rank==4) {  
     for (int i=0; i < shape[0]; i++) {  
       for (int j=0; j < shape[1]; j++) {  
         for (int k=0; k < shape[2]; k++) {  
           for (int l=0; l < shape[3]; l++) {  
             value[i][j][k][l] = valueView(i,j,k,l);  
           }  
         }  
       }  
     }  
   }  
   
1813  }  }
1814    
1815  void  void
# Line 2278  Data::archiveData(const std::string file Line 1853  Data::archiveData(const std::string file
1853    DataArrayView::ShapeType dataPointShape = getDataPointShape();    DataArrayView::ShapeType dataPointShape = getDataPointShape();
1854    vector<int> referenceNumbers(noSamples);    vector<int> referenceNumbers(noSamples);
1855    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {
1856      referenceNumbers[sampleNo] = getFunctionSpace().getReferenceNoFromSampleNo(sampleNo);      referenceNumbers[sampleNo] = getFunctionSpace().getReferenceIDOfSample(sampleNo);
1857    }    }
1858    vector<int> tagNumbers(noSamples);    vector<int> tagNumbers(noSamples);
1859    if (isTagged()) {    if (isTagged()) {
# Line 2487  Data::extractData(const std::string file Line 2062  Data::extractData(const std::string file
2062      throw DataException("extractData Error: incompatible FunctionSpace");      throw DataException("extractData Error: incompatible FunctionSpace");
2063    }    }
2064    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {
2065      if (referenceNumbers[sampleNo] != fspace.getReferenceNoFromSampleNo(sampleNo)) {      if (referenceNumbers[sampleNo] != fspace.getReferenceIDOfSample(sampleNo)) {
2066        throw DataException("extractData Error: incompatible FunctionSpace");        throw DataException("extractData Error: incompatible FunctionSpace");
2067      }      }
2068    }    }
# Line 2584  escript::C_GeneralTensorProduct(Data& ar Line 2159  escript::C_GeneralTensorProduct(Data& ar
2159                       int axis_offset,                       int axis_offset,
2160                       int transpose)                       int transpose)
2161  {  {
2162    // General tensor product: arg_2(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)
2163    // 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().
2164    
   #if defined DOPROF  
     // profData->binary++;  
   #endif  
   
2165    // Interpolate if necessary and find an appropriate function space    // Interpolate if necessary and find an appropriate function space
2166    Data arg_Z;    Data arg_0_Z, arg_1_Z;
2167    if (arg_0.getFunctionSpace()!=arg_1.getFunctionSpace()) {    if (arg_0.getFunctionSpace()!=arg_1.getFunctionSpace()) {
2168      if (arg_0.probeInterpolation(arg_1.getFunctionSpace())) {      if (arg_0.probeInterpolation(arg_1.getFunctionSpace())) {
2169        arg_Z = arg_0.interpolate(arg_1.getFunctionSpace());        arg_0_Z = arg_0.interpolate(arg_1.getFunctionSpace());
2170        // arg_0=arg_Z;        arg_1_Z = Data(arg_1);
2171      }      }
2172      else if (arg_1.probeInterpolation(arg_0.getFunctionSpace())) {      else if (arg_1.probeInterpolation(arg_0.getFunctionSpace())) {
2173        arg_1=arg_1.interpolate(arg_0.getFunctionSpace());        arg_1_Z=arg_1.interpolate(arg_0.getFunctionSpace());
2174          arg_0_Z =Data(arg_0);
2175      }      }
2176      else {      else {
2177        throw DataException("Error - C_GeneralTensorProduct: arguments have incompatible function spaces.");        throw DataException("Error - C_GeneralTensorProduct: arguments have incompatible function spaces.");
2178      }      }
2179      } else {
2180          arg_0_Z = Data(arg_0);
2181          arg_1_Z = Data(arg_1);
2182    }    }
2183    // Get rank and shape of inputs    // Get rank and shape of inputs
2184    int rank0 = arg_Z.getDataPointRank();    int rank0 = arg_0_Z.getDataPointRank();
2185    int rank1 = arg_1.getDataPointRank();    int rank1 = arg_1_Z.getDataPointRank();
2186    DataArrayView::ShapeType shape0 = arg_Z.getDataPointShape();    DataArrayView::ShapeType shape0 = arg_0_Z.getDataPointShape();
2187    DataArrayView::ShapeType shape1 = arg_1.getDataPointShape();    DataArrayView::ShapeType shape1 = arg_1_Z.getDataPointShape();
2188    
2189    // Prepare for the loops of the product and verify compatibility of shapes    // Prepare for the loops of the product and verify compatibility of shapes
2190    int start0=0, start1=0;    int start0=0, start1=0;
# Line 2655  escript::C_GeneralTensorProduct(Data& ar Line 2230  escript::C_GeneralTensorProduct(Data& ar
2230    
2231    // Define the shape of the output    // Define the shape of the output
2232    DataArrayView::ShapeType shape2;    DataArrayView::ShapeType shape2;
2233    for (int i=0; i<rank0-axis_offset; i++) { shape2.push_back(tmpShape0[i]); } // First part of arg_Z    for (int i=0; i<rank0-axis_offset; i++) { shape2.push_back(tmpShape0[i]); } // First part of arg_0_Z
2234    for (int i=axis_offset; i<rank1; i++)   { shape2.push_back(tmpShape1[i]); } // Last part of arg_1    for (int i=axis_offset; i<rank1; i++)   { shape2.push_back(tmpShape1[i]); } // Last part of arg_1_Z
2235    
2236    // Declare output Data object    // Declare output Data object
2237    Data arg_2;    Data res;
2238    
2239    if      (arg_Z.isConstant()   && arg_1.isConstant()) {    if      (arg_0_Z.isConstant()   && arg_1_Z.isConstant()) {
2240      arg_2 = Data(0.0, shape2, arg_1.getFunctionSpace());    // DataConstant output      res = Data(0.0, shape2, arg_1_Z.getFunctionSpace());    // DataConstant output
2241      double *ptr_0 = &((arg_Z.getPointDataView().getData())[0]);      double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[0]);
2242      double *ptr_1 = &((arg_1.getPointDataView().getData())[0]);      double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[0]);
2243      double *ptr_2 = &((arg_2.getPointDataView().getData())[0]);      double *ptr_2 = &((res.getPointDataView().getData())[0]);
2244      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);
2245    }    }
2246    else if (arg_Z.isConstant()   && arg_1.isTagged()) {    else if (arg_0_Z.isConstant()   && arg_1_Z.isTagged()) {
2247    
2248      // Prepare the DataConstant input      // Prepare the DataConstant input
2249      DataConstant* tmp_0=dynamic_cast<DataConstant*>(arg_Z.borrowData());      DataConstant* tmp_0=dynamic_cast<DataConstant*>(arg_0_Z.borrowData());
2250      if (tmp_0==0) { throw DataException("GTP Programming error - casting to DataConstant."); }      if (tmp_0==0) { throw DataException("GTP Programming error - casting to DataConstant."); }
2251    
2252      // Borrow DataTagged input from Data object      // Borrow DataTagged input from Data object
2253      DataTagged* tmp_1=dynamic_cast<DataTagged*>(arg_1.borrowData());      DataTagged* tmp_1=dynamic_cast<DataTagged*>(arg_1_Z.borrowData());
2254      if (tmp_1==0) { throw DataException("GTP_1 Programming error - casting to DataTagged."); }      if (tmp_1==0) { throw DataException("GTP_1 Programming error - casting to DataTagged."); }
2255    
2256      // Prepare a DataTagged output 2      // Prepare a DataTagged output 2
2257      arg_2 = Data(0.0, shape2, arg_1.getFunctionSpace());    // DataTagged output      res = Data(0.0, shape2, arg_1_Z.getFunctionSpace());    // DataTagged output
2258      arg_2.tag();      res.tag();
2259      DataTagged* tmp_2=dynamic_cast<DataTagged*>(arg_2.borrowData());      DataTagged* tmp_2=dynamic_cast<DataTagged*>(res.borrowData());
2260      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataTagged."); }      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataTagged."); }
2261    
2262      // Prepare offset into DataConstant      // Prepare offset into DataConstant
2263      int offset_0 = tmp_0->getPointOffset(0,0);      int offset_0 = tmp_0->getPointOffset(0,0);
2264      double *ptr_0 = &((arg_Z.getPointDataView().getData())[offset_0]);      double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);
2265      // Get the views      // Get the views
2266      DataArrayView view_1 = tmp_1->getDefaultValue();      DataArrayView view_1 = tmp_1->getDefaultValue();
2267      DataArrayView view_2 = tmp_2->getDefaultValue();      DataArrayView view_2 = tmp_2->getDefaultValue();
# Line 2708  escript::C_GeneralTensorProduct(Data& ar Line 2283  escript::C_GeneralTensorProduct(Data& ar
2283      }      }
2284    
2285    }    }
2286    else if (arg_Z.isConstant()   && arg_1.isExpanded()) {    else if (arg_0_Z.isConstant()   && arg_1_Z.isExpanded()) {
2287    
2288      arg_2 = Data(0.0, shape2, arg_1.getFunctionSpace(),true); // DataExpanded output      res = Data(0.0, shape2, arg_1_Z.getFunctionSpace(),true); // DataExpanded output
2289      DataConstant* tmp_0=dynamic_cast<DataConstant*>(arg_Z.borrowData());      DataConstant* tmp_0=dynamic_cast<DataConstant*>(arg_0_Z.borrowData());
2290      DataExpanded* tmp_1=dynamic_cast<DataExpanded*>(arg_1.borrowData());      DataExpanded* tmp_1=dynamic_cast<DataExpanded*>(arg_1_Z.borrowData());
2291      DataExpanded* tmp_2=dynamic_cast<DataExpanded*>(arg_2.borrowData());      DataExpanded* tmp_2=dynamic_cast<DataExpanded*>(res.borrowData());
2292      if (tmp_0==0) { throw DataException("GTP Programming error - casting to DataConstant."); }      if (tmp_0==0) { throw DataException("GTP Programming error - casting to DataConstant."); }
2293      if (tmp_1==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }      if (tmp_1==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }
2294      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }
2295      int sampleNo_1,dataPointNo_1;      int sampleNo_1,dataPointNo_1;
2296      int numSamples_1 = arg_1.getNumSamples();      int numSamples_1 = arg_1_Z.getNumSamples();
2297      int numDataPointsPerSample_1 = arg_1.getNumDataPointsPerSample();      int numDataPointsPerSample_1 = arg_1_Z.getNumDataPointsPerSample();
2298      int offset_0 = tmp_0->getPointOffset(0,0);      int offset_0 = tmp_0->getPointOffset(0,0);
2299      #pragma omp parallel for private(sampleNo_1,dataPointNo_1) schedule(static)      #pragma omp parallel for private(sampleNo_1,dataPointNo_1) schedule(static)
2300      for (sampleNo_1 = 0; sampleNo_1 < numSamples_1; sampleNo_1++) {      for (sampleNo_1 = 0; sampleNo_1 < numSamples_1; sampleNo_1++) {
2301        for (dataPointNo_1 = 0; dataPointNo_1 < numDataPointsPerSample_1; dataPointNo_1++) {        for (dataPointNo_1 = 0; dataPointNo_1 < numDataPointsPerSample_1; dataPointNo_1++) {
2302          int offset_1 = tmp_1->getPointOffset(sampleNo_1,dataPointNo_1);          int offset_1 = tmp_1->getPointOffset(sampleNo_1,dataPointNo_1);
2303          int offset_2 = tmp_2->getPointOffset(sampleNo_1,dataPointNo_1);          int offset_2 = tmp_2->getPointOffset(sampleNo_1,dataPointNo_1);
2304          double *ptr_0 = &((arg_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);
2305          double *ptr_1 = &((arg_1.getPointDataView().getData())[offset_1]);          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);
2306          double *ptr_2 = &((arg_2.getPointDataView().getData())[offset_2]);          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);
2307          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);
2308        }        }
2309      }      }
2310    
2311    }    }
2312    else if (arg_Z.isTagged()     && arg_1.isConstant()) {    else if (arg_0_Z.isTagged()     && arg_1_Z.isConstant()) {
2313    
2314      // Borrow DataTagged input from Data object      // Borrow DataTagged input from Data object
2315      DataTagged* tmp_0=dynamic_cast<DataTagged*>(arg_Z.borrowData());      DataTagged* tmp_0=dynamic_cast<DataTagged*>(arg_0_Z.borrowData());
2316      if (tmp_0==0) { throw DataException("GTP_0 Programming error - casting to DataTagged."); }      if (tmp_0==0) { throw DataException("GTP_0 Programming error - casting to DataTagged."); }
2317    
2318      // Prepare the DataConstant input      // Prepare the DataConstant input
2319      DataConstant* tmp_1=dynamic_cast<DataConstant*>(arg_1.borrowData());      DataConstant* tmp_1=dynamic_cast<DataConstant*>(arg_1_Z.borrowData());
2320      if (tmp_1==0) { throw DataException("GTP Programming error - casting to DataConstant."); }      if (tmp_1==0) { throw DataException("GTP Programming error - casting to DataConstant."); }
2321    
2322      // Prepare a DataTagged output 2      // Prepare a DataTagged output 2
2323      arg_2 = Data(0.0, shape2, arg_Z.getFunctionSpace());    // DataTagged output      res = Data(0.0, shape2, arg_0_Z.getFunctionSpace());    // DataTagged output
2324      arg_2.tag();      res.tag();
2325      DataTagged* tmp_2=dynamic_cast<DataTagged*>(arg_2.borrowData());      DataTagged* tmp_2=dynamic_cast<DataTagged*>(res.borrowData());
2326      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataTagged."); }      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataTagged."); }
2327    
2328      // Prepare offset into DataConstant      // Prepare offset into DataConstant
2329      int offset_1 = tmp_1->getPointOffset(0,0);      int offset_1 = tmp_1->getPointOffset(0,0);
2330      double *ptr_1 = &((arg_1.getPointDataView().getData())[offset_1]);      double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);
2331      // Get the views      // Get the views
2332      DataArrayView view_0 = tmp_0->getDefaultValue();      DataArrayView view_0 = tmp_0->getDefaultValue();
2333      DataArrayView view_2 = tmp_2->getDefaultValue();      DataArrayView view_2 = tmp_2->getDefaultValue();
# Line 2774  escript::C_GeneralTensorProduct(Data& ar Line 2349  escript::C_GeneralTensorProduct(Data& ar
2349      }      }
2350    
2351    }    }
2352    else if (arg_Z.isTagged()     && arg_1.isTagged()) {    else if (arg_0_Z.isTagged()     && arg_1_Z.isTagged()) {
2353    
2354      // Borrow DataTagged input from Data object      // Borrow DataTagged input from Data object
2355      DataTagged* tmp_0=dynamic_cast<DataTagged*>(arg_Z.borrowData());      DataTagged* tmp_0=dynamic_cast<DataTagged*>(arg_0_Z.borrowData());
2356      if (tmp_0==0) { throw DataException("GTP Programming error - casting to DataTagged."); }      if (tmp_0==0) { throw DataException("GTP Programming error - casting to DataTagged."); }
2357    
2358      // Borrow DataTagged input from Data object      // Borrow DataTagged input from Data object
2359      DataTagged* tmp_1=dynamic_cast<DataTagged*>(arg_1.borrowData());      DataTagged* tmp_1=dynamic_cast<DataTagged*>(arg_1_Z.borrowData());
2360      if (tmp_1==0) { throw DataException("GTP Programming error - casting to DataTagged."); }      if (tmp_1==0) { throw DataException("GTP Programming error - casting to DataTagged."); }
2361    
2362      // Prepare a DataTagged output 2      // Prepare a DataTagged output 2
2363      arg_2 = Data(0.0, shape2, arg_1.getFunctionSpace());      res = Data(0.0, shape2, arg_1_Z.getFunctionSpace());
2364      arg_2.tag();    // DataTagged output      res.tag();  // DataTagged output
2365      DataTagged* tmp_2=dynamic_cast<DataTagged*>(arg_2.borrowData());      DataTagged* tmp_2=dynamic_cast<DataTagged*>(res.borrowData());
2366      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataTagged."); }      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataTagged."); }
2367    
2368      // Get the views      // Get the views
# Line 2823  escript::C_GeneralTensorProduct(Data& ar Line 2398  escript::C_GeneralTensorProduct(Data& ar
2398      }      }
2399    
2400    }    }
2401    else if (arg_Z.isTagged()     && arg_1.isExpanded()) {    else if (arg_0_Z.isTagged()     && arg_1_Z.isExpanded()) {
2402    
2403      // After finding a common function space above the two inputs have the same numSamples and num DPPS      // After finding a common function space above the two inputs have the same numSamples and num DPPS
2404      arg_2 = Data(0.0, shape2, arg_1.getFunctionSpace(),true); // DataExpanded output      res = Data(0.0, shape2, arg_1_Z.getFunctionSpace(),true); // DataExpanded output
2405      DataTagged*   tmp_0=dynamic_cast<DataTagged*>(arg_Z.borrowData());      DataTagged*   tmp_0=dynamic_cast<DataTagged*>(arg_0_Z.borrowData());
2406      DataExpanded* tmp_1=dynamic_cast<DataExpanded*>(arg_1.borrowData());      DataExpanded* tmp_1=dynamic_cast<DataExpanded*>(arg_1_Z.borrowData());
2407      DataExpanded* tmp_2=dynamic_cast<DataExpanded*>(arg_2.borrowData());      DataExpanded* tmp_2=dynamic_cast<DataExpanded*>(res.borrowData());
2408      if (tmp_0==0) { throw DataException("GTP Programming error - casting to DataTagged."); }      if (tmp_0==0) { throw DataException("GTP Programming error - casting to DataTagged."); }
2409      if (tmp_1==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }      if (tmp_1==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }
2410      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }
2411      int sampleNo_0,dataPointNo_0;      int sampleNo_0,dataPointNo_0;
2412      int numSamples_0 = arg_Z.getNumSamples();      int numSamples_0 = arg_0_Z.getNumSamples();
2413      int numDataPointsPerSample_0 = arg_Z.getNumDataPointsPerSample();      int numDataPointsPerSample_0 = arg_0_Z.getNumDataPointsPerSample();
2414      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)
2415      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {
2416        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
2417        double *ptr_0 = &((arg_Z.getPointDataView().getData())[offset_0]);        double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);
2418        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {
2419          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);
2420          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2421          double *ptr_1 = &((arg_1.getPointDataView().getData())[offset_1]);          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);
2422          double *ptr_2 = &((arg_2.getPointDataView().getData())[offset_2]);          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);
2423          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);
2424        }        }
2425      }      }
2426    
2427    }    }
2428    else if (arg_Z.isExpanded()   && arg_1.isConstant()) {    else if (arg_0_Z.isExpanded()   && arg_1_Z.isConstant()) {
2429    
2430      arg_2 = Data(0.0, shape2, arg_1.getFunctionSpace(),true); // DataExpanded output      res = Data(0.0, shape2, arg_1_Z.getFunctionSpace(),true); // DataExpanded output
2431      DataExpanded* tmp_0=dynamic_cast<DataExpanded*>(arg_Z.borrowData());      DataExpanded* tmp_0=dynamic_cast<DataExpanded*>(arg_0_Z.borrowData());
2432      DataConstant* tmp_1=dynamic_cast<DataConstant*>(arg_1.borrowData());      DataConstant* tmp_1=dynamic_cast<DataConstant*>(arg_1_Z.borrowData());
2433      DataExpanded* tmp_2=dynamic_cast<DataExpanded*>(arg_2.borrowData());      DataExpanded* tmp_2=dynamic_cast<DataExpanded*>(res.borrowData());
2434      if (tmp_0==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }      if (tmp_0==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }
2435      if (tmp_1==0) { throw DataException("GTP Programming error - casting to DataConstant."); }      if (tmp_1==0) { throw DataException("GTP Programming error - casting to DataConstant."); }
2436      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }
2437      int sampleNo_0,dataPointNo_0;      int sampleNo_0,dataPointNo_0;
2438      int numSamples_0 = arg_Z.getNumSamples();      int numSamples_0 = arg_0_Z.getNumSamples();
2439      int numDataPointsPerSample_0 = arg_Z.getNumDataPointsPerSample();      int numDataPointsPerSample_0 = arg_0_Z.getNumDataPointsPerSample();
2440      int offset_1 = tmp_1->getPointOffset(0,0);      int offset_1 = tmp_1->getPointOffset(0,0);
2441      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)
2442      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {
2443        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {
2444          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);
2445          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2446          double *ptr_0 = &((arg_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);
2447          double *ptr_1 = &((arg_1.getPointDataView().getData())[offset_1]);          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);
2448          double *ptr_2 = &((arg_2.getPointDataView().getData())[offset_2]);          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);
2449          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);
2450        }        }
2451      }      }
2452    
2453    
2454    }    }
2455    else if (arg_Z.isExpanded()   && arg_1.isTagged()) {    else if (arg_0_Z.isExpanded()   && arg_1_Z.isTagged()) {
2456    
2457      // After finding a common function space above the two inputs have the same numSamples and num DPPS      // After finding a common function space above the two inputs have the same numSamples and num DPPS
2458      arg_2 = Data(0.0, shape2, arg_1.getFunctionSpace(),true); // DataExpanded output      res = Data(0.0, shape2, arg_1_Z.getFunctionSpace(),true); // DataExpanded output
2459      DataExpanded* tmp_0=dynamic_cast<DataExpanded*>(arg_Z.borrowData());      DataExpanded* tmp_0=dynamic_cast<DataExpanded*>(arg_0_Z.borrowData());
2460      DataTagged*   tmp_1=dynamic_cast<DataTagged*>(arg_1.borrowData());      DataTagged*   tmp_1=dynamic_cast<DataTagged*>(arg_1_Z.borrowData());
2461      DataExpanded* tmp_2=dynamic_cast<DataExpanded*>(arg_2.borrowData());      DataExpanded* tmp_2=dynamic_cast<DataExpanded*>(res.borrowData());
2462      if (tmp_0==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }      if (tmp_0==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }
2463      if (tmp_1==0) { throw DataException("GTP Programming error - casting to DataTagged."); }      if (tmp_1==0) { throw DataException("GTP Programming error - casting to DataTagged."); }
2464      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }
2465      int sampleNo_0,dataPointNo_0;      int sampleNo_0,dataPointNo_0;
2466      int numSamples_0 = arg_Z.getNumSamples();      int numSamples_0 = arg_0_Z.getNumSamples();
2467      int numDataPointsPerSample_0 = arg_Z.getNumDataPointsPerSample();      int numDataPointsPerSample_0 = arg_0_Z.getNumDataPointsPerSample();
2468      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)
2469      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {
2470        int offset_1 = tmp_1->getPointOffset(sampleNo_0,0);        int offset_1 = tmp_1->getPointOffset(sampleNo_0,0);
2471        double *ptr_1 = &((arg_1.getPointDataView().getData())[offset_1]);        double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);
2472        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {
2473          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);
2474          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2475          double *ptr_0 = &((arg_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);
2476          double *ptr_2 = &((arg_2.getPointDataView().getData())[offset_2]);          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);
2477          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);
2478        }        }
2479      }      }
2480    
2481    }    }
2482    else if (arg_Z.isExpanded()   && arg_1.isExpanded()) {    else if (arg_0_Z.isExpanded()   && arg_1_Z.isExpanded()) {
2483    
2484      // After finding a common function space above the two inputs have the same numSamples and num DPPS      // After finding a common function space above the two inputs have the same numSamples and num DPPS
2485      arg_2 = Data(0.0, shape2, arg_1.getFunctionSpace(),true); // DataExpanded output      res = Data(0.0, shape2, arg_1_Z.getFunctionSpace(),true); // DataExpanded output
2486      DataExpanded* tmp_0=dynamic_cast<DataExpanded*>(arg_Z.borrowData());      DataExpanded* tmp_0=dynamic_cast<DataExpanded*>(arg_0_Z.borrowData());
2487      DataExpanded* tmp_1=dynamic_cast<DataExpanded*>(arg_1.borrowData());      DataExpanded* tmp_1=dynamic_cast<DataExpanded*>(arg_1_Z.borrowData());
2488      DataExpanded* tmp_2=dynamic_cast<DataExpanded*>(arg_2.borrowData());      DataExpanded* tmp_2=dynamic_cast<DataExpanded*>(res.borrowData());
2489      if (tmp_0==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }      if (tmp_0==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }
2490      if (tmp_1==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }      if (tmp_1==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }
2491      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataExpanded."); }
2492      int sampleNo_0,dataPointNo_0;      int sampleNo_0,dataPointNo_0;
2493      int numSamples_0 = arg_Z.getNumSamples();      int numSamples_0 = arg_0_Z.getNumSamples();
2494      int numDataPointsPerSample_0 = arg_Z.getNumDataPointsPerSample();      int numDataPointsPerSample_0 = arg_0_Z.getNumDataPointsPerSample();
2495      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)
2496      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {
2497        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {
2498          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);
2499          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);
2500          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2501          double *ptr_0 = &((arg_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);
2502          double *ptr_1 = &((arg_1.getPointDataView().getData())[offset_1]);          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);
2503          double *ptr_2 = &((arg_2.getPointDataView().getData())[offset_2]);          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);
2504          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);
2505        }        }
2506      }      }
# Line 2935  escript::C_GeneralTensorProduct(Data& ar Line 2510  escript::C_GeneralTensorProduct(Data& ar
2510      throw DataException("Error - C_GeneralTensorProduct: unknown combination of inputs");      throw DataException("Error - C_GeneralTensorProduct: unknown combination of inputs");
2511    }    }
2512    
2513    return arg_2;    return res;
2514  }  }
2515    
2516  DataAbstract*  DataAbstract*
# Line 2947  Data::borrowData() const Line 2522  Data::borrowData() const
2522  /* Member functions specific to the MPI implementation */  /* Member functions specific to the MPI implementation */
2523    
2524  void  void
2525  Data::print()  Data::print()
2526  {  {
2527    int i,j;    int i,j;
2528      
2529    printf( "Data is %dX%d\n", getNumSamples(), getNumDataPointsPerSample() );    printf( "Data is %dX%d\n", getNumSamples(), getNumDataPointsPerSample() );
2530    for( i=0; i<getNumSamples(); i++ )    for( i=0; i<getNumSamples(); i++ )
2531    {    {
# Line 2960  Data::print() Line 2535  Data::print()
2535      printf( "\n" );      printf( "\n" );
2536    }    }
2537  }  }
2538    void
2539    Data::dump(const std::string fileName) const
2540    {
2541      try
2542         {
2543            return m_data->dump(fileName);
2544         }
2545         catch (exception& e)
2546         {
2547            cout << e.what() << endl;
2548         }
2549    }
2550    
2551  int  int
2552  Data::get_MPISize() const  Data::get_MPISize() const
# Line 2987  Data::get_MPIRank() const Line 2574  Data::get_MPIRank() const
2574    
2575  MPI_Comm  MPI_Comm
2576  Data::get_MPIComm() const  Data::get_MPIComm() const
2577  {  {
2578  #ifdef PASO_MPI  #ifdef PASO_MPI
2579      return MPI_COMM_WORLD;      return MPI_COMM_WORLD;
2580  #else  #else

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

  ViewVC Help
Powered by ViewVC 1.1.26