43 Eigen::DenseBase<TDerivedE>
const& E,
44 Eigen::DenseBase<TDerivedW>
const& w,
45 TIndex nNodes = TIndex(-1),
46 bool bVertexToElement =
false,
47 bool bHasDuplicates =
false) -> Eigen::SparseMatrix<TScalar, Eigen::ColMajor, TIndex>
49 PBAT_PROFILE_NAMED_SCOPE(
"pbat.graph.MeshAdjacencyMatrix");
51 nNodes = E.maxCoeff() + TIndex(1);
53 using AdjacencyMatrix = Eigen::SparseMatrix<TScalar, Eigen::ColMajor, TIndex>;
54 AdjacencyMatrix G(nNodes, E.cols());
55 using IndexVectorType = Eigen::Vector<TIndex, Eigen::Dynamic>;
56 if (not bHasDuplicates)
58 G.reserve(IndexVectorType::Constant(E.cols(),
static_cast<TIndex
>(E.rows())));
59 for (
auto e = 0; e < E.cols(); ++e)
60 for (
auto i = 0; i < E.rows(); ++i)
61 G.insert(E(i, e), e) = w(i, e);
65 using Triplet = Eigen::Triplet<TScalar, TIndex>;
66 std::vector<Triplet> triplets{};
67 triplets.reserve(
static_cast<std::size_t
>(E.rows() * E.cols()));
68 for (
auto e = 0; e < E.cols(); ++e)
69 for (
auto i = 0; i < E.rows(); ++i)
70 triplets.emplace_back(E(i, e), e, w(i, e));
71 G.setFromTriplets(triplets.begin(), triplets.end());
92 Eigen::DenseBase<TDerivedE>
const& E,
93 TIndex nNodes = TIndex(-1),
94 bool bVertexToElement =
false,
95 bool bHasDuplicates =
false) -> Eigen::SparseMatrix<TIndex, Eigen::ColMajor, TIndex>
97 using WeightMatrixType = Eigen::Matrix<TIndex, Eigen::Dynamic, Eigen::Dynamic>;
100 WeightMatrixType::Ones(E.rows(), E.cols()),
148 Eigen::DenseBase<TDerivedE>
const& E,
149 TIndex nNodes = TIndex(-1),
151 -> Eigen::SparseMatrix<TIndex, Eigen::ColMajor, TIndex>
153 PBAT_PROFILE_NAMED_SCOPE(
"pbat.graph.MeshDualGraph");
155 using SparseMatrixType = Eigen::SparseMatrix<TIndex, Eigen::ColMajor, TIndex>;
156 SparseMatrixType GTG = G.transpose() * G;
157 if (opts == EMeshDualGraphOptions::All)
159 auto flags =
static_cast<std::int32_t
>(opts);
160 bool const bKeepFaceAdjacencies =
161 flags &
static_cast<std::int32_t
>(EMeshDualGraphOptions::FaceAdjacent);
162 bool const bKeepEdgeAdjacencies =
163 flags &
static_cast<std::int32_t
>(EMeshDualGraphOptions::EdgeAdjacent);
164 bool const bKeepVertexAdjacencies =
165 flags &
static_cast<std::int32_t
>(EMeshDualGraphOptions::VertexAdjacent);
166 auto const fKeepAdjacency =
167 [=]([[maybe_unused]]
auto row, [[maybe_unused]]
auto col,
auto degree) {
168 bool const bKeep = (degree == 3 and bKeepFaceAdjacencies) or
169 (degree == 2 and bKeepEdgeAdjacencies) or
170 (degree == 1 and bKeepVertexAdjacencies);
173 GTG.prune(fKeepAdjacency);
auto MeshAdjacencyMatrix(Eigen::DenseBase< TDerivedE > const &E, Eigen::DenseBase< TDerivedW > const &w, TIndex nNodes=TIndex(-1), bool bVertexToElement=false, bool bHasDuplicates=false) -> Eigen::SparseMatrix< TScalar, Eigen::ColMajor, TIndex >
Construct adjacency matrix from mesh.
Definition Mesh.h:42
auto MeshPrimalGraph(Eigen::DenseBase< TDerivedE > const &E, TIndex nNodes=TIndex(-1)) -> Eigen::SparseMatrix< TIndex, Eigen::ColMajor, TIndex >
Construct primal graph of input mesh, i.e. the graph of adjacent vertices.
Definition Mesh.h:117
auto MeshDualGraph(Eigen::DenseBase< TDerivedE > const &E, TIndex nNodes=TIndex(-1), EMeshDualGraphOptions opts=EMeshDualGraphOptions::All) -> Eigen::SparseMatrix< TIndex, Eigen::ColMajor, TIndex >
Construct dual graph of input mesh, i.e. the graph of adjacent elements.
Definition Mesh.h:147