structsolve 0.11.0__tar.gz → 0.12.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. {structsolve-0.11.0/structsolve.egg-info → structsolve-0.12.0}/PKG-INFO +5 -2
  2. {structsolve-0.11.0 → structsolve-0.12.0}/README.md +4 -1
  3. {structsolve-0.11.0 → structsolve-0.12.0}/pyproject.toml +1 -1
  4. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve/analysis.py +16 -1
  5. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve/arc_length.py +2 -0
  6. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve/callbacks.py +24 -0
  7. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve/newton_raphson.py +1 -0
  8. {structsolve-0.11.0 → structsolve-0.12.0/structsolve.egg-info}/PKG-INFO +5 -2
  9. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve.egg-info/SOURCES.txt +1 -0
  10. structsolve-0.12.0/tests/test_on_converged.py +109 -0
  11. {structsolve-0.11.0 → structsolve-0.12.0}/LICENSE +0 -0
  12. {structsolve-0.11.0 → structsolve-0.12.0}/setup.cfg +0 -0
  13. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve/__init__.py +0 -0
  14. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve/arc_length_crisfield.py +0 -0
  15. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve/arc_length_riks.py +0 -0
  16. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve/arpackutils.py +0 -0
  17. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve/convergence.py +0 -0
  18. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve/displacement_control.py +0 -0
  19. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve/freq.py +0 -0
  20. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve/generalized_displacement_control.py +0 -0
  21. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve/linear_buckling.py +0 -0
  22. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve/logger.py +0 -0
  23. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve/pardiso.py +0 -0
  24. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve/sparseutils.py +0 -0
  25. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve/static.py +0 -0
  26. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve/stopping.py +0 -0
  27. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve.egg-info/dependency_links.txt +0 -0
  28. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve.egg-info/requires.txt +0 -0
  29. {structsolve-0.11.0 → structsolve-0.12.0}/structsolve.egg-info/top_level.txt +0 -0
  30. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_analysis.py +0 -0
  31. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_arc_length.py +0 -0
  32. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_arc_length_fung_kaplan.py +0 -0
  33. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_arc_length_robustness.py +0 -0
  34. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_arc_length_weights.py +0 -0
  35. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_arpackutils.py +0 -0
  36. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_branch_switching.py +0 -0
  37. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_constraint_values.py +0 -0
  38. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_constraint_values_load_factor.py +0 -0
  39. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_constraints.py +0 -0
  40. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_displacement_control.py +0 -0
  41. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_eigen_pardiso.py +0 -0
  42. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_factorization_cache.py +0 -0
  43. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_follower_freq_static.py +0 -0
  44. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_follower_loads.py +0 -0
  45. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_freq.py +0 -0
  46. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_generalized_displacement_control.py +0 -0
  47. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_inertia.py +0 -0
  48. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_inertia_unsymmetric.py +0 -0
  49. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_linear_buckling.py +0 -0
  50. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_linear_buckling_unsymmetric.py +0 -0
  51. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_load_factor_dependent_load.py +0 -0
  52. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_newton_raphson.py +0 -0
  53. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_pardiso.py +0 -0
  54. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_restart.py +0 -0
  55. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_reuse.py +0 -0
  56. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_simo1990_cylinder.py +0 -0
  57. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_sparse_first.py +0 -0
  58. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_sparseutils.py +0 -0
  59. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_static.py +0 -0
  60. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_static_deflection.py +0 -0
  61. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_stopping.py +0 -0
  62. {structsolve-0.11.0 → structsolve-0.12.0}/tests/test_warnings_registry.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: structsolve
3
- Version: 0.11.0
3
+ Version: 0.12.0
4
4
  Summary: Structural analysis solvers
5
5
  Author-email: "Saullo G. P. Castro" <castrosaullo@gmail.com>
6
6
  License-Expression: BSD-3-Clause
@@ -82,7 +82,7 @@ collected after each call, so that the WebAssembly heap is not exhausted.
82
82
  Citing this library
83
83
  ===================
84
84
 
85
- Saullo G. P. Castro (2026). Structural analysis solvers tailored for semi-analytical models (Version 0.11.0). Zenodo. DOI: https://doi.org/10.5281/zenodo.2581212.
85
+ Saullo G. P. Castro (2026). Structural analysis solvers tailored for semi-analytical models (Version 0.12.0). Zenodo. DOI: https://doi.org/10.5281/zenodo.2581212.
86
86
 
87
87
 
88
88
  Documentation
@@ -97,6 +97,9 @@ History
97
97
 
98
98
  See [CHANGELOG.md](CHANGELOG.md) for the details of each version.
99
99
 
