# the .vtu file to be generated is too big

**URL:** https://discourse.vtk.org/t/the-vtu-file-to-be-generated-is-too-big/11290
**Category:** Support
**Tags:** python, code
**Created:** [April 25, 2023, 3:05am UTC](https://discourse.vtk.org/t/the-vtu-file-to-be-generated-is-too-big/11290 "2023-04-25T03:05:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![meng\_deng](https://discourse.vtk.org/user_avatar/discourse.vtk.org/meng_deng/32/6979_2.png) [@meng\_deng](https://discourse.vtk.org/u/meng_deng)
#### Post date: [April 25, 2023, 3:05am UTC](https://discourse.vtk.org/t/the-vtu-file-to-be-generated-is-too-big/11290/1 "2023-04-25T03:05:20Z")

</div>

I tried to use points and cell values to generate a hexahedral mesh with Python. But the final file was too large to store(\>40 GB, ) and the program crashed, size of the data is 164640(56 \* 60 \* 49).  
[data.rar](https://discourse.vtk.org/uploads/short-url/tjaVZppzNcWmuHISNupAWoErOLH.rar) (882.1 KB)

```auto
import vtk
# define the dimensions of the grid
size_nx = int(57)
size_ny = int(61)
size_nz = int(50)
#define the grid
grid = vtk.vtkUnstructuredGrid()

values = vtk.vtkFloatArray()
points = vtk.vtkPoints()
#set the dimensions of the grid
# grid.SetDimensions(size_nx, size_ny, size_nz)

coor3d = open('coor3d.txt', 'r')
res = open('res.txt', 'r')

points.SetDataTypeToFloat()
for k in range(size_nx * size_ny * size_nz):
    lines = coor3d.readline().split(" ")
    x_coor = float(lines[0])
    y_coor = float(lines[2])
    z_coor = float(lines[4])
    points.InsertNextPoint(x_coor, y_coor, z_coor)
grid.SetPoints(points)

n_p = points.GetNumberOfPoints()
print(f"num of points {n_p}")

#
nx = size_nx-1
ny = size_ny-1
nz = size_nz-1

for i in range(nx* ny * nz):
    # poisition of the 8 vertices of the hexahedron
    v1 = int(i % nx)
    v2 = int((i / nx) % ny)
    v3 = int(i / (nx * ny))

    hex = vtk.vtkHexahedron()
    hex.GetPointIds().SetId(0, v1 + v2 * size_nx + v3 * size_nx * size_ny)
    hex.GetPointIds().SetId(1, v1 + v2 * size_nx + v3 * size_nx * size_ny + 1)
    hex.GetPointIds().SetId(2, v1 + v2 * size_nx + v3 * size_nx * size_ny + size_nx + 1)
    hex.GetPointIds().SetId(3, v1 + v2 * size_nx + v3 * size_nx * size_ny + size_nx)
    hex.GetPointIds().SetId(4, v1 + v2 * size_nx + v3 * size_nx * size_ny + size_nx * size_ny)
    hex.GetPointIds().SetId(5, v1 + v2 * size_nx + v3 * size_nx * size_ny + size_nx * size_ny + 1)
    hex.GetPointIds().SetId(6, v1 + v2 * size_nx + v3 * size_nx * size_ny + size_nx * size_ny + size_nx + 1)
    hex.GetPointIds().SetId(7, v1 + v2 * size_nx + v3 * size_nx * size_ny + size_nx * size_ny + size_nx)
    if range(0,nx* ny * nz+1,34770).count(i):
        print(f"{i*100/(nx* ny * nz):.2f}%")
    grid.InsertNextCell(hex.GetCellType(), hex.GetPointIds())
    value = res.readline().split("\n") # set value
    values.InsertNextValue(float(value[0]))
    grid.GetCellData().AddArray(values)
    
res.close()
coor3d.close()    
writer = vtk.vtkXMLUnstructuredGridWriter()
writer.SetFileName("output_res.vtu") # set the file name
writer.SetInputData(grid) # set the grid as input
writer.SetDataModeToBinary()
writer.Write() # write the file

```

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [April 25, 2023, 10:26pm UTC](https://discourse.vtk.org/t/the-vtu-file-to-be-generated-is-too-big/11290/2 "2023-04-25T22:26:13Z")

</div>

Hello,

I’d put the following line outside the loop:

> [@meng\_deng](#):
>
> `grid.GetCellData().AddArray(values)`

I believe you’re adding 164640 data arrays to your grid hence the size of file and crash. 164640 \* 4 (size of float) \* 164640 ~ 100GB.

take care,

PC

---

<div class="post-metadata">

### Author: ![meng\_deng](https://discourse.vtk.org/user_avatar/discourse.vtk.org/meng_deng/32/6979_2.png) [@meng\_deng](https://discourse.vtk.org/u/meng_deng)
#### Post date: [April 26, 2023, 6:57pm UTC](https://discourse.vtk.org/t/the-vtu-file-to-be-generated-is-too-big/11290/3 "2023-04-26T18:57:22Z")

</div>

yes, you are right.  
thank you, Paulo!
