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

Running OpenFoam with Python

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 20, 2022, 09:14
Default Running OpenFoam with Python
  #1
Senior Member
 
Nico
Join Date: Jan 2022
Location: Germany
Posts: 122
Rep Power: 6
Hr_kules is on a distinguished road
Hey,



i want to create a bigger application around OpenFoam, considering that the meshing is done with a Python api, i want to include the ./Allrun script into my Python files.
First instict was to import os in python and insert the commands from the ./Allrun script. However i am only met with following error messages:
Code:
./Allrun: line 5: /bin/tools/RunFunctions: No such file or directory
--> FOAM FATAL ERROR :
    Could not find mandatory etc entry (mode=ugo)
    'controlDict'

--> FOAM FATAL ERROR :
    Could not find mandatory etc entry (mode=ugo)
    'controlDict'
This is the Python code:
Code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
os.system("./Allrun")
and my ./allrun script:
Code:
#!/bin/bash
cd ${0%/*} || exit 1    # Run from this directory

# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions

gmshToFoam constant/pipeHex.msh
createPatch -overwrite

#------------------------------------------------------------------------------

I suppose the problem is related to paths, but i don't have any idea how to resolve this.


Any help is appreciated!
Hr_kules is offline   Reply With Quote

Old   October 20, 2022, 10:38
Default
  #2
Senior Member
 
Nico
Join Date: Jan 2022
Location: Germany
Posts: 122
Rep Power: 6
Hr_kules is on a distinguished road
It really had to do with paths, or rahter the right source.
If somebody is trying to do the same:
Code:
import subprocess
subprocess.call("./Allrun",shell=True)
i changed to the subprocess package and in the allrun script the bashrc must be referenced:
Code:
#!/bin/bash
source /opt/openfoam9/etc/bashrc
This does the trick
Hr_kules 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
How to contribute to the community of OpenFOAM users and to the OpenFOAM technology wyldckat OpenFOAM 17 November 10, 2017 16:54
OpenFOAM v3.0+ ?? SBusch OpenFOAM 22 December 26, 2016 15:24
[OpenFOAM.org] A Mac OS X of23x Development Environment Using Docker rt08 OpenFOAM Installation 1 February 28, 2016 20:00
Python for openfoam Divyaprakash OpenFOAM Programming & Development 1 August 22, 2014 10:05
Statically Compiling OpenFOAM Issues herzfeldd OpenFOAM Installation 21 January 6, 2009 10:38


All times are GMT -4. The time now is 00:15.