CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (https://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   Calling OpenFOAM from Scilab (https://www.cfd-online.com/Forums/openfoam-pre-processing/140086-calling-openfoam-scilab.html)

Jefferson_dhv August 7, 2014 10:22

Calling OpenFOAM from Scilab
 
Hi all,

I'm working on an optimization routine in Scilab that in a certain point calls OpenFOAM to do the simulation. I'm trying to use the unix function in Scilab to do this, but I'm having some problems. At first I tried to call the OpenFOAM function normally e.g. icoFoam, and then:

Code:

!--error 10000
unix_w: The command failed with the error code "127" and the following message:
sh: 1: icoFoam: not found

Later I tried to give the full path to the OpenFOAM function, "/opt/openfoam230/platforms/linux64GccDPOpt/bin/icoFoam" in this case, and then:

Code:

!--error 10000
unix_w: The command failed with the error code "127" and the following message:
/opt/openfoam230/platforms/linux64GccDPOpt/bin/icoFoam: error while loading shared libraries: libfiniteVolume.so: cannot open shared object file: No such file or directory

Does anyone know how to proceed?

Thanks in advance,
Jefferson V.

cnsidero August 7, 2014 10:34

I've never used scilab before (but know what it is) but my wild stab in the dark is that scilab does not inherit some/any of the shell environment variables from which is was started. Meaning none of the environment variables needed by OpenFOAM (as created by $WM_PROJECT_DIR/etc/bashrc) exist.

Ruli September 24, 2014 03:34

Dear Jefferson,

a few years ago I did perform an optimisation in Scilab using OpenFOAM and indeed it is possible. As I am currently again working on a combination of Scilab and OF, I will let you know, when I searched through my old project and found the basic instructions.

Best regards
Julian

Jefferson_dhv September 24, 2014 09:52

Hi Julian,

I've managed to do it. At first I was using a computer running Linux in a virtual machine, but when I tried in another computer without the virtual machine it worked fine using the unix function.

Regards,
Jefferson

jairoandres February 5, 2016 13:31

I am having the same issues calling openFOAM operations from Scilab... As you posted before, it returns error 127 when i try to run any openFoam command using host("") or unix("")...

Does anybody know any solution to this since i already invested considerable time writing my code in scilab?

I'd gladly appreciate any support

alexeym February 5, 2016 15:49

Hi,

To execute OpenFOAM commands you have to set up environment. Either do it by had or use foamExec function. So your Scilab code could look like:

Code:

function [rep, stat] = foamExec(cmd, version)
    [lhs, rhs] = argn(0);
    if rhs <= 1 then
        version = '2.4.0'
    end
    foam_home = home + '/OpenFOAM/OpenFOAM-' + version
    foam_exec = foam_home + '/bin/foamExec'
    cmd_line = foam_exec + ' ' + cmd
   
    [rep, stat] = unix_g(cmd_line)
endfunction

me = getenv('USER');
chdir(home + '/OpenFOAM/' + me + '-2.4.0/run/cavity');
[output, ret_val] = foamExec('blockMesh');
disp(ret_val);
[output, ret_val] = foamExec('icoFoam', '2.4.x');
disp(ret_val);
disp(output(8));

And the output is

Code:


    0. 
 
    0. 
 
 Build  : 2.4.x-eb277aee1088


jairoandres February 5, 2016 16:56

Found a different solution !
 
Thank you a lot.. however that did not work for me since Scilab shell commands do not recognize openFoam functions (As someone said before the environment variables configured in the bashrc file)... btw I am novice in ubuntu configurations...

After trying different approaches, I found out a way to operate this and make scilab recognize openFOAM using host or unix functions:

1. Open an ubuntu terminal and execute scilab by typing it.
2. Select the $FOAM_RUN directory as the working directory for scilab
3. Force the bashrc configuration to be reloaded it can be used the following:

unix("exec $BASH blockMesh -case $FOAM_RUN/cavity") ... I have already tested and it works with paraFoam and the solvers.

Thank you a lot for your answers though


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