/[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/escript/src/Data/DataExpanded.cpp revision 155 by jgs, Wed Nov 9 02:02:19 2005 UTC trunk/escript/src/DataExpanded.cpp revision 856 by gross, Tue Sep 26 01:00:36 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()
154  {  {
155  }  }
156    
 void  
 DataExpanded::reshapeDataPoint(const DataArrayView::ShapeType& shape)  
 {  
   if (getPointDataView().getRank()!=0) {  
     stringstream temp;  
     temp << "Error - Can only reshape Data with data points of rank 0. "  
          << "This Data has data points with rank: "  
          << getPointDataView().getRank();  
     throw DataException(temp.str());  
   }  
   //  
   // create the new DataBlocks2D data array, and a corresponding DataArrayView  
   DataBlocks2D newData(getNumSamples(),getNumDPPSample(),DataArrayView::noValues(shape));  
   DataArrayView newView(newData.getData(),shape);  
   //  
   // Copy the original data to every value for the new shape  
   int i,j;  
   int nRows=m_data.getNumRows();  
   int nCols=m_data.getNumCols();  
   #pragma omp parallel for private(i,j) schedule(static)  
   for (i=0;i<nRows;i++) {  
     for (j=0;j<nCols;j++) {  
       // NOTE: An exception may be thown from this call if  
       // DOASSERT is on which of course will play  
       // havoc with the omp threads. Run single threaded  
       // if using DOASSERT.  
       newView.copy(newData.index(i,j),m_data(i,j));  
     }  
   }  
   // swap the new data array for the original  
   m_data.Swap(newData);  
   // set the corresponding DataArrayView  
   DataArrayView temp(m_data.getData(),shape);  
   setPointDataView(temp);  
 }  
   
157  DataAbstract*  DataAbstract*
158  DataExpanded::getSlice(const DataArrayView::RegionType& region) const  DataExpanded::getSlice(const DataArrayView::RegionType& region) const
159  {  {
# Line 219  DataExpanded::setSlice(const DataAbstrac Line 177  DataExpanded::setSlice(const DataAbstrac
177    if (getPointDataView().getRank()!=region.size()) {    if (getPointDataView().getRank()!=region.size()) {
178      throw DataException("Error - Invalid slice region.");      throw DataException("Error - Invalid slice region.");
179    }    }
180    if (tempDataExp->getPointDataView().getRank()>0 and !value->getPointDataView().checkShape(shape)) {    if (tempDataExp->getPointDataView().getRank()>0 && !value->getPointDataView().checkShape(shape)) {
181      throw DataException (value->getPointDataView().createShapeErrorMessage(      throw DataException (value->getPointDataView().createShapeErrorMessage(
182          "Error - Couldn't copy slice due to shape mismatch.",shape));          "Error - Couldn't copy slice due to shape mismatch.",shape));
183    }    }
# Line 295  string Line 253  string
253  DataExpanded::toString() const  DataExpanded::toString() const
254  {  {
255    stringstream temp;    stringstream temp;
256      FunctionSpace fs=getFunctionSpace();
257    //    //
258    // create a temporary view as the offset will be changed    // create a temporary view as the offset will be changed
259    DataArrayView tempView(getPointDataView().getData(),getPointDataView().getShape(),getPointDataView().getOffset());    DataArrayView tempView(getPointDataView().getData(),getPointDataView().getShape(),getPointDataView().getOffset());
# Line 302  DataExpanded::toString() const Line 261  DataExpanded::toString() const
261      for (int j=0;j<m_data.getNumCols();j++) {      for (int j=0;j<m_data.getNumCols();j++) {
262        tempView.setOffset(m_data.index(i,j));        tempView.setOffset(m_data.index(i,j));
263        stringstream suffix;        stringstream suffix;
264        suffix << "(" << i << "," << j << ")";        suffix << "( id: " << i << ", ref: " << fs.getReferenceNoFromSampleNo(i) << ", pnt: " << j << ")";
265        temp << tempView.toString(suffix.str());        temp << tempView.toString(suffix.str());
266        if (!(i==(m_data.getNumRows()-1) && j==(m_data.getNumCols()-1))) {        if (!(i==(m_data.getNumRows()-1) && j==(m_data.getNumCols()-1))) {
267          temp << endl;          temp << endl;
# Line 468  DataExpanded::copyAll(const boost::pytho Line 427  DataExpanded::copyAll(const boost::pytho
427      }      }
428    }    }
429  }  }
430    void
431    DataExpanded::symmetric(DataAbstract* ev)
432    {
433      int sampleNo,dataPointNo;
434      int numSamples = getNumSamples();
435      int numDataPointsPerSample = getNumDPPSample();
436      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
437      if (temp_ev==0) {
438        throw DataException("Error - DataExpanded::symmetric: casting to DataExpanded failed (propably a programming error).");
439      }
440      DataArrayView& thisView=getPointDataView();
441      DataArrayView& evView=ev->getPointDataView();
442      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
443      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
444        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
445             DataArrayView::symmetric(thisView,getPointOffset(sampleNo,dataPointNo),
446                                        evView,ev->getPointOffset(sampleNo,dataPointNo));
447        }
448      }
449    }
450    void
451    DataExpanded::nonsymmetric(DataAbstract* ev)
452    {
453      int sampleNo,dataPointNo;
454      int numSamples = getNumSamples();
455      int numDataPointsPerSample = getNumDPPSample();
456      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
457      if (temp_ev==0) {
458        throw DataException("Error - DataExpanded::nonsymmetric: casting to DataExpanded failed (propably a programming error).");
459      }
460      DataArrayView& thisView=getPointDataView();
461      DataArrayView& evView=ev->getPointDataView();
462      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
463      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
464        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
465             DataArrayView::nonsymmetric(thisView,getPointOffset(sampleNo,dataPointNo),
466                                        evView,ev->getPointOffset(sampleNo,dataPointNo));
467        }
468      }
469    }
470    void
471    DataExpanded::trace(DataAbstract* ev, int axis_offset)
472    {
473      int sampleNo,dataPointNo;
474      int numSamples = getNumSamples();
475      int numDataPointsPerSample = getNumDPPSample();
476      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
477      if (temp_ev==0) {
478        throw DataException("Error - DataExpanded::trace: casting to DataExpanded failed (propably a programming error).");
479      }
480      DataArrayView& thisView=getPointDataView();
481      DataArrayView& evView=ev->getPointDataView();
482      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
483      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
484        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
485             DataArrayView::trace(thisView,getPointOffset(sampleNo,dataPointNo),
486                                        evView,ev->getPointOffset(sampleNo,dataPointNo),axis_offset);
487        }
488      }
489    }
490    
491    void
492    DataExpanded::transpose(DataAbstract* ev, int axis_offset)
493    {
494      int sampleNo,dataPointNo;
495      int numSamples = getNumSamples();
496      int numDataPointsPerSample = getNumDPPSample();
497      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
498      if (temp_ev==0) {
499        throw DataException("Error - DataExpanded::transpose: casting to DataExpanded failed (propably a programming error).");
500      }
501      DataArrayView& thisView=getPointDataView();
502      DataArrayView& evView=ev->getPointDataView();
503      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
504      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
505        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
506             DataArrayView::transpose(thisView,getPointOffset(sampleNo,dataPointNo),
507                                        evView,ev->getPointOffset(sampleNo,dataPointNo),axis_offset);
508        }
509      }
510    }
511    
512    void
513    DataExpanded::swapaxes(DataAbstract* ev, int axis0, int axis1)
514    {
515      int sampleNo,dataPointNo;
516      int numSamples = getNumSamples();
517      int numDataPointsPerSample = getNumDPPSample();
518      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
519      if (temp_ev==0) {
520        throw DataException("Error - DataExpanded::swapaxes: casting to DataExpanded failed (propably a programming error).");
521      }
522      DataArrayView& thisView=getPointDataView();
523      DataArrayView& evView=ev->getPointDataView();
524      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
525      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
526        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
527             DataArrayView::swapaxes(thisView,getPointOffset(sampleNo,dataPointNo),
528                                        evView,ev->getPointOffset(sampleNo,dataPointNo),axis0,axis1);
529        }
530      }
531    }
532    void
533    DataExpanded::eigenvalues(DataAbstract* ev)
534    {
535      int sampleNo,dataPointNo;
536      int numSamples = getNumSamples();
537      int numDataPointsPerSample = getNumDPPSample();
538      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
539      if (temp_ev==0) {
540        throw DataException("Error - DataExpanded::eigenvalues: casting to DataExpanded failed (propably a programming error).");
541      }
542      DataArrayView& thisView=getPointDataView();
543      DataArrayView& evView=ev->getPointDataView();
544      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
545      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
546        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
547             DataArrayView::eigenvalues(thisView,getPointOffset(sampleNo,dataPointNo),
548                                        evView,ev->getPointOffset(sampleNo,dataPointNo));
549        }
550      }
551    }
552    void
553    DataExpanded::eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol)
554    {
555      int numSamples = getNumSamples();
556      int numDataPointsPerSample = getNumDPPSample();
557      int sampleNo,dataPointNo;
558      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
559      if (temp_ev==0) {
560        throw DataException("Error - DataExpanded::eigenvalues_and_eigenvectors: casting to DataExpanded failed (propably a programming error).");
561      }
562      DataExpanded* temp_V=dynamic_cast<DataExpanded*>(V);
563      if (temp_V==0) {
564        throw DataException("Error - DataExpanded::eigenvalues_and_eigenvectors: casting to DataExpanded failed (propably a programming error).");
565      }
566      DataArrayView& thisView=getPointDataView();
567      DataArrayView& evView=ev->getPointDataView();
568      DataArrayView& VView=V->getPointDataView();
569      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
570      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
571        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
572             DataArrayView::eigenvalues_and_eigenvectors(thisView,getPointOffset(sampleNo,dataPointNo),
573                                                         evView,ev->getPointOffset(sampleNo,dataPointNo),
574                                                         VView,V->getPointOffset(sampleNo,dataPointNo),
575                                                         tol);
576        }
577      }
578    }
579    
580  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.155  
changed lines
  Added in v.856

  ViewVC Help
Powered by ViewVC 1.1.26