/[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

trunk/escript/src/Data/DataConstant.cpp revision 468 by jgs, Wed Jan 25 06:50:39 2006 UTC trunk/escript/src/DataConstant.cpp revision 1023 by gross, Tue Mar 13 05:43:36 2007 UTC
# Line 1  Line 1 
1  //$Id$  //$Id$
2  /*  /*
3   ******************************************************************************   ************************************************************
4   *                                                                            *   *          Copyright 2006 by ACcESS MNRF                   *
5   *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *   *                                                          *
6   *                                                                            *   *              http://www.access.edu.au                    *
7   * This software is the property of ACcESS. No part of this code              *   *       Primary Business: Queensland, Australia            *
8   * may be copied in any form or by any means without the expressed written    *   *  Licensed under the Open Software License version 3.0    *
9   * consent of ACcESS.  Copying, use or modification of this software          *   *     http://www.opensource.org/licenses/osl-3.0.php       *
10   * by any unauthorised person is illegal unless that person has a software    *   *                                                          *
11   * license agreement with ACcESS.                                             *   ************************************************************
  *                                                                            *  
  ******************************************************************************  
12  */  */
13    
14  #include "escript/Data/DataConstant.h"  #include "DataConstant.h"
15  #include "escript/Data/DataException.h"  #include "DataException.h"
16  #include "EsysAssert.h"  #include "esysUtils/EsysAssert.h"
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 154  DataConstant::setSlice(const DataAbstrac Line 155  DataConstant::setSlice(const DataAbstrac
155    if (getPointDataView().getRank()!=region.size()) {    if (getPointDataView().getRank()!=region.size()) {
156      throw DataException("Error - Invalid slice region.");      throw DataException("Error - Invalid slice region.");
157    }    }
158    if (tempDataConst->getPointDataView().getRank()>0 and !value->getPointDataView().checkShape(shape)) {    if (tempDataConst->getPointDataView().getRank()>0 && !value->getPointDataView().checkShape(shape)) {
159      throw DataException (value->getPointDataView().createShapeErrorMessage(      throw DataException (value->getPointDataView().createShapeErrorMessage(
160                  "Error - Couldn't copy slice due to shape mismatch.",shape));                  "Error - Couldn't copy slice due to shape mismatch.",shape));
161    }    }
# Line 162  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 191  DataConstant::extractData(ifstream& arch Line 177  DataConstant::extractData(ifstream& arch
177    return(m_data.extractData(archiveFile, noValues));    return(m_data.extractData(archiveFile, noValues));
178  }  }
179    
180    void
181    DataConstant::symmetric(DataAbstract* ev)
182    {
183      DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
184      if (temp_ev==0) {
185        throw DataException("Error - DataConstant::symmetric: casting to DataConstant failed (propably a programming error).");
186      }
187      DataArrayView& thisView=getPointDataView();
188      DataArrayView& evView=ev->getPointDataView();
189      DataArrayView::symmetric(thisView,0,evView,0);
190    }
191    
192    void
193    DataConstant::nonsymmetric(DataAbstract* ev)
194    {
195      DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
196      if (temp_ev==0) {
197        throw DataException("Error - DataConstant::nonsymmetric: casting to DataConstant failed (propably a programming error).");
198      }
199      DataArrayView& thisView=getPointDataView();
200      DataArrayView& evView=ev->getPointDataView();
201      DataArrayView::nonsymmetric(thisView,0,evView,0);
202    }
203    
204    void
205    DataConstant::trace(DataAbstract* ev, int axis_offset)
206    {
207      DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
208      if (temp_ev==0) {
209        throw DataException("Error - DataConstant::trace: casting to DataConstant failed (propably a programming error).");
210      }
211      DataArrayView& thisView=getPointDataView();
212      DataArrayView& evView=ev->getPointDataView();
213      DataArrayView::trace(thisView,0,evView,0,axis_offset);
214    }
215    
216    void
217    DataConstant::swapaxes(DataAbstract* ev, int axis0, int axis1)
218    {
219      DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
220      if (temp_ev==0) {
221        throw DataException("Error - DataConstant::swapaxes: casting to DataConstant failed (propably a programming error).");
222      }
223      DataArrayView& thisView=getPointDataView();
224      DataArrayView& evView=ev->getPointDataView();
225      DataArrayView::swapaxes(thisView,0,evView,0,axis0,axis1);
226    }
227    
228    void
229    DataConstant::transpose(DataAbstract* ev, int axis_offset)
230    {
231      DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
232      if (temp_ev==0) {
233        throw DataException("Error - DataConstant::transpose: casting to DataConstant failed (propably a programming error).");
234      }
235      DataArrayView& thisView=getPointDataView();
236      DataArrayView& evView=ev->getPointDataView();
237      DataArrayView::transpose(thisView,0,evView,0,axis_offset);
238    }
239    
240    void
241    DataConstant::eigenvalues(DataAbstract* ev)
242    {
243      DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
244      if (temp_ev==0) {
245        throw DataException("Error - DataConstant::eigenvalues: casting to DataConstant failed (propably a programming error).");
246      }
247      DataArrayView& thisView=getPointDataView();
248      DataArrayView& evView=ev->getPointDataView();
249      DataArrayView::eigenvalues(thisView,0,evView,0);
250    }
251    void
252    DataConstant::eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol)
253    {
254      DataConstant* temp_ev=dynamic_cast<DataConstant*>(ev);
255      if (temp_ev==0) {
256        throw DataException("Error - DataConstant::eigenvalues_and_eigenvectors: casting to DataConstant failed (propably a programming error).");
257      }
258      DataConstant* temp_V=dynamic_cast<DataConstant*>(V);
259      if (temp_V==0) {
260        throw DataException("Error - DataConstant::eigenvalues_and_eigenvectors: casting to DataConstant failed (propably a programming error).");
261      }
262      DataArrayView thisView=getPointDataView();
263      DataArrayView evView=ev->getPointDataView();
264      DataArrayView VView=V->getPointDataView();
265    
266      DataArrayView::eigenvalues_and_eigenvectors(thisView,0,evView,0,VView,tol);
267    }
268    
269    void
270    DataConstant::dump(const std::string fileName) const
271    {
272       #ifdef PASO_MPI
273       throw DataException("Error - DataConstant:: dump is not implemented for MPI yet.")
274       #endif
275       #ifdef USE_NETCDF
276       const NcDim* ncdims[DataArrayView::maxRank];
277       NcVar* var;
278       int rank = getPointDataView().getRank();
279       int type=  getFunctionSpace().getTypeCode();
280       int ndims =0;
281       long dims[DataArrayView::maxRank];
282       DataArrayView::ShapeType shape = getPointDataView().getShape();
283      
284       // netCDF error handler
285       NcError err(NcError::verbose_nonfatal);
286       // Create the file.
287       NcFile dataFile(fileName.c_str(), NcFile::Replace);
288       // check if writing was successful
289       if (!dataFile.is_valid())
290        throw DataException("Error - DataConstant:: opening of netCDF file for output failed.");
291       if (!dataFile.add_att("type","constant") )
292        throw DataException("Error - DataConstant:: appending data type to netCDF file failed.");
293       if (!dataFile.add_att("rank",rank) )
294        throw DataException("Error - DataConstant:: appending rank attribute to netCDF file failed.");
295       if (!dataFile.add_att("function_space_type",type))
296        throw DataException("Error - DataConstant:: appending function space attribute to netCDF file failed.");
297    
298       if (rank == 0) {
299          if( ! (ncdims[0] = dataFile.add_dim("l", 1)) )
300            throw DataException("Error - DataConstant:: appending ncdimsion 0 to netCDF file failed.");
301          dims[0]=1,
302          ndims=1;
303       } else {
304           ndims=rank;
305           dims[0]=shape[0];
306           if (! (ncdims[0] = dataFile.add_dim("d0",shape[0])) )
307            throw DataException("Error - DataConstant:: appending ncdimsion 0 to netCDF file failed.");
308           if ( rank >1 ) {
309               dims[1]=shape[1];
310               if (! (ncdims[1] = dataFile.add_dim("d1",shape[1])) )
311            throw DataException("Error - DataConstant:: appending ncdimsion 1 to netCDF file failed.");
312           }
313           if ( rank >2 ) {
314               dims[2]=shape[2];
315               if (! (ncdims[2] = dataFile.add_dim("d2", shape[2])) )
316            throw DataException("Error - DataConstant:: appending ncdimsion 2 to netCDF file failed.");
317           }
318           if ( rank >3 ) {
319               dims[3]=shape[3];
320               if (! (ncdims[3] = dataFile.add_dim("d3", shape[3])) )
321            throw DataException("Error - DataConstant:: appending ncdimsion 3 to netCDF file failed.");
322           }
323       }
324       if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )
325        throw DataException("Error - DataConstant:: appending variable to netCDF file failed.");
326       if (! (var->put(&m_data[0],dims)) )
327        throw DataException("Error - DataConstant:: copy data to netCDF buffer failed.");
328       #else
329       throw DataException("Error - DataConstant:: dump is not configured with netCDF. Please contact your installation manager.");
330       #endif
331    }
332    
333  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.468  
changed lines
  Added in v.1023

  ViewVC Help
Powered by ViewVC 1.1.26