/[escript]/branches/lapack2681/escript/src/DataConstant.cpp
ViewVC logotype

Diff of /branches/lapack2681/escript/src/DataConstant.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 800 by gross, Tue Aug 8 11:23:18 2006 UTC revision 1118 by gross, Tue Apr 24 08:55:04 2007 UTC
# Line 17  Line 17 
17    
18  #include <iostream>  #include <iostream>
19  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
20    #ifdef USE_NETCDF
21    #include <netcdfcpp.h>
22    #endif
23    
24  using namespace std;  using namespace std;
25    
# Line 160  DataConstant::setSlice(const DataAbstrac Line 163  DataConstant::setSlice(const DataAbstrac
163    getPointDataView().copySliceFrom(tempDataConst->getPointDataView(),region_loop_range);    getPointDataView().copySliceFrom(tempDataConst->getPointDataView(),region_loop_range);
164  }  }
165    
 void  
 DataConstant::reshapeDataPoint(const DataArrayView::ShapeType& shape)  
 {  
   if (getPointDataView().getRank()!=0) {  
     stringstream temp;  
     temp << "Error - Can only reshape Data with data points of rank 0. "  
          << "This Data has data points with rank: " << getPointDataView().getRank();  
     throw DataException(temp.str());  
   }  
   int len = DataArrayView::noValues(shape);  
   m_data.resize(len,getPointDataView()(),len);  
   DataArrayView newView(m_data,shape);  
   setPointDataView(newView);  
 }  
   
166  int  int
167  DataConstant::archiveData(ofstream& archiveFile,  DataConstant::archiveData(ofstream& archiveFile,
168                            const DataArrayView::ValueType::size_type noValues) const                            const DataArrayView::ValueType::size_type noValues) const
# Line 226  DataConstant::trace(DataAbstract* ev, in Line 214  DataConstant::trace(DataAbstract* ev, in
214  }  }
215    
216  void  void
217  DataConstant::swap(DataAbstract* ev, int axis_offset)  DataConstant::swapaxes(DataAbstract* ev, int axis0, int axis1)
218  {  {
219    DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);    DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
220    if (temp_ev==0) {    if (temp_ev==0) {
221      throw DataException("Error - DataConstant::swap: casting to DataConstant failed (propably a programming error).");      throw DataException("Error - DataConstant::swapaxes: casting to DataConstant failed (propably a programming error).");
222    }    }
223    DataArrayView& thisView=getPointDataView();    DataArrayView& thisView=getPointDataView();
224    DataArrayView& evView=ev->getPointDataView();    DataArrayView& evView=ev->getPointDataView();
225    DataArrayView::swap(thisView,0,evView,0,axis_offset);    DataArrayView::swapaxes(thisView,0,evView,0,axis0,axis1);
226  }  }
227    
228  void  void
# Line 278  DataConstant::eigenvalues_and_eigenvecto Line 266  DataConstant::eigenvalues_and_eigenvecto
266    DataArrayView::eigenvalues_and_eigenvectors(thisView,0,evView,0,VView,tol);    DataArrayView::eigenvalues_and_eigenvectors(thisView,0,evView,0,VView,tol);
267  }  }
268    
269    void
270    DataConstant::setToZero()
271    {
272        DataArrayView::ValueType::size_type n=m_data.size();
273        for (int i=0; i<n ;++i) m_data[i]=0.;
274    }
275    
276    void
277    DataConstant::dump(const std::string fileName) const
278    {
279       #ifdef PASO_MPI
280       throw DataException("Error - DataConstant:: dump is not implemented for MPI yet.")
281       #endif
282       #ifdef USE_NETCDF
283       const NcDim* ncdims[DataArrayView::maxRank];
284       NcVar* var;
285       int rank = getPointDataView().getRank();
286       int type=  getFunctionSpace().getTypeCode();
287       int ndims =0;
288       long dims[DataArrayView::maxRank];
289       DataArrayView::ShapeType shape = getPointDataView().getShape();
290      
291       // netCDF error handler
292       NcError err(NcError::verbose_nonfatal);
293       // Create the file.
294       NcFile dataFile(fileName.c_str(), NcFile::Replace);
295       // check if writing was successful
296       if (!dataFile.is_valid())
297        throw DataException("Error - DataConstant:: opening of netCDF file for output failed.");
298       if (!dataFile.add_att("type","constant") )
299        throw DataException("Error - DataConstant:: appending data type to netCDF file failed.");
300       if (!dataFile.add_att("rank",rank) )
301        throw DataException("Error - DataConstant:: appending rank attribute to netCDF file failed.");
302       if (!dataFile.add_att("function_space_type",type))
303        throw DataException("Error - DataConstant:: appending function space attribute to netCDF file failed.");
304    
305       if (rank == 0) {
306          if( ! (ncdims[0] = dataFile.add_dim("l", 1)) )
307            throw DataException("Error - DataConstant:: appending ncdimsion 0 to netCDF file failed.");
308          dims[0]=1,
309          ndims=1;
310       } else {
311           ndims=rank;
312           dims[0]=shape[0];
313           if (! (ncdims[0] = dataFile.add_dim("d0",shape[0])) )
314            throw DataException("Error - DataConstant:: appending ncdimsion 0 to netCDF file failed.");
315           if ( rank >1 ) {
316               dims[1]=shape[1];
317               if (! (ncdims[1] = dataFile.add_dim("d1",shape[1])) )
318            throw DataException("Error - DataConstant:: appending ncdimsion 1 to netCDF file failed.");
319           }
320           if ( rank >2 ) {
321               dims[2]=shape[2];
322               if (! (ncdims[2] = dataFile.add_dim("d2", shape[2])) )
323            throw DataException("Error - DataConstant:: appending ncdimsion 2 to netCDF file failed.");
324           }
325           if ( rank >3 ) {
326               dims[3]=shape[3];
327               if (! (ncdims[3] = dataFile.add_dim("d3", shape[3])) )
328            throw DataException("Error - DataConstant:: appending ncdimsion 3 to netCDF file failed.");
329           }
330       }
331       if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )
332        throw DataException("Error - DataConstant:: appending variable to netCDF file failed.");
333       if (! (var->put(&m_data[0],dims)) )
334        throw DataException("Error - DataConstant:: copy data to netCDF buffer failed.");
335       #else
336       throw DataException("Error - DataConstant:: dump is not configured with netCDF. Please contact your installation manager.");
337       #endif
338    }
339    
340  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.800  
changed lines
  Added in v.1118

  ViewVC Help
Powered by ViewVC 1.1.26