how to read out data array from unstructured mesh (advection-diffusion demo)

Asked by JJ Jiang

Hi all,
  I am running into a problem. I run the advection-diffusion demo. All the simulated mass transport quantities u were save to a vtk PVD file with an unstructured mesh.

My question is how to read out the u from the associated individual vtu files. I thought the u is attached to either PointData or CellData so that I can read out the scalar u using one of the following:
grid->GetPointData()->GetArray('name');
or
grid->GetCellData()->GetArray('name');

But my attempts have failed. Please provide your advice. Thanks so much for your help!

Best regards,
--JJ

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
Kent-Andre Mardal (kent-and) said :
#1

You should be able to use GetPointData().GetArray(). Have you looked at the
name of the variable in the vtu file? It is in ASCII format.

I attach something I did earlier.

Kent

On 4 March 2011 19:34, JJ Jiang <email address hidden>wrote:

> New question #147820 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/147820
>
> Hi all,
> I am running into a problem. I run the advection-diffusion demo. All the
> simulated mass transport quantities u were save to a vtk PVD file with an
> unstructured mesh.
>
> My question is how to read out the u from the associated individual vtu
> files. I thought the u is attached to either PointData or CellData so that
> I can read out the scalar u using one of the following:
> grid->GetPointData()->GetArray('name');
> or
> grid->GetCellData()->GetArray('name');
>
> But my attempts have failed. Please provide your advice. Thanks so much for
> your help!
>
> Best regards,
> --JJ
>
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~dolfin
> More help : https://help.launchpad.net/ListHelp
>

Revision history for this message
Johan Hake (johan-hake) said :
#2

Maybe Viper could provide a high level interface to read a vtu file into a
NumPy array, and a mesh into a coordinate and cell arrays?

Then we eventually can use this to pass data to Viper for plotting in the C++
interface. This might fix the parallel ploting issue we have.

It would also be cool to implement a helper function in the Python interface
of DOLFIN that uses the potential added functionality in Viper to generate a
Function, with or without a given mesh. A FunctionSpace could be automatically
generated based on the dimensions of the data (is this true?) If a mesh is not
given we generate it based on the stored mesh data from the file.

Johan

On Friday March 4 2011 11:30:52 Kent-Andre Mardal wrote:
> Question #147820 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/147820
>
> Status: Open => Answered
>
> Kent-Andre Mardal proposed the following answer:
> You should be able to use GetPointData().GetArray(). Have you looked at the
> name of the variable in the vtu file? It is in ASCII format.
>
> I attach something I did earlier.
>
> Kent
>
> On 4 March 2011 19:34, JJ Jiang
>
> <email address hidden>wrote:
> > New question #147820 on DOLFIN:
> > https://answers.launchpad.net/dolfin/+question/147820
> >
> > Hi all,
> >
> > I am running into a problem. I run the advection-diffusion demo. All the
> >
> > simulated mass transport quantities u were save to a vtk PVD file with an
> > unstructured mesh.
> >
> > My question is how to read out the u from the associated individual vtu
> > files. I thought the u is attached to either PointData or CellData so
> > that I can read out the scalar u using one of the following:
> > grid->GetPointData()->GetArray('name');
> > or
> > grid->GetCellData()->GetArray('name');
> >
> > But my attempts have failed. Please provide your advice. Thanks so much
> > for your help!
> >
> > Best regards,
> > --JJ
> >
> >
> > --
> > You received this question notification because you are a member of
> > DOLFIN Team, which is an answer contact for DOLFIN.
> >
> > _______________________________________________
> > Mailing list: https://launchpad.net/~dolfin
> > Post to : <email address hidden>
> > Unsubscribe : https://launchpad.net/~dolfin
> > More help : https://help.launchpad.net/ListHelp

Revision history for this message
JJ Jiang (jjiang2) said :
#3

