/[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

revision 2881 by jfenwick, Thu Jan 28 02:03:15 2010 UTC revision 2940 by caltinay, Fri Feb 19 00:38:45 2010 UTC
# Line 15  Line 15 
15  #include <escriptexport/ElementData.h>  #include <escriptexport/ElementData.h>
16  #include <escriptexport/FinleyMesh.h>  #include <escriptexport/FinleyMesh.h>
17  #include <escriptexport/NodeData.h>  #include <escriptexport/NodeData.h>
18    #ifndef VISIT_PLUGIN
19  #include <escript/Data.h>  #include <escript/Data.h>
20    #endif
21    
22  #if USE_NETCDF  #if USE_NETCDF
23  #include <netcdf.hh>  #include <netcdfcpp.h>
24  #endif  #endif
25    
26  #if USE_SILO  #if USE_SILO
# Line 90  void DataVar::cleanup() Line 92  void DataVar::cleanup()
92  //  //
93  bool DataVar::initFromEscript(escript::Data& escriptData, FinleyMesh_ptr mesh)  bool DataVar::initFromEscript(escript::Data& escriptData, FinleyMesh_ptr mesh)
94  {  {
95    #ifndef VISIT_PLUGIN
96      cleanup();      cleanup();
97    
98      if (!escriptData.actsExpanded()) {      if (!escriptData.actsExpanded()) {
# Line 163  bool DataVar::initFromEscript(escript::D Line 166  bool DataVar::initFromEscript(escript::D
166      }      }
167    
168      return initialized;      return initialized;
169    
170    #else // VISIT_PLUGIN
171        return false;
172    #endif
173  }  }
174    
175  //  //
# Line 366  float* DataVar::averageData(const float* Line 373  float* DataVar::averageData(const float*
373          res = new float[cellFactor * numSamples];          res = new float[cellFactor * numSamples];
374          float* dest = res;          float* dest = res;
375          QuadMaskInfo qmi = cells->getQuadMask(funcSpace);          QuadMaskInfo qmi = cells->getQuadMask(funcSpace);
376          if (qmi.mask.size() > 0) {          if (!qmi.mask.empty()) {
377              const float* tmpSrc = src;              const float* tmpSrc = src;
378              for (int i=0; i<numSamples; i++, tmpSrc+=stride*ptsPerSample) {              for (int i=0; i<numSamples; i++, tmpSrc+=stride*ptsPerSample) {
379                  for (int l=0; l<cellFactor; l++) {                  for (int l=0; l<cellFactor; l++) {
# Line 463  bool DataVar::reorderSamples() Line 470  bool DataVar::reorderSamples()
470      return true;      return true;
471  }  }
472    
473    //
474    //
475    //
476    void DataVar::sampleToStream(ostream& os, int index)
477    {
478        if (rank == 0) {
479            os << dataArray[0][index];
480        } else if (rank == 1) {
481            if (shape[0] < 3)
482                os << dataArray[0][index] << " " << dataArray[1][index]
483                    << " " << 0.;
484            else
485                os << dataArray[0][index] << " " << dataArray[1][index]
486                    << " " << dataArray[2][index];
487        } else if (rank == 2) {
488            if (shape[1] < 3) {
489                os << dataArray[0][index] << " " << dataArray[1][index]
490                    << " " << 0. << " ";
491                os << dataArray[2][index] << " " << dataArray[3][index]
492                    << " " << 0. << " ";
493                os << 0. << " " << 0. << " " << 0.;
494            } else {
495                os << dataArray[0][index] << " " << dataArray[1][index]
496                    << " " << dataArray[2][index] << " ";
497                os << dataArray[3][index] << " " << dataArray[4][index]
498                    << " " << dataArray[5][index] << " ";
499                os << dataArray[6][index] << " " << dataArray[7][index]
500                    << " " << dataArray[8][index];
501            }
502        }
503        os << endl;
504    }
505    
506    //
507    //
508    //
509    void DataVar::writeToVTK(ostream& os, int ownIndex)
510    {
511        if (numSamples == 0)
512            return;
513    
514        if (isNodeCentered()) {
515            // data was reordered in reorderSamples() but for VTK we write the
516            // original node mesh and thus need the original ordering...
517            const IntVec& requiredIDs = finleyMesh->getNodes()->getNodeIDs();
518            const IntVec& nodeGNI = finleyMesh->getNodes()->getGlobalNodeIndices();
519            const IntVec& nodeDist = finleyMesh->getNodes()->getNodeDistribution();
520            int firstId = nodeDist[ownIndex];
521            int lastId = nodeDist[ownIndex+1];
522            IndexMap sampleID2idx = buildIndexMap();
523            for (int i=0; i<nodeGNI.size(); i++) {
524                if (firstId <= nodeGNI[i] && nodeGNI[i] < lastId) {
525                    int idx = sampleID2idx[requiredIDs[i]];
526                    sampleToStream(os, idx);
527                }
528            }
529        } else {
530            // cell data: ghost cells have been removed so do not write ghost
531            // samples (which are the last elements in the arrays)
532            int toWrite =
533                finleyMesh->getElementsByName(meshName)->getNumElements();
534            for (int i=0; i<toWrite; i++) {
535                sampleToStream(os, i);
536            }
537        }
538    }
539    
540  ///////////////////////////////  ///////////////////////////////
541  // SILO related methods follow  // SILO related methods follow
542  ///////////////////////////////  ///////////////////////////////

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

  ViewVC Help
Powered by ViewVC 1.1.26