/[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 126 by jgs, Fri Jul 22 03:53:08 2005 UTC trunk/escript/src/DataExpanded.cpp revision 854 by gross, Thu Sep 21 05:29:42 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 468  DataExpanded::copyAll(const boost::pytho Line 426  DataExpanded::copyAll(const boost::pytho
426      }      }
427    }    }
428  }  }
429    void
430    DataExpanded::symmetric(DataAbstract* ev)
431    {
432      int sampleNo,dataPointNo;
433      int numSamples = getNumSamples();
434      int numDataPointsPerSample = getNumDPPSample();
435      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
436      if (temp_ev==0) {
437        throw DataException("Error - DataExpanded::symmetric: casting to DataExpanded failed (propably a programming error).");
438      }
439      DataArrayView& thisView=getPointDataView();
440      DataArrayView& evView=ev->getPointDataView();
441      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
442      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
443        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
444             DataArrayView::symmetric(thisView,getPointOffset(sampleNo,dataPointNo),
445                                        evView,ev->getPointOffset(sampleNo,dataPointNo));
446        }
447      }
448    }
449    void
450    DataExpanded::nonsymmetric(DataAbstract* ev)
451    {
452      int sampleNo,dataPointNo;
453      int numSamples = getNumSamples();
454      int numDataPointsPerSample = getNumDPPSample();
455      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
456      if (temp_ev==0) {
457        throw DataException("Error - DataExpanded::nonsymmetric: casting to DataExpanded failed (propably a programming error).");
458      }
459      DataArrayView& thisView=getPointDataView();
460      DataArrayView& evView=ev->getPointDataView();
461      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
462      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
463        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
464             DataArrayView::nonsymmetric(thisView,getPointOffset(sampleNo,dataPointNo),
465                                        evView,ev->getPointOffset(sampleNo,dataPointNo));
466        }
467      }
468    }
469    void
470    DataExpanded::trace(DataAbstract* ev, int axis_offset)
471    {
472      int sampleNo,dataPointNo;
473      int numSamples = getNumSamples();
474      int numDataPointsPerSample = getNumDPPSample();
475      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
476      if (temp_ev==0) {
477        throw DataException("Error - DataExpanded::trace: casting to DataExpanded failed (propably a programming error).");
478      }
479      DataArrayView& thisView=getPointDataView();
480      DataArrayView& evView=ev->getPointDataView();
481      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
482      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
483        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
484             DataArrayView::trace(thisView,getPointOffset(sampleNo,dataPointNo),
485                                        evView,ev->getPointOffset(sampleNo,dataPointNo),axis_offset);
486        }
487      }
488    }
489    
490    void
491    DataExpanded::transpose(DataAbstract* ev, int axis_offset)
492    {
493      int sampleNo,dataPointNo;
494      int numSamples = getNumSamples();
495      int numDataPointsPerSample = getNumDPPSample();
496      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
497      if (temp_ev==0) {
498        throw DataException("Error - DataExpanded::transpose: casting to DataExpanded failed (propably a programming error).");
499      }
500      DataArrayView& thisView=getPointDataView();
501      DataArrayView& evView=ev->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::transpose(thisView,getPointOffset(sampleNo,dataPointNo),
506                                        evView,ev->getPointOffset(sampleNo,dataPointNo),axis_offset);
507        }
508      }
509    }
510    
511    void
512    DataExpanded::swapaxes(DataAbstract* ev, int axis0, int axis1)
513    {
514      int sampleNo,dataPointNo;
515      int numSamples = getNumSamples();
516      int numDataPointsPerSample = getNumDPPSample();
517      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
518      if (temp_ev==0) {
519        throw DataException("Error - DataExpanded::swapaxes: casting to DataExpanded failed (propably a programming error).");
520      }
521      DataArrayView& thisView=getPointDataView();
522      DataArrayView& evView=ev->getPointDataView();
523      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
524      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
525        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
526             DataArrayView::swapaxes(thisView,getPointOffset(sampleNo,dataPointNo),
527                                        evView,ev->getPointOffset(sampleNo,dataPointNo),axis0,axis1);
528        }
529      }
530    }
531    void
532    DataExpanded::eigenvalues(DataAbstract* ev)
533    {
534      int sampleNo,dataPointNo;
535      int numSamples = getNumSamples();
536      int numDataPointsPerSample = getNumDPPSample();
537      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
538      if (temp_ev==0) {
539        throw DataException("Error - DataExpanded::eigenvalues: casting to DataExpanded failed (propably a programming error).");
540      }
541      DataArrayView& thisView=getPointDataView();
542      DataArrayView& evView=ev->getPointDataView();
543      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
544      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
545        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
546             DataArrayView::eigenvalues(thisView,getPointOffset(sampleNo,dataPointNo),
547                                        evView,ev->getPointOffset(sampleNo,dataPointNo));
548        }
549      }
550    }
551    void
552    DataExpanded::eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol)
553    {
554      int numSamples = getNumSamples();
555      int numDataPointsPerSample = getNumDPPSample();
556      int sampleNo,dataPointNo;
557      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
558      if (temp_ev==0) {
559        throw DataException("Error - DataExpanded::eigenvalues_and_eigenvectors: casting to DataExpanded failed (propably a programming error).");
560      }
561      DataExpanded* temp_V=dynamic_cast<DataExpanded*>(V);
562      if (temp_V==0) {
563        throw DataException("Error - DataExpanded::eigenvalues_and_eigenvectors: casting to DataExpanded failed (propably a programming error).");
564      }
565      DataArrayView& thisView=getPointDataView();
566      DataArrayView& evView=ev->getPointDataView();
567      DataArrayView& VView=V->getPointDataView();
568      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
569      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
570        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
571             DataArrayView::eigenvalues_and_eigenvectors(thisView,getPointOffset(sampleNo,dataPointNo),
572                                                         evView,ev->getPointOffset(sampleNo,dataPointNo),
573                                                         VView,V->getPointOffset(sampleNo,dataPointNo),
574                                                         tol);
575        }
576      }
577    }
578    
579  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.126  
changed lines
  Added in v.854

  ViewVC Help
Powered by ViewVC 1.1.26