Skip to content

Commit

Permalink
Fix PCS and PNLS scenes (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxbilger authored Nov 29, 2024
1 parent b102dd9 commit 3ac0327
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
13 changes: 6 additions & 7 deletions examples/python3/PCS_Example2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
11 changes: 5 additions & 6 deletions examples/python3/PNLS_Example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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))
Expand Down
11 changes: 5 additions & 6 deletions examples/python3/PNLS_Example2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion examples/python3/PNLS_Example3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 3ac0327

Please sign in to comment.