# Bug with the export to vtk of FLAC3D

**URL:** <https://forum.itascainternational.com/t/bug-with-the-export-to-vtk-of-flac3d/2238>\
**Category:** FLAC3D\
**Tags:** export, flac3d\
**Created:** [September 24, 2025, 3:20pm UTC](https://forum.itascainternational.com/t/bug-with-the-export-to-vtk-of-flac3d/2238 "2025-09-24T15:20:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephaneBeaussier](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@stephaneBeaussier](https://forum.itascainternational.com/u/stephaneBeaussier)\
**Post date:** [September 24, 2025, 3:20pm UTC](https://forum.itascainternational.com/t/bug-with-the-export-to-vtk-of-flac3d/2238/1 "2025-09-24T15:20:37Z")

</div>

Dear all,

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:

```auto
<?xml version="1.0" encoding="UTF-8"?>
<!--VTU file generated by flac3d 9.2 Release 20-->
<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">

```

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.

Other suggestion would also be warmly welcomed!

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![cheng](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@cheng](https://forum.itascainternational.com/u/cheng)\
**Post date:** [September 24, 2025, 3:46pm UTC](https://forum.itascainternational.com/t/bug-with-the-export-to-vtk-of-flac3d/2238/2 "2025-09-24T15:46:16Z")

</div>

**Steps to install VTK for FLAC3D’s embedded Python:**

1. **Open a terminal (Command Prompt).**  
Make sure you have write privileges.

2. **Navigate to the FLAC3D Python path.**  
For example:

3. **Install VTK using pip.**

4. **Restart FLAC3D.**  
The newly installed package should now be available.

These steps are applicable to installing other Python packages.

---

<div class="post-metadata">

**Author:** ![galleon](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.itascainternational.com/galleon/32/765_2.png) [@galleon](https://forum.itascainternational.com/u/galleon)\
**Post date:** [September 25, 2025, 1:52am UTC](https://forum.itascainternational.com/t/bug-with-the-export-to-vtk-of-flac3d/2238/3 "2025-09-25T01:52:43Z")

</div>

I followed the steps, but am I the only one who still can’t get it to work? It won’t save a VTU file in XML format.

---

<div class="post-metadata">

**Author:** ![stephaneBeaussier](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@stephaneBeaussier](https://forum.itascainternational.com/u/stephaneBeaussier)\
**Post date:** [September 25, 2025, 8:35am UTC](https://forum.itascainternational.com/t/bug-with-the-export-to-vtk-of-flac3d/2238/4 "2025-09-25T08:35:26Z")

</div>

Thank you it worked.!

I will post a script to export the results using the vtk library.

A word of warning for other people that comes across this discussion.

Do not install a module using ipython magic within the flac python console like this:

> !pip install vtk

This will either crash FLAC or silently fail. install the python modules outside of FLAC.

---

<div class="post-metadata">

**Author:** ![stephaneBeaussier](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@stephaneBeaussier](https://forum.itascainternational.com/u/stephaneBeaussier)\
**Post date:** [September 25, 2025, 8:43am UTC](https://forum.itascainternational.com/t/bug-with-the-export-to-vtk-of-flac3d/2238/5 "2025-09-25T08:43:12Z")

</div>

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
> 
> def export\_gridpoints\_to\_vtk(filename):
> 
> vtk\_points = vtk.vtkPoints()  
> pts = vtkmodules.util.numpy\_support.numpy\_to\_vtk(it.gridpointarray.pos(), deep=True)  
> vtk\_points.SetData(pts)
> 
> pts\_cloud = vtk.vtkPolyData()  
> pts\_cloud.SetPoints(vtk\_points)
> 
> disp = vtkmodules.util.numpy\_support.numpy\_to\_vtk(it.gridpointarray.disp(), deep=True)  
> disp.SetName(“Displacement”)  
> pts\_cloud.GetPointData().SetScalars(disp)
> 
> # 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:

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/itasca/original/2X/d/dc5d7acf90a24d2c874d0f12884d32161edc8a03.jpeg)

---

<div class="post-metadata">

**Author:** ![stephaneBeaussier](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@stephaneBeaussier](https://forum.itascainternational.com/u/stephaneBeaussier)\
**Post date:** [September 25, 2025, 12:56pm UTC](https://forum.itascainternational.com/t/bug-with-the-export-to-vtk-of-flac3d/2238/6 "2025-09-25T12:56:22Z")

</div>

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.

> import numpy as np
> 
> import itasca as it
> 
> import pyvista as pv
> 
> def export\_zones\_to\_vtk(filename):
> 
> order = [0, 1, 4, 2, 3, 6, 7, 5]  
> pos()  
> celltype = np.full(it.zone.count(), pv.CellType.HEXAHEDRON, dtype = np.uint8)  
> cells = np.hstack((np.ones((it.zone.count(), 1),dtype=np.int64)\*8, it.zonearray.gridpoints()[:, order]))  
> cellsflat = cells.ravel()  
> grid = pv.UnstructuredGrid(cellsflat, celltype, points)
> 
> grid.point\_data[“displacement”] = it.gridpointarray.disp() # gridpoint data  
> grid.cell\_data[“stresses”] = it.zonearray.stress() # zone data
> 
> grid.save(filename)
