Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python pipeline #79

Merged
merged 5 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions python3/mor/reduction/reduceModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,13 @@ def phase3(self,phasesToExecute=None,nbrOfModes=None):

for fileName in self.reductionParam.savedElementsFilesNames :
u.copyFileIntoAnother(results[self.phaseToSaveIndex]["directory"]+slash+fileName,self.packageBuilder.debugDir+fileName)
self.reductionParam.massName = glob.glob(results[self.phaseToSaveIndex]["directory"]+slash+"*_reduced.txt")[0]
# print("massName -----------------------> ",self.reductionParam.massName)
u.copy(self.reductionParam.massName,self.reductionParam.dataDir)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need this commented code?

### commented out waiting for change in c++ code
# optimization done in MMM but now removed
# self.reductionParam.massName = glob.glob(results[self.phaseToSaveIndex]["directory"]+slash+"*_reduced.txt")[0]
# # print("massName -----------------------> ",self.reductionParam.massName)
# u.copy(self.reductionParam.massName,self.reductionParam.dataDir)
#####

files = glob.glob(results[self.phaseToSaveIndex]["directory"]+slash+"*_Gie.txt")
if files:
Expand Down Expand Up @@ -460,13 +464,12 @@ def phase4(self,nbrOfModes=None):
self.reductionParam.savedElementsFilesNames[j] = self.reductionParam.savedElementsFilesNames[i]
self.reductionParam.savedElementsFilesNames[i] = tmp

# print(self.reductionParam.savedElementsFilesNames)
# print(self.reductionParam.gieFilesNames)
tmp = glob.glob(self.packageBuilder.dataDir+"*_reduced.txt")[0]
tmp = os.path.normpath(tmp)
self.reductionParam.massName = tmp.split(slash)[-1]
# print("massName -----------------------> ",self.reductionParam.massName)

### commented out waiting for change in c++ code
# optimization done in MMM but now removed
# tmp = glob.glob(self.packageBuilder.dataDir+"*_reduced.txt")[0]
# tmp = os.path.normpath(tmp)
# self.reductionParam.massName = tmp.split(slash)[-1]
####

self.reductionParam.RIDFilesNames = []
self.reductionParam.weightsFilesNames = []
Expand Down
3 changes: 0 additions & 3 deletions python3/mor/utility/sceneCreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,8 @@ def modifyGraphScene(node,nbrOfModes,newParam):
modelMOR.addObject(obj)
modelMOR.addObject('MechanicalObject', **argMecha)
# print param['paramMappedMatrixMapping']
modelMOR.addObject('MechanicalMatrixMapperMOR', **param['paramMappedMatrixMapping'] )
# print 'Create MechanicalMatrixMapperMOR in modelMOR'
if save:
replaceAndSave.myMORModel.append(('MechanicalObject',argMecha))
replaceAndSave.myMORModel.append(('MechanicalMatrixMapperMOR',param['paramMappedMatrixMapping']))

if 'paramMORMapping' in param:
#Find MechanicalObject name to be able to save to link it to the ModelOrderReductionMapping
Expand Down
7 changes: 3 additions & 4 deletions python3/mor/utility/writeScene.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def MyReducedModel(
parentNode = nodeName+"_MOR"
elif childName.find('/'+nodeName+'/') == -1:
print(childName,1)
tmp = filter(None, childName.split('/'))
tmp = list(filter(None, childName.split('/')))
if len(tmp) > 2: # Add all the parents that haven't been created yet
for i, node in enumerate(tmp):
if i < len(tmp)-2:
Expand All @@ -194,7 +194,6 @@ def MyReducedModel(
# print(toFind)
logFile.write(toFind)
parentNode = childName.split('/')[-2]

else:
parentNode = 'modelRoot'

Expand All @@ -204,7 +203,7 @@ def MyReducedModel(
if childName.split('/')[-2] == nodeName:
parentNode = nodeName
else:
tmp = filter(None, childName.split('/'))
tmp = list(filter(None, childName.split('/')))
parentNode = tmp[-2]
if len(tmp) > 2:
for i, node in enumerate(tmp):
Expand Down Expand Up @@ -388,4 +387,4 @@ def buildArgStr(arg,translation=None):
myArgs += ", "+key+" = "+str(val)#+"'"

# print(myArgs)
return myArgs
return myArgs
2 changes: 1 addition & 1 deletion python3/mor/wrapper/replaceAndSave.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def MORreplace(node,type,newParam,initialParam):
currentPath = node.getPathName()
# print('NODE : '+node.name.value)
# print('TYPE : '+str(type))
#print('PARAM :'+str(newParam[0][0]) )
# print('PARAM :'+str(newParam[0][0]) )
save = False
if 'save' in newParam[1]:
save = True
Expand Down
103 changes: 70 additions & 33 deletions tools/sofa_test_scene/diamondRobot.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# -*- coding: utf-8 -*-

import os
import sys
import os

# STLIB IMPORT
from stlib3.scene import MainHeader
from stlib3.solver import DefaultSolver
from stlib3.physics.deformable import ElasticMaterialObject
from stlib3.physics.constraints import FixedBox
from stlib3.visuals import VisualModel
from stlib3.physics.deformable import ElasticMaterialObject

# SOFTROBOTS IMPORT
from softrobots.actuators import PullingCable
Expand All @@ -31,51 +29,90 @@
}
]

plugins=["SofaPython3","SoftRobots","ModelOrderReduction","STLIB",
# normally plugin Sofa.Component is enough but still warning
"Sofa.Component.Visual",
"Sofa.Component.AnimationLoop",
"Sofa.GL.Component.Rendering3D",
"Sofa.Component.Constraint.Lagrangian.Solver",
'Sofa.Component.IO.Mesh',
'Sofa.Component.Playback',
'Sofa.Component.Constraint.Lagrangian.Correction', # Needed to use components [GenericConstraintCorrection]
'Sofa.Component.Engine.Select', # Needed to use components [BoxROI]
'Sofa.Component.LinearSolver.Direct', # Needed to use components [SparseLDLSolver]
'Sofa.Component.Mapping.Linear', # Needed to use components [BarycentricMapping]
'Sofa.Component.Mass', # Needed to use components [UniformMass]
'Sofa.Component.ODESolver.Backward', # Needed to use components [EulerImplicitSolver]
'Sofa.Component.SolidMechanics.FEM.Elastic', # Needed to use components [TetrahedronFEMForceField]
'Sofa.Component.SolidMechanics.Spring', # Needed to use components [RestShapeSpringsForceField]
'Sofa.Component.StateContainer', # Needed to use components [MechanicalObject]
'Sofa.Component.Topology.Container.Dynamic'] # Needed to use components [TetrahedronSetTopologyContainer]

meshPath = os.path.dirname(os.path.abspath(__file__))+'/mesh/'

def createScene(rootNode):

rootNode.addObject('FreeMotionAnimationLoop')
rootNode.addObject('GenericConstraintSolver', tolerance="1e-6", maxIterations="1000")
rootNode.addObject('OglSceneFrame', style="Arrows", alignment="TopRight")
rootNode.addObject('VisualStyle', displayFlags='showVisualModels showForceFields')
rootNode.addObject('RequiredPlugin', pluginName=plugins, printLog=False)

rootNode.findData('gravity').value=[0.0,0.0,-9810];
rootNode.findData('dt').value=1

plugins=["SofaPython","SoftRobots","ModelOrderReduction"]
for name in plugins:
rootNode.addObject('RequiredPlugin', name=name, printLog=False)

rootNode.addObject('OglSceneFrame', style="Arrows", alignment="TopRight")

rootNode.addObject('FreeMotionAnimationLoop')
rootNode.addObject('GenericConstraintSolver', tolerance="1e-6", maxIterations="1000")
volumeMeshFileName=meshPath+'siliconeV0.vtu'
rotation=[90, 0.0, 0.0]
translation=[0.0, 0.0, 35]
totalMass=0.5
surfaceMeshFileName=meshPath+'surface.stl'
surfaceColor=[0.7, 0.7, 0.7, 0.7]
poissonRatio=0.45
youngModulus=450
scale=[1., 1., 1.]


modelNode = rootNode.addChild('modelNode')
modelNode.addObject('EulerImplicitSolver', name='integration')
modelNode.addObject('SparseLDLSolver', name="solver", template='CompressedRowSparseMatrixMat3x3d')
loader = modelNode.addObject('MeshVTKLoader', name='loader', filename=volumeMeshFileName,
rotation=list(rotation), translation=list(translation),
scale3d=list(scale))

# loader.tetras.getLinkPath() AND loader.position.getLinkPath() ---> DO NOT WORK
# When you change the scene for the HyperReduction, seems to update the link path to correct new path
# BUT does not load the loader data anymore
modelNode.addObject('TetrahedronSetTopologyContainer', position='@loader.position',
tetras='@loader.tetrahedra', name='container')
modelNode.addObject('MechanicalObject', template='Vec3', name='dofs')
modelNode.addObject('UniformMass', totalMass=totalMass, name='mass')
modelNode.addObject('TetrahedronFEMForceField', template='Vec3',
method='large', name='forcefield',
poissonRatio=poissonRatio, youngModulus=youngModulus)

visualmodel = modelNode.addChild('visualmodel')
visualmodel.addObject('MeshSTLLoader', name='loader', filename=surfaceMeshFileName)
visualmodel.addObject('OglModel', name="OglModel", src="@loader",
rotation=list(rotation),
translation=list(translation),
scale3d=list(scale),
color=list(surfaceColor), updateNormals=False)
visualmodel.addObject('BarycentricMapping', name='mapping')

modelNode = ElasticMaterialObject(
attachedTo=rootNode,
volumeMeshFileName=meshPath+'siliconeV0.vtu',
name='modelNode',
rotation=[90, 0.0, 0.0],
translation=[0.0, 0.0, 35],
totalMass=0.5,
withConstrain=False,
surfaceMeshFileName=meshPath+'surface.stl',
surfaceColor=[0.7, 0.7, 0.7, 0.7],
poissonRatio=0.45,
youngModulus=450)

modelNode.addObject('GenericConstraintCorrection', solverName='solver')
modelNode.addObject('GenericConstraintCorrection', linearSolver='@solver')

FixedBox(
atPositions=[-15, -15, -40, 15, 15, 10],
applyTo=modelNode,
doVisualization=True)
doVisualization=True)

