/[escript]/trunk/weipa/src/DataVar.h
ViewVC logotype

Contents of /trunk/weipa/src/DataVar.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3143 - (show annotations)
Fri Sep 3 00:31:55 2010 UTC (8 years, 9 months ago) by caltinay
File MIME type: text/plain
File size: 5919 byte(s)
-Moved finley specifics into weipa subclasses
-EscriptDataset is now the only weipa class exported in Windows
-Some weipa code cleanup


1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14 #ifndef __WEIPA_DATAVAR_H__
15 #define __WEIPA_DATAVAR_H__
16
17 #include <weipa/DomainChunk.h>
18 #include <ostream>
19
20 class DBfile;
21 class NcFile;
22
23 namespace escript {
24 class Data;
25 }
26
27 namespace weipa {
28
29 /// \brief A class that provides functionality to read an escript data object
30 /// from a dump file or an escript::Data instance and write that data in Silo
31 /// or VTK XML formats.
32 class DataVar
33 {
34 public:
35 /// \brief Constructor with variable name
36 DataVar(const std::string& name);
37
38 /// \brief Copy constructor. Performs a deep copy of the data values.
39 DataVar(const DataVar& d);
40
41 /// \brief Destructor
42 ~DataVar();
43
44 /// \brief Initialises values and IDs from an escript::Data instance.
45 ///
46 /// \return true if a valid instance of expanded data was supplied,
47 /// false if the initialisation was unsuccessful.
48 bool initFromEscript(escript::Data& escriptData, const_DomainChunk_ptr dom);
49
50 /// \brief Initialises with integral mesh data like IDs or tags.
51 bool initFromMeshData(const_DomainChunk_ptr dom, const IntVec& data,
52 int fsCode, Centering c, NodeData_ptr nodes, const IntVec& id);
53
54 /// \brief Reads values and IDs for this variable from an escript dump
55 /// file.
56 ///
57 /// \return true if the file was found and contains valid escript data
58 /// with at least one sample, false otherwise.
59 /// \note Only expanded data with rank <=2 is supported at the moment.
60 bool initFromFile(const std::string& filename, const_DomainChunk_ptr dom);
61
62 /// \brief Writes the data into given directory within a Silo file.
63 ///
64 /// If Silo was not available at compile time this method returns false.
65 bool writeToSilo(DBfile* dbfile, const std::string& siloPath,
66 const std::string& units);
67
68 /// \brief Writes the data values to ostream in VTK text format.
69 void writeToVTK(std::ostream& os, int ownIndex);
70
71 /// \brief Returns the rank of the data.
72 int getRank() const { return rank; }
73
74 /// \brief Returns true if the variable data is node centered, false if
75 /// zone centered.
76 bool isNodeCentered() const;
77
78 /// \brief Returns the name of the associated mesh.
79 ///
80 /// The returned name is one of the sub-meshes of the mesh set with
81 /// setMesh() determined on the basis of the function space type and
82 /// whether reduced elements are used or not.
83 std::string getMeshName() const { return meshName; }
84
85 /// \brief Returns the shape vector of the data.
86 ///
87 /// The shape vector has as many elements as the rank of this variable.
88 const IntVec& getShape() const { return shape; }
89
90 /// \brief Returns the variable name.
91 std::string getName() const { return varName; }
92
93 /// \brief Returns the Silo tensor definition for this tensor.
94 ///
95 /// If the data is tensor data then the components of the tensor are stored
96 /// separately in the Silo file. This method then returns a string that
97 /// contains the proper Silo expression to put the tensor together again.
98 /// For non-tensor data this method returns an empty string.
99 std::string getTensorDef() const;
100
101 /// \brief Returns the number of data values.
102 int getNumberOfSamples() const { return numSamples; }
103
104 /// \brief Returns the array of data values where array[i] is the i-th
105 /// component of the data.
106 const CoordArray& getData() const { return dataArray; }
107
108 /// \brief Returns a flattened array of data values, i.e. the ordering is
109 /// s0c0 s0c1 s0c2 s1c0 s1c1 s1c2 s2c0 ...
110 /// where s denotes the sample number and c the component.
111 float* getDataFlat() const;
112
113 /// \brief Returns the total number of components (sum of shape elements).
114 int getNumberOfComponents() const;
115
116 private:
117 void cleanup();
118
119 /// \brief Averages and filters data.
120 ///
121 /// If a sample consists of more than one data point then this method
122 /// averages over the data points and returns the resulting array.
123 /// In any case, the data is filtered according to the stride value.
124 float* averageData(const float* src, size_t stride);
125
126 /// \brief Prepares a sample ID -> index mapping which is used to reorder
127 /// data.
128 IndexMap buildIndexMap();
129
130 /// \brief Reorders the samples according to the corresponding node or
131 /// element IDs.
132 ///
133 /// \return true if the function space is supported and the number of
134 /// elements or nodes matches the number of data samples.
135 bool reorderSamples();
136
137 /// \brief Outputs sample at index to output stream in VTK XML format
138 void sampleToStream(std::ostream& os, int index);
139
140 bool initialized;
141 const_DomainChunk_ptr domain;
142 std::string varName;
143 int numSamples, rank, ptsPerSample, funcSpace;
144 Centering centering;
145 IntVec shape;
146 IntVec sampleID;
147 CoordArray dataArray;
148 std::string meshName, siloMeshName;
149 };
150
151 inline IndexMap DataVar::buildIndexMap()
152 {
153 IndexMap sampleID2idx;
154 int idx = sampleID.size()-1;
155 // see this thread for why this is done the way it's done:
156 // http://www.tech-archive.net/Archive/VC/microsoft.public.vc.stl/2005-01/0075.html
157 IntVec::const_reverse_iterator idIt = sampleID.rbegin();
158 IntVec::const_reverse_iterator endIt = sampleID.rend();
159 for (; idIt != endIt; idIt++, idx--)
160 sampleID2idx[*idIt] = idx;
161
162 return sampleID2idx;
163 }
164
165 } // namespace weipa
166
167 #endif // __WEIPA_DATAVAR_H__
168

  ViewVC Help
Powered by ViewVC 1.1.26