/[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

trunk/esys2/escript/src/Data/DataExpanded.cpp revision 122 by jgs, Thu Jun 9 05:38:05 2005 UTC trunk/escript/src/DataExpanded.cpp revision 474 by jgs, Mon Jan 30 04:23:44 2006 UTC
# Line 13  Line 13 
13   ******************************************************************************   ******************************************************************************
14  */  */
15    
16  #include "escript/Data/DataException.h"  #include "DataException.h"
17  #include "escript/Data/DataExpanded.h"  #include "DataExpanded.h"
18  #include "escript/Data/DataConstant.h"  #include "DataConstant.h"
19  #include "escript/Data/DataTagged.h"  #include "DataTagged.h"
20  #include "escript/Data/DataArrayView.h"  #include "DataArrayView.h"
21    
22  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
23    
# Line 148  DataExpanded::DataExpanded(const Functio Line 148  DataExpanded::DataExpanded(const Functio
148    : DataAbstract(what)    : DataAbstract(what)
149  {  {
150    //    //
151      // create the view of the data
152      initialise(shape,what.getNumSamples(),what.getNumDPPSample());
153      //
154    // copy the data in the correct format    // copy the data in the correct format
155    m_data.getData()=data;    m_data.getData()=data;
   //  
   // create the view of the data  
   DataArrayView tempView(m_data.getData(),shape);  
   setPointDataView(tempView);  
156  }  }
157    
158  DataExpanded::~DataExpanded()  DataExpanded::~DataExpanded()
# Line 359  DataExpanded::setRefValue(int ref, Line 358  DataExpanded::setRefValue(int ref,
358    
359    for (int n=0; n<numDPPSample; n++) {    for (int n=0; n<numDPPSample; n++) {
360      //      //
361      // Get each data-point in the sample in turn.      // Get *each* data-point in the sample in turn.
362      DataArrayView pointView = getDataPoint(sampleNo, n);      DataArrayView pointView = getDataPoint(sampleNo, n);
363      //      //
364      // Assign the values in the DataArray to this data-point.      // Assign the values in the DataArray to this data-point.
# Line 392  DataExpanded::getRefValue(int ref, Line 391  DataExpanded::getRefValue(int ref,
391    }    }
392    
393    //    //
394    // Get the first data-point associated with this sample number.    // Get the *first* data-point associated with this sample number.
395    DataArrayView pointView = getDataPoint(sampleNo, 0);    DataArrayView pointView = getDataPoint(sampleNo, 0);
396    
397    //    //
# Line 400  DataExpanded::getRefValue(int ref, Line 399  DataExpanded::getRefValue(int ref,
399    value.getView().copy(pointView);    value.getView().copy(pointView);
400  }  }
401    
402    int
403    DataExpanded::archiveData(ofstream& archiveFile,
404                              const DataArrayView::ValueType::size_type noValues) const
405    {
406      return(m_data.archiveData(archiveFile, noValues));
407    }
408    
409    int
410    DataExpanded::extractData(ifstream& archiveFile,
411                              const DataArrayView::ValueType::size_type noValues)
412    {
413      return(m_data.extractData(archiveFile, noValues));
414    }
415    
416    void
417    DataExpanded::copyAll(const boost::python::numeric::array& value) {
418      //
419      // Get the number of samples and data-points per sample.
420      int numSamples = getNumSamples();
421      int numDataPointsPerSample = getNumDPPSample();
422      int dataPointRank = getPointDataView().getRank();
423      ShapeType dataPointShape = getPointDataView().getShape();
424      //
425      // check rank:
426      if (value.getrank()!=dataPointRank+1)
427           throw DataException("Rank of numarray does not match Data object rank");
428      if (value.getshape()[0]!=numSamples*numDataPointsPerSample)
429           throw DataException("leading dimension of numarray is too small");
430      //
431      int dataPoint = 0;
432      for (int sampleNo = 0; sampleNo < numSamples; sampleNo++) {
433        for (int dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
434          DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);
435          if (dataPointRank==0) {
436             dataPointView()=extract<double>(value[dataPoint]);
437          } else if (dataPointRank==1) {
438             for (int i=0; i<dataPointShape[0]; i++) {
439                dataPointView(i)=extract<double>(value[dataPoint][i]);
440             }
441          } else if (dataPointRank==2) {
442             for (int i=0; i<dataPointShape[0]; i++) {
443               for (int j=0; j<dataPointShape[1]; j++) {
444                 dataPointView(i,j)=extract<double>(value[dataPoint][i][j]);
445               }
446             }
447           } else if (dataPointRank==3) {
448             for (int i=0; i<dataPointShape[0]; i++) {
449               for (int j=0; j<dataPointShape[1]; j++) {
450                 for (int k=0; k<dataPointShape[2]; k++) {
451                     dataPointView(i,j,k)=extract<double>(value[dataPoint][i][j][k]);
452                 }
453               }
454             }
455           } else if (dataPointRank==4) {
456             for (int i=0; i<dataPointShape[0]; i++) {
457               for (int j=0; j<dataPointShape[1]; j++) {
458                 for (int k=0; k<dataPointShape[2]; k++) {
459                   for (int l=0; l<dataPointShape[3]; l++) {
460                     dataPointView(i,j,k,l)=extract<double>(value[dataPoint][i][j][k][l]);
461                   }
462                 }
463               }
464             }
465          }
466          dataPoint++;
467        }
468      }
469    }
470  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.122  
changed lines
  Added in v.474

  ViewVC Help
Powered by ViewVC 1.1.26