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

Bug in DynamicSparseGridTopologyContainer / Modifier #4796

Open
ScheiklP opened this issue Jun 27, 2024 · 0 comments
Open

Bug in DynamicSparseGridTopologyContainer / Modifier #4796

ScheiklP opened this issue Jun 27, 2024 · 0 comments
Labels
issue: bug (minor) Bug affecting only some users or with no major impact on the framework

Comments

@ScheiklP
Copy link
Contributor

Bonjour,
I am trying to model cutting on a deformable object, but I would like to use a Sparse Grid Topology to avoid meshing etc.
I found the component DynamicSparseGridTopologyContainer which seems to be the right thing, but sadly I get index errors, when I try to remove elements (through shift-right-click interaction in the GUI).
But something seems to happen, as the visual model deforms and also finally crashes, when no points are left.

Error:

[ERROR]   [DynamicSparseGridTopologyModifier(DynamicSparseGridTopologyModifier)] Unable to remove the hexahedra: 130 its index is out of bound.

Video:

dynamic.mp4

Example Scene:

import Sofa
import Sofa.Core
import Sofa.Simulation


PLUGINS = [
    "Sofa.Component.AnimationLoop",  # [FreeMotionAnimationLoop]
    "Sofa.Component.Collision.Detection.Algorithm",  # [BVHNarrowPhase,BruteForceBroadPhase,CollisionPipeline]
    "Sofa.Component.Collision.Detection.Intersection",  # [MinProximityIntersection]
    "Sofa.Component.Collision.Geometry",  # [TriangleCollisionModel]
    "Sofa.Component.Collision.Response.Contact",  # [CollisionResponse]
    "Sofa.Component.Constraint.Lagrangian.Correction",  # [LinearSolverConstraintCorrection]
    "Sofa.Component.Constraint.Lagrangian.Solver",  # [GenericConstraintSolver]
    "Sofa.Component.Constraint.Projective",  # [FixedConstraint]
    "Sofa.Component.IO.Mesh",  # [MeshOBJLoader]
    "Sofa.Component.LinearSolver.Direct",  # [SparseLDLSolver]
    "Sofa.Component.Mapping.Linear",  # [BarycentricMapping]
    "Sofa.Component.Mass",  # [UniformMass]
    "Sofa.Component.ODESolver.Backward",  # [EulerImplicitSolver]
    "Sofa.Component.SolidMechanics.FEM.Elastic",  # [HexahedronFEMForceField]
    "Sofa.Component.StateContainer",  # [MechanicalObject]
    "Sofa.Component.Topology.Container.Constant",  # [MeshTopology]
    "Sofa.Component.Topology.Container.Dynamic",  # [DynamicSparseGridGeometryAlgorithms,DynamicSparseGridTopologyContainer,Dyna
    "Sofa.Component.Topology.Container.Grid",  # [SparseGridTopology]
    "Sofa.Component.Visual",  # [VisualStyle]
    "Sofa.GL.Component.Rendering3D",  # [OglModel]
]


def createScene(root: Sofa.Core.Node):
    plugin_set = set(PLUGINS)
    for plugin in plugin_set:
        root.addObject("RequiredPlugin", name=plugin)

    root.gravity = [0.0, 0.0, -9.81 * 100.0]
    root.dt = 0.01

    root.addObject("FreeMotionAnimationLoop")
    root.addObject(
        "VisualStyle",
        displayFlags=[
            "showVisual",
            "showForceFields",
            "showBehaviorModels",
        ],
    )

    root.addObject("CollisionPipeline", depth=6, verbose=False, draw=False)
    root.addObject("BruteForceBroadPhase")
    root.addObject("BVHNarrowPhase")
    root.addObject("MinProximityIntersection", name="Proximity", alarmDistance=0.5, contactDistance=0.3)
    root.addObject("CollisionResponse", response="FrictionContactConstraint")
    root.addObject("GenericConstraintSolver")

    scene_node = root.addChild("scene")
    helper_topo = scene_node.addObject(
        "SparseGridTopology",
        n=[4, 6, 4],
        fileTopology="mesh/liver.obj",
    )

    liver_node = scene_node.addChild("liver")
    liver_node.addObject("DynamicSparseGridTopologyContainer", src=helper_topo.getLinkPath())
    liver_node.addObject("DynamicSparseGridTopologyModifier")
    liver_node.addObject("DynamicSparseGridGeometryAlgorithms")
    liver_node.addObject("EulerImplicitSolver")
    liver_node.addObject("SparseLDLSolver", template="CompressedRowSparseMatrixMat3x3d")
    liver_node.addObject("MechanicalObject")
    liver_node.addObject("HexahedronFEMForceField")
    liver_node.addObject("UniformMass", totalMass=1.07)
    liver_node.addObject("LinearSolverConstraintCorrection")

    fixed_constraint_indices = list(range(23))
    liver_node.addObject("FixedConstraint", indices=fixed_constraint_indices, drawSize=0.1)

    liver_visual_node = liver_node.addChild("visual")
    liver_visual_node.addObject("MeshOBJLoader", filename="mesh/liver.obj")
    liver_visual_node.addObject("OglModel", src="@MeshOBJLoader", color="1 0 0 1")
    liver_visual_node.addObject("BarycentricMapping")

    liver_collision_node = liver_node.addChild("collision")
    liver_collision_node.addObject("MeshOBJLoader", filename="mesh/liver.obj")
    liver_collision_node.addObject("MeshTopology", src="@MeshOBJLoader")
    liver_collision_node.addObject("MechanicalObject")
    liver_collision_node.addObject("TriangleCollisionModel", group=1)
    liver_collision_node.addObject("BarycentricMapping")

Cheers,
Paul

@ScheiklP ScheiklP added the issue: bug (minor) Bug affecting only some users or with no major impact on the framework label Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug (minor) Bug affecting only some users or with no major impact on the framework
Projects
None yet
Development

No branches or pull requests

1 participant