Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Refactor PCS_Example3.py: Remove unused code, fix variable names, and rename file #147

Merged
merged 7 commits into from
Dec 4, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@

import Sofa
from cosserat.cosseratObject import Cosserat
# from cosserat.nonLinearCosserat import NonLinearCosserat as nonCosserat
from cosserat.usefulFunctions import buildEdges, pluginList, BuildCosseratGeometry
from math import sqrt

# @todo ================ Unit: N, m, Kg, Pa ================
from splib3.numerics import Quat

LegendrePolyOrder = 5
# initialStrain = [[0., 0., 0], [0., 0., 0], [0., 0., 0]]
initialStrain = [[0., 0., 0], [0., 0., 0],
[0., 0., 0], [0., 0., 0], [0., 0., 0]]
YM = 4.015e8
Expand Down Expand Up @@ -52,11 +50,10 @@ def onAnimateEndEvent(self, event):
orientation = Quat(
position[3], position[4], position[5], position[6])
# 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]

def onKeypressedEvent(self, event):
key = event['key']
Expand All @@ -72,7 +69,7 @@ def createScene(rootNode):
rootNode.addObject('RequiredPlugin', name='plugins', pluginName=[pluginList])
rootNode.addObject('VisualStyle', displayFlags='showVisualModels showBehaviorModels hideCollisionModels '
'hideBoundingCollisionModels hideForceFields '
'hideInteractionForceFields hideWireframe')
'hideInteractionForceFields hideWireframe showMechanicalMappings')
rootNode.dt.value = 0.02
rootNode.gravity.value = [0., 0., 0.]
rootNode.addObject('BackgroundSetting', color='0 0.168627 0.211765')
Expand All @@ -91,12 +88,12 @@ def createScene(rootNode):
Cosserat(parent=solverNode, cosseratGeometry=nonLinearConfig, useCollisionModel=needCollisionModel,
inertialParams=inertialParams, name="cosserat", radius=Rb, youngModulus=YM))

beamFrame = nonLinearCosserat.cosseratFrame
beamFrame = PCS_Cosserat.cosseratFrame

constForce = beamFrame.addObject('ConstantForceField', name='constForce', showArrowSize=0.02,
indices=nonLinearConfig['nbFramesF'], force=F1)
indices=nonLinearConfig['nbFramesF'], forces=F1)

nonLinearCosserat = solverNode.addObject(
solverNode.addObject(
ForceController(parent=solverNode, cosseratFrames=beamFrame.FramesMO, forceNode=constForce))

# ----------------
Expand Down
Loading