/[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 854 by gross, Thu Sep 21 05:29:42 2006 UTC revision 1092 by gross, Fri Apr 13 03:39:49 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 350  Data::isTagged() const Line 297  Data::isTagged() const
297    return (temp!=0);    return (temp!=0);
298  }  }
299    
 /* TODO */  
 /* global reduction -- the local data being empty does not imply that it is empty on other processers*/  
300  bool  bool
301  Data::isEmpty() const  Data::isEmpty() const
302  {  {
# Line 425  Data::tag() Line 370  Data::tag()
370  Data  Data
371  Data::oneOver() const  Data::oneOver() const
372  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
373    return escript::unaryOp(*this,bind1st(divides<double>(),1.));    return escript::unaryOp(*this,bind1st(divides<double>(),1.));
374  }  }
375    
376  Data  Data
377  Data::wherePositive() const  Data::wherePositive() const
378  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
379    return escript::unaryOp(*this,bind2nd(greater<double>(),0.0));    return escript::unaryOp(*this,bind2nd(greater<double>(),0.0));
380  }  }
381    
382  Data  Data
383  Data::whereNegative() const  Data::whereNegative() const
384  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
385    return escript::unaryOp(*this,bind2nd(less<double>(),0.0));    return escript::unaryOp(*this,bind2nd(less<double>(),0.0));
386  }  }
387    
388  Data  Data
389  Data::whereNonNegative() const  Data::whereNonNegative() const
390  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
391    return escript::unaryOp(*this,bind2nd(greater_equal<double>(),0.0));    return escript::unaryOp(*this,bind2nd(greater_equal<double>(),0.0));
392  }  }
393    
394  Data  Data
395  Data::whereNonPositive() const  Data::whereNonPositive() const
396  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
397    return escript::unaryOp(*this,bind2nd(less_equal<double>(),0.0));    return escript::unaryOp(*this,bind2nd(less_equal<double>(),0.0));
398  }  }
399    
400  Data  Data
401  Data::whereZero(double tol) const  Data::whereZero(double tol) const
402  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
403    Data dataAbs=abs();    Data dataAbs=abs();
404    return escript::unaryOp(dataAbs,bind2nd(less_equal<double>(),tol));    return escript::unaryOp(dataAbs,bind2nd(less_equal<double>(),tol));
405  }  }
# Line 480  Data::whereZero(double tol) const Line 407  Data::whereZero(double tol) const
407  Data  Data
408  Data::whereNonZero(double tol) const  Data::whereNonZero(double tol) const
409  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
410    Data dataAbs=abs();    Data dataAbs=abs();
411    return escript::unaryOp(dataAbs,bind2nd(greater<double>(),tol));    return escript::unaryOp(dataAbs,bind2nd(greater<double>(),tol));
412  }  }
# Line 490  Data::whereNonZero(double tol) const Line 414  Data::whereNonZero(double tol) const
414  Data  Data
415  Data::interpolate(const FunctionSpace& functionspace) const  Data::interpolate(const FunctionSpace& functionspace) const
416  {  {
 #if defined DOPROF  
   profData->interpolate++;  
 #endif  
417    return Data(*this,functionspace);    return Data(*this,functionspace);
418  }  }
419    
# Line 514  Data::probeInterpolation(const FunctionS Line 435  Data::probeInterpolation(const FunctionS
435  Data  Data
436  Data::gradOn(const FunctionSpace& functionspace) const  Data::gradOn(const FunctionSpace& functionspace) const
437  {  {
 #if defined DOPROF  
   profData->grad++;  
 #endif  
438    if (functionspace.getDomain()!=getDomain())    if (functionspace.getDomain()!=getDomain())
439      throw DataException("Error - gradient cannot be calculated on different domains.");      throw DataException("Error - gradient cannot be calculated on different domains.");
440    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();
# Line 550  Data::getDataPointShape() const Line 468  Data::getDataPointShape() const
468    return getPointDataView().getShape();    return getPointDataView().getShape();
469  }  }
470    
 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");  
471    
   //  
   // 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");  
   }  
472    
473    //  const
   // make sure data is expanded:  
   if (!isExpanded()) {  
     expand();  
   }  
   
   //  
   // and copy over  
   m_data->copyAll(num_array);  
 }  
   
 const  
474  boost::python::numeric::array  boost::python::numeric::array
475  Data::convertToNumArray()  Data:: getValueOfDataPoint(int dataPointNo)
476  {  {
477    //    size_t length=0;
478    // determine the total number of data points    int i, j, k, l;
   int numSamples = getNumSamples();  
   int numDataPointsPerSample = getNumDataPointsPerSample();  
   int numDataPoints = numSamples * numDataPointsPerSample;  
   
479    //    //
480    // determine the rank and shape of each data point    // determine the rank and shape of each data point
481    int dataPointRank = getDataPointRank();    int dataPointRank = getDataPointRank();
# Line 599  Data::convertToNumArray() Line 486  Data::convertToNumArray()
486    boost::python::numeric::array numArray(0.0);    boost::python::numeric::array numArray(0.0);
487    
488    //    //
489    // the rank of the returned numeric array will be the rank of    // the shape of the returned numeric array will be the same
490    // the data points, plus one. Where the rank of the array is n,    // as that of the data point
491    // the last n-1 dimensions will be equal to the shape of the    int arrayRank = dataPointRank;
492    // 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]);  
   }  
493    
494    //    //
495    // resize the numeric array to the shape just calculated    // resize the numeric array to the shape just calculated
496      if (arrayRank==0) {
497        numArray.resize(1);
498      }
499    if (arrayRank==1) {    if (arrayRank==1) {
500      numArray.resize(arrayShape[0]);      numArray.resize(arrayShape[0]);
501    }    }
# Line 626  Data::convertToNumArray() Line 508  Data::convertToNumArray()
508    if (arrayRank==4) {    if (arrayRank==4) {
509      numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3]);      numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3]);
510    }    }
   if (arrayRank==5) {  
     numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3],arrayShape[4]);  
   }  
511    
512    //    if (getNumDataPointsPerSample()>0) {
513    // loop through each data point in turn, loading the values for that data point         int sampleNo = dataPointNo/getNumDataPointsPerSample();
514    // into the numeric array.         int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();
515    int dataPoint = 0;         //
516    for (int sampleNo = 0; sampleNo < numSamples; sampleNo++) {         // Check a valid sample number has been supplied
517      for (int dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {         if ((sampleNo >= getNumSamples()) || (sampleNo < 0 )) {
518        DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);             throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");
519        if (dataPointRank==0) {         }
520          numArray[dataPoint]=dataPointView();                
521        }         //
522        if (dataPointRank==1) {         // Check a valid data point number has been supplied
523          for (int i=0; i<dataPointShape[0]; i++) {         if ((dataPointNoInSample >= getNumDataPointsPerSample()) || (dataPointNoInSample < 0)) {
524            numArray[dataPoint][i]=dataPointView(i);             throw DataException("Error - Data::convertToNumArray: invalid dataPointNoInSample.");
525          }         }
526        }         // TODO: global error handling
527        if (dataPointRank==2) {         // create a view of the data if it is stored locally
528          for (int i=0; i<dataPointShape[0]; i++) {         DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);
529            for (int j=0; j<dataPointShape[1]; j++) {          
530              numArray[dataPoint][i][j] = dataPointView(i,j);         switch( dataPointRank ){
531            }              case 0 :
532          }                  numArray[0] = dataPointView();
533        }                  break;
534        if (dataPointRank==3) {              case 1 :        
535          for (int i=0; i<dataPointShape[0]; i++) {                  for( i=0; i<dataPointShape[0]; i++ )
536            for (int j=0; j<dataPointShape[1]; j++) {                      numArray[i]=dataPointView(i);
537              for (int k=0; k<dataPointShape[2]; k++) {                  break;
538                numArray[dataPoint][i][j][k]=dataPointView(i,j,k);              case 2 :        
539              }                  for( i=0; i<dataPointShape[0]; i++ )
540            }                      for( j=0; j<dataPointShape[1]; j++)
541          }                          numArray[make_tuple(i,j)]=dataPointView(i,j);
542        }                  break;
543        if (dataPointRank==4) {              case 3 :        
544          for (int i=0; i<dataPointShape[0]; i++) {                  for( i=0; i<dataPointShape[0]; i++ )
545            for (int j=0; j<dataPointShape[1]; j++) {                      for( j=0; j<dataPointShape[1]; j++ )
546              for (int k=0; k<dataPointShape[2]; k++) {                          for( k=0; k<dataPointShape[2]; k++)
547                for (int l=0; l<dataPointShape[3]; l++) {                              numArray[make_tuple(i,j,k)]=dataPointView(i,j,k);
548                  numArray[dataPoint][i][j][k][l]=dataPointView(i,j,k,l);                  break;
549                }              case 4 :
550              }                  for( i=0; i<dataPointShape[0]; i++ )
551            }                      for( j=0; j<dataPointShape[1]; j++ )
552          }                          for( k=0; k<dataPointShape[2]; k++ )
553        }                              for( l=0; l<dataPointShape[3]; l++)
554        dataPoint++;                                  numArray[make_tuple(i,j,k,l)]=dataPointView(i,j,k,l);
555      }                  break;
556        }
557    }    }
   
