/[escript]/trunk/escript/src/DataConstant.cpp
ViewVC logotype

Diff of /trunk/escript/src/DataConstant.cpp

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

revision 682 by robwdcock, Mon Mar 27 02:43:09 2006 UTC revision 950 by gross, Tue Feb 6 07:01:11 2007 UTC
# Line 17  Line 17 
17    
18  #include <iostream>  #include <iostream>
19  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
20    #include <netcdfcpp.h>
21    
22  using namespace std;  using namespace std;
23    
# Line 152  DataConstant::setSlice(const DataAbstrac Line 153  DataConstant::setSlice(const DataAbstrac
153    if (getPointDataView().getRank()!=region.size()) {    if (getPointDataView().getRank()!=region.size()) {
154      throw DataException("Error - Invalid slice region.");      throw DataException("Error - Invalid slice region.");
155    }    }
156    if (tempDataConst->getPointDataView().getRank()>0 and !value->getPointDataView().checkShape(shape)) {    if (tempDataConst->getPointDataView().getRank()>0 && !value->getPointDataView().checkShape(shape)) {
157      throw DataException (value->getPointDataView().createShapeErrorMessage(      throw DataException (value->getPointDataView().createShapeErrorMessage(
158                  "Error - Couldn't copy slice due to shape mismatch.",shape));                  "Error - Couldn't copy slice due to shape mismatch.",shape));
159    }    }
# Line 160  DataConstant::setSlice(const DataAbstrac Line 161  DataConstant::setSlice(const DataAbstrac
161    getPointDataView().copySliceFrom(tempDataConst->getPointDataView(),region_loop_range);    getPointDataView().copySliceFrom(tempDataConst->getPointDataView(),region_loop_range);
162  }  }
163    
 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);  
 }  
   
164  int  int
165  DataConstant::archiveData(ofstream& archiveFile,  DataConstant::archiveData(ofstream& archiveFile,
166                            const DataArrayView::ValueType::size_type noValues) const                            const DataArrayView::ValueType::size_type noValues) const
# Line 190  DataConstant::extractData(ifstream& arch Line 176  DataConstant::extractData(ifstream& arch
176  }  }
177    
178  void  void
179    DataConstant::symmetric(DataAbstract* ev)
180    {
181      DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
182      if (temp_ev==0) {
183        throw DataException("Error - DataConstant::symmetric: casting to DataConstant failed (propably a programming error).");
184      }
185      DataArrayView& thisView=getPointDataView();
186      DataArrayView& evView=ev->getPointDataView();
187      DataArrayView::symmetric(thisView,0,evView,0);
188    }
189    
190    void
191    DataConstant::nonsymmetric(DataAbstract* ev)
192    {
193      DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
194      if (temp_ev==0) {
195        throw DataException("Error - DataConstant::nonsymmetric: casting to DataConstant failed (propably a programming error).");
196      }
197      DataArrayView& thisView=getPointDataView();
198      DataArrayView& evView=ev->getPointDataView();
199      DataArrayView::nonsymmetric(thisView,0,evView,0);
200    }
201    
202    void
203    DataConstant::trace(DataAbstract* ev, int axis_offset)
204    {
205      DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
206      if (temp_ev==0) {
207        throw DataException("Error - DataConstant::trace: casting to DataConstant failed (propably a programming error).");
208      }
209      DataArrayView& thisView=getPointDataView();
210      DataArrayView& evView=ev->getPointDataView();
211      DataArrayView::trace(thisView,0,evView,0,axis_offset);
212    }
213    
214    void
215    DataConstant::swapaxes(DataAbstract* ev, int axis0, int axis1)
216    {
217      DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
218      if (temp_ev==0) {
219        throw DataException("Error - DataConstant::swapaxes: casting to DataConstant failed (propably a programming error).");
220      }
221      DataArrayView& thisView=getPointDataView();
222      DataArrayView& evView=ev->getPointDataView();
223      DataArrayView::swapaxes(thisView,0,evView,0,axis0,axis1);
224    }
225    
226    void
227    DataConstant::transpose(DataAbstract* ev, int axis_offset)
228    {
229      DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
230      if (temp_ev==0) {
231        throw DataException("Error - DataConstant::transpose: casting to DataConstant failed (propably a programming error).");
232      }
233      DataArrayView& thisView=getPointDataView();
234      DataArrayView& evView=ev->getPointDataView();
235      DataArrayView::transpose(thisView,0,evView,0,axis_offset);
236    }
237    
238    void
239  DataConstant::eigenvalues(DataAbstract* ev)  DataConstant::eigenvalues(DataAbstract* ev)
240  {  {
241    DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);    DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
# Line 218  DataConstant::eigenvalues_and_eigenvecto Line 264  DataConstant::eigenvalues_and_eigenvecto
264    DataArrayView::eigenvalues_and_eigenvectors(thisView,0,evView,0,VView,tol);    DataArrayView::eigenvalues_and_eigenvectors(thisView,0,evView,0,VView,tol);
265  }  }
266    
267    void
268    DataConstant::dump(const std::string fileName) const
269    {
270       #ifdef PASO_MPI
271       throw DataException("Error - DataConstant:: dump is not implemented for MPI yet.")
272       #endif
273       const NcDim* ncdims[DataArrayView::maxRank];
274       NcVar* var;
275       int rank = getPointDataView().getRank();
276       int type=  getFunctionSpace().getTypeCode();
277       int ndims =0;
278       long dims[DataArrayView::maxRank];
279       DataArrayView::ShapeType shape = getPointDataView().getShape();
280      
281       // netCDF error handler
282       NcError err(NcError::verbose_nonfatal);
283       // Create the file.
284       NcFile dataFile(fileName.c_str(), NcFile::Replace);
285       // check if writing was successful
286       if (!dataFile.is_valid())
287        throw DataException("Error - DataConstant:: opening of netCDF file for output failed.");
288       if (!dataFile.add_att("type","constant") )
289        throw DataException("Error - DataConstant:: appending data type to netCDF file failed.");
290       if (!dataFile.add_att("rank",rank) )
291        throw DataException("Error - DataConstant:: appending rank attribute to netCDF file failed.");
292       if (!dataFile.add_att("function_space_type",type))
293        throw DataException("Error - DataConstant:: appending function space attribute to netCDF file failed.");
294    
295       if (rank == 0) {
296          if( ! (ncdims[0] = dataFile.add_dim("l", 1)) )
297            throw DataException("Error - DataConstant:: appending ncdimsion 0 to netCDF file failed.");
298          dims[0]=1,
299          ndims=1;
300       } else {
301           ndims=rank;
302           dims[0]=shape[0];
303           if (! (ncdims[0] = dataFile.add_dim("d0",shape[0])) )
304            throw DataException("Error - DataConstant:: appending ncdimsion 0 to netCDF file failed.");
305           if ( rank >1 ) {
306               dims[1]=shape[1];
307               if (! (ncdims[1] = dataFile.add_dim("d1",shape[1])) )
308            throw DataException("Error - DataConstant:: appending ncdimsion 1 to netCDF file failed.");
309           }
310           if ( rank >2 ) {
311               dims[2]=shape[2];
312               if (! (ncdims[2] = dataFile.add_dim("d2", shape[2])) )
313            throw DataException("Error - DataConstant:: appending ncdimsion 2 to netCDF file failed.");
314           }
315           if ( rank >3 ) {
316               dims[3]=shape[3];
317               if (! (ncdims[3] = dataFile.add_dim("d3", shape[3])) )
318            throw DataException("Error - DataConstant:: appending ncdimsion 3 to netCDF file failed.");
319           }
320       }
321       if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )
322        throw DataException("Error - DataConstant:: appending variable to netCDF file failed.");
323       if (! (var->put(&m_data[0],dims)) )
324        throw DataException("Error - DataConstant:: copy data to netCDF buffer failed.");
325    }
326    
327  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.682  
changed lines
  Added in v.950

  ViewVC Help
Powered by ViewVC 1.1.26