.. _python_API_convergence_example:

.. currentmodule:: flow360

**************************
Convergence
**************************

This example demonstrates how to retrieve, process, and visualize convergence data from a completed Flow360 simulation using the Python API. It outlines the procedure for setting up a basic steady-state case, running it, and subsequently accessing and plotting convergence metrics such as nonlinear residuals and CFL numbers.

.. literalinclude:: ../../../../../Flow360/examples/post_processing/convergence/convergence.py
  :language: python
  :linenos:

Notes
=====

- The script utilizes ``case.wait()`` to pause execution until the simulation completes, ensuring that results are available for post-processing.
- Convergence history, including nonlinear residuals (``results.nonlinear_residuals``), maximum residual locations (``results.max_residual_location``), and CFL values (``results.cfl``), are accessed via the ``results`` object. These are converted to pandas DataFrames using ``.as_dataframe()`` for convenient analysis and plotting.
- Specific convergence-related files can be downloaded using the ``results.download()`` method by specifying the desired data types (e.g., ``nonlinear_residuals=True``, ``cfl=True``).
