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

Mapped forcefield matrix + minor spelling changes #276

Merged
merged 25 commits into from
Jun 16, 2017

Conversation

olivier-goury
Copy link
Contributor

@olivier-goury olivier-goury commented May 19, 2017

To experiment a new handling of sparse matrices under mappings in our plugin, a few changes are needed in the core of SOFA.
Main changes:


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.

ChristianDuriez and others added 16 commits December 2, 2016 15:37
So that the subsetmultimapping function getJs() returns a compressed row sparse matrix (by default it returns an sparse EIGEN matrix, which is not compatible with csparse solvers, like sparseLDLSolver... )
buildIdentityBlocksInJacobian
This function allows to put identity blocks in a MatrixDeriv of the mechanical state given a list of nodes + the ID of the MatrixDeriv
…MatrixAccessor that does not clear the mappedMatrices list so as not to initialise a new matrix at every timestep. This saves time when fine meshes are used. The new cheapClear function is used in MatrixLinearSolver. This commit may have side effects for some examples.
Change the name of MatrixDerivId for using more meaningful names
holonomicC() [now deprecated] => constraintMatrix()
nonHolonomicC() [that was not used] => delete

new type  mappingMatrix()   is introduced => use in some mapping to map the stiffness..
@sofabot
Copy link
Collaborator

sofabot commented May 19, 2017

Thank you for your pull request!
Someone will soon check it and start the builds.

@damienmarchal
Copy link
Contributor

Hi Olivier,

thank for your PR. Let's see of it build [ci-build].
I let other person to handle this PR as we are in the same team :)

@damienmarchal
Copy link
Contributor

Hi @olivier-goury , @ChristianDuriez

Some tests on our CI are crashing with your PR, following the link
https://www.sofa-framework.org/dash/?branch=pr/mapped_forcefield_matrix
You will find the crashing tests, those are the one that have a negative runtime, in the stackstrace you can see it is related to some Eigen spare matrix operation.

@damienmarchal damienmarchal added enhancement About a possible enhancement pr: status to review To notify reviewers to review this pull-request project : Mapping & Mask labels May 20, 2017
Copy link
Member

@matthieu-nesme matthieu-nesme left a comment

Choose a reason for hiding this comment

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

The visitor building sparse Jacobians is missing, and I still do not really get the point of these partially sparse Jacobians.
But despite the matrix vectors renaming, I do not see anything breaking the API, so it should not create troubles.

@@ -150,8 +151,14 @@ class TStandardVec<V_MATDERIV, vaccess>
public:
typedef TVecId<V_MATDERIV, vaccess> MyVecId;

static MyVecId holonomicC() { return MyVecId(1);}
static MyVecId nonHolonomicC() { return MyVecId(2);}
static MyVecId constraintMatrix() { return MyVecId(1);} // jacobian matrix of constraints
Copy link
Member

Choose a reason for hiding this comment

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

The matrix names are really unclear. Would it be possible to have some doc about it?
'constraintMatrix' seems to be 'constraintJacobian'? Does that mean that only the mstates in the same node as a Constraint would have such a matrix?
Whereas 'mappingMatrix' should be 'sparseJacobian', and every mstates should got one?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes we can rename constraintMatrix by constraintJacobian it is perhaps more clear.
In this case, we could name the second mappingJacobian (to be coherent).

@@ -226,6 +226,9 @@ class SOFA_CORE_API BaseMechanicalState : public virtual BaseState
/// build the jacobian of the constraint in a baseMatrix
virtual void getConstraintJacobian(const ExecParams* params, sofa::defaulttype::BaseMatrix* J,unsigned int & off) = 0;

/// fill the jacobian matrix (of the constraints) with identity blocks on the provided list of nodes(dofs)
Copy link
Member

Choose a reason for hiding this comment

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

For the usage I have in mind, it would be more useful to start building the sparse Jacobians from ForceFields/Constraints. I am not sure of the interest of starting from a full Identity.
Starting from a selection matrix (identity with 0s) corresponding to the dofs where the ForceFields/Constraints are contributing allows to have the as parse as possible Jacobians, possibly null for branches where there is no ForceFields/Constraints.
Note building such a selection matrix is actually managed by BaseForceField::updateForceMask.

Copy link
Contributor

Choose a reason for hiding this comment

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

Here the Identity is sparse and not necessary full (as you have a list of blocks).
It is implemented in the Mechanical State because these Jacobians are stored in the Mechanical State. But this function can be called, of course from ForceFields / Constraints

@@ -75,13 +75,13 @@ using defaulttype::BaseMatrix;
template <class DataTypes, class MassType>
Copy link
Member

Choose a reason for hiding this comment

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

This file is not really related to the PR, is it?

@@ -174,6 +174,11 @@ public :
{
}

~CompressedRowSparseMatrix()
Copy link
Member

Choose a reason for hiding this comment

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

