def measureAnimationTime(node, timerName, timerInterval, timerOutputType, resultFileName, simulationDeltaTime, iterations): # timer Sofa.timerSetInterval( timerName, timerInterval) # Set the number of steps neded to compute the timer Sofa.timerSetEnabled(timerName, True) resultFileName = resultFileName + ".log" rootNode = node.getRoot() with open(resultFileName, "w+") as outputFile: outputFile.write("{") i = 0 Sofa.timerSetOutPutType(timerName, timerOutputType) while i < iterations: Sofa.timerBegin(timerName) rootNode.simulationStep(simulationDeltaTime) result = Sofa.timerEnd(timerName, rootNode) if result != None: outputFile.write(result + ",") oldResult = result i = i + 1 last_pose = outputFile.tell() outputFile.seek(last_pose - 1) outputFile.write("\n}") outputFile.seek(7) firstStep = outputFile.read(1) outputFile.close() Sofa.timerSetEnabled(timerName, 0) print "[Scene info]: end of simulation." return 0
def createTimeProfiler(self): print 'Time statistics file: ' + self.estFolder + '/' + self.opt['time']['time_statistics_file'] Sofa.timerSetInterval(self.opt['time']['timer_name'], self.opt['time']['iterations_interval']) ### Set the number of steps neded to compute the timer Sofa.timerSetOutputType(self.opt['time']['timer_name'], 'json') ### Set output file format with open(self.estFolder + '/' + self.opt['time']['time_statistics_file'], "a") as outputFile: outputFile.write('{') outputFile.close() return 0
def createGraph(self, node): self.rootNode = node.getRoot() # Creation of stuff needed for collision management node.createObject('DefaultAnimationLoop') node.createObject('CollisionPipeline', depth='6', verbose='0', draw='0') node.createObject('BruteForceDetection') node.createObject('CollisionResponse', response='default') node.createObject('DiscreteIntersection') node.createObject('VisualStyle', displayFlags="showBehaviorModels showForceFields showVisual" ) # Creation of the 'poutreRegGrid' node poutreRegGridNode = node.createChild('poutreRegGrid') # Add solver poutreRegGridNode.createObject('EulerImplicit', name='cg_solver', printLog='false') poutreRegGridNode.createObject('CGLinearSolver', iterations='25', name='linearSolver', tolerance='1.0e-9', threshold='1.0e-9') # Creation of the regular grid poutreRegGridNode.createObject('MechanicalObject', name='mecaObj') poutreRegGridNode.createObject('RegularGrid', name='regGrid', nx='3', ny='5', nz='10', min='2.495 -0.005 -0.005', max='2.535 0.065 0.205') # Set a topology for boxROI poutreRegGridNode.createObject('HexahedronSetTopologyContainer', src='@regGrid', name='Container') poutreRegGridNode.createObject('HexahedronSetTopologyModifier', name='Modifier') poutreRegGridNode.createObject('HexahedronSetTopologyAlgorithms', template='Vec3d', name='TopoAlgo') poutreRegGridNode.createObject('HexahedronSetGeometryAlgorithms', template='Vec3d', name='GeomAlgo') # Physic manager poutreRegGridNode.createObject('HexahedronFEMForceField', name='HFEM', youngModulus='1000', poissonRatio='0.2') # BoxConstraint for fixed constraint (on the left) poutreRegGridNode.createObject('BoxROI', name="FixedROI", box="2.495 -0.005 -0.005 2.535 0.065 0.0205", position='@mecaObj.rest_position') poutreRegGridNode.createObject('FixedConstraint', template='Vec3d', name='default6', indices='@FixedROI.indices') # BoxROI for constant constraint (on the right) poutreRegGridNode.createObject('BoxROI', template='Vec3d', box='2.495 -0.005 0.18 2.535 0.065 0.205', name='box_roi2', position='@mecaObj.rest_position') poutreRegGridNode.createObject('ConstantForceField', indices="@box_roi2.indices", force='0 -0.1 0', arrowSizeCoef='0.01') # Visual node VisualNode = poutreRegGridNode.createChild('Visu') VisualNode.createObject('OglModel', name='poutreRegGridVisual', fileMesh='../mesh/poutre_surface.obj', color='red', dx='2.5') VisualNode.createObject('BarycentricMapping', input='@..', output='@poutreRegGridVisual') VisualNode.createObject('STLExporter', position="@poutreRegGridVisual.position", filename="../ModelsTimer/SOFA/poutre_grid_sofa_model", exportEveryNumberOfSteps='1', exportAtEnd="1", triangle="@poutreRegGridVisual.triangles", listening="1") # timer Sofa.timerSetInterval("timer_poutre_grid_sofa", 2) # Set the number of steps neded to compute the timer Sofa.timerSetEnabled("timer_poutre_grid_sofa", True)
def createGraph(self, node): # Creation of the 'poutre' node self.rootNode = node.getRoot() poutreNode = node.createChild('poutre') # Add solver poutreNode.createObject('EulerImplicit', name='cg_solver', printLog='false') poutreNode.createObject('CGLinearSolver', iterations='25', name='linearSolver', tolerance='1.0e-9', threshold='1.0e-9') # Mesh loader with physical properties poutreNode.createObject('MeshVTKLoader', name='loader', filename='../mesh/poutre2.vtk') poutreNode.createObject('Mesh', src='@loader') poutreNode.createObject('MechanicalObject', name='mecaObj', src='@loader', dx='2.5') # Physic manager # Set a topology for boxROI # poutreNode.createObject('VolumeTopologyContainer', src='@loader', name='Container') # poutreNode.createObject('VolumeTopologyModifier', name='Modifier') # poutreNode.createObject('VolumeGeometryAlgorithms', name='GeomAlgo') poutreNode.createObject('TetrahedronSetTopologyContainer', src='@loader', name='Container') poutreNode.createObject('TetrahedronSetTopologyModifier', name='Modifier') poutreNode.createObject('TetrahedronSetTopologyAlgorithms', template='Vec3d', name='TopoAlgo') poutreNode.createObject('TetrahedronSetGeometryAlgorithms', template='Vec3d', name='GeomAlgo') poutreNode.createObject('CMTetrahedralCorotationalFEMForceField', name='CFEM', youngModulus='1000', poissonRatio='0.2', computeGlobalMatrix='false') # BoxROI for fixed constraint (on the left) poutreNode.createObject('BoxROI', template='Vec3d', box='2.495 -0.005 -0.005 2.535 0.065 0.0205', drawBoxes='1', position='@mecaObj.position', name='FixedROI', computeTriangles='0', computeTetrahedra='0', computeEdges='0', tetrahedra='@Container.tetrahedra') poutreNode.createObject('FixedConstraint', template='Vec3d', name='default6', indices='@FixedROI.indices') # BoxROI for constant constraint (on the right) poutreNode.createObject('BoxROI', template='Vec3d', box='2.495 -0.005 0.18 2.535 0.065 0.205', drawBoxes='1', position='@mecaObj.rest_position', name='constForceFieldROI', computeTriangles='0', computeTetrahedra='0', computeEdges='0', tetrahedra='@Container.tetrahedra') poutreNode.createObject('ConstantForceField', indices='@constForceFieldROI.indices', force='0 0 0.5', arrowSizeCoef='0.1') # Visual node VisualNode = poutreNode.createChild('Visu') VisualNode.createObject('OglModel', name='poutreVisual', fileMesh='../mesh/poutre_surface.obj', color='red', dx='2.5') VisualNode.createObject('BarycentricMapping', input='@..', output='@poutreVisual') # timer Sofa.timerSetInterval("timer_CMTetrahedralCorotationalFEMForceField", 2) # Set the number of steps neded to compute the timer Sofa.timerSetEnabled("timer_CMTetrahedralCorotationalFEMForceField", True) return 0
def createGraph(self, node): self.rootNode = node.getRoot() # Creation of stuff needed for collision management node.createObject('CollisionPipeline', depth='6', verbose='0', draw='0') node.createObject('BruteForceDetection') node.createObject('CollisionResponse', response='default') node.createObject('DiscreteIntersection') node.createObject( 'VisualStyle', displayFlags="showBehaviorModels showForceFields showVisual") # Creation of the 'poutreRegGrid' node poutreRegGridNode = node.createChild('poutreRegGrid') # Add solver poutreRegGridNode.createObject('EulerImplicit', name='cg_solver', printLog='false') poutreRegGridNode.createObject('CGLinearSolver', iterations='25', name='linearSolver', tolerance='1.0e-9', threshold='1.0e-9') # Creation of the regular grid poutreRegGridNode.createObject('MechanicalObject', name='mecaObj') poutreRegGridNode.createObject('RegularGrid', name='regGrid', nx='3', ny='5', nz='10', min='2.495 -0.005 -0.005', max='2.535 0.065 0.205') # Set a topology for boxROI poutreRegGridNode.createObject('VolumeTopologyContainer', src='@regGrid', name='Container') poutreRegGridNode.createObject('VolumeTopologyModifier', name='Modifier') poutreRegGridNode.createObject('VolumeGeometryAlgorithms', name='GeomAlgo') # Physic manager poutreRegGridNode.createObject('CMHexahedronFEMForceField', name='HFEM', youngModulus='1000', poissonRatio='0.2') # BoxConstraint for fixed constraint (on the left) poutreRegGridNode.createObject( 'BoxROI', name="FixedROI", box="2.495 -0.005 -0.005 2.535 0.065 0.0205", position='@mecaObj.rest_position') poutreRegGridNode.createObject('FixedConstraint', template='Vec3d', name='default6', indices='@FixedROI.indices') # BoxROI for constant constraint (on the right) poutreRegGridNode.createObject( 'BoxROI', template='Vec3d', box='2.495 -0.005 0.18 2.535 0.065 0.205', name='box_roi2', position='@mecaObj.rest_position') poutreRegGridNode.createObject('ConstantForceField', indices="@box_roi2.indices", force='0 0.1 0', arrowSizeCoef='0.01') # Visual node VisualNode = poutreRegGridNode.createChild('Visu') VisualNode.createObject('OglModel', name='poutreRegGridVisual', fileMesh='../mesh/poutre_surface.obj', color='red', dx='2.5') VisualNode.createObject('BarycentricMapping', input='@..', output='@poutreRegGridVisual') VisualNode.createObject( 'STLExporter', position="@poutreRegGridVisual.position", filename="../ModelsTimer/CGOGN/poutre_grid_CGOGN_model", exportEveryNumberOfSteps='1', exportAtEnd="1", triangle="@poutreRegGridVisual.triangles", listening="1") # timer Sofa.timerSetInterval( "timer_poutre_grid_CGOGN", 2) # Set the number of steps neded to compute the timer Sofa.timerSetEnabled("timer_poutre_grid_CGOGN", True)
def createGraph(self, node): # Creation of the 'poutre' node self.rootNode = node.getRoot() poutreNode = node.createChild('poutre') # Add solver poutreNode.createObject('EulerImplicit', name='cg_solver', printLog='false') poutreNode.createObject('CGLinearSolver', iterations='25', name='linearSolver', tolerance='1.0e-9', threshold='1.0e-9') # Mesh loader with physical properties poutreNode.createObject('MeshVTKLoader', name='loader', filename='../mesh/poutre2.vtk') poutreNode.createObject('Mesh', src='@loader') poutreNode.createObject('MechanicalObject', name='mecaObj', src='@loader', dx='2.5') # Physic manager # Set a topology for boxROI # poutreNode.createObject('VolumeTopologyContainer', src='@loader', name='Container') # poutreNode.createObject('VolumeTopologyModifier', name='Modifier') # poutreNode.createObject('VolumeGeometryAlgorithms', name='GeomAlgo') poutreNode.createObject('TetrahedronSetTopologyContainer', src='@loader', name='Container') poutreNode.createObject('TetrahedronSetTopologyModifier', name='Modifier') poutreNode.createObject('TetrahedronSetTopologyAlgorithms', template='Vec3d', name='TopoAlgo') poutreNode.createObject('TetrahedronSetGeometryAlgorithms', template='Vec3d', name='GeomAlgo') poutreNode.createObject('CMTetrahedralCorotationalFEMForceField', name='CFEM', youngModulus='1000', poissonRatio='0.2', computeGlobalMatrix='false') # BoxROI for fixed constraint (on the left) poutreNode.createObject('BoxROI', template='Vec3d', box='2.495 -0.005 -0.005 2.535 0.065 0.0205', drawBoxes='1', position='@mecaObj.position', name='FixedROI', computeTriangles='0', computeTetrahedra='0', computeEdges='0', tetrahedra='@Container.tetrahedra') poutreNode.createObject('FixedConstraint', template='Vec3d', name='default6', indices='@FixedROI.indices') # BoxROI for constant constraint (on the right) poutreNode.createObject('BoxROI', template='Vec3d', box='2.495 -0.005 0.18 2.535 0.065 0.205', drawBoxes='1', position='@mecaObj.rest_position', name='constForceFieldROI', computeTriangles='0', computeTetrahedra='0', computeEdges='0', tetrahedra='@Container.tetrahedra') poutreNode.createObject('ConstantForceField', indices='@constForceFieldROI.indices', force='0 0 0.5', arrowSizeCoef='0.1') # Visual node VisualNode = poutreNode.createChild('Visu') VisualNode.createObject('OglModel', name='poutreVisual', fileMesh='../mesh/poutre_surface.obj', color='red', dx='2.5') VisualNode.createObject('BarycentricMapping', input='@..', output='@poutreVisual') # timer Sofa.timerSetInterval( "timer_CMTetrahedralCorotationalFEMForceField", 2) # Set the number of steps neded to compute the timer Sofa.timerSetEnabled("timer_CMTetrahedralCorotationalFEMForceField", True) return 0