/[escript]/trunk/dataexporter/src/ElementData.h
ViewVC logotype

Contents of /trunk/dataexporter/src/ElementData.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2810 - (show annotations)
Mon Dec 7 04:13:49 2009 UTC (10 years, 11 months ago) by caltinay
File MIME type: text/plain
File size: 6573 byte(s)
Reincarnation of the escriptreader as a more flexible escriptexport library:
 - can be initialised with instances of escript::Data and Finley_Mesh
 - is now MPI aware at the EscriptDataset level including Silo writer
 - now uses boost shared pointers
The lib is currently only used by the escriptconvert tool but this is going to
change...

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2009 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 __ELEMENTDATA_H__
15 #define __ELEMENTDATA_H__
16
17 #include <escriptexport/escriptexport.h>
18 #include <finley/ReferenceElements.h> // for ElementTypeId
19
20 class DBfile;
21 class NcFile;
22
23 struct Finley_ElementFile;
24
25 namespace escriptexport {
26
27 class NodeData;
28
29 typedef enum {
30 ZONETYPE_BEAM=1,
31 ZONETYPE_HEX,
32 ZONETYPE_POLYGON,
33 ZONETYPE_QUAD,
34 ZONETYPE_TET,
35 ZONETYPE_TRIANGLE
36 } ZoneType;
37
38 /// \brief Holds information that is used to convert from finley element types
39 /// to elements supported by Silo and VTK.
40 struct FinleyElementInfo
41 {
42 ZoneType elementType, reducedElementType;
43 int elementFactor;
44 int elementSize, reducedElementSize;
45 const size_t* multiCellIndices;
46 };
47
48 /// \brief Stores and manipulates one type of finley mesh elements (cells,
49 /// faces or contacts).
50 ///
51 /// This class provides functionality to manipulate a finley element file.
52 /// It is able to load element data from NetCDF files or retrieve it from
53 /// a Finley_ElementFile instance.
54 ///
55 /// \note The corresponding mesh nodes are not part of this class but are
56 /// stored in a NodeData instance.
57 class ElementData
58 {
59 public:
60
61 /// \brief Constructor with name and accompanying NodeData object.
62 ESCRIPTEXPORT_DLL_API
63 ElementData(const std::string& elementName, NodeData_ptr nodes);
64
65 /// \brief Copy constructor
66 ESCRIPTEXPORT_DLL_API
67 ElementData(const ElementData& e);
68
69 /// \brief Initialises with data from a Finley_ElementFile instance.
70 ESCRIPTEXPORT_DLL_API
71 bool initFromFinley(const Finley_ElementFile* finleyFile);
72
73 /// \brief Destructor
74 ESCRIPTEXPORT_DLL_API
75 ~ElementData();
76
77 /// \brief Reads element data from escript/finley NetCDF file.
78 ESCRIPTEXPORT_DLL_API
79 bool readFromNc(NcFile* ncfile);
80
81 /// \brief Moves "ghost" elements (whose owner does not match ownIndex)
82 /// and the corresponding data to the end of the arrays.
83 ESCRIPTEXPORT_DLL_API
84 void reorderGhostZones(int ownIndex);
85
86 /// \brief Removes "ghost" elements.
87 ESCRIPTEXPORT_DLL_API
88 void removeGhostZones(int ownIndex);
89
90 /// \brief Writes element data into given directory in given Silo file.
91 ///
92 /// Since the mesh depends on element information this method also writes
93 /// the node mesh itself. If Silo was not available at compile time or if
94 /// a Silo function fails this method returns false.
95 ESCRIPTEXPORT_DLL_API
96 bool writeToSilo(DBfile* dbfile, const std::string& siloPath);
97
98 /// \brief Returns the names of the meshes associated with the elements.
99 ESCRIPTEXPORT_DLL_API
100 StringVec getMeshNames() const;
101
102 /// \brief Returns a vector with the mesh variable names.
103 ESCRIPTEXPORT_DLL_API
104 StringVec getVarNames() const;
105
106 /// \brief Returns the number of elements.
107 ESCRIPTEXPORT_DLL_API
108 int getNumElements() const { return numElements; }
109
110 /// \brief Returns the number of reduced elements.
111 ESCRIPTEXPORT_DLL_API
112 int getReducedNumElements() const { return reducedNumElements; }
113
114 /// \brief Returns the number of nodes per element.
115 ESCRIPTEXPORT_DLL_API
116 int getNodesPerElement() const { return nodesPerElement; }
117
118 /// \brief Returns the number of nodes per reduced element.
119 ESCRIPTEXPORT_DLL_API
120 int getReducedNodesPerElement() const { return reducedNodesPerElement; }
121
122 /// \brief Returns the number of "ghost" elements.
123 ESCRIPTEXPORT_DLL_API
124 int getGhostCount() const { return numGhostElements; }
125
126 /// \brief Returns the number of "ghost" reduced elements.
127 ESCRIPTEXPORT_DLL_API
128 int getReducedGhostCount() const { return numReducedGhostElements; }
129
130 /// \brief Returns the type of the elements.
131 ESCRIPTEXPORT_DLL_API
132 ZoneType getType() const { return type; }
133
134 /// \brief Returns the type of reduced elements.
135 ESCRIPTEXPORT_DLL_API
136 ZoneType getReducedType() const { return reducedType; }
137
138 /// \brief Returns a vector of the node IDs used by the elements.
139 ESCRIPTEXPORT_DLL_API
140 const IntVec& getNodeList() const { return nodes; }
141
142 /// \brief Returns a vector of the node IDs used by the reduced elements.
143 ESCRIPTEXPORT_DLL_API
144 const IntVec& getReducedNodeList() const { return reducedNodes; }
145
146 /// \brief Returns a vector of element IDs.
147 ESCRIPTEXPORT_DLL_API
148 const IntVec& getIDs() const { return ID; }
149
150 /// \brief Returns a mapping of element IDs to array index.
151 ESCRIPTEXPORT_DLL_API
152 IndexMap getIndexMap() const;
153
154 /// \brief Returns an array of data values for the name provided.
155 ///
156 /// The name must be one of the names returned from getVarNames().
157 ESCRIPTEXPORT_DLL_API
158 const IntVec& getVarDataByName(const std::string varName) const;
159
160 /// \brief Returns the node mesh instance used by the elements.
161 ESCRIPTEXPORT_DLL_API
162 NodeData_ptr getNodeMesh() const { return fullMesh; }
163
164 /// \brief Returns the node mesh instance used by the reduced elements.
165 ESCRIPTEXPORT_DLL_API
166 NodeData_ptr getReducedNodeMesh() const { return reducedMesh; }
167
168 private:
169 ElementData() {}
170 FinleyElementInfo getFinleyTypeInfo(ElementTypeId typeId);
171 void buildMeshes();
172 void buildReducedElements(const FinleyElementInfo& f);
173 void prepareGhostIndices(int ownIndex, IntVec& indexArray,
174 IntVec& reducedIndexArray);
175 void reorderArray(IntVec& v, const IntVec& idx, int elementsPerIndex);
176
177 std::string name;
178 int numElements, reducedNumElements;
179 int numGhostElements, numReducedGhostElements;
180 NodeData_ptr fullMesh;
181 NodeData_ptr reducedMesh;
182 NodeData_ptr originalNodes;
183 bool fullMeshIsOriginalMesh;
184
185 int numDims;
186 ZoneType type, reducedType;
187 int nodesPerElement, reducedNodesPerElement;
188 IntVec nodes, reducedNodes;
189 IntVec color, ID, tag;
190 IntVec owner, reducedOwner;
191 };
192
193
194 inline IndexMap ElementData::getIndexMap() const
195 {
196 IndexMap ID2idx;
197 size_t idx = 0;
198 IntVec::const_iterator idIt;
199 for (idIt = ID.begin(); idIt != ID.end(); idIt++, idx++)
200 ID2idx[*idIt] = idx;
201 return ID2idx;
202 }
203
204 } // namespace escriptexport
205
206 #endif // __ELEMENTDATA_H__
207

  ViewVC Help
Powered by ViewVC 1.1.26