Hi Johan and Kevin,
   Thanks for the notes. I think you can dump simulated temperature or mass to raw files. That can be manipulated when the mesh data are also given either in a vtu format or in a raw format.
   By the way, I used Paraview to see the simulated "temperature" scalar has been attached to a vtu. Surprisingly, I couldn't read it out by its name. I don't know why.
   I guess Johan's suggestions will give users more flexibilities to handle the data.
   Thanks again to both of you.
Best regards,
--JJ

On 03/04/11, Johan Hake wrote:
> Your question #147820 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/147820
>
> Johan Hake proposed the following answer:
> Maybe Viper could provide a high level interface to read a vtu file into a
> NumPy array, and a mesh into a coordinate and cell arrays?
>
> Then we eventually can use this to pass data to Viper for plotting in the C++
> interface. This might fix the parallel ploting issue we have.
>
> It would also be cool to implement a helper function in the Python interface
> of DOLFIN that uses the potential added functionality in Viper to generate a
> Function, with or without a given mesh. A FunctionSpace could be automatically
> generated based on the dimensions of the data (is this true?) If a mesh is not
> given we generate it based on the stored mesh data from the file.
>
> Johan
>
>
> On Friday March 4 2011 11:30:52 Kent-Andre Mardal wrote:
> > Question #147820 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/147820
> >
> > Status: Open => Answered
> >
> > Kent-Andre Mardal proposed the following answer:
> > You should be able to use GetPointData().GetArray(). Have you looked at the
> > name of the variable in the vtu file? It is in ASCII format.
> >
> > I attach something I did earlier.
> >
> > Kent
> >
> > On 4 March 2011 19:34, JJ Jiang
> >
> > <email address hidden>wrote:
> > > New question #147820 on DOLFIN:
> > > https://answers.launchpad.net/dolfin/+question/147820
> > >
> > > Hi all,
> > >
> > > I am running into a problem. I run the advection-diffusion demo. All the
> > >
> > > simulated mass transport quantities u were save to a vtk PVD file with an
> > > unstructured mesh.
> > >
> > > My question is how to read out the u from the associated individual vtu
> > > files. I thought the u is attached to either PointData or CellData so
> > > that I can read out the scalar u using one of the following:
> > > grid->GetPointData()->GetArray('name');
> > > or
> > > grid->GetCellData()->GetArray('name');
> > >
> > > But my attempts have failed. Please provide your advice. Thanks so much
> > > for your help!
> > >
> > > Best regards,
> > > --JJ
> > >
> > >
> > > --
> > > You received this question notification because you are a member of
> > > DOLFIN Team, which is an answer contact for DOLFIN.
> > >
> > > _______________________________________________
> > > Mailing list: https://launchpad.net/~dolfin
> > > Post to : <email address hidden>
> > > Unsubscribe : https://launchpad.net/~dolfin
> > > More help : https://help.launchpad.net/ListHelp
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/dolfin/+question/147820/+confirm?answer_id=1
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/dolfin/+question/147820
>
> You received this question notification because you are a direct
> subscriber of the question.

--
+++++++++++++++++++++++++++++++++++
Jingfeng Jiang (JJ)
University of Wisconsin
Medical Physics Department
1530 Medical Sciences Center
1300 University Avenue
Madison, WI 53706
Phone: (608) 262-4197
FAX: (608) 262-2413
+++++++++++++++++++++++++++++++++++

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

The ParaView/VTK format is for post-processing, and not for saving data for later re-use. Solution data is not attached to meshes.

To save a solution to file for later use, the vector associated with a Function should be saved to an XML file, e.g.

    File("u_vector.xml") << u.vector()

Revision history for this message
Kent-Andre Mardal (kent-and) said :
#5

Could you send be the file ?

Kent

On 4 March 2011 21:30, JJ Jiang <email address hidden>wrote:

