View on GitHub

Vistle

Distributed Data-parallel Scientific Visualization in VR

structuredgridbase.h
Go to the documentation of this file.
1//-------------------------------------------------------------------------
2// STRUCTURED GRID OBJECT BASE CLASS H
3// *
4// * Base class for Structured Grid Objects
5//-------------------------------------------------------------------------
6#ifndef STRUCTURED_GRID_BASE_H
7#define STRUCTURED_GRID_BASE_H
8
9#include "scalar.h"
10#include "shm.h"
11#include "object.h"
12#include "export.h"
13#include "grid.h"
14
15namespace vistle {
16
17//-------------------------------------------------------------------------
18// DECLARATION OF STRUCTUREDGRIDBASE
19//-------------------------------------------------------------------------
21public:
23 typedef std::shared_ptr<Class> ptr;
24 typedef std::shared_ptr<const Class> const_ptr;
25 static std::shared_ptr<const Class> as(std::shared_ptr<const Object> ptr)
26 {
27 return std::dynamic_pointer_cast<const Class>(ptr);
28 }
29 static std::shared_ptr<Class> as(std::shared_ptr<Object> ptr) { return std::dynamic_pointer_cast<Class>(ptr); }
30
32 static constexpr std::array<Index, 8> HexahedronIndices[3] = {
33 0, 0, 0};
34
35 static inline int dimensionality(const Index dims[3])
36 {
37 if (dims[2] > 1)
38 return 3;
39 if (dims[1] > 1)
40 return 2;
41 if (dims[0] > 1)
42 return 1;
43 return 0;
44 }
45
46 // static inline method to obtain a cell index from (x,y,z) indices and max grid dimensions
47 static inline Index vertexIndex(const Index ix, const Index iy, const Index iz, const Index dims[3])
48 {
49 assert(ix < dims[0]);
50 assert(iy < dims[1]);
51 assert(iz < dims[2]);
52 return (ix * dims[1] + iy) * dims[2] + iz;
53 }
54 static inline Index vertexIndex(const Index i[3], const Index dims[3])
55 {
56 return vertexIndex(i[0], i[1], i[2], dims);
57 }
58 static inline std::array<Index, 3> vertexCoordinates(Index v, const Index dims[3])
59 {
60 std::array<Index, 3> coords;
61 coords[2] = v % dims[2];
62 v /= dims[2];
63 coords[1] = v % dims[1];
64 v /= dims[1];
65 coords[0] = v;
66 assert(coords[0] < dims[0]);
67 assert(coords[1] < dims[1]);
68 assert(coords[2] < dims[2]);
69 return coords;
70 }
71
72 static inline Index cellIndex(const Index ix, const Index iy, const Index iz, const Index dims[3])
73 {
74 assert(ix < dims[0] - 1 || ix == 0);
75 assert(iy < dims[1] - 1 || iy == 0);
76 assert(iz < dims[2] - 1 || iz == 0);
77 return (ix * std::max(dims[1] - 1, Index(1)) + iy) * std::max(dims[2] - 1, Index(1)) + iz;
78 }
79 static inline Index cellIndex(const Index i[3], const Index dims[3]) { return cellIndex(i[0], i[1], i[2], dims); }
80 static inline std::array<Index, 3> cellCoordinates(Index el, const Index dims[3])
81 {
82 std::array<Index, 3> coords;
83 Index div2 = std::max(dims[2] - 1, Index(1));
84 coords[2] = el % div2;
85 el /= div2;
86 Index div1 = std::max(dims[1] - 1, Index(1));
87 coords[1] = el % div1;
88 el /= div1;
89 coords[0] = el;
90 assert(coords[0] < dims[0] - 1 || coords[0] == 0);
91 assert(coords[1] < dims[1] - 1 || coords[1] == 0);
92 assert(coords[2] < dims[2] - 1 || coords[2] == 0);
93 return coords;
94 }
95 static inline std::array<Index, 8> cellVertices(Index el, const Index dims[3])
96 {
97 auto &H = HexahedronIndices;
98 std::array<Index, 3> n = cellCoordinates(el, dims);
99 std::array<Index, 8> cl;
100 if (dims[2] > 1) {
101 for (int i = 0; i < 8; ++i) {
102 cl[i] = vertexIndex(n[0] + H[0][i], n[1] + H[1][i], n[2] + H[2][i], dims);
103 }
104 } else if (dims[1] > 1) {
105 // return same index several times for lower-dimensional cells
106 for (int i = 0; i < 4; ++i) {
107 cl[i + 4] = cl[i] = vertexIndex(n[0] + H[0][i], n[1] + H[1][i], n[2] + H[2][i], dims);
108 }
109 } else if (dims[0] > 1) {
110 for (int i = 0; i < 2; ++i) {
111 cl[i + 6] = cl[i + 4] = cl[i + 2] = cl[i] =
112 vertexIndex(n[0] + H[0][i], n[1] + H[1][i], n[2] + H[2][i], dims);
113 }
114 }
115 return cl;
116 }
117
118 virtual bool isGhostCell(Index elem) const override;
119
120 // virtual get functions
121 virtual Index getNumElements() override
122 {
123 return (std::max(getNumDivisions(0) - 1, Index(1)) * std::max(getNumDivisions(1) - 1, Index(1)) *
124 std::max(getNumDivisions(2) - 1, Index(1)));
125 }
126 virtual Index getNumElements() const override
127 {
128 return (std::max(getNumDivisions(0) - 1, Index(1)) * std::max(getNumDivisions(1) - 1, Index(1)) *
129 std::max(getNumDivisions(2) - 1, Index(1)));
130 }
131 virtual Index getNumDivisions(int d) { return 1; } //< get number of vertices in dimension d
132 virtual Index getNumDivisions(int d) const { return 1; } //< get number of vertices in dimension d
133 virtual Index getNumGhostLayers(unsigned dim, GhostLayerPosition pos) { return 0; }
134 virtual Index getNumGhostLayers(unsigned dim, GhostLayerPosition pos) const { return 0; }
135
136 virtual Index getGlobalIndexOffset(int d) const { return 0; }
137 virtual void setGlobalIndexOffset(int d, Index offset) = 0;
138
139 // virtual set functions
140 virtual void setNumGhostLayers(unsigned dim, GhostLayerPosition pos, unsigned value) { return; }
141
142 virtual Scalar cellDiameter(Index elem) const override;
143 virtual Vector cellCenter(Index elem) const override;
144 virtual std::vector<Index> getNeighborElements(Index elem) const override;
145
146 Index cellNumFaces(Index elem) const override { return 6; }
147 std::vector<Index> cellVertices(Index elem) const override;
148};
149
150ARCHIVE_ASSUME_ABSTRACT(StructuredGridBase)
151
152} // namespace vistle
153#endif /* STRUCTURED_GRID_BASE_H */
#define ARCHIVE_ASSUME_ABSTRACT(obj)
Definition: archives_config.h:466
Definition: grid.h:14
Definition: structuredgridbase.h:20
virtual Index getNumElements() override
Definition: structuredgridbase.h:121
GhostLayerPosition
Definition: structuredgridbase.h:31
@ Bottom
Definition: structuredgridbase.h:31
std::shared_ptr< const Class > const_ptr
Definition: structuredgridbase.h:24
static std::array< Index, 3 > vertexCoordinates(Index v, const Index dims[3])
Definition: structuredgridbase.h:58
virtual void setNumGhostLayers(unsigned dim, GhostLayerPosition pos, unsigned value)
Definition: structuredgridbase.h:140
static Index cellIndex(const Index ix, const Index iy, const Index iz, const Index dims[3])
Definition: structuredgridbase.h:72
static std::shared_ptr< Class > as(std::shared_ptr< Object > ptr)
Definition: structuredgridbase.h:29
static Index vertexIndex(const Index i[3], const Index dims[3])
Definition: structuredgridbase.h:54
std::shared_ptr< Class > ptr
Definition: structuredgridbase.h:23
virtual Index getNumDivisions(int d) const
Definition: structuredgridbase.h:132
virtual void setGlobalIndexOffset(int d, Index offset)=0
static std::array< Index, 3 > cellCoordinates(Index el, const Index dims[3])
Definition: structuredgridbase.h:80
virtual Index getNumGhostLayers(unsigned dim, GhostLayerPosition pos)
Definition: structuredgridbase.h:133
static Index vertexIndex(const Index ix, const Index iy, const Index iz, const Index dims[3])
Definition: structuredgridbase.h:47
static std::array< Index, 8 > cellVertices(Index el, const Index dims[3])
Definition: structuredgridbase.h:95
static Index cellIndex(const Index i[3], const Index dims[3])
Definition: structuredgridbase.h:79
StructuredGridBase Class
Definition: structuredgridbase.h:22
static std::shared_ptr< const Class > as(std::shared_ptr< const Object > ptr)
Definition: structuredgridbase.h:25
virtual Index getGlobalIndexOffset(int d) const
Definition: structuredgridbase.h:136
Index cellNumFaces(Index elem) const override
Definition: structuredgridbase.h:146
static int dimensionality(const Index dims[3])
Definition: structuredgridbase.h:35
virtual Index getNumDivisions(int d)
Definition: structuredgridbase.h:131
virtual Index getNumElements() const override
Definition: structuredgridbase.h:126
virtual Index getNumGhostLayers(unsigned dim, GhostLayerPosition pos) const
Definition: structuredgridbase.h:134
#define V_COREEXPORT
Definition: export.h:9
Definition: allobjects.cpp:30
Vector3 Vector
Definition: vector.h:36
float Scalar
Definition: scalar.h:14
uint32_t Index
Definition: index.h:13