42namespace functionObjects
58static void writeList(Ostream&
os,
const string& header,
const UList<T>&
L)
61 os << header.c_str() <<
nl;
85 const fileName& commsDir,
86 const word& regionGroupName,
87 const wordRe& groupName
102void Foam::functionObjects::externalCoupled::readColumns
105 const label nColumns,
106 autoPtr<IFstream>& masterFilePtr,
107 List<scalarField>& data
111 const globalIndex globalFaces(nRows, globalIndex::gatherOnly{});
124 List<scalarField>
values(nColumns);
127 const label procNRows = globalFaces.localSize(proci);
131 values[columni].setSize(procNRows);
134 for (label rowi = 0; rowi < procNRows; ++rowi)
139 if (!masterFilePtr().good())
142 <<
"Trying to read data for processor " << proci
144 <<
". Does your file have as many rows as there are"
145 <<
" patch faces (" << globalFaces.totalSize()
149 masterFilePtr().getLine(line);
151 while (line.empty() || line[0] ==
'#');
153 IStringStream lineStr(line);
155 for (label columni = 0; columni < nColumns; ++columni)
157 lineStr >>
values[columni][rowi];
162 UOPstream toProc(proci, pBufs);
166 pBufs.finishedScatters();
174void Foam::functionObjects::externalCoupled::readLines
177 autoPtr<IFstream>& masterFilePtr,
182 const globalIndex globalFaces(nRows, globalIndex::gatherOnly{});
195 const label procNRows = globalFaces.localSize(proci);
197 UOPstream toProc(proci, pBufs);
199 for (label rowi = 0; rowi < procNRows; ++rowi)
204 if (!masterFilePtr().good())
207 <<
"Trying to read data for processor " << proci
209 <<
". Does your file have as many rows as there are"
210 <<
" patch faces (" << globalFaces.totalSize()
214 masterFilePtr().getLine(line);
216 while (line.empty() || line[0] ==
'#');
224 pBufs.finishedScatters();
228 for (label rowi = 0; rowi < nRows; ++rowi)
230 string line(fromMaster);
231 lines << line.c_str() <<
nl;
262 osPointsPtr() <<
"// Group: " << groupName <<
endl;
263 osFacesPtr() <<
"// Group: " << groupName <<
endl;
265 Info<< typeName <<
": writing geometry to " << dir <<
endl;
279 mesh.boundaryMesh().patchSet
285 for (
const label patchi : patchIDs)
289 mesh.globalData().mergePoints
300 collectedPoints[proci] =
pointField(
mesh.points(), uniquePointIDs);
304 faceList& patchFaces = collectedFaces[proci];
305 patchFaces =
p.localFaces();
319 allPoints.append(collectedPoints[proci]);
320 allFaces.
append(collectedFaces[proci]);
323 Info<< typeName <<
": mesh " <<
mesh.name()
324 <<
", patch " <<
p.name()
325 <<
": writing " << allPoints.size() <<
" points to "
326 << osPointsPtr().name() <<
nl
327 << typeName <<
": mesh " <<
mesh.name()
328 <<
", patch " <<
p.name()
329 <<
": writing " << allFaces.
size() <<
" faces to "
330 << osFacesPtr().name() <<
endl;
333 const string entryHeader =
334 patchKey +
' ' +
mesh.name() +
' ' +
p.name();
336 writeList(osPointsPtr(), entryHeader, allPoints);
337 writeList(osFacesPtr(), entryHeader, allFaces);
391 <<
"regionNames " <<
regionNames <<
" not in alphabetical order :"
397void Foam::functionObjects::externalCoupled::initCoupling()
399 if (initialisedCoupling_)
405 forAll(regionGroupNames_, regioni)
407 const word& compName = regionGroupNames_[regioni];
417 const labelList& groups = regionToGroups_[compName];
419 for (
const label groupi : groups)
421 const wordRe& groupName = groupNames_[groupi];
423 bool geomExists =
false;
426 fileName dir(groupDir(commDirectory(), compName, groupName));
430 ||
isFile(dir/
"patchFaces");
451 initialisedCoupling_ =
true;
455void Foam::functionObjects::externalCoupled::performCoupling()
468 const auto action = waitForSlave();
480 lastTrigger_ = time_.timeIndex();
485 action != time_.stopAt()
489 Info<<
type() <<
": slave requested action "
492 time_.stopAt(action);
510 initialisedCoupling_(false)
528 !initialisedCoupling_
529 || (time_.timeIndex() >= lastTrigger_ + calcFrequency_)
563 externalFileCoupler::readDict(
dict);
574 for (
const entry& dEntry : allRegionsDict)
576 if (!dEntry.isDict())
579 <<
"Regions must be specified in dictionary format"
583 const wordRe regionGroupName(dEntry.keyword());
590 regionGroupNames_.append(compositeName(
regionNames));
593 for (
const entry& dEntry : regionDict)
595 if (!dEntry.isDict())
598 <<
"Regions must be specified in dictionary format"
602 const wordRe groupName(dEntry.keyword());
605 const label nGroups = groupNames_.size();
609 auto fnd = regionToGroups_.find(regionGroupNames_.last());
612 fnd().append(nGroups);
616 regionToGroups_.insert
618 regionGroupNames_.last(),
622 groupNames_.append(groupName);
629 Info<<
type() <<
": Communicating with regions:" <<
endl;
630 for (
const word& compName : regionGroupNames_)
633 const labelList& groups = regionToGroups_[compName];
634 for (
const label groupi : groups)
636 const wordRe& groupName = groupNames_[groupi];
638 Info<<
indent <<
"patchGroup: " << groupName <<
"\t"
641 <<
indent <<
"Reading fields: "
642 << groupReadFields_[groupi]
644 <<
indent <<
"Writing fields: "
645 << groupWriteFields_[groupi]
658 for (
const word& compName : regionGroupNames_)
660 const labelList& groups = regionToGroups_[compName];
661 for (
const label groupi : groups)
663 const wordRe& groupName = groupNames_[groupi];
665 fileName dir(groupDir(commDirectory(), compName, groupName));
669 Log <<
type() <<
": creating communications directory "
683 forAll(regionGroupNames_, regioni)
685 const word& compName = regionGroupNames_[regioni];
695 const labelList& groups = regionToGroups_[compName];
697 for (
const label groupi : groups)
699 const wordRe& groupName = groupNames_[groupi];
700 const wordList& fieldNames = groupReadFields_[groupi];
702 for (
const word& fieldName : fieldNames)
706 readData<scalar>(
meshes, groupName, fieldName)
707 || readData<vector>(
meshes, groupName, fieldName)
708 || readData<sphericalTensor>(
meshes, groupName, fieldName)
709 || readData<symmTensor>(
meshes, groupName, fieldName)
710 || readData<tensor>(
meshes, groupName, fieldName)
716 <<
"Field " << fieldName <<
" in regions " << compName
717 <<
" was not found." <<
endl;
727 forAll(regionGroupNames_, regioni)
729 const word& compName = regionGroupNames_[regioni];
739 const labelList& groups = regionToGroups_[compName];
741 for (
const label groupi : groups)
743 const wordRe& groupName = groupNames_[groupi];
744 const wordList& fieldNames = groupWriteFields_[groupi];
746 for (
const word& fieldName : fieldNames)
750 writeData<scalar>(
meshes, groupName, fieldName)
751 || writeData<vector>(
meshes, groupName, fieldName)
752 || writeData<sphericalTensor>(
meshes, groupName, fieldName)
753 || writeData<symmTensor>(
meshes, groupName, fieldName)
754 || writeData<tensor>(
meshes, groupName, fieldName)
760 <<
"Field " << fieldName <<
" in regions " << compName
761 <<
" was not found." <<
endl;
776 Log <<
type() <<
": removing data files written by master" <<
nl;
778 for (
const word& compName : regionGroupNames_)
780 const labelList& groups = regionToGroups_[compName];
781 for (
const label groupi : groups)
783 const wordRe& groupName = groupNames_[groupi];
784 const wordList& fieldNames = groupReadFields_[groupi];
786 for (
const word& fieldName : fieldNames)
790 groupDir(commDirectory(), compName, groupName)
806 Log <<
type() <<
": removing data files written by slave" <<
nl;
808 for (
const word& compName : regionGroupNames_)
810 const labelList& groups = regionToGroups_[compName];
811 for (
const label groupi : groups)
813 const wordRe& groupName = groupNames_[groupi];
814 const wordList& fieldNames = groupReadFields_[groupi];
816 for (
const word& fieldName : fieldNames)
820 groupDir(commDirectory(), compName, groupName)
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
void append(const T &val)
Copy append an element to the end of this list.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
static MinMax< T > ge(const T &minVal)
A semi-infinite range from minVal to the type max.
Output to file stream, using an OSstream.
UPstream::rangeType allProcs() const noexcept
Range of ranks indices associated with PstreamBuffers.
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
static void gatherList(const List< commsStruct > &comms, List< T > &values, const int tag, const label comm)
static void scatter(const List< commsStruct > &comms, T &value, const int tag, const label comm)
Broadcast data: Distribute without modification.
const T * set(const label i) const
virtual bool read()
Re-read model coefficients if they have changed.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
static const Enum< stopAtControls > stopAtControlNames
Names for stopAtControls.
@ saUnknown
Dummy no-op. Do not change current value.
void size(const label n)
Older name for setAddressableSize.
@ nonBlocking
"nonBlocking"
static constexpr int masterNo() noexcept
Process index of the master (always 0)
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
label size() const noexcept
The number of elements in the list.
static constexpr direction size() noexcept
The number of elements in the VectorSpace = Ncmpts.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
void reset(autoPtr< T > &&other) noexcept
Delete managed object and set to new given pointer.
void writeGeometry()
Write the mesh.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
A keyword and a list of tokens is an 'entry'.
Encapsulates the logic for coordinating between OpenFOAM and an external application.
enum Time::stopAtControls useMaster(const bool wait=false) const
Create lock file to indicate that OpenFOAM is in charge.
bool slaveFirst() const
External application provides initial values.
A class for handling file names.
Abstract base-class for Time/database function objects.
virtual bool end()
Called when Time::run() determines that the time-loop exits.
Watches for presence of the named trigger file in the case directory and signals a simulation stop (o...
Provides a simple file-based communication interface for explicit coupling with an external applicati...
virtual void writeDataMaster() const
Write data files (all regions, all fields) from master (OpenFOAM)
virtual void removeDataSlave() const
Remove data files written by slave (external code)
static string patchKey
Name of patch key, e.g. '// Patch:' when looking for start of patch data.
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
virtual void readDataMaster()
Read data files (all regions, all fields) on master (OpenFOAM)
virtual void removeDataMaster() const
Remove data files written by master (OpenFOAM)
virtual bool execute()
Called at each ++ or += of the time-loop.
virtual bool write()
Write, currently a no-op.
virtual bool end()
Called when Time::run() determines that the time-loop exits.
static word compositeName(const wordList &)
Reads fields from the time directories and adds them to the mesh database for further post-processing...
Virtual base class for function objects with a reference to Time.
Mesh data needed to do the Finite Volume discretisation.
virtual void validate()
Validate the turbulence fields after construction.
void checkOrder() const
Deprecated(2019-08) check list is monotonically increasing.
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
static word defaultRegion
Return the default region name.
A patch is a list of labels that address the faces in the global face list.
int myProcNo() const noexcept
Return processor number.
splitCell * master() const
A class for handling character strings derived from std::string.
@ BEGIN_LIST
Begin list [isseparator].
@ END_LIST
End list [isseparator].
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
A List of wordRe with additional matching capabilities.
A class for handling words, derived from Foam::string.
static const word null
An empty word.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Foam::PtrList< Foam::fvMesh > meshes(regionNames.size())
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
#define WarningInFunction
Report a warning using Foam::Warning.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
List< word > wordList
A List of words.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
void inplaceRenumber(const labelUList &oldToNew, IntListType &input)
Inplace renumber the values (not the indices) of a list.
List< label > labelList
A List of labels.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
messageStream Info
Information stream (stdout output on master, null elsewhere)
vectorField pointField
pointField is a vectorField.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Ostream & indent(Ostream &os)
Indent stream.
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.
void writeFields(const fvMesh &mesh, const wordHashSet &selectedFields, const bool writeFaceFields)
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
errorManipArg< error, int > exit(error &err, const int errNo=1)
labelList findStrings(const regExp &matcher, const UList< StringType > &input, const bool invert=false)
Return list indices for strings matching the regular expression.
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
constexpr char nl
The newline '\n' character (0x0a)
#define forAll(list, i)
Loop across all elements in list.
Operations on lists of strings.
const vector L(dict.get< vector >("L"))