Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
openfoam
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
openfoam
Commits
b0cc93ec
Commit
b0cc93ec
authored
5 years ago
by
Mark OLESEN
Committed by
Andrew Heather
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
BACKPORT: openfoam shell wrapper (interactive or 'one-shot' use)
parent
58f6258d
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
bin/tools/openfoam
+191
-0
191 additions, 0 deletions
bin/tools/openfoam
bin/tools/source-bashrc
+93
-0
93 additions, 0 deletions
bin/tools/source-bashrc
etc/config.sh/aliases
+9
-8
9 additions, 8 deletions
etc/config.sh/aliases
with
293 additions
and
8 deletions
bin/tools/openfoam
0 → 100755
+
191
−
0
View file @
b0cc93ec
#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
#
# Script
# openfoam [args]
#
# Description
# Open an interactive bash session with an OpenFOAM environment,
# or run an OpenFOAM application (with arguments) after first sourcing
# the OpenFOAM etc/bashrc file from the project directory.
#
# This script normally exists in $WM_PROJECT_DIR/bin/tools but can also
# be modified to use a hard-coded PROJECT_DIR entry and placed elsewhere
# in the filesystem (eg, /usr/bin).
#
#------------------------------------------------------------------------------
# Hard-coded value (eg, with autoconfig)
projectDir
=
"@PROJECT_DIR@"
if
[
-z
"
$projectDir
"
]
||
[
"
${
projectDir
#@
}
"
!=
"
$projectDir
"
]
then
# Auto-detect from location
toolsDir
=
"
${
0
%/*
}
"
# The bin/tools dir
projectDir
=
"
${
toolsDir
%/bin/tools
}
"
# Project dir
case
"
$projectDir
"
in
(
/bin
|
/usr/bin
|
/usr/local/bin
)
# This shouldn't happen.
# If copied to a system dir, should also be using hard-coded values!
echo
"Warning: suspicious looking project dir:
$projectDir
"
1>&2
;;
(
"
$toolsDir
"
)
# Eg, called as ./openfoam etc - need to try harder
projectDir
=
"
$(
\c
d
$(
dirname
$0
)
/../..
&&
\p
wd
-L
)
"
||
unset
projectDir
;;
esac
fi
#------------------------------------------------------------------------------
usage
()
{
exec
1>&2
while
[
"$#"
-ge
1
]
;
do
echo
"
$1
"
;
shift
;
done
cat
<<
USAGE
Usage:
${
0
##*/
}
[OPTION] [application ...]
options:
-prefix=DIR Specify alternative OpenFOAM directory
-sp Single precision
-dp Double precision
-spdp Mixed single/double precision
-int32 | -int64 The label-size
-help Print the usage
Open an interactive bash session with an OpenFOAM environment,
or run an OpenFOAM application (with arguments) after first sourcing
the OpenFOAM etc/bashrc file from the project directory:
(
$projectDir
)
For more information: www.OpenFOAM.com
USAGE
exit
1
}
#-------------------------------------------------------------------------------
# Only preserve settings for non-interactive?
if
[
"$#"
-eq
0
]
then
unset
_foamSettings FOAM_SETTINGS
else
_foamSettings
=
"
$FOAM_SETTINGS
"
fi
# Parse options
while
[
"$#"
-gt
0
]
do
case
"
$1
"
in
-h
|
-help
*
)
usage
;;
-prefix
=
*
|
-foam
=
*
)
projectDir
=
"
${
1
#*=
}
"
;;
-sp
|
-SP
)
# WM_PRECISION_OPTION=...
_foamSettings
=
"
$_foamSettings
${
_foamSettings
:+
}
WM_PRECISION_OPTION=SP"
;;
-dp
|
-DP
)
# WM_PRECISION_OPTION=...
_foamSettings
=
"
$_foamSettings
${
_foamSettings
:+
}
WM_PRECISION_OPTION=DP"
;;
-spdp
|
-SPDP
)
# WM_PRECISION_OPTION=...
_foamSettings
=
"
$_foamSettings
${
_foamSettings
:+
}
WM_PRECISION_OPTION=SPDP"
;;
-int32
|
-int64
)
# WM_LABEL_SIZE=...
_foamSettings
=
"
$_foamSettings
${
_foamSettings
:+
}
WM_LABEL_SIZE=
${
1
#-int
}
"
;;
--
)
shift
break
;;
-
*
)
echo
"Error: unknown option: '
$1
'"
1>&2
exit
1
;;
*
)
break
;;
esac
shift
done
#-------------------------------------------------------------------------------
# Remove current OpenFOAM environment
if
[
-d
"
$WM_PROJECT_DIR
"
]
&&
[
-f
"
$WM_PROJECT_DIR
/etc/config.sh/unset"
]
then
.
"
$WM_PROJECT_DIR
/etc/config.sh/unset"
fi
[
-d
"
$projectDir
"
]
||
{
echo
"Error: no project dir:
$projectDir
"
1>&2
exit
2
}
_foamSourceBashEnv
=
"
$projectDir
/etc/bashrc"
if
[
"$#"
-eq
0
]
then
# Interactive shell
_foamSourceBashEnv
=
"
$projectDir
/bin/tools/source-bashrc"
fi
[
-f
"
$_foamSourceBashEnv
"
]
||
{
echo
"Error: file not found:
$_foamSourceBashEnv
"
1>&2
exit
2
}
if
[
"$#"
-eq
0
]
then
# Source user ~/.bashrc and OpenFOAM etc/bashrc.
# 1) Can either use a tmp file, or 2) chain off to a dedicated file
# We use a dedicated file.
if
[
-n
"
$_foamSettings
"
]
then
export
FOAM_SETTINGS
=
"
$_foamSettings
"
fi
## echo "Source with $_foamSourceBashEnv with '$FOAM_SETTINGS'" 1>&2
# Interactive shell (newer bash can use --init-file instead of --rcfile)
exec
bash
--rcfile
"
$_foamSourceBashEnv
"
-i
else
# Non-interactive
# Source bashrc within a function to preserve command-line arguments
# - this will not have aliases, but working non-interactively anyhow
sourceBashrc
()
{
.
"
$_foamSourceBashEnv
"
$_foamSettings
}
sourceBashrc
exec
"
$@
"
fi
#------------------------------------------------------------------------------
This diff is collapsed.
Click to expand it.
bin/tools/source-bashrc
0 → 100644
+
93
−
0
View file @
b0cc93ec
#----------------------------------*-sh-*--------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
# \\/ M anipulation |
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
#
# File
# bin/tools/source-bashrc
#
# Description
# Source user ~/.bashrc and OpenFOAM etc/bashrc
#
# This file is normally not sourced manually,
# but from bash with the --rcfile option.
#------------------------------------------------------------------------------
# Hard-coded value (eg, with autoconfig)
projectDir
=
"@PROJECT_DIR@"
if
[
-z
"
$projectDir
"
]
||
[
"
${
projectDir
#@
}
"
!=
"
$projectDir
"
]
then
# Auto-detect (as per OpenFOAM etc/bashrc)
# --
# Assuming this file is $WM_PROJECT_DIR/bin/tools/source-bashrc,
# the next lines should work when sourced by BASH or ZSH shells.
# --
projectDir
=
"
${
BASH_SOURCE
:-${
ZSH_NAME
:+
$0
}}
"
[
-n
"
$projectDir
"
]
&&
projectDir
=
"
$(
\c
d
$(
dirname
$projectDir
)
/../..
&&
\p
wd
-L
)
"
||
unset
projectDir
fi
#------------------------------------------------------------------------------
if
[
-d
"
$projectDir
"
]
then
_foamSourceBashEnv
=
"
$projectDir
/etc/bashrc"
else
unset
_foamSourceBashEnv
fi
# Source the user bashrc first.
# Simply hope that they don't unset/reset _foamSourceBashEnv !!
if
[
-f
"
$HOME
/.bashrc"
]
then
.
"
$HOME
/.bashrc"
fi
# Source the OpenFOAM etc/bashrc
if
[
-f
"
$_foamSourceBashEnv
"
]
then
.
"
$_foamSourceBashEnv
"
$FOAM_SETTINGS
# Avoid further inheritance
unset
FOAM_SETTINGS
# Some feedback
if
[
-n
"
$PS1
"
]
&&
[
-d
"
$WM_PROJECT_DIR
"
]
then
info
=
"
$(
foamEtcFile
-show-patch
2>/dev/null
)
"
# echo "Using: OpenFOAM-$WM_PROJECT_VERSION ($FOAM_API${info:+ patch=$info}) - see www.OpenFOAM.com" 1>&2
echo
"Using: OpenFOAM-
$WM_PROJECT_VERSION
${
info
:+
(patch=
$info
)
}
- see www.OpenFOAM.com"
1>&2
echo
"Arch:
$WM_OPTIONS
(mpi=
$FOAM_MPI
)"
1>&2
## echo "$WM_PROJECT_DIR" 1>&2
## echo 1>&2
# Set prompt as reminder that this is a shell session
# Chalmers likes this one:
# PS1="OpenFOAM${FOAM_API:+-$FOAM_API}:"'$(foamPwd)\n\u\$ '
PS1
=
"OpenFOAM
${
FOAM_API
:+-
$FOAM_API
}
:"
'\w/\n\u\$ '
fi
else
echo
"Could not locate OpenFOAM etc/bashrc in '
$projectDir
'"
1>&2
fi
echo
"OpenFOAM shell session - use exit to quit"
1>&2
echo
1>&2
# Cleanup variables (done as final statement for a clean exit code)
unset
_foamSourceBashEnv projectDir
#------------------------------------------------------------------------------
This diff is collapsed.
Click to expand it.
etc/config.sh/aliases
+
9
−
8
View file @
b0cc93ec
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
# ========= |
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / O peration |
# \\ / A nd | Copyright (C) 2016-201
8
OpenCFD Ltd.
# \\ / A nd | Copyright (C) 2016-201
9
OpenCFD Ltd.
# \\/ M anipulation |
# \\/ M anipulation |
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# | Copyright (C) 2011-2016 OpenFOAM Foundation
# | Copyright (C) 2011-2016 OpenFOAM Foundation
...
@@ -111,15 +111,16 @@ foamPV()
...
@@ -111,15 +111,16 @@ foamPV()
unset
-f
foamPwd 2>/dev/null
unset
-f
foamPwd 2>/dev/null
foamPwd
()
foamPwd
()
{
{
if
[
-
d
"
$WM_PROJECT_DIR
"
]
if
[
-
n
"
$WM_PROJECT_DIR
"
]
then
then
echo
"
$PWD
"
|
sed
\
echo
"
$PWD
/"
|
sed
\
-e
"s#^
${
FOAM_RUN
}
#
\$
FOAM_RUN#;"
\
-e
"s#^
${
FOAM_RUN
}
/#
\$
FOAM_RUN/#"
\
-e
"s#^
${
WM_PROJECT_DIR
}
#
\$
WM_PROJECT_DIR#;"
\
-e
"s#^
${
WM_PROJECT_DIR
}
/#
\$
WM_PROJECT_DIR/#"
\
-e
"s#^
${
WM_PROJECT_USER_DIR
}
#
\$
WM_PROJECT_USER_DIR#;"
\
-e
"s#^
${
WM_PROJECT_USER_DIR
}
/#
\$
WM_PROJECT_USER_DIR/#"
\
-e
"s#^
${
HOME
}
#
\$
HOME#"
;
-e
"s#^
${
HOME
}
/#~/#"
\
;
else
else
echo
"
$PWD
"
|
sed
-e
"s#^
${
HOME
}
#
\$
HOME#;"
echo
"
$PWD
/
"
|
sed
-e
"s#^
${
HOME
}
/#~/#"
;
fi
fi
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment