How to write a XDMF file which has mesh static over time?

Dear all.

I am writing output of a FEM problem to a XDMF file. The mesh does not change over time, only the scalar function being solved for changes over time. But in the XDMF file that fenics is generating, I see that the mesh geometry and topology are being written at every time step to the accompanying H5 file. Is there a way to avoid this?

I opened the XDMF file in Paraview and then used Paraview to export it to another XDMF file. Paraview asks me if the mesh is static over time. I chose yes and it drastically reduces the size of my output file from 1.1 GB to 88 MB!

Update:
I looked at the source code https://bitbucket.org/fenics-project/dolfin/src/2018.1.0/dolfin/io/XDMFFile.cpp. On line 65 and 478, there is a parameter rewrite_function_mesh which seems to control whether the mesh will be rewritten or not. So I added following lines to my Python code:

from dolfin import parameters
parameters.add('rewrite_function_mesh', False)

But I still get a XDMF with repeated mesh making the corresponding H5 file of 1.1 GB size. Does any one know why this did not work as expected?

Thanks in advance,
Amit

I found my answer. I should not manipulate the global parameters dictionary but the parameter dictionary associated with the XDMFFile object as shown below:

import dolfin
file = dolfin.XDMFFile('Test.xdmf')
file.parameters['rewrite_function_mesh'] = False

I found the answer by reading the source code https://bitbucket.org/fenics-project/dolfin/src/2018.1.0/dolfin/io/XDMFFile.h.

2 Likes