Problem with soft and rigid body collision #4033
Replies: 4 comments
-
Hi @Thanit09 So sorry for the delay, most of the team was in summer vacations! Regarding your rigid sphere, since it is a rigid body, no need to use a full mesh for the physics : all you need is one rigid frame in charge of the rigid motion. You could still map on this frame any mesh as a collision mesh. The behavior that you noticed with the collision models is due to the fact that you are using penalities and this needs fine tuning.
An example of this is available in the FrictionContact example. In your case, a working example would be: # Required import for python
import Sofa
# Choose in your script to activate or not the GUI
USE_GUI = True
def main():
import SofaRuntime
import Sofa.Gui
root = Sofa.Core.Node("root")
createScene(root)
Sofa.Simulation.init(root)
if not USE_GUI:
for iteration in range(10):
Sofa.Simulation.animate(root, root.dt.value)
else:
Sofa.Gui.GUIManager.Init("myscene", "qglviewer")
Sofa.Gui.GUIManager.createGUI(root, __file__)
Sofa.Gui.GUIManager.SetDimension(1080, 1080)
Sofa.Gui.GUIManager.MainLoop(root)
Sofa.Gui.GUIManager.closeGUI()
def createScene(root):
root.gravity=[0, -9.81, 0]
root.dt=0.02
root.addObject("RequiredPlugin", pluginName=[ 'Sofa.Component.Collision.Detection.Algorithm',
'Sofa.Component.Collision.Detection.Intersection',
'Sofa.Component.Collision.Geometry',
'Sofa.Component.Collision.Response.Contact',
'Sofa.Component.Constraint.Projective',
'Sofa.Component.IO.Mesh',
'Sofa.Component.LinearSolver.Iterative',
'Sofa.Component.Mapping.Linear',
'Sofa.Component.Mass',
'Sofa.Component.ODESolver.Backward',
'Sofa.Component.SolidMechanics.FEM.Elastic',
'Sofa.Component.StateContainer',
'Sofa.Component.Topology.Container.Dynamic',
'Sofa.Component.Visual',
'Sofa.GL.Component.Rendering3D'
])
root.addObject('VisualStyle', displayFlags="showCollisionModels hideVisualModels showForceFields")
root.addObject('FreeMotionAnimationLoop')
root.addObject('GenericConstraintSolver', maxIterations=1000, tolerance=1e-6)
root.addObject('CollisionPipeline', name="CollisionPipeline")
root.addObject('BruteForceBroadPhase', name="BroadPhase")
root.addObject('BVHNarrowPhase', name="NarrowPhase")
root.addObject('DefaultContactManager', name="CollisionResponse", response="FrictionContactConstraint")
root.addObject('MinProximityIntersection', useLineLine=True, usePointPoint=True, alarmDistance=0.3, contactDistance=0.15, useLinePoint=True)
root.addObject('MeshOBJLoader', name="LiverSurface", filename="mesh/liver-smooth.obj")
liver = root.addChild('Liver')
liver.addObject('EulerImplicitSolver', name="cg_odesolver", rayleighStiffness=0.1, rayleighMass=0.1)
liver.addObject('SparseLDLSolver', name="linear_solver", template="CompressedRowSparseMatrixMat3x3d")
liver.addObject('MeshGmshLoader', name="meshLoader", filename="mesh/liver.msh")
liver.addObject('TetrahedronSetTopologyContainer', name="topo", src="@meshLoader")
liver.addObject('MechanicalObject', name="dofs", src="@meshLoader")
liver.addObject('TetrahedronSetGeometryAlgorithms', template="Vec3d", name="GeomAlgo")
liver.addObject('DiagonalMass', name="Mass", massDensity=1.0)
liver.addObject('TetrahedralCorotationalFEMForceField', template="Vec3d", name="FEM", method="large", poissonRatio=0.3, youngModulus=3000, computeGlobalMatrix=False)
liver.addObject('FixedConstraint', name="FixedConstraint", indices="3 39 64")
liver.addObject('LinearSolverConstraintCorrection')
LiverSurf = liver.addChild('ExtractSurface')
LiverSurf.addObject('TriangleSetTopologyContainer', name="Container", position="@../topo.position")
LiverSurf.addObject('TriangleSetTopologyModifier', name="Modifier")
LiverSurf.addObject('Tetra2TriangleTopologicalMapping', name="SurfaceExtractMapping", input="@../topo", output="@Container")
LiverCollision = LiverSurf.addChild('Surf')
LiverCollision.addObject('TriangleSetTopologyContainer', name="Container", src="@../Container")
LiverCollision.addObject('MechanicalObject', name="surfaceDOFs")
LiverCollision.addObject('PointCollisionModel', name="CollisionModel")
LiverCollision.addObject('IdentityMapping', name="CollisionMapping", input="@../../dofs", output="@surfaceDOFs")
newSphere = root.addChild('FallingSphere-0')
newSphere.addObject('EulerImplicitSolver')
newSphere.addObject('CGLinearSolver', threshold='1e-09', tolerance='1e-09', iterations='200')
MO = newSphere.addObject('MechanicalObject', showObject=True, position=[-2, 10, 0, 0, 0, 0, 1], name=f'Particle-0', template='Rigid3d')
Mass = newSphere.addObject('UniformMass', totalMass=1)
Force = newSphere.addObject('ConstantForceField', name="CFF", totalForce=[0, -1, 0, 0, 0, 0] )
Sphere = newSphere.addObject('SphereCollisionModel', name="SCM", radius=1.0 )
newSphere.addObject('UncoupledConstraintCorrection' )
return root
# Function used only if this script is called from a python environment
if __name__ == '__main__':
main() Hope this helps PS: remember that we do provide training sessions to get started and progress on SOFA, more in this discussion here |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hello everyone,
I am new to SOFA, and my goal is to simulate the interaction between a rigid and soft body, and to extract the surface topology of the soft body during the interaction (think of an object lying on a mattress).
To start off I tried to modify the liver example of SOFA python.
I replaced the sphere with an obj model of a sphere, which is part of SOFA, and defined it as rigid. Additionally the sphere collision model of the liver was replaced by an Triangle/Point/LineCollisionModel, same for the sphere.
Since I need an intersection detection between two meshes I added the MinProximityIntersection object.
Running code can be seen here:
As soon as the sphere approaches the liver a long orange line appears extending upwards from the sphere. With continuation of the simulation the liver starts deforming and at some point the meshes disappear first partially (you can see the tetrahedral mesh inside the liver) and then completely and you have to zoom out to see them again, even though the objects don't appear to be that much larger.
I assume I have done something wrong with the collision model.
Could someone please give me pointers on how to solve this problem?
Thank you very much for your help!
Beta Was this translation helpful? Give feedback.
All reactions