CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   how to add OpenFoam in module environment (https://www.cfd-online.com/Forums/openfoam/87163-how-add-openfoam-module-environment.html)

smpark April 12, 2011 22:45

how to add OpenFoam in module environment
 
Hello,

I installed OpenFOAM 1.7.1 in /opt directory on linux cluster
and for users, I want to add OpenFOAM in module environment but I don't know how to do it.

Module environment has already installed on our system.
and I tried to add OpenFOAM by inseting /etc/modulefiles/OpenFOAM/OpenFOAM-1.7.1 file.
But, It did not work at all.

Here is file I put into.

#%Module1.0

################################################## ###################
##
## Modulefile for OpenFOAM 1.7.1
##
################################################## ###################

proc ModulesHelp { } {

puts stderr "OpenFOAM-1.7.1"

}

module-whatis "sets the environment for OpenFOAM 1.7.1"

# for Tcl script use only
set topdir /opt/OpenFOAM/OpenFOAM-1.7.1
set version 1.7.1

setenv OpenFOAM_HOME $topdir
prepend-path PATH $topdir/bin
prepend-path LD_LIBRARY_PATH $topdir/lib

and I think I have to put some line about exporting path like
source /opt/OpenFOAM/OpenFOAM/etc/bashrc

does anyone have idea?

thanks in advance.

Sangmin

wikstrom April 26, 2011 13:02

Hello,
I have the same problem. Have tried with

Code:

system("source ..../bashrc")
or
Code:

system "source ..../bashrc"
etc.
Both gives me a Tcl error.

/Niklas

eugene April 27, 2011 05:14

You only need a very small number of environmental variables to run OPENFOAM (to compile it you need a whole lot more).

With modules it is easier to simply set the exact environmental variables needed to run and do the compiling in a non-modules environment.

I can't recall all the variables needed, but there is no more than 10. The ones I remember:
- PATH and LD_LIBRARY_PATH
- MPI_BUFFER_SIZE
- WM_PROJECT_INST_DIR
- WM_PROJECT_DIR
- FOAM_SIGFPE & FOAM_SETNAN (optional)

Some might be superfluous and there might be one or two missing, but as far as I recall, that's the gist of it.

wikstrom April 27, 2011 15:46

Thank's a lot Eugene,

I will sort it out that way. You just saved me from wasting time on tedious scripting...

-Niklas

wikstrom May 12, 2011 14:00

Might as well post the simplest 'obvious' solution. To prepare the contents of a module file, I just run printenv before and after sourcing OpenFOAM, piping output to two different files. A diff on these combined with sed gives a 90% working OpenFOAM-module file. Then clean up the remaining 10% by hand.

Without fancyness:
Code:

printenv > /tmp/env_0
export FOAM_INST_DIR=/opt/OpenFOAM
. /opt/OpenFOAM/OpenFOAM-1.7.x/etc/bashrc
printenv > /tmp/env_1

diff /tmp/env_?|sed -ne 's/> \(.*\)=\(.*\)/setenv \1\t"\2"/gp' >> moduleFile

Crude, but quick and functional. 15 minutes more 'sed'ing and editing and the moduleFile can be 'parameterised', and reusable.

/N


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