2 #------------------------------------------------------------------------------
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
6 # \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
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_INST_DIR:-unknown}/site
34 userDir
=$HOME/.OpenFOAM
35 version
=${WM_PROJECT_VERSION:-unknown}
36 templateDir
="appTemplates"
38 #------------------------------------------------------------------------------
40 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
43 Usage: ${0##*/} [OPTION]
45 -app <name> specify the application to use
46 -case <dir> specify alternative case directory, default is the cwd
47 -list list the applications available
48 -version <ver> specify an alternative version (default: '$WM_PROJECT_VERSION')
50 clone initial application settings to the specified case from
51 $userDir/$templateDir/{$version,}/<APP>
52 $siteDir/$templateDir/{$version,}/<APP>
57 #------------------------------------------------------------------------------
58 unset appName caseName listOpt
68 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
73 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
82 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
87 usage
"unknown option: '$*'"
90 usage
"unexpected argument: '$*'"
95 # need rsync, except for when listing
96 type rsync
>/dev
/null
2>&1 ||
[ "$listOpt" = true
] || usage
"Error: 'rsync' seems to be missing"
99 #------------------------------------------------------------------------------
101 [ -n "$version" ] ||
{
102 echo "Error: no -version specified and \$WM_PROJECT_VERSION is not set"
107 # find apps in current directory
108 # considered an app if it has constant/ and system/ directories
112 for app
in $
(/bin
/ls -d * 2>/dev
/null
)
114 [ -d "$app/constant" -a -d "$app/system" ] && echo $app
120 for dir
in $userDir/$templateDir $siteDir/$templateDir
122 if cd $dir 2>/dev
/null
125 cd $version 2>/dev
/null
&& findApps
## version-specific
134 echo "applications available:"
143 if [ "$listOpt" = true
]
147 elif [ "$(echo $appList | wc -w)" -eq 0 ]
149 echo "Error: no applications available"
151 elif [ -z "$appName" ]
153 echo "Error: no -app specified"
159 # get the corresponding srcDir name
161 for dir
in $userDir/$templateDir $siteDir/$templateDir
165 for appDir
in $dir/$version/$appName $dir/$appName
167 if [ -d $appDir -a -d $appDir/constant
-a -d $appDir/system
]
178 [ -d "$srcDir" ] ||
{
179 echo "Error: could not find template for $appName"
185 # adjust for caseName as required
186 if [ -n "$caseName" ]
188 [ -d "$caseName" ] || mkdir
-p "$caseName"
189 cd "$caseName" 2>/dev
/null || usage
"directory does not exist: '$caseName'"
194 [ -d "$newDir" -a -w "$newDir" ] ||
{
195 echo "Error: target directory does not exist or is unwritable"
200 # add some useful subdirs:
201 mkdir
-p $newDir/postPro
204 echo " application $appName"
205 echo " source $srcDir"
206 echo " target $newDir"
209 # sync updated files only, itemize changes so we know what is going on
210 rsync
-aui $srcDir/ $newDir
214 # reuse or create new FOAM_SETTINGS (useful for queuing systems)
216 if [ -e "$newDir/FOAM_SETTINGS" ]
218 echo " retaining FOAM_SETTINGS"
220 echo " creating FOAM_SETTINGS"
221 cat << SETTINGS > "$newDir/FOAM_SETTINGS"
223 FOAM_VERSION=OpenFOAM-$version
229 #------------------------------------------------------------------------------