# Serializing fenics functions (objects) in HDF5 file

**URL:** <https://fenicsproject.discourse.group/t/serializing-fenics-functions-objects-in-hdf5-file/7601>\
**Category:** Uncategorized\
**Created:** [February 2, 2022, 2:36pm UTC](https://fenicsproject.discourse.group/t/serializing-fenics-functions-objects-in-hdf5-file/7601 "2022-02-02T14:36:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhassani](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@mhassani](https://fenicsproject.discourse.group/u/mhassani)\
**Post date:** [February 2, 2022, 2:36pm UTC](https://fenicsproject.discourse.group/t/serializing-fenics-functions-objects-in-hdf5-file/7601/1 "2022-02-02T14:36:29Z")

</div>

Dear fenics users/developers,  
first I have to say I am not a fenics expert, but I am trying to have a wrapper class to ease creation of mesh, equations, and plotting, etc. Since we want to ship the created C++ objects created by python classes to HPC nodes, it is desirable to serialize these objects in an HDF5 file. I read for example [here](https://fenicsproject.discourse.group/t/saving-to-hdf5-doesnt-work-on-docker-image-of-dolfinadjoint-on-linux/4661), that this can be possible somehow.  
For example:

```auto
mesh = UnitSquareMesh(nx, ny)
V = FunctionSpace(mesh, 'P', 1)

# Define boundary condition
u_D = Expression('1 + x[0]*x[0] + alpha*x[1]*x[1] + beta*t',
                 degree=2, alpha=alpha, beta=beta, t=0)

def boundary(x, on_boundary):
    return on_boundary

bc = DirichletBC(V, u_D, boundary)

# Define initial value
u_n = interpolate(u_D, V)
#u_n = project(u_D, V)

# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(beta - 2 - 2*alpha)

F = u*v*dx + dt*dot(grad(u), grad(v))*dx - (u_n + dt*f)*v*dx

```

and I am interested to serialize u, v, f, F, BC, u\_n into a HDF5 file. Is this possible?  
I would be grateful for any guidance. Thank you.
