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

Add tests to Cosserat. #114

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

Add tests to Cosserat. #114

wants to merge 17 commits into from

Conversation

damienmarchal
Copy link
Member

@damienmarchal damienmarchal commented Jul 12, 2024

The tests are splitted in two set.
The c++ tests are implemented in Cosserat.Core.Tests
The python tests are implemented in Cosserat.Scene.Tests

To add extra test please do:

# coding: utf8

import Sofa
import Sofa.Simulation
import SofaRuntime
import unittest
import numpy

class Test(unittest.TestCase):
    def test_cosserat_geometrical_behavior(self):
        """This test is validating the the scene in tuto_1 loads and reach a given position after a simulation step"""
        scene = Sofa.import_sofa_python_scene("/home/dmarchal/projects/dev/sofa1/plugins/Cosserat/docs/testScene/tuto_1.py")

        # create a root node to store the scene
        root = Sofa.Core.Node("rootNode")

        # fill the root node with the content of the scene
        scene.createScene(root)

        # initialize everything
        Sofa.Simulation.init(root)

        scenarios = [{
                "value" : [[0.0,0.0,0.0]] * 3,
                "result" :  [[-0., -0., -0.,  0.,  0.,  0.,  1.],
                             [10., -0., -0.,  0.,  0.,  0.,  1.],
                             [20., -0., -0.,  0.,  0.,  0.,  1.],
                             [30., -0., -0.,  0.,  0.,  0.,  1.]]
            },
            {
                "value" : [[0.0,0.1,0.0]] * 3,
                "result" :  [[ -0.        ,  -0.        ,  -0.        ,   0.        ,
                                0.        ,   0.        ,   1.        ],
                                [  8.41470985,  -0.        ,  -4.59697694,   0.        ,
                                   0.47942554,   0.        ,   0.87758256],
                                [  9.09297427,  -0.        , -14.16146837,   0.        ,
                                   0.84147098,   0.        ,   0.54030231],
                                [  1.41120008,  -0.        , -19.89992497,   0.        ,
                                    0.99749499,   0.        ,   0.0707372 ]]
            }
        ]
        for scenario in scenarios:
            root.cosseratCoordinate.cosserat_state.position.value = scenario["value"]
            Sofa.Simulation.animate(root, 0.01)
            numpy.testing.assert_array_almost_equal(root.rigid_base.cosserat_in_Sofa_frame_node.FramesMO.position.value, scenario["result"])
``

class Test(unittest.TestCase):
def test_example_scene(self):

scene = Sofa.import_sofa_python_scene("/home/dmarchal/projects/dev/sofa1/plugins/Cosserat/docs/testScene/tuto_1.py")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how to replace the hard coded path... a DataRepository for Cosserat ?

damienmarchal and others added 13 commits July 13, 2024 00:52
It looks like it is a controller... (but in that cas why exposing it to python ?)
Further refactoring should be added.
They are un-needed and bloat the namespace.
It is important to always keep only the neededs includes.
Having un-needed includes:
	- slow down compilation time
	- increase (non linearly) the amount of file to recompile on change
	- make the code appears more complex and entangled that it is actually.
namespace cosserat::controller
{
namespace {
using sofa::component::topology::container::dynamic::PointSetTopologyModifier;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need #include <sofa/component/topology/container/dynamic/PointSetTopologyModifier.h>

@@ -95,7 +95,7 @@ class DiscreteCosseratMapping : public BaseCosseratMapping<TIn1, TIn2, TOut> {

public:
//////////////////////////////////////////////////////////////////////
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't do this any more using typename Inherit1::In1VecCoord;

#include <sofa/helper/ColorMap.h>

#include <boost/math/special_functions/legendre.hpp>
#include <sofa/core/trait/DataTypes.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not compiling. Maybe miss something ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something that was merge 4 days ago: sofa-framework/sofa#4788 so maybe you need a fresher sofa version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants