Skip to content

Commit 2beaae5

Browse files
committed
Start improving wmtk tests.
1 parent 83e27ca commit 2beaae5

File tree

7 files changed

+382
-42
lines changed

7 files changed

+382
-42
lines changed

src/wmtk/TetMesh.cpp

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ int wmtk::TetMesh::get_next_empty_slot_t()
1919
}
2020
tet_connectivity_synchronizing_flag = true;
2121
auto current_capacity = m_tet_connectivity.size();
22-
p_edge_attrs->resize(2 * current_capacity * 6);
23-
p_face_attrs->resize(2 * current_capacity * 4);
24-
p_tet_attrs->resize(2 * current_capacity);
22+
if (p_edge_attrs) {
23+
p_edge_attrs->resize(2 * current_capacity * 6);
24+
}
25+
if (p_face_attrs) {
26+
p_face_attrs->resize(2 * current_capacity * 4);
27+
}
28+
if (p_tet_attrs) {
29+
p_tet_attrs->resize(2 * current_capacity);
30+
}
2531
m_tet_connectivity.grow_to_at_least(2 * current_capacity);
2632
tet_connectivity_synchronizing_flag = false;
2733
tet_connectivity_lock.unlock();
@@ -46,7 +52,9 @@ int wmtk::TetMesh::get_next_empty_slot_v()
4652
}
4753
vertex_connectivity_synchronizing_flag = true;
4854
auto current_capacity = m_vertex_connectivity.size();
49-
p_vertex_attrs->resize(2 * current_capacity);
55+
if (p_vertex_attrs) {
56+
p_vertex_attrs->resize(2 * current_capacity);
57+
}
5058
resize_vertex_mutex(2 * current_capacity);
5159
m_vertex_connectivity.grow_to_at_least(2 * current_capacity);
5260
vertex_connectivity_synchronizing_flag = false;
@@ -84,10 +92,18 @@ void wmtk::TetMesh::init(size_t n_vertices, const std::vector<std::array<size_t,
8492
m_vertex_mutex.grow_to_at_least(n_vertices);
8593

8694
// resize attributes
87-
p_vertex_attrs->resize(n_vertices);
88-
p_tet_attrs->resize(tets.size());
89-
p_face_attrs->resize(4 * tets.size());
90-
p_edge_attrs->resize(6 * tets.size());
95+
if (p_vertex_attrs) {
96+
p_vertex_attrs->resize(n_vertices);
97+
}
98+
if (p_tet_attrs) {
99+
p_tet_attrs->resize(tets.size());
100+
}
101+
if (p_face_attrs) {
102+
p_face_attrs->resize(4 * tets.size());
103+
}
104+
if (p_edge_attrs) {
105+
p_edge_attrs->resize(6 * tets.size());
106+
}
91107
}
92108

93109
void wmtk::TetMesh::init_with_isolated_vertices(
@@ -116,10 +132,34 @@ void wmtk::TetMesh::init_with_isolated_vertices(
116132
m_vertex_mutex.grow_to_at_least(n_vertices);
117133

118134
// resize attributes
119-
p_vertex_attrs->resize(n_vertices);
120-
p_tet_attrs->resize(tets.size());
121-
p_face_attrs->resize(4 * tets.size());
122-
p_edge_attrs->resize(6 * tets.size());
135+
if (p_vertex_attrs) {
136+
p_vertex_attrs->resize(n_vertices);
137+
}
138+
if (p_tet_attrs) {
139+
p_tet_attrs->resize(tets.size());
140+
}
141+
if (p_face_attrs) {
142+
p_face_attrs->resize(4 * tets.size());
143+
}
144+
if (p_edge_attrs) {
145+
p_edge_attrs->resize(6 * tets.size());
146+
}
147+
}
148+
149+
void wmtk::TetMesh::init(const MatrixXi& T)
150+
{
151+
size_t n_vertices = T.maxCoeff() + 1;
152+
153+
std::vector<std::array<size_t, 4>> tets;
154+
tets.resize(T.rows());
155+
156+
for (int i = 0; i < T.rows(); ++i) {
157+
for (int j = 0; j < 4; ++j) {
158+
tets[i][j] = T(i, j);
159+
}
160+
}
161+
162+
TetMesh::init(n_vertices, tets);
123163
}
124164

125165

@@ -618,7 +658,9 @@ void wmtk::TetMesh::consolidate_mesh()
618658
if (v_cnt != i) {
619659
assert(v_cnt < i);
620660
m_vertex_connectivity[v_cnt] = m_vertex_connectivity[i];
621-
p_vertex_attrs->move(i, v_cnt);
661+
if (p_vertex_attrs) {
662+
p_vertex_attrs->move(i, v_cnt);
663+
}
622664
}
623665
for (size_t& t_id : m_vertex_connectivity[v_cnt].m_conn_tets) t_id = map_t_ids[t_id];
624666
v_cnt++;
@@ -631,13 +673,19 @@ void wmtk::TetMesh::consolidate_mesh()
631673
assert(t_cnt < i);
632674
m_tet_connectivity[t_cnt] = m_tet_connectivity[i];
633675
m_tet_connectivity[t_cnt].hash = 0;
634-
p_tet_attrs->move(i, t_cnt);
676+
if (p_tet_attrs) {
677+
p_tet_attrs->move(i, t_cnt);
678+
}
635679

636-
for (auto j = 0; j < 4; j++) {
637-
p_face_attrs->move(i * 4 + j, t_cnt * 4 + j);
680+
if (p_face_attrs) {
681+
for (auto j = 0; j < 4; j++) {
682+
p_face_attrs->move(i * 4 + j, t_cnt * 4 + j);
683+
}
638684
}
639-
for (auto j = 0; j < 6; j++) {
640-
p_edge_attrs->move(i * 6 + j, t_cnt * 6 + j);
685+
if (p_edge_attrs) {
686+
for (auto j = 0; j < 6; j++) {
687+
p_edge_attrs->move(i * 6 + j, t_cnt * 6 + j);
688+
}
641689
}
642690
}
643691
for (size_t& v_id : m_tet_connectivity[t_cnt].m_indices) v_id = map_v_ids[v_id];

src/wmtk/TetMesh.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <wmtk/utils/VectorUtils.h>
44
#include <type_traits>
55
#include <wmtk/AttributeCollection.hpp>
6+
#include <wmtk/Types.hpp>
67
#include <wmtk/utils/Logger.hpp>
78

89
#include <tbb/concurrent_vector.h>
@@ -352,6 +353,13 @@ class TetMesh
352353
size_t n_vertices,
353354
const std::vector<std::array<size_t, 4>>& tets);
354355

356+
/**
357+
* @brief Generate the connectivity of the mesh from an IGL-style T matrix.
358+
*
359+
* @param #T by 4 list of vertex indices.
360+
*/
361+
void init(const MatrixXi& T);
362+
355363
/**
356364
* Split an edge
357365
*
@@ -489,7 +497,10 @@ class TetMesh
489497
using vector = tbb::concurrent_vector<T>;
490498

491499
public:
492-
AbstractAttributeContainer *p_vertex_attrs, *p_edge_attrs, *p_face_attrs, *p_tet_attrs;
500+
AbstractAttributeContainer* p_vertex_attrs = nullptr;
501+
AbstractAttributeContainer* p_edge_attrs = nullptr;
502+
AbstractAttributeContainer* p_face_attrs = nullptr;
503+
AbstractAttributeContainer* p_tet_attrs = nullptr;
493504
// AbstractAttributeContainer vertex_attrs, edge_attrs, face_attrs, tet_attrs;
494505

495506

src/wmtk/TriMesh.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <wmtk/utils/EnableWarnings.hpp>
1313
// clang-format on
1414

15-
#include <Eigen/Core>
1615
#include <algorithm>
1716
#include <array>
1817
#include <cassert>
@@ -253,14 +252,6 @@ class TriMesh
253252
*/
254253
std::vector<Tuple> get_vertices() const;
255254

256-
/**
257-
* Generate a vector of Tuples from global face index
258-
* @note Local vid is the first of the m_idices
259-
* Local eid assigned counter clockwise as in the ilustrated example
260-
* @return vector of Tuples refering to each face
261-
*/
262-
std::vector<Tuple> get_faces() const;
263-
264255
/**
265256
* Generate a vector of Tuples for each edge
266257
* @note ensures the fid assigned is the smallest between faces adjacent to the
@@ -269,6 +260,14 @@ class TriMesh
269260
*/
270261
std::vector<Tuple> get_edges() const;
271262

263+
/**
264+
* Generate a vector of Tuples from global face index
265+
* @note Local vid is the first of the m_idices
266+
* Local eid assigned counter clockwise as in the ilustrated example
267+
* @return vector of Tuples refering to each face
268+
*/
269+
std::vector<Tuple> get_faces() const;
270+
272271
/**
273272
* Generate a tuple using local vid and global fid
274273
* @param vid1, vid2 are local vids
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#include "TetMesh_examples.hpp"
2+
3+
namespace wmtk::utils::examples::tet {
4+
5+
TetMeshVT single_tet()
6+
{
7+
TetMeshVT m;
8+
auto& V = m.V;
9+
auto& T = m.T;
10+
11+
T.resize(1, 4);
12+
T.row(0) << 0, 1, 2, 3;
13+
14+
V.resize(4, 3);
15+
V.row(0) << 0, 0, 0;
16+
V.row(1) << 0, 0, 1;
17+
V.row(2) << 0, 1, 0;
18+
V.row(3) << 1, 0, 0;
19+
20+
return m;
21+
}
22+
23+
TetMeshVT two_tets()
24+
{
25+
TetMeshVT m;
26+
auto& V = m.V;
27+
auto& T = m.T;
28+
29+
T.resize(2, 4);
30+
T.row(0) << 0, 1, 2, 3;
31+
T.row(1) << 0, 2, 3, 4;
32+
33+
// TODO check if positions make sense
34+
V.resize(5, 3);
35+
V.row(0) << 0, 0, 0;
36+
V.row(1) << 0, 0, 1;
37+
V.row(2) << 0, 1, 0;
38+
V.row(3) << 1, 0, 0;
39+
V.row(4) << 1, 1, 1;
40+
41+
return m;
42+
}
43+
44+
// TetMeshVT two_ears()
45+
// {
46+
// TetMesh m;
47+
// RowVectors4l tets;
48+
// tets.resize(3, 4);
49+
// tets.row(0) << 0, 1, 2, 3;
50+
// tets.row(1) << 0, 2, 3, 4;
51+
// tets.row(2) << 0, 1, 3, 5;
52+
// m.initialize(tets);
53+
// return m;
54+
// }
55+
56+
TetMeshVT three_incident_tets()
57+
{
58+
TetMeshVT m;
59+
auto& V = m.V;
60+
auto& T = m.T;
61+
62+
T.resize(3, 4);
63+
T.row(0) << 0, 1, 2, 3;
64+
T.row(1) << 0, 2, 3, 4;
65+
T.row(2) << 2, 5, 3, 4;
66+
67+
V.resize(6, 3);
68+
V.row(0) = Eigen::Vector3d(-4., 0., 0);
69+
V.row(1) = Eigen::Vector3d(2., 2., 0);
70+
V.row(2) = Eigen::Vector3d(0., 2., 0);
71+
V.row(3) = Eigen::Vector3d(0., 1, 1);
72+
V.row(4) = Eigen::Vector3d(0., 1, -1);
73+
V.row(5) = Eigen::Vector3d(1., 1, -1);
74+
75+
return m;
76+
}
77+
78+
TetMeshVT six_cycle_tets()
79+
{
80+
// 0 ---------- 4
81+
// / \\ // \ .
82+
// / \ \ // \ .
83+
// / \ \ // \ .
84+
// / \ \3 \ .
85+
// 1 --------- 2/ -------- 5 tuple edge 2-3
86+
// \ / /\ \ / .
87+
// \ / / \\ / .
88+
// \ // \\ / .
89+
// \ // \ / .
90+
// 6 -----------7
91+
//
92+
93+
TetMeshVT m;
94+
auto& V = m.V;
95+
auto& T = m.T;
96+
97+
T.resize(6, 4);
98+
T.row(0) << 0, 1, 2, 3;
99+
T.row(1) << 0, 2, 3, 4;
100+
T.row(2) << 2, 5, 3, 4;
101+
T.row(3) << 6, 1, 2, 3;
102+
T.row(4) << 6, 2, 3, 7;
103+
T.row(5) << 7, 2, 3, 5;
104+
105+
V.resize(8, 3);
106+
V.row(2) = Eigen::Vector3d(0, 0, -1);
107+
V.row(3) = Eigen::Vector3d(0, 0, 1);
108+
109+
V.row(1) = Eigen::Vector3d(-1, 0, 0);
110+
V.row(5) = Eigen::Vector3d(1, 0, 0);
111+
112+
V.row(0) = Eigen::Vector3d(1, -1, 0);
113+
V.row(7) = Eigen::Vector3d(-1, 1, 0);
114+
115+
V.row(4) = Eigen::Vector3d(1, 1, 0);
116+
V.row(6) = Eigen::Vector3d(-1, -1, 0);
117+
118+
return m;
119+
}
120+
121+
// TetMeshVT three_cycle_tets()
122+
// {
123+
// TetMesh m;
124+
// RowVectors4l tets;
125+
// tets.resize(3, 4);
126+
// tets.row(0) << 0, 1, 2, 4;
127+
// tets.row(1) << 0, 1, 4, 3;
128+
// tets.row(2) << 0, 1, 3, 2;
129+
// m.initialize(tets);
130+
// return m;
131+
// }
132+
133+
// TetMeshVT four_cycle_tets()
134+
// {
135+
// TetMesh m;
136+
// RowVectors4l tets;
137+
// tets.resize(4, 4);
138+
// tets.row(0) << 0, 1, 3, 4;
139+
// tets.row(1) << 0, 1, 4, 5;
140+
// tets.row(2) << 0, 1, 5, 2;
141+
// tets.row(3) << 0, 1, 2, 3;
142+
// m.initialize(tets);
143+
// return m;
144+
// }
145+
146+
} // namespace wmtk::utils::examples::tet

0 commit comments

Comments
 (0)