bow-simulation / virtualbow

Software for designing and simulating bows
http://www.virtualbow.org/
GNU General Public License v3.0
23 stars 3 forks source link

Revisit the use of sparse matrices #82

Open stfnp opened 5 years ago

stfnp commented 5 years ago

In GitLab by spfeifer on Nov 29, 2017, 14:13

The tangent stiffness matrix could technically be stored as a sparse matrix. The problem however (and the reason why currently a dense matrix is used) is how to avoid (excessive) memory allocations and/or single entry lookups during the simulation. Contact handling makes this more difficult, because new elements have to be inserted on contact (no constant block-diagonal structure anymore).

Edit

Did some benchmarks with the Eigen library in order to find out if dense or sparse matrices are more efficient for this use case. Based on typical numbers of nodes and elements, dimensions of the mass and stiffness matrices up to 300 seem plausible. Those matrices are also symmetric and positive (semi-)definite. The benchmarks below were done with banded matrices with a bandwidth of 5 to approximate realistic sparsity patterns. The code can be found here: https://github.com/stfnp/virtualbow-eigen-benchmark.

It seems that sparse matrix operations outperform dense matrices already at fairly low dimensions (between 40 and 45, which corresponds to 9-10 limb and string elements in the current bow model). Even enabling multi-threading for the dense operations does not change that. So sparse matrices are probably the way to go, despite the complications they bring.

benchmark-decompositions

benchmark-matrix-vector

benchmark-matrix-matrix

stfnp commented 4 years ago

Maybe after #135