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

Inertia matrice in Rigids is not taken correctly into account #4936

Open
bakpaul opened this issue Aug 22, 2024 · 0 comments
Open

Inertia matrice in Rigids is not taken correctly into account #4936

bakpaul opened this issue Aug 22, 2024 · 0 comments
Labels
issue: bug (major) Critical bug affecting everyone: not working, performances or accuracy degraded

Comments

@bakpaul
Copy link
Contributor

bakpaul commented Aug 22, 2024

This PR #4935 adds a unit test showing that the inertia matrix in rigids is not working properly. After rotation of the rigid, the inertia matrix is not rotated accordingly.

You can try a 'hand-on' example with the following :

#Required import for python
import Sofa
import SofaRuntime
from Sofa import SofaLinearSolver
import numpy as np

# Function called when the scene graph is being created
def createScene(root):

    root.gravity=[0,0,0]

    root.addObject('VisualStyle', displayFlags="showBehaviorModels showForceFields")

    root.addObject("RequiredPlugin", pluginName=['Sofa.Component.Mass',
                                                    'Sofa.Component.StateContainer',
                                                    'Sofa.Component.Topology.Container.Grid',
                                                    'Sofa.Component.Visual'
                                                    ])

    root.addObject('DefaultAnimationLoop')
    root.addObject('DefaultVisualManagerLoop')

    root.addObject('RequiredPlugin', name='Sofa.Component.ODESolver.Backward')
    root.addObject('RequiredPlugin', name='Sofa.Component.LinearSolver.Direct')
    root.addObject('RequiredPlugin', name='Sofa.Component.Engine.Select')
    root.addObject('RequiredPlugin', name='Sofa.Component.Constraint.Projective')
    root.addObject('RequiredPlugin', name='Sofa.Component.SolidMechanics.FEM.Elastic')

    root.addObject(RotatorController('RotatorController', name='matrixAccessor', root=root))


    totalMass = 300
    x_side = 0.15
    y_side = 0.15
    z_side = 0.7
    volume = x_side*y_side*z_side
    inertiaMatrix = [(y_side**2 + z_side**2)/12, 0.0, 0.0, 0.0, (x_side**2 + z_side**2)/12, 0.0, 0.0, 0.0, (x_side**2 + y_side**2)/12]

    print([totalMass, volume, inertiaMatrix[:]])

    root.addObject('EulerImplicitSolver', rayleighStiffness="0.0", rayleighMass="0.0")
    root.addObject('SparseLDLSolver', applyPermutation="false", template="CompressedRowSparseMatrixd")


    aligned = root.addChild("Aligned")


    aligned.addObject('MechanicalObject', template='Rigid3', position=[0, 0, 0, 0, 0, 0, 1], showObject=True,
                                showObjectScale=0.1)
    aligned.addObject('UniformMass', name="mass", vertexMass=[totalMass, volume, inertiaMatrix[:]])
    aligned.addObject('ConstantForceField', name='ConstantForceField', forces=[0, 0, 0, 0, 0, 0])

    rotated = root.addChild("Rotated")

    rotated.addObject('MechanicalObject', name="MO", template='Rigid3', position=[1, 0, 0, 0,0,0,1], showObject=True,
                                showObjectScale=0.1)
    rotated.addObject('UniformMass', name="mass", vertexMass=[totalMass, volume, inertiaMatrix[:]])
    rotated.addObject('ConstantForceField',name='ConstantForceField', forces=[0, 0, 0, 0, 0, 0])

    return root


class RotatorController(Sofa.Core.Controller):
    def __init__(self, *args, **kwargs):
        Sofa.Core.Controller.__init__(self, *args, **kwargs)
        self.root = kwargs["root"]
        self.step = 0

    def onAnimateEndEvent(self, event):
        self.step += 1
        if(self.step == 2):
            self.root.Aligned.ConstantForceField.forces = [[0, 0, 0, 0, 0, 1]]
            self.root.Rotated.ConstantForceField.forces = [[0, 0, 0, 1, 0, 0]]
            self.root.Rotated.MO.position = np.array([[1, 0, 0, 0.707106781,0,0.707106781,0]])
@bakpaul bakpaul added issue: bug (minor) Bug affecting only some users or with no major impact on the framework issue: bug (major) Critical bug affecting everyone: not working, performances or accuracy degraded and removed issue: bug (minor) Bug affecting only some users or with no major impact on the framework labels Aug 22, 2024
@bakpaul bakpaul changed the title Inertia matrices in Rigids is not taken correctly into acocunt Inertia matrices in Rigids is not taken correctly into account Aug 23, 2024
@bakpaul bakpaul changed the title Inertia matrices in Rigids is not taken correctly into account Inertia matrice in Rigids is not taken correctly into account Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug (major) Critical bug affecting everyone: not working, performances or accuracy degraded
Projects
None yet
Development

No branches or pull requests

1 participant