558    //    //
559    // return the loaded array    // return the array
560    return numArray;    return numArray;
 }  
561    
562  const  }
563  boost::python::numeric::array  void
564  Data::convertToNumArrayFromSampleNo(int sampleNo)  Data::setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object)
565  {  {
566    //      // this will throw if the value cannot be represented
567    // Check a valid sample number has been supplied      boost::python::numeric::array num_array(py_object);
568    if (sampleNo >= getNumSamples()) {      setValueOfDataPointToArray(dataPointNo,num_array);
     throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");  
   }  
569    
   //  
   // determine the number of data points per sample  
   int numDataPointsPerSample = getNumDataPointsPerSample();  
570    
571    //  }
   // determine the rank and shape of each data point  
   int dataPointRank = getDataPointRank();  
   DataArrayView::ShapeType dataPointShape = getDataPointShape();  
572    
573    void
574    Data::setValueOfDataPointToArray(int dataPointNo, const boost::python::numeric::array& num_array)
575    {
576      if (isProtected()) {
577            throw DataException("Error - attempt to update protected Data object.");
578      }
579    //    //
580    // create the numeric array to be returned    // check rank
581    boost::python::numeric::array numArray(0.0);    if (num_array.getrank()<getDataPointRank())
582          throw DataException("Rank of numarray does not match Data object rank");
583    
584    //    //
585    // the rank of the returned numeric array will be the rank of    // check shape of num_array
586    // the data points, plus one. Where the rank of the array is n,    for (int i=0; i<getDataPointRank(); i++) {
587    // the last n-1 dimensions will be equal to the shape of the      if (extract<int>(num_array.getshape()[i])!=getDataPointShape()[i])
588    // 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]);  
589    }    }
   
590    //    //
591    // resize the numeric array to the shape just calculated    // make sure data is expanded:
592    if (arrayRank==1) {    if (!isExpanded()) {
593      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]);  
594    }    }
595      if (getNumDataPointsPerSample()>0) {
596    //         int sampleNo = dataPointNo/getNumDataPointsPerSample();
597    // loop through each data point in turn, loading the values for that data point         int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();
598    // into the numeric array.         m_data->copyToDataPoint(sampleNo, dataPointNoInSample,num_array);
599    for (int dataPoint = 0; dataPoint < numDataPointsPerSample; dataPoint++) {    } else {
600      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);  
             }  
           }  
         }  
       }  
     }  
601    }    }
   
   //  
   // return the loaded array  
   return numArray;  
602  }  }
603    
604  const  void
605  boost::python::numeric::array  Data::setValueOfDataPoint(int dataPointNo, const double value)
 Data::convertToNumArrayFromDPNo(int procNo,  
                                 int sampleNo,  
                                                                 int dataPointNo)  
   
606  {  {
607      size_t length=0;    if (isProtected()) {
608      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.");  
609    }    }
   
610    //    //
611    // Check a valid data point number has been supplied    // make sure data is expanded:
612    if (dataPointNo >= getNumDataPointsPerSample()) {    if (!isExpanded()) {
613      throw DataException("Error - Data::convertToNumArray: invalid dataPointNo.");      expand();
614      }
615      if (getNumDataPointsPerSample()>0) {
616           int sampleNo = dataPointNo/getNumDataPointsPerSample();
617           int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();
618           m_data->copyToDataPoint(sampleNo, dataPointNoInSample,value);
619      } else {
620           m_data->copyToDataPoint(-1, 0,value);
621    }    }
622    }
623    
624    const
625    boost::python::numeric::array
626    Data::getValueOfGlobalDataPoint(int procNo, int dataPointNo)
627    {
628      size_t length=0;
629      int i, j, k, l, pos;
630    //    //
631    // determine the rank and shape of each data point    // determine the rank and shape of each data point
632    int dataPointRank = getDataPointRank();    int dataPointRank = getDataPointRank();
# Line 838  Data::convertToNumArrayFromDPNo(int proc Line 660  Data::convertToNumArrayFromDPNo(int proc
660      numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3]);      numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3]);
661    }    }
662    
663      // added for the MPI communication    // added for the MPI communication
664      length=1;    length=1;
665      for( i=0; i<arrayRank; i++ )    for( i=0; i<arrayRank; i++ ) length *= arrayShape[i];
666          length *= arrayShape[i];    double *tmpData = new double[length];
     double *tmpData = new double[length];  
667    
668    //    //
669    // load the values for the data point into the numeric array.    // load the values for the data point into the numeric array.
670    
671      // updated for the MPI case      // updated for the MPI case
672      if( get_MPIRank()==procNo ){      if( get_MPIRank()==procNo ){
673                 if (getNumDataPointsPerSample()>0) {
674                    int sampleNo = dataPointNo/getNumDataPointsPerSample();
675                    int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();
676                    //
677                    // Check a valid sample number has been supplied
678                    if ((sampleNo >= getNumSamples()) || (sampleNo < 0 )) {
679                      throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");
680                    }
681                  
682                    //
683                    // Check a valid data point number has been supplied
684                    if ((dataPointNoInSample >= getNumDataPointsPerSample()) || (dataPointNoInSample < 0)) {
685                      throw DataException("Error - Data::convertToNumArray: invalid dataPointNoInSample.");
686                    }
687                    // TODO: global error handling
688          // create a view of the data if it is stored locally          // create a view of the data if it is stored locally
689          DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);          DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);
690                    
691          // pack the data from the view into tmpData for MPI communication          // pack the data from the view into tmpData for MPI communication
692          pos=0;          pos=0;
# Line 881  Data::convertToNumArrayFromDPNo(int proc Line 717  Data::convertToNumArrayFromDPNo(int proc
717                                  tmpData[pos]=dataPointView(i,j,k,l);                                  tmpData[pos]=dataPointView(i,j,k,l);
718                  break;                  break;
719          }          }
720                }
721      }      }
722  #ifdef PASO_MPI          #ifdef PASO_MPI
723          // broadcast the data to all other processes          // broadcast the data to all other processes
724          MPI_Bcast( tmpData, length, MPI_DOUBLE, procNo, get_MPIComm() );      MPI_Bcast( tmpData, length, MPI_DOUBLE, procNo, get_MPIComm() );
725  #endif          #endif
726    
727      // unpack the data      // unpack the data
728      switch( dataPointRank ){      switch( dataPointRank ){
729          case 0 :          case 0 :
730              numArray[i]=tmpData[0];              numArray[0]=tmpData[0];
731              break;              break;
732          case 1 :                  case 1 :        
733              for( i=0; i<dataPointShape[0]; i++ )              for( i=0; i<dataPointShape[0]; i++ )
# Line 899  Data::convertToNumArrayFromDPNo(int proc Line 736  Data::convertToNumArrayFromDPNo(int proc
736          case 2 :                  case 2 :        
737              for( i=0; i<dataPointShape[0]; i++ )              for( i=0; i<dataPointShape[0]; i++ )
738                  for( j=0; j<dataPointShape[1]; j++ )                  for( j=0; j<dataPointShape[1]; j++ )
739                      tmpData[i+j*dataPointShape[0]];                     numArray[make_tuple(i,j)]=tmpData[i+j*dataPointShape[0]];
740              break;              break;
741          case 3 :                  case 3 :        
742              for( i=0; i<dataPointShape[0]; i++ )              for( i=0; i<dataPointShape[0]; i++ )
743                  for( j=0; j<dataPointShape[1]; j++ )                  for( j=0; j<dataPointShape[1]; j++ )
744                      for( k=0; k<dataPointShape[2]; k++ )                      for( k=0; k<dataPointShape[2]; k++ )
745                          tmpData[i+dataPointShape[0]*(j*+k*dataPointShape[1])];                          numArray[make_tuple(i,j,k)]=tmpData[i+dataPointShape[0]*(j*+k*dataPointShape[1])];
746              break;              break;
747          case 4 :          case 4 :
748              for( i=0; i<dataPointShape[0]; i++ )              for( i=0; i<dataPointShape[0]; i++ )
749                  for( j=0; j<dataPointShape[1]; j++ )                  for( j=0; j<dataPointShape[1]; j++ )
750                      for( k=0; k<dataPointShape[2]; k++ )                      for( k=0; k<dataPointShape[2]; k++ )
751                          for( l=0; l<dataPointShape[3]; l++ )                          for( l=0; l<dataPointShape[3]; l++ )
752                              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]))];
753              break;              break;
754      }      }
755    
756      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);  
           }  
         }  
       }  
     }  
   }  
 */  
   
