dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #18857
Re: python: xml read for vector / std::vector
-----Original Message-----
From: Garth N. Wells [mailto:gnw20@xxxxxxxxx]
Sent: Wed 04.08.2010 19:07
To: johan.hake@xxxxxxxxx
Cc: Riesen Patrick; dolfin@xxxxxxxxxxxxxxxxxxx
Subject: Re: [Dolfin] python: xml read for vector / std::vector
On Wed, 2010-08-04 at 10:03 -0700, Johan Hake wrote:
> On Wednesday August 4 2010 09:28:22 Patrick Riesen wrote:
> > Patrick Riesen wrote:
> > > Johan Hake wrote:
> > >> Patrick!
> > >>
> > >> On Wednesday August 4 2010 09:13:24 Patrick Riesen wrote:
> > >>> hello dolfin developers
> > >>>
> > >>> I write out a std::vector in XML file format from cpp. Can I read the
> > >>> XML file in again in python and construct a numpy array?
> > >>> I know how to do it with a dolfin Vector, but is it possible with a
> > >>> std::vector<double>? I could not figure out the syntax, i tried
> > >>>
> > >>> # this is ok
> > >>> fn = File("data/norm.xml")
> > >>> div_vec = d.Vector()
> > >>> a = n.array((11,1))
> > >>>
> > >>> # fails
> > >>> fn >> a
> > >>> # fails
> > >>> fn >> div_vec.array()
> > >>
> > >> Have you tried:
> > >> fn >> div_vec
> > >> a = div_vec.array()
> > >
> > > yes, that gives the error:
> > > *** Error: Handler stack not empty. Something is wrong!
>
> The format is then different for the Vector XML file and the std::vector file?
>
> > if i write out a dolfin::Vector in xml, it's all fine with:
> >
> > fn = File("data/norm.xml")
> > div_vec = d.Vector()
> > fn >> div_vec
> > a = div_vec.array()
> >
> > but if i write out a std::vector<double> in xml, I can't read it in.
>
> Silly question from a Python user:
>
> How do you write the std::vector to a XML file?
>
You don't ;);
DOLFIN does. It's overloaded in the XMLFile class.
Well, anyway, i thought if dolfin can write out a std::vector to xml via File/XMLFile, pydolfin can also read it in, but obviously not.
it would have been slightly slightly more convenient ;-)
then i'll just use the dolfin Vector to do the job.
regards,
patrick
> A simple hack would be to convert the std::vector to a dolfin::Vector and save
> this to a XML file in C++. Then you can read it in, in PyDOLFIN.
>
That should work.
Garth
> Johan
>
> > regards,
> > patrick
> >
> > >> Johan
> > >>
> > >>> thanks for the help,
> > >>>
> > >>> patrick
> > >>>
> > >>>
> > >>>
> > >>> _______________________________________________
> > >>> Mailing list: https://launchpad.net/~dolfin
> > >>> Post to : dolfin@xxxxxxxxxxxxxxxxxxx
> > >>> Unsubscribe : https://launchpad.net/~dolfin
> > >>> More help : https://help.launchpad.net/ListHelp
> > >
> > > _______________________________________________
> > > Mailing list: https://launchpad.net/~dolfin
> > > Post to : dolfin@xxxxxxxxxxxxxxxxxxx
> > > Unsubscribe : https://launchpad.net/~dolfin
> > > More help : https://help.launchpad.net/ListHelp
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to : dolfin@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dolfin
> More help : https://help.launchpad.net/ListHelp
Follow ups
References