/[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 876 by ksteube, Thu Oct 19 03:50:23 2006 UTC revision 1118 by gross, Tue Apr 24 08:55:04 2007 UTC
# Line 38  using namespace boost::python; Line 38  using namespace boost::python;
38  using namespace boost;  using namespace boost;
39  using namespace escript;  using namespace escript;
40    
 #if defined DOPROF  
 //  
 // global table of profiling data for all Data objects  
 DataProf dataProfTable;  
 #endif  
   
41  Data::Data()  Data::Data()
42  {  {
43    //    //
# Line 52  Data::Data() Line 46  Data::Data()
46    shared_ptr<DataAbstract> temp_data(temp);    shared_ptr<DataAbstract> temp_data(temp);
47    m_data=temp_data;    m_data=temp_data;
48    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
49  }  }
50    
51  Data::Data(double value,  Data::Data(double value,
# Line 70  Data::Data(double value, Line 60  Data::Data(double value,
60    DataArray temp(dataPointShape,value);    DataArray temp(dataPointShape,value);
61    initialise(temp.getView(),what,expanded);    initialise(temp.getView(),what,expanded);
62    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
63  }  }
64    
65  Data::Data(double value,  Data::Data(double value,
# Line 85  Data::Data(double value, Line 71  Data::Data(double value,
71    pair<int,int> dataShape=what.getDataShape();    pair<int,int> dataShape=what.getDataShape();
72    initialise(temp.getView(),what,expanded);    initialise(temp.getView(),what,expanded);
73    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
74  }  }
75    
76  Data::Data(const Data& inData)  Data::Data(const Data& inData)
77  {  {
78    m_data=inData.m_data;    m_data=inData.m_data;
79    m_protected=inData.isProtected();    m_protected=inData.isProtected();
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
80  }  }
81    
82  Data::Data(const Data& inData,  Data::Data(const Data& inData,
# Line 110  Data::Data(const Data& inData, Line 88  Data::Data(const Data& inData,
88    shared_ptr<DataAbstract> temp_data(tmp);    shared_ptr<DataAbstract> temp_data(tmp);
89    m_data=temp_data;    m_data=temp_data;
90    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
91  }  }
92    
93  Data::Data(const Data& inData,  Data::Data(const Data& inData,
94             const FunctionSpace& functionspace)             const FunctionSpace& functionspace)
95  {  {
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
96    if (inData.getFunctionSpace()==functionspace) {    if (inData.getFunctionSpace()==functionspace) {
97      m_data=inData.m_data;      m_data=inData.m_data;
98    } else {    } else {
     #if defined DOPROF  
     profData->interpolate++;  
     #endif  
99      Data tmp(0,inData.getPointDataView().getShape(),functionspace,true);      Data tmp(0,inData.getPointDataView().getShape(),functionspace,true);
100      // Note: Must use a reference or pointer to a derived object      // Note: Must use a reference or pointer to a derived object
101      // 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 125  Data::Data(const DataTagged::TagListType
125    if (expanded) {    if (expanded) {
126      expand();      expand();
127    }    }
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
128  }  }
129    
130  Data::Data(const numeric::array& value,  Data::Data(const numeric::array& value,
# Line 170  Data::Data(const numeric::array& value, Line 133  Data::Data(const numeric::array& value,
133  {  {
134    initialise(value,what,expanded);    initialise(value,what,expanded);
135    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
136  }  }
137    
138  Data::Data(const DataArrayView& value,  Data::Data(const DataArrayView& value,
# Line 182  Data::Data(const DataArrayView& value, Line 141  Data::Data(const DataArrayView& value,
141  {  {
142    initialise(value,what,expanded);    initialise(value,what,expanded);
143    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
144  }  }
145    
146  Data::Data(const object& value,  Data::Data(const object& value,
# Line 195  Data::Data(const object& value, Line 150  Data::Data(const object& value,
150    numeric::array asNumArray(value);    numeric::array asNumArray(value);
151    initialise(asNumArray,what,expanded);    initialise(asNumArray,what,expanded);
152    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
153  }  }
154    
155  Data::Data(const object& value,  Data::Data(const object& value,
# Line 220  Data::Data(const object& value, Line 171  Data::Data(const object& value,
171      initialise(temp.getView(),other.getFunctionSpace(),false);      initialise(temp.getView(),other.getFunctionSpace(),false);
172    }    }
173    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
174  }  }
175    
176  Data::~Data()  Data::~Data()
# Line 266  Data::getShapeTuple() const Line 213  Data::getShapeTuple() const
213          throw DataException("Error - illegal Data rank.");          throw DataException("Error - illegal Data rank.");
214    }    }
215  }  }
   
216  void  void
217  Data::copy(const Data& other)  Data::copy(const Data& other)
218  {  {
# Line 319  Data::copy(const Data& other) Line 265  Data::copy(const Data& other)
265    throw DataException("Error - Copy not implemented for this Data type.");    throw DataException("Error - Copy not implemented for this Data type.");
266  }  }
267    
268    
269    void
270    Data::setToZero()
271    {
272      {
273        DataExpanded* temp=dynamic_cast<DataExpanded*>(m_data.get());
274        if (temp!=0) {
275           temp->setToZero();
276           return;
277        }
278      }
279      {
280        DataTagged* temp=dynamic_cast<DataTagged*>(m_data.get());
281        if (temp!=0) {
282          temp->setToZero();
283          return;
284        }
285      }
286      {
287        DataConstant* temp=dynamic_cast<DataConstant*>(m_data.get());
288        if (temp!=0) {
289          temp->setToZero();
290          return;
291        }
292      }
293      throw DataException("Error - Data can not be set to zero.");
294    }
295    
296  void  void
297  Data::copyWithMask(const Data& other,  Data::copyWithMask(const Data& other,
298                     const Data& mask)                     const Data& mask)
# Line 350  Data::isTagged() const Line 324  Data::isTagged() const
324    return (temp!=0);    return (temp!=0);
325  }  }
326    
 /* TODO */  
 /* global reduction -- the local data being empty does not imply that it is empty on other processers*/  
