/[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 757 by woo409, Mon Jun 26 13:12:56 2006 UTC revision 1023 by gross, Tue Mar 13 05:43:36 2007 UTC
# Line 16  Line 16 
16    
17  #include "DataConstant.h"  #include "DataConstant.h"
18  #include "DataException.h"  #include "DataException.h"
19    #ifdef USE_NETCDF
20    #include <netcdfcpp.h>
21    #endif
22    
23  using namespace std;  using namespace std;
24    
# Line 131  DataTagged::DataTagged(const DataConstan Line 134  DataTagged::DataTagged(const DataConstan
134    setPointDataView(temp);    setPointDataView(temp);
135  }  }
136    
 void  
 DataTagged::reshapeDataPoint(const DataArrayView::ShapeType& shape)  
 {  
   // can only reshape a rank zero data point  
   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());  
   }  
   
   // allocate enough space for all values  
   DataArrayView::ValueType newData(DataArrayView::noValues(shape)*(m_offsetLookup.size()+1));  
   DataArrayView newView(newData,shape);  
   newView.copy(0,getDefaultValue()());  
   
   // loop through the tag values  
   DataMapType::iterator pos;  
   DataArrayView::ValueType::size_type tagOffset=DataArrayView::noValues(shape);  
   for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();pos++){  
     newView.copy(tagOffset,m_data[pos->second]);  
     pos->second=tagOffset;  
     tagOffset+=DataArrayView::noValues(shape);  
   }  
   m_data=newData;  
   DataArrayView temp(m_data,shape);  
   setPointDataView(temp);  
 }  
   
137  DataAbstract*  DataAbstract*
138  DataTagged::getSlice(const DataArrayView::RegionType& region) const  DataTagged::getSlice(const DataArrayView::RegionType& region) const
139  {  {
# Line 443  DataTagged::extractData(ifstream& archiv Line 416  DataTagged::extractData(ifstream& archiv
416    return(m_data.extractData(archiveFile, noValues));    return(m_data.extractData(archiveFile, noValues));
417  }  }
418  void  void
419    DataTagged::symmetric(DataAbstract* ev)
420    {
421      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
422      if (temp_ev==0) {
423        throw DataException("Error - DataTagged::symmetric casting to DataTagged failed (probably a programming error).");
424      }
425      const DataTagged::DataMapType& thisLookup=getTagLookup();
426      DataTagged::DataMapType::const_iterator i;
427      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
428      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
429          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
430          DataArrayView thisView=getDataPointByTag(i->first);
431          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
432          DataArrayView::symmetric(thisView,0,evView,0);
433      }
434      DataArrayView::symmetric(getDefaultValue(),0,temp_ev->getDefaultValue(),0);
435    }
436    void
437    DataTagged::nonsymmetric(DataAbstract* ev)
438    {
439      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
440      if (temp_ev==0) {
441        throw DataException("Error - DataTagged::nonsymmetric casting to DataTagged failed (probably a programming error).");
442      }
443      const DataTagged::DataMapType& thisLookup=getTagLookup();
444      DataTagged::DataMapType::const_iterator i;
445      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
446      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
447          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
448          DataArrayView thisView=getDataPointByTag(i->first);
449          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
450          DataArrayView::nonsymmetric(thisView,0,evView,0);
451      }
452      DataArrayView::nonsymmetric(getDefaultValue(),0,temp_ev->getDefaultValue(),0);
453    }
454    void
455    DataTagged::trace(DataAbstract* ev, int axis_offset)
456    {
457      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
458      if (temp_ev==0) {
459        throw DataException("Error - DataTagged::trace casting to DataTagged failed (probably a programming error).");
460      }
461      const DataTagged::DataMapType& thisLookup=getTagLookup();
462      DataTagged::DataMapType::const_iterator i;
463      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
464      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
465          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
466          DataArrayView thisView=getDataPointByTag(i->first);
467          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
468          DataArrayView::trace(thisView,0,evView,0, axis_offset);
469      }
470      DataArrayView::trace(getDefaultValue(),0,temp_ev->getDefaultValue(),0,axis_offset);
471    }
472    
473    void
474    DataTagged::transpose(DataAbstract* ev, int axis_offset)
475    {
476      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
477      if (temp_ev==0) {
478        throw DataException("Error - DataTagged::transpose casting to DataTagged failed (probably a programming error).");
479      }
480      const DataTagged::DataMapType& thisLookup=getTagLookup();
481      DataTagged::DataMapType::const_iterator i;
482      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
483      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
484          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
485          DataArrayView thisView=getDataPointByTag(i->first);
486          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
487          DataArrayView::transpose(thisView,0,evView,0, axis_offset);
488      }
489      DataArrayView::transpose(getDefaultValue(),0,temp_ev->getDefaultValue(),0,axis_offset);
490    }
491    
492    void
493    DataTagged::swapaxes(DataAbstract* ev, int axis0, int axis1)
494    {
495      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
496      if (temp_ev==0) {
497        throw DataException("Error - DataTagged::swapaxes casting to DataTagged failed (probably a programming error).");
498      }
499      const DataTagged::DataMapType& thisLookup=getTagLookup();
500      DataTagged::DataMapType::const_iterator i;
501      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
502      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
503          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
504          DataArrayView thisView=getDataPointByTag(i->first);
505          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
506          DataArrayView::swapaxes(thisView,0,evView,0,axis0,axis1);
507      }
508      DataArrayView::swapaxes(getDefaultValue(),0,temp_ev->getDefaultValue(),0,axis0,axis1);
509    }
510    
511    void
512  DataTagged::eigenvalues(DataAbstract* ev)  DataTagged::eigenvalues(DataAbstract* ev)
513  {  {
514    DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);    DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
# Line 490  DataTagged::eigenvalues_and_eigenvectors Line 556  DataTagged::eigenvalues_and_eigenvectors
556    
557  }  }
558    
559    void
560    DataTagged::dump(const std::string fileName) const
561    {
562       #ifdef PASO_MPI
563       throw DataException("Error - DataTagged:: dump is not implemented for MPI yet.")
564       #endif
565       #ifdef USE_NETCDF
566       const int ldims=DataArrayView::maxRank+1;
567       const NcDim* ncdims[ldims];
568       NcVar *var, *tags_var;
569       int rank = getPointDataView().getRank();
570       int type=  getFunctionSpace().getTypeCode();
571       int ndims =0;
572       long dims[ldims];
573       DataArrayView::ShapeType shape = getPointDataView().getShape();
574    
575       // netCDF error handler
576       NcError err(NcError::verbose_nonfatal);
577       // Create the file.
578       NcFile dataFile(fileName.c_str(), NcFile::Replace);
579       // check if writing was successful
580       if (!dataFile.is_valid())
581            throw DataException("Error - DataTagged:: opening of netCDF file for output failed.");
582       if (!dataFile.add_att("type","tagged") )
583            throw DataException("Error - DataTagged:: appending data type to netCDF file failed.");
584       if (!dataFile.add_att("rank",rank) )
585            throw DataException("Error - DataTagged:: appending rank attribute to netCDF file failed.");
586       if (!dataFile.add_att("function_space_type",type))
587            throw DataException("Error - DataTagged:: appending function space attribute to netCDF file failed.");
588       ndims=rank+1;
589       if ( rank >0 ) {
590           dims[0]=shape[0];
591           if (! (ncdims[0] = dataFile.add_dim("d0",shape[0])) )
592                throw DataException("Error - DataTagged:: appending ncdimsion 0 to netCDF file failed.");
593       }
594       if ( rank >1 ) {
595           dims[1]=shape[1];
596           if (! (ncdims[1] = dataFile.add_dim("d1",shape[1])) )
597                throw DataException("Error - DataTagged:: appending ncdimsion 1 to netCDF file failed.");
598       }
599       if ( rank >2 ) {
600           dims[2]=shape[2];
601           if (! (ncdims[2] = dataFile.add_dim("d2", shape[2])) )
602                throw DataException("Error - DataTagged:: appending ncdimsion 2 to netCDF file failed.");
603       }
604       if ( rank >3 ) {
605           dims[3]=shape[3];
606           if (! (ncdims[3] = dataFile.add_dim("d3", shape[3])) )
607                throw DataException("Error - DataTagged:: appending ncdimsion 3 to netCDF file failed.");
608       }
609       const DataTagged::DataMapType& thisLookup=getTagLookup();
610       DataTagged::DataMapType::const_iterator i;
611       DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
612       int ntags=1;
613       for (i=thisLookup.begin();i!=thisLookupEnd;i++) ntags++;
614       int* tags =(int*) malloc(ntags*sizeof(int));
615       int c=1;
616       tags[0]=-1;
617       for (i=thisLookup.begin();i!=thisLookupEnd;i++) tags[c++]=i->first;
618       dims[rank]=ntags;
619       if (! (ncdims[rank] = dataFile.add_dim("num_tags", dims[rank])) )
620       {
621           free(tags);
622               throw DataException("Error - DataTagged:: appending num_tags to netCDF file failed.");
623       }
624       if (! ( tags_var = dataFile.add_var("tags", ncInt, ncdims[rank])) )
625       {
626        free(tags);
627            throw DataException("Error - DataTagged:: appending tags to netCDF file failed.");
628       }
629       if (! (tags_var->put(tags,dims[rank])) )
630       {
631        free(tags);
632            throw DataException("Error - DataTagged:: copy tags to netCDF buffer failed.");
633       }
634       if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )
635       {
636        free(tags);
637            throw DataException("Error - DataTagged:: appending variable to netCDF file failed.");
638       }
639       if (! (var->put(&m_data[0],dims)) )
640       {
641        free(tags);
642            throw DataException("Error - DataTagged:: copy data to netCDF buffer failed.");
643       }
644       #else
645       throw DataException("Error - DataTagged:: dump is not configured with netCDF. Please contact your installation manager.");
646       #endif
647    }
648  }  // end of namespace  }  // end of namespace

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

  ViewVC Help
Powered by ViewVC 1.1.26