Skip to content

Commit

Permalink
Update scenes (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxbilger authored Feb 8, 2023
1 parent ece7319 commit 7784481
Show file tree
Hide file tree
Showing 36 changed files with 791 additions and 773 deletions.
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ sofa_install_pythonscripts(PLUGIN_NAME ${PROJECT_NAME} PYTHONSCRIPTS_SOURCE_DIR

sofa_install_pythonscripts(PLUGIN_NAME ${PROJECT_NAME} PYTHONSCRIPTS_SOURCE_DIR "python3")

find_file(SofaPython3Tools NAMES "SofaPython3/lib/cmake/SofaPython3/SofaPython3Tools.cmake")
if(SofaPython3Tools)
message("-- Found SofaPython3Tools.")
include(${SofaPython3Tools})
else()
# try again with the find_package mechanism
find_package(SofaPython3 QUIET)
endif()
if(SofaPython3Tools OR SofaPython3_FOUND)
message("-- Python3 packages will be installed.")
set(SP3_PYTHON_PACKAGES_DIRECTORY "python3/site-packages")
SP3_add_python_package(
SOURCE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python3/mor
TARGET_DIRECTORY mor
)
SP3_add_python_package(
SOURCE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python3/morlib
TARGET_DIRECTORY morlib
)
endif()

# Move all resources when install: examples, doc and python files
install(FILES "README.md" "LICENSE" DESTINATION .)
Expand Down
148 changes: 74 additions & 74 deletions doc/examples/CaduceusRevisited/reduced_EnrichedCaduceus.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Sofa
from numpy import add,subtract,multiply
try:
from splib.numerics import *
from splib3.numerics import *
except:
raise ImportError("ModelOrderReduction plugin depend on SPLIB"\
+"Please install it : https://github.com/SofaDefrost/STLIB")
Expand Down Expand Up @@ -60,108 +60,108 @@ def Reduced_test(
"""

modelRoot = attachedTo.createChild(name)
modelRoot = attachedTo.addChild(name)

Snake_MOR = modelRoot.createChild('Snake_MOR')
Snake_MOR.createObject('EulerImplicitSolver' , rayleighStiffness = '0.1', rayleighMass = '0.1')
Snake_MOR.createObject('SparseLDLSolver' , name = 'preconditioner')
Snake_MOR.createObject('GenericConstraintCorrection' , solverName = 'preconditioner')
Snake_MOR.createObject('MechanicalObject' , position = [0]*nbrOfModes, template = 'Vec1d')
Snake_MOR.createObject('MechanicalMatrixMapperMOR' , object1 = '@./MechanicalObject', object2 = '@./MechanicalObject', listActiveNodesPath = path + r'/data/listActiveNodes.txt', template = 'Vec1d,Vec1d', usePrecomputedMass = True, timeInvariantMapping2 = True, performECSW = hyperReduction, timeInvariantMapping1 = True, precomputedMassPath = path + r'/data/UniformMass_reduced.txt', nodeToParse = '@./Snake')
Snake_MOR = modelRoot.addChild('Snake_MOR')
Snake_MOR.addObject('EulerImplicitSolver' , rayleighStiffness = '0.1', rayleighMass = '0.1')
Snake_MOR.addObject('SparseLDLSolver' , name = 'preconditioner')
Snake_MOR.addObject('GenericConstraintCorrection' , solverName = 'preconditioner')
Snake_MOR.addObject('MechanicalObject' , position = [0]*nbrOfModes, template = 'Vec1d')
Snake_MOR.addObject('MechanicalMatrixMapperMOR' , object1 = '@./MechanicalObject', object2 = '@./MechanicalObject', listActiveNodesPath = path + r'/data/listActiveNodes.txt', template = 'Vec1d,Vec1d', usePrecomputedMass = True, timeInvariantMapping2 = True, performECSW = hyperReduction, timeInvariantMapping1 = True, precomputedMassPath = path + r'/data/UniformMass_reduced.txt', nodeToParse = '@./Snake')


actuatorDummy = modelRoot.createChild('actuatorDummy')
actuatorDummy.createObject('MechanicalObject' , name = 'actuatorState', template = 'Vec3d')
actuatorDummy = modelRoot.addChild('actuatorDummy')
actuatorDummy.addObject('MechanicalObject' , name = 'actuatorState', template = 'Vec3d')


Snake = Snake_MOR.createChild('Snake')
Snake.createObject('MeshVTKLoader' , scale3d = multiply(scale,[1.0, 1.0, 1.0]), rotation = add(rotation,[-90, 0, 0]), translation = add(translation,[0, 5, 0]), name = 'loader', filename = path + r'/mesh/snake0.vtu')
Snake.createObject('TetrahedronSetTopologyContainer' , src = '@loader')
Snake.createObject('MechanicalObject')
Snake.createObject('UniformMass' , totalMass = '1.0')
Snake.createObject('HyperReducedTetrahedronFEMForceField' , RIDPath = path + r'/data/reducedFF_Snake_0_RID.txt', name = 'reducedFF_Snake_0', weightsPath = path + r'/data/reducedFF_Snake_0_weight.txt', youngModulus = '10000.0', modesPath = path + r'/data/modes.txt', performECSW = hyperReduction, method = 'large', poissonRatio = '0.4', nbModes = nbrOfModes)
Snake.createObject('ModelOrderReductionMapping' , input = '@../MechanicalObject', modesPath = path + r'/data/modes.txt', output = '@./MechanicalObject')
Snake = Snake_MOR.addChild('Snake')
Snake.addObject('MeshVTKLoader' , scale3d = multiply(scale,[1.0, 1.0, 1.0]), rotation = add(rotation,[-90, 0, 0]), translation = add(translation,[0, 5, 0]), name = 'loader', filename = path + r'/mesh/snake0.vtu')
Snake.addObject('TetrahedronSetTopologyContainer' , src = '@loader')
Snake.addObject('MechanicalObject')
Snake.addObject('UniformMass' , totalMass = '1.0')
Snake.addObject('HyperReducedTetrahedronFEMForceField' , RIDPath = path + r'/data/reducedFF_Snake_0_RID.txt', name = 'reducedFF_Snake_0', weightsPath = path + r'/data/reducedFF_Snake_0_weight.txt', youngModulus = '10000.0', modesPath = path + r'/data/modes.txt', performECSW = hyperReduction, method = 'large', poissonRatio = '0.4', nbModes = nbrOfModes)
Snake.addObject('ModelOrderReductionMapping' , input = '@../MechanicalObject', modesPath = path + r'/data/modes.txt', output = '@./MechanicalObject')


collis = Snake.createChild('collis')
collis.createObject('MeshObjLoader' , scale3d = multiply(scale,[1.0, 1.0, 1.0]), translation = add(translation,[0, 5, 0]), rotation = add(rotation,[0.0, 0.0, 0.0]), name = 'loader', filename = path + r'/mesh/meca_snake_900tri.obj')
collis.createObject('Mesh' , src = '@loader', name = 'topo')
collis.createObject('MechanicalObject' , name = 'CollisModel')
collis.createObject('Triangle' , selfCollision = True)
collis.createObject('Line' , selfCollision = True)
collis.createObject('Point' , selfCollision = True)
collis.createObject('BarycentricMapping')
collis = Snake.addChild('collis')
collis.addObject('MeshOBJLoader' , scale3d = multiply(scale,[1.0, 1.0, 1.0]), translation = add(translation,[0, 5, 0]), rotation = add(rotation,[0.0, 0.0, 0.0]), name = 'loader', filename = path + r'/mesh/meca_snake_900tri.obj')
collis.addObject('Mesh' , src = '@loader', name = 'topo')
collis.addObject('MechanicalObject' , name = 'CollisModel')
collis.addObject('TriangleCollisionModel' , selfCollision = True)
collis.addObject('LineCollisionModel' , selfCollision = True)
collis.addObject('PointCollisionModel' , selfCollision = True)
collis.addObject('BarycentricMapping')


VisuBody = Snake.createChild('VisuBody')
VisuBody.createObject('MeshObjLoader' , scale3d = multiply(scale,[1.0, 1.0, 1.0]), translation = add(translation,[0.0, 0.0, 0.0]), rotation = add(rotation,[0.0, 0.0, 0.0]), name = 'loader', filename = path + r'/mesh/snake_body.obj')
VisuBody.createObject('OglModel' , color = [1, 1, 1, 0.6], src = '@loader', translation = [0, 5, 0], texturename = 'textures/snakeColorMap.png', name = 'VisualBody')
VisuBody.createObject('BarycentricMapping')
VisuBody = Snake.addChild('VisuBody')
VisuBody.addObject('MeshOBJLoader' , scale3d = multiply(scale,[1.0, 1.0, 1.0]), translation = add(translation,[0.0, 0.0, 0.0]), rotation = add(rotation,[0.0, 0.0, 0.0]), name = 'loader', filename = path + r'/mesh/snake_body.obj')
VisuBody.addObject('OglModel' , color = [1, 1, 1, 0.6], src = '@loader', translation = [0, 5, 0], texturename = 'textures/snakeColorMap.png', name = 'VisualBody')
VisuBody.addObject('BarycentricMapping')


VisuCornea = Snake.createChild('VisuCornea')
VisuCornea.createObject('MeshObjLoader' , scale3d = multiply(scale,[1.0, 1.0, 1.0]), translation = add(translation,[0.0, 0.0, 0.0]), rotation = add(rotation,[0.0, 0.0, 0.0]), name = 'loader', filename = path + r'/mesh/snake_cornea.obj')
VisuCornea.createObject('OglModel' , src = '@loader', translation = [0, 5, 0], name = 'VisuCornea')
VisuCornea.createObject('BarycentricMapping')
VisuCornea = Snake.addChild('VisuCornea')
VisuCornea.addObject('MeshOBJLoader' , scale3d = multiply(scale,[1.0, 1.0, 1.0]), translation = add(translation,[0.0, 0.0, 0.0]), rotation = add(rotation,[0.0, 0.0, 0.0]), name = 'loader', filename = path + r'/mesh/snake_cornea.obj')
VisuCornea.addObject('OglModel' , src = '@loader', translation = [0, 5, 0], name = 'VisuCornea')
VisuCornea.addObject('BarycentricMapping')


VisualEye = Snake.createChild('VisualEye')
VisualEye.createObject('MeshObjLoader' , scale3d = multiply(scale,[1.0, 1.0, 1.0]), translation = add(translation,[0.0, 0.0, 0.0]), rotation = add(rotation,[0.0, 0.0, 0.0]), name = 'loader', filename = path + r'/mesh/snake_yellowEye.obj')
VisualEye.createObject('OglModel' , src = '@loader', translation = [0, 5, 0], name = 'VisualEye')
VisualEye.createObject('BarycentricMapping')
VisualEye = Snake.addChild('VisualEye')
VisualEye.addObject('MeshOBJLoader' , scale3d = multiply(scale,[1.0, 1.0, 1.0]), translation = add(translation,[0.0, 0.0, 0.0]), rotation = add(rotation,[0.0, 0.0, 0.0]), name = 'loader', filename = path + r'/mesh/snake_yellowEye.obj')
VisualEye.addObject('OglModel' , src = '@loader', translation = [0, 5, 0], name = 'VisualEye')
VisualEye.addObject('BarycentricMapping')

return Snake


# STLIB IMPORT
from stlib.scene import MainHeader
from stlib3.scene import MainHeader
def createScene(rootNode):
surfaceMeshFileName = False

MainHeader(rootNode,plugins=["SofaPython","SoftRobots","ModelOrderReduction"],
MainHeader(rootNode,plugins=["SofaPython3","SoftRobots","ModelOrderReduction"],
dt=0.02,
gravity=[0.0, -981.0, 0.0])
rootNode.VisualStyle.displayFlags="showForceFields"
rootNode.createObject('FreeMotionAnimationLoop')
rootNode.createObject('GenericConstraintSolver', printLog='0', tolerance="1e-6", maxIterations="500")
rootNode.createObject('CollisionPipeline', verbose="0")
rootNode.createObject('BruteForceBroadPhase', name="N2")
rootNode.createObject('BVHNarrowPhase')
rootNode.createObject('CollisionResponse', response="FrictionContact", responseParams="mu=0.7")
rootNode.createObject('LocalMinDistance', name="Proximity", alarmDistance="2.5", contactDistance="0.1", angleCone="0.05")
rootNode.addObject('FreeMotionAnimationLoop')
rootNode.addObject('GenericConstraintSolver', printLog='0', tolerance="1e-6", maxIterations="500")
rootNode.addObject('CollisionPipeline', verbose="0")
rootNode.addObject('BruteForceBroadPhase', name="N2")
rootNode.addObject('BVHNarrowPhase')
rootNode.addObject('CollisionResponse', response="FrictionContactConstraint", responseParams="mu=0.7")
rootNode.addObject('LocalMinDistance', name="Proximity", alarmDistance="2.5", contactDistance="0.1", angleCone="0.05")

Reduced_test(rootNode,
name="Reduced_test",
surfaceMeshFileName=surfaceMeshFileName)
base = rootNode.createChild("base")
base = rootNode.addChild("base")

stick = base.createChild("stick")
stick.createObject('MeshObjLoader',name="loader", filename="mesh/collision_batons.obj")
stick.createObject('Mesh', src='@loader', name='topo')
stick.createObject('MechanicalObject', name='stickCollisModel')
stick.createObject('Line',simulated="false", moving="false")
stick.createObject('Point',simulated="false", moving="false")
stick.createObject('UncoupledConstraintCorrection')
stick = base.addChild("stick")
stick.addObject('MeshOBJLoader',name="loader", filename="mesh/collision_batons.obj")
stick.addObject('Mesh', src='@loader', name='topo')
stick.addObject('MechanicalObject', name='stickCollisModel')
stick.addObject('LineCollisionModel',simulated="false", moving="false")
stick.addObject('PointCollisionModel',simulated="false", moving="false")
stick.addObject('UncoupledConstraintCorrection')

blobs = base.createChild("blobs")
blobs.createObject('MeshObjLoader',name="loader", filename="mesh/collision_boules_V3.obj")
blobs.createObject('Mesh', src='@loader', name='topo')
blobs.createObject('MechanicalObject', name='blobsCollisModel')
blobs.createObject('Triangle',simulated="false", moving="false")
blobs.createObject('Line',simulated="false", moving="false")
blobs.createObject('Point',simulated="false", moving="false")
blobs.createObject('UncoupledConstraintCorrection')

foot = base.createChild("foot")
foot.createObject('MeshObjLoader',name="loader", filename="mesh/collision_pied.obj")
foot.createObject('Mesh', src='@loader', name='topo')
foot.createObject('MechanicalObject', name='footCollisModel')
foot.createObject('Triangle',simulated="false", moving="false")
foot.createObject('Line',simulated="false", moving="false")
foot.createObject('Point',simulated="false", moving="false")
foot.createObject('UncoupledConstraintCorrection')
blobs = base.addChild("blobs")
blobs.addObject('MeshOBJLoader',name="loader", filename="mesh/collision_boules_V3.obj")
blobs.addObject('Mesh', src='@loader', name='topo')
blobs.addObject('MechanicalObject', name='blobsCollisModel')
blobs.addObject('TriangleCollisionModel',simulated="false", moving="false")
blobs.addObject('LineCollisionModel',simulated="false", moving="false")
blobs.addObject('PointCollisionModel',simulated="false", moving="false")
blobs.addObject('UncoupledConstraintCorrection')

foot = base.addChild("foot")
foot.addObject('MeshOBJLoader',name="loader", filename="mesh/collision_pied.obj")
foot.addObject('Mesh', src='@loader', name='topo')
foot.addObject('MechanicalObject', name='footCollisModel')
foot.addObject('TriangleCollisionModel',simulated="false", moving="false")
foot.addObject('LineCollisionModel',simulated="false", moving="false")
foot.addObject('PointCollisionModel',simulated="false", moving="false")
foot.addObject('UncoupledConstraintCorrection')

visu = base.createChild("visu")
visu.createObject('MeshObjLoader', name="SOFA_pod", filename="mesh/SOFA_pod.obj", handleSeams="1" )
visu.createObject('OglModel' , src = '@SOFA_pod', name = 'VisuPOD',color=[1,69.0/255.0,0])
visu = base.addChild("visu")
visu.addObject('MeshOBJLoader', name="SOFA_pod", filename="mesh/SOFA_pod.obj", handleSeams="1" )
visu.addObject('OglModel' , src = '@SOFA_pod', name = 'VisuPOD',color=[1,69.0/255.0,0])

Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def createScene(rootNode):
rootNode.addObject('BackgroundSetting', color='0 0.168627 0.211765')
rootNode.addObject('OglSceneFrame', style="Arrows", alignment="TopRight")
solverNode = rootNode.addChild('solverNode')
solverNode.addObject('EulerImplicit', name='odesolver',firstOrder="false", rayleighStiffness='0.01', rayleighMass='0.01', printLog=False)
solverNode.addObject('EulerImplicitSolver', name='odesolver',firstOrder="false", rayleighStiffness='0.01', rayleighMass='0.01', printLog=False)
solverNode.addObject('SparseLDLSolver', name="preconditioner", template="CompressedRowSparseMatrixMat3x3d")
solverNode.addObject('GenericConstraintCorrection', solverName='preconditioner')
solverNode.addObject('MechanicalMatrixMapperMOR', template='Vec1d,Vec1d', object1='@./reducedModel/alpha', object2='@./reducedModel/alpha', nodeToParse='@./reducedModel/model', performECSW=performECSWBoolMappedMatrix, listActiveNodesPath=listActiveNodesFile,timeInvariantMapping1 = True,timeInvariantMapping2 = True, saveReducedMass=False, usePrecomputedMass=False, precomputedMassPath='ROM_data/quadrupedMass_reduced63modes.txt', fastMatrixProduct=False, printLog=False)
Expand Down Expand Up @@ -303,11 +303,11 @@ def createScene(rootNode):
##########################################
modelVisu = model.addChild('visu')
modelVisu.addObject('MeshSTLLoader', name='loader', filename=pathMesh+"quadriped_collision.stl")
modelVisu.addObject('OglModel', src='@loader', template='ExtVec3f', color='0.7 0.7 0.7 0.6')
modelVisu.addObject('OglModel', src='@loader', template='Vec3d', color='0.7 0.7 0.7 0.6')
modelVisu.addObject('BarycentricMapping')

planeNode = rootNode.addChild('Plane')
planeNode.addObject('MeshObjLoader', name='loader', filename="mesh/floorFlat.obj", triangulate="true")
planeNode.addObject('MeshOBJLoader', name='loader', filename="mesh/floorFlat.obj", triangulate="true")
planeNode.addObject('Mesh', src="@loader")
planeNode.addObject('MechanicalObject', src="@loader", rotation="90 0 0", translation="0 35 -1", scale="15")
planeNode.addObject('TriangleCollisionModel',simulated="0", moving="0",group="1")
Expand Down
24 changes: 12 additions & 12 deletions doc/examples/SOFIA/DemoSofia.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import os

# STLIB IMPORT
from stlib.scene import MainHeader
from stlib.scene import ContactHeader
from stlib.physics.rigid import Floor
from stlib3.scene import MainHeader
from stlib3.scene import ContactHeader
from stlib3.physics.rigid import Floor

# SOFIA IMPORT
from sofia.sofiaLeg import SofiaLeg
Expand All @@ -21,14 +21,14 @@ def createScene(rootNode):
dt=0.01,
gravity=[0, -9810, 0])
rootNode.VisualStyle.displayFlags='showVisualModels'
rootNode.createObject('FreeMotionAnimationLoop');
rootNode.createObject('LCPConstraintSolver', mu=str(1), tolerance="1.0e-15", maxIt="10000");
rootNode.createObject('CollisionPipeline', verbose="0");
rootNode.createObject('BruteForceBroadPhase', name="N2")
rootNode.createObject('BVHNarrowPhase')
rootNode.createObject('CollisionResponse', response="FrictionContact");
rootNode.createObject('LocalMinDistance', name="Proximity", alarmDistance=10, contactDistance=1.5);
rootNode.createObject('SparseLDLSolver' , name = 'preconditioner')
rootNode.addObject('FreeMotionAnimationLoop');
rootNode.addObject('LCPConstraintSolver', mu=str(1), tolerance="1.0e-15", maxIt="10000");
rootNode.addObject('CollisionPipeline', verbose="0");
rootNode.addObject('BruteForceBroadPhase', name="N2")
rootNode.addObject('BVHNarrowPhase')
rootNode.addObject('CollisionResponse', response="FrictionContact");
rootNode.addObject('LocalMinDistance', name="Proximity", alarmDistance=10, contactDistance=1.5);
rootNode.addObject('SparseLDLSolver' , name = 'preconditioner')


Floor(rootNode,
Expand Down Expand Up @@ -64,4 +64,4 @@ def createScene(rootNode):
# rotation=[0, 0.0, 0.0],
# translation=[100, 0.0, 0.0],
# surfaceColor=[0.0, 0.0, 1, 0.5],
# surfaceMeshFileName=surfaceMeshFileName)
# surfaceMeshFileName=surfaceMeshFileName)
Loading

0 comments on commit 7784481

Please sign in to comment.