/[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

revision 922 by gross, Fri Jan 5 04:23:05 2007 UTC revision 1023 by gross, Tue Mar 13 05:43:36 2007 UTC
# Line 15  Line 15 
15  #include "DataException.h"  #include "DataException.h"
16  #include "DataConstant.h"  #include "DataConstant.h"
17  #include "DataTagged.h"  #include "DataTagged.h"
18    #ifdef USE_NETCDF
19    #include <netcdfcpp.h>
20    #endif
21    
22  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
23    
# Line 261  DataExpanded::toString() const Line 264  DataExpanded::toString() const
264      for (int j=0;j<m_data.getNumCols();j++) {      for (int j=0;j<m_data.getNumCols();j++) {
265        tempView.setOffset(m_data.index(i,j));        tempView.setOffset(m_data.index(i,j));
266        stringstream suffix;        stringstream suffix;
267        suffix << "( id: " << i << ", ref: " << fs.getReferenceNoFromSampleNo(i) << ", pnt: " << j << ")";        suffix << "( id: " << i << ", ref: " << fs.getReferenceIDOfSample(i) << ", pnt: " << j << ")";
268        temp << tempView.toString(suffix.str());        temp << tempView.toString(suffix.str());
269        if (!(i==(m_data.getNumRows()-1) && j==(m_data.getNumCols()-1))) {        if (!(i==(m_data.getNumRows()-1) && j==(m_data.getNumCols()-1))) {
270          temp << endl;          temp << endl;
# Line 292  DataExpanded::getLength() const Line 295  DataExpanded::getLength() const
295    return m_data.size();    return m_data.size();
296  }  }
297    
 void  
 DataExpanded::setRefValue(int ref,  
                           const DataArray& value)  
 {  
   //  
   // Get the number of samples and data-points per sample.  
   int numSamples = getNumSamples();  
   int numDPPSample = getNumDPPSample();  
   
   //  
   // Determine the sample number which corresponds to this reference number.  
   int sampleNo = -1;  
   int tempRef = -1;  
   for (int n=0; n<numSamples; n++) {  
     tempRef = getFunctionSpace().getReferenceNoFromSampleNo(n);  
     if (tempRef == ref) {  
       sampleNo = n;  
       break;  
     }  
   }  
   if (sampleNo == -1) {  
     throw DataException("DataExpanded::setRefValue error: invalid ref number supplied.");  
   }  
   
   for (int n=0; n<numDPPSample; n++) {  
     //  
     // Get *each* data-point in the sample in turn.  
     DataArrayView pointView = getDataPoint(sampleNo, n);  
     //  
     // Assign the values in the DataArray to this data-point.  
     pointView.copy(value.getView());  
   }  
 }  
   
 void  
 DataExpanded::getRefValue(int ref,  
                           DataArray& value)  
 {  
   //  
   // Get the number of samples and data-points per sample.  
   int numSamples = getNumSamples();  
   int numDPPSample = getNumDPPSample();  
   
   //  
   // Determine the sample number which corresponds to this reference number  
   int sampleNo = -1;  
   int tempRef = -1;  
   for (int n=0; n<numSamples; n++) {  
     tempRef = getFunctionSpace().getReferenceNoFromSampleNo(n);  
     if (tempRef == ref) {  
       sampleNo = n;  
       break;  
     }  
   }  
   if (sampleNo == -1) {  
     throw DataException("DataExpanded::getRefValue error: invalid ref number supplied.");  
   }  
   
   //  
   // Get the *first* data-point associated with this sample number.  
   DataArrayView pointView = getDataPoint(sampleNo, 0);  
   
   //  
   // Load the values from this data-point into the DataArray  
   value.getView().copy(pointView);  
 }  
   
298  int  int
299  DataExpanded::archiveData(ofstream& archiveFile,  DataExpanded::archiveData(ofstream& archiveFile,
300                            const DataArrayView::ValueType::size_type noValues) const                            const DataArrayView::ValueType::size_type noValues) const
# Line 383  DataExpanded::copyToDataPoint(const int Line 319  DataExpanded::copyToDataPoint(const int
319    ShapeType dataPointShape = getPointDataView().getShape();    ShapeType dataPointShape = getPointDataView().getShape();
320    if (numSamples*numDataPointsPerSample > 0) {    if (numSamples*numDataPointsPerSample > 0) {
321       //TODO: global error handling       //TODO: global error handling
322       if (sampleNo >= numSamples or sampleNo < 0 ) {       if ((sampleNo >= numSamples) || (sampleNo < 0 )) {
323            throw DataException("Error - DataExpanded::copyDataPoint invalid sampleNo.");            throw DataException("Error - DataExpanded::copyDataPoint invalid sampleNo.");
324       }       }
325       if (dataPointNo >= numDataPointsPerSample or dataPointNo < 0) {       if ((dataPointNo >= numDataPointsPerSample) || (dataPointNo < 0)) {
326             throw DataException("Error - DataExpanded::copyDataPoint invalid dataPointNoInSample.");             throw DataException("Error - DataExpanded::copyDataPoint invalid dataPointNoInSample.");
327       }       }
328       DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);       DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);
# Line 437  DataExpanded::copyToDataPoint(const int Line 373  DataExpanded::copyToDataPoint(const int
373         throw DataException("Rank of numarray does not match Data object rank");         throw DataException("Rank of numarray does not match Data object rank");
374    if (numSamples*numDataPointsPerSample > 0) {    if (numSamples*numDataPointsPerSample > 0) {
375       //TODO: global error handling       //TODO: global error handling
376       if (sampleNo >= numSamples or sampleNo < 0 ) {       if ((sampleNo >= numSamples) || (sampleNo < 0 )) {
377            throw DataException("Error - DataExpanded::copyDataPoint invalid sampleNo.");            throw DataException("Error - DataExpanded::copyDataPoint invalid sampleNo.");
378       }       }
379       if (dataPointNo >= numDataPointsPerSample or dataPointNo < 0) {       if ((dataPointNo >= numDataPointsPerSample) || (dataPointNo < 0)) {
380             throw DataException("Error - DataExpanded::copyDataPoint invalid dataPointNoInSample.");             throw DataException("Error - DataExpanded::copyDataPoint invalid dataPointNoInSample.");
381       }       }
382       DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);       DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);
# Line 681  DataExpanded::eigenvalues_and_eigenvecto Line 617  DataExpanded::eigenvalues_and_eigenvecto
617    }    }
618  }  }
619    
620    void
621    DataExpanded::dump(const std::string fileName) const
622    {
623       #ifdef PASO_MPI
624       throw DataException("Error - DataExpanded:: dump is not implemented for MPI yet.");
625       #endif
626       #ifdef USE_NETCDF
627       const int ldims=2+DataArrayView::maxRank;
628       const NcDim* ncdims[ldims];
629       NcVar *var, *ids;
630       int rank = getPointDataView().getRank();
631       int type=  getFunctionSpace().getTypeCode();
632       int ndims =0;
633       long dims[ldims];
634       DataArrayView::ShapeType shape = getPointDataView().getShape();
635    
636       // netCDF error handler
637       NcError err(NcError::verbose_nonfatal);
638       // Create the file.
639       NcFile dataFile(fileName.c_str(), NcFile::Replace);
640       // check if writing was successful
641       if (!dataFile.is_valid())
642            throw DataException("Error - DataExpanded:: opening of netCDF file for output failed.");
643       if (!dataFile.add_att("type","expanded") )
644            throw DataException("Error - DataExpanded:: appending data type to netCDF file failed.");
645       if (!dataFile.add_att("rank",rank) )
646            throw DataException("Error - DataExpanded:: appending rank attribute to netCDF file failed.");
647       if (!dataFile.add_att("function_space_type",type))
648            throw DataException("Error - DataExpanded:: appending function space attribute to netCDF file failed.");
649       ndims=rank+2;
650       if ( rank >0 ) {
651           dims[0]=shape[0];
652           if (! (ncdims[0] = dataFile.add_dim("d0",shape[0])) )
653                throw DataException("Error - DataExpanded:: appending ncdimsion 0 to netCDF file failed.");
654       }
655       if ( rank >1 ) {
656           dims[1]=shape[1];
657           if (! (ncdims[1] = dataFile.add_dim("d1",shape[1])) )
658                throw DataException("Error - DataExpanded:: appending ncdimsion 1 to netCDF file failed.");
659       }
660       if ( rank >2 ) {
661           dims[2]=shape[2];
662           if (! (ncdims[2] = dataFile.add_dim("d2", shape[2])) )
663                throw DataException("Error - DataExpanded:: appending ncdimsion 2 to netCDF file failed.");
664       }
665       if ( rank >3 ) {
666           dims[3]=shape[3];
667           if (! (ncdims[3] = dataFile.add_dim("d3", shape[3])) )
668                throw DataException("Error - DataExpanded:: appending ncdimsion 3 to netCDF file failed.");
669       }
670       dims[rank]=getFunctionSpace().getNumDataPointsPerSample();
671       if (! (ncdims[rank] = dataFile.add_dim("num_data_points_per_sample", dims[rank])) )
672                throw DataException("Error - DataExpanded:: appending num_data_points_per_sample to netCDF file failed.");
673       dims[rank+1]=getFunctionSpace().getNumSamples();
674       if (! (ncdims[rank+1] = dataFile.add_dim("num_samples", dims[rank+1])) )
675                throw DataException("Error - DataExpanded:: appending num_sample to netCDF file failed.");
676    
677       if (! ( ids = dataFile.add_var("id", ncInt, ncdims[rank+1])) )
678            throw DataException("Error - DataExpanded:: appending reference id to netCDF file failed.");
679       const int* ids_p=getFunctionSpace().borrowSampleReferenceIDs();
680       if (! (ids->put(ids_p,dims[rank+1])) )
681            throw DataException("Error - DataExpanded:: copy reference id  to netCDF buffer failed.");
682    
683       if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )
684            throw DataException("Error - DataExpanded:: appending variable to netCDF file failed.");
685       if (! (var->put(&m_data[0],dims)) )
686            throw DataException("Error - DataExpanded:: copy data to netCDF buffer failed.");
687       #else
688       throw DataException("Error - DataExpanded:: dump is not configured with netCDF. Please contact your installation manager.");
689       #endif
690    }
691  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.922  
changed lines
  Added in v.1023

  ViewVC Help
Powered by ViewVC 1.1.26