for i in range(len(actuatorsParam)):
cable = PullingCable(
attachedTo=modelNode,
name=actuatorsParam[i]['withName'],
cableGeometry=actuatorsParam[i]['withCableGeometry'],
pullPointLocation=actuatorsParam[i]['withAPullPointLocation'],
valueType="displacement")
PullingCable(
attachedTo=modelNode,
name=actuatorsParam[i]['withName'],
cableGeometry=actuatorsParam[i]['withCableGeometry'],
pullPointLocation=actuatorsParam[i]['withAPullPointLocation'],
valueType="displacement")

return rootNode
91 changes: 91 additions & 0 deletions tools/sofa_test_scene/diamondRobotWithPrefab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# -*- coding: utf-8 -*-
import sys
import os

# STLIB IMPORT
from stlib3.scene import MainHeader
from stlib3.physics.constraints import FixedBox
from stlib3.physics.deformable import ElasticMaterialObject

# SOFTROBOTS IMPORT
from softrobots.actuators import PullingCable

actuatorsParam = [
{'withName' : 'nord',
'withCableGeometry' : [[0, 97, 45]],
'withAPullPointLocation' : [0, 10, 30]
},
{'withName' : 'ouest',
'withCableGeometry' : [[-97, 0, 45]],
'withAPullPointLocation' : [-10, 0, 30]
},
{'withName' : 'sud',
'withCableGeometry' : [[0, -97, 45]],
'withAPullPointLocation' : [0, -10, 30]
},
{'withName' : 'est',
'withCableGeometry' : [[97, 0, 45]],
'withAPullPointLocation' : [10, 0, 30]
}
]

