/[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 965 by gross, Tue Feb 13 05:38:45 2007 UTC revision 1131 by gross, Tue May 8 05:52:21 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 615  DataExpanded::eigenvalues_and_eigenvecto Line 618  DataExpanded::eigenvalues_and_eigenvecto
618  }  }
619    
620  void  void
621    DataExpanded::setToZero(){
622      int numSamples = getNumSamples();
623      int numDataPointsPerSample = getNumDPPSample();
624      DataArrayView& thisView=getPointDataView();
625      DataArrayView::ValueType::size_type n = thisView.noValues();
626      double* p;
627      int  sampleNo,dataPointNo, i;
628      #pragma omp parallel for private(sampleNo,dataPointNo,p,i) schedule(static)
629      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
630        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
631            p=&(m_data[getPointOffset(sampleNo,dataPointNo)]);
632            for (int i=0; i<n ;++i) p[i]=0.;
633        }
634      }
635    }
636    
637    
638    void
639  DataExpanded::dump(const std::string fileName) const  DataExpanded::dump(const std::string fileName) const
640  {  {
641     #ifdef PASO_MPI     #ifdef PASO_MPI
642     throw DataException("Error - DataExpanded:: dump is not implemented for MPI yet.")     throw DataException("Error - DataExpanded:: dump is not implemented for MPI yet.");
643     #endif     #endif
644     const NcDim* ncdims[2+DataArrayView::maxRank];     #ifdef USE_NETCDF
645     NcVar* var;     const int ldims=2+DataArrayView::maxRank;
646       const NcDim* ncdims[ldims];
647       NcVar *var, *ids;
648     int rank = getPointDataView().getRank();     int rank = getPointDataView().getRank();
649     int type=  getFunctionSpace().getTypeCode();     int type=  getFunctionSpace().getTypeCode();
650     int ndims =0;     int ndims =0;
651     long dims[2+DataArrayView::maxRank];     long dims[ldims];
652     DataArrayView::ShapeType shape = getPointDataView().getShape();     DataArrayView::ShapeType shape = getPointDataView().getShape();
653    
654     // netCDF error handler     // netCDF error handler
# Line 635  DataExpanded::dump(const std::string fil Line 658  DataExpanded::dump(const std::string fil
658     // check if writing was successful     // check if writing was successful
659     if (!dataFile.is_valid())     if (!dataFile.is_valid())
660          throw DataException("Error - DataExpanded:: opening of netCDF file for output failed.");          throw DataException("Error - DataExpanded:: opening of netCDF file for output failed.");
661     if (!dataFile.add_att("type","constant") )     if (!dataFile.add_att("type","expanded") )
662          throw DataException("Error - DataExpanded:: appending data type to netCDF file failed.");          throw DataException("Error - DataExpanded:: appending data type to netCDF file failed.");
663     if (!dataFile.add_att("rank",rank) )     if (!dataFile.add_att("rank",rank) )
664          throw DataException("Error - DataExpanded:: appending rank attribute to netCDF file failed.");          throw DataException("Error - DataExpanded:: appending rank attribute to netCDF file failed.");
665     if (!dataFile.add_att("function_space_type",type))     if (!dataFile.add_att("function_space_type",type))
666          throw DataException("Error - DataExpanded:: appending function space attribute to netCDF file failed.");          throw DataException("Error - DataExpanded:: appending function space attribute to netCDF file failed.");
667     ndims=rank+2;     ndims=rank+2;
668     if ( rank >1 ) {     if ( rank >0 ) {
669         dims[0]=shape[0];         dims[0]=shape[0];
670         if (! (ncdims[0] = dataFile.add_dim("d0",shape[0])) )         if (! (ncdims[0] = dataFile.add_dim("d0",shape[0])) )
671              throw DataException("Error - DataExpanded:: appending ncdimsion 0 to netCDF file failed.");              throw DataException("Error - DataExpanded:: appending ncdimsion 0 to netCDF file failed.");
# Line 662  DataExpanded::dump(const std::string fil Line 685  DataExpanded::dump(const std::string fil
685         if (! (ncdims[3] = dataFile.add_dim("d3", shape[3])) )         if (! (ncdims[3] = dataFile.add_dim("d3", shape[3])) )
686              throw DataException("Error - DataExpanded:: appending ncdimsion 3 to netCDF file failed.");              throw DataException("Error - DataExpanded:: appending ncdimsion 3 to netCDF file failed.");
687     }     }
688     dims[rank]= getNumDataPointsPerSample();     dims[rank]=getFunctionSpace().getNumDataPointsPerSample();
689     if (! (ncdims[rank] = dataFile.add_dim("num_data_points_per_sample", dims[rank])) )     if (! (ncdims[rank] = dataFile.add_dim("num_data_points_per_sample", dims[rank])) )
690              throw DataException("Error - DataExpanded:: appending num_data_points_per_sample to netCDF file failed.");              throw DataException("Error - DataExpanded:: appending num_data_points_per_sample to netCDF file failed.");
691     dims[rank+1]= getNumSamples();     dims[rank+1]=getFunctionSpace().getNumSamples();
692     if (! (ncdims[rank+1] = dataFile.add_dim("num_sample", dims[rank+1])) )     if (! (ncdims[rank+1] = dataFile.add_dim("num_samples", dims[rank+1])) )
693              throw DataException("Error - DataExpanded:: appending num_sample to netCDF file failed.");              throw DataException("Error - DataExpanded:: appending num_sample to netCDF file failed.");
694    
695       if (! ( ids = dataFile.add_var("id", ncInt, ncdims[rank+1])) )
696            throw DataException("Error - DataExpanded:: appending reference id to netCDF file failed.");
697       const int* ids_p=getFunctionSpace().borrowSampleReferenceIDs();
698       if (! (ids->put(ids_p,dims[rank+1])) )
699            throw DataException("Error - DataExpanded:: copy reference id  to netCDF buffer failed.");
700    
701     if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )     if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )
702          throw DataException("Error - DataExpanded:: appending variable to netCDF file failed.");          throw DataException("Error - DataExpanded:: appending variable to netCDF file failed.");
703     if (! (var->put(&m_data[0],dims)) )     if (! (var->put(&m_data[0],dims)) )
704          throw DataException("Error - DataExpanded:: copy data to netCDF buffer failed.");          throw DataException("Error - DataExpanded:: copy data to netCDF buffer failed.");
705       #else
706       throw DataException("Error - DataExpanded:: dump is not configured with netCDF. Please contact your installation manager.");
707       #endif
708  }  }
   
   
709  }  // end of namespace  }  // end of namespace

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

  ViewVC Help
Powered by ViewVC 1.1.26