327  bool  bool
328  Data::isEmpty() const  Data::isEmpty() const
329  {  {
# Line 425  Data::tag() Line 397  Data::tag()
397  Data  Data
398  Data::oneOver() const  Data::oneOver() const
399  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
400    return escript::unaryOp(*this,bind1st(divides<double>(),1.));    return escript::unaryOp(*this,bind1st(divides<double>(),1.));
401  }  }
402    
403  Data  Data
404  Data::wherePositive() const  Data::wherePositive() const
405  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
406    return escript::unaryOp(*this,bind2nd(greater<double>(),0.0));    return escript::unaryOp(*this,bind2nd(greater<double>(),0.0));
407  }  }
408    
409  Data  Data
410  Data::whereNegative() const  Data::whereNegative() const
411  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
412    return escript::unaryOp(*this,bind2nd(less<double>(),0.0));    return escript::unaryOp(*this,bind2nd(less<double>(),0.0));
413  }  }
414    
415  Data  Data
416  Data::whereNonNegative() const  Data::whereNonNegative() const
417  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
418    return escript::unaryOp(*this,bind2nd(greater_equal<double>(),0.0));    return escript::unaryOp(*this,bind2nd(greater_equal<double>(),0.0));
419  }  }
420    
421  Data  Data
422  Data::whereNonPositive() const  Data::whereNonPositive() const
423  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
424    return escript::unaryOp(*this,bind2nd(less_equal<double>(),0.0));    return escript::unaryOp(*this,bind2nd(less_equal<double>(),0.0));
425  }  }
426    
427  Data  Data
428  Data::whereZero(double tol) const  Data::whereZero(double tol) const
429  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
430    Data dataAbs=abs();    Data dataAbs=abs();
431    return escript::unaryOp(dataAbs,bind2nd(less_equal<double>(),tol));    return escript::unaryOp(dataAbs,bind2nd(less_equal<double>(),tol));
432  }  }
# Line 480  Data::whereZero(double tol) const Line 434  Data::whereZero(double tol) const
434  Data  Data
435  Data::whereNonZero(double tol) const  Data::whereNonZero(double tol) const
436  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
437    Data dataAbs=abs();    Data dataAbs=abs();
438    return escript::unaryOp(dataAbs,bind2nd(greater<double>(),tol));    return escript::unaryOp(dataAbs,bind2nd(greater<double>(),tol));
439  }  }
# Line 490  Data::whereNonZero(double tol) const Line 441  Data::whereNonZero(double tol) const
441  Data  Data
442  Data::interpolate(const FunctionSpace& functionspace) const  Data::interpolate(const FunctionSpace& functionspace) const
443  {  {
 #if defined DOPROF  
   profData->interpolate++;  
 #endif  
444    return Data(*this,functionspace);    return Data(*this,functionspace);
445  }  }
446    
# Line 514  Data::probeInterpolation(const FunctionS Line 462  Data::probeInterpolation(const FunctionS
462  Data  Data
463  Data::gradOn(const FunctionSpace& functionspace) const  Data::gradOn(const FunctionSpace& functionspace) const
464  {  {
 #if defined DOPROF  
   profData->grad++;  
 #endif  
465    if (functionspace.getDomain()!=getDomain())    if (functionspace.getDomain()!=getDomain())
466      throw DataException("Error - gradient cannot be calculated on different domains.");      throw DataException("Error - gradient cannot be calculated on different domains.");
467    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();
# Line 550  Data::getDataPointShape() const Line 495  Data::getDataPointShape() const
495    return getPointDataView().getShape();    return getPointDataView().getShape();
496  }  }
497    
 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");  
498    
   //  
   // 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");  
   }  
499    
500    //  const
   // make sure data is expanded:  
   if (!isExpanded()) {  
     expand();  
   }  
   
   //  
   // and copy over  
   m_data->copyAll(num_array);  
 }  
   
 const  
501  boost::python::numeric::array  boost::python::numeric::array
502  Data::convertToNumArray()  Data:: getValueOfDataPoint(int dataPointNo)
503  {  {
504    //    size_t length=0;
505    // determine the total number of data points    int i, j, k, l;
   int numSamples = getNumSamples();  
   int numDataPointsPerSample = getNumDataPointsPerSample();  
   int numDataPoints = numSamples * numDataPointsPerSample;  
   
506    //    //
507    // determine the rank and shape of each data point    // determine the rank and shape of each data point
508    int dataPointRank = getDataPointRank();    int dataPointRank = getDataPointRank();
# Line 599  Data::convertToNumArray() Line 513  Data::convertToNumArray()
513    boost::python::numeric::array numArray(0.0);    boost::python::numeric::array numArray(0.0);
514    
515    //    //
516    // the rank of the returned numeric array will be the rank of    // the shape of the returned numeric array will be the same
517    // the data points, plus one. Where the rank of the array is n,    // as that of the data point
518    // the last n-1 dimensions will be equal to the shape of the    int arrayRank = dataPointRank;
519    // 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]);  
   }  
520    
521    //    //
522    // resize the numeric array to the shape just calculated    // resize the numeric array to the shape just calculated
523      if (arrayRank==0) {
524        numArray.resize(1);
525      }
526    if (arrayRank==1) {    if (arrayRank==1) {
527      numArray.resize(arrayShape[0]);      numArray.resize(arrayShape[0]);
528    }    }
# Line 626  Data::convertToNumArray() Line 535  Data::convertToNumArray()
535    if (arrayRank==4) {    if (arrayRank==4) {
536      numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3]);      numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3]);
537    }    }
   if (arrayRank==5) {  
     numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3],arrayShape[4]);  
   }  
538    
539    //    if (getNumDataPointsPerSample()>0) {
540    // loop through each data point in turn, loading the values for that data point         int sampleNo = dataPointNo/getNumDataPointsPerSample();
541    // into the numeric array.         int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();
542    int dataPoint = 0;         //
543    for (int sampleNo = 0; sampleNo < numSamples; sampleNo++) {         // Check a valid sample number has been supplied
544      for (int dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {         if ((sampleNo >= getNumSamples()) || (sampleNo < 0 )) {
545        DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);             throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");
546        if (dataPointRank==0) {         }
547          numArray[dataPoint]=dataPointView();                
548        }         //
549        if (dataPointRank==1) {         // Check a valid data point number has been supplied
550          for (int i=0; i<dataPointShape[0]; i++) {         if ((dataPointNoInSample >= getNumDataPointsPerSample()) || (dataPointNoInSample < 0)) {
551            numArray[dataPoint][i]=dataPointView(i);             throw DataException("Error - Data::convertToNumArray: invalid dataPointNoInSample.");
552          }         }
553        }         // TODO: global error handling
554        if (dataPointRank==2) {         // create a view of the data if it is stored locally
555          for (int i=0; i<dataPointShape[0]; i++) {         DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);
556            for (int j=0; j<dataPointShape[1]; j++) {          
557              numArray[dataPoint][i][j] = dataPointView(i,j);         switch( dataPointRank ){
558            }              case 0 :
559          }                  numArray[0] = dataPointView();
560        }                  break;
561        if (dataPointRank==3) {              case 1 :        
562          for (int i=0; i<dataPointShape[0]; i++) {                  for( i=0; i<dataPointShape[0]; i++ )
563            for (int j=0; j<dataPointShape[1]; j++) {                      numArray[i]=dataPointView(i);
564              for (int k=0; k<dataPointShape[2]; k++) {                  break;
565                numArray[dataPoint][i][j][k]=dataPointView(i,j,k);              case 2 :        
566              }                  for( i=0; i<dataPointShape[0]; i++ )
567            }                      for( j=0; j<dataPointShape[1]; j++)
568          }                          numArray[make_tuple(i,j)]=dataPointView(i,j);
569        }                  break;
570        if (dataPointRank==4) {              case 3 :        
571          for (int i=0; i<dataPointShape[0]; i++) {                  for( i=0; i<dataPointShape[0]; i++ )
572            for (int j=0; j<dataPointShape[1]; j++) {                      for( j=0; j<dataPointShape[1]; j++ )
573              for (int k=0; k<dataPointShape[2]; k++) {                          for( k=0; k<dataPointShape[2]; k++)
574                for (int l=0; l<dataPointShape[3]; l++) {                              numArray[make_tuple(i,j,k)]=dataPointView(i,j,k);
575                  numArray[dataPoint][i][j][k][l]=dataPointView(i,j,k,l);                  break;
576                }              case 4 :
577              }                  for( i=0; i<dataPointShape[0]; i++ )
578            }                      for( j=0; j<dataPointShape[1]; j++ )
579          }                          for( k=0; k<dataPointShape[2]; k++ )
580        }                              for( l=0; l<dataPointShape[3]; l++)
581        dataPoint++;                                  numArray[make_tuple(i,j,k,l)]=dataPointView(i,j,k,l);
582      }                  break;
583        }
584    }    }
   