100
+ * version 0.12.0 (2026-11-23)
101
+ - `Analysis.on_converged`: a callable called once after every converged increment of the non-linear analyses, never for a rejected or cut increment, to update the internal variables of path-dependent models, e.g. the damage of a cohesive zone
102
+
100
103
  * version 0.11.0 (2026-11-13)
101
104
  - `freq` with the dense solvers (`sparse_solver=False`) solves the shifted inverse problem, accurate for the lowest natural frequencies of stiff models, e.g. with penalty springs, and warns when one of the lowest eigenpairs fails the residual check
102
105
  - `freq` accepts the eigenpairs of the sparse solvers whose residual is at the round-off when the inertia of `K - s M` confirms the eigenvalue, instead of falling back to the dense solver or raising an error
@@ -45,7 +45,7 @@ collected after each call, so that the WebAssembly heap is not exhausted.
45
45
  Citing this library
46
46
  ===================
47
47
 
48
- Saullo G. P. Castro (2026). Structural analysis solvers tailored for semi-analytical models (Version 0.11.0). Zenodo. DOI: https://doi.org/10.5281/zenodo.2581212.
48
+ Saullo G. P. Castro (2026). Structural analysis solvers tailored for semi-analytical models (Version 0.12.0). Zenodo. DOI: https://doi.org/10.5281/zenodo.2581212.
49
49
 
50
50
 
51
51
  Documentation
@@ -60,6 +60,9 @@ History
60
60
 
61
61
  See [CHANGELOG.md](CHANGELOG.md) for the details of each version.
62
62
 
63
+ * version 0.12.0 (2026-11-23)
64
+ - `Analysis.on_converged`: a callable called once after every converged increment of the non-linear analyses, never for a rejected or cut increment, to update the internal variables of path-dependent models, e.g. the damage of a cohesive zone
65
+
63
66
  * version 0.11.0 (2026-11-13)
64
67
  - `freq` with the dense solvers (`sparse_solver=False`) solves the shifted inverse problem, accurate for the lowest natural frequencies of stiff models, e.g. with penalty springs, and warns when one of the lowest eigenpairs fails the residual check
65
68
  - `freq` accepts the eigenpairs of the sparse solvers whose residual is at the round-off when the inertia of `K - s M` confirms the eigenvalue, instead of falling back to the dense solver or raising an error
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "structsolve"
7
- version = "0.11.0"
7
+ version = "0.12.0"
8
8
  description = "Structural analysis solvers"
9
9
  readme = "README.md"
10
10
  license = "BSD-3-Clause"
@@ -182,6 +182,20 @@ class Analysis(object):
182
182
  increments beyond the first limit point or
183
183
  a displacement measure, see
184
184
  :mod:`.stopping`. Default is ``None``
185
+ ``on_converged`` ``callable``, ``on_converged(an)`` is
186
+ called once after every converged
187
+ increment of the non-linear analyses, when
188
+ ``an.cs[-1]`` and ``an.increments[-1]``
189
+ hold the new state, before
190
+ ``stop_criterion`` and before the next
191
+ increment starts, and never for an
192
+ increment that is rejected or cut, e.g. to
193
+ update the internal variables of a
194
+ path-dependent material, such as the
195
+ damage of a cohesive zone, which must only
196
+ change with converged states, see
197
+ :func:`.callbacks.converged`. Default is
198
+ ``None``
185
199
  ``final_load_factor`` ``float``, the load factor at which the
186
200
  non-linear analyses finish, exactly, or,
187
201
  for the arc-length and displacement control
@@ -399,7 +413,7 @@ class Analysis(object):
399
413
  'early_divergence', 'arc_length_weights', 'control_vector',
400
414
  'control_scale', 'linear_solver', 'inertia',
401
415
  'constraints', 'constraint_values', 'stop_criterion',
402
- 'final_load_factor',
416
+ 'on_converged', 'final_load_factor',
403
417
  'branch_switching', 'max_inertia_jump', 'inertia_num_eigvals',
404
418
  'restart_state', 'path_state', 'branch_points',
405
419
  'num_negative_eigvals', 'det_signs', 'num_perturbed_pivots',
@@ -428,6 +442,7 @@ class Analysis(object):
428
442
  self.constraints = None
429
443
  self.constraint_values = None
430
444
  self.stop_criterion = None
445
+ self.on_converged = None
431
446
  self.final_load_factor = 1.
432
447
  self.branch_switching = 0
433
448
  self.max_inertia_jump = None
@@ -1152,6 +1152,7 @@ def _solver_arc_length(an, method, silent=False):
1152
1152
  silent=silent)
1153
1153
  an.cs.append((c + dc1).copy())
1154
1154
  an.increments.append(target)
1155
+ callbacks.converged(an)
1155
1156
  if an.inertia:
1156
1157
  _converged_state(an, c + dc1, target, silent=silent)
1157
1158
  finished = True
