From 6c68c34e1ac97e2d699adead50708b236e40b5a2 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sun, 2 Dec 2018 18:25:57 +0100 Subject: [PATCH 01/18] ENH: update handling of versioning and make control (issue #1010) - Use the OPENFOAM define (eg, 1806, 1812), which normally corresponds to a major release, to define an API level. This remains consistent within a release cycle and means that it is possible to manage several sub-versions and continue to have a consistent lookup. The current API value is updated automatically during the build and cached as meta data for later use, even when the wmake/ directory is missing or OpenFOAM has not yet be initialized. The version information reported on program start or with -help usage adjusted to reflect this. The build tag from git now also carries the date as being more meaningful to trace than a hash value. - Update etc/bashrc and etc/cshrc to obtain the project directory directly instead of via its prefix directory. The value obtained corresponds to an absolute path, from which the prefix directory can be obtained. The combination of these changes removes the reliance on any particular directory naming convention. For example, With an 1812 version (API level): WM_PROJECT_VERSION=myVersion installed as /some/path/somewhere/openfoam-mySandbox This makes the -prefix, -foamInstall, -projectVersion, -version values of foamEtcFiles, and similar entries for foamConfigurePaths superfluous. WM_PROJECT_INST_DIR is no longer required or used ENH: improve handling and discovery of ThirdParty - improve the flexibility and reusability of ThirdParty packs to cover various standard use cases: 1. Unpacking initial release tar files with two parallel directories - OpenFOAM-v1812/ - ThirdParty-v1812/ 2. With an adjusted OpenFOAM directory name, for whatever reason - OpenFOAM-v1812-myCustom/ - openfoam-1812-other-info/ 3. Operating with/without ThirdParty directory To handle these use cases, the following discovery is used. Note PROJECT = the OpenFOAM directory `$WM_PROJECT_DIR` PREFIX = the parent directory VERSION = `$WM_PROJECT_VERSION` API = `$WM_PROJECT_API`, as per `foamEtcFiles -show-api` 0. PROJECT/ThirdParty - for single-directory installations 1. PREFIX/ThirdParty-VERSION - this corresponds to the traditional approach 2. PREFIX/ThirdParty-vAPI - allows for an updated value of VERSION (eg, v1812-myCustom) without requiring a renamed ThirdParty. The API value would still be '1812' and the original ThirdParty-v1812/ would be found. 3. PREFIX/ThirdParty-API - this is the same as the previous example, but using an unadorned API value. This also makes sense if the chosen version name also uses the unadorned API value in its naming (eg, 1812-patch190131, 1812.19W03) 4. PREFIX/ThirdParty-common - permits maximum reuse for various versions, but only for experienced user who are aware of potential version incompatibilities Directory existence is checked as is the presence of an Allwmake file or a platforms/ directory. This reduces the potential of false positive matches and limits the selection to directories that are either with sources (has the Allwmake file), or pre-compiled binaries (has the platforms/ directory). If none of the explored directories are found to be suitable, it reverts to using a PROJECT/ThirdParty dummy location since this is within the project source tree and can be trusted to have no negative side-effects. ENH: add csh support to foamConfigurePaths - this removes the previously experienced inconsistence in config file contents. REMOVED: foamExec - was previously used when switching versions and before the bashrc/cshrc discovery logic was added. It is now obsolete. --- META-INFO/.gitignore | 5 + META-INFO/README.md | 84 +++ META-INFO/api-info | 2 + bin/foamEtcFile | 180 +++--- bin/foamExec | 145 ----- bin/foamInstallationTest | 8 +- bin/foamLog | 23 +- bin/foamNewCase | 82 ++- bin/foamUpdateCaseFileHeader | 12 +- bin/tools/change-sitedir.sh | 16 +- bin/tools/change-userdir.sh | 4 +- bin/tools/foamConfigurePaths | 260 +++++---- bin/tools/foamCreateModuleInclude | 2 +- etc/README.md | 29 + etc/README.org | 21 - etc/bashrc | 133 +---- etc/config.csh/functions | 7 + etc/config.csh/settings | 16 +- etc/config.csh/setup | 187 ++++++ etc/config.csh/unset | 1 + etc/config.sh/functions | 11 +- etc/config.sh/settings | 16 +- etc/config.sh/setup | 171 ++++++ etc/config.sh/unset | 1 + etc/cshrc | 150 +---- src/Allwmake | 2 +- .../dynamicLibrary/dynamicCode/dynamicCode.C | 1 + src/OpenFOAM/global/etcFiles/etcFiles.C | 14 +- src/OpenFOAM/global/global.Cver | 10 +- .../utilities/systemCall/systemCall.C | 1 + wmake/rules/General/version | 6 +- wmake/wmakeBuildInfo | 531 ++++++++++++++++++ wmake/wmakePrintBuild | 11 + 33 files changed, 1428 insertions(+), 714 deletions(-) create mode 100644 META-INFO/.gitignore create mode 100644 META-INFO/README.md create mode 100644 META-INFO/api-info delete mode 100755 bin/foamExec create mode 100644 etc/README.md delete mode 100644 etc/README.org create mode 100644 etc/config.csh/setup create mode 100644 etc/config.sh/setup create mode 100755 wmake/wmakeBuildInfo diff --git a/META-INFO/.gitignore b/META-INFO/.gitignore new file mode 100644 index 0000000000..eddcd95786 --- /dev/null +++ b/META-INFO/.gitignore @@ -0,0 +1,5 @@ +# Do not track build information +build-info + +# Do not track time-stamp +time-stamp diff --git a/META-INFO/README.md b/META-INFO/README.md new file mode 100644 index 0000000000..3ac2880aa3 --- /dev/null +++ b/META-INFO/README.md @@ -0,0 +1,84 @@ +# META-INFO + +Meta-information is for OpenFOAM internal use only. + +Do not rely on any files or any file contents in this directory, +or even the existence of this directory. + +The format, content and meaning may be changed at anytime without +notice. + +The information is provided here for internal documentation purposes. + +## api-info + +This file and its contents are to be tracked by git. + +- File content (api) generated by wmakeBuildInfo from OPENFOAM define + in `wmake/rules/General/general` + +- File content (patch) is manually generated content. + + +## build-info + +This file is *never* to be tracked by git, but may be present in shipped +source archives. + +- File content (branch, build) generated by wmakeBuildInfo from git + information and cached from previous wmake (api) + + +## Content types + +### api + +- 4-digit year-month (YYMM) integer corresponding to the major + release or in unusual cases an intermediate release. + +- Format is year-month, as per `date +%y%m`. + Eg, `1712` for the Dec-2017 release. + + +### patch + +- 6-digit year-month-day (YYMMDD) integer corresponding to a patch-level + for the given **released** API. + Development branches have a patch value of `0`. + +- Format is year-month-day, as per `date +%y%m%d`. + +- The first release is by definition unpatched, and thus carries + a patch value of `0`. If this release were to be patched the following + day, the patch level would jump accordingly. + +The patch value is only meaningful together with the api value. + + +## Flow of information + +Changes in the build information must be reflected in information +available in the final binaries. Conversely, it is necessary for later +distributions to have a record of the same information. + +| property | source | saved | +|-----------|---------------------------|------------| +| api | wmake/rules | api-info | +| patch | manual (api-info) | build-info | +| branch | git | build-info | +| build | git | build-info | + + +The command `wmakeBuildInfo -check` is used to determine if +the saved information needs synchronization. The command +`wmakeBuildInfo -update` preforms the synchronitzation. + + +## Notes + +The saved information is split into two separate files. The `api-info` +contains more permanent information, whereas the `build-info` is more +transient in nature. + +---- +2018-11-29 diff --git a/META-INFO/api-info b/META-INFO/api-info new file mode 100644 index 0000000000..dc411fce20 --- /dev/null +++ b/META-INFO/api-info @@ -0,0 +1,2 @@ +api=1811 +patch=0 diff --git a/bin/foamEtcFile b/bin/foamEtcFile index 1239d83e7e..e45a7fd86d 100755 --- a/bin/foamEtcFile +++ b/bin/foamEtcFile @@ -24,21 +24,20 @@ # \endcode # # The -mode option can also be used when chaining settings. -# For example, in the user ~/.OpenFOAM//config.sh/compiler +# For example, in the user ~/.OpenFOAM/config.sh/compiler # \code # eval $(foamEtcFile -sh -mode=go config.sh/compiler) # \endcode # # Environment -# - WM_PROJECT (unset defaults to OpenFOAM) -# - WM_PROJECT_VERSION (unset defaults to detect from path) -# - WM_PROJECT_SITE (unset defaults to PREFIX/site) +# - WM_PROJECT_SITE (unset defaults to PROJECT/site) # # Note -# This script must exist in one of these locations: -# - PREFIX/OpenFOAM-/bin -# - PREFIX/openfoam-/bin -# - PREFIX/openfoam/bin +# This script must exist in the project 'bin' directory +# +# The '-show-api' and '-show-patch' options implement partial logic +# from wmake/wmakeBuildInfo. +# Make sure that any changes there are also reflected here. # #------------------------------------------------------------------------------- printHelp() { @@ -52,8 +51,6 @@ options: -list (-l) List directories or files to be checked -list-test List (existing) directories or files to be checked -mode=MODE Any combination of u(user), g(group), o(other) - -prefix=DIR Specify an alternative installation prefix - -version=VER Specify alternative OpenFOAM version (eg, 1712, 1806, ...) -csh Produce 'source FILE' output for a csh eval -sh Produce '. FILE' output for a sh eval -csh-verbose As per -csh, with additional verbosity @@ -61,6 +58,9 @@ options: -config Add config directory prefix for shell type: with -csh* for a config.csh/ prefix with -sh* for a config.sh/ prefix + -show-api Print api value from wmake/rules, or meta-info and exit + -show-patch Print patch value from meta-info and exit + -with-api=NUM Specify alternative api value to search with -quiet (-q) Suppress all normal output -silent (-s) Suppress stderr, except -csh-verbose, -sh-verbose output -help Print the usage @@ -70,8 +70,8 @@ Locate user/group/other file as per '#includeEtc' Do not group single character options. Equivalent options: | -mode=MODE | -mode MODE | -m MODE - | -prefix=DIR | -prefix DIR | -p DIR - | -version=VER | -version VER | -v VER + | -prefix=DIR | -prefix DIR | -p DIR [obsolete 1812] + | -version=VER | -version VER | -v VER [obsolete 1812] Exit status 0 when the file is found. Print resolved path to stdout. @@ -98,80 +98,71 @@ die() } #------------------------------------------------------------------------------- -binDir="${0%/*}" # The bin dir -projectDir="${binDir%/bin}" # The project dir -prefixDir="${projectDir%/*}" # The prefix dir (same as $WM_PROJECT_INST_DIR) +binDir="${0%/*}" # The bin dir +projectDir="$(\cd $(dirname $binDir) && \pwd -L)" # Project dir -# Could not resolve projectDir, prefixDir? (eg, called as ./bin/foamEtcFile) -if [ "$prefixDir" = "$projectDir" ] -then - binDir="$(cd $binDir && pwd -L)" - projectDir="${binDir%/bin}" - prefixDir="${projectDir%/*}" -fi -projectDirName="${projectDir##*/}" # The project directory name - -projectVersion="$WM_PROJECT_VERSION" # Empty? - will be treated later -userDir="$HOME/.OpenFOAM" # Hard-coded as per foamVersion.H +userDir="$HOME/.OpenFOAM" # As per foamVersion.H +groupDir="${WM_PROJECT_SITE:-$projectDir/site}" # As per foamVersion.H #------------------------------------------------------------------------------- -# Guess project version or simply get the stem part of the projectDirName. -# Handle standard naming conventions: +# The API locations. See wmake/wmakeBuildInfo +rulesFile="$projectDir/wmake/rules/General/general" +metaInfoDir="$projectDir/META-INFO" + +# Get api from rules/General/general # -# * OpenFOAM-[-extra...] -# * openfoam-[-extra...] -# * openfoam +# Failure modes: +# - No api information (can't find file etc). +# -> Fatal for building, but could be OK for a stripped down version # -# - projectVersion: update unless already set +# Fallback. Get from api-info # -# Helper variables: -# - dirBase (for reassembling name) == projectDirName without the version -unset dirBase -guessVersion() +getApi() { - local version + local value - case "$projectDirName" in - (OpenFOAM-* | openfoam-*) - # Dashed naming: OpenFOAM- or openfoam- - dirBase="${projectDirName%%-*}-" - version="${projectDirName#*-}" - version="${version%%*-}" # Extra safety, eg openfoam-version-packager - ;; + value="$(sed -ne '/^ *#/!{ /WM_VERSION.*OPENFOAM=/{ s@^.*OPENFOAM= *\([0-9][0-9]*\).*@\1@p; q }}' $rulesFile 2>/dev/null)" + if [ -z "$value" ] && [ -f "$metaInfoDir/api-info" ] + then + # Fallback. Get from api-info + value="$(sed -ne 's@^ *api *= *\([0-9][0-9]*\).*@\1@p' $metaInfoDir/api-info 2>/dev/null)" + fi - (openfoam[0-9]*) - # Debian-style naming: openfoam - dirBase="openfoam" - version="${projectDirName#openfoam}" - ;; - - (*) - die "unknown/unsupported naming convention for '$projectDirName'" - ;; - esac - - # Set projectVersion if required - : ${projectVersion:=$version} + if [ -n "$value" ] + then + echo "$value" + else + return 1 + fi } -# Set projectVersion and update versionNum, projectDirName accordingly -setVersion() +# Get patch from meta-info / api-info +# +# Failure modes: +# - No patch information (can't find file etc). +# +getPatchLevel() { - projectVersion="$1" + local value - # Need dirBase when reassembling projectDirName - [ -n "$dirBase" ] || guessVersion + # Fallback. Get from api-info + value="$(sed -ne 's@^ *patch *= *\([0-9][0-9]*\).*@\1@p' $metaInfoDir/api-info 2>/dev/null)" - projectDirName="$dirBase$projectVersion" + if [ -n "$value" ] + then + echo "$value" + else + return 1 + fi } #------------------------------------------------------------------------------- optMode=ugo # Default mode is always 'ugo' unset shellOutput verboseOutput -unset optAll optConfig optList optVersion +unset optAll optConfig optList projectApi # Parse options while [ "$#" -gt 0 ] @@ -180,6 +171,19 @@ do -h | -help*) printHelp ;; + -show-api) + # Show API and exit + getApi + exit $? + ;; + -show-patch) + # Show patch level and exit + getPatchLevel + exit $? + ;; + -with-api=*) + projectApi="${1#*=}" + ;; -a | -all) optAll=true unset shellOutput verboseOutput @@ -204,13 +208,6 @@ do -mode=[ugo]*) optMode="${1#*=}" ;; - -prefix=/*) - prefixDir="${1#*=}" - prefixDir="${prefixDir%/}" - ;; - -version=*) - optVersion="${1#*=}" - ;; -m | -mode) optMode="$2" shift @@ -223,22 +220,23 @@ do ;; esac ;; - -p | -prefix) - [ "$#" -ge 2 ] || die "'$1' option requires an argument" - prefixDir="${2%/}" - shift - ;; -q | -quiet) optQuiet=true ;; -s | -silent) optSilent=true ;; - -v | -version) + + -prefix=* | -version=*) + echo "ignored defunct option '${1%%=*}'" 1>&2 + ;; + -p | -prefix | -v | -version) + # Ignored, but still need to check/discard its argument [ "$#" -ge 2 ] || die "'$1' option requires an argument" - optVersion="$2" + echo "ignored defunct option '$1'" 1>&2 shift ;; + --) shift break @@ -255,6 +253,10 @@ done #------------------------------------------------------------------------------- +# Establish the API value +[ -n "$projectApi" ] || projectApi=$(getApi) + + # Split arguments into filename (for searching) and trailing bits for shell eval # Silently remove leading ~OpenFOAM/ (as per Foam::findEtcFile) nArgs=$# @@ -279,25 +281,9 @@ then fi -# Get version information -if [ -n "$optVersion" ] -then - setVersion $optVersion -elif [ -z "$projectVersion" ] -then - guessVersion -fi - -# Updates: -# - projectDir for changes via -prefix or -version -# - groupDir for changes via -prefix -projectDir="$prefixDir/$projectDirName" -groupDir="${WM_PROJECT_SITE:-$prefixDir/site}" - - # Debugging: # echo "Installed locations:" 1>&2 -# for i in projectDir prefixDir projectDirName projectVersion +# for i in projectDir # do # eval echo "$i=\$$i" 1>&2 # done @@ -305,12 +291,12 @@ groupDir="${WM_PROJECT_SITE:-$prefixDir/site}" # Define the various places to be searched: unset dirList case "$optMode" in (*u*) # (U)ser - dirList="$dirList $userDir/$projectVersion $userDir" + dirList="$dirList $userDir/$projectApi $userDir" ;; esac case "$optMode" in (*g*) # (G)roup == site - dirList="$dirList $groupDir/$projectVersion/etc $groupDir/etc" + dirList="$dirList $groupDir/$projectApi/etc $groupDir/etc" ;; esac diff --git a/bin/foamExec b/bin/foamExec deleted file mode 100755 index 85b20547e1..0000000000 --- a/bin/foamExec +++ /dev/null @@ -1,145 +0,0 @@ -#!/bin/bash -#------------------------------------------------------------------------------ -# ========= | -# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox -# \\ / O peration | -# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation -# \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. -#------------------------------------------------------------------------------- -# License -# This file is part of OpenFOAM. -# -# OpenFOAM is free software: you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# for more details. -# -# You should have received a copy of the GNU General Public License -# along with OpenFOAM. If not, see . -# -# Script -# foamExec -# -# Description -# Usage: foamExec [-version=foamVersion] ... -# -# Runs the version of executable -# with the rest of the arguments. -# -# Can also be used for parallel runs. For example, -# \code -# mpirun -np \ -# foamExec -version=VERSION ... -parallel -# \endcode -# -# Note -# This script must exist in $WM_PROJECT_INST_DIR/OpenFOAM-/bin -# or $WM_PROJECT_INST_DIR/openfoam/bin (debian) -# -# foamEtcFile located in the same directory as this script -# -# See also -# foamEtcFile -# -#------------------------------------------------------------------------------ -usage() { - exec 1>&2 - while [ "$#" -ge 1 ]; do echo "$1"; shift; done - cat< ... - -options: - -mode=MODE Any combination of u(user), g(group), o(other) - -prefix=DIR Specify an alternative installation prefix - pass through to foamEtcFile - -version=VER Specify alternative OpenFOAM version (eg, 3.0, 1612, ...) - pass through to foamEtcFile - -help Print the usage - -Run a particular OpenFOAM version of - -USAGE - exit 1 -} - -#------------------------------------------------------------------------------- -binDir="${0%/*}" # The bin dir -projectDir="${binDir%/bin}" # The project dir -# prefixDir="${projectDir%/*}" # The prefix dir (same as $WM_PROJECT_INST_DIR) - -projectVersion="${WM_PROJECT_VERSION:-unknown}" - -unset etcOpts -# parse options -while [ "$#" -gt 0 ] -do - case "$1" in - -h | -help*) - usage - ;; - -mode=*) - etcOpts="$etcOpts $1" # pass-thru to foamEtcFile - ;; - -prefix=/*) - etcOpts="$etcOpts $1" # pass-thru to foamEtcFile - ;; - -version=*) - etcOpts="$etcOpts $1" # pass-thru to foamEtcFile - projectVersion="${1#*=}" # for reporting - ;; - -m | -mode) - [ "$#" -ge 2 ] || usage "'$1' option requires an argument" - etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile - shift - ;; - -p | -prefix) - [ "$#" -ge 2 ] || usage "'$1' option requires an argument" - etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile - shift - ;; - -v | -version) - [ "$#" -ge 2 ] || usage "'$1' option requires an argument" - etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile - projectVersion="$2" # for reporting - shift - ;; - --) - shift - break - ;; - -*) - usage "invalid option '$1'" - ;; - *) - break - ;; - esac - shift -done - - -# Find and source the OpenFOAM -# placed in function to preserve command-line arguments -sourceBashrc() -{ - rcFile="$($binDir/foamEtcFile $etcOpts bashrc)" || { - echo "Error: bashrc file could not be found for OpenFOAM-$projectVersion" 1>&2 - exit 2 - } - - . $rcFile $FOAM_SETTINGS -} - - -[ "$#" -ge 1 ] || usage "no application specified" - -sourceBashrc -exec "$@" - -#------------------------------------------------------------------------------ diff --git a/bin/foamInstallationTest b/bin/foamInstallationTest index 286bd3292c..0aa8a5edc1 100755 --- a/bin/foamInstallationTest +++ b/bin/foamInstallationTest @@ -297,9 +297,7 @@ reportExecutable() checkOpenFOAMEnvironment() { - [ -d "$WM_PROJECT_INST_DIR" ] && \ - [ -d "$WM_PROJECT_DIR" ] && \ - [ -d "$WM_THIRD_PARTY_DIR" ] || { + [ -d "$WM_PROJECT_DIR" ] && [ -d "$WM_THIRD_PARTY_DIR" ] || { echo "" echo "FATAL ERROR: OpenFOAM environment not configured." echo "" @@ -389,7 +387,6 @@ COL5="Crit" hline echo "$COL1 $COL2 $COL3 $COL5" hline -reportEnv '$WM_PROJECT_INST_DIR' noPath yes reportEnv '$WM_PROJECT_USER_DIR' noPath no reportEnv '$WM_THIRD_PARTY_DIR' noPath yes hline @@ -415,11 +412,12 @@ hline reportEnv '$FOAM_LIBBIN' '$LD_LIBRARY_PATH' yes reportEnv '$FOAM_SITE_LIBBIN' '$LD_LIBRARY_PATH' no reportEnv '$FOAM_USER_LIBBIN' '$LD_LIBRARY_PATH' no +reportEnv '$FOAM_EXT_LIBBIN' '$LD_LIBRARY_PATH' maybe reportEnv '$MPI_ARCH_PATH' '$LD_LIBRARY_PATH' yes hline #------------------------------------------------------------------------------ -heading "Third-party software" +heading "Software Components" hline echo "$(fixlen Software 9) $(fixlen Version 10) $(fixlen Location 10)" hline diff --git a/bin/foamLog b/bin/foamLog index b3beddcbb0..2603832309 100755 --- a/bin/foamLog +++ b/bin/foamLog @@ -28,11 +28,16 @@ # Description # Extract data for each time-step from a log file for graphing. # +# Environment +# WM_PROJECT_API +# WM_PROJECT_DIR +# WM_PROJECT_SITE +# #------------------------------------------------------------------------------ -Script=${0##*/} -toolsDir=${0%/*}/tools -siteDir="${WM_PROJECT_SITE:-${WM_PROJECT_DIR:-}/site}" -userDir=$HOME/.OpenFOAM +Script="${0##*/}" +toolsDir="${0%/*}/tools" +groupDir="${WM_PROJECT_SITE:-${WM_PROJECT_DIR:-}/site}" +userDir="$HOME/.OpenFOAM" usage() { exec 1>&2 @@ -85,11 +90,11 @@ cat < specify the application to use - -case specify alternative case directory, default is the cwd + -app NAME specify the application to use + -case DIR specify alternative case directory, default is the cwd -list list the applications available - -version specify an alternative version (default: '$WM_PROJECT_VERSION') + -with-api=NUM specify alternative api to use (default: \$WM_PROJECT_API) + -version VER [obsolete] + -help Print the usage clone initial application settings to the specified case from - $userDir/$templateDir/{$version,}/ - $siteDir/$templateDir/{$version,}/ + $userDir/$templateDir/{$projectApi,}/APP + $groupDir/$templateDir/{$projectApi,}/APP USAGE exit 1 } #------------------------------------------------------------------------------ -unset appName caseName listOpt +unset appName caseName optList # parse options while [ "$#" -gt 0 ] @@ -69,21 +76,23 @@ do -app) [ "$#" -ge 2 ] || usage "'$1' option requires an argument" appName="$2" - shift 2 + shift ;; -case) [ "$#" -ge 2 ] || usage "'$1' option requires an argument" caseName="$2" - shift 2 + shift ;; -l | -list) - listOpt=true - shift + optList=true ;; -v | -ver | -version) [ "$#" -ge 2 ] || usage "'$1' option requires an argument" - version="$2" - shift 2 + echo "ignored defunct option -version" 1>&2 + shift + ;; + -with-api=*) + projectApi="${1#*=}" ;; -*) usage "unknown option: '$*'" @@ -92,19 +101,16 @@ do usage "unexpected argument: '$*'" ;; esac + shift done # need rsync, except for when listing -type rsync >/dev/null 2>&1 || [ "$listOpt" = true ] || usage "Error: 'rsync' seems to be missing" +command -v rsync >/dev/null 2>&1 || \ + [ "$optList" = true ] || usage "Error: 'rsync' seems to be missing" #------------------------------------------------------------------------------ -[ -n "$version" ] || { - echo "Error: no -version specified and \$WM_PROJECT_VERSION is not set" - exit 1 -} - # # find apps in current directory # considered an app if it has constant/ and system/ directories @@ -113,18 +119,23 @@ findApps() { for app in $(/bin/ls -d * 2>/dev/null) do - [ -d "$app/constant" -a -d "$app/system" ] && echo $app + [ -d "$app/constant" -a -d "$app/system" ] && echo "$app" done } appList=$( - for dir in $userDir/$templateDir $siteDir/$templateDir + for dir in "$userDir/$templateDir" "$groupDir/$templateDir" do - if cd $dir 2>/dev/null + if cd "$dir" 2>/dev/null then findApps ## generic - cd $version 2>/dev/null && findApps ## version-specific + + ## version-specific + if [ -n "$projectApi" ] + then + cd "$projectApi" 2>/dev/null && findApps + fi fi done | sort | uniq ) @@ -142,7 +153,7 @@ listApps() } -if [ "$listOpt" = true ] +if [ "$optList" = true ] then listApps exit 0 @@ -160,11 +171,11 @@ fi # get the corresponding srcDir name srcDir=$( - for dir in $userDir/$templateDir $siteDir/$templateDir + for dir in "$userDir/$templateDir" "$groupDir/$templateDir" do if [ -d $dir ] then - for appDir in $dir/$version/$appName $dir/$appName + for appDir in "$dir/$projectApi/$appName" "$dir/$appName" do if [ -d $appDir -a -d $appDir/constant -a -d $appDir/system ] then @@ -211,21 +222,6 @@ echo " syncing ..." # sync updated files only, itemize changes so we know what is going on rsync -aui $srcDir/ $newDir - -# -# reuse or create new FOAM_SETTINGS (useful for queuing systems) -# -if [ -e "$newDir/FOAM_SETTINGS" ] -then - echo " retaining FOAM_SETTINGS" -else - echo " creating FOAM_SETTINGS" - cat << SETTINGS > "$newDir/FOAM_SETTINGS" -APPLICATION=$appName -FOAM_VERSION=OpenFOAM-$version -SETTINGS -fi - echo Done #------------------------------------------------------------------------------ diff --git a/bin/foamUpdateCaseFileHeader b/bin/foamUpdateCaseFileHeader index 23a87a0c55..11f110a045 100755 --- a/bin/foamUpdateCaseFileHeader +++ b/bin/foamUpdateCaseFileHeader @@ -4,7 +4,7 @@ # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | # \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation -# \\/ M anipulation | +# \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM. @@ -44,7 +44,7 @@ options: -help print the usage Updates the header of application files and removes consecutive blank lines. - By default, writes current OpenFOAM version in the header. + By default, writes current OpenFOAM API number version in the header. An alternative version can be specified with the -version option. USAGE @@ -74,8 +74,12 @@ do esac done -# constant width for version - default to WM_PROJECT_VERSION -version=$(printf %-36s ${version:-$WM_PROJECT_VERSION}) +# Constant width for version - default to WM_PROJECT_API + +: ${version:=$WM_PROJECT_API} +: ${version:=$WM_PROJECT_VERSION} + +version=$(printf %-36s ${version:-OPENFOAM}) [ $# -ge 1 ] || usage diff --git a/bin/tools/change-sitedir.sh b/bin/tools/change-sitedir.sh index 220f1225d2..f66504a225 100644 --- a/bin/tools/change-sitedir.sh +++ b/bin/tools/change-sitedir.sh @@ -2,7 +2,7 @@ # ========= | # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | -# \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. +# \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. # \\/ M anipulation | #------------------------------------------------------------------------------ # License @@ -25,7 +25,7 @@ # . change-sitedir.sh PREFIX [SUFFIX] # # Shortcuts (prefix) -# -prefix "$WM_PROJECT_INST_DIR/site" +# -prefix "$WM_PROJECT_DIR/../site" # -project "$WM_PROJECT_DIR/site" # -none remove from environment # @@ -46,7 +46,7 @@ # # corresponds to the standard site location: # -# $WM_PROJECT_DIR/site{/$WM_PROJECT_VERSION/platforms/$WM_OPTIONS} +# $WM_PROJECT_DIR/site{/$WM_PROJECT_API/platforms/$WM_OPTIONS} # #------------------------------------------------------------------------------ @@ -56,7 +56,7 @@ then suffix="$2" foamOldDirs="$FOAM_SITE_APPBIN $FOAM_SITE_LIBBIN \ - $WM_PROJECT_SITE $WM_PROJECT_INST_DIR/site $WM_PROJECT_DIR/site" + $WM_PROJECT_SITE $WM_PROJECT_DIR/site" foamClean=$WM_PROJECT_DIR/bin/foamCleanPath if [ -x "$foamClean" ] then @@ -66,12 +66,12 @@ then fi case "$suffix" in - -plat*) suffix="platforms/$WM_OPTIONS" ;; + -plat*) suffix="platforms/$WM_OPTIONS" ;; esac case "$prefix" in - -prefix) prefix="$WM_PROJECT_INST_DIR/site" ;; - -project) prefix="$WM_PROJECT_DIR/site" ;; - -none) unset prefix ;; + -prefix) prefix="${WM_PROJECT_DIR%/*}/site" ;; + -project) prefix="$WM_PROJECT_DIR/site" ;; + -none) unset prefix ;; esac if [ -n "$prefix" ] diff --git a/bin/tools/change-userdir.sh b/bin/tools/change-userdir.sh index d126fcfe5d..06df062b63 100644 --- a/bin/tools/change-userdir.sh +++ b/bin/tools/change-userdir.sh @@ -69,8 +69,8 @@ then -plat*) suffix="platforms/$WM_OPTIONS" ;; esac case "$prefix" in - -home) prefix="$HOME/OpenFOAM/$USER-${WM_PROJECT_VERSION:-unknown}" ;; - -none) unset prefix ;; + -home) prefix="$HOME/OpenFOAM/$USER-${WM_PROJECT_VERSION:-unknown}" ;; + -none) unset prefix ;; esac if [ -n "$prefix" ] diff --git a/bin/tools/foamConfigurePaths b/bin/tools/foamConfigurePaths index ad0ea89887..6890d35ed0 100755 --- a/bin/tools/foamConfigurePaths +++ b/bin/tools/foamConfigurePaths @@ -25,9 +25,8 @@ usage() { usage: ${0##*/} options Basic - -prefix DIR specify installation directory (eg, /opt) - -version VER specify project version (eg, 1612) - -projectName NAME specify project directory name (eg, openfoam1612) + -project-path DIR specify 'WM_PROJECT_DIR' (eg, /opt/openfoam1806-patch1) + -version VER specify project version (eg, v1806) -archOption 32|64 specify 'WM_ARCH_OPTION' architecture option -SP | -float32 specify 'WM_PRECISION_OPTION' for single precision -DP | -float64 specify 'WM_PRECISION_OPTION' for double precision @@ -61,31 +60,26 @@ Components -metis ver specify 'METIS_VERSION' -metis-path DIR specify 'METIS_ARCH_PATH' -scotch VER specify 'SCOTCH_VERSION' (eg, scotch_6.0.4) - -scotch-path DIR specify 'SCOTCH_ARCH_PATH' (eg, /opt/OpenFOAM-scotch_6.0.4) + -scotch-path DIR specify 'SCOTCH_ARCH_PATH' (eg, /opt/scotch_6.0.4) Graphics -paraview VER specify 'ParaView_VERSION' (eg, 5.4.1) + -paraview-qt VER specify 'ParaView_QT' (eg, qt-system) -paraview-path DIR specify 'ParaView_DIR' (eg, /opt/ParaView-5.4.1) -vtk VER specify 'vtk_version' (eg, VTK-7.1.0) -mesa VER specify 'mesa_version' (eg, mesa-13.0.1) Misc - -default-third default ThirdParty location: PREFIX/ThirdParty-VERSION - -no-third use PROJECT/ThirdParty for ThirdParty location - -third-path DIR specify 'WM_THIRD_PARTY_DIR' - -default-site set PREFIX/site as fallback for WM_PROJECT_SITE - -no-site use PROJECT/site as fallback for WM_PROJECT_SITE - - -sigfpe | -no-sigfpe [defunct - now under etc/controlDict] + -foamInstall DIR [obsolete] + -projectName NAME [obsolete] + -sigfpe|-no-sigfpe [obsolete - now under etc/controlDict] Adjusts hardcoded versions and installation paths (for bash, POSIX shell). Equivalent options: - -prefix -foamInstall --foamInstall - -version -foamVersion --projectVersion - -projectName --projectName + -version -foamVersion --projectVersion -archOption --archOption -third -ThirdParty -paraview --paraviewVersion | -paraviewVersion @@ -186,6 +180,31 @@ replace() done } +# Standard type of replacements. +# replace .. +# looks for "setenv KEYWORD value" +# but avoids "setenv KEYWORD" without a value +replaceCsh() +{ + local file="$1" + shift + + local key val + + while [ "$#" -ge 2 ] + do + key=$1 + val=$2 + shift 2 + + _inlineSed \ + "$file" \ + "setenv *$key [^ #]*" \ + "setenv $key $val" \ + "Replaced $key setenv by '$val'" + done +} + # Get the option's value (argument). # Die if the argument doesn't exist or is empty # $1 option @@ -196,13 +215,14 @@ getOptionValue() echo "$2" } -# Remove BASH_SOURCE and FOAM_INST_DIR=... magic that looks like this: + +# Remove BASH_SOURCE and projectDir=... magic that looks like this: # ---- -# variable=$BASH_SOURCE -# [ -n "$variable" ] && FOAM_INST_DIR= ... -# FOAM_INST_DIR=... +# projectDir=$BASH_SOURCE +# [ -n "$projectDir" ] && projectDir= ... +# projectDir=... # ---- -removeMagic() +removeBashMagic() { local file="$1" @@ -211,10 +231,33 @@ removeMagic() exit 2 # Fatal } - echo " Remove default FOAM_INST_DIR setting ($file)" + echo " Remove automatic projectDir setting ($file)" sed -i \ - -e '/^ *#/!{/\(BASH_SOURCE\|FOAM_INST_DIR=\)/s/^/##IGNORE## /}' \ + -e '/^ *#/!{/\(BASH_SOURCE\|projectDir=\)/s/^/##IGNORE## /}' \ + "$file" +} + + +# Remove set projectName=, set projectDir= magic that looks like this: +# ---- +# set projectName="$WM_PROJECT" +# set projectDir=`lsof +p $$ |& \ +# sed -n -e 's@^[^/]*@@; s@\(/'"$projectName"'[^/]*\)/etc/cshrc[^/]*@\1@p'` +# ---- +removeCshMagic() +{ + local file="$1" + + [ -f "$file" ] || { + echo "Missing file: $file" + exit 2 # Fatal + } + + echo " Remove automatic projectDir setting ($file)" + + sed -i \ + -e '/^ *#/!{\@\(projectName=\|projectDir=\|/etc/cshrc\)@s/^/##IGNORE## /}' \ "$file" } @@ -235,23 +278,15 @@ do ## Basic ## - -prefix | -foamInstall | --foamInstall) - # Replace WM_PROJECT_INST_DIR, disable FOAM_INST_DIR discovery + -project-path) + # Replace WM_PROJECT_DIR=... optionValue=$(getOptionValue "$@") - removeMagic etc/bashrc - replace etc/bashrc WM_PROJECT_INST_DIR "$optionValue" - adjusted=true - shift - ;; + replace etc/bashrc WM_PROJECT_DIR "\"$optionValue\"" + replaceCsh etc/cshrc WM_PROJECT_DIR "\"$optionValue\"" + + removeBashMagic etc/bashrc + removeCshMagic etc/cshrc - -projectName | --projectName) - # Replace basename part of WM_PROJECT_DIR=... - optionValue=$(getOptionValue "$@") - _inlineSed \ - etc/bashrc \ - 'WM_PROJECT_DIR=.*' \ - 'WM_PROJECT_DIR=$WM_PROJECT_INST_DIR/'"$optionValue" \ - "Replaced WM_PROJECT_DIR basename by $optionValue" adjusted=true shift ;; @@ -259,7 +294,8 @@ do -version | -foamVersion | --projectVersion) # Replace WM_PROJECT_VERSION=... optionValue=$(getOptionValue "$@") - replace etc/bashrc WM_PROJECT_VERSION "$optionValue" + replace etc/bashrc WM_PROJECT_VERSION "$optionValue" + replaceCsh etc/cshrc WM_PROJECT_VERSION "$optionValue" adjusted=true shift ;; @@ -275,7 +311,8 @@ do echo "WM_ARCH_OPTION already set to $optionValue" : ${adjusted:=false} else - replace etc/bashrc WM_ARCH_OPTION "$optionValue" + replace etc/bashrc WM_ARCH_OPTION "$optionValue" + replaceCsh etc/cshrc WM_ARCH_OPTION "$optionValue" adjusted=true fi shift @@ -283,20 +320,23 @@ do -SP | -float32) # Replace WM_PRECISION_OPTION=... - replace etc/bashrc WM_PRECISION_OPTION "SP" + replace etc/bashrc WM_PRECISION_OPTION "SP" + replaceCsh etc/cshrc WM_PRECISION_OPTION "SP" adjusted=true ;; -DP | -float64) # Replace WM_PRECISION_OPTION=... - replace etc/bashrc WM_PRECISION_OPTION "DP" + replace etc/bashrc WM_PRECISION_OPTION "DP" + replaceCsh etc/cshrc WM_PRECISION_OPTION "DP" adjusted=true ;; -int32 | -int64) # Replace WM_LABEL_SIZE=... optionValue="${1#-int}" - replace etc/bashrc WM_LABEL_SIZE "$optionValue" + replace etc/bashrc WM_LABEL_SIZE "$optionValue" + replaceCsh etc/cshrc WM_LABEL_SIZE "$optionValue" adjusted=true ;; @@ -306,7 +346,8 @@ do -clang) # Replace clang_version=... optionValue=$(getOptionValue "$@") - replace etc/config.sh/compiler clang_version "$optionValue" + replace etc/config.sh/compiler clang_version "$optionValue" + replace etc/config.csh/compiler clang_version "$optionValue" adjusted=true shift ;; @@ -314,7 +355,8 @@ do -gcc) # Replace gcc_version=... optionValue=$(getOptionValue "$@") - replace etc/config.sh/compiler gcc_version "$optionValue" + replace etc/config.sh/compiler gcc_version "$optionValue" + replace etc/config.csh/compiler gcc_version "$optionValue" adjusted=true shift ;; @@ -325,6 +367,9 @@ do replace etc/bashrc \ WM_COMPILER_TYPE system \ WM_COMPILER "$optionValue" + replaceCsh etc/cshrc \ + WM_COMPILER_TYPE system \ + WM_COMPILER "$optionValue" adjusted=true shift ;; @@ -335,25 +380,31 @@ do replace etc/bashrc \ WM_COMPILER_TYPE ThirdParty \ WM_COMPILER "$optionValue" + replaceCsh etc/cshrc \ + WM_COMPILER_TYPE ThirdParty \ + WM_COMPILER "$optionValue" adjusted=true shift ;; gmp-[4-9]* | gmp-system) # gcc-related package - replace etc/config.sh/compiler gmp_version "$1" + replace etc/config.sh/compiler gmp_version "$1" + replace etc/config.csh/compiler gmp_version "$1" adjusted=true ;; mpfr-[2-9]* | mpfr-system) # gcc-related package - replace etc/config.sh/compiler mpfr_version "$1" + replace etc/config.sh/compiler mpfr_version "$1" + replace etc/config.csh/compiler mpfr_version "$1" adjusted=true ;; mpc-[0-9]* | mpc-system) # gcc-related package - replace etc/config.sh/compiler mpc_version "$1" + replace etc/config.sh/compiler mpc_version "$1" + replace etc/config.csh/compiler mpc_version "$1" adjusted=true ;; @@ -363,7 +414,8 @@ do -mpi) # Explicitly set WM_MPLIB=... optionValue=$(getOptionValue "$@") - replace etc/bashrc WM_MPLIB "$optionValue" + replace etc/bashrc WM_MPLIB "$optionValue" + replaceCsh etc/bashrc WM_MPLIB "$optionValue" optMpi=system adjusted=true shift @@ -383,21 +435,29 @@ do "FOAM_MPI=$optMpi" \ "Replaced 'FOAM_MPI=$expected' setting by 'FOAM_MPI=$optMpi'" - replace etc/bashrc WM_MPLIB OPENMPI + _inlineSed etc/config.csh/mpi \ + "FOAM_MPI $expected" \ + "FOAM_MPI $optMpi" \ + "Replaced 'FOAM_MPI $expected' setting by 'FOAM_MPI $optMpi'" + + replace etc/bashrc WM_MPLIB OPENMPI + replaceCsh etc/cshrc WM_MPLIB OPENMPI adjusted=true shift ;; -openmpi-system) # Explicitly set WM_MPLIB=SYSTEMOPENMPI - replace etc/bashrc WM_MPLIB SYSTEMOPENMPI + replace etc/bashrc WM_MPLIB SYSTEMOPENMPI + replaceCsh etc/cshrc WM_MPLIB SYSTEMOPENMPI optMpi=system adjusted=true ;; -openmpi-third) # Explicitly set WM_MPLIB=OPENMPI, using default setting for openmpi - replace etc/bashrc WM_MPLIB OPENMPI + replace etc/bashrc WM_MPLIB OPENMPI + replaceCsh etc/cshrc WM_MPLIB OPENMPI optMpi=third adjusted=true ;; @@ -408,7 +468,8 @@ do -boost) # Replace boost_version=... optionValue=$(getOptionValue "$@") - replace etc/config.sh/CGAL boost_version "$optionValue" + replace etc/config.sh/CGAL boost_version "$optionValue" + replace etc/config.csh/CGAL boost_version "$optionValue" adjusted=true shift ;; @@ -416,7 +477,8 @@ do -boost-path) # Replace BOOST_ARCH_PATH=... optionValue=$(getOptionValue "$@") - replace etc/config.sh/CGAL BOOST_ARCH_PATH "$optionValue" + replace etc/config.sh/CGAL BOOST_ARCH_PATH "\"$optionValue\"" + replaceCsh etc/config.csh/CGAL BOOST_ARCH_PATH "\"$optionValue\"" adjusted=true shift ;; @@ -424,7 +486,8 @@ do -cgal) # Replace cgal_version=... optionValue=$(getOptionValue "$@") - replace etc/config.sh/CGAL cgal_version "$optionValue" + replace etc/config.sh/CGAL cgal_version "$optionValue" + replace etc/config.csh/CGAL cgal_version "$optionValue" adjusted=true shift ;; @@ -432,7 +495,8 @@ do -cgal-path) # Replace CGAL_ARCH_PATH=... optionValue=$(getOptionValue "$@") - replace etc/config.sh/CGAL CGAL_ARCH_PATH "$optionValue" + replace etc/config.sh/CGAL CGAL_ARCH_PATH "$optionValue" + replaceCsh etc/config.csh/CGAL CGAL_ARCH_PATH "$optionValue" adjusted=true shift ;; @@ -440,7 +504,8 @@ do -fftw) # Replace fftw_version=... optionValue=$(getOptionValue "$@") - replace etc/config.sh/FFTW fftw_version "$optionValue" + replace etc/config.sh/FFTW fftw_version "$optionValue" + replace etc/config.csh/FFTW fftw_version "$optionValue" adjusted=true shift ;; @@ -448,7 +513,8 @@ do -fftw-path) # Replace FFTW_ARCH_PATH=... optionValue=$(getOptionValue "$@") - replace etc/config.sh/FFTW FFTW_ARCH_PATH "$optionValue" + replace etc/config.sh/FFTW FFTW_ARCH_PATH "\"$optionValue\"" + replaceCsh etc/config.csh/FFTW FFTW_ARCH_PATH "\"$optionValue\"" adjusted=true shift ;; @@ -456,7 +522,8 @@ do -cmake) # Replace cmake_version=... optionValue=$(getOptionValue "$@") - replace etc/config.sh/paraview cmake_version "$optionValue" + replace etc/config.sh/paraview cmake_version "$optionValue" + replace etc/config.csh/paraview cmake_version "$optionValue" adjusted=true shift ;; @@ -472,7 +539,7 @@ do -kahip-path) # Replace KAHIP_ARCH_PATH=... optionValue=$(getOptionValue "$@") - replace etc/config.sh/kahip KAHIP_ARCH_PATH "$optionValue" + replace etc/config.sh/kahip KAHIP_ARCH_PATH "\"$optionValue\"" adjusted=true shift ;; @@ -488,7 +555,7 @@ do -metis-path) # Replace METIS_ARCH_PATH=... optionValue=$(getOptionValue "$@") - replace etc/config.sh/metis METIS_ARCH_PATH "$optionValue" + replace etc/config.sh/metis METIS_ARCH_PATH "\"$optionValue\"" adjusted=true shift ;; @@ -504,7 +571,7 @@ do -scotch-path | -scotchArchPath | --scotchArchPath) # Replace SCOTCH_ARCH_PATH=... optionValue=$(getOptionValue "$@") - replace etc/config.sh/scotch SCOTCH_ARCH_PATH "$optionValue" + replace etc/config.sh/scotch SCOTCH_ARCH_PATH "\"$optionValue\"" adjusted=true shift ;; @@ -519,7 +586,17 @@ do _matches "$optionValue" "$expected" || \ die "'$1' has bad value: '$optionValue'" - replace etc/config.sh/paraview ParaView_VERSION "$optionValue" + replace etc/config.sh/paraview ParaView_VERSION "$optionValue" + replaceCsh etc/config.csh/paraview ParaView_VERSION "$optionValue" + adjusted=true + shift + ;; + + -paraview-qt) + # Replace ParaView_QT=... + optionValue=$(getOptionValue "$@") + replace etc/config.sh/paraview ParaView_QT "$optionValue" + replace etc/config.csh/paraview ParaView_QT "$optionValue" adjusted=true shift ;; @@ -527,7 +604,8 @@ do -paraview-path | -paraviewInstall | --paraviewInstall) # Replace ParaView_DIR=... optionValue=$(getOptionValue "$@") - replace etc/config.sh/paraview ParaView_DIR "$optionValue" + replace etc/config.sh/paraview ParaView_DIR \""$optionValue\"" + replaceCsh etc/config.csh/paraview ParaView_DIR \""$optionValue\"" adjusted=true shift ;; @@ -535,7 +613,8 @@ do -vtk) # Replace vtk_version=... optionValue=$(getOptionValue "$@") - replace etc/config.sh/vtk vtk_version "$optionValue" + replace etc/config.sh/vtk vtk_version "$optionValue" + replace etc/config.csh/vtk vtk_version "$optionValue" adjusted=true shift ;; @@ -543,7 +622,8 @@ do -mesa) # Replace mesa_version=... optionValue=$(getOptionValue "$@") - replace etc/config.sh/vtk mesa_version "$optionValue" + replace etc/config.sh/vtk mesa_version "$optionValue" + replace etc/config.csh/vtk mesa_version "$optionValue" adjusted=true shift ;; @@ -551,55 +631,17 @@ do ## Misc ## - -no-third) - # Replace WM_THIRD_PARTY_DIR=... with location within the project dir - replace etc/bashrc WM_THIRD_PARTY_DIR '$WM_PROJECT_DIR/ThirdParty' - adjusted=true - shift - ;; - - -default-third) - # Replace WM_THIRD_PARTY_DIR=... with default location/naming - replace etc/bashrc WM_THIRD_PARTY_DIR \ - '$WM_PROJECT_INST_DIR/ThirdParty-$WM_PROJECT_VERSION' - adjusted=true - shift - ;; - - -third-path) - # Replace WM_THIRD_PARTY_DIR=... - optionValue=$(getOptionValue "$@") - replace etc/bashrc WM_THIRD_PARTY_DIR "$optionValue" - adjusted=true - shift - ;; - - -no-site) - # Replace fallback value for site within the project dir - _inlineSed \ - etc/config.sh/settings \ - '^ *siteDir=.*\/site' \ - 'siteDir=$WM_PROJECT_DIR/site' \ - "Setting fallback site-dir '\$WM_PROJECT_DIR/site'" - adjusted=true - shift - ;; - - -default-site) - # Replace WM_THIRD_PARTY_DIR=... with standard location - _inlineSed \ - etc/config.sh/settings \ - '^ *siteDir=.*\/site' \ - 'siteDir=$WM_PROJECT_INST_DIR/site' \ - "Setting fallback site-dir '\$WM_PROJECT_INST_DIR/site'" - adjusted=true - shift - ;; - -sigfpe | -no-sigfpe) echo "Enable/disable FOAM_SIGFPE now via controlDict" 1>&2 ;; + -foamInstall | --foamInstall | -projectName | --projectName) + # Removed for 1812 + optionValue=$(getOptionValue "$@") + echo "Ignoring obsolete option $1" 1>&2 + shift + ;; + *) die "unknown option/argument: '$1'" ;; diff --git a/bin/tools/foamCreateModuleInclude b/bin/tools/foamCreateModuleInclude index f8e8775ed3..9c568cb3c6 100755 --- a/bin/tools/foamCreateModuleInclude +++ b/bin/tools/foamCreateModuleInclude @@ -219,7 +219,7 @@ echo "Using openfoam: $WM_PROJECT_DIR" 1>&2 echo "==> $moduleOutput" 1>&2 # Remove some cruft -unset FOAM_JOB_DIR FOAM_RUN FOAM_SETTINGS FOAM_INST_DIR +unset FOAM_JOB_DIR FOAM_RUN FOAM_SETTINGS FOAM_INST_DIR WM_PROJECT_INST_DIR unset WM_PROJECT_USER_DIR WM_THIRD_PARTY_DIR unset SCOTCH_VERSION diff --git a/etc/README.md b/etc/README.md new file mode 100644 index 0000000000..d638115c48 --- /dev/null +++ b/etc/README.md @@ -0,0 +1,29 @@ +OpenFOAM Configuration +---------------------- + +The main OpenFOAM settings are located in the parent `etc/` directory. +Both POSIX (bash, dash,...) and csh shells are supported. +To configure OpenFOAM, source either the `etc/bashrc` or the +`etc/cshrc` file, as appropriate for your shell. + +These source the following files in the `config.sh/` or +`config.csh/` directories: + +* `setup` : finalize setup of OpenFOAM environment (called by bashrc,cshrc) +* `settings` : core settings +* `aliases` : aliases for interactive shells +* `unset` : sourced to clear as many OpenFOAM environment settings as possible +* `mpi` : MPI communications library settings +* `ensight` : application settings for EnSight +* `paraview` : application settings for ParaView +* `scotch` : application settings for compiling against scotch +* `metis` : application settings for compiling against metis + +The `config.*/example` directories contain additional example configuration +files for the corresponding shell: + +* `compiler` : an example of fine tuning ThirdParty compiler settings +* `openmpi` : an example of fine tuning openmpi settings for OpenFOAM +* `paraview` : an example of chaining to the standard config/paraview + with a different ParaView_VERSION +* `prefs`: an example of supplying alternative site-defined settings diff --git a/etc/README.org b/etc/README.org deleted file mode 100644 index 60029da36a..0000000000 --- a/etc/README.org +++ /dev/null @@ -1,21 +0,0 @@ -* OpenFOAM Configuration - The main OpenFOAM settings are located in the parent etc/ directory. The bash - and csh shells are supported and to configure OpenFOAM source etc/bashrc or - etc/cshrc respectively which source the following files in the config.sh or - config.csh respectively: - + =settings=: core settings - + =aliases=: aliases for interactive shells - + =unset=: sourced to clear as many OpenFOAM environment settings as possible - + =mpi=: MPI communications library settings - + =ensight=: application settings for EnSight - + =paraview=: application settings for ParaView - + =scotch=: application settings for compiling against scotch - + =metis=: application settings for compiling against metis 5 - - The config.*/example directories contains various example configuration files - for the corresponding shell: - + =compiler=: an example of fine tuning ThirdParty compiler settings - + =openmpi=: an example of fine tuning openmpi settings for OpenFOAM - + =paraview=: an example of chaining to the standard config/paraview with a - different ParaView_VERSION - + =prefs=: an example of supplying alternative site-defined settings diff --git a/etc/bashrc b/etc/bashrc index 3a5262af78..b38f5f5b14 100644 --- a/etc/bashrc +++ b/etc/bashrc @@ -22,9 +22,9 @@ # - $WM_PROJECT_DIR/etc/prefs.sh # # - User or group values (first file found): -# - ~/.OpenFOAM/$WM_PROJECT_VERSION/prefs.sh +# - ~/.OpenFOAM/$WM_PROJECT_API/prefs.sh # - ~/.OpenFOAM/prefs.sh -# - $WM_PROJECT_SITE/$WM_PROJECT_VERSION/etc/prefs.sh +# - $WM_PROJECT_SITE/$WM_PROJECT_API/etc/prefs.sh # - $WM_PROJECT_SITE/etc/prefs.sh # # Environment @@ -43,21 +43,22 @@ export WM_PROJECT=OpenFOAM export WM_PROJECT_VERSION=plus -# [FOAM_INST_DIR] - parent directory containing the OpenFOAM installation. +# [projectDir] - directory containing this OpenFOAM version. # \- When this file is located as $WM_PROJECT_DIR/etc/bashrc, the next lines # should work when sourced by BASH or ZSH shells. If this however fails, # set one of the fallback values to an appropriate path. -# -- -rc="${BASH_SOURCE:-${ZSH_NAME:+$0}}" -[ -n "$rc" ] && FOAM_INST_DIR="$(\cd $(dirname $rc)/../.. && \pwd -L)" || \ -FOAM_INST_DIR="$HOME/$WM_PROJECT" -# FOAM_INST_DIR="/opt/$WM_PROJECT" -# FOAM_INST_DIR="/usr/local/$WM_PROJECT" # +# This can be removed if an absolute path is provided for WM_PROJECT_DIR +# later on in this file +# -- +projectDir="${BASH_SOURCE:-${ZSH_NAME:+$0}}"; +[ -n "$projectDir" ] && projectDir="$(\cd $(dirname $projectDir)/.. && \pwd -L)" ||\ +projectDir="$HOME/OpenFOAM/OpenFOAM-$WM_PROJECT_VERSION" +# projectDir="/opt/OpenFOAM/OpenFOAM-$WM_PROJECT_VERSION" +# projectDir="/usr/local/OpenFOAM/OpenFOAM-$WM_PROJECT_VERSION" # END OF (NORMAL) USER EDITABLE PART ################################################################################ : # Safety statement (if the user removed all fallback values) -unset rc # Configuration environment variables. # Should override via file instead of editing this file. @@ -127,113 +128,31 @@ foamOldDirs="$WM_PROJECT_DIR $WM_THIRD_PARTY_DIR \ $HOME/$WM_PROJECT/$USER $FOAM_USER_APPBIN $FOAM_USER_LIBBIN \ $WM_PROJECT_SITE $FOAM_SITE_APPBIN $FOAM_SITE_LIBBIN" -# Location of installation and third-party software -export WM_PROJECT_INST_DIR=$FOAM_INST_DIR -export WM_PROJECT_DIR=$WM_PROJECT_INST_DIR/$WM_PROJECT-$WM_PROJECT_VERSION -export WM_THIRD_PARTY_DIR=$WM_PROJECT_INST_DIR/ThirdParty-$WM_PROJECT_VERSION +# [WM_PROJECT_DIR] - Location of this OpenFOAM version +export WM_PROJECT_DIR="$projectDir" # [WM_PROJECT_USER_DIR] - Location of user files -export WM_PROJECT_USER_DIR=$HOME/$WM_PROJECT/$USER-$WM_PROJECT_VERSION +export WM_PROJECT_USER_DIR="$HOME/$WM_PROJECT/$USER-$WM_PROJECT_VERSION" # [WM_PROJECT_SITE] - Location of site-specific (group) files # Default (unset) implies WM_PROJECT_DIR/site # Normally defined in calling environment -if [ -d "$WM_PROJECT_SITE" ] + +# Finalize setup of OpenFOAM environment for POSIX shell +if [ -d "$WM_PROJECT_DIR" ] then - export WM_PROJECT_SITE + if [ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] + then + echo "source $WM_PROJECT_DIR/etc/config.sh/setup" 1>&2 + fi + . "$WM_PROJECT_DIR/etc/config.sh/setup" "$@" else - unset WM_PROJECT_SITE + echo "Error: did not locate installation path for $WM_PROJECT-$WM_PROJECT_VERSION" 1>&2 + echo "No directory: $WM_PROJECT_DIR" 1>&2 fi -# Load shell functions -unset WM_SHELL_FUNCTIONS -. $WM_PROJECT_DIR/etc/config.sh/functions - -# Overrides via -# 1. other (system) values -_foamEtc -mode=o prefs.sh - -# 2. user or group values (unless disabled) -[ -z "$FOAM_CONFIG_NOUSER" ] && _foamEtc -mode=ug prefs.sh - -# Evaluate command-line parameters and record settings for later. -# These can be used to set/unset values, specify additional files etc. -FOAM_SETTINGS="$@" -if [ -z "$FOAM_SETTINGS" ] -then - unset FOAM_SETTINGS -else - export FOAM_SETTINGS - _foamEval "$@" -fi - -# Clean standard environment variables (PATH, MANPATH, LD_LIBRARY_PATH) -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -export PATH MANPATH LD_LIBRARY_PATH -_foamClean PATH "$foamOldDirs" -_foamClean MANPATH "$foamOldDirs" -_foamClean LD_LIBRARY_PATH "$foamOldDirs" - -# Setup for OpenFOAM compilation etc -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -_foamEtc -config settings - -# Setup for third-party packages -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -_foamEtc -config mpi -_foamEtc -config paraview -- "$@" # Pass through for evaluation -_foamEtc -config vtk -_foamEtc -config ensight -_foamEtc -config gperftools -## _foamEtc -config ADIOS -## _foamEtc -config ADIOS2 -_foamEtc -config CGAL -_foamEtc -config scotch -_foamEtc -config FFTW - -if [ -d "$WM_PROJECT_DIR/doc/man1" ] -then - _foamAddMan "$WM_PROJECT_DIR/doc" -fi - -# Interactive shell -if /usr/bin/tty -s 2>/dev/null -then - _foamEtc -config aliases - [ "${BASH_VERSINFO:-0}" -ge 4 ] && _foamEtc -config bash_completion -fi - - -# Clean environment paths again. Only remove duplicates -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -export PATH MANPATH LD_LIBRARY_PATH - -_foamClean PATH -_foamClean MANPATH -_foamClean LD_LIBRARY_PATH - -# Add trailing ':' for system manpages -if [ -n "$MANPATH" ] -then - MANPATH="${MANPATH}:" -fi - -if [ -n "$LD_PRELOAD" ] -then - export LD_PRELOAD - _foamClean LD_PRELOAD -fi - - -# Cleanup temporary information -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -# Unload shell functions -. $WM_PROJECT_DIR/etc/config.sh/functions - -# Variables (done as the last statement for a clean exit code) -unset FOAM_INST_DIR # Old variable name (OpenFOAM-v1606) - now unneeded -unset cleaned foamOldDirs +# Cleanup variables (done as final statement for a clean exit code) +unset foamOldDirs projectDir #------------------------------------------------------------------------------ diff --git a/etc/config.csh/functions b/etc/config.csh/functions index 7365e632bc..f78a161f74 100644 --- a/etc/config.csh/functions +++ b/etc/config.csh/functions @@ -33,6 +33,13 @@ alias _foamAddLib 'setenv LD_LIBRARY_PATH \!*\:${LD_LIBRARY_PATH}' # $2 = fallback libname ('lib' or 'lib64') alias _foamAddLibAuto 'eval `$WM_PROJECT_DIR/bin/tools/lib-dir -csh \!*`' +# Echo values when FOAM_VERBOSE is on, no-op otherwise +if ($?FOAM_VERBOSE && $?prompt) then + alias _foamEcho 'echo \!*' +else + alias _foamEcho 'true' +endif + # Source an etc file, possibly with some verbosity if ($?FOAM_VERBOSE && $?prompt) then if ($?FOAM_CONFIG_NOUSER) then diff --git a/etc/config.csh/settings b/etc/config.csh/settings index e865f46af2..ac09ece5bd 100644 --- a/etc/config.csh/settings +++ b/etc/config.csh/settings @@ -147,9 +147,6 @@ setenv WM_OPTIONS "$WM_ARCH$WM_COMPILER$WM_PRECISION_OPTION$WM_LABEL_OPTION$WM_C setenv FOAM_APPBIN "$WM_PROJECT_DIR/platforms/$WM_OPTIONS/bin" setenv FOAM_LIBBIN "$WM_PROJECT_DIR/platforms/$WM_OPTIONS/lib" -# External (ThirdParty) libraries -setenv FOAM_EXT_LIBBIN "$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER$WM_PRECISION_OPTION$WM_LABEL_OPTION/lib" - # Site-specific (group) files # Default @@ -173,7 +170,7 @@ setenv FOAM_USER_LIBBIN "$WM_PROJECT_USER_DIR/platforms/$WM_OPTIONS/lib" # Prepend wmake to the path - not required for runtime-only environment set foundDir="${WM_PROJECT_DIR}/wmake" if ( $?WM_DIR ) then - if ( -d "${WM_DIR}" ) foundDir="${WM_DIR}" + if ( -d "${WM_DIR}" ) set foundDir="${WM_DIR}" endif if ( -d "$foundDir" ) then setenv PATH "${foundDir}:${PATH}" @@ -189,8 +186,8 @@ setenv PATH "${WM_PROJECT_DIR}/bin:${PATH}" if ( -d "$siteDir/bin" ) then # Generic _foamAddPath "$siteDir/bin" endif -if ( -d "$siteDir/$WM_PROJECT_VERSION/bin" ) then # Version-specific - _foamAddPath "$siteDir/$WM_PROJECT_VERSION/bin" +if ( -d "$siteDir/$WM_PROJECT_API/bin" ) then # API-specific + _foamAddPath "$siteDir/$WM_PROJECT_API/bin" endif # OpenFOAM executables (user, group, standard) @@ -200,8 +197,11 @@ _foamAddPath "${FOAM_USER_APPBIN}:${FOAM_SITE_APPBIN}:${FOAM_APPBIN}" _foamAddLib "$FOAM_LIBBIN/dummy" # External (ThirdParty) libraries. Also allowed to be unset -if ( $?FOAM_EXT_LIBBIN ) then - _foamAddLib $FOAM_EXT_LIBBIN +if ( -d "$WM_THIRD_PARTY_DIR" ) then + setenv FOAM_EXT_LIBBIN "$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER$WM_PRECISION_OPTION$WM_LABEL_OPTION/lib" + _foamAddLib "$FOAM_EXT_LIBBIN" +else + unsetenv FOAM_EXT_LIBBIN endif # OpenFOAM libraries (user, group, standard) diff --git a/etc/config.csh/setup b/etc/config.csh/setup new file mode 100644 index 0000000000..7f02c0dcb6 --- /dev/null +++ b/etc/config.csh/setup @@ -0,0 +1,187 @@ +#----------------------------------*-sh-*-------------------------------------- +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. +# \\/ M anipulation | +#------------------------------------------------------------------------------ +# License +# This file is part of OpenFOAM, licensed under GNU General Public License +# . +# +# File +# etc/config.csh/setup +# - sourced by OpenFOAM-*/etc/cshrc +# +# Description +# Finalize setup of OpenFOAM environment for C-shell (csh, tcsh) +# +# Environment +# FOAM_VERBOSE (set/unset) +# - add extra verbosity when sourcing files +# FOAM_CONFIG_NOUSER (set/unset) +# - suppress use of user/group configuration files +# +#------------------------------------------------------------------------------ + +# [WM_PROJECT_API] - The API level for the project +setenv WM_PROJECT_API `$WM_PROJECT_DIR/bin/foamEtcFile -show-api` + +# The installation parent directory +set prefixDir="${WM_PROJECT_DIR:h}" + +# Load shell "functions" (actually aliases) +source "$WM_PROJECT_DIR/etc/config.csh/functions" + + +# [WM_THIRD_PARTY_DIR] - Location of third-party software components +# \- This may be installed in a directory parallel to the OpenFOAM project +# directory, with the same version name or using the API value. +# It may also not be required at all, in which case a dummy "ThirdParty" +# directory inside of the OpenFOAM project directory. +# +# Note: only accept if the directory exists and contains a "Allwmake" file + +setenv WM_THIRD_PARTY_DIR +set foundDir='' +_foamEcho "Locating ThirdParty directory" +foreach WM_THIRD_PARTY_DIR (\ + "$WM_PROJECT_DIR/ThirdParty" \ + "$prefixDir/ThirdParty-$WM_PROJECT_VERSION" \ + "$prefixDir/ThirdParty-v$WM_PROJECT_API" \ + "$prefixDir/ThirdParty-$WM_PROJECT_API" \ + "$prefixDir/ThirdParty-common" \ +) + _foamEcho "... $WM_THIRD_PARTY_DIR" + if ( -d "$WM_THIRD_PARTY_DIR" ) then + if ( -f "$WM_THIRD_PARTY_DIR/Allwmake" || -d "$WM_THIRD_PARTY_DIR/platforms" ) then + set foundDir=true + break + endif + endif +end + +if ( "${%foundDir}" ) then + _foamEcho "Using $WM_THIRD_PARTY_DIR" +else + # Dummy fallback value + setenv WM_THIRD_PARTY_DIR "$WM_PROJECT_DIR/ThirdParty" + _foamEcho "Dummy $WM_THIRD_PARTY_DIR" +endif +# Done with ThirdParty discovery + + +# Overrides via +# 1. other (system) values +_foamEtc -mode=o prefs.csh + +# 2. user or group values (unless disabled) +if (! $?FOAM_CONFIG_NOUSER ) then + _foamEtc -mode=ug prefs.csh +endif + + +# Capture and evaluate any command-line parameters +# These can be used to set/unset values, specify additional files etc. +setenv FOAM_SETTINGS "${*}" + +while ( $#argv > 0 ) + switch ($argv[1]) + case -*: + # Stray option (not meant for us here) -> get out + break + breaksw + case *=: + # name= -> unsetenv name + _foamEcho "unsetenv $argv[1]:s/=//" + eval "unsetenv $argv[1]:s/=//" + breaksw + case *=*: + # name=value -> setenv name value + _foamEcho "setenv $argv[1]:s/=/ /" + eval "setenv $argv[1]:s/=/ /" + breaksw + default: + # Filename: source it + if ( -f "$argv[1]" ) then + _foamEcho "Using: $argv[1]" + source "$argv[1]" + else + _foamEtc -silent "$argv[1]" + endif + breaksw + endsw + shift +end + + +# Clean standard environment variables (PATH, MANPATH, LD_LIBRARY_PATH) +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# Prevent local variables from shadowing setenv variables +unset PATH MANPATH LD_LIBRARY_PATH LD_PRELOAD +if (! $?LD_LIBRARY_PATH ) setenv LD_LIBRARY_PATH +if (! $?MANPATH ) setenv MANPATH + +_foamClean PATH "$foamOldDirs" +_foamClean MANPATH "$foamOldDirs" +_foamClean LD_LIBRARY_PATH "$foamOldDirs" + +# Setup for OpenFOAM compilation etc +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +_foamEtc -config settings + +# Setup for third-party packages +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +_foamEtc -config mpi +_foamEtc -config paraview -- "$FOAM_SETTINGS" # Pass through for evaluation +_foamEtc -config vtk +_foamEtc -config ensight +## _foamEtc -config ADIOS +## _foamEtc -config ADIOS2 +_foamEtc -config CGAL +_foamEtc -config FFTW + +if ( -d "$WM_PROJECT_DIR/doc/man1" ) then + _foamAddMan "$WM_PROJECT_DIR/doc" +endif + +# Interactive shell +if ($?prompt) then + _foamEtc -config aliases + _foamEtc -config tcsh_completion +endif + + +# Clean environment paths again. Only remove duplicates +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +_foamClean PATH +_foamClean MANPATH +_foamClean LD_LIBRARY_PATH + +# Add trailing ':' for system manpages +if ( $?MANPATH ) then + setenv MANPATH "${MANPATH}:" +endif + +if ( $?LD_PRELOAD ) then + _foamClean LD_PRELOAD +endif + + +# Cleanup temporary information +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Unload shell "functions" +unalias _foamClean +unalias _foamEcho +unalias _foamEtc +unalias _foamAddPath +unalias _foamAddMan +unalias _foamAddLib +unalias _foamAddLibAuto + +# Variables (done as final statement for a clean exit code) +unset cleaned foamOldDirs foundDir prefixDir + +#------------------------------------------------------------------------------ diff --git a/etc/config.csh/unset b/etc/config.csh/unset index 7769d74e61..b35cef97ef 100644 --- a/etc/config.csh/unset +++ b/etc/config.csh/unset @@ -59,6 +59,7 @@ unsetenv WM_OPTIONS unsetenv WM_OSTYPE unsetenv WM_PRECISION_OPTION unsetenv WM_PROJECT +unsetenv WM_PROJECT_API unsetenv WM_PROJECT_DIR unsetenv WM_PROJECT_INST_DIR unsetenv WM_PROJECT_SITE diff --git a/etc/config.sh/functions b/etc/config.sh/functions index eef3d9941d..ead8071054 100644 --- a/etc/config.sh/functions +++ b/etc/config.sh/functions @@ -40,6 +40,15 @@ then unset "foamVar_name" } + # Echo values to stderr when FOAM_VERBOSE is on, no-op otherwise + unset -f _foamEcho 2>/dev/null + if [ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] + then + _foamEcho() { echo "$@" 1>&2; } + else + _foamEcho() { true; } + fi + # Source an etc file, possibly with some verbosity # - use eval to avoid intermediate variables (ksh doesn't have 'local') unset -f _foamEtc 2>/dev/null @@ -216,7 +225,7 @@ else # Was previously loaded/defined - now unset unset -f _foamAddPath _foamAddMan _foamAddLib _foamAddLibAuto 2>/dev/null - unset -f _foamClean _foamEtc _foamEval 2>/dev/null + unset -f _foamClean _foamEcho _foamEtc _foamEval 2>/dev/null unset foamClean unset WM_SHELL_FUNCTIONS diff --git a/etc/config.sh/settings b/etc/config.sh/settings index ae63d010fe..23aec009a3 100644 --- a/etc/config.sh/settings +++ b/etc/config.sh/settings @@ -140,9 +140,6 @@ export WM_OPTIONS="$WM_ARCH$WM_COMPILER$WM_PRECISION_OPTION$WM_LABEL_OPTION$WM_C export FOAM_APPBIN="$WM_PROJECT_DIR/platforms/$WM_OPTIONS/bin" export FOAM_LIBBIN="$WM_PROJECT_DIR/platforms/$WM_OPTIONS/lib" -# External (ThirdParty) libraries -export FOAM_EXT_LIBBIN="$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER$WM_PRECISION_OPTION$WM_LABEL_OPTION/lib" - # Site-specific (group) files # Default @@ -187,9 +184,9 @@ if [ -d "$siteDir/bin" ] # Generic then _foamAddPath "$siteDir/bin" fi -if [ -d "$siteDir/$WM_PROJECT_VERSION/bin" ] # Version-specific +if [ -d "$siteDir/$WM_PROJECT_API/bin" ] # API-specific then - _foamAddPath "$siteDir/$WM_PROJECT_VERSION/bin" + _foamAddPath "$siteDir/$WM_PROJECT_API/bin" fi # OpenFOAM executables (user, group, standard) @@ -198,10 +195,13 @@ _foamAddPath "$FOAM_USER_APPBIN:$FOAM_SITE_APPBIN:$FOAM_APPBIN" # Dummy versions of external libraries. To be found last in LD_LIBRARY_PATH _foamAddLib "$FOAM_LIBBIN/dummy" -# External libraries (allowed to be unset) -if [ -n "$FOAM_EXT_LIBBIN" ] +# External (ThirdParty) libraries. Also allowed to be unset +if [ -d "$WM_THIRD_PARTY_DIR" ] then - _foamAddLib $FOAM_EXT_LIBBIN + export FOAM_EXT_LIBBIN="$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER$WM_PRECISION_OPTION$WM_LABEL_OPTION/lib" + _foamAddLib "$FOAM_EXT_LIBBIN" +else + unset FOAM_EXT_LIBBIN fi # OpenFOAM libraries (user, group, standard) diff --git a/etc/config.sh/setup b/etc/config.sh/setup new file mode 100644 index 0000000000..423605ce92 --- /dev/null +++ b/etc/config.sh/setup @@ -0,0 +1,171 @@ +#----------------------------------*-sh-*-------------------------------------- +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. +# \\/ M anipulation | +#------------------------------------------------------------------------------ +# License +# This file is part of OpenFOAM, licensed under GNU General Public License +# . +# +# File +# etc/config.sh/setup +# - sourced by OpenFOAM-*/etc/bashrc +# +# Description +# Finalize setup of OpenFOAM environment for POSIX shell. +# +# Environment +# FOAM_VERBOSE (set/unset) +# - add extra verbosity when sourcing files +# FOAM_CONFIG_NOUSER (set/unset) +# - suppress use of user/group configuration files +# +#------------------------------------------------------------------------------ + +# [WM_PROJECT_API] - The API level for the project +export WM_PROJECT_API="$($WM_PROJECT_DIR/bin/foamEtcFile -show-api)" + +# The installation parent directory +prefixDir="${WM_PROJECT_DIR%/*}" + +# Load shell functions +unset WM_SHELL_FUNCTIONS +. "$WM_PROJECT_DIR/etc/config.sh/functions" + + +# [WM_THIRD_PARTY_DIR] - Location of third-party software components +# \- This may be installed in a directory parallel to the OpenFOAM project +# directory, with the same version name or using the API value. +# It may also not be required at all, in which case a dummy "ThirdParty" +# directory inside of the OpenFOAM project directory. +# +# Note: only accept if the directory exists and contains a "Allwmake" file +export WM_THIRD_PARTY_DIR +unset foundDir + +_foamEcho "Locating ThirdParty directory" + +for WM_THIRD_PARTY_DIR in \ + "$WM_PROJECT_DIR/ThirdParty" \ + "$prefixDir/ThirdParty-$WM_PROJECT_VERSION" \ + "$prefixDir/ThirdParty-v$WM_PROJECT_API" \ + "$prefixDir/ThirdParty-$WM_PROJECT_API" \ + "$prefixDir/ThirdParty-common" \ + ; +do + _foamEcho "... $WM_THIRD_PARTY_DIR" + if [ -d "$WM_THIRD_PARTY_DIR" ] + then + if [ -f "$WM_THIRD_PARTY_DIR/Allwmake" ] || \ + [ -d "$WM_THIRD_PARTY_DIR/platforms" ] + then + foundDir=true + break + fi + fi +done + +if [ -n "$foundDir" ] +then + _foamEcho "Using $WM_THIRD_PARTY_DIR" +else + # Dummy fallback value + WM_THIRD_PARTY_DIR="$WM_PROJECT_DIR/ThirdParty" + _foamEcho "Dummy $WM_THIRD_PARTY_DIR" +fi +# Done with ThirdParty discovery + + +# Overrides via +# 1. other (system) values +_foamEtc -mode=o prefs.sh + +# 2. user or group values (unless disabled) +[ -z "$FOAM_CONFIG_NOUSER" ] && _foamEtc -mode=ug prefs.sh + + +# Capture and evaluate any command-line parameters +# These can be used to set/unset values, specify additional files etc. +FOAM_SETTINGS="$@" + +# Evaluate the command-line parameters, which were saved as FOAM_SETTINGS. +# These can be used to set/unset values, specify additional files etc. +if [ -z "$FOAM_SETTINGS" ] +then + unset FOAM_SETTINGS +else + export FOAM_SETTINGS + _foamEval "$@" +fi + + +# Clean standard environment variables (PATH, MANPATH, LD_LIBRARY_PATH) +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +export PATH MANPATH LD_LIBRARY_PATH +_foamClean PATH "$foamOldDirs" +_foamClean MANPATH "$foamOldDirs" +_foamClean LD_LIBRARY_PATH "$foamOldDirs" + +# Setup for OpenFOAM compilation etc +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +_foamEtc -config settings + +# Setup for third-party packages +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +_foamEtc -config mpi +_foamEtc -config paraview -- "$@" # Pass through for evaluation +_foamEtc -config vtk +_foamEtc -config ensight +_foamEtc -config gperftools +## _foamEtc -config ADIOS +## _foamEtc -config ADIOS2 +_foamEtc -config CGAL +_foamEtc -config scotch +_foamEtc -config FFTW + +if [ -d "$WM_PROJECT_DIR/doc/man1" ] +then + _foamAddMan "$WM_PROJECT_DIR/doc" +fi + +# Interactive shell +if /usr/bin/tty -s 2>/dev/null +then + _foamEtc -config aliases + [ "${BASH_VERSINFO:-0}" -ge 4 ] && _foamEtc -config bash_completion +fi + + +# Clean environment paths again. Only remove duplicates +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +export PATH MANPATH LD_LIBRARY_PATH + +_foamClean PATH +_foamClean MANPATH +_foamClean LD_LIBRARY_PATH + +# Add trailing ':' for system manpages +if [ -n "$MANPATH" ] +then + MANPATH="${MANPATH}:" +fi + +if [ -n "$LD_PRELOAD" ] +then + export LD_PRELOAD + _foamClean LD_PRELOAD +fi + + +# Cleanup temporary information +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Unload shell functions +. "$WM_PROJECT_DIR/etc/config.sh/functions" + +# Variables (done as the last statement for a clean exit code) +unset cleaned foamOldDirs foundDir prefixDir + +#------------------------------------------------------------------------------ diff --git a/etc/config.sh/unset b/etc/config.sh/unset index 4ebfe76185..4d3c5fd0e4 100644 --- a/etc/config.sh/unset +++ b/etc/config.sh/unset @@ -50,6 +50,7 @@ unset WM_OPTIONS unset WM_OSTYPE unset WM_PRECISION_OPTION unset WM_PROJECT +unset WM_PROJECT_API unset WM_PROJECT_DIR unset WM_PROJECT_INST_DIR unset WM_PROJECT_SITE diff --git a/etc/cshrc b/etc/cshrc index 28b93b5ef9..971041cfa8 100644 --- a/etc/cshrc +++ b/etc/cshrc @@ -22,10 +22,10 @@ # - $WM_PROJECT_DIR/etc/prefs.csh # # - User or group values (first file found): -# - ~/.OpenFOAM/$WM_PROJECT_VERSION/prefs.csh +# - ~/.OpenFOAM/$WM_PROJECT_API/prefs.csh # - ~/.OpenFOAM/prefs.csh -# - $WM_PROJECT_SITE/$WM_PROJECT_VERSION/etc/prefs.csh -# - $WM_PROJECT_SITE/etc/prefs.csh +# - $WM_PROJECT_SITE/$WM_PROJECT_API/etc/prefs.csh +# - $WM_PROJECT_SITE/prefs.csh # # Environment # FOAM_VERBOSE (set/unset) @@ -43,17 +43,22 @@ setenv WM_PROJECT OpenFOAM setenv WM_PROJECT_VERSION plus -# [FOAM_INST_DIR] - parent directory containing the OpenFOAM installation. +# [projectDir] - parent directory containing the OpenFOAM installation. # \- When this file is located as $WM_PROJECT_DIR/etc/cshrc, the next lines # should work when sourced by CSH or TCSH shells. If this however fails, # set one of the fallback values to an appropriate path. -# -- -set FOAM_INST_DIR=`lsof +p $$ |& \ - sed -n -e 's@[^/]*@@' -e 's@/'$WM_PROJECT'[^/]*/etc/cshrc.*@@p'` -# set FOAM_INST_DIR=$HOME/$WM_PROJECT -# set FOAM_INST_DIR=/opt/$WM_PROJECT -# set FOAM_INST_DIR=/usr/local/$WM_PROJECT # +# This can be removed if an absolute path is provided for WM_PROJECT_DIR +# later on in this file. +# -- +# If the directory naming does not match WM_PROJECT, need to change here +set projectName="$WM_PROJECT" +set projectDir=`lsof +p $$ |& \ + sed -n -e 's@^[^/]*@@; s@\(/'"$projectName"'[^/]*\)/etc/cshrc[^/]*@\1@p'` + +# set projectDir="$HOME/OpenFOAM/OpenFOAM-$WM_PROJECT_VERSION" +# set projectDir="/opt/OpenFOAM/OpenFOAM-$WM_PROJECT_VERSION" +# set projectDir="/usr/local/OpenFOAM/OpenFOAM-$WM_PROJECT_VERSION" # END OF (NORMAL) USER EDITABLE PART ################################################################################ @@ -138,10 +143,8 @@ if ( $?FOAM_SITE_LIBBIN ) then set foamOldDirs="$foamOldDirs $FOAM_SITE_LIBBIN" endif -# Location of installation and third-party software -setenv WM_PROJECT_INST_DIR $FOAM_INST_DIR -setenv WM_PROJECT_DIR $WM_PROJECT_INST_DIR/$WM_PROJECT-$WM_PROJECT_VERSION -setenv WM_THIRD_PARTY_DIR $WM_PROJECT_INST_DIR/ThirdParty-$WM_PROJECT_VERSION +# [WM_PROJECT_DIR] - Location of this OpenFOAM version +setenv WM_PROJECT_DIR "$projectDir" # [WM_PROJECT_USER_DIR] - Location of user files setenv WM_PROJECT_USER_DIR "$HOME/$WM_PROJECT/$LOGNAME-$WM_PROJECT_VERSION" @@ -157,118 +160,17 @@ else unsetenv WM_PROJECT_SITE endif -# Load shell "functions" (actually aliases) -source $WM_PROJECT_DIR/etc/config.csh/functions -# Overrides via -# 1. other (system) values -_foamEtc -mode=o prefs.csh - -# 2. user or group values (unless disabled) -if (! $?FOAM_CONFIG_NOUSER ) then - _foamEtc -mode=ug prefs.csh +# Finalize setup of OpenFOAM environment +if ( -d "$WM_PROJECT_DIR" ) then + if ($?FOAM_VERBOSE && $?prompt) echo "source $WM_PROJECT_DIR/etc/config.csh/setup" + source "$WM_PROJECT_DIR/etc/config.csh/setup" "${*}" +else + echo "Error: did not locate installation path for $WM_PROJECT-$WM_PROJECT_VERSION" + echo "No directory: $WM_PROJECT_DIR" endif -# Evaluate command-line parameters and record settings for later. -# These can be used to set/unset values, specify additional files etc. -setenv FOAM_SETTINGS "${*}" -while ( $#argv > 0 ) - switch ($argv[1]) - case -*: - # Stray option (not meant for us here) -> get out - break - breaksw - case *=: - # name= -> unsetenv name - if ($?FOAM_VERBOSE && $?prompt) echo "unsetenv $argv[1]:s/=//" - eval "unsetenv $argv[1]:s/=//" - breaksw - case *=*: - # name=value -> setenv name value - if ($?FOAM_VERBOSE && $?prompt) echo "setenv $argv[1]:s/=/ /" - eval "setenv $argv[1]:s/=/ /" - breaksw - default: - # Filename: source it - if ( -f "$argv[1]" ) then - if ($?FOAM_VERBOSE && $?prompt) echo "Using: $argv[1]" - source "$argv[1]" - else - _foamEtc -silent "$argv[1]" - endif - breaksw - endsw - shift -end - - -# Clean standard environment variables (PATH, MANPATH, LD_LIBRARY_PATH) -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Prevent local variables from shadowing setenv variables -unset PATH MANPATH LD_LIBRARY_PATH LD_PRELOAD -if (! $?LD_LIBRARY_PATH ) setenv LD_LIBRARY_PATH -if (! $?MANPATH ) setenv MANPATH - -_foamClean PATH "$foamOldDirs" -_foamClean MANPATH "$foamOldDirs" -_foamClean LD_LIBRARY_PATH "$foamOldDirs" - -# Setup for OpenFOAM compilation etc -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -_foamEtc -config settings - -# Setup for third-party packages -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -_foamEtc -config mpi -_foamEtc -config paraview -- "$FOAM_SETTINGS" # Pass through for evaluation -_foamEtc -config vtk -_foamEtc -config ensight -## _foamEtc -config ADIOS -## _foamEtc -config ADIOS2 -_foamEtc -config CGAL -_foamEtc -config FFTW - -if ( -d "$WM_PROJECT_DIR/doc/man1" ) then - _foamAddMan "$WM_PROJECT_DIR/doc" -endif - -# Interactive shell -if ($?prompt) then - _foamEtc -config aliases - _foamEtc -config tcsh_completion -endif - - -# Clean environment paths again. Only remove duplicates -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -_foamClean PATH -_foamClean MANPATH -_foamClean LD_LIBRARY_PATH - -# Add trailing ':' for system manpages -if ( $?MANPATH ) then - setenv MANPATH "${MANPATH}:" -endif - -if ( $?LD_PRELOAD ) then - _foamClean LD_PRELOAD -endif - - -# Cleanup temporary information -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -# Unload shell "functions" -unalias _foamClean -unalias _foamEtc -unalias _foamAddPath -unalias _foamAddMan -unalias _foamAddLib -unalias _foamAddLibAuto - -# Variables (done as the last statement for a clean exit code) -unset FOAM_INST_DIR # Old variable name (OpenFOAM-v1606) - now unneeded -unset cleaned foamOldDirs +# Cleanup variables (done as final statement for a clean exit code) +unset foamOldDirs projectDir projectName #------------------------------------------------------------------------------ diff --git a/src/Allwmake b/src/Allwmake index bb96a54004..7742d3502c 100755 --- a/src/Allwmake +++ b/src/Allwmake @@ -16,7 +16,7 @@ cd ${0%/*} && wmakeCheckPwd "$WM_PROJECT_DIR/src" 2>/dev/null || { #------------------------------------------------------------------------------ # Trigger update of version strings as required -wmakePrintBuild -check || wrmo OpenFOAM/global/global.o 2>/dev/null +wmakeBuildInfo -check || wrmo OpenFOAM/global/global.o 2>/dev/null wmakeLnInclude -u OpenFOAM wmakeLnInclude -u OSspecific/"${WM_OSTYPE:-POSIX}" diff --git a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C index 6e564d58c6..0e92a02440 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C +++ b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C @@ -81,6 +81,7 @@ void Foam::dynamicCode::checkSecurity << " allowSystemOperations 1" << nl << nl << "to the InfoSwitches setting in the system controlDict." << nl << "The system controlDict is any of" << nl << nl + << " ~/.OpenFOAM/" << OPENFOAM << "/controlDict" << nl << " ~/.OpenFOAM/controlDict" << nl << " $WM_PROJECT_DIR/etc/controlDict" << nl << endl << exit(FatalIOError); diff --git a/src/OpenFOAM/global/etcFiles/etcFiles.C b/src/OpenFOAM/global/etcFiles/etcFiles.C index 68cdfd067b..c192baab4c 100644 --- a/src/OpenFOAM/global/etcFiles/etcFiles.C +++ b/src/OpenFOAM/global/etcFiles/etcFiles.C @@ -119,18 +119,8 @@ Foam::fileNameList searchEtc bool (*accept)(const Foam::fileName&) ) { - Foam::fileName version(Foam::getEnv("WM_PROJECT_VERSION")); - - // Fallback when WM_PROJECT_VERSION is unset - if (version.empty()) - { - #if OPENFOAM - version.assign(std::to_string(OPENFOAM)); - #else - version.assign(foamVersion::version); - #endif - } - + // Could use foamVersion::api, but this more direct. + const Foam::fileName version(std::to_string(OPENFOAM)); Foam::fileNameList list; Foam::fileName dir, candidate; diff --git a/src/OpenFOAM/global/global.Cver b/src/OpenFOAM/global/global.Cver index 5e8e56ad5a..1f27a0f91b 100644 --- a/src/OpenFOAM/global/global.Cver +++ b/src/OpenFOAM/global/global.Cver @@ -26,8 +26,8 @@ Description It is important that these are constructed in the appropriate order to avoid the use of unconstructed data in the global namespace. - This file has the extension .Cver to trigger a Makefile rule that converts - 'VERSION\_STRING' and 'BUILD\_STRING' into the appropriate strings. + This file has a '.Cver' extension to trigger a Makefile rule to replace + 'BUILD', 'VERSION' tags with the corresponding strings. \*---------------------------------------------------------------------------*/ @@ -48,14 +48,14 @@ const int Foam::foamVersion::api // Value of PATCH generated by the build-script const std::string Foam::foamVersion::patch ( - "" + "@PATCH@" ); // Value of the BUILD generated by the build-script const std::string Foam::foamVersion::build ( - "BUILD_STRING" + "@BUILD@" ); @@ -78,7 +78,7 @@ const std::string Foam::foamVersion::buildArch // Only required for compatibility const std::string Foam::foamVersion::version ( - "VERSION_STRING" + "@VERSION@" ); diff --git a/src/functionObjects/utilities/systemCall/systemCall.C b/src/functionObjects/utilities/systemCall/systemCall.C index 4d5c816ec7..26d19cd558 100644 --- a/src/functionObjects/utilities/systemCall/systemCall.C +++ b/src/functionObjects/utilities/systemCall/systemCall.C @@ -127,6 +127,7 @@ bool Foam::functionObjects::systemCall::read(const dictionary& dict) << " allowSystemOperations 1" << nl << nl << "to the InfoSwitches setting in the system controlDict." << nl << "The system controlDict is any of" << nl << nl + << " ~/.OpenFOAM/" << OPENFOAM << "/controlDict" << nl << " ~/.OpenFOAM/controlDict" << nl << " $WM_PROJECT_DIR/etc/controlDict" << nl << endl << exit(FatalError); diff --git a/wmake/rules/General/version b/wmake/rules/General/version index ef3aa5c37d..08400d12cc 100644 --- a/wmake/rules/General/version +++ b/wmake/rules/General/version @@ -2,11 +2,9 @@ SUFFIXES += .Cver -# Update version strings in C++ file and in $WM_PROJECT_DIR/.build file +# Update strings in C++ file and in META-INFO files Cvertoo = \ - sed -e 's!VERSION_STRING!$(shell wmakePrintBuild -major)!' \ - -e 's!BUILD_STRING!$(shell wmakePrintBuild -update)!' \ - $< > $(@D)/$( $(@D)/$(. +# +# Script +# wmakeBuildInfo +# +# Description +# Print the version used when building the project +# +# Environment +# - WM_PROJECT_DIR +# - WM_DIR (unset defaults to WM_PROJECT_DIR/wmake) +# +# Note +# Partial logic is also implemented in the bin/foamEtcFile +# -show-api and -show-patch options. +# Make sure that any changes here are also reflected there. +# +#------------------------------------------------------------------------------ +# Locations +rulesFile="${WM_DIR:-$WM_PROJECT_DIR/wmake}/rules/General/general" +metaInfoDir="$WM_PROJECT_DIR/META-INFO" + +usage() { + exec 1>&2 + + while [ "$#" -ge 1 ]; do echo "$1"; shift; done + cat<&2 + echo + echo "Error encountered:" + while [ "$#" -ge 1 ]; do echo " $1"; shift; done + echo + echo "See '${0##*/} -help' for usage" + echo + exit 1 +} + +#------------------------------------------------------------------------------ +# Parse arguments and options +#------------------------------------------------------------------------------ +unset optCheck optDryRun optUpdate optQuery optFilter + +while [ "$#" -gt 0 ] +do + case "$1" in + -h | -help*) + usage + ;; + -check) + optCheck=true + ;; + -diff) + optCheck=verbose + ;; + -dry-run) + optDryRun=true + ;; + -update) + optUpdate=true + ;; + -query) + optQuery="make:meta" + ;; + -query-make | -query-meta) + optQuery="$optQuery:${1##*-}" + ;; + -show-api) + optQuery="api" + ;; + -show-patch) + optQuery="patch" + ;; + -filter) + optFilter=true + shift # Stop here, a file name follows + break + ;; + *) + die "unknown option/argument: '$1'" + ;; + esac + shift +done + +#------------------------------------------------------------------------------ + +if [ "$optFilter" = true ] +then + [ -f "$1" ] || { + echo "Error in ${0##*/}: file not found '$1'" 1>&2 + exit 2 + } + + # Disable other methods that generate output to stdout + unset optCheck optQuery +else + [ "$#" -eq 0 ] || die "Unexpected option/arguments $@" + + # Nothing specified? Default to -query-make + if [ -z "$optCheck$optUpdate$optQuery" ] + then + optQuery="make" + fi +fi + + +#------------------------------------------------------------------------------ + +# Variables +declare -A makeInfo +declare -A metaInfo + +# +# Populate makeInfo array +# +# - api : from rules/General/general +# - patch : cached value from previous make +# - branch : from git +# - build : from git +# +# Failure modes: +# - No api information (can't find file etc). +# -> FATAL: should never happen. +# +# - No git installed or no git repo +# -> branch and build are populated as empty strings +# +# - Working on detached head. +# -> branch has value "HEAD" instead of something more readable. +# +getMakeInfo() +{ + local api patch build branch + makeInfo=() + + # (api) from WM_DIR/rules/General/general + # - extract WM_VERSION = OPENFOAM= + + api="$(sed -ne '/^ *#/!{ /WM_VERSION.*OPENFOAM=/{ s@^.*OPENFOAM= *\([0-9][0-9]*\).*@\1@p; q }}' $rulesFile 2>/dev/null)" + + if [ -d "$metaInfoDir" ] + then + # (patch) from build-info - not from api-info + patch="$(sed -ne 's@^patch *= *\([0-9][0-9]*\).*@\1@p' $metaInfoDir/build-info 2>/dev/null)" + fi + + # Build info from git + build="$(git --git-dir=$WM_PROJECT_DIR/.git log -1 --date='format:%y%m%d' --format='%h-%ad' 2>/dev/null)" + + # Branch info from git + if [ -n "$build" ] + then + branch="$(git --git-dir=$WM_PROJECT_DIR/.git rev-parse --abbrev-ref HEAD 2>/dev/null)" + fi + + makeInfo[api]="$api" + makeInfo[patch]="${patch:-0}" # default is 0 + makeInfo[branch]="$branch" + makeInfo[build]="$build" + makeInfo[cached]=true +} + + +# +# Populate metaInfo array +# +# - api : from META-INFO/api-info +# - patch : from META-INFO/api-info +# - branch : from META-INFO/build-info +# - build : from META-INFO/build-info +# +# Failure modes: +# - Directory, file or entry not found. +# -> corresponding entries are empty strings +# +getMetaInfo() +{ + local api patch build branch + metaInfo=() + + if [ -d "$metaInfoDir" ] + then + # (api, patch) from api-info + # (branch, build) from build-info + + api="$(sed -ne 's@^api *= *\([0-9][0-9]*\).*@\1@p' $metaInfoDir/api-info 2>/dev/null)" + patch="$(sed -ne 's@^patch *= *\([0-9][0-9]*\).*@\1@p' $metaInfoDir/api-info 2>/dev/null)" + branch="$(sed -ne 's@^branch *= *\([^ ]*\).*@\1@p' $metaInfoDir/build-info 2>/dev/null)" + build="$(sed -ne 's@^build *= *\([^ ]*\).*@\1@p' $metaInfoDir/build-info 2>/dev/null)" + fi + + metaInfo[api]="$api" + metaInfo[patch]="${patch:-0}" # default is 0 + metaInfo[branch]="$branch" + metaInfo[build]="$build" + metaInfo[cached]=true +} + + +# +# Get api from rules/General/general +# +# Failure modes: +# - No api information (can't find file etc). +# -> Fatal for building, but could be OK for a stripped down version +# +# Fallback. Get from api-info +# +getApi() +{ + [ -n "${makeInfo[cached]}" ] || getMakeInfo + + # Local copy + local api="${makeInfo[api]}" + + if [ -z "$api" ] + then + [ -n "${metaInfo[cached]}" ] || getMetaInfo + api="${metaInfo[api]}" + fi + + if [ -n "$api" ] + then + echo "$api" + else + return 1 + fi +} + + +# Get patch from meta-info / api-info +# +# Failure modes: +# - No patch information (can't find file etc). +# +getPatchLevel() +{ + [ -n "${metaInfo[cached]}" ] || getMetaInfo + + # Local copy + local value="${metaInfo[patch]}" + + if [ -n "$value" ] + then + echo "$value" + else + return 1 + fi +} + + +# Report make info +reportMakeInfo() +{ + local key + + [ -n "${makeInfo[cached]}" ] || getMakeInfo + [ -n "${metaInfo[cached]}" ] || getMetaInfo + + local patch="${metaInfo[patch]}" # <- From meta-info only + makeInfo[patch]="${patch:=0}" # Extra safety + + echo "make" + for key in api patch branch build + do + echo " $key = ${makeInfo[$key]}" + done +} + + +# Report meta info +reportMetaInfo() +{ + local key + + [ -n "${metaInfo[cached]}" ] || getMetaInfo + + local patch="${metaInfo[patch]}" # <- From meta-info only + metaInfo[patch]="${patch:=0}" # Extra safety + + echo "meta" + for key in api patch branch build + do + echo " $key = ${metaInfo[$key]}" + done +} + + +# Test make vs meta info. +# Return 0 for no differences, 1 otherwise +# $1 == verbose, print as diff. Silent otherwise +checkDiff() +{ + local verbose="$1" + local key diff + + [ -n "${makeInfo[cached]}" ] || getMakeInfo + [ -n "${metaInfo[cached]}" ] || getMetaInfo + + for key in api patch branch build + do + if [ "${makeInfo[$key]}" != "${metaInfo[$key]}" ] + then + diff="$diff $key" + fi + done + + if [ "$verbose" = verbose ] && [ -n "$diff" ] + then + echo "Differences" + for key in $diff + do + echo "$key:" + echo " make ${makeInfo[$key]}" + echo " meta ${metaInfo[$key]}" + done + fi + + test -z "$diff" +} + + +# +# Update metaInfo (on disk) based on the makeInfo +# +performUpdate() +{ + [ -n "${makeInfo[cached]}" ] || getMakeInfo + [ -n "${metaInfo[cached]}" ] || getMetaInfo + + # Local copies of the make info + local api="${makeInfo[api]}" + local branch="${makeInfo[branch]}" + local build="${makeInfo[build]}" + local patch="${makeInfo[patch]}" + + # If any of the make-info are empty (bad), + # use the meta-info to avoid spurious changes + [ -n "$api" ] || api="${metaInfo[api]}" + [ -n "$branch" ] || branch="${metaInfo[branch]}" + [ -n "$build" ] || build="${metaInfo[build]}" + + local outputFile + + # build-info + outputFile="$metaInfoDir/build-info" + if [ "$branch" != "${metaInfo[branch]}" ] || \ + [ "$build" != "${metaInfo[build]}" ] || \ + [ "$patch" != "${metaInfo[patch]}" ] + then + patch="${metaInfo[patch]}" # <- From meta-info only + : "${patch:=0}" # Extra safety + + if [ -n "$optDryRun" ] + then + echo "dry-run (update) ${outputFile##*/} branch=${branch}" 1>&2 + echo "dry-run (update) ${outputFile##*/} build=${build}" 1>&2 + echo "dry-run (update) ${outputFile##*/} patch=${patch}" 1>&2 + else + echo "branch=${branch}" >| "$outputFile" + echo "build=${build}" >> "$outputFile" + echo "patch=${patch}" >> "$outputFile" + fi + fi + + + # api-info + outputFile="$metaInfoDir/api-info" + if [ "$api" != "${metaInfo[api]}" ] + then + patch="${metaInfo[patch]}" # <- From meta-info only + : "${patch:=0}" # Extra safety + + if [ -n "$optDryRun" ] + then + echo "dry-run (update) ${outputFile##*/} api=${api}" 1>&2 + echo "dry-run (update) ${outputFile##*/} patch=${patch}" 1>&2 + else + echo "api=${api}" >| "$outputFile" + echo "patch=${patch}" >> "$outputFile" + fi + fi + + return 0 +} + + +# +# Update metaInfo (on disk) based on the makeInfo +# This is the +# +performFiltering() +{ + local input="$1" + + [ -f "$input" ] || { + echo "Error in ${0##*/}: file not found '$1'" 1>&2 + exit 2 + } + + [ -n "${makeInfo[cached]}" ] || getMakeInfo + [ -n "${metaInfo[cached]}" ] || getMetaInfo + + # Local copies of the make info + local api="${makeInfo[api]}" + local branch="${makeInfo[branch]}" + local build="${makeInfo[build]}" + local patch="${metaInfo[patch]}" # <- From meta-info only + : "${patch:=0}" # Extra safety + + + # If any of the make-info are empty (bad), + # conjure up something from the meta-info + + # api is not normally needed (available directly from -Ddefine) + # but we may wish to filter other types of files + + if [ -z "$api" ] + then + api="${metaInfo[api]}" + api="${api:-0}" # integer value + fi + + # branch/build could be missing for non-git + if [ -z "$branch" ] + then + branch="${metaInfo[branch]}" + branch="${branch:-unknown}" + fi + if [ -z "$build" ] + then + build="${metaInfo[build]}" + build="nogit${build:+-$build}" + fi + + sed \ + -e 's!@API@!'"${api}"'!g' \ + -e 's!@PATCH@!'"${patch:-0}"'!g' \ + -e 's!@BRANCH@!'"${branch}"'!g' \ + -e 's!@BUILD@!'"${build}"'!g' \ + -e 's!@VERSION@!'"${WM_PROJECT_VERSION}"'!g' \ + "$input" + + return 0 +} + + +#------------------------------------------------------------------------------ + +# Dispatching + +if [ -n "$optCheck" ] +then + checkDiff $optCheck + exit $? +elif [ "$optQuery" = api ] +then + # Show API and exit + getApi + exit $? +elif [ "$optQuery" = patch ] +then + # Show patch level and exit + getPatchLevel + exit $? +else + # Other queries + case "$optQuery" in (*make*) reportMakeInfo ;; esac + case "$optQuery" in (*meta*) reportMetaInfo ;; esac +fi + +[ -n "$optUpdate" ] && performUpdate + +if [ -n "$optFilter" ] +then + # Perform filter on file + performFiltering "$1" +fi + +exit 0 # clean exit + +#------------------------------------------------------------------------------ diff --git a/wmake/wmakePrintBuild b/wmake/wmakePrintBuild index 6c7941114a..bafd96bb6c 100755 --- a/wmake/wmakePrintBuild +++ b/wmake/wmakePrintBuild @@ -61,6 +61,17 @@ die() } +#------------------------------------------------------------------------------ + +cat << WARN_OBSOLETE 1>&2 +############################################################################### +## The wmakePrintBuild utility is OBSOLETE (Dec-2018). ## +## The wmakeBuildInfo utility is to be used instead. ## +############################################################################### + +WARN_OBSOLETE + + #------------------------------------------------------------------------------ # Parse arguments and options #------------------------------------------------------------------------------ From a8ff5b10e88faff17c6c0e3bbbbeb52f9e8bdd3c Mon Sep 17 00:00:00 2001 From: Andrew Heather <> Date: Mon, 3 Dec 2018 16:46:24 +0000 Subject: [PATCH 02/18] COMP: Resolved compiler warnings --- src/finiteArea/faMesh/faMeshMapper/faAreaMapper.C | 1 - src/finiteArea/faMesh/faMeshMapper/faAreaMapper.H | 3 --- src/finiteArea/faMesh/faMeshMapper/faEdgeMapper.C | 2 +- src/finiteArea/faMesh/faMeshMapper/faEdgeMapper.H | 2 +- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/finiteArea/faMesh/faMeshMapper/faAreaMapper.C b/src/finiteArea/faMesh/faMeshMapper/faAreaMapper.C index 0b772daad9..4d9918e62a 100644 --- a/src/finiteArea/faMesh/faMeshMapper/faAreaMapper.C +++ b/src/finiteArea/faMesh/faMeshMapper/faAreaMapper.C @@ -286,7 +286,6 @@ Foam::faAreaMapper::faAreaMapper : mesh_(mesh), mpm_(mpm), - insertedFaces_(false), direct_(false), hasUnmapped_(false), sizeBeforeMapping_(mesh.nFaces()), diff --git a/src/finiteArea/faMesh/faMeshMapper/faAreaMapper.H b/src/finiteArea/faMesh/faMeshMapper/faAreaMapper.H index e73dff11aa..1ff5fa79f0 100644 --- a/src/finiteArea/faMesh/faMeshMapper/faAreaMapper.H +++ b/src/finiteArea/faMesh/faMeshMapper/faAreaMapper.H @@ -68,9 +68,6 @@ class faAreaMapper //- Reference to mapPolyMesh const mapPolyMesh& mpm_; - //- Are there any inserted (unmapped) faces - bool insertedFaces_; - //- Is the mapping direct bool direct_; diff --git a/src/finiteArea/faMesh/faMeshMapper/faEdgeMapper.C b/src/finiteArea/faMesh/faMeshMapper/faEdgeMapper.C index d3eda760ae..f0095149db 100644 --- a/src/finiteArea/faMesh/faMeshMapper/faEdgeMapper.C +++ b/src/finiteArea/faMesh/faMeshMapper/faEdgeMapper.C @@ -65,7 +65,7 @@ Foam::faEdgeMapper::faEdgeMapper ) : mesh_(mesh), - mpm_(mpm), +// mpm_(mpm), sizeBeforeMapping_(mesh.nInternalEdges()), hasUnmapped_(false), directAddrPtr_(nullptr) diff --git a/src/finiteArea/faMesh/faMeshMapper/faEdgeMapper.H b/src/finiteArea/faMesh/faMeshMapper/faEdgeMapper.H index d9c5a9a470..c692e3d436 100644 --- a/src/finiteArea/faMesh/faMeshMapper/faEdgeMapper.H +++ b/src/finiteArea/faMesh/faMeshMapper/faEdgeMapper.H @@ -67,7 +67,7 @@ class faEdgeMapper const faMesh& mesh_; //- Reference to mapPolyMesh - const mapPolyMesh& mpm_; + //const mapPolyMesh& mpm_; //- Old mesh size label sizeBeforeMapping_; From f3488c122030584f113784134326c030559e8f66 Mon Sep 17 00:00:00 2001 From: Andrew Heather <> Date: Mon, 3 Dec 2018 16:58:40 +0000 Subject: [PATCH 03/18] ENH: writeFile - add option to (not)use user time. Fixes #1078 --- .../db/functionObjects/writeFile/writeFile.C | 19 +++++++++++++++---- .../db/functionObjects/writeFile/writeFile.H | 4 ++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C b/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C index 2326536279..94e02f6b0a 100644 --- a/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C +++ b/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C @@ -85,15 +85,18 @@ Foam::fileName Foam::functionObjects::writeFile::baseTimeDir() const Foam::autoPtr Foam::functionObjects::writeFile::createFile ( const word& name, - const scalar time + const scalar time0 ) const { autoPtr osPtr; if (Pstream::master() && writeToFile_) { - const scalar userTime = fileObr_.time().timeToUserTime(time); - const word timeName = Time::timeName(userTime); + const scalar time = useUserTime_ ? + fileObr_.time().timeToUserTime(time0) + : time0; + + const word timeName = Time::timeName(time); fileName outputDir(baseFileDir()/prefix_/timeName); @@ -164,6 +167,7 @@ Foam::functionObjects::writeFile::writeFile writePrecision_(IOstream::defaultPrecision()), writeToFile_(true), writtenHeader_(false), + useUserTime_(true), startTime_(obr.time().startTime().value()) {} @@ -183,6 +187,7 @@ Foam::functionObjects::writeFile::writeFile writePrecision_(IOstream::defaultPrecision()), writeToFile_(true), writtenHeader_(false), + useUserTime_(true), startTime_(obr.time().startTime().value()) { read(dict); @@ -205,6 +210,9 @@ bool Foam::functionObjects::writeFile::read(const dictionary& dict) writeToFile_ = dict.lookupOrDefault("writeToFile", true); writeToFile_ = writeToFile_ && Pstream::master(); + // Use user time, e.g. CA deg in preference to seconds + useUserTime_ = dict.lookupOrDefault("useUserTime", true); + return true; } @@ -277,7 +285,10 @@ void Foam::functionObjects::writeFile::writeHeader void Foam::functionObjects::writeFile::writeTime(Ostream& os) const { - const scalar timeNow = fileObr_.time().timeOutputValue(); + scalar timeNow = useUserTime_ ? + fileObr_.time().timeOutputValue() + : fileObr_.time().value(); + os << setw(charWidth()) << Time::timeName(timeNow); } diff --git a/src/OpenFOAM/db/functionObjects/writeFile/writeFile.H b/src/OpenFOAM/db/functionObjects/writeFile/writeFile.H index 3dcc397ff6..d430f0c340 100644 --- a/src/OpenFOAM/db/functionObjects/writeFile/writeFile.H +++ b/src/OpenFOAM/db/functionObjects/writeFile/writeFile.H @@ -82,6 +82,10 @@ protected: //- Flag to identify whether the header has been written bool writtenHeader_; + //- Flag to use the specified user time, e.g. CA deg instead + //- of seconds. Default = true + bool useUserTime_; + //- Start time value scalar startTime_; From 5252c70b462bacf6e79ce658ab0a252ae36b3bf3 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 4 Dec 2018 01:38:46 +0100 Subject: [PATCH 04/18] STYLE: add OpenFOAM/include directory in CMakeLists - eg for foamVersion.H --- .../graphics/PVReaders/PVFoamReader/CMakeLists-Project.txt | 1 + .../graphics/PVReaders/PVblockMeshReader/CMakeLists-Project.txt | 1 + .../graphics/runTimePostProcessing/CMakeLists-Project.txt | 1 + 3 files changed, 3 insertions(+) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/CMakeLists-Project.txt b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/CMakeLists-Project.txt index 9b8673260d..119caee55c 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/CMakeLists-Project.txt +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/CMakeLists-Project.txt @@ -6,6 +6,7 @@ link_directories( ) include_directories( + ${LIB_SRC}/OpenFOAM/include ${LIB_SRC}/OpenFOAM/lnInclude ${LIB_SRC}/OSspecific/${WM_OSTYPE}/lnInclude ${LIB_SRC}/fileFormats/lnInclude diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/CMakeLists-Project.txt b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/CMakeLists-Project.txt index 1b35d22bbe..f75b0db94b 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/CMakeLists-Project.txt +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/CMakeLists-Project.txt @@ -6,6 +6,7 @@ link_directories( ) include_directories( + ${LIB_SRC}/OpenFOAM/include ${LIB_SRC}/OpenFOAM/lnInclude ${LIB_SRC}/OSspecific/${WM_OSTYPE}/lnInclude ${LIB_SRC}/meshing/blockMesh/lnInclude diff --git a/src/functionObjects/graphics/runTimePostProcessing/CMakeLists-Project.txt b/src/functionObjects/graphics/runTimePostProcessing/CMakeLists-Project.txt index 6cd899348c..d64168acbd 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/CMakeLists-Project.txt +++ b/src/functionObjects/graphics/runTimePostProcessing/CMakeLists-Project.txt @@ -14,6 +14,7 @@ else() endif() include_directories( + ${LIB_SRC}/OpenFOAM/include ${LIB_SRC}/OpenFOAM/lnInclude ${LIB_SRC}/OSspecific/${WM_OSTYPE}/lnInclude ${LIB_SRC}/finiteVolume/lnInclude From cacbcd98d92c29efe2f086e208bc604b775b16f0 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 4 Dec 2018 01:40:54 +0100 Subject: [PATCH 05/18] SUBMODULE: minor catalyst and cfmesh updates --- modules/catalyst | 2 +- modules/cfmesh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/catalyst b/modules/catalyst index 0e65a8c916..38177ea96f 160000 --- a/modules/catalyst +++ b/modules/catalyst @@ -1 +1 @@ -Subproject commit 0e65a8c91644587ddfb0b38abf4bdd5771fbc82d +Subproject commit 38177ea96f1f19b3130acab6977357cd156b87b8 diff --git a/modules/cfmesh b/modules/cfmesh index 101a4d03cb..024454c8db 160000 --- a/modules/cfmesh +++ b/modules/cfmesh @@ -1 +1 @@ -Subproject commit 101a4d03cb7ff08da3bc9cde4ad62a15692eef7c +Subproject commit 024454c8dbef41a19d4e401b2c32ca4f03090d00 From d842118994eae513e6d92c16f066bb329f99c0da Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 4 Dec 2018 13:22:59 +0100 Subject: [PATCH 06/18] ENH: add cellSet support for volRegion (#1106) --- .../functionObjects/volRegion/volRegion.C | 76 +++++++++++++------ .../functionObjects/volRegion/volRegion.H | 35 +++++---- 2 files changed, 74 insertions(+), 37 deletions(-) diff --git a/src/finiteVolume/functionObjects/volRegion/volRegion.C b/src/finiteVolume/functionObjects/volRegion/volRegion.C index 1f4779afeb..c39c9cf8c5 100644 --- a/src/finiteVolume/functionObjects/volRegion/volRegion.C +++ b/src/finiteVolume/functionObjects/volRegion/volRegion.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,6 +25,7 @@ License #include "volRegion.H" #include "volMesh.H" +#include "cellSet.H" #include "globalMeshData.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -44,8 +45,9 @@ const Foam::Enum > Foam::functionObjects::volRegion::regionTypeNames_ ({ - { regionTypes::vrtCellZone, "cellZone" }, { regionTypes::vrtAll, "all" }, + { regionTypes::vrtCellSet, "cellSet" }, + { regionTypes::vrtCellZone, "cellZone" }, }); @@ -73,7 +75,7 @@ Foam::functionObjects::volRegion::volRegion const dictionary& dict ) : - mesh_(mesh), + volMesh_(mesh), regionType_ ( regionTypeNames_.lookupOrDefault @@ -83,7 +85,7 @@ Foam::functionObjects::volRegion::volRegion regionTypes::vrtAll ) ), - regionName_(polyMesh::defaultRegion), + regionName_(volMesh_.name()), regionID_(-1) { read(dict); @@ -94,12 +96,6 @@ Foam::functionObjects::volRegion::volRegion } -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::functionObjects::volRegion::~volRegion() -{} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // bool Foam::functionObjects::volRegion::read @@ -107,19 +103,41 @@ bool Foam::functionObjects::volRegion::read const dictionary& dict ) { + regionID_ = -1; + cellIds_.clear(); + switch (regionType_) { + case vrtCellSet: + { + dict.readEntry("name", regionName_); + + cellIds_ = cellSet(volMesh_, regionName_).sortedToc(); + + if (nCells() == 0) + { + FatalIOErrorInFunction(dict) + << regionTypeNames_[regionType_] + << "(" << regionName_ << "):" << nl + << " Region has no cells" + << exit(FatalIOError); + } + + break; + } + case vrtCellZone: { dict.readEntry("name", regionName_); - regionID_ = mesh_.cellZones().findZoneID(regionName_); + regionID_ = volMesh_.cellZones().findZoneID(regionName_); if (regionID_ < 0) { FatalIOErrorInFunction(dict) << "Unknown cell zone name: " << regionName_ - << ". Valid cell zones are: " << mesh_.cellZones().names() + << ". Valid cell zones : " + << flatOutput(volMesh_.cellZones().names()) << exit(FatalIOError); } @@ -137,6 +155,7 @@ bool Foam::functionObjects::volRegion::read case vrtAll: { + regionName_= volMesh_.name(); break; } @@ -144,7 +163,7 @@ bool Foam::functionObjects::volRegion::read { FatalIOErrorInFunction(dict) << "Unknown region type. Valid region types are:" - << regionTypeNames_.sortedToc() + << flatOutput(regionTypeNames_.names()) << nl << exit(FatalIOError); } } @@ -155,14 +174,21 @@ bool Foam::functionObjects::volRegion::read const Foam::labelList& Foam::functionObjects::volRegion::cellIDs() const { - if (regionType_ == vrtAll) + switch (regionType_) { - return labelList::null(); - } - else - { - return mesh_.cellZones()[regionID_]; + case vrtCellSet: + return cellIds_; + break; + + case vrtCellZone: + return volMesh_.cellZones()[regionID_]; + break; + + default: + break; } + + return labelList::null(); } @@ -170,7 +196,7 @@ Foam::label Foam::functionObjects::volRegion::nCells() const { if (regionType_ == vrtAll) { - return mesh_.globalData().nTotalCells(); + return volMesh_.globalData().nTotalCells(); } else { @@ -183,11 +209,17 @@ Foam::scalar Foam::functionObjects::volRegion::V() const { if (regionType_ == vrtAll) { - return gSum(mesh_.V()); + return gSum(volMesh_.V()); } else { - return gSum(scalarField(mesh_.V(), cellIDs())); + scalar vol = 0; + for (const label celli : cellIDs()) + { + vol += volMesh_.V()[celli]; + } + + return returnReduce(vol, sumOp()); } } diff --git a/src/finiteVolume/functionObjects/volRegion/volRegion.H b/src/finiteVolume/functionObjects/volRegion/volRegion.H index f95504684d..ef33682b94 100644 --- a/src/finiteVolume/functionObjects/volRegion/volRegion.H +++ b/src/finiteVolume/functionObjects/volRegion/volRegion.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -54,9 +54,9 @@ Description Usage \table - Property | Description | Required | Default value - regionType | cellZone or all | no | all - name | Name of cellZone if required | no | + Property | Description | Required | Default + regionType | Selection type: all/cellSet/cellZone | no | all + name | Name of cellSet/cellZone if required | no | \endtable See also @@ -78,7 +78,7 @@ SourceFiles namespace Foam { -// Forward declaration of classes +// Forward declarations class fvMesh; namespace functionObjects @@ -90,12 +90,16 @@ namespace functionObjects class volRegion { - // Private member data + // Private Member Data - const fvMesh& mesh_; + const fvMesh& volMesh_; + + //- The cell ids, from cellSet + labelList cellIds_; // Cache integral properties of the region for writeFileHeader label nCells_; + scalar V_; @@ -106,8 +110,9 @@ public: //- Region type enumeration enum regionTypes { - vrtCellZone, //!< cell zone - vrtAll //!< all cells + vrtAll, //!< All cells + vrtCellSet, //!< A cellSet + vrtCellZone //!< A cellZone }; //- Region type names @@ -116,15 +121,15 @@ public: protected: - // Protected data + // Protected Data //- Region type regionTypes regionType_; - //- Region name (patch, zone, etc.) + //- Region name (cellSet, cellZone, ...) word regionName_; - //- Region ID (patch ID, zone ID, etc.) + //- Region ID (zone ID, ...) label regionID_; @@ -147,13 +152,13 @@ public: //- Destructor - virtual ~volRegion(); + virtual ~volRegion() = default; // Public Member Functions //- Read from dictionary - bool read(const dictionary&); + bool read(const dictionary& dict); //- Return the region type inline const regionTypes& regionType() const; @@ -161,7 +166,7 @@ public: //- Return the local list of cell IDs const labelList& cellIDs() const; - //- Return the number of cells in the region + //- Return the number of cells selected in the region label nCells() const; //- Return total volume of the region From 077910628e02017e066fd967ba46dd6c0bb90b05 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 4 Dec 2018 15:16:03 +0100 Subject: [PATCH 07/18] ENH: momentum field function (issue #1105) Calculates linear/angular momentum, reporting integral values and optionally writing the fields. Example momentum1 { type momentum; libs ("libfieldFunctionObjects.so"); ... writeMomentum yes; writeVelocity no; cylindrical true; origin (0 0 0); e1 (1 0 0); e3 (0 0 1); } --- src/functionObjects/field/Make/files | 1 + src/functionObjects/field/momentum/momentum.C | 573 ++++++++++++++++++ src/functionObjects/field/momentum/momentum.H | 266 ++++++++ .../simpleFoam/pipeCyclic/system/controlDict | 1 + .../simpleFoam/pipeCyclic/system/momentum | 33 + 5 files changed, 874 insertions(+) create mode 100644 src/functionObjects/field/momentum/momentum.C create mode 100644 src/functionObjects/field/momentum/momentum.H create mode 100644 tutorials/incompressible/simpleFoam/pipeCyclic/system/momentum diff --git a/src/functionObjects/field/Make/files b/src/functionObjects/field/Make/files index 1afdfb2ea7..d5aa38ee3d 100644 --- a/src/functionObjects/field/Make/files +++ b/src/functionObjects/field/Make/files @@ -59,6 +59,7 @@ flowType/flowType.C CourantNo/CourantNo.C PecletNo/PecletNo.C blendingFactor/blendingFactor.C +momentum/momentum.C pressure/pressure.C MachNo/MachNo.C Curle/Curle.C diff --git a/src/functionObjects/field/momentum/momentum.C b/src/functionObjects/field/momentum/momentum.C new file mode 100644 index 0000000000..53438c91af --- /dev/null +++ b/src/functionObjects/field/momentum/momentum.C @@ -0,0 +1,573 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "momentum.H" +#include "fvMesh.H" +#include "volFields.H" +#include "cellSet.H" +#include "cylindricalRotation.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(momentum, 0); + addToRunTimeSelectionTable(functionObject, momentum, dictionary); +} +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // + +template +Foam::autoPtr +Foam::functionObjects::momentum::newField +( + const word& baseName, + const dimensionSet& dims, + bool registerObject +) const +{ + return + autoPtr::New + ( + IOobject + ( + scopedName(baseName), + time_.timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE, + registerObject + ), + mesh_, + dimensioned(dims, Zero) + ); +} + + +void Foam::functionObjects::momentum::calc() +{ + initialise(); + + // When field writing is not enabled we need our local storage + // for the momentum and angular velocity fields + autoPtr tmomentum, tAngularMom, tAngularVel; + + + // The base fields required + const auto& U = lookupObject(UName_); + const auto* rhoPtr = findObject(rhoName_); + + const dimensionedScalar rhoRef("rho", dimDensity, rhoRef_); + + // For quantities such as the mass-averaged angular velocity, + // we would calculate the mass per-cell here. + + // tmp tmass = + // ( + // rhoPtr + // ? (mesh_.V() * (*rhoPtr)) + // : (mesh_.V() * rhoRef) + // ); + + + // Linear momentum + // ~~~~~~~~~~~~~~~ + + auto* pmomentum = getObjectPtr(scopedName("momentum")); + + if (!pmomentum) + { + tmomentum = newField("momentum", dimVelocity*dimMass); + pmomentum = tmomentum.get(); // get(), not release() + } + auto& momentum = *pmomentum; + + if (rhoPtr) + { + momentum.ref() = (U * mesh_.V() * (*rhoPtr)); + } + else + { + momentum.ref() = (U * mesh_.V() * rhoRef); + } + momentum.correctBoundaryConditions(); + + + // Angular momentum + // ~~~~~~~~~~~~~~~~ + + auto* pAngularMom = + getObjectPtr(scopedName("angularMomentum")); + + if (hasCsys_ && !pAngularMom) + { + tAngularMom = + newField("angularMomentum", dimVelocity*dimMass); + pAngularMom = tAngularMom.get(); // get(), not release() + } + else if (!pAngularMom) + { + // Angular momentum not requested, but alias to normal momentum + // to simplify logic when calculating the summations + pAngularMom = pmomentum; + } + auto& angularMom = *pAngularMom; + + + // Angular velocity + // ~~~~~~~~~~~~~~~~ + + auto* pAngularVel = + getObjectPtr(scopedName("angularVelocity")); + + if (hasCsys_) + { + if (!pAngularVel) + { + tAngularVel = + newField("angularVelocity", dimVelocity); + pAngularVel = tAngularVel.get(); // get(), not release() + } + auto& angularVel = *pAngularVel; + + + // Global to local + + angularVel.primitiveFieldRef() = + csys_.invTransform(mesh_.cellCentres(), U.internalField()); + + angularVel.correctBoundaryConditions(); + + if (rhoPtr) + { + angularMom.ref() = (angularVel * mesh_.V() * (*rhoPtr)); + } + else + { + angularMom.ref() = (angularVel * mesh_.V() * rhoRef); + } + + angularMom.correctBoundaryConditions(); + } + + + // Integrate the selection + + sumMomentum_ = Zero; + sumAngularMom_ = Zero; + + switch (regionType_) + { + case vrtCellSet: + case vrtCellZone: + { + for (const label celli : cellIDs()) + { + sumMomentum_ += momentum[celli]; + sumAngularMom_ += angularMom[celli]; + } + break; + } + case vrtAll: + { + for (label celli=0; celli < mesh_.nCells(); ++celli) + { + sumMomentum_ += momentum[celli]; + sumAngularMom_ += angularMom[celli]; + } + break; + } + } + + reduce(sumMomentum_, sumOp()); + reduce(sumAngularMom_, sumOp()); +} + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +void Foam::functionObjects::momentum::writeFileHeader(Ostream& os) +{ + if (!writeToFile() || writtenHeader_) + { + return; + } + + if (hasCsys_) + { + writeHeader(os, "Momentum, Angular Momentum"); + writeHeaderValue(os, "origin", csys_.origin()); + writeHeaderValue(os, "axis", csys_.e3()); + } + else + { + writeHeader(os, "Momentum"); + } + + if (regionType_ != vrtAll) + { + writeHeader + ( + os, + "Selection " + regionTypeNames_[regionType_] + + " = " + regionName_ + ); + } + + writeHeader(os, ""); + writeCommented(os, "Time"); + writeTabbed(os, "(momentum_x momentum_y momentum_z)"); + + if (hasCsys_) + { + writeTabbed(os, "(momentum_r momentum_rtheta momentum_axis)"); + } + os << endl; + + + writtenHeader_ = true; +} + + +void Foam::functionObjects::momentum::initialise() +{ + if (initialised_) + { + return; + } + + if (!foundObject(UName_)) + { + FatalErrorInFunction + << "Could not find U: " << UName_ << " in database" + << exit(FatalError); + } + + + const auto* pPtr = cfindObject(pName_); + + if (pPtr && pPtr->dimensions() == dimPressure) + { + // Compressible - rho is mandatory + + if (!foundObject(rhoName_)) + { + FatalErrorInFunction + << "Could not find rho:" << rhoName_ + << exit(FatalError); + } + } + + initialised_ = true; +} + + +void Foam::functionObjects::momentum::writeValues(Ostream& os) +{ + Log << type() << " " << name() << " write:" << nl; + + Log << " Sum of Momentum"; + + if (regionType_ != vrtAll) + { + Log << ' ' << regionTypeNames_[regionType_] + << ' ' << regionName_; + } + + Log << nl + << " linear : " << sumMomentum_ << nl; + + if (hasCsys_) + { + Log << " angular : " << sumAngularMom_ << nl; + } + + if (writeToFile()) + { + writeTime(os); + + os << tab << sumMomentum_; + + if (hasCsys_) + { + os << tab << sumAngularMom_; + } + os << endl; + } + + Log << endl; +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::momentum::momentum +( + const word& name, + const Time& runTime, + const dictionary& dict, + bool readFields +) +: + fvMeshFunctionObject(name, runTime, dict), + volRegion(fvMeshFunctionObject::mesh_, dict), + writeFile(mesh_, name, typeName, dict), + sumMomentum_(Zero), + sumAngularMom_(Zero), + UName_(), + pName_(), + rhoName_(), + rhoRef_(1.0), + csys_(), + hasCsys_(false), + writeMomentum_(false), + writeVelocity_(false), + writePosition_(false), + initialised_(false) +{ + if (readFields) + { + read(dict); + Log << endl; + } +} + + +Foam::functionObjects::momentum::momentum +( + const word& name, + const objectRegistry& obr, + const dictionary& dict, + bool readFields +) +: + fvMeshFunctionObject(name, obr, dict), + volRegion(fvMeshFunctionObject::mesh_, dict), + writeFile(mesh_, name, typeName, dict), + sumMomentum_(Zero), + sumAngularMom_(Zero), + UName_(), + pName_(), + rhoName_(), + rhoRef_(1.0), + csys_(), + hasCsys_(false), + writeMomentum_(false), + writeVelocity_(false), + writePosition_(false), + initialised_(false) +{ + if (readFields) + { + read(dict); + Log << endl; + } +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::momentum::read(const dictionary& dict) +{ + fvMeshFunctionObject::read(dict); + volRegion::read(dict); + writeFile::read(dict); + + initialised_ = false; + + Info<< type() << " " << name() << ":" << nl; + + // Optional entries U and p + UName_ = dict.lookupOrDefault("U", "U"); + pName_ = dict.lookupOrDefault("p", "p"); + rhoName_ = dict.lookupOrDefault("rho", "rho"); + rhoRef_ = dict.lookupOrDefault("rhoRef", 1.0); + + rhoRef_ = dict.lookupOrDefault("rhoRef", 1.0); + + hasCsys_ = dict.lookupOrDefault("cylindrical", false); + + if (hasCsys_) + { + csys_ = coordSystem::cylindrical(dict); + } + + writeMomentum_ = dict.lookupOrDefault("writeMomentum", false); + writeVelocity_ = dict.lookupOrDefault("writeVelocity", false); + writePosition_ = dict.lookupOrDefault("writePosition", false); + + Info<<"Integrating for selection: " + << regionTypeNames_[regionType_] + << " (" << regionName_ << ")" << nl; + + if (writeMomentum_) + { + Info<< " Momentum fields will be written" << endl; + + mesh_.objectRegistry::store + ( + newField("momentum", dimVelocity*dimMass) + ); + + if (hasCsys_) + { + mesh_.objectRegistry::store + ( + newField("angularMomentum", dimVelocity*dimMass) + ); + } + } + + if (hasCsys_) + { + if (writeVelocity_) + { + Info<< " Angular velocity will be written" << endl; + + mesh_.objectRegistry::store + ( + newField("angularVelocity", dimVelocity) + ); + } + + if (writePosition_) + { + Info<< " Angular position will be written" << endl; + } + } + + return true; +} + + +bool Foam::functionObjects::momentum::execute() +{ + calc(); + + if (Pstream::master()) + { + writeFileHeader(file()); + + writeValues(file()); + + Log << endl; + } + + // Write state/results information + setResult("momentum_x", sumMomentum_[0]); + setResult("momentum_y", sumMomentum_[1]); + setResult("momentum_z", sumMomentum_[2]); + + setResult("momentum_r", sumAngularMom_[0]); + setResult("momentum_rtheta", sumAngularMom_[1]); + setResult("momentum_axis", sumAngularMom_[2]); + + return true; +} + + +bool Foam::functionObjects::momentum::write() +{ + if (writeMomentum_ || (hasCsys_ && (writeVelocity_ || writePosition_))) + { + Log <<"Writing fields" << nl; + + const volVectorField* fieldPtr; + + fieldPtr = findObject(scopedName("momentum")); + if (fieldPtr) fieldPtr->write(); + + fieldPtr = findObject(scopedName("angularMomentum")); + if (fieldPtr) fieldPtr->write(); + + fieldPtr = findObject(scopedName("angularVelocity")); + if (fieldPtr) fieldPtr->write(); + + if (hasCsys_ && writePosition_) + { + // Clunky, but currently no simple means of handling + // component-wise conversion and output + + auto cyl_r = newField("cyl_r", dimLength); + auto cyl_t = newField("cyl_theta", dimless); + auto cyl_z = newField("cyl_z", dimLength); + + // Internal + { + const auto& pts = mesh_.cellCentres(); + const label len = pts.size(); + + UList& r = cyl_r->primitiveFieldRef(false); + UList& t = cyl_t->primitiveFieldRef(false); + UList& z = cyl_z->primitiveFieldRef(false); + + for (label i=0; i < len; ++i) + { + point p(csys_.localPosition(pts[i])); + + r[i] = p.x(); + t[i] = p.y(); + z[i] = p.z(); + } + } + + // Boundary + const polyBoundaryMesh& pbm = mesh_.boundaryMesh(); + + forAll(pbm, patchi) + { + const auto& pts = pbm[patchi].faceCentres(); + const label len = pts.size(); + + UList& r = cyl_r->boundaryFieldRef(false)[patchi]; + UList& t = cyl_t->boundaryFieldRef(false)[patchi]; + UList& z = cyl_z->boundaryFieldRef(false)[patchi]; + + for (label i=0; i < len; ++i) + { + point p(csys_.localPosition(pts[i])); + + r[i] = p.x(); + t[i] = p.y(); + z[i] = p.z(); + } + } + + cyl_r->write(); + cyl_t->write(); + cyl_z->write(); + } + } + + return true; +} + + +// ************************************************************************* // diff --git a/src/functionObjects/field/momentum/momentum.H b/src/functionObjects/field/momentum/momentum.H new file mode 100644 index 0000000000..2da62e1ea0 --- /dev/null +++ b/src/functionObjects/field/momentum/momentum.H @@ -0,0 +1,266 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::functionObjects::momentum + +Group + grpFieldFunctionObjects + +Description + Calculates linear/angular momentum, reporting integral values + and optionally writing the fields. + + Data is written into momentum.dat in the + postProcessing/\ directory. + +Usage + Example of function object specification: + \verbatim + momentum1 + { + type momentum; + libs ("libfieldFunctionObjects.so"); + ... + log yes; + + regionType all; + writeMomentum yes; + writePosition yes; + writeVelocity yes; + + cylindrical true; + + origin (0 0 0); + e1 (1 0 0); + e3 (0 0 1); + } + \endverbatim + + Where the entries comprise: + \table + Property | Description | Required | Default + type | Type name: momentum | yes | + log | Log information to standard output | no | no + writeMomentum | Write (linear, angular) momentum fields | no | no + writePosition | Write angular position component fields | no | no + writeVelocity | Write angular velocity fields | no | no + p | Pressure field name | no | p + U | Velocity field name | no | U + rho | Density field name | no | rho + rhoRef | Reference density (incompressible) | no | 1.0 + cylindrical | Use cylindrical coordinates | no | false + origin | Origin for cylindrical coordinates | no | + regionType | Selection type: all/cellSet/cellZone | no | all + name | Name of cellSet/cellZone if required | no | + \endtable + +Note + - For incompressible cases, the value of \c rhoRef is used. + - When specifying the cylindrical coordinate system, the rotation + can be specified directly with e1/e2/e3 axes, or via a \c rotation + sub-dictionary + For example, + \verbatim + origin (0 0 0); + rotation + { + type cylindrical; + axis (0 0 1); + } + \endverbatim + +See also + Foam::functionObject + Foam::functionObjects::fvMeshFunctionObject + Foam::functionObjects::volRegion + Foam::functionObjects::writeFile + Foam::functionObjects::timeControl + +SourceFiles + momentum.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_momentum_H +#define functionObjects_momentum_H + +#include "fvMeshFunctionObject.H" +#include "writeFile.H" +#include "cylindricalCS.H" +#include "volFieldsFwd.H" +#include "volRegion.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declarations +class dimensionSet; + +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class momentum Declaration +\*---------------------------------------------------------------------------*/ + +class momentum +: + public fvMeshFunctionObject, + public volRegion, + public writeFile +{ + // Private Member Functions + + //- Calculate the fields and integral values + void calc(); + + //- Allocate a new zero geometric field + template + autoPtr newField + ( + const word& baseName, + const dimensionSet& dims, + bool registerObject=true + ) const; + + +protected: + + // Protected data + + //- Integral (linear) momentum + vector sumMomentum_; + + //- Integral angular momentum + vector sumAngularMom_; + + + // Read from dictionary + + //- The velocity field name (optional) + word UName_; + + //- The pressure field name (optional) + // Only used to determine incompressible/compressible + word pName_; + + //- The density field name (optional) + word rhoName_; + + //- Reference density (for incompressible) + scalar rhoRef_; + + //- Coordinate system for evaluating angular momentum + coordSystem::cylindrical csys_; + + //- Are we using the cylindrical coordinate system? + bool hasCsys_; + + //- Write fields flag + bool writeMomentum_; + + //- Write fields flag + bool writeVelocity_; + + //- Write fields flag + bool writePosition_; + + //- Initialised flag + bool initialised_; + + + // Protected Member Functions + + //- Initialise the fields + void initialise(); + + //- Output file header information + virtual void writeFileHeader(Ostream& os); + + //- Write momentum data + void writeValues(Ostream& os); + + //- No copy construct + momentum(const momentum&) = delete; + + //- No copy assignment + void operator=(const momentum&) = delete; + + +public: + + //- Runtime type information + TypeName("momentum"); + + + // Constructors + + //- Construct from Time and dictionary + momentum + ( + const word& name, + const Time& runTime, + const dictionary& dict, + const bool readFields = true + ); + + //- Construct from objectRegistry and dictionary + momentum + ( + const word& name, + const objectRegistry& obr, + const dictionary& dict, + const bool readFields = true + ); + + + //- Destructor + virtual ~momentum() = default; + + + // Member Functions + + //- Read the momentum data + virtual bool read(const dictionary&); + + //- Calculate and report the integral momentum + virtual bool execute(); + + //- Write the momentum, possibly angular momentum and velocity + virtual bool write(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/pipeCyclic/system/controlDict b/tutorials/incompressible/simpleFoam/pipeCyclic/system/controlDict index fae83278cb..0beed5f5bd 100644 --- a/tutorials/incompressible/simpleFoam/pipeCyclic/system/controlDict +++ b/tutorials/incompressible/simpleFoam/pipeCyclic/system/controlDict @@ -48,6 +48,7 @@ runTimeModifiable true; functions { #include "coordinateTransform" + #include "momentum" } diff --git a/tutorials/incompressible/simpleFoam/pipeCyclic/system/momentum b/tutorials/incompressible/simpleFoam/pipeCyclic/system/momentum new file mode 100644 index 0000000000..6f05784e69 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/pipeCyclic/system/momentum @@ -0,0 +1,33 @@ +// -*- C++ -*- +// Calculate momentum fields +momentum +{ + type momentum; + libs ("libfieldFunctionObjects.so"); + log true; + + executeInterval 10; + writeControl writeTime; + + // writeToFile true; + + writeMomentum true; + writePosition true; + writeVelocity true; + + // Cells to select (all/cellSet/cellZone) + regionType all; + // name c0; + + cylindrical true; + + origin (0 0 0); + rotation + { + type cylindrical; + axis (1 0 0); //< local Z + } +} + + +// ************************************************************************* // From 274bb501bc3d0aa16ee4ee35eb48811df8b85f7e Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 4 Dec 2018 17:19:25 +0100 Subject: [PATCH 08/18] STYLE: incorrect option name handling for foamCreateModuleInclude - The usage claimed '-output=', but was using '--output=' for the output file. Rectify to use single dash as documented. --- bin/tools/foamCreateModuleInclude | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/tools/foamCreateModuleInclude b/bin/tools/foamCreateModuleInclude index f8e8775ed3..77a275173f 100755 --- a/bin/tools/foamCreateModuleInclude +++ b/bin/tools/foamCreateModuleInclude @@ -85,10 +85,10 @@ do --recursive-backend--) optBackend=true ;; - --output=*) + -output=*) moduleOutput="${1#*=}" ;; - --tmpdir=*) + -tmpdir=*) moduleTmpDir="${1#*=}" ;; -*) From bff16a0ddcaf910e93bec75eb94ad3553ddbc56e Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 5 Dec 2018 08:42:55 +0100 Subject: [PATCH 09/18] STYLE: additional comments in Test-decomposePar --- .../test/decomposePar/Test-decomposePar.C | 45 +++++++------------ 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/applications/test/decomposePar/Test-decomposePar.C b/applications/test/decomposePar/Test-decomposePar.C index 26673bf6b1..4747c4e9ca 100644 --- a/applications/test/decomposePar/Test-decomposePar.C +++ b/applications/test/decomposePar/Test-decomposePar.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -22,32 +22,13 @@ License along with OpenFOAM. If not, see . Application - decomposePar + Test-decomposePar Group grpParallelUtilities Description - Automatically decomposes a mesh and fields of a case for parallel - execution of OpenFOAM. - -Usage - \b decomposePar [OPTION] - - Options: - - \par -region \ - Decompose named region. Does not check for existence of processor*. - - - \par -allRegions - Decompose all regions in regionProperties. Does not check for - existence of processor*. - - - \par -constant - - - \par -time xxx:yyy - Override controlDict settings and decompose selected times. Does not - re-decompose the mesh i.e. does not handle moving mesh or changing - mesh cases. + Like decomposePar -dry-run, but with additional options \*---------------------------------------------------------------------------*/ @@ -65,7 +46,10 @@ int main(int argc, char *argv[]) { argList::addNote ( - "decompose a mesh and fields of a case for parallel execution" + "Special-purpose version of decomposePar with additional" + " -domain and -method options." + " The '-dry-run' and '-cellDist' are implicit.\n" + "NB: The -domain/-method overrides may not work very well with regions" ); argList::noParallel(); @@ -79,33 +63,38 @@ int main(int argc, char *argv[]) argList::addBoolOption ( "allRegions", - "operate on all regions in regionProperties" + "Operate on all regions in regionProperties" ); argList::addBoolOption ( "verbose", - "more information about decomposition" + "Additional verbosity" ); argList::addOption ( "domains", "N", - "override numberOfSubdomains" + "Override numberOfSubdomains" ); argList::addOption ( "method", "name", - "override method" + "Override decomposition method" ); + + // These are implicit so just ignore them + argList::ignoreOptionCompat({"dry-run", 0}, false); + argList::ignoreOptionCompat({"cellDist", 0}, false); + // Include explicit constant options, have zero from time range timeSelector::addOptions(true, false); #include "setRootCase.H" - const bool region = args.found("region"); + const bool optRegion = args.found("region"); const bool allRegions = args.found("allRegions"); const bool verbose = args.found("verbose"); From 2469f698e97f4c8963370047ff22b64d0377e272 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 5 Dec 2018 08:50:38 +0100 Subject: [PATCH 10/18] CONFIG: update completion_cache (for csh users) - now consider options '-hostRoots', '-roots' to be advanced options that don't need to be in the cache --- bin/tools/foamCreateCompletionCache | 27 +- etc/config.sh/completion_cache | 396 ++++++++++++++-------------- 2 files changed, 216 insertions(+), 207 deletions(-) diff --git a/bin/tools/foamCreateCompletionCache b/bin/tools/foamCreateCompletionCache index cf1bcdef50..0e1e81bf1e 100755 --- a/bin/tools/foamCreateCompletionCache +++ b/bin/tools/foamCreateCompletionCache @@ -27,11 +27,12 @@ usage() { Usage: ${0##*/} [OPTION] [appName .. [appNameN]] options: - -d dir | -dir dir Directory to process - -u | -user Add \$FOAM_USER_APPBIN to the search directories - -no-header Suppress header generation - -o FILE Write to alternative output - -h | -help Print the usage + -dir DIR Directory to process + -user Add \$FOAM_USER_APPBIN to the search directories + -no-header Suppress header generation + -output FILE, -o FILE + Write to alternative output + -h | -help Print the usage Create cache of bash completion values for OpenFOAM applications. The cached values are typically used by the tcsh completion wrapper. @@ -68,13 +69,13 @@ do -h | -help*) usage ;; - -d | -dir) + -dir) [ "$#" -ge 2 ] || die "'$1' option requires an argument" searchDirs="$2" [ -d "$searchDirs" ] || die "directory not found '$searchDirs'" shift ;; - -u | -user) + -user) searchDirs="$searchDirs $FOAM_USER_APPBIN" ;; -no-head*) @@ -116,8 +117,8 @@ echo 1>&2 # Header not disabled [ "$optHeader" = true ] && cat << HEADER #----------------------------------*-sh-*-------------------------------------- -# Cached options for bash completion of OpenFOAM applications, primarily for -# use with the tcsh completion mechanism. +# Cached options for bash completion of OpenFOAM applications, +# primarily for use with the tcsh completion mechanism. # These are the values expected by the '_of_complete_' function # # Recreate with "${0##*/}" @@ -140,7 +141,12 @@ HEADER # -opt1 descrip # -opt2 descrip # -help-full -# Ignore -help-man (internal option). +# +# Ignores +# -help-man Internal option +# -hostRoots Advanced distributed run option +# -roots Advanced distributed run option +# # Terminate parsing on first appearance of -help-full. # - options with '=' (eg, -mode=ugo) are not handled very well at all. # - alternatives (eg, -a, -all) are not handled nicely either, @@ -150,6 +156,7 @@ extractOptions() local appName="$1" local helpText=$($appName -help-full 2>/dev/null | \ sed -ne 's/^ *//; /^$/d; /^[^-]/d; /^--/d; /^-help-man/d;' \ + -e '/^-hostRoots /d; /^-roots /d;' \ -e 'y/,/ /; s/=.*$/=/;' \ -e '/^-[^ ]* Date: Wed, 5 Dec 2018 11:19:08 +0100 Subject: [PATCH 11/18] ENH: code cleanup for vtk transcription - use cellCentres() instead of volField equivalent for vtk conversion - make looping variables more consistent - centralize the transcription of OpenFOAM -> vtk tuples --- .../vtkPVFoam/vtkPVFoamFieldTemplates.C | 204 +++++++----------- .../PVReaders/vtkPVFoam/vtkPVFoamMesh.C | 2 +- .../PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C | 26 +-- src/conversion/vtk/adaptor/foamVtkTools.H | 27 ++- src/conversion/vtk/adaptor/foamVtkToolsI.H | 30 +++ .../vtk/adaptor/foamVtkToolsTemplates.C | 35 ++- 6 files changed, 161 insertions(+), 163 deletions(-) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFieldTemplates.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFieldTemplates.C index 40802fdb7c..6cb7a81cde 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFieldTemplates.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFieldTemplates.C @@ -40,11 +40,11 @@ InClass #include "areaFaMesh.H" #include "areaFields.H" -// vtk includes -#include "vtkFloatArray.h" -#include "vtkCellData.h" -#include "vtkPointData.h" -#include "vtkSmartPointer.h" +// VTK includes +#include +#include +#include +#include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // @@ -68,10 +68,8 @@ void Foam::vtkPVFoam::convertVolField autoPtr> ptfPtr; if (interpField) { - if (debug) - { - Info<< "convertVolField interpolating:" << fld.name() << nl; - } + DebugInfo + << "convertVolField interpolating:" << fld.name() << nl; ptfPtr.reset ( @@ -102,7 +100,7 @@ void Foam::vtkPVFoam::convertVolField foamVtpData& vtpData = iter.object(); auto dataset = vtpData.dataset; - const labelList& patchIds = vtpData.additionalIds(); + const labelUList& patchIds = vtpData.additionalIds(); if (patchIds.empty()) { @@ -291,13 +289,13 @@ void Foam::vtkPVFoam::convertVolFields catch (Foam::IOerror& ioErr) { ioErr.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } catch (Foam::error& err) { // Bit of trickery to get the original message err.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } // Restore previous exception throwing state @@ -373,13 +371,13 @@ void Foam::vtkPVFoam::convertDimFields catch (Foam::IOerror& ioErr) { ioErr.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } catch (Foam::error& err) { // Bit of trickery to get the original message err.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } // Restore previous exception throwing state @@ -501,13 +499,13 @@ void Foam::vtkPVFoam::convertAreaFields catch (Foam::IOerror& ioErr) { ioErr.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } catch (Foam::error& err) { // Bit of trickery to get the original message err.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } // Restore previous exception throwing state @@ -545,10 +543,8 @@ void Foam::vtkPVFoam::convertPointFields continue; } - if (debug) - { - Info<< "convertPointFields : " << fieldName << nl; - } + DebugInfo + << "convertPointFields : " << fieldName << nl; // Throw FatalError, FatalIOError as exceptions const bool throwingError = FatalError.throwExceptions(); @@ -581,7 +577,7 @@ void Foam::vtkPVFoam::convertPointFields foamVtpData& vtpData = iter.object(); auto dataset = vtpData.dataset; - const labelList& patchIds = vtpData.additionalIds(); + const labelUList& patchIds = vtpData.additionalIds(); if (patchIds.size() != 1) { continue; @@ -645,13 +641,13 @@ void Foam::vtkPVFoam::convertPointFields catch (Foam::IOerror& ioErr) { ioErr.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } catch (Foam::error& err) { // Bit of trickery to get the original message err.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } // Restore previous exception throwing state @@ -706,7 +702,6 @@ vtkSmartPointer Foam::vtkPVFoam::convertPointField const foamVtuData& vtuData ) { - const int nComp(pTraits::nComponents); const labelUList& addPointCellLabels = vtuData.additionalIds(); const labelUList& pointMap = vtuData.pointMap(); @@ -714,7 +709,7 @@ vtkSmartPointer Foam::vtkPVFoam::convertPointField const label nPoints = (pointMap.size() ? pointMap.size() : pfld.size()); auto data = vtkSmartPointer::New(); - data->SetNumberOfComponents(nComp); + data->SetNumberOfComponents(static_cast(pTraits::nComponents)); data->SetNumberOfTuples(nPoints + addPointCellLabels.size()); // Note: using the name of the original volField @@ -729,75 +724,54 @@ vtkSmartPointer Foam::vtkPVFoam::convertPointField data->SetName(pfld.name().c_str()); } - if (debug) - { - Info<< "convert Point field: " - << pfld.name() - << " size=" << (nPoints + addPointCellLabels.size()) - << " (" << nPoints << " + " << addPointCellLabels.size() - << ") nComp=" << nComp << nl; - } + DebugInfo + << "Convert point field: " << pfld.name() + << " size=" << (nPoints + addPointCellLabels.size()) + << " (" << nPoints << " + " << addPointCellLabels.size() + << ") nComp=" << static_cast(pTraits::nComponents) << nl; - float vec[nComp]; - label pointi = 0; + float scratch[pTraits::nComponents]; + + vtkIdType pointi = 0; if (pointMap.size()) { - forAll(pointMap, i) + for (const label meshPointi : pointMap) { - const Type& t = pfld[pointMap[i]]; - for (direction d=0; d(vec); - - data->SetTuple(pointi++, vec); + vtk::Tools::foamToVtkTuple(scratch, pfld[meshPointi]); + data->SetTuple(pointi++, scratch); } } else { - forAll(pfld, i) + for (const Type& val : pfld) { - const Type& t = pfld[i]; - for (direction d=0; d(vec); - - data->SetTuple(pointi++, vec); + vtk::Tools::foamToVtkTuple(scratch, val); + data->SetTuple(pointi++, scratch); } } // Continue with additional points + // - correspond to cell centres if (notNull(vfld)) { - forAll(addPointCellLabels, apI) + for (const label meshCelli : addPointCellLabels) { - const Type& t = vfld[addPointCellLabels[apI]]; - for (direction d=0; d(vec); - - data->SetTuple(pointi++, vec); + vtk::Tools::foamToVtkTuple(scratch, vfld[meshCelli]); + data->SetTuple(pointi++, scratch); } } else { - forAll(addPointCellLabels, apI) + for (const label meshCelli : addPointCellLabels) { - Type t = interpolatePointToCell(pfld, addPointCellLabels[apI]); - for (direction d=0; d(vec); - - data->SetTuple(pointi++, vec); + vtk::Tools::foamToVtkTuple + ( + scratch, + interpolatePointToCell(pfld, meshCelli) + ); + data->SetTuple(pointi++, scratch); } } @@ -846,13 +820,13 @@ void Foam::vtkPVFoam::convertLagrangianFields catch (Foam::IOerror& ioErr) { ioErr.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } catch (Foam::error& err) { // Bit of trickery to get the original message err.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } // Restore previous exception throwing state @@ -876,53 +850,44 @@ Foam::vtkPVFoam::convertFaceFieldToVTK const labelUList& faceLabels ) const { - if (debug) - { - Info<< "convert face field: " - << fld.name() - << " size=" << faceLabels.size() - << " nComp=" << int(pTraits::nComponents) << nl; - } + DebugInfo + << "Convert face field: " << fld.name() + << " size=" << faceLabels.size() + << " nComp=" << static_cast(pTraits::nComponents) << nl; const fvMesh& mesh = fld.mesh(); - const int nComp(pTraits::nComponents); const label nInternalFaces = mesh.nInternalFaces(); - const labelList& faceOwner = mesh.faceOwner(); - const labelList& faceNeigh = mesh.faceNeighbour(); + const labelUList& faceOwner = mesh.faceOwner(); + const labelUList& faceNeigh = mesh.faceNeighbour(); auto data = vtkSmartPointer::New(); data->SetName(fld.name().c_str()); - data->SetNumberOfComponents(nComp); + data->SetNumberOfComponents(static_cast(pTraits::nComponents)); data->SetNumberOfTuples(faceLabels.size()); - float scratch[nComp]; - // Interior faces: average owner/neighbour // Boundary faces: the owner value - forAll(faceLabels, idx) - { - const label faceNo = faceLabels[idx]; - if (faceNo < nInternalFaces) - { - Type t = 0.5*(fld[faceOwner[faceNo]] + fld[faceNeigh[faceNo]]); - for (direction d=0; d::nComponents]; + + vtkIdType faceId = 0; + for (const label meshFacei : faceLabels) + { + if (meshFacei < nInternalFaces) + { + Type val = + 0.5*(fld[faceOwner[meshFacei]] + fld[faceNeigh[meshFacei]]); + + vtk::Tools::foamToVtkTuple(scratch, val); } else { - const Type& t = fld[faceOwner[faceNo]]; - for (direction d=0; d(scratch); - data->SetTuple(idx, scratch); + data->SetTuple(faceId++, scratch); } return data; @@ -937,35 +902,26 @@ Foam::vtkPVFoam::convertVolFieldToVTK const foamVtuData& vtuData ) const { - const int nComp(pTraits::nComponents); const labelUList& cellMap = vtuData.cellMap(); auto data = vtkSmartPointer::New(); data->SetName(fld.name().c_str()); - data->SetNumberOfComponents(nComp); + data->SetNumberOfComponents(static_cast(pTraits::nComponents)); data->SetNumberOfTuples(cellMap.size()); - if (debug) - { - Info<< "convert volField: " - << fld.name() - << " size=" << cellMap.size() - << " (" << fld.size() << " + " - << (cellMap.size() - fld.size()) - << ") nComp=" << nComp << nl; - } + DebugInfo + << "Convert volField: " << fld.name() << " size=" + << cellMap.size() << " (field " + << fld.size() << ") nComp=" + << static_cast(pTraits::nComponents) << nl; - float scratch[nComp]; - forAll(cellMap, idx) - { - const Type& t = fld[cellMap[idx]]; - for (direction d=0; d(scratch); + float scratch[pTraits::nComponents]; - data->SetTuple(idx, scratch); + vtkIdType celli = 0; + for (const label meshCelli : cellMap) + { + vtk::Tools::foamToVtkTuple(scratch, fld[meshCelli]); + data->SetTuple(celli++, scratch); } return data; diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMesh.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMesh.C index 7a29072240..eeb3bfab1e 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMesh.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMesh.C @@ -172,7 +172,7 @@ void Foam::vtkPVFoam::convertMeshPatches() { // Point movement on single patch is OK - const labelList& patchIds = vtpData.additionalIds(); + const labelUList& patchIds = vtpData.additionalIds(); if (patchIds.size() == 1) { vtkgeom = vtpData.getCopy(); diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C index 7ef9e570ff..28d304f51c 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C @@ -49,23 +49,21 @@ vtkSmartPointer Foam::vtkPVFoam::foamVtuData::points const pointField& pts = mesh.points(); // Additional cell centres - const labelList& addPoints = this->additionalIds(); + const labelUList& addPoints = this->additionalIds(); vtkpoints->SetNumberOfPoints(pts.size() + addPoints.size()); // Normal points - label pointId = 0; + vtkIdType pointId = 0; for (const point& p : pts) { - vtkpoints->SetPoint(pointId, p.v_); - ++pointId; + vtkpoints->SetPoint(pointId++, p.v_); } // Cell centres - for (const label ptId : addPoints) + for (const label meshCelli : addPoints) { - vtkpoints->SetPoint(pointId, mesh.C()[ptId].v_); - ++pointId; + vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_); } return vtkpoints; @@ -85,23 +83,21 @@ vtkSmartPointer Foam::vtkPVFoam::foamVtuData::points const pointField& pts = mesh.points(); // Additional cell centres - const labelList& addPoints = this->additionalIds(); + const labelUList& addPoints = this->additionalIds(); vtkpoints->SetNumberOfPoints(pointMap.size() + addPoints.size()); // Normal points - label pointId = 0; - for (const label ptId : pointMap) + vtkIdType pointId = 0; + for (const label meshPointi : pointMap) { - vtkpoints->SetPoint(pointId, pts[ptId].v_); - ++pointId; + vtkpoints->SetPoint(pointId++, pts[meshPointi].v_); } // Cell centres - for (const label ptId : addPoints) + for (const label meshCelli : addPoints) { - vtkpoints->SetPoint(pointId, mesh.C()[ptId].v_); - ++pointId; + vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_); } return vtkpoints; diff --git a/src/conversion/vtk/adaptor/foamVtkTools.H b/src/conversion/vtk/adaptor/foamVtkTools.H index e73dd87832..f52d3f1905 100644 --- a/src/conversion/vtk/adaptor/foamVtkTools.H +++ b/src/conversion/vtk/adaptor/foamVtkTools.H @@ -49,6 +49,7 @@ SourceFiles #include "pointField.H" #include "symmTensor.H" +// VTK includes #include #include #include @@ -209,13 +210,36 @@ public: //- Remapping for some OpenFOAM data types (eg, symmTensor) + // \param data[in,out] The data to be remapped in-place template inline static void remapTuple(float data[]) {} //- Remapping for some OpenFOAM data types (eg, symmTensor) + // \param data[in,out] The data to be remapped in-place template inline static void remapTuple(double data[]) {} + //- Copy/transcribe OpenFOAM data types to VTK format + // This allows a change of data type (float vs double) as well as + // addressing any swapping issues (eg, symmTensor) + // + // \param output[out] The output scratch space. Must be long enough + // to hold the result. + // \param val[in] The input data to copy/transcribe + template + inline static void foamToVtkTuple(float output[], const Type& val); + + //- Copy/transcribe OpenFOAM data types to VTK format + // This allows a change of data type (float vs double) as well as + // addressing any swapping issues (eg, symmTensor) + // + // \param output[out] The output scratch space. Must be long enough + // to hold the result. + // \param val[in] The input data to copy/transcribe + template + inline static void foamToVtkTuple(double output[], const Type& val); + + // Field Conversion Functions //- Copy list to pre-allocated vtk array. @@ -225,7 +249,7 @@ public: ( vtkFloatArray* array, const UList& input, - const label start = 0 + vtkIdType start = 0 //!< The write offset into output array ); //- Create named field initialized to zero @@ -270,7 +294,6 @@ inline void Foam::vtk::Tools::remapTuple(double data[]) } - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace vtk diff --git a/src/conversion/vtk/adaptor/foamVtkToolsI.H b/src/conversion/vtk/adaptor/foamVtkToolsI.H index f93b2c7d55..e151f1a7d1 100644 --- a/src/conversion/vtk/adaptor/foamVtkToolsI.H +++ b/src/conversion/vtk/adaptor/foamVtkToolsI.H @@ -87,4 +87,34 @@ inline vtkSmartPointer Foam::vtk::Tools::identityVertices }; +template +inline void Foam::vtk::Tools::foamToVtkTuple +( + float output[], + const Type& val +) +{ + for (direction cmpt=0; cmpt < pTraits::nComponents; ++cmpt) + { + output[cmpt] = component(val, cmpt); + } + remapTuple(output); +} + + +template +inline void Foam::vtk::Tools::foamToVtkTuple +( + double output[], + const Type& val +) +{ + for (direction cmpt=0; cmpt < pTraits::nComponents; ++cmpt) + { + output[cmpt] = component(val, cmpt); + } + remapTuple(output); +} + + // ************************************************************************* // diff --git a/src/conversion/vtk/adaptor/foamVtkToolsTemplates.C b/src/conversion/vtk/adaptor/foamVtkToolsTemplates.C index 3a7b653869..5049e67ff8 100644 --- a/src/conversion/vtk/adaptor/foamVtkToolsTemplates.C +++ b/src/conversion/vtk/adaptor/foamVtkToolsTemplates.C @@ -50,12 +50,11 @@ Foam::vtk::Tools::Patch::points(const PatchType& p) auto vtkpoints = vtkSmartPointer::New(); vtkpoints->SetNumberOfPoints(pts.size()); - vtkIdType pointId = 0; + vtkIdType pointId = 0; for (const point& p : pts) { - vtkpoints->SetPoint(pointId, p.v_); - ++pointId; + vtkpoints->SetPoint(pointId++, p.v_); } return vtkpoints; @@ -127,8 +126,7 @@ Foam::vtk::Tools::Patch::faceNormals(const PatchType& p) vtkIdType faceId = 0; for (const vector& n : norms) { - array->SetTuple(faceId, n.v_); - ++faceId; + array->SetTuple(faceId++, n.v_); } return array; @@ -145,7 +143,7 @@ Foam::label Foam::vtk::Tools::transcribeFloatData ( vtkFloatArray* array, const UList& input, - const label start + vtkIdType start ) { const int nComp(pTraits::nComponents); @@ -162,7 +160,7 @@ Foam::label Foam::vtk::Tools::transcribeFloatData } const vtkIdType maxSize = array->GetNumberOfTuples(); - const vtkIdType endPos = vtkIdType(start) + vtkIdType(input.size()); + const vtkIdType endPos = start + vtkIdType(input.size()); if (!maxSize) { @@ -174,7 +172,7 @@ Foam::label Foam::vtk::Tools::transcribeFloatData WarningInFunction << "vtk array '" << array->GetName() << "' copy with out-of-range [0," << long(maxSize) << ")" - << " starting at " << start + << " starting at " << long(start) << nl; return 0; @@ -185,23 +183,18 @@ Foam::label Foam::vtk::Tools::transcribeFloatData << "vtk array '" << array->GetName() << "' copy ends out-of-range (" << long(maxSize) << ")" << " using sizing (start,size) = (" - << start << "," << input.size() << ")" + << long(start) << "," << input.size() << ")" << nl; return 0; } - float scratch[nComp]; - forAll(input, idx) - { - const Type& t = input[idx]; - for (direction d=0; d(scratch); + float scratch[pTraits::nComponents]; - array->SetTuple(start+idx, scratch); + for (const Type& val : input) + { + foamToVtkTuple(scratch, val); + array->SetTuple(start++, scratch); } return input.size(); @@ -219,7 +212,7 @@ Foam::vtk::Tools::zeroField auto data = vtkSmartPointer::New(); data->SetName(name.c_str()); - data->SetNumberOfComponents(int(pTraits::nComponents)); + data->SetNumberOfComponents(static_cast(pTraits::nComponents)); data->SetNumberOfTuples(size); data->Fill(0); @@ -239,7 +232,7 @@ Foam::vtk::Tools::convertFieldToVTK auto data = vtkSmartPointer::New(); data->SetName(name.c_str()); - data->SetNumberOfComponents(int(pTraits::nComponents)); + data->SetNumberOfComponents(static_cast(pTraits::nComponents)); data->SetNumberOfTuples(fld.size()); transcribeFloatData(data, fld); From 8d124355dcfd7606f082357ae24f0f284bbca4d2 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 5 Dec 2018 18:07:28 +0100 Subject: [PATCH 12/18] CONFIG: update config for VTK from 9.0.0 to 8.2.0 - the previous 9.0.0 was a premature change from ParaView 5.5 and still will not be reached for a while --- etc/config.csh/vtk | 2 +- etc/config.sh/vtk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/config.csh/vtk b/etc/config.csh/vtk index 1ca8836fd7..aaeccc3861 100644 --- a/etc/config.csh/vtk +++ b/etc/config.csh/vtk @@ -30,7 +30,7 @@ #------------------------------------------------------------------------------ # USER EDITABLE PART: Changes made here may be lost with the next upgrade -set vtk_version=VTK-9.0.0 +set vtk_version=VTK-8.2.0 set mesa_version=mesa-17.1.1 setenv VTK_DIR $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$vtk_version diff --git a/etc/config.sh/vtk b/etc/config.sh/vtk index 242407e977..782fcc43e4 100644 --- a/etc/config.sh/vtk +++ b/etc/config.sh/vtk @@ -31,7 +31,7 @@ #------------------------------------------------------------------------------ # USER EDITABLE PART: Changes made here may be lost with the next upgrade -vtk_version=VTK-9.0.0 +vtk_version=VTK-8.2.0 mesa_version=mesa-17.1.1 export VTK_DIR=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$vtk_version From e3e0e0557ff219b5a0c12d87b4e4543e989497b2 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 5 Dec 2018 21:27:29 +0100 Subject: [PATCH 13/18] BUG: unguarded use of globalIndex in vtk writers (fixes #1110) - the problem occurred when running the writers in a parallel solver or utility but requesting output on the master only. Adjusted the logic to avoid globalIndex for these cases. Previously the if (parallel_) checks were happening later, after the globalIndex had already been created. --- .../vtk/output/foamVtkInternalWriter.C | 46 ++++++++----------- .../vtk/output/foamVtkInternalWriter.H | 10 ++-- .../vtk/output/foamVtkPatchWriter.C | 33 +++++++------ .../vtk/output/foamVtkPatchWriter.H | 10 ++-- src/fileFormats/vtk/file/foamVtkFileWriter.C | 1 - src/meshTools/output/foamVtkIndPatchWriter.C | 32 ++++++------- src/meshTools/output/foamVtkIndPatchWriter.H | 10 ++-- src/meshTools/output/foamVtkSurfaceWriter.C | 33 +++++++------ src/meshTools/output/foamVtkSurfaceWriter.H | 10 ++-- .../output/foamVtkWriteCellSetFaces.C | 43 +++++++++-------- src/meshTools/output/foamVtkWriteFaceSet.C | 14 ++++-- src/meshTools/output/foamVtkWritePointSet.C | 4 +- 12 files changed, 119 insertions(+), 127 deletions(-) diff --git a/src/conversion/vtk/output/foamVtkInternalWriter.C b/src/conversion/vtk/output/foamVtkInternalWriter.C index 11864207b1..1179b8971f 100644 --- a/src/conversion/vtk/output/foamVtkInternalWriter.C +++ b/src/conversion/vtk/output/foamVtkInternalWriter.C @@ -123,10 +123,7 @@ void Foam::vtk::internalWriter::writePoints() } -void Foam::vtk::internalWriter::writeCellsLegacy -( - const globalIndex& pointOffsets -) +void Foam::vtk::internalWriter::writeCellsLegacy(const label pointOffset) { const List& cellTypes = vtuCells_.cellTypes(); const labelList& vertLabels = vtuCells_.vertLabels(); @@ -165,7 +162,7 @@ void Foam::vtk::internalWriter::writeCellsLegacy vtk::vtuSizing::copyVertLabelsLegacy ( vertLabels, - pointOffsets.localStart() + pointOffset ) ); } @@ -206,10 +203,7 @@ void Foam::vtk::internalWriter::writeCellsLegacy } -void Foam::vtk::internalWriter::writeCellsConnectivity -( - const globalIndex& pointOffsets -) +void Foam::vtk::internalWriter::writeCellsConnectivity(const label pointOffset) { // // 'connectivity' @@ -239,7 +233,7 @@ void Foam::vtk::internalWriter::writeCellsConnectivity vtk::vtuSizing::copyVertLabelsXml ( vertLabels, - pointOffsets.localStart() + pointOffset ) ); } @@ -263,12 +257,6 @@ void Foam::vtk::internalWriter::writeCellsConnectivity const labelList& vertOffsets = vtuCells_.vertOffsets(); label nOffs = vertOffsets.size(); - // global connectivity offsets - const globalIndex procOffset - ( - vertOffsets.empty() ? 0 : vertOffsets.last() - ); - if (parallel_) { reduce(nOffs, sumOp