plugins=["SofaPython3","SoftRobots","ModelOrderReduction","STLIB",
# normally plugin Sofa.Component is enough but still warning
"Sofa.Component.Visual",
"Sofa.Component.AnimationLoop",
"Sofa.GL.Component.Rendering3D",
"Sofa.Component.Constraint.Lagrangian.Solver",
'Sofa.Component.IO.Mesh',
'Sofa.Component.Playback',
'Sofa.Component.Constraint.Lagrangian.Correction', # Needed to use components [GenericConstraintCorrection]
'Sofa.Component.Engine.Select', # Needed to use components [BoxROI]
'Sofa.Component.LinearSolver.Direct', # Needed to use components [SparseLDLSolver]
'Sofa.Component.Mapping.Linear', # Needed to use components [BarycentricMapping]
'Sofa.Component.Mass', # Needed to use components [UniformMass]
'Sofa.Component.ODESolver.Backward', # Needed to use components [EulerImplicitSolver]
'Sofa.Component.SolidMechanics.FEM.Elastic', # Needed to use components [TetrahedronFEMForceField]
'Sofa.Component.SolidMechanics.Spring', # Needed to use components [RestShapeSpringsForceField]
'Sofa.Component.StateContainer', # Needed to use components [MechanicalObject]
'Sofa.Component.Topology.Container.Dynamic'] # Needed to use components [TetrahedronSetTopologyContainer]

meshPath = os.path.dirname(os.path.abspath(__file__))+'/mesh/'

def createScene(rootNode):

MainHeader(rootNode,plugins=plugins,
dt=1.0,
gravity=[0.0, 0.0, -9810.0])

# not in Mainheader anymore, need some update
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# not in Mainheader anymore, need some update

rootNode.addObject('FreeMotionAnimationLoop')
rootNode.addObject('GenericConstraintSolver', tolerance="1e-6", maxIterations="1000")
rootNode.VisualStyle.displayFlags = 'showVisualModels showForceFields'
# -------------------------------------------

modelNode = ElasticMaterialObject(
parent=rootNode,
volumeMeshFileName=meshPath+'siliconeV0.vtu',
name='modelNode',
rotation=[90, 0.0, 0.0],
translation=[0.0, 0.0, 35],
totalMass=0.5,
withConstrain=False,
surfaceMeshFileName=meshPath+'surface.stl',
surfaceColor=[0.7, 0.7, 0.7, 0.7],
poissonRatio=0.45,
youngModulus=450)

FixedBox(
atPositions=[-15, -15, -40, 15, 15, 10],
applyTo=modelNode,
doVisualization=True)

for i in range(len(actuatorsParam)):
PullingCable(
attachedTo=modelNode,
name=actuatorsParam[i]['withName'],
cableGeometry=actuatorsParam[i]['withCableGeometry'],
pullPointLocation=actuatorsParam[i]['withAPullPointLocation'],
valueType="displacement")

return rootNode
2 changes: 1 addition & 1 deletion tools/sofa_test_scene/quadruped.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def createScene(rootNode):
model.addObject('BoxROI', name='boxROISubTopo', box='0 0 0 150 -100 1', drawBoxes='true')
model.addObject('BoxROI', name='membraneROISubTopo', box='0 0 -0.1 150 -100 0.1', computeTetrahedra="false",
drawBoxes='true')
model.addObject('GenericConstraintCorrection', solverName='preconditioner')
model.addObject('GenericConstraintCorrection', linearSolver='@preconditioner')
##########################################
# Sub topology
modelSubTopo = model.addChild('modelSubTopo')
Expand Down
Loading