Created
May 4, 2020 14:15
-
-
Save jnbrunet/7dfb354fbf2c6e0971674a1a83c29806 to your computer and use it in GitHub Desktop.
Caribou Eigen Sparse Segfault
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Sofa | |
import numpy as np | |
import copy | |
class Beam(Sofa.Core.Controller): | |
def __init__(self, node, *args, **kwargs): | |
Sofa.Core.Controller.__init__(self, *args, **kwargs) | |
self.gridShape = (4, 4, 16, 3) | |
self.createGraph(node) | |
def createGraph(self, rootNode): | |
# /root/mechanical_node/ | |
mechanical_node = rootNode.addChild('mechanical') | |
# Time integration using caribou components | |
self.solver = mechanical_node.addObject( | |
'StaticODESolver', | |
newton_iterations=10, | |
correction_tolerance_threshold=1e-3, | |
residual_tolerance_threshold=1e-3, | |
shoud_diverge_when_residual_is_growing=False, | |
printLog=False | |
) | |
mechanical_node.addObject( | |
'ConjugateGradientSolver', | |
name='CGSolver', | |
preconditioning_method='IncompleteCholesky', | |
maximum_number_of_iterations=2000, | |
residual_tolerance_threshold=1.e-9, | |
printLog=False | |
) | |
## Regular grid topology describing the beam | |
mechanical_node.addObject('RegularGridTopology', | |
nx=self.gridShape[2], ny=self.gridShape[1], nz=self.gridShape[0], name='grid', | |
min='0 0 0', | |
max='3.75 0.75 0.75' | |
) | |
## Hexa topology | |
mechanical_node.addObject('HexahedronSetTopologyContainer', name='hexa_topology', src='@grid') | |
mechanical_node.addObject('HexahedronSetGeometryAlgorithms', template='Vec3d', name='GeomAlgo') | |
mechanical_node.addObject('HexahedronSetTopologyModifier') | |
## Mechanical object | |
self.behavior_state = mechanical_node.addObject( | |
'MechanicalObject', | |
src='@grid', name='mo', showObject=False | |
) | |
self.elastic_law = mechanical_node.addObject( | |
'HexahedronElasticForce', | |
corotated=False, | |
youngModulus=5000, | |
poissonRatio=0.4, | |
topology_container='@hexa_topology', | |
) | |
## Fixed points | |
mechanical_node.addObject('BoxROI',box='0 0 0 0 0.75 0.75',name='fixed_box') | |
mechanical_node.addObject( | |
'FixedConstraint', | |
indices='@fixed_box.indices') | |
# /root/mechanical_node/collision | |
## Collision model for external force application | |
collision_node = mechanical_node.addChild('collision') | |
collision_node.addObject('VisualStyle', name="visu", displayFlags='hideWireframe') | |
collision_node.addObject( | |
'RegularGridTopology', | |
nx=1, ny=self.gridShape[1], nz=self.gridShape[0], | |
name='gridTip', | |
min='3.75 0.0 0.', | |
max='3.75 0.75 0.75' | |
) | |
collision_node.addObject( | |
'MechanicalObject', | |
tags="learnOn", | |
name="Submo", | |
src="@gridTip", | |
showObject=True, showObjectScale=5, showColor=[1, 0, 0, 1] | |
) | |
collision_node.addObject( | |
'ConstantForceField', | |
name='CFF', force='0 -10 0', indices='15', showArrowSize='0.1' | |
) | |
collision_node.addObject('BarycentricMapping') | |
# /root/mechanical_node/visual | |
visual_node = mechanical_node.addChild('visual') | |
visual_node.addObject('OglModel', name="oglModel", src='@../grid', color='white') | |
def createScene(rootNode): | |
rootNode.addObject('AttachBodyButtonSetting', name='mouse', stiffness='1.0') | |
rootNode.addObject('DefaultPipeline', depth='6', verbose='0', draw='0', name='DefaultCollisionPipeline') | |
rootNode.addObject('BruteForceDetection', name='Detection') | |
rootNode.addObject('DiscreteIntersection', name='Intersection') | |
rootNode.addObject('ViewerSetting', name='viewer') | |
rootNode.addObject('BackgroundSetting', name='ViewerBGcolor', color='0.1 0.1 0.1') | |
rootNode.addObject('VisualStyle', displayFlags='showVisualModels showBehaviorModels showForceFields showWireframe') | |
rootNode.addObject(Beam(rootNode)) | |
return rootNode | |
root = Sofa.Core.Node() | |
root.dt = 0.01 | |
root.name = 'root' | |
root.gravity = [0.0, 0.0, 0.0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment