Importing lagrangian data from openfoam into numpy arrays

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Importing lagrangian data from openfoam into numpy arrays

Victor Koppejan - TNW
Hi Everyone,

I'd like to import data from openfoam lagrangian particle (saved as binary or ascii vtk files) in simulations into numpy-arrays. The data is either in scalar or vector format. I can't find what I want in the examples or other online tutorials. Does anyone have a suggestion can you refer me to online material?

The data is stored as polydata, see a short version of the file (in this case ascii) contents below:

# vtk DataFile Version 2.0
linkCG2-500cmh-run1
ASCII
DATASET POLYDATA
POINTS 187550 float
<lots of points>
POINT_DATA 187550
FIELD attributes 8
origId 1 187550 float
<lots of points>
lmpCpuId 1 187550 float
<lots of points>

etc., here origId and lmpCpuId are scalar variables, after this there's 8 more variables. I can read it all in in matlab but I've been trying to move all my computations to python.

Thanks in advance for your help.

Kind regards,

Victor
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Importing lagrangian data from openfoam into numpy arrays

Paul Melis
Hi Victor,

Perhaps this series of blog posts on VTK+numpy integration can help you
further? I haven't used that stuff too much myself, but I believe you
should be able to use VTK's numpy adapters to get all your data as numpy
arrays:

https://blog.kitware.com/improved-vtk-numpy-integration/

Regards,
Paul

On 29-03-17 13:55, Victor Koppejan - TNW wrote:

> Hi Everyone,
>
> I'd like to import data from openfoam lagrangian particle (saved as binary or ascii vtk files) in simulations into numpy-arrays. The data is either in scalar or vector format. I can't find what I want in the examples or other online tutorials. Does anyone have a suggestion can you refer me to online material?
>
> The data is stored as polydata, see a short version of the file (in this case ascii) contents below:
>
> # vtk DataFile Version 2.0
> linkCG2-500cmh-run1
> ASCII
> DATASET POLYDATA
> POINTS 187550 float
> <lots of points>
> POINT_DATA 187550
> FIELD attributes 8
> origId 1 187550 float
> <lots of points>
> lmpCpuId 1 187550 float
> <lots of points>
>
> etc., here origId and lmpCpuId are scalar variables, after this there's 8 more variables. I can read it all in in matlab but I've been trying to move all my computations to python.
>
> Thanks in advance for your help.
>
> Kind regards,
>
> Victor
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>


--

Paul Melis
| Visualization group leader & developer | SURFsara |
| Science Park 140 | 1098 XG Amsterdam |
| T 020 800 1312 | [hidden email] | www.surfsara.nl |
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Importing lagrangian data from openfoam into numpy arrays

Cory Quammen-2
Victor,

To read in your file with VTK+Python, use

import vtk
reader = vtk.vtkPolyDataReader()
reader.SetFileName("myfile.vtk")
reader.Update()

Then, to convert your point data to numpy arrays, use

from vtk.numpy_interface import dataset_adapter as dsa
mydata = dsa.WrapDataObject(reader.GetOutput())
origId = mydata.PointData['origId']
ImpCpuId = mydata.PointData['lmpCpuId']

`oridId` and `ImpCpuId` are now NumPy-like arrays you can use like you
would NumPy arrays.

Paul's suggestion at looking at the blog posts for more comprehensive
information is a good one.

HTH,
Cory


On Thu, Mar 30, 2017 at 4:13 AM, Paul Melis <[hidden email]> wrote:

> Hi Victor,
>
> Perhaps this series of blog posts on VTK+numpy integration can help you
> further? I haven't used that stuff too much myself, but I believe you should
> be able to use VTK's numpy adapters to get all your data as numpy arrays:
>
> https://blog.kitware.com/improved-vtk-numpy-integration/
>
> Regards,
> Paul
>
>
> On 29-03-17 13:55, Victor Koppejan - TNW wrote:
>>
>> Hi Everyone,
>>
>> I'd like to import data from openfoam lagrangian particle (saved as binary
>> or ascii vtk files) in simulations into numpy-arrays. The data is either in
>> scalar or vector format. I can't find what I want in the examples or other
>> online tutorials. Does anyone have a suggestion can you refer me to online
>> material?
>>
>> The data is stored as polydata, see a short version of the file (in this
>> case ascii) contents below:
>>
>> # vtk DataFile Version 2.0
>> linkCG2-500cmh-run1
>> ASCII
>> DATASET POLYDATA
>> POINTS 187550 float
>> <lots of points>
>> POINT_DATA 187550
>> FIELD attributes 8
>> origId 1 187550 float
>> <lots of points>
>> lmpCpuId 1 187550 float
>> <lots of points>
>>
>> etc., here origId and lmpCpuId are scalar variables, after this there's 8
>> more variables. I can read it all in in matlab but I've been trying to move
>> all my computations to python.
>>
>> Thanks in advance for your help.
>>
>> Kind regards,
>>
>> Victor
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>>
>
>
> --
>
> Paul Melis
> | Visualization group leader & developer | SURFsara |
> | Science Park 140 | 1098 XG Amsterdam |
> | T 020 800 1312 | [hidden email] | www.surfsara.nl |
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers



--
Cory Quammen
Staff R&D Engineer
Kitware, Inc.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Loading...