/[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 1092 by gross, Fri Apr 13 03:39:49 2007 UTC revision 1327 by matt, Fri Oct 12 07:10:40 2007 UTC
# Line 1  Line 1 
 // $Id$  
1    
2  /*  /* $Id$ */
3   ************************************************************  
4   *          Copyright 2006 by ACcESS MNRF                   *  /*******************************************************
5   *                                                          *   *
6   *              http://www.access.edu.au                    *   *           Copyright 2003-2007 by ACceSS MNRF
7   *       Primary Business: Queensland, Australia            *   *       Copyright 2007 by University of Queensland
8   *  Licensed under the Open Software License version 3.0    *   *
9   *     http://www.opensource.org/licenses/osl-3.0.php       *   *                http://esscc.uq.edu.au
10   *                                                          *   *        Primary Business: Queensland, Australia
11   ************************************************************   *  Licensed under the Open Software License version 3.0
12  */   *     http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16  #include "Data.h"  #include "Data.h"
17    
18  #include "DataExpanded.h"  #include "DataExpanded.h"
19  #include "DataConstant.h"  #include "DataConstant.h"
20  #include "DataTagged.h"  #include "DataTagged.h"
21  #include "DataEmpty.h"  #include "DataEmpty.h"
 #include "DataArray.h"  
22  #include "DataArrayView.h"  #include "DataArrayView.h"
 #include "DataProf.h"  
23  #include "FunctionSpaceFactory.h"  #include "FunctionSpaceFactory.h"
24  #include "AbstractContinuousDomain.h"  #include "AbstractContinuousDomain.h"
25  #include "UnaryFuncs.h"  #include "UnaryFuncs.h"
26    extern "C" {
27    #include "escript/blocktimer.h"
28    }
29    
30  #include <fstream>  #include <fstream>
31  #include <algorithm>  #include <algorithm>
# Line 57  Data::Data(double value, Line 60  Data::Data(double value,
60    for (int i = 0; i < shape.attr("__len__")(); ++i) {    for (int i = 0; i < shape.attr("__len__")(); ++i) {
61      dataPointShape.push_back(extract<const int>(shape[i]));      dataPointShape.push_back(extract<const int>(shape[i]));
62    }    }
63    DataArray temp(dataPointShape,value);  
64    initialise(temp.getView(),what,expanded);    int len = DataArrayView::noValues(dataPointShape);
65      DataVector temp_data(len,value,len);
66      DataArrayView temp_dataView(temp_data, dataPointShape);
67    
68      initialise(temp_dataView, what, expanded);
69    
70    m_protected=false;    m_protected=false;
71  }  }
72    
# Line 67  Data::Data(double value, Line 75  Data::Data(double value,
75         const FunctionSpace& what,         const FunctionSpace& what,
76             bool expanded)             bool expanded)
77  {  {
78    DataArray temp(dataPointShape,value);    int len = DataArrayView::noValues(dataPointShape);
79    pair<int,int> dataShape=what.getDataShape();  
80    initialise(temp.getView(),what,expanded);    DataVector temp_data(len,value,len);
81      DataArrayView temp_dataView(temp_data, dataPointShape);
82    
83      initialise(temp_dataView, what, expanded);
84    
85    m_protected=false;    m_protected=false;
86  }  }
87    
# Line 152  Data::Data(const object& value, Line 164  Data::Data(const object& value,
164    m_protected=false;    m_protected=false;
165  }  }
166    
167    
168  Data::Data(const object& value,  Data::Data(const object& value,
169             const Data& other)             const Data& other)
170  {  {
171    
172      numeric::array asNumArray(value);
173    
174    
175      // extract the shape of the numarray
176      DataArrayView::ShapeType tempShape;
177      for (int i=0; i < asNumArray.getrank(); i++) {
178        tempShape.push_back(extract<int>(asNumArray.getshape()[i]));
179      }
180      // get the space for the data vector
181      int len = DataArrayView::noValues(tempShape);
182      DataVector temp_data(len, 0.0, len);
183      DataArrayView temp_dataView(temp_data, tempShape);
184      temp_dataView.copy(asNumArray);
185    
186    //    //
187    // Create DataConstant using the given value and all other parameters    // Create DataConstant using the given value and all other parameters
188    // copied from other. If value is a rank 0 object this Data    // copied from other. If value is a rank 0 object this Data
189    // will assume the point data shape of other.    // will assume the point data shape of other.
190    DataArray temp(value);  
191    if (temp.getView().getRank()==0) {    if (temp_dataView.getRank()==0) {
192      //      int len = DataArrayView::noValues(other.getPointDataView().getShape());
193      // Create a DataArray with the scalar value for all elements  
194      DataArray temp2(other.getPointDataView().getShape(),temp.getView()());      DataVector temp2_data(len, temp_dataView(), len);
195      initialise(temp2.getView(),other.getFunctionSpace(),false);      DataArrayView temp2_dataView(temp_data, other.getPointDataView().getShape());
196        initialise(temp2_dataView, other.getFunctionSpace(), false);
197    
198    } else {    } else {
199      //      //
200      // Create a DataConstant with the same sample shape as other      // Create a DataConstant with the same sample shape as other
201      initialise(temp.getView(),other.getFunctionSpace(),false);      initialise(temp_dataView, other.getFunctionSpace(), false);
202    }    }
203    m_protected=false;    m_protected=false;
204  }  }
# Line 213  Data::getShapeTuple() const Line 243  Data::getShapeTuple() const
243          throw DataException("Error - illegal Data rank.");          throw DataException("Error - illegal Data rank.");
244    }    }
245  }  }
   
246  void  void
247  Data::copy(const Data& other)  Data::copy(const Data& other)
248  {  {
# Line 266  Data::copy(const Data& other) Line 295  Data::copy(const Data& other)
295    throw DataException("Error - Copy not implemented for this Data type.");    throw DataException("Error - Copy not implemented for this Data type.");
296  }  }
297    
298    
299    void
300    Data::setToZero()
301    {
302      {
303        DataExpanded* temp=dynamic_cast<DataExpanded*>(m_data.get());
304        if (temp!=0) {
305           temp->setToZero();
306           return;
307        }
308      }
309      {
310        DataTagged* temp=dynamic_cast<DataTagged*>(m_data.get());
311        if (temp!=0) {
312          temp->setToZero();
313          return;
314        }
315      }
316      {
317        DataConstant* temp=dynamic_cast<DataConstant*>(m_data.get());
318        if (temp!=0) {
319          temp->setToZero();
320          return;
321        }
322      }
323      throw DataException("Error - Data can not be set to zero.");
324    }
325    
326  void  void
327  Data::copyWithMask(const Data& other,  Data::copyWithMask(const Data& other,
328                     const Data& mask)                     const Data& mask)
# Line 312  Data::isConstant() const Line 369  Data::isConstant() const
369  }  }
370    
371  void  void
372  Data::setProtection()  Data::setProtection()
373  {  {
374     m_protected=true;     m_protected=true;
375  }  }
376    
377  bool  bool
378  Data::isProtected() const  Data::isProtected() const
379  {  {
380     return m_protected;     return m_protected;
381  }  }
382    
# Line 435  Data::probeInterpolation(const FunctionS Line 492  Data::probeInterpolation(const FunctionS
492  Data  Data
493  Data::gradOn(const FunctionSpace& functionspace) const  Data::gradOn(const FunctionSpace& functionspace) const
494  {  {
495      double blocktimer_start = blocktimer_time();
496    if (functionspace.getDomain()!=getDomain())    if (functionspace.getDomain()!=getDomain())
497      throw DataException("Error - gradient cannot be calculated on different domains.");      throw DataException("Error - gradient cannot be calculated on different domains.");
498    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();
499    grad_shape.push_back(functionspace.getDim());    grad_shape.push_back(functionspace.getDim());
500    Data out(0.0,grad_shape,functionspace,true);    Data out(0.0,grad_shape,functionspace,true);
501    getDomain().setToGradient(out,*this);    getDomain().setToGradient(out,*this);
502      blocktimer_increment("grad()", blocktimer_start);
503    return out;    return out;
504  }  }
505    
# Line 470  Data::getDataPointShape() const Line 529  Data::getDataPointShape() const
529    
530    
531    
532  const  const
533  boost::python::numeric::array  boost::python::numeric::array
534  Data:: getValueOfDataPoint(int dataPointNo)  Data:: getValueOfDataPoint(int dataPointNo)
535  {  {
536    size_t length=0;    size_t length=0;
537    int i, j, k, l;    int i, j, k, l;
# Line 517  Data:: getValueOfDataPoint(int dataPoint Line 576  Data:: getValueOfDataPoint(int dataPoint
576         if ((sampleNo >= getNumSamples()) || (sampleNo < 0 )) {         if ((sampleNo >= getNumSamples()) || (sampleNo < 0 )) {
577             throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");             throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");
578         }         }
579                  
580         //         //
581         // Check a valid data point number has been supplied         // Check a valid data point number has been supplied
582         if ((dataPointNoInSample >= getNumDataPointsPerSample()) || (dataPointNoInSample < 0)) {         if ((dataPointNoInSample >= getNumDataPointsPerSample()) || (dataPointNoInSample < 0)) {
# Line 526  Data:: getValueOfDataPoint(int dataPoint Line 585  Data:: getValueOfDataPoint(int dataPoint
585         // TODO: global error handling         // TODO: global error handling
586         // create a view of the data if it is stored locally         // create a view of the data if it is stored locally
587         DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);         DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);
588            
589         switch( dataPointRank ){         switch( dataPointRank ){
590              case 0 :              case 0 :
591                  numArray[0] = dataPointView();                  numArray[0] = dataPointView();
592                  break;                  break;
593              case 1 :                      case 1 :
594                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
595                      numArray[i]=dataPointView(i);                      numArray[i]=dataPointView(i);
596                  break;                  break;
597              case 2 :                      case 2 :
598                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
599                      for( j=0; j<dataPointShape[1]; j++)                      for( j=0; j<dataPointShape[1]; j++)
600                          numArray[make_tuple(i,j)]=dataPointView(i,j);                          numArray[make_tuple(i,j)]=dataPointView(i,j);
601                  break;                  break;
602              case 3 :                      case 3 :
603                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
604                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
605                          for( k=0; k<dataPointShape[2]; k++)                          for( k=0; k<dataPointShape[2]; k++)
# Line 561  Data:: getValueOfDataPoint(int dataPoint Line 620  Data:: getValueOfDataPoint(int dataPoint
620    
621  }  }
622  void  void
623  Data::setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object)  Data::setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object)
624  {  {
625      // this will throw if the value cannot be represented      // this will throw if the value cannot be represented
626      boost::python::numeric::array num_array(py_object);      boost::python::numeric::array num_array(py_object);
# Line 578  Data::setValueOfDataPointToArray(int dat Line 637  Data::setValueOfDataPointToArray(int dat
637    }    }
638    //    //
639    // check rank    // check rank
640    if (num_array.getrank()<getDataPointRank())    if (num_array.getrank()<getDataPointRank())
641        throw DataException("Rank of numarray does not match Data object rank");        throw DataException("Rank of numarray does not match Data object rank");
642    
643    //    //
# Line 621  Data::setValueOfDataPoint(int dataPointN Line 680  Data::setValueOfDataPoint(int dataPointN
680    }    }
681  }  }
682    
683  const  const
684  boost::python::numeric::array  boost::python::numeric::array
685  Data::getValueOfGlobalDataPoint(int procNo, int dataPointNo)  Data::getValueOfGlobalDataPoint(int procNo, int dataPointNo)
686  {  {
687    size_t length=0;    size_t length=0;
688    int i, j, k, l, pos;    int i, j, k, l, pos;
# Line 678  Data::getValueOfGlobalDataPoint(int proc Line 737  Data::getValueOfGlobalDataPoint(int proc
737                  if ((sampleNo >= getNumSamples()) || (sampleNo < 0 )) {                  if ((sampleNo >= getNumSamples()) || (sampleNo < 0 )) {
738                    throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");                    throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");
739                  }                  }
740                  
741                  //                  //
742                  // Check a valid data point number has been supplied                  // Check a valid data point number has been supplied
743                  if ((dataPointNoInSample >= getNumDataPointsPerSample()) || (dataPointNoInSample < 0)) {                  if ((dataPointNoInSample >= getNumDataPointsPerSample()) || (dataPointNoInSample < 0)) {
# Line 687  Data::getValueOfGlobalDataPoint(int proc Line 746  Data::getValueOfGlobalDataPoint(int proc
746                  // TODO: global error handling                  // TODO: global error handling
747          // create a view of the data if it is stored locally          // create a view of the data if it is stored locally
748          DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);          DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);
749            
750          // pack the data from the view into tmpData for MPI communication          // pack the data from the view into tmpData for MPI communication
751          pos=0;          pos=0;
752          switch( dataPointRank ){          switch( dataPointRank ){
753              case 0 :              case 0 :
754                  tmpData[0] = dataPointView();                  tmpData[0] = dataPointView();
755                  break;                  break;
756              case 1 :                      case 1 :
757                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
758                      tmpData[i]=dataPointView(i);                      tmpData[i]=dataPointView(i);
759                  break;                  break;
760              case 2 :                      case 2 :
761                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
762                      for( j=0; j<dataPointShape[1]; j++, pos++ )                      for( j=0; j<dataPointShape[1]; j++, pos++ )
763                          tmpData[pos]=dataPointView(i,j);                          tmpData[pos]=dataPointView(i,j);
764                  break;                  break;
765              case 3 :                      case 3 :
766                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
767                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
768                          for( k=0; k<dataPointShape[2]; k++, pos++ )                          for( k=0; k<dataPointShape[2]; k++, pos++ )
# Line 719  Data::getValueOfGlobalDataPoint(int proc Line 778  Data::getValueOfGlobalDataPoint(int proc
778          }          }
779              }              }
780      }      }
781          #ifdef PASO_MPI          #ifdef PASO_MPI
782          // broadcast the data to all other processes          // broadcast the data to all other processes
783      MPI_Bcast( tmpData, length, MPI_DOUBLE, procNo, get_MPIComm() );      MPI_Bcast( tmpData, length, MPI_DOUBLE, procNo, get_MPIComm() );
784          #endif          #endif
# Line 729  Data::getValueOfGlobalDataPoint(int proc Line 788  Data::getValueOfGlobalDataPoint(int proc
788          case 0 :          case 0 :
789              numArray[0]=tmpData[0];              numArray[0]=tmpData[0];
790              break;              break;
791          case 1 :                  case 1 :
792              for( i=0; i<dataPointShape[0]; i++ )              for( i=0; i<dataPointShape[0]; i++ )
793                  numArray[i]=tmpData[i];                  numArray[i]=tmpData[i];
794              break;              break;
795          case 2 :                  case 2 :
796              for( i=0; i<dataPointShape[0]; i++ )              for( i=0; i<dataPointShape[0]; i++ )
797                  for( j=0; j<dataPointShape[1]; j++ )                  for( j=0; j<dataPointShape[1]; j++ )
798                     numArray[make_tuple(i,j)]=tmpData[i+j*dataPointShape[0]];                     numArray[make_tuple(i,j)]=tmpData[i+j*dataPointShape[0]];
799              break;              break;
800          case 3 :                  case 3 :
801              for( i=0; i<dataPointShape[0]; i++ )              for( i=0; i<dataPointShape[0]; i++ )
802                  for( j=0; j<dataPointShape[1]; j++ )                  for( j=0; j<dataPointShape[1]; j++ )
803                      for( k=0; k<dataPointShape[2]; k++ )                      for( k=0; k<dataPointShape[2]; k++ )
# Line 753  Data::getValueOfGlobalDataPoint(int proc Line 812  Data::getValueOfGlobalDataPoint(int proc
812              break;              break;
813      }      }
814    
815      delete [] tmpData;        delete [] tmpData;
816    //    //
817    // return the loaded array    // return the loaded array
818    return numArray;    return numArray;
# Line 767  Data::integrate() const Line 826  Data::integrate() const
826    int index;    int index;
827    int rank = getDataPointRank();    int rank = getDataPointRank();
828    DataArrayView::ShapeType shape = getDataPointShape();    DataArrayView::ShapeType shape = getDataPointShape();
829      int dataPointSize = getDataPointSize();
830    
831    //    //
832    // calculate the integral values    // calculate the integral values
833    vector<double> integrals(getDataPointSize());    vector<double> integrals(dataPointSize);
834      vector<double> integrals_local(dataPointSize);
835    #ifdef PASO_MPI
836      AbstractContinuousDomain::asAbstractContinuousDomain(getDomain()).setToIntegrals(integrals_local,*this);
837      // Global sum: use an array instead of a vector because elements of array are guaranteed to be contiguous in memory
838      double *tmp = new double[dataPointSize];
839      double *tmp_local = new double[dataPointSize];
840      for (int i=0; i<dataPointSize; i++) { tmp_local[i] = integrals_local[i]; }
841      MPI_Allreduce( &tmp_local[0], &tmp[0], dataPointSize, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
842      for (int i=0; i<dataPointSize; i++) { integrals[i] = tmp[i]; }
843      delete[] tmp;
844      delete[] tmp_local;
845    #else
846    AbstractContinuousDomain::asAbstractContinuousDomain(getDomain()).setToIntegrals(integrals,*this);    AbstractContinuousDomain::asAbstractContinuousDomain(getDomain()).setToIntegrals(integrals,*this);
847    #endif
848    
849    //    //
850    // create the numeric array to be returned    // create the numeric array to be returned
# Line 994  Data::Lsup() const Line 1066  Data::Lsup() const
1066  }  }
1067    
1068  double  double
 Data::Linf() const  
 {  
   double localValue, globalValue;  
   //  
   // set the initial absolute minimum value to max double  
   AbsMin abs_min_func;  
   localValue = algorithm(abs_min_func,numeric_limits<double>::max());  
   
 #ifdef PASO_MPI  
   MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD );  
   return globalValue;  
 #else  
   return localValue;  
 #endif  
 }  
   
 double  
1069  Data::sup() const  Data::sup() const
1070  {  {
1071    double localValue, globalValue;    double localValue, globalValue;
# Line 1092  Data::swapaxes(const int axis0, const in Line 1147  Data::swapaxes(const int axis0, const in
1147       }       }
1148       for (int i=0; i<rank; i++) {       for (int i=0; i<rank; i++) {
1149         if (i == axis0_tmp) {         if (i == axis0_tmp) {
1150            ev_shape.push_back(s[axis1_tmp]);            ev_shape.push_back(s[axis1_tmp]);
1151         } else if (i == axis1_tmp) {         } else if (i == axis1_tmp) {
1152            ev_shape.push_back(s[axis0_tmp]);            ev_shape.push_back(s[axis0_tmp]);
1153         } else {         } else {
1154            ev_shape.push_back(s[i]);            ev_shape.push_back(s[i]);
1155         }         }
1156       }       }
1157       Data ev(0.,ev_shape,getFunctionSpace());       Data ev(0.,ev_shape,getFunctionSpace());
# Line 1112  Data::symmetric() const Line 1167  Data::symmetric() const
1167       // check input       // check input
1168       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1169       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1170          if(s[0] != s[1])          if(s[0] != s[1])
1171             throw DataException("Error - Data::symmetric can only be calculated for rank 2 object with equal first and second dimension.");             throw DataException("Error - Data::symmetric can only be calculated for rank 2 object with equal first and second dimension.");
1172       }       }
1173       else if (getDataPointRank()==4) {       else if (getDataPointRank()==4) {
# Line 1134  Data::nonsymmetric() const Line 1189  Data::nonsymmetric() const
1189       // check input       // check input
1190       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1191       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1192          if(s[0] != s[1])          if(s[0] != s[1])
1193             throw DataException("Error - Data::nonsymmetric can only be calculated for rank 2 object with equal first and second dimension.");             throw DataException("Error - Data::nonsymmetric can only be calculated for rank 2 object with equal first and second dimension.");
1194          DataArrayView::ShapeType ev_shape;          DataArrayView::ShapeType ev_shape;
1195          ev_shape.push_back(s[0]);          ev_shape.push_back(s[0]);
# Line 1238  Data::eigenvalues() const Line 1293  Data::eigenvalues() const
1293  {  {
1294       // check input       // check input
1295       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1296       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
1297          throw DataException("Error - Data::eigenvalues can only be calculated for rank 2 object.");          throw DataException("Error - Data::eigenvalues can only be calculated for rank 2 object.");
1298       if(s[0] != s[1])       if(s[0] != s[1])
1299          throw DataException("Error - Data::eigenvalues can only be calculated for object with equal first and second dimension.");          throw DataException("Error - Data::eigenvalues can only be calculated for object with equal first and second dimension.");
1300       // create return       // create return
1301       DataArrayView::ShapeType ev_shape(1,s[0]);       DataArrayView::ShapeType ev_shape(1,s[0]);
# Line 1254  const boost::python::tuple Line 1309  const boost::python::tuple
1309  Data::eigenvalues_and_eigenvectors(const double tol) const  Data::eigenvalues_and_eigenvectors(const double tol) const
1310  {  {
1311       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1312       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
1313          throw DataException("Error - Data::eigenvalues and eigenvectors can only be calculated for rank 2 object.");          throw DataException("Error - Data::eigenvalues and eigenvectors can only be calculated for rank 2 object.");
1314       if(s[0] != s[1])       if(s[0] != s[1])
1315          throw DataException("Error - Data::eigenvalues and eigenvectors can only be calculated for object with equal first and second dimension.");          throw DataException("Error - Data::eigenvalues and eigenvectors can only be calculated for object with equal first and second dimension.");
1316       // create return       // create return
1317       DataArrayView::ShapeType ev_shape(1,s[0]);       DataArrayView::ShapeType ev_shape(1,s[0]);
# Line 1326  Data::calc_minGlobalDataPoint(int& ProcN Line 1381  Data::calc_minGlobalDataPoint(int& ProcN
1381      int lowProc = 0;      int lowProc = 0;
1382      double *globalMins = new double[get_MPISize()+1];      double *globalMins = new double[get_MPISize()+1];
1383      int error = MPI_Gather ( &next, 1, MPI_DOUBLE, globalMins, 1, MPI_DOUBLE, 0, get_MPIComm() );      int error = MPI_Gather ( &next, 1, MPI_DOUBLE, globalMins, 1, MPI_DOUBLE, 0, get_MPIComm() );
1384        
1385      if( get_MPIRank()==0 ){      if( get_MPIRank()==0 ){
1386          next = globalMins[lowProc];          next = globalMins[lowProc];
1387          for( i=1; i<get_MPISize(); i++ )          for( i=1; i<get_MPISize(); i++ )
# Line 1380  Data::operator+=(const boost::python::ob Line 1435  Data::operator+=(const boost::python::ob
1435    binaryOp(tmp,plus<double>());    binaryOp(tmp,plus<double>());
1436    return (*this);    return (*this);
1437  }  }
1438    Data&
1439    Data::operator=(const Data& other)
1440    {
1441      copy(other);
1442      return (*this);
1443    }
1444    
1445  Data&  Data&
1446  Data::operator-=(const Data& right)  Data::operator-=(const Data& right)
# Line 1454  Data::powD(const Data& right) const Line 1515  Data::powD(const Data& right) const
1515  {  {
1516    Data result;    Data result;
1517    if (getDataPointRank()<right.getDataPointRank()) {    if (getDataPointRank()<right.getDataPointRank()) {
1518       result.copy(right);       result.copy(right);
1519       result.binaryOp(*this,escript::rpow);       result.binaryOp(*this,escript::rpow);
1520    } else {    } else {
1521       result.copy(*this);       result.copy(*this);
# Line 1469  Data::powD(const Data& right) const Line 1530  Data::powD(const Data& right) const
1530  Data  Data
1531  escript::operator+(const Data& left, const Data& right)  escript::operator+(const Data& left, const Data& right)
1532  {  {
1533    Data result;    return C_TensorBinaryOperation(left, right, plus<double>());
   //  
   // perform a deep copy  
   if (left.getDataPointRank()<right.getDataPointRank()) {  
      result.copy(right);  
      result+=left;  
   } else {  
      result.copy(left);  
      result+=right;  
   }  
   return result;  
1534  }  }
1535    
1536  //  //
# Line 1487  escript::operator+(const Data& left, con Line 1538  escript::operator+(const Data& left, con
1538  Data  Data
1539  escript::operator-(const Data& left, const Data& right)  escript::operator-(const Data& left, const Data& right)
1540  {  {
1541    Data result;    return C_TensorBinaryOperation(left, right, minus<double>());
   //  
   // perform a deep copy  
   if (left.getDataPointRank()<right.getDataPointRank()) {  
      result=right.neg();  
      result+=left;  
   } else {  
      result.copy(left);  
      result-=right;  
   }  
   return result;  
1542  }  }
1543    
1544  //  //
# Line 1505  escript::operator-(const Data& left, con Line 1546  escript::operator-(const Data& left, con
1546  Data  Data
1547  escript::operator*(const Data& left, const Data& right)  escript::operator*(const Data& left, const Data& right)
1548  {  {
1549    Data result;    return C_TensorBinaryOperation(left, right, multiplies<double>());
   //  
   // perform a deep copy  
   if (left.getDataPointRank()<right.getDataPointRank()) {  
      result.copy(right);  
      result*=left;  
   } else {  
      result.copy(left);  
      result*=right;  
   }  
   return result;  
1550  }  }
1551    
1552  //  //
# Line 1523  escript::operator*(const Data& left, con Line 1554  escript::operator*(const Data& left, con
1554  Data  Data
1555  escript::operator/(const Data& left, const Data& right)  escript::operator/(const Data& left, const Data& right)
1556  {  {
1557    Data result;    return C_TensorBinaryOperation(left, right, divides<double>());
   //  
   // perform a deep copy  
   if (left.getDataPointRank()<right.getDataPointRank()) {  
      result=right.oneOver();  
      result*=left;  
   } else {  
      result.copy(left);  
      result/=right;  
   }  
   return result;  
1558  }  }
1559    
1560  //  //
# Line 1648  escript::operator/(const boost::python:: Line 1669  escript::operator/(const boost::python::
1669  /* TODO */  /* TODO */
1670  /* global reduction */  /* global reduction */
1671  Data  Data
1672  Data::getItem(const boost::python::object& key) const  Data::getItem(const boost::python::object& key) const
1673  {  {
1674    const DataArrayView& view=getPointDataView();    const DataArrayView& view=getPointDataView();
1675    
# Line 1679  Data::setItemO(const boost::python::obje Line 1700  Data::setItemO(const boost::python::obje
1700    setItemD(key,tempData);    setItemD(key,tempData);
1701  }  }
1702    
 /* TODO */  
 /* global reduction */  
1703  void  void
1704  Data::setItemD(const boost::python::object& key,  Data::setItemD(const boost::python::object& key,
1705                 const Data& value)                 const Data& value)
# Line 1698  Data::setItemD(const boost::python::obje Line 1717  Data::setItemD(const boost::python::obje
1717    }    }
1718  }  }
1719    
 /* TODO */  
 /* global reduction */  
1720  void  void
1721  Data::setSlice(const Data& value,  Data::setSlice(const Data& value,
1722                 const DataArrayView::RegionType& region)                 const DataArrayView::RegionType& region)
# Line 1743  Data::typeMatchRight(const Data& right) Line 1760  Data::typeMatchRight(const Data& right)
1760    
1761  void  void
1762  Data::setTaggedValueByName(std::string name,  Data::setTaggedValueByName(std::string name,
1763                             const boost::python::object& value)                             const boost::python::object& value)
1764  {  {
1765       if (getFunctionSpace().getDomain().isValidTagName(name)) {       if (getFunctionSpace().getDomain().isValidTagName(name)) {
1766          int tagKey=getFunctionSpace().getDomain().getTag(name);          int tagKey=getFunctionSpace().getDomain().getTag(name);
# Line 1765  Data::setTaggedValue(int tagKey, Line 1782  Data::setTaggedValue(int tagKey,
1782      throw DataException("Error - DataTagged conversion failed!!");      throw DataException("Error - DataTagged conversion failed!!");
1783    }    }
1784    
1785    //    numeric::array asNumArray(value);
1786    // Construct DataArray from boost::python::object input value  
1787    DataArray valueDataArray(value);  
1788      // extract the shape of the numarray
1789      DataArrayView::ShapeType tempShape;
1790      for (int i=0; i < asNumArray.getrank(); i++) {
1791        tempShape.push_back(extract<int>(asNumArray.getshape()[i]));
1792      }
1793    
1794      // get the space for the data vector
1795      int len = DataArrayView::noValues(tempShape);
1796      DataVector temp_data(len, 0.0, len);
1797      DataArrayView temp_dataView(temp_data, tempShape);
1798      temp_dataView.copy(asNumArray);
1799    
1800    //    //
1801    // Call DataAbstract::setTaggedValue    // Call DataAbstract::setTaggedValue
1802    m_data->setTaggedValue(tagKey,valueDataArray.getView());    m_data->setTaggedValue(tagKey,temp_dataView);
1803  }  }
1804    
1805  void  void
# Line 1788  Data::setTaggedValueFromCPP(int tagKey, Line 1816  Data::setTaggedValueFromCPP(int tagKey,
1816    if (!isTagged()) {    if (!isTagged()) {
1817      throw DataException("Error - DataTagged conversion failed!!");      throw DataException("Error - DataTagged conversion failed!!");
1818    }    }
1819                                                                                                                  
1820    //    //
1821    // Call DataAbstract::setTaggedValue    // Call DataAbstract::setTaggedValue
1822    m_data->setTaggedValue(tagKey,value);    m_data->setTaggedValue(tagKey,value);
# Line 2150  escript::C_GeneralTensorProduct(Data& ar Line 2178  escript::C_GeneralTensorProduct(Data& ar
2178    // 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)
2179    // 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().
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;
2183    if (arg_0.getFunctionSpace()!=arg_1.getFunctionSpace()) {    if (arg_0.getFunctionSpace()!=arg_1.getFunctionSpace()) {
# Line 2511  Data::borrowData() const Line 2538  Data::borrowData() const
2538  /* Member functions specific to the MPI implementation */  /* Member functions specific to the MPI implementation */
2539    
2540  void  void
2541  Data::print()  Data::print()
2542  {  {
2543    int i,j;    int i,j;
2544      
2545    printf( "Data is %dX%d\n", getNumSamples(), getNumDataPointsPerSample() );    printf( "Data is %dX%d\n", getNumSamples(), getNumDataPointsPerSample() );
2546    for( i=0; i<getNumSamples(); i++ )    for( i=0; i<getNumSamples(); i++ )
2547    {    {
# Line 2524  Data::print() Line 2551  Data::print()
2551      printf( "\n" );      printf( "\n" );
2552    }    }
2553  }  }
2554    void
2555    Data::dump(const std::string fileName) const
2556    {
2557      try
2558         {
2559            return m_data->dump(fileName);
2560         }
2561         catch (exception& e)
2562         {
2563            cout << e.what() << endl;
2564         }
2565    }
2566    
2567  int  int
2568  Data::get_MPISize() const  Data::get_MPISize() const
# Line 2551  Data::get_MPIRank() const Line 2590  Data::get_MPIRank() const
2590    
2591  MPI_Comm  MPI_Comm
2592  Data::get_MPIComm() const  Data::get_MPIComm() const
2593  {  {
2594  #ifdef PASO_MPI  #ifdef PASO_MPI
2595      return MPI_COMM_WORLD;      return MPI_COMM_WORLD;
2596  #else  #else

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

  ViewVC Help
Powered by ViewVC 1.1.26