/[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 123 by jgs, Fri Jul 8 04:08:13 2005 UTC trunk/escript/src/DataExpanded.cpp revision 584 by gross, Thu Mar 9 23:03:38 2006 UTC
# Line 13  Line 13 
13   ******************************************************************************   ******************************************************************************
14  */  */
15    
16  #include "escript/Data/DataException.h"  #include "DataExpanded.h"
17  #include "escript/Data/DataExpanded.h"  #include "DataException.h"
18  #include "escript/Data/DataConstant.h"  #include "DataConstant.h"
19  #include "escript/Data/DataTagged.h"  #include "DataTagged.h"
 #include "escript/Data/DataArrayView.h"  
20    
21  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
22    
 #include <iostream>  
   
23  using namespace std;  using namespace std;
24  using namespace boost::python;  using namespace boost::python;
25  using namespace boost;  using namespace boost;
# Line 148  DataExpanded::DataExpanded(const Functio Line 145  DataExpanded::DataExpanded(const Functio
145    : DataAbstract(what)    : DataAbstract(what)
146  {  {
147    //    //
148      // create the view of the data
149      initialise(shape,what.getNumSamples(),what.getNumDPPSample());
150      //
151    // copy the data in the correct format    // copy the data in the correct format
152    m_data.getData()=data;    m_data.getData()=data;
   //  
   // create the view of the data  
   DataArrayView tempView(m_data.getData(),shape);  
   setPointDataView(tempView);  
153  }  }
154    
155  DataExpanded::~DataExpanded()  DataExpanded::~DataExpanded()
# Line 359  DataExpanded::setRefValue(int ref, Line 355  DataExpanded::setRefValue(int ref,
355    
356    for (int n=0; n<numDPPSample; n++) {    for (int n=0; n<numDPPSample; n++) {
357      //      //
358      // Get each data-point in the sample in turn.      // Get *each* data-point in the sample in turn.
359      DataArrayView pointView = getDataPoint(sampleNo, n);      DataArrayView pointView = getDataPoint(sampleNo, n);
360      //      //
361      // 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 388  DataExpanded::getRefValue(int ref,
388    }    }
389    
390    //    //
391    // Get the first data-point associated with this sample number.    // Get the *first* data-point associated with this sample number.
392    DataArrayView pointView = getDataPoint(sampleNo, 0);    DataArrayView pointView = getDataPoint(sampleNo, 0);
393    
394    //    //
# Line 414  DataExpanded::extractData(ifstream& arch Line 410  DataExpanded::extractData(ifstream& arch
410    return(m_data.extractData(archiveFile, noValues));    return(m_data.extractData(archiveFile, noValues));
411  }  }
412    
413    void
414    DataExpanded::copyAll(const boost::python::numeric::array& value) {
415      //
416      // Get the number of samples and data-points per sample.
417      int numSamples = getNumSamples();
418      int numDataPointsPerSample = getNumDPPSample();
419      int dataPointRank = getPointDataView().getRank();
420      ShapeType dataPointShape = getPointDataView().getShape();
421      //
422      // check rank:
423      if (value.getrank()!=dataPointRank+1)
424           throw DataException("Rank of numarray does not match Data object rank");
425      if (value.getshape()[0]!=numSamples*numDataPointsPerSample)
426           throw DataException("leading dimension of numarray is too small");
427      //
428      int dataPoint = 0;
429      for (int sampleNo = 0; sampleNo < numSamples; sampleNo++) {
430        for (int dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
431          DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);
432          if (dataPointRank==0) {
433             dataPointView()=extract<double>(value[dataPoint]);
434          } else if (dataPointRank==1) {
435             for (int i=0; i<dataPointShape[0]; i++) {
436                dataPointView(i)=extract<double>(value[dataPoint][i]);
437             }
438          } else if (dataPointRank==2) {
439             for (int i=0; i<dataPointShape[0]; i++) {
440               for (int j=0; j<dataPointShape[1]; j++) {
441                 dataPointView(i,j)=extract<double>(value[dataPoint][i][j]);
442               }
443             }
444           } else if (dataPointRank==3) {
445             for (int i=0; i<dataPointShape[0]; i++) {
446               for (int j=0; j<dataPointShape[1]; j++) {
447                 for (int k=0; k<dataPointShape[2]; k++) {
448                     dataPointView(i,j,k)=extract<double>(value[dataPoint][i][j][k]);
449                 }
450               }
451             }
452           } else if (dataPointRank==4) {
453             for (int i=0; i<dataPointShape[0]; i++) {
454               for (int j=0; j<dataPointShape[1]; j++) {
455                 for (int k=0; k<dataPointShape[2]; k++) {
456                   for (int l=0; l<dataPointShape[3]; l++) {
457                     dataPointView(i,j,k,l)=extract<double>(value[dataPoint][i][j][k][l]);
458                   }
459                 }
460               }
461             }
462          }
463          dataPoint++;
464        }
465      }
466    }
467    void
468    DataExpanded::eigenvalues(DataAbstract* ev)
469    {
470      int sampleNo,dataPointNo;
471      int numSamples = getNumSamples();
472      int numDataPointsPerSample = getNumDPPSample();
473      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
474      if (temp_ev==0) {
475        throw DataException("Error - DataExpanded::eigenvalues: casting to DataExpanded failed (propably a programming error).");
476      }
477      DataArrayView& thisView=getPointDataView();
478      DataArrayView& evView=ev->getPointDataView();
479      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
480      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
481        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
482             DataArrayView::eigenvalues(thisView,getPointOffset(sampleNo,dataPointNo),
483                                        evView,ev->getPointOffset(sampleNo,dataPointNo));
484        }
485      }
486    }
487    void
488    DataExpanded::eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol)
489    {
490      int numSamples = getNumSamples();
491      int numDataPointsPerSample = getNumDPPSample();
492      int sampleNo,dataPointNo;
493      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
494      if (temp_ev==0) {
495        throw DataException("Error - DataExpanded::eigenvalues_and_eigenvectors: casting to DataExpanded failed (propably a programming error).");
496      }
497      DataExpanded* temp_V=dynamic_cast<DataExpanded*>(V);
498      if (temp_V==0) {
499        throw DataException("Error - DataExpanded::eigenvalues_and_eigenvectors: casting to DataExpanded failed (propably a programming error).");
500      }
501      DataArrayView& thisView=getPointDataView();
502      DataArrayView& evView=ev->getPointDataView();
503      DataArrayView& VView=V->getPointDataView();
504      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
505      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
506        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
507             DataArrayView::eigenvalues_and_eigenvectors(thisView,getPointOffset(sampleNo,dataPointNo),
508                                                         evView,ev->getPointOffset(sampleNo,dataPointNo),
509                                                         VView,V->getPointOffset(sampleNo,dataPointNo),
510                                                         tol);
511        }
512      }
513    }
514    
515  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.123  
changed lines
  Added in v.584

  ViewVC Help
Powered by ViewVC 1.1.26