I’m very glad I’ve found an active community to discuss Fortran related problems!
I’m writing a program where, at some points, I’ve to plot a mesh consisting of million of points, quadrilateral cells and possibly hexahedral cells. I may use some matplotlib interface but with that workload it is too slow and it is almost impossible to drag and zoom to inspect for mesh quality.
Possible resolutions that comes to my mind :
(a) write the mesh in some VTK internal format (like .vtu) and then call Paraview to open the mesh and inspect it… I want to avoid this, because it will be so slow (I/O bottleneck) and not well integrated within the main program
(b) write an interface to some VTK’s methods to call VTK routines in runtime (must anyway convert to VTK internal format initializing some data structure, but this is done without I/O latency. Unfortunately memory usage will at least double )
Suggestions of any type are welcome
Welcome @Rob777 !
There is this project:
but I have not tested it.
Concerning meshes inspection, I have already used https://www.meshlab.net/ but I don’t know its performances with 1M points.
Thank you very much, but :
About the VTK library : this is not an interface to VTK libraries but a library to read and write VTK internal format (.vtu , .vtm etc) files… “VTKFortran is a pure Fortran library to parse and emit VTK files”
This can be associated to the (a) point of the my first post (write a VTK file to disk and then call paraview to open and visualize the mesh), which I want to avoid…
About meshlab : Unfortunately it deals only with triangular meshes and it seems it comes only as a standalone application
About mesh inspection : I mean visual inspection, so only drag , zoom and rotate view…this is possible in matplotlib but when number of points increases performance decreases drastically. Other tools like VTK libraries (from which paraview is build upon) have algorithms for visualizing million points meshes efficently (for example plotting only points in the field of view)
I don’t have a lot of experience plotting unstructured meshes, but I have faced similar problems when I had to visualize millions of particles, or just scalar/vector fields on simpler meshes. What I like to do is to write raw data in a relatively simple format that can be used for other purposes such as checkpointing (I use raw binary data, but e.g. HDF5 would also work and may be better for portability), and then write a metadata xdmf file which paraview understands, that points to the larger file (see http://www.xdmf.org/index.php/XDMF_Model_and_Format).
For rendering about one million spheres I saved data in a binary file, ordered as follows (I hope its clear):
[x1,y1,z1],...,[xn,yn,zn] # this would be the position of the centroid of the spheres [a1] ... [an] # this would be some scalar attribute (e.g. temperature) [vx1,vy1,vz1]...[vxn,vyn,vzb] # this would be some vector attribute (e.g. velocity)
Then I generate an xdmf file corresponding to an unstructured grid that will plot this cloud of points. The quick and dirty Fortran script that I used can be found on this repo: https://github.com/p-costa/gen_xdmf_particles .
Perhaps you can try something similar for your more complicated mesh.
PS: I nowadays use a xml python parser to generate the xdmf files, e.g.: lines 77-132 of this script: https://github.com/p-costa/CaNS/blob/master/utils/visualize_fields/gen_xdmf_easy/write_xdmf.py not sure which approach would be more convenient to you.
Thanks for your help, the code you posted seems interesting and your suggestions are well appreciated, but as I said, I want to avoid to write data to disk and then call an external visualization program, firstly because the mesh is really big and it can take minutes for I/O, secondly because I prefer a more interactive and integrated solution. However, your suggestions and code can help me to solve future issues with xdmf files.
I see. Sorry, perhaps I read your original post a bit too quickly.
I guess that ParaView Catalyst library for in-situ visualization would work, but the visualization tasks must be implemented in C++ or Python.
Paraview Catalyst library is a solution allowing paraview to be used with In Situ visualization capabilites ( a simple example is a lot of data distributed on a cluster and the simulation running, producing and updating that data ). I think it is better to use VTK libraries, but as noted in point (b) of my original post, the downside of an interface to VTK libraries, which are very powerful tools to visualize scientific data like a big computational mesh, are that for using VTK classes and their methods you must initialize them. This means passing a lot of data to that data structures, at least doubling memory usage and I did not mention the fact that a Fortran interface to VTK is actually missing.
The ideal solution I’m searching for is something like matplotlib (you pass point by point the mesh to be plotted, without the memory catching on fire) but instead of plotting all of the data at once as matplotlib does , some sort of shaders is applied to the visualization (for example points out of the field of view are not plotted, or when you zoom out details becomes more raw).