-
Notifications
You must be signed in to change notification settings - Fork 49
/
UnstructuredGrid.cpp
241 lines (196 loc) · 8.47 KB
/
UnstructuredGrid.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#include <iostream>
#include <vector>
#include "vapor/VAssert.h"
#include <cmath>
#include <cassert>
#include <time.h>
#ifdef Darwin
#include <mach/mach_time.h>
#endif
#ifdef _WINDOWS
#include "windows.h"
#include "Winbase.h"
#include <limits>
#endif
#include <vapor/utils.h>
#include <vapor/UnstructuredGrid.h>
using namespace std;
using namespace VAPoR;
void UnstructuredGrid::_unstructuredGrid(const DimsType &vertexDims, const DimsType &faceDims, const DimsType &edgeDims, const DimsType &bs, const std::vector<float *> &blks,
size_t topology_dimension, const int *vertexOnFace, const int *faceOnVertex, const int *faceOnFace,
Location location, // node,face, edge
size_t maxVertexPerFace, size_t maxFacePerVertex, long nodeOffset, long cellOffset)
{
// vertexDims can be 0 in the case of a single-particle dataset since vapor considers length 1 topological data-dimensions as not contributing to the grids topological dimension
VAssert(GetNumDimensions(vertexDims) == 0 || GetNumDimensions(vertexDims) == 1 || GetNumDimensions(vertexDims) == 2);
VAssert(GetNumDimensions(vertexDims) == GetNumDimensions(faceDims));
VAssert((GetNumDimensions(vertexDims) == GetNumDimensions(edgeDims)) || (GetNumDimensions(edgeDims) == 0));
// Edge data not supported yet
//
VAssert(location == NODE || location == CELL);
_vertexDims = vertexDims;
_faceDims = faceDims;
_edgeDims = edgeDims;
_nDims = GetNumDimensions(vertexDims);
//
// Shallow copy raw pointers
//
_vertexOnFace = vertexOnFace;
_faceOnVertex = faceOnVertex;
_faceOnFace = faceOnFace;
_location = location;
_maxVertexPerFace = maxVertexPerFace;
_maxFacePerVertex = maxFacePerVertex;
_missingID = -1;
_boundaryID = -2;
Grid::SetNodeOffset(nodeOffset);
Grid::SetCellOffset(cellOffset);
}
UnstructuredGrid::UnstructuredGrid(const DimsType &vertexDims, const DimsType &faceDims, const DimsType &edgeDims, const DimsType &bs, const std::vector<float *> &blks, size_t topology_dimension,
const int *vertexOnFace, const int *faceOnVertex, const int *faceOnFace,
Location location, // node,face, edge
size_t maxVertexPerFace, size_t maxFacePerVertex, long nodeOffset, long cellOffset)
: Grid(location == NODE ? vertexDims : (location == CELL ? faceDims : edgeDims), bs, blks, topology_dimension)
{
_unstructuredGrid(vertexDims, faceDims, edgeDims, bs, blks, topology_dimension, vertexOnFace, faceOnVertex, faceOnFace, location, maxVertexPerFace, maxFacePerVertex, nodeOffset, cellOffset);
}
UnstructuredGrid::UnstructuredGrid(const std::vector<size_t> &vertexDimsv, const std::vector<size_t> &faceDimsv, const std::vector<size_t> &edgeDimsv, const std::vector<size_t> &bsv,
const std::vector<float *> &blks, size_t topology_dimension, const int *vertexOnFace, const int *faceOnVertex, const int *faceOnFace,
Location location, // node,face, edge
size_t maxVertexPerFace, size_t maxFacePerVertex, long nodeOffset, long cellOffset)
: Grid(location == NODE ? vertexDimsv : (location == CELL ? faceDimsv : edgeDimsv), bsv, blks, topology_dimension)
{
DimsType vertexDims = {1, 1, 1};
DimsType faceDims = {1, 1, 1};
DimsType edgeDims = {1, 1, 1};
DimsType bs = {1, 1, 1};
CopyToArr3(vertexDimsv, vertexDims);
CopyToArr3(faceDimsv, faceDims);
CopyToArr3(edgeDimsv, edgeDims);
CopyToArr3(bsv, bs);
_unstructuredGrid(vertexDims, faceDims, edgeDims, bs, blks, topology_dimension, vertexOnFace, faceOnVertex, faceOnFace, location, maxVertexPerFace, maxFacePerVertex, nodeOffset, cellOffset);
}
const VAPoR::DimsType &UnstructuredGrid::GetNodeDimensions() const { return (_vertexDims); }
const size_t UnstructuredGrid::GetNumNodeDimensions() const { return _nDims; }
bool UnstructuredGrid::GetCellNodes(const DimsType &cindices, vector<DimsType> &nodes) const
{
DimsType cCindices;
ClampCellIndex(cindices, cCindices);
// _vertexOnFace is dimensioned cdims[0] x _maxVertexPerFace
//
const int *ptr = _vertexOnFace + (_maxVertexPerFace * cCindices[0]);
long offset = GetNodeOffset();
size_t n = 0;
if (GetNumCellDimensions() == 1) {
nodes.resize(_maxVertexPerFace); // ensure sufficient memory
for (int i = 0; i < _maxVertexPerFace; i++, ptr++) {
if (*ptr == GetMissingID()) break;
if (*ptr == GetBoundaryID()) continue;
if (*ptr + offset < 0) break;
nodes[n][0] = *ptr + offset;
nodes[n][1] = 0;
nodes[n][2] = 0;
n++;
}
} else { // layered case
nodes.resize(2 * _maxVertexPerFace); // ensure sufficient memory
// Bottom layer
//
for (int i = 0; i < _maxVertexPerFace; i++, ptr++) {
if (*ptr == GetMissingID()) break;
if (*ptr == GetBoundaryID()) continue;
if (*ptr + offset < 0) break;
nodes[n][0] = *ptr + offset;
nodes[n][1] = cCindices[1];
n++;
}
// Top layer is identical to bottom layer accept for the
// slowest varying index (the layer index)
//
int nNodesPerLayer = n;
for (int i = 0; i < nNodesPerLayer; i++) {
nodes[n][0] = nodes[i][0];
nodes[n][1] = nodes[i][1] + 1;
n++;
}
}
nodes.resize(n); // resize to actual count
return (true);
}
bool UnstructuredGrid::GetCellNeighbors(const DimsType &cindices, std::vector<DimsType> &cells) const
{
cells.clear();
DimsType cCindices = {0, 0, 0};
ClampCellIndex(cindices, cCindices);
const DimsType &cdims = GetCellDimensions();
// _faceOnFace is dimensioned cdims[0] x _maxVertexPerFace
//
const int *ptr = _faceOnFace + (_maxVertexPerFace * cCindices[0]);
long offset = GetCellOffset();
DimsType indices = {0, 0, 0};
if (GetNumCellDimensions() == 1) {
for (int i = 0; i < _maxVertexPerFace; i++) {
if (*ptr == GetMissingID() || *ptr + offset < 0) break;
if (*ptr != GetBoundaryID()) { indices[0] = *ptr + offset; }
cells.push_back(indices);
}
} else { // layered case
for (int i = 0; i < _maxVertexPerFace; i++) {
if (*ptr == GetMissingID() || *ptr + offset < 0) break;
if (*ptr != GetBoundaryID()) {
indices[0] = *ptr + offset;
indices[1] = cCindices[1];
}
cells.push_back(indices);
}
// layer below
//
if (cCindices[1] != 0) {
DimsType indices = {cCindices[0], cCindices[1], 0};
indices[1] = cCindices[1] - 1;
cells.push_back(indices);
}
// layer above
//
if (cCindices[1] != cdims[1] - 1) {
DimsType indices = {cCindices[0], cCindices[1], 0};
indices[1] = indices[1] + 1;
cells.push_back(indices);
}
}
return (true);
}
bool UnstructuredGrid::GetNodeCells(const DimsType &indices, std::vector<DimsType> &cells) const
{
cells.clear();
VAssert(indices.size() == GetNumDimensions());
VAssert(0 && "GetNodeCells() Not supported");
return false;
}
/////////////////////////////////////////////////////////////////////////////
//
// Iterators
//
/////////////////////////////////////////////////////////////////////////////
namespace VAPoR {
std::ostream &operator<<(std::ostream &o, const UnstructuredGrid &ug)
{
o << "UnstructuredGrid " << endl;
o << " Node dimensions ";
for (int i = 0; i < ug._vertexDims.size(); i++) { o << ug._vertexDims[i] << " "; }
o << endl;
o << " Cell dimensions ";
for (int i = 0; i < ug._faceDims.size(); i++) { o << ug._faceDims[i] << " "; }
o << endl;
o << " Edge dimensions ";
for (int i = 0; i < ug._edgeDims.size(); i++) { o << ug._edgeDims[i] << " "; }
o << endl;
o << " Max nodes per face " << ug._maxVertexPerFace << endl;
o << " Max face per node " << ug._maxFacePerVertex << endl;
o << " Sample location" << ug._location << endl;
o << " Missing ID" << ug._missingID << endl;
o << " Boundary ID" << ug._boundaryID << endl;
o << (const Grid &)ug;
return o;
}
}; // namespace VAPoR