Skip to content

Commit

Permalink
[SofaSparseSolver] Clean examples scenes of sparse linear solvers (#2422
Browse files Browse the repository at this point in the history
)

* [SofaSparseSolver] Remove scenes as their equivalent are in examples\Components\linearsolver

* [examples] Add example for PrecomputedLinearSolver

* [examples] Add example for SVDLinearSolver

* [SofaSparseSolver] msg_info without parameter

* Cleaning

* [examples] Speed up the example using multithreading

* Turn multithreading on

* [examples] Run only a few iterations to test FEMBAR-SVDLinearSolver.scn

* Lower number of iterations

* Clean scenes

Remove collision components
Add a scene for CGLinearSolver
Set the right RequiredPlugin

* ignore FEMBAR-SVDLinearSolver.scn on the CI
  • Loading branch information
alxbilger authored Oct 22, 2021
1 parent d5fcd45 commit 7eac779
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 107 deletions.
10 changes: 5 additions & 5 deletions examples/.scene-tests
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ timeout "Components/solver/NewmarkImplicitSolver.scn" "60"
iterations "Components/forcefield/FastTetrahedronCorotationalForceField_validation.scn" "10"
timeout "Components/forcefield/FastTetrahedronCorotationalForceField_validation.scn" "90"

timeout "Components/linearsolver/MatrixContributions123.scn" "60"


# [Slow] Long compute only a few iterations
iterations "Components/mapping/BarycentricMapping.scn" "10"
timeout "Components/mapping/BarycentricMapping.scn" "60"
Expand All @@ -17,6 +14,9 @@ timeout "Components/mapping/BarycentricMapping.scn" "60"
iterations "Components/linearsolver/MatrixContributions123.scn" "10"
timeout "Components/linearsolver/MatrixContributions123.scn" "60"

# [Slow] Dense solver: takes too long to compute even a single iteration
ignore "Components/linearsolver/FEMBAR-SVDLinearSolver.scn"

# [Slow] Long compute only a few iterations
iterations "Components/mapping/SPHFluidSurfaceMapping.scn" "10"
timeout "Components/mapping/SPHFluidSurfaceMapping.scn" "60"
Expand All @@ -25,11 +25,11 @@ timeout "Components/mapping/SPHFluidSurfaceMapping.scn" "60"
iterations "Components/animationloop/FreeMotionAnimationLoop.scn" "10"
timeout "Components/animationloop/FreeMotionAnimationLoop.scn" "180"

# [Slow] Long
# [Slow] Long
iterations "Components/topology/TopologicalModifiers/RemovingTetra2TriangleProcess_performanceTest.scn" "10"
timeout "Components/topology/TopologicalModifiers/RemovingTetra2TriangleProcess_performanceTest.scn" "180"

# [Warning] Temporarily ignore this scene, because it produces litterally
# [Warning] Temporarily ignore this scene, because it produces literally
# millions of warnings:
# WARNING[default2(MinProximityIntersection)]: WARNING: null distance between contact detected
ignore "Tutorials/Mappings/TutorialMappingOctopusArticulated.scn"
Expand Down
4 changes: 2 additions & 2 deletions examples/Benchmark/Performance/TorusFall.scn
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

<VisualStyle displayFlags="showVisual showCollisionModels hideBehaviorModels showForceFields hideInteractionForceFields hideWireframe" />

<FreeMotionAnimationLoop name="animationLoop" solveVelocityConstraintFirst="true" />
<GenericConstraintSolver name="constraintSolver" maxIterations="100" tolerance="1.0e-9" multithreading="0"/>
<FreeMotionAnimationLoop name="animationLoop" solveVelocityConstraintFirst="true" parallelCollisionDetectionAndFreeMotion="true" parallelODESolving="true"/>
<GenericConstraintSolver name="constraintSolver" maxIterations="100" tolerance="1.0e-9" multithreading="1"/>
<DefaultPipeline name="Pipeline" />
<BruteForceBroadPhase name="BroadPhase" />
<BVHNarrowPhase name="NarrowPhase" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<Node name="root" dt="0.02" gravity="0 -10 0">
<RequiredPlugin name="SofaBoundaryCondition"/>
<RequiredPlugin name="SofaImplicitOdeSolver"/>
<RequiredPlugin name="SofaMiscCollision"/>
<RequiredPlugin name="SofaSimpleFem"/>
<RequiredPlugin name="SofaSparseSolver"/>

<VisualStyle displayFlags="showBehaviorModels showForceFields" />

<DefaultAnimationLoop/>
<DefaultVisualManagerLoop/>

