MATLAB Answers

Problems invoking openfoam utilities throught system-dos-unix functions - Matlab2018b - Ubuntu 18.04

1 view (last 30 days)
I've got Matlab2018b installed on a - 64 bits machine with Ubuntu 18.04 LTS.
I'm working on a 2D airfoil optimization throught Openfoam and I want to invoke the ubuntu terminal using the system function (or "dos" and "unix" function) from Matlab in order to give it multiple commands, either step by step or running a ./sh script, however when I try it with these functions an error appears, in fact, I do a similar thing but calling a python script from matlab (with either of those functions ex: "[status, cmdout] = system(python myScript.py)") which perform the same commands invoking the terminal, but the same error appears. It looks like the problem is the way how I'm using the matlab "system-unix-dos" functions or the functions itselfs when it calls the terminal, because when I call either the python script or execute the ./sh file directly from the terminal (locate in the same directory), the openfoam commands run perfectly, besides when I type in the matlab command window "!bash" it connects well but the user has to give the order manually to run the ./sh file in the command window, but that is not 100% automatic and is not wanted. Unfortunately I need to this from matlab because there I have all my openfoam files generator and airfoil mesh generator and other stuffs in order to do any airfoil or airfoils analysis automatically. Does anyone know how to fix this?
  1. error:
  • sh 1: plot3dToFoam: not found or appears command no found
  • sh:1: autoPatch: not found or appears command no found
  • sh:1: topoSet: not found or appears command no found
  • sh:1: createPatch: not found or appears command no found
  • sh:1: simpleFoam: not found or appears command no found

Answers (2)

Precise Simulation
Precise Simulation on 31 Mar 2021
It seems your shell script when run from MATLAB does not find the OpenFOAM executables, in this case the most likely issue is that your terminal/shell when started/opened in Linux sets up paths (to the executables) that MATLAB does not (for example via ".bashrc" and similar startup scripts). You can for example try comparing the "env" terminal output
env
with the same output when run within MATLAB with
system('env')

Camilo Echavarría Martínez
Hi @Precise Simulation, actually I already solve the issue using the command
[~,~] = system('bash -i File-Executable.sh')
the key was the -i. Thank you for take your time and answer

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!