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

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

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

revision 922 by gross, Fri Jan 5 04:23:05 2007 UTC revision 1319 by matt, Thu Sep 27 00:27:51 2007 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(temp_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 365  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 423  Data::tag() Line 427  Data::tag()
427  Data  Data
428  Data::oneOver() const  Data::oneOver() const
429  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
430    return escript::unaryOp(*this,bind1st(divides<double>(),1.));    return escript::unaryOp(*this,bind1st(divides<double>(),1.));
431  }  }
432    
433  Data  Data
434  Data::wherePositive() const  Data::wherePositive() const
435  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
436    return escript::unaryOp(*this,bind2nd(greater<double>(),0.0));    return escript::unaryOp(*this,bind2nd(greater<double>(),0.0));
437  }  }
438    
439  Data  Data
440  Data::whereNegative() const  Data::whereNegative() const
441  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
442    return escript::unaryOp(*this,bind2nd(less<double>(),0.0));    return escript::unaryOp(*this,bind2nd(less<double>(),0.0));
443  }  }
444    
445  Data  Data
446  Data::whereNonNegative() const  Data::whereNonNegative() const
447  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
448    return escript::unaryOp(*this,bind2nd(greater_equal<double>(),0.0));    return escript::unaryOp(*this,bind2nd(greater_equal<double>(),0.0));
449  }  }
450    
451  Data  Data
452  Data::whereNonPositive() const  Data::whereNonPositive() const
453  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
454    return escript::unaryOp(*this,bind2nd(less_equal<double>(),0.0));    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 escript::unaryOp(dataAbs,bind2nd(less_equal<double>(),tol));
462  }  }
# Line 478  Data::whereZero(double tol) const Line 464  Data::whereZero(double tol) const
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 escript::unaryOp(dataAbs,bind2nd(greater<double>(),tol));
469  }  }
# Line 488  Data::whereNonZero(double tol) const Line 471  Data::whereNonZero(double tol) const
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 512  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 550  Data::getDataPointShape() const Line 529  Data::getDataPointShape() const
529    
530    
531    
 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");  
   }  
   
   //  
   // make sure data is expanded:  
   if (!isExpanded()) {  
     expand();  
   }  
   
   //  
   // and copy over  
   m_data->copyAll(num_array);  
 }  
   
532  const  const
533  boost::python::numeric::array  boost::python::numeric::array
534  Data::convertToNumArray()  Data:: getValueOfDataPoint(int dataPointNo)
 {  
   //  
   // determine the total number of data points  
   int numSamples = getNumSamples();  
   int numDataPointsPerSample = getNumDataPointsPerSample();  
   int numDataPoints = numSamples * numDataPointsPerSample;  
   
   //  
   // determine the rank and shape of each data point  
   int dataPointRank = getDataPointRank();  
   DataArrayView::ShapeType dataPointShape = getDataPointShape();  
   
   //  
   // create the numeric array to be returned  
   boost::python::numeric::array numArray(0.0);  
   
   //  
   // the rank of the returned numeric array will be the rank of  
   // the data points, plus one. Where the rank of the array is n,  
   // the last n-1 dimensions will be equal to the shape of the  
   // data points, whilst the first dimension will be equal to the  
   // 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]);  
   }  
   
   //  
   // resize the numeric array to the shape just calculated  
   if (arrayRank==1) {  
     numArray.resize(arrayShape[0]);  
   }  
   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]);  
   }  
   if (arrayRank==5) {  
     numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3],arrayShape[4]);  
   }  
   
   //  
   // loop through each data point in turn, loading the values for that data point  
   // into the numeric array.  
   int dataPoint = 0;  
   for (int sampleNo = 0; sampleNo < numSamples; sampleNo++) {  
     for (int dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {  
       DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);  
       if (dataPointRank==0) {  
         numArray[dataPoint]=dataPointView();  
       }  
       if (dataPointRank==1) {  
         for (int i=0; i<dataPointShape[0]; i++) {  
           numArray[make_tuple(dataPoint,i)]=dataPointView(i);  
         }  
       }  
       if (dataPointRank==2) {  
         for (int i=0; i<dataPointShape[0]; i++) {  
           for (int j=0; j<dataPointShape[1]; j++) {  
             numArray[make_tuple(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[make_tuple(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[make_tuple(dataPoint,i,j,k,l)]=dataPointView(i,j,k,l);  
               }  
             }  
           }  
         }  
       }  
       dataPoint++;  
     }  
   }  
   
   //  
   // return the loaded array  
   return numArray;  
 }  
   
   
 const  
 boost::python::numeric::array  
 Data:: getValueOfDataPoint(int dataPointNo)  
535  {  {
536    size_t length=0;    size_t length=0;
537    int i, j, k, l;    int i, j, k, l;
# Line 726  Data:: getValueOfDataPoint(int dataPoint Line 573  Data:: getValueOfDataPoint(int dataPoint
573         int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();         int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();
574         //         //
575         // Check a valid sample number has been supplied         // Check a valid sample number has been supplied
576         if (sampleNo >= getNumSamples() or sampleNo < 0 ) {         if ((sampleNo >= getNumSamples()) || (sampleNo < 0 )) {
577             throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");             throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");
578         }         }
579                  
580         //         //
581         // Check a valid data point number has been supplied         // Check a valid data point number has been supplied
582         if (dataPointNoInSample >= getNumDataPointsPerSample() or dataPointNoInSample < 0) {         if ((dataPointNoInSample >= getNumDataPointsPerSample()) || (dataPointNoInSample < 0)) {
583             throw DataException("Error - Data::convertToNumArray: invalid dataPointNoInSample.");             throw DataException("Error - Data::convertToNumArray: invalid dataPointNoInSample.");
584         }         }
585         // TODO: global error handling         // TODO: global error handling
586         // create a view of the data if it is stored locally         // create a view of the data if it is stored locally
587         DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);         DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);
588            
589         switch( dataPointRank ){         switch( dataPointRank ){
590              case 0 :              case 0 :
591                  numArray[0] = dataPointView();                  numArray[0] = dataPointView();
592                  break;                  break;
593              case 1 :                      case 1 :
594                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
595                      numArray[i]=dataPointView(i);                      numArray[i]=dataPointView(i);
596                  break;                  break;
597              case 2 :                      case 2 :
598                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
599                      for( j=0; j<dataPointShape[1]; j++)                      for( j=0; j<dataPointShape[1]; j++)
600                          numArray[make_tuple(i,j)]=dataPointView(i,j);                          numArray[make_tuple(i,j)]=dataPointView(i,j);
601                  break;                  break;
602              case 3 :                      case 3 :
603                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
604                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
605                          for( k=0; k<dataPointShape[2]; k++)                          for( k=0; k<dataPointShape[2]; k++)
# Line 773  Data:: getValueOfDataPoint(int dataPoint Line 620  Data:: getValueOfDataPoint(int dataPoint
620    
621  }  }
622  void  void
623  Data::setValueOfDataPointToArray(int dataPointNo, const boost::python::numeric::array num_array)  Data::setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object)
624    {
625        // this will throw if the value cannot be represented
626        boost::python::numeric::array num_array(py_object);
627        setValueOfDataPointToArray(dataPointNo,num_array);
628    
629    
630    }
631    
632    void
633    Data::setValueOfDataPointToArray(int dataPointNo, const boost::python::numeric::array& num_array)
634  {  {
635    if (isProtected()) {    if (isProtected()) {
636          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
637    }    }
638    //    //
639    // check rank    // check rank
640    if (num_array.getrank()<getDataPointRank())    if (num_array.getrank()<getDataPointRank())
641        throw DataException("Rank of numarray does not match Data object rank");        throw DataException("Rank of numarray does not match Data object rank");
642    
643    //    //
# Line 823  Data::setValueOfDataPoint(int dataPointN Line 680  Data::setValueOfDataPoint(int dataPointN
680    }    }
681  }  }
682    
683  const  const
684  boost::python::numeric::array  boost::python::numeric::array
685  Data::getValueOfGlobalDataPoint(int procNo, int dataPointNo)  Data::getValueOfGlobalDataPoint(int procNo, 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;
# Line 877  Data::getValueOfGlobalDataPoint(int proc Line 734  Data::getValueOfGlobalDataPoint(int proc
734                  int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();                  int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();
735                  //                  //
736                  // Check a valid sample number has been supplied                  // Check a valid sample number has been supplied
737                  if (sampleNo >= getNumSamples() or sampleNo < 0 ) {                  if ((sampleNo >= getNumSamples()) || (sampleNo < 0 )) {
738                    throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");                    throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");
739                  }                  }
740                  
741                  //                  //
742                  // Check a valid data point number has been supplied                  // Check a valid data point number has been supplied
743                  if (dataPointNoInSample >= getNumDataPointsPerSample() or dataPointNoInSample < 0) {                  if ((dataPointNoInSample >= getNumDataPointsPerSample()) || (dataPointNoInSample < 0)) {
744                    throw DataException("Error - Data::convertToNumArray: invalid dataPointNoInSample.");                    throw DataException("Error - Data::convertToNumArray: invalid dataPointNoInSample.");
745                  }                  }
746                  // TODO: global error handling                  // 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, dataPointNoInSample);          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 921  Data::getValueOfGlobalDataPoint(int proc Line 778  Data::getValueOfGlobalDataPoint(int proc
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
# Line 931  Data::getValueOfGlobalDataPoint(int proc Line 788  Data::getValueOfGlobalDataPoint(int proc
788          case 0 :          case 0 :
789              numArray[0]=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                     numArray[make_tuple(i,j)]=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++ )
# Line 955  Data::getValueOfGlobalDataPoint(int proc Line 812  Data::getValueOfGlobalDataPoint(int proc
812              break;              break;
813      }      }
814    
815      delete [] tmpData;        delete [] tmpData;
816    //    //
817    // return the loaded array    // return the loaded array
818    return numArray;    return numArray;
# Line 969  Data::integrate() const Line 826  Data::integrate() const
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 1035  Data::integrate() const Line 902  Data::integrate() const
902  }  }
903    
904  Data  Data
 Data::erf() const  
 {  
 #if defined DOPROF  
   profData->unary++;  
 #endif  
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::erf);  
 }  
   
 Data  