585    //    //
586    // return the loaded array    // return the array
587    return numArray;    return numArray;
 }  
588    
589  const  }
590  boost::python::numeric::array  void
591  Data::convertToNumArrayFromSampleNo(int sampleNo)  Data::setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object)
592  {  {
593    //      // this will throw if the value cannot be represented
594    // Check a valid sample number has been supplied      boost::python::numeric::array num_array(py_object);
595    if (sampleNo >= getNumSamples()) {      setValueOfDataPointToArray(dataPointNo,num_array);
     throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");  
   }  
596    
   //  
   // determine the number of data points per sample  
   int numDataPointsPerSample = getNumDataPointsPerSample();  
597    
598    //  }
   // determine the rank and shape of each data point  
   int dataPointRank = getDataPointRank();  
   DataArrayView::ShapeType dataPointShape = getDataPointShape();  
599    
600    void
601    Data::setValueOfDataPointToArray(int dataPointNo, const boost::python::numeric::array& num_array)
602    {
603      if (isProtected()) {
604            throw DataException("Error - attempt to update protected Data object.");
605      }
606    //    //
607    // create the numeric array to be returned    // check rank
608    boost::python::numeric::array numArray(0.0);    if (num_array.getrank()<getDataPointRank())
609          throw DataException("Rank of numarray does not match Data object rank");
610    
611    //    //
612    // the rank of the returned numeric array will be the rank of    // check shape of num_array
613    // the data points, plus one. Where the rank of the array is n,    for (int i=0; i<getDataPointRank(); i++) {
614    // the last n-1 dimensions will be equal to the shape of the      if (extract<int>(num_array.getshape()[i])!=getDataPointShape()[i])
615    // 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]);  
616    }    }
   
617    //    //
618    // resize the numeric array to the shape just calculated    // make sure data is expanded:
619    if (arrayRank==1) {    if (!isExpanded()) {
620      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]);  
   }  
   if (arrayRank==5) {  
     numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3],arrayShape[4]);  
621    }    }
622      if (getNumDataPointsPerSample()>0) {
623    //         int sampleNo = dataPointNo/getNumDataPointsPerSample();
624    // loop through each data point in turn, loading the values for that data point         int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();
625    // into the numeric array.         m_data->copyToDataPoint(sampleNo, dataPointNoInSample,num_array);
626    for (int dataPoint = 0; dataPoint < numDataPointsPerSample; dataPoint++) {    } else {
627      DataArrayView dataPointView = getDataPoint(sampleNo, dataPoint);         m_data->copyToDataPoint(-1, 0,num_array);
     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);  
             }  
           }  
         }  
       }  
     }  
628    }    }
   
   //  
   // return the loaded array  
   return numArray;  
629  }  }
630    
631  const  void
632  boost::python::numeric::array  Data::setValueOfDataPoint(int dataPointNo, const double value)
 Data::convertToNumArrayFromDPNo(int procNo,  
                                 int sampleNo,  
                                                                 int dataPointNo)  
   
633  {  {
634      size_t length=0;    if (isProtected()) {
635      int i, j, k, l, pos;          throw DataException("Error - attempt to update protected Data object.");
   
   //  
   // Check a valid sample number has been supplied  
   if (sampleNo >= getNumSamples()) {  
     throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");  
636    }    }
   
637    //    //
638    // Check a valid data point number has been supplied    // make sure data is expanded:
639    if (dataPointNo >= getNumDataPointsPerSample()) {    if (!isExpanded()) {
640      throw DataException("Error - Data::convertToNumArray: invalid dataPointNo.");      expand();
641      }
642      if (getNumDataPointsPerSample()>0) {
643           int sampleNo = dataPointNo/getNumDataPointsPerSample();
644           int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();
645           m_data->copyToDataPoint(sampleNo, dataPointNoInSample,value);
646      } else {
647           m_data->copyToDataPoint(-1, 0,value);
648    }    }
649    }
650    
651    const
652    boost::python::numeric::array
653    Data::getValueOfGlobalDataPoint(int procNo, int dataPointNo)
654    {
655      size_t length=0;
656      int i, j, k, l, pos;
657    //    //
658    // determine the rank and shape of each data point    // determine the rank and shape of each data point
659    int dataPointRank = getDataPointRank();    int dataPointRank = getDataPointRank();
# Line 838  Data::convertToNumArrayFromDPNo(int proc Line 687  Data::convertToNumArrayFromDPNo(int proc
687      numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3]);      numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3]);
688    }    }
689    
690      // added for the MPI communication    // added for the MPI communication
691      length=1;    length=1;
692      for( i=0; i<arrayRank; i++ )    for( i=0; i<arrayRank; i++ ) length *= arrayShape[i];
693          length *= arrayShape[i];    double *tmpData = new double[length];
     double *tmpData = new double[length];  
