Home › Forum › SOFA › Using SOFA › [SOLVED] Animation issue Error in phase 3 of MOR plugin. Please Help!
Tagged: Linux_ubuntu, ModelOrderReduction, SOFA_2012
- This topic has 13 replies, 2 voices, and was last updated 3 years, 6 months ago by Pasquale94.
-
AuthorPosts
-
22 April 2021 at 19:11 #19275Pasquale94Blocked
Hello Sofa Forum,
I am a pneumatic actuator (just one air chamber so very simple) that i want to reduce of order.
So i am using on Ubuntu 20.04 Sofa 20.04 with python 2.7 and I arrived to write the code ModelOrderReduction.py like this, folowing the tutorial in online documentation:Import import os import sys sys.path.append(os.getcwd()+'/../python') # MOR IMPORT from mor.gui import utility from mor.reduction import ReduceModel from mor.reduction.container import ObjToAnimate # Important path from PyQt4 import QtCore, QtGui app = QtGui.QApplication(sys.argv) originalScene = utility.openFileName('Select the SOFA scene you want to reduce') #meshes = utility.openFilesNames('Select the meshes & visual of your scene') outputDir = utility.openDirName('Select the directory tha will contain all the results') # if you haven't install PyQt the previous function won't work # As an alternative you can enter the absolute path to the conresponding files directly: # originalScene = /PathToMy/Original/Scene nodesToReduce_finger = '/finger' cavity = ObjToAnimate("finger/cavity", incr=5e-6,incrPeriod=0.001,rangeOfAction=0.0483) listObjToAnimate_finger = [cavity] addRigidBodyModes_finger = [0,0,0] tolModes = 0.001 # Tolerance tolGIE = 0.05 # Optionnal verbose = False nbrCPU = 4 packageName = 'test' addToLib = False # Initialization of our script nodesToReduce = nodesToReduce_finger # nodesToReduce_STARFISH listObjToAnimate = listObjToAnimate_finger # listObjToAnimate_STARFISH addRigidBodyModes = addRigidBodyModes_finger # addRigidBodyModes_STARFISH reduceMyModel = ReduceModel( originalScene, nodesToReduce, listObjToAnimate, tolModes,tolGIE, outputDir, packageName = packageName, addToLib = addToLib, verbose = verbose, addRigidBodyModes = addRigidBodyModes) reduceMyModel.phase1() reduceMyModel.phase2() reduceMyModel.phase3()
I have a problem in the phase 3, in the terminal is present all this output:
periodSaveGIE : 6 | nbTrainingSet : 9660 | nbIterations : 9 ################################################## [140573650081536] processing threaded sofa task in: /tmp/sofa-launcher-WoW6ZK/phase1_snapshots.py [140573658830592] processing threaded sofa task in: /tmp/sofa-launcher-ulwwu7/phase1_snapshots.py PHASE 1 --- 14.8335149288 seconds --- ################################################### Executing readStateFilesAndComputeModes.py Arguments : INPUT : in stateFilePath : /home/pasquale/sofa-new-python2/src/applications/plugins/ModelOrderReduction/python/Thick_finger/debug/stateFile.state with arguments : -tolerance : 0.001 OUTPUT : -modesFileName : /home/pasquale/sofa-new-python2/src/applications/plugins/ModelOrderReduction/python/Thick_finger/data/modes.txt ################################################### 16 possible modes with a tolerance of 0.001 PHASE 2 --- 0.348403930664 seconds --- [140574291900160] processing threaded sofa task in: /tmp/sofa-launcher-0_5r9P/phase2_prepareECSW.py [140573163906816] processing threaded sofa task in: /tmp/sofa-launcher-za7OcM/phase2_prepareECSW.py IOError : there is no /tmp/sofa-launcher-0_5r9P/elmts_finger.txt , check the template log to find why. Here some clue for its probable origin : - Your animation arguments are incorrect and it hasn't find anything to animate Traceback (most recent call last): File "ModelOrderReduction.py", line 68, in <module> reduceMyModel.phase3() File "/home/pasquale/sofa-new-python2/src/applications/plugins/ModelOrderReduction/python/mor/reduction/reduceModel.py", line 379, in phase3 self.reductionParam.massName = glob.glob(results[self.phaseToSaveIndex]["directory"]+slash+"*_reduced.txt")[0] IndexError: list index out of range
I checked also in the relative output.log generated by the sofa launcher and the only error that i have is this:
[ERROR] [PythonScript] RuntimeError: Unable to create 'reducedFF_finger_0' of type 'HyperReducedTetrahedronHyperelasticityFEMForceField' in node 'finger'. Object type HyperReducedTetrahedronHyperelasticityFEMForceField<Vec3d> was not created The object is not in the factory. File "phase2_prepareECSW.py", line 43, in createScene phase1_snapshots.createScene(Wrapper(rootNode, replaceAndSave.MORreplace, paramWrapper)) File "phase1_snapshots.py", line 44, in createScene originalScene.createScene(rootNode) File "/home/pasquale/sofa-new-python2/src/applications/plugins/ModelOrderReduction/python/Thick_finger/thicker_finger.py", line 43, in createScene finger.createObject('TetrahedronHyperelasticityFEMForceField', template='Vec3f', name='FEM', src ='@topo', ParameterSet=str(mu)+' '+str(k0),materialName="NeoHookean") File "/home/pasquale/sofa-new-python2/src/applications/plugins/STLIB/python/stlib/scene/wrapper.py", line 35, in createObject return self.node.createObject(objectArg[0], **objectArg[1])
But is strange for me because i compiled the plugin so I don’t understand why the object is not in the factory.
I already know that @olivier-goury and @felixvanneste work on this plugin, also form other answers in the topic , so i tag directly them hope they can help me.
Thanks a lot in advance.23 April 2021 at 10:51 #19279FélixBlockedHello @pasquale94,
The easiest way to help you, I think, is that you give us your scene and I will do a quick test with it.
But at first glance it seems that it cannot instantiate a component from the plugin MOR. So maybe it cannot load the plugin for some reason…
Hope it help !
Have a good day,
Félix23 April 2021 at 10:57 #19280Pasquale94BlockedHello @felixvanneste ,
Is good for you if I contact you by email sending the scene?
Many Thanks for the help!
Pasquale
23 April 2021 at 11:34 #19282Pasquale94BlockedHello @felixvanneste ,
i created a github repo, so you can dowload the files, the scene is thicker_finger.py
Thanks again!
During the installation of MOR plugin I had problem with Sofa.Gl library apparently in my sofa 20.12 (ubuntu version) is not present.
Maybe this can be the origin of the issue.26 April 2021 at 10:33 #19312Pasquale94Blocked26 April 2021 at 14:17 #19313FélixBlockedHello @pasquale94,
they were multiple errors some from the plugin itself and some from your scene.
Concerning your scene:
– you need to add the plugin ModelOrderReduction in your initial scene, I need to add that fact into the documentation…
– use GenericConstraintSolver instead of LinearSolverConstraintCorrection, it seems there is problem with linearSolvers and mor component I also need to add that to the doc…For the reduction:
– you were putting incrPeriod=0.001 but I made a mistake in the documentation, its not the period but the number of dt between each animation. So here I guess you want one to animate each dt then incrPeriod=1.
– I have made some small modification in the python code to correct some issue, pleasecopy/pasteor pull to have the update.In the end I have something like that:
cavity = ObjToAnimate("finger/cavity", incr=5e-4,incrPeriod=1,rangeOfAction=0.1) listObjToAnimate = [cavity] addRigidBodyModes = [0,0,0] # Tolerance tolModes = 0.001 tolGIE = 0.05 # Optional verbose = True nbrCPU = 4 packageName = 'test' addToLib = False reduceMyModel = ReduceModel( originalScene, nodeToReduce, listObjToAnimate, tolModes,tolGIE, outputDir, phaseToSave=[1], packageName = packageName, addToLib = addToLib, verbose = verbose, addRigidBodyModes = addRigidBodyModes) reduceMyModel.phase1(phasesToExecute = [1]) reduceMyModel.phase2() reduceMyModel.phase3(phasesToExecute = [1]) reduceMyModel.phase4()
I hope this help and thanks for the feed back!
26 April 2021 at 14:32 #19314FélixBlockedLat thing, if you don’t know.
When you do phase 1 & 3 it generate some stateFile.state that you can check by launching the debug/debug_scene.py.
It will show you what happened during the scene execution allowing you to see if the animation function you use do the job.28 April 2021 at 14:09 #19336Pasquale94BlockedHello @felixvanneste,
I applied your modifications, but using the Generic Constraint solver the finger is not animated (seen in the debug scene).
Anyway using both Linear or Generic Solvers I have always this error when the phase2 starts:
Executing readStateFilesAndComputeModes.py Arguments : INPUT : in stateFilePath : /home/pasquale/sofa-new-python2/src/applications/plugins/ModelOrderReduction/python/Thick_finger/debug/stateFile.state with arguments : -tolerance : 0.001 OUTPUT : -modesFileName : /home/pasquale/sofa-new-python2/src/applications/plugins/ModelOrderReduction/python/Thick_finger/data/modes.txt ################################################### Reading file '/home/pasquale/sofa-new-python2/src/applications/plugins/ModelOrderReduction/python/Thick_finger/debug/stateFile.state': XO NOT FOUND Traceback (most recent call last): File "ModelOrderReduction.py", line 68, in <module> reduceMyModel.phase2() File "/home/pasquale/sofa-new-python2/src/applications/plugins/ModelOrderReduction/python/mor/reduction/reduceModel.py", line 294, in phase2 raise ValueError("problem of execution of readStateFilesAndComputeModes") ValueError: problem of execution of readStateFilesAndComputeModes
What does it mean? Then I seen that the file stateFile.state in debug folder starts from a T = 6 while i would expect that was T = 0 as first increment.
Thank you for the help. Do you had the same error with my scene?
28 April 2021 at 14:31 #19337FélixBlockedHello @pasquale94,
I am really sorry I forget to tell you that you need to put absolute path into your scene…
import Sofa import os path = os.path.dirname(os.path.abspath(__file__))+'/design/' def createScene(rootNode): rootNode.createObject('RequiredPlugin', pluginName='SoftRobots SofaPython SofaOpenglVisual SofaSparseSolver SofaPreconditioner SofaMiscCollision SofaExporter ModelOrderReduction SofaMiscFem SofaMiscForceField') rootNode.createObject('VisualStyle') #, displayFlags='showVisualModels showBehaviorModels hideCollisionModels hideBoundingCollisionModels showForceFields hideInteractionForceFields hideWireframe') rootNode.findData('gravity').value=[ 0, 0, -9810] rootNode.findData('dt').value = 0.001 rootNode.createObject('FreeMotionAnimationLoop') rootNode.createObject('GenericConstraintSolver', tolerance=1e-12, maxIterations=10000) rootNode.createObject('DefaultPipeline') rootNode.createObject('BruteForceDetection') rootNode.createObject('DefaultContactManager', response='FrictionContact', responseParams='mu=0.6') rootNode.createObject('LocalMinDistance', name='Proximity', alarmDistance=5, contactDistance=1, angleCone=0.0) rootNode.createObject('BackgroundSetting', color=[0, 0.168627, 0.211765]) rootNode.createObject('OglSceneFrame', style='Arrows', alignment='TopRight') #rootNode.createObject('PythonScriptController', filename='pythonControllers/fingerController.py', classname = 'FingerController') finger = rootNode.createChild('finger') finger.createObject('EulerImplicitSolver', name='odesolver', rayleighStiffness=0.1, rayleighMass=0.1) finger.createObject('SparseLDLSolver', name='directSolver') finger.createObject('MeshVTKLoader', name='loader', filename=path+'finger0.vtu') finger.createObject('MechanicalObject', name='tetras', template='Vec3d', src = '@loader') finger.createObject('TetrahedronSetTopologyContainer', name="topo", src ='@loader') finger.createObject('TetrahedronSetTopologyModifier' , name="Modifier") #finger.createObject('TetrahedronSetTopologyAlgorithms', name="TopoAlgo", template="Vec3d") finger.createObject('TetrahedronSetGeometryAlgorithms', template="Vec3d" ,name="GeomAlgo")#, drawTriangles="1") finger.createObject('MeshMatrixMass', massDensity='1.020e-9', src = '@topo') #youngModulus = 120 #poisson = 0.44 mu = 2*109 k0 = 1/1.150e-2 finger.createObject('TetrahedronHyperelasticityFEMForceField', template='Vec3d', name='FEM', src ='@topo', ParameterSet=str(mu)+' '+str(k0),materialName="NeoHookean") #finger.createObject('TetrahedronFEMForceField', template='Vec3d', name='FEM', src ='@topo', youngModulus = 120, poisson = 0.44) finger.createObject('BoxROI', name='boxROI', box=[-10, 0, 0, 10,15, 5], drawBoxes=True) finger.createObject('RestShapeSpringsForceField', points='@boxROI.indices', stiffness=1e12, angularStiffness=1e12) # finger.createObject('LinearSolverConstraintCorrection', solverName='directSolver') finger.createObject('GenericConstraintCorrection', solverName='directSolver') cavity = finger.createChild('cavity') cavity.createObject('MeshObjLoader', name='cavityLoader', filename=path+'BSPA_New_Design_Inner.obj') cavity.createObject('MeshTopology', src='@cavityLoader', name='cavityMesh') cavity.createObject('MechanicalObject', name='cavity') cavity.createObject('SurfacePressureConstraint', name='SurfacePressureConstraint', template='Vec3d', value= 0, triangles='@cavityMesh.triangles', valueType='pressure') cavity.createObject('BarycentricMapping', name='mapping', mapForces=False, mapMasses=False) collisionFinger = finger.createChild('collisionFinger') collisionFinger.createObject('MeshObjLoader', name='loader', filename=path+'BSPA_New_Design_Outer.obj') collisionFinger.createObject('MeshTopology', src='@loader', name='topo') collisionFinger.createObject('MechanicalObject', name='collisMech') collisionFinger.createObject('TriangleCollisionModel', selfCollision=False) collisionFinger.createObject('LineCollisionModel', selfCollision=False) collisionFinger.createObject('PointCollisionModel', selfCollision=False) collisionFinger.createObject('BarycentricMapping') modelVisu = finger.createChild('visu') modelVisu.createObject('MeshObjLoader', name='loader', filename=path+'BSPA_New_Design_Outer.obj') modelVisu.createObject('OglModel', src='@loader', color='yellow') modelVisu.createObject('BarycentricMapping') return rootNode
Also for the XO NOT FOUND issue if you haven’t pull my recent changes and used what I have put above its normal.
But if you don’t want to complicate yourself you can do it like that:cavity = ObjToAnimate("finger/cavity", incr=5e-4,incrPeriod=1,rangeOfAction=0.1) listObjToAnimate = [cavity] addRigidBodyModes = [0,0,0] # Tolerance tolModes = 0.001 tolGIE = 0.05 # Optional verbose = True nbrCPU = 4 packageName = 'test' addToLib = False reduceMyModel = ReduceModel( originalScene, nodeToReduce, listObjToAnimate, tolModes,tolGIE, outputDir, packageName = packageName, addToLib = addToLib, verbose = verbose, addRigidBodyModes = addRigidBodyModes) reduceMyModel.phase1() reduceMyModel.phase2() reduceMyModel.phase3() reduceMyModel.phase4()
I hope it solve your problems…
Sorry for the inconvenience, some work still need to be done with the documentation to help debug/avoid some little mistake.28 April 2021 at 15:31 #19338Pasquale94BlockedHello @felixvanneste,
Now the code produce the reduced_test.py scene, but when i launch the scene in sofa it don’t actuate the pneunet.
So I have to add a python controller to the scene?
Thanks a lot for the help!
28 April 2021 at 16:20 #19340FélixBlockedHey again @pasquale94,
Yes if everything works fine, the plugin only generate a python file that you can re-use as a module.
It contains a function with some basic parameters that instantiate the reduced model of the node you give as an argument to nodeToReduce.Doesn’t seems really clear so here an example :
import Sofa import os path = os.path.dirname(os.path.abspath(__file__))+'/design/' from reduced_test import Reduced_test def createScene(rootNode): rootNode.createObject('RequiredPlugin', pluginName='SoftRobots SofaPython SofaOpenglVisual SofaSparseSolver SofaPreconditioner SofaMiscCollision SofaExporter ModelOrderReduction SofaMiscFem SofaMiscForceField') rootNode.createObject('VisualStyle') rootNode.findData('gravity').value=[ 0, 0, -9810] rootNode.findData('dt').value = 0.001 rootNode.createObject('FreeMotionAnimationLoop') rootNode.createObject('GenericConstraintSolver', tolerance=1e-12, maxIterations=10000) rootNode.createObject('DefaultPipeline') rootNode.createObject('BruteForceDetection') rootNode.createObject('DefaultContactManager', response='FrictionContact', responseParams='mu=0.6') rootNode.createObject('LocalMinDistance', name='Proximity', alarmDistance=5, contactDistance=1, angleCone=0.0) rootNode.createObject('BackgroundSetting', color=[0, 0.168627, 0.211765]) rootNode.createObject('OglSceneFrame', style='Arrows', alignment='TopRight') # ADD your controller rootNode.createObject('PythonScriptController', filename='pythonControllers/fingerController.py', classname = 'FingerController') # ADD your reduced model Reduced_test(attachedTo=rootNode,name="Reduced_test",rotation=[0.0, 0.0, 0.0],translation=[0.0, 0.0, 0.0],scale=[1.0, 1.0, 1.0], surfaceMeshFileName=False,surfaceColor=[1.0, 1.0, 1.0],nbrOfModes=3,hyperReduction=True)
28 April 2021 at 18:31 #19343Pasquale94BlockedHello @felixvanneste .
This is the last question then i will close the topic ahah. Thanjks for your help.
Once I produced the reduced_scene, can i integer the scene in a Python 3 scripting?
Or I have to use always a scene coded in python 2?Thank you for the help.
29 April 2021 at 11:41 #19346FélixBlockedHello @pasquale94,
no problem I am happy to help you use it !
Yes you can adjust the scene to make it work for python3.
There are no problems for the c++ mor components to work with python3, its just that the interface I have developed to ease the reduction process is (for the moment) only working with python2…A last remark, when I had reduced your scene last Monday I have noted that even reduced your scene was kind of slow and its probably due to your visual mesh which seems to be maybe too precise for the purpose of a visual model.
29 April 2021 at 12:35 #19347Pasquale94BlockedHello @felixvanneste,
Thanks for all the help and advice.I will close the topic, the issue is solved.
-
AuthorPosts
- You must be logged in to reply to this topic.