read fields from .xdmf or .h5 as initial conditions


292
views
0
9 months ago by
bin  
I need to read the fields from .xdmf or .h5 file (the previously outputted data) to continue the simulations.
Could anybody has experience on this ?
Community: FEniCS Project

2 Answers


0
9 months ago by
RR  
lets say you have two solution FEniCS-functions E_s_r and E_s_i, defined on the Functionspace V for a certain mesh.
You can export as:

import dolfin as df

def write_h5(var, fname):

f = df.HDF5File(df.mpi_comm_world(), fname, "w")
f.write(var, "/data")
f.close()
df.MPI.barrier(df.mpi_comm_world())


write_h5(E_s_r, 'E_s_r.h5')
write_h5(E_s_i, 'E_s_i.h5')

you can import these as follows:

import dolfin as df

def read_h5(var, fname):

     f = df.HDF5File(df.mpi_comm_world(), fname, "r")
     f.read(var, "/data")
     f.close()

mesh = "yourmesh"
V = "yourFunctionSpace"(mesh)
E_s_r = df.Function(V)
E_s_i = df.Function(V)

read_h5(E_s_r, 'E_s_real.h5')
read_h5(E_s_i, 'E_s_imag.h5')
0
9 months ago by
I use HDF5 for checkpointing and restarting, where restarting involves setting initial conditions as you describe. The discussion here should have all of the info you need, but let us know if you're still stuck: https://www.allanswered.com/post/aqox/#pzew
Please login to add an answer/comment or follow this question.

Similar posts:
Search »