Advertisement
Guest User

Untitled

a guest
Feb 14th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.45 KB | None | 0 0
  1. import Sofa
  2. import os
  3.  
  4. meshPath = os.path.dirname(os.path.abspath(__file__))+'/mesh/'
  5.  
  6. def createScene(rootNode):
  7.    
  8.     rootNode.createObject('RequiredPlugin', name='ModelOrderReduction', pluginName='ModelOrderReduction')
  9.     rootNode.createObject('RequiredPlugin', name='SofaPython', pluginName='SofaPython')
  10.  
  11.     rootNode.createObject('VisualStyle', displayFlags='showCollision showVisualModels showForceFields showInteractionForceFields hideCollisionModels hideBoundingCollisionModels hideWireframe')
  12.     rootNode.findData('dt').value=0.01
  13.     rootNode.findData('gravity').value=[0, -981, 0]
  14.     rootNode.createObject('FreeMotionAnimationLoop')
  15.     rootNode.createObject('GenericConstraintSolver', tolerance="1e-12", maxIterations="10000")
  16.     liver = rootNode.createChild('liver')
  17.     liver.createObject('EulerImplicitSolver', rayleighStiffness = 0.0, rayleighMass = 0.0)
  18.     liver.createObject('SparseLDLSolver', saveMatrixToFile='False', name='preconditioner')
  19.     liver.createObject('MeshVTKLoader', name="loader", filename=meshPath+'liverFine.vtu')
  20.     liver.createObject('TetrahedronSetTopologyContainer', src="@loader")
  21.     liver.createObject('TetrahedronSetGeometryAlgorithms')
  22.     liver.createObject('MechanicalObject')
  23.     liver.createObject('BoxROI', name='ROI1', box='0 3 -1 2 5 2', drawBoxes='true')
  24.     liver.createObject('BoxROI', name='boxROIactuation', box='-5 0 -0.5 -4 0.5 0.5', drawBoxes='true')
  25.     liver.createObject('UniformMass', totalMass=0.3)
  26.     liver.createObject('TetrahedronFEMForceField', poissonRatio="0.3", youngModulus="5000")
  27.     liver.createObject('GenericConstraintCorrection', solverName='preconditioner')
  28.     liver.createObject('RestShapeSpringsForceField', points='@ROI1.indices', stiffness = '1e8')
  29.     liver.createObject('RestShapeSpringsForceField' , external_points = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], points = '@boxROIactuation.indices', name = 'actuatorSpring', stiffness = '1e8', external_rest_shape = '@actuator/actuatorState')
  30.    
  31.     visu = liver.createChild('visu')
  32.     visu.createObject(  'MeshObjLoader', name= 'loader', filename=meshPath+'liver-smoothUV.obj')
  33.     visu.createObject('OglModel', src="@loader")
  34.     visu.createObject('BarycentricMapping')
  35.  
  36.    
  37.  
  38.     actuator = rootNode.createChild('actuator')
  39.     actuator.createObject('MechanicalObject', name = 'actuatorState', position = '@../liver/boxROIactuation.pointsInROI', free_velocity = '@../liver/boxROIactuation.pointsInROI', template = 'Vec3d')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement