CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   OpenFOAM command from inside MATLAB (https://www.cfd-online.com/Forums/openfoam-post-processing/64021-openfoam-command-inside-matlab.html)

sega April 27, 2009 10:47

OpenFOAM command from inside MATLAB
 
Hello World.

I'm doing some post-processing with MATLAB and need to run the OpenFOAM 'sample' command from within MATLAB.

Unfortunately the MATLAB unix command used like
Code:

unix('sample -time 8');
does not work out, but produced this error:

Code:

>> [s,w]=unix('sample')

s =

    1


w =

sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by sample)
sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/libfiniteVolume.so)
sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/libmeshTools.so)
sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/libsampling.so)
sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/libtriSurface.so)
sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/liblagrangian.so)
sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/libOpenFOAM.so)
sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/openmpi-1.2.6/libPstream.so)

Do you have any ideas how I can fix this?

sega April 29, 2009 12:31

Location of GLIC
 
As I have found out through the MATLAB Newsgroup this is a problem due to a wrong pointer to GLIB.

I will have to change a setting so MATLAB will not use its own GLIB, but the one needed by OpenFOAM.

To do this I will have to know, where OpenFOAM's GLIB is located!
Can anybody tell me, so I can set the right path?

ngj April 30, 2009 02:24

Hi Sebastian

I believe that you should target the following file:

~/OpenFOAM/ThirdParty/gcc-4.3.1/platforms/linux/lib/libstdc++.so.6

Best regards,

Niels

Daniele111 June 30, 2010 10:55

Hi
I must use Openfoam in a matlab routine. OpenFoam run correcty but when I use this matlab command, unix('simpleFoam'), I have this error message:

/bin/bash: simpleFoam: command not found.

Why?

Thanks

anmartin December 29, 2010 10:15

Hello

Please, could you explain how i must change the settings so MATLAB will not use its own GLIB and use ~/OpenFOAM/ThirdParty/gcc-4.3.1/platforms/linux/lib/libstdc++.so.6
Because I would like to launch OF from matlab but i obtain the following error.
interDyMFoam: /MATHWORKS_R2008A/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by interDyMFoam)

Best regards

wyldckat December 30, 2010 10:16

Greetings to all!

Interesting, I thought this was something that was already solved and well documented... I guess not.

Well, it's somewhat easy, but a bit annoying to use:
Code:

unix('export LD_LIBRARY_PATH=""; $HOME/OpenFOAM/OpenFOAM-1.7.x/bin/foamExec foamInfoExec')
Let me explain:
  1. the first export command will reset the Library search path list. This way, MATLAB's libraries won't get in the way :D
  2. the long path to foamExec will make it possible to execute the desired solver/utility, in this case foamInfoExec. In other words, it will take care of the bureaucracy needed for run OpenFOAM executables.
In case you don't want to use foamExec (some-rare-times it doesn't work very well :(), then you can do it like this as well:
Code:

unix('export LD_LIBRARY_PATH=""; . $HOME/OpenFOAM/OpenFOAM-1.7.x/etc/bashrc; foamInfoExec')
If this feels too cumbersome to go around launching utilities like this, then wrap this command in a function... something like this:
Code:

function result=goGoOpenFOAM(command)
result=unix(['export LD_LIBRARY_PATH=""; . $HOME/OpenFOAM/OpenFOAM-1.7.x/etc/bashrc; ' command])

(Ironically, Inspector Gadget's famous "Go-Go-Gadget" command line came to mind, when I tried to come up with the name for the function :D)
Then simply use:
Code:

goGoOpenFOAM('foamInfoExec')
Best regards,
Bruno

anmartin December 30, 2010 14:46

Many Thanks,

With your explanations it looks like easy, but without them I had not been able to solve.

It works for me,

Best regards and happy new year

Best regards and happy new year

Eren10 April 13, 2011 11:39

Hi,

I want to use matlab to call openfoam and its solvers. I am using openfoam17x.

I have done the mentioned things in this topic but it did not help. when I just type unix('pisoFoam'). I get messages like:

Quote:

/opt/apps/matlab-R2008b/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by pisoFoam)
when i type this:

Quote:

unix('export LD_LIBRARY_PATH=""; $HOME/OpenFOAM/OpenFOAM-1.7.x/bin/foamExec pisoFoam')
I get:

Quote:

home/OpenFOAM/OpenFOAM-1.7.x/etc/bashrc: line 90: /opt/apps/openfoam//OpenFOAM-1.7.x/bin/foamEtcFile: No such file or directory
what should I do ?

l_r_mcglashan April 13, 2011 11:46

Quote:

home/OpenFOAM/OpenFOAM-1.7.x/etc/bashrc: line 90: /opt/apps/openfoam//OpenFOAM-1.7.x/bin/foamEtcFile: No such file or directory
Read the error message: There is an extra '/' in an environment variable.

Eren10 April 13, 2011 12:06

Quote:

Originally Posted by l_r_mcglashan (Post 303459)
Read the error message: There is an extra '/' in an environment variable.



I do not know where the extra / came from. I have checked the path, that should be correct. but I see that program does not search on the directory where Openfoam is installed, but it searches on other directory where normally applications are installed.

wyldckat April 13, 2011 18:04

Greetings to all!

The extra slash (usually) doesn't hurt in Linux. The main concern is "/opt/apps/openfoam/" being picked up at "bashrc: line 90".
The question is how did it get there, when you called the version installed at the "$HOME" folder? It seems to me that you have more than one version of OpenFOAM installed in your system. Somehow environment variables from another OpenFOAM installation have contaminated the environment used by MATLAB.

