polyfem / polyfem

A polyvalent C++ FEM library
https://polyfem.github.io/
MIT License
465 stars 87 forks source link

Eigen version Clash when POLYSOLVE_WITH_ACCELERATE enabled #240

Open zfergus opened 1 year ago

zfergus commented 1 year ago

There is an issue with conflicting versions of Eigen when this option is enabled.

I get this compilation error:

In file included from /Users/zachary/.cache/CPM/ipc-toolkit/ff96ec46f901ecdd6203d75076174d996a5eae0d/src/ipc/friction/constraints/friction_constraint.cpp:1:
In file included from /Users/zachary/.cache/CPM/ipc-toolkit/ff96ec46f901ecdd6203d75076174d996a5eae0d/src/ipc/friction/constraints/friction_constraint.hpp:3:
In file included from /Users/zachary/.cache/CPM/ipc-toolkit/ff96ec46f901ecdd6203d75076174d996a5eae0d/src/ipc/collisions/collision_constraints.hpp:3:
In file included from /Users/zachary/.cache/CPM/ipc-toolkit/ff96ec46f901ecdd6203d75076174d996a5eae0d/src/ipc/collision_mesh.hpp:5:
In file included from /Users/zachary/.cache/CPM/eigen/2e68522bbe453e136c9b281a06f112155cbeafd8/Eigen/Core:329:
/Users/zachary/.cache/CPM/eigen/2e68522bbe453e136c9b281a06f112155cbeafd8/Eigen/src/Core/IndexedView.h:148:14: error: data member instantiated with function type 'bool ()'
  ColIndices m_colIndices;
             ^
/Users/zachary/.cache/CPM/ipc-toolkit/ff96ec46f901ecdd6203d75076174d996a5eae0d/src/ipc/friction/constraints/friction_constraint.cpp:284:25: note: in instantiation of template class 'Eigen::IndexedView<const Eigen::Matrix<double, -1, -1, 0, 6, 12>, Eigen::ArithmeticSequence<long, long, long>, bool ()>' requested here
                        jac_Gamma_wrt_beta(
                        ^
/Users/zachary/.cache/CPM/ipc-toolkit/ff96ec46f901ecdd6203d75076174d996a5eae0d/src/ipc/friction/constraints/friction_constraint.cpp:285:63: error: no member named 'all' in namespace 'Eigen'; did you mean 'Eigen::indexing::all'?
                            Eigen::seqN(i, beta.size(), dim), Eigen::all)
                                                              ^~~~~~~~~~
                                                              Eigen::indexing::all
/Users/zachary/.cache/CPM/eigen/2e68522bbe453e136c9b281a06f112155cbeafd8/Eigen/src/Core/ArithmeticSequence.h:250:30: note: 'Eigen::indexing::all' declared here
  using Eigen::placeholders::all;
                             ^
In file included from /Users/zachary/.cache/CPM/ipc-toolkit/ff96ec46f901ecdd6203d75076174d996a5eae0d/src/ipc/friction/constraints/friction_constraint.cpp:1:
In file included from /Users/zachary/.cache/CPM/ipc-toolkit/ff96ec46f901ecdd6203d75076174d996a5eae0d/src/ipc/friction/constraints/friction_constraint.hpp:3:
In file included from /Users/zachary/.cache/CPM/ipc-toolkit/ff96ec46f901ecdd6203d75076174d996a5eae0d/src/ipc/collisions/collision_constraints.hpp:3:
In file included from /Users/zachary/.cache/CPM/ipc-toolkit/ff96ec46f901ecdd6203d75076174d996a5eae0d/src/ipc/collision_mesh.hpp:5:
In file included from /Users/zachary/.cache/CPM/eigen/2e68522bbe453e136c9b281a06f112155cbeafd8/Eigen/Core:290:
In file included from /Users/zachary/.cache/CPM/eigen/2e68522bbe453e136c9b281a06f112155cbeafd8/Eigen/src/Core/DenseBase.h:662:
/Users/zachary/.cache/CPM/eigen/2e68522bbe453e136c9b281a06f112155cbeafd8/Eigen/src/Core/util/../../plugins/IndexedViewMethods.h:63:73: error: no matching member function for call to 'ivcCol'
    return ConstReturnType(derived, derived.ivcRow(rowIndices), derived.ivcCol(colIndices));
                                                                ~~~~~~~~^~~~~~
/Users/zachary/.cache/CPM/eigen/2e68522bbe453e136c9b281a06f112155cbeafd8/Eigen/src/Core/util/../../plugins/IndexedViewMethods.h:239:55: note: in instantiation of member function 'Eigen::DenseBase<Eigen::Matrix<double, -1, -1, 0, 6, 12>>::IndexedViewSelector<Eigen::ArithmeticSequence<long, long, long>, bool (), false, false, true>::run' requested here
  return IndexedViewSelector<RowIndices, ColIndices>::run(derived(), rowIndices, colIndices);
                                                      ^
/Users/zachary/.cache/CPM/ipc-toolkit/ff96ec46f901ecdd6203d75076174d996a5eae0d/src/ipc/friction/constraints/friction_constraint.cpp:284:25: note: in instantiation of function template specialization 'Eigen::DenseBase<Eigen::Matrix<double, -1, -1, 0, 6, 12>>::operator()<Eigen::ArithmeticSequence<long, long, long>, bool (), true>' requested here
                        jac_Gamma_wrt_beta(
                        ^
/Users/zachary/.cache/CPM/eigen/2e68522bbe453e136c9b281a06f112155cbeafd8/Eigen/src/Core/util/../../plugins/IndexedViewMethods.h:34:28: note: candidate template ignored: substitution failure [with Indices = bool ()]: function cannot return function type 'IvcColType<bool ()>' (aka 'bool ()')
inline IvcColType<Indices> ivcCol(const Indices& indices) const {
       ~~~~~~~~~~          ^
3 errors generated.
make[2]: *** [_deps/ipc-toolkit-build/CMakeFiles/ipc_toolkit.dir/src/ipc/friction/constraints/friction_constraint.cpp.o] Error 1
make[1]: *** [_deps/ipc-toolkit-build/CMakeFiles/ipc_toolkit.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

_Originally posted by @zfergus in https://github.com/polyfem/polyfem/pull/239#discussion_r1298966745_

zfergus commented 1 year ago

Through some clever rewrites of the Jacobian calculation done in the IPC Toolkit (https://github.com/ipc-sim/ipc-toolkit/pull/56), I can now compile the IPC Toolkit with the newer Eigen. Unfortunately, it hits a snag when it needs to compile libigl:

[ 74%] Building CXX object CMakeFiles/polyfem.dir/src/polyfem/basis/PolygonalBasis3d.cpp.o
In file included from /Users/zachary/Development/research/polyfem/polyfem/src/polyfem/basis/PolygonalBasis3d.cpp:18:
In file included from /Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/per_vertex_normals.h:77:
In file included from /Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/per_vertex_normals.cpp:11:
In file included from /Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/per_face_normals.h:76:
In file included from /Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/per_face_normals.cpp:104:
In file included from /Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/cotmatrix.h:79:
In file included from /Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/cotmatrix.cpp:84:
In file included from /Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/diag.h:59:
/Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/diag.cpp:75:10: error: no member named 'DynamicSparseMatrix' in namespace 'Eigen'
  Eigen::DynamicSparseMatrix<T, Eigen::RowMajor> dyn_X(V.size(),V.size());
  ~~~~~~~^
/Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/diag.cpp:75:30: error: 'T' does not refer to a value
  Eigen::DynamicSparseMatrix<T, Eigen::RowMajor> dyn_X(V.size(),V.size());
                             ^
/Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/diag.cpp:69:20: note: declared here
template <typename T>
                   ^
/Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/diag.cpp:76:3: error: use of undeclared identifier 'dyn_X'
  dyn_X.reserve(V.size());
  ^
/Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/diag.cpp:80:5: error: use of undeclared identifier 'dyn_X'
    dyn_X.coeffRef(it.index(),it.index()) += it.value();
    ^
/Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/diag.cpp:82:30: error: use of undeclared identifier 'dyn_X'
  X = Eigen::SparseMatrix<T>(dyn_X);
                             ^
/Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/diag.cpp:92:10: error: no member named 'DynamicSparseMatrix' in namespace 'Eigen'
  Eigen::DynamicSparseMatrix<T, Eigen::RowMajor> dyn_X(V.size(),V.size());
  ~~~~~~~^
/Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/diag.cpp:92:30: error: 'T' does not refer to a value
  Eigen::DynamicSparseMatrix<T, Eigen::RowMajor> dyn_X(V.size(),V.size());
                             ^
/Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/diag.cpp:85:20: note: declared here
template <typename T, typename DerivedV>
                   ^
/Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/diag.cpp:93:3: error: use of undeclared identifier 'dyn_X'
  dyn_X.reserve(V.size());
  ^
/Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/diag.cpp:97:5: error: use of undeclared identifier 'dyn_X'
    dyn_X.coeffRef(i,i) += V[i];
    ^
/Users/zachary/.cache/CPM/libigl/121135a7e89a917cf11e894acdbecd58f5460544/include/igl/diag.cpp:99:30: error: use of undeclared identifier 'dyn_X'
  X = Eigen::SparseMatrix<T>(dyn_X);
                             ^
10 errors generated.
make[2]: *** [CMakeFiles/polyfem.dir/src/polyfem/basis/PolygonalBasis3d.cpp.o] Error 1
make[1]: *** [CMakeFiles/polyfem.dir/all] Error 2
make: *** [all] Error 2

It looks like we need to bug the libigl folks to remove the usage of the deprecated Eigen::DynamicSparseMatrix.

jdumas commented 1 year ago

DynamicSparseMatrix stuff was removed from libigl last year as part of https://github.com/libigl/libigl/pull/2016. You should be able to simply update the libigl version used in PolyFEM.

zfergus commented 1 year ago

Oh, thanks for letting me know! Maybe they should release a new version (the last one was Feb. 2022).

zfergus commented 1 year ago

Dang, so close!

[ 59%] Building CXX object _deps/wildmeshing-toolkit-build/CMakeFiles/wildmeshing_toolkit.dir/src/wmtk/utils/InsertTriangleUtils.cpp.o
In file included from /Users/zachary/.cache/CPM/wildmeshing-toolkit/a785d7e79c8a55035c3bcc3873c9730090efc95a/src/wmtk/utils/InsertTriangleUtils.cpp:3:
In file included from /Users/zachary/.cache/CPM/libigl/3d08427119f752ef9c9358f32224f9bb34efd025/include/igl/remove_duplicate_vertices.h:55:
/Users/zachary/.cache/CPM/libigl/3d08427119f752ef9c9358f32224f9bb34efd025/include/igl/predicates/../remove_duplicate_vertices.cpp:35:33: error: no member named 'all' in namespace 'Eigen'
    SV = V(SVI.derived(),Eigen::all);
                         ~~~~~~~^

I think Eigen::all was renamed to Eigen::placeholders::all

jdumas commented 1 year ago

That may be a change with the development version of Eigen, but I think the latest stable release still uses Eigen::all.

As for tagging a new release of libigl you'll have to check with @alecjacobson. I'm not involved in libigl development anymore.