CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Pre-Processing

Calling OpenFOAM from Scilab

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 7, 2014, 11:22
Default Calling OpenFOAM from Scilab
  #1
New Member
 
Jefferson Vieira
Join Date: Jul 2014
Location: Brazil/Scotland
Posts: 12
Rep Power: 12
Jefferson_dhv is on a distinguished road
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.
Jefferson_dhv is offline   Reply With Quote

Old   August 7, 2014, 11:34
Default
  #2
Senior Member
 
Chris Sideroff
Join Date: Mar 2009
Location: Ottawa, ON, CAN
Posts: 434
Rep Power: 22
cnsidero is on a distinguished road
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.
cnsidero is offline   Reply With Quote

Old   September 24, 2014, 04:34
Default
  #3
Member
 
Julian Langowski
Join Date: May 2011
Location: Bremen, Germany
Posts: 91
Rep Power: 15
Ruli is on a distinguished road
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
__________________
πάντα ῥεῖ - Heraclitus
Ruli is offline   Reply With Quote

Old   September 24, 2014, 10:52
Default
  #4
New Member
 
Jefferson Vieira
Join Date: Jul 2014
Location: Brazil/Scotland
Posts: 12
Rep Power: 12
Jefferson_dhv is on a distinguished road
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
Jefferson_dhv is offline   Reply With Quote

Old   February 5, 2016, 14:31
Default
  #5
Member
 
Jairo A. Gutiérrez S
Join Date: Nov 2014
Posts: 60
Rep Power: 12
jairoandres is on a distinguished road
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
jairoandres is offline   Reply With Quote

Old   February 5, 2016, 16:49
Default
  #6
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
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
alexeym is offline   Reply With Quote

Old   February 5, 2016, 17:56
Default Found a different solution !
  #7
Member
 
Jairo A. Gutiérrez S
Join Date: Nov 2014
Posts: 60
Rep Power: 12
jairoandres is on a distinguished road
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
jairoandres is offline   Reply With Quote

Reply

Tags
openfoam, scilab, unix


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
Frequently Asked Questions about Installing OpenFOAM wyldckat OpenFOAM Installation 3 November 14, 2023 12:58
OpenFOAM - Validation of Results Ahmed OpenFOAM Running, Solving & CFD 10 May 13, 2018 19:28
OpenFOAM Foundation releases OpenFOAM 2.2.2 opencfd OpenFOAM Announcements from ESI-OpenCFD 0 October 14, 2013 08:18
The OpenFOAM extensions project mbeaudoin OpenFOAM 16 October 9, 2007 10:33
OpenFOAM Training and Workshop Hrvoje Jasak Main CFD Forum 0 October 7, 2005 08:14


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