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

[all] Sofa add mechanical matrix mapper #721

Merged

Conversation

olivier-goury
Copy link
Contributor

@olivier-goury olivier-goury commented Jul 18, 2018

This PR:

The component MechanicalMatrixMapper allows to compute the mapped matrices computed by ForceFields under mappings, which are ignored by the SOFA animation loops.
Typical usage would be:
Node
MechanicalObject (MO) q
MechanicalMatrixMapper (NodeParsed = MappedNode) --> computes J^T.K.J and J^T.M.J
.....MappedNode
.....MappedMechanicalObject (MMO) q_m
.....Mapping (input = ../MO, output = MMO) -> Computes J.q_m
.....ForceField -> Computes stiffness matrix K
.....Mass -> Computes Mass Matrix M

Any comments welcome!
(Work with @VannesteFelix @ChristianDuriez )


This PR:

  • builds with SUCCESS for all platforms on the CI.
  • does not generate new warnings.
  • does not generate new unit test failures.
  • does not generate new scene test failures.
  • does not break API compatibility.
  • is more than 1 week old (or has fast-merge label).

Reviewers will merge only if all these checks are true.

@hugtalbot
Copy link
Contributor

[ci-build][with-scene-tests]

@hugtalbot hugtalbot changed the title Sofa add mechanical matrix mapper [all] Sofa add mechanical matrix mapper Jul 18, 2018
@hugtalbot hugtalbot added enhancement About a possible enhancement pr: status to review To notify reviewers to review this pull-request labels Jul 18, 2018
Copy link
Contributor

@epernod epernod left a comment

Choose a reason for hiding this comment

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

I'm sorry, I'm not an expert in this.
Is this new mapper a way to optimise the computation of the mechanical system or is it a new mechanism that was not possible before?

Copy link
Contributor

@epernod epernod left a comment

Choose a reason for hiding this comment

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

Hi nice one!
As this new component is very technical, could you provide at least one scene example in /examples/Components/animationloop/MechanicalMatrixMapper.scn



template<class DataTypes1, class DataTypes2>
void MechanicalMatrixMapper<DataTypes1, DataTypes2>::addKToMatrix(const MechanicalParams* mparams,
Copy link
Contributor

@epernod epernod Jul 19, 2018

Choose a reason for hiding this comment

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

This one is quite a big process. Do you think it could be possible to add a unit test for this method with known results?

{
sofa::core::behavior::BaseInteractionForceField::init();

if (mstate1.get() == NULL || mstate2.get() == NULL)
Copy link
Contributor

Choose a reason for hiding this comment

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

you are testing it well here. But there are several access to the mstate1 and 2 in the code. How will the scene behave if mstate are not found?
maybe you could use the paremeter: ComponentState::Invalid;

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the remarks, added in commit 451aefe

@@ -0,0 +1,77 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture, version 1.0 RC 1 *
* (c) 2006-2011 MGH, INRIA, USTL, UJF, CNRS *
Copy link
Contributor

Choose a reason for hiding this comment

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

2006-2018 ;-)

Copy link
Contributor

Choose a reason for hiding this comment

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

Done with ac71b0e, thanks for the review!

@@ -0,0 +1,222 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture, version 1.0 RC 1 *
* (c) 2006-2011 MGH, INRIA, USTL, UJF, CNRS *
Copy link
Contributor

Choose a reason for hiding this comment

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

2006-2018 ;-)

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,543 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture, version 1.0 RC 1 *
* (c) 2006-2011 MGH, INRIA, USTL, UJF, CNRS *
Copy link
Contributor

Choose a reason for hiding this comment

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

2006-2018 ;-)

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

@olivier-goury
Copy link
Contributor Author

@epernod Thank you for your comments!
When using a direct solver (e.g. SparseLDLSolver), and when the SOFA scene involves a forcefield under a mapping, this component allows to map the stiffness matrix through this mapping (and also the Mass matrix). At the moment SOFA just ignores that.

@epernod
Copy link
Contributor

epernod commented Jul 22, 2018

ok but shouldn't be the mapping that automatically does that?

@olivier-goury
Copy link
Contributor Author

Hey Erik,
You're right, this component is a current fix for the issue of mapping matrices through mappings, but ideally it would be an operation called automatically by the animation loop and done by the mapping for example. We will look into that in the future.
Olivier

//////////////////////////////////////////// FACTORY //////////////////////////////////////////////
SOFA_DECL_CLASS(MechanicalMatrixMapper)

int MechanicalMatrixMapperClass = core::RegisterObject("Partially rigidify a mechanical object using a rigid mapping.")
Copy link
Contributor

@damienmarchal damienmarchal Jul 25, 2018

Choose a reason for hiding this comment

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

Is this description correct ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it's not!

@guparan guparan added pr: status wip Development in the pull-request is still in progress and removed pr: status to review To notify reviewers to review this pull-request labels Jul 25, 2018
@olivier-goury
Copy link
Contributor Author

Doxygen doc was added to the component

template <class DataTypes>
void MechanicalObject<DataTypes>::renumberConstraintId(const sofa::helper::vector<unsigned>& /*renumbering*/)
{
this->serr << "MechanicalObject<DataTypes>::renumberConstraintId not implemented in the MatrixDeriv constraint API" << this->sendl;
Copy link
Contributor

@damienmarchal damienmarchal Jul 25, 2018

Choose a reason for hiding this comment

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

Please don't use serr/sout anymore...
but more fundamentally... a pure virtual method is ...pure specifically to force the object inheriting from the parent to not forget to implement them. Providing an empty implementation like this one sounds like skipping over the safeguard that was put in place so it compile and let the user handle the problem (which I doubt it can).

Don't we have a better way to handle those cases ?

Copy link
Contributor

Choose a reason for hiding this comment

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

If the override is mandatory, a pure virtual function is the way to go. This compiler-bypassing behavior should not be allowed.

If the override is not mandatory, then non-virtual + msg_warning("You didn't override") seems nice.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with your Guillaume :)

FEMNode= deformablePartNode.createChild('FEMNode')
RigidifiedNode.addChild(FEMNode)

FEMNode.createObject('Mesh',name='meshInput',src="@../../../../meshDivision/beamMesh")
Copy link
Contributor

Choose a reason for hiding this comment

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

You should replace link made by string like "@../../../../meshDivision/beamMesh" with automatically generated link from the target object eg: "@"+meshOfStructure.getPathName()

It is more robust against change of location & naming of the targeted components.

FEMNode.createObject('MechanicalObject', template='Vec3d',name='beamMecha')
FEMNode.createObject('HexahedronFEMForceField', name='HexaFF', src="@meshInput")
FEMNode.createObject('RestShapeSpringsForceField', name='restShapeFF', points='@../../../meshDivision/box_roi_fix.indices', stiffness="10000", angularStiffness="10000")
FEMNode.createObject('UniformMass', totalmass='0.1')
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't use "0.1" to pass constants you can just write totalmass=1.0

SolverNode= rootNode.createChild('SolverNode')
SolverNode.createObject('EulerImplicit',verbose='false')
SolverNode.createObject('SparseLDLSolver', name="ldlsolveur")
#SolverNode.createObject('MechanicalMatrixMapper', template='Vec3d,Rigid', object1='@./deformablePartNode/beamPart1Mech', object2='@./RigidNode/rigid1', nodeToParse='@./deformablePartNode/FEMNode')
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove useless lines :)

@@ -0,0 +1,50 @@
import Sofa
import random
Copy link
Contributor

@damienmarchal damienmarchal Jul 25, 2018

Choose a reason for hiding this comment

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

Is 'random' of any use ?

}
else
{
msg_info(this) << "There is no mappedMass";
Copy link
Contributor

Choose a reason for hiding this comment

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

no this.

@olivier-goury
Copy link
Contributor Author

  • Doxygen doc has been added in the header file
  • Html doc was added in the location of the example in examples/Components/animationLoop

@olivier-goury
Copy link
Contributor Author

Hello,
What is the status for this pull request? Are you OK to merge it?

@guparan
Copy link
Contributor

guparan commented Jul 27, 2018

Hi @olivier-goury,
I see there still are some edit requests from @damienmarchal in the comments.
Do you plan to fix them?

@damienmarchal
Copy link
Contributor

Actually there is no doubt this needs to be edited because it contains files that are not related to the PR.

@olivier-goury
Copy link
Contributor Author

OK, I removed changes unrelated to this PR, so there are no more unfulfilled edit requests!

@damienmarchal
Copy link
Contributor

[ci-build][with-scene-tests]

@olivier-goury olivier-goury added pr: status to review To notify reviewers to review this pull-request and removed pr: status wip Development in the pull-request is still in progress labels Aug 29, 2018
@olivier-goury
Copy link
Contributor Author

Hello, do you have more remarks on this PR?
Could we consider going for the merge?
Thanks

@damienmarchal
Copy link
Contributor

Not for me :)

@guparan guparan added pr: status ready Approved a pull-request, ready to be squashed and removed pr: status to review To notify reviewers to review this pull-request labels Sep 5, 2018
@guparan guparan merged commit 577716d into sofa-framework:master Sep 6, 2018
@olivier-goury olivier-goury deleted the Sofa_addMechanicalMatrixMapper branch September 12, 2018 15:15
@guparan guparan added this to the v18.12 milestone Oct 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement About a possible enhancement pr: status ready Approved a pull-request, ready to be squashed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants