Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
externalCoupled Class Reference

Provides a simple file-based communication interface for explicit coupling with an external application, so that data is transferred to- and from OpenFOAM. The data exchange employs specialised boundary conditions to provide either one-way or two-way coupling models. More...

Inheritance diagram for externalCoupled:
Inheritance graph
[legend]
Collaboration diagram for externalCoupled:
Collaboration graph
[legend]

Public Member Functions

 TypeName ("externalCoupled")
 
 externalCoupled (const word &name, const Time &runTime, const dictionary &dict)
 
 externalCoupled (const externalCoupled &)=delete
 
void operator= (const externalCoupled &)=delete
 
virtual ~externalCoupled ()=default
 
virtual bool execute ()
 
virtual bool execute (const label subIndex)
 
virtual bool end ()
 
virtual bool read (const dictionary &dict)
 
virtual bool write ()
 
virtual void writeDataMaster () const
 
virtual void readDataMaster ()
 
virtual void removeDataMaster () const
 
virtual void removeDataSlave () const
 
template<class Type >
Foam::tmp< Foam::Field< Type > > gatherAndCombine (const Field< Type > &fld)
 
- Public Member Functions inherited from timeFunctionObject
 timeFunctionObject (const word &name, const Time &runTime)
 
virtual ~timeFunctionObject ()=default
 
const Timetime () const
 
objectRegistrystoredObjects ()
 
const objectRegistrystoredObjects () const
 
- Public Member Functions inherited from functionObject
 declareRunTimeSelectionTable (autoPtr, functionObject, dictionary,(const word &name, const Time &runTime, const dictionary &dict),(name, runTime, dict))
 
 functionObject (const word &name, const bool withNamePrefix=defaultUseNamePrefix)
 
autoPtr< functionObjectclone () const
 
virtual ~functionObject ()=default
 
virtual const wordtype () const =0
 
const wordname () const noexcept
 
bool useNamePrefix () const noexcept
 
bool useNamePrefix (bool on) noexcept
 
virtual bool adjustTimeStep ()
 
virtual bool filesModified () const
 
virtual void updateMesh (const mapPolyMesh &mpm)
 
virtual void movePoints (const polyMesh &mesh)
 
- Public Member Functions inherited from externalFileCoupler
 TypeName ("externalFileCoupler")
 
 externalFileCoupler ()
 
 externalFileCoupler (const fileName &commsDir)
 
 externalFileCoupler (const dictionary &dict)
 
virtual ~externalFileCoupler ()
 
bool initialized () const
 
bool slaveFirst () const
 
const fileNamecommDirectory () const
 
fileName resolveFile (const word &file) const
 
fileName lockFile () const
 
bool readDict (const dictionary &dict)
 
enum Time::stopAtControls useMaster (const bool wait=false) const
 
enum Time::stopAtControls useSlave (const bool wait=false) const
 
enum Time::stopAtControls waitForMaster () const
 
enum Time::stopAtControls waitForSlave () const
 
virtual void readDataSlave ()
 
virtual void writeDataSlave () const
 
void shutdown () const
 
void removeDirectory () const
 

Static Public Member Functions

static word compositeName (const wordList &)
 
static void writeGeometry (const UPtrList< const fvMesh > &meshes, const fileName &commsDir, const wordRe &groupName)
 
- Static Public Member Functions inherited from functionObject
static autoPtr< functionObjectNew (const word &name, const Time &runTime, const dictionary &dict)
 

Public Attributes

bool log
 
- Public Attributes inherited from functionObject
bool log
 

Static Public Attributes

static string patchKey = "// Patch:"
 
- Static Public Attributes inherited from functionObject
static int debug
 
static bool postProcess
 
static bool defaultUseNamePrefix
 
static word outputPrefix
 
- Static Public Attributes inherited from externalFileCoupler
static word lockName = "OpenFOAM"
 

Additional Inherited Members

- Public Types inherited from externalFileCoupler
enum  runState { NONE, MASTER, SLAVE, DONE }
 
- Protected Member Functions inherited from timeFunctionObject
void clearOutputObjects (const wordList &objNames)
 
 timeFunctionObject (const timeFunctionObject &)=delete
 
void operator= (const timeFunctionObject &)=delete
 
- Protected Member Functions inherited from functionObject
word scopedName (const word &name) const
 
- Protected Attributes inherited from timeFunctionObject
const Timetime_
 

Detailed Description

Provides a simple file-based communication interface for explicit coupling with an external application, so that data is transferred to- and from OpenFOAM. The data exchange employs specialised boundary conditions to provide either one-way or two-way coupling models.

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 boundary condition 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 function object 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 reinstate the lock file. The function object will then read these values, apply them to the boundary conditions and pass program execution back to OpenFOAM.

Usage
Minimal example by using system/controlDict.functions:
externalCoupled1
{
    // Mandatory entries (unmodifiable)
    type            externalCoupled;
    libs            (fieldFunctionObjects);
    commsDir        "<case>/comms";
    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
            }
        }
    }
    initByExternal  true;

    // Optional entries (runtime modifiable)
    waitInterval    1;
    timeOut         100;
    statusDone      done;  // Any arbitrary status=... value
    calcFrequency   1;

    // Optional (inherited) entries
    ...
}

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.

The entries comprise:

Property Description Type Req'd Dflt
type Type name: externalCoupled word yes -
libs Library name: fieldFunctionObjects word yes -
commsDir Communication directory word yes -
regions The regions to couple word yes -
initByExternal Initialization values supplied by external app bool yes -
waitInterval Wait interval in [s] label no 1
timeOut Timeout in [s] label no 100*waitInterval
statusDone Lockfile status=... on termination word no done
calcFrequency Calculation frequency label no 1

The inherited entries are elaborated in:

Usage by the postProcess utility is not available.

See also
Source files

Definition at line 253 of file externalCoupled.H.

Constructor & Destructor Documentation

◆ externalCoupled() [1/2]

externalCoupled ( const word name,
const Time runTime,
const dictionary dict 
)

Definition at line 496 of file externalCoupled.C.

References dict, and Foam::read().

Here is the call graph for this function:

◆ externalCoupled() [2/2]

externalCoupled ( const externalCoupled )
delete

◆ ~externalCoupled()

virtual ~externalCoupled ( )
virtualdefault

Member Function Documentation

◆ TypeName()

TypeName ( "externalCoupled"  )

◆ operator=()

void operator= ( const externalCoupled )
delete

◆ execute() [1/2]

bool execute ( )
virtual

Implements functionObject.

Definition at line 519 of file externalCoupled.C.

◆ execute() [2/2]

bool execute ( const label  subIndex)
virtual

Reimplemented from functionObject.

Definition at line 535 of file externalCoupled.C.

◆ end()

bool end ( )
virtual

Reimplemented from functionObject.

Definition at line 543 of file externalCoupled.C.

References functionObject::end().

Here is the call graph for this function:

◆ read()

bool read ( const dictionary dict)
virtual

◆ write()

bool write ( )
virtual

Implements functionObject.

Definition at line 825 of file externalCoupled.C.

◆ writeDataMaster()

void writeDataMaster ( ) const
virtual

Reimplemented from externalFileCoupler.

Definition at line 721 of file externalCoupled.C.

References Foam::endl(), fieldNames(), forAll, meshes(), regionNames, PtrList::set(), and WarningInFunction.

Here is the call graph for this function:

◆ readDataMaster()

void readDataMaster ( )
virtual

Reimplemented from externalFileCoupler.

Definition at line 677 of file externalCoupled.C.

References Foam::endl(), fieldNames(), forAll, meshes(), regionNames, PtrList::set(), and WarningInFunction.

Here is the call graph for this function:

◆ removeDataMaster()

void removeDataMaster ( ) const
virtual

Reimplemented from externalFileCoupler.

Definition at line 765 of file externalCoupled.C.

References fieldNames(), Log, UPstream::master(), Foam::nl, Foam::rm(), and Foam::type().

Here is the call graph for this function:

◆ removeDataSlave()

void removeDataSlave ( ) const
virtual

Reimplemented from externalFileCoupler.

Definition at line 795 of file externalCoupled.C.

References fieldNames(), Log, UPstream::master(), Foam::nl, Foam::rm(), and Foam::type().

Here is the call graph for this function:

◆ compositeName()

Foam::word compositeName ( const wordList regionNames)
static

Definition at line 341 of file externalCoupled.C.

References Foam::abort(), polyMesh::defaultRegion, Foam::FatalError, FatalErrorInFunction, word::null, and regionNames.

Here is the call graph for this function:

◆ writeGeometry()

void writeGeometry ( const UPtrList< const fvMesh > &  meshes,
const fileName commsDir,
const wordRe groupName 
)
static

◆ gatherAndCombine()

Foam::tmp<Foam::Field<Type> > gatherAndCombine ( const Field< Type > &  fld)

Definition at line 264 of file externalCoupledTemplates.C.

References fld, forAll, Pstream::gatherList(), UPstream::master(), UPstream::myProcNo(), Foam::New(), UPstream::nProcs(), and List::setSize().

Here is the call graph for this function:

Member Data Documentation

◆ patchKey

Foam::string patchKey = "// Patch:"
static

Definition at line 358 of file externalCoupled.H.

◆ log

Definition at line 352 of file functionObject.H.


The documentation for this class was generated from the following files: