Repository navigation
Conversation
analyze_linear assembles the stiffness matrix once, but each load combination still called spsolve, which factorizes K11 again. With the sparse solver, K11 is now LU-factorized once (scipy.sparse.linalg.splu, in the new Analysis._factorize_K11) and the factorization is applied to the right-hand side of each combination. _solve_unknown_disp takes the optional solver and keeps the residual stability check unchanged. If splu cannot factorize K11 (exactly singular), _factorize_K11 returns None and the previous per-combination spsolve path runs, so unstable models are reported as before. The dense path is unchanged. Adds Testing/test_factorize_once.py: same results as the per-combination spsolve path and as the dense solver, one factorization for three combinations, and an unstable model that still raises. Part of JWock82#360 (item 2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BZww7wTphWeFLC22L7YkLE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Part of #360 (item 2). Follows #361.
analyze_linear()assembles the stiffness matrix only once, but each load combination still calledspsolve, which factorizes K11 again. With the sparse solver, K11 is now LU-factorized once and the factorization is applied to the right-hand side of each combination (a forward and a back substitution).Changes
Analysis._factorize_K11(K11)(new): factorizes K11 withscipy.sparse.linalg.spluand returns the factorization'ssolve. Ifsplucannot factorize the matrix (it raisesRuntimeErrorwhen K11 is exactly singular), it returnsNone.Analysis._solve_unknown_disp(...): new optionalsolverargument. When given (sparse case only), it is used instead ofspsolve. The residual/finiteness stability check after the solve is unchanged.FEModel3D.analyze_linear(): calls_factorize_K11once before the load-combination loop and passes the result to_solve_unknown_disp. WithNone(exactly singular matrix, dense solver, or no unknown displacements) the previous code path runs, so unstable models are reported as before.analyze(),analyze_PDelta()and the dense path are not changed.Tests
Testing/test_factorize_once.py(new): a quad wall with three load combinations gives the same displacements as the previous per-combinationspsolvepath (rel. 1e-9) and as the dense solver; K11 is factorized only once for the three combinations; a mechanism (internal hinge without support) still raises.test_beam_rotation,test_circular_hopper) and the 4 collection errors (vtk) are missing optional plotting packages in my environment and fail the same way without this change.ruff checkpasses.Benchmark (cylindrical wall from #360: R = 2.10 m, t = 0.20 m, H = 6 m, 10 cm mesh, 7,920 nodes, 7,788 quads,
analyze_linear(sparse=True))spsolve(current main)Each factorization of this K11 takes about 9 s, so every additional combination saves about that much. The largest displacement difference between the two runs is 4.1e-17 m on a maximum of 4.6e-5 m (relative 9e-13, round-off).
AI disclosure
The change, the test and the benchmark were prepared with the help of Claude (Anthropic). I have reviewed every changed line and checked the results against the previous code path and the dense solver.