/[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 3146 by caltinay, Fri Sep 3 01:29:21 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 28  Line 31 
31  #endif  #endif
32    
33  #include <numeric> // for accumulate  #include <numeric> // for accumulate
34    #include <iostream> // for cerr
35    #include <stdio.h>
36    
37  using namespace std;  using namespace std;
38    
# Line 92  bool DataVar::initFromEscript(escript::D Line 97  bool DataVar::initFromEscript(escript::D
97  #ifndef VISIT_PLUGIN  #ifndef VISIT_PLUGIN
98      cleanup();      cleanup();
99    
100      if (!escriptData.actsExpanded()) {      if (!escriptData.isConstant() && !escriptData.actsExpanded()) {
101          cerr << "WARNING: Only expanded data supported!" << endl;          cerr << "WARNING: Weipa only supports constant & expanded data, "
102                << "not initializing " << varName << endl;
103          return false;          return false;
104      }      }
105    
# Line 136  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];
154          float* destPtr = tempData;          float* destPtr = tempData;
155          for (int sampleNo=0; sampleNo<numSamples; sampleNo++) {          if (escriptData.isConstant()) {
156              const escript::DataAbstract::ValueType::value_type* values =              const escript::DataAbstract::ValueType::value_type* values =
157                  escriptData.getSampleDataRO(sampleNo);                  escriptData.getSampleDataRO(0);
158              copy(values, values+dataSize, destPtr);              for (int pointNo=0; pointNo<numSamples*ptsPerSample; pointNo++) {
159              destPtr += dataSize;                  copy(values, values+dimSize, destPtr);
160                    destPtr += dimSize;
161                }
162            } else {
163                for (int sampleNo=0; sampleNo<numSamples; sampleNo++) {
164                    const escript::DataAbstract::ValueType::value_type* values =
165                        escriptData.getSampleDataRO(sampleNo);
166                    copy(values, values+dataSize, destPtr);
167                    destPtr += dataSize;
168                }
169          }          }
170    
171          const float* srcPtr = tempData;          const float* srcPtr = tempData;
# Line 229  bool DataVar::initFromFile(const string& Line 250  bool DataVar::initFromFile(const string&
250      att = input->get_att("function_space_type");      att = input->get_att("function_space_type");
251      funcSpace = att->as_int(0);      funcSpace = att->as_int(0);
252    
253      centering = domain->getCenteringForFunctionSpace(funcSpace);      centering = dom->getCenteringForFunctionSpace(funcSpace);
254    
255      dim = input->get_dim("num_samples");      dim = input->get_dim("num_samples");
256      numSamples = dim->size();      numSamples = dim->size();
# Line 469  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 507  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 516  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.3146  
changed lines
  Added in v.4657

  ViewVC Help
Powered by ViewVC 1.1.26