Giter Site home page Giter Site logo

timofeymukha / turbulucid Goto Github PK

View Code? Open in Web Editor NEW
54.0 11.0 25.0 9.66 MB

A Python package for visualising 2D CFD datasets.

Home Page: https://timofeymukha.github.io/turbulucid/

License: GNU General Public License v3.0

Python 8.69% C++ 91.15% GLSL 0.15%
vtk visualization cfd flow

turbulucid's Introduction

turbulucid

What?

Turbulucid is a package for post-processing two-dimensional cell-centered VTK polyData. The main use case is envisioned to be analysis of cut-plane data coming from finite-volume based solvers for Computational Fluid Dynamics. The package contains functions for both plotting the data and data introspection.

For more details see this paper https://openresearchsoftware.metajnl.com/article/10.5334/jors.213/ Please cite it if you use Turbulucid in your work!

Why?

VTK has become a popular format for storing unstructured datasets (both 3d and 2d). The API of VTK and software such as Paraview already provide the means for working with VTK data, so why the need for a new package? The answer is that while the above-mentioned tools are excellent for general inspection of large 3d datasets, they do not provide the means for producing publication-quality plots of 2d data. An example of such a plot, produced with turbulucid, is shown below.

Also, while VTK provides an abundance of filters for extracting specific parts of a dataset, the object-oriented API is hard to learn and quite verbose. Turbulucid provides easier access to the data and a set of functions for performing simple extractions.

How?

Under the hood turbulucid uses VTK to handle the data, but exposes everything to the user in terms of numpy arrays. The plotting functions use matplotlib, and return associated matplotlib objects. This allows the user to harness the full customization power of matplotlib to make the plots look exactly as desired.

Installing

Turbulucid requires Python 3. It should work on any platform, where the packages described below also work. It has been used extensively on both Windows and Linux.

For turbulucid to work, several other packages have to installed. Four packages are numpy, scipy, matplotlib, and pytest. These are easy to obtain and are part of many python distributions, in particular, Anaconda.

Turbulucid also depends on python bindings for VTK, i.e the vtk package. The version of VTK should be at least 7.0.0. With Anaconda, VTK can be obtained by running conda install vtk in the terminal. However, recently there have been some issues with VTK and conda, which seem to be resolved by using the conda-forge package channel: conda install vtk -c conda-forge. The best practice is to then use a separate conda environment and install all the necessary pacakges from conda-forge there.

Installing the package is easy. Simply clone the git repository or download it as an archive and then unpack. Then navigate to the root catalog of the code in a terminal and execute python setup.py install. This may require root priviliges, if you lack them, the --user flag can be used. Alternatively, the --prefix flag can be used to directly specify the installation path.

Using conda, it is possible to test the package in a separate environment:

conda create -n tbl python=3.8
source activate tbl
conda install -c conda-forge vtk numpy scipy matplotlib pytest
python setup.py install

For more info regarding Anaconda environments refer to https://conda.io/docs/user-guide/tasks/manage-environments.html

Validation

Turbulucid comes with a number of unit tests, covering part of its functionality. Expanding the test suite is a work in progress. The tests are ran on Travis after each commit. To run the tests on your machine, go to the top-level directory of turbulucid and run pytest tests.

The best way to validate the functionality is to apply turbulucid to post-processing some simple dataset, which can also be opened in another software in order to compare results. To that end, three datasets are provided in the turbulucid/datasets folder. All are stored as .vtm VTK files that can also be opened in e.g. Paraview.

Dive in!

A great place to learn how to use the package is the tutorial availble in docs/tutorial. You can view the tutorial directly in the browser. To run it on your machine, you need to install Jupyter, please refer to https://jupyter.org for associated documentation.

A compilation of all the docstrings is availble at the project's Github pages.

A collection of video-tutorials are gathered in this Youtube playlist

Turbulucid is free software and is provided under the GNU GPL Version 3. See LICENSE.txt for the full text of the license.

The copyright to the code and documentation belongs to the author, Timofey Mukha.

Please take special notice of the following disclaimers.

Disclaimer of warranty

THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM β€œAS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

Limitation of liability

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

turbulucid's People

Contributors

timofeymukha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

turbulucid's Issues

Nek5000 reader

I glanced through your tutorial yesterday. I tried to output a .vtp file after loading the Nek5000 field file in paraview via the visnek utility. It does not seem to directly work with turbulucid's Case class.

I have a rough sketch for a VTK interface generated with help of Paraview here: https://github.com/exabl/sandbox/blob/master/paraview/nekio.py. It might be interesting to have it here.

Support for sliding mesh cases

Hello,
I would like to thank you for this package, it looks very promising. Particularly for static cases (no moving mesh).

Unfortunately, I have tried it to read a case with sliding mesh (Arbitrary Mesh Interface) but it doesn't seem to work.

Is there any plan to include support for sliding mesh cases?

How to directly plot an hdf5 file directly

Dear turbulucid Developers,

I wonder how to plot an hdf5 file containing several variables, each variable has 2-D uniform-grid data?
i.e.,
How to plot Temperature variable with a dimension of 1280x1280 grids in my hdf5 using turbulucid without have to convert it to vtk?
By using h5py, I can read my data, get T NumPy array of 1280x1280. How can I pass this array to Case object?
It seems that Case object only created if reading from vtk-type data.

Thank you,
Minh Bau.

The cloud map drawn is not smooth like paraview

Hello, Timofey
Thank you for developing such a great tool!
I got the cross-sectional data through openfoam's sample method, and then drew a cloud map by turbulucid, but this cloud map is not as smooth as paraview.
Is there any way to make the turbulucid cloud map smoother?

For example, in the case of cavity, paraview can get a smooth cloud map by interpolation
Snipaste_2021-05-09_11-35-20
Snipaste_2021-05-09_11-34-52
turbulucid seems to be able to draw only the raw data of the cloud map
Snipaste_2021-05-09_11-37-37

plot_vectors with colorField failed.

Hi,

Thank you for develop this useful tools. When I run the test case, I encounter some errors that disappear if I close the sampleByPlane. I think sampleByPlane caused the array to mismatch. Is it a bug?

Regards.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[c:\Users\Wang\Desktop\turbulucid-master\docs\tutorial\turbulucid_tutorial.ipynb](file:///C:/Users/Wang/Desktop/turbulucid-master/docs/tutorial/turbulucid_tutorial.ipynb) Cell 37 line 1
----> [1](vscode-notebook-cell:/c%3A/Users/Wang/Desktop/turbulucid-master/docs/tutorial/turbulucid_tutorial.ipynb#X51sZmlsZQ%3D%3D?line=0) plot_vectors(case, 'UMean', colorField='magUMean', scaleX=h, scaleY=h, normalize=True, sampleByPlane=True, planeResolution=[70,150], scale=50)
      [2](vscode-notebook-cell:/c%3A/Users/Wang/Desktop/turbulucid-master/docs/tutorial/turbulucid_tutorial.ipynb#X51sZmlsZQ%3D%3D?line=1) plt.xlim([-1, 6])
      [3](vscode-notebook-cell:/c%3A/Users/Wang/Desktop/turbulucid-master/docs/tutorial/turbulucid_tutorial.ipynb#X51sZmlsZQ%3D%3D?line=2) plt.ylim([-1, 1])

File /opt/miniconda3/envs/tbl/lib/python3.8/site-packages/turbulucid-0.4-py3.8.egg/turbulucid/core/plotting.py:214, in plot_vectors(case, field, colorField, normalize, scaleX, scaleY, sampleByPlane, planeResolution, plotBoundaries, **kwargs)
    [212](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/tbl/lib/python3.8/site-packages/turbulucid-0.4-py3.8.egg/turbulucid/core/plotting.py:212) if sampleByPlane:
    [213](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/tbl/lib/python3.8/site-packages/turbulucid-0.4-py3.8.egg/turbulucid/core/plotting.py:213)     if type(colorField) == str:
--> [214](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/tbl/lib/python3.8/site-packages/turbulucid-0.4-py3.8.egg/turbulucid/core/plotting.py:214)         colorData = sampledData[colorField].reshape(planeResolution[1] + 1,
    [215](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/tbl/lib/python3.8/site-packages/turbulucid-0.4-py3.8.egg/turbulucid/core/plotting.py:215)                                                     planeResolution[0] + 1)
    [216](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/tbl/lib/python3.8/site-packages/turbulucid-0.4-py3.8.egg/turbulucid/core/plotting.py:216)         return plt.quiver(pointsX/scaleX, pointsY/scaleY, data[:, 0],
    [217](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/tbl/lib/python3.8/site-packages/turbulucid-0.4-py3.8.egg/turbulucid/core/plotting.py:217)                           data[:, 1], colorData, **kwargs)
    [218](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/tbl/lib/python3.8/site-packages/turbulucid-0.4-py3.8.egg/turbulucid/core/plotting.py:218)     else:

ValueError: cannot reshape array of size 10500 into shape (151,71)

Incompatible with vtk 8.2.x

Turbulucid installs without problems, but an error encountered when trying to import it. This limits the available python version when using Anaconda to 3.6.

The following error is shown when trying to import turbulucid:


ImportError Traceback (most recent call last)
~\AppData\Local\Continuum\anaconda3\envs\Turbulucid\lib\site-packages\vtkmodules\vtkIOParallel.py in
4 # use relative import for installed modules
----> 5 from .vtkIOParallelPython import *
6 except ImportError:

ImportError: DLL load failed: The specified procedure could not be found.

During handling of the above exception, another exception occurred:

ModuleNotFoundError Traceback (most recent call last)
in
----> 1 import turbulucid

~\AppData\Local\Continuum\anaconda3\envs\Turbulucid\lib\site-packages\turbulucid-0.2-py3.7.egg\turbulucid_init_.py in
4 # See LICENCE.txt and the Legal section in the README for more information
5
----> 6 from . import core
7 from .core import *
8

~\AppData\Local\Continuum\anaconda3\envs\Turbulucid\lib\site-packages\turbulucid-0.2-py3.7.egg\turbulucid\core_init_.py in
4 # See LICENCE.txt and the Legal section in the README for more information
5
----> 6 from .case import *
7 from .plotting import *
8 from .data_extraction import *

~\AppData\Local\Continuum\anaconda3\envs\Turbulucid\lib\site-packages\turbulucid-0.2-py3.7.egg\turbulucid\core\case.py in
8 from future import print_function
9 import numpy as np
---> 10 from vtk.util.numpy_support import numpy_to_vtk
11 from vtk.util.numpy_support import vtk_to_numpy
12 import os

~\AppData\Local\Continuum\anaconda3\envs\Turbulucid\lib\site-packages\vtk.py in
30 all_spec = importlib.util.find_spec('vtkmodules.all')
31 all_m = importlib.util.module_from_spec(all_spec)
---> 32 all_spec.loader.exec_module(all_m)
33
34 # import vtkmodules

~\AppData\Local\Continuum\anaconda3\envs\Turbulucid\lib\site-packages\vtkmodules\all.py in
81 from .vtkIONetCDF import *
82 from .vtkIOPLY import *
---> 83 from .vtkIOParallel import *
84 from .vtkIOParallelXML import *
85 from .vtkIOSQL import *

~\AppData\Local\Continuum\anaconda3\envs\Turbulucid\lib\site-packages\vtkmodules\vtkIOParallel.py in
7 # during build and testing, the modules will be elsewhere,
8 # e.g. in lib directory or Release/Debug config directories
----> 9 from vtkIOParallelPython import *

ModuleNotFoundError: No module named 'vtkIOParallelPython'

Set the minimum and maximum color bar

Hi there,

Firstly, I would like to appreciate your work on the turbulucid.
It is very useful for the unstructured grid.

I need to use one color bar for many figures in one plot.
Anyway, how do we set the minimum and maximum color bar?
It is usually set by defining vmin and vmax.

problem reading *vtk structured_grid datasets

I am trying to plot CFD data with turbulucid. I have *vtk files wit STRUCTURED_GRID dataset type. These files work well with other 3d visualization packages as pyvista. But when I try to create the Case with turbulucid i get the following error.

2021-10-13 17:46:03.685 (1410.649s) [ 2DB42740] vtkPolyDataReader.cxx:126 ERR| vtkPolyDataReader (0x3b03f30): Cannot read dataset type: structured_grid

`---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
/tmp/ipykernel_871702/3782052166.py in
4 import turbulucid as tb
5 #
----> 6 case = tb.Case(vtk_files[0])
7 # ------------------------------------------------------------------------- #

/usr/local/lib/python3.8/dist-packages/turbulucid-0.2-py3.8.egg/turbulucid/core/case.py in init(self, fileName, clean, pointData)
38
39 # Read in the data
---> 40 self._blockData = self.read(clean, pointData)
41
42 # Compute the cell-centres

/usr/local/lib/python3.8/dist-packages/turbulucid-0.2-py3.8.egg/turbulucid/core/case.py in read(self, clean, pointData)
458 return reader.data
459 elif fileExt == ".vtk":
--> 460 return LegacyReader(fileName, clean=clean,
461 pointData=pointData).data
462 elif (fileExt == ".vtu") or (fileExt == ".vtp"):

/usr/local/lib/python3.8/dist-packages/turbulucid-0.2-py3.8.egg/turbulucid/core/readers.py in init(self, filename, clean, pointData)
175 self._vtkReader.Update()
176
--> 177 internalData = self._transform()
178 if clean:
179 internalData = self._clean(internalData)

/usr/local/lib/python3.8/dist-packages/turbulucid-0.2-py3.8.egg/turbulucid/core/readers.py in _transform(self)
93 transform = vtk.vtkTransform()
94
---> 95 meanNormal = self._compute_normal()
96
97 axis = np.cross(meanNormal, [0, 0, 1])

/usr/local/lib/python3.8/dist-packages/turbulucid-0.2-py3.8.egg/turbulucid/core/readers.py in _compute_normal(self)
129 vtkNormals.Update()
130 normals = dsa.WrapDataObject(vtkNormals.GetOutput()).CellData["Normals"]
--> 131 meanNormal = np.mean(normals, axis=0)
132 meanNormal /= np.linalg.norm(meanNormal)
133 return meanNormal

<array_function internals> in mean(*args, **kwargs)

/usr/lib/python3/dist-packages/numpy/core/fromnumeric.py in mean(a, axis, dtype, out, keepdims)
3254 return mean(axis=axis, dtype=dtype, out=out, **kwargs)
3255
-> 3256 return _methods._mean(a, axis=axis, dtype=dtype,
3257 out=out, **kwargs)
3258

/usr/lib/python3/dist-packages/numpy/core/_methods.py in _mean(a, axis, dtype, out, keepdims)
136
137 is_float16_result = False
--> 138 rcount = _count_reduce_items(arr, axis)
139 # Make this warning show up first
140 if rcount == 0:

/usr/lib/python3/dist-packages/numpy/core/_methods.py in _count_reduce_items(arr, axis)
55 items = 1
56 for ax in axis:
---> 57 items *= arr.shape[ax]
58 return items
59

IndexError: tuple index out of range`

Is it possible that structured grids are not supported and I should create polydata files?

Issues with plot rendering

When I plot the results from a simulation, I get a grainy plot using turblucid (see attached image).
Grainy image
When I zoom in, the graininess of the image disappears :
Zoomed image

This behavior may be related to the fact that the simulation was performed with an unstructured mesh so matplotlib has problems rendering it.

Sorry I cannot be more specific, but I do not know how to describe this problem with more detail.

store data in .vtm format from OpenFoam simulation

I have some results in the VTK format form my OpenFoam simulation (generated with foamToVTK). Can I use this vtk file for plotting? When I try to use this VTK file, I got an indexing error "IndexError: tuple index out of range". If I save my data in the .vtm format form paraview and try to load the .vtm file, I am still getting an error "'VTKNoneArray' object has no attribute 'GetNumberOfValues'". How are you storing your data into .ntm format from OpenFoam simulation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.