/[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 856 by gross, Tue Sep 26 01:00:36 2006 UTC revision 964 by gross, Tue Feb 13 05:10:26 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 373  DataExpanded::extractData(ifstream& arch Line 306  DataExpanded::extractData(ifstream& arch
306    return(m_data.extractData(archiveFile, noValues));    return(m_data.extractData(archiveFile, noValues));
307  }  }
308    
309    void
310    DataExpanded::copyToDataPoint(const int sampleNo, const int dataPointNo, const double value) {
311      //
312      // Get the number of samples and data-points per sample.
313      int numSamples = getNumSamples();
314      int numDataPointsPerSample = getNumDPPSample();
315      int dataPointRank = getPointDataView().getRank();
316      ShapeType dataPointShape = getPointDataView().getShape();
317      if (numSamples*numDataPointsPerSample > 0) {
318         //TODO: global error handling
319         if ((sampleNo >= numSamples) || (sampleNo < 0 )) {
320              throw DataException("Error - DataExpanded::copyDataPoint invalid sampleNo.");
321         }
322         if ((dataPointNo >= numDataPointsPerSample) || (dataPointNo < 0)) {
323               throw DataException("Error - DataExpanded::copyDataPoint invalid dataPointNoInSample.");
324         }
325         DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);
326         if (dataPointRank==0) {
327             dataPointView()=value;
328         } else if (dataPointRank==1) {
329            for (int i=0; i<dataPointShape[0]; i++) {
330                dataPointView(i)=value;
331            }
332         } else if (dataPointRank==2) {
333            for (int i=0; i<dataPointShape[0]; i++) {
334               for (int j=0; j<dataPointShape[1]; j++) {
335                  dataPointView(i,j)=value;
336               }
337            }
338         } else if (dataPointRank==3) {
339            for (int i=0; i<dataPointShape[0]; i++) {
340               for (int j=0; j<dataPointShape[1]; j++) {
341                  for (int k=0; k<dataPointShape[2]; k++) {
342                     dataPointView(i,j,k)=value;
343                  }
344               }
345            }
346         } else if (dataPointRank==4) {
347             for (int i=0; i<dataPointShape[0]; i++) {
348               for (int j=0; j<dataPointShape[1]; j++) {
349                 for (int k=0; k<dataPointShape[2]; k++) {
350                   for (int l=0; l<dataPointShape[3]; l++) {
351                      dataPointView(i,j,k,l)=value;
352                   }
353                 }
354               }
355             }
356         }
357      }
358    }
359    void
360    DataExpanded::copyToDataPoint(const int sampleNo, const int dataPointNo, const boost::python::numeric::array& value) {
361      //
362      // Get the number of samples and data-points per sample.
363      int numSamples = getNumSamples();
364      int numDataPointsPerSample = getNumDPPSample();
365      int dataPointRank = getPointDataView().getRank();
366      ShapeType dataPointShape = getPointDataView().getShape();
367      //
368      // check rank:
369      if (value.getrank()!=dataPointRank)
370           throw DataException("Rank of numarray does not match Data object rank");
371      if (numSamples*numDataPointsPerSample > 0) {
372         //TODO: global error handling
373         if ((sampleNo >= numSamples) || (sampleNo < 0 )) {
374              throw DataException("Error - DataExpanded::copyDataPoint invalid sampleNo.");
375         }
376         if ((dataPointNo >= numDataPointsPerSample) || (dataPointNo < 0)) {
377               throw DataException("Error - DataExpanded::copyDataPoint invalid dataPointNoInSample.");
378         }
379         DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);
380         if (dataPointRank==0) {
381             dataPointView()=extract<double>(value[0]);
382         } else if (dataPointRank==1) {
383            for (int i=0; i<dataPointShape[0]; i++) {
384                dataPointView(i)=extract<double>(value[i]);
385            }
386         } else if (dataPointRank==2) {
387            for (int i=0; i<dataPointShape[0]; i++) {
388               for (int j=0; j<dataPointShape[1]; j++) {
389                  dataPointView(i,j)=extract<double>(value[i][j]);
390               }
391            }
392         } else if (dataPointRank==3) {
393            for (int i=0; i<dataPointShape[0]; i++) {
394               for (int j=0; j<dataPointShape[1]; j++) {
395                  for (int k=0; k<dataPointShape[2]; k++) {
396                     dataPointView(i,j,k)=extract<double>(value[i][j][k]);
397                  }
398               }
399            }
400         } else if (dataPointRank==4) {
401             for (int i=0; i<dataPointShape[0]; i++) {
402               for (int j=0; j<dataPointShape[1]; j++) {
403                 for (int k=0; k<dataPointShape[2]; k++) {
404                   for (int l=0; l<dataPointShape[3]; l++) {
405                      dataPointView(i,j,k,l)=extract<double>(value[i][j][k][l]);
406                   }
407                 }
408               }
409             }
410         }
411      }
412    }
413  void  void
414  DataExpanded::copyAll(const boost::python::numeric::array& value) {  DataExpanded::copyAll(const boost::python::numeric::array& value) {
415    //    //
# Line 577  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        throw DataException("Error - DataExpanded:: dump: not implemented.");
621    }
622    
623    
624  }  // end of namespace  }  // end of namespace

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

  ViewVC Help
Powered by ViewVC 1.1.26