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

Running a python file from OpenFOAM

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 3 Post By Yann
  • 1 Post By Carlo_P
  • 1 Post By Yann

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 2, 2020, 09:27
Default Running a python file from OpenFOAM
  #1
Member
 
K
Join Date: Mar 2018
Posts: 34
Rep Power: 8
kuria is on a distinguished road
Hey Foamers


I am wondering if it is possible to run a python file by modifying OpenFOAM solver source code (like say simpleFOAM).

Lets just say the python file forces printing out a random statement during running of the solver.



My understanding of PyFOAM is that it is a wrapper around the C++ OpenFOAM source code so it doesn't allow running python script in the solver.


Thank you in advance for your comments and thoughts on this!
kuria is offline   Reply With Quote

Old   October 2, 2020, 10:27
Default
  #2
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,207
Rep Power: 28
Yann will become famous soon enough
Hello Kuria,

Why not using the systemCall function object for this ? This function allow to execute shell commands during a run.

Code:
    Executes system calls, entered in the form of a string lists.
    Calls can be made at the following points in the calculation:
    - every time step
    - every output time
    - end of the calculation

I usually use it to execute gnuplot scripts (e.g. to monitor residuals) but running a python script should not be a problem.

Cheers,
Yann
tomf, ashvinc9 and Carlo_P like this.
Yann is offline   Reply With Quote

Old   October 6, 2020, 04:28
Default
  #3
Senior Member
 
Carlo_P
Join Date: May 2019
Location: Italy
Posts: 176
Rep Power: 8
Carlo_P is on a distinguished road
Hey Yann,


nice functionObject..
Does it works both with Esi and org foam version?


For Kuris:
you can simple write "python pythonfile.py > pythonfile.log" in that system call.
Yann likes this.
Carlo_P is offline   Reply With Quote

Old   October 6, 2020, 06:07
Default
  #4
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,207
Rep Power: 28
Yann will become famous soon enough
Quote:
Originally Posted by Carlo_P View Post
Hey Yann,


nice functionObject..
Does it works both with Esi and org foam version?
Hi Carlo!

Yes this is quite an old function object and it exists in both branches!

I think it's an overlooked but powerful way to automatize tasks during a run, whether it is about running some shell commands or using other tools such as python or gnuplot.

Cheers,
Yann
Carlo_P likes this.
Yann 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
Custom Thermophysical Properties wsmith02 OpenFOAM 4 June 1, 2023 15:30
[foam-extend.org] problem when installing foam-extend-1.6 Thomas pan OpenFOAM Installation 7 September 9, 2015 22:53
[Other] Adding solvers from DensityBasedTurbo to foam-extend 3.0 Seroga OpenFOAM Community Contributions 9 June 12, 2015 18:18
friction forces icoFoam ofslcm OpenFOAM 3 April 7, 2012 11:57
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 18:51


All times are GMT -4. The time now is 12:32.