Merge branch 'externalCoupled' into 'master'

External coupled

Improvements and bugfixes for externalCoupledFunctionObject - issues #278 #269

See merge request !72
This commit is contained in:
Andrew Heather
2016-11-15 09:49:58 +00:00
7 changed files with 282 additions and 178 deletions

View File

@ -15,6 +15,12 @@ cd ${0%/*} || exit 1 # Run from this directory
# Decompose
runApplication decomposePar -allRegions
## Can verify parallel operation of createExternalCoupledPatchGeometry
# \rm -f log.createExternalCoupledPatchGeometry
# runParallel createExternalCoupledPatchGeometry \
# -regions '(topAir heater)' coupleGroup \
# -commsDir $PWD/comms
# Run OpenFOAM
runParallel $(getApplication) &

View File

@ -28,6 +28,6 @@ runApplication createExternalCoupledPatchGeometry \
echo
echo "creating files for paraview post-processing"
echo
paraFoam -touchAll
paraFoam -touchAll 2>/dev/null
# ----------------------------------------------------------------- end-of-file

View File

@ -20,13 +20,17 @@ 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
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: $@"
@ -53,7 +57,7 @@ init()
echo "$refValue2 $refGrad $valueFraction" >> "${dataFile}.in"
done
# create lock file to pass control to OF
# Create lock file to pass control to OpenFOAM
touch ${lockFile}
}
@ -61,7 +65,6 @@ init()
# create the comms directory
mkdir -p ${commsDir}/${regionGroupName}/${patchGroupName}
# tutorial case employs the 'initByExternalOption', so we need to provide
# the initial values
init
@ -69,11 +72,24 @@ init
totalWait=0
step=0
while [ $step -lt $nSteps ]; do
if [ -f $lockFile ]; then
log "found lock file ${lockFile} - waiting"
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
if [ $totalWait -gt $timeOut ]
then
log "timeout"
break
else
@ -91,7 +107,7 @@ while [ $step -lt $nSteps ]; do
log "updating ${dataFile}.in from ${dataFile}.out"
awk '{if( $1 != "#" ){print $1+1 " 0 1"}}' \
${dataFile}.out | tee ${dataFile}.in
${dataFile}.out >| ${dataFile}.in
log "creating lock file ${lockFile}"
touch ${lockFile}
@ -100,5 +116,7 @@ done
log "done"
# Remove the lock file too
\rm -f $lockFile 2>/dev/null
#------------------------------------------------------------------------------

View File

@ -26,11 +26,12 @@ startTime 0;
stopAt endTime;
endTime 1;
endTime 0.5;
deltaT 0.001;
writeControl adjustableRunTime;
writeInterval 0.1;
purgeWrite 0;
@ -56,40 +57,7 @@ adjustTimeStep yes;
functions
{
externalCoupled
{
// Where to load it from (if not already in solver)
functionObjectLibs ("libjobControl.so");
type externalCoupled;
// Directory to use for communication
commsDir "${FOAM_CASE}/comms";
// Does external process start first
initByExternal true;
// Additional output
log true;
regions
{
// Region name (wildcards allowed)
"(topAir|heater)"
{
// In topAir adjust the minX patch (fixedValue)
// Patch or patchGroup
coupleGroup
{
// Fields to output in commsDir
writeFields (T);
// Fields to read from commsDir
readFields (T);
}
}
}
}
#include "externalCoupled"
}

View File

@ -0,0 +1,43 @@
// -*- C++ -*-
// control for external coupled simulation
externalCoupled
{
// Where to load it from (if not already in solver)
functionObjectLibs ("libjobControl.so");
type externalCoupled;
// Directory to use for communication
commsDir "${FOAM_CASE}/comms";
// Does external process start first
initByExternal true;
// Cleanup behaviour on termination (remove|done)
stateEnd done;
// Additional output
log true;
regions
{
// Region name (wildcards allowed)
"(topAir|heater)"
{
// In topAir adjust the minX patch (fixedValue)
// Patch or patchGroup
coupleGroup
{
// Fields to output in commsDir
writeFields (T);
// Fields to read from commsDir
readFields (T);
}
}
}
}
// ************************************************************************* //