How to initialise a Function from data stored in a pvd file


166
views
0
4 months ago by
Hello,

I am developing a reusable flow solver. One feature I need is to (re)start a simulation. Is there a way to initialise a Function/TrialFunction from data previously stored to a Paraview PVD file?

Best regards,

Miguel
Community: FEniCS Project
You can save a Function into an xml file and then read it in again. I dont know how to do it with pvd.
written 4 months ago by Praveen C  

2 Answers


4
4 months ago by
pf4d  
Use HDF5 for saving variables and restarting and XDMF or .pvd for viewing:

from fenics import *

mesh = UnitCubeMesh(2,2,2)
P1   = FunctionSpace(mesh, 'CG', 1)

u    = Function(P1, name='u')
u.interpolate(Expression('pow(x[0],2) + pow(x[1],2) + pow(x[2],2)',
                         degree=2))

f    = HDF5File(mpi_comm_world(), 'f.h5', 'w')

f.write(u, u.name())
f.close()

un   = Function(P1, name=u.name())
f    = HDF5File(mpi_comm_world(), 'f.h5', 'r')

f.read(un, u.name())
f.close()

x = XDMFFile(un.name() + '.xdmf')
x.write(un)
x.close()​
Restarting from the HDF5 file works perfectly, but viewing the XDMF file with ParaView is not working. I get this error upon opening from the terminal:

ERROR: In /build/paraview-arsa8T/paraview-5.0.1+dfsg1/ParaViewCore/ServerImplementation/Core/vtkSIProxy.cxx, line 310
vtkSISourceProxy (0x375a240): Failed to create vtkXdmfReader. Aborting for debugging purposes.​
written 4 months ago by Miguel Goncalves  
Update your Paraview from their website.
written 4 months ago by pf4d  
0
4 months ago by
You defenitely can:

1. Create a function space (or spaces) giving the same mesh and FS properties. You need a .xml file for this containing your previous mesh.
2. Read a .xml file with your flow. You should store the flow to .pvd AND to .xml , and then read the corresponding .xml flow file.

This is my snippet:

	def loadPreviousState(self, Counter):
		PrevState   = Function(self.Vech); 
	
		UbInput = File('BaseFlow/ub_'+str(Counter)+'.xml')

		UbInput >> PrevState

		return PrevState​
Please login to add an answer/comment or follow this question.

Similar posts:
Search »