/[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 1946 by jfenwick, Wed Oct 29 05:48:53 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 134  DataTagged::DataTagged(const FunctionSpa Line 146  DataTagged::DataTagged(const FunctionSpa
146    
147  DataTagged::DataTagged(const DataTagged& other)  DataTagged::DataTagged(const DataTagged& other)
148    : DataAbstract(other.getFunctionSpace(),other.getShape()),    : DataAbstract(other.getFunctionSpace(),other.getShape()),
149    m_data(other.m_data),    m_offsetLookup(other.m_offsetLookup),
150    m_offsetLookup(other.m_offsetLookup)    m_data(other.m_data)
151  {  {
152    // copy constructor    // copy constructor
153    
# 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();         m_data.resize(defaultvalue.size(),0.);   // since this is tagged data, we should have blocksize=1
     //  m_offsetLookup.reserve(tagsource.getTagLookup().size());  
     m_data.resize(defaultvalue.size(),0.);  // since this is tagged data, we should have blocksize=1  
205    
206         DataTagged::DataMapType::const_iterator i;         DataTagged::DataMapType::const_iterator i;
207         for (i=tagsource->getTagLookup().begin();i!=tagsource->getTagLookup().end();i++) {         for (i=tagsource->getTagLookup().begin();i!=tagsource->getTagLookup().end();i++) {
# Line 193  DataTagged::DataTagged(const FunctionSpa Line 213  DataTagged::DataTagged(const FunctionSpa
213      m_data.resize(defaultvalue.size());      m_data.resize(defaultvalue.size());
214    }    }
215    
   
   
216    // need to set the default value ....    // need to set the default value ....
217    for (int i=0; i<defaultvalue.size(); i++) {    for (int i=0; i<defaultvalue.size(); i++) {
218       m_data[i]=defaultvalue[i];       m_data[i]=defaultvalue[i];
# Line 421  DataTagged::addTaggedValues(const TagLis Line 439  DataTagged::addTaggedValues(const TagLis
439                              const ShapeType& vShape)                              const ShapeType& vShape)
440  {  {
441    DataTypes::ValueType t(values.size(),0);    DataTypes::ValueType t(values.size(),0);
442    for (int i=0;i<values.size();++i)    for (size_t i=0;i<values.size();++i)
443    {    {
444      t[i]=values[i];      t[i]=values[i];
445    }    }
# Line 590  DataTagged::toString() const Line 608  DataTagged::toString() const
608  //   DataArrayView tempView(getPointDataView().getData(), getPointDataView().getShape());  //   DataArrayView tempView(getPointDataView().getData(), getPointDataView().getShape());
609    for (i=m_offsetLookup.begin();i!=m_offsetLookup.end();++i) {    for (i=m_offsetLookup.begin();i!=m_offsetLookup.end();++i) {
610      temp << "Tag(" << i->first << ")" << endl;      temp << "Tag(" << i->first << ")" << endl;
611      temp << pointToString(m_data,getShape(),i->second,empty);      temp << pointToString(m_data,getShape(),i->second,empty) << endl;
612  //     tempView.setOffset(i->second);  //     tempView.setOffset(i->second);
613  //     temp << tempView.toString() << endl;  //     temp << tempView.toString() << endl;
614    }    }
# Line 869  DataTagged::setToZero(){ Line 887  DataTagged::setToZero(){
887  void  void
888  DataTagged::dump(const std::string fileName) const  DataTagged::dump(const std::string fileName) const
889  {  {
    #ifdef PASO_MPI  
    throw DataException("Error - DataTagged:: dump is not implemented for MPI yet.");  
    #endif  
890     #ifdef USE_NETCDF     #ifdef USE_NETCDF
891     const int ldims=DataTypes::maxRank+1;     const int ldims=DataTypes::maxRank+1;
892     const NcDim* ncdims[ldims];     const NcDim* ncdims[ldims];
# Line 882  DataTagged::dump(const std::string fileN Line 897  DataTagged::dump(const std::string fileN
897     long dims[ldims];     long dims[ldims];
898     const double* d_ptr=&(m_data[0]);     const double* d_ptr=&(m_data[0]);
899     DataTypes::ShapeType shape = getShape();     DataTypes::ShapeType shape = getShape();
900       int mpi_iam=getFunctionSpace().getDomain()->getMPIRank();
901       int mpi_num=getFunctionSpace().getDomain()->getMPISize();
902    #ifdef PASO_MPI
903       MPI_Status status;
904    #endif
905    
906    #ifdef PASO_MPI
907       /* Serialize NetCDF I/O */
908       if (mpi_iam>0) MPI_Recv(&ndims, 0, MPI_INT, mpi_iam-1, 81803, MPI_COMM_WORLD, &status);
909    #endif
910    
911     // netCDF error handler     // netCDF error handler
912     NcError err(NcError::verbose_nonfatal);     NcError err(NcError::verbose_nonfatal);
913     // Create the file.     // Create the file.
914     NcFile dataFile(fileName.c_str(), NcFile::Replace);     char *newFileName = Escript_MPI_appendRankToFileName(fileName.c_str(), mpi_num, mpi_iam);
915       NcFile dataFile(newFileName, NcFile::Replace);
916     // check if writing was successful     // check if writing was successful
917     if (!dataFile.is_valid())     if (!dataFile.is_valid())
918          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 978  DataTagged::dump(const std::string fileN
978      esysUtils::free(tags);      esysUtils::free(tags);
979          throw DataException("Error - DataTagged:: copy data to netCDF buffer failed.");          throw DataException("Error - DataTagged:: copy data to netCDF buffer failed.");
980     }     }
981    #ifdef PASO_MPI
982       if (mpi_iam<mpi_num-1) MPI_Send(&ndims, 0, MPI_INT, mpi_iam+1, 81803, MPI_COMM_WORLD);
983    #endif
984     #else     #else
985     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.");
986     #endif     #endif

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

  ViewVC Help
Powered by ViewVC 1.1.26