CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Using python for OpenFoam

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree7Likes
  • 2 Post By aerosayan
  • 2 Post By AtoHM
  • 1 Post By AtoHM
  • 2 Post By danielcharles

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 13, 2021, 08:18
Default Using python for OpenFoam
  #1
Member
 
Jigs
Join Date: Aug 2017
Location: Ahmedabad
Posts: 31
Rep Power: 6
jmex is on a distinguished road
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!
jmex is offline   Reply With Quote

Old   February 13, 2021, 13:55
Default
  #2
Senior Member
 
Sayan Bhattacharjee
Join Date: Mar 2020
Posts: 385
Rep Power: 5
aerosayan is on a distinguished road
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
jmex and aero_head like this.
aerosayan is offline   Reply With Quote

Old   February 13, 2021, 14:01
Default
  #3
Senior Member
 
M
Join Date: Dec 2017
Posts: 443
Rep Power: 9
AtoHM is on a distinguished road
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 and aero_head like this.
AtoHM is offline   Reply With Quote

Old   February 14, 2021, 03:03
Default
  #4
Member
 
Jigs
Join Date: Aug 2017
Location: Ahmedabad
Posts: 31
Rep Power: 6
jmex is on a distinguished road
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.
jmex is offline   Reply With Quote

Old   February 14, 2021, 10:22
Default
  #5
Senior Member
 
M
Join Date: Dec 2017
Posts: 443
Rep Power: 9
AtoHM is on a distinguished road
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
jmex likes this.
AtoHM is offline   Reply With Quote

Old   February 25, 2021, 23:22
Default Using python for OpenFoam
  #6
New Member
 
daniel charles
Join Date: Feb 2021
Posts: 1
Rep Power: 0
danielcharles is on a distinguished road
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.
jmex and aerosayan like this.
danielcharles is offline   Reply With Quote

Reply

Tags
automation, cfd, openfoam, python

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
[PyFoam] Using pyFoamPlotWatcher.py To Plot Residuals m_ridzon OpenFOAM Community Contributions 22 January 26, 2021 18:48
Running Fluent from Python: UDF Compilation problems Ames Fluent UDF and Scheme Programming 5 November 16, 2020 06:12
[OpenFOAM] using the python shell in paraFoam colinB ParaView 14 September 14, 2015 09:04
[OpenFOAM] paraview v4 - building with python - OF2.3.0, PVv4, Python 2.7 aylalisa ParaView 4 June 13, 2014 08:52
CentFOAM Python Script Installation: Error socon009 OpenFOAM Installation 2 May 26, 2012 09:36


All times are GMT -4. The time now is 14:11.