This file is not really related to the PR, is it?

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 right... but It is maybe useful to have a destructor for CompressedRowSparseMatrix that does a clear() before destruction.

@@ -2623,6 +2623,32 @@ void MechanicalObject<DataTypes>::getConstraintJacobian(const core::ExecParams*
}

template <class DataTypes>
void MechanicalObject<DataTypes>::buildIdentityBlocksInJacobian(const sofa::helper::vector<unsigned int>& list_n, core::MatrixDerivId &mID)
Copy link
Member

Choose a reason for hiding this comment

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

To me, it breaks the purpose of mstates to make them build matrices...
To me mstates should only store state vectors, but this idea seems definitively lost.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove Jacobians from Mechanical States and store them in an other component.
But this would be an other modification of SOFA core.

@@ -168,6 +168,8 @@ class SOFA_CONSTRAINT_API LCPConstraintSolver : public ConstraintSolverImpl
Data<double> showCellWidth;
Data<defaulttype::Vector3> showTranslation;
Data<defaulttype::Vector3> showLevelTranslation;
Data< sofa::helper::vector<double> > delta;
Copy link
Member

Choose a reason for hiding this comment

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

are these new Data use somewhere?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for your comment...
My bad, again something that should not be included in the Pull Request

@@ -71,7 +71,12 @@ set(SOURCE_FILES

add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} PUBLIC SofaSimpleFem SofaRigid)

if(USE_COMPRESSED_ROW_SPARSE)
Copy link
Member

Choose a reason for hiding this comment

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

OK to have a new compilation variable 'USE_COMPRESSED_ROW_SPARSE'.
Indeed it is problematic, that we want the same code, with the same API, described with different matrix structure, and I have no elegant proposition to handle that.
But where would be defined USE_COMPRESSED_ROW_SPARSE, you defined it manually in your cmakecache?
To be clearer, would it be possible to simply add
add_definitions("-DUSE_COMPRESSED_ROW_SPARSE") rather than duplicating code.

Copy link
Contributor

Choose a reason for hiding this comment

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

My bad... It was an intermediate code that was useful to get getJs but we no longer use this function
This will be removed from the pull request

@@ -28,6 +28,7 @@
#include <iostream>
#include <SofaBaseMechanics/IdentityMapping.h>

#define USE_COMPRESSED_ROW_SPARSE 1
Copy link
Member

Choose a reason for hiding this comment

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

DEFINITIVELY NOT in the code!

Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment

@olivier-goury olivier-goury changed the title Mapped forcefield matrix Mapped forcefield matrix + minor spelling changes May 24, 2017
@olivier-goury
Copy link
Contributor Author

Thank you, warnings removed!

@olivier-goury
Copy link
Contributor Author

We took care of the comments, would you like to merge this PR or do you see other issues?
Thanks

@hugtalbot hugtalbot assigned courtecuisse and JeremieA and unassigned guparan May 31, 2017
@hugtalbot
Copy link
Contributor

hey everyone,
we discussed it this morning at the dev meeting. But we were not competent for this. That's why we added @courtecuisse and @JeremieA to this PR. The idea is to understand if the PR is breaking or not the constraint API.

@courtecuisse @JeremieA could you help us guys ?
Sorry @olivier-goury and @ChristianDuriez for the delay.

@hugtalbot
Copy link
Contributor

Without feedback of yours @courtecuisse and @JeremieA this will be merged tomorrow (7 days since we poked you)

@matthieu-nesme
Copy link
Member

Please, before merging, I'd like to get the interest of this PR?

Like already said, it does not bring anything but break the API, and polluate BaseMechanicalState with a off-purpose virtual function. So better motivate these modifications before merging.

@ChristianDuriez
Copy link
Contributor

Thank you for your comment
The interest is to be able to map the forcefields through the mapping in a sparse manner for many solvers of SOFA.

I agree that this functionality is not directly available in the API and for now, would be only available in a private plug-in. But this is work in progress and we need more time to have a clean code available.

Why does it break the API ?

@olivier-goury
Copy link
Contributor Author

We created a new tag SOFA_WITH_EXPERIMENTAL_FEATURES, set to OFF by default, which defines if the function buildIdentityBlocksInJacobian is used.
Hopefully, this PR can be merged now?

@guparan
Copy link
Contributor

guparan commented Jun 12, 2017

For some reason the latest commits have been ignored by the CI.
Let's [ci-build] them.

@bcarrez
Copy link
Contributor

bcarrez commented Jun 12, 2017

[ci-build]

@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 Jun 14, 2017
@damienmarchal
Copy link
Contributor

[ci-build]

@bcarrez bcarrez merged commit a096eb8 into sofa-framework:master Jun 16, 2017
@guparan guparan added this to the v17.06 milestone Jun 29, 2017
@damienmarchal damienmarchal deleted the mapped_forcefield_matrix branch July 5, 2017 21:21
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.

10 participants