2 #------------------------------------------------------------------------------
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
6 # \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
8 #-------------------------------------------------------------------------------
10 # This file is part of OpenFOAM.
12 # OpenFOAM is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
17 # OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
18 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 # You should have received a copy of the GNU General Public License
23 # along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
29 # Create a new case from a template for particular applications
32 #------------------------------------------------------------------------------
33 siteDir
=${WM_PROJECT_SITE:-${WM_PROJECT_INST_DIR:-<unknown>}/site}
34 userDir
=$HOME/.OpenFOAM
35 version
=${WM_PROJECT_VERSION:-unknown}
36 templateDir
="appTemplates"
38 #------------------------------------------------------------------------------
41 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
44 Usage: ${0##*/} [OPTION]
46 -app <name> specify the application to use
47 -case <dir> specify alternative case directory, default is the cwd
48 -list list the applications available
49 -version <ver> specify an alternative version (default: '$WM_PROJECT_VERSION')
51 clone initial application settings to the specified case from
52 $userDir/$templateDir/{$version,}/<APP>
53 $siteDir/$templateDir/{$version,}/<APP>
58 #------------------------------------------------------------------------------
59 unset appName caseName listOpt
69 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
74 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
83 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
88 usage
"unknown option: '$*'"
91 usage
"unexpected argument: '$*'"
96 # need rsync, except for when listing
97 type rsync
>/dev
/null
2>&1 ||
[ "$listOpt" = true
] || usage
"Error: 'rsync' seems to be missing"
100 #------------------------------------------------------------------------------
102 [ -n "$version" ] ||
{
103 echo "Error: no -version specified and \$WM_PROJECT_VERSION is not set"
108 # find apps in current directory
109 # considered an app if it has constant/ and system/ directories
113 for app
in $
(/bin
/ls -d * 2>/dev
/null
)
115 [ -d "$app/constant" -a -d "$app/system" ] && echo $app
121 for dir
in $userDir/$templateDir $siteDir/$templateDir
123 if cd $dir 2>/dev
/null
126 cd $version 2>/dev
/null
&& findApps
## version-specific
135 echo "applications available:"
144 if [ "$listOpt" = true
]
148 elif [ "$(echo $appList | wc -w)" -eq 0 ]
150 echo "Error: no applications available"
152 elif [ -z "$appName" ]
154 echo "Error: no -app specified"
160 # get the corresponding srcDir name
162 for dir
in $userDir/$templateDir $siteDir/$templateDir
166 for appDir
in $dir/$version/$appName $dir/$appName
168 if [ -d $appDir -a -d $appDir/constant
-a -d $appDir/system
]
179 [ -d "$srcDir" ] ||
{
180 echo "Error: could not find template for $appName"
186 # adjust for caseName as required
187 if [ -n "$caseName" ]
189 [ -d "$caseName" ] || mkdir
-p "$caseName"
190 cd "$caseName" 2>/dev
/null || usage
"directory does not exist: '$caseName'"
195 [ -d "$newDir" -a -w "$newDir" ] ||
{
196 echo "Error: target directory does not exist or is unwritable"
201 # add some useful subdirs:
202 mkdir
-p $newDir/postPro
205 echo " application $appName"
206 echo " source $srcDir"
207 echo " target $newDir"
210 # sync updated files only, itemize changes so we know what is going on
211 rsync
-aui $srcDir/ $newDir
215 # reuse or create new FOAM_SETTINGS (useful for queuing systems)
217 if [ -e "$newDir/FOAM_SETTINGS" ]
219 echo " retaining FOAM_SETTINGS"
221 echo " creating FOAM_SETTINGS"
222 cat << SETTINGS > "$newDir/FOAM_SETTINGS"
224 FOAM_VERSION=OpenFOAM-$version
230 #------------------------------------------------------------------------------