/[escript]/branches/split/weipa/src/DataVar.h
ViewVC logotype

Contents of /branches/split/weipa/src/DataVar.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4724 - (show annotations)
Thu Mar 6 05:22:12 2014 UTC (5 years, 1 month ago) by jfenwick
File MIME type: text/plain
File size: 6106 byte(s)
Work towards parallel domains

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

  ViewVC Help
Powered by ViewVC 1.1.26