@@ -1168,6 +1169,7 @@ def _solver_arc_length(an, method, silent=False):
1168
1169
  level=2, silent=silent)
1169
1170
  an.cs.append(c.copy()) #NOTE copy required
1170
1171
  an.increments.append(lbd)
1172
+ callbacks.converged(an)
1171
1173
  solve_kT_conv = None
1172
1174
  after_switch = switch is not None
1173
1175
  if after_switch:
@@ -81,6 +81,30 @@ solvers are scaled with the linear solution of `-\partial \boldsymbol{R}/\partia
81
81
  import inspect
82
82
 
83
83
 
84
+ def converged(an):
85
+ r"""Calls ``an.on_converged(an)``, if given, after a converged increment
86
+
87
+ Called by the non-linear solvers right after the new state is appended to
88
+ ``an.cs`` and ``an.increments``, once per converged increment, before
89
+ ``an.stop_criterion`` and before the next increment, and never for an
90
+ increment that is rejected, e.g. by the checks of the inertia or of the
91
+ branch switching, or cut.
92
+
93
+ Notes
94
+ -----
95
+ The callables of :class:`.Analysis` must be functions of the
96
+ configuration and of the load factor alone during the iterations of an
97
+ increment. A path-dependent model, e.g. a cohesive zone whose damage may
98
+ not decrease, evaluates them with its internal variables at the last
99
+ converged state, and updates these variables only with the states that
100
+ converged: ``on_converged`` is where this update belongs, with the new
101
+ state ``an.cs[-1]`` at the load factor ``an.increments[-1]``.
102
+
103
+ """
104
+ if getattr(an, 'on_converged', None) is not None:
105
+ an.on_converged(an)
106
+
107
+
84
108
  def accepts_kwarg(func, name):
85
109
  """Tell whether ``func`` declares the keyword argument ``name``
86
110
 
@@ -1069,6 +1069,7 @@ def _solver_NR(an, silent=False, initialInc=None):
1069
1069
  total_last = total
1070
1070
  an.cs.append(c.copy()) #NOTE copy required
1071
1071
  an.increments.append(total)
1072
+ callbacks.converged(an)
1072
1073
  if an.inertia:
1073
1074
  _record_inertia(an, solve_new, silent=silent)
1074
1075
  solve_last = solve_new
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: structsolve
3
- Version: 0.11.0
3
+ Version: 0.12.0
4
4
  Summary: Structural analysis solvers
5
5
  Author-email: "Saullo G. P. Castro" <castrosaullo@gmail.com>
6
6
  License-Expression: BSD-3-Clause
@@ -82,7 +82,7 @@ collected after each call, so that the WebAssembly heap is not exhausted.
82
82
  Citing this library
83
83
  ===================
84
84
 
85
- Saullo G. P. Castro (2026). Structural analysis solvers tailored for semi-analytical models (Version 0.11.0). Zenodo. DOI: https://doi.org/10.5281/zenodo.2581212.
85
+ Saullo G. P. Castro (2026). Structural analysis solvers tailored for semi-analytical models (Version 0.12.0). Zenodo. DOI: https://doi.org/10.5281/zenodo.2581212.
86
86
 
87
87
 
88
88
  Documentation
@@ -97,6 +97,9 @@ History
97
97
 
98
98
  See [CHANGELOG.md](CHANGELOG.md) for the details of each version.
99
99
 
100
+ * version 0.12.0 (2026-11-23)
101
+ - `Analysis.on_converged`: a callable called once after every converged increment of the non-linear analyses, never for a rejected or cut increment, to update the internal variables of path-dependent models, e.g. the damage of a cohesive zone
102
+
100
103
  * version 0.11.0 (2026-11-13)
101
104
  - `freq` with the dense solvers (`sparse_solver=False`) solves the shifted inverse problem, accurate for the lowest natural frequencies of stiff models, e.g. with penalty springs, and warns when one of the lowest eigenpairs fails the residual check
102
105
  - `freq` accepts the eigenpairs of the sparse solvers whose residual is at the round-off when the inertia of `K - s M` confirms the eigenvalue, instead of falling back to the dense solver or raising an error
@@ -47,6 +47,7 @@ tests/test_linear_buckling.py
47
47
  tests/test_linear_buckling_unsymmetric.py
48
48
  tests/test_load_factor_dependent_load.py
49
49
  tests/test_newton_raphson.py
50
+ tests/test_on_converged.py
50
51
  tests/test_pardiso.py
51
52
  tests/test_restart.py
52
53
  tests/test_reuse.py
@@ -0,0 +1,109 @@
1
+ """Tests of ``Analysis.on_converged``
2
+
3
+ The callable is called once per converged increment, with the new state
4
+ already appended, and never for a rejected or cut increment. A
5
+ path-dependent spring whose internal variable is updated only by
6
+ ``on_converged`` follows the exact solution, which it would not if the
7
+ variable were updated during the iterations.
8
+
9
+ """
10
+ import numpy as np
11
+ import pytest
12
+ from scipy.sparse import csr_matrix
13
+
14
+ from structsolve import Analysis
15
+ from analytic_problems import hardening_springs, von_mises_truss
16
+ from test_stopping import ARC_METHODS, kwargs_of
17
+
18
+
19
+ @pytest.mark.parametrize('method', ['NR'] + ARC_METHODS)
20
+ def test_called_once_per_converged_increment(method):
21
+ seen = []
22
+
23
+ def on_converged(an):
24
+ seen.append((len(an.cs), len(an.increments), an.increments[-1],
25
+ an.cs[-1].copy()))
26
+
27
+ p = hardening_springs()
28
+ kwargs = {}
29
+ if method == 'displacement_control':
30
+ kwargs['control_vector'] = np.array([0., 0., 0., 1.])
31
+ p.analysis(NL_method=method, initialInc=0.1, final_load_factor=1.,
32
+ on_converged=on_converged, **kwargs)
33
+ p.an.static(NLgeom=True, silent=True)
34
+ # one call per converged increment, the state already appended
35
+ assert len(seen) == len(p.an.increments) > 1
36
+ for k, (ncs, ninc, lbd, c) in enumerate(seen):
37
+ assert ncs == ninc == k + 1
38
+ assert lbd == p.an.increments[k]
39
+ np.testing.assert_array_equal(c, p.an.cs[k])
40
+
41
+
42
+ @pytest.mark.parametrize('method', ['NR', 'arc_length_riks'])
43
+ def test_not_called_for_cut_increments(method):
44
+ """Increments that do not converge are cut and retried: the calls
45
+ match the converged increments only"""
46
+ calls = []
47
+ p = von_mises_truss(frac=0.99 if method == 'NR' else 1.5)
48
+ p.analysis(NL_method=method, initialInc=0.5, maxInc=0.5,
49
+ on_converged=lambda an: calls.append(len(an.cs)))
50
+ p.an.static(NLgeom=True, silent=True)
51
+ assert calls == list(range(1, len(p.an.cs) + 1))
52
+
53
+
54
+ def _softening_spring():
55
+ r"""One spring with irreversible secant softening, loaded by a force
56
+ beyond its peak along a displacement-controlled path
57
+
58
+ `f(u) = k (1 - d) u` with `d = \max_{past} g(|u|)`, `g` growing from 0
59
+ at `u_0` to 0.5 at `2 u_0`. The internal variable `d` is a function of
60
+ the largest displacement of the converged states only.
61
+ """
62
+ k, u0 = 1., 1.
63
+
64
+ def g(u):
65
+ return np.clip(0.5*(abs(u) - u0)/u0, 0., 0.5)
66
+
67
+ state = {'d': 0.}
68
+
69
+ def dmg(u):
70
+ return max(state['d'], g(u))
71
+
72
+ def calc_fint(c, inc=1., silent=True):
73
+ return np.array([k*(1 - dmg(c[0]))*c[0]])
74
+
75
+ def calc_kC(c=None, NLgeom=False, inc=1., silent=True):
76
+ if c is None:
77
+ return csr_matrix(np.array([[k]]))
78
+ u = c[0]
79
+ d = dmg(u)
80
+ kt = k*(1 - d)
81
+ if g(u) > state['d'] and 0. < g(u) < 0.5:
82
+ kt -= k*u*np.sign(u)*0.5/u0
83
+ return csr_matrix(np.array([[kt]]))
84
+
85
+ def calc_kG(c=None, NLgeom=False, inc=1., silent=True):
86
+ return csr_matrix((1, 1))
87
+
88
+ def calc_fext(inc=1., silent=True):
89
+ return np.array([inc*1.])
90
+
91
+ def on_converged(an):
92
+ state['d'] = dmg(an.cs[-1][0])
93
+
94
+ return state, calc_fext, calc_fint, calc_kC, calc_kG, on_converged
95
+
96
+
97
+ def test_history_updated_only_at_converged_states():
98
+ state, fext, fint, kC, kG, on_converged = _softening_spring()
99
+ an = Analysis(fext, fint, kC, kG)
100
+ an.NL_method = 'NR'
101
+ an.initialInc = 0.05
102
+ an.maxInc = 0.05
103
+ an.final_load_factor = 1.
104
+ an.on_converged = on_converged
105
+ an.static(NLgeom=True, silent=True)
106
+ # below the peak force k*u0*(1 - 0) = 1 the spring is elastic, at the
107
+ # load factor 1 exactly at the onset: no damage, u = 1
108
+ assert state['d'] == 0.
109
+ np.testing.assert_allclose(an.cs[-1], [1.], rtol=1e-8)
File without changes
File without changes