Try the other possibility I listed on the other post, the one that uses bashrc directly. It should give you the exact same error. In case you don't see the elusive dot-space, here's another way to use it:
Code:

unix('export LD_LIBRARY_PATH=""; source $HOME/OpenFOAM/OpenFOAM-1.7.x/etc/bashrc; foamInfoExec')
If this doesn't work either, here is the flame-thrower way to do it:
Code:

unix('env -i HOME=~ $HOME/OpenFOAM/OpenFOAM-1.7.x/bin/foamExec foamInfoExec')
The break down of this command line is as follows:
  • "env -i" will make create new pseudo-shell to use a seriously clean environment;
  • "HOME=~" will jump-start the new environment to include the variable "$HOME" properly defined, which is required by the OpenFOAM scripts.
  • The rest is business as usual :)

Best regards,
Bruno

l_r_mcglashan April 14, 2011 04:28

Quote:

The extra slash (usually) doesn't hurt in Linux.
I recently had to install OF, and the OF environment variables weren't set due to the HOME env variable having an extra slash at the end.

On another note, interesting that people are running foam through matlab. Why not just do it with a shell script? Is there an advantage to doing it this way?

Eren10 April 14, 2011 06:22

Quote:

Originally Posted by wyldckat (Post 303512)
the flame-thrower way to do it

Bruno

Thank you very much Bruno http://www.theblueroom.me.uk/forum/smileys/smiley32.gif . Indeed, the flame-thrower did the job http://www.budoseek.net/vbulletin/im...r_emoticon.gif.

I will sequentially run openfoam and hereby with matlab I will change some input values for each run. I am not familiar with shell scripting, matlab looks easier for this kind of operations for me.

claco October 3, 2011 06:20

Quote:

Originally Posted by Daniele111 (Post 265164)
Hi
I must use Openfoam in a matlab routine. OpenFoam run correcty but when I use this matlab command, unix('simpleFoam'), I have this error message:

/bin/bash: simpleFoam: command not found.

Why?

Thanks


Dear Daniele,

have you solved your problem?

I have the same your problem and I cannot succeed in solving it.

Your sincerely,

Claudio

wyldckat October 3, 2011 10:59

Greetings Claudio,

Quote:

Originally Posted by claco (Post 326478)
Dear Daniele,

have you solved your problem?

I have the same your problem and I cannot succeed in solving it.

Why did you stop reading at post #4? There are multiple solutions after that post! Did none of them work?

If none of them work, then what errors occur after each possible solution?

Best regards,
Bruno

aerogt3 September 20, 2012 14:42

I tried writing Bruno's "flame thrower" command, with the following result

Code:

unix('env -i HOME=/opt/openfoam211/bin/foamExec foamInfoExec')

fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by fluent3DMeshToFoam)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by fluent3DMeshToFoam)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libmeshTools.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libmeshTools.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libdynamicMesh.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libdynamicMesh.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libOpenFOAM.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libOpenFOAM.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libtriSurface.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libtriSurface.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libfiniteVolume.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libfiniteVolume.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/openmpi-system/libPstream.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/openmpi-system/libPstream.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libfileFormats.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libfileFormats.so)


wyldckat September 22, 2012 17:04

Greetings Robert,

Apparently something got lost along the way... After all of the details I wrote down, you still didn't notice the discrepancy between the command you posted and the one I wrote months ago? :confused:

Mine was:
Code:

unix('env -i HOME=~ $HOME/OpenFOAM/OpenFOAM-1.7.x/bin/foamExec foamInfoExec')
Your command line was:
Code:

unix('env -i HOME=/opt/openfoam211/bin/foamExec foamInfoExec')
Comparing the two, it should be very easy to notice that you're missing a tilde and a space ;)
Code:

unix('env -i HOME=~ /opt/openfoam211/bin/foamExec foamInfoExec')
Best regards,
Bruno

aerogt3 September 24, 2012 13:58

Having corrected the error I am still not having success:

Code:

>> unix('env -i HOME=~ /opt/openfoam211/bin/foamExec foamInfoExec')
ans =
    0
>> unix('fluent3DMeshToFoam')
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by fluent3DMeshToFoam)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by fluent3DMeshToFoam)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libmeshTools.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libmeshTools.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libdynamicMesh.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libdynamicMesh.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libOpenFOAM.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libOpenFOAM.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libtriSurface.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libtriSurface.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libfiniteVolume.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libfiniteVolume.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/openmpi-system/libPstream.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/openmpi-system/libPstream.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libfileFormats.so)
fluent3DMeshToFoam: /usr/local/Matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by /opt/openfoam211/platforms/linux64GccDPOpt/lib/libfileFormats.so)
ans =
    1


wyldckat September 25, 2012 07:35

Hi Robert,

I guess you didn't read post #6 ;):
Quote:

Originally Posted by wyldckat (Post 288861)
Let me explain:
  1. the first export command will reset the Library search path list. This way, MATLAB's libraries won't get in the way :D
  2. the long path to foamExec will make it possible to execute the desired solver/utility, in this case foamInfoExec. In other words, it will take care of the bureaucracy needed for run OpenFOAM executables.

In other words: foamInfoExec is an OpenFOAM application that you're meant to replace for the desired solver or utility! It does not prepare the shell environment in MATLAB :(

As a side note: foamInfoExec use to provide the standard run-time OpenFOAM header, including version number and so on. But since OpenFOAM 2.0, it changed and it will only show the header if the proper arguments are given...

Have fun!
Bruno


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