> Question #147820 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/147820
>
> Status: Answered => Open
>
> JJ Jiang is still having a problem:
> Hi Johan and Kevin,
> Thanks for the notes. I think you can dump simulated temperature or mass
> to raw files. That can be manipulated when the mesh data are also given
> either in a vtu format or in a raw format.
> By the way, I used Paraview to see the simulated "temperature" scalar
> has been attached to a vtu. Surprisingly, I couldn't read it out by its
> name. I don't know why.
> I guess Johan's suggestions will give users more flexibilities to handle
> the data.
> Thanks again to both of you.
> Best regards,
> --JJ
>
> On 03/04/11, Johan Hake wrote:
> > Your question #147820 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/147820
> >
> > Johan Hake proposed the following answer:
> > Maybe Viper could provide a high level interface to read a vtu file into
> a
> > NumPy array, and a mesh into a coordinate and cell arrays?
> >
> > Then we eventually can use this to pass data to Viper for plotting in the
> C++
> > interface. This might fix the parallel ploting issue we have.
> >
> > It would also be cool to implement a helper function in the Python
> interface
> > of DOLFIN that uses the potential added functionality in Viper to
> generate a
> > Function, with or without a given mesh. A FunctionSpace could be
> automatically
> > generated based on the dimensions of the data (is this true?) If a mesh
> is not
> > given we generate it based on the stored mesh data from the file.
> >
> > Johan
> >
> >
> > On Friday March 4 2011 11:30:52 Kent-Andre Mardal wrote:
> > > Question #147820 on DOLFIN changed:
> > > https://answers.launchpad.net/dolfin/+question/147820
> > >
> > > Status: Open => Answered
> > >
> > > Kent-Andre Mardal proposed the following answer:
> > > You should be able to use GetPointData().GetArray(). Have you looked at
> the
> > > name of the variable in the vtu file? It is in ASCII format.
> > >
> > > I attach something I did earlier.
> > >
> > > Kent
> > >
> > > On 4 March 2011 19:34, JJ Jiang
> > >
> > > <email address hidden>wrote:
> > > > New question #147820 on DOLFIN:
> > > > https://answers.launchpad.net/dolfin/+question/147820
> > > >
> > > > Hi all,
> > > >
> > > > I am running into a problem. I run the advection-diffusion demo. All
> the
> > > >
> > > > simulated mass transport quantities u were save to a vtk PVD file
> with an
> > > > unstructured mesh.
> > > >
> > > > My question is how to read out the u from the associated individual
> vtu
> > > > files. I thought the u is attached to either PointData or CellData
> so
> > > > that I can read out the scalar u using one of the following:
> > > > grid->GetPointData()->GetArray('name');
> > > > or
> > > > grid->GetCellData()->GetArray('name');
> > > >
> > > > But my attempts have failed. Please provide your advice. Thanks so
> much
> > > > for your help!
> > > >
> > > > Best regards,
> > > > --JJ
> > > >
> > > >
> > > > --
> > > > You received this question notification because you are a member of
> > > > DOLFIN Team, which is an answer contact for DOLFIN.
> > > >
> > > > _______________________________________________
> > > > Mailing list: https://launchpad.net/~dolfin
> > > > Post to : <email address hidden>
> > > > Unsubscribe : https://launchpad.net/~dolfin
> > > > More help : https://help.launchpad.net/ListHelp
> >
> > --
> > If this answers your question, please go to the following page to let us
> > know that it is solved:
> >
> https://answers.launchpad.net/dolfin/+question/147820/+confirm?answer_id=1
> >
> > If you still need help, you can reply to this email or go to the
> > following page to enter your feedback:
> > https://answers.launchpad.net/dolfin/+question/147820
> >
> > You received this question notification because you are a direct
> > subscriber of the question.
>
> --
> +++++++++++++++++++++++++++++++++++
> Jingfeng Jiang (JJ)
> University of Wisconsin
> Medical Physics Department
> 1530 Medical Sciences Center
> 1300 University Avenue
> Madison, WI 53706
> Phone: (608) 262-4197
> FAX: (608) 262-2413
> +++++++++++++++++++++++++++++++++++
>
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~dolfin
> More help : https://help.launchpad.net/ListHelp
>

