#!/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=5 timeOut=100 nSteps=1000 # maximum number of time steps. Note: should be more than # number of iterations on the OpenFOAM side refGrad=0 valueFraction=1 # Remove any old junk \rm -f $lockFile 2>/dev/null 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 OpenFOAM 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 if grep -q "status=done" ${lockFile} then log "found lock file ${lockFile} with 'status=done' - finished" break elif [ -s $lockFile ] then log "found lock file ${lockFile} containing '$(cat $lockFile)' - waiting" else log "found lock file ${lockFile} - waiting" fi 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 >| ${dataFile}.in log "creating lock file ${lockFile}" touch ${lockFile} fi done log "done" # Remove the lock file too \rm -f $lockFile 2>/dev/null #------------------------------------------------------------------------------