/[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 4657 by jfenwick, Thu Feb 6 06:12:20 2014 UTC
# Line 1  Line 1 
1    
2  /*******************************************************  /*****************************************************************************
3  *  *
4  * Copyright (c) 2003-2010 by University of Queensland  * Copyright (c) 2003-2014 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 2012-2013 by School of Earth Sciences
13    * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14    *
15    *****************************************************************************/
16    
17  #include <weipa/DataVar.h>  #include <weipa/DataVar.h>
18  #include <weipa/DomainChunk.h>  #include <weipa/DomainChunk.h>
# Line 139  bool DataVar::initFromEscript(escript::D Line 142  bool DataVar::initFromEscript(escript::D
142          initialized = false;          initialized = false;
143      }      }
144    
145        // special case: shape=(1,) or shape=(1,1) -> convert to scalar
146        if (dimSize==1 && rank>0) {
147            rank=0;
148            shape.clear();
149        }
150    
151      if (initialized) {      if (initialized) {
152          size_t dataSize = dimSize * ptsPerSample;          size_t dataSize = dimSize * ptsPerSample;
153          float* tempData = new float[dataSize*numSamples];          float* tempData = new float[dataSize*numSamples];
# Line 481  float* DataVar::getDataFlat() const Line 490  float* DataVar::getDataFlat() const
490  //  //
491  void DataVar::sampleToStream(ostream& os, int index)  void DataVar::sampleToStream(ostream& os, int index)
492  {  {
493        // index is -1 for dummy samples, i.e. if writing the full mesh but
494        // only a reduced number of samples is required
495      if (rank == 0) {      if (rank == 0) {
496          os << dataArray[0][index];          if (index < 0) {
497                os << 0.;
498            } else {
499                os << dataArray[0][index];
500            }
501      } else if (rank == 1) {      } else if (rank == 1) {
502          if (shape[0] < 3)          if (index < 0) {
503                os << 0. << " " << 0.  << " " << 0.;
504            } else if (shape[0] < 3) {
505              os << dataArray[0][index] << " " << dataArray[1][index]              os << dataArray[0][index] << " " << dataArray[1][index]
506                  << " " << 0.;                  << " " << 0.;
507          else          } else {
508              os << dataArray[0][index] << " " << dataArray[1][index]              os << dataArray[0][index] << " " << dataArray[1][index]
509                  << " " << dataArray[2][index];                  << " " << dataArray[2][index];
510            }
511      } else if (rank == 2) {      } else if (rank == 2) {
512          if (shape[1] < 3) {          if (index < 0) {
513                os << 0. << " " << 0. << " " << 0. << " ";
514                os << 0. << " " << 0. << " " << 0. << " ";
515                os << 0. << " " << 0. << " " << 0.;
516            } else if (shape[1] < 3) {
517              os << dataArray[0][index] << " " << dataArray[1][index]              os << dataArray[0][index] << " " << dataArray[1][index]
518                  << " " << 0. << " ";                  << " " << 0. << " ";
519              os << dataArray[2][index] << " " << dataArray[3][index]              os << dataArray[2][index] << " " << dataArray[3][index]
# Line 519  void DataVar::writeToVTK(ostream& os, in Line 541  void DataVar::writeToVTK(ostream& os, in
541    
542      if (isNodeCentered()) {      if (isNodeCentered()) {
543          // data was reordered in reorderSamples() but for VTK we write the          // data was reordered in reorderSamples() but for VTK we write the
544          // original node mesh and thus need the original ordering...          // original node mesh and thus need the original ordering.
545            // Note, that this also means we may not have samples for all nodes
546            // in which case we set idx to -1 and write a dummy sample
547          const IntVec& requiredIDs = domain->getNodes()->getNodeIDs();          const IntVec& requiredIDs = domain->getNodes()->getNodeIDs();
548          const IntVec& nodeGNI = domain->getNodes()->getGlobalNodeIndices();          const IntVec& nodeGNI = domain->getNodes()->getGlobalNodeIndices();
549          const IntVec& nodeDist = domain->getNodes()->getNodeDistribution();          const IntVec& nodeDist = domain->getNodes()->getNodeDistribution();
# Line 528  void DataVar::writeToVTK(ostream& os, in Line 552  void DataVar::writeToVTK(ostream& os, in
552          IndexMap sampleID2idx = buildIndexMap();          IndexMap sampleID2idx = buildIndexMap();
553          for (int i=0; i<nodeGNI.size(); i++) {          for (int i=0; i<nodeGNI.size(); i++) {
554              if (firstId <= nodeGNI[i] && nodeGNI[i] < lastId) {              if (firstId <= nodeGNI[i] && nodeGNI[i] < lastId) {
555                  int idx = sampleID2idx[requiredIDs[i]];                  IndexMap::const_iterator it = sampleID2idx.find(requiredIDs[i]);
556                    int idx = (it==sampleID2idx.end() ? -1 : (int)it->second);
557                  sampleToStream(os, idx);                  sampleToStream(os, idx);
558              }              }
559          }          }

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

  ViewVC Help
Powered by ViewVC 1.1.26