/[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 615 by elspeth, Wed Mar 22 02:12:00 2006 UTC
# Line 1  Line 1 
1  // $Id$  // $Id$
2  /*  /*
3   ******************************************************************************   ************************************************************
4   *                                                                            *   *          Copyright 2006 by ACcESS MNRF                   *
5   *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *   *                                                          *
6   *                                                                            *   *              http://www.access.edu.au                    *
7   * This software is the property of ACcESS. No part of this code              *   *       Primary Business: Queensland, Australia            *
8   * may be copied in any form or by any means without the expressed written    *   *  Licensed under the Open Software License version 3.0    *
9   * consent of ACcESS.  Copying, use or modification of this software          *   *     http://www.opensource.org/licenses/osl-3.0.php       *
10   * by any unauthorised person is illegal unless that person has a software    *   *                                                          *
11   * license agreement with ACcESS.                                             *   ************************************************************
  *                                                                            *  
  ******************************************************************************  
12  */  */
13    
14  #include "escript/Data/DataException.h"  #include "DataExpanded.h"
15  #include "escript/Data/DataExpanded.h"  #include "DataException.h"
16  #include "escript/Data/DataConstant.h"  #include "DataConstant.h"
17  #include "escript/Data/DataTagged.h"  #include "DataTagged.h"
 #include "escript/Data/DataArrayView.h"  
18    
19  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
20    
 #include <iostream>  
   
21  using namespace std;  using namespace std;
22  using namespace boost::python;  using namespace boost::python;
23  using namespace boost;  using namespace boost;
# Line 148  DataExpanded::DataExpanded(const Functio Line 143  DataExpanded::DataExpanded(const Functio
143    : DataAbstract(what)    : DataAbstract(what)
144  {  {
145    //    //
146      // create the view of the data
147      initialise(shape,what.getNumSamples(),what.getNumDPPSample());
148      //
149    // copy the data in the correct format    // copy the data in the correct format
150    m_data.getData()=data;    m_data.getData()=data;
   //  
   // create the view of the data  
   DataArrayView tempView(m_data.getData(),shape);  
   setPointDataView(tempView);  
151  }  }
152    
153  DataExpanded::~DataExpanded()  DataExpanded::~DataExpanded()
# Line 359  DataExpanded::setRefValue(int ref, Line 353  DataExpanded::setRefValue(int ref,
353    
354    for (int n=0; n<numDPPSample; n++) {    for (int n=0; n<numDPPSample; n++) {
355      //      //
356      // Get each data-point in the sample in turn.      // Get *each* data-point in the sample in turn.
357      DataArrayView pointView = getDataPoint(sampleNo, n);      DataArrayView pointView = getDataPoint(sampleNo, n);
358      //      //
359      // 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 386  DataExpanded::getRefValue(int ref,
386    }    }
387    
388    //    //
389    // Get the first data-point associated with this sample number.    // Get the *first* data-point associated with this sample number.
390    DataArrayView pointView = getDataPoint(sampleNo, 0);    DataArrayView pointView = getDataPoint(sampleNo, 0);
391    
392    //    //
# Line 414  DataExpanded::extractData(ifstream& arch Line 408  DataExpanded::extractData(ifstream& arch
408    return(m_data.extractData(archiveFile, noValues));    return(m_data.extractData(archiveFile, noValues));
409  }  }
410    
411    void
412    DataExpanded::copyAll(const boost::python::numeric::array& value) {
413      //
414      // Get the number of samples and data-points per sample.
415      int numSamples = getNumSamples();
416      int numDataPointsPerSample = getNumDPPSample();
417      int dataPointRank = getPointDataView().getRank();
418      ShapeType dataPointShape = getPointDataView().getShape();
419      //
420      // check rank:
421      if (value.getrank()!=dataPointRank+1)
422           throw DataException("Rank of numarray does not match Data object rank");
423      if (value.getshape()[0]!=numSamples*numDataPointsPerSample)
424           throw DataException("leading dimension of numarray is too small");
425      //
426      int dataPoint = 0;
427      for (int sampleNo = 0; sampleNo < numSamples; sampleNo++) {
428        for (int dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
429          DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);
430          if (dataPointRank==0) {
431             dataPointView()=extract<double>(value[dataPoint]);
432          } else if (dataPointRank==1) {
433             for (int i=0; i<dataPointShape[0]; i++) {
434                dataPointView(i)=extract<double>(value[dataPoint][i]);
435             }
436          } else if (dataPointRank==2) {
437             for (int i=0; i<dataPointShape[0]; i++) {
438               for (int j=0; j<dataPointShape[1]; j++) {
439                 dataPointView(i,j)=extract<double>(value[dataPoint][i][j]);
440               }
441             }
442           } else if (dataPointRank==3) {
443             for (int i=0; i<dataPointShape[0]; i++) {
444               for (int j=0; j<dataPointShape[1]; j++) {
445                 for (int k=0; k<dataPointShape[2]; k++) {
446                     dataPointView(i,j,k)=extract<double>(value[dataPoint][i][j][k]);
447                 }
448               }
449             }
450           } else if (dataPointRank==4) {
451             for (int i=0; i<dataPointShape[0]; i++) {
452               for (int j=0; j<dataPointShape[1]; j++) {
453                 for (int k=0; k<dataPointShape[2]; k++) {
454                   for (int l=0; l<dataPointShape[3]; l++) {
455                     dataPointView(i,j,k,l)=extract<double>(value[dataPoint][i][j][k][l]);
456                   }
457                 }
458               }
459             }
460          }
461          dataPoint++;
462        }
463      }
464    }
465    void
466    DataExpanded::eigenvalues(DataAbstract* ev)
467    {
468      int sampleNo,dataPointNo;
469      int numSamples = getNumSamples();
470      int numDataPointsPerSample = getNumDPPSample();
471      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
472      if (temp_ev==0) {
473        throw DataException("Error - DataExpanded::eigenvalues: casting to DataExpanded failed (propably a programming error).");
474      }
475      DataArrayView& thisView=getPointDataView();
476      DataArrayView& evView=ev->getPointDataView();
477      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
478      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
479        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
480             DataArrayView::eigenvalues(thisView,getPointOffset(sampleNo,dataPointNo),
481                                        evView,ev->getPointOffset(sampleNo,dataPointNo));
482        }
483      }
484    }
485    void
486    DataExpanded::eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol)
487    {
488      int numSamples = getNumSamples();
489      int numDataPointsPerSample = getNumDPPSample();
490      int sampleNo,dataPointNo;
491      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
492      if (temp_ev==0) {
493        throw DataException("Error - DataExpanded::eigenvalues_and_eigenvectors: casting to DataExpanded failed (propably a programming error).");
494      }
495      DataExpanded* temp_V=dynamic_cast<DataExpanded*>(V);
496      if (temp_V==0) {
497        throw DataException("Error - DataExpanded::eigenvalues_and_eigenvectors: casting to DataExpanded failed (propably a programming error).");
498      }
499      DataArrayView& thisView=getPointDataView();
500      DataArrayView& evView=ev->getPointDataView();
501      DataArrayView& VView=V->getPointDataView();
502      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
503      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
504        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
505             DataArrayView::eigenvalues_and_eigenvectors(thisView,getPointOffset(sampleNo,dataPointNo),
506                                                         evView,ev->getPointOffset(sampleNo,dataPointNo),
507                                                         VView,V->getPointOffset(sampleNo,dataPointNo),
508                                                         tol);
509        }
510      }
511    }
512    
513  }  // end of namespace  }  // end of namespace

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

  ViewVC Help
Powered by ViewVC 1.1.26