diff --git a/docs/python.md b/docs/python.md index d702fed9..6c126ea8 100644 --- a/docs/python.md +++ b/docs/python.md @@ -629,7 +629,7 @@ $\|\mathbf{r}\|_2 \le \max(\mathrm{rtol}\,\|\mathbf{b}\|_2, \mathrm{atol})$. | Parameter | Description | |-----------|-------------| | `comm` | `Communicator` used for the global reductions. | -| `fc` | Collection (`GlobalFieldCollection`, `LocalFieldCollection` or `CartesianDecomposition`) on which temporary work fields are created and removed again. | +| `fc` | Collection (`GlobalFieldCollection`, `LocalFieldCollection` or `CartesianDecomposition`) holding the solver's work fields. They stay registered after the solve, so the next solve on the same collection reuses them instead of allocating anew; their names start with `cg-work`. | | `b` | Right-hand side field. Its dtype sets the working precision. | | `x` | Initial guess; overwritten with the solution. | | `hessp` | Callable `hessp(x, Ax)` writing $\mathbf{A}\mathbf{x}$ into `Ax`. | @@ -649,6 +649,10 @@ preconditioner is found not to be positive definite, or if a residual becomes NaN or infinite. With a `float32` right-hand side, an `rtol` below `muGrid.Solvers.FLOAT32_RTOL_FLOOR` (`1e-6`) triggers a `RuntimeWarning`. +Since the work fields remain in `fc`, a `register_field_collection` of that +collection without `field_names` would write them to the file as well; name +the fields you want written. + ### conjugate_gradients_pipelined ```python diff --git a/language_bindings/python/muGrid/Solvers.py b/language_bindings/python/muGrid/Solvers.py index a6d51d70..1d6cc680 100644 --- a/language_bindings/python/muGrid/Solvers.py +++ b/language_bindings/python/muGrid/Solvers.py @@ -224,8 +224,11 @@ def conjugate_gradients( Communicator for parallel processing. fc : muGrid.GlobalFieldCollection, muGrid.LocalFieldCollection, or muGrid.CartesianDecomposition - Collection for creating temporary fields used by the CG algorithm. - They are named ``cg#-`` and removed again on return. + Collection holding the work fields of the CG algorithm. They are + named ``cg-work--...`` and stay registered in the + collection after the solve for the next one to reuse; pass + ``field_names`` to ``FileIONetCDF.register_field_collection`` to + leave them out of a file. b : muGrid.Field Right-hand side vector. x : muGrid.Field @@ -641,7 +644,7 @@ def conjugate_gradients_pipelined( ---------- comm, fc, b, x, hessp, prec, tol, maxiter, timer, rtol, atol As for :func:`conjugate_gradients`. Work fields are named - ``pcg#-``. + ``pcg-work--...`` and stay in the collection as well. callback : callable, optional Called as ``callback(iteration, state_dict)`` at the start of every iteration, after the reduction completes, with keys "x", "r", "p",