-
Notifications
You must be signed in to change notification settings - Fork 317
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
Mapped forcefield matrix + minor spelling changes #276
Conversation
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... )
…e deleting the matrix
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.
…ead of a compressed one.
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..
Thank you for your pull request! |
Hi Olivier, thank for your PR. Let's see of it build [ci-build]. |
Hi @olivier-goury , @ChristianDuriez Some tests on our CI are crashing with your PR, following the link |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment
…raintJacobian, and mappingMatrix for MappingJacobian. DELETE: Delete some useless datafields in LCPconstraintSolver.h
Thank you, warnings removed! |
We took care of the comments, would you like to merge this PR or do you see other issues? |
hey everyone, @courtecuisse @JeremieA could you help us guys ? |
Without feedback of yours @courtecuisse and @JeremieA this will be merged tomorrow (7 days since we poked you) |
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. |
Thank you for your comment 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 ? |
…ction buildIdentityBlocksInJacobian in MechanicalObject
We created a new tag SOFA_WITH_EXPERIMENTAL_FEATURES, set to OFF by default, which defines if the function buildIdentityBlocksInJacobian is used. |
For some reason the latest commits have been ignored by the CI. |
[ci-build] |
[ci-build] |
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:
Linked to Project SparseMatrices, Mapping & Mask : general discussion #26
This PR:
Reviewers will merge only if all these checks are true.