Revision history for this message
Patrick Riesen (priesen) said :
#6

in python, I use this to read in a vtu file to an array:
this doesn't need the GetArray("name")

# -------------------------------------------------
import vtk as v
from enthought.tvtk import array_handler as ah

datareader = v.vtkXMLUnstructuredGridReader()
datareader.SetFileName(filename)
datareader.Update()

data = datareader.GetOutput()
# if you have a vector (e.g. velocity):
vtk_values = data.GetPointData().GetVectors()
# if you have a scalar:
# vtk_values = data.GetPointData().GetScalars()

# this is convenient to convert vtkarrays to numpy arrays
solution = ah.vtk2array(data)
# ------------------------------------------------------

regards,
patrick

On 03/04/2011 09:30 PM, JJ Jiang wrote:
> Question #147820 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/147820
>
> Status: Answered => Open
>
> JJ Jiang is still having a problem:
> Hi Johan and Kevin,
> Thanks for the notes. I think you can dump simulated temperature or mass to raw files. That can be manipulated when the mesh data are also given either in a vtu format or in a raw format.
> By the way, I used Paraview to see the simulated "temperature" scalar has been attached to a vtu. Surprisingly, I couldn't read it out by its name. I don't know why.
> I guess Johan's suggestions will give users more flexibilities to handle the data.
> Thanks again to both of you.
> Best regards,
> --JJ
>
> On 03/04/11, Johan Hake wrote:
>> Your question #147820 on DOLFIN changed:
>> https://answers.launchpad.net/dolfin/+question/147820
>>
>> Johan Hake proposed the following answer:
>> Maybe Viper could provide a high level interface to read a vtu file into a
>> NumPy array, and a mesh into a coordinate and cell arrays?
>>
>> Then we eventually can use this to pass data to Viper for plotting in the C++
>> interface. This might fix the parallel ploting issue we have.
>>
>> It would also be cool to implement a helper function in the Python interface
>> of DOLFIN that uses the potential added functionality in Viper to generate a
>> Function, with or without a given mesh. A FunctionSpace could be automatically
>> generated based on the dimensions of the data (is this true?) If a mesh is not
>> given we generate it based on the stored mesh data from the file.
>>
>> Johan
>>
>>
>> On Friday March 4 2011 11:30:52 Kent-Andre Mardal wrote:
>>> Question #147820 on DOLFIN changed:
>>> https://answers.launchpad.net/dolfin/+question/147820
>>>
>>> Status: Open => Answered
>>>
>>> Kent-Andre Mardal proposed the following answer:
>>> You should be able to use GetPointData().GetArray(). Have you looked at the
>>> name of the variable in the vtu file? It is in ASCII format.
>>>
>>> I attach something I did earlier.
>>>
>>> Kent
>>>
>>> On 4 March 2011 19:34, JJ Jiang
>>>
>>> <email address hidden>wrote:
>>>> New question #147820 on DOLFIN:
>>>> https://answers.launchpad.net/dolfin/+question/147820
>>>>
>>>> Hi all,
>>>>
>>>> I am running into a problem. I run the advection-diffusion demo. All the
>>>>
>>>> simulated mass transport quantities u were save to a vtk PVD file with an
>>>> unstructured mesh.
>>>>
>>>> My question is how to read out the u from the associated individual vtu
>>>> files. I thought the u is attached to either PointData or CellData so
>>>> that I can read out the scalar u using one of the following:
>>>> grid->GetPointData()->GetArray('name');
>>>> or
>>>> grid->GetCellData()->GetArray('name');
>>>>
>>>> But my attempts have failed. Please provide your advice. Thanks so much
>>>> for your help!
>>>>
>>>> Best regards,
>>>> --JJ
>>>>
>>>>
>>>> --
>>>> You received this question notification because you are a member of
>>>> DOLFIN Team, which is an answer contact for DOLFIN.
>>>>
>>>> _______________________________________________
>>>> Mailing list: https://launchpad.net/~dolfin
>>>> Post to : <email address hidden>
>>>> Unsubscribe : https://launchpad.net/~dolfin
>>>> More help : https://help.launchpad.net/ListHelp
>>
>> --
>> If this answers your question, please go to the following page to let us
>> know that it is solved:
>> https://answers.launchpad.net/dolfin/+question/147820/+confirm?answer_id=1
>>
>> If you still need help, you can reply to this email or go to the
>> following page to enter your feedback:
>> https://answers.launchpad.net/dolfin/+question/147820
>>
>> You received this question notification because you are a direct
>> subscriber of the question.
>
> --
> +++++++++++++++++++++++++++++++++++
> Jingfeng Jiang (JJ)
> University of Wisconsin
> Medical Physics Department
> 1530 Medical Sciences Center
> 1300 University Avenue
> Madison, WI 53706
> Phone: (608) 262-4197
> FAX: (608) 262-2413
> +++++++++++++++++++++++++++++++++++
>
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~dolfin
> More help : https://help.launchpad.net/ListHelp