905  Data::sin() const  Data::sin() const
906  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
907    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sin);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sin);
908  }  }
909    
910  Data  Data
911  Data::cos() const  Data::cos() const
912  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
913    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cos);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cos);
914  }  }
915    
916  Data  Data
917  Data::tan() const  Data::tan() const
918  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
919    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tan);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tan);
920  }  }
921    
922  Data  Data
923  Data::asin() const  Data::asin() const
924  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
925    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asin);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asin);
926  }  }
927    
928  Data  Data
929  Data::acos() const  Data::acos() const
930  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
931    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acos);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acos);
932  }  }
933    
934    
935  Data  Data
936  Data::atan() const  Data::atan() const
937  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
938    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atan);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atan);
939  }  }
940    
941  Data  Data
942  Data::sinh() const  Data::sinh() const
943  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
944    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sinh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sinh);
945  }  }
946    
947  Data  Data
948  Data::cosh() const  Data::cosh() const
949  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
950    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cosh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cosh);
951  }  }
952    
953  Data  Data
954  Data::tanh() const  Data::tanh() const
955  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
956    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tanh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tanh);
957  }  }
958    
959    
960  Data  Data
961  Data::asinh() const  Data::erf() const
962  {  {
963  #if defined DOPROF  #ifdef _WIN32
964    profData->unary++;    throw DataException("Error - Data:: erf function is not supported on _WIN32 platforms.");
965    #else
966      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::erf);
967  #endif  #endif
968    }
969    
970    Data
971    Data::asinh() const
972    {
973    #ifdef _WIN32
974      return escript::unaryOp(*this,escript::asinh_substitute);
975    #else
976    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asinh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asinh);
977    #endif
978  }  }
979    
980  Data  Data
981  Data::acosh() const  Data::acosh() const
982  {  {
983  #if defined DOPROF  #ifdef _WIN32
984    profData->unary++;    return escript::unaryOp(*this,escript::acosh_substitute);
985  #endif  #else
986    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acosh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acosh);
987    #endif
988  }  }
989    
990  Data  Data
991  Data::atanh() const  Data::atanh() const
992  {  {
993  #if defined DOPROF  #ifdef _WIN32
994    profData->unary++;    return escript::unaryOp(*this,escript::atanh_substitute);
995  #endif  #else
996    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atanh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atanh);
997    #endif
998  }  }
999    
1000  Data  Data
1001  Data::log10() const  Data::log10() const
1002  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
1003    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log10);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log10);
1004  }  }
1005    
1006  Data  Data
1007  Data::log() const  Data::log() const
1008  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
1009    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);
1010  }  }
1011    
1012  Data  Data
1013  Data::sign() const  Data::sign() const
1014  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
1015    return escript::unaryOp(*this,escript::fsign);    return escript::unaryOp(*this,escript::fsign);
1016  }  }
1017    
1018  Data  Data
1019  Data::abs() const  Data::abs() const
1020  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
1021    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);
1022  }  }
1023    
1024  Data  Data
1025  Data::neg() const  Data::neg() const
1026  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
1027    return escript::unaryOp(*this,negate<double>());    return escript::unaryOp(*this,negate<double>());
1028  }  }
1029    
1030  Data  Data
1031  Data::pos() const  Data::pos() const
1032  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
1033    Data result;    Data result;
1034    // perform a deep copy    // perform a deep copy
1035    result.copy(*this);    result.copy(*this);
# Line 1211  Data::pos() const Line 1039  Data::pos() const
1039  Data  Data
1040  Data::exp() const  Data::exp() const
1041  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
1042    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);
1043  }  }
1044    
1045  Data  Data
1046  Data::sqrt() const  Data::sqrt() const
1047  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
1048    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);
1049  }  }
1050    
# Line 1230  double Line 1052  double
1052  Data::Lsup() const  Data::Lsup() const
1053  {  {
1054    double localValue, globalValue;    double localValue, globalValue;
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
1055    //    //
1056    // set the initial absolute maximum value to zero    // set the initial absolute maximum value to zero
1057    
# Line 1247  Data::Lsup() const Line 1066  Data::Lsup() const
1066  }  }
1067    
1068  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  
1069  Data::sup() const  Data::sup() const
1070  {  {
1071    double localValue, globalValue;    double localValue, globalValue;
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
1072    //    //
1073    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1074    FMax fmax_func;    FMax fmax_func;
# Line 1289  double Line 1085  double
1085  Data::inf() const  Data::inf() const
1086  {  {
1087    double localValue, globalValue;    double localValue, globalValue;
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
1088    //    //
1089    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1090    FMin fmin_func;    FMin fmin_func;
# Line 1309  Data::inf() const Line 1102  Data::inf() const
1102  Data  Data
1103  Data::maxval() const  Data::maxval() const
1104  {  {
 #if defined DOPROF  
   profData->reduction2++;  
 #endif  
1105    //    //
1106    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1107    FMax fmax_func;    FMax fmax_func;
# Line 1321  Data::maxval() const Line 1111  Data::maxval() const
1111  Data  Data
1112  Data::minval() const  Data::minval() const
1113  {  {
 #if defined DOPROF  
   profData->reduction2++;  
 #endif  
1114    //    //
1115    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1116    FMin fmin_func;    FMin fmin_func;
# Line 1334  Data Line 1121  Data
1121  Data::swapaxes(const int axis0, const int axis1) const  Data::swapaxes(const int axis0, const int axis1) const
1122  {  {
1123       int axis0_tmp,axis1_tmp;       int axis0_tmp,axis1_tmp;
      #if defined DOPROF  
      profData->unary++;  
      #endif  
1124       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1125       DataArrayView::ShapeType ev_shape;       DataArrayView::ShapeType ev_shape;
1126       // 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 1363  Data::swapaxes(const int axis0, const in Line 1147  Data::swapaxes(const int axis0, const in
1147       }       }
1148       for (int i=0; i<rank; i++) {       for (int i=0; i<rank; i++) {
1149         if (i == axis0_tmp) {         if (i == axis0_tmp) {
1150            ev_shape.push_back(s[axis1_tmp]);            ev_shape.push_back(s[axis1_tmp]);
1151         } else if (i == axis1_tmp) {         } else if (i == axis1_tmp) {
1152            ev_shape.push_back(s[axis0_tmp]);            ev_shape.push_back(s[axis0_tmp]);
1153         } else {         } else {
1154            ev_shape.push_back(s[i]);            ev_shape.push_back(s[i]);
1155         }         }
1156       }       }
1157       Data ev(0.,ev_shape,getFunctionSpace());       Data ev(0.,ev_shape,getFunctionSpace());
# Line 1380  Data::swapaxes(const int axis0, const in Line 1164  Data::swapaxes(const int axis0, const in
1164  Data  Data
1165  Data::symmetric() const  Data::symmetric() const
1166  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1167       // check input       // check input
1168       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1169       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1170          if(s[0] != s[1])          if(s[0] != s[1])
1171             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.");
1172       }       }
1173       else if (getDataPointRank()==4) {       else if (getDataPointRank()==4) {
# Line 1405  Data::symmetric() const Line 1186  Data::symmetric() const
1186  Data  Data
1187  Data::nonsymmetric() const  Data::nonsymmetric() const
1188  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1189       // check input       // check input
1190       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1191       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1192          if(s[0] != s[1])          if(s[0] != s[1])
1193             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.");
1194          DataArrayView::ShapeType ev_shape;          DataArrayView::ShapeType ev_shape;
1195          ev_shape.push_back(s[0]);          ev_shape.push_back(s[0]);
# Line 1442  Data::nonsymmetric() const Line 1220  Data::nonsymmetric() const
1220  Data  Data
1221  Data::trace(int axis_offset) const  Data::trace(int axis_offset) const
1222  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1223       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1224       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1225          DataArrayView::ShapeType ev_shape;          DataArrayView::ShapeType ev_shape;
# Line 1495  Data::trace(int axis_offset) const Line 1270  Data::trace(int axis_offset) const
1270  Data  Data
1271  Data::transpose(int axis_offset) const  Data::transpose(int axis_offset) const
1272  {  {
      #if defined DOPROF  
      profData->unary++;  
      #endif  
1273       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1274       DataArrayView::ShapeType ev_shape;       DataArrayView::ShapeType ev_shape;
1275       // 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 1519  Data::transpose(int axis_offset) const Line 1291  Data::transpose(int axis_offset) const
1291  Data  Data
1292  Data::eigenvalues() const  Data::eigenvalues() const
1293  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1294       // check input       // check input
1295       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1296       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
1297          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.");
1298       if(s[0] != s[1])       if(s[0] != s[1])
1299          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.");
1300       // create return       // create return
1301       DataArrayView::ShapeType ev_shape(1,s[0]);       DataArrayView::ShapeType ev_shape(1,s[0]);
# Line 1539  Data::eigenvalues() const Line 1308  Data::eigenvalues() const
1308  const boost::python::tuple  const boost::python::tuple
1309  Data::eigenvalues_and_eigenvectors(const double tol) const  Data::eigenvalues_and_eigenvectors(const double tol) const
1310  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1311       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1312       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
1313          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.");
1314       if(s[0] != s[1])       if(s[0] != s[1])
1315          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.");
1316       // create return       // create return
1317       DataArrayView::ShapeType ev_shape(1,s[0]);       DataArrayView::ShapeType ev_shape(1,s[0]);
# Line 1615  Data::calc_minGlobalDataPoint(int& ProcN Line 1381  Data::calc_minGlobalDataPoint(int& ProcN
1381      int lowProc = 0;      int lowProc = 0;
1382      double *globalMins = new double[get_MPISize()+1];      double *globalMins = new double[get_MPISize()+1];
1383      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() );
1384        
1385      if( get_MPIRank()==0 ){      if( get_MPIRank()==0 ){
1386          next = globalMins[lowProc];          next = globalMins[lowProc];
1387          for( i=1; i<get_MPISize(); i++ )          for( i=1; i<get_MPISize(); i++ )
# Line 1669  Data::operator+=(const boost::python::ob Line 1435  Data::operator+=(const boost::python::ob
1435    binaryOp(tmp,plus<double>());    binaryOp(tmp,plus<double>());
1436    return (*this);    return (*this);
1437  }  }
1438    Data&
1439    Data::operator=(const Data& other)
1440    {
1441      copy(other);
1442      return (*this);
1443    }
1444    
1445  Data&  Data&
1446  Data::operator-=(const Data& right)  Data::operator-=(const Data& right)
# Line 1743  Data::powD(const Data& right) const Line 1515  Data::powD(const Data& right) const
1515  {  {
1516    Data result;    Data result;
1517    if (getDataPointRank()<right.getDataPointRank()) {    if (getDataPointRank()<right.getDataPointRank()) {
1518       result.copy(right);       result.copy(right);
1519       result.binaryOp(*this,escript::rpow);       result.binaryOp(*this,escript::rpow);
1520    } else {    } else {
1521       result.copy(*this);       result.copy(*this);
# Line 1937  escript::operator/(const boost::python:: Line 1709  escript::operator/(const boost::python::
1709  /* TODO */  /* TODO */
1710  /* global reduction */  /* global reduction */
1711  Data  Data
1712  Data::getItem(const boost::python::object& key) const  Data::getItem(const boost::python::object& key) const
1713  {  {
1714    const DataArrayView& view=getPointDataView();    const DataArrayView& view=getPointDataView();
1715    
# Line 1955  Data::getItem(const boost::python::objec Line 1727  Data::getItem(const boost::python::objec
1727  Data  Data
1728  Data::getSlice(const DataArrayView::RegionType& region) const  Data::getSlice(const DataArrayView::RegionType& region) const
1729  {  {
 #if defined DOPROF  
   profData->slicing++;  
 #endif  
1730    return Data(*this,region);    return Data(*this,region);
1731  }  }
1732    
# Line 1971  Data::setItemO(const boost::python::obje Line 1740  Data::setItemO(const boost::python::obje
1740    setItemD(key,tempData);    setItemD(key,tempData);
1741  }  }
1742    
 /* TODO */  
 /* global reduction */  
1743  void  void
1744  Data::setItemD(const boost::python::object& key,  Data::setItemD(const boost::python::object& key,
1745                 const Data& value)                 const Data& value)
# Line 1990  Data::setItemD(const boost::python::obje Line 1757  Data::setItemD(const boost::python::obje
1757    }    }
1758  }  }
1759    
 /* TODO */  
 /* global reduction */  
1760  void  void
1761  Data::setSlice(const Data& value,  Data::setSlice(const Data& value,
1762                 const DataArrayView::RegionType& region)                 const DataArrayView::RegionType& region)
# Line 1999  Data::setSlice(const Data& value, Line 1764  Data::setSlice(const Data& value,
1764    if (isProtected()) {    if (isProtected()) {
1765          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
1766    }    }
 #if defined DOPROF  
   profData->slicing++;  
 #endif  
1767    Data tempValue(value);    Data tempValue(value);
1768    typeMatchLeft(tempValue);    typeMatchLeft(tempValue);
1769    typeMatchRight(tempValue);    typeMatchRight(tempValue);
# Line 2036  Data::typeMatchRight(const Data& right) Line 1798  Data::typeMatchRight(const Data& right)
1798    }    }
1799  }  }
1800    
1801  /* TODO */  void
1802  /* global reduction */  Data::setTaggedValueByName(std::string name,
1803                               const boost::python::object& value)
1804    {
1805         if (getFunctionSpace().getDomain().isValidTagName(name)) {
1806            int tagKey=getFunctionSpace().getDomain().getTag(name);
1807            setTaggedValue(tagKey,value);
1808         }
1809    }
1810  void  void
1811  Data::setTaggedValue(int tagKey,  Data::setTaggedValue(int tagKey,
1812                       const boost::python::object& value)                       const boost::python::object& value)
# Line 2053  Data::setTaggedValue(int tagKey, Line 1822  Data::setTaggedValue(int tagKey,
1822      throw DataException("Error - DataTagged conversion failed!!");      throw DataException("Error - DataTagged conversion failed!!");
1823    }    }
1824    
1825    //    numeric::array asNumArray(value);
1826    // Construct DataArray from boost::python::object input value  
1827    DataArray valueDataArray(value);  
1828      // extract the shape of the numarray
1829      DataArrayView::ShapeType tempShape;
1830      for (int i=0; i < asNumArray.getrank(); i++) {
1831        tempShape.push_back(extract<int>(asNumArray.getshape()[i]));
1832      }
1833    
1834      // get the space for the data vector
1835      int len = DataArrayView::noValues(tempShape);
1836      DataVector temp_data(len, 0.0, len);
1837      DataArrayView temp_dataView(temp_data, tempShape);
1838      temp_dataView.copy(asNumArray);
1839    
1840    //    //
1841    // Call DataAbstract::setTaggedValue    // Call DataAbstract::setTaggedValue
1842    m_data->setTaggedValue(tagKey,valueDataArray.getView());    m_data->setTaggedValue(tagKey,temp_dataView);
1843  }  }
1844    
 /* TODO */  
 /* global reduction */  
1845  void  void
1846  Data::setTaggedValueFromCPP(int tagKey,  Data::setTaggedValueFromCPP(int tagKey,
1847                              const DataArrayView& value)                              const DataArrayView& value)
# Line 2078  Data::setTaggedValueFromCPP(int tagKey, Line 1856  Data::setTaggedValueFromCPP(int tagKey,
1856    if (!isTagged()) {    if (!isTagged()) {
1857      throw DataException("Error - DataTagged conversion failed!!");      throw DataException("Error - DataTagged conversion failed!!");
1858    }    }
1859                                                                                                                  
1860    //    //
1861    // Call DataAbstract::setTaggedValue    // Call DataAbstract::setTaggedValue
1862    m_data->setTaggedValue(tagKey,value);    m_data->setTaggedValue(tagKey,value);
1863  }  }
1864    
 /* TODO */  
 /* global reduction */  
