@@ -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