Files
openfoam/tutorials/heatTransfer/chtMultiRegionFoam/externalCoupledMultiRegionHeater/externalSolver
mattijs 8d5800c5f8 ENH: externalCoupled: changed to non-OutputFilter functionObject.
- moved control to functionObject (from bc)
- this allows multi-region support
- see heatTransfer/chtMultiRegionFoam/externalCoupledMultiRegionHeater tut
- generalisation of streamed reading/writing of specialised bcs
2015-11-26 13:04:06 +00:00

105 lines
2.5 KiB
Bash
Executable File

#!/bin/sh
#
# 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
echo "Executing dummy external solver"
commsDir="comms"
regionGroupName="heater_topAir"
patchGroupName="coupleGroup"
fieldName="T"
lockFile="${commsDir}/OpenFOAM.lock"
dataFile="${commsDir}/${regionGroupName}/${patchGroupName}/${fieldName}"
waitSec=1
timeOut=10
nSteps=200 # maximum number of time steps. Note: should be more than
# number of iterations on the OpenFOAM side
refGrad=0
valueFraction=1
log()
{
echo "External: $@"
}
init()
{
log "initialisation: creating ${dataFile}.in"
# Hard-coded for patch of size 8 (heater/minY)
n1=8
refValue1=500
touch "${dataFile}.in"
log "initialisation: adding $n1 data elements with refValue $refValue1"
for i in $(seq 1 $n1); do
echo "$refValue1 $refGrad $valueFraction" >> "${dataFile}.in"
done
# Hard-coded for patch of size 40 (topAir/minX)
n2=40
refValue2=300
log "initialisation: adding $n2 data elements with refValue $refValue2"
for i in $(seq 1 $n2); do
echo "$refValue2 $refGrad $valueFraction" >> "${dataFile}.in"
done
# create lock file to pass control to OF
touch ${lockFile}
}
# create the comms directory
mkdir -p ${commsDir}/${regionGroupName}/${patchGroupName}
# tutorial case employs the 'initByExternalOption', so we need to provide
# the initial values
init
totalWait=0
step=0
while [ $step -lt $nSteps ]; do
if [ -f $lockFile ]; then
log "found lock file ${lockFile} - waiting"
totalWait=$(expr $totalWait + $waitSec)
if [ $totalWait -gt $timeOut ]; then
log "timeout"
break
else
sleep $waitSec
fi
else
totalWait=0
step=$(expr $step + 1)
log "step $step"
log "lock not present - taking control"
log "sleeping for $waitSec secs to simulate external process"
sleep $waitSec
log "updating ${dataFile}.in from ${dataFile}.out"
awk '{if( $1 != "#" ){print $1+1 " 0 1"}}' \
${dataFile}.out | tee ${dataFile}.in
log "creating lock file ${lockFile}"
touch ${lockFile}
fi
done
log "done"
# ----------------------------------------------------------------- end-of-file