diff --git a/CMakeLists.txt b/CMakeLists.txt index 0af8de7..6aa020b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,8 @@ set(HEADER_FILES ${MOR_SRC}/component/forcefield/HyperReducedHexahedronFEMForceField.h ${MOR_SRC}/component/forcefield/HyperReducedHexahedronFEMForceField.inl ${MOR_SRC}/component/forcefield/HyperReducedRestShapeSpringsForceField.h - ${MOR_SRC}/component/forcefield/HyperReducedRestShapeSpringsForceField.inl + ${MOR_SRC}/component/forcefield/HyperReducedFixedWeakConstraint.h + ${MOR_SRC}/component/forcefield/HyperReducedFixedWeakConstraint.inl ${MOR_SRC}/component/forcefield/HyperReducedTetrahedralCorotationalFEMForceField.h ${MOR_SRC}/component/forcefield/HyperReducedTetrahedralCorotationalFEMForceField.inl ${MOR_SRC}/component/forcefield/HyperReducedTetrahedronFEMForceField.h @@ -58,6 +59,7 @@ set(SOURCE_FILES ${MOR_SRC}/component/forcefield/HyperReducedHelper.cpp ${MOR_SRC}/component/forcefield/HyperReducedHexahedronFEMForceField.cpp ${MOR_SRC}/component/forcefield/HyperReducedRestShapeSpringsForceField.cpp + ${MOR_SRC}/component/forcefield/HyperReducedFixedWeakConstraint.cpp ${MOR_SRC}/component/forcefield/HyperReducedTetrahedralCorotationalFEMForceField.cpp ${MOR_SRC}/component/forcefield/HyperReducedTetrahedronFEMForceField.cpp ${MOR_SRC}/component/forcefield/HyperReducedTetrahedronHyperelasticityFEMForceField.cpp diff --git a/examples/organs/liver/liverFineHyperElastic.pyscn b/examples/organs/liver/liverFineHyperElastic.pyscn index f09f8c1..95682ae 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('FixedWeakConstraint', 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/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..3404b4b 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('HyperReducedFixedWeakConstraint' , 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..2aa64b5 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('HyperReducedFixedWeakConstraint' , 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..33dc0b1 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('FixedWeakConstraint', 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..dfffb80 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('HyperReducedFixedWeakConstraint' , 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..b1d62b6 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('HyperReducedFixedWeakConstraint' , 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..037a98f 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('HyperReducedFixedWeakConstraint' , 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..7e5be45 100644 --- a/examples/softRobots/finger/finger.pyscn +++ b/examples/softRobots/finger/finger.pyscn @@ -62,9 +62,9 @@ def createScene(rootNode): # Or "SphereROI"... # finger.addObject('SphereROI', name='ROI', centers='0 0 0', radii='5') - # RestShapeSpringsForceField is one way in Sofa to implement fixed point constraint. + # FixedWeakConstraint 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('FixedWeakConstraint', 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..c52b174 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('HyperReducedFixedWeakConstraint' , 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..1acf911 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('HyperReducedFixedWeakConstraint' , 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) diff --git a/python/mor/utility/sceneCreation.py b/python/mor/utility/sceneCreation.py index 5dcb2fa..b523f54 100644 --- a/python/mor/utility/sceneCreation.py +++ b/python/mor/utility/sceneCreation.py @@ -34,7 +34,8 @@ 'HyperReducedHexahedronFEMForceField':'hexahedra', 'HyperReducedTetrahedronFEMForceField':'tetrahedra', 'HyperReducedTriangleFEMForceField':'triangles', - 'HyperReducedRestShapeSpringsForceField':'points' + 'HyperReducedRestShapeSpringsForceField':'indices', + 'FixedWeakConstraint':'indices' } import Sofa diff --git a/python/mor/wrapper/replaceAndSave.py b/python/mor/wrapper/replaceAndSave.py index 81b0285..230e282 100644 --- a/python/mor/wrapper/replaceAndSave.py +++ b/python/mor/wrapper/replaceAndSave.py @@ -37,7 +37,8 @@ 'HexahedronFEMForceField':('HyperReducedHexahedronFEMForceField','hexahedra'), 'TetrahedronFEMForceField':('HyperReducedTetrahedronFEMForceField','tetrahedra'), 'TriangleFEMForceField':('HyperReducedTriangleFEMForceField','triangles'), - 'RestShapeSpringsForceField':('HyperReducedRestShapeSpringsForceField','points') + 'RestShapeSpringsForceField':('HyperReducedRestShapeSpringsForceField','indices'), + 'FixedWeakConstraint':('HyperReducedFixedWeakConstraint','indices') } diff --git a/src/ModelOrderReduction/component/forcefield/HyperReducedFixedWeakConstraint.cpp b/src/ModelOrderReduction/component/forcefield/HyperReducedFixedWeakConstraint.cpp new file mode 100644 index 0000000..dfcce84 --- /dev/null +++ b/src/ModelOrderReduction/component/forcefield/HyperReducedFixedWeakConstraint.cpp @@ -0,0 +1,38 @@ +/****************************************************************************** +* Model Order Reduction plugin for SOFA * +* version 1.0 * +* Copyright © Inria * +* All rights reserved * +* 2018 * +* * +* This software is under the GNU General Public License v2 (GPLv2) * +* https://www.gnu.org/licenses/licenses.en.html * +* * +* * +* * +* Authors: Olivier Goury, Felix Vanneste * +* * +* Contact information: https://project.inria.fr/modelorderreduction/contact * +******************************************************************************/ +#define SOFA_COMPONENT_FORCEFIELD_HYPERREDUCEDFIXEDWEAKCONSTRAINT_CPP + +#include + +#include +#include + +namespace sofa::component::solidmechanics::spring +{ + +using namespace sofa::defaulttype; + + +SOFA_DECL_CLASS(HyperReducedFixedWeakConstraint) + + +int HyperReducedFixedWeakConstraintClass = core::RegisterObject("Simple elastic springs applied to given degrees of freedom between their current and rest shape position") + .add< HyperReducedFixedWeakConstraint >() + ; + +template class SOFA_MODELORDERREDUCTION_API HyperReducedFixedWeakConstraint; +} // namespace sofa::component::solidmechanics::spring diff --git a/src/ModelOrderReduction/component/forcefield/HyperReducedFixedWeakConstraint.h b/src/ModelOrderReduction/component/forcefield/HyperReducedFixedWeakConstraint.h new file mode 100644 index 0000000..450c101 --- /dev/null +++ b/src/ModelOrderReduction/component/forcefield/HyperReducedFixedWeakConstraint.h @@ -0,0 +1,110 @@ +/****************************************************************************** +* Model Order Reduction plugin for SOFA * +* version 1.0 * +* Copyright © Inria * +* All rights reserved * +* 2018 * +* * +* This software is under the GNU General Public License v2 (GPLv2) * +* https://www.gnu.org/licenses/licenses.en.html * +* * +* * +* * +* Authors: Olivier Goury, Felix Vanneste * +* * +* Contact information: https://project.inria.fr/modelorderreduction/contact * +******************************************************************************/ +#pragma once +#include + +#include +#include + +namespace sofa::core::behavior +{ +template< class T > class MechanicalState; +} // namespace sofa::core::behavior + +namespace sofa::component::solidmechanics::spring +{ + +/** +* @brief This class describes a simple elastic springs ForceField between DOFs positions and rest positions. +* +* Springs are applied to given degrees of freedom between their current positions and their rest shape positions. +* An external MechanicalState reference can also be passed to the ForceField as rest shape position. +*/ +template +class HyperReducedFixedWeakConstraint : public virtual FixedWeakConstraint, public modelorderreduction::HyperReducedHelper +{ +public: + SOFA_CLASS2(SOFA_TEMPLATE(HyperReducedFixedWeakConstraint, DataTypes), SOFA_TEMPLATE(FixedWeakConstraint, DataTypes), HyperReducedHelper); + + typedef HyperReducedHelper Inherit; + typedef typename DataTypes::VecCoord VecCoord; + typedef typename DataTypes::VecDeriv VecDeriv; + typedef typename DataTypes::Coord Coord; + typedef typename DataTypes::CPos CPos; + typedef typename DataTypes::Deriv Deriv; + typedef typename DataTypes::Real Real; + typedef type::vector< sofa::Index > VecIndex; + typedef type::vector< Real > VecReal; + + typedef core::objectmodel::Data DataVecCoord; + typedef core::objectmodel::Data DataVecDeriv; + + ////////////////////////// Inherited attributes //////////////////////////// + /// https://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html + /// Bring inherited attributes and function in the current lookup context. + /// otherwise any access to the base::attribute would require + /// the "this->" approach. + + using HyperReducedHelper::d_prepareECSW; + using HyperReducedHelper::d_nbModes; + using HyperReducedHelper::d_modesPath; + using HyperReducedHelper::d_nbTrainingSet; + using HyperReducedHelper::d_periodSaveGIE; + + using HyperReducedHelper::d_performECSW; + using HyperReducedHelper::d_RIDPath; + using HyperReducedHelper::d_weightsPath; + + using HyperReducedHelper::Gie; + using HyperReducedHelper::weights; + using HyperReducedHelper::reducedIntegrationDomain; + + using HyperReducedHelper::m_modes; + using HyperReducedHelper::m_RIDsize; + + + using FixedWeakConstraint::d_indices; + using FixedWeakConstraint::d_stiffness; + using FixedWeakConstraint::d_angularStiffness; + using FixedWeakConstraint::d_fixAll; + using FixedWeakConstraint::d_drawSpring; + using FixedWeakConstraint::d_springColor; + using FixedWeakConstraint::l_topology; + +protected: + HyperReducedFixedWeakConstraint(); + +public: + /// BaseObject initialization method. + void bwdInit() override ; + + /// Add the forces. + virtual void addForce(const core::MechanicalParams* mparams, DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v) override; + + virtual void addDForce(const core::MechanicalParams* mparams, DataVecDeriv& df, const DataVecDeriv& dx) override; + + void buildStiffnessMatrix(core::behavior::StiffnessMatrix* /* matrix */) override; + + virtual void draw(const core::visual::VisualParams* vparams) override; +}; + +#if !defined(SOFA_COMPONENT_FORCEFIELD_HYPERREDUCEDFIXEDWEAKCONSTRAINT_CPP) + +extern template class SOFA_MODELORDERREDUCTION_API HyperReducedFixedWeakConstraint; + +#endif +} // namespace sofa::component::solidmechanics::spring diff --git a/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.inl b/src/ModelOrderReduction/component/forcefield/HyperReducedFixedWeakConstraint.inl similarity index 58% rename from src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.inl rename to src/ModelOrderReduction/component/forcefield/HyperReducedFixedWeakConstraint.inl index a556f03..443d9b3 100644 --- a/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.inl +++ b/src/ModelOrderReduction/component/forcefield/HyperReducedFixedWeakConstraint.inl @@ -16,7 +16,7 @@ ******************************************************************************/ #pragma once -#include +#include #include #include #include @@ -71,164 +71,21 @@ using type::vector; using core::visual::VisualParams; template -HyperReducedRestShapeSpringsForceField::HyperReducedRestShapeSpringsForceField() +HyperReducedFixedWeakConstraint::HyperReducedFixedWeakConstraint() { -} - -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()); -} - -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() +void HyperReducedFixedWeakConstraint::bwdInit() { - 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; + FixedWeakConstraint::init(); + this->initMOR(d_indices.getValue().size(),notMuted()); } -template -const typename HyperReducedRestShapeSpringsForceField::DataVecCoord* HyperReducedRestShapeSpringsForceField::getExtPosition() const -{ - return (useRestMState ? l_restMState->read(sofa::core::vec_id::read_access::position) : this->mstate->read(sofa::core::vec_id::read_access::restPosition)); -} template -void HyperReducedRestShapeSpringsForceField::addForce(const MechanicalParams* mparams , DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v ) +void HyperReducedFixedWeakConstraint::addForce(const MechanicalParams* mparams , DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v ) { msg_info() << "--------------------------------> addForce"; @@ -240,20 +97,20 @@ 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(); + 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()!= m_indices.size() ) + if ( k.size()!= maxIt ) { const Real k0 = k[0]; unsigned int nbElementsConsidered; if (!d_performECSW.getValue()) { - nbElementsConsidered = m_indices.size(); + nbElementsConsidered = maxIt; } else { @@ -263,7 +120,7 @@ void HyperReducedRestShapeSpringsForceField::addForce(const Mechanica else { msg_warning() << "RID is empty!!! Taking all the elements..."; - nbElementsConsidered = m_indices.size(); + nbElementsConsidered = maxIt; } } for (unsigned int point = 0 ; point::addForce(const Mechanica else i = reducedIntegrationDomain(point); - const unsigned int index = m_indices[i]; + unsigned int index = i; + unsigned int ext_index = i; - unsigned int ext_index = m_indices[i]; + if (!fixedAll) + { + index = indices[i]; + ext_index = extIndices[i]; + } - if(useRestMState) - ext_index= m_ext_indices[i]; Deriv dx = p1[index] - p0[ext_index]; std::vector contrib; @@ -300,7 +160,7 @@ void HyperReducedRestShapeSpringsForceField::addForce(const Mechanica unsigned int nbElementsConsidered; if (!d_performECSW.getValue()) - nbElementsConsidered = m_indices.size(); + nbElementsConsidered = maxIt; else { if (m_RIDsize != 0) { @@ -308,7 +168,7 @@ void HyperReducedRestShapeSpringsForceField::addForce(const Mechanica } else { - nbElementsConsidered = m_indices.size(); + nbElementsConsidered = maxIt; msg_warning("RID is empty! Taking all the elements..."); } } @@ -319,11 +179,14 @@ void HyperReducedRestShapeSpringsForceField::addForce(const Mechanica else i = reducedIntegrationDomain(point); - const unsigned int index = m_indices[i]; + unsigned int index = i; + unsigned int ext_index = i; - unsigned int ext_index = m_indices[i]; - if(useRestMState) - ext_index= m_ext_indices[i]; + if (!fixedAll) + { + index = indices[i]; + ext_index = extIndices[i]; + } Deriv dx = p1[index] - p0[ext_index]; std::vector contrib; @@ -339,11 +202,11 @@ void HyperReducedRestShapeSpringsForceField::addForce(const Mechanica this->template updateGie(indexList, contrib, i); } } - this->saveGieFile(m_indices.size()); + this->saveGieFile(maxIt); } template -void HyperReducedRestShapeSpringsForceField::addDForce(const MechanicalParams* mparams, DataVecDeriv& df, const DataVecDeriv& dx) +void HyperReducedFixedWeakConstraint::addDForce(const MechanicalParams* mparams, DataVecDeriv& df, const DataVecDeriv& dx) { msg_info() << "--------------------------------> addDForce"; @@ -351,23 +214,44 @@ void HyperReducedRestShapeSpringsForceField::addDForce(const Mechanic ReadAccessor< DataVecDeriv > dx1 = dx; 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()!= m_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::addDForce(const Mechanic // draw for standard types (i.e Vec<1,2,3>) template -void HyperReducedRestShapeSpringsForceField::draw(const VisualParams *vparams) +void HyperReducedFixedWeakConstraint::draw(const VisualParams *vparams) { if (!vparams->displayFlags().getShowForceFields() || !d_drawSpring.getValue()) return; /// \todo put this in the parent class @@ -411,15 +311,28 @@ void HyperReducedRestShapeSpringsForceField::draw(const VisualParams ReadAccessor< DataVecCoord > p0 = *this->getExtPosition(); ReadAccessor< DataVecCoord > p = this->mstate->read(sofa::core::vec_id::read_access::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(); + + 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::draw(const VisualParams } template -void HyperReducedRestShapeSpringsForceField::buildStiffnessMatrix( +void HyperReducedFixedWeakConstraint::buildStiffnessMatrix( core::behavior::StiffnessMatrix* matrix) { const VecReal& k = d_stiffness.getValue(); const VecReal& k_a = d_angularStiffness.getValue(); - const auto activeDirections = d_activeDirections.getValue(); + const auto activeDirections = this->getActiveDirections(); constexpr sofa::Size space_size = Deriv::spatial_dimensions; // == total_size if DataTypes = VecTypes constexpr sofa::Size total_size = Deriv::total_size; @@ -472,18 +393,30 @@ void HyperReducedRestShapeSpringsForceField::buildStiffnessMatrix( .withRespectToPositionsIn(this->mstate); 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 = m_indices.size(); + nbIndicesConsidered = maxIt; for (sofa::Index index = 0; index < nbIndicesConsidered ; index++) { if (!d_performECSW.getValue()) - curIndex = m_indices[index]; + { + if (!fixedAll) + { + curIndex = indices[index]; + } + else + { + curIndex = index; + } + } else - curIndex = m_indices[reducedIntegrationDomain(index)]; + curIndex = indices[reducedIntegrationDomain(index)]; // translation const auto vt = -k[(curIndex < k.size()) * curIndex]; diff --git a/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.cpp b/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.cpp index 472fc9a..a28cb6a 100644 --- a/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.cpp +++ b/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.cpp @@ -16,7 +16,8 @@ ******************************************************************************/ #define SOFA_COMPONENT_FORCEFIELD_HYPERREDUCEDRESTSHAPESPRINGSFORCEFIELD_CPP -#include +#include +#include #include #include diff --git a/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.h b/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.h index 7e3281d..0c48cb9 100644 --- a/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.h +++ b/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.h @@ -15,9 +15,12 @@ * Contact information: https://project.inria.fr/modelorderreduction/contact * ******************************************************************************/ #pragma once +#include "HyperReducedFixedWeakConstraint.h" + #include #include +#include #include namespace sofa::core::behavior @@ -35,94 +38,23 @@ namespace sofa::component::solidmechanics::spring * An external MechanicalState reference can also be passed to the ForceField as rest shape position. */ template -class HyperReducedRestShapeSpringsForceField : public virtual RestShapeSpringsForceField, public modelorderreduction::HyperReducedHelper +class HyperReducedRestShapeSpringsForceField : public virtual RestShapeSpringsForceField, public virtual modelorderreduction::HyperReducedHelper, public HyperReducedFixedWeakConstraint { public: - SOFA_CLASS2(SOFA_TEMPLATE(HyperReducedRestShapeSpringsForceField, DataTypes), SOFA_TEMPLATE(RestShapeSpringsForceField, DataTypes), HyperReducedHelper); - - typedef HyperReducedHelper Inherit; - typedef typename DataTypes::VecCoord VecCoord; - typedef typename DataTypes::VecDeriv VecDeriv; - typedef typename DataTypes::Coord Coord; - typedef typename DataTypes::CPos CPos; - typedef typename DataTypes::Deriv Deriv; - typedef typename DataTypes::Real Real; - typedef type::vector< sofa::Index > VecIndex; - typedef type::vector< Real > VecReal; - - typedef core::objectmodel::Data DataVecCoord; - typedef core::objectmodel::Data DataVecDeriv; - - ////////////////////////// Inherited attributes //////////////////////////// - /// https://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html - /// Bring inherited attributes and function in the current lookup context. - /// otherwise any access to the base::attribute would require - /// the "this->" approach. - - using HyperReducedHelper::d_prepareECSW; - using HyperReducedHelper::d_nbModes; - using HyperReducedHelper::d_modesPath; - using HyperReducedHelper::d_nbTrainingSet; - using HyperReducedHelper::d_periodSaveGIE; - - using HyperReducedHelper::d_performECSW; - using HyperReducedHelper::d_RIDPath; - using HyperReducedHelper::d_weightsPath; - - using HyperReducedHelper::Gie; - using HyperReducedHelper::weights; - using HyperReducedHelper::reducedIntegrationDomain; - - using HyperReducedHelper::m_modes; - using HyperReducedHelper::m_RIDsize; - - - using RestShapeSpringsForceField::d_points; - 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_drawSpring; - using RestShapeSpringsForceField::d_springColor; - using RestShapeSpringsForceField::l_restMState; - using RestShapeSpringsForceField::d_activeDirections; - using RestShapeSpringsForceField::matS; + SOFA_CLASS3(SOFA_TEMPLATE(HyperReducedRestShapeSpringsForceField, DataTypes), SOFA_TEMPLATE(HyperReducedFixedWeakConstraint, DataTypes), SOFA_TEMPLATE(RestShapeSpringsForceField, DataTypes), HyperReducedHelper); protected: - HyperReducedRestShapeSpringsForceField(); - + HyperReducedRestShapeSpringsForceField() = default; 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; - - virtual void addDForce(const core::MechanicalParams* mparams, DataVecDeriv& df, const DataVecDeriv& dx) override; - - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* /* matrix */) override; - - 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 : + virtual void init(){ RestShapeSpringsForceField::init(); } + virtual void bwdInit(){ RestShapeSpringsForceField::bwdInit(); } + virtual void reinit(){ RestShapeSpringsForceField::reinit(); } + virtual void draw(const sofa::core::visual::VisualParams* vps){ RestShapeSpringsForceField::draw(vps); } + virtual bool insertInNode(sofa::core::objectmodel::BaseNode* node){ RestShapeSpringsForceField::insertInNode(node); } + virtual bool removeInNode(sofa::core::objectmodel::BaseNode* node){ RestShapeSpringsForceField::removeInNode(node); } + virtual sofa::core::behavior::BaseForceField* toBaseForceField(){return RestShapeSpringsForceField::toBaseForceField();} + virtual const sofa::core::behavior::BaseForceField* toBaseForceField() const {return RestShapeSpringsForceField::toBaseForceField();} - bool useRestMState; /// An external MechanicalState is used as rest reference. }; #if !defined(SOFA_COMPONENT_FORCEFIELD_HYPERREDUCEDRESTSHAPESPRINGSFORCEFIELD_CPP)