-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathMass.py
More file actions
63 lines (46 loc) · 2.51 KB
/
Copy pathMass.py
File metadata and controls
63 lines (46 loc) · 2.51 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
53
54
55
56
57
58
59
60
61
62
63
# coding: utf8
import unittest
import Sofa
import Sofa.Core
import Sofa.Helper
import Sofa.Simulation
import SofaRuntime
class Test(unittest.TestCase):
@staticmethod
def simulate_beam(linear_solver_template):
root = Sofa.Core.Node("rootNode")
root.addObject('DefaultAnimationLoop')
root.addObject('RequiredPlugin', pluginName='Sofa.Component.StateContainer')
root.addObject('RequiredPlugin', pluginName='Sofa.Component.IntegrationScheme.Backward')
root.addObject('RequiredPlugin', pluginName='Sofa.Component.LinearSolver.Direct')
root.addObject('RequiredPlugin', pluginName='Sofa.Component.Engine.Select')
root.addObject('RequiredPlugin', pluginName='Sofa.Component.Constraint.Projective')
root.addObject('RequiredPlugin', pluginName='Sofa.Component.SolidMechanics.FEM.Elastic')
root.addObject('RequiredPlugin', pluginName='Sofa.Component.Mass')
root.addObject('RequiredPlugin', pluginName='Sofa.Component.Topology.Container.Grid')
root.addObject('EulerImplicitIntegrationScheme', rayleighStiffness="0.1", rayleighMass="0.1")
root.addObject('SparseLDLSolver', template=linear_solver_template)
root.addObject('MechanicalObject', name="DoFs")
root.addObject('MeshMatrixMass', name="mass", totalMass="320")
root.addObject('RegularGridTopology', name="grid", nx="4", ny="4", nz="20", xmin="-9", xmax="-6", ymin="0", ymax="3", zmin="0", zmax="19")
root.addObject('BoxROI', name="box", box=[-10, -1, -0.0001, -5, 4, 0.0001])
root.addObject('FixedConstraint', indices="@box.indices")
root.addObject('HexahedronFEMForceField', name="FEM", youngModulus="4000", poissonRatio="0.3", method="large")
Sofa.Simulation.initRoot(root)
Sofa.Simulation.animate(root, 0.0001)
return root
def test_mass_matrix_access_scalar(self):
root = self.simulate_beam("CompressedRowSparseMatrixd")
M = root.mass.assembleMMatrix()
self.assertEqual(M.ndim, 2)
self.assertEqual(M.shape, (960, 960))
self.assertEqual(M.nnz, 9480)
def test_mass_matrix_access_blocks3x3(self):
root = self.simulate_beam("CompressedRowSparseMatrixMat3x3d")
M = root.mass.assembleMMatrix()
self.assertEqual(M.ndim, 2)
self.assertEqual(M.shape, (960, 960))
self.assertEqual(M.nnz, 9480)
def test_mass_mstate(self):
root = self.simulate_beam("CompressedRowSparseMatrixMat3x3d")
self.assertNotEqual(root.mass.mstate, None)