CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   Using python for OpenFoam (https://www.cfd-online.com/Forums/main/233827-using-python-openfoam.html)

jmex February 13, 2021 08:18

Using python for OpenFoam
 
Hello folks,


Hope everyone is well and safe!
I am learning python and knows little, can work with tkinter. I am looking to integrate python with openfoam in a way that i want to create an interface for openfoam. As such i am learning by my own, i need some guidance. I have come across pyFoam and i am trying to learn that as well. The problem i am facing is not proper knowledge.
Can someone help me with step by step, where should i start. I have literally jumped into the pool and struggling to swim. I think i should atleast get some idea of the swimming. Can someone point me in the right direction?


Thanks in advance!

aerosayan February 13, 2021 13:55

This is a really good idea, but I wouldn't recommend it to a beginner.:)


if you would really like to do it, I would recommend trying to see the few OpenFOAM GUIs available in the wild.


But in my own personal opinion ( which you can reject if it doesn't suit you):



Here's something that can be feasible, and will actually be a very good tool. I know something like this will be immensely helpful to me. I can't speak for others though.


- Run OpenFOAM on Linux. Understand how to use it and how it works.

- Create bash scripts to automate creation of the different dictionary files used by OpenFOAM.


- When you get more knowledgeable in using the linux grep, sed, awk tools, you can create a bash script to directly change the value inside the dictionary files (say mach_no = 1.5 ) to (say mach_no = 3.6 ) etc. This bash script should have command-line arguments that allow the user to change the different values in the dictionary file. It can be something like $ ./editor.sh --mach 3.6 --freestream-temp 300 --solver explicit


- The user could call your bash script from the terminal and pass in the variable they want to change. You can even make the bash script use autocomplete feature, so that the configuration parameters mach, freestream-temp, solver etc get autocompleted by the bash shell of the Linux terminal.


- Then you can create a GUI in python to take all of the inputs and call one of the previously developed bash scripts to do the required work.


Best of luck :)

AtoHM February 13, 2021 14:01

Well. Your task is either fairly easy or extremely hard. Why? It depends heavily on what you want your interface to be able to do. Do you want just a simple interface where you can adjust some basic settings for a certain setup? That might be easy. Do you want a UI to control OF entirely? Well, I don't say its impossible, but there is a quadrillion of options in OF and that's really hard.
However, I would suggest starting with a really easy case, probably a tutorial? And create something for this - for instance allowing the user of your interface to adjust some options in fvSchemes. Then maybe switching some boundary conditions. And then go from there and see how far you get.
Keep in mind that OF is constantly evolving and whatever you write might not work with future versions. The syntax of functions e.g. is changed from time to time. You need to keep updating all the time or stick to a certain version.

jmex February 14, 2021 03:03

Thanks AtoHM and aerosayan, I appreciate your reply. You both perfectly understood me. I am not entirely looking to control OF with interface but just simple simulations. Yes I am familiar with OF on linux and also with python. I am not sure how to link bash commands with python. Also exploring pyFoam so that i can use its feature.Thanks again, can you help me with a simple example? So that using it, i can learn and create my own.

AtoHM February 14, 2021 10:22

As I said, tutorials are a great way to start off. OF comes with a number of tutorials and there are also additional tutorials available for new OF users. Some for example are available here https://holzmann-cfd.com/community/training-cases which is page by moderator on this very forum: https://www.cfd-online.com/Forums/members/tobi.html

danielcharles February 25, 2021 23:22

Using python for OpenFoam
 
Hello everyone,

I found this script made by a researcher in Chalmers during his study on porous media. The background of the study and specific model assumptions are not so important I think. He is actually using the script to alternate between incompressible and compressible simulation on the fly, we can hopefully start with simpler stuff like calling applications and running them. The way he does it, the way he creates the python script, linking to the python library we talked about in our first meeting (pyFoam) may shed some light to you more experienced coders on how Butterfly can perhaps interface with OpenFoam in the same way. I hope it helps!

http://publications.lib.chalmers.se/...ext/160199.pdf (page 53)

Kind regards,
Daniel Charles.


All times are GMT -4. The time now is 16:43.