/[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/DataExpanded.cpp revision 1141 by gross, Tue May 15 04:24:51 2007 UTC temp_trunk_copy/escript/src/DataExpanded.cpp revision 1384 by phornby, Fri Jan 11 02:29:38 2008 UTC
# Line 1  Line 1 
1  // $Id$  
2  /*  /* $Id$ */
3   ************************************************************  
4   *          Copyright 2006 by ACcESS MNRF                   *  /*******************************************************
5   *                                                          *   *
6   *              http://www.access.edu.au                    *   *           Copyright 2003-2007 by ACceSS MNRF
7   *       Primary Business: Queensland, Australia            *   *       Copyright 2007 by University of Queensland
8   *  Licensed under the Open Software License version 3.0    *   *
9   *     http://www.opensource.org/licenses/osl-3.0.php       *   *                http://esscc.uq.edu.au
10   *                                                          *   *        Primary Business: Queensland, Australia
11   ************************************************************   *  Licensed under the Open Software License version 3.0
12  */   *     http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16  #include "DataExpanded.h"  #include "DataExpanded.h"
17  #include "DataException.h"  #include "DataException.h"
18  #include "DataConstant.h"  #include "DataConstant.h"
19  #include "DataTagged.h"  #include "DataTagged.h"
20  #ifdef USE_NETCDF  #ifdef USE_NETCDF
21  #include "netcdfcpp.h"  #include <netcdfcpp.h>
22  #endif  #endif
23    
24  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
# Line 158  DataExpanded::~DataExpanded() Line 160  DataExpanded::~DataExpanded()
160  }  }
161    
162  DataAbstract*  DataAbstract*
163  DataExpanded::getSlice(const DataArrayView::RegionType& region) const  DataExpanded::getSlice(const DataArrayView::RegionType& region) const
164  {  {
165    return new DataExpanded(*this,region);    return new DataExpanded(*this,region);
166  }  }
167    
168  void  void
169  DataExpanded::setSlice(const DataAbstract* value,  DataExpanded::setSlice(const DataAbstract* value,
170                         const DataArrayView::RegionType& region)                         const DataArrayView::RegionType& region)
171  {  {
172    const DataExpanded* tempDataExp=dynamic_cast<const DataExpanded*>(value);    const DataExpanded* tempDataExp=dynamic_cast<const DataExpanded*>(value);
173    if (tempDataExp==0) {    if (tempDataExp==0) {
# Line 201  DataExpanded::setSlice(const DataAbstrac Line 203  DataExpanded::setSlice(const DataAbstrac
203  }  }
204    
205  void  void
206  DataExpanded::copy(const DataArrayView& value)  DataExpanded::copy(const DataArrayView& value)
207  {  {
208    //    //
209    // copy a single value to every data point in this object    // copy a single value to every data point in this object
# Line 211  DataExpanded::copy(const DataArrayView& Line 213  DataExpanded::copy(const DataArrayView&
213    #pragma omp parallel for private(i,j) schedule(static)    #pragma omp parallel for private(i,j) schedule(static)
214    for (i=0;i<nRows;i++) {    for (i=0;i<nRows;i++) {
215      for (j=0;j<nCols;j++) {      for (j=0;j<nCols;j++) {
216        // NOTE: An exception may be thown from this call if        // NOTE: An exception may be thown from this call if
217        // DOASSERT is on which of course will play        // DOASSERT is on which of course will play
218        // havoc with the omp threads. Run single threaded        // havoc with the omp threads. Run single threaded
219        // if using DOASSERT.        // if using DOASSERT.
220        getPointDataView().copy(m_data.index(i,j),value);        getPointDataView().copy(getPointOffset(i,j),value);
221      }      }
222    }    }
223  }  }
224    
225  void  void
226  DataExpanded::copy(const boost::python::numeric::array& value)  DataExpanded::copy(const boost::python::numeric::array& value)
227  {  {
228    //  
229    // first convert the numarray into a DataArray object    // extract the shape of the numarray
230    DataArray temp(value);    DataArrayView::ShapeType tempShape;
231      for (int i=0; i < value.getrank(); i++) {
232        tempShape.push_back(extract<int>(value.getshape()[i]));
233      }
234    
235      // get the space for the data vector
236      int len = DataArrayView::noValues(tempShape);
237      DataVector temp_data(len, 0.0, len);
238      DataArrayView temp_dataView(temp_data, tempShape);
239      temp_dataView.copy(value);
240    
241    //    //
242    // check the input shape matches this shape    // check the input shape matches this shape
243    if (!getPointDataView().checkShape(temp.getView().getShape())) {    if (!getPointDataView().checkShape(temp_dataView.getShape())) {
244      throw DataException(getPointDataView().createShapeErrorMessage(      throw DataException(getPointDataView().createShapeErrorMessage(
245                          "Error - (DataExpanded) Cannot copy due to shape mismatch.",                          "Error - (DataExpanded) Cannot copy due to shape mismatch.",
246                          temp.getView().getShape()));                          temp_dataView.getShape()));
247    }    }
248    //    //
249    // now copy over the data    // now copy over the data
250    copy(temp.getView());    copy(temp_dataView);
251  }  }
252    
253  void  void
# Line 262  DataExpanded::toString() const Line 274  DataExpanded::toString() const
274    DataArrayView tempView(getPointDataView().getData(),getPointDataView().getShape(),getPointDataView().getOffset());    DataArrayView tempView(getPointDataView().getData(),getPointDataView().getShape(),getPointDataView().getOffset());
275    for (int i=0;i<m_data.getNumRows();i++) {    for (int i=0;i<m_data.getNumRows();i++) {
276      for (int j=0;j<m_data.getNumCols();j++) {      for (int j=0;j<m_data.getNumCols();j++) {
277        tempView.setOffset(m_data.index(i,j));        tempView.setOffset(getPointOffset(i,j));
278        stringstream suffix;        stringstream suffix;
279        suffix << "( id: " << i << ", ref: " << fs.getReferenceIDOfSample(i) << ", pnt: " << j << ")";        suffix << "( id: " << i << ", ref: " << fs.getReferenceIDOfSample(i) << ", pnt: " << j << ")";
280        temp << tempView.toString(suffix.str());        temp << tempView.toString(suffix.str());
# Line 271  DataExpanded::toString() const Line 283  DataExpanded::toString() const
283        }        }
284      }      }
285    }    }
286    return string(temp.str());    return temp.str();
287  }  }
288    
289  DataArrayView::ValueType::size_type  DataArrayView::ValueType::size_type
# Line 285  DataArrayView Line 297  DataArrayView
297  DataExpanded::getDataPoint(int sampleNo,  DataExpanded::getDataPoint(int sampleNo,
298                             int dataPointNo)                             int dataPointNo)
299  {  {
300    DataArrayView temp(m_data.getData(),getPointDataView().getShape(),m_data.index(sampleNo,dataPointNo));    DataArrayView temp(m_data.getData(),getPointDataView().getShape(),getPointOffset(sampleNo,dataPointNo));
301    return temp;    return temp;
302  }  }
303    
# Line 309  DataExpanded::extractData(ifstream& arch Line 321  DataExpanded::extractData(ifstream& arch
321    return(m_data.extractData(archiveFile, noValues));    return(m_data.extractData(archiveFile, noValues));
322  }  }
323    
324  void  void
325  DataExpanded::copyToDataPoint(const int sampleNo, const int dataPointNo, const double value) {  DataExpanded::copyToDataPoint(const int sampleNo, const int dataPointNo, const double value) {
326    //    //
327    // Get the number of samples and data-points per sample.    // Get the number of samples and data-points per sample.
# Line 356  DataExpanded::copyToDataPoint(const int Line 368  DataExpanded::copyToDataPoint(const int
368               }               }
369             }             }
370           }           }
371       }       }
372    }    }
373  }  }
374  void  void
375  DataExpanded::copyToDataPoint(const int sampleNo, const int dataPointNo, const boost::python::numeric::array& value) {  DataExpanded::copyToDataPoint(const int sampleNo, const int dataPointNo, const boost::python::numeric::array& value) {
376    //    //
377    // Get the number of samples and data-points per sample.    // Get the number of samples and data-points per sample.
# Line 410  DataExpanded::copyToDataPoint(const int Line 422  DataExpanded::copyToDataPoint(const int
422               }               }
423             }             }
424           }           }
425       }       }
426    }    }
427  }  }
428  void  void
# Line 707  DataExpanded::dump(const std::string fil Line 719  DataExpanded::dump(const std::string fil
719     throw DataException("Error - DataExpanded:: dump is not configured with netCDF. Please contact your installation manager.");     throw DataException("Error - DataExpanded:: dump is not configured with netCDF. Please contact your installation manager.");
720     #endif     #endif
721  }  }
722    
723    void
724    DataExpanded::setTaggedValue(int tagKey,
725                                 const DataArrayView& value)
726    {
727      int numSamples = getNumSamples();
728      int numDataPointsPerSample = getNumDPPSample();
729      int sampleNo,dataPointNo, i;
730      DataArrayView& thisView=getPointDataView();
731      DataArrayView::ValueType::size_type n = thisView.noValues();
732      double* p,*in=&(value.getData()[0]);
733      
734      if (value.noValues() != n) {
735        throw DataException("Error - DataExpanded::setTaggedValue: number of input values does not match number of values per data points.");
736      }
737    
738      #pragma omp parallel for private(sampleNo,dataPointNo,p,i) schedule(static)
739      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
740        if (getFunctionSpace().getTagFromSampleNo(sampleNo) == tagKey ) {
741            for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
742                p=&(m_data[getPointOffset(sampleNo,dataPointNo)]);
743                for (int i=0; i<n ;++i) p[i]=in[i];
744            }
745        }
746      }
747    }
748    
749    
750  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.1141  
changed lines
  Added in v.1384

  ViewVC Help
Powered by ViewVC 1.1.26