Merge remote-tracking branch 'origin/externalCoupled' into develop

- update tutorial and adjust function object for updated infrastructure.
This commit is contained in:
Mark Olesen
2016-11-19 18:43:34 +01:00
25 changed files with 618 additions and 953 deletions

View File

@ -52,7 +52,55 @@ namespace functionObjects
Foam::word Foam::functionObjects::externalCoupled::lockName = "OpenFOAM"; Foam::word Foam::functionObjects::externalCoupled::lockName = "OpenFOAM";
Foam::string Foam::functionObjects::externalCoupled::patchKey = "# Patch: "; Foam::string Foam::functionObjects::externalCoupled::patchKey = "// Patch:";
template<>
const char* Foam::NamedEnum
<
Foam::functionObjects::externalCoupled::stateEnd,
2
>::names[] =
{
"remove",
"done"
// The 'IGNORE' enumeration is internal use only and thus has no name
};
const Foam::NamedEnum
<
Foam::functionObjects::externalCoupled::stateEnd,
2
> Foam::functionObjects::externalCoupled::stateEndNames_;
namespace Foam
{
//! \cond fileScope
//- Write list content with size, bracket, content, bracket one-per-line.
// This makes for consistent for parsing, regardless of the list length.
template <class T>
static void writeList(Ostream& os, const string& header, const UList<T>& L)
{
// Header string
os << header.c_str() << nl;
// Write size and start delimiter
os << L.size() << nl
<< token::BEGIN_LIST;
// Write contents
forAll(L, i)
{
os << nl << L[i];
}
// Write end delimiter
os << nl << token::END_LIST << nl << endl;
}
//! \endcond
}
// namespace Foam
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -91,7 +139,7 @@ Foam::fileName Foam::functionObjects::externalCoupled::lockFile() const
} }
void Foam::functionObjects::externalCoupled::createLockFile() const void Foam::functionObjects::externalCoupled::useMaster() const
{ {
if (!Pstream::master()) if (!Pstream::master())
{ {
@ -107,13 +155,13 @@ void Foam::functionObjects::externalCoupled::createLockFile() const
Log << type() << ": creating lock file" << endl; Log << type() << ": creating lock file" << endl;
OFstream os(fName); OFstream os(fName);
os << "lock file"; os << "status=openfoam\n";
os.flush(); os.flush();
} }
} }
void Foam::functionObjects::externalCoupled::removeLockFile() const void Foam::functionObjects::externalCoupled::useSlave() const
{ {
if (!Pstream::master()) if (!Pstream::master())
{ {
@ -122,7 +170,37 @@ void Foam::functionObjects::externalCoupled::removeLockFile() const
Log << type() << ": removing lock file" << endl; Log << type() << ": removing lock file" << endl;
rm(lockFile()); Foam::rm(lockFile());
}
void Foam::functionObjects::externalCoupled::cleanup() const
{
if (!Pstream::master())
{
return;
}
const fileName lck(lockFile());
switch (stateEnd_)
{
case REMOVE:
{
Log << type() << ": removing lock file" << endl;
Foam::rm(lck);
}
break;
case DONE:
{
Log << type() << ": lock file status=done" << endl;
OFstream os(lck);
os << "status=done\n";
os.flush();
}
break;
case IGNORE:
break;
}
} }
@ -192,30 +270,29 @@ void Foam::functionObjects::externalCoupled::removeWriteFiles() const
} }
void Foam::functionObjects::externalCoupled::wait() const void Foam::functionObjects::externalCoupled::waitForSlave() const
{ {
const fileName fName(lockFile()); const fileName fName(lockFile());
label found = 0;
label totalTime = 0; label totalTime = 0;
bool found = false;
Log << type() << ": beginning wait for lock file " << fName << nl; Log << type() << ": beginning wait for lock file " << fName << nl;
while (found == 0) while (!found)
{ {
if (Pstream::master()) if (Pstream::master())
{ {
if (totalTime > timeOut_) if (totalTime > timeOut_)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Wait time exceeded time out time of " << timeOut_ << "Wait time exceeded timeout of " << timeOut_
<< " s" << abort(FatalError); << " s" << abort(FatalError);
} }
IFstream is(fName); IFstream is(fName);
if (is.good()) if (is.good())
{ {
found++; found = true;
Log << type() << ": found lock file " << fName << endl; Log << type() << ": found lock file " << fName << endl;
} }
@ -229,7 +306,7 @@ void Foam::functionObjects::externalCoupled::wait() const
} }
// Prevent other procs from racing ahead // Prevent other procs from racing ahead
reduce(found, sumOp<label>()); reduce(found, orOp<bool>());
} }
} }
@ -384,8 +461,6 @@ void Foam::functionObjects::externalCoupled::writeGeometry
fileName dir(groupDir(commsDir, compositeName(regionNames), groupName)); fileName dir(groupDir(commsDir, compositeName(regionNames), groupName));
Info<< typeName << ": writing geometry to " << dir << endl;
autoPtr<OFstream> osPointsPtr; autoPtr<OFstream> osPointsPtr;
autoPtr<OFstream> osFacesPtr; autoPtr<OFstream> osFacesPtr;
if (Pstream::master()) if (Pstream::master())
@ -393,124 +468,87 @@ void Foam::functionObjects::externalCoupled::writeGeometry
mkDir(dir); mkDir(dir);
osPointsPtr.reset(new OFstream(dir/"patchPoints")); osPointsPtr.reset(new OFstream(dir/"patchPoints"));
osFacesPtr.reset(new OFstream(dir/"patchFaces")); osFacesPtr.reset(new OFstream(dir/"patchFaces"));
osPointsPtr() << "// Group: " << groupName << endl;
osFacesPtr() << "// Group: " << groupName << endl;
Info<< typeName << ": writing geometry to " << dir << endl;
} }
// Individual region/patch entries
DynamicList<face> allMeshesFaces; DynamicList<face> allFaces;
DynamicField<point> allMeshesPoints; DynamicField<point> allPoints;
labelList pointToGlobal;
labelList uniquePointIDs;
forAll(meshes, meshi) forAll(meshes, meshi)
{ {
const fvMesh& mesh = meshes[meshi]; const fvMesh& mesh = meshes[meshi];
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
const labelList patchIDs const labelList patchIDs
( (
pbm.patchSet(List<wordRe>(1, groupName)).sortedToc() mesh.boundaryMesh().patchSet
(
List<wordRe>(1, groupName)
).sortedToc()
); );
// Count faces
label nFaces = 0;
forAll(patchIDs, i) forAll(patchIDs, i)
{ {
nFaces += pbm[patchIDs[i]].size(); const polyPatch& p = mesh.boundaryMesh()[patchIDs[i]];
}
// Collect faces mesh.globalData().mergePoints
DynamicList<label> allFaceIDs(nFaces); (
forAll(patchIDs, i) p.meshPoints(),
{ p.meshPointMap(),
const polyPatch& p = pbm[patchIDs[i]]; pointToGlobal,
uniquePointIDs
);
forAll(p, pi) label proci = Pstream::myProcNo();
List<pointField> collectedPoints(Pstream::nProcs());
collectedPoints[proci] = pointField(mesh.points(), uniquePointIDs);
Pstream::gatherList(collectedPoints);
List<faceList> collectedFaces(Pstream::nProcs());
faceList& patchFaces = collectedFaces[proci];
patchFaces = p.localFaces();
forAll(patchFaces, facei)
{ {
allFaceIDs.append(p.start()+pi); inplaceRenumber(pointToGlobal, patchFaces[facei]);
} }
} Pstream::gatherList(collectedFaces);
// Construct overall patch if (Pstream::master())
indirectPrimitivePatch allPatch
(
IndirectList<face>(mesh.faces(), allFaceIDs),
mesh.points()
);
labelList pointToGlobal;
labelList uniquePointIDs;
mesh.globalData().mergePoints
(
allPatch.meshPoints(),
allPatch.meshPointMap(),
pointToGlobal,
uniquePointIDs
);
label proci = Pstream::myProcNo();
List<pointField> collectedPoints(Pstream::nProcs());
collectedPoints[proci] = pointField(mesh.points(), uniquePointIDs);
Pstream::gatherList(collectedPoints);
List<faceList> collectedFaces(Pstream::nProcs());
faceList& patchFaces = collectedFaces[proci];
patchFaces = allPatch.localFaces();
forAll(patchFaces, facei)
{
inplaceRenumber(pointToGlobal, patchFaces[facei]);
}
Pstream::gatherList(collectedFaces);
if (Pstream::master())
{
// Append and renumber
label nPoints = allMeshesPoints.size();
forAll(collectedPoints, proci)
{ {
allMeshesPoints.append(collectedPoints[proci]); allPoints.clear();
allFaces.clear();
} for (label proci=0; proci < Pstream::nProcs(); ++proci)
face newFace;
forAll(collectedFaces, proci)
{
const faceList& procFaces = collectedFaces[proci];
forAll(procFaces, facei)
{ {
const face& f = procFaces[facei]; allPoints.append(collectedPoints[proci]);
allFaces.append(collectedFaces[proci]);
newFace.setSize(f.size());
forAll(f, fp)
{
newFace[fp] = f[fp]+nPoints;
}
allMeshesFaces.append(newFace);
} }
nPoints += collectedPoints[proci].size(); Info<< typeName << ": mesh " << mesh.name()
<< ", patch " << p.name()
<< ": writing " << allPoints.size() << " points to "
<< osPointsPtr().name() << nl
<< typeName << ": mesh " << mesh.name()
<< ", patch " << p.name()
<< ": writing " << allFaces.size() << " faces to "
<< osFacesPtr().name() << endl;
// The entry name (region / patch)
const string entryHeader =
patchKey + ' ' + mesh.name() + ' ' + p.name();
writeList(osPointsPtr(), entryHeader, allPoints);
writeList(osFacesPtr(), entryHeader, allFaces);
} }
} }
{
Info<< typeName << ": for mesh " << mesh.name()
<< " writing " << allMeshesPoints.size() << " points to "
<< osPointsPtr().name() << endl;
Info<< typeName << ": for mesh " << mesh.name()
<< " writing " << allMeshesFaces.size() << " faces to "
<< osFacesPtr().name() << endl;
}
}
// Write points
if (osPointsPtr.valid())
{
osPointsPtr() << allMeshesPoints << endl;
}
// Write faces
if (osFacesPtr.valid())
{
osFacesPtr() << allMeshesFaces << endl;
} }
} }
@ -532,7 +570,7 @@ Foam::word Foam::functionObjects::externalCoupled::compositeName
{ {
// For compatibility with single region cases suppress single // For compatibility with single region cases suppress single
// region name // region name
return word(""); return word::null;
} }
else else
{ {
@ -759,7 +797,7 @@ void Foam::functionObjects::externalCoupled::initialise()
if (initByExternal_) if (initByExternal_)
{ {
// Wait for initial data to be made available // Wait for initial data to be made available
wait(); waitForSlave();
// Read data passed back from external source // Read data passed back from external source
readData(); readData();
@ -780,7 +818,7 @@ Foam::functionObjects::externalCoupled::externalCoupled
: :
functionObject(name), functionObject(name),
time_(runTime), time_(runTime),
enabled_(true), stateEnd_(REMOVE),
initialised_(false) initialised_(false)
{ {
read(dict); read(dict);
@ -792,7 +830,7 @@ Foam::functionObjects::externalCoupled::externalCoupled
if (!initByExternal_) if (!initByExternal_)
{ {
createLockFile(); useMaster();
} }
} }
@ -800,7 +838,9 @@ Foam::functionObjects::externalCoupled::externalCoupled
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::externalCoupled::~externalCoupled() Foam::functionObjects::externalCoupled::~externalCoupled()
{} {
cleanup();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -815,11 +855,12 @@ bool Foam::functionObjects::externalCoupled::execute()
// Write data for external source // Write data for external source
writeData(); writeData();
// remove lock file, signalling external source to execute // Signal external source to execute (by removing lock file)
removeLockFile(); // - Wait for slave to provide data
useSlave();
// Wait for response // Wait for response
wait(); waitForSlave();
// Remove old data files from OpenFOAM // Remove old data files from OpenFOAM
removeWriteFiles(); removeWriteFiles();
@ -827,8 +868,8 @@ bool Foam::functionObjects::externalCoupled::execute()
// Read data passed back from external source // Read data passed back from external source
readData(); readData();
// create lock file for external source // Signal external source to wait (by creating the lock file)
createLockFile(); useMaster();
return true; return true;
} }
@ -846,7 +887,9 @@ bool Foam::functionObjects::externalCoupled::end()
// Remove old data files // Remove old data files
removeReadFiles(); removeReadFiles();
removeWriteFiles(); removeWriteFiles();
removeLockFile(); cleanup();
stateEnd_ = IGNORE; // Avoid running cleanup() again in destructor
return true; return true;
} }
@ -856,28 +899,24 @@ bool Foam::functionObjects::externalCoupled::read(const dictionary& dict)
{ {
functionObject::read(dict); functionObject::read(dict);
dict.readIfPresent("enabled", enabled_); calcFrequency_ = dict.lookupOrDefault("calcFrequency", 1);
if (!enabled_)
{
return true;
}
dict.lookup("commsDir") >> commsDir_; dict.lookup("commsDir") >> commsDir_;
commsDir_.expand(); commsDir_.expand();
commsDir_.clean();
waitInterval_ = dict.lookupOrDefault("waitInterval", 1); waitInterval_ = dict.lookupOrDefault("waitInterval", 1);
timeOut_ = dict.lookupOrDefault("timeOut", 100*waitInterval_); timeOut_ = dict.lookupOrDefault("timeOut", 100*waitInterval_);
calcFrequency_ = dict.lookupOrDefault("calcFrequency", 1);
initByExternal_ = readBool(dict.lookup("initByExternal")); initByExternal_ = readBool(dict.lookup("initByExternal"));
// initByExternal_ = dict.lookupOrDefault<Switch>("initByExternal", false);
stateEnd_ =
stateEndNames_[dict.lookupOrDefault<word>("stateEnd", "remove")];
// Get names of all fvMeshes (and derived types) // Get names of all fvMeshes (and derived types)
wordList allRegionNames(time_.lookupClass<fvMesh>().sortedToc()); wordList allRegionNames(time_.lookupClass<fvMesh>().sortedToc());
const dictionary& allRegionsDict = dict.subDict("regions"); const dictionary& allRegionsDict = dict.subDict("regions");
forAllConstIter(dictionary, allRegionsDict, iter) forAllConstIter(dictionary, allRegionsDict, iter)
{ {
if (!iter().isDict()) if (!iter().isDict())

View File

@ -82,6 +82,7 @@ Usage
log yes; log yes;
commsDir "${FOAM_CASE}/comms"; commsDir "${FOAM_CASE}/comms";
initByExternal yes; initByExternal yes;
stateEnd remove; // (remove | done)
regions regions
{ {
@ -113,6 +114,7 @@ Usage
application. application.
SourceFiles SourceFiles
externalCoupled.C
externalCoupledTemplates.C externalCoupledTemplates.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -124,6 +126,7 @@ SourceFiles
#include "DynamicList.H" #include "DynamicList.H"
#include "wordReList.H" #include "wordReList.H"
#include "scalarField.H" #include "scalarField.H"
#include "NamedEnum.H"
#include "Switch.H" #include "Switch.H"
#include "UPtrList.H" #include "UPtrList.H"
@ -147,14 +150,29 @@ class externalCoupled
: :
public functionObject public functionObject
{ {
public:
// Public data types
//- Lockfile state on termination
enum stateEnd
{
REMOVE, //!< Remove lock file on end
DONE, //!< Lock file contains status=done on end
IGNORE //!< Internal use only (for handling cleanup).
};
private:
//- State end names
static const NamedEnum<stateEnd, 2> stateEndNames_;
// Private data // Private data
//- Reference to the time database //- Reference to the time database
const Time& time_; const Time& time_;
//- Switch for the execution - defaults to 'yes/on'
Switch enabled_;
//- Path to communications directory //- Path to communications directory
fileName commsDir_; fileName commsDir_;
@ -170,6 +188,9 @@ class externalCoupled
//- Flag to indicate values are initialised by external application //- Flag to indicate values are initialised by external application
bool initByExternal_; bool initByExternal_;
//- Lockfile state on termination
stateEnd stateEnd_;
//- Names of (composite) regions //- Names of (composite) regions
DynamicList<word> regionGroupNames_; DynamicList<word> regionGroupNames_;
@ -208,11 +229,15 @@ class externalCoupled
//- Return the file path to the lock file //- Return the file path to the lock file
fileName lockFile() const; fileName lockFile() const;
//- Create lock file
void createLockFile() const;
//- Remove lock file //- Create lock file to indicate that OpenFOAM is in charge
void removeLockFile() const; void useMaster() const;
//- Remove lock file to indicate that the external program is in charge
void useSlave() const;
//- Remove lock file or status=done in lock.
void cleanup() const;
//- Remove files written by OpenFOAM //- Remove files written by OpenFOAM
void removeWriteFiles() const; void removeWriteFiles() const;
@ -220,8 +245,9 @@ class externalCoupled
//- Remove files written by external code //- Remove files written by external code
void removeReadFiles() const; void removeReadFiles() const;
//- Wait for response from external source //- Wait for indication that the external program has supplied input
void wait() const; // (ie, for the lock file to reappear).
void waitForSlave() const;
//- Read data for a single region, single field //- Read data for a single region, single field
@ -290,10 +316,10 @@ public:
//- Runtime type information //- Runtime type information
TypeName("externalCoupled"); TypeName("externalCoupled");
//- Name of lock file //- Name of lock file (normally 'OpenFOAM.lock')
static word lockName; static word lockName;
//- Name of patch key, e.g. '# Patch:' when looking for start of patch data //- Name of patch key, e.g. '// Patch:' when looking for start of patch data
static string patchKey; static string patchKey;
@ -335,7 +361,7 @@ public:
// separated by '_' // separated by '_'
static word compositeName(const wordList&); static word compositeName(const wordList&);
//- Write geometry for the group/patch //- Write geometry for the group as region/patch
static void writeGeometry static void writeGeometry
( (
const UPtrList<const fvMesh>& meshes, const UPtrList<const fvMesh>& meshes,

View File

@ -81,8 +81,6 @@ bool Foam::functionObjects::externalCoupled::readData
label nFound = 0; label nFound = 0;
forAll(meshes, i) forAll(meshes, i)
{ {
const fvMesh& mesh = meshes[i]; const fvMesh& mesh = meshes[i];

View File

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

View File

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

View File

@ -10,7 +10,6 @@ FoamFile
version 2.0; version 2.0;
format ascii; format ascii;
class dictionary; class dictionary;
location "constant/bottomWater";
object thermophysicalProperties; object thermophysicalProperties;
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

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

View File

@ -14,158 +14,154 @@ FoamFile
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dictionaryReplacement U
{ {
U internalField uniform (0.001 0 0);
boundaryField
{ {
internalField uniform (0.001 0 0); minX
boundaryField
{ {
minX type fixedValue;
{ value uniform (0.001 0 0);
type fixedValue; }
value uniform (0.001 0 0);
}
maxX maxX
{ {
type inletOutlet; type inletOutlet;
inletValue uniform (0 0 0); inletValue uniform (0 0 0);
} }
".*" ".*"
{ {
type fixedValue; type fixedValue;
value uniform (0 0 0); value uniform (0 0 0);
}
} }
} }
}
T T
{
internalField uniform 300;
boundaryField
{ {
internalField uniform 300; minX
boundaryField
{ {
minX type fixedValue;
{ value uniform 300;
type fixedValue; }
value uniform 300;
}
maxX maxX
{ {
type inletOutlet; type inletOutlet;
inletValue uniform 300; inletValue uniform 300;
} }
".*" ".*"
{ {
type zeroGradient; type zeroGradient;
value uniform 300; value uniform 300;
} }
"bottomWater_to_.*" "bottomWater_to_.*"
{ {
type compressible::turbulentTemperatureCoupledBaffleMixed; type compressible::turbulentTemperatureCoupledBaffleMixed;
Tnbr T; Tnbr T;
kappaMethod fluidThermo; kappaMethod fluidThermo;
kappa none; value uniform 300;
value uniform 300;
}
} }
} }
}
epsilon epsilon
{
internalField uniform 0.01;
boundaryField
{ {
internalField uniform 0.01; minX
boundaryField
{ {
minX type fixedValue;
{ value uniform 0.01;
type fixedValue; }
value uniform 0.01;
}
maxX maxX
{ {
type inletOutlet; type inletOutlet;
inletValue uniform 0.01; inletValue uniform 0.01;
} }
".*" ".*"
{ {
type epsilonWallFunction; type epsilonWallFunction;
value uniform 0.01; value uniform 0.01;
}
} }
} }
}
k k
{
internalField uniform 0.1;
boundaryField
{ {
internalField uniform 0.1; minX
boundaryField
{ {
minX type inletOutlet;
{ inletValue uniform 0.1;
type inletOutlet; }
inletValue uniform 0.1;
}
maxX maxX
{ {
type zeroGradient; type zeroGradient;
value uniform 0.1; value uniform 0.1;
} }
".*" ".*"
{ {
type kqRWallFunction; type kqRWallFunction;
value uniform 0.1; value uniform 0.1;
}
} }
} }
}
p_rgh p_rgh
{
internalField uniform 0;
boundaryField
{ {
internalField uniform 0; minX
boundaryField
{ {
minX type zeroGradient;
{ value uniform 0;
type zeroGradient; }
value uniform 0;
}
maxX maxX
{ {
type fixedValue; type fixedValue;
value uniform 0; value uniform 0;
} }
".*" ".*"
{ {
type fixedFluxPressure; type fixedFluxPressure;
value uniform 0; value uniform 0;
}
} }
} }
}
p p
{
internalField uniform 0;
boundaryField
{ {
internalField uniform 0; ".*"
boundaryField
{ {
".*" type calculated;
{ value uniform 0;
type calculated;
value uniform 0;
}
} }
} }
} }

View File

@ -16,7 +16,7 @@ FoamFile
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Library defines new boundary conditions // Library defines new boundary conditions
libs ("libOpenFOAM.so" "libjobControl.so"); libs ("libOpenFOAM.so" "libfieldFunctionObjects.so");
application chtMultiRegionFoam; application chtMultiRegionFoam;
@ -26,11 +26,12 @@ startTime 0;
stopAt endTime; stopAt endTime;
endTime 1; endTime 0.5;
deltaT 0.001; deltaT 0.001;
writeControl adjustableRunTime; writeControl adjustableRunTime;
writeInterval 0.1; writeInterval 0.1;
purgeWrite 0; purgeWrite 0;
@ -56,40 +57,7 @@ adjustTimeStep yes;
functions functions
{ {
externalCoupled #include "externalCoupled"
{
// Where to load it from (if not already in solver)
libs ("libfieldFunctionObjects.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);
}
}
}
}
} }

View File

@ -0,0 +1,43 @@
// -*- C++ -*-
// control for external coupled simulation
externalCoupled
{
// Where to load it from (if not already in solver)
libs ("libfieldFunctionObjects.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);
}
}
}
}
// ************************************************************************* //

View File

@ -14,62 +14,56 @@ FoamFile
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dictionaryReplacement boundary
{ {
boundary minY
{ {
type patch;
inGroups (coupleGroup);
}
minZ
{
type patch;
}
maxZ
{
type patch;
}
}
T
{
internalField uniform 300;
boundaryField
{
".*"
{
type zeroGradient;
value uniform 300;
}
"heater_to_.*"
{
type compressible::turbulentTemperatureCoupledBaffleMixed;
Tnbr T;
kappaMethod solidThermo;
value uniform 300;
}
heater_to_leftSolid
{
type compressible::turbulentTemperatureCoupledBaffleMixed;
Tnbr T;
kappaMethod solidThermo;
thicknessLayers (1e-3);
kappaLayers (5e-4);
value uniform 300;
}
minY minY
{ {
type patch; type fixedValue;
inGroups (coupleGroup); value uniform 500;
}
minZ
{
type patch;
}
maxZ
{
type patch;
}
}
T
{
internalField uniform 300;
boundaryField
{
".*"
{
type zeroGradient;
value uniform 300;
}
"heater_to_.*"
{
type compressible::turbulentTemperatureCoupledBaffleMixed;
Tnbr T;
kappaMethod solidThermo;
kappa none;
value uniform 300;
}
heater_to_leftSolid
{
type compressible::turbulentTemperatureCoupledBaffleMixed;
Tnbr T;
kappaMethod solidThermo;
kappa none;
thicknessLayers (1e-3);
kappaLayers (5e-4);
value uniform 300;
}
minY
{
type fixedValue;
value uniform 500;
}
} }
} }
} }

View File

@ -14,50 +14,45 @@ FoamFile
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dictionaryReplacement boundary
{ {
boundary minZ
{ {
minZ type patch;
{
type patch;
}
maxZ
{
type patch;
}
} }
maxZ
T
{ {
internalField uniform 300; type patch;
}
}
boundaryField T
{
internalField uniform 300;
boundaryField
{
".*"
{ {
".*" type zeroGradient;
{ value uniform 300;
type zeroGradient; }
value uniform 300; "leftSolid_to_.*"
} {
"leftSolid_to_.*" type compressible::turbulentTemperatureCoupledBaffleMixed;
{ Tnbr T;
type compressible::turbulentTemperatureCoupledBaffleMixed; kappaMethod solidThermo;
Tnbr T; value uniform 300;
kappaMethod solidThermo; }
kappa none;
value uniform 300;
}
leftSolid_to_heater leftSolid_to_heater
{ {
type compressible::turbulentTemperatureCoupledBaffleMixed; type compressible::turbulentTemperatureCoupledBaffleMixed;
Tnbr T; Tnbr T;
kappaMethod solidThermo; kappaMethod solidThermo;
kappa none; thicknessLayers (1e-3);
thicknessLayers (1e-3); kappaLayers (5e-4);
kappaLayers (5e-4); value uniform 300;
value uniform 300;
}
} }
} }
} }

View File

@ -14,39 +14,35 @@ FoamFile
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dictionaryReplacement boundary
{ {
boundary minZ
{ {
minZ type patch;
{
type patch;
}
maxZ
{
type patch;
}
} }
maxZ
T
{ {
internalField uniform 300; type patch;
}
}
boundaryField T
{
internalField uniform 300;
boundaryField
{
".*"
{ {
".*" type zeroGradient;
{ value uniform 300;
type zeroGradient; }
value uniform 300; "rightSolid_to_.*"
} {
"rightSolid_to_.*" type compressible::turbulentTemperatureCoupledBaffleMixed;
{ Tnbr T;
type compressible::turbulentTemperatureCoupledBaffleMixed; kappaMethod solidThermo;
Tnbr T; value uniform 300;
kappaMethod solidThermo;
kappa none;
value uniform 300;
}
} }
} }
} }

View File

@ -14,164 +14,160 @@ FoamFile
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dictionaryReplacement boundary
{ {
boundary minX
{ {
inGroups (coupleGroup);
}
}
U
{
internalField uniform (0.1 0 0);
boundaryField
{
".*"
{
type fixedValue;
value uniform (0 0 0);
}
minX minX
{ {
inGroups (coupleGroup); type fixedValue;
value uniform ( 0.1 0 0 );
}
maxX
{
type inletOutlet;
inletValue uniform ( 0 0 0 );
value uniform ( 0.1 0 0 );
} }
} }
}
U T
{
internalField uniform 300;
boundaryField
{ {
internalField uniform (0.1 0 0); ".*"
boundaryField
{ {
".*" type zeroGradient;
{ }
type fixedValue;
value uniform (0 0 0); minX
} {
minX type fixedValue;
{ value uniform 300;
type fixedValue; }
value uniform ( 0.1 0 0 ); maxX
} {
maxX type inletOutlet;
{ inletValue uniform 300;
type inletOutlet; value uniform 300;
inletValue uniform ( 0 0 0 ); }
value uniform ( 0.1 0 0 );
} "topAir_to_.*"
{
type compressible::turbulentTemperatureCoupledBaffleMixed;
Tnbr T;
kappaMethod fluidThermo;
value uniform 300;
} }
} }
}
T epsilon
{
internalField uniform 0.01;
boundaryField
{ {
internalField uniform 300; ".*"
boundaryField
{ {
".*" type epsilonWallFunction;
{ value uniform 0.01;
type zeroGradient; }
}
minX minX
{ {
type fixedValue; type fixedValue;
value uniform 300; value uniform 0.01;
} }
maxX maxX
{ {
type inletOutlet; type inletOutlet;
inletValue uniform 300; inletValue uniform 0.01;
value uniform 300; value uniform 0.01;
}
"topAir_to_.*"
{
type compressible::turbulentTemperatureCoupledBaffleMixed;
Tnbr T;
kappaMethod fluidThermo;
kappa none;
value uniform 300;
}
} }
} }
}
epsilon k
{
internalField uniform 0.1;
boundaryField
{ {
internalField uniform 0.01; ".*"
boundaryField
{ {
".*" type kqRWallFunction;
{ value uniform 0.1;
type epsilonWallFunction; }
value uniform 0.01;
}
minX minX
{ {
type fixedValue; type fixedValue;
value uniform 0.01; value uniform 0.1;
} }
maxX maxX
{ {
type inletOutlet; type inletOutlet;
inletValue uniform 0.01; inletValue uniform 0.1;
value uniform 0.01; value uniform 0.1;
}
} }
} }
}
k p_rgh
{
internalField uniform 1e5;
boundaryField
{ {
internalField uniform 0.1; ".*"
boundaryField
{ {
".*" type fixedFluxPressure;
{ value uniform 1e5;
type kqRWallFunction; }
value uniform 0.1;
}
minX maxX
{ {
type fixedValue; type fixedValue;
value uniform 0.1; value uniform 1e5;
}
maxX
{
type inletOutlet;
inletValue uniform 0.1;
value uniform 0.1;
}
} }
} }
}
p_rgh p
{
internalField uniform 1e5;
boundaryField
{ {
internalField uniform 1e5; ".*"
boundaryField
{ {
".*" type calculated;
{ value uniform 1e5;
type fixedFluxPressure;
value uniform 1e5;
}
maxX
{
type fixedValue;
value uniform 1e5;
}
} }
}
p maxX
{
internalField uniform 1e5;
boundaryField
{ {
".*" type calculated;
{ value uniform 1e5;
type calculated;
value uniform 1e5;
}
maxX
{
type calculated;
value uniform 1e5;
}
} }
} }
} }

View File

@ -10,7 +10,6 @@ FoamFile
version 2.0; version 2.0;
format ascii; format ascii;
class dictionary; class dictionary;
location "constant/bottomAir";
object thermophysicalProperties; object thermophysicalProperties;
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -1,74 +0,0 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: plus |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "0/bottomWater";
object T;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 0 0 1 0 0 0];
internalField uniform 300;
boundaryField
{
minX
{
type fixedValue;
value uniform 300;
}
maxX
{
type inletOutlet;
value uniform 300;
inletValue uniform 300;
}
minY
{
type zeroGradient;
value uniform 300;
}
minZ
{
type zeroGradient;
value uniform 300;
}
maxZ
{
type zeroGradient;
value uniform 300;
}
bottomWater_to_rightSolid
{
type compressible::turbulentTemperatureCoupledBaffleMixed;
value uniform 300;
Tnbr T;
kappaMethod fluidthermo;
}
bottomWater_to_leftSolid
{
type compressible::turbulentTemperatureCoupledBaffleMixed;
value uniform 300;
Tnbr T;
kappaMethod fluidthermo;
}
bottomWater_to_heater
{
type compressible::turbulentTemperatureCoupledBaffleMixed;
value uniform 300;
Tnbr T;
kappaMethod fluidthermo;
}
}
// ************************************************************************* //

View File

@ -1,62 +0,0 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: plus |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volVectorField;
location "0/bottomWater";
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 1 -1 0 0 0 0];
internalField uniform (0.001 0 0);
boundaryField
{
minX
{
type fixedValue;
value uniform (0.001 0 0);
}
maxX
{
type inletOutlet;
value uniform (0.01 0 0);
inletValue uniform (0 0 0);
}
minY
{
type noSlip;
}
minZ
{
type noSlip;
}
maxZ
{
type noSlip;
}
bottomWater_to_rightSolid
{
type noSlip;
}
bottomWater_to_leftSolid
{
type noSlip;
}
bottomWater_to_heater
{
type noSlip;
}
}
// ************************************************************************* //

View File

@ -1,68 +0,0 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: plus |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "0/bottomWater";
object epsilon;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 2 -3 0 0 0 0];
internalField uniform 0.01;
boundaryField
{
minX
{
type fixedValue;
value uniform 0.01;
}
maxX
{
type inletOutlet;
value uniform 0.01;
inletValue uniform 0.01;
}
minY
{
type epsilonWallFunction;
value uniform 0.01;
}
minZ
{
type epsilonWallFunction;
value uniform 0.01;
}
maxZ
{
type epsilonWallFunction;
value uniform 0.01;
}
bottomWater_to_rightSolid
{
type epsilonWallFunction;
value uniform 0.01;
}
bottomWater_to_leftSolid
{
type epsilonWallFunction;
value uniform 0.01;
}
bottomWater_to_heater
{
type epsilonWallFunction;
value uniform 0.01;
}
}
// ************************************************************************* //

View File

@ -1,68 +0,0 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: plus |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "0/bottomWater";
object k;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 2 -2 0 0 0 0];
internalField uniform 0.1;
boundaryField
{
minX
{
type inletOutlet;
value uniform 0.1;
inletValue uniform 0.1;
}
maxX
{
type zeroGradient;
value uniform 0.1;
}
minY
{
type kqRWallFunction;
value uniform 0.1;
}
minZ
{
type kqRWallFunction;
value uniform 0.1;
}
maxZ
{
type kqRWallFunction;
value uniform 0.1;
}
bottomWater_to_rightSolid
{
type kqRWallFunction;
value uniform 0.1;
}
bottomWater_to_leftSolid
{
type kqRWallFunction;
value uniform 0.1;
}
bottomWater_to_heater
{
type kqRWallFunction;
value uniform 0.1;
}
}
// ************************************************************************* //

View File

@ -1,67 +0,0 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: plus |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "0/bottomWater";
object p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [1 -1 -2 0 0 0 0];
internalField uniform 0;
boundaryField
{
minX
{
type calculated;
value uniform 0;
}
maxX
{
type calculated;
value uniform 0;
}
minY
{
type calculated;
value uniform 0;
}
minZ
{
type calculated;
value uniform 0;
}
maxZ
{
type calculated;
value uniform 0;
}
bottomWater_to_rightSolid
{
type calculated;
value uniform 0;
}
bottomWater_to_leftSolid
{
type calculated;
value uniform 0;
}
bottomWater_to_heater
{
type calculated;
value uniform 0;
}
}
// ************************************************************************* //

View File

@ -1,67 +0,0 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: plus |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "0/bottomWater";
object p_rgh;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [1 -1 -2 0 0 0 0];
internalField uniform 0;
boundaryField
{
minX
{
type zeroGradient;
value uniform 0;
}
maxX
{
type fixedValue;
value uniform 0;
}
minY
{
type fixedFluxPressure;
value uniform 0;
}
minZ
{
type fixedFluxPressure;
value uniform 0;
}
maxZ
{
type fixedFluxPressure;
value uniform 0;
}
bottomWater_to_rightSolid
{
type fixedFluxPressure;
value uniform 0;
}
bottomWater_to_leftSolid
{
type fixedFluxPressure;
value uniform 0;
}
bottomWater_to_heater
{
type fixedFluxPressure;
value uniform 0;
}
}
// ************************************************************************* //

View File

@ -7,12 +7,12 @@ cd ${0%/*} || exit 1 # Run from this directory
cleanCase cleanCase
rm -rf VTK rm -rf VTK
rm -rf constant/cellToRegion constant/polyMesh/sets rm -rf constant/cellToRegion constant/polyMesh/sets
rm -rf 0/bottomAir rm -f 0/cellToRegion
rm -rf 0/bottomWater
rm -rf 0/topAir rm -rf 0/topAir
rm -rf 0/heater rm -rf 0/heater
rm -rf 0/leftSolid rm -rf 0/leftSolid
rm -rf 0/rightSolid rm -rf 0/rightSolid
rm -f 0/cellToRegion
rm -rf constant/bottomWater/polyMesh rm -rf constant/bottomWater/polyMesh
rm -rf constant/topAir/polyMesh rm -rf constant/topAir/polyMesh
rm -rf constant/heater/polyMesh rm -rf constant/heater/polyMesh

View File

@ -10,7 +10,6 @@ FoamFile
version 2.0; version 2.0;
format ascii; format ascii;
class dictionary; class dictionary;
location "constant/bottomAir";
object thermophysicalProperties; object thermophysicalProperties;
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -10,7 +10,6 @@ FoamFile
version 2.0; version 2.0;
format ascii; format ascii;
class dictionary; class dictionary;
location "constant/bottomAir";
object thermophysicalProperties; object thermophysicalProperties;
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //