16 T
determinant(
const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3> &
mat)
18 assert(
mat.rows() ==
mat.cols());
22 else if (
mat.rows() == 2)
24 else if (
mat.rows() == 3)
25 return mat(0, 0) * (
mat(1, 1) *
mat(2, 2) -
mat(1, 2) *
mat(2, 1)) -
mat(0, 1) * (
mat(1, 0) *
mat(2, 2) -
mat(1, 2) *
mat(2, 0)) +
mat(0, 2) * (
mat(1, 0) *
mat(2, 1) -
mat(1, 1) *
mat(2, 0));
32 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3>
inverse(
const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3> &
mat)
34 assert(
mat.rows() ==
mat.cols());
38 Eigen::Matrix<T, 1, 1> inv;
39 inv(0, 0) = T(1.) /
mat(0);
43 else if (
mat.rows() == 2)
45 Eigen::Matrix<T, 2, 2> inv;
47 inv(0, 0) =
mat(1, 1) / det;
48 inv(0, 1) = -
mat(0, 1) / det;
49 inv(1, 0) = -
mat(1, 0) / det;
50 inv(1, 1) =
mat(0, 0) / det;
54 else if (
mat.rows() == 3)
56 Eigen::Matrix<T, 3, 3> inv;
58 inv(0, 0) = (-
mat(1, 2) *
mat(2, 1) +
mat(1, 1) *
mat(2, 2)) / det;
59 inv(0, 1) = (
mat(0, 2) *
mat(2, 1) -
mat(0, 1) *
mat(2, 2)) / det;
60 inv(0, 2) = (-
mat(0, 2) *
mat(1, 1) +
mat(0, 1) *
mat(1, 2)) / det;
61 inv(1, 0) = (
mat(1, 2) *
mat(2, 0) -
mat(1, 0) *
mat(2, 2)) / det;
62 inv(1, 1) = (-
mat(0, 2) *
mat(2, 0) +
mat(0, 0) *
mat(2, 2)) / det;
63 inv(1, 2) = (
mat(0, 2) *
mat(1, 0) -
mat(0, 0) *
mat(1, 2)) / det;
64 inv(2, 0) = (-
mat(1, 1) *
mat(2, 0) +
mat(1, 0) *
mat(2, 1)) / det;
65 inv(2, 1) = (
mat(0, 1) *
mat(2, 0) -
mat(0, 0) *
mat(2, 1)) / det;
66 inv(2, 2) = (-
mat(0, 1) *
mat(1, 0) +
mat(0, 0) *
mat(1, 1)) / det;
72 Eigen::Matrix<T, 1, 1> inv;
79 Eigen::SparseMatrix<double> I(rows, cols);
85 Eigen::VectorXd
flatten(
const Eigen::MatrixXd &X);
88 Eigen::MatrixXd
unflatten(
const Eigen::VectorXd &
x,
int dim);
95 Eigen::SparseMatrix<double>
lump_matrix(
const Eigen::SparseMatrix<double> &M);
105 const int reduced_size,
106 const std::vector<int> &removed_vars,
117 const Eigen::MatrixXd &in,
118 const Eigen::VectorXi &in_to_out,
120 const int block_size = 1);
129 const Eigen::MatrixXd &out,
130 const Eigen::VectorXi &in_to_out,
132 const int block_size = 1);
139 const Eigen::MatrixXi &in,
140 const Eigen::VectorXi &index_mapping);
142 template <
typename DstMat,
typename SrcMat>
148 dst.resize(dst.rows(), src.cols());
149 assert(dst.cols() == src.cols());
150 dst.conservativeResize(dst.rows() + src.rows(), dst.cols());
151 dst.bottomRows(src.rows()) = src;
154 template <
typename DstMat>
157 assert(dst.cols() > 0);
158 if (n_zero_rows == 0)
160 dst.conservativeResize(dst.rows() + n_zero_rows, dst.cols());
161 dst.bottomRows(n_zero_rows).setZero();
Eigen::SparseMatrix< double > lump_matrix(const Eigen::SparseMatrix< double > &M)
Lump each row of a matrix into the diagonal.
void show_matrix_stats(const Eigen::MatrixXd &M)
Eigen::MatrixXd reorder_matrix(const Eigen::MatrixXd &in, const Eigen::VectorXi &in_to_out, int out_blocks=-1, const int block_size=1)
Reorder row blocks in a matrix.
Eigen::SparseMatrix< double > sparse_identity(int rows, int cols)
void vector2matrix(const Eigen::VectorXd &vec, Eigen::MatrixXd &mat)
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3 > inverse(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3 > &mat)
Eigen::MatrixXd unreorder_matrix(const Eigen::MatrixXd &out, const Eigen::VectorXi &in_to_out, int in_blocks=-1, const int block_size=1)
Undo the reordering of row blocks in a matrix.
Eigen::MatrixXd unflatten(const Eigen::VectorXd &x, int dim)
Unflatten rowwises, so every dim elements in x become a row.
void append_rows_of_zeros(DstMat &dst, const size_t n_zero_rows)
T determinant(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3 > &mat)
void append_rows(DstMat &dst, const SrcMat &src)
Eigen::VectorXd flatten(const Eigen::MatrixXd &X)
Flatten rowwises.
Eigen::MatrixXi map_index_matrix(const Eigen::MatrixXi &in, const Eigen::VectorXi &index_mapping)
Map the entrys of an index matrix to new indices.
void full_to_reduced_matrix(const int full_size, const int reduced_size, const std::vector< int > &removed_vars, const StiffnessMatrix &full, StiffnessMatrix &reduced)
Map a full size matrix to a reduced one by dropping rows and columns.
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix