.. PyTraceSuite documentation master file, created by sphinx-quickstart on Fri Nov 22 14:33:53 2019. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. PyTraceSuite Documentation ========================== .. toctree:: :maxdepth: 2 modules/pyTraceSuite.rst modules/pyHelper.rst Introduction ------------- This documentation describes the Python interface of ``TRACE`` and ``POST``. The TraceSuite offers three different Python interfaces: * Python-Calls-TRACE * TRACE-Calls-Python * FSTrace This introduction focuses on the first, because the other interfaces build on-top of it. For more details on the other interfaces, see their corresponding pages. System requirements ------------------- In order to use the PyTraceSuite the regular dependencies of ``TRACE`` and ``POST`` must be installed. Furthermore, the Python module has some additional dependencies, including: * ``Python 3 (>= 3.9)`` * :mod:`scipy` * :mod:`numpy` * :mod:`mpi4py` For a complete list of dependencies, including the required versions, look at the requirements list that is distributed with the PyTraceSuite. The PyTraceSuite is developed and tested with Python 3.9, different versions might work but are not officially supported. The FSDM interface has additional dependencies that you can find on the installation part of this interface: :ref:`fsdm-documentation` .. note:: When installing :mod:`mpi4py`, you must make sure that the python module is built with the exact same MPI version that you have installed on your system! One way to make sure that this is the case is to always build the package from source when installing with :mod:`pip`. To do so, use the ``--no-binary`` option: .. code-block:: bash $ pip install --force-reinstall --ignore-installed --no-binary=mpi4py mpi4py Installation ------------ There are two ways to install the PyTraceSuite: If you have source-code access, the PyTraceSuite can be build alongside the other executables if ``PYTHON_EXTENSIONS`` is enabled in CMake, which is the default. After building the TraceSuite you can install the PyTraceSuite with: .. code-block:: bash $ pip install We recommend using a `virtual environment `_. Otherwise, a pre-build python wheel is included in the release archives of the TraceSuite which can also be installed with :mod:`pip`. Getting Started --------------- After successfully installing the PyTraceSuite, you can make sure that everything is configured correctly by running .. code-block:: bash $ python3 -c "import tracesuite; print(tracesuite.__version__)" 9.8.0 which should print the version of the installed PyTraceSuite. The ``tracesuite`` module acts as the main python module for the PyTraceSuite. It includes shared functionality between ``pyTRACE`` and ``pyPOST``. Those python interfaces to the native tools are implemented in a ``tracesuite.trace`` and ``tracesuite.post`` submodule respectively. The following script shows a minimal example of using ``pyTRACE`` to control a CFD simulation: .. code-block:: python :linenos: from tracesuite.trace import TRACE if __name__ == "__main__": trace = TRACE("-cgns TRACE.cgns -cntl TRACE_control.cntl") for block in trace.blocks: print(f"zone={block.zone_id} name={block.name}"} trace.run() print(f"TRACE finished after {trace.solver_step} solver steps!") trace.kill() The ``TRACE`` instance is set-up in line 4: The constructor accepts the same arguments as the ``TRACE`` command line interface. After the instance is set up, attributes can be read and modified. In this case all blocks with their ``zone_id`` and ``name`` are printed. Then, the simulation is started using the ``run()`` method. An optional parameter would allow to run only a fixed number of iterations. With no parameters however, TRACE runs until the simulation is finished. The instances remains active until the ``kill()`` method is called, therefore properties can still be read and written after running solver iterations. This could allow you to execute during solver iterations and perform online changes to the solver instance. It is important that the ``kill()`` method is called before exiting to make sure that the MPI environment is properly shut-down. Similar to ``TRACE`` for the simulation, ``POST`` also offers a python interface for post processing: .. code-block:: python :linenos: from tracesuite.post import POST if __name__ == "__main__": post = POST() dataset = post.input("TRACE.cgns", rbc=True) post.averaging(dataset) post.TurbomachineryAnalysis_0D1D(ds, tecplotASCII="../output/gta/", ulist="../output/GTA.ulst") In this example, ``pyPOST`` is initialized in line 4. The ``pyPOST`` interface operates on so called datasets. Those are created by the ``input(...)`` task. Similar to ``POST`` on the command line, ``pyPOST`` offers a set of tasks that operate on a dataset. In the example above, the post tasks ``averaging`` and ``TurbomachineryAnalysis_0D1D`` are used. Therefore the above Python script is equivalent to the following ``POST`` command line: .. code-block:: bash $ POST -i TRACE.cgns -rbc -avg -glora -tecplotASCII ../output/gta/ -ulist ../output/GTA.ulst As pyTRACE is fully MPI compatible, it can be executed in parallel by using ``mpirun``: .. code-block:: bash $ mpirun -np