[LinearSystem] MatrixProjectionMethod: Fix out-of-bounds matrix writes - #6256
[LinearSystem] MatrixProjectionMethod: Fix out-of-bounds matrix writes#6256fredroy wants to merge 1 commit into
Conversation
e482fad to
2b0c0df
Compare
|
for windows.... |
|
[ci-depends-on] detected during build #4. To unlock the merge button, you must
|
|
Strongly related to #6222 |
alxbilger
left a comment
There was a problem hiding this comment.
I am afraid Claude is wrong!
Consider a spring that has 2 input mapped states resulting into 2 mapping jacobian matrices:
I suggest to close this PR.
|
His/Its answer 👀: Thanks for pushing back on this - the requirement you state is right: all four coupling terms J1^T K J1, J1^T K J2, J2^T K J1, J2^T K J2 must end up in the global matrix. Where I think we differ is on where those four terms come from. They do not come from expanding one K over the union of both ancestor sets. They come from four separate mapped matrices, created upstream in inline auto generatePairs(const vector<BaseMechanicalState*>& mstates) A spring on states {M1, M2} therefore gets four mapped matrices K11, K12, K21, K22, each with its own I built exactly your scenario to check - a spring between two mapped states with different parents, global matrix P1(3) + P2(3) = 6: ... same, with M2 ...With the PR, logging every block handed to K=(M1,M1) a=P1 b=P1 J0=1 J1=1 pos=(0,0) block=3x3 nnz=9 That is precisely J1^T K J1, J1^T K J2, J2^T K J1, J2^T K J2 - all four terms, at the four expected offsets, each with both jacobians present. On the same scene before the PR, ten blocks are produced. The interesting ones: K=(M1,M2) a=P1 b=P1 J0=1 J1=0 pos=(0,0) <- spurious J0=0 / J1=0 means On the case where a single state is mapped from two parents (inputs1 == inputs2 == {P1,P2}), union and cartesian product are identical: 2x2 = 4 pairs either way. Measured on
So nothing with a genuine two-jacobian mapping changes. The PR only affects calls where the row state and the column state have different ancestor sets. The structural reason the union cannot be right: J[0] has to be a jacobian of the row state (|mstatePair[0]| x |a|) and J[1] of the column state. Drawing One case would change my mind: if you know a mapping configuration where a single K legitimately needs a jacobian from the other state's ancestor set. If so, |
MatrixProjectionMethod::addMappedMatrixToGlobalMatrixEigeniterated over the cartesian product of the union of both mechanical states' top-most ancestors, instead of inputs1 x inputs2.For the resulting spurious pairs no Jacobian exists, and computeProjection silently falls back to an unprojected block whose dimensions belong to the mapped state, written at the global offsets of an unrelated state.
[with-all-tests]
[ci-depends-on https://github.com/sofa-framework/Regression/pull/126]
By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).
Reviewers will merge this pull-request only if