/[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 3981 by jfenwick, Fri Sep 21 02:47:54 2012 UTC
# Line 1  Line 1 
1    
2  /*******************************************************  /*****************************************************************************
3  *  *
4  * Copyright (c) 2003-2010 by University of Queensland  * Copyright (c) 2003-2012 by University of Queensland
5  * Earth Systems Science Computational Center (ESSCC)  * http://www.uq.edu.au
 * http://www.uq.edu.au/esscc  
6  *  *
7  * Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
8  * Licensed under the Open Software License version 3.0  * Licensed under the Open Software License version 3.0
9  * http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
10  *  *
11  *******************************************************/  * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12    * Development since 2012 by School of Earth Sciences
13    *
14    *****************************************************************************/
15    
16  #include <weipa/DataVar.h>  #include <weipa/DataVar.h>
17  #include <weipa/DomainChunk.h>  #include <weipa/DomainChunk.h>
# Line 139  bool DataVar::initFromEscript(escript::D Line 141  bool DataVar::initFromEscript(escript::D
141          initialized = false;          initialized = false;
142      }      }
143    
144        // special case: shape=(1,) or shape=(1,1) -> convert to scalar
145        if (dimSize==1 && rank>0) {
146            rank=0;
147            shape.clear();
148        }
149    
150      if (initialized) {      if (initialized) {
151          size_t dataSize = dimSize * ptsPerSample;          size_t dataSize = dimSize * ptsPerSample;
152          float* tempData = new float[dataSize*numSamples];          float* tempData = new float[dataSize*numSamples];
# Line 481  float* DataVar::getDataFlat() const Line 489  float* DataVar::getDataFlat() const
489  //  //
490  void DataVar::sampleToStream(ostream& os, int index)  void DataVar::sampleToStream(ostream& os, int index)
491  {  {
492        // index is -1 for dummy samples, i.e. if writing the full mesh but
493        // only a reduced number of samples is required
494      if (rank == 0) {      if (rank == 0) {
495          os << dataArray[0][index];          if (index < 0) {
496                os << 0.;
497            } else {
498                os << dataArray[0][index];
499            }
500      } else if (rank == 1) {      } else if (rank == 1) {
501          if (shape[0] < 3)          if (index < 0) {
502                os << 0. << " " << 0.  << " " << 0.;
503            } else if (shape[0] < 3) {
504              os << dataArray[0][index] << " " << dataArray[1][index]              os << dataArray[0][index] << " " << dataArray[1][index]
505                  << " " << 0.;                  << " " << 0.;
506          else          } else {
507              os << dataArray[0][index] << " " << dataArray[1][index]              os << dataArray[0][index] << " " << dataArray[1][index]
508                  << " " << dataArray[2][index];                  << " " << dataArray[2][index];
509            }
510      } else if (rank == 2) {      } else if (rank == 2) {
511          if (shape[1] < 3) {          if (index < 0) {
512                os << 0. << " " << 0. << " " << 0. << " ";
513                os << 0. << " " << 0. << " " << 0. << " ";
514                os << 0. << " " << 0. << " " << 0.;
515            } else if (shape[1] < 3) {
516              os << dataArray[0][index] << " " << dataArray[1][index]              os << dataArray[0][index] << " " << dataArray[1][index]
517                  << " " << 0. << " ";                  << " " << 0. << " ";
518              os << dataArray[2][index] << " " << dataArray[3][index]              os << dataArray[2][index] << " " << dataArray[3][index]
# Line 519  void DataVar::writeToVTK(ostream& os, in Line 540  void DataVar::writeToVTK(ostream& os, in
540    
541      if (isNodeCentered()) {      if (isNodeCentered()) {
542          // data was reordered in reorderSamples() but for VTK we write the          // data was reordered in reorderSamples() but for VTK we write the
543          // original node mesh and thus need the original ordering...          // original node mesh and thus need the original ordering.
544            // Note, that this also means we may not have samples for all nodes
545            // in which case we set idx to -1 and write a dummy sample
546          const IntVec& requiredIDs = domain->getNodes()->getNodeIDs();          const IntVec& requiredIDs = domain->getNodes()->getNodeIDs();
547          const IntVec& nodeGNI = domain->getNodes()->getGlobalNodeIndices();          const IntVec& nodeGNI = domain->getNodes()->getGlobalNodeIndices();
548          const IntVec& nodeDist = domain->getNodes()->getNodeDistribution();          const IntVec& nodeDist = domain->getNodes()->getNodeDistribution();
# Line 528  void DataVar::writeToVTK(ostream& os, in Line 551  void DataVar::writeToVTK(ostream& os, in
551          IndexMap sampleID2idx = buildIndexMap();          IndexMap sampleID2idx = buildIndexMap();
552          for (int i=0; i<nodeGNI.size(); i++) {          for (int i=0; i<nodeGNI.size(); i++) {
553              if (firstId <= nodeGNI[i] && nodeGNI[i] < lastId) {              if (firstId <= nodeGNI[i] && nodeGNI[i] < lastId) {
554                  int idx = sampleID2idx[requiredIDs[i]];                  IndexMap::const_iterator it = sampleID2idx.find(requiredIDs[i]);
555                    int idx = (it==sampleID2idx.end() ? -1 : (int)it->second);
556                  sampleToStream(os, idx);                  sampleToStream(os, idx);
557              }              }
558          }          }

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

  ViewVC Help
Powered by ViewVC 1.1.26