escript  Revision_
DataVar.h
Go to the documentation of this file.
00001 
00002 /*****************************************************************************
00003 *
00004 * Copyright (c) 2003-2014 by University of Queensland
00005 * http://www.uq.edu.au
00006 *
00007 * Primary Business: Queensland, Australia
00008 * Licensed under the Open Software License version 3.0
00009 * http://www.opensource.org/licenses/osl-3.0.php
00010 *
00011 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
00012 * Development 2012-2013 by School of Earth Sciences
00013 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
00014 *
00015 *****************************************************************************/
00016 
00017 #ifndef __WEIPA_DATAVAR_H__
00018 #define __WEIPA_DATAVAR_H__
00019 
00020 #include <weipa/DomainChunk.h>
00021 #include <ostream>
00022 
00023 class DBfile;
00024 class NcFile;
00025 
00026 namespace escript {
00027     class Data;
00028 }
00029 
00030 namespace weipa {
00031 
00035 class DataVar
00036 {
00037 public:
00039     DataVar(const std::string& name);
00040 
00042     DataVar(const DataVar& d);
00043 
00045     ~DataVar();
00046 
00051     bool initFromEscript(escript::Data& escriptData, const_DomainChunk_ptr dom);
00052 
00054     bool initFromMeshData(const_DomainChunk_ptr dom, const IntVec& data,
00055             int fsCode, Centering c, NodeData_ptr nodes, const IntVec& id);
00056 
00063     bool initFromFile(const std::string& filename, const_DomainChunk_ptr dom);
00064 
00068     bool writeToSilo(DBfile* dbfile, const std::string& siloPath,
00069                      const std::string& units);
00070 
00072     void writeToVTK(std::ostream& os, int ownIndex);
00073 
00075     int getRank() const { return rank; }
00076 
00079     bool isNodeCentered() const;
00080 
00086     std::string getMeshName() const { return meshName; }
00087 
00091     const IntVec& getShape() const { return shape; }
00092 
00094     std::string getName() const { return varName; }
00095 
00102     std::string getTensorDef() const;
00103 
00105     int getNumberOfSamples() const { return numSamples; }
00106 
00109     const CoordArray& getData() const { return dataArray; }
00110 
00114     float* getDataFlat() const;
00115 
00117     int getNumberOfComponents() const;
00118 
00119 private:
00120     void cleanup();
00121 
00127     float* averageData(const float* src, size_t stride);
00128 
00131     IndexMap buildIndexMap();
00132 
00138     bool reorderSamples();
00139 
00141     void sampleToStream(std::ostream& os, int index);
00142 
00143     bool initialized;
00144     const_DomainChunk_ptr domain;
00145     std::string varName;
00146     int numSamples, rank, ptsPerSample, funcSpace;
00147     Centering centering;
00148     IntVec shape;
00149     IntVec sampleID;
00150     CoordArray dataArray;
00151     std::string meshName, siloMeshName;
00152 };
00153 
00154 inline IndexMap DataVar::buildIndexMap()
00155 {
00156     IndexMap sampleID2idx;
00157     int idx = sampleID.size()-1;
00158     // see this thread for why this is done the way it's done:
00159     // http://www.tech-archive.net/Archive/VC/microsoft.public.vc.stl/2005-01/0075.html
00160     IntVec::const_reverse_iterator idIt = sampleID.rbegin();
00161     IntVec::const_reverse_iterator endIt = sampleID.rend();
00162     for (; idIt != endIt; idIt++, idx--)
00163         sampleID2idx[*idIt] = idx;
00164 
00165     return sampleID2idx;
00166 }
00167 
00168 } // namespace weipa
00169 
00170 #endif // __WEIPA_DATAVAR_H__
00171