/[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 966 by gross, Tue Feb 13 05:45:18 2007 UTC revision 1312 by ksteube, Mon Sep 24 06:18:44 2007 UTC
# Line 1  Line 1 
1  // $Id$  
2  /*  /* $Id$ */
3   ************************************************************  
4   *          Copyright 2006 by ACcESS MNRF                   *  /*******************************************************
5   *                                                          *   *
6   *              http://www.access.edu.au                    *   *           Copyright 2003-2007 by ACceSS MNRF
7   *       Primary Business: Queensland, Australia            *   *       Copyright 2007 by University of Queensland
8   *  Licensed under the Open Software License version 3.0    *   *
9   *     http://www.opensource.org/licenses/osl-3.0.php       *   *                http://esscc.uq.edu.au
10   *                                                          *   *        Primary Business: Queensland, Australia
11   ************************************************************   *  Licensed under the Open Software License version 3.0
12  */   *     http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16  #include "DataExpanded.h"  #include "DataExpanded.h"
17  #include "DataException.h"  #include "DataException.h"
18  #include "DataConstant.h"  #include "DataConstant.h"
19  #include "DataTagged.h"  #include "DataTagged.h"
20    #ifdef USE_NETCDF
21    #include <netcdfcpp.h>
22    #endif
23    
24  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
25    
# Line 615  DataExpanded::eigenvalues_and_eigenvecto Line 620  DataExpanded::eigenvalues_and_eigenvecto
620  }  }
621    
622  void  void
623  DataExpanded::dump(const std::string fileName) const  DataExpanded::setToZero(){
624  {    int numSamples = getNumSamples();
625      int numDataPointsPerSample = getNumDPPSample();
626     throw DataException("Error - DataExpanded:: dump is not implemented yet.");    DataArrayView& thisView=getPointDataView();
627      DataArrayView::ValueType::size_type n = thisView.noValues();
628      double* p;
629      int  sampleNo,dataPointNo, i;
630      #pragma omp parallel for private(sampleNo,dataPointNo,p,i) schedule(static)
631      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
632        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
633            p=&(m_data[getPointOffset(sampleNo,dataPointNo)]);
634            for (int i=0; i<n ;++i) p[i]=0.;
635        }
636      }
637  }  }
638    
639    
640    void
641    DataExpanded::dump(const std::string fileName) const
642    {
643       #ifdef PASO_MPI
644       throw DataException("Error - DataExpanded:: dump is not implemented for MPI yet.");
645       #endif
646       #ifdef USE_NETCDF
647       const int ldims=2+DataArrayView::maxRank;
648       const NcDim* ncdims[ldims];
649       NcVar *var, *ids;
650       int rank = getPointDataView().getRank();
651       int type=  getFunctionSpace().getTypeCode();
652       int ndims =0;
653       long dims[ldims];
654       const double* d_ptr=&(m_data[0]);
655       DataArrayView::ShapeType shape = getPointDataView().getShape();
656    
657       // netCDF error handler
658       NcError err(NcError::verbose_nonfatal);
659       // Create the file.
660       NcFile dataFile(fileName.c_str(), NcFile::Replace);
661       // check if writing was successful
662       if (!dataFile.is_valid())
663            throw DataException("Error - DataExpanded:: opening of netCDF file for output failed.");
664       if (!dataFile.add_att("type_id",2) )
665            throw DataException("Error - DataExpanded:: appending data type to netCDF file failed.");
666       if (!dataFile.add_att("rank",rank) )
667            throw DataException("Error - DataExpanded:: appending rank attribute to netCDF file failed.");
668       if (!dataFile.add_att("function_space_type",type))
669            throw DataException("Error - DataExpanded:: appending function space attribute to netCDF file failed.");
670       ndims=rank+2;
671       if ( rank >0 ) {
672           dims[0]=shape[0];
673           if (! (ncdims[0] = dataFile.add_dim("d0",shape[0])) )
674                throw DataException("Error - DataExpanded:: appending ncdimsion 0 to netCDF file failed.");
675       }
676       if ( rank >1 ) {
677           dims[1]=shape[1];
678           if (! (ncdims[1] = dataFile.add_dim("d1",shape[1])) )
679                throw DataException("Error - DataExpanded:: appending ncdimsion 1 to netCDF file failed.");
680       }
681       if ( rank >2 ) {
682           dims[2]=shape[2];
683           if (! (ncdims[2] = dataFile.add_dim("d2", shape[2])) )
684                throw DataException("Error - DataExpanded:: appending ncdimsion 2 to netCDF file failed.");
685       }
686       if ( rank >3 ) {
687           dims[3]=shape[3];
688           if (! (ncdims[3] = dataFile.add_dim("d3", shape[3])) )
689                throw DataException("Error - DataExpanded:: appending ncdimsion 3 to netCDF file failed.");
690       }
691       dims[rank]=getFunctionSpace().getNumDataPointsPerSample();
692       if (! (ncdims[rank] = dataFile.add_dim("num_data_points_per_sample", dims[rank])) )
693                throw DataException("Error - DataExpanded:: appending num_data_points_per_sample to netCDF file failed.");
694       dims[rank+1]=getFunctionSpace().getNumSamples();
695       if (! (ncdims[rank+1] = dataFile.add_dim("num_samples", dims[rank+1])) )
696                throw DataException("Error - DataExpanded:: appending num_sample to netCDF file failed.");
697    
698       if (! ( ids = dataFile.add_var("id", ncInt, ncdims[rank+1])) )
699            throw DataException("Error - DataExpanded:: appending reference id to netCDF file failed.");
700       const int* ids_p=getFunctionSpace().borrowSampleReferenceIDs();
701       if (! (ids->put(ids_p,dims[rank+1])) )
702            throw DataException("Error - DataExpanded:: copy reference id  to netCDF buffer failed.");
703    
704       if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )
705            throw DataException("Error - DataExpanded:: appending variable to netCDF file failed.");
706       if (! (var->put(d_ptr,dims)) )
707            throw DataException("Error - DataExpanded:: copy data to netCDF buffer failed.");
708       #else
709       throw DataException("Error - DataExpanded:: dump is not configured with netCDF. Please contact your installation manager.");
710       #endif
711    }
712  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.966  
changed lines
  Added in v.1312

  ViewVC Help
Powered by ViewVC 1.1.26