11#include <vcVectorType.hpp>
15using namespace viennacore;
21template <
class T =
double>
class Mesh {
25 std::vector<std::array<unsigned, 2>>
lines;
27 std::vector<std::array<unsigned, 4>>
tetras;
28 std::vector<std::array<unsigned, 8>>
hexas;
38 static VectorIt find(VectorIt first, VectorIt last,
const Vec3D<T> &value) {
39 for (; first != last; ++first) {
40 if (*first == value) {
48 template <
class ElementType>
49 static void replaceNode(ElementType &elements,
50 std::pair<unsigned, unsigned> node) {
51 for (
unsigned i = 0; i < elements.size(); ++i) {
52 for (
unsigned j = 0; j < elements[i].size(); ++j) {
53 if (elements[i][j] == node.first) {
54 elements[i][j] = node.second;
65 template <
int D, std::enable_if_t<D == 1,
int> = 0>
70 template <
int D, std::enable_if_t<D == 2,
int> = 0>
75 template <
int D, std::enable_if_t<D == 3,
int> = 0>
80 template <
int D, std::enable_if_t<D == 4,
int> = 0>
85 template <
int D, std::enable_if_t<D == 8,
int> = 0>
99 nodes.push_back(node);
100 return nodes.size() - 1;
109 lines.push_back(line);
110 return lines.size() - 1;
124 hexas.push_back(hexa);
125 return hexas.size() - 1;
134 lines.push_back(line);
135 return lines.size() - 1;
149 hexas.push_back(hexa);
150 return hexas.size() - 1;
154 std::vector<Vec3D<T>> newNodes;
156 newNodes.push_back(
nodes[0]);
159 std::vector<std::pair<unsigned, unsigned>> duplicates;
160 bool adjusted =
false;
161 for (
unsigned i = 1; i <
nodes.size(); ++i) {
162 auto it = find(newNodes.begin(), newNodes.end(),
nodes[i]);
163 if (it != newNodes.end()) {
166 unsigned nodeId = std::distance(newNodes.begin(), it);
167 duplicates.emplace_back(i, nodeId);
170 duplicates.push_back(std::make_pair(i, newNodes.size()));
171 newNodes.push_back(
nodes[i]);
178 for (
auto &duplicate : duplicates) {
180 replaceNode(
lines, duplicate);
182 replaceNode(
tetras, duplicate);
183 replaceNode(
hexas, duplicate);
188 const unsigned numberOfOldNodes =
nodes.size();
194 const unsigned numberOfVertices =
vertices.size();
197 for (
unsigned i = numberOfVertices;
198 i < passedMesh.
vertices.size() + numberOfVertices; ++i) {
202 const unsigned numberOfLines =
lines.size();
204 for (
unsigned i = numberOfLines;
205 i < passedMesh.
lines.size() + numberOfLines; ++i) {
206 for (
unsigned d = 0; d < 2; ++d) {
207 lines[i][d] += numberOfOldNodes;
211 const unsigned numberOfTriangles =
triangles.size();
214 for (
unsigned i = numberOfTriangles;
215 i < passedMesh.
triangles.size() + numberOfTriangles; ++i) {
216 for (
unsigned d = 0; d < 3; ++d) {
221 const unsigned numberOfTetras =
tetras.size();
224 for (
unsigned i = numberOfTetras;
225 i < passedMesh.
tetras.size() + numberOfTetras; ++i) {
226 for (
unsigned d = 0; d < 4; ++d) {
227 tetras[i][d] += numberOfOldNodes;
231 const unsigned numberOfHexas =
hexas.size();
233 for (
unsigned i = numberOfHexas;
234 i < passedMesh.
hexas.size() + numberOfHexas; ++i) {
235 for (
unsigned d = 0; d < 8; ++d) {
236 hexas[i][d] += numberOfOldNodes;
247 for (
unsigned i = 0; i <
pointData.getScalarDataSize(); ++i) {
250 for (
unsigned i = 0; i <
pointData.getVectorDataSize(); ++i) {
254 for (
unsigned i = 0; i <
cellData.getScalarDataSize(); ++i) {
257 for (
unsigned i = 0; i <
cellData.getVectorDataSize(); ++i) {
274 std::cout <<
"Mesh:" << std::endl;
275 std::cout <<
"Number of Nodes: " <<
nodes.size() << std::endl;
277 std::cout <<
"Number of Vertices: " <<
vertices.size() << std::endl;
279 std::cout <<
"Number of Lines: " <<
lines.size() << std::endl;
281 std::cout <<
"Number of Triangles: " <<
triangles.size() << std::endl;
283 std::cout <<
"Number of Tetrahedrons: " <<
tetras.size() << std::endl;
285 std::cout <<
"Number of Hexas: " <<
hexas.size() << std::endl;
288 std::cout <<
"Scalar data:" << std::endl;
289 for (
unsigned i = 0; i <
pointData.getScalarDataSize(); ++i) {
290 std::cout <<
" \"" <<
pointData.getScalarDataLabel(i) <<
"\" of size "
291 <<
pointData.getScalarData(i)->size() << std::endl;
295 std::cout <<
"Vector data:" << std::endl;
296 for (
unsigned i = 0; i <
pointData.getVectorDataSize(); ++i) {
297 std::cout <<
" \"" <<
pointData.getVectorDataLabel(i) <<
"\" of size "
298 <<
pointData.getVectorData(i)->size() << std::endl;
303 if (
cellData.getScalarDataSize() > 0) {
304 std::cout <<
"Scalar data:" << std::endl;
305 for (
unsigned i = 0; i <
cellData.getScalarDataSize(); ++i) {
306 std::cout <<
" \"" <<
cellData.getScalarDataLabel(i) <<
"\" of size "
307 <<
cellData.getScalarData(i)->size() << std::endl;
310 if (
cellData.getVectorDataSize() > 0) {
311 std::cout <<
"Vector data:" << std::endl;
312 for (
unsigned i = 0; i <
cellData.getVectorDataSize(); ++i) {
313 std::cout <<
" \"" <<
cellData.getVectorDataLabel(i) <<
"\" of size "
314 <<
cellData.getVectorData(i)->size() << std::endl;
This class holds an explicit mesh, which is always given in 3 dimensions. If it describes a 2D mesh,...
Definition lsMesh.hpp:21
PointData< T > pointData
Definition lsMesh.hpp:29
unsigned insertNextElement(const std::array< unsigned, 3 > &triangle)
Definition lsMesh.hpp:138
unsigned insertNextElement(const std::array< unsigned, 4 > &tetra)
Definition lsMesh.hpp:143
const PointData< T > & getPointData() const
Definition lsMesh.hpp:92
std::vector< std::array< unsigned, 8 > > hexas
Definition lsMesh.hpp:28
unsigned insertNextNode(const Vec3D< T > &node)
Definition lsMesh.hpp:98
void removeDuplicateNodes()
Definition lsMesh.hpp:153
Vec3D< T > minimumExtent
Definition lsMesh.hpp:31
PointData< T > cellData
Definition lsMesh.hpp:30
std::vector< Vec3D< T > > & getNodes()
Definition lsMesh.hpp:63
std::vector< std::array< unsigned, 1 > > vertices
Definition lsMesh.hpp:24
std::vector< std::array< unsigned, 2 > > lines
Definition lsMesh.hpp:25
unsigned insertNextTriangle(const std::array< unsigned, 3 > &triangle)
Definition lsMesh.hpp:113
unsigned insertNextHexa(const std::array< unsigned, 8 > &hexa)
Definition lsMesh.hpp:123
void print()
Definition lsMesh.hpp:273
Vec3D< T > maximumExtent
Definition lsMesh.hpp:32
std::vector< std::array< unsigned, 4 > > tetras
Definition lsMesh.hpp:27
std::vector< Vec3D< T > > nodes
Definition lsMesh.hpp:23
unsigned insertNextTetra(const std::array< unsigned, 4 > &tetra)
Definition lsMesh.hpp:118
void clear()
Definition lsMesh.hpp:262
const PointData< T > & getCellData() const
Definition lsMesh.hpp:96
unsigned insertNextElement(const std::array< unsigned, 1 > &vertex)
Definition lsMesh.hpp:128
PointData< T > & getPointData()
Definition lsMesh.hpp:90
void append(const Mesh< T > &passedMesh)
Definition lsMesh.hpp:187
PointData< T > & getCellData()
Definition lsMesh.hpp:94
const std::vector< Vec3D< T > > & getNodes() const
Definition lsMesh.hpp:61
unsigned insertNextElement(const std::array< unsigned, 2 > &line)
Definition lsMesh.hpp:133
std::vector< std::array< unsigned, 3 > > triangles
Definition lsMesh.hpp:26
unsigned insertNextVertex(const std::array< unsigned, 1 > &vertex)
Definition lsMesh.hpp:103
unsigned insertNextElement(const std::array< unsigned, 8 > &hexa)
Definition lsMesh.hpp:148
unsigned insertNextLine(const std::array< unsigned, 2 > &line)
Definition lsMesh.hpp:108
std::vector< std::array< unsigned, D > > & getElements()
Definition lsMesh.hpp:66
This class holds data associated with points in space.
Definition lsPointData.hpp:20
#define PRECOMPILE_PRECISION(className)
Definition lsPreCompileMacros.hpp:30
Definition lsAdvect.hpp:36