# Vtu or xdmf, How to choose output file format?

**URL:** <https://fenicsproject.discourse.group/t/vtu-or-xdmf-how-to-choose-output-file-format/15107>\
**Category:** I/O\
**Created:** [June 30, 2024, 9:36am UTC](https://fenicsproject.discourse.group/t/vtu-or-xdmf-how-to-choose-output-file-format/15107 "2024-06-30T09:36:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bo-qian](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/bo-qian/32/7080_2.png) [@bo-qian](https://fenicsproject.discourse.group/u/bo-qian)\
**Post date:** [June 30, 2024, 9:36am UTC](https://fenicsproject.discourse.group/t/vtu-or-xdmf-how-to-choose-output-file-format/15107/1 "2024-06-30T09:36:03Z")

</div>

Recently I got a question about output result files, the original output file format which I choose is vtu, but I found that xdmf is more faster than vtu, so I changed the format to xdmf. Then these days I encountered an error when I open xdmf file by using paraview, the situation is paraview would be crashed when I open a xdmf file with much more mesh elements, like 10500 or more. I have never encountered such situation when I using vtu format to output result files.  
So how should I choose, change it back to vtu, or you guys have some nice methods to solve crashing of xdmf?

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [June 30, 2024, 9:39am UTC](https://fenicsproject.discourse.group/t/vtu-or-xdmf-how-to-choose-output-file-format/15107/2 "2024-06-30T09:39:15Z")

</div>

Xdmf is a more scalable format than VTK, and is preferred for large simulations (in legacy dolfin).

For outputting in DOLFINx we currently recommend VTXWriter, as it is scalable and support arbitrary order (discontinuous) Lagrange functions.

As to you error, without a minimal reproducible example, its hard to give you any further guidance.

---

<div class="post-metadata">

**Author:** ![bo-qian](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/bo-qian/32/7080_2.png) [@bo-qian](https://fenicsproject.discourse.group/u/bo-qian)\
**Post date:** [June 30, 2024, 9:45am UTC](https://fenicsproject.discourse.group/t/vtu-or-xdmf-how-to-choose-output-file-format/15107/3 "2024-06-30T09:45:34Z")

</div>

My fenics version is 2019.\*\*, so it is dolfin.

```auto
# Output file
xdmf_file = XDMFFile(Output_directory + "/solution.xdmf")
# file = File(os.path.join(results_directory, "solution.pvd"))
cwr = u_new.split()[0]
cwr.rename('C', 'C')
vwr = v_p_combined.split()[0]
vwr.rename('v', 'v')

# Variables for writing physical stress
stress = Function(SpaceTensor)
stress.rename('stress', 'stress')

print('----- writing the data of initial time step to file -----')
xdmf_file.write(cwr, timeCurrent)
xdmf_file.write(vwr, timeCurrent)
solve(stress_L == stress_R, stress, solver_parameters={'linear_solver': 'mumps'})
xdmf_file.write(stress, timeCurrent)

```

Above is the code of output part, I don’t know if the problem is caused by this part.

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [June 30, 2024, 10:13am UTC](https://fenicsproject.discourse.group/t/vtu-or-xdmf-how-to-choose-output-file-format/15107/4 "2024-06-30T10:13:56Z")

</div>

You should call `xdmf_file.close()` once you are done writing data to file.

Please note that without a reproducible example it’s hard to say whats gone wrong.

---

<div class="post-metadata">

**Author:** ![bo-qian](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/bo-qian/32/7080_2.png) [@bo-qian](https://fenicsproject.discourse.group/u/bo-qian)\
**Post date:** [June 30, 2024, 12:48pm UTC](https://fenicsproject.discourse.group/t/vtu-or-xdmf-how-to-choose-output-file-format/15107/5 "2024-06-30T12:48:22Z")

</div>

You mean that when I finished all of the output processes, I shoud call `xdmf_file.close()`, so it maybe solve the problem. Thank you, I will try it later.
