/[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 2880 by caltinay, Thu Jan 28 01:21:30 2010 UTC revision 2888 by caltinay, Fri Jan 29 00:07:00 2010 UTC
# Line 1  Line 1 
1    
2  /*******************************************************  /*******************************************************
3  *  *
4  * Copyright (c) 2003-2009 by University of Queensland  * Copyright (c) 2003-2010 by University of Queensland
5  * Earth Systems Science Computational Center (ESSCC)  * Earth Systems Science Computational Center (ESSCC)
6  * http://www.uq.edu.au/esscc  * http://www.uq.edu.au/esscc
7  *  *
# Line 18  Line 18 
18  #include <escript/Data.h>  #include <escript/Data.h>
19    
20  #if USE_NETCDF  #if USE_NETCDF
21  #include <netcdf.hh>  #include <netcdfcpp.h>
22  #endif  #endif
23    
24  #if USE_SILO  #if USE_SILO
# Line 463  bool DataVar::reorderSamples() Line 463  bool DataVar::reorderSamples()
463      return true;      return true;
464  }  }
465    
466    //
467    //
468    //
469    void DataVar::sampleToStream(ostream& os, int index)
470    {
471        if (rank == 0) {
472            os << dataArray[0][index];
473        } else if (rank == 1) {
474            if (shape[0] < 3)
475                os << dataArray[0][index] << " " << dataArray[1][index]
476                    << " " << 0.;
477            else
478                os << dataArray[0][index] << " " << dataArray[1][index]
479                    << " " << dataArray[2][index];
480        } else if (rank == 2) {
481            if (shape[1] < 3) {
482                os << dataArray[0][index] << " " << dataArray[1][index]
483                    << " " << 0. << " ";
484                os << dataArray[2][index] << " " << dataArray[3][index]
485                    << " " << 0. << " ";
486                os << 0. << " " << 0. << " " << 0.;
487            } else {
488                os << dataArray[0][index] << " " << dataArray[1][index]
489                    << " " << dataArray[2][index] << " ";
490                os << dataArray[3][index] << " " << dataArray[4][index]
491                    << " " << dataArray[5][index] << " ";
492                os << dataArray[6][index] << " " << dataArray[7][index]
493                    << " " << dataArray[8][index];
494            }
495        }
496        os << endl;
497    }
498    
499    //
500    //
501    //
502    void DataVar::writeToVTK(ostream& os, int ownIndex)
503    {
504        if (numSamples == 0)
505            return;
506    
507        if (isNodeCentered()) {
508            // data was reordered in reorderSamples() but for VTK we write the
509            // original node mesh and thus need the original ordering...
510            const IntVec& requiredIDs = finleyMesh->getNodes()->getNodeIDs();
511            const IntVec& nodeGNI = finleyMesh->getNodes()->getGlobalNodeIndices();
512            const IntVec& nodeDist = finleyMesh->getNodes()->getNodeDistribution();
513            int firstId = nodeDist[ownIndex];
514            int lastId = nodeDist[ownIndex+1];
515            IndexMap sampleID2idx = buildIndexMap();
516            for (int i=0; i<nodeGNI.size(); i++) {
517                if (firstId <= nodeGNI[i] && nodeGNI[i] < lastId) {
518                    int idx = sampleID2idx[requiredIDs[i]];
519                    sampleToStream(os, idx);
520                }
521            }
522        } else {
523            // cell data: ghost cells have been removed so do not write ghost
524            // samples (which are the last elements in the arrays)
525            int toWrite =
526                finleyMesh->getElementsByName(meshName)->getNumElements();
527            for (int i=0; i<toWrite; i++) {
528                sampleToStream(os, i);
529            }
530        }
531    }
532    
533  ///////////////////////////////  ///////////////////////////////
534  // SILO related methods follow  // SILO related methods follow
535  ///////////////////////////////  ///////////////////////////////

Legend:
Removed from v.2880  
changed lines
  Added in v.2888

  ViewVC Help
Powered by ViewVC 1.1.26