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

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

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

revision 1800 by ksteube, Thu Sep 18 05:28:20 2008 UTC revision 1872 by jfenwick, Mon Oct 13 00:18:55 2008 UTC
# Line 1  Line 1 
1    
 /* $Id$ */  
   
2  /*******************************************************  /*******************************************************
3   *  *
4   *           Copyright 2003-2007 by ACceSS MNRF  * Copyright (c) 2003-2008 by University of Queensland
5   *       Copyright 2007 by University of Queensland  * Earth Systems Science Computational Center (ESSCC)
6   *  * http://www.uq.edu.au/esscc
7   *                http://esscc.uq.edu.au  *
8   *        Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
9   *  Licensed under the Open Software License version 3.0  * Licensed under the Open Software License version 3.0
10   *     http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
11   *  *
12   *******************************************************/  *******************************************************/
13    
14    
15    #include "Data.h"
16  #include "DataTagged.h"  #include "DataTagged.h"
17  #include "esysUtils/esys_malloc.h"  #include "esysUtils/esys_malloc.h"
18    
# Line 21  Line 21 
21  #ifdef USE_NETCDF  #ifdef USE_NETCDF
22  #include <netcdfcpp.h>  #include <netcdfcpp.h>
23  #endif  #endif
24    #ifdef PASO_MPI
25    #include <mpi.h>
26    #endif
27  #include "DataMaths.h"  #include "DataMaths.h"
28    
29  using namespace std;  using namespace std;
# Line 72  DataTagged::DataTagged(const FunctionSpa Line 75  DataTagged::DataTagged(const FunctionSpa
75    // not unit_tested tested yet    // not unit_tested tested yet
76    // It is not explicitly unit tested yet, but it is called from DataFactory    // It is not explicitly unit tested yet, but it is called from DataFactory
77    
78      if (!what.canTag())
79      {
80        throw DataException("Programming error - DataTag created with a non-taggable FunctionSpace.");
81      }
82    // copy the data    // copy the data
83    m_data=data;    m_data=data;
84    
# Line 100  DataTagged::DataTagged(const FunctionSpa Line 107  DataTagged::DataTagged(const FunctionSpa
107  {  {
108    // alternative constructor    // alternative constructor
109    
110      if (!what.canTag())
111      {
112        throw DataException("Programming error - DataTag created with a non-taggable FunctionSpace.");
113      }
114    
115    // copy the data    // copy the data
116    m_data=data;    m_data=data;
117    
# Line 149  DataTagged::DataTagged(const DataConstan Line 161  DataTagged::DataTagged(const DataConstan
161  {  {
162    // copy constructor    // copy constructor
163    
164      if (!other.getFunctionSpace().canTag())
165      {
166        throw DataException("Programming error - DataTag created with a non-taggable FunctionSpace.");
167      }
168    
169    // fill the default value with the constant value item from "other"    // fill the default value with the constant value item from "other"
170  //   const DataArrayView& value=other.getPointDataView();  //   const DataArrayView& value=other.getPointDataView();
171    int len = other.getNoValues();    int len = other.getNoValues();
# Line 177  DataTagged::DataTagged(const FunctionSpa Line 194  DataTagged::DataTagged(const FunctionSpa
194    }    }
195    
196    
197      if (!what.canTag())
198      {
199        throw DataException("Programming error - DataTag created with a non-taggable FunctionSpace.");
200      }
201    
202    if (tagsource!=0)    if (tagsource!=0)
203    {    {
204      int numtags=tagsource->getTagLookup().size();      int numtags=tagsource->getTagLookup().size();
# Line 421  DataTagged::addTaggedValues(const TagLis Line 443  DataTagged::addTaggedValues(const TagLis
443                              const ShapeType& vShape)                              const ShapeType& vShape)
444  {  {
445    DataTypes::ValueType t(values.size(),0);    DataTypes::ValueType t(values.size(),0);
446    for (int i=0;i<values.size();++i)    for (size_t i=0;i<values.size();++i)
447    {    {
448      t[i]=values[i];      t[i]=values[i];
449    }    }
# Line 590  DataTagged::toString() const Line 612  DataTagged::toString() const
612  //   DataArrayView tempView(getPointDataView().getData(), getPointDataView().getShape());  //   DataArrayView tempView(getPointDataView().getData(), getPointDataView().getShape());
613    for (i=m_offsetLookup.begin();i!=m_offsetLookup.end();++i) {    for (i=m_offsetLookup.begin();i!=m_offsetLookup.end();++i) {
614      temp << "Tag(" << i->first << ")" << endl;      temp << "Tag(" << i->first << ")" << endl;
615      temp << pointToString(m_data,getShape(),i->second,empty);      temp << pointToString(m_data,getShape(),i->second,empty) << endl;
616  //     tempView.setOffset(i->second);  //     tempView.setOffset(i->second);
617  //     temp << tempView.toString() << endl;  //     temp << tempView.toString() << endl;
618    }    }
# Line 869  DataTagged::setToZero(){ Line 891  DataTagged::setToZero(){
891  void  void
892  DataTagged::dump(const std::string fileName) const  DataTagged::dump(const std::string fileName) const
893  {  {
    #ifdef PASO_MPI  
    throw DataException("Error - DataTagged:: dump is not implemented for MPI yet.");  
    #endif  
894     #ifdef USE_NETCDF     #ifdef USE_NETCDF
895     const int ldims=DataTypes::maxRank+1;     const int ldims=DataTypes::maxRank+1;
896     const NcDim* ncdims[ldims];     const NcDim* ncdims[ldims];
# Line 882  DataTagged::dump(const std::string fileN Line 901  DataTagged::dump(const std::string fileN
901     long dims[ldims];     long dims[ldims];
902     const double* d_ptr=&(m_data[0]);     const double* d_ptr=&(m_data[0]);
903     DataTypes::ShapeType shape = getShape();     DataTypes::ShapeType shape = getShape();
904       int mpi_iam=getFunctionSpace().getDomain()->getMPIRank();
905       int mpi_num=getFunctionSpace().getDomain()->getMPISize();
906    #ifdef PASO_MPI
907       MPI_Status status;
908    #endif
909    
910    #ifdef PASO_MPI
911       /* Serialize NetCDF I/O */
912       if (mpi_iam>0) MPI_Recv(&ndims, 0, MPI_INT, mpi_iam-1, 81803, MPI_COMM_WORLD, &status);
913    #endif
914    
915     // netCDF error handler     // netCDF error handler
916     NcError err(NcError::verbose_nonfatal);     NcError err(NcError::verbose_nonfatal);
917     // Create the file.     // Create the file.
918     NcFile dataFile(fileName.c_str(), NcFile::Replace);     char *newFileName = Escript_MPI_appendRankToFileName(fileName.c_str(), mpi_num, mpi_iam);
919       NcFile dataFile(newFileName, NcFile::Replace);
920     // check if writing was successful     // check if writing was successful
921     if (!dataFile.is_valid())     if (!dataFile.is_valid())
922          throw DataException("Error - DataTagged:: opening of netCDF file for output failed.");          throw DataException("Error - DataTagged:: opening of netCDF file for output failed.");
# Line 952  DataTagged::dump(const std::string fileN Line 982  DataTagged::dump(const std::string fileN
982      esysUtils::free(tags);      esysUtils::free(tags);
983          throw DataException("Error - DataTagged:: copy data to netCDF buffer failed.");          throw DataException("Error - DataTagged:: copy data to netCDF buffer failed.");
984     }     }
985    #ifdef PASO_MPI
986       if (mpi_iam<mpi_num-1) MPI_Send(&ndims, 0, MPI_INT, mpi_iam+1, 81803, MPI_COMM_WORLD);
987    #endif
988     #else     #else
989     throw DataException("Error - DataTagged:: dump is not configured with netCDF. Please contact your installation manager.");     throw DataException("Error - DataTagged:: dump is not configured with netCDF. Please contact your installation manager.");
990     #endif     #endif

Legend:
Removed from v.1800  
changed lines
  Added in v.1872

  ViewVC Help
Powered by ViewVC 1.1.26