Advanced tips for working with the OpenFOAM shell environment
Posted August 28, 2011 at 08:51 by wyldckat
Updated January 1, 2014 at 12:11 by wyldckat (Please go to http://openfoamwiki.net/index.php/Installation/Working_with_the_Shell)
Updated January 1, 2014 at 12:11 by wyldckat (Please go to http://openfoamwiki.net/index.php/Installation/Working_with_the_Shell)
Tags bash, environment, openfoam, shell
Finally finished writing a better page than this one at openfoamwiki.net: http://openfoamwiki.net/index.php/In...with_the_Shell
----------------------------------
This blog post envisions to explain the advanced usages of OpenFOAM's shell environment. For now, only the most common ideas will be explained here, but the idea is to expand it to a size worthy for then moving to openfoamwiki.net.
There is still more to come...
Note: read the second comment for more information!
----------------------------------
This blog post envisions to explain the advanced usages of OpenFOAM's shell environment. For now, only the most common ideas will be explained here, but the idea is to expand it to a size worthy for then moving to openfoamwiki.net.
- New to Linux? Then Google "Linux tutorial" Although, if you are lazy, here's some good start:
- Learning the shell - http://linuxcommand.org/learning_the_shell.php
- Understanding the folder structure in Linux - http://www.tecmint.com/linux-directo...ths-explained/
But... Why? You must learn that with OpenFOAM you will be doing a lot of searching! So you better get use to searching for knowledge about OpenFOAM, instead of simply going around asking in forums what to do next
_________________________________ - OpenFOAM shell environment
The shell environment is where all of the variables that are allocated in your currently running shell. To know which variables exist on your current shell, try running one of these commands:Code:env export
Code:WM_PROJECT_DIR FOAM_APPBIN
- If env worked:Code:
env | grep WM_PROJECT_DIR
- If export worked:Code:
export | grep WM_PROJECT_DIR
Variables started with "WM_" and "FOAM_" are usually related to OpenFOAM. If you want to see the content of one of those variables, run:Code:echo $WM_PROJECT_DIR
Code:ls -l $WM_PROJECT_DIR cd $WM_PROJECT_DIR
- If env worked:
- Starting the OpenFOAM shell environment
Traditionally, you are simply instructed to add something like the following line to the file "~/.bashrc":Code:. $HOME/OpenFOAM/OpenFOAM-X.Y.Z/etc/bashrc
Code:source $HOME/OpenFOAM/OpenFOAM-X.Y.Z/etc/bashrc
Note: The file "~/.bashrc" is the same as "$HOME/.bashrc", which you can see the location for it by running:
Code:echo $HOME/.bashrc
Anyway, you have a lot of version you want/need to be available on your machine. So what to do? Resort to aliases! Edit "~/.bashrc", remove or comment any lines you've got there and add lines like these:
Code:alias of15='. $HOME/OpenFOAM/OpenFOAM-1.5/etc/bashrc' alias of15x='. $HOME/OpenFOAM/OpenFOAM-1.5.x/etc/bashrc' alias of16='. $HOME/OpenFOAM/OpenFOAM-1.6/etc/bashrc' alias of16x='. $HOME/OpenFOAM/OpenFOAM-1.6.x/etc/bashrc' alias of170='. $HOME/OpenFOAM/OpenFOAM-1.7.0/etc/bashrc' alias of171='. $HOME/OpenFOAM/OpenFOAM-1.7.1/etc/bashrc' alias of17x='. $HOME/OpenFOAM/OpenFOAM-1.7.x/etc/bashrc' alias of200='. $HOME/OpenFOAM/OpenFOAM-2.0.0/etc/bashrc' alias of201='. $HOME/OpenFOAM/OpenFOAM-2.0.1/etc/bashrc' alias of20x='. $HOME/OpenFOAM/OpenFOAM-2.0.x/etc/bashrc' alias of15dev='. $HOME/OpenFOAM/OpenFOAM-1.5-dev/etc/bashrc' alias of16ext='. $HOME/OpenFOAM/OpenFOAM-1.6-ext/etc/bashrc'
This way, the game play has changed: now whenever you start a new terminal/console window or tab, the OpenFOAM environment is not available by default. You have to run one of the alias commands to activate the desired environment. So, start a new terminal and run one of the alias commands... for example:Code:of20x
This now means that whenever you need another version of OpenFOAM, you must start a new terminal!
There is still more to come...
Note: read the second comment for more information!
Total Comments 5
Comments
-
Hi Bruno.
I would propose a change:
I would make the alias point to the global openfoam bashrc, and not the local one
When you install openfoam (I means SGI OF 2.1.1) the installer suggest to source your .bashrc with the "global" bashrc, not the local one
. /opt/openfoam211/etc/bashrc
http://www.openfoam.org/download/ubuntu.php...
even for suse users :-)
http://www.openfoam.org/download/suse.php
(even more, my special account "cfduser" doesn't even have the ~/etc directory...)
------------------------------------------
Next my two questions:
1) your main idea is to REMOVE the sourcing of the OF bashrc, and to SUBSTITUTE it with the alias. Right ?
2) I had the idea to create two different user (say cfduser2.1.1. and cfduser 1.7.1) and install two different bashrc in the two.
Your trick seems clearly better, because can keep the same user, but
does even manage the different programs like
-paraview
-snappy
-...
that the different distribution may install ?Posted October 14, 2012 at 15:59 by Giuliano69 -
Hi Giuliano,
Well, I did write on the blog post that it isn't complete yet...
Nonetheless, OpenFOAM can be installed for all users (in "/opt" or "/usr/local" or anything similar) or be installed for a single user (usually "$HOME/OpenFOAM").
If you look at the instructions for building from source and git repository, you'll see that "$HOME/OpenFOAM" is standard installation path for these instructions!
This alias methodology (FYI: it was not me who discovered it ) can be used for any installations of OpenFOAM. For example, you can easily have this:
Code:alias of20x='. $HOME/OpenFOAM/OpenFOAM-2.0.x/etc/bashrc' alias of211='source /opt/openfoam211/etc/bashrc' alias of21x='source $HOME/OpenFOAM/OpenFOAM-2.1.x/etc/bashrc' alias of16ext='. $HOME/OpenFOAM/OpenFOAM-1.6-ext/etc/bashrc'
As for where to place these aliases:
- Do not confuse these two files:
- "OpenFOAM-2.1.x/etc/bashrc" - this file has the settings for OpenFOAM.
- "~/.bashrc" is the personal file for setting up the shell environment.
- You do not have to define these aliases in "~/.bashrc", because there are dedicated files for this, as you can see from the source code of that file. Examples:
- Ubuntu has a dedicated user file for aliases: "~/.bash_aliases"
- openSUSE has this one: "~/.alias"
- And yes, the idea is to replace the conventional line, such as this one:
Code:source /opt/openfoam211/etc/bashrc
As for running in parallel, the trick is to use foamJob, which relies on foamExec to setup the correct environment on the remote machines.
As for system-wide installations, the advice is basically this:
- Build with a normal user account and follow the desired building instructions.
- When finished, go into root mode, copy the whole installation to the desired global folder, such as "/opt/OpenFOAM".
- Then change the permissions on this whole folder, to avoid unintentional code/binary modifications.
- Edit the file "OpenFOAM-*/etc/bashrc" and find this big block of unmistakable code:
Quote:Code:################################################################################ # USER EDITABLE PART: Changes made here may be lost with the next upgrade # # either set $FOAM_INST_DIR before sourcing this file or set # 'foamInstall' below to where OpenFOAM is installed # # Location of the OpenFOAM installation # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ foamInstall=$HOME/$WM_PROJECT # foamInstall=~$WM_PROJECT # foamInstall=/opt/$WM_PROJECT # foamInstall=/usr/local/$WM_PROJECT # # END OF (NORMAL) USER EDITABLE PART ################################################################################
- Switch back to normal user and check if everything is working as intended.
You can easily create a global files with aliases for all users to use, such as "/opt/OpenFOAM/.ofaliases" and tell users to add the following line to their own "~/.bashrc" file:
Code:source /opt/OpenFOAM/.ofaliases
BrunoPosted October 14, 2012 at 16:38 by wyldckat - Do not confuse these two files:
-
Hi, I have OpenFoam2.1.1 installed on my system already. And now I need to have OpenFoam1.5 as well. So now I have this line in my .bashrc: source /opt/OpenFOAM-2.1.1/etc/bashrc
So should I now just simply comment that line out and add the below line?
alias of211= 'source /opt/OpenFOAM-2.1.1/etc/bashrc'
I did that but when I type of211 in my terminal, I get the error "command not found"
please let me know what I'm missing,
Thanks
MohsenPosted November 15, 2012 at 19:26 by mhsn -
Greetings Mohsen,
Sorry for the late reply. I think the problem is that you left a space between the = and ':
Quote:Code:alias of211= 'source /opt/OpenFOAM-2.1.1/etc/bashrc'
Code:alias of211='source /opt/OpenFOAM-2.1.1/etc/bashrc'
BrunoPosted November 26, 2012 at 16:13 by wyldckat -
I want to open a terminal without sourcing OpenFoam's bashrc. What should I do?
I have tried bash --norc , $ bash --noprofile --norc and env -i bash --rcfile /etc/profile, but non of them workedPosted January 31, 2019 at 18:02 by Samsam2