CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

How to Extract Data at Specific Coordinates in Non-Cubic Meshes Using Python

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 15, 2024, 07:16
Default How to Extract Data at Specific Coordinates in Non-Cubic Meshes Using Python
  #1
New Member
 
Lucas Liu
Join Date: Nov 2023
Posts: 4
Rep Power: 2
1111a1333 is on a distinguished road
Hi everyone,

I'm new to OpenFOAM and currently facing a challenge that I hope to get some guidance on. I am working on a project where I need to extract velocity data (U) at specific coordinates from my simulation results. However, the challenge arises because my mesh is not of a standard cubic form. Instead, it consists of various special shapes, making it difficult to directly use mesh coordinates for data extraction.

I am considering using Python for this task, but I am unsure about the best approach to locate the specific coordinates within my complex mesh and retrieve the corresponding U data. Here are some specifics about my situation:

1. The mesh geometry is complex and does not follow a regular pattern.
2. I have a list of specific coordinates (x, y, z) where I need to find the U data.
3. I am looking for a Python-based solution that can accurately map these coordinates to the mesh and extract the needed data.

I would greatly appreciate any advice, code snippets, or references to tools/libraries within the OpenFOAM ecosystem that could help with this task. Additionally, if anyone has experience with similar challenges or can suggest best practices for dealing with non-cubic meshes in OpenFOAM, I would be very thankful for your insights.

Thank you in advance for your time and help!

Best regards,
1111a1333 is offline   Reply With Quote

Old   February 15, 2024, 17:29
Default
  #2
Member
 
Shravan
Join Date: Mar 2017
Posts: 60
Rep Power: 9
Severus is on a distinguished road
Hello,
If your simulation is already over and you want to extract some data at specific points you can use the "Probe Location" filter in Paraview.
https://docs.paraview.org/en/latest/...ata.html#probe

If you want to automate it you can look at other posts in the forum:Probe location in a script

Now, if you still did not start your simulation you can use the "Probes" functionality in OpenFOAM.
https://doc.cfd.direct/openfoam/user...phs-monitoring
https://www.openfoam.com/documentati...8H_source.html
With this you can specify your required coordinates and your velocity data over time will be printed out. This is the most effective way if you already know what points to probe and you have to do it for many such simulations.

Good luck
Severus is offline   Reply With Quote

Old   February 16, 2024, 07:10
Default
  #3
New Member
 
Lucas Liu
Join Date: Nov 2023
Posts: 4
Rep Power: 2
1111a1333 is on a distinguished road
Quote:
Originally Posted by Severus View Post
Hello,
If your simulation is already over and you want to extract some data at specific points you can use the "Probe Location" filter in Paraview.
https://docs.paraview.org/en/latest/...ata.html#probe

If you want to automate it you can look at other posts in the forum:Probe location in a script

Now, if you still did not start your simulation you can use the "Probes" functionality in OpenFOAM.
https://doc.cfd.direct/openfoam/user...phs-monitoring
https://www.openfoam.com/documentati...8H_source.html
With this you can specify your required coordinates and your velocity data over time will be printed out. This is the most effective way if you already know what points to probe and you have to do it for many such simulations.

Good luck
Hi Severus,

Thank you for your reply. I believe I may not have clearly described my situation earlier. I have already completed my simulation and obtained the results. What I need now is for Python to output the U data in [u, v, w] format when I input the specific simulation time and coordinates. Is it possible?

Thank you once again.
1111a1333 is offline   Reply With Quote

Old   February 16, 2024, 11:52
Default
  #4
Member
 
Shravan
Join Date: Mar 2017
Posts: 60
Rep Power: 9
Severus is on a distinguished road
Hello,
I now understand it better. I think the best way then is to use a Python macro in Paraview
Did you see the code given in this thread?
Probe location in a script

For your case, you have a single file I guess (see the files variable), then add your coordinates similar to how it is shown
HTML Code:
probe.ProbeType.Center = [0,0,0]  # probe location [x,y,z]
I think you should be able to do it if you proceed along these lines

You can then save it as a Python macro and simply run the macro in Paraview.

Since as you mention that the points that you would like to probe are not located at the cell centres, interpolation is needed. So, using Python in Paraview could be a good option and you can let Paraview do the interpolation for you.

Exporting your data directly from OpenFOAM to Python will be really expensive and slow to load. On top of that you also have to do interpolation which might be cumbersome.

Thanks
Severus is offline   Reply With Quote

Old   March 29, 2024, 01:26
Default
  #5
New Member
 
Lucas Liu
Join Date: Nov 2023
Posts: 4
Rep Power: 2
1111a1333 is on a distinguished road
Hi,

Thank you for your response. I've implemented the method you suggested, and it was successful. However, I'm now looking to use my simulation results to train a reinforcement learning model, which requires probing data millions of times at various times and locations. I've found that using macros in Paraview isn't very efficient for this purpose. Do you have any alternative suggestions? Alternatively, is there a way to convert vtk data into a database format that can efficiently output velocity data in the [u, v, w] format when given specific simulation times and coordinates?
1111a1333 is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract data at a specific depth reespanau OpenFOAM Post-Processing 1 May 15, 2023 06:45
How to extract data from a specific layer of the grid? reespanau Main CFD Forum 1 January 10, 2023 21:47
[OpenFOAM] Get cell center coordinates in a python script francois ParaView 2 June 3, 2017 08:20
[General] 2 datas on one plot Akuji ParaView 46 December 1, 2013 14:06
Two-Phase Buoyant Flow Issue Miguel Baritto CFX 4 August 31, 2006 12:02


All times are GMT -4. The time now is 04:27.