ESYS13  Revision_
DataVar.h
Go to the documentation of this file.
00001 
00002 /*******************************************************
00003 *
00004 * Copyright (c) 2003-2012 by University of Queensland
00005 * Earth Systems Science Computational Center (ESSCC)
00006 * http://www.uq.edu.au/esscc
00007 *
00008 * Primary Business: Queensland, Australia
00009 * Licensed under the Open Software License version 3.0
00010 * http://www.opensource.org/licenses/osl-3.0.php
00011 *
00012 *******************************************************/
00013 
00014 #ifndef __WEIPA_DATAVAR_H__
00015 #define __WEIPA_DATAVAR_H__
00016 
00017 #include <weipa/DomainChunk.h>
00018 #include <ostream>
00019 
00020 class DBfile;
00021 class NcFile;
00022 
00023 namespace escript {
00024     class Data;
00025 }
00026 
00027 namespace weipa {
00028 
00032 class DataVar
00033 {
00034 public:
00036     DataVar(const std::string& name);
00037 
00039     DataVar(const DataVar& d);
00040 
00042     ~DataVar();
00043 
00048     bool initFromEscript(escript::Data& escriptData, const_DomainChunk_ptr dom);
00049 
00051     bool initFromMeshData(const_DomainChunk_ptr dom, const IntVec& data,
00052             int fsCode, Centering c, NodeData_ptr nodes, const IntVec& id);
00053 
00060     bool initFromFile(const std::string& filename, const_DomainChunk_ptr dom);
00061 
00065     bool writeToSilo(DBfile* dbfile, const std::string& siloPath,
00066                      const std::string& units);
00067 
00069     void writeToVTK(std::ostream& os, int ownIndex);
00070 
00072     int getRank() const { return rank; }
00073 
00076     bool isNodeCentered() const;
00077 
00083     std::string getMeshName() const { return meshName; }
00084 
00088     const IntVec& getShape() const { return shape; }
00089 
00091     std::string getName() const { return varName; }
00092 
00099     std::string getTensorDef() const;
00100 
00102     int getNumberOfSamples() const { return numSamples; }
00103 
00106     const CoordArray& getData() const { return dataArray; }
00107 
00111     float* getDataFlat() const;
00112 
00114     int getNumberOfComponents() const;
00115 
00116 private:
00117     void cleanup();
00118 
00124     float* averageData(const float* src, size_t stride);
00125 
00128     IndexMap buildIndexMap();
00129 
00135     bool reorderSamples();
00136 
00138     void sampleToStream(std::ostream& os, int index);
00139 
00140     bool initialized;
00141     const_DomainChunk_ptr domain;
00142     std::string varName;
00143     int numSamples, rank, ptsPerSample, funcSpace;
00144     Centering centering;
00145     IntVec shape;
00146     IntVec sampleID;
00147     CoordArray dataArray;
00148     std::string meshName, siloMeshName;
00149 };
00150 
00151 inline IndexMap DataVar::buildIndexMap()
00152 {
00153     IndexMap sampleID2idx;
00154     int idx = sampleID.size()-1;
00155     // see this thread for why this is done the way it's done:
00156     // http://www.tech-archive.net/Archive/VC/microsoft.public.vc.stl/2005-01/0075.html
00157     IntVec::const_reverse_iterator idIt = sampleID.rbegin();
00158     IntVec::const_reverse_iterator endIt = sampleID.rend();
00159     for (; idIt != endIt; idIt++, idx--)
00160         sampleID2idx[*idIt] = idx;
00161 
00162     return sampleID2idx;
00163 }
00164 
00165 } // namespace weipa
00166 
00167 #endif // __WEIPA_DATAVAR_H__
00168