Revision history for this message
Patrick Riesen (priesen) said :
#7

i'm sorry, the last line should be:
solution = ah.vtk2array(vtk_values)

patrick

On 03/07/2011 09:16 AM, Patrick Riesen wrote:
> in python, I use this to read in a vtu file to an array:
> this doesn't need the GetArray("name")
>
> # -------------------------------------------------
> import vtk as v
> from enthought.tvtk import array_handler as ah
>
> datareader = v.vtkXMLUnstructuredGridReader()
> datareader.SetFileName(filename)
> datareader.Update()
>
> data = datareader.GetOutput()
> # if you have a vector (e.g. velocity):
> vtk_values = data.GetPointData().GetVectors()
> # if you have a scalar:
> # vtk_values = data.GetPointData().GetScalars()
>
> # this is convenient to convert vtkarrays to numpy arrays
> solution = ah.vtk2array(data)
> # ------------------------------------------------------
>
>
> regards,
> patrick
>
>
> On 03/04/2011 09:30 PM, JJ Jiang wrote:
>> Question #147820 on DOLFIN changed:
>> https://answers.launchpad.net/dolfin/+question/147820
>>
>> Status: Answered => Open
>>
>> JJ Jiang is still having a problem:
>> Hi Johan and Kevin,
>> Thanks for the notes. I think you can dump simulated temperature or
>> mass to raw files. That can be manipulated when the mesh data are also
>> given either in a vtu format or in a raw format.
>> By the way, I used Paraview to see the simulated "temperature" scalar
>> has been attached to a vtu. Surprisingly, I couldn't read it out by
>> its name. I don't know why.
>> I guess Johan's suggestions will give users more flexibilities to
>> handle the data.
>> Thanks again to both of you.
>> Best regards,
>> --JJ
>>
>> On 03/04/11, Johan Hake wrote:
>>> Your question #147820 on DOLFIN changed:
>>> https://answers.launchpad.net/dolfin/+question/147820
>>>
>>> Johan Hake proposed the following answer:
>>> Maybe Viper could provide a high level interface to read a vtu file
>>> into a
>>> NumPy array, and a mesh into a coordinate and cell arrays?
>>>
>>> Then we eventually can use this to pass data to Viper for plotting in
>>> the C++
>>> interface. This might fix the parallel ploting issue we have.
>>>
>>> It would also be cool to implement a helper function in the Python
>>> interface
>>> of DOLFIN that uses the potential added functionality in Viper to
>>> generate a
>>> Function, with or without a given mesh. A FunctionSpace could be
>>> automatically
>>> generated based on the dimensions of the data (is this true?) If a
>>> mesh is not
>>> given we generate it based on the stored mesh data from the file.
>>>
>>> Johan
>>>
>>>
>>> On Friday March 4 2011 11:30:52 Kent-Andre Mardal wrote:
>>>> Question #147820 on DOLFIN changed:
>>>> https://answers.launchpad.net/dolfin/+question/147820
>>>>
>>>> Status: Open => Answered
>>>>
>>>> Kent-Andre Mardal proposed the following answer:
>>>> You should be able to use GetPointData().GetArray(). Have you looked
>>>> at the
>>>> name of the variable in the vtu file? It is in ASCII format.
>>>>
>>>> I attach something I did earlier.
>>>>
>>>> Kent
>>>>
>>>> On 4 March 2011 19:34, JJ Jiang
>>>>
>>>> <email address hidden>wrote:
>>>>> New question #147820 on DOLFIN:
>>>>> https://answers.launchpad.net/dolfin/+question/147820
>>>>>
>>>>> Hi all,
>>>>>
>>>>> I am running into a problem. I run the advection-diffusion demo.
>>>>> All the
>>>>>
>>>>> simulated mass transport quantities u were save to a vtk PVD file
>>>>> with an
>>>>> unstructured mesh.
>>>>>
>>>>> My question is how to read out the u from the associated individual
>>>>> vtu
>>>>> files. I thought the u is attached to either PointData or CellData so
>>>>> that I can read out the scalar u using one of the following:
>>>>> grid->GetPointData()->GetArray('name');
>>>>> or
>>>>> grid->GetCellData()->GetArray('name');
>>>>>
>>>>> But my attempts have failed. Please provide your advice. Thanks so
>>>>> much
>>>>> for your help!
>>>>>
>>>>> Best regards,
>>>>> --JJ
>>>>>
>>>>>
>>>>> --
>>>>> You received this question notification because you are a member of
>>>>> DOLFIN Team, which is an answer contact for DOLFIN.
>>>>>
>>>>> _______________________________________________
>>>>> Mailing list: https://launchpad.net/~dolfin
>>>>> Post to : <email address hidden>
>>>>> Unsubscribe : https://launchpad.net/~dolfin
>>>>> More help : https://help.launchpad.net/ListHelp
>>>
>>> --
>>> If this answers your question, please go to the following page to let us
>>> know that it is solved:
>>> https://answers.launchpad.net/dolfin/+question/147820/+confirm?answer_id=1
>>>
>>>
>>> If you still need help, you can reply to this email or go to the
>>> following page to enter your feedback:
>>> https://answers.launchpad.net/dolfin/+question/147820
>>>
>>> You received this question notification because you are a direct
>>> subscriber of the question.
>>
>> --
>> +++++++++++++++++++++++++++++++++++
>> Jingfeng Jiang (JJ)
>> University of Wisconsin
>> Medical Physics Department
>> 1530 Medical Sciences Center
>> 1300 University Avenue
>> Madison, WI 53706
>> Phone: (608) 262-4197
>> FAX: (608) 262-2413
>> +++++++++++++++++++++++++++++++++++
>>
>> You received this question notification because you are a member of
>> DOLFIN Team, which is an answer contact for DOLFIN.
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~dolfin
>> Post to : <email address hidden>
>> Unsubscribe : https://launchpad.net/~dolfin
>> More help : https://help.launchpad.net/ListHelp
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~dolfin
> More help : https://help.launchpad.net/ListHelp

Revision history for this message
Nico Schlömer (nschloe) said :
#8

meshio [1] (a side project of mine) can also read VTK files and isn't as massive as a dependency. Perhaps worthwhile checking out for your vtk i/o needs.

[1] https://github.com/nschloe/meshio

Can you help with this problem?

Provide an answer of your own, or ask JJ Jiang for more information if necessary.

To post a message you must log in.