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

Calling OpenFOAM from Scilab

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   August 7, 2014, 10:22
Default Calling OpenFOAM from Scilab
  #1
New Member
 
Jefferson Vieira
Join Date: Jul 2014
Location: Brazil/Scotland
Posts: 12
Rep Power: 3
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, 10:34
Default
  #2
Senior Member
 
Chris Sideroff
Join Date: Mar 2009
Location: Ottawa, ON, CAN
Posts: 381
Rep Power: 12
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, 03:34
Default
  #3
Member
 
Julian Langowski
Join Date: May 2011
Location: Bremen, Germany
Posts: 91
Rep Power: 6
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, 09:52
Default
  #4
New Member
 
Jefferson Vieira
Join Date: Jul 2014
Location: Brazil/Scotland
Posts: 12
Rep Power: 3
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   Today, 14:31
Default
  #5
New Member
 
Jairo A. Gutiérrez S
Join Date: Nov 2014
Posts: 5
Rep Power: 3
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   Today, 16:49
Default
  #6
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,300
Rep Power: 23
alexeym will become famous soon enoughalexeym will become famous soon enough
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   Today, 17:56
Default Found a different solution !
  #7
New Member
 
Jairo A. Gutiérrez S
Join Date: Nov 2014
Posts: 5
Rep Power: 3
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

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Frequently Asked Questions about Installing OpenFOAM wyldckat OpenFOAM Installation 0 January 1, 2014 20:21
OpenFOAM Foundation releases OpenFOAM 2.2.2 opencfd OpenFOAM Announcements from ESI-OpenCFD 0 October 14, 2013 07:18
OpenFOAM - Validation of Results Ahmed OpenFOAM Running, Solving & CFD 9 June 22, 2011 18:59
The OpenFOAM extensions project mbeaudoin OpenFOAM 16 October 9, 2007 09:33
OpenFOAM Training and Workshop Hrvoje Jasak Main CFD Forum 0 October 7, 2005 07:14


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