757    //    //
758    // return the loaded array    // return the loaded array
759    return numArray;    return numArray;
760  }  }
761    
762    
763    
764  boost::python::numeric::array  boost::python::numeric::array
765  Data::integrate() const  Data::integrate() const
766  {  {
# Line 967  Data::integrate() const Line 768  Data::integrate() const
768    int rank = getDataPointRank();    int rank = getDataPointRank();
769    DataArrayView::ShapeType shape = getDataPointShape();    DataArrayView::ShapeType shape = getDataPointShape();
770    
 #if defined DOPROF  
   profData->integrate++;  
 #endif  
771    
772    //    //
773    // calculate the integral values    // calculate the integral values
# Line 1034  Data::integrate() const Line 832  Data::integrate() const
832  Data  Data
833  Data::sin() const  Data::sin() const
834  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
835    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sin);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sin);
836  }  }
837    
838  Data  Data
839  Data::cos() const  Data::cos() const
840  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
841    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cos);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cos);
842  }  }
843    
844  Data  Data
845  Data::tan() const  Data::tan() const
846  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
847    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tan);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tan);
848  }  }
849    
850  Data  Data
851  Data::asin() const  Data::asin() const
852  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
853    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asin);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asin);
854  }  }
855    
856  Data  Data
857  Data::acos() const  Data::acos() const
858  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
859    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acos);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acos);
860  }  }
861    
862    
863  Data  Data
864  Data::atan() const  Data::atan() const
865  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
866    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atan);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atan);
867  }  }
868    
869  Data  Data
870  Data::sinh() const  Data::sinh() const
871  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
872    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sinh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sinh);
873  }  }
874    
875  Data  Data
876  Data::cosh() const  Data::cosh() const
877  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
878    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cosh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cosh);
879  }  }
880    
881  Data  Data
882  Data::tanh() const  Data::tanh() const
883  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
884    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tanh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tanh);
885  }  }
886    
887    
888  Data  Data
889  Data::asinh() const  Data::erf() const
890  {  {
891  #if defined DOPROF  #ifdef _WIN32
892    profData->unary++;    throw DataException("Error - Data:: erf function is not supported on _WIN32 platforms.");
893    #else
894      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::erf);
895  #endif  #endif
896    }
897    
898    Data
899    Data::asinh() const
900    {
901    #ifdef _WIN32
902      return escript::unaryOp(*this,escript::asinh_substitute);
903    #else
904    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asinh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asinh);
905    #endif
906  }  }
907    
908  Data  Data
909  Data::acosh() const  Data::acosh() const
910  {  {
911  #if defined DOPROF  #ifdef _WIN32
912    profData->unary++;    return escript::unaryOp(*this,escript::acosh_substitute);
913  #endif  #else
914    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acosh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acosh);
915    #endif
916  }  }
917    
918  Data  Data
919  Data::atanh() const  Data::atanh() const
920  {  {
921  #if defined DOPROF  #ifdef _WIN32
922    profData->unary++;    return escript::unaryOp(*this,escript::atanh_substitute);
923  #endif  #else
924    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atanh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atanh);
925    #endif
926  }  }
927    
928  Data  Data
929  Data::log10() const  Data::log10() const
930  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
931    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log10);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log10);
932  }  }
933    
934  Data  Data
935  Data::log() const  Data::log() const
936  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
937    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);
938  }  }
939    
940  Data  Data
941  Data::sign() const  Data::sign() const
942  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
943    return escript::unaryOp(*this,escript::fsign);    return escript::unaryOp(*this,escript::fsign);
944  }  }
945    
946  Data  Data
947  Data::abs() const  Data::abs() const
948  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
949    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);
950  }  }
951    
952  Data  Data
953  Data::neg() const  Data::neg() const
954  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
955    return escript::unaryOp(*this,negate<double>());    return escript::unaryOp(*this,negate<double>());
956  }  }
957    
958  Data  Data
959  Data::pos() const  Data::pos() const
960  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
961    Data result;    Data result;
962    // perform a deep copy    // perform a deep copy
963    result.copy(*this);    result.copy(*this);
# Line 1199  Data::pos() const Line 967  Data::pos() const
967  Data  Data
968  Data::exp() const  Data::exp() const
969  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
970    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);
971  }  }
972    
973  Data  Data
974  Data::sqrt() const  Data::sqrt() const
975  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
976    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);
977  }  }
978    
# Line 1218  double Line 980  double
980  Data::Lsup() const  Data::Lsup() const
981  {  {
982    double localValue, globalValue;    double localValue, globalValue;
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
983    //    //
984    // set the initial absolute maximum value to zero    // set the initial absolute maximum value to zero
985    
# Line 1238  double Line 997  double
997  Data::Linf() const  Data::Linf() const
998  {  {
999    double localValue, globalValue;    double localValue, globalValue;
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
1000    //    //
1001    // set the initial absolute minimum value to max double    // set the initial absolute minimum value to max double
1002    AbsMin abs_min_func;    AbsMin abs_min_func;
# Line 1258  double Line 1014  double
1014  Data::sup() const  Data::sup() const
1015  {  {
1016    double localValue, globalValue;    double localValue, globalValue;
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
1017    //    //
1018    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1019    FMax fmax_func;    FMax fmax_func;
# Line 1277  double Line 1030  double
1030  Data::inf() const  Data::inf() const
1031  {  {
1032    double localValue, globalValue;    double localValue, globalValue;
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
1033    //    //
1034    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1035    FMin fmin_func;    FMin fmin_func;
# Line 1297  Data::inf() const Line 1047  Data::inf() const
1047  Data  Data
1048  Data::maxval() const  Data::maxval() const
1049  {  {
 #if defined DOPROF  
   profData->reduction2++;  
 #endif  
1050    //    //
1051    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1052    FMax fmax_func;    FMax fmax_func;
# Line 1309  Data::maxval() const Line 1056  Data::maxval() const
1056  Data  Data
1057  Data::minval() const  Data::minval() const
1058  {  {
 #if defined DOPROF  
   profData->reduction2++;  
 #endif  
1059    //    //
1060    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1061    FMin fmin_func;    FMin fmin_func;
# Line 1322  Data Line 1066  Data
1066  Data::swapaxes(const int axis0, const int axis1) const  Data::swapaxes(const int axis0, const int axis1) const
1067  {  {
1068       int axis0_tmp,axis1_tmp;       int axis0_tmp,axis1_tmp;
      #if defined DOPROF  
      profData->unary++;  
      #endif  
1069       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1070       DataArrayView::ShapeType ev_shape;       DataArrayView::ShapeType ev_shape;
1071       // 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 1368  Data::swapaxes(const int axis0, const in Line 1109  Data::swapaxes(const int axis0, const in
1109  Data  Data
1110  Data::symmetric() const  Data::symmetric() const
1111  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1112       // check input       // check input
1113       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1114       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
# Line 1393  Data::symmetric() const Line 1131  Data::symmetric() const
1131  Data  Data
1132  Data::nonsymmetric() const  Data::nonsymmetric() const
1133  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1134       // check input       // check input
1135       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1136       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
# Line 1430  Data::nonsymmetric() const Line 1165  Data::nonsymmetric() const
1165  Data  Data
1166  Data::trace(int axis_offset) const  Data::trace(int axis_offset) const
1167  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1168       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1169       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1170          DataArrayView::ShapeType ev_shape;          DataArrayView::ShapeType ev_shape;
# Line 1483  Data::trace(int axis_offset) const Line 1215  Data::trace(int axis_offset) const
1215  Data  Data
1216  Data::transpose(int axis_offset) const  Data::transpose(int axis_offset) const
1217  {  {
      #if defined DOPROF  
      profData->unary++;  
      #endif  
1218       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1219       DataArrayView::ShapeType ev_shape;       DataArrayView::ShapeType ev_shape;
1220       // 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 1507  Data::transpose(int axis_offset) const Line 1236  Data::transpose(int axis_offset) const
1236  Data  Data
1237  Data::eigenvalues() const  Data::eigenvalues() const
1238  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1239       // check input       // check input
1240       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1241       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
# Line 1527  Data::eigenvalues() const Line 1253  Data::eigenvalues() const
1253  const boost::python::tuple  const boost::python::tuple
1254  Data::eigenvalues_and_eigenvectors(const double tol) const  Data::eigenvalues_and_eigenvectors(const double tol) const
1255  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1256       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1257       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
1258          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 1547  Data::eigenvalues_and_eigenvectors(const Line 1270  Data::eigenvalues_and_eigenvectors(const
1270  }  }
1271    
1272  const boost::python::tuple  const boost::python::tuple
1273  Data::mindp() const  Data::minGlobalDataPoint() const
1274  {  {
1275    // 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
1276    // 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
1277    // surrounding function    // surrounding function
1278    
   int SampleNo;  
1279    int DataPointNo;    int DataPointNo;
1280      int ProcNo;    int ProcNo;
1281    calc_mindp(ProcNo,SampleNo,DataPointNo);    calc_minGlobalDataPoint(ProcNo,DataPointNo);
1282    return make_tuple(ProcNo,SampleNo,DataPointNo);    return make_tuple(ProcNo,DataPointNo);
1283  }  }
1284    
1285  void  void
1286  Data::calc_mindp(   int& ProcNo,  Data::calc_minGlobalDataPoint(int& ProcNo,
1287                  int& SampleNo,                          int& DataPointNo) const
         int& DataPointNo) const  
1288  {  {
1289    int i,j;    int i,j;
1290    int lowi=0,lowj=0;    int lowi=0,lowj=0;
# Line 1621  Data::calc_mindp(  int& ProcNo, Line 1342  Data::calc_mindp(  int& ProcNo,
1342  #else  #else
1343      ProcNo = 0;      ProcNo = 0;
1344  #endif  #endif
1345    SampleNo = lowi;    DataPointNo = lowj + lowi * numDPPSample;
   DataPointNo = lowj;  
1346  }  }
1347    
1348  void  void
# Line 1946  Data::getItem(const boost::python::objec Line 1666  Data::getItem(const boost::python::objec
1666  Data  Data
1667  Data::getSlice(const DataArrayView::RegionType& region) const  Data::getSlice(const DataArrayView::RegionType& region) const
1668  {  {
 #if defined DOPROF  
   profData->slicing++;  
 #endif  
1669    return Data(*this,region);    return Data(*this,region);
1670  }  }
1671    
# Line 1990  Data::setSlice(const Data& value, Line 1707  Data::setSlice(const Data& value,
1707    if (isProtected()) {    if (isProtected()) {
1708          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
1709    }    }
 #if defined DOPROF  
   profData->slicing++;  
 #endif  
1710    Data tempValue(value);    Data tempValue(value);
1711    typeMatchLeft(tempValue);    typeMatchLeft(tempValue);
1712    typeMatchRight(tempValue);    typeMatchRight(tempValue);
# Line 2027  Data::typeMatchRight(const Data& right) Line 1741  Data::typeMatchRight(const Data& right)
1741    }    }
1742  }  }
1743    
1744  /* TODO */  void
1745  /* global reduction */  Data::setTaggedValueByName(std::string name,
1746                               const boost::python::object& value)
1747    {
1748         if (getFunctionSpace().getDomain().isValidTagName(name)) {
1749            int tagKey=getFunctionSpace().getDomain().getTag(name);
1750            setTaggedValue(tagKey,value);
1751         }
1752    }
1753  void  void
1754  Data::setTaggedValue(int tagKey,  Data::setTaggedValue(int tagKey,
1755                       const boost::python::object& value)                       const boost::python::object& value)
# Line 2053  Data::setTaggedValue(int tagKey, Line 1774  Data::setTaggedValue(int tagKey,
1774    m_data->setTaggedValue(tagKey,valueDataArray.getView());    m_data->setTaggedValue(tagKey,valueDataArray.getView());
1775  }  }
1776    
 /* TODO */  
 /* global reduction */  
1777  void  void
1778  Data::setTaggedValueFromCPP(int tagKey,  Data::setTaggedValueFromCPP(int tagKey,
1779                              const DataArrayView& value)                              const DataArrayView& value)
# Line 2075  Data::setTaggedValueFromCPP(int tagKey, Line 1794  Data::setTaggedValueFromCPP(int tagKey,
1794    m_data->setTaggedValue(tagKey,value);    m_data->setTaggedValue(tagKey,value);
1795  }  }
1796    
 /* TODO */  
 /* global reduction */  
1797  int  int
1798  Data::getTagNumber(int dpno)  Data::getTagNumber(int dpno)
1799  {  {
1800    return m_data->getTagNumber(dpno);    return m_data->getTagNumber(dpno);
1801  }  }
1802    
 /* 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);  
           }  
         }  
       }  
     }  
   }  
   
 }  
   
1803  void  void
1804  Data::archiveData(const std::string fileName)  Data::archiveData(const std::string fileName)
1805  {  {
# Line 2208  Data::archiveData(const std::string file Line 1841  Data::archiveData(const std::string file
1841    DataArrayView::ShapeType dataPointShape = getDataPointShape();    DataArrayView::ShapeType dataPointShape = getDataPointShape();
1842    vector<int> referenceNumbers(noSamples);    vector<int> referenceNumbers(noSamples);
1843    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {
1844      referenceNumbers[sampleNo] = getFunctionSpace().getReferenceNoFromSampleNo(sampleNo);      referenceNumbers[sampleNo] = getFunctionSpace().getReferenceIDOfSample(sampleNo);
1845    }    }
1846    vector<int> tagNumbers(noSamples);    vector<int> tagNumbers(noSamples);
1847    if (isTagged()) {    if (isTagged()) {
# Line 2417  Data::extractData(const std::string file Line 2050  Data::extractData(const std::string file
2050      throw DataException("extractData Error: incompatible FunctionSpace");      throw DataException("extractData Error: incompatible FunctionSpace");
2051    }    }
2052    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {
2053      if (referenceNumbers[sampleNo] != fspace.getReferenceNoFromSampleNo(sampleNo)) {      if (referenceNumbers[sampleNo] != fspace.getReferenceIDOfSample(sampleNo)) {
2054        throw DataException("extractData Error: incompatible FunctionSpace");        throw DataException("extractData Error: incompatible FunctionSpace");
2055      }      }
2056    }    }
# Line 2517  escript::C_GeneralTensorProduct(Data& ar Line 2150  escript::C_GeneralTensorProduct(Data& ar
2150    // 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)
2151    // 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().
2152    
   #if defined DOPROF  
     // profData->binary++;  
   #endif  
2153    
2154    // Interpolate if necessary and find an appropriate function space    // Interpolate if necessary and find an appropriate function space
2155    Data arg_0_Z, arg_1_Z;    Data arg_0_Z, arg_1_Z;

Legend:
Removed from v.854  
changed lines
  Added in v.1092

  ViewVC Help
Powered by ViewVC 1.1.26