Skip to content

Commit 80e2a58

Browse files
committed
Exposed shear construction
1 parent b1bf722 commit 80e2a58

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

src/optimization/cone_metric.hh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,66 @@
77

88
namespace CurvatureMetric {
99

10+
11+
class FlipMapMatrixGenerator {
12+
public:
13+
FlipMapMatrixGenerator(int size)
14+
: m_size(size) {
15+
reset();
16+
17+
}
18+
19+
void reset() {
20+
m_list_of_lists =
21+
std::vector<std::map<int, Scalar>>(m_size, std::map<int, Scalar>());
22+
for (int i = 0; i < m_size; ++i) {
23+
m_list_of_lists[i][i] = 1.0;
24+
}
25+
}
26+
27+
void multiply_by_matrix(
28+
const std::vector<int>& matrix_indices,
29+
const std::vector<Scalar>& matrix_scalars,
30+
int ed
31+
) {
32+
// Compute the new row of J_del corresponding to edge ed, which is the only
33+
// edge that changes
34+
std::map<int, Scalar> J_del_d_new;
35+
for (int i = 0; i < 5; ++i) {
36+
int ei = matrix_indices[i];
37+
Scalar Di = matrix_scalars[i];
38+
for (auto it : m_list_of_lists[ei]) {
39+
J_del_d_new[it.first] += Di * it.second;
40+
}
41+
}
42+
m_list_of_lists[ed] = J_del_d_new;
43+
}
44+
45+
MatrixX build_matrix() const {
46+
// Build triplets from list of lists
47+
typedef Eigen::Triplet<Scalar> T;
48+
std::vector<T> tripletList;
49+
tripletList.reserve(5 * m_size);
50+
for (int i = 0; i < m_size; ++i) {
51+
for (auto it : m_list_of_lists[i]) {
52+
tripletList.push_back(T(i, it.first, it.second));
53+
}
54+
}
55+
56+
// Create the matrix from the triplets
57+
MatrixX matrix;
58+
matrix.resize(m_size, m_size);
59+
matrix.reserve(tripletList.size());
60+
matrix.setFromTriplets(tripletList.begin(), tripletList.end());
61+
62+
return matrix;
63+
}
64+
65+
private:
66+
int m_size;
67+
std::vector<std::map<int, Scalar>> m_list_of_lists;
68+
};
69+
1070
class FlipMatrixGenerator
1171
{
1272
public:

src/optimization/shear.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void compute_spanning_tree(
199199
spanning_tree_vertex_in_edge));
200200
}
201201

202-
void compute_independent_to_full_edge_shear_matrix(
202+
void compute_shear_dual_matrix(
203203
const Mesh<Scalar>& m,
204204
const std::vector<int>& independent_edges,
205205
MatrixX& shear_matrix)
@@ -299,7 +299,7 @@ void compute_shear_dual_basis(
299299
index_vector_complement(dependent_edges, num_edges, independent_edges);
300300

301301
// Compute matrix of basis vectors
302-
compute_independent_to_full_edge_shear_matrix(m, independent_edges, shear_basis_matrix);
302+
compute_shear_dual_matrix(m, independent_edges, shear_basis_matrix);
303303
}
304304

305305
std::tuple<MatrixX, std::vector<int>> compute_shear_dual_basis_pybind(const Mesh<Scalar>& m)

src/optimization/shear.hh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ compute_shear_change(
2929
VectorX& he_shear_change
3030
);
3131

32+
/// TODO
33+
void compute_shear_dual_matrix(
34+
const Mesh<Scalar>& m,
35+
const std::vector<int>& independent_edges,
36+
MatrixX& shear_matrix);
37+
3238
/// Compute a basis for the space of shear coordinates for a given mesh of dual shear vectors.
3339
///
3440
/// Note that the coefficients of these basis vectors do not correspond to shear coordinates

0 commit comments

Comments
 (0)