/[escript]/branches/split/weipa/src/DataVar.cpp
ViewVC logotype

Diff of /branches/split/weipa/src/DataVar.cpp

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

trunk/dataexporter/src/DataVar.cpp revision 2940 by caltinay, Fri Feb 19 00:38:45 2010 UTC trunk/weipa/src/DataVar.cpp revision 3128 by caltinay, Wed Sep 1 03:54:09 2010 UTC
# Line 11  Line 11 
11  *  *
12  *******************************************************/  *******************************************************/
13    
14  #include <escriptexport/DataVar.h>  #include <weipa/DataVar.h>
15  #include <escriptexport/ElementData.h>  #include <weipa/ElementData.h>
16  #include <escriptexport/FinleyMesh.h>  #include <weipa/FinleyMesh.h>
17  #include <escriptexport/NodeData.h>  #include <weipa/NodeData.h>
18  #ifndef VISIT_PLUGIN  #ifndef VISIT_PLUGIN
19  #include <escript/Data.h>  #include <escript/Data.h>
20  #endif  #endif
# Line 27  Line 27 
27  #include <silo.h>  #include <silo.h>
28  #endif  #endif
29    
30    #include <numeric> // for accumulate
31    
32  using namespace std;  using namespace std;
33    
34  namespace escriptexport {  namespace weipa {
35            
36  enum {  enum {
37      NODE_CENTERED = 1,      NODE_CENTERED = 1,
# Line 473  bool DataVar::reorderSamples() Line 475  bool DataVar::reorderSamples()
475  //  //
476  //  //
477  //  //
478    int DataVar::getNumberOfComponents() const
479    {
480        return (rank == 0 ? 1 : accumulate(shape.begin(), shape.end(), 0));
481    }
482    
483    //
484    //
485    //
486    float* DataVar::getDataFlat() const
487    {
488        int totalSize = numSamples * getNumberOfComponents();
489        float* res = new float[totalSize];
490        if (rank == 0) {
491            copy(dataArray[0], dataArray[0]+numSamples, res);
492        } else if (rank == 1) {
493            float *dest = res;
494            for (size_t c=0; c<numSamples; c++) {
495                for (size_t i=0; i<shape[0]; i++) {
496                    *dest++ = dataArray[i][c];
497                }
498            }
499        } else if (rank == 2) {
500            float *dest = res;
501            for (size_t c=0; c<numSamples; c++) {
502                for (int i=0; i<shape[1]; i++) {
503                    for (int j=0; j<shape[0]; j++) {
504                        *dest++ = dataArray[i*shape[0]+j][c];
505                    }
506                }
507            }
508        }
509    
510        return res;
511    }
512    
513    //
514    //
515    //
516  void DataVar::sampleToStream(ostream& os, int index)  void DataVar::sampleToStream(ostream& os, int index)
517  {  {
518      if (rank == 0) {      if (rank == 0) {
# Line 590  string DataVar::getTensorDef() const Line 630  string DataVar::getTensorDef() const
630  // The corresponding mesh must have been written already and made known  // The corresponding mesh must have been written already and made known
631  // to this variable by a call to setMesh().  // to this variable by a call to setMesh().
632  //  //
633  bool DataVar::writeToSilo(DBfile* dbfile, const string& siloPath)  bool DataVar::writeToSilo(DBfile* dbfile, const string& siloPath,
634                              const string& units)
635  {  {
636  #if USE_SILO  #if USE_SILO
637      if (!initialized)      if (!initialized)
# Line 609  bool DataVar::writeToSilo(DBfile* dbfile Line 650  bool DataVar::writeToSilo(DBfile* dbfile
650    
651      char* siloMesh = const_cast<char*>(siloMeshName.c_str());      char* siloMesh = const_cast<char*>(siloMeshName.c_str());
652      int dcenter = (centering == NODE_CENTERED ? DB_NODECENT : DB_ZONECENT);      int dcenter = (centering == NODE_CENTERED ? DB_NODECENT : DB_ZONECENT);
653        DBoptlist* optList = DBMakeOptlist(2);
654        if (units.length()>0) {
655            DBAddOption(optList, DBOPT_UNITS, (void*)units.c_str());
656        }
657    
658      if (rank == 0) {      if (rank == 0) {
659          ret = DBPutUcdvar1(dbfile, varName.c_str(), siloMesh, dataArray[0],          ret = DBPutUcdvar1(dbfile, varName.c_str(), siloMesh, dataArray[0],
660                  numSamples, NULL, 0, DB_FLOAT, dcenter, NULL);                  numSamples, NULL, 0, DB_FLOAT, dcenter, optList);
661      }      }
662      else if (rank == 1) {      else if (rank == 1) {
663          const string comps[3] = {          const string comps[3] = {
# Line 624  bool DataVar::writeToSilo(DBfile* dbfile Line 669  bool DataVar::writeToSilo(DBfile* dbfile
669    
670          ret = DBPutUcdvar(dbfile, varName.c_str(), siloMesh, shape[0],          ret = DBPutUcdvar(dbfile, varName.c_str(), siloMesh, shape[0],
671                  (char**)varnames, &dataArray[0], numSamples, NULL,                  (char**)varnames, &dataArray[0], numSamples, NULL,
672                  0, DB_FLOAT, dcenter, NULL);                  0, DB_FLOAT, dcenter, optList);
673      }      }
674      else {      else {
675          string tensorDir = varName+string("_comps/");          string tensorDir = varName+string("_comps/");
676          ret = DBMkdir(dbfile, tensorDir.c_str());          ret = DBMkdir(dbfile, tensorDir.c_str());
677          if (ret == 0) {          if (ret == 0) {
678              int one = 1;              int one = 1;
             DBoptlist* optList = DBMakeOptlist(1);  
679              DBAddOption(optList, DBOPT_HIDE_FROM_GUI, &one);              DBAddOption(optList, DBOPT_HIDE_FROM_GUI, &one);
680    
681              for (int i=0; i<shape[1]; i++) {              for (int i=0; i<shape[1]; i++) {
# Line 645  bool DataVar::writeToSilo(DBfile* dbfile Line 689  bool DataVar::writeToSilo(DBfile* dbfile
689                  }                  }
690                  if (ret != 0) break;                  if (ret != 0) break;
691              }              }
             DBFreeOptlist(optList);  
692          } // ret==0          } // ret==0
693      } // rank      } // rank
694    
695        DBFreeOptlist(optList);
696      DBSetDir(dbfile, "/");      DBSetDir(dbfile, "/");
697      return (ret == 0);      return (ret == 0);
698    
# Line 657  bool DataVar::writeToSilo(DBfile* dbfile Line 701  bool DataVar::writeToSilo(DBfile* dbfile
701  #endif  #endif
702  }  }
703    
704  } // namespace escriptexport  } // namespace weipa
705    

Legend:
Removed from v.2940  
changed lines
  Added in v.3128

  ViewVC Help
Powered by ViewVC 1.1.26