From 3ac03278d10328ef4a55b6e4ae509460efc5b346 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Fri, 29 Nov 2024 17:30:54 +0100 Subject: [PATCH] Fix PCS and PNLS scenes (#140) --- examples/python3/PCS_Example2.py | 13 ++++++------- examples/python3/PNLS_Example1.py | 11 +++++------ examples/python3/PNLS_Example2.py | 11 +++++------ examples/python3/PNLS_Example3.py | 2 +- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/examples/python3/PCS_Example2.py b/examples/python3/PCS_Example2.py index c6dd3df7..2570242c 100644 --- a/examples/python3/PCS_Example2.py +++ b/examples/python3/PCS_Example2.py @@ -52,11 +52,11 @@ def __init__(self, *args, **kwargs): position = self.frames.position[self.size] # get the last rigid of the cosserat frame orientation = Quat(position[3], position[4], position[5], position[6]) # get the orientation # Get the force direction in order to remain orthogonal to the last section of beam - with self.forceNode.force.writeable() as force: + with self.forceNode.forces.writeable() as force: vec = orientation.rotate([0., self.forceCoeff, 0.]) # print(f' The new vec is : {vec}') for count in range(3): - force[count] = vec[count] + force[0][count] = vec[count] if self.forceCoeff < 13.1e4: self.forceCoeff += 100 else: @@ -88,15 +88,14 @@ def createScene(rootNode): solverNode.addObject('SparseLDLSolver', name='solver', template="CompressedRowSparseMatrixd") needCollisionModel = 0 # use this if the collision model if the beam will interact with another object - PCS_Cosserat = solverNode.addChild( - Cosserat(parent=solverNode, cosseratGeometry=nonLinearConfig, useCollisionModel=needCollisionModel, - inertialParams=inertialParams, name="cosserat", radius=Rb, youngModulus=YM)) + PCS_Cosserat = Cosserat(parent=solverNode, cosseratGeometry=nonLinearConfig, useCollisionModel=needCollisionModel, + inertialParams=inertialParams, name="cosserat", radius=Rb, youngModulus=YM, showObject="1") beamFrame = PCS_Cosserat.cosseratFrame constForce = beamFrame.addObject('ConstantForceField', name='constForce', showArrowSize=0.0, - indices=nonLinearConfig['nbFramesF'], force=F1) + indices=nonLinearConfig['nbFramesF'], forces=F1) - solverNode.addObject(ForceController(parent=solverNode, cosseratFrames=beamFrame.FramesMO, forceNode=constForce)) + solverNode.addObject(ForceController(parent=solverNode, name='forceController', cosseratFrames=beamFrame.FramesMO, forceNode=constForce)) return rootNode diff --git a/examples/python3/PNLS_Example1.py b/examples/python3/PNLS_Example1.py index 016785b3..b2541a11 100644 --- a/examples/python3/PNLS_Example1.py +++ b/examples/python3/PNLS_Example1.py @@ -52,10 +52,10 @@ def __init__(self, *args, **kwargs): def onAnimateEndEvent(self, event): if self.applyForce: - with self.forceNode.force.writeable() as force: + with self.forceNode.forces.writeable() as force: vec = [0., 0., 0., 0., (self.forceCoeff * 1.) / sqrt(2), (self.forceCoeff * 1.) / sqrt(2)] for i, v in enumerate(vec): - force[i] = v + force[0][i] = v # print(f' The new force: {force}') def onKeypressedEvent(self, event): @@ -85,18 +85,17 @@ def createScene(rootNode): solverNode.addObject('SparseLDLSolver', name='solver', template="CompressedRowSparseMatrixd") needCollisionModel = 0 # use this if the collision model if the beam will interact with another object - nonLinearCosserat = solverNode.addChild( - nonCosserat(parent=solverNode, cosseratGeometry=nonLinearConfig, inertialParams=inertialParams, + nonLinearCosserat = nonCosserat(parent=solverNode, cosseratGeometry=nonLinearConfig, inertialParams=inertialParams, useCollisionModel=needCollisionModel, name="cosserat", radius=Rb, youngModulus=YM, legendreControlPoints=initialStrain, poissonRatio=PR,order=LegendrePolyOrder, rayleighStiffness=rayleighStiffness, - activatedMMM=False)) + activatedMMM=False) cosseratNode = nonLinearCosserat.legendreControlPointsNode beamFrame = nonLinearCosserat.cosseratFrame constForce = beamFrame.addObject('ConstantForceField', name='constForce', showArrowSize=1.e-8, - indices=nonLinearConfig['nbFramesF'], force=F1) + indices=nonLinearConfig['nbFramesF'], forces=F1) nonLinearCosserat = solverNode.addObject( ForceController(parent=solverNode, cosseratFrames=beamFrame.FramesMO, forceNode=constForce)) diff --git a/examples/python3/PNLS_Example2.py b/examples/python3/PNLS_Example2.py index edc4cfe2..91d9f0d6 100644 --- a/examples/python3/PNLS_Example2.py +++ b/examples/python3/PNLS_Example2.py @@ -52,11 +52,11 @@ def onAnimateEndEvent(self, event): position = self.frames.position[self.size] # get the last rigid of the cosserat frame orientation = Quat(position[3], position[4], position[5], position[6]) # get the orientation # Get the force direction in order to remain orthogonal to the last section of beam - with self.forceNode.force.writeable() as force: + with self.forceNode.forces.writeable() as force: vec = orientation.rotate([0., self.forceCoeff, 0.]) # print(f' The new vec is : {vec}') for count in range(3): - force[count] = vec[count] + force[0][count] = vec[count] if self.forceCoeff < 13.1e4: self.forceCoeff += 100 else: @@ -87,17 +87,16 @@ def createScene(rootNode): solverNode.addObject('SparseLDLSolver', name='solver', template="CompressedRowSparseMatrixd") needCollisionModel = 0 # use this if the collision model if the beam will interact with another object - nonLinearCosserat = solverNode.addChild( - nonCosserat(parent=solverNode, cosseratGeometry=nonLinearConfig, useCollisionModel=needCollisionModel, + nonLinearCosserat = nonCosserat(parent=solverNode, cosseratGeometry=nonLinearConfig, useCollisionModel=needCollisionModel, name="cosserat", radius=Rb, youngModulus=YM, legendreControlPoints=initialStrain, order=LegendrePolyOrder, inertialParams=inertialParams, - activatedMMM=True)) + activatedMMM=True, showObject="1") cosseratNode = nonLinearCosserat.legendreControlPointsNode beamFrame = nonLinearCosserat.cosseratFrame constForce = beamFrame.addObject('ConstantForceField', name='constForce', showArrowSize=1.e-5, - indices=nonLinearConfig['nbFramesF'], force=F1) + indices=nonLinearConfig['nbFramesF'], forces=F1) nonLinearCosserat = solverNode.addObject( ForceController(parent=solverNode, cosseratFrames=beamFrame.FramesMO, forceNode=constForce)) diff --git a/examples/python3/PNLS_Example3.py b/examples/python3/PNLS_Example3.py index 6493cfe1..2aab3f4d 100644 --- a/examples/python3/PNLS_Example3.py +++ b/examples/python3/PNLS_Example3.py @@ -124,7 +124,7 @@ def createScene(rootNode): cosseratNode = nonLinearCosserat.legendreControlPointsNode constForce = beamFrame.addObject('ConstantForceField', name='constForce', showArrowSize=1.e-9, - indices=nonLinearConfig['nbFramesF'], force=F1) + indices=nonLinearConfig['nbFramesF'], forces=F1) nonLinearCosserat = solverNode.addObject( ForceController(parent=solverNode, cosseratFrames=beamFrame.FramesMO, controller=controlMo))