/[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 3128 by caltinay, Wed Sep 1 03:54:09 2010 UTC revision 3357 by caltinay, Wed Nov 17 06:21:37 2010 UTC
# Line 12  Line 12 
12  *******************************************************/  *******************************************************/
13    
14  #include <weipa/DataVar.h>  #include <weipa/DataVar.h>
15    #include <weipa/DomainChunk.h>
16  #include <weipa/ElementData.h>  #include <weipa/ElementData.h>
 #include <weipa/FinleyMesh.h>  
17  #include <weipa/NodeData.h>  #include <weipa/NodeData.h>
18  #ifndef VISIT_PLUGIN  #ifndef VISIT_PLUGIN
19  #include <escript/Data.h>  #include <escript/Data.h>
# Line 28  Line 28 
28  #endif  #endif
29    
30  #include <numeric> // for accumulate  #include <numeric> // for accumulate
31    #include <iostream> // for cerr
32    #include <stdio.h>
33    
34  using namespace std;  using namespace std;
35    
36  namespace weipa {  namespace weipa {
37            
 enum {  
     NODE_CENTERED = 1,  
     ZONE_CENTERED = 2  
 };  
   
38  //  //
39  // Constructor  // Constructor
40  //  //
41  DataVar::DataVar(const string& name) :  DataVar::DataVar(const string& name) :
42      initialized(false), varName(name),      initialized(false), varName(name),
43      numSamples(0), rank(0), ptsPerSample(0), centering(0)      numSamples(0), rank(0), ptsPerSample(0)
44  {  {
45  }  }
46    
# Line 51  DataVar::DataVar(const string& name) : Line 48  DataVar::DataVar(const string& name) :
48  // Copy constructor  // Copy constructor
49  //  //
50  DataVar::DataVar(const DataVar& d) :  DataVar::DataVar(const DataVar& d) :
51      initialized(d.initialized), finleyMesh(d.finleyMesh),      initialized(d.initialized), domain(d.domain),
52      varName(d.varName), numSamples(d.numSamples),      varName(d.varName), numSamples(d.numSamples),
53      rank(d.rank), ptsPerSample(d.ptsPerSample), centering(d.centering),      rank(d.rank), ptsPerSample(d.ptsPerSample), funcSpace(d.funcSpace),
54      funcSpace(d.funcSpace), shape(d.shape), sampleID(d.sampleID)      centering(d.centering), shape(d.shape), sampleID(d.sampleID)
55  {  {
56      if (numSamples > 0) {      if (numSamples > 0) {
57          CoordArray::const_iterator it;          CoordArray::const_iterator it;
# Line 92  void DataVar::cleanup() Line 89  void DataVar::cleanup()
89  //  //
90  //  //
91  //  //
92  bool DataVar::initFromEscript(escript::Data& escriptData, FinleyMesh_ptr mesh)  bool DataVar::initFromEscript(escript::Data& escriptData, const_DomainChunk_ptr dom)
93  {  {
94  #ifndef VISIT_PLUGIN  #ifndef VISIT_PLUGIN
95      cleanup();      cleanup();
96    
97      if (!escriptData.actsExpanded()) {      if (!escriptData.isConstant() && !escriptData.actsExpanded()) {
98          cerr << "WARNING: Only expanded data supported!" << endl;          cerr << "WARNING: Weipa only supports constant & expanded data, "
99                << "not initializing " << varName << endl;
100          return false;          return false;
101      }      }
102    
103      finleyMesh = mesh;      domain = dom;
104      rank = escriptData.getDataPointRank();      rank = escriptData.getDataPointRank();
105      ptsPerSample = escriptData.getNumDataPointsPerSample();      ptsPerSample = escriptData.getNumDataPointsPerSample();
106      shape = escriptData.getDataPointShape();      shape = escriptData.getDataPointShape();
107      funcSpace = escriptData.getFunctionSpace().getTypeCode();      funcSpace = escriptData.getFunctionSpace().getTypeCode();
108      numSamples = escriptData.getNumSamples();      numSamples = escriptData.getNumSamples();
109        centering = domain->getCenteringForFunctionSpace(funcSpace);
     if (funcSpace == FINLEY_REDUCED_NODES || funcSpace == FINLEY_NODES) {  
         centering = NODE_CENTERED;  
     } else {  
         centering = ZONE_CENTERED;  
     }  
110    
111  #ifdef _DEBUG  #ifdef _DEBUG
112      cout << varName << ":\t" << numSamples << " samples,  "      cout << varName << ":\t" << numSamples << " samples,  "
113          << ptsPerSample << " pts/s,  rank: " << rank << endl;          << ptsPerSample << " pts/s,  rank: " << rank << endl;
114  #endif  #endif
115    
116      NodeData_ptr nodes = finleyMesh->getMeshForFinleyFS(funcSpace);      NodeData_ptr nodes = domain->getMeshForFunctionSpace(funcSpace);
117      if (nodes == NULL)      if (nodes == NULL)
118          return false;          return false;
119    
# Line 150  bool DataVar::initFromEscript(escript::D Line 143  bool DataVar::initFromEscript(escript::D
143          size_t dataSize = dimSize * ptsPerSample;          size_t dataSize = dimSize * ptsPerSample;
144          float* tempData = new float[dataSize*numSamples];          float* tempData = new float[dataSize*numSamples];
145          float* destPtr = tempData;          float* destPtr = tempData;
146          for (int sampleNo=0; sampleNo<numSamples; sampleNo++) {          if (escriptData.isConstant()) {
147              const escript::DataAbstract::ValueType::value_type* values =              const escript::DataAbstract::ValueType::value_type* values =
148                  escriptData.getSampleDataRO(sampleNo);                  escriptData.getSampleDataRO(0);
149              copy(values, values+dataSize, destPtr);              for (int pointNo=0; pointNo<numSamples*ptsPerSample; pointNo++) {
150              destPtr += dataSize;                  copy(values, values+dimSize, destPtr);
151                    destPtr += dimSize;
152                }
153            } else {
154                for (int sampleNo=0; sampleNo<numSamples; sampleNo++) {
155                    const escript::DataAbstract::ValueType::value_type* values =
156                        escriptData.getSampleDataRO(sampleNo);
157                    copy(values, values+dataSize, destPtr);
158                    destPtr += dataSize;
159                }
160          }          }
161    
162          const float* srcPtr = tempData;          const float* srcPtr = tempData;
# Line 175  bool DataVar::initFromEscript(escript::D Line 177  bool DataVar::initFromEscript(escript::D
177  }  }
178    
179  //  //
180  // Initialise with mesh data  // Initialise with domain data
181  //  //
182  bool DataVar::initFromMesh(FinleyMesh_ptr mesh)  bool DataVar::initFromMeshData(const_DomainChunk_ptr dom, const IntVec& data,
183            int fsCode, Centering c, NodeData_ptr nodes, const IntVec& id)
184  {  {
185      cleanup();      cleanup();
186            
187      finleyMesh = mesh;      domain = dom;
188      rank = 0;      rank = 0;
189      ptsPerSample = 1;      ptsPerSample = 1;
190      NodeData_ptr nodes;      centering = c;
191        sampleID = id;
     if (varName.find("ContactElements_") != varName.npos) {  
         funcSpace = FINLEY_CONTACT_ELEMENTS_1;  
         centering = ZONE_CENTERED;  
         string elementName = varName.substr(0, varName.find('_'));  
         ElementData_ptr elements = mesh->getElementsByName(elementName);  
         nodes = elements->getNodeMesh();  
         sampleID = elements->getIDs();  
     } else if (varName.find("FaceElements_") != varName.npos) {  
         funcSpace = FINLEY_FACE_ELEMENTS;  
         centering = ZONE_CENTERED;  
         string elementName = varName.substr(0, varName.find('_'));  
         ElementData_ptr elements = mesh->getElementsByName(elementName);  
         nodes = elements->getNodeMesh();  
         sampleID = elements->getIDs();  
     } else if (varName.find("Elements_") != varName.npos) {  
         funcSpace = FINLEY_ELEMENTS;  
         centering = ZONE_CENTERED;  
         string elementName = varName.substr(0, varName.find('_'));  
         ElementData_ptr elements = mesh->getElementsByName(elementName);  
         nodes = elements->getNodeMesh();  
         sampleID = elements->getIDs();  
     } else if (varName.find("Nodes_") != varName.npos) {  
         funcSpace = FINLEY_NODES;  
         centering = NODE_CENTERED;  
         nodes = mesh->getNodes();  
         sampleID = nodes->getNodeIDs();  
     } else {  
         cerr << "WARNING: Unrecognized mesh variable '" << varName << "'\n";  
         return false;  
     }  
   
192      meshName = nodes->getName();      meshName = nodes->getName();
193      siloMeshName = nodes->getFullSiloName();      siloMeshName = nodes->getFullSiloName();
   
     const IntVec& data = mesh->getVarDataByName(varName);  
194      numSamples = data.size();      numSamples = data.size();
195    
196      if (numSamples > 0) {      if (numSamples > 0) {
# Line 236  bool DataVar::initFromMesh(FinleyMesh_pt Line 206  bool DataVar::initFromMesh(FinleyMesh_pt
206  }  }
207    
208  //  //
209  // Reads variable data from NetCDF file  // Reads variable data from dump file
210  //  //
211  bool DataVar::initFromNetCDF(const string& filename, FinleyMesh_ptr mesh)  bool DataVar::initFromFile(const string& filename, const_DomainChunk_ptr dom)
212  {  {
213      cleanup();      cleanup();
214            
# Line 271  bool DataVar::initFromNetCDF(const strin Line 241  bool DataVar::initFromNetCDF(const strin
241      att = input->get_att("function_space_type");      att = input->get_att("function_space_type");
242      funcSpace = att->as_int(0);      funcSpace = att->as_int(0);
243    
244      if (funcSpace == FINLEY_REDUCED_NODES || funcSpace == FINLEY_NODES) {      centering = dom->getCenteringForFunctionSpace(funcSpace);
         centering = NODE_CENTERED;  
     } else {  
         centering = ZONE_CENTERED;  
     }  
245    
246      dim = input->get_dim("num_samples");      dim = input->get_dim("num_samples");
247      numSamples = dim->size();      numSamples = dim->size();
# Line 285  bool DataVar::initFromNetCDF(const strin Line 251  bool DataVar::initFromNetCDF(const strin
251          << ptsPerSample << " pts/s,  rank: " << rank << endl;          << ptsPerSample << " pts/s,  rank: " << rank << endl;
252  #endif  #endif
253    
254      finleyMesh = mesh;      domain = dom;
255      NodeData_ptr nodes = finleyMesh->getMeshForFinleyFS(funcSpace);      NodeData_ptr nodes = domain->getMeshForFunctionSpace(funcSpace);
256      if (nodes == NULL) {      if (nodes == NULL) {
257          delete input;          delete input;
258          return false;          return false;
# Line 370  float* DataVar::averageData(const float* Line 336  float* DataVar::averageData(const float*
336          for (int i=0; i<numSamples; i++, src+=stride)          for (int i=0; i<numSamples; i++, src+=stride)
337              *dest++ = *src;              *dest++ = *src;
338      } else {      } else {
339          ElementData_ptr cells = finleyMesh->getElementsForFinleyFS(funcSpace);          ElementData_ptr cells = domain->getElementsForFunctionSpace(funcSpace);
340          int cellFactor = cells->getElementFactor();          int cellFactor = cells->getElementFactor();
341          res = new float[cellFactor * numSamples];          res = new float[cellFactor * numSamples];
342          float* dest = res;          float* dest = res;
# Line 419  bool DataVar::reorderSamples() Line 385  bool DataVar::reorderSamples()
385      int cellFactor = 1;      int cellFactor = 1;
386    
387      if (centering == NODE_CENTERED) {      if (centering == NODE_CENTERED) {
388          NodeData_ptr nodes = finleyMesh->getMeshForFinleyFS(funcSpace);          NodeData_ptr nodes = domain->getMeshForFunctionSpace(funcSpace);
389          requiredIDs = &nodes->getNodeIDs();          requiredIDs = &nodes->getNodeIDs();
390          requiredNumSamples = nodes->getNumNodes();          requiredNumSamples = nodes->getNumNodes();
391      } else {      } else {
392          ElementData_ptr cells = finleyMesh->getElementsForFinleyFS(funcSpace);          ElementData_ptr cells = domain->getElementsForFunctionSpace(funcSpace);
393          if (cells == NULL)          if (cells == NULL)
394              return false;              return false;
395    
# Line 554  void DataVar::writeToVTK(ostream& os, in Line 520  void DataVar::writeToVTK(ostream& os, in
520      if (isNodeCentered()) {      if (isNodeCentered()) {
521          // data was reordered in reorderSamples() but for VTK we write the          // data was reordered in reorderSamples() but for VTK we write the
522          // original node mesh and thus need the original ordering...          // original node mesh and thus need the original ordering...
523          const IntVec& requiredIDs = finleyMesh->getNodes()->getNodeIDs();          const IntVec& requiredIDs = domain->getNodes()->getNodeIDs();
524          const IntVec& nodeGNI = finleyMesh->getNodes()->getGlobalNodeIndices();          const IntVec& nodeGNI = domain->getNodes()->getGlobalNodeIndices();
525          const IntVec& nodeDist = finleyMesh->getNodes()->getNodeDistribution();          const IntVec& nodeDist = domain->getNodes()->getNodeDistribution();
526          int firstId = nodeDist[ownIndex];          int firstId = nodeDist[ownIndex];
527          int lastId = nodeDist[ownIndex+1];          int lastId = nodeDist[ownIndex+1];
528          IndexMap sampleID2idx = buildIndexMap();          IndexMap sampleID2idx = buildIndexMap();
# Line 569  void DataVar::writeToVTK(ostream& os, in Line 535  void DataVar::writeToVTK(ostream& os, in
535      } else {      } else {
536          // cell data: ghost cells have been removed so do not write ghost          // cell data: ghost cells have been removed so do not write ghost
537          // samples (which are the last elements in the arrays)          // samples (which are the last elements in the arrays)
538          int toWrite =          int toWrite = domain->getElementsByName(meshName)->getNumElements();
             finleyMesh->getElementsByName(meshName)->getNumElements();  
539          for (int i=0; i<toWrite; i++) {          for (int i=0; i<toWrite; i++) {
540              sampleToStream(os, i);              sampleToStream(os, i);
541          }          }
# Line 627  string DataVar::getTensorDef() const Line 592  string DataVar::getTensorDef() const
592    
593  //  //
594  // Writes the data to given Silo file under the virtual path provided.  // Writes the data to given Silo file under the virtual path provided.
595  // The corresponding mesh must have been written already and made known  // The corresponding mesh must have been written already.
 // to this variable by a call to setMesh().  
596  //  //
597  bool DataVar::writeToSilo(DBfile* dbfile, const string& siloPath,  bool DataVar::writeToSilo(DBfile* dbfile, const string& siloPath,
598                            const string& units)                            const string& units)

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

  ViewVC Help
Powered by ViewVC 1.1.26