reading nodal data from XML file

Asked by Siva Shankar Rudraraju

I am interested in having some restart capability in my script. Essentially, I need to be able to load my last converged nodal displacement solution from an XML file, and use this as the initial solution state for future load increments..... this is required as my multifield problem at times diverges, and I don't want to start again from the first load increment.

demo.py in pde/advection-diffusion/ has:
V = VectorFunctionSpace(mesh, "CG", 2)
velocity = Function(V, "../velocity.xml.gz");

But I would prefer the following:
V = VectorFunctionSpace(mesh, "CG", 2)

And at every restart point:
input= File("../velocity.xml.gz");
input >> V;

but this returns:
TypeError: in method 'File___rshift__', argument 2 of type 'dolfin::FunctionPlotData &'

So is there a way to initialize a scalar/vector nodal field from a XML file?

--shiva

Question information

Language:
English Edit question
Status:
Answered
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Anders Logg (logg) said :
#1

On Wed, Sep 01, 2010 at 05:17:25PM -0000, Siva Shankar Rudraraju wrote:
> New question #123668 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/123668
>
> I am interested in having some restart capability in my script. Essentially, I need to be able to load my last converged nodal displacement solution from an XML file, and use this as the initial solution state for future load increments..... this is required as my multifield problem at times diverges, and I don't want to start again from the first load increment.
>
> demo.py in pde/advection-diffusion/ has:
> V = VectorFunctionSpace(mesh, "CG", 2)
> velocity = Function(V, "../velocity.xml.gz");
>
> But I would prefer the following:
> V = VectorFunctionSpace(mesh, "CG", 2)
>
> And at every restart point:
> input= File("../velocity.xml.gz");
> input >> V;
>
> but this returns:
> TypeError: in method 'File___rshift__', argument 2 of type 'dolfin::FunctionPlotData &'
>
> So is there a way to initialize a scalar/vector nodal field from a XML file?
>
> --shiva

You need to read/write the vector, not the function or the mesh:

# First
f = File("vector.xml")
f << u.vector()

# Then
f >> u.vector()

--
Anders

Revision history for this message
Siva Shankar Rudraraju (rudraa) said :
#2

f << u.vector() & f >> u.vector() work as expected for single processor runs.

But with mpi runs, f << u.vector() writes .xml file with only the part of the solution vector corresponding to one of the processors, i.e, I have 8600 DOF, but for mpirun with 4 processors the single xml file written out has only 8600/4=2150 DOF values.

Any suggestions on getting f << u.vector() & f >> u.vector() to work properly on multiple processors?.

Revision history for this message
Garth Wells (garth-wells) said :
#3

Which version of DOLFIN are you using? I worked on this recently, so output of vectors to XML files should work in DOLFIN 0.9.9. Update to 0.9.9 if you're using an earlier version.

Can you help with this problem?

Provide an answer of your own, or ask Siva Shankar Rudraraju for more information if necessary.

To post a message you must log in.