694    
695    //    //
696    // load the values for the data point into the numeric array.    // load the values for the data point into the numeric array.
697    
698      // updated for the MPI case      // updated for the MPI case
699      if( get_MPIRank()==procNo ){      if( get_MPIRank()==procNo ){
700                 if (getNumDataPointsPerSample()>0) {
701                    int sampleNo = dataPointNo/getNumDataPointsPerSample();
702                    int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();
703                    //
704                    // Check a valid sample number has been supplied
705                    if ((sampleNo >= getNumSamples()) || (sampleNo < 0 )) {
706                      throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");
707                    }
708                  
709                    //
710                    // Check a valid data point number has been supplied
711                    if ((dataPointNoInSample >= getNumDataPointsPerSample()) || (dataPointNoInSample < 0)) {
712                      throw DataException("Error - Data::convertToNumArray: invalid dataPointNoInSample.");
713                    }
714                    // TODO: global error handling
715          // create a view of the data if it is stored locally          // create a view of the data if it is stored locally
716          DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);          DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);
717                    
718          // pack the data from the view into tmpData for MPI communication          // pack the data from the view into tmpData for MPI communication
719          pos=0;          pos=0;
# Line 881  Data::convertToNumArrayFromDPNo(int proc Line 744  Data::convertToNumArrayFromDPNo(int proc
744                                  tmpData[pos]=dataPointView(i,j,k,l);                                  tmpData[pos]=dataPointView(i,j,k,l);
745                  break;                  break;
746          }          }
747                }
748      }      }
749  #ifdef PASO_MPI          #ifdef PASO_MPI
750          // broadcast the data to all other processes          // broadcast the data to all other processes
751          MPI_Bcast( tmpData, length, MPI_DOUBLE, procNo, get_MPIComm() );      MPI_Bcast( tmpData, length, MPI_DOUBLE, procNo, get_MPIComm() );
752  #endif          #endif
753    
754      // unpack the data      // unpack the data
755      switch( dataPointRank ){      switch( dataPointRank ){
756          case 0 :          case 0 :
757              numArray[i]=tmpData[0];              numArray[0]=tmpData[0];
758              break;              break;
759          case 1 :                  case 1 :        
760              for( i=0; i<dataPointShape[0]; i++ )              for( i=0; i<dataPointShape[0]; i++ )
# Line 899  Data::convertToNumArrayFromDPNo(int proc Line 763  Data::convertToNumArrayFromDPNo(int proc
763          case 2 :                  case 2 :        
764              for( i=0; i<dataPointShape[0]; i++ )              for( i=0; i<dataPointShape[0]; i++ )
765                  for( j=0; j<dataPointShape[1]; j++ )                  for( j=0; j<dataPointShape[1]; j++ )
766                      tmpData[i+j*dataPointShape[0]];                     numArray[make_tuple(i,j)]=tmpData[i+j*dataPointShape[0]];
767              break;              break;
768          case 3 :                  case 3 :        
769              for( i=0; i<dataPointShape[0]; i++ )              for( i=0; i<dataPointShape[0]; i++ )
770                  for( j=0; j<dataPointShape[1]; j++ )                  for( j=0; j<dataPointShape[1]; j++ )
771                      for( k=0; k<dataPointShape[2]; k++ )                      for( k=0; k<dataPointShape[2]; k++ )
772                          tmpData[i+dataPointShape[0]*(j*+k*dataPointShape[1])];                          numArray[make_tuple(i,j,k)]=tmpData[i+dataPointShape[0]*(j*+k*dataPointShape[1])];
773              break;              break;
774          case 4 :          case 4 :
775              for( i=0; i<dataPointShape[0]; i++ )              for( i=0; i<dataPointShape[0]; i++ )
776                  for( j=0; j<dataPointShape[1]; j++ )                  for( j=0; j<dataPointShape[1]; j++ )
777                      for( k=0; k<dataPointShape[2]; k++ )                      for( k=0; k<dataPointShape[2]; k++ )
778                          for( l=0; l<dataPointShape[3]; l++ )                          for( l=0; l<dataPointShape[3]; l++ )
779                              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]))];
780              break;              break;
781      }      }
782    
783      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);  
           }  
         }  
       }  
     }  
   }  
 */  
   
784    //    //
785    // return the loaded array    // return the loaded array
786    return numArray;    return numArray;
787  }  }
788    
789    
790    
791  boost::python::numeric::array  boost::python::numeric::array
792  Data::integrate() const  Data::integrate() const
793  {  {
# Line 967  Data::integrate() const Line 795  Data::integrate() const
795    int rank = getDataPointRank();    int rank = getDataPointRank();
796    DataArrayView::ShapeType shape = getDataPointShape();    DataArrayView::ShapeType shape = getDataPointShape();
797    
 #if defined DOPROF  
   profData->integrate++;  
 #endif  
798    
799    //    //
800    // calculate the integral values    // calculate the integral values
# Line 1032  Data::integrate() const Line 857  Data::integrate() const
857  }  }
858    
859  Data  Data
 Data::erf() const  
 {  
 #if defined DOPROF  
   profData->unary++;  
 #endif  
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::erf);  
 }  
   
 Data  
