Go to the documentation of this file.
42 namespace functionObjects
64 static void writeList(Ostream& os,
const string& header,
const UList<T>&
L)
67 os << header.c_str() <<
nl;
91 const fileName& commsDir,
92 const word& regionGroupName,
93 const wordRe& groupName
100 /string::validate<fileName>(groupName)
108 void Foam::functionObjects::externalCoupled::readColumns
111 const label nColumns,
112 autoPtr<IFstream>& masterFilePtr,
113 List<scalarField>& data
117 const globalIndex globalFaces(nRows);
129 List<scalarField>
values(nColumns);
132 const label procNRows = globalFaces.localSize(proci);
136 values[columni].setSize(procNRows);
139 for (
label rowi = 0; rowi < procNRows; ++rowi)
144 if (!masterFilePtr().good())
147 <<
"Trying to read data for processor " << proci
149 <<
". Does your file have as many rows as there are"
150 <<
" patch faces (" << globalFaces.size()
154 masterFilePtr().getLine(line);
156 while (line.empty() || line[0] ==
'#');
158 IStringStream lineStr(line);
160 for (
label columni = 0; columni < nColumns; ++columni)
162 lineStr >>
values[columni][rowi];
167 UOPstream str(proci, pBufs);
171 pBufs.finishedSends();
179 void Foam::functionObjects::externalCoupled::readLines
182 autoPtr<IFstream>& masterFilePtr,
187 const globalIndex globalFaces(nRows);
200 const label procNRows = globalFaces.localSize(proci);
202 UOPstream toProc(proci, pBufs);
204 for (
label rowi = 0; rowi < procNRows; ++rowi)
209 if (!masterFilePtr().good())
212 <<
"Trying to read data for processor " << proci
214 <<
". Does your file have as many rows as there are"
215 <<
" patch faces (" << globalFaces.size()
219 masterFilePtr().getLine(line);
221 while (line.empty() || line[0] ==
'#');
230 pBufs.finishedSends();
234 for (
label rowi = 0; rowi < nRows; ++rowi)
237 lines << line.c_str() <<
nl;
252 regionNames[i] =
meshes[i].dbDir();
256 checkOrder(regionNames);
258 fileName dir(groupDir(commsDir, compositeName(regionNames), groupName));
268 osPointsPtr() <<
"// Group: " << groupName <<
endl;
269 osFacesPtr() <<
"// Group: " << groupName <<
endl;
271 Info<< typeName <<
": writing geometry to " << dir <<
endl;
285 mesh.boundaryMesh().patchSet
291 for (
const label patchi : patchIDs)
295 mesh.globalData().mergePoints
306 collectedPoints[proci] =
pointField(
mesh.points(), uniquePointIDs);
310 faceList& patchFaces = collectedFaces[proci];
311 patchFaces =
p.localFaces();
325 allPoints.append(collectedPoints[proci]);
326 allFaces.
append(collectedFaces[proci]);
329 Info<< typeName <<
": mesh " <<
mesh.name()
330 <<
", patch " <<
p.name()
331 <<
": writing " <<
allPoints.size() <<
" points to "
332 << osPointsPtr().name() <<
nl
333 << typeName <<
": mesh " <<
mesh.name()
334 <<
", patch " <<
p.name()
335 <<
": writing " << allFaces.size() <<
" faces to "
336 << osFacesPtr().name() <<
endl;
339 const string entryHeader =
340 patchKey +
' ' +
mesh.name() +
' ' +
p.name();
343 writeList(osFacesPtr(), entryHeader, allFaces);
355 if (regionNames.size() == 0)
361 else if (regionNames.size() == 1)
371 return regionNames[0];
376 checkOrder(regionNames);
378 word composite(regionNames[0]);
379 for (
label i = 1; i < regionNames.size(); ++i)
381 composite +=
"_" + regionNames[i];
388 void Foam::functionObjects::externalCoupled::checkOrder
394 if (order !=
identity(regionNames.size()))
397 <<
"regionNames " << regionNames <<
" not in alphabetical order :"
403 void Foam::functionObjects::externalCoupled::initCoupling()
405 if (initialisedCoupling_)
411 forAll(regionGroupNames_, regioni)
413 const word& compName = regionGroupNames_[regioni];
414 const wordList& regionNames = regionGroupRegions_[regioni];
417 UPtrList<const fvMesh>
meshes(regionNames.size());
420 meshes.set(regi, time_.findObject<fvMesh>(regionNames[regi]));
423 const labelList& groups = regionToGroups_[compName];
425 for (
const label groupi : groups)
427 const wordRe& groupName = groupNames_[groupi];
429 bool geomExists =
false;
432 fileName dir(groupDir(commDirectory(), compName, groupName));
436 ||
isFile(dir/
"patchFaces");
443 writeGeometry(
meshes, commDirectory(), groupName);
457 initialisedCoupling_ =
true;
461 void Foam::functionObjects::externalCoupled::performCoupling()
474 const auto action = waitForSlave();
486 lastTrigger_ = time_.timeIndex();
491 action != time_.stopAt()
492 && action != Time::stopAtControls::saUnknown
495 Info<<
type() <<
": slave requested action "
498 time_.stopAt(action);
505 Foam::functionObjects::externalCoupled::externalCoupled
516 initialisedCoupling_(
false)
534 !initialisedCoupling_
535 || (time_.timeIndex() >= lastTrigger_ + calcFrequency_)
571 calcFrequency_ =
dict.lookupOrDefault(
"calcFrequency", 1);
579 for (
const entry& dEntry : allRegionsDict)
581 if (!dEntry.isDict())
584 <<
"Regions must be specified in dictionary format"
588 const wordRe regionGroupName(dEntry.keyword());
593 const wordList regionNames(allRegionNames, regionIDs);
595 regionGroupNames_.append(compositeName(regionNames));
596 regionGroupRegions_.append(regionNames);
598 for (
const entry& dEntry : regionDict)
600 if (!dEntry.isDict())
603 <<
"Regions must be specified in dictionary format"
607 const wordRe groupName(dEntry.keyword());
610 const label nGroups = groupNames_.size();
614 auto fnd = regionToGroups_.find(regionGroupNames_.last());
617 fnd().append(nGroups);
621 regionToGroups_.insert
623 regionGroupNames_.last(),
627 groupNames_.append(groupName);
634 Info<<
type() <<
": Communicating with regions:" <<
endl;
635 for (
const word& compName : regionGroupNames_)
638 const labelList& groups = regionToGroups_[compName];
639 for (
const label groupi : groups)
641 const wordRe& groupName = groupNames_[groupi];
643 Info<<
indent <<
"patchGroup: " << groupName <<
"\t"
646 <<
indent <<
"Reading fields: "
647 << groupReadFields_[groupi]
649 <<
indent <<
"Writing fields: "
650 << groupWriteFields_[groupi]
663 for (
const word& compName : regionGroupNames_)
665 const labelList& groups = regionToGroups_[compName];
666 for (
const label groupi : groups)
668 const wordRe& groupName = groupNames_[groupi];
670 fileName dir(groupDir(commDirectory(), compName, groupName));
674 Log <<
type() <<
": creating communications directory "
688 forAll(regionGroupNames_, regioni)
690 const word& compName = regionGroupNames_[regioni];
691 const wordList& regionNames = regionGroupRegions_[regioni];
697 meshes.set(regi, time_.findObject<
fvMesh>(regionNames[regi]));
700 const labelList& groups = regionToGroups_[compName];
702 for (
const label groupi : groups)
704 const wordRe& groupName = groupNames_[groupi];
705 const wordList& fieldNames = groupReadFields_[groupi];
707 for (
const word& fieldName : fieldNames)
711 readData<scalar>(
meshes, groupName, fieldName)
712 || readData<vector>(
meshes, groupName, fieldName)
713 || readData<sphericalTensor>(
meshes, groupName, fieldName)
714 || readData<symmTensor>(
meshes, groupName, fieldName)
715 || readData<tensor>(
meshes, groupName, fieldName)
721 <<
"Field " << fieldName <<
" in regions " << compName
722 <<
" was not found." <<
endl;
732 forAll(regionGroupNames_, regioni)
734 const word& compName = regionGroupNames_[regioni];
735 const wordList& regionNames = regionGroupRegions_[regioni];
741 meshes.set(regi, time_.findObject<
fvMesh>(regionNames[regi]));
744 const labelList& groups = regionToGroups_[compName];
746 for (
const label groupi : groups)
748 const wordRe& groupName = groupNames_[groupi];
749 const wordList& fieldNames = groupWriteFields_[groupi];
751 for (
const word& fieldName : fieldNames)
755 writeData<scalar>(
meshes, groupName, fieldName)
756 || writeData<vector>(
meshes, groupName, fieldName)
757 || writeData<sphericalTensor>(
meshes, groupName, fieldName)
758 || writeData<symmTensor>(
meshes, groupName, fieldName)
759 || writeData<tensor>(
meshes, groupName, fieldName)
765 <<
"Field " << fieldName <<
" in regions " << compName
766 <<
" was not found." <<
endl;
781 Log <<
type() <<
": removing data files written by master" <<
nl;
783 for (
const word& compName : regionGroupNames_)
785 const labelList& groups = regionToGroups_[compName];
786 for (
const label groupi : groups)
788 const wordRe& groupName = groupNames_[groupi];
789 const wordList& fieldNames = groupReadFields_[groupi];
791 for (
const word& fieldName : fieldNames)
795 groupDir(commDirectory(), compName, groupName)
811 Log <<
type() <<
": removing data files written by slave" <<
nl;
813 for (
const word& compName : regionGroupNames_)
815 const labelList& groups = regionToGroups_[compName];
816 for (
const label groupi : groups)
818 const wordRe& groupName = groupNames_[groupi];
819 const wordList& fieldNames = groupReadFields_[groupi];
821 for (
const word& fieldName : fieldNames)
825 groupDir(commDirectory(), compName, groupName)
A keyword and a list of tokens is an 'entry'.
List< label > labelList
A List of labels.
virtual void readDataMaster()
Read data files (all regions, all fields) on master (OpenFOAM)
vectorField pointField
pointField is a vectorField.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
const vector L(dict.get< vector >("L"))
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
static constexpr int masterNo() noexcept
Process index of the master.
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
A class for handling words, derived from Foam::string.
A class for handling file names.
static word defaultRegion
Return the default region name.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
bool read(const char *buf, int32_t &val)
Same as readInt32.
static constexpr direction size()
Return the number of elements in the VectorSpace = Ncmpts.
Virtual base class for function objects with a reference to Time.
A class representing the concept of 1 (one), which can be used to avoid manipulating objects that are...
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
Ostream & endl(Ostream &os)
Add newline and flush stream.
A class for handling character strings derived from std::string.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
addToRunTimeSelectionTable(functionObject, add, dictionary)
void inplaceRenumber(const labelUList &oldToNew, IntListType &input)
Inplace renumber the values (not the indices) of a list.
#define forAll(list, i)
Loop across all elements in list.
List< word > wordList
A List of words.
static const Enum< stopAtControls > stopAtControlNames
Names for stopAtControls.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
messageStream Info
Information stream (uses stdout - output is on the master only)
A patch is a list of labels that address the faces in the global face list.
word name(const complex &c)
Return string representation of complex.
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
void clear()
Clear the addressed list, i.e. set the size to zero.
void writeFields(const fvMesh &mesh, const wordHashSet &selectedFields)
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
PtrList< fvMesh > meshes(regionNames.size())
void writeList(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
virtual bool end()
Called when Time::run() determines that the time-loop exits.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Macros for easy insertion into run-time selection tables.
virtual void removeDataMaster() const
Remove data files written by master (OpenFOAM)
Mesh data needed to do the Finite Volume discretisation.
virtual void writeDataMaster() const
Write data files (all regions, all fields) from master (OpenFOAM)
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
labelList findStrings(const regExp &matcher, const UList< StringType > &input, const bool invert=false)
Return list indices for strings matching the regular expression.
errorManip< error > abort(error &err)
Ostream & indent(Ostream &os)
Indent stream.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
static string patchKey
Name of patch key, e.g. '// Patch:' when looking for start of patch data.
errorManipArg< error, int > exit(error &err, const int errNo=1)
virtual bool end()
Called when Time::run() determines that the time-loop exits.
Output to file stream, using an OSstream.
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const wordHashSet &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the templated type.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
static bool master(const label communicator=0)
Am I the master process.
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
virtual void removeDataSlave() const
Remove data files written by slave (external code)
virtual bool write()
Write, currently a no-op.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Encapsulates the logic for coordinating between OpenFOAM and an external application.
virtual bool execute()
Called at each ++ or += of the time-loop.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
Input/output from file streams.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
static const word null
An empty word.
Reads fields from the time directories and adds them to the mesh database for further post-processing...
Operations on lists of strings.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
bool readDict(const dictionary &dict)
Read communication settings from dictionary.
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.
static void writeGeometry(const UPtrList< const fvMesh > &meshes, const fileName &commsDir, const wordRe &groupName)
Write geometry for the group as region/patch.
Begin list [isseparator].
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
static word compositeName(const wordList &)
Create single name by appending words (in sorted order),.
#define WarningInFunction
Report a warning using Foam::Warning.
#define Log
Report write to Foam::Info if the local log switch is true.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?