/[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 965 by gross, Tue Feb 13 05:38:45 2007 UTC
# Line 261  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 << "( id: " << i << ", ref: " << fs.getReferenceNoFromSampleNo(i) << ", pnt: " << j << ")";        suffix << "( id: " << i << ", ref: " << fs.getReferenceIDOfSample(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 292  DataExpanded::getLength() const Line 292  DataExpanded::getLength() const
292    return m_data.size();    return m_data.size();
293  }  }
294    
 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);  
 }  
   
295  int  int
296  DataExpanded::archiveData(ofstream& archiveFile,  DataExpanded::archiveData(ofstream& archiveFile,
297                            const DataArrayView::ValueType::size_type noValues) const                            const DataArrayView::ValueType::size_type noValues) const
# Line 383  DataExpanded::copyToDataPoint(const int Line 316  DataExpanded::copyToDataPoint(const int
316    ShapeType dataPointShape = getPointDataView().getShape();    ShapeType dataPointShape = getPointDataView().getShape();
317    if (numSamples*numDataPointsPerSample > 0) {    if (numSamples*numDataPointsPerSample > 0) {
318       //TODO: global error handling       //TODO: global error handling
319       if (sampleNo >= numSamples or sampleNo < 0 ) {       if ((sampleNo >= numSamples) || (sampleNo < 0 )) {
320            throw DataException("Error - DataExpanded::copyDataPoint invalid sampleNo.");            throw DataException("Error - DataExpanded::copyDataPoint invalid sampleNo.");
321       }       }
322       if (dataPointNo >= numDataPointsPerSample or dataPointNo < 0) {       if ((dataPointNo >= numDataPointsPerSample) || (dataPointNo < 0)) {
323             throw DataException("Error - DataExpanded::copyDataPoint invalid dataPointNoInSample.");             throw DataException("Error - DataExpanded::copyDataPoint invalid dataPointNoInSample.");
324       }       }
325       DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);       DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);
# Line 437  DataExpanded::copyToDataPoint(const int Line 370  DataExpanded::copyToDataPoint(const int
370         throw DataException("Rank of numarray does not match Data object rank");         throw DataException("Rank of numarray does not match Data object rank");
371    if (numSamples*numDataPointsPerSample > 0) {    if (numSamples*numDataPointsPerSample > 0) {
372       //TODO: global error handling       //TODO: global error handling
373       if (sampleNo >= numSamples or sampleNo < 0 ) {       if ((sampleNo >= numSamples) || (sampleNo < 0 )) {
374            throw DataException("Error - DataExpanded::copyDataPoint invalid sampleNo.");            throw DataException("Error - DataExpanded::copyDataPoint invalid sampleNo.");
375       }       }
376       if (dataPointNo >= numDataPointsPerSample or dataPointNo < 0) {       if ((dataPointNo >= numDataPointsPerSample) || (dataPointNo < 0)) {
377             throw DataException("Error - DataExpanded::copyDataPoint invalid dataPointNoInSample.");             throw DataException("Error - DataExpanded::copyDataPoint invalid dataPointNoInSample.");
378       }       }
379       DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);       DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);
# Line 681  DataExpanded::eigenvalues_and_eigenvecto Line 614  DataExpanded::eigenvalues_and_eigenvecto
614    }    }
615  }  }
616    
617    void
618    DataExpanded::dump(const std::string fileName) const
619    {
620       #ifdef PASO_MPI
621       throw DataException("Error - DataExpanded:: dump is not implemented for MPI yet.")
622       #endif
623       const NcDim* ncdims[2+DataArrayView::maxRank];
624       NcVar* var;
625       int rank = getPointDataView().getRank();
626       int type=  getFunctionSpace().getTypeCode();
627       int ndims =0;
628       long dims[2+DataArrayView::maxRank];
629       DataArrayView::ShapeType shape = getPointDataView().getShape();
630    
631       // netCDF error handler
632       NcError err(NcError::verbose_nonfatal);
633       // Create the file.
634       NcFile dataFile(fileName.c_str(), NcFile::Replace);
635       // check if writing was successful
636       if (!dataFile.is_valid())
637            throw DataException("Error - DataExpanded:: opening of netCDF file for output failed.");
638       if (!dataFile.add_att("type","constant") )
639            throw DataException("Error - DataExpanded:: appending data type to netCDF file failed.");
640       if (!dataFile.add_att("rank",rank) )
641            throw DataException("Error - DataExpanded:: appending rank attribute to netCDF file failed.");
642       if (!dataFile.add_att("function_space_type",type))
643            throw DataException("Error - DataExpanded:: appending function space attribute to netCDF file failed.");
644       ndims=rank+2;
645       if ( rank >1 ) {
646           dims[0]=shape[0];
647           if (! (ncdims[0] = dataFile.add_dim("d0",shape[0])) )
648                throw DataException("Error - DataExpanded:: appending ncdimsion 0 to netCDF file failed.");
649       }
650       if ( rank >1 ) {
651           dims[1]=shape[1];
652           if (! (ncdims[1] = dataFile.add_dim("d1",shape[1])) )
653                throw DataException("Error - DataExpanded:: appending ncdimsion 1 to netCDF file failed.");
654       }
655       if ( rank >2 ) {
656           dims[2]=shape[2];
657           if (! (ncdims[2] = dataFile.add_dim("d2", shape[2])) )
658                throw DataException("Error - DataExpanded:: appending ncdimsion 2 to netCDF file failed.");
659       }
660       if ( rank >3 ) {
661           dims[3]=shape[3];
662           if (! (ncdims[3] = dataFile.add_dim("d3", shape[3])) )
663                throw DataException("Error - DataExpanded:: appending ncdimsion 3 to netCDF file failed.");
664       }
665       dims[rank]= getNumDataPointsPerSample();
666       if (! (ncdims[rank] = dataFile.add_dim("num_data_points_per_sample", dims[rank])) )
667                throw DataException("Error - DataExpanded:: appending num_data_points_per_sample to netCDF file failed.");
668       dims[rank+1]= getNumSamples();
669       if (! (ncdims[rank+1] = dataFile.add_dim("num_sample", dims[rank+1])) )
670                throw DataException("Error - DataExpanded:: appending num_sample to netCDF file failed.");
671       if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )
672            throw DataException("Error - DataExpanded:: appending variable to netCDF file failed.");
673       if (! (var->put(&m_data[0],dims)) )
674            throw DataException("Error - DataExpanded:: copy data to netCDF buffer failed.");
675    }
676    
677    
678  }  // end of namespace  }  // end of namespace

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

  ViewVC Help
Powered by ViewVC 1.1.26