Skip to content

Commit

Permalink
update python prefabs
Browse files Browse the repository at this point in the history
  • Loading branch information
adagolodjo committed Aug 30, 2024
1 parent dd6da7d commit 37b54a7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
8 changes: 5 additions & 3 deletions examples/python3/cosserat/CosseratBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def _addRigidBaseNode(self):
template="Rigid3d",
name="RigidBaseMO",
showObjectScale=0.2,
position=positions
position=positions,
translation=self.translation,
rotation=self.rotation
)
rigidBaseNodeMo.showObject.setParent(self.showObject)

Expand Down Expand Up @@ -226,8 +228,8 @@ def _addCosseratFrame(self, framesF, curv_abs_inputS, curv_abs_outputF):
template="Rigid3d",
name="FramesMO",
position=framesF,
showIndices=self.params.beamGeoParams.showFramesObject,
showObject=self.params.beamGeoParams.showFramesObject,
showIndices=self.params.beamGeoParams.show_frames_indices,
showObject=self.params.beamGeoParams.show_frames_object,
showObjectScale=1.8, # Todo: remove this hard code
)

Expand Down
8 changes: 6 additions & 2 deletions examples/python3/useful/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def calculate_frame_parameters(beamGeoParams):
return frames_f, curv_abs_output_f, cable_position_f


def generate_edge_list(cable3DPos: List[List[float]]) -> List[int]:
def generate_edge_list(cable3DPos: List[List[float]]) -> list[list[int]]:
"""
Generate an edge list required in the EdgeSetTopologyContainer component.
Expand All @@ -78,7 +78,11 @@ def generate_edge_list(cable3DPos: List[List[float]]) -> List[int]:
List[int]: A list of indices forming edges in the EdgeSetTopologyContainer.
"""
number_of_points = len(cable3DPos)
return [i for i in range(number_of_points - 1) for _ in range(2)]
edges = []
for i in range(number_of_points - 1):
edges.append([i,i+1])
return edges



class CosseratGeometry:
Expand Down
24 changes: 15 additions & 9 deletions examples/python3/useful/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import os


def addHeader(parentNode, multithreading=False, inverse=False, isConstrained=False, isContact=False):
def addHeader(parentNode, multithreading=False, inverse=False, isConstrained=False, isContact=False, params=None):
"""
Adds to rootNode the default headers for a simulation with contact. Also adds and returns three nodes:
- Settings
Expand Down Expand Up @@ -68,7 +68,7 @@ def addHeader(parentNode, multithreading=False, inverse=False, isConstrained=Fal

parentNode.addObject('VisualStyle', displayFlags='showVisualModels showBehaviorModels showCollisionModels '
'hideBoundingCollisionModels hideForceFields '
'hideInteractionForceFields hideWireframe showMechanicalMappings')
'showInteractionForceFields hideWireframe showMechanicalMappings')
if isConstrained:
parentNode.addObject('FreeMotionAnimationLoop', parallelCollisionDetectionAndFreeMotion=multithreading,
parallelODESolving=multithreading)
Expand All @@ -78,20 +78,26 @@ def addHeader(parentNode, multithreading=False, inverse=False, isConstrained=Fal
multithreading=multithreading, epsilon=1)
else:
parentNode.addObject('GenericConstraintSolver', name='ConstraintSolver', tolerance=1e-8, maxIterations=100,
multithreading=multithreading)
multithreading=multithreading, printLog=1)

if isContact:
contactHeader(parentNode)
contactHeader(parentNode, _contact_params=params.contactParams)


# components needed for contact modeling
def contactHeader(parentNode):
def contactHeader(parentNode, _contact_params=None):
parentNode.addObject('CollisionPipeline')
parentNode.addObject("DefaultVisualManagerLoop")
parentNode.addObject('RuleBasedContactManager', responseParams='mu=0.8', response='FrictionContactConstraint')
parentNode.addObject('BruteForceBroadPhase')
parentNode.addObject('BVHNarrowPhase')
parentNode.addObject('LocalMinDistance', alarmDistance=0.05, contactDistance=0.01)
if not _contact_params == None:
parentNode.addObject('RuleBasedContactManager', responseParams=_contact_params.responseParams,
response='FrictionContactConstraint')
parentNode.addObject('LocalMinDistance', alarmDistance=_contact_params.alarmDistance,
contactDistance=_contact_params.contactDistance)
else :
parentNode.addObject('RuleBasedContactManager', responseParams='mu=0.1', response='FrictionContactConstraint')
parentNode.addObject('LocalMinDistance', alarmDistance=0.05, contactDistance=0.01)


def addVisual(node):
Expand All @@ -105,7 +111,7 @@ def addVisual(node):
"""
node.addObject('VisualStyle', displayFlags='showVisualModels showBehaviorModels hideCollisionModels '
'hideBoundingCollisionModels hideForceFields '
'hideInteractionForceFields hideWireframe showMechanicalMappings')
'showInteractionForceFields hideWireframe showMechanicalMappings')
return node


Expand Down Expand Up @@ -134,7 +140,7 @@ def addSolverNode(node, name='solverNode', template='CompressedRowSparseMatrixd'
if iterative:
solverNode.addObject('CGLinearSolver', name='Solver', template=template)
else:
solverNode.addObject('SparseLDLSolver', name='Solver', template=template)
solverNode.addObject('SparseLDLSolver', name='Solver', template=template, printLog=True)
if isConstrained:
solverNode.addObject('GenericConstraintCorrection', linearSolver=solverNode.Solver.getLinkPath())

Expand Down
5 changes: 3 additions & 2 deletions examples/python3/useful/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class BeamGeometryParameters:
) # The beam rigid base position as a list [x, y, z]

"""Parameters for the visualisation of the beam"""
showFramesObject: int = 1
show_frames_object: bool = True
show_frames_indices: bool = False
showRigidBaseObject: int = 1


Expand Down Expand Up @@ -71,7 +72,7 @@ class VisualParameters:
class ContactParameters:
"""Contact parameters"""

responseParams: str = "mu=0.8"
responseParams: str = "mu=0.0"
response: str = "FrictionContactConstraint"
alarmDistance: float = 0.05
contactDistance: float = 0.01
Expand Down

0 comments on commit 37b54a7

Please sign in to comment.