11#include <vcVectorUtil.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 VectorIt find(VectorIt first, VectorIt last,
const Vec3D<T> &value) {
39 for (; first != last; ++first) {
40 if (*first == value) {
48 template <
class ElementType>
49 void replaceNode(ElementType &elements, std::pair<unsigned, unsigned> node) {
50 for (
unsigned i = 0; i < elements.size(); ++i) {
51 for (
unsigned j = 0; j < elements[i].size(); ++j) {
52 if (elements[i][j] == node.first) {
53 elements[i][j] = node.second;
64 template <int D, typename std::enable_if<D == 1, int>::type = 0>
69 template <int D, typename std::enable_if<D == 2, int>::type = 0>
74 template <int D, typename std::enable_if<D == 3, int>::type = 0>
79 template <int D, typename std::enable_if<D == 4, int>::type = 0>
84 template <int D, typename std::enable_if<D == 8, int>::type = 0>
98 nodes.push_back(node);
99 return nodes.size() - 1;
108 lines.push_back(line);
109 return lines.size() - 1;
123 hexas.push_back(hexa);
124 return hexas.size() - 1;
133 lines.push_back(line);
134 return lines.size() - 1;
148 hexas.push_back(hexa);
149 return hexas.size() - 1;
153 std::vector<Vec3D<T>> newNodes;
155 newNodes.push_back(
nodes[0]);
158 std::vector<std::pair<unsigned, unsigned>> duplicates;
159 bool adjusted =
false;
160 for (
unsigned i = 1; i <
nodes.size(); ++i) {
161 auto it = find(newNodes.begin(), newNodes.end(),
nodes[i]);
162 if (it != newNodes.end()) {
165 unsigned nodeId = std::distance(newNodes.begin(), it);
166 duplicates.push_back(std::make_pair(i, nodeId));
169 duplicates.push_back(std::make_pair(i, newNodes.size()));
170 newNodes.push_back(
nodes[i]);
177 for (
unsigned i = 0; i < duplicates.size(); ++i) {
178 replaceNode(
vertices, duplicates[i]);
179 replaceNode(
lines, duplicates[i]);
181 replaceNode(
tetras, duplicates[i]);
182 replaceNode(
hexas, duplicates[i]);
187 const unsigned numberOfOldNodes =
nodes.size();
193 const unsigned numberOfVertices =
vertices.size();
196 for (
unsigned i = numberOfVertices;
197 i < passedMesh.
vertices.size() + numberOfVertices; ++i) {
201 const unsigned numberOfLines =
lines.size();
203 for (
unsigned i = numberOfLines;
204 i < passedMesh.
lines.size() + numberOfLines; ++i) {
205 for (
unsigned d = 0; d < 2; ++d) {
206 lines[i][d] += numberOfOldNodes;
210 const unsigned numberOfTriangles =
triangles.size();
213 for (
unsigned i = numberOfTriangles;
214 i < passedMesh.
triangles.size() + numberOfTriangles; ++i) {
215 for (
unsigned d = 0; d < 3; ++d) {
220 const unsigned numberOfTetras =
tetras.size();
223 for (
unsigned i = numberOfTetras;
224 i < passedMesh.
tetras.size() + numberOfTetras; ++i) {
225 for (
unsigned d = 0; d < 4; ++d) {
226 tetras[i][d] += numberOfOldNodes;
230 const unsigned numberOfHexas =
hexas.size();
232 for (
unsigned i = numberOfHexas;
233 i < passedMesh.
hexas.size() + numberOfHexas; ++i) {
234 for (
unsigned d = 0; d < 8; ++d) {
235 hexas[i][d] += numberOfOldNodes;
273 std::cout <<
"Mesh:" << std::endl;
274 std::cout <<
"Number of Nodes: " <<
nodes.size() << std::endl;
276 std::cout <<
"Number of Vertices: " <<
vertices.size() << std::endl;
277 if (
lines.size() > 0)
278 std::cout <<
"Number of Lines: " <<
lines.size() << std::endl;
280 std::cout <<
"Number of Triangles: " <<
triangles.size() << std::endl;
282 std::cout <<
"Number of Tetrahedrons: " <<
tetras.size() << std::endl;
283 if (
hexas.size() > 0)
284 std::cout <<
"Number of Hexas: " <<
hexas.size() << std::endl;
287 std::cout <<
"Scalar data:" << std::endl;
294 std::cout <<
"Vector data:" << std::endl;
303 std::cout <<
"Scalar data:" << std::endl;
310 std::cout <<
"Vector data:" << 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:137
unsigned insertNextElement(const std::array< unsigned, 4 > &tetra)
Definition lsMesh.hpp:142
const PointData< T > & getPointData() const
Definition lsMesh.hpp:91
std::vector< std::array< unsigned, 8 > > hexas
Definition lsMesh.hpp:28
unsigned insertNextNode(const Vec3D< T > &node)
Definition lsMesh.hpp:97
void removeDuplicateNodes()
Definition lsMesh.hpp:152
Vec3D< T > minimumExtent
Definition lsMesh.hpp:31
PointData< T > cellData
Definition lsMesh.hpp:30
std::vector< Vec3D< T > > & getNodes()
Definition lsMesh.hpp:62
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:112
unsigned insertNextHexa(const std::array< unsigned, 8 > &hexa)
Definition lsMesh.hpp:122
void print()
Definition lsMesh.hpp:272
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:117
void clear()
Definition lsMesh.hpp:261
const PointData< T > & getCellData() const
Definition lsMesh.hpp:95
unsigned insertNextElement(const std::array< unsigned, 1 > &vertex)
Definition lsMesh.hpp:127
PointData< T > & getPointData()
Definition lsMesh.hpp:89
void append(const Mesh< T > &passedMesh)
Definition lsMesh.hpp:186
PointData< T > & getCellData()
Definition lsMesh.hpp:93
const std::vector< Vec3D< T > > & getNodes() const
Definition lsMesh.hpp:60
unsigned insertNextElement(const std::array< unsigned, 2 > &line)
Definition lsMesh.hpp:132
std::vector< std::array< unsigned, 3 > > triangles
Definition lsMesh.hpp:26
unsigned insertNextVertex(const std::array< unsigned, 1 > &vertex)
Definition lsMesh.hpp:102
unsigned insertNextElement(const std::array< unsigned, 8 > &hexa)
Definition lsMesh.hpp:147
unsigned insertNextLine(const std::array< unsigned, 2 > &line)
Definition lsMesh.hpp:107
std::vector< std::array< unsigned, D > > & getElements()
Definition lsMesh.hpp:65
This class holds data associated with points in space.
Definition lsPointData.hpp:20
void clear()
Delete all data stored in this object.
Definition lsPointData.hpp:272
void append(const PointData &passedData)
Append the passed PointData to this one.
Definition lsPointData.hpp:213
unsigned getScalarDataSize() const
get the number of different scalar data arrays saved
Definition lsPointData.hpp:85
VectorDataType * getVectorData(int index)
Definition lsPointData.hpp:151
std::string getScalarDataLabel(int index) const
Definition lsPointData.hpp:135
std::string getVectorDataLabel(int index) const
Definition lsPointData.hpp:196
ScalarDataType * getScalarData(int index)
Definition lsPointData.hpp:90
unsigned getVectorDataSize() const
get the number of different vector data arrays saved
Definition lsPointData.hpp:88
#define PRECOMPILE_PRECISION(className)
Definition lsPreCompileMacros.hpp:30
Definition lsAdvect.hpp:46