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

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

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

revision 1801 by ksteube, Fri Sep 19 01:37:09 2008 UTC revision 1808 by jfenwick, Thu Sep 25 03:14:56 2008 UTC
# Line 39  DataExpanded::DataExpanded(const boost:: Line 39  DataExpanded::DataExpanded(const boost::
39                             const FunctionSpace& what)                             const FunctionSpace& what)
40    : DataAbstract(what,DataTypes::shapeFromNumArray(value))    : DataAbstract(what,DataTypes::shapeFromNumArray(value))
41  {  {
 /*  DataTypes::ShapeType tempShape;  
   //  
   // extract the shape of the python numarray  
   for (int i=0; i<value.getrank(); i++) {  
     tempShape.push_back(extract<int>(value.getshape()[i]));  
   }*/  
42    //    //
43    // initialise the data array for this object    // initialise the data array for this object
44    initialise(what.getNumSamples(),what.getNumDPPSample());    initialise(what.getNumSamples(),what.getNumDPPSample());
# Line 57  DataExpanded::DataExpanded(const DataExp Line 51  DataExpanded::DataExpanded(const DataExp
51    : DataAbstract(other.getFunctionSpace(), other.getShape()),    : DataAbstract(other.getFunctionSpace(), other.getShape()),
52    m_data(other.m_data)    m_data(other.m_data)
53  {  {
 /*  
   //  
   // create the view for the data  
   DataArrayView temp(m_data.getData(),other.getPointDataView().getShape());  
   setPointDataView(temp);  
   
   // keep local shape in sync  
   setShape(other.getPointDataView().getShape());*/  
54  }  }
55    
56  DataExpanded::DataExpanded(const DataConstant& other)  DataExpanded::DataExpanded(const DataConstant& other)
# Line 94  DataExpanded::DataExpanded(const DataTag Line 80  DataExpanded::DataExpanded(const DataTag
80    for (i=0;i<numRows;i++) {    for (i=0;i<numRows;i++) {
81      for (j=0;j<numCols;j++) {      for (j=0;j<numCols;j++) {
82        try {        try {
 //         getPointDataView().copy(getPointOffset(i,j),  
 //                                 other.getPointDataView(),  
 //                                 other.getPointOffset(i,j));  
83             DataTypes::copyPoint(getVector(), getPointOffset(i,j), getNoValues(),             DataTypes::copyPoint(getVector(), getPointOffset(i,j), getNoValues(),
84                                  other.getVector(),                                  other.getVector(),
85                                  other.getPointOffset(i,j));                                  other.getPointOffset(i,j));
# Line 336  void Line 319  void
319  DataExpanded::initialise(int noSamples,  DataExpanded::initialise(int noSamples,
320                           int noDataPointsPerSample)                           int noDataPointsPerSample)
321  {  {
322      if (noSamples==0)     //retain the default empty object
323      {
324         return;
325      }
326    //    //
327    // resize data array to the required size    // resize data array to the required size
328    m_data.resize(noSamples,noDataPointsPerSample,getNoValues());    m_data.resize(noSamples,noDataPointsPerSample,getNoValues());
   
   //  
 //   // create the data view of the data array  
 //   DataArrayView temp(m_data.getData(),shape);  
 //   setPointDataView(temp);  
   
 //   // keep shape in sync  
 //   setShape(shape);  
329  }  }
330    
331  string  string
# Line 354  DataExpanded::toString() const Line 333  DataExpanded::toString() const
333  {  {
334    stringstream temp;    stringstream temp;
335    FunctionSpace fs=getFunctionSpace();    FunctionSpace fs=getFunctionSpace();
   //  
   // create a temporary view as the offset will be changed  
 //  DataArrayView tempView(getPointDataView().getData(),getPointDataView().getShape(),getPointDataView().getOffset());  
336    
337    int offset=0;    int offset=0;
338    for (int i=0;i<m_data.getNumRows();i++) {    for (int i=0;i<m_data.getNumRows();i++) {
# Line 370  DataExpanded::toString() const Line 346  DataExpanded::toString() const
346        }        }
347      }      }
348    }    }
349      string result=temp.str();
350      if (result.empty())
351      {
352        return "(data contains no samples)\n";
353      }
354    return temp.str();    return temp.str();
355  }  }
356    
# Line 380  DataExpanded::getPointOffset(int sampleN Line 361  DataExpanded::getPointOffset(int sampleN
361    return m_data.index(sampleNo,dataPointNo);    return m_data.index(sampleNo,dataPointNo);
362  }  }
363    
 // DataArrayView  
 // DataExpanded::getDataPoint(int sampleNo,  
 //                            int dataPointNo)  
 // {  
 //   DataArrayView temp(m_data.getData(),getPointDataView().getShape(),getPointOffset(sampleNo,dataPointNo));  
 //   return temp;  
 // }  
   
364  DataTypes::ValueType::size_type  DataTypes::ValueType::size_type
365  DataExpanded::getLength() const  DataExpanded::getLength() const
366  {  {
# Line 467  DataExpanded::copyToDataPoint(const int Line 440  DataExpanded::copyToDataPoint(const int
440       if ((dataPointNo >= numDataPointsPerSample) || (dataPointNo < 0)) {       if ((dataPointNo >= numDataPointsPerSample) || (dataPointNo < 0)) {
441             throw DataException("Error - DataExpanded::copyDataPoint invalid dataPointNoInSample.");             throw DataException("Error - DataExpanded::copyDataPoint invalid dataPointNoInSample.");
442       }       }
  //    DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);  
443       ValueType& vec=getVector();       ValueType& vec=getVector();
444       if (dataPointRank==0) {       if (dataPointRank==0) {
445           vec[0]=extract<double>(value[0]);           vec[0]=extract<double>(value[0]);
# Line 521  DataExpanded::copyAll(const boost::pytho Line 493  DataExpanded::copyAll(const boost::pytho
493    int dataPoint = 0;    int dataPoint = 0;
494    for (int sampleNo = 0; sampleNo < numSamples; sampleNo++) {    for (int sampleNo = 0; sampleNo < numSamples; sampleNo++) {
495      for (int dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {      for (int dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
 //       DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);  
496        ValueType::size_type offset=getPointOffset(sampleNo, dataPointNo);        ValueType::size_type offset=getPointOffset(sampleNo, dataPointNo);
497        if (dataPointRank==0) {        if (dataPointRank==0) {
498           vec[offset]=extract<double>(value[dataPoint]);           vec[offset]=extract<double>(value[dataPoint]);
# Line 533  DataExpanded::copyAll(const boost::pytho Line 504  DataExpanded::copyAll(const boost::pytho
504           for (int i=0; i<dataPointShape[0]; i++) {           for (int i=0; i<dataPointShape[0]; i++) {
505             for (int j=0; j<dataPointShape[1]; j++) {             for (int j=0; j<dataPointShape[1]; j++) {
506           vec[offset+getRelIndex(dataPointShape,i,j)]=extract<double>(value[dataPoint][i][j]);           vec[offset+getRelIndex(dataPointShape,i,j)]=extract<double>(value[dataPoint][i][j]);
 //             dataPointView(i,j)=extract<double>(value[dataPoint][i][j]);  
507             }             }
508           }           }
509         } else if (dataPointRank==3) {         } else if (dataPointRank==3) {
# Line 569  DataExpanded::symmetric(DataAbstract* ev Line 539  DataExpanded::symmetric(DataAbstract* ev
539    if (temp_ev==0) {    if (temp_ev==0) {
540      throw DataException("Error - DataExpanded::symmetric: casting to DataExpanded failed (propably a programming error).");      throw DataException("Error - DataExpanded::symmetric: casting to DataExpanded failed (propably a programming error).");
541    }    }
 //  DataArrayView& thisView=getPointDataView();  
 //  DataArrayView& evView=ev->getPointDataView();  
542    ValueType& vec=getVector();    ValueType& vec=getVector();
543    const ShapeType& shape=getShape();    const ShapeType& shape=getShape();
544    ValueType& evVec=temp_ev->getVector();    ValueType& evVec=temp_ev->getVector();
# Line 593  DataExpanded::nonsymmetric(DataAbstract* Line 561  DataExpanded::nonsymmetric(DataAbstract*
561    if (temp_ev==0) {    if (temp_ev==0) {
562      throw DataException("Error - DataExpanded::nonsymmetric: casting to DataExpanded failed (propably a programming error).");      throw DataException("Error - DataExpanded::nonsymmetric: casting to DataExpanded failed (propably a programming error).");
563    }    }
 //   DataArrayView& thisView=getPointDataView();  
 //   DataArrayView& evView=ev->getPointDataView();  
564    ValueType& vec=getVector();    ValueType& vec=getVector();
565    const ShapeType& shape=getShape();    const ShapeType& shape=getShape();
566    ValueType& evVec=temp_ev->getVector();    ValueType& evVec=temp_ev->getVector();
# Line 602  DataExpanded::nonsymmetric(DataAbstract* Line 568  DataExpanded::nonsymmetric(DataAbstract*
568    #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)    #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
569    for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {    for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
570      for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {      for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
 //          DataArrayView::nonsymmetric(thisView,getPointOffset(sampleNo,dataPointNo),  
 //                                     evView,ev->getPointOffset(sampleNo,dataPointNo));  
571           DataMaths::nonsymmetric(vec,shape,getPointOffset(sampleNo,dataPointNo),           DataMaths::nonsymmetric(vec,shape,getPointOffset(sampleNo,dataPointNo),
572                                      evVec,evShape,ev->getPointOffset(sampleNo,dataPointNo));                                      evVec,evShape,ev->getPointOffset(sampleNo,dataPointNo));
573      }      }
# Line 626  DataExpanded::trace(DataAbstract* ev, in Line 590  DataExpanded::trace(DataAbstract* ev, in
590    #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)    #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
591    for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {    for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
592      for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {      for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
 /*         DataArrayView::trace(thisView,getPointOffset(sampleNo,dataPointNo),  
                                     evView,ev->getPointOffset(sampleNo,dataPointNo),axis_offset);*/  
593           DataMaths::trace(vec,shape,getPointOffset(sampleNo,dataPointNo),           DataMaths::trace(vec,shape,getPointOffset(sampleNo,dataPointNo),
594                                      evVec,evShape,ev->getPointOffset(sampleNo,dataPointNo),axis_offset);                                      evVec,evShape,ev->getPointOffset(sampleNo,dataPointNo),axis_offset);
595      }      }
# Line 822  DataExpanded::dump(const std::string fil Line 784  DataExpanded::dump(const std::string fil
784     if (! (ncdims[rank+1] = dataFile.add_dim("num_samples", dims[rank+1])) )     if (! (ncdims[rank+1] = dataFile.add_dim("num_samples", dims[rank+1])) )
785              throw DataException("Error - DataExpanded:: appending num_sample to netCDF file failed.");              throw DataException("Error - DataExpanded:: appending num_sample to netCDF file failed.");
786    
787     if (! ( ids = dataFile.add_var("id", ncInt, ncdims[rank+1])) )     if (getFunctionSpace().getNumSamples()>0)
788       {
789    
790         if (! ( ids = dataFile.add_var("id", ncInt, ncdims[rank+1])) )
791          throw DataException("Error - DataExpanded:: appending reference id to netCDF file failed.");          throw DataException("Error - DataExpanded:: appending reference id to netCDF file failed.");
792     const int* ids_p=getFunctionSpace().borrowSampleReferenceIDs();       const int* ids_p=getFunctionSpace().borrowSampleReferenceIDs();
793     if (! (ids->put(ids_p,dims[rank+1])) )       if (! (ids->put(ids_p,dims[rank+1])) )
794          throw DataException("Error - DataExpanded:: copy reference id  to netCDF buffer failed.");          throw DataException("Error - DataExpanded:: copy reference id  to netCDF buffer failed.");
795         if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )
    if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )  
796          throw DataException("Error - DataExpanded:: appending variable to netCDF file failed.");          throw DataException("Error - DataExpanded:: appending variable to netCDF file failed.");
797     if (! (var->put(d_ptr,dims)) )       if (! (var->put(d_ptr,dims)) )
798          throw DataException("Error - DataExpanded:: copy data to netCDF buffer failed.");          throw DataException("Error - DataExpanded:: copy data to netCDF buffer failed.");
799       }
800  #ifdef PASO_MPI  #ifdef PASO_MPI
801     if (mpi_iam<mpi_num-1) MPI_Send(&ndims, 0, MPI_INT, mpi_iam+1, 81801, MPI_COMM_WORLD);     if (mpi_iam<mpi_num-1) MPI_Send(&ndims, 0, MPI_INT, mpi_iam+1, 81801, MPI_COMM_WORLD);
802  #endif  #endif
# Line 840  DataExpanded::dump(const std::string fil Line 805  DataExpanded::dump(const std::string fil
805     #endif     #endif
806  }  }
807    
 // void  
 // DataExpanded::setTaggedValue(int tagKey,  
 //                              const DataArrayView& value)  
 // {  
 //   int numSamples = getNumSamples();  
 //   int numDataPointsPerSample = getNumDPPSample();  
 //   int sampleNo,dataPointNo, i;  
 //   DataTypes::ValueType::size_type n = getNoValues();  
 //   double* p,*in=&(value.getData()[0]);  
 //    
 //   if (value.noValues() != n) {  
 //     throw DataException("Error - DataExpanded::setTaggedValue: number of input values does not match number of values per data points.");  
 //   }  
 //  
 //   #pragma omp parallel for private(sampleNo,dataPointNo,p,i) schedule(static)  
 //   for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {  
 //     if (getFunctionSpace().getTagFromSampleNo(sampleNo) == tagKey ) {  
 //         for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {  
 //             p=&(m_data[getPointOffset(sampleNo,dataPointNo)]);  
 //             for (i=0; i<n ;++i) p[i]=in[i];  
 //         }  
 //     }  
 //   }  
 // }  
   
808  void    void  
809  DataExpanded::setTaggedValue(int tagKey,  DataExpanded::setTaggedValue(int tagKey,
810             const DataTypes::ShapeType& pointshape,             const DataTypes::ShapeType& pointshape,

Legend:
Removed from v.1801  
changed lines
  Added in v.1808

  ViewVC Help
Powered by ViewVC 1.1.26