/[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 3142 by caltinay, Wed Sep 1 03:54:09 2010 UTC revision 3143 by caltinay, Fri Sep 3 00:31:55 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 33  using namespace std; Line 33  using namespace std;
33    
34  namespace weipa {  namespace weipa {
35            
 enum {  
     NODE_CENTERED = 1,  
     ZONE_CENTERED = 2  
 };  
   
36  //  //
37  // Constructor  // Constructor
38  //  //
39  DataVar::DataVar(const string& name) :  DataVar::DataVar(const string& name) :
40      initialized(false), varName(name),      initialized(false), varName(name),
41      numSamples(0), rank(0), ptsPerSample(0), centering(0)      numSamples(0), rank(0), ptsPerSample(0)
42  {  {
43  }  }
44    
# Line 51  DataVar::DataVar(const string& name) : Line 46  DataVar::DataVar(const string& name) :
46  // Copy constructor  // Copy constructor
47  //  //
48  DataVar::DataVar(const DataVar& d) :  DataVar::DataVar(const DataVar& d) :
49      initialized(d.initialized), finleyMesh(d.finleyMesh),      initialized(d.initialized), domain(d.domain),
50      varName(d.varName), numSamples(d.numSamples),      varName(d.varName), numSamples(d.numSamples),
51      rank(d.rank), ptsPerSample(d.ptsPerSample), centering(d.centering),      rank(d.rank), ptsPerSample(d.ptsPerSample), funcSpace(d.funcSpace),
52      funcSpace(d.funcSpace), shape(d.shape), sampleID(d.sampleID)      centering(d.centering), shape(d.shape), sampleID(d.sampleID)
53  {  {
54      if (numSamples > 0) {      if (numSamples > 0) {
55          CoordArray::const_iterator it;          CoordArray::const_iterator it;
# Line 92  void DataVar::cleanup() Line 87  void DataVar::cleanup()
87  //  //
88  //  //
89  //  //
90  bool DataVar::initFromEscript(escript::Data& escriptData, FinleyMesh_ptr mesh)  bool DataVar::initFromEscript(escript::Data& escriptData, const_DomainChunk_ptr dom)
91  {  {
92  #ifndef VISIT_PLUGIN  #ifndef VISIT_PLUGIN
93      cleanup();      cleanup();
# Line 102  bool DataVar::initFromEscript(escript::D Line 97  bool DataVar::initFromEscript(escript::D
97          return false;          return false;
98      }      }
99    
100      finleyMesh = mesh;      domain = dom;
101      rank = escriptData.getDataPointRank();      rank = escriptData.getDataPointRank();
102      ptsPerSample = escriptData.getNumDataPointsPerSample();      ptsPerSample = escriptData.getNumDataPointsPerSample();
103      shape = escriptData.getDataPointShape();      shape = escriptData.getDataPointShape();
104      funcSpace = escriptData.getFunctionSpace().getTypeCode();      funcSpace = escriptData.getFunctionSpace().getTypeCode();
105      numSamples = escriptData.getNumSamples();      numSamples = escriptData.getNumSamples();
106        centering = domain->getCenteringForFunctionSpace(funcSpace);
     if (funcSpace == FINLEY_REDUCED_NODES || funcSpace == FINLEY_NODES) {  
         centering = NODE_CENTERED;  
     } else {  
         centering = ZONE_CENTERED;  
     }  
107    
108  #ifdef _DEBUG  #ifdef _DEBUG
109      cout << varName << ":\t" << numSamples << " samples,  "      cout << varName << ":\t" << numSamples << " samples,  "
110          << ptsPerSample << " pts/s,  rank: " << rank << endl;          << ptsPerSample << " pts/s,  rank: " << rank << endl;
111  #endif  #endif
112    
113      NodeData_ptr nodes = finleyMesh->getMeshForFinleyFS(funcSpace);      NodeData_ptr nodes = domain->getMeshForFunctionSpace(funcSpace);
114      if (nodes == NULL)      if (nodes == NULL)
115          return false;          return false;
116    
# Line 175  bool DataVar::initFromEscript(escript::D Line 165  bool DataVar::initFromEscript(escript::D
165  }  }
166    
167  //  //
168  // Initialise with mesh data  // Initialise with domain data
169  //  //
170  bool DataVar::initFromMesh(FinleyMesh_ptr mesh)  bool DataVar::initFromMeshData(const_DomainChunk_ptr dom, const IntVec& data,
171            int fsCode, Centering c, NodeData_ptr nodes, const IntVec& id)
172  {  {
173      cleanup();      cleanup();
174            
175      finleyMesh = mesh;      domain = dom;
176      rank = 0;      rank = 0;
177      ptsPerSample = 1;      ptsPerSample = 1;
178      NodeData_ptr nodes;      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;  
     }  
   
179      meshName = nodes->getName();      meshName = nodes->getName();
180      siloMeshName = nodes->getFullSiloName();      siloMeshName = nodes->getFullSiloName();
   
     const IntVec& data = mesh->getVarDataByName(varName);  
181      numSamples = data.size();      numSamples = data.size();
182    
183      if (numSamples > 0) {      if (numSamples > 0) {
# Line 236  bool DataVar::initFromMesh(FinleyMesh_pt Line 193  bool DataVar::initFromMesh(FinleyMesh_pt
193  }  }
194    
195  //  //
196  // Reads variable data from NetCDF file  // Reads variable data from dump file
197  //  //
198  bool DataVar::initFromNetCDF(const string& filename, FinleyMesh_ptr mesh)  bool DataVar::initFromFile(const string& filename, const_DomainChunk_ptr dom)
199  {  {
200      cleanup();      cleanup();
201            
# Line 271  bool DataVar::initFromNetCDF(const strin Line 228  bool DataVar::initFromNetCDF(const strin
228      att = input->get_att("function_space_type");      att = input->get_att("function_space_type");
229      funcSpace = att->as_int(0);      funcSpace = att->as_int(0);
230    
231      if (funcSpace == FINLEY_REDUCED_NODES || funcSpace == FINLEY_NODES) {      centering = domain->getCenteringForFunctionSpace(funcSpace);
         centering = NODE_CENTERED;  
     } else {  
         centering = ZONE_CENTERED;  
     }  
232    
233      dim = input->get_dim("num_samples");      dim = input->get_dim("num_samples");
234      numSamples = dim->size();      numSamples = dim->size();
# Line 285  bool DataVar::initFromNetCDF(const strin Line 238  bool DataVar::initFromNetCDF(const strin
238          << ptsPerSample << " pts/s,  rank: " << rank << endl;          << ptsPerSample << " pts/s,  rank: " << rank << endl;
239  #endif  #endif
240    
241      finleyMesh = mesh;      domain = dom;
242      NodeData_ptr nodes = finleyMesh->getMeshForFinleyFS(funcSpace);      NodeData_ptr nodes = domain->getMeshForFunctionSpace(funcSpace);
243      if (nodes == NULL) {      if (nodes == NULL) {
244          delete input;          delete input;
245          return false;          return false;
# Line 370  float* DataVar::averageData(const float* Line 323  float* DataVar::averageData(const float*
323          for (int i=0; i<numSamples; i++, src+=stride)          for (int i=0; i<numSamples; i++, src+=stride)
324              *dest++ = *src;              *dest++ = *src;
325      } else {      } else {
326          ElementData_ptr cells = finleyMesh->getElementsForFinleyFS(funcSpace);          ElementData_ptr cells = domain->getElementsForFunctionSpace(funcSpace);
327          int cellFactor = cells->getElementFactor();          int cellFactor = cells->getElementFactor();
328          res = new float[cellFactor * numSamples];          res = new float[cellFactor * numSamples];
329          float* dest = res;          float* dest = res;
# Line 419  bool DataVar::reorderSamples() Line 372  bool DataVar::reorderSamples()
372      int cellFactor = 1;      int cellFactor = 1;
373    
374      if (centering == NODE_CENTERED) {      if (centering == NODE_CENTERED) {
375          NodeData_ptr nodes = finleyMesh->getMeshForFinleyFS(funcSpace);          NodeData_ptr nodes = domain->getMeshForFunctionSpace(funcSpace);
376          requiredIDs = &nodes->getNodeIDs();          requiredIDs = &nodes->getNodeIDs();
377          requiredNumSamples = nodes->getNumNodes();          requiredNumSamples = nodes->getNumNodes();
378      } else {      } else {
379          ElementData_ptr cells = finleyMesh->getElementsForFinleyFS(funcSpace);          ElementData_ptr cells = domain->getElementsForFunctionSpace(funcSpace);
380          if (cells == NULL)          if (cells == NULL)
381              return false;              return false;
382    
# Line 554  void DataVar::writeToVTK(ostream& os, in Line 507  void DataVar::writeToVTK(ostream& os, in
507      if (isNodeCentered()) {      if (isNodeCentered()) {
508          // data was reordered in reorderSamples() but for VTK we write the          // data was reordered in reorderSamples() but for VTK we write the
509          // original node mesh and thus need the original ordering...          // original node mesh and thus need the original ordering...
510          const IntVec& requiredIDs = finleyMesh->getNodes()->getNodeIDs();          const IntVec& requiredIDs = domain->getNodes()->getNodeIDs();
511          const IntVec& nodeGNI = finleyMesh->getNodes()->getGlobalNodeIndices();          const IntVec& nodeGNI = domain->getNodes()->getGlobalNodeIndices();
512          const IntVec& nodeDist = finleyMesh->getNodes()->getNodeDistribution();          const IntVec& nodeDist = domain->getNodes()->getNodeDistribution();
513          int firstId = nodeDist[ownIndex];          int firstId = nodeDist[ownIndex];
514          int lastId = nodeDist[ownIndex+1];          int lastId = nodeDist[ownIndex+1];
515          IndexMap sampleID2idx = buildIndexMap();          IndexMap sampleID2idx = buildIndexMap();
# Line 569  void DataVar::writeToVTK(ostream& os, in Line 522  void DataVar::writeToVTK(ostream& os, in
522      } else {      } else {
523          // cell data: ghost cells have been removed so do not write ghost          // cell data: ghost cells have been removed so do not write ghost
524          // samples (which are the last elements in the arrays)          // samples (which are the last elements in the arrays)
525          int toWrite =          int toWrite = domain->getElementsByName(meshName)->getNumElements();
             finleyMesh->getElementsByName(meshName)->getNumElements();  
526          for (int i=0; i<toWrite; i++) {          for (int i=0; i<toWrite; i++) {
527              sampleToStream(os, i);              sampleToStream(os, i);
528          }          }
# Line 627  string DataVar::getTensorDef() const Line 579  string DataVar::getTensorDef() const
579    
580  //  //
581  // Writes the data to given Silo file under the virtual path provided.  // Writes the data to given Silo file under the virtual path provided.
582  // 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().  
583  //  //
584  bool DataVar::writeToSilo(DBfile* dbfile, const string& siloPath,  bool DataVar::writeToSilo(DBfile* dbfile, const string& siloPath,
585                            const string& units)                            const string& units)

Legend:
Removed from v.3142  
changed lines
  Added in v.3143

  ViewVC Help
Powered by ViewVC 1.1.26