1865  int  int
1866  Data::getTagNumber(int dpno)  Data::getTagNumber(int dpno)
1867  {  {
1868    return m_data->getTagNumber(dpno);    return m_data->getTagNumber(dpno);
1869  }  }
1870    
 /* 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[make_tuple(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[make_tuple(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[make_tuple(i,j,k,l)] = valueView(i,j,k,l);  
           }  
         }  
       }  
     }  
   }  
   
 }  
   
1871  void  void
1872  Data::archiveData(const std::string fileName)  Data::archiveData(const std::string fileName)
1873  {  {
# Line 2217  Data::archiveData(const std::string file Line 1909  Data::archiveData(const std::string file
1909    DataArrayView::ShapeType dataPointShape = getDataPointShape();    DataArrayView::ShapeType dataPointShape = getDataPointShape();
1910    vector<int> referenceNumbers(noSamples);    vector<int> referenceNumbers(noSamples);
1911    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {
1912      referenceNumbers[sampleNo] = getFunctionSpace().getReferenceNoFromSampleNo(sampleNo);      referenceNumbers[sampleNo] = getFunctionSpace().getReferenceIDOfSample(sampleNo);
1913    }    }
1914    vector<int> tagNumbers(noSamples);    vector<int> tagNumbers(noSamples);
1915    if (isTagged()) {    if (isTagged()) {
# Line 2426  Data::extractData(const std::string file Line 2118  Data::extractData(const std::string file
2118      throw DataException("extractData Error: incompatible FunctionSpace");      throw DataException("extractData Error: incompatible FunctionSpace");
2119    }    }
2120    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {
2121      if (referenceNumbers[sampleNo] != fspace.getReferenceNoFromSampleNo(sampleNo)) {      if (referenceNumbers[sampleNo] != fspace.getReferenceIDOfSample(sampleNo)) {
2122        throw DataException("extractData Error: incompatible FunctionSpace");        throw DataException("extractData Error: incompatible FunctionSpace");
2123      }      }
2124    }    }
# Line 2526  escript::C_GeneralTensorProduct(Data& ar Line 2218  escript::C_GeneralTensorProduct(Data& ar
2218    // General tensor product: res(SL x SR) = arg_0(SL x SM) * arg_1(SM x SR)    // General tensor product: res(SL x SR) = arg_0(SL x SM) * arg_1(SM x SR)
2219    // 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().
2220    
   #if defined DOPROF  
     // profData->binary++;  
   #endif  
   
2221    // Interpolate if necessary and find an appropriate function space    // Interpolate if necessary and find an appropriate function space
2222    Data arg_0_Z, arg_1_Z;    Data arg_0_Z, arg_1_Z;
2223    if (arg_0.getFunctionSpace()!=arg_1.getFunctionSpace()) {    if (arg_0.getFunctionSpace()!=arg_1.getFunctionSpace()) {
# Line 2890  Data::borrowData() const Line 2578  Data::borrowData() const
2578  /* Member functions specific to the MPI implementation */  /* Member functions specific to the MPI implementation */
2579    
2580  void  void
2581  Data::print()  Data::print()
2582  {  {
2583    int i,j;    int i,j;
2584      
2585    printf( "Data is %dX%d\n", getNumSamples(), getNumDataPointsPerSample() );    printf( "Data is %dX%d\n", getNumSamples(), getNumDataPointsPerSample() );
2586    for( i=0; i<getNumSamples(); i++ )    for( i=0; i<getNumSamples(); i++ )
2587    {    {
# Line 2903  Data::print() Line 2591  Data::print()
2591      printf( "\n" );      printf( "\n" );
2592    }    }
2593  }  }
2594    void
2595    Data::dump(const std::string fileName) const
2596    {
2597      try
2598         {
2599            return m_data->dump(fileName);
2600         }
2601         catch (exception& e)
2602         {
2603            cout << e.what() << endl;
2604         }
2605    }
2606    
2607  int  int
2608  Data::get_MPISize() const  Data::get_MPISize() const
# Line 2930  Data::get_MPIRank() const Line 2630  Data::get_MPIRank() const
2630    
2631  MPI_Comm  MPI_Comm
2632  Data::get_MPIComm() const  Data::get_MPIComm() const
2633  {  {
2634  #ifdef PASO_MPI  #ifdef PASO_MPI
2635      return MPI_COMM_WORLD;      return MPI_COMM_WORLD;
2636  #else  #else

Legend:
Removed from v.922  
changed lines
  Added in v.1319

  ViewVC Help
Powered by ViewVC 1.1.26