There seems to be an issue with the export of results to vtk in FLAC3D version 9.4.33 on Window 11.
I created below a minime viable example:
model new
zone create brick
zone vtk filename “testfile“
This will create a .vtu file, except that if you try to read it in a common vtk file reader such as Paraview it is not detected as a readable .vtu file.
By inspecting the beginning of the file the issue is clear: The file is directly binary instead of having an xml header.
Previous versions suc has 9.1 did produce correctly formatted vtu files as you can see with the example first few characters of a file I created in the past:
Therefore, I wish to know if there is a workaround that do not involve downgrading the version of FLAC3D.
For example, does someone has experience install packages such as the vtk package using the pip packages with the FLAC3D python? If I have access to the vtk package I can easily write a script to export to vtu using the python API.
I am reluctant to try things on the fly, that could break the flac installation and would be very thankful if someone had a return on experience with this type of endeavors.
Here is a script to show how to use vtk to export FLAC3D results. I use the numpy interface both in FLAC and vtk so it should work efficiently even for very large files.
First create a minimal viable mesh:
model new
zone create brick
The python function below will allow you to export gridpoints data to vtk fileformat (indentation is not correct, I do not know how to make it work correctly).
import itasca as it
import numpy as np
import vtk
import vtkmodules
# writer
writer = vtk.vtkXMLPolyDataWriter()
writer.SetFileName(filename)
writer.SetInputData(pts_cloud) #writer.SetDataModeToAscii() uncomment this line to get the file entirely in ascii xml
writer.Write()
print(f" {vtk_points.data.data_size} gripoints saved to file {filename}")
You can then run the script as follow
export_gridpoints_to_vtk(“test1.vtu”)
If you open the file in a viewer such as Paraview you should get the following view:
If you also want to export zone data. I advise to use the pyvista library rather than vtk. It offers a much better interoperability with numpy. This way pyvista and the itasca python library can interface using numpy structure, which is is much more performant than using vtk which would force us to use very inefficient python loops.
The following code works for meshes which only contains brick and degenerated bricks. I will come up with a more general solution later.