42 namespace functionObjects
58 static 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
102 void Foam::functionObjects::externalCoupled::readColumns
105 const label nColumns,
106 autoPtr<IFstream>& masterFilePtr,
107 List<scalarField>& data
111 const globalIndex globalFaces(globalIndex::gatherOnly{}, nRows);
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();
174 void Foam::functionObjects::externalCoupled::readLines
177 autoPtr<IFstream>& masterFilePtr,
182 const globalIndex globalFaces(globalIndex::gatherOnly{}, nRows);
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;
270 DynamicList<face> allFaces;
279 mesh.boundaryMesh().patchSet
281 wordRes(one{}, groupName)
287 const polyPatch&
p =
mesh.boundaryMesh()[patchi];
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();
337 writeList(osFacesPtr(), entryHeader, allFaces);
375 void Foam::functionObjects::externalCoupled::checkOrder
384 <<
"regionNames " <<
regionNames <<
" not in alphabetical order :" 390 void Foam::functionObjects::externalCoupled::initCoupling()
392 if (initialisedCoupling_)
398 forAll(regionGroupNames_, regioni)
400 const word& compName = regionGroupNames_[regioni];
410 const labelList& groups = regionToGroups_[compName];
412 for (
const label groupi : groups)
414 const wordRe& groupName = groupNames_[groupi];
416 bool geomExists =
false;
419 fileName dir(groupDir(commDirectory(), compName, groupName));
423 ||
isFile(dir/
"patchFaces");
444 initialisedCoupling_ =
true;
448 void Foam::functionObjects::externalCoupled::performCoupling()
461 const auto action = waitForSlave();
473 lastTrigger_ = time_.timeIndex();
478 action != time_.stopAt()
479 && action != Time::stopAtControls::saUnknown
482 Info<<
type() <<
": slave requested action " 485 time_.stopAt(action);
503 initialisedCoupling_(false)
521 !initialisedCoupling_
522 || (time_.timeIndex() >= lastTrigger_ + calcFrequency_)
567 for (
const entry& dEntry : allRegionsDict)
569 if (!dEntry.isDict())
572 <<
"Regions must be specified in dictionary format" 576 const wordRe regionGroupName(dEntry.keyword());
583 regionGroupNames_.append(compositeName(
regionNames));
586 for (
const entry& dEntry : regionDict)
588 if (!dEntry.isDict())
591 <<
"Regions must be specified in dictionary format" 595 const wordRe groupName(dEntry.keyword());
598 const label nGroups = groupNames_.size();
602 auto fnd = regionToGroups_.find(regionGroupNames_.last());
605 fnd().append(nGroups);
609 regionToGroups_.insert
611 regionGroupNames_.last(),
615 groupNames_.append(groupName);
622 Info<<
type() <<
": Communicating with regions:" <<
endl;
623 for (
const word& compName : regionGroupNames_)
626 const labelList& groups = regionToGroups_[compName];
627 for (
const label groupi : groups)
629 const wordRe& groupName = groupNames_[groupi];
631 Info<<
indent <<
"patchGroup: " << groupName <<
"\t" 634 <<
indent <<
"Reading fields: " 635 << groupReadFields_[groupi]
637 <<
indent <<
"Writing fields: " 638 << groupWriteFields_[groupi]
651 for (
const word& compName : regionGroupNames_)
653 const labelList& groups = regionToGroups_[compName];
654 for (
const label groupi : groups)
656 const wordRe& groupName = groupNames_[groupi];
658 fileName dir(groupDir(commDirectory(), compName, groupName));
662 Log <<
type() <<
": creating communications directory " 676 forAll(regionGroupNames_, regioni)
678 const word& compName = regionGroupNames_[regioni];
688 const labelList& groups = regionToGroups_[compName];
690 for (
const label groupi : groups)
692 const wordRe& groupName = groupNames_[groupi];
693 const wordList& fieldNames = groupReadFields_[groupi];
695 for (
const word& fieldName : fieldNames)
699 readData<scalar>(
meshes, groupName, fieldName)
700 || readData<vector>(
meshes, groupName, fieldName)
701 || readData<sphericalTensor>(
meshes, groupName, fieldName)
702 || readData<symmTensor>(
meshes, groupName, fieldName)
703 || readData<tensor>(
meshes, groupName, fieldName)
709 <<
"Field " << fieldName <<
" in regions " << compName
710 <<
" was not found." <<
endl;
720 forAll(regionGroupNames_, regioni)
722 const word& compName = regionGroupNames_[regioni];
732 const labelList& groups = regionToGroups_[compName];
734 for (
const label groupi : groups)
736 const wordRe& groupName = groupNames_[groupi];
737 const wordList& fieldNames = groupWriteFields_[groupi];
739 for (
const word& fieldName : fieldNames)
743 writeData<scalar>(
meshes, groupName, fieldName)
744 || writeData<vector>(
meshes, groupName, fieldName)
745 || writeData<sphericalTensor>(
meshes, groupName, fieldName)
746 || writeData<symmTensor>(
meshes, groupName, fieldName)
747 || writeData<tensor>(
meshes, groupName, fieldName)
753 <<
"Field " << fieldName <<
" in regions " << compName
754 <<
" was not found." <<
endl;
769 Log <<
type() <<
": removing data files written by master" <<
nl;
771 for (
const word& compName : regionGroupNames_)
773 const labelList& groups = regionToGroups_[compName];
774 for (
const label groupi : groups)
776 const wordRe& groupName = groupNames_[groupi];
777 const wordList& fieldNames = groupReadFields_[groupi];
779 for (
const word& fieldName : fieldNames)
783 groupDir(commDirectory(), compName, groupName)
799 Log <<
type() <<
": removing data files written by slave" <<
nl;
801 for (
const word& compName : regionGroupNames_)
803 const labelList& groups = regionToGroups_[compName];
804 for (
const label groupi : groups)
806 const wordRe& groupName = groupNames_[groupi];
807 const wordList& fieldNames = groupReadFields_[groupi];
809 for (
const word& fieldName : fieldNames)
813 groupDir(commDirectory(), compName, groupName)
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
virtual bool end()
Called when Time::run() determines that the time-loop exits.
const labelList patchIDs(pbm.indices(polyPatchNames, true))
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
defineTypeNameAndDebug(ObukhovLength, 0)
Encapsulates the logic for coordinating between OpenFOAM and an external application.
virtual bool write()
Write, currently a no-op.
A class for handling file names.
Ostream & indent(Ostream &os)
Indent stream.
virtual bool execute()
Called at each ++ or += of the time-loop.
bool slaveFirst() const
External application provides initial values.
errorManipArg< error, int > exit(error &err, const int errNo=1)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
const vector L(dict.get< vector >("L"))
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.
const word & regionName() const
The mesh region name or word::null if polyMesh::defaultRegion.
static rangeType allProcs(const label communicator=worldComm)
Range of process indices for all processes.
Output to file stream, using an OSstream.
constexpr char nl
The newline '\n' character (0x0a)
Ostream & endl(Ostream &os)
Add newline and flush stream.
static string patchKey
Name of patch key, e.g. '// Patch:' when looking for start of patch data.
Begin list [isseparator].
static void writeGeometry(const UPtrList< const fvMesh > &meshes, const fileName &commsDir, const wordRe &groupName)
Write geometry for the group as region/patch.
static const Enum< stopAtControls > stopAtControlNames
Names for stopAtControls.
Operations on lists of strings.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
virtual void removeDataSlave() const
Remove data files written by slave (external code)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Macros for easy insertion into run-time selection tables.
externalCoupled(const word &name, const Time &runTime, const dictionary &dict)
Construct given time and dictionary.
static void broadcast(Type &value, const label comm=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all communicator ranks. Does nothing in non-paral...
#define forAll(list, i)
Loop across all elements in list.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
virtual bool end()
Called when Time::run() determines that the time-loop exits.
List< face > faceList
List of faces.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
vectorField pointField
pointField is a vectorField.
static void gatherList(const List< commsStruct > &comms, List< T > &values, const int tag, const label comm)
Gather data, but keep individual values separate. Uses the specified communication schedule...
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const NameMatchPredicate &selectedFields, DynamicList< regIOobject *> &storedObjects)
Read the selected GeometricFields of the templated type and store on the objectRegistry.
A class for handling words, derived from Foam::string.
static constexpr int masterNo() noexcept
Relative rank for the master process - is always 0.
label size() const noexcept
The number of entries in the list.
static MinMax< T > ge(const T &minVal)
A semi-infinite range from minVal to the type max.
Foam::PtrList< Foam::fvMesh > meshes(regionNames.size())
static const word null
An empty word.
enum Time::stopAtControls useMaster(const bool wait=false) const
Create lock file to indicate that OpenFOAM is in charge.
virtual void removeDataMaster() const
Remove data files written by master (OpenFOAM)
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
errorManip< error > abort(error &err)
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
virtual void writeDataMaster() const
Write data files (all regions, all fields) from master (OpenFOAM)
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings...
void writeFields(const fvMesh &mesh, const wordHashSet &selectedFields, const bool writeFaceFields)
bool readDict(const dictionary &dict)
Read communication settings from dictionary.
void writeList(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
Reads fields from the time directories and adds them to the mesh database for further post-processing...
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
virtual void readDataMaster()
Read data files (all regions, all fields) on master (OpenFOAM)
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
List< word > wordList
List of word.
void inplaceRenumber(const labelUList &oldToNew, IntListType &input)
Inplace renumber the values (not the indices) of a list.
static word compositeName(const wordList &)
Create single name by appending words (in sorted order), separated by '_'.
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
Mesh data needed to do the Finite Volume discretisation.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
"nonBlocking" : (MPI_Isend, MPI_Irecv)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
List< label > labelList
A List of labels.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
A class for handling character strings derived from std::string.
labelList findStrings(const regExp &matcher, const UList< StringType > &input, const bool invert=false)
Return list indices for strings matching the regular expression.
Virtual base class for function objects with a reference to Time.
A keyword and a list of tokens is an 'entry'.
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...