CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How to Extract Data at Specific Coordinates in Non-Cubic Meshes Using Python (https://www.cfd-online.com/Forums/openfoam-programming-development/254515-how-extract-data-specific-coordinates-non-cubic-meshes-using-python.html)

1111a1333 February 15, 2024 07:16

How to Extract Data at Specific Coordinates in Non-Cubic Meshes Using Python
 
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,

Severus February 15, 2024 17:29

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:https://www.cfd-online.com/Forums/pa...on-script.html

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

1111a1333 February 16, 2024 07:10

Quote:

Originally Posted by Severus (Post 864795)
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:https://www.cfd-online.com/Forums/pa...on-script.html

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.

Severus February 16, 2024 11:52

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?
https://www.cfd-online.com/Forums/pa...tml#post564003

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

1111a1333 March 29, 2024 01:26

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?


All times are GMT -4. The time now is 10:29.