-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add all built-in solvers and several ordering methods (#1)
* Introduce LLT, LU and QR solvers * Choice of the ordering method * Add metis support * Optimal plugins * Link with Metis * find package metis * File encoding * Another try * Find metis for v21.12 * Fix CMakeLists.txt * unused variable * Remove find_package of metis * Missing template keyword * find_package SofaFramework * Make sure the linear solver module is found * Replace hard-coded value * Condition on finding the metis include file * Fix missing guard * Remove warning directive
- Loading branch information
Showing
28 changed files
with
710 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<Node name="root" dt="0.02" gravity="0 -10 0"> | ||
|
||
<Node name="plugins"> | ||
<RequiredPlugin name="EigenLinearSolvers"/> <!-- Needed to use components [EigenSimplicialLLT] --> | ||
<RequiredPlugin name="Sofa.Component.Constraint.Projective"/> <!-- Needed to use components [FixedConstraint] --> | ||
<RequiredPlugin name="Sofa.Component.Mass"/> <!-- Needed to use components [UniformMass] --> | ||
<RequiredPlugin name="Sofa.Component.ODESolver.Backward"/> <!-- Needed to use components [EulerImplicitSolver] --> | ||
<RequiredPlugin name="Sofa.Component.SolidMechanics.FEM.Elastic"/> <!-- Needed to use components [HexahedronFEMForceField] --> | ||
<RequiredPlugin name="Sofa.Component.StateContainer"/> <!-- Needed to use components [MechanicalObject] --> | ||
<RequiredPlugin name="Sofa.Component.Topology.Container.Grid"/> <!-- Needed to use components [RegularGridTopology] --> | ||
<RequiredPlugin name="Sofa.Component.Visual"/> <!-- Needed to use components [VisualStyle] --> | ||
<RequiredPlugin name="SofaEngine"/> <!-- Needed to use components [BoxROI] --> | ||
|
||
</Node> | ||
|
||
<VisualStyle displayFlags="showBehaviorModels showForceFields" /> | ||
|
||
<DefaultAnimationLoop name="animationLoop"/> | ||
<DefaultVisualManagerLoop name="visualLoop"/> | ||
|
||
<EulerImplicitSolver name="odesolver" rayleighStiffness="0.1" rayleighMass="0.1" /> | ||
<EigenSimplicialLLT template="CompressedRowSparseMatrixMat3x3d" ordering="AMD"/> | ||
|
||
<RegularGridTopology name="grid" nx="4" ny="4" nz="20" xmin="-9" xmax="-6" ymin="0" ymax="3" zmin="0" zmax="19" /> | ||
<MechanicalObject name="DoFs" /> | ||
|
||
<UniformMass name="mass" totalMass="320" /> | ||
<HexahedronFEMForceField name="FEM" youngModulus="4000" poissonRatio="0.45" method="large" /> | ||
|
||
<BoxROI name="box" box="-10 -1 -0.0001 -5 4 0.0001"/> | ||
<FixedConstraint indices="@box.indices" /> | ||
|
||
</Node> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<Node name="root" dt="0.02" gravity="0 -10 0"> | ||
|
||
<Node name="plugins"> | ||
<RequiredPlugin name="EigenLinearSolvers"/> <!-- Needed to use components [EigenSparseLU] --> | ||
<RequiredPlugin name="Sofa.Component.Constraint.Projective"/> <!-- Needed to use components [FixedConstraint] --> | ||
<RequiredPlugin name="Sofa.Component.Mass"/> <!-- Needed to use components [UniformMass] --> | ||
<RequiredPlugin name="Sofa.Component.ODESolver.Backward"/> <!-- Needed to use components [EulerImplicitSolver] --> | ||
<RequiredPlugin name="Sofa.Component.SolidMechanics.FEM.Elastic"/> <!-- Needed to use components [HexahedronFEMForceField] --> | ||
<RequiredPlugin name="Sofa.Component.StateContainer"/> <!-- Needed to use components [MechanicalObject] --> | ||
<RequiredPlugin name="Sofa.Component.Topology.Container.Grid"/> <!-- Needed to use components [RegularGridTopology] --> | ||
<RequiredPlugin name="Sofa.Component.Visual"/> <!-- Needed to use components [VisualStyle] --> | ||
<RequiredPlugin name="SofaEngine"/> <!-- Needed to use components [BoxROI] --> | ||
|
||
</Node> | ||
|
||
<VisualStyle displayFlags="showBehaviorModels showForceFields" /> | ||
|
||
<DefaultAnimationLoop name="animationLoop"/> | ||
<DefaultVisualManagerLoop name="visualLoop"/> | ||
|
||
<EulerImplicitSolver name="odesolver" rayleighStiffness="0.1" rayleighMass="0.1" /> | ||
<EigenSparseLU template="CompressedRowSparseMatrixMat3x3d" ordering="Natural"/> | ||
|
||
<RegularGridTopology name="grid" nx="4" ny="4" nz="20" xmin="-9" xmax="-6" ymin="0" ymax="3" zmin="0" zmax="19" /> | ||
<MechanicalObject name="DoFs" /> | ||
|
||
<UniformMass name="mass" totalMass="320" /> | ||
<HexahedronFEMForceField name="FEM" youngModulus="4000" poissonRatio="0.45" method="large" /> | ||
|
||
<BoxROI name="box" box="-10 -1 -0.0001 -5 4 0.0001"/> | ||
<FixedConstraint indices="@box.indices" /> | ||
|
||
</Node> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
#include <EigenLinearSolvers/config.h> | ||
|
||
namespace EigenLinearSolvers | ||
{ | ||
|
||
template<class TMatrix, class TVector, class EigenSolver> | ||
class EigenDirectSparseSolver | ||
{ | ||
public: | ||
virtual ~EigenDirectSparseSolver() = default; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#pragma once | ||
#include <EigenLinearSolvers/config.h> | ||
|
||
#include <EigenLinearSolvers/EigenDirectSparseSolver.h> | ||
|
||
#if __has_include(<sofa/component/linearsolver/iterative/MatrixLinearSolver.h>) | ||
#include <sofa/component/linearsolver/iterative/MatrixLinearSolver.h> | ||
#else | ||
#include <SofaBaseLinearSolver/MatrixLinearSolver.h> | ||
#endif | ||
|
||
#include <variant> | ||
#include <Eigen/SparseCore> | ||
|
||
#include <sofa/helper/OptionsGroup.h> | ||
#include <EigenLinearSolvers/FindMetis.h> | ||
|
||
namespace EigenLinearSolvers | ||
{ | ||
|
||
/** | ||
* Partial template specialization of EigenDirectSparseSolver for a matrix of type CompressedRowSparseMatrix | ||
*/ | ||
template<class TBlockType, class EigenSolver> | ||
class EigenDirectSparseSolver< | ||
sofa::linearalgebra::CompressedRowSparseMatrix<TBlockType>, | ||
sofa::linearalgebra::FullVector<typename sofa::linearalgebra::CompressedRowSparseMatrix<TBlockType>::Real>, | ||
EigenSolver > | ||
: public sofa::component::linearsolver::MatrixLinearSolver< | ||
sofa::linearalgebra::CompressedRowSparseMatrix<TBlockType>, | ||
sofa::linearalgebra::FullVector<typename sofa::linearalgebra::CompressedRowSparseMatrix<TBlockType>::Real> > | ||
{ | ||
public: | ||
typedef sofa::linearalgebra::CompressedRowSparseMatrix<TBlockType> Matrix; | ||
using Real = typename Matrix::Real; | ||
typedef sofa::linearalgebra::FullVector<Real> Vector; | ||
|
||
SOFA_ABSTRACT_CLASS(SOFA_TEMPLATE3(EigenDirectSparseSolver, Matrix, Vector, EigenSolver), | ||
SOFA_TEMPLATE2(sofa::component::linearsolver::MatrixLinearSolver, Matrix, Vector)); | ||
|
||
using NaturalOrderSolver = typename EigenSolver::NaturalOrderSolver; | ||
using AMDOrderSolver = typename EigenSolver::AMDOrderSolver; | ||
using COLAMDOrderSolver = typename EigenSolver::COLAMDOrderSolver; | ||
#if EIGENLINEARSOLVERS_HAS_METIS_INCLUDE == 1 | ||
using MetisOrderSolver = typename EigenSolver::MetisOrderSolver; | ||
#endif | ||
|
||
~EigenDirectSparseSolver() override = default; | ||
|
||
void init() override; | ||
void reinit() override; | ||
|
||
using EigenSparseMatrix = Eigen::SparseMatrix<Real, Eigen::RowMajor>; | ||
using EigenSparseMatrixMap = Eigen::Map<EigenSparseMatrix>; | ||
using EigenVectorXdMap = Eigen::Map<Eigen::Matrix<Real, Eigen::Dynamic, 1> >; | ||
|
||
void solve (Matrix& A, Vector& x, Vector& b) override; | ||
void invert(Matrix& A) override; | ||
|
||
protected: | ||
|
||
sofa::core::objectmodel::Data<sofa::helper::OptionsGroup> d_orderingMethod; | ||
unsigned int m_selectedOrderingMethod { std::numeric_limits<unsigned int>::max() }; | ||
|
||
std::variant<NaturalOrderSolver, AMDOrderSolver, COLAMDOrderSolver | ||
#if EIGENLINEARSOLVERS_HAS_METIS_INCLUDE == 1 | ||
, MetisOrderSolver | ||
#endif | ||
> m_solver; | ||
|
||
Eigen::ComputationInfo getSolverInfo() const; | ||
void updateSolverOderingMethod(); | ||
|
||
sofa::linearalgebra::CompressedRowSparseMatrix<Real> Mfiltered; | ||
std::unique_ptr<EigenSparseMatrixMap> m_map; | ||
|
||
typename sofa::linearalgebra::CompressedRowSparseMatrix<Real>::VecIndex MfilteredrowBegin; | ||
typename sofa::linearalgebra::CompressedRowSparseMatrix<Real>::VecIndex MfilteredcolsIndex; | ||
|
||
EigenDirectSparseSolver(); | ||
}; | ||
|
||
} |
Oops, something went wrong.