From 35ebe4eddee2dbfcd7798ea694552ea5fd992b08 Mon Sep 17 00:00:00 2001 From: Paul Baksic Date: Tue, 10 Dec 2024 16:21:27 +0100 Subject: [PATCH 1/4] apply data name change --- examples/organs/liver/liverFineHyperElastic.pyscn | 4 ++-- examples/organs/liver/liverFine_gravity.py | 2 +- examples/organs/liver/liverFine_rotationalActuation.py | 4 ++-- examples/organs/liver/reduced/liver/reduced_liverFine.py | 4 ++-- .../liver_hyperElastic/reduced_liverFineHyperElastic.py | 4 ++-- examples/others/hexaBeam/hexaBeam.pyscn | 2 +- examples/others/hexaBeam/reduced/reduced_hexaBeam.py | 2 +- .../diamond/reduced/diamond/reduced_diamondRobot.py | 2 +- .../diamond_hyperElastic/reduced_diamondRobotHyperElastic.py | 2 +- examples/softRobots/finger/finger.pyscn | 2 +- examples/softRobots/finger/reduced/reduced_finger.py | 2 +- examples/softRobots/sofiaLeg/reduced/reduced_sofiaLeg.py | 4 ++-- examples/softRobots/sofiaLeg/sofiaLeg.py | 4 ++-- 13 files changed, 19 insertions(+), 19 deletions(-) diff --git a/examples/organs/liver/liverFineHyperElastic.pyscn b/examples/organs/liver/liverFineHyperElastic.pyscn index f09f8c1..08beb18 100644 --- a/examples/organs/liver/liverFineHyperElastic.pyscn +++ b/examples/organs/liver/liverFineHyperElastic.pyscn @@ -45,8 +45,8 @@ def createScene(rootNode): liver.addObject('TetrahedronHyperelasticityFEMForceField',materialName="NeoHookean", ParameterSet=str(mu_) + " " + str(k0_), AnisotropyDirections="") - liver.addObject('RestShapeSpringsForceField', points='@ROI1.indices', stiffness = '1e8') - liver.addObject('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') + liver.addObject('RestShapeSpringsForceField', indices='@ROI1.indices', stiffness = '1e8') + liver.addObject('RestShapeSpringsForceField' , externalIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], points = '@boxROIactuation.indices', name = 'actuatorSpring', stiffness = '1e8', external_rest_shape = '@actuator/actuatorState') visu = liver.addChild('visu') visu.addObject( 'MeshOBJLoader', name= 'loader', filename=meshPath+'liver-smoothUV.obj') diff --git a/examples/organs/liver/liverFine_gravity.py b/examples/organs/liver/liverFine_gravity.py index b3286bf..2b72099 100644 --- a/examples/organs/liver/liverFine_gravity.py +++ b/examples/organs/liver/liverFine_gravity.py @@ -45,7 +45,7 @@ def createScene(rootNode): liver.addObject('UniformMass', totalMass=0.3) liver.addObject('TetrahedronFEMForceField', poissonRatio="0.3", youngModulus="5000") - liver.addObject('RestShapeSpringsForceField', points='@ROI1.indices', stiffness = '1e8') + liver.addObject('RestShapeSpringsForceField', indices='@ROI1.indices', stiffness = '1e8') # Add a visual model visu = liver.addChild('visu') diff --git a/examples/organs/liver/liverFine_rotationalActuation.py b/examples/organs/liver/liverFine_rotationalActuation.py index 5d8fc56..7d5cd7a 100644 --- a/examples/organs/liver/liverFine_rotationalActuation.py +++ b/examples/organs/liver/liverFine_rotationalActuation.py @@ -47,8 +47,8 @@ def createScene(rootNode): liver.addObject('UniformMass', totalMass=0.3) liver.addObject('TetrahedronFEMForceField', poissonRatio="0.3", youngModulus="5000") - liver.addObject('RestShapeSpringsForceField', points='@ROI1.indices', stiffness = '1e8') - liver.addObject('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') + liver.addObject('RestShapeSpringsForceField', indices='@ROI1.indices', stiffness = '1e8') + liver.addObject('RestShapeSpringsForceField' , externalIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], indices = '@boxROIactuation.indices', name = 'actuatorSpring', stiffness = '1e8', external_rest_shape = '@actuator/actuatorState') visu = liver.addChild('visu') visu.addObject( 'MeshOBJLoader', name= 'loader', filename=meshPath+'liver-smoothUV.obj') diff --git a/examples/organs/liver/reduced/liver/reduced_liverFine.py b/examples/organs/liver/reduced/liver/reduced_liverFine.py index ab39d65..e9fe999 100644 --- a/examples/organs/liver/reduced/liver/reduced_liverFine.py +++ b/examples/organs/liver/reduced/liver/reduced_liverFine.py @@ -77,8 +77,8 @@ def Reduced_test( liver.addObject('BoxROI' , name= 'boxROIactuation' , orientedBox= newBox([[-5.0, 0.5, -0.5], [-5.0, 0.0, -0.5], [-4.0, 0.0, -0.5]] , [0.0, 0.0, 0.0],translation,rotation,[0, 0, 0.5],scale) + multiply(scale[2],[1.0]).tolist(),drawBoxes=True) liver.addObject('UniformMass' , totalMass = 0.3) liver.addObject('HyperReducedTetrahedronFEMForceField' , poissonRatio = '0.3', youngModulus = '5000', name = 'reducedFF_liver_0', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_liver_0_RID.txt', weightsPath = path + r'/data/reducedFF_liver_0_weight.txt') - liver.addObject('HyperReducedRestShapeSpringsForceField' , points = '@ROI1.indices', stiffness = '1e8', name = 'reducedFF_liver_1', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_liver_1_RID.txt', weightsPath = path + r'/data/reducedFF_liver_1_weight.txt') - liver.addObject('HyperReducedRestShapeSpringsForceField' , external_points = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], points = '@boxROIactuation.indices', name = 'reducedFF_liver_2', stiffness = '1e8', external_rest_shape = '@actuator/actuatorState', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_liver_2_RID.txt', weightsPath = path + r'/data/reducedFF_liver_2_weight.txt') + liver.addObject('HyperReducedRestShapeSpringsForceField' , indices = '@ROI1.indices', stiffness = '1e8', name = 'reducedFF_liver_1', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_liver_1_RID.txt', weightsPath = path + r'/data/reducedFF_liver_1_weight.txt') + liver.addObject('HyperReducedRestShapeSpringsForceField' , externalIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], indices = '@boxROIactuation.indices', name = 'reducedFF_liver_2', stiffness = '1e8', external_rest_shape = '@actuator/actuatorState', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_liver_2_RID.txt', weightsPath = path + r'/data/reducedFF_liver_2_weight.txt') liver.addObject('ModelOrderReductionMapping' , input = '@../MechanicalObject', modesPath = path + r'/data/modes.txt', output = '@./MechanicalObject') diff --git a/examples/organs/liver/reduced/liver_hyperElastic/reduced_liverFineHyperElastic.py b/examples/organs/liver/reduced/liver_hyperElastic/reduced_liverFineHyperElastic.py index 148134a..c5c393f 100644 --- a/examples/organs/liver/reduced/liver_hyperElastic/reduced_liverFineHyperElastic.py +++ b/examples/organs/liver/reduced/liver_hyperElastic/reduced_liverFineHyperElastic.py @@ -77,8 +77,8 @@ def Reduced_test( liver.addObject('BoxROI' , name= 'boxROIactuation' , orientedBox= newBox([[-5.0, 0.5, -0.5], [-5.0, 0.0, -0.5], [-4.0, 0.0, -0.5]] , [0.0, 0.0, 0.0],translation,rotation,[0, 0, 0.5],scale) + multiply(scale[2],[1.0]).tolist(),drawBoxes=True) liver.addObject('UniformMass' , totalMass = 0.3) liver.addObject('HyperReducedTetrahedronHyperelasticityFEMForceField' , materialName = 'NeoHookean', ParameterSet = '1923.076923076923 4166.666666666666', AnisotropyDirections = '', name = 'reducedFF_liver_0', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_liver_0_RID.txt', weightsPath = path + r'/data/reducedFF_liver_0_weight.txt') - liver.addObject('HyperReducedRestShapeSpringsForceField' , points = '@ROI1.indices', stiffness = '1e8', name = 'reducedFF_liver_1', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_liver_1_RID.txt', weightsPath = path + r'/data/reducedFF_liver_1_weight.txt') - liver.addObject('HyperReducedRestShapeSpringsForceField' , external_points = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], points = '@boxROIactuation.indices', name = 'reducedFF_liver_2', stiffness = '1e8', external_rest_shape = '@actuator/actuatorState', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_liver_2_RID.txt', weightsPath = path + r'/data/reducedFF_liver_2_weight.txt') + liver.addObject('HyperReducedRestShapeSpringsForceField' , indices = '@ROI1.indices', stiffness = '1e8', name = 'reducedFF_liver_1', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_liver_1_RID.txt', weightsPath = path + r'/data/reducedFF_liver_1_weight.txt') + liver.addObject('HyperReducedRestShapeSpringsForceField' , externalIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], indices = '@boxROIactuation.indices', name = 'reducedFF_liver_2', stiffness = '1e8', external_rest_shape = '@actuator/actuatorState', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_liver_2_RID.txt', weightsPath = path + r'/data/reducedFF_liver_2_weight.txt') liver.addObject('ModelOrderReductionMapping' , input = '@../MechanicalObject', modesPath = path + r'/data/modes.txt', output = '@./MechanicalObject') diff --git a/examples/others/hexaBeam/hexaBeam.pyscn b/examples/others/hexaBeam/hexaBeam.pyscn index e4d89cb..c69c7e3 100644 --- a/examples/others/hexaBeam/hexaBeam.pyscn +++ b/examples/others/hexaBeam/hexaBeam.pyscn @@ -34,7 +34,7 @@ def createScene(rootNode): M1.addObject('MechanicalObject') M1.addObject('UniformMass', totalMass="0.1") M1.addObject('RegularGridTopology', nx="4", ny="4", nz="20", xmin="-9", xmax="-6", ymin="0", ymax="3", zmin="0", zmax="19") - M1.addObject('RestShapeSpringsForceField', points="0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", stiffness=1e12) + M1.addObject('RestShapeSpringsForceField', indices="0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", stiffness=1e12) M1.addObject('HexahedronFEMForceField', name="FEM", youngModulus="4000", poissonRatio="0.3", method="large") M1.addObject('GenericConstraintCorrection') diff --git a/examples/others/hexaBeam/reduced/reduced_hexaBeam.py b/examples/others/hexaBeam/reduced/reduced_hexaBeam.py index f9bcfe8..62177ac 100644 --- a/examples/others/hexaBeam/reduced/reduced_hexaBeam.py +++ b/examples/others/hexaBeam/reduced/reduced_hexaBeam.py @@ -73,7 +73,7 @@ def Reduced_test( M1.addObject('MechanicalObject') M1.addObject('UniformMass' , totalMass = '0.1') M1.addObject('RegularGridTopology' , nx = '4', ny = '4', nz = '20', xmin = '-9', xmax = '-6', ymin = '0', ymax = '3', zmin = '0', zmax = '19') - M1.addObject('HyperReducedRestShapeSpringsForceField' , points = '0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15', stiffness = 1000000000000.0, name = 'reducedFF_M1_0', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_M1_0_RID.txt', weightsPath = path + r'/data/reducedFF_M1_0_weight.txt') + M1.addObject('HyperReducedRestShapeSpringsForceField' , indices = '0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15', stiffness = 1000000000000.0, name = 'reducedFF_M1_0', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_M1_0_RID.txt', weightsPath = path + r'/data/reducedFF_M1_0_weight.txt') M1.addObject('HyperReducedHexahedronFEMForceField' , name = 'reducedFF_M1_1', youngModulus = '4000', poissonRatio = '0.3', method = 'large', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_M1_1_RID.txt', weightsPath = path + r'/data/reducedFF_M1_1_weight.txt') M1.addObject('ModelOrderReductionMapping' , input = '@../MechanicalObject', modesPath = path + r'/data/modes.txt', output = '@./MechanicalObject') diff --git a/examples/softRobots/diamond/reduced/diamond/reduced_diamondRobot.py b/examples/softRobots/diamond/reduced/diamond/reduced_diamondRobot.py index 70ae234..dc15b91 100644 --- a/examples/softRobots/diamond/reduced/diamond/reduced_diamondRobot.py +++ b/examples/softRobots/diamond/reduced/diamond/reduced_diamondRobot.py @@ -87,7 +87,7 @@ def Reduced_test( FixedBox = modelNode.addChild('FixedBox') FixedBox.addObject('BoxROI' , name= 'BoxROI' , orientedBox= newBox([[-15, 15, -40], [-15, -15, -40], [15, -15, -40]] , [0.0, 0.0, 35],translation,rotation,[0, 0, 25.0],scale) + multiply(scale[2],[50]).tolist(),drawBoxes=True) - FixedBox.addObject('HyperReducedRestShapeSpringsForceField' , points = '@BoxROI.indices', stiffness = 1000000000000.0, name = 'reducedFF_FixedBox_1', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_FixedBox_1_RID.txt', weightsPath = path + r'/data/reducedFF_FixedBox_1_weight.txt') + FixedBox.addObject('HyperReducedRestShapeSpringsForceField' , indices = '@BoxROI.indices', stiffness = 1000000000000.0, name = 'reducedFF_FixedBox_1', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_FixedBox_1_RID.txt', weightsPath = path + r'/data/reducedFF_FixedBox_1_weight.txt') north = modelNode.addChild('north') diff --git a/examples/softRobots/diamond/reduced/diamond_hyperElastic/reduced_diamondRobotHyperElastic.py b/examples/softRobots/diamond/reduced/diamond_hyperElastic/reduced_diamondRobotHyperElastic.py index 25b3ee3..3b7dcca 100644 --- a/examples/softRobots/diamond/reduced/diamond_hyperElastic/reduced_diamondRobotHyperElastic.py +++ b/examples/softRobots/diamond/reduced/diamond_hyperElastic/reduced_diamondRobotHyperElastic.py @@ -81,7 +81,7 @@ def Reduced_test( FixedBox = modelNode.addChild('FixedBox') FixedBox.addObject('BoxROI' , name= 'BoxROI' , orientedBox= newBox([[-15, 15, -40], [-15, -15, -40], [15, -15, -40]] , [0.0, 0.0, 35],translation,rotation,[0, 0, 25.0],scale) + multiply(scale[2],[50]).tolist(),drawBoxes=True) - FixedBox.addObject('HyperReducedRestShapeSpringsForceField' , points = '@BoxROI.indices', stiffness = 1000000000000.0, name = 'reducedFF_FixedBox_1', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_FixedBox_1_RID.txt', weightsPath = path + r'/data/reducedFF_FixedBox_1_weight.txt') + FixedBox.addObject('HyperReducedRestShapeSpringsForceField' , indices = '@BoxROI.indices', stiffness = 1000000000000.0, name = 'reducedFF_FixedBox_1', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_FixedBox_1_RID.txt', weightsPath = path + r'/data/reducedFF_FixedBox_1_weight.txt') north = modelNode.addChild('north') diff --git a/examples/softRobots/finger/finger.pyscn b/examples/softRobots/finger/finger.pyscn index e3ffe3a..22e7139 100644 --- a/examples/softRobots/finger/finger.pyscn +++ b/examples/softRobots/finger/finger.pyscn @@ -64,7 +64,7 @@ def createScene(rootNode): # RestShapeSpringsForceField is one way in Sofa to implement fixed point constraint. # Here the constraints are applied to the DoFs selected by the previously defined BoxROI - finger.addObject('RestShapeSpringsForceField', points='@ROI1.indices', stiffness=1e12) + finger.addObject('RestShapeSpringsForceField', indices='@ROI1.indices', stiffness=1e12) ########################################## # Cable # diff --git a/examples/softRobots/finger/reduced/reduced_finger.py b/examples/softRobots/finger/reduced/reduced_finger.py index d965600..b17c281 100644 --- a/examples/softRobots/finger/reduced/reduced_finger.py +++ b/examples/softRobots/finger/reduced/reduced_finger.py @@ -77,7 +77,7 @@ def Reduced_test( finger.addObject('UniformMass' , totalMass = 0.05) finger.addObject('HyperReducedTetrahedronFEMForceField' , poissonRatio = '0.45', youngModulus = '600', name = 'reducedFF_finger_0', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_finger_0_RID.txt', weightsPath = path + r'/data/reducedFF_finger_0_weight.txt') finger.addObject('BoxROI' , name= 'ROI1' , orientedBox= newBox([[-15, 10, 0], [-15, 0, 0], [5, 0, 0]] , [0.0, 0.0, 0.0],translation,rotation,[0, 0, 7.5],scale) + multiply(scale[2],[15]).tolist(),drawBoxes=True) - finger.addObject('HyperReducedRestShapeSpringsForceField' , points = '@ROI1.indices', stiffness = 1000000000000.0, name = 'reducedFF_finger_1', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_finger_1_RID.txt', weightsPath = path + r'/data/reducedFF_finger_1_weight.txt') + finger.addObject('HyperReducedRestShapeSpringsForceField' , indices = '@ROI1.indices', stiffness = 1000000000000.0, name = 'reducedFF_finger_1', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_finger_1_RID.txt', weightsPath = path + r'/data/reducedFF_finger_1_weight.txt') finger.addObject('ModelOrderReductionMapping' , input = '@../MechanicalObject', modesPath = path + r'/data/modes.txt', output = '@./MechanicalObject') diff --git a/examples/softRobots/sofiaLeg/reduced/reduced_sofiaLeg.py b/examples/softRobots/sofiaLeg/reduced/reduced_sofiaLeg.py index 95ada5b..c808bfc 100644 --- a/examples/softRobots/sofiaLeg/reduced/reduced_sofiaLeg.py +++ b/examples/softRobots/sofiaLeg/reduced/reduced_sofiaLeg.py @@ -76,10 +76,10 @@ def Reduced_SofiaLeg( SofiaLeg.addObject('UniformMass' , totalMass = 0.01) SofiaLeg.addObject('HyperReducedTetrahedronFEMForceField' , youngModulus = 300, poissonRatio = 0.45, name = 'reducedFF_SofiaLeg_0', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_SofiaLeg_0_RID.txt', weightsPath = path + r'/data/reducedFF_SofiaLeg_0_weight.txt') SofiaLeg.addObject('BoxROI' , name = 'boxROITop', orientedBox = [[-12.0, 53.0, 0.0], [12.0, 53.0, 0.0], [12.0, 64.0, 0.0], 16.0], drawBoxes = True) - SofiaLeg.addObject('HyperReducedRestShapeSpringsForceField' , name = 'reducedFF_SofiaLeg_1', points = '@boxROITop.indices', stiffness = '1e8', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_SofiaLeg_1_RID.txt', weightsPath = path + r'/data/reducedFF_SofiaLeg_1_weight.txt') + SofiaLeg.addObject('HyperReducedRestShapeSpringsForceField' , name = 'reducedFF_SofiaLeg_1', indices = '@boxROITop.indices', stiffness = '1e8', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_SofiaLeg_1_RID.txt', weightsPath = path + r'/data/reducedFF_SofiaLeg_1_weight.txt') SofiaLeg.addObject('BoxROI' , name = 'boxROICollision', orientedBox = [[-25.0, -41.0, -7.0], [25.0, -42.0, -7.0], [25.0, -39.0, -7.0], 2.0, [-25.0, -42.0, 7.0], [25.0, -42.0, 7.0], [25.0, -39.0, 7.0], 2.0], drawPoints = '0', computeEdges = '0', computeTriangles = '0', computeTetrahedra = '0', computeHexahedra = '0', computeQuad = '0', drawSize = 5, drawBoxes = True) SofiaLeg.addObject('BoxROI' , name = 'boxROIMiddle', orientedBox = [[-2.5, -8.5, 0.0], [2.5, -8.5, 0.0], [2.5, -3.5, 0.0], 18.0], drawBoxes = True) - SofiaLeg.addObject('HyperReducedRestShapeSpringsForceField' , external_points = [0, 1, 2], points = '@boxROIMiddle.indices', name = 'reducedFF_SofiaLeg_2', stiffness = '1e8', external_rest_shape = '@../../SofiaLeg_actuator/actuatorState', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_SofiaLeg_2_RID.txt', weightsPath = path + r'/data/reducedFF_SofiaLeg_2_weight.txt') + SofiaLeg.addObject('HyperReducedRestShapeSpringsForceField' , externalIndices = [0, 1, 2], indices = '@boxROIMiddle.indices', name = 'reducedFF_SofiaLeg_2', stiffness = '1e8', external_rest_shape = '@../../SofiaLeg_actuator/actuatorState', nbModes = nbrOfModes, performECSW = hyperReduction, modesPath = path + r'/data/modes.txt', RIDPath = path + r'/data/reducedFF_SofiaLeg_2_RID.txt', weightsPath = path + r'/data/reducedFF_SofiaLeg_2_weight.txt') SofiaLeg.addObject('ModelOrderReductionMapping' , input = '@../MechanicalObject', modesPath = path + r'/data/modes.txt', output = '@./tetras') diff --git a/examples/softRobots/sofiaLeg/sofiaLeg.py b/examples/softRobots/sofiaLeg/sofiaLeg.py index d21771a..e8b774a 100644 --- a/examples/softRobots/sofiaLeg/sofiaLeg.py +++ b/examples/softRobots/sofiaLeg/sofiaLeg.py @@ -73,7 +73,7 @@ def SofiaLeg( #To fix the Top part of the leg leg.addObject('BoxROI' , name= 'boxROITop' , orientedBox= newBox([[-12.0, 53.0, 0], [12.0, 53.0, 0], [12.0, 64.0, 0]] , [0.0, 0.0, 0.0],translation,rotation,[0, 0, 0.0],scale) + multiply(scale[2],[16.0]).tolist(),drawBoxes=True) - leg.addObject('RestShapeSpringsForceField', name = 'fixedTopForceField', points = '@boxROITop.indices', stiffness = '1e8') + leg.addObject('RestShapeSpringsForceField', name = 'fixedTopForceField', indices = '@boxROITop.indices', stiffness = '1e8') #Box to add collisions only on the tip of the leg leg.addObject('BoxROI', name='boxROICollision', orientedBox= newBox( @@ -87,7 +87,7 @@ def SofiaLeg( #To Actuate our leg we select some elements in the middle of our leg, add a Spring to them, then add an external_rest_shape that will allow us leg.addObject('BoxROI' , name= 'boxROIMiddle' , orientedBox= newBox([[-2.5, -8.5, 0], [2.5, -8.5, 0], [2.5, -3.5, 0]] , [0.0, 0.0, 0.0],translation,rotation,[0, 0, 0.0],scale) + multiply(scale[2],[18.0]).tolist(),drawBoxes=True) - leg.addObject('RestShapeSpringsForceField' , external_points =[i for i in range(3)], points = '@boxROIMiddle.indices', name = 'actuatorSpring', stiffness = '1e8', external_rest_shape = '@../'+name+'_actuator/actuatorState') + leg.addObject('RestShapeSpringsForceField' , externalIndices =[i for i in range(3)], indices = '@boxROIMiddle.indices', name = 'actuatorSpring', stiffness = '1e8', external_rest_shape = '@../'+name+'_actuator/actuatorState') SofiaLeg_actuator = attachedTo.addChild(name+'_actuator') SofiaLeg_actuator.addObject('MechanicalObject' , name = 'actuatorState', position = '@../'+name+'/boxROIMiddle.pointsInROI', template = 'Vec3d', showObject = True, showObjectScale=5) From c98c3c0baaccbb2e41ab40640afaae6487af9419 Mon Sep 17 00:00:00 2001 From: Paul Baksic Date: Tue, 10 Dec 2024 16:33:42 +0100 Subject: [PATCH 2/4] Fix compilation of HyperReducedRestShapeSpringsForceField --- .../HyperReducedRestShapeSpringsForceField.h | 20 +- ...HyperReducedRestShapeSpringsForceField.inl | 207 +++--------------- 2 files changed, 35 insertions(+), 192 deletions(-) diff --git a/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.h b/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.h index 7e3281d..81c126c 100644 --- a/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.h +++ b/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.h @@ -77,17 +77,14 @@ class HyperReducedRestShapeSpringsForceField : public virtual RestShapeSpringsFo using HyperReducedHelper::m_RIDsize; - using RestShapeSpringsForceField::d_points; + using RestShapeSpringsForceField::d_indices; using RestShapeSpringsForceField::d_stiffness; using RestShapeSpringsForceField::d_angularStiffness; - using RestShapeSpringsForceField::d_pivotPoints; - using RestShapeSpringsForceField::d_external_points; - using RestShapeSpringsForceField::d_recompute_indices; + using RestShapeSpringsForceField::d_externalIndices; using RestShapeSpringsForceField::d_drawSpring; using RestShapeSpringsForceField::d_springColor; using RestShapeSpringsForceField::l_restMState; using RestShapeSpringsForceField::d_activeDirections; - using RestShapeSpringsForceField::matS; protected: HyperReducedRestShapeSpringsForceField(); @@ -107,19 +104,6 @@ class HyperReducedRestShapeSpringsForceField : public virtual RestShapeSpringsFo virtual void draw(const core::visual::VisualParams* vparams) override; - const DataVecCoord* getExtPosition() const; - const VecIndex& getExtIndices() const { return (useRestMState ? m_ext_indices : m_indices); } - -protected : - void recomputeIndices(); - bool checkOutOfBoundsIndices(); - - using RestShapeSpringsForceField::m_indices; - using RestShapeSpringsForceField::m_ext_indices; - using RestShapeSpringsForceField::m_pivots; - - using RestShapeSpringsForceField::lastUpdatedStep; - private : bool useRestMState; /// An external MechanicalState is used as rest reference. diff --git a/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.inl b/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.inl index b1087b0..03d088a 100644 --- a/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.inl +++ b/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.inl @@ -73,159 +73,17 @@ using core::visual::VisualParams; template HyperReducedRestShapeSpringsForceField::HyperReducedRestShapeSpringsForceField() { -} - -template -void HyperReducedRestShapeSpringsForceField::parse(core::objectmodel::BaseObjectDescription *arg) -{ - const char* attr = arg->getAttribute("external_rest_shape") ; - if( attr != nullptr && attr[0] != '@') - { - msg_error() << "HyperReducedRestShapeSpringsForceField have changed since 17.06. The parameter 'external_rest_shape' is now a Link. To fix your scene you need to add and '@' in front of the provided path. See PR#315" ; - } - Inherit::parse(arg) ; } template void HyperReducedRestShapeSpringsForceField::bwdInit() { - ForceField::init(); - - if (d_stiffness.getValue().empty()) - { - msg_info() << "No stiffness is defined, assuming equal stiffness on each node, k = 100.0 "; - - VecReal stiffs; - stiffs.push_back(100.0); - d_stiffness.setValue(stiffs); - } - - if (l_restMState.get() == NULL) - { - useRestMState = false; - msg_info() << "no external rest shape used"; - - if(!l_restMState.empty()) - { - msg_warning() << "external_rest_shape in node " << this->getContext()->getName() << " not found"; - } - } - else - { - msg_info() << "external rest shape used"; - useRestMState = true; - } - - recomputeIndices(); - - BaseMechanicalState* state = this->getContext()->getMechanicalState(); - if(!state) - { - msg_warning() << "MechanicalState of the current context returns null pointer"; - } - else - { - assert(state); - matS.resize(state->getMatrixSize(),state->getMatrixSize()); - } - lastUpdatedStep = -1.0; - this->initMOR(d_points.getValue().size(),notMuted()); + RestShapeSpringsForceField::init(); + this->initMOR(d_indices.getValue().size(),notMuted()); } -template -void HyperReducedRestShapeSpringsForceField::reinit() -{ - if (d_stiffness.getValue().empty()) - { - msg_info() << "No stiffness is defined, assuming equal stiffness on each node, k = 100.0 " ; - VecReal stiffs; - stiffs.push_back(100.0); - d_stiffness.setValue(stiffs); - } -} - -template -void HyperReducedRestShapeSpringsForceField::recomputeIndices() -{ - m_indices.clear(); - m_ext_indices.clear(); - - for (unsigned int i = 0; i < d_points.getValue().size(); i++) - { - m_indices.push_back(d_points.getValue()[i]); - } - - for (unsigned int i = 0; i < d_external_points.getValue().size(); i++) - { - m_ext_indices.push_back(d_external_points.getValue()[i]); - } - - if (m_indices.empty()) - { - // no point are defined, default case: points = all points - for (unsigned int i = 0; i < (unsigned)this->mstate->getSize(); i++) - { - m_indices.push_back(i); - } - } - - if (m_ext_indices.empty()) - { - if (useRestMState) - { - for (unsigned int i = 0; i < getExtPosition()->getValue().size(); i++) - { - m_ext_indices.push_back(i); - } - } - else - { - for (unsigned int i = 0; i < m_indices.size(); i++) - { - m_ext_indices.push_back(m_indices[i]); - } - } - } - - if (!checkOutOfBoundsIndices()) - { - msg_error() << "The dimension of the source and the targeted points are different "; - m_indices.clear(); - } - else - { - msg_info() << "Indices successfully checked"; - } -} - -template -bool HyperReducedRestShapeSpringsForceField::checkOutOfBoundsIndices() -{ - if (!RestShapeSpringsForceField::checkOutOfBoundsIndices(m_indices, this->mstate->getSize())) - { - msg_error() << "Out of Bounds m_indices detected. ForceField is not activated."; - return false; - } - if (!RestShapeSpringsForceField::checkOutOfBoundsIndices(m_ext_indices, getExtPosition()->getValue().size())) - { - msg_error() << "Out of Bounds m_ext_indices detected. ForceField is not activated."; - return false; - } - if (m_indices.size() != m_ext_indices.size()) - { - msg_error() << "Dimensions of the source and the targeted points are different. ForceField is not activated."; - return false; - } - return true; -} - -template -const typename HyperReducedRestShapeSpringsForceField::DataVecCoord* HyperReducedRestShapeSpringsForceField::getExtPosition() const -{ - return (useRestMState ? l_restMState->read(VecCoordId::position()) : this->mstate->read(VecCoordId::restPosition())); -} template void HyperReducedRestShapeSpringsForceField::addForce(const MechanicalParams* mparams , DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v ) @@ -240,20 +98,18 @@ void HyperReducedRestShapeSpringsForceField::addForce(const Mechanica f1.resize(p1.size()); - if (d_recompute_indices.getValue()) - { - this->recomputeIndices(); - } + const auto & indices = this->getIndices(); + const auto & extIndices = this->getExtIndices(); unsigned int i; const VecReal &k = d_stiffness.getValue(); - if ( k.size()!= m_indices.size() ) + if ( k.size()!= indices.size() ) { const Real k0 = k[0]; unsigned int nbElementsConsidered; if (!d_performECSW.getValue()) { - nbElementsConsidered = m_indices.size(); + nbElementsConsidered = indices.size(); } else { @@ -263,7 +119,7 @@ void HyperReducedRestShapeSpringsForceField::addForce(const Mechanica else { msg_warning() << "RID is empty!!! Taking all the elements..."; - nbElementsConsidered = m_indices.size(); + nbElementsConsidered = indices.size(); } } for (unsigned int point = 0 ; point::addForce(const Mechanica else i = reducedIntegrationDomain(point); - const unsigned int index = m_indices[i]; + const unsigned int index = indices[i]; - unsigned int ext_index = m_indices[i]; + unsigned int ext_index = indices[i]; if(useRestMState) - ext_index= m_ext_indices[i]; + ext_index= extIndices[i]; Deriv dx = p1[index] - p0[ext_index]; std::vector contrib; @@ -300,7 +156,7 @@ void HyperReducedRestShapeSpringsForceField::addForce(const Mechanica unsigned int nbElementsConsidered; if (!d_performECSW.getValue()) - nbElementsConsidered = m_indices.size(); + nbElementsConsidered = indices.size(); else { if (m_RIDsize != 0) { @@ -308,7 +164,7 @@ void HyperReducedRestShapeSpringsForceField::addForce(const Mechanica } else { - nbElementsConsidered = m_indices.size(); + nbElementsConsidered = indices.size(); msg_warning("RID is empty! Taking all the elements..."); } } @@ -319,11 +175,11 @@ void HyperReducedRestShapeSpringsForceField::addForce(const Mechanica else i = reducedIntegrationDomain(point); - const unsigned int index = m_indices[i]; + const unsigned int index = indices[i]; - unsigned int ext_index = m_indices[i]; + unsigned int ext_index = indices[i]; if(useRestMState) - ext_index= m_ext_indices[i]; + ext_index= extIndices[i]; Deriv dx = p1[index] - p0[ext_index]; std::vector contrib; @@ -339,7 +195,7 @@ void HyperReducedRestShapeSpringsForceField::addForce(const Mechanica this->template updateGie(indexList, contrib, i); } } - this->saveGieFile(m_indices.size()); + this->saveGieFile(indices.size()); } template @@ -351,23 +207,25 @@ void HyperReducedRestShapeSpringsForceField::addDForce(const Mechanic ReadAccessor< DataVecDeriv > dx1 = dx; Real kFactor = (Real)mparams->kFactorIncludingRayleighDamping(this->rayleighStiffness.getValue()); + const auto & indices = this->getIndices(); + const VecReal &k = d_stiffness.getValue(); - if (k.size()!= m_indices.size() ) + if (k.size()!= indices.size() ) { const Real k0 = k[0]; if (d_performECSW.getValue()){ for(unsigned int i = 0 ; i::addDForce(const Mechanic if (d_performECSW.getValue()){ for(unsigned int i = 0 ; i::draw(const VisualParams ReadAccessor< DataVecCoord > p0 = *this->getExtPosition(); ReadAccessor< DataVecCoord > p = this->mstate->read(VecCoordId::position()); - const VecIndex& indices = m_indices; - const VecIndex& ext_indices = (useRestMState ? m_ext_indices : m_indices); + const VecIndex& indices = this->getIndices(); + const VecIndex& ext_indices = this->getExtIndices(); vector vertices; if (d_performECSW.getValue()){ @@ -472,18 +330,19 @@ void HyperReducedRestShapeSpringsForceField::buildStiffnessMatrix( .withRespectToPositionsIn(this->mstate); unsigned int nbIndicesConsidered; sofa::Index curIndex; + const VecIndex& indices = this->getIndices(); if (d_performECSW.getValue()) nbIndicesConsidered = m_RIDsize; else - nbIndicesConsidered = m_indices.size(); + nbIndicesConsidered = indices.size(); for (sofa::Index index = 0; index < nbIndicesConsidered ; index++) { if (!d_performECSW.getValue()) - curIndex = m_indices[index]; + curIndex = indices[index]; else - curIndex = m_indices[reducedIntegrationDomain(index)]; + curIndex = indices[reducedIntegrationDomain(index)]; // translation const auto vt = -k[(curIndex < k.size()) * curIndex]; From d2810b22a867a40d8b79dd1d8044fe539b5f93d0 Mon Sep 17 00:00:00 2001 From: Paul Baksic Date: Tue, 10 Dec 2024 17:19:24 +0100 Subject: [PATCH 3/4] Add usage of fixAll --- ...HyperReducedRestShapeSpringsForceField.inl | 135 ++++++++++++++---- 1 file changed, 105 insertions(+), 30 deletions(-) diff --git a/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.inl b/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.inl index 03d088a..77e0e52 100644 --- a/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.inl +++ b/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.inl @@ -100,16 +100,18 @@ void HyperReducedRestShapeSpringsForceField::addForce(const Mechanica const auto & indices = this->getIndices(); const auto & extIndices = this->getExtIndices(); + const bool fixedAll = this->d_fixAll.getValue(); + const unsigned maxIt = fixedAll ? this->mstate->getSize() : indices.size(); unsigned int i; const VecReal &k = d_stiffness.getValue(); - if ( k.size()!= indices.size() ) + if ( k.size()!= maxIt ) { const Real k0 = k[0]; unsigned int nbElementsConsidered; if (!d_performECSW.getValue()) { - nbElementsConsidered = indices.size(); + nbElementsConsidered = maxIt; } else { @@ -119,7 +121,7 @@ void HyperReducedRestShapeSpringsForceField::addForce(const Mechanica else { msg_warning() << "RID is empty!!! Taking all the elements..."; - nbElementsConsidered = indices.size(); + nbElementsConsidered = maxIt; } } for (unsigned int point = 0 ; point::addForce(const Mechanica else i = reducedIntegrationDomain(point); - const unsigned int index = indices[i]; + unsigned int index = i; + unsigned int ext_index = i; - unsigned int ext_index = indices[i]; + if (!fixedAll) + { + index = indices[i]; + ext_index = extIndices[i]; + } - if(useRestMState) - ext_index= extIndices[i]; Deriv dx = p1[index] - p0[ext_index]; std::vector contrib; @@ -156,7 +161,7 @@ void HyperReducedRestShapeSpringsForceField::addForce(const Mechanica unsigned int nbElementsConsidered; if (!d_performECSW.getValue()) - nbElementsConsidered = indices.size(); + nbElementsConsidered = maxIt; else { if (m_RIDsize != 0) { @@ -164,7 +169,7 @@ void HyperReducedRestShapeSpringsForceField::addForce(const Mechanica } else { - nbElementsConsidered = indices.size(); + nbElementsConsidered = maxIt; msg_warning("RID is empty! Taking all the elements..."); } } @@ -175,11 +180,14 @@ void HyperReducedRestShapeSpringsForceField::addForce(const Mechanica else i = reducedIntegrationDomain(point); - const unsigned int index = indices[i]; + unsigned int index = i; + unsigned int ext_index = i; - unsigned int ext_index = indices[i]; - if(useRestMState) - ext_index= extIndices[i]; + if (!fixedAll) + { + index = indices[i]; + ext_index = extIndices[i]; + } Deriv dx = p1[index] - p0[ext_index]; std::vector contrib; @@ -195,7 +203,7 @@ void HyperReducedRestShapeSpringsForceField::addForce(const Mechanica this->template updateGie(indexList, contrib, i); } } - this->saveGieFile(indices.size()); + this->saveGieFile(maxIt); } template @@ -208,24 +216,43 @@ void HyperReducedRestShapeSpringsForceField::addDForce(const Mechanic Real kFactor = (Real)mparams->kFactorIncludingRayleighDamping(this->rayleighStiffness.getValue()); const auto & indices = this->getIndices(); + const bool fixedAll = this->d_fixAll.getValue(); + const unsigned maxIt = fixedAll ? this->mstate->getSize() : indices.size(); + sofa::Index index; const VecReal &k = d_stiffness.getValue(); - if (k.size()!= indices.size() ) + if (k.size()!= maxIt ) { const Real k0 = k[0]; if (d_performECSW.getValue()){ for(unsigned int i = 0 ; i::addDForce(const Mechanic if (d_performECSW.getValue()){ for(unsigned int i = 0 ; i::draw(const VisualParams const VecIndex& indices = this->getIndices(); const VecIndex& ext_indices = this->getExtIndices(); + const bool fixedAll = this->d_fixAll.getValue(); + const unsigned maxIt = fixedAll ? this->mstate->getSize() : indices.size(); + unsigned int index; + unsigned int ext_index; + vector vertices; if (d_performECSW.getValue()){ for (unsigned int i=0; i::draw(const VisualParams } else { - for (unsigned int i=0; i::buildStiffnessMatrix( unsigned int nbIndicesConsidered; sofa::Index curIndex; const VecIndex& indices = this->getIndices(); + const bool fixedAll = this->d_fixAll.getValue(); + const unsigned maxIt = fixedAll ? this->mstate->getSize() : indices.size(); if (d_performECSW.getValue()) nbIndicesConsidered = m_RIDsize; else - nbIndicesConsidered = indices.size(); + nbIndicesConsidered = maxIt; for (sofa::Index index = 0; index < nbIndicesConsidered ; index++) { if (!d_performECSW.getValue()) - curIndex = indices[index]; + { + if (!fixedAll) + { + curIndex = indices[index]; + } + else + { + curIndex = index; + } + } else curIndex = indices[reducedIntegrationDomain(index)]; From b8fb227128e1cdfc1eb0e55a4e915fd258147232 Mon Sep 17 00:00:00 2001 From: Paul Baksic Date: Wed, 11 Dec 2024 11:27:44 +0100 Subject: [PATCH 4/4] Clean header --- .../forcefield/HyperReducedRestShapeSpringsForceField.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.h b/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.h index 81c126c..c9c4193 100644 --- a/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.h +++ b/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.h @@ -92,8 +92,6 @@ class HyperReducedRestShapeSpringsForceField : public virtual RestShapeSpringsFo public: /// BaseObject initialization method. void bwdInit() override ; - virtual void parse(core::objectmodel::BaseObjectDescription *arg) override ; - virtual void reinit() override ; /// Add the forces. virtual void addForce(const core::MechanicalParams* mparams, DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v) override; @@ -103,10 +101,6 @@ class HyperReducedRestShapeSpringsForceField : public virtual RestShapeSpringsFo void buildStiffnessMatrix(core::behavior::StiffnessMatrix* /* matrix */) override; virtual void draw(const core::visual::VisualParams* vparams) override; - -private : - - bool useRestMState; /// An external MechanicalState is used as rest reference. }; #if !defined(SOFA_COMPONENT_FORCEFIELD_HYPERREDUCEDRESTSHAPESPRINGSFORCEFIELD_CPP)