-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathmatrix_access.py
More file actions
52 lines (41 loc) · 2.67 KB
/
Copy pathmatrix_access.py
File metadata and controls
52 lines (41 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import unittest
import Sofa.Core
from Sofa import SofaConstraintSolver
class Test(unittest.TestCase):
def simulate_pendulum(self):
root = Sofa.Core.Node("rootNode")
root.addObject("RequiredPlugin", pluginName=["Sofa.Component.AnimationLoop",
"Sofa.Component.Constraint.Lagrangian.Correction",
"Sofa.Component.Constraint.Lagrangian.Model",
"Sofa.Component.Constraint.Lagrangian.Solver",
"Sofa.Component.Constraint.Projective",
"Sofa.Component.IO.Mesh",
"Sofa.Component.LinearSolver.Direct",
"Sofa.Component.Mapping.NonLinear",
"Sofa.Component.Mapping.MappedMatrix",
"Sofa.Component.Mass",
"Sofa.Component.IntegrationScheme.Backward",
"Sofa.Component.Topology.Container.Dynamic"])
root.addObject("FreeMotionAnimationLoop", solveVelocityConstraintFirst=True)
root.addObject("BlockGaussSeidelConstraintSolver", name="constraint_solver", tolerance=1e-9, maxIterations=1000)
root.addObject("StringMeshCreator", name="loader", resolution="20")
root.addObject("EulerImplicitIntegrationScheme")
root.addObject("EigenSimplicialLLT")
root.addObject("GenericConstraintCorrection")
root.addObject("EdgeSetTopologyContainer", name="edge_container", position="@loader.position", edges="@loader.edges")
root.addObject("MechanicalObject", name="defoDOF", template="Vec3d")
root.addObject("EdgeSetGeometryAlgorithms", drawEdges=True)
root.addObject("FixedConstraint", indices=[0])
root.addObject("DiagonalMass", name="mass", totalMass="1e-3")
ext = root.addChild("extensionsNode")
ext.addObject("MechanicalObject", template="Vec1d", name="extensionsDOF")
ext.addObject("DistanceMapping", name="distanceMapping", topology="@../edge_container")
ext.addObject("UniformConstraint", template="Vec1d", iterative=True)
Sofa.Simulation.initRoot(root)
Sofa.Simulation.animate(root, 0.0001)
return root
def test_matrix_access(self):
root = self.simulate_pendulum()
W = root.constraint_solver.W()
self.assertEqual(W.ndim, 2)
self.assertEqual(W.shape, (19, 19))