<Node name="M1">
<EulerImplicitSolver name="odesolver" printLog="false" rayleighStiffness="0.1" rayleighMass="0.1" />
<SparseLDLSolver printLog="false" template="CompressedRowSparseMatrixMat3x3d"/>
<!-- You can assemble the matrix using scalar instead of blocks by changing the SparseLDLSolver template as follows:
<SparseLDLSolver printLog="false" template="CompressedRowSparseMatrixd"/>
-->
<EulerImplicitSolver name="odesolver" rayleighStiffness="0.1" rayleighMass="0.1" />
<CGLinearSolver iterations="1000" threshold="1e-5" tolerance="1e-5"/>
<MechanicalObject />
<UniformMass vertexMass="1" />
<RegularGridTopology nx="4" ny="4" nz="20" xmin="-9" xmax="-6" ymin="0" ymax="3" zmin="0" zmax="19" />
Expand Down
25 changes: 11 additions & 14 deletions examples/Components/linearsolver/FEMBAR-PCGLinearSolver.scn
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
<Node name="root" dt="0.02" gravity="0 -10 0">
<RequiredPlugin pluginName="SofaSparseSolver"/>
<RequiredPlugin pluginName='SofaBoundaryCondition'/>
<RequiredPlugin pluginName='SofaImplicitOdeSolver'/>
<RequiredPlugin pluginName='SofaMiscCollision'/>
<RequiredPlugin pluginName='SofaSimpleFem'/>
<RequiredPlugin pluginName='SofaPreconditioner'/>
<RequiredPlugin name="SofaBoundaryCondition"/>
<RequiredPlugin name="SofaImplicitOdeSolver"/>
<RequiredPlugin name="SofaSimpleFem"/>
<RequiredPlugin name="SofaSparseSolver"/>
<RequiredPlugin name="SofaPreconditioner"/>

<VisualStyle displayFlags="showBehaviorModels showForceFields" />
<DefaultPipeline depth="6" verbose="0" draw="0" />
<BruteForceBroadPhase/>
<BVHNarrowPhase/>
<MinProximityIntersection name="Proximity" alarmDistance="0.5" contactDistance="0.3" />
<DefaultContactManager name="Response" response="default" />
<DefaultCollisionGroupManager name="Group" />

<DefaultAnimationLoop/>
<DefaultVisualManagerLoop/>

<Node name="M1">
<EulerImplicitSolver name="cg_odesolver" printLog="false" rayleighStiffness="0.1" rayleighMass="0.1" />
<ShewchukPCGLinearSolver iterations="1000" printLog="0" />
<EulerImplicitSolver name="odesolver" rayleighStiffness="0.1" rayleighMass="0.1" />
<ShewchukPCGLinearSolver iterations="1000" />
<MechanicalObject />
<UniformMass vertexMass="1" />
<RegularGridTopology nx="4" ny="4" nz="20" xmin="-9" xmax="-6" ymin="0" ymax="3" zmin="0" zmax="19" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Node name="root" dt="0.02" gravity="0 -10 0">
<RequiredPlugin name="SofaBoundaryCondition"/>
<RequiredPlugin name="SofaImplicitOdeSolver"/>
<RequiredPlugin name="SofaSimpleFem"/>
<RequiredPlugin name="SofaSparseSolver"/>

<VisualStyle displayFlags="showBehaviorModels showForceFields" />

<DefaultAnimationLoop/>
<DefaultVisualManagerLoop/>

<Node name="M1">
<EulerImplicitSolver name="odesolver" rayleighStiffness="0.1" rayleighMass="0.1" />
<PrecomputedLinearSolver/>
<MechanicalObject />
<UniformMass vertexMass="1" />
<RegularGridTopology nx="4" ny="4" nz="20" xmin="-9" xmax="-6" ymin="0" ymax="3" zmin="0" zmax="19" />
<FixedConstraint indices="0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" />
<HexahedronFEMForceField name="FEM" youngModulus="400000" poissonRatio="0.3" method="large" />
</Node>
</Node>
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<Node name="root" dt="0.02" gravity="0 -10 0">
<RequiredPlugin name="SofaBoundaryCondition"/>
<RequiredPlugin name="SofaImplicitOdeSolver"/>
<RequiredPlugin name="SofaSimpleFem"/>
<RequiredPlugin name="SofaDenseSolver"/>

<VisualStyle displayFlags="showBehaviorModels showForceFields" />
<CollisionPipeline depth="6" verbose="0" draw="0" />
<BruteForceBroadPhase/>
<BVHNarrowPhase/>
<MinProximityIntersection name="Proximity" alarmDistance="0.5" contactDistance="0.3" />
<CollisionResponse name="Response" response="default" />
<CollisionGroup name="Group" />

<DefaultAnimationLoop/>
<DefaultVisualManagerLoop/>

<Node name="M1">
<EulerImplicit name="cg_odesolver" printLog="false" rayleighStiffness="0.1" rayleighMass="0.1" />
<SparseLUSolver printLog="1" verbose="0" />
<EulerImplicitSolver name="odesolver" rayleighStiffness="0.1" rayleighMass="0.1" />
<SVDLinearSolver template="CompressedRowSparseMatrixMat3x3d"/>
<MechanicalObject />
<UniformMass vertexMass="1" />
<RegularGridTopology nx="4" ny="4" nz="20" xmin="-9" xmax="-6" ymin="0" ymax="3" zmin="0" zmax="19" />
Expand Down
23 changes: 10 additions & 13 deletions examples/Components/linearsolver/FEMBAR-SparseCholeskySolver.scn
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
<Node name="root" dt="0.02" gravity="0 -10 0">
<RequiredPlugin pluginName="SofaSparseSolver"/>
<RequiredPlugin pluginName='SofaBoundaryCondition'/>
<RequiredPlugin pluginName='SofaImplicitOdeSolver'/>
<RequiredPlugin pluginName='SofaMiscCollision'/>
<RequiredPlugin pluginName='SofaSimpleFem'/>
<RequiredPlugin name="SofaBoundaryCondition"/>
<RequiredPlugin name="SofaImplicitOdeSolver"/>
<RequiredPlugin name="SofaSimpleFem"/>
<RequiredPlugin name="SofaSparseSolver"/>

<VisualStyle displayFlags="showBehaviorModels showForceFields" />
<DefaultPipeline depth="6" verbose="0" draw="0" />
<BruteForceBroadPhase/>
<BVHNarrowPhase/>
<MinProximityIntersection name="Proximity" alarmDistance="0.5" contactDistance="0.3" />
<DefaultContactManager name="Response" response="default" />
<DefaultCollisionGroupManager name="Group" />

<DefaultAnimationLoop/>
<DefaultVisualManagerLoop/>

<Node name="M1">
<EulerImplicitSolver name="cg_odesolver" printLog="false" rayleighStiffness="0.1" rayleighMass="0.1" />
<SparseCholeskySolver printLog="0" verbose="0" />
<EulerImplicitSolver name="odesolver" rayleighStiffness="0.1" rayleighMass="0.1" />
<SparseCholeskySolver />
<MechanicalObject />
<UniformMass vertexMass="1" />
<RegularGridTopology nx="4" ny="4" nz="20" xmin="-9" xmax="-6" ymin="0" ymax="3" zmin="0" zmax="19" />
Expand Down
23 changes: 10 additions & 13 deletions examples/Components/linearsolver/FEMBAR-SparseLDLSolver.scn
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
<Node name="root" dt="0.02" gravity="0 -10 0">
<RequiredPlugin pluginName="SofaSparseSolver"/>
<RequiredPlugin pluginName='SofaBoundaryCondition'/>
<RequiredPlugin pluginName='SofaImplicitOdeSolver'/>
<RequiredPlugin pluginName='SofaMiscCollision'/>
<RequiredPlugin pluginName='SofaSimpleFem'/>
<RequiredPlugin name="SofaBoundaryCondition"/>
<RequiredPlugin name="SofaImplicitOdeSolver"/>
<RequiredPlugin name="SofaSimpleFem"/>
<RequiredPlugin name="SofaSparseSolver"/>

<VisualStyle displayFlags="showBehaviorModels showForceFields" />
<DefaultPipeline depth="6" verbose="0" draw="0" />
<BruteForceBroadPhase/>
<BVHNarrowPhase/>
<MinProximityIntersection name="Proximity" alarmDistance="0.5" contactDistance="0.3" />
<DefaultContactManager name="Response" response="default" />
<DefaultCollisionGroupManager name="Group" />

<DefaultAnimationLoop/>
<DefaultVisualManagerLoop/>

<Node name="M1">
<EulerImplicitSolver name="cg_odesolver" printLog="false" rayleighStiffness="0.1" rayleighMass="0.1" />
<SparseLDLSolver printLog="1"/>
<EulerImplicitSolver name="odesolver" rayleighStiffness="0.1" rayleighMass="0.1" />
<SparseLDLSolver template="CompressedRowSparseMatrixMat3x3d"/>
<MechanicalObject />
<UniformMass vertexMass="1" />
<RegularGridTopology nx="4" ny="4" nz="20" xmin="-9" xmax="-6" ymin="0" ymax="3" zmin="0" zmax="19" />
Expand Down
23 changes: 10 additions & 13 deletions examples/Components/linearsolver/FEMBAR-SparseLUSolver.scn
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
<Node name="root" dt="0.02" gravity="0 -10 0">
<RequiredPlugin pluginName="SofaSparseSolver"/>
<RequiredPlugin pluginName='SofaBoundaryCondition'/>
<RequiredPlugin pluginName='SofaImplicitOdeSolver'/>
<RequiredPlugin pluginName='SofaMiscCollision'/>
<RequiredPlugin pluginName='SofaSimpleFem'/>
<RequiredPlugin name="SofaBoundaryCondition"/>
<RequiredPlugin name="SofaImplicitOdeSolver"/>
<RequiredPlugin name="SofaSimpleFem"/>
<RequiredPlugin name="SofaSparseSolver"/>

<VisualStyle displayFlags="showBehaviorModels showForceFields" />
<DefaultPipeline depth="6" verbose="0" draw="0" />
<BruteForceBroadPhase/>
<BVHNarrowPhase/>
<MinProximityIntersection name="Proximity" alarmDistance="0.5" contactDistance="0.3" />
<DefaultContactManager name="Response" response="default" />
<DefaultCollisionGroupManager name="Group" />

<DefaultAnimationLoop/>
<DefaultVisualManagerLoop/>

<Node name="M1">
<EulerImplicitSolver name="cg_odesolver" printLog="false" rayleighStiffness="0.1" rayleighMass="0.1" />
<SparseLUSolver printLog="1" verbose="0"/>
<EulerImplicitSolver name="odesolver" rayleighStiffness="0.1" rayleighMass="0.1" />
<SparseLUSolver/>
<MechanicalObject />
<UniformMass vertexMass="1" />
<RegularGridTopology nx="4" ny="4" nz="20" xmin="-9" xmax="-6" ymin="0" ymax="3" zmin="0" zmax="19" />
Expand Down
28 changes: 0 additions & 28 deletions modules/SofaSparseSolver/examples/FEM_SparseCholeskySolver.scn

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void PrecomputedLinearSolver<TMatrix,TVector >::loadMatrix(TMatrix& M)
template<class TMatrix,class TVector>
void PrecomputedLinearSolver<TMatrix,TVector>::loadMatrixWithCSparse(TMatrix& M)
{
msg_info("PrecomputedLinearSolver") << "Compute the initial invert matrix with CS_PARSE" ;
msg_info() << "Compute the initial invert matrix with CS_PARSE" ;

CompressedRowSparseMatrix<double> matSolv;
FullVector<double> r;
Expand All @@ -143,15 +143,15 @@ void PrecomputedLinearSolver<TMatrix,TVector>::loadMatrixWithCSparse(TMatrix& M)
b.set(j,0.0);
}

msg_info("PrecomputedLinearSolver") << "Precomputing constraint correction LU decomposition " ;
msg_info() << "Precomputing constraint correction LU decomposition " ;
solver.invert(matSolv);

for (unsigned int j=0; j<systemSize; j++)
{
std::stringstream tmp;
tmp.precision(2);
tmp << "Precomputing constraint correction : " << std::fixed << (float)j/(float)systemSize*100.0f << " % " << '\xd';
msg_info("PrecomputedLinearSolver") << tmp.str() ;
msg_info() << tmp.str() ;

if (j>0) b.set(j-1,0.0);
b.set(j,1.0);
Expand All @@ -162,7 +162,7 @@ void PrecomputedLinearSolver<TMatrix,TVector>::loadMatrixWithCSparse(TMatrix& M)
internalData.Minv.set(j,i,r.element(i) * factInt);
}
}
msg_info("PrecomputedLinearSolver") << "Precomputing constraint correction : " << std::fixed << 100.0f << " % " << '\xd';
msg_info() << "Precomputing constraint correction : " << std::fixed << 100.0f << " % " << '\xd';

}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#define SOFA_COMPONENT_LINEARSOLVER_SPARSELUSOLVER_CPP
#include <sofa/core/ObjectFactory.h>
#include <SofaSparseSolver/SparseLUSolver.inl>

Expand All @@ -29,5 +30,7 @@ int SparseLUSolverClass = core::RegisterObject("Direct linear solver based on Sp
.add< SparseLUSolver< CompressedRowSparseMatrix<double>,FullVector<double> > >()
;

template class SOFA_SOFASPARSESOLVER_API SparseLUSolver< CompressedRowSparseMatrix<double>,FullVector<double> >;

} // namespace sofa::component::linearsolver

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
namespace sofa::component::linearsolver
{

//defaut structure for a LDL factorization
//defaut structure for a LU factorization
template<class Real>
class SparseLUInvertData : public MatrixInvertData {
public :
Expand Down Expand Up @@ -81,6 +81,10 @@ protected :

};

#if !defined(SOFA_COMPONENT_LINEARSOLVER_SPARSELUSOLVER_CPP)
extern template class SOFA_SOFASPARSESOLVER_API SparseLUSolver< CompressedRowSparseMatrix< double>,FullVector<double> >;
#endif

} // namespace sofa::component::linearsolver

#endif

0 comments on commit 7eac779

Please sign in to comment.