/[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 3357 by caltinay, Wed Nov 17 06:21:37 2010 UTC revision 3867 by caltinay, Thu Mar 15 05:45:54 2012 UTC
# Line 139  bool DataVar::initFromEscript(escript::D Line 139  bool DataVar::initFromEscript(escript::D
139          initialized = false;          initialized = false;
140      }      }
141    
142        // special case: shape=(1,) or shape=(1,1) -> convert to scalar
143        if (dimSize==1 && rank>0) {
144            rank=0;
145            shape.clear();
146        }
147    
148      if (initialized) {      if (initialized) {
149          size_t dataSize = dimSize * ptsPerSample;          size_t dataSize = dimSize * ptsPerSample;
150          float* tempData = new float[dataSize*numSamples];          float* tempData = new float[dataSize*numSamples];
# Line 481  float* DataVar::getDataFlat() const Line 487  float* DataVar::getDataFlat() const
487  //  //
488  void DataVar::sampleToStream(ostream& os, int index)  void DataVar::sampleToStream(ostream& os, int index)
489  {  {
490        // index is -1 for dummy samples, i.e. if writing the full mesh but
491        // only a reduced number of samples is required
492      if (rank == 0) {      if (rank == 0) {
493          os << dataArray[0][index];          if (index < 0) {
494                os << 0.;
495            } else {
496                os << dataArray[0][index];
497            }
498      } else if (rank == 1) {      } else if (rank == 1) {
499          if (shape[0] < 3)          if (index < 0) {
500                os << 0. << " " << 0.  << " " << 0.;
501            } else if (shape[0] < 3) {
502              os << dataArray[0][index] << " " << dataArray[1][index]              os << dataArray[0][index] << " " << dataArray[1][index]
503                  << " " << 0.;                  << " " << 0.;
504          else          } else {
505              os << dataArray[0][index] << " " << dataArray[1][index]              os << dataArray[0][index] << " " << dataArray[1][index]
506                  << " " << dataArray[2][index];                  << " " << dataArray[2][index];
507            }
508      } else if (rank == 2) {      } else if (rank == 2) {
509          if (shape[1] < 3) {          if (index < 0) {
510                os << 0. << " " << 0. << " " << 0. << " ";
511                os << 0. << " " << 0. << " " << 0. << " ";
512                os << 0. << " " << 0. << " " << 0.;
513            } else if (shape[1] < 3) {
514              os << dataArray[0][index] << " " << dataArray[1][index]              os << dataArray[0][index] << " " << dataArray[1][index]
515                  << " " << 0. << " ";                  << " " << 0. << " ";
516              os << dataArray[2][index] << " " << dataArray[3][index]              os << dataArray[2][index] << " " << dataArray[3][index]
# Line 519  void DataVar::writeToVTK(ostream& os, in Line 538  void DataVar::writeToVTK(ostream& os, in
538    
539      if (isNodeCentered()) {      if (isNodeCentered()) {
540          // data was reordered in reorderSamples() but for VTK we write the          // data was reordered in reorderSamples() but for VTK we write the
541          // original node mesh and thus need the original ordering...          // original node mesh and thus need the original ordering.
542            // Note, that this also means we may not have samples for all nodes
543            // in which case we set idx to -1 and write a dummy sample
544          const IntVec& requiredIDs = domain->getNodes()->getNodeIDs();          const IntVec& requiredIDs = domain->getNodes()->getNodeIDs();
545          const IntVec& nodeGNI = domain->getNodes()->getGlobalNodeIndices();          const IntVec& nodeGNI = domain->getNodes()->getGlobalNodeIndices();
546          const IntVec& nodeDist = domain->getNodes()->getNodeDistribution();          const IntVec& nodeDist = domain->getNodes()->getNodeDistribution();
# Line 528  void DataVar::writeToVTK(ostream& os, in Line 549  void DataVar::writeToVTK(ostream& os, in
549          IndexMap sampleID2idx = buildIndexMap();          IndexMap sampleID2idx = buildIndexMap();
550          for (int i=0; i<nodeGNI.size(); i++) {          for (int i=0; i<nodeGNI.size(); i++) {
551              if (firstId <= nodeGNI[i] && nodeGNI[i] < lastId) {              if (firstId <= nodeGNI[i] && nodeGNI[i] < lastId) {
552                  int idx = sampleID2idx[requiredIDs[i]];                  IndexMap::const_iterator it = sampleID2idx.find(requiredIDs[i]);
553                    int idx = (it==sampleID2idx.end() ? -1 : (int)it->second);
554                  sampleToStream(os, idx);                  sampleToStream(os, idx);
555              }              }
556          }          }

Legend:
Removed from v.3357  
changed lines
  Added in v.3867

  ViewVC Help
Powered by ViewVC 1.1.26