Do not assemble zero contributions from local to global matrix #543
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With this patch, entries from the local matrix that are zero are ignored and never added to the global matrix. More importantly, it is now allowed to have missing stored entries in the global matrix if the contribution that would have been added there is zero.
A concrete example where this is useful: Consider a two-field problem with unknowns (u, p) and test functions (v, q) where there is no coupling between, for example, p and q. In the global block matrix K = [A B; C D], D will be zero, and there is therefore no need to allocate entries in K corresponding to all couplings between p- and q-dofs. (Note though that currently it is not possible to create such a sparsity pattern because create_sparsity_pattern assumes full coupling between fields.) However, when assembling the local matrix k = [a b; c d] it is much easier to use a dense matrix, and simply initialize d to zero. After this patch it is perfectly fine to assemble the matrix k into K, even if the global entries for d are missing.
Extracted from #539.