ENH: add isTrue function to RunFunctions

- check if the first argument corresponds to an OpenFOAM value for
  'true' (as per Switch).
  True == 't', 'y', 'true', 'yes', 'on'. Everything else is not true.

- when the first argument is '-dict', it initializes the value
  with a query via foamDictionary.
  Eg,
       isTrue -dict mydict -entry parallel

   ==> value=$(foamDictionary mydict -entry parallel -value)
       isTrue $value

   a missing entry is silently treated as false.

ENH: add getNumberOfPatchFaces function in RunFunctions

- simple extraction of nFaces from boundary file for given patch/region
This commit is contained in:
Mark Olesen 2018-11-30 19:29:49 +01:00
parent f2e88645c2
commit c5beee63f3
3 changed files with 134 additions and 28 deletions

View File

@ -52,6 +52,76 @@ notTest()
}
#
# Check if '$1' corresponds to an OpenFOAM value for 'true' (see Switch.H)
# - does not handle integers very much, although Switch does
#
# Handles -dict as first argument to relay the balance to foamDictionary
# Eg,
# isTrue -dict controls -entry coupling
# ->
# value=$(foamDictionary controls -entry coupling -value)
# if value ...
#
isTrue()
{
local value="$1"
if [ "$value" = "-dict" ]
then
shift
value="$(foamDictionary -value $@ 2>/dev/null)" || return 2
fi
case "$value" in
(t | y | true | yes | on) return 0 ;;
(f | n | false | no | off) return 1 ;;
esac
return 2
}
#
# Extract 'nFaces' for given patchName from constant/polyMesh/boundary
# or constant/{region}/polyMesh/boundary
#
# On failure:
# return '1'
# exit status 1
#
getNumberOfPatchFaces()
{
local patch="${1:-}"
local file="${2:-}"
file="constant/$file${file:+/}polyMesh/boundary"
[ -n "$patch" ] || {
echo "No patch name given" 1>&2
return 1
}
[ -f "$file" ] || {
echo "No such file: $file" 1>&2
return 2
}
local nFaces
nFaces=$(sed -ne \
'/^ *'"$patch"' *$/,/}/{s/^ *nFaces *\([0-9][0-9]*\) *;.*$/\1/p}' \
"$file")
if [ -n "nFaces" ]
then
echo "$nFaces"
else
echo "No patch entry found for '$patch' in $file" 1>&2
echo 0 # Report as 0
return 2
fi
}
#
# Extract 'numberOfSubdomains' from system/decomposeParDict
# (or alternative location).

View File

@ -1,12 +1,14 @@
#!/bin/sh
#
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions
# Dummy external solver to communicate with OpenFOAM via externalCoupled
# functionObject
#
# Functionality is hard-coded for this particular test case
# - patch temperatures increased by 1K on each step
#
cd ${0%/*} || exit 1 # Run from this directory
# -----------------------------------------------------------------------------
# Check for unassigned variables
set -u
@ -53,28 +55,44 @@ stopMasterNow()
}
# Patch size (heater/minY)
nFaces1=$(getNumberOfPatchFaces minY heater) || exit $?
# Patch size (topAir/minX)
nFaces2=$(getNumberOfPatchFaces minX topAir) || exit $?
init()
{
log "init - creating ${dataFile}.in"
cat /dev/null >| "${dataFile}.in"
# Hard-coded for patch of size 8 (heater/minY)
local n1=8
local refValue1=500
# Local face counter, Local refValue
local nFaces refValue
log "init - adding $n1 data elements with refValue $refValue1"
for i in $(seq 1 $n1)
# Patch (heater/minY)
nFaces="$nFaces1"
refValue=500
log "init - adding $nFaces data elements with refValue $refValue"
while [ "$nFaces" -gt 0 ]
do
echo "$refValue1 $refGrad $valueFraction"
nFaces=$((nFaces - 1))
echo "$refValue $refGrad $valueFraction"
done >> "${dataFile}.in"
# Hard-coded for patch of size 40 (topAir/minX)
local n2=40
local refValue2=300
log "init - adding $n2 data elements with refValue $refValue2"
for i in $(seq 1 $n2)
# Patch (topAir/minX)
nFaces="$nFaces2"
refValue=300
log "init - adding $nFaces data elements with refValue $refValue"
while [ "$nFaces" -gt 0 ]
do
echo "$refValue2 $refGrad $valueFraction"
nFaces=$((nFaces - 1))
echo "$refValue $refGrad $valueFraction"
done >> "${dataFile}.in"
# Verify line count?

View File

@ -1,12 +1,14 @@
#!/bin/sh
#
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions
# Dummy external solver to communicate with OpenFOAM via externalCoupled
# functionObject
#
# Functionality is hard-coded for this particular test case
# - patch temperatures increased by 1K on each step
#
cd ${0%/*} || exit 1 # Run from this directory
# -----------------------------------------------------------------------------
# Check for unassigned variables
set -u
@ -53,28 +55,44 @@ stopMasterNow()
}
# Patch size (heater/minY)
nFaces1=$(getNumberOfPatchFaces minY heater) || exit $?
# Patch size (topAir/minX)
nFaces2=$(getNumberOfPatchFaces minX topAir) || exit $?
init()
{
log "init - creating ${dataFile}.in"
cat /dev/null >| "${dataFile}.in"
# Hard-coded for patch of size 8 (heater/minY)
local n1=8
local refValue1=500
# Local face counter, Local refValue
local nFaces refValue
log "init - adding $n1 data elements with refValue $refValue1"
for i in $(seq 1 $n1)
# Patch (heater/minY)
nFaces="$nFaces1"
refValue=500
log "init - adding $nFaces data elements with refValue $refValue"
while [ "$nFaces" -gt 0 ]
do
echo "$refValue1 $refGrad $valueFraction"
nFaces=$((nFaces - 1))
echo "$refValue $refGrad $valueFraction"
done >> "${dataFile}.in"
# Hard-coded for patch of size 40 (topAir/minX)
local n2=40
local refValue2=300
log "init - adding $n2 data elements with refValue $refValue2"
for i in $(seq 1 $n2)
# Patch (topAir/minX)
nFaces="$nFaces2"
refValue=300
log "init - adding $nFaces data elements with refValue $refValue"
while [ "$nFaces" -gt 0 ]
do
echo "$refValue2 $refGrad $valueFraction"
nFaces=$((nFaces - 1))
echo "$refValue $refGrad $valueFraction"
done >> "${dataFile}.in"
# Verify line count?