forked from sofa-framework/SofaPython3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemptyForceField.py
More file actions
76 lines (57 loc) · 2.35 KB
/
emptyForceField.py
File metadata and controls
76 lines (57 loc) · 2.35 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
64
65
66
67
68
69
70
71
72
73
74
75
76
import Sofa
from Sofa.Helper import msg_info
import numpy as np
# This python script shows the functions to be implemented
# in order to create your ForceField in python
class EmptyForceField(Sofa.Core.ForceFieldVec3d):
def __init__(self, *args, **kwargs):
Sofa.Core.ForceFieldVec3d.__init__(self, *args, **kwargs)
pass
# Function called at the component initialization
def init(self):
msg_info('init: not implemented yet')
pass
# Function implementing the explicit force f(x(t), v(t))
def addForce(self, m, forces, pos, vel):
msg_info('addForce: not implemented yet')
pass
# Function implementing the matrix-vector multiplication
# between the derivative of the force f with regards to
# the degrees of freedom, multiplied by a vector dx
def addDForce(self, m, dforce, dx):
msg_info('addDForce: not implemented yet')
pass
# Function implementing the matrix corresponding to the
# derivative of the force f with regards to the degrees
# of freedom
def addKToMatrix(self, mparams, nNodes, nDofs):
msg_info('addKToMatrix: not implemented yet')
pass
def createScene(root):
root.dt = 0.01
root.bbox = [[-1, -1, -1],[1,1,1]]
root.addObject("RequiredPlugin", pluginName=["Sofa.Component.LinearSolver.Iterative",
"Sofa.Component.ODESolver.Backward",
"Sofa.Component.StateContainer"
])
root.addObject('DefaultAnimationLoop')
node1 = root.addChild("Node1")
node1.addObject('EulerImplicitSolver')
node1.addObject('CGLinearSolver', iterations="100", tolerance="10-3", threshold="10-3")
node1.addObject('MechanicalObject', template="Vec3d")
# Add our python forcefield in the scene
node1.addObject( EmptyForceField(name="MyEmptyForceField") )
def main():
import SofaImGui
import Sofa.Gui
root=Sofa.Core.Node("root")
createScene(root)
Sofa.Simulation.initRoot(root)
Sofa.Gui.GUIManager.Init("myscene", "imgui")
Sofa.Gui.GUIManager.createGUI(root, __file__)
Sofa.Gui.GUIManager.SetDimension(1080, 1080)
Sofa.Gui.GUIManager.MainLoop(root)
Sofa.Gui.GUIManager.closeGUI()
print("End of simulation.")
if __name__ == '__main__':
main()