diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..0b30758a --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,16 @@ +# How to contribute + +Thanks for considering contributing to TransiFlow! Any contribution is welcome, but let me list some examples: + +- Add a new problem type. In this case you'd need to add a discretization for the problem, an example in the examples directory and a problem description to the documentation. This should be done in a single pull request. +- Add a new computational backend. An example can be a PETSc backend that provides a specialized preconditioner. Since this can be a large undertaking, this can (and probably should) be split into many smaller pull request. +- Add a new feature. For instance a new way to track bifurcations or a new time stepper. +- Fix a bug. Hopefully you don't encounter any bugs, but in case you do, feel free to fix them or report an issue. +- Fix the documentation. If you're in the process of reading the documentation, you're the one most likely to find any issues, that no one would notice otherwise. Fixing these issues is extremely useful! + +## Coding conventions + +In general, just follow the style of the code around the code you're editing. Other than that: + +- Make sure every commit makes sense as a stand-alone commit, and that the code still works after every commit. This makes the code easy to review and makes it easier to find bugs in the future. +- Make sure every commit has a readable commit message that follows the style of the existing commits. \ No newline at end of file diff --git a/README.md b/README.md index e0fb85b2..13d392c1 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,11 @@ An example of how to perform a continuation and compute eigenvalues can be found ## Installation +TransiFlow is available on [PyPi](https://pypi.org/project/transiflow/), and can be installed by running +``` +pip install transiflow +``` + TransiFlow is best installed in a [virtual environment](https://docs.python.org/3/library/venv.html). We state the most common steps for creating and using a virtual environment here. Refer to the documentation for more details. @@ -46,9 +51,11 @@ and to activate the virtual environment, run source /path/to/new/virtual/environment/bin/activate ``` -After this, we can upgrade pip and install TransiFlow in editable mode from the transiflow source directory. +After this, we can install TransiFlow from PyPi as described above, or from this source repository, to allow for easy modifications of the code. +To clone the TransiFlow git repository and install TransiFlow in editable mode from the transiflow source directory, one can perform the following commands ``` -pip install --upgrade pip +git clone https://github.com/BIMAU/transiflow.git +cd transiflow pip install -e . ``` This will also install all of the dependencies. @@ -66,3 +73,11 @@ ldc.py:64: UserWarning: Matplotlib is currently using agg, which is a non-GUI ba ``` this means that [tkinter](https://docs.python.org/3/library/tkinter.html) is not available. You can either just save the image to the disk, or install e.g. `python3-tk` or `python3-matplotlib` on Debian-based Linux distributions. + +## Optional dependencies + +To use the optional computational backends, you can install the following: + +- HYMLS: Install Trilinos with PyTrilinos enabled, then install [HYMLS](https://github.com/nlesc-smcm/hymls). +- Epetra: Install Trilinos with PyTrilinos enabled. This is enough to use the backend, but since there is no preconditioner, this may not be very useful. +- PETSc: Run `PETSC_CONFIGURE_OPTIONS='--download-mumps --download-scalapack' pip install mpi4py petsc4py`. This is enough to use the backend, but since there is no preconditioner yet, this may not be very useful. diff --git a/docs/continuation.rst b/docs/continuation.rst index 847ac9f1..c25069c9 100644 --- a/docs/continuation.rst +++ b/docs/continuation.rst @@ -2,6 +2,7 @@ Performing a continuation ========================= In this section, we will briefly guide you through the :ref:`Double-gyre wind-driven circulation` example as a means of explaining what a typical workflow looks like. The full example can be found in ``examples/qg.py``. +Note that the :ref:`examples` are kept simple to give an idea on how to implement a continuation for your own use case, not to give a demo of the most fancy features that are available. First we create an :func:`Interface <.create>`. This is the interface to the computational backend and to the discretization of the problem. diff --git a/docs/examples.rst b/docs/examples.rst new file mode 100644 index 00000000..0dfb613c --- /dev/null +++ b/docs/examples.rst @@ -0,0 +1,31 @@ +Examples +================================== +The ``examples`` directory contains several examples on how to use TransiFlow. +They do this based on a certain problem definition, but in theory, all examples are useful for any problem definition. +On this page, we give an overview of what every example is supposed to demonstrate. + +``ldc.py`` + The most basic example that shows the detection of a bifurcation point in a 2D lid-driven cavity, and computes the eigenvector at that point. + +``ldc2.py`` + An example that goes more into detail on how to compute generalized eigenvalues and eigenvectors for the problem definition. + +``ldc3.py`` + An example that shows how to perform time integration. + This may for instance be useful when computing periodic orbits after a Hopf-Bifurcation. + +``ldc3_3d.py`` + An example that shows how to use a parallel back-end (HYMLS in this case) for a 3D problem. + +``dhc.py`` + Essentially the same as ``ldc.py`` but now for a differentially heated cavity, meaning this now includes temperature. + +``qg.py`` + An example that shows how to move onto a stable branch after a pitchfork bifurcation by adding asymmetry to the problem. + +``amoc.py`` + A more advanced version of ``qg.py`` with added temperature and salinity and more advanced post-processing. + +.. + Explicitly enable math mode +.. math:: diff --git a/docs/index.rst b/docs/index.rst index 6fba495c..a5e84c81 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -16,6 +16,7 @@ The package is fully agnostic of the computational backend, which allows for eas continuation backends + examples custom-bc custom-model diff --git a/examples/amoc.py b/examples/amoc.py index 814def37..146ccbde 100644 --- a/examples/amoc.py +++ b/examples/amoc.py @@ -1,3 +1,7 @@ +'''An example of performing a continuation for a 2D AMOC, where the +plots and interim solutions are written to files instead of storing +them in memory and showing them on the screen.''' + import numpy import matplotlib.pyplot as plt @@ -38,10 +42,6 @@ def generate_plots(interface, x, sigma): def main(nx=60): - '''An example of performing a continuation for a 2D AMOC, where the plots and interim - solutions are written to files instead of storing them in memory and showing them on - the screen.''' - ny = nx // 2 # Define the problem diff --git a/examples/dhc.py b/examples/dhc.py index 2d68838c..27fe0756 100644 --- a/examples/dhc.py +++ b/examples/dhc.py @@ -1,3 +1,6 @@ +'''An example of performing a continuation for a 2D differentially +heated cavity and detecting a bifurcation point.''' + import matplotlib.pyplot as plt from transiflow import Continuation @@ -13,7 +16,6 @@ def postprocess(data, interface, x, mu): def main(nx=32): - ''' An example of performing a continuation for a 2D differentially heated cavity and detecting a bifurcation point''' ny = nx nz = 1 diff --git a/examples/ldc.py b/examples/ldc.py index 7f4e34a2..6babb569 100644 --- a/examples/ldc.py +++ b/examples/ldc.py @@ -1,3 +1,6 @@ +'''An example of performing a continuation for a 2D lid-driven cavity +and detecting a bifurcation point.''' + import matplotlib.pyplot as plt from transiflow import Continuation @@ -13,7 +16,6 @@ def postprocess(data, interface, x, mu): def main(nx=32): - ''' An example of performing a continuation for a 2D lid-driven cavity and detecting a bifurcation point''' ny = nx nz = 1 diff --git a/examples/ldc2.py b/examples/ldc2.py index 57107589..e39ce0a8 100644 --- a/examples/ldc2.py +++ b/examples/ldc2.py @@ -1,3 +1,6 @@ +'''An example of performing a continuation for a 2D lid-driven cavity +and computing eigenvalues along the way.''' + import numpy from transiflow import Continuation @@ -11,7 +14,6 @@ def main(nx=16): - ''' An example of performing a continuation for a 2D lid-driven cavity and computing eigenvalues along the way''' ny = nx # Define the problem diff --git a/examples/ldc3.py b/examples/ldc3.py index 4793bffc..0dddccff 100644 --- a/examples/ldc3.py +++ b/examples/ldc3.py @@ -1,3 +1,6 @@ +'''An example of performing a "poor man's continuation" for a 2D +lid-driven cavity using time integration.''' + import numpy import matplotlib.pyplot as plt @@ -14,7 +17,6 @@ def postprocess(data, interface, x, t): def main(nx=16): - ''' An example of performing a "poor man's continuation" for a 2D lid-driven cavity using time integration''' ny = nx # Define the problem diff --git a/examples/ldc_3d.py b/examples/ldc_3d.py index f25357be..1abef992 100644 --- a/examples/ldc_3d.py +++ b/examples/ldc_3d.py @@ -1,3 +1,10 @@ +''' An example of performing a continuation for a 3D lid-driven cavity using HYMLS. +Multiple processors can be used by calling this script using mpi, e.g.: + +OMP_NUM_THREADS=1 mpiexec -np 4 python examples/ldc_3d.py + +Disabling threading is adviced, since this is broken in Epetra.''' + from transiflow import Continuation from transiflow import Interface from transiflow import utils @@ -23,13 +30,6 @@ def postprocess(data, interface, x, mu, enable_output): def main(nx=16): - ''' An example of performing a continuation for a 3D lid-driven cavity using HYMLS. - Multiple processors can be used by calling this script using mpi, e.g.: - - OMP_NUM_THREADS=1 mpiexec -np 4 python examples/ldc_3d.py - - Disabling threading is adviced, since this is broken in Epetra.''' - ny = nx nz = nx diff --git a/examples/qg.py b/examples/qg.py index ad3f078b..eeab3287 100644 --- a/examples/qg.py +++ b/examples/qg.py @@ -1,3 +1,7 @@ +'''An example of performing a continuation for a double-gyre +wind-driven ocean, plotting the streamfunction at different Reynolds +numbers, and plotting the bifurcation diagram.''' + import numpy import matplotlib.pyplot as plt @@ -15,10 +19,6 @@ def postprocess(data, interface, x, mu): def main(nx=32): - '''An example of performing a continuation for a double-gyre - wind-driven ocean, plotting the streamfunction at different Reynolds - numbers, and plotting the bifurcation diagram.''' - ny = nx # Define the problem