Skip to content

Commit 3a1c3b9

Browse files
committed
Remove useless controller
1 parent 8d0b67e commit 3a1c3b9

2 files changed

Lines changed: 18 additions & 41 deletions

File tree

bindings/Sofa/tests/Core/ForceField.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_2_implicit_direct(self):
9595
def simulate_beam(linear_solver_template):
9696
root = Sofa.Core.Node("rootNode")
9797

98-
loop = root.addObject('DefaultAnimationLoop')
98+
root.addObject('DefaultAnimationLoop')
9999

100100
root.addObject('RequiredPlugin', name='Sofa.Component.ODESolver.Backward')
101101
root.addObject('RequiredPlugin', name='Sofa.Component.LinearSolver.Direct')
@@ -110,40 +110,29 @@ def simulate_beam(linear_solver_template):
110110
root.addObject('MechanicalObject', name="DoFs")
111111
root.addObject('UniformMass', name="mass", totalMass="320")
112112
root.addObject('RegularGridTopology', name="grid", nx="4", ny="4", nz="20", xmin="-9", xmax="-6", ymin="0", ymax="3", zmin="0", zmax="19")
113-
root.addObject('BoxROI', name="box", box="-10 -1 -0.0001 -5 4 0.0001")
113+
root.addObject('BoxROI', name="box", box=[-10, -1, -0.0001, -5, 4, 0.0001])
114114
root.addObject('FixedConstraint', indices="@box.indices")
115-
force_field = root.addObject('HexahedronFEMForceField', name="FEM", youngModulus="4000", poissonRatio="0.3", method="large")
116-
117-
matrix_accessor = root.addObject(MatrixAccessController('MatrixAccessor', name='matrixAccessor', force_field=force_field))
115+
root.addObject('HexahedronFEMForceField', name="FEM", youngModulus="4000", poissonRatio="0.3", method="large")
118116

119117
Sofa.Simulation.init(root)
120118
Sofa.Simulation.animate(root, 0.0001)
121119

122-
return matrix_accessor.stiffness_matrix
120+
return root
123121

124122
def test_stiffness_matrix_access_scalar(self):
125123

126-
K = self.simulate_beam("CompressedRowSparseMatrixd")
124+
root = self.simulate_beam("CompressedRowSparseMatrixd")
125+
K = root.FEM.assembleKMatrix()
127126

128127
self.assertEqual(K.ndim, 2)
129128
self.assertEqual(K.shape, (960, 960))
130129
self.assertEqual(K.nnz, 52200)
131130

132131
def test_stiffness_matrix_access_blocks3x3(self):
133132

134-
K = self.simulate_beam("CompressedRowSparseMatrixMat3x3d")
133+
root = self.simulate_beam("CompressedRowSparseMatrixMat3x3d")
134+
K = root.FEM.assembleKMatrix()
135135

136136
self.assertEqual(K.ndim, 2)
137137
self.assertEqual(K.shape, (960, 960))
138138
self.assertEqual(K.nnz, 52200)
139-
140-
141-
class MatrixAccessController(Sofa.Core.Controller):
142-
143-
144-
def __init__(self, *args, **kwargs):
145-
Sofa.Core.Controller.__init__(self, *args, **kwargs)
146-
self.force_field = kwargs.get("force_field")
147-
148-
def onAnimateEndEvent(self, event):
149-
self.stiffness_matrix = self.force_field.assembleKMatrix()

bindings/Sofa/tests/Core/Mass.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Test(unittest.TestCase):
1313
def simulate_beam(linear_solver_template):
1414
root = Sofa.Core.Node("rootNode")
1515

16-
loop = root.addObject('DefaultAnimationLoop')
16+
root.addObject('DefaultAnimationLoop')
1717

1818
root.addObject('RequiredPlugin', name='Sofa.Component.ODESolver.Backward')
1919
root.addObject('RequiredPlugin', name='Sofa.Component.LinearSolver.Direct')
@@ -26,43 +26,31 @@ def simulate_beam(linear_solver_template):
2626
root.addObject('SparseLDLSolver', applyPermutation="false", template=linear_solver_template)
2727

2828
root.addObject('MechanicalObject', name="DoFs")
29-
mass = root.addObject('MeshMatrixMass', name="mass", totalMass="320")
29+
root.addObject('MeshMatrixMass', name="mass", totalMass="320")
3030
root.addObject('RegularGridTopology', name="grid", nx="4", ny="4", nz="20", xmin="-9", xmax="-6", ymin="0", ymax="3", zmin="0", zmax="19")
31-
root.addObject('BoxROI', name="box", box="-10 -1 -0.0001 -5 4 0.0001")
31+
root.addObject('BoxROI', name="box", box=[-10, -1, -0.0001, -5, 4, 0.0001])
3232
root.addObject('FixedConstraint', indices="@box.indices")
3333
root.addObject('HexahedronFEMForceField', name="FEM", youngModulus="4000", poissonRatio="0.3", method="large")
3434

35-
matrix_accessor = root.addObject(MatrixAccessController('MatrixAccessor', name='matrixAccessor', mass=mass))
36-
3735
Sofa.Simulation.init(root)
3836
Sofa.Simulation.animate(root, 0.0001)
3937

40-
return matrix_accessor.mass_matrix
38+
return root
4139

42-
def test_stiffness_matrix_access_scalar(self):
40+
def test_mass_matrix_access_scalar(self):
4341

44-
M = self.simulate_beam("CompressedRowSparseMatrixd")
42+
root = self.simulate_beam("CompressedRowSparseMatrixd")
43+
M = root.mass.assembleMMatrix()
4544

4645
self.assertEqual(M.ndim, 2)
4746
self.assertEqual(M.shape, (960, 960))
4847
self.assertEqual(M.nnz, 9480)
4948

50-
def test_stiffness_matrix_access_blocks3x3(self):
49+
def test_mass_matrix_access_blocks3x3(self):
5150

52-
M = self.simulate_beam("CompressedRowSparseMatrixMat3x3d")
51+
root = self.simulate_beam("CompressedRowSparseMatrixMat3x3d")
52+
M = root.mass.assembleMMatrix()
5353

5454
self.assertEqual(M.ndim, 2)
5555
self.assertEqual(M.shape, (960, 960))
5656
self.assertEqual(M.nnz, 9480)
57-
58-
59-
60-
class MatrixAccessController(Sofa.Core.Controller):
61-
62-
63-
def __init__(self, *args, **kwargs):
64-
Sofa.Core.Controller.__init__(self, *args, **kwargs)
65-
self.mass = kwargs.get("mass")
66-
67-
def onAnimateEndEvent(self, event):
68-
self.mass_matrix = self.mass.assembleMMatrix()

0 commit comments

Comments
 (0)