860  Data::sin() const  Data::sin() const
861  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
862    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sin);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sin);
863  }  }
864    
865  Data  Data
866  Data::cos() const  Data::cos() const
867  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
868    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cos);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cos);
869  }  }
870    
871  Data  Data
872  Data::tan() const  Data::tan() const
873  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
874    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tan);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tan);
875  }  }
876    
877  Data  Data
878  Data::asin() const  Data::asin() const
879  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
880    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asin);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asin);
881  }  }
882    
883  Data  Data
884  Data::acos() const  Data::acos() const
885  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
886    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acos);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acos);
887  }  }
888    
889    
890  Data  Data
891  Data::atan() const  Data::atan() const
892  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
893    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atan);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atan);
894  }  }
895    
896  Data  Data
897  Data::sinh() const  Data::sinh() const
898  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
899    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sinh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sinh);
900  }  }
901    
902  Data  Data
903  Data::cosh() const  Data::cosh() const
904  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
905    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cosh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cosh);
906  }  }
907    
908  Data  Data
909  Data::tanh() const  Data::tanh() const
910  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
911    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tanh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tanh);
912  }  }
913    
914    
915  Data  Data
916  Data::asinh() const  Data::erf() const
917  {  {
918  #if defined DOPROF  #ifdef _WIN32
919    profData->unary++;    throw DataException("Error - Data:: erf function is not supported on _WIN32 platforms.");
920    #else
921      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::erf);
922  #endif  #endif
923    }
924    
925    Data
926    Data::asinh() const
927    {
928    #ifdef _WIN32
929      return escript::unaryOp(*this,escript::asinh_substitute);
930    #else
931    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asinh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asinh);
932    #endif
933  }  }
934    
935  Data  Data
936  Data::acosh() const  Data::acosh() const
937  {  {
938  #if defined DOPROF  #ifdef _WIN32
939    profData->unary++;    return escript::unaryOp(*this,escript::acosh_substitute);
940  #endif  #else
941    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acosh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acosh);
942    #endif
943  }  }
944    
945  Data  Data
946  Data::atanh() const  Data::atanh() const
947  {  {
948  #if defined DOPROF  #ifdef _WIN32
949    profData->unary++;    return escript::unaryOp(*this,escript::atanh_substitute);
950  #endif  #else
951    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atanh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atanh);
952    #endif
953  }  }
954    
955  Data  Data
956  Data::log10() const  Data::log10() const
957  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
958    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log10);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log10);
959  }  }
960    
961  Data  Data
962  Data::log() const  Data::log() const
963  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
964    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);
965  }  }
966    
967  Data  Data
968  Data::sign() const  Data::sign() const
969  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
970    return escript::unaryOp(*this,escript::fsign);    return escript::unaryOp(*this,escript::fsign);
971  }  }
972    
973  Data  Data
974  Data::abs() const  Data::abs() const
975  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
976    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);
977  }  }
978    
979  Data  Data
980  Data::neg() const  Data::neg() const
981  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
982    return escript::unaryOp(*this,negate<double>());    return escript::unaryOp(*this,negate<double>());
983  }  }
984    
985  Data  Data
986  Data::pos() const  Data::pos() const
987  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
988    Data result;    Data result;
989    // perform a deep copy    // perform a deep copy
990    result.copy(*this);    result.copy(*this);
# Line 1208  Data::pos() const Line 994  Data::pos() const
994  Data  Data
995  Data::exp() const  Data::exp() const
996  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
997    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);
998  }  }
999    
1000  Data  Data
1001  Data::sqrt() const  Data::sqrt() const
1002  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
1003    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);
1004  }  }
1005    
# Line 1227  double Line 1007  double
1007  Data::Lsup() const  Data::Lsup() const
1008  {  {
1009    double localValue, globalValue;    double localValue, globalValue;
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
1010    //    //
1011    // set the initial absolute maximum value to zero    // set the initial absolute maximum value to zero
1012    
# Line 1247  double Line 1024  double
1024  Data::Linf() const  Data::Linf() const
1025  {  {
1026    double localValue, globalValue;    double localValue, globalValue;
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
1027    //    //
1028    // set the initial absolute minimum value to max double    // set the initial absolute minimum value to max double
1029    AbsMin abs_min_func;    AbsMin abs_min_func;
# Line 1267  double Line 1041  double
1041  Data::sup() const  Data::sup() const
1042  {  {
1043    double localValue, globalValue;    double localValue, globalValue;
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
1044    //    //
1045    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1046    FMax fmax_func;    FMax fmax_func;
# Line 1286  double Line 1057  double
1057  Data::inf() const  Data::inf() const
1058  {  {
1059    double localValue, globalValue;    double localValue, globalValue;
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
1060    //    //
1061    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1062    FMin fmin_func;    FMin fmin_func;
# Line 1306  Data::inf() const Line 1074  Data::inf() const
1074  Data  Data
1075  Data::maxval() const  Data::maxval() const
1076  {  {
 #if defined DOPROF  
   profData->reduction2++;  
 #endif  
1077    //    //
1078    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1079    FMax fmax_func;    FMax fmax_func;
# Line 1318  Data::maxval() const Line 1083  Data::maxval() const
1083  Data  Data
1084  Data::minval() const  Data::minval() const
1085  {  {
 #if defined DOPROF  
   profData->reduction2++;  
 #endif  
1086    //    //
1087    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1088    FMin fmin_func;    FMin fmin_func;
# Line 1331  Data Line 1093  Data
1093  Data::swapaxes(const int axis0, const int axis1) const  Data::swapaxes(const int axis0, const int axis1) const
1094  {  {
1095       int axis0_tmp,axis1_tmp;       int axis0_tmp,axis1_tmp;
      #if defined DOPROF  
      profData->unary++;  
      #endif  
1096       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1097       DataArrayView::ShapeType ev_shape;       DataArrayView::ShapeType ev_shape;
1098       // 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 1377  Data::swapaxes(const int axis0, const in Line 1136  Data::swapaxes(const int axis0, const in
1136  Data  Data
1137  Data::symmetric() const  Data::symmetric() const
1138  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1139       // check input       // check input
1140       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1141       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
# Line 1402  Data::symmetric() const Line 1158  Data::symmetric() const
1158  Data  Data
1159  Data::nonsymmetric() const  Data::nonsymmetric() const
1160  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1161       // check input       // check input
1162       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1163       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
# Line 1439  Data::nonsymmetric() const Line 1192  Data::nonsymmetric() const
1192  Data  Data
1193  Data::trace(int axis_offset) const  Data::trace(int axis_offset) const
1194  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1195       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1196       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1197          DataArrayView::ShapeType ev_shape;          DataArrayView::ShapeType ev_shape;
# Line 1492  Data::trace(int axis_offset) const Line 1242  Data::trace(int axis_offset) const
1242  Data  Data
1243  Data::transpose(int axis_offset) const  Data::transpose(int axis_offset) const
1244  {  {
      #if defined DOPROF  
      profData->unary++;  
      #endif  
1245       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1246       DataArrayView::ShapeType ev_shape;       DataArrayView::ShapeType ev_shape;
1247       // 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 1516  Data::transpose(int axis_offset) const Line 1263  Data::transpose(int axis_offset) const
1263  Data  Data
1264  Data::eigenvalues() const  Data::eigenvalues() const
1265  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1266       // check input       // check input
1267       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1268       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
# Line 1536  Data::eigenvalues() const Line 1280  Data::eigenvalues() const
1280  const boost::python::tuple  const boost::python::tuple
1281  Data::eigenvalues_and_eigenvectors(const double tol) const  Data::eigenvalues_and_eigenvectors(const double tol) const
1282  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1283       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1284       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
1285          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.");
# Line 1556  Data::eigenvalues_and_eigenvectors(const Line 1297  Data::eigenvalues_and_eigenvectors(const
1297  }  }
1298    
1299  const boost::python::tuple  const boost::python::tuple
1300  Data::mindp() const  Data::minGlobalDataPoint() const
1301  {  {
1302    // 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
1303    // 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
1304    // surrounding function    // surrounding function
1305    
   int SampleNo;  
1306    int DataPointNo;    int DataPointNo;
1307      int ProcNo;    int ProcNo;
1308    calc_mindp(ProcNo,SampleNo,DataPointNo);    calc_minGlobalDataPoint(ProcNo,DataPointNo);
1309    return make_tuple(ProcNo,SampleNo,DataPointNo);    return make_tuple(ProcNo,DataPointNo);
1310  }  }
1311    
1312  void  void
1313  Data::calc_mindp(   int& ProcNo,  Data::calc_minGlobalDataPoint(int& ProcNo,
1314                  int& SampleNo,                          int& DataPointNo) const
         int& DataPointNo) const  
1315  {  {
1316    int i,j;    int i,j;
1317    int lowi=0,lowj=0;    int lowi=0,lowj=0;
# Line 1630  Data::calc_mindp(  int& ProcNo, Line 1369  Data::calc_mindp(  int& ProcNo,
1369  #else  #else
1370      ProcNo = 0;      ProcNo = 0;
1371  #endif  #endif
1372    SampleNo = lowi;    DataPointNo = lowj + lowi * numDPPSample;
   DataPointNo = lowj;  
1373  }  }
1374    
1375  void  void
# Line 1955  Data::getItem(const boost::python::objec Line 1693  Data::getItem(const boost::python::objec
1693  Data  Data
1694  Data::getSlice(const DataArrayView::RegionType& region) const  Data::getSlice(const DataArrayView::RegionType& region) const
1695  {  {
 #if defined DOPROF  
   profData->slicing++;  
 #endif  
1696    return Data(*this,region);    return Data(*this,region);
1697  }  }
1698    
# Line 1999  Data::setSlice(const Data& value, Line 1734  Data::setSlice(const Data& value,
1734    if (isProtected()) {    if (isProtected()) {
1735          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
1736    }    }
 #if defined DOPROF  
   profData->slicing++;  
 #endif  
1737    Data tempValue(value);    Data tempValue(value);
1738    typeMatchLeft(tempValue);    typeMatchLeft(tempValue);
1739    typeMatchRight(tempValue);    typeMatchRight(tempValue);
# Line 2036  Data::typeMatchRight(const Data& right) Line 1768  Data::typeMatchRight(const Data& right)
1768    }    }
1769  }  }
1770    
1771  /* TODO */  void
1772  /* global reduction */  Data::setTaggedValueByName(std::string name,
1773                               const boost::python::object& value)
1774    {
1775         if (getFunctionSpace().getDomain().isValidTagName(name)) {
1776            int tagKey=getFunctionSpace().getDomain().getTag(name);
1777            setTaggedValue(tagKey,value);
1778         }
1779    }
1780  void  void
1781  Data::setTaggedValue(int tagKey,  Data::setTaggedValue(int tagKey,
1782                       const boost::python::object& value)                       const boost::python::object& value)
# Line 2062  Data::setTaggedValue(int tagKey, Line 1801  Data::setTaggedValue(int tagKey,
1801    m_data->setTaggedValue(tagKey,valueDataArray.getView());    m_data->setTaggedValue(tagKey,valueDataArray.getView());
1802  }  }
1803    
 /* TODO */  
 /* global reduction */  
1804  void  void
1805  Data::setTaggedValueFromCPP(int tagKey,  Data::setTaggedValueFromCPP(int tagKey,
1806                              const DataArrayView& value)                              const DataArrayView& value)
# Line 2084  Data::setTaggedValueFromCPP(int tagKey, Line 1821  Data::setTaggedValueFromCPP(int tagKey,
1821    m_data->setTaggedValue(tagKey,value);    m_data->setTaggedValue(tagKey,value);
1822  }  }
1823    
 /* TODO */  
 /* global reduction */  
1824  int  int
1825  Data::getTagNumber(int dpno)  Data::getTagNumber(int dpno)
1826  {  {
1827    return m_data->getTagNumber(dpno);    return m_data->getTagNumber(dpno);
1828  }  }
1829    
 /* 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);  
           }  
         }  
       }  
     }  
   }  
   
 }  
   
1830  void  void
1831  Data::archiveData(const std::string fileName)  Data::archiveData(const std::string fileName)
1832  {  {
# Line 2217  Data::archiveData(const std::string file Line 1868  Data::archiveData(const std::string file
1868    DataArrayView::ShapeType dataPointShape = getDataPointShape();    DataArrayView::ShapeType dataPointShape = getDataPointShape();
1869    vector<int> referenceNumbers(noSamples);    vector<int> referenceNumbers(noSamples);
1870    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {
1871      referenceNumbers[sampleNo] = getFunctionSpace().getReferenceNoFromSampleNo(sampleNo);      referenceNumbers[sampleNo] = getFunctionSpace().getReferenceIDOfSample(sampleNo);
1872    }    }
1873    vector<int> tagNumbers(noSamples);    vector<int> tagNumbers(noSamples);
1874    if (isTagged()) {    if (isTagged()) {
# Line 2426  Data::extractData(const std::string file Line 2077  Data::extractData(const std::string file
2077      throw DataException("extractData Error: incompatible FunctionSpace");      throw DataException("extractData Error: incompatible FunctionSpace");
2078    }    }
2079    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {
2080      if (referenceNumbers[sampleNo] != fspace.getReferenceNoFromSampleNo(sampleNo)) {      if (referenceNumbers[sampleNo] != fspace.getReferenceIDOfSample(sampleNo)) {
2081        throw DataException("extractData Error: incompatible FunctionSpace");        throw DataException("extractData Error: incompatible FunctionSpace");
2082      }      }
2083    }    }
# Line 2526  escript::C_GeneralTensorProduct(Data& ar Line 2177  escript::C_GeneralTensorProduct(Data& ar
2177    // 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)
2178    // 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().
2179    
   #if defined DOPROF  
     // profData->binary++;  
   #endif  
2180    
2181    // Interpolate if necessary and find an appropriate function space    // Interpolate if necessary and find an appropriate function space
2182    Data arg_0_Z, arg_1_Z;    Data arg_0_Z, arg_1_Z;

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

  ViewVC Help
Powered by ViewVC 1.1.26