This functionObject provides a simple interface for explicit coupling with an external application. The coupling is through plain text files where OpenFOAM boundary data is read/written as one line per face (data from all processors collated): More...
Public Member Functions | |
TypeName ("externalCoupled") | |
Runtime type information. More... | |
externalCoupledFunctionObject (const word &name, const Time &runTime, const dictionary &dict) | |
Construct given time and dictionary. More... | |
virtual | ~externalCoupledFunctionObject () |
Destructor. More... | |
virtual bool | enabled () const |
Return the enabled flag. More... | |
virtual void | on () |
Switch the function object on. More... | |
virtual void | off () |
Switch the function object off. More... | |
virtual bool | start () |
Called at the start of the time-loop. More... | |
virtual bool | execute (const bool forceWrite) |
Called at each ++ or += of the time-loop. More... | |
virtual bool | end () |
Called when Time::run() determines that the time-loop exits. More... | |
virtual bool | timeSet () |
Called when time was set at the end of the Time::operator++. More... | |
virtual bool | adjustTimeStep () |
Called at the end of Time::adjustDeltaT() if adjustTime is true. More... | |
virtual bool | read (const dictionary &) |
Read and set the function object if its data have changed. More... | |
virtual void | updateMesh (const mapPolyMesh &mpm) |
Update for changes of mesh. More... | |
virtual void | movePoints (const polyMesh &mesh) |
Update for changes of mesh. More... | |
template<class Type > | |
Foam::tmp< Foam::Field< Type > > | gatherAndCombine (const Field< Type > &fld) |
![]() | |
virtual const word & | type () const =0 |
Runtime type information. More... | |
declareRunTimeSelectionTable (autoPtr, functionObject, dictionary,(const word &name, const Time &t, const dictionary &dict),(name, t, dict)) | |
functionObject (const word &name) | |
Construct from components. More... | |
autoPtr< functionObject > | clone () const |
Return clone. More... | |
virtual | ~functionObject () |
Destructor. More... | |
virtual const word & | name () const |
Name. More... | |
Static Public Member Functions | |
static word | compositeName (const wordList &) |
Create single name by appending words (in sorted order),. More... | |
static void | writeGeometry (const UPtrList< const fvMesh > &meshes, const fileName &commsDir, const wordRe &groupName) |
Write geometry for the group/patch. More... | |
![]() | |
static autoPtr< functionObject > | New (const word &name, const Time &, const dictionary &) |
Select from dictionary, based on its "type" entry. More... | |
Static Public Attributes | |
static word | lockName = "OpenFOAM" |
Name of lock file. More... | |
static string | patchKey = "# Patch: " |
Name of patch key, e.g. '# Patch:' when looking for start of patch data. More... | |
![]() | |
static int | debug |
Private Member Functions | |
fileName | baseDir () const |
Return the file path to the base communications directory. More... | |
fileName | lockFile () const |
Return the file path to the lock file. More... | |
void | createLockFile () const |
Create lock file. More... | |
void | removeLockFile () const |
Remove lock file. More... | |
void | removeWriteFiles () const |
Remove files written by OpenFOAM. More... | |
void | removeReadFiles () const |
Remove files written by external code. More... | |
void | wait () const |
Wait for response from external source. More... | |
template<class Type > | |
bool | readData (const UPtrList< const fvMesh > &meshes, const wordRe &groupName, const word &fieldName) |
Read data for a single region, single field. More... | |
void | readData () |
Read data for all regions, all fields. More... | |
template<class Type > | |
bool | writeData (const UPtrList< const fvMesh > &meshes, const wordRe &groupName, const word &fieldName) const |
Write data for a single region, single field. More... | |
void | writeData () const |
Write data for all regions, all fields. More... | |
void | initialise () |
void | readColumns (const label nRows, const label nColumns, autoPtr< IFstream > &masterFilePtr, List< scalarField > &data) const |
Read (and distribute) scalar columns from stream. Every processor. More... | |
void | readLines (const label nRows, autoPtr< IFstream > &masterFilePtr, OStringStream &data) const |
Read (and distribute) lines from stream. Every processor. More... | |
externalCoupledFunctionObject (const externalCoupledFunctionObject &) | |
Disallow default bitwise copy construc. More... | |
void | operator= (const externalCoupledFunctionObject &) |
Disallow default bitwise assignmen. More... | |
Static Private Member Functions | |
static fileName | groupDir (const fileName &commsDir, const word ®ionsName, const wordRe &groupName) |
Return the file path to the communications directory for the region. More... | |
template<class Type > | |
static tmp< Field< Type > > | gatherAndCombine (const Field< Type > &fld) |
Helper: append data from all processors onto master. More... | |
static void | checkOrder (const wordList &) |
Private Attributes | |
const Time & | time_ |
Reference to the time database. More... | |
Switch | enabled_ |
Switch for the execution - defaults to 'yes/on'. More... | |
fileName | commsDir_ |
Path to communications directory. More... | |
label | waitInterval_ |
Interval time between checking for return data [s]. More... | |
label | timeOut_ |
Time out time [s]. More... | |
label | calcFrequency_ |
Calculation frequency. More... | |
bool | initByExternal_ |
Flag to indicate values are initialised by external application. More... | |
bool | log_ |
Log flag. More... | |
DynamicList< word > | regionGroupNames_ |
Names of (composite) regions. More... | |
DynamicList< wordList > | regionGroupRegions_ |
HashTable< labelList > | regionToGroups_ |
DynamicList< wordRe > | groupNames_ |
DynamicList< wordList > | groupReadFields_ |
DynamicList< wordList > | groupWriteFields_ |
bool | initialised_ |
Initialised flag. More... | |
This functionObject provides a simple interface for explicit coupling with an external application. The coupling is through plain text files where OpenFOAM boundary data is read/written as one line per face (data from all processors collated):
# Patch: <patch name> <fld1> <fld2> .. <fldn> //face0 <fld1> <fld2> .. <fldn> //face1 .. <fld1> <fld2> .. <fldn> //faceN
where the actual entries depend on the bc type:
These text files are located in a user specified communications directory which gets read/written on the master processor only. In the communications directory the structure will be
<regionsName>/<patchGroup>/<fieldName>.[in|out]
(where regionsName is either the name of a single region or a composite of multiple region names)
At start-up, the boundary creates a lock file, i.e..
OpenFOAM.lock
... to signal the external source to wait. During the functionObject execution the boundary values are written to files (one per region, per patch(group), per field), e.g.
<regionsName>/<patchGroup>/<fieldName>.out
The lock file is then removed, instructing the external source to take control of the program execution. When ready, the external program should create the return values, e.g. to files
<regionsName>/<patchGroup>/<fieldName>.in
... and then re-instate the lock file. The functionObject will then read these values, apply them to the boundary conditions and pass program execution back to OpenFOAM.
Example of function object specification:
externalCoupled { type externalCoupled; ... log yes; commsDir "${FOAM_CASE}/comms"; initByExternal yes; regions { "(region1|region0)" // Name of region(s) { TPatchGroup // Name of patch(group) { readFields (p); // List of fields to read writeFields (T); // List of fields to write } } } }
This reads/writes (on the master processor) the directory: comms/region0_region1/TPatchGroup/ with contents: patchPoints (collected points) patchFaces (collected faces) p.in (input file of p, written by external application) T.out (output file of T, written by OpenFOAM)
The patchPoints/patchFaces files denote the (collated) geometry which will be written if it does not exist yet or can be written as a preprocessing step using the createExternalCoupledPatchGeometry application.
Definition at line 143 of file externalCoupledFunctionObject.H.
|
private |
Disallow default bitwise copy construc.
externalCoupledFunctionObject | ( | const word & | name, |
const Time & | runTime, | ||
const dictionary & | dict | ||
) |
Construct given time and dictionary.
Definition at line 784 of file externalCoupledFunctionObject.C.
References dict, UPstream::master(), Foam::mkDir(), and Foam::read().
|
virtual |
Destructor.
Definition at line 811 of file externalCoupledFunctionObject.C.
|
staticprivate |
Return the file path to the communications directory for the region.
Definition at line 67 of file externalCoupledFunctionObject.C.
References fileName::clean().
|
private |
Return the file path to the base communications directory.
Definition at line 57 of file externalCoupledFunctionObject.C.
References fileName::clean(), and externalCoupledFunctionObject::commsDir_.
|
private |
Return the file path to the lock file.
Definition at line 85 of file externalCoupledFunctionObject.C.
|
private |
Create lock file.
Definition at line 91 of file externalCoupledFunctionObject.C.
References Foam::endl(), OSstream::flush(), IOstream::good(), Foam::Info, UPstream::master(), and Foam::type().
|
private |
Remove lock file.
Definition at line 113 of file externalCoupledFunctionObject.C.
References Foam::endl(), Foam::Info, UPstream::master(), Foam::rm(), and Foam::type().
|
private |
Remove files written by OpenFOAM.
Definition at line 159 of file externalCoupledFunctionObject.C.
References Foam::endl(), forAll, Foam::Info, UPstream::master(), Foam::rm(), and Foam::type().
|
private |
Remove files written by external code.
Definition at line 126 of file externalCoupledFunctionObject.C.
References Foam::endl(), forAll, Foam::Info, UPstream::master(), Foam::rm(), and Foam::type().
|
private |
Wait for response from external source.
Definition at line 192 of file externalCoupledFunctionObject.C.
References Foam::abort(), Foam::endl(), Foam::FatalError, FatalErrorInFunction, found, IOstream::good(), Foam::Info, UPstream::master(), Foam::nl, Foam::reduce(), Foam::sleep(), and Foam::type().
|
private |
Read data for a single region, single field.
Definition at line 42 of file externalCoupledFunctionObjectTemplates.C.
References Foam::endl(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, Foam::FatalIOError, FatalIOErrorInFunction, forAll, fixedGradientFvPatchField< Type >::gradient(), Foam::Info, Foam::isA(), mesh, mixedFvPatchField< Type >::refGrad(), mixedFvPatchField< Type >::refValue(), Field::replace(), autoPtr::reset(), UPtrList::size(), OStringStream::str(), Foam::type(), and mixedFvPatchField< Type >::valueFraction().
|
private |
Read data for all regions, all fields.
Definition at line 583 of file externalCoupledFunctionObject.C.
References Foam::endl(), Foam::fieldNames(), forAll, regionName, UPtrList::set(), List::size(), and WarningInFunction.
|
private |
Write data for a single region, single field.
Definition at line 342 of file externalCoupledFunctionObjectTemplates.C.
References Foam::endl(), Foam::exit(), Foam::FatalIOError, FatalIOErrorInFunction, forAll, Foam::Info, Foam::isA(), mesh, Foam::nl, mixedFvPatchField< Type >::refGrad(), mixedFvPatchField< Type >::refValue(), autoPtr::reset(), UPtrList::size(), Foam::fvc::snGrad(), mixedFvPatchField< Type >::snGrad(), OStringStream::str(), Foam::type(), and mixedFvPatchField< Type >::valueFraction().
|
private |
Write data for all regions, all fields.
Definition at line 653 of file externalCoupledFunctionObject.C.
References Foam::endl(), Foam::fieldNames(), forAll, regionName, UPtrList::set(), List::size(), and WarningInFunction.
|
private |
Definition at line 723 of file externalCoupledFunctionObject.C.
References Foam::exists(), forAll, Foam::isFile(), UPstream::master(), regionName, Foam::returnReduce(), UPtrList::set(), and List::size().
|
private |
Read (and distribute) scalar columns from stream. Every processor.
gets nRows (= patch size) of these. Note: could make its argument ISstream& but then would need additional logic to construct valid stream on all processors.
Definition at line 241 of file externalCoupledFunctionObject.C.
References Foam::exit(), Foam::FatalIOError, FatalIOErrorInFunction, PstreamBuffers::finishedSends(), forAll, globalIndex::localSize(), UPstream::master(), UPstream::masterNo(), UPstream::nonBlocking, UPstream::nProcs(), List::setSize(), and globalIndex::size().
|
private |
Read (and distribute) lines from stream. Every processor.
gets nRows (= patch size) of these. Data kept as stream (instead of strings) for ease of interfacing to readData routines that take an Istream.
Definition at line 311 of file externalCoupledFunctionObject.C.
References Foam::exit(), Foam::FatalIOError, FatalIOErrorInFunction, PstreamBuffers::finishedSends(), globalIndex::localSize(), UPstream::master(), UPstream::masterNo(), Foam::nl, UPstream::nonBlocking, UPstream::nProcs(), and globalIndex::size().
Helper: append data from all processors onto master.
|
staticprivate |
Definition at line 568 of file externalCoupledFunctionObject.C.
References Foam::exit(), Foam::FatalError, FatalErrorInFunction, Foam::identity(), List::size(), and Foam::sortedOrder().
|
private |
Disallow default bitwise assignmen.
TypeName | ( | "externalCoupled" | ) |
Runtime type information.
|
inlinevirtual |
Return the enabled flag.
Definition at line 320 of file externalCoupledFunctionObject.H.
References externalCoupledFunctionObject::enabled_.
|
virtual |
Switch the function object on.
Definition at line 817 of file externalCoupledFunctionObject.C.
|
virtual |
Switch the function object off.
Definition at line 823 of file externalCoupledFunctionObject.C.
|
virtual |
Called at the start of the time-loop.
Implements functionObject.
Definition at line 829 of file externalCoupledFunctionObject.C.
|
virtual |
Called at each ++ or += of the time-loop.
Implements functionObject.
Definition at line 835 of file externalCoupledFunctionObject.C.
References writeData().
|
virtual |
Called when Time::run() determines that the time-loop exits.
Reimplemented from functionObject.
Definition at line 873 of file externalCoupledFunctionObject.C.
|
virtual |
Called when time was set at the end of the Time::operator++.
Reimplemented from functionObject.
Definition at line 887 of file externalCoupledFunctionObject.C.
|
virtual |
Called at the end of Time::adjustDeltaT() if adjustTime is true.
Reimplemented from functionObject.
Definition at line 894 of file externalCoupledFunctionObject.C.
|
virtual |
Read and set the function object if its data have changed.
Implements functionObject.
Definition at line 900 of file externalCoupledFunctionObject.C.
References Foam::decrIndent(), dict, Foam::endl(), Foam::exit(), Foam::FatalIOError, FatalIOErrorInFunction, Foam::findStrings(), forAll, forAllConstIter(), Foam::incrIndent(), Foam::indent(), Foam::Info, Foam::isDir(), dictionary::lookup(), dictionary::lookupOrDefault(), UPstream::master(), Foam::mkDir(), Foam::readBool(), Foam::readFields(), dictionary::readIfPresent(), HashTable::sortedToc(), dictionary::subDict(), and Foam::type().
|
virtual |
Update for changes of mesh.
Implements functionObject.
Definition at line 1049 of file externalCoupledFunctionObject.C.
|
virtual |
Update for changes of mesh.
Implements functionObject.
Definition at line 1053 of file externalCoupledFunctionObject.C.
|
static |
Create single name by appending words (in sorted order),.
separated by '_'
Definition at line 528 of file externalCoupledFunctionObject.C.
References Foam::abort(), polyMesh::defaultRegion, Foam::FatalError, FatalErrorInFunction, word::null, and List::size().
|
static |
Write geometry for the group/patch.
Definition at line 373 of file externalCoupledFunctionObject.C.
References DynamicList::append(), DynamicField::append(), polyMesh::boundaryMesh(), Foam::endl(), f(), polyMesh::faces(), forAll, Pstream::gatherList(), polyMesh::globalData(), Foam::Info, Foam::inplaceRenumber(), PrimitivePatch< Face, FaceList, PointField, PointType >::localFaces(), UPstream::master(), globalMeshData::mergePoints(), mesh, PrimitivePatch< Face, FaceList, PointField, PointType >::meshPointMap(), PrimitivePatch< Face, FaceList, PointField, PointType >::meshPoints(), Foam::mkDir(), UPstream::myProcNo(), fvMesh::name(), nPoints, UPstream::nProcs(), p, patchFaces(), polyBoundaryMesh::patchSet(), polyMesh::points(), autoPtr::reset(), List::setSize(), List::size(), UPtrList::size(), PtrList::size(), HashTable::sortedToc(), and autoPtr::valid().
Foam::tmp<Foam::Field<Type> > gatherAndCombine | ( | const Field< Type > & | fld | ) |
Definition at line 298 of file externalCoupledFunctionObjectTemplates.C.
References fld(), forAll, and List::size().
|
private |
Reference to the time database.
Definition at line 150 of file externalCoupledFunctionObject.H.
|
private |
Switch for the execution - defaults to 'yes/on'.
Definition at line 153 of file externalCoupledFunctionObject.H.
Referenced by externalCoupledFunctionObject::enabled().
|
private |
Path to communications directory.
Definition at line 156 of file externalCoupledFunctionObject.H.
Referenced by externalCoupledFunctionObject::baseDir().
|
private |
Interval time between checking for return data [s].
Definition at line 159 of file externalCoupledFunctionObject.H.
|
private |
Time out time [s].
Definition at line 162 of file externalCoupledFunctionObject.H.
|
private |
Calculation frequency.
Definition at line 165 of file externalCoupledFunctionObject.H.
|
private |
Flag to indicate values are initialised by external application.
Definition at line 168 of file externalCoupledFunctionObject.H.
|
private |
Log flag.
Definition at line 171 of file externalCoupledFunctionObject.H.
|
private |
Names of (composite) regions.
Definition at line 174 of file externalCoupledFunctionObject.H.
|
private |
Definition at line 177 of file externalCoupledFunctionObject.H.
Definition at line 180 of file externalCoupledFunctionObject.H.
|
private |
Definition at line 183 of file externalCoupledFunctionObject.H.
|
private |
Definition at line 186 of file externalCoupledFunctionObject.H.
|
private |
Definition at line 189 of file externalCoupledFunctionObject.H.
|
private |
Initialised flag.
Definition at line 192 of file externalCoupledFunctionObject.H.
|
static |
Name of lock file.
Definition at line 294 of file externalCoupledFunctionObject.H.
|
static |
Name of patch key, e.g. '# Patch:' when looking for start of patch data.
Definition at line 297 of file externalCoupledFunctionObject.H.
Copyright © 2011-2018 OpenFOAM | OPENFOAM® is a registered trademark of OpenCFD Ltd.